From 321abdb092bfc925749d528de590680ae8bc3d5c Mon Sep 17 00:00:00 2001 From: Mathias Agopian Date: Fri, 14 Aug 2009 18:52:17 -0700 Subject: make sure to update a surface's usage bits when it changes, instead of only the first time. also fixed a few locking issues in Surface and commented how each member is protected. --- include/ui/Surface.h | 52 +++++++++++++++++++++++++++++++++++----------------- 1 file changed, 35 insertions(+), 17 deletions(-) (limited to 'include') diff --git a/include/ui/Surface.h b/include/ui/Surface.h index 4ff0e4a..30ab82f 100644 --- a/include/ui/Surface.h +++ b/include/ui/Surface.h @@ -146,16 +146,16 @@ public: static bool isValid(const sp& surface) { return (surface != 0) && surface->isValid(); } - bool isValid() { - return mToken>=0 && mClient!=0; - } + static bool isSameSurface( const sp& lhs, const sp& rhs); - SurfaceID ID() const { return mToken; } - uint32_t getFlags() const { return mFlags; } - uint32_t getIdentity() const { return mIdentity; } + bool isValid(); + SurfaceID ID() const { return mToken; } + uint32_t getFlags() const { return mFlags; } + uint32_t getIdentity() const { return mIdentity; } + // the lock/unlock APIs must be used from the same thread status_t lock(SurfaceInfo* info, bool blocking = true); status_t lock(SurfaceInfo* info, Region* dirty, bool blocking = true); status_t unlockAndPost(); @@ -175,14 +175,18 @@ private: friend class SurfaceComposerClient; friend class SurfaceControl; + // camera and camcorder need access to the ISurface binder interface for preview friend class Camera; friend class MediaRecorder; // mediaplayer needs access to ISurface for display friend class MediaPlayer; - friend class Test; friend class IOMX; - const sp& getISurface() const { return mSurface; } + // this is just to be able to write some unit tests + friend class Test; + + sp getClient() const; + sp getISurface() const; status_t getBufferLocked(int index, int usage); @@ -210,24 +214,38 @@ private: status_t queueBuffer(const sp& buffer); - alloc_device_t* mAllocDevice; + void setUsage(uint32_t reqUsage); + + // constants sp mClient; sp mSurface; - sp mBuffers[2]; - sp mLockedBuffer; SurfaceID mToken; uint32_t mIdentity; - uint32_t mWidth; - uint32_t mHeight; - uint32_t mUsage; PixelFormat mFormat; uint32_t mFlags; + BufferMapper& mBufferMapper; + + // protected by mSurfaceLock + Rect mSwapRectangle; + uint32_t mUsage; + bool mUsageChanged; + + // protected by mSurfaceLock. These are also used from lock/unlock + // but in that case, they must be called form the same thread. + sp mBuffers[2]; mutable Region mDirtyRegion; - mutable Region mOldDirtyRegion; mutable uint8_t mBackbufferIndex; + + // must be used from the lock/unlock thread + sp mLockedBuffer; + mutable Region mOldDirtyRegion; + + // query() must be called from dequeueBuffer() thread + uint32_t mWidth; + uint32_t mHeight; + + // Inherently thread-safe mutable Mutex mSurfaceLock; - Rect mSwapRectangle; - BufferMapper& mBufferMapper; }; }; // namespace android -- cgit v1.1