blob: 3117495d3f41b3ba979c9038321d857845f7aff2 [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>
20#include <unistd.h>
21#include <fcntl.h>
22#include <errno.h>
23#include <sys/types.h>
24#include <sys/stat.h>
25
26#include <cutils/memory.h>
27
28#include <utils/Atomic.h>
29#include <utils/Errors.h>
30#include <utils/threads.h>
31#include <utils/KeyedVector.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080032#include <utils/Log.h>
33
Mathias Agopian000479f2010-02-09 17:46:37 -080034#include <binder/IServiceManager.h>
35#include <binder/IMemory.h>
36
Mathias Agopian1473f462009-04-10 14:24:30 -070037#include <ui/DisplayInfo.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080038#include <ui/Rect.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080039
Mathias Agopian000479f2010-02-09 17:46:37 -080040#include <surfaceflinger/ISurfaceComposer.h>
41#include <surfaceflinger/ISurfaceFlingerClient.h>
42#include <surfaceflinger/ISurface.h>
43#include <surfaceflinger/SurfaceComposerClient.h>
44
45#include <private/surfaceflinger/LayerState.h>
46#include <private/surfaceflinger/SharedBufferStack.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080047
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080048#define VERBOSE(...) ((void)0)
49//#define VERBOSE LOGD
50
51#define LIKELY( exp ) (__builtin_expect( (exp) != 0, true ))
52#define UNLIKELY( exp ) (__builtin_expect( (exp) != 0, false ))
53
54namespace android {
55
56// ---------------------------------------------------------------------------
57
58// Must not be holding SurfaceComposerClient::mLock when acquiring gLock here.
59static Mutex gLock;
60static sp<ISurfaceComposer> gSurfaceManager;
61static DefaultKeyedVector< sp<IBinder>, sp<SurfaceComposerClient> > gActiveConnections;
62static SortedVector<sp<SurfaceComposerClient> > gOpenTransactions;
Mathias Agopiand763b5d2009-07-02 18:11:53 -070063static sp<IMemoryHeap> gServerCblkMemory;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080064static volatile surface_flinger_cblk_t* gServerCblk;
65
Mathias Agopianbc726112009-09-23 15:44:05 -070066static sp<ISurfaceComposer> getComposerService()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080067{
Mathias Agopianbc726112009-09-23 15:44:05 -070068 sp<ISurfaceComposer> sc;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080069 Mutex::Autolock _l(gLock);
Mathias Agopianbc726112009-09-23 15:44:05 -070070 if (gSurfaceManager != 0) {
71 sc = gSurfaceManager;
72 } else {
73 // release the lock while we're waiting...
74 gLock.unlock();
75
76 sp<IBinder> binder;
77 sp<IServiceManager> sm = defaultServiceManager();
78 do {
79 binder = sm->getService(String16("SurfaceFlinger"));
80 if (binder == 0) {
81 LOGW("SurfaceFlinger not published, waiting...");
82 usleep(500000); // 0.5 s
83 }
84 } while(binder == 0);
85
86 // grab the lock again for updating gSurfaceManager
87 gLock.lock();
88 if (gSurfaceManager == 0) {
89 sc = interface_cast<ISurfaceComposer>(binder);
90 gSurfaceManager = sc;
91 } else {
92 sc = gSurfaceManager;
93 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080094 }
Mathias Agopianbc726112009-09-23 15:44:05 -070095 return sc;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080096}
97
98static volatile surface_flinger_cblk_t const * get_cblk()
99{
100 if (gServerCblk == 0) {
Mathias Agopianbc726112009-09-23 15:44:05 -0700101 sp<ISurfaceComposer> sm(getComposerService());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800102 Mutex::Autolock _l(gLock);
103 if (gServerCblk == 0) {
104 gServerCblkMemory = sm->getCblk();
105 LOGE_IF(gServerCblkMemory==0, "Can't get server control block");
Mathias Agopiand763b5d2009-07-02 18:11:53 -0700106 gServerCblk = (surface_flinger_cblk_t *)gServerCblkMemory->getBase();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800107 LOGE_IF(gServerCblk==0, "Can't get server control block address");
108 }
109 }
110 return gServerCblk;
111}
112
113// ---------------------------------------------------------------------------
114
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800115static inline int compare_type( const layer_state_t& lhs,
116 const layer_state_t& rhs) {
117 if (lhs.surface < rhs.surface) return -1;
118 if (lhs.surface > rhs.surface) return 1;
119 return 0;
120}
121
122SurfaceComposerClient::SurfaceComposerClient()
123{
Mathias Agopianbc726112009-09-23 15:44:05 -0700124 sp<ISurfaceComposer> sm(getComposerService());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800125 if (sm == 0) {
126 _init(0, 0);
127 return;
128 }
129
130 _init(sm, sm->createConnection());
131
132 if (mClient != 0) {
133 Mutex::Autolock _l(gLock);
134 VERBOSE("Adding client %p to map", this);
135 gActiveConnections.add(mClient->asBinder(), this);
136 }
137}
138
139SurfaceComposerClient::SurfaceComposerClient(
140 const sp<ISurfaceComposer>& sm, const sp<IBinder>& conn)
141{
142 _init(sm, interface_cast<ISurfaceFlingerClient>(conn));
143}
144
Mathias Agopianbc726112009-09-23 15:44:05 -0700145
146status_t SurfaceComposerClient::linkToComposerDeath(
147 const sp<IBinder::DeathRecipient>& recipient,
148 void* cookie, uint32_t flags)
149{
150 sp<ISurfaceComposer> sm(getComposerService());
151 return sm->asBinder()->linkToDeath(recipient, cookie, flags);
152}
153
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800154void SurfaceComposerClient::_init(
155 const sp<ISurfaceComposer>& sm, const sp<ISurfaceFlingerClient>& conn)
156{
157 VERBOSE("Creating client %p, conn %p", this, conn.get());
158
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800159 mPrebuiltLayerState = 0;
160 mTransactionOpen = 0;
161 mStatus = NO_ERROR;
162 mControl = 0;
163
164 mClient = conn;
165 if (mClient == 0) {
166 mStatus = NO_INIT;
167 return;
168 }
169
Mathias Agopiand763b5d2009-07-02 18:11:53 -0700170 mControlMemory = mClient->getControlBlock();
Mathias Agopiane05f07d2009-10-07 16:44:10 -0700171 mSignalServer = sm;
Mathias Agopian9779b2212009-09-07 16:32:45 -0700172 mControl = static_cast<SharedClient *>(mControlMemory->getBase());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800173}
174
175SurfaceComposerClient::~SurfaceComposerClient()
176{
177 VERBOSE("Destroying client %p, conn %p", this, mClient.get());
178 dispose();
179}
180
181status_t SurfaceComposerClient::initCheck() const
182{
183 return mStatus;
184}
185
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800186sp<IBinder> SurfaceComposerClient::connection() const
187{
188 return (mClient != 0) ? mClient->asBinder() : 0;
189}
190
191sp<SurfaceComposerClient>
192SurfaceComposerClient::clientForConnection(const sp<IBinder>& conn)
193{
194 sp<SurfaceComposerClient> client;
195
196 { // scope for lock
197 Mutex::Autolock _l(gLock);
198 client = gActiveConnections.valueFor(conn);
199 }
200
201 if (client == 0) {
202 // Need to make a new client.
Mathias Agopianbc726112009-09-23 15:44:05 -0700203 sp<ISurfaceComposer> sm(getComposerService());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800204 client = new SurfaceComposerClient(sm, conn);
205 if (client != 0 && client->initCheck() == NO_ERROR) {
206 Mutex::Autolock _l(gLock);
207 gActiveConnections.add(conn, client);
208 //LOGD("we have %d connections", gActiveConnections.size());
209 } else {
210 client.clear();
211 }
212 }
213
214 return client;
215}
216
217void SurfaceComposerClient::dispose()
218{
219 // this can be called more than once.
220
Mathias Agopiand763b5d2009-07-02 18:11:53 -0700221 sp<IMemoryHeap> controlMemory;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800222 sp<ISurfaceFlingerClient> client;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800223
224 {
225 Mutex::Autolock _lg(gLock);
226 Mutex::Autolock _lm(mLock);
227
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800228 mSignalServer = 0;
229
230 if (mClient != 0) {
231 client = mClient;
232 mClient.clear();
233
234 ssize_t i = gActiveConnections.indexOfKey(client->asBinder());
235 if (i >= 0 && gActiveConnections.valueAt(i) == this) {
236 VERBOSE("Removing client %p from map at %d", this, int(i));
237 gActiveConnections.removeItemsAt(i);
238 }
239 }
240
241 delete mPrebuiltLayerState;
242 mPrebuiltLayerState = 0;
243 controlMemory = mControlMemory;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800244 mControlMemory.clear();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800245 mControl = 0;
246 mStatus = NO_INIT;
247 }
248}
249
250status_t SurfaceComposerClient::getDisplayInfo(
251 DisplayID dpy, DisplayInfo* info)
252{
253 if (uint32_t(dpy)>=NUM_DISPLAY_MAX)
254 return BAD_VALUE;
255
256 volatile surface_flinger_cblk_t const * cblk = get_cblk();
257 volatile display_cblk_t const * dcblk = cblk->displays + dpy;
258
259 info->w = dcblk->w;
260 info->h = dcblk->h;
261 info->orientation = dcblk->orientation;
262 info->xdpi = dcblk->xdpi;
263 info->ydpi = dcblk->ydpi;
264 info->fps = dcblk->fps;
265 info->density = dcblk->density;
266 return getPixelFormatInfo(dcblk->format, &(info->pixelFormatInfo));
267}
268
269ssize_t SurfaceComposerClient::getDisplayWidth(DisplayID dpy)
270{
271 if (uint32_t(dpy)>=NUM_DISPLAY_MAX)
272 return BAD_VALUE;
273 volatile surface_flinger_cblk_t const * cblk = get_cblk();
274 volatile display_cblk_t const * dcblk = cblk->displays + dpy;
275 return dcblk->w;
276}
277
278ssize_t SurfaceComposerClient::getDisplayHeight(DisplayID dpy)
279{
280 if (uint32_t(dpy)>=NUM_DISPLAY_MAX)
281 return BAD_VALUE;
282 volatile surface_flinger_cblk_t const * cblk = get_cblk();
283 volatile display_cblk_t const * dcblk = cblk->displays + dpy;
284 return dcblk->h;
285}
286
287ssize_t SurfaceComposerClient::getDisplayOrientation(DisplayID dpy)
288{
289 if (uint32_t(dpy)>=NUM_DISPLAY_MAX)
290 return BAD_VALUE;
291 volatile surface_flinger_cblk_t const * cblk = get_cblk();
292 volatile display_cblk_t const * dcblk = cblk->displays + dpy;
293 return dcblk->orientation;
294}
295
296ssize_t SurfaceComposerClient::getNumberOfDisplays()
297{
298 volatile surface_flinger_cblk_t const * cblk = get_cblk();
299 uint32_t connected = cblk->connected;
300 int n = 0;
301 while (connected) {
302 if (connected&1) n++;
303 connected >>= 1;
304 }
305 return n;
306}
307
Mathias Agopian1473f462009-04-10 14:24:30 -0700308
309void SurfaceComposerClient::signalServer()
310{
311 mSignalServer->signal();
312}
313
Mathias Agopian17f638b2009-04-16 20:04:08 -0700314sp<SurfaceControl> SurfaceComposerClient::createSurface(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800315 int pid,
316 DisplayID display,
317 uint32_t w,
318 uint32_t h,
319 PixelFormat format,
320 uint32_t flags)
321{
Mathias Agopian5d26c1e2010-03-01 16:09:43 -0800322 String8 name;
323 const size_t SIZE = 128;
324 char buffer[SIZE];
325 snprintf(buffer, SIZE, "<pid_%d>", getpid());
326 name.append(buffer);
327
328 return SurfaceComposerClient::createSurface(pid, name, display,
329 w, h, format, flags);
330
331}
332
333sp<SurfaceControl> SurfaceComposerClient::createSurface(
334 int pid,
335 const String8& name,
336 DisplayID display,
337 uint32_t w,
338 uint32_t h,
339 PixelFormat format,
340 uint32_t flags)
341{
Mathias Agopian17f638b2009-04-16 20:04:08 -0700342 sp<SurfaceControl> result;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800343 if (mStatus == NO_ERROR) {
344 ISurfaceFlingerClient::surface_data_t data;
Mathias Agopian5d26c1e2010-03-01 16:09:43 -0800345 sp<ISurface> surface = mClient->createSurface(&data, pid, name,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800346 display, w, h, format, flags);
347 if (surface != 0) {
348 if (uint32_t(data.token) < NUM_LAYERS_MAX) {
Mathias Agopian17f638b2009-04-16 20:04:08 -0700349 result = new SurfaceControl(this, surface, data, w, h, format, flags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800350 }
351 }
352 }
353 return result;
354}
355
356status_t SurfaceComposerClient::destroySurface(SurfaceID sid)
357{
358 if (mStatus != NO_ERROR)
359 return mStatus;
360
361 // it's okay to destroy a surface while a transaction is open,
362 // (transactions really are a client-side concept)
363 // however, this indicates probably a misuse of the API or a bug
364 // in the client code.
365 LOGW_IF(mTransactionOpen,
366 "Destroying surface while a transaction is open. "
367 "Client %p: destroying surface %d, mTransactionOpen=%d",
368 this, sid, mTransactionOpen);
369
370 status_t err = mClient->destroySurface(sid);
371 return err;
372}
373
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800374void SurfaceComposerClient::openGlobalTransaction()
375{
376 Mutex::Autolock _l(gLock);
377
378 if (gOpenTransactions.size()) {
379 LOGE("openGlobalTransaction() called more than once. skipping.");
380 return;
381 }
382
383 const size_t N = gActiveConnections.size();
384 VERBOSE("openGlobalTransaction (%ld clients)", N);
385 for (size_t i=0; i<N; i++) {
386 sp<SurfaceComposerClient> client(gActiveConnections.valueAt(i));
387 if (gOpenTransactions.indexOf(client) < 0) {
388 if (client->openTransaction() == NO_ERROR) {
389 if (gOpenTransactions.add(client) < 0) {
390 // Ooops!
391 LOGE( "Unable to add a SurfaceComposerClient "
392 "to the global transaction set (out of memory?)");
393 client->closeTransaction();
394 // let it go, it'll fail later when the user
395 // tries to do something with the transaction
396 }
397 } else {
398 LOGE("openTransaction on client %p failed", client.get());
399 // let it go, it'll fail later when the user
400 // tries to do something with the transaction
401 }
402 }
403 }
404}
405
406void SurfaceComposerClient::closeGlobalTransaction()
407{
408 gLock.lock();
409 SortedVector< sp<SurfaceComposerClient> > clients(gOpenTransactions);
410 gOpenTransactions.clear();
411 gLock.unlock();
412
413 const size_t N = clients.size();
414 VERBOSE("closeGlobalTransaction (%ld clients)", N);
Mathias Agopian9779b2212009-09-07 16:32:45 -0700415
Mathias Agopianbc726112009-09-23 15:44:05 -0700416 sp<ISurfaceComposer> sm(getComposerService());
Mathias Agopian9779b2212009-09-07 16:32:45 -0700417 sm->openGlobalTransaction();
418 for (size_t i=0; i<N; i++) {
419 clients[i]->closeTransaction();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800420 }
Mathias Agopian9779b2212009-09-07 16:32:45 -0700421 sm->closeGlobalTransaction();
422
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800423}
424
Mathias Agopian9779b2212009-09-07 16:32:45 -0700425
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800426status_t SurfaceComposerClient::freezeDisplay(DisplayID dpy, uint32_t flags)
427{
Mathias Agopianbc726112009-09-23 15:44:05 -0700428 sp<ISurfaceComposer> sm(getComposerService());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800429 return sm->freezeDisplay(dpy, flags);
430}
431
432status_t SurfaceComposerClient::unfreezeDisplay(DisplayID dpy, uint32_t flags)
433{
Mathias Agopianbc726112009-09-23 15:44:05 -0700434 sp<ISurfaceComposer> sm(getComposerService());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800435 return sm->unfreezeDisplay(dpy, flags);
436}
437
Mathias Agopianeb0c86e2009-03-27 18:11:38 -0700438int SurfaceComposerClient::setOrientation(DisplayID dpy,
439 int orientation, uint32_t flags)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800440{
Mathias Agopianbc726112009-09-23 15:44:05 -0700441 sp<ISurfaceComposer> sm(getComposerService());
Mathias Agopianeb0c86e2009-03-27 18:11:38 -0700442 return sm->setOrientation(dpy, orientation, flags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800443}
444
445status_t SurfaceComposerClient::openTransaction()
446{
447 if (mStatus != NO_ERROR)
448 return mStatus;
449 Mutex::Autolock _l(mLock);
450 VERBOSE( "openTransaction (client %p, mTransactionOpen=%d)",
451 this, mTransactionOpen);
452 mTransactionOpen++;
453 if (mPrebuiltLayerState == 0) {
454 mPrebuiltLayerState = new layer_state_t;
455 }
456 return NO_ERROR;
457}
458
459
460status_t SurfaceComposerClient::closeTransaction()
461{
462 if (mStatus != NO_ERROR)
463 return mStatus;
464
465 Mutex::Autolock _l(mLock);
466
467 VERBOSE( "closeTransaction (client %p, mTransactionOpen=%d)",
468 this, mTransactionOpen);
469
470 if (mTransactionOpen <= 0) {
471 LOGE( "closeTransaction (client %p, mTransactionOpen=%d) "
472 "called more times than openTransaction()",
473 this, mTransactionOpen);
474 return INVALID_OPERATION;
475 }
476
477 if (mTransactionOpen >= 2) {
478 mTransactionOpen--;
479 return NO_ERROR;
480 }
481
482 mTransactionOpen = 0;
483 const ssize_t count = mStates.size();
484 if (count) {
485 mClient->setState(count, mStates.array());
486 mStates.clear();
487 }
488 return NO_ERROR;
489}
490
Mathias Agopian6d2c0bc2009-04-16 16:19:50 -0700491layer_state_t* SurfaceComposerClient::_get_state_l(SurfaceID index)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800492{
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800493 // API usage error, do nothing.
494 if (mTransactionOpen<=0) {
495 LOGE("Not in transaction (client=%p, SurfaceID=%d, mTransactionOpen=%d",
496 this, int(index), mTransactionOpen);
497 return 0;
498 }
499
500 // use mPrebuiltLayerState just to find out if we already have it
501 layer_state_t& dummy = *mPrebuiltLayerState;
502 dummy.surface = index;
503 ssize_t i = mStates.indexOf(dummy);
504 if (i < 0) {
505 // we don't have it, add an initialized layer_state to our list
506 i = mStates.add(dummy);
507 }
508 return mStates.editArray() + i;
509}
510
Mathias Agopian6d2c0bc2009-04-16 16:19:50 -0700511layer_state_t* SurfaceComposerClient::_lockLayerState(SurfaceID id)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800512{
513 layer_state_t* s;
514 mLock.lock();
Mathias Agopian6d2c0bc2009-04-16 16:19:50 -0700515 s = _get_state_l(id);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800516 if (!s) mLock.unlock();
517 return s;
518}
519
520void SurfaceComposerClient::_unlockLayerState()
521{
522 mLock.unlock();
523}
524
Mathias Agopian6d2c0bc2009-04-16 16:19:50 -0700525status_t SurfaceComposerClient::setPosition(SurfaceID id, int32_t x, int32_t y)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800526{
Mathias Agopian6d2c0bc2009-04-16 16:19:50 -0700527 layer_state_t* s = _lockLayerState(id);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800528 if (!s) return BAD_INDEX;
529 s->what |= ISurfaceComposer::ePositionChanged;
530 s->x = x;
531 s->y = y;
532 _unlockLayerState();
533 return NO_ERROR;
534}
535
Mathias Agopian6d2c0bc2009-04-16 16:19:50 -0700536status_t SurfaceComposerClient::setSize(SurfaceID id, uint32_t w, uint32_t h)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800537{
Mathias Agopian6d2c0bc2009-04-16 16:19:50 -0700538 layer_state_t* s = _lockLayerState(id);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800539 if (!s) return BAD_INDEX;
540 s->what |= ISurfaceComposer::eSizeChanged;
541 s->w = w;
542 s->h = h;
543 _unlockLayerState();
544 return NO_ERROR;
545}
546
Mathias Agopian6d2c0bc2009-04-16 16:19:50 -0700547status_t SurfaceComposerClient::setLayer(SurfaceID id, int32_t z)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800548{
Mathias Agopian6d2c0bc2009-04-16 16:19:50 -0700549 layer_state_t* s = _lockLayerState(id);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800550 if (!s) return BAD_INDEX;
551 s->what |= ISurfaceComposer::eLayerChanged;
552 s->z = z;
553 _unlockLayerState();
554 return NO_ERROR;
555}
556
Mathias Agopian6d2c0bc2009-04-16 16:19:50 -0700557status_t SurfaceComposerClient::hide(SurfaceID id)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800558{
Mathias Agopian6d2c0bc2009-04-16 16:19:50 -0700559 return setFlags(id, ISurfaceComposer::eLayerHidden,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800560 ISurfaceComposer::eLayerHidden);
561}
562
Mathias Agopian6d2c0bc2009-04-16 16:19:50 -0700563status_t SurfaceComposerClient::show(SurfaceID id, int32_t)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800564{
Mathias Agopian6d2c0bc2009-04-16 16:19:50 -0700565 return setFlags(id, 0, ISurfaceComposer::eLayerHidden);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800566}
567
Mathias Agopian6d2c0bc2009-04-16 16:19:50 -0700568status_t SurfaceComposerClient::freeze(SurfaceID id)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800569{
Mathias Agopian6d2c0bc2009-04-16 16:19:50 -0700570 return setFlags(id, ISurfaceComposer::eLayerFrozen,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800571 ISurfaceComposer::eLayerFrozen);
572}
573
Mathias Agopian6d2c0bc2009-04-16 16:19:50 -0700574status_t SurfaceComposerClient::unfreeze(SurfaceID id)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800575{
Mathias Agopian6d2c0bc2009-04-16 16:19:50 -0700576 return setFlags(id, 0, ISurfaceComposer::eLayerFrozen);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800577}
578
Mathias Agopian6d2c0bc2009-04-16 16:19:50 -0700579status_t SurfaceComposerClient::setFlags(SurfaceID id,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800580 uint32_t flags, uint32_t mask)
581{
Mathias Agopian6d2c0bc2009-04-16 16:19:50 -0700582 layer_state_t* s = _lockLayerState(id);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800583 if (!s) return BAD_INDEX;
584 s->what |= ISurfaceComposer::eVisibilityChanged;
585 s->flags &= ~mask;
586 s->flags |= (flags & mask);
587 s->mask |= mask;
588 _unlockLayerState();
589 return NO_ERROR;
590}
591
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800592status_t SurfaceComposerClient::setTransparentRegionHint(
Mathias Agopian6d2c0bc2009-04-16 16:19:50 -0700593 SurfaceID id, const Region& transparentRegion)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800594{
Mathias Agopian6d2c0bc2009-04-16 16:19:50 -0700595 layer_state_t* s = _lockLayerState(id);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800596 if (!s) return BAD_INDEX;
597 s->what |= ISurfaceComposer::eTransparentRegionChanged;
598 s->transparentRegion = transparentRegion;
599 _unlockLayerState();
600 return NO_ERROR;
601}
602
Mathias Agopian6d2c0bc2009-04-16 16:19:50 -0700603status_t SurfaceComposerClient::setAlpha(SurfaceID id, float alpha)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800604{
Mathias Agopian6d2c0bc2009-04-16 16:19:50 -0700605 layer_state_t* s = _lockLayerState(id);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800606 if (!s) return BAD_INDEX;
607 s->what |= ISurfaceComposer::eAlphaChanged;
608 s->alpha = alpha;
609 _unlockLayerState();
610 return NO_ERROR;
611}
612
613status_t SurfaceComposerClient::setMatrix(
Mathias Agopian6d2c0bc2009-04-16 16:19:50 -0700614 SurfaceID id,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800615 float dsdx, float dtdx,
616 float dsdy, float dtdy )
617{
Mathias Agopian6d2c0bc2009-04-16 16:19:50 -0700618 layer_state_t* s = _lockLayerState(id);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800619 if (!s) return BAD_INDEX;
620 s->what |= ISurfaceComposer::eMatrixChanged;
621 layer_state_t::matrix22_t matrix;
622 matrix.dsdx = dsdx;
623 matrix.dtdx = dtdx;
624 matrix.dsdy = dsdy;
625 matrix.dtdy = dtdy;
626 s->matrix = matrix;
627 _unlockLayerState();
628 return NO_ERROR;
629}
630
Mathias Agopian6d2c0bc2009-04-16 16:19:50 -0700631status_t SurfaceComposerClient::setFreezeTint(SurfaceID id, uint32_t tint)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800632{
Mathias Agopian6d2c0bc2009-04-16 16:19:50 -0700633 layer_state_t* s = _lockLayerState(id);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800634 if (!s) return BAD_INDEX;
635 s->what |= ISurfaceComposer::eFreezeTintChanged;
636 s->tint = tint;
637 _unlockLayerState();
638 return NO_ERROR;
639}
640
641}; // namespace android
642