blob: 814036e3fd120a3a4f36772e6a1f1acf9095dda5 [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>() {
49 const String16 name("SurfaceFlinger");
50 while (getService(name, &mComposerService) != NO_ERROR) {
51 usleep(250000);
52 }
Mathias Agopianb7e930d2010-06-01 15:12:58 -070053}
54
55sp<ISurfaceComposer> ComposerService::getComposerService() {
56 return ComposerService::getInstance().mComposerService;
57}
58
Mathias Agopian7e27f052010-05-28 14:22:23 -070059// ---------------------------------------------------------------------------
60
Mathias Agopian698c0872011-06-28 19:09:31 -070061static inline
Mathias Agopiane57f2922012-08-09 16:29:12 -070062int compare_type(const ComposerState& lhs, const ComposerState& rhs) {
Mathias Agopian698c0872011-06-28 19:09:31 -070063 if (lhs.client < rhs.client) return -1;
64 if (lhs.client > rhs.client) return 1;
65 if (lhs.state.surface < rhs.state.surface) return -1;
66 if (lhs.state.surface > rhs.state.surface) return 1;
67 return 0;
68}
69
Mathias Agopiane57f2922012-08-09 16:29:12 -070070static inline
71int compare_type(const DisplayState& lhs, const DisplayState& rhs) {
72 return compare_type(lhs.token, rhs.token);
73}
74
Mathias Agopian7e27f052010-05-28 14:22:23 -070075class Composer : public Singleton<Composer>
76{
Mathias Agopiand4784a32010-05-27 19:41:15 -070077 friend class Singleton<Composer>;
78
Mathias Agopian698c0872011-06-28 19:09:31 -070079 mutable Mutex mLock;
Mathias Agopiane57f2922012-08-09 16:29:12 -070080 SortedVector<ComposerState> mComposerStates;
81 SortedVector<DisplayState > mDisplayStates;
Jamie Gennis28378392011-10-12 17:39:00 -070082 uint32_t mForceSynchronous;
Mathias Agopian698c0872011-06-28 19:09:31 -070083
Jamie Gennisb8d69a52011-10-10 15:48:06 -070084 Composer() : Singleton<Composer>(),
Jamie Gennis28378392011-10-12 17:39:00 -070085 mForceSynchronous(0)
86 { }
Mathias Agopian698c0872011-06-28 19:09:31 -070087
Jamie Gennis28378392011-10-12 17:39:00 -070088 void closeGlobalTransactionImpl(bool synchronous);
Mathias Agopian698c0872011-06-28 19:09:31 -070089
90 layer_state_t* getLayerStateLocked(
91 const sp<SurfaceComposerClient>& client, SurfaceID id);
92
Mathias Agopiane57f2922012-08-09 16:29:12 -070093 DisplayState& getDisplayStateLocked(const sp<IBinder>& token);
94
Mathias Agopiand4784a32010-05-27 19:41:15 -070095public:
Mathias Agopiane57f2922012-08-09 16:29:12 -070096 sp<IBinder> createDisplay();
Jeff Brown9d4e3d22012-08-24 20:00:51 -070097 sp<IBinder> getBuiltInDisplay(int32_t id);
Mathias Agopian698c0872011-06-28 19:09:31 -070098
99 status_t setPosition(const sp<SurfaceComposerClient>& client, SurfaceID id,
Mathias Agopian41b6aab2011-08-30 18:51:54 -0700100 float x, float y);
Mathias Agopian698c0872011-06-28 19:09:31 -0700101 status_t setSize(const sp<SurfaceComposerClient>& client, SurfaceID id,
102 uint32_t w, uint32_t h);
103 status_t setLayer(const sp<SurfaceComposerClient>& client, SurfaceID id,
104 int32_t z);
105 status_t setFlags(const sp<SurfaceComposerClient>& client, SurfaceID id,
106 uint32_t flags, uint32_t mask);
107 status_t setTransparentRegionHint(
108 const sp<SurfaceComposerClient>& client, SurfaceID id,
109 const Region& transparentRegion);
110 status_t setAlpha(const sp<SurfaceComposerClient>& client, SurfaceID id,
111 float alpha);
112 status_t setMatrix(const sp<SurfaceComposerClient>& client, SurfaceID id,
113 float dsdx, float dtdx, float dsdy, float dtdy);
Jamie Gennisb8d69a52011-10-10 15:48:06 -0700114 status_t setOrientation(int orientation);
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700115 status_t setCrop(const sp<SurfaceComposerClient>& client, SurfaceID id,
116 const Rect& crop);
Mathias Agopian87855782012-07-24 21:41:09 -0700117 status_t setLayerStack(const sp<SurfaceComposerClient>& client,
118 SurfaceID id, uint32_t layerStack);
Mathias Agopian698c0872011-06-28 19:09:31 -0700119
Mathias Agopiane57f2922012-08-09 16:29:12 -0700120 void setDisplaySurface(const sp<IBinder>& token, const sp<ISurfaceTexture>& surface);
121 void setDisplayLayerStack(const sp<IBinder>& token, uint32_t layerStack);
Mathias Agopian00e8c7a2012-09-04 19:30:46 -0700122 void setDisplayProjection(const sp<IBinder>& token,
123 uint32_t orientation,
124 const Rect& layerStackRect,
125 const Rect& displayRect);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700126
Jamie Gennis28378392011-10-12 17:39:00 -0700127 static void closeGlobalTransaction(bool synchronous) {
128 Composer::getInstance().closeGlobalTransactionImpl(synchronous);
Mathias Agopiand4784a32010-05-27 19:41:15 -0700129 }
130};
131
132ANDROID_SINGLETON_STATIC_INSTANCE(Composer);
133
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800134// ---------------------------------------------------------------------------
135
Mathias Agopiane57f2922012-08-09 16:29:12 -0700136sp<IBinder> Composer::createDisplay() {
137 return ComposerService::getComposerService()->createDisplay();
138}
139
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700140sp<IBinder> Composer::getBuiltInDisplay(int32_t id) {
141 return ComposerService::getComposerService()->getBuiltInDisplay(id);
142}
143
Jamie Gennis28378392011-10-12 17:39:00 -0700144void Composer::closeGlobalTransactionImpl(bool synchronous) {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700145 sp<ISurfaceComposer> sm(ComposerService::getComposerService());
Mathias Agopian698c0872011-06-28 19:09:31 -0700146
147 Vector<ComposerState> transaction;
Mathias Agopian8b33f032012-07-24 20:43:54 -0700148 Vector<DisplayState> displayTransaction;
Jamie Gennis28378392011-10-12 17:39:00 -0700149 uint32_t flags = 0;
Mathias Agopian698c0872011-06-28 19:09:31 -0700150
151 { // scope for the lock
152 Mutex::Autolock _l(mLock);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700153 transaction = mComposerStates;
154 mComposerStates.clear();
Jamie Gennisb8d69a52011-10-10 15:48:06 -0700155
Mathias Agopiane57f2922012-08-09 16:29:12 -0700156 displayTransaction = mDisplayStates;
157 mDisplayStates.clear();
Jamie Gennis28378392011-10-12 17:39:00 -0700158
159 if (synchronous || mForceSynchronous) {
160 flags |= ISurfaceComposer::eSynchronous;
161 }
162 mForceSynchronous = false;
Mathias Agopian698c0872011-06-28 19:09:31 -0700163 }
164
Mathias Agopian8b33f032012-07-24 20:43:54 -0700165 sm->setTransactionState(transaction, displayTransaction, flags);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800166}
167
Mathias Agopian698c0872011-06-28 19:09:31 -0700168layer_state_t* Composer::getLayerStateLocked(
169 const sp<SurfaceComposerClient>& client, SurfaceID id) {
170
171 ComposerState s;
172 s.client = client->mClient;
173 s.state.surface = id;
174
Mathias Agopiane57f2922012-08-09 16:29:12 -0700175 ssize_t index = mComposerStates.indexOf(s);
Mathias Agopian698c0872011-06-28 19:09:31 -0700176 if (index < 0) {
177 // we don't have it, add an initialized layer_state to our list
Mathias Agopiane57f2922012-08-09 16:29:12 -0700178 index = mComposerStates.add(s);
Mathias Agopian698c0872011-06-28 19:09:31 -0700179 }
180
Mathias Agopiane57f2922012-08-09 16:29:12 -0700181 ComposerState* const out = mComposerStates.editArray();
Mathias Agopian698c0872011-06-28 19:09:31 -0700182 return &(out[index].state);
183}
184
185status_t Composer::setPosition(const sp<SurfaceComposerClient>& client,
Mathias Agopian41b6aab2011-08-30 18:51:54 -0700186 SurfaceID id, float x, float y) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700187 Mutex::Autolock _l(mLock);
188 layer_state_t* s = getLayerStateLocked(client, id);
189 if (!s)
190 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700191 s->what |= layer_state_t::ePositionChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700192 s->x = x;
193 s->y = y;
194 return NO_ERROR;
195}
196
197status_t Composer::setSize(const sp<SurfaceComposerClient>& client,
198 SurfaceID id, uint32_t w, uint32_t h) {
199 Mutex::Autolock _l(mLock);
200 layer_state_t* s = getLayerStateLocked(client, id);
201 if (!s)
202 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700203 s->what |= layer_state_t::eSizeChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700204 s->w = w;
205 s->h = h;
Jamie Gennis28378392011-10-12 17:39:00 -0700206
207 // Resizing a surface makes the transaction synchronous.
208 mForceSynchronous = true;
209
Mathias Agopian698c0872011-06-28 19:09:31 -0700210 return NO_ERROR;
211}
212
213status_t Composer::setLayer(const sp<SurfaceComposerClient>& client,
214 SurfaceID id, int32_t z) {
215 Mutex::Autolock _l(mLock);
216 layer_state_t* s = getLayerStateLocked(client, id);
217 if (!s)
218 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700219 s->what |= layer_state_t::eLayerChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700220 s->z = z;
221 return NO_ERROR;
222}
223
224status_t Composer::setFlags(const sp<SurfaceComposerClient>& client,
225 SurfaceID id, uint32_t flags,
226 uint32_t mask) {
227 Mutex::Autolock _l(mLock);
228 layer_state_t* s = getLayerStateLocked(client, id);
229 if (!s)
230 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700231 s->what |= layer_state_t::eVisibilityChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700232 s->flags &= ~mask;
233 s->flags |= (flags & mask);
234 s->mask |= mask;
235 return NO_ERROR;
236}
237
238status_t Composer::setTransparentRegionHint(
239 const sp<SurfaceComposerClient>& client, SurfaceID id,
240 const Region& transparentRegion) {
241 Mutex::Autolock _l(mLock);
242 layer_state_t* s = getLayerStateLocked(client, id);
243 if (!s)
244 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700245 s->what |= layer_state_t::eTransparentRegionChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700246 s->transparentRegion = transparentRegion;
247 return NO_ERROR;
248}
249
250status_t Composer::setAlpha(const sp<SurfaceComposerClient>& client,
251 SurfaceID id, float alpha) {
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::eAlphaChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700257 s->alpha = alpha;
258 return NO_ERROR;
259}
260
Mathias Agopian87855782012-07-24 21:41:09 -0700261status_t Composer::setLayerStack(const sp<SurfaceComposerClient>& client,
262 SurfaceID id, uint32_t layerStack) {
263 Mutex::Autolock _l(mLock);
264 layer_state_t* s = getLayerStateLocked(client, id);
265 if (!s)
266 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700267 s->what |= layer_state_t::eLayerStackChanged;
Mathias Agopian87855782012-07-24 21:41:09 -0700268 s->layerStack = layerStack;
269 return NO_ERROR;
270}
271
Mathias Agopian698c0872011-06-28 19:09:31 -0700272status_t Composer::setMatrix(const sp<SurfaceComposerClient>& client,
273 SurfaceID id, float dsdx, float dtdx,
274 float dsdy, float dtdy) {
275 Mutex::Autolock _l(mLock);
276 layer_state_t* s = getLayerStateLocked(client, id);
277 if (!s)
278 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700279 s->what |= layer_state_t::eMatrixChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700280 layer_state_t::matrix22_t matrix;
281 matrix.dsdx = dsdx;
282 matrix.dtdx = dtdx;
283 matrix.dsdy = dsdy;
284 matrix.dtdy = dtdy;
285 s->matrix = matrix;
286 return NO_ERROR;
287}
288
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700289status_t Composer::setCrop(const sp<SurfaceComposerClient>& client,
290 SurfaceID id, const Rect& crop) {
291 Mutex::Autolock _l(mLock);
292 layer_state_t* s = getLayerStateLocked(client, id);
293 if (!s)
294 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700295 s->what |= layer_state_t::eCropChanged;
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700296 s->crop = crop;
297 return NO_ERROR;
298}
299
Mathias Agopian698c0872011-06-28 19:09:31 -0700300// ---------------------------------------------------------------------------
301
Mathias Agopiane57f2922012-08-09 16:29:12 -0700302DisplayState& Composer::getDisplayStateLocked(const sp<IBinder>& token) {
303 DisplayState s;
304 s.token = token;
305 ssize_t index = mDisplayStates.indexOf(s);
306 if (index < 0) {
307 // we don't have it, add an initialized layer_state to our list
308 s.what = 0;
309 index = mDisplayStates.add(s);
310 }
311 return mDisplayStates.editItemAt(index);
312}
313
314void Composer::setDisplaySurface(const sp<IBinder>& token,
315 const sp<ISurfaceTexture>& surface) {
316 Mutex::Autolock _l(mLock);
317 DisplayState& s(getDisplayStateLocked(token));
318 s.surface = surface;
319 s.what |= DisplayState::eSurfaceChanged;
320}
321
322void Composer::setDisplayLayerStack(const sp<IBinder>& token,
323 uint32_t layerStack) {
324 Mutex::Autolock _l(mLock);
325 DisplayState& s(getDisplayStateLocked(token));
326 s.layerStack = layerStack;
327 s.what |= DisplayState::eLayerStackChanged;
328}
329
Mathias Agopian00e8c7a2012-09-04 19:30:46 -0700330void Composer::setDisplayProjection(const sp<IBinder>& token,
331 uint32_t orientation,
332 const Rect& layerStackRect,
333 const Rect& displayRect) {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700334 Mutex::Autolock _l(mLock);
335 DisplayState& s(getDisplayStateLocked(token));
336 s.orientation = orientation;
Mathias Agopian00e8c7a2012-09-04 19:30:46 -0700337 s.viewport = layerStackRect;
338 s.frame = displayRect;
339 s.what |= DisplayState::eDisplayProjectionChanged;
Mathias Agopiane57f2922012-08-09 16:29:12 -0700340 mForceSynchronous = true; // TODO: do we actually still need this?
341}
342
Mathias Agopiane57f2922012-08-09 16:29:12 -0700343// ---------------------------------------------------------------------------
344
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800345SurfaceComposerClient::SurfaceComposerClient()
Mathias Agopian698c0872011-06-28 19:09:31 -0700346 : mStatus(NO_INIT), mComposer(Composer::getInstance())
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800347{
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800348}
349
Mathias Agopian698c0872011-06-28 19:09:31 -0700350void SurfaceComposerClient::onFirstRef() {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700351 sp<ISurfaceComposer> sm(ComposerService::getComposerService());
Mathias Agopiand4784a32010-05-27 19:41:15 -0700352 if (sm != 0) {
Mathias Agopian7e27f052010-05-28 14:22:23 -0700353 sp<ISurfaceComposerClient> conn = sm->createConnection();
Mathias Agopiand4784a32010-05-27 19:41:15 -0700354 if (conn != 0) {
355 mClient = conn;
Mathias Agopiand4784a32010-05-27 19:41:15 -0700356 mStatus = NO_ERROR;
357 }
358 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800359}
360
Mathias Agopian698c0872011-06-28 19:09:31 -0700361SurfaceComposerClient::~SurfaceComposerClient() {
Mathias Agopian631f3582010-05-25 17:51:34 -0700362 dispose();
363}
Mathias Agopiandd3423c2009-09-23 15:44:05 -0700364
Mathias Agopian698c0872011-06-28 19:09:31 -0700365status_t SurfaceComposerClient::initCheck() const {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800366 return mStatus;
367}
368
Mathias Agopian698c0872011-06-28 19:09:31 -0700369sp<IBinder> SurfaceComposerClient::connection() const {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800370 return (mClient != 0) ? mClient->asBinder() : 0;
371}
372
Mathias Agopiand4784a32010-05-27 19:41:15 -0700373status_t SurfaceComposerClient::linkToComposerDeath(
374 const sp<IBinder::DeathRecipient>& recipient,
Mathias Agopian698c0872011-06-28 19:09:31 -0700375 void* cookie, uint32_t flags) {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700376 sp<ISurfaceComposer> sm(ComposerService::getComposerService());
Mathias Agopiand4784a32010-05-27 19:41:15 -0700377 return sm->asBinder()->linkToDeath(recipient, cookie, flags);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800378}
379
Mathias Agopian698c0872011-06-28 19:09:31 -0700380void SurfaceComposerClient::dispose() {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800381 // this can be called more than once.
Mathias Agopian7e27f052010-05-28 14:22:23 -0700382 sp<ISurfaceComposerClient> client;
Mathias Agopiand4784a32010-05-27 19:41:15 -0700383 Mutex::Autolock _lm(mLock);
384 if (mClient != 0) {
Mathias Agopiand4784a32010-05-27 19:41:15 -0700385 client = mClient; // hold ref while lock is held
386 mClient.clear();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800387 }
Mathias Agopiand4784a32010-05-27 19:41:15 -0700388 mStatus = NO_INIT;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800389}
390
Mathias Agopian698c0872011-06-28 19:09:31 -0700391sp<SurfaceControl> SurfaceComposerClient::createSurface(
Mathias Agopian698c0872011-06-28 19:09:31 -0700392 const String8& name,
Mathias Agopian698c0872011-06-28 19:09:31 -0700393 uint32_t w,
394 uint32_t h,
395 PixelFormat format,
396 uint32_t flags)
397{
398 sp<SurfaceControl> result;
399 if (mStatus == NO_ERROR) {
400 ISurfaceComposerClient::surface_data_t data;
401 sp<ISurface> surface = mClient->createSurface(&data, name,
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700402 w, h, format, flags);
Mathias Agopian698c0872011-06-28 19:09:31 -0700403 if (surface != 0) {
Mathias Agopianc10d9d92011-07-20 16:46:11 -0700404 result = new SurfaceControl(this, surface, data);
Mathias Agopian698c0872011-06-28 19:09:31 -0700405 }
406 }
407 return result;
408}
409
Mathias Agopiane57f2922012-08-09 16:29:12 -0700410sp<IBinder> SurfaceComposerClient::createDisplay() {
411 return Composer::getInstance().createDisplay();
412}
413
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700414sp<IBinder> SurfaceComposerClient::getBuiltInDisplay(int32_t id) {
415 return Composer::getInstance().getBuiltInDisplay(id);
416}
417
Mathias Agopian698c0872011-06-28 19:09:31 -0700418status_t SurfaceComposerClient::destroySurface(SurfaceID sid) {
419 if (mStatus != NO_ERROR)
420 return mStatus;
421 status_t err = mClient->destroySurface(sid);
422 return err;
423}
424
425inline Composer& SurfaceComposerClient::getComposer() {
426 return mComposer;
427}
428
429// ----------------------------------------------------------------------------
430
431void SurfaceComposerClient::openGlobalTransaction() {
432 // Currently a no-op
433}
434
Jamie Gennis28378392011-10-12 17:39:00 -0700435void SurfaceComposerClient::closeGlobalTransaction(bool synchronous) {
436 Composer::closeGlobalTransaction(synchronous);
Mathias Agopian698c0872011-06-28 19:09:31 -0700437}
438
439// ----------------------------------------------------------------------------
440
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700441status_t SurfaceComposerClient::setCrop(SurfaceID id, const Rect& crop) {
442 return getComposer().setCrop(this, id, crop);
443}
444
Mathias Agopian41b6aab2011-08-30 18:51:54 -0700445status_t SurfaceComposerClient::setPosition(SurfaceID id, float x, float y) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700446 return getComposer().setPosition(this, id, x, y);
447}
448
449status_t SurfaceComposerClient::setSize(SurfaceID id, uint32_t w, uint32_t h) {
450 return getComposer().setSize(this, id, w, h);
451}
452
453status_t SurfaceComposerClient::setLayer(SurfaceID id, int32_t z) {
454 return getComposer().setLayer(this, id, z);
455}
456
457status_t SurfaceComposerClient::hide(SurfaceID id) {
458 return getComposer().setFlags(this, id,
Mathias Agopian3165cc22012-08-08 19:42:09 -0700459 layer_state_t::eLayerHidden,
460 layer_state_t::eLayerHidden);
Mathias Agopian698c0872011-06-28 19:09:31 -0700461}
462
Jeff Brown380223b2012-08-26 22:49:35 -0700463status_t SurfaceComposerClient::show(SurfaceID id) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700464 return getComposer().setFlags(this, id,
465 0,
Mathias Agopian3165cc22012-08-08 19:42:09 -0700466 layer_state_t::eLayerHidden);
Mathias Agopian698c0872011-06-28 19:09:31 -0700467}
468
Mathias Agopian698c0872011-06-28 19:09:31 -0700469status_t SurfaceComposerClient::setFlags(SurfaceID id, uint32_t flags,
470 uint32_t mask) {
471 return getComposer().setFlags(this, id, flags, mask);
472}
473
474status_t SurfaceComposerClient::setTransparentRegionHint(SurfaceID id,
475 const Region& transparentRegion) {
476 return getComposer().setTransparentRegionHint(this, id, transparentRegion);
477}
478
479status_t SurfaceComposerClient::setAlpha(SurfaceID id, float alpha) {
480 return getComposer().setAlpha(this, id, alpha);
481}
482
Mathias Agopian87855782012-07-24 21:41:09 -0700483status_t SurfaceComposerClient::setLayerStack(SurfaceID id, uint32_t layerStack) {
484 return getComposer().setLayerStack(this, id, layerStack);
485}
486
Mathias Agopian698c0872011-06-28 19:09:31 -0700487status_t SurfaceComposerClient::setMatrix(SurfaceID id, float dsdx, float dtdx,
488 float dsdy, float dtdy) {
489 return getComposer().setMatrix(this, id, dsdx, dtdx, dsdy, dtdy);
490}
491
492// ----------------------------------------------------------------------------
493
Mathias Agopiane57f2922012-08-09 16:29:12 -0700494void SurfaceComposerClient::setDisplaySurface(const sp<IBinder>& token,
495 const sp<ISurfaceTexture>& surface) {
496 Composer::getInstance().setDisplaySurface(token, surface);
497}
498
499void SurfaceComposerClient::setDisplayLayerStack(const sp<IBinder>& token,
500 uint32_t layerStack) {
501 Composer::getInstance().setDisplayLayerStack(token, layerStack);
502}
503
Mathias Agopian00e8c7a2012-09-04 19:30:46 -0700504void SurfaceComposerClient::setDisplayProjection(const sp<IBinder>& token,
505 uint32_t orientation,
506 const Rect& layerStackRect,
507 const Rect& displayRect) {
508 Composer::getInstance().setDisplayProjection(token, orientation,
509 layerStackRect, displayRect);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700510}
511
512// ----------------------------------------------------------------------------
513
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800514status_t SurfaceComposerClient::getDisplayInfo(
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700515 const sp<IBinder>& display, DisplayInfo* info)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800516{
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700517 return ComposerService::getComposerService()->getDisplayInfo(display, info);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800518}
519
Jeff Browna50b51c2012-08-27 17:06:39 -0700520// TODO: Remove me. Do not use.
521// This is a compatibility shim for one product whose drivers are depending on
522// this legacy function (when they shouldn't).
523status_t SurfaceComposerClient::getDisplayInfo(
524 int32_t displayId, DisplayInfo* info)
525{
526 return getDisplayInfo(getBuiltInDisplay(displayId), info);
527}
528
Mathias Agopian698c0872011-06-28 19:09:31 -0700529// ----------------------------------------------------------------------------
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800530
Mathias Agopian74c40c02010-09-29 13:02:36 -0700531ScreenshotClient::ScreenshotClient()
532 : mWidth(0), mHeight(0), mFormat(PIXEL_FORMAT_NONE) {
533}
534
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700535status_t ScreenshotClient::update(const sp<IBinder>& display) {
Mathias Agopian74c40c02010-09-29 13:02:36 -0700536 sp<ISurfaceComposer> s(ComposerService::getComposerService());
537 if (s == NULL) return NO_INIT;
538 mHeap = 0;
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700539 return s->captureScreen(display, &mHeap,
Mathias Agopianbf2c6a62010-12-10 16:22:31 -0800540 &mWidth, &mHeight, &mFormat, 0, 0,
541 0, -1UL);
Mathias Agopian74c40c02010-09-29 13:02:36 -0700542}
543
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700544status_t ScreenshotClient::update(const sp<IBinder>& display,
545 uint32_t reqWidth, uint32_t reqHeight) {
Mathias Agopian74c40c02010-09-29 13:02:36 -0700546 sp<ISurfaceComposer> s(ComposerService::getComposerService());
547 if (s == NULL) return NO_INIT;
548 mHeap = 0;
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700549 return s->captureScreen(display, &mHeap,
Mathias Agopianbf2c6a62010-12-10 16:22:31 -0800550 &mWidth, &mHeight, &mFormat, reqWidth, reqHeight,
551 0, -1UL);
552}
553
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700554status_t ScreenshotClient::update(const sp<IBinder>& display,
555 uint32_t reqWidth, uint32_t reqHeight,
Mathias Agopianbf2c6a62010-12-10 16:22:31 -0800556 uint32_t minLayerZ, uint32_t maxLayerZ) {
557 sp<ISurfaceComposer> s(ComposerService::getComposerService());
558 if (s == NULL) return NO_INIT;
559 mHeap = 0;
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700560 return s->captureScreen(display, &mHeap,
Mathias Agopianbf2c6a62010-12-10 16:22:31 -0800561 &mWidth, &mHeight, &mFormat, reqWidth, reqHeight,
562 minLayerZ, maxLayerZ);
Mathias Agopian74c40c02010-09-29 13:02:36 -0700563}
564
565void ScreenshotClient::release() {
566 mHeap = 0;
567}
568
569void const* ScreenshotClient::getPixels() const {
570 return mHeap->getBase();
571}
572
573uint32_t ScreenshotClient::getWidth() const {
574 return mWidth;
575}
576
577uint32_t ScreenshotClient::getHeight() const {
578 return mHeight;
579}
580
581PixelFormat ScreenshotClient::getFormat() const {
582 return mFormat;
583}
584
585uint32_t ScreenshotClient::getStride() const {
586 return mWidth;
587}
588
589size_t ScreenshotClient::getSize() const {
590 return mHeap->getSize();
591}
592
593// ----------------------------------------------------------------------------
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800594}; // namespace android