| 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_SCENE_DEF_H_ | 5 #ifndef SERVICES_GFX_COMPOSITOR_GRAPH_SCENE_DEF_H_ |
| 6 #define SERVICES_GFX_COMPOSITOR_GRAPH_SCENE_DEF_H_ | 6 #define SERVICES_GFX_COMPOSITOR_GRAPH_SCENE_DEF_H_ |
| 7 | 7 |
| 8 #include <iosfwd> | 8 #include <iosfwd> |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <string> | 10 #include <string> |
| 11 #include <unordered_map> | 11 #include <unordered_map> |
| 12 #include <vector> | 12 #include <vector> |
| 13 | 13 |
| 14 #include "base/callback.h" | 14 #include "base/callback.h" |
| 15 #include "base/macros.h" | 15 #include "base/macros.h" |
| 16 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
| 17 #include "base/memory/weak_ptr.h" | 17 #include "base/memory/weak_ptr.h" |
| 18 #include "mojo/services/gfx/composition/interfaces/scenes.mojom.h" | 18 #include "mojo/services/gfx/composition/interfaces/scenes.mojom.h" |
| 19 #include "services/gfx/compositor/graph/node_def.h" | 19 #include "services/gfx/compositor/graph/nodes.h" |
| 20 #include "services/gfx/compositor/graph/resource_def.h" | 20 #include "services/gfx/compositor/graph/resources.h" |
| 21 #include "services/gfx/compositor/graph/scene_label.h" | 21 #include "services/gfx/compositor/graph/scene_label.h" |
| 22 | 22 |
| 23 namespace compositor { | 23 namespace compositor { |
| 24 | 24 |
| 25 class SceneContent; | 25 class SceneContent; |
| 26 class SceneDef; | 26 class SceneDef; |
| 27 class SnapshotBuilder; | 27 class SnapshotBuilder; |
| 28 | 28 |
| 29 // Resolves a scene token to a scene definition. | 29 // Resolves a scene token to a scene definition. |
| 30 using SceneResolver = base::Callback<base::WeakPtr<SceneDef>( | 30 using SceneResolver = base::Callback<base::WeakPtr<SceneDef>( |
| 31 const mojo::gfx::composition::SceneToken&)>; | 31 const mojo::gfx::composition::SceneToken&)>; |
| 32 | 32 |
| 33 // Sends a scene unavailable message with the specified resource id. | 33 // Sends a scene unavailable message with the specified resource id. |
| 34 using SceneUnavailableSender = base::Callback<void(uint32_t)>; | 34 using SceneUnavailableSender = base::Callback<void(uint32_t)>; |
| 35 | 35 |
| 36 // Scene definition. | 36 // Scene definition. |
| 37 // Contains all of the resources and nodes of a published scene. | |
| 38 // | 37 // |
| 39 // TODO(jeffbrown): Consider renaming to |Scene| since there is now an | 38 // Contains the client-supplied content that makes up a scene in an |
| 40 // asymmetry between the stateful nature of this class compared with | 39 // incrementally updatable form. As part of preparing the scene for |
| 41 // |NodeDef| and |ResourceDef| which are immutable but similarly named. | 40 // presentation, the content is gathered up into an immutable |
| 41 // |SceneContent| object. |
| 42 class SceneDef { | 42 class SceneDef { |
| 43 public: | 43 public: |
| 44 // Outcome of a call to |Present|. | 44 // Outcome of a call to |Present|. |
| 45 enum class Disposition { | 45 enum class Disposition { |
| 46 kUnchanged, | 46 kUnchanged, |
| 47 kSucceeded, | 47 kSucceeded, |
| 48 kFailed, | 48 kFailed, |
| 49 }; | 49 }; |
| 50 | 50 |
| 51 SceneDef(const SceneLabel& label); | 51 SceneDef(const SceneLabel& label); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 80 const SceneUnavailableSender& unavailable_sender, | 80 const SceneUnavailableSender& unavailable_sender, |
| 81 std::ostream& err); | 81 std::ostream& err); |
| 82 | 82 |
| 83 // Unlinks references to another scene which has been unregistered. | 83 // Unlinks references to another scene which has been unregistered. |
| 84 // Causes |OnResourceUnavailable()| to be delivered to the scene for all | 84 // Causes |OnResourceUnavailable()| to be delivered to the scene for all |
| 85 // invalidated scene resources. Returns true if any changes were made. | 85 // invalidated scene resources. Returns true if any changes were made. |
| 86 bool UnlinkReferencedScene(SceneDef* scene, | 86 bool UnlinkReferencedScene(SceneDef* scene, |
| 87 const SceneUnavailableSender& unavailable_sender); | 87 const SceneUnavailableSender& unavailable_sender); |
| 88 | 88 |
| 89 // Finds resources or nodes in the current version, returns nullptr if absent. | 89 // Finds resources or nodes in the current version, returns nullptr if absent. |
| 90 const ResourceDef* FindResource(uint32_t resource_id) const; | 90 const Resource* FindResource(uint32_t resource_id) const; |
| 91 const NodeDef* FindNode(uint32_t node_id) const; | 91 const Node* FindNode(uint32_t node_id) const; |
| 92 const NodeDef* FindRootNode() const { | 92 const Node* FindRootNode() const { |
| 93 return FindNode(mojo::gfx::composition::kSceneRootNodeId); | 93 return FindNode(mojo::gfx::composition::kSceneRootNodeId); |
| 94 } | 94 } |
| 95 | 95 |
| 96 // Finds the most recently presented content of the specified version, | 96 // Finds the most recently presented content of the specified version, |
| 97 // returns nullptr if absent. | 97 // returns nullptr if absent. |
| 98 // If the version is |kSceneVersionNone| returns the current version. | 98 // If the version is |kSceneVersionNone| returns the current version. |
| 99 const SceneContent* FindContent(uint32_t version) const; | 99 const SceneContent* FindContent(uint32_t version) const; |
| 100 | 100 |
| 101 private: | 101 private: |
| 102 struct Publication { | 102 struct Publication { |
| 103 Publication(mojo::gfx::composition::SceneMetadataPtr metadata); | 103 Publication(mojo::gfx::composition::SceneMetadataPtr metadata); |
| 104 ~Publication(); | 104 ~Publication(); |
| 105 | 105 |
| 106 bool is_due(int64_t presentation_time) const { | 106 bool is_due(int64_t presentation_time) const { |
| 107 return metadata->presentation_time <= presentation_time; | 107 return metadata->presentation_time <= presentation_time; |
| 108 } | 108 } |
| 109 | 109 |
| 110 mojo::gfx::composition::SceneMetadataPtr metadata; | 110 mojo::gfx::composition::SceneMetadataPtr metadata; |
| 111 std::vector<mojo::gfx::composition::SceneUpdatePtr> updates; | 111 std::vector<mojo::gfx::composition::SceneUpdatePtr> updates; |
| 112 | 112 |
| 113 private: | 113 private: |
| 114 DISALLOW_COPY_AND_ASSIGN(Publication); | 114 DISALLOW_COPY_AND_ASSIGN(Publication); |
| 115 }; | 115 }; |
| 116 | 116 |
| 117 bool ApplyUpdate(mojo::gfx::composition::SceneUpdatePtr update, | 117 bool ApplyUpdate(mojo::gfx::composition::SceneUpdatePtr update, |
| 118 const SceneResolver& resolver, | 118 const SceneResolver& resolver, |
| 119 const SceneUnavailableSender& unavailable_sender, | 119 const SceneUnavailableSender& unavailable_sender, |
| 120 std::ostream& err); | 120 std::ostream& err); |
| 121 | 121 |
| 122 scoped_refptr<const ResourceDef> CreateResource( | 122 scoped_refptr<const Resource> CreateResource( |
| 123 uint32_t resource_id, | 123 uint32_t resource_id, |
| 124 mojo::gfx::composition::ResourcePtr resource_decl, | 124 mojo::gfx::composition::ResourcePtr resource_decl, |
| 125 const SceneResolver& resolver, | 125 const SceneResolver& resolver, |
| 126 const SceneUnavailableSender& unavailable_sender, | 126 const SceneUnavailableSender& unavailable_sender, |
| 127 std::ostream& err); | 127 std::ostream& err); |
| 128 scoped_refptr<const NodeDef> CreateNode( | 128 scoped_refptr<const Node> CreateNode( |
| 129 uint32_t node_id, | 129 uint32_t node_id, |
| 130 mojo::gfx::composition::NodePtr node_decl, | 130 mojo::gfx::composition::NodePtr node_decl, |
| 131 std::ostream& err); | 131 std::ostream& err); |
| 132 | 132 |
| 133 const SceneLabel label_; | 133 const SceneLabel label_; |
| 134 | 134 |
| 135 std::vector<mojo::gfx::composition::SceneUpdatePtr> pending_updates_; | 135 std::vector<mojo::gfx::composition::SceneUpdatePtr> pending_updates_; |
| 136 std::vector<std::unique_ptr<Publication>> pending_publications_; | 136 std::vector<std::unique_ptr<Publication>> pending_publications_; |
| 137 | 137 |
| 138 uint32_t version_ = mojo::gfx::composition::kSceneVersionNone; | 138 uint32_t version_ = mojo::gfx::composition::kSceneVersionNone; |
| 139 std::unordered_map<uint32_t, scoped_refptr<const ResourceDef>> resources_; | 139 std::unordered_map<uint32_t, scoped_refptr<const Resource>> resources_; |
| 140 std::unordered_map<uint32_t, scoped_refptr<const NodeDef>> nodes_; | 140 std::unordered_map<uint32_t, scoped_refptr<const Node>> nodes_; |
| 141 | 141 |
| 142 scoped_refptr<const SceneContent> content_; | 142 scoped_refptr<const SceneContent> content_; |
| 143 | 143 |
| 144 base::WeakPtrFactory<SceneDef> weak_factory_; | 144 base::WeakPtrFactory<SceneDef> weak_factory_; |
| 145 | 145 |
| 146 DISALLOW_COPY_AND_ASSIGN(SceneDef); | 146 DISALLOW_COPY_AND_ASSIGN(SceneDef); |
| 147 }; | 147 }; |
| 148 | 148 |
| 149 } // namespace compositor | 149 } // namespace compositor |
| 150 | 150 |
| 151 #endif // SERVICES_GFX_COMPOSITOR_GRAPH_SCENE_DEF_H_ | 151 #endif // SERVICES_GFX_COMPOSITOR_GRAPH_SCENE_DEF_H_ |
| OLD | NEW |