blob: a1ff2c1e2f5dadb00f330e52c9abaf5ee8c6c90b [file] [log] [blame]
The Android Open Source Project9066cfe2009-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 Project9066cfe2009-03-03 19:31:44 -080020#include <sys/types.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080021
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080022#include <utils/Errors.h>
23#include <utils/threads.h>
Mathias Agopianc7b388c2010-05-27 19:41:15 -070024#include <utils/SortedVector.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080025#include <utils/Log.h>
Mathias Agopianc7b388c2010-05-27 19:41:15 -070026#include <utils/Singleton.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080027
Mathias Agopian000479f2010-02-09 17:46:37 -080028#include <binder/IServiceManager.h>
29#include <binder/IMemory.h>
30
Mathias Agopian1473f462009-04-10 14:24:30 -070031#include <ui/DisplayInfo.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080032
Mathias Agopian000479f2010-02-09 17:46:37 -080033#include <surfaceflinger/ISurfaceComposer.h>
Mathias Agopian770492c2010-05-28 14:22:23 -070034#include <surfaceflinger/ISurfaceComposerClient.h>
Mathias Agopian000479f2010-02-09 17:46:37 -080035#include <surfaceflinger/ISurface.h>
36#include <surfaceflinger/SurfaceComposerClient.h>
37
38#include <private/surfaceflinger/LayerState.h>
39#include <private/surfaceflinger/SharedBufferStack.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080040
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080041
42namespace android {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080043// ---------------------------------------------------------------------------
44
Mathias Agopian770492c2010-05-28 14:22:23 -070045ANDROID_SINGLETON_STATIC_INSTANCE(ComposerService);
46
Mathias Agopian7623da42010-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 }
53 mServerCblkMemory = mComposerService->getCblk();
54 mServerCblk = static_cast<surface_flinger_cblk_t volatile *>(
55 mServerCblkMemory->getBase());
56}
57
58sp<ISurfaceComposer> ComposerService::getComposerService() {
59 return ComposerService::getInstance().mComposerService;
60}
61
62surface_flinger_cblk_t const volatile * ComposerService::getControlBlock() {
63 return ComposerService::getInstance().mServerCblk;
64}
Mathias Agopian770492c2010-05-28 14:22:23 -070065
66static inline sp<ISurfaceComposer> getComposerService() {
67 return ComposerService::getComposerService();
68}
69
70static inline surface_flinger_cblk_t const volatile * get_cblk() {
71 return ComposerService::getControlBlock();
72}
73
74// ---------------------------------------------------------------------------
75
76class Composer : public Singleton<Composer>
77{
78 Mutex mLock;
79 SortedVector< wp<SurfaceComposerClient> > mActiveConnections;
80 SortedVector<sp<SurfaceComposerClient> > mOpenTransactions;
81
82 Composer() : Singleton<Composer>() {
83 }
84
Mathias Agopianc7b388c2010-05-27 19:41:15 -070085 void addClientImpl(const sp<SurfaceComposerClient>& client) {
86 Mutex::Autolock _l(mLock);
87 mActiveConnections.add(client);
88 }
89
90 void removeClientImpl(const sp<SurfaceComposerClient>& client) {
91 Mutex::Autolock _l(mLock);
92 mActiveConnections.remove(client);
93 }
94
95 void openGlobalTransactionImpl()
96 {
97 Mutex::Autolock _l(mLock);
98 if (mOpenTransactions.size()) {
99 LOGE("openGlobalTransaction() called more than once. skipping.");
100 return;
101 }
102 const size_t N = mActiveConnections.size();
103 for (size_t i=0; i<N; i++) {
104 sp<SurfaceComposerClient> client(mActiveConnections[i].promote());
105 if (client != 0 && mOpenTransactions.indexOf(client) < 0) {
106 if (client->openTransaction() == NO_ERROR) {
107 mOpenTransactions.add(client);
108 } else {
109 LOGE("openTransaction on client %p failed", client.get());
110 // let it go, it'll fail later when the user
111 // tries to do something with the transaction
112 }
Mathias Agopianbc726112009-09-23 15:44:05 -0700113 }
Mathias Agopianbc726112009-09-23 15:44:05 -0700114 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800115 }
Mathias Agopianc7b388c2010-05-27 19:41:15 -0700116
117 void closeGlobalTransactionImpl()
118 {
119 mLock.lock();
120 SortedVector< sp<SurfaceComposerClient> > clients(mOpenTransactions);
121 mOpenTransactions.clear();
122 mLock.unlock();
123
Mathias Agopian770492c2010-05-28 14:22:23 -0700124 sp<ISurfaceComposer> sm(getComposerService());
Mathias Agopianc7b388c2010-05-27 19:41:15 -0700125 sm->openGlobalTransaction();
126 const size_t N = clients.size();
127 for (size_t i=0; i<N; i++) {
128 clients[i]->closeTransaction();
129 }
130 sm->closeGlobalTransaction();
131 }
132
133 friend class Singleton<Composer>;
134
135public:
Mathias Agopianc7b388c2010-05-27 19:41:15 -0700136 static void addClient(const sp<SurfaceComposerClient>& client) {
137 Composer::getInstance().addClientImpl(client);
138 }
139 static void removeClient(const sp<SurfaceComposerClient>& client) {
140 Composer::getInstance().removeClientImpl(client);
141 }
142 static void openGlobalTransaction() {
143 Composer::getInstance().openGlobalTransactionImpl();
144 }
145 static void closeGlobalTransaction() {
146 Composer::getInstance().closeGlobalTransactionImpl();
147 }
148};
149
150ANDROID_SINGLETON_STATIC_INSTANCE(Composer);
151
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800152// ---------------------------------------------------------------------------
153
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800154static inline int compare_type( const layer_state_t& lhs,
155 const layer_state_t& rhs) {
156 if (lhs.surface < rhs.surface) return -1;
157 if (lhs.surface > rhs.surface) return 1;
158 return 0;
159}
160
161SurfaceComposerClient::SurfaceComposerClient()
Mathias Agopianc7b388c2010-05-27 19:41:15 -0700162 : mTransactionOpen(0), mPrebuiltLayerState(0), mStatus(NO_INIT)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800163{
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800164}
165
Mathias Agopianc7b388c2010-05-27 19:41:15 -0700166void SurfaceComposerClient::onFirstRef()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800167{
Mathias Agopianc7b388c2010-05-27 19:41:15 -0700168 sp<ISurfaceComposer> sm(getComposerService());
169 if (sm != 0) {
Mathias Agopian770492c2010-05-28 14:22:23 -0700170 sp<ISurfaceComposerClient> conn = sm->createConnection();
Mathias Agopianc7b388c2010-05-27 19:41:15 -0700171 if (conn != 0) {
172 mClient = conn;
173 Composer::addClient(this);
174 mPrebuiltLayerState = new layer_state_t;
175 mStatus = NO_ERROR;
176 }
177 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800178}
179
Mathias Agopian2ce19af2010-05-25 17:51:34 -0700180SurfaceComposerClient::~SurfaceComposerClient()
181{
Mathias Agopianc7b388c2010-05-27 19:41:15 -0700182 delete mPrebuiltLayerState;
Mathias Agopian2ce19af2010-05-25 17:51:34 -0700183 dispose();
184}
Mathias Agopianbc726112009-09-23 15:44:05 -0700185
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800186status_t SurfaceComposerClient::initCheck() const
187{
188 return mStatus;
189}
190
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800191sp<IBinder> SurfaceComposerClient::connection() const
192{
193 return (mClient != 0) ? mClient->asBinder() : 0;
194}
195
Mathias Agopianc7b388c2010-05-27 19:41:15 -0700196status_t SurfaceComposerClient::linkToComposerDeath(
197 const sp<IBinder::DeathRecipient>& recipient,
198 void* cookie, uint32_t flags)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800199{
Mathias Agopianc7b388c2010-05-27 19:41:15 -0700200 sp<ISurfaceComposer> sm(getComposerService());
201 return sm->asBinder()->linkToDeath(recipient, cookie, flags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800202}
203
204void SurfaceComposerClient::dispose()
205{
206 // this can be called more than once.
Mathias Agopian770492c2010-05-28 14:22:23 -0700207 sp<ISurfaceComposerClient> client;
Mathias Agopianc7b388c2010-05-27 19:41:15 -0700208 Mutex::Autolock _lm(mLock);
209 if (mClient != 0) {
210 Composer::removeClient(this);
211 client = mClient; // hold ref while lock is held
212 mClient.clear();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800213 }
Mathias Agopianc7b388c2010-05-27 19:41:15 -0700214 mStatus = NO_INIT;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800215}
216
217status_t SurfaceComposerClient::getDisplayInfo(
218 DisplayID dpy, DisplayInfo* info)
219{
Mathias Agopian898c4c92010-05-18 17:06:55 -0700220 if (uint32_t(dpy)>=SharedBufferStack::NUM_DISPLAY_MAX)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800221 return BAD_VALUE;
222
223 volatile surface_flinger_cblk_t const * cblk = get_cblk();
224 volatile display_cblk_t const * dcblk = cblk->displays + dpy;
225
226 info->w = dcblk->w;
227 info->h = dcblk->h;
228 info->orientation = dcblk->orientation;
229 info->xdpi = dcblk->xdpi;
230 info->ydpi = dcblk->ydpi;
231 info->fps = dcblk->fps;
232 info->density = dcblk->density;
233 return getPixelFormatInfo(dcblk->format, &(info->pixelFormatInfo));
234}
235
236ssize_t SurfaceComposerClient::getDisplayWidth(DisplayID dpy)
237{
Mathias Agopian898c4c92010-05-18 17:06:55 -0700238 if (uint32_t(dpy)>=SharedBufferStack::NUM_DISPLAY_MAX)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800239 return BAD_VALUE;
240 volatile surface_flinger_cblk_t const * cblk = get_cblk();
241 volatile display_cblk_t const * dcblk = cblk->displays + dpy;
242 return dcblk->w;
243}
244
245ssize_t SurfaceComposerClient::getDisplayHeight(DisplayID dpy)
246{
Mathias Agopian898c4c92010-05-18 17:06:55 -0700247 if (uint32_t(dpy)>=SharedBufferStack::NUM_DISPLAY_MAX)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800248 return BAD_VALUE;
249 volatile surface_flinger_cblk_t const * cblk = get_cblk();
250 volatile display_cblk_t const * dcblk = cblk->displays + dpy;
251 return dcblk->h;
252}
253
254ssize_t SurfaceComposerClient::getDisplayOrientation(DisplayID dpy)
255{
Mathias Agopian898c4c92010-05-18 17:06:55 -0700256 if (uint32_t(dpy)>=SharedBufferStack::NUM_DISPLAY_MAX)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800257 return BAD_VALUE;
258 volatile surface_flinger_cblk_t const * cblk = get_cblk();
259 volatile display_cblk_t const * dcblk = cblk->displays + dpy;
260 return dcblk->orientation;
261}
262
263ssize_t SurfaceComposerClient::getNumberOfDisplays()
264{
265 volatile surface_flinger_cblk_t const * cblk = get_cblk();
266 uint32_t connected = cblk->connected;
267 int n = 0;
268 while (connected) {
269 if (connected&1) n++;
270 connected >>= 1;
271 }
272 return n;
273}
274
Mathias Agopian17f638b2009-04-16 20:04:08 -0700275sp<SurfaceControl> SurfaceComposerClient::createSurface(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800276 DisplayID display,
277 uint32_t w,
278 uint32_t h,
279 PixelFormat format,
280 uint32_t flags)
281{
Mathias Agopian5d26c1e2010-03-01 16:09:43 -0800282 String8 name;
283 const size_t SIZE = 128;
284 char buffer[SIZE];
285 snprintf(buffer, SIZE, "<pid_%d>", getpid());
286 name.append(buffer);
287
Mathias Agopian9638e5c2011-04-20 14:19:32 -0700288 return SurfaceComposerClient::createSurface(name, display,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -0800289 w, h, format, flags);
Mathias Agopian5d26c1e2010-03-01 16:09:43 -0800290}
291
292sp<SurfaceControl> SurfaceComposerClient::createSurface(
Mathias Agopian5d26c1e2010-03-01 16:09:43 -0800293 const String8& name,
294 DisplayID display,
295 uint32_t w,
296 uint32_t h,
297 PixelFormat format,
298 uint32_t flags)
299{
Mathias Agopian17f638b2009-04-16 20:04:08 -0700300 sp<SurfaceControl> result;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800301 if (mStatus == NO_ERROR) {
Mathias Agopian770492c2010-05-28 14:22:23 -0700302 ISurfaceComposerClient::surface_data_t data;
Mathias Agopian9638e5c2011-04-20 14:19:32 -0700303 sp<ISurface> surface = mClient->createSurface(&data, name,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800304 display, w, h, format, flags);
305 if (surface != 0) {
Mathias Agopian1debc662010-06-08 15:40:56 -0700306 result = new SurfaceControl(this, surface, data, w, h, format, flags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800307 }
308 }
309 return result;
310}
311
312status_t SurfaceComposerClient::destroySurface(SurfaceID sid)
313{
314 if (mStatus != NO_ERROR)
315 return mStatus;
316
317 // it's okay to destroy a surface while a transaction is open,
318 // (transactions really are a client-side concept)
319 // however, this indicates probably a misuse of the API or a bug
320 // in the client code.
321 LOGW_IF(mTransactionOpen,
322 "Destroying surface while a transaction is open. "
323 "Client %p: destroying surface %d, mTransactionOpen=%d",
324 this, sid, mTransactionOpen);
325
326 status_t err = mClient->destroySurface(sid);
327 return err;
328}
329
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800330void SurfaceComposerClient::openGlobalTransaction()
331{
Mathias Agopianc7b388c2010-05-27 19:41:15 -0700332 Composer::openGlobalTransaction();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800333}
334
335void SurfaceComposerClient::closeGlobalTransaction()
336{
Mathias Agopianc7b388c2010-05-27 19:41:15 -0700337 Composer::closeGlobalTransaction();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800338}
339
340status_t SurfaceComposerClient::freezeDisplay(DisplayID dpy, uint32_t flags)
341{
Mathias Agopianbc726112009-09-23 15:44:05 -0700342 sp<ISurfaceComposer> sm(getComposerService());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800343 return sm->freezeDisplay(dpy, flags);
344}
345
346status_t SurfaceComposerClient::unfreezeDisplay(DisplayID dpy, uint32_t flags)
347{
Mathias Agopianbc726112009-09-23 15:44:05 -0700348 sp<ISurfaceComposer> sm(getComposerService());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800349 return sm->unfreezeDisplay(dpy, flags);
350}
351
Mathias Agopianeb0c86e2009-03-27 18:11:38 -0700352int SurfaceComposerClient::setOrientation(DisplayID dpy,
353 int orientation, uint32_t flags)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800354{
Mathias Agopianbc726112009-09-23 15:44:05 -0700355 sp<ISurfaceComposer> sm(getComposerService());
Mathias Agopianeb0c86e2009-03-27 18:11:38 -0700356 return sm->setOrientation(dpy, orientation, flags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800357}
358
359status_t SurfaceComposerClient::openTransaction()
360{
361 if (mStatus != NO_ERROR)
362 return mStatus;
363 Mutex::Autolock _l(mLock);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800364 mTransactionOpen++;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800365 return NO_ERROR;
366}
367
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800368status_t SurfaceComposerClient::closeTransaction()
369{
370 if (mStatus != NO_ERROR)
371 return mStatus;
372
373 Mutex::Autolock _l(mLock);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800374 if (mTransactionOpen <= 0) {
375 LOGE( "closeTransaction (client %p, mTransactionOpen=%d) "
376 "called more times than openTransaction()",
377 this, mTransactionOpen);
378 return INVALID_OPERATION;
379 }
380
381 if (mTransactionOpen >= 2) {
382 mTransactionOpen--;
383 return NO_ERROR;
384 }
385
386 mTransactionOpen = 0;
387 const ssize_t count = mStates.size();
388 if (count) {
389 mClient->setState(count, mStates.array());
390 mStates.clear();
391 }
392 return NO_ERROR;
393}
394
Mathias Agopian2ce19af2010-05-25 17:51:34 -0700395layer_state_t* SurfaceComposerClient::get_state_l(SurfaceID index)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800396{
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800397 // API usage error, do nothing.
398 if (mTransactionOpen<=0) {
399 LOGE("Not in transaction (client=%p, SurfaceID=%d, mTransactionOpen=%d",
400 this, int(index), mTransactionOpen);
401 return 0;
402 }
403
404 // use mPrebuiltLayerState just to find out if we already have it
Mathias Agopianc7b388c2010-05-27 19:41:15 -0700405 layer_state_t& dummy(*mPrebuiltLayerState);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800406 dummy.surface = index;
407 ssize_t i = mStates.indexOf(dummy);
408 if (i < 0) {
409 // we don't have it, add an initialized layer_state to our list
410 i = mStates.add(dummy);
411 }
412 return mStates.editArray() + i;
413}
414
Mathias Agopian2ce19af2010-05-25 17:51:34 -0700415layer_state_t* SurfaceComposerClient::lockLayerState(SurfaceID id)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800416{
417 layer_state_t* s;
418 mLock.lock();
Mathias Agopian2ce19af2010-05-25 17:51:34 -0700419 s = get_state_l(id);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800420 if (!s) mLock.unlock();
421 return s;
422}
423
Mathias Agopian2ce19af2010-05-25 17:51:34 -0700424void SurfaceComposerClient::unlockLayerState()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800425{
426 mLock.unlock();
427}
428
Mathias Agopian6d2c0bc2009-04-16 16:19:50 -0700429status_t SurfaceComposerClient::setPosition(SurfaceID id, int32_t x, int32_t y)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800430{
Mathias Agopian2ce19af2010-05-25 17:51:34 -0700431 layer_state_t* s = lockLayerState(id);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800432 if (!s) return BAD_INDEX;
433 s->what |= ISurfaceComposer::ePositionChanged;
434 s->x = x;
435 s->y = y;
Mathias Agopian2ce19af2010-05-25 17:51:34 -0700436 unlockLayerState();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800437 return NO_ERROR;
438}
439
Mathias Agopian6d2c0bc2009-04-16 16:19:50 -0700440status_t SurfaceComposerClient::setSize(SurfaceID id, uint32_t w, uint32_t h)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800441{
Mathias Agopian2ce19af2010-05-25 17:51:34 -0700442 layer_state_t* s = lockLayerState(id);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800443 if (!s) return BAD_INDEX;
444 s->what |= ISurfaceComposer::eSizeChanged;
445 s->w = w;
446 s->h = h;
Mathias Agopian2ce19af2010-05-25 17:51:34 -0700447 unlockLayerState();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800448 return NO_ERROR;
449}
450
Mathias Agopian6d2c0bc2009-04-16 16:19:50 -0700451status_t SurfaceComposerClient::setLayer(SurfaceID id, int32_t z)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800452{
Mathias Agopian2ce19af2010-05-25 17:51:34 -0700453 layer_state_t* s = lockLayerState(id);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800454 if (!s) return BAD_INDEX;
455 s->what |= ISurfaceComposer::eLayerChanged;
456 s->z = z;
Mathias Agopian2ce19af2010-05-25 17:51:34 -0700457 unlockLayerState();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800458 return NO_ERROR;
459}
460
Mathias Agopian6d2c0bc2009-04-16 16:19:50 -0700461status_t SurfaceComposerClient::hide(SurfaceID id)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800462{
Mathias Agopian6d2c0bc2009-04-16 16:19:50 -0700463 return setFlags(id, ISurfaceComposer::eLayerHidden,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800464 ISurfaceComposer::eLayerHidden);
465}
466
Mathias Agopian6d2c0bc2009-04-16 16:19:50 -0700467status_t SurfaceComposerClient::show(SurfaceID id, int32_t)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800468{
Mathias Agopian6d2c0bc2009-04-16 16:19:50 -0700469 return setFlags(id, 0, ISurfaceComposer::eLayerHidden);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800470}
471
Mathias Agopian6d2c0bc2009-04-16 16:19:50 -0700472status_t SurfaceComposerClient::freeze(SurfaceID id)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800473{
Mathias Agopian6d2c0bc2009-04-16 16:19:50 -0700474 return setFlags(id, ISurfaceComposer::eLayerFrozen,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800475 ISurfaceComposer::eLayerFrozen);
476}
477
Mathias Agopian6d2c0bc2009-04-16 16:19:50 -0700478status_t SurfaceComposerClient::unfreeze(SurfaceID id)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800479{
Mathias Agopian6d2c0bc2009-04-16 16:19:50 -0700480 return setFlags(id, 0, ISurfaceComposer::eLayerFrozen);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800481}
482
Mathias Agopian6d2c0bc2009-04-16 16:19:50 -0700483status_t SurfaceComposerClient::setFlags(SurfaceID id,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800484 uint32_t flags, uint32_t mask)
485{
Mathias Agopian2ce19af2010-05-25 17:51:34 -0700486 layer_state_t* s = lockLayerState(id);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800487 if (!s) return BAD_INDEX;
488 s->what |= ISurfaceComposer::eVisibilityChanged;
489 s->flags &= ~mask;
490 s->flags |= (flags & mask);
491 s->mask |= mask;
Mathias Agopian2ce19af2010-05-25 17:51:34 -0700492 unlockLayerState();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800493 return NO_ERROR;
494}
495
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800496status_t SurfaceComposerClient::setTransparentRegionHint(
Mathias Agopian6d2c0bc2009-04-16 16:19:50 -0700497 SurfaceID id, const Region& transparentRegion)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800498{
Mathias Agopian2ce19af2010-05-25 17:51:34 -0700499 layer_state_t* s = lockLayerState(id);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800500 if (!s) return BAD_INDEX;
501 s->what |= ISurfaceComposer::eTransparentRegionChanged;
502 s->transparentRegion = transparentRegion;
Mathias Agopian2ce19af2010-05-25 17:51:34 -0700503 unlockLayerState();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800504 return NO_ERROR;
505}
506
Mathias Agopian6d2c0bc2009-04-16 16:19:50 -0700507status_t SurfaceComposerClient::setAlpha(SurfaceID id, float alpha)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800508{
Mathias Agopian2ce19af2010-05-25 17:51:34 -0700509 layer_state_t* s = lockLayerState(id);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800510 if (!s) return BAD_INDEX;
511 s->what |= ISurfaceComposer::eAlphaChanged;
512 s->alpha = alpha;
Mathias Agopian2ce19af2010-05-25 17:51:34 -0700513 unlockLayerState();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800514 return NO_ERROR;
515}
516
517status_t SurfaceComposerClient::setMatrix(
Mathias Agopian6d2c0bc2009-04-16 16:19:50 -0700518 SurfaceID id,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800519 float dsdx, float dtdx,
520 float dsdy, float dtdy )
521{
Mathias Agopian2ce19af2010-05-25 17:51:34 -0700522 layer_state_t* s = lockLayerState(id);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800523 if (!s) return BAD_INDEX;
524 s->what |= ISurfaceComposer::eMatrixChanged;
525 layer_state_t::matrix22_t matrix;
526 matrix.dsdx = dsdx;
527 matrix.dtdx = dtdx;
528 matrix.dsdy = dsdy;
529 matrix.dtdy = dtdy;
530 s->matrix = matrix;
Mathias Agopian2ce19af2010-05-25 17:51:34 -0700531 unlockLayerState();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800532 return NO_ERROR;
533}
534
Mathias Agopian6d2c0bc2009-04-16 16:19:50 -0700535status_t SurfaceComposerClient::setFreezeTint(SurfaceID id, uint32_t tint)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800536{
Mathias Agopian2ce19af2010-05-25 17:51:34 -0700537 layer_state_t* s = lockLayerState(id);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800538 if (!s) return BAD_INDEX;
539 s->what |= ISurfaceComposer::eFreezeTintChanged;
540 s->tint = tint;
Mathias Agopian2ce19af2010-05-25 17:51:34 -0700541 unlockLayerState();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800542 return NO_ERROR;
543}
544
Mathias Agopianc7b388c2010-05-27 19:41:15 -0700545// ----------------------------------------------------------------------------
Mathias Agopian38ed2e32010-09-29 13:02:36 -0700546
547ScreenshotClient::ScreenshotClient()
548 : mWidth(0), mHeight(0), mFormat(PIXEL_FORMAT_NONE) {
549}
550
551status_t ScreenshotClient::update() {
552 sp<ISurfaceComposer> s(ComposerService::getComposerService());
553 if (s == NULL) return NO_INIT;
554 mHeap = 0;
555 return s->captureScreen(0, &mHeap,
Mathias Agopian3dd25a62010-12-10 16:22:31 -0800556 &mWidth, &mHeight, &mFormat, 0, 0,
557 0, -1UL);
Mathias Agopian38ed2e32010-09-29 13:02:36 -0700558}
559
560status_t ScreenshotClient::update(uint32_t reqWidth, uint32_t reqHeight) {
561 sp<ISurfaceComposer> s(ComposerService::getComposerService());
562 if (s == NULL) return NO_INIT;
563 mHeap = 0;
564 return s->captureScreen(0, &mHeap,
Mathias Agopian3dd25a62010-12-10 16:22:31 -0800565 &mWidth, &mHeight, &mFormat, reqWidth, reqHeight,
566 0, -1UL);
567}
568
569status_t ScreenshotClient::update(uint32_t reqWidth, uint32_t reqHeight,
570 uint32_t minLayerZ, uint32_t maxLayerZ) {
571 sp<ISurfaceComposer> s(ComposerService::getComposerService());
572 if (s == NULL) return NO_INIT;
573 mHeap = 0;
574 return s->captureScreen(0, &mHeap,
575 &mWidth, &mHeight, &mFormat, reqWidth, reqHeight,
576 minLayerZ, maxLayerZ);
Mathias Agopian38ed2e32010-09-29 13:02:36 -0700577}
578
579void ScreenshotClient::release() {
580 mHeap = 0;
581}
582
583void const* ScreenshotClient::getPixels() const {
584 return mHeap->getBase();
585}
586
587uint32_t ScreenshotClient::getWidth() const {
588 return mWidth;
589}
590
591uint32_t ScreenshotClient::getHeight() const {
592 return mHeight;
593}
594
595PixelFormat ScreenshotClient::getFormat() const {
596 return mFormat;
597}
598
599uint32_t ScreenshotClient::getStride() const {
600 return mWidth;
601}
602
603size_t ScreenshotClient::getSize() const {
604 return mHeap->getSize();
605}
606
607// ----------------------------------------------------------------------------
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800608}; // namespace android
609