Bug 1208283 (part 1) - Change gfxPattern's single-arg constructor to take a gfx::Color& instead of a gfxRGBA&. r=jwatt.
authorNicholas Nethercote <nnethercote@mozilla.com>
Thu, 24 Sep 2015 17:50:46 -0700
changeset 264678 8fbfb98cba6be8a8fe8db2d3432b02e989d87f5d
parent 264677 ac303706f7148c8cfd830d9bf3c4e7064641e00f
child 264679 daf573ce289f7aa25f390ecee71ff62ad216248a
push id29444
push usercbook@mozilla.com
push dateMon, 28 Sep 2015 12:17:21 +0000
treeherdermozilla-central@031db40e2b55 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjwatt
bugs1208283
milestone44.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 1208283 (part 1) - Change gfxPattern's single-arg constructor to take a gfx::Color& instead of a gfxRGBA&. r=jwatt.
gfx/thebes/gfxContext.cpp
gfx/thebes/gfxPattern.cpp
gfx/thebes/gfxPattern.h
gfx/thebes/gfxSVGGlyphs.cpp
gfx/thebes/gfxSVGGlyphs.h
layout/svg/SVGTextFrame.cpp
layout/svg/nsSVGGradientFrame.cpp
layout/svg/nsSVGPatternFrame.cpp
--- a/gfx/thebes/gfxContext.cpp
+++ b/gfx/thebes/gfxContext.cpp
@@ -767,17 +767,17 @@ gfxContext::GetPattern()
   nsRefPtr<gfxPattern> pat;
 
   AzureState &state = CurrentState();
   if (state.pattern) {
     pat = state.pattern;
   } else if (state.sourceSurface) {
     NS_ASSERTION(false, "Ugh, this isn't good.");
   } else {
-    pat = new gfxPattern(ThebesRGBA(state.color));
+    pat = new gfxPattern(state.color);
   }
   return pat.forget();
 }
 
 void
 gfxContext::SetFontSmoothingBackgroundColor(const Color& aColor)
 {
   CurrentState().fontSmoothingBackgroundColor = aColor;
--- a/gfx/thebes/gfxPattern.cpp
+++ b/gfx/thebes/gfxPattern.cpp
@@ -14,17 +14,17 @@
 #include "mozilla/gfx/2D.h"
 
 #include "cairo.h"
 
 #include <vector>
 
 using namespace mozilla::gfx;
 
-gfxPattern::gfxPattern(const gfxRGBA& aColor)
+gfxPattern::gfxPattern(const Color& aColor)
   : mExtend(EXTEND_NONE)
 {
   mGfxPattern.InitColorPattern(ToDeviceColor(aColor));
 }
 
 // linear
 gfxPattern::gfxPattern(gfxFloat x0, gfxFloat y0, gfxFloat x1, gfxFloat y1)
   : mExtend(EXTEND_NONE)
@@ -46,17 +46,17 @@ gfxPattern::gfxPattern(SourceSurface *aS
   : mPatternToUserSpace(aPatternToUserSpace)
   , mExtend(EXTEND_NONE)
 {
   mGfxPattern.InitSurfacePattern(aSurface, ToExtendMode(mExtend), Matrix(), // matrix is overridden in GetPattern()
                                  mozilla::gfx::Filter::GOOD);
 }
 
 void
-gfxPattern::AddColorStop(gfxFloat offset, const gfxRGBA& c)
+gfxPattern::AddColorStop(gfxFloat offset, const Color& c)
 {
   if (mGfxPattern.GetPattern()->GetType() != PatternType::LINEAR_GRADIENT &&
       mGfxPattern.GetPattern()->GetType() != PatternType::RADIAL_GRADIENT) {
     return;
   }
 
   mStops = nullptr;
 
--- a/gfx/thebes/gfxPattern.h
+++ b/gfx/thebes/gfxPattern.h
@@ -12,33 +12,32 @@
 #include "mozilla/Alignment.h"
 #include "mozilla/gfx/2D.h"
 #include "mozilla/gfx/PatternHelpers.h"
 #include "GraphicsFilter.h"
 #include "nsISupportsImpl.h"
 #include "nsAutoPtr.h"
 #include "nsTArray.h"
 
-struct gfxRGBA;
 typedef struct _cairo_pattern cairo_pattern_t;
 
 
 class gfxPattern final{
     NS_INLINE_DECL_REFCOUNTING(gfxPattern)
 
 public:
-    explicit gfxPattern(const gfxRGBA& aColor);
+    explicit gfxPattern(const mozilla::gfx::Color& aColor);
     // linear
     gfxPattern(gfxFloat x0, gfxFloat y0, gfxFloat x1, gfxFloat y1); // linear
     gfxPattern(gfxFloat cx0, gfxFloat cy0, gfxFloat radius0,
                gfxFloat cx1, gfxFloat cy1, gfxFloat radius1); // radial
     gfxPattern(mozilla::gfx::SourceSurface *aSurface,
                const mozilla::gfx::Matrix &aPatternToUserSpace);
 
-    void AddColorStop(gfxFloat offset, const gfxRGBA& c);
+    void AddColorStop(gfxFloat offset, const mozilla::gfx::Color& c);
     void SetColorStops(mozilla::gfx::GradientStops* aStops);
 
     // This should only be called on a cairo pattern that we want to use with
     // Azure. We will read back the color stops from cairo and try to look
     // them up in the cache.
     void CacheColorStops(const mozilla::gfx::DrawTarget *aDT);
 
     void SetMatrix(const gfxMatrix& matrix);
--- a/gfx/thebes/gfxSVGGlyphs.cpp
+++ b/gfx/thebes/gfxSVGGlyphs.cpp
@@ -35,17 +35,17 @@
 #define UTF8_CHARSET NS_LITERAL_CSTRING("utf-8")
 
 using namespace mozilla;
 
 typedef mozilla::dom::Element Element;
 
 mozilla::gfx::UserDataKey gfxTextContextPaint::sUserDataKey;
 
-const gfxRGBA SimpleTextContextPaint::sZero = gfxRGBA(0.0f, 0.0f, 0.0f, 0.0f);
+/* static */ const Color SimpleTextContextPaint::sZero = Color();
 
 gfxSVGGlyphs::gfxSVGGlyphs(hb_blob_t *aSVGTable, gfxFontEntry *aFontEntry)
     : mSVGData(aSVGTable)
     , mFontEntry(aFontEntry)
 {
     unsigned int length;
     const char* svgData = hb_blob_get_data(mSVGData, &length);
     mHeader = reinterpret_cast<const Header*>(svgData);
--- a/gfx/thebes/gfxSVGGlyphs.h
+++ b/gfx/thebes/gfxSVGGlyphs.h
@@ -224,17 +224,17 @@ private:
 
 /**
  * For passing in patterns where the text context has no separate pattern
  * opacity value.
  */
 class SimpleTextContextPaint : public gfxTextContextPaint
 {
 private:
-    static const gfxRGBA sZero;
+    static const mozilla::gfx::Color sZero;
 
 public:
     static gfxMatrix SetupDeviceToPatternMatrix(gfxPattern *aPattern,
                                                 const gfxMatrix& aCTM)
     {
         if (!aPattern) {
             return gfxMatrix();
         }
--- a/layout/svg/SVGTextFrame.cpp
+++ b/layout/svg/SVGTextFrame.cpp
@@ -3091,26 +3091,26 @@ SVGTextContextPaint::Paint::GetPattern(c
     // caller. We should get the same matrix each time a pattern is constructed
     // so this should be fine.
     pattern->SetMatrix(aCTM * mPatternMatrix);
     return pattern.forget();
   }
 
   switch (mPaintType) {
   case eStyleSVGPaintType_None:
-    pattern = new gfxPattern(gfxRGBA(0.0f, 0.0f, 0.0f, 0.0f));
+    pattern = new gfxPattern(Color());
     mPatternMatrix = gfxMatrix();
     break;
-  case eStyleSVGPaintType_Color:
-    pattern = new gfxPattern(gfxRGBA(NS_GET_R(mPaintDefinition.mColor) / 255.0,
-                                     NS_GET_G(mPaintDefinition.mColor) / 255.0,
-                                     NS_GET_B(mPaintDefinition.mColor) / 255.0,
-                                     NS_GET_A(mPaintDefinition.mColor) / 255.0 * aOpacity));
+  case eStyleSVGPaintType_Color: {
+    Color color = Color::FromABGR(mPaintDefinition.mColor);
+    color.a *= aOpacity;
+    pattern = new gfxPattern(color);
     mPatternMatrix = gfxMatrix();
     break;
+  }
   case eStyleSVGPaintType_Server:
     pattern = mPaintDefinition.mPaintServerFrame->GetPaintServerPattern(mFrame,
                                                                         aDrawTarget,
                                                                         mContextMatrix,
                                                                         aFillOrStroke,
                                                                         aOpacity);
     {
       // m maps original-user-space to pattern space
--- a/layout/svg/nsSVGGradientFrame.cpp
+++ b/layout/svg/nsSVGGradientFrame.cpp
@@ -15,16 +15,17 @@
 #include "nsSVGEffects.h"
 #include "nsSVGAnimatedTransformList.h"
 #include "gfxColor.h"
 
 // XXX Tight coupling with content classes ahead!
 
 using namespace mozilla;
 using namespace mozilla::dom;
+using namespace mozilla::gfx;
 
 //----------------------------------------------------------------------
 // Helper classes
 
 class MOZ_RAII nsSVGGradientFrame::AutoGradientReferencer
 {
 public:
   explicit AutoGradientReferencer(nsSVGGradientFrame *aFrame
@@ -230,32 +231,29 @@ nsSVGGradientFrame::GetPaintServerPatter
   nsAutoTArray<nsIFrame*,8> stopFrames;
   GetStopFrames(&stopFrames);
 
   uint32_t nStops = stopFrames.Length();
 
   // SVG specification says that no stops should be treated like
   // the corresponding fill or stroke had "none" specified.
   if (nStops == 0) {
-    nsRefPtr<gfxPattern> pattern = new gfxPattern(gfxRGBA(0, 0, 0, 0));
+    nsRefPtr<gfxPattern> pattern = new gfxPattern(Color());
     return pattern.forget();
   }
 
   if (nStops == 1 || GradientVectorLengthIsZero()) {
     // The gradient paints a single colour, using the stop-color of the last
     // gradient step if there are more than one.
     float stopOpacity = stopFrames[nStops-1]->StyleSVGReset()->mStopOpacity;
     nscolor stopColor = stopFrames[nStops-1]->StyleSVGReset()->mStopColor;
 
-    nsRefPtr<gfxPattern> pattern = new gfxPattern(
-                           gfxRGBA(NS_GET_R(stopColor)/255.0,
-                                   NS_GET_G(stopColor)/255.0,
-                                   NS_GET_B(stopColor)/255.0,
-                                   NS_GET_A(stopColor)/255.0 *
-                                     stopOpacity * aGraphicOpacity));
+    Color stopColor2 = Color::FromABGR(stopColor);
+    stopColor2.a *= stopOpacity * aGraphicOpacity;
+    nsRefPtr<gfxPattern> pattern = new gfxPattern(stopColor2);
     return pattern.forget();
   }
 
   // Get the transform list (if there is one). We do this after the returns
   // above since this call can be expensive when "gradientUnits" is set to
   // "objectBoundingBox" (since that requiring a GetBBox() call).
   gfxMatrix patternMatrix = GetGradientTransform(aSource, aOverrideBounds);
 
@@ -298,22 +296,19 @@ nsSVGGradientFrame::GetPaintServerPatter
 
     GetStopInformation(stopFrames[i], &offset, &stopColor, &stopOpacity);
 
     if (offset < lastOffset)
       offset = lastOffset;
     else
       lastOffset = offset;
 
-    gradient->AddColorStop(offset,
-                           gfxRGBA(NS_GET_R(stopColor)/255.0,
-                                   NS_GET_G(stopColor)/255.0,
-                                   NS_GET_B(stopColor)/255.0,
-                                   NS_GET_A(stopColor)/255.0 *
-                                     stopOpacity * aGraphicOpacity));
+    Color stopColor2 = Color::FromABGR(stopColor);
+    stopColor2.a *= stopOpacity * aGraphicOpacity;
+    gradient->AddColorStop(offset, stopColor2);
   }
 
   return gradient.forget();
 }
 
 // Private (helper) methods
 
 nsSVGGradientFrame *
--- a/layout/svg/nsSVGPatternFrame.cpp
+++ b/layout/svg/nsSVGPatternFrame.cpp
@@ -700,17 +700,17 @@ already_AddRefed<gfxPattern>
 nsSVGPatternFrame::GetPaintServerPattern(nsIFrame *aSource,
                                          const DrawTarget* aDrawTarget,
                                          const gfxMatrix& aContextMatrix,
                                          nsStyleSVGPaint nsStyleSVG::*aFillOrStroke,
                                          float aGraphicOpacity,
                                          const gfxRect *aOverrideBounds)
 {
   if (aGraphicOpacity == 0.0f) {
-    nsRefPtr<gfxPattern> pattern = new gfxPattern(gfxRGBA(0, 0, 0, 0));
+    nsRefPtr<gfxPattern> pattern = new gfxPattern(Color());
     return pattern.forget();
   }
 
   // Paint it!
   Matrix pMatrix;
   RefPtr<SourceSurface> surface =
     PaintPattern(aDrawTarget, &pMatrix, ToMatrix(aContextMatrix), aSource,
                  aFillOrStroke, aGraphicOpacity, aOverrideBounds);