blob: 3efd086bd081c4160cdb754ba92a8e59d8b6097d [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;
Mathias Agopian698c0872011-06-28 19:09:31 -0700118
Jamie Gennisb8d69a52011-10-10 15:48:06 -0700119 Composer() : Singleton<Composer>(),
Jamie Gennis28378392011-10-12 17:39:00 -0700120 mForceSynchronous(0)
121 { }
Mathias Agopian698c0872011-06-28 19:09:31 -0700122
Jamie Gennis28378392011-10-12 17:39:00 -0700123 void closeGlobalTransactionImpl(bool synchronous);
Mathias Agopian698c0872011-06-28 19:09:31 -0700124
125 layer_state_t* getLayerStateLocked(
126 const sp<SurfaceComposerClient>& client, SurfaceID id);
127
Mathias Agopiane57f2922012-08-09 16:29:12 -0700128 DisplayState& getDisplayStateLocked(const sp<IBinder>& token);
129
Mathias Agopiand4784a32010-05-27 19:41:15 -0700130public:
Andy McFadden8dfa92f2012-09-17 18:27:17 -0700131 sp<IBinder> createDisplay(const String8& displayName);
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700132 sp<IBinder> getBuiltInDisplay(int32_t id);
Mathias Agopian698c0872011-06-28 19:09:31 -0700133
134 status_t setPosition(const sp<SurfaceComposerClient>& client, SurfaceID id,
Mathias Agopian41b6aab2011-08-30 18:51:54 -0700135 float x, float y);
Mathias Agopian698c0872011-06-28 19:09:31 -0700136 status_t setSize(const sp<SurfaceComposerClient>& client, SurfaceID id,
137 uint32_t w, uint32_t h);
138 status_t setLayer(const sp<SurfaceComposerClient>& client, SurfaceID id,
139 int32_t z);
140 status_t setFlags(const sp<SurfaceComposerClient>& client, SurfaceID id,
141 uint32_t flags, uint32_t mask);
142 status_t setTransparentRegionHint(
143 const sp<SurfaceComposerClient>& client, SurfaceID id,
144 const Region& transparentRegion);
145 status_t setAlpha(const sp<SurfaceComposerClient>& client, SurfaceID id,
146 float alpha);
147 status_t setMatrix(const sp<SurfaceComposerClient>& client, SurfaceID id,
148 float dsdx, float dtdx, float dsdy, float dtdy);
Jamie Gennisb8d69a52011-10-10 15:48:06 -0700149 status_t setOrientation(int orientation);
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700150 status_t setCrop(const sp<SurfaceComposerClient>& client, SurfaceID id,
151 const Rect& crop);
Mathias Agopian87855782012-07-24 21:41:09 -0700152 status_t setLayerStack(const sp<SurfaceComposerClient>& client,
153 SurfaceID id, uint32_t layerStack);
Mathias Agopian698c0872011-06-28 19:09:31 -0700154
Mathias Agopiane57f2922012-08-09 16:29:12 -0700155 void setDisplaySurface(const sp<IBinder>& token, const sp<ISurfaceTexture>& surface);
156 void setDisplayLayerStack(const sp<IBinder>& token, uint32_t layerStack);
Mathias Agopian00e8c7a2012-09-04 19:30:46 -0700157 void setDisplayProjection(const sp<IBinder>& token,
158 uint32_t orientation,
159 const Rect& layerStackRect,
160 const Rect& displayRect);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700161
Jamie Gennis28378392011-10-12 17:39:00 -0700162 static void closeGlobalTransaction(bool synchronous) {
163 Composer::getInstance().closeGlobalTransactionImpl(synchronous);
Mathias Agopiand4784a32010-05-27 19:41:15 -0700164 }
165};
166
167ANDROID_SINGLETON_STATIC_INSTANCE(Composer);
168
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800169// ---------------------------------------------------------------------------
170
Andy McFadden8dfa92f2012-09-17 18:27:17 -0700171sp<IBinder> Composer::createDisplay(const String8& displayName) {
172 return ComposerService::getComposerService()->createDisplay(displayName);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700173}
174
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700175sp<IBinder> Composer::getBuiltInDisplay(int32_t id) {
176 return ComposerService::getComposerService()->getBuiltInDisplay(id);
177}
178
Jamie Gennis28378392011-10-12 17:39:00 -0700179void Composer::closeGlobalTransactionImpl(bool synchronous) {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700180 sp<ISurfaceComposer> sm(ComposerService::getComposerService());
Mathias Agopian698c0872011-06-28 19:09:31 -0700181
182 Vector<ComposerState> transaction;
Mathias Agopian8b33f032012-07-24 20:43:54 -0700183 Vector<DisplayState> displayTransaction;
Jamie Gennis28378392011-10-12 17:39:00 -0700184 uint32_t flags = 0;
Mathias Agopian698c0872011-06-28 19:09:31 -0700185
186 { // scope for the lock
187 Mutex::Autolock _l(mLock);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700188 transaction = mComposerStates;
189 mComposerStates.clear();
Jamie Gennisb8d69a52011-10-10 15:48:06 -0700190
Mathias Agopiane57f2922012-08-09 16:29:12 -0700191 displayTransaction = mDisplayStates;
192 mDisplayStates.clear();
Jamie Gennis28378392011-10-12 17:39:00 -0700193
194 if (synchronous || mForceSynchronous) {
195 flags |= ISurfaceComposer::eSynchronous;
196 }
197 mForceSynchronous = false;
Mathias Agopian698c0872011-06-28 19:09:31 -0700198 }
199
Mathias Agopian8b33f032012-07-24 20:43:54 -0700200 sm->setTransactionState(transaction, displayTransaction, flags);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800201}
202
Mathias Agopian698c0872011-06-28 19:09:31 -0700203layer_state_t* Composer::getLayerStateLocked(
204 const sp<SurfaceComposerClient>& client, SurfaceID id) {
205
206 ComposerState s;
207 s.client = client->mClient;
208 s.state.surface = id;
209
Mathias Agopiane57f2922012-08-09 16:29:12 -0700210 ssize_t index = mComposerStates.indexOf(s);
Mathias Agopian698c0872011-06-28 19:09:31 -0700211 if (index < 0) {
212 // we don't have it, add an initialized layer_state to our list
Mathias Agopiane57f2922012-08-09 16:29:12 -0700213 index = mComposerStates.add(s);
Mathias Agopian698c0872011-06-28 19:09:31 -0700214 }
215
Mathias Agopiane57f2922012-08-09 16:29:12 -0700216 ComposerState* const out = mComposerStates.editArray();
Mathias Agopian698c0872011-06-28 19:09:31 -0700217 return &(out[index].state);
218}
219
220status_t Composer::setPosition(const sp<SurfaceComposerClient>& client,
Mathias Agopian41b6aab2011-08-30 18:51:54 -0700221 SurfaceID id, float x, float y) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700222 Mutex::Autolock _l(mLock);
223 layer_state_t* s = getLayerStateLocked(client, id);
224 if (!s)
225 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700226 s->what |= layer_state_t::ePositionChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700227 s->x = x;
228 s->y = y;
229 return NO_ERROR;
230}
231
232status_t Composer::setSize(const sp<SurfaceComposerClient>& client,
233 SurfaceID id, uint32_t w, uint32_t h) {
234 Mutex::Autolock _l(mLock);
235 layer_state_t* s = getLayerStateLocked(client, id);
236 if (!s)
237 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700238 s->what |= layer_state_t::eSizeChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700239 s->w = w;
240 s->h = h;
Jamie Gennis28378392011-10-12 17:39:00 -0700241
242 // Resizing a surface makes the transaction synchronous.
243 mForceSynchronous = true;
244
Mathias Agopian698c0872011-06-28 19:09:31 -0700245 return NO_ERROR;
246}
247
248status_t Composer::setLayer(const sp<SurfaceComposerClient>& client,
249 SurfaceID id, int32_t z) {
250 Mutex::Autolock _l(mLock);
251 layer_state_t* s = getLayerStateLocked(client, id);
252 if (!s)
253 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700254 s->what |= layer_state_t::eLayerChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700255 s->z = z;
256 return NO_ERROR;
257}
258
259status_t Composer::setFlags(const sp<SurfaceComposerClient>& client,
260 SurfaceID id, uint32_t flags,
261 uint32_t mask) {
262 Mutex::Autolock _l(mLock);
263 layer_state_t* s = getLayerStateLocked(client, id);
264 if (!s)
265 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700266 s->what |= layer_state_t::eVisibilityChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700267 s->flags &= ~mask;
268 s->flags |= (flags & mask);
269 s->mask |= mask;
270 return NO_ERROR;
271}
272
273status_t Composer::setTransparentRegionHint(
274 const sp<SurfaceComposerClient>& client, SurfaceID id,
275 const Region& transparentRegion) {
276 Mutex::Autolock _l(mLock);
277 layer_state_t* s = getLayerStateLocked(client, id);
278 if (!s)
279 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700280 s->what |= layer_state_t::eTransparentRegionChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700281 s->transparentRegion = transparentRegion;
282 return NO_ERROR;
283}
284
285status_t Composer::setAlpha(const sp<SurfaceComposerClient>& client,
286 SurfaceID id, float alpha) {
287 Mutex::Autolock _l(mLock);
288 layer_state_t* s = getLayerStateLocked(client, id);
289 if (!s)
290 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700291 s->what |= layer_state_t::eAlphaChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700292 s->alpha = alpha;
293 return NO_ERROR;
294}
295
Mathias Agopian87855782012-07-24 21:41:09 -0700296status_t Composer::setLayerStack(const sp<SurfaceComposerClient>& client,
297 SurfaceID id, uint32_t layerStack) {
298 Mutex::Autolock _l(mLock);
299 layer_state_t* s = getLayerStateLocked(client, id);
300 if (!s)
301 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700302 s->what |= layer_state_t::eLayerStackChanged;
Mathias Agopian87855782012-07-24 21:41:09 -0700303 s->layerStack = layerStack;
304 return NO_ERROR;
305}
306
Mathias Agopian698c0872011-06-28 19:09:31 -0700307status_t Composer::setMatrix(const sp<SurfaceComposerClient>& client,
308 SurfaceID id, float dsdx, float dtdx,
309 float dsdy, float dtdy) {
310 Mutex::Autolock _l(mLock);
311 layer_state_t* s = getLayerStateLocked(client, id);
312 if (!s)
313 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700314 s->what |= layer_state_t::eMatrixChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700315 layer_state_t::matrix22_t matrix;
316 matrix.dsdx = dsdx;
317 matrix.dtdx = dtdx;
318 matrix.dsdy = dsdy;
319 matrix.dtdy = dtdy;
320 s->matrix = matrix;
321 return NO_ERROR;
322}
323
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700324status_t Composer::setCrop(const sp<SurfaceComposerClient>& client,
325 SurfaceID id, const Rect& crop) {
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::eCropChanged;
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700331 s->crop = crop;
332 return NO_ERROR;
333}
334
Mathias Agopian698c0872011-06-28 19:09:31 -0700335// ---------------------------------------------------------------------------
336
Mathias Agopiane57f2922012-08-09 16:29:12 -0700337DisplayState& Composer::getDisplayStateLocked(const sp<IBinder>& token) {
338 DisplayState s;
339 s.token = token;
340 ssize_t index = mDisplayStates.indexOf(s);
341 if (index < 0) {
342 // we don't have it, add an initialized layer_state to our list
343 s.what = 0;
344 index = mDisplayStates.add(s);
345 }
346 return mDisplayStates.editItemAt(index);
347}
348
349void Composer::setDisplaySurface(const sp<IBinder>& token,
350 const sp<ISurfaceTexture>& surface) {
351 Mutex::Autolock _l(mLock);
352 DisplayState& s(getDisplayStateLocked(token));
353 s.surface = surface;
354 s.what |= DisplayState::eSurfaceChanged;
355}
356
357void Composer::setDisplayLayerStack(const sp<IBinder>& token,
358 uint32_t layerStack) {
359 Mutex::Autolock _l(mLock);
360 DisplayState& s(getDisplayStateLocked(token));
361 s.layerStack = layerStack;
362 s.what |= DisplayState::eLayerStackChanged;
363}
364
Mathias Agopian00e8c7a2012-09-04 19:30:46 -0700365void Composer::setDisplayProjection(const sp<IBinder>& token,
366 uint32_t orientation,
367 const Rect& layerStackRect,
368 const Rect& displayRect) {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700369 Mutex::Autolock _l(mLock);
370 DisplayState& s(getDisplayStateLocked(token));
371 s.orientation = orientation;
Mathias Agopian00e8c7a2012-09-04 19:30:46 -0700372 s.viewport = layerStackRect;
373 s.frame = displayRect;
374 s.what |= DisplayState::eDisplayProjectionChanged;
Mathias Agopiane57f2922012-08-09 16:29:12 -0700375 mForceSynchronous = true; // TODO: do we actually still need this?
376}
377
Mathias Agopiane57f2922012-08-09 16:29:12 -0700378// ---------------------------------------------------------------------------
379
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800380SurfaceComposerClient::SurfaceComposerClient()
Mathias Agopian698c0872011-06-28 19:09:31 -0700381 : mStatus(NO_INIT), mComposer(Composer::getInstance())
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800382{
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800383}
384
Mathias Agopian698c0872011-06-28 19:09:31 -0700385void SurfaceComposerClient::onFirstRef() {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700386 sp<ISurfaceComposer> sm(ComposerService::getComposerService());
Mathias Agopiand4784a32010-05-27 19:41:15 -0700387 if (sm != 0) {
Mathias Agopian7e27f052010-05-28 14:22:23 -0700388 sp<ISurfaceComposerClient> conn = sm->createConnection();
Mathias Agopiand4784a32010-05-27 19:41:15 -0700389 if (conn != 0) {
390 mClient = conn;
Mathias Agopiand4784a32010-05-27 19:41:15 -0700391 mStatus = NO_ERROR;
392 }
393 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800394}
395
Mathias Agopian698c0872011-06-28 19:09:31 -0700396SurfaceComposerClient::~SurfaceComposerClient() {
Mathias Agopian631f3582010-05-25 17:51:34 -0700397 dispose();
398}
Mathias Agopiandd3423c2009-09-23 15:44:05 -0700399
Mathias Agopian698c0872011-06-28 19:09:31 -0700400status_t SurfaceComposerClient::initCheck() const {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800401 return mStatus;
402}
403
Mathias Agopian698c0872011-06-28 19:09:31 -0700404sp<IBinder> SurfaceComposerClient::connection() const {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800405 return (mClient != 0) ? mClient->asBinder() : 0;
406}
407
Mathias Agopiand4784a32010-05-27 19:41:15 -0700408status_t SurfaceComposerClient::linkToComposerDeath(
409 const sp<IBinder::DeathRecipient>& recipient,
Mathias Agopian698c0872011-06-28 19:09:31 -0700410 void* cookie, uint32_t flags) {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700411 sp<ISurfaceComposer> sm(ComposerService::getComposerService());
Mathias Agopiand4784a32010-05-27 19:41:15 -0700412 return sm->asBinder()->linkToDeath(recipient, cookie, flags);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800413}
414
Mathias Agopian698c0872011-06-28 19:09:31 -0700415void SurfaceComposerClient::dispose() {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800416 // this can be called more than once.
Mathias Agopian7e27f052010-05-28 14:22:23 -0700417 sp<ISurfaceComposerClient> client;
Mathias Agopiand4784a32010-05-27 19:41:15 -0700418 Mutex::Autolock _lm(mLock);
419 if (mClient != 0) {
Mathias Agopiand4784a32010-05-27 19:41:15 -0700420 client = mClient; // hold ref while lock is held
421 mClient.clear();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800422 }
Mathias Agopiand4784a32010-05-27 19:41:15 -0700423 mStatus = NO_INIT;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800424}
425
Mathias Agopian698c0872011-06-28 19:09:31 -0700426sp<SurfaceControl> SurfaceComposerClient::createSurface(
Mathias Agopian698c0872011-06-28 19:09:31 -0700427 const String8& name,
Mathias Agopian698c0872011-06-28 19:09:31 -0700428 uint32_t w,
429 uint32_t h,
430 PixelFormat format,
431 uint32_t flags)
432{
433 sp<SurfaceControl> result;
434 if (mStatus == NO_ERROR) {
435 ISurfaceComposerClient::surface_data_t data;
436 sp<ISurface> surface = mClient->createSurface(&data, name,
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700437 w, h, format, flags);
Mathias Agopian698c0872011-06-28 19:09:31 -0700438 if (surface != 0) {
Mathias Agopianc10d9d92011-07-20 16:46:11 -0700439 result = new SurfaceControl(this, surface, data);
Mathias Agopian698c0872011-06-28 19:09:31 -0700440 }
441 }
442 return result;
443}
444
Andy McFadden8dfa92f2012-09-17 18:27:17 -0700445sp<IBinder> SurfaceComposerClient::createDisplay(const String8& displayName) {
446 return Composer::getInstance().createDisplay(displayName);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700447}
448
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700449sp<IBinder> SurfaceComposerClient::getBuiltInDisplay(int32_t id) {
450 return Composer::getInstance().getBuiltInDisplay(id);
451}
452
Mathias Agopian698c0872011-06-28 19:09:31 -0700453status_t SurfaceComposerClient::destroySurface(SurfaceID sid) {
454 if (mStatus != NO_ERROR)
455 return mStatus;
456 status_t err = mClient->destroySurface(sid);
457 return err;
458}
459
460inline Composer& SurfaceComposerClient::getComposer() {
461 return mComposer;
462}
463
464// ----------------------------------------------------------------------------
465
466void SurfaceComposerClient::openGlobalTransaction() {
467 // Currently a no-op
468}
469
Jamie Gennis28378392011-10-12 17:39:00 -0700470void SurfaceComposerClient::closeGlobalTransaction(bool synchronous) {
471 Composer::closeGlobalTransaction(synchronous);
Mathias Agopian698c0872011-06-28 19:09:31 -0700472}
473
474// ----------------------------------------------------------------------------
475
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700476status_t SurfaceComposerClient::setCrop(SurfaceID id, const Rect& crop) {
477 return getComposer().setCrop(this, id, crop);
478}
479
Mathias Agopian41b6aab2011-08-30 18:51:54 -0700480status_t SurfaceComposerClient::setPosition(SurfaceID id, float x, float y) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700481 return getComposer().setPosition(this, id, x, y);
482}
483
484status_t SurfaceComposerClient::setSize(SurfaceID id, uint32_t w, uint32_t h) {
485 return getComposer().setSize(this, id, w, h);
486}
487
488status_t SurfaceComposerClient::setLayer(SurfaceID id, int32_t z) {
489 return getComposer().setLayer(this, id, z);
490}
491
492status_t SurfaceComposerClient::hide(SurfaceID id) {
493 return getComposer().setFlags(this, id,
Mathias Agopian3165cc22012-08-08 19:42:09 -0700494 layer_state_t::eLayerHidden,
495 layer_state_t::eLayerHidden);
Mathias Agopian698c0872011-06-28 19:09:31 -0700496}
497
Jeff Brown380223b2012-08-26 22:49:35 -0700498status_t SurfaceComposerClient::show(SurfaceID id) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700499 return getComposer().setFlags(this, id,
500 0,
Mathias Agopian3165cc22012-08-08 19:42:09 -0700501 layer_state_t::eLayerHidden);
Mathias Agopian698c0872011-06-28 19:09:31 -0700502}
503
Mathias Agopian698c0872011-06-28 19:09:31 -0700504status_t SurfaceComposerClient::setFlags(SurfaceID id, uint32_t flags,
505 uint32_t mask) {
506 return getComposer().setFlags(this, id, flags, mask);
507}
508
509status_t SurfaceComposerClient::setTransparentRegionHint(SurfaceID id,
510 const Region& transparentRegion) {
511 return getComposer().setTransparentRegionHint(this, id, transparentRegion);
512}
513
514status_t SurfaceComposerClient::setAlpha(SurfaceID id, float alpha) {
515 return getComposer().setAlpha(this, id, alpha);
516}
517
Mathias Agopian87855782012-07-24 21:41:09 -0700518status_t SurfaceComposerClient::setLayerStack(SurfaceID id, uint32_t layerStack) {
519 return getComposer().setLayerStack(this, id, layerStack);
520}
521
Mathias Agopian698c0872011-06-28 19:09:31 -0700522status_t SurfaceComposerClient::setMatrix(SurfaceID id, float dsdx, float dtdx,
523 float dsdy, float dtdy) {
524 return getComposer().setMatrix(this, id, dsdx, dtdx, dsdy, dtdy);
525}
526
527// ----------------------------------------------------------------------------
528
Mathias Agopiane57f2922012-08-09 16:29:12 -0700529void SurfaceComposerClient::setDisplaySurface(const sp<IBinder>& token,
530 const sp<ISurfaceTexture>& surface) {
531 Composer::getInstance().setDisplaySurface(token, surface);
532}
533
534void SurfaceComposerClient::setDisplayLayerStack(const sp<IBinder>& token,
535 uint32_t layerStack) {
536 Composer::getInstance().setDisplayLayerStack(token, layerStack);
537}
538
Mathias Agopian00e8c7a2012-09-04 19:30:46 -0700539void SurfaceComposerClient::setDisplayProjection(const sp<IBinder>& token,
540 uint32_t orientation,
541 const Rect& layerStackRect,
542 const Rect& displayRect) {
543 Composer::getInstance().setDisplayProjection(token, orientation,
544 layerStackRect, displayRect);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700545}
546
547// ----------------------------------------------------------------------------
548
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800549status_t SurfaceComposerClient::getDisplayInfo(
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700550 const sp<IBinder>& display, DisplayInfo* info)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800551{
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700552 return ComposerService::getComposerService()->getDisplayInfo(display, info);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800553}
554
Jeff Brown2a09bb32012-10-08 19:13:57 -0700555void SurfaceComposerClient::blankDisplay(const sp<IBinder>& token) {
556 ComposerService::getComposerService()->blank(token);
557}
558
559void SurfaceComposerClient::unblankDisplay(const sp<IBinder>& token) {
560 ComposerService::getComposerService()->unblank(token);
561}
562
Mathias Agopian698c0872011-06-28 19:09:31 -0700563// ----------------------------------------------------------------------------
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800564
Mathias Agopian74c40c02010-09-29 13:02:36 -0700565ScreenshotClient::ScreenshotClient()
566 : mWidth(0), mHeight(0), mFormat(PIXEL_FORMAT_NONE) {
567}
568
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700569status_t ScreenshotClient::update(const sp<IBinder>& display) {
Mathias Agopian74c40c02010-09-29 13:02:36 -0700570 sp<ISurfaceComposer> s(ComposerService::getComposerService());
571 if (s == NULL) return NO_INIT;
572 mHeap = 0;
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700573 return s->captureScreen(display, &mHeap,
Mathias Agopianbf2c6a62010-12-10 16:22:31 -0800574 &mWidth, &mHeight, &mFormat, 0, 0,
575 0, -1UL);
Mathias Agopian74c40c02010-09-29 13:02:36 -0700576}
577
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700578status_t ScreenshotClient::update(const sp<IBinder>& display,
579 uint32_t reqWidth, uint32_t reqHeight) {
Mathias Agopian74c40c02010-09-29 13:02:36 -0700580 sp<ISurfaceComposer> s(ComposerService::getComposerService());
581 if (s == NULL) return NO_INIT;
582 mHeap = 0;
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700583 return s->captureScreen(display, &mHeap,
Mathias Agopianbf2c6a62010-12-10 16:22:31 -0800584 &mWidth, &mHeight, &mFormat, reqWidth, reqHeight,
585 0, -1UL);
586}
587
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700588status_t ScreenshotClient::update(const sp<IBinder>& display,
589 uint32_t reqWidth, uint32_t reqHeight,
Mathias Agopianbf2c6a62010-12-10 16:22:31 -0800590 uint32_t minLayerZ, uint32_t maxLayerZ) {
591 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, reqWidth, reqHeight,
596 minLayerZ, maxLayerZ);
Mathias Agopian74c40c02010-09-29 13:02:36 -0700597}
598
599void ScreenshotClient::release() {
600 mHeap = 0;
601}
602
603void const* ScreenshotClient::getPixels() const {
604 return mHeap->getBase();
605}
606
607uint32_t ScreenshotClient::getWidth() const {
608 return mWidth;
609}
610
611uint32_t ScreenshotClient::getHeight() const {
612 return mHeight;
613}
614
615PixelFormat ScreenshotClient::getFormat() const {
616 return mFormat;
617}
618
619uint32_t ScreenshotClient::getStride() const {
620 return mWidth;
621}
622
623size_t ScreenshotClient::getSize() const {
624 return mHeap->getSize();
625}
626
627// ----------------------------------------------------------------------------
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800628}; // namespace android