Bug 1084093, part 2 - Convert gfxPlatform::TransformPixel to Moz2D, and move gfxPlatform::MaybeTransformColor to ToDeviceColor in gfxUtils.h. r=Bas
authorJonathan Watt <jwatt@jwatt.org>
Fri, 17 Oct 2014 12:53:15 +0100
changeset 211024 6d94aa5503e5b59595991819d5bc61d0522fc185
parent 211023 cb91f5ec6b44aa9e54ea3420af04eaecdf451046
child 211025 8714fdc213ca6bed614ee7981e1fe9f83e7cb67a
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewersBas
bugs1084093
milestone36.0a1
Bug 1084093, part 2 - Convert gfxPlatform::TransformPixel to Moz2D, and move gfxPlatform::MaybeTransformColor to ToDeviceColor in gfxUtils.h. r=Bas
gfx/thebes/gfxContext.cpp
gfx/thebes/gfxPattern.cpp
gfx/thebes/gfxPlatform.cpp
gfx/thebes/gfxPlatform.h
gfx/thebes/gfxUtils.cpp
gfx/thebes/gfxUtils.h
--- a/gfx/thebes/gfxContext.cpp
+++ b/gfx/thebes/gfxContext.cpp
@@ -822,17 +822,17 @@ gfxContext::ClipContainsRect(const gfxRe
 // rendering sources
 
 void
 gfxContext::SetColor(const gfxRGBA& c)
 {
   CurrentState().pattern = nullptr;
   CurrentState().sourceSurfCairo = nullptr;
   CurrentState().sourceSurface = nullptr;
-  CurrentState().color = gfxPlatform::MaybeTransformColor(c);
+  CurrentState().color = ToDeviceColor(c);
 }
 
 void
 gfxContext::SetDeviceColor(const gfxRGBA& c)
 {
   CurrentState().pattern = nullptr;
   CurrentState().sourceSurfCairo = nullptr;
   CurrentState().sourceSurface = nullptr;
--- a/gfx/thebes/gfxPattern.cpp
+++ b/gfx/thebes/gfxPattern.cpp
@@ -1,15 +1,17 @@
 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  * This Source Code Form is subject to the terms of the Mozilla Public
  * 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 "gfxPattern.h"
+
+#include "gfxUtils.h"
 #include "gfxTypes.h"
-#include "gfxPattern.h"
 #include "gfxASurface.h"
 #include "gfxPlatform.h"
 #include "gfx2DGlue.h"
 #include "gfxGradientCache.h"
 #include "mozilla/gfx/2D.h"
 
 #include "cairo.h"
 
@@ -52,27 +54,20 @@ void
 gfxPattern::AddColorStop(gfxFloat offset, const gfxRGBA& c)
 {
   if (mGfxPattern.GetPattern()->GetType() != PatternType::LINEAR_GRADIENT &&
       mGfxPattern.GetPattern()->GetType() != PatternType::RADIAL_GRADIENT) {
     return;
   }
 
   mStops = nullptr;
-  gfxRGBA color = c;
-  if (gfxPlatform::GetCMSMode() == eCMSMode_All) {
-    qcms_transform *transform = gfxPlatform::GetCMSRGBTransform();
-    if (transform) {
-      gfxPlatform::TransformPixel(color, color, transform);
-    }
-  }
 
   GradientStop stop;
   stop.offset = offset;
-  stop.color = ToColor(color);
+  stop.color = ToDeviceColor(c);
   mStopsList.AppendElement(stop);
 }
 
 void
 gfxPattern::SetColorStops(GradientStops* aStops)
 {
   mStops = aStops;
 }
--- a/gfx/thebes/gfxPlatform.cpp
+++ b/gfx/thebes/gfxPlatform.cpp
@@ -1596,65 +1596,43 @@ gfxPlatform::GetRenderingIntent()
             /* If the pref is out of range, use embedded profile. */
             gCMSIntent = -1;
         }
     }
     return gCMSIntent;
 }
 
 void
-gfxPlatform::TransformPixel(const gfxRGBA& in, gfxRGBA& out, qcms_transform *transform)
+gfxPlatform::TransformPixel(const Color& in, Color& out, qcms_transform *transform)
 {
 
     if (transform) {
         /* we want the bytes in RGB order */
 #ifdef IS_LITTLE_ENDIAN
         /* ABGR puts the bytes in |RGBA| order on little endian */
-        uint32_t packed = in.Packed(gfxRGBA::PACKED_ABGR);
+        uint32_t packed = in.ToABGR();
         qcms_transform_data(transform,
                        (uint8_t *)&packed, (uint8_t *)&packed,
                        1);
-        out.~gfxRGBA();
-        new (&out) gfxRGBA(packed, gfxRGBA::PACKED_ABGR);
+        out = Color::FromABGR(packed);
 #else
         /* ARGB puts the bytes in |ARGB| order on big endian */
-        uint32_t packed = in.Packed(gfxRGBA::PACKED_ARGB);
+        uint32_t packed = in.ToARGB();
         /* add one to move past the alpha byte */
         qcms_transform_data(transform,
                        (uint8_t *)&packed + 1, (uint8_t *)&packed + 1,
                        1);
-        out.~gfxRGBA();
-        new (&out) gfxRGBA(packed, gfxRGBA::PACKED_ARGB);
+        out = Color::FromARGB(packed);
 #endif
     }
 
     else if (&out != &in)
         out = in;
 }
 
