OSDN Git Service

Fix error where mediaLayer is derefed on UI thread prior to being derefed in Webkit.
authorDerek Sollenberger <djsollen@google.com>
Fri, 25 Mar 2011 14:43:12 +0000 (10:43 -0400)
committerDerek Sollenberger <djsollen@google.com>
Fri, 25 Mar 2011 14:45:26 +0000 (10:45 -0400)
bug: 4171470
Change-Id: I6afe957b2eccae249afa46baede822c34f8f1a7f

WebCore/platform/graphics/android/DoubleBufferedTexture.cpp
WebCore/platform/graphics/android/DoubleBufferedTexture.h
WebCore/platform/graphics/android/MediaTexture.cpp
WebCore/platform/graphics/android/SharedTexture.cpp
WebCore/platform/graphics/android/SharedTexture.h

index cf640e8..395bb2b 100644 (file)
@@ -114,6 +114,18 @@ void DoubleBufferedTexture::producerDeleteTextures()
     m_textureB.unlock();
 }
 
+void DoubleBufferedTexture::consumerDeleteTextures()
+{
+    m_textureA.lock();
+    m_textureB.lock();
+    LOGV("Deleting Consumer Textures A/B (%d:%d)", m_textureA.getTargetTextureId(),
+                                                   m_textureB.getTargetTextureId());
+    m_textureA.deleteTargetTexture();
+    m_textureB.deleteTargetTexture();
+    m_textureA.unlock();
+    m_textureB.unlock();
+}
+
 TextureInfo* DoubleBufferedTexture::producerLock()
 {
     SharedTexture* sharedTex = getWriteableTexture();
index 8a9d81e..ba56c0e 100644 (file)
@@ -47,6 +47,7 @@ public:
     // consumer thread functions
     TextureInfo* consumerLock();
     void consumerRelease();
+    void consumerDeleteTextures();
 
 protected:
     SharedTexture* getReadableTexture();
index 9821065..14f0c20 100644 (file)
@@ -104,8 +104,9 @@ void MediaTexture::consumerInc()
 /* Decrement the number of objects in the consumer's thread that are holding a
  * reference to this object. When removing the last reference we must delete
  * this object and by extension cleanup all GL objects that are associated with
- * the consumer's thread. At the time of deletion there should be no remaining
- * producer references.
+ * the consumer's thread. At the time of deletion if there is a remaining
+ * producer reference we must cleanup the consumer GL objects in the event that
+ * this texture will not be re-synced with the UI thread.
  */
 void MediaTexture::consumerDec()
 {
@@ -114,9 +115,10 @@ void MediaTexture::consumerDec()
     m_mediaLock.lock();
     m_consumerRefCount--;
     if (m_consumerRefCount == 0) {
-        needsDeleted = true;
-        if (m_producerRefCount != 0) {
-            XLOG("ERROR: We should not delete the consumer before the producer is finished");
+        consumerDeleteTextures();
+        if (m_producerRefCount < 1) {
+            XLOG("WARNING: This texture still exists within webkit.");
+            needsDeleted = true;
         }
     }
     m_mediaLock.unlock();
index 8c703d4..495fdd0 100644 (file)
@@ -80,10 +80,7 @@ SharedTexture::SharedTexture()
 // source texture and EGLImage is the responsibility of the caller.
 SharedTexture::~SharedTexture()
 {
-    if (m_supportsEGLImage)
-        GLUtils::deleteTexture(&m_targetTexture.m_textureId);
-    else
-        GLUtils::deleteTexture(&m_sourceTexture.m_textureId);
+    deleteTargetTexture();
 }
 
 void SharedTexture::initSourceTexture()
@@ -120,6 +117,14 @@ void SharedTexture::deleteSourceTexture()
     }
 }
 
+void SharedTexture::deleteTargetTexture()
+{
+    if (m_supportsEGLImage)
+        GLUtils::deleteTexture(&m_targetTexture.m_textureId);
+    else
+        GLUtils::deleteTexture(&m_sourceTexture.m_textureId);
+}
+
 TextureInfo* SharedTexture::lockSource()
 {
     m_lock.lock();
index 731aa5c..37d6091 100644 (file)
@@ -81,6 +81,7 @@ public:
 
     void initSourceTexture(); // producer thread only
     void deleteSourceTexture(); // producer thread only
+    void deleteTargetTexture(); // consumer thread only
     GLuint getSourceTextureId() { return m_sourceTexture.m_textureId; }
     GLuint getTargetTextureId() { return m_targetTexture.m_textureId; }
     EGLImageKHR getEGLImage() { return m_eglImage; }