| 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" | |
| 18 #include "mojo/services/gfx/composition/interfaces/scenes.mojom.h" | 17 #include "mojo/services/gfx/composition/interfaces/scenes.mojom.h" |
| 19 #include "services/gfx/compositor/graph/nodes.h" | 18 #include "services/gfx/compositor/graph/nodes.h" |
| 20 #include "services/gfx/compositor/graph/resources.h" | 19 #include "services/gfx/compositor/graph/resources.h" |
| 20 #include "services/gfx/compositor/graph/scene_content.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; | |
| 26 class SceneDef; | 25 class SceneDef; |
| 27 class SnapshotBuilder; | 26 class Universe; |
| 28 | 27 |
| 29 // Resolves a scene token to a scene definition. | 28 // Determines whether a scene is registered. |
| 30 using SceneResolver = base::Callback<base::WeakPtr<SceneDef>( | 29 using SceneResolver = |
| 31 const mojo::gfx::composition::SceneToken&)>; | 30 base::Callback<bool(const mojo::gfx::composition::SceneToken&)>; |
| 32 | 31 |
| 33 // Sends a scene unavailable message with the specified resource id. | 32 // Sends a scene unavailable message with the specified resource id. |
| 34 using SceneUnavailableSender = base::Callback<void(uint32_t)>; | 33 using SceneUnavailableSender = base::Callback<void(uint32_t)>; |
| 35 | 34 |
| 36 // Scene definition. | 35 // Scene definition. |
| 37 // | 36 // |
| 38 // Contains the client-supplied content that makes up a scene in an | 37 // Contains the client-supplied content that makes up a scene in an |
| 39 // incrementally updatable form. As part of preparing the scene for | 38 // incrementally updatable form. As part of preparing the scene for |
| 40 // presentation, the content is gathered up into an immutable | 39 // presentation, the content is gathered up into an immutable |
| 41 // |SceneContent| object. | 40 // |SceneContent| object. |
| 42 class SceneDef { | 41 class SceneDef { |
| 43 public: | 42 public: |
| 44 // Outcome of a call to |Present|. | 43 // Outcome of a call to |Present|. |
| 45 enum class Disposition { | 44 enum class Disposition { |
| 46 kUnchanged, | 45 kUnchanged, |
| 47 kSucceeded, | 46 kSucceeded, |
| 48 kFailed, | 47 kFailed, |
| 49 }; | 48 }; |
| 50 | 49 |
| 51 SceneDef(const SceneLabel& label); | 50 SceneDef(const SceneLabel& label); |
| 52 ~SceneDef(); | 51 ~SceneDef(); |
| 53 | 52 |
| 54 base::WeakPtr<SceneDef> GetWeakPtr() { return weak_factory_.GetWeakPtr(); } | |
| 55 | |
| 56 // Gets the scene label. | 53 // Gets the scene label. |
| 57 const SceneLabel& label() const { return label_; } | 54 const SceneLabel& label() const { return label_; } |
| 58 std::string FormattedLabel() const { | 55 std::string FormattedLabel() const { return label_.FormattedLabel(); } |
| 59 return label_.FormattedLabelForVersion(version_); | |
| 60 } | |
| 61 | |
| 62 // Gets the currently published scene graph version. | |
| 63 uint32_t version() const { return version_; } | |
| 64 | 56 |
| 65 // Enqueues a pending update event to the scene graph. | 57 // Enqueues a pending update event to the scene graph. |
| 66 void EnqueueUpdate(mojo::gfx::composition::SceneUpdatePtr update); | 58 void EnqueueUpdate(mojo::gfx::composition::SceneUpdatePtr update); |
| 67 | 59 |
| 68 // Enqueues a pending publish event to the scene graph. | 60 // Enqueues a pending publish event to the scene graph. |
| 69 // The changes are not applied until |ApplyChanges| is called. | 61 // The changes are not applied until |ApplyChanges| is called. |
| 70 void EnqueuePublish(mojo::gfx::composition::SceneMetadataPtr metadata); | 62 void EnqueuePublish(mojo::gfx::composition::SceneMetadataPtr metadata); |
| 71 | 63 |
| 72 // Applies published updates to the scene up to the point indicated by | 64 // Applies published updates to the scene up to the point indicated by |
| 73 // |presentation_time|. | 65 // |presentation_time|, adds new scene content to the universe. |
| 74 // | 66 // |
| 75 // Returns a value which indicates whether the updates succeded. | 67 // Returns a value which indicates whether the updates succeeded. |
| 76 // If the result is |kFailed|, the scene graph was left in an unusable | 68 // If the result is |kFailed|, the scene graph was left in an unusable |
| 77 // and inconsistent state and must be destroyed. | 69 // and inconsistent state and must be destroyed. |
| 78 Disposition Present(int64_t presentation_time, | 70 Disposition Present(int64_t presentation_time, |
| 71 Universe* universe, |
| 79 const SceneResolver& resolver, | 72 const SceneResolver& resolver, |
| 80 const SceneUnavailableSender& unavailable_sender, | 73 const SceneUnavailableSender& unavailable_sender, |
| 81 std::ostream& err); | 74 std::ostream& err); |
| 82 | 75 |
| 83 // Unlinks references to another scene which has been unregistered. | 76 // Reports that a scene has been unregistered. |
| 84 // Causes |OnResourceUnavailable()| to be delivered to the scene for all | 77 // Causes |OnResourceUnavailable()| to be delivered for all matching scene |
| 85 // invalidated scene resources. Returns true if any changes were made. | 78 // references. |
| 86 bool UnlinkReferencedScene(SceneDef* scene, | 79 void NotifySceneUnavailable( |
| 87 const SceneUnavailableSender& unavailable_sender); | 80 const mojo::gfx::composition::SceneToken& scene_token, |
| 88 | 81 const SceneUnavailableSender& unavailable_sender); |
| 89 // Finds resources or nodes in the current version, returns nullptr if absent. | |
| 90 const Resource* FindResource(uint32_t resource_id) const; | |
| 91 const Node* FindNode(uint32_t node_id) const; | |
| 92 const Node* FindRootNode() const { | |
| 93 return FindNode(mojo::gfx::composition::kSceneRootNodeId); | |
| 94 } | |
| 95 | |
| 96 // Finds the most recently presented content of the specified version, | |
| 97 // returns nullptr if absent. | |
| 98 // If the version is |kSceneVersionNone| returns the current version. | |
| 99 const SceneContent* FindContent(uint32_t version) const; | |
| 100 | 82 |
| 101 private: | 83 private: |
| 84 class Collector : public SceneContentBuilder { |
| 85 public: |
| 86 Collector(const SceneDef* scene, |
| 87 uint32_t version, |
| 88 int64_t presentation_time, |
| 89 std::ostream& err); |
| 90 ~Collector() override; |
| 91 |
| 92 protected: |
| 93 const Resource* FindResource(uint32_t resource_id) const override; |
| 94 const Node* FindNode(uint32_t node_id) const override; |
| 95 |
| 96 private: |
| 97 const SceneDef* scene_; |
| 98 |
| 99 DISALLOW_COPY_AND_ASSIGN(Collector); |
| 100 }; |
| 101 |
| 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; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 128 scoped_refptr<const Node> 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; | |
| 139 std::unordered_map<uint32_t, scoped_refptr<const Resource>> resources_; | 138 std::unordered_map<uint32_t, scoped_refptr<const Resource>> resources_; |
| 140 std::unordered_map<uint32_t, scoped_refptr<const Node>> nodes_; | 139 std::unordered_map<uint32_t, scoped_refptr<const Node>> nodes_; |
| 141 | 140 |
| 142 scoped_refptr<const SceneContent> content_; | |
| 143 | |
| 144 base::WeakPtrFactory<SceneDef> weak_factory_; | |
| 145 | |
| 146 DISALLOW_COPY_AND_ASSIGN(SceneDef); | 141 DISALLOW_COPY_AND_ASSIGN(SceneDef); |
| 147 }; | 142 }; |
| 148 | 143 |
| 149 } // namespace compositor | 144 } // namespace compositor |
| 150 | 145 |
| 151 #endif // SERVICES_GFX_COMPOSITOR_GRAPH_SCENE_DEF_H_ | 146 #endif // SERVICES_GFX_COMPOSITOR_GRAPH_SCENE_DEF_H_ |
| OLD | NEW |