Back out 7160624804ff:69062da26093 (bug 892966) on suspicion of mochitest-4 test_bug767779.html bustage
authorPhil Ringnalda <philringnalda@gmail.com>
Fri, 12 Jul 2013 16:39:36 -0700
changeset 138769 67eb0198434e93de33312c01cd58cb0c8654130c
parent 138768 33fb417caccf3fb5b2676d9d119f2f9e9ab71447
child 138770 855854e0545335e97b57298dc80bccb9503e75e1
push id270
push userpvanderbeken@mozilla.com
push dateThu, 06 Mar 2014 09:24:21 +0000
bugs892966, 767779
milestone25.0a1
backs out7160624804ff2a1fe196b8c0eeead9e26609ac18
Back out 7160624804ff:69062da26093 (bug 892966) on suspicion of mochitest-4 test_bug767779.html bustage CLOSED TREE
gfx/2d/2D.h
gfx/2d/DrawTargetCG.cpp
gfx/2d/DrawTargetCG.h
gfx/2d/DrawTargetDual.h
gfx/2d/SourceSurfaceCG.cpp
gfx/2d/SourceSurfaceCG.h
gfx/thebes/gfxPlatform.cpp
gfx/thebes/gfxPlatformMac.cpp
gfx/thebes/gfxQuartzNativeDrawing.cpp
gfx/thebes/gfxQuartzNativeDrawing.h
widget/cocoa/nsChildView.mm
widget/cocoa/nsNativeThemeCocoa.mm
--- a/gfx/2d/2D.h
+++ b/gfx/2d/2D.h
@@ -834,18 +834,16 @@ 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; }
 
