| OLD | NEW |
| (Empty) |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "cc/layers/picture_image_layer_impl.h" | |
| 6 | |
| 7 #include "base/memory/ptr_util.h" | |
| 8 #include "base/threading/thread_task_runner_handle.h" | |
| 9 #include "cc/layers/append_quads_data.h" | |
| 10 #include "cc/quads/draw_quad.h" | |
| 11 #include "cc/test/fake_impl_task_runner_provider.h" | |
| 12 #include "cc/test/fake_layer_tree_host_impl.h" | |
| 13 #include "cc/test/fake_output_surface.h" | |
| 14 #include "cc/test/fake_raster_source.h" | |
| 15 #include "cc/test/test_shared_bitmap_manager.h" | |
| 16 #include "cc/test/test_task_graph_runner.h" | |
| 17 #include "cc/tiles/tile_priority.h" | |
| 18 #include "cc/trees/layer_tree_impl.h" | |
| 19 #include "testing/gtest/include/gtest/gtest.h" | |
| 20 | |
| 21 namespace cc { | |
| 22 namespace { | |
| 23 | |
| 24 class TestablePictureImageLayerImpl : public PictureImageLayerImpl { | |
| 25 public: | |
| 26 TestablePictureImageLayerImpl(LayerTreeImpl* tree_impl, int id) | |
| 27 : PictureImageLayerImpl(tree_impl, id, false) {} | |
| 28 | |
| 29 std::unique_ptr<LayerImpl> CreateLayerImpl( | |
| 30 LayerTreeImpl* tree_impl) override { | |
| 31 return base::WrapUnique(new TestablePictureImageLayerImpl(tree_impl, id())); | |
| 32 } | |
| 33 | |
| 34 using PictureLayerImpl::UpdateIdealScales; | |
| 35 using PictureLayerImpl::MaximumTilingContentsScale; | |
| 36 | |
| 37 PictureLayerTilingSet* tilings() { return tilings_.get(); } | |
| 38 | |
| 39 friend class PictureImageLayerImplTest; | |
| 40 }; | |
| 41 | |
| 42 class PictureLayerImplImageTestSettings : public LayerTreeSettings { | |
| 43 public: | |
| 44 PictureLayerImplImageTestSettings() { | |
| 45 layer_transforms_should_scale_layer_contents = true; | |
| 46 } | |
| 47 }; | |
| 48 | |
| 49 class PictureImageLayerImplTest : public testing::Test { | |
| 50 public: | |
| 51 PictureImageLayerImplTest() | |
| 52 : task_runner_provider_(base::ThreadTaskRunnerHandle::Get()), | |
| 53 output_surface_(FakeOutputSurface::Create3d()), | |
| 54 host_impl_(PictureLayerImplImageTestSettings(), | |
| 55 &task_runner_provider_, | |
| 56 &shared_bitmap_manager_, | |
| 57 &task_graph_runner_) { | |
| 58 host_impl_.CreatePendingTree(); | |
| 59 host_impl_.SetVisible(true); | |
| 60 host_impl_.InitializeRenderer(output_surface_.get()); | |
| 61 } | |
| 62 | |
| 63 std::unique_ptr<TestablePictureImageLayerImpl> CreateLayer( | |
| 64 int id, | |
| 65 WhichTree which_tree) { | |
| 66 LayerTreeImpl* tree = nullptr; | |
| 67 switch (which_tree) { | |
| 68 case ACTIVE_TREE: | |
| 69 tree = host_impl_.active_tree(); | |
| 70 break; | |
| 71 case PENDING_TREE: | |
| 72 tree = host_impl_.pending_tree(); | |
| 73 break; | |
| 74 } | |
| 75 TestablePictureImageLayerImpl* layer = | |
| 76 new TestablePictureImageLayerImpl(tree, id); | |
| 77 layer->raster_source_ = FakeRasterSource::CreateInfiniteFilled(); | |
| 78 layer->SetBounds(layer->raster_source_->GetSize()); | |
| 79 return base::WrapUnique(layer); | |
| 80 } | |
| 81 | |
| 82 void SetupDrawPropertiesAndUpdateTiles(TestablePictureImageLayerImpl* layer, | |
| 83 float ideal_contents_scale, | |
| 84 float device_scale_factor, | |
| 85 float page_scale_factor, | |
| 86 float maximum_animation_contents_scale, | |
| 87 bool animating_transform_to_screen, | |
| 88 gfx::Rect viewport_rect) { | |
| 89 gfx::Transform scale_transform; | |
| 90 scale_transform.Scale(ideal_contents_scale, ideal_contents_scale); | |
| 91 layer->draw_properties().screen_space_transform = scale_transform; | |
| 92 layer->set_is_drawn_render_surface_layer_list_member(true); | |
| 93 DCHECK_EQ(layer->GetIdealContentsScale(), ideal_contents_scale); | |
| 94 layer->draw_properties().maximum_animation_contents_scale = | |
| 95 maximum_animation_contents_scale; | |
| 96 layer->draw_properties().screen_space_transform_is_animating = | |
| 97 animating_transform_to_screen; | |
| 98 layer->draw_properties().visible_layer_rect = viewport_rect; | |
| 99 layer->UpdateTiles(); | |
| 100 } | |
| 101 | |
| 102 protected: | |
| 103 FakeImplTaskRunnerProvider task_runner_provider_; | |
| 104 TestSharedBitmapManager shared_bitmap_manager_; | |
| 105 TestTaskGraphRunner task_graph_runner_; | |
| 106 std::unique_ptr<OutputSurface> output_surface_; | |
| 107 FakeLayerTreeHostImpl host_impl_; | |
| 108 }; | |
| 109 | |
| 110 TEST_F(PictureImageLayerImplTest, CalculateContentsScale) { | |
| 111 std::unique_ptr<TestablePictureImageLayerImpl> layer( | |
| 112 CreateLayer(1, PENDING_TREE)); | |
| 113 layer->SetDrawsContent(true); | |
| 114 | |
| 115 TestablePictureImageLayerImpl* layer_ptr = layer.get(); | |
| 116 host_impl_.pending_tree()->SetRootLayer(std::move(layer)); | |
| 117 host_impl_.pending_tree()->BuildLayerListAndPropertyTreesForTesting(); | |
| 118 | |
| 119 gfx::Rect viewport(100, 200); | |
| 120 SetupDrawPropertiesAndUpdateTiles(layer_ptr, 2.f, 3.f, 4.f, 1.f, false, | |
| 121 viewport); | |
| 122 EXPECT_FLOAT_EQ(1.f, layer_ptr->MaximumTilingContentsScale()); | |
| 123 } | |
| 124 | |
| 125 TEST_F(PictureImageLayerImplTest, IgnoreIdealContentScale) { | |
| 126 std::unique_ptr<TestablePictureImageLayerImpl> pending_layer( | |
| 127 CreateLayer(1, PENDING_TREE)); | |
| 128 pending_layer->SetDrawsContent(true); | |
| 129 | |
| 130 gfx::Rect viewport(100, 200); | |
| 131 | |
| 132 TestablePictureImageLayerImpl* pending_layer_ptr = pending_layer.get(); | |
| 133 host_impl_.pending_tree()->SetRootLayer(std::move(pending_layer)); | |
| 134 host_impl_.pending_tree()->BuildLayerListAndPropertyTreesForTesting(); | |
| 135 | |
| 136 // Set PictureLayerImpl::ideal_contents_scale_ to 2.f which is not equal | |
| 137 // to the content scale used by PictureImageLayerImpl. | |
| 138 const float suggested_ideal_contents_scale = 2.f; | |
| 139 const float device_scale_factor = 3.f; | |
| 140 const float page_scale_factor = 4.f; | |
| 141 const float maximum_animation_contents_scale = 1.f; | |
| 142 const bool animating_transform_to_screen = false; | |
| 143 SetupDrawPropertiesAndUpdateTiles( | |
| 144 pending_layer_ptr, suggested_ideal_contents_scale, device_scale_factor, | |
| 145 page_scale_factor, maximum_animation_contents_scale, | |
| 146 animating_transform_to_screen, viewport); | |
| 147 EXPECT_EQ(1.f, pending_layer_ptr->tilings()->tiling_at(0)->contents_scale()); | |
| 148 | |
| 149 // Push to active layer. | |
| 150 host_impl_.ActivateSyncTree(); | |
| 151 | |
| 152 TestablePictureImageLayerImpl* active_layer = | |
| 153 static_cast<TestablePictureImageLayerImpl*>( | |
| 154 host_impl_.active_tree()->root_layer()); | |
| 155 SetupDrawPropertiesAndUpdateTiles(active_layer, | |
| 156 suggested_ideal_contents_scale, | |
| 157 device_scale_factor, | |
| 158 page_scale_factor, | |
| 159 maximum_animation_contents_scale, | |
| 160 animating_transform_to_screen, | |
| 161 viewport); | |
| 162 EXPECT_EQ(1.f, active_layer->tilings()->tiling_at(0)->contents_scale()); | |
| 163 | |
| 164 // Create resources for the tiles. | |
| 165 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting( | |
| 166 active_layer->tilings()->tiling_at(0)->AllTilesForTesting()); | |
| 167 | |
| 168 // Draw. | |
| 169 std::unique_ptr<RenderPass> render_pass = RenderPass::Create(); | |
| 170 AppendQuadsData data; | |
| 171 active_layer->WillDraw(DRAW_MODE_SOFTWARE, nullptr); | |
| 172 active_layer->AppendQuads(render_pass.get(), &data); | |
| 173 active_layer->DidDraw(nullptr); | |
| 174 | |
| 175 EXPECT_EQ(DrawQuad::TILED_CONTENT, render_pass->quad_list.front()->material); | |
| 176 | |
| 177 // Tiles are ready at correct scale, so should not set had_incomplete_tile. | |
| 178 EXPECT_EQ(0, data.num_incomplete_tiles); | |
| 179 } | |
| 180 | |
| 181 } // namespace | |
| 182 } // namespace cc | |
| OLD | NEW |