From 3790732f9ae2e86955f105d8b63b52b3bf677264 Mon Sep 17 00:00:00 2001 From: Jonathan Watt Date: Fri, 3 Oct 2014 09:50:42 +0100 Subject: [PATCH] Bug 1074194 - Factor out gfxContext::SetColor()'s color management conversion into a gfxPlatform helper. r=Bas --- gfx/thebes/gfxContext.cpp | 15 +-------------- gfx/thebes/gfxPlatform.cpp | 20 ++++++++++++++++++++ gfx/thebes/gfxPlatform.h | 8 ++++++++ 3 files changed, 29 insertions(+), 14 deletions(-) diff --git a/gfx/thebes/gfxContext.cpp b/gfx/thebes/gfxContext.cpp index acc580f93b99..0670d124ae17 100644 --- a/gfx/thebes/gfxContext.cpp +++ b/gfx/thebes/gfxContext.cpp @@ -856,20 +856,7 @@ 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 diff --git a/gfx/thebes/gfxPlatform.cpp b/gfx/thebes/gfxPlatform.cpp index 60951c7c372f..0d078c0eadd0 100644 --- a/gfx/thebes/gfxPlatform.cpp +++ b/gfx/thebes/gfxPlatform.cpp @@ -1631,6 +1631,26 @@ gfxPlatform::TransformPixel(const gfxRGBA& in, gfxRGBA& out, qcms_transform *tra 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) { diff --git a/gfx/thebes/gfxPlatform.h b/gfx/thebes/gfxPlatform.h index c65751647929..1cf83e96140a 100644 --- a/gfx/thebes/gfxPlatform.h +++ b/gfx/thebes/gfxPlatform.h @@ -7,6 +7,7 @@ #define GFX_PLATFORM_H #include "prlog.h" +#include "mozilla/gfx/Types.h" #include "nsTArray.h" #include "nsString.h" #include "nsCOMPtr.h" @@ -158,6 +159,7 @@ GetBackendName(mozilla::gfx::BackendType aBackend) class gfxPlatform { public: + typedef mozilla::gfx::Color Color; typedef mozilla::gfx::DataSourceSurface DataSourceSurface; typedef mozilla::gfx::DrawTarget DrawTarget; typedef mozilla::gfx::IntSize IntSize; @@ -493,6 +495,12 @@ public: */ 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. */