2018-11-30 19:52:05 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
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"
|
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"
|
2018-04-05 17:53:56 +00:00
|
|
|
#include "nsCocoaFeatures.h"
|
2017-11-12 07:36:24 +00:00
|
|
|
#include "nsUnicodeProperties.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
|
|
|
|
2016-03-22 18:08:38 +00:00
|
|
|
#include "mozilla/layers/CompositorBridgeParent.h"
|
2014-12-18 16:30:06 +00:00
|
|
|
#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;
|
2017-11-12 07:36:24 +00:00
|
|
|
using namespace mozilla::unicode;
|
2011-06-12 02:30:16 +00:00
|
|
|
|
2017-11-02 17:23:16 +00:00
|
|
|
using mozilla::dom::SystemFontListEntry;
|
2016-11-15 13:58:29 +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
|
|
|
|
|
|
|
|
static void 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");
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2011-05-11 00:44:35 +00:00
|
|
|
// 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
|
|
|
|
2018-03-15 05:48:54 +00:00
|
|
|
InitBackendPrefs(GetBackendPrefs());
|
2015-02-02 20:24:01 +00:00
|
|
|
|
2015-05-21 23:00:28 +00:00
|
|
|
MacIOSurfaceLib::LoadLibrary();
|
2018-05-29 16:07:48 +00:00
|
|
|
|
|
|
|
if (nsCocoaFeatures::OnHighSierraOrLater()) {
|
|
|
|
mHasNativeColrFontSupport = true;
|
|
|
|
}
|
2009-03-30 00:31:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gfxPlatformMac::~gfxPlatformMac() { gfxCoreTextShaper::Shutdown(); }
|
2006-02-22 01:44:31 +00:00
|
|
|
|
2018-04-30 20:05:19 +00:00
|
|
|
BackendPrefsData gfxPlatformMac::GetBackendPrefs() const {
|
2018-03-15 05:48:54 +00:00
|
|
|
BackendPrefsData data;
|
|
|
|
|
|
|
|
data.mCanvasBitmask = BackendTypeBit(BackendType::SKIA);
|
|
|
|
data.mContentBitmask = BackendTypeBit(BackendType::SKIA);
|
|
|
|
data.mCanvasDefault = BackendType::SKIA;
|
|
|
|
data.mContentDefault = BackendType::SKIA;
|
|
|
|
|
2018-06-01 15:59:07 +00:00
|
|
|
return data;
|
2018-03-15 05:48:54 +00:00
|
|
|
}
|
|
|
|
|
Create a PaintWorker thread pool and dispatch tiles to it (bug 1425056, r=bas)
This commit adds a paint worker thread pool to PaintThread, and dispatches
tiled paints to it. The thread pool is only created if tiling is enabled,
and its size is set by 'layers.omtp.paint-workers' and defaults to 1. If
-1 is specified, it will be sized to 'max((cpu_cores * 3) / 4, 1)'.
The one tricky part of dispatching tiled paints to a thread pool is the
AsyncEndLayerTransaction message that must execute once all paints are
finished. Previously, this runnable would be queued after all the paints
had been queued, ensuring it would be run after they had all completed.
With a thread pool, there is no guarantee. Instead this commit, uses
a flag on CompositorBridgeChild to signify whether all of the paints
have been queued ('mOutstandingAsyncEndLayerTransaction'), and after
every tiled paint it is examined to see if that paint was the last
paint, and if it is to run AsyncEndLayerTransaction. In addition,
if the async paints complete before we even mark the end of the
layer transaction, we queue it like normal.
The profiler markers are also complicated by using a thread pool.
I don't know of a great way to keep them working as they are per
thread, so for now I've removed them. I may have been the only
one using them anyway.
MozReview-Commit-ID: 5LIJ9GWSfCn
--HG--
extra : rebase_source : 0c26806f337a1b4b1511945f9c72e787b426c5ba
2017-12-08 07:18:05 +00:00
|
|
|
bool gfxPlatformMac::UsesTiling() const {
|
|
|
|
// The non-tiling ContentClient requires CrossProcessSemaphore which
|
|
|
|
// isn't implemented for OSX.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-04-30 20:05:19 +00:00
|
|
|
bool gfxPlatformMac::ContentUsesTiling() const { return UsesTiling(); }
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2017-11-02 20:29:33 +00:00
|
|
|
void gfxPlatformMac::ReadSystemFontList(
|
2017-11-02 17:23:16 +00:00
|
|
|
InfallibleTArray<SystemFontListEntry>* aFontList) {
|
2017-11-02 20:29:33 +00:00
|
|
|
gfxMacPlatformFontList::PlatformFontList()->ReadSystemFontList(aFontList);
|
2016-11-15 13:58:29 +00:00
|
|
|
}
|
|
|
|
|
2015-07-07 01:21:47 +00:00
|
|
|
already_AddRefed<gfxASurface> gfxPlatformMac::CreateOffscreenSurface(
|
|
|
|
const IntSize& aSize, gfxImageFormat aFormat) {
|
2016-09-15 14:36:21 +00:00
|
|
|
if (!Factory::AllowedSurfaceSize(aSize)) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2015-07-07 01:21:47 +00:00
|
|
|
RefPtr<gfxASurface> newSurface = 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
|
|
|
|
2014-06-06 06:09:23 +00:00
|
|
|
gfxFontGroup* gfxPlatformMac::CreateFontGroup(
|
|
|
|
const FontFamilyList& aFontFamilyList, const gfxFontStyle* aStyle,
|
2015-09-11 04:24:33 +00:00
|
|
|
gfxTextPerfMetrics* aTextPerf, gfxUserFontSet* aUserFontSet,
|
2015-11-20 13:01:12 +00:00
|
|
|
gfxFloat aDevToCssSize) {
|
|
|
|
return new gfxFontGroup(aFontFamilyList, aStyle, aTextPerf, aUserFontSet,
|
|
|
|
aDevToCssSize);
|
2008-10-01 03:01:53 +00:00
|
|
|
}
|
|
|
|
|
2017-07-08 06:17:23 +00:00
|
|
|
bool gfxPlatformMac::IsFontFormatSupported(uint32_t aFormatFlags) {
|
2017-07-20 08:57:00 +00:00
|
|
|
if (gfxPlatform::IsFontFormatSupported(aFormatFlags)) {
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
2008-10-01 03:01:53 +00:00
|
|
|
}
|
|
|
|
|
2017-07-20 08:57:00 +00:00
|
|
|
// If the generic method rejected the format hint, then check for any
|
|
|
|
// platform-specific format we know about.
|
|
|
|
if (aFormatFlags & gfxUserFontSet::FLAG_FORMAT_TRUETYPE_AAT) {
|
|
|
|
return true;
|
2009-01-13 05:16:58 +00:00
|
|
|
}
|
2008-10-01 03:01:53 +00:00
|
|
|
|
2017-07-20 08:57:00 +00:00
|
|
|
return false;
|
2007-04-02 19:06:16 +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
|
|
|
|
2014-09-30 06:27:55 +00:00
|
|
|
void gfxPlatformMac::GetCommonFallbackFonts(uint32_t aCh, uint32_t aNextCh,
|
2016-04-21 17:58:59 +00:00
|
|
|
Script aRunScript,
|
2012-03-09 02:05:24 +00:00
|
|
|
nsTArray<const char*>& aFontList) {
|
2017-11-12 07:36:24 +00:00
|
|
|
EmojiPresentation emoji = GetEmojiPresentation(aCh);
|
|
|
|
if (emoji != EmojiPresentation::TextOnly) {
|
|
|
|
if (aNextCh == kVariationSelector16 ||
|
|
|
|
(aNextCh != kVariationSelector15 &&
|
|
|
|
emoji == EmojiPresentation::EmojiDefault)) {
|
|
|
|
// if char is followed by VS16, try for a color emoji glyph
|
|
|
|
aFontList.AppendElement(kFontAppleColorEmoji);
|
2014-09-30 06:27:55 +00:00
|
|
|
}
|
2018-11-30 10:46:48 +00:00
|
|
|
}
|
2014-09-30 06:27:55 +00:00
|
|
|
|
2012-03-09 02:05:24 +00:00
|
|
|
aFontList.AppendElement(kFontLucidaGrande);
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2012-03-09 02:05:24 +00:00
|
|
|
if (!IS_IN_BMP(aCh)) {
|
|
|
|
uint32_t p = aCh >> 16;
|
2014-04-14 23:45:18 +00:00
|
|
|
if (p == 1) {
|
|
|
|
aFontList.AppendElement(kFontAppleSymbols);
|
2012-03-09 02:05:24 +00:00
|
|
|
aFontList.AppendElement(kFontSTIXGeneral);
|
|
|
|
aFontList.AppendElement(kFontGeneva);
|
|
|
|
} else if (p == 2) {
|
2014-04-14 23:45:18 +00:00
|
|
|
// OSX installations with MS Office may have these fonts
|
2012-03-09 02:05:24 +00:00
|
|
|
aFontList.AppendElement(kFontMingLiUExtB);
|
|
|
|
aFontList.AppendElement(kFontSimSunExtB);
|
|
|
|
}
|
2018-11-30 10:46:48 +00:00
|
|
|
} else {
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t b = (aCh >> 8) & 0xff;
|
2018-11-30 10:46:48 +00:00
|
|
|
|
|
|
|
switch (b) {
|
2012-03-09 02:05:24 +00:00
|
|
|
case 0x03:
|
|
|
|
case 0x05:
|
2017-11-12 07:36:24 +00:00
|
|
|
aFontList.AppendElement(kFontGeneva);
|
2018-11-30 10:46:48 +00:00
|
|
|
break;
|
2012-03-09 02:05:24 +00:00
|
|
|
case 0x07:
|
|
|
|
aFontList.AppendElement(kFontGeezaPro);
|
2018-11-30 10:46:48 +00:00
|
|
|
break;
|
2014-04-14 23:45:18 +00:00
|
|
|
case 0x09:
|
|
|
|
aFontList.AppendElement(kFontDevanagariSangamMN);
|
2018-11-30 10:46:48 +00:00
|
|
|
break;
|
2014-04-14 23:45:18 +00:00
|
|
|
case 0x0a:
|
|
|
|
aFontList.AppendElement(kFontGurmukhiMN);
|
|
|
|
aFontList.AppendElement(kFontGujaratiSangamMN);
|
2018-11-30 10:46:48 +00:00
|
|
|
break;
|
2014-04-14 23:45:18 +00:00
|
|
|
case 0x0b:
|
|
|
|
aFontList.AppendElement(kFontTamilMN);
|
2018-11-30 10:46:48 +00:00
|
|
|
break;
|
2014-04-14 23:45:18 +00:00
|
|
|
case 0x0e:
|
|
|
|
aFontList.AppendElement(kFontLaoMN);
|
2018-11-30 10:46:48 +00:00
|
|
|
break;
|
2014-04-14 23:45:18 +00:00
|
|
|
case 0x0f:
|
|
|
|
aFontList.AppendElement(kFontSongtiSC);
|
2018-11-30 10:46:48 +00:00
|
|
|
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);
|
2018-11-30 10:46:48 +00:00
|
|
|
break;
|
2012-03-09 02:05:24 +00:00
|
|
|
case 0x13: // Cherokee
|
|
|
|
aFontList.AppendElement(kFontPlantagenetCherokee);
|
2014-04-14 23:45:18 +00:00
|
|
|
aFontList.AppendElement(kFontKefa);
|
2018-11-30 10:46:48 +00:00
|
|
|
break;
|
2014-04-14 23:45:18 +00:00
|
|
|
case 0x14: // Unified Canadian Aboriginal Syllabics
|
|
|
|
case 0x15:
|
|
|
|
case 0x16:
|
|
|
|
aFontList.AppendElement(kFontEuphemiaUCAS);
|
2012-03-09 02:05:24 +00:00
|
|
|
aFontList.AppendElement(kFontGeneva);
|
2018-11-30 10:46:48 +00:00
|
|
|
break;
|
2014-04-14 23:45:18 +00:00
|
|
|
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);
|
2018-11-30 10:46:48 +00:00
|
|
|
break;
|
2014-04-14 23:45:18 +00:00
|
|
|
case 0x19: // Khmer
|
|
|
|
aFontList.AppendElement(kFontKhmerMN);
|
2012-03-09 02:05:24 +00:00
|
|
|
aFontList.AppendElement(kFontMicrosoftTaiLe);
|
2018-11-30 10:46:48 +00:00
|
|
|
break;
|
2012-03-09 02:05:24 +00:00
|
|
|
case 0x1d:
|
|
|
|
case 0x1e:
|
|
|
|
aFontList.AppendElement(kFontGeneva);
|
2018-11-30 10:46:48 +00:00
|
|
|
break;
|
2012-03-09 02:05:24 +00:00
|
|
|
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);
|
|
|
|
aFontList.AppendElement(kFontGeneva);
|
|
|
|
aFontList.AppendElement(kFontAppleColorEmoji);
|
2018-11-30 10:46:48 +00:00
|
|
|
break;
|
2012-03-09 02:05:24 +00:00
|
|
|
case 0x2c:
|
2014-04-14 23:45:18 +00:00
|
|
|
aFontList.AppendElement(kFontGeneva);
|
2018-11-30 10:46:48 +00:00
|
|
|
break;
|
|
|
|
case 0x2d:
|
2014-04-14 23:45:18 +00:00
|
|
|
aFontList.AppendElement(kFontKefa);
|
|
|
|
aFontList.AppendElement(kFontGeneva);
|
2018-11-30 10:46:48 +00:00
|
|
|
break;
|
2012-03-09 02:05:24 +00:00
|
|
|
case 0x28: // Braille
|
|
|
|
aFontList.AppendElement(kFontAppleBraille);
|
2018-11-30 10:46:48 +00:00
|
|
|
break;
|
2014-04-14 23:45:18 +00:00
|
|
|
case 0x31:
|
2014-08-20 07:54:38 +00:00
|
|
|
aFontList.AppendElement(kFontHiraginoSansGB);
|
2018-11-30 10:46:48 +00:00
|
|
|
break;
|
2012-03-09 02:05:24 +00:00
|
|
|
case 0x4d:
|
|
|
|
aFontList.AppendElement(kFontAppleSymbols);
|
2018-11-30 10:46:48 +00:00
|
|
|
break;
|
2012-03-09 02:05:24 +00:00
|
|
|
case 0xa0: // Yi
|
|
|
|
case 0xa1:
|
|
|
|
case 0xa2:
|
|
|
|
case 0xa3:
|
|
|
|
case 0xa4:
|
|
|
|
aFontList.AppendElement(kFontSTHeiti);
|
2018-11-30 10:46:48 +00:00
|
|
|
break;
|
2012-03-09 02:05:24 +00:00
|
|
|
case 0xa6:
|
|
|
|
case 0xa7:
|
2014-04-14 23:45:18 +00:00
|
|
|
aFontList.AppendElement(kFontGeneva);
|
2012-03-09 02:05:24 +00:00
|
|
|
aFontList.AppendElement(kFontAppleSymbols);
|
2018-11-30 10:46:48 +00:00
|
|
|
break;
|
2014-04-14 23:45:18 +00:00
|
|
|
case 0xab:
|
|
|
|
aFontList.AppendElement(kFontKefa);
|
2018-11-30 10:46:48 +00:00
|
|
|
break;
|
2012-03-09 02:05:24 +00:00
|
|
|
case 0xfc:
|
|
|
|
case 0xff:
|
|
|
|
aFontList.AppendElement(kFontAppleSymbols);
|
2018-11-30 10:46:48 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-03-09 02:05:24 +00:00
|
|
|
|
|
|
|
// 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, nsACString& aSystemFontName,
|
2019-02-08 13:22:11 +00:00
|
|
|
gfxFontStyle& aFontStyle) {
|
2015-10-08 06:04:08 +00:00
|
|
|
gfxMacPlatformFontList* pfl = gfxMacPlatformFontList::PlatformFontList();
|
2019-02-08 13:22:11 +00:00
|
|
|
return pfl->LookupSystemFont(aSystemFontID, aSystemFontName, aFontStyle);
|
2015-10-08 06:04:08 +00:00
|
|
|
}
|
|
|
|
|
2008-05-01 09:07:17 +00:00
|
|
|
uint32_t 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);
|
2018-11-30 10:46:48 +00:00
|
|
|
}
|
2008-05-01 09:07:17 +00:00
|
|
|
|
|
|
|
return threshold;
|
|
|
|
}
|
2008-01-31 00:23:36 +00:00
|
|
|
|
2015-07-16 22:18:05 +00:00
|
|
|
bool gfxPlatformMac::AccelerateLayersByDefault() { return true; }
|
|
|
|
|
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() {}
|
|
|
|
|
2016-11-15 09:16:29 +00:00
|
|
|
Display& GetGlobalDisplay() override { return mGlobalDisplay; }
|
2014-12-18 16:30:06 +00:00
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
class OSXDisplay final : public VsyncSource::Display {
|
2014-12-18 16:30:06 +00:00
|
|
|
public:
|
2015-01-20 16:31:21 +00:00
|
|
|
OSXDisplay() : mDisplayLink(nullptr) {
|
2015-03-18 23:17:26 +00:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2017-10-16 06:15:12 +00:00
|
|
|
mTimer = NS_NewTimer();
|
2014-11-18 21:28:42 +00:00
|
|
|
}
|
|
|
|
|
2015-03-18 23:17:26 +00:00
|
|
|
~OSXDisplay() override { MOZ_ASSERT(NS_IsMainThread()); }
|
2014-12-18 16:30:06 +00:00
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2016-11-15 09:16:29 +00:00
|
|
|
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;
|
2017-06-29 19:13:25 +00:00
|
|
|
mTimer->InitWithNamedFuncCallback(RetryEnableVsync, this, delay,
|
|
|
|
nsITimer::TYPE_ONE_SHOT,
|
|
|
|
"RetryEnableVsync");
|
2015-03-18 23:17:26 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2016-11-15 09:16:29 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2016-11-15 09:16:29 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2016-11-15 09:16:29 +00:00
|
|
|
TimeDuration GetVsyncRate() override { return mVsyncRate; }
|
2015-11-06 16:20:58 +00:00
|
|
|
|
2016-11-15 09:16:29 +00:00
|
|
|
void Shutdown() override {
|
2016-06-06 17:07:29 +00:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
mTimer->Cancel();
|
|
|
|
mTimer = nullptr;
|
|
|
|
DisableVsync();
|
|
|
|
}
|
|
|
|
|
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:
|
2016-11-15 09:16:29 +00:00
|
|
|
~OSXVsyncSource() override = default;
|
2014-11-18 21:28:42 +00:00
|
|
|
|
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() {
|
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) {
|
|
|
|
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;
|
|
|
|
}
|
2018-11-30 10:46:48 +00:00
|
|
|
}
|
2013-10-09 05:53:37 +00:00
|
|
|
|
|
|
|
::CFRelease(iccp);
|
2007-07-23 22:02:17 +00:00
|
|
|
}
|
2018-04-05 17:53:56 +00:00
|
|
|
|
|
|
|
bool gfxPlatformMac::CheckVariationFontSupport() {
|
2018-04-25 13:03:44 +00:00
|
|
|
// We don't allow variation fonts to be enabled before 10.13,
|
2018-04-05 17:53:56 +00:00
|
|
|
// as although the Core Text APIs existed, they are known to be
|
|
|
|
// fairly buggy.
|
2018-04-25 13:03:44 +00:00
|
|
|
// (Note that Safari also requires 10.13 for variation-font support.)
|
|
|
|
return nsCocoaFeatures::OnHighSierraOrLater();
|
2018-04-05 17:53:56 +00:00
|
|
|
}
|