blob: 8586ed21847167020ac4dd19555d28bd2480af35 [file] [log] [blame]
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2007 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#define LOG_TAG "SurfaceComposerClient"
18
19#include <stdint.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080020#include <sys/types.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080021
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080022#include <utils/Errors.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080023#include <utils/Log.h>
Mathias Agopiand4784a32010-05-27 19:41:15 -070024#include <utils/Singleton.h>
Mathias Agopiana67932f2011-04-20 14:20:59 -070025#include <utils/SortedVector.h>
26#include <utils/String8.h>
27#include <utils/threads.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080028
Mathias Agopian9cce3252010-02-09 17:46:37 -080029#include <binder/IMemory.h>
Mathias Agopiana67932f2011-04-20 14:20:59 -070030#include <binder/IServiceManager.h>
Mathias Agopian9cce3252010-02-09 17:46:37 -080031
Mathias Agopian076b1cc2009-04-10 14:24:30 -070032#include <ui/DisplayInfo.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080033
Mathias Agopian90ac7992012-02-25 18:48:35 -080034#include <gui/ISurface.h>
35#include <gui/ISurfaceComposer.h>
36#include <gui/ISurfaceComposerClient.h>
37#include <gui/SurfaceComposerClient.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080038
Mathias Agopian41f673c2011-11-17 17:48:35 -080039#include <private/gui/ComposerService.h>
Mathias Agopian90ac7992012-02-25 18:48:35 -080040#include <private/gui/LayerState.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080041
42namespace android {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080043// ---------------------------------------------------------------------------
44
Mathias Agopian7e27f052010-05-28 14:22:23 -070045ANDROID_SINGLETON_STATIC_INSTANCE(ComposerService);
46
Mathias Agopianb7e930d2010-06-01 15:12:58 -070047ComposerService::ComposerService()
48: Singleton<ComposerService>() {
Andy McFadden6652b3e2012-09-06 18:45:56 -070049 Mutex::Autolock _l(mLock);
50 connectLocked();
51}
52
53void ComposerService::connectLocked() {
Mathias Agopianb7e930d2010-06-01 15:12:58 -070054 const String16 name("SurfaceFlinger");
55 while (getService(name, &mComposerService) != NO_ERROR) {
56 usleep(250000);
57 }
Andy McFadden6652b3e2012-09-06 18:45:56 -070058 assert(mComposerService != NULL);
59
60 // Create the death listener.
61 class DeathObserver : public IBinder::DeathRecipient {
62 ComposerService& mComposerService;
63 virtual void binderDied(const wp<IBinder>& who) {
64 ALOGW("ComposerService remote (surfaceflinger) died [%p]",
65 who.unsafe_get());
66 mComposerService.composerServiceDied();
67 }
68 public:
69 DeathObserver(ComposerService& mgr) : mComposerService(mgr) { }
70 };
71
72 mDeathObserver = new DeathObserver(*const_cast<ComposerService*>(this));
73 mComposerService->asBinder()->linkToDeath(mDeathObserver);
Mathias Agopianb7e930d2010-06-01 15:12:58 -070074}
75
Andy McFadden6652b3e2012-09-06 18:45:56 -070076/*static*/ sp<ISurfaceComposer> ComposerService::getComposerService() {
77 ComposerService& instance = ComposerService::getInstance();
78 Mutex::Autolock _l(instance.mLock);
79 if (instance.mComposerService == NULL) {
80 ComposerService::getInstance().connectLocked();
81 assert(instance.mComposerService != NULL);
82 ALOGD("ComposerService reconnected");
83 }
84 return instance.mComposerService;
85}
86
87void ComposerService::composerServiceDied()
88{
89 Mutex::Autolock _l(mLock);
90 mComposerService = NULL;
91 mDeathObserver = NULL;
Mathias Agopianb7e930d2010-06-01 15:12:58 -070092}
93
Mathias Agopian7e27f052010-05-28 14:22:23 -070094// ---------------------------------------------------------------------------
95
Mathias Agopian698c0872011-06-28 19:09:31 -070096static inline
Mathias Agopiane57f2922012-08-09 16:29:12 -070097int compare_type(const ComposerState& lhs, const ComposerState& rhs) {
Mathias Agopian698c0872011-06-28 19:09:31 -070098 if (lhs.client < rhs.client) return -1;
99 if (lhs.client > rhs.client) return 1;
100 if (lhs.state.surface < rhs.state.surface) return -1;
101 if (lhs.state.surface > rhs.state.surface) return 1;
102 return 0;
103}
104
Mathias Agopiane57f2922012-08-09 16:29:12 -0700105static inline
106int compare_type(const DisplayState& lhs, const DisplayState& rhs) {
107 return compare_type(lhs.token, rhs.token);
108}
109
Mathias Agopian7e27f052010-05-28 14:22:23 -0700110class Composer : public Singleton<Composer>
111{
Mathias Agopiand4784a32010-05-27 19:41:15 -0700112 friend class Singleton<Composer>;
113
Mathias Agopian698c0872011-06-28 19:09:31 -0700114 mutable Mutex mLock;
Mathias Agopiane57f2922012-08-09 16:29:12 -0700115 SortedVector<ComposerState> mComposerStates;
116 SortedVector<DisplayState > mDisplayStates;
Jamie Gennis28378392011-10-12 17:39:00 -0700117 uint32_t mForceSynchronous;
Jamie Gennis2d5e2302012-10-15 18:24:43 -0700118 bool mAnimation;
Mathias Agopian698c0872011-06-28 19:09:31 -0700119
Jamie Gennisb8d69a52011-10-10 15:48:06 -0700120 Composer() : Singleton<Composer>(),
Jamie Gennis2d5e2302012-10-15 18:24:43 -0700121 mForceSynchronous(0),
122 mAnimation(false)
Jamie Gennis28378392011-10-12 17:39:00 -0700123 { }
Mathias Agopian698c0872011-06-28 19:09:31 -0700124
Jamie Gennis28378392011-10-12 17:39:00 -0700125 void closeGlobalTransactionImpl(bool synchronous);
Jamie Gennis2d5e2302012-10-15 18:24:43 -0700126 void setAnimationTransactionImpl();
Mathias Agopian698c0872011-06-28 19:09:31 -0700127
128 layer_state_t* getLayerStateLocked(
129 const sp<SurfaceComposerClient>& client, SurfaceID id);
130
Mathias Agopiane57f2922012-08-09 16:29:12 -0700131 DisplayState& getDisplayStateLocked(const sp<IBinder>& token);
132
Mathias Agopiand4784a32010-05-27 19:41:15 -0700133public:
Andy McFadden8dfa92f2012-09-17 18:27:17 -0700134 sp<IBinder> createDisplay(const String8& displayName);
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700135 sp<IBinder> getBuiltInDisplay(int32_t id);
Mathias Agopian698c0872011-06-28 19:09:31 -0700136
137 status_t setPosition(const sp<SurfaceComposerClient>& client, SurfaceID id,
Mathias Agopian41b6aab2011-08-30 18:51:54 -0700138 float x, float y);
Mathias Agopian698c0872011-06-28 19:09:31 -0700139 status_t setSize(const sp<SurfaceComposerClient>& client, SurfaceID id,
140 uint32_t w, uint32_t h);
141 status_t setLayer(const sp<SurfaceComposerClient>& client, SurfaceID id,
142 int32_t z);
143 status_t setFlags(const sp<SurfaceComposerClient>& client, SurfaceID id,
144 uint32_t flags, uint32_t mask);
145 status_t setTransparentRegionHint(
146 const sp<SurfaceComposerClient>& client, SurfaceID id,
147 const Region& transparentRegion);
148 status_t setAlpha(const sp<SurfaceComposerClient>& client, SurfaceID id,
149 float alpha);
150 status_t setMatrix(const sp<SurfaceComposerClient>& client, SurfaceID id,
151 float dsdx, float dtdx, float dsdy, float dtdy);
Jamie Gennisb8d69a52011-10-10 15:48:06 -0700152 status_t setOrientation(int orientation);
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700153 status_t setCrop(const sp<SurfaceComposerClient>& client, SurfaceID id,
154 const Rect& crop);
Mathias Agopian87855782012-07-24 21:41:09 -0700155 status_t setLayerStack(const sp<SurfaceComposerClient>& client,
156 SurfaceID id, uint32_t layerStack);
Mathias Agopian698c0872011-06-28 19:09:31 -0700157
Mathias Agopiane57f2922012-08-09 16:29:12 -0700158 void setDisplaySurface(const sp<IBinder>& token, const sp<ISurfaceTexture>& surface);
159 void setDisplayLayerStack(const sp<IBinder>& token, uint32_t layerStack);
Mathias Agopian00e8c7a2012-09-04 19:30:46 -0700160 void setDisplayProjection(const sp<IBinder>& token,
161 uint32_t orientation,
162 const Rect& layerStackRect,
163 const Rect& displayRect);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700164
Jamie Gennis2d5e2302012-10-15 18:24:43 -0700165 static void setAnimationTransaction() {
166 Composer::getInstance().setAnimationTransactionImpl();
167 }
168
Jamie Gennis28378392011-10-12 17:39:00 -0700169 static void closeGlobalTransaction(bool synchronous) {
170 Composer::getInstance().closeGlobalTransactionImpl(synchronous);
Mathias Agopiand4784a32010-05-27 19:41:15 -0700171 }
172};
173
174ANDROID_SINGLETON_STATIC_INSTANCE(Composer);
175
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800176// ---------------------------------------------------------------------------
177
Andy McFadden8dfa92f2012-09-17 18:27:17 -0700178sp<IBinder> Composer::createDisplay(const String8& displayName) {
179 return ComposerService::getComposerService()->createDisplay(displayName);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700180}
181
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700182sp<IBinder> Composer::getBuiltInDisplay(int32_t id) {
183 return ComposerService::getComposerService()->getBuiltInDisplay(id);
184}
185
Jamie Gennis28378392011-10-12 17:39:00 -0700186void Composer::closeGlobalTransactionImpl(bool synchronous) {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700187 sp<ISurfaceComposer> sm(ComposerService::getComposerService());
Mathias Agopian698c0872011-06-28 19:09:31 -0700188
189 Vector<ComposerState> transaction;
Mathias Agopian8b33f032012-07-24 20:43:54 -0700190 Vector<DisplayState> displayTransaction;
Jamie Gennis28378392011-10-12 17:39:00 -0700191 uint32_t flags = 0;
Mathias Agopian698c0872011-06-28 19:09:31 -0700192
193 { // scope for the lock
194 Mutex::Autolock _l(mLock);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700195 transaction = mComposerStates;
196 mComposerStates.clear();
Jamie Gennisb8d69a52011-10-10 15:48:06 -0700197
Mathias Agopiane57f2922012-08-09 16:29:12 -0700198 displayTransaction = mDisplayStates;
199 mDisplayStates.clear();
Jamie Gennis28378392011-10-12 17:39:00 -0700200
201 if (synchronous || mForceSynchronous) {
202 flags |= ISurfaceComposer::eSynchronous;
203 }
Jamie Gennis2d5e2302012-10-15 18:24:43 -0700204 if (mAnimation) {
205 flags |= ISurfaceComposer::eAnimation;
206 }
207
Jamie Gennis28378392011-10-12 17:39:00 -0700208 mForceSynchronous = false;
Jamie Gennis2d5e2302012-10-15 18:24:43 -0700209 mAnimation = false;
Mathias Agopian698c0872011-06-28 19:09:31 -0700210 }
211
Mathias Agopian8b33f032012-07-24 20:43:54 -0700212 sm->setTransactionState(transaction, displayTransaction, flags);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800213}
214
Jamie Gennis2d5e2302012-10-15 18:24:43 -0700215void Composer::setAnimationTransactionImpl() {
216 Mutex::Autolock _l(mLock);
217 mAnimation = true;
218}
219
Mathias Agopian698c0872011-06-28 19:09:31 -0700220layer_state_t* Composer::getLayerStateLocked(
221 const sp<SurfaceComposerClient>& client, SurfaceID id) {
222
223 ComposerState s;
224 s.client = client->mClient;
225 s.state.surface = id;
226
Mathias Agopiane57f2922012-08-09 16:29:12 -0700227 ssize_t index = mComposerStates.indexOf(s);
Mathias Agopian698c0872011-06-28 19:09:31 -0700228 if (index < 0) {
229 // we don't have it, add an initialized layer_state to our list
Mathias Agopiane57f2922012-08-09 16:29:12 -0700230 index = mComposerStates.add(s);
Mathias Agopian698c0872011-06-28 19:09:31 -0700231 }
232
Mathias Agopiane57f2922012-08-09 16:29:12 -0700233 ComposerState* const out = mComposerStates.editArray();
Mathias Agopian698c0872011-06-28 19:09:31 -0700234 return &(out[index].state);
235}
236
237status_t Composer::setPosition(const sp<SurfaceComposerClient>& client,
Mathias Agopian41b6aab2011-08-30 18:51:54 -0700238 SurfaceID id, float x, float y) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700239 Mutex::Autolock _l(mLock);
240 layer_state_t* s = getLayerStateLocked(client, id);
241 if (!s)
242 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700243 s->what |= layer_state_t::ePositionChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700244 s->x = x;
245 s->y = y;
246 return NO_ERROR;
247}
248
249status_t Composer::setSize(const sp<SurfaceComposerClient>& client,
250 SurfaceID id, uint32_t w, uint32_t h) {
251 Mutex::Autolock _l(mLock);
252 layer_state_t* s = getLayerStateLocked(client, id);
253 if (!s)
254 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700255 s->what |= layer_state_t::eSizeChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700256 s->w = w;
257 s->h = h;
Jamie Gennis28378392011-10-12 17:39:00 -0700258
259 // Resizing a surface makes the transaction synchronous.
260 mForceSynchronous = true;
261
Mathias Agopian698c0872011-06-28 19:09:31 -0700262 return NO_ERROR;
263}
264
265status_t Composer::setLayer(const sp<SurfaceComposerClient>& client,
266 SurfaceID id, int32_t z) {
267 Mutex::Autolock _l(mLock);
268 layer_state_t* s = getLayerStateLocked(client, id);
269 if (!s)
270 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700271 s->what |= layer_state_t::eLayerChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700272 s->z = z;
273 return NO_ERROR;
274}
275
276status_t Composer::setFlags(const sp<SurfaceComposerClient>& client,
277 SurfaceID id, uint32_t flags,
278 uint32_t mask) {
279 Mutex::Autolock _l(mLock);
280 layer_state_t* s = getLayerStateLocked(client, id);
281 if (!s)
282 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700283 s->what |= layer_state_t::eVisibilityChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700284 s->flags &= ~mask;
285 s->flags |= (flags & mask);
286 s->mask |= mask;
287 return NO_ERROR;
288}
289
290status_t Composer::setTransparentRegionHint(
291 const sp<SurfaceComposerClient>& client, SurfaceID id,
292 const Region& transparentRegion) {
293 Mutex::Autolock _l(mLock);
294 layer_state_t* s = getLayerStateLocked(client, id);
295 if (!s)
296 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700297 s->what |= layer_state_t::eTransparentRegionChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700298 s->transparentRegion = transparentRegion;
299 return NO_ERROR;
300}
301
302status_t Composer::setAlpha(const sp<SurfaceComposerClient>& client,
303 SurfaceID id, float alpha) {
304 Mutex::Autolock _l(mLock);
305 layer_state_t* s = getLayerStateLocked(client, id);
306 if (!s)
307 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700308 s->what |= layer_state_t::eAlphaChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700309 s->alpha = alpha;
310 return NO_ERROR;
311}
312
Mathias Agopian87855782012-07-24 21:41:09 -0700313status_t Composer::setLayerStack(const sp<SurfaceComposerClient>& client,
314 SurfaceID id, uint32_t layerStack) {
315 Mutex::Autolock _l(mLock);
316 layer_state_t* s = getLayerStateLocked(client, id);
317 if (!s)
318 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700319 s->what |= layer_state_t::eLayerStackChanged;
Mathias Agopian87855782012-07-24 21:41:09 -0700320 s->layerStack = layerStack;
321 return NO_ERROR;
322}
323
Mathias Agopian698c0872011-06-28 19:09:31 -0700324status_t Composer::setMatrix(const sp<SurfaceComposerClient>& client,
325 SurfaceID id, float dsdx, float dtdx,
326 float dsdy, float dtdy) {
327 Mutex::Autolock _l(mLock);
328 layer_state_t* s = getLayerStateLocked(client, id);
329 if (!s)
330 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700331 s->what |= layer_state_t::eMatrixChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700332 layer_state_t::matrix22_t matrix;
333 matrix.dsdx = dsdx;
334 matrix.dtdx = dtdx;
335 matrix.dsdy = dsdy;
336 matrix.dtdy = dtdy;
337 s->matrix = matrix;
338 return NO_ERROR;
339}
340
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700341status_t Composer::setCrop(const sp<SurfaceComposerClient>& client,
342 SurfaceID id, const Rect& crop) {
343 Mutex::Autolock _l(mLock);
344 layer_state_t* s = getLayerStateLocked(client, id);
345 if (!s)
346 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700347 s->what |= layer_state_t::eCropChanged;
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700348 s->crop = crop;
349 return NO_ERROR;
350}
351
Mathias Agopian698c0872011-06-28 19:09:31 -0700352// ---------------------------------------------------------------------------
353
Mathias Agopiane57f2922012-08-09 16:29:12 -0700354DisplayState& Composer::getDisplayStateLocked(const sp<IBinder>& token) {
355 DisplayState s;
356 s.token = token;
357 ssize_t index = mDisplayStates.indexOf(s);
358 if (index < 0) {
359 // we don't have it, add an initialized layer_state to our list
360 s.what = 0;
361 index = mDisplayStates.add(s);
362 }
363 return mDisplayStates.editItemAt(index);
364}
365
366void Composer::setDisplaySurface(const sp<IBinder>& token,
367 const sp<ISurfaceTexture>& surface) {
368 Mutex::Autolock _l(mLock);
369 DisplayState& s(getDisplayStateLocked(token));
370 s.surface = surface;
371 s.what |= DisplayState::eSurfaceChanged;
372}
373
374void Composer::setDisplayLayerStack(const sp<IBinder>& token,
375 uint32_t layerStack) {
376 Mutex::Autolock _l(mLock);
377 DisplayState& s(getDisplayStateLocked(token));
378 s.layerStack = layerStack;
379 s.what |= DisplayState::eLayerStackChanged;
380}
381
Mathias Agopian00e8c7a2012-09-04 19:30:46 -0700382void Composer::setDisplayProjection(const sp<IBinder>& token,
383 uint32_t orientation,
384 const Rect& layerStackRect,
385 const Rect& displayRect) {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700386 Mutex::Autolock _l(mLock);
387 DisplayState& s(getDisplayStateLocked(token));
388 s.orientation = orientation;
Mathias Agopian00e8c7a2012-09-04 19:30:46 -0700389 s.viewport = layerStackRect;
390 s.frame = displayRect;
391 s.what |= DisplayState::eDisplayProjectionChanged;
Mathias Agopiane57f2922012-08-09 16:29:12 -0700392 mForceSynchronous = true; // TODO: do we actually still need this?
393}
394
Mathias Agopiane57f2922012-08-09 16:29:12 -0700395// ---------------------------------------------------------------------------
396
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800397SurfaceComposerClient::SurfaceComposerClient()
Mathias Agopian698c0872011-06-28 19:09:31 -0700398 : mStatus(NO_INIT), mComposer(Composer::getInstance())
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800399{
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800400}
401
Mathias Agopian698c0872011-06-28 19:09:31 -0700402void SurfaceComposerClient::onFirstRef() {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700403 sp<ISurfaceComposer> sm(ComposerService::getComposerService());
Mathias Agopiand4784a32010-05-27 19:41:15 -0700404 if (sm != 0) {
Mathias Agopian7e27f052010-05-28 14:22:23 -0700405 sp<ISurfaceComposerClient> conn = sm->createConnection();
Mathias Agopiand4784a32010-05-27 19:41:15 -0700406 if (conn != 0) {
407 mClient = conn;
Mathias Agopiand4784a32010-05-27 19:41:15 -0700408 mStatus = NO_ERROR;
409 }
410 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800411}
412
Mathias Agopian698c0872011-06-28 19:09:31 -0700413SurfaceComposerClient::~SurfaceComposerClient() {
Mathias Agopian631f3582010-05-25 17:51:34 -0700414 dispose();
415}
Mathias Agopiandd3423c2009-09-23 15:44:05 -0700416
Mathias Agopian698c0872011-06-28 19:09:31 -0700417status_t SurfaceComposerClient::initCheck() const {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800418 return mStatus;
419}
420
Mathias Agopian698c0872011-06-28 19:09:31 -0700421sp<IBinder> SurfaceComposerClient::connection() const {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800422 return (mClient != 0) ? mClient->asBinder() : 0;
423}
424
Mathias Agopiand4784a32010-05-27 19:41:15 -0700425status_t SurfaceComposerClient::linkToComposerDeath(
426 const sp<IBinder::DeathRecipient>& recipient,
Mathias Agopian698c0872011-06-28 19:09:31 -0700427 void* cookie, uint32_t flags) {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700428 sp<ISurfaceComposer> sm(ComposerService::getComposerService());
Mathias Agopiand4784a32010-05-27 19:41:15 -0700429 return sm->asBinder()->linkToDeath(recipient, cookie, flags);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800430}
431
Mathias Agopian698c0872011-06-28 19:09:31 -0700432void SurfaceComposerClient::dispose() {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800433 // this can be called more than once.
Mathias Agopian7e27f052010-05-28 14:22:23 -0700434 sp<ISurfaceComposerClient> client;
Mathias Agopiand4784a32010-05-27 19:41:15 -0700435 Mutex::Autolock _lm(mLock);
436 if (mClient != 0) {
Mathias Agopiand4784a32010-05-27 19:41:15 -0700437 client = mClient; // hold ref while lock is held
438 mClient.clear();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800439 }
Mathias Agopiand4784a32010-05-27 19:41:15 -0700440 mStatus = NO_INIT;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800441}
442
Mathias Agopian698c0872011-06-28 19:09:31 -0700443sp<SurfaceControl> SurfaceComposerClient::createSurface(
Mathias Agopian698c0872011-06-28 19:09:31 -0700444 const String8& name,
Mathias Agopian698c0872011-06-28 19:09:31 -0700445 uint32_t w,
446 uint32_t h,
447 PixelFormat format,
448 uint32_t flags)
449{
450 sp<SurfaceControl> result;
451 if (mStatus == NO_ERROR) {
452 ISurfaceComposerClient::surface_data_t data;
453 sp<ISurface> surface = mClient->createSurface(&data, name,
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700454 w, h, format, flags);
Mathias Agopian698c0872011-06-28 19:09:31 -0700455 if (surface != 0) {
Mathias Agopianc10d9d92011-07-20 16:46:11 -0700456 result = new SurfaceControl(this, surface, data);
Mathias Agopian698c0872011-06-28 19:09:31 -0700457 }
458 }
459 return result;
460}
461
Andy McFadden8dfa92f2012-09-17 18:27:17 -0700462sp<IBinder> SurfaceComposerClient::createDisplay(const String8& displayName) {
463 return Composer::getInstance().createDisplay(displayName);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700464}
465
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700466sp<IBinder> SurfaceComposerClient::getBuiltInDisplay(int32_t id) {
467 return Composer::getInstance().getBuiltInDisplay(id);
468}
469
Mathias Agopian698c0872011-06-28 19:09:31 -0700470status_t SurfaceComposerClient::destroySurface(SurfaceID sid) {
471 if (mStatus != NO_ERROR)
472 return mStatus;
473 status_t err = mClient->destroySurface(sid);
474 return err;
475}
476
477inline Composer& SurfaceComposerClient::getComposer() {
478 return mComposer;
479}
480
481// ----------------------------------------------------------------------------
482
483void SurfaceComposerClient::openGlobalTransaction() {
484 // Currently a no-op
485}
486
Jamie Gennis28378392011-10-12 17:39:00 -0700487void SurfaceComposerClient::closeGlobalTransaction(bool synchronous) {
488 Composer::closeGlobalTransaction(synchronous);
Mathias Agopian698c0872011-06-28 19:09:31 -0700489}
490
Jamie Gennis2d5e2302012-10-15 18:24:43 -0700491void SurfaceComposerClient::setAnimationTransaction() {
492 Composer::setAnimationTransaction();
493}
494
Mathias Agopian698c0872011-06-28 19:09:31 -0700495// ----------------------------------------------------------------------------
496
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700497status_t SurfaceComposerClient::setCrop(SurfaceID id, const Rect& crop) {
498 return getComposer().setCrop(this, id, crop);
499}
500
Mathias Agopian41b6aab2011-08-30 18:51:54 -0700501status_t SurfaceComposerClient::setPosition(SurfaceID id, float x, float y) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700502 return getComposer().setPosition(this, id, x, y);
503}
504
505status_t SurfaceComposerClient::setSize(SurfaceID id, uint32_t w, uint32_t h) {
506 return getComposer().setSize(this, id, w, h);
507}
508
509status_t SurfaceComposerClient::setLayer(SurfaceID id, int32_t z) {
510 return getComposer().setLayer(this, id, z);
511}
512
513status_t SurfaceComposerClient::hide(SurfaceID id) {
514 return getComposer().setFlags(this, id,
Mathias Agopian3165cc22012-08-08 19:42:09 -0700515 layer_state_t::eLayerHidden,
516 layer_state_t::eLayerHidden);
Mathias Agopian698c0872011-06-28 19:09:31 -0700517}
518
Jeff Brown380223b2012-08-26 22:49:35 -0700519status_t SurfaceComposerClient::show(SurfaceID id) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700520 return getComposer().setFlags(this, id,
521 0,
Mathias Agopian3165cc22012-08-08 19:42:09 -0700522 layer_state_t::eLayerHidden);
Mathias Agopian698c0872011-06-28 19:09:31 -0700523}
524
Mathias Agopian698c0872011-06-28 19:09:31 -0700525status_t SurfaceComposerClient::setFlags(SurfaceID id, uint32_t flags,
526 uint32_t mask) {
527 return getComposer().setFlags(this, id, flags, mask);
528}
529
530status_t SurfaceComposerClient::setTransparentRegionHint(SurfaceID id,
531 const Region& transparentRegion) {
532 return getComposer().setTransparentRegionHint(this, id, transparentRegion);
533}
534
535status_t SurfaceComposerClient::setAlpha(SurfaceID id, float alpha) {
536 return getComposer().setAlpha(this, id, alpha);
537}
538
Mathias Agopian87855782012-07-24 21:41:09 -0700539status_t SurfaceComposerClient::setLayerStack(SurfaceID id, uint32_t layerStack) {
540 return getComposer().setLayerStack(this, id, layerStack);
541}
542
Mathias Agopian698c0872011-06-28 19:09:31 -0700543status_t SurfaceComposerClient::setMatrix(SurfaceID id, float dsdx, float dtdx,
544 float dsdy, float dtdy) {
545 return getComposer().setMatrix(this, id, dsdx, dtdx, dsdy, dtdy);
546}
547
548// ----------------------------------------------------------------------------
549
Mathias Agopiane57f2922012-08-09 16:29:12 -0700550void SurfaceComposerClient::setDisplaySurface(const sp<IBinder>& token,
551 const sp<ISurfaceTexture>& surface) {
552 Composer::getInstance().setDisplaySurface(token, surface);
553}
554
555void SurfaceComposerClient::setDisplayLayerStack(const sp<IBinder>& token,
556 uint32_t layerStack) {
557 Composer::getInstance().setDisplayLayerStack(token, layerStack);
558}
559
Mathias Agopian00e8c7a2012-09-04 19:30:46 -0700560void SurfaceComposerClient::setDisplayProjection(const sp<IBinder>& token,
561 uint32_t orientation,
562 const Rect& layerStackRect,
563 const Rect& displayRect) {
564 Composer::getInstance().setDisplayProjection(token, orientation,
565 layerStackRect, displayRect);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700566}
567
568// ----------------------------------------------------------------------------
569
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800570status_t SurfaceComposerClient::getDisplayInfo(
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700571 const sp<IBinder>& display, DisplayInfo* info)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800572{
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700573 return ComposerService::getComposerService()->getDisplayInfo(display, info);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800574}
575
Jeff Brown2a09bb32012-10-08 19:13:57 -0700576void SurfaceComposerClient::blankDisplay(const sp<IBinder>& token) {
577 ComposerService::getComposerService()->blank(token);
578}
579
580void SurfaceComposerClient::unblankDisplay(const sp<IBinder>& token) {
581 ComposerService::getComposerService()->unblank(token);
582}
583
Mathias Agopian698c0872011-06-28 19:09:31 -0700584// ----------------------------------------------------------------------------
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800585
Mathias Agopian74c40c02010-09-29 13:02:36 -0700586ScreenshotClient::ScreenshotClient()
587 : mWidth(0), mHeight(0), mFormat(PIXEL_FORMAT_NONE) {
588}
589
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700590status_t ScreenshotClient::update(const sp<IBinder>& display) {
Mathias Agopian74c40c02010-09-29 13:02:36 -0700591 sp<ISurfaceComposer> s(ComposerService::getComposerService());
592 if (s == NULL) return NO_INIT;
593 mHeap = 0;
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700594 return s->captureScreen(display, &mHeap,
Mathias Agopianbf2c6a62010-12-10 16:22:31 -0800595 &mWidth, &mHeight, &mFormat, 0, 0,
596 0, -1UL);
Mathias Agopian74c40c02010-09-29 13:02:36 -0700597}
598
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700599status_t ScreenshotClient::update(const sp<IBinder>& display,
600 uint32_t reqWidth, uint32_t reqHeight) {
Mathias Agopian74c40c02010-09-29 13:02:36 -0700601 sp<ISurfaceComposer> s(ComposerService::getComposerService());
602 if (s == NULL) return NO_INIT;
603 mHeap = 0;
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700604 return s->captureScreen(display, &mHeap,
Mathias Agopianbf2c6a62010-12-10 16:22:31 -0800605 &mWidth, &mHeight, &mFormat, reqWidth, reqHeight,
606 0, -1UL);
607}
608
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700609status_t ScreenshotClient::update(const sp<IBinder>& display,
610 uint32_t reqWidth, uint32_t reqHeight,
Mathias Agopianbf2c6a62010-12-10 16:22:31 -0800611 uint32_t minLayerZ, uint32_t maxLayerZ) {
612 sp<ISurfaceComposer> s(ComposerService::getComposerService());
613 if (s == NULL) return NO_INIT;
614 mHeap = 0;
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700615 return s->captureScreen(display, &mHeap,
Mathias Agopianbf2c6a62010-12-10 16:22:31 -0800616 &mWidth, &mHeight, &mFormat, reqWidth, reqHeight,
617 minLayerZ, maxLayerZ);
Mathias Agopian74c40c02010-09-29 13:02:36 -0700618}
619
620void ScreenshotClient::release() {
621 mHeap = 0;
622}
623
624void const* ScreenshotClient::getPixels() const {
625 return mHeap->getBase();
626}
627
628uint32_t ScreenshotClient::getWidth() const {
629 return mWidth;
630}
631
632uint32_t ScreenshotClient::getHeight() const {
633 return mHeight;
634}
635
636PixelFormat ScreenshotClient::getFormat() const {
637 return mFormat;
638}
639
640uint32_t ScreenshotClient::getStride() const {
641 return mWidth;
642}
643
644size_t ScreenshotClient::getSize() const {
645 return mHeap->getSize();
646}
647
648// ----------------------------------------------------------------------------
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800649}; // namespace android