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 | |
| 28 | #include <ui/PixelFormat.h> |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 29 | #include <ui/Surface.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 30 | |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame^] | 31 | #include "Buffer.h" |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 32 | #include "clz.h" |
| 33 | #include "Layer.h" |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 34 | #include "SurfaceFlinger.h" |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 35 | #include "DisplayHardware/DisplayHardware.h" |
| 36 | |
| 37 | |
| 38 | #define DEBUG_RESIZE 0 |
| 39 | |
| 40 | |
| 41 | namespace android { |
| 42 | |
| 43 | // --------------------------------------------------------------------------- |
| 44 | |
| 45 | const uint32_t Layer::typeInfo = LayerBaseClient::typeInfo | 4; |
| 46 | const char* const Layer::typeID = "Layer"; |
| 47 | |
| 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) |
| 52 | : LayerBaseClient(flinger, display, c, i), lcblk(NULL), |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 53 | mSecure(false), |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame^] | 54 | mNeedsBlending(true) |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 55 | { |
| 56 | // no OpenGL operation is possible here, since we might not be |
| 57 | // in the OpenGL thread. |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame^] | 58 | lcblk = new SharedBufferServer(c->ctrlblk, i, NUM_BUFFERS); |
| 59 | mFrontBufferIndex = lcblk->getFrontBuffer(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | Layer::~Layer() |
| 63 | { |
Mathias Agopian | 0aa758d | 2009-04-22 15:23:34 -0700 | [diff] [blame] | 64 | destroy(); |
| 65 | // the actual buffers will be destroyed here |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame^] | 66 | delete lcblk; |
| 67 | |
Mathias Agopian | 0aa758d | 2009-04-22 15:23:34 -0700 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | void Layer::destroy() |
| 71 | { |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame^] | 72 | for (size_t i=0 ; i<NUM_BUFFERS ; i++) { |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 73 | if (mTextures[i].name != -1U) { |
Mathias Agopian | 550b79f | 2009-04-22 15:49:28 -0700 | [diff] [blame] | 74 | glDeleteTextures(1, &mTextures[i].name); |
Mathias Agopian | 0aa758d | 2009-04-22 15:23:34 -0700 | [diff] [blame] | 75 | mTextures[i].name = -1U; |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 76 | } |
| 77 | if (mTextures[i].image != EGL_NO_IMAGE_KHR) { |
| 78 | EGLDisplay dpy(mFlinger->graphicPlane(0).getEGLDisplay()); |
| 79 | eglDestroyImageKHR(dpy, mTextures[i].image); |
Mathias Agopian | 0aa758d | 2009-04-22 15:23:34 -0700 | [diff] [blame] | 80 | mTextures[i].image = EGL_NO_IMAGE_KHR; |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 81 | } |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame^] | 82 | mBuffers[i].clear(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 83 | } |
Mathias Agopian | 759fdb2 | 2009-07-02 17:33:40 -0700 | [diff] [blame] | 84 | mSurface.clear(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 85 | } |
| 86 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 87 | sp<LayerBaseClient::Surface> Layer::createSurface() const |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 88 | { |
| 89 | return mSurface; |
| 90 | } |
| 91 | |
Mathias Agopian | 9a11206 | 2009-04-17 19:36:26 -0700 | [diff] [blame] | 92 | status_t Layer::ditch() |
| 93 | { |
Mathias Agopian | 0aa758d | 2009-04-22 15:23:34 -0700 | [diff] [blame] | 94 | // the layer is not on screen anymore. free as much resources as possible |
Mathias Agopian | 0aa758d | 2009-04-22 15:23:34 -0700 | [diff] [blame] | 95 | destroy(); |
Mathias Agopian | 9a11206 | 2009-04-17 19:36:26 -0700 | [diff] [blame] | 96 | return NO_ERROR; |
| 97 | } |
| 98 | |
Mathias Agopian | f9d9327 | 2009-06-19 17:00:27 -0700 | [diff] [blame] | 99 | 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] | 100 | PixelFormat format, uint32_t flags) |
| 101 | { |
| 102 | PixelFormatInfo info; |
| 103 | status_t err = getPixelFormatInfo(format, &info); |
| 104 | if (err) return err; |
| 105 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 106 | uint32_t bufferFlags = 0; |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 107 | if (flags & ISurfaceComposer::eSecure) |
| 108 | bufferFlags |= Buffer::SECURE; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 109 | |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame^] | 110 | mFormat = format; |
| 111 | mWidth = w; |
| 112 | mHeight = h; |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 113 | mSecure = (bufferFlags & Buffer::SECURE) ? true : false; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 114 | mNeedsBlending = (info.h_alpha - info.l_alpha) > 0; |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame^] | 115 | mBufferFlags = bufferFlags; |
| 116 | for (size_t i=0 ; i<NUM_BUFFERS ; i++) { |
| 117 | mBuffers[i] = new Buffer(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 118 | } |
Mathias Agopian | 9a11206 | 2009-04-17 19:36:26 -0700 | [diff] [blame] | 119 | mSurface = new SurfaceLayer(mFlinger, clientIndex(), this); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 120 | return NO_ERROR; |
| 121 | } |
| 122 | |
| 123 | void Layer::reloadTexture(const Region& dirty) |
| 124 | { |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame^] | 125 | Mutex::Autolock _l(mLock); |
| 126 | sp<Buffer> buffer(getFrontBuffer()); |
Mathias Agopian | 0926f50 | 2009-05-04 14:17:04 -0700 | [diff] [blame] | 127 | if (LIKELY(mFlags & DisplayHardware::DIRECT_TEXTURE)) { |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 128 | int index = mFrontBufferIndex; |
| 129 | if (LIKELY(!mTextures[index].dirty)) { |
| 130 | glBindTexture(GL_TEXTURE_2D, mTextures[index].name); |
| 131 | } else { |
| 132 | // we need to recreate the texture |
| 133 | EGLDisplay dpy(mFlinger->graphicPlane(0).getEGLDisplay()); |
| 134 | |
| 135 | // create the new texture name if needed |
| 136 | if (UNLIKELY(mTextures[index].name == -1U)) { |
| 137 | mTextures[index].name = createTexture(); |
| 138 | } else { |
| 139 | glBindTexture(GL_TEXTURE_2D, mTextures[index].name); |
| 140 | } |
| 141 | |
| 142 | // free the previous image |
| 143 | if (mTextures[index].image != EGL_NO_IMAGE_KHR) { |
| 144 | eglDestroyImageKHR(dpy, mTextures[index].image); |
| 145 | mTextures[index].image = EGL_NO_IMAGE_KHR; |
| 146 | } |
| 147 | |
| 148 | // construct an EGL_NATIVE_BUFFER_ANDROID |
| 149 | android_native_buffer_t* clientBuf = buffer->getNativeBuffer(); |
| 150 | |
| 151 | // create the new EGLImageKHR |
| 152 | const EGLint attrs[] = { |
| 153 | EGL_IMAGE_PRESERVED_KHR, EGL_TRUE, |
| 154 | EGL_NONE, EGL_NONE |
| 155 | }; |
| 156 | mTextures[index].image = eglCreateImageKHR( |
| 157 | dpy, EGL_NO_CONTEXT, EGL_NATIVE_BUFFER_ANDROID, |
| 158 | (EGLClientBuffer)clientBuf, attrs); |
| 159 | |
| 160 | LOGE_IF(mTextures[index].image == EGL_NO_IMAGE_KHR, |
| 161 | "eglCreateImageKHR() failed. err=0x%4x", |
| 162 | eglGetError()); |
| 163 | |
| 164 | if (mTextures[index].image != EGL_NO_IMAGE_KHR) { |
| 165 | glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, |
| 166 | (GLeglImageOES)mTextures[index].image); |
| 167 | GLint error = glGetError(); |
| 168 | if (UNLIKELY(error != GL_NO_ERROR)) { |
| 169 | // this failed, for instance, because we don't support |
| 170 | // NPOT. |
| 171 | // FIXME: do something! |
| 172 | mFlags &= ~DisplayHardware::DIRECT_TEXTURE; |
| 173 | } else { |
| 174 | // Everything went okay! |
Mathias Agopian | 1fed11c | 2009-06-23 18:08:22 -0700 | [diff] [blame] | 175 | mTextures[index].dirty = false; |
| 176 | mTextures[index].width = clientBuf->width; |
| 177 | mTextures[index].height = clientBuf->height; |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 178 | } |
| 179 | } |
| 180 | } |
| 181 | } else { |
| 182 | GGLSurface t; |
Mathias Agopian | 0926f50 | 2009-05-04 14:17:04 -0700 | [diff] [blame] | 183 | status_t res = buffer->lock(&t, GRALLOC_USAGE_SW_READ_RARELY); |
| 184 | LOGE_IF(res, "error %d (%s) locking buffer %p", |
| 185 | res, strerror(res), buffer.get()); |
| 186 | if (res == NO_ERROR) { |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 187 | if (UNLIKELY(mTextures[0].name == -1U)) { |
| 188 | mTextures[0].name = createTexture(); |
| 189 | } |
Mathias Agopian | 1fed11c | 2009-06-23 18:08:22 -0700 | [diff] [blame] | 190 | loadTexture(&mTextures[0], mTextures[0].name, dirty, t); |
Mathias Agopian | 0926f50 | 2009-05-04 14:17:04 -0700 | [diff] [blame] | 191 | buffer->unlock(); |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 192 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 193 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 194 | } |
| 195 | |
| 196 | |
| 197 | void Layer::onDraw(const Region& clip) const |
| 198 | { |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 199 | const int index = (mFlags & DisplayHardware::DIRECT_TEXTURE) ? |
| 200 | mFrontBufferIndex : 0; |
| 201 | GLuint textureName = mTextures[index].name; |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 202 | if (UNLIKELY(textureName == -1LU)) { |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame^] | 203 | //LOGW("Layer %p doesn't have a texture", this); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 204 | // the texture has not been created yet, this Layer has |
| 205 | // in fact never been drawn into. this happens frequently with |
| 206 | // SurfaceView. |
| 207 | clearWithOpenGL(clip); |
| 208 | return; |
| 209 | } |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame^] | 210 | |
Mathias Agopian | 1fed11c | 2009-06-23 18:08:22 -0700 | [diff] [blame] | 211 | drawWithOpenGL(clip, mTextures[index]); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 212 | } |
| 213 | |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame^] | 214 | sp<SurfaceBuffer> Layer::requestBuffer(int index, int usage) |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 215 | { |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 216 | /* |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame^] | 217 | * This is called from the client's Surface::dequeue(). This can happen |
| 218 | * at any time, especially while we're in the middle of using the |
| 219 | * buffer 'index' as our front buffer. |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 220 | * |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame^] | 221 | * Make sure the buffer we're resizing is not the front buffer and has been |
| 222 | * dequeued. Once this condition is asserted, we are guaranteed that this |
| 223 | * buffer cannot become the front buffer under our feet, since we're called |
| 224 | * from Surface::dequeue() |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 225 | */ |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame^] | 226 | status_t err = lcblk->assertReallocate(index); |
| 227 | LOGE_IF(err, "assertReallocate(%d) failed (%s)", index, strerror(-err)); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 228 | |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame^] | 229 | Mutex::Autolock _l(mLock); |
| 230 | uint32_t w = mWidth; |
| 231 | uint32_t h = mHeight; |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 232 | |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame^] | 233 | sp<Buffer>& buffer(mBuffers[index]); |
| 234 | if (buffer->getStrongCount() == 1) { |
| 235 | err = buffer->reallocate(w, h, mFormat, usage, mBufferFlags); |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 236 | } else { |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame^] | 237 | // here we have to reallocate a new buffer because we could have a |
| 238 | // client in our process with a reference to it (eg: status bar), |
| 239 | // and we can't release the handle under its feet. |
| 240 | buffer.clear(); |
| 241 | buffer = new Buffer(w, h, mFormat, usage, mBufferFlags); |
| 242 | err = buffer->initCheck(); |
| 243 | } |
| 244 | |
| 245 | if (err || buffer->handle == 0) { |
| 246 | LOGE_IF(err || buffer->handle == 0, |
| 247 | "Layer::requestBuffer(this=%p), index=%d, w=%d, h=%d failed (%s)", |
| 248 | this, index, w, h, strerror(-err)); |
| 249 | } else { |
| 250 | LOGD_IF(DEBUG_RESIZE, |
| 251 | "Layer::requestBuffer(this=%p), index=%d, w=%d, h=%d", |
| 252 | this, index, w, h); |
| 253 | } |
| 254 | |
| 255 | if (err == NO_ERROR && buffer->handle != 0) { |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 256 | // texture is now dirty... |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame^] | 257 | mTextures[index].dirty = true; |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 258 | } |
| 259 | return buffer; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 260 | } |
| 261 | |
| 262 | uint32_t Layer::doTransaction(uint32_t flags) |
| 263 | { |
| 264 | const Layer::State& front(drawingState()); |
| 265 | const Layer::State& temp(currentState()); |
| 266 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 267 | // Index of the back buffer |
| 268 | const bool backbufferChanged = (front.w != temp.w) || (front.h != temp.h); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 269 | |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame^] | 270 | if (backbufferChanged) { |
| 271 | // 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] | 272 | LOGD_IF(DEBUG_RESIZE, |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame^] | 273 | "resize (layer=%p), requested (%dx%d), " |
| 274 | "drawing (%d,%d), (%dx%d), (%dx%d)", |
| 275 | this, int(temp.w), int(temp.h), |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 276 | int(drawingState().w), int(drawingState().h), |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame^] | 277 | int(mBuffers[0]->getWidth()), int(mBuffers[0]->getHeight()), |
| 278 | int(mBuffers[1]->getWidth()), int(mBuffers[1]->getHeight())); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 279 | |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame^] | 280 | // record the new size, form this point on, when the client request a |
| 281 | // buffer, it'll get the new size. |
| 282 | setDrawingSize(temp.w, temp.h); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 283 | |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame^] | 284 | // all buffers need reallocation |
| 285 | lcblk->reallocate(); |
| 286 | |
| 287 | // recompute the visible region |
| 288 | // FIXME: ideally we would do that only when we have received |
| 289 | // a buffer of the right size |
| 290 | flags |= Layer::eVisibleRegion; |
| 291 | this->contentDirty = true; |
| 292 | |
| 293 | #if 0 |
| 294 | // FIXME: handle freeze lock |
| 295 | // we're being resized and there is a freeze display request, |
| 296 | // acquire a freeze lock, so that the screen stays put |
| 297 | // until we've redrawn at the new size; this is to avoid |
| 298 | // glitches upon orientation changes. |
| 299 | if (mFlinger->hasFreezeRequest()) { |
| 300 | // if the surface is hidden, don't try to acquire the |
| 301 | // freeze lock, since hidden surfaces may never redraw |
| 302 | if (!(front.flags & ISurfaceComposer::eLayerHidden)) { |
| 303 | mFreezeLock = mFlinger->getFreezeLock(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 304 | } |
| 305 | } |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame^] | 306 | #endif |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 307 | } |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame^] | 308 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 309 | if (temp.sequence != front.sequence) { |
| 310 | if (temp.flags & ISurfaceComposer::eLayerHidden || temp.alpha == 0) { |
| 311 | // this surface is now hidden, so it shouldn't hold a freeze lock |
| 312 | // (it may never redraw, which is fine if it is hidden) |
| 313 | mFreezeLock.clear(); |
| 314 | } |
| 315 | } |
| 316 | |
| 317 | return LayerBase::doTransaction(flags); |
| 318 | } |
| 319 | |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame^] | 320 | void Layer::setDrawingSize(uint32_t w, uint32_t h) { |
| 321 | Mutex::Autolock _l(mLock); |
| 322 | mWidth = w; |
| 323 | mHeight = h; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 324 | } |
| 325 | |
| 326 | // ---------------------------------------------------------------------------- |
| 327 | // pageflip handling... |
| 328 | // ---------------------------------------------------------------------------- |
| 329 | |
| 330 | void Layer::lockPageFlip(bool& recomputeVisibleRegions) |
| 331 | { |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame^] | 332 | ssize_t buf = lcblk->retireAndLock(); |
| 333 | if (buf < NO_ERROR) { |
| 334 | //LOGW("nothing to retire (%s)", strerror(-buf)); |
| 335 | // NOTE: here the buffer is locked because we will used |
| 336 | // for composition later in the loop |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 337 | return; |
| 338 | } |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 339 | |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame^] | 340 | // we retired a buffer, which becomes the new front buffer |
| 341 | mFrontBufferIndex = buf; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 342 | |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame^] | 343 | // get the dirty region |
| 344 | sp<Buffer> newFrontBuffer(getBuffer(buf)); |
| 345 | const Region dirty(lcblk->getDirtyRegion(buf)); |
| 346 | mPostedDirtyRegion = dirty.intersect( newFrontBuffer->getBounds() ); |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 347 | |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame^] | 348 | // FIXME: signal an event if we have more buffers waiting |
| 349 | // mFlinger->signalEvent(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 350 | |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame^] | 351 | reloadTexture( mPostedDirtyRegion ); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 352 | } |
| 353 | |
| 354 | void Layer::unlockPageFlip( |
| 355 | const Transform& planeTransform, Region& outDirtyRegion) |
| 356 | { |
| 357 | Region dirtyRegion(mPostedDirtyRegion); |
| 358 | if (!dirtyRegion.isEmpty()) { |
| 359 | mPostedDirtyRegion.clear(); |
| 360 | // The dirty region is given in the layer's coordinate space |
| 361 | // transform the dirty region by the surface's transformation |
| 362 | // and the global transformation. |
| 363 | const Layer::State& s(drawingState()); |
| 364 | const Transform tr(planeTransform * s.transform); |
| 365 | dirtyRegion = tr.transform(dirtyRegion); |
| 366 | |
| 367 | // At this point, the dirty region is in screen space. |
| 368 | // Make sure it's constrained by the visible region (which |
| 369 | // is in screen space as well). |
| 370 | dirtyRegion.andSelf(visibleRegionScreen); |
| 371 | outDirtyRegion.orSelf(dirtyRegion); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 372 | } |
| 373 | } |
| 374 | |
| 375 | void Layer::finishPageFlip() |
| 376 | { |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame^] | 377 | status_t err = lcblk->unlock( mFrontBufferIndex ); |
| 378 | LOGE_IF(err!=NO_ERROR, |
| 379 | "layer %p, buffer=%d wasn't locked!", |
| 380 | this, mFrontBufferIndex); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 381 | } |
| 382 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 383 | // --------------------------------------------------------------------------- |
| 384 | |
Mathias Agopian | 9a11206 | 2009-04-17 19:36:26 -0700 | [diff] [blame] | 385 | Layer::SurfaceLayer::SurfaceLayer(const sp<SurfaceFlinger>& flinger, |
| 386 | SurfaceID id, const sp<Layer>& owner) |
| 387 | : Surface(flinger, id, owner->getIdentity(), owner) |
| 388 | { |
| 389 | } |
| 390 | |
| 391 | Layer::SurfaceLayer::~SurfaceLayer() |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 392 | { |
| 393 | } |
| 394 | |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame^] | 395 | sp<SurfaceBuffer> Layer::SurfaceLayer::requestBuffer(int index, int usage) |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 396 | { |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame^] | 397 | sp<SurfaceBuffer> buffer; |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 398 | sp<Layer> owner(getOwner()); |
| 399 | if (owner != 0) { |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame^] | 400 | LOGE_IF(uint32_t(index)>=NUM_BUFFERS, |
| 401 | "getBuffer() index (%d) out of range", index); |
| 402 | if (uint32_t(index) < NUM_BUFFERS) { |
| 403 | buffer = owner->requestBuffer(index, usage); |
| 404 | } |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 405 | } |
| 406 | return buffer; |
| 407 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 408 | |
| 409 | // --------------------------------------------------------------------------- |
| 410 | |
| 411 | |
| 412 | }; // namespace android |