Bug 1444373 - Don't crash when trying to draw an empty RectTextureImage. r?mattwoodrow
MozReview-Commit-ID: EsnxswIaABQ
--- a/widget/cocoa/RectTextureImage.h
+++ b/widget/cocoa/RectTextureImage.h
@@ -59,17 +59,17 @@ public:
void Draw(mozilla::layers::GLManager* aManager,
const LayoutDeviceIntPoint& aLocation,
const gfx::Matrix4x4& aTransform = gfx::Matrix4x4());
protected:
void DeleteTexture();
- void BindIOSurfaceToTexture(gl::GLContext* aGL);
+ bool BindIOSurfaceToTexture(gl::GLContext* aGL);
RefPtr<MacIOSurface> mIOSurface;
gl::GLContext* mGLContext;
LayoutDeviceIntRegion mUpdateRegion;
LayoutDeviceIntSize mBufferSize;
GLuint mTexture;
bool mInUpdate;
};
--- a/widget/cocoa/RectTextureImage.mm
+++ b/widget/cocoa/RectTextureImage.mm
@@ -103,17 +103,20 @@ RectTextureImage::UpdateFromCGContext(co
void
RectTextureImage::Draw(layers::GLManager* aManager,
const LayoutDeviceIntPoint& aLocation,
const gfx::Matrix4x4& aTransform)
{
gl::GLContext* gl = aManager->gl();
- BindIOSurfaceToTexture(gl);
+ bool bound = BindIOSurfaceToTexture(gl);
+ if (!bound) {
+ return;
+ }
layers::ShaderProgramOGL* program =
aManager->GetProgram(LOCAL_GL_TEXTURE_RECTANGLE_ARB,
gfx::SurfaceFormat::R8G8B8A8);
gl->fActiveTexture(LOCAL_GL_TEXTURE0);
gl::ScopedBindTexture texture(gl, mTexture, LOCAL_GL_TEXTURE_RECTANGLE_ARB);
@@ -136,19 +139,25 @@ RectTextureImage::DeleteTexture()
if (mTexture) {
MOZ_ASSERT(mGLContext);
mGLContext->MakeCurrent();
mGLContext->fDeleteTextures(1, &mTexture);
mTexture = 0;
}
}
-void
+bool
RectTextureImage::BindIOSurfaceToTexture(gl::GLContext* aGL)
{
+ if (!mIOSurface) {
+ // If our size is zero or MacIOSurface::CreateIOSurface failed for some
+ // other reason, there's nothing we can bind.
+ return false;
+ }
+
if (!mTexture) {
MOZ_ASSERT(aGL);
aGL->fGenTextures(1, &mTexture);
aGL->fActiveTexture(LOCAL_GL_TEXTURE0);
gl::ScopedBindTexture texture(aGL, mTexture, LOCAL_GL_TEXTURE_RECTANGLE_ARB);
aGL->fTexParameteri(LOCAL_GL_TEXTURE_RECTANGLE_ARB,
LOCAL_GL_TEXTURE_MIN_FILTER,
LOCAL_GL_LINEAR);
@@ -162,12 +171,14 @@ RectTextureImage::BindIOSurfaceToTexture
LOCAL_GL_TEXTURE_WRAP_S,
LOCAL_GL_CLAMP_TO_EDGE);
mIOSurface->CGLTexImageIOSurface2D(aGL,
gl::GLContextCGL::Cast(aGL)->GetCGLContext(),
0);
mGLContext = aGL;
}
+
+ return true;
}
} // namespace widget
} // namespace mozilla