2012-05-21 08:27:32 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
2012-05-21 04:12:37 -07:00
|
|
|
* 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/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-01-21 08:44:33 -08:00
|
|
|
#ifdef MOZ_LOGGING
|
|
|
|
#define FORCE_PR_LOG /* Allow logging in the release build */
|
|
|
|
#endif
|
|
|
|
#include "prlog.h"
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "gfxPlatform.h"
|
|
|
|
|
|
|
|
#if defined(XP_WIN)
|
|
|
|
#include "gfxWindowsPlatform.h"
|
2011-06-24 10:41:18 -07:00
|
|
|
#include "gfxD2DSurface.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#elif defined(XP_MACOSX)
|
|
|
|
#include "gfxPlatformMac.h"
|
2012-06-27 17:15:32 -07:00
|
|
|
#elif defined(MOZ_WIDGET_GTK)
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "gfxPlatformGtk.h"
|
2008-04-19 06:19:04 -07:00
|
|
|
#elif defined(MOZ_WIDGET_QT)
|
|
|
|
#include "gfxQtPlatform.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#elif defined(XP_OS2)
|
|
|
|
#include "gfxOS2Platform.h"
|
2010-05-11 10:27:36 -07:00
|
|
|
#elif defined(ANDROID)
|
|
|
|
#include "gfxAndroidPlatform.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
|
|
|
|
2012-03-29 14:08:43 -07:00
|
|
|
#include "nsGkAtoms.h"
|
2009-08-16 06:52:12 -07:00
|
|
|
#include "gfxPlatformFontList.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "gfxContext.h"
|
|
|
|
#include "gfxImageSurface.h"
|
2008-09-30 20:01:53 -07:00
|
|
|
#include "gfxUserFontSet.h"
|
2012-02-24 02:15:46 -08:00
|
|
|
#include "nsUnicodeProperties.h"
|
2012-04-21 14:24:39 -07:00
|
|
|
#include "harfbuzz/hb.h"
|
2011-12-09 14:32:29 -08:00
|
|
|
#ifdef MOZ_GRAPHITE
|
|
|
|
#include "gfxGraphiteShaper.h"
|
|
|
|
#endif
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-10-07 08:26:58 -07:00
|
|
|
#include "nsUnicodeRange.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsServiceManagerUtils.h"
|
2009-01-18 12:14:14 -08:00
|
|
|
#include "nsTArray.h"
|
2009-10-07 08:26:58 -07:00
|
|
|
#include "nsUnicharUtilCIID.h"
|
|
|
|
#include "nsILocaleService.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-09-08 14:47:26 -07:00
|
|
|
#include "nsWeakReference.h"
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "cairo.h"
|
2009-04-07 09:02:11 -07:00
|
|
|
#include "qcms.h"
|
2007-07-23 15:02:17 -07:00
|
|
|
|
2008-01-30 16:23:36 -08:00
|
|
|
#include "plstr.h"
|
2009-10-07 07:13:40 -07:00
|
|
|
#include "nsCRT.h"
|
2010-07-19 21:05:42 -07:00
|
|
|
#include "GLContext.h"
|
|
|
|
#include "GLContextProvider.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-04-05 19:28:54 -07:00
|
|
|
#include "mozilla/FunctionTimer.h"
|
2011-06-11 19:30:16 -07:00
|
|
|
#include "mozilla/Preferences.h"
|
2012-05-15 12:41:20 -07:00
|
|
|
#include "mozilla/Assertions.h"
|
2012-06-12 21:14:28 -07:00
|
|
|
#include "mozilla/Attributes.h"
|
2010-04-05 19:28:54 -07:00
|
|
|
|
2010-08-28 07:18:41 -07:00
|
|
|
#include "nsIGfxInfo.h"
|
|
|
|
|
2011-06-11 19:30:16 -07:00
|
|
|
using namespace mozilla;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
gfxPlatform *gPlatform = nsnull;
|
2011-04-21 12:36:49 -07:00
|
|
|
static bool gEverInitialized = false;
|
2008-07-16 20:09:08 -07:00
|
|
|
|
|
|
|
// These two may point to the same profile
|
2009-04-07 09:02:11 -07:00
|
|
|
static qcms_profile *gCMSOutputProfile = nsnull;
|
|
|
|
static qcms_profile *gCMSsRGBProfile = nsnull;
|
2008-07-16 20:09:08 -07:00
|
|
|
|
2009-04-07 09:02:11 -07:00
|
|
|
static qcms_transform *gCMSRGBTransform = nsnull;
|
|
|
|
static qcms_transform *gCMSInverseRGBTransform = nsnull;
|
|
|
|
static qcms_transform *gCMSRGBATransform = nsnull;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool gCMSInitialized = false;
|
2008-09-08 14:47:26 -07:00
|
|
|
static eCMSMode gCMSMode = eCMSMode_Off;
|
|
|
|
static int gCMSIntent = -2;
|
|
|
|
|
|
|
|
static void ShutdownCMS();
|
2008-08-11 21:55:36 -07:00
|
|
|
static void MigratePrefs();
|
|
|
|
|
2011-06-24 10:41:18 -07:00
|
|
|
#include "mozilla/gfx/2D.h"
|
|
|
|
using namespace mozilla::gfx;
|
2011-01-21 08:44:33 -08:00
|
|
|
|
|
|
|
// logs shared across gfx
|
|
|
|
#ifdef PR_LOGGING
|
|
|
|
static PRLogModuleInfo *sFontlistLog = nsnull;
|
|
|
|
static PRLogModuleInfo *sFontInitLog = nsnull;
|
|
|
|
static PRLogModuleInfo *sTextrunLog = nsnull;
|
|
|
|
static PRLogModuleInfo *sTextrunuiLog = nsnull;
|
2012-03-08 18:05:14 -08:00
|
|
|
static PRLogModuleInfo *sCmapDataLog = nsnull;
|
2011-01-21 08:44:33 -08:00
|
|
|
#endif
|
|
|
|
|
2008-09-08 14:47:26 -07:00
|
|
|
/* Class to listen for pref changes so that chrome code can dynamically
|
|
|
|
force sRGB as an output profile. See Bug #452125. */
|
2012-06-12 21:14:28 -07:00
|
|
|
class SRGBOverrideObserver MOZ_FINAL : public nsIObserver,
|
|
|
|
public nsSupportsWeakReference
|
2008-09-08 14:47:26 -07:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIOBSERVER
|
|
|
|
};
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS2(SRGBOverrideObserver, nsIObserver, nsISupportsWeakReference)
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
SRGBOverrideObserver::Observe(nsISupports *aSubject,
|
|
|
|
const char *aTopic,
|
|
|
|
const PRUnichar *someData)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(NS_strcmp(someData,
|
|
|
|
NS_LITERAL_STRING("gfx.color_mangement.force_srgb").get()),
|
|
|
|
"Restarting CMS on wrong pref!");
|
|
|
|
ShutdownCMS();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-05-26 22:05:30 -07:00
|
|
|
#define GFX_DOWNLOADABLE_FONTS_ENABLED "gfx.downloadable_fonts.enabled"
|
2010-10-07 00:59:19 -07:00
|
|
|
#define GFX_DOWNLOADABLE_FONTS_SANITIZE "gfx.downloadable_fonts.sanitize"
|
2010-05-26 22:05:30 -07:00
|
|
|
|
2011-04-11 04:17:31 -07:00
|
|
|
#define GFX_PREF_HARFBUZZ_SCRIPTS "gfx.font_rendering.harfbuzz.scripts"
|
2012-02-24 02:15:46 -08:00
|
|
|
#define HARFBUZZ_SCRIPTS_DEFAULT mozilla::unicode::SHAPING_DEFAULT
|
2012-03-08 18:05:40 -08:00
|
|
|
#define GFX_PREF_FALLBACK_USE_CMAPS "gfx.font_rendering.fallback.always_use_cmaps"
|
2009-10-07 10:16:52 -07:00
|
|
|
|
2011-12-09 14:32:29 -08:00
|
|
|
#ifdef MOZ_GRAPHITE
|
|
|
|
#define GFX_PREF_GRAPHITE_SHAPING "gfx.font_rendering.graphite.enabled"
|
|
|
|
#endif
|
|
|
|
|
2011-12-06 04:39:19 -08:00
|
|
|
#define BIDI_NUMERAL_PREF "bidi.numeral"
|
|
|
|
|
2011-06-11 19:30:16 -07:00
|
|
|
static const char* kObservedPrefs[] = {
|
|
|
|
"gfx.downloadable_fonts.",
|
|
|
|
"gfx.font_rendering.",
|
2011-12-06 04:39:19 -08:00
|
|
|
"bidi.numeral",
|
2011-06-11 19:30:16 -07:00
|
|
|
nsnull
|
|
|
|
};
|
|
|
|
|
2012-06-12 21:14:28 -07:00
|
|
|
class FontPrefsObserver MOZ_FINAL : public nsIObserver
|
2010-05-26 22:05:30 -07:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIOBSERVER
|
|
|
|
};
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS1(FontPrefsObserver, nsIObserver)
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
FontPrefsObserver::Observe(nsISupports *aSubject,
|
|
|
|
const char *aTopic,
|
|
|
|
const PRUnichar *someData)
|
|
|
|
{
|
2011-06-11 19:30:16 -07:00
|
|
|
if (!someData) {
|
2010-05-26 22:05:30 -07:00
|
|
|
NS_ERROR("font pref observer code broken");
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
2011-06-11 19:30:16 -07:00
|
|
|
NS_ASSERTION(gfxPlatform::GetPlatform(), "the singleton instance has gone");
|
|
|
|
gfxPlatform::GetPlatform()->FontsPrefsChanged(NS_ConvertUTF16toUTF8(someData).get());
|
2010-05-26 22:05:30 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-09-08 14:47:26 -07:00
|
|
|
|
2008-01-30 16:23:36 -08:00
|
|
|
// this needs to match the list of pref font.default.xx entries listed in all.js!
|
|
|
|
// the order *must* match the order in eFontPrefLang
|
|
|
|
static const char *gPrefLangNames[] = {
|
|
|
|
"x-western",
|
|
|
|
"x-central-euro",
|
|
|
|
"ja",
|
|
|
|
"zh-TW",
|
|
|
|
"zh-CN",
|
|
|
|
"zh-HK",
|
|
|
|
"ko",
|
|
|
|
"x-cyrillic",
|
|
|
|
"x-baltic",
|
|
|
|
"el",
|
|
|
|
"tr",
|
|
|
|
"th",
|
|
|
|
"he",
|
|
|
|
"ar",
|
|
|
|
"x-devanagari",
|
|
|
|
"x-tamil",
|
|
|
|
"x-armn",
|
|
|
|
"x-beng",
|
|
|
|
"x-cans",
|
|
|
|
"x-ethi",
|
|
|
|
"x-geor",
|
|
|
|
"x-gujr",
|
|
|
|
"x-guru",
|
|
|
|
"x-khmr",
|
|
|
|
"x-mlym",
|
2008-04-03 21:23:18 -07:00
|
|
|
"x-orya",
|
|
|
|
"x-telu",
|
|
|
|
"x-knda",
|
|
|
|
"x-sinh",
|
2010-03-04 00:55:53 -08:00
|
|
|
"x-tibt",
|
2008-01-30 16:23:36 -08:00
|
|
|
"x-unicode",
|
|
|
|
"x-user-def"
|
|
|
|
};
|
|
|
|
|
2010-05-26 22:05:30 -07:00
|
|
|
gfxPlatform::gfxPlatform()
|
2011-11-17 20:00:38 -08:00
|
|
|
: mAzureBackendCollector(this, &gfxPlatform::GetAzureBackendInfo)
|
2010-05-26 22:05:30 -07:00
|
|
|
{
|
2011-04-11 04:17:31 -07:00
|
|
|
mUseHarfBuzzScripts = UNINITIALIZED_VALUE;
|
2010-05-26 22:05:30 -07:00
|
|
|
mAllowDownloadableFonts = UNINITIALIZED_VALUE;
|
2010-10-07 00:59:19 -07:00
|
|
|
mDownloadableFontsSanitize = UNINITIALIZED_VALUE;
|
2012-03-08 18:05:40 -08:00
|
|
|
mFallbackUsesCmaps = UNINITIALIZED_VALUE;
|
|
|
|
|
2011-12-09 14:32:29 -08:00
|
|
|
#ifdef MOZ_GRAPHITE
|
|
|
|
mGraphiteShapingEnabled = UNINITIALIZED_VALUE;
|
|
|
|
#endif
|
2011-12-06 04:39:19 -08:00
|
|
|
mBidiNumeralOption = UNINITIALIZED_VALUE;
|
2012-01-27 14:38:00 -08:00
|
|
|
|
|
|
|
if (Preferences::GetBool("gfx.canvas.azure.prefer-skia", false)) {
|
|
|
|
mPreferredDrawTargetBackend = BACKEND_SKIA;
|
|
|
|
} else {
|
|
|
|
mPreferredDrawTargetBackend = BACKEND_NONE;
|
|
|
|
}
|
2010-05-26 22:05:30 -07:00
|
|
|
}
|
2008-01-30 16:23:36 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
gfxPlatform*
|
|
|
|
gfxPlatform::GetPlatform()
|
|
|
|
{
|
2011-04-21 12:36:49 -07:00
|
|
|
if (!gPlatform) {
|
|
|
|
Init();
|
|
|
|
}
|
2007-03-29 14:48:46 -07:00
|
|
|
return gPlatform;
|
|
|
|
}
|
|
|
|
|
2011-04-21 12:36:53 -07:00
|
|
|
void
|
2007-03-29 14:48:46 -07:00
|
|
|
gfxPlatform::Init()
|
|
|
|
{
|
2011-04-21 12:36:49 -07:00
|
|
|
if (gEverInitialized) {
|
|
|
|
NS_RUNTIMEABORT("Already started???");
|
|
|
|
}
|
|
|
|
gEverInitialized = true;
|
2010-02-24 09:57:57 -08:00
|
|
|
|
2011-01-21 08:44:33 -08:00
|
|
|
#ifdef PR_LOGGING
|
|
|
|
sFontlistLog = PR_NewLogModule("fontlist");;
|
|
|
|
sFontInitLog = PR_NewLogModule("fontinit");;
|
|
|
|
sTextrunLog = PR_NewLogModule("textrun");;
|
|
|
|
sTextrunuiLog = PR_NewLogModule("textrunui");;
|
2012-03-08 18:05:14 -08:00
|
|
|
sCmapDataLog = PR_NewLogModule("cmapdata");;
|
2011-01-21 08:44:33 -08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2010-08-28 07:18:41 -07:00
|
|
|
/* Initialize the GfxInfo service.
|
|
|
|
* Note: we can't call functions on GfxInfo that depend
|
|
|
|
* on gPlatform until after it has been initialized
|
|
|
|
* below. GfxInfo initialization annotates our
|
|
|
|
* crash reports so we want to do it before
|
|
|
|
* we try to load any drivers and do device detection
|
|
|
|
* incase that code crashes. See bug #591561. */
|
|
|
|
nsCOMPtr<nsIGfxInfo> gfxInfo;
|
|
|
|
/* this currently will only succeed on Windows */
|
|
|
|
gfxInfo = do_GetService("@mozilla.org/gfx/info;1");
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#if defined(XP_WIN)
|
2007-03-29 14:48:46 -07:00
|
|
|
gPlatform = new gfxWindowsPlatform;
|
2007-03-22 10:30:00 -07:00
|
|
|
#elif defined(XP_MACOSX)
|
2007-03-29 14:48:46 -07:00
|
|
|
gPlatform = new gfxPlatformMac;
|
2012-06-27 17:15:32 -07:00
|
|
|
#elif defined(MOZ_WIDGET_GTK)
|
2007-03-29 14:48:46 -07:00
|
|
|
gPlatform = new gfxPlatformGtk;
|
2008-04-19 06:19:04 -07:00
|
|
|
#elif defined(MOZ_WIDGET_QT)
|
|
|
|
gPlatform = new gfxQtPlatform;
|
2007-03-22 10:30:00 -07:00
|
|
|
#elif defined(XP_OS2)
|
2007-03-29 14:48:46 -07:00
|
|
|
gPlatform = new gfxOS2Platform;
|
2010-05-11 10:27:36 -07:00
|
|
|
#elif defined(ANDROID)
|
|
|
|
gPlatform = new gfxAndroidPlatform;
|
2011-04-16 18:22:41 -07:00
|
|
|
#else
|
|
|
|
#error "No gfxPlatform implementation available"
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
2007-03-29 14:48:46 -07:00
|
|
|
|
2012-05-12 16:23:56 -07:00
|
|
|
#ifdef DEBUG
|
|
|
|
mozilla::gl::GLContext::StaticInit();
|
|
|
|
#endif
|
|
|
|
|
2007-03-29 14:48:46 -07:00
|
|
|
nsresult rv;
|
|
|
|
|
2010-07-15 23:03:45 -07:00
|
|
|
#if defined(XP_MACOSX) || defined(XP_WIN) || defined(ANDROID) // temporary, until this is implemented on others
|
2009-08-16 06:52:12 -07:00
|
|
|
rv = gfxPlatformFontList::Init();
|
2007-03-29 14:48:46 -07:00
|
|
|
if (NS_FAILED(rv)) {
|
2011-04-21 12:36:53 -07:00
|
|
|
NS_RUNTIMEABORT("Could not initialize gfxPlatformFontList");
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2007-03-29 14:48:46 -07:00
|
|
|
#endif
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-11-08 03:02:27 -08:00
|
|
|
gPlatform->mScreenReferenceSurface =
|
|
|
|
gPlatform->CreateOffscreenSurface(gfxIntSize(1,1),
|
|
|
|
gfxASurface::CONTENT_COLOR_ALPHA);
|
|
|
|
if (!gPlatform->mScreenReferenceSurface) {
|
2011-04-21 12:36:53 -07:00
|
|
|
NS_RUNTIMEABORT("Could not initialize mScreenReferenceSurface");
|
2010-11-08 03:02:27 -08:00
|
|
|
}
|
|
|
|
|
2007-04-03 20:32:43 -07:00
|
|
|
rv = gfxFontCache::Init();
|
|
|
|
if (NS_FAILED(rv)) {
|
2011-04-21 12:36:53 -07:00
|
|
|
NS_RUNTIMEABORT("Could not initialize gfxFontCache");
|
2007-04-03 20:32:43 -07:00
|
|
|
}
|
|
|
|
|
2008-08-11 21:55:36 -07:00
|
|
|
/* Pref migration hook. */
|
|
|
|
MigratePrefs();
|
|
|
|
|
2008-09-08 14:47:26 -07:00
|
|
|
/* Create and register our CMS Override observer. */
|
2011-06-11 19:30:16 -07:00
|
|
|
gPlatform->mSRGBOverrideObserver = new SRGBOverrideObserver();
|
2011-07-27 10:56:22 -07:00
|
|
|
Preferences::AddWeakObserver(gPlatform->mSRGBOverrideObserver, "gfx.color_management.force_srgb");
|
2011-06-11 19:30:16 -07:00
|
|
|
|
|
|
|
gPlatform->mFontPrefsObserver = new FontPrefsObserver();
|
|
|
|
Preferences::AddStrongObservers(gPlatform->mFontPrefsObserver, kObservedPrefs);
|
2011-04-21 12:36:49 -07:00
|
|
|
|
2012-04-10 08:49:10 -07:00
|
|
|
gPlatform->mWorkAroundDriverBugs = Preferences::GetBool("gfx.work-around-driver-bugs", true);
|
|
|
|
|
2011-04-21 12:36:49 -07:00
|
|
|
// Force registration of the gfx component, thus arranging for
|
|
|
|
// ::Shutdown to be called.
|
|
|
|
nsCOMPtr<nsISupports> forceReg
|
|
|
|
= do_CreateInstance("@mozilla.org/gfx/init;1");
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gfxPlatform::Shutdown()
|
|
|
|
{
|
2007-03-29 14:48:46 -07:00
|
|
|
// These may be called before the corresponding subsystems have actually
|
|
|
|
// started up. That's OK, they can handle it.
|
2007-04-03 20:32:43 -07:00
|
|
|
gfxFontCache::Shutdown();
|
2010-02-24 09:57:44 -08:00
|
|
|
gfxFontGroup::Shutdown();
|
2011-12-09 14:32:29 -08:00
|
|
|
#ifdef MOZ_GRAPHITE
|
|
|
|
gfxGraphiteShaper::Shutdown();
|
|
|
|
#endif
|
2009-10-07 07:13:40 -07:00
|
|
|
#if defined(XP_MACOSX) || defined(XP_WIN) // temporary, until this is implemented on others
|
2009-08-16 06:52:12 -07:00
|
|
|
gfxPlatformFontList::Shutdown();
|
2007-03-29 14:48:46 -07:00
|
|
|
#endif
|
2008-07-16 20:09:08 -07:00
|
|
|
|
|
|
|
// Free the various non-null transforms and loaded profiles
|
2008-09-08 14:47:26 -07:00
|
|
|
ShutdownCMS();
|
2008-07-16 20:09:08 -07:00
|
|
|
|
2011-06-11 19:30:16 -07:00
|
|
|
// 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");
|
2011-07-27 10:56:22 -07:00
|
|
|
Preferences::RemoveObserver(gPlatform->mSRGBOverrideObserver, "gfx.color_management.force_srgb");
|
2011-06-11 19:30:16 -07:00
|
|
|
gPlatform->mSRGBOverrideObserver = nsnull;
|
|
|
|
|
|
|
|
NS_ASSERTION(gPlatform->mFontPrefsObserver, "mFontPrefsObserver has alreay gone");
|
|
|
|
Preferences::RemoveObservers(gPlatform->mFontPrefsObserver, kObservedPrefs);
|
|
|
|
gPlatform->mFontPrefsObserver = nsnull;
|
|
|
|
}
|
2009-09-09 18:22:03 -07:00
|
|
|
|
2012-02-09 11:05:11 -08:00
|
|
|
// Shut down the default GL context provider.
|
2010-07-19 21:05:42 -07:00
|
|
|
mozilla::gl::GLContextProvider::Shutdown();
|
2012-02-09 11:05:11 -08:00
|
|
|
|
|
|
|
// We always have OSMesa at least potentially available; shut it down too.
|
2012-02-06 19:09:28 -08:00
|
|
|
mozilla::gl::GLContextProviderOSMesa::Shutdown();
|
|
|
|
|
|
|
|
#if defined(XP_WIN)
|
2012-02-09 11:05:11 -08:00
|
|
|
// The above shutdown calls operate on the available context providers on
|
|
|
|
// most platforms. Windows is a "special snowflake", though, and has three
|
|
|
|
// context providers available, so we have to shut all of them down.
|
|
|
|
// We should only support the default GL provider on Windows; then, this
|
|
|
|
// could go away. Unfortunately, we currently support WGL (the default) for
|
|
|
|
// WebGL on Optimus.
|
2012-02-06 19:09:28 -08:00
|
|
|
mozilla::gl::GLContextProviderEGL::Shutdown();
|
|
|
|
#endif
|
2010-07-19 21:05:42 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
delete gPlatform;
|
|
|
|
gPlatform = nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
gfxPlatform::~gfxPlatform()
|
|
|
|
{
|
2012-05-11 14:21:41 -07:00
|
|
|
mScreenReferenceSurface = nsnull;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// The cairo folks think we should only clean up in debug builds,
|
|
|
|
// but we're generally in the habit of trying to shut down as
|
|
|
|
// cleanly as possible even in production code, so call this
|
|
|
|
// cairo_debug_* function unconditionally.
|
2007-10-25 18:21:50 -07:00
|
|
|
//
|
|
|
|
// because cairo can assert and thus crash on shutdown, don't do this in release builds
|
2008-02-11 22:47:40 -08:00
|
|
|
#if MOZ_TREE_CAIRO && (defined(DEBUG) || defined(NS_BUILD_REFCNT_LOGGING) || defined(NS_TRACE_MALLOC))
|
2007-03-22 10:30:00 -07:00
|
|
|
cairo_debug_reset_static_data();
|
2007-10-25 18:21:50 -07:00
|
|
|
#endif
|
2007-10-06 00:26:13 -07:00
|
|
|
|
|
|
|
#if 0
|
|
|
|
// It would be nice to do this (although it might need to be after
|
|
|
|
// the cairo shutdown that happens in ~gfxPlatform). It even looks
|
|
|
|
// idempotent. But it has fatal assertions that fire if stuff is
|
|
|
|
// leaked, and we hit them.
|
|
|
|
FcFini();
|
|
|
|
#endif
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-06-25 19:43:31 -07:00
|
|
|
already_AddRefed<gfxASurface>
|
|
|
|
gfxPlatform::CreateOffscreenImageSurface(const gfxIntSize& aSize,
|
|
|
|
gfxASurface::gfxContentType aContentType)
|
|
|
|
{
|
|
|
|
nsRefPtr<gfxASurface> newSurface;
|
|
|
|
newSurface = new gfxImageSurface(aSize, OptimalFormatForContent(aContentType));
|
|
|
|
|
|
|
|
return newSurface.forget();
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
already_AddRefed<gfxASurface>
|
2007-11-27 01:35:18 -08:00
|
|
|
gfxPlatform::OptimizeImage(gfxImageSurface *aSurface,
|
|
|
|
gfxASurface::gfxImageFormat format)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
const gfxIntSize& surfaceSize = aSurface->GetSize();
|
|
|
|
|
2010-02-25 22:36:07 -08:00
|
|
|
#ifdef XP_WIN
|
|
|
|
if (gfxWindowsPlatform::GetPlatform()->GetRenderMode() ==
|
|
|
|
gfxWindowsPlatform::RENDER_DIRECT2D) {
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
#endif
|
2010-09-16 14:34:53 -07:00
|
|
|
nsRefPtr<gfxASurface> optSurface = CreateOffscreenSurface(surfaceSize, gfxASurface::ContentFromFormat(format));
|
2007-11-27 01:35:18 -08:00
|
|
|
if (!optSurface || optSurface->CairoStatus() != 0)
|
2007-03-22 10:30:00 -07:00
|
|
|
return nsnull;
|
|
|
|
|
2007-12-31 20:42:49 -08:00
|
|
|
gfxContext tmpCtx(optSurface);
|
|
|
|
tmpCtx.SetOperator(gfxContext::OPERATOR_SOURCE);
|
|
|
|
tmpCtx.SetSource(aSurface);
|
|
|
|
tmpCtx.Paint();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
gfxASurface *ret = optSurface;
|
|
|
|
NS_ADDREF(ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-06-24 10:41:18 -07:00
|
|
|
cairo_user_data_key_t kDrawTarget;
|
|
|
|
|
|
|
|
RefPtr<DrawTarget>
|
|
|
|
gfxPlatform::CreateDrawTargetForSurface(gfxASurface *aSurface)
|
|
|
|
{
|
2012-01-27 10:09:20 -08:00
|
|
|
RefPtr<DrawTarget> drawTarget = Factory::CreateDrawTargetForCairoSurface(aSurface->CairoSurface());
|
|
|
|
aSurface->SetData(&kDrawTarget, drawTarget, NULL);
|
|
|
|
return drawTarget;
|
2011-06-24 10:41:18 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
cairo_user_data_key_t kSourceSurface;
|
|
|
|
|
|
|
|
void SourceBufferDestroy(void *srcBuffer)
|
|
|
|
{
|
|
|
|
static_cast<SourceSurface*>(srcBuffer)->Release();
|
|
|
|
}
|
|
|
|
|
2012-01-30 21:15:23 -08:00
|
|
|
void SourceSnapshotDetached(cairo_surface_t *nullSurf)
|
|
|
|
{
|
|
|
|
gfxImageSurface* origSurf =
|
|
|
|
static_cast<gfxImageSurface*>(cairo_surface_get_user_data(nullSurf, &kSourceSurface));
|
|
|
|
|
|
|
|
origSurf->SetData(&kSourceSurface, NULL, NULL);
|
|
|
|
}
|
|
|
|
|
2011-06-24 10:41:18 -07:00
|
|
|
RefPtr<SourceSurface>
|
|
|
|
gfxPlatform::GetSourceSurfaceForSurface(DrawTarget *aTarget, gfxASurface *aSurface)
|
|
|
|
{
|
|
|
|
void *userData = aSurface->GetData(&kSourceSurface);
|
|
|
|
|
|
|
|
if (userData) {
|
|
|
|
return static_cast<SourceSurface*>(userData);
|
|
|
|
}
|
|
|
|
|
|
|
|
SurfaceFormat format;
|
|
|
|
if (aSurface->GetContentType() == gfxASurface::CONTENT_ALPHA) {
|
|
|
|
format = FORMAT_A8;
|
|
|
|
} else if (aSurface->GetContentType() == gfxASurface::CONTENT_COLOR) {
|
|
|
|
format = FORMAT_B8G8R8X8;
|
|
|
|
} else {
|
|
|
|
format = FORMAT_B8G8R8A8;
|
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<SourceSurface> srcBuffer;
|
|
|
|
|
|
|
|
#ifdef XP_WIN
|
|
|
|
if (aSurface->GetType() == gfxASurface::SurfaceTypeD2D) {
|
|
|
|
NativeSurface surf;
|
|
|
|
surf.mFormat = format;
|
|
|
|
surf.mType = NATIVE_SURFACE_D3D10_TEXTURE;
|
|
|
|
surf.mSurface = static_cast<gfxD2DSurface*>(aSurface)->GetTexture();
|
|
|
|
mozilla::gfx::DrawTarget *dt = static_cast<mozilla::gfx::DrawTarget*>(aSurface->GetData(&kDrawTarget));
|
|
|
|
if (dt) {
|
|
|
|
dt->Flush();
|
|
|
|
}
|
|
|
|
srcBuffer = aTarget->CreateSourceSurfaceFromNativeSurface(surf);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (!srcBuffer) {
|
|
|
|
nsRefPtr<gfxImageSurface> imgSurface = aSurface->GetAsImageSurface();
|
|
|
|
|
2012-05-21 08:27:32 -07:00
|
|
|
bool isWin32ImageSurf = false;
|
|
|
|
|
|
|
|
if (imgSurface && aSurface->GetType() != gfxASurface::SurfaceTypeWin32) {
|
|
|
|
isWin32ImageSurf = true;
|
|
|
|
}
|
|
|
|
|
2011-06-24 10:41:18 -07:00
|
|
|
if (!imgSurface) {
|
2012-05-25 21:38:17 -07:00
|
|
|
imgSurface = new gfxImageSurface(aSurface->GetSize(), OptimalFormatForContent(aSurface->GetContentType()));
|
2011-06-24 10:41:18 -07:00
|
|
|
nsRefPtr<gfxContext> ctx = new gfxContext(imgSurface);
|
|
|
|
ctx->SetSource(aSurface);
|
|
|
|
ctx->SetOperator(gfxContext::OPERATOR_SOURCE);
|
|
|
|
ctx->Paint();
|
|
|
|
}
|
|
|
|
|
2011-11-02 12:55:03 -07:00
|
|
|
gfxImageFormat cairoFormat = imgSurface->Format();
|
|
|
|
switch(cairoFormat) {
|
|
|
|
case gfxASurface::ImageFormatARGB32:
|
|
|
|
format = FORMAT_B8G8R8A8;
|
|
|
|
break;
|
|
|
|
case gfxASurface::ImageFormatRGB24:
|
|
|
|
format = FORMAT_B8G8R8X8;
|
|
|
|
break;
|
|
|
|
case gfxASurface::ImageFormatA8:
|
|
|
|
format = FORMAT_A8;
|
|
|
|
break;
|
|
|
|
case gfxASurface::ImageFormatRGB16_565:
|
|
|
|
format = FORMAT_R5G6B5;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
NS_RUNTIMEABORT("Invalid surface format!");
|
|
|
|
}
|
|
|
|
|
2012-05-21 08:27:32 -07:00
|
|
|
IntSize size = IntSize(imgSurface->GetSize().width, imgSurface->GetSize().height);
|
2011-06-24 10:41:18 -07:00
|
|
|
srcBuffer = aTarget->CreateSourceSurfaceFromData(imgSurface->Data(),
|
2012-05-21 08:27:32 -07:00
|
|
|
size,
|
2011-06-24 10:41:18 -07:00
|
|
|
imgSurface->Stride(),
|
|
|
|
format);
|
2012-01-30 21:15:23 -08:00
|
|
|
|
2012-05-21 08:27:32 -07:00
|
|
|
if (!srcBuffer) {
|
|
|
|
// We need to check if our gfxASurface will keep the underlying data
|
|
|
|
// alive! This is true if gfxASurface actually -is- an ImageSurface or
|
|
|
|
// if it is a gfxWindowsSurface which supportes GetAsImageSurface.
|
|
|
|
if (imgSurface != aSurface && !isWin32ImageSurf) {
|
|
|
|
// This shouldn't happen for now, it can be easily supported by making
|
|
|
|
// a copy. For now let's just abort.
|
|
|
|
NS_RUNTIMEABORT("Attempt to create unsupported SourceSurface from"
|
|
|
|
"non-image surface.");
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
srcBuffer = Factory::CreateWrappingDataSourceSurface(imgSurface->Data(),
|
|
|
|
imgSurface->Stride(),
|
|
|
|
size, format);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-01-30 21:15:23 -08:00
|
|
|
cairo_surface_t *nullSurf =
|
|
|
|
cairo_null_surface_create(CAIRO_CONTENT_COLOR_ALPHA);
|
|
|
|
cairo_surface_set_user_data(nullSurf,
|
2012-05-21 08:27:32 -07:00
|
|
|
&kSourceSurface,
|
|
|
|
imgSurface,
|
|
|
|
NULL);
|
2012-01-30 21:15:23 -08:00
|
|
|
cairo_surface_attach_snapshot(imgSurface->CairoSurface(), nullSurf, SourceSnapshotDetached);
|
|
|
|
cairo_surface_destroy(nullSurf);
|
2011-06-24 10:41:18 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
srcBuffer->AddRef();
|
|
|
|
aSurface->SetData(&kSourceSurface, srcBuffer, SourceBufferDestroy);
|
|
|
|
|
|
|
|
return srcBuffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<ScaledFont>
|
|
|
|
gfxPlatform::GetScaledFontForFont(gfxFont *aFont)
|
|
|
|
{
|
2012-01-10 10:26:59 -08:00
|
|
|
NativeFont nativeFont;
|
|
|
|
nativeFont.mType = NATIVE_FONT_CAIRO_FONT_FACE;
|
|
|
|
nativeFont.mFont = aFont;
|
|
|
|
RefPtr<ScaledFont> scaledFont =
|
|
|
|
Factory::CreateScaledFontForNativeFont(nativeFont,
|
|
|
|
aFont->GetAdjustedSize());
|
|
|
|
return scaledFont;
|
2011-06-24 10:41:18 -07:00
|
|
|
}
|
|
|
|
|
2012-01-27 10:08:58 -08:00
|
|
|
UserDataKey kThebesSurfaceKey;
|
|
|
|
void
|
|
|
|
DestroyThebesSurface(void *data)
|
2012-01-13 06:48:29 -08:00
|
|
|
{
|
|
|
|
gfxASurface *surface = static_cast<gfxASurface*>(data);
|
|
|
|
surface->Release();
|
|
|
|
}
|
|
|
|
|
2011-06-24 10:41:18 -07:00
|
|
|
already_AddRefed<gfxASurface>
|
|
|
|
gfxPlatform::GetThebesSurfaceForDrawTarget(DrawTarget *aTarget)
|
|
|
|
{
|
2012-01-27 10:08:58 -08:00
|
|
|
// If we have already created a thebes surface, we can just return it.
|
|
|
|
void *surface = aTarget->GetUserData(&kThebesSurfaceKey);
|
2012-01-13 06:48:29 -08:00
|
|
|
if (surface) {
|
|
|
|
nsRefPtr<gfxASurface> surf = static_cast<gfxASurface*>(surface);
|
|
|
|
return surf.forget();
|
|
|
|
}
|
|
|
|
|
2012-01-27 10:09:20 -08:00
|
|
|
nsRefPtr<gfxASurface> surf;
|
|
|
|
if (aTarget->GetType() == BACKEND_CAIRO) {
|
|
|
|
cairo_surface_t* csurf =
|
|
|
|
static_cast<cairo_surface_t*>(aTarget->GetNativeSurface(NATIVE_SURFACE_CAIRO_SURFACE));
|
|
|
|
surf = gfxASurface::Wrap(csurf);
|
|
|
|
} else {
|
|
|
|
// The semantics of this part of the function are sort of weird. If we
|
|
|
|
// don't have direct support for the backend, we snapshot the first time
|
|
|
|
// and then return the snapshotted surface for the lifetime of the draw
|
|
|
|
// target. Sometimes it seems like this works out, but it seems like it
|
|
|
|
// might result in no updates ever.
|
|
|
|
RefPtr<SourceSurface> source = aTarget->Snapshot();
|
|
|
|
RefPtr<DataSourceSurface> data = source->GetDataSurface();
|
|
|
|
|
|
|
|
if (!data) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2011-11-02 12:55:03 -07:00
|
|
|
|
2012-01-27 10:09:20 -08:00
|
|
|
IntSize size = data->GetSize();
|
2012-05-25 21:38:17 -07:00
|
|
|
gfxASurface::gfxImageFormat format = OptimalFormatForContent(ContentForFormat(data->GetFormat()));
|
2011-11-02 12:55:03 -07:00
|
|
|
|
2012-06-14 15:00:44 -07:00
|
|
|
// We need to make a copy here because data might change its data under us
|
|
|
|
nsRefPtr<gfxImageSurface> imageSurf = new gfxImageSurface(gfxIntSize(size.width, size.height), format, false);
|
|
|
|
|
|
|
|
bool resultOfCopy = imageSurf->CopyFrom(source);
|
|
|
|
NS_ASSERTION(resultOfCopy, "Failed to copy surface.");
|
|
|
|
surf = imageSurf;
|
2012-01-27 10:09:20 -08:00
|
|
|
}
|
2012-01-13 06:48:29 -08:00
|
|
|
|
|
|
|
// add a reference to be held by the drawTarget
|
|
|
|
// careful, the reference graph is getting complicated here
|
|
|
|
surf->AddRef();
|
2012-01-27 10:08:58 -08:00
|
|
|
aTarget->AddUserData(&kThebesSurfaceKey, surf.get(), DestroyThebesSurface);
|
2012-01-13 06:48:29 -08:00
|
|
|
|
|
|
|
return surf.forget();
|
2011-11-02 12:55:03 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<DrawTarget>
|
|
|
|
gfxPlatform::CreateOffscreenDrawTarget(const IntSize& aSize, SurfaceFormat aFormat)
|
|
|
|
{
|
2011-11-17 20:00:38 -08:00
|
|
|
BackendType backend;
|
|
|
|
if (!SupportsAzure(backend)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2012-01-27 10:09:20 -08:00
|
|
|
|
|
|
|
// There is a bunch of knowledge in the gfxPlatform heirarchy about how to
|
|
|
|
// create the best offscreen surface for the current system and situation. We
|
|
|
|
// can easily take advantage of this for the Cairo backend, so that's what we
|
|
|
|
// do.
|
|
|
|
// mozilla::gfx::Factory can get away without having all this knowledge for
|
|
|
|
// now, but this might need to change in the future (using
|
|
|
|
// CreateOffscreenSurface() and CreateDrawTargetForSurface() for all
|
|
|
|
// backends).
|
|
|
|
if (backend == BACKEND_CAIRO) {
|
|
|
|
nsRefPtr<gfxASurface> surf = CreateOffscreenSurface(ThebesIntSize(aSize),
|
|
|
|
ContentForFormat(aFormat));
|
|
|
|
|
|
|
|
return CreateDrawTargetForSurface(surf);
|
|
|
|
} else {
|
|
|
|
return Factory::CreateDrawTarget(backend, aSize, aFormat);
|
|
|
|
}
|
2011-06-24 10:41:18 -07:00
|
|
|
}
|
|
|
|
|
2012-04-02 12:15:08 -07:00
|
|
|
RefPtr<DrawTarget>
|
|
|
|
gfxPlatform::CreateDrawTargetForData(unsigned char* aData, const IntSize& aSize, int32_t aStride, SurfaceFormat aFormat)
|
|
|
|
{
|
|
|
|
BackendType backend;
|
|
|
|
if (!SupportsAzure(backend)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return Factory::CreateDrawTargetForData(backend, aData, aSize, aStride, aFormat);
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult
|
2010-02-24 09:57:57 -08:00
|
|
|
gfxPlatform::GetFontList(nsIAtom *aLangGroup,
|
2007-03-22 10:30:00 -07:00
|
|
|
const nsACString& aGenericFamily,
|
2009-01-18 12:14:14 -08:00
|
|
|
nsTArray<nsString>& aListOfFonts)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
gfxPlatform::UpdateFontList()
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2008-09-30 20:01:53 -07:00
|
|
|
gfxPlatform::DownloadableFontsEnabled()
|
|
|
|
{
|
2010-05-26 22:05:30 -07:00
|
|
|
if (mAllowDownloadableFonts == UNINITIALIZED_VALUE) {
|
2010-10-07 00:59:19 -07:00
|
|
|
mAllowDownloadableFonts =
|
2011-09-28 23:19:26 -07:00
|
|
|
Preferences::GetBool(GFX_DOWNLOADABLE_FONTS_ENABLED, false);
|
2008-09-30 20:01:53 -07:00
|
|
|
}
|
|
|
|
|
2010-05-26 22:05:30 -07:00
|
|
|
return mAllowDownloadableFonts;
|
2008-09-30 20:01:53 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2010-10-07 00:59:19 -07:00
|
|
|
gfxPlatform::SanitizeDownloadedFonts()
|
|
|
|
{
|
|
|
|
if (mDownloadableFontsSanitize == UNINITIALIZED_VALUE) {
|
|
|
|
mDownloadableFontsSanitize =
|
2011-09-28 23:19:26 -07:00
|
|
|
Preferences::GetBool(GFX_DOWNLOADABLE_FONTS_SANITIZE, true);
|
2010-10-07 00:59:19 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return mDownloadableFontsSanitize;
|
|
|
|
}
|
|
|
|
|
2012-03-08 18:05:40 -08:00
|
|
|
bool
|
|
|
|
gfxPlatform::UseCmapsDuringSystemFallback()
|
|
|
|
{
|
|
|
|
if (mFallbackUsesCmaps == UNINITIALIZED_VALUE) {
|
|
|
|
mFallbackUsesCmaps =
|
|
|
|
Preferences::GetBool(GFX_PREF_FALLBACK_USE_CMAPS, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
return mFallbackUsesCmaps;
|
|
|
|
}
|
|
|
|
|
2011-12-09 14:32:29 -08:00
|
|
|
#ifdef MOZ_GRAPHITE
|
|
|
|
bool
|
|
|
|
gfxPlatform::UseGraphiteShaping()
|
|
|
|
{
|
|
|
|
if (mGraphiteShapingEnabled == UNINITIALIZED_VALUE) {
|
|
|
|
mGraphiteShapingEnabled =
|
|
|
|
Preferences::GetBool(GFX_PREF_GRAPHITE_SHAPING, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
return mGraphiteShapingEnabled;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2011-04-11 04:17:31 -07:00
|
|
|
gfxPlatform::UseHarfBuzzForScript(PRInt32 aScriptCode)
|
2009-10-07 10:16:52 -07:00
|
|
|
{
|
2011-04-11 04:17:31 -07:00
|
|
|
if (mUseHarfBuzzScripts == UNINITIALIZED_VALUE) {
|
2011-06-11 19:30:16 -07:00
|
|
|
mUseHarfBuzzScripts = Preferences::GetInt(GFX_PREF_HARFBUZZ_SCRIPTS, HARFBUZZ_SCRIPTS_DEFAULT);
|
2009-10-07 10:16:52 -07:00
|
|
|
}
|
|
|
|
|
2012-02-24 02:15:46 -08:00
|
|
|
PRInt32 shapingType = mozilla::unicode::ScriptShapingType(aScriptCode);
|
2011-04-11 04:17:31 -07:00
|
|
|
|
|
|
|
return (mUseHarfBuzzScripts & shapingType) != 0;
|
2009-10-07 10:16:52 -07:00
|
|
|
}
|
|
|
|
|
2009-08-30 06:55:24 -07:00
|
|
|
gfxFontEntry*
|
|
|
|
gfxPlatform::MakePlatformFont(const gfxProxyFontEntry *aProxyEntry,
|
|
|
|
const PRUint8 *aFontData,
|
|
|
|
PRUint32 aLength)
|
|
|
|
{
|
|
|
|
// Default implementation does not handle activating downloaded fonts;
|
|
|
|
// just free the data and return.
|
|
|
|
// Platforms that support @font-face must override this,
|
|
|
|
// using the data to instantiate the font, and taking responsibility
|
|
|
|
// for freeing it when no longer required.
|
|
|
|
if (aFontData) {
|
|
|
|
NS_Free((void*)aFontData);
|
|
|
|
}
|
|
|
|
return nsnull;
|
|
|
|
}
|
2008-09-30 20:01:53 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
static void
|
2010-02-24 09:57:57 -08:00
|
|
|
AppendGenericFontFromPref(nsString& aFonts, nsIAtom *aLangGroup, const char *aGenericName)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-06-11 19:30:16 -07:00
|
|
|
NS_ENSURE_TRUE(Preferences::GetRootBranch(), );
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-02-24 09:57:57 -08:00
|
|
|
nsCAutoString prefName, langGroupString;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-02-24 09:57:57 -08:00
|
|
|
aLangGroup->ToUTF8String(langGroupString);
|
|
|
|
|
2009-04-04 02:43:42 -07:00
|
|
|
nsCAutoString genericDotLang;
|
2007-03-22 10:30:00 -07:00
|
|
|
if (aGenericName) {
|
2009-04-04 02:43:42 -07:00
|
|
|
genericDotLang.Assign(aGenericName);
|
2007-03-22 10:30:00 -07:00
|
|
|
} else {
|
|
|
|
prefName.AssignLiteral("font.default.");
|
2010-02-24 09:57:57 -08:00
|
|
|
prefName.Append(langGroupString);
|
2011-06-11 19:30:16 -07:00
|
|
|
genericDotLang = Preferences::GetCString(prefName.get());
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
genericDotLang.AppendLiteral(".");
|
2010-02-24 09:57:57 -08:00
|
|
|
genericDotLang.Append(langGroupString);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-12-27 17:28:26 -08:00
|
|
|
// fetch font.name.xxx value
|
2007-03-22 10:30:00 -07:00
|
|
|
prefName.AssignLiteral("font.name.");
|
|
|
|
prefName.Append(genericDotLang);
|
2011-06-11 19:30:16 -07:00
|
|
|
nsAdoptingString nameValue = Preferences::GetString(prefName.get());
|
|
|
|
if (nameValue) {
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!aFonts.IsEmpty())
|
|
|
|
aFonts.AppendLiteral(", ");
|
2011-06-11 19:30:16 -07:00
|
|
|
aFonts += nameValue;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2007-12-27 17:28:26 -08:00
|
|
|
// fetch font.name-list.xxx value
|
2007-03-22 10:30:00 -07:00
|
|
|
prefName.AssignLiteral("font.name-list.");
|
|
|
|
prefName.Append(genericDotLang);
|
2011-06-11 19:30:16 -07:00
|
|
|
nsAdoptingString nameListValue = Preferences::GetString(prefName.get());
|
|
|
|
if (nameListValue && !nameListValue.Equals(nameValue)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!aFonts.IsEmpty())
|
|
|
|
aFonts.AppendLiteral(", ");
|
2011-06-11 19:30:16 -07:00
|
|
|
aFonts += nameListValue;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-09-28 23:19:26 -07:00
|
|
|
gfxPlatform::GetPrefFonts(nsIAtom *aLanguage, nsString& aFonts, bool aAppendUnicode)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
aFonts.Truncate();
|
|
|
|
|
2010-02-24 09:57:44 -08:00
|
|
|
AppendGenericFontFromPref(aFonts, aLanguage, nsnull);
|
2007-07-18 07:22:06 -07:00
|
|
|
if (aAppendUnicode)
|
2012-03-29 14:08:43 -07:00
|
|
|
AppendGenericFontFromPref(aFonts, nsGkAtoms::Unicode, nsnull);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool gfxPlatform::ForEachPrefFont(eFontPrefLang aLangArray[], PRUint32 aLangArrayLen, PrefFontCallback aCallback,
|
2008-01-30 16:23:36 -08:00
|
|
|
void *aClosure)
|
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
NS_ENSURE_TRUE(Preferences::GetRootBranch(), false);
|
2008-01-30 16:23:36 -08:00
|
|
|
|
|
|
|
PRUint32 i;
|
|
|
|
for (i = 0; i < aLangArrayLen; i++) {
|
|
|
|
eFontPrefLang prefLang = aLangArray[i];
|
|
|
|
const char *langGroup = GetPrefLangName(prefLang);
|
|
|
|
|
|
|
|
nsCAutoString prefName;
|
|
|
|
|
|
|
|
prefName.AssignLiteral("font.default.");
|
|
|
|
prefName.Append(langGroup);
|
2011-06-11 19:30:16 -07:00
|
|
|
nsAdoptingCString genericDotLang = Preferences::GetCString(prefName.get());
|
2008-01-30 16:23:36 -08:00
|
|
|
|
|
|
|
genericDotLang.AppendLiteral(".");
|
|
|
|
genericDotLang.Append(langGroup);
|
|
|
|
|
|
|
|
// fetch font.name.xxx value
|
|
|
|
prefName.AssignLiteral("font.name.");
|
|
|
|
prefName.Append(genericDotLang);
|
2011-06-11 19:30:16 -07:00
|
|
|
nsAdoptingCString nameValue = Preferences::GetCString(prefName.get());
|
|
|
|
if (nameValue) {
|
2009-04-04 02:43:42 -07:00
|
|
|
if (!aCallback(prefLang, NS_ConvertUTF8toUTF16(nameValue), aClosure))
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2008-01-30 16:23:36 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// fetch font.name-list.xxx value
|
|
|
|
prefName.AssignLiteral("font.name-list.");
|
|
|
|
prefName.Append(genericDotLang);
|
2011-06-11 19:30:16 -07:00
|
|
|
nsAdoptingCString nameListValue = Preferences::GetCString(prefName.get());
|
|
|
|
if (nameListValue && !nameListValue.Equals(nameValue)) {
|
2009-10-07 07:13:40 -07:00
|
|
|
const char kComma = ',';
|
|
|
|
const char *p, *p_end;
|
|
|
|
nsCAutoString list(nameListValue);
|
|
|
|
list.BeginReading(p);
|
|
|
|
list.EndReading(p_end);
|
|
|
|
while (p < p_end) {
|
|
|
|
while (nsCRT::IsAsciiSpace(*p)) {
|
|
|
|
if (++p == p_end)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (p == p_end)
|
|
|
|
break;
|
|
|
|
const char *start = p;
|
|
|
|
while (++p != p_end && *p != kComma)
|
|
|
|
/* nothing */ ;
|
|
|
|
nsCAutoString fontName(Substring(start, p));
|
2011-10-17 07:59:28 -07:00
|
|
|
fontName.CompressWhitespace(false, true);
|
2009-10-07 07:13:40 -07:00
|
|
|
if (!aCallback(prefLang, NS_ConvertUTF8toUTF16(fontName), aClosure))
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2009-10-07 07:13:40 -07:00
|
|
|
p++;
|
|
|
|
}
|
2008-01-30 16:23:36 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2008-01-30 16:23:36 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
eFontPrefLang
|
|
|
|
gfxPlatform::GetFontPrefLangFor(const char* aLang)
|
|
|
|
{
|
|
|
|
if (!aLang || !aLang[0])
|
|
|
|
return eFontPrefLang_Others;
|
|
|
|
for (PRUint32 i = 0; i < PRUint32(eFontPrefLang_LangCount); ++i) {
|
|
|
|
if (!PL_strcasecmp(gPrefLangNames[i], aLang))
|
|
|
|
return eFontPrefLang(i);
|
|
|
|
}
|
|
|
|
return eFontPrefLang_Others;
|
|
|
|
}
|
|
|
|
|
2010-02-24 09:57:57 -08:00
|
|
|
eFontPrefLang
|
|
|
|
gfxPlatform::GetFontPrefLangFor(nsIAtom *aLang)
|
|
|
|
{
|
|
|
|
if (!aLang)
|
|
|
|
return eFontPrefLang_Others;
|
|
|
|
nsCAutoString lang;
|
|
|
|
aLang->ToUTF8String(lang);
|
|
|
|
return GetFontPrefLangFor(lang.get());
|
|
|
|
}
|
|
|
|
|
2008-01-30 16:23:36 -08:00
|
|
|
const char*
|
|
|
|
gfxPlatform::GetPrefLangName(eFontPrefLang aLang)
|
|
|
|
{
|
|
|
|
if (PRUint32(aLang) < PRUint32(eFontPrefLang_AllCount))
|
|
|
|
return gPrefLangNames[PRUint32(aLang)];
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
2009-10-07 08:26:58 -07:00
|
|
|
eFontPrefLang
|
|
|
|
gfxPlatform::GetFontPrefLangFor(PRUint8 aUnicodeRange)
|
|
|
|
{
|
|
|
|
switch (aUnicodeRange) {
|
|
|
|
case kRangeSetLatin: return eFontPrefLang_Western;
|
|
|
|
case kRangeCyrillic: return eFontPrefLang_Cyrillic;
|
|
|
|
case kRangeGreek: return eFontPrefLang_Greek;
|
|
|
|
case kRangeTurkish: return eFontPrefLang_Turkish;
|
|
|
|
case kRangeHebrew: return eFontPrefLang_Hebrew;
|
|
|
|
case kRangeArabic: return eFontPrefLang_Arabic;
|
|
|
|
case kRangeBaltic: return eFontPrefLang_Baltic;
|
|
|
|
case kRangeThai: return eFontPrefLang_Thai;
|
|
|
|
case kRangeKorean: return eFontPrefLang_Korean;
|
|
|
|
case kRangeJapanese: return eFontPrefLang_Japanese;
|
|
|
|
case kRangeSChinese: return eFontPrefLang_ChineseCN;
|
|
|
|
case kRangeTChinese: return eFontPrefLang_ChineseTW;
|
|
|
|
case kRangeDevanagari: return eFontPrefLang_Devanagari;
|
|
|
|
case kRangeTamil: return eFontPrefLang_Tamil;
|
|
|
|
case kRangeArmenian: return eFontPrefLang_Armenian;
|
|
|
|
case kRangeBengali: return eFontPrefLang_Bengali;
|
|
|
|
case kRangeCanadian: return eFontPrefLang_Canadian;
|
|
|
|
case kRangeEthiopic: return eFontPrefLang_Ethiopic;
|
|
|
|
case kRangeGeorgian: return eFontPrefLang_Georgian;
|
|
|
|
case kRangeGujarati: return eFontPrefLang_Gujarati;
|
|
|
|
case kRangeGurmukhi: return eFontPrefLang_Gurmukhi;
|
|
|
|
case kRangeKhmer: return eFontPrefLang_Khmer;
|
|
|
|
case kRangeMalayalam: return eFontPrefLang_Malayalam;
|
2011-03-31 01:47:02 -07:00
|
|
|
case kRangeOriya: return eFontPrefLang_Oriya;
|
|
|
|
case kRangeTelugu: return eFontPrefLang_Telugu;
|
|
|
|
case kRangeKannada: return eFontPrefLang_Kannada;
|
|
|
|
case kRangeSinhala: return eFontPrefLang_Sinhala;
|
|
|
|
case kRangeTibetan: return eFontPrefLang_Tibetan;
|
2009-10-07 08:26:58 -07:00
|
|
|
case kRangeSetCJK: return eFontPrefLang_CJKSet;
|
|
|
|
default: return eFontPrefLang_Others;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2008-01-30 16:23:36 -08:00
|
|
|
gfxPlatform::IsLangCJK(eFontPrefLang aLang)
|
|
|
|
{
|
2010-03-08 01:14:56 -08:00
|
|
|
switch (aLang) {
|
|
|
|
case eFontPrefLang_Japanese:
|
|
|
|
case eFontPrefLang_ChineseTW:
|
|
|
|
case eFontPrefLang_ChineseCN:
|
|
|
|
case eFontPrefLang_ChineseHK:
|
|
|
|
case eFontPrefLang_Korean:
|
|
|
|
case eFontPrefLang_CJKSet:
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2010-03-08 01:14:56 -08:00
|
|
|
default:
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2010-03-08 01:14:56 -08:00
|
|
|
}
|
2008-01-30 16:23:36 -08:00
|
|
|
}
|
|
|
|
|
2009-10-07 08:26:58 -07:00
|
|
|
void
|
|
|
|
gfxPlatform::GetLangPrefs(eFontPrefLang aPrefLangs[], PRUint32 &aLen, eFontPrefLang aCharLang, eFontPrefLang aPageLang)
|
|
|
|
{
|
|
|
|
if (IsLangCJK(aCharLang)) {
|
|
|
|
AppendCJKPrefLangs(aPrefLangs, aLen, aCharLang, aPageLang);
|
|
|
|
} else {
|
|
|
|
AppendPrefLang(aPrefLangs, aLen, aCharLang);
|
|
|
|
}
|
|
|
|
|
|
|
|
AppendPrefLang(aPrefLangs, aLen, eFontPrefLang_Others);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gfxPlatform::AppendCJKPrefLangs(eFontPrefLang aPrefLangs[], PRUint32 &aLen, eFontPrefLang aCharLang, eFontPrefLang aPageLang)
|
|
|
|
{
|
|
|
|
// prefer the lang specified by the page *if* CJK
|
|
|
|
if (IsLangCJK(aPageLang)) {
|
|
|
|
AppendPrefLang(aPrefLangs, aLen, aPageLang);
|
|
|
|
}
|
|
|
|
|
|
|
|
// if not set up, set up the default CJK order, based on accept lang settings and locale
|
|
|
|
if (mCJKPrefLangs.Length() == 0) {
|
|
|
|
|
|
|
|
// temp array
|
|
|
|
eFontPrefLang tempPrefLangs[kMaxLenPrefLangList];
|
|
|
|
PRUint32 tempLen = 0;
|
|
|
|
|
|
|
|
// Add the CJK pref fonts from accept languages, the order should be same order
|
2011-06-11 19:30:16 -07:00
|
|
|
nsAdoptingCString list = Preferences::GetLocalizedCString("intl.accept_languages");
|
2010-03-15 11:29:55 -07:00
|
|
|
if (!list.IsEmpty()) {
|
2009-10-07 08:26:58 -07:00
|
|
|
const char kComma = ',';
|
|
|
|
const char *p, *p_end;
|
|
|
|
list.BeginReading(p);
|
|
|
|
list.EndReading(p_end);
|
|
|
|
while (p < p_end) {
|
|
|
|
while (nsCRT::IsAsciiSpace(*p)) {
|
|
|
|
if (++p == p_end)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (p == p_end)
|
|
|
|
break;
|
|
|
|
const char *start = p;
|
|
|
|
while (++p != p_end && *p != kComma)
|
|
|
|
/* nothing */ ;
|
|
|
|
nsCAutoString lang(Substring(start, p));
|
2011-10-17 07:59:28 -07:00
|
|
|
lang.CompressWhitespace(false, true);
|
2009-10-07 08:26:58 -07:00
|
|
|
eFontPrefLang fpl = gfxPlatform::GetFontPrefLangFor(lang.get());
|
|
|
|
switch (fpl) {
|
|
|
|
case eFontPrefLang_Japanese:
|
|
|
|
case eFontPrefLang_Korean:
|
|
|
|
case eFontPrefLang_ChineseCN:
|
|
|
|
case eFontPrefLang_ChineseHK:
|
|
|
|
case eFontPrefLang_ChineseTW:
|
|
|
|
AppendPrefLang(tempPrefLangs, tempLen, fpl);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
do { // to allow 'break' to abort this block if a call fails
|
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsILocaleService> ls =
|
|
|
|
do_GetService(NS_LOCALESERVICE_CONTRACTID, &rv);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
break;
|
|
|
|
|
|
|
|
nsCOMPtr<nsILocale> appLocale;
|
|
|
|
rv = ls->GetApplicationLocale(getter_AddRefs(appLocale));
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
break;
|
|
|
|
|
|
|
|
nsString localeStr;
|
|
|
|
rv = appLocale->
|
|
|
|
GetCategory(NS_LITERAL_STRING(NSILOCALE_MESSAGE), localeStr);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
break;
|
|
|
|
|
|
|
|
const nsAString& lang = Substring(localeStr, 0, 2);
|
|
|
|
if (lang.EqualsLiteral("ja")) {
|
|
|
|
AppendPrefLang(tempPrefLangs, tempLen, eFontPrefLang_Japanese);
|
|
|
|
} else if (lang.EqualsLiteral("zh")) {
|
|
|
|
const nsAString& region = Substring(localeStr, 3, 2);
|
|
|
|
if (region.EqualsLiteral("CN")) {
|
|
|
|
AppendPrefLang(tempPrefLangs, tempLen, eFontPrefLang_ChineseCN);
|
|
|
|
} else if (region.EqualsLiteral("TW")) {
|
|
|
|
AppendPrefLang(tempPrefLangs, tempLen, eFontPrefLang_ChineseTW);
|
|
|
|
} else if (region.EqualsLiteral("HK")) {
|
|
|
|
AppendPrefLang(tempPrefLangs, tempLen, eFontPrefLang_ChineseHK);
|
|
|
|
}
|
|
|
|
} else if (lang.EqualsLiteral("ko")) {
|
|
|
|
AppendPrefLang(tempPrefLangs, tempLen, eFontPrefLang_Korean);
|
|
|
|
}
|
|
|
|
} while (0);
|
|
|
|
|
|
|
|
// last resort... (the order is same as old gfx.)
|
|
|
|
AppendPrefLang(tempPrefLangs, tempLen, eFontPrefLang_Japanese);
|
|
|
|
AppendPrefLang(tempPrefLangs, tempLen, eFontPrefLang_Korean);
|
|
|
|
AppendPrefLang(tempPrefLangs, tempLen, eFontPrefLang_ChineseCN);
|
|
|
|
AppendPrefLang(tempPrefLangs, tempLen, eFontPrefLang_ChineseHK);
|
|
|
|
AppendPrefLang(tempPrefLangs, tempLen, eFontPrefLang_ChineseTW);
|
|
|
|
|
|
|
|
// copy into the cached array
|
|
|
|
PRUint32 j;
|
|
|
|
for (j = 0; j < tempLen; j++) {
|
|
|
|
mCJKPrefLangs.AppendElement(tempPrefLangs[j]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// append in cached CJK langs
|
|
|
|
PRUint32 i, numCJKlangs = mCJKPrefLangs.Length();
|
|
|
|
|
|
|
|
for (i = 0; i < numCJKlangs; i++) {
|
|
|
|
AppendPrefLang(aPrefLangs, aLen, (eFontPrefLang) (mCJKPrefLangs[i]));
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2008-01-30 16:23:36 -08:00
|
|
|
void
|
|
|
|
gfxPlatform::AppendPrefLang(eFontPrefLang aPrefLangs[], PRUint32& aLen, eFontPrefLang aAddLang)
|
|
|
|
{
|
|
|
|
if (aLen >= kMaxLenPrefLangList) return;
|
|
|
|
|
|
|
|
// make sure
|
|
|
|
PRUint32 i = 0;
|
|
|
|
while (i < aLen && aPrefLangs[i] != aAddLang) {
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i == aLen) {
|
|
|
|
aPrefLangs[aLen] = aAddLang;
|
|
|
|
aLen++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-06 11:38:50 -07:00
|
|
|
bool
|
|
|
|
gfxPlatform::UseProgressiveTilePainting()
|
|
|
|
{
|
|
|
|
static bool sUseProgressiveTilePainting;
|
|
|
|
static bool sUseProgressiveTilePaintingPrefCached = false;
|
|
|
|
|
|
|
|
if (!sUseProgressiveTilePaintingPrefCached) {
|
|
|
|
sUseProgressiveTilePaintingPrefCached = true;
|
|
|
|
mozilla::Preferences::AddBoolVarCache(&sUseProgressiveTilePainting,
|
|
|
|
"layers.progressive-paint",
|
2012-07-08 08:36:49 -07:00
|
|
|
false);
|
2012-07-06 11:38:50 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return sUseProgressiveTilePainting;
|
|
|
|
}
|
|
|
|
|
2012-01-04 23:17:52 -08:00
|
|
|
bool
|
|
|
|
gfxPlatform::UseAzureContentDrawing()
|
|
|
|
{
|
|
|
|
static bool sAzureContentDrawingEnabled;
|
|
|
|
static bool sAzureContentDrawingPrefCached = false;
|
|
|
|
|
|
|
|
if (!sAzureContentDrawingPrefCached) {
|
|
|
|
sAzureContentDrawingPrefCached = true;
|
2012-07-06 11:38:50 -07:00
|
|
|
mozilla::Preferences::AddBoolVarCache(&sAzureContentDrawingEnabled,
|
2012-01-04 23:17:52 -08:00
|
|
|
"gfx.content.azure.enabled");
|
|
|
|
}
|
|
|
|
|
|
|
|
return sAzureContentDrawingEnabled;
|
|
|
|
}
|
|
|
|
|
2008-08-11 21:55:36 -07:00
|
|
|
eCMSMode
|
|
|
|
gfxPlatform::GetCMSMode()
|
2007-07-23 15:02:17 -07:00
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
if (gCMSInitialized == false) {
|
|
|
|
gCMSInitialized = true;
|
2011-07-27 10:56:22 -07:00
|
|
|
nsresult rv;
|
|
|
|
|
2011-06-11 19:30:16 -07:00
|
|
|
PRInt32 mode;
|
2011-07-27 10:56:22 -07:00
|
|
|
rv = Preferences::GetInt("gfx.color_management.mode", &mode);
|
2011-06-11 19:30:16 -07:00
|
|
|
if (NS_SUCCEEDED(rv) && (mode >= 0) && (mode < eCMSMode_AllCount)) {
|
|
|
|
gCMSMode = static_cast<eCMSMode>(mode);
|
2007-07-23 15:02:17 -07:00
|
|
|
}
|
2011-07-27 10:56:22 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool enableV4;
|
2011-07-27 13:09:27 -07:00
|
|
|
rv = Preferences::GetBool("gfx.color_management.enablev4", &enableV4);
|
|
|
|
if (NS_SUCCEEDED(rv) && enableV4) {
|
2011-07-27 10:56:22 -07:00
|
|
|
qcms_enable_iccv4();
|
|
|
|
}
|
2007-07-23 15:02:17 -07:00
|
|
|
}
|
2008-09-08 14:47:26 -07:00
|
|
|
return gCMSMode;
|
2007-07-23 15:02:17 -07:00
|
|
|
}
|
|
|
|
|
2008-07-23 10:33:12 -07:00
|
|
|
/* Chris Murphy (CM consultant) suggests this as a default in the event that we
|
|
|
|
cannot reproduce relative + Black Point Compensation. BPC brings an
|
|
|
|
unacceptable performance overhead, so we go with perceptual. */
|
2009-04-07 09:02:11 -07:00
|
|
|
#define INTENT_DEFAULT QCMS_INTENT_PERCEPTUAL
|
|
|
|
#define INTENT_MIN 0
|
|
|
|
#define INTENT_MAX 3
|
2008-07-23 10:33:12 -07:00
|
|
|
|
2011-07-26 23:43:37 -07:00
|
|
|
int
|
2008-07-23 10:33:12 -07:00
|
|
|
gfxPlatform::GetRenderingIntent()
|
|
|
|
{
|
2008-09-08 14:47:26 -07:00
|
|
|
if (gCMSIntent == -2) {
|
2008-07-23 10:33:12 -07:00
|
|
|
|
|
|
|
/* Try to query the pref system for a rendering intent. */
|
2011-06-11 19:30:16 -07:00
|
|
|
PRInt32 pIntent;
|
2011-07-27 10:56:22 -07:00
|
|
|
if (NS_SUCCEEDED(Preferences::GetInt("gfx.color_management.rendering_intent", &pIntent))) {
|
2011-06-11 19:30:16 -07:00
|
|
|
/* 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;
|
2008-07-23 10:33:12 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/* If we didn't get a valid intent from prefs, use the default. */
|
2011-06-11 19:30:16 -07:00
|
|
|
else {
|
2008-09-08 14:47:26 -07:00
|
|
|
gCMSIntent = INTENT_DEFAULT;
|
2011-06-11 19:30:16 -07:00
|
|
|
}
|
2008-07-23 10:33:12 -07:00
|
|
|
}
|
2008-09-08 14:47:26 -07:00
|
|
|
return gCMSIntent;
|
2008-07-23 10:33:12 -07:00
|
|
|
}
|
|
|
|
|
2008-09-10 19:21:03 -07:00
|
|
|
void
|
2009-04-07 09:02:11 -07:00
|
|
|
gfxPlatform::TransformPixel(const gfxRGBA& in, gfxRGBA& out, qcms_transform *transform)
|
2008-09-10 19:21:03 -07:00
|
|
|
{
|
|
|
|
|
|
|
|
if (transform) {
|
2009-04-07 09:02:11 -07:00
|
|
|
/* we want the bytes in RGB order */
|
2008-09-10 19:21:03 -07:00
|
|
|
#ifdef IS_LITTLE_ENDIAN
|
2009-04-07 09:02:11 -07:00
|
|
|
/* ABGR puts the bytes in |RGBA| order on little endian */
|
2008-09-10 19:21:03 -07:00
|
|
|
PRUint32 packed = in.Packed(gfxRGBA::PACKED_ABGR);
|
2009-04-07 09:02:11 -07:00
|
|
|
qcms_transform_data(transform,
|
2008-09-10 19:21:03 -07:00
|
|
|
(PRUint8 *)&packed, (PRUint8 *)&packed,
|
|
|
|
1);
|
|
|
|
out.~gfxRGBA();
|
|
|
|
new (&out) gfxRGBA(packed, gfxRGBA::PACKED_ABGR);
|
|
|
|
#else
|
2009-04-07 09:02:11 -07:00
|
|
|
/* ARGB puts the bytes in |ARGB| order on big endian */
|
2008-09-10 19:21:03 -07:00
|
|
|
PRUint32 packed = in.Packed(gfxRGBA::PACKED_ARGB);
|
2009-04-07 09:02:11 -07:00
|
|
|
/* add one to move past the alpha byte */
|
|
|
|
qcms_transform_data(transform,
|
2008-09-10 19:21:03 -07:00
|
|
|
(PRUint8 *)&packed + 1, (PRUint8 *)&packed + 1,
|
|
|
|
1);
|
|
|
|
out.~gfxRGBA();
|
|
|
|
new (&out) gfxRGBA(packed, gfxRGBA::PACKED_ARGB);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (&out != &in)
|
|
|
|
out = in;
|
|
|
|
}
|
2008-07-23 10:33:12 -07:00
|
|
|
|
2009-04-07 09:02:11 -07:00
|
|
|
qcms_profile *
|
2007-07-23 15:02:17 -07:00
|
|
|
gfxPlatform::GetPlatformCMSOutputProfile()
|
|
|
|
{
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
2009-04-07 09:02:11 -07:00
|
|
|
qcms_profile *
|
2007-07-23 15:02:17 -07:00
|
|
|
gfxPlatform::GetCMSOutputProfile()
|
|
|
|
{
|
|
|
|
if (!gCMSOutputProfile) {
|
2010-04-05 19:28:54 -07:00
|
|
|
NS_TIME_FUNCTION;
|
2007-07-23 15:02:17 -07:00
|
|
|
|
2011-06-11 19:30:16 -07:00
|
|
|
/* Determine if we're using the internal override to force sRGB as
|
|
|
|
an output profile for reftests. See Bug 452125.
|
2008-09-08 14:47:26 -07:00
|
|
|
|
2011-06-11 19:30:16 -07:00
|
|
|
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).
|
|
|
|
*/
|
2011-09-28 23:19:26 -07:00
|
|
|
if (Preferences::GetBool("gfx.color_management.force_srgb", false)) {
|
2011-06-11 19:30:16 -07:00
|
|
|
gCMSOutputProfile = GetCMSsRGBProfile();
|
|
|
|
}
|
2008-09-08 14:47:26 -07:00
|
|
|
|
2011-06-11 19:30:16 -07:00
|
|
|
if (!gCMSOutputProfile) {
|
2011-07-27 10:56:22 -07:00
|
|
|
nsAdoptingCString fname = Preferences::GetCString("gfx.color_management.display_profile");
|
2011-06-11 19:30:16 -07:00
|
|
|
if (!fname.IsEmpty()) {
|
|
|
|
gCMSOutputProfile = qcms_profile_from_path(fname);
|
2007-07-23 15:02:17 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!gCMSOutputProfile) {
|
|
|
|
gCMSOutputProfile =
|
|
|
|
gfxPlatform::GetPlatform()->GetPlatformCMSOutputProfile();
|
|
|
|
}
|
|
|
|
|
2008-12-06 22:32:24 -08:00
|
|
|
/* Determine if the profile looks bogus. If so, close the profile
|
|
|
|
* and use sRGB instead. See bug 460629, */
|
2009-04-07 09:02:11 -07:00
|
|
|
if (gCMSOutputProfile && qcms_profile_is_bogus(gCMSOutputProfile)) {
|
2008-12-06 22:32:24 -08:00
|
|
|
NS_ASSERTION(gCMSOutputProfile != GetCMSsRGBProfile(),
|
|
|
|
"Builtin sRGB profile tagged as bogus!!!");
|
2009-04-07 09:02:11 -07:00
|
|
|
qcms_profile_release(gCMSOutputProfile);
|
2008-12-06 22:32:24 -08:00
|
|
|
gCMSOutputProfile = nsnull;
|
|
|
|
}
|
|
|
|
|
2007-07-23 15:02:17 -07:00
|
|
|
if (!gCMSOutputProfile) {
|
2008-07-16 20:09:08 -07:00
|
|
|
gCMSOutputProfile = GetCMSsRGBProfile();
|
2007-07-23 15:02:17 -07:00
|
|
|
}
|
2008-08-15 13:59:18 -07:00
|
|
|
/* Precache the LUT16 Interpolations for the output profile. See
|
|
|
|
bug 444661 for details. */
|
2009-04-07 09:02:11 -07:00
|
|
|
qcms_profile_precache_output_transform(gCMSOutputProfile);
|
2007-07-23 15:02:17 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return gCMSOutputProfile;
|
|
|
|
}
|
|
|
|
|
2009-04-07 09:02:11 -07:00
|
|
|
qcms_profile *
|
2008-07-16 20:09:08 -07:00
|
|
|
gfxPlatform::GetCMSsRGBProfile()
|
|
|
|
{
|
2008-08-15 13:59:18 -07:00
|
|
|
if (!gCMSsRGBProfile) {
|
|
|
|
|
2009-09-16 23:17:19 -07:00
|
|
|
/* Create the profile using qcms. */
|
2009-04-07 09:02:11 -07:00
|
|
|
gCMSsRGBProfile = qcms_profile_sRGB();
|
2008-08-15 13:59:18 -07:00
|
|
|
}
|
2008-07-16 20:09:08 -07:00
|
|
|
return gCMSsRGBProfile;
|
|
|
|
}
|
|
|
|
|
2009-04-07 09:02:11 -07:00
|
|
|
qcms_transform *
|
2007-07-23 15:02:17 -07:00
|
|
|
gfxPlatform::GetCMSRGBTransform()
|
|
|
|
{
|
|
|
|
if (!gCMSRGBTransform) {
|
2009-04-07 09:02:11 -07:00
|
|
|
qcms_profile *inProfile, *outProfile;
|
2007-07-23 15:02:17 -07:00
|
|
|
outProfile = GetCMSOutputProfile();
|
2008-07-16 20:09:08 -07:00
|
|
|
inProfile = GetCMSsRGBProfile();
|
2007-07-23 15:02:17 -07:00
|
|
|
|
|
|
|
if (!inProfile || !outProfile)
|
|
|
|
return nsnull;
|
|
|
|
|
2009-04-07 09:02:11 -07:00
|
|
|
gCMSRGBTransform = qcms_transform_create(inProfile, QCMS_DATA_RGB_8,
|
|
|
|
outProfile, QCMS_DATA_RGB_8,
|
|
|
|
QCMS_INTENT_PERCEPTUAL);
|
2007-07-23 15:02:17 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return gCMSRGBTransform;
|
|
|
|
}
|
|
|
|
|
2009-04-07 09:02:11 -07:00
|
|
|
qcms_transform *
|
2007-08-30 09:21:16 -07:00
|
|
|
gfxPlatform::GetCMSInverseRGBTransform()
|
|
|
|
{
|
|
|
|
if (!gCMSInverseRGBTransform) {
|
2009-04-07 09:02:11 -07:00
|
|
|
qcms_profile *inProfile, *outProfile;
|
2007-08-30 09:21:16 -07:00
|
|
|
inProfile = GetCMSOutputProfile();
|
2008-07-16 20:09:08 -07:00
|
|
|
outProfile = GetCMSsRGBProfile();
|
2007-08-30 09:21:16 -07:00
|
|
|
|
|
|
|
if (!inProfile || !outProfile)
|
|
|
|
return nsnull;
|
|
|
|
|
2009-04-07 09:02:11 -07:00
|
|
|
gCMSInverseRGBTransform = qcms_transform_create(inProfile, QCMS_DATA_RGB_8,
|
|
|
|
outProfile, QCMS_DATA_RGB_8,
|
|
|
|
QCMS_INTENT_PERCEPTUAL);
|
2007-08-30 09:21:16 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return gCMSInverseRGBTransform;
|
|
|
|
}
|
|
|
|
|
2009-04-07 09:02:11 -07:00
|
|
|
qcms_transform *
|
2007-07-23 15:02:17 -07:00
|
|
|
gfxPlatform::GetCMSRGBATransform()
|
|
|
|
{
|
|
|
|
if (!gCMSRGBATransform) {
|
2009-04-07 09:02:11 -07:00
|
|
|
qcms_profile *inProfile, *outProfile;
|
2007-07-23 15:02:17 -07:00
|
|
|
outProfile = GetCMSOutputProfile();
|
2008-07-16 20:09:08 -07:00
|
|
|
inProfile = GetCMSsRGBProfile();
|
2007-07-23 15:02:17 -07:00
|
|
|
|
|
|
|
if (!inProfile || !outProfile)
|
|
|
|
return nsnull;
|
|
|
|
|
2009-04-07 09:02:11 -07:00
|
|
|
gCMSRGBATransform = qcms_transform_create(inProfile, QCMS_DATA_RGBA_8,
|
|
|
|
outProfile, QCMS_DATA_RGBA_8,
|
|
|
|
QCMS_INTENT_PERCEPTUAL);
|
2007-07-23 15:02:17 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return gCMSRGBATransform;
|
|
|
|
}
|
2008-08-11 21:55:36 -07:00
|
|
|
|
2008-09-08 14:47:26 -07:00
|
|
|
/* Shuts down various transforms and profiles for CMS. */
|
|
|
|
static void ShutdownCMS()
|
|
|
|
{
|
|
|
|
|
|
|
|
if (gCMSRGBTransform) {
|
2009-04-07 09:02:11 -07:00
|
|
|
qcms_transform_release(gCMSRGBTransform);
|
2008-09-08 14:47:26 -07:00
|
|
|
gCMSRGBTransform = nsnull;
|
|
|
|
}
|
|
|
|
if (gCMSInverseRGBTransform) {
|
2009-04-07 09:02:11 -07:00
|
|
|
qcms_transform_release(gCMSInverseRGBTransform);
|
2008-09-08 14:47:26 -07:00
|
|
|
gCMSInverseRGBTransform = nsnull;
|
|
|
|
}
|
|
|
|
if (gCMSRGBATransform) {
|
2009-04-07 09:02:11 -07:00
|
|
|
qcms_transform_release(gCMSRGBATransform);
|
2008-09-08 14:47:26 -07:00
|
|
|
gCMSRGBATransform = nsnull;
|
|
|
|
}
|
|
|
|
if (gCMSOutputProfile) {
|
2009-04-07 09:02:11 -07:00
|
|
|
qcms_profile_release(gCMSOutputProfile);
|
2008-09-08 14:47:26 -07:00
|
|
|
|
|
|
|
// handle the aliased case
|
|
|
|
if (gCMSsRGBProfile == gCMSOutputProfile)
|
|
|
|
gCMSsRGBProfile = nsnull;
|
|
|
|
gCMSOutputProfile = nsnull;
|
|
|
|
}
|
|
|
|
if (gCMSsRGBProfile) {
|
2009-04-07 09:02:11 -07:00
|
|
|
qcms_profile_release(gCMSsRGBProfile);
|
2008-09-08 14:47:26 -07:00
|
|
|
gCMSsRGBProfile = nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Reset the state variables
|
|
|
|
gCMSIntent = -2;
|
|
|
|
gCMSMode = eCMSMode_Off;
|
2011-10-17 07:59:28 -07:00
|
|
|
gCMSInitialized = false;
|
2008-09-08 14:47:26 -07:00
|
|
|
}
|
|
|
|
|
2008-08-11 21:55:36 -07:00
|
|
|
static void MigratePrefs()
|
|
|
|
{
|
|
|
|
/* Migrate from the boolean color_management.enabled pref - we now use
|
|
|
|
color_management.mode. */
|
2011-07-27 10:56:22 -07:00
|
|
|
if (Preferences::HasUserValue("gfx.color_management.enabled")) {
|
2011-09-28 23:19:26 -07:00
|
|
|
if (Preferences::GetBool("gfx.color_management.enabled", false)) {
|
2011-07-27 10:56:22 -07:00
|
|
|
Preferences::SetInt("gfx.color_management.mode", static_cast<PRInt32>(eCMSMode_All));
|
2011-06-11 19:30:16 -07:00
|
|
|
}
|
2011-07-27 10:56:22 -07:00
|
|
|
Preferences::ClearUser("gfx.color_management.enabled");
|
2008-08-11 21:55:36 -07:00
|
|
|
}
|
|
|
|
}
|
2009-09-22 05:45:56 -07:00
|
|
|
|
2009-10-07 08:26:58 -07:00
|
|
|
// default SetupClusterBoundaries, based on Unicode properties;
|
|
|
|
// platform subclasses may override if they wish
|
|
|
|
void
|
|
|
|
gfxPlatform::SetupClusterBoundaries(gfxTextRun *aTextRun, const PRUnichar *aString)
|
|
|
|
{
|
|
|
|
if (aTextRun->GetFlags() & gfxTextRunFactory::TEXT_IS_8BIT) {
|
|
|
|
// 8-bit text doesn't have clusters.
|
|
|
|
// XXX is this true in all languages???
|
|
|
|
// behdad: don't think so. Czech for example IIRC has a
|
|
|
|
// 'ch' grapheme.
|
2010-12-06 05:22:24 -08:00
|
|
|
// jfkthame: but that's not expected to behave as a grapheme cluster
|
|
|
|
// for selection/editing/etc.
|
2009-10-07 08:26:58 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-12-06 04:39:19 -08:00
|
|
|
gfxShapedWord::SetupClusterBoundaries(aTextRun->GetCharacterGlyphs(),
|
|
|
|
aString, aTextRun->GetLength());
|
|
|
|
}
|
2010-12-06 05:22:24 -08:00
|
|
|
|
2011-12-06 04:39:19 -08:00
|
|
|
PRInt32
|
|
|
|
gfxPlatform::GetBidiNumeralOption()
|
|
|
|
{
|
|
|
|
if (mBidiNumeralOption == UNINITIALIZED_VALUE) {
|
|
|
|
mBidiNumeralOption = Preferences::GetInt(BIDI_NUMERAL_PREF, 0);
|
2009-10-07 08:26:58 -07:00
|
|
|
}
|
2011-12-06 04:39:19 -08:00
|
|
|
return mBidiNumeralOption;
|
2009-10-07 08:26:58 -07:00
|
|
|
}
|
2010-05-26 22:05:30 -07:00
|
|
|
|
|
|
|
void
|
2011-06-11 19:30:16 -07:00
|
|
|
gfxPlatform::FontsPrefsChanged(const char *aPref)
|
2010-05-26 22:05:30 -07:00
|
|
|
{
|
2009-10-07 10:16:52 -07:00
|
|
|
NS_ASSERTION(aPref != nsnull, "null preference");
|
2010-05-26 22:05:30 -07:00
|
|
|
if (!strcmp(GFX_DOWNLOADABLE_FONTS_ENABLED, aPref)) {
|
|
|
|
mAllowDownloadableFonts = UNINITIALIZED_VALUE;
|
2010-10-07 00:59:19 -07:00
|
|
|
} else if (!strcmp(GFX_DOWNLOADABLE_FONTS_SANITIZE, aPref)) {
|
|
|
|
mDownloadableFontsSanitize = UNINITIALIZED_VALUE;
|
2012-03-08 18:05:40 -08:00
|
|
|
} else if (!strcmp(GFX_PREF_FALLBACK_USE_CMAPS, aPref)) {
|
|
|
|
mFallbackUsesCmaps = UNINITIALIZED_VALUE;
|
2011-12-09 14:32:29 -08:00
|
|
|
#ifdef MOZ_GRAPHITE
|
|
|
|
} else if (!strcmp(GFX_PREF_GRAPHITE_SHAPING, aPref)) {
|
|
|
|
mGraphiteShapingEnabled = UNINITIALIZED_VALUE;
|
2012-02-16 13:26:50 -08:00
|
|
|
gfxFontCache *fontCache = gfxFontCache::GetCache();
|
|
|
|
if (fontCache) {
|
|
|
|
fontCache->AgeAllGenerations();
|
|
|
|
fontCache->FlushShapedWordCaches();
|
|
|
|
}
|
2011-12-09 14:32:29 -08:00
|
|
|
#endif
|
2011-04-11 04:17:31 -07:00
|
|
|
} else if (!strcmp(GFX_PREF_HARFBUZZ_SCRIPTS, aPref)) {
|
|
|
|
mUseHarfBuzzScripts = UNINITIALIZED_VALUE;
|
2012-02-16 13:26:50 -08:00
|
|
|
gfxFontCache *fontCache = gfxFontCache::GetCache();
|
|
|
|
if (fontCache) {
|
|
|
|
fontCache->AgeAllGenerations();
|
|
|
|
fontCache->FlushShapedWordCaches();
|
|
|
|
}
|
2011-12-06 04:39:19 -08:00
|
|
|
} else if (!strcmp(BIDI_NUMERAL_PREF, aPref)) {
|
|
|
|
mBidiNumeralOption = UNINITIALIZED_VALUE;
|
2010-05-26 22:05:30 -07:00
|
|
|
}
|
|
|
|
}
|
2011-01-21 08:44:33 -08:00
|
|
|
|
|
|
|
|
|
|
|
PRLogModuleInfo*
|
|
|
|
gfxPlatform::GetLog(eGfxLog aWhichLog)
|
|
|
|
{
|
|
|
|
#ifdef PR_LOGGING
|
|
|
|
switch (aWhichLog) {
|
|
|
|
case eGfxLog_fontlist:
|
|
|
|
return sFontlistLog;
|
|
|
|
break;
|
|
|
|
case eGfxLog_fontinit:
|
|
|
|
return sFontInitLog;
|
|
|
|
break;
|
|
|
|
case eGfxLog_textrun:
|
|
|
|
return sTextrunLog;
|
|
|
|
break;
|
|
|
|
case eGfxLog_textrunui:
|
|
|
|
return sTextrunuiLog;
|
|
|
|
break;
|
2012-03-08 18:05:14 -08:00
|
|
|
case eGfxLog_cmapdata:
|
|
|
|
return sCmapDataLog;
|
|
|
|
break;
|
2011-01-21 08:44:33 -08:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsnull;
|
|
|
|
#else
|
|
|
|
return nsnull;
|
|
|
|
#endif
|
|
|
|
}
|
2012-05-15 12:41:20 -07:00
|
|
|
|
|
|
|
int
|
|
|
|
gfxPlatform::GetScreenDepth() const
|
|
|
|
{
|
2012-07-06 06:19:27 -07:00
|
|
|
NS_WARNING("GetScreenDepth not implemented on this platform -- returning 0!");
|
2012-05-15 12:41:20 -07:00
|
|
|
return 0;
|
|
|
|
}
|
2012-05-25 21:38:17 -07:00
|
|
|
|
|
|
|
mozilla::gfx::SurfaceFormat
|
|
|
|
gfxPlatform::Optimal2DFormatForContent(gfxASurface::gfxContentType aContent)
|
|
|
|
{
|
|
|
|
switch (aContent) {
|
|
|
|
case gfxASurface::CONTENT_COLOR:
|
2012-06-19 21:03:24 -07:00
|
|
|
switch (GetOffscreenFormat()) {
|
|
|
|
case gfxASurface::ImageFormatARGB32:
|
|
|
|
return mozilla::gfx::FORMAT_B8G8R8A8;
|
|
|
|
case gfxASurface::ImageFormatRGB24:
|
|
|
|
return mozilla::gfx::FORMAT_B8G8R8X8;
|
|
|
|
case gfxASurface::ImageFormatRGB16_565:
|
|
|
|
return mozilla::gfx::FORMAT_R5G6B5;
|
|
|
|
default:
|
|
|
|
NS_NOTREACHED("unknown gfxImageFormat for CONTENT_COLOR");
|
|
|
|
return mozilla::gfx::FORMAT_B8G8R8A8;
|
|
|
|
}
|
2012-05-25 21:38:17 -07:00
|
|
|
case gfxASurface::CONTENT_ALPHA:
|
|
|
|
return mozilla::gfx::FORMAT_A8;
|
|
|
|
case gfxASurface::CONTENT_COLOR_ALPHA:
|
|
|
|
return mozilla::gfx::FORMAT_B8G8R8A8;
|
|
|
|
default:
|
|
|
|
NS_NOTREACHED("unknown gfxContentType");
|
|
|
|
return mozilla::gfx::FORMAT_B8G8R8A8;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gfxImageFormat
|
|
|
|
gfxPlatform::OptimalFormatForContent(gfxASurface::gfxContentType aContent)
|
|
|
|
{
|
|
|
|
switch (aContent) {
|
|
|
|
case gfxASurface::CONTENT_COLOR:
|
|
|
|
return GetOffscreenFormat();
|
|
|
|
case gfxASurface::CONTENT_ALPHA:
|
|
|
|
return gfxASurface::ImageFormatA8;
|
|
|
|
case gfxASurface::CONTENT_COLOR_ALPHA:
|
|
|
|
return gfxASurface::ImageFormatARGB32;
|
|
|
|
default:
|
|
|
|
NS_NOTREACHED("unknown gfxContentType");
|
|
|
|
return gfxASurface::ImageFormatARGB32;
|
|
|
|
}
|
|
|
|
}
|