blob: 1b81e45da725e25704cf6cf83f50aacbcbde2bc9 [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);
122 void setDisplayOrientation(const sp<IBinder>& token, uint32_t orientation);
123 void setDisplayViewport(const sp<IBinder>& token, const Rect& viewport);
124 void setDisplayFrame(const sp<IBinder>& token, const Rect& frame);
125
Jamie Gennis28378392011-10-12 17:39:00 -0700126 static void closeGlobalTransaction(bool synchronous) {
127 Composer::getInstance().closeGlobalTransactionImpl(synchronous);
Mathias Agopiand4784a32010-05-27 19:41:15 -0700128 }
129};
130
131ANDROID_SINGLETON_STATIC_INSTANCE(Composer);
132
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800133// ---------------------------------------------------------------------------
134
Mathias Agopiane57f2922012-08-09 16:29:12 -0700135sp<IBinder> Composer::createDisplay() {
136 return ComposerService::getComposerService()->createDisplay();
137}
138
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700139sp<IBinder> Composer::getBuiltInDisplay(int32_t id) {
140 return ComposerService::getComposerService()->getBuiltInDisplay(id);
141}
142
Jamie Gennis28378392011-10-12 17:39:00 -0700143void Composer::closeGlobalTransactionImpl(bool synchronous) {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700144 sp<ISurfaceComposer> sm(ComposerService::getComposerService());
Mathias Agopian698c0872011-06-28 19:09:31 -0700145
146 Vector<ComposerState> transaction;
Mathias Agopian8b33f032012-07-24 20:43:54 -0700147 Vector<DisplayState> displayTransaction;
Jamie Gennis28378392011-10-12 17:39:00 -0700148 uint32_t flags = 0;
Mathias Agopian698c0872011-06-28 19:09:31 -0700149
150 { // scope for the lock
151 Mutex::Autolock _l(mLock);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700152 transaction = mComposerStates;
153 mComposerStates.clear();
Jamie Gennisb8d69a52011-10-10 15:48:06 -0700154
Mathias Agopiane57f2922012-08-09 16:29:12 -0700155 displayTransaction = mDisplayStates;
156 mDisplayStates.clear();
Jamie Gennis28378392011-10-12 17:39:00 -0700157
158 if (synchronous || mForceSynchronous) {
159 flags |= ISurfaceComposer::eSynchronous;
160 }
161 mForceSynchronous = false;
Mathias Agopian698c0872011-06-28 19:09:31 -0700162 }
163
Mathias Agopian8b33f032012-07-24 20:43:54 -0700164 sm->setTransactionState(transaction, displayTransaction, flags);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800165}
166
Mathias Agopian698c0872011-06-28 19:09:31 -0700167layer_state_t* Composer::getLayerStateLocked(
168 const sp<SurfaceComposerClient>& client, SurfaceID id) {
169
170 ComposerState s;
171 s.client = client->mClient;
172 s.state.surface = id;
173
Mathias Agopiane57f2922012-08-09 16:29:12 -0700174 ssize_t index = mComposerStates.indexOf(s);
Mathias Agopian698c0872011-06-28 19:09:31 -0700175 if (index < 0) {
176 // we don't have it, add an initialized layer_state to our list
Mathias Agopiane57f2922012-08-09 16:29:12 -0700177 index = mComposerStates.add(s);
Mathias Agopian698c0872011-06-28 19:09:31 -0700178 }
179
Mathias Agopiane57f2922012-08-09 16:29:12 -0700180 ComposerState* const out = mComposerStates.editArray();
Mathias Agopian698c0872011-06-28 19:09:31 -0700181 return &(out[index].state);
182}
183
184status_t Composer::setPosition(const sp<SurfaceComposerClient>& client,
Mathias Agopian41b6aab2011-08-30 18:51:54 -0700185 SurfaceID id, float x, float y) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700186 Mutex::Autolock _l(mLock);
187 layer_state_t* s = getLayerStateLocked(client, id);
188 if (!s)
189 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700190 s->what |= layer_state_t::ePositionChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700191 s->x = x;
192 s->y = y;
193 return NO_ERROR;
194}
195
196status_t Composer::setSize(const sp<SurfaceComposerClient>& client,
197 SurfaceID id, uint32_t w, uint32_t h) {
198 Mutex::Autolock _l(mLock);
199 layer_state_t* s = getLayerStateLocked(client, id);
200 if (!s)
201 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700202 s->what |= layer_state_t::eSizeChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700203 s->w = w;
204 s->h = h;
Jamie Gennis28378392011-10-12 17:39:00 -0700205
206 // Resizing a surface makes the transaction synchronous.
207 mForceSynchronous = true;
208
Mathias Agopian698c0872011-06-28 19:09:31 -0700209 return NO_ERROR;
210}
211
212status_t Composer::setLayer(const sp<SurfaceComposerClient>& client,
213 SurfaceID id, int32_t z) {
214 Mutex::Autolock _l(mLock);
215 layer_state_t* s = getLayerStateLocked(client, id);
216 if (!s)
217 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700218 s->what |= layer_state_t::eLayerChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700219 s->z = z;
220 return NO_ERROR;
221}
222
223status_t Composer::setFlags(const sp<SurfaceComposerClient>& client,
224 SurfaceID id, uint32_t flags,
225 uint32_t mask) {
226 Mutex::Autolock _l(mLock);
227 layer_state_t* s = getLayerStateLocked(client, id);
228 if (!s)
229 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700230 s->what |= layer_state_t::eVisibilityChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700231 s->flags &= ~mask;
232 s->flags |= (flags & mask);
233 s->mask |= mask;
234 return NO_ERROR;
235}
236
237status_t Composer::setTransparentRegionHint(
238 const sp<SurfaceComposerClient>& client, SurfaceID id,
239 const Region& transparentRegion) {
240 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::eTransparentRegionChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700245 s->transparentRegion = transparentRegion;
246 return NO_ERROR;
247}
248
249status_t Composer::setAlpha(const sp<SurfaceComposerClient>& client,
250 SurfaceID id, float alpha) {
251 Mutex::Autolock _l(mLock);
252 layer_state_t* s = getLayerStateLocked(client, id);
253 if (!s)
254 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700255 s->what |= layer_state_t::eAlphaChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700256 s->alpha = alpha;
257 return NO_ERROR;
258}
259
Mathias Agopian87855782012-07-24 21:41:09 -0700260status_t Composer::setLayerStack(const sp<SurfaceComposerClient>& client,
261 SurfaceID id, uint32_t layerStack) {
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::eLayerStackChanged;
Mathias Agopian87855782012-07-24 21:41:09 -0700267 s->layerStack = layerStack;
268 return NO_ERROR;
269}
270
Mathias Agopian698c0872011-06-28 19:09:31 -0700271status_t Composer::setMatrix(const sp<SurfaceComposerClient>& client,
272 SurfaceID id, float dsdx, float dtdx,
273 float dsdy, float dtdy) {
274 Mutex::Autolock _l(mLock);
275 layer_state_t* s = getLayerStateLocked(client, id);
276 if (!s)
277 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700278 s->what |= layer_state_t::eMatrixChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700279 layer_state_t::matrix22_t matrix;
280 matrix.dsdx = dsdx;
281 matrix.dtdx = dtdx;
282 matrix.dsdy = dsdy;
283 matrix.dtdy = dtdy;
284 s->matrix = matrix;
285 return NO_ERROR;
286}
287
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700288status_t Composer::setCrop(const sp<SurfaceComposerClient>& client,
289 SurfaceID id, const Rect& crop) {
290 Mutex::Autolock _l(mLock);
291 layer_state_t* s = getLayerStateLocked(client, id);
292 if (!s)
293 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700294 s->what |= layer_state_t::eCropChanged;
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700295 s->crop = crop;
296 return NO_ERROR;
297}
298
Mathias Agopian698c0872011-06-28 19:09:31 -0700299// ---------------------------------------------------------------------------
300
Mathias Agopiane57f2922012-08-09 16:29:12 -0700301DisplayState& Composer::getDisplayStateLocked(const sp<IBinder>& token) {
302 DisplayState s;
303 s.token = token;
304 ssize_t index = mDisplayStates.indexOf(s);
305 if (index < 0) {
306 // we don't have it, add an initialized layer_state to our list
307 s.what = 0;
308 index = mDisplayStates.add(s);
309 }
310 return mDisplayStates.editItemAt(index);
311}
312
313void Composer::setDisplaySurface(const sp<IBinder>& token,
314 const sp<ISurfaceTexture>& surface) {
315 Mutex::Autolock _l(mLock);
316 DisplayState& s(getDisplayStateLocked(token));
317 s.surface = surface;
318 s.what |= DisplayState::eSurfaceChanged;
319}
320
321void Composer::setDisplayLayerStack(const sp<IBinder>& token,
322 uint32_t layerStack) {
323 Mutex::Autolock _l(mLock);
324 DisplayState& s(getDisplayStateLocked(token));
325 s.layerStack = layerStack;
326 s.what |= DisplayState::eLayerStackChanged;
327}
328
329void Composer::setDisplayOrientation(const sp<IBinder>& token,
330 uint32_t orientation) {
331 Mutex::Autolock _l(mLock);
332 DisplayState& s(getDisplayStateLocked(token));
333 s.orientation = orientation;
Mathias Agopian818b4602012-08-16 20:57:39 -0700334 s.what |= DisplayState::eOrientationChanged;
Mathias Agopiane57f2922012-08-09 16:29:12 -0700335 mForceSynchronous = true; // TODO: do we actually still need this?
336}
337
338// FIXME: get rid of this eventually
339status_t Composer::setOrientation(int orientation) {
340 sp<ISurfaceComposer> sm(ComposerService::getComposerService());
341 sp<IBinder> token(sm->getBuiltInDisplay(ISurfaceComposer::eDisplayIdMain));
342 Composer::setDisplayOrientation(token, orientation);
343 return NO_ERROR;
344}
345
346void Composer::setDisplayViewport(const sp<IBinder>& token,
347 const Rect& viewport) {
348 Mutex::Autolock _l(mLock);
349 DisplayState& s(getDisplayStateLocked(token));
350 s.viewport = viewport;
Mathias Agopian818b4602012-08-16 20:57:39 -0700351 s.what |= DisplayState::eViewportChanged;
Mathias Agopiane57f2922012-08-09 16:29:12 -0700352}
353
354void Composer::setDisplayFrame(const sp<IBinder>& token,
355 const Rect& frame) {
356 Mutex::Autolock _l(mLock);
357 DisplayState& s(getDisplayStateLocked(token));
358 s.frame = frame;
Mathias Agopian818b4602012-08-16 20:57:39 -0700359 s.what |= DisplayState::eFrameChanged;
Mathias Agopiane57f2922012-08-09 16:29:12 -0700360}
361
362// ---------------------------------------------------------------------------
363
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800364SurfaceComposerClient::SurfaceComposerClient()
Mathias Agopian698c0872011-06-28 19:09:31 -0700365 : mStatus(NO_INIT), mComposer(Composer::getInstance())
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800366{
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800367}
368
Mathias Agopian698c0872011-06-28 19:09:31 -0700369void SurfaceComposerClient::onFirstRef() {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700370 sp<ISurfaceComposer> sm(ComposerService::getComposerService());
Mathias Agopiand4784a32010-05-27 19:41:15 -0700371 if (sm != 0) {
Mathias Agopian7e27f052010-05-28 14:22:23 -0700372 sp<ISurfaceComposerClient> conn = sm->createConnection();
Mathias Agopiand4784a32010-05-27 19:41:15 -0700373 if (conn != 0) {
374 mClient = conn;
Mathias Agopiand4784a32010-05-27 19:41:15 -0700375 mStatus = NO_ERROR;
376 }
377 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800378}
379
Mathias Agopian698c0872011-06-28 19:09:31 -0700380SurfaceComposerClient::~SurfaceComposerClient() {
Mathias Agopian631f3582010-05-25 17:51:34 -0700381 dispose();
382}
Mathias Agopiandd3423c2009-09-23 15:44:05 -0700383
Mathias Agopian698c0872011-06-28 19:09:31 -0700384status_t SurfaceComposerClient::initCheck() const {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800385 return mStatus;
386}
387
Mathias Agopian698c0872011-06-28 19:09:31 -0700388sp<IBinder> SurfaceComposerClient::connection() const {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800389 return (mClient != 0) ? mClient->asBinder() : 0;
390}
391
Mathias Agopiand4784a32010-05-27 19:41:15 -0700392status_t SurfaceComposerClient::linkToComposerDeath(
393 const sp<IBinder::DeathRecipient>& recipient,
Mathias Agopian698c0872011-06-28 19:09:31 -0700394 void* cookie, uint32_t flags) {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700395 sp<ISurfaceComposer> sm(ComposerService::getComposerService());
Mathias Agopiand4784a32010-05-27 19:41:15 -0700396 return sm->asBinder()->linkToDeath(recipient, cookie, flags);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800397}
398
Mathias Agopian698c0872011-06-28 19:09:31 -0700399void SurfaceComposerClient::dispose() {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800400 // this can be called more than once.
Mathias Agopian7e27f052010-05-28 14:22:23 -0700401 sp<ISurfaceComposerClient> client;
Mathias Agopiand4784a32010-05-27 19:41:15 -0700402 Mutex::Autolock _lm(mLock);
403 if (mClient != 0) {
Mathias Agopiand4784a32010-05-27 19:41:15 -0700404 client = mClient; // hold ref while lock is held
405 mClient.clear();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800406 }
Mathias Agopiand4784a32010-05-27 19:41:15 -0700407 mStatus = NO_INIT;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800408}
409
Mathias Agopian698c0872011-06-28 19:09:31 -0700410sp<SurfaceControl> SurfaceComposerClient::createSurface(
Mathias Agopian698c0872011-06-28 19:09:31 -0700411 const String8& name,
Mathias Agopian698c0872011-06-28 19:09:31 -0700412 uint32_t w,
413 uint32_t h,
414 PixelFormat format,
415 uint32_t flags)
416{
417 sp<SurfaceControl> result;
418 if (mStatus == NO_ERROR) {
419 ISurfaceComposerClient::surface_data_t data;
420 sp<ISurface> surface = mClient->createSurface(&data, name,
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700421 w, h, format, flags);
Mathias Agopian698c0872011-06-28 19:09:31 -0700422 if (surface != 0) {
Mathias Agopianc10d9d92011-07-20 16:46:11 -0700423 result = new SurfaceControl(this, surface, data);
Mathias Agopian698c0872011-06-28 19:09:31 -0700424 }
425 }
426 return result;
427}
428
Mathias Agopiane57f2922012-08-09 16:29:12 -0700429sp<IBinder> SurfaceComposerClient::createDisplay() {
430 return Composer::getInstance().createDisplay();
431}
432
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700433sp<IBinder> SurfaceComposerClient::getBuiltInDisplay(int32_t id) {
434 return Composer::getInstance().getBuiltInDisplay(id);
435}
436
Mathias Agopian698c0872011-06-28 19:09:31 -0700437status_t SurfaceComposerClient::destroySurface(SurfaceID sid) {
438 if (mStatus != NO_ERROR)
439 return mStatus;
440 status_t err = mClient->destroySurface(sid);
441 return err;
442}
443
444inline Composer& SurfaceComposerClient::getComposer() {
445 return mComposer;
446}
447
448// ----------------------------------------------------------------------------
449
450void SurfaceComposerClient::openGlobalTransaction() {
451 // Currently a no-op
452}
453
Jamie Gennis28378392011-10-12 17:39:00 -0700454void SurfaceComposerClient::closeGlobalTransaction(bool synchronous) {
455 Composer::closeGlobalTransaction(synchronous);
Mathias Agopian698c0872011-06-28 19:09:31 -0700456}
457
458// ----------------------------------------------------------------------------
459
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700460status_t SurfaceComposerClient::setCrop(SurfaceID id, const Rect& crop) {
461 return getComposer().setCrop(this, id, crop);
462}
463
Mathias Agopian41b6aab2011-08-30 18:51:54 -0700464status_t SurfaceComposerClient::setPosition(SurfaceID id, float x, float y) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700465 return getComposer().setPosition(this, id, x, y);
466}
467
468status_t SurfaceComposerClient::setSize(SurfaceID id, uint32_t w, uint32_t h) {
469 return getComposer().setSize(this, id, w, h);
470}
471
472status_t SurfaceComposerClient::setLayer(SurfaceID id, int32_t z) {
473 return getComposer().setLayer(this, id, z);
474}
475
476status_t SurfaceComposerClient::hide(SurfaceID id) {
477 return getComposer().setFlags(this, id,
Mathias Agopian3165cc22012-08-08 19:42:09 -0700478 layer_state_t::eLayerHidden,
479 layer_state_t::eLayerHidden);
Mathias Agopian698c0872011-06-28 19:09:31 -0700480}
481
482status_t SurfaceComposerClient::show(SurfaceID id, int32_t) {
483 return getComposer().setFlags(this, id,
484 0,
Mathias Agopian3165cc22012-08-08 19:42:09 -0700485 layer_state_t::eLayerHidden);
Mathias Agopian698c0872011-06-28 19:09:31 -0700486}
487
Mathias Agopian698c0872011-06-28 19:09:31 -0700488status_t SurfaceComposerClient::setFlags(SurfaceID id, uint32_t flags,
489 uint32_t mask) {
490 return getComposer().setFlags(this, id, flags, mask);
491}
492
493status_t SurfaceComposerClient::setTransparentRegionHint(SurfaceID id,
494 const Region& transparentRegion) {
495 return getComposer().setTransparentRegionHint(this, id, transparentRegion);
496}
497
498status_t SurfaceComposerClient::setAlpha(SurfaceID id, float alpha) {
499 return getComposer().setAlpha(this, id, alpha);
500}
501
Mathias Agopian87855782012-07-24 21:41:09 -0700502status_t SurfaceComposerClient::setLayerStack(SurfaceID id, uint32_t layerStack) {
503 return getComposer().setLayerStack(this, id, layerStack);
504}
505
Mathias Agopian698c0872011-06-28 19:09:31 -0700506status_t SurfaceComposerClient::setMatrix(SurfaceID id, float dsdx, float dtdx,
507 float dsdy, float dtdy) {
508 return getComposer().setMatrix(this, id, dsdx, dtdx, dsdy, dtdy);
509}
510
511// ----------------------------------------------------------------------------
512
Mathias Agopiane57f2922012-08-09 16:29:12 -0700513void SurfaceComposerClient::setDisplaySurface(const sp<IBinder>& token,
514 const sp<ISurfaceTexture>& surface) {
515 Composer::getInstance().setDisplaySurface(token, surface);
516}
517
518void SurfaceComposerClient::setDisplayLayerStack(const sp<IBinder>& token,
519 uint32_t layerStack) {
520 Composer::getInstance().setDisplayLayerStack(token, layerStack);
521}
522
523void SurfaceComposerClient::setDisplayOrientation(const sp<IBinder>& token,
524 uint32_t orientation) {
525 Composer::getInstance().setDisplayOrientation(token, orientation);
526}
527
528void SurfaceComposerClient::setDisplayViewport(const sp<IBinder>& token,
529 const Rect& viewport) {
530 Composer::getInstance().setDisplayViewport(token, viewport);
531}
532
533void SurfaceComposerClient::setDisplayFrame(const sp<IBinder>& token,
534 const Rect& frame) {
535 Composer::getInstance().setDisplayFrame(token, frame);
536}
537
538// ----------------------------------------------------------------------------
539
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800540status_t SurfaceComposerClient::getDisplayInfo(
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700541 const sp<IBinder>& display, DisplayInfo* info)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800542{
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700543 return ComposerService::getComposerService()->getDisplayInfo(display, info);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800544}
545
Mathias Agopian698c0872011-06-28 19:09:31 -0700546// ----------------------------------------------------------------------------
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800547
Mathias Agopian74c40c02010-09-29 13:02:36 -0700548ScreenshotClient::ScreenshotClient()
549 : mWidth(0), mHeight(0), mFormat(PIXEL_FORMAT_NONE) {
550}
551
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700552status_t ScreenshotClient::update(const sp<IBinder>& display) {
Mathias Agopian74c40c02010-09-29 13:02:36 -0700553 sp<ISurfaceComposer> s(ComposerService::getComposerService());
554 if (s == NULL) return NO_INIT;
555 mHeap = 0;
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700556 return s->captureScreen(display, &mHeap,
Mathias Agopianbf2c6a62010-12-10 16:22:31 -0800557 &mWidth, &mHeight, &mFormat, 0, 0,
558 0, -1UL);
Mathias Agopian74c40c02010-09-29 13:02:36 -0700559}
560
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700561status_t ScreenshotClient::update(const sp<IBinder>& display,
562 uint32_t reqWidth, uint32_t reqHeight) {
Mathias Agopian74c40c02010-09-29 13:02:36 -0700563 sp<ISurfaceComposer> s(ComposerService::getComposerService());
564 if (s == NULL) return NO_INIT;
565 mHeap = 0;
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700566 return s->captureScreen(display, &mHeap,
Mathias Agopianbf2c6a62010-12-10 16:22:31 -0800567 &mWidth, &mHeight, &mFormat, reqWidth, reqHeight,
568 0, -1UL);
569}
570
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700571status_t ScreenshotClient::update(const sp<IBinder>& display,
572 uint32_t reqWidth, uint32_t reqHeight,
Mathias Agopianbf2c6a62010-12-10 16:22:31 -0800573 uint32_t minLayerZ, uint32_t maxLayerZ) {
574 sp<ISurfaceComposer> s(ComposerService::getComposerService());
575 if (s == NULL) return NO_INIT;
576 mHeap = 0;
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700577 return s->captureScreen(display, &mHeap,
Mathias Agopianbf2c6a62010-12-10 16:22:31 -0800578 &mWidth, &mHeight, &mFormat, reqWidth, reqHeight,
579 minLayerZ, maxLayerZ);
Mathias Agopian74c40c02010-09-29 13:02:36 -0700580}
581
582void ScreenshotClient::release() {
583 mHeap = 0;
584}
585
586void const* ScreenshotClient::getPixels() const {
587 return mHeap->getBase();
588}
589
590uint32_t ScreenshotClient::getWidth() const {
591 return mWidth;
592}
593
594uint32_t ScreenshotClient::getHeight() const {
595 return mHeight;
596}
597
598PixelFormat ScreenshotClient::getFormat() const {
599 return mFormat;
600}
601
602uint32_t ScreenshotClient::getStride() const {
603 return mWidth;
604}
605
606size_t ScreenshotClient::getSize() const {
607 return mHeap->getSize();
608}
609
610// ----------------------------------------------------------------------------
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800611}; // namespace android