Use md5_check in proguard.py to detect when it's not really necessary
[chromium-blink-merge.git] / cc / trees / property_tree.h
blob04e5aef0931af69e568f4b74c4a20e030db53ca3
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.
5 #ifndef CC_TREES_PROPERTY_TREE_H_
6 #define CC_TREES_PROPERTY_TREE_H_
8 #include <vector>
10 #include "base/basictypes.h"
11 #include "cc/base/cc_export.h"
12 #include "ui/gfx/geometry/rect.h"
13 #include "ui/gfx/geometry/scroll_offset.h"
14 #include "ui/gfx/transform.h"
16 namespace cc {
18 template <typename T>
19 struct CC_EXPORT TreeNode {
20 TreeNode() : id(-1), parent_id(-1), owner_id(-1), data() {}
21 int id;
22 int parent_id;
23 int owner_id;
24 T data;
27 struct CC_EXPORT TransformNodeData {
28 TransformNodeData();
29 ~TransformNodeData();
31 // The local transform information is combined to form to_parent (ignoring
32 // snapping) as follows:
34 // to_parent = M_post_local * T_scroll * M_local * M_pre_local.
36 // The pre/post may seem odd when read LTR, but we multiply our points from
37 // the right, so the pre_local matrix affects the result "first". This lines
38 // up with the notions of pre/post used in skia and gfx::Transform.
40 // TODO(vollick): The values labeled with "will be moved..." take up a lot of
41 // space, but are only necessary for animated or scrolled nodes (otherwise
42 // we'll just use the baked to_parent). These values will be ultimately stored
43 // directly on the transform/scroll display list items when that's possible,
44 // or potentially in a scroll tree.
46 // TODO(vollick): will be moved when accelerated effects are implemented.
47 gfx::Transform pre_local;
48 gfx::Transform local;
49 gfx::Transform post_local;
51 gfx::Transform to_parent;
53 gfx::Transform to_target;
54 gfx::Transform from_target;
56 gfx::Transform to_screen;
57 gfx::Transform from_screen;
59 int target_id;
60 // This id is used for all content that draws into a render surface associated
61 // with this transform node.
62 int content_target_id;
64 // This is the node with respect to which source_offset is defined. This will
65 // not be needed once layerization moves to cc, but is needed in order to
66 // efficiently update the transform tree for changes to position in the layer
67 // tree.
68 int source_node_id;
70 // TODO(vollick): will be moved when accelerated effects are implemented.
71 bool needs_local_transform_update : 1;
73 bool is_invertible : 1;
74 bool ancestors_are_invertible : 1;
76 bool is_animated : 1;
77 bool to_screen_is_animated : 1;
78 bool has_only_translation_animations : 1;
79 bool to_screen_has_scale_animation : 1;
81 // Flattening, when needed, is only applied to a node's inherited transform,
82 // never to its local transform.
83 bool flattens_inherited_transform : 1;
85 // This is true if the to_parent transform at every node on the path to the
86 // root is flat.
87 bool node_and_ancestors_are_flat : 1;
89 // This is needed to know if a layer can use lcd text.
90 bool node_and_ancestors_have_only_integer_translation : 1;
92 bool scrolls : 1;
94 bool needs_sublayer_scale : 1;
96 // These are used to position nodes wrt the right or bottom of the inner or
97 // outer viewport.
98 bool affected_by_inner_viewport_bounds_delta_x : 1;
99 bool affected_by_inner_viewport_bounds_delta_y : 1;
100 bool affected_by_outer_viewport_bounds_delta_x : 1;
101 bool affected_by_outer_viewport_bounds_delta_y : 1;
103 // This is used as a fallback when we either cannot adjust raster scale or if
104 // the raster scale cannot be extracted from the screen space transform.
105 float layer_scale_factor;
107 // TODO(vollick): will be moved when accelerated effects are implemented.
108 float post_local_scale_factor;
110 // The maximum scale that that node's |local| transform will have during
111 // current animations, considering only scales at keyframes not including the
112 // starting keyframe of each animation.
113 float local_maximum_animation_target_scale;
115 // The maximum scale that this node's |local| transform will have during
116 // current animatons, considering only the starting scale of each animation.
117 float local_starting_animation_scale;
119 // The maximum scale that this node's |to_target| transform will have during
120 // current animations, considering only scales at keyframes not incuding the
121 // starting keyframe of each animation.
122 float combined_maximum_animation_target_scale;
124 // The maximum scale that this node's |to_target| transform will have during
125 // current animations, considering only the starting scale of each animation.
126 float combined_starting_animation_scale;
128 gfx::Vector2dF sublayer_scale;
130 // TODO(vollick): will be moved when accelerated effects are implemented.
131 gfx::ScrollOffset scroll_offset;
133 // We scroll snap where possible, but this has an effect on scroll
134 // compensation: the snap is yet more scrolling that must be compensated for.
135 // This value stores the snapped amount for this purpose.
136 gfx::Vector2dF scroll_snap;
138 // TODO(vollick): will be moved when accelerated effects are implemented.
139 gfx::Vector2dF source_offset;
140 gfx::Vector2dF source_to_parent;
142 void set_to_parent(const gfx::Transform& transform) {
143 to_parent = transform;
144 is_invertible = to_parent.IsInvertible();
147 void update_pre_local_transform(const gfx::Point3F& transform_origin);
149 void update_post_local_transform(const gfx::PointF& position,
150 const gfx::Point3F& transform_origin);
153 typedef TreeNode<TransformNodeData> TransformNode;
155 struct CC_EXPORT ClipNodeData {
156 ClipNodeData();
158 gfx::RectF clip;
159 gfx::RectF combined_clip;
160 gfx::RectF clip_in_target_space;
161 int transform_id;
162 int target_id;
163 // This value is true for clip nodes created by layers that do not apply any
164 // clip themselves, but own a render surface that inherits the parent
165 // target space clip.
166 bool inherit_parent_target_space_clip;
167 bool requires_tight_clip_rect;
168 bool render_surface_is_clipped;
171 typedef TreeNode<ClipNodeData> ClipNode;
173 struct CC_EXPORT EffectNodeData {
174 EffectNodeData();
176 float opacity;
177 float screen_space_opacity;
180 typedef TreeNode<EffectNodeData> EffectNode;
182 template <typename T>
183 class CC_EXPORT PropertyTree {
184 public:
185 PropertyTree();
186 virtual ~PropertyTree();
188 int Insert(const T& tree_node, int parent_id);
190 T* Node(int i) {
191 // TODO(vollick): remove this.
192 CHECK(i < static_cast<int>(nodes_.size()));
193 return i > -1 ? &nodes_[i] : nullptr;
195 const T* Node(int i) const {
196 // TODO(vollick): remove this.
197 CHECK(i < static_cast<int>(nodes_.size()));
198 return i > -1 ? &nodes_[i] : nullptr;
201 T* parent(const T* t) { return Node(t->parent_id); }
202 const T* parent(const T* t) const { return Node(t->parent_id); }
204 T* back() { return size() ? &nodes_[nodes_.size() - 1] : nullptr; }
205 const T* back() const {
206 return size() ? &nodes_[nodes_.size() - 1] : nullptr;
209 virtual void clear();
210 size_t size() const { return nodes_.size(); }
212 void set_needs_update(bool needs_update) { needs_update_ = needs_update; }
213 bool needs_update() const { return needs_update_; }
215 private:
216 // Copy and assign are permitted. This is how we do tree sync.
217 std::vector<T> nodes_;
219 bool needs_update_;
222 class CC_EXPORT TransformTree final : public PropertyTree<TransformNode> {
223 public:
224 TransformTree();
225 ~TransformTree() override;
227 void clear() override;
229 // Computes the change of basis transform from node |source_id| to |dest_id|.
230 // The function returns false iff the inverse of a singular transform was
231 // used (and the result should, therefore, not be trusted). Transforms may
232 // be computed between any pair of nodes that have an ancestor/descendant
233 // relationship. Transforms between other pairs of nodes may only be computed
234 // if the following condition holds: let id1 the larger id and let id2 be the
235 // other id; then the nearest ancestor of node id1 whose id is smaller than
236 // id2 is the lowest common ancestor of the pair of nodes, and the transform
237 // from this lowest common ancestor to node id2 is only a 2d translation.
238 bool ComputeTransform(int source_id,
239 int dest_id,
240 gfx::Transform* transform) const;
242 // Computes the change of basis transform from node |source_id| to |dest_id|,
243 // including any sublayer scale at |dest_id|. The function returns false iff
244 // the inverse of a singular transform was used (and the result should,
245 // therefore, not be trusted).
246 bool ComputeTransformWithDestinationSublayerScale(
247 int source_id,
248 int dest_id,
249 gfx::Transform* transform) const;
251 // Computes the change of basis transform from node |source_id| to |dest_id|,
252 // including any sublayer scale at |source_id|. The function returns false
253 // iff the inverse of a singular transform was used (and the result should,
254 // therefore, not be trusted).
255 bool ComputeTransformWithSourceSublayerScale(int source_id,
256 int dest_id,
257 gfx::Transform* transform) const;
259 // Returns true iff the nodes indexed by |source_id| and |dest_id| are 2D axis
260 // aligned with respect to one another.
261 bool Are2DAxisAligned(int source_id, int dest_id) const;
263 // Updates the parent, target, and screen space transforms and snapping.
264 void UpdateTransforms(int id);
266 // A TransformNode's source_to_parent value is used to account for the fact
267 // that fixed-position layers are positioned by Blink wrt to their layer tree
268 // parent (their "source"), but are parented in the transform tree by their
269 // fixed-position container. This value needs to be updated on main-thread
270 // property trees (for position changes initiated by Blink), but not on the
271 // compositor thread (since the offset from a node corresponding to a
272 // fixed-position layer to its fixed-position container is unaffected by
273 // compositor-driven effects).
274 void set_source_to_parent_updates_allowed(bool allowed) {
275 source_to_parent_updates_allowed_ = allowed;
277 bool source_to_parent_updates_allowed() const {
278 return source_to_parent_updates_allowed_;
281 void SetInnerViewportBoundsDelta(gfx::Vector2dF bounds_delta);
282 gfx::Vector2dF inner_viewport_bounds_delta() const {
283 return inner_viewport_bounds_delta_;
286 void SetOuterViewportBoundsDelta(gfx::Vector2dF bounds_delta);
287 gfx::Vector2dF outer_viewport_bounds_delta() const {
288 return outer_viewport_bounds_delta_;
291 void AddNodeAffectedByInnerViewportBoundsDelta(int node_id);
292 void AddNodeAffectedByOuterViewportBoundsDelta(int node_id);
294 bool HasNodesAffectedByInnerViewportBoundsDelta() const;
295 bool HasNodesAffectedByOuterViewportBoundsDelta() const;
297 private:
298 // Returns true iff the node at |desc_id| is a descendant of the node at
299 // |anc_id|.
300 bool IsDescendant(int desc_id, int anc_id) const;
302 // Computes the combined transform between |source_id| and |dest_id| and
303 // returns false if the inverse of a singular transform was used. These two
304 // nodes must be on the same ancestor chain.
305 bool CombineTransformsBetween(int source_id,
306 int dest_id,
307 gfx::Transform* transform) const;
309 // Computes the combined inverse transform between |source_id| and |dest_id|
310 // and returns false if the inverse of a singular transform was used. These
311 // two nodes must be on the same ancestor chain.
312 bool CombineInversesBetween(int source_id,
313 int dest_id,
314 gfx::Transform* transform) const;
316 void UpdateLocalTransform(TransformNode* node);
317 void UpdateScreenSpaceTransform(TransformNode* node,
318 TransformNode* parent_node,
319 TransformNode* target_node);
320 void UpdateSublayerScale(TransformNode* node);
321 void UpdateTargetSpaceTransform(TransformNode* node,
322 TransformNode* target_node);
323 void UpdateAnimationProperties(TransformNode* node,
324 TransformNode* parent_node);
325 void UpdateSnapping(TransformNode* node);
326 void UpdateNodeAndAncestorsHaveIntegerTranslations(
327 TransformNode* node,
328 TransformNode* parent_node);
329 bool NeedsSourceToParentUpdate(TransformNode* node);
331 bool source_to_parent_updates_allowed_;
332 gfx::Vector2dF inner_viewport_bounds_delta_;
333 gfx::Vector2dF outer_viewport_bounds_delta_;
334 std::vector<int> nodes_affected_by_inner_viewport_bounds_delta_;
335 std::vector<int> nodes_affected_by_outer_viewport_bounds_delta_;
338 class CC_EXPORT ClipTree final : public PropertyTree<ClipNode> {
339 public:
340 void SetViewportClip(gfx::RectF viewport_rect);
341 gfx::RectF ViewportClip();
344 class CC_EXPORT EffectTree final : public PropertyTree<EffectNode> {
345 public:
346 void UpdateOpacities(int id);
349 class CC_EXPORT PropertyTrees final {
350 public:
351 PropertyTrees();
353 TransformTree transform_tree;
354 EffectTree effect_tree;
355 ClipTree clip_tree;
356 bool needs_rebuild;
357 int sequence_number;
360 } // namespace cc
362 #endif // CC_TREES_PROPERTY_TREE_H_