OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CC_TREES_PROPERTY_TREE_H_ |
| 6 #define CC_TREES_PROPERTY_TREE_H_ |
| 7 |
| 8 #include <vector> |
| 9 |
| 10 #include "base/basictypes.h" |
| 11 #include "cc/base/cc_export.h" |
| 12 #include "ui/gfx/rect.h" |
| 13 #include "ui/gfx/transform.h" |
| 14 |
| 15 namespace cc { |
| 16 |
| 17 template <typename T> |
| 18 struct CC_EXPORT TreeNode { |
| 19 TreeNode() : id(-1), parent_id(-1), data() {} |
| 20 int id; |
| 21 int parent_id; |
| 22 T data; |
| 23 }; |
| 24 |
| 25 struct CC_EXPORT TransformNodeData { |
| 26 TransformNodeData(); |
| 27 ~TransformNodeData(); |
| 28 |
| 29 gfx::Transform to_parent; |
| 30 gfx::Transform from_parent; |
| 31 |
| 32 gfx::Transform to_screen; |
| 33 gfx::Transform from_screen; |
| 34 |
| 35 int target_id; |
| 36 |
| 37 bool is_invertible; |
| 38 bool ancestors_are_invertible; |
| 39 |
| 40 bool is_animated; |
| 41 bool to_screen_is_animated; |
| 42 |
| 43 bool flattens; |
| 44 |
| 45 void set_to_parent(const gfx::Transform& transform) { |
| 46 to_parent = transform; |
| 47 is_invertible = to_parent.GetInverse(&from_parent); |
| 48 } |
| 49 }; |
| 50 |
| 51 typedef TreeNode<TransformNodeData> TransformNode; |
| 52 |
| 53 struct CC_EXPORT ClipNodeData { |
| 54 ClipNodeData(); |
| 55 |
| 56 gfx::RectF clip; |
| 57 gfx::RectF combined_clip; |
| 58 int transform_id; |
| 59 int target_id; |
| 60 }; |
| 61 |
| 62 typedef TreeNode<ClipNodeData> ClipNode; |
| 63 |
| 64 template <typename T> |
| 65 class CC_EXPORT PropertyTree { |
| 66 public: |
| 67 PropertyTree(); |
| 68 virtual ~PropertyTree(); |
| 69 |
| 70 int Insert(const T& tree_node, int parent_id); |
| 71 |
| 72 T* Node(int i) { return i > -1 ? &nodes_[i] : nullptr; } |
| 73 const T* Node(int i) const { return i > -1 ? &nodes_[i] : nullptr; } |
| 74 |
| 75 T* parent(const T* t) { |
| 76 return t->parent_id > -1 ? Node(t->parent_id) : nullptr; |
| 77 } |
| 78 const T* parent(const T* t) const { |
| 79 return t->parent_id > -1 ? Node(t->parent_id) : nullptr; |
| 80 } |
| 81 |
| 82 T* back() { return size() ? &nodes_[nodes_.size() - 1] : nullptr; } |
| 83 const T* back() const { |
| 84 return size() ? &nodes_[nodes_.size() - 1] : nullptr; |
| 85 } |
| 86 |
| 87 void clear() { nodes_.clear(); } |
| 88 size_t size() const { return nodes_.size(); } |
| 89 |
| 90 private: |
| 91 // Copy and assign are permitted. This is how we do tree sync. |
| 92 std::vector<T> nodes_; |
| 93 }; |
| 94 |
| 95 class CC_EXPORT TransformTree final : public PropertyTree<TransformNode> { |
| 96 public: |
| 97 // Computes the change of basis transform from node |source_id| to |dest_id|. |
| 98 // The function returns false iff the inverse of a singular transform was |
| 99 // used (and the result should, therefore, not be trusted). |
| 100 bool ComputeTransform(int source_id, |
| 101 int dest_id, |
| 102 gfx::Transform* transform) const; |
| 103 |
| 104 // Returns true iff the nodes indexed by |source_id| and |dest_id| are 2D axis |
| 105 // aligned with respect to one another. |
| 106 bool Are2DAxisAligned(int source_id, int dest_id) const; |
| 107 |
| 108 // This recomputes the screen space transform (and its inverse) for the node |
| 109 // at |id|. |
| 110 void UpdateScreenSpaceTransform(int id); |
| 111 |
| 112 private: |
| 113 // Returns true iff the node at |desc_id| is a descendant of the node at |
| 114 // |anc_id|. |
| 115 bool IsDescendant(int desc_id, int anc_id) const; |
| 116 |
| 117 // Returns the index of the lowest common ancestor of the nodes |a| and |b|. |
| 118 int LowestCommonAncestor(int a, int b) const; |
| 119 |
| 120 // Computes the combined transform between |source_id| and |dest_id| and |
| 121 // returns false if the inverse of a singular transform was used. These two |
| 122 // nodes must be on the same ancestor chain. |
| 123 bool CombineTransformsBetween(int source_id, |
| 124 int dest_id, |
| 125 gfx::Transform* transform) const; |
| 126 |
| 127 // Computes the combined inverse transform between |source_id| and |dest_id| |
| 128 // and returns false if the inverse of a singular transform was used. These |
| 129 // two nodes must be on the same ancestor chain. |
| 130 bool CombineInversesBetween(int source_id, |
| 131 int dest_id, |
| 132 gfx::Transform* transform) const; |
| 133 }; |
| 134 |
| 135 class CC_EXPORT ClipTree final : public PropertyTree<ClipNode> {}; |
| 136 |
| 137 } // namespace cc |
| 138 |
| 139 #endif // CC_TREES_PROPERTY_TREE_H_ |
OLD | NEW |