| 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_RESOURCES_H_ | 5 #ifndef SERVICES_GFX_COMPOSITOR_GRAPH_RESOURCES_H_ |
| 6 #define SERVICES_GFX_COMPOSITOR_GRAPH_RESOURCES_H_ | 6 #define SERVICES_GFX_COMPOSITOR_GRAPH_RESOURCES_H_ |
| 7 | 7 |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/memory/weak_ptr.h" | |
| 11 #include "mojo/services/gfx/composition/interfaces/resources.mojom.h" | 10 #include "mojo/services/gfx/composition/interfaces/resources.mojom.h" |
| 12 #include "services/gfx/compositor/render/render_image.h" | 11 #include "services/gfx/compositor/render/render_image.h" |
| 13 | 12 |
| 14 namespace compositor { | 13 namespace compositor { |
| 15 | 14 |
| 16 class SceneDef; | |
| 17 | |
| 18 // Base class for resources in a scene graph. | 15 // Base class for resources in a scene graph. |
| 19 // | 16 // |
| 20 // Instances of this class are immutable and reference counted so they may | 17 // Instances of this class are immutable and reference counted so they may |
| 21 // be shared by multiple versions of the same scene. | 18 // be shared by multiple versions of the same scene. |
| 22 class Resource : public base::RefCounted<Resource> { | 19 class Resource : public base::RefCounted<Resource> { |
| 23 public: | 20 public: |
| 24 enum class Type { kScene, kImage }; | 21 enum class Type { kScene, kImage }; |
| 25 | 22 |
| 26 Resource(); | 23 Resource(); |
| 27 | 24 |
| 28 // Gets the resource type. | 25 // Gets the resource type. |
| 29 virtual Type type() const = 0; | 26 virtual Type type() const = 0; |
| 30 | 27 |
| 31 protected: | 28 protected: |
| 32 friend class base::RefCounted<Resource>; | 29 friend class base::RefCounted<Resource>; |
| 33 virtual ~Resource(); | 30 virtual ~Resource(); |
| 34 | 31 |
| 35 private: | 32 private: |
| 36 DISALLOW_COPY_AND_ASSIGN(Resource); | 33 DISALLOW_COPY_AND_ASSIGN(Resource); |
| 37 }; | 34 }; |
| 38 | 35 |
| 39 // A resource which represents a reference to a specified scene. | 36 // A resource which represents a reference to a specified scene. |
| 40 class SceneResource : public Resource { | 37 class SceneResource : public Resource { |
| 41 public: | 38 public: |
| 42 SceneResource(const mojo::gfx::composition::SceneToken& scene_token, | 39 explicit SceneResource(const mojo::gfx::composition::SceneToken& scene_token); |
| 43 const base::WeakPtr<SceneDef>& referenced_scene); | |
| 44 | 40 |
| 45 Type type() const override; | 41 Type type() const override; |
| 46 | 42 |
| 47 const mojo::gfx::composition::SceneToken& scene_token() const { | 43 const mojo::gfx::composition::SceneToken& scene_token() const { |
| 48 return scene_token_; | 44 return scene_token_; |
| 49 } | 45 } |
| 50 | 46 |
| 51 // The referenced scene, may be null if the scene is unavailable. | |
| 52 const base::WeakPtr<SceneDef>& referenced_scene() const { | |
| 53 return referenced_scene_; | |
| 54 } | |
| 55 | |
| 56 // Returns a copy of the resource without its referenced scene. | |
| 57 scoped_refptr<const SceneResource> Unlink() const; | |
| 58 | |
| 59 protected: | 47 protected: |
| 60 ~SceneResource() override; | 48 ~SceneResource() override; |
| 61 | 49 |
| 62 private: | 50 private: |
| 63 mojo::gfx::composition::SceneToken scene_token_; | 51 mojo::gfx::composition::SceneToken scene_token_; |
| 64 base::WeakPtr<SceneDef> referenced_scene_; | |
| 65 | 52 |
| 66 DISALLOW_COPY_AND_ASSIGN(SceneResource); | 53 DISALLOW_COPY_AND_ASSIGN(SceneResource); |
| 67 }; | 54 }; |
| 68 | 55 |
| 69 // A resource which represents a refrence to a specified image. | 56 // A resource which represents a refrence to a specified image. |
| 70 class ImageResource : public Resource { | 57 class ImageResource : public Resource { |
| 71 public: | 58 public: |
| 72 explicit ImageResource(const scoped_refptr<RenderImage>& image); | 59 explicit ImageResource(const scoped_refptr<RenderImage>& image); |
| 73 | 60 |
| 74 Type type() const override; | 61 Type type() const override; |
| 75 | 62 |
| 76 // The referenced image, never null. | 63 // The referenced image, never null. |
| 77 const scoped_refptr<RenderImage>& image() const { return image_; } | 64 const scoped_refptr<RenderImage>& image() const { return image_; } |
| 78 | 65 |
| 79 protected: | 66 protected: |
| 80 ~ImageResource() override; | 67 ~ImageResource() override; |
| 81 | 68 |
| 82 private: | 69 private: |
| 83 scoped_refptr<RenderImage> image_; | 70 scoped_refptr<RenderImage> image_; |
| 84 | 71 |
| 85 DISALLOW_COPY_AND_ASSIGN(ImageResource); | 72 DISALLOW_COPY_AND_ASSIGN(ImageResource); |
| 86 }; | 73 }; |
| 87 | 74 |
| 88 } // namespace compositor | 75 } // namespace compositor |
| 89 | 76 |
| 90 #endif // SERVICES_GFX_COMPOSITOR_GRAPH_RESOURCES_H_ | 77 #endif // SERVICES_GFX_COMPOSITOR_GRAPH_RESOURCES_H_ |
| OLD | NEW |