Bug 910860: Use gfxPrefs to make sure preferences are evaluated on the main thread. This still leaves the preference re-evaluated all the time, not just at startup. Changing that is another bug. r=bgirard.

This commit is contained in:
Milan Sreckovic 2014-03-05 16:25:09 -05:00
parent 4de3678a20
commit 6cffe8ba37
3 changed files with 29 additions and 27 deletions

View File

@ -104,7 +104,10 @@ static qcms_transform *gCMSRGBATransform = nullptr;
static bool gCMSInitialized = false;
static eCMSMode gCMSMode = eCMSMode_Off;
static int gCMSIntent = -2;
static bool gCMSIntentInitialized = false;
static int gCMSIntent = QCMS_INTENT_DEFAULT;
static void ShutdownCMS();
@ -138,12 +141,7 @@ NS_IMPL_ISUPPORTS2(SRGBOverrideObserver, nsIObserver, nsISupportsWeakReference)
#define BIDI_NUMERAL_PREF "bidi.numeral"
#define GFX_PREF_CMS_RENDERING_INTENT "gfx.color_management.rendering_intent"
#define GFX_PREF_CMS_DISPLAY_PROFILE "gfx.color_management.display_profile"
#define GFX_PREF_CMS_ENABLED_OBSOLETE "gfx.color_management.enabled"
#define GFX_PREF_CMS_FORCE_SRGB "gfx.color_management.force_srgb"
#define GFX_PREF_CMS_ENABLEV4 "gfx.color_management.enablev4"
#define GFX_PREF_CMS_MODE "gfx.color_management.mode"
NS_IMETHODIMP
SRGBOverrideObserver::Observe(nsISupports *aSubject,
@ -1500,17 +1498,14 @@ gfxPlatform::GetCMSMode()
{
if (gCMSInitialized == false) {
gCMSInitialized = true;
nsresult rv;
int32_t mode;
rv = Preferences::GetInt(GFX_PREF_CMS_MODE, &mode);
if (NS_SUCCEEDED(rv) && (mode >= 0) && (mode < eCMSMode_AllCount)) {
int32_t mode = gfxPrefs::CMSMode();
if (mode >= 0 && mode < eCMSMode_AllCount) {
gCMSMode = static_cast<eCMSMode>(mode);
}
bool enableV4;
rv = Preferences::GetBool(GFX_PREF_CMS_ENABLEV4, &enableV4);
if (NS_SUCCEEDED(rv) && enableV4) {
bool enableV4 = gfxPrefs::CMSEnableV4();
if (enableV4) {
qcms_enable_iccv4();
}
}
@ -1520,23 +1515,22 @@ gfxPlatform::GetCMSMode()
int
gfxPlatform::GetRenderingIntent()
{
if (gCMSIntent == -2) {
if (!gCMSIntentInitialized) {
gCMSIntentInitialized = true;
// gfxPrefs.h is using 0 as the default for the rendering
// intent preference, based on that being the value for
// QCMS_INTENT_DEFAULT. Assert here to catch if that ever
// changes and we can then figure out what to do about it.
MOZ_ASSERT(QCMS_INTENT_DEFAULT == 0);
/* Try to query the pref system for a rendering intent. */
int32_t pIntent;
if (NS_SUCCEEDED(Preferences::GetInt(GFX_PREF_CMS_RENDERING_INTENT, &pIntent))) {
/* If the pref is within range, use it as an override. */
if ((pIntent >= QCMS_INTENT_MIN) && (pIntent <= QCMS_INTENT_MAX)) {
gCMSIntent = pIntent;
}
int32_t pIntent = gfxPrefs::CMSRenderingIntent();
if ((pIntent >= QCMS_INTENT_MIN) && (pIntent <= QCMS_INTENT_MAX)) {
gCMSIntent = pIntent;
} else {
/* If the pref is out of range, use embedded profile. */
else {
gCMSIntent = -1;
}
}
/* If we didn't get a valid intent from prefs, use the default. */
else {
gCMSIntent = QCMS_INTENT_DEFAULT;
gCMSIntent = -1;
}
}
return gCMSIntent;

View File

@ -118,6 +118,11 @@ private:
DECL_GFX_PREF(Once, "gfx.canvas.skiagl.cache-size", CanvasSkiaGLCacheSize, int32_t, 96);
DECL_GFX_PREF(Once, "gfx.canvas.skiagl.cache-items", CanvasSkiaGLCacheItems, int32_t, 256);
DECL_GFX_PREF(Live, "gfx.color_management.enablev4", CMSEnableV4, bool, false);
DECL_GFX_PREF(Live, "gfx.color_management.mode", CMSMode, int32_t,-1);
// The zero default here should match QCMS_INTENT_DEFAULT from qcms.h
DECL_GFX_PREF(Live, "gfx.color_management.rendering_intent", CMSRenderingIntent, int32_t, 0);
DECL_GFX_PREF(Once, "gfx.direct2d.disabled", Direct2DDisabled, bool, false);
DECL_GFX_PREF(Once, "gfx.direct2d.force-enabled", Direct2DForceEnabled, bool, false);
DECL_GFX_PREF(Live, "gfx.gralloc.fence-with-readpixels", GrallocFenceWithReadPixels, bool, false);

View File

@ -23,6 +23,7 @@
#include "nsIScriptSecurityManager.h"
#include "ImageFactory.h"
#include "gfxPrefs.h"
namespace mozilla {
namespace image {
@ -38,6 +39,8 @@ ImageFactory::Initialize()
{
MOZ_ASSERT(NS_IsMainThread());
if (!gInitializedPrefCaches) {
// Initialize the graphics preferences
gfxPrefs::GetSingleton();
Preferences::AddBoolVarCache(&gDiscardable, "image.mem.discardable");
Preferences::AddBoolVarCache(&gDecodeOnDraw, "image.mem.decodeondraw");
Preferences::AddBoolVarCache(&gEnableMozSampleSize, "image.mozsamplesize.enabled");