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