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