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>
|
|
|
|
|
2011-04-20 21:20:59 +00:00
|
|
|
#include <cutils/compiler.h>
|
2009-04-10 21:24:30 +00:00
|
|
|
#include <cutils/native_handle.h>
|
2011-04-20 21:20:59 +00:00
|
|
|
#include <cutils/properties.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"
|
2011-04-20 21:20:59 +00:00
|
|
|
#include "DisplayHardware/DisplayHardware.h"
|
|
|
|
#include "DisplayHardware/HWComposer.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"
|
2011-04-20 21:20:59 +00:00
|
|
|
#include "SurfaceTextureLayer.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),
|
2011-04-20 21:20:59 +00:00
|
|
|
mTextureName(-1U),
|
|
|
|
mQueuedFrames(0),
|
|
|
|
mCurrentTransform(0),
|
|
|
|
mCurrentOpacity(true),
|
2011-03-12 01:01:07 +00:00
|
|
|
mFormat(PIXEL_FORMAT_NONE),
|
2010-06-26 01:02:21 +00:00
|
|
|
mGLExtensions(GLExtensions::getInstance()),
|
2011-04-20 21:20:59 +00:00
|
|
|
mOpaqueLayer(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),
|
2011-04-20 21:20:59 +00:00
|
|
|
mFixedSize(false)
|
2009-04-22 22:23:34 +00:00
|
|
|
{
|
2011-04-20 21:20:59 +00:00
|
|
|
mCurrentCrop.makeInvalid();
|
|
|
|
glGenTextures(1, &mTextureName);
|
2010-05-11 03:06:11 +00:00
|
|
|
}
|
|
|
|
|
2011-06-13 01:05:53 +00:00
|
|
|
void Layer::destroy(RefBase const* base) {
|
|
|
|
mFlinger->destroyLayer(static_cast<LayerBase const*>(base));
|
2011-05-19 22:38:14 +00:00
|
|
|
}
|
|
|
|
|
2011-04-20 21:20:59 +00:00
|
|
|
void Layer::onFirstRef()
|
2010-06-03 06:28:45 +00:00
|
|
|
{
|
2011-04-20 21:20:59 +00:00
|
|
|
LayerBaseClient::onFirstRef();
|
2011-06-13 01:05:53 +00:00
|
|
|
setDestroyer(this);
|
|
|
|
|
2011-04-20 21:20:59 +00:00
|
|
|
struct FrameQueuedListener : public SurfaceTexture::FrameAvailableListener {
|
|
|
|
FrameQueuedListener(Layer* layer) : mLayer(layer) { }
|
|
|
|
private:
|
|
|
|
wp<Layer> mLayer;
|
|
|
|
virtual void onFrameAvailable() {
|
|
|
|
sp<Layer> that(mLayer.promote());
|
|
|
|
if (that != 0) {
|
|
|
|
that->onFrameQueued();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
mSurfaceTexture = new SurfaceTextureLayer(mTextureName, this);
|
|
|
|
mSurfaceTexture->setFrameAvailableListener(new FrameQueuedListener(this));
|
|
|
|
mSurfaceTexture->setSynchronousMode(true);
|
|
|
|
mSurfaceTexture->setBufferCountServer(2);
|
2010-06-01 22:12:58 +00:00
|
|
|
}
|
2010-06-03 06:28:45 +00:00
|
|
|
|
2011-04-20 21:20:59 +00:00
|
|
|
Layer::~Layer()
|
2010-06-01 22:12:58 +00:00
|
|
|
{
|
2011-04-20 21:20:59 +00:00
|
|
|
glDeleteTextures(1, &mTextureName);
|
2010-06-03 06:28:45 +00:00
|
|
|
}
|
|
|
|
|
2011-04-20 21:20:59 +00:00
|
|
|
void Layer::onFrameQueued() {
|
|
|
|
if (android_atomic_or(1, &mQueuedFrames) == 0) {
|
|
|
|
mFlinger->signalEvent();
|
|
|
|
}
|
2010-06-09 02:54:15 +00:00
|
|
|
}
|
|
|
|
|
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()
|
|
|
|
{
|
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
|
|
|
|
2011-04-20 21:20:59 +00:00
|
|
|
sp<ISurface> Layer::createSurface()
|
2009-03-04 03:31:44 +00:00
|
|
|
{
|
2011-04-20 21:20:59 +00:00
|
|
|
class BSurface : public BnSurface, public LayerCleaner {
|
|
|
|
wp<const Layer> mOwner;
|
|
|
|
virtual sp<ISurfaceTexture> getSurfaceTexture() const {
|
|
|
|
sp<ISurfaceTexture> res;
|
|
|
|
sp<const Layer> that( mOwner.promote() );
|
|
|
|
if (that != NULL) {
|
|
|
|
res = that->mSurfaceTexture;
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
public:
|
|
|
|
BSurface(const sp<SurfaceFlinger>& flinger,
|
|
|
|
const sp<Layer>& layer)
|
|
|
|
: LayerCleaner(flinger, layer), mOwner(layer) { }
|
|
|
|
};
|
|
|
|
sp<ISurface> sur(new BSurface(mFlinger, this));
|
2011-02-16 03:01:06 +00:00
|
|
|
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-08-25 21:59:15 +00:00
|
|
|
|
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;
|
2011-04-20 21:20:59 +00:00
|
|
|
mOpaqueLayer = (flags & ISurfaceComposer::eOpaque);
|
|
|
|
mCurrentOpacity = getOpacityForFormat(format);
|
|
|
|
|
|
|
|
mSurfaceTexture->setDefaultBufferSize(w, h);
|
|
|
|
mSurfaceTexture->setDefaultBufferFormat(format);
|
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;
|
|
|
|
}
|
|
|
|
|
2011-04-20 21:20:59 +00:00
|
|
|
// FIXME: shouldn't we take the state's transform into account here?
|
|
|
|
|
|
|
|
Transform tr(Transform(mOrientation) * Transform(mCurrentTransform));
|
2010-12-09 01:23:18 +00:00
|
|
|
hwcl->transform = tr.getOrientation();
|
2010-08-11 00:14:02 +00:00
|
|
|
|
2011-04-20 21:20:59 +00:00
|
|
|
if (!isOpaque()) {
|
2010-08-11 00:14:02 +00:00
|
|
|
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) {
|
2011-04-20 21:20:59 +00:00
|
|
|
const sp<GraphicBuffer>& buffer(mActiveBuffer);
|
2010-08-11 00:14:02 +00:00
|
|
|
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
|
|
|
|
2011-04-20 21:20:59 +00:00
|
|
|
if (isCropped()) {
|
|
|
|
hwcl->sourceCrop.left = mCurrentCrop.left;
|
|
|
|
hwcl->sourceCrop.top = mCurrentCrop.top;
|
|
|
|
hwcl->sourceCrop.right = mCurrentCrop.right;
|
|
|
|
hwcl->sourceCrop.bottom = mCurrentCrop.bottom;
|
2010-12-09 01:40:28 +00:00
|
|
|
} 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
|
|
|
}
|
|
|
|
|
2011-04-20 21:20:59 +00:00
|
|
|
static inline uint16_t pack565(int r, int g, int b) {
|
|
|
|
return (r<<11)|(g<<5)|b;
|
2010-09-29 20:02:36 +00:00
|
|
|
}
|
2009-03-04 03:31:44 +00:00
|
|
|
void Layer::onDraw(const Region& clip) const
|
|
|
|
{
|
2011-04-20 21:20:59 +00:00
|
|
|
if (CC_UNLIKELY(mActiveBuffer == 0)) {
|
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;
|
|
|
|
}
|
2011-04-20 21:20:59 +00:00
|
|
|
|
|
|
|
GLenum target = mSurfaceTexture->getCurrentTextureTarget();
|
|
|
|
glBindTexture(target, mTextureName);
|
|
|
|
if (getFiltering() || needsFiltering() || isFixedSize() || isCropped()) {
|
|
|
|
// TODO: we could be more subtle with isFixedSize()
|
|
|
|
glTexParameterx(target, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
|
|
|
glTexParameterx(target, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
|
|
|
} else {
|
|
|
|
glTexParameterx(target, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
|
|
|
glTexParameterx(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
|
|
|
}
|
|
|
|
glEnable(target);
|
|
|
|
glMatrixMode(GL_TEXTURE);
|
|
|
|
glLoadMatrixf(mTextureMatrix);
|
|
|
|
glMatrixMode(GL_MODELVIEW);
|
|
|
|
|
|
|
|
drawWithOpenGL(clip);
|
|
|
|
|
|
|
|
glDisable(target);
|
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)
|
|
|
|
|
2011-04-20 21:20:59 +00:00
|
|
|
bool Layer::getOpacityForFormat(uint32_t format)
|
2011-02-10 22:41:26 +00:00
|
|
|
{
|
2011-04-20 21:20:59 +00:00
|
|
|
if (HARDWARE_IS_DEVICE_FORMAT(format)) {
|
|
|
|
return true;
|
2011-02-10 22:41:26 +00:00
|
|
|
}
|
2011-04-20 21:20:59 +00:00
|
|
|
PixelFormatInfo info;
|
|
|
|
status_t err = getPixelFormatInfo(PixelFormat(format), &info);
|
|
|
|
// in case of error (unknown format), we assume no blending
|
|
|
|
return (err || info.h_alpha <= info.l_alpha);
|
2011-02-10 22:41:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-04-20 21:20:59 +00:00
|
|
|
bool Layer::isOpaque() const
|
2010-05-27 05:08:52 +00:00
|
|
|
{
|
2011-04-20 21:20:59 +00:00
|
|
|
// if we don't have a buffer yet, we're translucent regardless of the
|
|
|
|
// layer's opaque flag.
|
|
|
|
if (mActiveBuffer == 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// if the layer has the opaque flag, then we're always opaque,
|
|
|
|
// otherwise we use the current buffer's format.
|
|
|
|
return mOpaqueLayer || mCurrentOpacity;
|
2010-05-27 05:08:52 +00:00
|
|
|
}
|
|
|
|
|
2011-03-10 01:05:02 +00:00
|
|
|
bool Layer::isProtected() const
|
|
|
|
{
|
2011-04-20 21:20:59 +00:00
|
|
|
const sp<GraphicBuffer>& activeBuffer(mActiveBuffer);
|
2011-03-10 01:05:02 +00:00
|
|
|
return (activeBuffer != 0) &&
|
|
|
|
(activeBuffer->getUsage() & GRALLOC_USAGE_PROTECTED);
|
|
|
|
}
|
2010-05-07 22:58:44 +00:00
|
|
|
|
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,
|
2011-04-20 21:20:59 +00:00
|
|
|
"resize (layer=%p), requested (%dx%d), drawing (%d,%d), "
|
|
|
|
"fixedSize=%d",
|
2010-05-22 00:24:35 +00:00
|
|
|
this,
|
|
|
|
int(temp.requested_w), int(temp.requested_h),
|
2011-04-20 21:20:59 +00:00
|
|
|
int(front.requested_w), int(front.requested_h),
|
|
|
|
isFixedSize());
|
2010-05-22 00:24:35 +00:00
|
|
|
|
|
|
|
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.
|
2011-04-20 21:20:59 +00:00
|
|
|
mSurfaceTexture->setDefaultBufferSize(temp.requested_w, temp.requested_h);
|
2010-05-22 00:24:35 +00:00
|
|
|
}
|
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);
|
|
|
|
}
|
|
|
|
|
2011-04-20 21:20:59 +00:00
|
|
|
bool Layer::isFixedSize() const {
|
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);
|
2011-04-20 21:20:59 +00:00
|
|
|
return mFixedSize;
|
2009-03-04 03:31:44 +00:00
|
|
|
}
|
|
|
|
|
2011-04-20 21:20:59 +00:00
|
|
|
void Layer::setFixedSize(bool fixedSize)
|
|
|
|
{
|
2010-05-22 00:24:35 +00:00
|
|
|
Mutex::Autolock _l(mLock);
|
2011-04-20 21:20:59 +00:00
|
|
|
mFixedSize = fixedSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Layer::isCropped() const {
|
|
|
|
return !mCurrentCrop.isEmpty();
|
2010-05-22 00:24:35 +00:00
|
|
|
}
|
|
|
|
|
2009-03-04 03:31:44 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// pageflip handling...
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void Layer::lockPageFlip(bool& recomputeVisibleRegions)
|
|
|
|
{
|
2011-04-20 21:20:59 +00:00
|
|
|
if (android_atomic_and(0, &mQueuedFrames)) {
|
|
|
|
if (mSurfaceTexture->updateTexImage() < NO_ERROR) {
|
|
|
|
// something happened!
|
|
|
|
recomputeVisibleRegions = true;
|
|
|
|
return;
|
|
|
|
}
|
2010-03-16 01:15:20 +00:00
|
|
|
|
2011-04-20 21:20:59 +00:00
|
|
|
// signal another event if we have more frames waiting
|
|
|
|
if (mSurfaceTexture->getQueuedCount()) {
|
|
|
|
if (android_atomic_or(1, &mQueuedFrames) == 0) {
|
|
|
|
mFlinger->signalEvent();
|
|
|
|
}
|
|
|
|
}
|
2010-12-14 02:51:59 +00:00
|
|
|
|
2011-04-20 21:20:59 +00:00
|
|
|
mActiveBuffer = mSurfaceTexture->getCurrentBuffer();
|
|
|
|
mSurfaceTexture->getTransformMatrix(mTextureMatrix);
|
2011-02-10 22:41:26 +00:00
|
|
|
|
2011-04-20 21:20:59 +00:00
|
|
|
const Rect crop(mSurfaceTexture->getCurrentCrop());
|
|
|
|
const uint32_t transform(mSurfaceTexture->getCurrentTransform());
|
|
|
|
if ((crop != mCurrentCrop) || (transform != mCurrentTransform)) {
|
|
|
|
mCurrentCrop = crop;
|
|
|
|
mCurrentTransform = transform;
|
|
|
|
mFlinger->invalidateHwcGeometry();
|
|
|
|
}
|
2010-12-14 02:51:59 +00:00
|
|
|
|
2011-04-20 21:20:59 +00:00
|
|
|
const bool opacity(getOpacityForFormat(mActiveBuffer->format));
|
|
|
|
if (opacity != mCurrentOpacity) {
|
|
|
|
mCurrentOpacity = opacity;
|
2011-02-10 22:41:26 +00:00
|
|
|
recomputeVisibleRegions = true;
|
|
|
|
}
|
|
|
|
|
2011-04-20 21:20:59 +00:00
|
|
|
const GLenum target(mSurfaceTexture->getCurrentTextureTarget());
|
|
|
|
glTexParameterx(target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
|
|
|
glTexParameterx(target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
2010-03-16 01:15:20 +00:00
|
|
|
|
|
|
|
// update the layer size and release freeze-lock
|
|
|
|
const Layer::State& front(drawingState());
|
2011-04-20 21:20:59 +00:00
|
|
|
|
|
|
|
// FIXME: mPostedDirtyRegion = dirty & bounds
|
|
|
|
mPostedDirtyRegion.set(front.w, front.h);
|
|
|
|
|
|
|
|
sp<GraphicBuffer> newFrontBuffer(mActiveBuffer);
|
2011-05-16 23:55:03 +00:00
|
|
|
if ((newFrontBuffer->getWidth() == front.requested_w &&
|
|
|
|
newFrontBuffer->getHeight() == front.requested_h) ||
|
|
|
|
isFixedSize())
|
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();
|
|
|
|
}
|
2009-10-07 23:44:10 +00:00
|
|
|
}
|
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);
|
|
|
|
|
2011-04-20 21:20:59 +00:00
|
|
|
sp<const GraphicBuffer> buf0(mActiveBuffer);
|
|
|
|
uint32_t w0=0, h0=0, s0=0, f0=0;
|
2010-04-21 00:55:49 +00:00
|
|
|
if (buf0 != 0) {
|
|
|
|
w0 = buf0->getWidth();
|
|
|
|
h0 = buf0->getHeight();
|
|
|
|
s0 = buf0->getStride();
|
2011-04-20 21:20:59 +00:00
|
|
|
f0 = buf0->format;
|
2010-04-21 00:55:49 +00:00
|
|
|
}
|
|
|
|
snprintf(buffer, SIZE,
|
|
|
|
" "
|
2011-04-20 21:20:59 +00:00
|
|
|
"format=%2d, activeBuffer=[%3ux%3u:%3u,%3u],"
|
|
|
|
" freezeLock=%p, queued-frames=%d\n",
|
|
|
|
mFormat, w0, h0, s0,f0,
|
|
|
|
getFreezeLock().get(), mQueuedFrames);
|
2010-04-21 00:55:49 +00:00
|
|
|
|
|
|
|
result.append(buffer);
|
2010-05-11 03:06:11 +00:00
|
|
|
|
2011-04-20 21:20:59 +00:00
|
|
|
if (mSurfaceTexture != 0) {
|
|
|
|
mSurfaceTexture->dump(result, " ", buffer, SIZE);
|
2010-05-19 00:06:55 +00:00
|
|
|
}
|
2010-05-11 03:06:11 +00:00
|
|
|
}
|
|
|
|
|
2011-04-20 21:20:59 +00:00
|
|
|
uint32_t Layer::getEffectiveUsage(uint32_t usage) const
|
2010-05-07 22:58:44 +00:00
|
|
|
{
|
2011-04-20 21:20:59 +00:00
|
|
|
// TODO: should we do something special if mSecure is set?
|
|
|
|
if (mProtectedByApp) {
|
|
|
|
// need a hardware-protected path to external video sink
|
|
|
|
usage |= GraphicBuffer::USAGE_PROTECTED;
|
2010-05-07 22:58:44 +00:00
|
|
|
}
|
2011-04-20 21:20:59 +00:00
|
|
|
return usage;
|
2010-05-07 22:58:44 +00:00
|
|
|
}
|
|
|
|
|
2009-03-04 03:31:44 +00:00
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
}; // namespace android
|