fold LayerBaseClient into LayerBase

Change-Id: Ic745136522df59c42f0885fd969e75ea55d09f01
This commit is contained in:
Mathias Agopian 2013-03-05 15:14:58 -08:00
parent 089a15298e
commit b79f61d41e
10 changed files with 104 additions and 159 deletions

View File

@ -43,7 +43,7 @@ Client::~Client()
{
const size_t count = mLayers.size();
for (size_t i=0 ; i<count ; i++) {
sp<LayerBaseClient> layer(mLayers.valueAt(i).promote());
sp<LayerBase> layer(mLayers.valueAt(i).promote());
if (layer != 0) {
mFlinger->removeLayer(layer);
}
@ -54,13 +54,13 @@ status_t Client::initCheck() const {
return NO_ERROR;
}
void Client::attachLayer(const sp<IBinder>& handle, const sp<LayerBaseClient>& layer)
void Client::attachLayer(const sp<IBinder>& handle, const sp<LayerBase>& layer)
{
Mutex::Autolock _l(mLock);
mLayers.add(handle, layer);
}
void Client::detachLayer(const LayerBaseClient* layer)
void Client::detachLayer(const LayerBase* layer)
{
Mutex::Autolock _l(mLock);
// we do a linear search here, because this doesn't happen often
@ -72,11 +72,11 @@ void Client::detachLayer(const LayerBaseClient* layer)
}
}
}
sp<LayerBaseClient> Client::getLayerUser(const sp<IBinder>& handle) const
sp<LayerBase> Client::getLayerUser(const sp<IBinder>& handle) const
{
Mutex::Autolock _l(mLock);
sp<LayerBaseClient> lbc;
wp<LayerBaseClient> layer(mLayers.valueFor(handle));
sp<LayerBase> lbc;
wp<LayerBase> layer(mLayers.valueFor(handle));
if (layer != 0) {
lbc = layer.promote();
ALOGE_IF(lbc==0, "getLayerUser(name=%p) is dead", handle.get());

View File

@ -30,7 +30,7 @@ namespace android {
// ---------------------------------------------------------------------------
class LayerBaseClient;
class LayerBase;
class SurfaceFlinger;
// ---------------------------------------------------------------------------
@ -44,11 +44,11 @@ public:
status_t initCheck() const;
// protected by SurfaceFlinger::mStateLock
void attachLayer(const sp<IBinder>& handle, const sp<LayerBaseClient>& layer);
void attachLayer(const sp<IBinder>& handle, const sp<LayerBase>& layer);
void detachLayer(const LayerBaseClient* layer);
void detachLayer(const LayerBase* layer);
sp<LayerBaseClient> getLayerUser(const sp<IBinder>& handle) const;
sp<LayerBase> getLayerUser(const sp<IBinder>& handle) const;
private:
// ISurfaceComposerClient interface
@ -66,7 +66,7 @@ private:
sp<SurfaceFlinger> mFlinger;
// protected by mLock
DefaultKeyedVector< wp<IBinder>, wp<LayerBaseClient> > mLayers;
DefaultKeyedVector< wp<IBinder>, wp<LayerBase> > mLayers;
// thread-safe
mutable Mutex mLock;

View File

@ -50,7 +50,7 @@ namespace android {
// ---------------------------------------------------------------------------
Layer::Layer(SurfaceFlinger* flinger, const sp<Client>& client)
: LayerBaseClient(flinger, client),
: LayerBase(flinger, client),
mTextureName(-1U),
mQueuedFrames(0),
mCurrentTransform(0),
@ -70,7 +70,7 @@ Layer::Layer(SurfaceFlinger* flinger, const sp<Client>& client)
void Layer::onLayerDisplayed(const sp<const DisplayDevice>& hw,
HWComposer::HWCLayerInterface* layer) {
LayerBaseClient::onLayerDisplayed(hw, layer);
LayerBase::onLayerDisplayed(hw, layer);
if (layer) {
mSurfaceFlingerConsumer->setReleaseFence(layer->getAndResetReleaseFenceFd());
}
@ -78,7 +78,7 @@ void Layer::onLayerDisplayed(const sp<const DisplayDevice>& hw,
void Layer::onFirstRef()
{
LayerBaseClient::onFirstRef();
LayerBase::onFirstRef();
// Creates a custom BufferQueue for SurfaceFlingerConsumer to use
sp<BufferQueue> bq = new SurfaceTextureLayer();
@ -224,7 +224,7 @@ void Layer::setGeometry(
const sp<const DisplayDevice>& hw,
HWComposer::HWCLayerInterface& layer)
{
LayerBaseClient::setGeometry(hw, layer);
LayerBase::setGeometry(hw, layer);
// enable this layer
layer.setSkip(false);
@ -260,7 +260,7 @@ void Layer::setGeometry(
void Layer::setPerFrameData(const sp<const DisplayDevice>& hw,
HWComposer::HWCLayerInterface& layer) {
LayerBaseClient::setPerFrameData(hw, layer);
LayerBase::setPerFrameData(hw, layer);
// NOTE: buffer can be NULL if the client never drew into this
// layer yet, or if we ran out of memory
layer.setBuffer(mActiveBuffer);
@ -528,7 +528,7 @@ void Layer::onPostComposition() {
}
bool Layer::isVisible() const {
return LayerBaseClient::isVisible() && (mActiveBuffer != NULL);
return LayerBase::isVisible() && (mActiveBuffer != NULL);
}
Region Layer::latchBuffer(bool& recomputeVisibleRegions)
@ -704,7 +704,7 @@ Region Layer::latchBuffer(bool& recomputeVisibleRegions)
void Layer::dump(String8& result, char* buffer, size_t SIZE) const
{
LayerBaseClient::dump(result, buffer, SIZE);
LayerBase::dump(result, buffer, SIZE);
sp<const GraphicBuffer> buf0(mActiveBuffer);
uint32_t w0=0, h0=0, s0=0, f0=0;
@ -730,13 +730,13 @@ void Layer::dump(String8& result, char* buffer, size_t SIZE) const
void Layer::dumpStats(String8& result, char* buffer, size_t SIZE) const
{
LayerBaseClient::dumpStats(result, buffer, SIZE);
LayerBase::dumpStats(result, buffer, SIZE);
mFrameTracker.dump(result);
}
void Layer::clearStats()
{
LayerBaseClient::clearStats();
LayerBase::clearStats();
mFrameTracker.clear();
}

View File

@ -55,7 +55,7 @@ class GLExtensions;
* This also implements onFrameAvailable(), which notifies SurfaceFlinger
* that new data has arrived.
*/
class Layer : public LayerBaseClient,
class Layer : public LayerBase,
public SurfaceFlingerConsumer::FrameAvailableListener
{
public:
@ -93,7 +93,7 @@ public:
virtual void setName(const String8& name);
virtual bool isVisible() const;
// LayerBaseClient interface
// LayerBase interface
virtual wp<IBinder> getSurfaceTextureBinder() const;
// only for debugging

View File

@ -42,18 +42,24 @@ namespace android {
int32_t LayerBase::sSequence = 1;
LayerBase::LayerBase(SurfaceFlinger* flinger)
LayerBase::LayerBase(SurfaceFlinger* flinger, const sp<Client>& client)
: contentDirty(false),
sequence(uint32_t(android_atomic_inc(&sSequence))),
mFlinger(flinger), mFiltering(false),
mNeedsFiltering(false),
mTransactionFlags(0),
mPremultipliedAlpha(true), mName("unnamed"), mDebug(false)
mPremultipliedAlpha(true), mName("unnamed"), mDebug(false),
mHasSurface(false),
mClientRef(client)
{
}
LayerBase::~LayerBase()
{
sp<Client> c(mClientRef.promote());
if (c != 0) {
c->detachLayer(this);
}
}
void LayerBase::setName(const String8& name) {
@ -542,19 +548,22 @@ void LayerBase::dump(String8& result, char* buffer, size_t SIZE) const
s.transparentRegion.dump(result, "transparentRegion");
visibleRegion.dump(result, "visibleRegion");
sp<Client> client(mClientRef.promote());
snprintf(buffer, SIZE,
" "
"layerStack=%4d, z=%9d, pos=(%g,%g), size=(%4d,%4d), crop=(%4d,%4d,%4d,%4d), "
"isOpaque=%1d, needsDithering=%1d, invalidate=%1d, "
"alpha=0x%02x, flags=0x%08x, tr=[%.2f, %.2f][%.2f, %.2f]\n",
"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,
isOpaque(), needsDithering(), contentDirty,
s.alpha, s.flags,
s.transform[0][0], s.transform[0][1],
s.transform[1][0], s.transform[1][1]);
s.transform[1][0], s.transform[1][1],
client.get());
result.append(buffer);
}
@ -568,52 +577,32 @@ void LayerBase::dumpStats(String8& result, char* scratch, size_t SIZE) const {
void LayerBase::clearStats() {
}
sp<LayerBaseClient> LayerBase::getLayerBaseClient() const {
return 0;
}
sp<Layer> LayerBase::getLayer() const {
return 0;
}
// ---------------------------------------------------------------------------
LayerBaseClient::LayerBaseClient(SurfaceFlinger* flinger,
const sp<Client>& client)
: LayerBase(flinger),
mHasSurface(false),
mClientRef(client)
{
}
LayerBaseClient::~LayerBaseClient()
{
sp<Client> c(mClientRef.promote());
if (c != 0) {
c->detachLayer(this);
}
}
sp<ISurface> LayerBaseClient::createSurface()
sp<ISurface> LayerBase::createSurface()
{
class BSurface : public BnSurface, public LayerCleaner {
virtual sp<IGraphicBufferProducer> getSurfaceTexture() const { return 0; }
public:
BSurface(const sp<SurfaceFlinger>& flinger,
const sp<LayerBaseClient>& layer)
const sp<LayerBase>& layer)
: LayerCleaner(flinger, layer) { }
};
sp<ISurface> sur(new BSurface(mFlinger, this));
return sur;
}
sp<ISurface> LayerBaseClient::getSurface()
sp<ISurface> LayerBase::getSurface()
{
sp<ISurface> s;
Mutex::Autolock _l(mLock);
LOG_ALWAYS_FATAL_IF(mHasSurface,
"LayerBaseClient::getSurface() has already been called");
"LayerBase::getSurface() has already been called");
mHasSurface = true;
s = createSurface();
@ -621,36 +610,22 @@ sp<ISurface> LayerBaseClient::getSurface()
return s;
}
wp<IBinder> LayerBaseClient::getSurfaceBinder() const {
wp<IBinder> LayerBase::getSurfaceBinder() const {
return mClientSurfaceBinder;
}
wp<IBinder> LayerBaseClient::getSurfaceTextureBinder() const {
wp<IBinder> LayerBase::getSurfaceTextureBinder() const {
return 0;
}
void LayerBaseClient::dump(String8& result, char* buffer, size_t SIZE) const
{
LayerBase::dump(result, buffer, SIZE);
sp<Client> client(mClientRef.promote());
snprintf(buffer, SIZE, " client=%p\n", client.get());
result.append(buffer);
}
void LayerBaseClient::shortDump(String8& result, char* scratch, size_t size) const
{
LayerBaseClient::dump(result, scratch, size);
}
// ---------------------------------------------------------------------------
LayerBaseClient::LayerCleaner::LayerCleaner(const sp<SurfaceFlinger>& flinger,
const sp<LayerBaseClient>& layer)
LayerBase::LayerCleaner::LayerCleaner(const sp<SurfaceFlinger>& flinger,
const sp<LayerBase>& layer)
: mFlinger(flinger), mLayer(layer) {
}
LayerBaseClient::LayerCleaner::~LayerCleaner() {
LayerBase::LayerCleaner::~LayerCleaner() {
// destroy client resources
mFlinger->onLayerDestroyed(mLayer);
}

View File

@ -44,7 +44,6 @@ class Client;
class DisplayDevice;
class GraphicBuffer;
class Layer;
class LayerBaseClient;
class SurfaceFlinger;
// ---------------------------------------------------------------------------
@ -57,15 +56,25 @@ class SurfaceFlinger;
* Layers are organized into "layer stacks". Each layer is a member of
* exactly one layer stack, identified by an integer in Layer::State. A
* given layer stack may appear on more than one display.
*
* Notable subclasses (below LayerBaseClient) include Layer and LayerDim.
*/
class LayerBase : virtual public RefBase
{
static int32_t sSequence;
public:
LayerBase(SurfaceFlinger* flinger);
LayerBase(SurfaceFlinger* flinger, const sp<Client>& client);
// Creates an ISurface associated with this object. This may only be
// called once (see also getSurfaceBinder()).
sp<ISurface> getSurface();
// Returns the Binder object for the ISurface associated with
// this object.
wp<IBinder> getSurfaceBinder() const;
virtual wp<IBinder> getSurfaceTextureBinder() const;
mutable bool contentDirty;
// regions below are in window-manager space
@ -138,7 +147,6 @@ public:
Rect computeBounds() const;
virtual sp<LayerBaseClient> getLayerBaseClient() const;
virtual sp<Layer> getLayer() const;
virtual const char* getTypeId() const { return "LayerBase"; }
@ -294,6 +302,8 @@ public:
bool getFiltering() const;
private:
virtual sp<ISurface> createSurface();
Rect computeCrop(const sp<const DisplayDevice>& hw) const;
protected:
@ -301,6 +311,23 @@ protected:
GLclampf r, GLclampf g, GLclampf b, GLclampf alpha) const;
void drawWithOpenGL(const sp<const DisplayDevice>& hw, const Region& clip) const;
/*
* Trivial class, used to ensure that mFlinger->onLayerDestroyed(mLayer)
* is called.
*/
class LayerCleaner {
sp<SurfaceFlinger> mFlinger;
wp<LayerBase> mLayer;
protected:
~LayerCleaner();
public:
LayerCleaner(const sp<SurfaceFlinger>& flinger,
const sp<LayerBase>& layer);
};
sp<SurfaceFlinger> mFlinger;
private:
@ -323,64 +350,7 @@ protected:
mutable bool mDebug;
public:
// called from class SurfaceFlinger
virtual ~LayerBase();
private:
LayerBase(const LayerBase& rhs);
};
// ---------------------------------------------------------------------------
/*
* This adds some additional fields and methods to support some Binder IPC
* interactions. In particular, the LayerBaseClient's lifetime can be
* managed by references to an ISurface object in another process.
*/
class LayerBaseClient : public LayerBase
{
public:
LayerBaseClient(SurfaceFlinger* flinger, const sp<Client>& client);
virtual ~LayerBaseClient();
// Creates an ISurface associated with this object. This may only be
// called once (see also getSurfaceBinder()).
sp<ISurface> getSurface();
// Returns the Binder object for the ISurface associated with
// this object.
wp<IBinder> getSurfaceBinder() const;
virtual wp<IBinder> getSurfaceTextureBinder() const;
virtual sp<LayerBaseClient> getLayerBaseClient() const {
return const_cast<LayerBaseClient*>(this); }
virtual const char* getTypeId() const { return "LayerBaseClient"; }
protected:
virtual void dump(String8& result, char* scratch, size_t size) const;
virtual void shortDump(String8& result, char* scratch, size_t size) const;
/*
* Trivial class, used to ensure that mFlinger->onLayerDestroyed(mLayer)
* is called.
*/
class LayerCleaner {
sp<SurfaceFlinger> mFlinger;
wp<LayerBaseClient> mLayer;
protected:
~LayerCleaner();
public:
LayerCleaner(const sp<SurfaceFlinger>& flinger,
const sp<LayerBaseClient>& layer);
};
private:
virtual sp<ISurface> createSurface();
mutable Mutex mLock;
@ -391,6 +361,14 @@ private:
wp<IBinder> mClientSurfaceBinder;
const wp<Client> mClientRef;
public:
// called from class SurfaceFlinger
virtual ~LayerBase();
private:
LayerBase(const LayerBase& rhs);
};
// ---------------------------------------------------------------------------

View File

@ -34,7 +34,7 @@ namespace android {
// ---------------------------------------------------------------------------
LayerDim::LayerDim(SurfaceFlinger* flinger, const sp<Client>& client)
: LayerBaseClient(flinger, client)
: LayerBase(flinger, client)
{
}

View File

@ -29,7 +29,7 @@
namespace android {
class LayerDim : public LayerBaseClient
class LayerDim : public LayerBase
{
public:
LayerDim(SurfaceFlinger* flinger, const sp<Client>& client);

View File

@ -581,16 +581,13 @@ bool SurfaceFlinger::authenticateSurfaceTexture(
size_t count = currentLayers.size();
for (size_t i=0 ; i<count ; i++) {
const sp<LayerBase>& layer(currentLayers[i]);
sp<LayerBaseClient> lbc(layer->getLayerBaseClient());
if (lbc != NULL) {
// If this is an instance of Layer (as opposed to, say, LayerDim),
// we will get the consumer interface of SurfaceFlingerConsumer's
// BufferQueue. If it's the same Binder object as the graphic
// buffer producer interface, return success.
wp<IBinder> lbcBinder = lbc->getSurfaceTextureBinder();
if (lbcBinder == surfaceTextureBinder) {
return true;
}
// If this is an instance of Layer (as opposed to, say, LayerDim),
// we will get the consumer interface of SurfaceFlingerConsumer's
// BufferQueue. If it's the same Binder object as the graphic
// buffer producer interface, return success.
wp<IBinder> lbcBinder = layer->getSurfaceTextureBinder();
if (lbcBinder == surfaceTextureBinder) {
return true;
}
}
@ -604,12 +601,9 @@ bool SurfaceFlinger::authenticateSurfaceTexture(
size_t purgatorySize = mLayerPurgatory.size();
for (size_t i=0 ; i<purgatorySize ; i++) {
const sp<LayerBase>& layer(mLayerPurgatory.itemAt(i));
sp<LayerBaseClient> lbc(layer->getLayerBaseClient());
if (lbc != NULL) {
wp<IBinder> lbcBinder = lbc->getSurfaceTextureBinder();
if (lbcBinder == surfaceTextureBinder) {
return true;
}
wp<IBinder> lbcBinder = layer->getSurfaceTextureBinder();
if (lbcBinder == surfaceTextureBinder) {
return true;
}
}
@ -1683,7 +1677,7 @@ void SurfaceFlinger::drawWormhole(const sp<const DisplayDevice>& hw,
void SurfaceFlinger::addClientLayer(const sp<Client>& client,
const sp<IBinder>& handle,
const sp<LayerBaseClient>& lbc)
const sp<LayerBase>& lbc)
{
// attach this layer to the client
client->attachLayer(handle, lbc);
@ -1872,7 +1866,7 @@ uint32_t SurfaceFlinger::setClientStateLocked(
const layer_state_t& s)
{
uint32_t flags = 0;
sp<LayerBaseClient> layer(client->getLayerUser(s.surface));
sp<LayerBase> layer(client->getLayerUser(s.surface));
if (layer != 0) {
const uint32_t what = s.what;
if (what & layer_state_t::ePositionChanged) {
@ -1936,7 +1930,7 @@ sp<ISurface> SurfaceFlinger::createLayer(
uint32_t w, uint32_t h, PixelFormat format,
uint32_t flags)
{
sp<LayerBaseClient> layer;
sp<LayerBase> layer;
sp<ISurface> surfaceHandle;
if (int32_t(w|h) < 0) {
@ -2023,7 +2017,7 @@ status_t SurfaceFlinger::onLayerRemoved(const sp<Client>& client, const sp<IBind
status_t err = NAME_NOT_FOUND;
Mutex::Autolock _l(mStateLock);
sp<LayerBaseClient> layer = client->getLayerUser(handle);
sp<LayerBase> layer = client->getLayerUser(handle);
if (layer != 0) {
err = purgatorizeLayer_l(layer);
@ -2034,11 +2028,11 @@ status_t SurfaceFlinger::onLayerRemoved(const sp<Client>& client, const sp<IBind
return err;
}
status_t SurfaceFlinger::onLayerDestroyed(const wp<LayerBaseClient>& layer)
status_t SurfaceFlinger::onLayerDestroyed(const wp<LayerBase>& layer)
{
// called by ~ISurface() when all references are gone
status_t err = NO_ERROR;
sp<LayerBaseClient> l(layer.promote());
sp<LayerBase> l(layer.promote());
if (l != NULL) {
Mutex::Autolock _l(mStateLock);
err = removeLayer_l(l);

View File

@ -61,7 +61,6 @@ class EventThread;
class IGraphicBufferAlloc;
class Layer;
class LayerBase;
class LayerBaseClient;
class LayerDim;
class Surface;
@ -130,7 +129,6 @@ private:
friend class Client;
friend class DisplayEventConnection;
friend class LayerBase;
friend class LayerBaseClient;
friend class Layer;
// We're reference counted, never destroy SurfaceFlinger directly
@ -279,14 +277,14 @@ private:
// called when all clients have released all their references to
// this layer meaning it is entirely safe to destroy all
// resources associated to this layer.
status_t onLayerDestroyed(const wp<LayerBaseClient>& layer);
status_t onLayerDestroyed(const wp<LayerBase>& layer);
// remove a layer from SurfaceFlinger immediately
status_t removeLayer(const sp<LayerBase>& layer);
// add a layer to SurfaceFlinger
void addClientLayer(const sp<Client>& client, const sp<IBinder>& handle,
const sp<LayerBaseClient>& lbc);
const sp<LayerBase>& lbc);
status_t removeLayer_l(const sp<LayerBase>& layer);
status_t purgatorizeLayer_l(const sp<LayerBase>& layer);