| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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_CONTENT_H_ | 5 #ifndef SERVICES_GFX_COMPOSITOR_GRAPH_SCENE_CONTENT_H_ |
| 6 #define SERVICES_GFX_COMPOSITOR_GRAPH_SCENE_CONTENT_H_ | 6 #define SERVICES_GFX_COMPOSITOR_GRAPH_SCENE_CONTENT_H_ |
| 7 | 7 |
| 8 #include <iosfwd> | 8 #include <iosfwd> |
| 9 #include <string> |
| 9 #include <unordered_map> | 10 #include <unordered_map> |
| 10 | 11 |
| 11 #include "base/macros.h" | 12 #include "base/macros.h" |
| 12 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 13 #include "base/memory/weak_ptr.h" | |
| 14 #include "mojo/services/gfx/composition/interfaces/hit_tests.mojom.h" | 14 #include "mojo/services/gfx/composition/interfaces/hit_tests.mojom.h" |
| 15 #include "mojo/services/gfx/composition/interfaces/scenes.mojom.h" | 15 #include "mojo/services/gfx/composition/interfaces/scenes.mojom.h" |
| 16 #include "services/gfx/compositor/graph/nodes.h" | 16 #include "services/gfx/compositor/graph/nodes.h" |
| 17 #include "services/gfx/compositor/graph/resources.h" | 17 #include "services/gfx/compositor/graph/resources.h" |
| 18 #include "services/gfx/compositor/graph/scene_label.h" | 18 #include "services/gfx/compositor/graph/scene_label.h" |
| 19 | 19 |
| 20 class SkCanvas; | 20 class SkCanvas; |
| 21 struct SkPoint; | 21 struct SkPoint; |
| 22 class SkMatrix44; | 22 class SkMatrix44; |
| 23 | 23 |
| 24 namespace compositor { | 24 namespace compositor { |
| 25 | 25 |
| 26 class SceneContentBuilder; | 26 class SceneContentBuilder; |
| 27 class SceneDef; | |
| 28 | 27 |
| 29 // Represents the content of a particular published version of a scene. | 28 // Represents the content of a particular published version of a scene. |
| 30 // | 29 // |
| 31 // Holds a resource and node table which describes the content of a | 30 // Holds a resource and node table which describes the content of a |
| 32 // scene as it was when a particular version was published. Only the | 31 // scene as it was when a particular version was published. Only the |
| 33 // internal state of the scene is described; links to other scenes are | 32 // internal state of the scene is described; links to other scenes are |
| 34 // not resolved at this level. | 33 // not resolved at this level. |
| 35 // | 34 // |
| 36 // Once fully constructed, instances of this class are immutable and | 35 // Once fully constructed, instances of this class are immutable and |
| 37 // reference counted so they may be bound to scene references in other scenes. | 36 // reference counted so they may be bound to scene references in other scenes. |
| 38 // | 37 // |
| 39 // TODO(jeffbrown): To improve efficiency, we could replace the hash tables | 38 // TODO(jeffbrown): To improve efficiency, we could replace the hash tables |
| 40 // with a vector of internally linked graph edges. This is relatively easy | 39 // with a vector of internally linked graph edges. This is relatively easy |
| 41 // since the traversal order is well-known and we could even build some kind | 40 // since the traversal order is well-known and we could even build some kind |
| 42 // of hierarchical iterator to walk the graph starting from the root. | 41 // of hierarchical iterator to walk the graph starting from the root. |
| 43 class SceneContent : public base::RefCounted<SceneContent> { | 42 class SceneContent : public base::RefCounted<SceneContent> { |
| 44 public: | 43 public: |
| 45 // Gets the scene label. | 44 // Gets the scene label. |
| 46 const SceneLabel& label() const { return label_; } | 45 const SceneLabel& label() const { return label_; } |
| 47 std::string FormattedLabel() const { | 46 std::string FormattedLabel() const { |
| 48 return label_.FormattedLabelForVersion(version_); | 47 return label_.FormattedLabelForVersion(version_, presentation_time_); |
| 49 } | 48 } |
| 50 std::string FormattedLabelForNode(uint32_t node_id) const { | 49 std::string FormattedLabelForNode(uint32_t node_id) const { |
| 51 return label_.FormattedLabelForNode(version_, node_id); | 50 return label_.FormattedLabelForNode(version_, presentation_time_, node_id); |
| 52 } | 51 } |
| 53 | 52 |
| 54 // Gets the version of the scene represented by this object. | 53 // Gets the version of the scene represented by this object. |
| 55 uint32_t version() const { return version_; } | 54 uint32_t version() const { return version_; } |
| 56 | 55 |
| 56 // Gets the time when this scene was presented. |
| 57 int64_t presentation_time() const { return presentation_time_; } |
| 58 |
| 59 // Returns true if this content satisfies a request for the specified version. |
| 60 bool MatchesVersion(uint32_t requested_version) const; |
| 61 |
| 57 // Called to record drawing commands from a snapshot. | 62 // Called to record drawing commands from a snapshot. |
| 58 void RecordPicture(const Snapshot* snapshot, SkCanvas* canvas) const; | 63 void RecordPicture(const Snapshot* snapshot, SkCanvas* canvas) const; |
| 59 | 64 |
| 60 // Performs a hit test at the specified point. | 65 // Performs a hit test at the specified point. |
| 61 // The |scene_point| is the hit tested point in the scene's coordinate space. | 66 // The |scene_point| is the hit tested point in the scene's coordinate space. |
| 62 // The |global_to_scene_transform| is the accumulated transform from the | 67 // The |global_to_scene_transform| is the accumulated transform from the |
| 63 // global coordinate space to the scene's coordinate space. | 68 // global coordinate space to the scene's coordinate space. |
| 64 // Provides hit information for the scene in |out_scene_hit| if any. | 69 // Provides hit information for the scene in |out_scene_hit| if any. |
| 65 // Returns true if the search was terminated by an opaque hit. | 70 // Returns true if the search was terminated by an opaque hit. |
| 66 bool HitTest(const Snapshot* snapshot, | 71 bool HitTest(const Snapshot* snapshot, |
| 67 const SkPoint& scene_point, | 72 const SkPoint& scene_point, |
| 68 const SkMatrix44& global_to_scene_transform, | 73 const SkMatrix44& global_to_scene_transform, |
| 69 mojo::gfx::composition::SceneHitPtr* out_scene_hit) const; | 74 mojo::gfx::composition::SceneHitPtr* out_scene_hit) const; |
| 70 | 75 |
| 71 // Gets the requested resource, never null because it must be present. | 76 // Gets the requested resource, never null because it must be present. |
| 72 const Resource* GetResource(uint32_t resource_id, | 77 const Resource* GetResource(uint32_t resource_id, |
| 73 Resource::Type resource_type) const; | 78 Resource::Type resource_type) const; |
| 74 | 79 |
| 75 // Gets the requested node, never null because it must be present. | 80 // Gets the requested node, never null because it must be present. |
| 76 const Node* GetNode(uint32_t node_id) const; | 81 const Node* GetNode(uint32_t node_id) const; |
| 77 | 82 |
| 78 // Gets the root node if it exists, otherwise returns nullptr. | 83 // Gets the root node if it exists, otherwise returns nullptr. |
| 79 const Node* GetRootNodeIfExists() const; | 84 const Node* GetRootNodeIfExists() const; |
| 80 | 85 |
| 81 private: | 86 private: |
| 82 friend class base::RefCounted<SceneContent>; | 87 friend class base::RefCounted<SceneContent>; |
| 83 friend class SceneContentBuilder; | 88 friend class SceneContentBuilder; |
| 84 SceneContent(const SceneLabel& label, | 89 SceneContent(const SceneLabel& label, |
| 85 uint32_t version, | 90 uint32_t version, |
| 91 int64_t presentation_time, |
| 86 size_t max_resources, | 92 size_t max_resources, |
| 87 size_t max_nodes); | 93 size_t max_nodes); |
| 88 ~SceneContent(); | 94 ~SceneContent(); |
| 89 | 95 |
| 90 const SceneLabel label_; | 96 const SceneLabel label_; |
| 91 const uint32_t version_; | 97 const uint32_t version_; |
| 98 const int64_t presentation_time_; |
| 92 std::unordered_map<uint32_t, scoped_refptr<const Resource>> resources_; | 99 std::unordered_map<uint32_t, scoped_refptr<const Resource>> resources_; |
| 93 std::unordered_map<uint32_t, scoped_refptr<const Node>> nodes_; | 100 std::unordered_map<uint32_t, scoped_refptr<const Node>> nodes_; |
| 94 | 101 |
| 95 DISALLOW_COPY_AND_ASSIGN(SceneContent); | 102 DISALLOW_COPY_AND_ASSIGN(SceneContent); |
| 96 }; | 103 }; |
| 97 | 104 |
| 98 // Builds a table of all of the nodes and resources that make up the | 105 // Builds a table of all of the nodes and resources that make up the |
| 99 // content of a particular version of a scene. | 106 // content of a particular version of a scene. |
| 100 class SceneContentBuilder { | 107 class SceneContentBuilder { |
| 101 public: | 108 public: |
| 102 SceneContentBuilder(const SceneDef* scene, | 109 SceneContentBuilder(const SceneLabel& label, |
| 103 uint32_t version, | 110 uint32_t version, |
| 104 std::ostream& err, | 111 int64_t presentation_time, |
| 105 size_t max_resources, | 112 size_t max_resources, |
| 106 size_t max_nodes); | 113 size_t max_nodes, |
| 107 ~SceneContentBuilder(); | 114 std::ostream& err); |
| 115 virtual ~SceneContentBuilder(); |
| 108 | 116 |
| 109 // Stream for reporting validation error messages. | 117 // Stream for reporting validation error messages. |
| 110 std::ostream& err() { return err_; } | 118 std::ostream& err() { return err_; } |
| 111 | 119 |
| 112 // Ensures the requested resource is part of the retained scene graph and | 120 // Ensures the requested resource is part of the retained scene graph and |
| 113 // returns a reference to it, or nullptr if an error occurred. | 121 // returns a reference to it, or nullptr if an error occurred. |
| 114 const Resource* RequireResource(uint32_t resource_id, | 122 const Resource* RequireResource(uint32_t resource_id, |
| 115 Resource::Type resource_type, | 123 Resource::Type resource_type, |
| 116 uint32_t referrer_node_id); | 124 uint32_t referrer_node_id); |
| 117 | 125 |
| 118 // Ensures the requested node is part of the retained scene graph and | 126 // Ensures the requested node is part of the retained scene graph and |
| 119 // returns a reference to it, or nullptr if an error occurred. | 127 // returns a reference to it, or nullptr if an error occurred. |
| 120 const Node* RequireNode(uint32_t node_id, uint32_t referrer_node_id); | 128 const Node* RequireNode(uint32_t node_id, uint32_t referrer_node_id); |
| 121 | 129 |
| 122 // Builds the content graph. | 130 // Builds the content graph. |
| 123 // Returns nullptr if an error occurred. | 131 // Returns nullptr if an error occurred. |
| 124 scoped_refptr<const SceneContent> Build(); | 132 scoped_refptr<const SceneContent> Build(); |
| 125 | 133 |
| 134 protected: |
| 135 // Finds resources or nodes in the current version, returns nullptr if absent. |
| 136 virtual const Resource* FindResource(uint32_t resource_id) const = 0; |
| 137 virtual const Node* FindNode(uint32_t node_id) const = 0; |
| 138 |
| 126 private: | 139 private: |
| 127 bool AddNode(const Node* node); | 140 bool AddNode(const Node* node); |
| 128 | 141 |
| 129 scoped_refptr<SceneContent> content_; | 142 scoped_refptr<SceneContent> content_; |
| 130 const SceneDef* scene_; | |
| 131 std::ostream& err_; | 143 std::ostream& err_; |
| 144 |
| 145 DISALLOW_COPY_AND_ASSIGN(SceneContentBuilder); |
| 132 }; | 146 }; |
| 133 | 147 |
| 134 } // namespace compositor | 148 } // namespace compositor |
| 135 | 149 |
| 136 #endif // SERVICES_GFX_COMPOSITOR_GRAPH_SCENE_CONTENT_H_ | 150 #endif // SERVICES_GFX_COMPOSITOR_GRAPH_SCENE_CONTENT_H_ |
| OLD | NEW |