blob: 82a8e519f8738e6e9fbf892ae58c941ad91ed782 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2007 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080017#include <stdlib.h>
18#include <stdint.h>
19#include <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 Agopian6950e422009-10-05 17:07:12 -070026#include <ui/GraphicBuffer.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080027#include <ui/PixelFormat.h>
Mathias Agopiancbc4c9f2009-06-23 21:11:43 -070028#include <ui/FramebufferNativeWindow.h>
29
30#include <hardware/copybit.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080031
32#include "LayerBuffer.h"
33#include "SurfaceFlinger.h"
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080034#include "DisplayHardware/DisplayHardware.h"
35
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080036namespace android {
37
38// ---------------------------------------------------------------------------
39
40const uint32_t LayerBuffer::typeInfo = LayerBaseClient::typeInfo | 0x20;
41const char* const LayerBuffer::typeID = "LayerBuffer";
Mathias Agopian0b0722f2009-10-29 18:29:30 -070042gralloc_module_t const* LayerBuffer::sGrallocModule = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080043
44// ---------------------------------------------------------------------------
45
46LayerBuffer::LayerBuffer(SurfaceFlinger* flinger, DisplayID display,
Mathias Agopian6edf5af2009-06-19 17:00:27 -070047 const sp<Client>& client, int32_t i)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080048 : LayerBaseClient(flinger, display, client, i),
49 mNeedsBlending(false)
50{
51}
52
53LayerBuffer::~LayerBuffer()
54{
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080055}
56
Mathias Agopian6cf0db22009-04-17 19:36:26 -070057void LayerBuffer::onFirstRef()
58{
Mathias Agopianc6603952009-06-23 20:06:46 -070059 LayerBaseClient::onFirstRef();
Mathias Agopian9779b222009-09-07 16:32:45 -070060 mSurface = new SurfaceLayerBuffer(mFlinger, clientIndex(),
Mathias Agopian6cf0db22009-04-17 19:36:26 -070061 const_cast<LayerBuffer *>(this));
Mathias Agopian0b0722f2009-10-29 18:29:30 -070062
63 hw_module_t const* module = (hw_module_t const*)sGrallocModule;
64 if (!module) {
65 // NOTE: technically there is a race here, but it shouldn't
66 // cause any problem since hw_get_module() always returns
67 // the same value.
68 if (hw_get_module(GRALLOC_HARDWARE_MODULE_ID, &module) == 0) {
69 sGrallocModule = (gralloc_module_t const *)module;
70 }
71 }
Mathias Agopian6cf0db22009-04-17 19:36:26 -070072}
73
Mathias Agopian1473f462009-04-10 14:24:30 -070074sp<LayerBaseClient::Surface> LayerBuffer::createSurface() const
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080075{
Mathias Agopian6cf0db22009-04-17 19:36:26 -070076 return mSurface;
77}
78
79status_t LayerBuffer::ditch()
80{
81 mSurface.clear();
82 return NO_ERROR;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080083}
84
85bool LayerBuffer::needsBlending() const {
86 return mNeedsBlending;
87}
88
89void LayerBuffer::setNeedsBlending(bool blending) {
90 mNeedsBlending = blending;
91}
92
93void LayerBuffer::postBuffer(ssize_t offset)
94{
95 sp<Source> source(getSource());
96 if (source != 0)
97 source->postBuffer(offset);
98}
99
100void LayerBuffer::unregisterBuffers()
101{
102 sp<Source> source(clearSource());
103 if (source != 0)
104 source->unregisterBuffers();
105}
106
107uint32_t LayerBuffer::doTransaction(uint32_t flags)
108{
109 sp<Source> source(getSource());
110 if (source != 0)
111 source->onTransaction(flags);
112 return LayerBase::doTransaction(flags);
113}
114
115void LayerBuffer::unlockPageFlip(const Transform& planeTransform,
116 Region& outDirtyRegion)
117{
118 // this code-path must be as tight as possible, it's called each time
119 // the screen is composited.
120 sp<Source> source(getSource());
121 if (source != 0)
122 source->onVisibilityResolved(planeTransform);
123 LayerBase::unlockPageFlip(planeTransform, outDirtyRegion);
124}
125
126void LayerBuffer::onDraw(const Region& clip) const
127{
128 sp<Source> source(getSource());
129 if (LIKELY(source != 0)) {
130 source->onDraw(clip);
131 } else {
132 clearWithOpenGL(clip);
133 }
134}
135
136bool LayerBuffer::transformed() const
137{
138 sp<Source> source(getSource());
139 if (LIKELY(source != 0))
140 return source->transformed();
141 return false;
142}
143
Mathias Agopiana2804962009-09-08 23:52:08 -0700144void LayerBuffer::serverDestroy()
145{
146 sp<Source> source(clearSource());
147 if (source != 0) {
148 source->destroy();
149 }
150}
151
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800152/**
153 * This creates a "buffer" source for this surface
154 */
155status_t LayerBuffer::registerBuffers(const ISurface::BufferHeap& buffers)
156{
157 Mutex::Autolock _l(mLock);
158 if (mSource != 0)
159 return INVALID_OPERATION;
160
161 sp<BufferSource> source = new BufferSource(*this, buffers);
162
163 status_t result = source->getStatus();
164 if (result == NO_ERROR) {
165 mSource = source;
166 }
167 return result;
168}
169
170/**
171 * This creates an "overlay" source for this surface
172 */
173sp<OverlayRef> LayerBuffer::createOverlay(uint32_t w, uint32_t h, int32_t f)
174{
175 sp<OverlayRef> result;
176 Mutex::Autolock _l(mLock);
177 if (mSource != 0)
178 return result;
179
180 sp<OverlaySource> source = new OverlaySource(*this, &result, w, h, f);
181 if (result != 0) {
182 mSource = source;
183 }
184 return result;
185}
186
187sp<LayerBuffer::Source> LayerBuffer::getSource() const {
188 Mutex::Autolock _l(mLock);
189 return mSource;
190}
191
192sp<LayerBuffer::Source> LayerBuffer::clearSource() {
193 sp<Source> source;
194 Mutex::Autolock _l(mLock);
195 source = mSource;
196 mSource.clear();
197 return source;
198}
199
200// ============================================================================
Mathias Agopian9779b222009-09-07 16:32:45 -0700201// LayerBuffer::SurfaceLayerBuffer
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800202// ============================================================================
203
Mathias Agopian9779b222009-09-07 16:32:45 -0700204LayerBuffer::SurfaceLayerBuffer::SurfaceLayerBuffer(const sp<SurfaceFlinger>& flinger,
Mathias Agopian6cf0db22009-04-17 19:36:26 -0700205 SurfaceID id, const sp<LayerBuffer>& owner)
206 : LayerBaseClient::Surface(flinger, id, owner->getIdentity(), owner)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800207{
208}
209
Mathias Agopian9779b222009-09-07 16:32:45 -0700210LayerBuffer::SurfaceLayerBuffer::~SurfaceLayerBuffer()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800211{
212 unregisterBuffers();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800213}
214
Mathias Agopian9779b222009-09-07 16:32:45 -0700215status_t LayerBuffer::SurfaceLayerBuffer::registerBuffers(
Mathias Agopian1473f462009-04-10 14:24:30 -0700216 const ISurface::BufferHeap& buffers)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800217{
Mathias Agopian1473f462009-04-10 14:24:30 -0700218 sp<LayerBuffer> owner(getOwner());
219 if (owner != 0)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800220 return owner->registerBuffers(buffers);
221 return NO_INIT;
222}
223
Mathias Agopian9779b222009-09-07 16:32:45 -0700224void LayerBuffer::SurfaceLayerBuffer::postBuffer(ssize_t offset)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800225{
Mathias Agopian1473f462009-04-10 14:24:30 -0700226 sp<LayerBuffer> owner(getOwner());
227 if (owner != 0)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800228 owner->postBuffer(offset);
229}
230
Mathias Agopian9779b222009-09-07 16:32:45 -0700231void LayerBuffer::SurfaceLayerBuffer::unregisterBuffers()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800232{
Mathias Agopian1473f462009-04-10 14:24:30 -0700233 sp<LayerBuffer> owner(getOwner());
234 if (owner != 0)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800235 owner->unregisterBuffers();
236}
237
Mathias Agopian9779b222009-09-07 16:32:45 -0700238sp<OverlayRef> LayerBuffer::SurfaceLayerBuffer::createOverlay(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800239 uint32_t w, uint32_t h, int32_t format) {
240 sp<OverlayRef> result;
Mathias Agopian1473f462009-04-10 14:24:30 -0700241 sp<LayerBuffer> owner(getOwner());
242 if (owner != 0)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800243 result = owner->createOverlay(w, h, format);
244 return result;
245}
246
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800247// ============================================================================
248// LayerBuffer::Buffer
249// ============================================================================
250
251LayerBuffer::Buffer::Buffer(const ISurface::BufferHeap& buffers, ssize_t offset)
252 : mBufferHeap(buffers)
253{
254 NativeBuffer& src(mNativeBuffer);
Mathias Agopian0b0722f2009-10-29 18:29:30 -0700255 src.img.handle = 0;
Mathias Agopian2eab9d82009-06-24 16:55:59 -0700256
Mathias Agopian0b0722f2009-10-29 18:29:30 -0700257 gralloc_module_t const * module = LayerBuffer::getGrallocModule();
258 if (module && module->perform) {
259 int err = module->perform(module,
260 GRALLOC_MODULE_PERFORM_CREATE_HANDLE_FROM_BUFFER,
261 buffers.heap->heapID(), buffers.heap->getSize(),
262 offset, buffers.heap->base(),
263 &src.img.handle);
264
265 if (err == NO_ERROR) {
266 src.crop.l = 0;
267 src.crop.t = 0;
268 src.crop.r = buffers.w;
269 src.crop.b = buffers.h;
270
271 src.img.w = buffers.hor_stride ?: buffers.w;
272 src.img.h = buffers.ver_stride ?: buffers.h;
273 src.img.format = buffers.format;
274 src.img.base = (void*)(intptr_t(buffers.heap->base()) + offset);
275 }
276 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800277}
278
279LayerBuffer::Buffer::~Buffer()
280{
Mathias Agopian2eab9d82009-06-24 16:55:59 -0700281 NativeBuffer& src(mNativeBuffer);
Mathias Agopian0b0722f2009-10-29 18:29:30 -0700282 if (src.img.handle) {
283 native_handle_delete(src.img.handle);
284 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800285}
286
287// ============================================================================
288// LayerBuffer::Source
289// LayerBuffer::BufferSource
290// LayerBuffer::OverlaySource
291// ============================================================================
292
293LayerBuffer::Source::Source(LayerBuffer& layer)
294 : mLayer(layer)
295{
296}
297LayerBuffer::Source::~Source() {
298}
299void LayerBuffer::Source::onDraw(const Region& clip) const {
300}
301void LayerBuffer::Source::onTransaction(uint32_t flags) {
302}
303void LayerBuffer::Source::onVisibilityResolved(
304 const Transform& planeTransform) {
305}
306void LayerBuffer::Source::postBuffer(ssize_t offset) {
307}
308void LayerBuffer::Source::unregisterBuffers() {
309}
310bool LayerBuffer::Source::transformed() const {
311 return mLayer.mTransformed;
312}
313
314// ---------------------------------------------------------------------------
315
316LayerBuffer::BufferSource::BufferSource(LayerBuffer& layer,
317 const ISurface::BufferHeap& buffers)
Mathias Agopian999543b2009-06-23 18:08:22 -0700318 : Source(layer), mStatus(NO_ERROR), mBufferSize(0)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800319{
320 if (buffers.heap == NULL) {
321 // this is allowed, but in this case, it is illegal to receive
322 // postBuffer(). The surface just erases the framebuffer with
323 // fully transparent pixels.
324 mBufferHeap = buffers;
325 mLayer.setNeedsBlending(false);
326 return;
327 }
328
329 status_t err = (buffers.heap->heapID() >= 0) ? NO_ERROR : NO_INIT;
330 if (err != NO_ERROR) {
331 LOGE("LayerBuffer::BufferSource: invalid heap (%s)", strerror(err));
332 mStatus = err;
333 return;
334 }
335
336 PixelFormatInfo info;
337 err = getPixelFormatInfo(buffers.format, &info);
338 if (err != NO_ERROR) {
339 LOGE("LayerBuffer::BufferSource: invalid format %d (%s)",
340 buffers.format, strerror(err));
341 mStatus = err;
342 return;
343 }
344
345 if (buffers.hor_stride<0 || buffers.ver_stride<0) {
346 LOGE("LayerBuffer::BufferSource: invalid parameters "
347 "(w=%d, h=%d, xs=%d, ys=%d)",
348 buffers.w, buffers.h, buffers.hor_stride, buffers.ver_stride);
349 mStatus = BAD_VALUE;
350 return;
351 }
352
353 mBufferHeap = buffers;
354 mLayer.setNeedsBlending((info.h_alpha - info.l_alpha) > 0);
355 mBufferSize = info.getScanlineSize(buffers.hor_stride)*buffers.ver_stride;
356 mLayer.forceVisibilityTransaction();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800357}
358
359LayerBuffer::BufferSource::~BufferSource()
360{
Mathias Agopian999543b2009-06-23 18:08:22 -0700361 if (mTexture.name != -1U) {
362 glDeleteTextures(1, &mTexture.name);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800363 }
Mathias Agopian9042b452009-10-26 20:12:37 -0700364 if (mTexture.image != EGL_NO_IMAGE_KHR) {
365 EGLDisplay dpy(mLayer.mFlinger->graphicPlane(0).getEGLDisplay());
366 eglDestroyImageKHR(dpy, mTexture.image);
Mathias Agopian68eeb802009-06-25 15:39:25 -0700367 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800368}
369
370void LayerBuffer::BufferSource::postBuffer(ssize_t offset)
371{
372 ISurface::BufferHeap buffers;
373 { // scope for the lock
Mathias Agopianb34d1432009-09-08 20:02:47 -0700374 Mutex::Autolock _l(mBufferSourceLock);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800375 buffers = mBufferHeap;
376 if (buffers.heap != 0) {
377 const size_t memorySize = buffers.heap->getSize();
378 if ((size_t(offset) + mBufferSize) > memorySize) {
379 LOGE("LayerBuffer::BufferSource::postBuffer() "
380 "invalid buffer (offset=%d, size=%d, heap-size=%d",
381 int(offset), int(mBufferSize), int(memorySize));
382 return;
383 }
384 }
385 }
386
387 sp<Buffer> buffer;
388 if (buffers.heap != 0) {
389 buffer = new LayerBuffer::Buffer(buffers, offset);
390 if (buffer->getStatus() != NO_ERROR)
391 buffer.clear();
392 setBuffer(buffer);
393 mLayer.invalidate();
394 }
395}
396
397void LayerBuffer::BufferSource::unregisterBuffers()
398{
Mathias Agopianb34d1432009-09-08 20:02:47 -0700399 Mutex::Autolock _l(mBufferSourceLock);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800400 mBufferHeap.heap.clear();
401 mBuffer.clear();
402 mLayer.invalidate();
403}
404
405sp<LayerBuffer::Buffer> LayerBuffer::BufferSource::getBuffer() const
406{
Mathias Agopianb34d1432009-09-08 20:02:47 -0700407 Mutex::Autolock _l(mBufferSourceLock);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800408 return mBuffer;
409}
410
411void LayerBuffer::BufferSource::setBuffer(const sp<LayerBuffer::Buffer>& buffer)
412{
Mathias Agopianb34d1432009-09-08 20:02:47 -0700413 Mutex::Autolock _l(mBufferSourceLock);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800414 mBuffer = buffer;
415}
416
417bool LayerBuffer::BufferSource::transformed() const
418{
419 return mBufferHeap.transform ? true : Source::transformed();
420}
421
422void LayerBuffer::BufferSource::onDraw(const Region& clip) const
423{
Mathias Agopian999543b2009-06-23 18:08:22 -0700424 sp<Buffer> ourBuffer(getBuffer());
425 if (UNLIKELY(ourBuffer == 0)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800426 // nothing to do, we don't have a buffer
427 mLayer.clearWithOpenGL(clip);
428 return;
429 }
430
Mathias Agopiancbc4c9f2009-06-23 21:11:43 -0700431 status_t err = NO_ERROR;
432 NativeBuffer src(ourBuffer->getBuffer());
Mathias Agopiana2804962009-09-08 23:52:08 -0700433 const Rect transformedBounds(mLayer.getTransformedBounds());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800434
Mathias Agopian9042b452009-10-26 20:12:37 -0700435 if (UNLIKELY(mTexture.name == -1LU)) {
436 mTexture.name = mLayer.createTexture();
437 }
Mathias Agopiancbc4c9f2009-06-23 21:11:43 -0700438
Mathias Agopian9042b452009-10-26 20:12:37 -0700439#if defined(EGL_ANDROID_image_native_buffer)
440 if (mLayer.mFlags & DisplayHardware::DIRECT_TEXTURE) {
441 // NOTE: Assume the buffer is allocated with the proper USAGE flags
442 sp<GraphicBuffer> graphicBuffer = new GraphicBuffer(
443 src.crop.r, src.crop.b, src.img.format,
444 GraphicBuffer::USAGE_HW_TEXTURE,
445 src.img.w, src.img.handle, false);
Mathias Agopiancbc4c9f2009-06-23 21:11:43 -0700446
Mathias Agopian9042b452009-10-26 20:12:37 -0700447 err = mLayer.initializeEglImage(graphicBuffer, &mTexture);
Mathias Agopiancbc4c9f2009-06-23 21:11:43 -0700448 }
Mathias Agopian26c28b12009-06-24 22:39:26 -0700449#endif
Mathias Agopian9042b452009-10-26 20:12:37 -0700450 else {
451 err = INVALID_OPERATION;
452 }
453
454 if (err != NO_ERROR) {
Mathias Agopianf007a2f2009-10-28 21:00:29 -0700455 // slower fallback
Mathias Agopian999543b2009-06-23 18:08:22 -0700456 GGLSurface t;
457 t.version = sizeof(GGLSurface);
458 t.width = src.crop.r;
459 t.height = src.crop.b;
460 t.stride = src.img.w;
461 t.vstride= src.img.h;
462 t.format = src.img.format;
Mathias Agopian2eab9d82009-06-24 16:55:59 -0700463 t.data = (GGLubyte*)src.img.base;
Mathias Agopian999543b2009-06-23 18:08:22 -0700464 const Region dirty(Rect(t.width, t.height));
Mathias Agopian6950e422009-10-05 17:07:12 -0700465 mLayer.loadTexture(&mTexture, dirty, t);
Mathias Agopiandff8e582009-05-04 14:17:04 -0700466 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800467
Mathias Agopian9042b452009-10-26 20:12:37 -0700468 mTexture.transform = mBufferHeap.transform;
469 mLayer.drawWithOpenGL(clip, mTexture);
470}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800471
472// ---------------------------------------------------------------------------
473
474LayerBuffer::OverlaySource::OverlaySource(LayerBuffer& layer,
475 sp<OverlayRef>* overlayRef,
476 uint32_t w, uint32_t h, int32_t format)
477 : Source(layer), mVisibilityChanged(false),
478 mOverlay(0), mOverlayHandle(0), mOverlayDevice(0)
479{
480 overlay_control_device_t* overlay_dev = mLayer.mFlinger->getOverlayEngine();
481 if (overlay_dev == NULL) {
482 // overlays not supported
483 return;
484 }
485
486 mOverlayDevice = overlay_dev;
487 overlay_t* overlay = overlay_dev->createOverlay(overlay_dev, w, h, format);
488 if (overlay == NULL) {
489 // couldn't create the overlay (no memory? no more overlays?)
490 return;
491 }
492
493 // enable dithering...
494 overlay_dev->setParameter(overlay_dev, overlay,
495 OVERLAY_DITHER, OVERLAY_ENABLE);
496
497 mOverlay = overlay;
498 mWidth = overlay->w;
499 mHeight = overlay->h;
500 mFormat = overlay->format;
501 mWidthStride = overlay->w_stride;
502 mHeightStride = overlay->h_stride;
Rebecca Schultz Zavin43ab7632009-07-21 16:17:59 -0700503 mInitialized = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800504
505 mOverlayHandle = overlay->getHandleRef(overlay);
506
Mathias Agopiana2804962009-09-08 23:52:08 -0700507 sp<OverlayChannel> channel = new OverlayChannel( &layer );
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800508
509 *overlayRef = new OverlayRef(mOverlayHandle, channel,
510 mWidth, mHeight, mFormat, mWidthStride, mHeightStride);
Benny Wonge38212a2009-09-16 14:48:52 -0500511 mLayer.mFlinger->signalEvent();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800512}
513
514LayerBuffer::OverlaySource::~OverlaySource()
515{
516 if (mOverlay && mOverlayDevice) {
517 overlay_control_device_t* overlay_dev = mOverlayDevice;
518 overlay_dev->destroyOverlay(overlay_dev, mOverlay);
519 }
520}
521
Rebecca Schultz Zavin7ac5e692009-07-20 21:18:04 -0700522void LayerBuffer::OverlaySource::onDraw(const Region& clip) const
523{
Mathias Agopian8ae03842009-09-15 19:31:28 -0700524 // this would be where the color-key would be set, should we need it.
Rebecca Schultz Zavinc8546782009-09-01 23:06:45 -0700525 GLclampx red = 0;
526 GLclampx green = 0;
Mathias Agopian8ae03842009-09-15 19:31:28 -0700527 GLclampx blue = 0;
Rebecca Schultz Zavinc8546782009-09-01 23:06:45 -0700528 mLayer.clearWithOpenGL(clip, red, green, blue, 0);
Rebecca Schultz Zavin7ac5e692009-07-20 21:18:04 -0700529}
530
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800531void LayerBuffer::OverlaySource::onTransaction(uint32_t flags)
532{
533 const Layer::State& front(mLayer.drawingState());
534 const Layer::State& temp(mLayer.currentState());
535 if (temp.sequence != front.sequence) {
536 mVisibilityChanged = true;
537 }
538}
539
540void LayerBuffer::OverlaySource::onVisibilityResolved(
541 const Transform& planeTransform)
542{
543 // this code-path must be as tight as possible, it's called each time
544 // the screen is composited.
545 if (UNLIKELY(mOverlay != 0)) {
Rebecca Schultz Zavin43ab7632009-07-21 16:17:59 -0700546 if (mVisibilityChanged || !mInitialized) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800547 mVisibilityChanged = false;
Rebecca Schultz Zavin43ab7632009-07-21 16:17:59 -0700548 mInitialized = true;
Mathias Agopiana2804962009-09-08 23:52:08 -0700549 const Rect bounds(mLayer.getTransformedBounds());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800550 int x = bounds.left;
551 int y = bounds.top;
552 int w = bounds.width();
553 int h = bounds.height();
554
555 // we need a lock here to protect "destroy"
Mathias Agopianb34d1432009-09-08 20:02:47 -0700556 Mutex::Autolock _l(mOverlaySourceLock);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800557 if (mOverlay) {
558 overlay_control_device_t* overlay_dev = mOverlayDevice;
559 overlay_dev->setPosition(overlay_dev, mOverlay, x,y,w,h);
Rebecca Schultz Zavin43ab7632009-07-21 16:17:59 -0700560 overlay_dev->setParameter(overlay_dev, mOverlay,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800561 OVERLAY_TRANSFORM, mLayer.getOrientation());
Rebecca Schultz Zavin7ac5e692009-07-20 21:18:04 -0700562 overlay_dev->commit(overlay_dev, mOverlay);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800563 }
564 }
565 }
566}
567
Mathias Agopiana2804962009-09-08 23:52:08 -0700568void LayerBuffer::OverlaySource::destroy()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800569{
570 // we need a lock here to protect "onVisibilityResolved"
Mathias Agopianb34d1432009-09-08 20:02:47 -0700571 Mutex::Autolock _l(mOverlaySourceLock);
Mathias Agopiana2804962009-09-08 23:52:08 -0700572 if (mOverlay && mOverlayDevice) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800573 overlay_control_device_t* overlay_dev = mOverlayDevice;
574 overlay_dev->destroyOverlay(overlay_dev, mOverlay);
575 mOverlay = 0;
576 }
577}
578
579// ---------------------------------------------------------------------------
580}; // namespace android