Bug 757347; checking the format of images. r=roc
authorNicholas Cameron <ncameron@mozilla.com>
Tue, 26 Jun 2012 09:44:41 +1200
changeset 102898 673264ebb9ea98e6175cbc5f9150d183c751693a
parent 102897 ce4804e41b2144c3df06f0c6e167e6cdeb516cbe
child 102899 75c9e54e17f2bb789e6215a0a21110cceb7abd31
push id191
push userlsblakk@mozilla.com
push dateFri, 05 Oct 2012 17:12:53 +0000
treeherdermozilla-release@ddb22ac6c03b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc
bugs757347
milestone16.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 757347; checking the format of images. r=roc
gfx/layers/basic/BasicLayers.cpp
gfx/layers/d3d10/ImageLayerD3D10.cpp
gfx/layers/d3d9/ImageLayerD3D9.cpp
gfx/layers/opengl/ImageLayerOGL.cpp
--- a/gfx/layers/basic/BasicLayers.cpp
+++ b/gfx/layers/basic/BasicLayers.cpp
@@ -905,16 +905,19 @@ BasicImageLayer::GetAndPaintCurrentImage
   AutoLockImage autoLock(mContainer, getter_AddRefs(surface));
   Image *image = autoLock.GetImage();
   gfxIntSize size = mSize = autoLock.GetSize();
 
   if (!surface || surface->CairoStatus()) {
     return nsnull;
   }
 
