|
1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|
2 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
3 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
5 |
|
6 #include "mozilla/layers/CompositableClient.h" |
|
7 #include <stdint.h> // for uint64_t, uint32_t |
|
8 #include "gfxPlatform.h" // for gfxPlatform |
|
9 #include "mozilla/layers/CompositableForwarder.h" |
|
10 #include "mozilla/layers/TextureClient.h" // for TextureClient, etc |
|
11 #include "mozilla/layers/TextureClientOGL.h" |
|
12 #include "mozilla/mozalloc.h" // for operator delete, etc |
|
13 #ifdef XP_WIN |
|
14 #include "gfxWindowsPlatform.h" // for gfxWindowsPlatform |
|
15 #include "mozilla/layers/TextureD3D11.h" |
|
16 #include "mozilla/layers/TextureD3D9.h" |
|
17 #endif |
|
18 |
|
19 using namespace mozilla::gfx; |
|
20 |
|
21 namespace mozilla { |
|
22 namespace layers { |
|
23 |
|
24 /** |
|
25 * IPDL actor used by CompositableClient to match with its corresponding |
|
26 * CompositableHost on the compositor side. |
|
27 * |
|
28 * CompositableChild is owned by a CompositableClient. |
|
29 */ |
|
30 class CompositableChild : public PCompositableChild |
|
31 { |
|
32 public: |
|
33 CompositableChild() |
|
34 : mCompositableClient(nullptr), mAsyncID(0) |
|
35 { |
|
36 MOZ_COUNT_CTOR(CompositableChild); |
|
37 } |
|
38 |
|
39 ~CompositableChild() |
|
40 { |
|
41 MOZ_COUNT_DTOR(CompositableChild); |
|
42 } |
|
43 |
|
44 virtual void ActorDestroy(ActorDestroyReason) MOZ_OVERRIDE { |
|
45 if (mCompositableClient) { |
|
46 mCompositableClient->mCompositableChild = nullptr; |
|
47 } |
|
48 } |
|
49 |
|
50 CompositableClient* mCompositableClient; |
|
51 |
|
52 uint64_t mAsyncID; |
|
53 }; |
|
54 |
|
55 PCompositableChild* |
|
56 CompositableClient::CreateIPDLActor() |
|
57 { |
|
58 return new CompositableChild(); |
|
59 } |
|
60 |
|
61 bool |
|
62 CompositableClient::DestroyIPDLActor(PCompositableChild* actor) |
|
63 { |
|
64 delete actor; |
|
65 return true; |
|
66 } |
|
67 |
|
68 void |
|
69 CompositableClient::InitIPDLActor(PCompositableChild* aActor, uint64_t aAsyncID) |
|
70 { |
|
71 MOZ_ASSERT(aActor); |
|
72 CompositableChild* child = static_cast<CompositableChild*>(aActor); |
|
73 mCompositableChild = child; |
|
74 child->mCompositableClient = this; |
|
75 child->mAsyncID = aAsyncID; |
|
76 } |
|
77 |
|
78 CompositableClient* |
|
79 CompositableClient::FromIPDLActor(PCompositableChild* aActor) |
|
80 { |
|
81 MOZ_ASSERT(aActor); |
|
82 return static_cast<CompositableChild*>(aActor)->mCompositableClient; |
|
83 } |
|
84 |
|
85 CompositableClient::CompositableClient(CompositableForwarder* aForwarder, |
|
86 TextureFlags aTextureFlags) |
|
87 : mCompositableChild(nullptr) |
|
88 , mForwarder(aForwarder) |
|
89 , mTextureFlags(aTextureFlags) |
|
90 { |
|
91 MOZ_COUNT_CTOR(CompositableClient); |
|
92 } |
|
93 |
|
94 CompositableClient::~CompositableClient() |
|
95 { |
|
96 MOZ_COUNT_DTOR(CompositableClient); |
|
97 Destroy(); |
|
98 } |
|
99 |
|
100 LayersBackend |
|
101 CompositableClient::GetCompositorBackendType() const |
|
102 { |
|
103 return mForwarder->GetCompositorBackendType(); |
|
104 } |
|
105 |
|
106 void |
|
107 CompositableClient::SetIPDLActor(CompositableChild* aChild) |
|
108 { |
|
109 mCompositableChild = aChild; |
|
110 } |
|
111 |
|
112 PCompositableChild* |
|
113 CompositableClient::GetIPDLActor() const |
|
114 { |
|
115 return mCompositableChild; |
|
116 } |
|
117 |
|
118 bool |
|
119 CompositableClient::Connect() |
|
120 { |
|
121 if (!GetForwarder() || GetIPDLActor()) { |
|
122 return false; |
|
123 } |
|
124 GetForwarder()->Connect(this); |
|
125 return true; |
|
126 } |
|
127 |
|
128 void |
|
129 CompositableClient::Destroy() |
|
130 { |
|
131 if (!mCompositableChild) { |
|
132 return; |
|
133 } |
|
134 mCompositableChild->mCompositableClient = nullptr; |
|
135 PCompositableChild::Send__delete__(mCompositableChild); |
|
136 mCompositableChild = nullptr; |
|
137 } |
|
138 |
|
139 uint64_t |
|
140 CompositableClient::GetAsyncID() const |
|
141 { |
|
142 if (mCompositableChild) { |
|
143 return mCompositableChild->mAsyncID; |
|
144 } |
|
145 return 0; // zero is always an invalid async ID |
|
146 } |
|
147 |
|
148 TemporaryRef<BufferTextureClient> |
|
149 CompositableClient::CreateBufferTextureClient(SurfaceFormat aFormat, |
|
150 TextureFlags aTextureFlags, |
|
151 gfx::BackendType aMoz2DBackend) |
|
152 { |
|
153 return TextureClient::CreateBufferTextureClient(GetForwarder(), aFormat, |
|
154 aTextureFlags | mTextureFlags, |
|
155 aMoz2DBackend); |
|
156 } |
|
157 |
|
158 TemporaryRef<TextureClient> |
|
159 CompositableClient::CreateTextureClientForDrawing(SurfaceFormat aFormat, |
|
160 TextureFlags aTextureFlags, |
|
161 gfx::BackendType aMoz2DBackend, |
|
162 const IntSize& aSizeHint) |
|
163 { |
|
164 return TextureClient::CreateTextureClientForDrawing(GetForwarder(), aFormat, |
|
165 aTextureFlags | mTextureFlags, |
|
166 aMoz2DBackend, |
|
167 aSizeHint); |
|
168 } |
|
169 |
|
170 bool |
|
171 CompositableClient::AddTextureClient(TextureClient* aClient) |
|
172 { |
|
173 return aClient->InitIPDLActor(mForwarder); |
|
174 } |
|
175 |
|
176 void |
|
177 CompositableClient::OnTransaction() |
|
178 { |
|
179 } |
|
180 |
|
181 } // namespace layers |
|
182 } // namespace mozilla |