Back out efd165428f08 to 4a79fefefa28 (bug 580786, bug 716639, bug 692879, bug 717921) because of reftest error
authorMatt Brubeck <mbrubeck@mozilla.com>
Tue, 17 Jan 2012 10:08:38 -0800
changeset 87130 52f52eb53549961ef0e86a3b2504dacebb1cfc5a
parent 87129 26c821293430fe7cc0637db0fa177fca83ea0cac
child 87131 39948fbe66594b52b4d52d30f47326674e4ce74a
push id674
push userffxbld
push dateTue, 13 Mar 2012 21:17:50 +0000
treeherdermozilla-beta@e3c4c92dec31 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs580786, 716639, 692879, 717921
milestone12.0a1
backs outefd165428f08c0f5043745105a50875a8de312a9
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
Back out efd165428f08 to 4a79fefefa28 (bug 580786, bug 716639, bug 692879, bug 717921) because of reftest error
content/canvas/src/nsCanvasRenderingContext2DAzure.cpp
content/canvas/test/test_canvas.html
gfx/2d/2D.h
gfx/2d/DrawTargetCG.cpp
gfx/2d/DrawTargetCG.h
gfx/2d/DrawTargetSkia.cpp
gfx/2d/Factory.cpp
gfx/2d/Makefile.in
gfx/2d/PathCG.cpp
gfx/2d/PathCG.h
gfx/2d/ScaledFontBase.cpp
gfx/2d/ScaledFontBase.h
gfx/2d/ScaledFontMac.cpp
gfx/2d/ScaledFontMac.h
gfx/2d/ScaledFontSkia.cpp
gfx/2d/ScaledFontSkia.h
gfx/2d/ScaledFontWin.cpp
gfx/2d/ScaledFontWin.h
gfx/2d/SourceSurfaceCG.cpp
gfx/2d/SourceSurfaceCG.h
gfx/2d/Types.h
gfx/2d/UserData.h
gfx/thebes/gfxFont.h
gfx/thebes/gfxPlatform.cpp
gfx/thebes/gfxPlatform.h
gfx/thebes/gfxPlatformMac.cpp
gfx/thebes/gfxPlatformMac.h
gfx/thebes/gfxQuartzSurface.cpp
gfx/thebes/gfxQuartzSurface.h
gfx/thebes/gfxWindowsPlatform.cpp
layout/reftests/canvas/reftest.list
layout/reftests/css-gradients/reftest.list
layout/reftests/reftest-sanity/fuzzy-ref.html
layout/reftests/reftest-sanity/fuzzy.html
layout/reftests/reftest-sanity/reftest.list
layout/reftests/reftest-sanity/too-fuzzy.html
layout/reftests/svg/as-image/reftest.list
layout/tools/reftest/README.txt
layout/tools/reftest/print-manifest-dirs.py
layout/tools/reftest/reftest.js
modules/libpref/src/init/all.js
--- a/content/canvas/src/nsCanvasRenderingContext2DAzure.cpp
+++ b/content/canvas/src/nsCanvasRenderingContext2DAzure.cpp
@@ -1160,20 +1160,18 @@ nsCanvasRenderingContext2DAzure::Redraw(
 
   mIsEntireFrameInvalid = true;
 
   if (!mCanvasElement) {
     NS_ASSERTION(mDocShell, "Redraw with no canvas element or docshell!");
     return NS_OK;
   }
 
-  if (!mThebesSurface)
-    mThebesSurface =
-      gfxPlatform::GetPlatform()->GetThebesSurfaceForDrawTarget(mTarget);
-  mThebesSurface->MarkDirty();
+  if (mThebesSurface)
+      mThebesSurface->MarkDirty();
 
   nsSVGEffects::InvalidateDirectRenderingObservers(HTMLCanvasElement());
 
   HTMLCanvasElement()->InvalidateCanvasContent(nsnull);
 
   return NS_OK;
 }
 
@@ -1192,20 +1190,18 @@ nsCanvasRenderingContext2DAzure::Redraw(
     return;
   }
 
   if (!mCanvasElement) {
     NS_ASSERTION(mDocShell, "Redraw with no canvas element or docshell!");
     return;
   }
 
-  if (!mThebesSurface)
-    mThebesSurface =
-      gfxPlatform::GetPlatform()->GetThebesSurfaceForDrawTarget(mTarget);
-  mThebesSurface->MarkDirty();
+  if (mThebesSurface)
+      mThebesSurface->MarkDirty();
 
   nsSVGEffects::InvalidateDirectRenderingObservers(HTMLCanvasElement());
 
   gfxRect tmpR = ThebesRect(r);
   HTMLCanvasElement()->InvalidateCanvasContent(&tmpR);
 
   return;
 }
--- a/content/canvas/test/test_canvas.html
+++ b/content/canvas/test/test_canvas.html
@@ -13,33 +13,16 @@ function IsD2DEnabled() {
     try {
         netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
         enabled = Components.classes["@mozilla.org/gfx/info;1"].getService(Components.interfaces.nsIGfxInfo).D2DEnabled;
     } catch(e) {}
     
     return enabled;
 }
 
