From 4d9b822e2c18142e55fe2611aa6cd7dc7d4a62c6 Mon Sep 17 00:00:00 2001 From: Mathias Agopian Date: Tue, 12 Mar 2013 17:11:48 -0700 Subject: [PATCH] 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 --- include/gui/ISurface.h | 62 --------- include/gui/ISurfaceComposerClient.h | 10 +- include/gui/SurfaceControl.h | 10 +- include/private/gui/LayerState.h | 1 - libs/gui/Android.mk | 1 - libs/gui/ISurface.cpp | 66 ---------- libs/gui/ISurfaceComposerClient.cpp | 31 ++--- libs/gui/SurfaceComposerClient.cpp | 15 ++- libs/gui/SurfaceControl.cpp | 44 +++---- services/surfaceflinger/Client.cpp | 29 +++-- services/surfaceflinger/Client.h | 7 +- services/surfaceflinger/Layer.cpp | 139 +++++++++------------ services/surfaceflinger/Layer.h | 29 ++--- services/surfaceflinger/LayerDim.cpp | 18 +-- services/surfaceflinger/LayerDim.h | 4 +- services/surfaceflinger/SurfaceFlinger.cpp | 84 +++++++------ services/surfaceflinger/SurfaceFlinger.h | 16 ++- 17 files changed, 207 insertions(+), 359 deletions(-) delete mode 100644 include/gui/ISurface.h delete mode 100644 libs/gui/ISurface.cpp diff --git a/include/gui/ISurface.h b/include/gui/ISurface.h deleted file mode 100644 index 5a928f20b..000000000 --- a/include/gui/ISurface.h +++ /dev/null @@ -1,62 +0,0 @@ -/* - * 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. - */ - -#ifndef ANDROID_GUI_ISURFACE_H -#define ANDROID_GUI_ISURFACE_H - -#include -#include - -#include -#include - -#include - -#include - -namespace android { - -class IGraphicBufferProducer; - -class ISurface : public IInterface -{ -protected: - enum { - GET_SURFACE_TEXTURE = IBinder::FIRST_CALL_TRANSACTION, - }; - -public: - DECLARE_META_INTERFACE(Surface); - - virtual sp getSurfaceTexture() const = 0; -}; - -// ---------------------------------------------------------------------------- - -class BnSurface : public BnInterface -{ -public: - virtual status_t onTransact( uint32_t code, - const Parcel& data, - Parcel* reply, - uint32_t flags = 0); -}; - -// ---------------------------------------------------------------------------- - -}; // namespace android - -#endif // ANDROID_GUI_ISURFACE_H diff --git a/include/gui/ISurfaceComposerClient.h b/include/gui/ISurfaceComposerClient.h index 4afc86032..cb9816fb2 100644 --- a/include/gui/ISurfaceComposerClient.h +++ b/include/gui/ISurfaceComposerClient.h @@ -27,11 +27,11 @@ #include -#include - namespace android { // ---------------------------------------------------------------------------- +class IGraphicBufferProducer; + class ISurfaceComposerClient : public IInterface { public: @@ -55,9 +55,11 @@ public: /* * Requires ACCESS_SURFACE_FLINGER permission */ - virtual sp createSurface( + virtual status_t createSurface( const String8& name, uint32_t w, uint32_t h, - PixelFormat format, uint32_t flags) = 0; + PixelFormat format, uint32_t flags, + sp* handle, + sp* gbp) = 0; /* * Requires ACCESS_SURFACE_FLINGER permission diff --git a/include/gui/SurfaceControl.h b/include/gui/SurfaceControl.h index f70888ddf..fe8eb6f19 100644 --- a/include/gui/SurfaceControl.h +++ b/include/gui/SurfaceControl.h @@ -27,7 +27,6 @@ #include #include -#include #include namespace android { @@ -46,9 +45,11 @@ public: static bool isValid(const sp& surface) { return (surface != 0) && surface->isValid(); } + bool isValid() { - return mSurface!=0 && mClient!=0; + return mHandle!=0 && mClient!=0; } + static bool isSameSurface( const sp& lhs, const sp& rhs); @@ -82,7 +83,8 @@ private: SurfaceControl( const sp& client, - const sp& surface); + const sp& handle, + const sp& gbp); ~SurfaceControl(); @@ -90,7 +92,7 @@ private: void destroy(); sp mClient; - sp mSurface; + sp mHandle; sp mGraphicBufferProducer; mutable Mutex mLock; mutable sp mSurfaceData; diff --git a/include/private/gui/LayerState.h b/include/private/gui/LayerState.h index 0798e170e..bf4bf034f 100644 --- a/include/private/gui/LayerState.h +++ b/include/private/gui/LayerState.h @@ -24,7 +24,6 @@ #include #include -#include namespace android { diff --git a/libs/gui/Android.mk b/libs/gui/Android.mk index 544b66407..5c7bb4cb4 100644 --- a/libs/gui/Android.mk +++ b/libs/gui/Android.mk @@ -17,7 +17,6 @@ LOCAL_SRC_FILES:= \ IGraphicBufferProducer.cpp \ ISensorEventConnection.cpp \ ISensorServer.cpp \ - ISurface.cpp \ ISurfaceComposer.cpp \ ISurfaceComposerClient.cpp \ LayerState.cpp \ diff --git a/libs/gui/ISurface.cpp b/libs/gui/ISurface.cpp deleted file mode 100644 index 8c25f4513..000000000 --- a/libs/gui/ISurface.cpp +++ /dev/null @@ -1,66 +0,0 @@ -/* - * 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. - */ - -#define LOG_TAG "ISurface" - -#include -#include -#include - -#include - -#include -#include - -namespace android { - -// ---------------------------------------------------------------------- - -class BpSurface : public BpInterface -{ -public: - BpSurface(const sp& impl) - : BpInterface(impl) - { - } - - virtual sp getSurfaceTexture() const { - Parcel data, reply; - data.writeInterfaceToken(ISurface::getInterfaceDescriptor()); - remote()->transact(GET_SURFACE_TEXTURE, data, &reply); - return interface_cast(reply.readStrongBinder()); - } -}; - -IMPLEMENT_META_INTERFACE(Surface, "android.ui.ISurface"); - -// ---------------------------------------------------------------------- - -status_t BnSurface::onTransact( - uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) -{ - switch(code) { - case GET_SURFACE_TEXTURE: { - CHECK_INTERFACE(ISurface, data, reply); - reply->writeStrongBinder( getSurfaceTexture()->asBinder() ); - return NO_ERROR; - } - default: - return BBinder::onTransact(code, data, reply, flags); - } -} - -}; // namespace android diff --git a/libs/gui/ISurfaceComposerClient.cpp b/libs/gui/ISurfaceComposerClient.cpp index 101292d94..1adc134e4 100644 --- a/libs/gui/ISurfaceComposerClient.cpp +++ b/libs/gui/ISurfaceComposerClient.cpp @@ -29,7 +29,7 @@ #include #include -#include +#include #include #include @@ -46,16 +46,13 @@ class BpSurfaceComposerClient : public BpInterface { public: BpSurfaceComposerClient(const sp& impl) - : BpInterface(impl) - { + : BpInterface(impl) { } - virtual sp createSurface( const String8& name, - uint32_t w, - uint32_t h, - PixelFormat format, - uint32_t flags) - { + virtual status_t createSurface(const String8& name, uint32_t w, + uint32_t h, PixelFormat format, uint32_t flags, + sp* handle, + sp* gbp) { Parcel data, reply; data.writeInterfaceToken(ISurfaceComposerClient::getInterfaceDescriptor()); data.writeString8(name); @@ -64,11 +61,12 @@ public: data.writeInt32(format); data.writeInt32(flags); remote()->transact(CREATE_SURFACE, data, &reply); - return interface_cast(reply.readStrongBinder()); + *handle = reply.readStrongBinder(); + *gbp = interface_cast(reply.readStrongBinder()); + return reply.readInt32(); } - virtual status_t destroySurface(const sp& handle) - { + virtual status_t destroySurface(const sp& handle) { Parcel data, reply; data.writeInterfaceToken(ISurfaceComposerClient::getInterfaceDescriptor()); data.writeStrongBinder(handle); @@ -92,8 +90,13 @@ status_t BnSurfaceComposerClient::onTransact( uint32_t h = data.readInt32(); PixelFormat format = data.readInt32(); uint32_t flags = data.readInt32(); - sp s = createSurface(name, w, h, format, flags); - reply->writeStrongBinder(s->asBinder()); + sp handle; + sp gbp; + status_t result = createSurface(name, w, h, format, flags, + &handle, &gbp); + reply->writeStrongBinder(handle); + reply->writeStrongBinder(gbp->asBinder()); + reply->writeInt32(result); return NO_ERROR; } break; case DESTROY_SURFACE: { diff --git a/libs/gui/SurfaceComposerClient.cpp b/libs/gui/SurfaceComposerClient.cpp index edfa78a35..4a4c0c8df 100644 --- a/libs/gui/SurfaceComposerClient.cpp +++ b/libs/gui/SurfaceComposerClient.cpp @@ -32,7 +32,6 @@ #include #include -#include #include #include #include @@ -471,14 +470,18 @@ sp SurfaceComposerClient::createSurface( PixelFormat format, uint32_t flags) { - sp result; + sp sur; if (mStatus == NO_ERROR) { - sp surface = mClient->createSurface(name, w, h, format, flags); - if (surface != 0) { - result = new SurfaceControl(this, surface); + sp handle; + sp gbp; + status_t err = mClient->createSurface(name, w, h, format, flags, + &handle, &gbp); + ALOGE_IF(err, "SurfaceComposerClient::createSurface error %s", strerror(-err)); + if (err == NO_ERROR) { + sur = new SurfaceControl(this, handle, gbp); } } - return result; + return sur; } sp SurfaceComposerClient::createDisplay(const String8& displayName, diff --git a/libs/gui/SurfaceControl.cpp b/libs/gui/SurfaceControl.cpp index ef52269b0..bb57948d5 100644 --- a/libs/gui/SurfaceControl.cpp +++ b/libs/gui/SurfaceControl.cpp @@ -34,7 +34,6 @@ #include #include -#include #include #include #include @@ -48,13 +47,10 @@ namespace android { SurfaceControl::SurfaceControl( const sp& client, - const sp& surface) - : mClient(client) + const sp& handle, + const sp& gbp) + : mClient(client), mHandle(handle), mGraphicBufferProducer(gbp) { - if (surface != 0) { - mSurface = surface->asBinder(); - mGraphicBufferProducer = surface->getSurfaceTexture(); - } } SurfaceControl::~SurfaceControl() @@ -65,12 +61,12 @@ SurfaceControl::~SurfaceControl() void SurfaceControl::destroy() { if (isValid()) { - mClient->destroySurface(mSurface); + mClient->destroySurface(mHandle); } // clear all references and trigger an IPC now, to make sure things // happen without delay, since these resources are quite heavy. mClient.clear(); - mSurface.clear(); + mHandle.clear(); mGraphicBufferProducer.clear(); IPCThreadState::self()->flushCommands(); } @@ -91,81 +87,81 @@ bool SurfaceControl::isSameSurface( { if (lhs == 0 || rhs == 0) return false; - return lhs->mSurface == rhs->mSurface; + return lhs->mHandle == rhs->mHandle; } status_t SurfaceControl::setLayerStack(int32_t layerStack) { status_t err = validate(); if (err < 0) return err; const sp& client(mClient); - return client->setLayerStack(mSurface, layerStack); + return client->setLayerStack(mHandle, layerStack); } status_t SurfaceControl::setLayer(int32_t layer) { status_t err = validate(); if (err < 0) return err; const sp& client(mClient); - return client->setLayer(mSurface, layer); + return client->setLayer(mHandle, layer); } status_t SurfaceControl::setPosition(int32_t x, int32_t y) { status_t err = validate(); if (err < 0) return err; const sp& client(mClient); - return client->setPosition(mSurface, x, y); + return client->setPosition(mHandle, x, y); } status_t SurfaceControl::setSize(uint32_t w, uint32_t h) { status_t err = validate(); if (err < 0) return err; const sp& client(mClient); - return client->setSize(mSurface, w, h); + return client->setSize(mHandle, w, h); } status_t SurfaceControl::hide() { status_t err = validate(); if (err < 0) return err; const sp& client(mClient); - return client->hide(mSurface); + return client->hide(mHandle); } status_t SurfaceControl::show() { status_t err = validate(); if (err < 0) return err; const sp& client(mClient); - return client->show(mSurface); + return client->show(mHandle); } status_t SurfaceControl::setFlags(uint32_t flags, uint32_t mask) { status_t err = validate(); if (err < 0) return err; const sp& client(mClient); - return client->setFlags(mSurface, flags, mask); + return client->setFlags(mHandle, flags, mask); } status_t SurfaceControl::setTransparentRegionHint(const Region& transparent) { status_t err = validate(); if (err < 0) return err; const sp& client(mClient); - return client->setTransparentRegionHint(mSurface, transparent); + return client->setTransparentRegionHint(mHandle, transparent); } status_t SurfaceControl::setAlpha(float alpha) { status_t err = validate(); if (err < 0) return err; const sp& client(mClient); - return client->setAlpha(mSurface, alpha); + return client->setAlpha(mHandle, alpha); } status_t SurfaceControl::setMatrix(float dsdx, float dtdx, float dsdy, float dtdy) { status_t err = validate(); if (err < 0) return err; const sp& client(mClient); - return client->setMatrix(mSurface, dsdx, dtdx, dsdy, dtdy); + return client->setMatrix(mHandle, dsdx, dtdx, dsdy, dtdy); } status_t SurfaceControl::setCrop(const Rect& crop) { status_t err = validate(); if (err < 0) return err; const sp& client(mClient); - return client->setCrop(mSurface, crop); + return client->setCrop(mHandle, crop); } status_t SurfaceControl::validate() const { - if (mSurface==0 || mClient==0) { - ALOGE("invalid ISurface (%p) or client (%p)", - mSurface.get(), mClient.get()); + if (mHandle==0 || mClient==0) { + ALOGE("invalid handle (%p) or client (%p)", + mHandle.get(), mClient.get()); return NO_INIT; } return NO_ERROR; diff --git a/services/surfaceflinger/Client.cpp b/services/surfaceflinger/Client.cpp index 0575e352d..dd65348ea 100644 --- a/services/surfaceflinger/Client.cpp +++ b/services/surfaceflinger/Client.cpp @@ -105,10 +105,11 @@ status_t Client::onTransact( } -sp 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* handle, + sp* gbp) { /* * createSurface must be called from the GL thread so that it can @@ -116,9 +117,11 @@ sp Client::createSurface( */ class MessageCreateLayer : public MessageBase { - sp result; SurfaceFlinger* flinger; Client* client; + sp* handle; + sp* gbp; + status_t result; const String8& name; uint32_t w, h; PixelFormat format; @@ -126,21 +129,23 @@ sp 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* handle, + sp* gbp) + : flinger(flinger), client(client), + handle(handle), gbp(gbp), + name(name), w(w), h(h), format(format), flags(flags) { } - sp 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 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( msg.get() )->getResult(); } diff --git a/services/surfaceflinger/Client.h b/services/surfaceflinger/Client.h index 4f34b8659..84e649f4f 100644 --- a/services/surfaceflinger/Client.h +++ b/services/surfaceflinger/Client.h @@ -52,10 +52,11 @@ public: private: // ISurfaceComposerClient interface - virtual sp 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* handle, + sp* gbp); virtual status_t destroySurface(const sp& handle); diff --git a/services/surfaceflinger/Layer.cpp b/services/surfaceflinger/Layer.cpp index 44ef0b879..5996c907d 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) +Layer::Layer(SurfaceFlinger* flinger, const sp& 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) { 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 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 Layer::createSurface() { - /* - * 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 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. - */ - class BSurface : public BnSurface, public LayerCleaner { - wp mOwner; - virtual sp getSurfaceTexture() const { - sp res; - sp that( mOwner.promote() ); - if (that != NULL) { - res = that->mSurfaceFlingerConsumer->getBufferQueue(); - } - return res; - } - public: - BSurface(const sp& flinger, - const sp& layer) - : LayerCleaner(flinger, layer), mOwner(layer) { } - }; - sp sur(new BSurface(mFlinger, this)); - return sur; -} - -wp Layer::getSurfaceTextureBinder() const { - return mSurfaceFlingerConsumer->getBufferQueue()->asBinder(); -} - -sp Layer::getSurface() -{ - sp s; +sp Layer::getHandle() { Mutex::Autolock _l(mLock); LOG_ALWAYS_FATAL_IF(mHasSurface, - "Layer::getSurface() has already been called"); + "Layer::getHandle() has already been called"); mHasSurface = true; - s = createSurface(); - return s; + + /* + * 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. + * + * LayerCleaner ensures that mFlinger->onLayerDestroyed() is called for + * this layer when the handle is destroyed. + */ + + class Handle : public BBinder, public LayerCleaner { + wp mOwner; + public: + Handle(const sp& flinger, const sp& layer) + : LayerCleaner(flinger, layer), mOwner(layer) { + } + }; + + return new Handle(mFlinger, this); } +sp Layer::getBufferQueue() const { + return mSurfaceFlingerConsumer->getBufferQueue(); +} + +//virtual sp getSurfaceTexture() const { +// sp res; +// sp 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 5fb6d8b68..6bca9413a 100644 --- a/services/surfaceflinger/Layer.h +++ b/services/surfaceflinger/Layer.h @@ -124,16 +124,12 @@ public: // ----------------------------------------------------------------------- - Layer(SurfaceFlinger* flinger, const sp& client); + Layer(SurfaceFlinger* flinger, const sp& 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 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& hw, LayerMesh* mesh) const; Rect computeBounds() const; + sp getHandle(); + sp 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& hw, HWComposer::HWCLayerInterface& layer); virtual void setPerFrameData(const sp& hw, @@ -277,8 +269,6 @@ public: virtual void onRemoved(); - virtual wp getSurfaceTextureBinder() const; - // Updates the transform hint in our SurfaceFlingerConsumer to match // the current orientation of the display device. virtual void updateTransformHint(const sp& hw) const; @@ -336,9 +326,6 @@ protected: private: - // Creates an instance of ISurface for this Layer. - virtual sp 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 mClientRef; }; diff --git a/services/surfaceflinger/LayerDim.cpp b/services/surfaceflinger/LayerDim.cpp index 23decffe9..36bafdb10 100644 --- a/services/surfaceflinger/LayerDim.cpp +++ b/services/surfaceflinger/LayerDim.cpp @@ -33,8 +33,9 @@ namespace android { // --------------------------------------------------------------------------- -LayerDim::LayerDim(SurfaceFlinger* flinger, const sp& client) - : Layer(flinger, client) { +LayerDim::LayerDim(SurfaceFlinger* flinger, const sp& 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& hw, const Region& clip) con } } -sp LayerDim::createSurface() -{ - class BSurface : public BnSurface, public LayerCleaner { - virtual sp getSurfaceTexture() const { return 0; } - public: - BSurface(const sp& flinger, - const sp& layer) - : LayerCleaner(flinger, layer) { } - }; - sp 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 e1ea9bdf5..e19bf52d6 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); + LayerDim(SurfaceFlinger* flinger, const sp& client, + const String8& name, uint32_t w, uint32_t h, uint32_t flags); virtual ~LayerDim(); virtual void onDraw(const sp& hw, const Region& clip) const; @@ -44,7 +45,6 @@ public: virtual bool isFixedSize() const { return true; } virtual bool isVisible() const; - virtual sp createSurface(); }; // --------------------------------------------------------------------------- diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp index 184f47e91..c0ce6590d 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& 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 lbcBinder = layer->getSurfaceTextureBinder(); + sp 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& layer(mLayerPurgatory.itemAt(i)); - wp lbcBinder = layer->getSurfaceTextureBinder(); + sp lbcBinder = layer->getBufferQueue()->asBinder(); if (lbcBinder == surfaceTextureBinder) { return true; } @@ -1720,7 +1719,7 @@ status_t SurfaceFlinger::purgatorizeLayer_l(const sp& 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 SurfaceFlinger::createLayer( +status_t SurfaceFlinger::createLayer( const String8& name, const sp& client, - uint32_t w, uint32_t h, PixelFormat format, - uint32_t flags) + uint32_t w, uint32_t h, PixelFormat format, uint32_t flags, + sp* handle, sp* gbp) { - sp layer; - sp 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; + 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 SurfaceFlinger::createNormalLayer( - const sp& client, - uint32_t w, uint32_t h, uint32_t flags, - PixelFormat& format) +status_t SurfaceFlinger::createNormalLayer(const sp& client, + const String8& name, uint32_t w, uint32_t h, uint32_t flags, PixelFormat& format, + sp* handle, sp* gbp, sp* outLayer) { // initialize the surfaces switch (format) { @@ -1987,21 +1987,25 @@ sp SurfaceFlinger::createNormalLayer( format = PIXEL_FORMAT_RGBA_8888; #endif - sp 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 SurfaceFlinger::createDimLayer( - const sp& client, - uint32_t w, uint32_t h, uint32_t flags) +status_t SurfaceFlinger::createDimLayer(const sp& client, + const String8& name, uint32_t w, uint32_t h, uint32_t flags, + sp* handle, sp* gbp, sp* outLayer) { - sp 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, const sp& handle) @@ -2030,7 +2034,7 @@ status_t SurfaceFlinger::onLayerRemoved(const sp& client, const sp& layer) { - // called by ~ISurface() when all references are gone + // called by ~LayerCleaner() when all references are gone status_t err = NO_ERROR; sp l(layer.promote()); if (l != NULL) { diff --git a/services/surfaceflinger/SurfaceFlinger.h b/services/surfaceflinger/SurfaceFlinger.h index 241a7d635..f12434792 100644 --- a/services/surfaceflinger/SurfaceFlinger.h +++ b/services/surfaceflinger/SurfaceFlinger.h @@ -257,14 +257,18 @@ private: /* ------------------------------------------------------------------------ * Layer management */ - sp createLayer(const String8& name, const sp& client, - uint32_t w, uint32_t h, PixelFormat format, uint32_t flags); + status_t createLayer(const String8& name, const sp& client, + uint32_t w, uint32_t h, PixelFormat format, uint32_t flags, + sp* handle, sp* gbp); - sp createNormalLayer(const sp& client, - uint32_t w, uint32_t h, uint32_t flags, PixelFormat& format); + status_t createNormalLayer(const sp& client, const String8& name, + uint32_t w, uint32_t h, uint32_t flags, PixelFormat& format, + sp* outHandle, sp* outGbp, + sp* outLayer); - sp createDimLayer(const sp& client, - uint32_t w, uint32_t h, uint32_t flags); + status_t createDimLayer(const sp& client, const String8& name, + uint32_t w, uint32_t h, uint32_t flags, sp* outHandle, + sp* outGbp, sp* outLayer); // called in response to the window-manager calling // ISurfaceComposerClient::destroySurface()