Bug 1678487 - Make CMSMode an enum class. r=aosmond

Differential Revision: https://phabricator.services.mozilla.com/D104945
This commit is contained in:
Emilio Cobos Álvarez 2021-02-13 02:15:22 +00:00
Родитель 47b903f8b3
Коммит ba4d1a3c68
15 изменённых файлов: 37 добавлений и 35 удалений

Просмотреть файл

@ -177,7 +177,7 @@ static qcms_transform* gCMSRGBATransform = nullptr;
static qcms_transform* gCMSBGRATransform = nullptr; static qcms_transform* gCMSBGRATransform = nullptr;
static bool gCMSInitialized = false; static bool gCMSInitialized = false;
static eCMSMode gCMSMode = eCMSMode_Off; static CMSMode gCMSMode = CMSMode::Off;
static void ShutdownCMS(); static void ShutdownCMS();
@ -2021,11 +2021,11 @@ bool gfxPlatform::OffMainThreadCompositingEnabled() {
return UsesOffMainThreadCompositing(); return UsesOffMainThreadCompositing();
} }
eCMSMode gfxPlatform::GetCMSMode() { CMSMode gfxPlatform::GetCMSMode() {
if (!gCMSInitialized) { if (!gCMSInitialized) {
int32_t mode = StaticPrefs::gfx_color_management_mode(); int32_t mode = StaticPrefs::gfx_color_management_mode();
if (mode >= 0 && mode < eCMSMode_AllCount) { if (mode >= 0 && mode < int32_t(CMSMode::AllCount)) {
gCMSMode = static_cast<eCMSMode>(mode); gCMSMode = CMSMode(mode);
} }
bool enableV4 = StaticPrefs::gfx_color_management_enablev4(); bool enableV4 = StaticPrefs::gfx_color_management_enablev4();
@ -2037,7 +2037,7 @@ eCMSMode gfxPlatform::GetCMSMode() {
return gCMSMode; return gCMSMode;
} }
void gfxPlatform::SetCMSModeOverride(eCMSMode aMode) { void gfxPlatform::SetCMSModeOverride(CMSMode aMode) {
MOZ_ASSERT(gCMSInitialized); MOZ_ASSERT(gCMSInitialized);
gCMSMode = aMode; gCMSMode = aMode;
} }
@ -2283,7 +2283,7 @@ static void ShutdownCMS() {
} }
// Reset the state variables // Reset the state variables
gCMSMode = eCMSMode_Off; gCMSMode = CMSMode::Off;
gCMSInitialized = false; gCMSInitialized = false;
} }

Просмотреть файл

