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