From a67932fe6864ac346e7f78b86df11cf6c5344137 Mon Sep 17 00:00:00 2001 From: Mathias Agopian Date: Wed, 20 Apr 2011 14:20:59 -0700 Subject: unify SurfaceTexture and Surface Add the concept of synchronous dequeueBuffer in SurfaceTexture Implement {Surface|SurfaceTextureClient}::setSwapInterval() Add SurfaceTexture logging fix onFrameAvailable --- services/surfaceflinger/Layer.h | 164 ++++++---------------------------------- 1 file changed, 25 insertions(+), 139 deletions(-) (limited to 'services/surfaceflinger/Layer.h') diff --git a/services/surfaceflinger/Layer.h b/services/surfaceflinger/Layer.h index 278d64e..72e290c 100644 --- a/services/surfaceflinger/Layer.h +++ b/services/surfaceflinger/Layer.h @@ -20,9 +20,11 @@ #include #include +#include + +#include #include #include -#include #include #include @@ -30,8 +32,8 @@ #include #include "LayerBase.h" +#include "SurfaceTextureLayer.h" #include "Transform.h" -#include "TextureManager.h" namespace android { @@ -40,7 +42,6 @@ namespace android { class FreezeLock; class Client; class GLExtensions; -class UserClient; // --------------------------------------------------------------------------- @@ -58,164 +59,59 @@ public: status_t setBuffers(uint32_t w, uint32_t h, PixelFormat format, uint32_t flags=0); - // associate a UserClient to this Layer - status_t setToken(const sp& uc, SharedClient* sc, int32_t idx); - int32_t getToken() const; - sp getClient() const; - // Set this Layer's buffers size - void setBufferSize(uint32_t w, uint32_t h); bool isFixedSize() const; // LayerBase interface virtual void setGeometry(hwc_layer_t* hwcl); virtual void setPerFrameData(hwc_layer_t* hwcl); - virtual void drawForSreenShot() const; virtual void onDraw(const Region& clip) const; virtual uint32_t doTransaction(uint32_t transactionFlags); virtual void lockPageFlip(bool& recomputeVisibleRegions); virtual void unlockPageFlip(const Transform& planeTransform, Region& outDirtyRegion); - virtual bool needsBlending(const sp& buffer) const; - virtual bool needsBlending() const; + virtual bool isOpaque() const; virtual bool needsDithering() const { return mNeedsDithering; } - virtual bool needsFiltering() const; virtual bool isSecure() const { return mSecure; } virtual bool isProtected() const; - virtual sp createSurface() const; virtual void onRemoved(); // only for debugging - inline sp getBuffer(int i) const { - return mBufferManager.getBuffer(i); } - // only for debugging - inline const sp& getFreezeLock() const { - return mFreezeLock; } + inline const sp& getFreezeLock() const { return mFreezeLock; } protected: virtual void destroy() const; + virtual void onFirstRef(); virtual void dump(String8& result, char* scratch, size_t size) const; private: - void reloadTexture(const Region& dirty); + friend class SurfaceTextureLayer; + void onFrameQueued(); + virtual sp createSurface(); uint32_t getEffectiveUsage(uint32_t usage) const; - sp requestBuffer(int bufferIdx, - uint32_t w, uint32_t h, uint32_t format, uint32_t usage); - status_t setBufferCount(int bufferCount); - - // ----------------------------------------------------------------------- - - class SurfaceLayer : public LayerBaseClient::Surface { - public: - SurfaceLayer(const sp& flinger, const sp& owner); - ~SurfaceLayer(); - private: - virtual sp requestBuffer(int bufferIdx, - uint32_t w, uint32_t h, uint32_t format, uint32_t usage); - virtual status_t setBufferCount(int bufferCount); - sp getOwner() const { - return static_cast(Surface::getOwner().get()); - } - }; - friend class SurfaceLayer; + void setFixedSize(bool fixedSize); + bool isCropped() const; + static bool getOpacityForFormat(uint32_t format); // ----------------------------------------------------------------------- - class ClientRef { - ClientRef(const ClientRef& rhs); - ClientRef& operator = (const ClientRef& rhs); - mutable Mutex mLock; - // binder thread, page-flip thread - sp mControlBlock; - wp mUserClient; - int32_t mToken; - public: - ClientRef(); - ~ClientRef(); - int32_t getToken() const; - sp getClient() const; - status_t setToken(const sp& uc, - const sp& sharedClient, int32_t token); - sp getUserClientUnsafe() const; - class Access { - Access(const Access& rhs); - Access& operator = (const Access& rhs); - sp mUserClientStrongRef; - sp mControlBlock; - public: - Access(const ClientRef& ref); - ~Access(); - inline SharedBufferServer* get() const { return mControlBlock.get(); } - }; - friend class Access; - }; - - // ----------------------------------------------------------------------- - - class BufferManager { - static const size_t NUM_BUFFERS = 2; - struct BufferData { - sp buffer; - Image texture; - }; - // this lock protect mBufferData[].buffer but since there - // is very little contention, we have only one like for - // the whole array, we also use it to protect mNumBuffers. - mutable Mutex mLock; - BufferData mBufferData[SharedBufferStack::NUM_BUFFER_MAX]; - size_t mNumBuffers; - Texture mFailoverTexture; - TextureManager& mTextureManager; - ssize_t mActiveBufferIndex; - sp mActiveBuffer; - bool mFailover; - static status_t destroyTexture(Image* tex, EGLDisplay dpy); - - public: - static size_t getDefaultBufferCount() { return NUM_BUFFERS; } - BufferManager(TextureManager& tm); - ~BufferManager(); - - // detach/attach buffer from/to given index - sp detachBuffer(size_t index); - status_t attachBuffer(size_t index, const sp& buffer); - // resize the number of active buffers - status_t resize(size_t size, const sp& flinger, - EGLDisplay dpy); - - // ---------------------------------------------- - // must be called from GL thread - - // set/get active buffer index - status_t setActiveBufferIndex(size_t index); - size_t getActiveBufferIndex() const; - // return the active buffer - sp getActiveBuffer() const; - // return wether we have an active buffer - bool hasActiveBuffer() const; - // return the active texture (or fail-over) - Texture getActiveTexture() const; - // frees resources associated with all buffers - status_t destroy(EGLDisplay dpy); - // load bitmap data into the active buffer - status_t loadTexture(const Region& dirty, const GGLSurface& t); - // make active buffer an EGLImage if needed - status_t initEglImage(EGLDisplay dpy, - const sp& buffer); - - // ---------------------------------------------- - // only for debugging - sp getBuffer(size_t index) const; - }; - - // ----------------------------------------------------------------------- + // constants + sp mSurfaceTexture; + GLuint mTextureName; // thread-safe - ClientRef mUserClientRef; + volatile int32_t mQueuedFrames; + + // main thread + sp mActiveBuffer; + GLfloat mTextureMatrix[16]; + Rect mCurrentCrop; + uint32_t mCurrentTransform; + bool mCurrentOpacity; // constants PixelFormat mFormat; const GLExtensions& mGLExtensions; - bool mNeedsBlending; + bool mOpaqueLayer; bool mNeedsDithering; // page-flip thread (currently main thread) @@ -226,18 +122,8 @@ private: // page-flip thread and transaction thread (currently main thread) sp mFreezeLock; - // see threading usage in declaration - TextureManager mTextureManager; - BufferManager mBufferManager; - // binder thread, transaction thread mutable Mutex mLock; - uint32_t mWidth; - uint32_t mHeight; - uint32_t mReqWidth; - uint32_t mReqHeight; - uint32_t mReqFormat; - bool mNeedsScaling; bool mFixedSize; }; -- cgit v1.1