2006-02-22 01:44:31 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
2012-05-21 11:12:37 +00: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/. */
|
2006-02-22 01:44:31 +00:00
|
|
|
|
|
|
|
#include "gfxPlatformMac.h"
|
|
|
|
|
|
|
|
#include "gfxQuartzSurface.h"
|
2008-02-06 06:48:47 +00:00
|
|
|
#include "gfxQuartzImageSurface.h"
|
2011-11-02 19:55:03 +00:00
|
|
|
#include "mozilla/gfx/2D.h"
|
2015-05-21 23:00:28 +00:00
|
|
|
#include "mozilla/gfx/MacIOSurface.h"
|
2006-02-22 01:44:31 +00:00
|
|
|
|
2009-08-16 13:52:12 +00:00
|
|
|
#include "gfxMacPlatformFontList.h"
|
2010-03-10 12:46:41 +00:00
|
|
|
#include "gfxMacFont.h"
|
|
|
|
#include "gfxCoreTextShaper.h"
|
2014-09-16 09:58:12 +00:00
|
|
|
#include "gfxTextRun.h"
|
2008-10-01 03:01:53 +00:00
|
|
|
#include "gfxUserFontSet.h"
|
2009-03-30 00:31:51 +00:00
|
|
|
|
2009-01-18 20:14:14 +00:00
|
|
|
#include "nsTArray.h"
|
2011-06-12 02:30:16 +00:00
|
|
|
#include "mozilla/Preferences.h"
|
2014-11-18 21:28:42 +00:00
|
|
|
#include "mozilla/VsyncDispatcher.h"
|
2009-04-07 16:02:11 +00:00
|
|
|
#include "qcms.h"
|
2013-10-07 23:15:59 +00:00
|
|
|
#include "gfx2DGlue.h"
|
2007-07-23 22:02:17 +00:00
|
|
|
|
2011-05-11 00:44:35 +00:00
|
|
|
#include <dlfcn.h>
|
2014-11-18 21:28:42 +00:00
|
|
|
#include <CoreVideo/CoreVideo.h>
|
2011-05-11 00:44:35 +00:00
|
|
|
|
2013-12-19 16:42:19 +00:00
|
|
|
#include "nsCocoaFeatures.h"
|
2014-12-18 16:30:06 +00:00
|
|
|
#include "mozilla/layers/CompositorParent.h"
|
|
|
|
#include "VsyncSource.h"
|
2013-12-19 16:42:19 +00:00
|
|
|
|
2011-06-12 02:30:16 +00:00
|
|
|
using namespace mozilla;
|
2011-11-02 19:55:03 +00:00
|
|
|
using namespace mozilla::gfx;
|
2011-06-12 02:30:16 +00:00
|
|
|
|
2011-05-11 00:44:35 +00:00
|
|
|
// cribbed from CTFontManager.h
|
|
|
|
enum {
|
|
|
|
kAutoActivationDisabled = 1
|
|
|
|
};
|
|
|
|
typedef uint32_t AutoActivationSetting;
|
|
|
|
|
|
|
|
// bug 567552 - disable auto-activation of fonts
|
|
|
|
|
2014-12-18 16:30:06 +00:00
|
|
|
static void
|
2011-05-11 00:44:35 +00:00
|
|
|
DisableFontActivation()
|
|
|
|
{
|
|
|
|
// get the main bundle identifier
|
|
|
|
CFBundleRef mainBundle = ::CFBundleGetMainBundle();
|
2013-07-31 15:44:31 +00:00
|
|
|
CFStringRef mainBundleID = nullptr;
|
2011-05-11 00:44:35 +00:00
|
|
|
|
|
|
|
if (mainBundle) {
|
|
|
|
mainBundleID = ::CFBundleGetIdentifier(mainBundle);
|
|
|
|
}
|
|
|
|
|
2014-03-05 19:18:38 +00:00
|
|
|
// bug 969388 and bug 922590 - mainBundlID as null is sometimes problematic
|
|
|
|
if (!mainBundleID) {
|
|
|
|
NS_WARNING("missing bundle ID, packaging set up incorrectly");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-05-11 00:44:35 +00:00
|
|
|
// if possible, fetch CTFontManagerSetAutoActivationSetting
|
|
|
|
void (*CTFontManagerSetAutoActivationSettingPtr)
|
|
|
|
(CFStringRef, AutoActivationSetting);
|
|
|
|
CTFontManagerSetAutoActivationSettingPtr =
|
|
|
|
(void (*)(CFStringRef, AutoActivationSetting))
|
|
|
|
dlsym(RTLD_DEFAULT, "CTFontManagerSetAutoActivationSetting");
|
|
|
|
|
|
|
|
// bug 567552 - disable auto-activation of fonts
|
|
|
|
if (CTFontManagerSetAutoActivationSettingPtr) {
|
|
|
|
CTFontManagerSetAutoActivationSettingPtr(mainBundleID,
|
|
|
|
kAutoActivationDisabled);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-02-22 01:44:31 +00:00
|
|
|
gfxPlatformMac::gfxPlatformMac()
|
|
|
|
{
|
2013-03-07 23:00:07 +00:00
|
|
|
DisableFontActivation();
|
2008-05-01 09:07:17 +00:00
|
|
|
mFontAntiAliasingThreshold = ReadAntiAliasingThreshold();
|
2012-07-25 00:45:58 +00:00
|
|
|
|
2014-01-10 19:06:16 +00:00
|
|
|
uint32_t canvasMask = BackendTypeBit(BackendType::CAIRO) |
|
|
|
|
BackendTypeBit(BackendType::SKIA) |
|
|
|
|
BackendTypeBit(BackendType::COREGRAPHICS);
|
2015-04-14 15:41:30 +00:00
|
|
|
uint32_t contentMask = BackendTypeBit(BackendType::COREGRAPHICS) |
|
|
|
|
BackendTypeBit(BackendType::SKIA);
|
2014-01-10 19:06:16 +00:00
|
|
|
InitBackendPrefs(canvasMask, BackendType::COREGRAPHICS,
|
2014-09-30 03:12:28 +00:00
|
|
|
contentMask, BackendType::COREGRAPHICS);
|
2015-02-02 20:24:01 +00:00
|
|
|
|
|
|
|
// XXX: Bug 1036682 - we run out of fds on Mac when using tiled layers because
|
|
|
|
// with 256x256 tiles we can easily hit the soft limit of 800 when using double
|
|
|
|
// buffered tiles in e10s, so let's bump the soft limit to the hard limit for the OS
|
2015-02-06 19:29:26 +00:00
|
|
|
// up to a new cap of OPEN_MAX.
|
2015-02-02 20:24:01 +00:00
|
|
|
struct rlimit limits;
|
|
|
|
if (getrlimit(RLIMIT_NOFILE, &limits) == 0) {
|
2015-02-06 19:29:26 +00:00
|
|
|
limits.rlim_cur = std::min(rlim_t(OPEN_MAX), limits.rlim_max);
|
2015-02-02 20:24:01 +00:00
|
|
|
if (setrlimit(RLIMIT_NOFILE, &limits) != 0) {
|
|
|
|
NS_WARNING("Unable to bump RLIMIT_NOFILE to the maximum number on this OS");
|
|
|
|
}
|
|
|
|
}
|
2015-05-21 23:00:28 +00:00
|
|
|
|
|
|
|
MacIOSurfaceLib::LoadLibrary();
|
2009-03-30 00:31:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gfxPlatformMac::~gfxPlatformMac()
|
|
|
|
{
|
2010-03-10 12:46:41 +00:00
|
|
|
gfxCoreTextShaper::Shutdown();
|
2006-02-22 01:44:31 +00:00
|
|
|
}
|
|
|
|
|
2009-08-16 13:52:12 +00:00
|
|
|
gfxPlatformFontList*
|
|
|
|
gfxPlatformMac::CreatePlatformFontList()
|
|
|
|
{
|
2010-11-08 11:02:27 +00:00
|
|
|
gfxPlatformFontList* list = new gfxMacPlatformFontList();
|
|
|
|
if (NS_SUCCEEDED(list->InitFontList())) {
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
gfxPlatformFontList::Shutdown();
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2009-08-16 13:52:12 +00:00
|
|
|
}
|
|
|
|
|
2006-03-25 00:34:48 +00:00
|
|
|
already_AddRefed<gfxASurface>
|
2015-07-07 01:21:47 +00:00
|
|
|
gfxPlatformMac::CreateOffscreenSurface(const IntSize& aSize,
|
|
|
|
gfxImageFormat aFormat)
|
2006-02-22 01:44:31 +00:00
|
|
|
{
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<gfxASurface> newSurface =
|
2015-07-07 01:21:47 +00:00
|
|
|
new gfxQuartzSurface(aSize, aFormat);
|
2013-04-28 11:52:10 +00:00
|
|
|
return newSurface.forget();
|
2006-02-22 01:44:31 +00:00
|
|
|
}
|
2012-01-09 18:54:44 +00:00
|
|
|
|
2015-06-17 14:00:52 +00:00
|
|
|
already_AddRefed<ScaledFont>
|
2012-07-24 10:18:37 +00:00
|
|
|
gfxPlatformMac::GetScaledFontForFont(DrawTarget* aTarget, gfxFont *aFont)
|
2011-11-02 19:55:03 +00:00
|
|
|
{
|
|
|
|
gfxMacFont *font = static_cast<gfxMacFont*>(aFont);
|
2012-09-24 15:02:49 +00:00
|
|
|
return font->GetScaledFont(aTarget);
|
2011-11-02 19:55:03 +00:00
|
|
|
}
|
|
|
|
|
2008-03-13 10:32:50 +00:00
|
|
|
nsresult
|
|
|
|
gfxPlatformMac::GetStandardFamilyName(const nsAString& aFontName, nsAString& aFamilyName)
|
|
|
|
{
|
2009-08-16 13:52:12 +00:00
|
|
|
gfxPlatformFontList::PlatformFontList()->GetStandardFamilyName(aFontName, aFamilyName);
|
2008-03-13 10:32:50 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-04-02 19:06:16 +00:00
|
|
|
gfxFontGroup *
|
2014-06-06 06:09:23 +00:00
|
|
|
gfxPlatformMac::CreateFontGroup(const FontFamilyList& aFontFamilyList,
|
2008-10-01 03:01:53 +00:00
|
|
|
const gfxFontStyle *aStyle,
|
2015-09-11 04:24:33 +00:00
|
|
|
gfxTextPerfMetrics* aTextPerf,
|
2008-10-01 03:01:53 +00:00
|
|
|
gfxUserFontSet *aUserFontSet)
|
2007-04-02 19:06:16 +00:00
|
|
|
{
|
2015-09-11 04:24:33 +00:00
|
|
|
return new gfxFontGroup(aFontFamilyList, aStyle, aTextPerf, aUserFontSet);
|
2008-10-01 03:01:53 +00:00
|
|
|
}
|
|
|
|
|
2009-08-16 13:52:12 +00:00
|
|
|
// these will move to gfxPlatform once all platforms support the fontlist
|
2008-10-01 03:01:53 +00:00
|
|
|
gfxFontEntry*
|
2014-09-08 07:23:19 +00:00
|
|
|
gfxPlatformMac::LookupLocalFont(const nsAString& aFontName,
|
|
|
|
uint16_t aWeight,
|
|
|
|
int16_t aStretch,
|
2015-10-19 02:16:43 +00:00
|
|
|
uint8_t aStyle)
|
2008-10-01 03:01:53 +00:00
|
|
|
{
|
2014-09-08 07:23:19 +00:00
|
|
|
return gfxPlatformFontList::PlatformFontList()->LookupLocalFont(aFontName,
|
|
|
|
aWeight,
|
|
|
|
aStretch,
|
2015-10-19 02:16:43 +00:00
|
|
|
aStyle);
|
2008-10-01 03:01:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gfxFontEntry*
|
2014-09-08 07:23:19 +00:00
|
|
|
gfxPlatformMac::MakePlatformFont(const nsAString& aFontName,
|
|
|
|
uint16_t aWeight,
|
|
|
|
int16_t aStretch,
|
2015-10-19 02:16:43 +00:00
|
|
|
uint8_t aStyle,
|
2014-09-08 07:23:19 +00:00
|
|
|
const uint8_t* aFontData,
|
|
|
|
uint32_t aLength)
|
2008-10-01 03:01:53 +00:00
|
|
|
{
|
2009-10-07 14:13:40 +00:00
|
|
|
// Ownership of aFontData is received here, and passed on to
|
|
|
|
// gfxPlatformFontList::MakePlatformFont(), which must ensure the data
|
2015-04-01 05:29:55 +00:00
|
|
|
// is released with free when no longer needed
|
2014-09-08 07:23:19 +00:00
|
|
|
return gfxPlatformFontList::PlatformFontList()->MakePlatformFont(aFontName,
|
|
|
|
aWeight,
|
|
|
|
aStretch,
|
2015-10-19 02:16:43 +00:00
|
|
|
aStyle,
|
2009-10-07 14:13:40 +00:00
|
|
|
aFontData,
|
|
|
|
aLength);
|
2008-10-01 03:01:53 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2012-08-22 15:56:38 +00:00
|
|
|
gfxPlatformMac::IsFontFormatSupported(nsIURI *aFontURI, uint32_t aFormatFlags)
|
2008-10-01 03:01:53 +00:00
|
|
|
{
|
2009-01-13 05:16:58 +00:00
|
|
|
// check for strange format flags
|
|
|
|
NS_ASSERTION(!(aFormatFlags & gfxUserFontSet::FLAG_FORMAT_NOT_USED),
|
|
|
|
"strange font format hint set");
|
|
|
|
|
|
|
|
// accept supported formats
|
2014-10-04 10:36:05 +00:00
|
|
|
if (aFormatFlags & (gfxUserFontSet::FLAG_FORMATS_COMMON |
|
2009-01-13 05:16:58 +00:00
|
|
|
gfxUserFontSet::FLAG_FORMAT_TRUETYPE_AAT)) {
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
2008-10-01 03:01:53 +00:00
|
|
|
}
|
|
|
|
|
2009-01-13 05:16:58 +00:00
|
|
|
// reject all other formats, known and unknown
|
|
|
|
if (aFormatFlags != 0) {
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2009-01-13 05:16:58 +00:00
|
|
|
}
|
2008-10-01 03:01:53 +00:00
|
|
|
|
2009-01-13 05:16:58 +00:00
|
|
|
// no format hint set, need to look at data
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
2007-04-02 19:06:16 +00:00
|
|
|
}
|
|
|
|
|
2009-08-16 13:52:12 +00:00
|
|
|
// these will also move to gfxPlatform once all platforms support the fontlist
|
2006-11-22 00:52:09 +00:00
|
|
|
nsresult
|
2010-02-24 17:57:57 +00:00
|
|
|
gfxPlatformMac::GetFontList(nsIAtom *aLangGroup,
|
2006-11-22 00:52:09 +00:00
|
|
|
const nsACString& aGenericFamily,
|
2009-01-18 20:14:14 +00:00
|
|
|
nsTArray<nsString>& aListOfFonts)
|
2006-11-22 00:52:09 +00:00
|
|
|
{
|
2009-08-16 13:52:12 +00:00
|
|
|
gfxPlatformFontList::PlatformFontList()->GetFontList(aLangGroup, aGenericFamily, aListOfFonts);
|
2006-11-22 00:52:09 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2006-12-22 03:56:37 +00:00
|
|
|
|
|
|
|
nsresult
|
|
|
|
gfxPlatformMac::UpdateFontList()
|
|
|
|
{
|
2009-08-16 13:52:12 +00:00
|
|
|
gfxPlatformFontList::PlatformFontList()->UpdateFontList();
|
2006-12-22 03:56:37 +00:00
|
|
|
return NS_OK;
|
2007-02-08 20:47:48 +00:00
|
|
|
}
|
2007-07-23 22:02:17 +00:00
|
|
|
|
2012-03-09 02:05:24 +00:00
|
|
|
static const char kFontArialUnicodeMS[] = "Arial Unicode MS";
|
|
|
|
static const char kFontAppleBraille[] = "Apple Braille";
|
2014-04-14 23:45:18 +00:00
|
|
|
static const char kFontAppleColorEmoji[] = "Apple Color Emoji";
|
2012-03-09 02:05:24 +00:00
|
|
|
static const char kFontAppleSymbols[] = "Apple Symbols";
|
2014-04-14 23:45:18 +00:00
|
|
|
static const char kFontDevanagariSangamMN[] = "Devanagari Sangam MN";
|
|
|
|
static const char kFontEuphemiaUCAS[] = "Euphemia UCAS";
|
2012-03-09 02:05:24 +00:00
|
|
|
static const char kFontGeneva[] = "Geneva";
|
|
|
|
static const char kFontGeezaPro[] = "Geeza Pro";
|
2014-04-14 23:45:18 +00:00
|
|
|
static const char kFontGujaratiSangamMN[] = "Gujarati Sangam MN";
|
|
|
|
static const char kFontGurmukhiMN[] = "Gurmukhi MN";
|
2012-03-09 02:05:24 +00:00
|
|
|
static const char kFontHiraginoKakuGothic[] = "Hiragino Kaku Gothic ProN";
|
2014-04-14 23:45:18 +00:00
|
|
|
static const char kFontHiraginoSansGB[] = "Hiragino Sans GB";
|
|
|
|
static const char kFontKefa[] = "Kefa";
|
|
|
|
static const char kFontKhmerMN[] = "Khmer MN";
|
|
|
|
static const char kFontLaoMN[] = "Lao MN";
|
2012-03-09 02:05:24 +00:00
|
|
|
static const char kFontLucidaGrande[] = "Lucida Grande";
|
|
|
|
static const char kFontMenlo[] = "Menlo";
|
2014-04-14 23:45:18 +00:00
|
|
|
static const char kFontMicrosoftTaiLe[] = "Microsoft Tai Le";
|
|
|
|
static const char kFontMingLiUExtB[] = "MingLiU-ExtB";
|
|
|
|
static const char kFontMyanmarMN[] = "Myanmar MN";
|
2012-03-09 02:05:24 +00:00
|
|
|
static const char kFontPlantagenetCherokee[] = "Plantagenet Cherokee";
|
2014-04-14 23:45:18 +00:00
|
|
|
static const char kFontSimSunExtB[] = "SimSun-ExtB";
|
|
|
|
static const char kFontSongtiSC[] = "Songti SC";
|
2012-03-09 02:05:24 +00:00
|
|
|
static const char kFontSTHeiti[] = "STHeiti";
|
2014-04-14 23:45:18 +00:00
|
|
|
static const char kFontSTIXGeneral[] = "STIXGeneral";
|
|
|
|
static const char kFontTamilMN[] = "Tamil MN";
|
2012-03-09 02:05:24 +00:00
|
|
|
|
|
|
|
void
|
2014-09-30 06:27:55 +00:00
|
|
|
gfxPlatformMac::GetCommonFallbackFonts(uint32_t aCh, uint32_t aNextCh,
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t aRunScript,
|
2012-03-09 02:05:24 +00:00
|
|
|
nsTArray<const char*>& aFontList)
|
|
|
|
{
|
2014-09-30 06:27:55 +00:00
|
|
|
if (aNextCh == 0xfe0f) {
|
|
|
|
aFontList.AppendElement(kFontAppleColorEmoji);
|
|
|
|
}
|
|
|
|
|
2012-03-09 02:05:24 +00:00
|
|
|
aFontList.AppendElement(kFontLucidaGrande);
|
|
|
|
|
|
|
|
if (!IS_IN_BMP(aCh)) {
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t p = aCh >> 16;
|
2014-04-14 23:45:18 +00:00
|
|
|
uint32_t b = aCh >> 8;
|
2012-03-09 02:05:24 +00:00
|
|
|
if (p == 1) {
|
2014-04-14 23:45:18 +00:00
|
|
|
if (b >= 0x1f0 && b < 0x1f7) {
|
|
|
|
aFontList.AppendElement(kFontAppleColorEmoji);
|
|
|
|
} else {
|
|
|
|
aFontList.AppendElement(kFontAppleSymbols);
|
|
|
|
aFontList.AppendElement(kFontSTIXGeneral);
|
|
|
|
aFontList.AppendElement(kFontGeneva);
|
|
|
|
}
|
|
|
|
} else if (p == 2) {
|
|
|
|
// OSX installations with MS Office may have these fonts
|
|
|
|
aFontList.AppendElement(kFontMingLiUExtB);
|
|
|
|
aFontList.AppendElement(kFontSimSunExtB);
|
2012-03-09 02:05:24 +00:00
|
|
|
}
|
|
|
|
} else {
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t b = (aCh >> 8) & 0xff;
|
2012-03-09 02:05:24 +00:00
|
|
|
|
|
|
|
switch (b) {
|
|
|
|
case 0x03:
|
|
|
|
case 0x05:
|
|
|
|
aFontList.AppendElement(kFontGeneva);
|
|
|
|
break;
|
|
|
|
case 0x07:
|
|
|
|
aFontList.AppendElement(kFontGeezaPro);
|
|
|
|
break;
|
2014-04-14 23:45:18 +00:00
|
|
|
case 0x09:
|
|
|
|
aFontList.AppendElement(kFontDevanagariSangamMN);
|
|
|
|
break;
|
|
|
|
case 0x0a:
|
|
|
|
aFontList.AppendElement(kFontGurmukhiMN);
|
|
|
|
aFontList.AppendElement(kFontGujaratiSangamMN);
|
|
|
|
break;
|
|
|
|
case 0x0b:
|
|
|
|
aFontList.AppendElement(kFontTamilMN);
|
|
|
|
break;
|
|
|
|
case 0x0e:
|
|
|
|
aFontList.AppendElement(kFontLaoMN);
|
|
|
|
break;
|
|
|
|
case 0x0f:
|
|
|
|
aFontList.AppendElement(kFontSongtiSC);
|
|
|
|
break;
|
2012-03-09 02:05:24 +00:00
|
|
|
case 0x10:
|
|
|
|
aFontList.AppendElement(kFontMenlo);
|
2014-04-14 23:45:18 +00:00
|
|
|
aFontList.AppendElement(kFontMyanmarMN);
|
2012-03-09 02:05:24 +00:00
|
|
|
break;
|
|
|
|
case 0x13: // Cherokee
|
|
|
|
aFontList.AppendElement(kFontPlantagenetCherokee);
|
2014-04-14 23:45:18 +00:00
|
|
|
aFontList.AppendElement(kFontKefa);
|
2012-03-09 02:05:24 +00:00
|
|
|
break;
|
2014-04-14 23:45:18 +00:00
|
|
|
case 0x14: // Unified Canadian Aboriginal Syllabics
|
|
|
|
case 0x15:
|
|
|
|
case 0x16:
|
|
|
|
aFontList.AppendElement(kFontEuphemiaUCAS);
|
|
|
|
aFontList.AppendElement(kFontGeneva);
|
|
|
|
break;
|
|
|
|
case 0x18: // Mongolian, UCAS
|
2012-03-09 02:05:24 +00:00
|
|
|
aFontList.AppendElement(kFontSTHeiti);
|
2014-04-14 23:45:18 +00:00
|
|
|
aFontList.AppendElement(kFontEuphemiaUCAS);
|
|
|
|
break;
|
|
|
|
case 0x19: // Khmer
|
|
|
|
aFontList.AppendElement(kFontKhmerMN);
|
|
|
|
aFontList.AppendElement(kFontMicrosoftTaiLe);
|
2012-03-09 02:05:24 +00:00
|
|
|
break;
|
|
|
|
case 0x1d:
|
|
|
|
case 0x1e:
|
|
|
|
aFontList.AppendElement(kFontGeneva);
|
|
|
|
break;
|
|
|
|
case 0x20: // Symbol ranges
|
|
|
|
case 0x21:
|
|
|
|
case 0x22:
|
|
|
|
case 0x23:
|
|
|
|
case 0x24:
|
|
|
|
case 0x25:
|
|
|
|
case 0x26:
|
|
|
|
case 0x27:
|
|
|
|
case 0x29:
|
|
|
|
case 0x2a:
|
|
|
|
case 0x2b:
|
|
|
|
case 0x2e:
|
2014-08-20 07:54:38 +00:00
|
|
|
aFontList.AppendElement(kFontHiraginoKakuGothic);
|
2012-03-09 02:05:24 +00:00
|
|
|
aFontList.AppendElement(kFontAppleSymbols);
|
|
|
|
aFontList.AppendElement(kFontMenlo);
|
2014-04-14 23:45:18 +00:00
|
|
|
aFontList.AppendElement(kFontSTIXGeneral);
|
2012-03-09 02:05:24 +00:00
|
|
|
aFontList.AppendElement(kFontGeneva);
|
2014-04-14 23:45:18 +00:00
|
|
|
aFontList.AppendElement(kFontAppleColorEmoji);
|
2012-03-09 02:05:24 +00:00
|
|
|
break;
|
|
|
|
case 0x2c:
|
2014-04-14 23:45:18 +00:00
|
|
|
aFontList.AppendElement(kFontGeneva);
|
|
|
|
break;
|
2012-03-09 02:05:24 +00:00
|
|
|
case 0x2d:
|
2014-04-14 23:45:18 +00:00
|
|
|
aFontList.AppendElement(kFontKefa);
|
2012-03-09 02:05:24 +00:00
|
|
|
aFontList.AppendElement(kFontGeneva);
|
|
|
|
break;
|
|
|
|
case 0x28: // Braille
|
|
|
|
aFontList.AppendElement(kFontAppleBraille);
|
|
|
|
break;
|
2014-04-14 23:45:18 +00:00
|
|
|
case 0x31:
|
|
|
|
aFontList.AppendElement(kFontHiraginoSansGB);
|
|
|
|
break;
|
2012-03-09 02:05:24 +00:00
|
|
|
case 0x4d:
|
|
|
|
aFontList.AppendElement(kFontAppleSymbols);
|
|
|
|
break;
|
|
|
|
case 0xa0: // Yi
|
|
|
|
case 0xa1:
|
|
|
|
case 0xa2:
|
|
|
|
case 0xa3:
|
|
|
|
case 0xa4:
|
|
|
|
aFontList.AppendElement(kFontSTHeiti);
|
|
|
|
break;
|
|
|
|
case 0xa6:
|
|
|
|
case 0xa7:
|
|
|
|
aFontList.AppendElement(kFontGeneva);
|
|
|
|
aFontList.AppendElement(kFontAppleSymbols);
|
|
|
|
break;
|
2014-04-14 23:45:18 +00:00
|
|
|
case 0xab:
|
|
|
|
aFontList.AppendElement(kFontKefa);
|
|
|
|
break;
|
2012-03-09 02:05:24 +00:00
|
|
|
case 0xfc:
|
|
|
|
case 0xff:
|
|
|
|
aFontList.AppendElement(kFontAppleSymbols);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Arial Unicode MS has lots of glyphs for obscure, use it as a last resort
|
|
|
|
aFontList.AppendElement(kFontArialUnicodeMS);
|
|
|
|
}
|
|
|
|
|
2015-10-08 06:04:08 +00:00
|
|
|
/*static*/ void
|
|
|
|
gfxPlatformMac::LookupSystemFont(mozilla::LookAndFeel::FontID aSystemFontID,
|
|
|
|
nsAString& aSystemFontName,
|
|
|
|
gfxFontStyle& aFontStyle,
|
|
|
|
float aDevPixPerCSSPixel)
|
|
|
|
{
|
|
|
|
gfxMacPlatformFontList* pfl = gfxMacPlatformFontList::PlatformFontList();
|
|
|
|
return pfl->LookupSystemFont(aSystemFontID, aSystemFontName, aFontStyle,
|
|
|
|
aDevPixPerCSSPixel);
|
|
|
|
}
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t
|
2008-05-01 09:07:17 +00:00
|
|
|
gfxPlatformMac::ReadAntiAliasingThreshold()
|
|
|
|
{
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t threshold = 0; // default == no threshold
|
2014-11-18 21:28:42 +00:00
|
|
|
|
2008-05-01 09:07:17 +00:00
|
|
|
// first read prefs flag to determine whether to use the setting or not
|
2011-09-29 06:19:26 +00:00
|
|
|
bool useAntiAliasingThreshold = Preferences::GetBool("gfx.use_text_smoothing_setting", false);
|
2011-06-12 02:30:16 +00:00
|
|
|
|
2008-05-01 09:07:17 +00:00
|
|
|
// if the pref setting is disabled, return 0 which effectively disables this feature
|
|
|
|
if (!useAntiAliasingThreshold)
|
|
|
|
return threshold;
|
2014-11-18 21:28:42 +00:00
|
|
|
|
2008-05-01 09:07:17 +00:00
|
|
|
// value set via Appearance pref panel, "Turn off text smoothing for font sizes xxx and smaller"
|
|
|
|
CFNumberRef prefValue = (CFNumberRef)CFPreferencesCopyAppValue(CFSTR("AppleAntiAliasingThreshold"), kCFPreferencesCurrentApplication);
|
|
|
|
|
|
|
|
if (prefValue) {
|
|
|
|
if (!CFNumberGetValue(prefValue, kCFNumberIntType, &threshold)) {
|
|
|
|
threshold = 0;
|
|
|
|
}
|
|
|
|
CFRelease(prefValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
return threshold;
|
|
|
|
}
|
2008-01-31 00:23:36 +00:00
|
|
|
|
2012-07-31 15:17:43 +00:00
|
|
|
bool
|
|
|
|
gfxPlatformMac::UseAcceleratedCanvas()
|
|
|
|
{
|
|
|
|
// Lion or later is required
|
2014-03-28 05:40:42 +00:00
|
|
|
return nsCocoaFeatures::OnLionOrLater() && Preferences::GetBool("gfx.canvas.azure.accelerated", false);
|
2012-07-31 15:17:43 +00:00
|
|
|
}
|
2012-01-09 18:54:44 +00:00
|
|
|
|
2014-11-07 19:17:14 +00:00
|
|
|
bool
|
|
|
|
gfxPlatformMac::UseProgressivePaint()
|
|
|
|
{
|
|
|
|
// Progressive painting requires cross-process mutexes, which don't work so
|
|
|
|
// well on OS X 10.6 so we disable there.
|
|
|
|
return nsCocoaFeatures::OnLionOrLater() && gfxPlatform::UseProgressivePaint();
|
|
|
|
}
|
|
|
|
|
2015-07-16 22:18:05 +00:00
|
|
|
bool
|
|
|
|
gfxPlatformMac::AccelerateLayersByDefault()
|
|
|
|
{
|
|
|
|
// 10.6.2 and lower have a bug involving textures and pixel buffer objects
|
|
|
|
// that caused bug 629016, so we don't allow OpenGL-accelerated layers on
|
|
|
|
// those versions of the OS.
|
|
|
|
// This will still let full-screen video be accelerated on OpenGL, because
|
|
|
|
// that XUL widget opts in to acceleration, but that's probably OK.
|
|
|
|
return nsCocoaFeatures::AccelerateByDefault();
|
|
|
|
}
|
|
|
|
|
2014-11-18 21:28:42 +00:00
|
|
|
// This is the renderer output callback function, called on the vsync thread
|
|
|
|
static CVReturn VsyncCallback(CVDisplayLinkRef aDisplayLink,
|
|
|
|
const CVTimeStamp* aNow,
|
|
|
|
const CVTimeStamp* aOutputTime,
|
|
|
|
CVOptionFlags aFlagsIn,
|
|
|
|
CVOptionFlags* aFlagsOut,
|
2015-01-09 08:37:00 +00:00
|
|
|
void* aDisplayLinkContext);
|
2014-11-18 21:28:42 +00:00
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
class OSXVsyncSource final : public VsyncSource
|
2014-11-18 21:28:42 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
OSXVsyncSource()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual Display& GetGlobalDisplay() override
|
2014-11-18 21:28:42 +00:00
|
|
|
{
|
2014-12-18 16:30:06 +00:00
|
|
|
return mGlobalDisplay;
|
|
|
|
}
|
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
class OSXDisplay final : public VsyncSource::Display
|
2014-12-18 16:30:06 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
OSXDisplay()
|
2015-01-20 16:31:21 +00:00
|
|
|
: mDisplayLink(nullptr)
|
2014-12-18 16:30:06 +00:00
|
|
|
{
|
2015-03-18 23:17:26 +00:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
mTimer = do_CreateInstance(NS_TIMER_CONTRACTID);
|
2014-11-18 21:28:42 +00:00
|
|
|
}
|
|
|
|
|
2014-12-18 16:30:06 +00:00
|
|
|
~OSXDisplay()
|
|
|
|
{
|
2015-03-18 23:17:26 +00:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
mTimer->Cancel();
|
|
|
|
mTimer = nullptr;
|
2014-12-18 16:30:06 +00:00
|
|
|
DisableVsync();
|
|
|
|
}
|
|
|
|
|
2015-03-18 23:17:26 +00:00
|
|
|
static void RetryEnableVsync(nsITimer* aTimer, void* aOsxDisplay)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
OSXDisplay* osxDisplay = static_cast<OSXDisplay*>(aOsxDisplay);
|
|
|
|
MOZ_ASSERT(osxDisplay);
|
|
|
|
osxDisplay->EnableVsync();
|
|
|
|
}
|
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual void EnableVsync() override
|
2014-12-18 16:30:06 +00:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2015-01-20 16:31:22 +00:00
|
|
|
if (IsVsyncEnabled()) {
|
|
|
|
return;
|
|
|
|
}
|
2014-12-18 16:30:06 +00:00
|
|
|
|
|
|
|
// Create a display link capable of being used with all active displays
|
|
|
|
// TODO: See if we need to create an active DisplayLink for each monitor in multi-monitor
|
|
|
|
// situations. According to the docs, it is compatible with all displays running on the computer
|
|
|
|
// But if we have different monitors at different display rates, we may hit issues.
|
|
|
|
if (CVDisplayLinkCreateWithActiveCGDisplays(&mDisplayLink) != kCVReturnSuccess) {
|
2015-05-05 20:57:47 +00:00
|
|
|
NS_WARNING("Could not create a display link with all active displays. Retrying");
|
2015-03-15 04:23:53 +00:00
|
|
|
CVDisplayLinkRelease(mDisplayLink);
|
2015-03-18 23:17:26 +00:00
|
|
|
mDisplayLink = nullptr;
|
2015-03-15 04:23:53 +00:00
|
|
|
|
2015-03-18 23:17:26 +00:00
|
|
|
// bug 1142708 - When coming back from sleep,
|
|
|
|
// or when changing displays, active displays may not be ready yet,
|
|
|
|
// even if listening for the kIOMessageSystemHasPoweredOn event
|
|
|
|
// from OS X sleep notifications.
|
2015-03-15 04:23:53 +00:00
|
|
|
// Active displays are those that are drawable.
|
2015-03-18 23:17:26 +00:00
|
|
|
// bug 1144638 - When changing display configurations and getting
|
|
|
|
// notifications from CGDisplayReconfigurationCallBack, the
|
|
|
|
// callback gets called twice for each active display
|
|
|
|
// so it's difficult to know when all displays are active.
|
|
|
|
// Instead, try again soon. The delay is arbitrary. 100ms chosen
|
|
|
|
// because on a late 2013 15" retina, it takes about that
|
|
|
|
// long to come back up from sleep.
|
|
|
|
uint32_t delay = 100;
|
|
|
|
mTimer->InitWithFuncCallback(RetryEnableVsync, this, delay, nsITimer::TYPE_ONE_SHOT);
|
|
|
|
return;
|
2014-12-18 16:30:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (CVDisplayLinkSetOutputCallback(mDisplayLink, &VsyncCallback, this) != kCVReturnSuccess) {
|
|
|
|
NS_WARNING("Could not set displaylink output callback");
|
2015-03-15 04:23:53 +00:00
|
|
|
CVDisplayLinkRelease(mDisplayLink);
|
|
|
|
mDisplayLink = nullptr;
|
2014-12-18 16:30:06 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-01-09 08:37:00 +00:00
|
|
|
mPreviousTimestamp = TimeStamp::Now();
|
2014-12-18 16:30:06 +00:00
|
|
|
if (CVDisplayLinkStart(mDisplayLink) != kCVReturnSuccess) {
|
|
|
|
NS_WARNING("Could not activate the display link");
|
2015-03-15 04:23:53 +00:00
|
|
|
CVDisplayLinkRelease(mDisplayLink);
|
2014-12-18 16:30:06 +00:00
|
|
|
mDisplayLink = nullptr;
|
|
|
|
}
|
2015-11-06 16:20:58 +00:00
|
|
|
|
|
|
|
CVTime vsyncRate = CVDisplayLinkGetNominalOutputVideoRefreshPeriod(mDisplayLink);
|
|
|
|
if (vsyncRate.flags & kCVTimeIsIndefinite) {
|
|
|
|
NS_WARNING("Could not get vsync rate, setting to 60.");
|
|
|
|
mVsyncRate = TimeDuration::FromMilliseconds(1000.0 / 60.0);
|
|
|
|
} else {
|
|
|
|
int64_t timeValue = vsyncRate.timeValue;
|
|
|
|
int64_t timeScale = vsyncRate.timeScale;
|
|
|
|
const int milliseconds = 1000;
|
|
|
|
float rateInMs = ((double) timeValue / (double) timeScale) * milliseconds;
|
|
|
|
mVsyncRate = TimeDuration::FromMilliseconds(rateInMs);
|
|
|
|
}
|
2014-11-18 21:28:42 +00:00
|
|
|
}
|
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual void DisableVsync() override
|
2014-12-18 16:30:06 +00:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2015-01-20 16:31:22 +00:00
|
|
|
if (!IsVsyncEnabled()) {
|
|
|
|
return;
|
|
|
|
}
|
2014-12-18 16:30:06 +00:00
|
|
|
|
|
|
|
// Release the display link
|
|
|
|
if (mDisplayLink) {
|
|
|
|
CVDisplayLinkRelease(mDisplayLink);
|
|
|
|
mDisplayLink = nullptr;
|
|
|
|
}
|
2014-11-18 21:28:42 +00:00
|
|
|
}
|
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual bool IsVsyncEnabled() override
|
2014-12-18 16:30:06 +00:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
return mDisplayLink != nullptr;
|
2014-11-18 21:28:42 +00:00
|
|
|
}
|
|
|
|
|
2015-11-06 16:20:58 +00:00
|
|
|
virtual TimeDuration GetVsyncRate() override
|
|
|
|
{
|
|
|
|
return mVsyncRate;
|
|
|
|
}
|
|
|
|
|
2015-01-09 08:37:00 +00:00
|
|
|
// The vsync timestamps given by the CVDisplayLinkCallback are
|
|
|
|
// in the future for the NEXT frame. Large parts of Gecko, such
|
|
|
|
// as animations assume a timestamp at either now or in the past.
|
|
|
|
// Normalize the timestamps given to the VsyncDispatchers to the vsync
|
|
|
|
// that just occured, not the vsync that is upcoming.
|
|
|
|
TimeStamp mPreviousTimestamp;
|
|
|
|
|
2014-12-18 16:30:06 +00:00
|
|
|
private:
|
|
|
|
// Manages the display link render thread
|
|
|
|
CVDisplayLinkRef mDisplayLink;
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<nsITimer> mTimer;
|
2015-11-06 16:20:58 +00:00
|
|
|
TimeDuration mVsyncRate;
|
2014-12-18 16:30:06 +00:00
|
|
|
}; // OSXDisplay
|
2014-11-18 21:28:42 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
virtual ~OSXVsyncSource()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-12-18 16:30:06 +00:00
|
|
|
OSXDisplay mGlobalDisplay;
|
2014-11-18 21:28:42 +00:00
|
|
|
}; // OSXVsyncSource
|
|
|
|
|
2015-01-09 08:37:00 +00:00
|
|
|
static CVReturn VsyncCallback(CVDisplayLinkRef aDisplayLink,
|
|
|
|
const CVTimeStamp* aNow,
|
|
|
|
const CVTimeStamp* aOutputTime,
|
|
|
|
CVOptionFlags aFlagsIn,
|
|
|
|
CVOptionFlags* aFlagsOut,
|
|
|
|
void* aDisplayLinkContext)
|
|
|
|
{
|
|
|
|
// Executed on OS X hardware vsync thread
|
|
|
|
OSXVsyncSource::OSXDisplay* display = (OSXVsyncSource::OSXDisplay*) aDisplayLinkContext;
|
|
|
|
int64_t nextVsyncTimestamp = aOutputTime->hostTime;
|
|
|
|
|
2015-06-18 15:06:20 +00:00
|
|
|
mozilla::TimeStamp nextVsync = mozilla::TimeStamp::FromSystemTime(nextVsyncTimestamp);
|
2015-01-09 08:37:00 +00:00
|
|
|
mozilla::TimeStamp previousVsync = display->mPreviousTimestamp;
|
2015-06-02 20:16:41 +00:00
|
|
|
mozilla::TimeStamp now = TimeStamp::Now();
|
|
|
|
|
2015-06-18 15:06:20 +00:00
|
|
|
// Snow leopard sometimes sends vsync timestamps very far in the past.
|
|
|
|
// Normalize the vsync timestamps to now.
|
|
|
|
if (nextVsync <= previousVsync) {
|
|
|
|
nextVsync = now;
|
|
|
|
previousVsync = now;
|
|
|
|
} else if (now < previousVsync) {
|
|
|
|
// Bug 1158321 - The VsyncCallback can sometimes execute before the reported
|
|
|
|
// vsync time. In those cases, normalize the timestamp to Now() as sending
|
|
|
|
// timestamps in the future has undefined behavior. See the comment above
|
|
|
|
// OSXDisplay::mPreviousTimestamp
|
2015-06-02 20:16:41 +00:00
|
|
|
previousVsync = now;
|
|
|
|
}
|
2015-01-09 08:37:00 +00:00
|
|
|
|
2015-06-18 15:06:20 +00:00
|
|
|
display->mPreviousTimestamp = nextVsync;
|
|
|
|
|
2015-01-09 08:37:00 +00:00
|
|
|
display->NotifyVsync(previousVsync);
|
|
|
|
return kCVReturnSuccess;
|
|
|
|
}
|
|
|
|
|
2014-12-18 16:30:06 +00:00
|
|
|
already_AddRefed<mozilla::gfx::VsyncSource>
|
|
|
|
gfxPlatformMac::CreateHardwareVsyncSource()
|
2014-11-18 21:28:42 +00:00
|
|
|
{
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<VsyncSource> osxVsyncSource = new OSXVsyncSource();
|
2015-03-04 22:37:55 +00:00
|
|
|
VsyncSource::Display& primaryDisplay = osxVsyncSource->GetGlobalDisplay();
|
|
|
|
primaryDisplay.EnableVsync();
|
|
|
|
if (!primaryDisplay.IsVsyncEnabled()) {
|
2015-05-05 20:57:47 +00:00
|
|
|
NS_WARNING("OS X Vsync source not enabled. Falling back to software vsync.");
|
2015-03-04 22:37:55 +00:00
|
|
|
return gfxPlatform::CreateHardwareVsyncSource();
|
|
|
|
}
|
|
|
|
|
|
|
|
primaryDisplay.DisableVsync();
|
2014-12-18 16:30:06 +00:00
|
|
|
return osxVsyncSource.forget();
|
2014-11-18 21:28:42 +00:00
|
|
|
}
|
|
|
|
|
2013-11-07 10:20:08 +00:00
|
|
|
void
|
|
|
|
gfxPlatformMac::GetPlatformCMSOutputProfile(void* &mem, size_t &size)
|
2007-07-23 22:02:17 +00:00
|
|
|
{
|
2013-11-07 10:20:08 +00:00
|
|
|
mem = nullptr;
|
|
|
|
size = 0;
|
|
|
|
|
2013-10-09 05:53:37 +00:00
|
|
|
CGColorSpaceRef cspace = ::CGDisplayCopyColorSpace(::CGMainDisplayID());
|
|
|
|
if (!cspace) {
|
|
|
|
cspace = ::CGColorSpaceCreateDeviceRGB();
|
|
|
|
}
|
|
|
|
if (!cspace) {
|
2013-11-07 10:20:08 +00:00
|
|
|
return;
|
2013-10-09 05:53:37 +00:00
|
|
|
}
|
2007-07-23 22:02:17 +00:00
|
|
|
|
2013-10-09 05:53:37 +00:00
|
|
|
CFDataRef iccp = ::CGColorSpaceCopyICCProfile(cspace);
|
2009-10-03 18:33:55 +00:00
|
|
|
|
2013-10-09 05:53:37 +00:00
|
|
|
::CFRelease(cspace);
|
|
|
|
|
|
|
|
if (!iccp) {
|
2013-11-07 10:20:08 +00:00
|
|
|
return;
|
2007-07-23 22:02:17 +00:00
|
|
|
}
|
|
|
|
|
2013-11-07 10:20:08 +00:00
|
|
|
// copy to external buffer
|
|
|
|
size = static_cast<size_t>(::CFDataGetLength(iccp));
|
|
|
|
if (size > 0) {
|
|
|
|
void *data = malloc(size);
|
|
|
|
if (data) {
|
|
|
|
memcpy(data, ::CFDataGetBytePtr(iccp), size);
|
|
|
|
mem = data;
|
|
|
|
} else {
|
|
|
|
size = 0;
|
|
|
|
}
|
|
|
|
}
|
2013-10-09 05:53:37 +00:00
|
|
|
|
|
|
|
::CFRelease(iccp);
|
2007-07-23 22:02:17 +00:00
|
|
|
}
|