-  virtual bool IsDualDrawTarget() { return false; }
-
   void AddUserData(UserDataKey *key, void *userData, void (*destroy)(void*)) {
     mUserData.Add(key, userData, destroy);
   }
   void *GetUserData(UserDataKey *key) {
     return mUserData.Get(key);
   }
 
   /* Within this rectangle all pixels will be opaque by the time the result of
@@ -1009,38 +1007,21 @@ private:
  * DrawTargetCG. This is used for drawing themed widgets.
  *
  * Callers should check the cg member after constructing the object
  * to see if it succeeded. The DrawTarget should not be used while
  * the context is borrowed. */
 class BorrowedCGContext
 {
 public:
-  BorrowedCGContext()
-    : cg(nullptr)
-    , mDT(nullptr)
-  { }
-
-  BorrowedCGContext(DrawTarget *aDT)
-    : mDT(aDT)
+  BorrowedCGContext(DrawTarget *aDT) : mDT(aDT)
   {
     cg = BorrowCGContextFromDrawTarget(aDT);
   }
 
-  // We can optionally Init after construction in
-  // case we don't know what the DT will be at construction
-  // time.
-  CGContextRef Init(DrawTarget *aDT)
-  {
-    MOZ_ASSERT(!mDT, "Can't initialize twice!");
-    mDT = aDT;
-    cg = BorrowCGContextFromDrawTarget(aDT);
-    return cg;
-  }
-
   // The caller needs to call Finish if cg is non-null when
   // they are done with the context. This is currently explicit
   // instead of happening implicitly in the destructor to make
   // what's happening in the caller more clear. It also
   // let's you resume using the DrawTarget in the same scope.
   void Finish()
   {
     if (cg) {
--- a/gfx/2d/DrawTargetCG.cpp
+++ b/gfx/2d/DrawTargetCG.cpp
@@ -641,17 +641,32 @@ DrawTargetCG::StrokeRect(const Rect &aRe
 
   UnboundnessFixer fixer;
   CGContextRef cg = fixer.Check(mCg, aDrawOptions.mCompositionOp);
   CGContextSetAlpha(mCg, aDrawOptions.mAlpha);
   CGContextSetBlendMode(mCg, ToBlendMode(aDrawOptions.mCompositionOp));
 
   CGContextConcatCTM(cg, GfxMatrixToCGAffineTransform(mTransform));
 
-  SetStrokeOptions(cg, aStrokeOptions);
+  // 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);
@@ -1025,17 +1040,16 @@ DrawTargetCG::Init(CGContextRef cgContex
   //XXX: handle SurfaceFormat
 
   //XXX: we'd be better off reusing the Colorspace across draw targets
   mColorSpace = CGColorSpaceCreateDeviceRGB();
 
   mSize = aSize;
 
   mCg = cgContext;
-  CGContextRetain(mCg);
 
   mData = nullptr;
 
   assert(mCg);
 
   // CGContext's default to have the origin at the bottom left.
   // However, currently the only use of this function is to construct a
   // DrawTargetCG around a CGContextRef from a cairo quartz surface which
@@ -1078,31 +1092,16 @@ DrawTargetCG::GetNativeSurface(NativeSur
   if ((aType == NATIVE_SURFACE_CGCONTEXT && GetContextType(mCg) == CG_CONTEXT_TYPE_BITMAP) ||
       (aType == NATIVE_SURFACE_CGCONTEXT_ACCELERATED && GetContextType(mCg) == CG_CONTEXT_TYPE_IOSURFACE)) {
     return mCg;
   } else {
     return nullptr;
   }
 }
 
-TemporaryRef<SourceSurface>
-DrawTargetCG::CreateSourceSurfaceFromNativeSurface(const NativeSurface& aNative) const
-{
-  if (aNative.mType != NATIVE_SURFACE_CGCONTEXT) {
-    return nullptr;
-  }
-
-  CGContextRef cg = (CGContextRef)aNative.mSurface;
-  if (GetContextType(cg) != CG_CONTEXT_TYPE_BITMAP) {
-    return nullptr;
-  }
-
-  return new SourceSurfaceCGBitmapContext(cg);
-}
-
 void
 DrawTargetCG::Mask(const Pattern &aSource,
                    const Pattern &aMask,
                    const DrawOptions &aDrawOptions)
 {
   MarkChanged();
 
   CGContextSaveGState(mCg);
@@ -1205,18 +1204,16 @@ BorrowedCGContext::BorrowCGContextFromDr
 
     // swap out the context
     CGContextRef cg = cgDT->mCg;
     cgDT->mCg = nullptr;
 
     // save the state to make it easier for callers to avoid mucking with things
     CGContextSaveGState(cg);
 
-    CGContextConcatCTM(cg, GfxMatrixToCGAffineTransform(cgDT->mTransform));
-
     return cg;
   }
   return nullptr;
 }
 
 void
 BorrowedCGContext::ReturnCGContextToDrawTarget(DrawTarget *aDT, CGContextRef cg)
 {
--- a/gfx/2d/DrawTargetCG.h
+++ b/gfx/2d/DrawTargetCG.h
@@ -124,17 +124,17 @@ public:
   virtual void Fill(const Path *, const Pattern &, const DrawOptions &);
   virtual void FillGlyphs(ScaledFont *, const GlyphBuffer&, const Pattern &, const DrawOptions &, const GlyphRenderingOptions *);
   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;
+  virtual TemporaryRef<SourceSurface> CreateSourceSurfaceFromNativeSurface(const NativeSurface&) const { return nullptr;}
   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; }
--- a/gfx/2d/DrawTargetDual.h
+++ b/gfx/2d/DrawTargetDual.h
@@ -126,21 +126,16 @@ public:
   {
     return mA->CreateGradientStops(aStops, aNumStops, aExtendMode);
   }
      
   virtual void *GetNativeSurface(NativeSurfaceType aType)
   {
     return nullptr;
   }
-
-  virtual bool IsDualDrawTarget()
-  {
-    return true;
-  }
      
 private:
   RefPtr<DrawTarget> mA;
   RefPtr<DrawTarget> mB;
 };
      
 }
 }
--- a/gfx/2d/SourceSurfaceCG.cpp
+++ b/gfx/2d/SourceSurfaceCG.cpp
@@ -236,31 +236,19 @@ DataSourceSurfaceCG::GetData()
   // unfortunately the the method above only works for read-only access and
   // we need read-write for DataSourceSurfaces
   return (unsigned char*)mData;
 }
 
 SourceSurfaceCGBitmapContext::SourceSurfaceCGBitmapContext(DrawTargetCG *aDrawTarget)
 {
   mDrawTarget = aDrawTarget;
-  Init((CGContextRef)aDrawTarget->GetNativeSurface(NATIVE_SURFACE_CGCONTEXT));
-}
-
-SourceSurfaceCGBitmapContext::SourceSurfaceCGBitmapContext(CGContextRef cg)
-{
-  Init(cg);
-}
-
-void
-SourceSurfaceCGBitmapContext::Init(CGContextRef cg)
-{
-  MOZ_ASSERT(cg);
-  MOZ_ASSERT(GetContextType(cg) == CG_CONTEXT_TYPE_BITMAP);
-
-  mCg = CGContextRetain(cg);
+  mCg = (CGContextRef)aDrawTarget->GetNativeSurface(NATIVE_SURFACE_CGCONTEXT);
+  if (!mCg)
+    abort();
 
   mSize.width = CGBitmapContextGetWidth(mCg);
   mSize.height = CGBitmapContextGetHeight(mCg);
   mStride = CGBitmapContextGetBytesPerRow(mCg);
   mData = CGBitmapContextGetData(mCg);
 
   mImage = nullptr;
 }
