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

Side by Side Diff: cc/layer_impl_unittest.cc

Issue 12603013: Part 10 of cc/ directory shuffles: layers (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 9 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
« no previous file with comments | « cc/layer_impl.cc ('k') | cc/layer_iterator.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "cc/layer_impl.h"
6
7 #include "cc/test/fake_impl_proxy.h"
8 #include "cc/test/fake_layer_tree_host_impl.h"
9 #include "cc/test/fake_output_surface.h"
10 #include "cc/trees/layer_tree_impl.h"
11 #include "cc/trees/single_thread_proxy.h"
12 #include "testing/gmock/include/gmock/gmock.h"
13 #include "testing/gtest/include/gtest/gtest.h"
14 #include "third_party/WebKit/Source/Platform/chromium/public/WebFilterOperation. h"
15 #include "third_party/WebKit/Source/Platform/chromium/public/WebFilterOperations .h"
16 #include "third_party/skia/include/effects/SkBlurImageFilter.h"
17
18 using namespace WebKit;
19
20 namespace cc {
21 namespace {
22
23 #define EXECUTE_AND_VERIFY_SUBTREE_CHANGED(codeToTest) \
24 root->ResetAllChangeTrackingForSubtree(); \
25 codeToTest; \
26 EXPECT_TRUE(root->LayerPropertyChanged()); \
27 EXPECT_TRUE(child->LayerPropertyChanged()); \
28 EXPECT_TRUE(grandChild->LayerPropertyChanged()); \
29 EXPECT_FALSE(root->LayerSurfacePropertyChanged())
30
31
32 #define EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(codeToTest) \
33 root->ResetAllChangeTrackingForSubtree(); \
34 codeToTest; \
35 EXPECT_FALSE(root->LayerPropertyChanged()); \
36 EXPECT_FALSE(child->LayerPropertyChanged()); \
37 EXPECT_FALSE(grandChild->LayerPropertyChanged()); \
38 EXPECT_FALSE(root->LayerSurfacePropertyChanged())
39
40 #define EXECUTE_AND_VERIFY_ONLY_LAYER_CHANGED(codeToTest) \
41 root->ResetAllChangeTrackingForSubtree(); \
42 codeToTest; \
43 EXPECT_TRUE(root->LayerPropertyChanged()); \
44 EXPECT_FALSE(child->LayerPropertyChanged()); \
45 EXPECT_FALSE(grandChild->LayerPropertyChanged()); \
46 EXPECT_FALSE(root->LayerSurfacePropertyChanged())
47
48 #define EXECUTE_AND_VERIFY_ONLY_SURFACE_CHANGED(codeToTest) \
49 root->ResetAllChangeTrackingForSubtree(); \
50 codeToTest; \
51 EXPECT_FALSE(root->LayerPropertyChanged()); \
52 EXPECT_FALSE(child->LayerPropertyChanged()); \
53 EXPECT_FALSE(grandChild->LayerPropertyChanged()); \
54 EXPECT_TRUE(root->LayerSurfacePropertyChanged())
55
56 #define VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES(codeToTest) \
57 root->ResetAllChangeTrackingForSubtree(); \
58 hostImpl.ForcePrepareToDraw(); \
59 EXPECT_FALSE(hostImpl.active_tree()->needs_update_draw_properties()); \
60 codeToTest; \
61 EXPECT_TRUE(hostImpl.active_tree()->needs_update_draw_properties());
62
63 #define VERIFY_NO_NEEDS_UPDATE_DRAW_PROPERTIES(codeToTest) \
64 root->ResetAllChangeTrackingForSubtree(); \
65 hostImpl.ForcePrepareToDraw(); \
66 EXPECT_FALSE(hostImpl.active_tree()->needs_update_draw_properties()); \
67 codeToTest; \
68 EXPECT_FALSE(hostImpl.active_tree()->needs_update_draw_properties());
69
70 TEST(LayerImplTest, verifyLayerChangesAreTrackedProperly)
71 {
72 //
73 // This test checks that layerPropertyChanged() has the correct behavior.
74 //
75
76 // The constructor on this will fake that we are on the correct thread.
77 // Create a simple LayerImpl tree:
78 FakeImplProxy proxy;
79 FakeLayerTreeHostImpl hostImpl(&proxy);
80 EXPECT_TRUE(hostImpl.InitializeRenderer(createFakeOutputSurface()));
81 scoped_ptr<LayerImpl> root = LayerImpl::Create(hostImpl.active_tree(), 1);
82 root->AddChild(LayerImpl::Create(hostImpl.active_tree(), 2));
83 LayerImpl* child = root->children()[0];
84 child->AddChild(LayerImpl::Create(hostImpl.active_tree(), 3));
85 LayerImpl* grandChild = child->children()[0];
86
87 // Adding children is an internal operation and should not mark layers as ch anged.
88 EXPECT_FALSE(root->LayerPropertyChanged());
89 EXPECT_FALSE(child->LayerPropertyChanged());
90 EXPECT_FALSE(grandChild->LayerPropertyChanged());
91
92 gfx::PointF arbitraryPointF = gfx::PointF(0.125f, 0.25f);
93 float arbitraryNumber = 0.352f;
94 gfx::Size arbitrarySize = gfx::Size(111, 222);
95 gfx::Point arbitraryPoint = gfx::Point(333, 444);
96 gfx::Vector2d arbitraryVector2d = gfx::Vector2d(111, 222);
97 gfx::Rect arbitraryRect = gfx::Rect(arbitraryPoint, arbitrarySize);
98 gfx::RectF arbitraryRectF = gfx::RectF(arbitraryPointF, gfx::SizeF(1.234f, 5 .678f));
99 SkColor arbitraryColor = SkColorSetRGB(10, 20, 30);
100 gfx::Transform arbitraryTransform;
101 arbitraryTransform.Scale3d(0.1, 0.2, 0.3);
102 WebFilterOperations arbitraryFilters;
103 arbitraryFilters.append(WebFilterOperation::createOpacityFilter(0.5));
104 skia::RefPtr<SkImageFilter> arbitraryFilter = skia::AdoptRef(new SkBlurImage Filter(SK_Scalar1, SK_Scalar1));
105
106 // These properties are internal, and should not be considered "change" when they are used.
107 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(root->set_update_rect(arbitraryRec tF));
108 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(root->SetMaxScrollOffset(arbitrary Vector2d));
109
110 // Changing these properties affects the entire subtree of layers.
111 EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->SetAnchorPoint(arbitraryPointF));
112 EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->SetAnchorPointZ(arbitraryNumber));
113 EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->SetFilters(arbitraryFilters));
114 EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->SetFilters(WebFilterOperations()));
115 EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->SetFilter(arbitraryFilter));
116 EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->SetMaskLayer(LayerImpl::Create(host Impl.active_tree(), 4)));
117 EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->SetMasksToBounds(true));
118 EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->SetContentsOpaque(true));
119 EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->SetReplicaLayer(LayerImpl::Create(h ostImpl.active_tree(), 5)));
120 EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->SetPosition(arbitraryPointF));
121 EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->SetPreserves3d(true));
122 EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->SetDoubleSided(false)); // construc tor initializes it to "true".
123 EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->ScrollBy(arbitraryVector2d));
124 EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->SetScrollDelta(gfx::Vector2d()));
125 EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->SetScrollOffset(arbitraryVector2d)) ;
126 EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->SetImplTransform(arbitraryTransform ));
127
128 // Changing these properties only affects the layer itself.
129 EXECUTE_AND_VERIFY_ONLY_LAYER_CHANGED(root->SetContentBounds(arbitrarySize)) ;
130 EXECUTE_AND_VERIFY_ONLY_LAYER_CHANGED(root->SetContentsScale(arbitraryNumber , arbitraryNumber));
131 EXECUTE_AND_VERIFY_ONLY_LAYER_CHANGED(root->SetDrawsContent(true));
132 EXECUTE_AND_VERIFY_ONLY_LAYER_CHANGED(root->SetBackgroundColor(SK_ColorGRAY) );
133 EXECUTE_AND_VERIFY_ONLY_LAYER_CHANGED(root->SetBackgroundFilters(arbitraryFi lters));
134
135 // Changing these properties only affects how render surface is drawn
136 EXECUTE_AND_VERIFY_ONLY_SURFACE_CHANGED(root->SetOpacity(arbitraryNumber));
137 EXECUTE_AND_VERIFY_ONLY_SURFACE_CHANGED(root->SetTransform(arbitraryTransfor m));
138
139 // Special case: check that sublayer transform changes all layer's descendan ts, but not the layer itself.
140 root->ResetAllChangeTrackingForSubtree();
141 root->SetSublayerTransform(arbitraryTransform);
142 EXPECT_FALSE(root->LayerPropertyChanged());
143 EXPECT_TRUE(child->LayerPropertyChanged());
144 EXPECT_TRUE(grandChild->LayerPropertyChanged());
145
146 // Special case: check that setBounds changes behavior depending on masksToB ounds.
147 root->SetMasksToBounds(false);
148 EXECUTE_AND_VERIFY_ONLY_LAYER_CHANGED(root->SetBounds(gfx::Size(135, 246)));
149 root->SetMasksToBounds(true);
150 EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->SetBounds(arbitrarySize)); // shoul d be a different size than previous call, to ensure it marks tree changed.
151
152 // After setting all these properties already, setting to the exact same val ues again should
153 // not cause any change.
154 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(root->SetAnchorPoint(arbitraryPoin tF));
155 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(root->SetAnchorPointZ(arbitraryNum ber));
156 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(root->SetMasksToBounds(true));
157 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(root->SetPosition(arbitraryPointF) );
158 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(root->SetPreserves3d(true));
159 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(root->SetTransform(arbitraryTransf orm));
160 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(root->SetDoubleSided(false)); // c onstructor initializes it to "true".
161 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(root->SetScrollDelta(gfx::Vector2d ()));
162 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(root->SetScrollOffset(arbitraryVec tor2d));
163 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(root->SetImplTransform(arbitraryTr ansform));
164 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(root->SetContentBounds(arbitrarySi ze));
165 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(root->SetContentsScale(arbitraryNu mber, arbitraryNumber));
166 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(root->SetContentsOpaque(true));
167 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(root->SetOpacity(arbitraryNumber)) ;
168 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(root->SetDrawsContent(true));
169 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(root->SetSublayerTransform(arbitra ryTransform));
170 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(root->SetBounds(arbitrarySize));
171 }
172
173 TEST(LayerImplTest, VerifyNeedsUpdateDrawProperties)
174 {
175 FakeImplProxy proxy;
176 FakeLayerTreeHostImpl hostImpl(&proxy);
177 EXPECT_TRUE(hostImpl.InitializeRenderer(createFakeOutputSurface()));
178 scoped_ptr<LayerImpl> root = LayerImpl::Create(hostImpl.active_tree(), 1);
179
180 gfx::PointF arbitraryPointF = gfx::PointF(0.125f, 0.25f);
181 float arbitraryNumber = 0.352f;
182 gfx::Size arbitrarySize = gfx::Size(111, 222);
183 gfx::Point arbitraryPoint = gfx::Point(333, 444);
184 gfx::Vector2d arbitraryVector2d = gfx::Vector2d(111, 222);
185 gfx::Vector2d largeVector2d = gfx::Vector2d(1000, 1000);
186 gfx::Rect arbitraryRect = gfx::Rect(arbitraryPoint, arbitrarySize);
187 gfx::RectF arbitraryRectF = gfx::RectF(arbitraryPointF, gfx::SizeF(1.234f, 5 .678f));
188 SkColor arbitraryColor = SkColorSetRGB(10, 20, 30);
189 gfx::Transform arbitraryTransform;
190 arbitraryTransform.Scale3d(0.1, 0.2, 0.3);
191 WebFilterOperations arbitraryFilters;
192 arbitraryFilters.append(WebFilterOperation::createOpacityFilter(0.5));
193 skia::RefPtr<SkImageFilter> arbitraryFilter = skia::AdoptRef(new SkBlurImage Filter(SK_Scalar1, SK_Scalar1));
194
195 // Related filter functions.
196 VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES(root->SetFilters(arbitraryFilters));
197 VERIFY_NO_NEEDS_UPDATE_DRAW_PROPERTIES(root->SetFilters(arbitraryFilters));
198 VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES(root->SetFilters(WebFilterOperations())) ;
199 VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES(root->SetFilter(arbitraryFilter));
200 VERIFY_NO_NEEDS_UPDATE_DRAW_PROPERTIES(root->SetFilter(arbitraryFilter));
201
202 // Related scrolling functions.
203 VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES(root->SetMaxScrollOffset(largeVector2d)) ;
204 VERIFY_NO_NEEDS_UPDATE_DRAW_PROPERTIES(root->SetMaxScrollOffset(largeVector2 d));
205 VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES(root->ScrollBy(arbitraryVector2d));
206 VERIFY_NO_NEEDS_UPDATE_DRAW_PROPERTIES(root->ScrollBy(gfx::Vector2d()));
207 root->SetScrollDelta(gfx::Vector2d(0, 0));
208 hostImpl.ForcePrepareToDraw();
209 VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES(root->SetScrollDelta(arbitraryVector2d)) ;
210 VERIFY_NO_NEEDS_UPDATE_DRAW_PROPERTIES(root->SetScrollDelta(arbitraryVector2 d));
211 VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES(root->SetScrollOffset(arbitraryVector2d) );
212 VERIFY_NO_NEEDS_UPDATE_DRAW_PROPERTIES(root->SetScrollOffset(arbitraryVector 2d));
213
214 // Unrelated functions, always set to new values, always set needs update.
215 VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES(root->SetAnchorPointZ(arbitraryNumber));
216 VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES(root->SetMaskLayer(LayerImpl::Create(hos tImpl.active_tree(), 4)));
217 VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES(root->SetMasksToBounds(true));
218 VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES(root->SetContentsOpaque(true));
219 VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES(root->SetReplicaLayer(LayerImpl::Create( hostImpl.active_tree(), 5)));
220 VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES(root->SetPosition(arbitraryPointF));
221 VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES(root->SetPreserves3d(true));
222 VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES(root->SetDoubleSided(false)); // constru ctor initializes it to "true".
223 VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES(root->SetImplTransform(arbitraryTransfor m));
224 VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES(root->SetContentBounds(arbitrarySize));
225 VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES(root->SetContentsScale(arbitraryNumber, arbitraryNumber));
226 VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES(root->SetDrawsContent(true));
227 VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES(root->SetBackgroundColor(SK_ColorGRAY));
228 VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES(root->SetBackgroundFilters(arbitraryFilt ers));
229 VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES(root->SetOpacity(arbitraryNumber));
230 VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES(root->SetTransform(arbitraryTransform));
231 VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES(root->SetSublayerTransform(arbitraryTran sform));
232 VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES(root->SetBounds(arbitrarySize));
233
234 // Unrelated functions, set to the same values, no needs update.
235 VERIFY_NO_NEEDS_UPDATE_DRAW_PROPERTIES(root->SetAnchorPointZ(arbitraryNumber ));
236 VERIFY_NO_NEEDS_UPDATE_DRAW_PROPERTIES(root->SetFilter(arbitraryFilter));
237 VERIFY_NO_NEEDS_UPDATE_DRAW_PROPERTIES(root->SetMasksToBounds(true));
238 VERIFY_NO_NEEDS_UPDATE_DRAW_PROPERTIES(root->SetContentsOpaque(true));
239 VERIFY_NO_NEEDS_UPDATE_DRAW_PROPERTIES(root->SetPosition(arbitraryPointF));
240 VERIFY_NO_NEEDS_UPDATE_DRAW_PROPERTIES(root->SetPreserves3d(true));
241 VERIFY_NO_NEEDS_UPDATE_DRAW_PROPERTIES(root->SetDoubleSided(false)); // cons tructor initializes it to "true".
242 VERIFY_NO_NEEDS_UPDATE_DRAW_PROPERTIES(root->SetImplTransform(arbitraryTrans form));
243 VERIFY_NO_NEEDS_UPDATE_DRAW_PROPERTIES(root->SetContentBounds(arbitrarySize) );
244 VERIFY_NO_NEEDS_UPDATE_DRAW_PROPERTIES(root->SetContentsScale(arbitraryNumbe r, arbitraryNumber));
245 VERIFY_NO_NEEDS_UPDATE_DRAW_PROPERTIES(root->SetDrawsContent(true));
246 VERIFY_NO_NEEDS_UPDATE_DRAW_PROPERTIES(root->SetBackgroundColor(SK_ColorGRAY ));
247 VERIFY_NO_NEEDS_UPDATE_DRAW_PROPERTIES(root->SetBackgroundFilters(arbitraryF ilters));
248 VERIFY_NO_NEEDS_UPDATE_DRAW_PROPERTIES(root->SetOpacity(arbitraryNumber));
249 VERIFY_NO_NEEDS_UPDATE_DRAW_PROPERTIES(root->SetTransform(arbitraryTransform ));
250 VERIFY_NO_NEEDS_UPDATE_DRAW_PROPERTIES(root->SetSublayerTransform(arbitraryT ransform));
251 VERIFY_NO_NEEDS_UPDATE_DRAW_PROPERTIES(root->SetBounds(arbitrarySize));
252 }
253
254 } // namespace
255 } // namespace cc
OLDNEW
« no previous file with comments | « cc/layer_impl.cc ('k') | cc/layer_iterator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698