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"
|
2012-01-20 02:34:40 +00:00
|
|
|
#include <math.h>
|
2009-03-04 03:31:44 +00:00
|
|
|
|
|
|
|
#define DEBUG_RESIZE 0
|
|
|
|
|
|
|
|
namespace android {
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
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),
|
2011-07-18 23:15:08 +00:00
|
|
|
mCurrentScalingMode(NATIVE_WINDOW_SCALING_MODE_FREEZE),
|
2011-04-20 21:20:59 +00:00
|
|
|
mCurrentOpacity(true),
|
2012-02-24 04:05:39 +00:00
|
|
|
mRefreshPending(false),
|
2012-01-20 02:34:40 +00:00
|
|
|
mFrameLatencyNeeded(false),
|
|
|
|
mFrameLatencyOffset(0),
|
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-07-18 23:15:08 +00:00
|
|
|
mProtectedByApp(false)
|
2009-04-22 22:23:34 +00:00
|
|
|
{
|
2011-04-20 21:20:59 +00:00
|
|
|
mCurrentCrop.makeInvalid();
|
|
|
|
glGenTextures(1, &mTextureName);
|
2012-01-16 02:54:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Layer::onLayerDisplayed() {
|
|
|
|
if (mFrameLatencyNeeded) {
|
2012-01-20 02:34:40 +00:00
|
|
|
const DisplayHardware& hw(graphicPlane(0).displayHardware());
|
|
|
|
mFrameStats[mFrameLatencyOffset].timestamp = mSurfaceTexture->getTimestamp();
|
|
|
|
mFrameStats[mFrameLatencyOffset].set = systemTime();
|
|
|
|
mFrameStats[mFrameLatencyOffset].vsync = hw.getRefreshTimestamp();
|
2012-01-16 02:54:57 +00:00
|
|
|
mFrameLatencyOffset = (mFrameLatencyOffset + 1) % 128;
|
|
|
|
mFrameLatencyNeeded = false;
|
|
|
|
}
|
2010-05-11 03:06:11 +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
|
|
|
|
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);
|
2012-02-05 09:49:16 +00:00
|
|
|
#ifdef USE_TRIPLE_BUFFERING
|
|
|
|
#warning "using triple buffering"
|
|
|
|
mSurfaceTexture->setBufferCountServer(3);
|
|
|
|
#else
|
2011-04-20 21:20:59 +00:00
|
|
|
mSurfaceTexture->setBufferCountServer(2);
|
2012-02-05 09:49:16 +00:00
|
|
|
#endif
|
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-10-13 23:02:48 +00:00
|
|
|
mFlinger->postMessageAsync(
|
|
|
|
new SurfaceFlinger::MessageDestroyGLTexture(mTextureName) );
|
2010-06-03 06:28:45 +00:00
|
|
|
}
|
|
|
|
|
2011-04-20 21:20:59 +00:00
|
|
|
void Layer::onFrameQueued() {
|
2011-06-27 01:27:47 +00:00
|
|
|
android_atomic_inc(&mQueuedFrames);
|
2012-02-01 02:24:27 +00:00
|
|
|
mFlinger->signalLayerUpdate();
|
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()
|
|
|
|
{
|
2011-07-30 21:33:49 +00:00
|
|
|
mSurfaceTexture->abandon();
|
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-09-17 00:31:54 +00:00
|
|
|
void Layer::setName(const String8& name) {
|
|
|
|
LayerBase::setName(name);
|
|
|
|
mSurfaceTexture->setName(name);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2011-08-18 01:19:00 +00:00
|
|
|
wp<IBinder> Layer::getSurfaceTextureBinder() const
|
|
|
|
{
|
|
|
|
return mSurfaceTexture->asBinder();
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
2011-08-02 22:51:37 +00:00
|
|
|
LayerBaseClient::setGeometry(hwcl);
|
|
|
|
|
|
|
|
hwcl->flags &= ~HWC_SKIP_LAYER;
|
2010-08-11 00:14:02 +00:00
|
|
|
|
|
|
|
// we can't do alpha-fade with the hwc HAL
|
|
|
|
const State& s(drawingState());
|
|
|
|
if (s.alpha < 0xFF) {
|
|
|
|
hwcl->flags = HWC_SKIP_LAYER;
|
|
|
|
}
|
|
|
|
|
2011-07-12 21:51:45 +00:00
|
|
|
/*
|
|
|
|
* Transformations are applied in this order:
|
|
|
|
* 1) buffer orientation/flip/mirror
|
|
|
|
* 2) state transformation (window manager)
|
|
|
|
* 3) layer orientation (screen orientation)
|
2011-08-19 01:31:00 +00:00
|
|
|
* mTransform is already the composition of (2) and (3)
|
2011-07-12 21:51:45 +00:00
|
|
|
* (NOTE: the matrices are multiplied in reverse order)
|
|
|
|
*/
|
|
|
|
|
|
|
|
const Transform bufferOrientation(mCurrentTransform);
|
2011-08-19 01:31:00 +00:00
|
|
|
const Transform tr(mTransform * bufferOrientation);
|
2011-07-12 21:51:45 +00:00
|
|
|
|
|
|
|
// this gives us only the "orientation" component of the transform
|
|
|
|
const uint32_t finalTransform = tr.getOrientation();
|
|
|
|
|
2010-08-11 00:14:02 +00:00
|
|
|
// we can only handle simple transformation
|
2011-07-12 21:51:45 +00:00
|
|
|
if (finalTransform & Transform::ROT_INVALID) {
|
2010-08-11 00:14:02 +00:00
|
|
|
hwcl->flags = HWC_SKIP_LAYER;
|
2011-08-02 22:51:37 +00:00
|
|
|
} else {
|
|
|
|
hwcl->transform = finalTransform;
|
2010-08-11 00:14:02 +00:00
|
|
|
}
|
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 {
|
2011-08-30 22:02:41 +00:00
|
|
|
const sp<GraphicBuffer>& buffer(mActiveBuffer);
|
2010-12-09 01:40:28 +00:00
|
|
|
hwcl->sourceCrop.left = 0;
|
|
|
|
hwcl->sourceCrop.top = 0;
|
2011-08-03 01:29:51 +00:00
|
|
|
if (buffer != NULL) {
|
|
|
|
hwcl->sourceCrop.right = buffer->width;
|
|
|
|
hwcl->sourceCrop.bottom = buffer->height;
|
|
|
|
} else {
|
|
|
|
hwcl->sourceCrop.right = mTransformedBounds.width();
|
|
|
|
hwcl->sourceCrop.bottom = mTransformedBounds.height();
|
|
|
|
}
|
2010-12-09 01:40:28 +00:00
|
|
|
}
|
2010-08-11 00:14:02 +00:00
|
|
|
}
|
|
|
|
|
2011-08-30 22:02:41 +00:00
|
|
|
void Layer::setPerFrameData(hwc_layer_t* hwcl) {
|
|
|
|
const sp<GraphicBuffer>& buffer(mActiveBuffer);
|
|
|
|
if (buffer == NULL) {
|
|
|
|
// 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;
|
|
|
|
hwcl->handle = NULL;
|
|
|
|
} else {
|
|
|
|
hwcl->handle = buffer->handle;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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;
|
2011-08-23 19:34:29 +00:00
|
|
|
const SurfaceFlinger::LayerVector& drawingLayers(
|
|
|
|
mFlinger->mDrawingState.layersSortedByZ);
|
2010-05-07 03:21:45 +00:00
|
|
|
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
|
|
|
|
2011-10-07 21:51:16 +00:00
|
|
|
if (!isProtected()) {
|
2011-10-18 21:49:27 +00:00
|
|
|
glBindTexture(GL_TEXTURE_EXTERNAL_OES, mTextureName);
|
|
|
|
GLenum filter = GL_NEAREST;
|
2011-10-07 21:51:16 +00:00
|
|
|
if (getFiltering() || needsFiltering() || isFixedSize() || isCropped()) {
|
|
|
|
// TODO: we could be more subtle with isFixedSize()
|
2011-10-18 21:49:27 +00:00
|
|
|
filter = GL_LINEAR;
|
2011-10-07 21:51:16 +00:00
|
|
|
}
|
2011-10-18 21:49:27 +00:00
|
|
|
glTexParameterx(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MAG_FILTER, filter);
|
|
|
|
glTexParameterx(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MIN_FILTER, filter);
|
2011-10-07 21:51:16 +00:00
|
|
|
glMatrixMode(GL_TEXTURE);
|
|
|
|
glLoadMatrixf(mTextureMatrix);
|
|
|
|
glMatrixMode(GL_MODELVIEW);
|
2011-10-18 21:49:27 +00:00
|
|
|
glDisable(GL_TEXTURE_2D);
|
2011-10-21 23:18:48 +00:00
|
|
|
glEnable(GL_TEXTURE_EXTERNAL_OES);
|
2011-04-20 21:20:59 +00:00
|
|
|
} else {
|
2011-10-18 21:49:27 +00:00
|
|
|
glBindTexture(GL_TEXTURE_2D, mFlinger->getProtectedTexName());
|
2011-10-07 21:51:16 +00:00
|
|
|
glMatrixMode(GL_TEXTURE);
|
|
|
|
glLoadIdentity();
|
|
|
|
glMatrixMode(GL_MODELVIEW);
|
2011-10-18 21:49:27 +00:00
|
|
|
glDisable(GL_TEXTURE_EXTERNAL_OES);
|
|
|
|
glEnable(GL_TEXTURE_2D);
|
2011-04-20 21:20:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
drawWithOpenGL(clip);
|
|
|
|
|
2011-10-18 21:49:27 +00:00
|
|
|
glDisable(GL_TEXTURE_EXTERNAL_OES);
|
|
|
|
glDisable(GL_TEXTURE_2D);
|
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.
|
2011-07-28 21:54:07 +00:00
|
|
|
if (mActiveBuffer == 0) {
|
2011-04-20 21:20:59 +00:00
|
|
|
return false;
|
2011-07-28 21:54:07 +00:00
|
|
|
}
|
2011-04-20 21:20:59 +00:00
|
|
|
|
|
|
|
// 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
|
2011-12-20 16:23:08 +00:00
|
|
|
ALOGD_IF(DEBUG_RESIZE,
|
2011-07-26 02:56:08 +00:00
|
|
|
"doTransaction: "
|
2011-04-20 21:20:59 +00:00
|
|
|
"resize (layer=%p), requested (%dx%d), drawing (%d,%d), "
|
2011-07-26 02:56:08 +00:00
|
|
|
"scalingMode=%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),
|
2011-07-26 02:56:08 +00:00
|
|
|
mCurrentScalingMode);
|
2010-05-22 00:24:35 +00:00
|
|
|
|
|
|
|
if (!isFixedSize()) {
|
|
|
|
// 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;
|
|
|
|
}
|
2011-09-26 23:54:44 +00:00
|
|
|
|
|
|
|
// record the new size, form this point on, when the client request
|
|
|
|
// a buffer, it'll get the new size.
|
|
|
|
mSurfaceTexture->setDefaultBufferSize(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
|
|
|
return LayerBase::doTransaction(flags);
|
|
|
|
}
|
|
|
|
|
2011-04-20 21:20:59 +00:00
|
|
|
bool Layer::isFixedSize() const {
|
2011-07-18 23:15:08 +00:00
|
|
|
return mCurrentScalingMode != NATIVE_WINDOW_SCALING_MODE_FREEZE;
|
2011-04-20 21:20:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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...
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2012-02-24 04:05:39 +00:00
|
|
|
bool Layer::onPreComposition() {
|
|
|
|
mRefreshPending = false;
|
|
|
|
return mQueuedFrames > 0;
|
2012-02-01 02:24:27 +00:00
|
|
|
}
|
|
|
|
|
2009-03-04 03:31:44 +00:00
|
|
|
void Layer::lockPageFlip(bool& recomputeVisibleRegions)
|
|
|
|
{
|
2011-06-27 01:27:47 +00:00
|
|
|
if (mQueuedFrames > 0) {
|
2012-02-01 02:24:27 +00:00
|
|
|
|
|
|
|
// if we've already called updateTexImage() without going through
|
|
|
|
// a composition step, we have to skip this layer at this point
|
|
|
|
// because we cannot call updateTeximage() without a corresponding
|
|
|
|
// compositionComplete() call.
|
|
|
|
// we'll trigger an update in onPreComposition().
|
2012-02-24 04:05:39 +00:00
|
|
|
if (mRefreshPending) {
|
|
|
|
mPostedDirtyRegion.clear();
|
2012-02-01 02:24:27 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-02-24 04:05:39 +00:00
|
|
|
mRefreshPending = true;
|
2012-02-01 02:24:27 +00:00
|
|
|
|
2011-09-15 01:23:37 +00:00
|
|
|
// Capture the old state of the layer for comparisons later
|
2011-07-28 21:54:07 +00:00
|
|
|
const bool oldOpacity = isOpaque();
|
2011-09-15 01:23:37 +00:00
|
|
|
sp<GraphicBuffer> oldActiveBuffer = mActiveBuffer;
|
2011-07-28 21:54:07 +00:00
|
|
|
|
2011-06-27 01:27:47 +00:00
|
|
|
// signal another event if we have more frames pending
|
|
|
|
if (android_atomic_dec(&mQueuedFrames) > 1) {
|
2012-02-01 02:24:27 +00:00
|
|
|
mFlinger->signalLayerUpdate();
|
2011-06-27 01:27:47 +00:00
|
|
|
}
|
|
|
|
|
2011-04-20 21:20:59 +00:00
|
|
|
if (mSurfaceTexture->updateTexImage() < NO_ERROR) {
|
|
|
|
// something happened!
|
|
|
|
recomputeVisibleRegions = true;
|
|
|
|
return;
|
|
|
|
}
|
2010-03-16 01:15:20 +00:00
|
|
|
|
2011-09-15 01:23:37 +00:00
|
|
|
// update the active buffer
|
|
|
|
mActiveBuffer = mSurfaceTexture->getCurrentBuffer();
|
2012-01-16 02:54:57 +00:00
|
|
|
mFrameLatencyNeeded = true;
|
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());
|
2011-07-18 23:15:08 +00:00
|
|
|
const uint32_t scalingMode(mSurfaceTexture->getCurrentScalingMode());
|
|
|
|
if ((crop != mCurrentCrop) ||
|
|
|
|
(transform != mCurrentTransform) ||
|
|
|
|
(scalingMode != mCurrentScalingMode))
|
|
|
|
{
|
2011-04-20 21:20:59 +00:00
|
|
|
mCurrentCrop = crop;
|
|
|
|
mCurrentTransform = transform;
|
2011-07-18 23:15:08 +00:00
|
|
|
mCurrentScalingMode = scalingMode;
|
2011-04-20 21:20:59 +00:00
|
|
|
mFlinger->invalidateHwcGeometry();
|
|
|
|
}
|
2010-12-14 02:51:59 +00:00
|
|
|
|
2011-08-30 22:02:41 +00:00
|
|
|
GLfloat textureMatrix[16];
|
|
|
|
mSurfaceTexture->getTransformMatrix(textureMatrix);
|
|
|
|
if (memcmp(textureMatrix, mTextureMatrix, sizeof(textureMatrix))) {
|
|
|
|
memcpy(mTextureMatrix, textureMatrix, sizeof(textureMatrix));
|
|
|
|
mFlinger->invalidateHwcGeometry();
|
|
|
|
}
|
|
|
|
|
2011-09-15 01:23:37 +00:00
|
|
|
uint32_t bufWidth = mActiveBuffer->getWidth();
|
|
|
|
uint32_t bufHeight = mActiveBuffer->getHeight();
|
|
|
|
if (oldActiveBuffer != NULL) {
|
|
|
|
if (bufWidth != uint32_t(oldActiveBuffer->width) ||
|
|
|
|
bufHeight != uint32_t(oldActiveBuffer->height)) {
|
2011-08-30 22:02:41 +00:00
|
|
|
mFlinger->invalidateHwcGeometry();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-15 01:23:37 +00:00
|
|
|
mCurrentOpacity = getOpacityForFormat(mActiveBuffer->format);
|
2011-07-28 21:54:07 +00:00
|
|
|
if (oldOpacity != isOpaque()) {
|
2011-02-10 22:41:26 +00:00
|
|
|
recomputeVisibleRegions = true;
|
|
|
|
}
|
|
|
|
|
2011-08-23 19:34:29 +00:00
|
|
|
glTexParameterx(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
|
|
|
glTexParameterx(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
2010-03-16 01:15:20 +00:00
|
|
|
|
2011-10-14 23:44:08 +00:00
|
|
|
// update the layer size if needed
|
2010-03-16 01:15:20 +00:00
|
|
|
const Layer::State& front(drawingState());
|
2011-04-20 21:20:59 +00:00
|
|
|
|
|
|
|
// FIXME: mPostedDirtyRegion = dirty & bounds
|
|
|
|
mPostedDirtyRegion.set(front.w, front.h);
|
|
|
|
|
2011-07-19 22:24:46 +00:00
|
|
|
if ((front.w != front.requested_w) ||
|
|
|
|
(front.h != front.requested_h))
|
2009-09-30 21:07:22 +00:00
|
|
|
{
|
2011-07-19 22:24:46 +00:00
|
|
|
// check that we received a buffer of the right size
|
|
|
|
// (Take the buffer's orientation into account)
|
|
|
|
if (mCurrentTransform & Transform::ROT_90) {
|
|
|
|
swap(bufWidth, bufHeight);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isFixedSize() ||
|
|
|
|
(bufWidth == front.requested_w &&
|
|
|
|
bufHeight == front.requested_h))
|
2010-03-16 01:15:20 +00:00
|
|
|
{
|
|
|
|
// 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;
|
2011-07-19 22:24:46 +00:00
|
|
|
}
|
2011-07-26 02:56:08 +00:00
|
|
|
|
2011-12-20 16:23:08 +00:00
|
|
|
ALOGD_IF(DEBUG_RESIZE,
|
2011-07-26 02:56:08 +00:00
|
|
|
"lockPageFlip : "
|
|
|
|
" (layer=%p), buffer (%ux%u, tr=%02x), "
|
|
|
|
"requested (%dx%d)",
|
|
|
|
this,
|
|
|
|
bufWidth, bufHeight, mCurrentTransform,
|
|
|
|
front.requested_w, front.requested_h);
|
2010-03-16 01:15:20 +00:00
|
|
|
}
|
2009-10-07 23:44:10 +00:00
|
|
|
}
|
2009-03-04 03:31:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Layer::unlockPageFlip(
|
|
|
|
const Transform& planeTransform, Region& outDirtyRegion)
|
|
|
|
{
|
2012-02-24 04:05:39 +00:00
|
|
|
Region postedRegion(mPostedDirtyRegion);
|
|
|
|
if (!postedRegion.isEmpty()) {
|
2009-03-04 03:31:44 +00:00
|
|
|
mPostedDirtyRegion.clear();
|
2012-02-24 04:05:39 +00:00
|
|
|
if (!visibleRegionScreen.isEmpty()) {
|
|
|
|
// 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);
|
|
|
|
postedRegion = tr.transform(postedRegion);
|
|
|
|
|
|
|
|
// 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).
|
|
|
|
postedRegion.andSelf(visibleRegionScreen);
|
|
|
|
outDirtyRegion.orSelf(postedRegion);
|
|
|
|
}
|
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-08-08 23:02:13 +00:00
|
|
|
"format=%2d, activeBuffer=[%4ux%4u:%4u,%3X],"
|
2012-02-01 02:24:27 +00:00
|
|
|
" transform-hint=0x%02x, queued-frames=%d, mRefreshPending=%d\n",
|
2011-04-20 21:20:59 +00:00
|
|
|
mFormat, w0, h0, s0,f0,
|
2012-02-01 02:24:27 +00:00
|
|
|
getTransformHint(), mQueuedFrames, mRefreshPending);
|
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
|
|
|
}
|
|
|
|
|
2012-01-20 02:34:40 +00:00
|
|
|
void Layer::dumpStats(String8& result, char* buffer, size_t SIZE) const
|
|
|
|
{
|
|
|
|
LayerBaseClient::dumpStats(result, buffer, SIZE);
|
|
|
|
const size_t o = mFrameLatencyOffset;
|
|
|
|
const DisplayHardware& hw(graphicPlane(0).displayHardware());
|
|
|
|
const nsecs_t period = hw.getRefreshPeriod();
|
|
|
|
result.appendFormat("%lld\n", period);
|
|
|
|
for (size_t i=0 ; i<128 ; i++) {
|
|
|
|
const size_t index = (o+i) % 128;
|
|
|
|
const nsecs_t time_app = mFrameStats[index].timestamp;
|
|
|
|
const nsecs_t time_set = mFrameStats[index].set;
|
|
|
|
const nsecs_t time_vsync = mFrameStats[index].vsync;
|
|
|
|
result.appendFormat("%lld\t%lld\t%lld\n",
|
|
|
|
time_app,
|
|
|
|
time_vsync,
|
|
|
|
time_set);
|
|
|
|
}
|
|
|
|
result.append("\n");
|
|
|
|
}
|
|
|
|
|
2012-01-29 06:31:55 +00:00
|
|
|
void Layer::clearStats()
|
|
|
|
{
|
|
|
|
LayerBaseClient::clearStats();
|
|
|
|
memset(mFrameStats, 0, sizeof(mFrameStats));
|
|
|
|
}
|
|
|
|
|
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-08-10 18:48:07 +00:00
|
|
|
usage |= GraphicBuffer::USAGE_HW_COMPOSER;
|
2011-04-20 21:20:59 +00:00
|
|
|
return usage;
|
2010-05-07 22:58:44 +00:00
|
|
|
}
|
|
|
|
|
2011-08-24 01:03:18 +00:00
|
|
|
uint32_t Layer::getTransformHint() const {
|
|
|
|
uint32_t orientation = 0;
|
|
|
|
if (!mFlinger->mDebugDisableTransformHint) {
|
2011-09-23 22:54:34 +00:00
|
|
|
orientation = getPlaneOrientation();
|
2011-08-24 01:03:18 +00:00
|
|
|
if (orientation & Transform::ROT_INVALID) {
|
|
|
|
orientation = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return orientation;
|
|
|
|
}
|
|
|
|
|
2009-03-04 03:31:44 +00:00
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
}; // namespace android
|