Add ICU message format support
[chromium-blink-merge.git] / cc / trees / property_tree.h
blobbaaca64fa85336535594eee0c4b2bd0d4cb1ebb2
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;
79 // Flattening, when needed, is only applied to a node's inherited transform,
80 // never to its local transform.
81 bool flattens_inherited_transform : 1;
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 : 1;
87 // This is needed to know if a layer can use lcd text.
88 bool node_and_ancestors_have_only_integer_translation : 1;
90 bool scrolls : 1;
92 bool needs_sublayer_scale : 1;
94 // These are used to position nodes wrt the right or bottom of the inner or
95 // outer viewport.
96 bool affected_by_inner_viewport_bounds_delta_x : 1;
97 bool affected_by_inner_viewport_bounds_delta_y : 1;
98 bool affected_by_outer_viewport_bounds_delta_x : 1;
99 bool affected_by_outer_viewport_bounds_delta_y : 1;
101 // This is used as a fallback when we either cannot adjust raster scale or if
102 // the raster scale cannot be extracted from the screen space transform.
103 float layer_scale_factor;
105 // TODO(vollick): will be moved when accelerated effects are implemented.
106 float post_local_scale_factor;
108 gfx::Vector2dF sublayer_scale;
110 // TODO(vollick): will be moved when accelerated effects are implemented.
111 gfx::ScrollOffset scroll_offset;
113 // We scroll snap where possible, but this has an effect on scroll
114 // compensation: the snap is yet more scrolling that must be compensated for.
115 // This value stores the snapped amount for this purpose.
116 gfx::Vector2dF scroll_snap;
118 // TODO(vollick): will be moved when accelerated effects are implemented.
119 gfx::Vector2dF source_offset;
120 gfx::Vector2dF source_to_parent;
122 void set_to_parent(const gfx::Transform& transform) {
123 to_parent = transform;
124 is_invertible = to_parent.IsInvertible();
127 void update_pre_local_transform(const gfx::Point3F& transform_origin);
129 void update_post_local_transform(const gfx::PointF& position,
130 const gfx::Point3F& transform_origin);
133 typedef TreeNode<TransformNodeData> TransformNode;
135 struct CC_EXPORT ClipNodeData {
136 ClipNodeData();
138 gfx::RectF clip;
139 gfx::RectF combined_clip;
140 int transform_id;
141 int target_id;
142 // This value is true for clip nodes created by layers that do not apply any
143 // clip themselves, but own a render surface that inherits the parent
144 // target space clip.
145 bool inherit_parent_target_space_clip;
148 typedef TreeNode<ClipNodeData> ClipNode;
150 struct CC_EXPORT OpacityNodeData {
151 OpacityNodeData();
153 float opacity;
154 float screen_space_opacity;
157 typedef TreeNode<OpacityNodeData> OpacityNode;
159 template <typename T>
160 class CC_EXPORT PropertyTree {
161 public:
162 PropertyTree();
163 virtual ~PropertyTree();
165 int Insert(const T& tree_node, int parent_id);
167 T* Node(int i) {
168 // TODO(vollick): remove this.
169 CHECK(i < static_cast<int>(nodes_.size()));
170 return i > -1 ? &nodes_[i] : nullptr;
172 const T* Node(int i) const {
173 // TODO(vollick): remove this.
174 CHECK(i < static_cast<int>(nodes_.size()));
175 return i > -1 ? &nodes_[i] : nullptr;
178 T* parent(const T* t) { return Node(t->parent_id); }
179 const T* parent(const T* t) const { return Node(t->parent_id); }
181 T* back() { return size() ? &nodes_[nodes_.size() - 1] : nullptr; }
182 const T* back() const {
183 return size() ? &nodes_[nodes_.size() - 1] : nullptr;
186 virtual void clear();
187 size_t size() const { return nodes_.size(); }
189 void set_needs_update(bool needs_update) { needs_update_ = needs_update; }
190 bool needs_update() const { return needs_update_; }
192 private:
193 // Copy and assign are permitted. This is how we do tree sync.
194 std::vector<T> nodes_;
196 bool needs_update_;
199 class CC_EXPORT TransformTree final : public PropertyTree<TransformNode> {
200 public:
201 TransformTree();
202 ~TransformTree() override;
204 void clear() override;
206 // Computes the change of basis transform from node |source_id| to |dest_id|.
207 // The function returns false iff the inverse of a singular transform was
208 // used (and the result should, therefore, not be trusted). Transforms may
209 // be computed between any pair of nodes that have an ancestor/descendant
210 // relationship. Transforms between other pairs of nodes may only be computed
211 // if the following condition holds: let id1 the larger id and let id2 be the
212 // other id; then the nearest ancestor of node id1 whose id is smaller than
213 // id2 is the lowest common ancestor of the pair of nodes, and the transform
214 // from this lowest common ancestor to node id2 is only a 2d translation.
215 bool ComputeTransform(int source_id,
216 int dest_id,
217 gfx::Transform* transform) const;
219 // Computes the change of basis transform from node |source_id| to |dest_id|,
220 // including any sublayer scale at |dest_id|. The function returns false iff
221 // the inverse of a singular transform was used (and the result should,
222 // therefore, not be trusted).
223 bool ComputeTransformWithDestinationSublayerScale(
224 int source_id,
225 int dest_id,
226 gfx::Transform* transform) const;
228 // Computes the change of basis transform from node |source_id| to |dest_id|,
229 // including any sublayer scale at |source_id|. The function returns false
230 // iff the inverse of a singular transform was used (and the result should,
231 // therefore, not be trusted).
232 bool ComputeTransformWithSourceSublayerScale(int source_id,
233 int dest_id,
234 gfx::Transform* transform) const;
236 // Returns true iff the nodes indexed by |source_id| and |dest_id| are 2D axis
237 // aligned with respect to one another.
238 bool Are2DAxisAligned(int source_id, int dest_id) const;
240 // Updates the parent, target, and screen space transforms and snapping.
241 void UpdateTransforms(int id);
243 // A TransformNode's source_to_parent value is used to account for the fact
244 // that fixed-position layers are positioned by Blink wrt to their layer tree
245 // parent (their "source"), but are parented in the transform tree by their
246 // fixed-position container. This value needs to be updated on main-thread
247 // property trees (for position changes initiated by Blink), but not on the
248 // compositor thread (since the offset from a node corresponding to a
249 // fixed-position layer to its fixed-position container is unaffected by
250 // compositor-driven effects).
251 void set_source_to_parent_updates_allowed(bool allowed) {
252 source_to_parent_updates_allowed_ = allowed;
254 bool source_to_parent_updates_allowed() const {
255 return source_to_parent_updates_allowed_;
258 void SetInnerViewportBoundsDelta(gfx::Vector2dF bounds_delta);
259 gfx::Vector2dF inner_viewport_bounds_delta() const {
260 return inner_viewport_bounds_delta_;
263 void SetOuterViewportBoundsDelta(gfx::Vector2dF bounds_delta);
264 gfx::Vector2dF outer_viewport_bounds_delta() const {
265 return outer_viewport_bounds_delta_;
268 void AddNodeAffectedByInnerViewportBoundsDelta(int node_id);
269 void AddNodeAffectedByOuterViewportBoundsDelta(int node_id);
271 bool HasNodesAffectedByInnerViewportBoundsDelta() const;
272 bool HasNodesAffectedByOuterViewportBoundsDelta() const;
274 private:
275 // Returns true iff the node at |desc_id| is a descendant of the node at
276 // |anc_id|.
277 bool IsDescendant(int desc_id, int anc_id) const;
279 // Computes the combined transform between |source_id| and |dest_id| and
280 // returns false if the inverse of a singular transform was used. These two
281 // nodes must be on the same ancestor chain.
282 bool CombineTransformsBetween(int source_id,
283 int dest_id,
284 gfx::Transform* transform) const;
286 // Computes the combined inverse transform between |source_id| and |dest_id|
287 // and returns false if the inverse of a singular transform was used. These
288 // two nodes must be on the same ancestor chain.
289 bool CombineInversesBetween(int source_id,
290 int dest_id,
291 gfx::Transform* transform) const;
293 void UpdateLocalTransform(TransformNode* node);
294 void UpdateScreenSpaceTransform(TransformNode* node,
295 TransformNode* parent_node,
296 TransformNode* target_node);
297 void UpdateSublayerScale(TransformNode* node);
298 void UpdateTargetSpaceTransform(TransformNode* node,
299 TransformNode* target_node);
300 void UpdateIsAnimated(TransformNode* node, TransformNode* parent_node);
301 void UpdateSnapping(TransformNode* node);
302 void UpdateNodeAndAncestorsHaveIntegerTranslations(
303 TransformNode* node,
304 TransformNode* parent_node);
305 bool NeedsSourceToParentUpdate(TransformNode* node);
307 bool source_to_parent_updates_allowed_;
308 gfx::Vector2dF inner_viewport_bounds_delta_;
309 gfx::Vector2dF outer_viewport_bounds_delta_;
310 std::vector<int> nodes_affected_by_inner_viewport_bounds_delta_;
311 std::vector<int> nodes_affected_by_outer_viewport_bounds_delta_;
314 class CC_EXPORT ClipTree final : public PropertyTree<ClipNode> {};
316 class CC_EXPORT OpacityTree final : public PropertyTree<OpacityNode> {
317 public:
318 void UpdateOpacities(int id);
321 class CC_EXPORT PropertyTrees final {
322 public:
323 PropertyTrees();
325 TransformTree transform_tree;
326 OpacityTree opacity_tree;
327 ClipTree clip_tree;
328 bool needs_rebuild;
329 int sequence_number;
332 } // namespace cc
334 #endif // CC_TREES_PROPERTY_TREE_H_