2009-03-04 03:31:44 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2007 The Android Open Source Project
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <sys/types.h>
|
2013-02-28 06:03:19 +00:00
|
|
|
#include <math.h>
|
2009-03-04 03:31:44 +00:00
|
|
|
|
|
|
|
#include <utils/Errors.h>
|
|
|
|
#include <utils/Log.h>
|
2009-05-22 08:27:01 +00:00
|
|
|
#include <binder/IPCThreadState.h>
|
|
|
|
#include <binder/IServiceManager.h>
|
2009-03-04 03:31:44 +00:00
|
|
|
|
|
|
|
#include <GLES/gl.h>
|
|
|
|
#include <GLES/glext.h>
|
|
|
|
|
|
|
|
#include <hardware/hardware.h>
|
|
|
|
|
|
|
|
#include "clz.h"
|
2012-06-18 23:47:56 +00:00
|
|
|
#include "Client.h"
|
2009-03-04 03:31:44 +00:00
|
|
|
#include "LayerBase.h"
|
2012-07-24 06:11:29 +00:00
|
|
|
#include "Layer.h"
|
2009-03-04 03:31:44 +00:00
|
|
|
#include "SurfaceFlinger.h"
|
2012-08-01 06:09:07 +00:00
|
|
|
#include "DisplayDevice.h"
|
2009-03-04 03:31:44 +00:00
|
|
|
|
|
|
|
namespace android {
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2010-08-11 01:09:09 +00:00
|
|
|
int32_t LayerBase::sSequence = 1;
|
|
|
|
|
2012-08-27 23:28:24 +00:00
|
|
|
LayerBase::LayerBase(SurfaceFlinger* flinger)
|
|
|
|
: contentDirty(false),
|
2010-08-11 01:09:09 +00:00
|
|
|
sequence(uint32_t(android_atomic_inc(&sSequence))),
|
2011-04-20 21:20:59 +00:00
|
|
|
mFlinger(flinger), mFiltering(false),
|
2012-04-16 06:34:59 +00:00
|
|
|
mNeedsFiltering(false),
|
2009-03-04 03:31:44 +00:00
|
|
|
mTransactionFlags(0),
|
2012-02-01 02:24:27 +00:00
|
|
|
mPremultipliedAlpha(true), mName("unnamed"), mDebug(false)
|
2009-03-04 03:31:44 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
LayerBase::~LayerBase()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-03-10 03:17:47 +00:00
|
|
|
void LayerBase::setName(const String8& name) {
|
|
|
|
mName = name;
|
|
|
|
}
|
|
|
|
|
|
|
|
String8 LayerBase::getName() const {
|
|
|
|
return mName;
|
|
|
|
}
|
|
|
|
|
2009-03-04 03:31:44 +00:00
|
|
|
void LayerBase::initStates(uint32_t w, uint32_t h, uint32_t flags)
|
|
|
|
{
|
|
|
|
uint32_t layerFlags = 0;
|
2012-08-09 02:42:09 +00:00
|
|
|
if (flags & ISurfaceComposerClient::eHidden)
|
|
|
|
layerFlags = layer_state_t::eLayerHidden;
|
2009-03-04 03:31:44 +00:00
|
|
|
|
2012-08-09 02:42:09 +00:00
|
|
|
if (flags & ISurfaceComposerClient::eNonPremultiplied)
|
2009-03-04 03:31:44 +00:00
|
|
|
mPremultipliedAlpha = false;
|
|
|
|
|
2012-05-17 00:07:49 +00:00
|
|
|
mCurrentState.active.w = w;
|
|
|
|
mCurrentState.active.h = h;
|
|
|
|
mCurrentState.active.crop.makeInvalid();
|
|
|
|
mCurrentState.z = 0;
|
|
|
|
mCurrentState.alpha = 0xFF;
|
2012-07-25 04:41:09 +00:00
|
|
|
mCurrentState.layerStack = 0;
|
2012-05-17 00:07:49 +00:00
|
|
|
mCurrentState.flags = layerFlags;
|
|
|
|
mCurrentState.sequence = 0;
|
2009-03-04 03:31:44 +00:00
|
|
|
mCurrentState.transform.set(0, 0);
|
2012-05-17 00:07:49 +00:00
|
|
|
mCurrentState.requested = mCurrentState.active;
|
2009-03-04 03:31:44 +00:00
|
|
|
|
|
|
|
// drawing state & current state are identical
|
|
|
|
mDrawingState = mCurrentState;
|
|
|
|
}
|
|
|
|
|
2012-09-20 06:14:45 +00:00
|
|
|
bool LayerBase::needsFiltering(const sp<const DisplayDevice>& hw) const {
|
|
|
|
return mNeedsFiltering || hw->needsFiltering();
|
|
|
|
}
|
|
|
|
|
2009-09-30 05:32:36 +00:00
|
|
|
void LayerBase::commitTransaction() {
|
2009-03-04 03:31:44 +00:00
|
|
|
mDrawingState = mCurrentState;
|
|
|
|
}
|
|
|
|
void LayerBase::forceVisibilityTransaction() {
|
|
|
|
// this can be called without SurfaceFlinger.mStateLock, but if we
|
|
|
|
// can atomically increment the sequence number, it doesn't matter.
|
|
|
|
android_atomic_inc(&mCurrentState.sequence);
|
|
|
|
requestTransaction();
|
|
|
|
}
|
|
|
|
bool LayerBase::requestTransaction() {
|
|
|
|
int32_t old = setTransactionFlags(eTransactionNeeded);
|
|
|
|
return ((old & eTransactionNeeded) == 0);
|
|
|
|
}
|
|
|
|
uint32_t LayerBase::getTransactionFlags(uint32_t flags) {
|
|
|
|
return android_atomic_and(~flags, &mTransactionFlags) & flags;
|
|
|
|
}
|
|
|
|
uint32_t LayerBase::setTransactionFlags(uint32_t flags) {
|
|
|
|
return android_atomic_or(flags, &mTransactionFlags);
|
|
|
|
}
|
|
|
|
|
2011-08-31 01:51:54 +00:00
|
|
|
bool LayerBase::setPosition(float x, float y) {
|
2009-03-04 03:31:44 +00:00
|
|
|
if (mCurrentState.transform.tx() == x && mCurrentState.transform.ty() == y)
|
|
|
|
return false;
|
|
|
|
mCurrentState.sequence++;
|
|
|
|
mCurrentState.transform.set(x, y);
|
|
|
|
requestTransaction();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
bool LayerBase::setLayer(uint32_t z) {
|
|
|
|
if (mCurrentState.z == z)
|
|
|
|
return false;
|
|
|
|
mCurrentState.sequence++;
|
|
|
|
mCurrentState.z = z;
|
|
|
|
requestTransaction();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
bool LayerBase::setSize(uint32_t w, uint32_t h) {
|
2012-05-17 00:07:49 +00:00
|
|
|
if (mCurrentState.requested.w == w && mCurrentState.requested.h == h)
|
2009-03-04 03:31:44 +00:00
|
|
|
return false;
|
2012-05-17 00:07:49 +00:00
|
|
|
mCurrentState.requested.w = w;
|
|
|
|
mCurrentState.requested.h = h;
|
2009-03-04 03:31:44 +00:00
|
|
|
requestTransaction();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
bool LayerBase::setAlpha(uint8_t alpha) {
|
|
|
|
if (mCurrentState.alpha == alpha)
|
|
|
|
return false;
|
|
|
|
mCurrentState.sequence++;
|
|
|
|
mCurrentState.alpha = alpha;
|
|
|
|
requestTransaction();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
bool LayerBase::setMatrix(const layer_state_t::matrix22_t& matrix) {
|
|
|
|
mCurrentState.sequence++;
|
|
|
|
mCurrentState.transform.set(
|
|
|
|
matrix.dsdx, matrix.dsdy, matrix.dtdx, matrix.dtdy);
|
|
|
|
requestTransaction();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
bool LayerBase::setTransparentRegionHint(const Region& transparent) {
|
|
|
|
mCurrentState.sequence++;
|
|
|
|
mCurrentState.transparentRegion = transparent;
|
|
|
|
requestTransaction();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
bool LayerBase::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;
|
|
|
|
requestTransaction();
|
|
|
|
return true;
|
|
|
|
}
|
2012-05-11 03:43:55 +00:00
|
|
|
bool LayerBase::setCrop(const Rect& crop) {
|
2012-05-17 01:21:32 +00:00
|
|
|
if (mCurrentState.requested.crop == crop)
|
2012-05-11 03:43:55 +00:00
|
|
|
return false;
|
|
|
|
mCurrentState.sequence++;
|
2012-05-17 01:21:32 +00:00
|
|
|
mCurrentState.requested.crop = crop;
|
2012-05-11 03:43:55 +00:00
|
|
|
requestTransaction();
|
|
|
|
return true;
|
|
|
|
}
|
2009-03-04 03:31:44 +00:00
|
|
|
|
2012-07-25 04:41:09 +00:00
|
|
|
bool LayerBase::setLayerStack(uint32_t layerStack) {
|
|
|
|
if (mCurrentState.layerStack == layerStack)
|
|
|
|
return false;
|
|
|
|
mCurrentState.sequence++;
|
|
|
|
mCurrentState.layerStack = layerStack;
|
|
|
|
requestTransaction();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-03-04 03:31:44 +00:00
|
|
|
void LayerBase::setVisibleRegion(const Region& visibleRegion) {
|
|
|
|
// always called from main thread
|
2012-06-29 21:12:52 +00:00
|
|
|
this->visibleRegion = visibleRegion;
|
2009-03-04 03:31:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void LayerBase::setCoveredRegion(const Region& coveredRegion) {
|
|
|
|
// always called from main thread
|
2012-06-29 21:12:52 +00:00
|
|
|
this->coveredRegion = coveredRegion;
|
2009-03-04 03:31:44 +00:00
|
|
|
}
|
|
|
|
|
2012-09-25 20:25:04 +00:00
|
|
|
void LayerBase::setVisibleNonTransparentRegion(const Region&
|
|
|
|
setVisibleNonTransparentRegion) {
|
|
|
|
// always called from main thread
|
|
|
|
this->visibleNonTransparentRegion = setVisibleNonTransparentRegion;
|
|
|
|
}
|
|
|
|
|
2009-03-04 03:31:44 +00:00
|
|
|
uint32_t LayerBase::doTransaction(uint32_t flags)
|
|
|
|
{
|
|
|
|
const Layer::State& front(drawingState());
|
|
|
|
const Layer::State& temp(currentState());
|
|
|
|
|
2012-05-23 21:35:49 +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 {
|
2009-09-30 05:39:22 +00:00
|
|
|
Layer::State& editTemp(currentState());
|
2012-05-17 01:21:32 +00:00
|
|
|
editTemp.active = temp.requested;
|
2009-09-30 05:39:22 +00:00
|
|
|
}
|
2012-05-23 21:35:49 +00:00
|
|
|
|
2012-05-17 01:21:32 +00:00
|
|
|
if (front.active != temp.active) {
|
2009-09-30 19:48:47 +00:00
|
|
|
// invalidate and recompute the visible regions if needed
|
|
|
|
flags |= Layer::eVisibleRegion;
|
|
|
|
}
|
2009-09-30 05:39:22 +00:00
|
|
|
|
2009-03-04 03:31:44 +00:00
|
|
|
if (temp.sequence != front.sequence) {
|
|
|
|
// invalidate and recompute the visible regions if needed
|
|
|
|
flags |= eVisibleRegion;
|
|
|
|
this->contentDirty = true;
|
2009-09-24 01:34:53 +00:00
|
|
|
|
2010-12-03 05:32:29 +00:00
|
|
|
// we may use linear filtering, if the matrix scales us
|
|
|
|
const uint8_t type = temp.transform.getType();
|
|
|
|
mNeedsFiltering = (!temp.transform.preserveRects() ||
|
|
|
|
(type >= Transform::SCALE));
|
2009-09-24 01:34:53 +00:00
|
|
|
}
|
|
|
|
|
2009-03-04 03:31:44 +00:00
|
|
|
// Commit the transaction
|
2009-09-30 05:32:36 +00:00
|
|
|
commitTransaction();
|
2009-03-04 03:31:44 +00:00
|
|
|
return flags;
|
|
|
|
}
|
|
|
|
|
2012-08-05 07:40:46 +00:00
|
|
|
void LayerBase::computeGeometry(const sp<const DisplayDevice>& hw, LayerMesh* mesh) const
|
2009-03-04 03:31:44 +00:00
|
|
|
{
|
|
|
|
const Layer::State& s(drawingState());
|
2012-08-05 07:40:46 +00:00
|
|
|
const Transform tr(hw->getTransform() * s.transform);
|
|
|
|
const uint32_t hw_h = hw->getHeight();
|
2012-05-17 00:07:49 +00:00
|
|
|
Rect win(s.active.w, s.active.h);
|
2012-09-25 05:01:01 +00:00
|
|
|
if (!s.active.crop.isEmpty()) {
|
|
|
|
win.intersect(s.active.crop, &win);
|
2012-05-11 03:43:55 +00:00
|
|
|
}
|
2012-06-29 21:12:52 +00:00
|
|
|
if (mesh) {
|
|
|
|
tr.transform(mesh->mVertices[0], win.left, win.top);
|
|
|
|
tr.transform(mesh->mVertices[1], win.left, win.bottom);
|
|
|
|
tr.transform(mesh->mVertices[2], win.right, win.bottom);
|
|
|
|
tr.transform(mesh->mVertices[3], win.right, win.top);
|
|
|
|
for (size_t i=0 ; i<4 ; i++) {
|
|
|
|
mesh->mVertices[i][1] = hw_h - mesh->mVertices[i][1];
|
2009-03-04 03:31:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-29 21:12:52 +00:00
|
|
|
Rect LayerBase::computeBounds() const {
|
|
|
|
const Layer::State& s(drawingState());
|
|
|
|
Rect win(s.active.w, s.active.h);
|
2012-09-25 05:01:01 +00:00
|
|
|
if (!s.active.crop.isEmpty()) {
|
|
|
|
win.intersect(s.active.crop, &win);
|
2012-06-29 21:12:52 +00:00
|
|
|
}
|
2013-02-27 00:37:53 +00:00
|
|
|
return win;
|
2009-03-04 03:31:44 +00:00
|
|
|
}
|
|
|
|
|
2012-06-29 21:12:52 +00:00
|
|
|
Region LayerBase::latchBuffer(bool& recomputeVisibleRegions) {
|
|
|
|
Region result;
|
|
|
|
return result;
|
2009-03-04 03:31:44 +00:00
|
|
|
}
|
|
|
|
|
2013-02-28 06:03:19 +00:00
|
|
|
|
|
|
|
Rect LayerBase::getContentCrop() const {
|
|
|
|
// regular layers just use their active area as the content crop
|
|
|
|
const State& s(drawingState());
|
|
|
|
return Rect(s.active.w, s.active.h);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t LayerBase::getContentTransform() const {
|
|
|
|
// regular layers don't have a content transform
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
Rect LayerBase::computeCrop(const sp<const DisplayDevice>& hw) const {
|
2013-03-01 01:12:07 +00:00
|
|
|
/*
|
|
|
|
* The way we compute the crop (aka. texture coordinates when we have a
|
|
|
|
* Layer) produces a different output from the GL code in
|
|
|
|
* drawWithOpenGL() due to HWC being limited to integers. The difference
|
|
|
|
* can be large if getContentTransform() contains a large scale factor.
|
|
|
|
* See comments in drawWithOpenGL() for more details.
|
|
|
|
*/
|
|
|
|
|
2013-02-28 06:03:19 +00:00
|
|
|
// the content crop is the area of the content that gets scaled to the
|
|
|
|
// layer's size.
|
|
|
|
Rect crop(getContentCrop());
|
|
|
|
|
|
|
|
// the active.crop is the area of the window that gets cropped, but not
|
|
|
|
// scaled in any ways.
|
|
|
|
const State& s(drawingState());
|
2013-03-01 01:12:07 +00:00
|
|
|
|
|
|
|
// apply the projection's clipping to the window crop in
|
|
|
|
// layerstack space, and convert-back to layer space.
|
|
|
|
// if there are no window scaling (or content scaling) involved,
|
|
|
|
// this operation will map to full pixels in the buffer.
|
|
|
|
// NOTE: should we revert to GL composition if a scaling is involved
|
|
|
|
// since it cannot be represented in the HWC API?
|
|
|
|
Rect activeCrop(s.transform.transform(s.active.crop));
|
|
|
|
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-02-28 06:03:19 +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.
|
|
|
|
uint32_t invTransform = getContentTransform();
|
|
|
|
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(
|
|
|
|
invTransform, s.active.w, s.active.h);
|
|
|
|
|
|
|
|
// the code below essentially performs a scaled intersection
|
|
|
|
// of crop and winCrop
|
|
|
|
float xScale = float(crop.width()) / float(winWidth);
|
|
|
|
float yScale = float(crop.height()) / float(winHeight);
|
|
|
|
|
|
|
|
int insetL = int(ceilf( winCrop.left * xScale));
|
|
|
|
int insetT = int(ceilf( winCrop.top * yScale));
|
|
|
|
int insetR = int(ceilf((winWidth - winCrop.right ) * xScale));
|
|
|
|
int insetB = int(ceilf((winHeight - winCrop.bottom) * yScale));
|
|
|
|
|
|
|
|
crop.left += insetL;
|
|
|
|
crop.top += insetT;
|
|
|
|
crop.right -= insetR;
|
|
|
|
crop.bottom -= insetB;
|
|
|
|
}
|
|
|
|
return crop;
|
|
|
|
}
|
|
|
|
|
2012-06-29 21:12:52 +00:00
|
|
|
void LayerBase::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)
|
2011-08-02 22:51:37 +00:00
|
|
|
{
|
2012-05-14 03:42:01 +00:00
|
|
|
layer.setDefaultState();
|
2011-08-02 22:51:37 +00:00
|
|
|
|
|
|
|
// this gives us only the "orientation" component of the transform
|
|
|
|
const State& s(drawingState());
|
|
|
|
const uint32_t finalTransform = s.transform.getOrientation();
|
|
|
|
// we can only handle simple transformation
|
|
|
|
if (finalTransform & Transform::ROT_INVALID) {
|
2012-05-14 03:42:01 +00:00
|
|
|
layer.setTransform(0);
|
2011-08-02 22:51:37 +00:00
|
|
|
} else {
|
2012-05-14 03:42:01 +00:00
|
|
|
layer.setTransform(finalTransform);
|
2011-08-02 22:51:37 +00:00
|
|
|
}
|
|
|
|
|
2013-01-30 02:56:42 +00:00
|
|
|
if (!isOpaque() || s.alpha != 0xFF) {
|
2012-05-14 03:42:01 +00:00
|
|
|
layer.setBlending(mPremultipliedAlpha ?
|
|
|
|
HWC_BLENDING_PREMULT :
|
|
|
|
HWC_BLENDING_COVERAGE);
|
2011-08-02 22:51:37 +00:00
|
|
|
}
|
|
|
|
|
2012-06-29 21:12:52 +00:00
|
|
|
|
2013-02-27 00:37:53 +00:00
|
|
|
// apply the layer's transform, followed by the display's global transform
|
|
|
|
// here we're guaranteed that the layer's transform preserves rects
|
|
|
|
|
2013-02-28 06:03:19 +00:00
|
|
|
Rect frame(s.transform.transform(computeBounds()));
|
2013-03-01 01:12:07 +00:00
|
|
|
frame.intersect(hw->getViewport(), &frame);
|
2013-02-28 06:03:19 +00:00
|
|
|
const Transform& tr(hw->getTransform());
|
|
|
|
layer.setFrame(tr.transform(frame));
|
|
|
|
layer.setCrop(computeCrop(hw));
|
2012-05-14 03:42:01 +00:00
|
|
|
}
|
|
|
|
|
2012-08-05 07:40:46 +00:00
|
|
|
void LayerBase::setPerFrameData(const sp<const DisplayDevice>& hw,
|
2012-08-02 21:01:42 +00:00
|
|
|
HWComposer::HWCLayerInterface& layer) {
|
2012-09-01 00:51:25 +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.
|
2013-02-27 00:54:05 +00:00
|
|
|
// Apply this display's projection's viewport to the visible region
|
|
|
|
// before giving it to the HWC HAL.
|
2012-09-01 00:51:25 +00:00
|
|
|
const Transform& tr = hw->getTransform();
|
2013-02-27 00:54:05 +00:00
|
|
|
Region visible = tr.transform(visibleRegion.intersect(hw->getViewport()));
|
|
|
|
layer.setVisibleRegionScreen(visible);
|
2011-08-30 22:02:41 +00:00
|
|
|
}
|
|
|
|
|
2012-08-05 07:40:46 +00:00
|
|
|
void LayerBase::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
|
|
|
layer.setAcquireFenceFd(-1);
|
|
|
|
}
|
|
|
|
|
2012-09-01 00:51:25 +00:00
|
|
|
void LayerBase::onLayerDisplayed(const sp<const DisplayDevice>& hw,
|
|
|
|
HWComposer::HWCLayerInterface* layer) {
|
|
|
|
if (layer) {
|
|
|
|
layer->onDisplayed();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-20 21:20:59 +00:00
|
|
|
void LayerBase::setFiltering(bool filtering)
|
|
|
|
{
|
|
|
|
mFiltering = filtering;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool LayerBase::getFiltering() const
|
|
|
|
{
|
|
|
|
return mFiltering;
|
|
|
|
}
|
|
|
|
|
2012-09-14 01:17:13 +00:00
|
|
|
bool LayerBase::isVisible() const {
|
|
|
|
const Layer::State& s(mDrawingState);
|
|
|
|
return !(s.flags & layer_state_t::eLayerHidden) && s.alpha;
|
|
|
|
}
|
|
|
|
|
2012-08-05 07:40:46 +00:00
|
|
|
void LayerBase::draw(const sp<const DisplayDevice>& hw, const Region& clip) const
|
2009-03-04 03:31:44 +00:00
|
|
|
{
|
2012-06-21 00:51:20 +00:00
|
|
|
onDraw(hw, clip);
|
2009-03-04 03:31:44 +00:00
|
|
|
}
|
|
|
|
|
2012-08-05 07:40:46 +00:00
|
|
|
void LayerBase::draw(const sp<const DisplayDevice>& hw)
|
2010-09-29 20:02:36 +00:00
|
|
|
{
|
2012-08-05 07:40:46 +00:00
|
|
|
onDraw( hw, Region(hw->bounds()) );
|
2010-09-29 20:02:36 +00:00
|
|
|
}
|
|
|
|
|
2012-08-05 07:40:46 +00:00
|
|
|
void LayerBase::clearWithOpenGL(const sp<const DisplayDevice>& hw, const Region& clip,
|
2012-06-21 00:51:20 +00:00
|
|
|
GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha) const
|
2009-03-04 03:31:44 +00:00
|
|
|
{
|
2012-08-05 07:40:46 +00:00
|
|
|
const uint32_t fbHeight = hw->getHeight();
|
2010-05-27 05:26:12 +00:00
|
|
|
glColor4f(red,green,blue,alpha);
|
2010-06-15 04:20:00 +00:00
|
|
|
|
2011-10-18 21:49:27 +00:00
|
|
|
glDisable(GL_TEXTURE_EXTERNAL_OES);
|
2011-04-20 21:20:59 +00:00
|
|
|
glDisable(GL_TEXTURE_2D);
|
2009-03-04 03:31:44 +00:00
|
|
|
glDisable(GL_BLEND);
|
2009-05-11 07:03:41 +00:00
|
|
|
|
2012-06-29 21:12:52 +00:00
|
|
|
LayerMesh mesh;
|
|
|
|
computeGeometry(hw, &mesh);
|
|
|
|
|
|
|
|
glVertexPointer(2, GL_FLOAT, 0, mesh.getVertices());
|
|
|
|
glDrawArrays(GL_TRIANGLE_FAN, 0, mesh.getVertexCount());
|
2009-03-04 03:31:44 +00:00
|
|
|
}
|
|
|
|
|
2012-08-05 07:40:46 +00:00
|
|
|
void LayerBase::clearWithOpenGL(const sp<const DisplayDevice>& hw, const Region& clip) const
|
2009-09-02 06:06:45 +00:00
|
|
|
{
|
2012-06-21 00:51:20 +00:00
|
|
|
clearWithOpenGL(hw, clip, 0,0,0,0);
|
2009-09-02 06:06:45 +00:00
|
|
|
}
|
|
|
|
|
2012-08-05 07:40:46 +00:00
|
|
|
void LayerBase::drawWithOpenGL(const sp<const DisplayDevice>& hw, const Region& clip) const
|
2009-03-04 03:31:44 +00:00
|
|
|
{
|
2012-08-05 07:40:46 +00:00
|
|
|
const uint32_t fbHeight = hw->getHeight();
|
2009-03-04 03:31:44 +00:00
|
|
|
const State& s(drawingState());
|
|
|
|
|
2010-04-12 22:34:55 +00:00
|
|
|
GLenum src = mPremultipliedAlpha ? GL_ONE : GL_SRC_ALPHA;
|
2011-12-15 17:51:17 +00:00
|
|
|
if (CC_UNLIKELY(s.alpha < 0xFF)) {
|
2010-04-12 22:34:55 +00:00
|
|
|
const GLfloat alpha = s.alpha * (1.0f/255.0f);
|
|
|
|
if (mPremultipliedAlpha) {
|
|
|
|
glColor4f(alpha, alpha, alpha, alpha);
|
2009-03-04 03:31:44 +00:00
|
|
|
} else {
|
2010-04-12 22:34:55 +00:00
|
|
|
glColor4f(1, 1, 1, alpha);
|
2009-03-04 03:31:44 +00:00
|
|
|
}
|
|
|
|
glEnable(GL_BLEND);
|
|
|
|
glBlendFunc(src, GL_ONE_MINUS_SRC_ALPHA);
|
2010-04-12 22:34:55 +00:00
|
|
|
glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
|
2009-03-04 03:31:44 +00:00
|
|
|
} else {
|
2010-04-20 21:51:04 +00:00
|
|
|
glColor4f(1, 1, 1, 1);
|
2010-04-12 22:34:55 +00:00
|
|
|
glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
|
2011-04-20 21:20:59 +00:00
|
|
|
if (!isOpaque()) {
|
2009-03-04 03:31:44 +00:00
|
|
|
glEnable(GL_BLEND);
|
|
|
|
glBlendFunc(src, GL_ONE_MINUS_SRC_ALPHA);
|
|
|
|
} else {
|
|
|
|
glDisable(GL_BLEND);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-29 21:12:52 +00:00
|
|
|
LayerMesh mesh;
|
|
|
|
computeGeometry(hw, &mesh);
|
|
|
|
|
|
|
|
// TODO: we probably want to generate the texture coords with the mesh
|
|
|
|
// here we assume that we only have 4 vertices
|
|
|
|
|
2010-08-20 00:01:19 +00:00
|
|
|
struct TexCoords {
|
|
|
|
GLfloat u;
|
|
|
|
GLfloat v;
|
2010-04-20 21:51:04 +00:00
|
|
|
};
|
|
|
|
|
2013-03-01 01:12:07 +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
|
|
|
|
* is suspend is wether we should ignore this problem or revert to
|
|
|
|
* 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());
|
2012-09-25 05:01:01 +00:00
|
|
|
|
|
|
|
GLfloat left = GLfloat(win.left) / GLfloat(s.active.w);
|
|
|
|
GLfloat top = GLfloat(win.top) / GLfloat(s.active.h);
|
|
|
|
GLfloat right = GLfloat(win.right) / GLfloat(s.active.w);
|
|
|
|
GLfloat bottom = GLfloat(win.bottom) / GLfloat(s.active.h);
|
2012-05-11 03:43:55 +00:00
|
|
|
|
2010-08-20 00:01:19 +00:00
|
|
|
TexCoords texCoords[4];
|
2012-05-11 03:43:55 +00:00
|
|
|
texCoords[0].u = left;
|
|
|
|
texCoords[0].v = top;
|
|
|
|
texCoords[1].u = left;
|
|
|
|
texCoords[1].v = bottom;
|
|
|
|
texCoords[2].u = right;
|
|
|
|
texCoords[2].v = bottom;
|
|
|
|
texCoords[3].u = right;
|
|
|
|
texCoords[3].v = top;
|
|
|
|
for (int i = 0; i < 4; i++) {
|
|
|
|
texCoords[i].v = 1.0f - texCoords[i].v;
|
|
|
|
}
|
2009-03-04 03:31:44 +00:00
|
|
|
|
2010-04-20 21:51:04 +00:00
|
|
|
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
|
|
|
glTexCoordPointer(2, GL_FLOAT, 0, texCoords);
|
2012-06-29 21:12:52 +00:00
|
|
|
glVertexPointer(2, GL_FLOAT, 0, mesh.getVertices());
|
|
|
|
glDrawArrays(GL_TRIANGLE_FAN, 0, mesh.getVertexCount());
|
2009-03-04 03:31:44 +00:00
|
|
|
|
2010-04-20 21:51:04 +00:00
|
|
|
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
2011-10-18 21:49:27 +00:00
|
|
|
glDisable(GL_BLEND);
|
2009-03-04 03:31:44 +00:00
|
|
|
}
|
|
|
|
|
2010-04-21 00:55:49 +00:00
|
|
|
void LayerBase::dump(String8& result, char* buffer, size_t SIZE) const
|
|
|
|
{
|
|
|
|
const Layer::State& s(drawingState());
|
2012-02-05 08:19:27 +00:00
|
|
|
|
|
|
|
snprintf(buffer, SIZE,
|
|
|
|
"+ %s %p (%s)\n",
|
|
|
|
getTypeId(), this, getName().string());
|
|
|
|
result.append(buffer);
|
|
|
|
|
2012-01-20 02:34:40 +00:00
|
|
|
s.transparentRegion.dump(result, "transparentRegion");
|
2012-06-29 21:12:52 +00:00
|
|
|
visibleRegion.dump(result, "visibleRegion");
|
2012-02-05 08:19:27 +00:00
|
|
|
|
2010-04-21 00:55:49 +00:00
|
|
|
snprintf(buffer, SIZE,
|
|
|
|
" "
|
2012-08-11 01:50:38 +00:00
|
|
|
"layerStack=%4d, z=%9d, pos=(%g,%g), size=(%4d,%4d), crop=(%4d,%4d,%4d,%4d), "
|
2011-04-20 21:20:59 +00:00
|
|
|
"isOpaque=%1d, needsDithering=%1d, invalidate=%1d, "
|
2010-04-21 00:55:49 +00:00
|
|
|
"alpha=0x%02x, flags=0x%08x, tr=[%.2f, %.2f][%.2f, %.2f]\n",
|
2012-09-12 03:52:46 +00:00
|
|
|
s.layerStack, s.z, s.transform.tx(), s.transform.ty(), s.active.w, s.active.h,
|
2012-05-17 00:07:49 +00:00
|
|
|
s.active.crop.left, s.active.crop.top,
|
|
|
|
s.active.crop.right, s.active.crop.bottom,
|
2011-04-20 21:20:59 +00:00
|
|
|
isOpaque(), needsDithering(), contentDirty,
|
2010-04-21 00:55:49 +00:00
|
|
|
s.alpha, s.flags,
|
|
|
|
s.transform[0][0], s.transform[0][1],
|
|
|
|
s.transform[1][0], s.transform[1][1]);
|
|
|
|
result.append(buffer);
|
|
|
|
}
|
2009-10-27 03:12:37 +00:00
|
|
|
|
2012-01-29 06:31:55 +00:00
|
|
|
void LayerBase::shortDump(String8& result, char* scratch, size_t size) const {
|
2011-01-20 00:15:53 +00:00
|
|
|
LayerBase::dump(result, scratch, size);
|
|
|
|
}
|
|
|
|
|
2012-01-29 06:31:55 +00:00
|
|
|
void LayerBase::dumpStats(String8& result, char* scratch, size_t SIZE) const {
|
|
|
|
}
|
|
|
|
|
|
|
|
void LayerBase::clearStats() {
|
2012-01-20 02:34:40 +00:00
|
|
|
}
|
2011-01-20 00:15:53 +00:00
|
|
|
|
2012-07-24 06:11:29 +00:00
|
|
|
sp<LayerBaseClient> LayerBase::getLayerBaseClient() const {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
sp<Layer> LayerBase::getLayer() const {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-03-04 03:31:44 +00:00
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2012-08-27 23:28:24 +00:00
|
|
|
LayerBaseClient::LayerBaseClient(SurfaceFlinger* flinger,
|
2010-06-03 06:28:45 +00:00
|
|
|
const sp<Client>& client)
|
2012-08-27 23:28:24 +00:00
|
|
|
: LayerBase(flinger),
|
2011-02-16 03:01:06 +00:00
|
|
|
mHasSurface(false),
|
2013-02-12 00:40:36 +00:00
|
|
|
mClientRef(client)
|
2009-03-04 03:31:44 +00:00
|
|
|
{
|
2009-04-10 21:24:30 +00:00
|
|
|
}
|
2009-03-04 03:31:44 +00:00
|
|
|
|
|
|
|
LayerBaseClient::~LayerBaseClient()
|
|
|
|
{
|
2010-06-01 22:12:58 +00:00
|
|
|
sp<Client> c(mClientRef.promote());
|
2010-06-03 06:28:45 +00:00
|
|
|
if (c != 0) {
|
2010-06-01 22:12:58 +00:00
|
|
|
c->detachLayer(this);
|
2009-03-04 03:31:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-20 21:20:59 +00:00
|
|
|
sp<ISurface> LayerBaseClient::createSurface()
|
|
|
|
{
|
|
|
|
class BSurface : public BnSurface, public LayerCleaner {
|
2012-12-18 17:49:45 +00:00
|
|
|
virtual sp<IGraphicBufferProducer> getSurfaceTexture() const { return 0; }
|
2011-04-20 21:20:59 +00:00
|
|
|
public:
|
|
|
|
BSurface(const sp<SurfaceFlinger>& flinger,
|
|
|
|
const sp<LayerBaseClient>& layer)
|
|
|
|
: LayerCleaner(flinger, layer) { }
|
|
|
|
};
|
|
|
|
sp<ISurface> sur(new BSurface(mFlinger, this));
|
|
|
|
return sur;
|
|
|
|
}
|
|
|
|
|
|
|
|
sp<ISurface> LayerBaseClient::getSurface()
|
2009-04-10 21:24:30 +00:00
|
|
|
{
|
2011-04-20 21:20:59 +00:00
|
|
|
sp<ISurface> s;
|
2009-04-10 21:24:30 +00:00
|
|
|
Mutex::Autolock _l(mLock);
|
2011-02-16 03:01:06 +00:00
|
|
|
|
|
|
|
LOG_ALWAYS_FATAL_IF(mHasSurface,
|
|
|
|
"LayerBaseClient::getSurface() has already been called");
|
|
|
|
|
|
|
|
mHasSurface = true;
|
|
|
|
s = createSurface();
|
|
|
|
mClientSurfaceBinder = s->asBinder();
|
2009-04-10 21:24:30 +00:00
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2011-01-26 04:17:45 +00:00
|
|
|
wp<IBinder> LayerBaseClient::getSurfaceBinder() const {
|
|
|
|
return mClientSurfaceBinder;
|
|
|
|
}
|
|
|
|
|
2011-08-18 01:19:00 +00:00
|
|
|
wp<IBinder> LayerBaseClient::getSurfaceTextureBinder() const {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-04-21 00:55:49 +00:00
|
|
|
void LayerBaseClient::dump(String8& result, char* buffer, size_t SIZE) const
|
|
|
|
{
|
|
|
|
LayerBase::dump(result, buffer, SIZE);
|
2010-06-01 22:12:58 +00:00
|
|
|
sp<Client> client(mClientRef.promote());
|
2013-02-12 00:40:36 +00:00
|
|
|
snprintf(buffer, SIZE, " client=%p\n", client.get());
|
2010-04-21 00:55:49 +00:00
|
|
|
result.append(buffer);
|
|
|
|
}
|
|
|
|
|
2011-01-20 00:15:53 +00:00
|
|
|
|
|
|
|
void LayerBaseClient::shortDump(String8& result, char* scratch, size_t size) const
|
|
|
|
{
|
|
|
|
LayerBaseClient::dump(result, scratch, size);
|
|
|
|
}
|
|
|
|
|
2009-04-10 21:24:30 +00:00
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2011-04-20 21:20:59 +00:00
|
|
|
LayerBaseClient::LayerCleaner::LayerCleaner(const sp<SurfaceFlinger>& flinger,
|
|
|
|
const sp<LayerBaseClient>& layer)
|
|
|
|
: mFlinger(flinger), mLayer(layer) {
|
2009-04-10 21:24:30 +00:00
|
|
|
}
|
|
|
|
|
2011-04-20 21:20:59 +00:00
|
|
|
LayerBaseClient::LayerCleaner::~LayerCleaner() {
|
2009-04-18 02:36:26 +00:00
|
|
|
// destroy client resources
|
2012-07-24 06:11:29 +00:00
|
|
|
mFlinger->onLayerDestroyed(mLayer);
|
2010-05-07 22:58:44 +00:00
|
|
|
}
|
|
|
|
|
2009-03-04 03:31:44 +00:00
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
}; // namespace android
|