Skip to content

Commit

Permalink
cc: Move prepaint region calculations to the tiling set.
Browse files Browse the repository at this point in the history
This patch moves prepaint region calculations from the tiling to the
tiling set. This ensures that new tilings get proper skewport
information. It also allows us to retrieve prepaint regions
independently of tilings present, which is useful for iterating images.

R=enne, danakj
CQ_INCLUDE_TRYBOTS=tryserver.blink:linux_blink_rel

Review-Url: https://codereview.chromium.org/1939963002
Cr-Commit-Position: refs/heads/master@{#391645}
  • Loading branch information
vmpstr authored and Commit bot committed May 4, 2016
1 parent ad789e3 commit cf11133
Show file tree
Hide file tree
Showing 18 changed files with 914 additions and 1,494 deletions.
1 change: 0 additions & 1 deletion cc/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -977,7 +977,6 @@ test("cc_perftests") {
"surfaces/surface_aggregator_perftest.cc",
"test/cc_test_suite.cc",
"test/run_all_perftests.cc",
"tiles/picture_layer_tiling_perftest.cc",
"tiles/tile_manager_perftest.cc",
"trees/layer_tree_host_common_perftest.cc",
"trees/layer_tree_host_perftest.cc",
Expand Down
1 change: 0 additions & 1 deletion cc/cc_tests.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,6 @@
'surfaces/surface_aggregator_perftest.cc',
'test/cc_test_suite.cc',
'test/run_all_perftests.cc',
'tiles/picture_layer_tiling_perftest.cc',
'tiles/tile_manager_perftest.cc',
'trees/layer_tree_host_common_perftest.cc',
'trees/layer_tree_host_perftest.cc',
Expand Down
2 changes: 1 addition & 1 deletion cc/debug/rasterize_and_record_benchmark_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ void RasterizeAndRecordBenchmarkImpl::RunOnLayer(PictureLayerImpl* layer) {
PictureLayerTilingSet::Create(
layer->GetTree(), &client, settings.tiling_interest_area_padding,
settings.skewport_target_time_in_seconds,
settings.skewport_extrapolation_limit_in_content_pixels);
settings.skewport_extrapolation_limit_in_screen_pixels);

PictureLayerTiling* tiling =
tiling_set->AddTiling(1.f, layer->GetRasterSource());
Expand Down
4 changes: 2 additions & 2 deletions cc/layers/picture_layer_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ void PictureLayerImpl::UpdateViewportRectForTilePriorityInContentSpace() {
gfx::Rect padded_bounds(bounds());
int padding_amount = layer_tree_impl()
->settings()
.skewport_extrapolation_limit_in_content_pixels *
.skewport_extrapolation_limit_in_screen_pixels *
MaximumTilingContentsScale();
padded_bounds.Inset(-padding_amount, -padding_amount);
visible_rect_in_content_space.Intersect(padded_bounds);
Expand Down Expand Up @@ -1192,7 +1192,7 @@ PictureLayerImpl::CreatePictureLayerTilingSet() {
layer_tree_impl()->use_gpu_rasterization()
? settings.gpu_rasterization_skewport_target_time_in_seconds
: settings.skewport_target_time_in_seconds,
settings.skewport_extrapolation_limit_in_content_pixels);
settings.skewport_extrapolation_limit_in_screen_pixels);
}

void PictureLayerImpl::UpdateIdealScales() {
Expand Down
3 changes: 2 additions & 1 deletion cc/layers/picture_layer_impl_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2277,7 +2277,8 @@ TEST_F(PictureLayerImplTest, ShareTilesOnNextFrame) {
EXPECT_TRUE(pending_tiling->TileAt(1, 1));

// Drop the tiles on the active tree and recreate them.
active_tiling->ComputeTilePriorityRects(gfx::Rect(), 1.f, 1.0, Occlusion());
active_layer_->tilings()->UpdateTilePriorities(gfx::Rect(), 1.f, 1.0,
Occlusion(), true);
EXPECT_TRUE(active_tiling->AllTilesForTesting().empty());
active_tiling->CreateAllTilesForTesting();

Expand Down
2 changes: 1 addition & 1 deletion cc/proto/layer_tree_settings.proto
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ message LayerTreeSettings {
optional Size minimum_occlusion_tracking_size = 29;
optional uint32 tiling_interest_area_padding = 30;
optional float skewport_target_time_in_seconds = 31;
optional int32 skewport_extrapolation_limit_in_content_pixels = 32;
optional int32 skewport_extrapolation_limit_in_screen_pixels = 32;
optional uint32 max_memory_for_prepaint_percentage = 33;
optional bool use_zero_copy = 35;
optional bool use_partial_raster = 36;
Expand Down
202 changes: 21 additions & 181 deletions cc/tiles/picture_layer_tiling.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,40 +29,13 @@
#include "ui/gfx/geometry/size_conversions.h"

namespace cc {
namespace {

const float kSoonBorderDistanceViewportPercentage = 0.15f;
const float kMaxSoonBorderDistanceInScreenPixels = 312.f;

} // namespace

std::unique_ptr<PictureLayerTiling> PictureLayerTiling::Create(
WhichTree tree,
float contents_scale,
scoped_refptr<RasterSource> raster_source,
PictureLayerTilingClient* client,
size_t tiling_interest_area_padding,
float skewport_target_time_in_seconds,
int skewport_extrapolation_limit_in_content_pixels) {
return base::WrapUnique(new PictureLayerTiling(
tree, contents_scale, raster_source, client, tiling_interest_area_padding,
skewport_target_time_in_seconds,
skewport_extrapolation_limit_in_content_pixels));
}

PictureLayerTiling::PictureLayerTiling(
WhichTree tree,
float contents_scale,
scoped_refptr<RasterSource> raster_source,
PictureLayerTilingClient* client,
size_t tiling_interest_area_padding,
float skewport_target_time_in_seconds,
int skewport_extrapolation_limit_in_content_pixels)
: tiling_interest_area_padding_(tiling_interest_area_padding),
skewport_target_time_in_seconds_(skewport_target_time_in_seconds),
skewport_extrapolation_limit_in_content_pixels_(
skewport_extrapolation_limit_in_content_pixels),
contents_scale_(contents_scale),
PictureLayerTilingClient* client)
: contents_scale_(contents_scale),
client_(client),
tree_(tree),
raster_source_(raster_source),
Expand All @@ -75,8 +48,7 @@ PictureLayerTiling::PictureLayerTiling(
has_skewport_rect_tiles_(false),
has_soon_border_rect_tiles_(false),
has_eventually_rect_tiles_(false),
all_tiles_done_(true),
invalidated_since_last_compute_priority_rects_(false) {
all_tiles_done_(true) {
DCHECK(!raster_source->IsSolidColor());
gfx::Size content_bounds =
gfx::ScaleToCeiledSize(raster_source_->GetSize(), contents_scale);
Expand All @@ -95,17 +67,6 @@ PictureLayerTiling::PictureLayerTiling(
PictureLayerTiling::~PictureLayerTiling() {
}

// static
float PictureLayerTiling::CalculateSoonBorderDistance(
const gfx::Rect& visible_rect_in_content_space,
float content_to_screen_scale) {
float max_dimension = std::max(visible_rect_in_content_space.width(),
visible_rect_in_content_space.height());
return std::min(
kMaxSoonBorderDistanceInScreenPixels / content_to_screen_scale,
max_dimension * kSoonBorderDistanceViewportPercentage);
}

Tile* PictureLayerTiling::CreateTile(const Tile::CreateInfo& info) {
const int i = info.tiling_i_index;
const int j = info.tiling_j_index;
Expand Down Expand Up @@ -289,7 +250,6 @@ void PictureLayerTiling::SetRasterSourceAndResize(

void PictureLayerTiling::Invalidate(const Region& layer_invalidation) {
DCHECK(tree_ != ACTIVE_TREE || !client_->GetPendingOrActiveTwinTiling(this));
invalidated_since_last_compute_priority_rects_ = true;
RemoveTilesInRegion(layer_invalidation, true /* recreate tiles */);
}

Expand Down Expand Up @@ -575,69 +535,12 @@ void PictureLayerTiling::Reset() {
all_tiles_done_ = true;
}

gfx::Rect PictureLayerTiling::ComputeSkewport(
double current_frame_time_in_seconds,
const gfx::Rect& visible_rect_in_content_space) const {
gfx::Rect skewport = visible_rect_in_content_space;
if (skewport.IsEmpty())
return skewport;

if (visible_rect_history_[1].frame_time_in_seconds == 0.0)
return skewport;

double time_delta = current_frame_time_in_seconds -
visible_rect_history_[1].frame_time_in_seconds;
if (time_delta == 0.0)
return skewport;

double extrapolation_multiplier =
skewport_target_time_in_seconds_ / time_delta;

int old_x = visible_rect_history_[1].visible_rect_in_content_space.x();
int old_y = visible_rect_history_[1].visible_rect_in_content_space.y();
int old_right =
visible_rect_history_[1].visible_rect_in_content_space.right();
int old_bottom =
visible_rect_history_[1].visible_rect_in_content_space.bottom();

int new_x = visible_rect_in_content_space.x();
int new_y = visible_rect_in_content_space.y();
int new_right = visible_rect_in_content_space.right();
int new_bottom = visible_rect_in_content_space.bottom();

// Compute the maximum skewport based on
// |skewport_extrapolation_limit_in_content_pixels_|.
gfx::Rect max_skewport = skewport;
max_skewport.Inset(-skewport_extrapolation_limit_in_content_pixels_,
-skewport_extrapolation_limit_in_content_pixels_);

// Inset the skewport by the needed adjustment.
skewport.Inset(extrapolation_multiplier * (new_x - old_x),
extrapolation_multiplier * (new_y - old_y),
extrapolation_multiplier * (old_right - new_right),
extrapolation_multiplier * (old_bottom - new_bottom));

// Ensure that visible rect is contained in the skewport.
skewport.Union(visible_rect_in_content_space);

// Clip the skewport to |max_skewport|. This needs to happen after the
// union in case intersecting would have left the empty rect.
skewport.Intersect(max_skewport);

// Due to limits in int's representation, it is possible that the two
// operations above (union and intersect) result in an empty skewport. To
// avoid any unpleasant situations like that, union the visible rect again to
// ensure that skewport.Contains(visible_rect_in_content_space) is always
// true.
skewport.Union(visible_rect_in_content_space);

return skewport;
}

bool PictureLayerTiling::ComputeTilePriorityRects(
const gfx::Rect& viewport_in_layer_space,
void PictureLayerTiling::ComputeTilePriorityRects(
const gfx::Rect& visible_rect_in_layer_space,
const gfx::Rect& skewport_in_layer_space,
const gfx::Rect& soon_border_rect_in_layer_space,
const gfx::Rect& eventually_rect_in_layer_space,
float ideal_contents_scale,
double current_frame_time_in_seconds,
const Occlusion& occlusion_in_layer_space) {
// If we have, or had occlusions, mark the tiles as 'not done' to ensure that
// we reiterate the tiles for rasterization.
Expand All @@ -646,87 +549,24 @@ bool PictureLayerTiling::ComputeTilePriorityRects(
set_all_tiles_done(false);
}

bool invalidated = invalidated_since_last_compute_priority_rects_;
invalidated_since_last_compute_priority_rects_ = false;
if (!NeedsUpdateForFrameAtTimeAndViewport(current_frame_time_in_seconds,
viewport_in_layer_space)) {
// This should never be zero for the purposes of has_ever_been_updated().
DCHECK_NE(current_frame_time_in_seconds, 0.0);
return invalidated;
}

const float content_to_screen_scale = ideal_contents_scale / contents_scale_;

// We want to compute the visible rect and eventually rect from it in the
// space of the tiling. But the visible rect (viewport) can be arbitrarily
// positioned, so be careful when scaling it since we can exceed integer
// bounds.
gfx::Rect eventually_rect;
gfx::Rect visible_rect_in_content_space;

// We keep things as floats in here.
{
gfx::RectF visible_rectf_in_content_space =
gfx::ScaleRect(gfx::RectF(viewport_in_layer_space), contents_scale_);

// Determine if the eventually rect will even touch the tiling, if it's too
// far away just treat it as empty so we don't exceed integer bounds.
const float pad_in_content_space =
tiling_interest_area_padding_ / content_to_screen_scale;
gfx::RectF eventually_rectf = visible_rectf_in_content_space;
// If the visible rect is empty, keep the eventually rect as empty.
if (!eventually_rectf.IsEmpty()) {
eventually_rectf.Inset(-pad_in_content_space, -pad_in_content_space);

// If the eventually rect will touch the tiling, then we convert back to
// integers and set the visible and eventually rects.
auto bounds = gfx::RectF(gfx::SizeF(tiling_size()));
if (eventually_rectf.Intersects(bounds)) {
visible_rect_in_content_space =
gfx::ToEnclosingRect(visible_rectf_in_content_space);
eventually_rect = gfx::ToEnclosingRect(eventually_rectf);
}
}
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_));
}
DCHECK_EQ(visible_rect_in_content_space.IsEmpty(), eventually_rect.IsEmpty());

// Now we have an empty visible/eventually rect if it's not useful and a
// non-empty one if it is. We can compute the final eventually rect.
eventually_rect =
tiling_data_.ExpandRectIgnoringBordersToTileBounds(eventually_rect);
// Make sure the eventually rect is aligned to tile bounds.
output_rects[3] =
tiling_data_.ExpandRectIgnoringBordersToTileBounds(output_rects[3]);

DCHECK(eventually_rect.IsEmpty() ||
gfx::Rect(tiling_size()).Contains(eventually_rect))
<< "tiling_size: " << tiling_size().ToString()
<< " eventually_rect: " << eventually_rect.ToString();

if (tiling_size().IsEmpty()) {
UpdateVisibleRectHistory(current_frame_time_in_seconds,
visible_rect_in_content_space);
last_viewport_in_layer_space_ = viewport_in_layer_space;
return false;
}

// Calculate the skewport.
gfx::Rect skewport = ComputeSkewport(current_frame_time_in_seconds,
visible_rect_in_content_space);
DCHECK(skewport.Contains(visible_rect_in_content_space));

// Calculate the soon border rect.
gfx::Rect soon_border_rect = visible_rect_in_content_space;
float border = CalculateSoonBorderDistance(visible_rect_in_content_space,
content_to_screen_scale);
soon_border_rect.Inset(-border, -border, -border, -border);

UpdateVisibleRectHistory(current_frame_time_in_seconds,
visible_rect_in_content_space);
last_viewport_in_layer_space_ = viewport_in_layer_space;

SetTilePriorityRects(content_to_screen_scale, visible_rect_in_content_space,
skewport, soon_border_rect, eventually_rect,
SetTilePriorityRects(content_to_screen_scale, output_rects[0],
output_rects[1], output_rects[2], output_rects[3],
occlusion_in_layer_space);
SetLiveTilesRect(eventually_rect);
return true;
SetLiveTilesRect(output_rects[3]);
}

void PictureLayerTiling::SetTilePriorityRects(
Expand Down
Loading

0 comments on commit cf11133

Please sign in to comment.