Don't show supervised user as "already on this device" while they're being imported.
[chromium-blink-merge.git] / cc / trees / property_tree.h
blob83b33afd676925c29d40a7969819e254c97a9159
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;
73 bool is_invertible;
74 bool ancestors_are_invertible;
76 bool is_animated;
77 bool to_screen_is_animated;
79 // Flattening, when needed, is only applied to a node's inherited transform,
80 // never to its local transform.
81 bool flattens_inherited_transform;
83 // This is true if the to_parent transform at every node on the path to the
84 // root is flat.
85 bool node_and_ancestors_are_flat;
87 bool scrolls;
89 bool needs_sublayer_scale;
90 // This is used as a fallback when we either cannot adjust raster scale or if
91 // the raster scale cannot be extracted from the screen space transform.
92 float layer_scale_factor;
94 // TODO(vollick): will be moved when accelerated effects are implemented.
95 float post_local_scale_factor;
97 gfx::Vector2dF sublayer_scale;
99 // TODO(vollick): will be moved when accelerated effects are implemented.
100 gfx::ScrollOffset scroll_offset;
102 // We scroll snap where possible, but this has an effect on scroll
103 // compensation: the snap is yet more scrolling that must be compensated for.
104 // This value stores the snapped amount for this purpose.
105 gfx::Vector2dF scroll_snap;
107 // TODO(vollick): will be moved when accelerated effects are implemented.
108 gfx::Vector2dF source_offset;
110 void set_to_parent(const gfx::Transform& transform) {
111 to_parent = transform;
112 is_invertible = to_parent.IsInvertible();
115 void update_pre_local_transform(const gfx::Point3F& transform_origin);
117 void update_post_local_transform(const gfx::PointF& position,
118 const gfx::Point3F& transform_origin);
121 typedef TreeNode<TransformNodeData> TransformNode;
123 struct CC_EXPORT ClipNodeData {
124 ClipNodeData();
126 gfx::RectF clip;
127 gfx::RectF combined_clip;
128 int transform_id;
129 int target_id;
132 typedef TreeNode<ClipNodeData> ClipNode;
134 typedef TreeNode<float> OpacityNode;
136 template <typename T>
137 class CC_EXPORT PropertyTree {
138 public:
139 PropertyTree();
140 virtual ~PropertyTree();
142 int Insert(const T& tree_node, int parent_id);
144 T* Node(int i) {
145 // TODO(vollick): remove this.
146 CHECK(i < static_cast<int>(nodes_.size()));
147 return i > -1 ? &nodes_[i] : nullptr;
149 const T* Node(int i) const {
150 // TODO(vollick): remove this.
151 CHECK(i < static_cast<int>(nodes_.size()));
152 return i > -1 ? &nodes_[i] : nullptr;
155 T* parent(const T* t) { return Node(t->parent_id); }
156 const T* parent(const T* t) const { return Node(t->parent_id); }
158 T* back() { return size() ? &nodes_[nodes_.size() - 1] : nullptr; }
159 const T* back() const {
160 return size() ? &nodes_[nodes_.size() - 1] : nullptr;
163 void clear();
164 size_t size() const { return nodes_.size(); }
166 void set_needs_update(bool needs_update) { needs_update_ = needs_update; }
167 bool needs_update() const { return needs_update_; }
169 private:
170 // Copy and assign are permitted. This is how we do tree sync.
171 std::vector<T> nodes_;
173 bool needs_update_;
176 class CC_EXPORT TransformTree final : public PropertyTree<TransformNode> {
177 public:
178 // Computes the change of basis transform from node |source_id| to |dest_id|.
179 // The function returns false iff the inverse of a singular transform was
180 // used (and the result should, therefore, not be trusted). Transforms may
181 // be computed between any pair of nodes that have an ancestor/descendant
182 // relationship. Transforms between other pairs of nodes may only be computed
183 // if the following condition holds: let id1 the larger id and let id2 be the
184 // other id; then the nearest ancestor of node id1 whose id is smaller than
185 // id2 is the lowest common ancestor of the pair of nodes, and the transform
186 // from this lowest common ancestor to node id2 is only a 2d translation.
187 bool ComputeTransform(int source_id,
188 int dest_id,
189 gfx::Transform* transform) const;
191 // Computes the change of basis transform from node |source_id| to |dest_id|,
192 // including any sublayer scale at |dest_id|. The function returns false iff
193 // the inverse of a singular transform was used (and the result should,
194 // therefore, not be trusted).
195 bool ComputeTransformWithDestinationSublayerScale(
196 int source_id,
197 int dest_id,
198 gfx::Transform* transform) const;
200 // Computes the change of basis transform from node |source_id| to |dest_id|,
201 // including any sublayer scale at |source_id|. The function returns false
202 // iff the inverse of a singular transform was used (and the result should,
203 // therefore, not be trusted).
204 bool ComputeTransformWithSourceSublayerScale(int source_id,
205 int dest_id,
206 gfx::Transform* transform) const;
208 // Returns true iff the nodes indexed by |source_id| and |dest_id| are 2D axis
209 // aligned with respect to one another.
210 bool Are2DAxisAligned(int source_id, int dest_id) const;
212 // Updates the parent, target, and screen space transforms and snapping.
213 void UpdateTransforms(int id);
215 private:
216 // Returns true iff the node at |desc_id| is a descendant of the node at
217 // |anc_id|.
218 bool IsDescendant(int desc_id, int anc_id) const;
220 // Computes the combined transform between |source_id| and |dest_id| and
221 // returns false if the inverse of a singular transform was used. These two
222 // nodes must be on the same ancestor chain.
223 bool CombineTransformsBetween(int source_id,
224 int dest_id,
225 gfx::Transform* transform) const;
227 // Computes the combined inverse transform between |source_id| and |dest_id|
228 // and returns false if the inverse of a singular transform was used. These
229 // two nodes must be on the same ancestor chain.
230 bool CombineInversesBetween(int source_id,
231 int dest_id,
232 gfx::Transform* transform) const;
234 void UpdateLocalTransform(TransformNode* node);
235 void UpdateScreenSpaceTransform(TransformNode* node,
236 TransformNode* parent_node,
237 TransformNode* target_node);
238 void UpdateSublayerScale(TransformNode* node);
239 void UpdateTargetSpaceTransform(TransformNode* node,
240 TransformNode* target_node);
241 void UpdateIsAnimated(TransformNode* node, TransformNode* parent_node);
242 void UpdateSnapping(TransformNode* node);
245 class CC_EXPORT ClipTree final : public PropertyTree<ClipNode> {};
247 class CC_EXPORT OpacityTree final : public PropertyTree<OpacityNode> {};
249 class CC_EXPORT PropertyTrees final {
250 public:
251 PropertyTrees();
253 TransformTree transform_tree;
254 OpacityTree opacity_tree;
255 ClipTree clip_tree;
256 bool needs_rebuild;
257 int sequence_number;
260 } // namespace cc
262 #endif // CC_TREES_PROPERTY_TREE_H_