diff options
-rw-r--r-- | cc/layers/picture_image_layer_impl.cc | 20 | ||||
-rw-r--r-- | cc/layers/picture_image_layer_impl.h | 9 | ||||
-rw-r--r-- | cc/layers/picture_image_layer_impl_unittest.cc | 85 |
3 files changed, 109 insertions, 5 deletions
diff --git a/cc/layers/picture_image_layer_impl.cc b/cc/layers/picture_image_layer_impl.cc index 7ae9de4..199aec3 100644 --- a/cc/layers/picture_image_layer_impl.cc +++ b/cc/layers/picture_image_layer_impl.cc @@ -27,6 +27,26 @@ scoped_ptr<LayerImpl> PictureImageLayerImpl::CreateLayerImpl( return PictureImageLayerImpl::Create(tree_impl, id()).PassAs<LayerImpl>(); } +void PictureImageLayerImpl::CalculateContentsScale( + float ideal_contents_scale, + float device_scale_factor, + float page_scale_factor, + bool animating_transform_to_screen, + float* contents_scale_x, + float* contents_scale_y, + gfx::Size* content_bounds) { + // CalculateRasterContentsScale always returns 1.f, so make that the ideal + // scale. + ideal_contents_scale = 1.f; + PictureLayerImpl::CalculateContentsScale(ideal_contents_scale, + device_scale_factor, + page_scale_factor, + animating_transform_to_screen, + contents_scale_x, + contents_scale_y, + content_bounds); +} + void PictureImageLayerImpl::GetDebugBorderProperties( SkColor* color, float* width) const { *color = DebugColors::ImageLayerBorderColor(); diff --git a/cc/layers/picture_image_layer_impl.h b/cc/layers/picture_image_layer_impl.h index 4a2db50..c475e53 100644 --- a/cc/layers/picture_image_layer_impl.h +++ b/cc/layers/picture_image_layer_impl.h @@ -17,9 +17,17 @@ class CC_EXPORT PictureImageLayerImpl : public PictureLayerImpl { } virtual ~PictureImageLayerImpl(); + // LayerImpl overrides. virtual const char* LayerTypeAsString() const OVERRIDE; virtual scoped_ptr<LayerImpl> CreateLayerImpl( LayerTreeImpl* tree_impl) OVERRIDE; + virtual void CalculateContentsScale(float ideal_contents_scale, + float device_scale_factor, + float page_scale_factor, + bool animating_transform_to_screen, + float* contents_scale_x, + float* contents_scale_y, + gfx::Size* content_bounds) OVERRIDE; protected: PictureImageLayerImpl(LayerTreeImpl* tree_impl, int id); @@ -33,6 +41,7 @@ class CC_EXPORT PictureImageLayerImpl : public PictureLayerImpl { virtual void GetDebugBorderProperties( SkColor* color, float* width) const OVERRIDE; + private: DISALLOW_COPY_AND_ASSIGN(PictureImageLayerImpl); }; diff --git a/cc/layers/picture_image_layer_impl_unittest.cc b/cc/layers/picture_image_layer_impl_unittest.cc index 9aae4d6..2910da1 100644 --- a/cc/layers/picture_image_layer_impl_unittest.cc +++ b/cc/layers/picture_image_layer_impl_unittest.cc @@ -4,11 +4,14 @@ #include "cc/layers/picture_image_layer_impl.h" +#include "cc/layers/append_quads_data.h" +#include "cc/resources/tile_priority.h" #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/impl_side_painting_settings.h" +#include "cc/test/mock_quad_culler.h" #include "cc/trees/layer_tree_impl.h" #include "testing/gtest/include/gtest/gtest.h" @@ -20,6 +23,9 @@ class TestablePictureImageLayerImpl : public PictureImageLayerImpl { TestablePictureImageLayerImpl(LayerTreeImpl* tree_impl, int id) : PictureImageLayerImpl(tree_impl, id) { } + + PictureLayerTilingSet* tilings() { return tilings_.get(); } + friend class PictureImageLayerImplTest; }; @@ -32,9 +38,22 @@ class PictureImageLayerImplTest : public testing::Test { host_impl_.InitializeRenderer(CreateFakeOutputSurface()); } - scoped_ptr<TestablePictureImageLayerImpl> CreateLayer(int id) { + scoped_ptr<TestablePictureImageLayerImpl> CreateLayer(int id, + WhichTree which_tree) { + LayerTreeImpl* tree = NULL; + switch (which_tree) { + case ACTIVE_TREE: + tree = host_impl_.active_tree(); + break; + case PENDING_TREE: + tree = host_impl_.pending_tree(); + break; + case NUM_TREES: + NOTREACHED(); + break; + } TestablePictureImageLayerImpl* layer = - new TestablePictureImageLayerImpl(host_impl_.pending_tree(), id); + new TestablePictureImageLayerImpl(tree, id); layer->SetBounds(gfx::Size(100, 200)); layer->tilings_.reset(new PictureLayerTilingSet(&tiling_client_, layer->bounds())); @@ -46,14 +65,14 @@ class PictureImageLayerImplTest : public testing::Test { host_impl_.pending_tree()->UpdateDrawProperties(); } - private: + protected: FakeImplProxy proxy_; FakeLayerTreeHostImpl host_impl_; FakePictureLayerTilingClient tiling_client_; }; TEST_F(PictureImageLayerImplTest, CalculateContentsScale) { - scoped_ptr<TestablePictureImageLayerImpl> layer(CreateLayer(1)); + scoped_ptr<TestablePictureImageLayerImpl> layer(CreateLayer(1, PENDING_TREE)); layer->SetDrawsContent(true); float contents_scale_x; @@ -68,7 +87,7 @@ TEST_F(PictureImageLayerImplTest, CalculateContentsScale) { } TEST_F(PictureImageLayerImplTest, AreVisibleResourcesReady) { - scoped_ptr<TestablePictureImageLayerImpl> layer(CreateLayer(1)); + scoped_ptr<TestablePictureImageLayerImpl> layer(CreateLayer(1, PENDING_TREE)); layer->SetBounds(gfx::Size(100, 200)); layer->SetDrawsContent(true); @@ -85,5 +104,61 @@ TEST_F(PictureImageLayerImplTest, AreVisibleResourcesReady) { EXPECT_TRUE(layer->AreVisibleResourcesReady()); } +TEST_F(PictureImageLayerImplTest, IgnoreIdealContentScale) { + scoped_ptr<TestablePictureImageLayerImpl> pending_layer( + CreateLayer(1, PENDING_TREE)); + pending_layer->SetDrawsContent(true); + + // 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; + const float device_scale_factor = 3.f; + const float page_scale_factor = 4.f; + const bool animating_transform_to_screen = false; + float contents_scale_x; + float contents_scale_y; + gfx::Size content_bounds; + pending_layer->CalculateContentsScale(suggested_ideal_contents_scale, + device_scale_factor, + page_scale_factor, + animating_transform_to_screen, + &contents_scale_x, + &contents_scale_y, + &content_bounds); + + // Push to active layer. + host_impl_.ActivatePendingTree(); + scoped_ptr<TestablePictureImageLayerImpl> active_layer( + CreateLayer(1, ACTIVE_TREE)); + pending_layer->PushPropertiesTo(active_layer.get()); + active_layer->CalculateContentsScale(suggested_ideal_contents_scale, + device_scale_factor, + page_scale_factor, + animating_transform_to_screen, + &contents_scale_x, + &contents_scale_y, + &content_bounds); + + // Create tile and resource. + active_layer->tilings()->tiling_at(0)->CreateAllTilesForTesting(); + host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting( + active_layer->tilings()->tiling_at(0)->AllTilesForTesting(), + host_impl_.resource_provider()); + + // Draw. + active_layer->draw_properties().visible_content_rect = + gfx::Rect(active_layer->bounds()); + MockQuadCuller quad_culler; + AppendQuadsData data; + active_layer->WillDraw(DRAW_MODE_SOFTWARE, NULL); + active_layer->AppendQuads(&quad_culler, &data); + active_layer->DidDraw(NULL); + + EXPECT_EQ(DrawQuad::TILED_CONTENT, quad_culler.quad_list()[0]->material); + + // Tiles are ready at correct scale, so should not set had_incomplete_tile. + EXPECT_FALSE(data.had_incomplete_tile); +} + } // namespace } // namespace cc |