| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 #ifndef CC_TREES_PROPERTY_TREE_H_ | 5 #ifndef CC_TREES_PROPERTY_TREE_H_ |
| 6 #define CC_TREES_PROPERTY_TREE_H_ | 6 #define CC_TREES_PROPERTY_TREE_H_ |
| 7 | 7 |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "cc/base/cc_export.h" | 11 #include "cc/base/cc_export.h" |
| 12 #include "ui/gfx/geometry/rect_f.h" | 12 #include "ui/gfx/geometry/rect_f.h" |
| 13 #include "ui/gfx/geometry/scroll_offset.h" | 13 #include "ui/gfx/geometry/scroll_offset.h" |
| 14 #include "ui/gfx/transform.h" | 14 #include "ui/gfx/transform.h" |
| 15 | 15 |
| 16 namespace cc { | 16 namespace cc { |
| 17 | 17 |
| 18 namespace proto { |
| 19 class ClipNodeData; |
| 20 class EffectNodeData; |
| 21 class PropertyTree; |
| 22 class PropertyTrees; |
| 23 class TranformNodeData; |
| 24 class TransformTreeData; |
| 25 class TreeNode; |
| 26 } |
| 27 |
| 28 // Each class declared here has a corresponding proto defined in |
| 29 // cc/proto/property_tree.proto. When making any changes to a class structure |
| 30 // including addition/deletion/updation of a field, please also make the |
| 31 // change to its proto and the ToProtobuf and FromProtobuf methods for that |
| 32 // class. |
| 33 |
| 18 template <typename T> | 34 template <typename T> |
| 19 struct CC_EXPORT TreeNode { | 35 struct CC_EXPORT TreeNode { |
| 20 TreeNode() : id(-1), parent_id(-1), owner_id(-1), data() {} | 36 TreeNode() : id(-1), parent_id(-1), owner_id(-1), data() {} |
| 21 int id; | 37 int id; |
| 22 int parent_id; | 38 int parent_id; |
| 23 int owner_id; | 39 int owner_id; |
| 24 T data; | 40 T data; |
| 41 |
| 42 bool operator==(const TreeNode& other) const; |
| 43 |
| 44 void ToProtobuf(proto::TreeNode* proto) const; |
| 45 void FromProtobuf(const proto::TreeNode& proto); |
| 25 }; | 46 }; |
| 26 | 47 |
| 27 struct CC_EXPORT TransformNodeData { | 48 struct CC_EXPORT TransformNodeData { |
| 28 TransformNodeData(); | 49 TransformNodeData(); |
| 29 ~TransformNodeData(); | 50 ~TransformNodeData(); |
| 30 | 51 |
| 31 // The local transform information is combined to form to_parent (ignoring | 52 // The local transform information is combined to form to_parent (ignoring |
| 32 // snapping) as follows: | 53 // snapping) as follows: |
| 33 // | 54 // |
| 34 // to_parent = M_post_local * T_scroll * M_local * M_pre_local. | 55 // to_parent = M_post_local * T_scroll * M_local * M_pre_local. |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 | 155 |
| 135 // We scroll snap where possible, but this has an effect on scroll | 156 // We scroll snap where possible, but this has an effect on scroll |
| 136 // compensation: the snap is yet more scrolling that must be compensated for. | 157 // compensation: the snap is yet more scrolling that must be compensated for. |
| 137 // This value stores the snapped amount for this purpose. | 158 // This value stores the snapped amount for this purpose. |
| 138 gfx::Vector2dF scroll_snap; | 159 gfx::Vector2dF scroll_snap; |
| 139 | 160 |
| 140 // TODO(vollick): will be moved when accelerated effects are implemented. | 161 // TODO(vollick): will be moved when accelerated effects are implemented. |
| 141 gfx::Vector2dF source_offset; | 162 gfx::Vector2dF source_offset; |
| 142 gfx::Vector2dF source_to_parent; | 163 gfx::Vector2dF source_to_parent; |
| 143 | 164 |
| 165 bool operator==(const TransformNodeData& other) const; |
| 166 |
| 144 void set_to_parent(const gfx::Transform& transform) { | 167 void set_to_parent(const gfx::Transform& transform) { |
| 145 to_parent = transform; | 168 to_parent = transform; |
| 146 is_invertible = to_parent.IsInvertible(); | 169 is_invertible = to_parent.IsInvertible(); |
| 147 } | 170 } |
| 148 | 171 |
| 149 void update_pre_local_transform(const gfx::Point3F& transform_origin); | 172 void update_pre_local_transform(const gfx::Point3F& transform_origin); |
| 150 | 173 |
| 151 void update_post_local_transform(const gfx::PointF& position, | 174 void update_post_local_transform(const gfx::PointF& position, |
| 152 const gfx::Point3F& transform_origin); | 175 const gfx::Point3F& transform_origin); |
| 176 |
| 177 void ToProtobuf(proto::TreeNode* proto) const; |
| 178 void FromProtobuf(const proto::TreeNode& proto); |
| 153 }; | 179 }; |
| 154 | 180 |
| 155 typedef TreeNode<TransformNodeData> TransformNode; | 181 typedef TreeNode<TransformNodeData> TransformNode; |
| 156 | 182 |
| 157 struct CC_EXPORT ClipNodeData { | 183 struct CC_EXPORT ClipNodeData { |
| 158 ClipNodeData(); | 184 ClipNodeData(); |
| 159 | 185 |
| 160 // The clip rect that this node contributes, expressed in the space of its | 186 // The clip rect that this node contributes, expressed in the space of its |
| 161 // transform node. | 187 // transform node. |
| 162 gfx::RectF clip; | 188 gfx::RectF clip; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 191 // True if target surface needs to be drawn with a clip applied. | 217 // True if target surface needs to be drawn with a clip applied. |
| 192 bool target_is_clipped : 1; | 218 bool target_is_clipped : 1; |
| 193 | 219 |
| 194 // True if layers with this clip tree node need to be drawn with a clip | 220 // True if layers with this clip tree node need to be drawn with a clip |
| 195 // applied. | 221 // applied. |
| 196 bool layers_are_clipped : 1; | 222 bool layers_are_clipped : 1; |
| 197 bool layers_are_clipped_when_surfaces_disabled : 1; | 223 bool layers_are_clipped_when_surfaces_disabled : 1; |
| 198 | 224 |
| 199 // Nodes that correspond to unclipped surfaces disregard ancestor clips. | 225 // Nodes that correspond to unclipped surfaces disregard ancestor clips. |
| 200 bool resets_clip : 1; | 226 bool resets_clip : 1; |
| 227 |
| 228 bool operator==(const ClipNodeData& other) const; |
| 229 |
| 230 void ToProtobuf(proto::TreeNode* proto) const; |
| 231 void FromProtobuf(const proto::TreeNode& proto); |
| 201 }; | 232 }; |
| 202 | 233 |
| 203 typedef TreeNode<ClipNodeData> ClipNode; | 234 typedef TreeNode<ClipNodeData> ClipNode; |
| 204 | 235 |
| 205 struct CC_EXPORT EffectNodeData { | 236 struct CC_EXPORT EffectNodeData { |
| 206 EffectNodeData(); | 237 EffectNodeData(); |
| 207 | 238 |
| 208 float opacity; | 239 float opacity; |
| 209 float screen_space_opacity; | 240 float screen_space_opacity; |
| 210 | 241 |
| 211 bool has_render_surface; | 242 bool has_render_surface; |
| 212 int transform_id; | 243 int transform_id; |
| 213 int clip_id; | 244 int clip_id; |
| 245 |
| 246 bool operator==(const EffectNodeData& other) const; |
| 247 |
| 248 void ToProtobuf(proto::TreeNode* proto) const; |
| 249 void FromProtobuf(const proto::TreeNode& proto); |
| 214 }; | 250 }; |
| 215 | 251 |
| 216 typedef TreeNode<EffectNodeData> EffectNode; | 252 typedef TreeNode<EffectNodeData> EffectNode; |
| 217 | 253 |
| 218 template <typename T> | 254 template <typename T> |
| 219 class CC_EXPORT PropertyTree { | 255 class CC_EXPORT PropertyTree { |
| 220 public: | 256 public: |
| 221 PropertyTree(); | 257 PropertyTree(); |
| 222 virtual ~PropertyTree(); | 258 virtual ~PropertyTree(); |
| 223 | 259 |
| 260 bool operator==(const PropertyTree& other) const; |
| 261 |
| 224 int Insert(const T& tree_node, int parent_id); | 262 int Insert(const T& tree_node, int parent_id); |
| 225 | 263 |
| 226 T* Node(int i) { | 264 T* Node(int i) { |
| 227 // TODO(vollick): remove this. | 265 // TODO(vollick): remove this. |
| 228 CHECK(i < static_cast<int>(nodes_.size())); | 266 CHECK(i < static_cast<int>(nodes_.size())); |
| 229 return i > -1 ? &nodes_[i] : nullptr; | 267 return i > -1 ? &nodes_[i] : nullptr; |
| 230 } | 268 } |
| 231 const T* Node(int i) const { | 269 const T* Node(int i) const { |
| 232 // TODO(vollick): remove this. | 270 // TODO(vollick): remove this. |
| 233 CHECK(i < static_cast<int>(nodes_.size())); | 271 CHECK(i < static_cast<int>(nodes_.size())); |
| 234 return i > -1 ? &nodes_[i] : nullptr; | 272 return i > -1 ? &nodes_[i] : nullptr; |
| 235 } | 273 } |
| 236 | 274 |
| 237 T* parent(const T* t) { return Node(t->parent_id); } | 275 T* parent(const T* t) { return Node(t->parent_id); } |
| 238 const T* parent(const T* t) const { return Node(t->parent_id); } | 276 const T* parent(const T* t) const { return Node(t->parent_id); } |
| 239 | 277 |
| 240 T* back() { return size() ? &nodes_[nodes_.size() - 1] : nullptr; } | 278 T* back() { return size() ? &nodes_[nodes_.size() - 1] : nullptr; } |
| 241 const T* back() const { | 279 const T* back() const { |
| 242 return size() ? &nodes_[nodes_.size() - 1] : nullptr; | 280 return size() ? &nodes_[nodes_.size() - 1] : nullptr; |
| 243 } | 281 } |
| 244 | 282 |
| 245 virtual void clear(); | 283 virtual void clear(); |
| 246 size_t size() const { return nodes_.size(); } | 284 size_t size() const { return nodes_.size(); } |
| 247 | 285 |
| 248 void set_needs_update(bool needs_update) { needs_update_ = needs_update; } | 286 void set_needs_update(bool needs_update) { needs_update_ = needs_update; } |
| 249 bool needs_update() const { return needs_update_; } | 287 bool needs_update() const { return needs_update_; } |
| 250 | 288 |
| 289 const std::vector<T>& nodes() const { return nodes_; } |
| 290 |
| 251 int next_available_id() const { return static_cast<int>(size()); } | 291 int next_available_id() const { return static_cast<int>(size()); } |
| 252 | 292 |
| 293 void ToProtobuf(proto::PropertyTree* proto) const; |
| 294 void FromProtobuf(const proto::PropertyTree& proto); |
| 295 |
| 253 private: | 296 private: |
| 254 // Copy and assign are permitted. This is how we do tree sync. | 297 // Copy and assign are permitted. This is how we do tree sync. |
| 255 std::vector<T> nodes_; | 298 std::vector<T> nodes_; |
| 256 | 299 |
| 257 bool needs_update_; | 300 bool needs_update_; |
| 258 }; | 301 }; |
| 259 | 302 |
| 260 class CC_EXPORT TransformTree final : public PropertyTree<TransformNode> { | 303 class CC_EXPORT TransformTree final : public PropertyTree<TransformNode> { |
| 261 public: | 304 public: |
| 262 TransformTree(); | 305 TransformTree(); |
| 263 ~TransformTree() override; | 306 ~TransformTree() override; |
| 264 | 307 |
| 308 bool operator==(const TransformTree& other) const; |
| 309 |
| 265 void clear() override; | 310 void clear() override; |
| 266 | 311 |
| 267 // Computes the change of basis transform from node |source_id| to |dest_id|. | 312 // Computes the change of basis transform from node |source_id| to |dest_id|. |
| 268 // The function returns false iff the inverse of a singular transform was | 313 // The function returns false iff the inverse of a singular transform was |
| 269 // used (and the result should, therefore, not be trusted). Transforms may | 314 // used (and the result should, therefore, not be trusted). Transforms may |
| 270 // be computed between any pair of nodes that have an ancestor/descendant | 315 // be computed between any pair of nodes that have an ancestor/descendant |
| 271 // relationship. Transforms between other pairs of nodes may only be computed | 316 // relationship. Transforms between other pairs of nodes may only be computed |
| 272 // if the following condition holds: let id1 the larger id and let id2 be the | 317 // if the following condition holds: let id1 the larger id and let id2 be the |
| 273 // other id; then the nearest ancestor of node id1 whose id is smaller than | 318 // other id; then the nearest ancestor of node id1 whose id is smaller than |
| 274 // id2 is the lowest common ancestor of the pair of nodes, and the transform | 319 // id2 is the lowest common ancestor of the pair of nodes, and the transform |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 324 float page_scale_factor() const { return page_scale_factor_; } | 369 float page_scale_factor() const { return page_scale_factor_; } |
| 325 | 370 |
| 326 void set_device_scale_factor(float device_scale_factor) { | 371 void set_device_scale_factor(float device_scale_factor) { |
| 327 device_scale_factor_ = device_scale_factor; | 372 device_scale_factor_ = device_scale_factor; |
| 328 } | 373 } |
| 329 float device_scale_factor() const { return device_scale_factor_; } | 374 float device_scale_factor() const { return device_scale_factor_; } |
| 330 | 375 |
| 331 void SetDeviceTransform(const gfx::Transform& transform, | 376 void SetDeviceTransform(const gfx::Transform& transform, |
| 332 gfx::PointF root_position); | 377 gfx::PointF root_position); |
| 333 void SetDeviceTransformScaleFactor(const gfx::Transform& transform); | 378 void SetDeviceTransformScaleFactor(const gfx::Transform& transform); |
| 379 float device_transform_scale_factor() const { |
| 380 return device_transform_scale_factor_; |
| 381 } |
| 334 | 382 |
| 335 void SetInnerViewportBoundsDelta(gfx::Vector2dF bounds_delta); | 383 void SetInnerViewportBoundsDelta(gfx::Vector2dF bounds_delta); |
| 336 gfx::Vector2dF inner_viewport_bounds_delta() const { | 384 gfx::Vector2dF inner_viewport_bounds_delta() const { |
| 337 return inner_viewport_bounds_delta_; | 385 return inner_viewport_bounds_delta_; |
| 338 } | 386 } |
| 339 | 387 |
| 340 void SetOuterViewportBoundsDelta(gfx::Vector2dF bounds_delta); | 388 void SetOuterViewportBoundsDelta(gfx::Vector2dF bounds_delta); |
| 341 gfx::Vector2dF outer_viewport_bounds_delta() const { | 389 gfx::Vector2dF outer_viewport_bounds_delta() const { |
| 342 return outer_viewport_bounds_delta_; | 390 return outer_viewport_bounds_delta_; |
| 343 } | 391 } |
| 344 | 392 |
| 345 void AddNodeAffectedByInnerViewportBoundsDelta(int node_id); | 393 void AddNodeAffectedByInnerViewportBoundsDelta(int node_id); |
| 346 void AddNodeAffectedByOuterViewportBoundsDelta(int node_id); | 394 void AddNodeAffectedByOuterViewportBoundsDelta(int node_id); |
| 347 | 395 |
| 348 bool HasNodesAffectedByInnerViewportBoundsDelta() const; | 396 bool HasNodesAffectedByInnerViewportBoundsDelta() const; |
| 349 bool HasNodesAffectedByOuterViewportBoundsDelta() const; | 397 bool HasNodesAffectedByOuterViewportBoundsDelta() const; |
| 350 | 398 |
| 399 const std::vector<int>& nodes_affected_by_inner_viewport_bounds_delta() |
| 400 const { |
| 401 return nodes_affected_by_inner_viewport_bounds_delta_; |
| 402 } |
| 403 const std::vector<int>& nodes_affected_by_outer_viewport_bounds_delta() |
| 404 const { |
| 405 return nodes_affected_by_outer_viewport_bounds_delta_; |
| 406 } |
| 407 |
| 408 void ToProtobuf(proto::PropertyTree* proto) const; |
| 409 void FromProtobuf(const proto::PropertyTree& proto); |
| 410 |
| 351 private: | 411 private: |
| 352 // Returns true iff the node at |desc_id| is a descendant of the node at | 412 // Returns true iff the node at |desc_id| is a descendant of the node at |
| 353 // |anc_id|. | 413 // |anc_id|. |
| 354 bool IsDescendant(int desc_id, int anc_id) const; | 414 bool IsDescendant(int desc_id, int anc_id) const; |
| 355 | 415 |
| 356 // Computes the combined transform between |source_id| and |dest_id| and | 416 // Computes the combined transform between |source_id| and |dest_id| and |
| 357 // returns false if the inverse of a singular transform was used. These two | 417 // returns false if the inverse of a singular transform was used. These two |
| 358 // nodes must be on the same ancestor chain. | 418 // nodes must be on the same ancestor chain. |
| 359 bool CombineTransformsBetween(int source_id, | 419 bool CombineTransformsBetween(int source_id, |
| 360 int dest_id, | 420 int dest_id, |
| (...skipping 30 matching lines...) Expand all Loading... |
| 391 float device_scale_factor_; | 451 float device_scale_factor_; |
| 392 float device_transform_scale_factor_; | 452 float device_transform_scale_factor_; |
| 393 gfx::Vector2dF inner_viewport_bounds_delta_; | 453 gfx::Vector2dF inner_viewport_bounds_delta_; |
| 394 gfx::Vector2dF outer_viewport_bounds_delta_; | 454 gfx::Vector2dF outer_viewport_bounds_delta_; |
| 395 std::vector<int> nodes_affected_by_inner_viewport_bounds_delta_; | 455 std::vector<int> nodes_affected_by_inner_viewport_bounds_delta_; |
| 396 std::vector<int> nodes_affected_by_outer_viewport_bounds_delta_; | 456 std::vector<int> nodes_affected_by_outer_viewport_bounds_delta_; |
| 397 }; | 457 }; |
| 398 | 458 |
| 399 class CC_EXPORT ClipTree final : public PropertyTree<ClipNode> { | 459 class CC_EXPORT ClipTree final : public PropertyTree<ClipNode> { |
| 400 public: | 460 public: |
| 461 bool operator==(const ClipTree& other) const; |
| 462 |
| 401 void SetViewportClip(gfx::RectF viewport_rect); | 463 void SetViewportClip(gfx::RectF viewport_rect); |
| 402 gfx::RectF ViewportClip(); | 464 gfx::RectF ViewportClip(); |
| 465 |
| 466 void ToProtobuf(proto::PropertyTree* proto) const; |
| 467 void FromProtobuf(const proto::PropertyTree& proto); |
| 403 }; | 468 }; |
| 404 | 469 |
| 405 class CC_EXPORT EffectTree final : public PropertyTree<EffectNode> { | 470 class CC_EXPORT EffectTree final : public PropertyTree<EffectNode> { |
| 406 public: | 471 public: |
| 472 bool operator==(const EffectTree& other) const; |
| 473 |
| 407 void UpdateOpacities(int id); | 474 void UpdateOpacities(int id); |
| 475 |
| 476 void ToProtobuf(proto::PropertyTree* proto) const; |
| 477 void FromProtobuf(const proto::PropertyTree& proto); |
| 408 }; | 478 }; |
| 409 | 479 |
| 410 class CC_EXPORT PropertyTrees final { | 480 class CC_EXPORT PropertyTrees final { |
| 411 public: | 481 public: |
| 412 PropertyTrees(); | 482 PropertyTrees(); |
| 413 | 483 |
| 484 bool operator==(const PropertyTrees& other) const; |
| 485 |
| 486 void ToProtobuf(proto::PropertyTrees* proto) const; |
| 487 void FromProtobuf(const proto::PropertyTrees& proto); |
| 488 |
| 414 TransformTree transform_tree; | 489 TransformTree transform_tree; |
| 415 EffectTree effect_tree; | 490 EffectTree effect_tree; |
| 416 ClipTree clip_tree; | 491 ClipTree clip_tree; |
| 417 bool needs_rebuild; | 492 bool needs_rebuild; |
| 418 bool non_root_surfaces_enabled; | 493 bool non_root_surfaces_enabled; |
| 419 int sequence_number; | 494 int sequence_number; |
| 420 }; | 495 }; |
| 421 | 496 |
| 422 } // namespace cc | 497 } // namespace cc |
| 423 | 498 |
| 424 #endif // CC_TREES_PROPERTY_TREE_H_ | 499 #endif // CC_TREES_PROPERTY_TREE_H_ |
| OLD | NEW |