From 7e27f05739c8a2655cf0f7faea35614ce0a50278 Mon Sep 17 00:00:00 2001 From: Mathias Agopian Date: Fri, 28 May 2010 14:22:23 -0700 Subject: [PATCH] more clean-up in preparation of bigger changes the most important change here is the renaming of ISurfaceFlingerClient to ISurfaceComposerClient Change-Id: I94e18b0417f50e06f21377446639c61f65f959b3 --- .../surfaceflinger/SharedBufferStack.h | 3 +- include/surfaceflinger/ISurface.h | 14 ++++ include/surfaceflinger/ISurfaceComposer.h | 4 +- ...ingerClient.h => ISurfaceComposerClient.h} | 22 +++--- include/surfaceflinger/Surface.h | 4 +- .../surfaceflinger/SurfaceComposerClient.h | 4 +- libs/surfaceflinger/LayerBase.h | 2 +- libs/surfaceflinger/SurfaceFlinger.cpp | 6 +- libs/surfaceflinger/SurfaceFlinger.h | 10 +-- libs/surfaceflinger_client/Android.mk | 2 +- .../ISurfaceComposer.cpp | 4 +- ...rClient.cpp => ISurfaceComposerClient.cpp} | 38 +++++----- .../SharedBufferStack.cpp | 10 +-- libs/surfaceflinger_client/Surface.cpp | 11 ++- .../SurfaceComposerClient.cpp | 71 +++++++++++-------- 15 files changed, 116 insertions(+), 89 deletions(-) rename include/surfaceflinger/{ISurfaceFlingerClient.h => ISurfaceComposerClient.h} (86%) rename libs/surfaceflinger_client/{ISurfaceFlingerClient.cpp => ISurfaceComposerClient.cpp} (83%) diff --git a/include/private/surfaceflinger/SharedBufferStack.h b/include/private/surfaceflinger/SharedBufferStack.h index b859e78b7..dcce25e92 100644 --- a/include/private/surfaceflinger/SharedBufferStack.h +++ b/include/private/surfaceflinger/SharedBufferStack.h @@ -136,9 +136,7 @@ class SharedClient public: SharedClient(); ~SharedClient(); - status_t validate(size_t token) const; - uint32_t getIdentity(size_t token) const; private: friend class SharedBufferBase; @@ -160,6 +158,7 @@ public: int32_t identity); ~SharedBufferBase(); status_t getStatus() const; + int32_t getIdentity() const; size_t getFrontBuffer() const; String8 dump(char const* prefix) const; diff --git a/include/surfaceflinger/ISurface.h b/include/surfaceflinger/ISurface.h index 18e7950bc..ddbe03dbc 100644 --- a/include/surfaceflinger/ISurface.h +++ b/include/surfaceflinger/ISurface.h @@ -53,10 +53,24 @@ protected: public: DECLARE_META_INTERFACE(Surface); + /* + * requests a new buffer for the given index. If w, h, or format are + * null the buffer is created with the parameters assigned to the + * surface it is bound to. Otherwise the buffer's parameters are + * set to those specified. + */ virtual sp requestBuffer(int bufferIdx, uint32_t w, uint32_t h, uint32_t format, uint32_t usage) = 0; + + /* + * sets the number of buffers dequeuable for this surface. + */ virtual status_t setBufferCount(int bufferCount) = 0; + // ------------------------------------------------------------------------ + // Deprecated... + // ------------------------------------------------------------------------ + class BufferHeap { public: enum { diff --git a/include/surfaceflinger/ISurfaceComposer.h b/include/surfaceflinger/ISurfaceComposer.h index d1e7785cc..3271cfd47 100644 --- a/include/surfaceflinger/ISurfaceComposer.h +++ b/include/surfaceflinger/ISurfaceComposer.h @@ -27,7 +27,7 @@ #include -#include +#include namespace android { // ---------------------------------------------------------------------------- @@ -86,7 +86,7 @@ public: * ACCESS_SURFACE_FLINGER permission */ - virtual sp createConnection() = 0; + virtual sp createConnection() = 0; /* retrieve the control block */ virtual sp getCblk() const = 0; diff --git a/include/surfaceflinger/ISurfaceFlingerClient.h b/include/surfaceflinger/ISurfaceComposerClient.h similarity index 86% rename from include/surfaceflinger/ISurfaceFlingerClient.h rename to include/surfaceflinger/ISurfaceComposerClient.h index c96432feb..b2a4766bc 100644 --- a/include/surfaceflinger/ISurfaceFlingerClient.h +++ b/include/surfaceflinger/ISurfaceComposerClient.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef ANDROID_SF_ISURFACE_FLINGER_CLIENT_H -#define ANDROID_SF_ISURFACE_FLINGER_CLIENT_H +#ifndef ANDROID_SF_ISURFACE_COMPOSER_CLIENT_H +#define ANDROID_SF_ISURFACE_COMPOSER_CLIENT_H #include #include @@ -26,7 +26,7 @@ #include #include - + #include namespace android { @@ -42,10 +42,10 @@ typedef int32_t DisplayID; class layer_state_t; -class ISurfaceFlingerClient : public IInterface +class ISurfaceComposerClient : public IInterface { -public: - DECLARE_META_INTERFACE(SurfaceFlingerClient); +public: + DECLARE_META_INTERFACE(SurfaceComposerClient); struct surface_data_t { int32_t token; @@ -56,21 +56,21 @@ public: status_t readFromParcel(const Parcel& parcel); status_t writeToParcel(Parcel* parcel) const; }; - + virtual sp getControlBlock() const = 0; /* * Requires ACCESS_SURFACE_FLINGER permission */ virtual sp createSurface( surface_data_t* data, - int pid, + int pid, const String8& name, DisplayID display, uint32_t w, uint32_t h, PixelFormat format, uint32_t flags) = 0; - + /* * Requires ACCESS_SURFACE_FLINGER permission */ @@ -84,7 +84,7 @@ public: // ---------------------------------------------------------------------------- -class BnSurfaceFlingerClient : public BnInterface +class BnSurfaceComposerClient : public BnInterface { public: virtual status_t onTransact( uint32_t code, @@ -97,4 +97,4 @@ public: }; // namespace android -#endif // ANDROID_SF_ISURFACE_FLINGER_CLIENT_H +#endif // ANDROID_SF_ISURFACE_COMPOSER_CLIENT_H diff --git a/include/surfaceflinger/Surface.h b/include/surfaceflinger/Surface.h index 33269cbea..295797066 100644 --- a/include/surfaceflinger/Surface.h +++ b/include/surfaceflinger/Surface.h @@ -28,7 +28,7 @@ #include #include -#include +#include #define ANDROID_VIEW_SURFACE_JNI_ID "mNativeSurface" @@ -108,7 +108,7 @@ private: SurfaceControl( const sp& client, const sp& surface, - const ISurfaceFlingerClient::surface_data_t& data, + const ISurfaceComposerClient::surface_data_t& data, uint32_t w, uint32_t h, PixelFormat format, uint32_t flags); ~SurfaceControl(); diff --git a/include/surfaceflinger/SurfaceComposerClient.h b/include/surfaceflinger/SurfaceComposerClient.h index 102aebc6f..8e28a815b 100644 --- a/include/surfaceflinger/SurfaceComposerClient.h +++ b/include/surfaceflinger/SurfaceComposerClient.h @@ -149,7 +149,7 @@ private: // these don't need to be protected because they never change // after assignment status_t mStatus; - sp mClient; + sp mClient; }; // --------------------------------------------------------------------------- @@ -161,7 +161,7 @@ class SurfaceClient : public RefBase SharedClient* mControl; sp mControlMemory; sp mConnection; - sp mSignalServer; + sp mComposerService; void init(const sp& conn); public: explicit SurfaceClient(const sp& conn); diff --git a/libs/surfaceflinger/LayerBase.h b/libs/surfaceflinger/LayerBase.h index a78424ea5..2e2f2df89 100644 --- a/libs/surfaceflinger/LayerBase.h +++ b/libs/surfaceflinger/LayerBase.h @@ -29,7 +29,7 @@ #include #include -#include +#include #include #include diff --git a/libs/surfaceflinger/SurfaceFlinger.cpp b/libs/surfaceflinger/SurfaceFlinger.cpp index 5a6893f18..fff085392 100644 --- a/libs/surfaceflinger/SurfaceFlinger.cpp +++ b/libs/surfaceflinger/SurfaceFlinger.cpp @@ -225,7 +225,7 @@ sp SurfaceFlinger::getCblk() const return mServerHeap; } -sp SurfaceFlinger::createConnection() +sp SurfaceFlinger::createConnection() { Mutex::Autolock _l(mStateLock); uint32_t token = mTokens.acquire(); @@ -1230,7 +1230,7 @@ int SurfaceFlinger::setOrientation(DisplayID dpy, } sp SurfaceFlinger::createSurface(ClientID clientId, int pid, - const String8& name, ISurfaceFlingerClient::surface_data_t* params, + const String8& name, ISurfaceComposerClient::surface_data_t* params, DisplayID d, uint32_t w, uint32_t h, PixelFormat format, uint32_t flags) { @@ -1740,7 +1740,7 @@ sp BClient::getControlBlock() const { } sp BClient::createSurface( - ISurfaceFlingerClient::surface_data_t* params, int pid, + ISurfaceComposerClient::surface_data_t* params, int pid, const String8& name, DisplayID display, uint32_t w, uint32_t h, PixelFormat format, uint32_t flags) diff --git a/libs/surfaceflinger/SurfaceFlinger.h b/libs/surfaceflinger/SurfaceFlinger.h index 2558324d9..d8fe98cf1 100644 --- a/libs/surfaceflinger/SurfaceFlinger.h +++ b/libs/surfaceflinger/SurfaceFlinger.h @@ -32,7 +32,7 @@ #include #include -#include +#include #include "Barrier.h" #include "Layer.h" @@ -158,7 +158,7 @@ public: virtual status_t dump(int fd, const Vector& args); // ISurfaceComposer interface - virtual sp createConnection(); + virtual sp createConnection(); virtual sp getCblk() const; virtual void bootFinished(); virtual void openGlobalTransaction(); @@ -189,7 +189,7 @@ private: friend class LayerDim; sp createSurface(ClientID client, int pid, const String8& name, - ISurfaceFlingerClient::surface_data_t* params, + ISurfaceComposerClient::surface_data_t* params, DisplayID display, uint32_t w, uint32_t h, PixelFormat format, uint32_t flags); @@ -393,14 +393,14 @@ public: // --------------------------------------------------------------------------- -class BClient : public BnSurfaceFlingerClient +class BClient : public BnSurfaceComposerClient { public: BClient(SurfaceFlinger *flinger, ClientID cid, const sp& cblk); ~BClient(); - // ISurfaceFlingerClient interface + // ISurfaceComposerClient interface virtual sp getControlBlock() const; virtual sp createSurface( diff --git a/libs/surfaceflinger_client/Android.mk b/libs/surfaceflinger_client/Android.mk index fe85b3498..ce3c71a7d 100644 --- a/libs/surfaceflinger_client/Android.mk +++ b/libs/surfaceflinger_client/Android.mk @@ -4,7 +4,7 @@ include $(CLEAR_VARS) LOCAL_SRC_FILES:= \ ISurfaceComposer.cpp \ ISurface.cpp \ - ISurfaceFlingerClient.cpp \ + ISurfaceComposerClient.cpp \ LayerState.cpp \ SharedBufferStack.cpp \ Surface.cpp \ diff --git a/libs/surfaceflinger_client/ISurfaceComposer.cpp b/libs/surfaceflinger_client/ISurfaceComposer.cpp index b6f4e24a2..50495c16b 100644 --- a/libs/surfaceflinger_client/ISurfaceComposer.cpp +++ b/libs/surfaceflinger_client/ISurfaceComposer.cpp @@ -46,13 +46,13 @@ public: { } - virtual sp createConnection() + virtual sp createConnection() { uint32_t n; Parcel data, reply; data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor()); remote()->transact(BnSurfaceComposer::CREATE_CONNECTION, data, &reply); - return interface_cast(reply.readStrongBinder()); + return interface_cast(reply.readStrongBinder()); } virtual sp getCblk() const diff --git a/libs/surfaceflinger_client/ISurfaceFlingerClient.cpp b/libs/surfaceflinger_client/ISurfaceComposerClient.cpp similarity index 83% rename from libs/surfaceflinger_client/ISurfaceFlingerClient.cpp rename to libs/surfaceflinger_client/ISurfaceComposerClient.cpp index def96d70f..67c7df815 100644 --- a/libs/surfaceflinger_client/ISurfaceFlingerClient.cpp +++ b/libs/surfaceflinger_client/ISurfaceComposerClient.cpp @@ -30,7 +30,7 @@ #include #include -#include +#include #include // --------------------------------------------------------------------------- @@ -56,18 +56,18 @@ enum { SET_STATE }; -class BpSurfaceFlingerClient : public BpInterface +class BpSurfaceComposerClient : public BpInterface { public: - BpSurfaceFlingerClient(const sp& impl) - : BpInterface(impl) + BpSurfaceComposerClient(const sp& impl) + : BpInterface(impl) { } virtual sp getControlBlock() const { Parcel data, reply; - data.writeInterfaceToken(ISurfaceFlingerClient::getInterfaceDescriptor()); + data.writeInterfaceToken(ISurfaceComposerClient::getInterfaceDescriptor()); remote()->transact(GET_CBLK, data, &reply); return interface_cast(reply.readStrongBinder()); } @@ -82,7 +82,7 @@ public: uint32_t flags) { Parcel data, reply; - data.writeInterfaceToken(ISurfaceFlingerClient::getInterfaceDescriptor()); + data.writeInterfaceToken(ISurfaceComposerClient::getInterfaceDescriptor()); data.writeInt32(pid); data.writeString8(name); data.writeInt32(display); @@ -94,11 +94,11 @@ public: params->readFromParcel(reply); return interface_cast(reply.readStrongBinder()); } - + virtual status_t destroySurface(SurfaceID sid) { Parcel data, reply; - data.writeInterfaceToken(ISurfaceFlingerClient::getInterfaceDescriptor()); + data.writeInterfaceToken(ISurfaceComposerClient::getInterfaceDescriptor()); data.writeInt32(sid); remote()->transact(DESTROY_SURFACE, data, &reply); return reply.readInt32(); @@ -107,7 +107,7 @@ public: virtual status_t setState(int32_t count, const layer_state_t* states) { Parcel data, reply; - data.writeInterfaceToken(ISurfaceFlingerClient::getInterfaceDescriptor()); + data.writeInterfaceToken(ISurfaceComposerClient::getInterfaceDescriptor()); data.writeInt32(count); for (int i=0 ; i ctl(getControlBlock()); reply->writeStrongBinder(ctl->asBinder()); return NO_ERROR; @@ -135,7 +135,7 @@ status_t BnSurfaceFlingerClient::onTransact( } // these must be checked - + IPCThreadState* ipc = IPCThreadState::self(); const int pid = ipc->getCallingPid(); const int uid = ipc->getCallingUid(); @@ -150,10 +150,10 @@ status_t BnSurfaceFlingerClient::onTransact( return PERMISSION_DENIED; } } - + switch(code) { case CREATE_SURFACE: { - CHECK_INTERFACE(ISurfaceFlingerClient, data, reply); + CHECK_INTERFACE(ISurfaceComposerClient, data, reply); surface_data_t params; int32_t pid = data.readInt32(); String8 name = data.readString8(); @@ -169,12 +169,12 @@ status_t BnSurfaceFlingerClient::onTransact( return NO_ERROR; } break; case DESTROY_SURFACE: { - CHECK_INTERFACE(ISurfaceFlingerClient, data, reply); + CHECK_INTERFACE(ISurfaceComposerClient, data, reply); reply->writeInt32( destroySurface( data.readInt32() ) ); return NO_ERROR; } break; case SET_STATE: { - CHECK_INTERFACE(ISurfaceFlingerClient, data, reply); + CHECK_INTERFACE(ISurfaceComposerClient, data, reply); int32_t count = data.readInt32(); layer_state_t* states = new layer_state_t[count]; for (int i=0 ; iwriteInt32(token); parcel->writeInt32(identity); diff --git a/libs/surfaceflinger_client/SharedBufferStack.cpp b/libs/surfaceflinger_client/SharedBufferStack.cpp index 2577dc00e..8d031453b 100644 --- a/libs/surfaceflinger_client/SharedBufferStack.cpp +++ b/libs/surfaceflinger_client/SharedBufferStack.cpp @@ -49,10 +49,6 @@ status_t SharedClient::validate(size_t i) const { return surfaces[i].status; } -uint32_t SharedClient::getIdentity(size_t token) const { - return uint32_t(surfaces[token].identity); -} - // ---------------------------------------------------------------------------- @@ -161,6 +157,12 @@ status_t SharedBufferBase::getStatus() const return stack.status; } +int32_t SharedBufferBase::getIdentity() const +{ + SharedBufferStack& stack( *mSharedStack ); + return stack.identity; +} + size_t SharedBufferBase::getFrontBuffer() const { SharedBufferStack& stack( *mSharedStack ); diff --git a/libs/surfaceflinger_client/Surface.cpp b/libs/surfaceflinger_client/Surface.cpp index 35a4e8bd0..ac4b19839 100644 --- a/libs/surfaceflinger_client/Surface.cpp +++ b/libs/surfaceflinger_client/Surface.cpp @@ -104,7 +104,7 @@ static status_t copyBlt( SurfaceControl::SurfaceControl( const sp& client, const sp& surface, - const ISurfaceFlingerClient::surface_data_t& data, + const ISurfaceComposerClient::surface_data_t& data, uint32_t w, uint32_t h, PixelFormat format, uint32_t flags) : mClient(client), mSurface(surface), mToken(data.token), mIdentity(data.identity), @@ -278,7 +278,6 @@ sp SurfaceControl::getSurface() const // Surface // ============================================================================ - Surface::Surface(const sp& surface) : mSurface(surface->mSurface), mToken(surface->mToken), mIdentity(surface->mIdentity), @@ -369,7 +368,7 @@ status_t Surface::initCheck() const LOGE("cblk is null (surface id=%d, identity=%u)", mToken, mIdentity); return NO_INIT; } - return NO_ERROR; + return cblk->validate(mToken); } bool Surface::isValid() { @@ -386,9 +385,7 @@ status_t Surface::validate() const } // verify the identity of this surface - SharedClient const* cblk = mClient->getSharedClient(); - - uint32_t identity = cblk->getIdentity(mToken); + uint32_t identity = mSharedBufferClient->getIdentity(); // this is a bit of a (temporary) special case, identity==0 means that // no operation are allowed from the client (eg: dequeue/queue), this @@ -406,7 +403,7 @@ status_t Surface::validate() const } // check the surface didn't become invalid - status_t err = cblk->validate(mToken); + status_t err = mSharedBufferClient->getStatus(); if (err != NO_ERROR) { LOGE("surface (id=%d, identity=%u) is invalid, err=%d (%s)", mToken, mIdentity, err, strerror(-err)); diff --git a/libs/surfaceflinger_client/SurfaceComposerClient.cpp b/libs/surfaceflinger_client/SurfaceComposerClient.cpp index 8d39c8534..0670d2003 100644 --- a/libs/surfaceflinger_client/SurfaceComposerClient.cpp +++ b/libs/surfaceflinger_client/SurfaceComposerClient.cpp @@ -31,7 +31,7 @@ #include #include -#include +#include #include #include @@ -42,18 +42,14 @@ namespace android { // --------------------------------------------------------------------------- -class Composer : public Singleton +class ComposerService : public Singleton { // these are constants sp mComposerService; sp mServerCblkMemory; surface_flinger_cblk_t volatile* mServerCblk; - Mutex mLock; - SortedVector< wp > mActiveConnections; - SortedVector > mOpenTransactions; - - Composer() : Singleton() { + ComposerService() : Singleton() { const String16 name("SurfaceFlinger"); while (getService(name, &mComposerService) != NO_ERROR) { usleep(250000); @@ -63,6 +59,39 @@ class Composer : public Singleton mServerCblkMemory->getBase()); } + friend class Singleton; + +public: + static sp getComposerService() { + return ComposerService::getInstance().mComposerService; + } + static surface_flinger_cblk_t const volatile * getControlBlock() { + return ComposerService::getInstance().mServerCblk; + } +}; + +ANDROID_SINGLETON_STATIC_INSTANCE(ComposerService); + + +static inline sp getComposerService() { + return ComposerService::getComposerService(); +} + +static inline surface_flinger_cblk_t const volatile * get_cblk() { + return ComposerService::getControlBlock(); +} + +// --------------------------------------------------------------------------- + +class Composer : public Singleton +{ + Mutex mLock; + SortedVector< wp > mActiveConnections; + SortedVector > mOpenTransactions; + + Composer() : Singleton() { + } + void addClientImpl(const sp& client) { Mutex::Autolock _l(mLock); mActiveConnections.add(client); @@ -102,7 +131,7 @@ class Composer : public Singleton mOpenTransactions.clear(); mLock.unlock(); - sp sm(mComposerService); + sp sm(getComposerService()); sm->openGlobalTransaction(); const size_t N = clients.size(); for (size_t i=0; i friend class Singleton; public: - static sp getComposerService() { - return Composer::getInstance().mComposerService; - } - static surface_flinger_cblk_t const volatile * getControlBlock() { - return Composer::getInstance().mServerCblk; - } static void addClient(const sp& client) { Composer::getInstance().addClientImpl(client); } @@ -136,14 +159,6 @@ public: ANDROID_SINGLETON_STATIC_INSTANCE(Composer); -static inline sp getComposerService() { - return Composer::getComposerService(); -} - -static inline surface_flinger_cblk_t const volatile * get_cblk() { - return Composer::getControlBlock(); -} - // --------------------------------------------------------------------------- static inline int compare_type( const layer_state_t& lhs, @@ -162,7 +177,7 @@ void SurfaceComposerClient::onFirstRef() { sp sm(getComposerService()); if (sm != 0) { - sp conn = sm->createConnection(); + sp conn = sm->createConnection(); if (conn != 0) { mClient = conn; Composer::addClient(this); @@ -199,7 +214,7 @@ status_t SurfaceComposerClient::linkToComposerDeath( void SurfaceComposerClient::dispose() { // this can be called more than once. - sp client; + sp client; Mutex::Autolock _lm(mLock); if (mClient != 0) { Composer::removeClient(this); @@ -296,7 +311,7 @@ sp SurfaceComposerClient::createSurface( { sp result; if (mStatus == NO_ERROR) { - ISurfaceFlingerClient::surface_data_t data; + ISurfaceComposerClient::surface_data_t data; sp surface = mClient->createSurface(&data, pid, name, display, w, h, format, flags); if (surface != 0) { @@ -558,8 +573,8 @@ SurfaceClient::SurfaceClient(const sp& conn) } void SurfaceClient::init(const sp& conn) { - mSignalServer = getComposerService(); - sp sf(interface_cast(conn)); + mComposerService = getComposerService(); + sp sf(interface_cast(conn)); if (sf != 0) { mConnection = conn; mControlMemory = sf->getControlBlock(); @@ -574,7 +589,7 @@ SharedClient* SurfaceClient::getSharedClient() const { return mControl; } void SurfaceClient::signalServer() const { - mSignalServer->signal(); + mComposerService->signal(); } // ----------------------------------------------------------------------------