blob: 1e6e1bdcdaffe36a4e2949fe3a470e928fa57775 [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();
Mathias Agopian698c0872011-06-28 19:09:31 -070097
98 status_t setPosition(const sp<SurfaceComposerClient>& client, SurfaceID id,
Mathias Agopian41b6aab2011-08-30 18:51:54 -070099 float x, float y);
Mathias Agopian698c0872011-06-28 19:09:31 -0700100 status_t setSize(const sp<SurfaceComposerClient>& client, SurfaceID id,
101 uint32_t w, uint32_t h);
102 status_t setLayer(const sp<SurfaceComposerClient>& client, SurfaceID id,
103 int32_t z);
104 status_t setFlags(const sp<SurfaceComposerClient>& client, SurfaceID id,
105 uint32_t flags, uint32_t mask);
106 status_t setTransparentRegionHint(
107 const sp<SurfaceComposerClient>& client, SurfaceID id,
108 const Region& transparentRegion);
109 status_t setAlpha(const sp<SurfaceComposerClient>& client, SurfaceID id,
110 float alpha);
111 status_t setMatrix(const sp<SurfaceComposerClient>& client, SurfaceID id,
112 float dsdx, float dtdx, float dsdy, float dtdy);
Jamie Gennisb8d69a52011-10-10 15:48:06 -0700113 status_t setOrientation(int orientation);
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700114 status_t setCrop(const sp<SurfaceComposerClient>& client, SurfaceID id,
115 const Rect& crop);
Mathias Agopian87855782012-07-24 21:41:09 -0700116 status_t setLayerStack(const sp<SurfaceComposerClient>& client,
117 SurfaceID id, uint32_t layerStack);
Mathias Agopian698c0872011-06-28 19:09:31 -0700118
Mathias Agopiane57f2922012-08-09 16:29:12 -0700119 void setDisplaySurface(const sp<IBinder>& token, const sp<ISurfaceTexture>& surface);
120 void setDisplayLayerStack(const sp<IBinder>& token, uint32_t layerStack);
121 void setDisplayOrientation(const sp<IBinder>& token, uint32_t orientation);
122 void setDisplayViewport(const sp<IBinder>& token, const Rect& viewport);
123 void setDisplayFrame(const sp<IBinder>& token, const Rect& frame);
124
Jamie Gennis28378392011-10-12 17:39:00 -0700125 static void closeGlobalTransaction(bool synchronous) {
126 Composer::getInstance().closeGlobalTransactionImpl(synchronous);
Mathias Agopiand4784a32010-05-27 19:41:15 -0700127 }
128};
129
130ANDROID_SINGLETON_STATIC_INSTANCE(Composer);
131
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800132// ---------------------------------------------------------------------------
133
Mathias Agopiane57f2922012-08-09 16:29:12 -0700134sp<IBinder> Composer::createDisplay() {
135 return ComposerService::getComposerService()->createDisplay();
136}
137
Jamie Gennis28378392011-10-12 17:39:00 -0700138void Composer::closeGlobalTransactionImpl(bool synchronous) {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700139 sp<ISurfaceComposer> sm(ComposerService::getComposerService());
Mathias Agopian698c0872011-06-28 19:09:31 -0700140
141 Vector<ComposerState> transaction;
Mathias Agopian8b33f032012-07-24 20:43:54 -0700142 Vector<DisplayState> displayTransaction;
Jamie Gennis28378392011-10-12 17:39:00 -0700143 uint32_t flags = 0;
Mathias Agopian698c0872011-06-28 19:09:31 -0700144
145 { // scope for the lock
146 Mutex::Autolock _l(mLock);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700147 transaction = mComposerStates;
148 mComposerStates.clear();
Jamie Gennisb8d69a52011-10-10 15:48:06 -0700149
Mathias Agopiane57f2922012-08-09 16:29:12 -0700150 displayTransaction = mDisplayStates;
151 mDisplayStates.clear();
Jamie Gennis28378392011-10-12 17:39:00 -0700152
153 if (synchronous || mForceSynchronous) {
154 flags |= ISurfaceComposer::eSynchronous;
155 }
156 mForceSynchronous = false;
Mathias Agopian698c0872011-06-28 19:09:31 -0700157 }
158
Mathias Agopian8b33f032012-07-24 20:43:54 -0700159 sm->setTransactionState(transaction, displayTransaction, flags);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800160}
161
Mathias Agopian698c0872011-06-28 19:09:31 -0700162layer_state_t* Composer::getLayerStateLocked(
163 const sp<SurfaceComposerClient>& client, SurfaceID id) {
164
165 ComposerState s;
166 s.client = client->mClient;
167 s.state.surface = id;
168
Mathias Agopiane57f2922012-08-09 16:29:12 -0700169 ssize_t index = mComposerStates.indexOf(s);
Mathias Agopian698c0872011-06-28 19:09:31 -0700170 if (index < 0) {
171 // we don't have it, add an initialized layer_state to our list
Mathias Agopiane57f2922012-08-09 16:29:12 -0700172 index = mComposerStates.add(s);
Mathias Agopian698c0872011-06-28 19:09:31 -0700173 }
174
Mathias Agopiane57f2922012-08-09 16:29:12 -0700175 ComposerState* const out = mComposerStates.editArray();
Mathias Agopian698c0872011-06-28 19:09:31 -0700176 return &(out[index].state);
177}
178
179status_t Composer::setPosition(const sp<SurfaceComposerClient>& client,
Mathias Agopian41b6aab2011-08-30 18:51:54 -0700180 SurfaceID id, float x, float y) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700181 Mutex::Autolock _l(mLock);
182 layer_state_t* s = getLayerStateLocked(client, id);
183 if (!s)
184 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700185 s->what |= layer_state_t::ePositionChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700186 s->x = x;
187 s->y = y;
188 return NO_ERROR;
189}
190
191status_t Composer::setSize(const sp<SurfaceComposerClient>& client,
192 SurfaceID id, uint32_t w, uint32_t h) {
193 Mutex::Autolock _l(mLock);
194 layer_state_t* s = getLayerStateLocked(client, id);
195 if (!s)
196 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700197 s->what |= layer_state_t::eSizeChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700198 s->w = w;
199 s->h = h;
Jamie Gennis28378392011-10-12 17:39:00 -0700200
201 // Resizing a surface makes the transaction synchronous.
202 mForceSynchronous = true;
203
Mathias Agopian698c0872011-06-28 19:09:31 -0700204 return NO_ERROR;
205}
206
207status_t Composer::setLayer(const sp<SurfaceComposerClient>& client,
208 SurfaceID id, int32_t z) {
209 Mutex::Autolock _l(mLock);
210 layer_state_t* s = getLayerStateLocked(client, id);
211 if (!s)
212 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700213 s->what |= layer_state_t::eLayerChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700214 s->z = z;
215 return NO_ERROR;
216}
217
218status_t Composer::setFlags(const sp<SurfaceComposerClient>& client,
219 SurfaceID id, uint32_t flags,
220 uint32_t mask) {
221 Mutex::Autolock _l(mLock);
222 layer_state_t* s = getLayerStateLocked(client, id);
223 if (!s)
224 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700225 s->what |= layer_state_t::eVisibilityChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700226 s->flags &= ~mask;
227 s->flags |= (flags & mask);
228 s->mask |= mask;
229 return NO_ERROR;
230}
231
232status_t Composer::setTransparentRegionHint(
233 const sp<SurfaceComposerClient>& client, SurfaceID id,
234 const Region& transparentRegion) {
235 Mutex::Autolock _l(mLock);
236 layer_state_t* s = getLayerStateLocked(client, id);
237 if (!s)
238 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700239 s->what |= layer_state_t::eTransparentRegionChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700240 s->transparentRegion = transparentRegion;
241 return NO_ERROR;
242}
243
244status_t Composer::setAlpha(const sp<SurfaceComposerClient>& client,
245 SurfaceID id, float alpha) {
246 Mutex::Autolock _l(mLock);
247 layer_state_t* s = getLayerStateLocked(client, id);
248 if (!s)
249 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700250 s->what |= layer_state_t::eAlphaChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700251 s->alpha = alpha;
252 return NO_ERROR;
253}
254
Mathias Agopian87855782012-07-24 21:41:09 -0700255status_t Composer::setLayerStack(const sp<SurfaceComposerClient>& client,
256 SurfaceID id, uint32_t layerStack) {
257 Mutex::Autolock _l(mLock);
258 layer_state_t* s = getLayerStateLocked(client, id);
259 if (!s)
260 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700261 s->what |= layer_state_t::eLayerStackChanged;
Mathias Agopian87855782012-07-24 21:41:09 -0700262 s->layerStack = layerStack;
263 return NO_ERROR;
264}
265
Mathias Agopian698c0872011-06-28 19:09:31 -0700266status_t Composer::setMatrix(const sp<SurfaceComposerClient>& client,
267 SurfaceID id, float dsdx, float dtdx,
268 float dsdy, float dtdy) {
269 Mutex::Autolock _l(mLock);
270 layer_state_t* s = getLayerStateLocked(client, id);
271 if (!s)
272 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700273 s->what |= layer_state_t::eMatrixChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700274 layer_state_t::matrix22_t matrix;
275 matrix.dsdx = dsdx;
276 matrix.dtdx = dtdx;
277 matrix.dsdy = dsdy;
278 matrix.dtdy = dtdy;
279 s->matrix = matrix;
280 return NO_ERROR;
281}
282
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700283status_t Composer::setCrop(const sp<SurfaceComposerClient>& client,
284 SurfaceID id, const Rect& crop) {
285 Mutex::Autolock _l(mLock);
286 layer_state_t* s = getLayerStateLocked(client, id);
287 if (!s)
288 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700289 s->what |= layer_state_t::eCropChanged;
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700290 s->crop = crop;
291 return NO_ERROR;
292}
293
Mathias Agopian698c0872011-06-28 19:09:31 -0700294// ---------------------------------------------------------------------------
295
Mathias Agopiane57f2922012-08-09 16:29:12 -0700296DisplayState& Composer::getDisplayStateLocked(const sp<IBinder>& token) {
297 DisplayState s;
298 s.token = token;
299 ssize_t index = mDisplayStates.indexOf(s);
300 if (index < 0) {
301 // we don't have it, add an initialized layer_state to our list
302 s.what = 0;
303 index = mDisplayStates.add(s);
304 }
305 return mDisplayStates.editItemAt(index);
306}
307
308void Composer::setDisplaySurface(const sp<IBinder>& token,
309 const sp<ISurfaceTexture>& surface) {
310 Mutex::Autolock _l(mLock);
311 DisplayState& s(getDisplayStateLocked(token));
312 s.surface = surface;
313 s.what |= DisplayState::eSurfaceChanged;
314}
315
316void Composer::setDisplayLayerStack(const sp<IBinder>& token,
317 uint32_t layerStack) {
318 Mutex::Autolock _l(mLock);
319 DisplayState& s(getDisplayStateLocked(token));
320 s.layerStack = layerStack;
321 s.what |= DisplayState::eLayerStackChanged;
322}
323
324void Composer::setDisplayOrientation(const sp<IBinder>& token,
325 uint32_t orientation) {
326 Mutex::Autolock _l(mLock);
327 DisplayState& s(getDisplayStateLocked(token));
328 s.orientation = orientation;
Mathias Agopian818b4602012-08-16 20:57:39 -0700329 s.what |= DisplayState::eOrientationChanged;
Mathias Agopiane57f2922012-08-09 16:29:12 -0700330 mForceSynchronous = true; // TODO: do we actually still need this?
331}
332
333// FIXME: get rid of this eventually
334status_t Composer::setOrientation(int orientation) {
335 sp<ISurfaceComposer> sm(ComposerService::getComposerService());
336 sp<IBinder> token(sm->getBuiltInDisplay(ISurfaceComposer::eDisplayIdMain));
337 Composer::setDisplayOrientation(token, orientation);
338 return NO_ERROR;
339}
340
341void Composer::setDisplayViewport(const sp<IBinder>& token,
342 const Rect& viewport) {
343 Mutex::Autolock _l(mLock);
344 DisplayState& s(getDisplayStateLocked(token));
345 s.viewport = viewport;
Mathias Agopian818b4602012-08-16 20:57:39 -0700346 s.what |= DisplayState::eViewportChanged;
Mathias Agopiane57f2922012-08-09 16:29:12 -0700347}
348
349void Composer::setDisplayFrame(const sp<IBinder>& token,
350 const Rect& frame) {
351 Mutex::Autolock _l(mLock);
352 DisplayState& s(getDisplayStateLocked(token));
353 s.frame = frame;
Mathias Agopian818b4602012-08-16 20:57:39 -0700354 s.what |= DisplayState::eFrameChanged;
Mathias Agopiane57f2922012-08-09 16:29:12 -0700355}
356
357// ---------------------------------------------------------------------------
358
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800359SurfaceComposerClient::SurfaceComposerClient()
Mathias Agopian698c0872011-06-28 19:09:31 -0700360 : mStatus(NO_INIT), mComposer(Composer::getInstance())
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800361{
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800362}
363
Mathias Agopian698c0872011-06-28 19:09:31 -0700364void SurfaceComposerClient::onFirstRef() {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700365 sp<ISurfaceComposer> sm(ComposerService::getComposerService());
Mathias Agopiand4784a32010-05-27 19:41:15 -0700366 if (sm != 0) {
Mathias Agopian7e27f052010-05-28 14:22:23 -0700367 sp<ISurfaceComposerClient> conn = sm->createConnection();
Mathias Agopiand4784a32010-05-27 19:41:15 -0700368 if (conn != 0) {
369 mClient = conn;
Mathias Agopiand4784a32010-05-27 19:41:15 -0700370 mStatus = NO_ERROR;
371 }
372 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800373}
374
Mathias Agopian698c0872011-06-28 19:09:31 -0700375SurfaceComposerClient::~SurfaceComposerClient() {
Mathias Agopian631f3582010-05-25 17:51:34 -0700376 dispose();
377}
Mathias Agopiandd3423c2009-09-23 15:44:05 -0700378
Mathias Agopian698c0872011-06-28 19:09:31 -0700379status_t SurfaceComposerClient::initCheck() const {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800380 return mStatus;
381}
382
Mathias Agopian698c0872011-06-28 19:09:31 -0700383sp<IBinder> SurfaceComposerClient::connection() const {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800384 return (mClient != 0) ? mClient->asBinder() : 0;
385}
386
Mathias Agopiand4784a32010-05-27 19:41:15 -0700387status_t SurfaceComposerClient::linkToComposerDeath(
388 const sp<IBinder::DeathRecipient>& recipient,
Mathias Agopian698c0872011-06-28 19:09:31 -0700389 void* cookie, uint32_t flags) {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700390 sp<ISurfaceComposer> sm(ComposerService::getComposerService());
Mathias Agopiand4784a32010-05-27 19:41:15 -0700391 return sm->asBinder()->linkToDeath(recipient, cookie, flags);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800392}
393
Mathias Agopian698c0872011-06-28 19:09:31 -0700394void SurfaceComposerClient::dispose() {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800395 // this can be called more than once.
Mathias Agopian7e27f052010-05-28 14:22:23 -0700396 sp<ISurfaceComposerClient> client;
Mathias Agopiand4784a32010-05-27 19:41:15 -0700397 Mutex::Autolock _lm(mLock);
398 if (mClient != 0) {
Mathias Agopiand4784a32010-05-27 19:41:15 -0700399 client = mClient; // hold ref while lock is held
400 mClient.clear();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800401 }
Mathias Agopiand4784a32010-05-27 19:41:15 -0700402 mStatus = NO_INIT;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800403}
404
Mathias Agopian698c0872011-06-28 19:09:31 -0700405sp<SurfaceControl> SurfaceComposerClient::createSurface(
406 DisplayID display,
407 uint32_t w,
408 uint32_t h,
409 PixelFormat format,
410 uint32_t flags)
411{
412 String8 name;
413 const size_t SIZE = 128;
414 char buffer[SIZE];
415 snprintf(buffer, SIZE, "<pid_%d>", getpid());
416 name.append(buffer);
417
418 return SurfaceComposerClient::createSurface(name, display,
419 w, h, format, flags);
420}
421
422sp<SurfaceControl> SurfaceComposerClient::createSurface(
423 const String8& name,
424 DisplayID display,
425 uint32_t w,
426 uint32_t h,
427 PixelFormat format,
428 uint32_t flags)
429{
430 sp<SurfaceControl> result;
431 if (mStatus == NO_ERROR) {
432 ISurfaceComposerClient::surface_data_t data;
433 sp<ISurface> surface = mClient->createSurface(&data, name,
434 display, w, h, format, flags);
435 if (surface != 0) {
Mathias Agopianc10d9d92011-07-20 16:46:11 -0700436 result = new SurfaceControl(this, surface, data);
Mathias Agopian698c0872011-06-28 19:09:31 -0700437 }
438 }
439 return result;
440}
441
Mathias Agopiane57f2922012-08-09 16:29:12 -0700442sp<IBinder> SurfaceComposerClient::createDisplay() {
443 return Composer::getInstance().createDisplay();
444}
445
Mathias Agopian698c0872011-06-28 19:09:31 -0700446status_t SurfaceComposerClient::destroySurface(SurfaceID sid) {
447 if (mStatus != NO_ERROR)
448 return mStatus;
449 status_t err = mClient->destroySurface(sid);
450 return err;
451}
452
453inline Composer& SurfaceComposerClient::getComposer() {
454 return mComposer;
455}
456
457// ----------------------------------------------------------------------------
458
459void SurfaceComposerClient::openGlobalTransaction() {
460 // Currently a no-op
461}
462
Jamie Gennis28378392011-10-12 17:39:00 -0700463void SurfaceComposerClient::closeGlobalTransaction(bool synchronous) {
464 Composer::closeGlobalTransaction(synchronous);
Mathias Agopian698c0872011-06-28 19:09:31 -0700465}
466
467// ----------------------------------------------------------------------------
468
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700469status_t SurfaceComposerClient::setCrop(SurfaceID id, const Rect& crop) {
470 return getComposer().setCrop(this, id, crop);
471}
472
Mathias Agopian41b6aab2011-08-30 18:51:54 -0700473status_t SurfaceComposerClient::setPosition(SurfaceID id, float x, float y) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700474 return getComposer().setPosition(this, id, x, y);
475}
476
477status_t SurfaceComposerClient::setSize(SurfaceID id, uint32_t w, uint32_t h) {
478 return getComposer().setSize(this, id, w, h);
479}
480
481status_t SurfaceComposerClient::setLayer(SurfaceID id, int32_t z) {
482 return getComposer().setLayer(this, id, z);
483}
484
485status_t SurfaceComposerClient::hide(SurfaceID id) {
486 return getComposer().setFlags(this, id,
Mathias Agopian3165cc22012-08-08 19:42:09 -0700487 layer_state_t::eLayerHidden,
488 layer_state_t::eLayerHidden);
Mathias Agopian698c0872011-06-28 19:09:31 -0700489}
490
491status_t SurfaceComposerClient::show(SurfaceID id, int32_t) {
492 return getComposer().setFlags(this, id,
493 0,
Mathias Agopian3165cc22012-08-08 19:42:09 -0700494 layer_state_t::eLayerHidden);
Mathias Agopian698c0872011-06-28 19:09:31 -0700495}
496
Mathias Agopian698c0872011-06-28 19:09:31 -0700497status_t SurfaceComposerClient::setFlags(SurfaceID id, uint32_t flags,
498 uint32_t mask) {
499 return getComposer().setFlags(this, id, flags, mask);
500}
501
502status_t SurfaceComposerClient::setTransparentRegionHint(SurfaceID id,
503 const Region& transparentRegion) {
504 return getComposer().setTransparentRegionHint(this, id, transparentRegion);
505}
506
507status_t SurfaceComposerClient::setAlpha(SurfaceID id, float alpha) {
508 return getComposer().setAlpha(this, id, alpha);
509}
510
Mathias Agopian87855782012-07-24 21:41:09 -0700511status_t SurfaceComposerClient::setLayerStack(SurfaceID id, uint32_t layerStack) {
512 return getComposer().setLayerStack(this, id, layerStack);
513}
514
Mathias Agopian698c0872011-06-28 19:09:31 -0700515status_t SurfaceComposerClient::setMatrix(SurfaceID id, float dsdx, float dtdx,
516 float dsdy, float dtdy) {
517 return getComposer().setMatrix(this, id, dsdx, dtdx, dsdy, dtdy);
518}
519
Jamie Gennisb8d69a52011-10-10 15:48:06 -0700520status_t SurfaceComposerClient::setOrientation(DisplayID dpy,
521 int orientation, uint32_t flags)
522{
523 return Composer::getInstance().setOrientation(orientation);
524}
525
Mathias Agopian698c0872011-06-28 19:09:31 -0700526// ----------------------------------------------------------------------------
527
Mathias Agopiane57f2922012-08-09 16:29:12 -0700528void SurfaceComposerClient::setDisplaySurface(const sp<IBinder>& token,
529 const sp<ISurfaceTexture>& surface) {
530 Composer::getInstance().setDisplaySurface(token, surface);
531}
532
533void SurfaceComposerClient::setDisplayLayerStack(const sp<IBinder>& token,
534 uint32_t layerStack) {
535 Composer::getInstance().setDisplayLayerStack(token, layerStack);
536}
537
538void SurfaceComposerClient::setDisplayOrientation(const sp<IBinder>& token,
539 uint32_t orientation) {
540 Composer::getInstance().setDisplayOrientation(token, orientation);
541}
542
543void SurfaceComposerClient::setDisplayViewport(const sp<IBinder>& token,
544 const Rect& viewport) {
545 Composer::getInstance().setDisplayViewport(token, viewport);
546}
547
548void SurfaceComposerClient::setDisplayFrame(const sp<IBinder>& token,
549 const Rect& frame) {
550 Composer::getInstance().setDisplayFrame(token, frame);
551}
552
553// ----------------------------------------------------------------------------
554
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800555status_t SurfaceComposerClient::getDisplayInfo(
556 DisplayID dpy, DisplayInfo* info)
557{
Mathias Agopiane57f2922012-08-09 16:29:12 -0700558 return ComposerService::getComposerService()->getDisplayInfo(dpy, info);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800559}
560
Mathias Agopian698c0872011-06-28 19:09:31 -0700561// ----------------------------------------------------------------------------
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800562
Mathias Agopian74c40c02010-09-29 13:02:36 -0700563ScreenshotClient::ScreenshotClient()
564 : mWidth(0), mHeight(0), mFormat(PIXEL_FORMAT_NONE) {
565}
566
567status_t ScreenshotClient::update() {
568 sp<ISurfaceComposer> s(ComposerService::getComposerService());
569 if (s == NULL) return NO_INIT;
570 mHeap = 0;
571 return s->captureScreen(0, &mHeap,
Mathias Agopianbf2c6a62010-12-10 16:22:31 -0800572 &mWidth, &mHeight, &mFormat, 0, 0,
573 0, -1UL);
Mathias Agopian74c40c02010-09-29 13:02:36 -0700574}
575
576status_t ScreenshotClient::update(uint32_t reqWidth, uint32_t reqHeight) {
577 sp<ISurfaceComposer> s(ComposerService::getComposerService());
578 if (s == NULL) return NO_INIT;
579 mHeap = 0;
580 return s->captureScreen(0, &mHeap,
Mathias Agopianbf2c6a62010-12-10 16:22:31 -0800581 &mWidth, &mHeight, &mFormat, reqWidth, reqHeight,
582 0, -1UL);
583}
584
585status_t ScreenshotClient::update(uint32_t reqWidth, uint32_t reqHeight,
586 uint32_t minLayerZ, uint32_t maxLayerZ) {
587 sp<ISurfaceComposer> s(ComposerService::getComposerService());
588 if (s == NULL) return NO_INIT;
589 mHeap = 0;
590 return s->captureScreen(0, &mHeap,
591 &mWidth, &mHeight, &mFormat, reqWidth, reqHeight,
592 minLayerZ, maxLayerZ);
Mathias Agopian74c40c02010-09-29 13:02:36 -0700593}
594
595void ScreenshotClient::release() {
596 mHeap = 0;
597}
598
599void const* ScreenshotClient::getPixels() const {
600 return mHeap->getBase();
601}
602
603uint32_t ScreenshotClient::getWidth() const {
604 return mWidth;
605}
606
607uint32_t ScreenshotClient::getHeight() const {
608 return mHeight;
609}
610
611PixelFormat ScreenshotClient::getFormat() const {
612 return mFormat;
613}
614
615uint32_t ScreenshotClient::getStride() const {
616 return mWidth;
617}
618
619size_t ScreenshotClient::getSize() const {
620 return mHeap->getSize();
621}
622
623// ----------------------------------------------------------------------------
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800624}; // namespace android