Bug 934842. CopySurface for data source surfaces. r=Bas
authorNicholas Cameron <ncameron@mozilla.com>
Fri, 08 Nov 2013 14:54:37 +1300
changeset 302 cde5ef6a089e2637524e41d9f0a52fb1187f19ab
parent 301 b5c46d49cf65a9f590b5e009ec7462e6968a1d4f
child 303 fa6b9f54b4e4f2573b16f63981c7725aa87a7d3e
push id197
push userncameron@mozilla.com
push dateFri, 08 Nov 2013 01:55:25 +0000
reviewersBas
bugs934842
Bug 934842. CopySurface for data source surfaces. r=Bas
DrawTargetCairo.cpp
DrawTargetD2D.cpp
--- a/DrawTargetCairo.cpp
+++ b/DrawTargetCairo.cpp
@@ -719,24 +719,29 @@ DrawTargetCairo::CopySurfaceInternal(cai
 void
 DrawTargetCairo::CopySurface(SourceSurface *aSurface,
                              const IntRect &aSource,
                              const IntPoint &aDest)
 {
   AutoPrepareForDrawing prep(this, mContext);
   AutoClearDeviceOffset clear(aSurface);
 
-  if (!aSurface || aSurface->GetType() != SURFACE_CAIRO) {
+  if (!aSurface) {
     gfxWarning() << "Unsupported surface type specified";
     return;
   }
 
-  cairo_surface_t* surf = static_cast<SourceSurfaceCairo*>(aSurface)->GetSurface();
+  cairo_surface_t* surf = GetCairoSurfaceForSourceSurface(aSurface);
+  if (!surf) {
+    gfxWarning() << "Unsupported surface type specified";
+    return;
+  }
 
   CopySurfaceInternal(surf, aSource, aDest);
+  cairo_surface_destroy(surf);
 }
 
 void
 DrawTargetCairo::CopyRect(const IntRect &aSource,
                           const IntPoint &aDest)
 {
   AutoPrepareForDrawing prep(this, mContext);
 
--- a/DrawTargetD2D.cpp
+++ b/DrawTargetD2D.cpp
@@ -765,36 +765,17 @@ DrawTargetD2D::CopySurface(SourceSurface
                Float(aSourceRect.width), Float(aSourceRect.height));
 
   mRT->SetTransform(D2D1::IdentityMatrix());
   mTransformDirty = true;
   mRT->PushAxisAlignedClip(D2DRect(dstRect), D2D1_ANTIALIAS_MODE_ALIASED);
   mRT->Clear(D2D1::ColorF(0, 0.0f));
   mRT->PopAxisAlignedClip();
 
-  RefPtr<ID2D1Bitmap> bitmap;
-
-  switch (aSurface->GetType()) {
-  case SURFACE_D2D1_BITMAP:
-    {
-      SourceSurfaceD2D *srcSurf = static_cast<SourceSurfaceD2D*>(aSurface);
-      bitmap = srcSurf->GetBitmap();
-    }
-    break;
-  case SURFACE_D2D1_DRAWTARGET:
-    {
-      SourceSurfaceD2DTarget *srcSurf = static_cast<SourceSurfaceD2DTarget*>(aSurface);
-      bitmap = srcSurf->GetBitmap(mRT);
-      AddDependencyOnSource(srcSurf);
-    }
-    break;
-  default:
-    return;
-  }
-
+  RefPtr<ID2D1Bitmap> bitmap = GetBitmapForSurface(aSurface, srcRect);
   if (!bitmap) {
     return;
   }
 
   mRT->DrawBitmap(bitmap, D2DRect(dstRect), 1.0f,
                   D2D1_BITMAP_INTERPOLATION_MODE_LINEAR,
                   D2DRect(srcRect));
 }