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.
|
|
|
|
*/
|
|
|
|
|
2012-02-24 03:27:23 +00:00
|
|
|
#define ATRACE_TAG ATRACE_TAG_GRAPHICS
|
|
|
|
|
2009-03-04 03:31:44 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <sys/types.h>
|
2012-02-26 02:48:35 +00:00
|
|
|
#include <math.h>
|
2009-03-04 03:31:44 +00:00
|
|
|
|
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>
|
2012-02-24 03:27:23 +00:00
|
|
|
#include <utils/Trace.h>
|
2009-03-04 03:31:44 +00:00
|
|
|
|
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
|
|
|
|
2012-02-26 02:48:35 +00:00
|
|
|
#include <gui/Surface.h>
|
2009-03-04 03:31:44 +00:00
|
|
|
|
|
|
|
#include "clz.h"
|
2012-08-01 06:09:07 +00:00
|
|
|
#include "DisplayDevice.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
|
|
|
|
2012-06-21 00:51:20 +00:00
|
|
|
#include "DisplayHardware/HWComposer.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-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
|
|
|
}
|
|
|
|
|
2012-08-05 07:40:46 +00:00
|
|
|
void Layer::onLayerDisplayed(const sp<const DisplayDevice>& hw,
|
2012-08-02 21:01:42 +00:00
|
|
|
HWComposer::HWCLayerInterface* layer) {
|
2012-06-14 21:45:17 +00:00
|
|
|
if (layer) {
|
|
|
|
mSurfaceTexture->setReleaseFence(layer->getAndResetReleaseFenceFd());
|
|
|
|
}
|
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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2012-02-23 22:35:13 +00:00
|
|
|
|
|
|
|
// Creates a custom BufferQueue for SurfaceTexture to use
|
|
|
|
sp<BufferQueue> bq = new SurfaceTextureLayer();
|
|
|
|
mSurfaceTexture = new SurfaceTexture(mTextureName, true,
|
2012-04-23 20:59:36 +00:00
|
|
|
GL_TEXTURE_EXTERNAL_OES, false, bq);
|
2012-02-23 22:35:13 +00:00
|
|
|
|
|
|
|
mSurfaceTexture->setConsumerUsageBits(getEffectiveUsage(0));
|
2011-04-20 21:20:59 +00:00
|
|
|
mSurfaceTexture->setFrameAvailableListener(new FrameQueuedListener(this));
|
|
|
|
mSurfaceTexture->setSynchronousMode(true);
|
2012-02-23 22:35:13 +00:00
|
|
|
|
2012-04-24 03:00:16 +00:00
|
|
|
#ifdef TARGET_DISABLE_TRIPLE_BUFFERING
|
|
|
|
#warning "disabling triple buffering"
|
2011-04-20 21:20:59 +00:00
|
|
|
mSurfaceTexture->setBufferCountServer(2);
|
2012-04-24 03:00:16 +00:00
|
|
|
#else
|
|
|
|
mSurfaceTexture->setBufferCountServer(3);
|
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
|
|
|
{
|
2012-07-24 06:11:29 +00:00
|
|
|
mFlinger->deleteTextureAsync(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) {
|
2012-02-23 22:35:13 +00:00
|
|
|
res = that->mSurfaceTexture->getBufferQueue();
|
2011-04-20 21:20:59 +00:00
|
|
|
}
|
|
|
|
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
|
|
|
|
{
|
2012-02-23 22:35:13 +00:00
|
|
|
return mSurfaceTexture->getBufferQueue()->asBinder();
|
2011-08-18 01:19:00 +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);
|
2012-02-24 22:58:36 +00:00
|
|
|
if (err) {
|
|
|
|
ALOGE("unsupported pixelformat %d", format);
|
|
|
|
return err;
|
|
|
|
}
|
2009-03-04 03:31:44 +00:00
|
|
|
|
2010-04-14 23:43:44 +00:00
|
|
|
uint32_t const maxSurfaceDims = min(
|
2012-07-12 21:25:33 +00:00
|
|
|
mFlinger->getMaxTextureSize(), mFlinger->getMaxViewportDims());
|
2010-04-14 23:43:44 +00:00
|
|
|
|
|
|
|
// never allow a surface larger than what our underlying GL implementation
|
|
|
|
// can handle.
|
|
|
|
if ((uint32_t(w)>maxSurfaceDims) || (uint32_t(h)>maxSurfaceDims)) {
|
2012-02-24 22:58:36 +00:00
|
|
|
ALOGE("dimensions too large %u x %u", uint32_t(w), uint32_t(h));
|
2010-04-14 23:43:44 +00:00
|
|
|
return BAD_VALUE;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2012-08-09 02:42:09 +00:00
|
|
|
mSecure = (flags & ISurfaceComposerClient::eSecure) ? true : false;
|
|
|
|
mProtectedByApp = (flags & ISurfaceComposerClient::eProtectedByApp) ? true : false;
|
|
|
|
mOpaqueLayer = (flags & ISurfaceComposerClient::eOpaque);
|
2011-04-20 21:20:59 +00:00
|
|
|
mCurrentOpacity = getOpacityForFormat(format);
|
|
|
|
|
|
|
|
mSurfaceTexture->setDefaultBufferSize(w, h);
|
|
|
|
mSurfaceTexture->setDefaultBufferFormat(format);
|
2012-02-23 22:35:13 +00:00
|
|
|
mSurfaceTexture->setConsumerUsageBits(getEffectiveUsage(0));
|
2010-04-14 23:43:44 +00:00
|
|
|
|
2009-03-04 03:31:44 +00:00
|
|
|
return NO_ERROR;
|
|
|
|
}
|
|
|
|
|
2012-05-11 03:43:55 +00:00
|
|
|
Rect Layer::computeBufferCrop() const {
|
|
|
|
// Start with the SurfaceTexture's buffer crop...
|
|
|
|
Rect crop;
|
|
|
|
if (!mCurrentCrop.isEmpty()) {
|
|
|
|
crop = mCurrentCrop;
|
|
|
|
} else if (mActiveBuffer != NULL){
|
|
|
|
crop = Rect(mActiveBuffer->getWidth(), mActiveBuffer->getHeight());
|
|
|
|
} else {
|
2012-06-29 21:12:52 +00:00
|
|
|
crop.makeInvalid();
|
|
|
|
return crop;
|
2012-05-11 03:43:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ... then reduce that in the same proportions as the window crop reduces
|
|
|
|
// the window size.
|
|
|
|
const State& s(drawingState());
|
2012-05-17 00:07:49 +00:00
|
|
|
if (!s.active.crop.isEmpty()) {
|
2012-05-11 03:43:55 +00:00
|
|
|
// Transform the window crop to match the buffer coordinate system,
|
|
|
|
// which means using the inverse of the current transform set on the
|
|
|
|
// SurfaceTexture.
|
|
|
|
uint32_t invTransform = mCurrentTransform;
|
2012-05-17 00:07:49 +00:00
|
|
|
int winWidth = s.active.w;
|
|
|
|
int winHeight = s.active.h;
|
2012-05-11 03:43:55 +00:00
|
|
|
if (invTransform & NATIVE_WINDOW_TRANSFORM_ROT_90) {
|
|
|
|
invTransform ^= NATIVE_WINDOW_TRANSFORM_FLIP_V |
|
|
|
|
NATIVE_WINDOW_TRANSFORM_FLIP_H;
|
2012-05-17 00:07:49 +00:00
|
|
|
winWidth = s.active.h;
|
|
|
|
winHeight = s.active.w;
|
2012-05-11 03:43:55 +00:00
|
|
|
}
|
2012-05-17 00:07:49 +00:00
|
|
|
Rect winCrop = s.active.crop.transform(invTransform,
|
|
|
|
s.active.w, s.active.h);
|
2012-05-11 03:43:55 +00:00
|
|
|
|
|
|
|
float xScale = float(crop.width()) / float(winWidth);
|
|
|
|
float yScale = float(crop.height()) / float(winHeight);
|
2012-05-17 00:07:49 +00:00
|
|
|
crop.left += int(ceilf(float(winCrop.left) * xScale));
|
|
|
|
crop.top += int(ceilf(float(winCrop.top) * yScale));
|
|
|
|
crop.right -= int(ceilf(float(winWidth - winCrop.right) * xScale));
|
|
|
|
crop.bottom -= int(ceilf(float(winHeight - winCrop.bottom) * yScale));
|
2012-05-11 03:43:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return crop;
|
|
|
|
}
|
|
|
|
|
2012-06-29 21:12:52 +00:00
|
|
|
void Layer::setGeometry(
|
2012-08-05 07:40:46 +00:00
|
|
|
const sp<const DisplayDevice>& hw,
|
2012-06-29 21:12:52 +00:00
|
|
|
HWComposer::HWCLayerInterface& layer)
|
2010-08-11 00:14:02 +00:00
|
|
|
{
|
2012-06-29 21:12:52 +00:00
|
|
|
LayerBaseClient::setGeometry(hw, layer);
|
2011-08-02 22:51:37 +00:00
|
|
|
|
2012-05-14 03:42:01 +00:00
|
|
|
// enable this layer
|
|
|
|
layer.setSkip(false);
|
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) {
|
2012-05-14 03:42:01 +00:00
|
|
|
layer.setSkip(true);
|
2010-08-11 00:14:02 +00:00
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
* (NOTE: the matrices are multiplied in reverse order)
|
|
|
|
*/
|
|
|
|
|
|
|
|
const Transform bufferOrientation(mCurrentTransform);
|
2012-08-05 07:40:46 +00:00
|
|
|
const Transform tr(hw->getTransform() * s.transform * 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) {
|
2012-05-14 03:42:01 +00:00
|
|
|
layer.setSkip(true);
|
2011-08-02 22:51:37 +00:00
|
|
|
} else {
|
2012-05-14 03:42:01 +00:00
|
|
|
layer.setTransform(finalTransform);
|
2010-08-11 00:14:02 +00:00
|
|
|
}
|
2012-05-14 03:42:01 +00:00
|
|
|
layer.setCrop(computeBufferCrop());
|
2010-08-11 00:14:02 +00:00
|
|
|
}
|
|
|
|
|
2012-08-05 07:40:46 +00:00
|
|
|
void Layer::setPerFrameData(const sp<const DisplayDevice>& hw,
|
2012-08-02 21:01:42 +00:00
|
|
|
HWComposer::HWCLayerInterface& layer) {
|
2011-08-30 22:02:41 +00:00
|
|
|
const sp<GraphicBuffer>& buffer(mActiveBuffer);
|
2012-05-14 03:42:01 +00:00
|
|
|
// NOTE: buffer can be NULL if the client never drew into this
|
|
|
|
// layer yet, or if we ran out of memory
|
|
|
|
layer.setBuffer(buffer);
|
2012-07-02 23:49:28 +00:00
|
|
|
}
|
2012-06-29 22:21:18 +00:00
|
|
|
|
2012-08-05 07:40:46 +00:00
|
|
|
void Layer::setAcquireFence(const sp<const DisplayDevice>& hw,
|
2012-08-02 21:01:42 +00:00
|
|
|
HWComposer::HWCLayerInterface& layer) {
|
2012-07-02 23:49:28 +00:00
|
|
|
int fenceFd = -1;
|
2012-08-02 21:01:42 +00:00
|
|
|
|
|
|
|
// TODO: there is a possible optimization here: we only need to set the
|
|
|
|
// acquire fence the first time a new buffer is acquired on EACH display.
|
|
|
|
|
|
|
|
if (layer.getCompositionType() == HWC_OVERLAY) {
|
2012-06-29 22:21:18 +00:00
|
|
|
sp<Fence> fence = mSurfaceTexture->getCurrentFence();
|
|
|
|
if (fence.get()) {
|
2012-07-02 23:49:28 +00:00
|
|
|
fenceFd = fence->dup();
|
2012-06-29 22:21:18 +00:00
|
|
|
if (fenceFd == -1) {
|
|
|
|
ALOGW("failed to dup layer fence, skipping sync: %d", errno);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-07-02 23:49:28 +00:00
|
|
|
layer.setAcquireFenceFd(fenceFd);
|
2011-08-30 22:02:41 +00:00
|
|
|
}
|
|
|
|
|
2012-08-05 07:40:46 +00:00
|
|
|
void Layer::onDraw(const sp<const DisplayDevice>& hw, const Region& clip) const
|
2009-03-04 03:31:44 +00:00
|
|
|
{
|
2012-02-24 03:27:23 +00:00
|
|
|
ATRACE_CALL();
|
|
|
|
|
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;
|
2012-08-05 07:40:46 +00:00
|
|
|
under.orSelf( hw->getTransform().transform(layer->visibleRegion) );
|
2010-05-07 03:21:45 +00:00
|
|
|
}
|
|
|
|
// if not everything below us is covered, we plug the holes!
|
|
|
|
Region holes(clip.subtract(under));
|
|
|
|
if (!holes.isEmpty()) {
|
2012-06-21 00:51:20 +00:00
|
|
|
clearWithOpenGL(hw, 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
|
|
|
|
2012-06-29 22:21:18 +00:00
|
|
|
// TODO: replace this with a server-side wait
|
|
|
|
sp<Fence> fence = mSurfaceTexture->getCurrentFence();
|
|
|
|
if (fence.get()) {
|
|
|
|
status_t err = fence->wait(Fence::TIMEOUT_NEVER);
|
|
|
|
ALOGW_IF(err != OK, "Layer::onDraw: failed waiting for fence: %d", err);
|
|
|
|
// Go ahead and draw the buffer anyway; no matter what we do the screen
|
|
|
|
// is probably going to have something visibly wrong.
|
|
|
|
}
|
|
|
|
|
2011-10-07 21:51:16 +00:00
|
|
|
if (!isProtected()) {
|
2012-05-09 00:05:52 +00:00
|
|
|
// TODO: we could be more subtle with isFixedSize()
|
|
|
|
const bool useFiltering = getFiltering() || needsFiltering() || isFixedSize();
|
|
|
|
|
|
|
|
// Query the texture matrix given our current filtering mode.
|
|
|
|
float textureMatrix[16];
|
|
|
|
mSurfaceTexture->setFilteringEnabled(useFiltering);
|
|
|
|
mSurfaceTexture->getTransformMatrix(textureMatrix);
|
|
|
|
|
|
|
|
// Set things up for texturing.
|
2011-10-18 21:49:27 +00:00
|
|
|
glBindTexture(GL_TEXTURE_EXTERNAL_OES, mTextureName);
|
|
|
|
GLenum filter = GL_NEAREST;
|
2012-05-09 00:05:52 +00:00
|
|
|
if (useFiltering) {
|
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);
|
2012-05-09 00:05:52 +00:00
|
|
|
glLoadMatrixf(textureMatrix);
|
2011-10-07 21:51:16 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2012-06-21 00:51:20 +00:00
|
|
|
drawWithOpenGL(hw, clip);
|
2011-04-20 21:20:59 +00:00
|
|
|
|
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)
|
|
|
|
{
|
2012-02-24 03:27:23 +00:00
|
|
|
ATRACE_CALL();
|
|
|
|
|
2009-03-04 03:31:44 +00:00
|
|
|
const Layer::State& front(drawingState());
|
|
|
|
const Layer::State& temp(currentState());
|
|
|
|
|
2012-06-05 01:16:30 +00:00
|
|
|
const bool sizeChanged = (temp.requested.w != front.requested.w) ||
|
|
|
|
(temp.requested.h != front.requested.h);
|
2010-05-22 00:24:35 +00:00
|
|
|
|
|
|
|
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,
|
2012-05-23 21:34:07 +00:00
|
|
|
"doTransaction: geometry (layer=%p), scalingMode=%d\n"
|
|
|
|
" current={ active ={ wh={%4u,%4u} crop={%4d,%4d,%4d,%4d} (%4d,%4d) }\n"
|
|
|
|
" requested={ wh={%4u,%4u} crop={%4d,%4d,%4d,%4d} (%4d,%4d) }}\n"
|
|
|
|
" drawing={ active ={ wh={%4u,%4u} crop={%4d,%4d,%4d,%4d} (%4d,%4d) }\n"
|
|
|
|
" requested={ wh={%4u,%4u} crop={%4d,%4d,%4d,%4d} (%4d,%4d) }}\n",
|
|
|
|
this, mCurrentScalingMode,
|
|
|
|
temp.active.w, temp.active.h,
|
|
|
|
temp.active.crop.left,
|
|
|
|
temp.active.crop.top,
|
|
|
|
temp.active.crop.right,
|
|
|
|
temp.active.crop.bottom,
|
|
|
|
temp.active.crop.getWidth(),
|
|
|
|
temp.active.crop.getHeight(),
|
|
|
|
temp.requested.w, temp.requested.h,
|
2012-05-17 01:21:32 +00:00
|
|
|
temp.requested.crop.left,
|
|
|
|
temp.requested.crop.top,
|
|
|
|
temp.requested.crop.right,
|
|
|
|
temp.requested.crop.bottom,
|
|
|
|
temp.requested.crop.getWidth(),
|
|
|
|
temp.requested.crop.getHeight(),
|
2012-05-23 21:34:07 +00:00
|
|
|
front.active.w, front.active.h,
|
|
|
|
front.active.crop.left,
|
|
|
|
front.active.crop.top,
|
|
|
|
front.active.crop.right,
|
|
|
|
front.active.crop.bottom,
|
|
|
|
front.active.crop.getWidth(),
|
|
|
|
front.active.crop.getHeight(),
|
|
|
|
front.requested.w, front.requested.h,
|
2012-05-17 01:21:32 +00:00
|
|
|
front.requested.crop.left,
|
|
|
|
front.requested.crop.top,
|
|
|
|
front.requested.crop.right,
|
|
|
|
front.requested.crop.bottom,
|
|
|
|
front.requested.crop.getWidth(),
|
2012-05-23 21:34:07 +00:00
|
|
|
front.requested.crop.getHeight());
|
2010-05-22 00:24:35 +00:00
|
|
|
|
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.
|
2012-05-17 01:21:32 +00:00
|
|
|
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
|
|
|
|
2012-06-07 21:18:55 +00:00
|
|
|
if (!isFixedSize()) {
|
|
|
|
|
|
|
|
const bool resizePending = (temp.requested.w != temp.active.w) ||
|
|
|
|
(temp.requested.h != temp.active.h);
|
|
|
|
|
|
|
|
if (resizePending) {
|
|
|
|
// don't let LayerBase::doTransaction update the drawing state
|
|
|
|
// if we have a pending resize, unless we are in fixed-size mode.
|
|
|
|
// the drawing state will be updated only once we receive a buffer
|
|
|
|
// with the correct size.
|
|
|
|
//
|
|
|
|
// in particular, we want to make sure the clip (which is part
|
|
|
|
// of the geometry state) is latched together with the size but is
|
|
|
|
// latched immediately when no resizing is involved.
|
|
|
|
|
|
|
|
flags |= eDontUpdateGeometryState;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2012-08-02 21:01:42 +00:00
|
|
|
void Layer::onPostComposition() {
|
|
|
|
if (mFrameLatencyNeeded) {
|
|
|
|
const HWComposer& hwc = mFlinger->getHwComposer();
|
|
|
|
const size_t offset = mFrameLatencyOffset;
|
|
|
|
mFrameStats[offset].timestamp = mSurfaceTexture->getTimestamp();
|
|
|
|
mFrameStats[offset].set = systemTime();
|
|
|
|
mFrameStats[offset].vsync = hwc.getRefreshTimestamp();
|
|
|
|
mFrameLatencyOffset = (mFrameLatencyOffset + 1) % 128;
|
|
|
|
mFrameLatencyNeeded = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-29 21:12:52 +00:00
|
|
|
Region Layer::latchBuffer(bool& recomputeVisibleRegions)
|
2009-03-04 03:31:44 +00:00
|
|
|
{
|
2012-02-24 03:27:23 +00:00
|
|
|
ATRACE_CALL();
|
|
|
|
|
2012-06-29 21:12:52 +00:00
|
|
|
Region outDirtyRegion;
|
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) {
|
2012-06-29 21:12:52 +00:00
|
|
|
return outDirtyRegion;
|
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
|
|
|
}
|
|
|
|
|
2012-05-24 00:56:42 +00:00
|
|
|
struct Reject : public SurfaceTexture::BufferRejecter {
|
|
|
|
Layer::State& front;
|
|
|
|
Layer::State& current;
|
|
|
|
bool& recomputeVisibleRegions;
|
|
|
|
Reject(Layer::State& front, Layer::State& current,
|
|
|
|
bool& recomputeVisibleRegions)
|
|
|
|
: front(front), current(current),
|
|
|
|
recomputeVisibleRegions(recomputeVisibleRegions) {
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool reject(const sp<GraphicBuffer>& buf,
|
|
|
|
const BufferQueue::BufferItem& item) {
|
|
|
|
if (buf == NULL) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t bufWidth = buf->getWidth();
|
|
|
|
uint32_t bufHeight = buf->getHeight();
|
|
|
|
|
|
|
|
// check that we received a buffer of the right size
|
|
|
|
// (Take the buffer's orientation into account)
|
|
|
|
if (item.mTransform & Transform::ROT_90) {
|
|
|
|
swap(bufWidth, bufHeight);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool isFixedSize = item.mScalingMode != NATIVE_WINDOW_SCALING_MODE_FREEZE;
|
|
|
|
if (front.active != front.requested) {
|
|
|
|
|
|
|
|
if (isFixedSize ||
|
|
|
|
(bufWidth == front.requested.w &&
|
|
|
|
bufHeight == 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
|
|
|
|
front.active = front.requested;
|
|
|
|
|
|
|
|
// We also need to update the current state so that
|
|
|
|
// we don't end-up overwriting the drawing state with
|
|
|
|
// this stale current state during the next transaction
|
|
|
|
//
|
|
|
|
// NOTE: We don't need to hold the transaction lock here
|
|
|
|
// because State::active is only accessed from this thread.
|
|
|
|
current.active = front.active;
|
|
|
|
|
|
|
|
// recompute visible region
|
|
|
|
recomputeVisibleRegions = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
ALOGD_IF(DEBUG_RESIZE,
|
|
|
|
"lockPageFlip: (layer=%p), buffer (%ux%u, tr=%02x), scalingMode=%d\n"
|
|
|
|
" drawing={ active ={ wh={%4u,%4u} crop={%4d,%4d,%4d,%4d} (%4d,%4d) }\n"
|
|
|
|
" requested={ wh={%4u,%4u} crop={%4d,%4d,%4d,%4d} (%4d,%4d) }}\n",
|
|
|
|
this, bufWidth, bufHeight, item.mTransform, item.mScalingMode,
|
|
|
|
front.active.w, front.active.h,
|
|
|
|
front.active.crop.left,
|
|
|
|
front.active.crop.top,
|
|
|
|
front.active.crop.right,
|
|
|
|
front.active.crop.bottom,
|
|
|
|
front.active.crop.getWidth(),
|
|
|
|
front.active.crop.getHeight(),
|
|
|
|
front.requested.w, front.requested.h,
|
|
|
|
front.requested.crop.left,
|
|
|
|
front.requested.crop.top,
|
|
|
|
front.requested.crop.right,
|
|
|
|
front.requested.crop.bottom,
|
|
|
|
front.requested.crop.getWidth(),
|
|
|
|
front.requested.crop.getHeight());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!isFixedSize) {
|
|
|
|
if (front.active.w != bufWidth ||
|
|
|
|
front.active.h != bufHeight) {
|
2012-06-05 01:16:30 +00:00
|
|
|
// reject this buffer
|
2012-05-24 00:56:42 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
Reject r(mDrawingState, currentState(), recomputeVisibleRegions);
|
|
|
|
|
2012-06-29 21:12:52 +00:00
|
|
|
// XXX: not sure if setTransformHint belongs here
|
|
|
|
// it should only be needed when the main screen orientation changes
|
|
|
|
mSurfaceTexture->setTransformHint(getTransformHint());
|
|
|
|
|
2012-05-24 00:56:42 +00:00
|
|
|
if (mSurfaceTexture->updateTexImage(&r) < NO_ERROR) {
|
2011-04-20 21:20:59 +00:00
|
|
|
// something happened!
|
|
|
|
recomputeVisibleRegions = true;
|
2012-06-29 21:12:52 +00:00
|
|
|
return outDirtyRegion;
|
2011-04-20 21:20:59 +00:00
|
|
|
}
|
2010-03-16 01:15:20 +00:00
|
|
|
|
2011-09-15 01:23:37 +00:00
|
|
|
// update the active buffer
|
|
|
|
mActiveBuffer = mSurfaceTexture->getCurrentBuffer();
|
2012-05-30 03:41:03 +00:00
|
|
|
if (mActiveBuffer == NULL) {
|
|
|
|
// this can only happen if the very first buffer was rejected.
|
2012-06-29 21:12:52 +00:00
|
|
|
return outDirtyRegion;
|
2012-05-30 03:41:03 +00:00
|
|
|
}
|
2010-12-14 02:51:59 +00:00
|
|
|
|
2012-06-05 01:16:30 +00:00
|
|
|
mRefreshPending = true;
|
2012-05-24 00:50:31 +00:00
|
|
|
mFrameLatencyNeeded = true;
|
2012-05-30 03:41:03 +00:00
|
|
|
if (oldActiveBuffer == NULL) {
|
2012-05-24 00:56:42 +00:00
|
|
|
// the first time we receive a buffer, we need to trigger a
|
|
|
|
// geometry invalidation.
|
|
|
|
mFlinger->invalidateHwcGeometry();
|
|
|
|
}
|
2012-05-24 00:50:31 +00:00
|
|
|
|
|
|
|
Rect crop(mSurfaceTexture->getCurrentCrop());
|
2012-05-24 00:56:42 +00:00
|
|
|
const uint32_t transform(mSurfaceTexture->getCurrentTransform());
|
|
|
|
const uint32_t scalingMode(mSurfaceTexture->getCurrentScalingMode());
|
2012-05-24 00:50:31 +00:00
|
|
|
if ((crop != mCurrentCrop) ||
|
|
|
|
(transform != mCurrentTransform) ||
|
|
|
|
(scalingMode != mCurrentScalingMode))
|
|
|
|
{
|
|
|
|
mCurrentCrop = crop;
|
|
|
|
mCurrentTransform = transform;
|
|
|
|
mCurrentScalingMode = scalingMode;
|
|
|
|
mFlinger->invalidateHwcGeometry();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (oldActiveBuffer != NULL) {
|
2012-05-30 03:41:03 +00:00
|
|
|
uint32_t bufWidth = mActiveBuffer->getWidth();
|
|
|
|
uint32_t bufHeight = mActiveBuffer->getHeight();
|
2012-05-24 00:50:31 +00:00
|
|
|
if (bufWidth != uint32_t(oldActiveBuffer->width) ||
|
|
|
|
bufHeight != uint32_t(oldActiveBuffer->height)) {
|
|
|
|
mFlinger->invalidateHwcGeometry();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mCurrentOpacity = getOpacityForFormat(mActiveBuffer->format);
|
|
|
|
if (oldOpacity != isOpaque()) {
|
|
|
|
recomputeVisibleRegions = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2009-03-04 03:31:44 +00:00
|
|
|
|
2012-06-29 21:12:52 +00:00
|
|
|
// FIXME: postedRegion should be dirty & bounds
|
|
|
|
const Layer::State& front(drawingState());
|
|
|
|
Region dirtyRegion(Rect(front.active.w, front.active.h));
|
2012-02-24 03:27:23 +00:00
|
|
|
|
2012-06-29 21:12:52 +00:00
|
|
|
// transform the dirty region to window-manager space
|
|
|
|
outDirtyRegion = (front.transform.transform(dirtyRegion));
|
2009-03-04 03:31:44 +00:00
|
|
|
}
|
2012-06-29 21:12:52 +00:00
|
|
|
return outDirtyRegion;
|
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;
|
2012-08-05 04:10:38 +00:00
|
|
|
const nsecs_t period = mFlinger->getHwComposer().getRefreshPeriod();
|
2012-01-20 02:34:40 +00:00
|
|
|
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) {
|
2012-06-29 21:12:52 +00:00
|
|
|
// The transform hint is used to improve performance on the main
|
|
|
|
// display -- we can only have a single transform hint, it cannot
|
|
|
|
// apply to all displays.
|
|
|
|
// This is why we use the default display here. This is not an
|
|
|
|
// oversight.
|
2012-08-05 07:40:46 +00:00
|
|
|
sp<const DisplayDevice> hw(mFlinger->getDefaultDisplayDevice());
|
|
|
|
const Transform& planeTransform(hw->getTransform());
|
2012-06-29 21:12:52 +00:00
|
|
|
orientation = planeTransform.getOrientation();
|
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
|