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

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: update 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 if (render_surface_layer_list_count_ == std::numeric_limits<int>::max())
146 render_surface_layer_list_count_ = 1;
147 else
148 ++render_surface_layer_list_count_;
149
150 inputs.current_render_surface_layer_list_id =
151 render_surface_layer_list_count_;
152
138 LayerTreeHostCommon::CalculateDrawProperties(&inputs); 153 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
139 } 154 }
140 155
141 template <class LayerType> 156 template <class LayerType>
142 void ExecuteCalculateDrawProperties(LayerType* root_layer) { 157 void ExecuteCalculateDrawProperties(LayerType* root_layer) {
143 LayerType* page_scale_application_layer = NULL; 158 LayerType* page_scale_application_layer = NULL;
144 ExecuteCalculateDrawProperties( 159 ExecuteCalculateDrawProperties(
145 root_layer, 1.f, 1.f, page_scale_application_layer, false); 160 root_layer, 1.f, 1.f, page_scale_application_layer, false);
146 } 161 }
147 162
(...skipping 17 matching lines...) Expand all
165 device_scale_factor, 180 device_scale_factor,
166 page_scale_factor, 181 page_scale_factor,
167 page_scale_application_layer, 182 page_scale_application_layer,
168 false); 183 false);
169 } 184 }
170 185
171 RenderSurfaceLayerList* render_surface_layer_list() const { 186 RenderSurfaceLayerList* render_surface_layer_list() const {
172 return render_surface_layer_list_.get(); 187 return render_surface_layer_list_.get();
173 } 188 }
174 189
190 LayerImplList* render_surface_layer_list_impl() const {
191 return render_surface_layer_list_impl_.get();
192 }
193
194 int render_surface_layer_list_count() const {
195 return render_surface_layer_list_count_;
196 }
197
175 private: 198 private:
176 scoped_ptr<RenderSurfaceLayerList> render_surface_layer_list_; 199 scoped_ptr<RenderSurfaceLayerList> render_surface_layer_list_;
200 scoped_ptr<LayerImplList> render_surface_layer_list_impl_;
201
202 int render_surface_layer_list_count_;
177 }; 203 };
178 204
179 class LayerTreeHostCommonTest : public LayerTreeHostCommonTestBase, 205 class LayerTreeHostCommonTest : public LayerTreeHostCommonTestBase,
180 public testing::Test { 206 public testing::Test {
181 }; 207 };
182 208
183 class LayerWithForcedDrawsContent : public Layer { 209 class LayerWithForcedDrawsContent : public Layer {
184 public: 210 public:
185 LayerWithForcedDrawsContent() : Layer(), last_device_scale_factor_(0.f) {} 211 LayerWithForcedDrawsContent() : Layer(), last_device_scale_factor_(0.f) {}
186 212
(...skipping 9928 matching lines...) Expand 10 before | Expand all | Expand 10 after
10115 10141
10116 ExecuteCalculateDrawProperties(grand_parent.get()); 10142 ExecuteCalculateDrawProperties(grand_parent.get());
10117 10143
10118 // |grand_parent| has a transform that's neither a translation nor a scale. 10144 // |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()); 10145 EXPECT_EQ(0.f, grand_parent->last_maximum_animation_contents_scale());
10120 EXPECT_EQ(0.f, parent_raw->last_maximum_animation_contents_scale()); 10146 EXPECT_EQ(0.f, parent_raw->last_maximum_animation_contents_scale());
10121 EXPECT_EQ(0.f, child_raw->last_maximum_animation_contents_scale()); 10147 EXPECT_EQ(0.f, child_raw->last_maximum_animation_contents_scale());
10122 EXPECT_EQ(0.f, grand_child_raw->last_maximum_animation_contents_scale()); 10148 EXPECT_EQ(0.f, grand_child_raw->last_maximum_animation_contents_scale());
10123 } 10149 }
10124 10150
10151 static int membership_id(LayerImpl* layer) {
10152 return layer->draw_properties().last_valid_render_surface_layer_list_id;
10153 }
10154
10155 TEST_F(LayerTreeHostCommonTest, RenderSurfaceLayerListMembership) {
10156 FakeImplProxy proxy;
10157 TestSharedBitmapManager shared_bitmap_manager;
10158 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
10159 gfx::Transform identity_matrix;
10160 scoped_ptr<LayerImpl> grand_parent =
10161 LayerImpl::Create(host_impl.active_tree(), 1);
10162 scoped_ptr<LayerImpl> parent = LayerImpl::Create(host_impl.active_tree(), 2);
10163 scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.active_tree(), 3);
10164 scoped_ptr<LayerImpl> grand_child1 =
10165 LayerImpl::Create(host_impl.active_tree(), 4);
10166 scoped_ptr<LayerImpl> grand_child2 =
10167 LayerImpl::Create(host_impl.active_tree(), 5);
10168
10169 LayerImpl* grand_parent_raw = grand_parent.get();
10170 LayerImpl* parent_raw = parent.get();
10171 LayerImpl* child_raw = child.get();
10172 LayerImpl* grand_child1_raw = grand_child1.get();
10173 LayerImpl* grand_child2_raw = grand_child2.get();
10174
10175 child->AddChild(grand_child1.Pass());
10176 child->AddChild(grand_child2.Pass());
10177 parent->AddChild(child.Pass());
10178 grand_parent->AddChild(parent.Pass());
10179
10180 SetLayerPropertiesForTesting(grand_parent_raw,
10181 identity_matrix,
10182 gfx::PointF(),
10183 gfx::PointF(),
10184 gfx::Size(1, 2),
10185 true,
10186 false);
10187 SetLayerPropertiesForTesting(parent_raw,
10188 identity_matrix,
10189 gfx::PointF(),
10190 gfx::PointF(),
10191 gfx::Size(1, 2),
10192 true,
10193 false);
10194 SetLayerPropertiesForTesting(child_raw,
10195 identity_matrix,
10196 gfx::PointF(),
10197 gfx::PointF(),
10198 gfx::Size(1, 2),
10199 true,
10200 false);
10201 SetLayerPropertiesForTesting(grand_child1_raw,
10202 identity_matrix,
10203 gfx::PointF(),
10204 gfx::PointF(),
10205 gfx::Size(1, 2),
10206 true,
10207 false);
10208 SetLayerPropertiesForTesting(grand_child2_raw,
10209 identity_matrix,
10210 gfx::PointF(),
10211 gfx::PointF(),
10212 gfx::Size(1, 2),
10213 true,
10214 false);
10215
10216 ExecuteCalculateDrawProperties(grand_parent_raw);
10217 int member_id = render_surface_layer_list_count();
10218
10219 EXPECT_EQ(member_id, membership_id(grand_parent_raw));
10220 EXPECT_NE(member_id, membership_id(parent_raw));
10221 EXPECT_NE(member_id, membership_id(child_raw));
10222 EXPECT_NE(member_id, membership_id(grand_child1_raw));
10223 EXPECT_NE(member_id, membership_id(grand_child2_raw));
10224
10225 typedef LayerIterator<LayerImpl> LayerIteratorType;
10226 LayerIteratorType end =
10227 LayerIteratorType::End(render_surface_layer_list_impl());
10228 LayerIteratorType it =
10229 LayerIteratorType::Begin(render_surface_layer_list_impl());
10230 EXPECT_NE(end, it);
10231 EXPECT_EQ(grand_parent_raw, *it);
10232 ++it;
10233 EXPECT_EQ(end, it);
10234
10235 // If we force render surface, but none of the layers are in the layer list,
10236 // then this layer should not appear in RSLL.
10237 grand_child1_raw->SetForceRenderSurface(true);
10238
10239 ExecuteCalculateDrawProperties(grand_parent_raw);
10240 member_id = render_surface_layer_list_count();
10241
10242 EXPECT_EQ(member_id, membership_id(grand_parent_raw));
10243 EXPECT_NE(member_id, membership_id(parent_raw));
10244 EXPECT_NE(member_id, membership_id(child_raw));
10245 EXPECT_NE(member_id, membership_id(grand_child1_raw));
10246 EXPECT_NE(member_id, membership_id(grand_child2_raw));
10247
10248 end = LayerIteratorType::End(render_surface_layer_list_impl());
10249 it = LayerIteratorType::Begin(render_surface_layer_list_impl());
10250 EXPECT_NE(end, it);
10251 EXPECT_EQ(grand_parent_raw, *it);
10252 ++it;
10253 EXPECT_EQ(end, it);
10254
10255 // However, if we say that this layer also draws content, it will appear in
10256 // RSLL.
10257 grand_child1_raw->SetDrawsContent(true);
10258
10259 ExecuteCalculateDrawProperties(grand_parent_raw);
10260 member_id = render_surface_layer_list_count();
10261
10262 EXPECT_EQ(member_id, membership_id(grand_parent_raw));
10263 EXPECT_NE(member_id, membership_id(parent_raw));
10264 EXPECT_NE(member_id, membership_id(child_raw));
10265 EXPECT_EQ(member_id, membership_id(grand_child1_raw));
10266 EXPECT_NE(member_id, membership_id(grand_child2_raw));
10267
10268 std::set<LayerImpl*> expected;
10269 expected.insert(grand_parent_raw);
10270 expected.insert(grand_child1_raw);
10271
10272 std::set<LayerImpl*> actual;
10273 for (it = LayerIteratorType::Begin(render_surface_layer_list_impl()),
10274 end = LayerIteratorType::End(render_surface_layer_list_impl());
10275 it != end;
10276 ++it) {
10277 actual.insert(*it);
10278 }
10279
10280 EXPECT_EQ(expected, actual);
10281
10282 // Now child is forced to have a render surface, and one if its children draws
10283 // content.
10284 grand_child1_raw->SetDrawsContent(false);
10285 grand_child1_raw->SetForceRenderSurface(false);
10286 child_raw->SetForceRenderSurface(true);
10287 grand_child2_raw->SetDrawsContent(true);
10288
10289 ExecuteCalculateDrawProperties(grand_parent_raw);
10290 member_id = render_surface_layer_list_count();
10291
10292 EXPECT_EQ(member_id, membership_id(grand_parent_raw));
10293 EXPECT_NE(member_id, membership_id(parent_raw));
10294 EXPECT_EQ(member_id, membership_id(child_raw));
10295 EXPECT_NE(member_id, membership_id(grand_child1_raw));
10296 EXPECT_EQ(member_id, membership_id(grand_child2_raw));
10297
10298 expected.clear();
10299 expected.insert(grand_parent_raw);
10300 expected.insert(child_raw);
10301 expected.insert(grand_child2_raw);
10302
10303 actual.clear();
10304 for (it = LayerIteratorType::Begin(render_surface_layer_list_impl()),
10305 end = LayerIteratorType::End(render_surface_layer_list_impl());
10306 it != end;
10307 ++it) {
10308 actual.insert(*it);
10309 }
10310
10311 EXPECT_EQ(expected, actual);
10312
10313 // Now everyone's a member!
10314 grand_parent_raw->SetDrawsContent(true);
10315 parent_raw->SetDrawsContent(true);
10316 child_raw->SetDrawsContent(true);
10317 grand_child1_raw->SetDrawsContent(true);
10318 grand_child2_raw->SetDrawsContent(true);
10319
10320 ExecuteCalculateDrawProperties(grand_parent_raw);
10321 member_id = render_surface_layer_list_count();
10322
10323 EXPECT_EQ(member_id, membership_id(grand_parent_raw));
10324 EXPECT_EQ(member_id, membership_id(parent_raw));
10325 EXPECT_EQ(member_id, membership_id(child_raw));
10326 EXPECT_EQ(member_id, membership_id(grand_child1_raw));
10327 EXPECT_EQ(member_id, membership_id(grand_child2_raw));
10328
10329 expected.clear();
10330 expected.insert(grand_parent_raw);
10331 expected.insert(parent_raw);
10332 expected.insert(child_raw);
10333 expected.insert(grand_child1_raw);
10334 expected.insert(grand_child2_raw);
10335
10336 actual.clear();
10337 for (it = LayerIteratorType::Begin(render_surface_layer_list_impl()),
10338 end = LayerIteratorType::End(render_surface_layer_list_impl());
10339 it != end;
10340 ++it) {
10341 actual.insert(*it);
10342 }
10343
10344 EXPECT_EQ(expected, actual);
10345 }
10125 } // namespace 10346 } // namespace
10126 } // namespace cc 10347 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698