OSDN Git Service

Cleaning up BackedDoubleBufferedTexture.
authorDerek Sollenberger <djsollen@google.com>
Wed, 27 Oct 2010 14:56:34 +0000 (10:56 -0400)
committerDerek Sollenberger <djsollen@google.com>
Wed, 27 Oct 2010 14:57:46 +0000 (10:57 -0400)
The cleanup consisted of removing unused fields, ensuring mutexes
are only used for cross-thread interactions, and adding comments.

Change-Id: Ie008cd8f803299d418439793f21feb90d8325a8e

WebCore/platform/graphics/android/BackedDoubleBufferedTexture.cpp
WebCore/platform/graphics/android/BackedDoubleBufferedTexture.h

index 1615e0d..334f7fd 100644 (file)
@@ -40,7 +40,6 @@ BackedDoubleBufferedTexture::BackedDoubleBufferedTexture(uint32_t w, uint32_t h,
     : DoubleBufferedTexture(eglGetCurrentContext())
     , m_usedLevel(-1)
     , m_owner(0)
-    , m_painter(0)
     , m_busy(false)
 {
     m_bitmap.setConfig(config, w, h);
@@ -95,7 +94,6 @@ void BackedDoubleBufferedTexture::producerUpdate(BaseTile* painter,
     }
 
     m_varLock.lock();
-    m_painter = painter;
     // set the painting information for this texture
     if (equalsIdTextureA(textureInfo->m_textureId))
         m_paintingInfoA = info;
@@ -125,13 +123,15 @@ bool BackedDoubleBufferedTexture::consumerTextureSimilar(PaintingInfo& info)
 
 bool BackedDoubleBufferedTexture::acquire(BaseTile* owner)
 {
-    // if the writable texture is currently being written to we can't change the
-    // owner out from underneath that texture
-    android::Mutex::Autolock lock(m_varLock);
     if (m_owner == owner)
         return true;
+
+    // if the writable texture is busy (i.e. currently being written to) then we
+    // can't change the owner out from underneath that texture
+    m_varLock.lock();
     if (m_busy)
         return false;
+    m_varLock.unlock();
 
     if (m_owner)
         m_owner->removeTexture();
index 9bbda49..1faa110 100644 (file)
@@ -97,15 +97,15 @@ public:
     // We use this to prioritize the order in which we reclaim textures, see
     // TilesManager::getAvailableTexture() for more information.
     int usedLevel() { return m_usedLevel; }
-    void setUsedLevel(int used) { android::Mutex::Autolock lock(m_varLock); m_usedLevel = used; }
+    void setUsedLevel(int used) { m_usedLevel = used; }
 
-    // assigns ownership of the texture to the tile if possible
+    // allows consumer thread to assign ownership of the texture to the tile. It
+    // returns false if ownership cannot be transferred because the tile is busy
     bool acquire(BaseTile* owner);
 
     // private member accessor functions
-    BaseTile* owner() { android::Mutex::Autolock lock(m_varLock); return m_owner; }
-    BaseTile* painter() { return m_painter; }
-    SkCanvas* canvas() { return m_canvas; }
+    BaseTile* owner() { return m_owner; } // only used by the consumer thread
+    SkCanvas* canvas() { return m_canvas; } // only used by the producer thread
 
     // checks to see if the current readable texture equals the provided PaintingInfo
     bool consumerTextureUpToDate(PaintingInfo& info);
@@ -119,7 +119,8 @@ private:
     SkCanvas* m_canvas;
     int m_usedLevel;
     BaseTile* m_owner;
-    BaseTile* m_painter;
+
+    //The following values are shared among threads and use m_varLock to stay synced
     PaintingInfo m_paintingInfoA;
     PaintingInfo m_paintingInfoB;
     bool m_busy;