2018-11-30 22:52:05 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2018-11-30 18:39:55 +03:00
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2013-01-18 04:45:11 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
2012-05-21 15:12:37 +04:00
|
|
|
* 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/. */
|
2010-05-11 21:27:36 +04:00
|
|
|
|
2012-08-23 14:23:43 +04:00
|
|
|
#include "base/basictypes.h"
|
|
|
|
|
2010-05-11 21:27:36 +04:00
|
|
|
#include "gfxAndroidPlatform.h"
|
2011-11-02 23:55:03 +04:00
|
|
|
#include "mozilla/gfx/2D.h"
|
2020-07-02 16:43:19 +03:00
|
|
|
#include "mozilla/gfx/gfxVars.h"
|
2014-08-25 23:34:00 +04:00
|
|
|
#include "mozilla/CountingAllocatorBase.h"
|
2017-03-13 06:39:22 +03:00
|
|
|
#include "mozilla/intl/LocaleService.h"
|
2017-03-22 10:27:14 +03:00
|
|
|
#include "mozilla/intl/OSPreferences.h"
|
2020-07-02 16:43:19 +03:00
|
|
|
#include "mozilla/jni/Utils.h"
|
|
|
|
#include "mozilla/layers/AndroidHardwareBuffer.h"
|
2013-01-17 20:52:41 +04:00
|
|
|
#include "mozilla/Preferences.h"
|
2019-07-26 04:10:23 +03:00
|
|
|
#include "mozilla/StaticPrefs_gfx.h"
|
2010-05-11 21:27:36 +04:00
|
|
|
|
2014-02-09 12:04:38 +04:00
|
|
|
#include "gfx2DGlue.h"
|
2011-09-23 15:15:36 +04:00
|
|
|
#include "gfxFT2FontList.h"
|
2010-05-11 21:27:36 +04:00
|
|
|
#include "gfxImageSurface.h"
|
2014-09-16 13:58:12 +04:00
|
|
|
#include "gfxTextRun.h"
|
2012-02-09 02:52:57 +04:00
|
|
|
#include "nsXULAppAPI.h"
|
2012-03-14 00:59:26 +04:00
|
|
|
#include "nsIScreen.h"
|
2013-10-08 03:15:59 +04:00
|
|
|
#include "nsServiceManagerUtils.h"
|
2017-11-12 10:36:24 +03:00
|
|
|
#include "nsUnicodeProperties.h"
|
2011-09-23 15:15:36 +04:00
|
|
|
#include "cairo.h"
|
2014-12-18 19:30:06 +03:00
|
|
|
#include "VsyncSource.h"
|
2010-05-11 21:27:36 +04:00
|
|
|
|
|
|
|
#include "ft2build.h"
|
|
|
|
#include FT_FREETYPE_H
|
2012-11-20 07:00:19 +04:00
|
|
|
#include FT_MODULE_H
|
|
|
|
|
2020-05-15 20:05:59 +03:00
|
|
|
#include "mozilla/java/VsyncSourceNatives.h"
|
2016-12-20 10:24:49 +03:00
|
|
|
|
2011-11-02 23:55:03 +04:00
|
|
|
using namespace mozilla;
|
2012-08-23 14:23:43 +04:00
|
|
|
using namespace mozilla::dom;
|
2011-11-02 23:55:03 +04:00
|
|
|
using namespace mozilla::gfx;
|
2017-11-12 10:36:24 +03:00
|
|
|
using namespace mozilla::unicode;
|
2017-03-13 06:39:22 +03:00
|
|
|
using mozilla::intl::LocaleService;
|
2017-03-22 10:27:14 +03:00
|
|
|
using mozilla::intl::OSPreferences;
|
2010-05-11 21:27:36 +04:00
|
|
|
|
2013-07-31 19:44:31 +04:00
|
|
|
static FT_Library gPlatformFTLibrary = nullptr;
|
2010-05-11 21:27:36 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class FreetypeReporter final : public nsIMemoryReporter,
|
2015-03-27 21:52:19 +03:00
|
|
|
public CountingAllocatorBase<FreetypeReporter> {
|
2014-08-26 23:07:59 +04:00
|
|
|
private:
|
|
|
|
~FreetypeReporter() {}
|
|
|
|
|
2013-01-18 04:45:11 +04:00
|
|
|
public:
|
2013-12-08 10:09:10 +04:00
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
2014-04-08 21:51:20 +04:00
|
|
|
static void* Malloc(FT_Memory, long size) { return CountingMalloc(size); }
|
2012-11-20 07:00:19 +04:00
|
|
|
|
2014-04-08 21:51:20 +04:00
|
|
|
static void Free(FT_Memory, void* p) { return CountingFree(p); }
|
2012-11-20 07:00:19 +04:00
|
|
|
|
2014-04-08 21:51:20 +04:00
|
|
|
static void* Realloc(FT_Memory, long cur_size, long new_size, void* p) {
|
|
|
|
return CountingRealloc(p, new_size);
|
2013-01-18 04:45:11 +04:00
|
|
|
}
|
2012-11-20 07:00:19 +04:00
|
|
|
|
2013-12-08 10:09:10 +04:00
|
|
|
NS_IMETHOD CollectReports(nsIHandleReportCallback* aHandleReport,
|
2016-06-04 01:31:05 +03:00
|
|
|
nsISupports* aData, bool aAnonymize) override {
|
2014-04-08 21:51:20 +04:00
|
|
|
MOZ_COLLECT_REPORT("explicit/freetype", KIND_HEAP, UNITS_BYTES,
|
2013-12-08 10:09:10 +04:00
|
|
|
MemoryAllocated(), "Memory used by Freetype.");
|
2016-08-24 08:23:45 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
2013-12-08 10:09:10 +04:00
|
|
|
}
|
2013-01-18 04:45:11 +04:00
|
|
|
};
|
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS(FreetypeReporter, nsIMemoryReporter)
|
2013-12-08 10:09:10 +04:00
|
|
|
|
2018-07-31 22:22:54 +03:00
|
|
|
template <>
|
|
|
|
CountingAllocatorBase<FreetypeReporter>::AmountType
|
|
|
|
CountingAllocatorBase<FreetypeReporter>::sAmount(0);
|
2013-01-18 04:45:11 +04:00
|
|
|
|
|
|
|
static FT_MemoryRec_ sFreetypeMemoryRecord;
|
2012-11-20 07:00:19 +04:00
|
|
|
|
2010-05-11 21:27:36 +04:00
|
|
|
gfxAndroidPlatform::gfxAndroidPlatform() {
|
2012-11-20 07:00:19 +04:00
|
|
|
// A custom allocator. It counts allocations, enabling memory reporting.
|
|
|
|
sFreetypeMemoryRecord.user = nullptr;
|
2014-04-08 21:51:20 +04:00
|
|
|
sFreetypeMemoryRecord.alloc = FreetypeReporter::Malloc;
|
|
|
|
sFreetypeMemoryRecord.free = FreetypeReporter::Free;
|
|
|
|
sFreetypeMemoryRecord.realloc = FreetypeReporter::Realloc;
|
2012-11-20 07:00:19 +04:00
|
|
|
|
|
|
|
// These two calls are equivalent to FT_Init_FreeType(), but allow us to
|
|
|
|
// provide a custom memory allocator.
|
|
|
|
FT_New_Library(&sFreetypeMemoryRecord, &gPlatformFTLibrary);
|
|
|
|
FT_Add_Default_Modules(gPlatformFTLibrary);
|
|
|
|
|
2017-05-18 04:56:24 +03:00
|
|
|
Factory::SetFTLibrary(gPlatformFTLibrary);
|
|
|
|
|
2013-11-07 09:35:30 +04:00
|
|
|
RegisterStrongMemoryReporter(new FreetypeReporter());
|
2012-03-14 00:59:26 +04:00
|
|
|
|
2015-08-27 01:37:48 +03:00
|
|
|
mOffscreenFormat = GetScreenDepth() == 16 ? SurfaceFormat::R5G6B5_UINT16
|
2016-01-08 07:57:38 +03:00
|
|
|
: SurfaceFormat::X8R8G8B8_UINT32;
|
2013-01-17 20:52:41 +04:00
|
|
|
|
2019-07-22 05:10:14 +03:00
|
|
|
if (StaticPrefs::gfx_android_rgb16_force_AtStartup()) {
|
2016-01-08 07:57:38 +03:00
|
|
|
mOffscreenFormat = SurfaceFormat::R5G6B5_UINT16;
|
2013-01-17 20:52:41 +04:00
|
|
|
}
|
2010-05-11 21:27:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
gfxAndroidPlatform::~gfxAndroidPlatform() {
|
2012-11-20 07:00:19 +04:00
|
|
|
FT_Done_Library(gPlatformFTLibrary);
|
2013-07-31 19:44:31 +04:00
|
|
|
gPlatformFTLibrary = nullptr;
|
2010-05-11 21:27:36 +04:00
|
|
|
}
|
|
|
|
|
2020-07-02 16:43:19 +03:00
|
|
|
void gfxAndroidPlatform::InitAcceleration() {
|
|
|
|
gfxPlatform::InitAcceleration();
|
|
|
|
if (XRE_IsParentProcess() && jni::GetAPIVersion() >= 26) {
|
|
|
|
if (StaticPrefs::gfx_use_ahardwarebuffer_content_AtStartup()) {
|
|
|
|
gfxVars::SetUseAHardwareBufferContent(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (gfx::gfxVars::UseAHardwareBufferContent()) {
|
|
|
|
layers::AndroidHardwareBufferApi::Init();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-07 04:21:47 +03:00
|
|
|
already_AddRefed<gfxASurface> gfxAndroidPlatform::CreateOffscreenSurface(
|
|
|
|
const IntSize& aSize, gfxImageFormat aFormat) {
|
2016-09-15 17:36:21 +03:00
|
|
|
if (!Factory::AllowedSurfaceSize(aSize)) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<gfxASurface> newSurface;
|
2015-07-07 04:21:47 +03:00
|
|
|
newSurface = new gfxImageSurface(aSize, aFormat);
|
2010-05-11 21:27:36 +04:00
|
|
|
|
|
|
|
return newSurface.forget();
|
|
|
|
}
|
|
|
|
|
2013-04-07 01:04:30 +04:00
|
|
|
static bool IsJapaneseLocale() {
|
|
|
|
static bool sInitialized = false;
|
|
|
|
static bool sIsJapanese = false;
|
|
|
|
|
|
|
|
if (!sInitialized) {
|
|
|
|
sInitialized = true;
|
|
|
|
|
2017-03-13 06:39:22 +03:00
|
|
|
nsAutoCString appLocale;
|
2020-01-17 22:29:09 +03:00
|
|
|
LocaleService::GetInstance()->GetAppLocaleAsBCP47(appLocale);
|
2017-03-13 06:39:22 +03:00
|
|
|
|
|
|
|
const nsDependentCSubstring lang(appLocale, 0, 2);
|
|
|
|
if (lang.EqualsLiteral("ja")) {
|
|
|
|
sIsJapanese = true;
|
2017-03-22 10:27:14 +03:00
|
|
|
} else {
|
|
|
|
OSPreferences::GetInstance()->GetSystemLocale(appLocale);
|
|
|
|
|
|
|
|
const nsDependentCSubstring lang(appLocale, 0, 2);
|
|
|
|
if (lang.EqualsLiteral("ja")) {
|
|
|
|
sIsJapanese = true;
|
2017-03-13 06:39:22 +03:00
|
|
|
}
|
2013-04-07 01:04:30 +04:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2013-04-07 01:04:30 +04:00
|
|
|
|
|
|
|
return sIsJapanese;
|
|
|
|
}
|
|
|
|
|
2014-09-30 10:27:55 +04:00
|
|
|
void gfxAndroidPlatform::GetCommonFallbackFonts(
|
|
|
|
uint32_t aCh, uint32_t aNextCh, Script aRunScript,
|
2013-03-04 21:03:16 +04:00
|
|
|
nsTArray<const char*>& aFontList) {
|
|
|
|
static const char kDroidSansJapanese[] = "Droid Sans Japanese";
|
2013-08-30 14:01:43 +04:00
|
|
|
static const char kMotoyaLMaru[] = "MotoyaLMaru";
|
2016-09-05 06:01:01 +03:00
|
|
|
static const char kNotoSansCJKJP[] = "Noto Sans CJK JP";
|
2015-08-21 11:55:52 +03:00
|
|
|
static const char kNotoColorEmoji[] = "Noto Color Emoji";
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-11-12 10:36:24 +03: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(kNotoColorEmoji);
|
2014-09-30 10:27:55 +04:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2017-11-12 10:36:24 +03:00
|
|
|
if (IS_IN_BMP(aCh)) {
|
2014-06-02 11:46:54 +04:00
|
|
|
// try language-specific "Droid Sans *" and "Noto Sans *" fonts for
|
|
|
|
// certain blocks, as most devices probably have these
|
2013-03-04 21:03:16 +04:00
|
|
|
uint8_t block = (aCh >> 8) & 0xff;
|
|
|
|
switch (block) {
|
|
|
|
case 0x05:
|
2019-03-21 07:41:30 +03:00
|
|
|
aFontList.AppendElement("Noto Sans Hebrew");
|
2013-03-04 21:03:16 +04:00
|
|
|
aFontList.AppendElement("Droid Sans Hebrew");
|
2019-03-21 07:41:30 +03:00
|
|
|
aFontList.AppendElement("Noto Sans Armenian");
|
2013-03-04 21:03:16 +04:00
|
|
|
aFontList.AppendElement("Droid Sans Armenian");
|
|
|
|
break;
|
|
|
|
case 0x06:
|
2019-03-21 07:41:30 +03:00
|
|
|
aFontList.AppendElement("Noto Sans Arabic");
|
2013-03-04 21:03:16 +04:00
|
|
|
aFontList.AppendElement("Droid Sans Arabic");
|
|
|
|
break;
|
|
|
|
case 0x09:
|
2014-06-02 11:46:54 +04:00
|
|
|
aFontList.AppendElement("Noto Sans Devanagari");
|
2013-03-04 21:03:16 +04:00
|
|
|
aFontList.AppendElement("Droid Sans Devanagari");
|
|
|
|
break;
|
|
|
|
case 0x0b:
|
2014-06-02 11:46:54 +04:00
|
|
|
aFontList.AppendElement("Noto Sans Tamil");
|
2013-03-04 21:03:16 +04:00
|
|
|
aFontList.AppendElement("Droid Sans Tamil");
|
|
|
|
break;
|
|
|
|
case 0x0e:
|
2014-06-02 11:46:54 +04:00
|
|
|
aFontList.AppendElement("Noto Sans Thai");
|
2013-03-04 21:03:16 +04:00
|
|
|
aFontList.AppendElement("Droid Sans Thai");
|
|
|
|
break;
|
|
|
|
case 0x10:
|
|
|
|
case 0x2d:
|
2019-03-21 07:41:30 +03:00
|
|
|
aFontList.AppendElement("Noto Sans Georgian");
|
2013-03-04 21:03:16 +04:00
|
|
|
aFontList.AppendElement("Droid Sans Georgian");
|
|
|
|
break;
|
|
|
|
case 0x12:
|
|
|
|
case 0x13:
|
2019-03-21 07:41:30 +03:00
|
|
|
aFontList.AppendElement("Noto Sans Ethiopic");
|
2013-03-04 21:03:16 +04:00
|
|
|
aFontList.AppendElement("Droid Sans Ethiopic");
|
|
|
|
break;
|
2019-01-21 23:04:07 +03:00
|
|
|
case 0x21:
|
|
|
|
case 0x23:
|
|
|
|
case 0x24:
|
|
|
|
case 0x26:
|
|
|
|
case 0x27:
|
|
|
|
case 0x29:
|
|
|
|
aFontList.AppendElement("Noto Sans Symbols");
|
|
|
|
break;
|
2013-03-04 21:03:16 +04:00
|
|
|
case 0xf9:
|
|
|
|
case 0xfa:
|
2013-04-07 01:04:30 +04:00
|
|
|
if (IsJapaneseLocale()) {
|
2013-08-30 14:01:43 +04:00
|
|
|
aFontList.AppendElement(kMotoyaLMaru);
|
2016-09-05 06:01:01 +03:00
|
|
|
aFontList.AppendElement(kNotoSansCJKJP);
|
2013-03-04 21:03:16 +04:00
|
|
|
aFontList.AppendElement(kDroidSansJapanese);
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
break;
|
|
|
|
default:
|
2013-04-07 01:04:30 +04:00
|
|
|
if (block >= 0x2e && block <= 0x9f && IsJapaneseLocale()) {
|
2013-08-30 14:01:43 +04:00
|
|
|
aFontList.AppendElement(kMotoyaLMaru);
|
2016-09-05 06:01:01 +03:00
|
|
|
aFontList.AppendElement(kNotoSansCJKJP);
|
2013-04-07 01:04:30 +04:00
|
|
|
aFontList.AppendElement(kDroidSansJapanese);
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
break;
|
2013-03-04 21:03:16 +04:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2013-03-04 21:03:16 +04:00
|
|
|
// and try Droid Sans Fallback as a last resort
|
|
|
|
aFontList.AppendElement("Droid Sans Fallback");
|
|
|
|
}
|
|
|
|
|
2010-07-16 10:03:45 +04:00
|
|
|
gfxPlatformFontList* gfxAndroidPlatform::CreatePlatformFontList() {
|
2010-11-08 14:02:27 +03:00
|
|
|
gfxPlatformFontList* list = new gfxFT2FontList();
|
|
|
|
if (NS_SUCCEEDED(list->InitFontList())) {
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
gfxPlatformFontList::Shutdown();
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2010-07-16 10:03:45 +04:00
|
|
|
}
|
|
|
|
|
2020-03-09 15:27:45 +03:00
|
|
|
void gfxAndroidPlatform::ReadSystemFontList(
|
|
|
|
nsTArray<SystemFontListEntry>* aFontList) {
|
|
|
|
gfxFT2FontList::PlatformFontList()->ReadSystemFontList(aFontList);
|
|
|
|
}
|
|
|
|
|
2012-02-09 02:52:57 +04:00
|
|
|
bool gfxAndroidPlatform::FontHintingEnabled() {
|
|
|
|
// In "mobile" builds, we sometimes use non-reflow-zoom, so we
|
|
|
|
// might not want hinting. Let's see.
|
2013-01-15 19:19:28 +04:00
|
|
|
|
2016-09-08 17:03:34 +03:00
|
|
|
#ifdef MOZ_WIDGET_ANDROID
|
|
|
|
// On Android, we currently only use gecko to render web
|
2012-02-09 02:52:57 +04:00
|
|
|
// content that can always be be non-reflow-zoomed. So turn off
|
|
|
|
// hinting.
|
2016-12-20 10:24:49 +03:00
|
|
|
//
|
2013-01-15 19:19:28 +04:00
|
|
|
// XXX when gecko-android-java is used as an "app runtime", we may
|
|
|
|
// want to re-enable hinting for non-browser processes there.
|
|
|
|
return false;
|
2016-09-08 17:03:34 +03:00
|
|
|
#endif // MOZ_WIDGET_ANDROID
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2013-01-15 19:19:28 +04:00
|
|
|
// Currently, we don't have any other targets, but if/when we do,
|
|
|
|
// decide how to handle them here.
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-06-18 08:43:11 +03:00
|
|
|
MOZ_ASSERT_UNREACHABLE("oops, what platform is this?");
|
2013-01-15 19:19:28 +04:00
|
|
|
return gfxPlatform::FontHintingEnabled();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool gfxAndroidPlatform::RequiresLinearZoom() {
|
2016-09-08 17:03:34 +03:00
|
|
|
#ifdef MOZ_WIDGET_ANDROID
|
|
|
|
// On Android, we currently only use gecko to render web
|
2013-01-15 19:19:28 +04:00
|
|
|
// content that can always be be non-reflow-zoomed.
|
|
|
|
//
|
|
|
|
// XXX when gecko-android-java is used as an "app runtime", we may
|
2016-11-16 09:01:30 +03:00
|
|
|
// want to use linear zoom only for the web browser process, not other apps.
|
2013-01-15 19:19:28 +04:00
|
|
|
return true;
|
|
|
|
#endif
|
|
|
|
|
2018-06-18 08:43:11 +03:00
|
|
|
MOZ_ASSERT_UNREACHABLE("oops, what platform is this?");
|
2013-01-15 19:19:28 +04:00
|
|
|
return gfxPlatform::RequiresLinearZoom();
|
2012-02-09 02:52:57 +04:00
|
|
|
}
|
2012-05-15 23:41:20 +04:00
|
|
|
|
2016-12-20 10:24:49 +03:00
|
|
|
class AndroidVsyncSource final : public VsyncSource {
|
|
|
|
public:
|
|
|
|
class JavaVsyncSupport final
|
|
|
|
: public java::VsyncSource::Natives<JavaVsyncSupport> {
|
|
|
|
public:
|
|
|
|
using Base = java::VsyncSource::Natives<JavaVsyncSupport>;
|
|
|
|
using Base::DisposeNative;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-12-20 10:24:49 +03:00
|
|
|
static void NotifyVsync() {
|
|
|
|
GetDisplayInstance().NotifyVsync(TimeStamp::Now());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class Display final : public VsyncSource::Display {
|
2018-11-30 13:46:48 +03:00
|
|
|
public:
|
2016-12-20 10:24:49 +03:00
|
|
|
Display()
|
|
|
|
: mJavaVsync(java::VsyncSource::INSTANCE()), mObservingVsync(false) {
|
|
|
|
JavaVsyncSupport::Init(); // To register native methods.
|
|
|
|
}
|
|
|
|
|
|
|
|
~Display() { DisableVsync(); }
|
|
|
|
|
|
|
|
bool IsVsyncEnabled() override {
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
MOZ_ASSERT(mJavaVsync);
|
|
|
|
|
|
|
|
return mObservingVsync;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2016-12-20 10:24:49 +03:00
|
|
|
void EnableVsync() override {
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
MOZ_ASSERT(mJavaVsync);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-12-20 10:24:49 +03:00
|
|
|
if (mObservingVsync) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
bool ok = mJavaVsync->ObserveVsync(true);
|
|
|
|
if (ok && !mVsyncDuration) {
|
|
|
|
float fps = mJavaVsync->GetRefreshRate();
|
|
|
|
mVsyncDuration = TimeDuration::FromMilliseconds(1000.0 / fps);
|
|
|
|
}
|
|
|
|
mObservingVsync = ok;
|
|
|
|
MOZ_ASSERT(mObservingVsync);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DisableVsync() override {
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
MOZ_ASSERT(mJavaVsync);
|
|
|
|
|
|
|
|
if (!mObservingVsync) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mObservingVsync = mJavaVsync->ObserveVsync(false);
|
|
|
|
MOZ_ASSERT(!mObservingVsync);
|
|
|
|
}
|
|
|
|
|
|
|
|
TimeDuration GetVsyncRate() override { return mVsyncDuration; }
|
|
|
|
|
|
|
|
void Shutdown() override {
|
|
|
|
DisableVsync();
|
|
|
|
mJavaVsync = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
java::VsyncSource::GlobalRef mJavaVsync;
|
|
|
|
bool mObservingVsync;
|
|
|
|
TimeDuration mVsyncDuration;
|
|
|
|
};
|
|
|
|
|
2018-02-06 09:46:57 +03:00
|
|
|
Display& GetGlobalDisplay() final { return GetDisplayInstance(); }
|
2016-12-20 10:24:49 +03:00
|
|
|
|
2020-05-05 09:04:37 +03:00
|
|
|
private:
|
2019-04-11 15:36:51 +03:00
|
|
|
virtual ~AndroidVsyncSource() = default;
|
2016-12-20 10:24:49 +03:00
|
|
|
|
2020-05-05 09:04:37 +03:00
|
|
|
static Display& GetDisplayInstance() {
|
2020-05-09 02:19:31 +03:00
|
|
|
static RefPtr<Display> globalDisplay = new Display();
|
|
|
|
return *globalDisplay;
|
2020-05-05 09:04:37 +03:00
|
|
|
}
|
2016-12-20 10:24:49 +03:00
|
|
|
};
|
|
|
|
|
2014-12-18 19:30:06 +03:00
|
|
|
already_AddRefed<mozilla::gfx::VsyncSource>
|
|
|
|
gfxAndroidPlatform::CreateHardwareVsyncSource() {
|
2017-01-09 22:10:23 +03:00
|
|
|
// Vsync was introduced since JB (API 16~18) but inaccurate. Enable only for
|
|
|
|
// KK (API 19) and later.
|
|
|
|
if (AndroidBridge::Bridge() &&
|
|
|
|
AndroidBridge::Bridge()->GetAPIVersion() >= 19) {
|
2016-12-20 10:24:49 +03:00
|
|
|
RefPtr<AndroidVsyncSource> vsyncSource = new AndroidVsyncSource();
|
|
|
|
return vsyncSource.forget();
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-12-20 10:24:49 +03:00
|
|
|
NS_WARNING("Vsync not supported. Falling back to software vsync");
|
2015-03-20 18:12:53 +03:00
|
|
|
return gfxPlatform::CreateHardwareVsyncSource();
|
2014-12-18 19:30:06 +03:00
|
|
|
}
|