diff options
author | Mathias Agopian <mathias@google.com> | 2013-03-12 17:11:48 -0700 |
---|---|---|
committer | Mathias Agopian <mathias@google.com> | 2013-03-12 17:11:48 -0700 |
commit | 4d9b822e2c18142e55fe2611aa6cd7dc7d4a62c6 (patch) | |
tree | efde8891af25d54a8211ee4280733046f4417c25 /services | |
parent | f44e9f91f37d3fbed64bc952f241d5dc3c385b6a (diff) | |
download | frameworks_native-4d9b822e2c18142e55fe2611aa6cd7dc7d4a62c6.zip frameworks_native-4d9b822e2c18142e55fe2611aa6cd7dc7d4a62c6.tar.gz frameworks_native-4d9b822e2c18142e55fe2611aa6cd7dc7d4a62c6.tar.bz2 |
get rid of ISurface
ISurface was only used to get the IGraphicBufferProducer from
a Layer. It's now replaced by a BBinder subclass / IBinder and
is only used as a handle to the surface, to both refer to it
and manage its life-time.
Also cleaned-up a bit the ISurfaceComposer interface and
"create layer" code path.
Change-Id: I68d0e02d57b862cffb31d5168c3bc10cea0906eb
Diffstat (limited to 'services')
-rw-r--r-- | services/surfaceflinger/Client.cpp | 29 | ||||
-rw-r--r-- | services/surfaceflinger/Client.h | 7 | ||||
-rw-r--r-- | services/surfaceflinger/Layer.cpp | 131 | ||||
-rw-r--r-- | services/surfaceflinger/Layer.h | 29 | ||||
-rw-r--r-- | services/surfaceflinger/LayerDim.cpp | 18 | ||||
-rw-r--r-- | services/surfaceflinger/LayerDim.h | 4 | ||||
-rw-r--r-- | services/surfaceflinger/SurfaceFlinger.cpp | 84 | ||||
-rw-r--r-- | services/surfaceflinger/SurfaceFlinger.h | 20 |
8 files changed, 147 insertions, 175 deletions
diff --git a/services/surfaceflinger/Client.cpp b/services/surfaceflinger/Client.cpp index 0575e35..dd65348 100644 --- a/services/surfaceflinger/Client.cpp +++ b/services/surfaceflinger/Client.cpp @@ -105,10 +105,11 @@ status_t Client::onTransact( } -sp<ISurface> Client::createSurface( +status_t Client::createSurface( const String8& name, - uint32_t w, uint32_t h, PixelFormat format, - uint32_t flags) + uint32_t w, uint32_t h, PixelFormat format, uint32_t flags, + sp<IBinder>* handle, + sp<IGraphicBufferProducer>* gbp) { /* * createSurface must be called from the GL thread so that it can @@ -116,9 +117,11 @@ sp<ISurface> Client::createSurface( */ class MessageCreateLayer : public MessageBase { - sp<ISurface> result; SurfaceFlinger* flinger; Client* client; + sp<IBinder>* handle; + sp<IGraphicBufferProducer>* gbp; + status_t result; const String8& name; uint32_t w, h; PixelFormat format; @@ -126,21 +129,23 @@ sp<ISurface> Client::createSurface( public: MessageCreateLayer(SurfaceFlinger* flinger, const String8& name, Client* client, - uint32_t w, uint32_t h, PixelFormat format, - uint32_t flags) - : flinger(flinger), client(client), name(name), - w(w), h(h), format(format), flags(flags) - { + uint32_t w, uint32_t h, PixelFormat format, uint32_t flags, + sp<IBinder>* handle, + sp<IGraphicBufferProducer>* gbp) + : flinger(flinger), client(client), + handle(handle), gbp(gbp), + name(name), w(w), h(h), format(format), flags(flags) { } - sp<ISurface> getResult() const { return result; } + status_t getResult() const { return result; } virtual bool handler() { - result = flinger->createLayer(name, client, w, h, format, flags); + result = flinger->createLayer(name, client, w, h, format, flags, + handle, gbp); return true; } }; sp<MessageBase> msg = new MessageCreateLayer(mFlinger.get(), - name, this, w, h, format, flags); + name, this, w, h, format, flags, handle, gbp); mFlinger->postMessageSync(msg); return static_cast<MessageCreateLayer*>( msg.get() )->getResult(); } diff --git a/services/surfaceflinger/Client.h b/services/surfaceflinger/Client.h index 4f34b86..84e649f 100644 --- a/services/surfaceflinger/Client.h +++ b/services/surfaceflinger/Client.h @@ -52,10 +52,11 @@ public: private: // ISurfaceComposerClient interface - virtual sp<ISurface> createSurface( + virtual status_t createSurface( const String8& name, - uint32_t w, uint32_t h,PixelFormat format, - uint32_t flags); + uint32_t w, uint32_t h,PixelFormat format, uint32_t flags, + sp<IBinder>* handle, + sp<IGraphicBufferProducer>* gbp); virtual status_t destroySurface(const sp<IBinder>& handle); diff --git a/services/surfaceflinger/Layer.cpp b/services/surfaceflinger/Layer.cpp index 44ef0b8..5996c90 100644 --- a/services/surfaceflinger/Layer.cpp +++ b/services/surfaceflinger/Layer.cpp @@ -52,7 +52,8 @@ namespace android { int32_t Layer::sSequence = 1; -Layer::Layer(SurfaceFlinger* flinger, const sp<Client>& client) +Layer::Layer(SurfaceFlinger* flinger, const sp<Client>& client, + const String8& name, uint32_t w, uint32_t h, uint32_t flags) : contentDirty(false), sequence(uint32_t(android_atomic_inc(&sSequence))), mFlinger(flinger), @@ -79,6 +80,29 @@ Layer::Layer(SurfaceFlinger* flinger, const sp<Client>& client) { mCurrentCrop.makeInvalid(); glGenTextures(1, &mTextureName); + + uint32_t layerFlags = 0; + if (flags & ISurfaceComposerClient::eHidden) + layerFlags = layer_state_t::eLayerHidden; + + 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; } void Layer::onFirstRef() @@ -91,6 +115,7 @@ void Layer::onFirstRef() mSurfaceFlingerConsumer->setConsumerUsageBits(getEffectiveUsage(0)); mSurfaceFlingerConsumer->setFrameAvailableListener(this); mSurfaceFlingerConsumer->setSynchronousMode(true); + mSurfaceFlingerConsumer->setName(mName); #ifdef TARGET_DISABLE_TRIPLE_BUFFERING #warning "disabling triple buffering" @@ -103,8 +128,7 @@ void Layer::onFirstRef() updateTransformHint(hw); } -Layer::~Layer() -{ +Layer::~Layer() { sp<Client> c(mClientRef.promote()); if (c != 0) { c->detachLayer(this); @@ -139,39 +163,10 @@ void Layer::onRemoved() { // set-up // --------------------------------------------------------------------------- -void Layer::setName(const String8& name) { - mName = name; - mSurfaceFlingerConsumer->setName(name); -} - String8 Layer::getName() const { return mName; } -void Layer::initStates(uint32_t w, uint32_t h, uint32_t flags) -{ - uint32_t layerFlags = 0; - if (flags & ISurfaceComposerClient::eHidden) - layerFlags = layer_state_t::eLayerHidden; - - if (flags & ISurfaceComposerClient::eNonPremultiplied) - mPremultipliedAlpha = false; - - 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; -} - status_t Layer::setBuffers( uint32_t w, uint32_t h, PixelFormat format, uint32_t flags) { @@ -207,59 +202,47 @@ status_t Layer::setBuffers( uint32_t w, uint32_t h, return NO_ERROR; } -sp<ISurface> Layer::createSurface() { +sp<IBinder> Layer::getHandle() { + Mutex::Autolock _l(mLock); + + LOG_ALWAYS_FATAL_IF(mHasSurface, + "Layer::getHandle() has already been called"); + + mHasSurface = true; + /* - * This class provides an implementation of BnSurface (the "native" or - * "remote" side of the Binder IPC interface ISurface), and mixes in - * LayerCleaner to ensure that mFlinger->onLayerDestroyed() is called for - * this layer when the BSurface is destroyed. - * - * The idea is to provide a handle to the Layer through ISurface that - * is cleaned up automatically when the last reference to the ISurface - * goes away. (The references will be held on the "proxy" side, while - * the Layer exists on the "native" side.) + * 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. * - * The Layer has a reference to an instance of SurfaceFlinger's variant - * of GLConsumer, which holds a reference to the BufferQueue. The - * getSurfaceTexture() call returns a Binder interface reference for - * the producer interface of the buffer queue associated with the Layer. + * LayerCleaner ensures that mFlinger->onLayerDestroyed() is called for + * this layer when the handle is destroyed. */ - class BSurface : public BnSurface, public LayerCleaner { + + class Handle : public BBinder, public LayerCleaner { wp<const Layer> mOwner; - virtual sp<IGraphicBufferProducer> getSurfaceTexture() const { - sp<IGraphicBufferProducer> res; - sp<const Layer> that( mOwner.promote() ); - if (that != NULL) { - res = that->mSurfaceFlingerConsumer->getBufferQueue(); - } - return res; - } public: - BSurface(const sp<SurfaceFlinger>& flinger, - const sp<Layer>& layer) - : LayerCleaner(flinger, layer), mOwner(layer) { } + Handle(const sp<SurfaceFlinger>& flinger, const sp<Layer>& layer) + : LayerCleaner(flinger, layer), mOwner(layer) { + } }; - sp<ISurface> sur(new BSurface(mFlinger, this)); - return sur; -} -wp<IBinder> Layer::getSurfaceTextureBinder() const { - return mSurfaceFlingerConsumer->getBufferQueue()->asBinder(); + return new Handle(mFlinger, this); } -sp<ISurface> Layer::getSurface() -{ - sp<ISurface> s; - Mutex::Autolock _l(mLock); - - LOG_ALWAYS_FATAL_IF(mHasSurface, - "Layer::getSurface() has already been called"); - - mHasSurface = true; - s = createSurface(); - return s; +sp<BufferQueue> Layer::getBufferQueue() const { + return mSurfaceFlingerConsumer->getBufferQueue(); } +//virtual sp<IGraphicBufferProducer> getSurfaceTexture() const { +// sp<IGraphicBufferProducer> res; +// sp<const Layer> that( mOwner.promote() ); +// if (that != NULL) { +// res = that->mSurfaceFlingerConsumer->getBufferQueue(); +// } +// return res; +//} + // --------------------------------------------------------------------------- // h/w composer set-up // --------------------------------------------------------------------------- diff --git a/services/surfaceflinger/Layer.h b/services/surfaceflinger/Layer.h index 5fb6d8b..6bca941 100644 --- a/services/surfaceflinger/Layer.h +++ b/services/surfaceflinger/Layer.h @@ -124,16 +124,12 @@ public: // ----------------------------------------------------------------------- - Layer(SurfaceFlinger* flinger, const sp<Client>& client); + Layer(SurfaceFlinger* flinger, const sp<Client>& client, + const String8& name, uint32_t w, uint32_t h, uint32_t flags); virtual ~Layer(); // the this layer's size and format - status_t setBuffers(uint32_t w, uint32_t h, - PixelFormat format, uint32_t flags=0); - - // Creates an ISurface associated with this object. This may only be - // called once. to provide your own ISurface, override createSurface(). - sp<ISurface> getSurface(); + status_t setBuffers(uint32_t w, uint32_t h, PixelFormat format, uint32_t flags); // modify current state bool setPosition(float x, float y); @@ -154,18 +150,14 @@ public: void computeGeometry(const sp<const DisplayDevice>& hw, LayerMesh* mesh) const; Rect computeBounds() const; - // ----------------------------------------------------------------------- + sp<IBinder> getHandle(); + sp<BufferQueue> getBufferQueue() const; + String8 getName() const; - /* - * initStates - called just after construction - */ - virtual void initStates(uint32_t w, uint32_t h, uint32_t flags); + // ----------------------------------------------------------------------- virtual const char* getTypeId() const { return "Layer"; } - virtual void setName(const String8& name); - String8 getName() const; - virtual void setGeometry(const sp<const DisplayDevice>& hw, HWComposer::HWCLayerInterface& layer); virtual void setPerFrameData(const sp<const DisplayDevice>& hw, @@ -277,8 +269,6 @@ public: virtual void onRemoved(); - virtual wp<IBinder> getSurfaceTextureBinder() const; - // Updates the transform hint in our SurfaceFlingerConsumer to match // the current orientation of the display device. virtual void updateTransformHint(const sp<const DisplayDevice>& hw) const; @@ -336,9 +326,6 @@ protected: private: - // Creates an instance of ISurface for this Layer. - virtual sp<ISurface> createSurface(); - // Interface implementation for SurfaceFlingerConsumer::FrameAvailableListener virtual void onFrameAvailable(); @@ -394,7 +381,7 @@ private: // protected by mLock mutable Mutex mLock; - // Set to true if an ISurface has been associated with this object. + // Set to true once we've returned this surface's handle mutable bool mHasSurface; const wp<Client> mClientRef; }; diff --git a/services/surfaceflinger/LayerDim.cpp b/services/surfaceflinger/LayerDim.cpp index 23decff..36bafdb 100644 --- a/services/surfaceflinger/LayerDim.cpp +++ b/services/surfaceflinger/LayerDim.cpp @@ -33,8 +33,9 @@ namespace android { // --------------------------------------------------------------------------- -LayerDim::LayerDim(SurfaceFlinger* flinger, const sp<Client>& client) - : Layer(flinger, client) { +LayerDim::LayerDim(SurfaceFlinger* flinger, const sp<Client>& client, + const String8& name, uint32_t w, uint32_t h, uint32_t flags) + : Layer(flinger, client, name, w, h, flags) { } LayerDim::~LayerDim() { @@ -69,19 +70,6 @@ void LayerDim::onDraw(const sp<const DisplayDevice>& hw, const Region& clip) con } } -sp<ISurface> LayerDim::createSurface() -{ - class BSurface : public BnSurface, public LayerCleaner { - virtual sp<IGraphicBufferProducer> getSurfaceTexture() const { return 0; } - public: - BSurface(const sp<SurfaceFlinger>& flinger, - const sp<Layer>& layer) - : LayerCleaner(flinger, layer) { } - }; - sp<ISurface> sur(new BSurface(mFlinger, this)); - return sur; -} - bool LayerDim::isVisible() const { const Layer::State& s(drawingState()); return !(s.flags & layer_state_t::eLayerHidden) && s.alpha; diff --git a/services/surfaceflinger/LayerDim.h b/services/surfaceflinger/LayerDim.h index e1ea9bd..e19bf52 100644 --- a/services/surfaceflinger/LayerDim.h +++ b/services/surfaceflinger/LayerDim.h @@ -32,7 +32,8 @@ namespace android { class LayerDim : public Layer { public: - LayerDim(SurfaceFlinger* flinger, const sp<Client>& client); + LayerDim(SurfaceFlinger* flinger, const sp<Client>& client, + const String8& name, uint32_t w, uint32_t h, uint32_t flags); virtual ~LayerDim(); virtual void onDraw(const sp<const DisplayDevice>& hw, const Region& clip) const; @@ -44,7 +45,6 @@ public: virtual bool isFixedSize() const { return true; } virtual bool isVisible() const; - virtual sp<ISurface> createSurface(); }; // --------------------------------------------------------------------------- diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp index 184f47e..c0ce659 100644 --- a/services/surfaceflinger/SurfaceFlinger.cpp +++ b/services/surfaceflinger/SurfaceFlinger.cpp @@ -581,11 +581,10 @@ bool SurfaceFlinger::authenticateSurfaceTexture( size_t count = currentLayers.size(); for (size_t i=0 ; i<count ; i++) { const sp<Layer>& layer(currentLayers[i]); - // If this is an instance of Layer (as opposed to, say, LayerDim), - // we will get the consumer interface of SurfaceFlingerConsumer's + // 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(); + sp<IBinder> lbcBinder = layer->getBufferQueue()->asBinder(); if (lbcBinder == surfaceTextureBinder) { return true; } @@ -601,7 +600,7 @@ bool SurfaceFlinger::authenticateSurfaceTexture( size_t purgatorySize = mLayerPurgatory.size(); for (size_t i=0 ; i<purgatorySize ; i++) { const sp<Layer>& layer(mLayerPurgatory.itemAt(i)); - wp<IBinder> lbcBinder = layer->getSurfaceTextureBinder(); + sp<IBinder> lbcBinder = layer->getBufferQueue()->asBinder(); if (lbcBinder == surfaceTextureBinder) { return true; } @@ -1720,7 +1719,7 @@ status_t SurfaceFlinger::purgatorizeLayer_l(const sp<Layer>& layer) // it's possible that we don't find a layer, because it might // have been destroyed already -- this is not technically an error // from the user because there is a race between Client::destroySurface(), - // ~Client() and ~ISurface(). + // ~Client() and ~LayerCleaner(). return (err == NAME_NOT_FOUND) ? status_t(NO_ERROR) : err; } @@ -1924,48 +1923,49 @@ uint32_t SurfaceFlinger::setClientStateLocked( return flags; } -sp<ISurface> SurfaceFlinger::createLayer( +status_t SurfaceFlinger::createLayer( const String8& name, const sp<Client>& client, - uint32_t w, uint32_t h, PixelFormat format, - uint32_t flags) + uint32_t w, uint32_t h, PixelFormat format, uint32_t flags, + sp<IBinder>* handle, sp<IGraphicBufferProducer>* gbp) { - sp<Layer> layer; - sp<ISurface> surfaceHandle; - + //ALOGD("createLayer for (%d x %d), name=%s", w, h, name.string()); if (int32_t(w|h) < 0) { ALOGE("createLayer() failed, w or h is negative (w=%d, h=%d)", int(w), int(h)); - return surfaceHandle; + return BAD_VALUE; } - //ALOGD("createLayer for (%d x %d), name=%s", w, h, name.string()); + status_t result = NO_ERROR; + + sp<Layer> layer; + switch (flags & ISurfaceComposerClient::eFXSurfaceMask) { case ISurfaceComposerClient::eFXSurfaceNormal: - layer = createNormalLayer(client, w, h, flags, format); + result = createNormalLayer(client, + name, w, h, flags, format, + handle, gbp, &layer); break; case ISurfaceComposerClient::eFXSurfaceDim: - layer = createDimLayer(client, w, h, flags); + result = createDimLayer(client, + name, w, h, flags, + handle, gbp, &layer); + break; + default: + result = BAD_VALUE; break; } - if (layer != 0) { - layer->initStates(w, h, flags); - layer->setName(name); - surfaceHandle = layer->getSurface(); - if (surfaceHandle != 0) { - addClientLayer(client, surfaceHandle->asBinder(), layer); - } + if (result == NO_ERROR) { + addClientLayer(client, *handle, layer); setTransactionFlags(eTransactionNeeded); } - - return surfaceHandle; + return result; } -sp<Layer> SurfaceFlinger::createNormalLayer( - const sp<Client>& client, - uint32_t w, uint32_t h, uint32_t flags, - PixelFormat& format) +status_t SurfaceFlinger::createNormalLayer(const sp<Client>& client, + const String8& name, uint32_t w, uint32_t h, uint32_t flags, PixelFormat& format, + sp<IBinder>* handle, sp<IGraphicBufferProducer>* gbp, sp<Layer>* outLayer) { // initialize the surfaces switch (format) { @@ -1987,21 +1987,25 @@ sp<Layer> SurfaceFlinger::createNormalLayer( format = PIXEL_FORMAT_RGBA_8888; #endif - sp<Layer> layer = new Layer(this, client); - status_t err = layer->setBuffers(w, h, format, flags); - if (CC_LIKELY(err != NO_ERROR)) { - ALOGE("createNormalLayer() failed (%s)", strerror(-err)); - layer.clear(); + *outLayer = new Layer(this, client, name, w, h, flags); + status_t err = (*outLayer)->setBuffers(w, h, format, flags); + if (err == NO_ERROR) { + *handle = (*outLayer)->getHandle(); + *gbp = (*outLayer)->getBufferQueue(); } - return layer; + + ALOGE_IF(err, "createNormalLayer() failed (%s)", strerror(-err)); + return err; } -sp<LayerDim> SurfaceFlinger::createDimLayer( - const sp<Client>& client, - uint32_t w, uint32_t h, uint32_t flags) +status_t SurfaceFlinger::createDimLayer(const sp<Client>& client, + const String8& name, uint32_t w, uint32_t h, uint32_t flags, + sp<IBinder>* handle, sp<IGraphicBufferProducer>* gbp, sp<Layer>* outLayer) { - sp<LayerDim> layer = new LayerDim(this, client); - return layer; + *outLayer = new LayerDim(this, client, name, w, h, flags); + *handle = (*outLayer)->getHandle(); + *gbp = (*outLayer)->getBufferQueue(); + return NO_ERROR; } status_t SurfaceFlinger::onLayerRemoved(const sp<Client>& client, const sp<IBinder>& handle) @@ -2030,7 +2034,7 @@ status_t SurfaceFlinger::onLayerRemoved(const sp<Client>& client, const sp<IBind status_t SurfaceFlinger::onLayerDestroyed(const wp<Layer>& layer) { - // called by ~ISurface() when all references are gone + // called by ~LayerCleaner() when all references are gone status_t err = NO_ERROR; sp<Layer> l(layer.promote()); if (l != NULL) { diff --git a/services/surfaceflinger/SurfaceFlinger.h b/services/surfaceflinger/SurfaceFlinger.h index 241a7d6..f124347 100644 --- a/services/surfaceflinger/SurfaceFlinger.h +++ b/services/surfaceflinger/SurfaceFlinger.h @@ -257,14 +257,18 @@ private: /* ------------------------------------------------------------------------ * Layer management */ - sp<ISurface> createLayer(const String8& name, const sp<Client>& client, - uint32_t w, uint32_t h, PixelFormat format, uint32_t flags); - - sp<Layer> createNormalLayer(const sp<Client>& client, - uint32_t w, uint32_t h, uint32_t flags, PixelFormat& format); - - sp<LayerDim> createDimLayer(const sp<Client>& client, - uint32_t w, uint32_t h, uint32_t flags); + status_t createLayer(const String8& name, const sp<Client>& client, + uint32_t w, uint32_t h, PixelFormat format, uint32_t flags, + sp<IBinder>* handle, sp<IGraphicBufferProducer>* gbp); + + status_t createNormalLayer(const sp<Client>& client, const String8& name, + uint32_t w, uint32_t h, uint32_t flags, PixelFormat& format, + sp<IBinder>* outHandle, sp<IGraphicBufferProducer>* outGbp, + sp<Layer>* outLayer); + + status_t createDimLayer(const sp<Client>& client, const String8& name, + uint32_t w, uint32_t h, uint32_t flags, sp<IBinder>* outHandle, + sp<IGraphicBufferProducer>* outGbp, sp<Layer>* outLayer); // called in response to the window-manager calling // ISurfaceComposerClient::destroySurface() |