OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 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_SCENE_CONTENT_H_ |
| 6 #define SERVICES_GFX_COMPOSITOR_GRAPH_SCENE_CONTENT_H_ |
| 7 |
| 8 #include <iosfwd> |
| 9 #include <unordered_map> |
| 10 |
| 11 #include "base/macros.h" |
| 12 #include "base/memory/ref_counted.h" |
| 13 #include "base/memory/weak_ptr.h" |
| 14 #include "mojo/services/gfx/composition/interfaces/scenes.mojom.h" |
| 15 #include "services/gfx/compositor/graph/node_def.h" |
| 16 #include "services/gfx/compositor/graph/resource_def.h" |
| 17 #include "services/gfx/compositor/graph/scene_label.h" |
| 18 |
| 19 namespace compositor { |
| 20 |
| 21 class SceneContentBuilder; |
| 22 class SceneDef; |
| 23 |
| 24 // Represents the content of a particular published version of a scene. |
| 25 // |
| 26 // Holds a resource and node table which describes the content of a |
| 27 // scene as it was when a particular version was published. Only the |
| 28 // internal state of the scene is described; links to other scenes are |
| 29 // not resolved at this level. |
| 30 // |
| 31 // Once fully constructed, instances of this class are immutable and |
| 32 // reference counted so they may be bound to scene references in other scenes. |
| 33 // |
| 34 // TODO(jeffbrown): To improve efficiency, we could replace the hash tables |
| 35 // with a vector of internally linked graph edges. This is relatively easy |
| 36 // since the traversal order is well-known and we could even build some kind |
| 37 // of hierarchical iterator to walk the graph starting from the root. |
| 38 class SceneContent : public base::RefCounted<SceneContent> { |
| 39 public: |
| 40 // Gets the scene label. |
| 41 const SceneLabel& label() const { return label_; } |
| 42 std::string FormattedLabel() const { |
| 43 return label_.FormattedLabelForVersion(version_); |
| 44 } |
| 45 std::string FormattedLabelForNode(uint32_t node_id) const { |
| 46 return label_.FormattedLabelForNode(version_, node_id); |
| 47 } |
| 48 |
| 49 // Gets the version of the scene represented by this object. |
| 50 uint32_t version() const { return version_; } |
| 51 |
| 52 // Gets the requested resource, never null because it must be present. |
| 53 const ResourceDef* GetResource(uint32_t resource_id, |
| 54 ResourceDef::Type resource_type) const; |
| 55 |
| 56 // Gets the requested node, never null because it must be present. |
| 57 const NodeDef* GetNode(uint32_t node_id) const; |
| 58 |
| 59 // Gets the root node if it exists, otherwise returns nullptr. |
| 60 const NodeDef* GetRootNodeIfExists() const; |
| 61 |
| 62 private: |
| 63 friend class base::RefCounted<SceneContent>; |
| 64 friend class SceneContentBuilder; |
| 65 SceneContent(const SceneLabel& label, |
| 66 uint32_t version, |
| 67 size_t max_resources, |
| 68 size_t max_nodes); |
| 69 ~SceneContent(); |
| 70 |
| 71 const SceneLabel label_; |
| 72 const uint32_t version_; |
| 73 std::unordered_map<uint32_t, scoped_refptr<const ResourceDef>> resources_; |
| 74 std::unordered_map<uint32_t, scoped_refptr<const NodeDef>> nodes_; |
| 75 |
| 76 DISALLOW_COPY_AND_ASSIGN(SceneContent); |
| 77 }; |
| 78 |
| 79 // Builds a table of all of the nodes and resources that make up the |
| 80 // content of a particular version of a scene. |
| 81 class SceneContentBuilder { |
| 82 public: |
| 83 SceneContentBuilder(const SceneDef* scene, |
| 84 uint32_t version, |
| 85 std::ostream& err, |
| 86 size_t max_resources, |
| 87 size_t max_nodes); |
| 88 ~SceneContentBuilder(); |
| 89 |
| 90 // Stream for reporting validation error messages. |
| 91 std::ostream& err() { return err_; } |
| 92 |
| 93 // Ensures the requested resource is part of the retained scene graph and |
| 94 // returns a reference to it, or nullptr if an error occurred. |
| 95 const ResourceDef* RequireResource(uint32_t resource_id, |
| 96 ResourceDef::Type resource_type, |
| 97 uint32_t referrer_node_id); |
| 98 |
| 99 // Ensures the requested node is part of the retained scene graph and |
| 100 // returns a reference to it, or nullptr if an error occurred. |
| 101 const NodeDef* RequireNode(uint32_t node_id, uint32_t referrer_node_id); |
| 102 |
| 103 // Builds the content graph. |
| 104 // Returns nullptr if an error occurred. |
| 105 scoped_refptr<const SceneContent> Build(); |
| 106 |
| 107 private: |
| 108 bool AddNode(const NodeDef* node); |
| 109 |
| 110 scoped_refptr<SceneContent> content_; |
| 111 const SceneDef* scene_; |
| 112 std::ostream& err_; |
| 113 }; |
| 114 |
| 115 } // namespace compositor |
| 116 |
| 117 #endif // SERVICES_GFX_COMPOSITOR_GRAPH_SCENE_CONTENT_H_ |
OLD | NEW |