OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef CC_SURFACES_SURFACE_EMBEDDING_BASE_H_ | |
6 #define CC_SURFACES_SURFACE_EMBEDDING_BASE_H_ | |
7 | |
8 #include <memory> | |
9 | |
10 #include "base/memory/ptr_util.h" | |
11 #include "cc/surfaces/surface_id.h" | |
12 #include "cc/surfaces/surface_sequence.h" | |
13 #include "cc/surfaces/surface_sequence_generator.h" | |
14 #include "ui/gfx/geometry/size.h" | |
15 | |
16 namespace cc { | |
17 | |
18 struct SurfaceInfo { | |
19 SurfaceId id; | |
20 float scale = 1.f; | |
21 gfx::Size size; | |
22 | |
23 SurfaceInfo() {} | |
24 SurfaceInfo(const SurfaceId& id, float scale, gfx::Size size) | |
25 : id(id), scale(scale), size(size) {} | |
26 bool operator==(const SurfaceInfo& info) const { | |
27 return id == info.id && scale == info.scale && size == info.size; | |
28 } | |
29 }; | |
30 | |
31 class CompositorFrameMetadata; | |
32 class SurfaceEmbedding; | |
33 typedef std::unique_ptr<SurfaceEmbedding> SurfaceEmbeddingPtr; | |
34 | |
35 class SurfaceEmbeddingOwner { | |
36 public: | |
37 virtual SurfaceSequenceGenerator* GetSurfaceSequenceGenerator() = 0; | |
38 }; | |
39 | |
40 class SurfaceRef; | |
41 typedef std::unique_ptr<SurfaceRef> SurfaceRefPtr; | |
42 | |
43 class SurfaceRef final { | |
Fady Samuel
2016/12/12 16:11:59
Make this move only and create on stack. Call it S
| |
44 public: | |
45 void Destroy(); | |
46 void Destroy(CompositorFrameMetadata* metadata); | |
47 ~SurfaceRef(); | |
48 | |
49 private: | |
50 friend class SurfaceEmbedding; | |
51 explicit SurfaceRef(SurfaceEmbeddingPtr embedding); | |
52 bool is_deleted_ = false; | |
Fady Samuel
2016/12/12 16:11:59
What's the point of this? Set embedding_ = nullptr
| |
53 SurfaceEmbeddingPtr embedding_; | |
54 }; | |
55 | |
56 class SurfaceEmbedding { | |
Fady Samuel
2016/12/12 16:11:59
Make this refcounted.
| |
57 public: | |
58 explicit SurfaceEmbedding(const SurfaceInfo& info) : info_(info) {} | |
59 | |
60 SurfaceRefPtr CreateReference(SurfaceEmbeddingOwner* owner) const { | |
61 SurfaceEmbeddingPtr clone = Clone(); | |
62 clone->owner_ = owner; | |
63 return SurfaceRefPtr(new SurfaceRef(std::move(clone))); | |
64 } | |
65 | |
66 const SurfaceInfo& info() const { return info_; } | |
67 const SurfaceId& id() const { return info_.id; } | |
68 float scale() const { return info_.scale; } | |
69 const gfx::Size& size() const { return info_.size; } | |
70 | |
71 SurfaceEmbeddingPtr Clone() const { return SurfaceEmbeddingPtr(CloneImpl()); } | |
72 | |
73 protected: | |
74 SurfaceEmbeddingOwner* owner() { return owner_; } | |
75 | |
76 private: | |
77 virtual void AddReference() = 0; | |
78 virtual void RemoveReference() = 0; | |
79 virtual void RemoveReference(CompositorFrameMetadata*) = 0; | |
80 virtual SurfaceEmbedding* CloneImpl() const = 0; | |
81 | |
82 const SurfaceInfo info_; | |
83 SurfaceEmbeddingOwner* owner_ = nullptr; | |
84 | |
85 friend class SurfaceRef; | |
86 }; | |
87 | |
88 } // namespace cc | |
89 | |
90 #endif // CC_SURFACES_SURFACE_EMBEDDING_BASE_H_ | |
OLD | NEW |