-Color
-gfxPlatform::MaybeTransformColor(const gfxRGBA& aColor)
-{
-    // We only return this object to get some return value optimization goodness:
-    Color color;
-    if (GetCMSMode() == eCMSMode_All) {
-        gfxRGBA cms;
-        qcms_transform *transform = GetCMSRGBTransform();
-        if (transform) {
-            TransformPixel(aColor, cms, transform);
-            // Use the original alpha to avoid unnecessary float->byte->float
-            // conversion errors
-            color = ToColor(cms);
-            return color;
-        }
-    }
-    color = ToColor(aColor);
-    return color;
-}
-
 void
 gfxPlatform::GetPlatformCMSOutputProfile(void *&mem, size_t &size)
 {
     mem = nullptr;
     size = 0;
 }
 
 void
--- a/gfx/thebes/gfxPlatform.h
+++ b/gfx/thebes/gfxPlatform.h
@@ -488,23 +488,17 @@ public:
      */
     static int GetRenderingIntent();
 
     /**
      * Convert a pixel using a cms transform in an endian-aware manner.
      *
      * Sets 'out' to 'in' if transform is nullptr.
      */
-    static void TransformPixel(const gfxRGBA& in, gfxRGBA& out, qcms_transform *transform);
-
-    /**
-     * Converts the color using the GetCMSRGBTransform() transform if the
-     * CMS mode is eCMSMode_All, else just returns the color.
-     */
-    static Color MaybeTransformColor(const gfxRGBA& aColor);
+    static void TransformPixel(const Color& in, Color& out, qcms_transform *transform);
 
     /**
      * Return the output device ICC profile.
      */
     static qcms_profile* GetCMSOutputProfile();
 
     /**
      * Return the sRGB ICC profile.
--- a/gfx/thebes/gfxUtils.cpp
+++ b/gfx/thebes/gfxUtils.cpp
@@ -1344,8 +1344,41 @@ static bool sDumpPaintList = getenv("MOZ
 gfxUtils::DumpPaintList() {
   return sDumpPaintList || gfxPrefs::LayoutDumpDisplayList();
 }
 
 bool gfxUtils::sDumpPainting = getenv("MOZ_DUMP_PAINT") != 0;
 bool gfxUtils::sDumpPaintingToFile = getenv("MOZ_DUMP_PAINT_TO_FILE") != 0;
 FILE *gfxUtils::sDumpPaintFile = nullptr;
 #endif
+
+namespace mozilla {
+namespace gfx {
+
+Color ToDeviceColor(Color aColor)
+{
+  // aColor is pass-by-value since to get return value optimization goodness we
+  // need to return the same object from all return points in this function. We
+  // could declare a local Color variable and use that, but we might as well
+  // just use aColor.
+  if (gfxPlatform::GetCMSMode() == eCMSMode_All) {
+    qcms_transform *transform = gfxPlatform::GetCMSRGBTransform();
+    if (transform) {
+      gfxPlatform::TransformPixel(aColor, aColor, transform);
+      // Use the original alpha to avoid unnecessary float->byte->float
+      // conversion errors
+    }
+  }
+  return aColor;
+}
+
+Color ToDeviceColor(nscolor aColor)
+{
+  return ToDeviceColor(Color::FromABGR(aColor));
+}
+
+Color ToDeviceColor(const gfxRGBA& aColor)
+{
+  return ToDeviceColor(ToColor(aColor));
+}
+
+} // namespace gfx
+} // namespace mozilla
--- a/gfx/thebes/gfxUtils.h
+++ b/gfx/thebes/gfxUtils.h
@@ -7,16 +7,17 @@
 #define GFX_UTILS_H
 
 #include "gfxColor.h"
 #include "gfxTypes.h"
 #include "GraphicsFilter.h"
 #include "imgIContainer.h"
 #include "mozilla/gfx/2D.h"
 #include "mozilla/RefPtr.h"
+#include "nsColor.h"
 #include "nsPrintfCString.h"
 
 class gfxASurface;
 class gfxDrawable;
 class nsIntRegion;
 class nsIPresShell;
 
 struct nsIntRect;
@@ -304,16 +305,26 @@ public:
     static bool sDumpPaintingToFile;
     static FILE* sDumpPaintFile;
 #endif
 };
 
 namespace mozilla {
 namespace gfx {
 
+/**
+ * If the CMS mode is eCMSMode_All, these functions transform the passed
+ * color to a device color using the transform returened by gfxPlatform::
+ * GetCMSRGBTransform().  If the CMS mode is some other value, the color is
+ * returned unchanged (other than a type change to Moz2D Color, if
+ * applicable).
+ */
+Color ToDeviceColor(Color aColor);
+Color ToDeviceColor(nscolor aColor);
+Color ToDeviceColor(const gfxRGBA& aColor);
 
 /* These techniques are suggested by "Bit Twiddling Hacks"
  */
 
 /**
  * Returns true if |aNumber| is a power of two
  * 0 is incorreclty considered a power of two
  */