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 <math.h> |
| 20 | #include <sys/types.h> |
| 21 | |
| 22 | #include <utils/Errors.h> |
| 23 | #include <utils/Log.h> |
| 24 | #include <utils/StopWatch.h> |
| 25 | |
Mathias Agopian | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 26 | #include <ui/GraphicBuffer.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 27 | #include <ui/PixelFormat.h> |
Mathias Agopian | 69029eb | 2009-06-23 21:11:43 -0700 | [diff] [blame] | 28 | #include <ui/FramebufferNativeWindow.h> |
Mathias Agopian | bbc21b0 | 2009-11-05 23:08:00 -0800 | [diff] [blame] | 29 | #include <ui/Rect.h> |
| 30 | #include <ui/Region.h> |
Mathias Agopian | 69029eb | 2009-06-23 21:11:43 -0700 | [diff] [blame] | 31 | |
| 32 | #include <hardware/copybit.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 33 | |
| 34 | #include "LayerBuffer.h" |
| 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 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 38 | namespace android { |
| 39 | |
| 40 | // --------------------------------------------------------------------------- |
| 41 | |
| 42 | const uint32_t LayerBuffer::typeInfo = LayerBaseClient::typeInfo | 0x20; |
| 43 | const char* const LayerBuffer::typeID = "LayerBuffer"; |
Mathias Agopian | 863e5fd | 2009-10-29 18:29:30 -0700 | [diff] [blame] | 44 | gralloc_module_t const* LayerBuffer::sGrallocModule = 0; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 45 | |
| 46 | // --------------------------------------------------------------------------- |
| 47 | |
| 48 | LayerBuffer::LayerBuffer(SurfaceFlinger* flinger, DisplayID display, |
Mathias Agopian | f9d9327 | 2009-06-19 17:00:27 -0700 | [diff] [blame] | 49 | const sp<Client>& client, int32_t i) |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 50 | : LayerBaseClient(flinger, display, client, i), |
Mathias Agopian | bbc21b0 | 2009-11-05 23:08:00 -0800 | [diff] [blame] | 51 | mNeedsBlending(false), mBlitEngine(0) |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 52 | { |
| 53 | } |
| 54 | |
| 55 | LayerBuffer::~LayerBuffer() |
| 56 | { |
Mathias Agopian | bbc21b0 | 2009-11-05 23:08:00 -0800 | [diff] [blame] | 57 | if (mBlitEngine) { |
| 58 | copybit_close(mBlitEngine); |
| 59 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 60 | } |
| 61 | |
Mathias Agopian | 9a11206 | 2009-04-17 19:36:26 -0700 | [diff] [blame] | 62 | void LayerBuffer::onFirstRef() |
| 63 | { |
Mathias Agopian | 2e12324 | 2009-06-23 20:06:46 -0700 | [diff] [blame] | 64 | LayerBaseClient::onFirstRef(); |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 65 | mSurface = new SurfaceLayerBuffer(mFlinger, clientIndex(), |
Mathias Agopian | 9a11206 | 2009-04-17 19:36:26 -0700 | [diff] [blame] | 66 | const_cast<LayerBuffer *>(this)); |
Mathias Agopian | 863e5fd | 2009-10-29 18:29:30 -0700 | [diff] [blame] | 67 | |
| 68 | hw_module_t const* module = (hw_module_t const*)sGrallocModule; |
| 69 | if (!module) { |
| 70 | // NOTE: technically there is a race here, but it shouldn't |
| 71 | // cause any problem since hw_get_module() always returns |
| 72 | // the same value. |
| 73 | if (hw_get_module(GRALLOC_HARDWARE_MODULE_ID, &module) == 0) { |
| 74 | sGrallocModule = (gralloc_module_t const *)module; |
| 75 | } |
| 76 | } |
Mathias Agopian | bbc21b0 | 2009-11-05 23:08:00 -0800 | [diff] [blame] | 77 | |
| 78 | if (hw_get_module(COPYBIT_HARDWARE_MODULE_ID, &module) == 0) { |
| 79 | copybit_open(module, &mBlitEngine); |
| 80 | } |
Mathias Agopian | 9a11206 | 2009-04-17 19:36:26 -0700 | [diff] [blame] | 81 | } |
| 82 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 83 | sp<LayerBaseClient::Surface> LayerBuffer::createSurface() const |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 84 | { |
Mathias Agopian | 9a11206 | 2009-04-17 19:36:26 -0700 | [diff] [blame] | 85 | return mSurface; |
| 86 | } |
| 87 | |
| 88 | status_t LayerBuffer::ditch() |
| 89 | { |
| 90 | mSurface.clear(); |
| 91 | return NO_ERROR; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | bool LayerBuffer::needsBlending() const { |
| 95 | return mNeedsBlending; |
| 96 | } |
| 97 | |
| 98 | void LayerBuffer::setNeedsBlending(bool blending) { |
| 99 | mNeedsBlending = blending; |
| 100 | } |
| 101 | |
| 102 | void LayerBuffer::postBuffer(ssize_t offset) |
| 103 | { |
| 104 | sp<Source> source(getSource()); |
| 105 | if (source != 0) |
| 106 | source->postBuffer(offset); |
| 107 | } |
| 108 | |
| 109 | void LayerBuffer::unregisterBuffers() |
| 110 | { |
| 111 | sp<Source> source(clearSource()); |
| 112 | if (source != 0) |
| 113 | source->unregisterBuffers(); |
| 114 | } |
| 115 | |
| 116 | uint32_t LayerBuffer::doTransaction(uint32_t flags) |
| 117 | { |
| 118 | sp<Source> source(getSource()); |
| 119 | if (source != 0) |
| 120 | source->onTransaction(flags); |
Mathias Agopian | 713795a | 2009-11-19 14:46:26 -0800 | [diff] [blame] | 121 | uint32_t res = LayerBase::doTransaction(flags); |
| 122 | // we always want filtering for these surfaces |
Mathias Agopian | 69ff5de | 2009-12-08 19:29:38 -0800 | [diff] [blame] | 123 | mUseLinearFiltering = !(mFlags & DisplayHardware::SLOW_CONFIG); |
Mathias Agopian | 713795a | 2009-11-19 14:46:26 -0800 | [diff] [blame] | 124 | return res; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 125 | } |
| 126 | |
| 127 | void LayerBuffer::unlockPageFlip(const Transform& planeTransform, |
| 128 | Region& outDirtyRegion) |
| 129 | { |
| 130 | // this code-path must be as tight as possible, it's called each time |
| 131 | // the screen is composited. |
| 132 | sp<Source> source(getSource()); |
| 133 | if (source != 0) |
| 134 | source->onVisibilityResolved(planeTransform); |
| 135 | LayerBase::unlockPageFlip(planeTransform, outDirtyRegion); |
| 136 | } |
| 137 | |
| 138 | void LayerBuffer::onDraw(const Region& clip) const |
| 139 | { |
| 140 | sp<Source> source(getSource()); |
| 141 | if (LIKELY(source != 0)) { |
| 142 | source->onDraw(clip); |
| 143 | } else { |
| 144 | clearWithOpenGL(clip); |
| 145 | } |
| 146 | } |
| 147 | |
| 148 | bool LayerBuffer::transformed() const |
| 149 | { |
| 150 | sp<Source> source(getSource()); |
| 151 | if (LIKELY(source != 0)) |
| 152 | return source->transformed(); |
| 153 | return false; |
| 154 | } |
| 155 | |
Mathias Agopian | 454ea68 | 2009-09-08 23:52:08 -0700 | [diff] [blame] | 156 | void LayerBuffer::serverDestroy() |
| 157 | { |
| 158 | sp<Source> source(clearSource()); |
| 159 | if (source != 0) { |
| 160 | source->destroy(); |
| 161 | } |
| 162 | } |
| 163 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 164 | /** |
| 165 | * This creates a "buffer" source for this surface |
| 166 | */ |
| 167 | status_t LayerBuffer::registerBuffers(const ISurface::BufferHeap& buffers) |
| 168 | { |
| 169 | Mutex::Autolock _l(mLock); |
| 170 | if (mSource != 0) |
| 171 | return INVALID_OPERATION; |
| 172 | |
| 173 | sp<BufferSource> source = new BufferSource(*this, buffers); |
| 174 | |
| 175 | status_t result = source->getStatus(); |
| 176 | if (result == NO_ERROR) { |
| 177 | mSource = source; |
| 178 | } |
| 179 | return result; |
| 180 | } |
| 181 | |
| 182 | /** |
| 183 | * This creates an "overlay" source for this surface |
| 184 | */ |
Chih-Chung Chang | 52e7200 | 2010-01-21 17:31:06 -0800 | [diff] [blame] | 185 | sp<OverlayRef> LayerBuffer::createOverlay(uint32_t w, uint32_t h, int32_t f, |
| 186 | int32_t orientation) |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 187 | { |
| 188 | sp<OverlayRef> result; |
| 189 | Mutex::Autolock _l(mLock); |
| 190 | if (mSource != 0) |
| 191 | return result; |
| 192 | |
Chih-Chung Chang | 52e7200 | 2010-01-21 17:31:06 -0800 | [diff] [blame] | 193 | sp<OverlaySource> source = new OverlaySource(*this, &result, w, h, f, orientation); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 194 | if (result != 0) { |
| 195 | mSource = source; |
| 196 | } |
| 197 | return result; |
| 198 | } |
| 199 | |
| 200 | sp<LayerBuffer::Source> LayerBuffer::getSource() const { |
| 201 | Mutex::Autolock _l(mLock); |
| 202 | return mSource; |
| 203 | } |
| 204 | |
| 205 | sp<LayerBuffer::Source> LayerBuffer::clearSource() { |
| 206 | sp<Source> source; |
| 207 | Mutex::Autolock _l(mLock); |
| 208 | source = mSource; |
| 209 | mSource.clear(); |
| 210 | return source; |
| 211 | } |
| 212 | |
| 213 | // ============================================================================ |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 214 | // LayerBuffer::SurfaceLayerBuffer |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 215 | // ============================================================================ |
| 216 | |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 217 | LayerBuffer::SurfaceLayerBuffer::SurfaceLayerBuffer(const sp<SurfaceFlinger>& flinger, |
Mathias Agopian | 9a11206 | 2009-04-17 19:36:26 -0700 | [diff] [blame] | 218 | SurfaceID id, const sp<LayerBuffer>& owner) |
| 219 | : LayerBaseClient::Surface(flinger, id, owner->getIdentity(), owner) |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 220 | { |
| 221 | } |
| 222 | |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 223 | LayerBuffer::SurfaceLayerBuffer::~SurfaceLayerBuffer() |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 224 | { |
| 225 | unregisterBuffers(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 226 | } |
| 227 | |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 228 | status_t LayerBuffer::SurfaceLayerBuffer::registerBuffers( |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 229 | const ISurface::BufferHeap& buffers) |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 230 | { |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 231 | sp<LayerBuffer> owner(getOwner()); |
| 232 | if (owner != 0) |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 233 | return owner->registerBuffers(buffers); |
| 234 | return NO_INIT; |
| 235 | } |
| 236 | |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 237 | void LayerBuffer::SurfaceLayerBuffer::postBuffer(ssize_t offset) |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 238 | { |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 239 | sp<LayerBuffer> owner(getOwner()); |
| 240 | if (owner != 0) |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 241 | owner->postBuffer(offset); |
| 242 | } |
| 243 | |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 244 | void LayerBuffer::SurfaceLayerBuffer::unregisterBuffers() |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 245 | { |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 246 | sp<LayerBuffer> owner(getOwner()); |
| 247 | if (owner != 0) |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 248 | owner->unregisterBuffers(); |
| 249 | } |
| 250 | |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 251 | sp<OverlayRef> LayerBuffer::SurfaceLayerBuffer::createOverlay( |
Chih-Chung Chang | 52e7200 | 2010-01-21 17:31:06 -0800 | [diff] [blame] | 252 | uint32_t w, uint32_t h, int32_t format, int32_t orientation) { |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 253 | sp<OverlayRef> result; |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 254 | sp<LayerBuffer> owner(getOwner()); |
| 255 | if (owner != 0) |
Chih-Chung Chang | 52e7200 | 2010-01-21 17:31:06 -0800 | [diff] [blame] | 256 | result = owner->createOverlay(w, h, format, orientation); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 257 | return result; |
| 258 | } |
| 259 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 260 | // ============================================================================ |
| 261 | // LayerBuffer::Buffer |
| 262 | // ============================================================================ |
| 263 | |
Mathias Agopian | fcfeb4b | 2010-03-08 11:14:20 -0800 | [diff] [blame^] | 264 | LayerBuffer::Buffer::Buffer(const ISurface::BufferHeap& buffers, |
| 265 | ssize_t offset, size_t bufferSize) |
Mathias Agopian | 1faed66 | 2010-01-20 13:24:14 -0800 | [diff] [blame] | 266 | : mBufferHeap(buffers), mSupportsCopybit(false) |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 267 | { |
| 268 | NativeBuffer& src(mNativeBuffer); |
Mathias Agopian | 3e8a81e | 2009-12-02 16:23:11 -0800 | [diff] [blame] | 269 | src.crop.l = 0; |
| 270 | src.crop.t = 0; |
| 271 | src.crop.r = buffers.w; |
| 272 | src.crop.b = buffers.h; |
| 273 | |
| 274 | src.img.w = buffers.hor_stride ?: buffers.w; |
| 275 | src.img.h = buffers.ver_stride ?: buffers.h; |
| 276 | src.img.format = buffers.format; |
| 277 | src.img.base = (void*)(intptr_t(buffers.heap->base()) + offset); |
| 278 | src.img.handle = 0; |
Mathias Agopian | 5911aa9 | 2009-06-24 16:55:59 -0700 | [diff] [blame] | 279 | |
Mathias Agopian | 863e5fd | 2009-10-29 18:29:30 -0700 | [diff] [blame] | 280 | gralloc_module_t const * module = LayerBuffer::getGrallocModule(); |
| 281 | if (module && module->perform) { |
| 282 | int err = module->perform(module, |
| 283 | GRALLOC_MODULE_PERFORM_CREATE_HANDLE_FROM_BUFFER, |
Mathias Agopian | fcfeb4b | 2010-03-08 11:14:20 -0800 | [diff] [blame^] | 284 | buffers.heap->heapID(), bufferSize, |
Mathias Agopian | 863e5fd | 2009-10-29 18:29:30 -0700 | [diff] [blame] | 285 | offset, buffers.heap->base(), |
| 286 | &src.img.handle); |
| 287 | |
Mathias Agopian | 1faed66 | 2010-01-20 13:24:14 -0800 | [diff] [blame] | 288 | // we can fail here is the passed buffer is purely software |
| 289 | mSupportsCopybit = (err == NO_ERROR); |
Mathias Agopian | 863e5fd | 2009-10-29 18:29:30 -0700 | [diff] [blame] | 290 | } |
Mathias Agopian | 3e8a81e | 2009-12-02 16:23:11 -0800 | [diff] [blame] | 291 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 292 | |
| 293 | LayerBuffer::Buffer::~Buffer() |
| 294 | { |
Mathias Agopian | 5911aa9 | 2009-06-24 16:55:59 -0700 | [diff] [blame] | 295 | NativeBuffer& src(mNativeBuffer); |
Mathias Agopian | 863e5fd | 2009-10-29 18:29:30 -0700 | [diff] [blame] | 296 | if (src.img.handle) { |
| 297 | native_handle_delete(src.img.handle); |
| 298 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 299 | } |
| 300 | |
| 301 | // ============================================================================ |
| 302 | // LayerBuffer::Source |
| 303 | // LayerBuffer::BufferSource |
| 304 | // LayerBuffer::OverlaySource |
| 305 | // ============================================================================ |
| 306 | |
| 307 | LayerBuffer::Source::Source(LayerBuffer& layer) |
| 308 | : mLayer(layer) |
| 309 | { |
| 310 | } |
| 311 | LayerBuffer::Source::~Source() { |
| 312 | } |
| 313 | void LayerBuffer::Source::onDraw(const Region& clip) const { |
| 314 | } |
| 315 | void LayerBuffer::Source::onTransaction(uint32_t flags) { |
| 316 | } |
| 317 | void LayerBuffer::Source::onVisibilityResolved( |
| 318 | const Transform& planeTransform) { |
| 319 | } |
| 320 | void LayerBuffer::Source::postBuffer(ssize_t offset) { |
| 321 | } |
| 322 | void LayerBuffer::Source::unregisterBuffers() { |
| 323 | } |
| 324 | bool LayerBuffer::Source::transformed() const { |
| 325 | return mLayer.mTransformed; |
| 326 | } |
| 327 | |
| 328 | // --------------------------------------------------------------------------- |
| 329 | |
| 330 | LayerBuffer::BufferSource::BufferSource(LayerBuffer& layer, |
| 331 | const ISurface::BufferHeap& buffers) |
Mathias Agopian | a7e3803 | 2010-02-04 17:13:06 -0800 | [diff] [blame] | 332 | : Source(layer), mStatus(NO_ERROR), mBufferSize(0), |
| 333 | mUseEGLImageDirectly(true) |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 334 | { |
| 335 | if (buffers.heap == NULL) { |
| 336 | // this is allowed, but in this case, it is illegal to receive |
| 337 | // postBuffer(). The surface just erases the framebuffer with |
| 338 | // fully transparent pixels. |
| 339 | mBufferHeap = buffers; |
| 340 | mLayer.setNeedsBlending(false); |
| 341 | return; |
| 342 | } |
| 343 | |
| 344 | status_t err = (buffers.heap->heapID() >= 0) ? NO_ERROR : NO_INIT; |
| 345 | if (err != NO_ERROR) { |
| 346 | LOGE("LayerBuffer::BufferSource: invalid heap (%s)", strerror(err)); |
| 347 | mStatus = err; |
| 348 | return; |
| 349 | } |
| 350 | |
| 351 | PixelFormatInfo info; |
| 352 | err = getPixelFormatInfo(buffers.format, &info); |
| 353 | if (err != NO_ERROR) { |
| 354 | LOGE("LayerBuffer::BufferSource: invalid format %d (%s)", |
| 355 | buffers.format, strerror(err)); |
| 356 | mStatus = err; |
| 357 | return; |
| 358 | } |
| 359 | |
| 360 | if (buffers.hor_stride<0 || buffers.ver_stride<0) { |
| 361 | LOGE("LayerBuffer::BufferSource: invalid parameters " |
| 362 | "(w=%d, h=%d, xs=%d, ys=%d)", |
| 363 | buffers.w, buffers.h, buffers.hor_stride, buffers.ver_stride); |
| 364 | mStatus = BAD_VALUE; |
| 365 | return; |
| 366 | } |
| 367 | |
| 368 | mBufferHeap = buffers; |
| 369 | mLayer.setNeedsBlending((info.h_alpha - info.l_alpha) > 0); |
| 370 | mBufferSize = info.getScanlineSize(buffers.hor_stride)*buffers.ver_stride; |
| 371 | mLayer.forceVisibilityTransaction(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 372 | } |
| 373 | |
| 374 | LayerBuffer::BufferSource::~BufferSource() |
| 375 | { |
Mathias Agopian | edfd97c | 2010-01-21 16:04:56 -0800 | [diff] [blame] | 376 | class MessageDestroyTexture : public MessageBase { |
| 377 | SurfaceFlinger* flinger; |
| 378 | GLuint name; |
| 379 | public: |
| 380 | MessageDestroyTexture( |
| 381 | SurfaceFlinger* flinger, GLuint name) |
| 382 | : flinger(flinger), name(name) { } |
| 383 | virtual bool handler() { |
| 384 | glDeleteTextures(1, &name); |
| 385 | return true; |
| 386 | } |
| 387 | }; |
| 388 | |
Mathias Agopian | 1fed11c | 2009-06-23 18:08:22 -0700 | [diff] [blame] | 389 | if (mTexture.name != -1U) { |
Mathias Agopian | edfd97c | 2010-01-21 16:04:56 -0800 | [diff] [blame] | 390 | // GL textures can only be destroyed from the GL thread |
| 391 | mLayer.mFlinger->mEventQueue.postMessage( |
| 392 | new MessageDestroyTexture(mLayer.mFlinger.get(), mTexture.name) ); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 393 | } |
Mathias Agopian | 54ba51d | 2009-10-26 20:12:37 -0700 | [diff] [blame] | 394 | if (mTexture.image != EGL_NO_IMAGE_KHR) { |
| 395 | EGLDisplay dpy(mLayer.mFlinger->graphicPlane(0).getEGLDisplay()); |
| 396 | eglDestroyImageKHR(dpy, mTexture.image); |
Mathias Agopian | 240c9fe | 2009-06-25 15:39:25 -0700 | [diff] [blame] | 397 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 398 | } |
| 399 | |
| 400 | void LayerBuffer::BufferSource::postBuffer(ssize_t offset) |
| 401 | { |
| 402 | ISurface::BufferHeap buffers; |
| 403 | { // scope for the lock |
Mathias Agopian | 4d2de2c | 2009-09-08 20:02:47 -0700 | [diff] [blame] | 404 | Mutex::Autolock _l(mBufferSourceLock); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 405 | buffers = mBufferHeap; |
| 406 | if (buffers.heap != 0) { |
| 407 | const size_t memorySize = buffers.heap->getSize(); |
| 408 | if ((size_t(offset) + mBufferSize) > memorySize) { |
| 409 | LOGE("LayerBuffer::BufferSource::postBuffer() " |
| 410 | "invalid buffer (offset=%d, size=%d, heap-size=%d", |
| 411 | int(offset), int(mBufferSize), int(memorySize)); |
| 412 | return; |
| 413 | } |
| 414 | } |
| 415 | } |
| 416 | |
| 417 | sp<Buffer> buffer; |
| 418 | if (buffers.heap != 0) { |
Mathias Agopian | fcfeb4b | 2010-03-08 11:14:20 -0800 | [diff] [blame^] | 419 | buffer = new LayerBuffer::Buffer(buffers, offset, mBufferSize); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 420 | if (buffer->getStatus() != NO_ERROR) |
| 421 | buffer.clear(); |
| 422 | setBuffer(buffer); |
| 423 | mLayer.invalidate(); |
| 424 | } |
| 425 | } |
| 426 | |
| 427 | void LayerBuffer::BufferSource::unregisterBuffers() |
| 428 | { |
Mathias Agopian | 4d2de2c | 2009-09-08 20:02:47 -0700 | [diff] [blame] | 429 | Mutex::Autolock _l(mBufferSourceLock); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 430 | mBufferHeap.heap.clear(); |
| 431 | mBuffer.clear(); |
| 432 | mLayer.invalidate(); |
| 433 | } |
| 434 | |
| 435 | sp<LayerBuffer::Buffer> LayerBuffer::BufferSource::getBuffer() const |
| 436 | { |
Mathias Agopian | 4d2de2c | 2009-09-08 20:02:47 -0700 | [diff] [blame] | 437 | Mutex::Autolock _l(mBufferSourceLock); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 438 | return mBuffer; |
| 439 | } |
| 440 | |
| 441 | void LayerBuffer::BufferSource::setBuffer(const sp<LayerBuffer::Buffer>& buffer) |
| 442 | { |
Mathias Agopian | 4d2de2c | 2009-09-08 20:02:47 -0700 | [diff] [blame] | 443 | Mutex::Autolock _l(mBufferSourceLock); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 444 | mBuffer = buffer; |
| 445 | } |
| 446 | |
| 447 | bool LayerBuffer::BufferSource::transformed() const |
| 448 | { |
| 449 | return mBufferHeap.transform ? true : Source::transformed(); |
| 450 | } |
| 451 | |
| 452 | void LayerBuffer::BufferSource::onDraw(const Region& clip) const |
| 453 | { |
Mathias Agopian | 1fed11c | 2009-06-23 18:08:22 -0700 | [diff] [blame] | 454 | sp<Buffer> ourBuffer(getBuffer()); |
| 455 | if (UNLIKELY(ourBuffer == 0)) { |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 456 | // nothing to do, we don't have a buffer |
| 457 | mLayer.clearWithOpenGL(clip); |
| 458 | return; |
| 459 | } |
| 460 | |
Mathias Agopian | 69029eb | 2009-06-23 21:11:43 -0700 | [diff] [blame] | 461 | status_t err = NO_ERROR; |
| 462 | NativeBuffer src(ourBuffer->getBuffer()); |
Mathias Agopian | 454ea68 | 2009-09-08 23:52:08 -0700 | [diff] [blame] | 463 | const Rect transformedBounds(mLayer.getTransformedBounds()); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 464 | |
Mathias Agopian | 8c3b597 | 2010-01-21 16:27:30 -0800 | [diff] [blame] | 465 | if (UNLIKELY(mTexture.name == -1LU)) { |
| 466 | mTexture.name = mLayer.createTexture(); |
| 467 | } |
| 468 | |
Mathias Agopian | 54ba51d | 2009-10-26 20:12:37 -0700 | [diff] [blame] | 469 | #if defined(EGL_ANDROID_image_native_buffer) |
| 470 | if (mLayer.mFlags & DisplayHardware::DIRECT_TEXTURE) { |
Mathias Agopian | a7e3803 | 2010-02-04 17:13:06 -0800 | [diff] [blame] | 471 | err = INVALID_OPERATION; |
| 472 | if (ourBuffer->supportsCopybit()) { |
Mathias Agopian | fcfeb4b | 2010-03-08 11:14:20 -0800 | [diff] [blame^] | 473 | |
| 474 | // there are constraints on buffers used by the GPU and these may not |
| 475 | // be honored here. We need to change the API so the buffers |
| 476 | // are allocated with gralloc. For now disable this code-path |
| 477 | #if 0 |
Mathias Agopian | a7e3803 | 2010-02-04 17:13:06 -0800 | [diff] [blame] | 478 | // First, try to use the buffer as an EGLImage directly |
| 479 | if (mUseEGLImageDirectly) { |
Mathias Agopian | bbc21b0 | 2009-11-05 23:08:00 -0800 | [diff] [blame] | 480 | // NOTE: Assume the buffer is allocated with the proper USAGE flags |
Mathias Agopian | c9e4a12 | 2010-02-12 18:50:28 -0800 | [diff] [blame] | 481 | |
Mathias Agopian | a7e3803 | 2010-02-04 17:13:06 -0800 | [diff] [blame] | 482 | sp<GraphicBuffer> buffer = new GraphicBuffer( |
| 483 | src.img.w, src.img.h, src.img.format, |
| 484 | GraphicBuffer::USAGE_HW_TEXTURE, |
| 485 | src.img.w, src.img.handle, false); |
Mathias Agopian | c9e4a12 | 2010-02-12 18:50:28 -0800 | [diff] [blame] | 486 | |
Mathias Agopian | a7e3803 | 2010-02-04 17:13:06 -0800 | [diff] [blame] | 487 | err = mLayer.initializeEglImage(buffer, &mTexture); |
Mathias Agopian | ecc99c0 | 2010-01-20 13:56:07 -0800 | [diff] [blame] | 488 | if (err != NO_ERROR) { |
Mathias Agopian | a7e3803 | 2010-02-04 17:13:06 -0800 | [diff] [blame] | 489 | mUseEGLImageDirectly = false; |
Mathias Agopian | ecc99c0 | 2010-01-20 13:56:07 -0800 | [diff] [blame] | 490 | } |
Mathias Agopian | bbc21b0 | 2009-11-05 23:08:00 -0800 | [diff] [blame] | 491 | } |
Mathias Agopian | fcfeb4b | 2010-03-08 11:14:20 -0800 | [diff] [blame^] | 492 | #endif |
| 493 | |
Mathias Agopian | a7e3803 | 2010-02-04 17:13:06 -0800 | [diff] [blame] | 494 | copybit_device_t* copybit = mLayer.mBlitEngine; |
| 495 | if (copybit && err != NO_ERROR) { |
| 496 | // create our EGLImageKHR the first time |
| 497 | err = initTempBuffer(); |
| 498 | if (err == NO_ERROR) { |
| 499 | // NOTE: Assume the buffer is allocated with the proper USAGE flags |
| 500 | const NativeBuffer& dst(mTempBuffer); |
| 501 | region_iterator clip(Region(Rect(dst.crop.r, dst.crop.b))); |
| 502 | copybit->set_parameter(copybit, COPYBIT_TRANSFORM, 0); |
| 503 | copybit->set_parameter(copybit, COPYBIT_PLANE_ALPHA, 0xFF); |
| 504 | copybit->set_parameter(copybit, COPYBIT_DITHER, COPYBIT_ENABLE); |
| 505 | err = copybit->stretch(copybit, &dst.img, &src.img, |
| 506 | &dst.crop, &src.crop, &clip); |
| 507 | if (err != NO_ERROR) { |
| 508 | clearTempBufferImage(); |
| 509 | } |
| 510 | } |
| 511 | } |
Mathias Agopian | bbc21b0 | 2009-11-05 23:08:00 -0800 | [diff] [blame] | 512 | } |
Mathias Agopian | 69029eb | 2009-06-23 21:11:43 -0700 | [diff] [blame] | 513 | } |
Mathias Agopian | 2ab55a4 | 2009-06-24 22:39:26 -0700 | [diff] [blame] | 514 | #endif |
Mathias Agopian | 54ba51d | 2009-10-26 20:12:37 -0700 | [diff] [blame] | 515 | else { |
| 516 | err = INVALID_OPERATION; |
| 517 | } |
| 518 | |
| 519 | if (err != NO_ERROR) { |
Mathias Agopian | df2d929 | 2009-10-28 21:00:29 -0700 | [diff] [blame] | 520 | // slower fallback |
Mathias Agopian | 1fed11c | 2009-06-23 18:08:22 -0700 | [diff] [blame] | 521 | GGLSurface t; |
| 522 | t.version = sizeof(GGLSurface); |
| 523 | t.width = src.crop.r; |
| 524 | t.height = src.crop.b; |
| 525 | t.stride = src.img.w; |
| 526 | t.vstride= src.img.h; |
| 527 | t.format = src.img.format; |
Mathias Agopian | 5911aa9 | 2009-06-24 16:55:59 -0700 | [diff] [blame] | 528 | t.data = (GGLubyte*)src.img.base; |
Mathias Agopian | 1fed11c | 2009-06-23 18:08:22 -0700 | [diff] [blame] | 529 | const Region dirty(Rect(t.width, t.height)); |
Mathias Agopian | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 530 | mLayer.loadTexture(&mTexture, dirty, t); |
Mathias Agopian | 0926f50 | 2009-05-04 14:17:04 -0700 | [diff] [blame] | 531 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 532 | |
Mathias Agopian | 54ba51d | 2009-10-26 20:12:37 -0700 | [diff] [blame] | 533 | mTexture.transform = mBufferHeap.transform; |
| 534 | mLayer.drawWithOpenGL(clip, mTexture); |
| 535 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 536 | |
Mathias Agopian | c5e181f | 2009-12-09 14:32:56 -0800 | [diff] [blame] | 537 | status_t LayerBuffer::BufferSource::initTempBuffer() const |
| 538 | { |
| 539 | // figure out the size we need now |
| 540 | const ISurface::BufferHeap& buffers(mBufferHeap); |
| 541 | uint32_t w = mLayer.mTransformedBounds.width(); |
| 542 | uint32_t h = mLayer.mTransformedBounds.height(); |
| 543 | if (buffers.w * h != buffers.h * w) { |
| 544 | int t = w; w = h; h = t; |
| 545 | } |
| 546 | |
Mathias Agopian | 5fdea8d | 2010-01-20 14:31:53 -0800 | [diff] [blame] | 547 | // we're in the copybit case, so make sure we can handle this blit |
| 548 | // we don't have to keep the aspect ratio here |
| 549 | copybit_device_t* copybit = mLayer.mBlitEngine; |
| 550 | const int down = copybit->get(copybit, COPYBIT_MINIFICATION_LIMIT); |
| 551 | const int up = copybit->get(copybit, COPYBIT_MAGNIFICATION_LIMIT); |
| 552 | if (buffers.w > w*down) w = buffers.w / down; |
| 553 | else if (w > buffers.w*up) w = buffers.w*up; |
| 554 | if (buffers.h > h*down) h = buffers.h / down; |
| 555 | else if (h > buffers.h*up) h = buffers.h*up; |
| 556 | |
Mathias Agopian | c5e181f | 2009-12-09 14:32:56 -0800 | [diff] [blame] | 557 | if (mTexture.image != EGL_NO_IMAGE_KHR) { |
| 558 | // we have an EGLImage, make sure the needed size didn't change |
| 559 | if (w!=mTexture.width || h!= mTexture.height) { |
| 560 | // delete the EGLImage and texture |
Mathias Agopian | ecc99c0 | 2010-01-20 13:56:07 -0800 | [diff] [blame] | 561 | clearTempBufferImage(); |
Mathias Agopian | c5e181f | 2009-12-09 14:32:56 -0800 | [diff] [blame] | 562 | } else { |
| 563 | // we're good, we have an EGLImageKHR and it's (still) the |
| 564 | // right size |
| 565 | return NO_ERROR; |
| 566 | } |
| 567 | } |
| 568 | |
| 569 | // figure out if we need linear filtering |
| 570 | if (buffers.w * h == buffers.h * w) { |
| 571 | // same pixel area, don't use filtering |
| 572 | mLayer.mUseLinearFiltering = false; |
| 573 | } |
| 574 | |
| 575 | // Allocate a temporary buffer and create the corresponding EGLImageKHR |
Mathias Agopian | c9e4a12 | 2010-02-12 18:50:28 -0800 | [diff] [blame] | 576 | // once the EGLImage has been created we don't need the |
| 577 | // graphic buffer reference anymore. |
| 578 | sp<GraphicBuffer> buffer = new GraphicBuffer( |
Mathias Agopian | c5e181f | 2009-12-09 14:32:56 -0800 | [diff] [blame] | 579 | w, h, HAL_PIXEL_FORMAT_RGB_565, |
| 580 | GraphicBuffer::USAGE_HW_TEXTURE | |
| 581 | GraphicBuffer::USAGE_HW_2D); |
| 582 | |
Mathias Agopian | c9e4a12 | 2010-02-12 18:50:28 -0800 | [diff] [blame] | 583 | status_t err = buffer->initCheck(); |
Mathias Agopian | c5e181f | 2009-12-09 14:32:56 -0800 | [diff] [blame] | 584 | if (err == NO_ERROR) { |
| 585 | NativeBuffer& dst(mTempBuffer); |
Mathias Agopian | c9e4a12 | 2010-02-12 18:50:28 -0800 | [diff] [blame] | 586 | dst.img.w = buffer->getStride(); |
Mathias Agopian | c5e181f | 2009-12-09 14:32:56 -0800 | [diff] [blame] | 587 | dst.img.h = h; |
Mathias Agopian | c9e4a12 | 2010-02-12 18:50:28 -0800 | [diff] [blame] | 588 | dst.img.format = buffer->getPixelFormat(); |
| 589 | dst.img.handle = (native_handle_t *)buffer->handle; |
Mathias Agopian | c5e181f | 2009-12-09 14:32:56 -0800 | [diff] [blame] | 590 | dst.img.base = 0; |
| 591 | dst.crop.l = 0; |
| 592 | dst.crop.t = 0; |
| 593 | dst.crop.r = w; |
| 594 | dst.crop.b = h; |
| 595 | |
Mathias Agopian | c9e4a12 | 2010-02-12 18:50:28 -0800 | [diff] [blame] | 596 | err = mLayer.initializeEglImage(buffer, &mTexture); |
Mathias Agopian | c5e181f | 2009-12-09 14:32:56 -0800 | [diff] [blame] | 597 | } |
| 598 | |
| 599 | return err; |
| 600 | } |
| 601 | |
Mathias Agopian | ecc99c0 | 2010-01-20 13:56:07 -0800 | [diff] [blame] | 602 | void LayerBuffer::BufferSource::clearTempBufferImage() const |
| 603 | { |
Mathias Agopian | 8c3b597 | 2010-01-21 16:27:30 -0800 | [diff] [blame] | 604 | // delete the image |
Mathias Agopian | ecc99c0 | 2010-01-20 13:56:07 -0800 | [diff] [blame] | 605 | EGLDisplay dpy(mLayer.mFlinger->graphicPlane(0).getEGLDisplay()); |
Mathias Agopian | ecc99c0 | 2010-01-20 13:56:07 -0800 | [diff] [blame] | 606 | eglDestroyImageKHR(dpy, mTexture.image); |
Mathias Agopian | 8c3b597 | 2010-01-21 16:27:30 -0800 | [diff] [blame] | 607 | |
| 608 | // and the associated texture (recreate a name) |
| 609 | glDeleteTextures(1, &mTexture.name); |
Mathias Agopian | ecc99c0 | 2010-01-20 13:56:07 -0800 | [diff] [blame] | 610 | Texture defaultTexture; |
| 611 | mTexture = defaultTexture; |
Mathias Agopian | 8c3b597 | 2010-01-21 16:27:30 -0800 | [diff] [blame] | 612 | mTexture.name = mLayer.createTexture(); |
Mathias Agopian | ecc99c0 | 2010-01-20 13:56:07 -0800 | [diff] [blame] | 613 | } |
| 614 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 615 | // --------------------------------------------------------------------------- |
| 616 | |
| 617 | LayerBuffer::OverlaySource::OverlaySource(LayerBuffer& layer, |
| 618 | sp<OverlayRef>* overlayRef, |
Chih-Chung Chang | 52e7200 | 2010-01-21 17:31:06 -0800 | [diff] [blame] | 619 | uint32_t w, uint32_t h, int32_t format, int32_t orientation) |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 620 | : Source(layer), mVisibilityChanged(false), |
Chih-Chung Chang | 52e7200 | 2010-01-21 17:31:06 -0800 | [diff] [blame] | 621 | mOverlay(0), mOverlayHandle(0), mOverlayDevice(0), mOrientation(orientation) |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 622 | { |
| 623 | overlay_control_device_t* overlay_dev = mLayer.mFlinger->getOverlayEngine(); |
| 624 | if (overlay_dev == NULL) { |
| 625 | // overlays not supported |
| 626 | return; |
| 627 | } |
| 628 | |
| 629 | mOverlayDevice = overlay_dev; |
| 630 | overlay_t* overlay = overlay_dev->createOverlay(overlay_dev, w, h, format); |
| 631 | if (overlay == NULL) { |
| 632 | // couldn't create the overlay (no memory? no more overlays?) |
| 633 | return; |
| 634 | } |
| 635 | |
| 636 | // enable dithering... |
| 637 | overlay_dev->setParameter(overlay_dev, overlay, |
| 638 | OVERLAY_DITHER, OVERLAY_ENABLE); |
| 639 | |
| 640 | mOverlay = overlay; |
| 641 | mWidth = overlay->w; |
| 642 | mHeight = overlay->h; |
| 643 | mFormat = overlay->format; |
| 644 | mWidthStride = overlay->w_stride; |
| 645 | mHeightStride = overlay->h_stride; |
Rebecca Schultz Zavin | 1000170 | 2009-07-21 16:17:59 -0700 | [diff] [blame] | 646 | mInitialized = false; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 647 | |
| 648 | mOverlayHandle = overlay->getHandleRef(overlay); |
| 649 | |
Mathias Agopian | 454ea68 | 2009-09-08 23:52:08 -0700 | [diff] [blame] | 650 | sp<OverlayChannel> channel = new OverlayChannel( &layer ); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 651 | |
| 652 | *overlayRef = new OverlayRef(mOverlayHandle, channel, |
| 653 | mWidth, mHeight, mFormat, mWidthStride, mHeightStride); |
Benny Wong | 5643261 | 2009-09-16 14:48:52 -0500 | [diff] [blame] | 654 | mLayer.mFlinger->signalEvent(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 655 | } |
| 656 | |
| 657 | LayerBuffer::OverlaySource::~OverlaySource() |
| 658 | { |
| 659 | if (mOverlay && mOverlayDevice) { |
| 660 | overlay_control_device_t* overlay_dev = mOverlayDevice; |
| 661 | overlay_dev->destroyOverlay(overlay_dev, mOverlay); |
| 662 | } |
| 663 | } |
| 664 | |
Rebecca Schultz Zavin | 96df49b | 2009-07-20 21:18:04 -0700 | [diff] [blame] | 665 | void LayerBuffer::OverlaySource::onDraw(const Region& clip) const |
| 666 | { |
Mathias Agopian | b8cfc0f | 2009-09-15 19:31:28 -0700 | [diff] [blame] | 667 | // this would be where the color-key would be set, should we need it. |
Rebecca Schultz Zavin | 29aa74c | 2009-09-01 23:06:45 -0700 | [diff] [blame] | 668 | GLclampx red = 0; |
| 669 | GLclampx green = 0; |
Mathias Agopian | b8cfc0f | 2009-09-15 19:31:28 -0700 | [diff] [blame] | 670 | GLclampx blue = 0; |
Rebecca Schultz Zavin | 29aa74c | 2009-09-01 23:06:45 -0700 | [diff] [blame] | 671 | mLayer.clearWithOpenGL(clip, red, green, blue, 0); |
Rebecca Schultz Zavin | 96df49b | 2009-07-20 21:18:04 -0700 | [diff] [blame] | 672 | } |
| 673 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 674 | void LayerBuffer::OverlaySource::onTransaction(uint32_t flags) |
| 675 | { |
| 676 | const Layer::State& front(mLayer.drawingState()); |
| 677 | const Layer::State& temp(mLayer.currentState()); |
| 678 | if (temp.sequence != front.sequence) { |
| 679 | mVisibilityChanged = true; |
| 680 | } |
| 681 | } |
| 682 | |
| 683 | void LayerBuffer::OverlaySource::onVisibilityResolved( |
| 684 | const Transform& planeTransform) |
| 685 | { |
| 686 | // this code-path must be as tight as possible, it's called each time |
| 687 | // the screen is composited. |
| 688 | if (UNLIKELY(mOverlay != 0)) { |
Rebecca Schultz Zavin | 1000170 | 2009-07-21 16:17:59 -0700 | [diff] [blame] | 689 | if (mVisibilityChanged || !mInitialized) { |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 690 | mVisibilityChanged = false; |
Rebecca Schultz Zavin | 1000170 | 2009-07-21 16:17:59 -0700 | [diff] [blame] | 691 | mInitialized = true; |
Mathias Agopian | 454ea68 | 2009-09-08 23:52:08 -0700 | [diff] [blame] | 692 | const Rect bounds(mLayer.getTransformedBounds()); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 693 | int x = bounds.left; |
| 694 | int y = bounds.top; |
| 695 | int w = bounds.width(); |
| 696 | int h = bounds.height(); |
| 697 | |
| 698 | // we need a lock here to protect "destroy" |
Mathias Agopian | 4d2de2c | 2009-09-08 20:02:47 -0700 | [diff] [blame] | 699 | Mutex::Autolock _l(mOverlaySourceLock); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 700 | if (mOverlay) { |
| 701 | overlay_control_device_t* overlay_dev = mOverlayDevice; |
| 702 | overlay_dev->setPosition(overlay_dev, mOverlay, x,y,w,h); |
Chih-Chung Chang | 52e7200 | 2010-01-21 17:31:06 -0800 | [diff] [blame] | 703 | // we need to combine the layer orientation and the |
| 704 | // user-requested orientation. |
| 705 | Transform finalTransform = Transform(mOrientation) * |
| 706 | Transform(mLayer.getOrientation()); |
Rebecca Schultz Zavin | 1000170 | 2009-07-21 16:17:59 -0700 | [diff] [blame] | 707 | overlay_dev->setParameter(overlay_dev, mOverlay, |
Chih-Chung Chang | 52e7200 | 2010-01-21 17:31:06 -0800 | [diff] [blame] | 708 | OVERLAY_TRANSFORM, finalTransform.getOrientation()); |
Rebecca Schultz Zavin | 96df49b | 2009-07-20 21:18:04 -0700 | [diff] [blame] | 709 | overlay_dev->commit(overlay_dev, mOverlay); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 710 | } |
| 711 | } |
| 712 | } |
| 713 | } |
| 714 | |
Mathias Agopian | 454ea68 | 2009-09-08 23:52:08 -0700 | [diff] [blame] | 715 | void LayerBuffer::OverlaySource::destroy() |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 716 | { |
| 717 | // we need a lock here to protect "onVisibilityResolved" |
Mathias Agopian | 4d2de2c | 2009-09-08 20:02:47 -0700 | [diff] [blame] | 718 | Mutex::Autolock _l(mOverlaySourceLock); |
Mathias Agopian | 454ea68 | 2009-09-08 23:52:08 -0700 | [diff] [blame] | 719 | if (mOverlay && mOverlayDevice) { |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 720 | overlay_control_device_t* overlay_dev = mOverlayDevice; |
| 721 | overlay_dev->destroyOverlay(overlay_dev, mOverlay); |
| 722 | mOverlay = 0; |
| 723 | } |
| 724 | } |
| 725 | |
| 726 | // --------------------------------------------------------------------------- |
| 727 | }; // namespace android |