Bug 764125; implement DrawTargetCairo::CopySurface; r=Bas
authorAnthony Jones <ajones@mozilla.com>
Tue, 24 Jul 2012 22:18:37 +1200
changeset 100530 338de2a051a53874c547b26ecd452f351828f08a
parent 100529 c2ad73cea385063bcb84e30dc34c5ffb8b7941eb
child 100531 89a18a804e350acb253a5655e2f7e3bc59894b28
push idunknown
push userunknown
push dateunknown
reviewersBas
bugs764125
milestone17.0a1
Bug 764125; implement DrawTargetCairo::CopySurface; r=Bas
gfx/2d/DrawTargetCairo.cpp
--- a/gfx/2d/DrawTargetCairo.cpp
+++ b/gfx/2d/DrawTargetCairo.cpp
@@ -8,16 +8,17 @@
 #include "SourceSurfaceCairo.h"
 #include "PathCairo.h"
 #include "HelpersCairo.h"
 #include "ScaledFontBase.h"
 
 #include "cairo.h"
 
 #include "Blur.h"
+#include "Logging.h"
 
 #ifdef CAIRO_HAS_QUARTZ_SURFACE
 #include "cairo-quartz.h"
 #include <ApplicationServices/ApplicationServices.h>
 #endif
 
 #ifdef CAIRO_HAS_XLIB_SURFACE
 #include "cairo-xlib.h"
@@ -462,20 +463,41 @@ DrawTargetCairo::FillRect(const Rect &aR
   cairo_new_path(mContext);
   cairo_rectangle(mContext, aRect.x, aRect.y, aRect.Width(), aRect.Height());
 
   DrawPattern(aPattern, StrokeOptions(), aOptions, DRAW_FILL);
 }
 
 void
 DrawTargetCairo::CopySurface(SourceSurface *aSurface,
-                             const IntRect &aSourceRect,
-                             const IntPoint &aDestination)
+                             const IntRect &aSource,
+                             const IntPoint &aDest)
 {
   AutoPrepareForDrawing prep(this, mContext);
+
+  if (!aSurface || aSurface->GetType() != SURFACE_CAIRO) {
+    gfxWarning() << "Unsupported surface type specified";
+    return;
+  }
+
+  cairo_surface_t* surf = static_cast<SourceSurfaceCairo*>(aSurface)->GetSurface();
+
+  cairo_save(mContext);
+
+  cairo_identity_matrix(mContext);
+
+  cairo_set_source_surface(mContext, surf, aDest.x - aSource.x, aDest.y - aSource.y);
+  cairo_set_operator(mContext, CAIRO_OPERATOR_SOURCE);
+
+  cairo_reset_clip(mContext);
+  cairo_new_path(mContext);
+  cairo_rectangle(mContext, aDest.x, aDest.y, aSource.width, aSource.height);
+  cairo_fill(mContext);
+
+  cairo_restore(mContext);
 }
 
 void
 DrawTargetCairo::ClearRect(const Rect& aRect)
 {
   AutoPrepareForDrawing prep(this, mContext);
 
   cairo_save(mContext);