@ -74,11 +74,11 @@ class SystemFontListEntry;
} \ } \
} while (0) } while (0)
enum eCMSMode { enum class CMSMode : int32_t {
eCMSMode_Off = 0, // No color management Off = 0, // No color management
eCMSMode_All = 1, // Color manage everything All = 1, // Color manage everything
eCMSMode_TaggedOnly = 2, // Color manage tagged Images Only TaggedOnly = 2, // Color manage tagged Images Only
eCMSMode_AllCount = 3 AllCount = 3
}; };
enum eGfxLog { enum eGfxLog {
@ -530,12 +530,12 @@ class gfxPlatform : public mozilla::layers::MemoryPressureListener {
/** /**
* Are we going to try color management? * Are we going to try color management?
*/ */
static eCMSMode GetCMSMode(); static CMSMode GetCMSMode();
/** /**
* Used only for testing. Override the pref setting. * Used only for testing. Override the pref setting.
*/ */
static void SetCMSModeOverride(eCMSMode aMode); static void SetCMSModeOverride(CMSMode aMode);
/** /**
* Determines the rendering intent for color management. * Determines the rendering intent for color management.

Просмотреть файл

@ -1464,7 +1464,7 @@ DeviceColor ToDeviceColor(const sRGBColor& aColor) {
// need to return the same object from all return points in this function. 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 // could declare a local Color variable and use that, but we might as well
// just use aColor. // just use aColor.
if (gfxPlatform::GetCMSMode() == eCMSMode_All) { if (gfxPlatform::GetCMSMode() == CMSMode::All) {
qcms_transform* transform = gfxPlatform::GetCMSRGBTransform(); qcms_transform* transform = gfxPlatform::GetCMSRGBTransform();
if (transform) { if (transform) {
return gfxPlatform::TransformPixel(aColor, transform); return gfxPlatform::TransformPixel(aColor, transform);

Просмотреть файл

@ -318,10 +318,10 @@ struct StyleRGBA;
namespace gfx { namespace gfx {
/** /**
* If the CMS mode is eCMSMode_All, these functions transform the passed * If the CMS mode is CMSMode::All, these functions transform the passed
* color to a device color using the transform returened by gfxPlatform:: * color to a device color using the transform returned by
* GetCMSRGBTransform(). If the CMS mode is some other value, the color is * gfxPlatform::GetCMSRGBTransform(). If the CMS mode is some other value, the
* returned unchanged (other than a type change to Moz2D Color, if * color is returned unchanged (other than a type change to Moz2D Color, if
* applicable). * applicable).
*/ */
DeviceColor ToDeviceColor(const sRGBColor& aColor); DeviceColor ToDeviceColor(const sRGBColor& aColor);

Просмотреть файл

@ -95,7 +95,7 @@ void Decoder::SetSurfaceFlags(SurfaceFlags aSurfaceFlags) {
MOZ_ASSERT(!mInitialized); MOZ_ASSERT(!mInitialized);
mSurfaceFlags = aSurfaceFlags; mSurfaceFlags = aSurfaceFlags;
if (mSurfaceFlags & SurfaceFlags::NO_COLORSPACE_CONVERSION) { if (mSurfaceFlags & SurfaceFlags::NO_COLORSPACE_CONVERSION) {
mCMSMode = eCMSMode_Off; mCMSMode = CMSMode::Off;
} }
} }

Просмотреть файл

@ -20,6 +20,8 @@
#include "SurfaceFlags.h" #include "SurfaceFlags.h"
#include "qcms.h" #include "qcms.h"
enum class CMSMode : int32_t;
namespace mozilla { namespace mozilla {
namespace Telemetry { namespace Telemetry {
@ -567,7 +569,7 @@ class Decoder {
uint8_t* mImageData; // Pointer to image data in BGRA/X uint8_t* mImageData; // Pointer to image data in BGRA/X
uint32_t mImageDataLength; uint32_t mImageDataLength;
uint32_t mCMSMode; CMSMode mCMSMode;
private: private:
RefPtr<RasterImage> mImage; RefPtr<RasterImage> mImage;

Просмотреть файл

@ -717,7 +717,7 @@ LexerTransition<nsBMPDecoder::State> nsBMPDecoder::ReadBitfields(
mBytesPerColor = (mH.mBIHSize == InfoHeaderLength::WIN_V2) ? 3 : 4; mBytesPerColor = (mH.mBIHSize == InfoHeaderLength::WIN_V2) ? 3 : 4;
} }
if (mCMSMode != eCMSMode_Off) { if (mCMSMode != CMSMode::Off) {
switch (mH.mCsType) { switch (mH.mCsType) {
case InfoColorSpace::EMBEDDED: case InfoColorSpace::EMBEDDED:
return SeekColorProfile(aLength); return SeekColorProfile(aLength);

Просмотреть файл

@ -410,7 +410,7 @@ void nsGIFDecoder2::ConvertColormap(uint32_t* aColormap, uint32_t aColors) {
} }
// Apply CMS transformation if enabled and available // Apply CMS transformation if enabled and available
if (mCMSMode == eCMSMode_All) { if (mCMSMode == CMSMode::All) {
qcms_transform* transform = GetCMSsRGBTransform(SurfaceFormat::R8G8B8); qcms_transform* transform = GetCMSsRGBTransform(SurfaceFormat::R8G8B8);
if (transform) { if (transform) {
qcms_transform_data(transform, aColormap, aColormap, aColors); qcms_transform_data(transform, aColormap, aColormap, aColors);

Просмотреть файл

@ -58,7 +58,7 @@ LexerTransition<nsIconDecoder::State> nsIconDecoder::ReadHeader(
// premultiplied, so we can't support the surface flags with icons right now. // premultiplied, so we can't support the surface flags with icons right now.
SurfacePipeFlags pipeFlags = SurfacePipeFlags(); SurfacePipeFlags pipeFlags = SurfacePipeFlags();
if (transform) { if (transform) {
if (mCMSMode == eCMSMode_All) { if (mCMSMode == CMSMode::All) {
mTransform = GetCMSsRGBTransform(format); mTransform = GetCMSsRGBTransform(format);
} }

Просмотреть файл

@ -283,7 +283,7 @@ LexerTransition<nsJPEGDecoder::State> nsJPEGDecoder::ReadJPEGData(
return Transition::TerminateFailure(); return Transition::TerminateFailure();
} }
if (mCMSMode != eCMSMode_Off) { if (mCMSMode != CMSMode::Off) {
if ((mInProfile = GetICCProfile(mInfo)) != nullptr && if ((mInProfile = GetICCProfile(mInfo)) != nullptr &&
GetCMSOutputProfile()) { GetCMSOutputProfile()) {
uint32_t profileSpace = qcms_profile_get_color_space(mInProfile); uint32_t profileSpace = qcms_profile_get_color_space(mInProfile);
@ -326,7 +326,7 @@ LexerTransition<nsJPEGDecoder::State> nsJPEGDecoder::ReadJPEGData(
GetCMSOutputProfile(), GetCMSOutputProfile(),
outputType, (qcms_intent)intent); outputType, (qcms_intent)intent);
} }
} else if (mCMSMode == eCMSMode_All) { } else if (mCMSMode == CMSMode::All) {
mTransform = GetCMSsRGBTransform(SurfaceFormat::OS_RGBX); mTransform = GetCMSsRGBTransform(SurfaceFormat::OS_RGBX);
} }
} }

Просмотреть файл

@ -308,7 +308,7 @@ nsresult nsPNGDecoder::InitInternal() {
#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
// Ignore unused chunks // Ignore unused chunks
if (mCMSMode == eCMSMode_Off || IsMetadataDecode()) { if (mCMSMode == CMSMode::Off || IsMetadataDecode()) {
png_set_keep_unknown_chunks(mPNG, 1, color_chunks, 2); png_set_keep_unknown_chunks(mPNG, 1, color_chunks, 2);
} }
@ -584,7 +584,7 @@ void nsPNGDecoder::info_callback(png_structp png_ptr, png_infop info_ptr) {
uint32_t intent = -1; uint32_t intent = -1;
bool sRGBTag = false; bool sRGBTag = false;
if (!decoder->IsMetadataDecode()) { if (!decoder->IsMetadataDecode()) {
if (decoder->mCMSMode != eCMSMode_Off) { if (decoder->mCMSMode != CMSMode::Off) {
intent = gfxPlatform::GetRenderingIntent(); intent = gfxPlatform::GetRenderingIntent();
uint32_t pIntent = uint32_t pIntent =
decoder->ReadColorProfile(png_ptr, info_ptr, color_type, &sRGBTag); decoder->ReadColorProfile(png_ptr, info_ptr, color_type, &sRGBTag);
@ -597,7 +597,7 @@ void nsPNGDecoder::info_callback(png_structp png_ptr, png_infop info_ptr) {
png_set_gray_to_rgb(png_ptr); png_set_gray_to_rgb(png_ptr);
// only do gamma correction if CMS isn't entirely disabled // only do gamma correction if CMS isn't entirely disabled
if (decoder->mCMSMode != eCMSMode_Off) { if (decoder->mCMSMode != CMSMode::Off) {
PNGDoGammaCorrection(png_ptr, info_ptr); PNGDoGammaCorrection(png_ptr, info_ptr);
} }
} }
@ -685,8 +685,8 @@ void nsPNGDecoder::info_callback(png_structp png_ptr, png_infop info_ptr) {
decoder->mTransform = qcms_transform_create(decoder->mInProfile, inType, decoder->mTransform = qcms_transform_create(decoder->mInProfile, inType,
decoder->GetCMSOutputProfile(), decoder->GetCMSOutputProfile(),
outType, (qcms_intent)intent); outType, (qcms_intent)intent);
} else if ((sRGBTag && decoder->mCMSMode == eCMSMode_TaggedOnly) || } else if ((sRGBTag && decoder->mCMSMode == CMSMode::TaggedOnly) ||
decoder->mCMSMode == eCMSMode_All) { decoder->mCMSMode == CMSMode::All) {
// If the transform happens with SurfacePipe, it will be in RGBA if we // If the transform happens with SurfacePipe, it will be in RGBA if we
// have an alpha channel, because the swizzle and premultiplication // have an alpha channel, because the swizzle and premultiplication
// happens after color management. Otherwise it will be in OS_RGBA because // happens after color management. Otherwise it will be in OS_RGBA because

Просмотреть файл

@ -299,8 +299,8 @@ void nsWebPDecoder::ApplyColorProfile(const char* aProfile, size_t aLength) {
MOZ_ASSERT(!mGotColorProfile); MOZ_ASSERT(!mGotColorProfile);
mGotColorProfile = true; mGotColorProfile = true;
if (mCMSMode == eCMSMode_Off || !GetCMSOutputProfile() || if (mCMSMode == CMSMode::Off || !GetCMSOutputProfile() ||
(mCMSMode == eCMSMode_TaggedOnly && !aProfile)) { (mCMSMode == CMSMode::TaggedOnly && !aProfile)) {
return; return;
} }

Просмотреть файл

@ -56,7 +56,7 @@ AutoInitializeImageLib::AutoInitializeImageLib() {
// Ensure we always color manage images with gtests. // Ensure we always color manage images with gtests.
gfxPlatform::GetCMSMode(); gfxPlatform::GetCMSMode();
gfxPlatform::SetCMSModeOverride(eCMSMode_All); gfxPlatform::SetCMSModeOverride(CMSMode::All);
// Depending on initialization order, it is possible that our pref changes // Depending on initialization order, it is possible that our pref changes
// have not taken effect yet because there are pending gfx-related events on // have not taken effect yet because there are pending gfx-related events on

Просмотреть файл

@ -4156,7 +4156,7 @@
mirror: always mirror: always
# 0 = Off, 1 = Full, 2 = Tagged Images Only. # 0 = Off, 1 = Full, 2 = Tagged Images Only.
# See eCMSMode in gfx/thebes/gfxPlatform.h. # See CMSMode in gfx/thebes/gfxPlatform.h.
- name: gfx.color_management.mode - name: gfx.color_management.mode
type: RelaxedAtomicInt32 type: RelaxedAtomicInt32
value: 2 value: 2

Просмотреть файл

@ -828,7 +828,7 @@ nsresult nsXPLookAndFeel::GetColorValue(ColorID aID,
// the traversal. // the traversal.
if (!mozilla::ServoStyleSet::IsInServoTraversal()) { if (!mozilla::ServoStyleSet::IsInServoTraversal()) {
MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(NS_IsMainThread());
if (gfxPlatform::GetCMSMode() == eCMSMode_All && if (gfxPlatform::GetCMSMode() == CMSMode::All &&
!IsSpecialColor(aID, aResult)) { !IsSpecialColor(aID, aResult)) {
qcms_transform* transform = gfxPlatform::GetCMSInverseRGBTransform(); qcms_transform* transform = gfxPlatform::GetCMSInverseRGBTransform();
if (transform) { if (transform) {