Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(110)

Side by Side Diff: services/gfx/compositor/graph/node_def.h

Issue 1774373002: Mozart: Implement hit testing. (Closed) Base URL: git@github.com:domokit/mojo.git@moz-4
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « services/gfx/compositor/compositor_engine.cc ('k') | services/gfx/compositor/graph/node_def.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 |point| is the hit tested point in the parent's coordinate space.
79 // The |global_to_parent_transform| is the accumulated transform from the
80 // global coordinate space to the parent's coordinate space.
81 // Adds hit information for the node to |hits|.
82 // Returns true if the search was terminated by an opaque hit.
83 bool HitTest(const SceneContent* content,
84 const Snapshot* snapshot,
85 const SkPoint& parent_point,
86 const SkMatrix& global_to_parent_transform,
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 bool HitTestInner(
107 const SceneContent* content,
108 const Snapshot* snapshot,
109 const SkPoint& local_point,
110 const SkMatrix& global_to_local_transform,
111 mojo::Array<mojo::gfx::composition::HitPtr>* hits) const;
112
88 private: 113 private:
114 bool HitTestSelf(const SceneContent* content,
115 const Snapshot* snapshot,
116 const SkPoint& local_point,
117 const SkMatrix& global_to_local_transform,
118 mojo::Array<mojo::gfx::composition::HitPtr>* hits) const;
119
89 uint32_t const node_id_; 120 uint32_t const node_id_;
90 mojo::TransformPtr const content_transform_; 121 mojo::TransformPtr const content_transform_;
91 mojo::RectPtr const content_clip_; 122 mojo::RectPtr const content_clip_;
123 mojo::gfx::composition::HitTestBehaviorPtr const hit_test_behavior_;
92 Combinator const combinator_; 124 Combinator const combinator_;
93 std::vector<uint32_t> const child_node_ids_; 125 std::vector<uint32_t> const child_node_ids_;
94 126
95 DISALLOW_COPY_AND_ASSIGN(NodeDef); 127 DISALLOW_COPY_AND_ASSIGN(NodeDef);
96 }; 128 };
97 129
98 // Represents a rectangle node. 130 // Represents a rectangle node.
99 // 131 //
100 // Draws a solid color filled rectangle node underneath its children. 132 // Draws a solid color filled rectangle node underneath its children.
101 class RectNodeDef : public NodeDef { 133 class RectNodeDef : public NodeDef {
102 public: 134 public:
103 RectNodeDef(uint32_t node_id, 135 RectNodeDef(uint32_t node_id,
104 mojo::TransformPtr content_transform, 136 mojo::TransformPtr content_transform,
105 mojo::RectPtr content_clip, 137 mojo::RectPtr content_clip,
138 mojo::gfx::composition::HitTestBehaviorPtr hit_test_behavior,
106 Combinator combinator, 139 Combinator combinator,
107 const std::vector<uint32_t>& child_node_ids, 140 const std::vector<uint32_t>& child_node_ids,
108 const mojo::Rect& content_rect, 141 const mojo::Rect& content_rect,
109 const mojo::gfx::composition::Color& color); 142 const mojo::gfx::composition::Color& color);
110 143
111 const mojo::Rect& content_rect() const { return content_rect_; } 144 const mojo::Rect& content_rect() const { return content_rect_; }
112 const mojo::gfx::composition::Color& color() const { return color_; } 145 const mojo::gfx::composition::Color& color() const { return color_; }
113 146
114 protected: 147 protected:
115 ~RectNodeDef() override; 148 ~RectNodeDef() override;
(...skipping 10 matching lines...) Expand all
126 }; 159 };
127 160
128 // Represents an image node. 161 // Represents an image node.
129 // 162 //
130 // Draws an image filled rectangle underneath its children. 163 // Draws an image filled rectangle underneath its children.
131 class ImageNodeDef : public NodeDef { 164 class ImageNodeDef : public NodeDef {
132 public: 165 public:
133 ImageNodeDef(uint32_t node_id, 166 ImageNodeDef(uint32_t node_id,
134 mojo::TransformPtr content_transform, 167 mojo::TransformPtr content_transform,
135 mojo::RectPtr content_clip, 168 mojo::RectPtr content_clip,
169 mojo::gfx::composition::HitTestBehaviorPtr hit_test_behavior,
136 Combinator combinator, 170 Combinator combinator,
137 const std::vector<uint32_t>& child_node_ids, 171 const std::vector<uint32_t>& child_node_ids,
138 const mojo::Rect& content_rect, 172 const mojo::Rect& content_rect,
139 mojo::RectPtr image_rect, 173 mojo::RectPtr image_rect,
140 uint32 image_resource_id, 174 uint32 image_resource_id,
141 mojo::gfx::composition::BlendPtr blend); 175 mojo::gfx::composition::BlendPtr blend);
142 176
143 const mojo::Rect& content_rect() const { return content_rect_; } 177 const mojo::Rect& content_rect() const { return content_rect_; }
144 const mojo::Rect* image_rect() const { return image_rect_.get(); } 178 const mojo::Rect* image_rect() const { return image_rect_.get(); }
145 uint32_t image_resource_id() const { return image_resource_id_; } 179 uint32_t image_resource_id() const { return image_resource_id_; }
(...skipping 18 matching lines...) Expand all
164 }; 198 };
165 199
166 // Represents a scene node. 200 // Represents a scene node.
167 // 201 //
168 // Draws an embedded scene underneath its children. 202 // Draws an embedded scene underneath its children.
169 class SceneNodeDef : public NodeDef { 203 class SceneNodeDef : public NodeDef {
170 public: 204 public:
171 SceneNodeDef(uint32_t node_id, 205 SceneNodeDef(uint32_t node_id,
172 mojo::TransformPtr content_transform, 206 mojo::TransformPtr content_transform,
173 mojo::RectPtr content_clip, 207 mojo::RectPtr content_clip,
208 mojo::gfx::composition::HitTestBehaviorPtr hit_test_behavior,
174 Combinator combinator, 209 Combinator combinator,
175 const std::vector<uint32_t>& child_node_ids, 210 const std::vector<uint32_t>& child_node_ids,
176 uint32_t scene_resource_id, 211 uint32_t scene_resource_id,
177 uint32_t scene_version); 212 uint32_t scene_version);
178 213
179 uint32_t scene_resource_id() const { return scene_resource_id_; } 214 uint32_t scene_resource_id() const { return scene_resource_id_; }
180 uint32_t scene_version() const { return scene_version_; } 215 uint32_t scene_version() const { return scene_version_; }
181 216
182 bool RecordContent(SceneContentBuilder* builder) const override; 217 bool RecordContent(SceneContentBuilder* builder) const override;
183 218
184 Snapshot::Disposition RecordSnapshot(const SceneContent* content, 219 Snapshot::Disposition RecordSnapshot(const SceneContent* content,
185 SnapshotBuilder* builder) const override; 220 SnapshotBuilder* builder) const override;
186 221
187 protected: 222 protected:
188 ~SceneNodeDef() override; 223 ~SceneNodeDef() override;
189 224
190 void RecordPictureInner(const SceneContent* content, 225 void RecordPictureInner(const SceneContent* content,
191 const Snapshot* snapshot, 226 const Snapshot* snapshot,
192 SkCanvas* canvas) const override; 227 SkCanvas* canvas) const override;
193 228
229 bool HitTestInner(
230 const SceneContent* content,
231 const Snapshot* snapshot,
232 const SkPoint& local_point,
233 const SkMatrix& global_to_local_transform,
234 mojo::Array<mojo::gfx::composition::HitPtr>* hits) const override;
235
194 private: 236 private:
195 uint32_t const scene_resource_id_; 237 uint32_t const scene_resource_id_;
196 uint32_t const scene_version_; 238 uint32_t const scene_version_;
197 239
198 DISALLOW_COPY_AND_ASSIGN(SceneNodeDef); 240 DISALLOW_COPY_AND_ASSIGN(SceneNodeDef);
199 }; 241 };
200 242
201 // Represents a layer node. 243 // Represents a layer node.
202 // 244 //
203 // Composites its children to a layer and applies a blending operation. 245 // Composites its children to a layer and applies a blending operation.
204 class LayerNodeDef : public NodeDef { 246 class LayerNodeDef : public NodeDef {
205 public: 247 public:
206 LayerNodeDef(uint32_t node_id, 248 LayerNodeDef(uint32_t node_id,
207 mojo::TransformPtr content_transform, 249 mojo::TransformPtr content_transform,
208 mojo::RectPtr content_clip, 250 mojo::RectPtr content_clip,
251 mojo::gfx::composition::HitTestBehaviorPtr hit_test_behavior,
209 Combinator combinator, 252 Combinator combinator,
210 const std::vector<uint32_t>& child_node_ids, 253 const std::vector<uint32_t>& child_node_ids,
211 const mojo::Size& size, 254 const mojo::Size& size,
212 mojo::gfx::composition::BlendPtr blend); 255 mojo::gfx::composition::BlendPtr blend);
213 256
214 const mojo::Size& size() const { return size_; } 257 const mojo::Size& size() const { return size_; }
215 const mojo::gfx::composition::Blend* blend() const { return blend_.get(); } 258 const mojo::gfx::composition::Blend* blend() const { return blend_.get(); }
216 259
217 protected: 260 protected:
218 ~LayerNodeDef() override; 261 ~LayerNodeDef() override;
219 262
220 void RecordPictureInner(const SceneContent* content, 263 void RecordPictureInner(const SceneContent* content,
221 const Snapshot* snapshot, 264 const Snapshot* snapshot,
222 SkCanvas* canvas) const override; 265 SkCanvas* canvas) const override;
223 266
224 private: 267 private:
225 mojo::Size const size_; 268 mojo::Size const size_;
226 mojo::gfx::composition::BlendPtr const blend_; 269 mojo::gfx::composition::BlendPtr const blend_;
227 270
228 DISALLOW_COPY_AND_ASSIGN(LayerNodeDef); 271 DISALLOW_COPY_AND_ASSIGN(LayerNodeDef);
229 }; 272 };
230 273
231 } // namespace compositor 274 } // namespace compositor
232 275
233 #endif // SERVICES_GFX_COMPOSITOR_GRAPH_NODE_DEF_H_ 276 #endif // SERVICES_GFX_COMPOSITOR_GRAPH_NODE_DEF_H_
OLDNEW
« no previous file with comments | « services/gfx/compositor/compositor_engine.cc ('k') | services/gfx/compositor/graph/node_def.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698