2009-03-04 03:31:44 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2007 The Android Open Source Project
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
|
|
|
#include <cutils/properties.h>
|
2009-04-10 21:24:30 +00:00
|
|
|
#include <cutils/native_handle.h>
|
2009-03-04 03:31:44 +00:00
|
|
|
|
|
|
|
#include <utils/Errors.h>
|
|
|
|
#include <utils/Log.h>
|
|
|
|
#include <utils/StopWatch.h>
|
|
|
|
|
2009-10-06 00:07:12 +00:00
|
|
|
#include <ui/GraphicBuffer.h>
|
2009-03-04 03:31:44 +00:00
|
|
|
#include <ui/PixelFormat.h>
|
2010-02-10 01:46:37 +00:00
|
|
|
|
|
|
|
#include <surfaceflinger/Surface.h>
|
2009-03-04 03:31:44 +00:00
|
|
|
|
|
|
|
#include "clz.h"
|
2010-06-26 01:02:21 +00:00
|
|
|
#include "GLExtensions.h"
|
2009-03-04 03:31:44 +00:00
|
|
|
#include "Layer.h"
|
|
|
|
#include "SurfaceFlinger.h"
|
|
|
|
#include "DisplayHardware/DisplayHardware.h"
|
2010-08-11 00:14:02 +00:00
|
|
|
#include "DisplayHardware/HWComposer.h"
|
2009-03-04 03:31:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
#define DEBUG_RESIZE 0
|
|
|
|
|
|
|
|
|
|
|
|
namespace android {
|
|
|
|
|
2010-04-14 23:43:44 +00:00
|
|
|
template <typename T> inline T min(T a, T b) {
|
|
|
|
return a<b ? a : b;
|
|
|
|
}
|
|
|
|
|
2009-03-04 03:31:44 +00:00
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2010-06-03 06:28:45 +00:00
|
|
|
Layer::Layer(SurfaceFlinger* flinger,
|
|
|
|
DisplayID display, const sp<Client>& client)
|
|
|
|
: LayerBaseClient(flinger, display, client),
|
2010-06-26 01:02:21 +00:00
|
|
|
mGLExtensions(GLExtensions::getInstance()),
|
2009-09-24 02:16:27 +00:00
|
|
|
mNeedsBlending(true),
|
2010-05-11 03:06:11 +00:00
|
|
|
mNeedsDithering(false),
|
2010-06-01 22:12:58 +00:00
|
|
|
mSecure(false),
|
2011-01-19 23:27:27 +00:00
|
|
|
mProtectedByApp(false),
|
2010-06-26 01:02:21 +00:00
|
|
|
mTextureManager(),
|
2010-05-22 00:24:35 +00:00
|
|
|
mBufferManager(mTextureManager),
|
2010-12-03 05:32:29 +00:00
|
|
|
mWidth(0), mHeight(0), mNeedsScaling(false), mFixedSize(false)
|
2009-03-04 03:31:44 +00:00
|
|
|
{
|
2011-06-16 03:41:24 +00:00
|
|
|
setDestroyer(this);
|
2009-03-04 03:31:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Layer::~Layer()
|
2009-04-22 22:23:34 +00:00
|
|
|
{
|
2010-05-19 00:06:55 +00:00
|
|
|
// FIXME: must be called from the main UI thread
|
|
|
|
EGLDisplay dpy(mFlinger->graphicPlane(0).getEGLDisplay());
|
|
|
|
mBufferManager.destroy(dpy);
|
|
|
|
|
2010-06-01 22:12:58 +00:00
|
|
|
// we can use getUserClientUnsafe here because we know we're
|
|
|
|
// single-threaded at that point.
|
|
|
|
sp<UserClient> ourClient(mUserClientRef.getUserClientUnsafe());
|
|
|
|
if (ourClient != 0) {
|
|
|
|
ourClient->detachLayer(this);
|
|
|
|
}
|
2010-05-11 03:06:11 +00:00
|
|
|
}
|
|
|
|
|
2011-06-16 03:41:24 +00:00
|
|
|
void Layer::destroy(RefBase const* base) {
|
|
|
|
mFlinger->destroyLayer(static_cast<LayerBase const*>(base));
|
|
|
|
}
|
|
|
|
|
2010-06-01 22:12:58 +00:00
|
|
|
status_t Layer::setToken(const sp<UserClient>& userClient,
|
|
|
|
SharedClient* sharedClient, int32_t token)
|
2010-06-03 06:28:45 +00:00
|
|
|
{
|
2010-06-09 02:54:15 +00:00
|
|
|
sp<SharedBufferServer> lcblk = new SharedBufferServer(
|
2010-06-01 22:12:58 +00:00
|
|
|
sharedClient, token, mBufferManager.getDefaultBufferCount(),
|
|
|
|
getIdentity());
|
2010-06-03 06:28:45 +00:00
|
|
|
|
2010-06-09 02:54:15 +00:00
|
|
|
|
2010-12-14 00:49:05 +00:00
|
|
|
sp<UserClient> ourClient(mUserClientRef.getClient());
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Here it is guaranteed that userClient != ourClient
|
|
|
|
* (see UserClient::getTokenForSurface()).
|
|
|
|
*
|
|
|
|
* We release the token used by this surface in ourClient below.
|
|
|
|
* This should be safe to do so now, since this layer won't be attached
|
|
|
|
* to this client, it should be okay to reuse that id.
|
|
|
|
*
|
|
|
|
* If this causes problems, an other solution would be to keep a list
|
|
|
|
* of all the {UserClient, token} ever used and release them when the
|
|
|
|
* Layer is destroyed.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (ourClient != 0) {
|
|
|
|
ourClient->detachLayer(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
status_t err = mUserClientRef.setToken(userClient, lcblk, token);
|
2010-06-09 02:54:15 +00:00
|
|
|
LOGE_IF(err != NO_ERROR,
|
|
|
|
"ClientRef::setToken(%p, %p, %u) failed",
|
|
|
|
userClient.get(), lcblk.get(), token);
|
|
|
|
|
|
|
|
if (err == NO_ERROR) {
|
|
|
|
// we need to free the buffers associated with this surface
|
2010-06-01 22:12:58 +00:00
|
|
|
}
|
2010-06-03 06:28:45 +00:00
|
|
|
|
2010-06-01 22:12:58 +00:00
|
|
|
return err;
|
|
|
|
}
|
2010-06-03 06:28:45 +00:00
|
|
|
|
2010-06-01 22:12:58 +00:00
|
|
|
int32_t Layer::getToken() const
|
|
|
|
{
|
|
|
|
return mUserClientRef.getToken();
|
2010-06-03 06:28:45 +00:00
|
|
|
}
|
|
|
|
|
2010-06-09 02:54:15 +00:00
|
|
|
sp<UserClient> Layer::getClient() const
|
|
|
|
{
|
|
|
|
return mUserClientRef.getClient();
|
|
|
|
}
|
|
|
|
|
2010-05-11 03:06:11 +00:00
|
|
|
// called with SurfaceFlinger::mStateLock as soon as the layer is entered
|
|
|
|
// in the purgatory list
|
|
|
|
void Layer::onRemoved()
|
|
|
|
{
|
2010-06-01 22:12:58 +00:00
|
|
|
ClientRef::Access sharedClient(mUserClientRef);
|
|
|
|
SharedBufferServer* lcblk(sharedClient.get());
|
|
|
|
if (lcblk) {
|
2010-06-03 06:28:45 +00:00
|
|
|
// wake up the condition
|
|
|
|
lcblk->setStatus(NO_INIT);
|
|
|
|
}
|
2009-09-11 02:41:18 +00:00
|
|
|
}
|
fix [2068105] implement queueBuffer/lockBuffer/dequeueBuffer properly
Rewrote SurfaceFlinger's buffer management from the ground-up.
The design now support an arbitrary number of buffers per surface, however the current implementation is limited to four. Currently only 2 buffers are used in practice.
The main new feature is to be able to dequeue all buffers at once (very important when there are only two).
A client can dequeue all buffers until there are none available, it can lock all buffers except the last one that is used for composition. The client will block then, until a new buffer is enqueued.
The current implementation requires that buffers are locked in the same order they are dequeued and enqueued in the same order they are locked. Only one buffer can be locked at a time.
eg. Allowed sequence: DQ, DQ, LOCK, Q, LOCK, Q
eg. Forbidden sequence: DQ, DQ, LOCK, LOCK, Q, Q
2009-09-07 23:32:45 +00:00
|
|
|
|
2009-04-10 21:24:30 +00:00
|
|
|
sp<LayerBaseClient::Surface> Layer::createSurface() const
|
2009-03-04 03:31:44 +00:00
|
|
|
{
|
2011-02-16 03:01:06 +00:00
|
|
|
sp<Surface> sur(new SurfaceLayer(mFlinger, const_cast<Layer *>(this)));
|
|
|
|
return sur;
|
2009-03-04 03:31:44 +00:00
|
|
|
}
|
|
|
|
|
2009-06-20 00:00:27 +00:00
|
|
|
status_t Layer::setBuffers( uint32_t w, uint32_t h,
|
2009-03-04 03:31:44 +00:00
|
|
|
PixelFormat format, uint32_t flags)
|
|
|
|
{
|
2009-09-24 02:16:27 +00:00
|
|
|
// this surfaces pixel format
|
2009-03-04 03:31:44 +00:00
|
|
|
PixelFormatInfo info;
|
|
|
|
status_t err = getPixelFormatInfo(format, &info);
|
|
|
|
if (err) return err;
|
|
|
|
|
2009-09-24 02:16:27 +00:00
|
|
|
// the display's pixel format
|
|
|
|
const DisplayHardware& hw(graphicPlane(0).displayHardware());
|
2010-04-14 23:43:44 +00:00
|
|
|
uint32_t const maxSurfaceDims = min(
|
|
|
|
hw.getMaxTextureSize(), hw.getMaxViewportDims());
|
|
|
|
|
|
|
|
// never allow a surface larger than what our underlying GL implementation
|
|
|
|
// can handle.
|
|
|
|
if ((uint32_t(w)>maxSurfaceDims) || (uint32_t(h)>maxSurfaceDims)) {
|
|
|
|
return BAD_VALUE;
|
|
|
|
}
|
|
|
|
|
2009-09-24 02:16:27 +00:00
|
|
|
PixelFormatInfo displayInfo;
|
|
|
|
getPixelFormatInfo(hw.getFormat(), &displayInfo);
|
2009-10-06 01:20:39 +00:00
|
|
|
const uint32_t hwFlags = hw.getFlags();
|
|
|
|
|
fix [2068105] implement queueBuffer/lockBuffer/dequeueBuffer properly
Rewrote SurfaceFlinger's buffer management from the ground-up.
The design now support an arbitrary number of buffers per surface, however the current implementation is limited to four. Currently only 2 buffers are used in practice.
The main new feature is to be able to dequeue all buffers at once (very important when there are only two).
A client can dequeue all buffers until there are none available, it can lock all buffers except the last one that is used for composition. The client will block then, until a new buffer is enqueued.
The current implementation requires that buffers are locked in the same order they are dequeued and enqueued in the same order they are locked. Only one buffer can be locked at a time.
eg. Allowed sequence: DQ, DQ, LOCK, Q, LOCK, Q
eg. Forbidden sequence: DQ, DQ, LOCK, LOCK, Q, Q
2009-09-07 23:32:45 +00:00
|
|
|
mFormat = format;
|
2010-04-14 23:43:44 +00:00
|
|
|
mWidth = w;
|
fix [2068105] implement queueBuffer/lockBuffer/dequeueBuffer properly
Rewrote SurfaceFlinger's buffer management from the ground-up.
The design now support an arbitrary number of buffers per surface, however the current implementation is limited to four. Currently only 2 buffers are used in practice.
The main new feature is to be able to dequeue all buffers at once (very important when there are only two).
A client can dequeue all buffers until there are none available, it can lock all buffers except the last one that is used for composition. The client will block then, until a new buffer is enqueued.
The current implementation requires that buffers are locked in the same order they are dequeued and enqueued in the same order they are locked. Only one buffer can be locked at a time.
eg. Allowed sequence: DQ, DQ, LOCK, Q, LOCK, Q
eg. Forbidden sequence: DQ, DQ, LOCK, LOCK, Q, Q
2009-09-07 23:32:45 +00:00
|
|
|
mHeight = h;
|
2010-08-25 21:59:15 +00:00
|
|
|
|
|
|
|
mReqFormat = format;
|
|
|
|
mReqWidth = w;
|
|
|
|
mReqHeight = h;
|
|
|
|
|
2009-10-06 00:07:12 +00:00
|
|
|
mSecure = (flags & ISurfaceComposer::eSecure) ? true : false;
|
2011-01-19 23:27:27 +00:00
|
|
|
mProtectedByApp = (flags & ISurfaceComposer::eProtectedByApp) ? true : false;
|
2010-10-10 20:33:22 +00:00
|
|
|
mNeedsBlending = (info.h_alpha - info.l_alpha) > 0 &&
|
|
|
|
(flags & ISurfaceComposer::eOpaque) == 0;
|
2010-04-14 23:43:44 +00:00
|
|
|
|
2009-09-24 02:16:27 +00:00
|
|
|
// we use the red index
|
|
|
|
int displayRedSize = displayInfo.getSize(PixelFormatInfo::INDEX_RED);
|
|
|
|
int layerRedsize = info.getSize(PixelFormatInfo::INDEX_RED);
|
|
|
|
mNeedsDithering = layerRedsize > displayRedSize;
|
|
|
|
|
2009-03-04 03:31:44 +00:00
|
|
|
return NO_ERROR;
|
|
|
|
}
|
|
|
|
|
2010-08-11 00:14:02 +00:00
|
|
|
void Layer::setGeometry(hwc_layer_t* hwcl)
|
|
|
|
{
|
|
|
|
hwcl->compositionType = HWC_FRAMEBUFFER;
|
|
|
|
hwcl->hints = 0;
|
|
|
|
hwcl->flags = 0;
|
|
|
|
hwcl->transform = 0;
|
|
|
|
hwcl->blending = HWC_BLENDING_NONE;
|
|
|
|
|
|
|
|
// we can't do alpha-fade with the hwc HAL
|
|
|
|
const State& s(drawingState());
|
|
|
|
if (s.alpha < 0xFF) {
|
|
|
|
hwcl->flags = HWC_SKIP_LAYER;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// we can only handle simple transformation
|
|
|
|
if (mOrientation & Transform::ROT_INVALID) {
|
|
|
|
hwcl->flags = HWC_SKIP_LAYER;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-12-09 01:23:18 +00:00
|
|
|
Transform tr(Transform(mOrientation) * Transform(mBufferTransform));
|
|
|
|
hwcl->transform = tr.getOrientation();
|
2010-08-11 00:14:02 +00:00
|
|
|
|
|
|
|
if (needsBlending()) {
|
|
|
|
hwcl->blending = mPremultipliedAlpha ?
|
|
|
|
HWC_BLENDING_PREMULT : HWC_BLENDING_COVERAGE;
|
|
|
|
}
|
|
|
|
|
|
|
|
hwcl->displayFrame.left = mTransformedBounds.left;
|
|
|
|
hwcl->displayFrame.top = mTransformedBounds.top;
|
|
|
|
hwcl->displayFrame.right = mTransformedBounds.right;
|
|
|
|
hwcl->displayFrame.bottom = mTransformedBounds.bottom;
|
|
|
|
|
|
|
|
hwcl->visibleRegionScreen.rects =
|
|
|
|
reinterpret_cast<hwc_rect_t const *>(
|
|
|
|
visibleRegionScreen.getArray(
|
|
|
|
&hwcl->visibleRegionScreen.numRects));
|
|
|
|
}
|
|
|
|
|
|
|
|
void Layer::setPerFrameData(hwc_layer_t* hwcl) {
|
|
|
|
sp<GraphicBuffer> buffer(mBufferManager.getActiveBuffer());
|
|
|
|
if (buffer == NULL) {
|
2010-12-14 02:51:59 +00:00
|
|
|
// this can happen if the client never drew into this layer yet,
|
|
|
|
// or if we ran out of memory. In that case, don't let
|
|
|
|
// HWC handle it.
|
|
|
|
hwcl->flags |= HWC_SKIP_LAYER;
|
2010-08-11 00:14:02 +00:00
|
|
|
hwcl->handle = NULL;
|
|
|
|
return;
|
|
|
|
}
|
2010-12-01 20:29:36 +00:00
|
|
|
hwcl->handle = buffer->handle;
|
2010-12-09 01:40:28 +00:00
|
|
|
|
|
|
|
if (!mBufferCrop.isEmpty()) {
|
|
|
|
hwcl->sourceCrop.left = mBufferCrop.left;
|
|
|
|
hwcl->sourceCrop.top = mBufferCrop.top;
|
|
|
|
hwcl->sourceCrop.right = mBufferCrop.right;
|
|
|
|
hwcl->sourceCrop.bottom = mBufferCrop.bottom;
|
|
|
|
} else {
|
|
|
|
hwcl->sourceCrop.left = 0;
|
|
|
|
hwcl->sourceCrop.top = 0;
|
|
|
|
hwcl->sourceCrop.right = buffer->width;
|
|
|
|
hwcl->sourceCrop.bottom = buffer->height;
|
|
|
|
}
|
2010-08-11 00:14:02 +00:00
|
|
|
}
|
|
|
|
|
2009-03-04 03:31:44 +00:00
|
|
|
void Layer::reloadTexture(const Region& dirty)
|
|
|
|
{
|
2010-05-11 03:06:11 +00:00
|
|
|
sp<GraphicBuffer> buffer(mBufferManager.getActiveBuffer());
|
2009-12-10 23:52:29 +00:00
|
|
|
if (buffer == NULL) {
|
|
|
|
// this situation can happen if we ran out of memory for instance.
|
|
|
|
// not much we can do. continue to use whatever texture was bound
|
|
|
|
// to this context.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-06-26 01:02:21 +00:00
|
|
|
if (mGLExtensions.haveDirectTexture()) {
|
2010-05-11 03:06:11 +00:00
|
|
|
EGLDisplay dpy(mFlinger->graphicPlane(0).getEGLDisplay());
|
|
|
|
if (mBufferManager.initEglImage(dpy, buffer) != NO_ERROR) {
|
|
|
|
// not sure what we can do here...
|
|
|
|
goto slowpath;
|
2009-04-10 21:24:30 +00:00
|
|
|
}
|
2010-06-26 01:02:21 +00:00
|
|
|
} else {
|
2010-03-08 19:14:20 +00:00
|
|
|
slowpath:
|
2009-04-10 21:24:30 +00:00
|
|
|
GGLSurface t;
|
2010-08-20 22:59:53 +00:00
|
|
|
if (buffer->usage & GRALLOC_USAGE_SW_READ_MASK) {
|
|
|
|
status_t res = buffer->lock(&t, GRALLOC_USAGE_SW_READ_OFTEN);
|
|
|
|
LOGE_IF(res, "error %d (%s) locking buffer %p",
|
|
|
|
res, strerror(res), buffer.get());
|
|
|
|
if (res == NO_ERROR) {
|
|
|
|
mBufferManager.loadTexture(dirty, t);
|
|
|
|
buffer->unlock();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// we can't do anything
|
2009-04-10 21:24:30 +00:00
|
|
|
}
|
2009-03-04 03:31:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-29 20:02:36 +00:00
|
|
|
void Layer::drawForSreenShot() const
|
|
|
|
{
|
2010-12-03 05:32:29 +00:00
|
|
|
const bool currentFiltering = mNeedsFiltering;
|
|
|
|
const_cast<Layer*>(this)->mNeedsFiltering = true;
|
2010-09-29 20:02:36 +00:00
|
|
|
LayerBase::drawForSreenShot();
|
2010-12-03 05:32:29 +00:00
|
|
|
const_cast<Layer*>(this)->mNeedsFiltering = currentFiltering;
|
2010-09-29 20:02:36 +00:00
|
|
|
}
|
|
|
|
|
2009-03-04 03:31:44 +00:00
|
|
|
void Layer::onDraw(const Region& clip) const
|
|
|
|
{
|
2010-05-11 03:06:11 +00:00
|
|
|
Texture tex(mBufferManager.getActiveTexture());
|
|
|
|
if (tex.name == -1LU) {
|
2009-03-04 03:31:44 +00:00
|
|
|
// the texture has not been created yet, this Layer has
|
2010-05-07 03:21:45 +00:00
|
|
|
// in fact never been drawn into. This happens frequently with
|
|
|
|
// SurfaceView because the WindowManager can't know when the client
|
|
|
|
// has drawn the first time.
|
|
|
|
|
|
|
|
// If there is nothing under us, we paint the screen in black, otherwise
|
|
|
|
// we just skip this update.
|
|
|
|
|
|
|
|
// figure out if there is something below us
|
|
|
|
Region under;
|
|
|
|
const SurfaceFlinger::LayerVector& drawingLayers(mFlinger->mDrawingState.layersSortedByZ);
|
|
|
|
const size_t count = drawingLayers.size();
|
|
|
|
for (size_t i=0 ; i<count ; ++i) {
|
|
|
|
const sp<LayerBase>& layer(drawingLayers[i]);
|
|
|
|
if (layer.get() == static_cast<LayerBase const*>(this))
|
|
|
|
break;
|
|
|
|
under.orSelf(layer->visibleRegionScreen);
|
|
|
|
}
|
|
|
|
// if not everything below us is covered, we plug the holes!
|
|
|
|
Region holes(clip.subtract(under));
|
|
|
|
if (!holes.isEmpty()) {
|
2010-06-15 04:20:00 +00:00
|
|
|
clearWithOpenGL(holes, 0, 0, 0, 1);
|
2010-05-07 03:21:45 +00:00
|
|
|
}
|
2009-03-04 03:31:44 +00:00
|
|
|
return;
|
|
|
|
}
|
2010-05-11 03:06:11 +00:00
|
|
|
drawWithOpenGL(clip, tex);
|
2009-03-04 03:31:44 +00:00
|
|
|
}
|
|
|
|
|
2011-02-10 22:41:26 +00:00
|
|
|
// As documented in libhardware header, formats in the range
|
|
|
|
// 0x100 - 0x1FF are specific to the HAL implementation, and
|
|
|
|
// are known to have no alpha channel
|
|
|
|
// TODO: move definition for device-specific range into
|
|
|
|
// hardware.h, instead of using hard-coded values here.
|
|
|
|
#define HARDWARE_IS_DEVICE_FORMAT(f) ((f) >= 0x100 && (f) <= 0x1FF)
|
|
|
|
|
|
|
|
bool Layer::needsBlending(const sp<GraphicBuffer>& buffer) const
|
|
|
|
{
|
|
|
|
// If buffers where set with eOpaque flag, all buffers are known to
|
|
|
|
// be opaque without having to check their actual format
|
|
|
|
if (mNeedsBlending && buffer != NULL) {
|
|
|
|
PixelFormat format = buffer->getPixelFormat();
|
|
|
|
|
|
|
|
if (HARDWARE_IS_DEVICE_FORMAT(format)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
PixelFormatInfo info;
|
|
|
|
status_t err = getPixelFormatInfo(format, &info);
|
|
|
|
if (!err && info.h_alpha <= info.l_alpha) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return opacity as determined from flags and format options
|
|
|
|
// passed to setBuffers()
|
|
|
|
return mNeedsBlending;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Layer::needsBlending() const
|
|
|
|
{
|
|
|
|
if (mBufferManager.hasActiveBuffer()) {
|
|
|
|
return needsBlending(mBufferManager.getActiveBuffer());
|
|
|
|
}
|
|
|
|
|
|
|
|
return mNeedsBlending;
|
|
|
|
}
|
|
|
|
|
2010-05-27 05:08:52 +00:00
|
|
|
bool Layer::needsFiltering() const
|
|
|
|
{
|
|
|
|
if (!(mFlags & DisplayHardware::SLOW_CONFIG)) {
|
2010-12-03 05:32:29 +00:00
|
|
|
// if our buffer is not the same size than ourselves,
|
|
|
|
// we need filtering.
|
|
|
|
Mutex::Autolock _l(mLock);
|
|
|
|
if (mNeedsScaling)
|
2010-05-27 05:08:52 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return LayerBase::needsFiltering();
|
|
|
|
}
|
|
|
|
|
2011-03-10 01:05:02 +00:00
|
|
|
bool Layer::isProtected() const
|
|
|
|
{
|
|
|
|
sp<GraphicBuffer> activeBuffer(mBufferManager.getActiveBuffer());
|
|
|
|
return (activeBuffer != 0) &&
|
|
|
|
(activeBuffer->getUsage() & GRALLOC_USAGE_PROTECTED);
|
|
|
|
}
|
2010-05-07 22:58:44 +00:00
|
|
|
|
|
|
|
status_t Layer::setBufferCount(int bufferCount)
|
|
|
|
{
|
2010-06-01 22:12:58 +00:00
|
|
|
ClientRef::Access sharedClient(mUserClientRef);
|
|
|
|
SharedBufferServer* lcblk(sharedClient.get());
|
|
|
|
if (!lcblk) {
|
2010-05-07 22:58:44 +00:00
|
|
|
// oops, the client is already gone
|
|
|
|
return DEAD_OBJECT;
|
|
|
|
}
|
|
|
|
|
2010-05-19 00:06:55 +00:00
|
|
|
// NOTE: lcblk->resize() is protected by an internal lock
|
|
|
|
status_t err = lcblk->resize(bufferCount);
|
2010-11-02 18:51:32 +00:00
|
|
|
if (err == NO_ERROR) {
|
|
|
|
EGLDisplay dpy(mFlinger->graphicPlane(0).getEGLDisplay());
|
|
|
|
mBufferManager.resize(bufferCount, mFlinger, dpy);
|
|
|
|
}
|
2010-05-07 22:58:44 +00:00
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2010-05-22 00:24:35 +00:00
|
|
|
sp<GraphicBuffer> Layer::requestBuffer(int index,
|
|
|
|
uint32_t reqWidth, uint32_t reqHeight, uint32_t reqFormat,
|
|
|
|
uint32_t usage)
|
2009-03-04 03:31:44 +00:00
|
|
|
{
|
2009-10-06 00:07:12 +00:00
|
|
|
sp<GraphicBuffer> buffer;
|
2009-09-11 02:41:18 +00:00
|
|
|
|
2010-06-01 22:12:58 +00:00
|
|
|
if (int32_t(reqWidth | reqHeight | reqFormat) < 0)
|
2010-05-22 00:24:35 +00:00
|
|
|
return buffer;
|
|
|
|
|
|
|
|
if ((!reqWidth && reqHeight) || (reqWidth && !reqHeight))
|
|
|
|
return buffer;
|
|
|
|
|
2009-09-11 02:41:18 +00:00
|
|
|
// this ensures our client doesn't go away while we're accessing
|
|
|
|
// the shared area.
|
2010-06-01 22:12:58 +00:00
|
|
|
ClientRef::Access sharedClient(mUserClientRef);
|
|
|
|
SharedBufferServer* lcblk(sharedClient.get());
|
|
|
|
if (!lcblk) {
|
2009-09-11 02:41:18 +00:00
|
|
|
// oops, the client is already gone
|
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
|
2009-04-10 21:24:30 +00:00
|
|
|
/*
|
fix [2068105] implement queueBuffer/lockBuffer/dequeueBuffer properly
Rewrote SurfaceFlinger's buffer management from the ground-up.
The design now support an arbitrary number of buffers per surface, however the current implementation is limited to four. Currently only 2 buffers are used in practice.
The main new feature is to be able to dequeue all buffers at once (very important when there are only two).
A client can dequeue all buffers until there are none available, it can lock all buffers except the last one that is used for composition. The client will block then, until a new buffer is enqueued.
The current implementation requires that buffers are locked in the same order they are dequeued and enqueued in the same order they are locked. Only one buffer can be locked at a time.
eg. Allowed sequence: DQ, DQ, LOCK, Q, LOCK, Q
eg. Forbidden sequence: DQ, DQ, LOCK, LOCK, Q, Q
2009-09-07 23:32:45 +00:00
|
|
|
* This is called from the client's Surface::dequeue(). This can happen
|
|
|
|
* at any time, especially while we're in the middle of using the
|
|
|
|
* buffer 'index' as our front buffer.
|
2009-04-10 21:24:30 +00:00
|
|
|
*/
|
2009-09-11 02:41:18 +00:00
|
|
|
|
2010-07-28 03:11:35 +00:00
|
|
|
status_t err = NO_ERROR;
|
2010-05-22 00:24:35 +00:00
|
|
|
uint32_t w, h, f;
|
2009-09-11 02:41:18 +00:00
|
|
|
{ // scope for the lock
|
|
|
|
Mutex::Autolock _l(mLock);
|
2010-08-25 21:59:15 +00:00
|
|
|
|
|
|
|
// zero means default
|
2010-09-21 17:52:42 +00:00
|
|
|
const bool fixedSize = reqWidth && reqHeight;
|
2010-08-25 21:59:15 +00:00
|
|
|
if (!reqFormat) reqFormat = mFormat;
|
|
|
|
if (!reqWidth) reqWidth = mWidth;
|
|
|
|
if (!reqHeight) reqHeight = mHeight;
|
|
|
|
|
|
|
|
w = reqWidth;
|
|
|
|
h = reqHeight;
|
|
|
|
f = reqFormat;
|
|
|
|
|
|
|
|
if ((reqWidth != mReqWidth) || (reqHeight != mReqHeight) ||
|
|
|
|
(reqFormat != mReqFormat)) {
|
|
|
|
mReqWidth = reqWidth;
|
|
|
|
mReqHeight = reqHeight;
|
|
|
|
mReqFormat = reqFormat;
|
2010-09-21 17:52:42 +00:00
|
|
|
mFixedSize = fixedSize;
|
2010-12-03 05:32:29 +00:00
|
|
|
mNeedsScaling = mWidth != mReqWidth || mHeight != mReqHeight;
|
2010-08-25 21:59:15 +00:00
|
|
|
|
2010-05-22 00:24:35 +00:00
|
|
|
lcblk->reallocateAllExcept(index);
|
|
|
|
}
|
2009-09-11 02:41:18 +00:00
|
|
|
}
|
|
|
|
|
2010-07-28 03:11:35 +00:00
|
|
|
// here we have to reallocate a new buffer because the buffer could be
|
|
|
|
// used as the front buffer, or by a client in our process
|
|
|
|
// (eg: status bar), and we can't release the handle under its feet.
|
2009-10-06 00:07:12 +00:00
|
|
|
const uint32_t effectiveUsage = getEffectiveUsage(usage);
|
2010-07-28 03:11:35 +00:00
|
|
|
buffer = new GraphicBuffer(w, h, f, effectiveUsage);
|
|
|
|
err = buffer->initCheck();
|
fix [2068105] implement queueBuffer/lockBuffer/dequeueBuffer properly
Rewrote SurfaceFlinger's buffer management from the ground-up.
The design now support an arbitrary number of buffers per surface, however the current implementation is limited to four. Currently only 2 buffers are used in practice.
The main new feature is to be able to dequeue all buffers at once (very important when there are only two).
A client can dequeue all buffers until there are none available, it can lock all buffers except the last one that is used for composition. The client will block then, until a new buffer is enqueued.
The current implementation requires that buffers are locked in the same order they are dequeued and enqueued in the same order they are locked. Only one buffer can be locked at a time.
eg. Allowed sequence: DQ, DQ, LOCK, Q, LOCK, Q
eg. Forbidden sequence: DQ, DQ, LOCK, LOCK, Q, Q
2009-09-07 23:32:45 +00:00
|
|
|
|
|
|
|
if (err || buffer->handle == 0) {
|
2010-12-04 01:33:09 +00:00
|
|
|
GraphicBuffer::dumpAllocationsToSystemLog();
|
fix [2068105] implement queueBuffer/lockBuffer/dequeueBuffer properly
Rewrote SurfaceFlinger's buffer management from the ground-up.
The design now support an arbitrary number of buffers per surface, however the current implementation is limited to four. Currently only 2 buffers are used in practice.
The main new feature is to be able to dequeue all buffers at once (very important when there are only two).
A client can dequeue all buffers until there are none available, it can lock all buffers except the last one that is used for composition. The client will block then, until a new buffer is enqueued.
The current implementation requires that buffers are locked in the same order they are dequeued and enqueued in the same order they are locked. Only one buffer can be locked at a time.
eg. Allowed sequence: DQ, DQ, LOCK, Q, LOCK, Q
eg. Forbidden sequence: DQ, DQ, LOCK, LOCK, Q, Q
2009-09-07 23:32:45 +00:00
|
|
|
LOGE_IF(err || buffer->handle == 0,
|
|
|
|
"Layer::requestBuffer(this=%p), index=%d, w=%d, h=%d failed (%s)",
|
|
|
|
this, index, w, h, strerror(-err));
|
2009-03-04 03:31:44 +00:00
|
|
|
} else {
|
fix [2068105] implement queueBuffer/lockBuffer/dequeueBuffer properly
Rewrote SurfaceFlinger's buffer management from the ground-up.
The design now support an arbitrary number of buffers per surface, however the current implementation is limited to four. Currently only 2 buffers are used in practice.
The main new feature is to be able to dequeue all buffers at once (very important when there are only two).
A client can dequeue all buffers until there are none available, it can lock all buffers except the last one that is used for composition. The client will block then, until a new buffer is enqueued.
The current implementation requires that buffers are locked in the same order they are dequeued and enqueued in the same order they are locked. Only one buffer can be locked at a time.
eg. Allowed sequence: DQ, DQ, LOCK, Q, LOCK, Q
eg. Forbidden sequence: DQ, DQ, LOCK, LOCK, Q, Q
2009-09-07 23:32:45 +00:00
|
|
|
LOGD_IF(DEBUG_RESIZE,
|
2009-09-30 05:39:22 +00:00
|
|
|
"Layer::requestBuffer(this=%p), index=%d, w=%d, h=%d, handle=%p",
|
|
|
|
this, index, w, h, buffer->handle);
|
2009-03-04 03:31:44 +00:00
|
|
|
}
|
|
|
|
|
fix [2068105] implement queueBuffer/lockBuffer/dequeueBuffer properly
Rewrote SurfaceFlinger's buffer management from the ground-up.
The design now support an arbitrary number of buffers per surface, however the current implementation is limited to four. Currently only 2 buffers are used in practice.
The main new feature is to be able to dequeue all buffers at once (very important when there are only two).
A client can dequeue all buffers until there are none available, it can lock all buffers except the last one that is used for composition. The client will block then, until a new buffer is enqueued.
The current implementation requires that buffers are locked in the same order they are dequeued and enqueued in the same order they are locked. Only one buffer can be locked at a time.
eg. Allowed sequence: DQ, DQ, LOCK, Q, LOCK, Q
eg. Forbidden sequence: DQ, DQ, LOCK, LOCK, Q, Q
2009-09-07 23:32:45 +00:00
|
|
|
if (err == NO_ERROR && buffer->handle != 0) {
|
2009-09-11 02:41:18 +00:00
|
|
|
Mutex::Autolock _l(mLock);
|
2010-05-22 00:24:35 +00:00
|
|
|
mBufferManager.attachBuffer(index, buffer);
|
2009-06-20 00:00:27 +00:00
|
|
|
}
|
fix [2068105] implement queueBuffer/lockBuffer/dequeueBuffer properly
Rewrote SurfaceFlinger's buffer management from the ground-up.
The design now support an arbitrary number of buffers per surface, however the current implementation is limited to four. Currently only 2 buffers are used in practice.
The main new feature is to be able to dequeue all buffers at once (very important when there are only two).
A client can dequeue all buffers until there are none available, it can lock all buffers except the last one that is used for composition. The client will block then, until a new buffer is enqueued.
The current implementation requires that buffers are locked in the same order they are dequeued and enqueued in the same order they are locked. Only one buffer can be locked at a time.
eg. Allowed sequence: DQ, DQ, LOCK, Q, LOCK, Q
eg. Forbidden sequence: DQ, DQ, LOCK, LOCK, Q, Q
2009-09-07 23:32:45 +00:00
|
|
|
return buffer;
|
2009-06-20 00:00:27 +00:00
|
|
|
}
|
|
|
|
|
2009-10-06 00:07:12 +00:00
|
|
|
uint32_t Layer::getEffectiveUsage(uint32_t usage) const
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* buffers used for software rendering, but h/w composition
|
|
|
|
* are allocated with SW_READ_OFTEN | SW_WRITE_OFTEN | HW_TEXTURE
|
|
|
|
*
|
|
|
|
* buffers used for h/w rendering and h/w composition
|
|
|
|
* are allocated with HW_RENDER | HW_TEXTURE
|
|
|
|
*
|
|
|
|
* buffers used with h/w rendering and either NPOT or no egl_image_ext
|
|
|
|
* are allocated with SW_READ_RARELY | HW_RENDER
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (mSecure) {
|
|
|
|
// secure buffer, don't store it into the GPU
|
|
|
|
usage = GraphicBuffer::USAGE_SW_READ_OFTEN |
|
|
|
|
GraphicBuffer::USAGE_SW_WRITE_OFTEN;
|
|
|
|
} else {
|
|
|
|
// it's allowed to modify the usage flags here, but generally
|
|
|
|
// the requested flags should be honored.
|
2010-05-11 03:10:10 +00:00
|
|
|
// request EGLImage for all buffers
|
|
|
|
usage |= GraphicBuffer::USAGE_HW_TEXTURE;
|
2009-10-06 00:07:12 +00:00
|
|
|
}
|
2011-03-10 01:05:02 +00:00
|
|
|
if (mProtectedByApp) {
|
2011-01-19 23:27:27 +00:00
|
|
|
// need a hardware-protected path to external video sink
|
|
|
|
usage |= GraphicBuffer::USAGE_PROTECTED;
|
|
|
|
}
|
2009-10-06 00:07:12 +00:00
|
|
|
return usage;
|
|
|
|
}
|
|
|
|
|
2009-03-04 03:31:44 +00:00
|
|
|
uint32_t Layer::doTransaction(uint32_t flags)
|
|
|
|
{
|
|
|
|
const Layer::State& front(drawingState());
|
|
|
|
const Layer::State& temp(currentState());
|
|
|
|
|
2010-05-22 00:24:35 +00:00
|
|
|
const bool sizeChanged = (front.requested_w != temp.requested_w) ||
|
|
|
|
(front.requested_h != temp.requested_h);
|
|
|
|
|
|
|
|
if (sizeChanged) {
|
fix [2068105] implement queueBuffer/lockBuffer/dequeueBuffer properly
Rewrote SurfaceFlinger's buffer management from the ground-up.
The design now support an arbitrary number of buffers per surface, however the current implementation is limited to four. Currently only 2 buffers are used in practice.
The main new feature is to be able to dequeue all buffers at once (very important when there are only two).
A client can dequeue all buffers until there are none available, it can lock all buffers except the last one that is used for composition. The client will block then, until a new buffer is enqueued.
The current implementation requires that buffers are locked in the same order they are dequeued and enqueued in the same order they are locked. Only one buffer can be locked at a time.
eg. Allowed sequence: DQ, DQ, LOCK, Q, LOCK, Q
eg. Forbidden sequence: DQ, DQ, LOCK, LOCK, Q, Q
2009-09-07 23:32:45 +00:00
|
|
|
// the size changed, we need to ask our client to request a new buffer
|
2009-03-04 03:31:44 +00:00
|
|
|
LOGD_IF(DEBUG_RESIZE,
|
2010-05-22 00:24:35 +00:00
|
|
|
"resize (layer=%p), requested (%dx%d), drawing (%d,%d)",
|
|
|
|
this,
|
|
|
|
int(temp.requested_w), int(temp.requested_h),
|
|
|
|
int(front.requested_w), int(front.requested_h));
|
|
|
|
|
|
|
|
if (!isFixedSize()) {
|
|
|
|
// we're being resized and there is a freeze display request,
|
|
|
|
// acquire a freeze lock, so that the screen stays put
|
|
|
|
// until we've redrawn at the new size; this is to avoid
|
|
|
|
// glitches upon orientation changes.
|
|
|
|
if (mFlinger->hasFreezeRequest()) {
|
|
|
|
// if the surface is hidden, don't try to acquire the
|
|
|
|
// freeze lock, since hidden surfaces may never redraw
|
|
|
|
if (!(front.flags & ISurfaceComposer::eLayerHidden)) {
|
|
|
|
mFreezeLock = mFlinger->getFreezeLock();
|
|
|
|
}
|
2009-03-04 03:31:44 +00:00
|
|
|
}
|
2009-09-17 01:27:24 +00:00
|
|
|
|
2010-05-22 00:24:35 +00:00
|
|
|
// this will make sure LayerBase::doTransaction doesn't update
|
|
|
|
// the drawing state's size
|
|
|
|
Layer::State& editDraw(mDrawingState);
|
|
|
|
editDraw.requested_w = temp.requested_w;
|
|
|
|
editDraw.requested_h = temp.requested_h;
|
2009-09-30 21:07:22 +00:00
|
|
|
|
2010-05-22 00:24:35 +00:00
|
|
|
// record the new size, form this point on, when the client request
|
|
|
|
// a buffer, it'll get the new size.
|
|
|
|
setBufferSize(temp.requested_w, temp.requested_h);
|
2009-09-30 19:48:47 +00:00
|
|
|
|
2010-06-01 22:12:58 +00:00
|
|
|
ClientRef::Access sharedClient(mUserClientRef);
|
|
|
|
SharedBufferServer* lcblk(sharedClient.get());
|
|
|
|
if (lcblk) {
|
2010-06-03 06:28:45 +00:00
|
|
|
// all buffers need reallocation
|
|
|
|
lcblk->reallocateAll();
|
|
|
|
}
|
2010-05-22 00:24:35 +00:00
|
|
|
} else {
|
|
|
|
// record the new size
|
|
|
|
setBufferSize(temp.requested_w, temp.requested_h);
|
|
|
|
}
|
2009-03-04 03:31:44 +00:00
|
|
|
}
|
fix [2068105] implement queueBuffer/lockBuffer/dequeueBuffer properly
Rewrote SurfaceFlinger's buffer management from the ground-up.
The design now support an arbitrary number of buffers per surface, however the current implementation is limited to four. Currently only 2 buffers are used in practice.
The main new feature is to be able to dequeue all buffers at once (very important when there are only two).
A client can dequeue all buffers until there are none available, it can lock all buffers except the last one that is used for composition. The client will block then, until a new buffer is enqueued.
The current implementation requires that buffers are locked in the same order they are dequeued and enqueued in the same order they are locked. Only one buffer can be locked at a time.
eg. Allowed sequence: DQ, DQ, LOCK, Q, LOCK, Q
eg. Forbidden sequence: DQ, DQ, LOCK, LOCK, Q, Q
2009-09-07 23:32:45 +00:00
|
|
|
|
2009-03-04 03:31:44 +00:00
|
|
|
if (temp.sequence != front.sequence) {
|
|
|
|
if (temp.flags & ISurfaceComposer::eLayerHidden || temp.alpha == 0) {
|
|
|
|
// this surface is now hidden, so it shouldn't hold a freeze lock
|
|
|
|
// (it may never redraw, which is fine if it is hidden)
|
|
|
|
mFreezeLock.clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return LayerBase::doTransaction(flags);
|
|
|
|
}
|
|
|
|
|
2010-05-22 00:24:35 +00:00
|
|
|
void Layer::setBufferSize(uint32_t w, uint32_t h) {
|
fix [2068105] implement queueBuffer/lockBuffer/dequeueBuffer properly
Rewrote SurfaceFlinger's buffer management from the ground-up.
The design now support an arbitrary number of buffers per surface, however the current implementation is limited to four. Currently only 2 buffers are used in practice.
The main new feature is to be able to dequeue all buffers at once (very important when there are only two).
A client can dequeue all buffers until there are none available, it can lock all buffers except the last one that is used for composition. The client will block then, until a new buffer is enqueued.
The current implementation requires that buffers are locked in the same order they are dequeued and enqueued in the same order they are locked. Only one buffer can be locked at a time.
eg. Allowed sequence: DQ, DQ, LOCK, Q, LOCK, Q
eg. Forbidden sequence: DQ, DQ, LOCK, LOCK, Q, Q
2009-09-07 23:32:45 +00:00
|
|
|
Mutex::Autolock _l(mLock);
|
|
|
|
mWidth = w;
|
|
|
|
mHeight = h;
|
2010-12-03 05:32:29 +00:00
|
|
|
mNeedsScaling = mWidth != mReqWidth || mHeight != mReqHeight;
|
2009-03-04 03:31:44 +00:00
|
|
|
}
|
|
|
|
|
2010-05-22 00:24:35 +00:00
|
|
|
bool Layer::isFixedSize() const {
|
|
|
|
Mutex::Autolock _l(mLock);
|
|
|
|
return mFixedSize;
|
|
|
|
}
|
|
|
|
|
2009-03-04 03:31:44 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// pageflip handling...
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void Layer::lockPageFlip(bool& recomputeVisibleRegions)
|
|
|
|
{
|
2010-06-01 22:12:58 +00:00
|
|
|
ClientRef::Access sharedClient(mUserClientRef);
|
|
|
|
SharedBufferServer* lcblk(sharedClient.get());
|
|
|
|
if (!lcblk) {
|
2010-06-03 06:28:45 +00:00
|
|
|
// client died
|
|
|
|
recomputeVisibleRegions = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
fix [2068105] implement queueBuffer/lockBuffer/dequeueBuffer properly
Rewrote SurfaceFlinger's buffer management from the ground-up.
The design now support an arbitrary number of buffers per surface, however the current implementation is limited to four. Currently only 2 buffers are used in practice.
The main new feature is to be able to dequeue all buffers at once (very important when there are only two).
A client can dequeue all buffers until there are none available, it can lock all buffers except the last one that is used for composition. The client will block then, until a new buffer is enqueued.
The current implementation requires that buffers are locked in the same order they are dequeued and enqueued in the same order they are locked. Only one buffer can be locked at a time.
eg. Allowed sequence: DQ, DQ, LOCK, Q, LOCK, Q
eg. Forbidden sequence: DQ, DQ, LOCK, LOCK, Q, Q
2009-09-07 23:32:45 +00:00
|
|
|
ssize_t buf = lcblk->retireAndLock();
|
2010-05-11 03:06:11 +00:00
|
|
|
if (buf == NOT_ENOUGH_DATA) {
|
|
|
|
// NOTE: This is not an error, it simply means there is nothing to
|
|
|
|
// retire. The buffer is locked because we will use it
|
fix [2068105] implement queueBuffer/lockBuffer/dequeueBuffer properly
Rewrote SurfaceFlinger's buffer management from the ground-up.
The design now support an arbitrary number of buffers per surface, however the current implementation is limited to four. Currently only 2 buffers are used in practice.
The main new feature is to be able to dequeue all buffers at once (very important when there are only two).
A client can dequeue all buffers until there are none available, it can lock all buffers except the last one that is used for composition. The client will block then, until a new buffer is enqueued.
The current implementation requires that buffers are locked in the same order they are dequeued and enqueued in the same order they are locked. Only one buffer can be locked at a time.
eg. Allowed sequence: DQ, DQ, LOCK, Q, LOCK, Q
eg. Forbidden sequence: DQ, DQ, LOCK, LOCK, Q, Q
2009-09-07 23:32:45 +00:00
|
|
|
// for composition later in the loop
|
2009-03-04 03:31:44 +00:00
|
|
|
return;
|
|
|
|
}
|
2010-03-16 01:15:20 +00:00
|
|
|
|
2010-05-11 03:06:11 +00:00
|
|
|
if (buf < NO_ERROR) {
|
2010-06-01 22:12:58 +00:00
|
|
|
LOGE("retireAndLock() buffer index (%d) out of range", int(buf));
|
2010-03-16 01:15:20 +00:00
|
|
|
mPostedDirtyRegion.clear();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
fix [2068105] implement queueBuffer/lockBuffer/dequeueBuffer properly
Rewrote SurfaceFlinger's buffer management from the ground-up.
The design now support an arbitrary number of buffers per surface, however the current implementation is limited to four. Currently only 2 buffers are used in practice.
The main new feature is to be able to dequeue all buffers at once (very important when there are only two).
A client can dequeue all buffers until there are none available, it can lock all buffers except the last one that is used for composition. The client will block then, until a new buffer is enqueued.
The current implementation requires that buffers are locked in the same order they are dequeued and enqueued in the same order they are locked. Only one buffer can be locked at a time.
eg. Allowed sequence: DQ, DQ, LOCK, Q, LOCK, Q
eg. Forbidden sequence: DQ, DQ, LOCK, LOCK, Q, Q
2009-09-07 23:32:45 +00:00
|
|
|
// we retired a buffer, which becomes the new front buffer
|
2010-12-14 02:51:59 +00:00
|
|
|
|
|
|
|
const bool noActiveBuffer = !mBufferManager.hasActiveBuffer();
|
2011-02-10 22:41:26 +00:00
|
|
|
const bool activeBlending =
|
|
|
|
noActiveBuffer ? true : needsBlending(mBufferManager.getActiveBuffer());
|
|
|
|
|
2010-05-11 03:06:11 +00:00
|
|
|
if (mBufferManager.setActiveBufferIndex(buf) < NO_ERROR) {
|
2010-06-01 22:12:58 +00:00
|
|
|
LOGE("retireAndLock() buffer index (%d) out of range", int(buf));
|
2010-05-11 03:06:11 +00:00
|
|
|
mPostedDirtyRegion.clear();
|
|
|
|
return;
|
|
|
|
}
|
2009-03-04 03:31:44 +00:00
|
|
|
|
2010-12-14 02:51:59 +00:00
|
|
|
if (noActiveBuffer) {
|
|
|
|
// we didn't have an active buffer, we need to recompute
|
|
|
|
// our visible region
|
|
|
|
recomputeVisibleRegions = true;
|
|
|
|
}
|
|
|
|
|
2009-10-06 00:07:12 +00:00
|
|
|
sp<GraphicBuffer> newFrontBuffer(getBuffer(buf));
|
2010-03-16 01:15:20 +00:00
|
|
|
if (newFrontBuffer != NULL) {
|
2011-02-10 22:41:26 +00:00
|
|
|
if (!noActiveBuffer && activeBlending != needsBlending(newFrontBuffer)) {
|
|
|
|
// new buffer has different opacity than previous active buffer, need
|
|
|
|
// to recompute visible regions accordingly
|
|
|
|
recomputeVisibleRegions = true;
|
|
|
|
}
|
|
|
|
|
2010-08-20 00:01:19 +00:00
|
|
|
// get the dirty region
|
2010-03-16 01:15:20 +00:00
|
|
|
// compute the posted region
|
|
|
|
const Region dirty(lcblk->getDirtyRegion(buf));
|
|
|
|
mPostedDirtyRegion = dirty.intersect( newFrontBuffer->getBounds() );
|
|
|
|
|
|
|
|
// update the layer size and release freeze-lock
|
|
|
|
const Layer::State& front(drawingState());
|
|
|
|
if (newFrontBuffer->getWidth() == front.requested_w &&
|
|
|
|
newFrontBuffer->getHeight() == front.requested_h)
|
2009-09-30 21:07:22 +00:00
|
|
|
{
|
2010-03-16 01:15:20 +00:00
|
|
|
if ((front.w != front.requested_w) ||
|
|
|
|
(front.h != front.requested_h))
|
|
|
|
{
|
|
|
|
// Here we pretend the transaction happened by updating the
|
|
|
|
// current and drawing states. Drawing state is only accessed
|
|
|
|
// in this thread, no need to have it locked
|
|
|
|
Layer::State& editDraw(mDrawingState);
|
|
|
|
editDraw.w = editDraw.requested_w;
|
|
|
|
editDraw.h = editDraw.requested_h;
|
|
|
|
|
|
|
|
// We also need to update the current state so that we don't
|
|
|
|
// end-up doing too much work during the next transaction.
|
|
|
|
// NOTE: We actually don't need hold the transaction lock here
|
|
|
|
// because State::w and State::h are only accessed from
|
|
|
|
// this thread
|
|
|
|
Layer::State& editTemp(currentState());
|
|
|
|
editTemp.w = editDraw.w;
|
|
|
|
editTemp.h = editDraw.h;
|
|
|
|
|
|
|
|
// recompute visible region
|
|
|
|
recomputeVisibleRegions = true;
|
|
|
|
}
|
2009-10-08 00:58:29 +00:00
|
|
|
|
2010-03-16 01:15:20 +00:00
|
|
|
// we now have the correct size, unfreeze the screen
|
|
|
|
mFreezeLock.clear();
|
|
|
|
}
|
2010-08-20 00:01:19 +00:00
|
|
|
|
|
|
|
// get the crop region
|
|
|
|
setBufferCrop( lcblk->getCrop(buf) );
|
|
|
|
|
|
|
|
// get the transformation
|
|
|
|
setBufferTransform( lcblk->getTransform(buf) );
|
|
|
|
|
2010-03-16 01:15:20 +00:00
|
|
|
} else {
|
|
|
|
// this should not happen unless we ran out of memory while
|
|
|
|
// allocating the buffer. we're hoping that things will get back
|
|
|
|
// to normal the next time the app tries to draw into this buffer.
|
|
|
|
// meanwhile, pretend the screen didn't update.
|
|
|
|
mPostedDirtyRegion.clear();
|
2009-09-17 01:27:24 +00:00
|
|
|
}
|
|
|
|
|
2009-10-07 23:44:10 +00:00
|
|
|
if (lcblk->getQueuedCount()) {
|
|
|
|
// signal an event if we have more buffers waiting
|
|
|
|
mFlinger->signalEvent();
|
|
|
|
}
|
2009-03-04 03:31:44 +00:00
|
|
|
|
2010-04-21 22:24:11 +00:00
|
|
|
/* a buffer was posted, so we need to call reloadTexture(), which
|
|
|
|
* will update our internal data structures (eg: EGLImageKHR or
|
|
|
|
* texture names). we need to do this even if mPostedDirtyRegion is
|
|
|
|
* empty -- it's orthogonal to the fact that a new buffer was posted,
|
|
|
|
* for instance, a degenerate case could be that the user did an empty
|
|
|
|
* update but repainted the buffer with appropriate content (after a
|
|
|
|
* resize for instance).
|
|
|
|
*/
|
|
|
|
reloadTexture( mPostedDirtyRegion );
|
2009-03-04 03:31:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Layer::unlockPageFlip(
|
|
|
|
const Transform& planeTransform, Region& outDirtyRegion)
|
|
|
|
{
|
|
|
|
Region dirtyRegion(mPostedDirtyRegion);
|
|
|
|
if (!dirtyRegion.isEmpty()) {
|
|
|
|
mPostedDirtyRegion.clear();
|
|
|
|
// The dirty region is given in the layer's coordinate space
|
|
|
|
// transform the dirty region by the surface's transformation
|
|
|
|
// and the global transformation.
|
|
|
|
const Layer::State& s(drawingState());
|
|
|
|
const Transform tr(planeTransform * s.transform);
|
|
|
|
dirtyRegion = tr.transform(dirtyRegion);
|
|
|
|
|
|
|
|
// At this point, the dirty region is in screen space.
|
|
|
|
// Make sure it's constrained by the visible region (which
|
|
|
|
// is in screen space as well).
|
|
|
|
dirtyRegion.andSelf(visibleRegionScreen);
|
|
|
|
outDirtyRegion.orSelf(dirtyRegion);
|
|
|
|
}
|
2009-11-30 19:15:41 +00:00
|
|
|
if (visibleRegionScreen.isEmpty()) {
|
|
|
|
// an invisible layer should not hold a freeze-lock
|
2010-04-21 00:55:49 +00:00
|
|
|
// (because it may never be updated and therefore never release it)
|
2009-11-30 19:15:41 +00:00
|
|
|
mFreezeLock.clear();
|
|
|
|
}
|
2009-03-04 03:31:44 +00:00
|
|
|
}
|
|
|
|
|
2010-04-21 00:55:49 +00:00
|
|
|
void Layer::dump(String8& result, char* buffer, size_t SIZE) const
|
|
|
|
{
|
|
|
|
LayerBaseClient::dump(result, buffer, SIZE);
|
|
|
|
|
2010-06-01 22:12:58 +00:00
|
|
|
ClientRef::Access sharedClient(mUserClientRef);
|
|
|
|
SharedBufferServer* lcblk(sharedClient.get());
|
|
|
|
uint32_t totalTime = 0;
|
|
|
|
if (lcblk) {
|
|
|
|
SharedBufferStack::Statistics stats = lcblk->getStats();
|
|
|
|
totalTime= stats.totalTime;
|
|
|
|
result.append( lcblk->dump(" ") );
|
|
|
|
}
|
|
|
|
|
2010-04-21 00:55:49 +00:00
|
|
|
sp<const GraphicBuffer> buf0(getBuffer(0));
|
|
|
|
sp<const GraphicBuffer> buf1(getBuffer(1));
|
|
|
|
uint32_t w0=0, h0=0, s0=0;
|
|
|
|
uint32_t w1=0, h1=0, s1=0;
|
|
|
|
if (buf0 != 0) {
|
|
|
|
w0 = buf0->getWidth();
|
|
|
|
h0 = buf0->getHeight();
|
|
|
|
s0 = buf0->getStride();
|
|
|
|
}
|
|
|
|
if (buf1 != 0) {
|
|
|
|
w1 = buf1->getWidth();
|
|
|
|
h1 = buf1->getHeight();
|
|
|
|
s1 = buf1->getStride();
|
|
|
|
}
|
|
|
|
snprintf(buffer, SIZE,
|
|
|
|
" "
|
|
|
|
"format=%2d, [%3ux%3u:%3u] [%3ux%3u:%3u],"
|
|
|
|
" freezeLock=%p, dq-q-time=%u us\n",
|
2010-06-01 22:12:58 +00:00
|
|
|
mFormat, w0, h0, s0, w1, h1, s1,
|
|
|
|
getFreezeLock().get(), totalTime);
|
2010-04-21 00:55:49 +00:00
|
|
|
|
|
|
|
result.append(buffer);
|
|
|
|
}
|
|
|
|
|
2009-04-10 21:24:30 +00:00
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2010-06-01 22:12:58 +00:00
|
|
|
Layer::ClientRef::ClientRef()
|
2010-06-09 02:54:15 +00:00
|
|
|
: mControlBlock(0), mToken(-1) {
|
2010-06-01 22:12:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Layer::ClientRef::~ClientRef() {
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t Layer::ClientRef::getToken() const {
|
|
|
|
Mutex::Autolock _l(mLock);
|
|
|
|
return mToken;
|
|
|
|
}
|
|
|
|
|
2010-06-09 02:54:15 +00:00
|
|
|
sp<UserClient> Layer::ClientRef::getClient() const {
|
|
|
|
Mutex::Autolock _l(mLock);
|
|
|
|
return mUserClient.promote();
|
|
|
|
}
|
|
|
|
|
2010-06-01 22:12:58 +00:00
|
|
|
status_t Layer::ClientRef::setToken(const sp<UserClient>& uc,
|
2010-06-09 02:54:15 +00:00
|
|
|
const sp<SharedBufferServer>& sharedClient, int32_t token) {
|
2010-06-01 22:12:58 +00:00
|
|
|
Mutex::Autolock _l(mLock);
|
2010-06-09 02:54:15 +00:00
|
|
|
|
|
|
|
{ // scope for strong mUserClient reference
|
|
|
|
sp<UserClient> userClient(mUserClient.promote());
|
2011-03-18 23:35:13 +00:00
|
|
|
if (userClient != 0 && mControlBlock != 0) {
|
2010-06-09 02:54:15 +00:00
|
|
|
mControlBlock->setStatus(NO_INIT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-01 22:12:58 +00:00
|
|
|
mUserClient = uc;
|
|
|
|
mToken = token;
|
2010-06-09 02:54:15 +00:00
|
|
|
mControlBlock = sharedClient;
|
2010-06-01 22:12:58 +00:00
|
|
|
return NO_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
sp<UserClient> Layer::ClientRef::getUserClientUnsafe() const {
|
|
|
|
return mUserClient.promote();
|
|
|
|
}
|
|
|
|
|
|
|
|
// this class gives us access to SharedBufferServer safely
|
|
|
|
// it makes sure the UserClient (and its associated shared memory)
|
|
|
|
// won't go away while we're accessing it.
|
|
|
|
Layer::ClientRef::Access::Access(const ClientRef& ref)
|
2010-06-09 02:54:15 +00:00
|
|
|
: mControlBlock(0)
|
2010-06-01 22:12:58 +00:00
|
|
|
{
|
|
|
|
Mutex::Autolock _l(ref.mLock);
|
|
|
|
mUserClientStrongRef = ref.mUserClient.promote();
|
|
|
|
if (mUserClientStrongRef != 0)
|
2010-06-09 02:54:15 +00:00
|
|
|
mControlBlock = ref.mControlBlock;
|
|
|
|
}
|
|
|
|
|
|
|
|
Layer::ClientRef::Access::~Access()
|
|
|
|
{
|
2010-06-01 22:12:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2010-05-11 03:06:11 +00:00
|
|
|
Layer::BufferManager::BufferManager(TextureManager& tm)
|
2010-05-19 00:06:55 +00:00
|
|
|
: mNumBuffers(NUM_BUFFERS), mTextureManager(tm),
|
2010-12-15 04:30:37 +00:00
|
|
|
mActiveBufferIndex(-1), mFailover(false)
|
2010-05-19 00:06:55 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
Layer::BufferManager::~BufferManager()
|
2010-05-11 03:06:11 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-11-02 18:51:32 +00:00
|
|
|
status_t Layer::BufferManager::resize(size_t size,
|
|
|
|
const sp<SurfaceFlinger>& flinger, EGLDisplay dpy)
|
2010-05-19 00:06:55 +00:00
|
|
|
{
|
|
|
|
Mutex::Autolock _l(mLock);
|
2010-11-02 18:51:32 +00:00
|
|
|
|
|
|
|
if (size < mNumBuffers) {
|
2011-03-17 06:18:07 +00:00
|
|
|
// If there is an active texture, move it into slot 0 if needed
|
|
|
|
if (mActiveBufferIndex > 0) {
|
|
|
|
BufferData activeBufferData = mBufferData[mActiveBufferIndex];
|
|
|
|
mBufferData[mActiveBufferIndex] = mBufferData[0];
|
|
|
|
mBufferData[0] = activeBufferData;
|
|
|
|
mActiveBufferIndex = 0;
|
|
|
|
}
|
2010-11-02 18:51:32 +00:00
|
|
|
|
|
|
|
// Free the buffers that are no longer needed.
|
|
|
|
for (size_t i = size; i < mNumBuffers; i++) {
|
|
|
|
mBufferData[i].buffer = 0;
|
|
|
|
|
|
|
|
// Create a message to destroy the textures on SurfaceFlinger's GL
|
|
|
|
// thread.
|
|
|
|
class MessageDestroyTexture : public MessageBase {
|
|
|
|
Image mTexture;
|
|
|
|
EGLDisplay mDpy;
|
|
|
|
public:
|
|
|
|
MessageDestroyTexture(const Image& texture, EGLDisplay dpy)
|
|
|
|
: mTexture(texture), mDpy(dpy) { }
|
|
|
|
virtual bool handler() {
|
|
|
|
status_t err = Layer::BufferManager::destroyTexture(
|
|
|
|
&mTexture, mDpy);
|
|
|
|
LOGE_IF(err<0, "error destroying texture: %d (%s)",
|
|
|
|
mTexture.name, strerror(-err));
|
|
|
|
return true; // XXX: err == 0; ????
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
MessageDestroyTexture *msg = new MessageDestroyTexture(
|
|
|
|
mBufferData[i].texture, dpy);
|
|
|
|
|
|
|
|
// Don't allow this texture to be cleaned up by
|
|
|
|
// BufferManager::destroy.
|
|
|
|
mBufferData[i].texture.name = -1U;
|
|
|
|
mBufferData[i].texture.image = EGL_NO_IMAGE_KHR;
|
|
|
|
|
|
|
|
// Post the message to the SurfaceFlinger object.
|
|
|
|
flinger->postMessageAsync(msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-19 00:06:55 +00:00
|
|
|
mNumBuffers = size;
|
|
|
|
return NO_ERROR;
|
2010-05-11 03:06:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// only for debugging
|
|
|
|
sp<GraphicBuffer> Layer::BufferManager::getBuffer(size_t index) const {
|
|
|
|
return mBufferData[index].buffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
status_t Layer::BufferManager::setActiveBufferIndex(size_t index) {
|
2010-12-15 04:30:37 +00:00
|
|
|
BufferData const * const buffers = mBufferData;
|
|
|
|
Mutex::Autolock _l(mLock);
|
|
|
|
mActiveBuffer = buffers[index].buffer;
|
|
|
|
mActiveBufferIndex = index;
|
2010-05-11 03:06:11 +00:00
|
|
|
return NO_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t Layer::BufferManager::getActiveBufferIndex() const {
|
2010-12-15 04:30:37 +00:00
|
|
|
return mActiveBufferIndex;
|
2010-05-11 03:06:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Texture Layer::BufferManager::getActiveTexture() const {
|
2010-05-19 00:06:55 +00:00
|
|
|
Texture res;
|
2010-12-15 04:30:37 +00:00
|
|
|
if (mFailover || mActiveBufferIndex<0) {
|
2010-05-19 00:06:55 +00:00
|
|
|
res = mFailoverTexture;
|
|
|
|
} else {
|
2010-12-15 04:30:37 +00:00
|
|
|
static_cast<Image&>(res) = mBufferData[mActiveBufferIndex].texture;
|
2010-05-19 00:06:55 +00:00
|
|
|
}
|
|
|
|
return res;
|
2010-05-11 03:06:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sp<GraphicBuffer> Layer::BufferManager::getActiveBuffer() const {
|
2010-12-15 04:30:37 +00:00
|
|
|
return mActiveBuffer;
|
2010-05-11 03:06:11 +00:00
|
|
|
}
|
|
|
|
|
2010-12-14 02:51:59 +00:00
|
|
|
bool Layer::BufferManager::hasActiveBuffer() const {
|
2010-12-15 04:30:37 +00:00
|
|
|
return mActiveBufferIndex >= 0;
|
2010-12-14 02:51:59 +00:00
|
|
|
}
|
|
|
|
|
2010-05-11 03:06:11 +00:00
|
|
|
sp<GraphicBuffer> Layer::BufferManager::detachBuffer(size_t index)
|
|
|
|
{
|
2010-05-19 00:06:55 +00:00
|
|
|
BufferData* const buffers = mBufferData;
|
2010-05-11 03:06:11 +00:00
|
|
|
sp<GraphicBuffer> buffer;
|
|
|
|
Mutex::Autolock _l(mLock);
|
2010-05-19 00:06:55 +00:00
|
|
|
buffer = buffers[index].buffer;
|
|
|
|
buffers[index].buffer = 0;
|
2010-05-11 03:06:11 +00:00
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
status_t Layer::BufferManager::attachBuffer(size_t index,
|
|
|
|
const sp<GraphicBuffer>& buffer)
|
|
|
|
{
|
2010-05-19 00:06:55 +00:00
|
|
|
BufferData* const buffers = mBufferData;
|
2010-05-11 03:06:11 +00:00
|
|
|
Mutex::Autolock _l(mLock);
|
2010-05-19 00:06:55 +00:00
|
|
|
buffers[index].buffer = buffer;
|
|
|
|
buffers[index].texture.dirty = true;
|
2010-05-11 03:06:11 +00:00
|
|
|
return NO_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
status_t Layer::BufferManager::destroy(EGLDisplay dpy)
|
|
|
|
{
|
2010-05-19 00:06:55 +00:00
|
|
|
BufferData* const buffers = mBufferData;
|
|
|
|
size_t num;
|
|
|
|
{ // scope for the lock
|
|
|
|
Mutex::Autolock _l(mLock);
|
|
|
|
num = mNumBuffers;
|
|
|
|
for (size_t i=0 ; i<num ; i++) {
|
|
|
|
buffers[i].buffer = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (size_t i=0 ; i<num ; i++) {
|
|
|
|
destroyTexture(&buffers[i].texture, dpy);
|
2010-05-11 03:06:11 +00:00
|
|
|
}
|
|
|
|
destroyTexture(&mFailoverTexture, dpy);
|
|
|
|
return NO_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
status_t Layer::BufferManager::initEglImage(EGLDisplay dpy,
|
|
|
|
const sp<GraphicBuffer>& buffer)
|
|
|
|
{
|
2010-06-01 22:12:58 +00:00
|
|
|
status_t err = NO_INIT;
|
2010-12-15 04:30:37 +00:00
|
|
|
ssize_t index = mActiveBufferIndex;
|
2010-06-01 22:12:58 +00:00
|
|
|
if (index >= 0) {
|
2010-06-26 01:02:21 +00:00
|
|
|
if (!mFailover) {
|
|
|
|
Image& texture(mBufferData[index].texture);
|
|
|
|
err = mTextureManager.initEglImage(&texture, dpy, buffer);
|
|
|
|
// if EGLImage fails, we switch to regular texture mode, and we
|
|
|
|
// free all resources associated with using EGLImages.
|
|
|
|
if (err == NO_ERROR) {
|
|
|
|
mFailover = false;
|
|
|
|
destroyTexture(&mFailoverTexture, dpy);
|
|
|
|
} else {
|
|
|
|
mFailover = true;
|
|
|
|
const size_t num = mNumBuffers;
|
|
|
|
for (size_t i=0 ; i<num ; i++) {
|
|
|
|
destroyTexture(&mBufferData[i].texture, dpy);
|
|
|
|
}
|
2010-06-25 16:25:19 +00:00
|
|
|
}
|
2010-06-26 01:02:21 +00:00
|
|
|
} else {
|
|
|
|
// we failed once, don't try again
|
|
|
|
err = BAD_VALUE;
|
2010-05-11 03:06:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
status_t Layer::BufferManager::loadTexture(
|
|
|
|
const Region& dirty, const GGLSurface& t)
|
|
|
|
{
|
|
|
|
return mTextureManager.loadTexture(&mFailoverTexture, dirty, t);
|
|
|
|
}
|
|
|
|
|
2010-05-19 00:06:55 +00:00
|
|
|
status_t Layer::BufferManager::destroyTexture(Image* tex, EGLDisplay dpy)
|
|
|
|
{
|
|
|
|
if (tex->name != -1U) {
|
|
|
|
glDeleteTextures(1, &tex->name);
|
|
|
|
tex->name = -1U;
|
|
|
|
}
|
|
|
|
if (tex->image != EGL_NO_IMAGE_KHR) {
|
|
|
|
eglDestroyImageKHR(dpy, tex->image);
|
|
|
|
tex->image = EGL_NO_IMAGE_KHR;
|
|
|
|
}
|
|
|
|
return NO_ERROR;
|
|
|
|
}
|
|
|
|
|
2010-05-11 03:06:11 +00:00
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2009-04-18 02:36:26 +00:00
|
|
|
Layer::SurfaceLayer::SurfaceLayer(const sp<SurfaceFlinger>& flinger,
|
2010-06-03 06:28:45 +00:00
|
|
|
const sp<Layer>& owner)
|
|
|
|
: Surface(flinger, owner->getIdentity(), owner)
|
2009-04-18 02:36:26 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
Layer::SurfaceLayer::~SurfaceLayer()
|
2009-04-10 21:24:30 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-05-22 00:24:35 +00:00
|
|
|
sp<GraphicBuffer> Layer::SurfaceLayer::requestBuffer(int index,
|
|
|
|
uint32_t w, uint32_t h, uint32_t format, uint32_t usage)
|
2009-04-10 21:24:30 +00:00
|
|
|
{
|
2009-10-06 00:07:12 +00:00
|
|
|
sp<GraphicBuffer> buffer;
|
2009-04-10 21:24:30 +00:00
|
|
|
sp<Layer> owner(getOwner());
|
|
|
|
if (owner != 0) {
|
2010-05-19 00:06:55 +00:00
|
|
|
/*
|
|
|
|
* requestBuffer() cannot be called from the main thread
|
|
|
|
* as it could cause a dead-lock, since it may have to wait
|
|
|
|
* on conditions updated my the main thread.
|
|
|
|
*/
|
2010-05-22 00:24:35 +00:00
|
|
|
buffer = owner->requestBuffer(index, w, h, format, usage);
|
2009-04-10 21:24:30 +00:00
|
|
|
}
|
|
|
|
return buffer;
|
|
|
|
}
|
2009-03-04 03:31:44 +00:00
|
|
|
|
2010-05-07 22:58:44 +00:00
|
|
|
status_t Layer::SurfaceLayer::setBufferCount(int bufferCount)
|
|
|
|
{
|
|
|
|
status_t err = DEAD_OBJECT;
|
|
|
|
sp<Layer> owner(getOwner());
|
|
|
|
if (owner != 0) {
|
2010-05-19 00:06:55 +00:00
|
|
|
/*
|
|
|
|
* setBufferCount() cannot be called from the main thread
|
|
|
|
* as it could cause a dead-lock, since it may have to wait
|
|
|
|
* on conditions updated my the main thread.
|
|
|
|
*/
|
2010-05-07 22:58:44 +00:00
|
|
|
err = owner->setBufferCount(bufferCount);
|
|
|
|
}
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2009-03-04 03:31:44 +00:00
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
}; // namespace android
|