The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 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 Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17 | #include <stdlib.h> |
| 18 | #include <stdint.h> |
| 19 | #include <sys/types.h> |
| 20 | |
| 21 | #include <cutils/properties.h> |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 22 | #include <cutils/native_handle.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 23 | |
| 24 | #include <utils/Errors.h> |
| 25 | #include <utils/Log.h> |
| 26 | #include <utils/StopWatch.h> |
| 27 | |
Mathias Agopian | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 28 | #include <ui/GraphicBuffer.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 29 | #include <ui/PixelFormat.h> |
Mathias Agopian | 9cce325 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 30 | |
| 31 | #include <surfaceflinger/Surface.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 32 | |
| 33 | #include "clz.h" |
| 34 | #include "Layer.h" |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 35 | #include "SurfaceFlinger.h" |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 36 | #include "DisplayHardware/DisplayHardware.h" |
| 37 | |
| 38 | |
| 39 | #define DEBUG_RESIZE 0 |
| 40 | |
| 41 | |
| 42 | namespace android { |
| 43 | |
Mathias Agopian | ca99fb8 | 2010-04-14 16:43:44 -0700 | [diff] [blame] | 44 | template <typename T> inline T min(T a, T b) { |
| 45 | return a<b ? a : b; |
| 46 | } |
| 47 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 48 | // --------------------------------------------------------------------------- |
| 49 | |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 50 | Layer::Layer(SurfaceFlinger* flinger, DisplayID display, |
| 51 | const sp<Client>& c, int32_t i) |
Mathias Agopian | 48d819a | 2009-09-10 19:41:18 -0700 | [diff] [blame] | 52 | : LayerBaseClient(flinger, display, c, i), |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 53 | mSecure(false), |
Mathias Agopian | a4b740e | 2009-10-05 18:20:39 -0700 | [diff] [blame] | 54 | mNoEGLImageForSwBuffers(false), |
Mathias Agopian | 401c257 | 2009-09-23 19:16:27 -0700 | [diff] [blame] | 55 | mNeedsBlending(true), |
| 56 | mNeedsDithering(false) |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 57 | { |
| 58 | // no OpenGL operation is possible here, since we might not be |
| 59 | // in the OpenGL thread. |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 60 | mFrontBufferIndex = lcblk->getFrontBuffer(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | Layer::~Layer() |
| 64 | { |
Mathias Agopian | 0aa758d | 2009-04-22 15:23:34 -0700 | [diff] [blame] | 65 | destroy(); |
| 66 | // the actual buffers will be destroyed here |
Mathias Agopian | 48d819a | 2009-09-10 19:41:18 -0700 | [diff] [blame] | 67 | } |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 68 | |
Mathias Agopian | 0aa758d | 2009-04-22 15:23:34 -0700 | [diff] [blame] | 69 | void Layer::destroy() |
| 70 | { |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 71 | for (size_t i=0 ; i<NUM_BUFFERS ; i++) { |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 72 | if (mTextures[i].name != -1U) { |
Mathias Agopian | 550b79f | 2009-04-22 15:49:28 -0700 | [diff] [blame] | 73 | glDeleteTextures(1, &mTextures[i].name); |
Mathias Agopian | 0aa758d | 2009-04-22 15:23:34 -0700 | [diff] [blame] | 74 | mTextures[i].name = -1U; |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 75 | } |
| 76 | if (mTextures[i].image != EGL_NO_IMAGE_KHR) { |
| 77 | EGLDisplay dpy(mFlinger->graphicPlane(0).getEGLDisplay()); |
| 78 | eglDestroyImageKHR(dpy, mTextures[i].image); |
Mathias Agopian | 0aa758d | 2009-04-22 15:23:34 -0700 | [diff] [blame] | 79 | mTextures[i].image = EGL_NO_IMAGE_KHR; |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 80 | } |
Mathias Agopian | 48d819a | 2009-09-10 19:41:18 -0700 | [diff] [blame] | 81 | Mutex::Autolock _l(mLock); |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 82 | mBuffers[i].clear(); |
Mathias Agopian | 48d819a | 2009-09-10 19:41:18 -0700 | [diff] [blame] | 83 | mWidth = mHeight = 0; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 84 | } |
Mathias Agopian | 8c0a3d7 | 2009-09-23 16:44:00 -0700 | [diff] [blame] | 85 | mSurface.clear(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 86 | } |
| 87 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 88 | sp<LayerBaseClient::Surface> Layer::createSurface() const |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 89 | { |
| 90 | return mSurface; |
| 91 | } |
| 92 | |
Mathias Agopian | 9a11206 | 2009-04-17 19:36:26 -0700 | [diff] [blame] | 93 | status_t Layer::ditch() |
| 94 | { |
Mathias Agopian | 0aa758d | 2009-04-22 15:23:34 -0700 | [diff] [blame] | 95 | // the layer is not on screen anymore. free as much resources as possible |
Mathias Agopian | f5430db | 2009-12-11 00:56:10 -0800 | [diff] [blame] | 96 | mFreezeLock.clear(); |
Mathias Agopian | 8c0a3d7 | 2009-09-23 16:44:00 -0700 | [diff] [blame] | 97 | destroy(); |
Mathias Agopian | 9a11206 | 2009-04-17 19:36:26 -0700 | [diff] [blame] | 98 | return NO_ERROR; |
| 99 | } |
| 100 | |
Mathias Agopian | f9d9327 | 2009-06-19 17:00:27 -0700 | [diff] [blame] | 101 | status_t Layer::setBuffers( uint32_t w, uint32_t h, |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 102 | PixelFormat format, uint32_t flags) |
| 103 | { |
Mathias Agopian | 401c257 | 2009-09-23 19:16:27 -0700 | [diff] [blame] | 104 | // this surfaces pixel format |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 105 | PixelFormatInfo info; |
| 106 | status_t err = getPixelFormatInfo(format, &info); |
| 107 | if (err) return err; |
| 108 | |
Mathias Agopian | 401c257 | 2009-09-23 19:16:27 -0700 | [diff] [blame] | 109 | // the display's pixel format |
| 110 | const DisplayHardware& hw(graphicPlane(0).displayHardware()); |
Mathias Agopian | ca99fb8 | 2010-04-14 16:43:44 -0700 | [diff] [blame] | 111 | uint32_t const maxSurfaceDims = min( |
| 112 | hw.getMaxTextureSize(), hw.getMaxViewportDims()); |
| 113 | |
| 114 | // never allow a surface larger than what our underlying GL implementation |
| 115 | // can handle. |
| 116 | if ((uint32_t(w)>maxSurfaceDims) || (uint32_t(h)>maxSurfaceDims)) { |
| 117 | return BAD_VALUE; |
| 118 | } |
| 119 | |
Mathias Agopian | 401c257 | 2009-09-23 19:16:27 -0700 | [diff] [blame] | 120 | PixelFormatInfo displayInfo; |
| 121 | getPixelFormatInfo(hw.getFormat(), &displayInfo); |
Mathias Agopian | a4b740e | 2009-10-05 18:20:39 -0700 | [diff] [blame] | 122 | const uint32_t hwFlags = hw.getFlags(); |
| 123 | |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 124 | mFormat = format; |
Mathias Agopian | ca99fb8 | 2010-04-14 16:43:44 -0700 | [diff] [blame] | 125 | mWidth = w; |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 126 | mHeight = h; |
Mathias Agopian | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 127 | mSecure = (flags & ISurfaceComposer::eSecure) ? true : false; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 128 | mNeedsBlending = (info.h_alpha - info.l_alpha) > 0; |
Mathias Agopian | a4b740e | 2009-10-05 18:20:39 -0700 | [diff] [blame] | 129 | mNoEGLImageForSwBuffers = !(hwFlags & DisplayHardware::CACHED_BUFFERS); |
Mathias Agopian | ca99fb8 | 2010-04-14 16:43:44 -0700 | [diff] [blame] | 130 | |
Mathias Agopian | 401c257 | 2009-09-23 19:16:27 -0700 | [diff] [blame] | 131 | // we use the red index |
| 132 | int displayRedSize = displayInfo.getSize(PixelFormatInfo::INDEX_RED); |
| 133 | int layerRedsize = info.getSize(PixelFormatInfo::INDEX_RED); |
| 134 | mNeedsDithering = layerRedsize > displayRedSize; |
| 135 | |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 136 | for (size_t i=0 ; i<NUM_BUFFERS ; i++) { |
Mathias Agopian | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 137 | mBuffers[i] = new GraphicBuffer(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 138 | } |
Mathias Agopian | 9a11206 | 2009-04-17 19:36:26 -0700 | [diff] [blame] | 139 | mSurface = new SurfaceLayer(mFlinger, clientIndex(), this); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 140 | return NO_ERROR; |
| 141 | } |
| 142 | |
| 143 | void Layer::reloadTexture(const Region& dirty) |
| 144 | { |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 145 | Mutex::Autolock _l(mLock); |
Mathias Agopian | 9ec430a | 2009-10-06 19:00:57 -0700 | [diff] [blame] | 146 | sp<GraphicBuffer> buffer(getFrontBufferLocked()); |
Mathias Agopian | 8f03b47 | 2009-12-10 15:52:29 -0800 | [diff] [blame] | 147 | if (buffer == NULL) { |
| 148 | // this situation can happen if we ran out of memory for instance. |
| 149 | // not much we can do. continue to use whatever texture was bound |
| 150 | // to this context. |
| 151 | return; |
| 152 | } |
| 153 | |
| 154 | const int index = mFrontBufferIndex; |
Mathias Agopian | 57720c3 | 2009-10-21 16:27:21 -0700 | [diff] [blame] | 155 | |
| 156 | // create the new texture name if needed |
| 157 | if (UNLIKELY(mTextures[index].name == -1U)) { |
| 158 | mTextures[index].name = createTexture(); |
| 159 | mTextures[index].width = 0; |
| 160 | mTextures[index].height = 0; |
| 161 | } |
| 162 | |
Mathias Agopian | 54ba51d | 2009-10-26 20:12:37 -0700 | [diff] [blame] | 163 | #ifdef EGL_ANDROID_image_native_buffer |
Mathias Agopian | 57720c3 | 2009-10-21 16:27:21 -0700 | [diff] [blame] | 164 | if (mFlags & DisplayHardware::DIRECT_TEXTURE) { |
| 165 | if (buffer->usage & GraphicBuffer::USAGE_HW_TEXTURE) { |
| 166 | if (mTextures[index].dirty) { |
Mathias Agopian | fcfeb4b | 2010-03-08 11:14:20 -0800 | [diff] [blame] | 167 | if (initializeEglImage(buffer, &mTextures[index]) != NO_ERROR) { |
| 168 | // not sure what we can do here... |
| 169 | mFlags &= ~DisplayHardware::DIRECT_TEXTURE; |
| 170 | goto slowpath; |
| 171 | } |
Mathias Agopian | 57720c3 | 2009-10-21 16:27:21 -0700 | [diff] [blame] | 172 | } |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 173 | } else { |
Mathias Agopian | 57720c3 | 2009-10-21 16:27:21 -0700 | [diff] [blame] | 174 | if (mHybridBuffer==0 || (mHybridBuffer->width != buffer->width || |
| 175 | mHybridBuffer->height != buffer->height)) { |
| 176 | mHybridBuffer.clear(); |
| 177 | mHybridBuffer = new GraphicBuffer( |
| 178 | buffer->width, buffer->height, buffer->format, |
| 179 | GraphicBuffer::USAGE_SW_WRITE_OFTEN | |
| 180 | GraphicBuffer::USAGE_HW_TEXTURE); |
Mathias Agopian | fcfeb4b | 2010-03-08 11:14:20 -0800 | [diff] [blame] | 181 | if (initializeEglImage( |
| 182 | mHybridBuffer, &mTextures[0]) != NO_ERROR) { |
| 183 | // not sure what we can do here... |
| 184 | mFlags &= ~DisplayHardware::DIRECT_TEXTURE; |
| 185 | mHybridBuffer.clear(); |
| 186 | goto slowpath; |
| 187 | } |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 188 | } |
| 189 | |
Mathias Agopian | 57720c3 | 2009-10-21 16:27:21 -0700 | [diff] [blame] | 190 | GGLSurface t; |
| 191 | status_t res = buffer->lock(&t, GRALLOC_USAGE_SW_READ_OFTEN); |
| 192 | LOGE_IF(res, "error %d (%s) locking buffer %p", |
| 193 | res, strerror(res), buffer.get()); |
| 194 | if (res == NO_ERROR) { |
| 195 | Texture* const texture(&mTextures[0]); |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 196 | |
Mathias Agopian | 57720c3 | 2009-10-21 16:27:21 -0700 | [diff] [blame] | 197 | glBindTexture(GL_TEXTURE_2D, texture->name); |
| 198 | |
| 199 | sp<GraphicBuffer> buf(mHybridBuffer); |
| 200 | void* vaddr; |
| 201 | res = buf->lock(GraphicBuffer::USAGE_SW_WRITE_OFTEN, &vaddr); |
| 202 | if (res == NO_ERROR) { |
| 203 | int bpp = 0; |
| 204 | switch (t.format) { |
Mathias Agopian | 54ed4f6 | 2010-02-16 17:33:37 -0800 | [diff] [blame] | 205 | case HAL_PIXEL_FORMAT_RGB_565: |
| 206 | case HAL_PIXEL_FORMAT_RGBA_4444: |
Mathias Agopian | 57720c3 | 2009-10-21 16:27:21 -0700 | [diff] [blame] | 207 | bpp = 2; |
| 208 | break; |
Mathias Agopian | 54ed4f6 | 2010-02-16 17:33:37 -0800 | [diff] [blame] | 209 | case HAL_PIXEL_FORMAT_RGBA_8888: |
| 210 | case HAL_PIXEL_FORMAT_RGBX_8888: |
Mathias Agopian | 57720c3 | 2009-10-21 16:27:21 -0700 | [diff] [blame] | 211 | bpp = 4; |
| 212 | break; |
Mathias Agopian | 57720c3 | 2009-10-21 16:27:21 -0700 | [diff] [blame] | 213 | default: |
Mathias Agopian | 54ed4f6 | 2010-02-16 17:33:37 -0800 | [diff] [blame] | 214 | if (isSupportedYuvFormat(t.format)) { |
| 215 | // just show the Y plane of YUV buffers |
| 216 | bpp = 1; |
| 217 | break; |
| 218 | } |
Mathias Agopian | 57720c3 | 2009-10-21 16:27:21 -0700 | [diff] [blame] | 219 | // oops, we don't handle this format! |
| 220 | LOGE("layer %p, texture=%d, using format %d, which is not " |
| 221 | "supported by the GL", this, texture->name, t.format); |
| 222 | } |
| 223 | if (bpp) { |
| 224 | const Rect bounds(dirty.getBounds()); |
| 225 | size_t src_stride = t.stride; |
| 226 | size_t dst_stride = buf->stride; |
| 227 | if (src_stride == dst_stride && |
| 228 | bounds.width() == t.width && |
| 229 | bounds.height() == t.height) |
| 230 | { |
| 231 | memcpy(vaddr, t.data, t.height * t.stride * bpp); |
| 232 | } else { |
| 233 | GLubyte const * src = t.data + |
| 234 | (bounds.left + bounds.top * src_stride) * bpp; |
| 235 | GLubyte * dst = (GLubyte *)vaddr + |
| 236 | (bounds.left + bounds.top * dst_stride) * bpp; |
| 237 | const size_t length = bounds.width() * bpp; |
| 238 | size_t h = bounds.height(); |
| 239 | src_stride *= bpp; |
| 240 | dst_stride *= bpp; |
| 241 | while (h--) { |
| 242 | memcpy(dst, src, length); |
| 243 | dst += dst_stride; |
| 244 | src += src_stride; |
| 245 | } |
| 246 | } |
| 247 | } |
| 248 | buf->unlock(); |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 249 | } |
Mathias Agopian | 57720c3 | 2009-10-21 16:27:21 -0700 | [diff] [blame] | 250 | buffer->unlock(); |
| 251 | } |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 252 | } |
Mathias Agopian | 54ba51d | 2009-10-26 20:12:37 -0700 | [diff] [blame] | 253 | } else |
| 254 | #endif |
| 255 | { |
Mathias Agopian | fcfeb4b | 2010-03-08 11:14:20 -0800 | [diff] [blame] | 256 | slowpath: |
Mathias Agopian | 57720c3 | 2009-10-21 16:27:21 -0700 | [diff] [blame] | 257 | for (size_t i=0 ; i<NUM_BUFFERS ; i++) { |
Mathias Agopian | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 258 | mTextures[i].image = EGL_NO_IMAGE_KHR; |
Mathias Agopian | 57720c3 | 2009-10-21 16:27:21 -0700 | [diff] [blame] | 259 | } |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 260 | GGLSurface t; |
Mathias Agopian | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 261 | status_t res = buffer->lock(&t, GRALLOC_USAGE_SW_READ_OFTEN); |
Mathias Agopian | 0926f50 | 2009-05-04 14:17:04 -0700 | [diff] [blame] | 262 | LOGE_IF(res, "error %d (%s) locking buffer %p", |
| 263 | res, strerror(res), buffer.get()); |
| 264 | if (res == NO_ERROR) { |
Mathias Agopian | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 265 | loadTexture(&mTextures[0], dirty, t); |
Mathias Agopian | 0926f50 | 2009-05-04 14:17:04 -0700 | [diff] [blame] | 266 | buffer->unlock(); |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 267 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 268 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 269 | } |
| 270 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 271 | void Layer::onDraw(const Region& clip) const |
| 272 | { |
Mathias Agopian | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 273 | int index = mFrontBufferIndex; |
| 274 | if (mTextures[index].image == EGL_NO_IMAGE_KHR) |
| 275 | index = 0; |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 276 | GLuint textureName = mTextures[index].name; |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 277 | if (UNLIKELY(textureName == -1LU)) { |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 278 | // the texture has not been created yet, this Layer has |
| 279 | // in fact never been drawn into. this happens frequently with |
| 280 | // SurfaceView. |
| 281 | clearWithOpenGL(clip); |
| 282 | return; |
| 283 | } |
Mathias Agopian | 1fed11c | 2009-06-23 18:08:22 -0700 | [diff] [blame] | 284 | drawWithOpenGL(clip, mTextures[index]); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 285 | } |
| 286 | |
Mathias Agopian | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 287 | sp<GraphicBuffer> Layer::requestBuffer(int index, int usage) |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 288 | { |
Mathias Agopian | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 289 | sp<GraphicBuffer> buffer; |
Mathias Agopian | 48d819a | 2009-09-10 19:41:18 -0700 | [diff] [blame] | 290 | |
| 291 | // this ensures our client doesn't go away while we're accessing |
| 292 | // the shared area. |
| 293 | sp<Client> ourClient(client.promote()); |
| 294 | if (ourClient == 0) { |
| 295 | // oops, the client is already gone |
| 296 | return buffer; |
| 297 | } |
| 298 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 299 | /* |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 300 | * This is called from the client's Surface::dequeue(). This can happen |
| 301 | * at any time, especially while we're in the middle of using the |
| 302 | * buffer 'index' as our front buffer. |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 303 | * |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 304 | * Make sure the buffer we're resizing is not the front buffer and has been |
| 305 | * dequeued. Once this condition is asserted, we are guaranteed that this |
| 306 | * buffer cannot become the front buffer under our feet, since we're called |
| 307 | * from Surface::dequeue() |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 308 | */ |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 309 | status_t err = lcblk->assertReallocate(index); |
| 310 | LOGE_IF(err, "assertReallocate(%d) failed (%s)", index, strerror(-err)); |
Mathias Agopian | 48d819a | 2009-09-10 19:41:18 -0700 | [diff] [blame] | 311 | if (err != NO_ERROR) { |
| 312 | // the surface may have died |
| 313 | return buffer; |
| 314 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 315 | |
Mathias Agopian | 48d819a | 2009-09-10 19:41:18 -0700 | [diff] [blame] | 316 | uint32_t w, h; |
| 317 | { // scope for the lock |
| 318 | Mutex::Autolock _l(mLock); |
| 319 | w = mWidth; |
| 320 | h = mHeight; |
| 321 | buffer = mBuffers[index]; |
Mathias Agopian | 6d9f698 | 2009-09-17 19:19:08 -0700 | [diff] [blame] | 322 | |
| 323 | // destroy() could have been called before we get here, we log it |
| 324 | // because it's uncommon, and the code below should handle it |
| 325 | LOGW_IF(buffer==0, |
| 326 | "mBuffers[%d] is null (mWidth=%d, mHeight=%d)", |
| 327 | index, w, h); |
| 328 | |
Mathias Agopian | 48d819a | 2009-09-10 19:41:18 -0700 | [diff] [blame] | 329 | mBuffers[index].clear(); |
| 330 | } |
| 331 | |
Mathias Agopian | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 332 | const uint32_t effectiveUsage = getEffectiveUsage(usage); |
Mathias Agopian | 6d9f698 | 2009-09-17 19:19:08 -0700 | [diff] [blame] | 333 | if (buffer!=0 && buffer->getStrongCount() == 1) { |
Mathias Agopian | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 334 | err = buffer->reallocate(w, h, mFormat, effectiveUsage); |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 335 | } else { |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 336 | // here we have to reallocate a new buffer because we could have a |
| 337 | // client in our process with a reference to it (eg: status bar), |
| 338 | // and we can't release the handle under its feet. |
| 339 | buffer.clear(); |
Mathias Agopian | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 340 | buffer = new GraphicBuffer(w, h, mFormat, effectiveUsage); |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 341 | err = buffer->initCheck(); |
| 342 | } |
| 343 | |
| 344 | if (err || buffer->handle == 0) { |
| 345 | LOGE_IF(err || buffer->handle == 0, |
| 346 | "Layer::requestBuffer(this=%p), index=%d, w=%d, h=%d failed (%s)", |
| 347 | this, index, w, h, strerror(-err)); |
| 348 | } else { |
| 349 | LOGD_IF(DEBUG_RESIZE, |
Mathias Agopian | 7e4a587 | 2009-09-29 22:39:22 -0700 | [diff] [blame] | 350 | "Layer::requestBuffer(this=%p), index=%d, w=%d, h=%d, handle=%p", |
| 351 | this, index, w, h, buffer->handle); |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 352 | } |
| 353 | |
| 354 | if (err == NO_ERROR && buffer->handle != 0) { |
Mathias Agopian | 48d819a | 2009-09-10 19:41:18 -0700 | [diff] [blame] | 355 | Mutex::Autolock _l(mLock); |
| 356 | if (mWidth && mHeight) { |
| 357 | // and we have new buffer |
| 358 | mBuffers[index] = buffer; |
| 359 | // texture is now dirty... |
| 360 | mTextures[index].dirty = true; |
| 361 | } else { |
| 362 | // oops we got killed while we were allocating the buffer |
| 363 | buffer.clear(); |
| 364 | } |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 365 | } |
| 366 | return buffer; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 367 | } |
| 368 | |
Mathias Agopian | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 369 | uint32_t Layer::getEffectiveUsage(uint32_t usage) const |
| 370 | { |
| 371 | /* |
| 372 | * buffers used for software rendering, but h/w composition |
| 373 | * are allocated with SW_READ_OFTEN | SW_WRITE_OFTEN | HW_TEXTURE |
| 374 | * |
| 375 | * buffers used for h/w rendering and h/w composition |
| 376 | * are allocated with HW_RENDER | HW_TEXTURE |
| 377 | * |
| 378 | * buffers used with h/w rendering and either NPOT or no egl_image_ext |
| 379 | * are allocated with SW_READ_RARELY | HW_RENDER |
| 380 | * |
| 381 | */ |
| 382 | |
| 383 | if (mSecure) { |
| 384 | // secure buffer, don't store it into the GPU |
| 385 | usage = GraphicBuffer::USAGE_SW_READ_OFTEN | |
| 386 | GraphicBuffer::USAGE_SW_WRITE_OFTEN; |
| 387 | } else { |
| 388 | // it's allowed to modify the usage flags here, but generally |
| 389 | // the requested flags should be honored. |
Mathias Agopian | a4b740e | 2009-10-05 18:20:39 -0700 | [diff] [blame] | 390 | if (mNoEGLImageForSwBuffers) { |
| 391 | if (usage & GraphicBuffer::USAGE_HW_MASK) { |
| 392 | // request EGLImage for h/w buffers only |
| 393 | usage |= GraphicBuffer::USAGE_HW_TEXTURE; |
| 394 | } |
| 395 | } else { |
| 396 | // request EGLImage for all buffers |
| 397 | usage |= GraphicBuffer::USAGE_HW_TEXTURE; |
| 398 | } |
Mathias Agopian | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 399 | } |
| 400 | return usage; |
| 401 | } |
| 402 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 403 | uint32_t Layer::doTransaction(uint32_t flags) |
| 404 | { |
| 405 | const Layer::State& front(drawingState()); |
| 406 | const Layer::State& temp(currentState()); |
| 407 | |
Mathias Agopian | 7e4a587 | 2009-09-29 22:39:22 -0700 | [diff] [blame] | 408 | if ((front.requested_w != temp.requested_w) || |
| 409 | (front.requested_h != temp.requested_h)) { |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 410 | // the size changed, we need to ask our client to request a new buffer |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 411 | LOGD_IF(DEBUG_RESIZE, |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 412 | "resize (layer=%p), requested (%dx%d), " |
| 413 | "drawing (%d,%d), (%dx%d), (%dx%d)", |
Mathias Agopian | 7e4a587 | 2009-09-29 22:39:22 -0700 | [diff] [blame] | 414 | this, |
| 415 | int(temp.requested_w), int(temp.requested_h), |
| 416 | int(front.requested_w), int(front.requested_h), |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 417 | int(mBuffers[0]->getWidth()), int(mBuffers[0]->getHeight()), |
| 418 | int(mBuffers[1]->getWidth()), int(mBuffers[1]->getHeight())); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 419 | |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 420 | // we're being resized and there is a freeze display request, |
| 421 | // acquire a freeze lock, so that the screen stays put |
| 422 | // until we've redrawn at the new size; this is to avoid |
| 423 | // glitches upon orientation changes. |
| 424 | if (mFlinger->hasFreezeRequest()) { |
| 425 | // if the surface is hidden, don't try to acquire the |
| 426 | // freeze lock, since hidden surfaces may never redraw |
| 427 | if (!(front.flags & ISurfaceComposer::eLayerHidden)) { |
| 428 | mFreezeLock = mFlinger->getFreezeLock(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 429 | } |
| 430 | } |
Mathias Agopian | caa600c | 2009-09-16 18:27:24 -0700 | [diff] [blame] | 431 | |
Mathias Agopian | df3e0b9 | 2009-09-30 14:07:22 -0700 | [diff] [blame] | 432 | // this will make sure LayerBase::doTransaction doesn't update |
| 433 | // the drawing state's size |
| 434 | Layer::State& editDraw(mDrawingState); |
| 435 | editDraw.requested_w = temp.requested_w; |
| 436 | editDraw.requested_h = temp.requested_h; |
| 437 | |
Mathias Agopian | 6656dbc | 2009-09-30 12:48:47 -0700 | [diff] [blame] | 438 | // record the new size, form this point on, when the client request a |
| 439 | // buffer, it'll get the new size. |
| 440 | setDrawingSize(temp.requested_w, temp.requested_h); |
| 441 | |
Mathias Agopian | caa600c | 2009-09-16 18:27:24 -0700 | [diff] [blame] | 442 | // all buffers need reallocation |
| 443 | lcblk->reallocate(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 444 | } |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 445 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 446 | if (temp.sequence != front.sequence) { |
| 447 | if (temp.flags & ISurfaceComposer::eLayerHidden || temp.alpha == 0) { |
| 448 | // this surface is now hidden, so it shouldn't hold a freeze lock |
| 449 | // (it may never redraw, which is fine if it is hidden) |
| 450 | mFreezeLock.clear(); |
| 451 | } |
| 452 | } |
| 453 | |
| 454 | return LayerBase::doTransaction(flags); |
| 455 | } |
| 456 | |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 457 | void Layer::setDrawingSize(uint32_t w, uint32_t h) { |
| 458 | Mutex::Autolock _l(mLock); |
| 459 | mWidth = w; |
| 460 | mHeight = h; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 461 | } |
| 462 | |
| 463 | // ---------------------------------------------------------------------------- |
| 464 | // pageflip handling... |
| 465 | // ---------------------------------------------------------------------------- |
| 466 | |
| 467 | void Layer::lockPageFlip(bool& recomputeVisibleRegions) |
| 468 | { |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 469 | ssize_t buf = lcblk->retireAndLock(); |
| 470 | if (buf < NO_ERROR) { |
| 471 | //LOGW("nothing to retire (%s)", strerror(-buf)); |
| 472 | // NOTE: here the buffer is locked because we will used |
| 473 | // for composition later in the loop |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 474 | return; |
| 475 | } |
Mathias Agopian | d343e3d | 2010-03-15 18:15:20 -0700 | [diff] [blame] | 476 | |
| 477 | // ouch, this really should never happen |
| 478 | if (uint32_t(buf)>=NUM_BUFFERS) { |
| 479 | LOGE("retireAndLock() buffer index (%d) out of range", buf); |
| 480 | mPostedDirtyRegion.clear(); |
| 481 | return; |
| 482 | } |
| 483 | |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 484 | // we retired a buffer, which becomes the new front buffer |
| 485 | mFrontBufferIndex = buf; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 486 | |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 487 | // get the dirty region |
Mathias Agopian | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 488 | sp<GraphicBuffer> newFrontBuffer(getBuffer(buf)); |
Mathias Agopian | d343e3d | 2010-03-15 18:15:20 -0700 | [diff] [blame] | 489 | if (newFrontBuffer != NULL) { |
| 490 | // compute the posted region |
| 491 | const Region dirty(lcblk->getDirtyRegion(buf)); |
| 492 | mPostedDirtyRegion = dirty.intersect( newFrontBuffer->getBounds() ); |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 493 | |
Mathias Agopian | d343e3d | 2010-03-15 18:15:20 -0700 | [diff] [blame] | 494 | // update the layer size and release freeze-lock |
| 495 | const Layer::State& front(drawingState()); |
| 496 | if (newFrontBuffer->getWidth() == front.requested_w && |
| 497 | newFrontBuffer->getHeight() == front.requested_h) |
Mathias Agopian | df3e0b9 | 2009-09-30 14:07:22 -0700 | [diff] [blame] | 498 | { |
Mathias Agopian | d343e3d | 2010-03-15 18:15:20 -0700 | [diff] [blame] | 499 | if ((front.w != front.requested_w) || |
| 500 | (front.h != front.requested_h)) |
| 501 | { |
| 502 | // Here we pretend the transaction happened by updating the |
| 503 | // current and drawing states. Drawing state is only accessed |
| 504 | // in this thread, no need to have it locked |
| 505 | Layer::State& editDraw(mDrawingState); |
| 506 | editDraw.w = editDraw.requested_w; |
| 507 | editDraw.h = editDraw.requested_h; |
Mathias Agopian | df3e0b9 | 2009-09-30 14:07:22 -0700 | [diff] [blame] | 508 | |
Mathias Agopian | d343e3d | 2010-03-15 18:15:20 -0700 | [diff] [blame] | 509 | // We also need to update the current state so that we don't |
| 510 | // end-up doing too much work during the next transaction. |
| 511 | // NOTE: We actually don't need hold the transaction lock here |
| 512 | // because State::w and State::h are only accessed from |
| 513 | // this thread |
| 514 | Layer::State& editTemp(currentState()); |
| 515 | editTemp.w = editDraw.w; |
| 516 | editTemp.h = editDraw.h; |
Mathias Agopian | df3e0b9 | 2009-09-30 14:07:22 -0700 | [diff] [blame] | 517 | |
Mathias Agopian | d343e3d | 2010-03-15 18:15:20 -0700 | [diff] [blame] | 518 | // recompute visible region |
| 519 | recomputeVisibleRegions = true; |
| 520 | } |
| 521 | |
| 522 | // we now have the correct size, unfreeze the screen |
| 523 | mFreezeLock.clear(); |
Mathias Agopian | df3e0b9 | 2009-09-30 14:07:22 -0700 | [diff] [blame] | 524 | } |
Mathias Agopian | d343e3d | 2010-03-15 18:15:20 -0700 | [diff] [blame] | 525 | } else { |
| 526 | // this should not happen unless we ran out of memory while |
| 527 | // allocating the buffer. we're hoping that things will get back |
| 528 | // to normal the next time the app tries to draw into this buffer. |
| 529 | // meanwhile, pretend the screen didn't update. |
| 530 | mPostedDirtyRegion.clear(); |
Mathias Agopian | caa600c | 2009-09-16 18:27:24 -0700 | [diff] [blame] | 531 | } |
| 532 | |
Mathias Agopian | e700501 | 2009-10-07 16:44:10 -0700 | [diff] [blame] | 533 | if (lcblk->getQueuedCount()) { |
| 534 | // signal an event if we have more buffers waiting |
| 535 | mFlinger->signalEvent(); |
| 536 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 537 | |
Mathias Agopian | 245e4d7 | 2010-04-21 15:24:11 -0700 | [diff] [blame] | 538 | /* a buffer was posted, so we need to call reloadTexture(), which |
| 539 | * will update our internal data structures (eg: EGLImageKHR or |
| 540 | * texture names). we need to do this even if mPostedDirtyRegion is |
| 541 | * empty -- it's orthogonal to the fact that a new buffer was posted, |
| 542 | * for instance, a degenerate case could be that the user did an empty |
| 543 | * update but repainted the buffer with appropriate content (after a |
| 544 | * resize for instance). |
| 545 | */ |
| 546 | reloadTexture( mPostedDirtyRegion ); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 547 | } |
| 548 | |
| 549 | void Layer::unlockPageFlip( |
| 550 | const Transform& planeTransform, Region& outDirtyRegion) |
| 551 | { |
| 552 | Region dirtyRegion(mPostedDirtyRegion); |
| 553 | if (!dirtyRegion.isEmpty()) { |
| 554 | mPostedDirtyRegion.clear(); |
| 555 | // The dirty region is given in the layer's coordinate space |
| 556 | // transform the dirty region by the surface's transformation |
| 557 | // and the global transformation. |
| 558 | const Layer::State& s(drawingState()); |
| 559 | const Transform tr(planeTransform * s.transform); |
| 560 | dirtyRegion = tr.transform(dirtyRegion); |
| 561 | |
| 562 | // At this point, the dirty region is in screen space. |
| 563 | // Make sure it's constrained by the visible region (which |
| 564 | // is in screen space as well). |
| 565 | dirtyRegion.andSelf(visibleRegionScreen); |
| 566 | outDirtyRegion.orSelf(dirtyRegion); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 567 | } |
Mathias Agopian | c61de17 | 2009-11-30 11:15:41 -0800 | [diff] [blame] | 568 | if (visibleRegionScreen.isEmpty()) { |
| 569 | // an invisible layer should not hold a freeze-lock |
Mathias Agopian | 1b5e102 | 2010-04-20 17:55:49 -0700 | [diff] [blame^] | 570 | // (because it may never be updated and therefore never release it) |
Mathias Agopian | c61de17 | 2009-11-30 11:15:41 -0800 | [diff] [blame] | 571 | mFreezeLock.clear(); |
| 572 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 573 | } |
| 574 | |
| 575 | void Layer::finishPageFlip() |
| 576 | { |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 577 | status_t err = lcblk->unlock( mFrontBufferIndex ); |
| 578 | LOGE_IF(err!=NO_ERROR, |
| 579 | "layer %p, buffer=%d wasn't locked!", |
| 580 | this, mFrontBufferIndex); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 581 | } |
| 582 | |
Mathias Agopian | 1b5e102 | 2010-04-20 17:55:49 -0700 | [diff] [blame^] | 583 | |
| 584 | void Layer::dump(String8& result, char* buffer, size_t SIZE) const |
| 585 | { |
| 586 | LayerBaseClient::dump(result, buffer, SIZE); |
| 587 | |
| 588 | SharedBufferStack::Statistics stats = lcblk->getStats(); |
| 589 | result.append( lcblk->dump(" ") ); |
| 590 | sp<const GraphicBuffer> buf0(getBuffer(0)); |
| 591 | sp<const GraphicBuffer> buf1(getBuffer(1)); |
| 592 | uint32_t w0=0, h0=0, s0=0; |
| 593 | uint32_t w1=0, h1=0, s1=0; |
| 594 | if (buf0 != 0) { |
| 595 | w0 = buf0->getWidth(); |
| 596 | h0 = buf0->getHeight(); |
| 597 | s0 = buf0->getStride(); |
| 598 | } |
| 599 | if (buf1 != 0) { |
| 600 | w1 = buf1->getWidth(); |
| 601 | h1 = buf1->getHeight(); |
| 602 | s1 = buf1->getStride(); |
| 603 | } |
| 604 | snprintf(buffer, SIZE, |
| 605 | " " |
| 606 | "format=%2d, [%3ux%3u:%3u] [%3ux%3u:%3u]," |
| 607 | " freezeLock=%p, dq-q-time=%u us\n", |
| 608 | pixelFormat(), |
| 609 | w0, h0, s0, w1, h1, s1, |
| 610 | getFreezeLock().get(), stats.totalTime); |
| 611 | |
| 612 | result.append(buffer); |
| 613 | } |
| 614 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 615 | // --------------------------------------------------------------------------- |
| 616 | |
Mathias Agopian | 9a11206 | 2009-04-17 19:36:26 -0700 | [diff] [blame] | 617 | Layer::SurfaceLayer::SurfaceLayer(const sp<SurfaceFlinger>& flinger, |
| 618 | SurfaceID id, const sp<Layer>& owner) |
| 619 | : Surface(flinger, id, owner->getIdentity(), owner) |
| 620 | { |
| 621 | } |
| 622 | |
| 623 | Layer::SurfaceLayer::~SurfaceLayer() |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 624 | { |
| 625 | } |
| 626 | |
Mathias Agopian | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 627 | sp<GraphicBuffer> Layer::SurfaceLayer::requestBuffer(int index, int usage) |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 628 | { |
Mathias Agopian | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 629 | sp<GraphicBuffer> buffer; |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 630 | sp<Layer> owner(getOwner()); |
| 631 | if (owner != 0) { |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 632 | LOGE_IF(uint32_t(index)>=NUM_BUFFERS, |
| 633 | "getBuffer() index (%d) out of range", index); |
| 634 | if (uint32_t(index) < NUM_BUFFERS) { |
| 635 | buffer = owner->requestBuffer(index, usage); |
| 636 | } |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 637 | } |
| 638 | return buffer; |
| 639 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 640 | |
| 641 | // --------------------------------------------------------------------------- |
| 642 | |
| 643 | |
| 644 | }; // namespace android |