| Index: cc/tiles/picture_layer_tiling.cc
|
| diff --git a/cc/tiles/picture_layer_tiling.cc b/cc/tiles/picture_layer_tiling.cc
|
| index b429260472a1a0d523c50d1565cbc9309a2cabe3..17f1fed579570d783a83ffebdf803cf39b311554 100644
|
| --- a/cc/tiles/picture_layer_tiling.cc
|
| +++ b/cc/tiles/picture_layer_tiling.cc
|
| @@ -32,29 +32,36 @@ namespace cc {
|
|
|
| PictureLayerTiling::PictureLayerTiling(
|
| WhichTree tree,
|
| - float contents_scale,
|
| + const ScaleTranslate2d& raster_transform,
|
| scoped_refptr<RasterSource> raster_source,
|
| PictureLayerTilingClient* client,
|
| float min_preraster_distance,
|
| float max_preraster_distance)
|
| - : contents_scale_(contents_scale),
|
| + : raster_transform_(raster_transform),
|
| client_(client),
|
| tree_(tree),
|
| raster_source_(raster_source),
|
| min_preraster_distance_(min_preraster_distance),
|
| max_preraster_distance_(max_preraster_distance) {
|
| DCHECK(!raster_source->IsSolidColor());
|
| - gfx::Size content_bounds =
|
| - gfx::ScaleToCeiledSize(raster_source_->GetSize(), contents_scale_);
|
| - gfx::Size tile_size = client_->CalculateTileSize(content_bounds);
|
| + DCHECK_GE(raster_transform.translation().x(), 0.f);
|
| + DCHECK_LT(raster_transform.translation().x(), 1.f);
|
| + DCHECK_GE(raster_transform.translation().y(), 0.f);
|
| + DCHECK_LT(raster_transform.translation().y(), 1.f);
|
|
|
| - DCHECK(!gfx::ScaleToFlooredSize(raster_source_->GetSize(), contents_scale_)
|
| + DCHECK(!gfx::ScaleToFlooredSize(raster_source_->GetSize(),
|
| + raster_transform.scale())
|
| .IsEmpty())
|
| << "Tiling created with scale too small as contents become empty."
|
| << " Layer bounds: " << raster_source_->GetSize().ToString()
|
| - << " Raster scale: " << contents_scale_;
|
| -
|
| - tiling_data_.SetTilingSize(content_bounds);
|
| + << " Raster transform: " << raster_transform_.ToString();
|
| +
|
| + gfx::Rect content_bounds_rect =
|
| + EnclosingContentsRectFromLayerRect(gfx::Rect(raster_source_->GetSize()));
|
| + gfx::Size tiling_size = gfx::Size(content_bounds_rect.bottom_right().x(),
|
| + content_bounds_rect.bottom_right().y());
|
| + tiling_data_.SetTilingSize(tiling_size);
|
| + gfx::Size tile_size = client_->CalculateTileSize(tiling_size);
|
| tiling_data_.SetMaxTextureSize(tile_size);
|
| }
|
|
|
| @@ -108,7 +115,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);
|
| }
|
| @@ -167,12 +174,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
|
| @@ -187,7 +195,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 =
|
| @@ -198,7 +205,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;
|
| @@ -263,7 +270,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.
|
| @@ -300,9 +307,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(this, i, j, enclosing_layer_rect, tile_rect,
|
| - contents_scale_);
|
| + raster_transform_);
|
| }
|
|
|
| bool PictureLayerTiling::ShouldCreateTileAt(
|
| @@ -342,7 +349,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;
|
| }
|
| @@ -371,12 +378,16 @@ PictureLayerTiling::CoverageIterator::CoverageIterator(
|
| const PictureLayerTiling* tiling,
|
| float coverage_scale,
|
| const gfx::Rect& coverage_rect)
|
| - : tiling_(tiling), coverage_rect_(coverage_rect) {
|
| + : tiling_(tiling),
|
| + coverage_rect_(coverage_rect),
|
| + coverage_to_content_(
|
| + ScaleTranslate2d::PreScale(tiling->raster_transform(),
|
| + 1.f / coverage_scale)) {
|
| DCHECK(tiling_);
|
| // In order to avoid artifacts in geometry_rect scaling and clamping to ints,
|
| // the |coverage_scale| should always be at least as big as the tiling's
|
| // raster scales.
|
| - DCHECK_GE(coverage_scale, tiling_->contents_scale_);
|
| + DCHECK_GE(coverage_scale, tiling_->raster_transform_.scale());
|
|
|
| // Clamp |coverage_rect| to the bounds of this tiling's raster source.
|
| coverage_rect_max_bounds_ =
|
| @@ -385,8 +396,6 @@ PictureLayerTiling::CoverageIterator::CoverageIterator(
|
| if (coverage_rect_.IsEmpty())
|
| return;
|
|
|
| - coverage_to_content_scale_ = tiling_->contents_scale_ / coverage_scale;
|
| -
|
| // Find the indices of the texel samples that enclose the rect we want to
|
| // cover.
|
| // Because we don't know the target transform at this point, we have to be
|
| @@ -394,8 +403,8 @@ PictureLayerTiling::CoverageIterator::CoverageIterator(
|
| // snapped to a pixel sample) inside of the content rect may be sampled.
|
| // This code maps the boundary points into contents space, then find out the
|
| // enclosing texture samples. For example, assume we have:
|
| - // dest_scale : content_scale = 1.23 : 1
|
| - // dest_rect = (l:123, t:234, r:345, b:456)
|
| + // coverage_scale : content_scale = 1.23 : 1
|
| + // coverage_rect = (l:123, t:234, r:345, b:456)
|
| // Then it follows that:
|
| // content_rect = (l:100.00, t:190.24, r:280.49, b:370.73)
|
| // Without MSAA, the sample point of a texel is at the center of that texel,
|
| @@ -404,7 +413,7 @@ PictureLayerTiling::CoverageIterator::CoverageIterator(
|
| // Or in integer index:
|
| // wanted_texels(integer index) = (l:99, t:189, r:280, b:371)
|
| gfx::RectF content_rect =
|
| - gfx::ScaleRect(gfx::RectF(coverage_rect_), coverage_to_content_scale_);
|
| + coverage_to_content_.TransformRect(gfx::RectF(coverage_rect_));
|
| content_rect.Offset(-0.5f, -0.5f);
|
| gfx::Rect wanted_texels = gfx::ToEnclosingRect(content_rect);
|
|
|
| @@ -466,7 +475,7 @@ PictureLayerTiling::CoverageIterator::operator++() {
|
| // Convert texel_extent to coverage scale, which is what we have to report
|
| // geometry_rect in.
|
| current_geometry_rect_ = gfx::ToEnclosedRect(
|
| - gfx::ScaleRect(texel_extent, 1.f / coverage_to_content_scale_));
|
| + coverage_to_content_.TransformRectReverse(texel_extent));
|
| {
|
| // Adjust external edges to cover the whole layer in dest space.
|
| //
|
| @@ -529,12 +538,9 @@ gfx::RectF PictureLayerTiling::CoverageIterator::texture_rect() const {
|
| auto tex_origin = gfx::PointF(
|
| tiling_->tiling_data_.TileBoundsWithBorder(tile_i_, tile_j_).origin());
|
|
|
| - // Convert from dest space => content space => texture space.
|
| + // Convert from coverage space => content space => texture space.
|
| gfx::RectF texture_rect(current_geometry_rect_);
|
| - texture_rect.Scale(coverage_to_content_scale_);
|
| - texture_rect.Intersect(gfx::RectF(gfx::SizeF(tiling_->tiling_size())));
|
| - if (texture_rect.IsEmpty())
|
| - return texture_rect;
|
| + texture_rect = coverage_to_content_.TransformRect(texture_rect);
|
| texture_rect.Offset(-tex_origin.OffsetFromOrigin());
|
|
|
| return texture_rect;
|
| @@ -577,16 +583,15 @@ void PictureLayerTiling::ComputeTilePriorityRects(
|
| set_all_tiles_done(false);
|
| }
|
|
|
| - float content_to_screen_scale = ideal_contents_scale / contents_scale_;
|
| + const float content_to_screen_scale =
|
| + ideal_contents_scale / raster_transform_.scale();
|
|
|
| const gfx::Rect* input_rects[] = {
|
| &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]);
|
| @@ -731,10 +736,7 @@ 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_);
|
| - }
|
| + tile_query_rect = EnclosingLayerRectFromContentsRect(tile_query_rect);
|
| return current_occlusion_in_layer_space_.IsOccluded(tile_query_rect);
|
| }
|
|
|
| @@ -825,7 +827,8 @@ PrioritizedTile PictureLayerTiling::MakePrioritizedTile(
|
| PriorityRectType priority_rect_type) const {
|
| DCHECK(tile);
|
| DCHECK(raster_source()->CoversRect(tile->enclosing_layer_rect()))
|
| - << "Tile layer rect: " << tile->enclosing_layer_rect().ToString();
|
| + << "Recording rect: "
|
| + << EnclosingLayerRectFromContentsRect(tile->content_rect()).ToString();
|
|
|
| UpdateRequiredStatesOnTile(tile);
|
| const auto& tile_priority = ComputePriorityForTile(tile, priority_rect_type);
|
| @@ -925,7 +928,13 @@ void PictureLayerTiling::GetAllPrioritizedTilesForTracing(
|
| 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());
|
| + state->SetDouble("content_scale", contents_scale_key());
|
| +
|
| + state->BeginArray("raster_transform");
|
| + state->AppendDouble(raster_transform_.scale());
|
| + state->AppendDouble(raster_transform_.translation().x());
|
| + state->AppendDouble(raster_transform_.translation().y());
|
| + state->EndArray();
|
|
|
| MathUtil::AddToTracedValue("visible_rect", current_visible_rect_, state);
|
| MathUtil::AddToTracedValue("skewport_rect", current_skewport_rect_, state);
|
| @@ -944,4 +953,16 @@ size_t PictureLayerTiling::GPUMemoryUsageInBytes() const {
|
| return amount;
|
| }
|
|
|
| +gfx::Rect PictureLayerTiling::EnclosingContentsRectFromLayerRect(
|
| + const gfx::Rect& layer_rect) const {
|
| + return ToEnclosingRect(
|
| + raster_transform_.TransformRect(gfx::RectF(layer_rect)));
|
| +}
|
| +
|
| +gfx::Rect PictureLayerTiling::EnclosingLayerRectFromContentsRect(
|
| + const gfx::Rect& contents_rect) const {
|
| + return ToEnclosingRect(
|
| + raster_transform_.TransformRectReverse(gfx::RectF(contents_rect)));
|
| +}
|
| +
|
| } // namespace cc
|
|
|