Bug 826628 - Release the texture after unbind it. r=jgilbert
authorKan-Ru Chen (陳侃如) <kanru@kanru.info>
Sat, 05 Jan 2013 11:20:50 +0800
changeset 126811 dc3d10cccb8681f6b34fed79d9a864a5bccbd4fb
parent 126810 a0414feb9656087500ebcea200ac3162af4c4dde
child 126812 bd3b4d20072a3cd9b040ecfca0d5a9217c1cc59e
push id2151
push userlsblakk@mozilla.com
push dateTue, 19 Feb 2013 18:06:57 +0000
treeherdermozilla-beta@4952e88741ec [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjgilbert
bugs826628
milestone20.0a1
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 826628 - Release the texture after unbind it. r=jgilbert
gfx/layers/opengl/ImageLayerOGL.cpp
--- a/gfx/layers/opengl/ImageLayerOGL.cpp
+++ b/gfx/layers/opengl/ImageLayerOGL.cpp
@@ -966,50 +966,51 @@ ShadowImageLayerOGL::RenderLayer(int aPr
   if (mOGLManager->CompositingDisabled()) {
     return;
   }
   mOGLManager->MakeCurrent();
   if (mImageContainerID) {
     ImageContainerParent::SetCompositorIDForImage(mImageContainerID,
                                                   mOGLManager->GetCompositorID());
     uint32_t imgVersion = ImageContainerParent::GetSharedImageVersion(mImageContainerID);
+    SharedImage* img = ImageContainerParent::GetSharedImage(mImageContainerID);
     if (imgVersion != mImageVersion) {
-      SharedImage* img = ImageContainerParent::GetSharedImage(mImageContainerID);
       if (img && (img->type() == SharedImage::TYUVImage)) {
         UploadSharedYUVToTexture(img->get_YUVImage());
   
         mImageVersion = imgVersion;
       } else if (img && (img->type() == SharedImage::TYCbCrImage)) {
         ShmemYCbCrImage shmemImage(img->get_YCbCrImage().data(),
                                    img->get_YCbCrImage().offset());
         UploadSharedYCbCrToTexture(shmemImage, img->get_YCbCrImage().picture());
 
         mImageVersion = imgVersion;
       } else if (img && (img->type() == SharedImage::TRGBImage)) {
         UploadSharedRGBToTexture(&img->get_RGBImage().data(),
                                  img->get_RGBImage().picture(),
                                  img->get_RGBImage().rgbFormat());
         mImageVersion = imgVersion;
-#ifdef MOZ_WIDGET_GONK
-      } else if (img
-                 && (img->type() == SharedImage::TSurfaceDescriptor)
-                 && (img->get_SurfaceDescriptor().type() == SurfaceDescriptor::TSurfaceDescriptorGralloc)) {
-        const SurfaceDescriptorGralloc& desc = img->get_SurfaceDescriptor().get_SurfaceDescriptorGralloc();
-        sp<GraphicBuffer> graphicBuffer = GrallocBufferActor::GetFrom(desc);
-        mSize = gfxIntSize(graphicBuffer->getWidth(), graphicBuffer->getHeight());
-        if (!mExternalBufferTexture.IsAllocated()) {
-          mExternalBufferTexture.Allocate(gl());
-        }
-        gl()->MakeCurrent();
-        gl()->fActiveTexture(LOCAL_GL_TEXTURE0);
-        gl()->BindExternalBuffer(mExternalBufferTexture.GetTextureID(), graphicBuffer->getNativeBuffer());
-        mImageVersion = imgVersion;
-#endif
       }
     }
+#ifdef MOZ_WIDGET_GONK
+    if (img
+        && (img->type() == SharedImage::TSurfaceDescriptor)
+        && (img->get_SurfaceDescriptor().type() == SurfaceDescriptor::TSurfaceDescriptorGralloc)) {
+      const SurfaceDescriptorGralloc& desc = img->get_SurfaceDescriptor().get_SurfaceDescriptorGralloc();
+      sp<GraphicBuffer> graphicBuffer = GrallocBufferActor::GetFrom(desc);
+      mSize = gfxIntSize(graphicBuffer->getWidth(), graphicBuffer->getHeight());
+      if (!mExternalBufferTexture.IsAllocated()) {
+        mExternalBufferTexture.Allocate(gl());
+      }
+      gl()->MakeCurrent();
+      gl()->fActiveTexture(LOCAL_GL_TEXTURE0);
+      gl()->BindExternalBuffer(mExternalBufferTexture.GetTextureID(), graphicBuffer->getNativeBuffer());
+      mImageVersion = imgVersion;
+    }
+#endif
   }
 
 
   if (mTexImage) {
     NS_ASSERTION(mTexImage->GetContentType() != gfxASurface::CONTENT_ALPHA,
                  "Image layer has alpha image");
 
     ShaderProgramOGL *colorProgram =
@@ -1064,17 +1065,21 @@ ShadowImageLayerOGL::RenderLayer(int aPr
                                         mSize.width, mSize.height));
     program->SetLayerTransform(GetEffectiveTransform());
     program->SetLayerOpacity(GetEffectiveOpacity());
     program->SetRenderOffset(aOffset);
     program->SetTextureUnit(0);
     program->LoadMask(GetMaskLayer());
 
     mOGLManager->BindAndDrawQuad(program);
+
+    // Make sure that we release the underlying external image
+    gl()->fActiveTexture(LOCAL_GL_TEXTURE0);
     gl()->fBindTexture(LOCAL_GL_TEXTURE_EXTERNAL, 0);
+    mExternalBufferTexture.Release();
 #endif
   } else if (mSharedHandle) {
     GLContext::SharedHandleDetails handleDetails;
     if (!gl()->GetSharedHandleDetails(mShareType, mSharedHandle, handleDetails)) {
       NS_ERROR("Failed to get shared handle details");
       return;
     }