Backed out changeset 8dcb029b9ca5 (bug 880836) for asserts.
authorRyan VanderMeulen <ryanvm@gmail.com>
Tue, 18 Jun 2013 12:08:19 -0400
changeset 146975 d5b59c74871e627869f7399015f02b62bb5bd839
parent 146974 86ae36fa3ea2a264e27184d459de175021577ef7
child 146976 8416c29fecda6ecc9c5a2a68dfb9b1679823b8fb
push id2697
push userbbajaj@mozilla.com
push dateMon, 05 Aug 2013 18:49:53 +0000
treeherdermozilla-beta@dfec938c7b63 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs880836
milestone24.0a1
backs out8dcb029b9ca587d315419f2f907671ddb4c9620a
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
Backed out changeset 8dcb029b9ca5 (bug 880836) for asserts. CLOSED TREE
gfx/2d/2D.h
gfx/2d/DrawTargetCG.cpp
gfx/2d/DrawTargetCG.h
gfx/2d/DrawTargetCairo.cpp
gfx/2d/DrawTargetD2D.cpp
gfx/2d/DrawTargetD2D.h
gfx/thebes/gfxContext.cpp
layout/reftests/bugs/reftest.list
--- a/gfx/2d/2D.h
+++ b/gfx/2d/2D.h
@@ -702,31 +702,16 @@ public:
    * aMask Mask pattern
    * aOptions Drawing options
    */
   virtual void Mask(const Pattern &aSource,
                     const Pattern &aMask,
                     const DrawOptions &aOptions = DrawOptions()) = 0;
 
   /*
-   * This takes a source pattern and a mask, and composites the source pattern
-   * onto the destination surface using the alpha channel of the mask source.
-   * The operation is bound by the extents of the mask.
-   *
-   * aSource Source pattern
-   * aMask Mask surface
-   * aOffset a transformed offset that the surface is masked at
-   * aOptions Drawing options
-   */
-  virtual void MaskSurface(const Pattern &aSource,
-                           SourceSurface *aMask,
-                           Point aOffset,
-                           const DrawOptions &aOptions = DrawOptions()) { MOZ_ASSERT(0); };
-
-  /*
    * Push a clip to the DrawTarget.
    *
    * aPath The path to clip to
    */
   virtual void PushClip(const Path *aPath) = 0;
 
   /*
    * Push an axis-aligned rectangular clip to the DrawTarget. This rectangle
--- a/gfx/2d/DrawTargetCG.cpp
+++ b/gfx/2d/DrawTargetCG.cpp
@@ -295,48 +295,16 @@ DrawTargetCG::DrawSurface(SourceSurface 
 
   fixer.Fix(mCg);
 
   CGContextRestoreGState(mCg);
 
   CGImageRelease(subimage);
 }
 
-void
-DrawTargetCG::MaskSurface(const Pattern &aSource,
-                          SourceSurface *aMask,
-                          Point aOffset,
-                          const DrawOptions &aDrawOptions)
-{
-  MarkChanged();
-
-  CGImageRef 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));
-  image = GetImageFromSourceSurface(aMask);
-
-  CGContextScaleCTM(cg, 1, -1);
-
-  IntSize size = aMask->GetSize();
-  CGContextClipToMask(cg, CGRectMake(aOffset.x, aOffset.y, size.width, size.height), image);
-  
-  FillRect(Rect(0, 0, size.width, size.height), aSource, aDrawOptions);
-  
-  fixer.Fix(mCg);
-
-  CGContextRestoreGState(mCg);
-
-}
-
 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
 {
--- a/gfx/2d/DrawTargetCG.h
+++ b/gfx/2d/DrawTargetCG.h
@@ -91,20 +91,16 @@ public:
   virtual BackendType GetType() const;
   virtual TemporaryRef<SourceSurface> Snapshot();
 
   virtual void DrawSurface(SourceSurface *aSurface,
                            const Rect &aDest,
                            const Rect &aSource,
                            const DrawSurfaceOptions &aSurfOptions = DrawSurfaceOptions(),
                            const DrawOptions &aOptions = DrawOptions());
-  virtual void MaskSurface(const Pattern &aSource,
-                           SourceSurface *aMask,
-                           Point aOffset,
-                           const DrawOptions &aOptions = DrawOptions());
 
   virtual void FillRect(const Rect &aRect,
                         const Pattern &aPattern,
                         const DrawOptions &aOptions = DrawOptions());
 
 
   //XXX: why do we take a reference to SurfaceFormat?
   bool Init(BackendType aType, const IntSize &aSize, SurfaceFormat&);
--- a/gfx/2d/DrawTargetCairo.cpp
+++ b/gfx/2d/DrawTargetCairo.cpp
@@ -671,65 +671,16 @@ DrawTargetCairo::Mask(const Pattern &aSo
   cairo_set_source(mContext, source);
 
   cairo_pattern_t* mask = GfxPatternToCairoPattern(aMask, aOptions.mAlpha);
   cairo_mask(mContext, mask);
 
   cairo_pattern_destroy(mask);
   cairo_pattern_destroy(source);
 }
-#if 0
-DrawTargetCairo::MaskSurface(SourceSurface *aSurface,
-                             const Rect &aDest,
-                             const Rect &aSource,
-                             const DrawSurfaceOptions &aSurfOptions,
-                             const DrawOptions &aOptions)
-{
-  AutoPrepareForDrawing prep(this, mContext);
-
-  float sx = aSource.Width() / aDest.Width();
-  float sy = aSource.Height() / aDest.Height();
-
-  cairo_matrix_t src_mat;
-  cairo_matrix_init_translate(&src_mat, aSource.X(), aSource.Y());
-  cairo_matrix_scale(&src_mat, sx, sy);
-
-  cairo_surface_t* surf = GetCairoSurfaceForSourceSurface(aSurface);
-  cairo_pattern_t* pat = cairo_pattern_create_for_surface(surf);
-  cairo_surface_destroy(surf);
-
-  cairo_pattern_set_matrix(pat, &src_mat);
-  cairo_pattern_set_filter(pat, GfxFilterToCairoFilter(aSurfOptions.mFilter));
-  cairo_pattern_set_extend(pat, CAIRO_EXTEND_PAD);
-
-  cairo_translate(mContext, aDest.X(), aDest.Y());
-
-  if (IsOperatorBoundByMask(aOptions.mCompositionOp)) {
-    cairo_new_path(mContext);
-    cairo_rectangle(mContext, 0, 0, aDest.Width(), aDest.Height());
-    cairo_clip(mContext);
-    cairo_set_source(mContext, pat);
-  } else {
-    cairo_push_group(mContext);
-      cairo_new_path(mContext);
-      cairo_rectangle(mContext, 0, 0, aDest.Width(), aDest.Height());
-      cairo_set_source(mContext, pat);
-      cairo_fill(mContext);
-    cairo_pop_group_to_source(mContext);
-  }
-
-  cairo_set_operator(mContext, GfxOpToCairoOp(aOptions.mCompositionOp));
-  DrawPattern(aPattern, StrokeOptions(), aOptions, DRAW_FILL);
-
-  cairo_paint_with_alpha(mContext, aOptions.mAlpha);
-
-  cairo_pattern_destroy(pat);
-}
-
-#endif
 
 void
 DrawTargetCairo::PushClip(const Path *aPath)
 {
   if (aPath->GetBackendType() != BACKEND_CAIRO) {
     return;
   }
 
--- a/gfx/2d/DrawTargetD2D.cpp
+++ b/gfx/2d/DrawTargetD2D.cpp
@@ -252,73 +252,16 @@ void
 DrawTargetD2D::AddDependencyOnSource(SourceSurfaceD2DTarget* aSource)
 {
   if (aSource->mDrawTarget && !mDependingOnTargets.count(aSource->mDrawTarget)) {
     aSource->mDrawTarget->mDependentTargets.insert(this);
     mDependingOnTargets.insert(aSource->mDrawTarget);
   }
 }
 
-TemporaryRef<ID2D1Bitmap>
-DrawTargetD2D::GetBitmapForSurface(SourceSurface *aSurface,
-                                   Rect &aSource)
-{
-  RefPtr<ID2D1Bitmap> bitmap;
-
-  switch (aSurface->GetType()) {
-
-  case SURFACE_D2D1_BITMAP:
-    {
-      SourceSurfaceD2D *srcSurf = static_cast<SourceSurfaceD2D*>(aSurface);
-      bitmap = srcSurf->GetBitmap();
-    }
-    break;
-  case SURFACE_D2D1_DRAWTARGET:
-    {
-      SourceSurfaceD2DTarget *srcSurf = static_cast<SourceSurfaceD2DTarget*>(aSurface);
-      bitmap = srcSurf->GetBitmap(mRT);
-      AddDependencyOnSource(srcSurf);
-    }
-    break;
-  default:
-    {
-      RefPtr<DataSourceSurface> srcSurf = aSurface->GetDataSurface();
-
-      if (!srcSurf) {
-        gfxDebug() << "Not able to deal with non-data source surface.";
-        return nullptr;
-      }
-
-      if (aSource.width > mRT->GetMaximumBitmapSize() ||
-          aSource.height > mRT->GetMaximumBitmapSize()) {
-        gfxDebug() << "Bitmap source larger than texture size specified. DrawBitmap will silently fail.";
-        // Don't know how to deal with this yet.
-        return nullptr;
-      }
-
-      int stride = srcSurf->Stride();
-
-      unsigned char *data = srcSurf->GetData() +
-                            (uint32_t)aSource.y * stride +
-                            (uint32_t)aSource.x * BytesPerPixel(srcSurf->GetFormat());
-
-      D2D1_BITMAP_PROPERTIES props =
-        D2D1::BitmapProperties(D2D1::PixelFormat(DXGIFormat(srcSurf->GetFormat()), AlphaMode(srcSurf->GetFormat())));
-      mRT->CreateBitmap(D2D1::SizeU(UINT32(aSource.width), UINT32(aSource.height)), data, stride, props, byRef(bitmap));
-
-      // subtract the integer part leaving the fractional part
-      aSource.x -= (uint32_t)aSource.x;
-      aSource.y -= (uint32_t)aSource.y;
-    }
-    break;
-  }
-
-  return bitmap;
-}
-
 void
 DrawTargetD2D::DrawSurface(SourceSurface *aSurface,
                            const Rect &aDest,
                            const Rect &aSource,
                            const DrawSurfaceOptions &aSurfOptions,
                            const DrawOptions &aOptions)
 {
   RefPtr<ID2D1Bitmap> bitmap;
@@ -326,56 +269,73 @@ DrawTargetD2D::DrawSurface(SourceSurface
   ID2D1RenderTarget *rt = GetRTForOperation(aOptions.mCompositionOp, ColorPattern(Color()));
   
   PrepareForDrawing(rt);
 
   rt->SetAntialiasMode(D2DAAMode(aOptions.mAntialiasMode));
 
   Rect srcRect = aSource;
 
-  bitmap = GetBitmapForSurface(aSurface, srcRect);
-  if (!bitmap) {
-      return;
+  switch (aSurface->GetType()) {
+
+  case SURFACE_D2D1_BITMAP:
+    {
+      SourceSurfaceD2D *srcSurf = static_cast<SourceSurfaceD2D*>(aSurface);
+      bitmap = srcSurf->GetBitmap();
+
+      if (!bitmap) {
+        return;
+      }
+    }
+    break;
+  case SURFACE_D2D1_DRAWTARGET:
+    {
+      SourceSurfaceD2DTarget *srcSurf = static_cast<SourceSurfaceD2DTarget*>(aSurface);
+      bitmap = srcSurf->GetBitmap(mRT);
+      AddDependencyOnSource(srcSurf);
+    }
+    break;
+  default:
+    {
+      RefPtr<DataSourceSurface> srcSurf = aSurface->GetDataSurface();
+
+      if (!srcSurf) {
+        gfxDebug() << "Not able to deal with non-data source surface.";
+        return;
+      }
+
+      if (aSource.width > rt->GetMaximumBitmapSize() ||
+          aSource.height > rt->GetMaximumBitmapSize()) {
+        gfxDebug() << "Bitmap source larger than texture size specified. DrawBitmap will silently fail.";
+        // Don't know how to deal with this yet.
+        return;
+      }
+
+      int stride = srcSurf->Stride();
+
+      unsigned char *data = srcSurf->GetData() +
+                            (uint32_t)aSource.y * stride +
+                            (uint32_t)aSource.x * BytesPerPixel(srcSurf->GetFormat());
+
+      D2D1_BITMAP_PROPERTIES props =
+        D2D1::BitmapProperties(D2D1::PixelFormat(DXGIFormat(srcSurf->GetFormat()), AlphaMode(srcSurf->GetFormat())));
+      mRT->CreateBitmap(D2D1::SizeU(UINT32(aSource.width), UINT32(aSource.height)), data, stride, props, byRef(bitmap));
+
+      srcRect.x -= (uint32_t)aSource.x;
+      srcRect.y -= (uint32_t)aSource.y;
+    }
+    break;
   }
- 
+
   rt->DrawBitmap(bitmap, D2DRect(aDest), aOptions.mAlpha, D2DFilter(aSurfOptions.mFilter), D2DRect(srcRect));
 
   FinalizeRTForOperation(aOptions.mCompositionOp, ColorPattern(Color()), aDest);
 }
 
 void
-DrawTargetD2D::MaskSurface(const Pattern &aSource,
-                           SourceSurface *aMask,
-                           Point aOffset,
-                           const DrawOptions &aOptions)
-{
-  RefPtr<ID2D1Bitmap> bitmap;
-
-  ID2D1RenderTarget *rt = GetRTForOperation(aOptions.mCompositionOp, ColorPattern(Color()));
-
-  PrepareForDrawing(rt);
-
-  // FillOpacityMask only works if the antialias mode is MODE_ALIASED
-  rt->SetAntialiasMode(D2D1_ANTIALIAS_MODE_ALIASED);
-
-  IntSize size = aMask->GetSize();
-  Rect maskRect = Rect(0.f, 0.f, size.width, size.height);
-  bitmap = GetBitmapForSurface(aMask, maskRect);
-  if (!bitmap) {
-       return;
-  }
-
-  Rect dest = Rect(aOffset.x, aOffset.y, size.width, size.height);
-  RefPtr<ID2D1Brush> brush = CreateBrushForPattern(aSource, aOptions.mAlpha);
-  rt->FillOpacityMask(bitmap, brush, D2D1_OPACITY_MASK_CONTENT_GRAPHICS, D2DRect(dest), D2DRect(maskRect));
-
-  FinalizeRTForOperation(aOptions.mCompositionOp, ColorPattern(Color()), dest);
-}
-
-void
 DrawTargetD2D::DrawSurfaceWithShadow(SourceSurface *aSurface,
                                      const Point &aDest,
                                      const Color &aColor,
                                      const Point &aOffset,
                                      Float aSigma,
                                      CompositionOp aOperator)
 {
   RefPtr<ID3D10ShaderResourceView> srView = nullptr;
--- a/gfx/2d/DrawTargetD2D.h
+++ b/gfx/2d/DrawTargetD2D.h
@@ -58,21 +58,16 @@ public:
                            const DrawOptions &aOptions = DrawOptions());
   virtual void DrawSurfaceWithShadow(SourceSurface *aSurface,
                                      const Point &aDest,
                                      const Color &aColor,
                                      const Point &aOffset,
                                      Float aSigma,
                                      CompositionOp aOperator);
   virtual void ClearRect(const Rect &aRect);
-  virtual void MaskSurface(const Pattern &aSource,
-                           SourceSurface *aMask,
-                           Point aOffset,
-                           const DrawOptions &aOptions = DrawOptions());
-
 
   virtual void CopySurface(SourceSurface *aSurface,
                            const IntRect &aSourceRect,
                            const IntPoint &aDestination);
 
   virtual void FillRect(const Rect &aRect,
                         const Pattern &aPattern,
                         const DrawOptions &aOptions = DrawOptions());
@@ -142,19 +137,16 @@ public:
     stream << "DrawTargetD2D(" << this << ")";
     return stream.str();
   }
 
   static uint64_t mVRAMUsageDT;
   static uint64_t mVRAMUsageSS;
 
 private:
-  TemporaryRef<ID2D1Bitmap>
-  DrawTargetD2D::GetBitmapForSurface(SourceSurface *aSurface,
-                                     Rect &aSource);
   friend class AutoSaveRestoreClippedOut;
   friend class SourceSurfaceD2DTarget;
 
 #ifdef _MSC_VER
   typedef stdext::hash_set<DrawTargetD2D*> TargetSet;
 #else
   typedef std::unordered_set<DrawTargetD2D*> TargetSet;
 #endif
--- a/gfx/thebes/gfxContext.cpp
+++ b/gfx/thebes/gfxContext.cpp
@@ -1392,16 +1392,17 @@ gfxContext::GetPattern()
       pat = new gfxPattern(ThebesRGBA(state.color));
     }
     return pat.forget();
   }
 }
 
 
 // masking
+
 void
 gfxContext::Mask(gfxPattern *pattern)
 {
   if (mCairo) {
     cairo_mask(mCairo, pattern->CairoPattern());
   } else {
     bool needsClip = false;
     if (pattern->Extend() == gfxPattern::EXTEND_NONE) {
@@ -1457,20 +1458,22 @@ gfxContext::Mask(gfxASurface *surface, c
   } else {
     // Lifetime needs to be limited here as we may simply wrap surface's data.
     RefPtr<SourceSurface> sourceSurf =
       gfxPlatform::GetPlatform()->GetSourceSurfaceForSurface(mDT, surface);
 
     gfxPoint pt = surface->GetDeviceOffset();
 
     // We clip here to bind to the mask surface bounds, see above.
-    mDT->MaskSurface(GeneralPattern(this), 
-              sourceSurf,
-              Point(offset.x - pt.x, offset.y -  pt.y),
+    mDT->PushClipRect(Rect(offset.x - pt.x, offset.y - pt.y, sourceSurf->GetSize().width, sourceSurf->GetSize().height));
+    mDT->Mask(GeneralPattern(this), 
+              SurfacePattern(sourceSurf, EXTEND_CLAMP,
+                             Matrix(1.0f, 0, 0, 1.0f, Float(offset.x - pt.x), Float(offset.y - pt.y))),
               DrawOptions(1.0f, CurrentState().op, CurrentState().aaMode));
+    mDT->PopClip();
   }
 }
 
 void
 gfxContext::Paint(gfxFloat alpha)
 {
   PROFILER_LABEL("gfxContext", "Paint");
   if (mCairo) {
--- a/layout/reftests/bugs/reftest.list
+++ b/layout/reftests/bugs/reftest.list
@@ -1711,17 +1711,17 @@ needs-focus == 731726-1.html 731726-1-re
 == 748692-1b.html 748692-1-ref.html
 skip-if(B2G) == 748803-1.html 748803-1-ref.html
 == 750551-1.html 750551-1-ref.html
 skip-if(B2G) == 751012-1a.html 751012-1-ref.html
 skip-if(B2G) == 751012-1b.html 751012-1-ref.html
 random-if(Android) == 753329-1.html about:blank
 == 758561-1.html 758561-1-ref.html
 fuzzy-if(true,1,19) fails-if(d2d) == 759036-1.html 759036-1-ref.html
-fuzzy-if(true,17,5860) == 759036-2.html 759036-2-ref.html
+fuzzy-if(true,17,5859) == 759036-2.html 759036-2-ref.html
 == 776265-1a.html 776265-1-ref.html
 == 776265-1b.html 776265-1-ref.html
 == 776265-1c.html 776265-1-ref.html
 == 776265-1d.html 776265-1-ref.html
 == 776265-2a.html 776265-2-ref.html
 == 776265-2b.html 776265-2-ref.html
 == 776265-2c.html 776265-2-ref.html
 == 776265-2d.html 776265-2-ref.html