OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef CC_TREES_PROPERTY_TREE_H_ | |
6 #define CC_TREES_PROPERTY_TREE_H_ | |
7 | |
8 #include <vector> | |
9 | |
10 #include "base/basictypes.h" | |
11 #include "cc/base/cc_export.h" | |
12 #include "ui/gfx/geometry/rect.h" | |
13 #include "ui/gfx/transform.h" | |
14 | |
15 namespace cc { | |
16 | |
17 template <typename T> | |
18 struct CC_EXPORT TreeNode { | |
19 TreeNode() : id(-1), parent_id(-1), data() {} | |
20 int id; | |
21 int parent_id; | |
22 T data; | |
23 }; | |
24 | |
25 struct CC_EXPORT TransformNodeData { | |
26 TransformNodeData(); | |
27 ~TransformNodeData(); | |
28 | |
29 // The local transform information is combined to form to_parent (ignoring | |
30 // snapping) as follows: | |
31 // | |
32 // to_parent = M_post_local * T_scroll * M_local * M_pre_local. | |
33 // | |
34 // The pre/post may seem odd when read LTR, but we multiply our points from | |
35 // the right, so the pre_local matrix affects the result "first". This lines | |
36 // up with the notions of pre/post used in skia and gfx::Transform. | |
37 // | |
38 // TODO(vollick): The values labeled with "will be moved..." take up a lot of | |
39 // space, but are only necessary for animated or scrolled nodes (otherwise | |
40 // we'll just use the baked to_parent). These values will be ultimately stored | |
41 // directly on the transform/scroll display list items when that's possible, | |
42 // or potentially in a scroll tree. | |
43 // | |
44 // TODO(vollick): will be moved when accelerated effects are implemented. | |
45 gfx::Transform pre_local; | |
46 gfx::Transform local; | |
47 gfx::Transform post_local; | |
48 | |
49 gfx::Transform to_parent; | |
50 | |
51 gfx::Transform to_target; | |
52 gfx::Transform from_target; | |
53 | |
54 gfx::Transform to_screen; | |
55 gfx::Transform from_screen; | |
56 | |
57 int target_id; | |
58 // This id is used for all content that draws into a render surface associated | |
59 // with this transform node. | |
60 int content_target_id; | |
61 | |
62 // TODO(vollick): will be moved when accelerated effects are implemented. | |
63 bool needs_local_transform_update; | |
64 | |
65 bool is_invertible; | |
66 bool ancestors_are_invertible; | |
67 | |
68 bool is_animated; | |
69 bool to_screen_is_animated; | |
70 | |
71 // Flattening, when needed, is only applied to a node's inherited transform, | |
72 // never to its local transform. | |
73 bool flattens_inherited_transform; | |
74 | |
75 // This is true if the to_parent transform at every node on the path to the | |
76 // root is flat. | |
77 bool node_and_ancestors_are_flat; | |
78 | |
79 bool scrolls; | |
80 | |
81 bool needs_sublayer_scale; | |
82 // This is used as a fallback when we either cannot adjust raster scale or if | |
83 // the raster scale cannot be extracted from the screen space transform. | |
84 float layer_scale_factor; | |
85 gfx::Vector2dF sublayer_scale; | |
86 | |
87 // TODO(vollick): will be moved when accelerated effects are implemented. | |
88 gfx::Vector2dF scroll_offset; | |
89 | |
90 void set_to_parent(const gfx::Transform& transform) { | |
91 to_parent = transform; | |
92 is_invertible = to_parent.IsInvertible(); | |
93 } | |
94 }; | |
95 | |
96 typedef TreeNode<TransformNodeData> TransformNode; | |
97 | |
98 struct CC_EXPORT ClipNodeData { | |
99 ClipNodeData(); | |
100 | |
101 gfx::RectF clip; | |
102 gfx::RectF combined_clip; | |
103 int transform_id; | |
104 int target_id; | |
105 }; | |
106 | |
107 typedef TreeNode<ClipNodeData> ClipNode; | |
108 | |
109 typedef TreeNode<float> OpacityNode; | |
110 | |
111 template <typename T> | |
112 class CC_EXPORT PropertyTree { | |
113 public: | |
114 PropertyTree(); | |
115 virtual ~PropertyTree(); | |
116 | |
117 int Insert(const T& tree_node, int parent_id); | |
118 | |
119 T* Node(int i) { return i > -1 ? &nodes_[i] : nullptr; } | |
120 const T* Node(int i) const { return i > -1 ? &nodes_[i] : nullptr; } | |
121 | |
122 T* parent(const T* t) { | |
123 return t->parent_id > -1 ? Node(t->parent_id) : nullptr; | |
124 } | |
125 const T* parent(const T* t) const { | |
126 return t->parent_id > -1 ? Node(t->parent_id) : nullptr; | |
127 } | |
128 | |
129 T* back() { return size() ? &nodes_[nodes_.size() - 1] : nullptr; } | |
130 const T* back() const { | |
131 return size() ? &nodes_[nodes_.size() - 1] : nullptr; | |
132 } | |
133 | |
134 void clear() { nodes_.clear(); } | |
135 size_t size() const { return nodes_.size(); } | |
136 | |
137 private: | |
138 // Copy and assign are permitted. This is how we do tree sync. | |
139 std::vector<T> nodes_; | |
140 }; | |
141 | |
142 class CC_EXPORT TransformTree final : public PropertyTree<TransformNode> { | |
143 public: | |
144 // Computes the change of basis transform from node |source_id| to |dest_id|. | |
145 // The function returns false iff the inverse of a singular transform was | |
146 // used (and the result should, therefore, not be trusted). | |
147 bool ComputeTransform(int source_id, | |
148 int dest_id, | |
149 gfx::Transform* transform) const; | |
150 | |
151 // Returns true iff the nodes indexed by |source_id| and |dest_id| are 2D axis | |
152 // aligned with respect to one another. | |
153 bool Are2DAxisAligned(int source_id, int dest_id) const; | |
154 | |
155 // Updates the parent, target, and screen space transforms and snapping. | |
156 void UpdateTransforms(int id); | |
157 | |
158 private: | |
159 // Returns true iff the node at |desc_id| is a descendant of the node at | |
160 // |anc_id|. | |
161 bool IsDescendant(int desc_id, int anc_id) const; | |
162 | |
163 // Returns the index of the lowest common ancestor of the nodes |a| and |b|. | |
164 int LowestCommonAncestor(int a, int b) const; | |
165 | |
166 // Computes the combined transform between |source_id| and |dest_id| and | |
167 // returns false if the inverse of a singular transform was used. These two | |
168 // nodes must be on the same ancestor chain. | |
169 bool CombineTransformsBetween(int source_id, | |
170 int dest_id, | |
171 gfx::Transform* transform) const; | |
172 | |
173 // Computes the combined inverse transform between |source_id| and |dest_id| | |
174 // and returns false if the inverse of a singular transform was used. These | |
175 // two nodes must be on the same ancestor chain. | |
176 bool CombineInversesBetween(int source_id, | |
177 int dest_id, | |
178 gfx::Transform* transform) const; | |
179 | |
180 void UpdateLocalTransform(TransformNode* node); | |
181 void UpdateScreenSpaceTransform(TransformNode* node, | |
182 TransformNode* parent_node, | |
183 TransformNode* target_node); | |
184 void UpdateSublayerScale(TransformNode* node); | |
185 void UpdateTargetSpaceTransform(TransformNode* node, | |
186 TransformNode* target_node); | |
187 void UpdateIsAnimated(TransformNode* node, TransformNode* parent_node); | |
188 void UpdateSnapping(TransformNode* node); | |
189 }; | |
190 | |
191 class CC_EXPORT ClipTree final : public PropertyTree<ClipNode> {}; | |
192 | |
193 class CC_EXPORT OpacityTree final : public PropertyTree<OpacityNode> {}; | |
194 | |
195 } // namespace cc | |
196 | |
197 #endif // CC_TREES_PROPERTY_TREE_H_ | |
OLD | NEW |