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 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 26 | #include <ui/PixelFormat.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 27 | |
| 28 | #include "LayerBuffer.h" |
| 29 | #include "SurfaceFlinger.h" |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 30 | #include "DisplayHardware/DisplayHardware.h" |
| 31 | |
| 32 | |
| 33 | namespace android { |
| 34 | |
| 35 | // --------------------------------------------------------------------------- |
| 36 | |
| 37 | const uint32_t LayerBuffer::typeInfo = LayerBaseClient::typeInfo | 0x20; |
| 38 | const char* const LayerBuffer::typeID = "LayerBuffer"; |
| 39 | |
| 40 | // --------------------------------------------------------------------------- |
| 41 | |
| 42 | LayerBuffer::LayerBuffer(SurfaceFlinger* flinger, DisplayID display, |
| 43 | Client* client, int32_t i) |
| 44 | : LayerBaseClient(flinger, display, client, i), |
| 45 | mNeedsBlending(false) |
| 46 | { |
| 47 | } |
| 48 | |
| 49 | LayerBuffer::~LayerBuffer() |
| 50 | { |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 51 | } |
| 52 | |
Mathias Agopian | 9a11206 | 2009-04-17 19:36:26 -0700 | [diff] [blame^] | 53 | void LayerBuffer::onFirstRef() |
| 54 | { |
| 55 | mSurface = new SurfaceBuffer(mFlinger, clientIndex(), |
| 56 | const_cast<LayerBuffer *>(this)); |
| 57 | } |
| 58 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 59 | sp<LayerBaseClient::Surface> LayerBuffer::createSurface() const |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 60 | { |
Mathias Agopian | 9a11206 | 2009-04-17 19:36:26 -0700 | [diff] [blame^] | 61 | return mSurface; |
| 62 | } |
| 63 | |
| 64 | status_t LayerBuffer::ditch() |
| 65 | { |
| 66 | mSurface.clear(); |
| 67 | return NO_ERROR; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | bool LayerBuffer::needsBlending() const { |
| 71 | return mNeedsBlending; |
| 72 | } |
| 73 | |
| 74 | void LayerBuffer::setNeedsBlending(bool blending) { |
| 75 | mNeedsBlending = blending; |
| 76 | } |
| 77 | |
| 78 | void LayerBuffer::postBuffer(ssize_t offset) |
| 79 | { |
| 80 | sp<Source> source(getSource()); |
| 81 | if (source != 0) |
| 82 | source->postBuffer(offset); |
| 83 | } |
| 84 | |
| 85 | void LayerBuffer::unregisterBuffers() |
| 86 | { |
| 87 | sp<Source> source(clearSource()); |
| 88 | if (source != 0) |
| 89 | source->unregisterBuffers(); |
| 90 | } |
| 91 | |
| 92 | uint32_t LayerBuffer::doTransaction(uint32_t flags) |
| 93 | { |
| 94 | sp<Source> source(getSource()); |
| 95 | if (source != 0) |
| 96 | source->onTransaction(flags); |
| 97 | return LayerBase::doTransaction(flags); |
| 98 | } |
| 99 | |
| 100 | void LayerBuffer::unlockPageFlip(const Transform& planeTransform, |
| 101 | Region& outDirtyRegion) |
| 102 | { |
| 103 | // this code-path must be as tight as possible, it's called each time |
| 104 | // the screen is composited. |
| 105 | sp<Source> source(getSource()); |
| 106 | if (source != 0) |
| 107 | source->onVisibilityResolved(planeTransform); |
| 108 | LayerBase::unlockPageFlip(planeTransform, outDirtyRegion); |
| 109 | } |
| 110 | |
| 111 | void LayerBuffer::onDraw(const Region& clip) const |
| 112 | { |
| 113 | sp<Source> source(getSource()); |
| 114 | if (LIKELY(source != 0)) { |
| 115 | source->onDraw(clip); |
| 116 | } else { |
| 117 | clearWithOpenGL(clip); |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | bool LayerBuffer::transformed() const |
| 122 | { |
| 123 | sp<Source> source(getSource()); |
| 124 | if (LIKELY(source != 0)) |
| 125 | return source->transformed(); |
| 126 | return false; |
| 127 | } |
| 128 | |
| 129 | /** |
| 130 | * This creates a "buffer" source for this surface |
| 131 | */ |
| 132 | status_t LayerBuffer::registerBuffers(const ISurface::BufferHeap& buffers) |
| 133 | { |
| 134 | Mutex::Autolock _l(mLock); |
| 135 | if (mSource != 0) |
| 136 | return INVALID_OPERATION; |
| 137 | |
| 138 | sp<BufferSource> source = new BufferSource(*this, buffers); |
| 139 | |
| 140 | status_t result = source->getStatus(); |
| 141 | if (result == NO_ERROR) { |
| 142 | mSource = source; |
| 143 | } |
| 144 | return result; |
| 145 | } |
| 146 | |
| 147 | /** |
| 148 | * This creates an "overlay" source for this surface |
| 149 | */ |
| 150 | sp<OverlayRef> LayerBuffer::createOverlay(uint32_t w, uint32_t h, int32_t f) |
| 151 | { |
| 152 | sp<OverlayRef> result; |
| 153 | Mutex::Autolock _l(mLock); |
| 154 | if (mSource != 0) |
| 155 | return result; |
| 156 | |
| 157 | sp<OverlaySource> source = new OverlaySource(*this, &result, w, h, f); |
| 158 | if (result != 0) { |
| 159 | mSource = source; |
| 160 | } |
| 161 | return result; |
| 162 | } |
| 163 | |
| 164 | sp<LayerBuffer::Source> LayerBuffer::getSource() const { |
| 165 | Mutex::Autolock _l(mLock); |
| 166 | return mSource; |
| 167 | } |
| 168 | |
| 169 | sp<LayerBuffer::Source> LayerBuffer::clearSource() { |
| 170 | sp<Source> source; |
| 171 | Mutex::Autolock _l(mLock); |
| 172 | source = mSource; |
| 173 | mSource.clear(); |
| 174 | return source; |
| 175 | } |
| 176 | |
| 177 | // ============================================================================ |
| 178 | // LayerBuffer::SurfaceBuffer |
| 179 | // ============================================================================ |
| 180 | |
Mathias Agopian | 9a11206 | 2009-04-17 19:36:26 -0700 | [diff] [blame^] | 181 | LayerBuffer::SurfaceBuffer::SurfaceBuffer(const sp<SurfaceFlinger>& flinger, |
| 182 | SurfaceID id, const sp<LayerBuffer>& owner) |
| 183 | : LayerBaseClient::Surface(flinger, id, owner->getIdentity(), owner) |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 184 | { |
| 185 | } |
| 186 | |
| 187 | LayerBuffer::SurfaceBuffer::~SurfaceBuffer() |
| 188 | { |
| 189 | unregisterBuffers(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 190 | } |
| 191 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 192 | status_t LayerBuffer::SurfaceBuffer::registerBuffers( |
| 193 | const ISurface::BufferHeap& buffers) |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 194 | { |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 195 | sp<LayerBuffer> owner(getOwner()); |
| 196 | if (owner != 0) |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 197 | return owner->registerBuffers(buffers); |
| 198 | return NO_INIT; |
| 199 | } |
| 200 | |
| 201 | void LayerBuffer::SurfaceBuffer::postBuffer(ssize_t offset) |
| 202 | { |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 203 | sp<LayerBuffer> owner(getOwner()); |
| 204 | if (owner != 0) |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 205 | owner->postBuffer(offset); |
| 206 | } |
| 207 | |
| 208 | void LayerBuffer::SurfaceBuffer::unregisterBuffers() |
| 209 | { |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 210 | sp<LayerBuffer> owner(getOwner()); |
| 211 | if (owner != 0) |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 212 | owner->unregisterBuffers(); |
| 213 | } |
| 214 | |
| 215 | sp<OverlayRef> LayerBuffer::SurfaceBuffer::createOverlay( |
| 216 | uint32_t w, uint32_t h, int32_t format) { |
| 217 | sp<OverlayRef> result; |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 218 | sp<LayerBuffer> owner(getOwner()); |
| 219 | if (owner != 0) |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 220 | result = owner->createOverlay(w, h, format); |
| 221 | return result; |
| 222 | } |
| 223 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 224 | // ============================================================================ |
| 225 | // LayerBuffer::Buffer |
| 226 | // ============================================================================ |
| 227 | |
| 228 | LayerBuffer::Buffer::Buffer(const ISurface::BufferHeap& buffers, ssize_t offset) |
| 229 | : mBufferHeap(buffers) |
| 230 | { |
| 231 | NativeBuffer& src(mNativeBuffer); |
| 232 | src.crop.l = 0; |
| 233 | src.crop.t = 0; |
| 234 | src.crop.r = buffers.w; |
| 235 | src.crop.b = buffers.h; |
| 236 | src.img.w = buffers.hor_stride ?: buffers.w; |
| 237 | src.img.h = buffers.ver_stride ?: buffers.h; |
| 238 | src.img.format = buffers.format; |
| 239 | src.img.offset = offset; |
| 240 | src.img.base = buffers.heap->base(); |
| 241 | src.img.fd = buffers.heap->heapID(); |
| 242 | } |
| 243 | |
| 244 | LayerBuffer::Buffer::~Buffer() |
| 245 | { |
| 246 | } |
| 247 | |
| 248 | // ============================================================================ |
| 249 | // LayerBuffer::Source |
| 250 | // LayerBuffer::BufferSource |
| 251 | // LayerBuffer::OverlaySource |
| 252 | // ============================================================================ |
| 253 | |
| 254 | LayerBuffer::Source::Source(LayerBuffer& layer) |
| 255 | : mLayer(layer) |
| 256 | { |
| 257 | } |
| 258 | LayerBuffer::Source::~Source() { |
| 259 | } |
| 260 | void LayerBuffer::Source::onDraw(const Region& clip) const { |
| 261 | } |
| 262 | void LayerBuffer::Source::onTransaction(uint32_t flags) { |
| 263 | } |
| 264 | void LayerBuffer::Source::onVisibilityResolved( |
| 265 | const Transform& planeTransform) { |
| 266 | } |
| 267 | void LayerBuffer::Source::postBuffer(ssize_t offset) { |
| 268 | } |
| 269 | void LayerBuffer::Source::unregisterBuffers() { |
| 270 | } |
| 271 | bool LayerBuffer::Source::transformed() const { |
| 272 | return mLayer.mTransformed; |
| 273 | } |
| 274 | |
| 275 | // --------------------------------------------------------------------------- |
| 276 | |
| 277 | LayerBuffer::BufferSource::BufferSource(LayerBuffer& layer, |
| 278 | const ISurface::BufferHeap& buffers) |
| 279 | : Source(layer), mStatus(NO_ERROR), |
| 280 | mBufferSize(0), mTextureName(-1U) |
| 281 | { |
| 282 | if (buffers.heap == NULL) { |
| 283 | // this is allowed, but in this case, it is illegal to receive |
| 284 | // postBuffer(). The surface just erases the framebuffer with |
| 285 | // fully transparent pixels. |
| 286 | mBufferHeap = buffers; |
| 287 | mLayer.setNeedsBlending(false); |
| 288 | return; |
| 289 | } |
| 290 | |
| 291 | status_t err = (buffers.heap->heapID() >= 0) ? NO_ERROR : NO_INIT; |
| 292 | if (err != NO_ERROR) { |
| 293 | LOGE("LayerBuffer::BufferSource: invalid heap (%s)", strerror(err)); |
| 294 | mStatus = err; |
| 295 | return; |
| 296 | } |
| 297 | |
| 298 | PixelFormatInfo info; |
| 299 | err = getPixelFormatInfo(buffers.format, &info); |
| 300 | if (err != NO_ERROR) { |
| 301 | LOGE("LayerBuffer::BufferSource: invalid format %d (%s)", |
| 302 | buffers.format, strerror(err)); |
| 303 | mStatus = err; |
| 304 | return; |
| 305 | } |
| 306 | |
| 307 | if (buffers.hor_stride<0 || buffers.ver_stride<0) { |
| 308 | LOGE("LayerBuffer::BufferSource: invalid parameters " |
| 309 | "(w=%d, h=%d, xs=%d, ys=%d)", |
| 310 | buffers.w, buffers.h, buffers.hor_stride, buffers.ver_stride); |
| 311 | mStatus = BAD_VALUE; |
| 312 | return; |
| 313 | } |
| 314 | |
| 315 | mBufferHeap = buffers; |
| 316 | mLayer.setNeedsBlending((info.h_alpha - info.l_alpha) > 0); |
| 317 | mBufferSize = info.getScanlineSize(buffers.hor_stride)*buffers.ver_stride; |
| 318 | mLayer.forceVisibilityTransaction(); |
| 319 | |
| 320 | } |
| 321 | |
| 322 | LayerBuffer::BufferSource::~BufferSource() |
| 323 | { |
| 324 | if (mTextureName != -1U) { |
| 325 | LayerBase::deletedTextures.add(mTextureName); |
| 326 | } |
| 327 | } |
| 328 | |
| 329 | void LayerBuffer::BufferSource::postBuffer(ssize_t offset) |
| 330 | { |
| 331 | ISurface::BufferHeap buffers; |
| 332 | { // scope for the lock |
| 333 | Mutex::Autolock _l(mLock); |
| 334 | buffers = mBufferHeap; |
| 335 | if (buffers.heap != 0) { |
| 336 | const size_t memorySize = buffers.heap->getSize(); |
| 337 | if ((size_t(offset) + mBufferSize) > memorySize) { |
| 338 | LOGE("LayerBuffer::BufferSource::postBuffer() " |
| 339 | "invalid buffer (offset=%d, size=%d, heap-size=%d", |
| 340 | int(offset), int(mBufferSize), int(memorySize)); |
| 341 | return; |
| 342 | } |
| 343 | } |
| 344 | } |
| 345 | |
| 346 | sp<Buffer> buffer; |
| 347 | if (buffers.heap != 0) { |
| 348 | buffer = new LayerBuffer::Buffer(buffers, offset); |
| 349 | if (buffer->getStatus() != NO_ERROR) |
| 350 | buffer.clear(); |
| 351 | setBuffer(buffer); |
| 352 | mLayer.invalidate(); |
| 353 | } |
| 354 | } |
| 355 | |
| 356 | void LayerBuffer::BufferSource::unregisterBuffers() |
| 357 | { |
| 358 | Mutex::Autolock _l(mLock); |
| 359 | mBufferHeap.heap.clear(); |
| 360 | mBuffer.clear(); |
| 361 | mLayer.invalidate(); |
| 362 | } |
| 363 | |
| 364 | sp<LayerBuffer::Buffer> LayerBuffer::BufferSource::getBuffer() const |
| 365 | { |
| 366 | Mutex::Autolock _l(mLock); |
| 367 | return mBuffer; |
| 368 | } |
| 369 | |
| 370 | void LayerBuffer::BufferSource::setBuffer(const sp<LayerBuffer::Buffer>& buffer) |
| 371 | { |
| 372 | Mutex::Autolock _l(mLock); |
| 373 | mBuffer = buffer; |
| 374 | } |
| 375 | |
| 376 | bool LayerBuffer::BufferSource::transformed() const |
| 377 | { |
| 378 | return mBufferHeap.transform ? true : Source::transformed(); |
| 379 | } |
| 380 | |
| 381 | void LayerBuffer::BufferSource::onDraw(const Region& clip) const |
| 382 | { |
| 383 | sp<Buffer> buffer(getBuffer()); |
| 384 | if (UNLIKELY(buffer == 0)) { |
| 385 | // nothing to do, we don't have a buffer |
| 386 | mLayer.clearWithOpenGL(clip); |
| 387 | return; |
| 388 | } |
| 389 | |
| 390 | status_t err = NO_ERROR; |
| 391 | NativeBuffer src(buffer->getBuffer()); |
| 392 | const Rect& transformedBounds = mLayer.getTransformedBounds(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 393 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 394 | // FIXME: We should model this after the overlay stuff |
| 395 | |
| 396 | if (UNLIKELY(mTextureName == -1LU)) { |
| 397 | mTextureName = mLayer.createTexture(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 398 | } |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 399 | GLuint w = 0; |
| 400 | GLuint h = 0; |
| 401 | GGLSurface t; |
| 402 | t.version = sizeof(GGLSurface); |
| 403 | t.width = src.crop.r; |
| 404 | t.height = src.crop.b; |
| 405 | t.stride = src.img.w; |
| 406 | t.vstride= src.img.h; |
| 407 | t.format = src.img.format; |
| 408 | t.data = (GGLubyte*)(intptr_t(src.img.base) + src.img.offset); |
| 409 | const Region dirty(Rect(t.width, t.height)); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 410 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 411 | // FIXME: Use EGLImage extension for this |
| 412 | mLayer.loadTexture(dirty, mTextureName, t, w, h); |
| 413 | mLayer.drawWithOpenGL(clip, mTextureName, t, mBufferHeap.transform); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 414 | } |
| 415 | |
| 416 | |
| 417 | // --------------------------------------------------------------------------- |
| 418 | |
| 419 | LayerBuffer::OverlaySource::OverlaySource(LayerBuffer& layer, |
| 420 | sp<OverlayRef>* overlayRef, |
| 421 | uint32_t w, uint32_t h, int32_t format) |
| 422 | : Source(layer), mVisibilityChanged(false), |
| 423 | mOverlay(0), mOverlayHandle(0), mOverlayDevice(0) |
| 424 | { |
| 425 | overlay_control_device_t* overlay_dev = mLayer.mFlinger->getOverlayEngine(); |
| 426 | if (overlay_dev == NULL) { |
| 427 | // overlays not supported |
| 428 | return; |
| 429 | } |
| 430 | |
| 431 | mOverlayDevice = overlay_dev; |
| 432 | overlay_t* overlay = overlay_dev->createOverlay(overlay_dev, w, h, format); |
| 433 | if (overlay == NULL) { |
| 434 | // couldn't create the overlay (no memory? no more overlays?) |
| 435 | return; |
| 436 | } |
| 437 | |
| 438 | // enable dithering... |
| 439 | overlay_dev->setParameter(overlay_dev, overlay, |
| 440 | OVERLAY_DITHER, OVERLAY_ENABLE); |
| 441 | |
| 442 | mOverlay = overlay; |
| 443 | mWidth = overlay->w; |
| 444 | mHeight = overlay->h; |
| 445 | mFormat = overlay->format; |
| 446 | mWidthStride = overlay->w_stride; |
| 447 | mHeightStride = overlay->h_stride; |
| 448 | |
| 449 | mOverlayHandle = overlay->getHandleRef(overlay); |
| 450 | |
| 451 | // NOTE: here it's okay to acquire a reference to "this"m as long as |
| 452 | // the reference is not released before we leave the ctor. |
| 453 | sp<OverlayChannel> channel = new OverlayChannel(this); |
| 454 | |
| 455 | *overlayRef = new OverlayRef(mOverlayHandle, channel, |
| 456 | mWidth, mHeight, mFormat, mWidthStride, mHeightStride); |
| 457 | } |
| 458 | |
| 459 | LayerBuffer::OverlaySource::~OverlaySource() |
| 460 | { |
| 461 | if (mOverlay && mOverlayDevice) { |
| 462 | overlay_control_device_t* overlay_dev = mOverlayDevice; |
| 463 | overlay_dev->destroyOverlay(overlay_dev, mOverlay); |
| 464 | } |
| 465 | } |
| 466 | |
| 467 | void LayerBuffer::OverlaySource::onTransaction(uint32_t flags) |
| 468 | { |
| 469 | const Layer::State& front(mLayer.drawingState()); |
| 470 | const Layer::State& temp(mLayer.currentState()); |
| 471 | if (temp.sequence != front.sequence) { |
| 472 | mVisibilityChanged = true; |
| 473 | } |
| 474 | } |
| 475 | |
| 476 | void LayerBuffer::OverlaySource::onVisibilityResolved( |
| 477 | const Transform& planeTransform) |
| 478 | { |
| 479 | // this code-path must be as tight as possible, it's called each time |
| 480 | // the screen is composited. |
| 481 | if (UNLIKELY(mOverlay != 0)) { |
| 482 | if (mVisibilityChanged) { |
| 483 | mVisibilityChanged = false; |
| 484 | const Rect& bounds = mLayer.getTransformedBounds(); |
| 485 | int x = bounds.left; |
| 486 | int y = bounds.top; |
| 487 | int w = bounds.width(); |
| 488 | int h = bounds.height(); |
| 489 | |
| 490 | // we need a lock here to protect "destroy" |
| 491 | Mutex::Autolock _l(mLock); |
| 492 | if (mOverlay) { |
| 493 | overlay_control_device_t* overlay_dev = mOverlayDevice; |
| 494 | overlay_dev->setPosition(overlay_dev, mOverlay, x,y,w,h); |
| 495 | overlay_dev->setParameter(overlay_dev, mOverlay, |
| 496 | OVERLAY_TRANSFORM, mLayer.getOrientation()); |
| 497 | } |
| 498 | } |
| 499 | } |
| 500 | } |
| 501 | |
| 502 | void LayerBuffer::OverlaySource::serverDestroy() |
| 503 | { |
| 504 | mLayer.clearSource(); |
| 505 | destroyOverlay(); |
| 506 | } |
| 507 | |
| 508 | void LayerBuffer::OverlaySource::destroyOverlay() |
| 509 | { |
| 510 | // we need a lock here to protect "onVisibilityResolved" |
| 511 | Mutex::Autolock _l(mLock); |
| 512 | if (mOverlay) { |
| 513 | overlay_control_device_t* overlay_dev = mOverlayDevice; |
| 514 | overlay_dev->destroyOverlay(overlay_dev, mOverlay); |
| 515 | mOverlay = 0; |
| 516 | } |
| 517 | } |
| 518 | |
| 519 | // --------------------------------------------------------------------------- |
| 520 | }; // namespace android |