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
+493
−670
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.
Loading status checks…
Add some tests for for_each_tile.
- Loading branch information
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)); | ||
|
||
| 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.), | ||
kvark
Member
|
||
| &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); | ||
| } | ||
| } | ||
|
||
ProTip!
Use n and p to navigate between commits in a pull request.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
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)