blob: f2704616070996114107798bc4233a60539d0460 [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 int pid,
277 DisplayID display,
278 uint32_t w,
279 uint32_t h,
280 PixelFormat format,
281 uint32_t flags)
282{
Mathias Agopian5d26c1e2010-03-01 16:09:43 -0800283 String8 name;
284 const size_t SIZE = 128;
285 char buffer[SIZE];
286 snprintf(buffer, SIZE, "<pid_%d>", getpid());
287 name.append(buffer);
288
289 return SurfaceComposerClient::createSurface(pid, name, display,
290 w, h, format, flags);
Mathias Agopian5d26c1e2010-03-01 16:09:43 -0800291}
292
293sp<SurfaceControl> SurfaceComposerClient::createSurface(
294 int pid,
295 const String8& name,
296 DisplayID display,
297 uint32_t w,
298 uint32_t h,
299 PixelFormat format,
300 uint32_t flags)
301{
Mathias Agopian17f638b2009-04-16 20:04:08 -0700302 sp<SurfaceControl> result;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800303 if (mStatus == NO_ERROR) {
Mathias Agopian770492c2010-05-28 14:22:23 -0700304 ISurfaceComposerClient::surface_data_t data;
Mathias Agopian5d26c1e2010-03-01 16:09:43 -0800305 sp<ISurface> surface = mClient->createSurface(&data, pid, name,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800306 display, w, h, format, flags);
307 if (surface != 0) {
Mathias Agopian1debc662010-06-08 15:40:56 -0700308 result = new SurfaceControl(this, surface, data, w, h, format, flags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800309 }
310 }
311 return result;
312}
313
314status_t SurfaceComposerClient::destroySurface(SurfaceID sid)
315{
316 if (mStatus != NO_ERROR)
317 return mStatus;
318
319 // it's okay to destroy a surface while a transaction is open,
320 // (transactions really are a client-side concept)
321 // however, this indicates probably a misuse of the API or a bug
322 // in the client code.
323 LOGW_IF(mTransactionOpen,
324 "Destroying surface while a transaction is open. "
325 "Client %p: destroying surface %d, mTransactionOpen=%d",
326 this, sid, mTransactionOpen);
327
328 status_t err = mClient->destroySurface(sid);
329 return err;
330}
331
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800332void SurfaceComposerClient::openGlobalTransaction()
333{
Mathias Agopianc7b388c2010-05-27 19:41:15 -0700334 Composer::openGlobalTransaction();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800335}
336
337void SurfaceComposerClient::closeGlobalTransaction()
338{
Mathias Agopianc7b388c2010-05-27 19:41:15 -0700339 Composer::closeGlobalTransaction();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800340}
341
342status_t SurfaceComposerClient::freezeDisplay(DisplayID dpy, uint32_t flags)
343{
Mathias Agopianbc726112009-09-23 15:44:05 -0700344 sp<ISurfaceComposer> sm(getComposerService());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800345 return sm->freezeDisplay(dpy, flags);
346}
347
348status_t SurfaceComposerClient::unfreezeDisplay(DisplayID dpy, uint32_t flags)
349{
Mathias Agopianbc726112009-09-23 15:44:05 -0700350 sp<ISurfaceComposer> sm(getComposerService());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800351 return sm->unfreezeDisplay(dpy, flags);
352}
353
Mathias Agopianeb0c86e2009-03-27 18:11:38 -0700354int SurfaceComposerClient::setOrientation(DisplayID dpy,
355 int orientation, uint32_t flags)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800356{
Mathias Agopianbc726112009-09-23 15:44:05 -0700357 sp<ISurfaceComposer> sm(getComposerService());
Mathias Agopianeb0c86e2009-03-27 18:11:38 -0700358 return sm->setOrientation(dpy, orientation, flags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800359}
360
361status_t SurfaceComposerClient::openTransaction()
362{
363 if (mStatus != NO_ERROR)
364 return mStatus;
365 Mutex::Autolock _l(mLock);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800366 mTransactionOpen++;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800367 return NO_ERROR;
368}
369
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800370status_t SurfaceComposerClient::closeTransaction()
371{
372 if (mStatus != NO_ERROR)
373 return mStatus;
374
375 Mutex::Autolock _l(mLock);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800376 if (mTransactionOpen <= 0) {
377 LOGE( "closeTransaction (client %p, mTransactionOpen=%d) "
378 "called more times than openTransaction()",
379 this, mTransactionOpen);
380 return INVALID_OPERATION;
381 }
382
383 if (mTransactionOpen >= 2) {
384 mTransactionOpen--;
385 return NO_ERROR;
386 }
387
388 mTransactionOpen = 0;
389 const ssize_t count = mStates.size();
390 if (count) {
391 mClient->setState(count, mStates.array());
392 mStates.clear();
393 }
394 return NO_ERROR;
395}
396
Mathias Agopian2ce19af2010-05-25 17:51:34 -0700397layer_state_t* SurfaceComposerClient::get_state_l(SurfaceID index)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800398{
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800399 // API usage error, do nothing.
400 if (mTransactionOpen<=0) {
401 LOGE("Not in transaction (client=%p, SurfaceID=%d, mTransactionOpen=%d",
402 this, int(index), mTransactionOpen);
403 return 0;
404 }
405
406 // use mPrebuiltLayerState just to find out if we already have it
Mathias Agopianc7b388c2010-05-27 19:41:15 -0700407 layer_state_t& dummy(*mPrebuiltLayerState);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800408 dummy.surface = index;
409 ssize_t i = mStates.indexOf(dummy);
410 if (i < 0) {
411 // we don't have it, add an initialized layer_state to our list
412 i = mStates.add(dummy);
413 }
414 return mStates.editArray() + i;
415}
416
Mathias Agopian2ce19af2010-05-25 17:51:34 -0700417layer_state_t* SurfaceComposerClient::lockLayerState(SurfaceID id)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800418{
419 layer_state_t* s;
420 mLock.lock();
Mathias Agopian2ce19af2010-05-25 17:51:34 -0700421 s = get_state_l(id);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800422 if (!s) mLock.unlock();
423 return s;
424}
425
Mathias Agopian2ce19af2010-05-25 17:51:34 -0700426void SurfaceComposerClient::unlockLayerState()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800427{
428 mLock.unlock();
429}
430
Mathias Agopian6d2c0bc2009-04-16 16:19:50 -0700431status_t SurfaceComposerClient::setPosition(SurfaceID id, int32_t x, int32_t y)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800432{
Mathias Agopian2ce19af2010-05-25 17:51:34 -0700433 layer_state_t* s = lockLayerState(id);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800434 if (!s) return BAD_INDEX;
435 s->what |= ISurfaceComposer::ePositionChanged;
436 s->x = x;
437 s->y = y;
Mathias Agopian2ce19af2010-05-25 17:51:34 -0700438 unlockLayerState();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800439 return NO_ERROR;
440}
441
Mathias Agopian6d2c0bc2009-04-16 16:19:50 -0700442status_t SurfaceComposerClient::setSize(SurfaceID id, uint32_t w, uint32_t h)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800443{
Mathias Agopian2ce19af2010-05-25 17:51:34 -0700444 layer_state_t* s = lockLayerState(id);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800445 if (!s) return BAD_INDEX;
446 s->what |= ISurfaceComposer::eSizeChanged;
447 s->w = w;
448 s->h = h;
Mathias Agopian2ce19af2010-05-25 17:51:34 -0700449 unlockLayerState();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800450 return NO_ERROR;
451}
452
Mathias Agopian6d2c0bc2009-04-16 16:19:50 -0700453status_t SurfaceComposerClient::setLayer(SurfaceID id, int32_t z)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800454{
Mathias Agopian2ce19af2010-05-25 17:51:34 -0700455 layer_state_t* s = lockLayerState(id);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800456 if (!s) return BAD_INDEX;
457 s->what |= ISurfaceComposer::eLayerChanged;
458 s->z = z;
Mathias Agopian2ce19af2010-05-25 17:51:34 -0700459 unlockLayerState();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800460 return NO_ERROR;
461}
462
Mathias Agopian6d2c0bc2009-04-16 16:19:50 -0700463status_t SurfaceComposerClient::hide(SurfaceID id)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800464{
Mathias Agopian6d2c0bc2009-04-16 16:19:50 -0700465 return setFlags(id, ISurfaceComposer::eLayerHidden,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800466 ISurfaceComposer::eLayerHidden);
467}
468
Mathias Agopian6d2c0bc2009-04-16 16:19:50 -0700469status_t SurfaceComposerClient::show(SurfaceID id, int32_t)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800470{
Mathias Agopian6d2c0bc2009-04-16 16:19:50 -0700471 return setFlags(id, 0, ISurfaceComposer::eLayerHidden);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800472}
473
Mathias Agopian6d2c0bc2009-04-16 16:19:50 -0700474status_t SurfaceComposerClient::freeze(SurfaceID id)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800475{
Mathias Agopian6d2c0bc2009-04-16 16:19:50 -0700476 return setFlags(id, ISurfaceComposer::eLayerFrozen,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800477 ISurfaceComposer::eLayerFrozen);
478}
479
Mathias Agopian6d2c0bc2009-04-16 16:19:50 -0700480status_t SurfaceComposerClient::unfreeze(SurfaceID id)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800481{
Mathias Agopian6d2c0bc2009-04-16 16:19:50 -0700482 return setFlags(id, 0, ISurfaceComposer::eLayerFrozen);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800483}
484
Mathias Agopian6d2c0bc2009-04-16 16:19:50 -0700485status_t SurfaceComposerClient::setFlags(SurfaceID id,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800486 uint32_t flags, uint32_t mask)
487{
Mathias Agopian2ce19af2010-05-25 17:51:34 -0700488 layer_state_t* s = lockLayerState(id);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800489 if (!s) return BAD_INDEX;
490 s->what |= ISurfaceComposer::eVisibilityChanged;
491 s->flags &= ~mask;
492 s->flags |= (flags & mask);
493 s->mask |= mask;
Mathias Agopian2ce19af2010-05-25 17:51:34 -0700494 unlockLayerState();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800495 return NO_ERROR;
496}
497
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800498status_t SurfaceComposerClient::setTransparentRegionHint(
Mathias Agopian6d2c0bc2009-04-16 16:19:50 -0700499 SurfaceID id, const Region& transparentRegion)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800500{
Mathias Agopian2ce19af2010-05-25 17:51:34 -0700501 layer_state_t* s = lockLayerState(id);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800502 if (!s) return BAD_INDEX;
503 s->what |= ISurfaceComposer::eTransparentRegionChanged;
504 s->transparentRegion = transparentRegion;
Mathias Agopian2ce19af2010-05-25 17:51:34 -0700505 unlockLayerState();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800506 return NO_ERROR;
507}
508
Mathias Agopian6d2c0bc2009-04-16 16:19:50 -0700509status_t SurfaceComposerClient::setAlpha(SurfaceID id, float alpha)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800510{
Mathias Agopian2ce19af2010-05-25 17:51:34 -0700511 layer_state_t* s = lockLayerState(id);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800512 if (!s) return BAD_INDEX;
513 s->what |= ISurfaceComposer::eAlphaChanged;
514 s->alpha = alpha;
Mathias Agopian2ce19af2010-05-25 17:51:34 -0700515 unlockLayerState();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800516 return NO_ERROR;
517}
518
519status_t SurfaceComposerClient::setMatrix(
Mathias Agopian6d2c0bc2009-04-16 16:19:50 -0700520 SurfaceID id,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800521 float dsdx, float dtdx,
522 float dsdy, float dtdy )
523{
Mathias Agopian2ce19af2010-05-25 17:51:34 -0700524 layer_state_t* s = lockLayerState(id);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800525 if (!s) return BAD_INDEX;
526 s->what |= ISurfaceComposer::eMatrixChanged;
527 layer_state_t::matrix22_t matrix;
528 matrix.dsdx = dsdx;
529 matrix.dtdx = dtdx;
530 matrix.dsdy = dsdy;
531 matrix.dtdy = dtdy;
532 s->matrix = matrix;
Mathias Agopian2ce19af2010-05-25 17:51:34 -0700533 unlockLayerState();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800534 return NO_ERROR;
535}
536
Mathias Agopian6d2c0bc2009-04-16 16:19:50 -0700537status_t SurfaceComposerClient::setFreezeTint(SurfaceID id, uint32_t tint)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800538{
Mathias Agopian2ce19af2010-05-25 17:51:34 -0700539 layer_state_t* s = lockLayerState(id);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800540 if (!s) return BAD_INDEX;
541 s->what |= ISurfaceComposer::eFreezeTintChanged;
542 s->tint = tint;
Mathias Agopian2ce19af2010-05-25 17:51:34 -0700543 unlockLayerState();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800544 return NO_ERROR;
545}
546
Mathias Agopianc7b388c2010-05-27 19:41:15 -0700547// ----------------------------------------------------------------------------
Mathias Agopian38ed2e32010-09-29 13:02:36 -0700548
549ScreenshotClient::ScreenshotClient()
550 : mWidth(0), mHeight(0), mFormat(PIXEL_FORMAT_NONE) {
551}
552
553status_t ScreenshotClient::update() {
554 sp<ISurfaceComposer> s(ComposerService::getComposerService());
555 if (s == NULL) return NO_INIT;
556 mHeap = 0;
557 return s->captureScreen(0, &mHeap,
558 &mWidth, &mHeight, &mFormat, 0, 0);
559}
560
561status_t ScreenshotClient::update(uint32_t reqWidth, uint32_t reqHeight) {
562 sp<ISurfaceComposer> s(ComposerService::getComposerService());
563 if (s == NULL) return NO_INIT;
564 mHeap = 0;
565 return s->captureScreen(0, &mHeap,
566 &mWidth, &mHeight, &mFormat, reqWidth, reqHeight);
567}
568
569void ScreenshotClient::release() {
570 mHeap = 0;
571}
572
573void const* ScreenshotClient::getPixels() const {
574 return mHeap->getBase();
575}
576
577uint32_t ScreenshotClient::getWidth() const {
578 return mWidth;
579}
580
581uint32_t ScreenshotClient::getHeight() const {
582 return mHeight;
583}
584
585PixelFormat ScreenshotClient::getFormat() const {
586 return mFormat;
587}
588
589uint32_t ScreenshotClient::getStride() const {
590 return mWidth;
591}
592
593size_t ScreenshotClient::getSize() const {
594 return mHeap->getSize();
595}
596
597// ----------------------------------------------------------------------------
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800598}; // namespace android
599