Bug 813372: Guard against TiledTextureImage with dimensions of 0. r=mattwoodrow a=blocking-basecamp

This commit is contained in:
Chris Jones 2012-12-04 00:39:21 -08:00
parent 2756b7d1d0
commit 61c95ce59c
2 changed files with 28 additions and 12 deletions

View File

@ -202,7 +202,7 @@ TiledTextureImage::TiledTextureImage(GLContext* aGL,
{ {
mTileSize = (!(aFlags & TextureImage::ForceSingleTile) && mGL->WantsSmallTiles()) mTileSize = (!(aFlags & TextureImage::ForceSingleTile) && mGL->WantsSmallTiles())
? 256 : mGL->GetMaxTextureSize(); ? 256 : mGL->GetMaxTextureSize();
if (aSize != nsIntSize(0,0)) { if (aSize.width != 0 && aSize.height != 0) {
Resize(aSize); Resize(aSize);
} }
} }
@ -214,6 +214,10 @@ TiledTextureImage::~TiledTextureImage()
bool bool
TiledTextureImage::DirectUpdate(gfxASurface* aSurf, const nsIntRegion& aRegion, const nsIntPoint& aFrom /* = nsIntPoint(0, 0) */) TiledTextureImage::DirectUpdate(gfxASurface* aSurf, const nsIntRegion& aRegion, const nsIntPoint& aFrom /* = nsIntPoint(0, 0) */)
{ {
if (mSize.width == 0 || mSize.height == 0) {
return true;
}
nsIntRegion region; nsIntRegion region;
if (mTextureState != Valid) { if (mTextureState != Valid) {
@ -432,6 +436,9 @@ void TiledTextureImage::SetIterationCallback(TileIterationCallback aCallback,
nsIntRect TiledTextureImage::GetTileRect() nsIntRect TiledTextureImage::GetTileRect()
{ {
if (!GetTileCount()) {
return nsIntRect();
}
nsIntRect rect = mImages[mCurrentImage]->GetTileRect(); nsIntRect rect = mImages[mCurrentImage]->GetTileRect();
unsigned int xPos = (mCurrentImage % mColumns) * mTileSize; unsigned int xPos = (mCurrentImage % mColumns) * mTileSize;
unsigned int yPos = (mCurrentImage / mColumns) * mTileSize; unsigned int yPos = (mCurrentImage / mColumns) * mTileSize;
@ -451,6 +458,9 @@ nsIntRect TiledTextureImage::GetSrcTileRect()
void void
TiledTextureImage::BindTexture(GLenum aTextureUnit) TiledTextureImage::BindTexture(GLenum aTextureUnit)
{ {
if (!GetTileCount()) {
return;
}
mImages[mCurrentImage]->BindTexture(aTextureUnit); mImages[mCurrentImage]->BindTexture(aTextureUnit);
} }

View File

@ -990,20 +990,26 @@ ShadowImageLayerOGL::RenderLayer(int aPreviousFrameBuffer,
if (gl()->CanUploadNonPowerOfTwo()) { if (gl()->CanUploadNonPowerOfTwo()) {
do { do {
TextureImage::ScopedBindTextureAndApplyFilter texBind(mTexImage, LOCAL_GL_TEXTURE0); nsIntRect rect = mTexImage->GetTileRect();
colorProgram->SetLayerQuadRect(mTexImage->GetTileRect()); if (!rect.IsEmpty()) {
mOGLManager->BindAndDrawQuad(colorProgram); TextureImage::ScopedBindTextureAndApplyFilter texBind(mTexImage, LOCAL_GL_TEXTURE0);
colorProgram->SetLayerQuadRect(rect);
mOGLManager->BindAndDrawQuad(colorProgram);
}
} while (mTexImage->NextTile()); } while (mTexImage->NextTile());
} else { } else {
do { do {
TextureImage::ScopedBindTextureAndApplyFilter texBind(mTexImage, LOCAL_GL_TEXTURE0); nsIntRect rect = mTexImage->GetTileRect();
colorProgram->SetLayerQuadRect(mTexImage->GetTileRect()); if (!rect.IsEmpty()) {
// We can't use BindAndDrawQuad because that always uploads the whole texture from 0.0f -> 1.0f TextureImage::ScopedBindTextureAndApplyFilter texBind(mTexImage, LOCAL_GL_TEXTURE0);
// in x and y. We use BindAndDrawQuadWithTextureRect to actually draw a subrect of the texture colorProgram->SetLayerQuadRect(rect);
mOGLManager->BindAndDrawQuadWithTextureRect(colorProgram, // We can't use BindAndDrawQuad because that always uploads the whole texture from 0.0f -> 1.0f
nsIntRect(0, 0, mTexImage->GetTileRect().width, // in x and y. We use BindAndDrawQuadWithTextureRect to actually draw a subrect of the texture
mTexImage->GetTileRect().height), mOGLManager->BindAndDrawQuadWithTextureRect(colorProgram,
mTexImage->GetTileRect().Size()); nsIntRect(0, 0, mTexImage->GetTileRect().width,
mTexImage->GetTileRect().height),
mTexImage->GetTileRect().Size());
}
} while (mTexImage->NextTile()); } while (mTexImage->NextTile());
} }
#ifdef MOZ_WIDGET_GONK #ifdef MOZ_WIDGET_GONK