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_REF_BASE_H_ | |
6 #define CC_SURFACES_SURFACE_REF_BASE_H_ | |
7 | |
8 #include <memory> | |
9 | |
10 #include "cc/surfaces/surface_id.h" | |
11 #include "cc/surfaces/surface_sequence.h" | |
12 #include "ui/gfx/geometry/size.h" | |
13 | |
14 namespace cc { | |
15 | |
16 class LayerTreeHost; | |
17 class SurfaceRefInternal; | |
18 class CompositorFrameMetadata; | |
19 typedef std::unique_ptr<SurfaceRefInternal> SurfaceRefPtr; | |
20 template <class T> | |
21 class SurfaceRefBase; | |
22 | |
23 class SurfaceRefInternal { | |
Fady Samuel
2016/11/30 19:51:29
kylechar@ and I were chatting. My current thinking
| |
24 public: | |
25 virtual SurfaceRefPtr Clone() const = 0; | |
26 | |
27 ~SurfaceRefInternal(); | |
28 | |
29 SurfaceRefInternal* SetId(const SurfaceId& id) { | |
Fady Samuel
2016/11/30 19:51:29
Can we get rid of these setters? I'd prefer if id,
| |
30 DCHECK(!is_active_); | |
31 id_ = id; | |
32 return this; | |
33 } | |
34 SurfaceRefInternal* SetScale(float scale) { | |
35 DCHECK(!is_active_); | |
36 scale_ = scale; | |
37 return this; | |
38 } | |
39 SurfaceRefInternal* SetSize(const gfx::Size& size) { | |
40 DCHECK(!is_active_); | |
41 size_ = size; | |
42 return this; | |
43 } | |
44 void SetHost(LayerTreeHost* host) { | |
Fady Samuel
2016/11/30 19:51:29
I'd prefer if the base class didn't know about Lay
| |
45 DCHECK(!is_active_); | |
46 host_ = host; | |
47 } | |
48 void AllowSurfaceDestruction() { | |
Fady Samuel
2016/11/30 19:51:29
I'm super confused about these things. What does A
| |
49 if (!is_active_) | |
50 return; | |
51 DCHECK(id_.is_valid()); | |
52 AllowImpl(); | |
53 is_active_ = false; | |
54 } | |
55 void BlockSurfaceDestruction() { | |
56 if (is_active_) | |
57 return; | |
58 BlockImpl(); | |
59 is_active_ = true; | |
60 } | |
61 bool is_active() { return is_active_; } | |
Fady Samuel
2016/11/30 19:51:29
What does this mean?
| |
62 | |
63 void SetMetadata(const SurfaceId& id, float scale, const gfx::Size& size) { | |
Fady Samuel
2016/11/30 19:51:29
Do these quantities change? Maybe make this in the
| |
64 SetId(id); | |
65 SetScale(scale); | |
66 SetSize(size); | |
67 } | |
68 | |
69 void DelegateLock(CompositorFrameMetadata* metadata) { | |
70 DelegateLockImpl(metadata); | |
71 is_active_ = false; | |
72 } | |
73 | |
74 const SurfaceId& id() const { return id_; } | |
75 float scale() const { return scale_; } | |
76 const gfx::Size& size() const { return size_; } | |
77 LayerTreeHost* host() const { return host_; } | |
Fady Samuel
2016/11/30 19:51:29
SurfaceRef/SurfaceEmbedding shouldn't know about L
| |
78 | |
79 protected: | |
80 virtual void AllowImpl() = 0; | |
81 virtual void BlockImpl() = 0; | |
82 virtual void DelegateLockImpl(CompositorFrameMetadata*) = 0; | |
83 | |
84 private: | |
85 SurfaceId id_; | |
86 float scale_ = 1.f; | |
87 gfx::Size size_; | |
88 bool is_active_ = false; | |
Saman Sami
2016/11/30 18:05:52
rename?
| |
89 LayerTreeHost* host_ = nullptr; | |
90 template <class U> | |
91 friend class SurfaceRefBase; | |
92 }; | |
93 | |
94 template <class T> | |
95 class SurfaceRefBase : public SurfaceRefInternal { | |
96 public: | |
97 SurfaceRefPtr Clone() const override { | |
98 SurfaceRefPtr res(new T(*(T*)this)); | |
Fady Samuel
2016/11/30 19:51:29
Use static_cast
| |
99 res->is_active_ = false; | |
100 return res; | |
101 } | |
102 }; | |
103 | |
104 } // namespace cc | |
105 | |
106 #endif // CC_SURFACES_SURFACE_REF_BASE_H_ | |
OLD | NEW |