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 <string> |
| 11 #include <vector> |
| 12 |
| 13 #include "base/callback.h" |
| 14 #include "base/macros.h" |
| 15 #include "mojo/services/gfx/composition/interfaces/nodes.mojom.h" |
| 16 #include "services/gfx/compositor/graph/resource_def.h" |
| 17 |
| 18 namespace compositor { |
| 19 |
| 20 class RenderImage; |
| 21 class RenderLayerBuilder; |
| 22 class SceneDef; |
| 23 class SnapshotBuilder; |
| 24 class NodeOp; |
| 25 |
| 26 // Scene graph node definition. |
| 27 class NodeDef { |
| 28 public: |
| 29 using Combinator = mojo::gfx::composition::Node::Combinator; |
| 30 |
| 31 NodeDef(uint32_t node_id, |
| 32 mojo::TransformPtr content_transform, |
| 33 mojo::RectPtr content_clip, |
| 34 uint32_t hit_id, |
| 35 Combinator combinator, |
| 36 const std::vector<uint32_t>& child_node_ids, |
| 37 NodeOp* op); |
| 38 ~NodeDef(); |
| 39 |
| 40 uint32_t node_id() { return node_id_; } |
| 41 const mojo::Transform* content_transform() { |
| 42 return content_transform_.get(); |
| 43 } |
| 44 const mojo::Rect* content_clip() { return content_clip_.get(); } |
| 45 uint32_t hit_id() { return hit_id_; } |
| 46 Combinator combinator() { return combinator_; } |
| 47 const std::vector<uint32_t>& child_node_ids() { return child_node_ids_; } |
| 48 NodeOp* op() { return op_.get(); } |
| 49 |
| 50 std::string FormattedLabel(SceneDef* scene); |
| 51 |
| 52 // Updated by |Validate()|. |
| 53 const std::vector<NodeDef*>& child_nodes() { return child_nodes_; } |
| 54 |
| 55 // Validates and prepares the object for rendering. |
| 56 // Returns true if successful, false if errors were reported. |
| 57 bool Validate(SceneDef* scene, std::ostream& err); |
| 58 |
| 59 // Generates a snapshot of the node into the specified builder. |
| 60 // Returns true if successful, false if the node is blocked from rendering. |
| 61 bool Snapshot(SnapshotBuilder* snapshot_builder, |
| 62 RenderLayerBuilder* layer_builder, |
| 63 SceneDef* scene); |
| 64 |
| 65 // Generates a snapshot of the node's children into the specified builder. |
| 66 // Returns true if successful, false if the children are blocked from |
| 67 // rendering. |
| 68 bool SnapshotChildren(SnapshotBuilder* snapshot_builder, |
| 69 RenderLayerBuilder* layer_builder, |
| 70 SceneDef* scene); |
| 71 |
| 72 private: |
| 73 bool SnapshotInner(SnapshotBuilder* snapshot_builder, |
| 74 RenderLayerBuilder* layer_builder, |
| 75 SceneDef* scene); |
| 76 |
| 77 uint32_t node_id_; |
| 78 mojo::TransformPtr const content_transform_; |
| 79 mojo::RectPtr const content_clip_; |
| 80 uint32_t const hit_id_; |
| 81 Combinator const combinator_; |
| 82 std::vector<uint32_t> const child_node_ids_; |
| 83 std::unique_ptr<NodeOp> const op_; |
| 84 |
| 85 std::vector<NodeDef*> child_nodes_; |
| 86 |
| 87 // Used to detect cycles during a snapshot operation. |
| 88 // This is safe because the object will only be used by a single thread. |
| 89 bool visited_ = false; |
| 90 |
| 91 DISALLOW_COPY_AND_ASSIGN(NodeDef); |
| 92 }; |
| 93 |
| 94 // Abstract scene graph node operation. |
| 95 class NodeOp { |
| 96 public: |
| 97 NodeOp() = default; |
| 98 virtual ~NodeOp() = default; |
| 99 |
| 100 // Validates and prepares the object for rendering. |
| 101 // Returns true if successful, false if errors were reported. |
| 102 virtual bool Validate(SceneDef* scene, NodeDef* node, std::ostream& err); |
| 103 |
| 104 // Generates a snapshot of the node operation into the specified builder. |
| 105 // This method is responsible for calling |SnapshotChildren| to process |
| 106 // the children of the node. Returns true if successful, false if the node |
| 107 // is blocked from rendering. |
| 108 virtual bool Snapshot(SnapshotBuilder* snapshot_builder, |
| 109 RenderLayerBuilder* layer_builder, |
| 110 SceneDef* scene, |
| 111 NodeDef* node) = 0; |
| 112 |
| 113 private: |
| 114 DISALLOW_COPY_AND_ASSIGN(NodeOp); |
| 115 }; |
| 116 |
| 117 // A solid color filled rectangle node definition. |
| 118 class RectNodeOp : public NodeOp { |
| 119 public: |
| 120 RectNodeOp(const mojo::Rect& content_rect, |
| 121 const mojo::gfx::composition::Color& color); |
| 122 ~RectNodeOp() override; |
| 123 |
| 124 const mojo::Rect& content_rect() { return content_rect_; } |
| 125 const mojo::gfx::composition::Color& color() { return color_; } |
| 126 |
| 127 bool Snapshot(SnapshotBuilder* snapshot_builder, |
| 128 RenderLayerBuilder* layer_builder, |
| 129 SceneDef* scene, |
| 130 NodeDef* node) override; |
| 131 |
| 132 private: |
| 133 mojo::Rect content_rect_; |
| 134 mojo::gfx::composition::Color color_; |
| 135 |
| 136 DISALLOW_COPY_AND_ASSIGN(RectNodeOp); |
| 137 }; |
| 138 |
| 139 // An image filled rectangle node definition. |
| 140 class ImageNodeOp : public NodeOp { |
| 141 public: |
| 142 ImageNodeOp(const mojo::Rect& content_rect, |
| 143 mojo::RectPtr image_rect, |
| 144 uint32 image_resource_id, |
| 145 mojo::gfx::composition::BlendPtr blend); |
| 146 ~ImageNodeOp() override; |
| 147 |
| 148 const mojo::Rect& content_rect() { return content_rect_; } |
| 149 mojo::Rect* image_rect() { return image_rect_.get(); } |
| 150 uint32_t image_resource_id() { return image_resource_id_; } |
| 151 mojo::gfx::composition::Blend* blend() { return blend_.get(); } |
| 152 |
| 153 // Updated by |Validate()|. |
| 154 ImageResourceDef* image_resource() { return image_resource_; } |
| 155 |
| 156 bool Validate(SceneDef* scene, NodeDef* node, std::ostream& err) override; |
| 157 |
| 158 bool Snapshot(SnapshotBuilder* snapshot_builder, |
| 159 RenderLayerBuilder* layer_builder, |
| 160 SceneDef* scene, |
| 161 NodeDef* node) override; |
| 162 |
| 163 private: |
| 164 mojo::Rect const content_rect_; |
| 165 mojo::RectPtr const image_rect_; |
| 166 uint32_t const image_resource_id_; |
| 167 mojo::gfx::composition::BlendPtr const blend_; |
| 168 |
| 169 ImageResourceDef* image_resource_ = nullptr; |
| 170 |
| 171 DISALLOW_COPY_AND_ASSIGN(ImageNodeOp); |
| 172 }; |
| 173 |
| 174 // An embedded scene node definition. |
| 175 class SceneNodeOp : public NodeOp { |
| 176 public: |
| 177 SceneNodeOp(uint32_t scene_resource_id, uint32_t scene_version); |
| 178 ~SceneNodeOp() override; |
| 179 |
| 180 uint32_t scene_resource_id() { return scene_resource_id_; } |
| 181 uint32_t scene_version() { return scene_version_; } |
| 182 |
| 183 // Updated by |Validate()|. |
| 184 SceneResourceDef* scene_resource() { return scene_resource_; } |
| 185 |
| 186 bool Validate(SceneDef* scene, NodeDef* node, std::ostream& err) override; |
| 187 |
| 188 bool Snapshot(SnapshotBuilder* snapshot_builder, |
| 189 RenderLayerBuilder* layer_builder, |
| 190 SceneDef* scene, |
| 191 NodeDef* node) override; |
| 192 |
| 193 private: |
| 194 uint32_t const scene_resource_id_; |
| 195 uint32_t const scene_version_; |
| 196 |
| 197 SceneResourceDef* scene_resource_ = nullptr; |
| 198 |
| 199 DISALLOW_COPY_AND_ASSIGN(SceneNodeOp); |
| 200 }; |
| 201 |
| 202 // A composited layer node definition. |
| 203 class LayerNodeOp : public NodeOp { |
| 204 public: |
| 205 LayerNodeOp(const mojo::Size& size, mojo::gfx::composition::BlendPtr blend); |
| 206 ~LayerNodeOp() override; |
| 207 |
| 208 const mojo::Size& size() { return size_; } |
| 209 mojo::gfx::composition::Blend* blend() { return blend_.get(); } |
| 210 |
| 211 bool Snapshot(SnapshotBuilder* snapshot_builder, |
| 212 RenderLayerBuilder* layer_builder, |
| 213 SceneDef* scene, |
| 214 NodeDef* node) override; |
| 215 |
| 216 private: |
| 217 mojo::Size const size_; |
| 218 mojo::gfx::composition::BlendPtr const blend_; |
| 219 |
| 220 DISALLOW_COPY_AND_ASSIGN(LayerNodeOp); |
| 221 }; |
| 222 |
| 223 } // namespace compositor |
| 224 |
| 225 #endif // SERVICES_GFX_COMPOSITOR_GRAPH_NODE_DEF_H_ |
OLD | NEW |