summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorTeng-Hui Zhu <ztenghui@google.com>2012-02-28 10:29:36 -0800
committerTeng-Hui Zhu <ztenghui@google.com>2012-02-28 14:11:42 -0800
commit5965903d393505b9a49ac3a142aa0c17cd98bce8 (patch)
treee22fbaf86855f3805cd60bd5eba1d3a00a0a6812 /Source
parent7adab1830575d4438d058b5d7f6e932e97451c56 (diff)
downloadexternal_webkit-5965903d393505b9a49ac3a142aa0c17cd98bce8.zip
external_webkit-5965903d393505b9a49ac3a142aa0c17cd98bce8.tar.gz
external_webkit-5965903d393505b9a49ac3a142aa0c17cd98bce8.tar.bz2
Delete the GL shader resources in a cleaner way
bug:6079959 Change-Id: I55c96bb6abc90503c178607d0798c82e2c5ecaf1
Diffstat (limited to 'Source')
-rw-r--r--Source/WebCore/platform/graphics/android/GLWebViewState.cpp13
-rw-r--r--Source/WebCore/platform/graphics/android/ShaderProgram.cpp31
-rw-r--r--Source/WebCore/platform/graphics/android/ShaderProgram.h29
-rw-r--r--Source/WebCore/platform/graphics/android/TilesManager.cpp1
-rw-r--r--Source/WebCore/platform/graphics/android/TilesManager.h5
-rw-r--r--Source/WebKit/android/nav/WebView.cpp2
6 files changed, 56 insertions, 25 deletions
diff --git a/Source/WebCore/platform/graphics/android/GLWebViewState.cpp b/Source/WebCore/platform/graphics/android/GLWebViewState.cpp
index 86f33e0..a29ab82 100644
--- a/Source/WebCore/platform/graphics/android/GLWebViewState.cpp
+++ b/Source/WebCore/platform/graphics/android/GLWebViewState.cpp
@@ -353,19 +353,16 @@ double GLWebViewState::setupDrawing(const IntRect& viewRect, const SkRect& visib
int height = viewRect.height();
TilesManager* tilesManager = TilesManager::instance();
- // Make sure the GL Context has not changed, otherwise, re-create all GL
- // resources. Only check this after onTrimMemory happens.
- bool contextChanged = tilesManager->contextChanged();
- tilesManager->setContextChanged(false);
-
// Make sure GL resources are created on the UI thread.
+ // They are created either for the first time, or after EGL context
+ // recreation caused by onTrimMemory in the framework.
ShaderProgram* shader = tilesManager->shader();
- if (shader->needsInit() || contextChanged) {
+ if (shader->needsInit()) {
XLOGC("Reinit shader");
- shader->init();
+ shader->initGLResources();
}
TransferQueue* transferQueue = tilesManager->transferQueue();
- if (transferQueue->needsInit() || contextChanged) {
+ if (transferQueue->needsInit()) {
XLOGC("Reinit transferQueue");
transferQueue->initGLResources(TilesManager::tileWidth(),
TilesManager::tileHeight());
diff --git a/Source/WebCore/platform/graphics/android/ShaderProgram.cpp b/Source/WebCore/platform/graphics/android/ShaderProgram.cpp
index 4925bd6..ba728ad 100644
--- a/Source/WebCore/platform/graphics/android/ShaderProgram.cpp
+++ b/Source/WebCore/platform/graphics/android/ShaderProgram.cpp
@@ -221,6 +221,9 @@ GLint ShaderProgram::createProgram(const char* pVertexSource, const char* pFragm
program = -1;
}
}
+
+ ShaderResource newResource(program, vertexShader, pixelShader);
+ m_resources.append(newResource);
return program;
}
@@ -233,12 +236,30 @@ ShaderProgram::ShaderProgram()
{
}
-void ShaderProgram::init()
+void ShaderProgram::cleanupGLResources()
+{
+ for (unsigned int i = 0; i < m_resources.size(); i++) {
+ glDetachShader(m_resources[i].program, m_resources[i].vertexShader);
+ glDetachShader(m_resources[i].program, m_resources[i].fragmentShader);
+ glDeleteShader(m_resources[i].vertexShader);
+ glDeleteShader(m_resources[i].fragmentShader);
+ glDeleteProgram(m_resources[i].program);
+ }
+ glDeleteBuffers(1, m_textureBuffer);
+
+ m_resources.clear();
+ m_needsInit = true;
+ GLUtils::checkGlError("cleanupGLResources");
+
+ return;
+}
+
+void ShaderProgram::initGLResources()
{
// To detect whether or not resources for ShaderProgram allocated
// successfully, we clean up pre-existing errors here and will check for
// new errors at the end of this function.
- GLUtils::checkGlError("before init");
+ GLUtils::checkGlError("before initGLResources");
GLint tex2DProgram = createProgram(gVertexShader, gFragmentShader);
GLint pureColorProgram = createProgram(gPureColorVertexShader, gPureColorFragmentShader);
@@ -324,11 +345,7 @@ void ShaderProgram::init()
matrix.translate3d(-0.5, -0.5, 0);
GLUtils::toGLMatrix(m_transferProjMtx, matrix);
- if (GLUtils::checkGlError("init"))
- m_needsInit = true;
- else
- m_needsInit = false;
-
+ m_needsInit = GLUtils::checkGlError("initGLResources");
return;
}
diff --git a/Source/WebCore/platform/graphics/android/ShaderProgram.h b/Source/WebCore/platform/graphics/android/ShaderProgram.h
index e528e60..5a0c52b 100644
--- a/Source/WebCore/platform/graphics/android/ShaderProgram.h
+++ b/Source/WebCore/platform/graphics/android/ShaderProgram.h
@@ -80,11 +80,31 @@ struct ShaderHandles {
GLint videoMtxHandle;
};
+struct ShaderResource {
+ ShaderResource()
+ : program(-1)
+ , vertexShader(-1)
+ , fragmentShader(-1)
+ {
+ };
+
+ ShaderResource(GLuint prog, GLuint vertex, GLuint fragment)
+ : program(prog)
+ , vertexShader(vertex)
+ , fragmentShader(fragment)
+ {
+ };
+
+ GLuint program;
+ GLuint vertexShader;
+ GLuint fragmentShader;
+};
+
class ShaderProgram {
public:
ShaderProgram();
- void init();
-
+ void initGLResources();
+ void cleanupGLResources();
// Drawing
void setupDrawing(const IntRect& viewRect, const SkRect& visibleRect,
const IntRect& webViewRect, int titleBarHeight,
@@ -124,7 +144,8 @@ public:
FloatRect documentViewport() { return m_documentViewport; }
float contrast() { return m_contrast; }
- void setContrast(float c) {
+ void setContrast(float c)
+ {
float contrast = c;
if (contrast < 0)
contrast = 0;
@@ -204,6 +225,8 @@ private:
// For transfer queue blitting, we need a special matrix map from (0,1) to
// (-1,1)
GLfloat m_transferProjMtx[16];
+
+ Vector<ShaderResource> m_resources;
};
} // namespace WebCore
diff --git a/Source/WebCore/platform/graphics/android/TilesManager.cpp b/Source/WebCore/platform/graphics/android/TilesManager.cpp
index 6640230..184d80c 100644
--- a/Source/WebCore/platform/graphics/android/TilesManager.cpp
+++ b/Source/WebCore/platform/graphics/android/TilesManager.cpp
@@ -110,7 +110,6 @@ TilesManager::TilesManager()
, m_drawGLCount(1)
, m_lastTimeLayersUsed(0)
, m_hasLayerTextures(false)
- , m_EGLContextChanged(true)
{
XLOG("TilesManager ctor");
m_textures.reserveCapacity(MAX_TEXTURE_ALLOCATION);
diff --git a/Source/WebCore/platform/graphics/android/TilesManager.h b/Source/WebCore/platform/graphics/android/TilesManager.h
index 749ba98..b670055 100644
--- a/Source/WebCore/platform/graphics/android/TilesManager.h
+++ b/Source/WebCore/platform/graphics/android/TilesManager.h
@@ -110,9 +110,6 @@ public:
void setHighEndGfx(bool highEnd);
bool highEndGfx();
- bool contextChanged() { return m_EGLContextChanged; }
- void setContextChanged(bool changed) { m_EGLContextChanged = changed; }
-
int maxTextureCount();
int maxLayerTextureCount();
void setMaxTextureCount(int max);
@@ -266,8 +263,6 @@ private:
unsigned long long m_drawGLCount;
double m_lastTimeLayersUsed;
bool m_hasLayerTextures;
-
- bool m_EGLContextChanged;
};
} // namespace WebCore
diff --git a/Source/WebKit/android/nav/WebView.cpp b/Source/WebKit/android/nav/WebView.cpp
index 624a696..a3f4233 100644
--- a/Source/WebKit/android/nav/WebView.cpp
+++ b/Source/WebKit/android/nav/WebView.cpp
@@ -1430,7 +1430,7 @@ static void nativeOnTrimMemory(JNIEnv *env, jobject obj, jint level)
if (level >= TRIM_MEMORY_MODERATE
&& !TilesManager::instance()->highEndGfx()) {
TilesManager::instance()->transferQueue()->emptyQueue();
- TilesManager::instance()->setContextChanged(true);
+ TilesManager::instance()->shader()->cleanupGLResources();
}
bool freeAllTextures = (level > TRIM_MEMORY_UI_HIDDEN), glTextures = true;