blob: 746057b4298d9910ebd3e63c6899e89a3ce398a8 [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;
Jeff Brownf3f7db62012-08-31 02:18:38 -0700118 uint32_t mTransactionNestCount;
Jamie Gennis2d5e2302012-10-15 18:24:43 -0700119 bool mAnimation;
Mathias Agopian698c0872011-06-28 19:09:31 -0700120
Jamie Gennisb8d69a52011-10-10 15:48:06 -0700121 Composer() : Singleton<Composer>(),
Jeff Brownf3f7db62012-08-31 02:18:38 -0700122 mForceSynchronous(0), mTransactionNestCount(0),
Jamie Gennis2d5e2302012-10-15 18:24:43 -0700123 mAnimation(false)
Jamie Gennis28378392011-10-12 17:39:00 -0700124 { }
Mathias Agopian698c0872011-06-28 19:09:31 -0700125
Jeff Brownf3f7db62012-08-31 02:18:38 -0700126 void openGlobalTransactionImpl();
Jamie Gennis28378392011-10-12 17:39:00 -0700127 void closeGlobalTransactionImpl(bool synchronous);
Jamie Gennis2d5e2302012-10-15 18:24:43 -0700128 void setAnimationTransactionImpl();
Mathias Agopian698c0872011-06-28 19:09:31 -0700129
130 layer_state_t* getLayerStateLocked(
131 const sp<SurfaceComposerClient>& client, SurfaceID id);
132
Mathias Agopiane57f2922012-08-09 16:29:12 -0700133 DisplayState& getDisplayStateLocked(const sp<IBinder>& token);
134
Mathias Agopiand4784a32010-05-27 19:41:15 -0700135public:
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700136 sp<IBinder> createDisplay(const String8& displayName, bool secure);
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700137 sp<IBinder> getBuiltInDisplay(int32_t id);
Mathias Agopian698c0872011-06-28 19:09:31 -0700138
139 status_t setPosition(const sp<SurfaceComposerClient>& client, SurfaceID id,
Mathias Agopian41b6aab2011-08-30 18:51:54 -0700140 float x, float y);
Mathias Agopian698c0872011-06-28 19:09:31 -0700141 status_t setSize(const sp<SurfaceComposerClient>& client, SurfaceID id,
142 uint32_t w, uint32_t h);
143 status_t setLayer(const sp<SurfaceComposerClient>& client, SurfaceID id,
144 int32_t z);
145 status_t setFlags(const sp<SurfaceComposerClient>& client, SurfaceID id,
146 uint32_t flags, uint32_t mask);
147 status_t setTransparentRegionHint(
148 const sp<SurfaceComposerClient>& client, SurfaceID id,
149 const Region& transparentRegion);
150 status_t setAlpha(const sp<SurfaceComposerClient>& client, SurfaceID id,
151 float alpha);
152 status_t setMatrix(const sp<SurfaceComposerClient>& client, SurfaceID id,
153 float dsdx, float dtdx, float dsdy, float dtdy);
Jamie Gennisb8d69a52011-10-10 15:48:06 -0700154 status_t setOrientation(int orientation);
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700155 status_t setCrop(const sp<SurfaceComposerClient>& client, SurfaceID id,
156 const Rect& crop);
Mathias Agopian87855782012-07-24 21:41:09 -0700157 status_t setLayerStack(const sp<SurfaceComposerClient>& client,
158 SurfaceID id, uint32_t layerStack);
Mathias Agopian698c0872011-06-28 19:09:31 -0700159
Mathias Agopiane57f2922012-08-09 16:29:12 -0700160 void setDisplaySurface(const sp<IBinder>& token, const sp<ISurfaceTexture>& surface);
161 void setDisplayLayerStack(const sp<IBinder>& token, uint32_t layerStack);
Mathias Agopian00e8c7a2012-09-04 19:30:46 -0700162 void setDisplayProjection(const sp<IBinder>& token,
163 uint32_t orientation,
164 const Rect& layerStackRect,
165 const Rect& displayRect);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700166
Jamie Gennis2d5e2302012-10-15 18:24:43 -0700167 static void setAnimationTransaction() {
168 Composer::getInstance().setAnimationTransactionImpl();
169 }
170
Jeff Brownf3f7db62012-08-31 02:18:38 -0700171 static void openGlobalTransaction() {
172 Composer::getInstance().openGlobalTransactionImpl();
173 }
174
Jamie Gennis28378392011-10-12 17:39:00 -0700175 static void closeGlobalTransaction(bool synchronous) {
176 Composer::getInstance().closeGlobalTransactionImpl(synchronous);
Mathias Agopiand4784a32010-05-27 19:41:15 -0700177 }
178};
179
180ANDROID_SINGLETON_STATIC_INSTANCE(Composer);
181
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800182// ---------------------------------------------------------------------------
183
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700184sp<IBinder> Composer::createDisplay(const String8& displayName, bool secure) {
185 return ComposerService::getComposerService()->createDisplay(displayName,
186 secure);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700187}
188
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700189sp<IBinder> Composer::getBuiltInDisplay(int32_t id) {
190 return ComposerService::getComposerService()->getBuiltInDisplay(id);
191}
192
Jeff Brownf3f7db62012-08-31 02:18:38 -0700193void Composer::openGlobalTransactionImpl() {
194 { // scope for the lock
195 Mutex::Autolock _l(mLock);
196 mTransactionNestCount += 1;
197 }
198}
199
Jamie Gennis28378392011-10-12 17:39:00 -0700200void Composer::closeGlobalTransactionImpl(bool synchronous) {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700201 sp<ISurfaceComposer> sm(ComposerService::getComposerService());
Mathias Agopian698c0872011-06-28 19:09:31 -0700202
203 Vector<ComposerState> transaction;
Mathias Agopian8b33f032012-07-24 20:43:54 -0700204 Vector<DisplayState> displayTransaction;
Jamie Gennis28378392011-10-12 17:39:00 -0700205 uint32_t flags = 0;
Mathias Agopian698c0872011-06-28 19:09:31 -0700206
207 { // scope for the lock
208 Mutex::Autolock _l(mLock);
Jeff Brownf3f7db62012-08-31 02:18:38 -0700209 mForceSynchronous |= synchronous;
210 if (!mTransactionNestCount) {
211 ALOGW("At least one call to closeGlobalTransaction() was not matched by a prior "
212 "call to openGlobalTransaction().");
213 } else if (--mTransactionNestCount) {
214 return;
215 }
216
Mathias Agopiane57f2922012-08-09 16:29:12 -0700217 transaction = mComposerStates;
218 mComposerStates.clear();
Jamie Gennisb8d69a52011-10-10 15:48:06 -0700219
Mathias Agopiane57f2922012-08-09 16:29:12 -0700220 displayTransaction = mDisplayStates;
221 mDisplayStates.clear();
Jamie Gennis28378392011-10-12 17:39:00 -0700222
Jeff Brownf3f7db62012-08-31 02:18:38 -0700223 if (mForceSynchronous) {
Jamie Gennis28378392011-10-12 17:39:00 -0700224 flags |= ISurfaceComposer::eSynchronous;
225 }
Jamie Gennis2d5e2302012-10-15 18:24:43 -0700226 if (mAnimation) {
227 flags |= ISurfaceComposer::eAnimation;
228 }
229
Jamie Gennis28378392011-10-12 17:39:00 -0700230 mForceSynchronous = false;
Jamie Gennis2d5e2302012-10-15 18:24:43 -0700231 mAnimation = false;
Mathias Agopian698c0872011-06-28 19:09:31 -0700232 }
233
Mathias Agopian8b33f032012-07-24 20:43:54 -0700234 sm->setTransactionState(transaction, displayTransaction, flags);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800235}
236
Jamie Gennis2d5e2302012-10-15 18:24:43 -0700237void Composer::setAnimationTransactionImpl() {
238 Mutex::Autolock _l(mLock);
239 mAnimation = true;
240}
241
Mathias Agopian698c0872011-06-28 19:09:31 -0700242layer_state_t* Composer::getLayerStateLocked(
243 const sp<SurfaceComposerClient>& client, SurfaceID id) {
244
245 ComposerState s;
246 s.client = client->mClient;
247 s.state.surface = id;
248
Mathias Agopiane57f2922012-08-09 16:29:12 -0700249 ssize_t index = mComposerStates.indexOf(s);
Mathias Agopian698c0872011-06-28 19:09:31 -0700250 if (index < 0) {
251 // we don't have it, add an initialized layer_state to our list
Mathias Agopiane57f2922012-08-09 16:29:12 -0700252 index = mComposerStates.add(s);
Mathias Agopian698c0872011-06-28 19:09:31 -0700253 }
254
Mathias Agopiane57f2922012-08-09 16:29:12 -0700255 ComposerState* const out = mComposerStates.editArray();
Mathias Agopian698c0872011-06-28 19:09:31 -0700256 return &(out[index].state);
257}
258
259status_t Composer::setPosition(const sp<SurfaceComposerClient>& client,
Mathias Agopian41b6aab2011-08-30 18:51:54 -0700260 SurfaceID id, float x, float y) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700261 Mutex::Autolock _l(mLock);
262 layer_state_t* s = getLayerStateLocked(client, id);
263 if (!s)
264 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700265 s->what |= layer_state_t::ePositionChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700266 s->x = x;
267 s->y = y;
268 return NO_ERROR;
269}
270
271status_t Composer::setSize(const sp<SurfaceComposerClient>& client,
272 SurfaceID id, uint32_t w, uint32_t h) {
273 Mutex::Autolock _l(mLock);
274 layer_state_t* s = getLayerStateLocked(client, id);
275 if (!s)
276 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700277 s->what |= layer_state_t::eSizeChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700278 s->w = w;
279 s->h = h;
Jamie Gennis28378392011-10-12 17:39:00 -0700280
281 // Resizing a surface makes the transaction synchronous.
282 mForceSynchronous = true;
283
Mathias Agopian698c0872011-06-28 19:09:31 -0700284 return NO_ERROR;
285}
286
287status_t Composer::setLayer(const sp<SurfaceComposerClient>& client,
288 SurfaceID id, int32_t z) {
289 Mutex::Autolock _l(mLock);
290 layer_state_t* s = getLayerStateLocked(client, id);
291 if (!s)
292 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700293 s->what |= layer_state_t::eLayerChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700294 s->z = z;
295 return NO_ERROR;
296}
297
298status_t Composer::setFlags(const sp<SurfaceComposerClient>& client,
299 SurfaceID id, uint32_t flags,
300 uint32_t mask) {
301 Mutex::Autolock _l(mLock);
302 layer_state_t* s = getLayerStateLocked(client, id);
303 if (!s)
304 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700305 s->what |= layer_state_t::eVisibilityChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700306 s->flags &= ~mask;
307 s->flags |= (flags & mask);
308 s->mask |= mask;
309 return NO_ERROR;
310}
311
312status_t Composer::setTransparentRegionHint(
313 const sp<SurfaceComposerClient>& client, SurfaceID id,
314 const Region& transparentRegion) {
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::eTransparentRegionChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700320 s->transparentRegion = transparentRegion;
321 return NO_ERROR;
322}
323
324status_t Composer::setAlpha(const sp<SurfaceComposerClient>& client,
325 SurfaceID id, float alpha) {
326 Mutex::Autolock _l(mLock);
327 layer_state_t* s = getLayerStateLocked(client, id);
328 if (!s)
329 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700330 s->what |= layer_state_t::eAlphaChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700331 s->alpha = alpha;
332 return NO_ERROR;
333}
334
Mathias Agopian87855782012-07-24 21:41:09 -0700335status_t Composer::setLayerStack(const sp<SurfaceComposerClient>& client,
336 SurfaceID id, uint32_t layerStack) {
337 Mutex::Autolock _l(mLock);
338 layer_state_t* s = getLayerStateLocked(client, id);
339 if (!s)
340 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700341 s->what |= layer_state_t::eLayerStackChanged;
Mathias Agopian87855782012-07-24 21:41:09 -0700342 s->layerStack = layerStack;
343 return NO_ERROR;
344}
345
Mathias Agopian698c0872011-06-28 19:09:31 -0700346status_t Composer::setMatrix(const sp<SurfaceComposerClient>& client,
347 SurfaceID id, float dsdx, float dtdx,
348 float dsdy, float dtdy) {
349 Mutex::Autolock _l(mLock);
350 layer_state_t* s = getLayerStateLocked(client, id);
351 if (!s)
352 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700353 s->what |= layer_state_t::eMatrixChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700354 layer_state_t::matrix22_t matrix;
355 matrix.dsdx = dsdx;
356 matrix.dtdx = dtdx;
357 matrix.dsdy = dsdy;
358 matrix.dtdy = dtdy;
359 s->matrix = matrix;
360 return NO_ERROR;
361}
362
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700363status_t Composer::setCrop(const sp<SurfaceComposerClient>& client,
364 SurfaceID id, const Rect& crop) {
365 Mutex::Autolock _l(mLock);
366 layer_state_t* s = getLayerStateLocked(client, id);
367 if (!s)
368 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700369 s->what |= layer_state_t::eCropChanged;
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700370 s->crop = crop;
371 return NO_ERROR;
372}
373
Mathias Agopian698c0872011-06-28 19:09:31 -0700374// ---------------------------------------------------------------------------
375
Mathias Agopiane57f2922012-08-09 16:29:12 -0700376DisplayState& Composer::getDisplayStateLocked(const sp<IBinder>& token) {
377 DisplayState s;
378 s.token = token;
379 ssize_t index = mDisplayStates.indexOf(s);
380 if (index < 0) {
381 // we don't have it, add an initialized layer_state to our list
382 s.what = 0;
383 index = mDisplayStates.add(s);
384 }
385 return mDisplayStates.editItemAt(index);
386}
387
388void Composer::setDisplaySurface(const sp<IBinder>& token,
389 const sp<ISurfaceTexture>& surface) {
390 Mutex::Autolock _l(mLock);
391 DisplayState& s(getDisplayStateLocked(token));
392 s.surface = surface;
393 s.what |= DisplayState::eSurfaceChanged;
394}
395
396void Composer::setDisplayLayerStack(const sp<IBinder>& token,
397 uint32_t layerStack) {
398 Mutex::Autolock _l(mLock);
399 DisplayState& s(getDisplayStateLocked(token));
400 s.layerStack = layerStack;
401 s.what |= DisplayState::eLayerStackChanged;
402}
403
Mathias Agopian00e8c7a2012-09-04 19:30:46 -0700404void Composer::setDisplayProjection(const sp<IBinder>& token,
405 uint32_t orientation,
406 const Rect& layerStackRect,
407 const Rect& displayRect) {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700408 Mutex::Autolock _l(mLock);
409 DisplayState& s(getDisplayStateLocked(token));
410 s.orientation = orientation;
Mathias Agopian00e8c7a2012-09-04 19:30:46 -0700411 s.viewport = layerStackRect;
412 s.frame = displayRect;
413 s.what |= DisplayState::eDisplayProjectionChanged;
Mathias Agopiane57f2922012-08-09 16:29:12 -0700414 mForceSynchronous = true; // TODO: do we actually still need this?
415}
416
Mathias Agopiane57f2922012-08-09 16:29:12 -0700417// ---------------------------------------------------------------------------
418
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800419SurfaceComposerClient::SurfaceComposerClient()
Mathias Agopian698c0872011-06-28 19:09:31 -0700420 : mStatus(NO_INIT), mComposer(Composer::getInstance())
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800421{
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800422}
423
Mathias Agopian698c0872011-06-28 19:09:31 -0700424void SurfaceComposerClient::onFirstRef() {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700425 sp<ISurfaceComposer> sm(ComposerService::getComposerService());
Mathias Agopiand4784a32010-05-27 19:41:15 -0700426 if (sm != 0) {
Mathias Agopian7e27f052010-05-28 14:22:23 -0700427 sp<ISurfaceComposerClient> conn = sm->createConnection();
Mathias Agopiand4784a32010-05-27 19:41:15 -0700428 if (conn != 0) {
429 mClient = conn;
Mathias Agopiand4784a32010-05-27 19:41:15 -0700430 mStatus = NO_ERROR;
431 }
432 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800433}
434
Mathias Agopian698c0872011-06-28 19:09:31 -0700435SurfaceComposerClient::~SurfaceComposerClient() {
Mathias Agopian631f3582010-05-25 17:51:34 -0700436 dispose();
437}
Mathias Agopiandd3423c2009-09-23 15:44:05 -0700438
Mathias Agopian698c0872011-06-28 19:09:31 -0700439status_t SurfaceComposerClient::initCheck() const {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800440 return mStatus;
441}
442
Mathias Agopian698c0872011-06-28 19:09:31 -0700443sp<IBinder> SurfaceComposerClient::connection() const {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800444 return (mClient != 0) ? mClient->asBinder() : 0;
445}
446
Mathias Agopiand4784a32010-05-27 19:41:15 -0700447status_t SurfaceComposerClient::linkToComposerDeath(
448 const sp<IBinder::DeathRecipient>& recipient,
Mathias Agopian698c0872011-06-28 19:09:31 -0700449 void* cookie, uint32_t flags) {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700450 sp<ISurfaceComposer> sm(ComposerService::getComposerService());
Mathias Agopiand4784a32010-05-27 19:41:15 -0700451 return sm->asBinder()->linkToDeath(recipient, cookie, flags);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800452}
453
Mathias Agopian698c0872011-06-28 19:09:31 -0700454void SurfaceComposerClient::dispose() {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800455 // this can be called more than once.
Mathias Agopian7e27f052010-05-28 14:22:23 -0700456 sp<ISurfaceComposerClient> client;
Mathias Agopiand4784a32010-05-27 19:41:15 -0700457 Mutex::Autolock _lm(mLock);
458 if (mClient != 0) {
Mathias Agopiand4784a32010-05-27 19:41:15 -0700459 client = mClient; // hold ref while lock is held
460 mClient.clear();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800461 }
Mathias Agopiand4784a32010-05-27 19:41:15 -0700462 mStatus = NO_INIT;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800463}
464
Mathias Agopian698c0872011-06-28 19:09:31 -0700465sp<SurfaceControl> SurfaceComposerClient::createSurface(
Mathias Agopian698c0872011-06-28 19:09:31 -0700466 const String8& name,
Mathias Agopian698c0872011-06-28 19:09:31 -0700467 uint32_t w,
468 uint32_t h,
469 PixelFormat format,
470 uint32_t flags)
471{
472 sp<SurfaceControl> result;
473 if (mStatus == NO_ERROR) {
474 ISurfaceComposerClient::surface_data_t data;
475 sp<ISurface> surface = mClient->createSurface(&data, name,
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700476 w, h, format, flags);
Mathias Agopian698c0872011-06-28 19:09:31 -0700477 if (surface != 0) {
Mathias Agopianc10d9d92011-07-20 16:46:11 -0700478 result = new SurfaceControl(this, surface, data);
Mathias Agopian698c0872011-06-28 19:09:31 -0700479 }
480 }
481 return result;
482}
483
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700484sp<IBinder> SurfaceComposerClient::createDisplay(const String8& displayName,
485 bool secure) {
486 return Composer::getInstance().createDisplay(displayName, secure);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700487}
488
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700489sp<IBinder> SurfaceComposerClient::getBuiltInDisplay(int32_t id) {
490 return Composer::getInstance().getBuiltInDisplay(id);
491}
492
Mathias Agopian698c0872011-06-28 19:09:31 -0700493status_t SurfaceComposerClient::destroySurface(SurfaceID sid) {
494 if (mStatus != NO_ERROR)
495 return mStatus;
496 status_t err = mClient->destroySurface(sid);
497 return err;
498}
499
500inline Composer& SurfaceComposerClient::getComposer() {
501 return mComposer;
502}
503
504// ----------------------------------------------------------------------------
505
506void SurfaceComposerClient::openGlobalTransaction() {
Jeff Brownf3f7db62012-08-31 02:18:38 -0700507 Composer::openGlobalTransaction();
Mathias Agopian698c0872011-06-28 19:09:31 -0700508}
509
Jamie Gennis28378392011-10-12 17:39:00 -0700510void SurfaceComposerClient::closeGlobalTransaction(bool synchronous) {
511 Composer::closeGlobalTransaction(synchronous);
Mathias Agopian698c0872011-06-28 19:09:31 -0700512}
513
Jamie Gennis2d5e2302012-10-15 18:24:43 -0700514void SurfaceComposerClient::setAnimationTransaction() {
515 Composer::setAnimationTransaction();
516}
517
Mathias Agopian698c0872011-06-28 19:09:31 -0700518// ----------------------------------------------------------------------------
519
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700520status_t SurfaceComposerClient::setCrop(SurfaceID id, const Rect& crop) {
521 return getComposer().setCrop(this, id, crop);
522}
523
Mathias Agopian41b6aab2011-08-30 18:51:54 -0700524status_t SurfaceComposerClient::setPosition(SurfaceID id, float x, float y) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700525 return getComposer().setPosition(this, id, x, y);
526}
527
528status_t SurfaceComposerClient::setSize(SurfaceID id, uint32_t w, uint32_t h) {
529 return getComposer().setSize(this, id, w, h);
530}
531
532status_t SurfaceComposerClient::setLayer(SurfaceID id, int32_t z) {
533 return getComposer().setLayer(this, id, z);
534}
535
536status_t SurfaceComposerClient::hide(SurfaceID id) {
537 return getComposer().setFlags(this, id,
Mathias Agopian3165cc22012-08-08 19:42:09 -0700538 layer_state_t::eLayerHidden,
539 layer_state_t::eLayerHidden);
Mathias Agopian698c0872011-06-28 19:09:31 -0700540}
541
Jeff Brown380223b2012-08-26 22:49:35 -0700542status_t SurfaceComposerClient::show(SurfaceID id) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700543 return getComposer().setFlags(this, id,
544 0,
Mathias Agopian3165cc22012-08-08 19:42:09 -0700545 layer_state_t::eLayerHidden);
Mathias Agopian698c0872011-06-28 19:09:31 -0700546}
547
Mathias Agopian698c0872011-06-28 19:09:31 -0700548status_t SurfaceComposerClient::setFlags(SurfaceID id, uint32_t flags,
549 uint32_t mask) {
550 return getComposer().setFlags(this, id, flags, mask);
551}
552
553status_t SurfaceComposerClient::setTransparentRegionHint(SurfaceID id,
554 const Region& transparentRegion) {
555 return getComposer().setTransparentRegionHint(this, id, transparentRegion);
556}
557
558status_t SurfaceComposerClient::setAlpha(SurfaceID id, float alpha) {
559 return getComposer().setAlpha(this, id, alpha);
560}
561
Mathias Agopian87855782012-07-24 21:41:09 -0700562status_t SurfaceComposerClient::setLayerStack(SurfaceID id, uint32_t layerStack) {
563 return getComposer().setLayerStack(this, id, layerStack);
564}
565
Mathias Agopian698c0872011-06-28 19:09:31 -0700566status_t SurfaceComposerClient::setMatrix(SurfaceID id, float dsdx, float dtdx,
567 float dsdy, float dtdy) {
568 return getComposer().setMatrix(this, id, dsdx, dtdx, dsdy, dtdy);
569}
570
571// ----------------------------------------------------------------------------
572
Mathias Agopiane57f2922012-08-09 16:29:12 -0700573void SurfaceComposerClient::setDisplaySurface(const sp<IBinder>& token,
574 const sp<ISurfaceTexture>& surface) {
575 Composer::getInstance().setDisplaySurface(token, surface);
576}
577
578void SurfaceComposerClient::setDisplayLayerStack(const sp<IBinder>& token,
579 uint32_t layerStack) {
580 Composer::getInstance().setDisplayLayerStack(token, layerStack);
581}
582
Mathias Agopian00e8c7a2012-09-04 19:30:46 -0700583void SurfaceComposerClient::setDisplayProjection(const sp<IBinder>& token,
584 uint32_t orientation,
585 const Rect& layerStackRect,
586 const Rect& displayRect) {
587 Composer::getInstance().setDisplayProjection(token, orientation,
588 layerStackRect, displayRect);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700589}
590
591// ----------------------------------------------------------------------------
592
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800593status_t SurfaceComposerClient::getDisplayInfo(
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700594 const sp<IBinder>& display, DisplayInfo* info)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800595{
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700596 return ComposerService::getComposerService()->getDisplayInfo(display, info);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800597}
598
Jeff Brown2a09bb32012-10-08 19:13:57 -0700599void SurfaceComposerClient::blankDisplay(const sp<IBinder>& token) {
600 ComposerService::getComposerService()->blank(token);
601}
602
603void SurfaceComposerClient::unblankDisplay(const sp<IBinder>& token) {
604 ComposerService::getComposerService()->unblank(token);
605}
606
Mathias Agopian698c0872011-06-28 19:09:31 -0700607// ----------------------------------------------------------------------------
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800608
Mathias Agopian74c40c02010-09-29 13:02:36 -0700609ScreenshotClient::ScreenshotClient()
610 : mWidth(0), mHeight(0), mFormat(PIXEL_FORMAT_NONE) {
611}
612
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700613status_t ScreenshotClient::update(const sp<IBinder>& display) {
Mathias Agopian74c40c02010-09-29 13:02:36 -0700614 sp<ISurfaceComposer> s(ComposerService::getComposerService());
615 if (s == NULL) return NO_INIT;
616 mHeap = 0;
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700617 return s->captureScreen(display, &mHeap,
Mathias Agopianbf2c6a62010-12-10 16:22:31 -0800618 &mWidth, &mHeight, &mFormat, 0, 0,
619 0, -1UL);
Mathias Agopian74c40c02010-09-29 13:02:36 -0700620}
621
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700622status_t ScreenshotClient::update(const sp<IBinder>& display,
623 uint32_t reqWidth, uint32_t reqHeight) {
Mathias Agopian74c40c02010-09-29 13:02:36 -0700624 sp<ISurfaceComposer> s(ComposerService::getComposerService());
625 if (s == NULL) return NO_INIT;
626 mHeap = 0;
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700627 return s->captureScreen(display, &mHeap,
Mathias Agopianbf2c6a62010-12-10 16:22:31 -0800628 &mWidth, &mHeight, &mFormat, reqWidth, reqHeight,
629 0, -1UL);
630}
631
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700632status_t ScreenshotClient::update(const sp<IBinder>& display,
633 uint32_t reqWidth, uint32_t reqHeight,
Mathias Agopianbf2c6a62010-12-10 16:22:31 -0800634 uint32_t minLayerZ, uint32_t maxLayerZ) {
635 sp<ISurfaceComposer> s(ComposerService::getComposerService());
636 if (s == NULL) return NO_INIT;
637 mHeap = 0;
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700638 return s->captureScreen(display, &mHeap,
Mathias Agopianbf2c6a62010-12-10 16:22:31 -0800639 &mWidth, &mHeight, &mFormat, reqWidth, reqHeight,
640 minLayerZ, maxLayerZ);
Mathias Agopian74c40c02010-09-29 13:02:36 -0700641}
642
643void ScreenshotClient::release() {
644 mHeap = 0;
645}
646
647void const* ScreenshotClient::getPixels() const {
648 return mHeap->getBase();
649}
650
651uint32_t ScreenshotClient::getWidth() const {
652 return mWidth;
653}
654
655uint32_t ScreenshotClient::getHeight() const {
656 return mHeight;
657}
658
659PixelFormat ScreenshotClient::getFormat() const {
660 return mFormat;
661}
662
663uint32_t ScreenshotClient::getStride() const {
664 return mWidth;
665}
666
667size_t ScreenshotClient::getSize() const {
668 return mHeap->getSize();
669}
670
671// ----------------------------------------------------------------------------
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800672}; // namespace android