blob: 401af01e6174b98e2671d79e386fd297b34281fa [file] [log] [blame]
trchendba8b1502016-07-08 09:47:011// Copyright 2016 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_TRANSFORM_NODE_H_
6#define CC_TREES_TRANSFORM_NODE_H_
7
chrishtrac41ff92017-03-17 05:07:308#include "cc/cc_export.h"
Xida Chenaf5964b32019-07-18 19:44:229#include "cc/paint/element_id.h"
Xianzhu Wang6e8ae992019-08-20 17:44:1410#include "ui/gfx/geometry/point3_f.h"
trchendba8b1502016-07-08 09:47:0111#include "ui/gfx/geometry/point_f.h"
12#include "ui/gfx/geometry/scroll_offset.h"
13#include "ui/gfx/transform.h"
14
15namespace base {
16namespace trace_event {
17class TracedValue;
18} // namespace trace_event
19} // namespace base
20
21namespace cc {
22
trchendba8b1502016-07-08 09:47:0123struct CC_EXPORT TransformNode {
24 TransformNode();
25 TransformNode(const TransformNode&);
26
wkormana4c2d8682017-01-05 01:16:3727 // The node index of this node in the transform tree node vector.
Thiemo Nagel326859c2017-10-06 11:50:5928 int id;
wkormana4c2d8682017-01-05 01:16:3729 // The node index of the parent node in the transform tree node vector.
Thiemo Nagel326859c2017-10-06 11:50:5930 int parent_id;
Chris Harrelson7f8e23952017-06-16 23:15:1931
32 ElementId element_id;
trchendba8b1502016-07-08 09:47:0133
Thiemo Nagel326859c2017-10-06 11:50:5934 // The local transform information is combined to form to_parent (ignoring
35 // snapping) as follows:
Xianzhu Wang6e8ae992019-08-20 17:44:1436 // to_parent =
37 // T_post_translation * T_origin * T_scroll * M_local * -T_origin.
trchendba8b1502016-07-08 09:47:0138 gfx::Transform local;
Xianzhu Wang6e8ae992019-08-20 17:44:1439 gfx::Point3F origin;
Xianzhu Wangc9109552019-08-28 03:57:0140 // For layer tree mode only. In layer list mode, when the translation is
41 // needed, blink creates paint offset translation node above this node.
Xianzhu Wang6e8ae992019-08-20 17:44:1442 gfx::Vector2dF post_translation;
trchendba8b1502016-07-08 09:47:0143
Thiemo Nagel326859c2017-10-06 11:50:5944 gfx::Transform to_parent;
45
46 // This is the node which defines the sticky position constraints for this
47 // transform node. -1 indicates there are no sticky position constraints.
48 int sticky_position_constraint_id;
flackr2215b4e2016-09-21 20:16:0149
trchendba8b1502016-07-08 09:47:0150 // This id determines which 3d rendering context the node is in. 0 is a
51 // special value and indicates that the node is not in any 3d rendering
52 // context.
Thiemo Nagel326859c2017-10-06 11:50:5953 int sorting_context_id;
trchendba8b1502016-07-08 09:47:0154
Philip Rogers038bf1d2019-06-07 21:37:4555 // True if |TransformTree::UpdateLocalTransform| needs to be called which
Xianzhu Wangc9109552019-08-28 03:57:0156 // will update |to_parent|.
trchendba8b1502016-07-08 09:47:0157 bool needs_local_transform_update : 1;
58
wkormana6fc2f22017-05-17 03:28:0559 // Whether this node or any ancestor has a potentially running
60 // (i.e., irrespective of exact timeline) transform animation or an
61 // invertible transform.
trchendba8b1502016-07-08 09:47:0162 bool node_and_ancestors_are_animated_or_invertible : 1;
63
64 bool is_invertible : 1;
wkormana6fc2f22017-05-17 03:28:0565 // Whether the transform from this node to the screen is
66 // invertible.
trchendba8b1502016-07-08 09:47:0167 bool ancestors_are_invertible : 1;
68
wkormana6fc2f22017-05-17 03:28:0569 // Whether this node has a potentially running (i.e., irrespective
70 // of exact timeline) transform animation.
trchendba8b1502016-07-08 09:47:0171 bool has_potential_animation : 1;
wkormana6fc2f22017-05-17 03:28:0572 // Whether this node has a currently running transform animation.
trchendba8b1502016-07-08 09:47:0173 bool is_currently_animating : 1;
wkormana6fc2f22017-05-17 03:28:0574 // Whether this node *or an ancestor* has a potentially running
75 // (i.e., irrespective of exact timeline) transform
76 // animation.
trchendba8b1502016-07-08 09:47:0177 bool to_screen_is_potentially_animated : 1;
trchendba8b1502016-07-08 09:47:0178
Thiemo Nagel326859c2017-10-06 11:50:5979 // Flattening, when needed, is only applied to a node's inherited transform,
Xianzhu Wangd3250522019-08-26 18:48:2480 // never to its local transform. It's true by default.
Thiemo Nagel326859c2017-10-06 11:50:5981 bool flattens_inherited_transform : 1;
82
trchendba8b1502016-07-08 09:47:0183 // 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;
86
87 // This is needed to know if a layer can use lcd text.
88 bool node_and_ancestors_have_only_integer_translation : 1;
89
Thiemo Nagel326859c2017-10-06 11:50:5990 bool scrolls : 1;
91
92 bool should_be_snapped : 1;
93
Xianzhu Wang41319ab42019-08-28 01:06:3694 // Used by the compositor to determine which layers need to be repositioned by
95 // the compositor as a result of browser controls expanding/contracting the
96 // outer viewport size before Blink repositions the fixed layers.
Thiemo Nagel326859c2017-10-06 11:50:5997 bool moved_by_outer_viewport_bounds_delta_y : 1;
98
99 // Layer scale factor is used as a fallback when we either cannot adjust
100 // raster scale or if the raster scale cannot be extracted from the screen
101 // space transform. For layers in the subtree of the page scale layer, the
102 // layer scale factor should include the page scale factor.
103 bool in_subtree_of_page_scale_layer : 1;
104
trchendba8b1502016-07-08 09:47:01105 // We need to track changes to to_screen transform to compute the damage rect.
106 bool transform_changed : 1;
107
Thiemo Nagel326859c2017-10-06 11:50:59108 gfx::ScrollOffset scroll_offset;
109
jaydasika2a1718b2016-10-26 22:58:02110 // This value stores the snapped amount whenever we snap. If the snap is due
111 // to a scroll, we need it to calculate fixed-pos elements adjustment, even
112 // otherwise we may need it to undo the snapping next frame.
113 gfx::Vector2dF snap_amount;
Thiemo Nagel326859c2017-10-06 11:50:59114
Xianzhu Wang51647042019-04-26 22:50:16115 // See MutatorHost::GetAnimationScales() for their meanings. Updated by
116 // PropertyTrees::AnimationScalesChanged().
Xianzhu Wang89ec9082019-04-03 22:32:39117 float maximum_animation_scale;
118 float starting_animation_scale;
119
trchendba8b1502016-07-08 09:47:01120 bool operator==(const TransformNode& other) const;
121
Thiemo Nagel326859c2017-10-06 11:50:59122 void set_to_parent(const gfx::Transform& transform) {
123 to_parent = transform;
124 is_invertible = to_parent.IsInvertible();
125 }
126
trchendba8b1502016-07-08 09:47:01127 void AsValueInto(base::trace_event::TracedValue* value) const;
128};
129
130// TODO(sunxd): move this into PropertyTrees::cached_data_.
131struct CC_EXPORT TransformCachedNodeData {
132 TransformCachedNodeData();
133 TransformCachedNodeData(const TransformCachedNodeData& other);
134 ~TransformCachedNodeData();
135
trchendba8b1502016-07-08 09:47:01136 gfx::Transform from_screen;
137 gfx::Transform to_screen;
trchendba8b1502016-07-08 09:47:01138
trchen75204782016-11-03 01:05:42139 bool is_showing_backface : 1;
140
trchendba8b1502016-07-08 09:47:01141 bool operator==(const TransformCachedNodeData& other) const;
trchendba8b1502016-07-08 09:47:01142};
143
144} // namespace cc
145
146#endif // CC_TREES_TRANSFORM_NODE_H_