2013-01-18 04:45:11 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/* vim: set ts=8 sts=4 et sw=4 tw=80: */
|
|
|
|
/* 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"
|
2014-08-25 23:34:00 +04:00
|
|
|
#include "mozilla/CountingAllocatorBase.h"
|
2013-01-17 20:52:41 +04:00
|
|
|
#include "mozilla/Preferences.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-08-23 14:23:43 +04:00
|
|
|
#include "mozilla/dom/ContentChild.h"
|
2012-02-09 02:52:57 +04:00
|
|
|
#include "nsXULAppAPI.h"
|
2012-03-14 00:59:26 +04:00
|
|
|
#include "nsIScreen.h"
|
|
|
|
#include "nsIScreenManager.h"
|
2013-04-07 01:04:30 +04:00
|
|
|
#include "nsILocaleService.h"
|
2013-10-08 03:15:59 +04:00
|
|
|
#include "nsServiceManagerUtils.h"
|
2014-03-04 02:11:06 +04:00
|
|
|
#include "gfxPrefs.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
|
|
|
|
2014-04-01 17:33:49 +04:00
|
|
|
#ifdef MOZ_WIDGET_GONK
|
|
|
|
#include <cutils/properties.h>
|
2016-03-22 21:08:38 +03:00
|
|
|
#include "mozilla/layers/CompositorBridgeParent.h"
|
2014-12-18 19:30:06 +03:00
|
|
|
#include "HwcComposer2D.h"
|
2014-04-01 17:33:49 +04:00
|
|
|
#endif
|
|
|
|
|
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
|
|
|
|
|
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;
|
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>
|
2012-11-20 07:00:19 +04:00
|
|
|
{
|
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)
|
2013-01-18 04:45:11 +04:00
|
|
|
{
|
2014-04-08 21:51:20 +04:00
|
|
|
return CountingMalloc(size);
|
2013-01-18 04:45:11 +04:00
|
|
|
}
|
2012-11-20 07:00:19 +04:00
|
|
|
|
2014-04-08 21:51:20 +04:00
|
|
|
static void Free(FT_Memory, void* p)
|
2013-01-18 04:45:11 +04:00
|
|
|
{
|
2014-04-08 21:51:20 +04:00
|
|
|
return CountingFree(p);
|
2013-01-18 04:45:11 +04:00
|
|
|
}
|
2012-11-20 07:00:19 +04:00
|
|
|
|
2013-01-18 04:45:11 +04:00
|
|
|
static void*
|
2014-04-08 21:51:20 +04:00
|
|
|
Realloc(FT_Memory, long cur_size, long new_size, void* p)
|
2013-01-18 04:45:11 +04:00
|
|
|
{
|
2014-04-08 21:51:20 +04:00
|
|
|
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
|
2013-12-08 10:09:10 +04:00
|
|
|
{
|
|
|
|
return MOZ_COLLECT_REPORT(
|
2014-04-08 21:51:20 +04:00
|
|
|
"explicit/freetype", KIND_HEAP, UNITS_BYTES, MemoryAllocated(),
|
2013-12-08 10:09:10 +04:00
|
|
|
"Memory used by Freetype.");
|
|
|
|
}
|
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
|
|
|
|
2014-04-08 21:51:20 +04:00
|
|
|
template<> Atomic<size_t> 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);
|
|
|
|
|
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
|
2016-01-08 07:57:38 +03:00
|
|
|
? SurfaceFormat::R5G6B5_UINT16
|
|
|
|
: SurfaceFormat::X8R8G8B8_UINT32;
|
2013-01-17 20:52:41 +04:00
|
|
|
|
2014-03-04 02:11:06 +04:00
|
|
|
if (gfxPrefs::AndroidRGB16Force()) {
|
2016-01-08 07:57:38 +03:00
|
|
|
mOffscreenFormat = SurfaceFormat::R5G6B5_UINT16;
|
2013-01-17 20:52:41 +04:00
|
|
|
}
|
|
|
|
|
2014-04-01 17:33:49 +04:00
|
|
|
#ifdef MOZ_WIDGET_GONK
|
|
|
|
char propQemu[PROPERTY_VALUE_MAX];
|
|
|
|
property_get("ro.kernel.qemu", propQemu, "");
|
|
|
|
mIsInGonkEmulator = !strncmp(propQemu, "1", 1);
|
|
|
|
#endif
|
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
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<gfxASurface>
|
2015-07-07 04:21:47 +03:00
|
|
|
gfxAndroidPlatform::CreateOffscreenSurface(const IntSize& aSize,
|
|
|
|
gfxImageFormat aFormat)
|
2010-05-11 21:27:36 +04:00
|
|
|
{
|
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;
|
|
|
|
|
|
|
|
do { // to allow 'break' to abandon 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 = nsDependentSubstring(localeStr, 0, 2);
|
|
|
|
if (lang.EqualsLiteral("ja")) {
|
|
|
|
sIsJapanese = true;
|
|
|
|
}
|
|
|
|
} while (false);
|
|
|
|
}
|
|
|
|
|
|
|
|
return sIsJapanese;
|
|
|
|
}
|
|
|
|
|
2013-03-04 21:03:16 +04:00
|
|
|
void
|
2014-09-30 10:27:55 +04:00
|
|
|
gfxAndroidPlatform::GetCommonFallbackFonts(uint32_t aCh, uint32_t aNextCh,
|
2016-04-21 20:58:59 +03:00
|
|
|
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";
|
2015-08-21 11:55:52 +03:00
|
|
|
static const char kNotoColorEmoji[] = "Noto Color Emoji";
|
|
|
|
#ifdef MOZ_WIDGET_GONK
|
|
|
|
static const char kFirefoxEmoji[] = "Firefox Emoji";
|
|
|
|
#endif
|
2013-03-04 21:03:16 +04:00
|
|
|
|
2014-09-30 10:27:55 +04:00
|
|
|
if (aNextCh == 0xfe0fu) {
|
|
|
|
// if char is followed by VS16, try for a color emoji glyph
|
2015-08-21 11:55:52 +03:00
|
|
|
#ifdef MOZ_WIDGET_GONK
|
|
|
|
aFontList.AppendElement(kFirefoxEmoji);
|
|
|
|
#endif
|
|
|
|
aFontList.AppendElement(kNotoColorEmoji);
|
2014-09-30 10:27:55 +04:00
|
|
|
}
|
|
|
|
|
2015-08-21 11:55:52 +03:00
|
|
|
if (!IS_IN_BMP(aCh)) {
|
|
|
|
uint32_t p = aCh >> 16;
|
|
|
|
if (p == 1) { // try color emoji font, unless VS15 (text style) present
|
|
|
|
if (aNextCh != 0xfe0fu && aNextCh != 0xfe0eu) {
|
|
|
|
#ifdef MOZ_WIDGET_GONK
|
|
|
|
aFontList.AppendElement(kFirefoxEmoji);
|
|
|
|
#endif
|
|
|
|
aFontList.AppendElement(kNotoColorEmoji);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
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:
|
|
|
|
aFontList.AppendElement("Droid Sans Hebrew");
|
|
|
|
aFontList.AppendElement("Droid Sans Armenian");
|
|
|
|
break;
|
|
|
|
case 0x06:
|
|
|
|
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:
|
|
|
|
aFontList.AppendElement("Droid Sans Georgian");
|
|
|
|
break;
|
|
|
|
case 0x12: case 0x13:
|
|
|
|
aFontList.AppendElement("Droid Sans Ethiopic");
|
|
|
|
break;
|
|
|
|
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);
|
2013-04-07 01:04:30 +04:00
|
|
|
aFontList.AppendElement(kDroidSansJapanese);
|
|
|
|
}
|
2013-03-04 21:03:16 +04: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);
|
2013-03-04 21:03:16 +04:00
|
|
|
aFontList.AppendElement(kDroidSansJapanese);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// and try Droid Sans Fallback as a last resort
|
|
|
|
aFontList.AppendElement("Droid Sans Fallback");
|
|
|
|
}
|
|
|
|
|
2011-01-13 07:04:42 +03:00
|
|
|
void
|
2015-05-13 08:11:25 +03:00
|
|
|
gfxAndroidPlatform::GetSystemFontList(InfallibleTArray<FontListEntry>* retValue)
|
2010-05-11 21:27:36 +04:00
|
|
|
{
|
2015-05-13 08:11:25 +03:00
|
|
|
gfxFT2FontList::PlatformFontList()->GetSystemFontList(retValue);
|
2011-01-13 07:04:42 +03:00
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2012-08-22 19:56:38 +04:00
|
|
|
gfxAndroidPlatform::IsFontFormatSupported(nsIURI *aFontURI, uint32_t aFormatFlags)
|
2010-07-16 10:03:45 +04: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 14:36:05 +04:00
|
|
|
if (aFormatFlags & gfxUserFontSet::FLAG_FORMATS_COMMON) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2010-07-16 10:03:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// reject all other formats, known and unknown
|
|
|
|
if (aFormatFlags != 0) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2010-07-16 10:03:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// no format hint set, need to look at data
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2010-07-16 10:03:45 +04:00
|
|
|
}
|
|
|
|
|
2010-05-11 21:27:36 +04:00
|
|
|
gfxFontGroup *
|
2014-06-06 10:09:23 +04:00
|
|
|
gfxAndroidPlatform::CreateFontGroup(const FontFamilyList& aFontFamilyList,
|
2015-09-11 07:24:33 +03:00
|
|
|
const gfxFontStyle* aStyle,
|
|
|
|
gfxTextPerfMetrics* aTextPerf,
|
2015-11-20 16:01:12 +03:00
|
|
|
gfxUserFontSet* aUserFontSet,
|
|
|
|
gfxFloat aDevToCssSize)
|
2010-05-11 21:27:36 +04:00
|
|
|
{
|
2015-11-20 16:01:12 +03:00
|
|
|
return new gfxFontGroup(aFontFamilyList, aStyle, aTextPerf,
|
|
|
|
aUserFontSet, aDevToCssSize);
|
2010-05-11 21:27:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
FT_Library
|
|
|
|
gfxAndroidPlatform::GetFTLibrary()
|
|
|
|
{
|
|
|
|
return gPlatformFTLibrary;
|
|
|
|
}
|
|
|
|
|
2015-06-17 17:00:52 +03:00
|
|
|
already_AddRefed<ScaledFont>
|
2012-07-24 14:18:37 +04:00
|
|
|
gfxAndroidPlatform::GetScaledFontForFont(DrawTarget* aTarget, gfxFont *aFont)
|
2011-11-02 23:55:03 +04:00
|
|
|
{
|
2014-01-30 11:01:16 +04:00
|
|
|
return GetScaledFontForFontWithCairoSkia(aTarget, aFont);
|
2011-11-02 23:55:03 +04:00
|
|
|
}
|
|
|
|
|
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-06-01 02:06:06 +03:00
|
|
|
#ifdef MOZ_USING_ANDROID_JAVA_WIDGETS
|
|
|
|
// On android-java, 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.
|
|
|
|
//
|
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-06-01 02:06:06 +03:00
|
|
|
#endif // MOZ_USING_ANDROID_JAVA_WIDGETS
|
2013-01-15 19:19:28 +04:00
|
|
|
|
2013-01-30 16:03:39 +04:00
|
|
|
#ifdef MOZ_WIDGET_GONK
|
2013-01-15 19:19:28 +04:00
|
|
|
// On B2G, the UX preference is currently to keep hinting disabled
|
|
|
|
// for all text (see bug 829523).
|
2012-02-09 02:52:57 +04:00
|
|
|
return false;
|
2013-01-30 16:03:39 +04:00
|
|
|
#endif
|
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.
|
|
|
|
|
|
|
|
NS_NOTREACHED("oops, what platform is this?");
|
|
|
|
return gfxPlatform::FontHintingEnabled();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
gfxAndroidPlatform::RequiresLinearZoom()
|
|
|
|
{
|
2016-06-01 02:06:06 +03:00
|
|
|
#ifdef MOZ_USING_ANDROID_JAVA_WIDGETS
|
|
|
|
// On android-java, 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
|
|
|
|
// want to treat it like B2G and use linear zoom only for the web
|
|
|
|
// browser process, not other apps.
|
|
|
|
return true;
|
|
|
|
#endif
|
|
|
|
|
2013-01-30 16:03:39 +04:00
|
|
|
#ifdef MOZ_WIDGET_GONK
|
2013-01-15 19:19:28 +04:00
|
|
|
// On B2G, we need linear zoom for the browser, but otherwise prefer
|
|
|
|
// the improved glyph spacing that results from respecting the device
|
|
|
|
// pixel resolution for glyph layout (see bug 816614).
|
2015-07-04 04:29:00 +03:00
|
|
|
return XRE_IsContentProcess() &&
|
2013-01-15 19:19:28 +04:00
|
|
|
ContentChild::GetSingleton()->IsForBrowser();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
NS_NOTREACHED("oops, what platform is this?");
|
|
|
|
return gfxPlatform::RequiresLinearZoom();
|
2012-02-09 02:52:57 +04:00
|
|
|
}
|
2012-05-15 23:41:20 +04:00
|
|
|
|
2014-12-18 19:30:06 +03:00
|
|
|
#ifdef MOZ_WIDGET_GONK
|
2015-03-21 19:28:04 +03:00
|
|
|
class GonkVsyncSource final : public VsyncSource
|
2014-12-18 19:30:06 +03:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
GonkVsyncSource()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual Display& GetGlobalDisplay() override
|
2014-12-18 19:30:06 +03:00
|
|
|
{
|
|
|
|
return mGlobalDisplay;
|
|
|
|
}
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class GonkDisplay final : public VsyncSource::Display
|
2014-12-18 19:30:06 +03:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
GonkDisplay() : mVsyncEnabled(false)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
~GonkDisplay()
|
|
|
|
{
|
2016-06-06 20:07:29 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void Shutdown() override
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2014-12-18 19:30:06 +03:00
|
|
|
DisableVsync();
|
|
|
|
}
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual void EnableVsync() override
|
2014-12-18 19:30:06 +03:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2015-01-20 19:31:22 +03:00
|
|
|
if (IsVsyncEnabled()) {
|
|
|
|
return;
|
|
|
|
}
|
2014-12-18 19:30:06 +03:00
|
|
|
mVsyncEnabled = HwcComposer2D::GetInstance()->EnableVsync(true);
|
|
|
|
}
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual void DisableVsync() override
|
2014-12-18 19:30:06 +03:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2015-01-20 19:31:22 +03:00
|
|
|
if (!IsVsyncEnabled()) {
|
|
|
|
return;
|
|
|
|
}
|
2014-12-18 19:30:06 +03:00
|
|
|
mVsyncEnabled = HwcComposer2D::GetInstance()->EnableVsync(false);
|
|
|
|
}
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual bool IsVsyncEnabled() override
|
2014-12-18 19:30:06 +03:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
return mVsyncEnabled;
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
bool mVsyncEnabled;
|
|
|
|
}; // GonkDisplay
|
|
|
|
|
|
|
|
private:
|
|
|
|
virtual ~GonkVsyncSource()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
GonkDisplay mGlobalDisplay;
|
|
|
|
}; // GonkVsyncSource
|
|
|
|
#endif
|
|
|
|
|
|
|
|
already_AddRefed<mozilla::gfx::VsyncSource>
|
|
|
|
gfxAndroidPlatform::CreateHardwareVsyncSource()
|
|
|
|
{
|
2015-05-17 19:12:00 +03:00
|
|
|
// Only enable true hardware vsync on kit-kat and L device. Jelly Bean has
|
|
|
|
// inaccurate hardware vsync so disable on JB. Android pre-JB doesn't have
|
|
|
|
// hardware vsync.
|
|
|
|
// L is android version 21, L-MR1 is 22, kit-kat is 19, 20 is kit-kat for
|
|
|
|
// wearables.
|
|
|
|
#if defined(MOZ_WIDGET_GONK) && (ANDROID_VERSION == 19 || ANDROID_VERSION >= 21)
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<GonkVsyncSource> vsyncSource = new GonkVsyncSource();
|
2015-01-20 19:31:21 +03:00
|
|
|
VsyncSource::Display& display = vsyncSource->GetGlobalDisplay();
|
|
|
|
display.EnableVsync();
|
|
|
|
if (!display.IsVsyncEnabled()) {
|
2015-05-05 23:57:47 +03:00
|
|
|
NS_WARNING("Error enabling gonk vsync. Falling back to software vsync");
|
2015-01-15 18:56:12 +03:00
|
|
|
return gfxPlatform::CreateHardwareVsyncSource();
|
|
|
|
}
|
2015-01-20 19:31:21 +03:00
|
|
|
display.DisableVsync();
|
2014-12-18 19:30:06 +03:00
|
|
|
return vsyncSource.forget();
|
|
|
|
#else
|
2015-03-20 18:12:53 +03:00
|
|
|
return gfxPlatform::CreateHardwareVsyncSource();
|
2014-12-18 19:30:06 +03:00
|
|
|
#endif
|
|
|
|
}
|