2018-11-30 22:52:05 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
2012-05-21 15:12:37 +04: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 23:29:45 +03:00
|
|
|
|
2006-04-18 19:21:42 +04:00
|
|
|
#define PANGO_ENABLE_BACKEND
|
|
|
|
#define PANGO_ENABLE_ENGINE
|
|
|
|
|
2005-11-29 23:29:45 +03:00
|
|
|
#include "gfxPlatformGtk.h"
|
|
|
|
|
2020-06-26 13:04:04 +03:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
#include <fontconfig/fontconfig.h>
|
|
|
|
|
|
|
|
#include "base/task.h"
|
|
|
|
#include "base/thread.h"
|
|
|
|
#include "base/message_loop.h"
|
|
|
|
#include "cairo.h"
|
2014-02-09 12:04:38 +04:00
|
|
|
#include "gfx2DGlue.h"
|
2015-05-13 08:11:25 +03:00
|
|
|
#include "gfxFcPlatformFontList.h"
|
2016-06-21 22:51:34 +03:00
|
|
|
#include "gfxConfig.h"
|
2008-07-14 01:40:16 +04:00
|
|
|
#include "gfxContext.h"
|
2020-06-26 13:04:04 +03:00
|
|
|
#include "gfxImageSurface.h"
|
2008-12-06 02:19:27 +03:00
|
|
|
#include "gfxUserFontSet.h"
|
2014-06-24 02:48:59 +04:00
|
|
|
#include "gfxUtils.h"
|
2012-05-17 02:30:10 +04:00
|
|
|
#include "gfxFT2FontBase.h"
|
2017-12-01 18:18:07 +03:00
|
|
|
#include "gfxTextRun.h"
|
2020-06-26 13:04:04 +03:00
|
|
|
#include "GLContextProvider.h"
|
2016-05-09 18:35:58 +03:00
|
|
|
#include "mozilla/Atomics.h"
|
2021-02-18 16:26:29 +03:00
|
|
|
#include "mozilla/Components.h"
|
2021-09-14 19:01:08 +03:00
|
|
|
#include "mozilla/dom/ContentChild.h"
|
2018-04-13 22:34:37 +03:00
|
|
|
#include "mozilla/FontPropertyTypes.h"
|
2012-01-26 04:54:31 +04:00
|
|
|
#include "mozilla/gfx/2D.h"
|
2020-06-26 13:04:04 +03:00
|
|
|
#include "mozilla/gfx/Logging.h"
|
2021-07-06 10:42:42 +03:00
|
|
|
#include "mozilla/gfx/XlibDisplay.h"
|
2020-06-26 13:04:04 +03:00
|
|
|
#include "mozilla/Monitor.h"
|
|
|
|
#include "mozilla/Preferences.h"
|
2021-01-25 22:41:04 +03:00
|
|
|
#include "mozilla/StaticPrefs_gfx.h"
|
2020-06-26 13:04:04 +03:00
|
|
|
#include "mozilla/StaticPrefs_layers.h"
|
2022-02-23 14:47:07 +03:00
|
|
|
#include "mozilla/StaticPrefs_media.h"
|
2021-01-15 00:24:24 +03:00
|
|
|
#include "nsAppRunner.h"
|
2020-11-24 16:30:19 +03:00
|
|
|
#include "nsIGfxInfo.h"
|
2020-06-26 13:04:04 +03:00
|
|
|
#include "nsMathUtils.h"
|
|
|
|
#include "nsUnicharUtils.h"
|
|
|
|
#include "nsUnicodeProperties.h"
|
|
|
|
#include "VsyncSource.h"
|
2012-01-26 04:54:31 +04:00
|
|
|
|
2008-08-07 00:48:55 +04:00
|
|
|
#ifdef MOZ_X11
|
|
|
|
# include <gdk/gdkx.h>
|
2021-10-23 14:19:10 +03:00
|
|
|
# include <X11/extensions/Xrandr.h>
|
2008-08-19 07:22:42 +04:00
|
|
|
# include "cairo-xlib.h"
|
2020-06-26 13:04:04 +03:00
|
|
|
# include "gfxXlibSurface.h"
|
2016-05-09 18:35:58 +03:00
|
|
|
# include "GLContextGLX.h"
|
|
|
|
# include "GLXLibrary.h"
|
2020-06-26 13:04:04 +03:00
|
|
|
# include "mozilla/X11Util.h"
|
2021-10-23 14:19:10 +03:00
|
|
|
# include "SoftwareVsyncSource.h"
|
2016-05-09 18:35:58 +03:00
|
|
|
|
2009-04-20 20:36:37 +04: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-07 00:48:55 +04:00
|
|
|
#endif /* MOZ_X11 */
|
2005-11-29 23:29:45 +03:00
|
|
|
|
2020-06-23 09:27:09 +03:00
|
|
|
#ifdef MOZ_WAYLAND
|
|
|
|
# include <gdk/gdkwayland.h>
|
|
|
|
# include "mozilla/widget/nsWaylandDisplay.h"
|
|
|
|
# include "mozilla/widget/DMABufLibWrapper.h"
|
2022-02-23 14:47:07 +03:00
|
|
|
# include "mozilla/widget/VAAPIUtils.h"
|
2021-03-16 23:14:51 +03:00
|
|
|
# include "mozilla/StaticPrefs_widget.h"
|
2020-06-23 09:27:09 +03:00
|
|
|
#endif
|
|
|
|
|
2008-11-10 02:39:41 +03:00
|
|
|
#define GDK_PIXMAP_SIZE_MAX 32767
|
|
|
|
|
2015-11-20 07:35:15 +03:00
|
|
|
#define GFX_PREF_MAX_GENERIC_SUBSTITUTIONS \
|
|
|
|
"gfx.font_rendering.fontconfig.max_generic_substitutions"
|
|
|
|
|
2012-01-26 04:54:31 +04:00
|
|
|
using namespace mozilla;
|
|
|
|
using namespace mozilla::gfx;
|
2012-03-09 07:10:05 +04:00
|
|
|
using namespace mozilla::unicode;
|
2020-01-13 16:30:26 +03:00
|
|
|
using namespace mozilla::widget;
|
2012-01-26 04:54:31 +04:00
|
|
|
|
2019-09-16 20:12:38 +03:00
|
|
|
static FT_Library gPlatformFTLibrary = nullptr;
|
2020-11-09 15:18:59 +03:00
|
|
|
static int32_t sDPI;
|
|
|
|
|
|
|
|
static void screen_resolution_changed(GdkScreen* aScreen, GParamSpec* aPspec,
|
|
|
|
gpointer aClosure) {
|
|
|
|
sDPI = 0;
|
|
|
|
}
|
2019-09-16 20:12:38 +03:00
|
|
|
|
2021-01-25 22:41:04 +03:00
|
|
|
#if defined(MOZ_X11)
|
|
|
|
// TODO(aosmond): The envvar is deprecated. We should remove it once EGL is the
|
|
|
|
// default in release.
|
|
|
|
static bool IsX11EGLEnvvarEnabled() {
|
|
|
|
const char* eglPref = PR_GetEnv("MOZ_X11_EGL");
|
|
|
|
return (eglPref && *eglPref);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2005-11-29 23:29:45 +03:00
|
|
|
gfxPlatformGtk::gfxPlatformGtk() {
|
2017-04-04 17:22:00 +03:00
|
|
|
if (!gfxPlatform::IsHeadless()) {
|
|
|
|
gtk_init(nullptr, nullptr);
|
|
|
|
}
|
2015-07-29 23:38:28 +03:00
|
|
|
|
2015-11-20 07:35:15 +03:00
|
|
|
mMaxGenericSubstitutions = UNINITIALIZED_VALUE;
|
2021-03-11 17:32:53 +03:00
|
|
|
mIsX11Display = gfxPlatform::IsHeadless() ? false : GdkIsX11Display();
|
2020-07-22 21:58:11 +03:00
|
|
|
if (XRE_IsParentProcess()) {
|
2021-03-02 18:49:06 +03:00
|
|
|
InitX11EGLConfig();
|
|
|
|
if (IsWaylandDisplay() || gfxConfig::IsEnabled(Feature::X11_EGL)) {
|
2020-07-22 21:58:11 +03:00
|
|
|
gfxVars::SetUseEGL(true);
|
2021-03-16 23:14:51 +03:00
|
|
|
}
|
|
|
|
InitDmabufConfig();
|
|
|
|
if (gfxConfig::IsEnabled(Feature::DMABUF)) {
|
|
|
|
gfxVars::SetUseDMABuf(true);
|
2020-07-22 21:58:11 +03:00
|
|
|
}
|
2022-02-23 14:47:07 +03:00
|
|
|
InitVAAPIConfig();
|
|
|
|
if (gfxConfig::IsEnabled(Feature::VAAPI)) {
|
|
|
|
gfxVars::SetUseVAAPI(true);
|
|
|
|
}
|
2020-07-22 21:58:11 +03:00
|
|
|
}
|
|
|
|
|
2021-05-25 13:21:56 +03:00
|
|
|
InitBackendPrefs(GetBackendPrefs());
|
|
|
|
|
2019-09-16 20:12:38 +03:00
|
|
|
gPlatformFTLibrary = Factory::NewFTLibrary();
|
2020-07-05 22:40:37 +03:00
|
|
|
MOZ_RELEASE_ASSERT(gPlatformFTLibrary);
|
2019-09-16 20:12:38 +03:00
|
|
|
Factory::SetFTLibrary(gPlatformFTLibrary);
|
2020-11-09 15:18:59 +03:00
|
|
|
|
2020-11-25 13:08:51 +03:00
|
|
|
GdkScreen* gdkScreen = gdk_screen_get_default();
|
|
|
|
if (gdkScreen) {
|
|
|
|
g_signal_connect(gdkScreen, "notify::resolution",
|
|
|
|
G_CALLBACK(screen_resolution_changed), nullptr);
|
|
|
|
}
|
2021-09-17 19:44:10 +03:00
|
|
|
|
|
|
|
// Bug 1714483: Force disable FXAA Antialiasing on NV drivers. This is a
|
|
|
|
// temporary workaround for a driver bug.
|
|
|
|
PR_SetEnv("__GL_ALLOW_FXAA_USAGE=0");
|
2005-11-29 23:29:45 +03:00
|
|
|
}
|
|
|
|
|
2007-03-20 02:16:15 +03:00
|
|
|
gfxPlatformGtk::~gfxPlatformGtk() {
|
2019-09-16 20:12:38 +03:00
|
|
|
Factory::ReleaseFTLibrary(gPlatformFTLibrary);
|
|
|
|
gPlatformFTLibrary = nullptr;
|
2007-03-20 02:16:15 +03:00
|
|
|
}
|
|
|
|
|
2021-03-02 18:49:06 +03:00
|
|
|
void gfxPlatformGtk::InitX11EGLConfig() {
|
|
|
|
FeatureState& feature = gfxConfig::GetFeature(Feature::X11_EGL);
|
|
|
|
#ifdef MOZ_X11
|
|
|
|
feature.EnableByDefault();
|
|
|
|
|
|
|
|
if (StaticPrefs::gfx_x11_egl_force_enabled_AtStartup()) {
|
|
|
|
feature.UserForceEnable("Force enabled by pref");
|
|
|
|
} else if (IsX11EGLEnvvarEnabled()) {
|
|
|
|
feature.UserForceEnable("Force enabled by envvar");
|
|
|
|
} else if (StaticPrefs::gfx_x11_egl_force_disabled_AtStartup()) {
|
|
|
|
feature.UserDisable("Force disabled by pref",
|
|
|
|
"FEATURE_FAILURE_USER_FORCE_DISABLED"_ns);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCString failureId;
|
|
|
|
int32_t status;
|
|
|
|
nsCOMPtr<nsIGfxInfo> gfxInfo = components::GfxInfo::Service();
|
|
|
|
if (NS_FAILED(gfxInfo->GetFeatureStatus(nsIGfxInfo::FEATURE_X11_EGL,
|
|
|
|
failureId, &status))) {
|
|
|
|
feature.Disable(FeatureStatus::BlockedNoGfxInfo, "gfxInfo is broken",
|
|
|
|
"FEATURE_FAILURE_NO_GFX_INFO"_ns);
|
|
|
|
} else if (status != nsIGfxInfo::FEATURE_STATUS_OK) {
|
|
|
|
feature.Disable(FeatureStatus::Blocklisted, "Blocklisted by gfxInfo",
|
|
|
|
failureId);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoString testType;
|
|
|
|
gfxInfo->GetTestType(testType);
|
|
|
|
// We can only use X11/EGL if we actually found the EGL library and
|
|
|
|
// successfully use it to determine system information in glxtest.
|
|
|
|
if (testType != u"EGL") {
|
|
|
|
feature.ForceDisable(FeatureStatus::Broken, "glxtest could not use EGL",
|
|
|
|
"FEATURE_FAILURE_GLXTEST_NO_EGL"_ns);
|
|
|
|
}
|
2021-09-13 17:55:05 +03:00
|
|
|
|
2022-01-20 23:43:45 +03:00
|
|
|
if (feature.IsEnabled() && IsX11Display()) {
|
|
|
|
// Enabling glthread crashes on X11/EGL, see bug 1670545
|
2021-09-13 17:55:05 +03:00
|
|
|
PR_SetEnv("mesa_glthread=false");
|
|
|
|
}
|
2021-03-02 18:49:06 +03:00
|
|
|
#else
|
|
|
|
feature.DisableByDefault(FeatureStatus::Unavailable, "X11 support missing",
|
|
|
|
"FEATURE_FAILURE_NO_X11"_ns);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2021-03-16 23:14:51 +03:00
|
|
|
void gfxPlatformGtk::InitDmabufConfig() {
|
|
|
|
FeatureState& feature = gfxConfig::GetFeature(Feature::DMABUF);
|
|
|
|
#ifdef MOZ_WAYLAND
|
|
|
|
feature.EnableByDefault();
|
|
|
|
|
|
|
|
if (StaticPrefs::widget_dmabuf_force_enabled_AtStartup()) {
|
|
|
|
feature.UserForceEnable("Force enabled by pref");
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCString failureId;
|
|
|
|
int32_t status;
|
|
|
|
nsCOMPtr<nsIGfxInfo> gfxInfo = components::GfxInfo::Service();
|
|
|
|
if (NS_FAILED(gfxInfo->GetFeatureStatus(nsIGfxInfo::FEATURE_DMABUF, failureId,
|
|
|
|
&status))) {
|
|
|
|
feature.Disable(FeatureStatus::BlockedNoGfxInfo, "gfxInfo is broken",
|
|
|
|
"FEATURE_FAILURE_NO_GFX_INFO"_ns);
|
|
|
|
} else if (status != nsIGfxInfo::FEATURE_STATUS_OK) {
|
|
|
|
feature.Disable(FeatureStatus::Blocklisted, "Blocklisted by gfxInfo",
|
|
|
|
failureId);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!gfxVars::UseEGL()) {
|
|
|
|
feature.ForceDisable(FeatureStatus::Unavailable, "Requires EGL",
|
|
|
|
"FEATURE_FAILURE_REQUIRES_EGL"_ns);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (feature.IsEnabled()) {
|
|
|
|
nsAutoCString drmRenderDevice;
|
|
|
|
gfxInfo->GetDrmRenderDevice(drmRenderDevice);
|
|
|
|
gfxVars::SetDrmRenderDevice(drmRenderDevice);
|
|
|
|
|
|
|
|
if (!GetDMABufDevice()->Configure(failureId)) {
|
|
|
|
feature.ForceDisable(FeatureStatus::Failed, "Failed to configure",
|
|
|
|
failureId);
|
|
|
|
}
|
|
|
|
}
|
2022-02-23 14:47:07 +03:00
|
|
|
#else
|
|
|
|
feature.DisableByDefault(FeatureStatus::Unavailable,
|
|
|
|
"Wayland support missing",
|
|
|
|
"FEATURE_FAILURE_NO_WAYLAND"_ns);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void gfxPlatformGtk::InitVAAPIConfig() {
|
|
|
|
FeatureState& feature = gfxConfig::GetFeature(Feature::VAAPI);
|
|
|
|
#ifdef MOZ_WAYLAND
|
|
|
|
feature.DisableByDefault(FeatureStatus::Disabled,
|
|
|
|
"VAAPI is disabled by default",
|
|
|
|
"FEATURE_VAAPI_DISABLED"_ns);
|
|
|
|
|
|
|
|
if (StaticPrefs::media_ffmpeg_vaapi_enabled()) {
|
|
|
|
feature.UserForceEnable("Force enabled by pref");
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCString failureId;
|
|
|
|
int32_t status;
|
|
|
|
nsCOMPtr<nsIGfxInfo> gfxInfo = components::GfxInfo::Service();
|
|
|
|
if (NS_FAILED(gfxInfo->GetFeatureStatus(nsIGfxInfo::FEATURE_VAAPI, failureId,
|
|
|
|
&status))) {
|
|
|
|
feature.Disable(FeatureStatus::BlockedNoGfxInfo, "gfxInfo is broken",
|
|
|
|
"FEATURE_FAILURE_NO_GFX_INFO"_ns);
|
|
|
|
} else if (status != nsIGfxInfo::FEATURE_STATUS_OK) {
|
|
|
|
feature.Disable(FeatureStatus::Blocklisted, "Blocklisted by gfxInfo",
|
|
|
|
failureId);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!gfxVars::UseEGL()) {
|
|
|
|
feature.ForceDisable(FeatureStatus::Unavailable, "Requires EGL",
|
|
|
|
"FEATURE_FAILURE_REQUIRES_EGL"_ns);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (feature.IsEnabled()) {
|
|
|
|
if (!VAAPIIsSupported()) {
|
|
|
|
feature.ForceDisable(FeatureStatus::Failed, "Failed to configure",
|
|
|
|
failureId);
|
|
|
|
}
|
|
|
|
}
|
2021-03-16 23:14:51 +03:00
|
|
|
#else
|
|
|
|
feature.DisableByDefault(FeatureStatus::Unavailable,
|
|
|
|
"Wayland support missing",
|
|
|
|
"FEATURE_FAILURE_NO_WAYLAND"_ns);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2021-05-11 16:38:59 +03:00
|
|
|
void gfxPlatformGtk::InitWebRenderConfig() {
|
|
|
|
gfxPlatform::InitWebRenderConfig();
|
|
|
|
|
|
|
|
if (!XRE_IsParentProcess()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
FeatureState& feature = gfxConfig::GetFeature(Feature::WEBRENDER_COMPOSITOR);
|
|
|
|
if (feature.IsEnabled()) {
|
2021-05-26 00:14:39 +03:00
|
|
|
if (!(gfxConfig::IsEnabled(Feature::WEBRENDER) ||
|
|
|
|
gfxConfig::IsEnabled(Feature::WEBRENDER_SOFTWARE))) {
|
2021-05-11 16:38:59 +03:00
|
|
|
feature.ForceDisable(FeatureStatus::Unavailable, "WebRender disabled",
|
|
|
|
"FEATURE_FAILURE_WR_DISABLED"_ns);
|
|
|
|
} else if (!IsWaylandDisplay()) {
|
|
|
|
feature.ForceDisable(FeatureStatus::Unavailable,
|
|
|
|
"Wayland support missing",
|
|
|
|
"FEATURE_FAILURE_NO_WAYLAND"_ns);
|
|
|
|
}
|
|
|
|
#ifdef MOZ_WAYLAND
|
2021-07-13 16:44:12 +03:00
|
|
|
else if (gfxConfig::IsEnabled(Feature::WEBRENDER) &&
|
|
|
|
!gfxConfig::IsEnabled(Feature::DMABUF)) {
|
|
|
|
// We use zwp_linux_dmabuf_v1 and GBM directly to manage FBOs. In theory
|
|
|
|
// this is also possible vie EGLstreams, but we don't bother to implement
|
|
|
|
// it as recent NVidia drivers support GBM and DMABuf as well.
|
|
|
|
feature.ForceDisable(FeatureStatus::Unavailable,
|
|
|
|
"Hardware Webrender requires DMAbuf support",
|
|
|
|
"FEATURE_FAILURE_NO_DMABUF"_ns);
|
|
|
|
} else if (!widget::WaylandDisplayGet()->GetViewporter()) {
|
2021-05-11 16:38:59 +03:00
|
|
|
feature.ForceDisable(FeatureStatus::Unavailable,
|
|
|
|
"Requires wp_viewporter protocol support",
|
|
|
|
"FEATURE_FAILURE_REQUIRES_WPVIEWPORTER"_ns);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
gfxVars::SetUseWebRenderCompositor(feature.IsEnabled());
|
|
|
|
}
|
|
|
|
|
2019-05-27 00:43:34 +03:00
|
|
|
void gfxPlatformGtk::InitPlatformGPUProcessPrefs() {
|
|
|
|
#ifdef MOZ_WAYLAND
|
2019-11-07 17:28:55 +03:00
|
|
|
if (IsWaylandDisplay()) {
|
2019-05-27 00:43:34 +03:00
|
|
|
FeatureState& gpuProc = gfxConfig::GetFeature(Feature::GPU_PROCESS);
|
|
|
|
gpuProc.ForceDisable(FeatureStatus::Blocked,
|
|
|
|
"Wayland does not work in the GPU process",
|
|
|
|
"FEATURE_FAILURE_WAYLAND"_ns);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2015-07-07 04:21:47 +03:00
|
|
|
already_AddRefed<gfxASurface> gfxPlatformGtk::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;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool needsClear = true;
|
2008-08-07 00:48:55 +04:00
|
|
|
#ifdef MOZ_X11
|
2006-02-23 03:45:55 +03: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 07:55:24 +04:00
|
|
|
GdkScreen* gdkScreen = gdk_screen_get_default();
|
|
|
|
if (gdkScreen) {
|
2021-08-25 22:35:23 +03:00
|
|
|
newSurface = new gfxImageSurface(aSize, aFormat);
|
|
|
|
// The gfxImageSurface ctor zeroes this for us, no need to
|
|
|
|
// waste time clearing again
|
|
|
|
needsClear = false;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2008-08-07 00:48:55 +04:00
|
|
|
#endif
|
2005-11-29 23:29:45 +03:00
|
|
|
|
2008-11-10 02:39:41 +03:00
|
|
|
if (!newSurface) {
|
|
|
|
// We couldn't create a native surface for whatever reason;
|
2010-07-02 07:55:24 +04:00
|
|
|
// e.g., no display, no RENDER, bad size, etc.
|
2008-11-10 02:39:41 +03:00
|
|
|
// Fall back to image surface for the data.
|
2015-07-07 04:21:47 +03:00
|
|
|
newSurface = new gfxImageSurface(aSize, aFormat);
|
2008-11-10 02:39:41 +03:00
|
|
|
}
|
|
|
|
|
2010-11-19 19:56:05 +03:00
|
|
|
if (newSurface->CairoStatus()) {
|
2012-07-30 18:20:58 +04:00
|
|
|
newSurface = nullptr; // surface isn't valid for some reason
|
2010-11-19 19:56:05 +03:00
|
|
|
}
|
|
|
|
|
2010-09-24 05:00:06 +04:00
|
|
|
if (newSurface && needsClear) {
|
2014-06-24 02:48:59 +04:00
|
|
|
gfxUtils::ClearThebesSurface(newSurface);
|
2008-07-14 01:40:16 +04:00
|
|
|
}
|
|
|
|
|
2007-11-27 04:40:03 +03:00
|
|
|
return newSurface.forget();
|
2005-11-29 23:29:45 +03:00
|
|
|
}
|
|
|
|
|
2017-10-03 01:05:19 +03:00
|
|
|
nsresult gfxPlatformGtk::GetFontList(nsAtom* aLangGroup,
|
2006-01-10 23:26:40 +03:00
|
|
|
const nsACString& aGenericFamily,
|
2009-01-18 23:14:14 +03:00
|
|
|
nsTArray<nsString>& aListOfFonts) {
|
2017-03-22 05:34:03 +03:00
|
|
|
gfxPlatformFontList::PlatformFontList()->GetFontList(
|
|
|
|
aLangGroup, aGenericFamily, aListOfFonts);
|
|
|
|
return NS_OK;
|
2006-11-21 09:31:04 +03:00
|
|
|
}
|
|
|
|
|
2015-05-13 08:11:25 +03: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";
|
|
|
|
static const char kFontFreeSans[] = "FreeSans";
|
|
|
|
static const char kFontFreeSerif[] = "FreeSerif";
|
|
|
|
static const char kFontTakaoPGothic[] = "TakaoPGothic";
|
2018-03-09 03:23:19 +03:00
|
|
|
static const char kFontTwemojiMozilla[] = "Twemoji Mozilla";
|
2015-05-13 08:11:25 +03:00
|
|
|
static const char kFontDroidSansFallback[] = "Droid Sans Fallback";
|
|
|
|
static const char kFontWenQuanYiMicroHei[] = "WenQuanYi Micro Hei";
|
|
|
|
static const char kFontNanumGothic[] = "NanumGothic";
|
2018-06-20 21:47:08 +03:00
|
|
|
static const char kFontSymbola[] = "Symbola";
|
2021-06-14 20:09:21 +03:00
|
|
|
static const char kFontNotoSansSymbols[] = "Noto Sans Symbols";
|
|
|
|
static const char kFontNotoSansSymbols2[] = "Noto Sans Symbols2";
|
2015-05-13 08:11:25 +03:00
|
|
|
|
2020-08-26 12:31:58 +03:00
|
|
|
void gfxPlatformGtk::GetCommonFallbackFonts(uint32_t aCh, Script aRunScript,
|
|
|
|
eFontPresentation aPresentation,
|
2015-05-13 08:11:25 +03:00
|
|
|
nsTArray<const char*>& aFontList) {
|
2020-09-01 10:43:53 +03:00
|
|
|
if (PrefersColor(aPresentation)) {
|
2020-07-28 10:40:54 +03:00
|
|
|
aFontList.AppendElement(kFontTwemojiMozilla);
|
2018-11-30 13:46:48 +03: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 23:58:49 +03:00
|
|
|
|
2015-05-13 08:11:25 +03:00
|
|
|
aFontList.AppendElement(kFontDejaVuSerif);
|
|
|
|
aFontList.AppendElement(kFontFreeSerif);
|
|
|
|
aFontList.AppendElement(kFontDejaVuSans);
|
|
|
|
aFontList.AppendElement(kFontFreeSans);
|
2018-06-20 21:47:08 +03:00
|
|
|
aFontList.AppendElement(kFontSymbola);
|
2021-06-14 20:09:21 +03:00
|
|
|
aFontList.AppendElement(kFontNotoSansSymbols);
|
|
|
|
aFontList.AppendElement(kFontNotoSansSymbols2);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-05-13 08:11:25 +03: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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-02 23:29:33 +03:00
|
|
|
void gfxPlatformGtk::ReadSystemFontList(
|
2021-05-01 23:00:31 +03:00
|
|
|
mozilla::dom::SystemFontList* retValue) {
|
2017-11-02 23:29:33 +03:00
|
|
|
gfxFcPlatformFontList::PlatformFontList()->ReadSystemFontList(retValue);
|
|
|
|
}
|
|
|
|
|
2021-05-18 14:10:42 +03:00
|
|
|
bool gfxPlatformGtk::CreatePlatformFontList() {
|
|
|
|
return gfxPlatformFontList::Initialize(new gfxFcPlatformFontList);
|
2015-05-13 08:11:25 +03:00
|
|
|
}
|
|
|
|
|
2017-06-14 11:54:21 +03:00
|
|
|
int32_t gfxPlatformGtk::GetFontScaleDPI() {
|
2021-03-22 19:11:33 +03:00
|
|
|
MOZ_ASSERT(XRE_IsParentProcess(),
|
|
|
|
"You can access this via LookAndFeel if you need it in child "
|
|
|
|
"processes");
|
2020-11-09 15:18:59 +03:00
|
|
|
if (MOZ_LIKELY(sDPI != 0)) {
|
|
|
|
return sDPI;
|
|
|
|
}
|
2020-10-13 05:47:27 +03:00
|
|
|
GdkScreen* screen = gdk_screen_get_default();
|
2020-11-09 15:18:59 +03:00
|
|
|
// Ensure settings in config files are processed.
|
2020-10-13 05:47:27 +03:00
|
|
|
gtk_settings_get_for_screen(screen);
|
|
|
|
int32_t dpi = int32_t(round(gdk_screen_get_resolution(screen)));
|
|
|
|
if (dpi <= 0) {
|
|
|
|
// Fall back to something sane
|
|
|
|
dpi = 96;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2020-11-09 15:18:59 +03:00
|
|
|
sDPI = dpi;
|
2020-10-13 05:47:27 +03:00
|
|
|
return dpi;
|
2006-04-18 19:21:42 +04:00
|
|
|
}
|
2007-07-24 02:02:17 +04:00
|
|
|
|
2017-06-14 11:54:21 +03:00
|
|
|
double gfxPlatformGtk::GetFontScaleFactor() {
|
2019-12-31 13:36:29 +03: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.
|
|
|
|
//
|
|
|
|
// A similar step for 1.25 is added as well, because this is the scale that
|
|
|
|
// "Large text" settings use in gnome, and it seems worth to allow, especially
|
|
|
|
// on already-hidpi environments.
|
2017-06-14 11:54:21 +03:00
|
|
|
int32_t dpi = GetFontScaleDPI();
|
2019-12-31 13:36:29 +03:00
|
|
|
if (dpi < 120) {
|
2016-05-11 00:21:13 +03:00
|
|
|
return 1.0;
|
2017-02-09 15:39:27 +03:00
|
|
|
}
|
2019-12-31 13:36:29 +03:00
|
|
|
if (dpi < 132) {
|
|
|
|
return 1.25;
|
|
|
|
}
|
2017-02-09 15:39:27 +03:00
|
|
|
if (dpi < 168) {
|
2016-05-11 00:21:13 +03:00
|
|
|
return 1.5;
|
|
|
|
}
|
2017-02-09 15:39:27 +03:00
|
|
|
return round(dpi / 96.0);
|
2015-02-10 10:14:00 +03:00
|
|
|
}
|
|
|
|
|
2010-12-15 21:17:26 +03:00
|
|
|
gfxImageFormat gfxPlatformGtk::GetOffscreenFormat() {
|
2012-05-26 08:38:17 +04:00
|
|
|
// Make sure there is a screen
|
|
|
|
GdkScreen* screen = gdk_screen_get_default();
|
2012-06-28 04:15:32 +04:00
|
|
|
if (screen && gdk_visual_get_depth(gdk_visual_get_system()) == 16) {
|
2016-01-08 07:57:38 +03:00
|
|
|
return SurfaceFormat::R5G6B5_UINT16;
|
2010-12-15 21:17:26 +03:00
|
|
|
}
|
|
|
|
|
2016-01-08 07:57:38 +03:00
|
|
|
return SurfaceFormat::X8R8G8B8_UINT32;
|
2010-12-15 21:17:26 +03:00
|
|
|
}
|
|
|
|
|
2015-11-20 07:35:15 +03:00
|
|
|
void gfxPlatformGtk::FontsPrefsChanged(const char* aPref) {
|
|
|
|
// only checking for generic substitions, pass other changes up
|
2021-04-29 13:43:17 +03:00
|
|
|
if (strcmp(GFX_PREF_MAX_GENERIC_SUBSTITUTIONS, aPref) != 0) {
|
2015-11-20 07:35:15 +03:00
|
|
|
gfxPlatform::FontsPrefsChanged(aPref);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mMaxGenericSubstitutions = UNINITIALIZED_VALUE;
|
2017-03-22 05:34:03 +03:00
|
|
|
gfxFcPlatformFontList* pfl = gfxFcPlatformFontList::PlatformFontList();
|
|
|
|
pfl->ClearGenericMappings();
|
|
|
|
FlushFontAndWordCaches();
|
2015-11-20 07:35:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t gfxPlatformGtk::MaxGenericSubstitions() {
|
|
|
|
if (mMaxGenericSubstitutions == UNINITIALIZED_VALUE) {
|
|
|
|
mMaxGenericSubstitutions =
|
|
|
|
Preferences::GetInt(GFX_PREF_MAX_GENERIC_SUBSTITUTIONS, 3);
|
|
|
|
if (mMaxGenericSubstitutions < 0) {
|
|
|
|
mMaxGenericSubstitutions = 3;
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2015-11-20 07:35:15 +03:00
|
|
|
|
|
|
|
return uint32_t(mMaxGenericSubstitutions);
|
|
|
|
}
|
|
|
|
|
2018-01-10 21:09:18 +03:00
|
|
|
bool gfxPlatformGtk::AccelerateLayersByDefault() { return true; }
|
|
|
|
|
2020-02-22 00:27:53 +03:00
|
|
|
#if defined(MOZ_X11)
|
2013-11-07 14:20:08 +04:00
|
|
|
|
2020-02-22 00:27:53 +03:00
|
|
|
static nsTArray<uint8_t> GetDisplayICCProfile(Display* dpy, Window& root) {
|
|
|
|
const char kIccProfileAtomName[] = "_ICC_PROFILE";
|
|
|
|
Atom iccAtom = XInternAtom(dpy, kIccProfileAtomName, TRUE);
|
|
|
|
if (!iccAtom) {
|
|
|
|
return nsTArray<uint8_t>();
|
|
|
|
}
|
|
|
|
|
|
|
|
Atom retAtom;
|
|
|
|
int retFormat;
|
|
|
|
unsigned long retLength, retAfter;
|
|
|
|
unsigned char* retProperty;
|
|
|
|
|
|
|
|
if (XGetWindowProperty(dpy, root, iccAtom, 0, INT_MAX /* length */, X11False,
|
|
|
|
AnyPropertyType, &retAtom, &retFormat, &retLength,
|
|
|
|
&retAfter, &retProperty) != Success) {
|
|
|
|
return nsTArray<uint8_t>();
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2020-02-22 00:27:53 +03:00
|
|
|
nsTArray<uint8_t> result;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2020-02-22 00:27:53 +03:00
|
|
|
if (retLength > 0) {
|
|
|
|
result.AppendElements(static_cast<uint8_t*>(retProperty), retLength);
|
|
|
|
}
|
|
|
|
|
|
|
|
XFree(retProperty);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsTArray<uint8_t> gfxPlatformGtk::GetPlatformCMSOutputProfileData() {
|
2020-04-02 18:42:15 +03:00
|
|
|
nsTArray<uint8_t> prefProfileData = GetPrefCMSOutputProfileData();
|
|
|
|
if (!prefProfileData.IsEmpty()) {
|
|
|
|
return prefProfileData;
|
|
|
|
}
|
|
|
|
|
2021-09-14 19:01:08 +03:00
|
|
|
if (XRE_IsContentProcess()) {
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
// This will be passed in during InitChild so we can avoid sending a
|
|
|
|
// sync message back to the parent during init.
|
|
|
|
const mozilla::gfx::ContentDeviceData* contentDeviceData =
|
|
|
|
GetInitContentDeviceData();
|
|
|
|
if (contentDeviceData) {
|
|
|
|
// On Windows, we assert that the profile isn't empty, but on
|
|
|
|
// Linux it can legitimately be empty if the display isn't
|
|
|
|
// calibrated. Thus, no assertion here.
|
|
|
|
return contentDeviceData->cmsOutputProfileData().Clone();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise we need to ask the parent for the updated color profile
|
|
|
|
mozilla::dom::ContentChild* cc = mozilla::dom::ContentChild::GetSingleton();
|
|
|
|
nsTArray<uint8_t> result;
|
|
|
|
Unused << cc->SendGetOutputColorProfileData(&result);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2020-02-22 00:27:53 +03:00
|
|
|
if (!mIsX11Display) {
|
|
|
|
return nsTArray<uint8_t>();
|
|
|
|
}
|
|
|
|
|
|
|
|
GdkDisplay* display = gdk_display_get_default();
|
2015-03-05 05:56:00 +03:00
|
|
|
Display* dpy = GDK_DISPLAY_XDISPLAY(display);
|
2013-03-22 07:12:30 +04: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 14:20:08 +04:00
|
|
|
// return with nullptr.
|
2020-02-22 00:27:53 +03:00
|
|
|
if (!dpy) {
|
|
|
|
return nsTArray<uint8_t>();
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2007-07-24 02:02:17 +04:00
|
|
|
Window root = gdk_x11_get_default_root_xwindow();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2020-02-22 00:27:53 +03:00
|
|
|
// First try ICC Profile
|
|
|
|
nsTArray<uint8_t> iccResult = GetDisplayICCProfile(dpy, root);
|
|
|
|
if (!iccResult.IsEmpty()) {
|
|
|
|
return iccResult;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If ICC doesn't work, then try EDID
|
|
|
|
const char kEdid1AtomName[] = "XFree86_DDC_EDID1_RAWDATA";
|
|
|
|
Atom edidAtom = XInternAtom(dpy, kEdid1AtomName, TRUE);
|
|
|
|
if (!edidAtom) {
|
|
|
|
return nsTArray<uint8_t>();
|
|
|
|
}
|
|
|
|
|
2007-07-24 02:02:17 +04:00
|
|
|
Atom retAtom;
|
|
|
|
int retFormat;
|
|
|
|
unsigned long retLength, retAfter;
|
|
|
|
unsigned char* retProperty;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2020-02-22 00:27:53 +03:00
|
|
|
if (XGetWindowProperty(dpy, root, edidAtom, 0, 32, X11False, AnyPropertyType,
|
|
|
|
&retAtom, &retFormat, &retLength, &retAfter,
|
|
|
|
&retProperty) != Success) {
|
|
|
|
return nsTArray<uint8_t>();
|
|
|
|
}
|
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 23:58:49 +03:00
|
|
|
|
2020-02-22 00:27:53 +03:00
|
|
|
if (retLength != 128) {
|
|
|
|
return nsTArray<uint8_t>();
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2020-02-22 00:27:53 +03:00
|
|
|
// Format documented in "VESA E-EDID Implementation Guide"
|
2021-04-29 13:43:17 +03:00
|
|
|
float gamma = (100 + (float)retProperty[0x17]) / 100.0f;
|
2020-02-22 00:27:53 +03:00
|
|
|
|
|
|
|
qcms_CIE_xyY whitePoint;
|
|
|
|
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;
|
|
|
|
|
|
|
|
qcms_CIE_xyYTRIPLE primaries;
|
|
|
|
primaries.red.x =
|
|
|
|
((retProperty[0x1b] << 2) | (retProperty[0x19] >> 6 & 3)) / 1024.0;
|
|
|
|
primaries.red.y =
|
|
|
|
((retProperty[0x1c] << 2) | (retProperty[0x19] >> 4 & 3)) / 1024.0;
|
|
|
|
primaries.red.Y = 1.0;
|
|
|
|
|
|
|
|
primaries.green.x =
|
|
|
|
((retProperty[0x1d] << 2) | (retProperty[0x19] >> 2 & 3)) / 1024.0;
|
|
|
|
primaries.green.y =
|
|
|
|
((retProperty[0x1e] << 2) | (retProperty[0x19] >> 0 & 3)) / 1024.0;
|
|
|
|
primaries.green.Y = 1.0;
|
|
|
|
|
|
|
|
primaries.blue.x =
|
|
|
|
((retProperty[0x1f] << 2) | (retProperty[0x1a] >> 6 & 3)) / 1024.0;
|
|
|
|
primaries.blue.y =
|
|
|
|
((retProperty[0x20] << 2) | (retProperty[0x1a] >> 4 & 3)) / 1024.0;
|
|
|
|
primaries.blue.Y = 1.0;
|
|
|
|
|
|
|
|
XFree(retProperty);
|
|
|
|
|
|
|
|
void* mem = nullptr;
|
|
|
|
size_t size = 0;
|
|
|
|
qcms_data_create_rgb_with_gamma(whitePoint, primaries, gamma, &mem, &size);
|
|
|
|
if (!mem) {
|
|
|
|
return nsTArray<uint8_t>();
|
|
|
|
}
|
2007-07-24 02:02:17 +04:00
|
|
|
|
2020-02-22 00:27:53 +03:00
|
|
|
nsTArray<uint8_t> result;
|
|
|
|
result.AppendElements(static_cast<uint8_t*>(mem), size);
|
|
|
|
free(mem);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2021-03-31 17:32:55 +03:00
|
|
|
// XXX: It seems like we get wrong colors when using this constructed profile:
|
|
|
|
// See bug 1696819. For now just forget that we made it.
|
|
|
|
return nsTArray<uint8_t>();
|
2020-02-22 00:27:53 +03:00
|
|
|
}
|
2007-07-24 02:02:17 +04:00
|
|
|
|
2020-02-22 00:27:53 +03:00
|
|
|
#else // defined(MOZ_X11)
|
2007-07-24 02:02:17 +04:00
|
|
|
|
2020-02-22 00:27:53 +03:00
|
|
|
nsTArray<uint8_t> gfxPlatformGtk::GetPlatformCMSOutputProfileData() {
|
|
|
|
return nsTArray<uint8_t>();
|
2007-07-24 02:02:17 +04:00
|
|
|
}
|
2008-08-07 00:48:55 +04:00
|
|
|
|
2020-02-22 00:27:53 +03:00
|
|
|
#endif
|
|
|
|
|
2018-04-05 20:53:56 +03:00
|
|
|
bool gfxPlatformGtk::CheckVariationFontSupport() {
|
|
|
|
// Although there was some variation/multiple-master support in FreeType
|
|
|
|
// in older versions, it seems too incomplete/unstable for us to use
|
|
|
|
// until at least 2.7.1.
|
|
|
|
FT_Int major, minor, patch;
|
2019-09-16 20:12:38 +03:00
|
|
|
FT_Library_Version(Factory::GetFTLibrary(), &major, &minor, &patch);
|
2018-04-05 20:53:56 +03:00
|
|
|
return major * 1000000 + minor * 1000 + patch >= 2007001;
|
|
|
|
}
|
2008-08-07 00:48:55 +04:00
|
|
|
|
2018-05-24 15:06:31 +03:00
|
|
|
#ifdef MOZ_X11
|
2016-05-09 18:35:58 +03:00
|
|
|
|
2018-06-29 14:15:41 +03:00
|
|
|
class GtkVsyncSource final : public VsyncSource {
|
2016-05-09 18:35:58 +03:00
|
|
|
public:
|
2018-06-29 14:15:41 +03:00
|
|
|
GtkVsyncSource() {
|
2016-05-09 18:35:58 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
mGlobalDisplay = new GLXDisplay();
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~GtkVsyncSource() { MOZ_ASSERT(NS_IsMainThread()); }
|
|
|
|
|
|
|
|
virtual Display& GetGlobalDisplay() override { return *mGlobalDisplay; }
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-05-09 18:35:58 +03:00
|
|
|
class GLXDisplay final : public VsyncSource::Display {
|
|
|
|
public:
|
|
|
|
GLXDisplay()
|
|
|
|
: mGLContext(nullptr),
|
2016-08-22 21:44:54 +03:00
|
|
|
mXDisplay(nullptr),
|
2016-05-09 18:35:58 +03:00
|
|
|
mSetupLock("GLXVsyncSetupLock"),
|
|
|
|
mVsyncThread("GLXVsyncThread"),
|
|
|
|
mVsyncTask(nullptr),
|
|
|
|
mVsyncEnabledLock("GLXVsyncEnabledLock"),
|
2019-11-27 03:21:33 +03:00
|
|
|
mVsyncEnabled(false) {}
|
2016-05-09 18:35:58 +03:00
|
|
|
|
|
|
|
// 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;
|
|
|
|
|
2017-06-12 22:34:10 +03:00
|
|
|
RefPtr<Runnable> vsyncSetup =
|
2018-06-29 14:15:41 +03:00
|
|
|
NewRunnableMethod("GtkVsyncSource::GLXDisplay::SetupGLContext", this,
|
2017-06-12 22:34:10 +03:00
|
|
|
&GLXDisplay::SetupGLContext);
|
2016-05-09 18:35:58 +03:00
|
|
|
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);
|
2016-08-22 21:44:54 +03:00
|
|
|
MOZ_ASSERT(!NS_IsMainThread());
|
|
|
|
MOZ_ASSERT(!mGLContext, "GLContext already setup!");
|
2016-05-09 18:35:58 +03:00
|
|
|
|
2017-03-15 23:14:03 +03:00
|
|
|
// Create video sync timer on a separate Display to prevent locking the
|
|
|
|
// main thread X display.
|
|
|
|
mXDisplay = XOpenDisplay(nullptr);
|
|
|
|
if (!mXDisplay) {
|
|
|
|
lock.NotifyAll();
|
2018-11-30 13:46:48 +03:00
|
|
|
return;
|
|
|
|
}
|
2016-05-09 18:35:58 +03:00
|
|
|
|
2016-06-11 08:27:29 +03:00
|
|
|
// Most compositors wait for vsync events on the root window.
|
|
|
|
Window root = DefaultRootWindow(mXDisplay);
|
|
|
|
int screen = DefaultScreen(mXDisplay);
|
|
|
|
|
2016-05-09 18:35:58 +03:00
|
|
|
ScopedXFree<GLXFBConfig> cfgs;
|
|
|
|
GLXFBConfig config;
|
|
|
|
int visid;
|
|
|
|
bool forWebRender = false;
|
|
|
|
if (!gl::GLContextGLX::FindFBConfigForWindow(
|
|
|
|
mXDisplay, screen, root, &cfgs, &config, &visid, forWebRender)) {
|
|
|
|
lock.NotifyAll();
|
|
|
|
return;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2016-05-09 18:35:58 +03:00
|
|
|
|
2021-07-06 10:42:42 +03:00
|
|
|
mGLContext = gl::GLContextGLX::CreateGLContext(
|
|
|
|
{}, gfx::XlibDisplay::Borrow(mXDisplay), root, config, false,
|
|
|
|
nullptr);
|
2016-05-09 18:35:58 +03:00
|
|
|
|
2016-06-11 08:27:29 +03:00
|
|
|
if (!mGLContext) {
|
2016-05-09 18:35:58 +03:00
|
|
|
lock.NotifyAll();
|
2018-11-30 13:46:48 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-05-09 18:35:58 +03:00
|
|
|
mGLContext->MakeCurrent();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-05-09 18:35:58 +03:00
|
|
|
// Test that SGI_video_sync lets us get the counter.
|
|
|
|
unsigned int syncCounter = 0;
|
2017-03-04 06:24:51 +03:00
|
|
|
if (gl::sGLXLibrary.fGetVideoSync(&syncCounter) != 0) {
|
2016-05-09 18:35:58 +03:00
|
|
|
mGLContext = nullptr;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2016-08-22 21:44:54 +03:00
|
|
|
lock.NotifyAll();
|
2016-05-09 18:35:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
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) {
|
2019-11-27 03:21:33 +03:00
|
|
|
mVsyncTask = NewRunnableMethod("GtkVsyncSource::GLXDisplay::RunVsync",
|
|
|
|
this, &GLXDisplay::RunVsync);
|
2016-05-09 18:35:58 +03:00
|
|
|
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.
|
2017-06-12 22:34:10 +03:00
|
|
|
RefPtr<Runnable> shutdownTask = NewRunnableMethod(
|
2018-06-29 14:15:41 +03:00
|
|
|
"GtkVsyncSource::GLXDisplay::Cleanup", this, &GLXDisplay::Cleanup);
|
2016-05-09 18:35:58 +03:00
|
|
|
mVsyncThread.message_loop()->PostTask(shutdownTask.forget());
|
|
|
|
|
|
|
|
// Stop, waiting for the cleanup task to finish execution.
|
|
|
|
mVsyncThread.Stop();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2019-04-11 15:36:51 +03:00
|
|
|
virtual ~GLXDisplay() = default;
|
2016-05-09 18:35:58 +03:00
|
|
|
|
|
|
|
void RunVsync() {
|
|
|
|
MOZ_ASSERT(!NS_IsMainThread());
|
|
|
|
|
|
|
|
mGLContext->MakeCurrent();
|
|
|
|
|
|
|
|
unsigned int syncCounter = 0;
|
2017-03-04 06:24:51 +03:00
|
|
|
gl::sGLXLibrary.fGetVideoSync(&syncCounter);
|
2016-05-09 18:35:58 +03:00
|
|
|
for (;;) {
|
|
|
|
{
|
|
|
|
MonitorAutoLock lock(mVsyncEnabledLock);
|
|
|
|
if (!mVsyncEnabled) {
|
|
|
|
mVsyncTask = nullptr;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TimeStamp lastVsync = TimeStamp::Now();
|
2016-06-14 15:19:43 +03:00
|
|
|
bool useSoftware = false;
|
|
|
|
|
2016-05-09 18:35:58 +03: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 15:19:43 +03:00
|
|
|
int status;
|
2021-04-29 13:43:17 +03:00
|
|
|
if ((status = gl::sGLXLibrary.fWaitVideoSync(2, (int)nextSync % 2,
|
2017-03-04 06:24:51 +03:00
|
|
|
&syncCounter)) != 0) {
|
2016-06-14 15:19:43 +03:00
|
|
|
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) {
|
2022-02-11 18:19:46 +03:00
|
|
|
AUTO_PROFILER_THREAD_SLEEP;
|
2021-04-29 13:43:17 +03:00
|
|
|
PlatformThread::Sleep((int)remaining);
|
2016-05-09 18:35:58 +03:00
|
|
|
}
|
|
|
|
}
|
2016-06-14 15:19:43 +03:00
|
|
|
|
|
|
|
lastVsync = TimeStamp::Now();
|
2020-07-18 08:34:35 +03:00
|
|
|
TimeStamp outputTime = lastVsync + GetVsyncRate();
|
|
|
|
NotifyVsync(lastVsync, outputTime);
|
2016-05-09 18:35:58 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Cleanup() {
|
|
|
|
MOZ_ASSERT(!NS_IsMainThread());
|
|
|
|
|
|
|
|
mGLContext = nullptr;
|
2018-06-29 14:15:41 +03:00
|
|
|
if (mXDisplay) XCloseDisplay(mXDisplay);
|
2016-05-09 18:35:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Owned by the vsync thread.
|
|
|
|
RefPtr<gl::GLContextGLX> mGLContext;
|
2016-08-22 21:44:54 +03:00
|
|
|
_XDisplay* mXDisplay;
|
2016-05-09 18:35:58 +03:00
|
|
|
Monitor mSetupLock;
|
|
|
|
base::Thread mVsyncThread;
|
|
|
|
RefPtr<Runnable> mVsyncTask;
|
|
|
|
Monitor mVsyncEnabledLock;
|
|
|
|
bool mVsyncEnabled;
|
|
|
|
};
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-05-09 18:35:58 +03:00
|
|
|
private:
|
|
|
|
// We need a refcounted VsyncSource::Display to use chromium IPC runnables.
|
|
|
|
RefPtr<GLXDisplay> mGlobalDisplay;
|
|
|
|
};
|
|
|
|
|
2021-10-23 14:19:10 +03:00
|
|
|
class XrandrSoftwareVsyncSource final : public SoftwareVsyncSource {
|
|
|
|
public:
|
|
|
|
XrandrSoftwareVsyncSource() : SoftwareVsyncSource(false) {
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
mGlobalDisplay = new XrandrSoftwareDisplay();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
class XrandrSoftwareDisplay final : public SoftwareDisplay {
|
|
|
|
public:
|
|
|
|
XrandrSoftwareDisplay() {
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
UpdateVsyncRate();
|
|
|
|
|
|
|
|
GdkScreen* defaultScreen = gdk_screen_get_default();
|
|
|
|
g_signal_connect(defaultScreen, "monitors-changed",
|
|
|
|
G_CALLBACK(monitors_changed), this);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2021-10-28 20:46:18 +03:00
|
|
|
// Request the current refresh rate via xrandr. It is hard to find the
|
|
|
|
// "correct" one, thus choose the highest one, assuming this will usually
|
|
|
|
// give the best user experience.
|
2021-10-23 14:19:10 +03:00
|
|
|
void UpdateVsyncRate() {
|
|
|
|
struct _XDisplay* dpy = gdk_x11_get_default_xdisplay();
|
|
|
|
|
|
|
|
// Use the default software refresh rate as lower bound. Allowing lower
|
|
|
|
// rates makes a bunch of tests start to fail on CI. The main goal of this
|
|
|
|
// VsyncSource is to support refresh rates greater than the default one.
|
|
|
|
double highestRefreshRate = gfxPlatform::GetSoftwareVsyncRate();
|
|
|
|
|
2021-10-28 20:46:18 +03:00
|
|
|
// When running on remote X11 the xrandr version may be stuck on an
|
|
|
|
// ancient version. There are still setups using remote X11 out there, so
|
|
|
|
// make sure we don't crash.
|
|
|
|
int eventBase, errorBase, major, minor;
|
|
|
|
if (XRRQueryExtension(dpy, &eventBase, &errorBase) &&
|
|
|
|
XRRQueryVersion(dpy, &major, &minor) &&
|
|
|
|
(major > 1 || (major == 1 && minor >= 3))) {
|
|
|
|
Window root = gdk_x11_get_default_root_xwindow();
|
|
|
|
XRRScreenResources* res = XRRGetScreenResourcesCurrent(dpy, root);
|
|
|
|
|
2021-10-28 20:46:18 +03:00
|
|
|
// We can't use refresh rates far below the default one (60Hz) because
|
|
|
|
// otherwise random CI tests start to fail. However, many users have
|
|
|
|
// screens just below the default rate, e.g. 59.95Hz. So slightly
|
|
|
|
// decrease the lower bound.
|
|
|
|
highestRefreshRate -= 1.0;
|
|
|
|
|
2021-10-28 20:46:18 +03:00
|
|
|
for (int i = 0; i < res->noutput; i++) {
|
|
|
|
XRROutputInfo* outputInfo =
|
|
|
|
XRRGetOutputInfo(dpy, res, res->outputs[i]);
|
|
|
|
if (!outputInfo->crtc) {
|
|
|
|
XRRFreeOutputInfo(outputInfo);
|
|
|
|
continue;
|
|
|
|
}
|
2021-10-23 14:19:10 +03:00
|
|
|
|
2021-10-28 20:46:18 +03:00
|
|
|
XRRCrtcInfo* crtcInfo = XRRGetCrtcInfo(dpy, res, outputInfo->crtc);
|
|
|
|
for (int j = 0; j < res->nmode; j++) {
|
|
|
|
if (res->modes[j].id == crtcInfo->mode) {
|
|
|
|
double refreshRate = mode_refresh(&res->modes[j]);
|
|
|
|
if (refreshRate > highestRefreshRate) {
|
|
|
|
highestRefreshRate = refreshRate;
|
|
|
|
}
|
|
|
|
break;
|
2021-10-23 14:19:10 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-28 20:46:18 +03:00
|
|
|
XRRFreeCrtcInfo(crtcInfo);
|
|
|
|
XRRFreeOutputInfo(outputInfo);
|
|
|
|
}
|
|
|
|
XRRFreeScreenResources(res);
|
2021-10-23 14:19:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
const double rate = 1000.0 / highestRefreshRate;
|
|
|
|
mVsyncRate = mozilla::TimeDuration::FromMilliseconds(rate);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void monitors_changed(GdkScreen* aScreen, gpointer aClosure) {
|
|
|
|
XrandrSoftwareDisplay* self =
|
|
|
|
static_cast<XrandrSoftwareDisplay*>(aClosure);
|
|
|
|
self->UpdateVsyncRate();
|
|
|
|
}
|
|
|
|
|
|
|
|
// from xrandr.c
|
|
|
|
static double mode_refresh(const XRRModeInfo* mode_info) {
|
|
|
|
double rate;
|
|
|
|
double vTotal = mode_info->vTotal;
|
|
|
|
|
|
|
|
if (mode_info->modeFlags & RR_DoubleScan) {
|
|
|
|
/* doublescan doubles the number of lines */
|
|
|
|
vTotal *= 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mode_info->modeFlags & RR_Interlace) {
|
|
|
|
/* interlace splits the frame into two fields */
|
|
|
|
/* the field rate is what is typically reported by monitors */
|
|
|
|
vTotal /= 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mode_info->hTotal && vTotal) {
|
|
|
|
rate = ((double)mode_info->dotClock /
|
|
|
|
((double)mode_info->hTotal * (double)vTotal));
|
|
|
|
} else {
|
|
|
|
rate = 0;
|
|
|
|
}
|
|
|
|
return rate;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2016-05-09 18:35:58 +03:00
|
|
|
already_AddRefed<gfx::VsyncSource> gfxPlatformGtk::CreateHardwareVsyncSource() {
|
2021-10-23 14:19:10 +03:00
|
|
|
if (IsHeadless() || IsWaylandDisplay()) {
|
|
|
|
// On Wayland we can not create a global hardware based vsync source, thus
|
|
|
|
// use a software based one here. We create window specific ones later.
|
2019-11-27 03:21:33 +03:00
|
|
|
return gfxPlatform::CreateHardwareVsyncSource();
|
2018-06-29 14:15:41 +03:00
|
|
|
}
|
2021-10-23 14:19:10 +03:00
|
|
|
|
|
|
|
nsCOMPtr<nsIGfxInfo> gfxInfo = components::GfxInfo::Service();
|
|
|
|
nsString windowProtocol;
|
|
|
|
gfxInfo->GetWindowProtocol(windowProtocol);
|
|
|
|
bool isXwayland = windowProtocol.Find("xwayland") != -1;
|
|
|
|
nsString adapterDriverVendor;
|
|
|
|
gfxInfo->GetAdapterDriverVendor(adapterDriverVendor);
|
|
|
|
bool isMesa = adapterDriverVendor.Find("mesa") != -1;
|
2018-06-29 14:15:41 +03:00
|
|
|
|
2021-07-06 10:42:42 +03:00
|
|
|
// Only use GLX vsync when the OpenGL compositor / WebRender is being used.
|
2021-10-23 14:19:10 +03:00
|
|
|
// The extra cost of initializing a GLX context while blocking the main thread
|
|
|
|
// is not worth it when using basic composition. Do not use it on Xwayland, as
|
|
|
|
// Xwayland will give us a software timer as we are listening for the root
|
|
|
|
// window, which does not have a Wayland equivalent. Don't call
|
|
|
|
// gl::sGLXLibrary.SupportsVideoSync() when EGL is used as NVIDIA drivers
|
|
|
|
// refuse to use EGL GL context when GLX was initialized first and fail
|
|
|
|
// silently.
|
|
|
|
if (gfxConfig::IsEnabled(Feature::HW_COMPOSITING) && !isXwayland &&
|
|
|
|
(!gfxVars::UseEGL() || isMesa) &&
|
|
|
|
gl::sGLXLibrary.SupportsVideoSync(DefaultXDisplay())) {
|
|
|
|
RefPtr<VsyncSource> vsyncSource = new GtkVsyncSource();
|
|
|
|
VsyncSource::Display& display = vsyncSource->GetGlobalDisplay();
|
|
|
|
if (!static_cast<GtkVsyncSource::GLXDisplay&>(display).Setup()) {
|
|
|
|
NS_WARNING("Failed to setup GLContext, falling back to software vsync.");
|
|
|
|
return gfxPlatform::CreateHardwareVsyncSource();
|
2016-06-21 22:51:34 +03:00
|
|
|
}
|
2021-10-23 14:19:10 +03:00
|
|
|
return vsyncSource.forget();
|
2016-05-09 18:35:58 +03:00
|
|
|
}
|
2021-10-23 09:42:25 +03:00
|
|
|
|
2021-10-23 14:19:10 +03:00
|
|
|
RefPtr<VsyncSource> softwareVsync = new XrandrSoftwareVsyncSource();
|
|
|
|
return softwareVsync.forget();
|
|
|
|
}
|
2016-05-09 18:35:58 +03:00
|
|
|
#endif
|
2021-09-14 19:01:08 +03:00
|
|
|
|
|
|
|
void gfxPlatformGtk::BuildContentDeviceData(ContentDeviceData* aOut) {
|
|
|
|
gfxPlatform::BuildContentDeviceData(aOut);
|
|
|
|
|
|
|
|
aOut->cmsOutputProfileData() = GetPlatformCMSOutputProfileData();
|
|
|
|
}
|