-function IsMacOSX10_5orOlder() {
-    var is105orOlder = false;
-
-    if (navigator.platform.indexOf("Mac") == 0) {
-        netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
-        var version = Components.classes["@mozilla.org/system-info;1"]
-                            .getService(Components.interfaces.nsIPropertyBag2)
-                            .getProperty("version");
-        // the next line is correct: Mac OS 10.6 corresponds to Darwin version 10 !
-        // Mac OS 10.5 would be Darwin version 9. the |version| string we've got here
-        // is the Darwin version.
-        is105orOlder = (parseFloat(version) < 10.0);
-    }
-    return is105orOlder;
-}
-
-
 function IsAzureEnabled() {
   var enabled = false;
 
   try {
     netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
     enabled = Components.classes["@mozilla.org/gfx/info;1"].getService(Components.interfaces.nsIGfxInfo).AzureEnabled;
   } catch (e) { }
 
@@ -5790,22 +5773,20 @@ isPixel(ctx, 80,25, 0,255,0,255, 2);
 <script>
 
 
 function test_2d_gradient_interpolate_overlap() {
 
 var canvas = document.getElementById('c215');
 var ctx = canvas.getContext('2d');
 
-if (!IsD2DEnabled() && !IsMacOSX10_5orOlder()) {
-    // On D2D the different nature of how gradients
+if (!IsD2DEnabled()) {
+    // Only run this on non-D2D. On D2D the different nature of how gradients
     // are drawn makes it so we cannot guarantee these stops are completely
     // hard.
-
-    // On OS X 10.5 quartz is confused by the overlapping stops: Bug #715235
     canvas.width = 200;
     var g = ctx.createLinearGradient(0, 0, 200, 0);
     g.addColorStop(0, '#f00');
     g.addColorStop(0, '#ff0');
     g.addColorStop(0.25, '#00f');
     g.addColorStop(0.25, '#0f0');
     g.addColorStop(0.25, '#0f0');
     g.addColorStop(0.25, '#0f0');
@@ -5849,25 +5830,22 @@ for (var p = 0; p < ps.length; ++p)
 {
         g.addColorStop(ps[p], '#0f0');
         for (var i = 0; i < 15; ++i)
                 g.addColorStop(ps[p], '#f00');
         g.addColorStop(ps[p], '#0f0');
 }
 ctx.fillStyle = g;
 ctx.fillRect(0, 0, 100, 50);
-
-if (!IsMacOSX10_5orOlder()) {
-    // On OS X 10.5 quartz is confused by the overlapping stops: Bug #715235
-    isPixel(ctx, 1,25, 0,255,0,255, 0);
-    isPixel(ctx, 30,25, 0,255,0,255, 0);
-    isPixel(ctx, 40,25, 0,255,0,255, 0);
-    isPixel(ctx, 60,25, 0,255,0,255, 0);
-    isPixel(ctx, 80,25, 0,255,0,255, 0);
-}
+isPixel(ctx, 1,25, 0,255,0,255, 0);
+isPixel(ctx, 30,25, 0,255,0,255, 0);
+isPixel(ctx, 40,25, 0,255,0,255, 0);
+isPixel(ctx, 60,25, 0,255,0,255, 0);
+isPixel(ctx, 80,25, 0,255,0,255, 0);
+
 
 }
 </script>
 
 <!-- [[[ test_2d.gradient.interpolate.solid.html ]]] -->
 
 <p>Canvas test: 2d.gradient.interpolate.solid</p>
 <canvas id="c217" width="100" height="50"><p class="fallback">FAIL (fallback content)</p></canvas>
--- a/gfx/2d/2D.h
+++ b/gfx/2d/2D.h
@@ -36,17 +36,17 @@
  * ***** END LICENSE BLOCK ***** */
 
 #ifndef _MOZILLA_GFX_2D_H
 #define _MOZILLA_GFX_2D_H
 
 #include "Point.h"
 #include "Rect.h"
 #include "Matrix.h"
-#include "UserData.h"
+
 // This RefPtr class isn't ideal for usage in Azure, as it doesn't allow T**
 // outparams using the &-operator. But it will have to do as there's no easy
 // solution.
 #include "mozilla/RefPtr.h"
 
 struct _cairo_surface;
 typedef _cairo_surface cairo_surface_t;
 
@@ -739,24 +739,17 @@ public:
 
   SurfaceFormat GetFormat() { return mFormat; }
 
   /* Tries to get a native surface for a DrawTarget, this may fail if the
    * draw target cannot convert to this surface type.
    */
   virtual void *GetNativeSurface(NativeSurfaceType aType) { return NULL; }
 
-  void AddUserData(UserDataKey *key, void *userData, void (*destroy)(void*)) {
-    mUserData.Add(key, userData, destroy);
-  }
-  void *GetUserData(UserDataKey *key) {
-    return mUserData.Get(key);
-  }
 protected:
-  UserData mUserData;
   Matrix mTransform;
   bool mTransformDirty : 1;
 
   SurfaceFormat mFormat;
 };
 
 class Factory
 {
--- a/gfx/2d/DrawTargetCG.cpp
+++ b/gfx/2d/DrawTargetCG.cpp
@@ -14,17 +14,17 @@
  *
  * The Original Code is Mozilla Corporation code.
  *
  * The Initial Developer of the Original Code is Mozilla Foundation.
  * Portions created by the Initial Developer are Copyright (C) 2009
  * the Initial Developer. All Rights Reserved.
  *
  * Contributor(s):
- *   Jeff Muizelaar <jmuizelaar@mozilla.com>
+ *   Bas Schouten <bschouten@mozilla.com>
  *
  * Alternatively, the contents of this file may be used under the terms of
  * either the GNU General Public License Version 2 or later (the "GPL"), or
  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  * in which case the provisions of the GPL or the LGPL are applicable instead
  * of those above. If you wish to allow use of your version of this file only
  * under the terms of either the GPL or the LGPL, and not to allow others to
  * use your version of this file under the terms of the MPL, indicate your
@@ -32,934 +32,153 @@
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 #include "DrawTargetCG.h"
 #include "SourceSurfaceCG.h"
 #include "Rect.h"
-#include "ScaledFontMac.h"
-#include "Tools.h"
-#include <vector>
 
 //CG_EXTERN void CGContextSetCompositeOperation (CGContextRef, PrivateCGCompositeMode);
 
 namespace mozilla {
 namespace gfx {
 
 static CGRect RectToCGRect(Rect r)
 {
   return CGRectMake(r.x, r.y, r.width, r.height);
 }
 
-static CGRect IntRectToCGRect(IntRect r)
-{
-  return CGRectMake(r.x, r.y, r.width, r.height);
-}
-
 CGBlendMode ToBlendMode(CompositionOp op)
 {
   CGBlendMode mode;
   switch (op) {
     case OP_OVER:
       mode = kCGBlendModeNormal;
       break;
+    case OP_SOURCE:
+      mode = kCGBlendModeCopy;
+      break;
+    case OP_CLEAR:
+      mode = kCGBlendModeClear;
+      break;
     case OP_ADD:
       mode = kCGBlendModePlusLighter;
       break;
     case OP_ATOP:
       mode = kCGBlendModeSourceAtop;
       break;
-    case OP_OUT:
-      mode = kCGBlendModeSourceOut;
-      break;
-    case OP_IN:
-      mode = kCGBlendModeSourceIn;
-      break;
-    case OP_SOURCE:
-      mode = kCGBlendModeCopy;
-      break;
-    case OP_DEST_IN:
-      mode = kCGBlendModeDestinationIn;
-      break;
-    case OP_DEST_OUT:
-      mode = kCGBlendModeDestinationOut;
-      break;
-    case OP_DEST_OVER:
-      mode = kCGBlendModeDestinationOver;
-      break;
-    case OP_DEST_ATOP:
-      mode = kCGBlendModeDestinationAtop;
-      break;
-    case OP_XOR:
-      mode = kCGBlendModeXOR;
-      break;
-      /*
-    case OP_CLEAR:
-      mode = kCGBlendModeClear;
-      break;*/
     default:
       mode = kCGBlendModeNormal;
   }
   return mode;
 }
 
 
 
 DrawTargetCG::DrawTargetCG()
 {
 }
 
 DrawTargetCG::~DrawTargetCG()
 {
-  // We need to conditionally release these because Init can fail without initializing these.
-  if (mColorSpace)
-    CGColorSpaceRelease(mColorSpace);
-  if (mCg)
-    CGContextRelease(mCg);
 }
 
 TemporaryRef<SourceSurface>
 DrawTargetCG::Snapshot()
 {
-  RefPtr<SourceSurfaceCG> newSurf = new SourceSurfaceCG(CGBitmapContextCreateImage(mCg));
-  return newSurf;
-}
-
-TemporaryRef<DrawTarget>
-DrawTargetCG::CreateSimilarDrawTarget(const IntSize &aSize, SurfaceFormat aFormat) const
-{
-  // XXX: in thebes we use CGLayers to do this kind of thing. It probably makes sense
-  // to add that in somehow, but at a higher level
-  RefPtr<DrawTargetCG> newTarget = new DrawTargetCG();
-  if (newTarget->Init(aSize, aFormat)) {
-    return newTarget;
-  } else {
-    return NULL;
-  }
+  return NULL;
 }
 
 TemporaryRef<SourceSurface>
 DrawTargetCG::CreateSourceSurfaceFromData(unsigned char *aData,
                                            const IntSize &aSize,
                                            int32_t aStride,
                                            SurfaceFormat aFormat) const
 {
   RefPtr<SourceSurfaceCG> newSurf = new SourceSurfaceCG();
 
- if (!newSurf->InitFromData(aData, aSize, aStride, aFormat)) {
+  if (!newSurf->InitFromData(aData, aSize, aStride, aFormat)) {
     return NULL;
   }
 
   return newSurf;
 }
 
 TemporaryRef<SourceSurface>
 DrawTargetCG::OptimizeSourceSurface(SourceSurface *aSurface) const
 {
   return NULL;
 }
 
-class UnboundnessFixer
-{
-    CGRect mClipBounds;
-    CGLayerRef mLayer;
-    CGContextRef mCg;
-  public:
-    UnboundnessFixer() : mCg(NULL) {}
-
-    CGContextRef Check(CGContextRef baseCg, CompositionOp blend)
-    {
-      if (!IsOperatorBoundByMask(blend)) {
-        mClipBounds = CGContextGetClipBoundingBox(baseCg);
-        // TransparencyLayers aren't blended using the blend mode so
-        // we are forced to use CGLayers
-
-        //XXX: The size here is in default user space units, of the layer relative to the graphics context.
-        // is the clip bounds still correct if, for example, we have a scale applied to the context?
-        mLayer = CGLayerCreateWithContext(baseCg, mClipBounds.size, NULL);
-        mCg = CGLayerGetContext(mLayer);
-        // CGContext's default to have the origin at the bottom left
-        // so flip it to the top left and adjust for the origin
-        // of the layer
-        CGContextTranslateCTM(mCg, -mClipBounds.origin.x, mClipBounds.origin.y + mClipBounds.size.height);
-        CGContextScaleCTM(mCg, 1, -1);
-
-        return mCg;
-      } else {
-        return baseCg;
-      }
-    }
-
-    void Fix(CGContextRef baseCg)
-    {
-        if (mCg) {
-            CGContextTranslateCTM(baseCg, 0, mClipBounds.size.height);
-            CGContextScaleCTM(baseCg, 1, -1);
-            mClipBounds.origin.y *= -1;
-            CGContextDrawLayerAtPoint(baseCg, mClipBounds.origin, mLayer);
-            CGContextRelease(mCg);
-        }
-    }
-};
-
 void
 DrawTargetCG::DrawSurface(SourceSurface *aSurface,
                            const Rect &aDest,
                            const Rect &aSource,
-                           const DrawSurfaceOptions &aSurfOptions,
-                           const DrawOptions &aDrawOptions)
+                           const DrawOptions &aOptions,
+                           const DrawSurfaceOptions &aSurfOptions)
 {
   CGImageRef image;
   CGImageRef subimage = NULL;
-  if (aSurface->GetType() == SURFACE_COREGRAPHICS_IMAGE) {
-    CGContextSaveGState(mCg);
-
-    CGContextSetBlendMode(mCg, ToBlendMode(aDrawOptions.mCompositionOp));
-    UnboundnessFixer fixer;
-    CGContextRef cg = fixer.Check(mCg, aDrawOptions.mCompositionOp);
-    CGContextSetAlpha(cg, aDrawOptions.mAlpha);
-
-    CGContextConcatCTM(cg, GfxMatrixToCGAffineTransform(mTransform));
+  if (aSurface->GetType() == COREGRAPHICS_IMAGE) {
     image = static_cast<SourceSurfaceCG*>(aSurface)->GetImage();
     /* we have two options here:
      *  - create a subimage -- this is slower
      *  - fancy things with clip and different dest rects */
     {
       subimage = CGImageCreateWithImageInRect(image, RectToCGRect(aSource));
       image = subimage;
     }
 
-    CGContextScaleCTM(cg, 1, -1);
-
-    CGRect flippedRect = CGRectMake(aDest.x, -(aDest.y + aDest.height),
-                                    aDest.width, aDest.height);
-
-    //XXX: we should implement this for patterns too
-    if (aSurfOptions.mFilter == FILTER_POINT)
-      CGContextSetInterpolationQuality(cg, kCGInterpolationNone);
-
-    CGContextDrawImage(cg, flippedRect, image);
-
-    fixer.Fix(mCg);
-
-    CGContextRestoreGState(mCg);
-
-    CGImageRelease(subimage);
-  }
-}
-
-static CGColorRef ColorToCGColor(CGColorSpaceRef aColorSpace, const Color& aColor)
-{
-  CGFloat components[4] = {aColor.r, aColor.g, aColor.b, aColor.a};
-  return CGColorCreate(aColorSpace, components);
-}
-
-class GradientStopsCG : public GradientStops
-{
-  public:
-  //XXX: The skia backend uses a vector and passes in aNumStops. It should do better
-  GradientStopsCG(GradientStop* aStops, uint32_t aNumStops, ExtendMode aExtendMode)
-  {
-    //XXX: do the stops need to be in any particular order?
-    // what should we do about the color space here? we certainly shouldn't be
-    // recreating it all the time
-    std::vector<CGFloat> colors;
-    std::vector<CGFloat> offsets;
-    colors.reserve(aNumStops*4);
-    offsets.reserve(aNumStops);
-
-    for (uint32_t i = 0; i < aNumStops; i++) {
-      colors.push_back(aStops[i].color.r);
-      colors.push_back(aStops[i].color.g);
-      colors.push_back(aStops[i].color.b);
-      colors.push_back(aStops[i].color.a);
-
-      offsets.push_back(aStops[i].offset);
-    }
-
-    CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
-    mGradient = CGGradientCreateWithColorComponents(colorSpace,
-                                                    &colors.front(),
-                                                    &offsets.front(),
-                                                    aNumStops);
-    CGColorSpaceRelease(colorSpace);
-  }
-  virtual ~GradientStopsCG() {
-    CGGradientRelease(mGradient);
-  }
-  BackendType GetBackendType() const { return BACKEND_COREGRAPHICS; }
-  CGGradientRef mGradient;
-};
-
-TemporaryRef<GradientStops>
-DrawTargetCG::CreateGradientStops(GradientStop *aStops, uint32_t aNumStops,
-                                  ExtendMode aExtendMode) const
-{
-  return new GradientStopsCG(aStops, aNumStops, aExtendMode);
-}
-
-static void
-DrawGradient(CGContextRef cg, const Pattern &aPattern)
-{
-  if (aPattern.GetType() == PATTERN_LINEAR_GRADIENT) {
-    const LinearGradientPattern& pat = static_cast<const LinearGradientPattern&>(aPattern);
-    GradientStopsCG *stops = static_cast<GradientStopsCG*>(pat.mStops.get());
-    // XXX: we should take the m out of the properties of LinearGradientPatterns
-    CGPoint startPoint = { pat.mBegin.x, pat.mBegin.y };
-    CGPoint endPoint   = { pat.mEnd.x,   pat.mEnd.y };
-
-    // Canvas spec states that we should avoid drawing degenerate gradients (XXX: should this be in common code?)
-    //if (startPoint.x == endPoint.x && startPoint.y == endPoint.y)
-    //  return;
-
-    CGContextDrawLinearGradient(cg, stops->mGradient, startPoint, endPoint,
-                                kCGGradientDrawsBeforeStartLocation | kCGGradientDrawsAfterEndLocation);
-  } else if (aPattern.GetType() == PATTERN_RADIAL_GRADIENT) {
-    const RadialGradientPattern& pat = static_cast<const RadialGradientPattern&>(aPattern);
-    GradientStopsCG *stops = static_cast<GradientStopsCG*>(pat.mStops.get());
-
-    // XXX: we should take the m out of the properties of RadialGradientPatterns
-    CGPoint startCenter = { pat.mCenter1.x, pat.mCenter1.y };
-    CGFloat startRadius = pat.mRadius1;
-    CGPoint endCenter   = { pat.mCenter2.x, pat.mCenter2.y };
-    CGFloat endRadius   = pat.mRadius2;
-
-    //XXX: are there degenerate radial gradients that we should avoid drawing?
-    CGContextDrawRadialGradient(cg, stops->mGradient, startCenter, startRadius, endCenter, endRadius,
-                                kCGGradientDrawsBeforeStartLocation | kCGGradientDrawsAfterEndLocation);
-  } else {
-    assert(0);
-  }
-
-}
-
-static void
-drawPattern(void *info, CGContextRef context)
-{
-  CGImageRef image = static_cast<CGImageRef>(info);
-  CGRect rect = {{0, 0},
-    {static_cast<CGFloat>(CGImageGetWidth(image)),
-     static_cast<CGFloat>(CGImageGetHeight(image))}};
-  CGContextDrawImage(context, rect, image);
-}
-
-static void
-releaseInfo(void *info)
-{
-  CGImageRef image = static_cast<CGImageRef>(info);
-  CGImageRelease(image);
-}
-
-CGPatternCallbacks patternCallbacks = {
-  0,
-  drawPattern,
-  releaseInfo
-};
-
-static bool
-isGradient(const Pattern &aPattern)
-{
-  return aPattern.GetType() == PATTERN_LINEAR_GRADIENT || aPattern.GetType() == PATTERN_RADIAL_GRADIENT;
-}
-
-/* CoreGraphics patterns ignore the userspace transform so
- * we need to multiply it in */
-static CGPatternRef
-CreateCGPattern(const Pattern &aPattern, CGAffineTransform aUserSpace)
-{
-  const SurfacePattern& pat = static_cast<const SurfacePattern&>(aPattern);
-  // XXX: is .get correct here?
-  CGImageRef image = static_cast<SourceSurfaceCG*>(pat.mSurface.get())->GetImage();
-  CGFloat xStep, yStep;
-  switch (pat.mExtendMode) {
-    case EXTEND_CLAMP:
-      // The 1 << 22 comes from Webkit see Pattern::createPlatformPattern() in PatternCG.cpp for more info
-      xStep = static_cast<CGFloat>(1 << 22);
-      yStep = static_cast<CGFloat>(1 << 22);
-      break;
-    case EXTEND_REFLECT:
-      assert(0);
-    case EXTEND_REPEAT:
-      xStep = static_cast<CGFloat>(CGImageGetWidth(image));
-      yStep = static_cast<CGFloat>(CGImageGetHeight(image));
-      // webkit uses wkCGPatternCreateWithImageAndTransform a wrapper around CGPatternCreateWithImage2
-      // this is done to avoid pixel-cracking along pattern boundaries
-      // (see https://bugs.webkit.org/show_bug.cgi?id=53055)
-      // typedef enum {
-      //    wkPatternTilingNoDistortion,
-      //    wkPatternTilingConstantSpacingMinimalDistortion,
-      //    wkPatternTilingConstantSpacing
-      // } wkPatternTiling;
-      // extern CGPatternRef (*wkCGPatternCreateWithImageAndTransform)(CGImageRef, CGAffineTransform, int);
-  }
-
-  //XXX: We should be using CGContextDrawTiledImage when we can. Even though it
-  // creates a pattern, it seems to go down a faster path than using a delegate
-  // like we do below
-  CGRect bounds = {
-    {0, 0,},
-    {static_cast<CGFloat>(CGImageGetWidth(image)), static_cast<CGFloat>(CGImageGetHeight(image))}
-  };
-  CGAffineTransform transform = CGAffineTransformConcat(CGAffineTransformMakeScale(1, -1), aUserSpace);
-  transform = CGAffineTransformTranslate(transform, 0, -static_cast<float>(CGImageGetHeight(image)));
-  return CGPatternCreate(CGImageRetain(image), bounds, transform, xStep, yStep, kCGPatternTilingConstantSpacing,
-                         true, &patternCallbacks);
-}
-
-static void
-SetFillFromPattern(CGContextRef cg, CGColorSpaceRef aColorSpace, const Pattern &aPattern)
-{
-  assert(!isGradient(aPattern));
-  if (aPattern.GetType() == PATTERN_COLOR) {
-
-    const Color& color = static_cast<const ColorPattern&>(aPattern).mColor;
-    //XXX: we should cache colors
-    CGColorRef cgcolor = ColorToCGColor(aColorSpace, color);
-    CGContextSetFillColorWithColor(cg, cgcolor);
-    CGColorRelease(cgcolor);
-  } else if (aPattern.GetType() == PATTERN_SURFACE) {
-
-    CGColorSpaceRef patternSpace;
-    patternSpace = CGColorSpaceCreatePattern (NULL);
-    CGContextSetFillColorSpace(cg, patternSpace);
-    CGColorSpaceRelease(patternSpace);
-
-    CGPatternRef pattern = CreateCGPattern(aPattern, CGContextGetCTM(cg));
-    CGFloat alpha = 1.;
-    CGContextSetFillPattern(cg, pattern, &alpha);
-    CGPatternRelease(pattern);
-  }
-}
-
-static void
-SetStrokeFromPattern(CGContextRef cg, CGColorSpaceRef aColorSpace, const Pattern &aPattern)
-{
-  assert(!isGradient(aPattern));
-  if (aPattern.GetType() == PATTERN_COLOR) {
-    const Color& color = static_cast<const ColorPattern&>(aPattern).mColor;
-    //XXX: we should cache colors
-    CGColorRef cgcolor = ColorToCGColor(aColorSpace, color);
-    CGContextSetStrokeColorWithColor(cg, cgcolor);
-    CGColorRelease(cgcolor);
-  } else if (aPattern.GetType() == PATTERN_SURFACE) {
-    CGColorSpaceRef patternSpace;
-    patternSpace = CGColorSpaceCreatePattern (NULL);
-    CGContextSetStrokeColorSpace(cg, patternSpace);
-    CGColorSpaceRelease(patternSpace);
-
-    CGPatternRef pattern = CreateCGPattern(aPattern, CGContextGetCTM(cg));
-    CGFloat alpha = 1.;
-    CGContextSetStrokePattern(cg, pattern, &alpha);
-    CGPatternRelease(pattern);
-  }
-
-}
-
-
-void
-DrawTargetCG::FillRect(const Rect &aRect,
-                        const Pattern &aPattern,
-                        const DrawOptions &aDrawOptions)
-{
-  CGContextSaveGState(mCg);
-
-  UnboundnessFixer fixer;
-  CGContextRef cg = fixer.Check(mCg, aDrawOptions.mCompositionOp);
-  CGContextSetAlpha(mCg, aDrawOptions.mAlpha);
-  CGContextSetBlendMode(mCg, ToBlendMode(aDrawOptions.mCompositionOp));
-
-  CGContextConcatCTM(cg, GfxMatrixToCGAffineTransform(mTransform));
-
-  if (isGradient(aPattern)) {
-    CGContextClipToRect(cg, RectToCGRect(aRect));
-    DrawGradient(cg, aPattern);
-  } else {
-    SetFillFromPattern(cg, mColorSpace, aPattern);
-    CGContextFillRect(cg, RectToCGRect(aRect));
-  }
-
-  fixer.Fix(mCg);
-  CGContextRestoreGState(mCg);
-}
-
-void
-DrawTargetCG::StrokeLine(const Point &p1, const Point &p2, const Pattern &aPattern, const StrokeOptions &aStrokeOptions, const DrawOptions &aDrawOptions)
-{
-  CGContextSaveGState(mCg);
-
-  UnboundnessFixer fixer;
-  CGContextRef cg = fixer.Check(mCg, aDrawOptions.mCompositionOp);
-  CGContextSetAlpha(mCg, aDrawOptions.mAlpha);
-  CGContextSetBlendMode(mCg, ToBlendMode(aDrawOptions.mCompositionOp));
-
-  CGContextConcatCTM(cg, GfxMatrixToCGAffineTransform(mTransform));
-
-  CGContextBeginPath(cg);
-  CGContextMoveToPoint(cg, p1.x, p1.y);
-  CGContextAddLineToPoint(cg, p2.x, p2.y);
-
-  SetStrokeOptions(cg, aStrokeOptions);
-
-  if (isGradient(aPattern)) {
-    CGContextReplacePathWithStrokedPath(cg);
-    //XXX: should we use EO clip here?
-    CGContextClip(cg);
-    DrawGradient(cg, aPattern);
-  } else {
-    SetStrokeFromPattern(cg, mColorSpace, aPattern);
-    CGContextStrokePath(cg);
-  }
-
-  fixer.Fix(mCg);
-  CGContextRestoreGState(mCg);
-}
-
-void
-DrawTargetCG::StrokeRect(const Rect &aRect,
-                         const Pattern &aPattern,
-                         const StrokeOptions &aStrokeOptions,
-                         const DrawOptions &aDrawOptions)
-{
-  CGContextSaveGState(mCg);
-
-  UnboundnessFixer fixer;
-  CGContextRef cg = fixer.Check(mCg, aDrawOptions.mCompositionOp);
-  CGContextSetAlpha(mCg, aDrawOptions.mAlpha);
-  CGContextSetBlendMode(mCg, ToBlendMode(aDrawOptions.mCompositionOp));
-
-  CGContextConcatCTM(cg, GfxMatrixToCGAffineTransform(mTransform));
-
-  // we don't need to set all of the stroke state because
-  // it doesn't apply when stroking rects
-  switch (aStrokeOptions.mLineJoin)
-  {
-    case JOIN_BEVEL:
-      CGContextSetLineJoin(cg, kCGLineJoinBevel);
-      break;
-    case JOIN_ROUND:
-      CGContextSetLineJoin(cg, kCGLineJoinRound);
-      break;
-    case JOIN_MITER:
-    case JOIN_MITER_OR_BEVEL:
-      CGContextSetLineJoin(cg, kCGLineJoinMiter);
-      break;
-  }
-  CGContextSetLineWidth(cg, aStrokeOptions.mLineWidth);
-
-  if (isGradient(aPattern)) {
-    // There's no CGContextClipStrokeRect so we do it by hand
-    CGContextBeginPath(cg);
-    CGContextAddRect(cg, RectToCGRect(aRect));
-    CGContextReplacePathWithStrokedPath(cg);
-    //XXX: should we use EO clip here?
-    CGContextClip(cg);
-    DrawGradient(cg, aPattern);
-  } else {
-    SetStrokeFromPattern(cg, mColorSpace, aPattern);
-    CGContextStrokeRect(cg, RectToCGRect(aRect));
-  }
-
-  fixer.Fix(mCg);
-  CGContextRestoreGState(mCg);
-}
-
-
-void
-DrawTargetCG::ClearRect(const Rect &aRect)
-{
-  CGContextSaveGState(mCg);
-  CGContextConcatCTM(mCg, GfxMatrixToCGAffineTransform(mTransform));
-
-  CGContextClearRect(mCg, RectToCGRect(aRect));
-
-  CGContextRestoreGState(mCg);
-}
-
-void
-DrawTargetCG::Stroke(const Path *aPath, const Pattern &aPattern, const StrokeOptions &aStrokeOptions, const DrawOptions &aDrawOptions)
-{
-  CGContextSaveGState(mCg);
-
-  UnboundnessFixer fixer;
-  CGContextRef cg = fixer.Check(mCg, aDrawOptions.mCompositionOp);
-  CGContextSetAlpha(mCg, aDrawOptions.mAlpha);
-  CGContextSetBlendMode(mCg, ToBlendMode(aDrawOptions.mCompositionOp));
-
-  CGContextConcatCTM(cg, GfxMatrixToCGAffineTransform(mTransform));
-
-
-  CGContextBeginPath(cg);
-
-  assert(aPath->GetBackendType() == BACKEND_COREGRAPHICS);
-  const PathCG *cgPath = static_cast<const PathCG*>(aPath);
-  CGContextAddPath(cg, cgPath->GetPath());
-
-  SetStrokeOptions(cg, aStrokeOptions);
-
-  if (isGradient(aPattern)) {
-    CGContextReplacePathWithStrokedPath(cg);
-    //XXX: should we use EO clip here?
-    CGContextClip(cg);
-    DrawGradient(cg, aPattern);
-  } else {
-    CGContextBeginPath(cg);
-    // XXX: we could put fill mode into the path fill rule if we wanted
-    const PathCG *cgPath = static_cast<const PathCG*>(aPath);
-    CGContextAddPath(cg, cgPath->GetPath());
-
-    SetStrokeFromPattern(cg, mColorSpace, aPattern);
-    CGContextStrokePath(cg);
-  }
-
-  fixer.Fix(mCg);
-  CGContextRestoreGState(mCg);
-}
-
-void
-DrawTargetCG::Fill(const Path *aPath, const Pattern &aPattern, const DrawOptions &aDrawOptions)
-{
-  assert(aPath->GetBackendType() == BACKEND_COREGRAPHICS);
-
-  CGContextSaveGState(mCg);
-
-  CGContextSetBlendMode(mCg, ToBlendMode(aDrawOptions.mCompositionOp));
-  UnboundnessFixer fixer;
-  CGContextRef cg = fixer.Check(mCg, aDrawOptions.mCompositionOp);
-  CGContextSetAlpha(cg, aDrawOptions.mAlpha);
-
-  CGContextConcatCTM(cg, GfxMatrixToCGAffineTransform(mTransform));
-
-  if (isGradient(aPattern)) {
-    // XXX: we should be able to avoid the extra SaveState that PushClip does
-    PushClip(aPath);
-    DrawGradient(cg, aPattern);
-    PopClip();
-  } else {
-    CGContextBeginPath(cg);
-    // XXX: we could put fill mode into the path fill rule if we wanted
-    const PathCG *cgPath = static_cast<const PathCG*>(aPath);
-    CGContextAddPath(cg, cgPath->GetPath());
-
-    SetFillFromPattern(cg, mColorSpace, aPattern);
-
-    if (cgPath->GetFillRule() == FILL_EVEN_ODD)
-      CGContextEOFillPath(cg);
-    else
-      CGContextFillPath(cg);
-  }
-
-  fixer.Fix(mCg);
-  CGContextRestoreGState(mCg);
-}
-
-
-void
-DrawTargetCG::FillGlyphs(ScaledFont *aFont, const GlyphBuffer &aBuffer, const Pattern &aPattern, const DrawOptions &aDrawOptions)
-{
-  assert(aBuffer.mNumGlyphs);
-  CGContextSaveGState(mCg);
-
-  CGContextSetBlendMode(mCg, ToBlendMode(aDrawOptions.mCompositionOp));
-  UnboundnessFixer fixer;
-  CGContextRef cg = fixer.Check(mCg, aDrawOptions.mCompositionOp);
-  CGContextSetAlpha(cg, aDrawOptions.mAlpha);
-
-  CGContextConcatCTM(cg, GfxMatrixToCGAffineTransform(mTransform));
-
-  ScaledFontMac* cgFont = static_cast<ScaledFontMac*>(aFont);
-  CGContextSetFont(cg, cgFont->mFont);
-  CGContextSetFontSize(cg, cgFont->mSize);
-
-  //XXX: we should use a stack vector here when we have a class like that
-  std::vector<CGGlyph> glyphs;
-  std::vector<CGPoint> positions;
-  glyphs.resize(aBuffer.mNumGlyphs);
-  positions.resize(aBuffer.mNumGlyphs);
-
-  CGFloat xprev = aBuffer.mGlyphs[0].mPosition.x;
-  CGFloat yprev = aBuffer.mGlyphs[0].mPosition.y;
-  CGContextSetTextPosition(cg, xprev, yprev);
-
-  // Handle the flip
-  CGAffineTransform matrix = CGAffineTransformMakeScale(1, -1);//CGAffineTransformMake(1, 0, 0, -1, 0, -mSize.height);
-  // "Note that the text matrix is not a part of the graphics state"
-  CGContextSetTextMatrix(cg, matrix);
-
-  for (unsigned int i = 0; i < aBuffer.mNumGlyphs; i++) {
-    glyphs[i] = aBuffer.mGlyphs[i].mIndex;
-    // XXX: CGPointMake might not be inlined
-    positions[i] = CGPointMake(aBuffer.mGlyphs[i].mPosition.x,
-                              -aBuffer.mGlyphs[i].mPosition.y);
-  }
-
-  //XXX: CGContextShowGlyphsAtPositions is 10.5+ for older versions use CGContextShowGlyphsWithAdvances
-  if (isGradient(aPattern)) {
-    CGContextSetTextDrawingMode(cg, kCGTextClip);
-    CGContextShowGlyphsAtPositions(cg, &glyphs.front(), &positions.front(), aBuffer.mNumGlyphs);
-    DrawGradient(cg, aPattern);
-  } else {
-    //XXX: with CoreGraphics we can stroke text directly instead of going
-    // through GetPath. It would be nice to add support for using that
-    CGContextSetTextDrawingMode(cg, kCGTextFill);
-    SetFillFromPattern(cg, mColorSpace, aPattern);
-    CGContextShowGlyphsAtPositions(cg, &glyphs.front(), &positions.front(), aBuffer.mNumGlyphs);
-  }
-
-  fixer.Fix(mCg);
-  CGContextRestoreGState(cg);
-}
-
-extern "C" {
-void
-CGContextResetClip(CGContextRef);
-};
-
-void
-DrawTargetCG::CopySurface(SourceSurface *aSurface,
-                          const IntRect& aSourceRect,
-                          const IntPoint &aDestination)
-{
-  CGImageRef image;
-  CGImageRef subimage = NULL;
-  if (aSurface->GetType() == SURFACE_COREGRAPHICS_IMAGE) {
-    image = static_cast<SourceSurfaceCG*>(aSurface)->GetImage();
-    /* we have two options here:
-     *  - create a subimage -- this is slower
-     *  - fancy things with clip and different dest rects */
-    {
-      subimage = CGImageCreateWithImageInRect(image, IntRectToCGRect(aSourceRect));
-      image = subimage;
-    }
-    // XXX: it might be more efficient for us to do the copy directly if we have access to the bits
-
-    CGContextSaveGState(mCg);
-
-    // CopySurface ignores the clip, so we need to use private API to temporarily reset it
-    CGContextResetClip(mCg);
-    CGContextSetBlendMode(mCg, kCGBlendModeCopy);
-
-    CGContextScaleCTM(mCg, 1, -1);
-
-    CGRect flippedRect = CGRectMake(aDestination.x, -(aDestination.y + aSourceRect.height),
-                                    aSourceRect.width, aSourceRect.height);
-
-    CGContextDrawImage(mCg, flippedRect, image);
-
-    CGContextRestoreGState(mCg);
+    CGContextDrawImage(mCg, RectToCGRect(aDest), image);
 
     CGImageRelease(subimage);
   }
 }
 
 void
-DrawTargetCG::DrawSurfaceWithShadow(SourceSurface *aSurface, const Point &aDest, const Color &aColor, const Point &aOffset, Float aSigma, CompositionOp aOperator)
+DrawTargetCG::FillRect(const Rect &aRect,
+                        const Pattern &aPattern,
+                        const DrawOptions &aOptions)
 {
-  CGImageRef image;
-  CGImageRef subimage = NULL;
-  if (aSurface->GetType() == SURFACE_COREGRAPHICS_IMAGE) {
-    image = static_cast<SourceSurfaceCG*>(aSurface)->GetImage();
-
-    IntSize size = aSurface->GetSize();
-    CGContextSaveGState(mCg);
-    //XXX do we need to do the fixup here?
-    CGContextSetBlendMode(mCg, ToBlendMode(aOperator));
-
-    CGContextScaleCTM(mCg, 1, -1);
+  //XXX: it would be nice to hang a CGColor off of the pattern here
+  if (aPattern.GetType() == COLOR) {
+    Color color = static_cast<const ColorPattern*>(&aPattern)->mColor;
+    //XXX: the m prefixes are painful here
+    CGContextSetRGBFillColor(mCg, color.mR, color.mG, color.mB, color.mA);
+  }
 
-    CGRect flippedRect = CGRectMake(aDest.x, -(aDest.y + size.height),
-                                    size.width, size.height);
+  CGContextSetBlendMode(mCg, ToBlendMode(aOptions.mCompositionOp));
+  CGContextFillRect(mCg, RectToCGRect(aRect));
+}
 
-    CGColorRef color = ColorToCGColor(mColorSpace, aColor);
-    CGSize offset = {aOffset.x, -aOffset.y};
-    // CoreGraphics needs twice sigma as it's amount of blur
-    CGContextSetShadowWithColor(mCg, offset, 2*aSigma, color);
-    CGColorRelease(color);
-
-    CGContextDrawImage(mCg, flippedRect, image);
-
-    CGContextRestoreGState(mCg);
-
-    CGImageRelease(subimage);
-  }
-}
 
 bool
-DrawTargetCG::Init(CGContextRef cgContext, const IntSize &aSize)
+DrawTargetCG::Init(const IntSize &aSize)
 {
-  // XXX: we should come up with some consistent semantics for dealing
-  // with zero area drawtargets
-  if (aSize.width == 0 || aSize.height == 0) {
-    mColorSpace = NULL;
-    mCg = NULL;
-    return false;
-  }
-
-  //XXX: handle SurfaceFormat
-
-  //XXX: we'd be better off reusing the Colorspace across draw targets
-  mColorSpace = CGColorSpaceCreateDeviceRGB();
-
-  mSize = aSize;
-
-  mCg = cgContext;
-
-  mData = NULL;
-
-  assert(mCg);
-  // CGContext's default to have the origin at the bottom left
-  // so flip it to the top left
-  CGContextTranslateCTM(mCg, 0, mSize.height);
-  CGContextScaleCTM(mCg, 1, -1);
-
-  //XXX: set correct format
-  mFormat = FORMAT_B8G8R8A8;
-
-  return true;
-}
-
-bool
-DrawTargetCG::Init(const IntSize &aSize, SurfaceFormat &)
-{
-  // XXX: we should come up with some consistent semantics for dealing
-  // with zero area drawtargets
-  if (aSize.width == 0 || aSize.height == 0) {
-    mColorSpace = NULL;
-    mCg = NULL;
-    return false;
-  }
-
-  //XXX: handle SurfaceFormat
-
-  //XXX: we'd be better off reusing the Colorspace across draw targets
-  mColorSpace = CGColorSpaceCreateDeviceRGB();
+  CGColorSpaceRef cgColorspace;
+  cgColorspace = CGColorSpaceCreateDeviceRGB();
 
   mSize = aSize;
 
   int bitsPerComponent = 8;
-  int stride = mSize.width*4;
+  int stride = mSize.width;
 
   CGBitmapInfo bitinfo;
 
   bitinfo = kCGBitmapByteOrder32Host | kCGImageAlphaPremultipliedFirst;
 
-  // XXX: currently we allocate ourselves so that we can easily return a gfxImageSurface
-  // we might not need to later if once we don't need to support gfxImageSurface
-  //XXX: currently Init implicitly clears, that can often be a waste of time
-  // XXX: leaked
-  mData = calloc(mSize.height * stride, 1);
-  // XXX: what should we do if this fails?
-  mCg = CGBitmapContextCreate (mData,
-                               mSize.width,
-                               mSize.height,
-                               bitsPerComponent,
-                               stride,
-                               mColorSpace,
-                               bitinfo);
+  // XXX: mWidth is ugly
+  mCg = CGBitmapContextCreate (NULL,
+                         mSize.width,
+			 mSize.height,
+			 bitsPerComponent,
+			 stride,
+			 cgColorspace,
+			 bitinfo);
 
-
-  assert(mCg);
-  // CGContext's default to have the origin at the bottom left
-  // so flip it to the top left
-  CGContextTranslateCTM(mCg, 0, mSize.height);
-  CGContextScaleCTM(mCg, 1, -1);
-
-  //XXX: set correct format
-  mFormat = FORMAT_B8G8R8A8;
+  CGColorSpaceRelease (cgColorspace);
 
   return true;
 }
-
-TemporaryRef<PathBuilder>
-DrawTargetCG::CreatePathBuilder(FillRule aFillRule) const
-{
-  RefPtr<PathBuilderCG> pb = new PathBuilderCG(aFillRule);
-  return pb;
-}
-
-void*
-DrawTargetCG::GetNativeSurface(NativeSurfaceType aType)
-{
-  if (aType == NATIVE_SURFACE_CGCONTEXT) {
-    return mCg;
-  } else {
-    return NULL;
-  }
-}
-
-void
-DrawTargetCG::Mask(const Pattern &aSource,
-                   const Pattern &aMask,
-                   const DrawOptions &aDrawOptions)
-{
-
-  CGContextSaveGState(mCg);
-
-  if (isGradient(aMask)) {
-    assert(0);
-  } else {
-    if (aMask.GetType() == PATTERN_COLOR) {
-      DrawOptions drawOptions(aDrawOptions);
-      const Color& color = static_cast<const ColorPattern&>(aMask).mColor;
-      drawOptions.mAlpha *= color.a;
-      assert(0);
-      // XXX: we need to get a rect that when transformed covers the entire surface
-      //Rect
-      //FillRect(rect, aSource, drawOptions);
-    } else if (aMask.GetType() == PATTERN_SURFACE) {
-      const SurfacePattern& pat = static_cast<const SurfacePattern&>(aMask);
-      CGImageRef mask = static_cast<SourceSurfaceCG*>(pat.mSurface.get())->GetImage();
-      Rect rect(0,0, CGImageGetWidth(mask), CGImageGetHeight(mask));
-      // XXX: probably we need to do some flipping of the image or something
-      CGContextClipToMask(mCg, RectToCGRect(rect), mask);
-      FillRect(rect, aSource, aDrawOptions);
-    }
-  }
-
-  CGContextRestoreGState(mCg);
-}
-
-void
-DrawTargetCG::PushClipRect(const Rect &aRect)
-{
-  CGContextSaveGState(mCg);
-
-  CGContextClipToRect(mCg, RectToCGRect(aRect));
-}
-
-
-void
-DrawTargetCG::PushClip(const Path *aPath)
-{
-  CGContextSaveGState(mCg);
-
-  CGContextBeginPath(mCg);
-  assert(aPath->GetBackendType() == BACKEND_COREGRAPHICS);
-
-  const PathCG *cgPath = static_cast<const PathCG*>(aPath);
-
-  // Weirdly, CoreGraphics clips empty paths as all shown
-  // but emtpy rects as all clipped.  We detect this situation and
-  // workaround it appropriately
-  if (CGPathIsEmpty(cgPath->GetPath())) {
-    // XXX: should we return here?
-    CGContextClipToRect(mCg, CGRectZero);
-  }
-
-
-  CGContextAddPath(mCg, cgPath->GetPath());
-  if (cgPath->GetFillRule() == FILL_EVEN_ODD)
-    CGContextEOClip(mCg);
-  else
-    CGContextClip(mCg);
-}
-
-void
-DrawTargetCG::PopClip()
-{
-  CGContextRestoreGState(mCg);
-}
-
-
-
 }
 }
--- a/gfx/2d/DrawTargetCG.h
+++ b/gfx/2d/DrawTargetCG.h
@@ -30,161 +30,56 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
+#pragma once
+
 #include <ApplicationServices/ApplicationServices.h>
 
 #include "2D.h"
 #include "Rect.h"
-#include "PathCG.h"
-
 namespace mozilla {
 namespace gfx {
 
-static inline CGAffineTransform
-GfxMatrixToCGAffineTransform(Matrix m)
-{
-  CGAffineTransform t;
-  t.a = m._11;
-  t.b = m._12;
-  t.c = m._21;
-  t.d = m._22;
-  t.tx = m._31;
-  t.ty = m._32;
-  return t;
-}
-
-static inline Rect
-CGRectToRect(CGRect rect)
-{
-  return Rect(rect.origin.x,
-              rect.origin.y,
-              rect.size.width,
-              rect.size.height);
-}
-
-static inline void
-SetStrokeOptions(CGContextRef cg, const StrokeOptions &aStrokeOptions)
-{
-  switch (aStrokeOptions.mLineCap)
-  {
-    case CAP_BUTT:
-      CGContextSetLineCap(cg, kCGLineCapButt);
-      break;
-    case CAP_ROUND:
-      CGContextSetLineCap(cg, kCGLineCapRound);
-      break;
-    case CAP_SQUARE:
-      CGContextSetLineCap(cg, kCGLineCapSquare);
-      break;
-  }
-
-  switch (aStrokeOptions.mLineJoin)
-  {
-    case JOIN_BEVEL:
-      CGContextSetLineJoin(cg, kCGLineJoinBevel);
-      break;
-    case JOIN_ROUND:
-      CGContextSetLineJoin(cg, kCGLineJoinRound);
-      break;
-    case JOIN_MITER:
-    case JOIN_MITER_OR_BEVEL:
-      CGContextSetLineJoin(cg, kCGLineJoinMiter);
-      break;
-  }
-
-  CGContextSetLineWidth(cg, aStrokeOptions.mLineWidth);
-  CGContextSetMiterLimit(cg, aStrokeOptions.mMiterLimit);
-
-  // XXX: rename mDashLength to dashLength
-  if (aStrokeOptions.mDashLength > 1) {
-    // we use a regular array instead of a std::vector here because we don't want to leak the <vector> include
-    CGFloat *dashes = new CGFloat[aStrokeOptions.mDashLength];
-    for (size_t i=0; i<aStrokeOptions.mDashLength; i++) {
-      dashes[i] = aStrokeOptions.mDashPattern[i];
-    }
-    CGContextSetLineDash(cg, aStrokeOptions.mDashOffset, dashes, aStrokeOptions.mDashLength);
-    delete[] dashes;
-  }
-}
-
-
 class DrawTargetCG : public DrawTarget
 {
 public:
   DrawTargetCG();
   virtual ~DrawTargetCG();
 
-  virtual BackendType GetType() const { return BACKEND_COREGRAPHICS; }
+  virtual BackendType GetType() const { return COREGRAPHICS; }
   virtual TemporaryRef<SourceSurface> Snapshot();
 
   virtual void DrawSurface(SourceSurface *aSurface,
                            const Rect &aDest,
                            const Rect &aSource,
-                           const DrawSurfaceOptions &aSurfOptions = DrawSurfaceOptions(),
-                           const DrawOptions &aOptions = DrawOptions());
+                           const DrawOptions &aOptions = DrawOptions(),
+                           const DrawSurfaceOptions &aSurfOptions = DrawSurfaceOptions());
 
   virtual void FillRect(const Rect &aRect,
                         const Pattern &aPattern,
                         const DrawOptions &aOptions = DrawOptions());
 
 
-  //XXX: why do we take a reference to SurfaceFormat?
-  bool Init(const IntSize &aSize, SurfaceFormat&);
+  bool Init(const IntSize &aSize);
   bool Init(CGContextRef cgContext, const IntSize &aSize);
 
-
-  virtual void Flush() {}
-
-  virtual void DrawSurfaceWithShadow(SourceSurface *, const Point &, const Color &, const Point &, Float, CompositionOp);
-  virtual void ClearRect(const Rect &);
-  virtual void CopySurface(SourceSurface *, const IntRect&, const IntPoint&);
-  virtual void StrokeRect(const Rect &, const Pattern &, const StrokeOptions&, const DrawOptions&);
-  virtual void StrokeLine(const Point &, const Point &, const Pattern &, const StrokeOptions &, const DrawOptions &);
-  virtual void Stroke(const Path *, const Pattern &, const StrokeOptions &, const DrawOptions &);
-  virtual void Fill(const Path *, const Pattern &, const DrawOptions &);
-  virtual void FillGlyphs(ScaledFont *, const GlyphBuffer&, const Pattern &, const DrawOptions &);
-  virtual void Mask(const Pattern &aSource,
-                    const Pattern &aMask,
-                    const DrawOptions &aOptions = DrawOptions());
-  virtual void PushClip(const Path *);
-  virtual void PushClipRect(const Rect &aRect);
-  virtual void PopClip();
-  virtual TemporaryRef<SourceSurface> CreateSourceSurfaceFromNativeSurface(const NativeSurface&) const { return NULL;}
-  virtual TemporaryRef<DrawTarget> CreateSimilarDrawTarget(const IntSize &, SurfaceFormat) const;
-  virtual TemporaryRef<PathBuilder> CreatePathBuilder(FillRule) const;
-  virtual TemporaryRef<GradientStops> CreateGradientStops(GradientStop *, uint32_t,
-                                                          ExtendMode aExtendMode = EXTEND_CLAMP) const;
-
-  virtual void *GetNativeSurface(NativeSurfaceType);
-
-  virtual IntSize GetSize() { return mSize; }
-
-
   /* This is for creating good compatible surfaces */
   virtual TemporaryRef<SourceSurface> CreateSourceSurfaceFromData(unsigned char *aData,
                                                             const IntSize &aSize,
                                                             int32_t aStride,
                                                             SurfaceFormat aFormat) const;
   virtual TemporaryRef<SourceSurface> OptimizeSourceSurface(SourceSurface *aSurface) const;
-  CGContextRef GetCGContext() {
-      return mCg;
-  }
 private:
   bool InitCGRenderTarget();
 
   IntSize mSize;
-  CGColorSpaceRef mColorSpace;
   CGContextRef mCg;
 
-  void *mData;
-
-  SurfaceFormat mFormat;
-
 };
 
 }
 }
--- a/gfx/2d/DrawTargetSkia.cpp
+++ b/gfx/2d/DrawTargetSkia.cpp
@@ -32,17 +32,17 @@
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include "DrawTargetSkia.h"
 #include "SourceSurfaceSkia.h"
-#include "ScaledFontBase.h"
+#include "ScaledFontSkia.h"
 #include "skia/SkDevice.h"
 #include "skia/SkTypeface.h"
 #include "skia/SkGradientShader.h"
 #include "skia/SkBlurDrawLooper.h"
 #include "skia/SkBlurMaskFilter.h"
 #include "skia/SkColorFilter.h"
 #include "skia/SkLayerRasterizer.h"
 #include "skia/SkLayerDrawLooper.h"
@@ -53,17 +53,16 @@
 #include "Tools.h"
 #include <algorithm>
 
 namespace mozilla {
 namespace gfx {
 
 SkColor ColorToSkColor(const Color &color, Float aAlpha)
 {
-  //XXX: do a better job converting to int
   return SkColorSetARGB(color.a*aAlpha*255.0, color.r*255.0, color.g*255.0, color.b*255.0);
 }
 
 class GradientStopsSkia : public GradientStops
 {
 public:
   GradientStopsSkia(const std::vector<GradientStop>& aStops, uint32_t aNumStops)
     : mCount(aNumStops)
@@ -516,20 +515,20 @@ DrawTargetSkia::FillGlyphs(ScaledFont *a
                            const DrawOptions &aOptions)
 {
   if (aFont->GetType() != FONT_MAC && aFont->GetType() != FONT_SKIA) {
     return;
   }
 
   MarkChanged();
 
-  ScaledFontBase* skiaFont = static_cast<ScaledFontBase*>(aFont);
+  ScaledFontSkia* skiaFont = static_cast<ScaledFontSkia*>(aFont);
 
   AutoPaintSetup paint(mCanvas.get(), aOptions, aPattern);
-  paint.mPaint.setTypeface(skiaFont->GetSkTypeface());
+  paint.mPaint.setTypeface(skiaFont->mTypeface);
   paint.mPaint.setTextSize(SkFloatToScalar(skiaFont->mSize));
   paint.mPaint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
   
   std::vector<uint16_t> indices;
   std::vector<SkPoint> offsets;
   indices.resize(aBuffer.mNumGlyphs);
   offsets.resize(aBuffer.mNumGlyphs);
 
--- a/gfx/2d/Factory.cpp
+++ b/gfx/2d/Factory.cpp
@@ -39,30 +39,23 @@
 
 #ifdef USE_CAIRO
 #include "DrawTargetCairo.h"
 #include "ScaledFontCairo.h"
 #endif
 
 #ifdef USE_SKIA
 #include "DrawTargetSkia.h"
-#include "ScaledFontBase.h"
+#ifdef XP_MACOSX
+#include "ScaledFontMac.h"
 #endif
-
 #ifdef WIN32
 #include "ScaledFontWin.h"
 #endif
-
-#ifdef XP_MACOSX
-#include "ScaledFontMac.h"
-#endif
-
-
-#ifdef XP_MACOSX
-#include "DrawTargetCG.h"
+#include "ScaledFontSkia.h"
 #endif
 
 #ifdef WIN32
 #include "DrawTargetD2D.h"
 #include "ScaledFontDWrite.h"
 #include <d3d10_1.h>
 #endif
 
@@ -92,40 +85,28 @@ Factory::CreateDrawTarget(BackendType aB
     {
       RefPtr<DrawTargetD2D> newTarget;
       newTarget = new DrawTargetD2D();
       if (newTarget->Init(aSize, aFormat)) {
         return newTarget;
       }
       break;
     }
-#elif defined XP_MACOSX || defined ANDROID
+#endif
 #ifdef USE_SKIA
   case BACKEND_SKIA:
     {
       RefPtr<DrawTargetSkia> newTarget;
       newTarget = new DrawTargetSkia();
       if (newTarget->Init(aSize, aFormat)) {
         return newTarget;
       }
       break;
     }
 #endif
-#ifdef XP_MACOSX
-  case BACKEND_COREGRAPHICS:
-    {
-      RefPtr<DrawTargetCG> newTarget;
-      newTarget = new DrawTargetCG();
-      if (newTarget->Init(aSize, aFormat)) {
-        return newTarget;
-      }
-      break;
-    }
-#endif
-#endif
   default:
     gfxDebug() << "Invalid draw target type specified.";
     return NULL;
   }
 
   gfxDebug() << "Failed to create DrawTarget, Type: " << aBackend << " Size: " << aSize;
   // Failed
   return NULL;
@@ -136,32 +117,32 @@ Factory::CreateScaledFontForNativeFont(c
 {
   switch (aNativeFont.mType) {
 #ifdef WIN32
   case NATIVE_FONT_DWRITE_FONT_FACE:
     {
       return new ScaledFontDWrite(static_cast<IDWriteFontFace*>(aNativeFont.mFont), aSize);
     }
 #endif
+#ifdef USE_SKIA
 #ifdef XP_MACOSX
   case NATIVE_FONT_MAC_FONT_FACE:
     {
       return new ScaledFontMac(static_cast<CGFontRef>(aNativeFont.mFont), aSize);
     }
 #endif
-#ifdef USE_SKIA
 #ifdef WIN32
   case NATIVE_FONT_GDI_FONT_FACE:
     {
       return new ScaledFontWin(static_cast<gfxGDIFont*>(aNativeFont.mFont), aSize);
     }
 #endif
   case NATIVE_FONT_SKIA_FONT_FACE:
     {
-      return new ScaledFontBase(static_cast<gfxFont*>(aNativeFont.mFont), aSize);
+      return new ScaledFontSkia(static_cast<gfxFont*>(aNativeFont.mFont), aSize);
     }
 #endif
   case NATIVE_FONT_CAIRO_FONT_FACE:
     {
       return new ScaledFontCairo(static_cast<gfxFont*>(aNativeFont.mFont));
     }
   default:
     gfxWarning() << "Invalid native font type specified.";
--- a/gfx/2d/Makefile.in
+++ b/gfx/2d/Makefile.in
@@ -57,45 +57,37 @@ EXPORTS_mozilla/gfx	= \
         BaseRect.h \
         BaseSize.h \
         Blur.h \
         PathHelpers.h \
         Point.h \
         Matrix.h \
         Rect.h \
         Types.h \
-        UserData.h \
 	$(NULL)
 
 CPPSRCS	= \
 	Factory.cpp \
         Matrix.cpp \
         DrawTargetCairo.cpp \
         ScaledFontCairo.cpp \
         SourceSurfaceCairo.cpp \
         PathCairo.cpp \
         Blur.cpp \
-        ScaledFontBase.cpp \
         $(NULL)
 
-ifeq (cocoa,$(MOZ_WIDGET_TOOLKIT))
-CPPSRCS	+= \
-	   SourceSurfaceCG.cpp \
-	   DrawTargetCG.cpp \
-	   PathCG.cpp \
-	   $(NULL)
-endif
 
 DEFINES += -DMOZ_GFX -DUSE_CAIRO
 
 ifdef MOZ_ENABLE_SKIA
 CPPSRCS	+= \
         SourceSurfaceSkia.cpp \
         DrawTargetSkia.cpp \
         PathSkia.cpp \
+        ScaledFontSkia.cpp \
         $(NULL)
 
 DEFINES += -DUSE_SKIA
 
 endif
 
 ifeq (cocoa,$(MOZ_WIDGET_TOOLKIT))
 ifdef MOZ_ENABLE_SKIA
deleted file mode 100644
--- a/gfx/2d/PathCG.cpp
+++ /dev/null
@@ -1,273 +0,0 @@
-/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
- * ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is Mozilla Corporation code.
- *
- * The Initial Developer of the Original Code is Mozilla Foundation.
- * Portions created by the Initial Developer are Copyright (C) 2011
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *   Bas Schouten <bschouten@mozilla.com>
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or
- * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-
-#include "PathCG.h"
-#include <math.h>
-#include "DrawTargetCG.h"
-#include "Logging.h"
-
-namespace mozilla {
-namespace gfx {
-
-PathBuilderCG::~PathBuilderCG()
-{
-  CGPathRelease(mCGPath);
-}
-
-void
-PathBuilderCG::MoveTo(const Point &aPoint)
-{
-  CGPathMoveToPoint(mCGPath, NULL, aPoint.x, aPoint.y);
-}
-
-void
-PathBuilderCG::LineTo(const Point &aPoint)
-{
-  if (CGPathIsEmpty(mCGPath))
-    MoveTo(aPoint);
-  else
-    CGPathAddLineToPoint(mCGPath, NULL, aPoint.x, aPoint.y);
-}
-
-void
-PathBuilderCG::BezierTo(const Point &aCP1,
-                         const Point &aCP2,
-                         const Point &aCP3)
-{
-
-  if (CGPathIsEmpty(mCGPath))
-    MoveTo(aCP1);
-  else
-    CGPathAddCurveToPoint(mCGPath, NULL,
-                          aCP1.x, aCP1.y,
-                          aCP2.x, aCP2.y,
-                          aCP3.x, aCP3.y);
-
-}
-
-void
-PathBuilderCG::QuadraticBezierTo(const Point &aCP1,
-                                  const Point &aCP2)
-{
-  if (CGPathIsEmpty(mCGPath))
-    MoveTo(aCP1);
-  else
-    CGPathAddQuadCurveToPoint(mCGPath, NULL,
-                              aCP1.x, aCP1.y,
-                              aCP2.x, aCP2.y);
-}
-
-void
-PathBuilderCG::Close()
-{
-  if (!CGPathIsEmpty(mCGPath))
-    CGPathCloseSubpath(mCGPath);
-}
-
-void
-PathBuilderCG::Arc(const Point &aOrigin, Float aRadius, Float aStartAngle,
-                 Float aEndAngle, bool aAntiClockwise)
-{
-}
-
-Point
-PathBuilderCG::CurrentPoint() const
-{
-  CGPoint pt = CGPathGetCurrentPoint(mCGPath);
-  Point ret(pt.x, pt.y);
-  return ret;
-}
-
-void
-PathBuilderCG::EnsureActive(const Point &aPoint)
-{
-}
-
-TemporaryRef<Path>
-PathBuilderCG::Finish()
-{
-  RefPtr<PathCG> path = new PathCG(mCGPath, mFillRule);
-  return path;
-}
-
-TemporaryRef<PathBuilder>
-PathCG::CopyToBuilder(FillRule aFillRule) const
-{
-  CGMutablePathRef path = CGPathCreateMutableCopy(mPath);
-  RefPtr<PathBuilderCG> builder = new PathBuilderCG(path, aFillRule);
-  return builder;
-}
-
-
-
-TemporaryRef<PathBuilder>
-PathCG::TransformedCopyToBuilder(const Matrix &aTransform, FillRule aFillRule) const
-{
-  // 10.7 adds CGPathCreateMutableCopyByTransformingPath it might be faster than doing
-  // this by hand
-
-  struct TransformApplier {
-    CGMutablePathRef path;
-    CGAffineTransform transform;
-    static void
-    TranformCGPathApplierFunc(void *vinfo, const CGPathElement *element)
-    {
-      TransformApplier *info = reinterpret_cast<TransformApplier*>(vinfo);
-      switch (element->type) {
-        case kCGPathElementMoveToPoint:
-          {
-            CGPoint pt = element->points[0];
-            CGPathMoveToPoint(info->path, &info->transform, pt.x, pt.y);
-            break;
-          }
-        case kCGPathElementAddLineToPoint:
-          {
-            CGPoint pt = element->points[0];
-            CGPathAddLineToPoint(info->path, &info->transform, pt.x, pt.y);
-            break;
-          }
-        case kCGPathElementAddQuadCurveToPoint:
-          {
-            CGPoint pt  = element->points[0];
-            CGPoint cpt = element->points[1];
-            CGPathAddQuadCurveToPoint(info->path, &info->transform, cpt.x, cpt.y, pt.x, pt.y);
-            break;
-          }
-        case kCGPathElementAddCurveToPoint:
-          {
-            CGPoint pt   = element->points[0];
-            CGPoint cpt1 = element->points[1];
-            CGPoint cpt2 = element->points[2];
-            CGPathAddCurveToPoint(info->path, &info->transform, cpt1.x, cpt1.y, cpt2.x, cpt2.y, pt.x, pt.y);
-            break;
-          }
-        case kCGPathElementCloseSubpath:
-          {
-            CGPathCloseSubpath(info->path);
-            break;
-          }
-      }
-    }
-  };
-
-  TransformApplier ta;
-  ta.path = CGPathCreateMutable();
-  ta.transform = GfxMatrixToCGAffineTransform(aTransform);
-
-  CGPathApply(mPath, &ta, TransformApplier::TranformCGPathApplierFunc);
-  RefPtr<PathBuilderCG> builder = new PathBuilderCG(ta.path, aFillRule);
-  return builder;
-}
-
-
-bool
-PathCG::ContainsPoint(const Point &aPoint, const Matrix &aTransform) const
-{
-  Matrix inverse = aTransform;
-  inverse.Invert();
-  Point transformedPoint = inverse*aPoint;
-  // We could probably drop the input transform and just transform the point at the caller?
-  CGPoint point = {transformedPoint.x, transformedPoint.y};
-
-  // The transform parameter of CGPathContainsPoint doesn't seem to work properly on OS X 10.5
-  // so we transform aPoint ourselves.
-  return CGPathContainsPoint(mPath, NULL, point, mFillRule == FILL_EVEN_ODD);
-}
-
-static size_t
-PutBytesNull(void *info, const void *buffer, size_t count)
-{
-  return count;
-}
-
-/* The idea of a scratch context comes from WebKit */
-static CGContextRef
-CreateScratchContext()
-{
-  CGDataConsumerCallbacks callbacks = {PutBytesNull, NULL};
-  CGDataConsumerRef consumer = CGDataConsumerCreate(NULL, &callbacks);
-  CGContextRef cg = CGPDFContextCreate(consumer, NULL, NULL);
-  CGDataConsumerRelease(consumer);
-  return cg;
-}
-
-static CGContextRef
-ScratchContext()
-{
-  static CGContextRef cg = CreateScratchContext();
-  return cg;
-}
-
-//XXX: what should these functions return for an empty path?
-// currently they return CGRectNull {inf,inf, 0, 0}
-Rect
-PathCG::GetBounds(const Matrix &aTransform) const
-{
-  //XXX: are these bounds tight enough
-  Rect bounds = CGRectToRect(CGPathGetBoundingBox(mPath));
-  //XXX: curretnly this returns the bounds of the transformed bounds
-  // this is strictly looser than the bounds of the transformed path
-  return aTransform.TransformBounds(bounds);
-}
-
-Rect
-PathCG::GetStrokedBounds(const StrokeOptions &aStrokeOptions,
-                         const Matrix &aTransform) const
-{
-  // 10.7 has CGPathCreateCopyByStrokingPath which we could use
-  // instead of this scratch context business
-  CGContextRef cg = ScratchContext();
-
-  CGContextSaveGState(cg);
-
-  CGContextBeginPath(cg);
-  CGContextAddPath(cg, mPath);
-
-  SetStrokeOptions(cg, aStrokeOptions);
-
-  CGContextReplacePathWithStrokedPath(cg);
-  Rect bounds = CGRectToRect(CGContextGetPathBoundingBox(cg));
-
-  CGContextRestoreGState(cg);
-
-  return aTransform.TransformBounds(bounds);
-}
-
-
-}
-
-}
deleted file mode 100644
--- a/gfx/2d/PathCG.h
+++ /dev/null
@@ -1,133 +0,0 @@
-/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
- * ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is Mozilla Corporation code.
- *
- * The Initial Developer of the Original Code is Mozilla Foundation.
- * Portions created by the Initial Developer are Copyright (C) 2011
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *   Bas Schouten <bschouten@mozilla.com>
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or
- * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-
-#ifndef MOZILLA_GFX_PATHCG_H_
-#define MOZILLA_GFX_PATHCG_H_
-
-#include <ApplicationServices/ApplicationServices.h>
-#include "2D.h"
-
-namespace mozilla {
-namespace gfx {
-
-class PathCG;
-
-class PathBuilderCG : public PathBuilder
-{
-public:
-  // absorbs a reference of aPath
-  PathBuilderCG(CGMutablePathRef aPath, FillRule aFillRule)
-    : mFigureActive(false)
-    , mFillRule(aFillRule)
-  {
-      mCGPath = aPath;
-  }
-
-  PathBuilderCG(FillRule aFillRule)
-    : mFigureActive(false)
-    , mFillRule(aFillRule)
-  {
-      mCGPath = CGPathCreateMutable();
-  }
-
-  virtual ~PathBuilderCG();
-
-  virtual void MoveTo(const Point &aPoint);
-  virtual void LineTo(const Point &aPoint);
-  virtual void BezierTo(const Point &aCP1,
-                        const Point &aCP2,
-                        const Point &aCP3);
-  virtual void QuadraticBezierTo(const Point &aCP1,
-                                 const Point &aCP2);
-  virtual void Close();
-  virtual void Arc(const Point &aOrigin, Float aRadius, Float aStartAngle,
-                   Float aEndAngle, bool aAntiClockwise = false);
-  virtual Point CurrentPoint() const;
-
-  virtual TemporaryRef<Path> Finish();
-
-private:
-  friend class PathCG;
-
-  void EnsureActive(const Point &aPoint);
-
-  CGMutablePathRef mCGPath;
-  bool mFigureActive;
-  Point mCurrentPoint;
-  Point mBeginPoint;
-  FillRule mFillRule;
-};
-
-class PathCG : public Path
-{
-public:
-  PathCG(CGMutablePathRef aPath, FillRule aFillRule)
-    : mPath(aPath)
-    , mFillRule(aFillRule)
-  {
-    CGPathRetain(mPath);
-  }
-  virtual ~PathCG() { CGPathRelease(mPath); }
-
-  virtual BackendType GetBackendType() const { return BACKEND_COREGRAPHICS; }
-
-  virtual TemporaryRef<PathBuilder> CopyToBuilder(FillRule aFillRule = FILL_WINDING) const;
-  virtual TemporaryRef<PathBuilder> TransformedCopyToBuilder(const Matrix &aTransform,
-                                                             FillRule aFillRule = FILL_WINDING) const;
-
-  virtual bool ContainsPoint(const Point &aPoint, const Matrix &aTransform) const;
-  virtual Rect GetBounds(const Matrix &aTransform = Matrix()) const;
-  virtual Rect GetStrokedBounds(const StrokeOptions &aStrokeOptions,
-                                const Matrix &aTransform = Matrix()) const;
-
-  virtual FillRule GetFillRule() const { return mFillRule; }
-
-  CGMutablePathRef GetPath() const { return mPath; }
-
-private:
-  friend class DrawTargetCG;
-
-  CGMutablePathRef mPath;
-  bool mEndedActive;
-  Point mEndPoint;
-  FillRule mFillRule;
-};
-
-}
-}
-
-#endif
deleted file mode 100644
--- a/gfx/2d/ScaledFontBase.cpp
+++ /dev/null
@@ -1,120 +0,0 @@
-/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
- * ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is Mozilla Corporation code.
- *
- * The Initial Developer of the Original Code is Mozilla Foundation.
- * Portions created by the Initial Developer are Copyright (C) 2011
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *   Matt Woodrow <mwoodrow@mozilla.com>
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or
- * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-
-#include "ScaledFontBase.h"
-#ifdef USE_SKIA
-#include "PathSkia.h"
-#include "skia/SkPaint.h"
-#include "skia/SkPath.h"
-#endif
-#include <vector>
-#include <cmath>
-using namespace std;
-#include "gfxFont.h"
-
-namespace mozilla {
-namespace gfx {
-#ifdef USE_SKIA
-static SkTypeface::Style gfxFontStyleToSkia(const gfxFontStyle* aStyle)
-{
-  if (aStyle->style == NS_FONT_STYLE_ITALIC) {
-    if (aStyle->weight == NS_FONT_WEIGHT_BOLD) {
-      return SkTypeface::kBoldItalic;
-    }
-    return SkTypeface::kItalic;
-  }
-  if (aStyle->weight == NS_FONT_WEIGHT_BOLD) {
-    return SkTypeface::kBold;
-  }
-  return SkTypeface::kNormal;
-}
-
-ScaledFontBase::ScaledFontBase(gfxFont* aFont, Float aSize)
-  : mSize(aSize)
-{
-  NS_LossyConvertUTF16toASCII name(aFont->GetName());
-  mTypeface = SkTypeface::CreateFromName(name.get(), gfxFontStyleToSkia(aFont->GetStyle()));
-}
-#endif
-
-ScaledFontBase::~ScaledFontBase()
-{
-#ifdef USE_SKIA
-  SkSafeUnref(mTypeface);
-#endif
-}
-
-ScaledFontBase::ScaledFontBase(Float aSize)
-  : mSize(aSize)
-{
-#ifdef USE_SKIA
-  mTypeface = NULL;
-#endif
-}
-
-
-TemporaryRef<Path>
-ScaledFontBase::GetPathForGlyphs(const GlyphBuffer &aBuffer, const DrawTarget *aTarget)
-{
-#ifdef USE_SKIA
-  if (aTarget->GetType() == BACKEND_SKIA) {
-    SkPaint paint;
-    paint.setTypeface(GetSkTypeface());
-    paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
-    paint.setTextSize(SkFloatToScalar(mSize));
-
-    std::vector<uint16_t> indices;
-    std::vector<SkPoint> offsets;
-    indices.resize(aBuffer.mNumGlyphs);
-    offsets.resize(aBuffer.mNumGlyphs);
-
-    for (unsigned int i = 0; i < aBuffer.mNumGlyphs; i++) {
-      indices[i] = aBuffer.mGlyphs[i].mIndex;
-      offsets[i].fX = SkFloatToScalar(aBuffer.mGlyphs[i].mPosition.x);
-      offsets[i].fY = SkFloatToScalar(aBuffer.mGlyphs[i].mPosition.y);
-    }
-
-    SkPath path;
-    paint.getPosTextPath(&indices.front(), aBuffer.mNumGlyphs*2, &offsets.front(), &path);
-    return new PathSkia(path, FILL_WINDING);
-  }
-#endif
-  return NULL;
-}
-
-}
-}
deleted file mode 100644
--- a/gfx/2d/ScaledFontBase.h
+++ /dev/null
@@ -1,75 +0,0 @@
-/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
- * ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is Mozilla Corporation code.
- *
- * The Initial Developer of the Original Code is Mozilla Foundation.
- * Portions created by the Initial Developer are Copyright (C) 2011
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *   Matt Woodrow <mwoodrow@mozilla.com>
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or
- * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-
-#ifndef MOZILLA_GFX_SCALEDFONTBASE_H_
-#define MOZILLA_GFX_SCALEDFONTBASE_H_
-
-#include "2D.h"
-#ifdef USE_SKIA
-#include "skia/SkTypeface.h"
-#endif
-
-class gfxFont;
-
-namespace mozilla {
-namespace gfx {
-
-class ScaledFontBase : public ScaledFont
-{
-public:
-  ScaledFontBase(Float aSize);
-  virtual ~ScaledFontBase();
-
-  virtual TemporaryRef<Path> GetPathForGlyphs(const GlyphBuffer &aBuffer, const DrawTarget *aTarget);
-#ifdef USE_SKIA
-  ScaledFontBase(gfxFont* aFont, Float aSize);
-  virtual SkTypeface* GetSkTypeface() { return mTypeface; }
-  virtual FontType GetType() const { return FONT_SKIA; }
-#endif
-
-protected:
-  friend class DrawTargetSkia;
-#ifdef USE_SKIA
-  SkTypeface* mTypeface;
-#endif
-  Float mSize;
-};
-
-}
-}
-
-#endif /* MOZILLA_GFX_SCALEDFONTBASE_H_ */
--- a/gfx/2d/ScaledFontMac.cpp
+++ b/gfx/2d/ScaledFontMac.cpp
@@ -31,82 +31,31 @@
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include "ScaledFontMac.h"
-#ifdef USE_SKIA
 #include "PathSkia.h"
 #include "skia/SkPaint.h"
 #include "skia/SkPath.h"
 #include "skia/SkTypeface_mac.h"
-#endif
-#include "DrawTargetCG.h"
 #include <vector>
 
-// prototype for private API
-extern "C" {
-CGPathRef CGFontGetGlyphPath(CGFontRef fontRef, CGAffineTransform *textTransform, int unknown, CGGlyph glyph);
-};
-
-
 namespace mozilla {
 namespace gfx {
 
 ScaledFontMac::ScaledFontMac(CGFontRef aFont, Float aSize)
-  : ScaledFontBase(aSize)
+  : ScaledFontSkia(aSize)
 {
-  // XXX: should we be taking a reference
-  mFont = CGFontRetain(aFont);
+  mFontFace = CTFontCreateWithGraphicsFont(aFont, aSize, NULL, NULL);
+  mTypeface = SkCreateTypefaceFromCTFont(mFontFace);
 }
 
 ScaledFontMac::~ScaledFontMac()
 {
-  CGFontRelease(mFont);
-}
-
-#ifdef USE_SKIA
-SkTypeface* ScaledFontMac::GetSkTypeface()
-{
-  if (!mTypeface) {
-    CTFontRef fontFace = CTFontCreateWithGraphicsFont(mFont, mSize, NULL, NULL);
-    mTypeface = SkCreateTypefaceFromCTFont(fontFace);
-    CFRelease(fontFace);
-  }
-  return mTypeface;
-}
-#endif
-
-// private API here are the public options on OS X
-// CTFontCreatePathForGlyph
-// ATSUGlyphGetCubicPaths
-// we've used this in cairo sucessfully for some time.
-// Note: cairo dlsyms it. We could do that but maybe it's
-// safe just to use?
-
-TemporaryRef<Path>
-ScaledFontMac::GetPathForGlyphs(const GlyphBuffer &aBuffer, const DrawTarget *aTarget)
-{
-  if (aTarget->GetType() == BACKEND_COREGRAPHICS) {
-      CGMutablePathRef path = CGPathCreateMutable();
-
-      for (unsigned int i = 0; i < aBuffer.mNumGlyphs; i++) {
-          // XXX: we could probably fold both of these transforms together to avoid extra work
-          CGAffineTransform flip = CGAffineTransformMakeScale(1, -1);
-          CGPathRef glyphPath = ::CGFontGetGlyphPath(mFont, &flip, 0, aBuffer.mGlyphs[i].mIndex);
-
-          CGAffineTransform matrix = CGAffineTransformMake(mSize, 0, 0, mSize,
-                                                           aBuffer.mGlyphs[i].mPosition.x,
-                                                           aBuffer.mGlyphs[i].mPosition.y);
-          CGPathAddPath(path, &matrix, glyphPath);
-          CGPathRelease(glyphPath);
-      }
-      return new PathCG(path, FILL_WINDING);
-  } else {
-      return ScaledFontBase::GetPathForGlyphs(aBuffer, aTarget);
-  }
+  CFRelease(mFontFace);
 }
 
 }
 }
--- a/gfx/2d/ScaledFontMac.h
+++ b/gfx/2d/ScaledFontMac.h
@@ -33,36 +33,33 @@
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #ifndef MOZILLA_GFX_SCALEDFONTMAC_H_
 #define MOZILLA_GFX_SCALEDFONTMAC_H_
 
+#include "ScaledFontSkia.h"
 #import <ApplicationServices/ApplicationServices.h>
-#include "2D.h"
 
-#include "ScaledFontBase.h"
 
 namespace mozilla {
 namespace gfx {
 
-class ScaledFontMac : public ScaledFontBase
+class ScaledFontMac : public ScaledFontSkia
 {
 public:
   ScaledFontMac(CGFontRef aFont, Float aSize);
   virtual ~ScaledFontMac();
 
   virtual FontType GetType() const { return FONT_MAC; }
-#ifdef USE_SKIA
-  virtual SkTypeface* GetSkTypeface();
-#endif
-  virtual TemporaryRef<Path> GetPathForGlyphs(const GlyphBuffer &aBuffer, const DrawTarget *aTarget);
+
 private:
-  friend class DrawTargetCG;
-  CGFontRef mFont;
+  friend class DrawTargetSkia;
+
+  CTFontRef mFontFace;
 };
 
 }
 }
 
 #endif /* MOZILLA_GFX_SCALEDFONTMAC_H_ */
new file mode 100644
--- /dev/null
+++ b/gfx/2d/ScaledFontSkia.cpp
@@ -0,0 +1,110 @@
+/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
+ * ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is Mozilla Corporation code.
+ *
+ * The Initial Developer of the Original Code is Mozilla Foundation.
+ * Portions created by the Initial Developer are Copyright (C) 2011
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *   Matt Woodrow <mwoodrow@mozilla.com>
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+#include "ScaledFontSkia.h"
+#include "PathSkia.h"
+#include "skia/SkPaint.h"
+#include "skia/SkPath.h"
+#include <vector>
+#include <cmath>
+using namespace std;
+#include "gfxFont.h"
+
+namespace mozilla {
+namespace gfx {
+
+static SkTypeface::Style gfxFontStyleToSkia(const gfxFontStyle* aStyle)
+{
+  if (aStyle->style == NS_FONT_STYLE_ITALIC) {
+    if (aStyle->weight == NS_FONT_WEIGHT_BOLD) {
+      return SkTypeface::kBoldItalic;
+    }
+    return SkTypeface::kItalic;
+  }
+  if (aStyle->weight == NS_FONT_WEIGHT_BOLD) {
+    return SkTypeface::kBold;
+  }
+  return SkTypeface::kNormal;
+}
+
+ScaledFontSkia::ScaledFontSkia(gfxFont* aFont, Float aSize)
+  : mSize(aSize)
+{
+  NS_LossyConvertUTF16toASCII name(aFont->GetName());
+  mTypeface = SkTypeface::CreateFromName(name.get(), gfxFontStyleToSkia(aFont->GetStyle()));
+}
+
+ScaledFontSkia::ScaledFontSkia(Float aSize)
+  : mSize(aSize)
+{
+}
+
+ScaledFontSkia::~ScaledFontSkia()
+{
+  SkSafeUnref(mTypeface);
+}
+
+TemporaryRef<Path>
+ScaledFontSkia::GetPathForGlyphs(const GlyphBuffer &aBuffer, const DrawTarget *aTarget)
+{
+  if (aTarget->GetType() != BACKEND_SKIA) {
+    return NULL;
+  }
+
+  SkPaint paint;
+  paint.setTypeface(mTypeface);
+  paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
+  paint.setTextSize(SkFloatToScalar(mSize));
+  
+  std::vector<uint16_t> indices;
+  std::vector<SkPoint> offsets;
+  indices.resize(aBuffer.mNumGlyphs);
+  offsets.resize(aBuffer.mNumGlyphs);
+
+  for (unsigned int i = 0; i < aBuffer.mNumGlyphs; i++) {
+    indices[i] = aBuffer.mGlyphs[i].mIndex;
+    offsets[i].fX = SkFloatToScalar(aBuffer.mGlyphs[i].mPosition.x);
+    offsets[i].fY = SkFloatToScalar(aBuffer.mGlyphs[i].mPosition.y);
+  }
+
+  SkPath path;
+  paint.getPosTextPath(&indices.front(), aBuffer.mNumGlyphs*2, &offsets.front(), &path);
+  return new PathSkia(path, FILL_WINDING);
+}
+
+}
+}
new file mode 100644
--- /dev/null
+++ b/gfx/2d/ScaledFontSkia.h
@@ -0,0 +1,70 @@
+/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
+ * ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is Mozilla Corporation code.
+ *
+ * The Initial Developer of the Original Code is Mozilla Foundation.
+ * Portions created by the Initial Developer are Copyright (C) 2011
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *   Matt Woodrow <mwoodrow@mozilla.com>
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+#ifndef MOZILLA_GFX_SCALEDFONTSKIA_H_
+#define MOZILLA_GFX_SCALEDFONTSKIA_H_
+
+#include "2D.h"
+#include "skia/SkTypeface.h"
+
+class gfxFont;
+
+namespace mozilla {
+namespace gfx {
+
+class ScaledFontSkia : public ScaledFont
+{
+public:
+  ScaledFontSkia(gfxFont* aFont, Float aSize);
+  ScaledFontSkia(Float aSize);
+  virtual ~ScaledFontSkia();
+
+  virtual FontType GetType() const { return FONT_SKIA; }
+
+  virtual TemporaryRef<Path> GetPathForGlyphs(const GlyphBuffer &aBuffer, const DrawTarget *aTarget);
+
+protected:
+  friend class DrawTargetSkia;
+
+  SkTypeface* mTypeface;
+  Float mSize;
+};
+
+}
+}
+
+#endif /* MOZILLA_GFX_SCALEDFONTSKIA_H_ */
--- a/gfx/2d/ScaledFontWin.cpp
+++ b/gfx/2d/ScaledFontWin.cpp
@@ -31,37 +31,23 @@
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include "ScaledFontWin.h"
-#include "ScaeldFontBase.h"
-
-#ifdef USE_SKIA
 #include "skia/SkTypeface_win.h"
-#endif
 
 namespace mozilla {
 namespace gfx {
 
 ScaledFontWin::ScaledFontWin(gfxGDIFont* aFont, Float aSize)
-  : ScaledFontBase(aSize)
+  : ScaledFontSkia(aSize)
 {
   LOGFONT lf;
   GetObject(aFont->GetHFONT(), sizeof(LOGFONT), &lf);
+  mTypeface = SkCreateTypefaceFromLOGFONT(lf);
 }
 
-#ifdef USE_SKIA
-SkTypeface* ScaledFontWin::GetSkTypeface()
-{
-  if (!mTypeface) {
-    mTypeface = SkCreateTypefaceFromLOGFONT(lf);
-  }
-  return mTypeface;
-}
-#endif
-
-
 }
 }
--- a/gfx/2d/ScaledFontWin.h
+++ b/gfx/2d/ScaledFontWin.h
@@ -33,33 +33,29 @@
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #ifndef MOZILLA_GFX_SCALEDFONTWIN_H_
 #define MOZILLA_GFX_SCALEDFONTWIN_H_
 
-#include "ScaledFontBase.h"
+#include "ScaledFontSkia.h"
 #include "gfxGDIFont.h"
 
 namespace mozilla {
 namespace gfx {
 
-class ScaledFontWin : public ScaledFontBase
+class ScaledFontWin : public ScaledFontSkia
 {
 public:
   ScaledFontWin(gfxGDIFont* aFont, Float aSize);
 
   virtual FontType GetType() const { return FONT_GDI; }
-#ifdef USE_SKIA
-  virtual SkTypeface* GetSkTypeface();
-#endif
+
 private:
-#ifdef USE_SKIA
   friend class DrawTargetSkia;
-#endif
 };
 
 }
 }
 
 #endif /* MOZILLA_GFX_SCALEDFONTWIN_H_ */
--- a/gfx/2d/SourceSurfaceCG.cpp
+++ b/gfx/2d/SourceSurfaceCG.cpp
@@ -35,47 +35,47 @@
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include "SourceSurfaceCG.h"
 
 namespace mozilla {
 namespace gfx {
 
+SourceSurfaceCG::SourceSurfaceCG()
+{
+}
 
 SourceSurfaceCG::~SourceSurfaceCG()
 {
   CGImageRelease(mImage);
 }
 
 IntSize
 SourceSurfaceCG::GetSize() const
 {
   IntSize size;
-  size.width = CGImageGetWidth(mImage);
-  size.height = CGImageGetHeight(mImage);
+  size.width = CGImageGetHeight(mImage);
+  size.height = CGImageGetWidth(mImage);
   return size;
 }
 
 SurfaceFormat
 SourceSurfaceCG::GetFormat() const
 {
   return mFormat;
 }
 
 TemporaryRef<DataSourceSurface>
 SourceSurfaceCG::GetDataSurface()
 {
-  //XXX: we should be more disciplined about who takes a reference and where
-  CGImageRetain(mImage);
-  RefPtr<DataSourceSurfaceCG> dataSurf =
-    new DataSourceSurfaceCG(mImage);
-  return dataSurf;
+  return NULL;
 }
 
+
 static void releaseCallback(void *info, const void *data, size_t size) {
   free(info);
 }
 
 bool
 SourceSurfaceCG::InitFromData(unsigned char *aData,
                                const IntSize &aSize,
                                int32_t aStride,
@@ -83,50 +83,48 @@ SourceSurfaceCG::InitFromData(unsigned c
 {
   //XXX: we should avoid creating this colorspace everytime
   CGColorSpaceRef colorSpace = NULL;
   CGBitmapInfo bitinfo = 0;
   CGDataProviderRef dataProvider = NULL;
   int bitsPerComponent = 0;
   int bitsPerPixel = 0;
 
-  assert(aSize.width >= 0 && aSize.height >= 0);
-
   switch (aFormat) {
-    case FORMAT_B8G8R8A8:
+    case B8G8R8A8:
       colorSpace = CGColorSpaceCreateDeviceRGB();
       bitinfo = kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host;
       bitsPerComponent = 8;
       bitsPerPixel = 32;
       break;
 
-    case FORMAT_B8G8R8X8:
+    case B8G8R8X8:
       colorSpace = CGColorSpaceCreateDeviceRGB();
       bitinfo = kCGImageAlphaNoneSkipFirst | kCGBitmapByteOrder32Host;
       bitsPerComponent = 8;
       bitsPerPixel = 32;
       break;
 
-    case FORMAT_A8:
+    case A8:
       // XXX: why don't we set a colorspace here?
       bitsPerComponent = 8;
       bitsPerPixel = 8;
   };
 
   void *data = malloc(aStride * aSize.height);
   memcpy(data, aData, aStride * aSize.height);
 
   mFormat = aFormat;
 
   dataProvider = CGDataProviderCreateWithData (data,
                                                data,
 					       aSize.height * aStride,
 					       releaseCallback);
 
-  if (aFormat == FORMAT_A8) {
+  if (aFormat == A8) {
     CGFloat decode[] = {1.0, 0.0};
     mImage = CGImageMaskCreate (aSize.width, aSize.height,
 				bitsPerComponent,
 				bitsPerPixel,
 				aStride,
 				dataProvider,
 				decode,
 				true);
@@ -142,178 +140,17 @@ SourceSurfaceCG::InitFromData(unsigned c
 			    NULL,
 			    true,
 			    kCGRenderingIntentDefault);
   }
 
   CGDataProviderRelease(dataProvider);
   CGColorSpaceRelease (colorSpace);
 
-  return mImage != NULL;
-}
-
-DataSourceSurfaceCG::~DataSourceSurfaceCG()
-{
-  CGImageRelease(mImage);
-  free(CGBitmapContextGetData(mCg));
-  CGContextRelease(mCg);
-}
-
-IntSize
-DataSourceSurfaceCG::GetSize() const
-{
-  IntSize size;
-  size.width = CGImageGetWidth(mImage);
-  size.height = CGImageGetHeight(mImage);
-  return size;
-}
-
-bool
-DataSourceSurfaceCG::InitFromData(unsigned char *aData,
-                               const IntSize &aSize,
-                               int32_t aStride,
-                               SurfaceFormat aFormat)
-{
-  //XXX: we should avoid creating this colorspace everytime
-  CGColorSpaceRef colorSpace = NULL;
-  CGBitmapInfo bitinfo = 0;
-  CGDataProviderRef dataProvider = NULL;
-  int bitsPerComponent = 0;
-  int bitsPerPixel = 0;
-
-  switch (aFormat) {
-    case FORMAT_B8G8R8A8:
-      colorSpace = CGColorSpaceCreateDeviceRGB();
-      bitinfo = kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host;
-      bitsPerComponent = 8;
-      bitsPerPixel = 32;
-      break;
-
-    case FORMAT_B8G8R8X8:
-      colorSpace = CGColorSpaceCreateDeviceRGB();
-      bitinfo = kCGImageAlphaNoneSkipFirst | kCGBitmapByteOrder32Host;
-      bitsPerComponent = 8;
-      bitsPerPixel = 32;
-      break;
-
-    case FORMAT_A8:
-      // XXX: why don't we set a colorspace here?
-      bitsPerComponent = 8;
-      bitsPerPixel = 8;
-  };
-
-  void *data = malloc(aStride * aSize.height);
-  memcpy(data, aData, aStride * aSize.height);
-
-  //mFormat = aFormat;
-
-  dataProvider = CGDataProviderCreateWithData (data,
-                                               data,
-					       aSize.height * aStride,
-					       releaseCallback);
-
-  if (aFormat == FORMAT_A8) {
-    CGFloat decode[] = {1.0, 0.0};
-    mImage = CGImageMaskCreate (aSize.width, aSize.height,
-				bitsPerComponent,
-				bitsPerPixel,
-				aStride,
-				dataProvider,
-				decode,
-				true);
-
-  } else {
-    mImage = CGImageCreate (aSize.width, aSize.height,
-			    bitsPerComponent,
-			    bitsPerPixel,
-			    aStride,
-			    colorSpace,
-			    bitinfo,
-			    dataProvider,
-			    NULL,
-			    true,
-			    kCGRenderingIntentDefault);
+  if (mImage) {
+    return false;
   }
 
-  CGDataProviderRelease(dataProvider);
-  CGColorSpaceRelease (colorSpace);
-
-  return mImage;
-}
-
-CGContextRef CreateBitmapContextForImage(CGImageRef image)
-{
-  CGColorSpaceRef colorSpace;
-
-  size_t width  = CGImageGetWidth(image);
-  size_t height = CGImageGetHeight(image);
-
-  int bitmapBytesPerRow = (width * 4);
-  int bitmapByteCount   = (bitmapBytesPerRow * height);
-
-  void *data = calloc(bitmapByteCount, 1);
-  //XXX: which color space should we be using here?
-  colorSpace = CGColorSpaceCreateDeviceRGB();
-  assert(colorSpace);
-
-  // we'd like to pass NULL as the first parameter
-  // to let Quartz manage this memory for us. However,
-  // on 10.5 and older CGBitmapContextGetData will return
-  // NULL instead of the associated buffer so we need
-  // to manage it ourselves.
-  CGContextRef cg = CGBitmapContextCreate(data,
-                                          width,
-                                          height,
-                                          8,
-                                          bitmapBytesPerRow,
-                                          colorSpace,
-                                          kCGBitmapByteOrder32Host | kCGImageAlphaPremultipliedFirst);
-  assert(cg);
-
-  CGColorSpaceRelease(colorSpace);
-
-  return cg;
+  return true;
 }
 
-DataSourceSurfaceCG::DataSourceSurfaceCG(CGImageRef aImage)
-{
-  mImage = aImage;
-  mCg = CreateBitmapContextForImage(aImage);
-  if (mCg == NULL) {
-    // error creating context
-    return;
-  }
-
-  // Get image width, height. We'll use the entire image.
-  CGFloat w = CGImageGetWidth(aImage);
-  CGFloat h = CGImageGetHeight(aImage);
-  CGRect rect = {{0,0},{w,h}};
-
-  // Draw the image to the bitmap context. Once we draw, the memory
-  // allocated for the context for rendering will then contain the
-  // raw image data in the specified color space.
-  CGContextDrawImage(mCg, rect, aImage);
-
-  // Now we can get a pointer to the image data associated with the bitmap
-  // context.
-  mData = CGBitmapContextGetData(mCg);
-  assert(mData);
-}
-
-unsigned char *
-DataSourceSurfaceCG::GetData()
-{
-  // See http://developer.apple.com/library/mac/#qa/qa1509/_index.html
-  // the following only works on 10.5+, the Q&A above suggests a method
-  // that can be used for earlier versions
-  //CFDataRef data = CGDataProviderCopyData(CGImageGetDataProvider(cgImage));
-  //unsigned char *dataPtr = CFDataGetBytePtr(data);
-  //CFDataRelease(data);
-  // unfortunately the the method above only works for read-only access and
-  // we need read-write for DataSourceSurfaces
-
-  return (unsigned char*)mData;
-}
-
-
-
 }
 }
--- a/gfx/2d/SourceSurfaceCG.h
+++ b/gfx/2d/SourceSurfaceCG.h
@@ -42,21 +42,20 @@
 #include "2D.h"
 
 namespace mozilla {
 namespace gfx {
 
 class SourceSurfaceCG : public SourceSurface
 {
 public:
-  SourceSurfaceCG() {}
-  SourceSurfaceCG(CGImageRef aImage) : mImage(aImage) {}
+  SourceSurfaceCG();
   ~SourceSurfaceCG();
 
-  virtual SurfaceType GetType() const { return SURFACE_COREGRAPHICS_IMAGE; }
+  virtual SurfaceType GetType() const { return COREGRAPHICS_IMAGE; }
   virtual IntSize GetSize() const;
   virtual SurfaceFormat GetFormat() const;
   virtual TemporaryRef<DataSourceSurface> GetDataSurface();
 
   CGImageRef GetImage() { return mImage; }
 
   bool InitFromData(unsigned char *aData,
                     const IntSize &aSize,
@@ -67,43 +66,10 @@ private:
   CGImageRef mImage;
 
   /* It might be better to just use the bitmap info from the CGImageRef to
    * deduce the format to save space in SourceSurfaceCG,
    * for now we just store it in mFormat */
   SurfaceFormat mFormat;
 };
 
-class DataSourceSurfaceCG : public DataSourceSurface
-{
-public:
-  DataSourceSurfaceCG() {}
-  DataSourceSurfaceCG(CGImageRef aImage);
-  ~DataSourceSurfaceCG();
-
-  virtual SurfaceType GetType() const { return SURFACE_DATA; }
-  virtual IntSize GetSize() const;
-  virtual SurfaceFormat GetFormat() const { return FORMAT_B8G8R8A8; }
-
-  CGImageRef GetImage() { return mImage; }
-
-  bool InitFromData(unsigned char *aData,
-                    const IntSize &aSize,
-                    int32_t aStride,
-                    SurfaceFormat aFormat);
-
-  virtual unsigned char *GetData();
-
-  virtual int32_t Stride() { return CGImageGetBytesPerRow(mImage); }
-
-
-private:
-  CGContextRef mCg;
-  CGImageRef mImage;
-  //XXX: we don't need to store mData we can just get it from the CGContext
-  void *mData;
-  /* It might be better to just use the bitmap info from the CGImageRef to
-   * deduce the format to save space in SourceSurfaceCG,
-   * for now we just store it in mFormat */
-};
-
 }
 }
--- a/gfx/2d/Types.h
+++ b/gfx/2d/Types.h
@@ -75,25 +75,23 @@ enum BackendType
 };
 
 enum FontType
 {
   FONT_DWRITE,
   FONT_GDI,
   FONT_MAC,
   FONT_SKIA,
-  FONT_CAIRO,
-  FONT_COREGRAPHICS
+  FONT_CAIRO
 };
 
 enum NativeSurfaceType
 {
   NATIVE_SURFACE_D3D10_TEXTURE,
-  NATIVE_SURFACE_CAIRO_SURFACE,
-  NATIVE_SURFACE_CGCONTEXT
+  NATIVE_SURFACE_CAIRO_SURFACE
 };
 
 enum NativeFontType
 {
   NATIVE_FONT_DWRITE_FONT_FACE,
   NATIVE_FONT_GDI_FONT_FACE,
   NATIVE_FONT_MAC_FONT_FACE,
   NATIVE_FONT_SKIA_FONT_FACE,
deleted file mode 100644
--- a/gfx/2d/UserData.h
+++ /dev/null
@@ -1,108 +0,0 @@
-/* -*- Mode: c++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
- * ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is Mozilla Corporation code.
- *
- * The Initial Developer of the Original Code is Mozilla Foundation.
- * Portions created by the Initial Developer are Copyright (Sub) 2011
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *   Jeff Muizelaar <jmuizelaar@mozilla.com>
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or
- * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-
-
-#include <stdlib.h>
-#include "mozilla/mozalloc.h"
-
-namespace mozilla {
-namespace gfx {
-
-struct UserDataKey {
-  int unused;
-};
-
-/* this class is basically a clone of the user data concept from cairo */
-class UserData
-{
-  typedef void (*destroyFunc)(void *data);
-public:
-  UserData() : count(0), entries(NULL) {}
-
-  /* Attaches untyped userData associated with key. destroy is called on destruction */
-  void Add(UserDataKey *key, void *userData, destroyFunc destroy)
-  {
-    // We could keep entries in a std::vector instead of managing it by hand
-    // but that would propagate an stl dependency out which we'd rather not
-    // do (see bug 666609). Plus, the entries array is expect to stay small
-    // so doing a realloc everytime we add a new entry shouldn't be too costly
-    entries = static_cast<Entry*>(moz_xrealloc(entries, sizeof(Entry)*(count+1)));
-
-    entries[count].key      = key;
-    entries[count].userData = userData;
-    entries[count].destroy  = destroy;
-
-    count++;
-  }
-
-  //XXX: we probably want to add a way to remove Keys
-
-  /* Retrives the userData for the associated key */
-  void *Get(UserDataKey *key)
-  {
-    for (int i=0; i<count; i++) {
-      if (key == entries[i].key) {
-        return entries[i].userData;
-      }
-    }
-    return NULL;
-  }
-
-  ~UserData()
-  {
-    for (int i=0; i<count; i++) {
-      entries[i].destroy(entries[i].userData);
-    }
-    free(entries);
-  }
-
-private:
-  struct Entry {
-    const UserDataKey *key;
-    void *userData;
-    destroyFunc destroy;
-  };
-
-  int count;
-  Entry *entries;
-
-};
-
-}
-}
-
-
--- a/gfx/thebes/gfxFont.h
+++ b/gfx/thebes/gfxFont.h
@@ -678,17 +678,17 @@ struct gfxTextRange {
  * by the fonts if they get aged three times without being re-used in the
  * meantime.
  *
  * Note that the ShapedWord timeout is much larger than the font timeout,
  * so that in the case of a short-lived font, we'll discard the gfxFont
  * completely, with all its words, and avoid the cost of aging the words
  * individually. That only happens with longer-lived fonts.
  */
-class THEBES_API gfxFontCache MOZ_FINAL : public nsExpirationTracker<gfxFont,3> {
+class THEBES_API gfxFontCache : public nsExpirationTracker<gfxFont,3> {
 public:
     enum {
         FONT_TIMEOUT_SECONDS = 10,
         SHAPED_WORD_TIMEOUT_SECONDS = 60
     };
 
     gfxFontCache();
     ~gfxFontCache();
--- a/gfx/thebes/gfxPlatform.cpp
+++ b/gfx/thebes/gfxPlatform.cpp
@@ -527,58 +527,35 @@ gfxPlatform::GetScaledFontForFont(gfxFon
 
 cairo_user_data_key_t kDrawSourceSurface;
 static void
 DataSourceSurfaceDestroy(void *dataSourceSurface)
 {
       static_cast<DataSourceSurface*>(dataSourceSurface)->Release();
 }
 
-void DestroyThebesSurface(void *data)
-{
-  gfxASurface *surface = static_cast<gfxASurface*>(data);
-  surface->Release();
-}
-
-UserDataKey ThebesSurfaceKey;
-
-// The semantics of this function are sort of weird. We snapshot the first
-// time and then return the snapshotted surface for the lifetime of the
-// draw target
 already_AddRefed<gfxASurface>
 gfxPlatform::GetThebesSurfaceForDrawTarget(DrawTarget *aTarget)
 {
-  void *surface = aTarget->GetUserData(&ThebesSurfaceKey);
-  if (surface) {
-    nsRefPtr<gfxASurface> surf = static_cast<gfxASurface*>(surface);
-    return surf.forget();
-  }
-
   RefPtr<SourceSurface> source = aTarget->Snapshot();
   RefPtr<DataSourceSurface> data = source->GetDataSurface();
 
   if (!data) {
     return NULL;
   }
 
   IntSize size = data->GetSize();
   gfxASurface::gfxImageFormat format = gfxASurface::FormatFromContent(ContentForFormat(data->GetFormat()));
   
-  nsRefPtr<gfxImageSurface> surf =
+  nsRefPtr<gfxImageSurface> image =
     new gfxImageSurface(data->GetData(), gfxIntSize(size.width, size.height),
                         data->Stride(), format);
 
-  surf->SetData(&kDrawSourceSurface, data.forget().drop(), DataSourceSurfaceDestroy);
-
-  // add a reference to be held by the drawTarget
-  // careful, the reference graph is getting complicated here
-  surf->AddRef();
-  aTarget->AddUserData(&ThebesSurfaceKey, surf.get(), DestroyThebesSurface);
-
-  return surf.forget();
+  image->SetData(&kDrawSourceSurface, data.forget().drop(), DataSourceSurfaceDestroy);
+  return image.forget();
 }
 
 RefPtr<DrawTarget>
 gfxPlatform::CreateOffscreenDrawTarget(const IntSize& aSize, SurfaceFormat aFormat)
 {
   BackendType backend;
   if (!SupportsAzure(backend)) {
     return NULL;
--- a/gfx/thebes/gfxPlatform.h
+++ b/gfx/thebes/gfxPlatform.h
@@ -66,19 +66,16 @@ struct gfxFontStyle;
 class gfxUserFontSet;
 class gfxFontEntry;
 class gfxProxyFontEntry;
 class gfxPlatformFontList;
 class gfxTextRun;
 class nsIURI;
 class nsIAtom;
 
-extern mozilla::gfx::UserDataKey ThebesSurfaceKey;
-void DestroyThebesSurface(void *data);
-
 extern cairo_user_data_key_t kDrawTarget;
 
 // pref lang id's for font prefs
 // !!! needs to match the list of pref font.default.xx entries listed in all.js !!!
 // !!! don't use as bit mask, this may grow larger !!!
 
 enum eFontPrefLang {
     eFontPrefLang_Western     =  0,
--- a/gfx/thebes/gfxPlatformMac.cpp
+++ b/gfx/thebes/gfxPlatformMac.cpp
@@ -52,17 +52,16 @@
 #include "nsTArray.h"
 #include "nsUnicodeRange.h"
 
 #include "mozilla/Preferences.h"
 
 #include "qcms.h"
 
 #include <dlfcn.h>
-#include "mozilla/gfx/2D.h"
 
 using namespace mozilla;
 using namespace mozilla::gfx;
 
 // cribbed from CTFontManager.h
 enum {
    kAutoActivationDisabled = 1
 };
@@ -127,17 +126,17 @@ gfxPlatformMac::CreateOffscreenSurface(c
 {
     gfxASurface *newSurface = nsnull;
 
     newSurface = new gfxQuartzSurface(size, gfxASurface::FormatFromContent(contentType));
 
     NS_IF_ADDREF(newSurface);
     return newSurface;
 }
-
+    
 already_AddRefed<gfxASurface>
 gfxPlatformMac::OptimizeImage(gfxImageSurface *aSurface,
                               gfxASurface::gfxImageFormat format)
 {
     const gfxIntSize& surfaceSize = aSurface->GetSize();
     nsRefPtr<gfxImageSurface> isurf = aSurface;
 
     if (format != aSurface->Format()) {
@@ -158,17 +157,17 @@ gfxPlatformMac::GetScaledFontForFont(gfx
 {
     gfxMacFont *font = static_cast<gfxMacFont*>(aFont);
     return font->GetScaledFont();
 }
 
 bool
 gfxPlatformMac::SupportsAzure(BackendType& aBackend)
 {
-  aBackend = BACKEND_COREGRAPHICS;
+  aBackend = BACKEND_SKIA;
   return true;
 }
 
 nsresult
 gfxPlatformMac::ResolveFontName(const nsAString& aFontName,
                                 FontResolverCallback aCallback,
                                 void *aClosure, bool& aAborted)
 {
@@ -294,46 +293,16 @@ gfxPlatformMac::ReadAntiAliasingThreshol
             threshold = 0;
         }
         CFRelease(prefValue);
     }
 
     return threshold;
 }
 
-already_AddRefed<gfxASurface>
-gfxPlatformMac::GetThebesSurfaceForDrawTarget(DrawTarget *aTarget)
-{
-  if (aTarget->GetType() == BACKEND_COREGRAPHICS) {
-    void *surface = aTarget->GetUserData(&ThebesSurfaceKey);
-    if (surface) {
-      nsRefPtr<gfxASurface> surf = static_cast<gfxQuartzSurface*>(surface);
-      return surf.forget();
-    } else {
-      CGContextRef cg = static_cast<CGContextRef>(aTarget->GetNativeSurface(NATIVE_SURFACE_CGCONTEXT));
-
-      //XXX: it would be nice to have an implicit conversion from IntSize to gfxIntSize
-      IntSize intSize = aTarget->GetSize();
-      gfxIntSize size(intSize.width, intSize.height);
-
-      nsRefPtr<gfxASurface> surf =
-        new gfxQuartzSurface(cg, size);
-
-      // add a reference to be held by the drawTarget
-      surf->AddRef();
-      aTarget->AddUserData(&ThebesSurfaceKey, surf.get(), DestroyThebesSurface);
-
-      return surf.forget();
-    }
-  }
-
-  return gfxPlatform::GetThebesSurfaceForDrawTarget(aTarget);
-}
-
-
 qcms_profile *
 gfxPlatformMac::GetPlatformCMSOutputProfile()
 {
     qcms_profile *profile = nsnull;
     CMProfileRef cmProfile;
     CMProfileLocation *location;
     UInt32 locationSize;
 
--- a/gfx/thebes/gfxPlatformMac.h
+++ b/gfx/thebes/gfxPlatformMac.h
@@ -45,17 +45,16 @@
 #define MAC_OS_X_VERSION_10_4_HEX 0x00001040
 #define MAC_OS_X_VERSION_10_5_HEX 0x00001050
 #define MAC_OS_X_VERSION_10_6_HEX 0x00001060
 #define MAC_OS_X_VERSION_10_7_HEX 0x00001070
 
 #define MAC_OS_X_MAJOR_VERSION_MASK 0xFFFFFFF0U
 
 class gfxTextRun;
-class mozilla::gfx::DrawTarget;
 
 class THEBES_API gfxPlatformMac : public gfxPlatform {
 public:
     gfxPlatformMac();
     virtual ~gfxPlatformMac();
 
     static gfxPlatformMac *GetPlatform() {
         return (gfxPlatformMac*) gfxPlatform::GetPlatform();
@@ -100,18 +99,16 @@ public:
 
     // Returns the OS X version as returned from Gestalt(gestaltSystemVersion, ...)
     // Ex: Mac OS X 10.4.x ==> 0x104x 
     PRInt32 OSXVersion();
 
     // lower threshold on font anti-aliasing
     PRUint32 GetAntiAliasingThreshold() { return mFontAntiAliasingThreshold; }
 
-    virtual already_AddRefed<gfxASurface>
-    GetThebesSurfaceForDrawTarget(mozilla::gfx::DrawTarget *aTarget);
 private:
     virtual qcms_profile* GetPlatformCMSOutputProfile();
     
     // read in the pref value for the lower threshold on font anti-aliasing
     static PRUint32 ReadAntiAliasingThreshold();    
     
     PRInt32 mOSXVersion;
     PRUint32 mFontAntiAliasingThreshold;
--- a/gfx/thebes/gfxQuartzSurface.cpp
+++ b/gfx/thebes/gfxQuartzSurface.cpp
@@ -76,36 +76,16 @@ gfxQuartzSurface::gfxQuartzSurface(CGCon
     gfxIntSize size((unsigned int) floor(desiredSize.width),
                     (unsigned int) floor(desiredSize.height));
     if (!CheckSurfaceSize(size))
         MakeInvalid();
 
     unsigned int width = static_cast<unsigned int>(mSize.width);
     unsigned int height = static_cast<unsigned int>(mSize.height);
 
-    cairo_surface_t *surf =
-        cairo_quartz_surface_create_for_cg_context(context,
-                                                   width, height);
-
-    CGContextRetain(mCGContext);
-
-    Init(surf);
-}
-
-gfxQuartzSurface::gfxQuartzSurface(CGContextRef context,
-                                   const gfxIntSize& size,
-                                   bool aForPrinting)
-    : mCGContext(context), mSize(size), mForPrinting(aForPrinting)
-{
-    if (!CheckSurfaceSize(size))
-        MakeInvalid();
-
-    unsigned int width = static_cast<unsigned int>(mSize.width);
-    unsigned int height = static_cast<unsigned int>(mSize.height);
-
     cairo_surface_t *surf = 
         cairo_quartz_surface_create_for_cg_context(context,
                                                    width, height);
 
     CGContextRetain(mCGContext);
 
     Init(surf);
 }
--- a/gfx/thebes/gfxQuartzSurface.h
+++ b/gfx/thebes/gfxQuartzSurface.h
@@ -45,17 +45,16 @@
 #include <Carbon/Carbon.h>
 
 class gfxContext;
 
 class THEBES_API gfxQuartzSurface : public gfxASurface {
 public:
     gfxQuartzSurface(const gfxSize& size, gfxImageFormat format, bool aForPrinting = false);
     gfxQuartzSurface(CGContextRef context, const gfxSize& size, bool aForPrinting = false);
-    gfxQuartzSurface(CGContextRef context, const gfxIntSize& size, bool aForPrinting = false);
     gfxQuartzSurface(cairo_surface_t *csurf, bool aForPrinting = false);
     gfxQuartzSurface(unsigned char *data, const gfxSize& size, long stride, gfxImageFormat format, bool aForPrinting = false);
 
     virtual ~gfxQuartzSurface();
 
     virtual already_AddRefed<gfxASurface> CreateSimilarSurface(gfxContentType aType,
                                                                const gfxIntSize& aSize);
 
--- a/gfx/thebes/gfxWindowsPlatform.cpp
+++ b/gfx/thebes/gfxWindowsPlatform.cpp
@@ -502,45 +502,31 @@ gfxWindowsPlatform::GetScaledFontForFont
   return scaledFont;
 }
 
 already_AddRefed<gfxASurface>
 gfxWindowsPlatform::GetThebesSurfaceForDrawTarget(DrawTarget *aTarget)
 {
 #ifdef XP_WIN
   if (aTarget->GetType() == BACKEND_DIRECT2D) {
-    void *surface = aTarget->GetUserData(&ThebesSurfaceKey);
-    if (surface) {
-      nsRefPtr<gfxASurface> surf = static_cast<gfxASurface*>(surface);
-      return surf.forget();
-    } else {
-      RefPtr<ID3D10Texture2D> texture =
-        static_cast<ID3D10Texture2D*>(aTarget->GetNativeSurface(NATIVE_SURFACE_D3D10_TEXTURE));
+    RefPtr<ID3D10Texture2D> texture =
+      static_cast<ID3D10Texture2D*>(aTarget->GetNativeSurface(NATIVE_SURFACE_D3D10_TEXTURE));
 
-      if (!texture) {
-        return gfxPlatform::GetThebesSurfaceForDrawTarget(aTarget);
-      }
-
-      aTarget->Flush();
+    if (!texture) {
+      return gfxPlatform::GetThebesSurfaceForDrawTarget(aTarget);
+    }
 
-      nsRefPtr<gfxASurface> surf =
-        new gfxD2DSurface(texture, ContentForFormat(aTarget->GetFormat()));
+    aTarget->Flush();
 
-      // add a reference to be held by the drawTarget
-      surf->AddRef();
-      aTarget->AddUserData(&ThebesSurfaceKey, surf.get(), DestroyThebesSurface);
-      /* "It might be worth it to clear cairo surfaces associated with a drawtarget.
-	  The strong reference means for example for D2D that cairo's scratch surface
-	  will be kept alive (well after a user being done) and consume extra VRAM.
-	  We can deal with this in a follow-up though." */
+    nsRefPtr<gfxASurface> surf =
+      new gfxD2DSurface(texture, ContentForFormat(aTarget->GetFormat()));
 
-      // shouldn't this hold a reference?
-      surf->SetData(&kDrawTarget, aTarget, NULL);
-      return surf.forget();
-    }
+    surf->SetData(&kDrawTarget, aTarget, NULL);
+
+    return surf.forget();
   }
 #endif
 
   return gfxPlatform::GetThebesSurfaceForDrawTarget(aTarget);
 }
 
 bool
 gfxWindowsPlatform::SupportsAzure(BackendType& aBackend)
--- a/layout/reftests/canvas/reftest.list
+++ b/layout/reftests/canvas/reftest.list
@@ -42,23 +42,19 @@ asserts-if(cocoaWidget,0-2) == size-chan
 == text-bidi-rtl-test.html text-bidi-rtl-ref.html
 
 fails-if(Android) != text-font-lang.html text-font-lang-notref.html
 
 == text-measure.html text-measure-ref.html
 
 == strokeText-path.html strokeText-path-ref.html
 
-# azure quartz uses CGDrawLinearGradient instead of DrawShading
-# so we have less control over degenerate behaviour as tested by this
-# test
-fails-if(azureQuartz) == linear-gradient-1a.html linear-gradient-1-ref.html
-
-# this passes with cairo on 10.7 but not with azure for reasons unknown
-fails-if(/Mac\x20OS\x20X\x2010\.[56]/.test(http.oscpu)||(azureQuartz&&/Mac\x20OS\x20X\x2010\.7/.test(http.oscpu)) == linear-gradient-1b.html linear-gradient-1-ref.html
+# gradient off-by-one, fails on windows and linux
+== linear-gradient-1a.html linear-gradient-1-ref.html
+fails-if(/Mac\x20OS\x20X\x2010\.[56]/.test(http.oscpu)) == linear-gradient-1b.html linear-gradient-1-ref.html
 
 == zero-dimensions.html zero-dimensions-ref.html
 
 == evenodd-fill-sanity.html data:text/html,<body>Pass
 != evenodd-fill-1.html nonzero-fill-1.html
 == evenodd-fill-1.html evenodd-fill-ref.html
 == evenodd-fill-2.html evenodd-fill-ref.html
 == evenodd-fill-3.html nonzero-fill-2.html
--- a/layout/reftests/css-gradients/reftest.list
+++ b/layout/reftests/css-gradients/reftest.list
@@ -1,14 +1,14 @@
-fuzzy-if(azureQuartz) fails-if(Android) == linear-1a.html linear-1-ref.html
-fuzzy-if(azureQuartz) fails-if(Android) == linear-1b.html linear-1-ref.html
-fuzzy-if(azureQuartz) fails-if(Android) == linear-keywords-1a.html linear-keywords-1-ref.html
-fuzzy-if(azureQuartz) fails-if(Android) == linear-keywords-1b.html linear-keywords-1-ref.html
-fuzzy-if(azureQuartz) fails-if(Android) == linear-percent.html linear-percent-ref.html
-fuzzy-if(azureQuartz) fails-if(Android) == linear-mix.html linear-mix-ref.html
+fails-if(Android) == linear-1a.html linear-1-ref.html
+fails-if(Android) == linear-1b.html linear-1-ref.html
+fails-if(Android) == linear-keywords-1a.html linear-keywords-1-ref.html
+fails-if(Android) == linear-keywords-1b.html linear-keywords-1-ref.html
+fails-if(Android) == linear-percent.html linear-percent-ref.html
+fails-if(Android) == linear-mix.html linear-mix-ref.html
 == linear-diagonal-1a.html linear-diagonal-1-ref.html
 == linear-diagonal-1b.html linear-diagonal-1-ref.html
 == linear-diagonal-1c.html linear-diagonal-1-ref.html
 == linear-diagonal-2a.html linear-diagonal-2-ref.html
 == linear-diagonal-2b.html linear-diagonal-2-ref.html
 == linear-diagonal-2c.html linear-diagonal-2-ref.html
 == linear-diagonal-3a.html linear-diagonal-3-ref.html
 == linear-diagonal-3b.html linear-diagonal-3-ref.html
@@ -31,30 +31,30 @@ fails-if(d2d) == linear-repeat-1f.html l
 fails-if(d2d) == linear-repeat-1g.html linear-repeat-1-ref.html # bug 582236
 == linear-size-1a.html linear-size-1-ref.html
 == linear-stops-1a.html linear-stops-1-ref.html
 == linear-stops-1b.html linear-stops-1-ref.html
 == linear-stops-1c.html linear-stops-1-ref.html
 == linear-stops-1d.html linear-stops-1-ref.html
 == linear-stops-1e.html linear-stops-1-ref.html
 == linear-stops-1f.html linear-stops-1-ref.html
-fuzzy-if(azureQuartz) fails-if(Android) == linear-vertical-1a.html linear-vertical-1-ref.html
-fuzzy-if(azureQuartz) fails-if(Android) == linear-vertical-1b.html linear-vertical-1-ref.html
-fuzzy-if(azureQuartz) fails-if(Android) == linear-vertical-1c.html linear-vertical-1-ref.html
-fuzzy-if(azureQuartz) fails-if(Android) == linear-vertical-1d.html linear-vertical-1-ref.html
-fuzzy-if(azureQuartz) fails-if(Android) == linear-vertical-1e.html linear-vertical-1-ref.html
+fails-if(Android) == linear-vertical-1a.html linear-vertical-1-ref.html
+fails-if(Android) == linear-vertical-1b.html linear-vertical-1-ref.html
+fails-if(Android) == linear-vertical-1c.html linear-vertical-1-ref.html
+fails-if(Android) == linear-vertical-1d.html linear-vertical-1-ref.html
+fails-if(Android) == linear-vertical-1e.html linear-vertical-1-ref.html
 == linear-viewport.html linear-viewport-ref.html
 == linear-zero-length-1a.html linear-zero-length-1-ref.html
 == linear-zero-length-1b.html linear-zero-length-1-ref.html
 == linear-zero-length-1c.html linear-zero-length-1-ref.html
 == nostops.html about:blank
 == onestop.html about:blank
-fuzzy-if(azureQuartz) fails-if(Android) random-if(d2d) == radial-1a.html radial-1-ref.html
-fuzzy-if(azureQuartz) fails-if(Android) == radial-2a.html radial-2-ref.html
-fuzzy-if(azureQuartz) fails-if(Android) == radial-2b.html radial-2-ref.html
+fails-if(Android) random-if(d2d) == radial-1a.html radial-1-ref.html
+fails-if(Android) == radial-2a.html radial-2-ref.html
+fails-if(Android) == radial-2b.html radial-2-ref.html
 == radial-position-1a.html radial-position-1-ref.html
 == radial-shape-closest-corner-1a.html radial-shape-closest-corner-1-ref.html
 == radial-shape-closest-side-1a.html radial-shape-closest-side-1-ref.html
 == radial-shape-farthest-corner-1a.html radial-shape-farthest-corner-1-ref.html
 == radial-shape-farthest-side-1a.html radial-shape-farthest-side-1-ref.html
 == radial-size-1a.html radial-size-1-ref.html
 == radial-zero-length-1a.html radial-zero-length-1-ref.html
 == radial-zero-length-1b.html radial-zero-length-1-ref.html
@@ -72,33 +72,33 @@ fails-if(d2d) == repeating-linear-1b.htm
 == twostops-1b.html twostops-1-ref.html
 fails-if(/Mac\x20OS\x20X\x2010\.[56]/.test(http.oscpu)) == twostops-1c.html twostops-1-ref.html # bug 524173
 == twostops-1d.html twostops-1-ref.html
 == twostops-1e.html twostops-1-ref.html
 == twostops-1f.html twostops-1-ref.html
 == twostops-1g.html twostops-1-ref.html
 
 # from http://www.xanthir.com/:4bhipd by way of http://a-ja.net/newgrad.html
-fuzzy-if(azureQuartz) fails-if(Android) == aja-linear-1a.html aja-linear-1-ref.html
+fails-if(Android) == aja-linear-1a.html aja-linear-1-ref.html
 fails-if(!d2d) == aja-linear-1b.html aja-linear-1-ref.html # bug 526694
-fuzzy-if(azureQuartz) fails-if(Android) == aja-linear-1c.html aja-linear-1-ref.html
-fuzzy-if(azureQuartz) fails-if(Android) == aja-linear-1d.html aja-linear-1-ref.html
-fuzzy-if(azureQuartz) fails-if(Android) == aja-linear-1e.html aja-linear-1-ref.html
-fuzzy-if(azureQuartz) fails-if(Android) == aja-linear-1f.html aja-linear-1-ref.html
-fuzzy-if(azureQuartz) fails-if(Android) == aja-linear-1g.html aja-linear-1-ref.html
-fuzzy-if(azureQuartz) fails-if(Android) == aja-linear-2a.html aja-linear-2-ref.html
-fuzzy-if(azureQuartz) fails-if(Android) == aja-linear-2b.html aja-linear-2-ref.html
+fails-if(Android) == aja-linear-1c.html aja-linear-1-ref.html
+fails-if(Android) == aja-linear-1d.html aja-linear-1-ref.html
+fails-if(Android) == aja-linear-1e.html aja-linear-1-ref.html
+fails-if(Android) == aja-linear-1f.html aja-linear-1-ref.html
+fails-if(Android) == aja-linear-1g.html aja-linear-1-ref.html
+fails-if(Android) == aja-linear-2a.html aja-linear-2-ref.html
+fails-if(Android) == aja-linear-2b.html aja-linear-2-ref.html
 fails == aja-linear-2c.html aja-linear-2-ref.html # bug 522607
 fails-if(!d2d) == aja-linear-2d.html aja-linear-2-ref.html # bug 526694
-fuzzy-if(azureQuartz) fails-if(Android) == aja-linear-3a.html aja-linear-3-ref.html
-fuzzy-if(azureQuartz) fails-if(Android) == aja-linear-3b.html aja-linear-3-ref.html
-fuzzy-if(azureQuartz) fails-if(Android) == aja-linear-4a.html aja-linear-4-ref.html
-fuzzy-if(azureQuartz) fails-if(Android) == aja-linear-4b.html aja-linear-4-ref.html
-fuzzy-if(azureQuartz) fails-if(Android) == aja-linear-5a.html aja-linear-5-ref.html
-fuzzy-if(azureQuartz) fails-if(Android) fails-if(/Mac\x20OS\x20X\x2010\.5/.test(http.oscpu)) == aja-linear-6a.html aja-linear-6-ref.html # bug 526708
+fails-if(Android) == aja-linear-3a.html aja-linear-3-ref.html
+fails-if(Android) == aja-linear-3b.html aja-linear-3-ref.html
+fails-if(Android) == aja-linear-4a.html aja-linear-4-ref.html
+fails-if(Android) == aja-linear-4b.html aja-linear-4-ref.html
+fails-if(Android) == aja-linear-5a.html aja-linear-5-ref.html
+fails-if(Android) fails-if(/Mac\x20OS\x20X\x2010\.5/.test(http.oscpu)) == aja-linear-6a.html aja-linear-6-ref.html # bug 526708
 fails == aja-linear-6b.html aja-linear-6-ref.html # bug 522607
 == height-dependence-1.html height-dependence-1-ref.html
 fails-if(cocoaWidget) == height-dependence-2.html height-dependence-2-ref.html # bug 535007
 == height-dependence-3.html height-dependence-3-ref.html
 
 fails-if(d2d) == linear-onestopposition-1.html linear-onestopposition-1-ref.html # bug 638664
 == linear-onestopposition-1.html linear-onestopposition-1-ref2.html
 fails-if(d2d) fails-if(cocoaWidget) == radial-onestopposition-1.html radial-onestopposition-1-ref.html # bug 638664
deleted file mode 100644
--- a/layout/reftests/reftest-sanity/fuzzy-ref.html
+++ /dev/null
@@ -1,6 +0,0 @@
-<!DOCTYPE html>
-<html>
-  <body>
-    <div style="background: #ff00ff; width: 500px; height: 500px;"></div>
-  </body>
-</html>
deleted file mode 100644
--- a/layout/reftests/reftest-sanity/fuzzy.html
+++ /dev/null
@@ -1,6 +0,0 @@
-<!DOCTYPE html>
-<html>
-  <body>
-    <div style="background: #ff01ff; width: 500px; height: 500px;"></div>
-  </body>
-</html>
--- a/layout/reftests/reftest-sanity/reftest.list
+++ b/layout/reftests/reftest-sanity/reftest.list
@@ -124,15 +124,8 @@ fails pref(font.size.variable.x-western,
 fails pref(font.size.variable.x-western,"foo") == font-size-16.html font-default.html
 # a string pref
 pref(font.default.x-western,"serif") == font-serif.html font-default.html
 pref(font.default.x-western,"serif") != font-sans-serif.html font-default.html
 pref(font.default.x-western,"sans-serif") == font-sans-serif.html font-default.html
 pref(font.default.x-western,"sans-serif") != font-serif.html font-default.html
 fails pref(font.default.x-western,true) == font-serif.html font-default.html
 fails pref(font.default.x-western,0) == font-serif.html font-default.html
-# reftest syntax: fuzzy
-fuzzy == fuzzy.html fuzzy-ref.html
-fuzzy != too-fuzzy.html fuzzy-ref.html
-fuzzy-if(true) == fuzzy.html fuzzy-ref.html
-fuzzy-if(false) == fuzzy-ref.html fuzzy-ref.html
-# When using 565 fuzzy.html and fuzzy-ref.html will compare as equal
-fails fuzzy-if(false) random-if(Android) == fuzzy.html fuzzy-ref.html
deleted file mode 100644
--- a/layout/reftests/reftest-sanity/too-fuzzy.html
+++ /dev/null
@@ -1,6 +0,0 @@
-<!DOCTYPE html>
-<html>
-  <body>
-    <div style="background: #ff04ff; width: 500px; height: 500px;"></div>
-  </body>
-</html>
--- a/layout/reftests/svg/as-image/reftest.list
+++ b/layout/reftests/svg/as-image/reftest.list
@@ -34,17 +34,17 @@ include zoom/reftest.list
 == canvas-drawImage-scale-1a.html lime100x100-ref.html
 == canvas-drawImage-scale-1b.html lime100x100-ref.html
 == canvas-drawImage-scale-1c.html lime100x100-ref.html
 
 fails == canvas-drawImage-scale-2a.html canvas-drawImage-scale-2-ref.html # XXX all edges fuzzy
 fails == canvas-drawImage-scale-2b.html canvas-drawImage-scale-2-ref.html # XXX all edges fuzzy
 
 == canvas-drawImage-slice-1a.html lime100x100-ref.html
-fails-if(!azureQuartz) == canvas-drawImage-slice-1b.html lime100x100-ref.html # XXX all edges fuzzy
+fails == canvas-drawImage-slice-1b.html lime100x100-ref.html # XXX all edges fuzzy
 
 == canvas-drawImage-origin-clean-1.html lime100x100-ref.html
 
 # Simple <img> tests
 == img-simple-1.html  lime100x100-ref.html
 == img-simple-2.html  lime100x100-ref.html
 == img-simple-3.html  img-simple-3-ref.html
 == img-simple-4.html  lime100x100-ref.html
--- a/layout/tools/reftest/README.txt
+++ b/layout/tools/reftest/README.txt
@@ -101,24 +101,16 @@ 2. A test item
 
       slow-if(condition) If the condition is met, the test is treated as if
                          'slow' had been specified.  This is useful for tests
                          which are slow only on particular platforms (e.g. a
                          test which exercised out-of-memory behavior might be
                          fast on a 32-bit system but inordinately slow on a
                          64-bit system).
 
-      fuzzy  This allows a test to pass if the pixel value differences
-             are <= 2. It can also be used with '!=' to ensure that the
-             difference is greater than 2.
-
-      fuzzy-if(condition) If the condition is met, the test is treated as if
-                          'fuzzy' had been specified. This is useful if there
-                          are differences on particular platforms.
-
       require-or(cond1&&cond2&&...,fallback)
           Require some particular setup be performed or environmental
           condition(s) made true (eg setting debug mode) before the test
           is run. If any condition is unknown, unimplemented, or fails,
           revert to the fallback failure-type.
           Example: require-or(debugMode,skip)
 
       asserts(count)
--- a/layout/tools/reftest/print-manifest-dirs.py
+++ b/layout/tools/reftest/print-manifest-dirs.py
@@ -34,17 +34,17 @@
 # the provisions above, a recipient may use your version of this file under
 # the terms of any one of the MPL, the GPL or the LGPL.
 #
 # ***** END LICENSE BLOCK *****
 
 import sys, os.path, re
 
 commentRE = re.compile(r"\s+#")
-conditionsRE = re.compile(r"^(fails|needs-focus|random|skip|asserts|fuzzy)")
+conditionsRE = re.compile(r"^(fails|needs-focus|random|skip|asserts)")
 httpRE = re.compile(r"HTTP\((\.\.(\/\.\.)*)\)")
 protocolRE = re.compile(r"^\w+:")
 
 def parseManifest(manifest, dirs):
   """Parse the reftest manifest |manifest|, adding all directories containing
   tests (and the dirs containing the manifests themselves) to the set |dirs|."""
   manifestdir = os.path.dirname(os.path.abspath(manifest))
   dirs.add(manifestdir)
--- a/layout/tools/reftest/reftest.js
+++ b/layout/tools/reftest/reftest.js
@@ -144,17 +144,16 @@ const TYPE_SCRIPT = 'script'; // test co
 // the test by using the *larger*.  
 // FIXME: In the future, we may also want to use this rule for combining
 // statuses that are on the same line (rather than making the last one
 // win).
 const EXPECTED_PASS = 0;
 const EXPECTED_FAIL = 1;
 const EXPECTED_RANDOM = 2;
 const EXPECTED_DEATH = 3;  // test must be skipped to avoid e.g. crash/hang
-const EXPECTED_FUZZY = 4;
 
 // types of preference value we might want to set for a specific test
 const PREF_BOOLEAN = 0;
 const PREF_STRING  = 1;
 const PREF_INTEGER = 2;
 
 var gPrefsToRestore = [];
 
@@ -341,19 +340,23 @@ function InitAndStartRefTests()
         gTotalChunks = prefs.getIntPref("reftest.totalChunks");
         gThisChunk = prefs.getIntPref("reftest.thisChunk");
     }
     catch(e) {
         gTotalChunks = 0;
         gThisChunk = 0;
     }
 
-    gWindowUtils = gContainingWindow.QueryInterface(CI.nsIInterfaceRequestor).getInterface(CI.nsIDOMWindowUtils);
-    if (!gWindowUtils || !gWindowUtils.compareCanvases)
-        throw "nsIDOMWindowUtils inteface missing";
+    try {
+        gWindowUtils = gContainingWindow.QueryInterface(CI.nsIInterfaceRequestor).getInterface(CI.nsIDOMWindowUtils);
+        if (gWindowUtils && !gWindowUtils.compareCanvases)
+            gWindowUtils = null;
+    } catch (e) {
+        gWindowUtils = null;
+    }
 
     gIOService = CC[IO_SERVICE_CONTRACTID].getService(CI.nsIIOService);
     gDebug = CC[DEBUG_CONTRACTID].getService(CI.nsIDebug2);
 
     RegisterProcessCrashObservers();
 
     if (gRemote) {
         gServer = null;
@@ -504,30 +507,28 @@ function BuildConditionSandbox(aURL) {
 
     // xr.XPCOMABI throws exception for configurations without full ABI
     // support (mobile builds on ARM)
     try {
         sandbox.xulRuntime.XPCOMABI = xr.XPCOMABI;
     } catch(e) {
         sandbox.xulRuntime.XPCOMABI = "";
     }
- 
-    
-    var gfxInfo = (NS_GFXINFO_CONTRACTID in CC) && CC[NS_GFXINFO_CONTRACTID].getService(CI.nsIGfxInfo);
+  
     try {
-      sandbox.d2d = gfxInfo.D2DEnabled;
-    } catch (e) {
-      sandbox.d2d = false;
+        // nsIGfxInfo is currently only implemented on Windows
+        sandbox.d2d = (NS_GFXINFO_CONTRACTID in CC) && CC[NS_GFXINFO_CONTRACTID].getService(CI.nsIGfxInfo).D2DEnabled;
+    } catch(e) {
+        sandbox.d2d = false;
     }
-    sandbox.azureQuartz = gfxInfo.getInfo().AzureBackend == "quartz";
 
     sandbox.layersGPUAccelerated =
-      gWindowUtils.layerManagerType != "Basic";
+      gWindowUtils && gWindowUtils.layerManagerType != "Basic";
     sandbox.layersOpenGL =
-      gWindowUtils.layerManagerType == "OpenGL";
+      gWindowUtils && gWindowUtils.layerManagerType == "OpenGL";
 
     // Shortcuts for widget toolkits.
     sandbox.Android = xr.OS == "Android";
     sandbox.cocoaWidget = xr.widgetToolkit == "cocoa";
     sandbox.gtk2Widget = xr.widgetToolkit == "gtk2";
     sandbox.qtWidget = xr.widgetToolkit == "qt";
     sandbox.winWidget = xr.widgetToolkit == "windows";
 
@@ -684,26 +685,26 @@ function ReadManifest(aURL, inherited_st
         var expected_status = EXPECTED_PASS;
         var allow_silent_fail = false;
         var minAsserts = 0;
         var maxAsserts = 0;
         var needs_focus = false;
         var slow = false;
         var prefSettings = [];
         
-        while (items[0].match(/^(fails|needs-focus|random|skip|asserts|slow|require-or|silentfail|pref|fuzzy)/)) {
+        while (items[0].match(/^(fails|needs-focus|random|skip|asserts|slow|require-or|silentfail|pref)/)) {
             var item = items.shift();
             var stat;
             var cond;
-            var m = item.match(/^(fails|random|skip|silentfail|fuzzy)-if(\(.*\))$/);
+            var m = item.match(/^(fails|random|skip|silentfail)-if(\(.*\))$/);
             if (m) {
                 stat = m[1];
                 // Note: m[2] contains the parentheses, and we want them.
                 cond = Components.utils.evalInSandbox(m[2], sandbox);
-            } else if (item.match(/^(fails|random|skip|fuzzy)$/)) {
+            } else if (item.match(/^(fails|random|skip)$/)) {
                 stat = item;
                 cond = true;
             } else if (item == "needs-focus") {
                 needs_focus = true;
                 cond = false;
             } else if ((m = item.match(/^asserts\((\d+)(-\d+)?\)$/))) {
                 cond = false;
                 minAsserts = Number(m[1]);
@@ -775,18 +776,16 @@ function ReadManifest(aURL, inherited_st
 
             if (cond) {
                 if (stat == "fails") {
                     expected_status = EXPECTED_FAIL;
                 } else if (stat == "random") {
                     expected_status = EXPECTED_RANDOM;
                 } else if (stat == "skip") {
                     expected_status = EXPECTED_DEATH;
-                } else if (stat == "fuzzy") {
-                    expected_status = EXPECTED_FUZZY;
                 } else if (stat == "silentfail") {
                     allow_silent_fail = true;
                 }
             }
         }
 
         expected_status = Math.max(expected_status, inherited_status);
 
@@ -1296,18 +1295,16 @@ function RecordResult(testRunTime, error
     outputs[EXPECTED_FAIL] = {
         true:  {s: "TEST-UNEXPECTED-PASS"       , n: "UnexpectedPass"},
         false: {s: "TEST-KNOWN-FAIL"            , n: "KnownFail"}
     };
     outputs[EXPECTED_RANDOM] = {
         true:  {s: "TEST-PASS" + randomMsg      , n: "Random"},
         false: {s: "TEST-KNOWN-FAIL" + randomMsg, n: "Random"}
     };
-    outputs[EXPECTED_FUZZY] = outputs[EXPECTED_PASS];
-
     var output;
 
     if (gURLs[0].type == TYPE_LOAD) {
         ++gTestResults.LoadOnly;
         gDumpLog("REFTEST TEST-PASS | " + gURLs[0].prettyPath + " | (LOAD ONLY)\n");
         gCurrentCanvas = null;
         FinishTestItem();
         return;
@@ -1400,35 +1397,31 @@ function RecordResult(testRunTime, error
             // Both documents have been loaded. Compare the renderings and see
             // if the comparison result matches the expected result specified
             // in the manifest.
 
             // number of different pixels
             var differences;
             // whether the two renderings match:
             var equal;
-            var maxDifference = {};
 
-            differences = gWindowUtils.compareCanvases(gCanvas1, gCanvas2, maxDifference);
-            equal = (differences == 0);
-
-            // what is expected on this platform (PASS, FAIL, or RANDOM)
-            var expected = gURLs[0].expected;
-
-            if (maxDifference.value > 0 && maxDifference.value <= 2) {
-                if (equal) {
-                    throw "Inconsistent result from compareCanvases.";
-                }
-                equal = expected == EXPECTED_FUZZY;
-                gDumpLog("REFTEST fuzzy match\n");
+            if (gWindowUtils) {
+                differences = gWindowUtils.compareCanvases(gCanvas1, gCanvas2, {});
+                equal = (differences == 0);
+            } else {
+                differences = -1;
+                var k1 = gCanvas1.toDataURL();
+                var k2 = gCanvas2.toDataURL();
+                equal = (k1 == k2);
             }
 
             // whether the comparison result matches what is in the manifest
             var test_passed = (equal == (gURLs[0].type == TYPE_REFTEST_EQUAL));
-
+            // what is expected on this platform (PASS, FAIL, or RANDOM)
+            var expected = gURLs[0].expected;
             output = outputs[expected][test_passed];
 
             ++gTestResults[output.n];
 
             var result = "REFTEST " + output.s + " | " +
                          gURLs[0].prettyPath + " | "; // the URL being tested
             switch (gURLs[0].type) {
                 case TYPE_REFTEST_NOTEQUAL:
@@ -1436,22 +1429,21 @@ function RecordResult(testRunTime, error
                     break;
                 case TYPE_REFTEST_EQUAL:
                     result += "image comparison (==) ";
                     break;
             }
             gDumpLog(result + "\n");
 
             if (!test_passed && expected == EXPECTED_PASS ||
-                !test_passed && expected == EXPECTED_FUZZY ||
                 test_passed && expected == EXPECTED_FAIL) {
                 if (!equal) {
                     gDumpLog("REFTEST   IMAGE 1 (TEST): " + gCanvas1.toDataURL() + "\n");
                     gDumpLog("REFTEST   IMAGE 2 (REFERENCE): " + gCanvas2.toDataURL() + "\n");
-                    gDumpLog("REFTEST number of differing pixels: " + differences + " max difference: " + maxDifference.value + "\n");
+                    gDumpLog("REFTEST number of differing pixels: " + differences + "\n");
                 } else {
                     gDumpLog("REFTEST   IMAGE: " + gCanvas1.toDataURL() + "\n");
                 }
             }
 
             if (!test_passed && expected == EXPECTED_PASS) {
                 FlushTestLog();
             }
--- a/modules/libpref/src/init/all.js
+++ b/modules/libpref/src/init/all.js
@@ -226,20 +226,16 @@ pref("gfx.font_rendering.harfbuzz.script
 
 #ifdef XP_WIN
 pref("gfx.font_rendering.directwrite.enabled", false);
 pref("gfx.font_rendering.directwrite.use_gdi_table_loading", true);
 #endif
 
 #ifdef XP_WIN
 pref("gfx.canvas.azure.enabled", true);
-#else
-#ifdef XP_MACOSX
-pref("gfx.canvas.azure.enabled", true);
-#endif
 #endif
 
 pref("accessibility.browsewithcaret", false);
 pref("accessibility.warn_on_browsewithcaret", true);
 
 pref("accessibility.browsewithcaret_shortcut.enabled", true);
 
 #ifndef XP_MACOSX