Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(193)

Side by Side Diff: cc/trees/layer_tree_host_common_unittest.cc

Issue 265883013: cc: Add a flag to layers that returns true if the layer is in RSLL. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2011 The Chromium Authors. All rights reserved. 1 // Copyright 2011 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/trees/layer_tree_host_common.h" 5 #include "cc/trees/layer_tree_host_common.h"
6 6
7 #include <set> 7 #include <set>
8 8
9 #include "cc/animation/layer_animation_controller.h" 9 #include "cc/animation/layer_animation_controller.h"
10 #include "cc/animation/transform_operations.h" 10 #include "cc/animation/transform_operations.h"
11 #include "cc/base/math_util.h" 11 #include "cc/base/math_util.h"
12 #include "cc/layers/content_layer.h" 12 #include "cc/layers/content_layer.h"
13 #include "cc/layers/content_layer_client.h" 13 #include "cc/layers/content_layer_client.h"
14 #include "cc/layers/heads_up_display_layer_impl.h" 14 #include "cc/layers/heads_up_display_layer_impl.h"
15 #include "cc/layers/layer.h" 15 #include "cc/layers/layer.h"
16 #include "cc/layers/layer_client.h" 16 #include "cc/layers/layer_client.h"
17 #include "cc/layers/layer_impl.h" 17 #include "cc/layers/layer_impl.h"
18 #include "cc/layers/layer_iterator.h"
18 #include "cc/layers/render_surface.h" 19 #include "cc/layers/render_surface.h"
19 #include "cc/layers/render_surface_impl.h" 20 #include "cc/layers/render_surface_impl.h"
20 #include "cc/output/copy_output_request.h" 21 #include "cc/output/copy_output_request.h"
21 #include "cc/output/copy_output_result.h" 22 #include "cc/output/copy_output_result.h"
22 #include "cc/test/animation_test_common.h" 23 #include "cc/test/animation_test_common.h"
23 #include "cc/test/fake_impl_proxy.h" 24 #include "cc/test/fake_impl_proxy.h"
24 #include "cc/test/fake_layer_tree_host.h" 25 #include "cc/test/fake_layer_tree_host.h"
25 #include "cc/test/fake_layer_tree_host_impl.h" 26 #include "cc/test/fake_layer_tree_host_impl.h"
26 #include "cc/test/geometry_test_utils.h" 27 #include "cc/test/geometry_test_utils.h"
27 #include "cc/trees/layer_tree_impl.h" 28 #include "cc/trees/layer_tree_impl.h"
28 #include "cc/trees/proxy.h" 29 #include "cc/trees/proxy.h"
29 #include "cc/trees/single_thread_proxy.h" 30 #include "cc/trees/single_thread_proxy.h"
30 #include "testing/gmock/include/gmock/gmock.h" 31 #include "testing/gmock/include/gmock/gmock.h"
31 #include "testing/gtest/include/gtest/gtest.h" 32 #include "testing/gtest/include/gtest/gtest.h"
32 #include "ui/gfx/quad_f.h" 33 #include "ui/gfx/quad_f.h"
33 #include "ui/gfx/size_conversions.h" 34 #include "ui/gfx/size_conversions.h"
34 #include "ui/gfx/transform.h" 35 #include "ui/gfx/transform.h"
35 36
36 namespace cc { 37 namespace cc {
37 namespace { 38 namespace {
38 39
39 class LayerTreeHostCommonTestBase { 40 class LayerTreeHostCommonTestBase {
40 protected: 41 protected:
42 LayerTreeHostCommonTestBase() : render_surface_layer_list_count_(0) {}
43
41 template <typename LayerType> 44 template <typename LayerType>
42 void SetLayerPropertiesForTestingInternal( 45 void SetLayerPropertiesForTestingInternal(
43 LayerType* layer, 46 LayerType* layer,
44 const gfx::Transform& transform, 47 const gfx::Transform& transform,
45 const gfx::PointF& anchor, 48 const gfx::PointF& anchor,
46 const gfx::PointF& position, 49 const gfx::PointF& position,
47 const gfx::Size& bounds, 50 const gfx::Size& bounds,
48 bool flatten_transform, 51 bool flatten_transform,
49 bool is_3d_sorted) { 52 bool is_3d_sorted) {
50 layer->SetTransform(transform); 53 layer->SetTransform(transform);
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 inputs.can_adjust_raster_scales = true; 116 inputs.can_adjust_raster_scales = true;
114 LayerTreeHostCommon::CalculateDrawProperties(&inputs); 117 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
115 } 118 }
116 119
117 void ExecuteCalculateDrawProperties(LayerImpl* root_layer, 120 void ExecuteCalculateDrawProperties(LayerImpl* root_layer,
118 float device_scale_factor, 121 float device_scale_factor,
119 float page_scale_factor, 122 float page_scale_factor,
120 LayerImpl* page_scale_application_layer, 123 LayerImpl* page_scale_application_layer,
121 bool can_use_lcd_text) { 124 bool can_use_lcd_text) {
122 gfx::Transform identity_matrix; 125 gfx::Transform identity_matrix;
123 LayerImplList dummy_render_surface_layer_list;
124 gfx::Size device_viewport_size = 126 gfx::Size device_viewport_size =
125 gfx::Size(root_layer->bounds().width() * device_scale_factor, 127 gfx::Size(root_layer->bounds().width() * device_scale_factor,
126 root_layer->bounds().height() * device_scale_factor); 128 root_layer->bounds().height() * device_scale_factor);
127 129
130 render_surface_layer_list_impl_.reset(new LayerImplList);
131
128 // We are probably not testing what is intended if the root_layer bounds are 132 // We are probably not testing what is intended if the root_layer bounds are
129 // empty. 133 // empty.
130 DCHECK(!root_layer->bounds().IsEmpty()); 134 DCHECK(!root_layer->bounds().IsEmpty());
131 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( 135 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
132 root_layer, device_viewport_size, &dummy_render_surface_layer_list); 136 root_layer,
137 device_viewport_size,
138 render_surface_layer_list_impl_.get());
133 inputs.device_scale_factor = device_scale_factor; 139 inputs.device_scale_factor = device_scale_factor;
134 inputs.page_scale_factor = page_scale_factor; 140 inputs.page_scale_factor = page_scale_factor;
135 inputs.page_scale_application_layer = page_scale_application_layer; 141 inputs.page_scale_application_layer = page_scale_application_layer;
136 inputs.can_use_lcd_text = can_use_lcd_text; 142 inputs.can_use_lcd_text = can_use_lcd_text;
137 inputs.can_adjust_raster_scales = true; 143 inputs.can_adjust_raster_scales = true;
144
145 ++render_surface_layer_list_count_;
146 inputs.current_render_surface_layer_list_id =
147 render_surface_layer_list_count_;
148
138 LayerTreeHostCommon::CalculateDrawProperties(&inputs); 149 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
139 } 150 }
140 151
141 template <class LayerType> 152 template <class LayerType>
142 void ExecuteCalculateDrawProperties(LayerType* root_layer) { 153 void ExecuteCalculateDrawProperties(LayerType* root_layer) {
143 LayerType* page_scale_application_layer = NULL; 154 LayerType* page_scale_application_layer = NULL;
144 ExecuteCalculateDrawProperties( 155 ExecuteCalculateDrawProperties(
145 root_layer, 1.f, 1.f, page_scale_application_layer, false); 156 root_layer, 1.f, 1.f, page_scale_application_layer, false);
146 } 157 }
147 158
(...skipping 17 matching lines...) Expand all
165 device_scale_factor, 176 device_scale_factor,
166 page_scale_factor, 177 page_scale_factor,
167 page_scale_application_layer, 178 page_scale_application_layer,
168 false); 179 false);
169 } 180 }
170 181
171 RenderSurfaceLayerList* render_surface_layer_list() const { 182 RenderSurfaceLayerList* render_surface_layer_list() const {
172 return render_surface_layer_list_.get(); 183 return render_surface_layer_list_.get();
173 } 184 }
174 185
186 LayerImplList* render_surface_layer_list_impl() const {
187 return render_surface_layer_list_impl_.get();
188 }
189
190 int render_surface_layer_list_count() const {
191 return render_surface_layer_list_count_;
192 }
193
175 private: 194 private:
176 scoped_ptr<RenderSurfaceLayerList> render_surface_layer_list_; 195 scoped_ptr<RenderSurfaceLayerList> render_surface_layer_list_;
196 scoped_ptr<LayerImplList> render_surface_layer_list_impl_;
197
198 int render_surface_layer_list_count_;
177 }; 199 };
178 200
179 class LayerTreeHostCommonTest : public LayerTreeHostCommonTestBase, 201 class LayerTreeHostCommonTest : public LayerTreeHostCommonTestBase,
180 public testing::Test { 202 public testing::Test {
181 }; 203 };
182 204
183 class LayerWithForcedDrawsContent : public Layer { 205 class LayerWithForcedDrawsContent : public Layer {
184 public: 206 public:
185 LayerWithForcedDrawsContent() : Layer(), last_device_scale_factor_(0.f) {} 207 LayerWithForcedDrawsContent() : Layer(), last_device_scale_factor_(0.f) {}
186 208
(...skipping 9928 matching lines...) Expand 10 before | Expand all | Expand 10 after
10115 10137
10116 ExecuteCalculateDrawProperties(grand_parent.get()); 10138 ExecuteCalculateDrawProperties(grand_parent.get());
10117 10139
10118 // |grand_parent| has a transform that's neither a translation nor a scale. 10140 // |grand_parent| has a transform that's neither a translation nor a scale.
10119 EXPECT_EQ(0.f, grand_parent->last_maximum_animation_contents_scale()); 10141 EXPECT_EQ(0.f, grand_parent->last_maximum_animation_contents_scale());
10120 EXPECT_EQ(0.f, parent_raw->last_maximum_animation_contents_scale()); 10142 EXPECT_EQ(0.f, parent_raw->last_maximum_animation_contents_scale());
10121 EXPECT_EQ(0.f, child_raw->last_maximum_animation_contents_scale()); 10143 EXPECT_EQ(0.f, child_raw->last_maximum_animation_contents_scale());
10122 EXPECT_EQ(0.f, grand_child_raw->last_maximum_animation_contents_scale()); 10144 EXPECT_EQ(0.f, grand_child_raw->last_maximum_animation_contents_scale());
10123 } 10145 }
10124 10146
10147 static int membership_id(LayerImpl* layer) {
10148 return layer->draw_properties().last_drawn_render_surface_layer_list_id;
10149 }
10150
10151 static void gather_drawn_layers(LayerImplList* rsll,
10152 std::set<LayerImpl*>* drawn_layers) {
10153 for (LayerIterator<LayerImpl> it = LayerIterator<LayerImpl>::Begin(rsll),
10154 end = LayerIterator<LayerImpl>::End(rsll);
10155 it != end;
10156 ++it) {
10157 LayerImpl* layer = *it;
10158 if (it.represents_itself())
10159 drawn_layers->insert(layer);
10160
10161 if (!it.represents_contributing_render_surface())
10162 continue;
10163
10164 if (layer->mask_layer())
10165 drawn_layers->insert(layer->mask_layer());
10166 if (layer->replica_layer() && layer->replica_layer()->mask_layer())
10167 drawn_layers->insert(layer->replica_layer()->mask_layer());
10168 }
10169 }
10170
10171 TEST_F(LayerTreeHostCommonTest, RenderSurfaceLayerListMembership) {
10172 FakeImplProxy proxy;
10173 TestSharedBitmapManager shared_bitmap_manager;
10174 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
10175 gfx::Transform identity_matrix;
10176
10177 scoped_ptr<LayerImpl> grand_parent =
10178 LayerImpl::Create(host_impl.active_tree(), 1);
10179 scoped_ptr<LayerImpl> parent = LayerImpl::Create(host_impl.active_tree(), 3);
10180 scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.active_tree(), 5);
10181 scoped_ptr<LayerImpl> grand_child1 =
10182 LayerImpl::Create(host_impl.active_tree(), 7);
10183 scoped_ptr<LayerImpl> grand_child2 =
10184 LayerImpl::Create(host_impl.active_tree(), 9);
10185
10186 LayerImpl* grand_parent_raw = grand_parent.get();
10187 LayerImpl* parent_raw = parent.get();
10188 LayerImpl* child_raw = child.get();
10189 LayerImpl* grand_child1_raw = grand_child1.get();
10190 LayerImpl* grand_child2_raw = grand_child2.get();
10191
10192 child->AddChild(grand_child1.Pass());
10193 child->AddChild(grand_child2.Pass());
10194 parent->AddChild(child.Pass());
10195 grand_parent->AddChild(parent.Pass());
10196
10197 SetLayerPropertiesForTesting(grand_parent_raw,
10198 identity_matrix,
10199 gfx::PointF(),
10200 gfx::PointF(),
10201 gfx::Size(1, 2),
10202 true,
10203 false);
10204 SetLayerPropertiesForTesting(parent_raw,
10205 identity_matrix,
10206 gfx::PointF(),
10207 gfx::PointF(),
10208 gfx::Size(1, 2),
10209 true,
10210 false);
10211 SetLayerPropertiesForTesting(child_raw,
10212 identity_matrix,
10213 gfx::PointF(),
10214 gfx::PointF(),
10215 gfx::Size(1, 2),
10216 true,
10217 false);
10218 SetLayerPropertiesForTesting(grand_child1_raw,
10219 identity_matrix,
10220 gfx::PointF(),
10221 gfx::PointF(),
10222 gfx::Size(1, 2),
10223 true,
10224 false);
10225 SetLayerPropertiesForTesting(grand_child2_raw,
10226 identity_matrix,
10227 gfx::PointF(),
10228 gfx::PointF(),
10229 gfx::Size(1, 2),
10230 true,
10231 false);
10232
10233 // Start with nothing being drawn.
10234 ExecuteCalculateDrawProperties(grand_parent_raw);
10235 int member_id = render_surface_layer_list_count();
10236
10237 EXPECT_NE(member_id, membership_id(grand_parent_raw));
10238 EXPECT_NE(member_id, membership_id(parent_raw));
10239 EXPECT_NE(member_id, membership_id(child_raw));
10240 EXPECT_NE(member_id, membership_id(grand_child1_raw));
10241 EXPECT_NE(member_id, membership_id(grand_child2_raw));
10242
10243 std::set<LayerImpl*> expected;
10244 std::set<LayerImpl*> actual;
10245 gather_drawn_layers(render_surface_layer_list_impl(), &actual);
10246 EXPECT_EQ(expected, actual);
10247
10248 // If we force render surface, but none of the layers are in the layer list,
10249 // then this layer should not appear in RSLL.
10250 grand_child1_raw->SetForceRenderSurface(true);
10251
10252 ExecuteCalculateDrawProperties(grand_parent_raw);
10253 member_id = render_surface_layer_list_count();
10254
10255 EXPECT_NE(member_id, membership_id(grand_parent_raw));
10256 EXPECT_NE(member_id, membership_id(parent_raw));
10257 EXPECT_NE(member_id, membership_id(child_raw));
10258 EXPECT_NE(member_id, membership_id(grand_child1_raw));
10259 EXPECT_NE(member_id, membership_id(grand_child2_raw));
10260
10261 expected.clear();
10262 actual.clear();
10263 gather_drawn_layers(render_surface_layer_list_impl(), &actual);
10264 EXPECT_EQ(expected, actual);
10265
10266 // However, if we say that this layer also draws content, it will appear in
10267 // RSLL.
10268 grand_child1_raw->SetDrawsContent(true);
10269
10270 ExecuteCalculateDrawProperties(grand_parent_raw);
10271 member_id = render_surface_layer_list_count();
10272
10273 EXPECT_NE(member_id, membership_id(grand_parent_raw));
10274 EXPECT_NE(member_id, membership_id(parent_raw));
10275 EXPECT_NE(member_id, membership_id(child_raw));
10276 EXPECT_EQ(member_id, membership_id(grand_child1_raw));
10277 EXPECT_NE(member_id, membership_id(grand_child2_raw));
10278
10279 expected.clear();
10280 expected.insert(grand_child1_raw);
10281
10282 actual.clear();
10283 gather_drawn_layers(render_surface_layer_list_impl(), &actual);
10284 EXPECT_EQ(expected, actual);
10285
10286 // Now child is forced to have a render surface, and one if its children draws
10287 // content.
10288 grand_child1_raw->SetDrawsContent(false);
10289 grand_child1_raw->SetForceRenderSurface(false);
10290 child_raw->SetForceRenderSurface(true);
10291 grand_child2_raw->SetDrawsContent(true);
10292
10293 ExecuteCalculateDrawProperties(grand_parent_raw);
10294 member_id = render_surface_layer_list_count();
10295
10296 EXPECT_NE(member_id, membership_id(grand_parent_raw));
10297 EXPECT_NE(member_id, membership_id(parent_raw));
10298 EXPECT_NE(member_id, membership_id(child_raw));
10299 EXPECT_NE(member_id, membership_id(grand_child1_raw));
10300 EXPECT_EQ(member_id, membership_id(grand_child2_raw));
10301
10302 expected.clear();
10303 expected.insert(grand_child2_raw);
10304
10305 actual.clear();
10306 gather_drawn_layers(render_surface_layer_list_impl(), &actual);
10307 EXPECT_EQ(expected, actual);
10308
10309 // Add a mask layer to child.
10310 child_raw->SetMaskLayer(LayerImpl::Create(host_impl.active_tree(), 6).Pass());
10311
10312 ExecuteCalculateDrawProperties(grand_parent_raw);
10313 member_id = render_surface_layer_list_count();
10314
10315 EXPECT_NE(member_id, membership_id(grand_parent_raw));
10316 EXPECT_NE(member_id, membership_id(parent_raw));
10317 EXPECT_NE(member_id, membership_id(child_raw));
10318 EXPECT_EQ(member_id, membership_id(child_raw->mask_layer()));
10319 EXPECT_NE(member_id, membership_id(grand_child1_raw));
10320 EXPECT_EQ(member_id, membership_id(grand_child2_raw));
10321
10322 expected.clear();
10323 expected.insert(grand_child2_raw);
10324 expected.insert(child_raw->mask_layer());
10325
10326 actual.clear();
10327 gather_drawn_layers(render_surface_layer_list_impl(), &actual);
10328 EXPECT_EQ(expected, actual);
10329
10330 child_raw->TakeMaskLayer();
10331
10332 // Now everyone's a member!
10333 grand_parent_raw->SetDrawsContent(true);
10334 parent_raw->SetDrawsContent(true);
10335 child_raw->SetDrawsContent(true);
10336 grand_child1_raw->SetDrawsContent(true);
10337 grand_child2_raw->SetDrawsContent(true);
10338
10339 ExecuteCalculateDrawProperties(grand_parent_raw);
10340 member_id = render_surface_layer_list_count();
10341
10342 EXPECT_EQ(member_id, membership_id(grand_parent_raw));
10343 EXPECT_EQ(member_id, membership_id(parent_raw));
10344 EXPECT_EQ(member_id, membership_id(child_raw));
10345 EXPECT_EQ(member_id, membership_id(grand_child1_raw));
10346 EXPECT_EQ(member_id, membership_id(grand_child2_raw));
10347
10348 expected.clear();
10349 expected.insert(grand_parent_raw);
10350 expected.insert(parent_raw);
10351 expected.insert(child_raw);
10352 expected.insert(grand_child1_raw);
10353 expected.insert(grand_child2_raw);
10354
10355 actual.clear();
10356 gather_drawn_layers(render_surface_layer_list_impl(), &actual);
10357 EXPECT_EQ(expected, actual);
10358 }
10125 } // namespace 10359 } // namespace
10126 } // namespace cc 10360 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698