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

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: rebase 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
« no previous file with comments | « cc/trees/layer_tree_impl_unittest.cc ('k') | cc/trees/property_tree.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 gfx::Vector2dF sublayer_scale;
277
278 bool has_render_surface;
279 RenderSurfaceImpl* render_surface;
280 bool has_copy_request;
281 bool hidden_by_backface_visibility;
282 bool double_sided;
283 bool is_drawn;
284 // TODO(jaydasika) : Delete this after implementation of
285 // SetHideLayerAndSubtree is cleaned up. (crbug.com/595843)
286 bool subtree_hidden;
287 bool has_potential_opacity_animation;
288 bool is_currently_animating_opacity;
289 // We need to track changes to effects on the compositor to compute damage
290 // rect.
291 bool effect_changed;
292 int num_copy_requests_in_subtree;
293 bool has_unclipped_descendants;
294 int transform_id;
295 int clip_id;
296 // Effect node id of which this effect contributes to.
297 int target_id;
298 int mask_layer_id;
299 int replica_layer_id;
300 int replica_mask_layer_id;
301
302 bool operator==(const EffectNodeData& other) const;
303
304 void ToProtobuf(proto::TreeNode* proto) const;
305 void FromProtobuf(const proto::TreeNode& proto);
306 void AsValueInto(base::trace_event::TracedValue* value) const;
307 };
308
309 typedef TreeNode<EffectNodeData> EffectNode;
310
311 struct CC_EXPORT ScrollNodeData {
312 ScrollNodeData();
313 ScrollNodeData(const ScrollNodeData& other);
314
315 bool scrollable;
316 uint32_t main_thread_scrolling_reasons;
317 bool contains_non_fast_scrollable_region;
318 gfx::Size scroll_clip_layer_bounds;
319 gfx::Size bounds;
320 bool max_scroll_offset_affected_by_page_scale;
321 bool is_inner_viewport_scroll_layer;
322 bool is_outer_viewport_scroll_layer;
323 gfx::Vector2dF offset_to_transform_parent;
324 bool should_flatten;
325 bool user_scrollable_horizontal;
326 bool user_scrollable_vertical;
327 ElementId element_id;
328 int transform_id;
329 // Number of drawn layers pointing to this node or any of its descendants.
330 int num_drawn_descendants;
331
332 bool operator==(const ScrollNodeData& other) const;
333
334 void ToProtobuf(proto::TreeNode* proto) const;
335 void FromProtobuf(const proto::TreeNode& proto);
336 void AsValueInto(base::trace_event::TracedValue* value) const;
337 };
338
339 typedef TreeNode<ScrollNodeData> ScrollNode;
340
341 class PropertyTrees; 55 class PropertyTrees;
342 56
343 template <typename T> 57 template <typename T>
344 class CC_EXPORT PropertyTree { 58 class CC_EXPORT PropertyTree {
345 public: 59 public:
346 PropertyTree(); 60 PropertyTree();
347 PropertyTree(const PropertyTree& other) = delete; 61 PropertyTree(const PropertyTree& other) = delete;
62
63 // These C++ special member functions cannot be implicit inline because
64 // they are exported by CC_EXPORT. They will be instantiated in every
65 // compilation units that included this header, and compilation can fail
66 // because T may be incomplete.
348 ~PropertyTree(); 67 ~PropertyTree();
68 PropertyTree<T>& operator=(const PropertyTree<T>&);
349 69
350 bool operator==(const PropertyTree<T>& other) const; 70 bool operator==(const PropertyTree<T>& other) const;
351 71
352 int Insert(const T& tree_node, int parent_id); 72 int Insert(const T& tree_node, int parent_id);
353 73
354 T* Node(int i) { 74 T* Node(int i) {
355 // TODO(vollick): remove this. 75 // TODO(vollick): remove this.
356 CHECK(i < static_cast<int>(nodes_.size())); 76 CHECK(i < static_cast<int>(nodes_.size()));
357 return i > -1 ? &nodes_[i] : nullptr; 77 return i > -1 ? &nodes_[i] : nullptr;
358 } 78 }
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
395 private: 115 private:
396 std::vector<T> nodes_; 116 std::vector<T> nodes_;
397 117
398 bool needs_update_; 118 bool needs_update_;
399 PropertyTrees* property_trees_; 119 PropertyTrees* property_trees_;
400 }; 120 };
401 121
402 class CC_EXPORT TransformTree final : public PropertyTree<TransformNode> { 122 class CC_EXPORT TransformTree final : public PropertyTree<TransformNode> {
403 public: 123 public:
404 TransformTree(); 124 TransformTree();
125
126 // These C++ special member functions cannot be implicit inline because
127 // they are exported by CC_EXPORT. They will be instantiated in every
128 // compilation units that included this header, and compilation can fail
129 // because TransformCachedNodeData may be incomplete.
130 TransformTree(const TransformTree&) = delete;
405 ~TransformTree(); 131 ~TransformTree();
132 TransformTree& operator=(const TransformTree&);
406 133
407 bool operator==(const TransformTree& other) const; 134 bool operator==(const TransformTree& other) const;
408 135
409 int Insert(const TransformNode& tree_node, int parent_id); 136 int Insert(const TransformNode& tree_node, int parent_id);
410 137
411 void clear(); 138 void clear();
412 139
413 // Computes the change of basis transform from node |source_id| to |dest_id|. 140 // Computes the change of basis transform from node |source_id| to |dest_id|.
414 // The function returns false iff the inverse of a singular transform was 141 // The function returns false iff the inverse of a singular transform was
415 // used (and the result should, therefore, not be trusted). Transforms may 142 // used (and the result should, therefore, not be trusted). Transforms may
(...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after
843 gfx::Vector2dF inner_viewport_container_bounds_delta_; 570 gfx::Vector2dF inner_viewport_container_bounds_delta_;
844 gfx::Vector2dF outer_viewport_container_bounds_delta_; 571 gfx::Vector2dF outer_viewport_container_bounds_delta_;
845 gfx::Vector2dF inner_viewport_scroll_bounds_delta_; 572 gfx::Vector2dF inner_viewport_scroll_bounds_delta_;
846 573
847 PropertyTreesCachedData cached_data_; 574 PropertyTreesCachedData cached_data_;
848 }; 575 };
849 576
850 } // namespace cc 577 } // namespace cc
851 578
852 #endif // CC_TREES_PROPERTY_TREE_H_ 579 #endif // CC_TREES_PROPERTY_TREE_H_
OLDNEW
« no previous file with comments | « cc/trees/layer_tree_impl_unittest.cc ('k') | cc/trees/property_tree.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698