From c666cae2d5995097ec49a87e375e2afdd92802b7 Mon Sep 17 00:00:00 2001 From: Mathias Agopian Date: Wed, 25 Jul 2012 18:56:13 -0700 Subject: [PATCH] get rid of the shared-memory control block Change-Id: If814060aca1d2ff2619d4adcd57296983d207f7f --- include/gui/ISurfaceComposer.h | 10 +-- include/gui/SurfaceComposerClient.h | 6 -- include/private/gui/ComposerService.h | 4 -- include/private/gui/SharedBufferStack.h | 59 ----------------- include/ui/DisplayInfo.h | 22 +++---- libs/gui/ISurfaceComposer.cpp | 32 +++++---- libs/gui/SurfaceComposerClient.cpp | 66 +------------------ services/surfaceflinger/DisplayHardware.cpp | 34 ++++------ services/surfaceflinger/DisplayHardware.h | 2 + services/surfaceflinger/SurfaceFlinger.cpp | 29 +++----- services/surfaceflinger/SurfaceFlinger.h | 7 +- .../surfaceflinger/tests/Transaction_test.cpp | 8 ++- 12 files changed, 69 insertions(+), 210 deletions(-) delete mode 100644 include/private/gui/SharedBufferStack.h diff --git a/include/gui/ISurfaceComposer.h b/include/gui/ISurfaceComposer.h index 0d4a76b89..315a39b8b 100644 --- a/include/gui/ISurfaceComposer.h +++ b/include/gui/ISurfaceComposer.h @@ -35,6 +35,7 @@ namespace android { class ComposerState; class DisplayState; +class DisplayInfo; class IDisplayEventConnection; class IMemoryHeap; @@ -102,9 +103,6 @@ public: */ virtual sp createGraphicBufferAlloc() = 0; - /* retrieve the control block */ - virtual sp getCblk() const = 0; - /* open/close transactions. requires ACCESS_SURFACE_FLINGER permission */ virtual void setTransactionState( const Vector& state, @@ -145,6 +143,10 @@ public: /* triggers screen on and waits for it to complete */ virtual void unblank() = 0; + /* returns information about a physical screen. This is intended to be + * used by low-level native tests */ + virtual status_t getDisplayInfo(DisplayID dpy, DisplayInfo* info) = 0; + /* connects to an external display */ virtual void connectDisplay(const sp display) = 0; }; @@ -160,7 +162,7 @@ public: BOOT_FINISHED = IBinder::FIRST_CALL_TRANSACTION, CREATE_CONNECTION, CREATE_GRAPHIC_BUFFER_ALLOC, - GET_CBLK, + GET_DISPLAY_INFO, SET_TRANSACTION_STATE, SET_ORIENTATION, CAPTURE_SCREEN, diff --git a/include/gui/SurfaceComposerClient.h b/include/gui/SurfaceComposerClient.h index aef422303..b058b8dad 100644 --- a/include/gui/SurfaceComposerClient.h +++ b/include/gui/SurfaceComposerClient.h @@ -97,14 +97,8 @@ public: //! Set the orientation of the given display static int setOrientation(DisplayID dpy, int orientation, uint32_t flags); - // Query the number of displays - static ssize_t getNumberOfDisplays(); - // Get information about a display static status_t getDisplayInfo(DisplayID dpy, DisplayInfo* info); - static ssize_t getDisplayWidth(DisplayID dpy); - static ssize_t getDisplayHeight(DisplayID dpy); - static ssize_t getDisplayOrientation(DisplayID dpy); status_t linkToComposerDeath(const sp& recipient, void* cookie = NULL, uint32_t flags = 0); diff --git a/include/private/gui/ComposerService.h b/include/private/gui/ComposerService.h index d04491a86..c2761b89a 100644 --- a/include/private/gui/ComposerService.h +++ b/include/private/gui/ComposerService.h @@ -30,7 +30,6 @@ namespace android { class IMemoryHeap; class ISurfaceComposer; -class surface_flinger_cblk_t; // --------------------------------------------------------------------------- @@ -38,13 +37,10 @@ class ComposerService : public Singleton { // these are constants sp mComposerService; - sp mServerCblkMemory; - surface_flinger_cblk_t volatile* mServerCblk; ComposerService(); friend class Singleton; public: static sp getComposerService(); - static surface_flinger_cblk_t const volatile * getControlBlock(); }; // --------------------------------------------------------------------------- diff --git a/include/private/gui/SharedBufferStack.h b/include/private/gui/SharedBufferStack.h deleted file mode 100644 index 0da03d134..000000000 --- a/include/private/gui/SharedBufferStack.h +++ /dev/null @@ -1,59 +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_SF_SHARED_BUFFER_STACK_H -#define ANDROID_SF_SHARED_BUFFER_STACK_H - -#include -#include - -#include - -namespace android { -// --------------------------------------------------------------------------- - -#define NUM_DISPLAY_MAX 4 - -struct display_cblk_t -{ - uint16_t w; - uint16_t h; - uint8_t format; - uint8_t orientation; - uint8_t reserved[2]; - float fps; - float density; - float xdpi; - float ydpi; - uint32_t pad[2]; -}; - -struct surface_flinger_cblk_t // 4KB max -{ - uint8_t connected; - uint8_t reserved[3]; - uint32_t pad[7]; - display_cblk_t displays[NUM_DISPLAY_MAX]; -}; - -// --------------------------------------------------------------------------- - -COMPILE_TIME_ASSERT(sizeof(surface_flinger_cblk_t) <= 4096) - -// --------------------------------------------------------------------------- -}; // namespace android - -#endif /* ANDROID_SF_SHARED_BUFFER_STACK_H */ diff --git a/include/ui/DisplayInfo.h b/include/ui/DisplayInfo.h index edd28a6ee..c7dc35484 100644 --- a/include/ui/DisplayInfo.h +++ b/include/ui/DisplayInfo.h @@ -14,7 +14,6 @@ * limitations under the License. */ - #ifndef ANDROID_UI_DISPLAY_INFO_H #define ANDROID_UI_DISPLAY_INFO_H @@ -26,15 +25,16 @@ namespace android { struct DisplayInfo { - uint32_t w; - uint32_t h; - PixelFormatInfo pixelFormatInfo; - uint8_t orientation; - uint8_t reserved[3]; - float fps; - float density; - float xdpi; - float ydpi; + uint32_t w; + uint32_t h; + float xdpi; + float ydpi; + float fps; + float density; + uint8_t orientation; + uint8_t reserved[3]; + // TODO: this needs to go away (currently needed only by webkit) + PixelFormatInfo pixelFormatInfo; }; /* Display orientations as defined in Surface.java and ISurfaceComposer.h. */ @@ -45,8 +45,6 @@ enum { DISPLAY_ORIENTATION_270 = 3 }; - }; // namespace android #endif // ANDROID_COMPOSER_DISPLAY_INFO_H - diff --git a/libs/gui/ISurfaceComposer.cpp b/libs/gui/ISurfaceComposer.cpp index 60341ff26..4cc026205 100644 --- a/libs/gui/ISurfaceComposer.cpp +++ b/libs/gui/ISurfaceComposer.cpp @@ -68,14 +68,6 @@ public: return interface_cast(reply.readStrongBinder()); } - virtual sp getCblk() const - { - Parcel data, reply; - data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor()); - remote()->transact(BnSurfaceComposer::GET_CBLK, data, &reply); - return interface_cast(reply.readStrongBinder()); - } - virtual void setTransactionState( const Vector& state, const Vector& displays, @@ -219,6 +211,17 @@ public: remote()->transact(BnSurfaceComposer::UNBLANK, data, &reply); } + virtual status_t getDisplayInfo(DisplayID dpy, DisplayInfo* info) + { + Parcel data, reply; + data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor()); + data.writeInt32(dpy); + remote()->transact(BnSurfaceComposer::GET_DISPLAY_INFO, data, &reply); + memcpy(info, reply.readInplace(sizeof(DisplayInfo)), sizeof(DisplayInfo)); + return reply.readInt32(); + } + + virtual void connectDisplay(const sp display) { Parcel data, reply; data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor()); @@ -270,11 +273,6 @@ status_t BnSurfaceComposer::onTransact( CHECK_INTERFACE(ISurfaceComposer, data, reply); bootFinished(); } break; - case GET_CBLK: { - CHECK_INTERFACE(ISurfaceComposer, data, reply); - sp b = getCblk()->asBinder(); - reply->writeStrongBinder(b); - } break; case CAPTURE_SCREEN: { CHECK_INTERFACE(ISurfaceComposer, data, reply); DisplayID dpy = data.readInt32(); @@ -326,6 +324,14 @@ status_t BnSurfaceComposer::onTransact( CHECK_INTERFACE(ISurfaceComposer, data, reply); unblank(); } break; + case GET_DISPLAY_INFO: { + CHECK_INTERFACE(ISurfaceComposer, data, reply); + DisplayInfo info; + DisplayID dpy = data.readInt32(); + status_t result = getDisplayInfo(dpy, &info); + memcpy(reply->writeInplace(sizeof(DisplayInfo)), &info, sizeof(DisplayInfo)); + reply->writeInt32(result); + } break; case CONNECT_DISPLAY: { CHECK_INTERFACE(ISurfaceComposer, data, reply); sp surfaceTexture = diff --git a/libs/gui/SurfaceComposerClient.cpp b/libs/gui/SurfaceComposerClient.cpp index 4930e336f..1aecddb1d 100644 --- a/libs/gui/SurfaceComposerClient.cpp +++ b/libs/gui/SurfaceComposerClient.cpp @@ -38,7 +38,6 @@ #include #include -#include namespace android { // --------------------------------------------------------------------------- @@ -51,27 +50,16 @@ ComposerService::ComposerService() while (getService(name, &mComposerService) != NO_ERROR) { usleep(250000); } - mServerCblkMemory = mComposerService->getCblk(); - mServerCblk = static_cast( - mServerCblkMemory->getBase()); } sp ComposerService::getComposerService() { return ComposerService::getInstance().mComposerService; } -surface_flinger_cblk_t const volatile * ComposerService::getControlBlock() { - return ComposerService::getInstance().mServerCblk; -} - static inline sp getComposerService() { return ComposerService::getComposerService(); } -static inline surface_flinger_cblk_t const volatile * get_cblk() { - return ComposerService::getControlBlock(); -} - // --------------------------------------------------------------------------- // NOTE: this is NOT a member function (it's a friend defined with its @@ -476,59 +464,7 @@ status_t SurfaceComposerClient::setOrientation(DisplayID dpy, status_t SurfaceComposerClient::getDisplayInfo( DisplayID dpy, DisplayInfo* info) { - if (uint32_t(dpy)>=NUM_DISPLAY_MAX) - return BAD_VALUE; - - volatile surface_flinger_cblk_t const * cblk = get_cblk(); - volatile display_cblk_t const * dcblk = cblk->displays + dpy; - - info->w = dcblk->w; - info->h = dcblk->h; - info->orientation = dcblk->orientation; - info->xdpi = dcblk->xdpi; - info->ydpi = dcblk->ydpi; - info->fps = dcblk->fps; - info->density = dcblk->density; - return getPixelFormatInfo(dcblk->format, &(info->pixelFormatInfo)); -} - -ssize_t SurfaceComposerClient::getDisplayWidth(DisplayID dpy) -{ - if (uint32_t(dpy)>=NUM_DISPLAY_MAX) - return BAD_VALUE; - volatile surface_flinger_cblk_t const * cblk = get_cblk(); - volatile display_cblk_t const * dcblk = cblk->displays + dpy; - return dcblk->w; -} - -ssize_t SurfaceComposerClient::getDisplayHeight(DisplayID dpy) -{ - if (uint32_t(dpy)>=NUM_DISPLAY_MAX) - return BAD_VALUE; - volatile surface_flinger_cblk_t const * cblk = get_cblk(); - volatile display_cblk_t const * dcblk = cblk->displays + dpy; - return dcblk->h; -} - -ssize_t SurfaceComposerClient::getDisplayOrientation(DisplayID dpy) -{ - if (uint32_t(dpy)>=NUM_DISPLAY_MAX) - return BAD_VALUE; - volatile surface_flinger_cblk_t const * cblk = get_cblk(); - volatile display_cblk_t const * dcblk = cblk->displays + dpy; - return dcblk->orientation; -} - -ssize_t SurfaceComposerClient::getNumberOfDisplays() -{ - volatile surface_flinger_cblk_t const * cblk = get_cblk(); - uint32_t connected = cblk->connected; - int n = 0; - while (connected) { - if (connected&1) n++; - connected >>= 1; - } - return n; + return getComposerService()->getDisplayInfo(dpy, info); } // ---------------------------------------------------------------------------- diff --git a/services/surfaceflinger/DisplayHardware.cpp b/services/surfaceflinger/DisplayHardware.cpp index 067a54f6d..4b5d8abdd 100644 --- a/services/surfaceflinger/DisplayHardware.cpp +++ b/services/surfaceflinger/DisplayHardware.cpp @@ -24,6 +24,7 @@ #include #include +#include #include #include @@ -31,7 +32,6 @@ #include #include -#include #include "DisplayHardware/FramebufferSurface.h" #include "DisplayHardware/DisplayHardwareBase.h" @@ -148,6 +148,19 @@ EGLSurface DisplayHardware::getEGLSurface() const { return mSurface; } +status_t DisplayHardware::getInfo(DisplayInfo* info) const { + info->w = getWidth(); + info->h = getHeight(); + info->xdpi = getDpiX(); + info->ydpi = getDpiY(); + info->fps = getRefreshRate(); + info->density = getDensity(); + info->orientation = getOrientation(); + // TODO: this needs to go away (currently needed only by webkit) + getPixelFormatInfo(getFormat(), &info->pixelFormatInfo); + return NO_ERROR; +} + void DisplayHardware::init(EGLConfig config) { ANativeWindow* const window = mNativeWindow.get(); @@ -226,17 +239,6 @@ void DisplayHardware::init(EGLConfig config) mFormat = format; mPageFlipCount = 0; - // initialize the shared control block - surface_flinger_cblk_t* const scblk = mFlinger->getControlBlock(); - scblk->connected |= 1 << mDisplayId; - display_cblk_t* dcblk = &scblk->displays[mDisplayId]; - memset(dcblk, 0, sizeof(display_cblk_t)); - dcblk->format = format; - dcblk->xdpi = mDpiX; - dcblk->ydpi = mDpiY; - dcblk->fps = mRefreshRate; - dcblk->density = mDensity; - // initialize the display orientation transform. DisplayHardware::setOrientation(ISurfaceComposer::eOrientationDefault); } @@ -365,13 +367,5 @@ status_t DisplayHardware::setOrientation(int orientation) { h = tmp; } mOrientation = orientation; - - // update the shared control block - surface_flinger_cblk_t* const scblk = mFlinger->getControlBlock(); - volatile display_cblk_t* dcblk = &scblk->displays[mDisplayId]; - dcblk->orientation = orientation; - dcblk->w = w; - dcblk->h = h; - return NO_ERROR; } diff --git a/services/surfaceflinger/DisplayHardware.h b/services/surfaceflinger/DisplayHardware.h index 88a8c0d07..98579b47a 100644 --- a/services/surfaceflinger/DisplayHardware.h +++ b/services/surfaceflinger/DisplayHardware.h @@ -36,6 +36,7 @@ namespace android { +class DisplayInfo; class FramebufferSurface; class LayerBase; class SurfaceFlinger; @@ -74,6 +75,7 @@ public: uint32_t getFlags() const; nsecs_t getRefreshPeriod() const; nsecs_t getRefreshTimestamp() const; + status_t getInfo(DisplayInfo* info) const; EGLSurface getEGLSurface() const; diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp index 992c7798b..192378f3e 100644 --- a/services/surfaceflinger/SurfaceFlinger.cpp +++ b/services/surfaceflinger/SurfaceFlinger.cpp @@ -32,6 +32,8 @@ #include #include +#include + #include #include #include @@ -45,7 +47,6 @@ #include #include -#include #include "clz.h" #include "DdmConnection.h" @@ -153,11 +154,6 @@ void SurfaceFlinger::binderDied(const wp& who) startBootAnim(); } -sp SurfaceFlinger::getCblk() const -{ - return mServerHeap; -} - sp SurfaceFlinger::createConnection() { sp bclient; @@ -361,24 +357,11 @@ void SurfaceFlinger::initializeGL(EGLDisplay display, EGLSurface surface) { ALOGI("GL_MAX_VIEWPORT_DIMS = %d x %d", mMaxViewportDims[0], mMaxViewportDims[1]); } -surface_flinger_cblk_t* SurfaceFlinger::getControlBlock() const { - return mServerCblk; -} - status_t SurfaceFlinger::readyToRun() { ALOGI( "SurfaceFlinger's main thread ready to run. " "Initializing graphics H/W..."); - // create the shared control-block - mServerHeap = new MemoryHeapBase(4096, - MemoryHeapBase::READ_ONLY, "SurfaceFlinger read-only heap"); - ALOGE_IF(mServerHeap==0, "can't create shared memory dealer"); - mServerCblk = static_cast(mServerHeap->getBase()); - ALOGE_IF(mServerCblk==0, "can't get to shared control block's address"); - new(mServerCblk) surface_flinger_cblk_t; - - // initialize EGL EGLDisplay display = eglGetDisplay(EGL_DEFAULT_DISPLAY); eglInitialize(display, NULL, NULL); @@ -485,6 +468,14 @@ bool SurfaceFlinger::authenticateSurfaceTexture( return false; } +status_t SurfaceFlinger::getDisplayInfo(DisplayID dpy, DisplayInfo* info) { + if (uint32_t(dpy) >= 2) { + return BAD_INDEX; + } + const DisplayHardware& hw(getDefaultDisplayHardware()); + return hw.getInfo(info); +} + // ---------------------------------------------------------------------------- sp SurfaceFlinger::createDisplayEventConnection() { diff --git a/services/surfaceflinger/SurfaceFlinger.h b/services/surfaceflinger/SurfaceFlinger.h index 64181222c..c33f1a335 100644 --- a/services/surfaceflinger/SurfaceFlinger.h +++ b/services/surfaceflinger/SurfaceFlinger.h @@ -64,7 +64,6 @@ class LayerBaseClient; class LayerDim; class LayerScreenshot; class SurfaceTextureClient; -struct surface_flinger_cblk_t; // --------------------------------------------------------------------------- @@ -176,7 +175,6 @@ private: */ virtual sp createConnection(); virtual sp createGraphicBufferAlloc(); - virtual sp getCblk() const; virtual void bootFinished(); virtual void setTransactionState(const Vector& state, const Vector& displays, uint32_t flags); @@ -193,6 +191,7 @@ private: virtual void blank(); // called when screen is turning back on virtual void unblank(); + virtual status_t getDisplayInfo(DisplayID dpy, DisplayInfo* info); virtual void connectDisplay(const sp display); /* ------------------------------------------------------------------------ @@ -382,8 +381,6 @@ private: Region mInvalidateRegion; // constant members (no synchronization needed for access) - sp mServerHeap; - surface_flinger_cblk_t* mServerCblk; HWComposer* mHwc; GLuint mWormholeTexName; GLuint mProtectedTexName; @@ -431,8 +428,6 @@ private: EGLSurface getExternalDisplaySurface() const; sp mExternalDisplayNativeWindow; EGLSurface mExternalDisplaySurface; -public: - surface_flinger_cblk_t* getControlBlock() const; }; // --------------------------------------------------------------------------- diff --git a/services/surfaceflinger/tests/Transaction_test.cpp b/services/surfaceflinger/tests/Transaction_test.cpp index 84ae0d957..e3a98ffa9 100644 --- a/services/surfaceflinger/tests/Transaction_test.cpp +++ b/services/surfaceflinger/tests/Transaction_test.cpp @@ -24,6 +24,7 @@ #include #include +#include namespace android { @@ -92,8 +93,11 @@ protected: mComposerClient = new SurfaceComposerClient; ASSERT_EQ(NO_ERROR, mComposerClient->initCheck()); - ssize_t displayWidth = mComposerClient->getDisplayWidth(0); - ssize_t displayHeight = mComposerClient->getDisplayHeight(0); + DisplayInfo info; + SurfaceComposerClient::getDisplayInfo(0, &info); + + ssize_t displayWidth = info.w; + ssize_t displayHeight = info.h; // Background surface mBGSurfaceControl = mComposerClient->createSurface(