Bug 595055 - Use the correct context when deleting textures, so we don't accidentally unset some state like the viewport. r=vlad a=b
authorJoe Drew <joe@drew.ca>
Thu, 09 Sep 2010 23:09:39 -0400
changeset 53690 508d0a50827c32b4b7ec0940595aebcef7353108
parent 53689 46c0a7c9e4f5ba256e620309f41f03dbb22bdeb1
child 53691 84ee6bc0484dd0e9c2193461f33a481a28e92371
push id15675
push uservladimir@mozilla.com
push dateMon, 13 Sep 2010 03:11:36 +0000
treeherdermozilla-central@508d0a50827c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersvlad, b
bugs595055
milestone2.0b6pre
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 595055 - Use the correct context when deleting textures, so we don't accidentally unset some state like the viewport. r=vlad a=b
gfx/thebes/GLContext.cpp
gfx/thebes/GLContext.h
--- a/gfx/thebes/GLContext.cpp
+++ b/gfx/thebes/GLContext.cpp
@@ -39,16 +39,18 @@
  * ***** END LICENSE BLOCK ***** */
 
 
 #include <string.h>
 #include <stdio.h>
 
 #include "prlink.h"
 
+#include "nsThreadUtils.h"
+
 #include "gfxImageSurface.h"
 #include "GLContext.h"
 #include "GLContextProvider.h"
 
 namespace mozilla {
 namespace gl {
 
 // define this here since it's global to GLContextProvider, not any
@@ -431,22 +433,29 @@ GLContext::CreateTextureImage(const nsIn
   fTexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_WRAP_T, aWrapMode);
   DEBUG_GL_ERROR_CHECK(this);
 
   return CreateBasicTextureImage(texture, aSize, aContentType, this);
 }
 
 BasicTextureImage::~BasicTextureImage()
 {
-    nsRefPtr<GLContext> ctx = mGLContext->GetSharedContext();
-    if (!ctx) {
-      ctx = mGLContext;
+    GLContext *ctx = mGLContext;
+    if (ctx->IsDestroyed() || !NS_IsMainThread()) {
+        ctx = ctx->GetSharedContext();
     }
-    ctx->MakeCurrent();
-    ctx->fDeleteTextures(1, &mTexture);
+
+    // If we have a context, then we need to delete the texture;
+    // if we don't have a context (either real or shared),
+    // then they went away when the contex was deleted, because it
+    // was the only one that had access to it.
+    if (ctx && !ctx->IsDestroyed()) {
+        mGLContext->MakeCurrent();
+        mGLContext->fDeleteTextures(1, &mTexture);
+    }
 }
 
 gfxContext*
 BasicTextureImage::BeginUpdate(nsIntRegion& aRegion)
 {
     NS_ASSERTION(!mUpdateContext, "BeginUpdate() without EndUpdate()?");
 
     // determine the region the client will need to repaint
--- a/gfx/thebes/GLContext.h
+++ b/gfx/thebes/GLContext.h
@@ -388,16 +388,21 @@ public:
     void SetUserData(void *aKey, void *aValue) {
         mUserData.Put(aKey, aValue);
     }
 
     // Mark this context as destroyed.  This will NULL out all
     // the GL function pointers!
     void THEBES_API MarkDestroyed();
 
+    PRBool IsDestroyed() {
+        // MarkDestroyed will mark all these as null.
+        return fUseProgram == nsnull;
+    }
+
     enum NativeDataType {
       NativeGLContext,
       NativeImageSurface,
       NativeThebesSurface,
       NativeDataTypeMax
     };
 
     virtual void *GetNativeData(NativeDataType aType) { return NULL; }