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_NODE_DEF_H_ |
6 #define SERVICES_GFX_COMPOSITOR_GRAPH_NODE_DEF_H_ | 6 #define SERVICES_GFX_COMPOSITOR_GRAPH_NODE_DEF_H_ |
7 | 7 |
8 #include <iosfwd> | 8 #include <iosfwd> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
13 #include "mojo/services/gfx/composition/interfaces/nodes.mojom.h" | 13 #include "mojo/services/gfx/composition/interfaces/nodes.mojom.h" |
14 #include "services/gfx/compositor/graph/snapshot.h" | 14 #include "services/gfx/compositor/graph/snapshot.h" |
15 | 15 |
16 class SkCanvas; | 16 class SkCanvas; |
17 struct SkPoint; | |
18 class SkMatrix; | |
17 | 19 |
18 namespace compositor { | 20 namespace compositor { |
19 | 21 |
20 class SceneContent; | 22 class SceneContent; |
21 class SceneContentBuilder; | 23 class SceneContentBuilder; |
22 class SceneDef; | 24 class SceneDef; |
23 | 25 |
24 // Represents a scene graph node. | 26 // Represents a scene graph node. |
25 // | 27 // |
26 // The base class mainly acts as a container for other nodes and does not | 28 // The base class mainly acts as a container for other nodes and does not |
27 // draw any content of its own. | 29 // draw any content of its own. |
28 // | 30 // |
29 // Instances of this class are immutable and reference counted so they may | 31 // Instances of this class are immutable and reference counted so they may |
30 // be shared by multiple versions of the same scene. | 32 // be shared by multiple versions of the same scene. |
31 class NodeDef : public base::RefCounted<NodeDef> { | 33 class NodeDef : public base::RefCounted<NodeDef> { |
32 public: | 34 public: |
33 using Combinator = mojo::gfx::composition::Node::Combinator; | 35 using Combinator = mojo::gfx::composition::Node::Combinator; |
34 | 36 |
35 NodeDef(uint32_t node_id, | 37 NodeDef(uint32_t node_id, |
36 mojo::TransformPtr content_transform, | 38 mojo::TransformPtr content_transform, |
37 mojo::RectPtr content_clip, | 39 mojo::RectPtr content_clip, |
40 mojo::gfx::composition::HitTestBehaviorPtr hit_test_behavior, | |
38 Combinator combinator, | 41 Combinator combinator, |
39 const std::vector<uint32_t>& child_node_ids); | 42 const std::vector<uint32_t>& child_node_ids); |
40 | 43 |
41 uint32_t node_id() const { return node_id_; } | 44 uint32_t node_id() const { return node_id_; } |
42 const mojo::Transform* content_transform() const { | 45 const mojo::Transform* content_transform() const { |
43 return content_transform_.get(); | 46 return content_transform_.get(); |
44 } | 47 } |
48 const mojo::gfx::composition::HitTestBehavior* hit_test_behavior() const { | |
49 return hit_test_behavior_.get(); | |
50 } | |
45 const mojo::Rect* content_clip() const { return content_clip_.get(); } | 51 const mojo::Rect* content_clip() const { return content_clip_.get(); } |
46 Combinator combinator() const { return combinator_; } | 52 Combinator combinator() const { return combinator_; } |
47 const std::vector<uint32_t>& child_node_ids() const { | 53 const std::vector<uint32_t>& child_node_ids() const { |
48 return child_node_ids_; | 54 return child_node_ids_; |
49 } | 55 } |
50 | 56 |
51 // Gets a descriptive label. | 57 // Gets a descriptive label. |
52 std::string FormattedLabel(const SceneContent* content) const; | 58 std::string FormattedLabel(const SceneContent* content) const; |
53 | 59 |
54 // Called by the scene content builder to traverse the node's dependencies | 60 // Called by the scene content builder to traverse the node's dependencies |
55 // recursively and ensure they are included in the scene's local content. | 61 // recursively and ensure they are included in the scene's local content. |
56 // Returns true if successful, false if the node contains linkage errors. | 62 // Returns true if successful, false if the node contains linkage errors. |
57 virtual bool RecordContent(SceneContentBuilder* builder) const; | 63 virtual bool RecordContent(SceneContentBuilder* builder) const; |
58 | 64 |
59 // Called by the snapshot builder to traverse the node's dependencies | 65 // Called by the snapshot builder to traverse the node's dependencies |
60 // recursively follow links into other scenes, evaluate whether the | 66 // recursively follow links into other scenes, evaluate whether the |
61 // node can be rendered, and record which path was taken for the purposes | 67 // node can be rendered, and record which path was taken for the purposes |
62 // of satisfying combinators. | 68 // of satisfying combinators. |
63 virtual Snapshot::Disposition RecordSnapshot(const SceneContent* content, | 69 virtual Snapshot::Disposition RecordSnapshot(const SceneContent* content, |
64 SnapshotBuilder* builder) const; | 70 SnapshotBuilder* builder) const; |
65 | 71 |
66 // Called to record drawing commands from a snapshot. | 72 // Called to record drawing commands from a snapshot. |
67 void RecordPicture(const SceneContent* content, | 73 void RecordPicture(const SceneContent* content, |
68 const Snapshot* snapshot, | 74 const Snapshot* snapshot, |
69 SkCanvas* canvas) const; | 75 SkCanvas* canvas) const; |
70 | 76 |
77 // Performs a hit test at the specified point. | |
78 // The |global_point| is the original hit tested point. | |
79 // The |parent_transform| is the accumulated transform from the parent's | |
80 // coordinate space to the global coordinate space. | |
81 // Adds hit information for the node to the array. | |
82 void HitTest(const SceneContent* content, | |
83 const Snapshot* snapshot, | |
84 const SkPoint& global_point, | |
85 const SkMatrix& parent_transform, | |
abarth
2016/03/09 04:02:48
Don't you want an SkMatrix44 here?
jeffbrown
2016/03/09 20:32:11
I didn't know that existed! ha! I'll make a note
| |
86 bool* opaque, | |
87 mojo::Array<mojo::gfx::composition::HitPtr>* hits) const; | |
88 | |
71 protected: | 89 protected: |
72 friend class base::RefCounted<NodeDef>; | 90 friend class base::RefCounted<NodeDef>; |
73 virtual ~NodeDef(); | 91 virtual ~NodeDef(); |
74 | 92 |
75 // Applies a unary function to the children selected by the node's | 93 // Applies a unary function to the children selected by the node's |
76 // combinator rule during a snapshot. | 94 // combinator rule during a snapshot. |
77 // Stops when |Func| returns false. | 95 // Stops when |Func| returns false. |
78 // |Func| should have the signature |bool func(const NodeDef*)|. | 96 // |Func| should have the signature |bool func(const NodeDef*)|. |
79 template <typename Func> | 97 template <typename Func> |
80 void TraverseSnapshottedChildren(const SceneContent* content, | 98 void TraverseSnapshottedChildren(const SceneContent* content, |
81 const Snapshot* snapshot, | 99 const Snapshot* snapshot, |
82 const Func& func) const; | 100 const Func& func) const; |
83 | 101 |
84 virtual void RecordPictureInner(const SceneContent* content, | 102 virtual void RecordPictureInner(const SceneContent* content, |
85 const Snapshot* snapshot, | 103 const Snapshot* snapshot, |
86 SkCanvas* canvas) const; | 104 SkCanvas* canvas) const; |
87 | 105 |
106 virtual void HitTestInner( | |
107 const SceneContent* content, | |
108 const Snapshot* snapshot, | |
109 const SkPoint& global_point, | |
110 const SkMatrix& node_transform, | |
111 bool* opaque, | |
112 mojo::Array<mojo::gfx::composition::HitPtr>* hits) const; | |
113 | |
88 private: | 114 private: |
89 uint32_t const node_id_; | 115 uint32_t const node_id_; |
90 mojo::TransformPtr const content_transform_; | 116 mojo::TransformPtr const content_transform_; |
91 mojo::RectPtr const content_clip_; | 117 mojo::RectPtr const content_clip_; |
118 mojo::gfx::composition::HitTestBehaviorPtr const hit_test_behavior_; | |
92 Combinator const combinator_; | 119 Combinator const combinator_; |
93 std::vector<uint32_t> const child_node_ids_; | 120 std::vector<uint32_t> const child_node_ids_; |
94 | 121 |
95 DISALLOW_COPY_AND_ASSIGN(NodeDef); | 122 DISALLOW_COPY_AND_ASSIGN(NodeDef); |
96 }; | 123 }; |
97 | 124 |
98 // Represents a rectangle node. | 125 // Represents a rectangle node. |
99 // | 126 // |
100 // Draws a solid color filled rectangle node underneath its children. | 127 // Draws a solid color filled rectangle node underneath its children. |
101 class RectNodeDef : public NodeDef { | 128 class RectNodeDef : public NodeDef { |
102 public: | 129 public: |
103 RectNodeDef(uint32_t node_id, | 130 RectNodeDef(uint32_t node_id, |
104 mojo::TransformPtr content_transform, | 131 mojo::TransformPtr content_transform, |
105 mojo::RectPtr content_clip, | 132 mojo::RectPtr content_clip, |
133 mojo::gfx::composition::HitTestBehaviorPtr hit_test_behavior, | |
106 Combinator combinator, | 134 Combinator combinator, |
107 const std::vector<uint32_t>& child_node_ids, | 135 const std::vector<uint32_t>& child_node_ids, |
108 const mojo::Rect& content_rect, | 136 const mojo::Rect& content_rect, |
109 const mojo::gfx::composition::Color& color); | 137 const mojo::gfx::composition::Color& color); |
110 | 138 |
111 const mojo::Rect& content_rect() const { return content_rect_; } | 139 const mojo::Rect& content_rect() const { return content_rect_; } |
112 const mojo::gfx::composition::Color& color() const { return color_; } | 140 const mojo::gfx::composition::Color& color() const { return color_; } |
113 | 141 |
114 protected: | 142 protected: |
115 ~RectNodeDef() override; | 143 ~RectNodeDef() override; |
(...skipping 10 matching lines...) Expand all Loading... | |
126 }; | 154 }; |
127 | 155 |
128 // Represents an image node. | 156 // Represents an image node. |
129 // | 157 // |
130 // Draws an image filled rectangle underneath its children. | 158 // Draws an image filled rectangle underneath its children. |
131 class ImageNodeDef : public NodeDef { | 159 class ImageNodeDef : public NodeDef { |
132 public: | 160 public: |
133 ImageNodeDef(uint32_t node_id, | 161 ImageNodeDef(uint32_t node_id, |
134 mojo::TransformPtr content_transform, | 162 mojo::TransformPtr content_transform, |
135 mojo::RectPtr content_clip, | 163 mojo::RectPtr content_clip, |
164 mojo::gfx::composition::HitTestBehaviorPtr hit_test_behavior, | |
136 Combinator combinator, | 165 Combinator combinator, |
137 const std::vector<uint32_t>& child_node_ids, | 166 const std::vector<uint32_t>& child_node_ids, |
138 const mojo::Rect& content_rect, | 167 const mojo::Rect& content_rect, |
139 mojo::RectPtr image_rect, | 168 mojo::RectPtr image_rect, |
140 uint32 image_resource_id, | 169 uint32 image_resource_id, |
141 mojo::gfx::composition::BlendPtr blend); | 170 mojo::gfx::composition::BlendPtr blend); |
142 | 171 |
143 const mojo::Rect& content_rect() const { return content_rect_; } | 172 const mojo::Rect& content_rect() const { return content_rect_; } |
144 const mojo::Rect* image_rect() const { return image_rect_.get(); } | 173 const mojo::Rect* image_rect() const { return image_rect_.get(); } |
145 uint32_t image_resource_id() const { return image_resource_id_; } | 174 uint32_t image_resource_id() const { return image_resource_id_; } |
(...skipping 18 matching lines...) Expand all Loading... | |
164 }; | 193 }; |
165 | 194 |
166 // Represents a scene node. | 195 // Represents a scene node. |
167 // | 196 // |
168 // Draws an embedded scene underneath its children. | 197 // Draws an embedded scene underneath its children. |
169 class SceneNodeDef : public NodeDef { | 198 class SceneNodeDef : public NodeDef { |
170 public: | 199 public: |
171 SceneNodeDef(uint32_t node_id, | 200 SceneNodeDef(uint32_t node_id, |
172 mojo::TransformPtr content_transform, | 201 mojo::TransformPtr content_transform, |
173 mojo::RectPtr content_clip, | 202 mojo::RectPtr content_clip, |
203 mojo::gfx::composition::HitTestBehaviorPtr hit_test_behavior, | |
174 Combinator combinator, | 204 Combinator combinator, |
175 const std::vector<uint32_t>& child_node_ids, | 205 const std::vector<uint32_t>& child_node_ids, |
176 uint32_t scene_resource_id, | 206 uint32_t scene_resource_id, |
177 uint32_t scene_version); | 207 uint32_t scene_version); |
178 | 208 |
179 uint32_t scene_resource_id() const { return scene_resource_id_; } | 209 uint32_t scene_resource_id() const { return scene_resource_id_; } |
180 uint32_t scene_version() const { return scene_version_; } | 210 uint32_t scene_version() const { return scene_version_; } |
181 | 211 |
182 bool RecordContent(SceneContentBuilder* builder) const override; | 212 bool RecordContent(SceneContentBuilder* builder) const override; |
183 | 213 |
184 Snapshot::Disposition RecordSnapshot(const SceneContent* content, | 214 Snapshot::Disposition RecordSnapshot(const SceneContent* content, |
185 SnapshotBuilder* builder) const override; | 215 SnapshotBuilder* builder) const override; |
186 | 216 |
187 protected: | 217 protected: |
188 ~SceneNodeDef() override; | 218 ~SceneNodeDef() override; |
189 | 219 |
190 void RecordPictureInner(const SceneContent* content, | 220 void RecordPictureInner(const SceneContent* content, |
191 const Snapshot* snapshot, | 221 const Snapshot* snapshot, |
192 SkCanvas* canvas) const override; | 222 SkCanvas* canvas) const override; |
193 | 223 |
224 void HitTestInner( | |
225 const SceneContent* content, | |
226 const Snapshot* snapshot, | |
227 const SkPoint& global_point, | |
228 const SkMatrix& node_transform, | |
229 bool* opaque, | |
230 mojo::Array<mojo::gfx::composition::HitPtr>* hits) const override; | |
231 | |
194 private: | 232 private: |
195 uint32_t const scene_resource_id_; | 233 uint32_t const scene_resource_id_; |
196 uint32_t const scene_version_; | 234 uint32_t const scene_version_; |
197 | 235 |
198 DISALLOW_COPY_AND_ASSIGN(SceneNodeDef); | 236 DISALLOW_COPY_AND_ASSIGN(SceneNodeDef); |
199 }; | 237 }; |
200 | 238 |
201 // Represents a layer node. | 239 // Represents a layer node. |
202 // | 240 // |
203 // Composites its children to a layer and applies a blending operation. | 241 // Composites its children to a layer and applies a blending operation. |
204 class LayerNodeDef : public NodeDef { | 242 class LayerNodeDef : public NodeDef { |
205 public: | 243 public: |
206 LayerNodeDef(uint32_t node_id, | 244 LayerNodeDef(uint32_t node_id, |
207 mojo::TransformPtr content_transform, | 245 mojo::TransformPtr content_transform, |
208 mojo::RectPtr content_clip, | 246 mojo::RectPtr content_clip, |
247 mojo::gfx::composition::HitTestBehaviorPtr hit_test_behavior, | |
209 Combinator combinator, | 248 Combinator combinator, |
210 const std::vector<uint32_t>& child_node_ids, | 249 const std::vector<uint32_t>& child_node_ids, |
211 const mojo::Size& size, | 250 const mojo::Size& size, |
212 mojo::gfx::composition::BlendPtr blend); | 251 mojo::gfx::composition::BlendPtr blend); |
213 | 252 |
214 const mojo::Size& size() const { return size_; } | 253 const mojo::Size& size() const { return size_; } |
215 const mojo::gfx::composition::Blend* blend() const { return blend_.get(); } | 254 const mojo::gfx::composition::Blend* blend() const { return blend_.get(); } |
216 | 255 |
217 protected: | 256 protected: |
218 ~LayerNodeDef() override; | 257 ~LayerNodeDef() override; |
219 | 258 |
220 void RecordPictureInner(const SceneContent* content, | 259 void RecordPictureInner(const SceneContent* content, |
221 const Snapshot* snapshot, | 260 const Snapshot* snapshot, |
222 SkCanvas* canvas) const override; | 261 SkCanvas* canvas) const override; |
223 | 262 |
224 private: | 263 private: |
225 mojo::Size const size_; | 264 mojo::Size const size_; |
226 mojo::gfx::composition::BlendPtr const blend_; | 265 mojo::gfx::composition::BlendPtr const blend_; |
227 | 266 |
228 DISALLOW_COPY_AND_ASSIGN(LayerNodeDef); | 267 DISALLOW_COPY_AND_ASSIGN(LayerNodeDef); |
229 }; | 268 }; |
230 | 269 |
231 } // namespace compositor | 270 } // namespace compositor |
232 | 271 |
233 #endif // SERVICES_GFX_COMPOSITOR_GRAPH_NODE_DEF_H_ | 272 #endif // SERVICES_GFX_COMPOSITOR_GRAPH_NODE_DEF_H_ |
OLD | NEW |