blob: 0b5e504e5ae4200840eb6e6f8f90b64710fbda89 [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>
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 Projectedbf3b62009-03-03 19:31:44 -080032#include <utils/Log.h>
33
Mathias Agopian9cce3252010-02-09 17:46:37 -080034#include <binder/IServiceManager.h>
35#include <binder/IMemory.h>
36
Mathias Agopian076b1cc2009-04-10 14:24:30 -070037#include <ui/DisplayInfo.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080038#include <ui/Rect.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080039
Mathias Agopian9cce3252010-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 Projectedbf3b62009-03-03 19:31:44 -080047
The Android Open Source Projectedbf3b62009-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 Agopian7303c6b2009-07-02 18:11:53 -070063static sp<IMemoryHeap> gServerCblkMemory;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080064static volatile surface_flinger_cblk_t* gServerCblk;
65
Mathias Agopiandd3423c2009-09-23 15:44:05 -070066static sp<ISurfaceComposer> getComposerService()
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080067{
Mathias Agopiandd3423c2009-09-23 15:44:05 -070068 sp<ISurfaceComposer> sc;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080069 Mutex::Autolock _l(gLock);
Mathias Agopiandd3423c2009-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 Projectedbf3b62009-03-03 19:31:44 -080094 }
Mathias Agopiandd3423c2009-09-23 15:44:05 -070095 return sc;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080096}
97
98static volatile surface_flinger_cblk_t const * get_cblk()
99{
100 if (gServerCblk == 0) {
Mathias Agopiandd3423c2009-09-23 15:44:05 -0700101 sp<ISurfaceComposer> sm(getComposerService());
The Android Open Source Projectedbf3b62009-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 Agopian7303c6b2009-07-02 18:11:53 -0700106 gServerCblk = (surface_flinger_cblk_t *)gServerCblkMemory->getBase();
The Android Open Source Projectedbf3b62009-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 Projectedbf3b62009-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 Agopiandd3423c2009-09-23 15:44:05 -0700124 sp<ISurfaceComposer> sm(getComposerService());
The Android Open Source Projectedbf3b62009-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 Agopiandd3423c2009-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 Projectedbf3b62009-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 Projectedbf3b62009-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 Agopian7303c6b2009-07-02 18:11:53 -0700170 mControlMemory = mClient->getControlBlock();
Mathias Agopiane7005012009-10-07 16:44:10 -0700171 mSignalServer = sm;
Mathias Agopiancbb288b2009-09-07 16:32:45 -0700172 mControl = static_cast<SharedClient *>(mControlMemory->getBase());
The Android Open Source Projectedbf3b62009-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 Projectedbf3b62009-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 Agopiandd3423c2009-09-23 15:44:05 -0700203 sp<ISurfaceComposer> sm(getComposerService());
The Android Open Source Projectedbf3b62009-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 Agopian7303c6b2009-07-02 18:11:53 -0700221 sp<IMemoryHeap> controlMemory;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800222 sp<ISurfaceFlingerClient> client;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800223
224 {
225 Mutex::Autolock _lg(gLock);
226 Mutex::Autolock _lm(mLock);
227
The Android Open Source Projectedbf3b62009-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 Projectedbf3b62009-03-03 19:31:44 -0800244 mControlMemory.clear();
The Android Open Source Projectedbf3b62009-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 Agopian076b1cc2009-04-10 14:24:30 -0700308
309void SurfaceComposerClient::signalServer()
310{
311 mSignalServer->signal();
312}
313
Mathias Agopian01b76682009-04-16 20:04:08 -0700314sp<SurfaceControl> SurfaceComposerClient::createSurface(
The Android Open Source Projectedbf3b62009-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 Agopian01b76682009-04-16 20:04:08 -0700322 sp<SurfaceControl> result;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800323 if (mStatus == NO_ERROR) {
324 ISurfaceFlingerClient::surface_data_t data;
325 sp<ISurface> surface = mClient->createSurface(&data, pid,
326 display, w, h, format, flags);
327 if (surface != 0) {
328 if (uint32_t(data.token) < NUM_LAYERS_MAX) {
Mathias Agopian01b76682009-04-16 20:04:08 -0700329 result = new SurfaceControl(this, surface, data, w, h, format, flags);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800330 }
331 }
332 }
333 return result;
334}
335
336status_t SurfaceComposerClient::destroySurface(SurfaceID sid)
337{
338 if (mStatus != NO_ERROR)
339 return mStatus;
340
341 // it's okay to destroy a surface while a transaction is open,
342 // (transactions really are a client-side concept)
343 // however, this indicates probably a misuse of the API or a bug
344 // in the client code.
345 LOGW_IF(mTransactionOpen,
346 "Destroying surface while a transaction is open. "
347 "Client %p: destroying surface %d, mTransactionOpen=%d",
348 this, sid, mTransactionOpen);
349
350 status_t err = mClient->destroySurface(sid);
351 return err;
352}
353
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800354void SurfaceComposerClient::openGlobalTransaction()
355{
356 Mutex::Autolock _l(gLock);
357
358 if (gOpenTransactions.size()) {
359 LOGE("openGlobalTransaction() called more than once. skipping.");
360 return;
361 }
362
363 const size_t N = gActiveConnections.size();
364 VERBOSE("openGlobalTransaction (%ld clients)", N);
365 for (size_t i=0; i<N; i++) {
366 sp<SurfaceComposerClient> client(gActiveConnections.valueAt(i));
367 if (gOpenTransactions.indexOf(client) < 0) {
368 if (client->openTransaction() == NO_ERROR) {
369 if (gOpenTransactions.add(client) < 0) {
370 // Ooops!
371 LOGE( "Unable to add a SurfaceComposerClient "
372 "to the global transaction set (out of memory?)");
373 client->closeTransaction();
374 // let it go, it'll fail later when the user
375 // tries to do something with the transaction
376 }
377 } else {
378 LOGE("openTransaction on client %p failed", client.get());
379 // let it go, it'll fail later when the user
380 // tries to do something with the transaction
381 }
382 }
383 }
384}
385
386void SurfaceComposerClient::closeGlobalTransaction()
387{
388 gLock.lock();
389 SortedVector< sp<SurfaceComposerClient> > clients(gOpenTransactions);
390 gOpenTransactions.clear();
391 gLock.unlock();
392
393 const size_t N = clients.size();
394 VERBOSE("closeGlobalTransaction (%ld clients)", N);
Mathias Agopiancbb288b2009-09-07 16:32:45 -0700395
Mathias Agopiandd3423c2009-09-23 15:44:05 -0700396 sp<ISurfaceComposer> sm(getComposerService());
Mathias Agopiancbb288b2009-09-07 16:32:45 -0700397 sm->openGlobalTransaction();
398 for (size_t i=0; i<N; i++) {
399 clients[i]->closeTransaction();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800400 }
Mathias Agopiancbb288b2009-09-07 16:32:45 -0700401 sm->closeGlobalTransaction();
402
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800403}
404
Mathias Agopiancbb288b2009-09-07 16:32:45 -0700405
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800406status_t SurfaceComposerClient::freezeDisplay(DisplayID dpy, uint32_t flags)
407{
Mathias Agopiandd3423c2009-09-23 15:44:05 -0700408 sp<ISurfaceComposer> sm(getComposerService());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800409 return sm->freezeDisplay(dpy, flags);
410}
411
412status_t SurfaceComposerClient::unfreezeDisplay(DisplayID dpy, uint32_t flags)
413{
Mathias Agopiandd3423c2009-09-23 15:44:05 -0700414 sp<ISurfaceComposer> sm(getComposerService());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800415 return sm->unfreezeDisplay(dpy, flags);
416}
417
Mathias Agopianc08731e2009-03-27 18:11:38 -0700418int SurfaceComposerClient::setOrientation(DisplayID dpy,
419 int orientation, uint32_t flags)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800420{
Mathias Agopiandd3423c2009-09-23 15:44:05 -0700421 sp<ISurfaceComposer> sm(getComposerService());
Mathias Agopianc08731e2009-03-27 18:11:38 -0700422 return sm->setOrientation(dpy, orientation, flags);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800423}
424
425status_t SurfaceComposerClient::openTransaction()
426{
427 if (mStatus != NO_ERROR)
428 return mStatus;
429 Mutex::Autolock _l(mLock);
430 VERBOSE( "openTransaction (client %p, mTransactionOpen=%d)",
431 this, mTransactionOpen);
432 mTransactionOpen++;
433 if (mPrebuiltLayerState == 0) {
434 mPrebuiltLayerState = new layer_state_t;
435 }
436 return NO_ERROR;
437}
438
439
440status_t SurfaceComposerClient::closeTransaction()
441{
442 if (mStatus != NO_ERROR)
443 return mStatus;
444
445 Mutex::Autolock _l(mLock);
446
447 VERBOSE( "closeTransaction (client %p, mTransactionOpen=%d)",
448 this, mTransactionOpen);
449
450 if (mTransactionOpen <= 0) {
451 LOGE( "closeTransaction (client %p, mTransactionOpen=%d) "
452 "called more times than openTransaction()",
453 this, mTransactionOpen);
454 return INVALID_OPERATION;
455 }
456
457 if (mTransactionOpen >= 2) {
458 mTransactionOpen--;
459 return NO_ERROR;
460 }
461
462 mTransactionOpen = 0;
463 const ssize_t count = mStates.size();
464 if (count) {
465 mClient->setState(count, mStates.array());
466 mStates.clear();
467 }
468 return NO_ERROR;
469}
470
Mathias Agopian62185b72009-04-16 16:19:50 -0700471layer_state_t* SurfaceComposerClient::_get_state_l(SurfaceID index)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800472{
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800473 // API usage error, do nothing.
474 if (mTransactionOpen<=0) {
475 LOGE("Not in transaction (client=%p, SurfaceID=%d, mTransactionOpen=%d",
476 this, int(index), mTransactionOpen);
477 return 0;
478 }
479
480 // use mPrebuiltLayerState just to find out if we already have it
481 layer_state_t& dummy = *mPrebuiltLayerState;
482 dummy.surface = index;
483 ssize_t i = mStates.indexOf(dummy);
484 if (i < 0) {
485 // we don't have it, add an initialized layer_state to our list
486 i = mStates.add(dummy);
487 }
488 return mStates.editArray() + i;
489}
490
Mathias Agopian62185b72009-04-16 16:19:50 -0700491layer_state_t* SurfaceComposerClient::_lockLayerState(SurfaceID id)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800492{
493 layer_state_t* s;
494 mLock.lock();
Mathias Agopian62185b72009-04-16 16:19:50 -0700495 s = _get_state_l(id);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800496 if (!s) mLock.unlock();
497 return s;
498}
499
500void SurfaceComposerClient::_unlockLayerState()
501{
502 mLock.unlock();
503}
504
Mathias Agopian62185b72009-04-16 16:19:50 -0700505status_t SurfaceComposerClient::setPosition(SurfaceID id, int32_t x, int32_t y)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800506{
Mathias Agopian62185b72009-04-16 16:19:50 -0700507 layer_state_t* s = _lockLayerState(id);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800508 if (!s) return BAD_INDEX;
509 s->what |= ISurfaceComposer::ePositionChanged;
510 s->x = x;
511 s->y = y;
512 _unlockLayerState();
513 return NO_ERROR;
514}
515
Mathias Agopian62185b72009-04-16 16:19:50 -0700516status_t SurfaceComposerClient::setSize(SurfaceID id, uint32_t w, uint32_t h)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800517{
Mathias Agopian62185b72009-04-16 16:19:50 -0700518 layer_state_t* s = _lockLayerState(id);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800519 if (!s) return BAD_INDEX;
520 s->what |= ISurfaceComposer::eSizeChanged;
521 s->w = w;
522 s->h = h;
523 _unlockLayerState();
524 return NO_ERROR;
525}
526
Mathias Agopian62185b72009-04-16 16:19:50 -0700527status_t SurfaceComposerClient::setLayer(SurfaceID id, int32_t z)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800528{
Mathias Agopian62185b72009-04-16 16:19:50 -0700529 layer_state_t* s = _lockLayerState(id);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800530 if (!s) return BAD_INDEX;
531 s->what |= ISurfaceComposer::eLayerChanged;
532 s->z = z;
533 _unlockLayerState();
534 return NO_ERROR;
535}
536
Mathias Agopian62185b72009-04-16 16:19:50 -0700537status_t SurfaceComposerClient::hide(SurfaceID id)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800538{
Mathias Agopian62185b72009-04-16 16:19:50 -0700539 return setFlags(id, ISurfaceComposer::eLayerHidden,
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800540 ISurfaceComposer::eLayerHidden);
541}
542
Mathias Agopian62185b72009-04-16 16:19:50 -0700543status_t SurfaceComposerClient::show(SurfaceID id, int32_t)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800544{
Mathias Agopian62185b72009-04-16 16:19:50 -0700545 return setFlags(id, 0, ISurfaceComposer::eLayerHidden);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800546}
547
Mathias Agopian62185b72009-04-16 16:19:50 -0700548status_t SurfaceComposerClient::freeze(SurfaceID id)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800549{
Mathias Agopian62185b72009-04-16 16:19:50 -0700550 return setFlags(id, ISurfaceComposer::eLayerFrozen,
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800551 ISurfaceComposer::eLayerFrozen);
552}
553
Mathias Agopian62185b72009-04-16 16:19:50 -0700554status_t SurfaceComposerClient::unfreeze(SurfaceID id)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800555{
Mathias Agopian62185b72009-04-16 16:19:50 -0700556 return setFlags(id, 0, ISurfaceComposer::eLayerFrozen);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800557}
558
Mathias Agopian62185b72009-04-16 16:19:50 -0700559status_t SurfaceComposerClient::setFlags(SurfaceID id,
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800560 uint32_t flags, uint32_t mask)
561{
Mathias Agopian62185b72009-04-16 16:19:50 -0700562 layer_state_t* s = _lockLayerState(id);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800563 if (!s) return BAD_INDEX;
564 s->what |= ISurfaceComposer::eVisibilityChanged;
565 s->flags &= ~mask;
566 s->flags |= (flags & mask);
567 s->mask |= mask;
568 _unlockLayerState();
569 return NO_ERROR;
570}
571
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800572status_t SurfaceComposerClient::setTransparentRegionHint(
Mathias Agopian62185b72009-04-16 16:19:50 -0700573 SurfaceID id, const Region& transparentRegion)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800574{
Mathias Agopian62185b72009-04-16 16:19:50 -0700575 layer_state_t* s = _lockLayerState(id);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800576 if (!s) return BAD_INDEX;
577 s->what |= ISurfaceComposer::eTransparentRegionChanged;
578 s->transparentRegion = transparentRegion;
579 _unlockLayerState();
580 return NO_ERROR;
581}
582
Mathias Agopian62185b72009-04-16 16:19:50 -0700583status_t SurfaceComposerClient::setAlpha(SurfaceID id, float alpha)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800584{
Mathias Agopian62185b72009-04-16 16:19:50 -0700585 layer_state_t* s = _lockLayerState(id);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800586 if (!s) return BAD_INDEX;
587 s->what |= ISurfaceComposer::eAlphaChanged;
588 s->alpha = alpha;
589 _unlockLayerState();
590 return NO_ERROR;
591}
592
593status_t SurfaceComposerClient::setMatrix(
Mathias Agopian62185b72009-04-16 16:19:50 -0700594 SurfaceID id,
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800595 float dsdx, float dtdx,
596 float dsdy, float dtdy )
597{
Mathias Agopian62185b72009-04-16 16:19:50 -0700598 layer_state_t* s = _lockLayerState(id);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800599 if (!s) return BAD_INDEX;
600 s->what |= ISurfaceComposer::eMatrixChanged;
601 layer_state_t::matrix22_t matrix;
602 matrix.dsdx = dsdx;
603 matrix.dtdx = dtdx;
604 matrix.dsdy = dsdy;
605 matrix.dtdy = dtdy;
606 s->matrix = matrix;
607 _unlockLayerState();
608 return NO_ERROR;
609}
610
Mathias Agopian62185b72009-04-16 16:19:50 -0700611status_t SurfaceComposerClient::setFreezeTint(SurfaceID id, uint32_t tint)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800612{
Mathias Agopian62185b72009-04-16 16:19:50 -0700613 layer_state_t* s = _lockLayerState(id);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800614 if (!s) return BAD_INDEX;
615 s->what |= ISurfaceComposer::eFreezeTintChanged;
616 s->tint = tint;
617 _unlockLayerState();
618 return NO_ERROR;
619}
620
621}; // namespace android
622