2005-11-29 20:29:45 +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/. */
|
2005-11-29 20:29:45 +00:00
|
|
|
|
2006-04-18 15:21:42 +00:00
|
|
|
#define PANGO_ENABLE_BACKEND
|
|
|
|
#define PANGO_ENABLE_ENGINE
|
|
|
|
|
2005-11-29 20:29:45 +00:00
|
|
|
#include "gfxPlatformGtk.h"
|
2013-06-20 21:32:04 +00:00
|
|
|
#include "prenv.h"
|
2005-11-29 20:29:45 +00:00
|
|
|
|
2009-09-09 15:35:08 +00:00
|
|
|
#include "nsUnicharUtils.h"
|
2012-03-09 03:38:01 +00:00
|
|
|
#include "nsUnicodeProperties.h"
|
2014-02-09 08:04:38 +00:00
|
|
|
#include "gfx2DGlue.h"
|
2015-05-13 05:11:25 +00:00
|
|
|
#include "gfxFcPlatformFontList.h"
|
2007-01-30 08:20:29 +00:00
|
|
|
#include "gfxFontconfigUtils.h"
|
2015-05-20 15:44:09 +00:00
|
|
|
#include "gfxFontconfigFonts.h"
|
2016-06-21 19:51:34 +00:00
|
|
|
#include "gfxConfig.h"
|
2008-07-13 21:40:16 +00:00
|
|
|
#include "gfxContext.h"
|
2008-12-05 23:19:27 +00:00
|
|
|
#include "gfxUserFontSet.h"
|
2014-06-23 22:48:59 +00:00
|
|
|
#include "gfxUtils.h"
|
2012-05-16 22:30:10 +00:00
|
|
|
#include "gfxFT2FontBase.h"
|
2015-07-15 15:38:00 +00:00
|
|
|
#include "gfxPrefs.h"
|
2016-05-09 15:35:58 +00:00
|
|
|
#include "VsyncSource.h"
|
|
|
|
#include "mozilla/Atomics.h"
|
|
|
|
#include "mozilla/Monitor.h"
|
|
|
|
#include "base/task.h"
|
|
|
|
#include "base/thread.h"
|
|
|
|
#include "base/message_loop.h"
|
|
|
|
#include "mozilla/gfx/Logging.h"
|
2006-01-10 20:26:40 +00:00
|
|
|
|
2012-01-26 00:54:31 +00:00
|
|
|
#include "mozilla/gfx/2D.h"
|
|
|
|
|
2007-01-27 02:14:19 +00:00
|
|
|
#include "cairo.h"
|
2005-11-29 20:29:45 +00:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
|
|
|
#include "gfxImageSurface.h"
|
2008-08-06 20:48:55 +00:00
|
|
|
#ifdef MOZ_X11
|
|
|
|
#include <gdk/gdkx.h>
|
2005-11-29 20:29:45 +00:00
|
|
|
#include "gfxXlibSurface.h"
|
2008-08-19 03:22:42 +00:00
|
|
|
#include "cairo-xlib.h"
|
2012-04-18 14:27:32 +00:00
|
|
|
#include "mozilla/Preferences.h"
|
2015-05-04 10:35:18 +00:00
|
|
|
#include "mozilla/X11Util.h"
|
2009-04-20 16:36:37 +00:00
|
|
|
|
2016-05-09 15:35:58 +00:00
|
|
|
#ifdef GL_PROVIDER_GLX
|
|
|
|
#include "GLContextProvider.h"
|
|
|
|
#include "GLContextGLX.h"
|
|
|
|
#include "GLXLibrary.h"
|
|
|
|
#endif
|
|
|
|
|
2009-04-20 16:36:37 +00:00
|
|
|
/* Undefine the Status from Xlib since it will conflict with system headers on OSX */
|
|
|
|
#if defined(__APPLE__) && defined(Status)
|
|
|
|
#undef Status
|
|
|
|
#endif
|
|
|
|
|
2008-08-06 20:48:55 +00:00
|
|
|
#endif /* MOZ_X11 */
|
2005-11-29 20:29:45 +00:00
|
|
|
|
2006-01-10 20:26:40 +00:00
|
|
|
#include <fontconfig/fontconfig.h>
|
2006-11-21 06:31:04 +00:00
|
|
|
|
2007-03-02 22:41:06 +00:00
|
|
|
#include "nsMathUtils.h"
|
2006-04-18 15:21:42 +00:00
|
|
|
|
2008-11-09 23:39:41 +00:00
|
|
|
#define GDK_PIXMAP_SIZE_MAX 32767
|
|
|
|
|
2015-11-20 04:35:15 +00:00
|
|
|
#define GFX_PREF_MAX_GENERIC_SUBSTITUTIONS "gfx.font_rendering.fontconfig.max_generic_substitutions"
|
|
|
|
|
2012-01-26 00:54:31 +00:00
|
|
|
using namespace mozilla;
|
|
|
|
using namespace mozilla::gfx;
|
2012-03-09 03:10:05 +00:00
|
|
|
using namespace mozilla::unicode;
|
2012-01-26 00:54:31 +00:00
|
|
|
|
2012-07-30 14:20:58 +00:00
|
|
|
gfxFontconfigUtils *gfxPlatformGtk::sFontconfigUtils = nullptr;
|
2006-01-10 20:26:40 +00:00
|
|
|
|
2014-04-09 00:23:00 +00:00
|
|
|
#if (MOZ_WIDGET_GTK == 2)
|
2008-08-19 03:22:42 +00:00
|
|
|
static cairo_user_data_key_t cairo_gdk_drawable_key;
|
2014-04-09 00:23:00 +00:00
|
|
|
#endif
|
2007-11-27 00:22:39 +00:00
|
|
|
|
2015-05-13 05:11:25 +00:00
|
|
|
bool gfxPlatformGtk::sUseFcFontList = false;
|
|
|
|
|
2005-11-29 20:29:45 +00:00
|
|
|
gfxPlatformGtk::gfxPlatformGtk()
|
|
|
|
{
|
2015-07-29 20:38:28 +00:00
|
|
|
gtk_init(nullptr, nullptr);
|
|
|
|
|
2015-05-13 05:11:25 +00:00
|
|
|
sUseFcFontList = mozilla::Preferences::GetBool("gfx.font_rendering.fontconfig.fontlist.enabled");
|
|
|
|
if (!sUseFcFontList && !sFontconfigUtils) {
|
2007-01-30 08:20:29 +00:00
|
|
|
sFontconfigUtils = gfxFontconfigUtils::GetFontconfigUtils();
|
2015-05-13 05:11:25 +00:00
|
|
|
}
|
|
|
|
|
2015-11-20 04:35:15 +00:00
|
|
|
mMaxGenericSubstitutions = UNINITIALIZED_VALUE;
|
|
|
|
|
2012-04-18 14:27:32 +00:00
|
|
|
#ifdef MOZ_X11
|
2016-08-04 18:33:44 +00:00
|
|
|
if (XRE_IsParentProcess()) {
|
|
|
|
if (GDK_IS_X11_DISPLAY(gdk_display_get_default()) &&
|
|
|
|
mozilla::Preferences::GetBool("gfx.xrender.enabled"))
|
|
|
|
{
|
|
|
|
gfxVars::SetUseXRender(true);
|
|
|
|
}
|
|
|
|
}
|
2012-04-18 14:27:32 +00:00
|
|
|
#endif
|
2007-10-06 07:26:13 +00:00
|
|
|
|
2016-07-26 00:42:09 +00:00
|
|
|
uint32_t canvasMask = BackendTypeBit(BackendType::CAIRO);
|
|
|
|
uint32_t contentMask = BackendTypeBit(BackendType::CAIRO);
|
|
|
|
#ifdef USE_SKIA
|
|
|
|
canvasMask |= BackendTypeBit(BackendType::SKIA);
|
|
|
|
contentMask |= BackendTypeBit(BackendType::SKIA);
|
|
|
|
#endif
|
2014-01-10 19:06:16 +00:00
|
|
|
InitBackendPrefs(canvasMask, BackendType::CAIRO,
|
|
|
|
contentMask, BackendType::CAIRO);
|
2016-07-11 21:36:53 +00:00
|
|
|
|
|
|
|
#ifdef MOZ_X11
|
|
|
|
if (GDK_IS_X11_DISPLAY(gdk_display_get_default())) {
|
|
|
|
mCompositorDisplay = XOpenDisplay(nullptr);
|
|
|
|
MOZ_ASSERT(mCompositorDisplay, "Failed to create compositor display!");
|
|
|
|
} else {
|
|
|
|
mCompositorDisplay = nullptr;
|
|
|
|
}
|
|
|
|
#endif // MOZ_X11
|
2005-11-29 20:29:45 +00:00
|
|
|
}
|
|
|
|
|
2007-03-19 23:16:15 +00:00
|
|
|
gfxPlatformGtk::~gfxPlatformGtk()
|
|
|
|
{
|
2015-05-13 05:11:25 +00:00
|
|
|
if (!sUseFcFontList) {
|
|
|
|
gfxFontconfigUtils::Shutdown();
|
|
|
|
sFontconfigUtils = nullptr;
|
|
|
|
gfxPangoFontGroup::Shutdown();
|
|
|
|
}
|
2016-07-11 21:36:53 +00:00
|
|
|
|
|
|
|
#ifdef MOZ_X11
|
|
|
|
if (mCompositorDisplay) {
|
|
|
|
XCloseDisplay(mCompositorDisplay);
|
|
|
|
}
|
|
|
|
#endif // MOZ_X11
|
2007-03-19 23:16:15 +00:00
|
|
|
}
|
|
|
|
|
2015-05-04 10:35:18 +00:00
|
|
|
void
|
|
|
|
gfxPlatformGtk::FlushContentDrawing()
|
|
|
|
{
|
2016-08-04 18:33:44 +00:00
|
|
|
if (gfxVars::UseXRender()) {
|
2015-05-04 10:35:18 +00:00
|
|
|
XFlush(DefaultXDisplay());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-03-25 00:34:48 +00:00
|
|
|
already_AddRefed<gfxASurface>
|
2015-07-07 01:21:47 +00:00
|
|
|
gfxPlatformGtk::CreateOffscreenSurface(const IntSize& aSize,
|
|
|
|
gfxImageFormat aFormat)
|
2005-11-29 20:29:45 +00:00
|
|
|
{
|
2016-09-15 14:36:21 +00:00
|
|
|
if (!Factory::AllowedSurfaceSize(aSize)) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<gfxASurface> newSurface;
|
2011-09-29 06:19:26 +00:00
|
|
|
bool needsClear = true;
|
2008-08-06 20:48:55 +00:00
|
|
|
#ifdef MOZ_X11
|
2006-02-23 00:45:55 +00:00
|
|
|
// XXX we really need a different interface here, something that passes
|
|
|
|
// in more context, including the display and/or target surface type that
|
|
|
|
// we should try to match
|
2010-07-02 03:55:24 +00:00
|
|
|
GdkScreen *gdkScreen = gdk_screen_get_default();
|
|
|
|
if (gdkScreen) {
|
2014-09-26 17:07:06 +00:00
|
|
|
// When forcing PaintedLayers to use image surfaces for content,
|
2014-07-22 23:04:47 +00:00
|
|
|
// force creation of gfxImageSurface surfaces.
|
2016-08-04 18:33:44 +00:00
|
|
|
if (gfxVars::UseXRender() && !UseImageOffscreenSurfaces()) {
|
2010-09-24 01:00:06 +00:00
|
|
|
Screen *screen = gdk_x11_screen_get_xscreen(gdkScreen);
|
|
|
|
XRenderPictFormat* xrenderFormat =
|
|
|
|
gfxXlibSurface::FindRenderFormat(DisplayOfScreen(screen),
|
2015-07-07 01:21:47 +00:00
|
|
|
aFormat);
|
2010-09-24 01:00:06 +00:00
|
|
|
|
|
|
|
if (xrenderFormat) {
|
2014-02-09 08:04:38 +00:00
|
|
|
newSurface = gfxXlibSurface::Create(screen, xrenderFormat,
|
2015-07-07 01:21:47 +00:00
|
|
|
aSize);
|
2010-09-24 01:00:06 +00:00
|
|
|
}
|
2012-09-17 03:23:00 +00:00
|
|
|
} else {
|
|
|
|
// We're not going to use XRender, so we don't need to
|
|
|
|
// search for a render format
|
2015-07-07 01:21:47 +00:00
|
|
|
newSurface = new gfxImageSurface(aSize, aFormat);
|
2012-09-17 03:23:00 +00:00
|
|
|
// The gfxImageSurface ctor zeroes this for us, no need to
|
|
|
|
// waste time clearing again
|
|
|
|
needsClear = false;
|
2006-03-22 01:15:23 +00:00
|
|
|
}
|
2008-09-30 17:53:38 +00:00
|
|
|
}
|
2008-08-06 20:48:55 +00:00
|
|
|
#endif
|
2005-11-29 20:29:45 +00:00
|
|
|
|
2008-11-09 23:39:41 +00:00
|
|
|
if (!newSurface) {
|
|
|
|
// We couldn't create a native surface for whatever reason;
|
2010-07-02 03:55:24 +00:00
|
|
|
// e.g., no display, no RENDER, bad size, etc.
|
2008-11-09 23:39:41 +00:00
|
|
|
// Fall back to image surface for the data.
|
2015-07-07 01:21:47 +00:00
|
|
|
newSurface = new gfxImageSurface(aSize, aFormat);
|
2008-11-09 23:39:41 +00:00
|
|
|
}
|
|
|
|
|
2010-11-19 16:56:05 +00:00
|
|
|
if (newSurface->CairoStatus()) {
|
2012-07-30 14:20:58 +00:00
|
|
|
newSurface = nullptr; // surface isn't valid for some reason
|
2010-11-19 16:56:05 +00:00
|
|
|
}
|
|
|
|
|
2010-09-24 01:00:06 +00:00
|
|
|
if (newSurface && needsClear) {
|
2014-06-23 22:48:59 +00:00
|
|
|
gfxUtils::ClearThebesSurface(newSurface);
|
2008-07-13 21:40:16 +00:00
|
|
|
}
|
|
|
|
|
2007-11-27 01:40:03 +00:00
|
|
|
return newSurface.forget();
|
2005-11-29 20:29:45 +00:00
|
|
|
}
|
|
|
|
|
2006-01-10 20:26:40 +00:00
|
|
|
nsresult
|
2010-02-24 17:57:57 +00:00
|
|
|
gfxPlatformGtk::GetFontList(nsIAtom *aLangGroup,
|
2006-01-10 20:26:40 +00:00
|
|
|
const nsACString& aGenericFamily,
|
2009-01-18 20:14:14 +00:00
|
|
|
nsTArray<nsString>& aListOfFonts)
|
2006-01-10 20:26:40 +00:00
|
|
|
{
|
2015-05-13 05:11:25 +00:00
|
|
|
if (sUseFcFontList) {
|
|
|
|
gfxPlatformFontList::PlatformFontList()->GetFontList(aLangGroup,
|
|
|
|
aGenericFamily,
|
|
|
|
aListOfFonts);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return sFontconfigUtils->GetFontList(aLangGroup,
|
|
|
|
aGenericFamily,
|
2007-01-30 08:20:29 +00:00
|
|
|
aListOfFonts);
|
2006-11-21 06:31:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
gfxPlatformGtk::UpdateFontList()
|
|
|
|
{
|
2015-05-13 05:11:25 +00:00
|
|
|
if (sUseFcFontList) {
|
|
|
|
gfxPlatformFontList::PlatformFontList()->UpdateFontList();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-01-30 08:20:29 +00:00
|
|
|
return sFontconfigUtils->UpdateFontList();
|
2006-11-21 06:31:04 +00:00
|
|
|
}
|
|
|
|
|
2015-05-13 05:11:25 +00:00
|
|
|
// xxx - this is ubuntu centric, need to go through other distros and flesh
|
|
|
|
// out a more general list
|
|
|
|
static const char kFontDejaVuSans[] = "DejaVu Sans";
|
|
|
|
static const char kFontDejaVuSerif[] = "DejaVu Serif";
|
Bug 1231701 - Ship our own variant of EmojiOne on Windows and Linux, r=glandium, r=dolske, r=jfkthame, r=gerv
This patch bundles a color font named "EmojiOne Mozilla", and turn on
the necessary code for including the bundled font, on Linux and Windows.
With that, users of Linux and Windows <=8.0 is able to see color Emoji
on Firefox without support from System.
The font bundled is the v0.2.1 version, generated from the project repo
in
https://github.com/mozilla/emojione-colr
with artwork from the original EmojiOne font and Twemoji,
under CC BY 4.0 license.
Test files, about:license page, and the packager instruction are
modified accordingly.
MozReview-Commit-ID: 2mmxnA0vS3u
2016-06-15 20:58:49 +00:00
|
|
|
static const char kFontEmojiOneMozilla[] = "EmojiOne Mozilla";
|
2015-05-13 05:11:25 +00:00
|
|
|
static const char kFontFreeSans[] = "FreeSans";
|
|
|
|
static const char kFontFreeSerif[] = "FreeSerif";
|
|
|
|
static const char kFontTakaoPGothic[] = "TakaoPGothic";
|
|
|
|
static const char kFontDroidSansFallback[] = "Droid Sans Fallback";
|
|
|
|
static const char kFontWenQuanYiMicroHei[] = "WenQuanYi Micro Hei";
|
|
|
|
static const char kFontNanumGothic[] = "NanumGothic";
|
|
|
|
|
|
|
|
void
|
|
|
|
gfxPlatformGtk::GetCommonFallbackFonts(uint32_t aCh, uint32_t aNextCh,
|
2016-04-21 17:58:59 +00:00
|
|
|
Script aRunScript,
|
2015-05-13 05:11:25 +00:00
|
|
|
nsTArray<const char*>& aFontList)
|
|
|
|
{
|
Bug 1231701 - Ship our own variant of EmojiOne on Windows and Linux, r=glandium, r=dolske, r=jfkthame, r=gerv
This patch bundles a color font named "EmojiOne Mozilla", and turn on
the necessary code for including the bundled font, on Linux and Windows.
With that, users of Linux and Windows <=8.0 is able to see color Emoji
on Firefox without support from System.
The font bundled is the v0.2.1 version, generated from the project repo
in
https://github.com/mozilla/emojione-colr
with artwork from the original EmojiOne font and Twemoji,
under CC BY 4.0 license.
Test files, about:license page, and the packager instruction are
modified accordingly.
MozReview-Commit-ID: 2mmxnA0vS3u
2016-06-15 20:58:49 +00:00
|
|
|
if (aNextCh == 0xfe0fu) {
|
|
|
|
// if char is followed by VS16, try for a color emoji glyph
|
|
|
|
aFontList.AppendElement(kFontEmojiOneMozilla);
|
|
|
|
}
|
|
|
|
|
2015-05-13 05:11:25 +00:00
|
|
|
aFontList.AppendElement(kFontDejaVuSerif);
|
|
|
|
aFontList.AppendElement(kFontFreeSerif);
|
|
|
|
aFontList.AppendElement(kFontDejaVuSans);
|
|
|
|
aFontList.AppendElement(kFontFreeSans);
|
|
|
|
|
Bug 1231701 - Ship our own variant of EmojiOne on Windows and Linux, r=glandium, r=dolske, r=jfkthame, r=gerv
This patch bundles a color font named "EmojiOne Mozilla", and turn on
the necessary code for including the bundled font, on Linux and Windows.
With that, users of Linux and Windows <=8.0 is able to see color Emoji
on Firefox without support from System.
The font bundled is the v0.2.1 version, generated from the project repo
in
https://github.com/mozilla/emojione-colr
with artwork from the original EmojiOne font and Twemoji,
under CC BY 4.0 license.
Test files, about:license page, and the packager instruction are
modified accordingly.
MozReview-Commit-ID: 2mmxnA0vS3u
2016-06-15 20:58:49 +00: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) {
|
|
|
|
aFontList.AppendElement(kFontEmojiOneMozilla);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-13 05:11:25 +00:00
|
|
|
// add fonts for CJK ranges
|
|
|
|
// xxx - this isn't really correct, should use the same CJK font ordering
|
|
|
|
// as the pref font code
|
|
|
|
if (aCh >= 0x3000 &&
|
|
|
|
((aCh < 0xe000) ||
|
|
|
|
(aCh >= 0xf900 && aCh < 0xfff0) ||
|
|
|
|
((aCh >> 16) == 2))) {
|
|
|
|
aFontList.AppendElement(kFontTakaoPGothic);
|
|
|
|
aFontList.AppendElement(kFontDroidSansFallback);
|
|
|
|
aFontList.AppendElement(kFontWenQuanYiMicroHei);
|
|
|
|
aFontList.AppendElement(kFontNanumGothic);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gfxPlatformFontList*
|
|
|
|
gfxPlatformGtk::CreatePlatformFontList()
|
|
|
|
{
|
|
|
|
gfxPlatformFontList* list = new gfxFcPlatformFontList();
|
|
|
|
if (NS_SUCCEEDED(list->InitFontList())) {
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
gfxPlatformFontList::Shutdown();
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2008-03-13 10:32:50 +00:00
|
|
|
nsresult
|
|
|
|
gfxPlatformGtk::GetStandardFamilyName(const nsAString& aFontName, nsAString& aFamilyName)
|
|
|
|
{
|
2015-05-13 05:11:25 +00:00
|
|
|
if (sUseFcFontList) {
|
|
|
|
gfxPlatformFontList::PlatformFontList()->
|
|
|
|
GetStandardFamilyName(aFontName, aFamilyName);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2008-03-13 10:32:50 +00:00
|
|
|
return sFontconfigUtils->GetStandardFamilyName(aFontName, aFamilyName);
|
|
|
|
}
|
|
|
|
|
2007-04-02 19:06:16 +00:00
|
|
|
gfxFontGroup *
|
2014-06-06 06:09:23 +00:00
|
|
|
gfxPlatformGtk::CreateFontGroup(const FontFamilyList& aFontFamilyList,
|
2015-09-11 04:24:33 +00:00
|
|
|
const gfxFontStyle* aStyle,
|
|
|
|
gfxTextPerfMetrics* aTextPerf,
|
2015-11-20 13:01:12 +00:00
|
|
|
gfxUserFontSet* aUserFontSet,
|
|
|
|
gfxFloat aDevToCssSize)
|
2007-04-02 19:06:16 +00:00
|
|
|
{
|
2015-05-13 05:11:25 +00:00
|
|
|
if (sUseFcFontList) {
|
2015-11-20 13:01:12 +00:00
|
|
|
return new gfxFontGroup(aFontFamilyList, aStyle, aTextPerf,
|
|
|
|
aUserFontSet, aDevToCssSize);
|
2015-05-13 05:11:25 +00:00
|
|
|
}
|
|
|
|
|
2015-11-20 13:01:12 +00:00
|
|
|
return new gfxPangoFontGroup(aFontFamilyList, aStyle,
|
|
|
|
aUserFontSet, aDevToCssSize);
|
2007-04-02 19:06:16 +00:00
|
|
|
}
|
|
|
|
|
2009-01-03 03:21:49 +00:00
|
|
|
gfxFontEntry*
|
2014-09-08 07:23:19 +00:00
|
|
|
gfxPlatformGtk::LookupLocalFont(const nsAString& aFontName,
|
|
|
|
uint16_t aWeight,
|
|
|
|
int16_t aStretch,
|
2015-10-19 02:16:43 +00:00
|
|
|
uint8_t aStyle)
|
2009-01-03 03:21:49 +00:00
|
|
|
{
|
2015-05-13 05:11:25 +00:00
|
|
|
if (sUseFcFontList) {
|
|
|
|
gfxPlatformFontList* pfl = gfxPlatformFontList::PlatformFontList();
|
2015-10-19 02:16:43 +00:00
|
|
|
return pfl->LookupLocalFont(aFontName, aWeight, aStretch,
|
|
|
|
aStyle);
|
2015-05-13 05:11:25 +00:00
|
|
|
}
|
|
|
|
|
2014-09-08 07:23:19 +00:00
|
|
|
return gfxPangoFontGroup::NewFontEntry(aFontName, aWeight,
|
2015-10-19 02:16:43 +00:00
|
|
|
aStretch, aStyle);
|
2009-01-03 03:21:49 +00:00
|
|
|
}
|
|
|
|
|
Bug 1231701 - Ship our own variant of EmojiOne on Windows and Linux, r=glandium, r=dolske, r=jfkthame, r=gerv
This patch bundles a color font named "EmojiOne Mozilla", and turn on
the necessary code for including the bundled font, on Linux and Windows.
With that, users of Linux and Windows <=8.0 is able to see color Emoji
on Firefox without support from System.
The font bundled is the v0.2.1 version, generated from the project repo
in
https://github.com/mozilla/emojione-colr
with artwork from the original EmojiOne font and Twemoji,
under CC BY 4.0 license.
Test files, about:license page, and the packager instruction are
modified accordingly.
MozReview-Commit-ID: 2mmxnA0vS3u
2016-06-15 20:58:49 +00:00
|
|
|
gfxFontEntry*
|
2014-09-08 07:23:19 +00:00
|
|
|
gfxPlatformGtk::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-12-05 23:19:27 +00:00
|
|
|
{
|
2015-05-13 05:11:25 +00:00
|
|
|
if (sUseFcFontList) {
|
|
|
|
gfxPlatformFontList* pfl = gfxPlatformFontList::PlatformFontList();
|
2015-10-19 02:16:43 +00:00
|
|
|
return pfl->MakePlatformFont(aFontName, aWeight, aStretch,
|
|
|
|
aStyle, aFontData, aLength);
|
2015-05-13 05:11:25 +00:00
|
|
|
}
|
|
|
|
|
2009-08-30 13:55:24 +00:00
|
|
|
// passing ownership of the font data to the new font entry
|
2014-09-08 07:23:19 +00:00
|
|
|
return gfxPangoFontGroup::NewFontEntry(aFontName, aWeight,
|
2015-10-19 02:16:43 +00:00
|
|
|
aStretch, aStyle,
|
2008-12-05 23:19:27 +00:00
|
|
|
aFontData, aLength);
|
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2012-08-22 15:56:38 +00:00
|
|
|
gfxPlatformGtk::IsFontFormatSupported(nsIURI *aFontURI, uint32_t aFormatFlags)
|
2008-12-05 23:19:27 +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");
|
2008-12-05 23:19:27 +00:00
|
|
|
|
2009-01-13 05:16:58 +00:00
|
|
|
// accept supported formats
|
2008-12-05 23:19:27 +00:00
|
|
|
// Pango doesn't apply features from AAT TrueType extensions.
|
|
|
|
// Assume that if this is the only SFNT format specified,
|
|
|
|
// then AAT extensions are required for complex script support.
|
2014-10-04 10:36:05 +00:00
|
|
|
if (aFormatFlags & gfxUserFontSet::FLAG_FORMATS_COMMON) {
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
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;
|
2008-12-05 23:19:27 +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;
|
2008-12-05 23:19:27 +00:00
|
|
|
}
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
static int32_t sDPI = 0;
|
2010-08-13 09:58:01 +00:00
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t
|
2010-08-13 09:58:01 +00:00
|
|
|
gfxPlatformGtk::GetDPI()
|
2006-04-18 15:21:42 +00:00
|
|
|
{
|
2010-08-13 09:58:01 +00:00
|
|
|
if (!sDPI) {
|
|
|
|
// Make sure init is run so we have a resolution
|
|
|
|
GdkScreen *screen = gdk_screen_get_default();
|
|
|
|
gtk_settings_get_for_screen(screen);
|
2012-08-22 15:56:38 +00:00
|
|
|
sDPI = int32_t(round(gdk_screen_get_resolution(screen)));
|
2010-08-13 09:58:01 +00:00
|
|
|
if (sDPI <= 0) {
|
|
|
|
// Fall back to something sane
|
|
|
|
sDPI = 96;
|
|
|
|
}
|
2006-04-18 15:21:42 +00:00
|
|
|
}
|
2010-08-13 09:58:01 +00:00
|
|
|
return sDPI;
|
2006-04-18 15:21:42 +00:00
|
|
|
}
|
2007-07-23 22:02:17 +00:00
|
|
|
|
2015-02-10 07:14:00 +00:00
|
|
|
double
|
|
|
|
gfxPlatformGtk::GetDPIScale()
|
|
|
|
{
|
2016-05-10 21:21:13 +00:00
|
|
|
// Integer scale factors work well with GTK window scaling, image scaling,
|
|
|
|
// and pixel alignment, but there is a range where 1 is too small and 2 is
|
|
|
|
// too big. An additional step of 1.5 is added because this is common
|
|
|
|
// scale on WINNT and at this ratio the advantages of larger rendering
|
|
|
|
// outweigh the disadvantages from scaling and pixel mis-alignment.
|
2015-02-10 07:14:00 +00:00
|
|
|
int32_t dpi = GetDPI();
|
2016-05-10 21:21:13 +00:00
|
|
|
if (dpi < 144) {
|
|
|
|
return 1.0;
|
|
|
|
} else if (dpi < 168) {
|
|
|
|
return 1.5;
|
|
|
|
} else {
|
|
|
|
return round(dpi/96.0);
|
|
|
|
}
|
2015-02-10 07:14:00 +00:00
|
|
|
}
|
|
|
|
|
2015-07-15 15:38:00 +00:00
|
|
|
bool
|
|
|
|
gfxPlatformGtk::UseImageOffscreenSurfaces()
|
|
|
|
{
|
2016-03-01 19:33:53 +00:00
|
|
|
return GetDefaultContentBackend() != mozilla::gfx::BackendType::CAIRO ||
|
|
|
|
gfxPrefs::UseImageOffscreenSurfaces();
|
2015-07-15 15:38:00 +00:00
|
|
|
}
|
|
|
|
|
2010-12-15 18:17:26 +00:00
|
|
|
gfxImageFormat
|
|
|
|
gfxPlatformGtk::GetOffscreenFormat()
|
|
|
|
{
|
2012-05-26 04:38:17 +00:00
|
|
|
// Make sure there is a screen
|
|
|
|
GdkScreen *screen = gdk_screen_get_default();
|
2012-06-28 00:15:32 +00:00
|
|
|
if (screen && gdk_visual_get_depth(gdk_visual_get_system()) == 16) {
|
2016-01-08 04:57:38 +00:00
|
|
|
return SurfaceFormat::R5G6B5_UINT16;
|
2010-12-15 18:17:26 +00:00
|
|
|
}
|
|
|
|
|
2016-01-08 04:57:38 +00:00
|
|
|
return SurfaceFormat::X8R8G8B8_UINT32;
|
2010-12-15 18:17:26 +00:00
|
|
|
}
|
|
|
|
|
2015-11-20 04:35:15 +00:00
|
|
|
void gfxPlatformGtk::FontsPrefsChanged(const char *aPref)
|
|
|
|
{
|
|
|
|
// only checking for generic substitions, pass other changes up
|
|
|
|
if (strcmp(GFX_PREF_MAX_GENERIC_SUBSTITUTIONS, aPref)) {
|
|
|
|
gfxPlatform::FontsPrefsChanged(aPref);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mMaxGenericSubstitutions = UNINITIALIZED_VALUE;
|
|
|
|
if (sUseFcFontList) {
|
|
|
|
gfxFcPlatformFontList* pfl = gfxFcPlatformFontList::PlatformFontList();
|
|
|
|
pfl->ClearGenericMappings();
|
|
|
|
FlushFontAndWordCaches();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t gfxPlatformGtk::MaxGenericSubstitions()
|
|
|
|
{
|
|
|
|
if (mMaxGenericSubstitutions == UNINITIALIZED_VALUE) {
|
|
|
|
mMaxGenericSubstitutions =
|
|
|
|
Preferences::GetInt(GFX_PREF_MAX_GENERIC_SUBSTITUTIONS, 3);
|
|
|
|
if (mMaxGenericSubstitutions < 0) {
|
|
|
|
mMaxGenericSubstitutions = 3;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return uint32_t(mMaxGenericSubstitutions);
|
|
|
|
}
|
|
|
|
|
2013-11-07 10:20:08 +00:00
|
|
|
void
|
|
|
|
gfxPlatformGtk::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;
|
|
|
|
|
2008-08-06 20:48:55 +00:00
|
|
|
#ifdef MOZ_X11
|
2015-03-05 02:56:00 +00:00
|
|
|
GdkDisplay *display = gdk_display_get_default();
|
|
|
|
if (!GDK_IS_X11_DISPLAY(display))
|
|
|
|
return;
|
|
|
|
|
2007-07-23 22:02:17 +00:00
|
|
|
const char EDID1_ATOM_NAME[] = "XFree86_DDC_EDID1_RAWDATA";
|
|
|
|
const char ICC_PROFILE_ATOM_NAME[] = "_ICC_PROFILE";
|
|
|
|
|
|
|
|
Atom edidAtom, iccAtom;
|
2015-03-05 02:56:00 +00:00
|
|
|
Display *dpy = GDK_DISPLAY_XDISPLAY(display);
|
2013-03-22 03:12:30 +00:00
|
|
|
// In xpcshell tests, we never initialize X and hence don't have a Display.
|
|
|
|
// In this case, there's no output colour management to be done, so we just
|
2013-11-07 10:20:08 +00:00
|
|
|
// return with nullptr.
|
|
|
|
if (!dpy)
|
|
|
|
return;
|
Bug 1231701 - Ship our own variant of EmojiOne on Windows and Linux, r=glandium, r=dolske, r=jfkthame, r=gerv
This patch bundles a color font named "EmojiOne Mozilla", and turn on
the necessary code for including the bundled font, on Linux and Windows.
With that, users of Linux and Windows <=8.0 is able to see color Emoji
on Firefox without support from System.
The font bundled is the v0.2.1 version, generated from the project repo
in
https://github.com/mozilla/emojione-colr
with artwork from the original EmojiOne font and Twemoji,
under CC BY 4.0 license.
Test files, about:license page, and the packager instruction are
modified accordingly.
MozReview-Commit-ID: 2mmxnA0vS3u
2016-06-15 20:58:49 +00:00
|
|
|
|
2007-07-23 22:02:17 +00:00
|
|
|
Window root = gdk_x11_get_default_root_xwindow();
|
|
|
|
|
|
|
|
Atom retAtom;
|
|
|
|
int retFormat;
|
|
|
|
unsigned long retLength, retAfter;
|
|
|
|
unsigned char *retProperty ;
|
|
|
|
|
|
|
|
iccAtom = XInternAtom(dpy, ICC_PROFILE_ATOM_NAME, TRUE);
|
|
|
|
if (iccAtom) {
|
|
|
|
// read once to get size, once for the data
|
|
|
|
if (Success == XGetWindowProperty(dpy, root, iccAtom,
|
2012-07-19 01:09:13 +00:00
|
|
|
0, INT_MAX /* length */,
|
2007-07-23 22:02:17 +00:00
|
|
|
False, AnyPropertyType,
|
|
|
|
&retAtom, &retFormat, &retLength,
|
|
|
|
&retAfter, &retProperty)) {
|
2009-01-07 19:50:14 +00:00
|
|
|
|
2013-11-07 10:20:08 +00:00
|
|
|
if (retLength > 0) {
|
|
|
|
void *buffer = malloc(retLength);
|
|
|
|
if (buffer) {
|
|
|
|
memcpy(buffer, retProperty, retLength);
|
|
|
|
mem = buffer;
|
|
|
|
size = retLength;
|
|
|
|
}
|
|
|
|
}
|
2007-07-23 22:02:17 +00:00
|
|
|
|
|
|
|
XFree(retProperty);
|
2013-11-07 10:20:08 +00:00
|
|
|
if (size > 0) {
|
2007-07-23 22:02:17 +00:00
|
|
|
#ifdef DEBUG_tor
|
|
|
|
fprintf(stderr,
|
|
|
|
"ICM profile read from %s successfully\n",
|
|
|
|
ICC_PROFILE_ATOM_NAME);
|
|
|
|
#endif
|
2013-11-07 10:20:08 +00:00
|
|
|
return;
|
2007-07-23 22:02:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
edidAtom = XInternAtom(dpy, EDID1_ATOM_NAME, TRUE);
|
|
|
|
if (edidAtom) {
|
|
|
|
if (Success == XGetWindowProperty(dpy, root, edidAtom, 0, 32,
|
|
|
|
False, AnyPropertyType,
|
|
|
|
&retAtom, &retFormat, &retLength,
|
|
|
|
&retAfter, &retProperty)) {
|
|
|
|
double gamma;
|
2009-04-07 16:02:11 +00:00
|
|
|
qcms_CIE_xyY whitePoint;
|
|
|
|
qcms_CIE_xyYTRIPLE primaries;
|
2007-07-23 22:02:17 +00:00
|
|
|
|
|
|
|
if (retLength != 128) {
|
|
|
|
#ifdef DEBUG_tor
|
|
|
|
fprintf(stderr, "Short EDID data\n");
|
|
|
|
#endif
|
2013-11-07 10:20:08 +00:00
|
|
|
return;
|
2007-07-23 22:02:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Format documented in "VESA E-EDID Implementation Guide"
|
|
|
|
|
|
|
|
gamma = (100 + retProperty[0x17]) / 100.0;
|
|
|
|
whitePoint.x = ((retProperty[0x21] << 2) |
|
|
|
|
(retProperty[0x1a] >> 2 & 3)) / 1024.0;
|
|
|
|
whitePoint.y = ((retProperty[0x22] << 2) |
|
|
|
|
(retProperty[0x1a] >> 0 & 3)) / 1024.0;
|
|
|
|
whitePoint.Y = 1.0;
|
|
|
|
|
2009-04-07 16:02:11 +00:00
|
|
|
primaries.red.x = ((retProperty[0x1b] << 2) |
|
2007-07-23 22:02:17 +00:00
|
|
|
(retProperty[0x19] >> 6 & 3)) / 1024.0;
|
2009-04-07 16:02:11 +00:00
|
|
|
primaries.red.y = ((retProperty[0x1c] << 2) |
|
2007-07-23 22:02:17 +00:00
|
|
|
(retProperty[0x19] >> 4 & 3)) / 1024.0;
|
2009-04-07 16:02:11 +00:00
|
|
|
primaries.red.Y = 1.0;
|
2007-07-23 22:02:17 +00:00
|
|
|
|
2009-04-07 16:02:11 +00:00
|
|
|
primaries.green.x = ((retProperty[0x1d] << 2) |
|
2007-07-23 22:02:17 +00:00
|
|
|
(retProperty[0x19] >> 2 & 3)) / 1024.0;
|
2009-04-07 16:02:11 +00:00
|
|
|
primaries.green.y = ((retProperty[0x1e] << 2) |
|
2007-07-23 22:02:17 +00:00
|
|
|
(retProperty[0x19] >> 0 & 3)) / 1024.0;
|
2009-04-07 16:02:11 +00:00
|
|
|
primaries.green.Y = 1.0;
|
2007-07-23 22:02:17 +00:00
|
|
|
|
2009-04-07 16:02:11 +00:00
|
|
|
primaries.blue.x = ((retProperty[0x1f] << 2) |
|
2007-07-23 22:02:17 +00:00
|
|
|
(retProperty[0x1a] >> 6 & 3)) / 1024.0;
|
2009-04-07 16:02:11 +00:00
|
|
|
primaries.blue.y = ((retProperty[0x20] << 2) |
|
2007-07-23 22:02:17 +00:00
|
|
|
(retProperty[0x1a] >> 4 & 3)) / 1024.0;
|
2009-04-07 16:02:11 +00:00
|
|
|
primaries.blue.Y = 1.0;
|
2007-07-23 22:02:17 +00:00
|
|
|
|
|
|
|
XFree(retProperty);
|
|
|
|
|
|
|
|
#ifdef DEBUG_tor
|
|
|
|
fprintf(stderr, "EDID gamma: %f\n", gamma);
|
|
|
|
fprintf(stderr, "EDID whitepoint: %f %f %f\n",
|
|
|
|
whitePoint.x, whitePoint.y, whitePoint.Y);
|
|
|
|
fprintf(stderr, "EDID primaries: [%f %f %f] [%f %f %f] [%f %f %f]\n",
|
|
|
|
primaries.Red.x, primaries.Red.y, primaries.Red.Y,
|
|
|
|
primaries.Green.x, primaries.Green.y, primaries.Green.Y,
|
|
|
|
primaries.Blue.x, primaries.Blue.y, primaries.Blue.Y);
|
|
|
|
#endif
|
|
|
|
|
2013-11-07 10:20:08 +00:00
|
|
|
qcms_data_create_rgb_with_gamma(whitePoint, primaries, gamma, &mem, &size);
|
2007-07-23 22:02:17 +00:00
|
|
|
|
|
|
|
#ifdef DEBUG_tor
|
2013-11-07 10:20:08 +00:00
|
|
|
if (size > 0) {
|
2007-07-23 22:02:17 +00:00
|
|
|
fprintf(stderr,
|
|
|
|
"ICM profile read from %s successfully\n",
|
|
|
|
EDID1_ATOM_NAME);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
2008-08-06 20:48:55 +00:00
|
|
|
#endif
|
2007-07-23 22:02:17 +00:00
|
|
|
}
|
2008-08-06 20:48:55 +00:00
|
|
|
|
|
|
|
|
2012-06-28 00:15:32 +00:00
|
|
|
#if (MOZ_WIDGET_GTK == 2)
|
2008-08-06 20:48:55 +00:00
|
|
|
void
|
2013-10-25 21:25:40 +00:00
|
|
|
gfxPlatformGtk::SetGdkDrawable(cairo_surface_t *target,
|
2008-08-06 20:48:55 +00:00
|
|
|
GdkDrawable *drawable)
|
|
|
|
{
|
2013-10-25 21:25:40 +00:00
|
|
|
if (cairo_surface_status(target))
|
2008-08-06 20:48:55 +00:00
|
|
|
return;
|
|
|
|
|
2009-02-02 17:49:58 +00:00
|
|
|
g_object_ref(drawable);
|
2008-08-19 03:22:42 +00:00
|
|
|
|
2013-10-25 21:25:40 +00:00
|
|
|
cairo_surface_set_user_data (target,
|
2008-08-06 20:48:55 +00:00
|
|
|
&cairo_gdk_drawable_key,
|
|
|
|
drawable,
|
2012-06-28 00:15:32 +00:00
|
|
|
g_object_unref);
|
2008-08-06 20:48:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GdkDrawable *
|
2013-10-25 21:25:40 +00:00
|
|
|
gfxPlatformGtk::GetGdkDrawable(cairo_surface_t *target)
|
2008-08-06 20:48:55 +00:00
|
|
|
{
|
2013-10-25 21:25:40 +00:00
|
|
|
if (cairo_surface_status(target))
|
2013-07-31 15:44:31 +00:00
|
|
|
return nullptr;
|
2008-08-06 20:48:55 +00:00
|
|
|
|
2008-08-19 03:22:42 +00:00
|
|
|
GdkDrawable *result;
|
|
|
|
|
2013-10-25 21:25:40 +00:00
|
|
|
result = (GdkDrawable*) cairo_surface_get_user_data (target,
|
2008-08-19 03:22:42 +00:00
|
|
|
&cairo_gdk_drawable_key);
|
|
|
|
if (result)
|
|
|
|
return result;
|
|
|
|
|
|
|
|
#ifdef MOZ_X11
|
2013-10-25 21:25:40 +00:00
|
|
|
if (cairo_surface_get_type(target) != CAIRO_SURFACE_TYPE_XLIB)
|
2013-07-31 15:44:31 +00:00
|
|
|
return nullptr;
|
2010-06-22 23:11:42 +00:00
|
|
|
|
|
|
|
// try looking it up in gdk's table
|
2013-10-25 21:25:40 +00:00
|
|
|
result = (GdkDrawable*) gdk_xid_table_lookup(cairo_xlib_surface_get_drawable(target));
|
2010-06-22 23:11:42 +00:00
|
|
|
if (result) {
|
|
|
|
SetGdkDrawable(target, result);
|
|
|
|
return result;
|
|
|
|
}
|
2010-07-02 04:04:09 +00:00
|
|
|
#endif
|
2008-08-19 03:22:42 +00:00
|
|
|
|
2013-07-31 15:44:31 +00:00
|
|
|
return nullptr;
|
2008-08-06 20:48:55 +00:00
|
|
|
}
|
2012-06-28 00:15:32 +00:00
|
|
|
#endif
|
2012-01-26 00:54:31 +00:00
|
|
|
|
2015-06-17 14:00:52 +00:00
|
|
|
already_AddRefed<ScaledFont>
|
2012-07-24 10:18:37 +00:00
|
|
|
gfxPlatformGtk::GetScaledFontForFont(DrawTarget* aTarget, gfxFont *aFont)
|
2012-01-26 00:54:31 +00:00
|
|
|
{
|
2016-07-20 19:07:11 +00:00
|
|
|
switch (aTarget->GetBackendType()) {
|
|
|
|
case BackendType::CAIRO:
|
|
|
|
case BackendType::SKIA:
|
|
|
|
if (aFont->GetType() == gfxFont::FONT_TYPE_FONTCONFIG) {
|
|
|
|
gfxFontconfigFontBase* fcFont = static_cast<gfxFontconfigFontBase*>(aFont);
|
|
|
|
return Factory::CreateScaledFontForFontconfigFont(
|
|
|
|
fcFont->GetCairoScaledFont(),
|
|
|
|
fcFont->GetPattern(),
|
|
|
|
fcFont->GetAdjustedSize());
|
|
|
|
}
|
|
|
|
MOZ_FALLTHROUGH;
|
|
|
|
default:
|
|
|
|
return GetScaledFontForFontWithCairoSkia(aTarget, aFont);
|
|
|
|
}
|
2012-07-26 06:48:24 +00:00
|
|
|
}
|
2016-05-09 15:35:58 +00:00
|
|
|
|
|
|
|
#ifdef GL_PROVIDER_GLX
|
|
|
|
|
|
|
|
class GLXVsyncSource final : public VsyncSource
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
GLXVsyncSource()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
mGlobalDisplay = new GLXDisplay();
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~GLXVsyncSource()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual Display& GetGlobalDisplay() override
|
|
|
|
{
|
|
|
|
return *mGlobalDisplay;
|
|
|
|
}
|
|
|
|
|
|
|
|
class GLXDisplay final : public VsyncSource::Display
|
|
|
|
{
|
|
|
|
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(GLXDisplay)
|
|
|
|
|
|
|
|
public:
|
|
|
|
GLXDisplay() : mGLContext(nullptr)
|
2016-08-22 18:44:54 +00:00
|
|
|
, mXDisplay(nullptr)
|
2016-05-09 15:35:58 +00:00
|
|
|
, mSetupLock("GLXVsyncSetupLock")
|
|
|
|
, mVsyncThread("GLXVsyncThread")
|
|
|
|
, mVsyncTask(nullptr)
|
|
|
|
, mVsyncEnabledLock("GLXVsyncEnabledLock")
|
|
|
|
, mVsyncEnabled(false)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
// Sets up the display's GL context on a worker thread.
|
|
|
|
// Required as GLContexts may only be used by the creating thread.
|
|
|
|
// Returns true if setup was a success.
|
|
|
|
bool Setup()
|
|
|
|
{
|
|
|
|
MonitorAutoLock lock(mSetupLock);
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
if (!mVsyncThread.Start())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
RefPtr<Runnable> vsyncSetup = NewRunnableMethod(this, &GLXDisplay::SetupGLContext);
|
|
|
|
mVsyncThread.message_loop()->PostTask(vsyncSetup.forget());
|
|
|
|
// Wait until the setup has completed.
|
|
|
|
lock.Wait();
|
|
|
|
return mGLContext != nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Called on the Vsync thread to setup the GL context.
|
|
|
|
void SetupGLContext()
|
|
|
|
{
|
|
|
|
MonitorAutoLock lock(mSetupLock);
|
|
|
|
MOZ_ASSERT(!NS_IsMainThread());
|
|
|
|
MOZ_ASSERT(!mGLContext, "GLContext already setup!");
|
|
|
|
|
2016-08-22 18:44:54 +00:00
|
|
|
// Create video sync timer on a separate Display to prevent locking the
|
|
|
|
// main thread X display.
|
|
|
|
mXDisplay = XOpenDisplay(nullptr);
|
|
|
|
if (!mXDisplay) {
|
|
|
|
lock.NotifyAll();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-05-09 15:35:58 +00:00
|
|
|
// Most compositors wait for vsync events on the root window.
|
2016-08-22 18:44:54 +00:00
|
|
|
Window root = DefaultRootWindow(mXDisplay);
|
|
|
|
int screen = DefaultScreen(mXDisplay);
|
2016-05-09 15:35:58 +00:00
|
|
|
|
|
|
|
ScopedXFree<GLXFBConfig> cfgs;
|
|
|
|
GLXFBConfig config;
|
|
|
|
int visid;
|
2016-08-22 18:44:54 +00:00
|
|
|
if (!gl::GLContextGLX::FindFBConfigForWindow(mXDisplay, screen, root,
|
2016-05-09 15:35:58 +00:00
|
|
|
&cfgs, &config, &visid)) {
|
|
|
|
lock.NotifyAll();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mGLContext = gl::GLContextGLX::CreateGLContext(
|
2016-06-06 23:27:43 +00:00
|
|
|
gl::CreateContextFlags::NONE,
|
2016-05-09 15:35:58 +00:00
|
|
|
gl::SurfaceCaps::Any(),
|
|
|
|
nullptr,
|
|
|
|
false,
|
2016-08-22 18:44:54 +00:00
|
|
|
mXDisplay,
|
2016-05-09 15:35:58 +00:00
|
|
|
root,
|
|
|
|
config,
|
|
|
|
false);
|
|
|
|
|
2016-06-11 05:27:29 +00:00
|
|
|
if (!mGLContext) {
|
|
|
|
lock.NotifyAll();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-05-09 15:35:58 +00:00
|
|
|
mGLContext->MakeCurrent();
|
|
|
|
|
|
|
|
// Test that SGI_video_sync lets us get the counter.
|
|
|
|
unsigned int syncCounter = 0;
|
|
|
|
if (gl::sGLXLibrary.xGetVideoSync(&syncCounter) != 0) {
|
|
|
|
mGLContext = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
lock.NotifyAll();
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void EnableVsync() override
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
MOZ_ASSERT(mGLContext, "GLContext not setup!");
|
|
|
|
|
|
|
|
MonitorAutoLock lock(mVsyncEnabledLock);
|
|
|
|
if (mVsyncEnabled) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mVsyncEnabled = true;
|
|
|
|
|
|
|
|
// If the task has not nulled itself out, it hasn't yet realized
|
|
|
|
// that vsync was disabled earlier, so continue its execution.
|
|
|
|
if (!mVsyncTask) {
|
|
|
|
mVsyncTask = NewRunnableMethod(this, &GLXDisplay::RunVsync);
|
|
|
|
RefPtr<Runnable> addrefedTask = mVsyncTask;
|
|
|
|
mVsyncThread.message_loop()->PostTask(addrefedTask.forget());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void DisableVsync() override
|
|
|
|
{
|
|
|
|
MonitorAutoLock lock(mVsyncEnabledLock);
|
|
|
|
mVsyncEnabled = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool IsVsyncEnabled() override
|
|
|
|
{
|
|
|
|
MonitorAutoLock lock(mVsyncEnabledLock);
|
|
|
|
return mVsyncEnabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void Shutdown() override
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
DisableVsync();
|
|
|
|
|
|
|
|
// Cleanup thread-specific resources before shutting down.
|
|
|
|
RefPtr<Runnable> shutdownTask = NewRunnableMethod(this, &GLXDisplay::Cleanup);
|
|
|
|
mVsyncThread.message_loop()->PostTask(shutdownTask.forget());
|
|
|
|
|
|
|
|
// Stop, waiting for the cleanup task to finish execution.
|
|
|
|
mVsyncThread.Stop();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
virtual ~GLXDisplay()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void RunVsync()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(!NS_IsMainThread());
|
|
|
|
|
|
|
|
mGLContext->MakeCurrent();
|
|
|
|
|
|
|
|
unsigned int syncCounter = 0;
|
|
|
|
gl::sGLXLibrary.xGetVideoSync(&syncCounter);
|
|
|
|
for (;;) {
|
|
|
|
{
|
|
|
|
MonitorAutoLock lock(mVsyncEnabledLock);
|
|
|
|
if (!mVsyncEnabled) {
|
|
|
|
mVsyncTask = nullptr;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TimeStamp lastVsync = TimeStamp::Now();
|
2016-06-14 12:19:43 +00:00
|
|
|
bool useSoftware = false;
|
|
|
|
|
2016-05-09 15:35:58 +00:00
|
|
|
// Wait until the video sync counter reaches the next value by waiting
|
|
|
|
// until the parity of the counter value changes.
|
|
|
|
unsigned int nextSync = syncCounter + 1;
|
2016-06-14 12:19:43 +00:00
|
|
|
int status;
|
|
|
|
if ((status = gl::sGLXLibrary.xWaitVideoSync(2, nextSync % 2, &syncCounter)) != 0) {
|
|
|
|
gfxWarningOnce() << "glXWaitVideoSync returned " << status;
|
|
|
|
useSoftware = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (syncCounter == (nextSync - 1)) {
|
|
|
|
gfxWarningOnce() << "glXWaitVideoSync failed to increment the sync counter.";
|
|
|
|
useSoftware = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (useSoftware) {
|
|
|
|
double remaining = (1000.f / 60.f) -
|
|
|
|
(TimeStamp::Now() - lastVsync).ToMilliseconds();
|
|
|
|
if (remaining > 0) {
|
|
|
|
PlatformThread::Sleep(remaining);
|
2016-05-09 15:35:58 +00:00
|
|
|
}
|
|
|
|
}
|
2016-06-14 12:19:43 +00:00
|
|
|
|
|
|
|
lastVsync = TimeStamp::Now();
|
|
|
|
NotifyVsync(lastVsync);
|
2016-05-09 15:35:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Cleanup() {
|
|
|
|
MOZ_ASSERT(!NS_IsMainThread());
|
|
|
|
|
|
|
|
mGLContext = nullptr;
|
2016-08-22 18:44:54 +00:00
|
|
|
XCloseDisplay(mXDisplay);
|
2016-05-09 15:35:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Owned by the vsync thread.
|
|
|
|
RefPtr<gl::GLContextGLX> mGLContext;
|
2016-08-22 18:44:54 +00:00
|
|
|
_XDisplay* mXDisplay;
|
2016-05-09 15:35:58 +00:00
|
|
|
Monitor mSetupLock;
|
|
|
|
base::Thread mVsyncThread;
|
|
|
|
RefPtr<Runnable> mVsyncTask;
|
|
|
|
Monitor mVsyncEnabledLock;
|
|
|
|
bool mVsyncEnabled;
|
|
|
|
};
|
|
|
|
private:
|
|
|
|
// We need a refcounted VsyncSource::Display to use chromium IPC runnables.
|
|
|
|
RefPtr<GLXDisplay> mGlobalDisplay;
|
|
|
|
};
|
|
|
|
|
|
|
|
already_AddRefed<gfx::VsyncSource>
|
|
|
|
gfxPlatformGtk::CreateHardwareVsyncSource()
|
|
|
|
{
|
2016-06-21 19:51:34 +00:00
|
|
|
// Only use GLX vsync when the OpenGL compositor is being used.
|
|
|
|
// The extra cost of initializing a GLX context while blocking the main
|
|
|
|
// thread is not worth it when using basic composition.
|
|
|
|
if (gfxConfig::IsEnabled(Feature::HW_COMPOSITING)) {
|
|
|
|
if (gl::sGLXLibrary.SupportsVideoSync()) {
|
|
|
|
RefPtr<VsyncSource> vsyncSource = new GLXVsyncSource();
|
|
|
|
VsyncSource::Display& display = vsyncSource->GetGlobalDisplay();
|
|
|
|
if (!static_cast<GLXVsyncSource::GLXDisplay&>(display).Setup()) {
|
|
|
|
NS_WARNING("Failed to setup GLContext, falling back to software vsync.");
|
|
|
|
return gfxPlatform::CreateHardwareVsyncSource();
|
|
|
|
}
|
|
|
|
return vsyncSource.forget();
|
|
|
|
}
|
|
|
|
NS_WARNING("SGI_video_sync unsupported. Falling back to software vsync.");
|
2016-05-09 15:35:58 +00:00
|
|
|
}
|
|
|
|
return gfxPlatform::CreateHardwareVsyncSource();
|
|
|
|
}
|
|
|
|
|
2016-06-26 16:31:07 +00:00
|
|
|
bool
|
|
|
|
gfxPlatformGtk::SupportsApzTouchInput() const
|
|
|
|
{
|
|
|
|
int value = gfxPrefs::TouchEventsEnabled();
|
|
|
|
return value == 1 || value == 2;
|
|
|
|
}
|
|
|
|
|
2016-05-09 15:35:58 +00:00
|
|
|
#endif
|