@@ -315,31 +303,27 @@ SourceSurfaceCGBitmapContext::DrawTarget
     // we transfer it to mImage
     memcpy(mData, CGBitmapContextGetData(mCg), stride*height);
 
     // drop the current image for the data associated with the CGBitmapContext
     if (mImage)
       CGImageRelease(mImage);
     mImage = nullptr;
 
-    CGContextRelease(mCg);
     mCg = nullptr;
     mDrawTarget = nullptr;
   }
 }
 
 SourceSurfaceCGBitmapContext::~SourceSurfaceCGBitmapContext()
 {
   if (!mImage && !mCg) {
     // neither mImage or mCg owns the data
     free(mData);
   }
-  if (mCg) {
-    CGContextRelease(mCg);
-  }
   if (mImage)
     CGImageRelease(mImage);
 }
 
 SourceSurfaceCGIOSurfaceContext::SourceSurfaceCGIOSurfaceContext(DrawTargetCG *aDrawTarget)
 {
   CGContextRef cg = (CGContextRef)aDrawTarget->GetNativeSurface(NATIVE_SURFACE_CGCONTEXT_ACCELERATED);
 
--- a/gfx/2d/SourceSurfaceCG.h
+++ b/gfx/2d/SourceSurfaceCG.h
@@ -83,42 +83,37 @@ public:
   virtual void DrawTargetWillChange() = 0;
   virtual CGImageRef GetImage() = 0;
 };
 
 class SourceSurfaceCGBitmapContext : public SourceSurfaceCGContext
 {
 public:
   SourceSurfaceCGBitmapContext(DrawTargetCG *);
-  SourceSurfaceCGBitmapContext(CGContextRef);
   ~SourceSurfaceCGBitmapContext();
 
-  void Init(CGContextRef);
-
   virtual SurfaceType GetType() const { return SURFACE_COREGRAPHICS_CGCONTEXT; }
   virtual IntSize GetSize() const;
   virtual SurfaceFormat GetFormat() const { return FORMAT_B8G8R8A8; }
 
   CGImageRef GetImage() { EnsureImage(); return mImage; }
 
   virtual unsigned char *GetData() { return static_cast<unsigned char*>(mData); }
 
   virtual int32_t Stride() { return mStride; }
 
 private:
   //XXX: do the other backends friend their DrawTarget?
   friend class DrawTargetCG;
   virtual void DrawTargetWillChange();
   void EnsureImage() const;
 
-  // We hold a weak reference to this objects.
+  // We hold a weak reference to these two objects.
+  // The cycle is broken by DrawTargetWillChange
   DrawTargetCG *mDrawTarget;
-
-  // We hold a strong reference to this.
-  // The cycle is broken by DrawTargetWillChange
   CGContextRef mCg;
 
   mutable CGImageRef mImage;
 
   // mData can be owned by three different things:
   // mImage, mCg or SourceSurfaceCGBitmapContext
   void *mData;
 
--- a/gfx/thebes/gfxPlatform.cpp
+++ b/gfx/thebes/gfxPlatform.cpp
@@ -634,25 +634,16 @@ gfxPlatform::GetSourceSurfaceForSurface(
     surf.mType = NATIVE_SURFACE_D3D10_TEXTURE;
     surf.mSurface = static_cast<gfxD2DSurface*>(aSurface)->GetTexture();
     mozilla::gfx::DrawTarget *dt = static_cast<mozilla::gfx::DrawTarget*>(aSurface->GetData(&kDrawTarget));
     if (dt) {
       dt->Flush();
     }
     srcBuffer = aTarget->CreateSourceSurfaceFromNativeSurface(surf);
   } else
-#elif defined XP_MACOSX
-  if (aSurface->GetType() == gfxASurface::SurfaceTypeQuartz) {
-    NativeSurface surf;
-    surf.mFormat = format;
-    surf.mType = NATIVE_SURFACE_CGCONTEXT;
-    surf.mSurface = static_cast<gfxQuartzSurface*>(aSurface)->GetCGContext();
-
-    srcBuffer = aTarget->CreateSourceSurfaceFromNativeSurface(surf);
-  } else
 #endif
   if (aSurface->CairoSurface() && aTarget->GetType() == BACKEND_CAIRO) {
     // If this is an xlib cairo surface we don't want to fetch it into memory
     // because this is a major slow down.
     NativeSurface surf;
     surf.mFormat = format;
     surf.mType = NATIVE_SURFACE_CAIRO_SURFACE;
     surf.mSurface = aSurface->CairoSurface();
--- a/gfx/thebes/gfxPlatformMac.cpp
+++ b/gfx/thebes/gfxPlatformMac.cpp
@@ -66,17 +66,17 @@ gfxPlatformMac::gfxPlatformMac()
 {
     mOSXVersion = 0;
     OSXVersion();
 
     DisableFontActivation();
     mFontAntiAliasingThreshold = ReadAntiAliasingThreshold();
 
     uint32_t canvasMask = (1 << BACKEND_CAIRO) | (1 << BACKEND_SKIA) | (1 << BACKEND_COREGRAPHICS);
-    uint32_t contentMask = (1 << BACKEND_COREGRAPHICS);
+    uint32_t contentMask = 0;
     InitBackendPrefs(canvasMask, contentMask);
 }
 
 gfxPlatformMac::~gfxPlatformMac()
 {
     gfxCoreTextShaper::Shutdown();
 }
 
--- a/gfx/thebes/gfxQuartzNativeDrawing.cpp
+++ b/gfx/thebes/gfxQuartzNativeDrawing.cpp
@@ -3,65 +3,39 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "nsMathUtils.h"
 
 #include "gfxQuartzNativeDrawing.h"
 #include "gfxQuartzSurface.h"
 #include "cairo-quartz.h"
-#include "mozilla/gfx/2D.h"
 // see cairo-quartz-surface.c for the complete list of these
 enum {
     kPrivateCGCompositeSourceOver = 2
 };
 
-using namespace mozilla::gfx;
-using namespace mozilla;
-
 // private Quartz routine needed here
 extern "C" {
     CG_EXTERN void CGContextSetCompositeOperation(CGContextRef, int);
 }
 
 gfxQuartzNativeDrawing::gfxQuartzNativeDrawing(gfxContext* ctx,
                                                const gfxRect& nativeRect,
                                                gfxFloat aBackingScale)
-    : mContext(ctx)
-    , mNativeRect(nativeRect)
-    , mBackingScale(aBackingScale)
+    : mContext(ctx), mNativeRect(nativeRect), mBackingScale(aBackingScale)
 {
     mNativeRect.RoundOut();
 }
 
 CGContextRef
 gfxQuartzNativeDrawing::BeginNativeDrawing()
 {
     NS_ASSERTION(!mQuartzSurface, "BeginNativeDrawing called when drawing already in progress");
 
-    if (!mContext->IsCairo()) {
-      DrawTarget *dt = mContext->GetDrawTarget();
-      if (mContext->GetDrawTarget()->IsDualDrawTarget()) {
-        IntSize backingSize(NSToIntFloor(mNativeRect.width * mBackingScale),
-                            NSToIntFloor(mNativeRect.height * mBackingScale));
-        mDrawTarget = Factory::CreateDrawTarget(BACKEND_COREGRAPHICS, backingSize, FORMAT_B8G8R8A8);
-
-        Matrix transform;
-        transform.Scale(mBackingScale, mBackingScale);
-        transform.Translate(-mNativeRect.x, -mNativeRect.y);
-
-        mDrawTarget->SetTransform(transform);
-        dt = mDrawTarget;
-      }
-
-      mCGContext = mBorrowedContext.Init(dt);
-      MOZ_ASSERT(mCGContext);
-      return mCGContext;
-    }
-
     gfxPoint deviceOffset;
     nsRefPtr<gfxASurface> surf = mContext->CurrentSurface(&deviceOffset.x, &deviceOffset.y);
     if (!surf || surf->CairoStatus())
         return nullptr;
 
     // if this is a native Quartz surface, we don't have to redirect
     // rendering to our own CGContextRef; in most cases, we are able to
     // use the CGContextRef from the surface directly.  we can extend
@@ -117,44 +91,17 @@ gfxQuartzNativeDrawing::BeginNativeDrawi
     }
 
     return mCGContext;
 }
 
 void
 gfxQuartzNativeDrawing::EndNativeDrawing()
 {
-    NS_ASSERTION(mCGContext, "EndNativeDrawing called without BeginNativeDrawing");
-
-    if (mBorrowedContext.cg) {
-        MOZ_ASSERT(!mContext->IsCairo());
-        if (mDrawTarget) {
-          DrawTarget *dest = mContext->GetDrawTarget();
-          RefPtr<SourceSurface> source = mDrawTarget->Snapshot();
-
-          IntSize backingSize(NSToIntFloor(mNativeRect.width * mBackingScale),
-                              NSToIntFloor(mNativeRect.height * mBackingScale));
-
-          Matrix oldTransform = dest->GetTransform();
-          Matrix newTransform = oldTransform;
-          newTransform.Translate(mNativeRect.x, mNativeRect.y);
-          newTransform.Scale(1.0f / mBackingScale, 1.0f / mBackingScale);
-
-          dest->SetTransform(newTransform);
-
-          dest->DrawSurface(source,
-                            gfx::Rect(0, 0, backingSize.width, backingSize.height),
-                            gfx::Rect(0, 0, backingSize.width, backingSize.height));
-
-
-          dest->SetTransform(oldTransform);
-        }
-        mBorrowedContext.Finish();
-        return;
-    }
+    NS_ASSERTION(mQuartzSurface, "EndNativeDrawing called without BeginNativeDrawing");
 
     cairo_quartz_finish_cg_context_with_clip(mSurfaceContext->GetCairo());
     mQuartzSurface->MarkDirty();
     if (mSurfaceContext != mContext) {
         gfxContextMatrixAutoSaveRestore save(mContext);
 
         // Copy back to destination
         mContext->Translate(mNativeRect.TopLeft());
--- a/gfx/thebes/gfxQuartzNativeDrawing.h
+++ b/gfx/thebes/gfxQuartzNativeDrawing.h
@@ -51,21 +51,18 @@ public:
     /* Marks the end of native drawing */
     void EndNativeDrawing();
 
 private:
     // don't allow copying via construction or assignment
     gfxQuartzNativeDrawing(const gfxQuartzNativeDrawing&) MOZ_DELETE;
     const gfxQuartzNativeDrawing& operator=(const gfxQuartzNativeDrawing&) MOZ_DELETE;
 
-
     // Final destination context
     nsRefPtr<gfxContext> mContext;
-    mozilla::RefPtr<mozilla::gfx::DrawTarget> mDrawTarget;
-    mozilla::gfx::BorrowedCGContext mBorrowedContext;
     // context that draws to mQuartzSurface; can be different from mContext
     // if mContext is not drawing to Quartz
     nsRefPtr<gfxContext> mSurfaceContext;
     gfxRect mNativeRect;
     gfxFloat mBackingScale;
 
     // saved state
     nsRefPtr<gfxQuartzSurface> mQuartzSurface;
--- a/widget/cocoa/nsChildView.mm
+++ b/widget/cocoa/nsChildView.mm
@@ -2100,19 +2100,17 @@ nsChildView::MaybeDrawResizeIndicator(GL
 
   if (!mResizerImage) {
     mResizerImage = new RectTextureImage(aManager->gl());
   }
 
   nsIntSize size = mResizeIndicatorRect.Size();
   mResizerImage->UpdateIfNeeded(size, nsIntRegion(), ^(gfx::DrawTarget* drawTarget, const nsIntRegion& updateRegion) {
     ClearRegion(drawTarget, updateRegion);
-    gfx::BorrowedCGContext borrow(drawTarget);
-    DrawResizer(borrow.cg);
-    borrow.Finish();
+    DrawResizer(static_cast<CGContextRef>(drawTarget->GetNativeSurface(gfx::NATIVE_SURFACE_CGCONTEXT)));
   });
 
   mResizerImage->Draw(aManager, mResizeIndicatorRect.TopLeft());
 }
 
 // Draw the highlight line at the top of the titlebar.
 // This function draws into the current NSGraphicsContext and assumes flippedness.
 static void
@@ -2162,18 +2160,19 @@ nsChildView::UpdateTitlebarImageBuffer()
                                      gfx::FORMAT_B8G8R8A8);
   }
 
   if (dirtyTitlebarRegion.IsEmpty())
     return;
 
   ClearRegion(mTitlebarImageBuffer, dirtyTitlebarRegion);
 
-  gfx::BorrowedCGContext borrow(mTitlebarImageBuffer);
-  CGContextRef ctx = borrow.cg;
+  CGContextRef ctx =
+    static_cast<CGContextRef>(mTitlebarImageBuffer->GetNativeSurface(gfx::NATIVE_SURFACE_CGCONTEXT));
+  CGContextSaveGState(ctx);
 
   double scale = BackingScaleFactor();
   CGContextScaleCTM(ctx, scale, scale);
   NSGraphicsContext* oldContext = [NSGraphicsContext currentContext];
 
   CGContextSaveGState(ctx);
 
   BaseWindow* window = (BaseWindow*)[mView window];
@@ -2229,17 +2228,17 @@ nsChildView::UpdateTitlebarImageBuffer()
   }
 
   CGContextRestoreGState(ctx);
 
   DrawTitlebarHighlight([frameView bounds].size, [(ChildView*)mView cornerRadius],
                         DevPixelsToCocoaPoints(1));
 
   [NSGraphicsContext setCurrentContext:oldContext];
