| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/trace_event/trace_event_argument.h" | 5 #include "base/trace_event/trace_event_argument.h" |
| 6 #include "cc/base/math_util.h" | 6 #include "cc/base/math_util.h" |
| 7 #include "cc/proto/gfx_conversions.h" | 7 #include "cc/proto/gfx_conversions.h" |
| 8 #include "cc/proto/property_tree.pb.h" | |
| 9 #include "cc/trees/transform_node.h" | 8 #include "cc/trees/transform_node.h" |
| 10 #include "ui/gfx/geometry/point3_f.h" | 9 #include "ui/gfx/geometry/point3_f.h" |
| 11 | 10 |
| 12 namespace cc { | 11 namespace cc { |
| 13 | 12 |
| 14 TransformNode::TransformNode() | 13 TransformNode::TransformNode() |
| 15 : id(-1), | 14 : id(-1), |
| 16 parent_id(-1), | 15 parent_id(-1), |
| 17 owner_id(-1), | 16 owner_id(-1), |
| 18 sticky_position_constraint_id(-1), | 17 sticky_position_constraint_id(-1), |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 const gfx::PointF& position, | 93 const gfx::PointF& position, |
| 95 const gfx::Point3F& transform_origin) { | 94 const gfx::Point3F& transform_origin) { |
| 96 post_local.MakeIdentity(); | 95 post_local.MakeIdentity(); |
| 97 post_local.Scale(post_local_scale_factor, post_local_scale_factor); | 96 post_local.Scale(post_local_scale_factor, post_local_scale_factor); |
| 98 post_local.Translate3d( | 97 post_local.Translate3d( |
| 99 position.x() + source_offset.x() + transform_origin.x(), | 98 position.x() + source_offset.x() + transform_origin.x(), |
| 100 position.y() + source_offset.y() + transform_origin.y(), | 99 position.y() + source_offset.y() + transform_origin.y(), |
| 101 transform_origin.z()); | 100 transform_origin.z()); |
| 102 } | 101 } |
| 103 | 102 |
| 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_should_be_snapped(should_be_snapped); | |
| 142 | |
| 143 data->set_moved_by_inner_viewport_bounds_delta_x( | |
| 144 moved_by_inner_viewport_bounds_delta_x); | |
| 145 data->set_moved_by_inner_viewport_bounds_delta_y( | |
| 146 moved_by_inner_viewport_bounds_delta_y); | |
| 147 data->set_moved_by_outer_viewport_bounds_delta_x( | |
| 148 moved_by_outer_viewport_bounds_delta_x); | |
| 149 data->set_moved_by_outer_viewport_bounds_delta_y( | |
| 150 moved_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 ScrollOffsetToProto(scroll_offset, data->mutable_scroll_offset()); | |
| 157 Vector2dFToProto(snap_amount, data->mutable_snap_amount()); | |
| 158 Vector2dFToProto(source_offset, data->mutable_source_offset()); | |
| 159 Vector2dFToProto(source_to_parent, data->mutable_source_to_parent()); | |
| 160 } | |
| 161 | |
| 162 void TransformNode::FromProtobuf(const proto::TreeNode& proto) { | |
| 163 id = proto.id(); | |
| 164 parent_id = proto.parent_id(); | |
| 165 owner_id = proto.owner_id(); | |
| 166 | |
| 167 DCHECK(proto.has_transform_node_data()); | |
| 168 const proto::TranformNodeData& data = proto.transform_node_data(); | |
| 169 | |
| 170 pre_local = ProtoToTransform(data.pre_local()); | |
| 171 local = ProtoToTransform(data.local()); | |
| 172 post_local = ProtoToTransform(data.post_local()); | |
| 173 | |
| 174 to_parent = ProtoToTransform(data.to_parent()); | |
| 175 | |
| 176 source_node_id = data.source_node_id(); | |
| 177 sorting_context_id = data.sorting_context_id(); | |
| 178 | |
| 179 needs_local_transform_update = data.needs_local_transform_update(); | |
| 180 | |
| 181 node_and_ancestors_are_animated_or_invertible = | |
| 182 data.node_and_ancestors_are_animated_or_invertible(); | |
| 183 | |
| 184 is_invertible = data.is_invertible(); | |
| 185 ancestors_are_invertible = data.ancestors_are_invertible(); | |
| 186 | |
| 187 has_potential_animation = data.has_potential_animation(); | |
| 188 is_currently_animating = data.is_currently_animating(); | |
| 189 to_screen_is_potentially_animated = data.to_screen_is_potentially_animated(); | |
| 190 has_only_translation_animations = data.has_only_translation_animations(); | |
| 191 | |
| 192 flattens_inherited_transform = data.flattens_inherited_transform(); | |
| 193 node_and_ancestors_are_flat = data.node_and_ancestors_are_flat(); | |
| 194 | |
| 195 node_and_ancestors_have_only_integer_translation = | |
| 196 data.node_and_ancestors_have_only_integer_translation(); | |
| 197 scrolls = data.scrolls(); | |
| 198 should_be_snapped = data.should_be_snapped(); | |
| 199 | |
| 200 moved_by_inner_viewport_bounds_delta_x = | |
| 201 data.moved_by_inner_viewport_bounds_delta_x(); | |
| 202 moved_by_inner_viewport_bounds_delta_y = | |
| 203 data.moved_by_inner_viewport_bounds_delta_y(); | |
| 204 moved_by_outer_viewport_bounds_delta_x = | |
| 205 data.moved_by_outer_viewport_bounds_delta_x(); | |
| 206 moved_by_outer_viewport_bounds_delta_y = | |
| 207 data.moved_by_outer_viewport_bounds_delta_y(); | |
| 208 | |
| 209 in_subtree_of_page_scale_layer = data.in_subtree_of_page_scale_layer(); | |
| 210 transform_changed = data.transform_changed(); | |
| 211 post_local_scale_factor = data.post_local_scale_factor(); | |
| 212 | |
| 213 scroll_offset = ProtoToScrollOffset(data.scroll_offset()); | |
| 214 snap_amount = ProtoToVector2dF(data.snap_amount()); | |
| 215 source_offset = ProtoToVector2dF(data.source_offset()); | |
| 216 source_to_parent = ProtoToVector2dF(data.source_to_parent()); | |
| 217 } | |
| 218 | |
| 219 void TransformNode::AsValueInto(base::trace_event::TracedValue* value) const { | 103 void TransformNode::AsValueInto(base::trace_event::TracedValue* value) const { |
| 220 value->SetInteger("id", id); | 104 value->SetInteger("id", id); |
| 221 value->SetInteger("parent_id", parent_id); | 105 value->SetInteger("parent_id", parent_id); |
| 222 value->SetInteger("owner_id", owner_id); | 106 value->SetInteger("owner_id", owner_id); |
| 223 MathUtil::AddToTracedValue("pre_local", pre_local, value); | 107 MathUtil::AddToTracedValue("pre_local", pre_local, value); |
| 224 MathUtil::AddToTracedValue("local", local, value); | 108 MathUtil::AddToTracedValue("local", local, value); |
| 225 MathUtil::AddToTracedValue("post_local", post_local, value); | 109 MathUtil::AddToTracedValue("post_local", post_local, value); |
| 226 // TODO(sunxd): make frameviewer work without target_id | 110 // TODO(sunxd): make frameviewer work without target_id |
| 227 value->SetInteger("target_id", 0); | 111 value->SetInteger("target_id", 0); |
| 228 value->SetInteger("content_target_id", 0); | 112 value->SetInteger("content_target_id", 0); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 241 TransformCachedNodeData::~TransformCachedNodeData() {} | 125 TransformCachedNodeData::~TransformCachedNodeData() {} |
| 242 | 126 |
| 243 bool TransformCachedNodeData::operator==( | 127 bool TransformCachedNodeData::operator==( |
| 244 const TransformCachedNodeData& other) const { | 128 const TransformCachedNodeData& other) const { |
| 245 return from_screen == other.from_screen && to_screen == other.to_screen && | 129 return from_screen == other.from_screen && to_screen == other.to_screen && |
| 246 target_id == other.target_id && | 130 target_id == other.target_id && |
| 247 content_target_id == other.content_target_id && | 131 content_target_id == other.content_target_id && |
| 248 is_showing_backface == other.is_showing_backface; | 132 is_showing_backface == other.is_showing_backface; |
| 249 } | 133 } |
| 250 | 134 |
| 251 void TransformCachedNodeData::ToProtobuf( | |
| 252 proto::TransformCachedNodeData* proto) const { | |
| 253 TransformToProto(from_screen, proto->mutable_from_screen()); | |
| 254 TransformToProto(to_screen, proto->mutable_to_screen()); | |
| 255 proto->set_target_id(target_id); | |
| 256 proto->set_content_target_id(content_target_id); | |
| 257 proto->set_is_showing_backface(is_showing_backface); | |
| 258 } | |
| 259 | |
| 260 void TransformCachedNodeData::FromProtobuf( | |
| 261 const proto::TransformCachedNodeData& proto) { | |
| 262 from_screen = ProtoToTransform(proto.from_screen()); | |
| 263 to_screen = ProtoToTransform(proto.to_screen()); | |
| 264 target_id = proto.target_id(); | |
| 265 content_target_id = proto.content_target_id(); | |
| 266 is_showing_backface = proto.is_showing_backface(); | |
| 267 } | |
| 268 | |
| 269 } // namespace cc | 135 } // namespace cc |
| OLD | NEW |