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

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

Powered by Google App Engine
This is Rietveld 408576698