Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(530)

Side by Side Diff: cc/trees/transform_node.cc

Issue 2118993002: Detemplatize cc property nodes (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « cc/trees/transform_node.h ('k') | cc/trees/tree_synchronizer_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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 #include "base/trace_event/trace_event_argument.h"
6 #include "cc/base/math_util.h"
7 #include "cc/proto/gfx_conversions.h"
8 #include "cc/proto/property_tree.pb.h"
9 #include "cc/trees/transform_node.h"
10 #include "ui/gfx/geometry/point3_f.h"
11
12 namespace cc {
13
14 TransformNode::TransformNode()
15 : id(-1),
16 parent_id(-1),
17 owner_id(-1),
18 source_node_id(-1),
19 sorting_context_id(0),
20 needs_local_transform_update(true),
21 node_and_ancestors_are_animated_or_invertible(true),
22 is_invertible(true),
23 ancestors_are_invertible(true),
24 has_potential_animation(false),
25 is_currently_animating(false),
26 to_screen_is_potentially_animated(false),
27 has_only_translation_animations(true),
28 flattens_inherited_transform(false),
29 node_and_ancestors_are_flat(true),
30 node_and_ancestors_have_only_integer_translation(true),
31 scrolls(false),
32 needs_sublayer_scale(false),
33 affected_by_inner_viewport_bounds_delta_x(false),
34 affected_by_inner_viewport_bounds_delta_y(false),
35 affected_by_outer_viewport_bounds_delta_x(false),
36 affected_by_outer_viewport_bounds_delta_y(false),
37 in_subtree_of_page_scale_layer(false),
38 transform_changed(false),
39 post_local_scale_factor(1.0f) {}
40
41 TransformNode::TransformNode(const TransformNode&) = default;
42
43 bool TransformNode::operator==(const TransformNode& other) const {
44 return id == other.id && parent_id == other.parent_id &&
45 owner_id == other.owner_id && pre_local == other.pre_local &&
46 local == other.local && post_local == other.post_local &&
47 to_parent == other.to_parent &&
48 source_node_id == other.source_node_id &&
49 sorting_context_id == other.sorting_context_id &&
50 needs_local_transform_update == other.needs_local_transform_update &&
51 node_and_ancestors_are_animated_or_invertible ==
52 other.node_and_ancestors_are_animated_or_invertible &&
53 is_invertible == other.is_invertible &&
54 ancestors_are_invertible == other.ancestors_are_invertible &&
55 has_potential_animation == other.has_potential_animation &&
56 is_currently_animating == other.is_currently_animating &&
57 to_screen_is_potentially_animated ==
58 other.to_screen_is_potentially_animated &&
59 has_only_translation_animations ==
60 other.has_only_translation_animations &&
61 flattens_inherited_transform == other.flattens_inherited_transform &&
62 node_and_ancestors_are_flat == other.node_and_ancestors_are_flat &&
63 node_and_ancestors_have_only_integer_translation ==
64 other.node_and_ancestors_have_only_integer_translation &&
65 scrolls == other.scrolls &&
66 needs_sublayer_scale == other.needs_sublayer_scale &&
67 affected_by_inner_viewport_bounds_delta_x ==
68 other.affected_by_inner_viewport_bounds_delta_x &&
69 affected_by_inner_viewport_bounds_delta_y ==
70 other.affected_by_inner_viewport_bounds_delta_y &&
71 affected_by_outer_viewport_bounds_delta_x ==
72 other.affected_by_outer_viewport_bounds_delta_x &&
73 affected_by_outer_viewport_bounds_delta_y ==
74 other.affected_by_outer_viewport_bounds_delta_y &&
75 in_subtree_of_page_scale_layer ==
76 other.in_subtree_of_page_scale_layer &&
77 transform_changed == other.transform_changed &&
78 post_local_scale_factor == other.post_local_scale_factor &&
79 sublayer_scale == other.sublayer_scale &&
80 scroll_offset == other.scroll_offset &&
81 scroll_snap == other.scroll_snap &&
82 source_offset == other.source_offset &&
83 source_to_parent == other.source_to_parent;
84 }
85
86 void TransformNode::update_pre_local_transform(
87 const gfx::Point3F& transform_origin) {
88 pre_local.MakeIdentity();
89 pre_local.Translate3d(-transform_origin.x(), -transform_origin.y(),
90 -transform_origin.z());
91 }
92
93 void TransformNode::update_post_local_transform(
94 const gfx::PointF& position,
95 const gfx::Point3F& transform_origin) {
96 post_local.MakeIdentity();
97 post_local.Scale(post_local_scale_factor, post_local_scale_factor);
98 post_local.Translate3d(
99 position.x() + source_offset.x() + transform_origin.x(),
100 position.y() + source_offset.y() + transform_origin.y(),
101 transform_origin.z());
102 }
103
104 void TransformNode::ToProtobuf(proto::TreeNode* proto) const {
105 proto->set_id(id);
106 proto->set_parent_id(parent_id);
107 proto->set_owner_id(owner_id);
108
109 DCHECK(!proto->has_transform_node_data());
110 proto::TranformNodeData* data = proto->mutable_transform_node_data();
111
112 TransformToProto(pre_local, data->mutable_pre_local());
113 TransformToProto(local, data->mutable_local());
114 TransformToProto(post_local, data->mutable_post_local());
115
116 TransformToProto(to_parent, data->mutable_to_parent());
117
118 data->set_source_node_id(source_node_id);
119 data->set_sorting_context_id(sorting_context_id);
120
121 data->set_needs_local_transform_update(needs_local_transform_update);
122
123 data->set_node_and_ancestors_are_animated_or_invertible(
124 node_and_ancestors_are_animated_or_invertible);
125
126 data->set_is_invertible(is_invertible);
127 data->set_ancestors_are_invertible(ancestors_are_invertible);
128
129 data->set_has_potential_animation(has_potential_animation);
130 data->set_is_currently_animating(is_currently_animating);
131 data->set_to_screen_is_potentially_animated(
132 to_screen_is_potentially_animated);
133 data->set_has_only_translation_animations(has_only_translation_animations);
134
135 data->set_flattens_inherited_transform(flattens_inherited_transform);
136 data->set_node_and_ancestors_are_flat(node_and_ancestors_are_flat);
137
138 data->set_node_and_ancestors_have_only_integer_translation(
139 node_and_ancestors_have_only_integer_translation);
140 data->set_scrolls(scrolls);
141 data->set_needs_sublayer_scale(needs_sublayer_scale);
142
143 data->set_affected_by_inner_viewport_bounds_delta_x(
144 affected_by_inner_viewport_bounds_delta_x);
145 data->set_affected_by_inner_viewport_bounds_delta_y(
146 affected_by_inner_viewport_bounds_delta_y);
147 data->set_affected_by_outer_viewport_bounds_delta_x(
148 affected_by_outer_viewport_bounds_delta_x);
149 data->set_affected_by_outer_viewport_bounds_delta_y(
150 affected_by_outer_viewport_bounds_delta_y);
151
152 data->set_in_subtree_of_page_scale_layer(in_subtree_of_page_scale_layer);
153 data->set_transform_changed(transform_changed);
154 data->set_post_local_scale_factor(post_local_scale_factor);
155
156 Vector2dFToProto(sublayer_scale, data->mutable_sublayer_scale());
157 ScrollOffsetToProto(scroll_offset, data->mutable_scroll_offset());
158 Vector2dFToProto(scroll_snap, data->mutable_scroll_snap());
159 Vector2dFToProto(source_offset, data->mutable_source_offset());
160 Vector2dFToProto(source_to_parent, data->mutable_source_to_parent());
161 }
162
163 void TransformNode::FromProtobuf(const proto::TreeNode& proto) {
164 id = proto.id();
165 parent_id = proto.parent_id();
166 owner_id = proto.owner_id();
167
168 DCHECK(proto.has_transform_node_data());
169 const proto::TranformNodeData& data = proto.transform_node_data();
170
171 pre_local = ProtoToTransform(data.pre_local());
172 local = ProtoToTransform(data.local());
173 post_local = ProtoToTransform(data.post_local());
174
175 to_parent = ProtoToTransform(data.to_parent());
176
177 source_node_id = data.source_node_id();
178 sorting_context_id = data.sorting_context_id();
179
180 needs_local_transform_update = data.needs_local_transform_update();
181
182 node_and_ancestors_are_animated_or_invertible =
183 data.node_and_ancestors_are_animated_or_invertible();
184
185 is_invertible = data.is_invertible();
186 ancestors_are_invertible = data.ancestors_are_invertible();
187
188 has_potential_animation = data.has_potential_animation();
189 is_currently_animating = data.is_currently_animating();
190 to_screen_is_potentially_animated = data.to_screen_is_potentially_animated();
191 has_only_translation_animations = data.has_only_translation_animations();
192
193 flattens_inherited_transform = data.flattens_inherited_transform();
194 node_and_ancestors_are_flat = data.node_and_ancestors_are_flat();
195
196 node_and_ancestors_have_only_integer_translation =
197 data.node_and_ancestors_have_only_integer_translation();
198 scrolls = data.scrolls();
199 needs_sublayer_scale = data.needs_sublayer_scale();
200
201 affected_by_inner_viewport_bounds_delta_x =
202 data.affected_by_inner_viewport_bounds_delta_x();
203 affected_by_inner_viewport_bounds_delta_y =
204 data.affected_by_inner_viewport_bounds_delta_y();
205 affected_by_outer_viewport_bounds_delta_x =
206 data.affected_by_outer_viewport_bounds_delta_x();
207 affected_by_outer_viewport_bounds_delta_y =
208 data.affected_by_outer_viewport_bounds_delta_y();
209
210 in_subtree_of_page_scale_layer = data.in_subtree_of_page_scale_layer();
211 transform_changed = data.transform_changed();
212 post_local_scale_factor = data.post_local_scale_factor();
213
214 sublayer_scale = ProtoToVector2dF(data.sublayer_scale());
215 scroll_offset = ProtoToScrollOffset(data.scroll_offset());
216 scroll_snap = ProtoToVector2dF(data.scroll_snap());
217 source_offset = ProtoToVector2dF(data.source_offset());
218 source_to_parent = ProtoToVector2dF(data.source_to_parent());
219 }
220
221 void TransformNode::AsValueInto(base::trace_event::TracedValue* value) const {
222 value->SetInteger("id", id);
223 value->SetInteger("parent_id", parent_id);
224 value->SetInteger("owner_id", owner_id);
225 MathUtil::AddToTracedValue("pre_local", pre_local, value);
226 MathUtil::AddToTracedValue("local", local, value);
227 MathUtil::AddToTracedValue("post_local", post_local, value);
228 // TODO(sunxd): make frameviewer work without target_id
229 value->SetInteger("target_id", 0);
230 value->SetInteger("content_target_id", 0);
231 value->SetInteger("source_node_id", source_node_id);
232 value->SetInteger("sorting_context_id", sorting_context_id);
233 }
234
235 TransformCachedNodeData::TransformCachedNodeData()
236 : target_id(-1), content_target_id(-1) {}
237
238 TransformCachedNodeData::TransformCachedNodeData(
239 const TransformCachedNodeData& other) = default;
240
241 TransformCachedNodeData::~TransformCachedNodeData() {}
242
243 bool TransformCachedNodeData::operator==(
244 const TransformCachedNodeData& other) const {
245 return from_target == other.from_target && to_target == other.to_target &&
246 from_screen == other.from_screen && to_screen == other.to_screen &&
247 target_id == other.target_id &&
248 content_target_id == other.content_target_id;
249 }
250
251 void TransformCachedNodeData::ToProtobuf(
252 proto::TransformCachedNodeData* proto) const {
253 TransformToProto(from_target, proto->mutable_from_target());
254 TransformToProto(to_target, proto->mutable_to_target());
255 TransformToProto(from_screen, proto->mutable_from_screen());
256 TransformToProto(to_screen, proto->mutable_to_screen());
257 proto->set_target_id(target_id);
258 proto->set_content_target_id(content_target_id);
259 }
260
261 void TransformCachedNodeData::FromProtobuf(
262 const proto::TransformCachedNodeData& proto) {
263 from_target = ProtoToTransform(proto.from_target());
264 to_target = ProtoToTransform(proto.to_target());
265 from_screen = ProtoToTransform(proto.from_screen());
266 to_screen = ProtoToTransform(proto.to_screen());
267 target_id = proto.target_id();
268 content_target_id = proto.content_target_id();
269 }
270
271 } // namespace cc
OLDNEW
« no previous file with comments | « cc/trees/transform_node.h ('k') | cc/trees/tree_synchronizer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698