trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 1 | // 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 | |
chrishtr | ac41ff9 | 2017-03-17 05:07:30 | [diff] [blame] | 8 | #include "cc/cc_export.h" |
Xida Chen | af5964b3 | 2019-07-18 19:44:22 | [diff] [blame] | 9 | #include "cc/paint/element_id.h" |
Xianzhu Wang | 6e8ae99 | 2019-08-20 17:44:14 | [diff] [blame] | 10 | #include "ui/gfx/geometry/point3_f.h" |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 11 | #include "ui/gfx/geometry/point_f.h" |
| 12 | #include "ui/gfx/geometry/scroll_offset.h" |
| 13 | #include "ui/gfx/transform.h" |
| 14 | |
| 15 | namespace base { |
| 16 | namespace trace_event { |
| 17 | class TracedValue; |
| 18 | } // namespace trace_event |
| 19 | } // namespace base |
| 20 | |
| 21 | namespace cc { |
| 22 | |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 23 | struct CC_EXPORT TransformNode { |
| 24 | TransformNode(); |
| 25 | TransformNode(const TransformNode&); |
| 26 | |
wkorman | a4c2d868 | 2017-01-05 01:16:37 | [diff] [blame] | 27 | // The node index of this node in the transform tree node vector. |
Thiemo Nagel | 326859c | 2017-10-06 11:50:59 | [diff] [blame] | 28 | int id; |
wkorman | a4c2d868 | 2017-01-05 01:16:37 | [diff] [blame] | 29 | // The node index of the parent node in the transform tree node vector. |
Thiemo Nagel | 326859c | 2017-10-06 11:50:59 | [diff] [blame] | 30 | int parent_id; |
Chris Harrelson | 7f8e2395 | 2017-06-16 23:15:19 | [diff] [blame] | 31 | |
| 32 | ElementId element_id; |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 33 | |
Thiemo Nagel | 326859c | 2017-10-06 11:50:59 | [diff] [blame] | 34 | // The local transform information is combined to form to_parent (ignoring |
| 35 | // snapping) as follows: |
Xianzhu Wang | 6e8ae99 | 2019-08-20 17:44:14 | [diff] [blame] | 36 | // to_parent = |
| 37 | // T_post_translation * T_origin * T_scroll * M_local * -T_origin. |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 38 | gfx::Transform local; |
Xianzhu Wang | 6e8ae99 | 2019-08-20 17:44:14 | [diff] [blame] | 39 | gfx::Point3F origin; |
Xianzhu Wang | c910955 | 2019-08-28 03:57:01 | [diff] [blame] | 40 | // 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 Wang | 6e8ae99 | 2019-08-20 17:44:14 | [diff] [blame] | 42 | gfx::Vector2dF post_translation; |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 43 | |
Thiemo Nagel | 326859c | 2017-10-06 11:50:59 | [diff] [blame] | 44 | 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; |
flackr | 2215b4e | 2016-09-21 20:16:01 | [diff] [blame] | 49 | |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 50 | // 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 Nagel | 326859c | 2017-10-06 11:50:59 | [diff] [blame] | 53 | int sorting_context_id; |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 54 | |
Philip Rogers | 038bf1d | 2019-06-07 21:37:45 | [diff] [blame] | 55 | // True if |TransformTree::UpdateLocalTransform| needs to be called which |
Xianzhu Wang | c910955 | 2019-08-28 03:57:01 | [diff] [blame] | 56 | // will update |to_parent|. |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 57 | bool needs_local_transform_update : 1; |
| 58 | |
wkorman | a6fc2f2 | 2017-05-17 03:28:05 | [diff] [blame] | 59 | // Whether this node or any ancestor has a potentially running |
| 60 | // (i.e., irrespective of exact timeline) transform animation or an |
| 61 | // invertible transform. |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 62 | bool node_and_ancestors_are_animated_or_invertible : 1; |
| 63 | |
| 64 | bool is_invertible : 1; |
wkorman | a6fc2f2 | 2017-05-17 03:28:05 | [diff] [blame] | 65 | // Whether the transform from this node to the screen is |
| 66 | // invertible. |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 67 | bool ancestors_are_invertible : 1; |
| 68 | |
wkorman | a6fc2f2 | 2017-05-17 03:28:05 | [diff] [blame] | 69 | // Whether this node has a potentially running (i.e., irrespective |
| 70 | // of exact timeline) transform animation. |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 71 | bool has_potential_animation : 1; |
wkorman | a6fc2f2 | 2017-05-17 03:28:05 | [diff] [blame] | 72 | // Whether this node has a currently running transform animation. |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 73 | bool is_currently_animating : 1; |
wkorman | a6fc2f2 | 2017-05-17 03:28:05 | [diff] [blame] | 74 | // Whether this node *or an ancestor* has a potentially running |
| 75 | // (i.e., irrespective of exact timeline) transform |
| 76 | // animation. |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 77 | bool to_screen_is_potentially_animated : 1; |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 78 | |
Thiemo Nagel | 326859c | 2017-10-06 11:50:59 | [diff] [blame] | 79 | // Flattening, when needed, is only applied to a node's inherited transform, |
Xianzhu Wang | d325052 | 2019-08-26 18:48:24 | [diff] [blame] | 80 | // never to its local transform. It's true by default. |
Thiemo Nagel | 326859c | 2017-10-06 11:50:59 | [diff] [blame] | 81 | bool flattens_inherited_transform : 1; |
| 82 | |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 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; |
| 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 Nagel | 326859c | 2017-10-06 11:50:59 | [diff] [blame] | 90 | bool scrolls : 1; |
| 91 | |
| 92 | bool should_be_snapped : 1; |
| 93 | |
Xianzhu Wang | 41319ab4 | 2019-08-28 01:06:36 | [diff] [blame] | 94 | // 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 Nagel | 326859c | 2017-10-06 11:50:59 | [diff] [blame] | 97 | 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 | |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 105 | // We need to track changes to to_screen transform to compute the damage rect. |
| 106 | bool transform_changed : 1; |
| 107 | |
Thiemo Nagel | 326859c | 2017-10-06 11:50:59 | [diff] [blame] | 108 | gfx::ScrollOffset scroll_offset; |
| 109 | |
jaydasika | 2a1718b | 2016-10-26 22:58:02 | [diff] [blame] | 110 | // 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 Nagel | 326859c | 2017-10-06 11:50:59 | [diff] [blame] | 114 | |
Xianzhu Wang | 5164704 | 2019-04-26 22:50:16 | [diff] [blame] | 115 | // See MutatorHost::GetAnimationScales() for their meanings. Updated by |
| 116 | // PropertyTrees::AnimationScalesChanged(). |
Xianzhu Wang | 89ec908 | 2019-04-03 22:32:39 | [diff] [blame] | 117 | float maximum_animation_scale; |
| 118 | float starting_animation_scale; |
| 119 | |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 120 | bool operator==(const TransformNode& other) const; |
| 121 | |
Thiemo Nagel | 326859c | 2017-10-06 11:50:59 | [diff] [blame] | 122 | void set_to_parent(const gfx::Transform& transform) { |
| 123 | to_parent = transform; |
| 124 | is_invertible = to_parent.IsInvertible(); |
| 125 | } |
| 126 | |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 127 | void AsValueInto(base::trace_event::TracedValue* value) const; |
| 128 | }; |
| 129 | |
| 130 | // TODO(sunxd): move this into PropertyTrees::cached_data_. |
| 131 | struct CC_EXPORT TransformCachedNodeData { |
| 132 | TransformCachedNodeData(); |
| 133 | TransformCachedNodeData(const TransformCachedNodeData& other); |
| 134 | ~TransformCachedNodeData(); |
| 135 | |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 136 | gfx::Transform from_screen; |
| 137 | gfx::Transform to_screen; |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 138 | |
trchen | 7520478 | 2016-11-03 01:05:42 | [diff] [blame] | 139 | bool is_showing_backface : 1; |
| 140 | |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 141 | bool operator==(const TransformCachedNodeData& other) const; |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 142 | }; |
| 143 | |
| 144 | } // namespace cc |
| 145 | |
| 146 | #endif // CC_TREES_TRANSFORM_NODE_H_ |