blob: 3efd086bd081c4160cdb754ba92a8e59d8b6097d [file] [log] [blame]
The Android Open Source Projectedbf3b62009-03-04 03:31:441/*
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-04 03:31:4420#include <sys/types.h>
The Android Open Source Projectedbf3b62009-03-04 03:31:4421
The Android Open Source Projectedbf3b62009-03-04 03:31:4422#include <utils/Errors.h>
The Android Open Source Projectedbf3b62009-03-04 03:31:4423#include <utils/Log.h>
Mathias Agopiand4784a32010-05-28 02:41:1524#include <utils/Singleton.h>
Mathias Agopiana67932f2011-04-20 21:20:5925#include <utils/SortedVector.h>
26#include <utils/String8.h>
27#include <utils/threads.h>
The Android Open Source Projectedbf3b62009-03-04 03:31:4428
Mathias Agopian9cce3252010-02-10 01:46:3729#include <binder/IMemory.h>
Mathias Agopiana67932f2011-04-20 21:20:5930#include <binder/IServiceManager.h>
Mathias Agopian9cce3252010-02-10 01:46:3731
Mathias Agopian076b1cc2009-04-10 21:24:3032#include <ui/DisplayInfo.h>
The Android Open Source Projectedbf3b62009-03-04 03:31:4433
Mathias Agopian90ac7992012-02-26 02:48:3534#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-04 03:31:4438
Mathias Agopian41f673c2011-11-18 01:48:3539#include <private/gui/ComposerService.h>
Mathias Agopian90ac7992012-02-26 02:48:3540#include <private/gui/LayerState.h>
The Android Open Source Projectedbf3b62009-03-04 03:31:4441
42namespace android {
The Android Open Source Projectedbf3b62009-03-04 03:31:4443// ---------------------------------------------------------------------------
44
Mathias Agopian7e27f052010-05-28 21:22:2345ANDROID_SINGLETON_STATIC_INSTANCE(ComposerService);
46
Mathias Agopianb7e930d2010-06-01 22:12:5847ComposerService::ComposerService()
48: Singleton<ComposerService>() {
Andy McFadden6652b3e2012-09-07 01:45:5649 Mutex::Autolock _l(mLock);
50 connectLocked();
51}
52
53void ComposerService::connectLocked() {
Mathias Agopianb7e930d2010-06-01 22:12:5854 const String16 name("SurfaceFlinger");
55 while (getService(name, &mComposerService) != NO_ERROR) {
56 usleep(250000);
57 }
Andy McFadden6652b3e2012-09-07 01:45:5658 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 22:12:5874}
75
Andy McFadden6652b3e2012-09-07 01:45:5676/*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 22:12:5892}
93
Mathias Agopian7e27f052010-05-28 21:22:2394// ---------------------------------------------------------------------------
95
Mathias Agopian698c0872011-06-29 02:09:3196static inline
Mathias Agopiane57f2922012-08-09 23:29:1297int compare_type(const ComposerState& lhs, const ComposerState& rhs) {
Mathias Agopian698c0872011-06-29 02:09:3198 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 23:29:12105static inline
106int compare_type(const DisplayState& lhs, const DisplayState& rhs) {
107 return compare_type(lhs.token, rhs.token);
108}
109
Mathias Agopian7e27f052010-05-28 21:22:23110class Composer : public Singleton<Composer>
111{
Mathias Agopiand4784a32010-05-28 02:41:15112 friend class Singleton<Composer>;
113
Mathias Agopian698c0872011-06-29 02:09:31114 mutable Mutex mLock;
Mathias Agopiane57f2922012-08-09 23:29:12115 SortedVector<ComposerState> mComposerStates;
116 SortedVector<DisplayState > mDisplayStates;
Jamie Gennis28378392011-10-13 00:39:00117 uint32_t mForceSynchronous;
Mathias Agopian698c0872011-06-29 02:09:31118
Jamie Gennisb8d69a52011-10-10 22:48:06119 Composer() : Singleton<Composer>(),
Jamie Gennis28378392011-10-13 00:39:00120 mForceSynchronous(0)
121 { }
Mathias Agopian698c0872011-06-29 02:09:31122
Jamie Gennis28378392011-10-13 00:39:00123 void closeGlobalTransactionImpl(bool synchronous);
Mathias Agopian698c0872011-06-29 02:09:31124
125 layer_state_t* getLayerStateLocked(
126 const sp<SurfaceComposerClient>& client, SurfaceID id);
127
Mathias Agopiane57f2922012-08-09 23:29:12128 DisplayState& getDisplayStateLocked(const sp<IBinder>& token);
129
Mathias Agopiand4784a32010-05-28 02:41:15130public:
Andy McFadden8dfa92f2012-09-18 01:27:17131 sp<IBinder> createDisplay(const String8& displayName);
Jeff Brown9d4e3d22012-08-25 03:00:51132 sp<IBinder> getBuiltInDisplay(int32_t id);
Mathias Agopian698c0872011-06-29 02:09:31133
134 status_t setPosition(const sp<SurfaceComposerClient>& client, SurfaceID id,
Mathias Agopian41b6aab2011-08-31 01:51:54135 float x, float y);
Mathias Agopian698c0872011-06-29 02:09:31136 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 22:48:06149 status_t setOrientation(int orientation);
Jamie Gennisf15a83f2012-05-11 03:43:55150 status_t setCrop(const sp<SurfaceComposerClient>& client, SurfaceID id,
151 const Rect& crop);
Mathias Agopian87855782012-07-25 04:41:09152 status_t setLayerStack(const sp<SurfaceComposerClient>& client,
153 SurfaceID id, uint32_t layerStack);
Mathias Agopian698c0872011-06-29 02:09:31154
Mathias Agopiane57f2922012-08-09 23:29:12155 void setDisplaySurface(const sp<IBinder>& token, const sp<ISurfaceTexture>& surface);
156 void setDisplayLayerStack(const sp<IBinder>& token, uint32_t layerStack);
Mathias Agopian00e8c7a2012-09-05 02:30:46157 void setDisplayProjection(const sp<IBinder>& token,
158 uint32_t orientation,
159 const Rect& layerStackRect,
160 const Rect& displayRect);
Mathias Agopiane57f2922012-08-09 23:29:12161
Jamie Gennis28378392011-10-13 00:39:00162 static void closeGlobalTransaction(bool synchronous) {
163 Composer::getInstance().closeGlobalTransactionImpl(synchronous);
Mathias Agopiand4784a32010-05-28 02:41:15164 }
165};
166
167ANDROID_SINGLETON_STATIC_INSTANCE(Composer);
168
The Android Open Source Projectedbf3b62009-03-04 03:31:44169// ---------------------------------------------------------------------------
170
Andy McFadden8dfa92f2012-09-18 01:27:17171sp<IBinder> Composer::createDisplay(const String8& displayName) {
172 return ComposerService::getComposerService()->createDisplay(displayName);
Mathias Agopiane57f2922012-08-09 23:29:12173}
174
Jeff Brown9d4e3d22012-08-25 03:00:51175sp<IBinder> Composer::getBuiltInDisplay(int32_t id) {
176 return ComposerService::getComposerService()->getBuiltInDisplay(id);
177}
178
Jamie Gennis28378392011-10-13 00:39:00179void Composer::closeGlobalTransactionImpl(bool synchronous) {
Mathias Agopiane57f2922012-08-09 23:29:12180 sp<ISurfaceComposer> sm(ComposerService::getComposerService());
Mathias Agopian698c0872011-06-29 02:09:31181
182 Vector<ComposerState> transaction;
Mathias Agopian8b33f032012-07-25 03:43:54183 Vector<DisplayState> displayTransaction;
Jamie Gennis28378392011-10-13 00:39:00184 uint32_t flags = 0;
Mathias Agopian698c0872011-06-29 02:09:31185
186 { // scope for the lock
187 Mutex::Autolock _l(mLock);
Mathias Agopiane57f2922012-08-09 23:29:12188 transaction = mComposerStates;
189 mComposerStates.clear();
Jamie Gennisb8d69a52011-10-10 22:48:06190
Mathias Agopiane57f2922012-08-09 23:29:12191 displayTransaction = mDisplayStates;
192 mDisplayStates.clear();
Jamie Gennis28378392011-10-13 00:39:00193
194 if (synchronous || mForceSynchronous) {
195 flags |= ISurfaceComposer::eSynchronous;
196 }
197 mForceSynchronous = false;
Mathias Agopian698c0872011-06-29 02:09:31198 }
199
Mathias Agopian8b33f032012-07-25 03:43:54200 sm->setTransactionState(transaction, displayTransaction, flags);
The Android Open Source Projectedbf3b62009-03-04 03:31:44201}
202
Mathias Agopian698c0872011-06-29 02:09:31203layer_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 23:29:12210 ssize_t index = mComposerStates.indexOf(s);
Mathias Agopian698c0872011-06-29 02:09:31211 if (index < 0) {
212 // we don't have it, add an initialized layer_state to our list
Mathias Agopiane57f2922012-08-09 23:29:12213 index = mComposerStates.add(s);
Mathias Agopian698c0872011-06-29 02:09:31214 }
215
Mathias Agopiane57f2922012-08-09 23:29:12216 ComposerState* const out = mComposerStates.editArray();
Mathias Agopian698c0872011-06-29 02:09:31217 return &(out[index].state);
218}
219
220status_t Composer::setPosition(const sp<SurfaceComposerClient>& client,
Mathias Agopian41b6aab2011-08-31 01:51:54221 SurfaceID id, float x, float y) {
Mathias Agopian698c0872011-06-29 02:09:31222 Mutex::Autolock _l(mLock);
223 layer_state_t* s = getLayerStateLocked(client, id);
224 if (!s)
225 return BAD_INDEX;
Mathias Agopian3165cc22012-08-09 02:42:09226 s->what |= layer_state_t::ePositionChanged;
Mathias Agopian698c0872011-06-29 02:09:31227 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-09 02:42:09238 s->what |= layer_state_t::eSizeChanged;
Mathias Agopian698c0872011-06-29 02:09:31239 s->w = w;
240 s->h = h;
Jamie Gennis28378392011-10-13 00:39:00241
242 // Resizing a surface makes the transaction synchronous.
243 mForceSynchronous = true;
244
Mathias Agopian698c0872011-06-29 02:09:31245 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-09 02:42:09254 s->what |= layer_state_t::eLayerChanged;
Mathias Agopian698c0872011-06-29 02:09:31255 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-09 02:42:09266 s->what |= layer_state_t::eVisibilityChanged;
Mathias Agopian698c0872011-06-29 02:09:31267 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-09 02:42:09280 s->what |= layer_state_t::eTransparentRegionChanged;
Mathias Agopian698c0872011-06-29 02:09:31281 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-09 02:42:09291 s->what |= layer_state_t::eAlphaChanged;
Mathias Agopian698c0872011-06-29 02:09:31292 s->alpha = alpha;
293 return NO_ERROR;
294}
295
Mathias Agopian87855782012-07-25 04:41:09296status_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-09 02:42:09302 s->what |= layer_state_t::eLayerStackChanged;
Mathias Agopian87855782012-07-25 04:41:09303 s->layerStack = layerStack;
304 return NO_ERROR;
305}
306
Mathias Agopian698c0872011-06-29 02:09:31307status_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-09 02:42:09314 s->what |= layer_state_t::eMatrixChanged;
Mathias Agopian698c0872011-06-29 02:09:31315 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-11 03:43:55324status_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-09 02:42:09330 s->what |= layer_state_t::eCropChanged;
Jamie Gennisf15a83f2012-05-11 03:43:55331 s->crop = crop;
332 return NO_ERROR;
333}
334
Mathias Agopian698c0872011-06-29 02:09:31335// ---------------------------------------------------------------------------
336
Mathias Agopiane57f2922012-08-09 23:29:12337DisplayState& 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-05 02:30:46365void Composer::setDisplayProjection(const sp<IBinder>& token,
366 uint32_t orientation,
367 const Rect& layerStackRect,
368 const Rect& displayRect) {
Mathias Agopiane57f2922012-08-09 23:29:12369 Mutex::Autolock _l(mLock);
370 DisplayState& s(getDisplayStateLocked(token));
371 s.orientation = orientation;
Mathias Agopian00e8c7a2012-09-05 02:30:46372 s.viewport = layerStackRect;
373 s.frame = displayRect;
374 s.what |= DisplayState::eDisplayProjectionChanged;
Mathias Agopiane57f2922012-08-09 23:29:12375 mForceSynchronous = true; // TODO: do we actually still need this?
376}
377
Mathias Agopiane57f2922012-08-09 23:29:12378// ---------------------------------------------------------------------------
379
The Android Open Source Projectedbf3b62009-03-04 03:31:44380SurfaceComposerClient::SurfaceComposerClient()
Mathias Agopian698c0872011-06-29 02:09:31381 : mStatus(NO_INIT), mComposer(Composer::getInstance())
The Android Open Source Projectedbf3b62009-03-04 03:31:44382{
The Android Open Source Projectedbf3b62009-03-04 03:31:44383}
384
Mathias Agopian698c0872011-06-29 02:09:31385void SurfaceComposerClient::onFirstRef() {
Mathias Agopiane57f2922012-08-09 23:29:12386 sp<ISurfaceComposer> sm(ComposerService::getComposerService());
Mathias Agopiand4784a32010-05-28 02:41:15387 if (sm != 0) {
Mathias Agopian7e27f052010-05-28 21:22:23388 sp<ISurfaceComposerClient> conn = sm->createConnection();
Mathias Agopiand4784a32010-05-28 02:41:15389 if (conn != 0) {
390 mClient = conn;
Mathias Agopiand4784a32010-05-28 02:41:15391 mStatus = NO_ERROR;
392 }
393 }
The Android Open Source Projectedbf3b62009-03-04 03:31:44394}
395
Mathias Agopian698c0872011-06-29 02:09:31396SurfaceComposerClient::~SurfaceComposerClient() {
Mathias Agopian631f3582010-05-26 00:51:34397 dispose();
398}
Mathias Agopiandd3423c2009-09-23 22:44:05399
Mathias Agopian698c0872011-06-29 02:09:31400status_t SurfaceComposerClient::initCheck() const {
The Android Open Source Projectedbf3b62009-03-04 03:31:44401 return mStatus;
402}
403
Mathias Agopian698c0872011-06-29 02:09:31404sp<IBinder> SurfaceComposerClient::connection() const {
The Android Open Source Projectedbf3b62009-03-04 03:31:44405 return (mClient != 0) ? mClient->asBinder() : 0;
406}
407
Mathias Agopiand4784a32010-05-28 02:41:15408status_t SurfaceComposerClient::linkToComposerDeath(
409 const sp<IBinder::DeathRecipient>& recipient,
Mathias Agopian698c0872011-06-29 02:09:31410 void* cookie, uint32_t flags) {
Mathias Agopiane57f2922012-08-09 23:29:12411 sp<ISurfaceComposer> sm(ComposerService::getComposerService());
Mathias Agopiand4784a32010-05-28 02:41:15412 return sm->asBinder()->linkToDeath(recipient, cookie, flags);
The Android Open Source Projectedbf3b62009-03-04 03:31:44413}
414
Mathias Agopian698c0872011-06-29 02:09:31415void SurfaceComposerClient::dispose() {
The Android Open Source Projectedbf3b62009-03-04 03:31:44416 // this can be called more than once.
Mathias Agopian7e27f052010-05-28 21:22:23417 sp<ISurfaceComposerClient> client;
Mathias Agopiand4784a32010-05-28 02:41:15418 Mutex::Autolock _lm(mLock);
419 if (mClient != 0) {
Mathias Agopiand4784a32010-05-28 02:41:15420 client = mClient; // hold ref while lock is held
421 mClient.clear();
The Android Open Source Projectedbf3b62009-03-04 03:31:44422 }
Mathias Agopiand4784a32010-05-28 02:41:15423 mStatus = NO_INIT;
The Android Open Source Projectedbf3b62009-03-04 03:31:44424}
425
Mathias Agopian698c0872011-06-29 02:09:31426sp<SurfaceControl> SurfaceComposerClient::createSurface(
Mathias Agopian698c0872011-06-29 02:09:31427 const String8& name,
Mathias Agopian698c0872011-06-29 02:09:31428 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-25 03:00:51437 w, h, format, flags);
Mathias Agopian698c0872011-06-29 02:09:31438 if (surface != 0) {
Mathias Agopianc10d9d92011-07-20 23:46:11439 result = new SurfaceControl(this, surface, data);
Mathias Agopian698c0872011-06-29 02:09:31440 }
441 }
442 return result;
443}
444
Andy McFadden8dfa92f2012-09-18 01:27:17445sp<IBinder> SurfaceComposerClient::createDisplay(const String8& displayName) {
446 return Composer::getInstance().createDisplay(displayName);
Mathias Agopiane57f2922012-08-09 23:29:12447}
448
Jeff Brown9d4e3d22012-08-25 03:00:51449sp<IBinder> SurfaceComposerClient::getBuiltInDisplay(int32_t id) {
450 return Composer::getInstance().getBuiltInDisplay(id);
451}
452
Mathias Agopian698c0872011-06-29 02:09:31453status_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-13 00:39:00470void SurfaceComposerClient::closeGlobalTransaction(bool synchronous) {
471 Composer::closeGlobalTransaction(synchronous);
Mathias Agopian698c0872011-06-29 02:09:31472}
473
474// ----------------------------------------------------------------------------
475
Jamie Gennisf15a83f2012-05-11 03:43:55476status_t SurfaceComposerClient::setCrop(SurfaceID id, const Rect& crop) {
477 return getComposer().setCrop(this, id, crop);
478}
479
Mathias Agopian41b6aab2011-08-31 01:51:54480status_t SurfaceComposerClient::setPosition(SurfaceID id, float x, float y) {
Mathias Agopian698c0872011-06-29 02:09:31481 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-09 02:42:09494 layer_state_t::eLayerHidden,
495 layer_state_t::eLayerHidden);
Mathias Agopian698c0872011-06-29 02:09:31496}
497
Jeff Brown380223b2012-08-27 05:49:35498status_t SurfaceComposerClient::show(SurfaceID id) {
Mathias Agopian698c0872011-06-29 02:09:31499 return getComposer().setFlags(this, id,
500 0,
Mathias Agopian3165cc22012-08-09 02:42:09501 layer_state_t::eLayerHidden);
Mathias Agopian698c0872011-06-29 02:09:31502}
503
Mathias Agopian698c0872011-06-29 02:09:31504status_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-25 04:41:09518status_t SurfaceComposerClient::setLayerStack(SurfaceID id, uint32_t layerStack) {
519 return getComposer().setLayerStack(this, id, layerStack);
520}
521
Mathias Agopian698c0872011-06-29 02:09:31522status_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 23:29:12529void 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-05 02:30:46539void 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 23:29:12545}
546
547// ----------------------------------------------------------------------------
548
The Android Open Source Projectedbf3b62009-03-04 03:31:44549status_t SurfaceComposerClient::getDisplayInfo(
Jeff Brown9d4e3d22012-08-25 03:00:51550 const sp<IBinder>& display, DisplayInfo* info)
The Android Open Source Projectedbf3b62009-03-04 03:31:44551{
Jeff Brown9d4e3d22012-08-25 03:00:51552 return ComposerService::getComposerService()->getDisplayInfo(display, info);
The Android Open Source Projectedbf3b62009-03-04 03:31:44553}
554
Jeff Brown2a09bb32012-10-09 02:13:57555void 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-29 02:09:31563// ----------------------------------------------------------------------------
The Android Open Source Projectedbf3b62009-03-04 03:31:44564
Mathias Agopian74c40c02010-09-29 20:02:36565ScreenshotClient::ScreenshotClient()
566 : mWidth(0), mHeight(0), mFormat(PIXEL_FORMAT_NONE) {
567}
568
Jeff Brown9d4e3d22012-08-25 03:00:51569status_t ScreenshotClient::update(const sp<IBinder>& display) {
Mathias Agopian74c40c02010-09-29 20:02:36570 sp<ISurfaceComposer> s(ComposerService::getComposerService());
571 if (s == NULL) return NO_INIT;
572 mHeap = 0;
Jeff Brown9d4e3d22012-08-25 03:00:51573 return s->captureScreen(display, &mHeap,
Mathias Agopianbf2c6a62010-12-11 00:22:31574 &mWidth, &mHeight, &mFormat, 0, 0,
575 0, -1UL);
Mathias Agopian74c40c02010-09-29 20:02:36576}
577
Jeff Brown9d4e3d22012-08-25 03:00:51578status_t ScreenshotClient::update(const sp<IBinder>& display,
579 uint32_t reqWidth, uint32_t reqHeight) {
Mathias Agopian74c40c02010-09-29 20:02:36580 sp<ISurfaceComposer> s(ComposerService::getComposerService());
581 if (s == NULL) return NO_INIT;
582 mHeap = 0;
Jeff Brown9d4e3d22012-08-25 03:00:51583 return s->captureScreen(display, &mHeap,
Mathias Agopianbf2c6a62010-12-11 00:22:31584 &mWidth, &mHeight, &mFormat, reqWidth, reqHeight,
585 0, -1UL);
586}
587
Jeff Brown9d4e3d22012-08-25 03:00:51588status_t ScreenshotClient::update(const sp<IBinder>& display,
589 uint32_t reqWidth, uint32_t reqHeight,
Mathias Agopianbf2c6a62010-12-11 00:22:31590 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-25 03:00:51594 return s->captureScreen(display, &mHeap,
Mathias Agopianbf2c6a62010-12-11 00:22:31595 &mWidth, &mHeight, &mFormat, reqWidth, reqHeight,
596 minLayerZ, maxLayerZ);
Mathias Agopian74c40c02010-09-29 20:02:36597}
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-04 03:31:44628}; // namespace android