summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPierre-Antoine LaFayette <plafayet@codeaurora.org>2012-10-10 13:43:45 -0400
committerSteve Kondik <shade@chemlab.org>2013-01-20 18:38:31 -0800
commitc018655c37a1da5d7e1f9dc94d0467130cf630f1 (patch)
tree1fdea05f45d91439905ed7904b194e4747342364
parent77ab7f788fa2de43390a0ddb447c94a191284e88 (diff)
downloadexternal_webkit-c018655c37a1da5d7e1f9dc94d0467130cf630f1.zip
external_webkit-c018655c37a1da5d7e1f9dc94d0467130cf630f1.tar.gz
external_webkit-c018655c37a1da5d7e1f9dc94d0467130cf630f1.tar.bz2
Fix for memory leak in WebGL
CRs-fixed: 407009 (cherry-picked from commit 796a2a4cc637a3b04ee845e595b081e826207924) Change-Id: I584fe07dd5887ed52b74bc84044d510f8a2e2ba8
-rw-r--r--Source/WebCore/platform/graphics/android/GraphicsContext3DInternal.cpp7
-rw-r--r--Source/WebCore/platform/graphics/android/GraphicsContext3DProxy.cpp23
-rw-r--r--Source/WebCore/platform/graphics/android/GraphicsContext3DProxy.h3
-rw-r--r--Source/WebCore/platform/graphics/android/WebGLLayer.cpp5
-rw-r--r--Source/WebCore/platform/graphics/android/WebGLLayer.h3
5 files changed, 12 insertions, 29 deletions
diff --git a/Source/WebCore/platform/graphics/android/GraphicsContext3DInternal.cpp b/Source/WebCore/platform/graphics/android/GraphicsContext3DInternal.cpp
index 85c9719..7855739 100644
--- a/Source/WebCore/platform/graphics/android/GraphicsContext3DInternal.cpp
+++ b/Source/WebCore/platform/graphics/android/GraphicsContext3DInternal.cpp
@@ -170,8 +170,8 @@ GLint GraphicsContext3DInternal::checkGLError(const char* s)
GraphicsContext3DInternal::GraphicsContext3DInternal(HTMLCanvasElement* canvas,
GraphicsContext3D::Attributes attrs,
HostWindow* hostWindow)
- : m_proxy(new GraphicsContext3DProxy())
- , m_compositingLayer(new WebGLLayer(m_proxy.get()))
+ : m_proxy(adoptRef(new GraphicsContext3DProxy()))
+ , m_compositingLayer(new WebGLLayer(m_proxy))
, m_canvas(canvas)
, m_attrs(attrs)
, m_layerComposited(false)
@@ -200,7 +200,6 @@ GraphicsContext3DInternal::GraphicsContext3DInternal(HTMLCanvasElement* canvas,
}
LOGWEBGL("GraphicsContext3DInternal() = %p, m_compositingLayer = %p", this, m_compositingLayer);
- m_compositingLayer->ref();
m_proxy->setGraphicsContext(this);
if (!m_canvas || !m_canvas->document() || !m_canvas->document()->view())
@@ -284,7 +283,7 @@ GraphicsContext3DInternal::~GraphicsContext3DInternal()
m_proxy->setGraphicsContext(0);
MutexLocker lock(m_fboMutex);
- m_compositingLayer->unref();
+ SkSafeUnref(m_compositingLayer);
m_compositingLayer = 0;
deleteContext(true);
diff --git a/Source/WebCore/platform/graphics/android/GraphicsContext3DProxy.cpp b/Source/WebCore/platform/graphics/android/GraphicsContext3DProxy.cpp
index 0d273bb..e2ab6f9 100644
--- a/Source/WebCore/platform/graphics/android/GraphicsContext3DProxy.cpp
+++ b/Source/WebCore/platform/graphics/android/GraphicsContext3DProxy.cpp
@@ -34,6 +34,7 @@
namespace WebCore {
GraphicsContext3DProxy::GraphicsContext3DProxy()
+ : m_texture(0)
{
LOGWEBGL("GraphicsContext3DProxy::GraphicsContext3DProxy(), this = %p", this);
}
@@ -49,22 +50,6 @@ void GraphicsContext3DProxy::setGraphicsContext(GraphicsContext3DInternal* conte
m_context = context;
}
-void GraphicsContext3DProxy::incr()
-{
- MutexLocker lock(m_mutex);
- m_refcount++;
-}
-
-void GraphicsContext3DProxy::decr()
-{
- MutexLocker lock(m_mutex);
- m_refcount--;
- if (m_refcount == 0) {
- glDeleteTextures(1, &m_texture);
- m_texture = 0;
- }
-}
-
bool GraphicsContext3DProxy::lockFrontBuffer(GLuint& texture, SkRect& rect)
{
MutexLocker lock(m_mutex);
@@ -79,6 +64,7 @@ bool GraphicsContext3DProxy::lockFrontBuffer(GLuint& texture, SkRect& rect)
glBindTexture(GL_TEXTURE_EXTERNAL_OES, m_texture);
glEGLImageTargetTexture2DOES(GL_TEXTURE_EXTERNAL_OES, image);
+ glBindTexture(GL_TEXTURE_EXTERNAL_OES, 0);
texture = m_texture;
}
@@ -88,10 +74,13 @@ bool GraphicsContext3DProxy::lockFrontBuffer(GLuint& texture, SkRect& rect)
void GraphicsContext3DProxy::releaseFrontBuffer()
{
MutexLocker lock(m_mutex);
+ if (m_texture) {
+ glDeleteTextures(1, &m_texture);
+ m_texture = 0;
+ }
if (!m_context) {
return;
}
- glBindTexture(GL_TEXTURE_EXTERNAL_OES, 0);
m_context->releaseFrontBuffer();
}
}
diff --git a/Source/WebCore/platform/graphics/android/GraphicsContext3DProxy.h b/Source/WebCore/platform/graphics/android/GraphicsContext3DProxy.h
index 060acdf..1cc1453 100644
--- a/Source/WebCore/platform/graphics/android/GraphicsContext3DProxy.h
+++ b/Source/WebCore/platform/graphics/android/GraphicsContext3DProxy.h
@@ -47,8 +47,6 @@ public:
~GraphicsContext3DProxy();
void setGraphicsContext(GraphicsContext3DInternal* context);
- void incr();
- void decr();
bool lockFrontBuffer(GLuint& texture, SkRect& rect);
void releaseFrontBuffer();
@@ -57,7 +55,6 @@ private:
WTF::Mutex m_mutex;
GraphicsContext3DInternal* m_context;
GLuint m_texture;
- int m_refcount;
};
}
diff --git a/Source/WebCore/platform/graphics/android/WebGLLayer.cpp b/Source/WebCore/platform/graphics/android/WebGLLayer.cpp
index af1f31d..9feb2e1 100644
--- a/Source/WebCore/platform/graphics/android/WebGLLayer.cpp
+++ b/Source/WebCore/platform/graphics/android/WebGLLayer.cpp
@@ -37,23 +37,20 @@
namespace WebCore {
-WebGLLayer::WebGLLayer(GraphicsContext3DProxy* proxy)
+WebGLLayer::WebGLLayer(PassRefPtr<GraphicsContext3DProxy> proxy)
: LayerAndroid((RenderLayer*)0)
, m_proxy(proxy)
{
- m_proxy->incr();
}
WebGLLayer::WebGLLayer(const WebGLLayer& layer)
: LayerAndroid(layer)
, m_proxy(layer.m_proxy)
{
- m_proxy->incr();
}
WebGLLayer::~WebGLLayer()
{
- m_proxy->decr();
}
bool WebGLLayer::drawGL(bool layerTilesDisabled)
diff --git a/Source/WebCore/platform/graphics/android/WebGLLayer.h b/Source/WebCore/platform/graphics/android/WebGLLayer.h
index e7371f7..6a69082 100644
--- a/Source/WebCore/platform/graphics/android/WebGLLayer.h
+++ b/Source/WebCore/platform/graphics/android/WebGLLayer.h
@@ -34,6 +34,7 @@
#include "GLUtils.h"
#include "GraphicsContext3DProxy.h"
#include "LayerAndroid.h"
+#include "PassRefPtr.h"
#include "RefPtr.h"
#include <jni.h>
@@ -43,7 +44,7 @@ class GraphicsContext3DInternal;
class WebGLLayer : public LayerAndroid {
public:
- WebGLLayer(GraphicsContext3DProxy* proxy);
+ WebGLLayer(PassRefPtr<GraphicsContext3DProxy> proxy);
WebGLLayer(const WebGLLayer& layer);
virtual ~WebGLLayer();