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>
|
2013-03-06 01:47:11 +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>
|
2014-03-03 23:42:54 +00:00
|
|
|
#include <utils/NativeHandle.h>
|
2009-03-04 03:31:44 +00:00
|
|
|
#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"
|
2013-04-22 15:52:16 +00:00
|
|
|
#include "Colorizer.h"
|
2012-08-01 06:09:07 +00:00
|
|
|
#include "DisplayDevice.h"
|
2009-03-04 03:31:44 +00:00
|
|
|
#include "Layer.h"
|
2014-03-13 18:55:57 +00:00
|
|
|
#include "MonitoredProducer.h"
|
2009-03-04 03:31:44 +00:00
|
|
|
#include "SurfaceFlinger.h"
|
|
|
|
|
2012-06-21 00:51:20 +00:00
|
|
|
#include "DisplayHardware/HWComposer.h"
|
|
|
|
|
2013-06-07 22:35:48 +00:00
|
|
|
#include "RenderEngine/RenderEngine.h"
|
|
|
|
|
2009-03-04 03:31:44 +00:00
|
|
|
#define DEBUG_RESIZE 0
|
|
|
|
|
|
|
|
namespace android {
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2013-03-06 01:47:11 +00:00
|
|
|
int32_t Layer::sSequence = 1;
|
|
|
|
|
2013-03-13 00:11:48 +00:00
|
|
|
Layer::Layer(SurfaceFlinger* flinger, const sp<Client>& client,
|
|
|
|
const String8& name, uint32_t w, uint32_t h, uint32_t flags)
|
2013-03-06 01:47:11 +00:00
|
|
|
: contentDirty(false),
|
|
|
|
sequence(uint32_t(android_atomic_inc(&sSequence))),
|
|
|
|
mFlinger(flinger),
|
2011-04-20 21:20:59 +00:00
|
|
|
mTextureName(-1U),
|
2013-03-06 01:47:11 +00:00
|
|
|
mPremultipliedAlpha(true),
|
|
|
|
mName("unnamed"),
|
|
|
|
mDebug(false),
|
|
|
|
mFormat(PIXEL_FORMAT_NONE),
|
|
|
|
mTransactionFlags(0),
|
2011-04-20 21:20:59 +00:00
|
|
|
mQueuedFrames(0),
|
2014-03-03 23:42:54 +00:00
|
|
|
mSidebandStreamChanged(false),
|
2011-04-20 21:20:59 +00:00
|
|
|
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),
|
2013-03-06 01:47:11 +00:00
|
|
|
mFiltering(false),
|
|
|
|
mNeedsFiltering(false),
|
2013-08-14 03:51:23 +00:00
|
|
|
mMesh(Mesh::TRIANGLE_FAN, 4, 2, 2),
|
2010-06-01 22:12:58 +00:00
|
|
|
mSecure(false),
|
2013-03-06 01:47:11 +00:00
|
|
|
mProtectedByApp(false),
|
|
|
|
mHasSurface(false),
|
2014-07-01 21:22:59 +00:00
|
|
|
mClientRef(client),
|
|
|
|
mPotentialCursor(false)
|
2009-04-22 22:23:34 +00:00
|
|
|
{
|
2011-04-20 21:20:59 +00:00
|
|
|
mCurrentCrop.makeInvalid();
|
2013-08-08 04:24:32 +00:00
|
|
|
mFlinger->getRenderEngine().genTextures(1, &mTextureName);
|
2013-08-15 01:20:17 +00:00
|
|
|
mTexture.init(Texture::TEXTURE_EXTERNAL, mTextureName);
|
2013-03-13 00:11:48 +00:00
|
|
|
|
|
|
|
uint32_t layerFlags = 0;
|
|
|
|
if (flags & ISurfaceComposerClient::eHidden)
|
2014-01-30 01:17:11 +00:00
|
|
|
layerFlags |= layer_state_t::eLayerHidden;
|
|
|
|
if (flags & ISurfaceComposerClient::eOpaque)
|
|
|
|
layerFlags |= layer_state_t::eLayerOpaque;
|
2013-03-13 00:11:48 +00:00
|
|
|
|
|
|
|
if (flags & ISurfaceComposerClient::eNonPremultiplied)
|
|
|
|
mPremultipliedAlpha = false;
|
|
|
|
|
|
|
|
mName = name;
|
|
|
|
|
|
|
|
mCurrentState.active.w = w;
|
|
|
|
mCurrentState.active.h = h;
|
|
|
|
mCurrentState.active.crop.makeInvalid();
|
|
|
|
mCurrentState.z = 0;
|
|
|
|
mCurrentState.alpha = 0xFF;
|
|
|
|
mCurrentState.layerStack = 0;
|
|
|
|
mCurrentState.flags = layerFlags;
|
|
|
|
mCurrentState.sequence = 0;
|
|
|
|
mCurrentState.transform.set(0, 0);
|
|
|
|
mCurrentState.requested = mCurrentState.active;
|
|
|
|
|
|
|
|
// drawing state & current state are identical
|
|
|
|
mDrawingState = mCurrentState;
|
2013-07-17 03:12:42 +00:00
|
|
|
|
|
|
|
nsecs_t displayPeriod =
|
|
|
|
flinger->getHwComposer().getRefreshPeriod(HWC_DISPLAY_PRIMARY);
|
|
|
|
mFrameTracker.setDisplayRefreshPeriod(displayPeriod);
|
2012-01-16 02:54:57 +00:00
|
|
|
}
|
|
|
|
|
2013-08-08 04:24:32 +00:00
|
|
|
void Layer::onFirstRef() {
|
2012-12-05 00:51:15 +00:00
|
|
|
// Creates a custom BufferQueue for SurfaceFlingerConsumer to use
|
2014-04-07 23:33:59 +00:00
|
|
|
sp<IGraphicBufferProducer> producer;
|
|
|
|
sp<IGraphicBufferConsumer> consumer;
|
2014-03-13 18:55:57 +00:00
|
|
|
BufferQueue::createBufferQueue(&producer, &consumer);
|
|
|
|
mProducer = new MonitoredProducer(producer, mFlinger);
|
|
|
|
mSurfaceFlingerConsumer = new SurfaceFlingerConsumer(consumer, mTextureName);
|
2012-12-05 00:51:15 +00:00
|
|
|
mSurfaceFlingerConsumer->setConsumerUsageBits(getEffectiveUsage(0));
|
2014-03-03 23:42:54 +00:00
|
|
|
mSurfaceFlingerConsumer->setContentsChangedListener(this);
|
2013-03-13 00:11:48 +00:00
|
|
|
mSurfaceFlingerConsumer->setName(mName);
|
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"
|
2012-12-05 00:51:15 +00:00
|
|
|
mSurfaceFlingerConsumer->setDefaultMaxBufferCount(2);
|
2012-04-24 03:00:16 +00:00
|
|
|
#else
|
2012-12-05 00:51:15 +00:00
|
|
|
mSurfaceFlingerConsumer->setDefaultMaxBufferCount(3);
|
2012-02-05 09:49:16 +00:00
|
|
|
#endif
|
2012-09-14 23:10:11 +00:00
|
|
|
|
2012-11-22 00:02:13 +00:00
|
|
|
const sp<const DisplayDevice> hw(mFlinger->getDefaultDisplayDevice());
|
|
|
|
updateTransformHint(hw);
|
2010-06-01 22:12:58 +00:00
|
|
|
}
|
2010-06-03 06:28:45 +00:00
|
|
|
|
2013-03-13 00:11:48 +00:00
|
|
|
Layer::~Layer() {
|
2013-03-06 01:47:11 +00:00
|
|
|
sp<Client> c(mClientRef.promote());
|
|
|
|
if (c != 0) {
|
|
|
|
c->detachLayer(this);
|
|
|
|
}
|
2012-07-24 06:11:29 +00:00
|
|
|
mFlinger->deleteTextureAsync(mTextureName);
|
2013-07-17 03:12:42 +00:00
|
|
|
mFrameTracker.logAndResetStats(mName);
|
2010-06-03 06:28:45 +00:00
|
|
|
}
|
|
|
|
|
2013-03-06 01:47:11 +00:00
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
// callbacks
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2014-02-14 23:03:43 +00:00
|
|
|
void Layer::onLayerDisplayed(const sp<const DisplayDevice>& /* hw */,
|
2013-03-06 01:47:11 +00:00
|
|
|
HWComposer::HWCLayerInterface* layer) {
|
|
|
|
if (layer) {
|
|
|
|
layer->onDisplayed();
|
2013-03-20 18:37:21 +00:00
|
|
|
mSurfaceFlingerConsumer->setReleaseFence(layer->getAndResetReleaseFence());
|
2013-03-06 01:47:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-29 20:36:11 +00:00
|
|
|
void Layer::onFrameAvailable() {
|
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
|
|
|
}
|
|
|
|
|
2014-03-03 23:42:54 +00:00
|
|
|
void Layer::onSidebandStreamChanged() {
|
|
|
|
if (android_atomic_release_cas(false, true, &mSidebandStreamChanged) == 0) {
|
|
|
|
// mSidebandStreamChanged was false
|
|
|
|
mFlinger->signalLayerUpdate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-15 02:18:13 +00:00
|
|
|
// called with SurfaceFlinger::mStateLock from the drawing thread after
|
|
|
|
// the layer has been remove from the current state list (and just before
|
|
|
|
// it's removed from the drawing state list)
|
2013-03-06 01:47:11 +00:00
|
|
|
void Layer::onRemoved() {
|
2012-12-05 00:51:15 +00:00
|
|
|
mSurfaceFlingerConsumer->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
|
|
|
|
2013-03-06 01:47:11 +00:00
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
// set-up
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2013-06-05 23:59:15 +00:00
|
|
|
const String8& Layer::getName() const {
|
2013-03-06 01:47:11 +00:00
|
|
|
return mName;
|
|
|
|
}
|
|
|
|
|
|
|
|
status_t Layer::setBuffers( uint32_t w, uint32_t h,
|
|
|
|
PixelFormat format, uint32_t flags)
|
2009-03-04 03:31:44 +00:00
|
|
|
{
|
2013-03-06 01:47:11 +00:00
|
|
|
uint32_t const maxSurfaceDims = min(
|
|
|
|
mFlinger->getMaxTextureSize(), mFlinger->getMaxViewportDims());
|
|
|
|
|
|
|
|
// never allow a surface larger than what our underlying GL implementation
|
|
|
|
// can handle.
|
|
|
|
if ((uint32_t(w)>maxSurfaceDims) || (uint32_t(h)>maxSurfaceDims)) {
|
|
|
|
ALOGE("dimensions too large %u x %u", uint32_t(w), uint32_t(h));
|
|
|
|
return BAD_VALUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
mFormat = format;
|
|
|
|
|
2014-07-01 21:22:59 +00:00
|
|
|
mPotentialCursor = (flags & ISurfaceComposerClient::eCursorWindow) ? true : false;
|
2013-03-06 01:47:11 +00:00
|
|
|
mSecure = (flags & ISurfaceComposerClient::eSecure) ? true : false;
|
|
|
|
mProtectedByApp = (flags & ISurfaceComposerClient::eProtectedByApp) ? true : false;
|
|
|
|
mCurrentOpacity = getOpacityForFormat(format);
|
|
|
|
|
|
|
|
mSurfaceFlingerConsumer->setDefaultBufferSize(w, h);
|
|
|
|
mSurfaceFlingerConsumer->setDefaultBufferFormat(format);
|
|
|
|
mSurfaceFlingerConsumer->setConsumerUsageBits(getEffectiveUsage(0));
|
|
|
|
|
|
|
|
return NO_ERROR;
|
|
|
|
}
|
|
|
|
|
2013-03-13 00:11:48 +00:00
|
|
|
sp<IBinder> Layer::getHandle() {
|
|
|
|
Mutex::Autolock _l(mLock);
|
|
|
|
|
|
|
|
LOG_ALWAYS_FATAL_IF(mHasSurface,
|
|
|
|
"Layer::getHandle() has already been called");
|
|
|
|
|
|
|
|
mHasSurface = true;
|
|
|
|
|
2013-01-09 00:06:15 +00:00
|
|
|
/*
|
2013-03-13 00:11:48 +00:00
|
|
|
* The layer handle is just a BBinder object passed to the client
|
|
|
|
* (remote process) -- we don't keep any reference on our side such that
|
|
|
|
* the dtor is called when the remote side let go of its reference.
|
2013-01-09 00:06:15 +00:00
|
|
|
*
|
2013-03-13 00:11:48 +00:00
|
|
|
* LayerCleaner ensures that mFlinger->onLayerDestroyed() is called for
|
|
|
|
* this layer when the handle is destroyed.
|
2013-01-09 00:06:15 +00:00
|
|
|
*/
|
2013-03-13 00:11:48 +00:00
|
|
|
|
|
|
|
class Handle : public BBinder, public LayerCleaner {
|
2011-04-20 21:20:59 +00:00
|
|
|
wp<const Layer> mOwner;
|
|
|
|
public:
|
2013-03-13 00:11:48 +00:00
|
|
|
Handle(const sp<SurfaceFlinger>& flinger, const sp<Layer>& layer)
|
|
|
|
: LayerCleaner(flinger, layer), mOwner(layer) {
|
|
|
|
}
|
2011-04-20 21:20:59 +00:00
|
|
|
};
|
2009-03-04 03:31:44 +00:00
|
|
|
|
2013-03-13 00:11:48 +00:00
|
|
|
return new Handle(mFlinger, this);
|
2011-08-18 01:19:00 +00:00
|
|
|
}
|
|
|
|
|
2014-03-13 18:55:57 +00:00
|
|
|
sp<IGraphicBufferProducer> Layer::getProducer() const {
|
|
|
|
return mProducer;
|
2009-03-04 03:31:44 +00:00
|
|
|
}
|
|
|
|
|
2013-03-06 01:47:11 +00:00
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
// h/w composer set-up
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2013-02-28 06:03:19 +00:00
|
|
|
Rect Layer::getContentCrop() const {
|
|
|
|
// this is the crop rectangle that applies to the buffer
|
|
|
|
// itself (as opposed to the window)
|
2012-05-11 03:43:55 +00:00
|
|
|
Rect crop;
|
|
|
|
if (!mCurrentCrop.isEmpty()) {
|
2013-02-28 06:03:19 +00:00
|
|
|
// if the buffer crop is defined, we use that
|
2012-05-11 03:43:55 +00:00
|
|
|
crop = mCurrentCrop;
|
2013-02-28 06:03:19 +00:00
|
|
|
} else if (mActiveBuffer != NULL) {
|
|
|
|
// otherwise we use the whole buffer
|
|
|
|
crop = mActiveBuffer->getBounds();
|
2012-05-11 03:43:55 +00:00
|
|
|
} else {
|
2013-02-28 06:03:19 +00:00
|
|
|
// if we don't have a buffer yet, we use an empty/invalid crop
|
2012-06-29 21:12:52 +00:00
|
|
|
crop.makeInvalid();
|
2012-05-11 03:43:55 +00:00
|
|
|
}
|
|
|
|
return crop;
|
|
|
|
}
|
|
|
|
|
2013-05-11 01:01:12 +00:00
|
|
|
static Rect reduce(const Rect& win, const Region& exclude) {
|
|
|
|
if (CC_LIKELY(exclude.isEmpty())) {
|
|
|
|
return win;
|
|
|
|
}
|
|
|
|
if (exclude.isRect()) {
|
|
|
|
return win.reduce(exclude.getBounds());
|
|
|
|
}
|
|
|
|
return Region(win).subtract(exclude).getBounds();
|
|
|
|
}
|
|
|
|
|
2013-03-06 01:47:11 +00:00
|
|
|
Rect Layer::computeBounds() const {
|
2013-06-05 23:59:15 +00:00
|
|
|
const Layer::State& s(getDrawingState());
|
2013-03-06 01:47:11 +00:00
|
|
|
Rect win(s.active.w, s.active.h);
|
|
|
|
if (!s.active.crop.isEmpty()) {
|
|
|
|
win.intersect(s.active.crop, &win);
|
|
|
|
}
|
2013-05-10 03:37:10 +00:00
|
|
|
// subtract the transparent region and snap to the bounds
|
2013-05-11 01:01:12 +00:00
|
|
|
return reduce(win, s.activeTransparentRegion);
|
2013-03-06 01:47:11 +00:00
|
|
|
}
|
|
|
|
|
2013-07-10 04:24:52 +00:00
|
|
|
FloatRect Layer::computeCrop(const sp<const DisplayDevice>& hw) const {
|
2013-03-06 01:47:11 +00:00
|
|
|
// the content crop is the area of the content that gets scaled to the
|
|
|
|
// layer's size.
|
2013-07-10 04:24:52 +00:00
|
|
|
FloatRect crop(getContentCrop());
|
2013-03-06 01:47:11 +00:00
|
|
|
|
|
|
|
// the active.crop is the area of the window that gets cropped, but not
|
|
|
|
// scaled in any ways.
|
2013-06-05 23:59:15 +00:00
|
|
|
const State& s(getDrawingState());
|
2013-03-06 01:47:11 +00:00
|
|
|
|
|
|
|
// apply the projection's clipping to the window crop in
|
|
|
|
// layerstack space, and convert-back to layer space.
|
2013-07-10 04:24:52 +00:00
|
|
|
// if there are no window scaling involved, this operation will map to full
|
|
|
|
// pixels in the buffer.
|
|
|
|
// FIXME: the 3 lines below can produce slightly incorrect clipping when we have
|
|
|
|
// a viewport clipping and a window transform. we should use floating point to fix this.
|
2013-08-21 04:41:07 +00:00
|
|
|
|
|
|
|
Rect activeCrop(s.active.w, s.active.h);
|
|
|
|
if (!s.active.crop.isEmpty()) {
|
|
|
|
activeCrop = s.active.crop;
|
|
|
|
}
|
|
|
|
|
|
|
|
activeCrop = s.transform.transform(activeCrop);
|
2013-03-06 01:47:11 +00:00
|
|
|
activeCrop.intersect(hw->getViewport(), &activeCrop);
|
|
|
|
activeCrop = s.transform.inverse().transform(activeCrop);
|
|
|
|
|
|
|
|
// paranoia: make sure the window-crop is constrained in the
|
|
|
|
// window's bounds
|
|
|
|
activeCrop.intersect(Rect(s.active.w, s.active.h), &activeCrop);
|
|
|
|
|
2013-05-11 01:01:12 +00:00
|
|
|
// subtract the transparent region and snap to the bounds
|
|
|
|
activeCrop = reduce(activeCrop, s.activeTransparentRegion);
|
|
|
|
|
2013-03-06 01:47:11 +00:00
|
|
|
if (!activeCrop.isEmpty()) {
|
|
|
|
// Transform the window crop to match the buffer coordinate system,
|
|
|
|
// which means using the inverse of the current transform set on the
|
|
|
|
// SurfaceFlingerConsumer.
|
2013-07-10 04:24:52 +00:00
|
|
|
uint32_t invTransform = mCurrentTransform;
|
2013-03-06 01:47:11 +00:00
|
|
|
int winWidth = s.active.w;
|
|
|
|
int winHeight = s.active.h;
|
|
|
|
if (invTransform & NATIVE_WINDOW_TRANSFORM_ROT_90) {
|
|
|
|
invTransform ^= NATIVE_WINDOW_TRANSFORM_FLIP_V |
|
|
|
|
NATIVE_WINDOW_TRANSFORM_FLIP_H;
|
|
|
|
winWidth = s.active.h;
|
|
|
|
winHeight = s.active.w;
|
|
|
|
}
|
|
|
|
const Rect winCrop = activeCrop.transform(
|
2014-08-07 20:40:48 +00:00
|
|
|
invTransform, winWidth, winHeight);
|
2013-03-06 01:47:11 +00:00
|
|
|
|
2013-07-10 04:24:52 +00:00
|
|
|
// below, crop is intersected with winCrop expressed in crop's coordinate space
|
|
|
|
float xScale = crop.getWidth() / float(winWidth);
|
|
|
|
float yScale = crop.getHeight() / float(winHeight);
|
2013-03-06 01:47:11 +00:00
|
|
|
|
2014-08-07 20:40:48 +00:00
|
|
|
float insetL = winCrop.left * xScale;
|
|
|
|
float insetT = winCrop.top * yScale;
|
|
|
|
float insetR = (s.active.w - winCrop.right ) * xScale;
|
|
|
|
float insetB = (s.active.h - winCrop.bottom) * yScale;
|
2013-03-06 01:47:11 +00:00
|
|
|
|
|
|
|
crop.left += insetL;
|
|
|
|
crop.top += insetT;
|
|
|
|
crop.right -= insetR;
|
|
|
|
crop.bottom -= insetB;
|
|
|
|
}
|
|
|
|
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
|
|
|
{
|
2013-03-06 01:47:11 +00:00
|
|
|
layer.setDefaultState();
|
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
|
|
|
|
2012-10-20 01:19:11 +00:00
|
|
|
if (isSecure() && !hw->isSecure()) {
|
|
|
|
layer.setSkip(true);
|
|
|
|
}
|
|
|
|
|
2013-03-06 01:47:11 +00:00
|
|
|
// this gives us only the "orientation" component of the transform
|
2013-06-05 23:59:15 +00:00
|
|
|
const State& s(getDrawingState());
|
2014-01-30 01:17:11 +00:00
|
|
|
if (!isOpaque(s) || s.alpha != 0xFF) {
|
2013-03-06 01:47:11 +00:00
|
|
|
layer.setBlending(mPremultipliedAlpha ?
|
|
|
|
HWC_BLENDING_PREMULT :
|
|
|
|
HWC_BLENDING_COVERAGE);
|
|
|
|
}
|
|
|
|
|
|
|
|
// apply the layer's transform, followed by the display's global transform
|
|
|
|
// here we're guaranteed that the layer's transform preserves rects
|
|
|
|
Rect frame(s.transform.transform(computeBounds()));
|
|
|
|
frame.intersect(hw->getViewport(), &frame);
|
|
|
|
const Transform& tr(hw->getTransform());
|
|
|
|
layer.setFrame(tr.transform(frame));
|
|
|
|
layer.setCrop(computeCrop(hw));
|
2013-01-30 02:56:42 +00:00
|
|
|
layer.setPlaneAlpha(s.alpha);
|
|
|
|
|
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);
|
2013-09-18 06:45:22 +00:00
|
|
|
Transform transform(tr * s.transform * bufferOrientation);
|
|
|
|
|
|
|
|
if (mSurfaceFlingerConsumer->getTransformToDisplayInverse()) {
|
|
|
|
/*
|
|
|
|
* the code below applies the display's inverse transform to the buffer
|
|
|
|
*/
|
|
|
|
uint32_t invTransform = hw->getOrientationTransform();
|
|
|
|
// calculate the inverse transform
|
|
|
|
if (invTransform & NATIVE_WINDOW_TRANSFORM_ROT_90) {
|
|
|
|
invTransform ^= NATIVE_WINDOW_TRANSFORM_FLIP_V |
|
|
|
|
NATIVE_WINDOW_TRANSFORM_FLIP_H;
|
|
|
|
}
|
|
|
|
// and apply to the current transform
|
|
|
|
transform = transform * Transform(invTransform);
|
|
|
|
}
|
2011-07-12 21:51:45 +00:00
|
|
|
|
|
|
|
// this gives us only the "orientation" component of the transform
|
2013-03-06 01:47:11 +00:00
|
|
|
const uint32_t orientation = transform.getOrientation();
|
|
|
|
if (orientation & Transform::ROT_INVALID) {
|
|
|
|
// we can only handle simple transformation
|
2012-05-14 03:42:01 +00:00
|
|
|
layer.setSkip(true);
|
2011-08-02 22:51:37 +00:00
|
|
|
} else {
|
2013-03-06 01:47:11 +00:00
|
|
|
layer.setTransform(orientation);
|
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) {
|
2013-03-06 01:47:11 +00:00
|
|
|
// we have to set the visible region on every frame because
|
|
|
|
// we currently free it during onLayerDisplayed(), which is called
|
|
|
|
// after HWComposer::commit() -- every frame.
|
|
|
|
// Apply this display's projection's viewport to the visible region
|
|
|
|
// before giving it to the HWC HAL.
|
|
|
|
const Transform& tr = hw->getTransform();
|
|
|
|
Region visible = tr.transform(visibleRegion.intersect(hw->getViewport()));
|
|
|
|
layer.setVisibleRegionScreen(visible);
|
|
|
|
|
2014-03-03 23:42:54 +00:00
|
|
|
if (mSidebandStream.get()) {
|
|
|
|
layer.setSidebandStream(mSidebandStream);
|
|
|
|
} else {
|
|
|
|
// NOTE: buffer can be NULL if the client never drew into this
|
|
|
|
// layer yet, or if we ran out of memory
|
|
|
|
layer.setBuffer(mActiveBuffer);
|
|
|
|
}
|
2012-07-02 23:49:28 +00:00
|
|
|
}
|
2012-06-29 22:21:18 +00:00
|
|
|
|
2014-02-14 23:03:43 +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.
|
|
|
|
|
2014-07-01 21:22:59 +00:00
|
|
|
if (layer.getCompositionType() == HWC_OVERLAY || layer.getCompositionType() == HWC_CURSOR_OVERLAY) {
|
2012-12-05 00:51:15 +00:00
|
|
|
sp<Fence> fence = mSurfaceFlingerConsumer->getCurrentFence();
|
2012-12-20 22:05:45 +00:00
|
|
|
if (fence->isValid()) {
|
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
|
|
|
}
|
|
|
|
|
2014-07-01 21:22:59 +00:00
|
|
|
Rect Layer::getPosition(
|
|
|
|
const sp<const DisplayDevice>& hw)
|
|
|
|
{
|
|
|
|
// this gives us only the "orientation" component of the transform
|
|
|
|
const State& s(getCurrentState());
|
|
|
|
|
|
|
|
// apply the layer's transform, followed by the display's global transform
|
|
|
|
// here we're guaranteed that the layer's transform preserves rects
|
|
|
|
Rect win(s.active.w, s.active.h);
|
|
|
|
if (!s.active.crop.isEmpty()) {
|
|
|
|
win.intersect(s.active.crop, &win);
|
|
|
|
}
|
|
|
|
// subtract the transparent region and snap to the bounds
|
|
|
|
Rect bounds = reduce(win, s.activeTransparentRegion);
|
|
|
|
Rect frame(s.transform.transform(bounds));
|
|
|
|
frame.intersect(hw->getViewport(), &frame);
|
|
|
|
const Transform& tr(hw->getTransform());
|
|
|
|
return Rect(tr.transform(frame));
|
|
|
|
}
|
|
|
|
|
2013-03-06 01:47:11 +00:00
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
// drawing...
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void Layer::draw(const sp<const DisplayDevice>& hw, const Region& clip) const {
|
2014-02-14 23:03:43 +00:00
|
|
|
onDraw(hw, clip, false);
|
2013-03-06 01:47:11 +00:00
|
|
|
}
|
|
|
|
|
2014-02-14 23:03:43 +00:00
|
|
|
void Layer::draw(const sp<const DisplayDevice>& hw,
|
|
|
|
bool useIdentityTransform) const {
|
|
|
|
onDraw(hw, Region(hw->bounds()), useIdentityTransform);
|
2013-03-06 01:47:11 +00:00
|
|
|
}
|
|
|
|
|
2014-02-14 23:03:43 +00:00
|
|
|
void Layer::draw(const sp<const DisplayDevice>& hw) const {
|
|
|
|
onDraw(hw, Region(hw->bounds()), false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Layer::onDraw(const sp<const DisplayDevice>& hw, const Region& clip,
|
|
|
|
bool useIdentityTransform) 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) {
|
2013-03-06 01:47:11 +00:00
|
|
|
const sp<Layer>& layer(drawingLayers[i]);
|
|
|
|
if (layer.get() == static_cast<Layer const*>(this))
|
2010-05-07 03:21:45 +00:00
|
|
|
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-12-11 23:21:45 +00:00
|
|
|
// Bind the current buffer to the GL texture, and wait for it to be
|
|
|
|
// ready for us to draw into.
|
2012-12-05 00:51:15 +00:00
|
|
|
status_t err = mSurfaceFlingerConsumer->bindTextureImage();
|
|
|
|
if (err != NO_ERROR) {
|
2012-12-11 23:21:45 +00:00
|
|
|
ALOGW("onDraw: bindTextureImage failed (err=%d)", err);
|
2012-06-29 22:21:18 +00:00
|
|
|
// Go ahead and draw the buffer anyway; no matter what we do the screen
|
|
|
|
// is probably going to have something visibly wrong.
|
|
|
|
}
|
|
|
|
|
2012-10-20 01:19:11 +00:00
|
|
|
bool blackOutLayer = isProtected() || (isSecure() && !hw->isSecure());
|
|
|
|
|
2013-06-07 22:35:48 +00:00
|
|
|
RenderEngine& engine(mFlinger->getRenderEngine());
|
|
|
|
|
2012-10-20 01:19:11 +00:00
|
|
|
if (!blackOutLayer) {
|
2012-05-09 00:05:52 +00:00
|
|
|
// TODO: we could be more subtle with isFixedSize()
|
2012-09-20 06:14:45 +00:00
|
|
|
const bool useFiltering = getFiltering() || needsFiltering(hw) || isFixedSize();
|
2012-05-09 00:05:52 +00:00
|
|
|
|
|
|
|
// Query the texture matrix given our current filtering mode.
|
|
|
|
float textureMatrix[16];
|
2012-12-05 00:51:15 +00:00
|
|
|
mSurfaceFlingerConsumer->setFilteringEnabled(useFiltering);
|
|
|
|
mSurfaceFlingerConsumer->getTransformMatrix(textureMatrix);
|
2012-05-09 00:05:52 +00:00
|
|
|
|
2013-09-18 06:45:22 +00:00
|
|
|
if (mSurfaceFlingerConsumer->getTransformToDisplayInverse()) {
|
|
|
|
|
|
|
|
/*
|
|
|
|
* the code below applies the display's inverse transform to the texture transform
|
|
|
|
*/
|
|
|
|
|
|
|
|
// create a 4x4 transform matrix from the display transform flags
|
|
|
|
const mat4 flipH(-1,0,0,0, 0,1,0,0, 0,0,1,0, 1,0,0,1);
|
|
|
|
const mat4 flipV( 1,0,0,0, 0,-1,0,0, 0,0,1,0, 0,1,0,1);
|
|
|
|
const mat4 rot90( 0,1,0,0, -1,0,0,0, 0,0,1,0, 1,0,0,1);
|
|
|
|
|
|
|
|
mat4 tr;
|
|
|
|
uint32_t transform = hw->getOrientationTransform();
|
|
|
|
if (transform & NATIVE_WINDOW_TRANSFORM_ROT_90)
|
|
|
|
tr = tr * rot90;
|
|
|
|
if (transform & NATIVE_WINDOW_TRANSFORM_FLIP_H)
|
|
|
|
tr = tr * flipH;
|
|
|
|
if (transform & NATIVE_WINDOW_TRANSFORM_FLIP_V)
|
|
|
|
tr = tr * flipV;
|
|
|
|
|
|
|
|
// calculate the inverse
|
|
|
|
tr = inverse(tr);
|
|
|
|
|
|
|
|
// and finally apply it to the original texture matrix
|
|
|
|
const mat4 texTransform(mat4(static_cast<const float*>(textureMatrix)) * tr);
|
|
|
|
memcpy(textureMatrix, texTransform.asArray(), sizeof(textureMatrix));
|
|
|
|
}
|
|
|
|
|
2012-05-09 00:05:52 +00:00
|
|
|
// Set things up for texturing.
|
2013-08-15 01:20:17 +00:00
|
|
|
mTexture.setDimensions(mActiveBuffer->getWidth(), mActiveBuffer->getHeight());
|
|
|
|
mTexture.setFiltering(useFiltering);
|
|
|
|
mTexture.setMatrix(textureMatrix);
|
|
|
|
|
|
|
|
engine.setupLayerTexturing(mTexture);
|
2011-04-20 21:20:59 +00:00
|
|
|
} else {
|
2013-06-07 22:35:48 +00:00
|
|
|
engine.setupLayerBlackedOut();
|
2011-04-20 21:20:59 +00:00
|
|
|
}
|
2014-02-14 23:03:43 +00:00
|
|
|
drawWithOpenGL(hw, clip, useIdentityTransform);
|
2013-06-07 22:35:48 +00:00
|
|
|
engine.disableTexturing();
|
2009-03-04 03:31:44 +00:00
|
|
|
}
|
|
|
|
|
2013-03-06 01:47:11 +00:00
|
|
|
|
2014-02-14 23:03:43 +00:00
|
|
|
void Layer::clearWithOpenGL(const sp<const DisplayDevice>& hw,
|
|
|
|
const Region& /* clip */, float red, float green, float blue,
|
|
|
|
float alpha) const
|
2013-03-06 01:47:11 +00:00
|
|
|
{
|
2013-08-29 01:13:56 +00:00
|
|
|
RenderEngine& engine(mFlinger->getRenderEngine());
|
2014-02-14 23:03:43 +00:00
|
|
|
computeGeometry(hw, mMesh, false);
|
2013-08-29 01:13:56 +00:00
|
|
|
engine.setupFillWithColor(red, green, blue, alpha);
|
|
|
|
engine.drawMesh(mMesh);
|
2013-03-06 01:47:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Layer::clearWithOpenGL(
|
|
|
|
const sp<const DisplayDevice>& hw, const Region& clip) const {
|
|
|
|
clearWithOpenGL(hw, clip, 0,0,0,0);
|
|
|
|
}
|
|
|
|
|
2014-02-14 23:03:43 +00:00
|
|
|
void Layer::drawWithOpenGL(const sp<const DisplayDevice>& hw,
|
|
|
|
const Region& /* clip */, bool useIdentityTransform) const {
|
2013-03-06 01:47:11 +00:00
|
|
|
const uint32_t fbHeight = hw->getHeight();
|
2013-06-05 23:59:15 +00:00
|
|
|
const State& s(getDrawingState());
|
2013-03-06 01:47:11 +00:00
|
|
|
|
2014-02-14 23:03:43 +00:00
|
|
|
computeGeometry(hw, mMesh, useIdentityTransform);
|
2013-03-06 01:47:11 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* NOTE: the way we compute the texture coordinates here produces
|
|
|
|
* different results than when we take the HWC path -- in the later case
|
|
|
|
* the "source crop" is rounded to texel boundaries.
|
|
|
|
* This can produce significantly different results when the texture
|
|
|
|
* is scaled by a large amount.
|
|
|
|
*
|
|
|
|
* The GL code below is more logical (imho), and the difference with
|
|
|
|
* HWC is due to a limitation of the HWC API to integers -- a question
|
2013-09-18 06:45:22 +00:00
|
|
|
* is suspend is whether we should ignore this problem or revert to
|
2013-03-06 01:47:11 +00:00
|
|
|
* GL composition when a buffer scaling is applied (maybe with some
|
|
|
|
* minimal value)? Or, we could make GL behave like HWC -- but this feel
|
|
|
|
* like more of a hack.
|
|
|
|
*/
|
|
|
|
const Rect win(computeBounds());
|
|
|
|
|
2013-08-08 04:24:32 +00:00
|
|
|
float left = float(win.left) / float(s.active.w);
|
|
|
|
float top = float(win.top) / float(s.active.h);
|
|
|
|
float right = float(win.right) / float(s.active.w);
|
|
|
|
float bottom = float(win.bottom) / float(s.active.h);
|
2013-03-06 01:47:11 +00:00
|
|
|
|
2013-06-07 22:35:48 +00:00
|
|
|
// TODO: we probably want to generate the texture coords with the mesh
|
|
|
|
// here we assume that we only have 4 vertices
|
2013-09-02 04:36:12 +00:00
|
|
|
Mesh::VertexArray<vec2> texCoords(mMesh.getTexCoordArray<vec2>());
|
|
|
|
texCoords[0] = vec2(left, 1.0f - top);
|
|
|
|
texCoords[1] = vec2(left, 1.0f - bottom);
|
|
|
|
texCoords[2] = vec2(right, 1.0f - bottom);
|
|
|
|
texCoords[3] = vec2(right, 1.0f - top);
|
2013-03-06 01:47:11 +00:00
|
|
|
|
2013-06-07 22:35:48 +00:00
|
|
|
RenderEngine& engine(mFlinger->getRenderEngine());
|
2014-01-30 01:17:11 +00:00
|
|
|
engine.setupLayerBlending(mPremultipliedAlpha, isOpaque(s), s.alpha);
|
2013-08-14 03:51:23 +00:00
|
|
|
engine.drawMesh(mMesh);
|
2013-06-07 22:35:48 +00:00
|
|
|
engine.disableBlending();
|
2013-03-06 01:47:11 +00:00
|
|
|
}
|
|
|
|
|
2014-06-27 22:51:55 +00:00
|
|
|
uint32_t Layer::getProducerStickyTransform() const {
|
|
|
|
int producerStickyTransform = 0;
|
|
|
|
int ret = mProducer->query(NATIVE_WINDOW_STICKY_TRANSFORM, &producerStickyTransform);
|
|
|
|
if (ret != OK) {
|
|
|
|
ALOGW("%s: Error %s (%d) while querying window sticky transform.", __FUNCTION__,
|
|
|
|
strerror(-ret), ret);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return static_cast<uint32_t>(producerStickyTransform);
|
|
|
|
}
|
|
|
|
|
2013-03-06 01:47:11 +00:00
|
|
|
void Layer::setFiltering(bool filtering) {
|
|
|
|
mFiltering = filtering;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Layer::getFiltering() const {
|
|
|
|
return mFiltering;
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
|
2013-07-26 02:24:31 +00:00
|
|
|
bool Layer::getOpacityForFormat(uint32_t format) {
|
2011-04-20 21:20:59 +00:00
|
|
|
if (HARDWARE_IS_DEVICE_FORMAT(format)) {
|
|
|
|
return true;
|
2011-02-10 22:41:26 +00:00
|
|
|
}
|
2013-07-26 02:24:31 +00:00
|
|
|
switch (format) {
|
|
|
|
case HAL_PIXEL_FORMAT_RGBA_8888:
|
|
|
|
case HAL_PIXEL_FORMAT_BGRA_8888:
|
2013-08-08 20:40:22 +00:00
|
|
|
case HAL_PIXEL_FORMAT_sRGB_A_8888:
|
2013-07-26 22:31:39 +00:00
|
|
|
return false;
|
2013-07-26 02:24:31 +00:00
|
|
|
}
|
|
|
|
// in all other case, we have no blending (also for unknown formats)
|
2013-07-26 22:31:39 +00:00
|
|
|
return true;
|
2011-02-10 22:41:26 +00:00
|
|
|
}
|
|
|
|
|
2013-03-06 01:47:11 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// local state
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2014-02-14 23:03:43 +00:00
|
|
|
void Layer::computeGeometry(const sp<const DisplayDevice>& hw, Mesh& mesh,
|
|
|
|
bool useIdentityTransform) const
|
2013-03-06 01:47:11 +00:00
|
|
|
{
|
2013-06-05 23:59:15 +00:00
|
|
|
const Layer::State& s(getDrawingState());
|
2014-02-14 23:03:43 +00:00
|
|
|
const Transform tr(useIdentityTransform ?
|
|
|
|
hw->getTransform() : hw->getTransform() * s.transform);
|
2013-03-06 01:47:11 +00:00
|
|
|
const uint32_t hw_h = hw->getHeight();
|
|
|
|
Rect win(s.active.w, s.active.h);
|
|
|
|
if (!s.active.crop.isEmpty()) {
|
|
|
|
win.intersect(s.active.crop, &win);
|
|
|
|
}
|
2013-05-10 03:37:10 +00:00
|
|
|
// subtract the transparent region and snap to the bounds
|
2013-05-11 01:01:12 +00:00
|
|
|
win = reduce(win, s.activeTransparentRegion);
|
2013-08-08 04:24:32 +00:00
|
|
|
|
2013-09-02 04:36:12 +00:00
|
|
|
Mesh::VertexArray<vec2> position(mesh.getPositionArray<vec2>());
|
|
|
|
position[0] = tr.transform(win.left, win.top);
|
|
|
|
position[1] = tr.transform(win.left, win.bottom);
|
|
|
|
position[2] = tr.transform(win.right, win.bottom);
|
|
|
|
position[3] = tr.transform(win.right, win.top);
|
2013-08-08 04:24:32 +00:00
|
|
|
for (size_t i=0 ; i<4 ; i++) {
|
2013-08-14 03:51:23 +00:00
|
|
|
position[i].y = hw_h - position[i].y;
|
2013-03-06 01:47:11 +00:00
|
|
|
}
|
|
|
|
}
|
2011-02-10 22:41:26 +00:00
|
|
|
|
2014-01-30 01:17:11 +00:00
|
|
|
bool Layer::isOpaque(const Layer::State& s) 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.
|
2014-01-30 01:17:11 +00:00
|
|
|
return ((s.flags & layer_state_t::eLayerOpaque) != 0) || 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
|
|
|
|
2013-03-06 01:47:11 +00:00
|
|
|
bool Layer::isFixedSize() const {
|
|
|
|
return mCurrentScalingMode != NATIVE_WINDOW_SCALING_MODE_FREEZE;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Layer::isCropped() const {
|
|
|
|
return !mCurrentCrop.isEmpty();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Layer::needsFiltering(const sp<const DisplayDevice>& hw) const {
|
|
|
|
return mNeedsFiltering || hw->needsFiltering();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Layer::setVisibleRegion(const Region& visibleRegion) {
|
|
|
|
// always called from main thread
|
|
|
|
this->visibleRegion = visibleRegion;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Layer::setCoveredRegion(const Region& coveredRegion) {
|
|
|
|
// always called from main thread
|
|
|
|
this->coveredRegion = coveredRegion;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Layer::setVisibleNonTransparentRegion(const Region&
|
|
|
|
setVisibleNonTransparentRegion) {
|
|
|
|
// always called from main thread
|
|
|
|
this->visibleNonTransparentRegion = setVisibleNonTransparentRegion;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// transaction
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
uint32_t Layer::doTransaction(uint32_t flags) {
|
2012-02-24 03:27:23 +00:00
|
|
|
ATRACE_CALL();
|
|
|
|
|
2013-06-05 23:59:15 +00:00
|
|
|
const Layer::State& s(getDrawingState());
|
|
|
|
const Layer::State& c(getCurrentState());
|
2009-03-04 03:31:44 +00:00
|
|
|
|
2013-06-05 23:59:15 +00:00
|
|
|
const bool sizeChanged = (c.requested.w != s.requested.w) ||
|
|
|
|
(c.requested.h != s.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-09-14 23:10:11 +00:00
|
|
|
"doTransaction: geometry (layer=%p '%s'), tr=%02x, scalingMode=%d\n"
|
2012-05-23 21:34:07 +00:00
|
|
|
" 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",
|
2013-06-05 23:59:15 +00:00
|
|
|
this, getName().string(), mCurrentTransform, mCurrentScalingMode,
|
|
|
|
c.active.w, c.active.h,
|
|
|
|
c.active.crop.left,
|
|
|
|
c.active.crop.top,
|
|
|
|
c.active.crop.right,
|
|
|
|
c.active.crop.bottom,
|
|
|
|
c.active.crop.getWidth(),
|
|
|
|
c.active.crop.getHeight(),
|
|
|
|
c.requested.w, c.requested.h,
|
|
|
|
c.requested.crop.left,
|
|
|
|
c.requested.crop.top,
|
|
|
|
c.requested.crop.right,
|
|
|
|
c.requested.crop.bottom,
|
|
|
|
c.requested.crop.getWidth(),
|
|
|
|
c.requested.crop.getHeight(),
|
|
|
|
s.active.w, s.active.h,
|
|
|
|
s.active.crop.left,
|
|
|
|
s.active.crop.top,
|
|
|
|
s.active.crop.right,
|
|
|
|
s.active.crop.bottom,
|
|
|
|
s.active.crop.getWidth(),
|
|
|
|
s.active.crop.getHeight(),
|
|
|
|
s.requested.w, s.requested.h,
|
|
|
|
s.requested.crop.left,
|
|
|
|
s.requested.crop.top,
|
|
|
|
s.requested.crop.right,
|
|
|
|
s.requested.crop.bottom,
|
|
|
|
s.requested.crop.getWidth(),
|
|
|
|
s.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-12-05 00:51:15 +00:00
|
|
|
mSurfaceFlingerConsumer->setDefaultBufferSize(
|
2013-06-05 23:59:15 +00:00
|
|
|
c.requested.w, c.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()) {
|
|
|
|
|
2013-06-05 23:59:15 +00:00
|
|
|
const bool resizePending = (c.requested.w != c.active.w) ||
|
|
|
|
(c.requested.h != c.active.h);
|
2012-06-07 21:18:55 +00:00
|
|
|
|
|
|
|
if (resizePending) {
|
2013-03-06 01:47:11 +00:00
|
|
|
// don't let Layer::doTransaction update the drawing state
|
2012-06-07 21:18:55 +00:00
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-06 01:47:11 +00:00
|
|
|
// always set active to requested, unless we're asked not to
|
|
|
|
// this is used by Layer, which special cases resizes.
|
|
|
|
if (flags & eDontUpdateGeometryState) {
|
|
|
|
} else {
|
2013-06-05 23:59:15 +00:00
|
|
|
Layer::State& editCurrentState(getCurrentState());
|
|
|
|
editCurrentState.active = c.requested;
|
2013-03-06 01:47:11 +00:00
|
|
|
}
|
|
|
|
|
2013-06-05 23:59:15 +00:00
|
|
|
if (s.active != c.active) {
|
2013-03-06 01:47:11 +00:00
|
|
|
// invalidate and recompute the visible regions if needed
|
|
|
|
flags |= Layer::eVisibleRegion;
|
|
|
|
}
|
|
|
|
|
2013-06-05 23:59:15 +00:00
|
|
|
if (c.sequence != s.sequence) {
|
2013-03-06 01:47:11 +00:00
|
|
|
// invalidate and recompute the visible regions if needed
|
|
|
|
flags |= eVisibleRegion;
|
|
|
|
this->contentDirty = true;
|
|
|
|
|
|
|
|
// we may use linear filtering, if the matrix scales us
|
2013-06-05 23:59:15 +00:00
|
|
|
const uint8_t type = c.transform.getType();
|
|
|
|
mNeedsFiltering = (!c.transform.preserveRects() ||
|
2013-03-06 01:47:11 +00:00
|
|
|
(type >= Transform::SCALE));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Commit the transaction
|
|
|
|
commitTransaction();
|
|
|
|
return flags;
|
2009-03-04 03:31:44 +00:00
|
|
|
}
|
|
|
|
|
2013-03-06 01:47:11 +00:00
|
|
|
void Layer::commitTransaction() {
|
|
|
|
mDrawingState = mCurrentState;
|
2011-04-20 21:20:59 +00:00
|
|
|
}
|
|
|
|
|
2013-03-06 01:47:11 +00:00
|
|
|
uint32_t Layer::getTransactionFlags(uint32_t flags) {
|
|
|
|
return android_atomic_and(~flags, &mTransactionFlags) & flags;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t Layer::setTransactionFlags(uint32_t flags) {
|
|
|
|
return android_atomic_or(flags, &mTransactionFlags);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Layer::setPosition(float x, float y) {
|
|
|
|
if (mCurrentState.transform.tx() == x && mCurrentState.transform.ty() == y)
|
|
|
|
return false;
|
|
|
|
mCurrentState.sequence++;
|
|
|
|
mCurrentState.transform.set(x, y);
|
|
|
|
setTransactionFlags(eTransactionNeeded);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
bool Layer::setLayer(uint32_t z) {
|
|
|
|
if (mCurrentState.z == z)
|
|
|
|
return false;
|
|
|
|
mCurrentState.sequence++;
|
|
|
|
mCurrentState.z = z;
|
|
|
|
setTransactionFlags(eTransactionNeeded);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
bool Layer::setSize(uint32_t w, uint32_t h) {
|
|
|
|
if (mCurrentState.requested.w == w && mCurrentState.requested.h == h)
|
|
|
|
return false;
|
|
|
|
mCurrentState.requested.w = w;
|
|
|
|
mCurrentState.requested.h = h;
|
|
|
|
setTransactionFlags(eTransactionNeeded);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
bool Layer::setAlpha(uint8_t alpha) {
|
|
|
|
if (mCurrentState.alpha == alpha)
|
|
|
|
return false;
|
|
|
|
mCurrentState.sequence++;
|
|
|
|
mCurrentState.alpha = alpha;
|
|
|
|
setTransactionFlags(eTransactionNeeded);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
bool Layer::setMatrix(const layer_state_t::matrix22_t& matrix) {
|
|
|
|
mCurrentState.sequence++;
|
|
|
|
mCurrentState.transform.set(
|
|
|
|
matrix.dsdx, matrix.dsdy, matrix.dtdx, matrix.dtdy);
|
|
|
|
setTransactionFlags(eTransactionNeeded);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
bool Layer::setTransparentRegionHint(const Region& transparent) {
|
2013-04-03 01:30:32 +00:00
|
|
|
mCurrentState.requestedTransparentRegion = transparent;
|
2013-03-06 01:47:11 +00:00
|
|
|
setTransactionFlags(eTransactionNeeded);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
bool Layer::setFlags(uint8_t flags, uint8_t mask) {
|
|
|
|
const uint32_t newFlags = (mCurrentState.flags & ~mask) | (flags & mask);
|
|
|
|
if (mCurrentState.flags == newFlags)
|
|
|
|
return false;
|
|
|
|
mCurrentState.sequence++;
|
|
|
|
mCurrentState.flags = newFlags;
|
|
|
|
setTransactionFlags(eTransactionNeeded);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
bool Layer::setCrop(const Rect& crop) {
|
|
|
|
if (mCurrentState.requested.crop == crop)
|
|
|
|
return false;
|
|
|
|
mCurrentState.sequence++;
|
|
|
|
mCurrentState.requested.crop = crop;
|
|
|
|
setTransactionFlags(eTransactionNeeded);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Layer::setLayerStack(uint32_t layerStack) {
|
|
|
|
if (mCurrentState.layerStack == layerStack)
|
|
|
|
return false;
|
|
|
|
mCurrentState.sequence++;
|
|
|
|
mCurrentState.layerStack = layerStack;
|
|
|
|
setTransactionFlags(eTransactionNeeded);
|
|
|
|
return true;
|
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;
|
2014-03-03 23:42:54 +00:00
|
|
|
return mQueuedFrames > 0 || mSidebandStreamChanged;
|
2012-02-01 02:24:27 +00:00
|
|
|
}
|
|
|
|
|
2012-08-02 21:01:42 +00:00
|
|
|
void Layer::onPostComposition() {
|
|
|
|
if (mFrameLatencyNeeded) {
|
2012-12-05 00:51:15 +00:00
|
|
|
nsecs_t desiredPresentTime = mSurfaceFlingerConsumer->getTimestamp();
|
2012-11-09 03:23:28 +00:00
|
|
|
mFrameTracker.setDesiredPresentTime(desiredPresentTime);
|
|
|
|
|
2012-12-05 00:51:15 +00:00
|
|
|
sp<Fence> frameReadyFence = mSurfaceFlingerConsumer->getCurrentFence();
|
2013-02-25 21:37:54 +00:00
|
|
|
if (frameReadyFence->isValid()) {
|
2012-11-09 03:23:28 +00:00
|
|
|
mFrameTracker.setFrameReadyFence(frameReadyFence);
|
|
|
|
} else {
|
|
|
|
// There was no fence for this frame, so assume that it was ready
|
|
|
|
// to be presented at the desired present time.
|
|
|
|
mFrameTracker.setFrameReadyTime(desiredPresentTime);
|
|
|
|
}
|
|
|
|
|
2012-08-02 21:01:42 +00:00
|
|
|
const HWComposer& hwc = mFlinger->getHwComposer();
|
2012-11-09 03:23:28 +00:00
|
|
|
sp<Fence> presentFence = hwc.getDisplayFence(HWC_DISPLAY_PRIMARY);
|
2013-02-25 21:37:54 +00:00
|
|
|
if (presentFence->isValid()) {
|
2012-11-09 03:23:28 +00:00
|
|
|
mFrameTracker.setActualPresentFence(presentFence);
|
|
|
|
} else {
|
|
|
|
// The HWC doesn't support present fences, so use the refresh
|
|
|
|
// timestamp instead.
|
|
|
|
nsecs_t presentTime = hwc.getRefreshTimestamp(HWC_DISPLAY_PRIMARY);
|
|
|
|
mFrameTracker.setActualPresentTime(presentTime);
|
|
|
|
}
|
|
|
|
|
|
|
|
mFrameTracker.advanceFrame();
|
2012-08-02 21:01:42 +00:00
|
|
|
mFrameLatencyNeeded = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-14 01:17:13 +00:00
|
|
|
bool Layer::isVisible() const {
|
2013-03-06 01:47:11 +00:00
|
|
|
const Layer::State& s(mDrawingState);
|
|
|
|
return !(s.flags & layer_state_t::eLayerHidden) && s.alpha
|
2014-03-31 14:16:08 +00:00
|
|
|
&& (mActiveBuffer != NULL || mSidebandStream != NULL);
|
2012-09-14 01:17:13 +00:00
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
|
2014-03-03 23:42:54 +00:00
|
|
|
if (android_atomic_acquire_cas(true, false, &mSidebandStreamChanged) == 0) {
|
|
|
|
// mSidebandStreamChanged was true
|
|
|
|
mSidebandStream = mSurfaceFlingerConsumer->getSidebandStream();
|
|
|
|
}
|
|
|
|
|
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
|
2014-01-30 01:17:11 +00:00
|
|
|
const State& s(getDrawingState());
|
|
|
|
const bool oldOpacity = isOpaque(s);
|
2011-09-15 01:23:37 +00:00
|
|
|
sp<GraphicBuffer> oldActiveBuffer = mActiveBuffer;
|
2011-07-28 21:54:07 +00:00
|
|
|
|
2012-12-05 00:51:15 +00:00
|
|
|
struct Reject : public SurfaceFlingerConsumer::BufferRejecter {
|
2012-05-24 00:56:42 +00:00
|
|
|
Layer::State& front;
|
|
|
|
Layer::State& current;
|
|
|
|
bool& recomputeVisibleRegions;
|
2014-06-27 22:51:55 +00:00
|
|
|
bool stickyTransformSet;
|
2012-05-24 00:56:42 +00:00
|
|
|
Reject(Layer::State& front, Layer::State& current,
|
2014-06-27 22:51:55 +00:00
|
|
|
bool& recomputeVisibleRegions, bool stickySet)
|
2012-05-24 00:56:42 +00:00
|
|
|
: front(front), current(current),
|
2014-06-27 22:51:55 +00:00
|
|
|
recomputeVisibleRegions(recomputeVisibleRegions),
|
|
|
|
stickyTransformSet(stickySet) {
|
2012-05-24 00:56:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool reject(const sp<GraphicBuffer>& buf,
|
2013-08-02 08:40:18 +00:00
|
|
|
const IGraphicBufferConsumer::BufferItem& item) {
|
2012-05-24 00:56:42 +00:00
|
|
|
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,
|
2012-09-14 23:10:11 +00:00
|
|
|
"latchBuffer/reject: buffer (%ux%u, tr=%02x), scalingMode=%d\n"
|
2012-05-24 00:56:42 +00:00
|
|
|
" 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",
|
2012-09-14 23:10:11 +00:00
|
|
|
bufWidth, bufHeight, item.mTransform, item.mScalingMode,
|
2012-05-24 00:56:42 +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,
|
|
|
|
front.requested.crop.left,
|
|
|
|
front.requested.crop.top,
|
|
|
|
front.requested.crop.right,
|
|
|
|
front.requested.crop.bottom,
|
|
|
|
front.requested.crop.getWidth(),
|
|
|
|
front.requested.crop.getHeight());
|
|
|
|
}
|
|
|
|
|
2014-06-27 22:51:55 +00:00
|
|
|
if (!isFixedSize && !stickyTransformSet) {
|
2012-05-24 00:56:42 +00:00
|
|
|
if (front.active.w != bufWidth ||
|
|
|
|
front.active.h != bufHeight) {
|
2012-06-05 01:16:30 +00:00
|
|
|
// reject this buffer
|
2014-06-27 22:51:55 +00:00
|
|
|
ALOGE("rejecting buffer: bufWidth=%d, bufHeight=%d, front.active.{w=%d, h=%d}",
|
|
|
|
bufWidth, bufHeight, front.active.w, front.active.h);
|
2012-05-24 00:56:42 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2013-04-03 01:30:32 +00:00
|
|
|
|
|
|
|
// if the transparent region has changed (this test is
|
|
|
|
// conservative, but that's fine, worst case we're doing
|
|
|
|
// a bit of extra work), we latch the new one and we
|
|
|
|
// trigger a visible-region recompute.
|
|
|
|
if (!front.activeTransparentRegion.isTriviallyEqual(
|
|
|
|
front.requestedTransparentRegion)) {
|
|
|
|
front.activeTransparentRegion = front.requestedTransparentRegion;
|
2013-04-12 23:58:11 +00:00
|
|
|
|
|
|
|
// 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.activeTransparentRegion = front.activeTransparentRegion;
|
|
|
|
|
|
|
|
// recompute visible region
|
2013-04-03 01:30:32 +00:00
|
|
|
recomputeVisibleRegions = true;
|
|
|
|
}
|
|
|
|
|
2012-05-24 00:56:42 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-06-27 22:51:55 +00:00
|
|
|
Reject r(mDrawingState, getCurrentState(), recomputeVisibleRegions,
|
|
|
|
getProducerStickyTransform() != 0);
|
2012-05-24 00:56:42 +00:00
|
|
|
|
2014-04-25 23:58:34 +00:00
|
|
|
status_t updateResult = mSurfaceFlingerConsumer->updateTexImage(&r,
|
|
|
|
mFlinger->mPrimaryDispSync);
|
2013-06-28 20:52:40 +00:00
|
|
|
if (updateResult == BufferQueue::PRESENT_LATER) {
|
|
|
|
// Producer doesn't want buffer to be displayed yet. Signal a
|
|
|
|
// layer update so we check again at the next opportunity.
|
|
|
|
mFlinger->signalLayerUpdate();
|
|
|
|
return outDirtyRegion;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Decrement the queued-frames count. Signal another event if we
|
|
|
|
// have more frames pending.
|
|
|
|
if (android_atomic_dec(&mQueuedFrames) > 1) {
|
|
|
|
mFlinger->signalLayerUpdate();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (updateResult != 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
|
2012-12-05 00:51:15 +00:00
|
|
|
mActiveBuffer = mSurfaceFlingerConsumer->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.
|
2012-09-26 23:19:12 +00:00
|
|
|
recomputeVisibleRegions = true;
|
2012-05-24 00:56:42 +00:00
|
|
|
}
|
2012-05-24 00:50:31 +00:00
|
|
|
|
2012-12-05 00:51:15 +00:00
|
|
|
Rect crop(mSurfaceFlingerConsumer->getCurrentCrop());
|
|
|
|
const uint32_t transform(mSurfaceFlingerConsumer->getCurrentTransform());
|
|
|
|
const uint32_t scalingMode(mSurfaceFlingerConsumer->getCurrentScalingMode());
|
2012-05-24 00:50:31 +00:00
|
|
|
if ((crop != mCurrentCrop) ||
|
|
|
|
(transform != mCurrentTransform) ||
|
|
|
|
(scalingMode != mCurrentScalingMode))
|
|
|
|
{
|
|
|
|
mCurrentCrop = crop;
|
|
|
|
mCurrentTransform = transform;
|
|
|
|
mCurrentScalingMode = scalingMode;
|
2012-09-26 23:19:12 +00:00
|
|
|
recomputeVisibleRegions = true;
|
2012-05-24 00:50:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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)) {
|
2012-09-26 23:19:12 +00:00
|
|
|
recomputeVisibleRegions = true;
|
2012-05-24 00:50:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mCurrentOpacity = getOpacityForFormat(mActiveBuffer->format);
|
2014-01-30 01:17:11 +00:00
|
|
|
if (oldOpacity != isOpaque(s)) {
|
2012-05-24 00:50:31 +00:00
|
|
|
recomputeVisibleRegions = true;
|
|
|
|
}
|
|
|
|
|
2012-06-29 21:12:52 +00:00
|
|
|
// FIXME: postedRegion should be dirty & bounds
|
2013-06-05 23:59:15 +00:00
|
|
|
Region dirtyRegion(Rect(s.active.w, s.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
|
2013-06-05 23:59:15 +00:00
|
|
|
outDirtyRegion = (s.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
|
|
|
}
|
|
|
|
|
2013-03-06 01:47:11 +00:00
|
|
|
uint32_t Layer::getEffectiveUsage(uint32_t usage) const
|
|
|
|
{
|
|
|
|
// 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;
|
|
|
|
}
|
2014-07-01 21:22:59 +00:00
|
|
|
if (mPotentialCursor) {
|
|
|
|
usage |= GraphicBuffer::USAGE_CURSOR;
|
|
|
|
}
|
2013-03-06 01:47:11 +00:00
|
|
|
usage |= GraphicBuffer::USAGE_HW_COMPOSER;
|
|
|
|
return usage;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Layer::updateTransformHint(const sp<const DisplayDevice>& hw) const {
|
|
|
|
uint32_t orientation = 0;
|
|
|
|
if (!mFlinger->mDebugDisableTransformHint) {
|
|
|
|
// The transform hint is used to improve performance, but we can
|
|
|
|
// only have a single transform hint, it cannot
|
|
|
|
// apply to all displays.
|
|
|
|
const Transform& planeTransform(hw->getTransform());
|
|
|
|
orientation = planeTransform.getOrientation();
|
|
|
|
if (orientation & Transform::ROT_INVALID) {
|
|
|
|
orientation = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mSurfaceFlingerConsumer->setTransformHint(orientation);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// debugging
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2013-04-22 15:52:16 +00:00
|
|
|
void Layer::dump(String8& result, Colorizer& colorizer) const
|
2010-04-21 00:55:49 +00:00
|
|
|
{
|
2013-06-05 23:59:15 +00:00
|
|
|
const Layer::State& s(getDrawingState());
|
2013-03-06 01:47:11 +00:00
|
|
|
|
2013-04-22 15:52:16 +00:00
|
|
|
colorizer.colorize(result, Colorizer::GREEN);
|
2013-04-22 14:55:35 +00:00
|
|
|
result.appendFormat(
|
2013-03-06 01:47:11 +00:00
|
|
|
"+ %s %p (%s)\n",
|
|
|
|
getTypeId(), this, getName().string());
|
2013-04-22 15:52:16 +00:00
|
|
|
colorizer.reset(result);
|
2013-03-06 01:47:11 +00:00
|
|
|
|
2013-04-03 01:30:32 +00:00
|
|
|
s.activeTransparentRegion.dump(result, "transparentRegion");
|
2013-03-06 01:47:11 +00:00
|
|
|
visibleRegion.dump(result, "visibleRegion");
|
|
|
|
sp<Client> client(mClientRef.promote());
|
|
|
|
|
2013-04-22 14:55:35 +00:00
|
|
|
result.appendFormat( " "
|
2013-03-06 01:47:11 +00:00
|
|
|
"layerStack=%4d, z=%9d, pos=(%g,%g), size=(%4d,%4d), crop=(%4d,%4d,%4d,%4d), "
|
|
|
|
"isOpaque=%1d, invalidate=%1d, "
|
|
|
|
"alpha=0x%02x, flags=0x%08x, tr=[%.2f, %.2f][%.2f, %.2f]\n"
|
|
|
|
" client=%p\n",
|
|
|
|
s.layerStack, s.z, s.transform.tx(), s.transform.ty(), s.active.w, s.active.h,
|
|
|
|
s.active.crop.left, s.active.crop.top,
|
|
|
|
s.active.crop.right, s.active.crop.bottom,
|
2014-01-30 01:17:11 +00:00
|
|
|
isOpaque(s), contentDirty,
|
2013-03-06 01:47:11 +00:00
|
|
|
s.alpha, s.flags,
|
|
|
|
s.transform[0][0], s.transform[0][1],
|
|
|
|
s.transform[1][0], s.transform[1][1],
|
|
|
|
client.get());
|
2010-04-21 00:55:49 +00:00
|
|
|
|
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
|
|
|
}
|
2013-04-22 14:55:35 +00:00
|
|
|
result.appendFormat(
|
2010-04-21 00:55:49 +00:00
|
|
|
" "
|
2011-08-08 23:02:13 +00:00
|
|
|
"format=%2d, activeBuffer=[%4ux%4u:%4u,%3X],"
|
2012-09-14 23:10:11 +00:00
|
|
|
" queued-frames=%d, mRefreshPending=%d\n",
|
2011-04-20 21:20:59 +00:00
|
|
|
mFormat, w0, h0, s0,f0,
|
2012-09-14 23:10:11 +00:00
|
|
|
mQueuedFrames, mRefreshPending);
|
2010-04-21 00:55:49 +00:00
|
|
|
|
2012-12-05 00:51:15 +00:00
|
|
|
if (mSurfaceFlingerConsumer != 0) {
|
2013-04-22 14:55:35 +00:00
|
|
|
mSurfaceFlingerConsumer->dump(result, " ");
|
2010-05-19 00:06:55 +00:00
|
|
|
}
|
2010-05-11 03:06:11 +00:00
|
|
|
}
|
|
|
|
|
2014-03-20 17:28:31 +00:00
|
|
|
void Layer::dumpFrameStats(String8& result) const {
|
|
|
|
mFrameTracker.dumpStats(result);
|
2012-01-20 02:34:40 +00:00
|
|
|
}
|
|
|
|
|
2014-03-20 17:28:31 +00:00
|
|
|
void Layer::clearFrameStats() {
|
|
|
|
mFrameTracker.clearStats();
|
2012-01-29 06:31:55 +00:00
|
|
|
}
|
|
|
|
|
2013-07-17 03:12:42 +00:00
|
|
|
void Layer::logFrameStats() {
|
|
|
|
mFrameTracker.logAndResetStats(mName);
|
|
|
|
}
|
|
|
|
|
2014-03-20 17:28:31 +00:00
|
|
|
void Layer::getFrameStats(FrameStats* outStats) const {
|
|
|
|
mFrameTracker.getStats(outStats);
|
|
|
|
}
|
|
|
|
|
2013-03-06 01:47:11 +00:00
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
Layer::LayerCleaner::LayerCleaner(const sp<SurfaceFlinger>& flinger,
|
|
|
|
const sp<Layer>& layer)
|
|
|
|
: mFlinger(flinger), mLayer(layer) {
|
2010-05-07 22:58:44 +00:00
|
|
|
}
|
|
|
|
|
2013-03-06 01:47:11 +00:00
|
|
|
Layer::LayerCleaner::~LayerCleaner() {
|
|
|
|
// destroy client resources
|
|
|
|
mFlinger->onLayerDestroyed(mLayer);
|
2011-08-24 01:03:18 +00:00
|
|
|
}
|
|
|
|
|
2009-03-04 03:31:44 +00:00
|
|
|
// ---------------------------------------------------------------------------
|
2013-08-08 04:24:32 +00:00
|
|
|
}; // namespace android
|
2009-03-04 03:31:44 +00:00
|
|
|
|
2013-08-08 04:24:32 +00:00
|
|
|
#if defined(__gl_h_)
|
|
|
|
#error "don't include gl/gl.h in this file"
|
|
|
|
#endif
|
2009-03-04 03:31:44 +00:00
|
|
|
|
2013-08-08 04:24:32 +00:00
|
|
|
#if defined(__gl2_h_)
|
|
|
|
#error "don't include gl2/gl2.h in this file"
|
|
|
|
#endif
|