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

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

Powered by Google App Engine
This is Rietveld 408576698