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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
cc / test / property_tree_test_utils.h [blame]
// Copyright 2019 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CC_TEST_PROPERTY_TREE_TEST_UTILS_H_
#define CC_TEST_PROPERTY_TREE_TEST_UTILS_H_
#include "cc/trees/clip_node.h"
#include "cc/trees/effect_node.h"
#include "cc/trees/property_tree.h"
#include "cc/trees/scroll_node.h"
#include "cc/trees/transform_node.h"
#include "ui/gfx/geometry/point_f.h"
#include "ui/gfx/geometry/vector2d_f.h"
namespace cc {
class Layer;
class LayerImpl;
class PictureLayer;
class PictureLayerImpl;
// Sets up properties that apply to the root layer.
void SetupRootProperties(Layer* root);
void SetupRootProperties(LayerImpl* root);
// Copies property tree indexes from |from| to |to|. For the |Layer| form, also
// copies |from|'s layer_host_host and property_tree_sequence_number to |to|.
void CopyProperties(Layer* from, Layer* to);
void CopyProperties(const LayerImpl* from, LayerImpl* to);
// Each of the following functions creates a property node for the layer,
// and sets the new node as the layer's property node of the type.
// The new property node's parent will be |parent_id| if it's specified.
// Otherwise the layer's current property node of the corresponding type will
// be the parent. The latter case is useful to create property nodes after
// CopyProperties() under the copied properties.
TransformNode& CreateTransformNode(Layer*,
int parent_id = kInvalidPropertyNodeId);
TransformNode& CreateTransformNode(LayerImpl*,
int parent_id = kInvalidPropertyNodeId);
ClipNode& CreateClipNode(Layer*, int parent_id = kInvalidPropertyNodeId);
ClipNode& CreateClipNode(LayerImpl*, int parent_id = kInvalidPropertyNodeId);
EffectNode& CreateEffectNode(Layer*, int parent_id = kInvalidPropertyNodeId);
EffectNode& CreateEffectNode(LayerImpl*,
int parent_id = kInvalidPropertyNodeId);
// The scroll node is not scrollable if |scroll_container_bounds| is empty.
ScrollNode& CreateScrollNode(Layer*,
const gfx::Size& scroll_container_bounds,
int parent_id = kInvalidPropertyNodeId);
ScrollNode& CreateScrollNode(LayerImpl*,
const gfx::Size& scroll_container_bounds,
int parent_id = kInvalidPropertyNodeId);
// These functions create property nodes not associated with layers.
TransformNode& CreateTransformNode(PropertyTrees*, int parent_id);
ClipNode& CreateClipNode(PropertyTrees*, int parent_id, int transform_id);
EffectNode& CreateEffectNode(PropertyTrees*,
int parent_id,
int transform_id,
int clip_id);
// This creates a scroll node that looks like a scroller that wasn't composited
// (isn't connected to a Layer). This function will also create a matching
// transform node that is a child of the parent's transform node.
ScrollNode& CreateScrollNodeForNonCompositedScroller(
PropertyTrees* property_trees,
int parent_id,
ElementId element_id,
const gfx::Size& bounds,
const gfx::Size& scroll_container_bounds,
const gfx::Point& scroll_container_origin = gfx::Point());
void SetupMaskProperties(LayerImpl* masked_layer, PictureLayerImpl* mask_layer);
void SetupMaskProperties(Layer* masked_layer, PictureLayer* mask_layer);
PropertyTrees* GetPropertyTrees(Layer* layer);
const PropertyTrees* GetPropertyTrees(const Layer* layer);
PropertyTrees* GetPropertyTrees(LayerImpl* layer);
const PropertyTrees* GetPropertyTrees(const LayerImpl* layer);
template <typename LayerType>
TransformNode* GetTransformNode(LayerType* layer) {
return GetPropertyTrees(layer)->transform_tree_mutable().Node(
layer->transform_tree_index());
}
template <typename LayerType>
const TransformNode* GetTransformNode(const LayerType* layer) {
return GetPropertyTrees(layer)->transform_tree().Node(
layer->transform_tree_index());
}
template <typename LayerType>
ClipNode* GetClipNode(LayerType* layer) {
return GetPropertyTrees(layer)->clip_tree_mutable().Node(
layer->clip_tree_index());
}
template <typename LayerType>
const ClipNode* GetClipNode(const LayerType* layer) {
return GetPropertyTrees(layer)->clip_tree().Node(layer->clip_tree_index());
}
template <typename LayerType>
EffectNode* GetEffectNode(LayerType* layer) {
return GetPropertyTrees(layer)->effect_tree_mutable().Node(
layer->effect_tree_index());
}
template <typename LayerType>
const EffectNode* GetEffectNode(const LayerType* layer) {
return GetPropertyTrees(layer)->effect_tree().Node(
layer->effect_tree_index());
}
template <typename LayerType>
ScrollNode* GetScrollNode(LayerType* layer) {
return GetPropertyTrees(layer)->scroll_tree_mutable().Node(
layer->scroll_tree_index());
}
template <typename LayerType>
const ScrollNode* GetScrollNode(const LayerType* layer) {
return GetPropertyTrees(layer)->scroll_tree().Node(
layer->scroll_tree_index());
}
void SetScrollOffset(Layer*, const gfx::PointF&);
void SetScrollOffset(LayerImpl*, const gfx::PointF&);
// Used to synchronize the main-thread scroll offset with the impl-side. The
// difference from SetScrollOffset() is this function doesn't schedule commit.
void SetScrollOffsetFromImplSide(Layer*, const gfx::PointF&);
template <typename LayerType>
void SetLocalTransformChanged(LayerType* layer) {
DCHECK(layer->has_transform_node());
auto* transform_node = GetTransformNode(layer);
transform_node->needs_local_transform_update = true;
transform_node->transform_changed = true;
GetPropertyTrees(layer)->transform_tree_mutable().set_needs_update(true);
}
template <typename LayerType>
void SetWillChangeTransform(LayerType* layer, bool will_change_transform) {
DCHECK(layer->has_transform_node());
auto* transform_node = GetTransformNode(layer);
transform_node->will_change_transform = will_change_transform;
transform_node->node_or_ancestors_will_change_transform =
will_change_transform;
transform_node->transform_changed = true;
TransformTree& transform_tree =
GetPropertyTrees(layer)->transform_tree_mutable();
transform_tree.UpdateNodeOrAncestorsWillChangeTransform(
transform_node, transform_tree.parent(transform_node));
transform_tree.set_needs_update(true);
}
template <typename LayerType>
void SetTransform(LayerType* layer, const gfx::Transform& transform) {
GetTransformNode(layer)->local = transform;
SetLocalTransformChanged(layer);
}
template <typename LayerType>
void SetTransformOrigin(LayerType* layer, const gfx::Point3F& origin) {
GetTransformNode(layer)->origin = origin;
SetLocalTransformChanged(layer);
}
template <typename LayerType>
void SetPostTranslation(LayerType* layer,
const gfx::Vector2dF& post_translation) {
GetTransformNode(layer)->post_translation = post_translation;
SetLocalTransformChanged(layer);
}
// This will affect all layers associated with this layer's effect node.
template <typename LayerType>
void SetOpacity(LayerType* layer, float opacity) {
auto* effect_node = GetEffectNode(layer);
effect_node->opacity = opacity;
effect_node->effect_changed = true;
GetPropertyTrees(layer)->effect_tree_mutable().set_needs_update(true);
}
// This will affect all layers associated with this layer's effect node.
template <typename LayerType>
void SetFilter(LayerType* layer, const FilterOperations& filters) {
auto* effect_node = GetEffectNode(layer);
effect_node->filters = filters;
effect_node->effect_changed = true;
GetPropertyTrees(layer)->effect_tree_mutable().set_needs_update(true);
}
// This will affect all layers associated with this layer's effect node.
template <typename LayerType>
void SetRenderSurfaceReason(LayerType* layer, RenderSurfaceReason reason) {
auto* effect_node = GetEffectNode(layer);
effect_node->render_surface_reason = reason;
effect_node->effect_changed = true;
GetPropertyTrees(layer)->effect_tree_mutable().set_needs_update(true);
}
// This will affect all layers associated with this layer's effect node.
template <typename LayerType>
void SetBackdropFilter(LayerType* layer, const FilterOperations& filters) {
auto* effect_node = GetEffectNode(layer);
effect_node->backdrop_filters = filters;
effect_node->effect_changed = true;
GetPropertyTrees(layer)->effect_tree_mutable().set_needs_update(true);
}
// This will affect all layers associated with this layer's clip node.
template <typename LayerType>
void SetClipRect(LayerType* layer, const gfx::RectF& clip) {
auto* clip_node = GetClipNode(layer);
clip_node->clip = clip;
GetPropertyTrees(layer)->clip_tree.set_needs_update(true);
}
// Creates viewport layers and (in layer list mode) paint properties.
// Convenient overload of the method below that creates a scrolling layer as
// the outer viewport scroll layer. The inner viewport size will be
// root->bounds().
void SetupViewport(Layer* root,
const gfx::Size& outer_viewport_size,
const gfx::Size& content_size);
// Creates viewport layers and (in layer list mode) paint properties.
// Uses the given scroll layer as the content "outer viewport scroll layer".
void SetupViewport(Layer* root,
scoped_refptr<Layer> outer_viewport_scroll_layer,
const gfx::Size& outer_viewport_size);
// The impl-side counterpart of the first version of SetupViewport().
void SetupViewport(LayerImpl* root,
const gfx::Size& outer_viewport_size,
const gfx::Size& content_size);
// Returns the RenderSurfaceImpl into which the given layer draws.
RenderSurfaceImpl* GetRenderSurface(LayerImpl* layer);
const RenderSurfaceImpl* GetRenderSurface(const LayerImpl* layer);
gfx::PointF ScrollOffsetBase(const LayerImpl* layer);
gfx::Vector2dF ScrollDelta(const LayerImpl* layer);
gfx::PointF CurrentScrollOffset(const Layer* layer,
const PropertyTrees* property_trees = nullptr);
gfx::PointF CurrentScrollOffset(const LayerImpl* layer);
gfx::PointF MaxScrollOffset(const LayerImpl* layer);
} // namespace cc
#endif // CC_TEST_PROPERTY_TREE_TEST_UTILS_H_