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

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

Issue 235753002: cc: Give TilingData a Rect instead of a Size (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Git cl format Created 6 years, 8 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
« no previous file with comments | « cc/resources/picture_layer_tiling.h ('k') | cc/resources/picture_layer_tiling_set.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 client)); 53 client));
54 } 54 }
55 55
56 PictureLayerTiling::PictureLayerTiling(float contents_scale, 56 PictureLayerTiling::PictureLayerTiling(float contents_scale,
57 const gfx::Size& layer_bounds, 57 const gfx::Size& layer_bounds,
58 PictureLayerTilingClient* client) 58 PictureLayerTilingClient* client)
59 : contents_scale_(contents_scale), 59 : contents_scale_(contents_scale),
60 layer_bounds_(layer_bounds), 60 layer_bounds_(layer_bounds),
61 resolution_(NON_IDEAL_RESOLUTION), 61 resolution_(NON_IDEAL_RESOLUTION),
62 client_(client), 62 client_(client),
63 tiling_data_(gfx::Size(), gfx::Size(), true), 63 tiling_data_(gfx::Size(), gfx::Rect(), true),
64 last_impl_frame_time_in_seconds_(0.0), 64 last_impl_frame_time_in_seconds_(0.0),
65 eviction_tiles_cache_valid_(false), 65 eviction_tiles_cache_valid_(false),
66 eviction_cache_tree_priority_(SAME_PRIORITY_FOR_BOTH_TREES) { 66 eviction_cache_tree_priority_(SAME_PRIORITY_FOR_BOTH_TREES) {
67 gfx::Size content_bounds = 67 gfx::Size content_bounds =
68 gfx::ToCeiledSize(gfx::ScaleSize(layer_bounds, contents_scale)); 68 gfx::ToCeiledSize(gfx::ScaleSize(layer_bounds, contents_scale));
69 gfx::Size tile_size = client_->CalculateTileSize(content_bounds); 69 gfx::Size tile_size = client_->CalculateTileSize(content_bounds);
70 70
71 DCHECK(!gfx::ToFlooredSize( 71 DCHECK(!gfx::ToFlooredSize(
72 gfx::ScaleSize(layer_bounds, contents_scale)).IsEmpty()) << 72 gfx::ScaleSize(layer_bounds, contents_scale)).IsEmpty()) <<
73 "Tiling created with scale too small as contents become empty." << 73 "Tiling created with scale too small as contents become empty." <<
74 " Layer bounds: " << layer_bounds.ToString() << 74 " Layer bounds: " << layer_bounds.ToString() <<
75 " Contents scale: " << contents_scale; 75 " Contents scale: " << contents_scale;
76 76
77 tiling_data_.SetTotalSize(content_bounds); 77 tiling_data_.SetTilingRect(gfx::Rect(content_bounds));
78 tiling_data_.SetMaxTextureSize(tile_size); 78 tiling_data_.SetMaxTextureSize(tile_size);
79 } 79 }
80 80
81 PictureLayerTiling::~PictureLayerTiling() { 81 PictureLayerTiling::~PictureLayerTiling() {
82 } 82 }
83 83
84 void PictureLayerTiling::SetClient(PictureLayerTilingClient* client) { 84 void PictureLayerTiling::SetClient(PictureLayerTilingClient* client) {
85 client_ = client; 85 client_ = client;
86 } 86 }
87 87
88 gfx::Rect PictureLayerTiling::ContentRect() const { 88 gfx::Rect PictureLayerTiling::TilingRect() const {
89 return gfx::Rect(tiling_data_.total_size()); 89 return tiling_data_.tiling_rect();
90 }
91
92 gfx::SizeF PictureLayerTiling::ContentSizeF() const {
93 return gfx::ScaleSize(layer_bounds_, contents_scale_);
94 } 90 }
95 91
96 Tile* PictureLayerTiling::CreateTile(int i, 92 Tile* PictureLayerTiling::CreateTile(int i,
97 int j, 93 int j,
98 const PictureLayerTiling* twin_tiling) { 94 const PictureLayerTiling* twin_tiling) {
99 TileMapKey key(i, j); 95 TileMapKey key(i, j);
100 DCHECK(tiles_.find(key) == tiles_.end()); 96 DCHECK(tiles_.find(key) == tiles_.end());
101 97
102 gfx::Rect paint_rect = tiling_data_.TileBoundsWithBorder(i, j); 98 gfx::Rect paint_rect = tiling_data_.TileBoundsWithBorder(i, j);
103 gfx::Rect tile_rect = paint_rect; 99 gfx::Rect tile_rect = paint_rect;
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 } 148 }
153 149
154 void PictureLayerTiling::SetLayerBounds(const gfx::Size& layer_bounds) { 150 void PictureLayerTiling::SetLayerBounds(const gfx::Size& layer_bounds) {
155 if (layer_bounds_ == layer_bounds) 151 if (layer_bounds_ == layer_bounds)
156 return; 152 return;
157 153
158 DCHECK(!layer_bounds.IsEmpty()); 154 DCHECK(!layer_bounds.IsEmpty());
159 155
160 gfx::Size old_layer_bounds = layer_bounds_; 156 gfx::Size old_layer_bounds = layer_bounds_;
161 layer_bounds_ = layer_bounds; 157 layer_bounds_ = layer_bounds;
162 gfx::Size old_content_bounds = tiling_data_.total_size();
163 gfx::Size content_bounds = 158 gfx::Size content_bounds =
164 gfx::ToCeiledSize(gfx::ScaleSize(layer_bounds_, contents_scale_)); 159 gfx::ToCeiledSize(gfx::ScaleSize(layer_bounds_, contents_scale_));
165 160
166 gfx::Size tile_size = client_->CalculateTileSize(content_bounds); 161 gfx::Size tile_size = client_->CalculateTileSize(content_bounds);
167 if (tile_size != tiling_data_.max_texture_size()) { 162 if (tile_size != tiling_data_.max_texture_size()) {
168 tiling_data_.SetTotalSize(content_bounds); 163 tiling_data_.SetTilingRect(gfx::Rect(content_bounds));
169 tiling_data_.SetMaxTextureSize(tile_size); 164 tiling_data_.SetMaxTextureSize(tile_size);
170 Reset(); 165 Reset();
171 return; 166 return;
172 } 167 }
173 168
174 // Any tiles outside our new bounds are invalid and should be dropped. 169 // Any tiles outside our new bounds are invalid and should be dropped.
175 gfx::Rect bounded_live_tiles_rect(live_tiles_rect_); 170 gfx::Rect bounded_live_tiles_rect(live_tiles_rect_);
176 bounded_live_tiles_rect.Intersect(gfx::Rect(content_bounds)); 171 bounded_live_tiles_rect.Intersect(gfx::Rect(content_bounds));
177 SetLiveTilesRect(bounded_live_tiles_rect); 172 SetLiveTilesRect(bounded_live_tiles_rect);
178 tiling_data_.SetTotalSize(content_bounds); 173 tiling_data_.SetTilingRect(gfx::Rect(content_bounds));
179 174
180 // Create tiles for newly exposed areas. 175 // Create tiles for newly exposed areas.
181 Region layer_region((gfx::Rect(layer_bounds_))); 176 Region layer_region((gfx::Rect(layer_bounds_)));
182 layer_region.Subtract(gfx::Rect(old_layer_bounds)); 177 layer_region.Subtract(gfx::Rect(old_layer_bounds));
183 Invalidate(layer_region); 178 Invalidate(layer_region);
184 } 179 }
185 180
186 void PictureLayerTiling::RemoveTilesInRegion(const Region& layer_region) { 181 void PictureLayerTiling::RemoveTilesInRegion(const Region& layer_region) {
187 DoInvalidate(layer_region, false /* recreate_tiles */); 182 DoInvalidate(layer_region, false /* recreate_tiles */);
188 } 183 }
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 tile_j_(0), 241 tile_j_(0),
247 left_(0), 242 left_(0),
248 top_(0), 243 top_(0),
249 right_(-1), 244 right_(-1),
250 bottom_(-1) { 245 bottom_(-1) {
251 DCHECK(tiling_); 246 DCHECK(tiling_);
252 if (dest_rect_.IsEmpty()) 247 if (dest_rect_.IsEmpty())
253 return; 248 return;
254 249
255 dest_to_content_scale_ = tiling_->contents_scale_ / dest_scale; 250 dest_to_content_scale_ = tiling_->contents_scale_ / dest_scale;
256 // This is the maximum size that the dest rect can be, given the content size.
257 gfx::Size dest_content_size = gfx::ToCeiledSize(gfx::ScaleSize(
258 tiling_->ContentRect().size(),
259 1 / dest_to_content_scale_,
260 1 / dest_to_content_scale_));
261 251
262 gfx::Rect content_rect = 252 gfx::Rect content_rect =
263 gfx::ScaleToEnclosingRect(dest_rect_, 253 gfx::ScaleToEnclosingRect(dest_rect_,
264 dest_to_content_scale_, 254 dest_to_content_scale_,
265 dest_to_content_scale_); 255 dest_to_content_scale_);
266 // IndexFromSrcCoord clamps to valid tile ranges, so it's necessary to 256 // IndexFromSrcCoord clamps to valid tile ranges, so it's necessary to
267 // check for non-intersection first. 257 // check for non-intersection first.
268 content_rect.Intersect(gfx::Rect(tiling_->tiling_data_.total_size())); 258 content_rect.Intersect(tiling_->TilingRect());
269 if (content_rect.IsEmpty()) 259 if (content_rect.IsEmpty())
270 return; 260 return;
271 261
272 left_ = tiling_->tiling_data_.TileXIndexFromSrcCoord(content_rect.x()); 262 left_ = tiling_->tiling_data_.TileXIndexFromSrcCoord(content_rect.x());
273 top_ = tiling_->tiling_data_.TileYIndexFromSrcCoord(content_rect.y()); 263 top_ = tiling_->tiling_data_.TileYIndexFromSrcCoord(content_rect.y());
274 right_ = tiling_->tiling_data_.TileXIndexFromSrcCoord( 264 right_ = tiling_->tiling_data_.TileXIndexFromSrcCoord(
275 content_rect.right() - 1); 265 content_rect.right() - 1);
276 bottom_ = tiling_->tiling_data_.TileYIndexFromSrcCoord( 266 bottom_ = tiling_->tiling_data_.TileYIndexFromSrcCoord(
277 content_rect.bottom() - 1); 267 content_rect.bottom() - 1);
278 268
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 350
361 gfx::RectF PictureLayerTiling::CoverageIterator::texture_rect() const { 351 gfx::RectF PictureLayerTiling::CoverageIterator::texture_rect() const {
362 gfx::PointF tex_origin = 352 gfx::PointF tex_origin =
363 tiling_->tiling_data_.TileBoundsWithBorder(tile_i_, tile_j_).origin(); 353 tiling_->tiling_data_.TileBoundsWithBorder(tile_i_, tile_j_).origin();
364 354
365 // Convert from dest space => content space => texture space. 355 // Convert from dest space => content space => texture space.
366 gfx::RectF texture_rect(current_geometry_rect_); 356 gfx::RectF texture_rect(current_geometry_rect_);
367 texture_rect.Scale(dest_to_content_scale_, 357 texture_rect.Scale(dest_to_content_scale_,
368 dest_to_content_scale_); 358 dest_to_content_scale_);
369 texture_rect.Offset(-tex_origin.OffsetFromOrigin()); 359 texture_rect.Offset(-tex_origin.OffsetFromOrigin());
370 texture_rect.Intersect(tiling_->ContentRect()); 360 texture_rect.Intersect(tiling_->TilingRect());
371 361
372 return texture_rect; 362 return texture_rect;
373 } 363 }
374 364
375 gfx::Size PictureLayerTiling::CoverageIterator::texture_size() const { 365 gfx::Size PictureLayerTiling::CoverageIterator::texture_size() const {
376 return tiling_->tiling_data_.max_texture_size(); 366 return tiling_->tiling_data_.max_texture_size();
377 } 367 }
378 368
379 void PictureLayerTiling::Reset() { 369 void PictureLayerTiling::Reset() {
380 live_tiles_rect_ = gfx::Rect(); 370 live_tiles_rect_ = gfx::Rect();
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
436 double current_frame_time_in_seconds) { 426 double current_frame_time_in_seconds) {
437 if (!NeedsUpdateForFrameAtTime(current_frame_time_in_seconds)) { 427 if (!NeedsUpdateForFrameAtTime(current_frame_time_in_seconds)) {
438 // This should never be zero for the purposes of has_ever_been_updated(). 428 // This should never be zero for the purposes of has_ever_been_updated().
439 DCHECK_NE(current_frame_time_in_seconds, 0.0); 429 DCHECK_NE(current_frame_time_in_seconds, 0.0);
440 return; 430 return;
441 } 431 }
442 432
443 gfx::Rect visible_rect_in_content_space = 433 gfx::Rect visible_rect_in_content_space =
444 gfx::ScaleToEnclosingRect(visible_layer_rect, contents_scale_); 434 gfx::ScaleToEnclosingRect(visible_layer_rect, contents_scale_);
445 435
446 if (ContentRect().IsEmpty()) { 436 if (TilingRect().IsEmpty()) {
447 last_impl_frame_time_in_seconds_ = current_frame_time_in_seconds; 437 last_impl_frame_time_in_seconds_ = current_frame_time_in_seconds;
448 last_visible_rect_in_content_space_ = visible_rect_in_content_space; 438 last_visible_rect_in_content_space_ = visible_rect_in_content_space;
449 return; 439 return;
450 } 440 }
451 441
452 size_t max_tiles_for_interest_area = client_->GetMaxTilesForInterestArea(); 442 size_t max_tiles_for_interest_area = client_->GetMaxTilesForInterestArea();
453 443
454 gfx::Size tile_size = tiling_data_.max_texture_size(); 444 gfx::Size tile_size = tiling_data_.max_texture_size();
455 int64 eventually_rect_area = 445 int64 eventually_rect_area =
456 max_tiles_for_interest_area * tile_size.width() * tile_size.height(); 446 max_tiles_for_interest_area * tile_size.width() * tile_size.height();
457 447
458 gfx::Rect skewport = ComputeSkewport(current_frame_time_in_seconds, 448 gfx::Rect skewport = ComputeSkewport(current_frame_time_in_seconds,
459 visible_rect_in_content_space); 449 visible_rect_in_content_space);
460 DCHECK(skewport.Contains(visible_rect_in_content_space)); 450 DCHECK(skewport.Contains(visible_rect_in_content_space));
461 451
462 gfx::Rect eventually_rect = 452 gfx::Rect eventually_rect =
463 ExpandRectEquallyToAreaBoundedBy(visible_rect_in_content_space, 453 ExpandRectEquallyToAreaBoundedBy(visible_rect_in_content_space,
464 eventually_rect_area, 454 eventually_rect_area,
465 ContentRect(), 455 TilingRect(),
466 &expansion_cache_); 456 &expansion_cache_);
467 457
468 DCHECK(eventually_rect.IsEmpty() || ContentRect().Contains(eventually_rect)); 458 DCHECK(eventually_rect.IsEmpty() || TilingRect().Contains(eventually_rect));
469 459
470 SetLiveTilesRect(eventually_rect); 460 SetLiveTilesRect(eventually_rect);
471 461
472 last_impl_frame_time_in_seconds_ = current_frame_time_in_seconds; 462 last_impl_frame_time_in_seconds_ = current_frame_time_in_seconds;
473 last_visible_rect_in_content_space_ = visible_rect_in_content_space; 463 last_visible_rect_in_content_space_ = visible_rect_in_content_space;
474 464
475 current_visible_rect_in_content_space_ = visible_rect_in_content_space; 465 current_visible_rect_in_content_space_ = visible_rect_in_content_space;
476 current_skewport_ = skewport; 466 current_skewport_ = skewport;
477 current_eventually_rect_ = eventually_rect; 467 current_eventually_rect_ = eventually_rect;
478 eviction_tiles_cache_valid_ = false; 468 eviction_tiles_cache_valid_ = false;
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
534 content_to_screen_scale; 524 content_to_screen_scale;
535 TilePriority priority( 525 TilePriority priority(
536 resolution_, TilePriority::EVENTUALLY, distance_to_visible); 526 resolution_, TilePriority::EVENTUALLY, distance_to_visible);
537 tile->SetPriority(tree, priority); 527 tile->SetPriority(tree, priority);
538 } 528 }
539 } 529 }
540 530
541 void PictureLayerTiling::SetLiveTilesRect( 531 void PictureLayerTiling::SetLiveTilesRect(
542 const gfx::Rect& new_live_tiles_rect) { 532 const gfx::Rect& new_live_tiles_rect) {
543 DCHECK(new_live_tiles_rect.IsEmpty() || 533 DCHECK(new_live_tiles_rect.IsEmpty() ||
544 ContentRect().Contains(new_live_tiles_rect)); 534 TilingRect().Contains(new_live_tiles_rect));
545 if (live_tiles_rect_ == new_live_tiles_rect) 535 if (live_tiles_rect_ == new_live_tiles_rect)
546 return; 536 return;
547 537
548 // Iterate to delete all tiles outside of our new live_tiles rect. 538 // Iterate to delete all tiles outside of our new live_tiles rect.
549 for (TilingData::DifferenceIterator iter(&tiling_data_, 539 for (TilingData::DifferenceIterator iter(&tiling_data_,
550 live_tiles_rect_, 540 live_tiles_rect_,
551 new_live_tiles_rect); 541 new_live_tiles_rect);
552 iter; 542 iter;
553 ++iter) { 543 ++iter) {
554 TileMapKey key(iter.index()); 544 TileMapKey key(iter.index());
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
602 void PictureLayerTiling::UpdateTilesToCurrentPile() { 592 void PictureLayerTiling::UpdateTilesToCurrentPile() {
603 for (TileMap::const_iterator it = tiles_.begin(); it != tiles_.end(); ++it) { 593 for (TileMap::const_iterator it = tiles_.begin(); it != tiles_.end(); ++it) {
604 client_->UpdatePile(it->second.get()); 594 client_->UpdatePile(it->second.get());
605 } 595 }
606 } 596 }
607 597
608 scoped_ptr<base::Value> PictureLayerTiling::AsValue() const { 598 scoped_ptr<base::Value> PictureLayerTiling::AsValue() const {
609 scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue()); 599 scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue());
610 state->SetInteger("num_tiles", tiles_.size()); 600 state->SetInteger("num_tiles", tiles_.size());
611 state->SetDouble("content_scale", contents_scale_); 601 state->SetDouble("content_scale", contents_scale_);
612 state->Set("content_bounds", 602 state->Set("tiling_rect", MathUtil::AsValue(TilingRect()).release());
613 MathUtil::AsValue(ContentRect().size()).release());
614 return state.PassAs<base::Value>(); 603 return state.PassAs<base::Value>();
615 } 604 }
616 605
617 size_t PictureLayerTiling::GPUMemoryUsageInBytes() const { 606 size_t PictureLayerTiling::GPUMemoryUsageInBytes() const {
618 size_t amount = 0; 607 size_t amount = 0;
619 for (TileMap::const_iterator it = tiles_.begin(); it != tiles_.end(); ++it) { 608 for (TileMap::const_iterator it = tiles_.begin(); it != tiles_.end(); ++it) {
620 const Tile* tile = it->second.get(); 609 const Tile* tile = it->second.get();
621 amount += tile->GPUMemoryUsageInBytes(); 610 amount += tile->GPUMemoryUsageInBytes();
622 } 611 }
623 return amount; 612 return amount;
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after
932 tiling_->UpdateEvictionCacheIfNeeded(tree_priority_); 921 tiling_->UpdateEvictionCacheIfNeeded(tree_priority_);
933 tile_iterator_ = tiling_->eviction_tiles_cache_.begin(); 922 tile_iterator_ = tiling_->eviction_tiles_cache_.begin();
934 is_valid_ = true; 923 is_valid_ = true;
935 if (tile_iterator_ != tiling_->eviction_tiles_cache_.end() && 924 if (tile_iterator_ != tiling_->eviction_tiles_cache_.end() &&
936 !(*tile_iterator_)->HasResources()) { 925 !(*tile_iterator_)->HasResources()) {
937 ++(*this); 926 ++(*this);
938 } 927 }
939 } 928 }
940 929
941 } // namespace cc 930 } // namespace cc
OLDNEW
« no previous file with comments | « cc/resources/picture_layer_tiling.h ('k') | cc/resources/picture_layer_tiling_set.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698