summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDerek Sollenberger <djsollen@google.com>2010-10-20 11:19:43 -0400
committerDerek Sollenberger <djsollen@google.com>2010-10-22 08:07:58 -0400
commitf56ebc1167a793612f34175b5e33db5cef631457 (patch)
tree52757a2eb1c198afa2ef2fff136c885c3bbb5510
parent47576fc759b81fe0b6571fcb3a7910bd304db739 (diff)
downloadexternal_webkit-f56ebc1167a793612f34175b5e33db5cef631457.zip
external_webkit-f56ebc1167a793612f34175b5e33db5cef631457.tar.gz
external_webkit-f56ebc1167a793612f34175b5e33db5cef631457.tar.bz2
Cleanup DoubleBufferedTexture and SharedTexture classes.
The cleanup consisted of... 1. removing uneeded mutex calls 2. ensuring user's of the class fully initialize them before use 3. hiding protected variables to prevent potential misuse by subclasses There will be a follow on CL focusing on cleaning up the use of mutexes in BackedDoubleBufferedTexture. Change-Id: Ia642d54d8a5b154ac287640a07d8b2c0e5d85334
-rw-r--r--WebCore/platform/graphics/android/BackedDoubleBufferedTexture.cpp8
-rw-r--r--WebCore/platform/graphics/android/BackedDoubleBufferedTexture.h2
-rw-r--r--WebCore/platform/graphics/android/DoubleBufferedTexture.cpp34
-rw-r--r--WebCore/platform/graphics/android/DoubleBufferedTexture.h19
-rw-r--r--WebCore/platform/graphics/android/SharedTexture.cpp5
-rw-r--r--WebCore/platform/graphics/android/TilesManager.cpp6
6 files changed, 29 insertions, 45 deletions
diff --git a/WebCore/platform/graphics/android/BackedDoubleBufferedTexture.cpp b/WebCore/platform/graphics/android/BackedDoubleBufferedTexture.cpp
index d4725f2..1615e0d 100644
--- a/WebCore/platform/graphics/android/BackedDoubleBufferedTexture.cpp
+++ b/WebCore/platform/graphics/android/BackedDoubleBufferedTexture.cpp
@@ -97,9 +97,9 @@ void BackedDoubleBufferedTexture::producerUpdate(BaseTile* painter,
m_varLock.lock();
m_painter = painter;
// set the painting information for this texture
- if (textureInfo->m_textureId == m_textureA.getSourceTextureId())
+ if (equalsIdTextureA(textureInfo->m_textureId))
m_paintingInfoA = info;
- else if (textureInfo->m_textureId == m_textureB.getSourceTextureId())
+ else if (equalsIdTextureB(textureInfo->m_textureId))
m_paintingInfoB = info;
m_varLock.unlock();
@@ -110,7 +110,7 @@ void BackedDoubleBufferedTexture::producerUpdate(BaseTile* painter,
bool BackedDoubleBufferedTexture::consumerTextureUpToDate(PaintingInfo& info)
{
android::Mutex::Autolock lock(m_varLock);
- if (getReadableTexture() == &m_textureA)
+ if (isTextureAReadable())
return info == m_paintingInfoA;
return info == m_paintingInfoB;
}
@@ -118,7 +118,7 @@ bool BackedDoubleBufferedTexture::consumerTextureUpToDate(PaintingInfo& info)
bool BackedDoubleBufferedTexture::consumerTextureSimilar(PaintingInfo& info)
{
android::Mutex::Autolock lock(m_varLock);
- if (getReadableTexture() == &m_textureA)
+ if (isTextureAReadable())
return info.similar(m_paintingInfoA);
return info.similar(m_paintingInfoB);
}
diff --git a/WebCore/platform/graphics/android/BackedDoubleBufferedTexture.h b/WebCore/platform/graphics/android/BackedDoubleBufferedTexture.h
index 9161153..9bbda49 100644
--- a/WebCore/platform/graphics/android/BackedDoubleBufferedTexture.h
+++ b/WebCore/platform/graphics/android/BackedDoubleBufferedTexture.h
@@ -123,6 +123,8 @@ private:
PaintingInfo m_paintingInfoA;
PaintingInfo m_paintingInfoB;
bool m_busy;
+
+ android::Mutex m_varLock;
};
} // namespace WebCore
diff --git a/WebCore/platform/graphics/android/DoubleBufferedTexture.cpp b/WebCore/platform/graphics/android/DoubleBufferedTexture.cpp
index ef261a0..bce230f 100644
--- a/WebCore/platform/graphics/android/DoubleBufferedTexture.cpp
+++ b/WebCore/platform/graphics/android/DoubleBufferedTexture.cpp
@@ -36,9 +36,6 @@ namespace WebCore {
DoubleBufferedTexture::DoubleBufferedTexture(EGLContext sharedContext)
{
- // the mutex ensures that the variables are not used in any other thread
- // until the constructor has the opportunity to initialize them
- android::Mutex::Autolock lock(m_varLock);
m_display = eglGetCurrentDisplay();
m_pContext = EGL_NO_CONTEXT;
m_cContext = sharedContext;
@@ -59,8 +56,6 @@ SharedTexture* DoubleBufferedTexture::getReadableTexture()
EGLContext DoubleBufferedTexture::producerAcquireContext()
{
- // ensure that the constructor has completed and all values are initialized
- android::Mutex::Autolock lock(m_varLock);
if (m_pContext != EGL_NO_CONTEXT) {
LOGV("AquireContext has previously generated a context.\n");
@@ -110,36 +105,26 @@ TextureInfo* DoubleBufferedTexture::producerLock()
void DoubleBufferedTexture::producerRelease()
{
- producerReleaseTexture();
+ // get the writable texture and unlock it
+ SharedTexture* sharedTex = getWriteableTexture();
+ LOGV("Releasing P Lock (%d)", sharedTex->getSourceTextureId());
+ sharedTex->releaseSource();
}
void DoubleBufferedTexture::producerReleaseAndSwap()
{
- SharedTexture* sharedTex = producerReleaseTexture();
-
- // swap the front and back buffers
- m_varLock.lock();
- m_writeableTexture = (sharedTex == &m_textureA) ? &m_textureB : &m_textureA;
- LOGV("Released P Lock (%d)", sharedTex->getSourceTextureId());
- m_varLock.unlock();
-}
+ producerRelease();
-SharedTexture* DoubleBufferedTexture::producerReleaseTexture()
-{
- // get the front texture, unlock it, and return the id
- SharedTexture* sharedTex = getWriteableTexture();
- LOGV("Releasing P Lock (%d)", sharedTex->getSourceTextureId());
- sharedTex->releaseSource();
- return sharedTex;
+ // swap the front and back buffers using an atomic op for the memory barrier
+ android_atomic_acquire_store((int32_t)getReadableTexture(), (int32_t*)&m_writeableTexture);
+ LOGV("Released P Lock (%d)", m_writeableTexture->getSourceTextureId());
}
TextureInfo* DoubleBufferedTexture::consumerLock()
{
- m_varLock.lock();
SharedTexture* sharedTex = getReadableTexture();
LOGV("Acquiring C Lock (%d)", sharedTex->getSourceTextureId());
m_lockedConsumerTexture = sharedTex;
- m_varLock.unlock();
TextureInfo* texInfo = sharedTex->lockTarget();
LOGV("Acquired C Lock");
@@ -152,9 +137,8 @@ TextureInfo* DoubleBufferedTexture::consumerLock()
void DoubleBufferedTexture::consumerRelease()
{
- android::Mutex::Autolock lock(m_varLock);
// we must check to see what texture the consumer had locked since the
- // producer may have swapped out the front buffer
+ // producer may have swapped out the readable buffer
SharedTexture* sharedTex = m_lockedConsumerTexture;
sharedTex->releaseTarget();
LOGV("Released C Lock (%d)", sharedTex->getSourceTextureId());
diff --git a/WebCore/platform/graphics/android/DoubleBufferedTexture.h b/WebCore/platform/graphics/android/DoubleBufferedTexture.h
index de75479..d90c0d1 100644
--- a/WebCore/platform/graphics/android/DoubleBufferedTexture.h
+++ b/WebCore/platform/graphics/android/DoubleBufferedTexture.h
@@ -48,24 +48,23 @@ public:
void consumerRelease();
protected:
- SharedTexture m_textureA;
- SharedTexture m_textureB;
- SharedTexture* m_writeableTexture;
- android::Mutex m_varLock;
-
- SharedTexture* getReadableTexture();
+ bool equalsIdTextureA(GLuint id) { return id == m_textureA.getSourceTextureId(); }
+ bool equalsIdTextureB(GLuint id) { return id == m_textureB.getSourceTextureId(); }
+ bool isTextureAReadable() { return getReadableTexture() == &m_textureA; }
private:
+ SharedTexture* getReadableTexture();
SharedTexture* getWriteableTexture();
- SharedTexture* producerReleaseTexture();
- EGLDisplay m_display;
+ SharedTexture m_textureA;
+ SharedTexture m_textureB;
+ SharedTexture* m_writeableTexture;
+ SharedTexture* m_lockedConsumerTexture; // only used by the consumer
+ EGLDisplay m_display;
EGLContext m_pContext;
EGLContext m_cContext;
- SharedTexture* m_lockedConsumerTexture; // only used by the consumer
-
bool m_supportsEGLImage;
};
diff --git a/WebCore/platform/graphics/android/SharedTexture.cpp b/WebCore/platform/graphics/android/SharedTexture.cpp
index fee9c32..b9f71c9 100644
--- a/WebCore/platform/graphics/android/SharedTexture.cpp
+++ b/WebCore/platform/graphics/android/SharedTexture.cpp
@@ -57,10 +57,6 @@ bool TextureInfo::operator==(const TextureInfo& otherTexture) {
}
SharedTexture::SharedTexture() {
-
- // the mutex ensures that the variables are not used in any other thread
- // until the constructor has the opportunity to initialize them
- android::Mutex::Autolock lock(m_lock);
m_display = eglGetCurrentDisplay();
m_eglImage = EGL_NO_IMAGE_KHR;
m_isNewImage = true;
@@ -84,7 +80,6 @@ SharedTexture::~SharedTexture() {
} else {
glDeleteTextures(1, &m_sourceTexture.m_textureId);
}
- m_lock.unlock();
}
void SharedTexture::initSourceTexture() {
diff --git a/WebCore/platform/graphics/android/TilesManager.cpp b/WebCore/platform/graphics/android/TilesManager.cpp
index b05c640..bac5eb1 100644
--- a/WebCore/platform/graphics/android/TilesManager.cpp
+++ b/WebCore/platform/graphics/android/TilesManager.cpp
@@ -31,6 +31,7 @@
#include "BaseTile.h"
#include "SkCanvas.h"
#include "SkPaint.h"
+#include <cutils/atomic.h>
#ifdef DEBUG
@@ -67,7 +68,10 @@ TilesManager::TilesManager()
for (int i = 0; i < DEFAULT_TEXTURES_ALLOCATION; i++) {
BackedDoubleBufferedTexture* texture = new BackedDoubleBufferedTexture(
tileWidth(), tileHeight());
- m_textures.append(texture);
+ // the atomic load ensures that the texture has been fully initialized
+ // before we pass a pointer for other threads to operate on
+ m_textures.append(
+ (BackedDoubleBufferedTexture*)android_atomic_acquire_load((int32_t*)&texture));
}
m_pixmapsGenerationThread = new TexturesGenerator();