Bug 663036 part.3 gfx should use mozilla::Preferences r=roc+joe

This commit is contained in:
Masayuki Nakano 2011-06-12 11:30:16 +09:00
parent 59142e247a
commit e06d6eb819
26 changed files with 227 additions and 454 deletions

View File

@ -41,7 +41,6 @@
#include "nsIServiceManager.h"
#include "nsIConsoleService.h"
#include "nsPrintfCString.h"
#include "nsIPrefService.h"
#include "Nv3DVUtils.h"
#include "plstr.h"

View File

@ -46,9 +46,8 @@
#include "gfxWindowsPlatform.h"
#include "nsIGfxInfo.h"
#include "nsServiceManagerUtils.h"
#include "nsIPrefService.h"
#include "nsIPrefBranch2.h"
#include "gfxFailure.h"
#include "mozilla/Preferences.h"
#include "gfxCrashReporterUtils.h"
@ -75,15 +74,9 @@ LayerManagerD3D9::Initialize()
{
ScopedGfxFeatureReporter reporter("D3D9 Layers");
nsCOMPtr<nsIPrefBranch2> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
/* XXX: this preference and blacklist code should move out of the layer manager */
PRBool forceAccelerate = PR_FALSE;
if (prefs) {
// we should use Preferences::AddBoolVarCache
prefs->GetBoolPref("layers.acceleration.force-enabled",
&forceAccelerate);
}
PRBool forceAccelerate =
Preferences::GetBool("layers.acceleration.force-enabled", PR_FALSE);
nsCOMPtr<nsIGfxInfo> gfxInfo = do_GetService("@mozilla.org/gfx/info;1");
if (gfxInfo) {

View File

@ -57,8 +57,6 @@
#include "nsIServiceManager.h"
#include "nsIConsoleService.h"
#include "nsIPrefService.h"
#include "nsIPrefBranch2.h"
#include "gfxCrashReporterUtils.h"

View File

@ -45,11 +45,11 @@
#include "nsIWidget.h"
#include "mozilla/Services.h"
#include "mozilla/Preferences.h"
#include "nsIServiceManager.h"
#include "nsILanguageAtomService.h"
#include "nsIObserver.h"
#include "nsIObserverService.h"
#include "nsIPrefService.h"
#include "gfxImageSurface.h"
@ -84,6 +84,7 @@ static nsSystemFontsAndroid *gSystemFonts = nsnull;
#error Need to declare gSystemFonts!
#endif
using namespace mozilla;
using mozilla::services::GetObserverService;
class nsFontCache : public nsIObserver
@ -368,19 +369,11 @@ nsDeviceContext::SetDPI()
mAppUnitsPerDevNotScaledPixel =
NS_lround((AppUnitsPerCSSPixel() * 96) / dpi);
} else {
nsCOMPtr<nsIPrefBranch> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
// A value of -1 means use the maximum of 96 and the system DPI.
// A value of 0 means use the system DPI. A positive value is used as the DPI.
// This sets the physical size of a device pixel and thus controls the
// interpretation of physical units.
PRInt32 prefDPI = -1;
if (prefs) {
nsresult rv = prefs->GetIntPref("layout.css.dpi", &prefDPI);
if (NS_FAILED(rv)) {
prefDPI = -1;
}
}
PRInt32 prefDPI = Preferences::GetInt("layout.css.dpi", -1);
if (prefDPI > 0) {
dpi = prefDPI;
@ -399,12 +392,9 @@ nsDeviceContext::SetDPI()
// controls the size of a CSS "px".
float devPixelsPerCSSPixel = -1.0;
if (prefs) {
nsXPIDLCString prefString;
nsresult rv = prefs->GetCharPref("layout.css.devPixelsPerPx", getter_Copies(prefString));
if (NS_SUCCEEDED(rv) && !prefString.IsEmpty()) {
devPixelsPerCSSPixel = static_cast<float>(atof(prefString));
}
nsAdoptingCString prefString = Preferences::GetCString("layout.css.devPixelsPerPx");
if (!prefString.IsEmpty()) {
devPixelsPerCSSPixel = static_cast<float>(atof(prefString));
}
if (devPixelsPerCSSPixel <= 0) {

View File

@ -40,9 +40,7 @@
#include "nsString.h"
#include "nsDependentString.h"
#include "nsServiceManagerUtils.h"
#include "nsIPrefService.h"
#include "nsIPrefBranch.h"
#include "mozilla/Preferences.h"
#include "gfxContext.h"
#include "gfxFont.h"
@ -59,6 +57,8 @@
#include "gtk/gtk.h"
#endif
using namespace mozilla;
enum {
S_UTF8 = 0,
S_ASCII = 1
@ -358,21 +358,7 @@ main (int argc, char **argv) {
if (0) {
nsresult rv;
nsCOMPtr<nsIPrefService> prefsvc = do_GetService(NS_PREFSERVICE_CONTRACTID);
if (!prefsvc) {
printf ("Pref svc get failed!\n");
}
nsCOMPtr<nsIPrefBranch> branch;
rv = prefsvc->GetBranch(nsnull, getter_AddRefs(branch));
if (NS_FAILED(rv))
printf ("Failed 0x%08x\n", rv);
nsXPIDLCString str;
rv = branch->GetCharPref("font.name.sans-serif.x-western", getter_Copies(str));
if (NS_FAILED(rv))
printf ("Failed[2] 0x%08x\n", rv);
nsAdoptingCString str = Preferences::GetCString("font.name.sans-serif.x-western");
printf ("sans-serif.x-western: %s\n", nsPromiseFlatCString(str).get());
}

View File

@ -42,10 +42,6 @@
#include "prinrval.h"
#include "nsServiceManagerUtils.h"
#include "nsIPrefService.h"
#include "nsIPrefBranch.h"
#include "gfxContext.h"
#include "gfxFont.h"
#include "gfxPlatform.h"

View File

@ -42,10 +42,6 @@
#include "prinrval.h"
#include "nsServiceManagerUtils.h"
#include "nsIPrefService.h"
#include "nsIPrefBranch.h"
#include "gfxContext.h"
#include "gfxFont.h"
#include "gfxPlatform.h"

View File

@ -78,8 +78,7 @@ typedef void *EGLNativeWindowType;
#elif defined(XP_WIN)
#include "nsServiceManagerUtils.h"
#include "nsIPrefBranch.h"
#include "mozilla/Preferences.h"
#include "nsILocalFile.h"
#ifndef WIN32_LEAN_AND_MEAN
@ -318,14 +317,10 @@ public:
// Allow for explicitly specifying the location of libEGL.dll and
// libGLESv2.dll.
do {
nsCOMPtr<nsIPrefBranch> prefs = do_GetService("@mozilla.org/preferences-service;1");
nsCOMPtr<nsILocalFile> eglFile, glesv2File;
if (!prefs)
break;
nsresult rv = prefs->GetComplexValue("gfx.angle.egl.path",
NS_GET_IID(nsILocalFile),
getter_AddRefs(eglFile));
nsresult rv = Preferences::GetComplex("gfx.angle.egl.path",
NS_GET_IID(nsILocalFile),
getter_AddRefs(eglFile));
if (NS_FAILED(rv) || !eglFile)
break;

View File

@ -43,7 +43,7 @@
#include "nsDirectoryServiceUtils.h"
#include "nsAppDirectoryServiceDefs.h"
#include "nsIConsoleService.h"
#include "nsIPrefService.h"
#include "mozilla/Preferences.h"
#include "gfxASurface.h"
#include "gfxImageSurface.h"
@ -106,22 +106,8 @@ OSMesaLibrary::EnsureInitialized()
if (mInitialized)
return PR_TRUE;
nsresult rv;
nsCOMPtr<nsIPrefService> prefService = do_GetService(NS_PREFSERVICE_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, PR_FALSE);
nsCOMPtr<nsIPrefBranch> prefBranch;
rv = prefService->GetBranch("webgl.", getter_AddRefs(prefBranch));
NS_ENSURE_SUCCESS(rv, PR_FALSE);
nsCString osmesalib;
rv = prefBranch->GetCharPref("osmesalib", getter_Copies(osmesalib));
if (NS_FAILED(rv) ||
osmesalib.Length() == 0)
{
nsAdoptingCString osmesalib = Preferences::GetCString("webgl.osmesalib");
if (osmesalib.IsEmpty()) {
return PR_FALSE;
}

View File

@ -40,7 +40,6 @@
// Mozilla includes
#include "nscore.h"
#include "nsIPrefService.h"
#include "nsIServiceManager.h"
#include "nsCOMPtr.h"
#include "nsAutoPtr.h"

View File

@ -42,10 +42,9 @@
#include "gfxDWriteFonts.h"
#include "nsUnicharUtils.h"
#include "nsILocaleService.h"
#include "nsIPrefService.h"
#include "nsIPrefBranch2.h"
#include "nsServiceManagerUtils.h"
#include "nsCharSeparatedTokenizer.h"
#include "mozilla/Preferences.h"
#include "gfxGDIFontList.h"
@ -696,15 +695,7 @@ gfxDWriteFontList::InitFontList()
fc->AgeAllGenerations();
}
nsCOMPtr<nsIPrefBranch2> pref = do_GetService(NS_PREFSERVICE_CONTRACTID);
nsresult rv;
rv = pref->GetBoolPref(
"gfx.font_rendering.directwrite.use_gdi_table_loading",
&mGDIFontTableAccess);
if (NS_FAILED(rv)) {
mGDIFontTableAccess = PR_FALSE;
}
mGDIFontTableAccess = Preferences::GetBool("gfx.font_rendering.directwrite.use_gdi_table_loading", PR_FALSE);
gfxPlatformFontList::InitFontList();
@ -953,12 +944,9 @@ gfxDWriteFontList::DelayedInitFontList()
}
}
nsCOMPtr<nsIPrefBranch2> pref = do_GetService(NS_PREFSERVICE_CONTRACTID);
nsXPIDLCString classicFamilies;
nsresult rv = pref->GetCharPref(
"gfx.font_rendering.cleartype_params.force_gdi_classic_for_families",
getter_Copies(classicFamilies));
if (NS_SUCCEEDED(rv)) {
nsAdoptingCString classicFamilies =
Preferences::GetCString("gfx.font_rendering.cleartype_params.force_gdi_classic_for_families");
if (classicFamilies) {
nsCCharSeparatedTokenizer tokenizer(classicFamilies, ',');
while (tokenizer.hasMoreTokens()) {
NS_ConvertUTF8toUTF16 name(tokenizer.nextToken());
@ -969,12 +957,9 @@ gfxDWriteFontList::DelayedInitFontList()
}
}
}
PRInt32 forceGDIClassicMaxFontSize = 0;
rv = pref->GetIntPref("gfx.font_rendering.cleartype_params.force_gdi_classic_max_size",
&forceGDIClassicMaxFontSize);
if (NS_SUCCEEDED(rv)) {
mForceGDIClassicMaxFontSize = forceGDIClassicMaxFontSize;
}
mForceGDIClassicMaxFontSize =
Preferences::GetInt("gfx.font_rendering.cleartype_params.force_gdi_classic_max_size",
mForceGDIClassicMaxFontSize);
StartLoader(kDelayBeforeLoadingFonts, kIntervalBetweenLoadingFonts);

View File

@ -67,13 +67,15 @@
#include "gfxAtoms.h"
#include "nsTArray.h"
#include "nsUnicodeRange.h"
#include "nsIPrefService.h"
#include "nsIPrefLocalizedString.h"
#include "nsServiceManagerUtils.h"
#include "nsCRT.h"
#include "prlog.h"
#include "prinit.h"
#include "mozilla/Preferences.h"
using namespace mozilla;
static PRLogModuleInfo *gFontLog = PR_NewLogModule("ft2fonts");
static const char *sCJKLangGroup[] = {
@ -510,25 +512,9 @@ void gfxFT2FontGroup::GetCJKPrefFonts(nsTArray<nsRefPtr<gfxFontEntry> >& aFontEn
key.AppendInt(mStyle.weight);
if (!platform->GetPrefFontEntries(key, &aFontEntryList)) {
nsCOMPtr<nsIPrefService> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
if (!prefs)
return;
nsCOMPtr<nsIPrefBranch> prefBranch;
prefs->GetBranch(0, getter_AddRefs(prefBranch));
if (!prefBranch)
return;
NS_ENSURE_TRUE(Preferences::GetRootBranch(), );
// Add the CJK pref fonts from accept languages, the order should be same order
nsCAutoString list;
nsCOMPtr<nsIPrefLocalizedString> val;
nsresult rv = prefBranch->GetComplexValue("intl.accept_languages", NS_GET_IID(nsIPrefLocalizedString),
getter_AddRefs(val));
if (NS_SUCCEEDED(rv) && val) {
nsAutoString temp;
val->ToString(getter_Copies(temp));
LossyCopyUTF16toASCII(temp, list);
}
nsAdoptingCString list = Preferences::GetLocalizedCString("intl.accept_languages");
if (!list.IsEmpty()) {
const char kComma = ',';
const char *p, *p_end;

View File

@ -43,7 +43,6 @@
#endif
#include "prlog.h"
#include "nsIPrefService.h"
#include "nsServiceManagerUtils.h"
#include "nsReadableUtils.h"
#include "nsExpirationTracker.h"
@ -66,6 +65,7 @@
#include "nsUnicodeRange.h"
#include "nsCompressedCharMap.h"
#include "nsStyleConsts.h"
#include "mozilla/Preferences.h"
#include "cairo.h"
#include "gfxFontTest.h"
@ -2178,8 +2178,6 @@ gfxFontGroup::ForEachFontInternal(const nsAString& aFamilies,
}
groupAtom->ToUTF8String(groupString);
nsCOMPtr<nsIPrefBranch> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
nsPromiseFlatString families(aFamilies);
const PRUnichar *p, *p_end;
families.BeginReading(p);
@ -2187,7 +2185,6 @@ gfxFontGroup::ForEachFontInternal(const nsAString& aFamilies,
nsAutoString family;
nsCAutoString lcFamily;
nsAutoString genericFamily;
nsXPIDLCString value;
while (p < p_end) {
while (nsCRT::IsAsciiSpace(*p) || *p == kComma)
@ -2239,12 +2236,10 @@ gfxFontGroup::ForEachFontInternal(const nsAString& aFamilies,
prefName.AppendLiteral(".");
prefName.Append(groupString);
// prefs file always uses (must use) UTF-8 so that we can use
// |GetCharPref| and treat the result as a UTF-8 string.
nsresult rv = prefs->GetCharPref(prefName.get(), getter_Copies(value));
if (NS_SUCCEEDED(rv)) {
nsAdoptingString value = Preferences::GetString(prefName.get());
if (value) {
CopyASCIItoUTF16(lcFamily, genericFamily);
CopyUTF8toUTF16(value, family);
family = value;
}
} else {
generic = PR_FALSE;
@ -2293,10 +2288,9 @@ gfxFontGroup::ForEachFontInternal(const nsAString& aFamilies,
prefName.Append(lcFamily);
prefName.AppendLiteral(".");
prefName.Append(groupString);
nsresult rv = prefs->GetCharPref(prefName.get(), getter_Copies(value));
if (NS_SUCCEEDED(rv)) {
ForEachFontInternal(NS_ConvertUTF8toUTF16(value),
groupAtom, PR_FALSE, aResolveFontName,
nsAdoptingString value = Preferences::GetString(prefName.get());
if (value) {
ForEachFontInternal(value, groupAtom, PR_FALSE, aResolveFontName,
fc, closure);
}
}

View File

@ -41,10 +41,8 @@
#include "nsServiceManagerUtils.h"
#include "nsIPrefBranch.h"
#include "nsIPrefService.h"
#include "nsIPrefLocalizedString.h"
#include "nsISupportsPrimitives.h"
#include "mozilla/Preferences.h"
#include "nsIStreamBufferAccess.h"
#include "nsIUUIDGenerator.h"
#include "nsMemory.h"
@ -862,17 +860,11 @@ void gfxFontUtils::GetPrefsFontList(const char *aPrefName, nsTArray<nsString>& a
aFontList.Clear();
// get the list of single-face font families
nsCOMPtr<nsIPrefBranch> prefs(do_GetService(NS_PREFSERVICE_CONTRACTID));
nsAutoString fontlistValue;
if (prefs) {
nsCOMPtr<nsISupportsString> prefString;
prefs->GetComplexValue(aPrefName, NS_GET_IID(nsISupportsString), getter_AddRefs(prefString));
if (!prefString)
return;
prefString->GetData(fontlistValue);
nsAdoptingString fontlistValue = Preferences::GetString(aPrefName);
if (!fontlistValue) {
return;
}
// append each font name to the list
nsAutoString fontname;
nsPromiseFlatString fonts(fontlistValue);

View File

@ -44,15 +44,16 @@
#include <locale.h>
#include <fontconfig/fontconfig.h>
#include "nsIPrefBranch.h"
#include "nsIPrefService.h"
#include "nsServiceManagerUtils.h"
#include "nsILanguageAtomService.h"
#include "nsTArray.h"
#include "mozilla/Preferences.h"
#include "nsIAtom.h"
#include "nsCRT.h"
using namespace mozilla;
/* static */ gfxFontconfigUtils* gfxFontconfigUtils::sUtils = nsnull;
static nsILanguageAtomService* gLangService = nsnull;
@ -587,17 +588,8 @@ gfxFontconfigUtils::UpdateFontListInternal(PRBool aForce)
// fontconfig converts the non existing font to sans-serif.
// This is not good if the web page specifies font-family
// that has Windows font name in the first.
nsCOMPtr<nsIPrefService> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
if (!prefs)
return NS_ERROR_FAILURE;
nsCOMPtr<nsIPrefBranch> prefBranch;
prefs->GetBranch(0, getter_AddRefs(prefBranch));
if (!prefBranch)
return NS_ERROR_FAILURE;
nsXPIDLCString list;
prefBranch->GetCharPref("font.alias-list", getter_Copies(list));
NS_ENSURE_TRUE(Preferences::GetRootBranch(), NS_ERROR_FAILURE);
nsAdoptingCString list = Preferences::GetCString("font.alias-list");
if (!list.IsEmpty()) {
const char kComma = ',';

View File

@ -47,10 +47,11 @@
#include "nsTArray.h"
#include "gfxAtoms.h"
#include "nsIServiceManager.h"
#include "nsIPlatformCharset.h"
#include "nsIPrefBranch.h"
#include "nsIPrefService.h"
#include "mozilla/Preferences.h"
using namespace mozilla;
/**********************************************************************
* class gfxOS2Font
@ -68,18 +69,14 @@ gfxOS2Font::gfxOS2Font(gfxOS2FontEntry *aFontEntry, const gfxFontStyle *aFontSty
NS_LossyConvertUTF16toASCII(aFontEntry->Name()).get());
#endif
// try to get the preferences for hinting, antialias, and embolden options
nsCOMPtr<nsIPrefBranch> prefbranch = do_GetService(NS_PREFSERVICE_CONTRACTID);
if (prefbranch) {
int value;
nsresult rv = prefbranch->GetIntPref("gfx.os2.font.hinting", &value);
if (NS_SUCCEEDED(rv) && value >= FC_HINT_NONE && value <= FC_HINT_FULL)
mHinting = value;
PRBool enabled;
rv = prefbranch->GetBoolPref("gfx.os2.font.antialiasing", &enabled);
if (NS_SUCCEEDED(rv))
mAntialias = enabled;
PRInt32 value;
nsresult rv = Preferences::GetInt("gfx.os2.font.hinting", &value);
if (NS_SUCCEEDED(rv) && value >= FC_HINT_NONE && value <= FC_HINT_FULL) {
mHinting = value;
}
mAntialias = Preferences::GetBool("gfx.os2.font.antialiasing", mAntialias);
#ifdef DEBUG_thebes_2
printf(" font display options: hinting=%d, antialiasing=%s\n",
mHinting, mAntialias ? "on" : "off");

View File

@ -79,18 +79,17 @@
#include "qcms.h"
#include "plstr.h"
#include "nsIPrefService.h"
#include "nsIPrefBranch.h"
#include "nsIPrefBranch2.h"
#include "nsIPrefLocalizedString.h"
#include "nsCRT.h"
#include "GLContext.h"
#include "GLContextProvider.h"
#include "mozilla/FunctionTimer.h"
#include "mozilla/Preferences.h"
#include "nsIGfxInfo.h"
using namespace mozilla;
gfxPlatform *gPlatform = nsnull;
static bool gEverInitialized = false;
@ -154,6 +153,12 @@ SRGBOverrideObserver::Observe(nsISupports *aSubject,
#define GFX_PREF_HARFBUZZ_SCRIPTS "gfx.font_rendering.harfbuzz.scripts"
#define HARFBUZZ_SCRIPTS_DEFAULT gfxUnicodeProperties::SHAPING_DEFAULT
static const char* kObservedPrefs[] = {
"gfx.downloadable_fonts.",
"gfx.font_rendering.",
nsnull
};
class FontPrefsObserver : public nsIObserver
{
public:
@ -168,14 +173,12 @@ FontPrefsObserver::Observe(nsISupports *aSubject,
const char *aTopic,
const PRUnichar *someData)
{
nsCOMPtr<nsIPrefBranch> branch = do_QueryInterface(aSubject);
if (!branch || someData == nsnull) {
if (!someData) {
NS_ERROR("font pref observer code broken");
return NS_ERROR_UNEXPECTED;
}
gfxPlatform::GetPlatform()->FontsPrefsChanged(branch,
NS_ConvertUTF16toUTF8(someData).get());
NS_ASSERTION(gfxPlatform::GetPlatform(), "the singleton instance has gone");
gfxPlatform::GetPlatform()->FontsPrefsChanged(NS_ConvertUTF16toUTF8(someData).get());
return NS_OK;
}
@ -315,15 +318,11 @@ gfxPlatform::Init()
MigratePrefs();
/* Create and register our CMS Override observer. */
gPlatform->overrideObserver = new SRGBOverrideObserver();
FontPrefsObserver *fontPrefObserver = new FontPrefsObserver();
gPlatform->mSRGBOverrideObserver = new SRGBOverrideObserver();
Preferences::AddWeakObserver(gPlatform->mSRGBOverrideObserver, CMForceSRGBPrefName);
nsCOMPtr<nsIPrefBranch2> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
if (prefs) {
prefs->AddObserver(CMForceSRGBPrefName, gPlatform->overrideObserver, PR_TRUE);
prefs->AddObserver("gfx.downloadable_fonts.", fontPrefObserver, PR_FALSE);
prefs->AddObserver("gfx.font_rendering.", fontPrefObserver, PR_FALSE);
}
gPlatform->mFontPrefsObserver = new FontPrefsObserver();
Preferences::AddStrongObservers(gPlatform->mFontPrefsObserver, kObservedPrefs);
// Force registration of the gfx component, thus arranging for
// ::Shutdown to be called.
@ -347,10 +346,18 @@ gfxPlatform::Shutdown()
// Free the various non-null transforms and loaded profiles
ShutdownCMS();
/* Unregister our CMS Override callback. */
nsCOMPtr<nsIPrefBranch2> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
if (prefs)
prefs->RemoveObserver(CMForceSRGBPrefName, gPlatform->overrideObserver);
// In some cases, gPlatform may not be created but Shutdown() called,
// e.g., during xpcshell tests.
if (gPlatform) {
/* Unregister our CMS Override callback. */
NS_ASSERTION(gPlatform->mSRGBOverrideObserver, "mSRGBOverrideObserver has alreay gone");
Preferences::RemoveObserver(gPlatform->mSRGBOverrideObserver, CMForceSRGBPrefName);
gPlatform->mSRGBOverrideObserver = nsnull;
NS_ASSERTION(gPlatform->mFontPrefsObserver, "mFontPrefsObserver has alreay gone");
Preferences::RemoveObservers(gPlatform->mFontPrefsObserver, kObservedPrefs);
gPlatform->mFontPrefsObserver = nsnull;
}
mozilla::gl::GLContextProvider::Shutdown();
@ -419,26 +426,12 @@ gfxPlatform::UpdateFontList()
return NS_ERROR_NOT_IMPLEMENTED;
}
PRBool
gfxPlatform::GetBoolPref(const char *aPref, PRBool aDefault)
{
nsCOMPtr<nsIPrefBranch> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
if (prefs) {
PRBool allow;
nsresult rv = prefs->GetBoolPref(aPref, &allow);
if (NS_SUCCEEDED(rv))
return allow;
}
return aDefault;
}
PRBool
gfxPlatform::DownloadableFontsEnabled()
{
if (mAllowDownloadableFonts == UNINITIALIZED_VALUE) {
mAllowDownloadableFonts =
GetBoolPref(GFX_DOWNLOADABLE_FONTS_ENABLED, PR_FALSE);
Preferences::GetBool(GFX_DOWNLOADABLE_FONTS_ENABLED, PR_FALSE);
}
return mAllowDownloadableFonts;
@ -449,7 +442,7 @@ gfxPlatform::SanitizeDownloadedFonts()
{
if (mDownloadableFontsSanitize == UNINITIALIZED_VALUE) {
mDownloadableFontsSanitize =
GetBoolPref(GFX_DOWNLOADABLE_FONTS_SANITIZE, PR_TRUE);
Preferences::GetBool(GFX_DOWNLOADABLE_FONTS_SANITIZE, PR_TRUE);
}
return mDownloadableFontsSanitize;
@ -459,15 +452,7 @@ PRBool
gfxPlatform::UseHarfBuzzForScript(PRInt32 aScriptCode)
{
if (mUseHarfBuzzScripts == UNINITIALIZED_VALUE) {
mUseHarfBuzzScripts = HARFBUZZ_SCRIPTS_DEFAULT;
nsCOMPtr<nsIPrefBranch2> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
if (prefs) {
PRInt32 scripts;
nsresult rv = prefs->GetIntPref(GFX_PREF_HARFBUZZ_SCRIPTS, &scripts);
if (NS_SUCCEEDED(rv)) {
mUseHarfBuzzScripts = scripts;
}
}
mUseHarfBuzzScripts = Preferences::GetInt(GFX_PREF_HARFBUZZ_SCRIPTS, HARFBUZZ_SCRIPTS_DEFAULT);
}
PRInt32 shapingType = gfxUnicodeProperties::ScriptShapingType(aScriptCode);
@ -494,14 +479,9 @@ gfxPlatform::MakePlatformFont(const gfxProxyFontEntry *aProxyEntry,
static void
AppendGenericFontFromPref(nsString& aFonts, nsIAtom *aLangGroup, const char *aGenericName)
{
nsresult rv;
nsCOMPtr<nsIPrefBranch> prefs(do_GetService(NS_PREFSERVICE_CONTRACTID));
if (!prefs)
return;
NS_ENSURE_TRUE(Preferences::GetRootBranch(), );
nsCAutoString prefName, langGroupString;
nsXPIDLCString nameValue, nameListValue;
aLangGroup->ToUTF8String(langGroupString);
@ -511,7 +491,7 @@ AppendGenericFontFromPref(nsString& aFonts, nsIAtom *aLangGroup, const char *aGe
} else {
prefName.AssignLiteral("font.default.");
prefName.Append(langGroupString);
prefs->GetCharPref(prefName.get(), getter_Copies(genericDotLang));
genericDotLang = Preferences::GetCString(prefName.get());
}
genericDotLang.AppendLiteral(".");
@ -520,21 +500,21 @@ AppendGenericFontFromPref(nsString& aFonts, nsIAtom *aLangGroup, const char *aGe
// fetch font.name.xxx value
prefName.AssignLiteral("font.name.");
prefName.Append(genericDotLang);
rv = prefs->GetCharPref(prefName.get(), getter_Copies(nameValue));
if (NS_SUCCEEDED(rv)) {
nsAdoptingString nameValue = Preferences::GetString(prefName.get());
if (nameValue) {
if (!aFonts.IsEmpty())
aFonts.AppendLiteral(", ");
aFonts.Append(NS_ConvertUTF8toUTF16(nameValue));
aFonts += nameValue;
}
// fetch font.name-list.xxx value
prefName.AssignLiteral("font.name-list.");
prefName.Append(genericDotLang);
rv = prefs->GetCharPref(prefName.get(), getter_Copies(nameListValue));
if (NS_SUCCEEDED(rv) && !nameListValue.Equals(nameValue)) {
nsAdoptingString nameListValue = Preferences::GetString(prefName.get());
if (nameListValue && !nameListValue.Equals(nameValue)) {
if (!aFonts.IsEmpty())
aFonts.AppendLiteral(", ");
aFonts.Append(NS_ConvertUTF8toUTF16(nameListValue));
aFonts += nameListValue;
}
}
@ -551,25 +531,18 @@ gfxPlatform::GetPrefFonts(nsIAtom *aLanguage, nsString& aFonts, PRBool aAppendUn
PRBool gfxPlatform::ForEachPrefFont(eFontPrefLang aLangArray[], PRUint32 aLangArrayLen, PrefFontCallback aCallback,
void *aClosure)
{
nsresult rv;
nsCOMPtr<nsIPrefBranch> prefs(do_GetService(NS_PREFSERVICE_CONTRACTID));
if (!prefs)
return PR_FALSE;
NS_ENSURE_TRUE(Preferences::GetRootBranch(), PR_FALSE);
PRUint32 i;
for (i = 0; i < aLangArrayLen; i++) {
eFontPrefLang prefLang = aLangArray[i];
const char *langGroup = GetPrefLangName(prefLang);
nsCAutoString prefName;
nsXPIDLCString nameValue, nameListValue;
nsCAutoString genericDotLang;
prefName.AssignLiteral("font.default.");
prefName.Append(langGroup);
prefs->GetCharPref(prefName.get(), getter_Copies(genericDotLang));
nsAdoptingCString genericDotLang = Preferences::GetCString(prefName.get());
genericDotLang.AppendLiteral(".");
genericDotLang.Append(langGroup);
@ -577,8 +550,8 @@ PRBool gfxPlatform::ForEachPrefFont(eFontPrefLang aLangArray[], PRUint32 aLangAr
// fetch font.name.xxx value
prefName.AssignLiteral("font.name.");
prefName.Append(genericDotLang);
rv = prefs->GetCharPref(prefName.get(), getter_Copies(nameValue));
if (NS_SUCCEEDED(rv)) {
nsAdoptingCString nameValue = Preferences::GetCString(prefName.get());
if (nameValue) {
if (!aCallback(prefLang, NS_ConvertUTF8toUTF16(nameValue), aClosure))
return PR_FALSE;
}
@ -586,8 +559,8 @@ PRBool gfxPlatform::ForEachPrefFont(eFontPrefLang aLangArray[], PRUint32 aLangAr
// fetch font.name-list.xxx value
prefName.AssignLiteral("font.name-list.");
prefName.Append(genericDotLang);
rv = prefs->GetCharPref(prefName.get(), getter_Copies(nameListValue));
if (NS_SUCCEEDED(rv) && !nameListValue.Equals(nameValue)) {
nsAdoptingCString nameListValue = Preferences::GetCString(prefName.get());
if (nameListValue && !nameListValue.Equals(nameValue)) {
const char kComma = ',';
const char *p, *p_end;
nsCAutoString list(nameListValue);
@ -713,8 +686,6 @@ gfxPlatform::GetLangPrefs(eFontPrefLang aPrefLangs[], PRUint32 &aLen, eFontPrefL
void
gfxPlatform::AppendCJKPrefLangs(eFontPrefLang aPrefLangs[], PRUint32 &aLen, eFontPrefLang aCharLang, eFontPrefLang aPageLang)
{
nsCOMPtr<nsIPrefBranch> prefs(do_GetService(NS_PREFSERVICE_CONTRACTID));
// prefer the lang specified by the page *if* CJK
if (IsLangCJK(aPageLang)) {
AppendPrefLang(aPrefLangs, aLen, aPageLang);
@ -728,20 +699,7 @@ gfxPlatform::AppendCJKPrefLangs(eFontPrefLang aPrefLangs[], PRUint32 &aLen, eFon
PRUint32 tempLen = 0;
// Add the CJK pref fonts from accept languages, the order should be same order
nsCAutoString list;
if (prefs) {
nsCOMPtr<nsIPrefLocalizedString> prefString;
nsresult rv =
prefs->GetComplexValue("intl.accept_languages",
NS_GET_IID(nsIPrefLocalizedString),
getter_AddRefs(prefString));
if (NS_SUCCEEDED(rv) && prefString) {
nsAutoString temp;
prefString->ToString(getter_Copies(temp));
LossyCopyUTF16toASCII(temp, list);
}
}
nsAdoptingCString list = Preferences::GetLocalizedCString("intl.accept_languages");
if (!list.IsEmpty()) {
const char kComma = ',';
const char *p, *p_end;
@ -855,14 +813,10 @@ gfxPlatform::GetCMSMode()
{
if (gCMSInitialized == PR_FALSE) {
gCMSInitialized = PR_TRUE;
nsCOMPtr<nsIPrefBranch> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
if (prefs) {
PRInt32 mode;
nsresult rv =
prefs->GetIntPref(CMPrefName, &mode);
if (NS_SUCCEEDED(rv) && (mode >= 0) && (mode < eCMSMode_AllCount)) {
gCMSMode = static_cast<eCMSMode>(mode);
}
PRInt32 mode;
nsresult rv = Preferences::GetInt(CMPrefName, &mode);
if (NS_SUCCEEDED(rv) && (mode >= 0) && (mode < eCMSMode_AllCount)) {
gCMSMode = static_cast<eCMSMode>(mode);
}
}
return gCMSMode;
@ -881,25 +835,21 @@ gfxPlatform::GetRenderingIntent()
if (gCMSIntent == -2) {
/* Try to query the pref system for a rendering intent. */
nsCOMPtr<nsIPrefBranch> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
if (prefs) {
PRInt32 pIntent;
nsresult rv = prefs->GetIntPref(CMIntentPrefName, &pIntent);
if (NS_SUCCEEDED(rv)) {
/* If the pref is within range, use it as an override. */
if ((pIntent >= INTENT_MIN) && (pIntent <= INTENT_MAX))
gCMSIntent = pIntent;
/* If the pref is out of range, use embedded profile. */
else
gCMSIntent = -1;
PRInt32 pIntent;
if (NS_SUCCEEDED(Preferences::GetInt(CMIntentPrefName, &pIntent))) {
/* If the pref is within range, use it as an override. */
if ((pIntent >= INTENT_MIN) && (pIntent <= INTENT_MAX)) {
gCMSIntent = pIntent;
}
/* 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. */
if (gCMSIntent == -2)
else {
gCMSIntent = INTENT_DEFAULT;
}
}
return gCMSIntent;
}
@ -946,31 +896,21 @@ gfxPlatform::GetCMSOutputProfile()
if (!gCMSOutputProfile) {
NS_TIME_FUNCTION;
nsCOMPtr<nsIPrefBranch> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
if (prefs) {
/* Determine if we're using the internal override to force sRGB as
an output profile for reftests. See Bug 452125.
nsresult rv;
Note that we don't normally (outside of tests) set a
default value of this preference, which means nsIPrefBranch::GetBoolPref
will typically throw (and leave its out-param untouched).
*/
if (Preferences::GetBool(CMForceSRGBPrefName, PR_FALSE)) {
gCMSOutputProfile = GetCMSsRGBProfile();
}
/* Determine if we're using the internal override to force sRGB as
an output profile for reftests. See Bug 452125.
Note that we don't normally (outside of tests) set a
default value of this preference, which means GetBoolPref
will typically throw (and leave its out-param untouched).
*/
PRBool doSRGBOverride;
rv = prefs->GetBoolPref(CMForceSRGBPrefName, &doSRGBOverride);
if (NS_SUCCEEDED(rv) && doSRGBOverride)
gCMSOutputProfile = GetCMSsRGBProfile();
if (!gCMSOutputProfile) {
nsXPIDLCString fname;
rv = prefs->GetCharPref(CMProfilePrefName,
getter_Copies(fname));
if (NS_SUCCEEDED(rv) && !fname.IsEmpty()) {
gCMSOutputProfile = qcms_profile_from_path(fname);
}
if (!gCMSOutputProfile) {
nsAdoptingCString fname = Preferences::GetCString(CMProfilePrefName);
if (!fname.IsEmpty()) {
gCMSOutputProfile = qcms_profile_from_path(fname);
}
}
@ -1104,26 +1044,14 @@ static void ShutdownCMS()
static void MigratePrefs()
{
/* Load the pref service. If we don't get it die quietly since this isn't
critical code. */
nsCOMPtr<nsIPrefBranch> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
if (!prefs)
return;
/* Migrate from the boolean color_management.enabled pref - we now use
color_management.mode. */
PRBool hasOldCMPref;
nsresult rv =
prefs->PrefHasUserValue(CMPrefNameOld, &hasOldCMPref);
if (NS_SUCCEEDED(rv) && (hasOldCMPref == PR_TRUE)) {
PRBool CMWasEnabled;
rv = prefs->GetBoolPref(CMPrefNameOld, &CMWasEnabled);
if (NS_SUCCEEDED(rv) && (CMWasEnabled == PR_TRUE))
prefs->SetIntPref(CMPrefName, eCMSMode_All);
prefs->ClearUserPref(CMPrefNameOld);
if (Preferences::HasUserValue(CMPrefNameOld)) {
if (Preferences::GetBool(CMPrefNameOld, PR_FALSE)) {
Preferences::SetInt(CMPrefName, static_cast<PRInt32>(eCMSMode_All));
}
Preferences::ClearUser(CMPrefNameOld);
}
}
// default SetupClusterBoundaries, based on Unicode properties;
@ -1244,7 +1172,7 @@ gfxPlatform::SetupClusterBoundaries(gfxTextRun *aTextRun, const PRUnichar *aStri
}
void
gfxPlatform::FontsPrefsChanged(nsIPrefBranch *aPrefBranch, const char *aPref)
gfxPlatform::FontsPrefsChanged(const char *aPref)
{
NS_ASSERTION(aPref != nsnull, "null preference");
if (!strcmp(GFX_DOWNLOADABLE_FONTS_ENABLED, aPref)) {

View File

@ -65,7 +65,6 @@ class gfxPlatformFontList;
class gfxTextRun;
class nsIURI;
class nsIAtom;
class nsIPrefBranch;
// pref lang id's for font prefs
// !!! needs to match the list of pref font.default.xx entries listed in all.js !!!
@ -350,7 +349,7 @@ public:
*/
static qcms_transform* GetCMSRGBATransform();
virtual void FontsPrefsChanged(nsIPrefBranch *aPrefBranch, const char *aPref);
virtual void FontsPrefsChanged(const char *aPref);
/**
* Returns a 1x1 surface that can be used to create graphics contexts
@ -370,8 +369,6 @@ protected:
gfxPlatform();
virtual ~gfxPlatform();
static PRBool GetBoolPref(const char *aPref, PRBool aDefault);
void AppendCJKPrefLangs(eFontPrefLang aPrefLangs[], PRUint32 &aLen,
eFontPrefLang aCharLang, eFontPrefLang aPageLang);
@ -386,7 +383,8 @@ private:
nsRefPtr<gfxASurface> mScreenReferenceSurface;
nsTArray<PRUint32> mCJKPrefLangs;
nsCOMPtr<nsIObserver> overrideObserver;
nsCOMPtr<nsIObserver> mSRGBOverrideObserver;
nsCOMPtr<nsIObserver> mFontPrefsObserver;
};
#endif /* GFX_PLATFORM_H */

View File

@ -72,13 +72,14 @@
#include "gfxPlatformFontList.h"
#include "gfxTextRunWordCache.h"
#include "nsIPrefService.h"
#include "nsIPrefBranch2.h" // for pref changes callback notification
#include "nsServiceManagerUtils.h"
#include "nsUnicharUtils.h"
#include "nsUnicodeRange.h"
#include "gfxUnicodeProperties.h"
#include "mozilla/Preferences.h"
using namespace mozilla;
// font info loader constants
static const PRUint32 kDelayBeforeLoadingCmaps = 8 * 1000; // 8secs
static const PRUint32 kIntervalBetweenLoadingCmaps = 150; // 150ms
@ -97,12 +98,21 @@ static const PRUint32 kNumFontsPerSlice = 10; // read in info 10 fonts at a time
gfxPlatformFontList *gfxPlatformFontList::sPlatformFontList = nsnull;
static const char* kObservedPrefs[] = {
"font.",
"font.name-list.",
"intl.accept_languages", // hmmmm...
nsnull
};
class gfxFontListPrefObserver : public nsIObserver {
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIOBSERVER
};
static gfxFontListPrefObserver* gFontListPrefObserver = nsnull;
NS_IMPL_ISUPPORTS1(gfxFontListPrefObserver, nsIObserver)
NS_IMETHODIMP
@ -139,17 +149,18 @@ gfxPlatformFontList::gfxPlatformFontList(PRBool aNeedFullnamePostscriptNames)
LoadBadUnderlineList();
// pref changes notification setup
gfxFontListPrefObserver *observer = new gfxFontListPrefObserver();
if (observer) {
nsCOMPtr<nsIPrefBranch2> pref = do_GetService(NS_PREFSERVICE_CONTRACTID);
if (pref) {
pref->AddObserver("font.", observer, PR_FALSE);
pref->AddObserver("font.name-list.", observer, PR_FALSE);
pref->AddObserver("intl.accept_languages", observer, PR_FALSE); // hmmmm...
} else {
delete observer;
}
}
NS_ASSERTION(!gFontListPrefObserver,
"There has been font list pref observer already");
gFontListPrefObserver = new gfxFontListPrefObserver();
NS_ADDREF(gFontListPrefObserver);
Preferences::AddStrongObservers(gFontListPrefObserver, kObservedPrefs);
}
gfxPlatformFontList::~gfxPlatformFontList()
{
NS_ASSERTION(gFontListPrefObserver, "There is no font list pref observer");
Preferences::RemoveObservers(gFontListPrefObserver, kObservedPrefs);
NS_RELEASE(gFontListPrefObserver);
}
nsresult

View File

@ -79,6 +79,8 @@ public:
sPlatformFontList = nsnull;
}
virtual ~gfxPlatformFontList();
// initialize font lists
virtual nsresult InitFontList();

View File

@ -47,18 +47,18 @@
#include "gfxCoreTextShaper.h"
#include "gfxUserFontSet.h"
#include "nsIPrefBranch.h"
#include "nsIPrefService.h"
#include "nsIPrefLocalizedString.h"
#include "nsServiceManagerUtils.h"
#include "nsCRT.h"
#include "nsTArray.h"
#include "nsUnicodeRange.h"
#include "mozilla/Preferences.h"
#include "qcms.h"
#include <dlfcn.h>
using namespace mozilla;
// cribbed from CTFontManager.h
enum {
kAutoActivationDisabled = 1
@ -270,17 +270,8 @@ gfxPlatformMac::ReadAntiAliasingThreshold()
PRUint32 threshold = 0; // default == no threshold
// first read prefs flag to determine whether to use the setting or not
PRBool useAntiAliasingThreshold = PR_FALSE;
nsCOMPtr<nsIPrefBranch> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
if (prefs) {
PRBool enabled;
nsresult rv =
prefs->GetBoolPref("gfx.use_text_smoothing_setting", &enabled);
if (NS_SUCCEEDED(rv)) {
useAntiAliasingThreshold = enabled;
}
}
PRBool useAntiAliasingThreshold = Preferences::GetBool("gfx.use_text_smoothing_setting", PR_FALSE);
// if the pref setting is disabled, return 0 which effectively disables this feature
if (!useAntiAliasingThreshold)
return threshold;

View File

@ -76,8 +76,9 @@
#include FT_FREETYPE_H
#endif
#include "nsIPrefBranch.h"
#include "nsIPrefService.h"
#include "mozilla/Preferences.h"
using namespace mozilla;
#define DEFAULT_RENDER_MODE RENDER_DIRECT
@ -123,15 +124,9 @@ gfxQtPlatform::gfxQtPlatform()
#endif
nsresult rv;
PRInt32 ival;
// 0 - default gfxQPainterSurface
// 1 - gfxImageSurface
nsCOMPtr<nsIPrefBranch> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID, &rv);
if (prefs) {
rv = prefs->GetIntPref("mozilla.widget-qt.render-mode", &ival);
if (NS_FAILED(rv))
ival = DEFAULT_RENDER_MODE;
}
PRInt32 ival = Preferences::GetInt("mozilla.widget-qt.render-mode", DEFAULT_RENDER_MODE);
const char *envTypeOverride = getenv("MOZ_QT_RENDER_TYPE");
if (envTypeOverride)

View File

@ -41,13 +41,10 @@
#include "nsWeakReference.h"
#include "nsCRT.h"
#include "nsServiceManagerUtils.h"
#include "nsIPrefBranch.h"
#include "nsIPrefBranch2.h"
#include "nsIPrefService.h"
#include "nsIObserver.h"
#include "nsBidiUtils.h"
#include "mozilla/Preferences.h"
#if defined(XP_UNIX)
#include <stdint.h>
@ -57,6 +54,8 @@
#include <stdio.h>
#endif
using namespace mozilla;
/**
* Cache individual "words" (strings delimited by white-space or white-space-like
* characters that don't involve kerning or ligatures) in textruns.
@ -221,8 +220,6 @@ protected:
nsTHashtable<CacheHashEntry> mCache;
PRInt32 mBidiNumeral;
nsCOMPtr<nsIPrefBranch2> mPrefBranch;
nsCOMPtr<nsIPrefBranch2> mFontPrefBranch;
#ifdef DEBUG
static PLDHashOperator CacheDumpEntry(CacheHashEntry* aEntry, void* userArg);
@ -235,6 +232,12 @@ static TextRunWordCache *gTextRunWordCache = nsnull;
static PRLogModuleInfo *gWordCacheLog = PR_NewLogModule("wordCache");
static const char* kObservedPrefs[] = {
"bidi.",
"font.",
nsnull
};
void
TextRunWordCache::Init()
{
@ -242,33 +245,14 @@ TextRunWordCache::Init()
mGeneration = 0;
#endif
nsCOMPtr<nsIPrefService> prefService = do_GetService(NS_PREFSERVICE_CONTRACTID);
if (!prefService)
return;
nsCOMPtr<nsIPrefBranch> branch;
prefService->GetBranch("bidi.", getter_AddRefs(branch));
mPrefBranch = do_QueryInterface(branch);
if (!mPrefBranch)
return;
mPrefBranch->AddObserver("", this, PR_TRUE);
mPrefBranch->GetIntPref("numeral", &mBidiNumeral);
nsCOMPtr<nsIPrefBranch> fontBranch;
prefService->GetBranch("font.", getter_AddRefs(fontBranch));
mFontPrefBranch = do_QueryInterface(fontBranch);
if (mFontPrefBranch)
mFontPrefBranch->AddObserver("", this, PR_TRUE);
Preferences::AddWeakObservers(this, kObservedPrefs);
mBidiNumeral = Preferences::GetInt("bidi.numeral", mBidiNumeral);
}
void
TextRunWordCache::Uninit()
{
if (mPrefBranch)
mPrefBranch->RemoveObserver("", this);
if (mFontPrefBranch)
mFontPrefBranch->RemoveObserver("", this);
Preferences::RemoveObservers(this, kObservedPrefs);
}
NS_IMETHODIMP
@ -277,8 +261,8 @@ TextRunWordCache::Observe(nsISupports *aSubject,
const PRUnichar *aData)
{
if (!nsCRT::strcmp(aTopic, NS_PREFBRANCH_PREFCHANGE_TOPIC_ID)) {
if (!nsCRT::strcmp(aData, NS_LITERAL_STRING("numeral").get())) {
mPrefBranch->GetIntPref("numeral", &mBidiNumeral);
if (!nsCRT::strcmp(aData, NS_LITERAL_STRING("bidi.numeral").get())) {
mBidiNumeral = Preferences::GetInt("bidi.numeral", mBidiNumeral);
}
mCache.Clear();
PR_LOG(gWordCacheLog, PR_LOG_DEBUG, ("flushing the textrun cache"));

View File

@ -46,8 +46,7 @@
#include "nsUnicharUtils.h"
#include "nsIPrefService.h"
#include "nsIPrefBranch2.h"
#include "mozilla/Preferences.h"
#include "nsServiceManagerUtils.h"
#include "nsTArray.h"
@ -86,6 +85,8 @@
#include "nsIMemoryReporter.h"
#include "nsMemory.h"
using namespace mozilla;
class D2DCacheReporter :
public nsIMemoryReporter
{
@ -283,18 +284,7 @@ gfxWindowsPlatform::UpdateRenderMode()
if (xr)
xr->GetInSafeMode(&safeMode);
nsCOMPtr<nsIPrefBranch2> pref = do_GetService(NS_PREFSERVICE_CONTRACTID);
nsresult rv;
PRBool preferDirectWrite = PR_FALSE;
rv = pref->GetBoolPref(
"gfx.font_rendering.directwrite.enabled", &preferDirectWrite);
if (NS_FAILED(rv)) {
preferDirectWrite = PR_FALSE;
}
mUseDirectWrite = preferDirectWrite;
mUseDirectWrite = Preferences::GetBool("gfx.font_rendering.directwrite.enabled", PR_FALSE);
#ifdef CAIRO_HAS_D2D_SURFACE
PRBool d2dDisabled = PR_FALSE;
@ -316,12 +306,8 @@ gfxWindowsPlatform::UpdateRenderMode()
}
}
rv = pref->GetBoolPref("gfx.direct2d.disabled", &d2dDisabled);
if (NS_FAILED(rv))
d2dDisabled = PR_FALSE;
rv = pref->GetBoolPref("gfx.direct2d.force-enabled", &d2dForceEnabled);
if (NS_FAILED(rv))
d2dForceEnabled = PR_FALSE;
d2dDisabled = Preferences::GetBool("gfx.direct2d.disabled", PR_FALSE);
d2dForceEnabled = Preferences::GetBool("gfx.direct2d.force-enabled", PR_FALSE);
bool tryD2D = !d2dBlocked || d2dForceEnabled;
@ -364,7 +350,7 @@ gfxWindowsPlatform::UpdateRenderMode()
mDWriteFactory = factory;
factory->Release();
SetupClearTypeParams(pref);
SetupClearTypeParams();
if (hr == S_OK)
reporter.SetSuccessful();
@ -713,7 +699,7 @@ PRBool
gfxWindowsPlatform::UseClearTypeForDownloadableFonts()
{
if (mUseClearTypeForDownloadableFonts == UNINITIALIZED_VALUE) {
mUseClearTypeForDownloadableFonts = GetBoolPref(GFX_DOWNLOADABLE_FONTS_USE_CLEARTYPE, PR_TRUE);
mUseClearTypeForDownloadableFonts = Preferences::GetBool(GFX_DOWNLOADABLE_FONTS_USE_CLEARTYPE, PR_TRUE);
}
return mUseClearTypeForDownloadableFonts;
@ -723,7 +709,7 @@ PRBool
gfxWindowsPlatform::UseClearTypeAlways()
{
if (mUseClearTypeAlways == UNINITIALIZED_VALUE) {
mUseClearTypeAlways = GetBoolPref(GFX_USE_CLEARTYPE_ALWAYS, PR_FALSE);
mUseClearTypeAlways = Preferences::GetBool(GFX_USE_CLEARTYPE_ALWAYS, PR_FALSE);
}
return mUseClearTypeAlways;
@ -891,11 +877,11 @@ gfxWindowsPlatform::GetCleartypeParams(nsTArray<ClearTypeParameterInfo>& aParams
}
void
gfxWindowsPlatform::FontsPrefsChanged(nsIPrefBranch *aPrefBranch, const char *aPref)
gfxWindowsPlatform::FontsPrefsChanged(const char *aPref)
{
PRBool clearTextFontCaches = PR_TRUE;
gfxPlatform::FontsPrefsChanged(aPrefBranch, aPref);
gfxPlatform::FontsPrefsChanged(aPref);
if (!aPref) {
mUseClearTypeForDownloadableFonts = UNINITIALIZED_VALUE;
@ -905,7 +891,7 @@ gfxWindowsPlatform::FontsPrefsChanged(nsIPrefBranch *aPrefBranch, const char *aP
} else if (!strcmp(GFX_USE_CLEARTYPE_ALWAYS, aPref)) {
mUseClearTypeAlways = UNINITIALIZED_VALUE;
} else if (!strncmp(GFX_CLEARTYPE_PARAMS, aPref, strlen(GFX_CLEARTYPE_PARAMS))) {
SetupClearTypeParams(aPrefBranch);
SetupClearTypeParams();
} else {
clearTextFontCaches = PR_FALSE;
}
@ -920,7 +906,7 @@ gfxWindowsPlatform::FontsPrefsChanged(nsIPrefBranch *aPrefBranch, const char *aP
}
void
gfxWindowsPlatform::SetupClearTypeParams(nsIPrefBranch *aPrefBranch)
gfxWindowsPlatform::SetupClearTypeParams()
{
#if CAIRO_HAS_DWRITE_FONT
if (GetDWriteFactory()) {
@ -932,36 +918,36 @@ gfxWindowsPlatform::SetupClearTypeParams(nsIPrefBranch *aPrefBranch)
int geometry = -1;
int mode = -1;
PRInt32 value;
if (NS_SUCCEEDED(aPrefBranch->GetIntPref(GFX_CLEARTYPE_PARAMS_GAMMA,
&value))) {
if (NS_SUCCEEDED(Preferences::GetInt(GFX_CLEARTYPE_PARAMS_GAMMA, &value))) {
if (value >= 1000 && value <= 2200) {
gamma = FLOAT(value / 1000.0);
}
}
if (NS_SUCCEEDED(aPrefBranch->GetIntPref(GFX_CLEARTYPE_PARAMS_CONTRAST,
&value))) {
if (NS_SUCCEEDED(Preferences::GetInt(GFX_CLEARTYPE_PARAMS_CONTRAST, &value))) {
if (value >= 0 && value <= 1000) {
contrast = FLOAT(value / 100.0);
}
}
if (NS_SUCCEEDED(aPrefBranch->GetIntPref(GFX_CLEARTYPE_PARAMS_LEVEL,
&value))) {
if (NS_SUCCEEDED(Preferences::GetInt(GFX_CLEARTYPE_PARAMS_LEVEL, &value))) {
if (value >= 0 && value <= 100) {
level = FLOAT(value / 100.0);
}
}
if (NS_SUCCEEDED(aPrefBranch->GetIntPref(GFX_CLEARTYPE_PARAMS_STRUCTURE,
&value))) {
if (NS_SUCCEEDED(Preferences::GetInt(GFX_CLEARTYPE_PARAMS_STRUCTURE, &value))) {
if (value >= 0 && value <= 2) {
geometry = value;
}
}
if (NS_SUCCEEDED(aPrefBranch->GetIntPref(GFX_CLEARTYPE_PARAMS_MODE,
&value))) {
if (NS_SUCCEEDED(Preferences::GetInt(GFX_CLEARTYPE_PARAMS_MODE, &value))) {
if (value >= 0 && value <= 5) {
mode = value;
}
}
cairo_dwrite_set_cleartype_params(gamma, contrast, level, geometry, mode);
switch (mode) {

View File

@ -243,9 +243,9 @@ public:
// returns ClearType tuning information for each display
static void GetCleartypeParams(nsTArray<ClearTypeParameterInfo>& aParams);
virtual void FontsPrefsChanged(nsIPrefBranch *aPrefBranch, const char *aPref);
virtual void FontsPrefsChanged(const char *aPref);
void SetupClearTypeParams(nsIPrefBranch *aPrefBranch);
void SetupClearTypeParams();
#ifdef CAIRO_HAS_DWRITE_FONT
IDWriteFactory *GetDWriteFactory() { return mDWriteFactory; }

View File

@ -45,10 +45,11 @@
#include "nsTArray.h"
#include "nsAlgorithm.h"
#include "nsServiceManagerUtils.h"
#include "nsIPrefService.h"
#include "mozilla/Preferences.h"
#include "cairo-xlib-xrender.h"
using namespace mozilla;
// Although the dimension parameters in the xCreatePixmapReq wire protocol are
// 16-bit unsigned integers, the server's CreatePixmap returns BadAlloc if
// either dimension cannot be represented by a 16-bit *signed* integer.
@ -169,14 +170,7 @@ gfxXlibSurface::Create(Screen *screen, XRenderPictFormat *format,
static PRBool GetForce24bppPref()
{
PRBool val = PR_FALSE; // default
nsCOMPtr<nsIPrefBranch> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
if (!prefs)
return val;
prefs->GetBoolPref("mozilla.widget.force-24bpp", &val);
return val;
return Preferences::GetBool("mozilla.widget.force-24bpp", PR_FALSE);
}
already_AddRefed<gfxASurface>