| 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 <unordered_map> | 9 #include <unordered_map> |
| 10 | 10 |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 13 #include "base/memory/weak_ptr.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/node_def.h" | 16 #include "services/gfx/compositor/graph/nodes.h" |
| 17 #include "services/gfx/compositor/graph/resource_def.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; | 27 class SceneDef; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 // The |global_to_scene_transform| is the accumulated transform from the | 62 // The |global_to_scene_transform| is the accumulated transform from the |
| 63 // global coordinate space to the scene's coordinate space. | 63 // global coordinate space to the scene's coordinate space. |
| 64 // Provides hit information for the scene in |out_scene_hit| if any. | 64 // Provides hit information for the scene in |out_scene_hit| if any. |
| 65 // Returns true if the search was terminated by an opaque hit. | 65 // Returns true if the search was terminated by an opaque hit. |
| 66 bool HitTest(const Snapshot* snapshot, | 66 bool HitTest(const Snapshot* snapshot, |
| 67 const SkPoint& scene_point, | 67 const SkPoint& scene_point, |
| 68 const SkMatrix44& global_to_scene_transform, | 68 const SkMatrix44& global_to_scene_transform, |
| 69 mojo::gfx::composition::SceneHitPtr* out_scene_hit) const; | 69 mojo::gfx::composition::SceneHitPtr* out_scene_hit) const; |
| 70 | 70 |
| 71 // Gets the requested resource, never null because it must be present. | 71 // Gets the requested resource, never null because it must be present. |
| 72 const ResourceDef* GetResource(uint32_t resource_id, | 72 const Resource* GetResource(uint32_t resource_id, |
| 73 ResourceDef::Type resource_type) const; | 73 Resource::Type resource_type) const; |
| 74 | 74 |
| 75 // Gets the requested node, never null because it must be present. | 75 // Gets the requested node, never null because it must be present. |
| 76 const NodeDef* GetNode(uint32_t node_id) const; | 76 const Node* GetNode(uint32_t node_id) const; |
| 77 | 77 |
| 78 // Gets the root node if it exists, otherwise returns nullptr. | 78 // Gets the root node if it exists, otherwise returns nullptr. |
| 79 const NodeDef* GetRootNodeIfExists() const; | 79 const Node* GetRootNodeIfExists() const; |
| 80 | 80 |
| 81 private: | 81 private: |
| 82 friend class base::RefCounted<SceneContent>; | 82 friend class base::RefCounted<SceneContent>; |
| 83 friend class SceneContentBuilder; | 83 friend class SceneContentBuilder; |
| 84 SceneContent(const SceneLabel& label, | 84 SceneContent(const SceneLabel& label, |
| 85 uint32_t version, | 85 uint32_t version, |
| 86 size_t max_resources, | 86 size_t max_resources, |
| 87 size_t max_nodes); | 87 size_t max_nodes); |
| 88 ~SceneContent(); | 88 ~SceneContent(); |
| 89 | 89 |
| 90 const SceneLabel label_; | 90 const SceneLabel label_; |
| 91 const uint32_t version_; | 91 const uint32_t version_; |
| 92 std::unordered_map<uint32_t, scoped_refptr<const ResourceDef>> resources_; | 92 std::unordered_map<uint32_t, scoped_refptr<const Resource>> resources_; |
| 93 std::unordered_map<uint32_t, scoped_refptr<const NodeDef>> nodes_; | 93 std::unordered_map<uint32_t, scoped_refptr<const Node>> nodes_; |
| 94 | 94 |
| 95 DISALLOW_COPY_AND_ASSIGN(SceneContent); | 95 DISALLOW_COPY_AND_ASSIGN(SceneContent); |
| 96 }; | 96 }; |
| 97 | 97 |
| 98 // Builds a table of all of the nodes and resources that make up the | 98 // Builds a table of all of the nodes and resources that make up the |
| 99 // content of a particular version of a scene. | 99 // content of a particular version of a scene. |
| 100 class SceneContentBuilder { | 100 class SceneContentBuilder { |
| 101 public: | 101 public: |
| 102 SceneContentBuilder(const SceneDef* scene, | 102 SceneContentBuilder(const SceneDef* scene, |
| 103 uint32_t version, | 103 uint32_t version, |
| 104 std::ostream& err, | 104 std::ostream& err, |
| 105 size_t max_resources, | 105 size_t max_resources, |
| 106 size_t max_nodes); | 106 size_t max_nodes); |
| 107 ~SceneContentBuilder(); | 107 ~SceneContentBuilder(); |
| 108 | 108 |
| 109 // Stream for reporting validation error messages. | 109 // Stream for reporting validation error messages. |
| 110 std::ostream& err() { return err_; } | 110 std::ostream& err() { return err_; } |
| 111 | 111 |
| 112 // Ensures the requested resource is part of the retained scene graph and | 112 // Ensures the requested resource is part of the retained scene graph and |
| 113 // returns a reference to it, or nullptr if an error occurred. | 113 // returns a reference to it, or nullptr if an error occurred. |
| 114 const ResourceDef* RequireResource(uint32_t resource_id, | 114 const Resource* RequireResource(uint32_t resource_id, |
| 115 ResourceDef::Type resource_type, | 115 Resource::Type resource_type, |
| 116 uint32_t referrer_node_id); | 116 uint32_t referrer_node_id); |
| 117 | 117 |
| 118 // Ensures the requested node is part of the retained scene graph and | 118 // Ensures the requested node is part of the retained scene graph and |
| 119 // returns a reference to it, or nullptr if an error occurred. | 119 // returns a reference to it, or nullptr if an error occurred. |
| 120 const NodeDef* RequireNode(uint32_t node_id, uint32_t referrer_node_id); | 120 const Node* RequireNode(uint32_t node_id, uint32_t referrer_node_id); |
| 121 | 121 |
| 122 // Builds the content graph. | 122 // Builds the content graph. |
| 123 // Returns nullptr if an error occurred. | 123 // Returns nullptr if an error occurred. |
| 124 scoped_refptr<const SceneContent> Build(); | 124 scoped_refptr<const SceneContent> Build(); |
| 125 | 125 |
| 126 private: | 126 private: |
| 127 bool AddNode(const NodeDef* node); | 127 bool AddNode(const Node* node); |
| 128 | 128 |
| 129 scoped_refptr<SceneContent> content_; | 129 scoped_refptr<SceneContent> content_; |
| 130 const SceneDef* scene_; | 130 const SceneDef* scene_; |
| 131 std::ostream& err_; | 131 std::ostream& err_; |
| 132 }; | 132 }; |
| 133 | 133 |
| 134 } // namespace compositor | 134 } // namespace compositor |
| 135 | 135 |
| 136 #endif // SERVICES_GFX_COMPOSITOR_GRAPH_SCENE_CONTENT_H_ | 136 #endif // SERVICES_GFX_COMPOSITOR_GRAPH_SCENE_CONTENT_H_ |
| OLD | NEW |