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

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

Issue 367833003: cc: Start using raster/eviction iterators. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: update Created 6 years, 5 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 <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 #include <limits> 9 #include <limits>
10 10
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 58
59 PictureLayerTiling::PictureLayerTiling(float contents_scale, 59 PictureLayerTiling::PictureLayerTiling(float contents_scale,
60 const gfx::Size& layer_bounds, 60 const gfx::Size& layer_bounds,
61 PictureLayerTilingClient* client) 61 PictureLayerTilingClient* client)
62 : contents_scale_(contents_scale), 62 : contents_scale_(contents_scale),
63 layer_bounds_(layer_bounds), 63 layer_bounds_(layer_bounds),
64 resolution_(NON_IDEAL_RESOLUTION), 64 resolution_(NON_IDEAL_RESOLUTION),
65 client_(client), 65 client_(client),
66 tiling_data_(gfx::Size(), gfx::Rect(), true), 66 tiling_data_(gfx::Size(), gfx::Rect(), true),
67 last_impl_frame_time_in_seconds_(0.0), 67 last_impl_frame_time_in_seconds_(0.0),
68 eviction_tiles_cache_valid_(false), 68 current_visible_rect_has_tiles_(false),
69 eviction_cache_tree_priority_(SAME_PRIORITY_FOR_BOTH_TREES) { 69 current_skewport_has_tiles_(false),
70 current_eventually_rect_has_tiles_(false),
71 current_soon_border_rect_has_tiles_(false) {
70 gfx::Size content_bounds = 72 gfx::Size content_bounds =
71 gfx::ToCeiledSize(gfx::ScaleSize(layer_bounds, contents_scale)); 73 gfx::ToCeiledSize(gfx::ScaleSize(layer_bounds, contents_scale));
72 gfx::Size tile_size = client_->CalculateTileSize(content_bounds); 74 gfx::Size tile_size = client_->CalculateTileSize(content_bounds);
73 75
74 DCHECK(!gfx::ToFlooredSize( 76 DCHECK(!gfx::ToFlooredSize(
75 gfx::ScaleSize(layer_bounds, contents_scale)).IsEmpty()) << 77 gfx::ScaleSize(layer_bounds, contents_scale)).IsEmpty()) <<
76 "Tiling created with scale too small as contents become empty." << 78 "Tiling created with scale too small as contents become empty." <<
77 " Layer bounds: " << layer_bounds.ToString() << 79 " Layer bounds: " << layer_bounds.ToString() <<
78 " Contents scale: " << contents_scale; 80 " Contents scale: " << contents_scale;
79 81
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 gfx::ScaleToEnclosingRect(paint_rect, 1.0f / contents_scale_); 113 gfx::ScaleToEnclosingRect(paint_rect, 1.0f / contents_scale_);
112 if (!client_->GetInvalidation()->Intersects(rect)) { 114 if (!client_->GetInvalidation()->Intersects(rect)) {
113 tiles_[key] = candidate_tile; 115 tiles_[key] = candidate_tile;
114 return candidate_tile; 116 return candidate_tile;
115 } 117 }
116 } 118 }
117 } 119 }
118 120
119 // Create a new tile because our twin didn't have a valid one. 121 // Create a new tile because our twin didn't have a valid one.
120 scoped_refptr<Tile> tile = client_->CreateTile(this, tile_rect); 122 scoped_refptr<Tile> tile = client_->CreateTile(this, tile_rect);
121 if (tile.get()) 123 if (tile.get()) {
124 tile->set_tiling_index(i, j);
122 tiles_[key] = tile; 125 tiles_[key] = tile;
126 }
123 return tile.get(); 127 return tile.get();
124 } 128 }
125 129
126 void PictureLayerTiling::CreateMissingTilesInLiveTilesRect() { 130 Tile* PictureLayerTiling::GetOrCreateTileAt(int i, int j) {
127 const PictureLayerTiling* twin_tiling = client_->GetTwinTiling(this); 131 Tile* existing_tile = TileAt(i, j);
128 bool include_borders = true; 132 if (existing_tile)
129 for (TilingData::Iterator iter( 133 return existing_tile;
130 &tiling_data_, live_tiles_rect_, include_borders); 134 return CreateTile(i, j, client_->GetTwinTiling(this));
131 iter;
132 ++iter) {
133 TileMapKey key = iter.index();
134 TileMap::iterator find = tiles_.find(key);
135 if (find != tiles_.end())
136 continue;
137 CreateTile(key.first, key.second, twin_tiling);
138 }
139 } 135 }
140 136
141 void PictureLayerTiling::UpdateTilesToCurrentPile( 137 void PictureLayerTiling::UpdateTilesToCurrentPile(
142 const Region& layer_invalidation, 138 const Region& layer_invalidation,
143 const gfx::Size& new_layer_bounds) { 139 const gfx::Size& new_layer_bounds) {
144 DCHECK(!new_layer_bounds.IsEmpty()); 140 DCHECK(!new_layer_bounds.IsEmpty());
145 141
146 gfx::Size old_layer_bounds = layer_bounds_; 142 gfx::Size old_layer_bounds = layer_bounds_;
147 layer_bounds_ = new_layer_bounds; 143 layer_bounds_ = new_layer_bounds;
148 144
(...skipping 17 matching lines...) Expand all
166 } else { 162 } else {
167 Invalidate(layer_invalidation); 163 Invalidate(layer_invalidation);
168 } 164 }
169 165
170 PicturePileImpl* pile = client_->GetPile(); 166 PicturePileImpl* pile = client_->GetPile();
171 for (TileMap::const_iterator it = tiles_.begin(); it != tiles_.end(); ++it) 167 for (TileMap::const_iterator it = tiles_.begin(); it != tiles_.end(); ++it)
172 it->second->set_picture_pile(pile); 168 it->second->set_picture_pile(pile);
173 } 169 }
174 170
175 void PictureLayerTiling::Invalidate(const Region& layer_region) { 171 void PictureLayerTiling::Invalidate(const Region& layer_region) {
176 std::vector<TileMapKey> new_tile_keys;
177 gfx::Rect expanded_live_tiles_rect = 172 gfx::Rect expanded_live_tiles_rect =
178 tiling_data_.ExpandRectIgnoringBordersToTileBoundsWithBorders( 173 tiling_data_.ExpandRectIgnoringBordersToTileBoundsWithBorders(
179 live_tiles_rect_); 174 live_tiles_rect_);
180 for (Region::Iterator iter(layer_region); iter.has_rect(); iter.next()) { 175 for (Region::Iterator iter(layer_region); iter.has_rect(); iter.next()) {
181 gfx::Rect layer_rect = iter.rect(); 176 gfx::Rect layer_rect = iter.rect();
182 gfx::Rect content_rect = 177 gfx::Rect content_rect =
183 gfx::ScaleToEnclosingRect(layer_rect, contents_scale_); 178 gfx::ScaleToEnclosingRect(layer_rect, contents_scale_);
184 // Avoid needless work by not bothering to invalidate where there aren't 179 // Avoid needless work by not bothering to invalidate where there aren't
185 // tiles. 180 // tiles.
186 content_rect.Intersect(expanded_live_tiles_rect); 181 content_rect.Intersect(expanded_live_tiles_rect);
187 if (content_rect.IsEmpty()) 182 if (content_rect.IsEmpty())
188 continue; 183 continue;
189 bool include_borders = true; 184 bool include_borders = true;
190 for (TilingData::Iterator iter( 185 for (TilingData::Iterator iter(
191 &tiling_data_, content_rect, include_borders); 186 &tiling_data_, content_rect, include_borders);
192 iter; 187 iter;
193 ++iter) { 188 ++iter) {
194 TileMapKey key(iter.index()); 189 TileMapKey key(iter.index());
195 TileMap::iterator find = tiles_.find(key); 190 TileMap::iterator find = tiles_.find(key);
196 if (find == tiles_.end()) 191 if (find == tiles_.end())
197 continue; 192 continue;
198 tiles_.erase(find); 193 tiles_.erase(find);
199 new_tile_keys.push_back(key);
200 }
201 }
202
203 if (!new_tile_keys.empty()) {
204 for (size_t i = 0; i < new_tile_keys.size(); ++i) {
205 // Don't try to share a tile with the twin layer, it's been invalidated so
206 // we have to make our own tile here.
207 PictureLayerTiling* twin_tiling = NULL;
208 CreateTile(new_tile_keys[i].first, new_tile_keys[i].second, twin_tiling);
209 } 194 }
210 } 195 }
211 } 196 }
212 197
198 void PictureLayerTiling::UpdateTileOcclusion(Tile* tile) {
199 if (!tile)
200 return;
201
202 bool is_occluded = occlusion_set_.count(std::make_pair(
203 tile->tiling_i_index(), tile->tiling_j_index())) != 0;
204 WhichTree tree = client_->GetTree();
205 tile->set_is_occluded(tree, is_occluded);
206 }
207
208 bool PictureLayerTiling::IsTileRequiredForActivation(Tile* tile) const {
209 if (resolution_ != HIGH_RESOLUTION)
210 return false;
211
212 WhichTree tree = client_->GetTree();
213 if (tree != PENDING_TREE)
214 return false;
215
216 if (tile->is_occluded(tree))
217 return false;
218
219 if (client_->RequiresHighResToDraw())
220 return true;
221
222 const PictureLayerTiling* twin_tiling = client_->GetTwinTiling(this);
223 if (twin_tiling) {
224 if (twin_tiling->layer_bounds() != layer_bounds())
225 return true;
226
227 if (twin_tiling->current_visible_rect_in_content_space_ !=
228 current_visible_rect_in_content_space_) {
229 return true;
230 }
231
232 Tile* twin_tile =
233 twin_tiling->TileAt(tile->tiling_i_index(), tile->tiling_j_index());
234 if (!twin_tile || twin_tile == tile)
235 return false;
236 }
237 return true;
238 }
239
213 PictureLayerTiling::CoverageIterator::CoverageIterator() 240 PictureLayerTiling::CoverageIterator::CoverageIterator()
214 : tiling_(NULL), 241 : tiling_(NULL),
215 current_tile_(NULL), 242 current_tile_(NULL),
216 tile_i_(0), 243 tile_i_(0),
217 tile_j_(0), 244 tile_j_(0),
218 left_(0), 245 left_(0),
219 top_(0), 246 top_(0),
220 right_(-1), 247 right_(-1),
221 bottom_(-1) { 248 bottom_(-1) {
222 } 249 }
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
452 TilingRect(), 479 TilingRect(),
453 &expansion_cache_); 480 &expansion_cache_);
454 481
455 DCHECK(eventually_rect.IsEmpty() || TilingRect().Contains(eventually_rect)); 482 DCHECK(eventually_rect.IsEmpty() || TilingRect().Contains(eventually_rect));
456 483
457 SetLiveTilesRect(eventually_rect); 484 SetLiveTilesRect(eventually_rect);
458 485
459 last_impl_frame_time_in_seconds_ = current_frame_time_in_seconds; 486 last_impl_frame_time_in_seconds_ = current_frame_time_in_seconds;
460 last_visible_rect_in_content_space_ = visible_rect_in_content_space; 487 last_visible_rect_in_content_space_ = visible_rect_in_content_space;
461 488
489 const gfx::Rect& tiling_rect = TilingRect();
462 current_visible_rect_in_content_space_ = visible_rect_in_content_space; 490 current_visible_rect_in_content_space_ = visible_rect_in_content_space;
491 current_visible_rect_has_tiles_ =
492 tiling_rect.Intersects(current_visible_rect_in_content_space_);
463 current_skewport_ = skewport; 493 current_skewport_ = skewport;
494 current_skewport_has_tiles_ = tiling_rect.Intersects(current_skewport_);
464 current_eventually_rect_ = eventually_rect; 495 current_eventually_rect_ = eventually_rect;
465 eviction_tiles_cache_valid_ = false; 496 current_eventually_rect_has_tiles_ =
497 tiling_rect.Intersects(current_eventually_rect_);
498 content_to_screen_scale_ = 1.0f / (contents_scale_ * ideal_contents_scale);
466 499
467 TilePriority now_priority(resolution_, TilePriority::NOW, 0); 500 current_soon_border_rect_ = visible_rect_in_content_space;
468 float content_to_screen_scale = 501 float border = kSoonBorderDistanceInScreenPixels / content_to_screen_scale_;
469 1.0f / (contents_scale_ * ideal_contents_scale); 502 current_soon_border_rect_.Inset(-border, -border, -border, -border);
503 current_soon_border_rect_has_tiles_ =
504 tiling_rect.Intersects(current_soon_border_rect_);
470 505
471 // Assign now priority to all visible tiles. 506 // Compute occluded indecies.
472 bool include_borders = true; 507 occlusion_set_.clear();
473 for (TilingData::Iterator iter( 508 if (occlusion_tracker) {
474 &tiling_data_, visible_rect_in_content_space, include_borders); 509 bool include_borders = true;
475 iter; 510 for (TilingData::Iterator iter(
476 ++iter) { 511 &tiling_data_, visible_rect_in_content_space, include_borders);
477 TileMap::iterator find = tiles_.find(iter.index()); 512 iter;
478 if (find == tiles_.end()) 513 ++iter) {
479 continue; 514 gfx::Rect paint_rect =
480 Tile* tile = find->second.get(); 515 tiling_data_.TileBoundsWithBorder(iter.index_x(), iter.index_y());
516 gfx::Rect tile_rect = paint_rect;
517 tile_rect.set_size(tiling_data_.max_texture_size());
518 gfx::Rect tile_query_rect = ScaleToEnclosingRect(
519 IntersectRects(tile_rect, visible_rect_in_content_space),
520 1.0f / contents_scale_);
521 bool is_occluded = occlusion_tracker->Occluded(
522 render_target, tile_query_rect, draw_transform);
523 if (!is_occluded)
524 continue;
481 525
482 tile->SetPriority(tree, now_priority); 526 occlusion_set_.insert(iter.index());
483
484 // Set whether tile is occluded or not.
485 bool is_occluded = false;
486 if (occlusion_tracker) {
487 gfx::Rect tile_query_rect = ScaleToEnclosingRect(
488 IntersectRects(tile->content_rect(), visible_rect_in_content_space),
489 1.0f / contents_scale_);
490 // TODO(vmpstr): Remove render_target and draw_transform from the
491 // parameters so they can be hidden from the tiling.
492 is_occluded = occlusion_tracker->Occluded(
493 render_target, tile_query_rect, draw_transform);
494 } 527 }
495 tile->set_is_occluded(tree, is_occluded);
496 }
497
498 // Assign soon priority to skewport tiles.
499 for (TilingData::DifferenceIterator iter(
500 &tiling_data_, skewport, visible_rect_in_content_space);
501 iter;
502 ++iter) {
503 TileMap::iterator find = tiles_.find(iter.index());
504 if (find == tiles_.end())
505 continue;
506 Tile* tile = find->second.get();
507
508 gfx::Rect tile_bounds =
509 tiling_data_.TileBounds(iter.index_x(), iter.index_y());
510
511 float distance_to_visible =
512 visible_rect_in_content_space.ManhattanInternalDistance(tile_bounds) *
513 content_to_screen_scale;
514
515 TilePriority priority(resolution_, TilePriority::SOON, distance_to_visible);
516 tile->SetPriority(tree, priority);
517 }
518
519 // Assign eventually priority to interest rect tiles.
520 for (TilingData::DifferenceIterator iter(
521 &tiling_data_, eventually_rect, skewport);
522 iter;
523 ++iter) {
524 TileMap::iterator find = tiles_.find(iter.index());
525 if (find == tiles_.end())
526 continue;
527 Tile* tile = find->second.get();
528
529 gfx::Rect tile_bounds =
530 tiling_data_.TileBounds(iter.index_x(), iter.index_y());
531
532 float distance_to_visible =
533 visible_rect_in_content_space.ManhattanInternalDistance(tile_bounds) *
534 content_to_screen_scale;
535 TilePriority priority(
536 resolution_, TilePriority::EVENTUALLY, distance_to_visible);
537 tile->SetPriority(tree, priority);
538 }
539
540 // Upgrade the priority on border tiles to be SOON.
541 current_soon_border_rect_ = visible_rect_in_content_space;
542 float border = kSoonBorderDistanceInScreenPixels / content_to_screen_scale;
543 current_soon_border_rect_.Inset(-border, -border, -border, -border);
544 for (TilingData::DifferenceIterator iter(
545 &tiling_data_, current_soon_border_rect_, skewport);
546 iter;
547 ++iter) {
548 TileMap::iterator find = tiles_.find(iter.index());
549 if (find == tiles_.end())
550 continue;
551 Tile* tile = find->second.get();
552
553 TilePriority priority(resolution_,
554 TilePriority::SOON,
555 tile->priority(tree).distance_to_visible);
556 tile->SetPriority(tree, priority);
557 } 528 }
558 } 529 }
559 530
531 void PictureLayerTiling::SetTileAndTwinPriority(Tile* tile) const {
532 // First update the twin if required.
533 const PictureLayerTiling* twin_tiling = client_->GetTwinTiling(this);
534 if (twin_tiling)
535 twin_tiling->SetTilePriority(tile);
536 SetTilePriority(tile);
537 }
538
539 void PictureLayerTiling::SetTilePriority(Tile* tile) const {
540 WhichTree tree = client_->GetTree();
541
542 // If we're on the pending tree, start by clearing out the required for
543 // activation flag.
544 if (tree == PENDING_TREE)
545 tile->set_required_for_activation(false);
546
547 // If this tiling doesn't have the given tile, then set default priority.
548 if (TileAt(tile->tiling_i_index(), tile->tiling_j_index()) != tile) {
549 tile->SetPriority(tree, TilePriority());
550 return;
551 }
552
553 gfx::Rect tile_bounds = tiling_data_.TileBoundsWithBorder(
554 tile->tiling_i_index(), tile->tiling_j_index());
555
556 // If we're in the now bin, set the priority and return.
557 if (current_visible_rect_in_content_space_.Intersects(tile_bounds)) {
558 tile->SetPriority(tree, TilePriority(resolution_, TilePriority::NOW, 0));
559
560 // If necessary, mark this visible tile as required for activation.
561 tile->set_required_for_activation(IsTileRequiredForActivation(tile));
562 return;
563 }
564
565 // For non-now bin, we'll need to know distance to visible.
566 float distance_to_visible =
567 current_visible_rect_in_content_space_.ManhattanInternalDistance(
568 tile_bounds) *
569 content_to_screen_scale_;
570
571 // Soon border and skewport tiles get SOON bin, otherwise they get EVENTUALLY
572 // bin.
573 if (current_soon_border_rect_.Intersects(tile_bounds) ||
574 current_skewport_.Intersects(tile_bounds)) {
575 tile->SetPriority(
576 tree,
577 TilePriority(resolution_, TilePriority::SOON, distance_to_visible));
578 return;
579 }
580
581 tile->SetPriority(
582 tree,
583 TilePriority(resolution_, TilePriority::EVENTUALLY, distance_to_visible));
584 }
585
560 void PictureLayerTiling::SetLiveTilesRect( 586 void PictureLayerTiling::SetLiveTilesRect(
561 const gfx::Rect& new_live_tiles_rect) { 587 const gfx::Rect& new_live_tiles_rect) {
562 DCHECK(new_live_tiles_rect.IsEmpty() || 588 DCHECK(new_live_tiles_rect.IsEmpty() ||
563 TilingRect().Contains(new_live_tiles_rect)); 589 TilingRect().Contains(new_live_tiles_rect));
564 if (live_tiles_rect_ == new_live_tiles_rect) 590 if (live_tiles_rect_ == new_live_tiles_rect)
565 return; 591 return;
566 592
567 // Iterate to delete all tiles outside of our new live_tiles rect. 593 // Iterate to delete all tiles outside of our new live_tiles rect.
568 for (TilingData::DifferenceIterator iter(&tiling_data_, 594 for (TilingData::DifferenceIterator iter(&tiling_data_,
569 live_tiles_rect_, 595 live_tiles_rect_,
570 new_live_tiles_rect); 596 new_live_tiles_rect);
571 iter; 597 iter;
572 ++iter) { 598 ++iter) {
573 TileMapKey key(iter.index()); 599 TileMapKey key(iter.index());
574 TileMap::iterator found = tiles_.find(key); 600 TileMap::iterator found = tiles_.find(key);
575 // If the tile was outside of the recorded region, it won't exist even 601 // If the tile was outside of the recorded region, it won't exist even
576 // though it was in the live rect. 602 // though it was in the live rect.
577 if (found != tiles_.end()) 603 if (found != tiles_.end())
578 tiles_.erase(found); 604 tiles_.erase(found);
579 } 605 }
580 606
581 const PictureLayerTiling* twin_tiling = client_->GetTwinTiling(this);
582
583 // Iterate to allocate new tiles for all regions with newly exposed area.
584 for (TilingData::DifferenceIterator iter(&tiling_data_,
585 new_live_tiles_rect,
586 live_tiles_rect_);
587 iter;
588 ++iter) {
589 TileMapKey key(iter.index());
590 CreateTile(key.first, key.second, twin_tiling);
591 }
592
593 live_tiles_rect_ = new_live_tiles_rect; 607 live_tiles_rect_ = new_live_tiles_rect;
594 } 608 }
595 609
596 void PictureLayerTiling::DidBecomeRecycled() {
597 // DidBecomeActive below will set the active priority for tiles that are
598 // still in the tree. Calling this first on an active tiling that is becoming
599 // recycled takes care of tiles that are no longer in the active tree (eg.
600 // due to a pending invalidation).
601 for (TileMap::const_iterator it = tiles_.begin(); it != tiles_.end(); ++it) {
602 it->second->SetPriority(ACTIVE_TREE, TilePriority());
603 }
604 }
605
606 void PictureLayerTiling::DidBecomeActive() { 610 void PictureLayerTiling::DidBecomeActive() {
607 PicturePileImpl* active_pile = client_->GetPile(); 611 PicturePileImpl* active_pile = client_->GetPile();
608 for (TileMap::const_iterator it = tiles_.begin(); it != tiles_.end(); ++it) { 612 for (TileMap::const_iterator it = tiles_.begin(); it != tiles_.end(); ++it) {
609 it->second->SetPriority(ACTIVE_TREE, it->second->priority(PENDING_TREE)); 613 it->second->set_required_for_activation(false);
610 it->second->SetPriority(PENDING_TREE, TilePriority());
611 614
612 // Tile holds a ref onto a picture pile. If the tile never gets invalidated 615 // Tile holds a ref onto a picture pile. If the tile never gets invalidated
613 // and recreated, then that picture pile ref could exist indefinitely. To 616 // and recreated, then that picture pile ref could exist indefinitely. To
614 // prevent this, ask the client to update the pile to its own ref. This 617 // prevent this, ask the client to update the pile to its own ref. This
615 // will cause PicturePileImpls and their clones to get deleted once the 618 // will cause PicturePileImpls and their clones to get deleted once the
616 // corresponding PictureLayerImpl and any in flight raster jobs go out of 619 // corresponding PictureLayerImpl and any in flight raster jobs go out of
617 // scope. 620 // scope.
618 it->second->set_picture_pile(active_pile); 621 it->second->set_picture_pile(active_pile);
619 } 622 }
620 } 623 }
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
780 } 783 }
781 784
782 gfx::Rect result(origin_x, origin_y, width, height); 785 gfx::Rect result(origin_x, origin_y, width, height);
783 if (cache) 786 if (cache)
784 cache->previous_result = result; 787 cache->previous_result = result;
785 return result; 788 return result;
786 } 789 }
787 790
788 void PictureLayerTiling::UpdateEvictionCacheIfNeeded( 791 void PictureLayerTiling::UpdateEvictionCacheIfNeeded(
789 TreePriority tree_priority) { 792 TreePriority tree_priority) {
790 if (eviction_tiles_cache_valid_ &&
791 eviction_cache_tree_priority_ == tree_priority)
792 return;
793 793
794 eviction_tiles_cache_.clear(); 794 eviction_tiles_cache_.clear();
795 eviction_tiles_cache_.reserve(tiles_.size()); 795 eviction_tiles_cache_.reserve(tiles_.size());
796 for (TileMap::iterator it = tiles_.begin(); it != tiles_.end(); ++it) { 796 for (TileMap::iterator it = tiles_.begin(); it != tiles_.end(); ++it) {
797 // TODO(vmpstr): This should update the priority if UpdateTilePriorities 797 UpdateTileOcclusion(it->second);
798 // changes not to do this. 798 SetTileAndTwinPriority(it->second);
799 eviction_tiles_cache_.push_back(it->second); 799 eviction_tiles_cache_.push_back(it->second);
800 } 800 }
801 801
802 std::sort(eviction_tiles_cache_.begin(), 802 std::sort(eviction_tiles_cache_.begin(),
803 eviction_tiles_cache_.end(), 803 eviction_tiles_cache_.end(),
804 TileEvictionOrder(tree_priority)); 804 TileEvictionOrder(tree_priority));
805 eviction_tiles_cache_valid_ = true;
806 eviction_cache_tree_priority_ = tree_priority;
807 } 805 }
808 806
809 PictureLayerTiling::TilingRasterTileIterator::TilingRasterTileIterator() 807 PictureLayerTiling::TilingRasterTileIterator::TilingRasterTileIterator()
810 : tiling_(NULL), current_tile_(NULL) {} 808 : tiling_(NULL), current_tile_(NULL) {}
811 809
812 PictureLayerTiling::TilingRasterTileIterator::TilingRasterTileIterator( 810 PictureLayerTiling::TilingRasterTileIterator::TilingRasterTileIterator(
813 PictureLayerTiling* tiling, 811 PictureLayerTiling* tiling,
814 WhichTree tree) 812 WhichTree tree)
815 : tiling_(tiling), 813 : tiling_(tiling),
816 type_(TilePriority::NOW), 814 type_(TilePriority::NOW),
817 visible_rect_in_content_space_(
818 tiling_->current_visible_rect_in_content_space_),
819 skewport_in_content_space_(tiling_->current_skewport_),
820 eventually_rect_in_content_space_(tiling_->current_eventually_rect_),
821 soon_border_rect_in_content_space_(tiling_->current_soon_border_rect_),
822 tree_(tree), 815 tree_(tree),
823 current_tile_(NULL), 816 current_tile_(NULL),
824 visible_iterator_(&tiling->tiling_data_,
825 visible_rect_in_content_space_,
826 true /* include_borders */),
827 spiral_iterator_(&tiling->tiling_data_,
828 skewport_in_content_space_,
829 visible_rect_in_content_space_,
830 visible_rect_in_content_space_),
831 skewport_processed_(false) { 817 skewport_processed_(false) {
818 if (tiling_->current_visible_rect_has_tiles_) {
819 visible_iterator_ =
820 TilingData::Iterator(&tiling_->tiling_data_,
821 tiling_->current_visible_rect_in_content_space_,
822 true /* include_borders */);
823 }
824
832 if (!visible_iterator_) { 825 if (!visible_iterator_) {
833 AdvancePhase(); 826 AdvancePhase();
834 return; 827 return;
835 } 828 }
836 829
837 current_tile_ = 830 current_tile_ = tiling_->GetOrCreateTileAt(visible_iterator_.index_x(),
838 tiling_->TileAt(visible_iterator_.index_x(), visible_iterator_.index_y()); 831 visible_iterator_.index_y());
839 if (!current_tile_ || !TileNeedsRaster(current_tile_)) 832 if (!current_tile_) {
840 ++(*this); 833 ++(*this);
834 } else {
835 tiling_->UpdateTileOcclusion(current_tile_);
836 if (!TileNeedsRaster(current_tile_))
837 ++(*this);
838 else
839 tiling_->SetTileAndTwinPriority(current_tile_);
840 }
841 } 841 }
842 842
843 PictureLayerTiling::TilingRasterTileIterator::~TilingRasterTileIterator() {} 843 PictureLayerTiling::TilingRasterTileIterator::~TilingRasterTileIterator() {}
844 844
845 void PictureLayerTiling::TilingRasterTileIterator::AdvancePhase() { 845 void PictureLayerTiling::TilingRasterTileIterator::AdvancePhase() {
846 DCHECK_LT(type_, TilePriority::EVENTUALLY); 846 DCHECK_LT(type_, TilePriority::EVENTUALLY);
847 DCHECK(!spiral_iterator_);
847 848
848 do { 849 do {
849 type_ = static_cast<TilePriority::PriorityBin>(type_ + 1); 850 if (type_ == TilePriority::SOON && !skewport_processed_)
850 if (type_ == TilePriority::EVENTUALLY) { 851 skewport_processed_ = true;
852 else
853 type_ = static_cast<TilePriority::PriorityBin>(type_ + 1);
854
855 if (type_ == TilePriority::SOON && !skewport_processed_) {
856 if (!tiling_->current_soon_border_rect_has_tiles_)
857 continue;
858
851 spiral_iterator_ = TilingData::SpiralDifferenceIterator( 859 spiral_iterator_ = TilingData::SpiralDifferenceIterator(
852 &tiling_->tiling_data_, 860 &tiling_->tiling_data_,
853 eventually_rect_in_content_space_, 861 tiling_->current_skewport_,
854 skewport_in_content_space_, 862 tiling_->current_visible_rect_in_content_space_,
855 visible_rect_in_content_space_); 863 tiling_->current_visible_rect_in_content_space_);
864 } else if (type_ == TilePriority::SOON && skewport_processed_) {
865 if (!tiling_->current_skewport_has_tiles_)
866 continue;
867
868 spiral_iterator_ = TilingData::SpiralDifferenceIterator(
869 &tiling_->tiling_data_,
870 tiling_->current_soon_border_rect_,
871 tiling_->current_skewport_,
872 tiling_->current_visible_rect_in_content_space_);
873 } else if (type_ == TilePriority::EVENTUALLY) {
874 if (!tiling_->current_eventually_rect_has_tiles_) {
875 current_tile_ = NULL;
876 break;
877 }
878
879 spiral_iterator_ = TilingData::SpiralDifferenceIterator(
880 &tiling_->tiling_data_,
881 tiling_->current_eventually_rect_,
882 tiling_->current_skewport_,
883 tiling_->current_soon_border_rect_);
856 } 884 }
857 885
858 while (spiral_iterator_) { 886 while (spiral_iterator_) {
859 current_tile_ = tiling_->TileAt(spiral_iterator_.index_x(), 887 current_tile_ = tiling_->GetOrCreateTileAt(spiral_iterator_.index_x(),
860 spiral_iterator_.index_y()); 888 spiral_iterator_.index_y());
889 tiling_->UpdateTileOcclusion(current_tile_);
861 if (current_tile_ && TileNeedsRaster(current_tile_)) 890 if (current_tile_ && TileNeedsRaster(current_tile_))
862 break; 891 break;
863 ++spiral_iterator_; 892 ++spiral_iterator_;
864 } 893 }
865 894
866 if (!spiral_iterator_ && type_ == TilePriority::EVENTUALLY) { 895 if (!spiral_iterator_ && type_ == TilePriority::EVENTUALLY) {
867 current_tile_ = NULL; 896 current_tile_ = NULL;
868 break; 897 break;
869 } 898 }
870 } while (!spiral_iterator_); 899 } while (!spiral_iterator_);
900
901 if (current_tile_)
902 tiling_->SetTileAndTwinPriority(current_tile_);
871 } 903 }
872 904
873 PictureLayerTiling::TilingRasterTileIterator& 905 PictureLayerTiling::TilingRasterTileIterator&
874 PictureLayerTiling::TilingRasterTileIterator:: 906 PictureLayerTiling::TilingRasterTileIterator::
875 operator++() { 907 operator++() {
876 current_tile_ = NULL; 908 current_tile_ = NULL;
877 while (!current_tile_ || !TileNeedsRaster(current_tile_)) { 909 while (!current_tile_ || !TileNeedsRaster(current_tile_)) {
878 std::pair<int, int> next_index; 910 std::pair<int, int> next_index;
879 switch (type_) { 911 switch (type_) {
880 case TilePriority::NOW: 912 case TilePriority::NOW:
881 ++visible_iterator_; 913 ++visible_iterator_;
882 if (!visible_iterator_) { 914 if (!visible_iterator_) {
883 AdvancePhase(); 915 AdvancePhase();
884 return *this; 916 return *this;
885 } 917 }
886 next_index = visible_iterator_.index(); 918 next_index = visible_iterator_.index();
887 break; 919 break;
888 case TilePriority::SOON: 920 case TilePriority::SOON:
889 ++spiral_iterator_; 921 ++spiral_iterator_;
890 if (!spiral_iterator_) { 922 if (!spiral_iterator_) {
891 if (skewport_processed_) { 923 AdvancePhase();
892 AdvancePhase(); 924 return *this;
893 return *this;
894 }
895 skewport_processed_ = true;
896 spiral_iterator_ = TilingData::SpiralDifferenceIterator(
897 &tiling_->tiling_data_,
898 soon_border_rect_in_content_space_,
899 skewport_in_content_space_,
900 visible_rect_in_content_space_);
901 if (!spiral_iterator_) {
902 AdvancePhase();
903 return *this;
904 }
905 } 925 }
906 next_index = spiral_iterator_.index(); 926 next_index = spiral_iterator_.index();
907 break; 927 break;
908 case TilePriority::EVENTUALLY: 928 case TilePriority::EVENTUALLY:
909 ++spiral_iterator_; 929 ++spiral_iterator_;
910 if (!spiral_iterator_) { 930 if (!spiral_iterator_) {
911 current_tile_ = NULL; 931 current_tile_ = NULL;
912 return *this; 932 return *this;
913 } 933 }
914 next_index = spiral_iterator_.index(); 934 next_index = spiral_iterator_.index();
915 break; 935 break;
916 } 936 }
917 current_tile_ = tiling_->TileAt(next_index.first, next_index.second); 937 current_tile_ =
938 tiling_->GetOrCreateTileAt(next_index.first, next_index.second);
939 tiling_->UpdateTileOcclusion(current_tile_);
918 } 940 }
941
942 if (current_tile_)
943 tiling_->SetTileAndTwinPriority(current_tile_);
919 return *this; 944 return *this;
920 } 945 }
921 946
922 PictureLayerTiling::TilingEvictionTileIterator::TilingEvictionTileIterator() 947 PictureLayerTiling::TilingEvictionTileIterator::TilingEvictionTileIterator()
923 : is_valid_(false), tiling_(NULL) {} 948 : is_valid_(false), tiling_(NULL) {}
924 949
925 PictureLayerTiling::TilingEvictionTileIterator::TilingEvictionTileIterator( 950 PictureLayerTiling::TilingEvictionTileIterator::TilingEvictionTileIterator(
926 PictureLayerTiling* tiling, 951 PictureLayerTiling* tiling,
927 TreePriority tree_priority) 952 TreePriority tree_priority)
928 : is_valid_(false), tiling_(tiling), tree_priority_(tree_priority) {} 953 : is_valid_(false), tiling_(tiling), tree_priority_(tree_priority) {}
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
963 tiling_->UpdateEvictionCacheIfNeeded(tree_priority_); 988 tiling_->UpdateEvictionCacheIfNeeded(tree_priority_);
964 tile_iterator_ = tiling_->eviction_tiles_cache_.begin(); 989 tile_iterator_ = tiling_->eviction_tiles_cache_.begin();
965 is_valid_ = true; 990 is_valid_ = true;
966 if (tile_iterator_ != tiling_->eviction_tiles_cache_.end() && 991 if (tile_iterator_ != tiling_->eviction_tiles_cache_.end() &&
967 !(*tile_iterator_)->HasResources()) { 992 !(*tile_iterator_)->HasResources()) {
968 ++(*this); 993 ++(*this);
969 } 994 }
970 } 995 }
971 996
972 } // namespace cc 997 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698