Bug 1520877 - Part 2: Implement FillRoundedRect for D2D. r=mattwoodrow
authorBas Schouten <bschouten@mozilla.com>
Thu, 17 Jan 2019 20:29:43 +0100
changeset 514507 1d614d0ffdc104414c18c108c6c75c93dbd459c4
parent 514506 5ab4532b7850be80c87121325321774c7bcb1d3e
child 514508 e3ef1e27eb9222d2215c91b9209291c75eaeb4df
push id1953
push userffxbld-merge
push dateMon, 11 Mar 2019 12:10:20 +0000
treeherdermozilla-release@9c35dcbaa899 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmattwoodrow
bugs1520877
milestone66.0a1
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
Bug 1520877 - Part 2: Implement FillRoundedRect for D2D. r=mattwoodrow Differential Revision: https://phabricator.services.mozilla.com/D16893
gfx/2d/DrawTargetD2D1.cpp
gfx/2d/DrawTargetD2D1.h
gfx/2d/HelpersD2D.h
--- a/gfx/2d/DrawTargetD2D1.cpp
+++ b/gfx/2d/DrawTargetD2D1.cpp
@@ -546,16 +546,32 @@ void DrawTargetD2D1::FillRect(const Rect
   mDC->SetAntialiasMode(D2DAAMode(aOptions.mAntialiasMode));
 
   RefPtr<ID2D1Brush> brush = CreateBrushForPattern(aPattern, aOptions.mAlpha);
   mDC->FillRectangle(D2DRect(aRect), brush);
 
   FinalizeDrawing(aOptions.mCompositionOp, aPattern);
 }
 
+void DrawTargetD2D1::FillRoundedRect(const RoundedRect &aRect,
+                                     const Pattern &aPattern,
+                                     const DrawOptions &aOptions) {
+  if (!aRect.corners.AreRadiiSame()) {
+    return DrawTarget::FillRoundedRect(aRect, aPattern, aOptions);
+  }
+  PrepareForDrawing(aOptions.mCompositionOp, aPattern);
+
+  mDC->SetAntialiasMode(D2DAAMode(aOptions.mAntialiasMode));
+
+  RefPtr<ID2D1Brush> brush = CreateBrushForPattern(aPattern, aOptions.mAlpha);
+  mDC->FillRoundedRectangle(D2DRoundedRect(aRect), brush);
+
+  FinalizeDrawing(aOptions.mCompositionOp, aPattern);
+}
+
 void DrawTargetD2D1::StrokeRect(const Rect &aRect, const Pattern &aPattern,
                                 const StrokeOptions &aStrokeOptions,
                                 const DrawOptions &aOptions) {
   PrepareForDrawing(aOptions.mCompositionOp, aPattern);
 
   mDC->SetAntialiasMode(D2DAAMode(aOptions.mAntialiasMode));
 
   RefPtr<ID2D1Brush> brush = CreateBrushForPattern(aPattern, aOptions.mAlpha);
--- a/gfx/2d/DrawTargetD2D1.h
+++ b/gfx/2d/DrawTargetD2D1.h
@@ -62,16 +62,20 @@ class DrawTargetD2D1 : public DrawTarget
       const Pattern &aSource, SourceSurface *aMask, Point aOffset,
       const DrawOptions &aOptions = DrawOptions()) override;
 
   virtual void CopySurface(SourceSurface *aSurface, const IntRect &aSourceRect,
                            const IntPoint &aDestination) override;
 
   virtual void FillRect(const Rect &aRect, const Pattern &aPattern,
                         const DrawOptions &aOptions = DrawOptions()) override;
+  virtual void FillRoundedRect(
+      const RoundedRect &aRect, const Pattern &aPattern,
+      const DrawOptions &aOptions = DrawOptions()) override;
+
   virtual void StrokeRect(const Rect &aRect, const Pattern &aPattern,
                           const StrokeOptions &aStrokeOptions = StrokeOptions(),
                           const DrawOptions &aOptions = DrawOptions()) override;
   virtual void StrokeLine(const Point &aStart, const Point &aEnd,
                           const Pattern &aPattern,
                           const StrokeOptions &aStrokeOptions = StrokeOptions(),
                           const DrawOptions &aOptions = DrawOptions()) override;
   virtual void Stroke(const Path *aPath, const Pattern &aPattern,
--- a/gfx/2d/HelpersD2D.h
+++ b/gfx/2d/HelpersD2D.h
@@ -35,16 +35,22 @@ static inline D2D1_SIZE_U D2DIntSize(con
   return D2D1::SizeU(aSize.width, aSize.height);
 }
 
 template <typename T>
 static inline D2D1_RECT_F D2DRect(const T &aRect) {
   return D2D1::RectF(aRect.X(), aRect.Y(), aRect.XMost(), aRect.YMost());
 }
 
+static inline D2D1_ROUNDED_RECT D2DRoundedRect(const RoundedRect &aRect) {
+  return D2D1::RoundedRect(D2DRect(aRect.rect),
+                           aRect.corners.BottomLeft().width,
+                           aRect.corners.BottomLeft().height);
+}
+
 static inline D2D1_EXTEND_MODE D2DExtend(ExtendMode aExtendMode, Axis aAxis) {
   D2D1_EXTEND_MODE extend;
   switch (aExtendMode) {
     case ExtendMode::REPEAT:
       extend = D2D1_EXTEND_MODE_WRAP;
       break;
     case ExtendMode::REPEAT_X: {
       extend = aAxis == Axis::X_AXIS ? D2D1_EXTEND_MODE_WRAP