Bug 1074194 - Factor out gfxContext::SetColor()'s color management conversion into a gfxPlatform helper. r=Bas
authorJonathan Watt <jwatt@jwatt.org>
Fri, 03 Oct 2014 09:50:42 +0100
changeset 208550 0ffdd0092d9b617c33d3cfeb661c863baa5112b7
parent 208549 01bbf35c82bdc31c7fe4bf129fe8a8e421f68cef
child 208551 70d8b88af2a6fd10e2c8e0eb240dc5685a152b88
push idunknown
push userunknown
push dateunknown
reviewersBas
bugs1074194
milestone35.0a1
Bug 1074194 - Factor out gfxContext::SetColor()'s color management conversion into a gfxPlatform helper. r=Bas
gfx/thebes/gfxContext.cpp
gfx/thebes/gfxPlatform.cpp
gfx/thebes/gfxPlatform.h
--- a/gfx/thebes/gfxContext.cpp
+++ b/gfx/thebes/gfxContext.cpp
@@ -851,30 +851,17 @@ gfxContext::ClipContainsRect(const gfxRe
 // rendering sources
 
 void
 gfxContext::SetColor(const gfxRGBA& c)
 {
   CurrentState().pattern = nullptr;
   CurrentState().sourceSurfCairo = nullptr;
   CurrentState().sourceSurface = nullptr;
-
-  if (gfxPlatform::GetCMSMode() == eCMSMode_All) {
-
-      gfxRGBA cms;
-      qcms_transform *transform = gfxPlatform::GetCMSRGBTransform();
-      if (transform)
-        gfxPlatform::TransformPixel(c, cms, transform);
-
-      // Use the original alpha to avoid unnecessary float->byte->float
-      // conversion errors
-      CurrentState().color = ToColor(cms);
-  }
-  else
-      CurrentState().color = ToColor(c);
+  CurrentState().color = gfxPlatform::MaybeTransformColor(c);
 }
 
 void
 gfxContext::SetDeviceColor(const gfxRGBA& c)
 {
   CurrentState().pattern = nullptr;
   CurrentState().sourceSurfCairo = nullptr;
   CurrentState().sourceSurface = nullptr;
--- a/gfx/thebes/gfxPlatform.cpp
+++ b/gfx/thebes/gfxPlatform.cpp
@@ -1626,16 +1626,36 @@ gfxPlatform::TransformPixel(const gfxRGB
         new (&out) gfxRGBA(packed, gfxRGBA::PACKED_ARGB);
 #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
@@ -2,16 +2,17 @@
  * 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/. */
 
 #ifndef GFX_PLATFORM_H
 #define GFX_PLATFORM_H
 
 #include "prlog.h"
+#include "mozilla/gfx/Types.h"
 #include "nsTArray.h"
 #include "nsString.h"
 #include "nsCOMPtr.h"
 #include "nsAutoPtr.h"
 
 #include "gfxPrefs.h"
 #include "gfxTypes.h"
 #include "gfxFontFamilyList.h"
@@ -153,16 +154,17 @@ GetBackendName(mozilla::gfx::BackendType
       case mozilla::gfx::BackendType::NONE:
         return "none";
   }
   MOZ_CRASH("Incomplete switch");
 }
 
 class gfxPlatform {
 public:
+    typedef mozilla::gfx::Color Color;
     typedef mozilla::gfx::DataSourceSurface DataSourceSurface;
     typedef mozilla::gfx::DrawTarget DrawTarget;
     typedef mozilla::gfx::IntSize IntSize;
     typedef mozilla::gfx::SourceSurface SourceSurface;
 
     /**
      * Return a pointer to the current active platform.
      * This is a singleton; it contains mostly convenience
@@ -489,16 +491,22 @@ public:
     /**
      * 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);
+
+    /**
      * Return the output device ICC profile.
      */
     static qcms_profile* GetCMSOutputProfile();
 
     /**
      * Return the sRGB ICC profile.
      */
     static qcms_profile* GetCMSsRGBProfile();