+  NS_ASSERTION(surface->GetContentType() != gfxASurface::CONTENT_ALPHA,
+               "Image layer has alpha image");
+
   nsRefPtr<gfxPattern> pat = new gfxPattern(surface);
   if (!pat) {
     return nsnull;
   }
 
   pat->SetFilter(mFilter);
   gfxIntSize sourceSize = surface->GetSize();
   if (mScaleMode != SCALE_NONE) {
--- a/gfx/layers/d3d10/ImageLayerD3D10.cpp
+++ b/gfx/layers/d3d10/ImageLayerD3D10.cpp
@@ -186,16 +186,20 @@ ImageLayerD3D10::RenderLayer()
   SetEffectTransformAndOpacity();
 
   ID3D10EffectTechnique *technique;
   nsRefPtr<IDXGIKeyedMutex> keyedMutex;
 
   if (image->GetFormat() == Image::CAIRO_SURFACE || image->GetFormat() == Image::REMOTE_IMAGE_BITMAP ||
       image->GetFormat() == Image::REMOTE_IMAGE_DXGI_TEXTURE)
   {
+    NS_ASSERTION(image->GetFormat() != Image::CAIRO_SURFACE ||
+                 !static_cast<CairoImage*>(image)->mSurface ||
+                 static_cast<CairoImage*>(image)->mSurface->GetContentType() != gfxASurface::CONTENT_ALPHA,
+                 "Image layer has alpha image");
     bool hasAlpha = false;
 
     nsRefPtr<ID3D10ShaderResourceView> srView = GetImageSRView(image, hasAlpha, getter_AddRefs(keyedMutex));
     if (!srView) {
       return;
     }
     
     PRUint8 shaderFlags = SHADER_PREMUL;
--- a/gfx/layers/d3d9/ImageLayerD3D9.cpp
+++ b/gfx/layers/d3d9/ImageLayerD3D9.cpp
@@ -367,16 +367,21 @@ ImageLayerD3D9::RenderLayer()
 
   SetShaderTransformAndOpacity();
 
   gfxIntSize size = mScaleMode == SCALE_NONE ? image->GetSize() : mScaleToSize;
 
   if (image->GetFormat() == Image::CAIRO_SURFACE ||
       image->GetFormat() == Image::REMOTE_IMAGE_BITMAP)
   {
+    NS_ASSERTION(image->GetFormat() != Image::CAIRO_SURFACE ||
+                 !static_cast<CairoImage*>(image)->mSurface ||
+                 static_cast<CairoImage*>(image)->mSurface->GetContentType() != gfxASurface::CONTENT_ALPHA,
+                 "Image layer has alpha image");
+
     bool hasAlpha = false;
     nsRefPtr<IDirect3DTexture9> texture = GetTexture(image, hasAlpha);
 
     device()->SetVertexShaderConstantF(CBvLayerQuad,
                                        ShaderConstantRect(0,
                                                           0,
                                                           size.width,
                                                           size.height),
--- a/gfx/layers/opengl/ImageLayerOGL.cpp
+++ b/gfx/layers/opengl/ImageLayerOGL.cpp
@@ -266,16 +266,19 @@ ImageLayerOGL::RenderLayer(int,
   } else if (image->GetFormat() == Image::CAIRO_SURFACE) {
     CairoImage *cairoImage =
       static_cast<CairoImage*>(image);
 
     if (!cairoImage->mSurface) {
       return;
     }
 
+    NS_ASSERTION(cairoImage->mSurface->GetContentType() != gfxASurface::CONTENT_ALPHA,
+                 "Image layer has alpha image");
+
     CairoOGLBackendData *data =
       static_cast<CairoOGLBackendData*>(cairoImage->GetBackendData(LayerManager::LAYERS_OPENGL));
 
     if (data && data->mTexture.GetGLContext() != gl()) {
       // If this texture was allocated by another layer manager, clear
       // it out and re-allocate below.
       data = nsnull;
       cairoImage->SetBackendData(LayerManager::LAYERS_OPENGL, nsnull);
@@ -589,16 +592,19 @@ ImageLayerOGL::LoadAsTexture(GLuint aTex
   if (!cairoImage->mSurface) {
     return false;
   }
 
   CairoOGLBackendData *data = static_cast<CairoOGLBackendData*>(
     cairoImage->GetBackendData(LayerManager::LAYERS_OPENGL));
 
   if (!data) {
+    NS_ASSERTION(cairoImage->mSurface->GetContentType() == gfxASurface::CONTENT_ALPHA,
+                 "OpenGL mask layers must be backed by alpha surfaces");
+
     // allocate a new texture and save the details in the backend data
     data = new CairoOGLBackendData;
     data->mTextureSize = CalculatePOTSize(cairoImage->mSize, gl());
 
     GLTexture &texture = data->mTexture;
     texture.Allocate(mOGLManager->gl());
 
     if (!texture.IsAllocated()) {
@@ -770,16 +776,19 @@ ShadowImageLayerOGL::GetLayer()
 
 void
 ShadowImageLayerOGL::RenderLayer(int aPreviousFrameBuffer,
                                  const nsIntPoint& aOffset)
 {
   mOGLManager->MakeCurrent();
 
   if (mTexImage) {
+    NS_ASSERTION(mTexImage->GetContentType() != gfxASurface::CONTENT_ALPHA,
+                 "Image layer has alpha image");
+
     ShaderProgramOGL *colorProgram =
       mOGLManager->GetProgram(mTexImage->GetShaderProgramType(), GetMaskLayer());
 
     colorProgram->Activate();
     colorProgram->SetTextureUnit(0);
     colorProgram->SetLayerTransform(GetEffectiveTransform());
     colorProgram->SetLayerOpacity(GetEffectiveOpacity());
     colorProgram->SetRenderOffset(aOffset);
@@ -840,16 +849,19 @@ bool
 ShadowImageLayerOGL::LoadAsTexture(GLuint aTextureUnit, gfxIntSize* aSize)
 {
   if (!mTexImage) {
     return false;
   }
 
   mTexImage->BindTextureAndApplyFilter(aTextureUnit);
 
+  NS_ASSERTION(mTexImage->GetContentType() == gfxASurface::CONTENT_ALPHA,
+               "OpenGL mask layers must be backed by alpha surfaces");
+
   // We're assuming that the gl backend won't cheat and use NPOT
   // textures when glContext says it can't (which seems to happen
   // on a mac when you force POT textures)
   *aSize = CalculatePOTSize(mTexImage->GetSize(), gl());
   return true;
 }
 
 void