Commit 757ba9ee authored by hendrikw's avatar hendrikw Committed by Commit bot

cc: Keep tilings texture size in sync

This approach keeps the viewport size as a property of the layerimpl,
doing this makes sure that the pending and active trees are in sync,
because the only way for the size to migrate from the pending to
active tree is via a push.

Since being in sync is all the matters, we avoid having to reach in from
outside of the layer and recreate tilings.

BUG=458750

Review URL: https://codereview.chromium.org/1024633002

Cr-Commit-Position: refs/heads/master@{#321851}
parent 541203fd
...@@ -73,6 +73,8 @@ void PictureLayer::PushPropertiesTo(LayerImpl* base_layer) { ...@@ -73,6 +73,8 @@ void PictureLayer::PushPropertiesTo(LayerImpl* base_layer) {
bool can_use_lcd_text = layer_impl->RasterSourceUsesLCDText(); bool can_use_lcd_text = layer_impl->RasterSourceUsesLCDText();
scoped_refptr<RasterSource> raster_source = scoped_refptr<RasterSource> raster_source =
recording_source_->CreateRasterSource(can_use_lcd_text); recording_source_->CreateRasterSource(can_use_lcd_text);
layer_impl->set_gpu_raster_max_texture_size(
layer_tree_host()->device_viewport_size());
layer_impl->UpdateRasterSource(raster_source, &recording_invalidation_, layer_impl->UpdateRasterSource(raster_source, &recording_invalidation_,
nullptr); nullptr);
DCHECK(recording_invalidation_.IsEmpty()); DCHECK(recording_invalidation_.IsEmpty());
......
...@@ -130,6 +130,7 @@ void PictureLayerImpl::PushPropertiesTo(LayerImpl* base_layer) { ...@@ -130,6 +130,7 @@ void PictureLayerImpl::PushPropertiesTo(LayerImpl* base_layer) {
DCHECK_LE(tilings_->num_tilings(), DCHECK_LE(tilings_->num_tilings(),
layer_tree_impl()->create_low_res_tiling() ? 2u : 1u); layer_tree_impl()->create_low_res_tiling() ? 2u : 1u);
layer_impl->set_gpu_raster_max_texture_size(gpu_raster_max_texture_size_);
layer_impl->UpdateRasterSource(raster_source_, &invalidation_, layer_impl->UpdateRasterSource(raster_source_, &invalidation_,
tilings_.get()); tilings_.get());
DCHECK(invalidation_.IsEmpty()); DCHECK(invalidation_.IsEmpty());
...@@ -689,8 +690,8 @@ gfx::Size PictureLayerImpl::CalculateTileSize( ...@@ -689,8 +690,8 @@ gfx::Size PictureLayerImpl::CalculateTileSize(
// For GPU rasterization, we pick an ideal tile size using the viewport // For GPU rasterization, we pick an ideal tile size using the viewport
// so we don't need any settings. The current approach uses 4 tiles // so we don't need any settings. The current approach uses 4 tiles
// to cover the viewport vertically. // to cover the viewport vertically.
int viewport_width = layer_tree_impl()->device_viewport_size().width(); int viewport_width = gpu_raster_max_texture_size_.width();
int viewport_height = layer_tree_impl()->device_viewport_size().height(); int viewport_height = gpu_raster_max_texture_size_.height();
default_tile_width = viewport_width; default_tile_width = viewport_width;
// Also, increase the height proportionally as the width decreases, and // Also, increase the height proportionally as the width decreases, and
// pad by our border texels to make the tiles exactly match the viewport. // pad by our border texels to make the tiles exactly match the viewport.
......
...@@ -77,6 +77,9 @@ class CC_EXPORT PictureLayerImpl ...@@ -77,6 +77,9 @@ class CC_EXPORT PictureLayerImpl
bool RequiresHighResToDraw() const override; bool RequiresHighResToDraw() const override;
gfx::Rect GetEnclosingRectInTargetSpace() const override; gfx::Rect GetEnclosingRectInTargetSpace() const override;
void set_gpu_raster_max_texture_size(gfx::Size gpu_raster_max_texture_size) {
gpu_raster_max_texture_size_ = gpu_raster_max_texture_size;
}
void UpdateRasterSource(scoped_refptr<RasterSource> raster_source, void UpdateRasterSource(scoped_refptr<RasterSource> raster_source,
Region* new_invalidation, Region* new_invalidation,
const PictureLayerTilingSet* pending_set); const PictureLayerTilingSet* pending_set);
...@@ -173,6 +176,8 @@ class CC_EXPORT PictureLayerImpl ...@@ -173,6 +176,8 @@ class CC_EXPORT PictureLayerImpl
gfx::Rect visible_rect_for_tile_priority_; gfx::Rect visible_rect_for_tile_priority_;
gfx::Rect viewport_rect_for_tile_priority_in_content_space_; gfx::Rect viewport_rect_for_tile_priority_in_content_space_;
gfx::Size gpu_raster_max_texture_size_;
// List of tilings that were used last time we appended quads. This can be // List of tilings that were used last time we appended quads. This can be
// used as an optimization not to remove tilings if they are still being // used as an optimization not to remove tilings if they are still being
// drawn. Note that accessing this vector should only be done in the context // drawn. Note that accessing this vector should only be done in the context
......
...@@ -4950,6 +4950,8 @@ TEST_F(TileSizeTest, TileSizes) { ...@@ -4950,6 +4950,8 @@ TEST_F(TileSizeTest, TileSizes) {
// The +2's below are for border texels. // The +2's below are for border texels.
host_impl_.SetUseGpuRasterization(true); host_impl_.SetUseGpuRasterization(true);
host_impl_.SetViewportSize(gfx::Size(2000, 2000)); host_impl_.SetViewportSize(gfx::Size(2000, 2000));
layer->set_gpu_raster_max_texture_size(host_impl_.device_viewport_size());
result = layer->CalculateTileSize(gfx::Size(10000, 10000)); result = layer->CalculateTileSize(gfx::Size(10000, 10000));
EXPECT_EQ(result.width(), 2000); EXPECT_EQ(result.width(), 2000);
EXPECT_EQ(result.height(), 500 + 2); EXPECT_EQ(result.height(), 500 + 2);
...@@ -4957,6 +4959,7 @@ TEST_F(TileSizeTest, TileSizes) { ...@@ -4957,6 +4959,7 @@ TEST_F(TileSizeTest, TileSizes) {
// Clamp and round-up, when smaller than viewport. // Clamp and round-up, when smaller than viewport.
// Tile-height doubles to 50% when width shrinks to <= 50%. // Tile-height doubles to 50% when width shrinks to <= 50%.
host_impl_.SetViewportSize(gfx::Size(1000, 1000)); host_impl_.SetViewportSize(gfx::Size(1000, 1000));
layer->set_gpu_raster_max_texture_size(host_impl_.device_viewport_size());
result = layer->CalculateTileSize(gfx::Size(447, 10000)); result = layer->CalculateTileSize(gfx::Size(447, 10000));
EXPECT_EQ(result.width(), 448); EXPECT_EQ(result.width(), 448);
EXPECT_EQ(result.height(), 500 + 2); EXPECT_EQ(result.height(), 500 + 2);
......
...@@ -132,6 +132,7 @@ void FakePictureLayerImpl::SetRasterSourceOnPending( ...@@ -132,6 +132,7 @@ void FakePictureLayerImpl::SetRasterSourceOnPending(
DCHECK(layer_tree_impl()->IsPendingTree()); DCHECK(layer_tree_impl()->IsPendingTree());
Region invalidation_temp = invalidation; Region invalidation_temp = invalidation;
const PictureLayerTilingSet* pending_set = nullptr; const PictureLayerTilingSet* pending_set = nullptr;
set_gpu_raster_max_texture_size(layer_tree_impl()->device_viewport_size());
UpdateRasterSource(raster_source, &invalidation_temp, pending_set); UpdateRasterSource(raster_source, &invalidation_temp, pending_set);
} }
......
...@@ -8147,7 +8147,10 @@ TEST_F(LayerTreeHostImplTest, GetPictureLayerImplPairs) { ...@@ -8147,7 +8147,10 @@ TEST_F(LayerTreeHostImplTest, GetPictureLayerImplPairs) {
gfx::Size(10, 10), gfx::Size(10, 10))); gfx::Size(10, 10), gfx::Size(10, 10)));
Region empty_invalidation; Region empty_invalidation;
const PictureLayerTilingSet* null_tiling_set = nullptr; const PictureLayerTilingSet* null_tiling_set = nullptr;
layer->set_gpu_raster_max_texture_size(host_impl_->device_viewport_size());
layer->UpdateRasterSource(pile, &empty_invalidation, null_tiling_set); layer->UpdateRasterSource(pile, &empty_invalidation, null_tiling_set);
nondraw_layer->set_gpu_raster_max_texture_size(
host_impl_->device_viewport_size());
nondraw_layer->UpdateRasterSource(pile, &empty_invalidation, null_tiling_set); nondraw_layer->UpdateRasterSource(pile, &empty_invalidation, null_tiling_set);
layer->AddChild(nondraw_layer.Pass()); layer->AddChild(nondraw_layer.Pass());
...@@ -8265,7 +8268,10 @@ TEST_F(LayerTreeHostImplTest, GetPictureLayerImplPairsWithNonRSLLMembers) { ...@@ -8265,7 +8268,10 @@ TEST_F(LayerTreeHostImplTest, GetPictureLayerImplPairsWithNonRSLLMembers) {
gfx::Size(10, 10), gfx::Size(10, 10))); gfx::Size(10, 10), gfx::Size(10, 10)));
Region empty_invalidation; Region empty_invalidation;
const PictureLayerTilingSet* null_tiling_set = nullptr; const PictureLayerTilingSet* null_tiling_set = nullptr;
layer->set_gpu_raster_max_texture_size(host_impl_->device_viewport_size());
layer->UpdateRasterSource(pile, &empty_invalidation, null_tiling_set); layer->UpdateRasterSource(pile, &empty_invalidation, null_tiling_set);
nondraw_layer->set_gpu_raster_max_texture_size(
host_impl_->device_viewport_size());
nondraw_layer->UpdateRasterSource(pile, &empty_invalidation, null_tiling_set); nondraw_layer->UpdateRasterSource(pile, &empty_invalidation, null_tiling_set);
layer->AddChild(nondraw_layer.Pass()); layer->AddChild(nondraw_layer.Pass());
......
...@@ -485,6 +485,86 @@ class LayerTreeHostTestSetNeedsRedrawRect : public LayerTreeHostTest { ...@@ -485,6 +485,86 @@ class LayerTreeHostTestSetNeedsRedrawRect : public LayerTreeHostTest {
SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestSetNeedsRedrawRect); SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestSetNeedsRedrawRect);
// Ensure the texture size of the pending and active trees are identical when a
// layer is not in the viewport and a resize happens on the viewport
class LayerTreeHostTestGpuRasterDeviceSizeChanged : public LayerTreeHostTest {
public:
LayerTreeHostTestGpuRasterDeviceSizeChanged()
: num_draws_(0), bounds_(500, 64), invalid_rect_(10, 10, 20, 20) {}
void BeginTest() override {
client_.set_fill_with_nonsolid_color(true);
root_layer_ = FakePictureLayer::Create(&client_);
root_layer_->SetIsDrawable(true);
gfx::Transform transform;
// Translate the layer out of the viewport to force it to not update its
// tile size via PushProperties.
transform.Translate(10000.0, 10000.0);
root_layer_->SetTransform(transform);
root_layer_->SetBounds(bounds_);
layer_tree_host()->SetRootLayer(root_layer_);
layer_tree_host()->SetViewportSize(bounds_);
PostSetNeedsCommitToMainThread();
}
void InitializeSettings(LayerTreeSettings* settings) override {
settings->gpu_rasterization_enabled = true;
settings->gpu_rasterization_forced = true;
}
void DrawLayersOnThread(LayerTreeHostImpl* impl) override {
// Perform 2 commits.
if (!num_draws_) {
PostSetNeedsRedrawRectToMainThread(invalid_rect_);
} else {
EndTest();
}
num_draws_++;
}
void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override {
if (num_draws_ == 2) {
auto pending_tree = host_impl->pending_tree();
auto pending_layer_impl =
static_cast<FakePictureLayerImpl*>(pending_tree->root_layer());
EXPECT_NE(pending_layer_impl, nullptr);
auto active_tree = host_impl->pending_tree();
auto active_layer_impl =
static_cast<FakePictureLayerImpl*>(active_tree->root_layer());
EXPECT_NE(pending_layer_impl, nullptr);
auto active_tiling_set = active_layer_impl->picture_layer_tiling_set();
auto active_tiling = active_tiling_set->tiling_at(0);
auto pending_tiling_set = pending_layer_impl->picture_layer_tiling_set();
auto pending_tiling = pending_tiling_set->tiling_at(0);
EXPECT_EQ(
pending_tiling->TilingDataForTesting().max_texture_size().width(),
active_tiling->TilingDataForTesting().max_texture_size().width());
}
}
void DidCommitAndDrawFrame() override {
// On the second commit, resize the viewport.
if (num_draws_ == 1) {
layer_tree_host()->SetViewportSize(gfx::Size(400, 64));
}
}
void AfterTest() override {}
private:
int num_draws_;
const gfx::Size bounds_;
const gfx::Rect invalid_rect_;
FakeContentLayerClient client_;
scoped_refptr<FakePictureLayer> root_layer_;
};
SINGLE_AND_MULTI_THREAD_IMPL_TEST_F(
LayerTreeHostTestGpuRasterDeviceSizeChanged);
class LayerTreeHostTestNoExtraCommitFromInvalidate : public LayerTreeHostTest { class LayerTreeHostTestNoExtraCommitFromInvalidate : public LayerTreeHostTest {
public: public:
void InitializeSettings(LayerTreeSettings* settings) override { void InitializeSettings(LayerTreeSettings* settings) override {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment