Commit 7b4cac77 authored by danakj's avatar danakj Committed by Commit bot

cc: Make consistent use of bounds() versus the pile's size.

In PictureLayerImpl we assume that the pile size matches the bounds but
this is subtley not true when the layer is not part of the visible
frame (ie. not in the RenderSurfaceLayerList).

So use the pile's size consistently everywhere except during drawing
where using the bounds makes some logical sense. And DCHECK they are
equal there.

R=enne, vmpstr

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

Cr-Commit-Position: refs/heads/master@{#301366}
parent db927545
......@@ -10,7 +10,7 @@
#include "cc/test/fake_impl_proxy.h"
#include "cc/test/fake_layer_tree_host_impl.h"
#include "cc/test/fake_output_surface.h"
#include "cc/test/fake_picture_layer_tiling_client.h"
#include "cc/test/fake_picture_pile_impl.h"
#include "cc/test/impl_side_painting_settings.h"
#include "cc/test/test_shared_bitmap_manager.h"
#include "cc/trees/layer_tree_impl.h"
......@@ -40,7 +40,6 @@ class PictureImageLayerImplTest : public testing::Test {
host_impl_(ImplSidePaintingSettings(),
&proxy_,
&shared_bitmap_manager_) {
tiling_client_.SetTileSize(ImplSidePaintingSettings().default_tile_size);
host_impl_.CreatePendingTree();
host_impl_.InitializeRenderer(FakeOutputSurface::Create3d());
}
......@@ -61,10 +60,9 @@ class PictureImageLayerImplTest : public testing::Test {
}
TestablePictureImageLayerImpl* layer =
new TestablePictureImageLayerImpl(tree, id);
layer->SetBounds(gfx::Size(100, 200));
layer->SetContentBounds(gfx::Size(100, 200));
layer->tilings_.reset(new PictureLayerTilingSet(&tiling_client_));
layer->pile_ = tiling_client_.GetPile();
layer->pile_ = FakePicturePileImpl::CreateInfiniteFilledPile();
layer->SetBounds(layer->pile_->tiling_size());
layer->SetContentBounds(layer->pile_->tiling_size());
return make_scoped_ptr(layer);
}
......@@ -73,7 +71,8 @@ class PictureImageLayerImplTest : public testing::Test {
float device_scale_factor,
float page_scale_factor,
float maximum_animation_contents_scale,
bool animating_transform_to_screen) {
bool animating_transform_to_screen,
gfx::Rect viewport_rect) {
layer->draw_properties().ideal_contents_scale = ideal_contents_scale;
layer->draw_properties().device_scale_factor = device_scale_factor;
layer->draw_properties().page_scale_factor = page_scale_factor;
......@@ -81,6 +80,7 @@ class PictureImageLayerImplTest : public testing::Test {
maximum_animation_contents_scale;
layer->draw_properties().screen_space_transform_is_animating =
animating_transform_to_screen;
layer->draw_properties().visible_content_rect = viewport_rect;
bool resourceless_software_draw = false;
layer->UpdateTiles(Occlusion(), resourceless_software_draw);
}
......@@ -89,14 +89,16 @@ class PictureImageLayerImplTest : public testing::Test {
FakeImplProxy proxy_;
FakeLayerTreeHostImpl host_impl_;
TestSharedBitmapManager shared_bitmap_manager_;
FakePictureLayerTilingClient tiling_client_;
};
TEST_F(PictureImageLayerImplTest, CalculateContentsScale) {
scoped_ptr<TestablePictureImageLayerImpl> layer(CreateLayer(1, PENDING_TREE));
layer->SetDrawsContent(true);
layer->DoPostCommitInitializationIfNeeded();
SetupDrawPropertiesAndUpdateTiles(layer.get(), 2.f, 3.f, 4.f, 1.f, false);
gfx::Rect viewport(100, 200);
SetupDrawPropertiesAndUpdateTiles(
layer.get(), 2.f, 3.f, 4.f, 1.f, false, viewport);
EXPECT_FLOAT_EQ(1.f, layer->contents_scale_x());
EXPECT_FLOAT_EQ(1.f, layer->contents_scale_y());
......@@ -108,6 +110,8 @@ TEST_F(PictureImageLayerImplTest, IgnoreIdealContentScale) {
CreateLayer(1, PENDING_TREE));
pending_layer->SetDrawsContent(true);
gfx::Rect viewport(100, 200);
// Set PictureLayerImpl::ideal_contents_scale_ to 2.f which is not equal
// to the content scale used by PictureImageLayerImpl.
const float suggested_ideal_contents_scale = 2.f;
......@@ -120,12 +124,14 @@ TEST_F(PictureImageLayerImplTest, IgnoreIdealContentScale) {
device_scale_factor,
page_scale_factor,
maximum_animation_contents_scale,
animating_transform_to_screen);
animating_transform_to_screen,
viewport);
EXPECT_EQ(1.f, pending_layer->tilings()->tiling_at(0)->contents_scale());
// Push to active layer.
host_impl_.pending_tree()->SetRootLayer(pending_layer.Pass());
host_impl_.ActivateSyncTree();
TestablePictureImageLayerImpl* active_layer =
static_cast<TestablePictureImageLayerImpl*>(
host_impl_.active_tree()->root_layer());
......@@ -134,17 +140,15 @@ TEST_F(PictureImageLayerImplTest, IgnoreIdealContentScale) {
device_scale_factor,
page_scale_factor,
maximum_animation_contents_scale,
animating_transform_to_screen);
animating_transform_to_screen,
viewport);
EXPECT_EQ(1.f, active_layer->tilings()->tiling_at(0)->contents_scale());
// Create tile and resource.
active_layer->tilings()->tiling_at(0)->CreateAllTilesForTesting();
// Create resources for the tiles.
host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(
active_layer->tilings()->tiling_at(0)->AllTilesForTesting());
// Draw.
active_layer->draw_properties().visible_content_rect =
gfx::Rect(active_layer->bounds());
scoped_ptr<RenderPass> render_pass = RenderPass::Create();
AppendQuadsData data;
active_layer->WillDraw(DRAW_MODE_SOFTWARE, nullptr);
......
......@@ -155,6 +155,11 @@ void PictureLayerImpl::AppendQuads(RenderPass* render_pass,
const Occlusion& occlusion_in_content_space,
AppendQuadsData* append_quads_data) {
DCHECK(!needs_post_commit_initialization_);
// The bounds and the pile size may differ if the pile wasn't updated (ie.
// PictureLayer::Update didn't happen). But that should never be the case if
// the layer is part of the visible frame, which is why we're appending quads
// in the first place
DCHECK_EQ(bounds().ToString(), pile_->tiling_size().ToString());
SharedQuadState* shared_quad_state =
render_pass->CreateAndAppendSharedQuadState();
......@@ -163,7 +168,7 @@ void PictureLayerImpl::AppendQuads(RenderPass* render_pass,
PopulateSharedQuadState(shared_quad_state);
AppendDebugBorderQuad(
render_pass, content_bounds(), shared_quad_state, append_quads_data);
render_pass, bounds(), shared_quad_state, append_quads_data);
SolidColorLayerImpl::AppendSolidQuads(render_pass,
occlusion_in_content_space,
......@@ -179,7 +184,7 @@ void PictureLayerImpl::AppendQuads(RenderPass* render_pass,
scaled_draw_transform.Scale(SK_MScalar1 / max_contents_scale,
SK_MScalar1 / max_contents_scale);
gfx::Size scaled_content_bounds =
gfx::ToCeiledSize(gfx::ScaleSize(content_bounds(), max_contents_scale));
gfx::ToCeiledSize(gfx::ScaleSize(bounds(), max_contents_scale));
gfx::Rect scaled_visible_content_rect =
gfx::ScaleToEnclosingRect(visible_content_rect(), max_contents_scale);
scaled_visible_content_rect.Intersect(gfx::Rect(scaled_content_bounds));
......@@ -770,8 +775,10 @@ void PictureLayerImpl::SyncFromActiveLayer(const PictureLayerImpl* other) {
bool synced_high_res_tiling = false;
if (CanHaveTilings()) {
synced_high_res_tiling = tilings_->SyncTilings(
*other->tilings_, bounds(), invalidation_, MinimumContentsScale());
synced_high_res_tiling = tilings_->SyncTilings(*other->tilings_,
pile_->tiling_size(),
invalidation_,
MinimumContentsScale());
} else {
RemoveAllTilings();
}
......@@ -793,7 +800,7 @@ void PictureLayerImpl::SyncTiling(
const PictureLayerTiling* tiling) {
if (!CanHaveTilingWithScale(tiling->contents_scale()))
return;
tilings_->AddTiling(tiling->contents_scale(), bounds());
tilings_->AddTiling(tiling->contents_scale(), pile_->tiling_size());
// If this tree needs update draw properties, then the tiling will
// get updated prior to drawing or activation. If this tree does not
......@@ -812,6 +819,7 @@ void PictureLayerImpl::SyncTiling(
void PictureLayerImpl::GetContentsResourceId(
ResourceProvider::ResourceId* resource_id,
gfx::Size* resource_size) const {
DCHECK_EQ(bounds().ToString(), pile_->tiling_size().ToString());
gfx::Rect content_rect(bounds());
PictureLayerTilingSet::CoverageIterator iter(
tilings_.get(), 1.f, content_rect, ideal_contents_scale_);
......@@ -864,7 +872,8 @@ PictureLayerTiling* PictureLayerImpl::AddTiling(float contents_scale) {
DCHECK(CanHaveTilingWithScale(contents_scale)) <<
"contents_scale: " << contents_scale;
PictureLayerTiling* tiling = tilings_->AddTiling(contents_scale, bounds());
PictureLayerTiling* tiling =
tilings_->AddTiling(contents_scale, pile_->tiling_size());
DCHECK(pile_->HasRecordings());
......@@ -1067,8 +1076,8 @@ void PictureLayerImpl::RecalculateRasterScales() {
// See crbug.com/422341.
float maximum_scale = draw_properties().maximum_animation_contents_scale;
if (maximum_scale) {
gfx::Size bounds_at_maximum_scale =
gfx::ToCeiledSize(gfx::ScaleSize(bounds(), maximum_scale));
gfx::Size bounds_at_maximum_scale = gfx::ToCeiledSize(
gfx::ScaleSize(pile_->tiling_size(), maximum_scale));
if (bounds_at_maximum_scale.GetArea() <=
layer_tree_impl()->device_viewport_size().GetArea())
can_raster_at_maximum_scale = true;
......@@ -1084,11 +1093,11 @@ void PictureLayerImpl::RecalculateRasterScales() {
// If this layer would create zero or one tiles at this content scale,
// don't create a low res tiling.
gfx::Size content_bounds =
gfx::ToCeiledSize(gfx::ScaleSize(bounds(), raster_contents_scale_));
gfx::Size tile_size = CalculateTileSize(content_bounds);
bool tile_covers_bounds = tile_size.width() >= content_bounds.width() &&
tile_size.height() >= content_bounds.height();
gfx::Size raster_bounds = gfx::ToCeiledSize(
gfx::ScaleSize(pile_->tiling_size(), raster_contents_scale_));
gfx::Size tile_size = CalculateTileSize(raster_bounds);
bool tile_covers_bounds = tile_size.width() >= raster_bounds.width() &&
tile_size.height() >= raster_bounds.height();
if (tile_size.IsEmpty() || tile_covers_bounds) {
low_res_raster_contents_scale_ = raster_contents_scale_;
return;
......@@ -1185,7 +1194,8 @@ float PictureLayerImpl::MinimumContentsScale() const {
// then it will end up having less than one pixel of content in that
// dimension. Bump the minimum contents scale up in this case to prevent
// this from happening.
int min_dimension = std::min(bounds().width(), bounds().height());
int min_dimension =
std::min(pile_->tiling_size().width(), pile_->tiling_size().height());
if (!min_dimension)
return setting_min;
......@@ -1318,10 +1328,11 @@ void PictureLayerImpl::AsValueInto(base::debug::TracedValue* state) const {
state->EndArray();
state->BeginArray("coverage_tiles");
for (PictureLayerTilingSet::CoverageIterator iter(tilings_.get(),
1.f,
gfx::Rect(content_bounds()),
ideal_contents_scale_);
for (PictureLayerTilingSet::CoverageIterator iter(
tilings_.get(),
1.f,
gfx::Rect(pile_->tiling_size()),
ideal_contents_scale_);
iter;
++iter) {
state->BeginDictionary();
......
......@@ -2222,13 +2222,17 @@ TEST_F(PictureLayerImplTest, SyncTilingAfterGpuRasterizationToggles) {
}
TEST_F(PictureLayerImplTest, HighResCreatedWhenBoundsShrink) {
SetupDefaultTrees(gfx::Size(10, 10));
gfx::Size tile_size(100, 100);
scoped_refptr<FakePicturePileImpl> active_pile =
FakePicturePileImpl::CreateFilledPile(tile_size, gfx::Size(10, 10));
SetupPendingTree(active_pile);
ActivateTree();
host_impl_.active_tree()->UpdateDrawProperties();
EXPECT_FALSE(host_impl_.active_tree()->needs_update_draw_properties());
SetupDrawPropertiesAndUpdateTiles(
active_layer_, 0.5f, 0.5f, 0.5f, 0.5f, false);
pending_layer_->tilings()->RemoveAllTilings();
active_layer_->tilings()->RemoveAllTilings();
PictureLayerTiling* tiling = active_layer_->AddTiling(0.5f);
active_layer_->AddTiling(1.5f);
......@@ -2239,18 +2243,13 @@ TEST_F(PictureLayerImplTest, HighResCreatedWhenBoundsShrink) {
ASSERT_EQ(3u, active_layer_->tilings()->num_tilings());
ASSERT_EQ(tiling, active_layer_->tilings()->TilingAtScale(0.5f));
pending_layer_->tilings()->RemoveAllTilings();
ASSERT_EQ(0u, pending_layer_->tilings()->num_tilings());
// Now, set the bounds to be 1x1 (so that minimum contents scale becomes
// 1.0f). Note that we should also ensure that the pending layer needs post
// commit initialization, since this is what would happen during commit. In
// other words we want the pending layer to sync from the active layer.
pending_layer_->SetBounds(gfx::Size(1, 1));
pending_layer_->SetNeedsPostCommitInitialization();
pending_layer_->set_twin_layer(nullptr);
active_layer_->set_twin_layer(nullptr);
EXPECT_TRUE(pending_layer_->needs_post_commit_initialization());
scoped_refptr<FakePicturePileImpl> pending_pile =
FakePicturePileImpl::CreateFilledPile(tile_size, gfx::Size(1, 1));
SetupPendingTree(pending_pile);
// Update the draw properties: sync from active tree should happen here.
host_impl_.pending_tree()->UpdateDrawProperties();
......
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