blob: 80dd6ee96afecdcb5991761b52061cef0197db2f [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:
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700134 sp<IBinder> createDisplay(const String8& displayName, bool secure);
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
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700178sp<IBinder> Composer::createDisplay(const String8& displayName, bool secure) {
179 return ComposerService::getComposerService()->createDisplay(displayName,
180 secure);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700181}
182
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700183sp<IBinder> Composer::getBuiltInDisplay(int32_t id) {
184 return ComposerService::getComposerService()->getBuiltInDisplay(id);
185}
186
Jamie Gennis28378392011-10-12 17:39:00 -0700187void Composer::closeGlobalTransactionImpl(bool synchronous) {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700188 sp<ISurfaceComposer> sm(ComposerService::getComposerService());
Mathias Agopian698c0872011-06-28 19:09:31 -0700189
190 Vector<ComposerState> transaction;
Mathias Agopian8b33f032012-07-24 20:43:54 -0700191 Vector<DisplayState> displayTransaction;
Jamie Gennis28378392011-10-12 17:39:00 -0700192 uint32_t flags = 0;
Mathias Agopian698c0872011-06-28 19:09:31 -0700193
194 { // scope for the lock
195 Mutex::Autolock _l(mLock);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700196 transaction = mComposerStates;
197 mComposerStates.clear();
Jamie Gennisb8d69a52011-10-10 15:48:06 -0700198
Mathias Agopiane57f2922012-08-09 16:29:12 -0700199 displayTransaction = mDisplayStates;
200 mDisplayStates.clear();
Jamie Gennis28378392011-10-12 17:39:00 -0700201
202 if (synchronous || mForceSynchronous) {
203 flags |= ISurfaceComposer::eSynchronous;
204 }
Jamie Gennis2d5e2302012-10-15 18:24:43 -0700205 if (mAnimation) {
206 flags |= ISurfaceComposer::eAnimation;
207 }
208
Jamie Gennis28378392011-10-12 17:39:00 -0700209 mForceSynchronous = false;
Jamie Gennis2d5e2302012-10-15 18:24:43 -0700210 mAnimation = false;
Mathias Agopian698c0872011-06-28 19:09:31 -0700211 }
212
Mathias Agopian8b33f032012-07-24 20:43:54 -0700213 sm->setTransactionState(transaction, displayTransaction, flags);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800214}
215
Jamie Gennis2d5e2302012-10-15 18:24:43 -0700216void Composer::setAnimationTransactionImpl() {
217 Mutex::Autolock _l(mLock);
218 mAnimation = true;
219}
220
Mathias Agopian698c0872011-06-28 19:09:31 -0700221layer_state_t* Composer::getLayerStateLocked(
222 const sp<SurfaceComposerClient>& client, SurfaceID id) {
223
224 ComposerState s;
225 s.client = client->mClient;
226 s.state.surface = id;
227
Mathias Agopiane57f2922012-08-09 16:29:12 -0700228 ssize_t index = mComposerStates.indexOf(s);
Mathias Agopian698c0872011-06-28 19:09:31 -0700229 if (index < 0) {
230 // we don't have it, add an initialized layer_state to our list
Mathias Agopiane57f2922012-08-09 16:29:12 -0700231 index = mComposerStates.add(s);
Mathias Agopian698c0872011-06-28 19:09:31 -0700232 }
233
Mathias Agopiane57f2922012-08-09 16:29:12 -0700234 ComposerState* const out = mComposerStates.editArray();
Mathias Agopian698c0872011-06-28 19:09:31 -0700235 return &(out[index].state);
236}
237
238status_t Composer::setPosition(const sp<SurfaceComposerClient>& client,
Mathias Agopian41b6aab2011-08-30 18:51:54 -0700239 SurfaceID id, float x, float y) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700240 Mutex::Autolock _l(mLock);
241 layer_state_t* s = getLayerStateLocked(client, id);
242 if (!s)
243 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700244 s->what |= layer_state_t::ePositionChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700245 s->x = x;
246 s->y = y;
247 return NO_ERROR;
248}
249
250status_t Composer::setSize(const sp<SurfaceComposerClient>& client,
251 SurfaceID id, uint32_t w, uint32_t h) {
252 Mutex::Autolock _l(mLock);
253 layer_state_t* s = getLayerStateLocked(client, id);
254 if (!s)
255 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700256 s->what |= layer_state_t::eSizeChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700257 s->w = w;
258 s->h = h;
Jamie Gennis28378392011-10-12 17:39:00 -0700259
260 // Resizing a surface makes the transaction synchronous.
261 mForceSynchronous = true;
262
Mathias Agopian698c0872011-06-28 19:09:31 -0700263 return NO_ERROR;
264}
265
266status_t Composer::setLayer(const sp<SurfaceComposerClient>& client,
267 SurfaceID id, int32_t z) {
268 Mutex::Autolock _l(mLock);
269 layer_state_t* s = getLayerStateLocked(client, id);
270 if (!s)
271 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700272 s->what |= layer_state_t::eLayerChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700273 s->z = z;
274 return NO_ERROR;
275}
276
277status_t Composer::setFlags(const sp<SurfaceComposerClient>& client,
278 SurfaceID id, uint32_t flags,
279 uint32_t mask) {
280 Mutex::Autolock _l(mLock);
281 layer_state_t* s = getLayerStateLocked(client, id);
282 if (!s)
283 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700284 s->what |= layer_state_t::eVisibilityChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700285 s->flags &= ~mask;
286 s->flags |= (flags & mask);
287 s->mask |= mask;
288 return NO_ERROR;
289}
290
291status_t Composer::setTransparentRegionHint(
292 const sp<SurfaceComposerClient>& client, SurfaceID id,
293 const Region& transparentRegion) {
294 Mutex::Autolock _l(mLock);
295 layer_state_t* s = getLayerStateLocked(client, id);
296 if (!s)
297 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700298 s->what |= layer_state_t::eTransparentRegionChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700299 s->transparentRegion = transparentRegion;
300 return NO_ERROR;
301}
302
303status_t Composer::setAlpha(const sp<SurfaceComposerClient>& client,
304 SurfaceID id, float alpha) {
305 Mutex::Autolock _l(mLock);
306 layer_state_t* s = getLayerStateLocked(client, id);
307 if (!s)
308 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700309 s->what |= layer_state_t::eAlphaChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700310 s->alpha = alpha;
311 return NO_ERROR;
312}
313
Mathias Agopian87855782012-07-24 21:41:09 -0700314status_t Composer::setLayerStack(const sp<SurfaceComposerClient>& client,
315 SurfaceID id, uint32_t layerStack) {
316 Mutex::Autolock _l(mLock);
317 layer_state_t* s = getLayerStateLocked(client, id);
318 if (!s)
319 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700320 s->what |= layer_state_t::eLayerStackChanged;
Mathias Agopian87855782012-07-24 21:41:09 -0700321 s->layerStack = layerStack;
322 return NO_ERROR;
323}
324
Mathias Agopian698c0872011-06-28 19:09:31 -0700325status_t Composer::setMatrix(const sp<SurfaceComposerClient>& client,
326 SurfaceID id, float dsdx, float dtdx,
327 float dsdy, float dtdy) {
328 Mutex::Autolock _l(mLock);
329 layer_state_t* s = getLayerStateLocked(client, id);
330 if (!s)
331 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700332 s->what |= layer_state_t::eMatrixChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700333 layer_state_t::matrix22_t matrix;
334 matrix.dsdx = dsdx;
335 matrix.dtdx = dtdx;
336 matrix.dsdy = dsdy;
337 matrix.dtdy = dtdy;
338 s->matrix = matrix;
339 return NO_ERROR;
340}
341
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700342status_t Composer::setCrop(const sp<SurfaceComposerClient>& client,
343 SurfaceID id, const Rect& crop) {
344 Mutex::Autolock _l(mLock);
345 layer_state_t* s = getLayerStateLocked(client, id);
346 if (!s)
347 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700348 s->what |= layer_state_t::eCropChanged;
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700349 s->crop = crop;
350 return NO_ERROR;
351}
352
Mathias Agopian698c0872011-06-28 19:09:31 -0700353// ---------------------------------------------------------------------------
354
Mathias Agopiane57f2922012-08-09 16:29:12 -0700355DisplayState& Composer::getDisplayStateLocked(const sp<IBinder>& token) {
356 DisplayState s;
357 s.token = token;
358 ssize_t index = mDisplayStates.indexOf(s);
359 if (index < 0) {
360 // we don't have it, add an initialized layer_state to our list
361 s.what = 0;
362 index = mDisplayStates.add(s);
363 }
364 return mDisplayStates.editItemAt(index);
365}
366
367void Composer::setDisplaySurface(const sp<IBinder>& token,
368 const sp<ISurfaceTexture>& surface) {
369 Mutex::Autolock _l(mLock);
370 DisplayState& s(getDisplayStateLocked(token));
371 s.surface = surface;
372 s.what |= DisplayState::eSurfaceChanged;
373}
374
375void Composer::setDisplayLayerStack(const sp<IBinder>& token,
376 uint32_t layerStack) {
377 Mutex::Autolock _l(mLock);
378 DisplayState& s(getDisplayStateLocked(token));
379 s.layerStack = layerStack;
380 s.what |= DisplayState::eLayerStackChanged;
381}
382
Mathias Agopian00e8c7a2012-09-04 19:30:46 -0700383void Composer::setDisplayProjection(const sp<IBinder>& token,
384 uint32_t orientation,
385 const Rect& layerStackRect,
386 const Rect& displayRect) {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700387 Mutex::Autolock _l(mLock);
388 DisplayState& s(getDisplayStateLocked(token));
389 s.orientation = orientation;
Mathias Agopian00e8c7a2012-09-04 19:30:46 -0700390 s.viewport = layerStackRect;
391 s.frame = displayRect;
392 s.what |= DisplayState::eDisplayProjectionChanged;
Mathias Agopiane57f2922012-08-09 16:29:12 -0700393 mForceSynchronous = true; // TODO: do we actually still need this?
394}
395
Mathias Agopiane57f2922012-08-09 16:29:12 -0700396// ---------------------------------------------------------------------------
397
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800398SurfaceComposerClient::SurfaceComposerClient()
Mathias Agopian698c0872011-06-28 19:09:31 -0700399 : mStatus(NO_INIT), mComposer(Composer::getInstance())
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800400{
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800401}
402
Mathias Agopian698c0872011-06-28 19:09:31 -0700403void SurfaceComposerClient::onFirstRef() {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700404 sp<ISurfaceComposer> sm(ComposerService::getComposerService());
Mathias Agopiand4784a32010-05-27 19:41:15 -0700405 if (sm != 0) {
Mathias Agopian7e27f052010-05-28 14:22:23 -0700406 sp<ISurfaceComposerClient> conn = sm->createConnection();
Mathias Agopiand4784a32010-05-27 19:41:15 -0700407 if (conn != 0) {
408 mClient = conn;
Mathias Agopiand4784a32010-05-27 19:41:15 -0700409 mStatus = NO_ERROR;
410 }
411 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800412}
413
Mathias Agopian698c0872011-06-28 19:09:31 -0700414SurfaceComposerClient::~SurfaceComposerClient() {
Mathias Agopian631f3582010-05-25 17:51:34 -0700415 dispose();
416}
Mathias Agopiandd3423c2009-09-23 15:44:05 -0700417
Mathias Agopian698c0872011-06-28 19:09:31 -0700418status_t SurfaceComposerClient::initCheck() const {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800419 return mStatus;
420}
421
Mathias Agopian698c0872011-06-28 19:09:31 -0700422sp<IBinder> SurfaceComposerClient::connection() const {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800423 return (mClient != 0) ? mClient->asBinder() : 0;
424}
425
Mathias Agopiand4784a32010-05-27 19:41:15 -0700426status_t SurfaceComposerClient::linkToComposerDeath(
427 const sp<IBinder::DeathRecipient>& recipient,
Mathias Agopian698c0872011-06-28 19:09:31 -0700428 void* cookie, uint32_t flags) {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700429 sp<ISurfaceComposer> sm(ComposerService::getComposerService());
Mathias Agopiand4784a32010-05-27 19:41:15 -0700430 return sm->asBinder()->linkToDeath(recipient, cookie, flags);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800431}
432
Mathias Agopian698c0872011-06-28 19:09:31 -0700433void SurfaceComposerClient::dispose() {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800434 // this can be called more than once.
Mathias Agopian7e27f052010-05-28 14:22:23 -0700435 sp<ISurfaceComposerClient> client;
Mathias Agopiand4784a32010-05-27 19:41:15 -0700436 Mutex::Autolock _lm(mLock);
437 if (mClient != 0) {
Mathias Agopiand4784a32010-05-27 19:41:15 -0700438 client = mClient; // hold ref while lock is held
439 mClient.clear();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800440 }
Mathias Agopiand4784a32010-05-27 19:41:15 -0700441 mStatus = NO_INIT;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800442}
443
Mathias Agopian698c0872011-06-28 19:09:31 -0700444sp<SurfaceControl> SurfaceComposerClient::createSurface(
Mathias Agopian698c0872011-06-28 19:09:31 -0700445 const String8& name,
Mathias Agopian698c0872011-06-28 19:09:31 -0700446 uint32_t w,
447 uint32_t h,
448 PixelFormat format,
449 uint32_t flags)
450{
451 sp<SurfaceControl> result;
452 if (mStatus == NO_ERROR) {
453 ISurfaceComposerClient::surface_data_t data;
454 sp<ISurface> surface = mClient->createSurface(&data, name,
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700455 w, h, format, flags);
Mathias Agopian698c0872011-06-28 19:09:31 -0700456 if (surface != 0) {
Mathias Agopianc10d9d92011-07-20 16:46:11 -0700457 result = new SurfaceControl(this, surface, data);
Mathias Agopian698c0872011-06-28 19:09:31 -0700458 }
459 }
460 return result;
461}
462
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700463sp<IBinder> SurfaceComposerClient::createDisplay(const String8& displayName,
464 bool secure) {
465 return Composer::getInstance().createDisplay(displayName, secure);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700466}
467
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700468sp<IBinder> SurfaceComposerClient::getBuiltInDisplay(int32_t id) {
469 return Composer::getInstance().getBuiltInDisplay(id);
470}
471
Mathias Agopian698c0872011-06-28 19:09:31 -0700472status_t SurfaceComposerClient::destroySurface(SurfaceID sid) {
473 if (mStatus != NO_ERROR)
474 return mStatus;
475 status_t err = mClient->destroySurface(sid);
476 return err;
477}
478
479inline Composer& SurfaceComposerClient::getComposer() {
480 return mComposer;
481}
482
483// ----------------------------------------------------------------------------
484
485void SurfaceComposerClient::openGlobalTransaction() {
486 // Currently a no-op
487}
488
Jamie Gennis28378392011-10-12 17:39:00 -0700489void SurfaceComposerClient::closeGlobalTransaction(bool synchronous) {
490 Composer::closeGlobalTransaction(synchronous);
Mathias Agopian698c0872011-06-28 19:09:31 -0700491}
492
Jamie Gennis2d5e2302012-10-15 18:24:43 -0700493void SurfaceComposerClient::setAnimationTransaction() {
494 Composer::setAnimationTransaction();
495}
496
Mathias Agopian698c0872011-06-28 19:09:31 -0700497// ----------------------------------------------------------------------------
498
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700499status_t SurfaceComposerClient::setCrop(SurfaceID id, const Rect& crop) {
500 return getComposer().setCrop(this, id, crop);
501}
502
Mathias Agopian41b6aab2011-08-30 18:51:54 -0700503status_t SurfaceComposerClient::setPosition(SurfaceID id, float x, float y) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700504 return getComposer().setPosition(this, id, x, y);
505}
506
507status_t SurfaceComposerClient::setSize(SurfaceID id, uint32_t w, uint32_t h) {
508 return getComposer().setSize(this, id, w, h);
509}
510
511status_t SurfaceComposerClient::setLayer(SurfaceID id, int32_t z) {
512 return getComposer().setLayer(this, id, z);
513}
514
515status_t SurfaceComposerClient::hide(SurfaceID id) {
516 return getComposer().setFlags(this, id,
Mathias Agopian3165cc22012-08-08 19:42:09 -0700517 layer_state_t::eLayerHidden,
518 layer_state_t::eLayerHidden);
Mathias Agopian698c0872011-06-28 19:09:31 -0700519}
520
Jeff Brown380223b2012-08-26 22:49:35 -0700521status_t SurfaceComposerClient::show(SurfaceID id) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700522 return getComposer().setFlags(this, id,
523 0,
Mathias Agopian3165cc22012-08-08 19:42:09 -0700524 layer_state_t::eLayerHidden);
Mathias Agopian698c0872011-06-28 19:09:31 -0700525}
526
Mathias Agopian698c0872011-06-28 19:09:31 -0700527status_t SurfaceComposerClient::setFlags(SurfaceID id, uint32_t flags,
528 uint32_t mask) {
529 return getComposer().setFlags(this, id, flags, mask);
530}
531
532status_t SurfaceComposerClient::setTransparentRegionHint(SurfaceID id,
533 const Region& transparentRegion) {
534 return getComposer().setTransparentRegionHint(this, id, transparentRegion);
535}
536
537status_t SurfaceComposerClient::setAlpha(SurfaceID id, float alpha) {
538 return getComposer().setAlpha(this, id, alpha);
539}
540
Mathias Agopian87855782012-07-24 21:41:09 -0700541status_t SurfaceComposerClient::setLayerStack(SurfaceID id, uint32_t layerStack) {
542 return getComposer().setLayerStack(this, id, layerStack);
543}
544
Mathias Agopian698c0872011-06-28 19:09:31 -0700545status_t SurfaceComposerClient::setMatrix(SurfaceID id, float dsdx, float dtdx,
546 float dsdy, float dtdy) {
547 return getComposer().setMatrix(this, id, dsdx, dtdx, dsdy, dtdy);
548}
549
550// ----------------------------------------------------------------------------
551
Mathias Agopiane57f2922012-08-09 16:29:12 -0700552void SurfaceComposerClient::setDisplaySurface(const sp<IBinder>& token,
553 const sp<ISurfaceTexture>& surface) {
554 Composer::getInstance().setDisplaySurface(token, surface);
555}
556
557void SurfaceComposerClient::setDisplayLayerStack(const sp<IBinder>& token,
558 uint32_t layerStack) {
559 Composer::getInstance().setDisplayLayerStack(token, layerStack);
560}
561
Mathias Agopian00e8c7a2012-09-04 19:30:46 -0700562void SurfaceComposerClient::setDisplayProjection(const sp<IBinder>& token,
563 uint32_t orientation,
564 const Rect& layerStackRect,
565 const Rect& displayRect) {
566 Composer::getInstance().setDisplayProjection(token, orientation,
567 layerStackRect, displayRect);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700568}
569
570// ----------------------------------------------------------------------------
571
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800572status_t SurfaceComposerClient::getDisplayInfo(
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700573 const sp<IBinder>& display, DisplayInfo* info)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800574{
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700575 return ComposerService::getComposerService()->getDisplayInfo(display, info);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800576}
577
Jeff Brown2a09bb32012-10-08 19:13:57 -0700578void SurfaceComposerClient::blankDisplay(const sp<IBinder>& token) {
579 ComposerService::getComposerService()->blank(token);
580}
581
582void SurfaceComposerClient::unblankDisplay(const sp<IBinder>& token) {
583 ComposerService::getComposerService()->unblank(token);
584}
585
Mathias Agopian698c0872011-06-28 19:09:31 -0700586// ----------------------------------------------------------------------------
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800587
Mathias Agopian74c40c02010-09-29 13:02:36 -0700588ScreenshotClient::ScreenshotClient()
589 : mWidth(0), mHeight(0), mFormat(PIXEL_FORMAT_NONE) {
590}
591
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700592status_t ScreenshotClient::update(const sp<IBinder>& display) {
Mathias Agopian74c40c02010-09-29 13:02:36 -0700593 sp<ISurfaceComposer> s(ComposerService::getComposerService());
594 if (s == NULL) return NO_INIT;
595 mHeap = 0;
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700596 return s->captureScreen(display, &mHeap,
Mathias Agopianbf2c6a62010-12-10 16:22:31 -0800597 &mWidth, &mHeight, &mFormat, 0, 0,
598 0, -1UL);
Mathias Agopian74c40c02010-09-29 13:02:36 -0700599}
600
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700601status_t ScreenshotClient::update(const sp<IBinder>& display,
602 uint32_t reqWidth, uint32_t reqHeight) {
Mathias Agopian74c40c02010-09-29 13:02:36 -0700603 sp<ISurfaceComposer> s(ComposerService::getComposerService());
604 if (s == NULL) return NO_INIT;
605 mHeap = 0;
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700606 return s->captureScreen(display, &mHeap,
Mathias Agopianbf2c6a62010-12-10 16:22:31 -0800607 &mWidth, &mHeight, &mFormat, reqWidth, reqHeight,
608 0, -1UL);
609}
610
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700611status_t ScreenshotClient::update(const sp<IBinder>& display,
612 uint32_t reqWidth, uint32_t reqHeight,
Mathias Agopianbf2c6a62010-12-10 16:22:31 -0800613 uint32_t minLayerZ, uint32_t maxLayerZ) {
614 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, reqWidth, reqHeight,
619 minLayerZ, maxLayerZ);
Mathias Agopian74c40c02010-09-29 13:02:36 -0700620}
621
622void ScreenshotClient::release() {
623 mHeap = 0;
624}
625
626void const* ScreenshotClient::getPixels() const {
627 return mHeap->getBase();
628}
629
630uint32_t ScreenshotClient::getWidth() const {
631 return mWidth;
632}
633
634uint32_t ScreenshotClient::getHeight() const {
635 return mHeight;
636}
637
638PixelFormat ScreenshotClient::getFormat() const {
639 return mFormat;
640}
641
642uint32_t ScreenshotClient::getStride() const {
643 return mWidth;
644}
645
646size_t ScreenshotClient::getSize() const {
647 return mHeap->getSize();
648}
649
650// ----------------------------------------------------------------------------
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800651}; // namespace android