blob: e3cf27e0ffd93ad3a41ac8ebf2eb4ea6803aa856 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2007 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
The Android Open Source Project9066cfe2009-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 Agopian1473f462009-04-10 14:24:30 -070022#include <cutils/native_handle.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080023
24#include <utils/Errors.h>
25#include <utils/Log.h>
26#include <utils/StopWatch.h>
27
Mathias Agopian6950e422009-10-05 17:07:12 -070028#include <ui/GraphicBuffer.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080029#include <ui/PixelFormat.h>
Mathias Agopian000479f2010-02-09 17:46:37 -080030
31#include <surfaceflinger/Surface.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080032
33#include "clz.h"
Mathias Agopian781953d2010-06-25 18:02:21 -070034#include "GLExtensions.h"
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080035#include "Layer.h"
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080036#include "SurfaceFlinger.h"
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080037#include "DisplayHardware/DisplayHardware.h"
38
39
40#define DEBUG_RESIZE 0
41
42
43namespace android {
44
Mathias Agopian967dce32010-04-14 16:43:44 -070045template <typename T> inline T min(T a, T b) {
46 return a<b ? a : b;
47}
48
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080049// ---------------------------------------------------------------------------
50
Mathias Agopian593c05c2010-06-02 23:28:45 -070051Layer::Layer(SurfaceFlinger* flinger,
52 DisplayID display, const sp<Client>& client)
53 : LayerBaseClient(flinger, display, client),
Mathias Agopian781953d2010-06-25 18:02:21 -070054 mGLExtensions(GLExtensions::getInstance()),
Mathias Agopiancc934762009-09-23 19:16:27 -070055 mNeedsBlending(true),
Mathias Agopian9f2c4fd2010-05-10 20:06:11 -070056 mNeedsDithering(false),
Mathias Agopian7623da42010-06-01 15:12:58 -070057 mSecure(false),
Mathias Agopian781953d2010-06-25 18:02:21 -070058 mTextureManager(),
Mathias Agopian2be352a2010-05-21 17:24:35 -070059 mBufferManager(mTextureManager),
Mathias Agopian025005f2010-11-01 23:32:18 -070060 mWidth(0), mHeight(0), mNeedsScaling(false), mFixedSize(false),
61 mBypassState(false)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080062{
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080063}
64
65Layer::~Layer()
66{
Mathias Agopian898c4c92010-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 Agopian7623da42010-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 Agopian9f2c4fd2010-05-10 20:06:11 -070077}
78
Mathias Agopian7623da42010-06-01 15:12:58 -070079status_t Layer::setToken(const sp<UserClient>& userClient,
80 SharedClient* sharedClient, int32_t token)
Mathias Agopian593c05c2010-06-02 23:28:45 -070081{
Mathias Agopian5e140102010-06-08 19:54:15 -070082 sp<SharedBufferServer> lcblk = new SharedBufferServer(
Mathias Agopian7623da42010-06-01 15:12:58 -070083 sharedClient, token, mBufferManager.getDefaultBufferCount(),
Mathias Agopian593c05c2010-06-02 23:28:45 -070084 getIdentity());
85
Mathias Agopian7623da42010-06-01 15:12:58 -070086 status_t err = mUserClientRef.setToken(userClient, lcblk, token);
Mathias Agopian5e140102010-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 Agopian7623da42010-06-01 15:12:58 -070094 }
95
96 return err;
97}
98
99int32_t Layer::getToken() const
100{
101 return mUserClientRef.getToken();
Mathias Agopian593c05c2010-06-02 23:28:45 -0700102}
103
Mathias Agopian5e140102010-06-08 19:54:15 -0700104sp<UserClient> Layer::getClient() const
105{
106 return mUserClientRef.getClient();
107}
108
Mathias Agopian9f2c4fd2010-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 Agopian7623da42010-06-01 15:12:58 -0700113 ClientRef::Access sharedClient(mUserClientRef);
114 SharedBufferServer* lcblk(sharedClient.get());
115 if (lcblk) {
Mathias Agopian593c05c2010-06-02 23:28:45 -0700116 // wake up the condition
117 lcblk->setStatus(NO_INIT);
118 }
Mathias Agopian248b5bd2009-09-10 19:41:18 -0700119}
Mathias Agopian9779b2212009-09-07 16:32:45 -0700120
Mathias Agopian1473f462009-04-10 14:24:30 -0700121sp<LayerBaseClient::Surface> Layer::createSurface() const
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800122{
Mathias Agopian951d3fe2011-02-09 18:38:55 -0800123 sp<Surface> sur(new SurfaceLayer(mFlinger, const_cast<Layer *>(this)));
124 return sur;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800125}
126
Mathias Agopian6cf0db22009-04-17 19:36:26 -0700127status_t Layer::ditch()
128{
Mathias Agopian898c4c92010-05-18 17:06:55 -0700129 // NOTE: Called from the main UI thread
130
Mathias Agopiana3aa6c92009-04-22 15:23:34 -0700131 // the layer is not on screen anymore. free as much resources as possible
Mathias Agopianf9b0e822009-12-11 00:56:10 -0800132 mFreezeLock.clear();
Mathias Agopian898c4c92010-05-18 17:06:55 -0700133
Mathias Agopian898c4c92010-05-18 17:06:55 -0700134 Mutex::Autolock _l(mLock);
135 mWidth = mHeight = 0;
Mathias Agopian6cf0db22009-04-17 19:36:26 -0700136 return NO_ERROR;
137}
138
Mathias Agopian6edf5af2009-06-19 17:00:27 -0700139status_t Layer::setBuffers( uint32_t w, uint32_t h,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800140 PixelFormat format, uint32_t flags)
141{
Mathias Agopiancc934762009-09-23 19:16:27 -0700142 // this surfaces pixel format
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800143 PixelFormatInfo info;
144 status_t err = getPixelFormatInfo(format, &info);
145 if (err) return err;
146
Mathias Agopiancc934762009-09-23 19:16:27 -0700147 // the display's pixel format
148 const DisplayHardware& hw(graphicPlane(0).displayHardware());
Mathias Agopian967dce32010-04-14 16:43:44 -0700149 uint32_t const maxSurfaceDims = min(
150 hw.getMaxTextureSize(), hw.getMaxViewportDims());
151
152 // never allow a surface larger than what our underlying GL implementation
153 // can handle.
154 if ((uint32_t(w)>maxSurfaceDims) || (uint32_t(h)>maxSurfaceDims)) {
155 return BAD_VALUE;
156 }
157
Mathias Agopiancc934762009-09-23 19:16:27 -0700158 PixelFormatInfo displayInfo;
159 getPixelFormatInfo(hw.getFormat(), &displayInfo);
Mathias Agopian351a7072009-10-05 18:20:39 -0700160 const uint32_t hwFlags = hw.getFlags();
161
Mathias Agopian9779b2212009-09-07 16:32:45 -0700162 mFormat = format;
Mathias Agopian967dce32010-04-14 16:43:44 -0700163 mWidth = w;
Mathias Agopian9779b2212009-09-07 16:32:45 -0700164 mHeight = h;
Mathias Agopianc51114f2010-08-25 14:59:15 -0700165
166 mReqFormat = format;
167 mReqWidth = w;
168 mReqHeight = h;
169
Mathias Agopian6950e422009-10-05 17:07:12 -0700170 mSecure = (flags & ISurfaceComposer::eSecure) ? true : false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800171 mNeedsBlending = (info.h_alpha - info.l_alpha) > 0;
Mathias Agopian967dce32010-04-14 16:43:44 -0700172
Mathias Agopiancc934762009-09-23 19:16:27 -0700173 // we use the red index
174 int displayRedSize = displayInfo.getSize(PixelFormatInfo::INDEX_RED);
175 int layerRedsize = info.getSize(PixelFormatInfo::INDEX_RED);
176 mNeedsDithering = layerRedsize > displayRedSize;
177
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800178 return NO_ERROR;
179}
180
181void Layer::reloadTexture(const Region& dirty)
182{
Mathias Agopian9f2c4fd2010-05-10 20:06:11 -0700183 sp<GraphicBuffer> buffer(mBufferManager.getActiveBuffer());
Mathias Agopian083a557c2009-12-10 15:52:29 -0800184 if (buffer == NULL) {
185 // this situation can happen if we ran out of memory for instance.
186 // not much we can do. continue to use whatever texture was bound
187 // to this context.
188 return;
189 }
190
Mathias Agopian781953d2010-06-25 18:02:21 -0700191 if (mGLExtensions.haveDirectTexture()) {
Mathias Agopian9f2c4fd2010-05-10 20:06:11 -0700192 EGLDisplay dpy(mFlinger->graphicPlane(0).getEGLDisplay());
193 if (mBufferManager.initEglImage(dpy, buffer) != NO_ERROR) {
194 // not sure what we can do here...
Mathias Agopian9f2c4fd2010-05-10 20:06:11 -0700195 goto slowpath;
Mathias Agopian1473f462009-04-10 14:24:30 -0700196 }
Mathias Agopian781953d2010-06-25 18:02:21 -0700197 } else {
Mathias Agopian1d211f82010-03-08 11:14:20 -0800198slowpath:
Mathias Agopian1473f462009-04-10 14:24:30 -0700199 GGLSurface t;
Mathias Agopianc817b222010-08-20 15:59:53 -0700200 if (buffer->usage & GRALLOC_USAGE_SW_READ_MASK) {
201 status_t res = buffer->lock(&t, GRALLOC_USAGE_SW_READ_OFTEN);
202 LOGE_IF(res, "error %d (%s) locking buffer %p",
203 res, strerror(res), buffer.get());
204 if (res == NO_ERROR) {
205 mBufferManager.loadTexture(dirty, t);
206 buffer->unlock();
207 }
208 } else {
209 // we can't do anything
Mathias Agopian1473f462009-04-10 14:24:30 -0700210 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800211 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800212}
213
Mathias Agopian597c7f62010-09-29 13:02:36 -0700214void Layer::drawForSreenShot() const
215{
Mathias Agopian1989af22010-12-02 21:32:29 -0800216 const bool currentFiltering = mNeedsFiltering;
217 const_cast<Layer*>(this)->mNeedsFiltering = true;
Mathias Agopian597c7f62010-09-29 13:02:36 -0700218 LayerBase::drawForSreenShot();
Mathias Agopian1989af22010-12-02 21:32:29 -0800219 const_cast<Layer*>(this)->mNeedsFiltering = currentFiltering;
Mathias Agopian597c7f62010-09-29 13:02:36 -0700220}
221
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800222void Layer::onDraw(const Region& clip) const
223{
Mathias Agopian9f2c4fd2010-05-10 20:06:11 -0700224 Texture tex(mBufferManager.getActiveTexture());
225 if (tex.name == -1LU) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800226 // the texture has not been created yet, this Layer has
Mathias Agopian2df6f512010-05-06 20:21:45 -0700227 // in fact never been drawn into. This happens frequently with
228 // SurfaceView because the WindowManager can't know when the client
229 // has drawn the first time.
230
231 // If there is nothing under us, we paint the screen in black, otherwise
232 // we just skip this update.
233
234 // figure out if there is something below us
235 Region under;
236 const SurfaceFlinger::LayerVector& drawingLayers(mFlinger->mDrawingState.layersSortedByZ);
237 const size_t count = drawingLayers.size();
238 for (size_t i=0 ; i<count ; ++i) {
239 const sp<LayerBase>& layer(drawingLayers[i]);
240 if (layer.get() == static_cast<LayerBase const*>(this))
241 break;
242 under.orSelf(layer->visibleRegionScreen);
243 }
244 // if not everything below us is covered, we plug the holes!
245 Region holes(clip.subtract(under));
246 if (!holes.isEmpty()) {
Mathias Agopianf8b4b442010-06-14 21:20:00 -0700247 clearWithOpenGL(holes, 0, 0, 0, 1);
Mathias Agopian2df6f512010-05-06 20:21:45 -0700248 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800249 return;
250 }
Mathias Agopian025005f2010-11-01 23:32:18 -0700251
252#ifdef USE_COMPOSITION_BYPASS
253 sp<GraphicBuffer> buffer(mBufferManager.getActiveBuffer());
254 if ((buffer != NULL) && (buffer->transform)) {
255 // Here we have a "bypass" buffer, but we need to composite it
256 // most likely because it's not fullscreen anymore.
257 // Since the buffer may have a transformation applied by the client
258 // we need to inverse this transformation here.
259
260 // calculate the inverse of the buffer transform
261 const uint32_t mask = HAL_TRANSFORM_FLIP_V | HAL_TRANSFORM_FLIP_H;
262 const uint32_t bufferTransformInverse = buffer->transform ^ mask;
263
264 // To accomplish the inverse transform, we use "mBufferTransform"
265 // which is not used by Layer.cpp
266 const_cast<Layer*>(this)->mBufferTransform = bufferTransformInverse;
267 drawWithOpenGL(clip, tex);
268 // reset to "no transfrom"
269 const_cast<Layer*>(this)->mBufferTransform = 0;
270 return;
271 }
272#endif
273
Mathias Agopian9f2c4fd2010-05-10 20:06:11 -0700274 drawWithOpenGL(clip, tex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800275}
276
Mathias Agopian92377032010-05-26 22:08:52 -0700277bool Layer::needsFiltering() const
278{
279 if (!(mFlags & DisplayHardware::SLOW_CONFIG)) {
Mathias Agopian1989af22010-12-02 21:32:29 -0800280 // if our buffer is not the same size than ourselves,
281 // we need filtering.
282 Mutex::Autolock _l(mLock);
283 if (mNeedsScaling)
Mathias Agopian92377032010-05-26 22:08:52 -0700284 return true;
285 }
286 return LayerBase::needsFiltering();
287}
288
Mathias Agopian59751db2010-05-07 15:58:44 -0700289
290status_t Layer::setBufferCount(int bufferCount)
291{
Mathias Agopian7623da42010-06-01 15:12:58 -0700292 ClientRef::Access sharedClient(mUserClientRef);
293 SharedBufferServer* lcblk(sharedClient.get());
294 if (!lcblk) {
Mathias Agopian59751db2010-05-07 15:58:44 -0700295 // oops, the client is already gone
296 return DEAD_OBJECT;
297 }
298
Mathias Agopian898c4c92010-05-18 17:06:55 -0700299 // NOTE: lcblk->resize() is protected by an internal lock
300 status_t err = lcblk->resize(bufferCount);
301 if (err == NO_ERROR)
302 mBufferManager.resize(bufferCount);
Mathias Agopian59751db2010-05-07 15:58:44 -0700303
304 return err;
305}
306
Mathias Agopian2be352a2010-05-21 17:24:35 -0700307sp<GraphicBuffer> Layer::requestBuffer(int index,
308 uint32_t reqWidth, uint32_t reqHeight, uint32_t reqFormat,
309 uint32_t usage)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800310{
Mathias Agopian6950e422009-10-05 17:07:12 -0700311 sp<GraphicBuffer> buffer;
Mathias Agopian248b5bd2009-09-10 19:41:18 -0700312
Mathias Agopian7623da42010-06-01 15:12:58 -0700313 if (int32_t(reqWidth | reqHeight | reqFormat) < 0)
Mathias Agopian2be352a2010-05-21 17:24:35 -0700314 return buffer;
315
316 if ((!reqWidth && reqHeight) || (reqWidth && !reqHeight))
317 return buffer;
318
Mathias Agopian248b5bd2009-09-10 19:41:18 -0700319 // this ensures our client doesn't go away while we're accessing
320 // the shared area.
Mathias Agopian7623da42010-06-01 15:12:58 -0700321 ClientRef::Access sharedClient(mUserClientRef);
322 SharedBufferServer* lcblk(sharedClient.get());
323 if (!lcblk) {
Mathias Agopian248b5bd2009-09-10 19:41:18 -0700324 // oops, the client is already gone
325 return buffer;
326 }
327
Mathias Agopian1473f462009-04-10 14:24:30 -0700328 /*
Mathias Agopian9779b2212009-09-07 16:32:45 -0700329 * This is called from the client's Surface::dequeue(). This can happen
330 * at any time, especially while we're in the middle of using the
331 * buffer 'index' as our front buffer.
Mathias Agopian1473f462009-04-10 14:24:30 -0700332 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800333
Mathias Agopian025005f2010-11-01 23:32:18 -0700334 uint32_t w, h, f, bypass;
Mathias Agopian248b5bd2009-09-10 19:41:18 -0700335 { // scope for the lock
336 Mutex::Autolock _l(mLock);
Mathias Agopianc51114f2010-08-25 14:59:15 -0700337
Mathias Agopian025005f2010-11-01 23:32:18 -0700338 bypass = mBypassState;
339
Mathias Agopianc51114f2010-08-25 14:59:15 -0700340 // zero means default
Mathias Agopian1989af22010-12-02 21:32:29 -0800341 mFixedSize = reqWidth && reqHeight;
Mathias Agopianc51114f2010-08-25 14:59:15 -0700342 if (!reqFormat) reqFormat = mFormat;
343 if (!reqWidth) reqWidth = mWidth;
344 if (!reqHeight) reqHeight = mHeight;
345
346 w = reqWidth;
347 h = reqHeight;
348 f = reqFormat;
349
350 if ((reqWidth != mReqWidth) || (reqHeight != mReqHeight) ||
351 (reqFormat != mReqFormat)) {
352 mReqWidth = reqWidth;
353 mReqHeight = reqHeight;
354 mReqFormat = reqFormat;
Mathias Agopian1989af22010-12-02 21:32:29 -0800355 mNeedsScaling = mWidth != mReqWidth || mHeight != mReqHeight;
Mathias Agopianc51114f2010-08-25 14:59:15 -0700356
Mathias Agopian2be352a2010-05-21 17:24:35 -0700357 lcblk->reallocateAllExcept(index);
358 }
Mathias Agopian248b5bd2009-09-10 19:41:18 -0700359 }
360
Mathias Agopian51c70e32010-07-27 20:11:35 -0700361 // here we have to reallocate a new buffer because the buffer could be
362 // used as the front buffer, or by a client in our process
363 // (eg: status bar), and we can't release the handle under its feet.
Mathias Agopian025005f2010-11-01 23:32:18 -0700364 uint32_t effectiveUsage = getEffectiveUsage(usage);
365
366 status_t err = NO_MEMORY;
367
368#ifdef USE_COMPOSITION_BYPASS
369 if (!mSecure && bypass && (effectiveUsage & GRALLOC_USAGE_HW_RENDER)) {
370 // always allocate a buffer matching the screen size. the size
371 // may be different from (w,h) if the buffer is rotated.
372 const DisplayHardware& hw(graphicPlane(0).displayHardware());
373 int32_t w = hw.getWidth();
374 int32_t h = hw.getHeight();
375 int32_t f = hw.getFormat();
376
377 buffer = new GraphicBuffer(w, h, f, effectiveUsage | GRALLOC_USAGE_HW_FB);
378 err = buffer->initCheck();
379 buffer->transform = uint8_t(getOrientation());
380
381 if (err != NO_ERROR) {
382 // allocation didn't succeed, probably because an older bypass
383 // window hasn't released all its resources yet.
384 ClientRef::Access sharedClient(mUserClientRef);
385 SharedBufferServer* lcblk(sharedClient.get());
386 if (lcblk) {
387 // all buffers need reallocation
388 lcblk->reallocateAll();
389 }
390 }
391 }
392#endif
393
394 if (err != NO_ERROR) {
395 buffer = new GraphicBuffer(w, h, f, effectiveUsage);
396 err = buffer->initCheck();
397 }
Mathias Agopian9779b2212009-09-07 16:32:45 -0700398
399 if (err || buffer->handle == 0) {
Mathias Agopiane869aee2010-12-03 17:33:09 -0800400 GraphicBuffer::dumpAllocationsToSystemLog();
Mathias Agopian9779b2212009-09-07 16:32:45 -0700401 LOGE_IF(err || buffer->handle == 0,
402 "Layer::requestBuffer(this=%p), index=%d, w=%d, h=%d failed (%s)",
403 this, index, w, h, strerror(-err));
404 } else {
405 LOGD_IF(DEBUG_RESIZE,
Mathias Agopiane1b6f242009-09-29 22:39:22 -0700406 "Layer::requestBuffer(this=%p), index=%d, w=%d, h=%d, handle=%p",
407 this, index, w, h, buffer->handle);
Mathias Agopian9779b2212009-09-07 16:32:45 -0700408 }
409
410 if (err == NO_ERROR && buffer->handle != 0) {
Mathias Agopian248b5bd2009-09-10 19:41:18 -0700411 Mutex::Autolock _l(mLock);
Mathias Agopian2be352a2010-05-21 17:24:35 -0700412 mBufferManager.attachBuffer(index, buffer);
Mathias Agopian1473f462009-04-10 14:24:30 -0700413 }
414 return buffer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800415}
416
Mathias Agopian6950e422009-10-05 17:07:12 -0700417uint32_t Layer::getEffectiveUsage(uint32_t usage) const
418{
419 /*
420 * buffers used for software rendering, but h/w composition
421 * are allocated with SW_READ_OFTEN | SW_WRITE_OFTEN | HW_TEXTURE
422 *
423 * buffers used for h/w rendering and h/w composition
424 * are allocated with HW_RENDER | HW_TEXTURE
425 *
426 * buffers used with h/w rendering and either NPOT or no egl_image_ext
427 * are allocated with SW_READ_RARELY | HW_RENDER
428 *
429 */
430
431 if (mSecure) {
432 // secure buffer, don't store it into the GPU
433 usage = GraphicBuffer::USAGE_SW_READ_OFTEN |
434 GraphicBuffer::USAGE_SW_WRITE_OFTEN;
435 } else {
436 // it's allowed to modify the usage flags here, but generally
437 // the requested flags should be honored.
Mathias Agopianaca2ee82010-05-10 20:10:10 -0700438 // request EGLImage for all buffers
439 usage |= GraphicBuffer::USAGE_HW_TEXTURE;
Mathias Agopian6950e422009-10-05 17:07:12 -0700440 }
441 return usage;
442}
443
Mathias Agopian025005f2010-11-01 23:32:18 -0700444bool Layer::setBypass(bool enable)
445{
446 Mutex::Autolock _l(mLock);
447
448 if (mNeedsScaling || mNeedsFiltering) {
449 return false;
450 }
451
452 if (mBypassState != enable) {
453 mBypassState = enable;
454 ClientRef::Access sharedClient(mUserClientRef);
455 SharedBufferServer* lcblk(sharedClient.get());
456 if (lcblk) {
457 // all buffers need reallocation
458 lcblk->reallocateAll();
459 }
460 }
461
462 return true;
463}
464
Mathias Agopianee5a3aca2010-12-07 21:00:25 -0800465void Layer::updateBuffersOrientation()
466{
467 sp<GraphicBuffer> buffer(getBypassBuffer());
468 if (buffer != NULL && mOrientation != buffer->transform) {
469 ClientRef::Access sharedClient(mUserClientRef);
470 SharedBufferServer* lcblk(sharedClient.get());
471 if (lcblk) { // all buffers need reallocation
472 lcblk->reallocateAll();
473 }
474 }
475}
476
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800477uint32_t Layer::doTransaction(uint32_t flags)
478{
479 const Layer::State& front(drawingState());
480 const Layer::State& temp(currentState());
481
Mathias Agopian2be352a2010-05-21 17:24:35 -0700482 const bool sizeChanged = (front.requested_w != temp.requested_w) ||
483 (front.requested_h != temp.requested_h);
484
485 if (sizeChanged) {
Mathias Agopian9779b2212009-09-07 16:32:45 -0700486 // the size changed, we need to ask our client to request a new buffer
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800487 LOGD_IF(DEBUG_RESIZE,
Mathias Agopian2be352a2010-05-21 17:24:35 -0700488 "resize (layer=%p), requested (%dx%d), drawing (%d,%d)",
489 this,
490 int(temp.requested_w), int(temp.requested_h),
491 int(front.requested_w), int(front.requested_h));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800492
Mathias Agopian2be352a2010-05-21 17:24:35 -0700493 if (!isFixedSize()) {
494 // we're being resized and there is a freeze display request,
495 // acquire a freeze lock, so that the screen stays put
496 // until we've redrawn at the new size; this is to avoid
497 // glitches upon orientation changes.
498 if (mFlinger->hasFreezeRequest()) {
499 // if the surface is hidden, don't try to acquire the
500 // freeze lock, since hidden surfaces may never redraw
501 if (!(front.flags & ISurfaceComposer::eLayerHidden)) {
502 mFreezeLock = mFlinger->getFreezeLock();
503 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800504 }
Mathias Agopian2be352a2010-05-21 17:24:35 -0700505
506 // this will make sure LayerBase::doTransaction doesn't update
507 // the drawing state's size
508 Layer::State& editDraw(mDrawingState);
509 editDraw.requested_w = temp.requested_w;
510 editDraw.requested_h = temp.requested_h;
511
512 // record the new size, form this point on, when the client request
513 // a buffer, it'll get the new size.
514 setBufferSize(temp.requested_w, temp.requested_h);
515
Mathias Agopian7623da42010-06-01 15:12:58 -0700516 ClientRef::Access sharedClient(mUserClientRef);
517 SharedBufferServer* lcblk(sharedClient.get());
518 if (lcblk) {
Mathias Agopian593c05c2010-06-02 23:28:45 -0700519 // all buffers need reallocation
520 lcblk->reallocateAll();
521 }
Mathias Agopian2be352a2010-05-21 17:24:35 -0700522 } else {
523 // record the new size
524 setBufferSize(temp.requested_w, temp.requested_h);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800525 }
526 }
Mathias Agopian9779b2212009-09-07 16:32:45 -0700527
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800528 if (temp.sequence != front.sequence) {
529 if (temp.flags & ISurfaceComposer::eLayerHidden || temp.alpha == 0) {
530 // this surface is now hidden, so it shouldn't hold a freeze lock
531 // (it may never redraw, which is fine if it is hidden)
532 mFreezeLock.clear();
533 }
534 }
535
536 return LayerBase::doTransaction(flags);
537}
538
Mathias Agopian2be352a2010-05-21 17:24:35 -0700539void Layer::setBufferSize(uint32_t w, uint32_t h) {
Mathias Agopian9779b2212009-09-07 16:32:45 -0700540 Mutex::Autolock _l(mLock);
541 mWidth = w;
542 mHeight = h;
Mathias Agopian1989af22010-12-02 21:32:29 -0800543 mNeedsScaling = mWidth != mReqWidth || mHeight != mReqHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800544}
545
Mathias Agopian2be352a2010-05-21 17:24:35 -0700546bool Layer::isFixedSize() const {
547 Mutex::Autolock _l(mLock);
548 return mFixedSize;
549}
550
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800551// ----------------------------------------------------------------------------
552// pageflip handling...
553// ----------------------------------------------------------------------------
554
555void Layer::lockPageFlip(bool& recomputeVisibleRegions)
556{
Mathias Agopian7623da42010-06-01 15:12:58 -0700557 ClientRef::Access sharedClient(mUserClientRef);
558 SharedBufferServer* lcblk(sharedClient.get());
559 if (!lcblk) {
Mathias Agopian593c05c2010-06-02 23:28:45 -0700560 // client died
561 recomputeVisibleRegions = true;
562 return;
563 }
564
Mathias Agopian9779b2212009-09-07 16:32:45 -0700565 ssize_t buf = lcblk->retireAndLock();
Mathias Agopian9f2c4fd2010-05-10 20:06:11 -0700566 if (buf == NOT_ENOUGH_DATA) {
567 // NOTE: This is not an error, it simply means there is nothing to
568 // retire. The buffer is locked because we will use it
Mathias Agopian9779b2212009-09-07 16:32:45 -0700569 // for composition later in the loop
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800570 return;
571 }
Mathias Agopian9e3d6932010-03-15 18:15:20 -0700572
Mathias Agopian9f2c4fd2010-05-10 20:06:11 -0700573 if (buf < NO_ERROR) {
Mathias Agopian7623da42010-06-01 15:12:58 -0700574 LOGE("retireAndLock() buffer index (%d) out of range", int(buf));
Mathias Agopian9e3d6932010-03-15 18:15:20 -0700575 mPostedDirtyRegion.clear();
576 return;
577 }
578
Mathias Agopian9779b2212009-09-07 16:32:45 -0700579 // we retired a buffer, which becomes the new front buffer
Mathias Agopian9f2c4fd2010-05-10 20:06:11 -0700580 if (mBufferManager.setActiveBufferIndex(buf) < NO_ERROR) {
Mathias Agopian7623da42010-06-01 15:12:58 -0700581 LOGE("retireAndLock() buffer index (%d) out of range", int(buf));
Mathias Agopian9f2c4fd2010-05-10 20:06:11 -0700582 mPostedDirtyRegion.clear();
583 return;
584 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800585
Mathias Agopian6950e422009-10-05 17:07:12 -0700586 sp<GraphicBuffer> newFrontBuffer(getBuffer(buf));
Mathias Agopian9e3d6932010-03-15 18:15:20 -0700587 if (newFrontBuffer != NULL) {
Mathias Agopiane96aa3e2010-08-19 17:01:19 -0700588 // get the dirty region
Mathias Agopian9e3d6932010-03-15 18:15:20 -0700589 // compute the posted region
590 const Region dirty(lcblk->getDirtyRegion(buf));
591 mPostedDirtyRegion = dirty.intersect( newFrontBuffer->getBounds() );
Mathias Agopian1473f462009-04-10 14:24:30 -0700592
Mathias Agopian9e3d6932010-03-15 18:15:20 -0700593 // update the layer size and release freeze-lock
594 const Layer::State& front(drawingState());
595 if (newFrontBuffer->getWidth() == front.requested_w &&
596 newFrontBuffer->getHeight() == front.requested_h)
Mathias Agopianbd23e302009-09-30 14:07:22 -0700597 {
Mathias Agopian9e3d6932010-03-15 18:15:20 -0700598 if ((front.w != front.requested_w) ||
599 (front.h != front.requested_h))
600 {
601 // Here we pretend the transaction happened by updating the
602 // current and drawing states. Drawing state is only accessed
603 // in this thread, no need to have it locked
604 Layer::State& editDraw(mDrawingState);
605 editDraw.w = editDraw.requested_w;
606 editDraw.h = editDraw.requested_h;
Mathias Agopianbd23e302009-09-30 14:07:22 -0700607
Mathias Agopian9e3d6932010-03-15 18:15:20 -0700608 // We also need to update the current state so that we don't
609 // end-up doing too much work during the next transaction.
610 // NOTE: We actually don't need hold the transaction lock here
611 // because State::w and State::h are only accessed from
612 // this thread
613 Layer::State& editTemp(currentState());
614 editTemp.w = editDraw.w;
615 editTemp.h = editDraw.h;
Mathias Agopianbd23e302009-09-30 14:07:22 -0700616
Mathias Agopian9e3d6932010-03-15 18:15:20 -0700617 // recompute visible region
618 recomputeVisibleRegions = true;
619 }
620
621 // we now have the correct size, unfreeze the screen
622 mFreezeLock.clear();
Mathias Agopianbd23e302009-09-30 14:07:22 -0700623 }
Mathias Agopiane96aa3e2010-08-19 17:01:19 -0700624
625 // get the crop region
626 setBufferCrop( lcblk->getCrop(buf) );
627
628 // get the transformation
629 setBufferTransform( lcblk->getTransform(buf) );
630
Mathias Agopian9e3d6932010-03-15 18:15:20 -0700631 } else {
632 // this should not happen unless we ran out of memory while
633 // allocating the buffer. we're hoping that things will get back
634 // to normal the next time the app tries to draw into this buffer.
635 // meanwhile, pretend the screen didn't update.
636 mPostedDirtyRegion.clear();
Mathias Agopian7cf03ba2009-09-16 18:27:24 -0700637 }
638
Mathias Agopiane05f07d2009-10-07 16:44:10 -0700639 if (lcblk->getQueuedCount()) {
640 // signal an event if we have more buffers waiting
641 mFlinger->signalEvent();
642 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800643
Mathias Agopiana8a0aa82010-04-21 15:24:11 -0700644 /* a buffer was posted, so we need to call reloadTexture(), which
645 * will update our internal data structures (eg: EGLImageKHR or
646 * texture names). we need to do this even if mPostedDirtyRegion is
647 * empty -- it's orthogonal to the fact that a new buffer was posted,
648 * for instance, a degenerate case could be that the user did an empty
649 * update but repainted the buffer with appropriate content (after a
650 * resize for instance).
651 */
652 reloadTexture( mPostedDirtyRegion );
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800653}
654
655void Layer::unlockPageFlip(
656 const Transform& planeTransform, Region& outDirtyRegion)
657{
658 Region dirtyRegion(mPostedDirtyRegion);
659 if (!dirtyRegion.isEmpty()) {
660 mPostedDirtyRegion.clear();
661 // The dirty region is given in the layer's coordinate space
662 // transform the dirty region by the surface's transformation
663 // and the global transformation.
664 const Layer::State& s(drawingState());
665 const Transform tr(planeTransform * s.transform);
666 dirtyRegion = tr.transform(dirtyRegion);
667
668 // At this point, the dirty region is in screen space.
669 // Make sure it's constrained by the visible region (which
670 // is in screen space as well).
671 dirtyRegion.andSelf(visibleRegionScreen);
672 outDirtyRegion.orSelf(dirtyRegion);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800673 }
Mathias Agopian5469a4a2009-11-30 11:15:41 -0800674 if (visibleRegionScreen.isEmpty()) {
675 // an invisible layer should not hold a freeze-lock
Mathias Agopian9bce8732010-04-20 17:55:49 -0700676 // (because it may never be updated and therefore never release it)
Mathias Agopian5469a4a2009-11-30 11:15:41 -0800677 mFreezeLock.clear();
678 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800679}
680
Mathias Agopian9bce8732010-04-20 17:55:49 -0700681void Layer::dump(String8& result, char* buffer, size_t SIZE) const
682{
683 LayerBaseClient::dump(result, buffer, SIZE);
684
Mathias Agopian7623da42010-06-01 15:12:58 -0700685 ClientRef::Access sharedClient(mUserClientRef);
686 SharedBufferServer* lcblk(sharedClient.get());
687 uint32_t totalTime = 0;
688 if (lcblk) {
689 SharedBufferStack::Statistics stats = lcblk->getStats();
690 totalTime= stats.totalTime;
691 result.append( lcblk->dump(" ") );
692 }
693
Mathias Agopian9bce8732010-04-20 17:55:49 -0700694 sp<const GraphicBuffer> buf0(getBuffer(0));
695 sp<const GraphicBuffer> buf1(getBuffer(1));
696 uint32_t w0=0, h0=0, s0=0;
697 uint32_t w1=0, h1=0, s1=0;
698 if (buf0 != 0) {
699 w0 = buf0->getWidth();
700 h0 = buf0->getHeight();
701 s0 = buf0->getStride();
702 }
703 if (buf1 != 0) {
704 w1 = buf1->getWidth();
705 h1 = buf1->getHeight();
706 s1 = buf1->getStride();
707 }
708 snprintf(buffer, SIZE,
709 " "
710 "format=%2d, [%3ux%3u:%3u] [%3ux%3u:%3u],"
Mathias Agopian025005f2010-11-01 23:32:18 -0700711 " freezeLock=%p, bypass=%d, dq-q-time=%u us\n",
Mathias Agopian7623da42010-06-01 15:12:58 -0700712 mFormat, w0, h0, s0, w1, h1, s1,
Mathias Agopian025005f2010-11-01 23:32:18 -0700713 getFreezeLock().get(), mBypassState, totalTime);
Mathias Agopian9bce8732010-04-20 17:55:49 -0700714
715 result.append(buffer);
716}
717
Mathias Agopian1473f462009-04-10 14:24:30 -0700718// ---------------------------------------------------------------------------
719
Mathias Agopian7623da42010-06-01 15:12:58 -0700720Layer::ClientRef::ClientRef()
Mathias Agopian5e140102010-06-08 19:54:15 -0700721 : mControlBlock(0), mToken(-1) {
Mathias Agopian7623da42010-06-01 15:12:58 -0700722}
723
724Layer::ClientRef::~ClientRef() {
Mathias Agopian7623da42010-06-01 15:12:58 -0700725}
726
727int32_t Layer::ClientRef::getToken() const {
728 Mutex::Autolock _l(mLock);
729 return mToken;
730}
731
Mathias Agopian5e140102010-06-08 19:54:15 -0700732sp<UserClient> Layer::ClientRef::getClient() const {
Mathias Agopian7623da42010-06-01 15:12:58 -0700733 Mutex::Autolock _l(mLock);
Mathias Agopian5e140102010-06-08 19:54:15 -0700734 return mUserClient.promote();
735}
736
737status_t Layer::ClientRef::setToken(const sp<UserClient>& uc,
738 const sp<SharedBufferServer>& sharedClient, int32_t token) {
739 Mutex::Autolock _l(mLock);
740
741 { // scope for strong mUserClient reference
742 sp<UserClient> userClient(mUserClient.promote());
743 if (mUserClient != 0 && mControlBlock != 0) {
744 mControlBlock->setStatus(NO_INIT);
745 }
746 }
747
Mathias Agopian7623da42010-06-01 15:12:58 -0700748 mUserClient = uc;
749 mToken = token;
Mathias Agopian5e140102010-06-08 19:54:15 -0700750 mControlBlock = sharedClient;
Mathias Agopian7623da42010-06-01 15:12:58 -0700751 return NO_ERROR;
752}
753
754sp<UserClient> Layer::ClientRef::getUserClientUnsafe() const {
755 return mUserClient.promote();
756}
757
758// this class gives us access to SharedBufferServer safely
759// it makes sure the UserClient (and its associated shared memory)
760// won't go away while we're accessing it.
761Layer::ClientRef::Access::Access(const ClientRef& ref)
Mathias Agopian5e140102010-06-08 19:54:15 -0700762 : mControlBlock(0)
Mathias Agopian7623da42010-06-01 15:12:58 -0700763{
764 Mutex::Autolock _l(ref.mLock);
765 mUserClientStrongRef = ref.mUserClient.promote();
766 if (mUserClientStrongRef != 0)
Mathias Agopian5e140102010-06-08 19:54:15 -0700767 mControlBlock = ref.mControlBlock;
768}
769
770Layer::ClientRef::Access::~Access()
771{
Mathias Agopian7623da42010-06-01 15:12:58 -0700772}
773
774// ---------------------------------------------------------------------------
775
Mathias Agopian9f2c4fd2010-05-10 20:06:11 -0700776Layer::BufferManager::BufferManager(TextureManager& tm)
Mathias Agopian898c4c92010-05-18 17:06:55 -0700777 : mNumBuffers(NUM_BUFFERS), mTextureManager(tm),
Mathias Agopian7623da42010-06-01 15:12:58 -0700778 mActiveBuffer(-1), mFailover(false)
Mathias Agopian9f2c4fd2010-05-10 20:06:11 -0700779{
780}
781
Mathias Agopian898c4c92010-05-18 17:06:55 -0700782Layer::BufferManager::~BufferManager()
783{
784}
785
786status_t Layer::BufferManager::resize(size_t size)
787{
788 Mutex::Autolock _l(mLock);
789 mNumBuffers = size;
790 return NO_ERROR;
Mathias Agopian9f2c4fd2010-05-10 20:06:11 -0700791}
792
793// only for debugging
794sp<GraphicBuffer> Layer::BufferManager::getBuffer(size_t index) const {
795 return mBufferData[index].buffer;
796}
797
798status_t Layer::BufferManager::setActiveBufferIndex(size_t index) {
Mathias Agopian9f2c4fd2010-05-10 20:06:11 -0700799 mActiveBuffer = index;
800 return NO_ERROR;
801}
802
803size_t Layer::BufferManager::getActiveBufferIndex() const {
804 return mActiveBuffer;
805}
806
807Texture Layer::BufferManager::getActiveTexture() const {
Mathias Agopian898c4c92010-05-18 17:06:55 -0700808 Texture res;
Mathias Agopian7623da42010-06-01 15:12:58 -0700809 if (mFailover || mActiveBuffer<0) {
Mathias Agopian898c4c92010-05-18 17:06:55 -0700810 res = mFailoverTexture;
811 } else {
812 static_cast<Image&>(res) = mBufferData[mActiveBuffer].texture;
813 }
814 return res;
Mathias Agopian9f2c4fd2010-05-10 20:06:11 -0700815}
816
817sp<GraphicBuffer> Layer::BufferManager::getActiveBuffer() const {
Mathias Agopian7623da42010-06-01 15:12:58 -0700818 sp<GraphicBuffer> result;
819 const ssize_t activeBuffer = mActiveBuffer;
820 if (activeBuffer >= 0) {
821 BufferData const * const buffers = mBufferData;
822 Mutex::Autolock _l(mLock);
823 result = buffers[activeBuffer].buffer;
824 }
825 return result;
Mathias Agopian9f2c4fd2010-05-10 20:06:11 -0700826}
827
828sp<GraphicBuffer> Layer::BufferManager::detachBuffer(size_t index)
829{
Mathias Agopian898c4c92010-05-18 17:06:55 -0700830 BufferData* const buffers = mBufferData;
Mathias Agopian9f2c4fd2010-05-10 20:06:11 -0700831 sp<GraphicBuffer> buffer;
832 Mutex::Autolock _l(mLock);
Mathias Agopian898c4c92010-05-18 17:06:55 -0700833 buffer = buffers[index].buffer;
834 buffers[index].buffer = 0;
Mathias Agopian9f2c4fd2010-05-10 20:06:11 -0700835 return buffer;
836}
837
838status_t Layer::BufferManager::attachBuffer(size_t index,
839 const sp<GraphicBuffer>& buffer)
840{
Mathias Agopian898c4c92010-05-18 17:06:55 -0700841 BufferData* const buffers = mBufferData;
Mathias Agopian9f2c4fd2010-05-10 20:06:11 -0700842 Mutex::Autolock _l(mLock);
Mathias Agopian898c4c92010-05-18 17:06:55 -0700843 buffers[index].buffer = buffer;
844 buffers[index].texture.dirty = true;
Mathias Agopian9f2c4fd2010-05-10 20:06:11 -0700845 return NO_ERROR;
846}
847
848status_t Layer::BufferManager::destroy(EGLDisplay dpy)
849{
Mathias Agopian898c4c92010-05-18 17:06:55 -0700850 BufferData* const buffers = mBufferData;
851 size_t num;
852 { // scope for the lock
853 Mutex::Autolock _l(mLock);
854 num = mNumBuffers;
855 for (size_t i=0 ; i<num ; i++) {
856 buffers[i].buffer = 0;
857 }
858 }
859 for (size_t i=0 ; i<num ; i++) {
860 destroyTexture(&buffers[i].texture, dpy);
Mathias Agopian9f2c4fd2010-05-10 20:06:11 -0700861 }
862 destroyTexture(&mFailoverTexture, dpy);
863 return NO_ERROR;
864}
865
866status_t Layer::BufferManager::initEglImage(EGLDisplay dpy,
867 const sp<GraphicBuffer>& buffer)
868{
Mathias Agopian7623da42010-06-01 15:12:58 -0700869 status_t err = NO_INIT;
870 ssize_t index = mActiveBuffer;
871 if (index >= 0) {
Mathias Agopian781953d2010-06-25 18:02:21 -0700872 if (!mFailover) {
873 Image& texture(mBufferData[index].texture);
874 err = mTextureManager.initEglImage(&texture, dpy, buffer);
875 // if EGLImage fails, we switch to regular texture mode, and we
876 // free all resources associated with using EGLImages.
877 if (err == NO_ERROR) {
878 mFailover = false;
879 destroyTexture(&mFailoverTexture, dpy);
880 } else {
881 mFailover = true;
882 const size_t num = mNumBuffers;
883 for (size_t i=0 ; i<num ; i++) {
884 destroyTexture(&mBufferData[i].texture, dpy);
885 }
Andreas Huber330dd302010-06-25 09:25:19 -0700886 }
Mathias Agopian781953d2010-06-25 18:02:21 -0700887 } else {
888 // we failed once, don't try again
889 err = BAD_VALUE;
Mathias Agopian9f2c4fd2010-05-10 20:06:11 -0700890 }
891 }
892 return err;
893}
894
895status_t Layer::BufferManager::loadTexture(
896 const Region& dirty, const GGLSurface& t)
897{
898 return mTextureManager.loadTexture(&mFailoverTexture, dirty, t);
899}
900
Mathias Agopian898c4c92010-05-18 17:06:55 -0700901status_t Layer::BufferManager::destroyTexture(Image* tex, EGLDisplay dpy)
902{
903 if (tex->name != -1U) {
904 glDeleteTextures(1, &tex->name);
905 tex->name = -1U;
906 }
907 if (tex->image != EGL_NO_IMAGE_KHR) {
908 eglDestroyImageKHR(dpy, tex->image);
909 tex->image = EGL_NO_IMAGE_KHR;
910 }
911 return NO_ERROR;
912}
913
Mathias Agopian9f2c4fd2010-05-10 20:06:11 -0700914// ---------------------------------------------------------------------------
915
Mathias Agopian6cf0db22009-04-17 19:36:26 -0700916Layer::SurfaceLayer::SurfaceLayer(const sp<SurfaceFlinger>& flinger,
Mathias Agopian593c05c2010-06-02 23:28:45 -0700917 const sp<Layer>& owner)
918 : Surface(flinger, owner->getIdentity(), owner)
Mathias Agopian6cf0db22009-04-17 19:36:26 -0700919{
920}
921
922Layer::SurfaceLayer::~SurfaceLayer()
Mathias Agopian1473f462009-04-10 14:24:30 -0700923{
924}
925
Mathias Agopian2be352a2010-05-21 17:24:35 -0700926sp<GraphicBuffer> Layer::SurfaceLayer::requestBuffer(int index,
927 uint32_t w, uint32_t h, uint32_t format, uint32_t usage)
Mathias Agopian1473f462009-04-10 14:24:30 -0700928{
Mathias Agopian6950e422009-10-05 17:07:12 -0700929 sp<GraphicBuffer> buffer;
Mathias Agopian1473f462009-04-10 14:24:30 -0700930 sp<Layer> owner(getOwner());
931 if (owner != 0) {
Mathias Agopian898c4c92010-05-18 17:06:55 -0700932 /*
933 * requestBuffer() cannot be called from the main thread
934 * as it could cause a dead-lock, since it may have to wait
935 * on conditions updated my the main thread.
936 */
Mathias Agopian2be352a2010-05-21 17:24:35 -0700937 buffer = owner->requestBuffer(index, w, h, format, usage);
Mathias Agopian1473f462009-04-10 14:24:30 -0700938 }
939 return buffer;
940}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800941
Mathias Agopian59751db2010-05-07 15:58:44 -0700942status_t Layer::SurfaceLayer::setBufferCount(int bufferCount)
943{
944 status_t err = DEAD_OBJECT;
945 sp<Layer> owner(getOwner());
946 if (owner != 0) {
Mathias Agopian898c4c92010-05-18 17:06:55 -0700947 /*
948 * setBufferCount() cannot be called from the main thread
949 * as it could cause a dead-lock, since it may have to wait
950 * on conditions updated my the main thread.
951 */
Mathias Agopian59751db2010-05-07 15:58:44 -0700952 err = owner->setBufferCount(bufferCount);
953 }
954 return err;
955}
956
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800957// ---------------------------------------------------------------------------
958
959
960}; // namespace android