From 770492cb2b19f6a36ad748cd05fbedfbb9a67dfa Mon Sep 17 00:00:00 2001 From: Mathias Agopian Date: Fri, 28 May 2010 14:22:23 -0700 Subject: more clean-up in preparation of bigger changes the most important change here is the renaming of ISurfaceFlingerClient to ISurfaceComposerClient Change-Id: I94e18b0417f50e06f21377446639c61f65f959b3 --- libs/surfaceflinger_client/Android.mk | 2 +- libs/surfaceflinger_client/ISurfaceComposer.cpp | 4 +- .../ISurfaceComposerClient.cpp | 214 +++++++++++++++++++++ .../ISurfaceFlingerClient.cpp | 214 --------------------- libs/surfaceflinger_client/SharedBufferStack.cpp | 10 +- libs/surfaceflinger_client/Surface.cpp | 11 +- .../SurfaceComposerClient.cpp | 71 ++++--- 7 files changed, 270 insertions(+), 256 deletions(-) create mode 100644 libs/surfaceflinger_client/ISurfaceComposerClient.cpp delete mode 100644 libs/surfaceflinger_client/ISurfaceFlingerClient.cpp (limited to 'libs/surfaceflinger_client') diff --git a/libs/surfaceflinger_client/Android.mk b/libs/surfaceflinger_client/Android.mk index fe85b34..ce3c71a 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 b6f4e24..50495c1 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/ISurfaceComposerClient.cpp b/libs/surfaceflinger_client/ISurfaceComposerClient.cpp new file mode 100644 index 0000000..67c7df8 --- /dev/null +++ b/libs/surfaceflinger_client/ISurfaceComposerClient.cpp @@ -0,0 +1,214 @@ +/* + * 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. + */ + +// tag as surfaceflinger +#define LOG_TAG "SurfaceFlinger" + +#include +#include +#include + +#include +#include +#include +#include + +#include +#include + +#include +#include +#include + +// --------------------------------------------------------------------------- + +/* ideally AID_GRAPHICS would be in a semi-public header + * or there would be a way to map a user/group name to its id + */ +#ifndef AID_GRAPHICS +#define AID_GRAPHICS 1003 +#endif + +#define LIKELY( exp ) (__builtin_expect( (exp) != 0, true )) +#define UNLIKELY( exp ) (__builtin_expect( (exp) != 0, false )) + +// --------------------------------------------------------------------------- + +namespace android { + +enum { + GET_CBLK = IBinder::FIRST_CALL_TRANSACTION, + CREATE_SURFACE, + DESTROY_SURFACE, + SET_STATE +}; + +class BpSurfaceComposerClient : public BpInterface +{ +public: + BpSurfaceComposerClient(const sp& impl) + : BpInterface(impl) + { + } + + virtual sp getControlBlock() const + { + Parcel data, reply; + data.writeInterfaceToken(ISurfaceComposerClient::getInterfaceDescriptor()); + remote()->transact(GET_CBLK, data, &reply); + return interface_cast(reply.readStrongBinder()); + } + + virtual sp createSurface( surface_data_t* params, + int pid, + const String8& name, + DisplayID display, + uint32_t w, + uint32_t h, + PixelFormat format, + uint32_t flags) + { + Parcel data, reply; + data.writeInterfaceToken(ISurfaceComposerClient::getInterfaceDescriptor()); + data.writeInt32(pid); + data.writeString8(name); + data.writeInt32(display); + data.writeInt32(w); + data.writeInt32(h); + data.writeInt32(format); + data.writeInt32(flags); + remote()->transact(CREATE_SURFACE, data, &reply); + params->readFromParcel(reply); + return interface_cast(reply.readStrongBinder()); + } + + virtual status_t destroySurface(SurfaceID sid) + { + Parcel data, reply; + data.writeInterfaceToken(ISurfaceComposerClient::getInterfaceDescriptor()); + data.writeInt32(sid); + remote()->transact(DESTROY_SURFACE, data, &reply); + return reply.readInt32(); + } + + virtual status_t setState(int32_t count, const layer_state_t* states) + { + Parcel data, reply; + data.writeInterfaceToken(ISurfaceComposerClient::getInterfaceDescriptor()); + data.writeInt32(count); + for (int i=0 ; itransact(SET_STATE, data, &reply); + return reply.readInt32(); + } +}; + +IMPLEMENT_META_INTERFACE(SurfaceComposerClient, "android.ui.ISurfaceComposerClient"); + +// ---------------------------------------------------------------------- + +status_t BnSurfaceComposerClient::onTransact( + uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) +{ + // codes that don't require permission check + + switch(code) { + case GET_CBLK: { + CHECK_INTERFACE(ISurfaceComposerClient, data, reply); + sp ctl(getControlBlock()); + reply->writeStrongBinder(ctl->asBinder()); + return NO_ERROR; + } break; + } + + // these must be checked + + IPCThreadState* ipc = IPCThreadState::self(); + const int pid = ipc->getCallingPid(); + const int uid = ipc->getCallingUid(); + const int self_pid = getpid(); + if (UNLIKELY(pid != self_pid && uid != AID_GRAPHICS)) { + // we're called from a different process, do the real check + if (!checkCallingPermission( + String16("android.permission.ACCESS_SURFACE_FLINGER"))) + { + LOGE("Permission Denial: " + "can't openGlobalTransaction pid=%d, uid=%d", pid, uid); + return PERMISSION_DENIED; + } + } + + switch(code) { + case CREATE_SURFACE: { + CHECK_INTERFACE(ISurfaceComposerClient, data, reply); + surface_data_t params; + int32_t pid = data.readInt32(); + String8 name = data.readString8(); + DisplayID display = data.readInt32(); + uint32_t w = data.readInt32(); + uint32_t h = data.readInt32(); + PixelFormat format = data.readInt32(); + uint32_t flags = data.readInt32(); + sp s = createSurface(¶ms, pid, name, display, w, h, + format, flags); + params.writeToParcel(reply); + reply->writeStrongBinder(s->asBinder()); + return NO_ERROR; + } break; + case DESTROY_SURFACE: { + CHECK_INTERFACE(ISurfaceComposerClient, data, reply); + reply->writeInt32( destroySurface( data.readInt32() ) ); + return NO_ERROR; + } break; + case SET_STATE: { + CHECK_INTERFACE(ISurfaceComposerClient, data, reply); + int32_t count = data.readInt32(); + layer_state_t* states = new layer_state_t[count]; + for (int i=0 ; iwriteInt32(err); + return NO_ERROR; + } break; + default: + return BBinder::onTransact(code, data, reply, flags); + } +} + +// ---------------------------------------------------------------------- + +status_t ISurfaceComposerClient::surface_data_t::readFromParcel(const Parcel& parcel) +{ + token = parcel.readInt32(); + identity = parcel.readInt32(); + width = parcel.readInt32(); + height = parcel.readInt32(); + format = parcel.readInt32(); + return NO_ERROR; +} + +status_t ISurfaceComposerClient::surface_data_t::writeToParcel(Parcel* parcel) const +{ + parcel->writeInt32(token); + parcel->writeInt32(identity); + parcel->writeInt32(width); + parcel->writeInt32(height); + parcel->writeInt32(format); + return NO_ERROR; +} + +}; // namespace android diff --git a/libs/surfaceflinger_client/ISurfaceFlingerClient.cpp b/libs/surfaceflinger_client/ISurfaceFlingerClient.cpp deleted file mode 100644 index def96d7..0000000 --- a/libs/surfaceflinger_client/ISurfaceFlingerClient.cpp +++ /dev/null @@ -1,214 +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. - */ - -// tag as surfaceflinger -#define LOG_TAG "SurfaceFlinger" - -#include -#include -#include - -#include -#include -#include -#include - -#include -#include - -#include -#include -#include - -// --------------------------------------------------------------------------- - -/* ideally AID_GRAPHICS would be in a semi-public header - * or there would be a way to map a user/group name to its id - */ -#ifndef AID_GRAPHICS -#define AID_GRAPHICS 1003 -#endif - -#define LIKELY( exp ) (__builtin_expect( (exp) != 0, true )) -#define UNLIKELY( exp ) (__builtin_expect( (exp) != 0, false )) - -// --------------------------------------------------------------------------- - -namespace android { - -enum { - GET_CBLK = IBinder::FIRST_CALL_TRANSACTION, - CREATE_SURFACE, - DESTROY_SURFACE, - SET_STATE -}; - -class BpSurfaceFlingerClient : public BpInterface -{ -public: - BpSurfaceFlingerClient(const sp& impl) - : BpInterface(impl) - { - } - - virtual sp getControlBlock() const - { - Parcel data, reply; - data.writeInterfaceToken(ISurfaceFlingerClient::getInterfaceDescriptor()); - remote()->transact(GET_CBLK, data, &reply); - return interface_cast(reply.readStrongBinder()); - } - - virtual sp createSurface( surface_data_t* params, - int pid, - const String8& name, - DisplayID display, - uint32_t w, - uint32_t h, - PixelFormat format, - uint32_t flags) - { - Parcel data, reply; - data.writeInterfaceToken(ISurfaceFlingerClient::getInterfaceDescriptor()); - data.writeInt32(pid); - data.writeString8(name); - data.writeInt32(display); - data.writeInt32(w); - data.writeInt32(h); - data.writeInt32(format); - data.writeInt32(flags); - remote()->transact(CREATE_SURFACE, data, &reply); - params->readFromParcel(reply); - return interface_cast(reply.readStrongBinder()); - } - - virtual status_t destroySurface(SurfaceID sid) - { - Parcel data, reply; - data.writeInterfaceToken(ISurfaceFlingerClient::getInterfaceDescriptor()); - data.writeInt32(sid); - remote()->transact(DESTROY_SURFACE, data, &reply); - return reply.readInt32(); - } - - virtual status_t setState(int32_t count, const layer_state_t* states) - { - Parcel data, reply; - data.writeInterfaceToken(ISurfaceFlingerClient::getInterfaceDescriptor()); - data.writeInt32(count); - for (int i=0 ; itransact(SET_STATE, data, &reply); - return reply.readInt32(); - } -}; - -IMPLEMENT_META_INTERFACE(SurfaceFlingerClient, "android.ui.ISurfaceFlingerClient"); - -// ---------------------------------------------------------------------- - -status_t BnSurfaceFlingerClient::onTransact( - uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) -{ - // codes that don't require permission check - - switch(code) { - case GET_CBLK: { - CHECK_INTERFACE(ISurfaceFlingerClient, data, reply); - sp ctl(getControlBlock()); - reply->writeStrongBinder(ctl->asBinder()); - return NO_ERROR; - } break; - } - - // these must be checked - - IPCThreadState* ipc = IPCThreadState::self(); - const int pid = ipc->getCallingPid(); - const int uid = ipc->getCallingUid(); - const int self_pid = getpid(); - if (UNLIKELY(pid != self_pid && uid != AID_GRAPHICS)) { - // we're called from a different process, do the real check - if (!checkCallingPermission( - String16("android.permission.ACCESS_SURFACE_FLINGER"))) - { - LOGE("Permission Denial: " - "can't openGlobalTransaction pid=%d, uid=%d", pid, uid); - return PERMISSION_DENIED; - } - } - - switch(code) { - case CREATE_SURFACE: { - CHECK_INTERFACE(ISurfaceFlingerClient, data, reply); - surface_data_t params; - int32_t pid = data.readInt32(); - String8 name = data.readString8(); - DisplayID display = data.readInt32(); - uint32_t w = data.readInt32(); - uint32_t h = data.readInt32(); - PixelFormat format = data.readInt32(); - uint32_t flags = data.readInt32(); - sp s = createSurface(¶ms, pid, name, display, w, h, - format, flags); - params.writeToParcel(reply); - reply->writeStrongBinder(s->asBinder()); - return NO_ERROR; - } break; - case DESTROY_SURFACE: { - CHECK_INTERFACE(ISurfaceFlingerClient, data, reply); - reply->writeInt32( destroySurface( data.readInt32() ) ); - return NO_ERROR; - } break; - case SET_STATE: { - CHECK_INTERFACE(ISurfaceFlingerClient, data, reply); - int32_t count = data.readInt32(); - layer_state_t* states = new layer_state_t[count]; - for (int i=0 ; iwriteInt32(err); - return NO_ERROR; - } break; - default: - return BBinder::onTransact(code, data, reply, flags); - } -} - -// ---------------------------------------------------------------------- - -status_t ISurfaceFlingerClient::surface_data_t::readFromParcel(const Parcel& parcel) -{ - token = parcel.readInt32(); - identity = parcel.readInt32(); - width = parcel.readInt32(); - height = parcel.readInt32(); - format = parcel.readInt32(); - return NO_ERROR; -} - -status_t ISurfaceFlingerClient::surface_data_t::writeToParcel(Parcel* parcel) const -{ - parcel->writeInt32(token); - parcel->writeInt32(identity); - parcel->writeInt32(width); - parcel->writeInt32(height); - parcel->writeInt32(format); - return NO_ERROR; -} - -}; // namespace android diff --git a/libs/surfaceflinger_client/SharedBufferStack.cpp b/libs/surfaceflinger_client/SharedBufferStack.cpp index 2577dc0..8d03145 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 35a4e8b..ac4b198 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 8d39c85..0670d20 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(); } // ---------------------------------------------------------------------------- -- cgit v1.1