Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4)

Side by Side Diff: cc/trees/property_tree.h

Issue 2118993002: Detemplatize cc property nodes (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 #ifndef CC_TREES_PROPERTY_TREE_H_ 5 #ifndef CC_TREES_PROPERTY_TREE_H_
6 #define CC_TREES_PROPERTY_TREE_H_ 6 #define CC_TREES_PROPERTY_TREE_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 9
10 #include <memory> 10 #include <memory>
11 #include <unordered_map> 11 #include <unordered_map>
12 #include <vector> 12 #include <vector>
13 13
14 #include "cc/animation/element_id.h" 14 #include "cc/animation/element_id.h"
15 #include "cc/base/cc_export.h" 15 #include "cc/base/cc_export.h"
16 #include "cc/base/synced_property.h" 16 #include "cc/base/synced_property.h"
17 #include "cc/output/filter_operations.h"
18 #include "ui/gfx/geometry/rect_f.h" 17 #include "ui/gfx/geometry/rect_f.h"
19 #include "ui/gfx/geometry/scroll_offset.h" 18 #include "ui/gfx/geometry/scroll_offset.h"
20 #include "ui/gfx/transform.h" 19 #include "ui/gfx/transform.h"
21 20
22 namespace base { 21 namespace base {
23 namespace trace_event { 22 namespace trace_event {
24 class TracedValue; 23 class TracedValue;
25 } 24 }
26 } 25 }
27 26
28 namespace cc { 27 namespace cc {
29 28
30 namespace proto { 29 namespace proto {
31 class ClipNodeData;
32 class EffectNodeData;
33 class PropertyTree; 30 class PropertyTree;
34 class PropertyTrees; 31 class PropertyTrees;
35 class ScrollNodeData; 32 class ScrollNodeData;
36 class TransformNodeData;
37 class TransformCachedNodeData;
38 class TransformTreeData;
39 class TreeNode; 33 class TreeNode;
40 } // namespace proto 34 } // namespace proto
41 35
42 class CopyOutputRequest; 36 class CopyOutputRequest;
43 class LayerTreeImpl; 37 class LayerTreeImpl;
44 class RenderSurfaceImpl;
45 class ScrollState; 38 class ScrollState;
39 struct ClipNode;
40 struct EffectNode;
46 struct ScrollAndScaleSet; 41 struct ScrollAndScaleSet;
42 struct ScrollNode;
43 struct TransformNode;
44 struct TransformCachedNodeData;
47 45
48 // ------------------------------*IMPORTANT*--------------------------------- 46 // ------------------------------*IMPORTANT*---------------------------------
49 // Each class declared here has a corresponding proto defined in 47 // Each class declared here has a corresponding proto defined in
50 // cc/proto/property_tree.proto. When making any changes to a class structure 48 // cc/proto/property_tree.proto. When making any changes to a class structure
51 // including addition/deletion/updation of a field, please also make the 49 // including addition/deletion/updation of a field, please also make the
52 // change to its proto and the ToProtobuf and FromProtobuf methods for that 50 // change to its proto and the ToProtobuf and FromProtobuf methods for that
53 // class. 51 // class.
54 52
55 typedef SyncedProperty<AdditionGroup<gfx::ScrollOffset>> SyncedScrollOffset; 53 typedef SyncedProperty<AdditionGroup<gfx::ScrollOffset>> SyncedScrollOffset;
56 54
57 template <typename T>
58 struct CC_EXPORT TreeNode {
59 TreeNode() : id(-1), parent_id(-1), owner_id(-1), data() {}
60 int id;
61 int parent_id;
62 int owner_id;
63 T data;
64
65 bool operator==(const TreeNode<T>& other) const;
66
67 void ToProtobuf(proto::TreeNode* proto) const;
68 void FromProtobuf(const proto::TreeNode& proto);
69
70 void AsValueInto(base::trace_event::TracedValue* value) const;
71 };
72
73 struct CC_EXPORT TransformNodeData {
74 TransformNodeData();
75 TransformNodeData(const TransformNodeData& other);
76 ~TransformNodeData();
77
78 // The local transform information is combined to form to_parent (ignoring
79 // snapping) as follows:
80 //
81 // to_parent = M_post_local * T_scroll * M_local * M_pre_local.
82 //
83 // The pre/post may seem odd when read LTR, but we multiply our points from
84 // the right, so the pre_local matrix affects the result "first". This lines
85 // up with the notions of pre/post used in skia and gfx::Transform.
86 //
87 // TODO(vollick): The values labeled with "will be moved..." take up a lot of
88 // space, but are only necessary for animated or scrolled nodes (otherwise
89 // we'll just use the baked to_parent). These values will be ultimately stored
90 // directly on the transform/scroll display list items when that's possible,
91 // or potentially in a scroll tree.
92 //
93 // TODO(vollick): will be moved when accelerated effects are implemented.
94 gfx::Transform pre_local;
95 gfx::Transform local;
96 gfx::Transform post_local;
97
98 gfx::Transform to_parent;
99
100 // This is the node with respect to which source_offset is defined. This will
101 // not be needed once layerization moves to cc, but is needed in order to
102 // efficiently update the transform tree for changes to position in the layer
103 // tree.
104 int source_node_id;
105
106 // This id determines which 3d rendering context the node is in. 0 is a
107 // special value and indicates that the node is not in any 3d rendering
108 // context.
109 int sorting_context_id;
110
111 // TODO(vollick): will be moved when accelerated effects are implemented.
112 bool needs_local_transform_update : 1;
113
114 bool node_and_ancestors_are_animated_or_invertible : 1;
115
116 bool is_invertible : 1;
117 bool ancestors_are_invertible : 1;
118
119 bool has_potential_animation : 1;
120 bool is_currently_animating : 1;
121 bool to_screen_is_potentially_animated : 1;
122 bool has_only_translation_animations : 1;
123
124 // Flattening, when needed, is only applied to a node's inherited transform,
125 // never to its local transform.
126 bool flattens_inherited_transform : 1;
127
128 // This is true if the to_parent transform at every node on the path to the
129 // root is flat.
130 bool node_and_ancestors_are_flat : 1;
131
132 // This is needed to know if a layer can use lcd text.
133 bool node_and_ancestors_have_only_integer_translation : 1;
134
135 bool scrolls : 1;
136
137 bool needs_sublayer_scale : 1;
138
139 // These are used to position nodes wrt the right or bottom of the inner or
140 // outer viewport.
141 bool affected_by_inner_viewport_bounds_delta_x : 1;
142 bool affected_by_inner_viewport_bounds_delta_y : 1;
143 bool affected_by_outer_viewport_bounds_delta_x : 1;
144 bool affected_by_outer_viewport_bounds_delta_y : 1;
145
146 // Layer scale factor is used as a fallback when we either cannot adjust
147 // raster scale or if the raster scale cannot be extracted from the screen
148 // space transform. For layers in the subtree of the page scale layer, the
149 // layer scale factor should include the page scale factor.
150 bool in_subtree_of_page_scale_layer : 1;
151
152 // We need to track changes to to_screen transform to compute the damage rect.
153 bool transform_changed : 1;
154
155 // TODO(vollick): will be moved when accelerated effects are implemented.
156 float post_local_scale_factor;
157
158 gfx::Vector2dF sublayer_scale;
159
160 // TODO(vollick): will be moved when accelerated effects are implemented.
161 gfx::ScrollOffset scroll_offset;
162
163 // We scroll snap where possible, but this means fixed-pos elements must be
164 // adjusted. This value stores the snapped amount for this purpose.
165 gfx::Vector2dF scroll_snap;
166
167 // TODO(vollick): will be moved when accelerated effects are implemented.
168 gfx::Vector2dF source_offset;
169 gfx::Vector2dF source_to_parent;
170
171 bool operator==(const TransformNodeData& other) const;
172
173 void set_to_parent(const gfx::Transform& transform) {
174 to_parent = transform;
175 is_invertible = to_parent.IsInvertible();
176 }
177
178 void update_pre_local_transform(const gfx::Point3F& transform_origin);
179
180 void update_post_local_transform(const gfx::PointF& position,
181 const gfx::Point3F& transform_origin);
182
183 void ToProtobuf(proto::TreeNode* proto) const;
184 void FromProtobuf(const proto::TreeNode& proto);
185
186 void AsValueInto(base::trace_event::TracedValue* value) const;
187 };
188
189 // TODO(sunxd): move this into PropertyTrees::cached_data_.
190 struct CC_EXPORT TransformCachedNodeData {
191 TransformCachedNodeData();
192 TransformCachedNodeData(const TransformCachedNodeData& other);
193 ~TransformCachedNodeData();
194
195 gfx::Transform from_target;
196 gfx::Transform to_target;
197 gfx::Transform from_screen;
198 gfx::Transform to_screen;
199 int target_id;
200 // This id is used for all content that draws into a render surface associated
201 // with this transform node.
202 int content_target_id;
203
204 bool operator==(const TransformCachedNodeData& other) const;
205
206 void ToProtobuf(proto::TransformCachedNodeData* proto) const;
207 void FromProtobuf(const proto::TransformCachedNodeData& proto);
208 };
209
210 typedef TreeNode<TransformNodeData> TransformNode;
211
212 struct CC_EXPORT ClipNodeData {
213 ClipNodeData();
214 ClipNodeData(const ClipNodeData& other);
215
216 // The clip rect that this node contributes, expressed in the space of its
217 // transform node.
218 gfx::RectF clip;
219
220 // Clip nodes are uses for two reasons. First, they are used for determining
221 // which parts of each layer are visible. Second, they are used for
222 // determining whether a clip needs to be applied when drawing a layer, and if
223 // so, the rect that needs to be used. These can be different since not all
224 // clips need to be applied directly to each layer. For example, a layer is
225 // implicitly clipped by the bounds of its target render surface and by clips
226 // applied to this surface. |combined_clip_in_target_space| is used for
227 // computing visible rects, and |clip_in_target_space| is used for computing
228 // clips applied at draw time. Both rects are expressed in the space of the
229 // target transform node, and may include clips contributed by ancestors.
230 gfx::RectF combined_clip_in_target_space;
231 gfx::RectF clip_in_target_space;
232
233 // The id of the transform node that defines the clip node's local space.
234 int transform_id;
235
236 // The id of the transform node that defines the clip node's target space.
237 int target_id;
238
239 // Whether this node contributes a new clip (that is, whether |clip| needs to
240 // be applied), rather than only inheriting ancestor clips.
241 bool applies_local_clip : 1;
242
243 // When true, |clip_in_target_space| does not include clips from ancestor
244 // nodes.
245 bool layer_clipping_uses_only_local_clip : 1;
246
247 // True if target surface needs to be drawn with a clip applied.
248 bool target_is_clipped : 1;
249
250 // True if layers with this clip tree node need to be drawn with a clip
251 // applied.
252 bool layers_are_clipped : 1;
253 bool layers_are_clipped_when_surfaces_disabled : 1;
254
255 // Nodes that correspond to unclipped surfaces disregard ancestor clips.
256 bool resets_clip : 1;
257
258 bool operator==(const ClipNodeData& other) const;
259
260 void ToProtobuf(proto::TreeNode* proto) const;
261 void FromProtobuf(const proto::TreeNode& proto);
262 void AsValueInto(base::trace_event::TracedValue* value) const;
263 };
264
265 typedef TreeNode<ClipNodeData> ClipNode;
266
267 struct CC_EXPORT EffectNodeData {
268 EffectNodeData();
269 EffectNodeData(const EffectNodeData& other);
270
271 float opacity;
272 float screen_space_opacity;
273
274 FilterOperations background_filters;
275
276 bool has_render_surface;
277 RenderSurfaceImpl* render_surface;
278 bool has_copy_request;
279 bool hidden_by_backface_visibility;
280 bool double_sided;
281 bool is_drawn;
282 // TODO(jaydasika) : Delete this after implementation of
283 // SetHideLayerAndSubtree is cleaned up. (crbug.com/595843)
284 bool subtree_hidden;
285 bool has_potential_opacity_animation;
286 bool is_currently_animating_opacity;
287 // We need to track changes to effects on the compositor to compute damage
288 // rect.
289 bool effect_changed;
290 int num_copy_requests_in_subtree;
291 bool has_unclipped_descendants;
292 int transform_id;
293 int clip_id;
294 // Effect node id of which this effect contributes to.
295 int target_id;
296 int mask_layer_id;
297 int replica_layer_id;
298 int replica_mask_layer_id;
299
300 bool operator==(const EffectNodeData& other) const;
301
302 void ToProtobuf(proto::TreeNode* proto) const;
303 void FromProtobuf(const proto::TreeNode& proto);
304 void AsValueInto(base::trace_event::TracedValue* value) const;
305 };
306
307 typedef TreeNode<EffectNodeData> EffectNode;
308
309 struct CC_EXPORT ScrollNodeData {
310 ScrollNodeData();
311 ScrollNodeData(const ScrollNodeData& other);
312
313 bool scrollable;
314 uint32_t main_thread_scrolling_reasons;
315 bool contains_non_fast_scrollable_region;
316 gfx::Size scroll_clip_layer_bounds;
317 gfx::Size bounds;
318 bool max_scroll_offset_affected_by_page_scale;
319 bool is_inner_viewport_scroll_layer;
320 bool is_outer_viewport_scroll_layer;
321 gfx::Vector2dF offset_to_transform_parent;
322 bool should_flatten;
323 bool user_scrollable_horizontal;
324 bool user_scrollable_vertical;
325 ElementId element_id;
326 int transform_id;
327 // Number of drawn layers pointing to this node or any of its descendants.
328 int num_drawn_descendants;
329
330 bool operator==(const ScrollNodeData& other) const;
331
332 void ToProtobuf(proto::TreeNode* proto) const;
333 void FromProtobuf(const proto::TreeNode& proto);
334 void AsValueInto(base::trace_event::TracedValue* value) const;
335 };
336
337 typedef TreeNode<ScrollNodeData> ScrollNode;
338
339 class PropertyTrees; 55 class PropertyTrees;
340 56
341 template <typename T> 57 template <typename T>
342 class CC_EXPORT PropertyTree { 58 class CC_EXPORT PropertyTree {
343 public: 59 public:
344 PropertyTree(); 60 PropertyTree();
345 PropertyTree(const PropertyTree& other) = delete; 61 PropertyTree(const PropertyTree& other) = delete;
346 ~PropertyTree(); 62 ~PropertyTree();
347 63
348 bool operator==(const PropertyTree<T>& other) const; 64 bool operator==(const PropertyTree<T>& other) const;
(...skipping 490 matching lines...) Expand 10 before | Expand all | Expand 10 after
839 gfx::Vector2dF inner_viewport_container_bounds_delta_; 555 gfx::Vector2dF inner_viewport_container_bounds_delta_;
840 gfx::Vector2dF outer_viewport_container_bounds_delta_; 556 gfx::Vector2dF outer_viewport_container_bounds_delta_;
841 gfx::Vector2dF inner_viewport_scroll_bounds_delta_; 557 gfx::Vector2dF inner_viewport_scroll_bounds_delta_;
842 558
843 PropertyTreesCachedData cached_data_; 559 PropertyTreesCachedData cached_data_;
844 }; 560 };
845 561
846 } // namespace cc 562 } // namespace cc
847 563
848 #endif // CC_TREES_PROPERTY_TREE_H_ 564 #endif // CC_TREES_PROPERTY_TREE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698