-  borrow.Finish();
+  CGContextRestoreGState(ctx);
 
   mUpdatedTitlebarRegion.Or(mUpdatedTitlebarRegion, dirtyTitlebarRegion);
 }
 
 // This method draws an overlay in the top of the window which contains the
 // titlebar controls (e.g. close, min, zoom, fullscreen) and the titlebar
 // highlight effect.
 // This is necessary because the real titlebar controls are covered by our
@@ -2286,19 +2285,18 @@ nsChildView::MaybeDrawRoundedCorners(GLM
 
   if (!mCornerMaskImage) {
     mCornerMaskImage = new RectTextureImage(aManager->gl());
   }
 
   nsIntSize size(mDevPixelCornerRadius, mDevPixelCornerRadius);
   mCornerMaskImage->UpdateIfNeeded(size, nsIntRegion(), ^(gfx::DrawTarget* drawTarget, const nsIntRegion& updateRegion) {
     ClearRegion(drawTarget, updateRegion);
-    gfx::BorrowedCGContext borrow(drawTarget);
-    DrawTopLeftCornerMask(borrow.cg, mDevPixelCornerRadius);
-    borrow.Finish();
+    DrawTopLeftCornerMask(static_cast<CGContextRef>(drawTarget->GetNativeSurface(gfx::NATIVE_SURFACE_CGCONTEXT)),
+                          mDevPixelCornerRadius);
   });
 
   // Use operator destination in: multiply all 4 channels with source alpha.
   aManager->gl()->fBlendFuncSeparate(LOCAL_GL_ZERO, LOCAL_GL_SRC_ALPHA,
                                      LOCAL_GL_ZERO, LOCAL_GL_SRC_ALPHA);
 
   gfx3DMatrix flipX = gfx3DMatrix::ScalingMatrix(-1, 1, 1);
   gfx3DMatrix flipY = gfx3DMatrix::ScalingMatrix(1, -1, 1);
--- a/widget/cocoa/nsNativeThemeCocoa.mm
+++ b/widget/cocoa/nsNativeThemeCocoa.mm
@@ -28,18 +28,16 @@
 #include "mozilla/dom/Element.h"
 #include "nsLookAndFeel.h"
 
 #include "gfxContext.h"
 #include "gfxQuartzSurface.h"
 #include "gfxQuartzNativeDrawing.h"
 #include <algorithm>
 
-using namespace mozilla::gfx;
-
 #define DRAW_IN_FRAME_DEBUG 0
 #define SCROLLBARS_VISUAL_DEBUG 0
 
 // private Quartz routines needed here
 extern "C" {
   CG_EXTERN void CGContextSetCTM(CGContextRef, CGAffineTransform);
 }
 
@@ -2035,25 +2033,17 @@ nsNativeThemeCocoa::DrawWidgetBackground
       // The rounded corners draw outside the frame.
       CGRect deflatedRect = CGRectMake(macRect.origin.x, macRect.origin.y + 4,
                                        macRect.size.width, macRect.size.height - 8);
       HIThemeDrawMenuBackground(&deflatedRect, &mdi, cgContext, HITHEME_ORIENTATION);
     }
       break;
 
     case NS_THEME_MENUITEM: {
-      bool isTransparent;
-      if (thebesCtx->IsCairo()) {
-        isTransparent = thebesCtx->OriginalSurface()->GetContentType() == gfxASurface::CONTENT_COLOR_ALPHA;
-      } else {
-        SurfaceFormat format  = thebesCtx->GetDrawTarget()->GetFormat();
-        isTransparent = (format == FORMAT_R8G8B8A8) ||
-                        (format == FORMAT_B8G8R8A8);
-      }
-      if (isTransparent) {
+      if (thebesCtx->OriginalSurface()->GetContentType() == gfxASurface::CONTENT_COLOR_ALPHA) {
         // Clear the background to get correct transparency.
         CGContextClearRect(cgContext, macRect);
       }
 
       // maybe use kThemeMenuItemHierBackground or PopUpBackground instead of just Plain?
       HIThemeMenuItemDrawInfo drawInfo;
       memset(&drawInfo, 0, sizeof(drawInfo));
       drawInfo.version = 0;