diff options
author | Adrienne Walker <enne@chromium.org> | 2014-11-18 16:53:48 -0800 |
---|---|---|
committer | Adrienne Walker <enne@chromium.org> | 2014-11-19 00:54:48 +0000 |
commit | e606d6333c214baae2a39441701dd115ae8fa266 (patch) | |
tree | 28511d24db3a57db46cd99fe8a3d383dead46788 | |
parent | 8ee15b37bf22ccfd36f42f53fd374ca5ba4501e7 (diff) | |
download | chromium_src-e606d6333c214baae2a39441701dd115ae8fa266.zip chromium_src-e606d6333c214baae2a39441701dd115ae8fa266.tar.gz chromium_src-e606d6333c214baae2a39441701dd115ae8fa266.tar.bz2 |
Revert "cc: Add invalidations when shrinking piles"
This reverts commit 4210133350dbe253df7b6bea8e15dd8699764a25.
Reason for revert:
Accidentally merged to m39. Undoing after discussion with TPMs.
TBR=danakj@chromium.org
Review URL: https://codereview.chromium.org/742623002
Cr-Commit-Position: refs/branch-heads/2171@{#429}
Cr-Branched-From: 267aeeb8d85c8503a7fd12bd14654b8ea78d3974-refs/heads/master@{#297060}
-rw-r--r-- | cc/resources/picture_pile.cc | 99 | ||||
-rw-r--r-- | cc/resources/picture_pile_unittest.cc | 615 |
2 files changed, 296 insertions, 418 deletions
diff --git a/cc/resources/picture_pile.cc b/cc/resources/picture_pile.cc index 71a421d..ae2f8af 100644 --- a/cc/resources/picture_pile.cc +++ b/cc/resources/picture_pile.cc @@ -189,30 +189,21 @@ bool PicturePile::UpdateAndExpandInvalidation( gfx::Rect interest_rect_over_tiles = tiling_.ExpandRectToTileBounds(interest_rect); - gfx::Size min_tiling_size( - std::min(tiling_size().width(), old_tiling_size.width()), - std::min(tiling_size().height(), old_tiling_size.height())); - gfx::Size max_tiling_size( - std::max(tiling_size().width(), old_tiling_size.width()), - std::max(tiling_size().height(), old_tiling_size.height())); - if (old_tiling_size != layer_size) { has_any_recordings_ = false; - // Drop recordings that are outside the new or old layer bounds or that - // changed size. Newly exposed areas are considered invalidated. - // Previously exposed areas that are now outside of bounds also need to - // be invalidated, as they may become part of raster when scale < 1. + // Drop recordings that are outside the new layer bounds or that changed + // size. std::vector<PictureMapKey> to_erase; int min_toss_x = tiling_.num_tiles_x(); - if (max_tiling_size.width() > min_tiling_size.width()) { + if (tiling_size().width() > old_tiling_size.width()) { min_toss_x = - tiling_.FirstBorderTileXIndexFromSrcCoord(min_tiling_size.width()); + tiling_.FirstBorderTileXIndexFromSrcCoord(old_tiling_size.width()); } int min_toss_y = tiling_.num_tiles_y(); - if (max_tiling_size.height() > min_tiling_size.height()) { + if (tiling_size().height() > old_tiling_size.height()) { min_toss_y = - tiling_.FirstBorderTileYIndexFromSrcCoord(min_tiling_size.height()); + tiling_.FirstBorderTileYIndexFromSrcCoord(old_tiling_size.height()); } for (PictureMap::const_iterator it = picture_map_.begin(); it != picture_map_.end(); @@ -231,22 +222,20 @@ bool PicturePile::UpdateAndExpandInvalidation( // If a recording is dropped and not re-recorded below, invalidate that // full recording to cause any raster tiles that would use it to be // dropped. - // If the recording will be replaced below, invalidate newly exposed - // areas and previously exposed areas to force raster tiles that include the - // old recording to know there is new recording to display. - gfx::Rect min_tiling_rect_over_tiles = - tiling_.ExpandRectToTileBounds(gfx::Rect(min_tiling_size)); + // If the recording will be replaced below, just invalidate newly exposed + // areas to force raster tiles that include the old recording to know + // there is new recording to display. + gfx::Rect old_tiling_rect_over_tiles = + tiling_.ExpandRectToTileBounds(gfx::Rect(old_tiling_size)); if (min_toss_x < tiling_.num_tiles_x()) { // The bounds which we want to invalidate are the tiles along the old - // edge of the pile when expanding, or the new edge of the pile when - // shrinking. In either case, it's the difference of the two, so we'll - // call this bounding box the DELTA EDGE RECT. + // edge of the pile. We'll call this bounding box the OLD EDGE RECT. // - // In the picture below, the delta edge rect would be the bounding box of - // tiles {h,i,j}. |min_toss_x| would be equal to the horizontal index of - // the same tiles. + // In the picture below, the old edge rect would be the bounding box + // of tiles {h,i,j}. |min_toss_x| would be equal to the horizontal index + // of the same tiles. // - // min pile edge-v max pile edge-v + // old pile edge-v new pile edge-v // ---------------+ - - - - - - - -+ // mmppssvvyybbeeh|h . // mmppssvvyybbeeh|h . @@ -254,33 +243,33 @@ bool PicturePile::UpdateAndExpandInvalidation( // nnqqttwwzzccffi|i . // oorruuxxaaddggj|j . // oorruuxxaaddggj|j . - // ---------------+ - - - - - - - -+ <- min pile edge + // ---------------+ - - - - - - - -+ <- old pile edge // . - // - - - - - - - - - - - - - - - -+ <- max pile edge + // - - - - - - - - - - - - - - - -+ <- new pile edge // // If you were to slide a vertical beam from the left edge of the - // delta edge rect toward the right, it would either hit the right edge - // of the delta edge rect, or the interest rect (expanded to the bounds + // old edge rect toward the right, it would either hit the right edge + // of the old edge rect, or the interest rect (expanded to the bounds // of the tiles it touches). The same is true for a beam parallel to - // any of the four edges, sliding across the delta edge rect. We use + // any of the four edges, sliding accross the old edge rect. We use // the union of these four rectangles generated by these beams to - // determine which part of the delta edge rect is outside of the expanded + // determine which part of the old edge rect is outside of the expanded // interest rect. // - // Case 1: Intersect rect is outside the delta edge rect. It can be + // Case 1: Intersect rect is outside the old edge rect. It can be // either on the left or the right. The |left_rect| and |right_rect|, // cover this case, one will be empty and one will cover the full - // delta edge rect. In the picture below, |left_rect| would cover the - // delta edge rect, and |right_rect| would be empty. + // old edge rect. In the picture below, |left_rect| would cover the + // old edge rect, and |right_rect| would be empty. // +----------------------+ |^^^^^^^^^^^^^^^| - // |===> DELTA EDGE RECT | | | + // |===> OLD EDGE RECT | | | // |===> | | INTEREST RECT | // |===> | | | // |===> | | | // +----------------------+ |vvvvvvvvvvvvvvv| // - // Case 2: Interest rect is inside the delta edge rect. It will always - // fill the entire delta edge rect horizontally since the old edge rect + // Case 2: Interest rect is inside the old edge rect. It will always + // fill the entire old edge rect horizontally since the old edge rect // is a single tile wide, and the interest rect has been expanded to the // bounds of the tiles it touches. In this case the |left_rect| and // |right_rect| will be empty, but the case is handled by the |top_rect| @@ -297,19 +286,19 @@ bool PicturePile::UpdateAndExpandInvalidation( // | | // +-----------------+ // | | - // | DELTA EDGE RECT | + // | OLD EDGE RECT | // +-----------------+ // // Lastly, we need to consider tiles inside the expanded interest rect. // For those tiles, we want to invalidate exactly the newly exposed - // pixels. In the picture below the tiles in the delta edge rect have - // been resized and the area covered by periods must be invalidated. The + // pixels. In the picture below the tiles in the old edge rect have been + // resized and the area covered by periods must be invalidated. The // |exposed_rect| will cover exactly that area. - // v-min pile edge + // v-old pile edge // +---------+-------+ // | ........| // | ........| - // | DELTA EDGE.RECT.| + // | OLD EDGE.RECT..| // | ........| // | ........| // | ........| @@ -320,18 +309,18 @@ bool PicturePile::UpdateAndExpandInvalidation( int left = tiling_.TilePositionX(min_toss_x); int right = left + tiling_.TileSizeX(min_toss_x); - int top = min_tiling_rect_over_tiles.y(); - int bottom = min_tiling_rect_over_tiles.bottom(); + int top = old_tiling_rect_over_tiles.y(); + int bottom = old_tiling_rect_over_tiles.bottom(); int left_until = std::min(interest_rect_over_tiles.x(), right); int right_until = std::max(interest_rect_over_tiles.right(), left); int top_until = std::min(interest_rect_over_tiles.y(), bottom); int bottom_until = std::max(interest_rect_over_tiles.bottom(), top); - int exposed_left = min_tiling_size.width(); - int exposed_left_until = max_tiling_size.width(); + int exposed_left = old_tiling_size.width(); + int exposed_left_until = tiling_size().width(); int exposed_top = top; - int exposed_bottom = max_tiling_size.height(); + int exposed_bottom = tiling_size().height(); DCHECK_GE(exposed_left, left); gfx::Rect left_rect(left, top, left_until - left, bottom - top); @@ -351,23 +340,23 @@ bool PicturePile::UpdateAndExpandInvalidation( } if (min_toss_y < tiling_.num_tiles_y()) { // The same thing occurs here as in the case above, but the invalidation - // rect is the bounding box around the bottom row of tiles in the min + // rect is the bounding box around the bottom row of tiles in the old // pile. This would be tiles {o,r,u,x,a,d,g,j} in the above picture. int top = tiling_.TilePositionY(min_toss_y); int bottom = top + tiling_.TileSizeY(min_toss_y); - int left = min_tiling_rect_over_tiles.x(); - int right = min_tiling_rect_over_tiles.right(); + int left = old_tiling_rect_over_tiles.x(); + int right = old_tiling_rect_over_tiles.right(); int top_until = std::min(interest_rect_over_tiles.y(), bottom); int bottom_until = std::max(interest_rect_over_tiles.bottom(), top); int left_until = std::min(interest_rect_over_tiles.x(), right); int right_until = std::max(interest_rect_over_tiles.right(), left); - int exposed_top = min_tiling_size.height(); - int exposed_top_until = max_tiling_size.height(); + int exposed_top = old_tiling_size.height(); + int exposed_top_until = tiling_size().height(); int exposed_left = left; - int exposed_right = max_tiling_size.width(); + int exposed_right = tiling_size().width(); DCHECK_GE(exposed_top, top); gfx::Rect left_rect(left, top, left_until - left, bottom - top); diff --git a/cc/resources/picture_pile_unittest.cc b/cc/resources/picture_pile_unittest.cc index c9bc063..5143b44 100644 --- a/cc/resources/picture_pile_unittest.cc +++ b/cc/resources/picture_pile_unittest.cc @@ -614,11 +614,11 @@ TEST_P(PicturePileResizeCornerTest, ResizePileOutsideInterestRect) { } UpdateAndExpandInvalidation( - &invalidation, grow_down_tiling_size, + &invalidation, + grow_down_tiling_size, CornerSinglePixelRect(corner, grow_down_tiling_size)); - // We should have lost all of the recordings in the bottom row as none of them - // are in the current interest rect (which is either the above or below it). + // We should have lost the recordings in the bottom row. EXPECT_EQ(6, pile_->tiling().num_tiles_x()); EXPECT_EQ(8, pile_->tiling().num_tiles_y()); for (int i = 0; i < 6; ++i) { @@ -643,11 +643,11 @@ TEST_P(PicturePileResizeCornerTest, ResizePileOutsideInterestRect) { invalidation.Clear(); UpdateWholePile(); - UpdateAndExpandInvalidation(&invalidation, base_tiling_size, + UpdateAndExpandInvalidation(&invalidation, + base_tiling_size, CornerSinglePixelRect(corner, base_tiling_size)); - // When shrinking, we should have lost all the recordings in the bottom row - // not touching the interest rect. + // We should have lost the recordings that are now outside the tiling only. EXPECT_EQ(6, pile_->tiling().num_tiles_x()); EXPECT_EQ(6, pile_->tiling().num_tiles_y()); for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { @@ -655,60 +655,22 @@ TEST_P(PicturePileResizeCornerTest, ResizePileOutsideInterestRect) { TestPicturePile::PictureMapKey key(i, j); TestPicturePile::PictureMap& map = pile_->picture_map(); TestPicturePile::PictureMap::iterator it = map.find(key); - bool expect_tile; - switch (corner) { - case TOP_LEFT: - case TOP_RIGHT: - expect_tile = j < 5; - break; - case BOTTOM_LEFT: - // The interest rect in the bottom left tile means we'll record it. - expect_tile = j < 5 || (j == 5 && i == 0); - break; - case BOTTOM_RIGHT: - // The interest rect in the bottom right tile means we'll record it. - expect_tile = j < 5 || (j == 5 && i == 5); - break; - } - EXPECT_EQ(expect_tile, it != map.end() && it->second.GetPicture()); + EXPECT_EQ(j < 6, it != map.end() && it->second.GetPicture()); } } - // When shrinking, the previously exposed region is invalidated. - expected_invalidation = SubtractRegions(gfx::Rect(grow_down_tiling_size), - gfx::Rect(base_tiling_size)); - // The whole bottom row of tiles (except any with the interest rect) are - // dropped. - gfx::Rect bottom_row_minus_existing_corner = gfx::UnionRects( - pile_->tiling().TileBounds(0, 5), pile_->tiling().TileBounds(5, 5)); - switch (corner) { - case TOP_LEFT: - case TOP_RIGHT: - // No tiles are kept in the changed region because it doesn't - // intersect with the interest rect. - break; - case BOTTOM_LEFT: - bottom_row_minus_existing_corner.Subtract( - pile_->tiling().TileBounds(0, 5)); - break; - case BOTTOM_RIGHT: - bottom_row_minus_existing_corner.Subtract( - pile_->tiling().TileBounds(5, 5)); - break; - } - - expected_invalidation.Union(bottom_row_minus_existing_corner); + // No invalidation when shrinking. + expected_invalidation.Clear(); EXPECT_EQ(expected_invalidation.ToString(), invalidation.ToString()); invalidation.Clear(); UpdateWholePile(); UpdateAndExpandInvalidation( - &invalidation, grow_right_tiling_size, + &invalidation, + grow_right_tiling_size, CornerSinglePixelRect(corner, grow_right_tiling_size)); - // We should have lost all of the recordings in the right column as none of - // them are in the current interest rect (which is either entirely left or - // right of it). + // We should have lost the recordings in the right column. EXPECT_EQ(8, pile_->tiling().num_tiles_x()); EXPECT_EQ(6, pile_->tiling().num_tiles_y()); for (int i = 0; i < 6; ++i) { @@ -733,11 +695,11 @@ TEST_P(PicturePileResizeCornerTest, ResizePileOutsideInterestRect) { invalidation.Clear(); UpdateWholePile(); - UpdateAndExpandInvalidation(&invalidation, base_tiling_size, + UpdateAndExpandInvalidation(&invalidation, + base_tiling_size, CornerSinglePixelRect(corner, base_tiling_size)); - // When shrinking, we should have lost all the recordings in the right column - // not touching the interest rect. + // We should have lost the recordings that are now outside the tiling only. EXPECT_EQ(6, pile_->tiling().num_tiles_x()); EXPECT_EQ(6, pile_->tiling().num_tiles_y()); for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { @@ -745,54 +707,19 @@ TEST_P(PicturePileResizeCornerTest, ResizePileOutsideInterestRect) { TestPicturePile::PictureMapKey key(i, j); TestPicturePile::PictureMap& map = pile_->picture_map(); TestPicturePile::PictureMap::iterator it = map.find(key); - bool expect_tile; - switch (corner) { - case TOP_LEFT: - case BOTTOM_LEFT: - // No tiles are kept in the changed region because it doesn't - // intersect with the interest rect. - expect_tile = i < 5; - break; - case TOP_RIGHT: - // The interest rect in the top right tile means we'll record it. - expect_tile = i < 5 || (j == 0 && i == 5); - break; - case BOTTOM_RIGHT: - // The interest rect in the bottom right tile means we'll record it. - expect_tile = i < 5 || (j == 5 && i == 5); - break; - } - EXPECT_EQ(expect_tile, it != map.end() && it->second.GetPicture()); + EXPECT_EQ(i < 6, it != map.end() && it->second.GetPicture()); } } - // When shrinking, the previously exposed region is invalidated. - expected_invalidation = SubtractRegions(gfx::Rect(grow_right_tiling_size), - gfx::Rect(base_tiling_size)); - // The whole right column of tiles (except for ones with the interest rect) - // are dropped. - gfx::Rect right_column_minus_existing_corner = gfx::UnionRects( - pile_->tiling().TileBounds(5, 0), pile_->tiling().TileBounds(5, 5)); - switch (corner) { - case TOP_LEFT: - case BOTTOM_LEFT: - break; - case TOP_RIGHT: - right_column_minus_existing_corner.Subtract( - pile_->tiling().TileBounds(5, 0)); - break; - case BOTTOM_RIGHT: - right_column_minus_existing_corner.Subtract( - pile_->tiling().TileBounds(5, 5)); - break; - } - expected_invalidation.Union(right_column_minus_existing_corner); + // No invalidation when shrinking. + expected_invalidation.Clear(); EXPECT_EQ(expected_invalidation.ToString(), invalidation.ToString()); invalidation.Clear(); UpdateWholePile(); UpdateAndExpandInvalidation( - &invalidation, grow_both_tiling_size, + &invalidation, + grow_both_tiling_size, CornerSinglePixelRect(corner, grow_both_tiling_size)); // We should have lost the recordings in the right column and bottom row. @@ -810,7 +737,7 @@ TEST_P(PicturePileResizeCornerTest, ResizePileOutsideInterestRect) { // We invalidated all new pixels in the recording. expected_invalidation = SubtractRegions(gfx::Rect(grow_both_tiling_size), gfx::Rect(base_tiling_size)); - // But the new pixels don't cover the whole right column or bottom row. + // But the new pixels don't cover the whole right_column. Region right_column_and_bottom_row = UnionRegions(gfx::UnionRects(pile_->tiling().TileBounds(5, 0), pile_->tiling().TileBounds(5, 5)), @@ -823,11 +750,9 @@ TEST_P(PicturePileResizeCornerTest, ResizePileOutsideInterestRect) { invalidation.Clear(); UpdateWholePile(); - UpdateAndExpandInvalidation(&invalidation, base_tiling_size, - CornerSinglePixelRect(corner, base_tiling_size)); + UpdateAndExpandInvalidation(&invalidation, base_tiling_size, gfx::Rect()); - // We should have lost the recordings in the right column and bottom row, - // except where it intersects the interest rect. + // We should have lost the recordings that are now outside the tiling only. EXPECT_EQ(6, pile_->tiling().num_tiles_x()); EXPECT_EQ(6, pile_->tiling().num_tiles_y()); for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { @@ -835,54 +760,12 @@ TEST_P(PicturePileResizeCornerTest, ResizePileOutsideInterestRect) { TestPicturePile::PictureMapKey key(i, j); TestPicturePile::PictureMap& map = pile_->picture_map(); TestPicturePile::PictureMap::iterator it = map.find(key); - bool expect_tile; - switch (corner) { - case TOP_LEFT: - expect_tile = i < 5 && j < 5; - break; - case TOP_RIGHT: - // The interest rect in the top right tile means we'll record it. - expect_tile = (i < 5 && j < 5) || (j == 0 && i == 5); - break; - case BOTTOM_LEFT: - // The interest rect in the bottom left tile means we'll record it. - expect_tile = (i < 5 && j < 5) || (j == 5 && i == 0); - break; - case BOTTOM_RIGHT: - // The interest rect in the bottom right tile means we'll record it. - expect_tile = (i < 5 && j < 5) || (j == 5 && i == 5); - break; - } - EXPECT_EQ(expect_tile, it != map.end() && it->second.GetPicture()) - << i << "," << j; + EXPECT_EQ(i < 6 && j < 6, it != map.end() && it->second.GetPicture()); } } - // We invalidated all previous pixels in the recording. - expected_invalidation = SubtractRegions(gfx::Rect(grow_both_tiling_size), - gfx::Rect(base_tiling_size)); - // The whole right column and bottom row of tiles (except for ones with the - // interest rect) are dropped. - Region right_column_and_bottom_row_minus_existing_corner = - right_column_and_bottom_row; - switch (corner) { - case TOP_LEFT: - break; - case BOTTOM_LEFT: - right_column_and_bottom_row_minus_existing_corner.Subtract( - pile_->tiling().TileBounds(0, 5)); - break; - case TOP_RIGHT: - right_column_and_bottom_row_minus_existing_corner.Subtract( - pile_->tiling().TileBounds(5, 0)); - break; - case BOTTOM_RIGHT: - right_column_and_bottom_row_minus_existing_corner.Subtract( - pile_->tiling().TileBounds(5, 5)); - break; - } - expected_invalidation.Union( - right_column_and_bottom_row_minus_existing_corner); + // No invalidation when shrinking. + expected_invalidation.Clear(); EXPECT_EQ(expected_invalidation.ToString(), invalidation.ToString()); invalidation.Clear(); } @@ -922,238 +805,261 @@ TEST_P(PicturePileResizeCornerTest, SmallResizePileOutsideInterestRect) { } } - // In this test (unlike the large resize test), as all growing and shrinking - // happens within tiles, the resulting invalidation is symmetrical, so use - // this enum to repeat the test both ways. - enum ChangeDirection { GROW, SHRINK, LAST_DIRECTION = SHRINK }; - - // Grow downward. - for (int dir = 0; dir <= LAST_DIRECTION; ++dir) { - gfx::Size new_tiling_size = - dir == GROW ? grow_down_tiling_size : base_tiling_size; - UpdateWholePile(); - UpdateAndExpandInvalidation(&invalidation, new_tiling_size, - CornerSinglePixelRect(corner, new_tiling_size)); - - // We should have lost the recordings in the bottom row that do not - // intersect the interest rect. - EXPECT_EQ(6, pile_->tiling().num_tiles_x()); - EXPECT_EQ(6, pile_->tiling().num_tiles_y()); - for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { - for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { - TestPicturePile::PictureMapKey key(i, j); - TestPicturePile::PictureMap& map = pile_->picture_map(); - TestPicturePile::PictureMap::iterator it = map.find(key); - bool expect_tile; - switch (corner) { - case TOP_LEFT: - case TOP_RIGHT: - expect_tile = j < 5; - break; - case BOTTOM_LEFT: - // The interest rect in the bottom left tile means we'll record it. - expect_tile = j < 5 || (j == 5 && i == 0); - break; - case BOTTOM_RIGHT: - // The interest rect in the bottom right tile means we'll record it. - expect_tile = j < 5 || (j == 5 && i == 5); - break; - } - EXPECT_EQ(expect_tile, it != map.end() && it->second.GetPicture()); - } - } + UpdateAndExpandInvalidation( + &invalidation, + grow_down_tiling_size, + CornerSinglePixelRect(corner, grow_down_tiling_size)); - // We invalidated the bottom row outside the new interest rect. The tile - // that insects the interest rect in invalidated only on its newly - // exposed or previously exposed pixels. - if (dir == GROW) { - // Only calculate the expected invalidation while growing, as the tile - // bounds post-growing is the newly exposed / previously exposed sizes. - // Post-shrinking, the tile bounds are smaller, so can't be used. + // We should have lost the recordings in the bottom row that do not intersect + // the interest rect. + EXPECT_EQ(6, pile_->tiling().num_tiles_x()); + EXPECT_EQ(6, pile_->tiling().num_tiles_y()); + for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { + for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { + TestPicturePile::PictureMapKey key(i, j); + TestPicturePile::PictureMap& map = pile_->picture_map(); + TestPicturePile::PictureMap::iterator it = map.find(key); + bool expect_tile; switch (corner) { case TOP_LEFT: case TOP_RIGHT: - expected_invalidation = - gfx::UnionRects(pile_->tiling().TileBounds(0, 5), - pile_->tiling().TileBounds(5, 5)); + expect_tile = j < 5; break; case BOTTOM_LEFT: - expected_invalidation = - gfx::UnionRects(pile_->tiling().TileBounds(1, 5), - pile_->tiling().TileBounds(5, 5)); - expected_invalidation.Union(SubtractRects( - pile_->tiling().TileBounds(0, 5), gfx::Rect(base_tiling_size))); + // The interest rect in the bottom left tile means we'll record it. + expect_tile = j < 5 || (j == 5 && i == 0); break; case BOTTOM_RIGHT: - expected_invalidation = - gfx::UnionRects(pile_->tiling().TileBounds(0, 5), - pile_->tiling().TileBounds(4, 5)); - expected_invalidation.Union(SubtractRects( - pile_->tiling().TileBounds(5, 5), gfx::Rect(base_tiling_size))); + // The interest rect in the bottom right tile means we'll record it. + expect_tile = j < 5 || (j == 5 && i == 5); break; } + EXPECT_EQ(expect_tile, it != map.end() && it->second.GetPicture()); } - EXPECT_EQ(expected_invalidation.ToString(), invalidation.ToString()); - invalidation.Clear(); } - // Grow right. - for (int dir = 0; dir <= LAST_DIRECTION; ++dir) { - gfx::Size new_tiling_size = - dir == GROW ? grow_right_tiling_size : base_tiling_size; - UpdateWholePile(); - UpdateAndExpandInvalidation(&invalidation, new_tiling_size, - CornerSinglePixelRect(corner, new_tiling_size)); - - // We should have lost the recordings in the right column. - EXPECT_EQ(6, pile_->tiling().num_tiles_x()); - EXPECT_EQ(6, pile_->tiling().num_tiles_y()); - for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { - for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { - TestPicturePile::PictureMapKey key(i, j); - TestPicturePile::PictureMap& map = pile_->picture_map(); - TestPicturePile::PictureMap::iterator it = map.find(key); - bool expect_tile; - switch (corner) { - case TOP_LEFT: - case BOTTOM_LEFT: - expect_tile = i < 5; - break; - case TOP_RIGHT: - // The interest rect in the top right tile means we'll record it. - expect_tile = i < 5 || (j == 0 && i == 5); - break; - case BOTTOM_RIGHT: - // The interest rect in the bottom right tile means we'll record it. - expect_tile = i < 5 || (j == 5 && i == 5); - break; - } - EXPECT_EQ(expect_tile, it != map.end() && it->second.GetPicture()); - } + // We invalidated the bottom row outside the new interest rect. The tile that + // insects the interest rect in invalidated only on its new pixels. + switch (corner) { + case TOP_LEFT: + case TOP_RIGHT: + expected_invalidation = gfx::UnionRects(pile_->tiling().TileBounds(0, 5), + pile_->tiling().TileBounds(5, 5)); + break; + case BOTTOM_LEFT: + expected_invalidation = gfx::UnionRects(pile_->tiling().TileBounds(1, 5), + pile_->tiling().TileBounds(5, 5)); + expected_invalidation.Union(SubtractRects( + pile_->tiling().TileBounds(0, 5), gfx::Rect(base_tiling_size))); + break; + case BOTTOM_RIGHT: + expected_invalidation = gfx::UnionRects(pile_->tiling().TileBounds(0, 5), + pile_->tiling().TileBounds(4, 5)); + expected_invalidation.Union(SubtractRects( + pile_->tiling().TileBounds(5, 5), gfx::Rect(base_tiling_size))); + break; + } + EXPECT_EQ(expected_invalidation.ToString(), invalidation.ToString()); + invalidation.Clear(); + + UpdateWholePile(); + UpdateAndExpandInvalidation(&invalidation, + base_tiling_size, + CornerSinglePixelRect(corner, base_tiling_size)); + + // We should have lost nothing. + EXPECT_EQ(6, pile_->tiling().num_tiles_x()); + EXPECT_EQ(6, pile_->tiling().num_tiles_y()); + for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { + for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { + TestPicturePile::PictureMapKey key(i, j); + TestPicturePile::PictureMap& map = pile_->picture_map(); + TestPicturePile::PictureMap::iterator it = map.find(key); + EXPECT_TRUE(it != map.end() && it->second.GetPicture()); } + } - // We invalidated the right column outside the new interest rect. The tile - // that insects the interest rect in invalidated only on its new or - // previously exposed pixels. - if (dir == GROW) { - // Calculate the expected invalidation the first time through the loop. + // We invalidated nothing. + expected_invalidation.Clear(); + EXPECT_EQ(expected_invalidation.ToString(), invalidation.ToString()); + invalidation.Clear(); + + UpdateWholePile(); + UpdateAndExpandInvalidation( + &invalidation, + grow_right_tiling_size, + CornerSinglePixelRect(corner, grow_right_tiling_size)); + + // We should have lost the recordings in the right column. + EXPECT_EQ(6, pile_->tiling().num_tiles_x()); + EXPECT_EQ(6, pile_->tiling().num_tiles_y()); + for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { + for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { + TestPicturePile::PictureMapKey key(i, j); + TestPicturePile::PictureMap& map = pile_->picture_map(); + TestPicturePile::PictureMap::iterator it = map.find(key); + bool expect_tile; switch (corner) { case TOP_LEFT: case BOTTOM_LEFT: - expected_invalidation = - gfx::UnionRects(pile_->tiling().TileBounds(5, 0), - pile_->tiling().TileBounds(5, 5)); + expect_tile = i < 5; break; case TOP_RIGHT: - expected_invalidation = - gfx::UnionRects(pile_->tiling().TileBounds(5, 1), - pile_->tiling().TileBounds(5, 5)); - expected_invalidation.Union(SubtractRects( - pile_->tiling().TileBounds(5, 0), gfx::Rect(base_tiling_size))); + // The interest rect in the top right tile means we'll record it. + expect_tile = i < 5 || (j == 0 && i == 5); break; case BOTTOM_RIGHT: - expected_invalidation = - gfx::UnionRects(pile_->tiling().TileBounds(5, 0), - pile_->tiling().TileBounds(5, 4)); - expected_invalidation.Union(SubtractRects( - pile_->tiling().TileBounds(5, 5), gfx::Rect(base_tiling_size))); + // The interest rect in the bottom right tile means we'll record it. + expect_tile = i < 5 || (j == 5 && i == 5); break; } + EXPECT_EQ(expect_tile, it != map.end() && it->second.GetPicture()); } - EXPECT_EQ(expected_invalidation.ToString(), invalidation.ToString()); - invalidation.Clear(); } - // Grow both. - for (int dir = 0; dir <= LAST_DIRECTION; ++dir) { - gfx::Size new_tiling_size = - dir == GROW ? grow_both_tiling_size : base_tiling_size; - UpdateWholePile(); - UpdateAndExpandInvalidation(&invalidation, new_tiling_size, - CornerSinglePixelRect(corner, new_tiling_size)); - - // We should have lost the recordings in the right column and bottom row. - // The tile that insects the interest rect in invalidated only on its new - // or previously exposed pixels. - EXPECT_EQ(6, pile_->tiling().num_tiles_x()); - EXPECT_EQ(6, pile_->tiling().num_tiles_y()); - for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { - for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { - TestPicturePile::PictureMapKey key(i, j); - TestPicturePile::PictureMap& map = pile_->picture_map(); - TestPicturePile::PictureMap::iterator it = map.find(key); - bool expect_tile; - switch (corner) { - case TOP_LEFT: - expect_tile = i < 5 && j < 5; - break; - case TOP_RIGHT: - // The interest rect in the top right tile means we'll record it. - expect_tile = (i < 5 && j < 5) || (j == 0 && i == 5); - break; - case BOTTOM_LEFT: - // The interest rect in the bottom left tile means we'll record it. - expect_tile = (i < 5 && j < 5) || (j == 5 && i == 0); - break; - case BOTTOM_RIGHT: - // The interest rect in the bottom right tile means we'll record it. - expect_tile = (i < 5 && j < 5) || (j == 5 && i == 5); - break; - } - EXPECT_EQ(expect_tile, it != map.end() && it->second.GetPicture()) - << i << "," << j; - } + // We invalidated the right column outside the new interest rect. The tile + // that insects the interest rect in invalidated only on its new pixels. + switch (corner) { + case TOP_LEFT: + case BOTTOM_LEFT: + expected_invalidation = gfx::UnionRects(pile_->tiling().TileBounds(5, 0), + pile_->tiling().TileBounds(5, 5)); + break; + case TOP_RIGHT: + expected_invalidation = gfx::UnionRects(pile_->tiling().TileBounds(5, 1), + pile_->tiling().TileBounds(5, 5)); + expected_invalidation.Union(SubtractRects( + pile_->tiling().TileBounds(5, 0), gfx::Rect(base_tiling_size))); + break; + case BOTTOM_RIGHT: + expected_invalidation = gfx::UnionRects(pile_->tiling().TileBounds(5, 0), + pile_->tiling().TileBounds(5, 4)); + expected_invalidation.Union(SubtractRects( + pile_->tiling().TileBounds(5, 5), gfx::Rect(base_tiling_size))); + break; + } + EXPECT_EQ(expected_invalidation.ToString(), invalidation.ToString()); + invalidation.Clear(); + + UpdateWholePile(); + UpdateAndExpandInvalidation(&invalidation, + base_tiling_size, + CornerSinglePixelRect(corner, base_tiling_size)); + + // We should have lost nothing. + EXPECT_EQ(6, pile_->tiling().num_tiles_x()); + EXPECT_EQ(6, pile_->tiling().num_tiles_y()); + for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { + for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { + TestPicturePile::PictureMapKey key(i, j); + TestPicturePile::PictureMap& map = pile_->picture_map(); + TestPicturePile::PictureMap::iterator it = map.find(key); + EXPECT_TRUE(it != map.end() && it->second.GetPicture()); } + } + + // We invalidated nothing. + expected_invalidation.Clear(); + EXPECT_EQ(expected_invalidation.ToString(), invalidation.ToString()); + invalidation.Clear(); + + UpdateWholePile(); + UpdateAndExpandInvalidation( + &invalidation, + grow_both_tiling_size, + CornerSinglePixelRect(corner, grow_both_tiling_size)); - // We invalidated the right column and the bottom row outside the new - // interest rect. The tile that insects the interest rect in invalidated - // only on its new or previous exposed pixels. - if (dir == GROW) { - // Calculate the expected invalidation the first time through the loop. + // We should have lost the recordings in the right column and bottom row. The + // tile that insects the interest rect in invalidated only on its new pixels. + EXPECT_EQ(6, pile_->tiling().num_tiles_x()); + EXPECT_EQ(6, pile_->tiling().num_tiles_y()); + for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { + for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { + TestPicturePile::PictureMapKey key(i, j); + TestPicturePile::PictureMap& map = pile_->picture_map(); + TestPicturePile::PictureMap::iterator it = map.find(key); + bool expect_tile; switch (corner) { case TOP_LEFT: - expected_invalidation = - gfx::UnionRects(pile_->tiling().TileBounds(5, 0), - pile_->tiling().TileBounds(5, 5)); - expected_invalidation.Union( - gfx::UnionRects(pile_->tiling().TileBounds(0, 5), - pile_->tiling().TileBounds(5, 5))); + expect_tile = i < 5 && j < 5; break; case TOP_RIGHT: - expected_invalidation = - gfx::UnionRects(pile_->tiling().TileBounds(5, 1), - pile_->tiling().TileBounds(5, 5)); - expected_invalidation.Union( - gfx::UnionRects(pile_->tiling().TileBounds(0, 5), - pile_->tiling().TileBounds(5, 5))); - expected_invalidation.Union(SubtractRects( - pile_->tiling().TileBounds(5, 0), gfx::Rect(base_tiling_size))); + // The interest rect in the top right tile means we'll record it. + expect_tile = (i < 5 && j < 5) || (j == 0 && i == 5); break; case BOTTOM_LEFT: - expected_invalidation = - gfx::UnionRects(pile_->tiling().TileBounds(5, 0), - pile_->tiling().TileBounds(5, 5)); - expected_invalidation.Union( - gfx::UnionRects(pile_->tiling().TileBounds(1, 5), - pile_->tiling().TileBounds(5, 5))); - expected_invalidation.Union(SubtractRects( - pile_->tiling().TileBounds(0, 5), gfx::Rect(base_tiling_size))); + // The interest rect in the bottom left tile means we'll record it. + expect_tile = (i < 5 && j < 5) || (j == 5 && i == 0); break; case BOTTOM_RIGHT: - expected_invalidation = - gfx::UnionRects(pile_->tiling().TileBounds(5, 0), - pile_->tiling().TileBounds(5, 4)); - expected_invalidation.Union( - gfx::UnionRects(pile_->tiling().TileBounds(0, 5), - pile_->tiling().TileBounds(4, 5))); - expected_invalidation.Union(SubtractRegions( - pile_->tiling().TileBounds(5, 5), gfx::Rect(base_tiling_size))); + // The interest rect in the bottom right tile means we'll record it. + expect_tile = (i < 5 && j < 5) || (j == 5 && i == 5); break; } + EXPECT_EQ(expect_tile, it != map.end() && it->second.GetPicture()) + << i << "," << j; } - EXPECT_EQ(expected_invalidation.ToString(), invalidation.ToString()); - invalidation.Clear(); } + + // We invalidated the right column and the bottom row outside the new interest + // rect. The tile that insects the interest rect in invalidated only on its + // new pixels. + switch (corner) { + case TOP_LEFT: + expected_invalidation = gfx::UnionRects(pile_->tiling().TileBounds(5, 0), + pile_->tiling().TileBounds(5, 5)); + expected_invalidation.Union(gfx::UnionRects( + pile_->tiling().TileBounds(0, 5), pile_->tiling().TileBounds(5, 5))); + break; + case TOP_RIGHT: + expected_invalidation = gfx::UnionRects(pile_->tiling().TileBounds(5, 1), + pile_->tiling().TileBounds(5, 5)); + expected_invalidation.Union(gfx::UnionRects( + pile_->tiling().TileBounds(0, 5), pile_->tiling().TileBounds(5, 5))); + expected_invalidation.Union(SubtractRects( + pile_->tiling().TileBounds(5, 0), gfx::Rect(base_tiling_size))); + break; + case BOTTOM_LEFT: + expected_invalidation = gfx::UnionRects(pile_->tiling().TileBounds(5, 0), + pile_->tiling().TileBounds(5, 5)); + expected_invalidation.Union(gfx::UnionRects( + pile_->tiling().TileBounds(1, 5), pile_->tiling().TileBounds(5, 5))); + expected_invalidation.Union(SubtractRects( + pile_->tiling().TileBounds(0, 5), gfx::Rect(base_tiling_size))); + break; + case BOTTOM_RIGHT: + expected_invalidation = gfx::UnionRects(pile_->tiling().TileBounds(5, 0), + pile_->tiling().TileBounds(5, 4)); + expected_invalidation.Union(gfx::UnionRects( + pile_->tiling().TileBounds(0, 5), pile_->tiling().TileBounds(4, 5))); + expected_invalidation.Union(SubtractRegions( + pile_->tiling().TileBounds(5, 5), gfx::Rect(base_tiling_size))); + break; + } + EXPECT_EQ(expected_invalidation.ToString(), invalidation.ToString()); + invalidation.Clear(); + + UpdateWholePile(); + UpdateAndExpandInvalidation(&invalidation, + base_tiling_size, + CornerSinglePixelRect(corner, base_tiling_size)); + + // We should have lost nothing. + EXPECT_EQ(6, pile_->tiling().num_tiles_x()); + EXPECT_EQ(6, pile_->tiling().num_tiles_y()); + for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { + for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { + TestPicturePile::PictureMapKey key(i, j); + TestPicturePile::PictureMap& map = pile_->picture_map(); + TestPicturePile::PictureMap::iterator it = map.find(key); + EXPECT_TRUE(it != map.end() && it->second.GetPicture()); + } + } + + // We invalidated nothing. + expected_invalidation.Clear(); + EXPECT_EQ(expected_invalidation.ToString(), invalidation.ToString()); + invalidation.Clear(); } INSTANTIATE_TEST_CASE_P( @@ -1230,11 +1136,8 @@ TEST_F(PicturePileTest, ResizePileInsideInterestRect) { } } - // We invalidated the previously exposed pixels on the bottom row of tiles. - expected_invalidation = SubtractRegions(gfx::Rect(grow_down_tiling_size), - gfx::Rect(base_tiling_size)); - EXPECT_TRUE(expected_invalidation.Contains(bottom_row_new_pixels)); - EXPECT_EQ(expected_invalidation.ToString(), invalidation.ToString()); + // No invalidation when shrinking. + EXPECT_EQ(Region().ToString(), invalidation.ToString()); invalidation.Clear(); UpdateWholePile(); @@ -1279,11 +1182,8 @@ TEST_F(PicturePileTest, ResizePileInsideInterestRect) { } } - // We invalidated the previously exposed pixels on the right column of tiles. - expected_invalidation = SubtractRegions(gfx::Rect(grow_right_tiling_size), - gfx::Rect(base_tiling_size)); - EXPECT_TRUE(expected_invalidation.Contains(right_column_new_pixels)); - EXPECT_EQ(expected_invalidation.ToString(), invalidation.ToString()); + // No invalidation when shrinking. + EXPECT_EQ(Region().ToString(), invalidation.ToString()); invalidation.Clear(); UpdateWholePile(); @@ -1332,13 +1232,8 @@ TEST_F(PicturePileTest, ResizePileInsideInterestRect) { } } - // We invalidated the previously exposed pixels on the bottom row and right - // column of tiles. - expected_invalidation = SubtractRegions(gfx::Rect(grow_both_tiling_size), - gfx::Rect(base_tiling_size)); - EXPECT_TRUE( - expected_invalidation.Contains(bottom_row_and_right_column_new_pixels)); - EXPECT_EQ(expected_invalidation.ToString(), invalidation.ToString()); + // No invalidation when shrinking. + EXPECT_EQ(Region().ToString(), invalidation.ToString()); invalidation.Clear(); } @@ -1406,10 +1301,8 @@ TEST_F(PicturePileTest, SmallResizePileInsideInterestRect) { } } - // We invalidated the previously exposed pixels. - expected_invalidation = SubtractRegions(gfx::Rect(grow_down_tiling_size), - gfx::Rect(base_tiling_size)); - EXPECT_EQ(expected_invalidation.ToString(), invalidation.ToString()); + // No invalidation when shrinking. + EXPECT_EQ(Region().ToString(), invalidation.ToString()); invalidation.Clear(); UpdateWholePile(); @@ -1449,10 +1342,8 @@ TEST_F(PicturePileTest, SmallResizePileInsideInterestRect) { } } - // We invalidated the previously exposed pixels. - expected_invalidation = SubtractRegions(gfx::Rect(grow_right_tiling_size), - gfx::Rect(base_tiling_size)); - EXPECT_EQ(expected_invalidation.ToString(), invalidation.ToString()); + // No invalidation when shrinking. + EXPECT_EQ(Region().ToString(), invalidation.ToString()); invalidation.Clear(); UpdateWholePile(); @@ -1492,10 +1383,8 @@ TEST_F(PicturePileTest, SmallResizePileInsideInterestRect) { } } - // We invalidated the previously exposed pixels. - expected_invalidation = SubtractRegions(gfx::Rect(grow_both_tiling_size), - gfx::Rect(base_tiling_size)); - EXPECT_EQ(expected_invalidation.ToString(), invalidation.ToString()); + // No invalidation when shrinking. + EXPECT_EQ(Region().ToString(), invalidation.ToString()); invalidation.Clear(); } |