Bug 784260; DrawTargetD2D should deal with Cairo surfaces in CreateBrush... . r=Bas
authorNicholas Cameron <ncameron@mozilla.com>
Thu, 23 Aug 2012 08:56:03 +1200
changeset 105098 ca3a3ff0af73b6e885b2c2de97f249cacf8dd099
parent 105097 e508c52d91efdbd7a81f679210aca353a3152fc9
child 105099 4666c4ccea092752dd84d4354359c1d084786b0e
push id55
push usershu@rfrn.org
push dateThu, 30 Aug 2012 01:33:09 +0000
reviewersBas
bugs784260
milestone17.0a1
Bug 784260; DrawTargetD2D should deal with Cairo surfaces in CreateBrush... . r=Bas
gfx/2d/DrawTargetCairo.cpp
gfx/2d/DrawTargetD2D.cpp
--- a/gfx/2d/DrawTargetCairo.cpp
+++ b/gfx/2d/DrawTargetCairo.cpp
@@ -146,16 +146,20 @@ GetCairoSurfaceForSourceSurface(SourceSu
   if (aSurface->GetType() == SURFACE_CAIRO_IMAGE) {
     cairo_surface_t* surf =
       static_cast<const DataSourceSurfaceCairo*>(aSurface)->GetSurface();
     cairo_surface_reference(surf);
     return surf;
   }
 
   RefPtr<DataSourceSurface> data = aSurface->GetDataSurface();
+  if (!data) {
+    return nullptr;
+  }
+
   cairo_surface_t* surf =
     cairo_image_surface_create_for_data(data->GetData(),
                                         GfxFormatToCairoFormat(data->GetFormat()),
                                         data->GetSize().width,
                                         data->GetSize().height,
                                         data->Stride());
   cairo_surface_set_user_data(surf,
  				                      &surfaceDataKey,
--- a/gfx/2d/DrawTargetD2D.cpp
+++ b/gfx/2d/DrawTargetD2D.cpp
@@ -2085,29 +2085,30 @@ DrawTargetD2D::CreateBrushForPattern(con
     case SURFACE_D2D1_DRAWTARGET:
       {
         SourceSurfaceD2DTarget *surf =
           static_cast<SourceSurfaceD2DTarget*>(pat->mSurface.get());
         bitmap = surf->GetBitmap(mRT);
         AddDependencyOnSource(surf);
       }
       break;
-    case SURFACE_DATA:
+    default:
       {
-        DataSourceSurface *dataSurf =
-          static_cast<DataSourceSurface*>(pat->mSurface.get());
-        bitmap = CreatePartialBitmapForSurface(dataSurf, mat, pat->mExtendMode);
-        
+        RefPtr<DataSourceSurface> dataSurf = pat->mSurface->GetDataSurface();
+        if (!dataSurf) {
+          gfxWarning() << "Invalid surface type.";
+          return nullptr;
+        }
+
+        bitmap = CreatePartialBitmapForSurface(dataSurf, mat, pat->mExtendMode); 
         if (!bitmap) {
           return nullptr;
         }
       }
       break;
-    default:
-      break;
     }
     
     mRT->CreateBitmapBrush(bitmap,
                            D2D1::BitmapBrushProperties(D2DExtend(pat->mExtendMode),
                                                        D2DExtend(pat->mExtendMode),
                                                        D2DFilter(pat->mFilter)),
                            D2D1::BrushProperties(aAlpha, D2DMatrix(mat)),
                            byRef(bmBrush));