Bug 386083 - SVG code should check gfxASurface::CairoStatus() when it creates new surfaces. r=jwatt,sr=tor
authorlongsonr@gmail.com
Tue, 17 Jul 2007 02:24:27 -0700
changeset 3558 63948bbfcbb02bec1725474a1ea83025e9628c4b
parent 3557 cc2d6b62bcbcc731ffb60541e59cb4410faa2a0f
child 3559 0a51b7f5419a5a0eaf9ee9be3eb255ba2308592e
push idunknown
push userunknown
push dateunknown
reviewersjwatt, tor
bugs386083
milestone1.9a7pre
Bug 386083 - SVG code should check gfxASurface::CairoStatus() when it creates new surfaces. r=jwatt,sr=tor
content/svg/content/src/nsSVGFilters.cpp
layout/svg/base/src/nsSVGFilterFrame.cpp
layout/svg/base/src/nsSVGMaskFrame.cpp
layout/svg/base/src/nsSVGPatternFrame.cpp
layout/svg/base/src/nsSVGUtils.cpp
--- a/content/svg/content/src/nsSVGFilters.cpp
+++ b/content/svg/content/src/nsSVGFilters.cpp
@@ -4109,18 +4109,18 @@ nsSVGFEConvolveMatrixElement::Filter(nsS
 
 #ifdef DEBUG_tor
     fprintf(stderr, "scaled size %d %d\n", scaledSize.width, scaledSize.height);
 #endif
     scaledSource = new gfxImageSurface(scaledSize,
                                        gfxASurface::ImageFormatARGB32);
     scaledTarget = new gfxImageSurface(scaledSize,
                                        gfxASurface::ImageFormatARGB32);
-    if (!scaledSource || !scaledSource->Data() ||
-        !scaledTarget || !scaledTarget->Data())
+    if (!scaledSource || scaledSource->CairoStatus() ||
+        !scaledTarget || scaledTarget->CairoStatus())
       return NS_ERROR_FAILURE;
 
     gfxContext ctx(scaledSource);
     ctx.SetOperator(gfxContext::OPERATOR_SOURCE);
     ctx.Scale(double(scaledSize.width) / fr.GetWidth(),
               double(scaledSize.height) / fr.GetHeight());
     ctx.SetSource(sourceSurface);
     ctx.Paint();
--- a/layout/svg/base/src/nsSVGFilterFrame.cpp
+++ b/layout/svg/base/src/nsSVGFilterFrame.cpp
@@ -222,17 +222,17 @@ nsSVGFilterFrame::FilterPaint(nsSVGRende
                   0.0f,                         filterRes.height / height,
                   -x * filterRes.width / width, -y * filterRes.height / height);
   aTarget->SetOverrideCTM(filterTransform);
   aTarget->NotifyCanvasTMChanged(PR_TRUE);
 
   // paint the target geometry
   nsRefPtr<gfxImageSurface> tmpSurface =
     new gfxImageSurface(filterRes, gfxASurface::ImageFormatARGB32);
-  if (!tmpSurface || !tmpSurface->Data()) {
+  if (!tmpSurface || tmpSurface->CairoStatus()) {
     FilterFailCleanup(aContext, aTarget);
     return NS_OK;
   }
 
   gfxContext tmpContext(tmpSurface);
   nsSVGRenderState tmpState(&tmpContext);
 
   tmpContext.SetOperator(gfxContext::OPERATOR_CLEAR);
@@ -250,17 +250,17 @@ nsSVGFilterFrame::FilterPaint(nsSVGRende
   nsSVGFilterInstance::ColorModel 
     colorModel(nsSVGFilterInstance::ColorModel::SRGB,
                nsSVGFilterInstance::ColorModel::PREMULTIPLIED);
 
   if (requirements & NS_FE_SOURCEALPHA) {
     nsRefPtr<gfxImageSurface> alpha =
       new gfxImageSurface(filterRes, gfxASurface::ImageFormatARGB32);
 
-    if (!alpha || !alpha->Data()) {
+    if (!alpha || alpha->CairoStatus()) {
       FilterFailCleanup(aContext, aTarget);
       return NS_OK;
     }
 
     PRUint8 *data = tmpSurface->Data();
     PRUint8 *alphaData = alpha->Data();
     PRUint32 stride = tmpSurface->Stride();
 
@@ -513,17 +513,17 @@ nsSVGFilterInstance::GetFilterSubregion(
 
 already_AddRefed<gfxImageSurface>
 nsSVGFilterInstance::GetImage()
 {
   nsRefPtr<gfxImageSurface> surface =
     new gfxImageSurface(gfxIntSize(mFilterResX, mFilterResY),
                         gfxASurface::ImageFormatARGB32);
 
-  if (!(surface && surface->Data())) {
+  if (!surface || surface->CairoStatus()) {
     return nsnull;
   }
 
   gfxContext ctx(surface);
   ctx.SetOperator(gfxContext::OPERATOR_CLEAR);
   ctx.Paint();
 
   gfxImageSurface *retval = nsnull;
--- a/layout/svg/base/src/nsSVGMaskFrame.cpp
+++ b/layout/svg/base/src/nsSVGMaskFrame.cpp
@@ -198,35 +198,33 @@ nsSVGMaskFrame::ComputeMaskAlpha(nsSVGRe
   if (surfaceSize.width <= 0 || surfaceSize.height <= 0)
     return nsnull;
 
   if (resultOverflows)
     return nsnull;
 
   nsRefPtr<gfxImageSurface> image =
     new gfxImageSurface(surfaceSize, gfxASurface::ImageFormatARGB32);
-  if (!image || !image->Data())
+  if (!image || image->CairoStatus())
     return nsnull;
 
   gfxContext transferCtx(image);
   transferCtx.SetOperator(gfxContext::OPERATOR_SOURCE);
   transferCtx.SetSource(surface, -clipExtents.pos);
   transferCtx.Paint();
 
-  PRUint32 width  = surfaceSize.width;
-  PRUint32 height = surfaceSize.height;
   PRUint8 *data   = image->Data();
   PRInt32  stride = image->Stride();
 
-  nsRect rect(0, 0, width, height);
+  nsRect rect(0, 0, surfaceSize.width, surfaceSize.height);
   nsSVGUtils::UnPremultiplyImageDataAlpha(data, stride, rect);
   nsSVGUtils::ConvertImageDataToLinearRGB(data, stride, rect);
 
-  for (PRUint32 y = 0; y < height; y++)
-    for (PRUint32 x = 0; x < width; x++) {
+  for (PRUint32 y = 0; y < surfaceSize.height; y++)
+    for (PRUint32 x = 0; x < surfaceSize.width; x++) {
       PRUint8 *pixel = data + stride * y + 4 * x;
 
       /* linearRGB -> intensity */
       PRUint8 alpha =
         static_cast<PRUint8>
                    ((pixel[GFX_ARGB32_OFFSET_R] * 0.2125 +
                         pixel[GFX_ARGB32_OFFSET_G] * 0.7154 +
                         pixel[GFX_ARGB32_OFFSET_B] * 0.0721) *
--- a/layout/svg/base/src/nsSVGPatternFrame.cpp
+++ b/layout/svg/base/src/nsSVGPatternFrame.cpp
@@ -178,17 +178,18 @@ nsSVGPatternFrame::GetType() const
 //----------------------------------------------------------------------
 // nsSVGContainerFrame methods:
 
 // If our GetCanvasTM is getting called, we
 // need to return *our current* transformation
 // matrix, which depends on our units parameters
 // and X, Y, Width, and Height
 already_AddRefed<nsIDOMSVGMatrix> 
-nsSVGPatternFrame::GetCanvasTM() {
+nsSVGPatternFrame::GetCanvasTM()
+{
   nsIDOMSVGMatrix *rCTM;
   
   if (mCTM) {
     rCTM = mCTM;
     NS_IF_ADDREF(rCTM);
   } else {
     // Do we know our rendering parent?
     if (mSource) {
@@ -311,17 +312,17 @@ nsSVGPatternFrame::PaintPattern(gfxASurf
 
 #ifdef DEBUG_scooter
   printf("Creating %dX%d surface\n", int(surfaceSize.width), int(surfaceSize.height));
 #endif
 
   nsRefPtr<gfxASurface> tmpSurface =
     gfxPlatform::GetPlatform()->CreateOffscreenSurface(surfaceSize,
                                                        gfxASurface::ImageFormatARGB32);
-  if (!tmpSurface)
+  if (!tmpSurface || tmpSurface->CairoStatus())
     return NS_ERROR_FAILURE;
 
   gfxContext tmpContext(tmpSurface);
   nsSVGRenderState tmpState(&tmpContext);
 
   // Fill with transparent black
   tmpContext.SetOperator(gfxContext::OPERATOR_CLEAR);
   tmpContext.Paint();
--- a/layout/svg/base/src/nsSVGUtils.cpp
+++ b/layout/svg/base/src/nsSVGUtils.cpp
@@ -1380,16 +1380,18 @@ nsSVGUtils::ConvertToSurfaceSize(const g
 
 gfxASurface *
 nsSVGUtils::GetThebesComputationalSurface()
 {
   if (!mThebesComputationalSurface) {
     nsRefPtr<gfxASurface> surface =
       gfxPlatform::GetPlatform()->CreateOffscreenSurface(gfxIntSize(1, 1),
                                                          gfxASurface::ImageFormatARGB32);
+    NS_ASSERTION(surface && !surface->CairoStatus(),
+                 "Could not create offscreen surface");
     mThebesComputationalSurface = surface;
     // we want to keep this surface around
     NS_IF_ADDREF(mThebesComputationalSurface);
   }
 
   return mThebesComputationalSurface;
 }