Fix up a few more lint warnings.
[chromium-blink-merge.git] / cc / trees / property_tree.h
blob404f498d4e3ca9ef4a0daeed0b2ca4101a756305
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/transform.h"
15 namespace cc {
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;
25 struct CC_EXPORT TransformNodeData {
26 TransformNodeData();
27 ~TransformNodeData();
29 // The local transform information is combined to form to_parent (ignoring
30 // snapping) as follows:
32 // to_parent = M_post_local * T_scroll * M_local * M_pre_local.
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.
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.
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;
49 gfx::Transform to_parent;
50 gfx::Transform from_parent;
52 gfx::Transform to_target;
53 gfx::Transform from_target;
55 gfx::Transform to_screen;
56 gfx::Transform from_screen;
58 int target_id;
59 // This id is used for all content that draws into a render surface associated
60 // with this transform node.
61 int content_target_id;
63 // TODO(vollick): will be moved when accelerated effects are implemented.
64 bool needs_local_transform_update;
66 bool is_invertible;
67 bool ancestors_are_invertible;
69 bool is_animated;
70 bool to_screen_is_animated;
72 bool flattens;
73 bool scrolls;
75 bool needs_sublayer_scale;
76 // This is used as a fallback when we either cannot adjust raster scale or if
77 // the raster scale cannot be extracted from the screen space transform.
78 float layer_scale_factor;
79 gfx::Vector2dF sublayer_scale;
81 // TODO(vollick): will be moved when accelerated effects are implemented.
82 gfx::Vector2dF scroll_offset;
84 void set_to_parent(const gfx::Transform& transform) {
85 to_parent = transform;
86 is_invertible = to_parent.GetInverse(&from_parent);
90 typedef TreeNode<TransformNodeData> TransformNode;
92 struct CC_EXPORT ClipNodeData {
93 ClipNodeData();
95 gfx::RectF clip;
96 gfx::RectF combined_clip;
97 int transform_id;
98 int target_id;
101 typedef TreeNode<ClipNodeData> ClipNode;
103 typedef TreeNode<float> OpacityNode;
105 template <typename T>
106 class CC_EXPORT PropertyTree {
107 public:
108 PropertyTree();
109 virtual ~PropertyTree();
111 int Insert(const T& tree_node, int parent_id);
113 T* Node(int i) { return i > -1 ? &nodes_[i] : nullptr; }
114 const T* Node(int i) const { return i > -1 ? &nodes_[i] : nullptr; }
116 T* parent(const T* t) {
117 return t->parent_id > -1 ? Node(t->parent_id) : nullptr;
119 const T* parent(const T* t) const {
120 return t->parent_id > -1 ? Node(t->parent_id) : nullptr;
123 T* back() { return size() ? &nodes_[nodes_.size() - 1] : nullptr; }
124 const T* back() const {
125 return size() ? &nodes_[nodes_.size() - 1] : nullptr;
128 void clear() { nodes_.clear(); }
129 size_t size() const { return nodes_.size(); }
131 private:
132 // Copy and assign are permitted. This is how we do tree sync.
133 std::vector<T> nodes_;
136 class CC_EXPORT TransformTree final : public PropertyTree<TransformNode> {
137 public:
138 // Computes the change of basis transform from node |source_id| to |dest_id|.
139 // The function returns false iff the inverse of a singular transform was
140 // used (and the result should, therefore, not be trusted).
141 bool ComputeTransform(int source_id,
142 int dest_id,
143 gfx::Transform* transform) const;
145 // Returns true iff the nodes indexed by |source_id| and |dest_id| are 2D axis
146 // aligned with respect to one another.
147 bool Are2DAxisAligned(int source_id, int dest_id) const;
149 // Updates the parent, target, and screen space transforms and snapping.
150 void UpdateTransforms(int id);
152 private:
153 // Returns true iff the node at |desc_id| is a descendant of the node at
154 // |anc_id|.
155 bool IsDescendant(int desc_id, int anc_id) const;
157 // Returns the index of the lowest common ancestor of the nodes |a| and |b|.
158 int LowestCommonAncestor(int a, int b) const;
160 // Computes the combined transform between |source_id| and |dest_id| and
161 // returns false if the inverse of a singular transform was used. These two
162 // nodes must be on the same ancestor chain.
163 bool CombineTransformsBetween(int source_id,
164 int dest_id,
165 gfx::Transform* transform) const;
167 // Computes the combined inverse transform between |source_id| and |dest_id|
168 // and returns false if the inverse of a singular transform was used. These
169 // two nodes must be on the same ancestor chain.
170 bool CombineInversesBetween(int source_id,
171 int dest_id,
172 gfx::Transform* transform) const;
174 void UpdateLocalTransform(TransformNode* node);
175 void UpdateScreenSpaceTransform(TransformNode* node,
176 TransformNode* parent_node,
177 TransformNode* target_node);
178 void UpdateSublayerScale(TransformNode* node);
179 void UpdateTargetSpaceTransform(TransformNode* node,
180 TransformNode* target_node);
181 void UpdateIsAnimated(TransformNode* node, TransformNode* parent_node);
182 void UpdateSnapping(TransformNode* node);
185 class CC_EXPORT ClipTree final : public PropertyTree<ClipNode> {};
187 class CC_EXPORT OpacityTree final : public PropertyTree<OpacityNode> {};
189 } // namespace cc
191 #endif // CC_TREES_PROPERTY_TREE_H_