| 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 "cc/layers/append_quads_data.h" | |
| 8 #include "cc/quads/draw_quad.h" | |
| 9 #include "cc/resources/tile_priority.h" | |
| 10 #include "cc/test/fake_impl_proxy.h" | |
| 11 #include "cc/test/fake_layer_tree_host_impl.h" | |
| 12 #include "cc/test/fake_output_surface.h" | |
| 13 #include "cc/test/fake_picture_pile_impl.h" | |
| 14 #include "cc/test/impl_side_painting_settings.h" | |
| 15 #include "cc/test/test_shared_bitmap_manager.h" | |
| 16 #include "cc/test/test_task_graph_runner.h" | |
| 17 #include "cc/trees/layer_tree_impl.h" | |
| 18 #include "testing/gtest/include/gtest/gtest.h" | |
| 19 | |
| 20 namespace cc { | |
| 21 namespace { | |
| 22 | |
| 23 class TestablePictureImageLayerImpl : public PictureImageLayerImpl { | |
| 24 public: | |
| 25 TestablePictureImageLayerImpl(LayerTreeImpl* tree_impl, int id) | |
| 26 : PictureImageLayerImpl(tree_impl, id, false) {} | |
| 27 using PictureLayerImpl::UpdateIdealScales; | |
| 28 using PictureLayerImpl::MaximumTilingContentsScale; | |
| 29 | |
| 30 PictureLayerTilingSet* tilings() { return tilings_.get(); } | |
| 31 | |
| 32 friend class PictureImageLayerImplTest; | |
| 33 }; | |
| 34 | |
| 35 class PictureImageLayerImplTest : public testing::Test { | |
| 36 public: | |
| 37 PictureImageLayerImplTest() | |
| 38 : proxy_(base::MessageLoopProxy::current()), | |
| 39 host_impl_(ImplSidePaintingSettings(), | |
| 40 &proxy_, | |
| 41 &shared_bitmap_manager_, | |
| 42 &task_graph_runner_) { | |
| 43 host_impl_.CreatePendingTree(); | |
| 44 host_impl_.InitializeRenderer(FakeOutputSurface::Create3d()); | |
| 45 } | |
| 46 | |
| 47 scoped_ptr<TestablePictureImageLayerImpl> CreateLayer(int id, | |
| 48 WhichTree which_tree) { | |
| 49 LayerTreeImpl* tree = nullptr; | |
| 50 switch (which_tree) { | |
| 51 case ACTIVE_TREE: | |
| 52 tree = host_impl_.active_tree(); | |
| 53 break; | |
| 54 case PENDING_TREE: | |
| 55 tree = host_impl_.pending_tree(); | |
| 56 break; | |
| 57 } | |
| 58 TestablePictureImageLayerImpl* layer = | |
| 59 new TestablePictureImageLayerImpl(tree, id); | |
| 60 layer->raster_source_ = FakePicturePileImpl::CreateInfiniteFilledPile(); | |
| 61 layer->SetBounds(layer->raster_source_->GetSize()); | |
| 62 layer->SetContentBounds(layer->raster_source_->GetSize()); | |
| 63 return make_scoped_ptr(layer); | |
| 64 } | |
| 65 | |
| 66 void SetupDrawPropertiesAndUpdateTiles(TestablePictureImageLayerImpl* layer, | |
| 67 float ideal_contents_scale, | |
| 68 float device_scale_factor, | |
| 69 float page_scale_factor, | |
| 70 float maximum_animation_contents_scale, | |
| 71 bool animating_transform_to_screen, | |
| 72 gfx::Rect viewport_rect) { | |
| 73 layer->draw_properties().ideal_contents_scale = ideal_contents_scale; | |
| 74 layer->draw_properties().device_scale_factor = device_scale_factor; | |
| 75 layer->draw_properties().page_scale_factor = page_scale_factor; | |
| 76 layer->draw_properties().maximum_animation_contents_scale = | |
| 77 maximum_animation_contents_scale; | |
| 78 layer->draw_properties().screen_space_transform_is_animating = | |
| 79 animating_transform_to_screen; | |
| 80 layer->draw_properties().visible_content_rect = viewport_rect; | |
| 81 bool resourceless_software_draw = false; | |
| 82 layer->UpdateTiles(resourceless_software_draw); | |
| 83 } | |
| 84 | |
| 85 protected: | |
| 86 FakeImplProxy proxy_; | |
| 87 TestSharedBitmapManager shared_bitmap_manager_; | |
| 88 TestTaskGraphRunner task_graph_runner_; | |
| 89 FakeLayerTreeHostImpl host_impl_; | |
| 90 }; | |
| 91 | |
| 92 TEST_F(PictureImageLayerImplTest, CalculateContentsScale) { | |
| 93 scoped_ptr<TestablePictureImageLayerImpl> layer(CreateLayer(1, PENDING_TREE)); | |
| 94 layer->SetDrawsContent(true); | |
| 95 | |
| 96 gfx::Rect viewport(100, 200); | |
| 97 SetupDrawPropertiesAndUpdateTiles( | |
| 98 layer.get(), 2.f, 3.f, 4.f, 1.f, false, viewport); | |
| 99 | |
| 100 EXPECT_FLOAT_EQ(1.f, layer->contents_scale_x()); | |
| 101 EXPECT_FLOAT_EQ(1.f, layer->contents_scale_y()); | |
| 102 EXPECT_FLOAT_EQ(1.f, layer->MaximumTilingContentsScale()); | |
| 103 } | |
| 104 | |
| 105 TEST_F(PictureImageLayerImplTest, IgnoreIdealContentScale) { | |
| 106 scoped_ptr<TestablePictureImageLayerImpl> pending_layer( | |
| 107 CreateLayer(1, PENDING_TREE)); | |
| 108 pending_layer->SetDrawsContent(true); | |
| 109 | |
| 110 gfx::Rect viewport(100, 200); | |
| 111 | |
| 112 // Set PictureLayerImpl::ideal_contents_scale_ to 2.f which is not equal | |
| 113 // to the content scale used by PictureImageLayerImpl. | |
| 114 const float suggested_ideal_contents_scale = 2.f; | |
| 115 const float device_scale_factor = 3.f; | |
| 116 const float page_scale_factor = 4.f; | |
| 117 const float maximum_animation_contents_scale = 1.f; | |
| 118 const bool animating_transform_to_screen = false; | |
| 119 SetupDrawPropertiesAndUpdateTiles(pending_layer.get(), | |
| 120 suggested_ideal_contents_scale, | |
| 121 device_scale_factor, | |
| 122 page_scale_factor, | |
| 123 maximum_animation_contents_scale, | |
| 124 animating_transform_to_screen, | |
| 125 viewport); | |
| 126 EXPECT_EQ(1.f, pending_layer->tilings()->tiling_at(0)->contents_scale()); | |
| 127 | |
| 128 // Push to active layer. | |
| 129 host_impl_.pending_tree()->SetRootLayer(pending_layer.Pass()); | |
| 130 host_impl_.ActivateSyncTree(); | |
| 131 | |
| 132 TestablePictureImageLayerImpl* active_layer = | |
| 133 static_cast<TestablePictureImageLayerImpl*>( | |
| 134 host_impl_.active_tree()->root_layer()); | |
| 135 SetupDrawPropertiesAndUpdateTiles(active_layer, | |
| 136 suggested_ideal_contents_scale, | |
| 137 device_scale_factor, | |
| 138 page_scale_factor, | |
| 139 maximum_animation_contents_scale, | |
| 140 animating_transform_to_screen, | |
| 141 viewport); | |
| 142 EXPECT_EQ(1.f, active_layer->tilings()->tiling_at(0)->contents_scale()); | |
| 143 | |
| 144 // Create resources for the tiles. | |
| 145 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting( | |
| 146 active_layer->tilings()->tiling_at(0)->AllTilesForTesting()); | |
| 147 | |
| 148 // Draw. | |
| 149 scoped_ptr<RenderPass> render_pass = RenderPass::Create(); | |
| 150 AppendQuadsData data; | |
| 151 active_layer->WillDraw(DRAW_MODE_SOFTWARE, nullptr); | |
| 152 active_layer->AppendQuads(render_pass.get(), &data); | |
| 153 active_layer->DidDraw(nullptr); | |
| 154 | |
| 155 EXPECT_EQ(DrawQuad::TILED_CONTENT, render_pass->quad_list.front()->material); | |
| 156 | |
| 157 // Tiles are ready at correct scale, so should not set had_incomplete_tile. | |
| 158 EXPECT_EQ(0, data.num_incomplete_tiles); | |
| 159 } | |
| 160 | |
| 161 } // namespace | |
| 162 } // namespace cc | |
| OLD | NEW |