Skip to content
This repository was archived by the owner on Apr 3, 2020. It is now read-only.

Commit 04a24ab

Browse files
danakjCommit bot
authored and
Commit bot
committed
cc: Correct expansion of invalidation for tiles outside of interest rect
Previously we subtracted the interest_rect_over_tiles from the invalid_rect when looking to see what invalidation would not be recorded but this computation is wrong. Instead, we need to expand the invalidation to the bounds of the tiles it touches (including tiles it touches on borders). Then we can subtract the interest rect expanded to the bounds of tiles it touches (including tiles it touches on borders). This makes each expansion match the iteration of the given rect where we include borders. If a tile is touched only on the border by invalidation, but the tile is not touched even on a border by the interest rect, we want to expand the invalidation to cover that tile. R=enne, vmpstr BUG=421729 Review URL: https://codereview.chromium.org/657913002 Cr-Commit-Position: refs/heads/master@{#299750}
1 parent 55721c1 commit 04a24ab

File tree

3 files changed

+98
-13
lines changed

3 files changed

+98
-13
lines changed

cc/resources/picture_pile.cc

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,9 @@ float ClusterTiles(const std::vector<gfx::Rect>& invalid_tiles,
149149

150150
namespace cc {
151151

152-
PicturePile::PicturePile() : is_suitable_for_gpu_rasterization_(true) {
152+
PicturePile::PicturePile()
153+
: is_suitable_for_gpu_rasterization_(true),
154+
pixel_record_distance_(kPixelDistanceToRecord) {
153155
}
154156

155157
PicturePile::~PicturePile() {
@@ -180,11 +182,7 @@ bool PicturePile::UpdateAndExpandInvalidation(
180182
}
181183

182184
gfx::Rect interest_rect = visible_layer_rect;
183-
interest_rect.Inset(
184-
-kPixelDistanceToRecord,
185-
-kPixelDistanceToRecord,
186-
-kPixelDistanceToRecord,
187-
-kPixelDistanceToRecord);
185+
interest_rect.Inset(-pixel_record_distance_, -pixel_record_distance_);
188186
recorded_viewport_ = interest_rect;
189187
recorded_viewport_.Intersect(gfx::Rect(tiling_size()));
190188

@@ -385,23 +383,31 @@ bool PicturePile::UpdateAndExpandInvalidation(
385383
for (auto& it : picture_map_)
386384
updated = it.second.Invalidate(frame_number) || updated;
387385
} else {
388-
// Expand invalidation that is outside tiles that intersect the interest
389-
// rect. These tiles are no longer valid and should be considerered fully
390-
// invalid, so we can know to not keep around raster tiles that intersect
391-
// with these recording tiles.
386+
// Expand invalidation that is on tiles that aren't in the interest rect and
387+
// will not be re-recorded below. These tiles are no longer valid and should
388+
// be considerered fully invalid, so we can know to not keep around raster
389+
// tiles that intersect with these recording tiles.
392390
Region invalidation_expanded_to_full_tiles;
393391

394392
for (Region::Iterator i(*invalidation); i.has_rect(); i.next()) {
395393
gfx::Rect invalid_rect = i.rect();
396394

397-
gfx::Rect invalid_rect_outside_interest_rect_tiles = invalid_rect;
395+
// This rect covers the bounds (excluding borders) of all tiles whose
396+
// bounds (including borders) touch the |interest_rect|. This matches
397+
// the iteration of the |invalid_rect| below which includes borders when
398+
// calling Invalidate() on pictures.
399+
gfx::Rect invalid_rect_outside_interest_rect_tiles =
400+
tiling_.ExpandRectToTileBounds(invalid_rect);
401+
// We subtract the |interest_rect_over_tiles| which represents the bounds
402+
// of tiles that will be re-recorded below. This matches the iteration of
403+
// |interest_rect| below which includes borders.
398404
// TODO(danakj): We should have a Rect-subtract-Rect-to-2-rects operator
399405
// instead of using Rect::Subtract which gives you the bounding box of the
400406
// subtraction.
401407
invalid_rect_outside_interest_rect_tiles.Subtract(
402408
interest_rect_over_tiles);
403-
invalidation_expanded_to_full_tiles.Union(tiling_.ExpandRectToTileBounds(
404-
invalid_rect_outside_interest_rect_tiles));
409+
invalidation_expanded_to_full_tiles.Union(
410+
invalid_rect_outside_interest_rect_tiles);
405411

406412
// Split this inflated invalidation across tile boundaries and apply it
407413
// to all tiles that it touches.

cc/resources/picture_pile.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ class CC_EXPORT PicturePile : public PicturePileBase {
5151
is_suitable_for_gpu_rasterization_ = false;
5252
}
5353

54+
void SetPixelRecordDistanceForTesting(int d) { pixel_record_distance_ = d; }
55+
5456
protected:
5557
virtual ~PicturePile();
5658

@@ -60,6 +62,7 @@ class CC_EXPORT PicturePile : public PicturePileBase {
6062
void DetermineIfSolidColor();
6163

6264
bool is_suitable_for_gpu_rasterization_;
65+
int pixel_record_distance_;
6366

6467
DISALLOW_COPY_AND_ASSIGN(PicturePile);
6568
};

cc/resources/picture_pile_unittest.cc

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,82 @@ class PicturePileTest : public PicturePileTestBase, public testing::Test {
9999
virtual void SetUp() override { InitializeData(); }
100100
};
101101

102+
TEST_F(PicturePileTest, InvalidationOnTileBorderOutsideInterestRect) {
103+
// Don't expand the interest rect past what we invalidate.
104+
pile_->SetPixelRecordDistanceForTesting(0);
105+
106+
gfx::Size tile_size(100, 100);
107+
pile_->tiling().SetMaxTextureSize(tile_size);
108+
109+
gfx::Size pile_size(400, 400);
110+
SetTilingSize(pile_size);
111+
112+
// We have multiple tiles.
113+
EXPECT_GT(pile_->tiling().num_tiles_x(), 2);
114+
EXPECT_GT(pile_->tiling().num_tiles_y(), 2);
115+
116+
// Record everything.
117+
Region invalidation(tiling_rect());
118+
UpdateAndExpandInvalidation(&invalidation, tiling_size(), tiling_rect());
119+
120+
// +----------+-----------------+-----------+
121+
// | | VVVV 1,0| |
122+
// | | VVVV | |
123+
// | | VVVV | |
124+
// | ...|.................|... |
125+
// | ...|.................|... |
126+
// +----------+-----------------+-----------+
127+
// | ...| |... |
128+
// | ...| |... |
129+
// | ...| |... |
130+
// | ...| |... |
131+
// | ...| 1,1|... |
132+
// +----------+-----------------+-----------+
133+
// | ...|.................|... |
134+
// | ...|.................|... |
135+
// +----------+-----------------+-----------+
136+
//
137+
// .. = border pixels for tile 1,1
138+
// VV = interest rect (what we will record)
139+
//
140+
// The first invalidation is inside VV, so it does not touch border pixels of
141+
// tile 1,1.
142+
//
143+
// The second invalidation goes below VV into the .. border pixels of 1,1.
144+
145+
// This is the VV interest rect which will be entirely inside 1,0 and not
146+
// touch the border of 1,1.
147+
gfx::Rect interest_rect(
148+
pile_->tiling().TilePositionX(1) + pile_->tiling().border_texels(),
149+
0,
150+
10,
151+
pile_->tiling().TileSizeY(0) - pile_->tiling().border_texels());
152+
153+
// Invalidate tile 1,0 only. This is a rect that avoids the borders of any
154+
// other tiles.
155+
gfx::Rect invalidate_tile = interest_rect;
156+
// This should cause the tile 1,0 to be invalidated and re-recorded. The
157+
// invalidation did not need to be expanded.
158+
invalidation = invalidate_tile;
159+
UpdateAndExpandInvalidation(&invalidation, tiling_size(), interest_rect);
160+
EXPECT_EQ(invalidate_tile, invalidation);
161+
162+
// Invalidate tile 1,0 and 1,1 by invalidating something that only touches the
163+
// border of 1,1 (and is inside the tile bounds of 1,0). This is a 10px wide
164+
// strip from the top of the tiling onto the border pixels of tile 1,1 that
165+
// avoids border pixels of any other tiles.
166+
gfx::Rect invalidate_border = interest_rect;
167+
invalidate_border.Inset(0, 0, 0, -1);
168+
// This should cause the tile 1,0 and 1,1 to be invalidated. The 1,1 tile will
169+
// not be re-recorded since it does not touch the interest rect, so the
170+
// invalidation should be expanded to cover all of 1,1.
171+
invalidation = invalidate_border;
172+
UpdateAndExpandInvalidation(&invalidation, tiling_size(), interest_rect);
173+
Region expected_invalidation = invalidate_border;
174+
expected_invalidation.Union(pile_->tiling().TileBounds(1, 1));
175+
EXPECT_EQ(expected_invalidation.ToString(), invalidation.ToString());
176+
}
177+
102178
TEST_F(PicturePileTest, SmallInvalidateInflated) {
103179
// Invalidate something inside a tile.
104180
Region invalidate_rect(gfx::Rect(50, 50, 1, 1));

0 commit comments

Comments
 (0)