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