diff options
Diffstat (limited to 'libs/gui/SurfaceComposerClient.cpp')
-rw-r--r-- | libs/gui/SurfaceComposerClient.cpp | 276 |
1 files changed, 140 insertions, 136 deletions
diff --git a/libs/gui/SurfaceComposerClient.cpp b/libs/gui/SurfaceComposerClient.cpp index 8fa2167..1e6e1bd 100644 --- a/libs/gui/SurfaceComposerClient.cpp +++ b/libs/gui/SurfaceComposerClient.cpp @@ -38,7 +38,6 @@ #include <private/gui/ComposerService.h> #include <private/gui/LayerState.h> -#include <private/gui/SharedBufferStack.h> namespace android { // --------------------------------------------------------------------------- @@ -51,33 +50,16 @@ ComposerService::ComposerService() while (getService(name, &mComposerService) != NO_ERROR) { usleep(250000); } - mServerCblkMemory = mComposerService->getCblk(); - mServerCblk = static_cast<surface_flinger_cblk_t volatile *>( - mServerCblkMemory->getBase()); } sp<ISurfaceComposer> ComposerService::getComposerService() { return ComposerService::getInstance().mComposerService; } -surface_flinger_cblk_t const volatile * ComposerService::getControlBlock() { - return ComposerService::getInstance().mServerCblk; -} - -static inline sp<ISurfaceComposer> 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 -// declaration). static inline -int compare_type( const ComposerState& lhs, const ComposerState& rhs) { +int compare_type(const ComposerState& lhs, const ComposerState& rhs) { if (lhs.client < rhs.client) return -1; if (lhs.client > rhs.client) return 1; if (lhs.state.surface < rhs.state.surface) return -1; @@ -85,17 +67,21 @@ int compare_type( const ComposerState& lhs, const ComposerState& rhs) { return 0; } +static inline +int compare_type(const DisplayState& lhs, const DisplayState& rhs) { + return compare_type(lhs.token, rhs.token); +} + class Composer : public Singleton<Composer> { friend class Singleton<Composer>; mutable Mutex mLock; - SortedVector<ComposerState> mStates; - int mOrientation; + SortedVector<ComposerState> mComposerStates; + SortedVector<DisplayState > mDisplayStates; uint32_t mForceSynchronous; Composer() : Singleton<Composer>(), - mOrientation(ISurfaceComposer::eOrientationUnchanged), mForceSynchronous(0) { } @@ -104,7 +90,10 @@ class Composer : public Singleton<Composer> layer_state_t* getLayerStateLocked( const sp<SurfaceComposerClient>& client, SurfaceID id); + DisplayState& getDisplayStateLocked(const sp<IBinder>& token); + public: + sp<IBinder> createDisplay(); status_t setPosition(const sp<SurfaceComposerClient>& client, SurfaceID id, float x, float y); @@ -121,12 +110,17 @@ public: float alpha); status_t setMatrix(const sp<SurfaceComposerClient>& client, SurfaceID id, float dsdx, float dtdx, float dsdy, float dtdy); - status_t setFreezeTint( - const sp<SurfaceComposerClient>& client, SurfaceID id, - uint32_t tint); status_t setOrientation(int orientation); status_t setCrop(const sp<SurfaceComposerClient>& client, SurfaceID id, const Rect& crop); + status_t setLayerStack(const sp<SurfaceComposerClient>& client, + SurfaceID id, uint32_t layerStack); + + void setDisplaySurface(const sp<IBinder>& token, const sp<ISurfaceTexture>& surface); + void setDisplayLayerStack(const sp<IBinder>& token, uint32_t layerStack); + void setDisplayOrientation(const sp<IBinder>& token, uint32_t orientation); + void setDisplayViewport(const sp<IBinder>& token, const Rect& viewport); + void setDisplayFrame(const sp<IBinder>& token, const Rect& frame); static void closeGlobalTransaction(bool synchronous) { Composer::getInstance().closeGlobalTransactionImpl(synchronous); @@ -137,20 +131,24 @@ ANDROID_SINGLETON_STATIC_INSTANCE(Composer); // --------------------------------------------------------------------------- +sp<IBinder> Composer::createDisplay() { + return ComposerService::getComposerService()->createDisplay(); +} + void Composer::closeGlobalTransactionImpl(bool synchronous) { - sp<ISurfaceComposer> sm(getComposerService()); + sp<ISurfaceComposer> sm(ComposerService::getComposerService()); Vector<ComposerState> transaction; - int orientation; + Vector<DisplayState> displayTransaction; uint32_t flags = 0; { // scope for the lock Mutex::Autolock _l(mLock); - transaction = mStates; - mStates.clear(); + transaction = mComposerStates; + mComposerStates.clear(); - orientation = mOrientation; - mOrientation = ISurfaceComposer::eOrientationUnchanged; + displayTransaction = mDisplayStates; + mDisplayStates.clear(); if (synchronous || mForceSynchronous) { flags |= ISurfaceComposer::eSynchronous; @@ -158,7 +156,7 @@ void Composer::closeGlobalTransactionImpl(bool synchronous) { mForceSynchronous = false; } - sm->setTransactionState(transaction, orientation, flags); + sm->setTransactionState(transaction, displayTransaction, flags); } layer_state_t* Composer::getLayerStateLocked( @@ -168,13 +166,13 @@ layer_state_t* Composer::getLayerStateLocked( s.client = client->mClient; s.state.surface = id; - ssize_t index = mStates.indexOf(s); + ssize_t index = mComposerStates.indexOf(s); if (index < 0) { // we don't have it, add an initialized layer_state to our list - index = mStates.add(s); + index = mComposerStates.add(s); } - ComposerState* const out = mStates.editArray(); + ComposerState* const out = mComposerStates.editArray(); return &(out[index].state); } @@ -184,7 +182,7 @@ status_t Composer::setPosition(const sp<SurfaceComposerClient>& client, layer_state_t* s = getLayerStateLocked(client, id); if (!s) return BAD_INDEX; - s->what |= ISurfaceComposer::ePositionChanged; + s->what |= layer_state_t::ePositionChanged; s->x = x; s->y = y; return NO_ERROR; @@ -196,7 +194,7 @@ status_t Composer::setSize(const sp<SurfaceComposerClient>& client, layer_state_t* s = getLayerStateLocked(client, id); if (!s) return BAD_INDEX; - s->what |= ISurfaceComposer::eSizeChanged; + s->what |= layer_state_t::eSizeChanged; s->w = w; s->h = h; @@ -212,7 +210,7 @@ status_t Composer::setLayer(const sp<SurfaceComposerClient>& client, layer_state_t* s = getLayerStateLocked(client, id); if (!s) return BAD_INDEX; - s->what |= ISurfaceComposer::eLayerChanged; + s->what |= layer_state_t::eLayerChanged; s->z = z; return NO_ERROR; } @@ -224,7 +222,7 @@ status_t Composer::setFlags(const sp<SurfaceComposerClient>& client, layer_state_t* s = getLayerStateLocked(client, id); if (!s) return BAD_INDEX; - s->what |= ISurfaceComposer::eVisibilityChanged; + s->what |= layer_state_t::eVisibilityChanged; s->flags &= ~mask; s->flags |= (flags & mask); s->mask |= mask; @@ -238,7 +236,7 @@ status_t Composer::setTransparentRegionHint( layer_state_t* s = getLayerStateLocked(client, id); if (!s) return BAD_INDEX; - s->what |= ISurfaceComposer::eTransparentRegionChanged; + s->what |= layer_state_t::eTransparentRegionChanged; s->transparentRegion = transparentRegion; return NO_ERROR; } @@ -249,11 +247,22 @@ status_t Composer::setAlpha(const sp<SurfaceComposerClient>& client, layer_state_t* s = getLayerStateLocked(client, id); if (!s) return BAD_INDEX; - s->what |= ISurfaceComposer::eAlphaChanged; + s->what |= layer_state_t::eAlphaChanged; s->alpha = alpha; return NO_ERROR; } +status_t Composer::setLayerStack(const sp<SurfaceComposerClient>& client, + SurfaceID id, uint32_t layerStack) { + Mutex::Autolock _l(mLock); + layer_state_t* s = getLayerStateLocked(client, id); + if (!s) + return BAD_INDEX; + s->what |= layer_state_t::eLayerStackChanged; + s->layerStack = layerStack; + return NO_ERROR; +} + status_t Composer::setMatrix(const sp<SurfaceComposerClient>& client, SurfaceID id, float dsdx, float dtdx, float dsdy, float dtdy) { @@ -261,7 +270,7 @@ status_t Composer::setMatrix(const sp<SurfaceComposerClient>& client, layer_state_t* s = getLayerStateLocked(client, id); if (!s) return BAD_INDEX; - s->what |= ISurfaceComposer::eMatrixChanged; + s->what |= layer_state_t::eMatrixChanged; layer_state_t::matrix22_t matrix; matrix.dsdx = dsdx; matrix.dtdx = dtdx; @@ -271,36 +280,78 @@ status_t Composer::setMatrix(const sp<SurfaceComposerClient>& client, return NO_ERROR; } -status_t Composer::setFreezeTint(const sp<SurfaceComposerClient>& client, - SurfaceID id, uint32_t tint) { +status_t Composer::setCrop(const sp<SurfaceComposerClient>& client, + SurfaceID id, const Rect& crop) { Mutex::Autolock _l(mLock); layer_state_t* s = getLayerStateLocked(client, id); if (!s) return BAD_INDEX; - s->what |= ISurfaceComposer::eFreezeTintChanged; - s->tint = tint; + s->what |= layer_state_t::eCropChanged; + s->crop = crop; return NO_ERROR; } -status_t Composer::setOrientation(int orientation) { +// --------------------------------------------------------------------------- + +DisplayState& Composer::getDisplayStateLocked(const sp<IBinder>& token) { + DisplayState s; + s.token = token; + ssize_t index = mDisplayStates.indexOf(s); + if (index < 0) { + // we don't have it, add an initialized layer_state to our list + s.what = 0; + index = mDisplayStates.add(s); + } + return mDisplayStates.editItemAt(index); +} + +void Composer::setDisplaySurface(const sp<IBinder>& token, + const sp<ISurfaceTexture>& surface) { Mutex::Autolock _l(mLock); - mOrientation = orientation; + DisplayState& s(getDisplayStateLocked(token)); + s.surface = surface; + s.what |= DisplayState::eSurfaceChanged; +} - // Changing the orientation makes the transaction synchronous. - mForceSynchronous = true; +void Composer::setDisplayLayerStack(const sp<IBinder>& token, + uint32_t layerStack) { + Mutex::Autolock _l(mLock); + DisplayState& s(getDisplayStateLocked(token)); + s.layerStack = layerStack; + s.what |= DisplayState::eLayerStackChanged; +} +void Composer::setDisplayOrientation(const sp<IBinder>& token, + uint32_t orientation) { + Mutex::Autolock _l(mLock); + DisplayState& s(getDisplayStateLocked(token)); + s.orientation = orientation; + s.what |= DisplayState::eOrientationChanged; + mForceSynchronous = true; // TODO: do we actually still need this? +} + +// FIXME: get rid of this eventually +status_t Composer::setOrientation(int orientation) { + sp<ISurfaceComposer> sm(ComposerService::getComposerService()); + sp<IBinder> token(sm->getBuiltInDisplay(ISurfaceComposer::eDisplayIdMain)); + Composer::setDisplayOrientation(token, orientation); return NO_ERROR; } -status_t Composer::setCrop(const sp<SurfaceComposerClient>& client, - SurfaceID id, const Rect& crop) { +void Composer::setDisplayViewport(const sp<IBinder>& token, + const Rect& viewport) { Mutex::Autolock _l(mLock); - layer_state_t* s = getLayerStateLocked(client, id); - if (!s) - return BAD_INDEX; - s->what |= ISurfaceComposer::eCropChanged; - s->crop = crop; - return NO_ERROR; + DisplayState& s(getDisplayStateLocked(token)); + s.viewport = viewport; + s.what |= DisplayState::eViewportChanged; +} + +void Composer::setDisplayFrame(const sp<IBinder>& token, + const Rect& frame) { + Mutex::Autolock _l(mLock); + DisplayState& s(getDisplayStateLocked(token)); + s.frame = frame; + s.what |= DisplayState::eFrameChanged; } // --------------------------------------------------------------------------- @@ -311,7 +362,7 @@ SurfaceComposerClient::SurfaceComposerClient() } void SurfaceComposerClient::onFirstRef() { - sp<ISurfaceComposer> sm(getComposerService()); + sp<ISurfaceComposer> sm(ComposerService::getComposerService()); if (sm != 0) { sp<ISurfaceComposerClient> conn = sm->createConnection(); if (conn != 0) { @@ -336,7 +387,7 @@ sp<IBinder> SurfaceComposerClient::connection() const { status_t SurfaceComposerClient::linkToComposerDeath( const sp<IBinder::DeathRecipient>& recipient, void* cookie, uint32_t flags) { - sp<ISurfaceComposer> sm(getComposerService()); + sp<ISurfaceComposer> sm(ComposerService::getComposerService()); return sm->asBinder()->linkToDeath(recipient, cookie, flags); } @@ -388,6 +439,10 @@ sp<SurfaceControl> SurfaceComposerClient::createSurface( return result; } +sp<IBinder> SurfaceComposerClient::createDisplay() { + return Composer::getInstance().createDisplay(); +} + status_t SurfaceComposerClient::destroySurface(SurfaceID sid) { if (mStatus != NO_ERROR) return mStatus; @@ -415,10 +470,6 @@ status_t SurfaceComposerClient::setCrop(SurfaceID id, const Rect& crop) { return getComposer().setCrop(this, id, crop); } -status_t SurfaceComposerClient::setFreezeTint(SurfaceID id, uint32_t tint) { - return getComposer().setFreezeTint(this, id, tint); -} - status_t SurfaceComposerClient::setPosition(SurfaceID id, float x, float y) { return getComposer().setPosition(this, id, x, y); } @@ -433,26 +484,14 @@ status_t SurfaceComposerClient::setLayer(SurfaceID id, int32_t z) { status_t SurfaceComposerClient::hide(SurfaceID id) { return getComposer().setFlags(this, id, - ISurfaceComposer::eLayerHidden, - ISurfaceComposer::eLayerHidden); + layer_state_t::eLayerHidden, + layer_state_t::eLayerHidden); } status_t SurfaceComposerClient::show(SurfaceID id, int32_t) { return getComposer().setFlags(this, id, 0, - ISurfaceComposer::eLayerHidden); -} - -status_t SurfaceComposerClient::freeze(SurfaceID id) { - return getComposer().setFlags(this, id, - ISurfaceComposer::eLayerFrozen, - ISurfaceComposer::eLayerFrozen); -} - -status_t SurfaceComposerClient::unfreeze(SurfaceID id) { - return getComposer().setFlags(this, id, - 0, - ISurfaceComposer::eLayerFrozen); + layer_state_t::eLayerHidden); } status_t SurfaceComposerClient::setFlags(SurfaceID id, uint32_t flags, @@ -469,6 +508,10 @@ status_t SurfaceComposerClient::setAlpha(SurfaceID id, float alpha) { return getComposer().setAlpha(this, id, alpha); } +status_t SurfaceComposerClient::setLayerStack(SurfaceID id, uint32_t layerStack) { + return getComposer().setLayerStack(this, id, layerStack); +} + status_t SurfaceComposerClient::setMatrix(SurfaceID id, float dsdx, float dtdx, float dsdy, float dtdy) { return getComposer().setMatrix(this, id, dsdx, dtdx, dsdy, dtdy); @@ -482,76 +525,37 @@ 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)); +void SurfaceComposerClient::setDisplaySurface(const sp<IBinder>& token, + const sp<ISurfaceTexture>& surface) { + Composer::getInstance().setDisplaySurface(token, surface); } -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; +void SurfaceComposerClient::setDisplayLayerStack(const sp<IBinder>& token, + uint32_t layerStack) { + Composer::getInstance().setDisplayLayerStack(token, layerStack); } -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; +void SurfaceComposerClient::setDisplayOrientation(const sp<IBinder>& token, + uint32_t orientation) { + Composer::getInstance().setDisplayOrientation(token, orientation); } -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; +void SurfaceComposerClient::setDisplayViewport(const sp<IBinder>& token, + const Rect& viewport) { + Composer::getInstance().setDisplayViewport(token, viewport); } -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; +void SurfaceComposerClient::setDisplayFrame(const sp<IBinder>& token, + const Rect& frame) { + Composer::getInstance().setDisplayFrame(token, frame); } // ---------------------------------------------------------------------------- -status_t SurfaceComposerClient::freezeDisplay(DisplayID dpy, uint32_t flags) -{ - // This has been made a no-op because it can cause Gralloc buffer deadlocks. - return NO_ERROR; -} - -status_t SurfaceComposerClient::unfreezeDisplay(DisplayID dpy, uint32_t flags) +status_t SurfaceComposerClient::getDisplayInfo( + DisplayID dpy, DisplayInfo* info) { - // This has been made a no-op because it can cause Gralloc buffer deadlocks. - return NO_ERROR; + return ComposerService::getComposerService()->getDisplayInfo(dpy, info); } // ---------------------------------------------------------------------------- |