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())
? 256 : mGL->GetMaxTextureSize();
if (aSize != nsIntSize(0,0)) {
if (aSize.width != 0 && aSize.height != 0) {
Resize(aSize);
}
}
@ -214,6 +214,10 @@ 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) {
@ -432,6 +436,9 @@ void TiledTextureImage::SetIterationCallback(TileIterationCallback aCallback,
nsIntRect TiledTextureImage::GetTileRect()
{
if (!GetTileCount()) {
return nsIntRect();
}
nsIntRect rect = mImages[mCurrentImage]->GetTileRect();
unsigned int xPos = (mCurrentImage % mColumns) * mTileSize;
unsigned int yPos = (mCurrentImage / mColumns) * mTileSize;
@ -451,6 +458,9 @@ nsIntRect TiledTextureImage::GetSrcTileRect()
void
TiledTextureImage::BindTexture(GLenum aTextureUnit)
{
if (!GetTileCount()) {
return;
}
mImages[mCurrentImage]->BindTexture(aTextureUnit);
}

View File

@ -990,20 +990,26 @@ ShadowImageLayerOGL::RenderLayer(int aPreviousFrameBuffer,
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