| OLD | NEW |
| (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 "config.h" | |
| 6 | |
| 7 #include "CCLayerImpl.h" | |
| 8 | |
| 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> | |
| 14 | |
| 15 using namespace cc; | |
| 16 using namespace WebKit; | |
| 17 | |
| 18 namespace { | |
| 19 | |
| 20 #define EXECUTE_AND_VERIFY_SUBTREE_CHANGED(codeToTest) \ | |
| 21 root->resetAllChangeTrackingForSubtree(); \ | |
| 22 codeToTest; \ | |
| 23 EXPECT_TRUE(root->layerPropertyChanged()); \ | |
| 24 EXPECT_TRUE(child->layerPropertyChanged()); \ | |
| 25 EXPECT_TRUE(grandChild->layerPropertyChanged()); \ | |
| 26 EXPECT_FALSE(root->layerSurfacePropertyChanged()) | |
| 27 | |
| 28 | |
| 29 #define EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(codeToTest) \ | |
| 30 root->resetAllChangeTrackingForSubtree(); \ | |
| 31 codeToTest; \ | |
| 32 EXPECT_FALSE(root->layerPropertyChanged()); \ | |
| 33 EXPECT_FALSE(child->layerPropertyChanged()); \ | |
| 34 EXPECT_FALSE(grandChild->layerPropertyChanged()); \ | |
| 35 EXPECT_FALSE(root->layerSurfacePropertyChanged()) | |
| 36 | |
| 37 #define EXECUTE_AND_VERIFY_ONLY_LAYER_CHANGED(codeToTest) \ | |
| 38 root->resetAllChangeTrackingForSubtree(); \ | |
| 39 codeToTest; \ | |
| 40 EXPECT_TRUE(root->layerPropertyChanged()); \ | |
| 41 EXPECT_FALSE(child->layerPropertyChanged()); \ | |
| 42 EXPECT_FALSE(grandChild->layerPropertyChanged()); \ | |
| 43 EXPECT_FALSE(root->layerSurfacePropertyChanged()) | |
| 44 | |
| 45 #define EXECUTE_AND_VERIFY_ONLY_SURFACE_CHANGED(codeToTest) \ | |
| 46 root->resetAllChangeTrackingForSubtree(); \ | |
| 47 codeToTest; \ | |
| 48 EXPECT_FALSE(root->layerPropertyChanged()); \ | |
| 49 EXPECT_FALSE(child->layerPropertyChanged()); \ | |
| 50 EXPECT_FALSE(grandChild->layerPropertyChanged()); \ | |
| 51 EXPECT_TRUE(root->layerSurfacePropertyChanged()) | |
| 52 | |
| 53 TEST(CCLayerImplTest, verifyLayerChangesAreTrackedProperly) | |
| 54 { | |
| 55 // | |
| 56 // This test checks that layerPropertyChanged() has the correct behavior. | |
| 57 // | |
| 58 | |
| 59 // The constructor on this will fake that we are on the correct thread. | |
| 60 DebugScopedSetImplThread setImplThread; | |
| 61 | |
| 62 // Create a simple CCLayerImpl tree: | |
| 63 scoped_ptr<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]; | |
| 68 | |
| 69 // Adding children is an internal operation and should not mark layers as ch
anged. | |
| 70 EXPECT_FALSE(root->layerPropertyChanged()); | |
| 71 EXPECT_FALSE(child->layerPropertyChanged()); | |
| 72 EXPECT_FALSE(grandChild->layerPropertyChanged()); | |
| 73 | |
| 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.23
4f, 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)); | |
| 85 | |
| 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(arbitraryNumb
er)); | |
| 89 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(root->setRenderTarget(0)); | |
| 90 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(root->setDrawTransform(arbitraryTr
ansform)); | |
| 91 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(root->setScreenSpaceTransform(arbi
traryTransform)); | |
| 92 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(root->setDrawableContentRect(arbit
raryIntRect)); | |
| 93 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(root->setUpdateRect(arbitraryFloat
Rect)); | |
| 94 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(root->setVisibleContentRect(arbitr
aryIntRect)); | |
| 95 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(root->setMaxScrollPosition(arbitra
ryIntSize)); | |
| 96 | |
| 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)); // construc
tor 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
)); | |
| 112 | |
| 113 // Changing these properties only affects the layer itself. | |
| 114 EXECUTE_AND_VERIFY_ONLY_LAYER_CHANGED(root->setContentBounds(arbitraryIntSiz
e)); | |
| 115 EXECUTE_AND_VERIFY_ONLY_LAYER_CHANGED(root->setDebugBorderColor(arbitraryCol
or)); | |
| 116 EXECUTE_AND_VERIFY_ONLY_LAYER_CHANGED(root->setDebugBorderWidth(arbitraryNum
ber)); | |
| 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(arbitraryFi
lters)); | |
| 120 | |
| 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(arbitraryTransfor
m)); | |
| 124 | |
| 125 // Special case: check that sublayer transform changes all layer's descendan
ts, 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()); | |
| 131 | |
| 132 // Special case: check that setBounds changes behavior depending on masksToB
ounds. | |
| 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)); // sh
ould be a different size than previous call, to ensure it marks tree changed. | |
| 137 | |
| 138 // After setting all these properties already, setting to the exact same val
ues again should | |
| 139 // not cause any change. | |
| 140 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(root->setAnchorPoint(arbitraryFloa
tPoint)); | |
| 141 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(root->setAnchorPointZ(arbitraryNum
ber)); | |
| 142 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(root->setMasksToBounds(true)); | |
| 143 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(root->setPosition(arbitraryFloatPo
int)); | |
| 144 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(root->setPreserves3D(true)); | |
| 145 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(root->setTransform(arbitraryTransf
orm)); | |
| 146 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(root->setDoubleSided(false)); // c
onstructor 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(arbitraryI
ntPoint)); | |
| 149 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(root->setImplTransform(arbitraryTr
ansform)); | |
| 150 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(root->setContentBounds(arbitraryIn
tSize)); | |
| 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(arbitrar
yColor)); | |
| 154 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(root->setDebugBorderWidth(arbitrar
yNumber)); | |
| 155 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(root->setDrawsContent(true)); | |
| 156 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(root->setSublayerTransform(arbitra
ryTransform)); | |
| 157 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(root->setBounds(arbitraryIntSize))
; | |
| 158 } | |
| 159 | |
| 160 } // namespace | |
| OLD | NEW |