: DoubleBufferedTexture(eglGetCurrentContext())
, m_usedLevel(-1)
, m_owner(0)
- , m_painter(0)
, m_busy(false)
{
m_bitmap.setConfig(config, w, h);
}
m_varLock.lock();
- m_painter = painter;
// set the painting information for this texture
if (equalsIdTextureA(textureInfo->m_textureId))
m_paintingInfoA = 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();
// 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);
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;