Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decompose tiled images during frame building (v4) #2742

Merged
merged 3 commits into from May 10, 2018
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Prev

Add some tests for for_each_tile.

  • Loading branch information
jrmuizel committed May 10, 2018
commit 9d5a0e307e953816d02965a546442f4f0e6a064b
@@ -224,3 +224,66 @@ pub fn for_each_tile(
}
}
}

#[cfg(test)]
mod tests {
use super::*;
use std::collections::HashSet;
use api::{LayoutRect, DeviceUintSize};
use euclid::{rect, size2};

// this checks some additional invariants
fn checked_for_each_tile(
prim_rect: &LayoutRect,
visible_rect: &LayoutRect,
device_image_size: &DeviceUintSize,
device_tile_size: u32,
callback: &mut FnMut(&LayoutRect, TileOffset, EdgeAaSegmentMask),
) {
let mut coverage = LayoutRect::zero();
let mut tiles = HashSet::new();
for_each_tile(prim_rect,
visible_rect,
device_image_size,
device_tile_size,
&mut |tile_rect, tile_offset, tile_flags| {
// make sure we don't get sent duplicate tiles
assert!(!tiles.contains(&tile_offset));

This comment has been minimized.

@kvark

kvark May 10, 2018

Member

can assert that prim_rect.contains(&tile_rect) as well as
!tiles.any(|t| t.intersects(&tile_rect)) which is superior to !tiles.contains(&tile_offset)

tiles.insert(tile_offset);
coverage = coverage.union(tile_rect);
assert!(prim_rect.contains_rect(&tile_rect));
callback(tile_rect, tile_offset, tile_flags);
},
);
assert!(prim_rect.contains_rect(&coverage));
assert!(coverage.contains_rect(&visible_rect.intersection(&prim_rect).unwrap_or(LayoutRect::zero())));
}

#[test]
fn basic() {
let mut count = 0;
checked_for_each_tile(&rect(0., 0., 1000., 1000.),

This comment has been minimized.

@kvark

kvark May 10, 2018

Member

we can just make it to count things right away instead of accepting a generic closure

&rect(75., 75., 400., 400.),
&size2(400, 400),
36,
&mut |_tile_rect, _tile_offset, _tile_flags| {
count += 1;
},
);
assert_eq!(count, 36);
}

#[test]
fn empty() {
let mut count = 0;
checked_for_each_tile(&rect(0., 0., 74., 74.),
&rect(75., 75., 400., 400.),
&size2(400, 400),
36,
&mut |_tile_rect, _tile_offset, _tile_flags| {
count += 1;
},
);
assert_eq!(count, 0);
}
}

This comment has been minimized.

@kvark

kvark May 10, 2018

Member

newline!

ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.