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.
7 #include "CCLayerImpl.h"
9 #include "CCSingleThreadProxy.h"
10 #include "testing/gmock/include/gmock/gmock.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12 #include <public/WebFilterOperation.h>
13 #include <public/WebFilterOperations.h>
16 using namespace WebKit
;
20 #define EXECUTE_AND_VERIFY_SUBTREE_CHANGED(codeToTest) \
21 root->resetAllChangeTrackingForSubtree(); \
23 EXPECT_TRUE(root->layerPropertyChanged()); \
24 EXPECT_TRUE(child->layerPropertyChanged()); \
25 EXPECT_TRUE(grandChild->layerPropertyChanged()); \
26 EXPECT_FALSE(root->layerSurfacePropertyChanged())
29 #define EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(codeToTest) \
30 root->resetAllChangeTrackingForSubtree(); \
32 EXPECT_FALSE(root->layerPropertyChanged()); \
33 EXPECT_FALSE(child->layerPropertyChanged()); \
34 EXPECT_FALSE(grandChild->layerPropertyChanged()); \
35 EXPECT_FALSE(root->layerSurfacePropertyChanged())
37 #define EXECUTE_AND_VERIFY_ONLY_LAYER_CHANGED(codeToTest) \
38 root->resetAllChangeTrackingForSubtree(); \
40 EXPECT_TRUE(root->layerPropertyChanged()); \
41 EXPECT_FALSE(child->layerPropertyChanged()); \
42 EXPECT_FALSE(grandChild->layerPropertyChanged()); \
43 EXPECT_FALSE(root->layerSurfacePropertyChanged())
45 #define EXECUTE_AND_VERIFY_ONLY_SURFACE_CHANGED(codeToTest) \
46 root->resetAllChangeTrackingForSubtree(); \
48 EXPECT_FALSE(root->layerPropertyChanged()); \
49 EXPECT_FALSE(child->layerPropertyChanged()); \
50 EXPECT_FALSE(grandChild->layerPropertyChanged()); \
51 EXPECT_TRUE(root->layerSurfacePropertyChanged())
53 TEST(CCLayerImplTest
, verifyLayerChangesAreTrackedProperly
)
56 // This test checks that layerPropertyChanged() has the correct behavior.
59 // The constructor on this will fake that we are on the correct thread.
60 DebugScopedSetImplThread setImplThread
;
62 // Create a simple CCLayerImpl tree:
63 OwnPtr
<CCLayerImpl
> root
= CCLayerImpl::create(1);
64 root
->addChild(CCLayerImpl::create(2));
65 CCLayerImpl
* child
= root
->children()[0];
66 child
->addChild(CCLayerImpl::create(3));
67 CCLayerImpl
* grandChild
= child
->children()[0];
69 // Adding children is an internal operation and should not mark layers as changed.
70 EXPECT_FALSE(root
->layerPropertyChanged());
71 EXPECT_FALSE(child
->layerPropertyChanged());
72 EXPECT_FALSE(grandChild
->layerPropertyChanged());
74 FloatPoint arbitraryFloatPoint
= FloatPoint(0.125f
, 0.25f
);
75 float arbitraryNumber
= 0.352f
;
76 IntSize arbitraryIntSize
= IntSize(111, 222);
77 IntPoint arbitraryIntPoint
= IntPoint(333, 444);
78 IntRect arbitraryIntRect
= IntRect(arbitraryIntPoint
, arbitraryIntSize
);
79 FloatRect arbitraryFloatRect
= FloatRect(arbitraryFloatPoint
, FloatSize(1.234f
, 5.678f
));
80 SkColor arbitraryColor
= SkColorSetRGB(10, 20, 30);
81 WebTransformationMatrix arbitraryTransform
;
82 arbitraryTransform
.scale3d(0.1, 0.2, 0.3);
83 WebFilterOperations arbitraryFilters
;
84 arbitraryFilters
.append(WebFilterOperation::createOpacityFilter(0.5));
86 // These properties are internal, and should not be considered "change" when they are used.
87 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(root
->setUseLCDText(true));
88 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(root
->setDrawOpacity(arbitraryNumber
));
89 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(root
->setRenderTarget(0));
90 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(root
->setDrawTransform(arbitraryTransform
));
91 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(root
->setScreenSpaceTransform(arbitraryTransform
));
92 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(root
->setDrawableContentRect(arbitraryIntRect
));
93 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(root
->setUpdateRect(arbitraryFloatRect
));
94 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(root
->setVisibleContentRect(arbitraryIntRect
));
95 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(root
->setMaxScrollPosition(arbitraryIntSize
));
97 // Changing these properties affects the entire subtree of layers.
98 EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root
->setAnchorPoint(arbitraryFloatPoint
));
99 EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root
->setAnchorPointZ(arbitraryNumber
));
100 EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root
->setFilters(arbitraryFilters
));
101 EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root
->setMaskLayer(CCLayerImpl::create(4)));
102 EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root
->setMasksToBounds(true));
103 EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root
->setContentsOpaque(true));
104 EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root
->setReplicaLayer(CCLayerImpl::create(5)));
105 EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root
->setPosition(arbitraryFloatPoint
));
106 EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root
->setPreserves3D(true));
107 EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root
->setDoubleSided(false)); // constructor initializes it to "true".
108 EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root
->scrollBy(arbitraryIntSize
));
109 EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root
->setScrollDelta(IntSize()));
110 EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root
->setScrollPosition(arbitraryIntPoint
));
111 EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root
->setImplTransform(arbitraryTransform
));
113 // Changing these properties only affects the layer itself.
114 EXECUTE_AND_VERIFY_ONLY_LAYER_CHANGED(root
->setContentBounds(arbitraryIntSize
));
115 EXECUTE_AND_VERIFY_ONLY_LAYER_CHANGED(root
->setDebugBorderColor(arbitraryColor
));
116 EXECUTE_AND_VERIFY_ONLY_LAYER_CHANGED(root
->setDebugBorderWidth(arbitraryNumber
));
117 EXECUTE_AND_VERIFY_ONLY_LAYER_CHANGED(root
->setDrawsContent(true));
118 EXECUTE_AND_VERIFY_ONLY_LAYER_CHANGED(root
->setBackgroundColor(SK_ColorGRAY
));
119 EXECUTE_AND_VERIFY_ONLY_LAYER_CHANGED(root
->setBackgroundFilters(arbitraryFilters
));
121 // Changing these properties only affects how render surface is drawn
122 EXECUTE_AND_VERIFY_ONLY_SURFACE_CHANGED(root
->setOpacity(arbitraryNumber
));
123 EXECUTE_AND_VERIFY_ONLY_SURFACE_CHANGED(root
->setTransform(arbitraryTransform
));
125 // Special case: check that sublayer transform changes all layer's descendants, but not the layer itself.
126 root
->resetAllChangeTrackingForSubtree();
127 root
->setSublayerTransform(arbitraryTransform
);
128 EXPECT_FALSE(root
->layerPropertyChanged());
129 EXPECT_TRUE(child
->layerPropertyChanged());
130 EXPECT_TRUE(grandChild
->layerPropertyChanged());
132 // Special case: check that setBounds changes behavior depending on masksToBounds.
133 root
->setMasksToBounds(false);
134 EXECUTE_AND_VERIFY_ONLY_LAYER_CHANGED(root
->setBounds(IntSize(135, 246)));
135 root
->setMasksToBounds(true);
136 EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root
->setBounds(arbitraryIntSize
)); // should be a different size than previous call, to ensure it marks tree changed.
138 // After setting all these properties already, setting to the exact same values again should
139 // not cause any change.
140 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(root
->setAnchorPoint(arbitraryFloatPoint
));
141 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(root
->setAnchorPointZ(arbitraryNumber
));
142 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(root
->setMasksToBounds(true));
143 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(root
->setPosition(arbitraryFloatPoint
));
144 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(root
->setPreserves3D(true));
145 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(root
->setTransform(arbitraryTransform
));
146 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(root
->setDoubleSided(false)); // constructor initializes it to "true".
147 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(root
->setScrollDelta(IntSize()));
148 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(root
->setScrollPosition(arbitraryIntPoint
));
149 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(root
->setImplTransform(arbitraryTransform
));
150 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(root
->setContentBounds(arbitraryIntSize
));
151 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(root
->setContentsOpaque(true));
152 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(root
->setOpacity(arbitraryNumber
));
153 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(root
->setDebugBorderColor(arbitraryColor
));
154 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(root
->setDebugBorderWidth(arbitraryNumber
));
155 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(root
->setDrawsContent(true));
156 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(root
->setSublayerTransform(arbitraryTransform
));
157 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(root
->setBounds(arbitraryIntSize
));