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