| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 SERVICES_GFX_COMPOSITOR_GRAPH_NODE_DEF_H_ | 5 #ifndef SERVICES_GFX_COMPOSITOR_GRAPH_NODES_H_ |
| 6 #define SERVICES_GFX_COMPOSITOR_GRAPH_NODE_DEF_H_ | 6 #define SERVICES_GFX_COMPOSITOR_GRAPH_NODES_H_ |
| 7 | 7 |
| 8 #include <iosfwd> | 8 #include <iosfwd> |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 14 #include "mojo/services/gfx/composition/interfaces/nodes.mojom.h" | 14 #include "mojo/services/gfx/composition/interfaces/nodes.mojom.h" |
| 15 #include "services/gfx/compositor/graph/snapshot.h" | 15 #include "services/gfx/compositor/graph/snapshot.h" |
| 16 | 16 |
| 17 class SkCanvas; | 17 class SkCanvas; |
| 18 struct SkPoint; | 18 struct SkPoint; |
| 19 class SkMatrix44; | 19 class SkMatrix44; |
| 20 | 20 |
| 21 namespace compositor { | 21 namespace compositor { |
| 22 | 22 |
| 23 class SceneContent; | 23 class SceneContent; |
| 24 class SceneContentBuilder; | 24 class SceneContentBuilder; |
| 25 class SceneDef; | 25 class SceneDef; |
| 26 class TransformPair; | 26 class TransformPair; |
| 27 | 27 |
| 28 // Represents a scene graph node. | 28 // Base class for nodes in a scene graph. |
| 29 // | 29 // |
| 30 // The base class mainly acts as a container for other nodes and does not | 30 // The base class mainly acts as a container for other nodes and does not |
| 31 // draw any content of its own. | 31 // draw any content of its own. |
| 32 // | 32 // |
| 33 // Instances of this class are immutable and reference counted so they may | 33 // Instances of this class are immutable and reference counted so they may |
| 34 // be shared by multiple versions of the same scene. | 34 // be shared by multiple versions of the same scene. |
| 35 class NodeDef : public base::RefCounted<NodeDef> { | 35 class Node : public base::RefCounted<Node> { |
| 36 public: | 36 public: |
| 37 using Combinator = mojo::gfx::composition::Node::Combinator; | 37 using Combinator = mojo::gfx::composition::Node::Combinator; |
| 38 | 38 |
| 39 NodeDef(uint32_t node_id, | 39 Node(uint32_t node_id, |
| 40 std::unique_ptr<TransformPair> content_transform, | 40 std::unique_ptr<TransformPair> content_transform, |
| 41 mojo::RectFPtr content_clip, | 41 mojo::RectFPtr content_clip, |
| 42 mojo::gfx::composition::HitTestBehaviorPtr hit_test_behavior, | 42 mojo::gfx::composition::HitTestBehaviorPtr hit_test_behavior, |
| 43 Combinator combinator, | 43 Combinator combinator, |
| 44 const std::vector<uint32_t>& child_node_ids); | 44 const std::vector<uint32_t>& child_node_ids); |
| 45 | 45 |
| 46 uint32_t node_id() const { return node_id_; } | 46 uint32_t node_id() const { return node_id_; } |
| 47 const TransformPair* content_transform() const { | 47 const TransformPair* content_transform() const { |
| 48 return content_transform_.get(); | 48 return content_transform_.get(); |
| 49 } | 49 } |
| 50 const mojo::gfx::composition::HitTestBehavior* hit_test_behavior() const { | 50 const mojo::gfx::composition::HitTestBehavior* hit_test_behavior() const { |
| 51 return hit_test_behavior_.get(); | 51 return hit_test_behavior_.get(); |
| 52 } | 52 } |
| 53 const mojo::RectF* content_clip() const { return content_clip_.get(); } | 53 const mojo::RectF* content_clip() const { return content_clip_.get(); } |
| 54 Combinator combinator() const { return combinator_; } | 54 Combinator combinator() const { return combinator_; } |
| (...skipping 27 matching lines...) Expand all Loading... |
| 82 // global coordinate space to the parent's coordinate space. | 82 // global coordinate space to the parent's coordinate space. |
| 83 // Adds hit information for the node to |hits|. | 83 // Adds hit information for the node to |hits|. |
| 84 // Returns true if the search was terminated by an opaque hit. | 84 // Returns true if the search was terminated by an opaque hit. |
| 85 bool HitTest(const SceneContent* content, | 85 bool HitTest(const SceneContent* content, |
| 86 const Snapshot* snapshot, | 86 const Snapshot* snapshot, |
| 87 const SkPoint& parent_point, | 87 const SkPoint& parent_point, |
| 88 const SkMatrix44& global_to_parent_transform, | 88 const SkMatrix44& global_to_parent_transform, |
| 89 mojo::Array<mojo::gfx::composition::HitPtr>* hits) const; | 89 mojo::Array<mojo::gfx::composition::HitPtr>* hits) const; |
| 90 | 90 |
| 91 protected: | 91 protected: |
| 92 friend class base::RefCounted<NodeDef>; | 92 friend class base::RefCounted<Node>; |
| 93 virtual ~NodeDef(); | 93 virtual ~Node(); |
| 94 | 94 |
| 95 // Applies a unary function to the children selected by the node's | 95 // Applies a unary function to the children selected by the node's |
| 96 // combinator rule during a snapshot. | 96 // combinator rule during a snapshot. |
| 97 // Stops when |Func| returns false. | 97 // Stops when |Func| returns false. |
| 98 // |Func| should have the signature |bool func(const NodeDef*)|. | 98 // |Func| should have the signature |bool func(const Node*)|. |
| 99 template <typename Func> | 99 template <typename Func> |
| 100 void TraverseSnapshottedChildren(const SceneContent* content, | 100 void TraverseSnapshottedChildren(const SceneContent* content, |
| 101 const Snapshot* snapshot, | 101 const Snapshot* snapshot, |
| 102 const Func& func) const; | 102 const Func& func) const; |
| 103 | 103 |
| 104 virtual void RecordPictureInner(const SceneContent* content, | 104 virtual void RecordPictureInner(const SceneContent* content, |
| 105 const Snapshot* snapshot, | 105 const Snapshot* snapshot, |
| 106 SkCanvas* canvas) const; | 106 SkCanvas* canvas) const; |
| 107 | 107 |
| 108 virtual bool HitTestInner( | 108 virtual bool HitTestInner( |
| (...skipping 10 matching lines...) Expand all Loading... |
| 119 const SkMatrix44& global_to_local_transform, | 119 const SkMatrix44& global_to_local_transform, |
| 120 mojo::Array<mojo::gfx::composition::HitPtr>* hits) const; | 120 mojo::Array<mojo::gfx::composition::HitPtr>* hits) const; |
| 121 | 121 |
| 122 uint32_t const node_id_; | 122 uint32_t const node_id_; |
| 123 std::unique_ptr<TransformPair> const content_transform_; | 123 std::unique_ptr<TransformPair> const content_transform_; |
| 124 mojo::RectFPtr const content_clip_; | 124 mojo::RectFPtr const content_clip_; |
| 125 mojo::gfx::composition::HitTestBehaviorPtr const hit_test_behavior_; | 125 mojo::gfx::composition::HitTestBehaviorPtr const hit_test_behavior_; |
| 126 Combinator const combinator_; | 126 Combinator const combinator_; |
| 127 std::vector<uint32_t> const child_node_ids_; | 127 std::vector<uint32_t> const child_node_ids_; |
| 128 | 128 |
| 129 DISALLOW_COPY_AND_ASSIGN(NodeDef); | 129 DISALLOW_COPY_AND_ASSIGN(Node); |
| 130 }; | 130 }; |
| 131 | 131 |
| 132 // Represents a rectangle node. | 132 // Represents a rectangle node. |
| 133 // | 133 // |
| 134 // Draws a solid color filled rectangle node underneath its children. | 134 // Draws a solid color filled rectangle node underneath its children. |
| 135 class RectNodeDef : public NodeDef { | 135 class RectNode : public Node { |
| 136 public: | 136 public: |
| 137 RectNodeDef(uint32_t node_id, | 137 RectNode(uint32_t node_id, |
| 138 std::unique_ptr<TransformPair> content_transform, | 138 std::unique_ptr<TransformPair> content_transform, |
| 139 mojo::RectFPtr content_clip, | 139 mojo::RectFPtr content_clip, |
| 140 mojo::gfx::composition::HitTestBehaviorPtr hit_test_behavior, | 140 mojo::gfx::composition::HitTestBehaviorPtr hit_test_behavior, |
| 141 Combinator combinator, | 141 Combinator combinator, |
| 142 const std::vector<uint32_t>& child_node_ids, | 142 const std::vector<uint32_t>& child_node_ids, |
| 143 const mojo::RectF& content_rect, | 143 const mojo::RectF& content_rect, |
| 144 const mojo::gfx::composition::Color& color); | 144 const mojo::gfx::composition::Color& color); |
| 145 | 145 |
| 146 const mojo::RectF& content_rect() const { return content_rect_; } | 146 const mojo::RectF& content_rect() const { return content_rect_; } |
| 147 const mojo::gfx::composition::Color& color() const { return color_; } | 147 const mojo::gfx::composition::Color& color() const { return color_; } |
| 148 | 148 |
| 149 protected: | 149 protected: |
| 150 ~RectNodeDef() override; | 150 ~RectNode() override; |
| 151 | 151 |
| 152 void RecordPictureInner(const SceneContent* content, | 152 void RecordPictureInner(const SceneContent* content, |
| 153 const Snapshot* snapshot, | 153 const Snapshot* snapshot, |
| 154 SkCanvas* canvas) const override; | 154 SkCanvas* canvas) const override; |
| 155 | 155 |
| 156 private: | 156 private: |
| 157 mojo::RectF const content_rect_; | 157 mojo::RectF const content_rect_; |
| 158 mojo::gfx::composition::Color const color_; | 158 mojo::gfx::composition::Color const color_; |
| 159 | 159 |
| 160 DISALLOW_COPY_AND_ASSIGN(RectNodeDef); | 160 DISALLOW_COPY_AND_ASSIGN(RectNode); |
| 161 }; | 161 }; |
| 162 | 162 |
| 163 // Represents an image node. | 163 // Represents an image node. |
| 164 // | 164 // |
| 165 // Draws an image filled rectangle underneath its children. | 165 // Draws an image filled rectangle underneath its children. |
| 166 class ImageNodeDef : public NodeDef { | 166 class ImageNode : public Node { |
| 167 public: | 167 public: |
| 168 ImageNodeDef(uint32_t node_id, | 168 ImageNode(uint32_t node_id, |
| 169 std::unique_ptr<TransformPair> content_transform, | 169 std::unique_ptr<TransformPair> content_transform, |
| 170 mojo::RectFPtr content_clip, | 170 mojo::RectFPtr content_clip, |
| 171 mojo::gfx::composition::HitTestBehaviorPtr hit_test_behavior, | 171 mojo::gfx::composition::HitTestBehaviorPtr hit_test_behavior, |
| 172 Combinator combinator, | 172 Combinator combinator, |
| 173 const std::vector<uint32_t>& child_node_ids, | 173 const std::vector<uint32_t>& child_node_ids, |
| 174 const mojo::RectF& content_rect, | 174 const mojo::RectF& content_rect, |
| 175 mojo::RectFPtr image_rect, | 175 mojo::RectFPtr image_rect, |
| 176 uint32 image_resource_id, | 176 uint32 image_resource_id, |
| 177 mojo::gfx::composition::BlendPtr blend); | 177 mojo::gfx::composition::BlendPtr blend); |
| 178 | 178 |
| 179 const mojo::RectF& content_rect() const { return content_rect_; } | 179 const mojo::RectF& content_rect() const { return content_rect_; } |
| 180 const mojo::RectF* image_rect() const { return image_rect_.get(); } | 180 const mojo::RectF* image_rect() const { return image_rect_.get(); } |
| 181 uint32_t image_resource_id() const { return image_resource_id_; } | 181 uint32_t image_resource_id() const { return image_resource_id_; } |
| 182 const mojo::gfx::composition::Blend* blend() const { return blend_.get(); } | 182 const mojo::gfx::composition::Blend* blend() const { return blend_.get(); } |
| 183 | 183 |
| 184 bool RecordContent(SceneContentBuilder* builder) const override; | 184 bool RecordContent(SceneContentBuilder* builder) const override; |
| 185 | 185 |
| 186 protected: | 186 protected: |
| 187 ~ImageNodeDef() override; | 187 ~ImageNode() override; |
| 188 | 188 |
| 189 void RecordPictureInner(const SceneContent* content, | 189 void RecordPictureInner(const SceneContent* content, |
| 190 const Snapshot* snapshot, | 190 const Snapshot* snapshot, |
| 191 SkCanvas* canvas) const override; | 191 SkCanvas* canvas) const override; |
| 192 | 192 |
| 193 private: | 193 private: |
| 194 mojo::RectF const content_rect_; | 194 mojo::RectF const content_rect_; |
| 195 mojo::RectFPtr const image_rect_; | 195 mojo::RectFPtr const image_rect_; |
| 196 uint32_t const image_resource_id_; | 196 uint32_t const image_resource_id_; |
| 197 mojo::gfx::composition::BlendPtr const blend_; | 197 mojo::gfx::composition::BlendPtr const blend_; |
| 198 | 198 |
| 199 DISALLOW_COPY_AND_ASSIGN(ImageNodeDef); | 199 DISALLOW_COPY_AND_ASSIGN(ImageNode); |
| 200 }; | 200 }; |
| 201 | 201 |
| 202 // Represents a scene node. | 202 // Represents a scene node. |
| 203 // | 203 // |
| 204 // Draws an embedded scene underneath its children. | 204 // Draws an embedded scene underneath its children. |
| 205 class SceneNodeDef : public NodeDef { | 205 class SceneNode : public Node { |
| 206 public: | 206 public: |
| 207 SceneNodeDef(uint32_t node_id, | 207 SceneNode(uint32_t node_id, |
| 208 std::unique_ptr<TransformPair> content_transform, | 208 std::unique_ptr<TransformPair> content_transform, |
| 209 mojo::RectFPtr content_clip, | 209 mojo::RectFPtr content_clip, |
| 210 mojo::gfx::composition::HitTestBehaviorPtr hit_test_behavior, | 210 mojo::gfx::composition::HitTestBehaviorPtr hit_test_behavior, |
| 211 Combinator combinator, | 211 Combinator combinator, |
| 212 const std::vector<uint32_t>& child_node_ids, | 212 const std::vector<uint32_t>& child_node_ids, |
| 213 uint32_t scene_resource_id, | 213 uint32_t scene_resource_id, |
| 214 uint32_t scene_version); | 214 uint32_t scene_version); |
| 215 | 215 |
| 216 uint32_t scene_resource_id() const { return scene_resource_id_; } | 216 uint32_t scene_resource_id() const { return scene_resource_id_; } |
| 217 uint32_t scene_version() const { return scene_version_; } | 217 uint32_t scene_version() const { return scene_version_; } |
| 218 | 218 |
| 219 bool RecordContent(SceneContentBuilder* builder) const override; | 219 bool RecordContent(SceneContentBuilder* builder) const override; |
| 220 | 220 |
| 221 Snapshot::Disposition RecordSnapshot(const SceneContent* content, | 221 Snapshot::Disposition RecordSnapshot(const SceneContent* content, |
| 222 SnapshotBuilder* builder) const override; | 222 SnapshotBuilder* builder) const override; |
| 223 | 223 |
| 224 protected: | 224 protected: |
| 225 ~SceneNodeDef() override; | 225 ~SceneNode() override; |
| 226 | 226 |
| 227 void RecordPictureInner(const SceneContent* content, | 227 void RecordPictureInner(const SceneContent* content, |
| 228 const Snapshot* snapshot, | 228 const Snapshot* snapshot, |
| 229 SkCanvas* canvas) const override; | 229 SkCanvas* canvas) const override; |
| 230 | 230 |
| 231 bool HitTestInner( | 231 bool HitTestInner( |
| 232 const SceneContent* content, | 232 const SceneContent* content, |
| 233 const Snapshot* snapshot, | 233 const Snapshot* snapshot, |
| 234 const SkPoint& local_point, | 234 const SkPoint& local_point, |
| 235 const SkMatrix44& global_to_local_transform, | 235 const SkMatrix44& global_to_local_transform, |
| 236 mojo::Array<mojo::gfx::composition::HitPtr>* hits) const override; | 236 mojo::Array<mojo::gfx::composition::HitPtr>* hits) const override; |
| 237 | 237 |
| 238 private: | 238 private: |
| 239 uint32_t const scene_resource_id_; | 239 uint32_t const scene_resource_id_; |
| 240 uint32_t const scene_version_; | 240 uint32_t const scene_version_; |
| 241 | 241 |
| 242 DISALLOW_COPY_AND_ASSIGN(SceneNodeDef); | 242 DISALLOW_COPY_AND_ASSIGN(SceneNode); |
| 243 }; | 243 }; |
| 244 | 244 |
| 245 // Represents a layer node. | 245 // Represents a layer node. |
| 246 // | 246 // |
| 247 // Composites its children to a layer and applies a blending operation. | 247 // Composites its children to a layer and applies a blending operation. |
| 248 class LayerNodeDef : public NodeDef { | 248 class LayerNode : public Node { |
| 249 public: | 249 public: |
| 250 LayerNodeDef(uint32_t node_id, | 250 LayerNode(uint32_t node_id, |
| 251 std::unique_ptr<TransformPair> content_transform, | 251 std::unique_ptr<TransformPair> content_transform, |
| 252 mojo::RectFPtr content_clip, | 252 mojo::RectFPtr content_clip, |
| 253 mojo::gfx::composition::HitTestBehaviorPtr hit_test_behavior, | 253 mojo::gfx::composition::HitTestBehaviorPtr hit_test_behavior, |
| 254 Combinator combinator, | 254 Combinator combinator, |
| 255 const std::vector<uint32_t>& child_node_ids, | 255 const std::vector<uint32_t>& child_node_ids, |
| 256 const mojo::RectF& layer_rect, | 256 const mojo::RectF& layer_rect, |
| 257 mojo::gfx::composition::BlendPtr blend); | 257 mojo::gfx::composition::BlendPtr blend); |
| 258 | 258 |
| 259 const mojo::RectF& layer_rect() const { return layer_rect_; } | 259 const mojo::RectF& layer_rect() const { return layer_rect_; } |
| 260 const mojo::gfx::composition::Blend* blend() const { return blend_.get(); } | 260 const mojo::gfx::composition::Blend* blend() const { return blend_.get(); } |
| 261 | 261 |
| 262 protected: | 262 protected: |
| 263 ~LayerNodeDef() override; | 263 ~LayerNode() override; |
| 264 | 264 |
| 265 void RecordPictureInner(const SceneContent* content, | 265 void RecordPictureInner(const SceneContent* content, |
| 266 const Snapshot* snapshot, | 266 const Snapshot* snapshot, |
| 267 SkCanvas* canvas) const override; | 267 SkCanvas* canvas) const override; |
| 268 | 268 |
| 269 private: | 269 private: |
| 270 mojo::RectF const layer_rect_; | 270 mojo::RectF const layer_rect_; |
| 271 mojo::gfx::composition::BlendPtr const blend_; | 271 mojo::gfx::composition::BlendPtr const blend_; |
| 272 | 272 |
| 273 DISALLOW_COPY_AND_ASSIGN(LayerNodeDef); | 273 DISALLOW_COPY_AND_ASSIGN(LayerNode); |
| 274 }; | 274 }; |
| 275 | 275 |
| 276 } // namespace compositor | 276 } // namespace compositor |
| 277 | 277 |
| 278 #endif // SERVICES_GFX_COMPOSITOR_GRAPH_NODE_DEF_H_ | 278 #endif // SERVICES_GFX_COMPOSITOR_GRAPH_NODES_H_ |
| OLD | NEW |