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

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

Issue 2175553002: Raster PictureLayerTiling with fractional translation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: clean up Created 4 years, 3 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
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/tiles/picture_layer_tiling.h" 5 #include "cc/tiles/picture_layer_tiling.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <cmath> 10 #include <cmath>
(...skipping 14 matching lines...) Expand all
25 #include "ui/gfx/geometry/point_conversions.h" 25 #include "ui/gfx/geometry/point_conversions.h"
26 #include "ui/gfx/geometry/rect_conversions.h" 26 #include "ui/gfx/geometry/rect_conversions.h"
27 #include "ui/gfx/geometry/rect_f.h" 27 #include "ui/gfx/geometry/rect_f.h"
28 #include "ui/gfx/geometry/safe_integer_conversions.h" 28 #include "ui/gfx/geometry/safe_integer_conversions.h"
29 #include "ui/gfx/geometry/size_conversions.h" 29 #include "ui/gfx/geometry/size_conversions.h"
30 30
31 namespace cc { 31 namespace cc {
32 32
33 PictureLayerTiling::PictureLayerTiling( 33 PictureLayerTiling::PictureLayerTiling(
34 WhichTree tree, 34 WhichTree tree,
35 float contents_scale, 35 const ScaleTranslate2d& contents_transform,
36 scoped_refptr<RasterSource> raster_source, 36 scoped_refptr<RasterSource> raster_source,
37 PictureLayerTilingClient* client) 37 PictureLayerTilingClient* client)
38 : contents_scale_(contents_scale), 38 : contents_transform_(contents_transform),
39 client_(client), 39 client_(client),
40 tree_(tree), 40 tree_(tree),
41 raster_source_(raster_source), 41 raster_source_(raster_source),
42 resolution_(NON_IDEAL_RESOLUTION), 42 resolution_(NON_IDEAL_RESOLUTION),
43 may_contain_low_resolution_tiles_(false), 43 may_contain_low_resolution_tiles_(false),
44 tiling_data_(gfx::Size(), gfx::Size(), kBorderTexels), 44 tiling_data_(gfx::Size(), gfx::Size(), kBorderTexels),
45 can_require_tiles_for_activation_(false), 45 can_require_tiles_for_activation_(false),
46 current_content_to_screen_scale_(0.f), 46 current_content_to_screen_scale_(0.f),
47 has_visible_rect_tiles_(false), 47 has_visible_rect_tiles_(false),
48 has_skewport_rect_tiles_(false), 48 has_skewport_rect_tiles_(false),
49 has_soon_border_rect_tiles_(false), 49 has_soon_border_rect_tiles_(false),
50 has_eventually_rect_tiles_(false), 50 has_eventually_rect_tiles_(false),
51 all_tiles_done_(true) { 51 all_tiles_done_(true) {
52 DCHECK(!raster_source->IsSolidColor()); 52 DCHECK(!raster_source->IsSolidColor());
53 gfx::Size content_bounds = 53 DCHECK_GE(contents_transform.translation().x(), 0.f);
54 gfx::ScaleToCeiledSize(raster_source_->GetSize(), contents_scale); 54 DCHECK_LT(contents_transform.translation().x(), 1.f);
55 gfx::Size tile_size = client_->CalculateTileSize(content_bounds); 55 DCHECK_GE(contents_transform.translation().y(), 0.f);
56 DCHECK_LT(contents_transform.translation().y(), 1.f);
56 57
57 DCHECK(!gfx::ScaleToFlooredSize(raster_source_->GetSize(), contents_scale) 58 DCHECK(!gfx::ScaleToFlooredSize(raster_source_->GetSize(),
59 contents_transform.pre_scale())
58 .IsEmpty()) 60 .IsEmpty())
59 << "Tiling created with scale too small as contents become empty." 61 << "Tiling created with scale too small as contents become empty."
60 << " Layer bounds: " << raster_source_->GetSize().ToString() 62 << " Layer bounds: " << raster_source_->GetSize().ToString()
61 << " Contents scale: " << contents_scale; 63 << " Contents scale: " << contents_transform.pre_scale();
62 64
63 tiling_data_.SetTilingSize(content_bounds); 65 gfx::Rect content_bounds_rect =
66 EnclosingContentsRectFromLayerRect(gfx::Rect(raster_source_->GetSize()));
67 gfx::Size tiling_size = gfx::Size(content_bounds_rect.bottom_right().x(),
68 content_bounds_rect.bottom_right().y());
69 tiling_data_.SetTilingSize(tiling_size);
70 gfx::Size tile_size = client_->CalculateTileSize(tiling_size);
64 tiling_data_.SetMaxTextureSize(tile_size); 71 tiling_data_.SetMaxTextureSize(tile_size);
65 } 72 }
66 73
67 PictureLayerTiling::~PictureLayerTiling() { 74 PictureLayerTiling::~PictureLayerTiling() {
68 } 75 }
69 76
70 Tile* PictureLayerTiling::CreateTile(const Tile::CreateInfo& info) { 77 Tile* PictureLayerTiling::CreateTile(const Tile::CreateInfo& info) {
71 const int i = info.tiling_i_index; 78 const int i = info.tiling_i_index;
72 const int j = info.tiling_j_index; 79 const int j = info.tiling_j_index;
73 TileMapKey key(i, j); 80 TileMapKey key(i, j);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 // the previous content ID of these tiles. In that case, we need only 114 // the previous content ID of these tiles. In that case, we need only
108 // partially raster the tile content. 115 // partially raster the tile content.
109 if (tile && invalidation && TilingMatchesTileIndices(active_twin)) { 116 if (tile && invalidation && TilingMatchesTileIndices(active_twin)) {
110 if (const Tile* old_tile = 117 if (const Tile* old_tile =
111 active_twin->TileAt(key.index_x, key.index_y)) { 118 active_twin->TileAt(key.index_x, key.index_y)) {
112 gfx::Rect tile_rect = tile->content_rect(); 119 gfx::Rect tile_rect = tile->content_rect();
113 gfx::Rect invalidated; 120 gfx::Rect invalidated;
114 for (Region::Iterator iter(*invalidation); iter.has_rect(); 121 for (Region::Iterator iter(*invalidation); iter.has_rect();
115 iter.next()) { 122 iter.next()) {
116 gfx::Rect invalid_content_rect = 123 gfx::Rect invalid_content_rect =
117 gfx::ScaleToEnclosingRect(iter.rect(), contents_scale_); 124 EnclosingContentsRectFromLayerRect(iter.rect());
118 invalid_content_rect.Intersect(tile_rect); 125 invalid_content_rect.Intersect(tile_rect);
119 invalidated.Union(invalid_content_rect); 126 invalidated.Union(invalid_content_rect);
120 } 127 }
121 tile->SetInvalidated(invalidated, old_tile->id()); 128 tile->SetInvalidated(invalidated, old_tile->id());
122 } 129 }
123 } 130 }
124 } 131 }
125 } 132 }
126 VerifyLiveTilesRect(false); 133 VerifyLiveTilesRect(false);
127 } 134 }
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 pending_twin->current_eventually_rect_, 176 pending_twin->current_eventually_rect_,
170 pending_twin->current_occlusion_in_layer_space_); 177 pending_twin->current_occlusion_in_layer_space_);
171 } 178 }
172 179
173 void PictureLayerTiling::SetRasterSourceAndResize( 180 void PictureLayerTiling::SetRasterSourceAndResize(
174 scoped_refptr<RasterSource> raster_source) { 181 scoped_refptr<RasterSource> raster_source) {
175 DCHECK(!raster_source->IsSolidColor()); 182 DCHECK(!raster_source->IsSolidColor());
176 gfx::Size old_layer_bounds = raster_source_->GetSize(); 183 gfx::Size old_layer_bounds = raster_source_->GetSize();
177 raster_source_ = std::move(raster_source); 184 raster_source_ = std::move(raster_source);
178 gfx::Size new_layer_bounds = raster_source_->GetSize(); 185 gfx::Size new_layer_bounds = raster_source_->GetSize();
179 gfx::Size content_bounds = 186 gfx::Rect content_rect =
180 gfx::ScaleToCeiledSize(new_layer_bounds, contents_scale_); 187 EnclosingContentsRectFromLayerRect(gfx::Rect(new_layer_bounds));
181 gfx::Size tile_size = client_->CalculateTileSize(content_bounds); 188 DCHECK(content_rect.origin() == gfx::Point());
189 gfx::Size tile_size = client_->CalculateTileSize(content_rect.size());
182 190
183 if (tile_size != tiling_data_.max_texture_size()) { 191 if (tile_size != tiling_data_.max_texture_size()) {
184 tiling_data_.SetTilingSize(content_bounds); 192 tiling_data_.SetTilingSize(content_rect.size());
185 tiling_data_.SetMaxTextureSize(tile_size); 193 tiling_data_.SetMaxTextureSize(tile_size);
186 // When the tile size changes, the TilingData positions no longer work 194 // When the tile size changes, the TilingData positions no longer work
187 // as valid keys to the TileMap, so just drop all tiles and clear the live 195 // as valid keys to the TileMap, so just drop all tiles and clear the live
188 // tiles rect. 196 // tiles rect.
189 Reset(); 197 Reset();
190 return; 198 return;
191 } 199 }
192 200
193 if (old_layer_bounds == new_layer_bounds) 201 if (old_layer_bounds == new_layer_bounds)
194 return; 202 return;
195 203
196 // The SetLiveTilesRect() method would drop tiles outside the new bounds, 204 // The SetLiveTilesRect() method would drop tiles outside the new bounds,
197 // but may do so incorrectly if resizing the tiling causes the number of 205 // but may do so incorrectly if resizing the tiling causes the number of
198 // tiles in the tiling_data_ to change. 206 // tiles in the tiling_data_ to change.
199 gfx::Rect content_rect(content_bounds);
200 int before_left = tiling_data_.TileXIndexFromSrcCoord(live_tiles_rect_.x()); 207 int before_left = tiling_data_.TileXIndexFromSrcCoord(live_tiles_rect_.x());
201 int before_top = tiling_data_.TileYIndexFromSrcCoord(live_tiles_rect_.y()); 208 int before_top = tiling_data_.TileYIndexFromSrcCoord(live_tiles_rect_.y());
202 int before_right = 209 int before_right =
203 tiling_data_.TileXIndexFromSrcCoord(live_tiles_rect_.right() - 1); 210 tiling_data_.TileXIndexFromSrcCoord(live_tiles_rect_.right() - 1);
204 int before_bottom = 211 int before_bottom =
205 tiling_data_.TileYIndexFromSrcCoord(live_tiles_rect_.bottom() - 1); 212 tiling_data_.TileYIndexFromSrcCoord(live_tiles_rect_.bottom() - 1);
206 213
207 // The live_tiles_rect_ is clamped to stay within the tiling size as we 214 // The live_tiles_rect_ is clamped to stay within the tiling size as we
208 // change it. 215 // change it.
209 live_tiles_rect_.Intersect(content_rect); 216 live_tiles_rect_.Intersect(content_rect);
210 tiling_data_.SetTilingSize(content_bounds); 217 tiling_data_.SetTilingSize(content_rect.size());
211 218
212 int after_right = -1; 219 int after_right = -1;
213 int after_bottom = -1; 220 int after_bottom = -1;
214 if (!live_tiles_rect_.IsEmpty()) { 221 if (!live_tiles_rect_.IsEmpty()) {
215 after_right = 222 after_right =
216 tiling_data_.TileXIndexFromSrcCoord(live_tiles_rect_.right() - 1); 223 tiling_data_.TileXIndexFromSrcCoord(live_tiles_rect_.right() - 1);
217 after_bottom = 224 after_bottom =
218 tiling_data_.TileYIndexFromSrcCoord(live_tiles_rect_.bottom() - 1); 225 tiling_data_.TileYIndexFromSrcCoord(live_tiles_rect_.bottom() - 1);
219 } 226 }
220 227
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 // unordered_map instead of a vector in the SmallMap. 272 // unordered_map instead of a vector in the SmallMap.
266 base::SmallMap<std::unordered_map<TileMapKey, gfx::Rect, TileMapKeyHash>, 16> 273 base::SmallMap<std::unordered_map<TileMapKey, gfx::Rect, TileMapKeyHash>, 16>
267 remove_tiles; 274 remove_tiles;
268 gfx::Rect expanded_live_tiles_rect = 275 gfx::Rect expanded_live_tiles_rect =
269 tiling_data_.ExpandRectToTileBounds(live_tiles_rect_); 276 tiling_data_.ExpandRectToTileBounds(live_tiles_rect_);
270 for (Region::Iterator iter(layer_invalidation); iter.has_rect(); 277 for (Region::Iterator iter(layer_invalidation); iter.has_rect();
271 iter.next()) { 278 iter.next()) {
272 gfx::Rect layer_rect = iter.rect(); 279 gfx::Rect layer_rect = iter.rect();
273 // The pixels which are invalid in content space. 280 // The pixels which are invalid in content space.
274 gfx::Rect invalid_content_rect = 281 gfx::Rect invalid_content_rect =
275 gfx::ScaleToEnclosingRect(layer_rect, contents_scale_); 282 EnclosingContentsRectFromLayerRect(layer_rect);
276 gfx::Rect coverage_content_rect = invalid_content_rect; 283 gfx::Rect coverage_content_rect = invalid_content_rect;
277 // Avoid needless work by not bothering to invalidate where there aren't 284 // Avoid needless work by not bothering to invalidate where there aren't
278 // tiles. 285 // tiles.
279 coverage_content_rect.Intersect(expanded_live_tiles_rect); 286 coverage_content_rect.Intersect(expanded_live_tiles_rect);
280 if (coverage_content_rect.IsEmpty()) 287 if (coverage_content_rect.IsEmpty())
281 continue; 288 continue;
282 // Since the content_rect needs to invalidate things that only touch a 289 // Since the content_rect needs to invalidate things that only touch a
283 // border of a tile, we need to include the borders while iterating. 290 // border of a tile, we need to include the borders while iterating.
284 bool include_borders = true; 291 bool include_borders = true;
285 for (TilingData::Iterator iter(&tiling_data_, coverage_content_rect, 292 for (TilingData::Iterator iter(&tiling_data_, coverage_content_rect,
(...skipping 16 matching lines...) Expand all
302 if (Tile* tile = CreateTile(info)) 309 if (Tile* tile = CreateTile(info))
303 tile->SetInvalidated(invalid_content_rect, old_tile->id()); 310 tile->SetInvalidated(invalid_content_rect, old_tile->id());
304 } 311 }
305 } 312 }
306 } 313 }
307 314
308 Tile::CreateInfo PictureLayerTiling::CreateInfoForTile(int i, int j) const { 315 Tile::CreateInfo PictureLayerTiling::CreateInfoForTile(int i, int j) const {
309 gfx::Rect tile_rect = tiling_data_.TileBoundsWithBorder(i, j); 316 gfx::Rect tile_rect = tiling_data_.TileBoundsWithBorder(i, j);
310 tile_rect.set_size(tiling_data_.max_texture_size()); 317 tile_rect.set_size(tiling_data_.max_texture_size());
311 gfx::Rect enclosing_layer_rect = 318 gfx::Rect enclosing_layer_rect =
312 gfx::ScaleToEnclosingRect(tile_rect, 1.f / contents_scale_); 319 EnclosingLayerRectFromContentsRect(tile_rect);
313 return Tile::CreateInfo(i, j, enclosing_layer_rect, tile_rect, 320 return Tile::CreateInfo(i, j, enclosing_layer_rect, tile_rect,
314 contents_scale_); 321 contents_transform_);
315 } 322 }
316 323
317 bool PictureLayerTiling::ShouldCreateTileAt( 324 bool PictureLayerTiling::ShouldCreateTileAt(
318 const Tile::CreateInfo& info) const { 325 const Tile::CreateInfo& info) const {
319 const int i = info.tiling_i_index; 326 const int i = info.tiling_i_index;
320 const int j = info.tiling_j_index; 327 const int j = info.tiling_j_index;
321 // Active tree should always create a tile. The reason for this is that active 328 // Active tree should always create a tile. The reason for this is that active
322 // tree represents content that we draw on screen, which means that whenever 329 // tree represents content that we draw on screen, which means that whenever
323 // we check whether a tile should exist somewhere, the answer is yes. This 330 // we check whether a tile should exist somewhere, the answer is yes. This
324 // doesn't mean it will actually be created (if raster source doesn't cover 331 // doesn't mean it will actually be created (if raster source doesn't cover
(...skipping 19 matching lines...) Expand all
344 return true; 351 return true;
345 352
346 const Region* layer_invalidation = client_->GetPendingInvalidation(); 353 const Region* layer_invalidation = client_->GetPendingInvalidation();
347 354
348 // If this tile is invalidated, then the pending tree should create one. 355 // If this tile is invalidated, then the pending tree should create one.
349 // Do the intersection test in content space to match the corresponding check 356 // Do the intersection test in content space to match the corresponding check
350 // on the active tree and avoid floating point inconsistencies. 357 // on the active tree and avoid floating point inconsistencies.
351 for (Region::Iterator iter(*layer_invalidation); iter.has_rect(); 358 for (Region::Iterator iter(*layer_invalidation); iter.has_rect();
352 iter.next()) { 359 iter.next()) {
353 gfx::Rect invalid_content_rect = 360 gfx::Rect invalid_content_rect =
354 gfx::ScaleToEnclosingRect(iter.rect(), contents_scale_); 361 EnclosingContentsRectFromLayerRect(iter.rect());
355 if (invalid_content_rect.Intersects(info.content_rect)) 362 if (invalid_content_rect.Intersects(info.content_rect))
356 return true; 363 return true;
357 } 364 }
358 // If the active tree doesn't have a tile here, but it's in the pending tree's 365 // If the active tree doesn't have a tile here, but it's in the pending tree's
359 // visible rect, then the pending tree should create a tile. This can happen 366 // visible rect, then the pending tree should create a tile. This can happen
360 // if the pending visible rect is outside of the active tree's live tiles 367 // if the pending visible rect is outside of the active tree's live tiles
361 // rect. In those situations, we need to block activation until we're ready to 368 // rect. In those situations, we need to block activation until we're ready to
362 // display content, which will have to come from the pending tree. 369 // display content, which will have to come from the pending tree.
363 if (!active_twin->TileAt(i, j) && 370 if (!active_twin->TileAt(i, j) &&
364 current_visible_rect_.Intersects(info.content_rect)) 371 current_visible_rect_.Intersects(info.content_rect))
(...skipping 19 matching lines...) Expand all
384 right_(-1), 391 right_(-1),
385 bottom_(-1) { 392 bottom_(-1) {
386 } 393 }
387 394
388 PictureLayerTiling::CoverageIterator::CoverageIterator( 395 PictureLayerTiling::CoverageIterator::CoverageIterator(
389 const PictureLayerTiling* tiling, 396 const PictureLayerTiling* tiling,
390 float dest_scale, 397 float dest_scale,
391 const gfx::Rect& dest_rect) 398 const gfx::Rect& dest_rect)
392 : tiling_(tiling), 399 : tiling_(tiling),
393 dest_rect_(dest_rect), 400 dest_rect_(dest_rect),
394 dest_to_content_scale_(0), 401 dest_to_content_(ScaleTranslate2d::PreScale(tiling->contents_transform(),
402 1.f / dest_scale)),
395 current_tile_(NULL), 403 current_tile_(NULL),
396 tile_i_(0), 404 tile_i_(0),
397 tile_j_(0), 405 tile_j_(0),
398 left_(0), 406 left_(0),
399 top_(0), 407 top_(0),
400 right_(-1), 408 right_(-1),
401 bottom_(-1) { 409 bottom_(-1) {
402 DCHECK(tiling_); 410 DCHECK(tiling_);
403 if (dest_rect_.IsEmpty()) 411 if (dest_rect_.IsEmpty())
404 return; 412 return;
405 413
406 dest_to_content_scale_ = tiling_->contents_scale_ / dest_scale; 414 gfx::Rect content_rect =
415 gfx::ToEnclosingRect(dest_to_content_.Transform(gfx::RectF(dest_rect_)));
407 416
408 gfx::Rect content_rect =
409 gfx::ScaleToEnclosingRect(dest_rect_,
410 dest_to_content_scale_,
411 dest_to_content_scale_);
412 // IndexFromSrcCoord clamps to valid tile ranges, so it's necessary to 417 // IndexFromSrcCoord clamps to valid tile ranges, so it's necessary to
413 // check for non-intersection first. 418 // check for non-intersection first.
414 content_rect.Intersect(gfx::Rect(tiling_->tiling_size())); 419 content_rect.Intersect(gfx::Rect(tiling_->tiling_size()));
415 if (content_rect.IsEmpty()) 420 if (content_rect.IsEmpty())
416 return; 421 return;
417 422
418 left_ = tiling_->tiling_data_.TileXIndexFromSrcCoord(content_rect.x()); 423 left_ = tiling_->tiling_data_.TileXIndexFromSrcCoord(content_rect.x());
419 top_ = tiling_->tiling_data_.TileYIndexFromSrcCoord(content_rect.y()); 424 top_ = tiling_->tiling_data_.TileYIndexFromSrcCoord(content_rect.y());
420 right_ = tiling_->tiling_data_.TileXIndexFromSrcCoord( 425 right_ = tiling_->tiling_data_.TileXIndexFromSrcCoord(
421 content_rect.right() - 1); 426 content_rect.right() - 1);
(...skipping 26 matching lines...) Expand all
448 } 453 }
449 } 454 }
450 455
451 current_tile_ = tiling_->TileAt(tile_i_, tile_j_); 456 current_tile_ = tiling_->TileAt(tile_i_, tile_j_);
452 457
453 // Calculate the current geometry rect. Due to floating point rounding 458 // Calculate the current geometry rect. Due to floating point rounding
454 // and ToEnclosingRect, tiles might overlap in destination space on the 459 // and ToEnclosingRect, tiles might overlap in destination space on the
455 // edges. 460 // edges.
456 gfx::Rect last_geometry_rect = current_geometry_rect_; 461 gfx::Rect last_geometry_rect = current_geometry_rect_;
457 462
458 gfx::Rect content_rect = tiling_->tiling_data_.TileBounds(tile_i_, tile_j_);
459
460 current_geometry_rect_ = 463 current_geometry_rect_ =
461 gfx::ScaleToEnclosingRect(content_rect, 1 / dest_to_content_scale_); 464 gfx::ToEnclosingRect(dest_to_content_.TransformReverse(
465 gfx::RectF(tiling_->tiling_data_.TileBounds(tile_i_, tile_j_))));
462 466
463 current_geometry_rect_.Intersect(dest_rect_); 467 current_geometry_rect_.Intersect(dest_rect_);
464 DCHECK(!current_geometry_rect_.IsEmpty()); 468 DCHECK(!current_geometry_rect_.IsEmpty());
465 469
466 if (first_time) 470 if (first_time)
467 return *this; 471 return *this;
468 472
469 // Iteration happens left->right, top->bottom. Running off the bottom-right 473 // Iteration happens left->right, top->bottom. Running off the bottom-right
470 // edge is handled by the intersection above with dest_rect_. Here we make 474 // edge is handled by the intersection above with dest_rect_. Here we make
471 // sure that the new current geometry rect doesn't overlap with the last. 475 // sure that the new current geometry rect doesn't overlap with the last.
(...skipping 22 matching lines...) Expand all
494 498
495 gfx::Rect PictureLayerTiling::CoverageIterator::geometry_rect() const { 499 gfx::Rect PictureLayerTiling::CoverageIterator::geometry_rect() const {
496 return current_geometry_rect_; 500 return current_geometry_rect_;
497 } 501 }
498 502
499 gfx::RectF PictureLayerTiling::CoverageIterator::texture_rect() const { 503 gfx::RectF PictureLayerTiling::CoverageIterator::texture_rect() const {
500 auto tex_origin = gfx::PointF( 504 auto tex_origin = gfx::PointF(
501 tiling_->tiling_data_.TileBoundsWithBorder(tile_i_, tile_j_).origin()); 505 tiling_->tiling_data_.TileBoundsWithBorder(tile_i_, tile_j_).origin());
502 506
503 // Convert from dest space => content space => texture space. 507 // Convert from dest space => content space => texture space.
504 gfx::RectF texture_rect(current_geometry_rect_); 508 gfx::RectF texture_rect =
505 texture_rect.Scale(dest_to_content_scale_, 509 dest_to_content_.Transform(gfx::RectF(current_geometry_rect_));
506 dest_to_content_scale_);
507 texture_rect.Intersect(gfx::RectF(gfx::SizeF(tiling_->tiling_size()))); 510 texture_rect.Intersect(gfx::RectF(gfx::SizeF(tiling_->tiling_size())));
508 if (texture_rect.IsEmpty()) 511 if (texture_rect.IsEmpty())
509 return texture_rect; 512 return texture_rect;
510 texture_rect.Offset(-tex_origin.OffsetFromOrigin()); 513 texture_rect.Offset(-tex_origin.OffsetFromOrigin());
511 514
512 return texture_rect; 515 return texture_rect;
513 } 516 }
514 517
515 ScopedTilePtr PictureLayerTiling::TakeTileAt(int i, int j) { 518 ScopedTilePtr PictureLayerTiling::TakeTileAt(int i, int j) {
516 TileMap::iterator found = tiles_.find(TileMapKey(i, j)); 519 TileMap::iterator found = tiles_.find(TileMapKey(i, j));
(...skipping 25 matching lines...) Expand all
542 const gfx::Rect& eventually_rect_in_layer_space, 545 const gfx::Rect& eventually_rect_in_layer_space,
543 float ideal_contents_scale, 546 float ideal_contents_scale,
544 const Occlusion& occlusion_in_layer_space) { 547 const Occlusion& occlusion_in_layer_space) {
545 // If we have, or had occlusions, mark the tiles as 'not done' to ensure that 548 // If we have, or had occlusions, mark the tiles as 'not done' to ensure that
546 // we reiterate the tiles for rasterization. 549 // we reiterate the tiles for rasterization.
547 if (occlusion_in_layer_space.HasOcclusion() || 550 if (occlusion_in_layer_space.HasOcclusion() ||
548 current_occlusion_in_layer_space_.HasOcclusion()) { 551 current_occlusion_in_layer_space_.HasOcclusion()) {
549 set_all_tiles_done(false); 552 set_all_tiles_done(false);
550 } 553 }
551 554
552 const float content_to_screen_scale = ideal_contents_scale / contents_scale_; 555 const float content_to_screen_scale =
556 ideal_contents_scale / contents_transform_.pre_scale();
553 557
554 const gfx::Rect* input_rects[] = { 558 const gfx::Rect* input_rects[] = {
555 &visible_rect_in_layer_space, &skewport_in_layer_space, 559 &visible_rect_in_layer_space, &skewport_in_layer_space,
556 &soon_border_rect_in_layer_space, &eventually_rect_in_layer_space}; 560 &soon_border_rect_in_layer_space, &eventually_rect_in_layer_space};
557 gfx::Rect output_rects[4]; 561 gfx::Rect output_rects[4];
558 for (size_t i = 0; i < arraysize(input_rects); ++i) { 562 for (size_t i = 0; i < arraysize(input_rects); ++i)
559 output_rects[i] = gfx::ToEnclosingRect( 563 output_rects[i] = EnclosingContentsRectFromLayerRect(*input_rects[i]);
560 gfx::ScaleRect(gfx::RectF(*input_rects[i]), contents_scale_));
561 }
562 // Make sure the eventually rect is aligned to tile bounds. 564 // Make sure the eventually rect is aligned to tile bounds.
563 output_rects[3] = 565 output_rects[3] =
564 tiling_data_.ExpandRectIgnoringBordersToTileBounds(output_rects[3]); 566 tiling_data_.ExpandRectIgnoringBordersToTileBounds(output_rects[3]);
565 567
566 SetTilePriorityRects(content_to_screen_scale, output_rects[0], 568 SetTilePriorityRects(content_to_screen_scale, output_rects[0],
567 output_rects[1], output_rects[2], output_rects[3], 569 output_rects[1], output_rects[2], output_rects[3],
568 occlusion_in_layer_space); 570 occlusion_in_layer_space);
569 SetLiveTilesRect(output_rects[3]); 571 SetLiveTilesRect(output_rects[3]);
570 } 572 }
571 573
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
682 bool PictureLayerTiling::IsTileOccludedOnCurrentTree(const Tile* tile) const { 684 bool PictureLayerTiling::IsTileOccludedOnCurrentTree(const Tile* tile) const {
683 if (!current_occlusion_in_layer_space_.HasOcclusion()) 685 if (!current_occlusion_in_layer_space_.HasOcclusion())
684 return false; 686 return false;
685 gfx::Rect tile_query_rect = 687 gfx::Rect tile_query_rect =
686 gfx::IntersectRects(tile->content_rect(), current_visible_rect_); 688 gfx::IntersectRects(tile->content_rect(), current_visible_rect_);
687 // Explicitly check if the tile is outside the viewport. If so, we need to 689 // Explicitly check if the tile is outside the viewport. If so, we need to
688 // return false, since occlusion for this tile is unknown. 690 // return false, since occlusion for this tile is unknown.
689 if (tile_query_rect.IsEmpty()) 691 if (tile_query_rect.IsEmpty())
690 return false; 692 return false;
691 693
692 if (contents_scale_ != 1.f) { 694 tile_query_rect = EnclosingLayerRectFromContentsRect(tile_query_rect);
693 tile_query_rect =
694 gfx::ScaleToEnclosingRect(tile_query_rect, 1.f / contents_scale_);
695 }
696 return current_occlusion_in_layer_space_.IsOccluded(tile_query_rect); 695 return current_occlusion_in_layer_space_.IsOccluded(tile_query_rect);
697 } 696 }
698 697
699 bool PictureLayerTiling::IsTileRequiredForActivation(const Tile* tile) const { 698 bool PictureLayerTiling::IsTileRequiredForActivation(const Tile* tile) const {
700 if (tree_ == PENDING_TREE) { 699 if (tree_ == PENDING_TREE) {
701 if (!can_require_tiles_for_activation_) 700 if (!can_require_tiles_for_activation_)
702 return false; 701 return false;
703 702
704 if (resolution_ != HIGH_RESOLUTION) 703 if (resolution_ != HIGH_RESOLUTION)
705 return false; 704 return false;
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
767 tile->set_required_for_activation(IsTileRequiredForActivation(tile)); 766 tile->set_required_for_activation(IsTileRequiredForActivation(tile));
768 tile->set_required_for_draw(IsTileRequiredForDraw(tile)); 767 tile->set_required_for_draw(IsTileRequiredForDraw(tile));
769 } 768 }
770 769
771 PrioritizedTile PictureLayerTiling::MakePrioritizedTile( 770 PrioritizedTile PictureLayerTiling::MakePrioritizedTile(
772 Tile* tile, 771 Tile* tile,
773 PriorityRectType priority_rect_type) const { 772 PriorityRectType priority_rect_type) const {
774 DCHECK(tile); 773 DCHECK(tile);
775 DCHECK(raster_source()->CoversRect(tile->enclosing_layer_rect())) 774 DCHECK(raster_source()->CoversRect(tile->enclosing_layer_rect()))
776 << "Recording rect: " 775 << "Recording rect: "
777 << gfx::ScaleToEnclosingRect(tile->content_rect(), 776 << EnclosingLayerRectFromContentsRect(tile->content_rect()).ToString();
778 1.f / tile->contents_scale())
779 .ToString();
780 777
781 return PrioritizedTile(tile, this, 778 return PrioritizedTile(tile, this,
782 ComputePriorityForTile(tile, priority_rect_type), 779 ComputePriorityForTile(tile, priority_rect_type),
783 IsTileOccluded(tile)); 780 IsTileOccluded(tile));
784 } 781 }
785 782
786 std::map<const Tile*, PrioritizedTile> 783 std::map<const Tile*, PrioritizedTile>
787 PictureLayerTiling::UpdateAndGetAllPrioritizedTilesForTesting() const { 784 PictureLayerTiling::UpdateAndGetAllPrioritizedTilesForTesting() const {
788 std::map<const Tile*, PrioritizedTile> result; 785 std::map<const Tile*, PrioritizedTile> result;
789 for (const auto& key_tile_pair : tiles_) { 786 for (const auto& key_tile_pair : tiles_) {
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
860 for (const auto& tile_pair : tiles_) { 857 for (const auto& tile_pair : tiles_) {
861 Tile* tile = tile_pair.second.get(); 858 Tile* tile = tile_pair.second.get();
862 prioritized_tiles->push_back( 859 prioritized_tiles->push_back(
863 MakePrioritizedTile(tile, ComputePriorityRectTypeForTile(tile))); 860 MakePrioritizedTile(tile, ComputePriorityRectTypeForTile(tile)));
864 } 861 }
865 } 862 }
866 863
867 void PictureLayerTiling::AsValueInto( 864 void PictureLayerTiling::AsValueInto(
868 base::trace_event::TracedValue* state) const { 865 base::trace_event::TracedValue* state) const {
869 state->SetInteger("num_tiles", base::saturated_cast<int>(tiles_.size())); 866 state->SetInteger("num_tiles", base::saturated_cast<int>(tiles_.size()));
870 state->SetDouble("content_scale", contents_scale_); 867 state->SetDouble("content_transform_pre_scale",
868 contents_transform_.pre_scale());
869 MathUtil::AddToTracedValue("content_transform_translation",
870 contents_transform_.translation(), state);
871 MathUtil::AddToTracedValue("visible_rect", current_visible_rect_, state); 871 MathUtil::AddToTracedValue("visible_rect", current_visible_rect_, state);
872 MathUtil::AddToTracedValue("skewport_rect", current_skewport_rect_, state); 872 MathUtil::AddToTracedValue("skewport_rect", current_skewport_rect_, state);
873 MathUtil::AddToTracedValue("soon_rect", current_soon_border_rect_, state); 873 MathUtil::AddToTracedValue("soon_rect", current_soon_border_rect_, state);
874 MathUtil::AddToTracedValue("eventually_rect", current_eventually_rect_, 874 MathUtil::AddToTracedValue("eventually_rect", current_eventually_rect_,
875 state); 875 state);
876 MathUtil::AddToTracedValue("tiling_size", tiling_size(), state); 876 MathUtil::AddToTracedValue("tiling_size", tiling_size(), state);
877 } 877 }
878 878
879 size_t PictureLayerTiling::GPUMemoryUsageInBytes() const { 879 size_t PictureLayerTiling::GPUMemoryUsageInBytes() const {
880 size_t amount = 0; 880 size_t amount = 0;
881 for (TileMap::const_iterator it = tiles_.begin(); it != tiles_.end(); ++it) { 881 for (TileMap::const_iterator it = tiles_.begin(); it != tiles_.end(); ++it) {
882 const Tile* tile = it->second.get(); 882 const Tile* tile = it->second.get();
883 amount += tile->GPUMemoryUsageInBytes(); 883 amount += tile->GPUMemoryUsageInBytes();
884 } 884 }
885 return amount; 885 return amount;
886 } 886 }
887 887
888 gfx::Rect PictureLayerTiling::EnclosingContentsRectFromLayerRect(
889 const gfx::Rect& layer_rect) const {
890 return ToEnclosingRect(contents_transform_.Transform(gfx::RectF(layer_rect)));
891 }
892
893 gfx::Rect PictureLayerTiling::EnclosingLayerRectFromContentsRect(
894 const gfx::Rect& contents_rect) const {
895 return ToEnclosingRect(
896 contents_transform_.TransformReverse(gfx::RectF(contents_rect)));
897 }
898
888 } // namespace cc 899 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698