Bug 813372: Guard against TiledTextureImage with dimensions of 0. r=mattwoodrow a=blocking-basecamp
authorChris Jones <jones.chris.g@gmail.com>
Tue, 04 Dec 2012 00:39:21 -0800
changeset 114898 3932ed990e9b1f24c3aca313b3ca472232dfe1a1
parent 114897 fd841806e43bcdad3e82b380d5eeb5473cd016d3
child 114899 54731c5fdc2c08e31fa78cf7975bf309cd4da6d1
push id23947
push useremorley@mozilla.com
push dateTue, 04 Dec 2012 14:54:11 +0000
treeherdermozilla-central@0035f77045bc [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmattwoodrow, blocking-basecamp
bugs813372
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 813372: Guard against TiledTextureImage with dimensions of 0. r=mattwoodrow a=blocking-basecamp
gfx/gl/GLTextureImage.cpp
gfx/layers/opengl/ImageLayerOGL.cpp
--- a/gfx/gl/GLTextureImage.cpp
+++ b/gfx/gl/GLTextureImage.cpp
@@ -197,28 +197,32 @@ TiledTextureImage::TiledTextureImage(GLC
     , mInUpdate(false)
     , mRows(0)
     , mColumns(0)
     , mGL(aGL)
     , mTextureState(Created)
 {
     mTileSize = (!(aFlags & TextureImage::ForceSingleTile) && mGL->WantsSmallTiles())
         ? 256 : mGL->GetMaxTextureSize();
-    if (aSize != nsIntSize(0,0)) {
+    if (aSize.width != 0 && aSize.height != 0) {
         Resize(aSize);
     }
 }
 
 TiledTextureImage::~TiledTextureImage()
 {
 }
 
 bool
 TiledTextureImage::DirectUpdate(gfxASurface* aSurf, const nsIntRegion& aRegion, const nsIntPoint& aFrom /* = nsIntPoint(0, 0) */)
 {
+    if (mSize.width == 0 || mSize.height == 0) {
+        return true;
+    }
+
     nsIntRegion region;
 
     if (mTextureState != Valid) {
         nsIntRect bounds = nsIntRect(0, 0, mSize.width, mSize.height);
         region = nsIntRegion(bounds);
     } else {
         region = aRegion;
     }
@@ -427,16 +431,19 @@ void TiledTextureImage::SetIterationCall
                                              void* aCallbackData)
 {
     mIterationCallback = aCallback;
     mIterationCallbackData = aCallbackData;
 }
 
 nsIntRect TiledTextureImage::GetTileRect()
 {
+    if (!GetTileCount()) {
+        return nsIntRect();
+    }
     nsIntRect rect = mImages[mCurrentImage]->GetTileRect();
     unsigned int xPos = (mCurrentImage % mColumns) * mTileSize;
     unsigned int yPos = (mCurrentImage / mColumns) * mTileSize;
     rect.MoveBy(xPos, yPos);
     return rect;
 }
 
 nsIntRect TiledTextureImage::GetSrcTileRect()
@@ -446,16 +453,19 @@ nsIntRect TiledTextureImage::GetSrcTileR
                         ? mSize.height - rect.height - rect.y
                         : rect.y;
     return nsIntRect(rect.x, srcY, rect.width, rect.height);
 }
 
 void
 TiledTextureImage::BindTexture(GLenum aTextureUnit)
 {
+    if (!GetTileCount()) {
+        return;
+    }
     mImages[mCurrentImage]->BindTexture(aTextureUnit);
 }
 
 void
 TiledTextureImage::ApplyFilter()
 {
    mGL->ApplyFilterToBoundTexture(mFilter);
 }
--- a/gfx/layers/opengl/ImageLayerOGL.cpp
+++ b/gfx/layers/opengl/ImageLayerOGL.cpp
@@ -985,30 +985,36 @@ ShadowImageLayerOGL::RenderLayer(int aPr
     colorProgram->SetRenderOffset(aOffset);
     colorProgram->LoadMask(GetMaskLayer());
 
     mTexImage->SetFilter(mFilter);
     mTexImage->BeginTileIteration();
 
     if (gl()->CanUploadNonPowerOfTwo()) {
       do {
-        TextureImage::ScopedBindTextureAndApplyFilter texBind(mTexImage, LOCAL_GL_TEXTURE0);
-        colorProgram->SetLayerQuadRect(mTexImage->GetTileRect());
-        mOGLManager->BindAndDrawQuad(colorProgram);
+        nsIntRect rect = mTexImage->GetTileRect();
+        if (!rect.IsEmpty()) {
+          TextureImage::ScopedBindTextureAndApplyFilter texBind(mTexImage, LOCAL_GL_TEXTURE0);
+          colorProgram->SetLayerQuadRect(rect);
+          mOGLManager->BindAndDrawQuad(colorProgram);
+        }
       } while (mTexImage->NextTile());
     } else {
       do {
-        TextureImage::ScopedBindTextureAndApplyFilter texBind(mTexImage, LOCAL_GL_TEXTURE0);
-        colorProgram->SetLayerQuadRect(mTexImage->GetTileRect());
-        // We can't use BindAndDrawQuad because that always uploads the whole texture from 0.0f -> 1.0f
-        // in x and y. We use BindAndDrawQuadWithTextureRect to actually draw a subrect of the texture
-        mOGLManager->BindAndDrawQuadWithTextureRect(colorProgram,
-                                                    nsIntRect(0, 0, mTexImage->GetTileRect().width,
-                                                                    mTexImage->GetTileRect().height),
-                                                    mTexImage->GetTileRect().Size());
+        nsIntRect rect = mTexImage->GetTileRect();
+        if (!rect.IsEmpty()) {
+          TextureImage::ScopedBindTextureAndApplyFilter texBind(mTexImage, LOCAL_GL_TEXTURE0);
+          colorProgram->SetLayerQuadRect(rect);
+          // We can't use BindAndDrawQuad because that always uploads the whole texture from 0.0f -> 1.0f
+          // in x and y. We use BindAndDrawQuadWithTextureRect to actually draw a subrect of the texture
+          mOGLManager->BindAndDrawQuadWithTextureRect(colorProgram,
+                                                      nsIntRect(0, 0, mTexImage->GetTileRect().width,
+                                                                mTexImage->GetTileRect().height),
+                                                      mTexImage->GetTileRect().Size());
+        }
       } while (mTexImage->NextTile());
     }
 #ifdef MOZ_WIDGET_GONK
   } else if (mExternalBufferTexture.IsAllocated()) {
     gl()->MakeCurrent();
     gl()->fActiveTexture(LOCAL_GL_TEXTURE0);
     gl()->fBindTexture(LOCAL_GL_TEXTURE_EXTERNAL, mExternalBufferTexture.GetTextureID());