Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(310)

Side by Side Diff: cc/resources/picture_layer_tiling.cc

Issue 12865017: Makes tile-creation lazy (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "cc/resources/picture_layer_tiling.h" 5 #include "cc/resources/picture_layer_tiling.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 8
9 #include "base/debug/trace_event.h" 9 #include "base/debug/trace_event.h"
10 #include "cc/base/math_util.h" 10 #include "cc/base/math_util.h"
11 #include "ui/gfx/point_conversions.h" 11 #include "ui/gfx/point_conversions.h"
12 #include "ui/gfx/rect_conversions.h" 12 #include "ui/gfx/rect_conversions.h"
13 #include "ui/gfx/safe_integer_conversions.h" 13 #include "ui/gfx/safe_integer_conversions.h"
14 #include "ui/gfx/size_conversions.h" 14 #include "ui/gfx/size_conversions.h"
15 15
16 namespace cc { 16 namespace cc {
17 17
18 scoped_ptr<PictureLayerTiling> PictureLayerTiling::Create( 18 scoped_ptr<PictureLayerTiling> PictureLayerTiling::Create(
19 float contents_scale) { 19 float contents_scale) {
20 return make_scoped_ptr(new PictureLayerTiling(contents_scale)); 20 return make_scoped_ptr(new PictureLayerTiling(contents_scale));
21 } 21 }
22 22
23 scoped_ptr<PictureLayerTiling> PictureLayerTiling::Clone() const { 23 scoped_ptr<PictureLayerTiling> PictureLayerTiling::Clone() const {
24 return make_scoped_ptr(new PictureLayerTiling(*this)); 24 return make_scoped_ptr(new PictureLayerTiling(*this, 0));
25 } 25 }
26 26
27 PictureLayerTiling::PictureLayerTiling(float contents_scale) 27 PictureLayerTiling::PictureLayerTiling(float contents_scale)
28 : client_(NULL), 28 : client_(NULL),
29 contents_scale_(contents_scale), 29 contents_scale_(contents_scale),
30 tiling_data_(gfx::Size(), gfx::Size(), true), 30 tiling_data_(gfx::Size(), gfx::Size(), true),
31 resolution_(NON_IDEAL_RESOLUTION), 31 resolution_(NON_IDEAL_RESOLUTION),
32 last_source_frame_number_(0), 32 last_source_frame_number_(0),
33 last_impl_frame_time_(0) { 33 last_impl_frame_time_(0) {
34 } 34 }
35 35
36 PictureLayerTiling::PictureLayerTiling(const PictureLayerTiling& other, int)
enne (OOO) 2013/03/27 16:16:27 I'm assuming this "int" here is a way to have an o
whunt 2013/03/27 17:42:02 I agree, that's reasonable.
37 : contents_scale_(other.contents_scale_),
38 layer_bounds_(other.layer_bounds_),
39 resolution_(other.resolution_),
40 client_(other.client_),
41 tiling_data_(other.tiling_data_),
42 tiles_(),
43 interest_rect_(),
44 last_interest_rect_(other.last_interest_rect_),
45 last_source_frame_number_(other.last_source_frame_number_),
46 last_impl_frame_time_(other.last_impl_frame_time_) {
47 }
48
36 PictureLayerTiling::~PictureLayerTiling() { 49 PictureLayerTiling::~PictureLayerTiling() {
37 } 50 }
38 51
39 void PictureLayerTiling::SetClient(PictureLayerTilingClient* client) { 52 void PictureLayerTiling::SetClient(PictureLayerTilingClient* client) {
40 client_ = client; 53 client_ = client;
41 } 54 }
42 55
43 gfx::Rect PictureLayerTiling::ContentRect() const { 56 gfx::Rect PictureLayerTiling::ContentRect() const {
44 return gfx::Rect(tiling_data_.total_size()); 57 return gfx::Rect(tiling_data_.total_size());
45 } 58 }
46 59
47 gfx::SizeF PictureLayerTiling::ContentSizeF() const { 60 gfx::SizeF PictureLayerTiling::ContentSizeF() const {
48 return gfx::ScaleSize(layer_bounds_, contents_scale_); 61 return gfx::ScaleSize(layer_bounds_, contents_scale_);
49 } 62 }
50 63
51 Tile* PictureLayerTiling::TileAt(int i, int j) const { 64 Tile* PictureLayerTiling::TileAt(int i, int j) const {
52 TileMap::const_iterator iter = tiles_.find(TileMapKey(i, j)); 65 TileMap::const_iterator iter = tiles_.find(TileMapKey(i, j));
53 if (iter == tiles_.end()) 66 if (iter == tiles_.end())
54 return NULL; 67 return NULL;
55 return iter->second.get(); 68 return iter->second.get();
56 } 69 }
57 70
58 void PictureLayerTiling::CreateTile(int i, int j) { 71 void PictureLayerTiling::CreateTile(int i, int j) {
59 gfx::Rect tile_rect = tiling_data_.TileBoundsWithBorder(i, j);
60 tile_rect.set_size(tiling_data_.max_texture_size());
61 TileMapKey key(i, j); 72 TileMapKey key(i, j);
62 DCHECK(tiles_.find(key) == tiles_.end()); 73 DCHECK(tiles_.find(key) == tiles_.end());
63 scoped_refptr<Tile> tile = client_->CreateTile(this, tile_rect); 74
75 gfx::Rect paint_rect = tiling_data_.TileBoundsWithBorder(i, j);
enne (OOO) 2013/03/27 16:16:27 I don't understand this paint_rect code at all. W
whunt 2013/03/27 17:42:02 The paint rect has to do with layers that change s
enne (OOO) 2013/03/27 18:03:20 Ah, I see. Storing a paint rect on every tile sti
76 gfx::Rect tile_rect = paint_rect;
77 tile_rect.set_size(tiling_data_.max_texture_size());
78
79 TileMap::iterator found = tiles_.find(key);
80 if (found != tiles_.end()) {
81 if (found->second->paint_rect().Contains(paint_rect))
82 return;
83 tiles_.erase(found);
84 }
85
86 const PictureLayerTiling* sibling = client_->GetSibling(this);
87 if (sibling) {
88 Tile* candidate_tile = sibling->TileAt(i, j);
89 if (candidate_tile &&
90 candidate_tile->paint_rect().Contains(paint_rect) &&
91 !client_->GetInvalidation()->Intersects(paint_rect)) {
92 tiles_[key] = candidate_tile;
93 return;
94 }
95 }
96
97 scoped_refptr<Tile> tile = client_->CreateTile(this, tile_rect,
98 paint_rect);
64 if (tile) 99 if (tile)
65 tiles_[key] = tile; 100 tiles_[key] = tile;
66 } 101 }
67 102
68 Region PictureLayerTiling::OpaqueRegionInContentRect( 103 Region PictureLayerTiling::OpaqueRegionInContentRect(
69 const gfx::Rect& content_rect) const { 104 const gfx::Rect& content_rect) const {
70 Region opaque_region; 105 Region opaque_region;
71 // TODO(enne): implement me 106 // TODO(enne): implement me
72 return opaque_region; 107 return opaque_region;
73 } 108 }
74 109
75 void PictureLayerTiling::SetLayerBounds(gfx::Size layer_bounds) { 110 void PictureLayerTiling::SetLayerBounds(gfx::Size layer_bounds) {
76 if (layer_bounds_ == layer_bounds) 111 if (layer_bounds_ == layer_bounds)
77 return; 112 return;
78 113
79 gfx::Size old_layer_bounds = layer_bounds_; 114 gfx::Size old_layer_bounds = layer_bounds_;
80 layer_bounds_ = layer_bounds; 115 layer_bounds_ = layer_bounds;
116
117 // Handle the case where the new bounds are empty.
118 if (layer_bounds_.IsEmpty()) {
enne (OOO) 2013/03/27 16:16:27 I don't think you need to special case this. The
whunt 2013/03/27 17:42:02 I agree, it's not entirely necessary. The check w
119 tiles_.clear();
120 interest_rect_ = gfx::Rect();
121 tiling_data_.SetTotalSize(gfx::Size());
122 return;
123 }
124
125 // Calculate new content bounds.
81 gfx::Size old_content_bounds = tiling_data_.total_size(); 126 gfx::Size old_content_bounds = tiling_data_.total_size();
82 gfx::Size content_bounds = 127 gfx::Size content_bounds =
83 gfx::ToCeiledSize(gfx::ScaleSize(layer_bounds_, contents_scale_)); 128 gfx::ToCeiledSize(gfx::ScaleSize(layer_bounds_, contents_scale_));
84
85 tiling_data_.SetTotalSize(content_bounds); 129 tiling_data_.SetTotalSize(content_bounds);
86 if (layer_bounds_.IsEmpty()) {
87 tiles_.clear();
88 return;
89 }
90
91 gfx::Size tile_size = client_->CalculateTileSize( 130 gfx::Size tile_size = client_->CalculateTileSize(
92 tiling_data_.max_texture_size(), 131 tiling_data_.max_texture_size(),
93 content_bounds); 132 content_bounds);
133
134 // Handle the case where the size of our tiling has changed.
94 if (tile_size != tiling_data_.max_texture_size()) { 135 if (tile_size != tiling_data_.max_texture_size()) {
95 tiling_data_.SetMaxTextureSize(tile_size); 136 tiling_data_.SetMaxTextureSize(tile_size);
96 tiles_.clear(); 137 tiles_.clear();
138 interest_rect_ = gfx::Rect();
enne (OOO) 2013/03/27 16:16:27 Why does this need to happen?
whunt 2013/03/27 17:42:02 It shouldn't happen. This line was left over from
97 CreateTilesFromLayerRect(gfx::Rect(layer_bounds_)); 139 CreateTilesFromLayerRect(gfx::Rect(layer_bounds_));
98 return;
99 }
100
101 // Any tiles outside our new bounds are invalid and should be dropped.
enne (OOO) 2013/03/27 16:16:27 I think you still need this block in the SetLayerB
whunt 2013/03/27 17:42:02 The old interest rect still contains those tiles.
enne (OOO) 2013/03/27 18:03:20 It does, but when you change TilingData's total si
102 if (old_content_bounds.width() > content_bounds.width() ||
103 old_content_bounds.height() > content_bounds.height()) {
104 int right =
105 tiling_data_.TileXIndexFromSrcCoord(content_bounds.width() - 1);
106 int bottom =
107 tiling_data_.TileYIndexFromSrcCoord(content_bounds.height() - 1);
108
109 std::vector<TileMapKey> invalid_tile_keys;
110 for (TileMap::const_iterator it = tiles_.begin();
111 it != tiles_.end(); ++it) {
112 if (it->first.first > right || it->first.second > bottom)
113 invalid_tile_keys.push_back(it->first);
114 }
115 for (size_t i = 0; i < invalid_tile_keys.size(); ++i)
116 tiles_.erase(invalid_tile_keys[i]);
117 }
118
119 // Create tiles for newly exposed areas.
120 Region layer_region((gfx::Rect(layer_bounds_)));
121 layer_region.Subtract(gfx::Rect(old_layer_bounds));
122 for (Region::Iterator iter(layer_region); iter.has_rect(); iter.next()) {
123 Invalidate(iter.rect());
124 CreateTilesFromLayerRect(iter.rect());
125 } 140 }
126 } 141 }
127 142
128 void PictureLayerTiling::Invalidate(const Region& layer_invalidation) {
129 std::vector<TileMapKey> new_tiles;
130
131 for (Region::Iterator region_iter(layer_invalidation);
132 region_iter.has_rect();
133 region_iter.next()) {
134
135 gfx::Rect layer_invalidation = region_iter.rect();
136 layer_invalidation.Intersect(gfx::Rect(layer_bounds_));
137 gfx::Rect rect =
138 gfx::ToEnclosingRect(ScaleRect(layer_invalidation, contents_scale_));
139
140 for (PictureLayerTiling::Iterator tile_iter(this, contents_scale_, rect);
141 tile_iter;
142 ++tile_iter) {
143 TileMapKey key(tile_iter.tile_i_, tile_iter.tile_j_);
144 TileMap::iterator found = tiles_.find(key);
145 if (found == tiles_.end())
146 continue;
147
148 tiles_.erase(found);
149 new_tiles.push_back(key);
150 }
151 }
152
153 for (size_t i = 0; i < new_tiles.size(); ++i)
154 CreateTile(new_tiles[i].first, new_tiles[i].second);
155 }
156
157 void PictureLayerTiling::CreateTilesFromLayerRect(gfx::Rect layer_rect) { 143 void PictureLayerTiling::CreateTilesFromLayerRect(gfx::Rect layer_rect) {
158 gfx::Rect content_rect = 144 gfx::Rect content_rect =
159 gfx::ToEnclosingRect(ScaleRect(layer_rect, contents_scale_)); 145 gfx::ToEnclosingRect(ScaleRect(layer_rect, contents_scale_));
160 CreateTilesFromContentRect(content_rect); 146 CreateTilesFromContentRect(content_rect);
161 } 147 }
162 148
163 void PictureLayerTiling::CreateTilesFromContentRect(gfx::Rect content_rect) { 149 void PictureLayerTiling::CreateTilesFromContentRect(gfx::Rect content_rect) {
164 for (TilingData::Iterator iter(&tiling_data_, content_rect); iter; ++iter) { 150 for (TilingData::Iterator iter(&tiling_data_, content_rect); iter; ++iter) {
165 TileMap::iterator found = 151 TileMap::iterator found =
166 tiles_.find(TileMapKey(iter.index_x(), iter.index_y())); 152 tiles_.find(TileMapKey(iter.index_x(), iter.index_y()));
167 // Ignore any tiles that already exist. 153 // Ignore any tiles that already exist.
168 if (found != tiles_.end()) 154 if (found != tiles_.end())
169 continue; 155 continue;
170 CreateTile(iter.index_x(), iter.index_y()); 156 CreateTile(iter.index_x(), iter.index_y());
171 } 157 }
172 } 158 }
173 159
160 PictureLayerTiling::SimpleIterator::SimpleIterator(
161 const PictureLayerTiling* tiling,
162 const gfx::Rect& rect)
163 : key_(0, 0),
164 left_(0),
165 right_(0),
166 bottom_(0) {
167 DCHECK(tiling);
168 if (rect.IsEmpty())
169 return;
170
171 const TilingData& tiling_data = tiling->tiling_data_;
172 key_.first = tiling_data.TileXIndexFromSrcCoord(rect.x());
173 key_.second = tiling_data.TileYIndexFromSrcCoord(rect.y());
174 right_ = tiling_data.TileXIndexFromSrcCoord(rect.right() - 1) + 1;
175 bottom_ = tiling_data.TileYIndexFromSrcCoord(rect.bottom() - 1) + 1;
176 left_ = key_.first;
177 }
178
179 PictureLayerTiling::SimpleIterator& PictureLayerTiling::SimpleIterator::operator ++() {
180 ++key_.first;
181 if (key_.first == right_) {
182 key_.first = left_;
183 ++key_.second;
184 }
185 return *this;
186 }
187
174 PictureLayerTiling::Iterator::Iterator() 188 PictureLayerTiling::Iterator::Iterator()
175 : tiling_(NULL), 189 : tiling_(NULL),
176 current_tile_(NULL), 190 current_tile_(NULL),
177 tile_i_(0), 191 tile_i_(0),
178 tile_j_(0), 192 tile_j_(0),
179 left_(0), 193 left_(0),
180 top_(0), 194 top_(0),
181 right_(-1), 195 right_(-1),
182 bottom_(-1) { 196 bottom_(-1) {
183 } 197 }
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 float last_layer_contents_scale, 343 float last_layer_contents_scale,
330 float current_layer_contents_scale, 344 float current_layer_contents_scale,
331 const gfx::Transform& last_screen_transform, 345 const gfx::Transform& last_screen_transform,
332 const gfx::Transform& current_screen_transform, 346 const gfx::Transform& current_screen_transform,
333 int current_source_frame_number, 347 int current_source_frame_number,
334 double current_frame_time, 348 double current_frame_time,
335 bool store_screen_space_quads_on_tiles) { 349 bool store_screen_space_quads_on_tiles) {
336 if (ContentRect().IsEmpty()) 350 if (ContentRect().IsEmpty())
337 return; 351 return;
338 352
353 gfx::Rect viewport_in_content_space =
354 gfx::ToEnclosingRect(gfx::ScaleRect(viewport_in_layer_space,
355 contents_scale_));
356
357 gfx::Size tile_size = tiling_data_.max_texture_size();
358 int64 interest_rect_area =
359 TilePriority::kNumTilesToCoverWithInflatedViewportRectForPrioritization *
360 tile_size.width() * tile_size.height();
361
362 gfx::Rect interest_rect = ExpandRectEquallyToAreaBoundedBy(
363 viewport_in_content_space,
364 interest_rect_area,
365 ContentRect());
366 DCHECK(ContentRect().Contains(interest_rect));
367
368 ManageTiles(interest_rect_, interest_rect);
369 // ManageTiles(gfx::Rect(), interest_rect);
enne (OOO) 2013/03/27 16:16:27 ?
whunt 2013/03/27 17:42:02 Old debugging code, will be deleted.
370 // ManageTiles(gfx::Rect(), viewport_in_content_space);
371 interest_rect_ = interest_rect;
enne (OOO) 2013/03/27 16:16:27 I don't think you need to store this. Is last_int
whunt 2013/03/27 17:42:02 Not sure yet.
372
339 bool first_update_in_new_source_frame = 373 bool first_update_in_new_source_frame =
340 current_source_frame_number != last_source_frame_number_; 374 current_source_frame_number != last_source_frame_number_;
341 375
342 bool first_update_in_new_impl_frame = 376 bool first_update_in_new_impl_frame =
343 current_frame_time != last_impl_frame_time_; 377 current_frame_time != last_impl_frame_time_;
344 378
345 // In pending tree, this is always called. We update priorities: 379 // In pending tree, this is always called. We update priorities:
346 // - Immediately after a commit (first_update_in_new_source_frame). 380 // - Immediately after a commit (first_update_in_new_source_frame).
347 // - On animation ticks after the first frame in the tree 381 // - On animation ticks after the first frame in the tree
348 // (first_update_in_new_impl_frame). 382 // (first_update_in_new_impl_frame).
349 // In active tree, this is only called during draw. We update priorities: 383 // In active tree, this is only called during draw. We update priorities:
350 // - On draw if properties were not already computed by the pending tree 384 // - On draw if properties were not already computed by the pending tree
351 // and activated for the frame (first_update_in_new_impl_frame). 385 // and activated for the frame (first_update_in_new_impl_frame).
352 if (!first_update_in_new_impl_frame && !first_update_in_new_source_frame) 386 if (!first_update_in_new_impl_frame && !first_update_in_new_source_frame)
353 return; 387 return;
354 388
355 double time_delta = 0; 389 double time_delta = 0.0;
356 if (last_impl_frame_time_ != 0 && last_layer_bounds == current_layer_bounds) 390 if (last_impl_frame_time_ != 0.0 &&
391 last_layer_bounds == current_layer_bounds)
357 time_delta = current_frame_time - last_impl_frame_time_; 392 time_delta = current_frame_time - last_impl_frame_time_;
358 393
359 gfx::Rect viewport_in_content_space =
360 gfx::ToEnclosingRect(gfx::ScaleRect(viewport_in_layer_space,
361 contents_scale_));
362
363 gfx::Size tile_size = tiling_data_.max_texture_size();
364 int64 prioritized_rect_area =
365 TilePriority::kNumTilesToCoverWithInflatedViewportRectForPrioritization *
366 tile_size.width() * tile_size.height();
367
368 gfx::Rect prioritized_rect = ExpandRectEquallyToAreaBoundedBy(
369 viewport_in_content_space,
370 prioritized_rect_area,
371 ContentRect());
372 DCHECK(ContentRect().Contains(prioritized_rect));
373
374 // Iterate through all of the tiles that were live last frame but will 394 // Iterate through all of the tiles that were live last frame but will
375 // not be live this frame, and mark them as being dead. 395 // not be live this frame, and mark them as being dead.
376 for (TilingData::DifferenceIterator iter(&tiling_data_, 396 for (TilingData::DifferenceIterator iter(&tiling_data_,
377 last_prioritized_rect_, 397 last_interest_rect_,
378 prioritized_rect); 398 interest_rect);
379 iter; 399 iter;
380 ++iter) { 400 ++iter) {
381 TileMap::iterator find = tiles_.find(iter.index()); 401 TileMap::iterator find = tiles_.find(iter.index());
382 if (find == tiles_.end()) 402 if (find == tiles_.end())
383 continue; 403 continue;
384 404
385 TilePriority priority; 405 TilePriority priority;
386 DCHECK(!priority.is_live); 406 DCHECK(!priority.is_live);
enne (OOO) 2013/03/27 16:16:27 My expectation for this patch was that TilePriorit
387 Tile* tile = find->second.get(); 407 Tile* tile = find->second.get();
388 tile->SetPriority(tree, priority); 408 tile->SetPriority(tree, priority);
389 } 409 }
390 last_prioritized_rect_ = prioritized_rect; 410 last_interest_rect_ = interest_rect;
391 411
392 gfx::Rect view_rect(device_viewport); 412 gfx::Rect view_rect(device_viewport);
393 float current_scale = current_layer_contents_scale / contents_scale_; 413 float current_scale = current_layer_contents_scale / contents_scale_;
394 float last_scale = last_layer_contents_scale / contents_scale_; 414 float last_scale = last_layer_contents_scale / contents_scale_;
395 415
396 // Fast path tile priority calculation when both transforms are translations. 416 // Fast path tile priority calculation when both transforms are translations.
397 if (last_screen_transform.IsIdentityOrTranslation() && 417 if (last_screen_transform.IsIdentityOrTranslation() &&
398 current_screen_transform.IsIdentityOrTranslation()) 418 current_screen_transform.IsIdentityOrTranslation())
399 { 419 {
400 gfx::Vector2dF current_offset( 420 gfx::Vector2dF current_offset(
401 current_screen_transform.matrix().get(0, 3), 421 current_screen_transform.matrix().get(0, 3),
402 current_screen_transform.matrix().get(1, 3)); 422 current_screen_transform.matrix().get(1, 3));
403 gfx::Vector2dF last_offset( 423 gfx::Vector2dF last_offset(
404 last_screen_transform.matrix().get(0, 3), 424 last_screen_transform.matrix().get(0, 3),
405 last_screen_transform.matrix().get(1, 3)); 425 last_screen_transform.matrix().get(1, 3));
406 426
407 for (TilingData::Iterator iter(&tiling_data_, prioritized_rect); 427 for (TilingData::Iterator iter(&tiling_data_, interest_rect);
408 iter; ++iter) { 428 iter; ++iter) {
409 TileMap::iterator find = tiles_.find(iter.index()); 429 TileMap::iterator find = tiles_.find(iter.index());
410 if (find == tiles_.end()) 430 if (find == tiles_.end())
411 continue; 431 continue;
412 Tile* tile = find->second.get(); 432 Tile* tile = find->second.get();
413 433
414 gfx::Rect tile_bounds = 434 gfx::Rect tile_bounds =
415 tiling_data_.TileBounds(iter.index_x(), iter.index_y()); 435 tiling_data_.TileBounds(iter.index_x(), iter.index_y());
416 gfx::RectF current_screen_rect = gfx::ScaleRect( 436 gfx::RectF current_screen_rect = gfx::ScaleRect(
417 tile_bounds, 437 tile_bounds,
(...skipping 12 matching lines...) Expand all
430 last_screen_rect, current_screen_rect, time_delta, view_rect); 450 last_screen_rect, current_screen_rect, time_delta, view_rect);
431 TilePriority priority( 451 TilePriority priority(
432 resolution_, 452 resolution_,
433 time_to_visible_in_seconds, 453 time_to_visible_in_seconds,
434 distance_to_visible_in_pixels); 454 distance_to_visible_in_pixels);
435 if (store_screen_space_quads_on_tiles) 455 if (store_screen_space_quads_on_tiles)
436 priority.set_current_screen_quad(gfx::QuadF(current_screen_rect)); 456 priority.set_current_screen_quad(gfx::QuadF(current_screen_rect));
437 tile->SetPriority(tree, priority); 457 tile->SetPriority(tree, priority);
438 } 458 }
439 } else { 459 } else {
440 for (TilingData::Iterator iter(&tiling_data_, prioritized_rect); 460 for (TilingData::Iterator iter(&tiling_data_, interest_rect);
441 iter; ++iter) { 461 iter; ++iter) {
442 TileMap::iterator find = tiles_.find(iter.index()); 462 TileMap::iterator find = tiles_.find(iter.index());
443 if (find == tiles_.end()) 463 if (find == tiles_.end())
444 continue; 464 continue;
445 Tile* tile = find->second.get(); 465 Tile* tile = find->second.get();
446 466
447 gfx::Rect tile_bounds = 467 gfx::Rect tile_bounds =
448 tiling_data_.TileBounds(iter.index_x(), iter.index_y()); 468 tiling_data_.TileBounds(iter.index_x(), iter.index_y());
449 gfx::RectF current_layer_content_rect = gfx::ScaleRect( 469 gfx::RectF current_layer_content_rect = gfx::ScaleRect(
450 tile_bounds, 470 tile_bounds,
(...skipping 27 matching lines...) Expand all
478 &clipped)); 498 &clipped));
479 } 499 }
480 tile->SetPriority(tree, priority); 500 tile->SetPriority(tree, priority);
481 } 501 }
482 } 502 }
483 503
484 last_source_frame_number_ = current_source_frame_number; 504 last_source_frame_number_ = current_source_frame_number;
485 last_impl_frame_time_ = current_frame_time; 505 last_impl_frame_time_ = current_frame_time;
486 } 506 }
487 507
508 void PictureLayerTiling::ManageTiles(const gfx::Rect& old_interest_rect,
509 const gfx::Rect& new_interest_rect) {
510 if (old_interest_rect == new_interest_rect)
511 return;
512
513 Region free_region(old_interest_rect);
514 free_region.Subtract(new_interest_rect);
515
516 // Iterate to delete all tiles outside of our new interest rect.
517 for (Region::Iterator iter(free_region); iter.has_rect(); iter.next()) {
enne (OOO) 2013/03/27 16:16:27 Both of these loops look like a job for TilingData
whunt 2013/03/27 17:42:02 I'll give that a look.
518 for (SimpleIterator tile_iter(this, iter.rect()); tile_iter; ++tile_iter) {
519 TileMapKey key = *tile_iter;
520 TileMap::iterator found = tiles_.find(key);
521 if (found != tiles_.end() &&
enne (OOO) 2013/03/27 16:16:27 Did you mean || here? I think this intersects con
whunt 2013/03/27 17:42:02 No, I don't mean ||. In this case we're looking f
522 !new_interest_rect.Intersects(found->second->content_rect()))
523 tiles_.erase(found);
524 }
525 }
526
527 Region alloc_region(new_interest_rect);
528 alloc_region.Subtract(old_interest_rect);
529
530 // Iterate to allocate new tiles for all regions with newly exposed area.
531 for (Region::Iterator iter(alloc_region); iter.has_rect(); iter.next()) {
532 for (SimpleIterator tile_iter(this, iter.rect()); tile_iter; ++tile_iter) {
533 TileMapKey key = *tile_iter;
534 TileMap::iterator found = tiles_.find(key);
535 CreateTile(key.first, key.second);
536 }
537 }
538 }
539
488 void PictureLayerTiling::DidBecomeActive() { 540 void PictureLayerTiling::DidBecomeActive() {
489 for (TileMap::const_iterator it = tiles_.begin(); it != tiles_.end(); ++it) { 541 for (TileMap::const_iterator it = tiles_.begin(); it != tiles_.end(); ++it) {
490 it->second->SetPriority(ACTIVE_TREE, it->second->priority(PENDING_TREE)); 542 it->second->SetPriority(ACTIVE_TREE, it->second->priority(PENDING_TREE));
491 it->second->SetPriority(PENDING_TREE, TilePriority()); 543 it->second->SetPriority(PENDING_TREE, TilePriority());
492 544
493 // Tile holds a ref onto a picture pile. If the tile never gets invalidated 545 // Tile holds a ref onto a picture pile. If the tile never gets invalidated
494 // and recreated, then that picture pile ref could exist indefinitely. To 546 // and recreated, then that picture pile ref could exist indefinitely. To
495 // prevent this, ask the client to update the pile to its own ref. This 547 // prevent this, ask the client to update the pile to its own ref. This
496 // will cause PicturePileImpls and their clones to get deleted once the 548 // will cause PicturePileImpls and their clones to get deleted once the
497 // corresponding PictureLayerImpl and any in flight raster jobs go out of 549 // corresponding PictureLayerImpl and any in flight raster jobs go out of
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
603 655
604 // If our delta is less then our event distance, we're done. 656 // If our delta is less then our event distance, we're done.
605 if (delta < event.distance) 657 if (delta < event.distance)
606 break; 658 break;
607 } 659 }
608 660
609 return gfx::Rect(origin_x, origin_y, width, height); 661 return gfx::Rect(origin_x, origin_y, width, height);
610 } 662 }
611 663
612 } // namespace cc 664 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698