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

Unified 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: use draw transform instead? Created 4 years, 4 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 side-by-side diff with in-line comments
Download patch
Index: cc/tiles/picture_layer_tiling.cc
diff --git a/cc/tiles/picture_layer_tiling.cc b/cc/tiles/picture_layer_tiling.cc
index 94a36cdde51411ad70db1f54187c9c44e042301d..86b7feee12f66dfc6df3ad1d700ddcaaa0b2f203 100644
--- a/cc/tiles/picture_layer_tiling.cc
+++ b/cc/tiles/picture_layer_tiling.cc
@@ -33,9 +33,11 @@ namespace cc {
PictureLayerTiling::PictureLayerTiling(
WhichTree tree,
float contents_scale,
+ const gfx::Vector2dF& contents_translation,
scoped_refptr<RasterSource> raster_source,
PictureLayerTilingClient* client)
: contents_scale_(contents_scale),
+ contents_translation_(contents_translation),
client_(client),
tree_(tree),
raster_source_(raster_source),
@@ -50,9 +52,14 @@ PictureLayerTiling::PictureLayerTiling(
has_eventually_rect_tiles_(false),
all_tiles_done_(true) {
DCHECK(!raster_source->IsSolidColor());
- gfx::Size content_bounds =
- gfx::ScaleToCeiledSize(raster_source_->GetSize(), contents_scale);
- gfx::Size tile_size = client_->CalculateTileSize(content_bounds);
+ DCHECK(contents_translation.x() >= 0.f && contents_translation.x() < 1.f);
enne (OOO) 2016/08/22 22:57:39 Please separate these conditions onto different li
trchen 2016/08/29 10:14:48 Done.
+ DCHECK(contents_translation.y() >= 0.f && contents_translation.y() < 1.f);
+
+ gfx::Rect content_bounds_rect =
+ EnclosingContentsRectFromLayerRect(gfx::Rect(raster_source_->GetSize()));
+ DCHECK(content_bounds_rect.origin() == gfx::Point());
enne (OOO) 2016/08/22 22:57:39 Can you make this DCHECK_EQ or maybe make a separa
trchen 2016/08/29 10:14:48 I think we need to fix this in base/logging.h. log
+
+ gfx::Size tile_size = client_->CalculateTileSize(content_bounds_rect.size());
DCHECK(!gfx::ScaleToFlooredSize(raster_source_->GetSize(), contents_scale)
.IsEmpty())
@@ -60,7 +67,7 @@ PictureLayerTiling::PictureLayerTiling(
<< " Layer bounds: " << raster_source_->GetSize().ToString()
<< " Contents scale: " << contents_scale;
- tiling_data_.SetTilingSize(content_bounds);
+ tiling_data_.SetTilingSize(content_bounds_rect.size());
tiling_data_.SetMaxTextureSize(tile_size);
}
@@ -114,7 +121,7 @@ void PictureLayerTiling::CreateMissingTilesInLiveTilesRect() {
for (Region::Iterator iter(*invalidation); iter.has_rect();
iter.next()) {
gfx::Rect invalid_content_rect =
- gfx::ScaleToEnclosingRect(iter.rect(), contents_scale_);
+ EnclosingContentsRectFromLayerRect(iter.rect());
invalid_content_rect.Intersect(tile_rect);
invalidated.Union(invalid_content_rect);
}
@@ -176,12 +183,13 @@ void PictureLayerTiling::SetRasterSourceAndResize(
gfx::Size old_layer_bounds = raster_source_->GetSize();
raster_source_ = std::move(raster_source);
gfx::Size new_layer_bounds = raster_source_->GetSize();
- gfx::Size content_bounds =
- gfx::ScaleToCeiledSize(new_layer_bounds, contents_scale_);
- gfx::Size tile_size = client_->CalculateTileSize(content_bounds);
+ gfx::Rect content_rect =
+ EnclosingContentsRectFromLayerRect(gfx::Rect(new_layer_bounds));
+ DCHECK(content_rect.origin() == gfx::Point());
+ gfx::Size tile_size = client_->CalculateTileSize(content_rect.size());
if (tile_size != tiling_data_.max_texture_size()) {
- tiling_data_.SetTilingSize(content_bounds);
+ tiling_data_.SetTilingSize(content_rect.size());
tiling_data_.SetMaxTextureSize(tile_size);
// When the tile size changes, the TilingData positions no longer work
// as valid keys to the TileMap, so just drop all tiles and clear the live
@@ -196,7 +204,6 @@ void PictureLayerTiling::SetRasterSourceAndResize(
// The SetLiveTilesRect() method would drop tiles outside the new bounds,
// but may do so incorrectly if resizing the tiling causes the number of
// tiles in the tiling_data_ to change.
- gfx::Rect content_rect(content_bounds);
int before_left = tiling_data_.TileXIndexFromSrcCoord(live_tiles_rect_.x());
int before_top = tiling_data_.TileYIndexFromSrcCoord(live_tiles_rect_.y());
int before_right =
@@ -207,7 +214,7 @@ void PictureLayerTiling::SetRasterSourceAndResize(
// The live_tiles_rect_ is clamped to stay within the tiling size as we
// change it.
live_tiles_rect_.Intersect(content_rect);
- tiling_data_.SetTilingSize(content_bounds);
+ tiling_data_.SetTilingSize(content_rect.size());
int after_right = -1;
int after_bottom = -1;
@@ -272,7 +279,7 @@ void PictureLayerTiling::RemoveTilesInRegion(const Region& layer_invalidation,
gfx::Rect layer_rect = iter.rect();
// The pixels which are invalid in content space.
gfx::Rect invalid_content_rect =
- gfx::ScaleToEnclosingRect(layer_rect, contents_scale_);
+ EnclosingContentsRectFromLayerRect(layer_rect);
gfx::Rect coverage_content_rect = invalid_content_rect;
// Avoid needless work by not bothering to invalidate where there aren't
// tiles.
@@ -309,9 +316,9 @@ Tile::CreateInfo PictureLayerTiling::CreateInfoForTile(int i, int j) const {
gfx::Rect tile_rect = tiling_data_.TileBoundsWithBorder(i, j);
tile_rect.set_size(tiling_data_.max_texture_size());
gfx::Rect enclosing_layer_rect =
- gfx::ScaleToEnclosingRect(tile_rect, 1.f / contents_scale_);
+ EnclosingLayerRectFromContentsRect(tile_rect);
return Tile::CreateInfo(i, j, enclosing_layer_rect, tile_rect,
- contents_scale_);
+ contents_scale_, contents_translation_);
}
bool PictureLayerTiling::ShouldCreateTileAt(
@@ -351,7 +358,7 @@ bool PictureLayerTiling::ShouldCreateTileAt(
for (Region::Iterator iter(*layer_invalidation); iter.has_rect();
iter.next()) {
gfx::Rect invalid_content_rect =
- gfx::ScaleToEnclosingRect(iter.rect(), contents_scale_);
+ EnclosingContentsRectFromLayerRect(iter.rect());
if (invalid_content_rect.Intersects(info.content_rect))
return true;
}
@@ -405,10 +412,11 @@ PictureLayerTiling::CoverageIterator::CoverageIterator(
dest_to_content_scale_ = tiling_->contents_scale_ / dest_scale;
- gfx::Rect content_rect =
- gfx::ScaleToEnclosingRect(dest_rect_,
- dest_to_content_scale_,
- dest_to_content_scale_);
+ gfx::RectF dest_rect_in_contents_space(dest_rect_);
+ dest_rect_in_contents_space.Scale(dest_to_content_scale_);
+ dest_rect_in_contents_space.Offset(tiling->contents_translation());
enne (OOO) 2016/08/16 23:02:52 It seems that contents translation is in layer spa
trchen 2016/08/29 10:14:48 It is a cheat to take advantage of transform assoc
+ gfx::Rect content_rect = gfx::ToEnclosingRect(dest_rect_in_contents_space);
+
// IndexFromSrcCoord clamps to valid tile ranges, so it's necessary to
// check for non-intersection first.
content_rect.Intersect(gfx::Rect(tiling_->tiling_size()));
@@ -455,10 +463,11 @@ PictureLayerTiling::CoverageIterator::operator++() {
// edges.
gfx::Rect last_geometry_rect = current_geometry_rect_;
- gfx::Rect content_rect = tiling_->tiling_data_.TileBounds(tile_i_, tile_j_);
-
- current_geometry_rect_ =
- gfx::ScaleToEnclosingRect(content_rect, 1 / dest_to_content_scale_);
+ gfx::RectF tile_bounds_in_dest_space(
+ tiling_->tiling_data_.TileBounds(tile_i_, tile_j_));
+ tile_bounds_in_dest_space.Offset(-tiling_->contents_translation());
enne (OOO) 2016/08/22 22:57:39 I'm not 100% convinced that this satisfies the ass
trchen 2016/08/29 10:14:48 It will because the pre-rounding tile_bounds_in_de
+ tile_bounds_in_dest_space.Scale(1 / dest_to_content_scale_);
+ current_geometry_rect_ = gfx::ToEnclosingRect(tile_bounds_in_dest_space);
current_geometry_rect_.Intersect(dest_rect_);
DCHECK(!current_geometry_rect_.IsEmpty());
@@ -504,6 +513,7 @@ gfx::RectF PictureLayerTiling::CoverageIterator::texture_rect() const {
gfx::RectF texture_rect(current_geometry_rect_);
texture_rect.Scale(dest_to_content_scale_,
dest_to_content_scale_);
+ texture_rect.Offset(tiling_->contents_translation());
texture_rect.Intersect(gfx::RectF(gfx::SizeF(tiling_->tiling_size())));
if (texture_rect.IsEmpty())
return texture_rect;
@@ -555,10 +565,8 @@ void PictureLayerTiling::ComputeTilePriorityRects(
&visible_rect_in_layer_space, &skewport_in_layer_space,
&soon_border_rect_in_layer_space, &eventually_rect_in_layer_space};
gfx::Rect output_rects[4];
- for (size_t i = 0; i < arraysize(input_rects); ++i) {
- output_rects[i] = gfx::ToEnclosingRect(
- gfx::ScaleRect(gfx::RectF(*input_rects[i]), contents_scale_));
- }
+ for (size_t i = 0; i < arraysize(input_rects); ++i)
+ output_rects[i] = EnclosingContentsRectFromLayerRect(*input_rects[i]);
// Make sure the eventually rect is aligned to tile bounds.
output_rects[3] =
tiling_data_.ExpandRectIgnoringBordersToTileBounds(output_rects[3]);
@@ -689,10 +697,8 @@ bool PictureLayerTiling::IsTileOccludedOnCurrentTree(const Tile* tile) const {
if (tile_query_rect.IsEmpty())
return false;
- if (contents_scale_ != 1.f) {
- tile_query_rect =
- gfx::ScaleToEnclosingRect(tile_query_rect, 1.f / contents_scale_);
- }
+ if (contents_scale_ != 1.f || !contents_translation_.IsZero())
+ tile_query_rect = EnclosingLayerRectFromContentsRect(tile_query_rect);
return current_occlusion_in_layer_space_.IsOccluded(tile_query_rect);
}
@@ -774,9 +780,7 @@ PrioritizedTile PictureLayerTiling::MakePrioritizedTile(
DCHECK(tile);
DCHECK(raster_source()->CoversRect(tile->enclosing_layer_rect()))
<< "Recording rect: "
- << gfx::ScaleToEnclosingRect(tile->content_rect(),
- 1.f / tile->contents_scale())
- .ToString();
+ << EnclosingLayerRectFromContentsRect(tile->content_rect()).ToString();
return PrioritizedTile(tile, this,
ComputePriorityForTile(tile, priority_rect_type),
@@ -868,6 +872,8 @@ void PictureLayerTiling::AsValueInto(
base::trace_event::TracedValue* state) const {
state->SetInteger("num_tiles", base::saturated_cast<int>(tiles_.size()));
state->SetDouble("content_scale", contents_scale_);
+ MathUtil::AddToTracedValue("content_translation", contents_translation_,
+ state);
MathUtil::AddToTracedValue("visible_rect", current_visible_rect_, state);
MathUtil::AddToTracedValue("skewport_rect", current_skewport_rect_, state);
MathUtil::AddToTracedValue("soon_rect", current_soon_border_rect_, state);
@@ -885,4 +891,20 @@ size_t PictureLayerTiling::GPUMemoryUsageInBytes() const {
return amount;
}
+gfx::Rect PictureLayerTiling::EnclosingContentsRectFromLayerRect(
+ const gfx::Rect& layer_rect) const {
+ gfx::RectF contents_rect =
+ gfx::ScaleRect(gfx::RectF(layer_rect), contents_scale_);
+ contents_rect.Offset(contents_translation_);
+ return ToEnclosingRect(contents_rect);
+}
+
+gfx::Rect PictureLayerTiling::EnclosingLayerRectFromContentsRect(
+ const gfx::Rect& contents_rect) const {
+ gfx::RectF layer_rect(contents_rect);
+ layer_rect.Offset(-contents_translation_);
+ layer_rect.Scale(1.f / contents_scale_);
+ return ToEnclosingRect(layer_rect);
+}
+
} // namespace cc

Powered by Google App Engine
This is Rietveld 408576698