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

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

Issue 62283012: cc: Added tile bundles (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 1 month 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
11 #include "base/debug/trace_event.h" 11 #include "base/debug/trace_event.h"
12 #include "cc/base/math_util.h" 12 #include "cc/base/math_util.h"
13 #include "ui/gfx/point_conversions.h" 13 #include "ui/gfx/point_conversions.h"
14 #include "ui/gfx/rect_conversions.h" 14 #include "ui/gfx/rect_conversions.h"
15 #include "ui/gfx/safe_integer_conversions.h" 15 #include "ui/gfx/safe_integer_conversions.h"
16 #include "ui/gfx/size_conversions.h" 16 #include "ui/gfx/size_conversions.h"
17 17
18 namespace cc { 18 namespace cc {
19 19
20 namespace {
21
22 const int kTileBundleWidth = 2;
23 const int kTileBundleHeight = 2;
24
25 std::pair<int, int> ComputeTileBundleIndex(int i, int j) {
26 return std::make_pair(i / kTileBundleWidth, j / kTileBundleHeight);
27 }
28
29 }
30
20 scoped_ptr<PictureLayerTiling> PictureLayerTiling::Create( 31 scoped_ptr<PictureLayerTiling> PictureLayerTiling::Create(
21 float contents_scale, 32 float contents_scale,
22 gfx::Size layer_bounds, 33 gfx::Size layer_bounds,
23 PictureLayerTilingClient* client) { 34 PictureLayerTilingClient* client) {
24 return make_scoped_ptr(new PictureLayerTiling(contents_scale, 35 return make_scoped_ptr(new PictureLayerTiling(contents_scale,
25 layer_bounds, 36 layer_bounds,
26 client)); 37 client));
27 } 38 }
28 39
29 PictureLayerTiling::PictureLayerTiling(float contents_scale, 40 PictureLayerTiling::PictureLayerTiling(float contents_scale,
30 gfx::Size layer_bounds, 41 gfx::Size layer_bounds,
31 PictureLayerTilingClient* client) 42 PictureLayerTilingClient* client)
32 : contents_scale_(contents_scale), 43 : contents_scale_(contents_scale),
33 layer_bounds_(layer_bounds), 44 layer_bounds_(layer_bounds),
34 resolution_(NON_IDEAL_RESOLUTION), 45 resolution_(NON_IDEAL_RESOLUTION),
35 client_(client), 46 client_(client),
36 tiling_data_(gfx::Size(), gfx::Size(), true), 47 tiling_data_(gfx::Size(), gfx::Size(), true),
48 bundle_tiling_data_(gfx::Size(), gfx::Size(), true),
37 last_impl_frame_time_in_seconds_(0.0) { 49 last_impl_frame_time_in_seconds_(0.0) {
38 gfx::Size content_bounds = 50 gfx::Size content_bounds =
39 gfx::ToCeiledSize(gfx::ScaleSize(layer_bounds, contents_scale)); 51 gfx::ToCeiledSize(gfx::ScaleSize(layer_bounds, contents_scale));
40 gfx::Size tile_size = client_->CalculateTileSize(content_bounds); 52 gfx::Size tile_size = client_->CalculateTileSize(content_bounds);
41 53
42 DCHECK(!gfx::ToFlooredSize( 54 DCHECK(!gfx::ToFlooredSize(
43 gfx::ScaleSize(layer_bounds, contents_scale)).IsEmpty()) << 55 gfx::ScaleSize(layer_bounds, contents_scale)).IsEmpty()) <<
44 "Tiling created with scale too small as contents become empty." << 56 "Tiling created with scale too small as contents become empty." <<
45 " Layer bounds: " << layer_bounds.ToString() << 57 " Layer bounds: " << layer_bounds.ToString() <<
46 " Contents scale: " << contents_scale; 58 " Contents scale: " << contents_scale;
47 59
48 tiling_data_.SetTotalSize(content_bounds); 60 tiling_data_.SetTotalSize(content_bounds);
49 tiling_data_.SetMaxTextureSize(tile_size); 61 tiling_data_.SetMaxTextureSize(tile_size);
62 bundle_tiling_data_.SetTotalSize(content_bounds);
63 bundle_tiling_data_.SetMaxTextureSize(
64 gfx::Size(tile_size.width() * kTileBundleWidth,
65 tile_size.height() * kTileBundleHeight));
50 } 66 }
51 67
52 PictureLayerTiling::~PictureLayerTiling() { 68 PictureLayerTiling::~PictureLayerTiling() {
53 } 69 }
54 70
55 void PictureLayerTiling::SetClient(PictureLayerTilingClient* client) { 71 void PictureLayerTiling::SetClient(PictureLayerTilingClient* client) {
56 client_ = client; 72 client_ = client;
73 for (TileBundleMap::iterator it = tile_bundles_.begin();
74 it != tile_bundles_.end();
75 ++it) {
76 it->second->SetClient(client_);
77 }
57 } 78 }
58 79
59 gfx::Rect PictureLayerTiling::ContentRect() const { 80 gfx::Rect PictureLayerTiling::ContentRect() const {
60 return gfx::Rect(tiling_data_.total_size()); 81 return gfx::Rect(tiling_data_.total_size());
61 } 82 }
62 83
63 gfx::SizeF PictureLayerTiling::ContentSizeF() const { 84 gfx::SizeF PictureLayerTiling::ContentSizeF() const {
64 return gfx::ScaleSize(layer_bounds_, contents_scale_); 85 return gfx::ScaleSize(layer_bounds_, contents_scale_);
65 } 86 }
66 87
88 TileBundle* PictureLayerTiling::CreateBundleForTileAt(int i, int j) {
89 TileBundleMapKey key = ComputeTileBundleIndex(i, j);
90 DCHECK(tile_bundles_.find(key) == tile_bundles_.end());
91
92 scoped_refptr<TileBundle> bundle =
93 client_->CreateTileBundle(kTileBundleWidth,
94 kTileBundleHeight,
95 key.first * kTileBundleWidth,
96 key.second * kTileBundleHeight);
97 bundle->SetTiling(this);
98 tile_bundles_[key] = bundle;
99 return bundle.get();
100 }
101
102 TileBundle* PictureLayerTiling::TileBundleContainingTileAt(int i, int j) const {
103 TileBundleMapKey key = ComputeTileBundleIndex(i, j);
104 return TileBundleAt(key.first, key.second);
105 }
106
107 TileBundle* PictureLayerTiling::TileBundleAt(int i, int j) const {
108 TileBundleMapKey key(i, j);
109 TileBundleMap::const_iterator it = tile_bundles_.find(key);
110 if (it == tile_bundles_.end())
111 return NULL;
112 return it->second.get();
113 }
114
67 Tile* PictureLayerTiling::TileAt(int i, int j) const { 115 Tile* PictureLayerTiling::TileAt(int i, int j) const {
68 TileMap::const_iterator iter = tiles_.find(TileMapKey(i, j)); 116 TileBundle* bundle = TileBundleContainingTileAt(i, j);
69 if (iter == tiles_.end()) 117 if (!bundle)
70 return NULL; 118 return NULL;
71 return iter->second.get(); 119 return bundle->TileAt(i, j);
72 } 120 }
73 121
74 void PictureLayerTiling::CreateTile(int i, 122 void PictureLayerTiling::CreateTile(int i,
75 int j, 123 int j,
76 const PictureLayerTiling* twin_tiling) { 124 const PictureLayerTiling* twin_tiling) {
77 TileMapKey key(i, j); 125 TileBundle* bundle = TileBundleContainingTileAt(i, j);
78 DCHECK(tiles_.find(key) == tiles_.end()); 126 if (!bundle)
127 bundle = CreateBundleForTileAt(i, j);
79 128
80 gfx::Rect paint_rect = tiling_data_.TileBoundsWithBorder(i, j); 129 gfx::Rect paint_rect = tiling_data_.TileBoundsWithBorder(i, j);
81 gfx::Rect tile_rect = paint_rect; 130 gfx::Rect tile_rect = paint_rect;
82 tile_rect.set_size(tiling_data_.max_texture_size()); 131 tile_rect.set_size(tiling_data_.max_texture_size());
83 132
84 // Check our twin for a valid tile. 133 // Check our twin for a valid tile.
85 if (twin_tiling && 134 if (twin_tiling &&
86 tiling_data_.max_texture_size() == 135 tiling_data_.max_texture_size() ==
87 twin_tiling->tiling_data_.max_texture_size()) { 136 twin_tiling->tiling_data_.max_texture_size()) {
88 if (Tile* candidate_tile = twin_tiling->TileAt(i, j)) { 137 if (Tile* candidate_tile = twin_tiling->TileAt(i, j)) {
89 gfx::Rect rect = 138 gfx::Rect rect =
90 gfx::ScaleToEnclosingRect(paint_rect, 1.0f / contents_scale_); 139 gfx::ScaleToEnclosingRect(paint_rect, 1.0f / contents_scale_);
91 if (!client_->GetInvalidation()->Intersects(rect)) { 140 if (!client_->GetInvalidation()->Intersects(rect)) {
92 tiles_[key] = candidate_tile; 141 bundle->AddTileAt(i, j, candidate_tile);
93 return; 142 return;
94 } 143 }
95 } 144 }
96 } 145 }
97 146
98 // Create a new tile because our twin didn't have a valid one. 147 // Create a new tile because our twin didn't have a valid one.
99 scoped_refptr<Tile> tile = client_->CreateTile(this, tile_rect); 148 scoped_refptr<Tile> tile = client_->CreateTile(this, tile_rect);
100 if (tile.get()) 149 if (tile.get())
101 tiles_[key] = tile; 150 bundle->AddTileAt(i, j, tile);
151 }
152
153 bool PictureLayerTiling::RemoveTile(int i, int j) {
154 TileBundleMapKey key = ComputeTileBundleIndex(i, j);
155 TileBundleMap::iterator it = tile_bundles_.find(key);
156 if (it == tile_bundles_.end())
157 return false;
158
159 bool did_delete = it->second->RemoveTileAt(i, j);
160 if (it->second->TileCount() == 0)
161 tile_bundles_.erase(it);
162 return did_delete;
102 } 163 }
103 164
104 Region PictureLayerTiling::OpaqueRegionInContentRect( 165 Region PictureLayerTiling::OpaqueRegionInContentRect(
105 gfx::Rect content_rect) const { 166 gfx::Rect content_rect) const {
106 Region opaque_region; 167 Region opaque_region;
107 // TODO(enne): implement me 168 // TODO(enne): implement me
108 return opaque_region; 169 return opaque_region;
109 } 170 }
110 171
111 void PictureLayerTiling::SetCanUseLCDText(bool can_use_lcd_text) { 172 void PictureLayerTiling::SetCanUseLCDText(bool can_use_lcd_text) {
112 for (TileMap::iterator it = tiles_.begin(); it != tiles_.end(); ++it) 173 for (TileBundleMap::iterator it = tile_bundles_.begin();
113 it->second->set_can_use_lcd_text(can_use_lcd_text); 174 it != tile_bundles_.end();
175 ++it) {
176 for (TileBundle::Iterator tile_it(it->second); tile_it; ++tile_it)
177 tile_it->set_can_use_lcd_text(can_use_lcd_text);
178 }
114 } 179 }
115 180
116 void PictureLayerTiling::CreateMissingTilesInLiveTilesRect() { 181 void PictureLayerTiling::CreateMissingTilesInLiveTilesRect() {
117 const PictureLayerTiling* twin_tiling = client_->GetTwinTiling(this); 182 const PictureLayerTiling* twin_tiling = client_->GetTwinTiling(this);
118 for (TilingData::Iterator iter(&tiling_data_, live_tiles_rect_); iter; 183 for (TilingData::Iterator iter(&tiling_data_, live_tiles_rect_); iter;
119 ++iter) { 184 ++iter) {
120 TileMapKey key = iter.index(); 185 int tile_x = iter.index_x();
121 TileMap::iterator find = tiles_.find(key); 186 int tile_y = iter.index_y();
122 if (find != tiles_.end()) 187 Tile* tile = TileAt(tile_x, tile_y);
188 if (tile)
123 continue; 189 continue;
124 CreateTile(key.first, key.second, twin_tiling); 190 CreateTile(tile_x, tile_y, twin_tiling);
125 } 191 }
126 } 192 }
127 193
128 void PictureLayerTiling::SetLayerBounds(gfx::Size layer_bounds) { 194 void PictureLayerTiling::SetLayerBounds(gfx::Size layer_bounds) {
129 if (layer_bounds_ == layer_bounds) 195 if (layer_bounds_ == layer_bounds)
130 return; 196 return;
131 197
132 DCHECK(!layer_bounds.IsEmpty()); 198 DCHECK(!layer_bounds.IsEmpty());
133 199
134 gfx::Size old_layer_bounds = layer_bounds_; 200 gfx::Size old_layer_bounds = layer_bounds_;
135 layer_bounds_ = layer_bounds; 201 layer_bounds_ = layer_bounds;
136 gfx::Size old_content_bounds = tiling_data_.total_size(); 202 gfx::Size old_content_bounds = tiling_data_.total_size();
137 gfx::Size content_bounds = 203 gfx::Size content_bounds =
138 gfx::ToCeiledSize(gfx::ScaleSize(layer_bounds_, contents_scale_)); 204 gfx::ToCeiledSize(gfx::ScaleSize(layer_bounds_, contents_scale_));
139 205
140 gfx::Size tile_size = client_->CalculateTileSize(content_bounds); 206 gfx::Size tile_size = client_->CalculateTileSize(content_bounds);
141 if (tile_size != tiling_data_.max_texture_size()) { 207 if (tile_size != tiling_data_.max_texture_size()) {
142 tiling_data_.SetTotalSize(content_bounds); 208 tiling_data_.SetTotalSize(content_bounds);
143 tiling_data_.SetMaxTextureSize(tile_size); 209 tiling_data_.SetMaxTextureSize(tile_size);
210 bundle_tiling_data_.SetTotalSize(content_bounds);
211 bundle_tiling_data_.SetMaxTextureSize(
212 gfx::Size(tile_size.width() * kTileBundleWidth,
213 tile_size.height() * kTileBundleHeight));
144 Reset(); 214 Reset();
145 return; 215 return;
146 } 216 }
147 217
148 // Any tiles outside our new bounds are invalid and should be dropped. 218 // Any tiles outside our new bounds are invalid and should be dropped.
149 gfx::Rect bounded_live_tiles_rect(live_tiles_rect_); 219 gfx::Rect bounded_live_tiles_rect(live_tiles_rect_);
150 bounded_live_tiles_rect.Intersect(gfx::Rect(content_bounds)); 220 bounded_live_tiles_rect.Intersect(gfx::Rect(content_bounds));
151 SetLiveTilesRect(bounded_live_tiles_rect); 221 SetLiveTilesRect(bounded_live_tiles_rect);
152 tiling_data_.SetTotalSize(content_bounds); 222 tiling_data_.SetTotalSize(content_bounds);
223 bundle_tiling_data_.SetTotalSize(content_bounds);
153 224
154 // Create tiles for newly exposed areas. 225 // Create tiles for newly exposed areas.
155 Region layer_region((gfx::Rect(layer_bounds_))); 226 Region layer_region((gfx::Rect(layer_bounds_)));
156 layer_region.Subtract(gfx::Rect(old_layer_bounds)); 227 layer_region.Subtract(gfx::Rect(old_layer_bounds));
157 Invalidate(layer_region); 228 Invalidate(layer_region);
158 } 229 }
159 230
160 void PictureLayerTiling::Invalidate(const Region& layer_region) { 231 void PictureLayerTiling::Invalidate(const Region& layer_region) {
161 std::vector<TileMapKey> new_tile_keys; 232 std::vector<std::pair<int, int> > new_tile_keys;
162 for (Region::Iterator iter(layer_region); iter.has_rect(); iter.next()) { 233 for (Region::Iterator iter(layer_region); iter.has_rect(); iter.next()) {
163 gfx::Rect layer_rect = iter.rect(); 234 gfx::Rect layer_rect = iter.rect();
164 gfx::Rect content_rect = 235 gfx::Rect content_rect =
165 gfx::ScaleToEnclosingRect(layer_rect, contents_scale_); 236 gfx::ScaleToEnclosingRect(layer_rect, contents_scale_);
166 content_rect.Intersect(live_tiles_rect_); 237 content_rect.Intersect(live_tiles_rect_);
167 if (content_rect.IsEmpty()) 238 if (content_rect.IsEmpty())
168 continue; 239 continue;
169 for (TilingData::Iterator iter(&tiling_data_, content_rect); iter; ++iter) { 240 for (TilingData::Iterator iter(&tiling_data_, content_rect); iter; ++iter) {
170 TileMapKey key(iter.index()); 241 int tile_x = iter.index_x();
171 TileMap::iterator find = tiles_.find(key); 242 int tile_y = iter.index_y();
172 if (find == tiles_.end()) 243
173 continue; 244 // If there is no bundle for the given tile, we can skip.
174 tiles_.erase(find); 245 bool deleted = RemoveTile(tile_x, tile_y);
175 new_tile_keys.push_back(key); 246 if (deleted)
247 new_tile_keys.push_back(std::make_pair(tile_x, tile_y));
176 } 248 }
177 } 249 }
178 250
179 const PictureLayerTiling* twin_tiling = client_->GetTwinTiling(this); 251 const PictureLayerTiling* twin_tiling = client_->GetTwinTiling(this);
180 for (size_t i = 0; i < new_tile_keys.size(); ++i) 252 for (size_t i = 0; i < new_tile_keys.size(); ++i)
181 CreateTile(new_tile_keys[i].first, new_tile_keys[i].second, twin_tiling); 253 CreateTile(new_tile_keys[i].first, new_tile_keys[i].second, twin_tiling);
182 } 254 }
183 255
184 PictureLayerTiling::CoverageIterator::CoverageIterator() 256 PictureLayerTiling::CoverageIterator::CoverageIterator()
185 : tiling_(NULL), 257 : tiling_(NULL),
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 return current_geometry_rect_; 381 return current_geometry_rect_;
310 } 382 }
311 383
312 gfx::Rect 384 gfx::Rect
313 PictureLayerTiling::CoverageIterator::full_tile_geometry_rect() const { 385 PictureLayerTiling::CoverageIterator::full_tile_geometry_rect() const {
314 gfx::Rect rect = tiling_->tiling_data_.TileBoundsWithBorder(tile_i_, tile_j_); 386 gfx::Rect rect = tiling_->tiling_data_.TileBoundsWithBorder(tile_i_, tile_j_);
315 rect.set_size(tiling_->tiling_data_.max_texture_size()); 387 rect.set_size(tiling_->tiling_data_.max_texture_size());
316 return rect; 388 return rect;
317 } 389 }
318 390
391 TilePriority PictureLayerTiling::CoverageIterator::priority() {
392 TileBundle* bundle = tiling_->TileBundleContainingTileAt(tile_i_, tile_j_);
393 if (bundle)
394 return bundle->GetPriority();
395 return TilePriority();
396 }
397
398 void PictureLayerTiling::CoverageIterator::SetPriorityForTesting(
399 const TilePriority& priority) {
400 TileBundle* bundle = tiling_->TileBundleContainingTileAt(tile_i_, tile_j_);
401 bundle->SetPriority(priority);
402 }
403
319 gfx::RectF PictureLayerTiling::CoverageIterator::texture_rect() const { 404 gfx::RectF PictureLayerTiling::CoverageIterator::texture_rect() const {
320 gfx::PointF tex_origin = 405 gfx::PointF tex_origin =
321 tiling_->tiling_data_.TileBoundsWithBorder(tile_i_, tile_j_).origin(); 406 tiling_->tiling_data_.TileBoundsWithBorder(tile_i_, tile_j_).origin();
322 407
323 // Convert from dest space => content space => texture space. 408 // Convert from dest space => content space => texture space.
324 gfx::RectF texture_rect(current_geometry_rect_); 409 gfx::RectF texture_rect(current_geometry_rect_);
325 texture_rect.Scale(dest_to_content_scale_, 410 texture_rect.Scale(dest_to_content_scale_,
326 dest_to_content_scale_); 411 dest_to_content_scale_);
327 texture_rect.Offset(-tex_origin.OffsetFromOrigin()); 412 texture_rect.Offset(-tex_origin.OffsetFromOrigin());
328 texture_rect.Intersect(tiling_->ContentRect()); 413 texture_rect.Intersect(tiling_->ContentRect());
329 414
330 return texture_rect; 415 return texture_rect;
331 } 416 }
332 417
333 gfx::Size PictureLayerTiling::CoverageIterator::texture_size() const { 418 gfx::Size PictureLayerTiling::CoverageIterator::texture_size() const {
334 return tiling_->tiling_data_.max_texture_size(); 419 return tiling_->tiling_data_.max_texture_size();
335 } 420 }
336 421
337 void PictureLayerTiling::Reset() { 422 void PictureLayerTiling::Reset() {
338 live_tiles_rect_ = gfx::Rect(); 423 live_tiles_rect_ = gfx::Rect();
339 tiles_.clear(); 424 tile_bundles_.clear();
340 } 425 }
341 426
342 void PictureLayerTiling::UpdateTilePriorities( 427 void PictureLayerTiling::UpdateTilePriorities(
343 WhichTree tree, 428 WhichTree tree,
344 gfx::Size device_viewport, 429 gfx::Size device_viewport,
345 gfx::Rect viewport_in_layer_space, 430 gfx::Rect viewport_in_layer_space,
346 gfx::Rect visible_layer_rect, 431 gfx::Rect visible_layer_rect,
347 gfx::Size last_layer_bounds, 432 gfx::Size last_layer_bounds,
348 gfx::Size current_layer_bounds, 433 gfx::Size current_layer_bounds,
349 float last_layer_contents_scale, 434 float last_layer_contents_scale,
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 std::numeric_limits<float>::epsilon()) && 485 std::numeric_limits<float>::epsilon()) &&
401 current_screen_transform.IsApproximatelyIdentityOrTranslation( 486 current_screen_transform.IsApproximatelyIdentityOrTranslation(
402 std::numeric_limits<float>::epsilon())) { 487 std::numeric_limits<float>::epsilon())) {
403 gfx::Vector2dF current_offset( 488 gfx::Vector2dF current_offset(
404 current_screen_transform.matrix().get(0, 3), 489 current_screen_transform.matrix().get(0, 3),
405 current_screen_transform.matrix().get(1, 3)); 490 current_screen_transform.matrix().get(1, 3));
406 gfx::Vector2dF last_offset( 491 gfx::Vector2dF last_offset(
407 last_screen_transform.matrix().get(0, 3), 492 last_screen_transform.matrix().get(0, 3),
408 last_screen_transform.matrix().get(1, 3)); 493 last_screen_transform.matrix().get(1, 3));
409 494
410 for (TilingData::Iterator iter(&tiling_data_, interest_rect); 495 for (TilingData::Iterator iter(&bundle_tiling_data_, interest_rect);
411 iter; ++iter) { 496 iter; ++iter) {
412 TileMap::iterator find = tiles_.find(iter.index()); 497 int bundle_x = iter.index_x();
413 if (find == tiles_.end()) 498 int bundle_y = iter.index_y();
499 TileBundle* bundle = TileBundleAt(bundle_x, bundle_y);
500 if (!bundle)
414 continue; 501 continue;
415 Tile* tile = find->second.get();
416 502
417 gfx::Rect tile_bounds = 503 gfx::Rect bundle_bounds =
418 tiling_data_.TileBounds(iter.index_x(), iter.index_y()); 504 bundle_tiling_data_.TileBounds(bundle_x, bundle_y);
419 gfx::RectF current_screen_rect = gfx::ScaleRect( 505 gfx::RectF current_screen_rect =
420 tile_bounds, 506 gfx::ScaleRect(bundle_bounds, current_scale, current_scale) +
421 current_scale, 507 current_offset;
422 current_scale) + current_offset; 508 gfx::RectF last_screen_rect =
423 gfx::RectF last_screen_rect = gfx::ScaleRect( 509 gfx::ScaleRect(bundle_bounds, last_scale, last_scale) +
424 tile_bounds, 510 last_offset;
425 last_scale,
426 last_scale) + last_offset;
427 511
428 float distance_to_visible_in_pixels = 512 float distance_to_visible_in_pixels =
429 TilePriority::manhattanDistance(current_screen_rect, view_rect); 513 TilePriority::manhattanDistance(current_screen_rect, view_rect);
430 514
431 float time_to_visible_in_seconds = 515 float time_to_visible_in_seconds =
432 TilePriority::TimeForBoundsToIntersect( 516 TilePriority::TimeForBoundsToIntersect(
433 last_screen_rect, current_screen_rect, time_delta, view_rect); 517 last_screen_rect, current_screen_rect, time_delta, view_rect);
434 TilePriority priority( 518 TilePriority priority(
435 resolution_, 519 resolution_,
436 time_to_visible_in_seconds, 520 time_to_visible_in_seconds,
437 distance_to_visible_in_pixels); 521 distance_to_visible_in_pixels);
438 tile->SetPriority(tree, priority); 522
523 bundle->SetPriority(priority);
439 } 524 }
440 } else if (!last_screen_transform.HasPerspective() && 525 } else if (!last_screen_transform.HasPerspective() &&
441 !current_screen_transform.HasPerspective()) { 526 !current_screen_transform.HasPerspective()) {
442 // Secondary fast path that can be applied for any affine transforms. 527 // Secondary fast path that can be applied for any affine transforms.
443 528
444 // Initialize the necessary geometry in screen space, so that we can 529 // Initialize the necessary geometry in screen space, so that we can
445 // iterate over tiles in screen space without needing a costly transform 530 // iterate over tiles in screen space without needing a costly transform
446 // mapping for each tile. 531 // mapping for each tile.
447 532
448 // Apply screen space transform to the local origin point (0, 0); only the 533 // Apply screen space transform to the local origin point (0, 0); only the
449 // translation component is needed and can be initialized directly. 534 // translation component is needed and can be initialized directly.
450 gfx::Point current_screen_space_origin( 535 gfx::Point current_screen_space_origin(
451 current_screen_transform.matrix().get(0, 3), 536 current_screen_transform.matrix().get(0, 3),
452 current_screen_transform.matrix().get(1, 3)); 537 current_screen_transform.matrix().get(1, 3));
453 538
454 gfx::Point last_screen_space_origin( 539 gfx::Point last_screen_space_origin(
455 last_screen_transform.matrix().get(0, 3), 540 last_screen_transform.matrix().get(0, 3),
456 last_screen_transform.matrix().get(1, 3)); 541 last_screen_transform.matrix().get(1, 3));
457 542
458 float current_tile_width = tiling_data_.TileSizeX(0) * current_scale; 543 float current_bundle_width =
459 float last_tile_width = tiling_data_.TileSizeX(0) * last_scale; 544 bundle_tiling_data_.TileSizeX(0) * current_scale;
460 float current_tile_height = tiling_data_.TileSizeY(0) * current_scale; 545 float last_bundle_width =
461 float last_tile_height = tiling_data_.TileSizeY(0) * last_scale; 546 bundle_tiling_data_.TileSizeX(0) * last_scale;
547 float current_bundle_height =
548 bundle_tiling_data_.TileSizeY(0) * current_scale;
549 float last_bundle_height =
550 bundle_tiling_data_.TileSizeY(0) * last_scale;
462 551
463 // Apply screen space transform to local basis vectors (tile_width, 0) and 552 // Apply screen space transform to local basis vectors (tile_width, 0) and
464 // (0, tile_height); the math simplifies and can be initialized directly. 553 // (0, tile_height); the math simplifies and can be initialized directly.
465 gfx::Vector2dF current_horizontal( 554 gfx::Vector2dF current_horizontal(
466 current_screen_transform.matrix().get(0, 0) * current_tile_width, 555 current_screen_transform.matrix().get(0, 0) * current_bundle_width,
467 current_screen_transform.matrix().get(1, 0) * current_tile_width); 556 current_screen_transform.matrix().get(1, 0) * current_bundle_width);
468 gfx::Vector2dF current_vertical( 557 gfx::Vector2dF current_vertical(
469 current_screen_transform.matrix().get(0, 1) * current_tile_height, 558 current_screen_transform.matrix().get(0, 1) * current_bundle_height,
470 current_screen_transform.matrix().get(1, 1) * current_tile_height); 559 current_screen_transform.matrix().get(1, 1) * current_bundle_height);
471 560
472 gfx::Vector2dF last_horizontal( 561 gfx::Vector2dF last_horizontal(
473 last_screen_transform.matrix().get(0, 0) * last_tile_width, 562 last_screen_transform.matrix().get(0, 0) * last_bundle_width,
474 last_screen_transform.matrix().get(1, 0) * last_tile_width); 563 last_screen_transform.matrix().get(1, 0) * last_bundle_width);
475 gfx::Vector2dF last_vertical( 564 gfx::Vector2dF last_vertical(
476 last_screen_transform.matrix().get(0, 1) * last_tile_height, 565 last_screen_transform.matrix().get(0, 1) * last_bundle_height,
477 last_screen_transform.matrix().get(1, 1) * last_tile_height); 566 last_screen_transform.matrix().get(1, 1) * last_bundle_height);
478 567
479 for (TilingData::Iterator iter(&tiling_data_, interest_rect); 568 for (TilingData::Iterator iter(&bundle_tiling_data_, interest_rect);
480 iter; ++iter) { 569 iter; ++iter) {
481 TileMap::iterator find = tiles_.find(iter.index()); 570 int bundle_x = iter.index_x();
482 if (find == tiles_.end()) 571 int bundle_y = iter.index_y();
572 TileBundle* bundle = TileBundleAt(bundle_x, bundle_y);
573 if (!bundle)
483 continue; 574 continue;
484 575
485 Tile* tile = find->second.get(); 576 gfx::PointF current_bundle_origin = current_screen_space_origin +
486 577 ScaleVector2d(current_horizontal, bundle_x) +
487 int i = iter.index_x(); 578 ScaleVector2d(current_vertical, bundle_y);
488 int j = iter.index_y(); 579 gfx::PointF last_bundle_origin = last_screen_space_origin +
489 gfx::PointF current_tile_origin = current_screen_space_origin + 580 ScaleVector2d(last_horizontal, bundle_x) +
490 ScaleVector2d(current_horizontal, i) + 581 ScaleVector2d(last_vertical, bundle_y);
491 ScaleVector2d(current_vertical, j);
492 gfx::PointF last_tile_origin = last_screen_space_origin +
493 ScaleVector2d(last_horizontal, i) +
494 ScaleVector2d(last_vertical, j);
495 582
496 gfx::RectF current_screen_rect = gfx::QuadF( 583 gfx::RectF current_screen_rect = gfx::QuadF(
497 current_tile_origin, 584 current_bundle_origin,
498 current_tile_origin + current_horizontal, 585 current_bundle_origin + current_horizontal,
499 current_tile_origin + current_horizontal + current_vertical, 586 current_bundle_origin + current_horizontal + current_vertical,
500 current_tile_origin + current_vertical).BoundingBox(); 587 current_bundle_origin + current_vertical).BoundingBox();
501 588
502 gfx::RectF last_screen_rect = gfx::QuadF( 589 gfx::RectF last_screen_rect = gfx::QuadF(
503 last_tile_origin, 590 last_bundle_origin,
504 last_tile_origin + last_horizontal, 591 last_bundle_origin + last_horizontal,
505 last_tile_origin + last_horizontal + last_vertical, 592 last_bundle_origin + last_horizontal + last_vertical,
506 last_tile_origin + last_vertical).BoundingBox(); 593 last_bundle_origin + last_vertical).BoundingBox();
507 594
508 float distance_to_visible_in_pixels = 595 float distance_to_visible_in_pixels =
509 TilePriority::manhattanDistance(current_screen_rect, view_rect); 596 TilePriority::manhattanDistance(current_screen_rect, view_rect);
510 597
511 float time_to_visible_in_seconds = 598 float time_to_visible_in_seconds =
512 TilePriority::TimeForBoundsToIntersect( 599 TilePriority::TimeForBoundsToIntersect(
513 last_screen_rect, current_screen_rect, time_delta, view_rect); 600 last_screen_rect, current_screen_rect, time_delta, view_rect);
514 TilePriority priority( 601 TilePriority priority(
515 resolution_, 602 resolution_,
516 time_to_visible_in_seconds, 603 time_to_visible_in_seconds,
517 distance_to_visible_in_pixels); 604 distance_to_visible_in_pixels);
518 tile->SetPriority(tree, priority); 605
606 bundle->SetPriority(priority);
519 } 607 }
520 } else { 608 } else {
521 for (TilingData::Iterator iter(&tiling_data_, interest_rect); 609 for (TilingData::Iterator iter(&bundle_tiling_data_, interest_rect);
522 iter; ++iter) { 610 iter; ++iter) {
523 TileMap::iterator find = tiles_.find(iter.index()); 611 int bundle_x = iter.index_x();
524 if (find == tiles_.end()) 612 int bundle_y = iter.index_y();
613 TileBundle* bundle = TileBundleAt(bundle_x, bundle_y);
614 if (!bundle)
525 continue; 615 continue;
526 Tile* tile = find->second.get();
527 616
528 gfx::Rect tile_bounds = 617 gfx::Rect bundle_bounds =
529 tiling_data_.TileBounds(iter.index_x(), iter.index_y()); 618 bundle_tiling_data_.TileBounds(bundle_x, bundle_y);
530 gfx::RectF current_layer_content_rect = gfx::ScaleRect( 619 gfx::RectF current_layer_content_rect = gfx::ScaleRect(
531 tile_bounds, 620 bundle_bounds,
532 current_scale, 621 current_scale,
533 current_scale); 622 current_scale);
534 gfx::RectF current_screen_rect = MathUtil::MapClippedRect( 623 gfx::RectF current_screen_rect = MathUtil::MapClippedRect(
535 current_screen_transform, current_layer_content_rect); 624 current_screen_transform, current_layer_content_rect);
536 gfx::RectF last_layer_content_rect = gfx::ScaleRect( 625 gfx::RectF last_layer_content_rect = gfx::ScaleRect(
537 tile_bounds, 626 bundle_bounds,
538 last_scale, 627 last_scale,
539 last_scale); 628 last_scale);
540 gfx::RectF last_screen_rect = MathUtil::MapClippedRect( 629 gfx::RectF last_screen_rect = MathUtil::MapClippedRect(
541 last_screen_transform, last_layer_content_rect); 630 last_screen_transform, last_layer_content_rect);
542 631
543 float distance_to_visible_in_pixels = 632 float distance_to_visible_in_pixels =
544 TilePriority::manhattanDistance(current_screen_rect, view_rect); 633 TilePriority::manhattanDistance(current_screen_rect, view_rect);
545 634
546 float time_to_visible_in_seconds = 635 float time_to_visible_in_seconds =
547 TilePriority::TimeForBoundsToIntersect( 636 TilePriority::TimeForBoundsToIntersect(
548 last_screen_rect, current_screen_rect, time_delta, view_rect); 637 last_screen_rect, current_screen_rect, time_delta, view_rect);
549 638
550 TilePriority priority( 639 TilePriority priority(
551 resolution_, 640 resolution_,
552 time_to_visible_in_seconds, 641 time_to_visible_in_seconds,
553 distance_to_visible_in_pixels); 642 distance_to_visible_in_pixels);
554 tile->SetPriority(tree, priority); 643
644 bundle->SetPriority(priority);
555 } 645 }
556 } 646 }
557 647
558 last_impl_frame_time_in_seconds_ = current_frame_time_in_seconds; 648 last_impl_frame_time_in_seconds_ = current_frame_time_in_seconds;
559 } 649 }
560 650
561 void PictureLayerTiling::SetLiveTilesRect( 651 void PictureLayerTiling::SetLiveTilesRect(
562 gfx::Rect new_live_tiles_rect) { 652 gfx::Rect new_live_tiles_rect) {
563 DCHECK(new_live_tiles_rect.IsEmpty() || 653 DCHECK(new_live_tiles_rect.IsEmpty() ||
564 ContentRect().Contains(new_live_tiles_rect)); 654 ContentRect().Contains(new_live_tiles_rect));
565 if (live_tiles_rect_ == new_live_tiles_rect) 655 if (live_tiles_rect_ == new_live_tiles_rect)
566 return; 656 return;
567 657
568 // Iterate to delete all tiles outside of our new live_tiles rect. 658 // Iterate to delete all tiles outside of our new live_tiles rect.
569 for (TilingData::DifferenceIterator iter(&tiling_data_, 659 for (TilingData::DifferenceIterator iter(&tiling_data_,
570 live_tiles_rect_, 660 live_tiles_rect_,
571 new_live_tiles_rect); 661 new_live_tiles_rect);
572 iter; 662 iter;
573 ++iter) { 663 ++iter) {
574 TileMapKey key(iter.index()); 664 int tile_x = iter.index_x();
575 TileMap::iterator found = tiles_.find(key); 665 int tile_y = iter.index_y();
666
576 // If the tile was outside of the recorded region, it won't exist even 667 // If the tile was outside of the recorded region, it won't exist even
577 // though it was in the live rect. 668 // though it was in the live rect.
578 if (found != tiles_.end()) 669 RemoveTile(tile_x, tile_y);
579 tiles_.erase(found);
580 } 670 }
581 671
582 const PictureLayerTiling* twin_tiling = client_->GetTwinTiling(this); 672 const PictureLayerTiling* twin_tiling = client_->GetTwinTiling(this);
583 673
584 // Iterate to allocate new tiles for all regions with newly exposed area. 674 // Iterate to allocate new tiles for all regions with newly exposed area.
585 for (TilingData::DifferenceIterator iter(&tiling_data_, 675 for (TilingData::DifferenceIterator iter(&tiling_data_,
586 new_live_tiles_rect, 676 new_live_tiles_rect,
587 live_tiles_rect_); 677 live_tiles_rect_);
588 iter; 678 iter;
589 ++iter) { 679 ++iter) {
590 TileMapKey key(iter.index()); 680 CreateTile(iter.index_x(), iter.index_y(), twin_tiling);
591 CreateTile(key.first, key.second, twin_tiling);
592 } 681 }
593 682
594 live_tiles_rect_ = new_live_tiles_rect; 683 live_tiles_rect_ = new_live_tiles_rect;
595 } 684 }
596 685
597 void PictureLayerTiling::DidBecomeRecycled() { 686 void PictureLayerTiling::DidBecomeRecycled() {
598 // DidBecomeActive below will set the active priority for tiles that are 687 // DidBecomeActive below will set the active priority for tiles that are
599 // still in the tree. Calling this first on an active tiling that is becoming 688 // still in the tree. Calling this first on an active tiling that is becoming
600 // recycled takes care of tiles that are no longer in the active tree (eg. 689 // recycled takes care of tiles that are no longer in the active tree (eg.
601 // due to a pending invalidation). 690 // due to a pending invalidation).
602 for (TileMap::const_iterator it = tiles_.begin(); it != tiles_.end(); ++it) { 691 for (TileBundleMap::const_iterator it = tile_bundles_.begin();
603 it->second->SetPriority(ACTIVE_TREE, TilePriority()); 692 it != tile_bundles_.end();
693 ++it) {
694 it->second->DidBecomeRecycled();
604 } 695 }
605 } 696 }
606 697
607 void PictureLayerTiling::DidBecomeActive() { 698 void PictureLayerTiling::DidBecomeActive() {
608 for (TileMap::const_iterator it = tiles_.begin(); it != tiles_.end(); ++it) { 699 for (TileBundleMap::const_iterator it = tile_bundles_.begin();
609 it->second->SetPriority(ACTIVE_TREE, it->second->priority(PENDING_TREE)); 700 it != tile_bundles_.end();
610 it->second->SetPriority(PENDING_TREE, TilePriority()); 701 ++it) {
611 702 it->second->DidBecomeActive();
612 // Tile holds a ref onto a picture pile. If the tile never gets invalidated 703 for (TileBundle::Iterator tile_it(it->second.get()); tile_it; ++tile_it) {
613 // and recreated, then that picture pile ref could exist indefinitely. To 704 // Tile holds a ref onto a picture pile. If the tile never gets
614 // prevent this, ask the client to update the pile to its own ref. This 705 // invalidated and recreated, then that picture pile ref could exist
615 // will cause PicturePileImpls and their clones to get deleted once the 706 // indefinitely. To prevent this, ask the client to update the pile to
616 // corresponding PictureLayerImpl and any in flight raster jobs go out of 707 // its own ref. This will cause PicturePileImpls and their clones to get
617 // scope. 708 // deleted once the corresponding PictureLayerImpl and any in flight
618 client_->UpdatePile(it->second.get()); 709 // raster jobs go out of scope.
710 client_->UpdatePile(*tile_it);
711 }
619 } 712 }
620 } 713 }
621 714
622 void PictureLayerTiling::UpdateTilesToCurrentPile() { 715 void PictureLayerTiling::UpdateTilesToCurrentPile() {
623 for (TileMap::const_iterator it = tiles_.begin(); it != tiles_.end(); ++it) { 716 for (TileBundleMap::const_iterator it = tile_bundles_.begin();
624 client_->UpdatePile(it->second.get()); 717 it != tile_bundles_.end();
718 ++it) {
719 for (TileBundle::Iterator tile_it(it->second.get()); tile_it; ++tile_it)
720 client_->UpdatePile(*tile_it);
625 } 721 }
626 } 722 }
627 723
628 scoped_ptr<base::Value> PictureLayerTiling::AsValue() const { 724 scoped_ptr<base::Value> PictureLayerTiling::AsValue() const {
629 scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue()); 725 scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue());
630 state->SetInteger("num_tiles", tiles_.size()); 726 state->SetInteger("num_tile_bundles", tile_bundles_.size());
631 state->SetDouble("content_scale", contents_scale_); 727 state->SetDouble("content_scale", contents_scale_);
632 state->Set("content_bounds", 728 state->Set("content_bounds",
633 MathUtil::AsValue(ContentRect().size()).release()); 729 MathUtil::AsValue(ContentRect().size()).release());
634 return state.PassAs<base::Value>(); 730 return state.PassAs<base::Value>();
635 } 731 }
636 732
637 size_t PictureLayerTiling::GPUMemoryUsageInBytes() const { 733 size_t PictureLayerTiling::GPUMemoryUsageInBytes() const {
638 size_t amount = 0; 734 size_t amount = 0;
639 for (TileMap::const_iterator it = tiles_.begin(); it != tiles_.end(); ++it) { 735 for (TileBundleMap::const_iterator it = tile_bundles_.begin();
640 const Tile* tile = it->second.get(); 736 it != tile_bundles_.end();
641 amount += tile->GPUMemoryUsageInBytes(); 737 ++it) {
738 for (TileBundle::Iterator tile_it(it->second.get()); tile_it; ++tile_it)
739 amount += tile_it->GPUMemoryUsageInBytes();
642 } 740 }
643 return amount; 741 return amount;
644 } 742 }
645 743
646 PictureLayerTiling::RectExpansionCache::RectExpansionCache() 744 PictureLayerTiling::RectExpansionCache::RectExpansionCache()
647 : previous_target(0) { 745 : previous_target(0) {
648 } 746 }
649 747
650 namespace { 748 namespace {
651 749
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
786 break; 884 break;
787 } 885 }
788 886
789 gfx::Rect result(origin_x, origin_y, width, height); 887 gfx::Rect result(origin_x, origin_y, width, height);
790 if (cache) 888 if (cache)
791 cache->previous_result = result; 889 cache->previous_result = result;
792 return result; 890 return result;
793 } 891 }
794 892
795 } // namespace cc 893 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698