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