blob: 194c29550d5942eabdb8405751e2fda5b930718c [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
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080017#include <stdlib.h>
18#include <stdint.h>
19#include <sys/types.h>
20
21#include <cutils/properties.h>
Mathias Agopian076b1cc2009-04-10 14:24:30 -070022#include <cutils/native_handle.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080023
24#include <utils/Errors.h>
25#include <utils/Log.h>
26#include <utils/StopWatch.h>
27
Mathias Agopian3330b202009-10-05 17:07:12 -070028#include <ui/GraphicBuffer.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080029#include <ui/PixelFormat.h>
Mathias Agopian9cce3252010-02-09 17:46:37 -080030
31#include <surfaceflinger/Surface.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080032
33#include "clz.h"
Mathias Agopian1f7bec62010-06-25 18:02:21 -070034#include "GLExtensions.h"
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080035#include "Layer.h"
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080036#include "SurfaceFlinger.h"
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080037#include "DisplayHardware/DisplayHardware.h"
Mathias Agopiana350ff92010-08-10 17:14:02 -070038#include "DisplayHardware/HWComposer.h"
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080039
40
41#define DEBUG_RESIZE 0
42
43
44namespace android {
45
Mathias Agopianca99fb82010-04-14 16:43:44 -070046template <typename T> inline T min(T a, T b) {
47 return a<b ? a : b;
48}
49
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080050// ---------------------------------------------------------------------------
51
Mathias Agopian96f08192010-06-02 23:28:45 -070052Layer::Layer(SurfaceFlinger* flinger,
53 DisplayID display, const sp<Client>& client)
54 : LayerBaseClient(flinger, display, client),
Mathias Agopian1f7bec62010-06-25 18:02:21 -070055 mGLExtensions(GLExtensions::getInstance()),
Mathias Agopian401c2572009-09-23 19:16:27 -070056 mNeedsBlending(true),
Mathias Agopiand606de62010-05-10 20:06:11 -070057 mNeedsDithering(false),
Mathias Agopianb7e930d2010-06-01 15:12:58 -070058 mSecure(false),
Mathias Agopian1f7bec62010-06-25 18:02:21 -070059 mTextureManager(),
Mathias Agopiana138f892010-05-21 17:24:35 -070060 mBufferManager(mTextureManager),
61 mWidth(0), mHeight(0), mFixedSize(false)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080062{
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080063}
64
65Layer::~Layer()
66{
Mathias Agopianbb641242010-05-18 17:06:55 -070067 // FIXME: must be called from the main UI thread
68 EGLDisplay dpy(mFlinger->graphicPlane(0).getEGLDisplay());
69 mBufferManager.destroy(dpy);
70
Mathias Agopianb7e930d2010-06-01 15:12:58 -070071 // we can use getUserClientUnsafe here because we know we're
72 // single-threaded at that point.
73 sp<UserClient> ourClient(mUserClientRef.getUserClientUnsafe());
74 if (ourClient != 0) {
75 ourClient->detachLayer(this);
76 }
Mathias Agopiand606de62010-05-10 20:06:11 -070077}
78
Mathias Agopianb7e930d2010-06-01 15:12:58 -070079status_t Layer::setToken(const sp<UserClient>& userClient,
80 SharedClient* sharedClient, int32_t token)
Mathias Agopian96f08192010-06-02 23:28:45 -070081{
Mathias Agopian579b3f82010-06-08 19:54:15 -070082 sp<SharedBufferServer> lcblk = new SharedBufferServer(
Mathias Agopianb7e930d2010-06-01 15:12:58 -070083 sharedClient, token, mBufferManager.getDefaultBufferCount(),
Mathias Agopian96f08192010-06-02 23:28:45 -070084 getIdentity());
85
Mathias Agopianb7e930d2010-06-01 15:12:58 -070086 status_t err = mUserClientRef.setToken(userClient, lcblk, token);
Mathias Agopian579b3f82010-06-08 19:54:15 -070087
88 LOGE_IF(err != NO_ERROR,
89 "ClientRef::setToken(%p, %p, %u) failed",
90 userClient.get(), lcblk.get(), token);
91
92 if (err == NO_ERROR) {
93 // we need to free the buffers associated with this surface
Mathias Agopianb7e930d2010-06-01 15:12:58 -070094 }
95
96 return err;
97}
98
99int32_t Layer::getToken() const
100{
101 return mUserClientRef.getToken();
Mathias Agopian96f08192010-06-02 23:28:45 -0700102}
103
Mathias Agopian579b3f82010-06-08 19:54:15 -0700104sp<UserClient> Layer::getClient() const
105{
106 return mUserClientRef.getClient();
107}
108
Mathias Agopiand606de62010-05-10 20:06:11 -0700109// called with SurfaceFlinger::mStateLock as soon as the layer is entered
110// in the purgatory list
111void Layer::onRemoved()
112{
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700113 ClientRef::Access sharedClient(mUserClientRef);
114 SharedBufferServer* lcblk(sharedClient.get());
115 if (lcblk) {
Mathias Agopian96f08192010-06-02 23:28:45 -0700116 // wake up the condition
117 lcblk->setStatus(NO_INIT);
118 }
Mathias Agopian48d819a2009-09-10 19:41:18 -0700119}
Mathias Agopiancbb288b2009-09-07 16:32:45 -0700120
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700121sp<LayerBaseClient::Surface> Layer::createSurface() const
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800122{
123 return mSurface;
124}
125
Mathias Agopian9a112062009-04-17 19:36:26 -0700126status_t Layer::ditch()
127{
Mathias Agopianbb641242010-05-18 17:06:55 -0700128 // NOTE: Called from the main UI thread
129
Mathias Agopian0aa758d2009-04-22 15:23:34 -0700130 // the layer is not on screen anymore. free as much resources as possible
Mathias Agopianf5430db2009-12-11 00:56:10 -0800131 mFreezeLock.clear();
Mathias Agopianbb641242010-05-18 17:06:55 -0700132
133 EGLDisplay dpy(mFlinger->graphicPlane(0).getEGLDisplay());
134 mBufferManager.destroy(dpy);
135 mSurface.clear();
136
137 Mutex::Autolock _l(mLock);
138 mWidth = mHeight = 0;
Mathias Agopian9a112062009-04-17 19:36:26 -0700139 return NO_ERROR;
140}
141
Mathias Agopianf9d93272009-06-19 17:00:27 -0700142status_t Layer::setBuffers( uint32_t w, uint32_t h,
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800143 PixelFormat format, uint32_t flags)
144{
Mathias Agopian401c2572009-09-23 19:16:27 -0700145 // this surfaces pixel format
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800146 PixelFormatInfo info;
147 status_t err = getPixelFormatInfo(format, &info);
148 if (err) return err;
149
Mathias Agopian401c2572009-09-23 19:16:27 -0700150 // the display's pixel format
151 const DisplayHardware& hw(graphicPlane(0).displayHardware());
Mathias Agopianca99fb82010-04-14 16:43:44 -0700152 uint32_t const maxSurfaceDims = min(
153 hw.getMaxTextureSize(), hw.getMaxViewportDims());
154
155 // never allow a surface larger than what our underlying GL implementation
156 // can handle.
157 if ((uint32_t(w)>maxSurfaceDims) || (uint32_t(h)>maxSurfaceDims)) {
158 return BAD_VALUE;
159 }
160
Mathias Agopian401c2572009-09-23 19:16:27 -0700161 PixelFormatInfo displayInfo;
162 getPixelFormatInfo(hw.getFormat(), &displayInfo);
Mathias Agopiana4b740e2009-10-05 18:20:39 -0700163 const uint32_t hwFlags = hw.getFlags();
164
Mathias Agopiancbb288b2009-09-07 16:32:45 -0700165 mFormat = format;
Mathias Agopianca99fb82010-04-14 16:43:44 -0700166 mWidth = w;
Mathias Agopiancbb288b2009-09-07 16:32:45 -0700167 mHeight = h;
Mathias Agopianeff062c2010-08-25 14:59:15 -0700168
169 mReqFormat = format;
170 mReqWidth = w;
171 mReqHeight = h;
172
Mathias Agopian3330b202009-10-05 17:07:12 -0700173 mSecure = (flags & ISurfaceComposer::eSecure) ? true : false;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800174 mNeedsBlending = (info.h_alpha - info.l_alpha) > 0;
Mathias Agopianca99fb82010-04-14 16:43:44 -0700175
Mathias Agopian401c2572009-09-23 19:16:27 -0700176 // we use the red index
177 int displayRedSize = displayInfo.getSize(PixelFormatInfo::INDEX_RED);
178 int layerRedsize = info.getSize(PixelFormatInfo::INDEX_RED);
179 mNeedsDithering = layerRedsize > displayRedSize;
180
Mathias Agopian96f08192010-06-02 23:28:45 -0700181 mSurface = new SurfaceLayer(mFlinger, this);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800182 return NO_ERROR;
183}
184
Mathias Agopiana350ff92010-08-10 17:14:02 -0700185void Layer::setGeometry(hwc_layer_t* hwcl)
186{
187 hwcl->compositionType = HWC_FRAMEBUFFER;
188 hwcl->hints = 0;
189 hwcl->flags = 0;
190 hwcl->transform = 0;
191 hwcl->blending = HWC_BLENDING_NONE;
192
193 // we can't do alpha-fade with the hwc HAL
194 const State& s(drawingState());
195 if (s.alpha < 0xFF) {
196 hwcl->flags = HWC_SKIP_LAYER;
197 return;
198 }
199
200 // we can only handle simple transformation
201 if (mOrientation & Transform::ROT_INVALID) {
202 hwcl->flags = HWC_SKIP_LAYER;
203 return;
204 }
205
206 hwcl->transform = mOrientation;
207
208 if (needsBlending()) {
209 hwcl->blending = mPremultipliedAlpha ?
210 HWC_BLENDING_PREMULT : HWC_BLENDING_COVERAGE;
211 }
212
213 hwcl->displayFrame.left = mTransformedBounds.left;
214 hwcl->displayFrame.top = mTransformedBounds.top;
215 hwcl->displayFrame.right = mTransformedBounds.right;
216 hwcl->displayFrame.bottom = mTransformedBounds.bottom;
217
218 hwcl->visibleRegionScreen.rects =
219 reinterpret_cast<hwc_rect_t const *>(
220 visibleRegionScreen.getArray(
221 &hwcl->visibleRegionScreen.numRects));
222}
223
224void Layer::setPerFrameData(hwc_layer_t* hwcl) {
225 sp<GraphicBuffer> buffer(mBufferManager.getActiveBuffer());
226 if (buffer == NULL) {
227 // this situation can happen if we ran out of memory for instance.
228 // not much we can do. continue to use whatever texture was bound
229 // to this context.
230 hwcl->handle = NULL;
231 return;
232 }
233 hwcl->handle = const_cast<native_handle_t*>(buffer->handle);
234 // TODO: set the crop value properly
235 hwcl->sourceCrop.left = 0;
236 hwcl->sourceCrop.top = 0;
237 hwcl->sourceCrop.right = buffer->width;
238 hwcl->sourceCrop.bottom = buffer->height;
239}
240
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800241void Layer::reloadTexture(const Region& dirty)
242{
Mathias Agopiand606de62010-05-10 20:06:11 -0700243 sp<GraphicBuffer> buffer(mBufferManager.getActiveBuffer());
Mathias Agopian8f03b472009-12-10 15:52:29 -0800244 if (buffer == NULL) {
245 // this situation can happen if we ran out of memory for instance.
246 // not much we can do. continue to use whatever texture was bound
247 // to this context.
248 return;
249 }
250
Mathias Agopian1f7bec62010-06-25 18:02:21 -0700251 if (mGLExtensions.haveDirectTexture()) {
Mathias Agopiand606de62010-05-10 20:06:11 -0700252 EGLDisplay dpy(mFlinger->graphicPlane(0).getEGLDisplay());
253 if (mBufferManager.initEglImage(dpy, buffer) != NO_ERROR) {
254 // not sure what we can do here...
Mathias Agopiand606de62010-05-10 20:06:11 -0700255 goto slowpath;
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700256 }
Mathias Agopian1f7bec62010-06-25 18:02:21 -0700257 } else {
Mathias Agopianfcfeb4b2010-03-08 11:14:20 -0800258slowpath:
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700259 GGLSurface t;
Mathias Agopianf1b38242010-08-20 15:59:53 -0700260 if (buffer->usage & GRALLOC_USAGE_SW_READ_MASK) {
261 status_t res = buffer->lock(&t, GRALLOC_USAGE_SW_READ_OFTEN);
262 LOGE_IF(res, "error %d (%s) locking buffer %p",
263 res, strerror(res), buffer.get());
264 if (res == NO_ERROR) {
265 mBufferManager.loadTexture(dirty, t);
266 buffer->unlock();
267 }
268 } else {
269 // we can't do anything
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700270 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800271 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800272}
273
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800274void Layer::onDraw(const Region& clip) const
275{
Mathias Agopiand606de62010-05-10 20:06:11 -0700276 Texture tex(mBufferManager.getActiveTexture());
277 if (tex.name == -1LU) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800278 // the texture has not been created yet, this Layer has
Mathias Agopian179169e2010-05-06 20:21:45 -0700279 // in fact never been drawn into. This happens frequently with
280 // SurfaceView because the WindowManager can't know when the client
281 // has drawn the first time.
282
283 // If there is nothing under us, we paint the screen in black, otherwise
284 // we just skip this update.
285
286 // figure out if there is something below us
287 Region under;
288 const SurfaceFlinger::LayerVector& drawingLayers(mFlinger->mDrawingState.layersSortedByZ);
289 const size_t count = drawingLayers.size();
290 for (size_t i=0 ; i<count ; ++i) {
291 const sp<LayerBase>& layer(drawingLayers[i]);
292 if (layer.get() == static_cast<LayerBase const*>(this))
293 break;
294 under.orSelf(layer->visibleRegionScreen);
295 }
296 // if not everything below us is covered, we plug the holes!
297 Region holes(clip.subtract(under));
298 if (!holes.isEmpty()) {
Mathias Agopian0a917752010-06-14 21:20:00 -0700299 clearWithOpenGL(holes, 0, 0, 0, 1);
Mathias Agopian179169e2010-05-06 20:21:45 -0700300 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800301 return;
302 }
Mathias Agopiand606de62010-05-10 20:06:11 -0700303 drawWithOpenGL(clip, tex);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800304}
305
Mathias Agopiana7f66922010-05-26 22:08:52 -0700306bool Layer::needsFiltering() const
307{
308 if (!(mFlags & DisplayHardware::SLOW_CONFIG)) {
309 // NOTE: there is a race here, because mFixedSize is updated in a
310 // binder transaction. however, it doesn't really matter since it is
311 // evaluated each time we draw. To be perfectly correct, this flag
312 // would have to be associated with a buffer.
313 if (mFixedSize)
314 return true;
315 }
316 return LayerBase::needsFiltering();
317}
318
Mathias Agopianb5b7f262010-05-07 15:58:44 -0700319
320status_t Layer::setBufferCount(int bufferCount)
321{
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700322 ClientRef::Access sharedClient(mUserClientRef);
323 SharedBufferServer* lcblk(sharedClient.get());
324 if (!lcblk) {
Mathias Agopianb5b7f262010-05-07 15:58:44 -0700325 // oops, the client is already gone
326 return DEAD_OBJECT;
327 }
328
Mathias Agopianbb641242010-05-18 17:06:55 -0700329 // NOTE: lcblk->resize() is protected by an internal lock
330 status_t err = lcblk->resize(bufferCount);
331 if (err == NO_ERROR)
332 mBufferManager.resize(bufferCount);
Mathias Agopianb5b7f262010-05-07 15:58:44 -0700333
334 return err;
335}
336
Mathias Agopiana138f892010-05-21 17:24:35 -0700337sp<GraphicBuffer> Layer::requestBuffer(int index,
338 uint32_t reqWidth, uint32_t reqHeight, uint32_t reqFormat,
339 uint32_t usage)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800340{
Mathias Agopian3330b202009-10-05 17:07:12 -0700341 sp<GraphicBuffer> buffer;
Mathias Agopian48d819a2009-09-10 19:41:18 -0700342
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700343 if (int32_t(reqWidth | reqHeight | reqFormat) < 0)
Mathias Agopiana138f892010-05-21 17:24:35 -0700344 return buffer;
345
346 if ((!reqWidth && reqHeight) || (reqWidth && !reqHeight))
347 return buffer;
348
Mathias Agopian48d819a2009-09-10 19:41:18 -0700349 // this ensures our client doesn't go away while we're accessing
350 // the shared area.
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700351 ClientRef::Access sharedClient(mUserClientRef);
352 SharedBufferServer* lcblk(sharedClient.get());
353 if (!lcblk) {
Mathias Agopian48d819a2009-09-10 19:41:18 -0700354 // oops, the client is already gone
355 return buffer;
356 }
357
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700358 /*
Mathias Agopiancbb288b2009-09-07 16:32:45 -0700359 * This is called from the client's Surface::dequeue(). This can happen
360 * at any time, especially while we're in the middle of using the
361 * buffer 'index' as our front buffer.
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700362 */
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800363
Mathias Agopian208cb072010-07-27 20:11:35 -0700364 status_t err = NO_ERROR;
Mathias Agopiana138f892010-05-21 17:24:35 -0700365 uint32_t w, h, f;
Mathias Agopian48d819a2009-09-10 19:41:18 -0700366 { // scope for the lock
367 Mutex::Autolock _l(mLock);
Mathias Agopianeff062c2010-08-25 14:59:15 -0700368
369 // zero means default
370 if (!reqFormat) reqFormat = mFormat;
371 if (!reqWidth) reqWidth = mWidth;
372 if (!reqHeight) reqHeight = mHeight;
373
374 w = reqWidth;
375 h = reqHeight;
376 f = reqFormat;
377
378 if ((reqWidth != mReqWidth) || (reqHeight != mReqHeight) ||
379 (reqFormat != mReqFormat)) {
380 mReqWidth = reqWidth;
381 mReqHeight = reqHeight;
382 mReqFormat = reqFormat;
383
Mathias Agopiana138f892010-05-21 17:24:35 -0700384 lcblk->reallocateAllExcept(index);
385 }
Mathias Agopian48d819a2009-09-10 19:41:18 -0700386 }
387
Mathias Agopian208cb072010-07-27 20:11:35 -0700388 // here we have to reallocate a new buffer because the buffer could be
389 // used as the front buffer, or by a client in our process
390 // (eg: status bar), and we can't release the handle under its feet.
Mathias Agopian3330b202009-10-05 17:07:12 -0700391 const uint32_t effectiveUsage = getEffectiveUsage(usage);
Mathias Agopian208cb072010-07-27 20:11:35 -0700392 buffer = new GraphicBuffer(w, h, f, effectiveUsage);
393 err = buffer->initCheck();
Mathias Agopiancbb288b2009-09-07 16:32:45 -0700394
395 if (err || buffer->handle == 0) {
396 LOGE_IF(err || buffer->handle == 0,
397 "Layer::requestBuffer(this=%p), index=%d, w=%d, h=%d failed (%s)",
398 this, index, w, h, strerror(-err));
399 } else {
400 LOGD_IF(DEBUG_RESIZE,
Mathias Agopian7e4a5872009-09-29 22:39:22 -0700401 "Layer::requestBuffer(this=%p), index=%d, w=%d, h=%d, handle=%p",
402 this, index, w, h, buffer->handle);
Mathias Agopiancbb288b2009-09-07 16:32:45 -0700403 }
404
405 if (err == NO_ERROR && buffer->handle != 0) {
Mathias Agopian48d819a2009-09-10 19:41:18 -0700406 Mutex::Autolock _l(mLock);
Mathias Agopiana138f892010-05-21 17:24:35 -0700407 mBufferManager.attachBuffer(index, buffer);
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700408 }
409 return buffer;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800410}
411
Mathias Agopian3330b202009-10-05 17:07:12 -0700412uint32_t Layer::getEffectiveUsage(uint32_t usage) const
413{
414 /*
415 * buffers used for software rendering, but h/w composition
416 * are allocated with SW_READ_OFTEN | SW_WRITE_OFTEN | HW_TEXTURE
417 *
418 * buffers used for h/w rendering and h/w composition
419 * are allocated with HW_RENDER | HW_TEXTURE
420 *
421 * buffers used with h/w rendering and either NPOT or no egl_image_ext
422 * are allocated with SW_READ_RARELY | HW_RENDER
423 *
424 */
425
426 if (mSecure) {
427 // secure buffer, don't store it into the GPU
428 usage = GraphicBuffer::USAGE_SW_READ_OFTEN |
429 GraphicBuffer::USAGE_SW_WRITE_OFTEN;
430 } else {
431 // it's allowed to modify the usage flags here, but generally
432 // the requested flags should be honored.
Mathias Agopian89141f92010-05-10 20:10:10 -0700433 // request EGLImage for all buffers
434 usage |= GraphicBuffer::USAGE_HW_TEXTURE;
Mathias Agopian3330b202009-10-05 17:07:12 -0700435 }
436 return usage;
437}
438
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800439uint32_t Layer::doTransaction(uint32_t flags)
440{
441 const Layer::State& front(drawingState());
442 const Layer::State& temp(currentState());
443
Mathias Agopiana138f892010-05-21 17:24:35 -0700444 const bool sizeChanged = (front.requested_w != temp.requested_w) ||
445 (front.requested_h != temp.requested_h);
446
447 if (sizeChanged) {
Mathias Agopiancbb288b2009-09-07 16:32:45 -0700448 // the size changed, we need to ask our client to request a new buffer
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800449 LOGD_IF(DEBUG_RESIZE,
Mathias Agopiana138f892010-05-21 17:24:35 -0700450 "resize (layer=%p), requested (%dx%d), drawing (%d,%d)",
451 this,
452 int(temp.requested_w), int(temp.requested_h),
453 int(front.requested_w), int(front.requested_h));
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800454
Mathias Agopiana138f892010-05-21 17:24:35 -0700455 if (!isFixedSize()) {
456 // we're being resized and there is a freeze display request,
457 // acquire a freeze lock, so that the screen stays put
458 // until we've redrawn at the new size; this is to avoid
459 // glitches upon orientation changes.
460 if (mFlinger->hasFreezeRequest()) {
461 // if the surface is hidden, don't try to acquire the
462 // freeze lock, since hidden surfaces may never redraw
463 if (!(front.flags & ISurfaceComposer::eLayerHidden)) {
464 mFreezeLock = mFlinger->getFreezeLock();
465 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800466 }
Mathias Agopiana138f892010-05-21 17:24:35 -0700467
468 // this will make sure LayerBase::doTransaction doesn't update
469 // the drawing state's size
470 Layer::State& editDraw(mDrawingState);
471 editDraw.requested_w = temp.requested_w;
472 editDraw.requested_h = temp.requested_h;
473
474 // record the new size, form this point on, when the client request
475 // a buffer, it'll get the new size.
476 setBufferSize(temp.requested_w, temp.requested_h);
477
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700478 ClientRef::Access sharedClient(mUserClientRef);
479 SharedBufferServer* lcblk(sharedClient.get());
480 if (lcblk) {
Mathias Agopian96f08192010-06-02 23:28:45 -0700481 // all buffers need reallocation
482 lcblk->reallocateAll();
483 }
Mathias Agopiana138f892010-05-21 17:24:35 -0700484 } else {
485 // record the new size
486 setBufferSize(temp.requested_w, temp.requested_h);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800487 }
488 }
Mathias Agopiancbb288b2009-09-07 16:32:45 -0700489
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800490 if (temp.sequence != front.sequence) {
491 if (temp.flags & ISurfaceComposer::eLayerHidden || temp.alpha == 0) {
492 // this surface is now hidden, so it shouldn't hold a freeze lock
493 // (it may never redraw, which is fine if it is hidden)
494 mFreezeLock.clear();
495 }
496 }
497
498 return LayerBase::doTransaction(flags);
499}
500
Mathias Agopiana138f892010-05-21 17:24:35 -0700501void Layer::setBufferSize(uint32_t w, uint32_t h) {
Mathias Agopiancbb288b2009-09-07 16:32:45 -0700502 Mutex::Autolock _l(mLock);
503 mWidth = w;
504 mHeight = h;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800505}
506
Mathias Agopiana138f892010-05-21 17:24:35 -0700507bool Layer::isFixedSize() const {
508 Mutex::Autolock _l(mLock);
509 return mFixedSize;
510}
511
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800512// ----------------------------------------------------------------------------
513// pageflip handling...
514// ----------------------------------------------------------------------------
515
516void Layer::lockPageFlip(bool& recomputeVisibleRegions)
517{
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700518 ClientRef::Access sharedClient(mUserClientRef);
519 SharedBufferServer* lcblk(sharedClient.get());
520 if (!lcblk) {
Mathias Agopian96f08192010-06-02 23:28:45 -0700521 // client died
522 recomputeVisibleRegions = true;
523 return;
524 }
525
Mathias Agopiancbb288b2009-09-07 16:32:45 -0700526 ssize_t buf = lcblk->retireAndLock();
Mathias Agopiand606de62010-05-10 20:06:11 -0700527 if (buf == NOT_ENOUGH_DATA) {
528 // NOTE: This is not an error, it simply means there is nothing to
529 // retire. The buffer is locked because we will use it
Mathias Agopiancbb288b2009-09-07 16:32:45 -0700530 // for composition later in the loop
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800531 return;
532 }
Mathias Agopiand343e3d2010-03-15 18:15:20 -0700533
Mathias Agopiand606de62010-05-10 20:06:11 -0700534 if (buf < NO_ERROR) {
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700535 LOGE("retireAndLock() buffer index (%d) out of range", int(buf));
Mathias Agopiand343e3d2010-03-15 18:15:20 -0700536 mPostedDirtyRegion.clear();
537 return;
538 }
539
Mathias Agopiancbb288b2009-09-07 16:32:45 -0700540 // we retired a buffer, which becomes the new front buffer
Mathias Agopiand606de62010-05-10 20:06:11 -0700541 if (mBufferManager.setActiveBufferIndex(buf) < NO_ERROR) {
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700542 LOGE("retireAndLock() buffer index (%d) out of range", int(buf));
Mathias Agopiand606de62010-05-10 20:06:11 -0700543 mPostedDirtyRegion.clear();
544 return;
545 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800546
Mathias Agopian3330b202009-10-05 17:07:12 -0700547 sp<GraphicBuffer> newFrontBuffer(getBuffer(buf));
Mathias Agopiand343e3d2010-03-15 18:15:20 -0700548 if (newFrontBuffer != NULL) {
Mathias Agopianb661d662010-08-19 17:01:19 -0700549 // get the dirty region
Mathias Agopiand343e3d2010-03-15 18:15:20 -0700550 // compute the posted region
551 const Region dirty(lcblk->getDirtyRegion(buf));
552 mPostedDirtyRegion = dirty.intersect( newFrontBuffer->getBounds() );
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700553
Mathias Agopiand343e3d2010-03-15 18:15:20 -0700554 // update the layer size and release freeze-lock
555 const Layer::State& front(drawingState());
556 if (newFrontBuffer->getWidth() == front.requested_w &&
557 newFrontBuffer->getHeight() == front.requested_h)
Mathias Agopiandf3e0b92009-09-30 14:07:22 -0700558 {
Mathias Agopiand343e3d2010-03-15 18:15:20 -0700559 if ((front.w != front.requested_w) ||
560 (front.h != front.requested_h))
561 {
562 // Here we pretend the transaction happened by updating the
563 // current and drawing states. Drawing state is only accessed
564 // in this thread, no need to have it locked
565 Layer::State& editDraw(mDrawingState);
566 editDraw.w = editDraw.requested_w;
567 editDraw.h = editDraw.requested_h;
Mathias Agopiandf3e0b92009-09-30 14:07:22 -0700568
Mathias Agopiand343e3d2010-03-15 18:15:20 -0700569 // We also need to update the current state so that we don't
570 // end-up doing too much work during the next transaction.
571 // NOTE: We actually don't need hold the transaction lock here
572 // because State::w and State::h are only accessed from
573 // this thread
574 Layer::State& editTemp(currentState());
575 editTemp.w = editDraw.w;
576 editTemp.h = editDraw.h;
Mathias Agopiandf3e0b92009-09-30 14:07:22 -0700577
Mathias Agopiand343e3d2010-03-15 18:15:20 -0700578 // recompute visible region
579 recomputeVisibleRegions = true;
580 }
581
582 // we now have the correct size, unfreeze the screen
583 mFreezeLock.clear();
Mathias Agopiandf3e0b92009-09-30 14:07:22 -0700584 }
Mathias Agopianb661d662010-08-19 17:01:19 -0700585
586 // get the crop region
587 setBufferCrop( lcblk->getCrop(buf) );
588
589 // get the transformation
590 setBufferTransform( lcblk->getTransform(buf) );
591
Mathias Agopiand343e3d2010-03-15 18:15:20 -0700592 } else {
593 // this should not happen unless we ran out of memory while
594 // allocating the buffer. we're hoping that things will get back
595 // to normal the next time the app tries to draw into this buffer.
596 // meanwhile, pretend the screen didn't update.
597 mPostedDirtyRegion.clear();
Mathias Agopiancaa600c2009-09-16 18:27:24 -0700598 }
599
Mathias Agopiane7005012009-10-07 16:44:10 -0700600 if (lcblk->getQueuedCount()) {
601 // signal an event if we have more buffers waiting
602 mFlinger->signalEvent();
603 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800604
Mathias Agopian245e4d72010-04-21 15:24:11 -0700605 /* a buffer was posted, so we need to call reloadTexture(), which
606 * will update our internal data structures (eg: EGLImageKHR or
607 * texture names). we need to do this even if mPostedDirtyRegion is
608 * empty -- it's orthogonal to the fact that a new buffer was posted,
609 * for instance, a degenerate case could be that the user did an empty
610 * update but repainted the buffer with appropriate content (after a
611 * resize for instance).
612 */
613 reloadTexture( mPostedDirtyRegion );
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800614}
615
616void Layer::unlockPageFlip(
617 const Transform& planeTransform, Region& outDirtyRegion)
618{
619 Region dirtyRegion(mPostedDirtyRegion);
620 if (!dirtyRegion.isEmpty()) {
621 mPostedDirtyRegion.clear();
622 // The dirty region is given in the layer's coordinate space
623 // transform the dirty region by the surface's transformation
624 // and the global transformation.
625 const Layer::State& s(drawingState());
626 const Transform tr(planeTransform * s.transform);
627 dirtyRegion = tr.transform(dirtyRegion);
628
629 // At this point, the dirty region is in screen space.
630 // Make sure it's constrained by the visible region (which
631 // is in screen space as well).
632 dirtyRegion.andSelf(visibleRegionScreen);
633 outDirtyRegion.orSelf(dirtyRegion);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800634 }
Mathias Agopianc61de172009-11-30 11:15:41 -0800635 if (visibleRegionScreen.isEmpty()) {
636 // an invisible layer should not hold a freeze-lock
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700637 // (because it may never be updated and therefore never release it)
Mathias Agopianc61de172009-11-30 11:15:41 -0800638 mFreezeLock.clear();
639 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800640}
641
642void Layer::finishPageFlip()
643{
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700644 ClientRef::Access sharedClient(mUserClientRef);
645 SharedBufferServer* lcblk(sharedClient.get());
646 if (lcblk) {
Mathias Agopian96f08192010-06-02 23:28:45 -0700647 int buf = mBufferManager.getActiveBufferIndex();
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700648 if (buf >= 0) {
649 status_t err = lcblk->unlock( buf );
650 LOGE_IF(err!=NO_ERROR,
651 "layer %p, buffer=%d wasn't locked!",
652 this, buf);
653 }
Mathias Agopian96f08192010-06-02 23:28:45 -0700654 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800655}
656
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700657
658void Layer::dump(String8& result, char* buffer, size_t SIZE) const
659{
660 LayerBaseClient::dump(result, buffer, SIZE);
661
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700662 ClientRef::Access sharedClient(mUserClientRef);
663 SharedBufferServer* lcblk(sharedClient.get());
664 uint32_t totalTime = 0;
665 if (lcblk) {
666 SharedBufferStack::Statistics stats = lcblk->getStats();
667 totalTime= stats.totalTime;
668 result.append( lcblk->dump(" ") );
669 }
670
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700671 sp<const GraphicBuffer> buf0(getBuffer(0));
672 sp<const GraphicBuffer> buf1(getBuffer(1));
673 uint32_t w0=0, h0=0, s0=0;
674 uint32_t w1=0, h1=0, s1=0;
675 if (buf0 != 0) {
676 w0 = buf0->getWidth();
677 h0 = buf0->getHeight();
678 s0 = buf0->getStride();
679 }
680 if (buf1 != 0) {
681 w1 = buf1->getWidth();
682 h1 = buf1->getHeight();
683 s1 = buf1->getStride();
684 }
685 snprintf(buffer, SIZE,
686 " "
687 "format=%2d, [%3ux%3u:%3u] [%3ux%3u:%3u],"
688 " freezeLock=%p, dq-q-time=%u us\n",
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700689 mFormat, w0, h0, s0, w1, h1, s1,
690 getFreezeLock().get(), totalTime);
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700691
692 result.append(buffer);
693}
694
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700695// ---------------------------------------------------------------------------
696
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700697Layer::ClientRef::ClientRef()
Mathias Agopian579b3f82010-06-08 19:54:15 -0700698 : mControlBlock(0), mToken(-1) {
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700699}
700
701Layer::ClientRef::~ClientRef() {
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700702}
703
704int32_t Layer::ClientRef::getToken() const {
705 Mutex::Autolock _l(mLock);
706 return mToken;
707}
708
Mathias Agopian579b3f82010-06-08 19:54:15 -0700709sp<UserClient> Layer::ClientRef::getClient() const {
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700710 Mutex::Autolock _l(mLock);
Mathias Agopian579b3f82010-06-08 19:54:15 -0700711 return mUserClient.promote();
712}
713
714status_t Layer::ClientRef::setToken(const sp<UserClient>& uc,
715 const sp<SharedBufferServer>& sharedClient, int32_t token) {
716 Mutex::Autolock _l(mLock);
717
718 { // scope for strong mUserClient reference
719 sp<UserClient> userClient(mUserClient.promote());
720 if (mUserClient != 0 && mControlBlock != 0) {
721 mControlBlock->setStatus(NO_INIT);
722 }
723 }
724
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700725 mUserClient = uc;
726 mToken = token;
Mathias Agopian579b3f82010-06-08 19:54:15 -0700727 mControlBlock = sharedClient;
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700728 return NO_ERROR;
729}
730
731sp<UserClient> Layer::ClientRef::getUserClientUnsafe() const {
732 return mUserClient.promote();
733}
734
735// this class gives us access to SharedBufferServer safely
736// it makes sure the UserClient (and its associated shared memory)
737// won't go away while we're accessing it.
738Layer::ClientRef::Access::Access(const ClientRef& ref)
Mathias Agopian579b3f82010-06-08 19:54:15 -0700739 : mControlBlock(0)
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700740{
741 Mutex::Autolock _l(ref.mLock);
742 mUserClientStrongRef = ref.mUserClient.promote();
743 if (mUserClientStrongRef != 0)
Mathias Agopian579b3f82010-06-08 19:54:15 -0700744 mControlBlock = ref.mControlBlock;
745}
746
747Layer::ClientRef::Access::~Access()
748{
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700749}
750
751// ---------------------------------------------------------------------------
752
Mathias Agopiand606de62010-05-10 20:06:11 -0700753Layer::BufferManager::BufferManager(TextureManager& tm)
Mathias Agopianbb641242010-05-18 17:06:55 -0700754 : mNumBuffers(NUM_BUFFERS), mTextureManager(tm),
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700755 mActiveBuffer(-1), mFailover(false)
Mathias Agopiand606de62010-05-10 20:06:11 -0700756{
757}
758
Mathias Agopianbb641242010-05-18 17:06:55 -0700759Layer::BufferManager::~BufferManager()
760{
761}
762
763status_t Layer::BufferManager::resize(size_t size)
764{
765 Mutex::Autolock _l(mLock);
766 mNumBuffers = size;
767 return NO_ERROR;
Mathias Agopiand606de62010-05-10 20:06:11 -0700768}
769
770// only for debugging
771sp<GraphicBuffer> Layer::BufferManager::getBuffer(size_t index) const {
772 return mBufferData[index].buffer;
773}
774
775status_t Layer::BufferManager::setActiveBufferIndex(size_t index) {
Mathias Agopiand606de62010-05-10 20:06:11 -0700776 mActiveBuffer = index;
777 return NO_ERROR;
778}
779
780size_t Layer::BufferManager::getActiveBufferIndex() const {
781 return mActiveBuffer;
782}
783
784Texture Layer::BufferManager::getActiveTexture() const {
Mathias Agopianbb641242010-05-18 17:06:55 -0700785 Texture res;
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700786 if (mFailover || mActiveBuffer<0) {
Mathias Agopianbb641242010-05-18 17:06:55 -0700787 res = mFailoverTexture;
788 } else {
789 static_cast<Image&>(res) = mBufferData[mActiveBuffer].texture;
790 }
791 return res;
Mathias Agopiand606de62010-05-10 20:06:11 -0700792}
793
794sp<GraphicBuffer> Layer::BufferManager::getActiveBuffer() const {
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700795 sp<GraphicBuffer> result;
796 const ssize_t activeBuffer = mActiveBuffer;
797 if (activeBuffer >= 0) {
798 BufferData const * const buffers = mBufferData;
799 Mutex::Autolock _l(mLock);
800 result = buffers[activeBuffer].buffer;
801 }
802 return result;
Mathias Agopiand606de62010-05-10 20:06:11 -0700803}
804
805sp<GraphicBuffer> Layer::BufferManager::detachBuffer(size_t index)
806{
Mathias Agopianbb641242010-05-18 17:06:55 -0700807 BufferData* const buffers = mBufferData;
Mathias Agopiand606de62010-05-10 20:06:11 -0700808 sp<GraphicBuffer> buffer;
809 Mutex::Autolock _l(mLock);
Mathias Agopianbb641242010-05-18 17:06:55 -0700810 buffer = buffers[index].buffer;
811 buffers[index].buffer = 0;
Mathias Agopiand606de62010-05-10 20:06:11 -0700812 return buffer;
813}
814
815status_t Layer::BufferManager::attachBuffer(size_t index,
816 const sp<GraphicBuffer>& buffer)
817{
Mathias Agopianbb641242010-05-18 17:06:55 -0700818 BufferData* const buffers = mBufferData;
Mathias Agopiand606de62010-05-10 20:06:11 -0700819 Mutex::Autolock _l(mLock);
Mathias Agopianbb641242010-05-18 17:06:55 -0700820 buffers[index].buffer = buffer;
821 buffers[index].texture.dirty = true;
Mathias Agopiand606de62010-05-10 20:06:11 -0700822 return NO_ERROR;
823}
824
825status_t Layer::BufferManager::destroy(EGLDisplay dpy)
826{
Mathias Agopianbb641242010-05-18 17:06:55 -0700827 BufferData* const buffers = mBufferData;
828 size_t num;
829 { // scope for the lock
830 Mutex::Autolock _l(mLock);
831 num = mNumBuffers;
832 for (size_t i=0 ; i<num ; i++) {
833 buffers[i].buffer = 0;
834 }
835 }
836 for (size_t i=0 ; i<num ; i++) {
837 destroyTexture(&buffers[i].texture, dpy);
Mathias Agopiand606de62010-05-10 20:06:11 -0700838 }
839 destroyTexture(&mFailoverTexture, dpy);
840 return NO_ERROR;
841}
842
843status_t Layer::BufferManager::initEglImage(EGLDisplay dpy,
844 const sp<GraphicBuffer>& buffer)
845{
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700846 status_t err = NO_INIT;
847 ssize_t index = mActiveBuffer;
848 if (index >= 0) {
Mathias Agopian1f7bec62010-06-25 18:02:21 -0700849 if (!mFailover) {
850 Image& texture(mBufferData[index].texture);
851 err = mTextureManager.initEglImage(&texture, dpy, buffer);
852 // if EGLImage fails, we switch to regular texture mode, and we
853 // free all resources associated with using EGLImages.
854 if (err == NO_ERROR) {
855 mFailover = false;
856 destroyTexture(&mFailoverTexture, dpy);
857 } else {
858 mFailover = true;
859 const size_t num = mNumBuffers;
860 for (size_t i=0 ; i<num ; i++) {
861 destroyTexture(&mBufferData[i].texture, dpy);
862 }
Andreas Hubere049a952010-06-25 09:25:19 -0700863 }
Mathias Agopian1f7bec62010-06-25 18:02:21 -0700864 } else {
865 // we failed once, don't try again
866 err = BAD_VALUE;
Mathias Agopiand606de62010-05-10 20:06:11 -0700867 }
868 }
869 return err;
870}
871
872status_t Layer::BufferManager::loadTexture(
873 const Region& dirty, const GGLSurface& t)
874{
875 return mTextureManager.loadTexture(&mFailoverTexture, dirty, t);
876}
877
Mathias Agopianbb641242010-05-18 17:06:55 -0700878status_t Layer::BufferManager::destroyTexture(Image* tex, EGLDisplay dpy)
879{
880 if (tex->name != -1U) {
881 glDeleteTextures(1, &tex->name);
882 tex->name = -1U;
883 }
884 if (tex->image != EGL_NO_IMAGE_KHR) {
885 eglDestroyImageKHR(dpy, tex->image);
886 tex->image = EGL_NO_IMAGE_KHR;
887 }
888 return NO_ERROR;
889}
890
Mathias Agopiand606de62010-05-10 20:06:11 -0700891// ---------------------------------------------------------------------------
892
Mathias Agopian9a112062009-04-17 19:36:26 -0700893Layer::SurfaceLayer::SurfaceLayer(const sp<SurfaceFlinger>& flinger,
Mathias Agopian96f08192010-06-02 23:28:45 -0700894 const sp<Layer>& owner)
895 : Surface(flinger, owner->getIdentity(), owner)
Mathias Agopian9a112062009-04-17 19:36:26 -0700896{
897}
898
899Layer::SurfaceLayer::~SurfaceLayer()
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700900{
901}
902
Mathias Agopiana138f892010-05-21 17:24:35 -0700903sp<GraphicBuffer> Layer::SurfaceLayer::requestBuffer(int index,
904 uint32_t w, uint32_t h, uint32_t format, uint32_t usage)
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700905{
Mathias Agopian3330b202009-10-05 17:07:12 -0700906 sp<GraphicBuffer> buffer;
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700907 sp<Layer> owner(getOwner());
908 if (owner != 0) {
Mathias Agopianbb641242010-05-18 17:06:55 -0700909 /*
910 * requestBuffer() cannot be called from the main thread
911 * as it could cause a dead-lock, since it may have to wait
912 * on conditions updated my the main thread.
913 */
Mathias Agopiana138f892010-05-21 17:24:35 -0700914 buffer = owner->requestBuffer(index, w, h, format, usage);
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700915 }
916 return buffer;
917}
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800918
Mathias Agopianb5b7f262010-05-07 15:58:44 -0700919status_t Layer::SurfaceLayer::setBufferCount(int bufferCount)
920{
921 status_t err = DEAD_OBJECT;
922 sp<Layer> owner(getOwner());
923 if (owner != 0) {
Mathias Agopianbb641242010-05-18 17:06:55 -0700924 /*
925 * setBufferCount() cannot be called from the main thread
926 * as it could cause a dead-lock, since it may have to wait
927 * on conditions updated my the main thread.
928 */
Mathias Agopianb5b7f262010-05-07 15:58:44 -0700929 err = owner->setBufferCount(bufferCount);
930 }
931 return err;
932}
933
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800934// ---------------------------------------------------------------------------
935
936
937}; // namespace android