blob: 1678711aaf4286c2916ae71ddfc5f54de0aa6549 [file] [log] [blame]
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2007 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#define LOG_TAG "SurfaceComposerClient"
18
19#include <stdint.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080020#include <sys/types.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080021
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080022#include <utils/Errors.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080023#include <utils/Log.h>
Mathias Agopiand4784a32010-05-27 19:41:15 -070024#include <utils/Singleton.h>
Mathias Agopiana67932f2011-04-20 14:20:59 -070025#include <utils/SortedVector.h>
26#include <utils/String8.h>
27#include <utils/threads.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080028
Mathias Agopian9cce3252010-02-09 17:46:37 -080029#include <binder/IMemory.h>
Mathias Agopiana67932f2011-04-20 14:20:59 -070030#include <binder/IServiceManager.h>
Mathias Agopian9cce3252010-02-09 17:46:37 -080031
Mathias Agopian076b1cc2009-04-10 14:24:30 -070032#include <ui/DisplayInfo.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080033
Mathias Agopiana67932f2011-04-20 14:20:59 -070034#include <surfaceflinger/ISurface.h>
Mathias Agopian9cce3252010-02-09 17:46:37 -080035#include <surfaceflinger/ISurfaceComposer.h>
Mathias Agopian7e27f052010-05-28 14:22:23 -070036#include <surfaceflinger/ISurfaceComposerClient.h>
Mathias Agopian9cce3252010-02-09 17:46:37 -080037#include <surfaceflinger/SurfaceComposerClient.h>
38
39#include <private/surfaceflinger/LayerState.h>
40#include <private/surfaceflinger/SharedBufferStack.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080041
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080042
43namespace android {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080044// ---------------------------------------------------------------------------
45
Mathias Agopian7e27f052010-05-28 14:22:23 -070046ANDROID_SINGLETON_STATIC_INSTANCE(ComposerService);
47
Mathias Agopianb7e930d2010-06-01 15:12:58 -070048ComposerService::ComposerService()
49: Singleton<ComposerService>() {
50 const String16 name("SurfaceFlinger");
51 while (getService(name, &mComposerService) != NO_ERROR) {
52 usleep(250000);
53 }
54 mServerCblkMemory = mComposerService->getCblk();
55 mServerCblk = static_cast<surface_flinger_cblk_t volatile *>(
56 mServerCblkMemory->getBase());
57}
58
59sp<ISurfaceComposer> ComposerService::getComposerService() {
60 return ComposerService::getInstance().mComposerService;
61}
62
63surface_flinger_cblk_t const volatile * ComposerService::getControlBlock() {
64 return ComposerService::getInstance().mServerCblk;
65}
Mathias Agopian7e27f052010-05-28 14:22:23 -070066
67static inline sp<ISurfaceComposer> getComposerService() {
68 return ComposerService::getComposerService();
69}
70
71static inline surface_flinger_cblk_t const volatile * get_cblk() {
72 return ComposerService::getControlBlock();
73}
74
75// ---------------------------------------------------------------------------
76
77class Composer : public Singleton<Composer>
78{
79 Mutex mLock;
80 SortedVector< wp<SurfaceComposerClient> > mActiveConnections;
81 SortedVector<sp<SurfaceComposerClient> > mOpenTransactions;
82
83 Composer() : Singleton<Composer>() {
84 }
85
Mathias Agopiand4784a32010-05-27 19:41:15 -070086 void addClientImpl(const sp<SurfaceComposerClient>& client) {
87 Mutex::Autolock _l(mLock);
88 mActiveConnections.add(client);
89 }
90
91 void removeClientImpl(const sp<SurfaceComposerClient>& client) {
92 Mutex::Autolock _l(mLock);
93 mActiveConnections.remove(client);
94 }
95
96 void openGlobalTransactionImpl()
97 {
98 Mutex::Autolock _l(mLock);
99 if (mOpenTransactions.size()) {
100 LOGE("openGlobalTransaction() called more than once. skipping.");
101 return;
102 }
103 const size_t N = mActiveConnections.size();
104 for (size_t i=0; i<N; i++) {
105 sp<SurfaceComposerClient> client(mActiveConnections[i].promote());
106 if (client != 0 && mOpenTransactions.indexOf(client) < 0) {
107 if (client->openTransaction() == NO_ERROR) {
108 mOpenTransactions.add(client);
109 } else {
110 LOGE("openTransaction on client %p failed", client.get());
111 // let it go, it'll fail later when the user
112 // tries to do something with the transaction
113 }
Mathias Agopiandd3423c2009-09-23 15:44:05 -0700114 }
Mathias Agopiandd3423c2009-09-23 15:44:05 -0700115 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800116 }
Mathias Agopiand4784a32010-05-27 19:41:15 -0700117
118 void closeGlobalTransactionImpl()
119 {
120 mLock.lock();
121 SortedVector< sp<SurfaceComposerClient> > clients(mOpenTransactions);
122 mOpenTransactions.clear();
123 mLock.unlock();
124
Mathias Agopian7e27f052010-05-28 14:22:23 -0700125 sp<ISurfaceComposer> sm(getComposerService());
Mathias Agopiand4784a32010-05-27 19:41:15 -0700126 sm->openGlobalTransaction();
127 const size_t N = clients.size();
128 for (size_t i=0; i<N; i++) {
129 clients[i]->closeTransaction();
130 }
131 sm->closeGlobalTransaction();
132 }
133
134 friend class Singleton<Composer>;
135
136public:
Mathias Agopiand4784a32010-05-27 19:41:15 -0700137 static void addClient(const sp<SurfaceComposerClient>& client) {
138 Composer::getInstance().addClientImpl(client);
139 }
140 static void removeClient(const sp<SurfaceComposerClient>& client) {
141 Composer::getInstance().removeClientImpl(client);
142 }
143 static void openGlobalTransaction() {
144 Composer::getInstance().openGlobalTransactionImpl();
145 }
146 static void closeGlobalTransaction() {
147 Composer::getInstance().closeGlobalTransactionImpl();
148 }
149};
150
151ANDROID_SINGLETON_STATIC_INSTANCE(Composer);
152
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800153// ---------------------------------------------------------------------------
154
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800155static inline int compare_type( const layer_state_t& lhs,
156 const layer_state_t& rhs) {
157 if (lhs.surface < rhs.surface) return -1;
158 if (lhs.surface > rhs.surface) return 1;
159 return 0;
160}
161
162SurfaceComposerClient::SurfaceComposerClient()
Mathias Agopiand4784a32010-05-27 19:41:15 -0700163 : mTransactionOpen(0), mPrebuiltLayerState(0), mStatus(NO_INIT)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800164{
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800165}
166
Mathias Agopiand4784a32010-05-27 19:41:15 -0700167void SurfaceComposerClient::onFirstRef()
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800168{
Mathias Agopiand4784a32010-05-27 19:41:15 -0700169 sp<ISurfaceComposer> sm(getComposerService());
170 if (sm != 0) {
Mathias Agopian7e27f052010-05-28 14:22:23 -0700171 sp<ISurfaceComposerClient> conn = sm->createConnection();
Mathias Agopiand4784a32010-05-27 19:41:15 -0700172 if (conn != 0) {
173 mClient = conn;
174 Composer::addClient(this);
175 mPrebuiltLayerState = new layer_state_t;
176 mStatus = NO_ERROR;
177 }
178 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800179}
180
Mathias Agopian631f3582010-05-25 17:51:34 -0700181SurfaceComposerClient::~SurfaceComposerClient()
182{
Mathias Agopiand4784a32010-05-27 19:41:15 -0700183 delete mPrebuiltLayerState;
Mathias Agopian631f3582010-05-25 17:51:34 -0700184 dispose();
185}
Mathias Agopiandd3423c2009-09-23 15:44:05 -0700186
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800187status_t SurfaceComposerClient::initCheck() const
188{
189 return mStatus;
190}
191
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800192sp<IBinder> SurfaceComposerClient::connection() const
193{
194 return (mClient != 0) ? mClient->asBinder() : 0;
195}
196
Mathias Agopiand4784a32010-05-27 19:41:15 -0700197status_t SurfaceComposerClient::linkToComposerDeath(
198 const sp<IBinder::DeathRecipient>& recipient,
199 void* cookie, uint32_t flags)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800200{
Mathias Agopiand4784a32010-05-27 19:41:15 -0700201 sp<ISurfaceComposer> sm(getComposerService());
202 return sm->asBinder()->linkToDeath(recipient, cookie, flags);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800203}
204
205void SurfaceComposerClient::dispose()
206{
207 // this can be called more than once.
Mathias Agopian7e27f052010-05-28 14:22:23 -0700208 sp<ISurfaceComposerClient> client;
Mathias Agopiand4784a32010-05-27 19:41:15 -0700209 Mutex::Autolock _lm(mLock);
210 if (mClient != 0) {
211 Composer::removeClient(this);
212 client = mClient; // hold ref while lock is held
213 mClient.clear();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800214 }
Mathias Agopiand4784a32010-05-27 19:41:15 -0700215 mStatus = NO_INIT;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800216}
217
218status_t SurfaceComposerClient::getDisplayInfo(
219 DisplayID dpy, DisplayInfo* info)
220{
Mathias Agopiana67932f2011-04-20 14:20:59 -0700221 if (uint32_t(dpy)>=NUM_DISPLAY_MAX)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800222 return BAD_VALUE;
223
224 volatile surface_flinger_cblk_t const * cblk = get_cblk();
225 volatile display_cblk_t const * dcblk = cblk->displays + dpy;
226
227 info->w = dcblk->w;
228 info->h = dcblk->h;
229 info->orientation = dcblk->orientation;
230 info->xdpi = dcblk->xdpi;
231 info->ydpi = dcblk->ydpi;
232 info->fps = dcblk->fps;
233 info->density = dcblk->density;
234 return getPixelFormatInfo(dcblk->format, &(info->pixelFormatInfo));
235}
236
237ssize_t SurfaceComposerClient::getDisplayWidth(DisplayID dpy)
238{
Mathias Agopiana67932f2011-04-20 14:20:59 -0700239 if (uint32_t(dpy)>=NUM_DISPLAY_MAX)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800240 return BAD_VALUE;
241 volatile surface_flinger_cblk_t const * cblk = get_cblk();
242 volatile display_cblk_t const * dcblk = cblk->displays + dpy;
243 return dcblk->w;
244}
245
246ssize_t SurfaceComposerClient::getDisplayHeight(DisplayID dpy)
247{
Mathias Agopiana67932f2011-04-20 14:20:59 -0700248 if (uint32_t(dpy)>=NUM_DISPLAY_MAX)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800249 return BAD_VALUE;
250 volatile surface_flinger_cblk_t const * cblk = get_cblk();
251 volatile display_cblk_t const * dcblk = cblk->displays + dpy;
252 return dcblk->h;
253}
254
255ssize_t SurfaceComposerClient::getDisplayOrientation(DisplayID dpy)
256{
Mathias Agopiana67932f2011-04-20 14:20:59 -0700257 if (uint32_t(dpy)>=NUM_DISPLAY_MAX)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800258 return BAD_VALUE;
259 volatile surface_flinger_cblk_t const * cblk = get_cblk();
260 volatile display_cblk_t const * dcblk = cblk->displays + dpy;
261 return dcblk->orientation;
262}
263
264ssize_t SurfaceComposerClient::getNumberOfDisplays()
265{
266 volatile surface_flinger_cblk_t const * cblk = get_cblk();
267 uint32_t connected = cblk->connected;
268 int n = 0;
269 while (connected) {
270 if (connected&1) n++;
271 connected >>= 1;
272 }
273 return n;
274}
275
Mathias Agopian01b76682009-04-16 20:04:08 -0700276sp<SurfaceControl> SurfaceComposerClient::createSurface(
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800277 DisplayID display,
278 uint32_t w,
279 uint32_t h,
280 PixelFormat format,
281 uint32_t flags)
282{
Mathias Agopian285dbde2010-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
Mathias Agopian0ef4e152011-04-20 14:19:32 -0700289 return SurfaceComposerClient::createSurface(name, display,
Mathias Agopian285dbde2010-03-01 16:09:43 -0800290 w, h, format, flags);
Mathias Agopian285dbde2010-03-01 16:09:43 -0800291}
292
293sp<SurfaceControl> SurfaceComposerClient::createSurface(
Mathias Agopian285dbde2010-03-01 16:09:43 -0800294 const String8& name,
295 DisplayID display,
296 uint32_t w,
297 uint32_t h,
298 PixelFormat format,
299 uint32_t flags)
300{
Mathias Agopian01b76682009-04-16 20:04:08 -0700301 sp<SurfaceControl> result;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800302 if (mStatus == NO_ERROR) {
Mathias Agopian7e27f052010-05-28 14:22:23 -0700303 ISurfaceComposerClient::surface_data_t data;
Mathias Agopian0ef4e152011-04-20 14:19:32 -0700304 sp<ISurface> surface = mClient->createSurface(&data, name,
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800305 display, w, h, format, flags);
306 if (surface != 0) {
Mathias Agopian53503a92010-06-08 15:40:56 -0700307 result = new SurfaceControl(this, surface, data, w, h, format, flags);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800308 }
309 }
310 return result;
311}
312
313status_t SurfaceComposerClient::destroySurface(SurfaceID sid)
314{
315 if (mStatus != NO_ERROR)
316 return mStatus;
317
318 // it's okay to destroy a surface while a transaction is open,
319 // (transactions really are a client-side concept)
320 // however, this indicates probably a misuse of the API or a bug
321 // in the client code.
322 LOGW_IF(mTransactionOpen,
323 "Destroying surface while a transaction is open. "
324 "Client %p: destroying surface %d, mTransactionOpen=%d",
325 this, sid, mTransactionOpen);
326
327 status_t err = mClient->destroySurface(sid);
328 return err;
329}
330
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800331void SurfaceComposerClient::openGlobalTransaction()
332{
Mathias Agopiand4784a32010-05-27 19:41:15 -0700333 Composer::openGlobalTransaction();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800334}
335
336void SurfaceComposerClient::closeGlobalTransaction()
337{
Mathias Agopiand4784a32010-05-27 19:41:15 -0700338 Composer::closeGlobalTransaction();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800339}
340
341status_t SurfaceComposerClient::freezeDisplay(DisplayID dpy, uint32_t flags)
342{
Mathias Agopiandd3423c2009-09-23 15:44:05 -0700343 sp<ISurfaceComposer> sm(getComposerService());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800344 return sm->freezeDisplay(dpy, flags);
345}
346
347status_t SurfaceComposerClient::unfreezeDisplay(DisplayID dpy, uint32_t flags)
348{
Mathias Agopiandd3423c2009-09-23 15:44:05 -0700349 sp<ISurfaceComposer> sm(getComposerService());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800350 return sm->unfreezeDisplay(dpy, flags);
351}
352
Mathias Agopianc08731e2009-03-27 18:11:38 -0700353int SurfaceComposerClient::setOrientation(DisplayID dpy,
354 int orientation, uint32_t flags)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800355{
Mathias Agopiandd3423c2009-09-23 15:44:05 -0700356 sp<ISurfaceComposer> sm(getComposerService());
Mathias Agopianc08731e2009-03-27 18:11:38 -0700357 return sm->setOrientation(dpy, orientation, flags);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800358}
359
360status_t SurfaceComposerClient::openTransaction()
361{
362 if (mStatus != NO_ERROR)
363 return mStatus;
364 Mutex::Autolock _l(mLock);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800365 mTransactionOpen++;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800366 return NO_ERROR;
367}
368
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800369status_t SurfaceComposerClient::closeTransaction()
370{
371 if (mStatus != NO_ERROR)
372 return mStatus;
373
374 Mutex::Autolock _l(mLock);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800375 if (mTransactionOpen <= 0) {
376 LOGE( "closeTransaction (client %p, mTransactionOpen=%d) "
377 "called more times than openTransaction()",
378 this, mTransactionOpen);
379 return INVALID_OPERATION;
380 }
381
382 if (mTransactionOpen >= 2) {
383 mTransactionOpen--;
384 return NO_ERROR;
385 }
386
387 mTransactionOpen = 0;
388 const ssize_t count = mStates.size();
389 if (count) {
390 mClient->setState(count, mStates.array());
391 mStates.clear();
392 }
393 return NO_ERROR;
394}
395
Mathias Agopian631f3582010-05-25 17:51:34 -0700396layer_state_t* SurfaceComposerClient::get_state_l(SurfaceID index)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800397{
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800398 // API usage error, do nothing.
399 if (mTransactionOpen<=0) {
400 LOGE("Not in transaction (client=%p, SurfaceID=%d, mTransactionOpen=%d",
401 this, int(index), mTransactionOpen);
402 return 0;
403 }
404
405 // use mPrebuiltLayerState just to find out if we already have it
Mathias Agopiand4784a32010-05-27 19:41:15 -0700406 layer_state_t& dummy(*mPrebuiltLayerState);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800407 dummy.surface = index;
408 ssize_t i = mStates.indexOf(dummy);
409 if (i < 0) {
410 // we don't have it, add an initialized layer_state to our list
411 i = mStates.add(dummy);
412 }
413 return mStates.editArray() + i;
414}
415
Mathias Agopian631f3582010-05-25 17:51:34 -0700416layer_state_t* SurfaceComposerClient::lockLayerState(SurfaceID id)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800417{
418 layer_state_t* s;
419 mLock.lock();
Mathias Agopian631f3582010-05-25 17:51:34 -0700420 s = get_state_l(id);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800421 if (!s) mLock.unlock();
422 return s;
423}
424
Mathias Agopian631f3582010-05-25 17:51:34 -0700425void SurfaceComposerClient::unlockLayerState()
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800426{
427 mLock.unlock();
428}
429
Mathias Agopian62185b72009-04-16 16:19:50 -0700430status_t SurfaceComposerClient::setPosition(SurfaceID id, int32_t x, int32_t y)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800431{
Mathias Agopian631f3582010-05-25 17:51:34 -0700432 layer_state_t* s = lockLayerState(id);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800433 if (!s) return BAD_INDEX;
434 s->what |= ISurfaceComposer::ePositionChanged;
435 s->x = x;
436 s->y = y;
Mathias Agopian631f3582010-05-25 17:51:34 -0700437 unlockLayerState();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800438 return NO_ERROR;
439}
440
Mathias Agopian62185b72009-04-16 16:19:50 -0700441status_t SurfaceComposerClient::setSize(SurfaceID id, uint32_t w, uint32_t h)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800442{
Mathias Agopian631f3582010-05-25 17:51:34 -0700443 layer_state_t* s = lockLayerState(id);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800444 if (!s) return BAD_INDEX;
445 s->what |= ISurfaceComposer::eSizeChanged;
446 s->w = w;
447 s->h = h;
Mathias Agopian631f3582010-05-25 17:51:34 -0700448 unlockLayerState();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800449 return NO_ERROR;
450}
451
Mathias Agopian62185b72009-04-16 16:19:50 -0700452status_t SurfaceComposerClient::setLayer(SurfaceID id, int32_t z)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800453{
Mathias Agopian631f3582010-05-25 17:51:34 -0700454 layer_state_t* s = lockLayerState(id);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800455 if (!s) return BAD_INDEX;
456 s->what |= ISurfaceComposer::eLayerChanged;
457 s->z = z;
Mathias Agopian631f3582010-05-25 17:51:34 -0700458 unlockLayerState();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800459 return NO_ERROR;
460}
461
Mathias Agopian62185b72009-04-16 16:19:50 -0700462status_t SurfaceComposerClient::hide(SurfaceID id)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800463{
Mathias Agopian62185b72009-04-16 16:19:50 -0700464 return setFlags(id, ISurfaceComposer::eLayerHidden,
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800465 ISurfaceComposer::eLayerHidden);
466}
467
Mathias Agopian62185b72009-04-16 16:19:50 -0700468status_t SurfaceComposerClient::show(SurfaceID id, int32_t)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800469{
Mathias Agopian62185b72009-04-16 16:19:50 -0700470 return setFlags(id, 0, ISurfaceComposer::eLayerHidden);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800471}
472
Mathias Agopian62185b72009-04-16 16:19:50 -0700473status_t SurfaceComposerClient::freeze(SurfaceID id)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800474{
Mathias Agopian62185b72009-04-16 16:19:50 -0700475 return setFlags(id, ISurfaceComposer::eLayerFrozen,
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800476 ISurfaceComposer::eLayerFrozen);
477}
478
Mathias Agopian62185b72009-04-16 16:19:50 -0700479status_t SurfaceComposerClient::unfreeze(SurfaceID id)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800480{
Mathias Agopian62185b72009-04-16 16:19:50 -0700481 return setFlags(id, 0, ISurfaceComposer::eLayerFrozen);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800482}
483
Mathias Agopian62185b72009-04-16 16:19:50 -0700484status_t SurfaceComposerClient::setFlags(SurfaceID id,
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800485 uint32_t flags, uint32_t mask)
486{
Mathias Agopian631f3582010-05-25 17:51:34 -0700487 layer_state_t* s = lockLayerState(id);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800488 if (!s) return BAD_INDEX;
489 s->what |= ISurfaceComposer::eVisibilityChanged;
490 s->flags &= ~mask;
491 s->flags |= (flags & mask);
492 s->mask |= mask;
Mathias Agopian631f3582010-05-25 17:51:34 -0700493 unlockLayerState();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800494 return NO_ERROR;
495}
496
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800497status_t SurfaceComposerClient::setTransparentRegionHint(
Mathias Agopian62185b72009-04-16 16:19:50 -0700498 SurfaceID id, const Region& transparentRegion)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800499{
Mathias Agopian631f3582010-05-25 17:51:34 -0700500 layer_state_t* s = lockLayerState(id);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800501 if (!s) return BAD_INDEX;
502 s->what |= ISurfaceComposer::eTransparentRegionChanged;
503 s->transparentRegion = transparentRegion;
Mathias Agopian631f3582010-05-25 17:51:34 -0700504 unlockLayerState();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800505 return NO_ERROR;
506}
507
Mathias Agopian62185b72009-04-16 16:19:50 -0700508status_t SurfaceComposerClient::setAlpha(SurfaceID id, float alpha)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800509{
Mathias Agopian631f3582010-05-25 17:51:34 -0700510 layer_state_t* s = lockLayerState(id);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800511 if (!s) return BAD_INDEX;
512 s->what |= ISurfaceComposer::eAlphaChanged;
513 s->alpha = alpha;
Mathias Agopian631f3582010-05-25 17:51:34 -0700514 unlockLayerState();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800515 return NO_ERROR;
516}
517
518status_t SurfaceComposerClient::setMatrix(
Mathias Agopian62185b72009-04-16 16:19:50 -0700519 SurfaceID id,
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800520 float dsdx, float dtdx,
521 float dsdy, float dtdy )
522{
Mathias Agopian631f3582010-05-25 17:51:34 -0700523 layer_state_t* s = lockLayerState(id);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800524 if (!s) return BAD_INDEX;
525 s->what |= ISurfaceComposer::eMatrixChanged;
526 layer_state_t::matrix22_t matrix;
527 matrix.dsdx = dsdx;
528 matrix.dtdx = dtdx;
529 matrix.dsdy = dsdy;
530 matrix.dtdy = dtdy;
531 s->matrix = matrix;
Mathias Agopian631f3582010-05-25 17:51:34 -0700532 unlockLayerState();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800533 return NO_ERROR;
534}
535
Mathias Agopian62185b72009-04-16 16:19:50 -0700536status_t SurfaceComposerClient::setFreezeTint(SurfaceID id, uint32_t tint)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800537{
Mathias Agopian631f3582010-05-25 17:51:34 -0700538 layer_state_t* s = lockLayerState(id);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800539 if (!s) return BAD_INDEX;
540 s->what |= ISurfaceComposer::eFreezeTintChanged;
541 s->tint = tint;
Mathias Agopian631f3582010-05-25 17:51:34 -0700542 unlockLayerState();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800543 return NO_ERROR;
544}
545
Mathias Agopiand4784a32010-05-27 19:41:15 -0700546// ----------------------------------------------------------------------------
Mathias Agopian74c40c02010-09-29 13:02:36 -0700547
548ScreenshotClient::ScreenshotClient()
549 : mWidth(0), mHeight(0), mFormat(PIXEL_FORMAT_NONE) {
550}
551
552status_t ScreenshotClient::update() {
553 sp<ISurfaceComposer> s(ComposerService::getComposerService());
554 if (s == NULL) return NO_INIT;
555 mHeap = 0;
556 return s->captureScreen(0, &mHeap,
Mathias Agopianbf2c6a62010-12-10 16:22:31 -0800557 &mWidth, &mHeight, &mFormat, 0, 0,
558 0, -1UL);
Mathias Agopian74c40c02010-09-29 13:02:36 -0700559}
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,
Mathias Agopianbf2c6a62010-12-10 16:22:31 -0800566 &mWidth, &mHeight, &mFormat, reqWidth, reqHeight,
567 0, -1UL);
568}
569
570status_t ScreenshotClient::update(uint32_t reqWidth, uint32_t reqHeight,
571 uint32_t minLayerZ, uint32_t maxLayerZ) {
572 sp<ISurfaceComposer> s(ComposerService::getComposerService());
573 if (s == NULL) return NO_INIT;
574 mHeap = 0;
575 return s->captureScreen(0, &mHeap,
576 &mWidth, &mHeight, &mFormat, reqWidth, reqHeight,
577 minLayerZ, maxLayerZ);
Mathias Agopian74c40c02010-09-29 13:02:36 -0700578}
579
580void ScreenshotClient::release() {
581 mHeap = 0;
582}
583
584void const* ScreenshotClient::getPixels() const {
585 return mHeap->getBase();
586}
587
588uint32_t ScreenshotClient::getWidth() const {
589 return mWidth;
590}
591
592uint32_t ScreenshotClient::getHeight() const {
593 return mHeight;
594}
595
596PixelFormat ScreenshotClient::getFormat() const {
597 return mFormat;
598}
599
600uint32_t ScreenshotClient::getStride() const {
601 return mWidth;
602}
603
604size_t ScreenshotClient::getSize() const {
605 return mHeap->getSize();
606}
607
608// ----------------------------------------------------------------------------
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800609}; // namespace android
610