1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #include "mozilla/FontPropertyTypes.h"
7 #include "mozilla/RDDProcessManager.h"
8 #include "mozilla/image/ImageMemoryReporter.h"
9 #include "mozilla/layers/CompositorManagerChild.h"
10 #include "mozilla/layers/CompositorThread.h"
11 #include "mozilla/layers/ImageBridgeChild.h"
12 #include "mozilla/layers/ISurfaceAllocator.h" // for GfxMemoryImageReporter
13 #include "mozilla/layers/CompositorBridgeChild.h"
14 #include "mozilla/layers/RemoteTextureMap.h"
15 #include "mozilla/layers/VideoBridgeParent.h"
16 #include "mozilla/webrender/RenderThread.h"
17 #include "mozilla/webrender/WebRenderAPI.h"
18 #include "mozilla/webrender/webrender_ffi.h"
19 #include "mozilla/gfx/BuildConstants.h"
20 #include "mozilla/gfx/gfxConfigManager.h"
21 #include "mozilla/gfx/gfxVars.h"
22 #include "mozilla/gfx/GPUProcessManager.h"
23 #include "mozilla/gfx/GraphicsMessages.h"
24 #include "mozilla/gfx/CanvasRenderThread.h"
25 #include "mozilla/gfx/CanvasShutdownManager.h"
26 #include "mozilla/ClearOnShutdown.h"
27 #include "mozilla/DebugOnly.h"
28 #include "mozilla/EnumTypeTraits.h"
29 #include "mozilla/StaticPrefs_accessibility.h"
30 #include "mozilla/StaticPrefs_apz.h"
31 #include "mozilla/StaticPrefs_bidi.h"
32 #include "mozilla/StaticPrefs_gfx.h"
33 #include "mozilla/StaticPrefs_layout.h"
34 #include "mozilla/StaticPrefs_layers.h"
35 #include "mozilla/StaticPrefs_media.h"
36 #include "mozilla/StaticPrefs_privacy.h"
37 #include "mozilla/StaticPrefs_webgl.h"
38 #include "mozilla/StaticPrefs_widget.h"
39 #include "mozilla/Telemetry.h"
40 #include "mozilla/glean/GleanMetrics.h"
41 #include "mozilla/TimeStamp.h"
42 #include "mozilla/Unused.h"
43 #include "mozilla/IntegerPrintfMacros.h"
44 #include "mozilla/Base64.h"
45 #include "mozilla/VsyncDispatcher.h"
47 #include "mozilla/Logging.h"
48 #include "mozilla/Components.h"
49 #include "nsAppRunner.h"
50 #include "nsAppDirectoryServiceDefs.h"
51 #include "nsCSSProps.h"
52 #include "nsContentUtils.h"
54 #include "gfxCrashReporterUtils.h"
55 #include "gfxPlatform.h"
56 #include "gfxPlatformWorker.h"
60 #include "gfxTextRun.h"
61 #include "gfxUserFontSet.h"
62 #include "gfxConfig.h"
63 #include "GfxDriverInfo.h"
64 #include "VRProcessManager.h"
69 # define getpid _getpid
74 #include "nsXULAppAPI.h"
75 #include "nsIXULAppInfo.h"
76 #include "nsDirectoryServiceUtils.h"
77 #include "nsDirectoryServiceDefs.h"
80 # include "gfxWindowsPlatform.h"
81 # include "mozilla/widget/WinWindowOcclusionTracker.h"
82 #elif defined(XP_DARWIN)
83 # include "gfxPlatformMac.h"
84 # include "gfxQuartzSurface.h"
85 #elif defined(MOZ_WIDGET_GTK)
86 # include "gfxPlatformGtk.h"
87 #elif defined(ANDROID)
88 # include "gfxAndroidPlatform.h"
90 #if defined(MOZ_WIDGET_ANDROID)
91 # include "mozilla/jni/Utils.h" // for IsFennec
95 # include "mozilla/WindowsVersion.h"
96 # include "WinUtils.h"
99 #include "nsGkAtoms.h"
100 #include "gfxPlatformFontList.h"
101 #include "gfxContext.h"
102 #include "gfxImageSurface.h"
103 #include "nsUnicodeProperties.h"
104 #include "harfbuzz/hb.h"
105 #include "gfxGraphiteShaper.h"
106 #include "gfx2DGlue.h"
107 #include "gfxGradientCache.h"
108 #include "gfxUtils.h" // for NextPowerOfTwo
109 #include "gfxFontMissingGlyphs.h"
111 #include "nsExceptionHandler.h"
112 #include "nsServiceManagerUtils.h"
113 #include "nsTArray.h"
114 #include "nsIObserverService.h"
115 #include "mozilla/widget/Screen.h"
116 #include "mozilla/widget/ScreenManager.h"
117 #include "MainThreadUtils.h"
119 #include "nsWeakReference.h"
124 #include "imgITools.h"
127 #include "GLContext.h"
128 #include "GLContextProvider.h"
129 #include "mozilla/gfx/Logging.h"
132 # pragma GCC diagnostic push
133 # pragma GCC diagnostic ignored "-Wshadow"
135 #include "skia/include/core/SkGraphics.h"
136 #ifdef MOZ_ENABLE_FREETYPE
137 # include "skia/include/ports/SkTypeface_cairo.h"
139 #include "mozilla/gfx/SkMemoryReporter.h"
141 # pragma GCC diagnostic pop // -Wshadow
143 static const uint32_t kDefaultGlyphCacheSize
= -1;
145 #include "mozilla/Preferences.h"
146 #include "mozilla/Assertions.h"
147 #include "mozilla/Atomics.h"
148 #include "mozilla/Attributes.h"
149 #include "mozilla/Mutex.h"
151 #include "nsAlgorithm.h"
152 #include "nsIGfxInfo.h"
153 #include "nsIXULRuntime.h"
154 #include "VsyncSource.h"
155 #include "SoftwareVsyncSource.h"
156 #include "nscore.h" // for NS_FREE_PERMANENT_DATA
157 #include "mozilla/dom/ContentChild.h"
158 #include "mozilla/dom/ContentParent.h"
159 #include "mozilla/dom/TouchEvent.h"
161 #include "VRManager.h"
162 #include "VRManagerChild.h"
163 #include "mozilla/gfx/GPUParent.h"
164 #include "prsystem.h"
166 #include "mozilla/gfx/2D.h"
167 #include "mozilla/gfx/SourceSurfaceCairo.h"
169 using namespace mozilla
;
170 using namespace mozilla::layers
;
171 using namespace mozilla::gl
;
172 using namespace mozilla::gfx
;
174 gfxPlatform
* gPlatform
= nullptr;
175 static bool gEverInitialized
= false;
177 const ContentDeviceData
* gContentDeviceInitData
= nullptr;
178 Maybe
<nsTArray
<uint8_t>> gCMSOutputProfileData
;
180 Atomic
<bool, MemoryOrdering::ReleaseAcquire
> gfxPlatform::gCMSInitialized
;
181 CMSMode
gfxPlatform::gCMSMode
= CMSMode::Off
;
183 // These two may point to the same profile
184 qcms_profile
* gfxPlatform::gCMSOutputProfile
= nullptr;
185 qcms_profile
* gfxPlatform::gCMSsRGBProfile
= nullptr;
187 qcms_transform
* gfxPlatform::gCMSRGBTransform
= nullptr;
188 qcms_transform
* gfxPlatform::gCMSInverseRGBTransform
= nullptr;
189 qcms_transform
* gfxPlatform::gCMSRGBATransform
= nullptr;
190 qcms_transform
* gfxPlatform::gCMSBGRATransform
= nullptr;
192 /// This override of the LogForwarder, initially used for the critical graphics
193 /// errors, is sending the log to the crash annotations as well, but only
194 /// if the capacity set with the method below is >= 2. We always retain the
195 /// very first critical message, and the latest capacity-1 messages are
196 /// rotated through. Note that we don't expect the total number of times
197 /// this gets called to be large - it is meant for critical errors only.
199 class CrashStatsLogForwarder
: public mozilla::gfx::LogForwarder
{
201 explicit CrashStatsLogForwarder(CrashReporter::Annotation aKey
);
202 void Log(const std::string
& aString
) override
;
203 void CrashAction(LogReason aReason
) override
;
204 bool UpdateStringsVector(const std::string
& aString
) override
;
206 LoggingRecord
LoggingRecordCopy() override
;
208 void SetCircularBufferSize(uint32_t aCapacity
);
211 // Helper for the Log()
212 void UpdateCrashReport();
215 LoggingRecord mBuffer
;
216 CrashReporter::Annotation mCrashCriticalKey
;
217 uint32_t mMaxCapacity
;
219 Mutex mMutex MOZ_UNANNOTATED
;
222 CrashStatsLogForwarder::CrashStatsLogForwarder(CrashReporter::Annotation aKey
)
223 : mCrashCriticalKey(aKey
),
226 mMutex("CrashStatsLogForwarder") {}
228 void CrashStatsLogForwarder::SetCircularBufferSize(uint32_t aCapacity
) {
229 MutexAutoLock
lock(mMutex
);
231 mMaxCapacity
= aCapacity
;
232 mBuffer
.reserve(static_cast<size_t>(aCapacity
));
235 LoggingRecord
CrashStatsLogForwarder::LoggingRecordCopy() {
236 MutexAutoLock
lock(mMutex
);
240 bool CrashStatsLogForwarder::UpdateStringsVector(const std::string
& aString
) {
241 // We want at least the first one and the last one. Otherwise, no point.
242 if (mMaxCapacity
< 2) {
247 MOZ_ASSERT(mIndex
>= 0);
249 // index will count 0, 1, 2, ..., max-1, 1, 2, ..., max-1, 1, 2, ...
250 int32_t index
= mIndex
? (mIndex
- 1) % (mMaxCapacity
- 1) + 1 : 0;
251 MOZ_ASSERT(index
>= 0 && index
< (int32_t)mMaxCapacity
);
252 MOZ_ASSERT(index
<= mIndex
&& index
<= (int32_t)mBuffer
.size());
254 double tStamp
= (TimeStamp::NowLoRes() - TimeStamp::ProcessCreation())
255 .ToSecondsSigDigits();
257 // Checking for index >= mBuffer.size(), rather than index == mBuffer.size()
258 // just out of paranoia, but we know index <= mBuffer.size().
259 LoggingRecordEntry
newEntry(mIndex
, aString
, tStamp
);
260 if (index
>= static_cast<int32_t>(mBuffer
.size())) {
261 mBuffer
.push_back(newEntry
);
263 mBuffer
[index
] = newEntry
;
268 void CrashStatsLogForwarder::UpdateCrashReport() {
269 std::stringstream message
;
270 std::string logAnnotation
;
272 switch (XRE_GetProcessType()) {
273 case GeckoProcessType_Default
:
274 logAnnotation
= "|[";
276 case GeckoProcessType_Content
:
277 logAnnotation
= "|[C";
279 case GeckoProcessType_GPU
:
280 logAnnotation
= "|[G";
283 logAnnotation
= "|[X";
287 for (auto& it
: mBuffer
) {
288 message
<< logAnnotation
<< std::get
<0>(it
) << "]" << std::get
<1>(it
)
289 << " (t=" << std::get
<2>(it
) << ") ";
292 nsresult annotated
= CrashReporter::RecordAnnotationCString(
293 mCrashCriticalKey
, message
.str().c_str());
295 if (annotated
!= NS_OK
) {
296 printf("Crash Annotation %s: %s",
297 CrashReporter::AnnotationToString(mCrashCriticalKey
),
298 message
.str().c_str());
302 class LogForwarderEvent
: public Runnable
{
303 virtual ~LogForwarderEvent() = default;
306 NS_INLINE_DECL_REFCOUNTING_INHERITED(LogForwarderEvent
, Runnable
)
308 explicit LogForwarderEvent(const nsCString
& aMessage
)
309 : mozilla::Runnable("LogForwarderEvent"), mMessage(aMessage
) {}
311 NS_IMETHOD
Run() override
{
312 MOZ_ASSERT(NS_IsMainThread() &&
313 (XRE_IsContentProcess() || XRE_IsGPUProcess()));
315 if (XRE_IsContentProcess()) {
316 dom::ContentChild
* cc
= dom::ContentChild::GetSingleton();
317 Unused
<< cc
->SendGraphicsError(mMessage
);
318 } else if (XRE_IsGPUProcess()) {
319 GPUParent
* gp
= GPUParent::GetSingleton();
320 Unused
<< gp
->SendGraphicsError(mMessage
);
330 void CrashStatsLogForwarder::Log(const std::string
& aString
) {
331 MutexAutoLock
lock(mMutex
);
333 if (UpdateStringsVector(aString
)) {
337 // Add it to the parent strings
338 if (!XRE_IsParentProcess()) {
339 nsCString
stringToSend(aString
.c_str());
340 if (NS_IsMainThread()) {
341 if (XRE_IsContentProcess()) {
342 dom::ContentChild
* cc
= dom::ContentChild::GetSingleton();
343 Unused
<< cc
->SendGraphicsError(stringToSend
);
344 } else if (XRE_IsGPUProcess()) {
345 GPUParent
* gp
= GPUParent::GetSingleton();
346 Unused
<< gp
->SendGraphicsError(stringToSend
);
349 nsCOMPtr
<nsIRunnable
> r1
= new LogForwarderEvent(stringToSend
);
350 NS_DispatchToMainThread(r1
);
355 class CrashTelemetryEvent
: public Runnable
{
356 virtual ~CrashTelemetryEvent() = default;
359 NS_INLINE_DECL_REFCOUNTING_INHERITED(CrashTelemetryEvent
, Runnable
)
361 explicit CrashTelemetryEvent(uint32_t aReason
)
362 : mozilla::Runnable("CrashTelemetryEvent"), mReason(aReason
) {}
364 NS_IMETHOD
Run() override
{
365 MOZ_ASSERT(NS_IsMainThread());
366 Telemetry::Accumulate(Telemetry::GFX_CRASH
, mReason
);
374 void CrashStatsLogForwarder::CrashAction(LogReason aReason
) {
375 #ifndef RELEASE_OR_BETA
376 // Non-release builds crash by default, but will use telemetry
377 // if this environment variable is present.
378 static bool useTelemetry
= gfxEnv::MOZ_GFX_CRASH_TELEMETRY();
380 // Release builds use telemetry by default, but will crash instead
381 // if this environment variable is present.
382 static bool useTelemetry
= !gfxEnv::MOZ_GFX_CRASH_MOZ_CRASH();
386 // The callers need to assure that aReason is in the range
387 // that the telemetry call below supports.
388 if (NS_IsMainThread()) {
389 Telemetry::Accumulate(Telemetry::GFX_CRASH
, (uint32_t)aReason
);
391 nsCOMPtr
<nsIRunnable
> r1
= new CrashTelemetryEvent((uint32_t)aReason
);
392 NS_DispatchToMainThread(r1
);
395 // ignoring aReason, we can get the information we need from the stack
396 MOZ_CRASH("GFX_CRASH");
400 #define GFX_DOWNLOADABLE_FONTS_ENABLED "gfx.downloadable_fonts.enabled"
402 #define GFX_PREF_FALLBACK_USE_CMAPS \
403 "gfx.font_rendering.fallback.always_use_cmaps"
405 #define GFX_PREF_OPENTYPE_SVG "gfx.font_rendering.opentype_svg.enabled"
407 #define GFX_PREF_WORD_CACHE_CHARLIMIT "gfx.font_rendering.wordcache.charlimit"
408 #define GFX_PREF_WORD_CACHE_MAXENTRIES "gfx.font_rendering.wordcache.maxentries"
410 #define GFX_PREF_GRAPHITE_SHAPING "gfx.font_rendering.graphite.enabled"
411 #if defined(XP_DARWIN)
412 # define GFX_PREF_CORETEXT_SHAPING "gfx.font_rendering.coretext.enabled"
415 #define FONT_VARIATIONS_PREF "layout.css.font-variations.enabled"
417 static const char* kObservedPrefs
[] = {"gfx.downloadable_fonts.",
418 "gfx.font_rendering.", nullptr};
420 static void FontPrefChanged(const char* aPref
, void* aData
) {
422 NS_ASSERTION(gfxPlatform::GetPlatform(), "the singleton instance has gone");
423 gfxPlatform::GetPlatform()->FontsPrefsChanged(aPref
);
426 void gfxPlatform::OnMemoryPressure(layers::MemoryPressureReason aWhy
) {
427 Factory::PurgeAllCaches();
428 gfxGradientCache::PurgeAllCaches();
429 gfxFontMissingGlyphs::Purge();
430 PurgeSkiaFontCache();
431 if (XRE_IsParentProcess()) {
432 layers::CompositorManagerChild
* manager
=
433 CompositorManagerChild::GetInstance();
435 manager
->SendNotifyMemoryPressure();
440 gfxPlatform::gfxPlatform()
441 : mAzureCanvasBackendCollector(this, &gfxPlatform::GetAzureBackendInfo
),
442 mApzSupportCollector(this, &gfxPlatform::GetApzSupportInfo
),
443 mFrameStatsCollector(this, &gfxPlatform::GetFrameStats
),
444 mCMSInfoCollector(this, &gfxPlatform::GetCMSSupportInfo
),
445 mDisplayInfoCollector(this, &gfxPlatform::GetDisplayInfo
),
446 mOverlayInfoCollector(this, &gfxPlatform::GetOverlayInfo
),
447 mSwapChainInfoCollector(this, &gfxPlatform::GetSwapChainInfo
),
448 mCompositorBackend(layers::LayersBackend::LAYERS_NONE
) {
449 mAllowDownloadableFonts
= UNINITIALIZED_VALUE
;
451 InitBackendPrefs(GetBackendPrefs());
452 VRManager::ManagerInit();
455 gfxPlatform
* gfxPlatform::GetPlatform() {
457 MOZ_RELEASE_ASSERT(!XRE_IsContentProcess(),
458 "Content Process should have called InitChild() before "
459 "first GetPlatform()");
465 bool gfxPlatform::Initialized() { return !!gPlatform
; }
468 void gfxPlatform::InitChild(const ContentDeviceData
& aData
) {
469 MOZ_ASSERT(XRE_IsContentProcess());
470 MOZ_ASSERT(!gPlatform
,
471 "InitChild() should be called before first GetPlatform()");
472 // Make the provided initial ContentDeviceData available to the init
474 gContentDeviceInitData
= &aData
;
476 gContentDeviceInitData
= nullptr;
479 #define WR_DEBUG_PREF "gfx.webrender.debug"
481 static void SwapIntervalPrefChangeCallback(const char* aPrefName
, void*) {
482 bool egl
= Preferences::GetBool("gfx.swap-interval.egl", false);
483 bool glx
= Preferences::GetBool("gfx.swap-interval.glx", false);
484 gfxVars::SetSwapIntervalEGL(egl
);
485 gfxVars::SetSwapIntervalGLX(glx
);
488 static void WebRendeProfilerUIPrefChangeCallback(const char* aPrefName
, void*) {
490 if (NS_SUCCEEDED(Preferences::GetCString("gfx.webrender.debug.profiler-ui",
492 gfxVars::SetWebRenderProfilerUI(uiString
);
496 // List of boolean dynamic parameter for WebRender.
498 // The parameters in this list are:
500 // - The BoolParameter enum variant (see webrender_api/src/lib.rs)
501 // - A default value.
502 #define WR_BOOL_PARAMETER_LIST(_) \
503 _("gfx.webrender.batched-texture-uploads", \
504 wr::BoolParameter::BatchedUploads, true) \
505 _("gfx.webrender.draw-calls-for-texture-copy", \
506 wr::BoolParameter::DrawCallsForTextureCopy, true) \
507 _("gfx.webrender.pbo-uploads", wr::BoolParameter::PboUploads, true) \
508 _("gfx.webrender.multithreading", wr::BoolParameter::Multithreading, true)
510 static void WebRenderBoolParameterChangeCallback(const char*, void*) {
513 #define WR_BOOL_PARAMETER(name, key, default_val) \
514 if (Preferences::GetBool(name, default_val)) { \
515 bits |= 1 << (uint32_t)key; \
518 WR_BOOL_PARAMETER_LIST(WR_BOOL_PARAMETER
)
519 #undef WR_BOOL_PARAMETER
521 gfx::gfxVars::SetWebRenderBoolParameters(bits
);
524 static void RegisterWebRenderBoolParamCallback() {
525 #define WR_BOOL_PARAMETER(name, _key, _default_val) \
526 Preferences::RegisterCallback(WebRenderBoolParameterChangeCallback, name);
528 WR_BOOL_PARAMETER_LIST(WR_BOOL_PARAMETER
)
529 #undef WR_BOOL_PARAMETER
531 WebRenderBoolParameterChangeCallback(nullptr, nullptr);
534 static void WebRenderDebugPrefChangeCallback(const char* aPrefName
, void*) {
535 wr::DebugFlags flags
{0};
536 #define GFX_WEBRENDER_DEBUG(suffix, bit) \
537 if (Preferences::GetBool(WR_DEBUG_PREF suffix, false)) { \
541 GFX_WEBRENDER_DEBUG(".profiler", wr::DebugFlags::PROFILER_DBG
)
542 GFX_WEBRENDER_DEBUG(".render-targets", wr::DebugFlags::RENDER_TARGET_DBG
)
543 GFX_WEBRENDER_DEBUG(".texture-cache", wr::DebugFlags::TEXTURE_CACHE_DBG
)
544 GFX_WEBRENDER_DEBUG(".gpu-time-queries", wr::DebugFlags::GPU_TIME_QUERIES
)
545 GFX_WEBRENDER_DEBUG(".gpu-sample-queries", wr::DebugFlags::GPU_SAMPLE_QUERIES
)
546 GFX_WEBRENDER_DEBUG(".disable-batching", wr::DebugFlags::DISABLE_BATCHING
)
547 GFX_WEBRENDER_DEBUG(".epochs", wr::DebugFlags::EPOCHS
)
548 GFX_WEBRENDER_DEBUG(".smart-profiler", wr::DebugFlags::SMART_PROFILER
)
549 GFX_WEBRENDER_DEBUG(".echo-driver-messages",
550 wr::DebugFlags::ECHO_DRIVER_MESSAGES
)
551 GFX_WEBRENDER_DEBUG(".show-overdraw", wr::DebugFlags::SHOW_OVERDRAW
)
552 GFX_WEBRENDER_DEBUG(".gpu-cache", wr::DebugFlags::GPU_CACHE_DBG
)
553 GFX_WEBRENDER_DEBUG(".texture-cache.clear-evicted",
554 wr::DebugFlags::TEXTURE_CACHE_DBG_CLEAR_EVICTED
)
555 GFX_WEBRENDER_DEBUG(".picture-caching", wr::DebugFlags::PICTURE_CACHING_DBG
)
556 GFX_WEBRENDER_DEBUG(".force-picture-invalidation",
557 wr::DebugFlags::FORCE_PICTURE_INVALIDATION
)
558 GFX_WEBRENDER_DEBUG(".primitives", wr::DebugFlags::PRIMITIVE_DBG
)
559 // Bit 18 is for the zoom display, which requires the mouse position and thus
560 // currently only works in wrench.
561 GFX_WEBRENDER_DEBUG(".small-screen", wr::DebugFlags::SMALL_SCREEN
)
562 GFX_WEBRENDER_DEBUG(".disable-opaque-pass",
563 wr::DebugFlags::DISABLE_OPAQUE_PASS
)
564 GFX_WEBRENDER_DEBUG(".disable-alpha-pass", wr::DebugFlags::DISABLE_ALPHA_PASS
)
565 GFX_WEBRENDER_DEBUG(".disable-clip-masks", wr::DebugFlags::DISABLE_CLIP_MASKS
)
566 GFX_WEBRENDER_DEBUG(".disable-text-prims", wr::DebugFlags::DISABLE_TEXT_PRIMS
)
567 GFX_WEBRENDER_DEBUG(".disable-gradient-prims",
568 wr::DebugFlags::DISABLE_GRADIENT_PRIMS
)
569 GFX_WEBRENDER_DEBUG(".obscure-images", wr::DebugFlags::OBSCURE_IMAGES
)
570 GFX_WEBRENDER_DEBUG(".glyph-flashing", wr::DebugFlags::GLYPH_FLASHING
)
571 GFX_WEBRENDER_DEBUG(".capture-profiler", wr::DebugFlags::PROFILER_CAPTURE
)
572 GFX_WEBRENDER_DEBUG(".window-visibility",
573 wr::DebugFlags::WINDOW_VISIBILITY_DBG
)
574 GFX_WEBRENDER_DEBUG(".restrict-blob-size", wr::DebugFlags::RESTRICT_BLOB_SIZE
)
575 #undef GFX_WEBRENDER_DEBUG
576 gfx::gfxVars::SetWebRenderDebugFlags(flags
._0
);
579 static void WebRenderQualityPrefChangeCallback(const char* aPref
, void*) {
580 gfxPlatform::GetPlatform()->UpdateForceSubpixelAAWherePossible();
583 static void WebRenderBatchingPrefChangeCallback(const char* aPrefName
, void*) {
584 uint32_t count
= Preferences::GetUint(
585 StaticPrefs::GetPrefName_gfx_webrender_batching_lookback(), 10);
587 gfx::gfxVars::SetWebRenderBatchingLookback(count
);
590 static void WebRenderBlobTileSizePrefChangeCallback(const char* aPrefName
,
592 uint32_t tileSize
= Preferences::GetUint(
593 StaticPrefs::GetPrefName_gfx_webrender_blob_tile_size(), 256);
594 gfx::gfxVars::SetWebRenderBlobTileSize(tileSize
);
597 static void WebRenderUploadThresholdPrefChangeCallback(const char* aPrefName
,
599 int value
= Preferences::GetInt(
600 StaticPrefs::GetPrefName_gfx_webrender_batched_upload_threshold(),
603 gfxVars::SetWebRenderBatchedUploadThreshold(value
);
606 static uint32_t GetSkiaGlyphCacheSize() {
607 // Only increase font cache size on non-android to save memory.
608 #if !defined(MOZ_WIDGET_ANDROID)
609 // 10mb as the default pref cache size on desktop due to talos perf tweaking.
610 // Chromium uses 20mb and skia default uses 2mb.
611 // We don't need to change the font cache count since we usually
612 // cache thrash due to asian character sets in talos.
613 // Only increase memory on the content process
615 StaticPrefs::gfx_content_skia_font_cache_size_AtStartup() * 1024 * 1024;
616 if (mozilla::BrowserTabsRemoteAutostart()) {
617 return XRE_IsContentProcess() ? cacheSize
: kDefaultGlyphCacheSize
;
622 return kDefaultGlyphCacheSize
;
623 #endif // MOZ_WIDGET_ANDROID
626 class WebRenderMemoryReporter final
: public nsIMemoryReporter
{
629 NS_DECL_NSIMEMORYREPORTER
632 ~WebRenderMemoryReporter() = default;
635 // Memory reporter for WebRender.
637 // The reporting within WebRender is manual and incomplete. We could do a much
638 // more thorough job by depending on the malloc_size_of crate, but integrating
639 // that into WebRender is tricky [1].
641 // So the idea is to start with manual reporting for the large allocations
642 // detected by DMD, and see how much that can cover in practice (which may
643 // require a few rounds of iteration). If that approach turns out to be
644 // fundamentally insufficient, we can either duplicate more of the
645 // malloc_size_of functionality in WebRender, or deal with the complexity of a
646 // gecko-only crate dependency.
648 // [1] See https://bugzilla.mozilla.org/show_bug.cgi?id=1480293#c1
649 struct WebRenderMemoryReporterHelper
{
650 WebRenderMemoryReporterHelper(nsIHandleReportCallback
* aCallback
,
652 : mCallback(aCallback
), mData(aData
) {}
653 nsCOMPtr
<nsIHandleReportCallback
> mCallback
;
654 nsCOMPtr
<nsISupports
> mData
;
656 void Report(size_t aBytes
, const char* aName
) const {
657 nsPrintfCString
path("explicit/gfx/webrender/%s", aName
);
658 nsCString
desc("CPU heap memory used by WebRender"_ns
);
659 ReportInternal(aBytes
, path
, desc
, nsIMemoryReporter::KIND_HEAP
);
662 void ReportTexture(size_t aBytes
, const char* aName
) const {
663 nsPrintfCString
path("gfx/webrender/textures/%s", aName
);
664 nsCString
desc("GPU texture memory used by WebRender"_ns
);
665 ReportInternal(aBytes
, path
, desc
, nsIMemoryReporter::KIND_OTHER
);
668 void ReportTotalGPUBytes(size_t aBytes
) const {
669 nsCString
path("gfx/webrender/total-gpu-bytes"_ns
);
670 nsCString
desc(nsLiteralCString(
671 "Total GPU bytes used by WebRender (should match textures/ sum)"));
672 ReportInternal(aBytes
, path
, desc
, nsIMemoryReporter::KIND_OTHER
);
675 void ReportInternal(size_t aBytes
, nsACString
& aPath
, nsACString
& aDesc
,
676 int32_t aKind
) const {
677 // Generally, memory reporters pass the empty string as the process name to
678 // indicate "current process". However, if we're using a GPU process, the
679 // measurements will actually take place in that process, and it's easier to
680 // just note that here rather than trying to invoke the memory reporter in
682 nsAutoCString processName
;
683 if (gfxConfig::IsEnabled(Feature::GPU_PROCESS
)) {
684 GPUParent::GetGPUProcessName(processName
);
687 mCallback
->Callback(processName
, aPath
, aKind
,
688 nsIMemoryReporter::UNITS_BYTES
, aBytes
, aDesc
, mData
);
692 static void FinishAsyncMemoryReport() {
693 nsCOMPtr
<nsIMemoryReporterManager
> imgr
=
694 do_GetService("@mozilla.org/memory-reporter-manager;1");
701 // (For some reason, clang-format gets the second macro right, but totally mangles the first).
702 #define REPORT_INTERNER(id) \
703 helper.Report(aReport.interning.interners.id, \
704 "interning/" #id "/interners");
707 #define REPORT_DATA_STORE(id) \
708 helper.Report(aReport.interning.data_stores.id, \
709 "interning/" #id "/data-stores");
711 NS_IMPL_ISUPPORTS(WebRenderMemoryReporter
, nsIMemoryReporter
)
714 WebRenderMemoryReporter::CollectReports(nsIHandleReportCallback
* aHandleReport
,
715 nsISupports
* aData
, bool aAnonymize
) {
716 MOZ_ASSERT(XRE_IsParentProcess());
717 MOZ_ASSERT(NS_IsMainThread());
718 layers::CompositorManagerChild
* manager
=
719 CompositorManagerChild::GetInstance();
721 FinishAsyncMemoryReport();
725 WebRenderMemoryReporterHelper
helper(aHandleReport
, aData
);
726 manager
->SendReportMemory(
727 [=](wr::MemoryReport aReport
) {
729 helper
.Report(aReport
.clip_stores
, "clip-stores");
730 helper
.Report(aReport
.gpu_cache_metadata
, "gpu-cache/metadata");
731 helper
.Report(aReport
.gpu_cache_cpu_mirror
, "gpu-cache/cpu-mirror");
732 helper
.Report(aReport
.render_tasks
, "render-tasks");
733 helper
.Report(aReport
.hit_testers
, "hit-testers");
734 helper
.Report(aReport
.fonts
, "resource-cache/fonts");
735 helper
.Report(aReport
.weak_fonts
, "resource-cache/weak-fonts");
736 helper
.Report(aReport
.images
, "resource-cache/images");
737 helper
.Report(aReport
.rasterized_blobs
,
738 "resource-cache/rasterized-blobs");
739 helper
.Report(aReport
.texture_cache_structures
,
740 "texture-cache/structures");
741 helper
.Report(aReport
.shader_cache
, "shader-cache");
742 helper
.Report(aReport
.display_list
, "display-list");
743 helper
.Report(aReport
.swgl
, "swgl");
744 helper
.Report(aReport
.upload_staging_memory
, "upload-stagin-memory");
746 WEBRENDER_FOR_EACH_INTERNER(REPORT_INTERNER
);
747 WEBRENDER_FOR_EACH_INTERNER(REPORT_DATA_STORE
);
750 helper
.ReportTexture(aReport
.gpu_cache_textures
, "gpu-cache");
751 helper
.ReportTexture(aReport
.vertex_data_textures
, "vertex-data");
752 helper
.ReportTexture(aReport
.render_target_textures
, "render-targets");
753 helper
.ReportTexture(aReport
.depth_target_textures
, "depth-targets");
754 helper
.ReportTexture(aReport
.picture_tile_textures
, "picture-tiles");
755 helper
.ReportTexture(aReport
.atlas_textures
, "texture-cache/atlas");
756 helper
.ReportTexture(aReport
.standalone_textures
,
757 "texture-cache/standalone");
758 helper
.ReportTexture(aReport
.texture_upload_pbos
,
759 "texture-upload-pbos");
760 helper
.ReportTexture(aReport
.swap_chain
, "swap-chains");
761 helper
.ReportTexture(aReport
.render_texture_hosts
,
762 "render-texture-hosts");
763 helper
.ReportTexture(aReport
.upload_staging_textures
,
764 "upload-staging-textures");
766 FinishAsyncMemoryReport();
768 [](mozilla::ipc::ResponseRejectReason
&& aReason
) {
769 FinishAsyncMemoryReport();
775 #undef REPORT_INTERNER
776 #undef REPORT_DATA_STORE
778 std::atomic
<int8_t> gfxPlatform::sHasVariationFontSupport
= -1;
780 bool gfxPlatform::HasVariationFontSupport() {
781 // We record the status here: 0 for not supported, 1 for supported.
782 if (sHasVariationFontSupport
< 0) {
783 // It doesn't actually matter if we race with another thread setting this,
784 // as any thread will set it to the same value.
786 sHasVariationFontSupport
= gfxWindowsPlatform::CheckVariationFontSupport();
787 #elif defined(XP_DARWIN)
788 sHasVariationFontSupport
= gfxPlatformMac::CheckVariationFontSupport();
789 #elif defined(MOZ_WIDGET_GTK)
790 sHasVariationFontSupport
= gfxPlatformGtk::CheckVariationFontSupport();
791 #elif defined(ANDROID)
792 sHasVariationFontSupport
= gfxAndroidPlatform::CheckVariationFontSupport();
794 # error "No gfxPlatform implementation available"
797 return sHasVariationFontSupport
> 0;
800 void gfxPlatform::Init() {
801 MOZ_RELEASE_ASSERT(!XRE_IsGPUProcess(), "GFX: Not allowed in GPU process.");
802 MOZ_RELEASE_ASSERT(!XRE_IsRDDProcess(), "GFX: Not allowed in RDD process.");
803 MOZ_RELEASE_ASSERT(NS_IsMainThread(), "GFX: Not in main thread.");
805 if (gEverInitialized
) {
806 MOZ_CRASH("Already started???");
808 gEverInitialized
= true;
810 gfxVars::Initialize();
814 if (XRE_IsParentProcess()) {
815 GPUProcessManager::Initialize();
816 RDDProcessManager::Initialize();
818 nsCOMPtr
<nsIFile
> file
;
819 nsresult rv
= NS_GetSpecialDirectory(NS_GRE_DIR
, getter_AddRefs(file
));
821 gfxVars::SetGREDirectory(nsString());
825 gfxVars::SetGREDirectory(nsString(path
));
829 if (XRE_IsParentProcess()) {
830 nsCOMPtr
<nsIFile
> profDir
;
831 nsresult rv
= NS_GetSpecialDirectory(NS_APP_PROFILE_DIR_STARTUP
,
832 getter_AddRefs(profDir
));
834 gfxVars::SetProfDirectory(nsString());
837 profDir
->GetPath(path
);
838 gfxVars::SetProfDirectory(nsString(path
));
842 Preferences::GetCString("layers.windowrecording.path", path
);
843 gfxVars::SetLayersWindowRecordingPath(path
);
846 gfxVars::SetFxREmbedded(true);
850 // Drop a note in the crash report if we end up forcing an option that could
851 // destabilize things. New items should be appended at the end (of an
852 // existing or in a new section), so that we don't have to know the version to
853 // interpret these cryptic strings.
855 nsAutoCString forcedPrefs
;
857 forcedPrefs
.AppendPrintf(
858 "FP(D%d%d", StaticPrefs::gfx_direct2d_disabled_AtStartup(),
859 StaticPrefs::gfx_direct2d_force_enabled_AtStartup());
861 forcedPrefs
.AppendPrintf(
863 StaticPrefs::layers_amd_switchable_gfx_enabled_AtStartup(),
864 StaticPrefs::layers_acceleration_disabled_AtStartup_DoNotUseDirectly(),
866 layers_acceleration_force_enabled_AtStartup_DoNotUseDirectly(),
867 StaticPrefs::layers_d3d11_force_warp_AtStartup());
869 forcedPrefs
.AppendPrintf(
870 "-W%d%d%d%d%d%d%d", StaticPrefs::webgl_angle_force_d3d11(),
871 StaticPrefs::webgl_angle_force_warp(), StaticPrefs::webgl_disabled(),
872 StaticPrefs::webgl_disable_angle(), StaticPrefs::webgl_dxgl_enabled(),
873 StaticPrefs::webgl_force_enabled(), StaticPrefs::webgl_msaa_force());
874 // Prefs that don't fit into any of the other sections
875 forcedPrefs
.AppendPrintf("-T%d%d%d) ",
876 StaticPrefs::gfx_android_rgb16_force_AtStartup(),
877 StaticPrefs::gfx_canvas_accelerated(),
878 StaticPrefs::layers_force_shmem_tiles_AtStartup());
879 ScopedGfxFeatureReporter::AppNote(forcedPrefs
);
884 /* Initialize the GfxInfo service.
885 * Note: we can't call functions on GfxInfo that depend
886 * on gPlatform until after it has been initialized
887 * below. GfxInfo initialization annotates our
888 * crash reports so we want to do it before
889 * we try to load any drivers and do device detection
890 * incase that code crashes. See bug #591561. */
891 nsCOMPtr
<nsIGfxInfo
> gfxInfo
;
892 /* this currently will only succeed on Windows */
893 gfxInfo
= components::GfxInfo::Service();
895 if (XRE_IsParentProcess()) {
896 // Some gfxVars must be initialized prior gPlatform for coherent results.
897 gfxVars::SetDXInterop2Blocked(IsDXInterop2Blocked());
898 gfxVars::SetDXNV12Blocked(IsDXNV12Blocked());
899 gfxVars::SetDXP010Blocked(IsDXP010Blocked());
900 gfxVars::SetDXP016Blocked(IsDXP016Blocked());
904 gPlatform
= new gfxWindowsPlatform
;
905 #elif defined(XP_DARWIN)
906 gPlatform
= new gfxPlatformMac
;
907 #elif defined(MOZ_WIDGET_GTK)
908 gPlatform
= new gfxPlatformGtk
;
909 #elif defined(ANDROID)
910 gPlatform
= new gfxAndroidPlatform
;
912 # error "No gfxPlatform implementation available"
914 gPlatform
->PopulateScreenInfo();
915 gPlatform
->InitAcceleration();
916 gPlatform
->InitWebRenderConfig();
918 gPlatform
->InitHardwareVideoConfig();
919 gPlatform
->InitWebGLConfig();
920 gPlatform
->InitWebGPUConfig();
921 gPlatform
->InitWindowOcclusionConfig();
922 gPlatform
->InitBackdropFilterConfig();
923 gPlatform
->InitAcceleratedCanvas2DConfig();
926 // When using WebRender, we defer initialization of the D3D11 devices until
927 // the (rare) cases where they're used. Note that the GPU process where
928 // WebRender runs doesn't initialize gfxPlatform and performs explicit
929 // initialization of the bits it needs.
930 if (XRE_IsParentProcess() && !gfxConfig::IsEnabled(Feature::GPU_PROCESS
) &&
932 gfx_webrender_enabled_no_gpu_process_with_angle_win_AtStartup()) {
933 gPlatform
->EnsureDevicesInitialized();
937 if (XRE_IsParentProcess()) {
938 mozilla::glean::gpu_process::feature_status
.Set(
939 gfxConfig::GetFeature(Feature::GPU_PROCESS
)
940 .GetStatusAndFailureIdString());
943 if (gfxConfig::IsEnabled(Feature::GPU_PROCESS
)) {
944 GPUProcessManager
* gpu
= GPUProcessManager::Get();
945 Unused
<< gpu
->LaunchGPUProcess();
948 if (XRE_IsParentProcess()) {
949 // Create the global vsync source and dispatcher.
950 RefPtr
<VsyncSource
> vsyncSource
=
951 gfxPlatform::ForceSoftwareVsync()
952 ? gPlatform
->GetSoftwareVsyncSource()
953 : gPlatform
->GetGlobalHardwareVsyncSource();
954 gPlatform
->mVsyncDispatcher
= new VsyncDispatcher(vsyncSource
);
956 // Listen for layout.frame_rate pref changes.
957 Preferences::RegisterCallback(
958 gfxPlatform::ReInitFrameRate
,
959 nsDependentCString(StaticPrefs::GetPrefName_layout_frame_rate()));
960 Preferences::RegisterCallback(
961 gfxPlatform::ReInitFrameRate
,
963 StaticPrefs::GetPrefName_privacy_resistFingerprinting()));
966 // Create the sRGB to output display profile transforms. They can be accessed
967 // off the main thread so we want to avoid a race condition.
971 #ifdef MOZ_ENABLE_FREETYPE
972 SkInitCairoFT(gPlatform
->FontHintingEnabled());
974 gfxGradientCache::Init();
978 // This *create* the platform font list instance, but may not *initialize* it
979 // yet if the gfx.font-list.lazy-init.enabled pref is set. The first *use*
980 // of the list will ensure it is initialized.
981 if (!gPlatform
->CreatePlatformFontList()) {
982 MOZ_CRASH("Could not initialize gfxPlatformFontList");
985 gPlatform
->mScreenReferenceDrawTarget
=
986 gPlatform
->CreateOffscreenContentDrawTarget(IntSize(1, 1),
987 SurfaceFormat::B8G8R8A8
);
988 if (!gPlatform
->mScreenReferenceDrawTarget
||
989 !gPlatform
->mScreenReferenceDrawTarget
->IsValid()) {
990 // If TDR is detected, create a draw target with software backend
991 // and it should be replaced later when the process gets the device
992 // reset notification.
993 if (!gPlatform
->DidRenderingDeviceReset()) {
994 gfxCriticalError() << "Could not initialize mScreenReferenceDrawTarget";
998 if (NS_FAILED(gfxFontCache::Init())) {
999 MOZ_CRASH("Could not initialize gfxFontCache");
1002 Preferences::RegisterPrefixCallbacks(FontPrefChanged
, kObservedPrefs
);
1004 GLContext::PlatformStartup();
1006 // Listen to memory pressure event so we can purge DrawTarget caches
1007 gPlatform
->mMemoryPressureObserver
=
1008 layers::MemoryPressureObserver::Create(gPlatform
);
1010 // Request the imgITools service, implicitly initializing ImageLib.
1011 nsCOMPtr
<imgITools
> imgTools
= do_GetService("@mozilla.org/image/tools;1");
1013 MOZ_CRASH("Could not initialize ImageLib");
1016 RegisterStrongMemoryReporter(new GfxMemoryImageReporter());
1017 if (XRE_IsParentProcess()) {
1018 RegisterStrongAsyncMemoryReporter(new WebRenderMemoryReporter());
1021 RegisterStrongMemoryReporter(new SkMemoryReporter());
1023 uint32_t skiaCacheSize
= GetSkiaGlyphCacheSize();
1024 if (skiaCacheSize
!= kDefaultGlyphCacheSize
) {
1025 SkGraphics::SetFontCacheLimit(skiaCacheSize
);
1031 if (XRE_IsParentProcess()) {
1032 Preferences::Unlock(FONT_VARIATIONS_PREF
);
1033 if (!gfxPlatform::HasVariationFontSupport()) {
1034 // Ensure variation fonts are disabled and the pref is locked.
1035 Preferences::SetBool(FONT_VARIATIONS_PREF
, false, PrefValueKind::Default
);
1036 Preferences::SetBool(FONT_VARIATIONS_PREF
, false);
1037 Preferences::Lock(FONT_VARIATIONS_PREF
);
1041 if (XRE_IsParentProcess()) {
1045 nsCOMPtr
<nsIObserverService
> obs
= services::GetObserverService();
1047 obs
->NotifyObservers(nullptr, "gfx-features-ready", nullptr);
1051 void gfxPlatform::ReportTelemetry() {
1052 MOZ_RELEASE_ASSERT(XRE_IsParentProcess(),
1053 "GFX: Only allowed to be called from parent process.");
1055 nsCOMPtr
<nsIGfxInfo
> gfxInfo
= components::GfxInfo::Service();
1058 auto& screenManager
= widget::ScreenManager::GetSingleton();
1059 const uint32_t screenCount
= screenManager
.CurrentScreenList().Length();
1060 RefPtr
<widget::Screen
> primaryScreen
= screenManager
.GetPrimaryScreen();
1061 const LayoutDeviceIntRect rect
= primaryScreen
->GetRect();
1063 mozilla::glean::gfx_display::count
.Set(screenCount
);
1064 mozilla::glean::gfx_display::primary_height
.Set(rect
.Height());
1065 mozilla::glean::gfx_display::primary_width
.Set(rect
.Width());
1067 // Check if any screen known by screenManager supports HDR.
1068 bool supportsHDR
= false;
1069 for (const auto& screen
: screenManager
.CurrentScreenList()) {
1070 supportsHDR
|= screen
->GetIsHDR();
1072 Telemetry::ScalarSet(Telemetry::ScalarID::GFX_SUPPORTS_HDR
, supportsHDR
);
1075 nsString adapterDesc
;
1076 gfxInfo
->GetAdapterDescription(adapterDesc
);
1078 // Android description is constructed in a way that makes it possible to exceed
1079 // the metric's length limit.
1080 #if defined(ANDROID)
1081 if (!adapterDesc
.IsEmpty()) {
1082 adapterDesc
.Truncate(99);
1086 mozilla::glean::gfx_adapter_primary::description
.Set(
1087 NS_ConvertUTF16toUTF8(adapterDesc
));
1089 nsString adapterVendorId
;
1090 gfxInfo
->GetAdapterVendorID(adapterVendorId
);
1091 mozilla::glean::gfx_adapter_primary::vendor_id
.Set(
1092 NS_ConvertUTF16toUTF8(adapterVendorId
));
1094 nsString adapterDeviceId
;
1095 gfxInfo
->GetAdapterDeviceID(adapterDeviceId
);
1096 mozilla::glean::gfx_adapter_primary::device_id
.Set(
1097 NS_ConvertUTF16toUTF8(adapterDeviceId
));
1099 nsString adapterSubsystemId
;
1100 gfxInfo
->GetAdapterSubsysID(adapterSubsystemId
);
1101 mozilla::glean::gfx_adapter_primary::subsystem_id
.Set(
1102 NS_ConvertUTF16toUTF8(adapterSubsystemId
));
1104 uint32_t adapterRam
= 0;
1105 gfxInfo
->GetAdapterRAM(&adapterRam
);
1106 mozilla::glean::gfx_adapter_primary::ram
.Set(adapterRam
);
1108 nsString adapterDriver
;
1109 gfxInfo
->GetAdapterDriver(adapterDriver
);
1110 mozilla::glean::gfx_adapter_primary::driver_files
.Set(
1111 NS_ConvertUTF16toUTF8(adapterDriver
));
1113 nsString adapterDriverVendor
;
1114 gfxInfo
->GetAdapterDriverVendor(adapterDriverVendor
);
1115 mozilla::glean::gfx_adapter_primary::driver_vendor
.Set(
1116 NS_ConvertUTF16toUTF8(adapterDriverVendor
));
1118 nsString adapterDriverVersion
;
1119 gfxInfo
->GetAdapterDriverVersion(adapterDriverVersion
);
1120 mozilla::glean::gfx_adapter_primary::driver_version
.Set(
1121 NS_ConvertUTF16toUTF8(adapterDriverVersion
));
1123 nsString adapterDriverDate
;
1124 gfxInfo
->GetAdapterDriverDate(adapterDriverDate
);
1125 mozilla::glean::gfx_adapter_primary::driver_date
.Set(
1126 NS_ConvertUTF16toUTF8(adapterDriverDate
));
1128 mozilla::glean::gfx_status::headless
.Set(IsHeadless());
1131 static bool IsFeatureSupported(long aFeature
, bool aDefault
) {
1132 nsCOMPtr
<nsIGfxInfo
> gfxInfo
= components::GfxInfo::Service();
1135 if (!NS_SUCCEEDED(gfxInfo
->GetFeatureStatus(aFeature
, blockId
, &status
))) {
1138 return status
== nsIGfxInfo::FEATURE_STATUS_OK
;
1142 bool gfxPlatform::IsDXInterop2Blocked() {
1143 return !IsFeatureSupported(nsIGfxInfo::FEATURE_DX_INTEROP2
, false);
1147 bool gfxPlatform::IsDXNV12Blocked() {
1148 return !IsFeatureSupported(nsIGfxInfo::FEATURE_DX_NV12
, false);
1152 bool gfxPlatform::IsDXP010Blocked() {
1153 return !IsFeatureSupported(nsIGfxInfo::FEATURE_DX_P010
, false);
1157 bool gfxPlatform::IsDXP016Blocked() {
1158 return !IsFeatureSupported(nsIGfxInfo::FEATURE_DX_P016
, false);
1162 int32_t gfxPlatform::MaxTextureSize() {
1163 // Make sure we don't completely break rendering because of a typo in the
1165 const int32_t kMinSizePref
= 2048;
1168 StaticPrefs::gfx_max_texture_size_AtStartup_DoNotUseDirectly());
1172 int32_t gfxPlatform::MaxAllocSize() {
1173 // Make sure we don't completely break rendering because of a typo in the
1175 const int32_t kMinAllocPref
= 10000000;
1176 return std::max(kMinAllocPref
,
1177 StaticPrefs::gfx_max_alloc_size_AtStartup_DoNotUseDirectly());
1181 void gfxPlatform::InitMoz2DLogging() {
1182 auto fwd
= new CrashStatsLogForwarder(
1183 CrashReporter::Annotation::GraphicsCriticalError
);
1184 fwd
->SetCircularBufferSize(StaticPrefs::gfx_logging_crash_length_AtStartup());
1186 mozilla::gfx::Config cfg
;
1187 cfg
.mLogForwarder
= fwd
;
1188 cfg
.mMaxTextureSize
= gfxPlatform::MaxTextureSize();
1189 cfg
.mMaxAllocSize
= gfxPlatform::MaxAllocSize();
1191 gfx::Factory::Init(cfg
);
1195 bool gfxPlatform::IsHeadless() {
1196 static bool initialized
= false;
1197 static bool headless
= false;
1200 headless
= PR_GetEnv("MOZ_HEADLESS");
1206 bool gfxPlatform::UseRemoteCanvas() {
1207 return XRE_IsContentProcess() && (gfx::gfxVars::RemoteCanvasEnabled() ||
1208 gfx::gfxVars::UseAcceleratedCanvas2D());
1212 bool gfxPlatform::IsBackendAccelerated(
1213 const mozilla::gfx::BackendType aBackendType
) {
1214 return aBackendType
== BackendType::DIRECT2D
||
1215 aBackendType
== BackendType::DIRECT2D1_1
;
1219 bool gfxPlatform::CanMigrateMacGPUs() {
1220 int32_t pMigration
= StaticPrefs::gfx_compositor_gpu_migration();
1222 bool forceDisable
= pMigration
== 0;
1223 bool forceEnable
= pMigration
== 2;
1225 return forceEnable
|| !forceDisable
;
1228 static bool sLayersIPCIsUp
= false;
1231 void gfxPlatform::InitNullMetadata() {
1232 ScrollMetadata::sNullMetadata
= new ScrollMetadata();
1233 ClearOnShutdown(&ScrollMetadata::sNullMetadata
);
1236 void gfxPlatform::Shutdown() {
1237 // In some cases, gPlatform may not be created but Shutdown() called,
1238 // e.g., during xpcshell tests.
1243 MOZ_ASSERT(!sLayersIPCIsUp
);
1245 // These may be called before the corresponding subsystems have actually
1246 // started up. That's OK, they can handle it.
1247 gfxFontCache::Shutdown();
1248 gfxGradientCache::Shutdown();
1249 gfxAlphaBoxBlur::ShutdownBlurCache();
1250 gfxGraphiteShaper::Shutdown();
1251 gfxPlatformFontList::Shutdown();
1252 gfxFontMissingGlyphs::Shutdown();
1254 // Free the various non-null transforms and loaded profiles
1257 Preferences::UnregisterPrefixCallbacks(FontPrefChanged
, kObservedPrefs
);
1259 NS_ASSERTION(gPlatform
->mMemoryPressureObserver
,
1260 "mMemoryPressureObserver has already gone");
1261 if (gPlatform
->mMemoryPressureObserver
) {
1262 gPlatform
->mMemoryPressureObserver
->Unregister();
1263 gPlatform
->mMemoryPressureObserver
= nullptr;
1266 if (XRE_IsParentProcess()) {
1267 if (gPlatform
->mGlobalHardwareVsyncSource
) {
1268 gPlatform
->mGlobalHardwareVsyncSource
->Shutdown();
1270 if (gPlatform
->mSoftwareVsyncSource
&&
1271 gPlatform
->mSoftwareVsyncSource
!=
1272 gPlatform
->mGlobalHardwareVsyncSource
) {
1273 gPlatform
->mSoftwareVsyncSource
->Shutdown();
1277 gPlatform
->mGlobalHardwareVsyncSource
= nullptr;
1278 gPlatform
->mSoftwareVsyncSource
= nullptr;
1279 gPlatform
->mVsyncDispatcher
= nullptr;
1281 // Shut down the default GL context provider.
1282 GLContextProvider::Shutdown();
1285 // The above shutdown calls operate on the available context providers on
1286 // most platforms. Windows is a "special snowflake", though, and has three
1287 // context providers available, so we have to shut all of them down.
1288 // We should only support the default GL provider on Windows; then, this
1289 // could go away. Unfortunately, we currently support WGL (the default) for
1290 // WebGL on Optimus.
1291 GLContextProviderEGL::Shutdown();
1294 if (XRE_IsParentProcess()) {
1295 GPUProcessManager::Shutdown();
1296 VRProcessManager::Shutdown();
1297 RDDProcessManager::Shutdown();
1300 gfx::Factory::ShutDown();
1301 gfxVars::Shutdown();
1302 gfxFont::DestroySingletons();
1304 gfxConfig::Shutdown();
1306 gPlatform
->WillShutdown();
1309 gPlatform
= nullptr;
1313 void gfxPlatform::InitLayersIPC() {
1314 if (sLayersIPCIsUp
) {
1317 sLayersIPCIsUp
= true;
1319 if (XRE_IsParentProcess()) {
1321 if (gfxConfig::IsEnabled(gfx::Feature::WINDOW_OCCLUSION
)) {
1322 widget::WinWindowOcclusionTracker::Ensure();
1325 if (!gfxConfig::IsEnabled(Feature::GPU_PROCESS
)) {
1326 RemoteTextureMap::Init();
1327 wr::RenderThread::Start(GPUProcessManager::Get()->AllocateNamespace());
1328 image::ImageMemoryReporter::InitForWebRender();
1331 layers::CompositorThreadHolder::Start();
1333 if (!gfxConfig::IsEnabled(Feature::GPU_PROCESS
)) {
1334 gfx::CanvasRenderThread::Start();
1340 void gfxPlatform::ShutdownLayersIPC() {
1341 if (!sLayersIPCIsUp
) {
1344 sLayersIPCIsUp
= false;
1346 if (XRE_IsContentProcess()) {
1347 gfx::VRManagerChild::ShutDown();
1348 gfx::CanvasShutdownManager::Shutdown();
1350 if (StaticPrefs::layers_child_process_shutdown()) {
1351 layers::CompositorManagerChild::Shutdown();
1352 layers::ImageBridgeChild::ShutDown();
1355 } else if (XRE_IsParentProcess()) {
1356 VideoBridgeParent::Shutdown();
1357 RDDProcessManager::RDDProcessShutdown();
1358 gfx::VRManagerChild::ShutDown();
1359 gfx::CanvasShutdownManager::Shutdown();
1360 layers::CompositorManagerChild::Shutdown();
1361 layers::ImageBridgeChild::ShutDown();
1362 // This could be running on either the Compositor thread, the Renderer
1363 // thread, or the dedicated CanvasRender thread, so we need to shutdown
1364 // before the former two.
1365 gfx::CanvasRenderThread::Shutdown();
1366 // This has to happen after shutting down the child protocols.
1367 layers::CompositorThreadHolder::Shutdown();
1368 RemoteTextureMap::Shutdown();
1369 image::ImageMemoryReporter::ShutdownForWebRender();
1370 // There is a case that RenderThread exists when UseWebRender() is
1371 // false. This could happen when WebRender was fallbacked to compositor.
1372 if (wr::RenderThread::Get()) {
1373 wr::RenderThread::ShutDown();
1375 Preferences::UnregisterCallback(WebRenderDebugPrefChangeCallback
,
1377 Preferences::UnregisterCallback(WebRendeProfilerUIPrefChangeCallback
,
1378 "gfx.webrender.debug.profiler-ui");
1379 Preferences::UnregisterCallback(
1380 WebRenderBlobTileSizePrefChangeCallback
,
1382 StaticPrefs::GetPrefName_gfx_webrender_blob_tile_size()));
1385 widget::WinWindowOcclusionTracker::ShutDown();
1388 // TODO: There are other kind of processes and we should make sure gfx
1389 // stuff is either not created there or shut down properly.
1393 void gfxPlatform::WillShutdown() {
1394 // Destoy these first in case they depend on backend-specific resources.
1395 // Otherwise, the backend's destructor would be called before the
1396 // base gfxPlatform destructor.
1397 mScreenReferenceSurface
= nullptr;
1398 mScreenReferenceDrawTarget
= nullptr;
1400 // Always clear out the Skia font cache here, in case it is referencing any
1401 // SharedFTFaces that would otherwise outlive destruction of the FT_Library
1403 SkGraphics::PurgeFontCache();
1405 // The cairo folks think we should only clean up in debug builds,
1406 // but we're generally in the habit of trying to shut down as
1407 // cleanly as possible even in production code, so call this
1408 // cairo_debug_* function unconditionally.
1410 // because cairo can assert and thus crash on shutdown, don't do this in
1412 #ifdef NS_FREE_PERMANENT_DATA
1413 cairo_debug_reset_static_data();
1417 gfxPlatform::~gfxPlatform() = default;
1420 already_AddRefed
<DrawTarget
> gfxPlatform::CreateDrawTargetForSurface(
1421 gfxASurface
* aSurface
, const IntSize
& aSize
) {
1422 SurfaceFormat format
= aSurface
->GetSurfaceFormat();
1423 RefPtr
<DrawTarget
> drawTarget
= Factory::CreateDrawTargetForCairoSurface(
1424 aSurface
->CairoSurface(), aSize
, &format
);
1426 gfxWarning() << "gfxPlatform::CreateDrawTargetForSurface failed in "
1427 "CreateDrawTargetForCairoSurface";
1430 return drawTarget
.forget();
1433 cairo_user_data_key_t kSourceSurface
;
1436 * Record the backend that was used to construct the SourceSurface.
1437 * When getting the cached SourceSurface for a gfxASurface/DrawTarget pair,
1438 * we check to make sure the DrawTarget's backend matches the backend
1439 * for the cached SourceSurface, and only use it if they match. This
1440 * can avoid expensive and unnecessary readbacks.
1442 struct SourceSurfaceUserData
{
1443 RefPtr
<SourceSurface
> mSrcSurface
;
1444 BackendType mBackendType
;
1447 static void SourceBufferDestroy(void* srcSurfUD
) {
1448 delete static_cast<SourceSurfaceUserData
*>(srcSurfUD
);
1451 UserDataKey kThebesSurface
;
1453 struct DependentSourceSurfaceUserData
{
1454 RefPtr
<gfxASurface
> mSurface
;
1457 static void SourceSurfaceDestroyed(void* aData
) {
1458 delete static_cast<DependentSourceSurfaceUserData
*>(aData
);
1461 void gfxPlatform::ClearSourceSurfaceForSurface(gfxASurface
* aSurface
) {
1462 aSurface
->SetData(&kSourceSurface
, nullptr, nullptr);
1466 already_AddRefed
<SourceSurface
> gfxPlatform::GetSourceSurfaceForSurface(
1467 RefPtr
<DrawTarget
> aTarget
, gfxASurface
* aSurface
, bool aIsPlugin
) {
1468 if (!aSurface
->CairoSurface() || aSurface
->CairoStatus()) {
1473 aTarget
= gfxPlatform::GetPlatform()->ScreenReferenceDrawTarget();
1476 void* userData
= aSurface
->GetData(&kSourceSurface
);
1479 SourceSurfaceUserData
* surf
= static_cast<SourceSurfaceUserData
*>(userData
);
1481 if (surf
->mSrcSurface
->IsValid() &&
1482 surf
->mBackendType
== aTarget
->GetBackendType()) {
1483 RefPtr
<SourceSurface
> srcSurface(surf
->mSrcSurface
);
1484 return srcSurface
.forget();
1486 // We can just continue here as when setting new user data the destroy
1487 // function will be called for the old user data.
1490 SurfaceFormat format
= aSurface
->GetSurfaceFormat();
1492 if (aTarget
->GetBackendType() == BackendType::CAIRO
) {
1493 // If we're going to be used with a CAIRO DrawTarget, then just create a
1494 // SourceSurfaceCairo since we don't know the underlying type of the CAIRO
1495 // DrawTarget and can't pick a better surface type. Doing this also avoids
1496 // readback of aSurface's surface into memory if, for example, aSurface
1497 // wraps an xlib cairo surface (which can be important to avoid a major
1500 // We return here regardless of whether CreateSourceSurfaceFromNativeSurface
1501 // succeeds or not since we don't expect to be able to do any better below
1504 // Note that the returned SourceSurfaceCairo holds a strong reference to
1505 // the cairo_surface_t* that it wraps, which essencially means it holds a
1506 // strong reference to aSurface since aSurface shares its
1507 // cairo_surface_t*'s reference count variable. As a result we can't cache
1508 // srcBuffer on aSurface (see below) since aSurface would then hold a
1509 // strong reference back to srcBuffer, creating a reference loop and a
1510 // memory leak. Not caching is fine since wrapping is cheap enough (no
1511 // copying) so we can just wrap again next time we're called.
1512 return Factory::CreateSourceSurfaceForCairoSurface(
1513 aSurface
->CairoSurface(), aSurface
->GetSize(), format
);
1516 RefPtr
<SourceSurface
> srcBuffer
;
1518 // Currently no other DrawTarget types implement
1519 // CreateSourceSurfaceFromNativeSurface
1522 // If aSurface wraps data, we can create a SourceSurfaceRawData that wraps
1523 // the same data, then optimize it for aTarget:
1524 RefPtr
<DataSourceSurface
> surf
= GetWrappedDataSourceSurface(aSurface
);
1526 srcBuffer
= aIsPlugin
1527 ? aTarget
->OptimizeSourceSurfaceForUnknownAlpha(surf
)
1528 : aTarget
->OptimizeSourceSurface(surf
);
1530 if (srcBuffer
== surf
) {
1531 // GetWrappedDataSourceSurface returns a SourceSurface that holds a
1532 // strong reference to aSurface since it wraps aSurface's data and
1533 // needs it to stay alive. As a result we can't cache srcBuffer on
1534 // aSurface (below) since aSurface would then hold a strong reference
1535 // back to srcBuffer, creating a reference loop and a memory leak. Not
1536 // caching is fine since wrapping is cheap enough (no copying) so we
1537 // can just wrap again next time we're called.
1539 // Note that the check below doesn't catch this since srcBuffer will be
1540 // a SourceSurfaceRawData object (even if aSurface is not a
1541 // gfxImageSurface object), which is why we need this separate check.
1542 return srcBuffer
.forget();
1548 MOZ_ASSERT(aTarget
->GetBackendType() != BackendType::CAIRO
,
1549 "We already tried CreateSourceSurfaceFromNativeSurface with a "
1550 "DrawTargetCairo above");
1551 // We've run out of performant options. We now try creating a SourceSurface
1552 // using a temporary DrawTargetCairo and then optimizing it to aTarget's
1553 // actual type. The CreateSourceSurfaceFromNativeSurface() call will
1554 // likely create a DataSourceSurface (possibly involving copying and/or
1555 // readback), and the OptimizeSourceSurface may well copy again and upload
1556 // to the GPU. So, while this code path is rarely hit, hitting it may be
1558 srcBuffer
= Factory::CreateSourceSurfaceForCairoSurface(
1559 aSurface
->CairoSurface(), aSurface
->GetSize(), format
);
1561 srcBuffer
= aTarget
->OptimizeSourceSurface(srcBuffer
);
1569 if ((srcBuffer
->GetType() == SurfaceType::CAIRO
&&
1570 static_cast<SourceSurfaceCairo
*>(srcBuffer
.get())->GetSurface() ==
1571 aSurface
->CairoSurface()) ||
1572 (srcBuffer
->GetType() == SurfaceType::CAIRO_IMAGE
&&
1573 static_cast<DataSourceSurfaceCairo
*>(srcBuffer
.get())->GetSurface() ==
1574 aSurface
->CairoSurface())) {
1575 // See the "Note that the returned SourceSurfaceCairo..." comment above.
1576 return srcBuffer
.forget();
1579 // Add user data to aSurface so we can cache lookups in the future.
1580 auto* srcSurfUD
= new SourceSurfaceUserData
;
1581 srcSurfUD
->mBackendType
= aTarget
->GetBackendType();
1582 srcSurfUD
->mSrcSurface
= srcBuffer
;
1583 aSurface
->SetData(&kSourceSurface
, srcSurfUD
, SourceBufferDestroy
);
1585 return srcBuffer
.forget();
1588 already_AddRefed
<DataSourceSurface
> gfxPlatform::GetWrappedDataSourceSurface(
1589 gfxASurface
* aSurface
) {
1590 RefPtr
<gfxImageSurface
> image
= aSurface
->GetAsImageSurface();
1594 RefPtr
<DataSourceSurface
> result
= Factory::CreateWrappingDataSourceSurface(
1595 image
->Data(), image
->Stride(), image
->GetSize(),
1596 ImageFormatToSurfaceFormat(image
->Format()));
1602 // If we wrapped the underlying data of aSurface, then we need to add user
1603 // data to make sure aSurface stays alive until we are done with the data.
1604 auto* srcSurfUD
= new DependentSourceSurfaceUserData
;
1605 srcSurfUD
->mSurface
= aSurface
;
1606 result
->AddUserData(&kThebesSurface
, srcSurfUD
, SourceSurfaceDestroyed
);
1608 return result
.forget();
1611 void gfxPlatform::PopulateScreenInfo() {
1612 // We're only going to set some gfxVars here, which is only possible from
1613 // the parent process.
1614 if (!XRE_IsParentProcess()) {
1618 nsCOMPtr
<nsIScreenManager
> manager
=
1619 do_GetService("@mozilla.org/gfx/screenmanager;1");
1620 MOZ_ASSERT(manager
, "failed to get nsIScreenManager");
1622 nsCOMPtr
<nsIScreen
> screen
;
1623 manager
->GetPrimaryScreen(getter_AddRefs(screen
));
1625 // This can happen in xpcshell, for instance
1629 int32_t screenDepth
;
1630 screen
->GetColorDepth(&screenDepth
);
1631 gfxVars::SetPrimaryScreenDepth(screenDepth
);
1634 bool gfxPlatform::SupportsAzureContentForDrawTarget(DrawTarget
* aTarget
) {
1635 if (!aTarget
|| !aTarget
->IsValid()) {
1639 return SupportsAzureContentForType(aTarget
->GetBackendType());
1642 void gfxPlatform::PurgeSkiaFontCache() {
1643 if (gfxPlatform::GetPlatform()->GetDefaultContentBackend() ==
1644 BackendType::SKIA
) {
1645 SkGraphics::PurgeFontCache();
1649 already_AddRefed
<DrawTarget
> gfxPlatform::CreateDrawTargetForBackend(
1650 BackendType aBackend
, const IntSize
& aSize
, SurfaceFormat aFormat
) {
1651 // There is a bunch of knowledge in the gfxPlatform heirarchy about how to
1652 // create the best offscreen surface for the current system and situation. We
1653 // can easily take advantage of this for the Cairo backend, so that's what we
1655 // mozilla::gfx::Factory can get away without having all this knowledge for
1656 // now, but this might need to change in the future (using
1657 // CreateOffscreenSurface() and CreateDrawTargetForSurface() for all
1659 if (aBackend
== BackendType::CAIRO
) {
1660 RefPtr
<gfxASurface
> surf
=
1661 CreateOffscreenSurface(aSize
, SurfaceFormatToImageFormat(aFormat
));
1662 if (!surf
|| surf
->CairoStatus()) {
1665 return CreateDrawTargetForSurface(surf
, aSize
);
1667 return Factory::CreateDrawTarget(aBackend
, aSize
, aFormat
);
1670 already_AddRefed
<DrawTarget
> gfxPlatform::CreateOffscreenCanvasDrawTarget(
1671 const IntSize
& aSize
, SurfaceFormat aFormat
) {
1672 NS_ASSERTION(mPreferredCanvasBackend
!= BackendType::NONE
, "No backend.");
1674 // If we are using remote canvas we don't want to use acceleration in
1675 // canvas DrawTargets we are not remoting, so we always use the fallback
1677 if (!gfxPlatform::UseRemoteCanvas() ||
1678 !gfxPlatform::IsBackendAccelerated(mPreferredCanvasBackend
)) {
1679 RefPtr
<DrawTarget
> target
=
1680 CreateDrawTargetForBackend(mPreferredCanvasBackend
, aSize
, aFormat
);
1681 if (target
|| mFallbackCanvasBackend
== BackendType::NONE
) {
1682 return target
.forget();
1687 // On Windows, the fallback backend (Cairo) should use its image backend.
1688 return Factory::CreateDrawTarget(mFallbackCanvasBackend
, aSize
, aFormat
);
1690 return CreateDrawTargetForBackend(mFallbackCanvasBackend
, aSize
, aFormat
);
1694 already_AddRefed
<DrawTarget
> gfxPlatform::CreateOffscreenContentDrawTarget(
1695 const IntSize
& aSize
, SurfaceFormat aFormat
, bool aFallback
) {
1696 BackendType backend
= (aFallback
) ? mSoftwareBackend
: mContentBackend
;
1697 NS_ASSERTION(backend
!= BackendType::NONE
, "No backend.");
1698 RefPtr
<DrawTarget
> dt
= CreateDrawTargetForBackend(backend
, aSize
, aFormat
);
1704 // We'd prefer this to take proper care and return a CaptureDT, but for the
1705 // moment since we can't and this means we're going to be drawing on the main
1706 // thread force it's initialization. See bug 1526045 and bug 1521368.
1707 dt
->ClearRect(gfx::Rect());
1708 if (!dt
->IsValid()) {
1714 already_AddRefed
<DrawTarget
> gfxPlatform::CreateSimilarSoftwareDrawTarget(
1715 DrawTarget
* aDT
, const IntSize
& aSize
, SurfaceFormat aFormat
) {
1716 RefPtr
<DrawTarget
> dt
;
1718 if (Factory::DoesBackendSupportDataDrawtarget(aDT
->GetBackendType())) {
1719 dt
= aDT
->CreateSimilarDrawTarget(aSize
, aFormat
);
1721 BackendType backendType
= BackendType::SKIA
;
1722 dt
= Factory::CreateDrawTarget(backendType
, aSize
, aFormat
);
1729 already_AddRefed
<DrawTarget
> gfxPlatform::CreateDrawTargetForData(
1730 unsigned char* aData
, const IntSize
& aSize
, int32_t aStride
,
1731 SurfaceFormat aFormat
, bool aUninitialized
) {
1732 BackendType backendType
= gfxVars::ContentBackend();
1733 NS_ASSERTION(backendType
!= BackendType::NONE
, "No backend.");
1735 if (!Factory::DoesBackendSupportDataDrawtarget(backendType
)) {
1736 backendType
= BackendType::SKIA
;
1739 RefPtr
<DrawTarget
> dt
= Factory::CreateDrawTargetForData(
1740 backendType
, aData
, aSize
, aStride
, aFormat
, aUninitialized
);
1746 BackendType
gfxPlatform::BackendTypeForName(const nsCString
& aName
) {
1747 if (aName
.EqualsLiteral("cairo")) return BackendType::CAIRO
;
1748 if (aName
.EqualsLiteral("skia")) return BackendType::SKIA
;
1749 if (aName
.EqualsLiteral("direct2d")) return BackendType::DIRECT2D
;
1750 if (aName
.EqualsLiteral("direct2d1.1")) return BackendType::DIRECT2D1_1
;
1751 return BackendType::NONE
;
1754 nsresult
gfxPlatform::GetFontList(nsAtom
* aLangGroup
,
1755 const nsACString
& aGenericFamily
,
1756 nsTArray
<nsString
>& aListOfFonts
) {
1757 gfxPlatformFontList::PlatformFontList()->GetFontList(
1758 aLangGroup
, aGenericFamily
, aListOfFonts
);
1762 nsresult
gfxPlatform::UpdateFontList(bool aFullRebuild
) {
1763 gfxPlatformFontList::PlatformFontList()->UpdateFontList(aFullRebuild
);
1767 void gfxPlatform::GetStandardFamilyName(const nsCString
& aFontName
,
1768 nsACString
& aFamilyName
) {
1769 gfxPlatformFontList::PlatformFontList()->GetStandardFamilyName(aFontName
,
1773 nsAutoCString
gfxPlatform::GetDefaultFontName(
1774 const nsACString
& aLangGroup
, const nsACString
& aGenericFamily
) {
1775 // To benefit from Return Value Optimization, all paths here must return
1776 // this one variable:
1777 nsAutoCString result
;
1779 auto* pfl
= gfxPlatformFontList::PlatformFontList();
1780 FamilyAndGeneric fam
= pfl
->GetDefaultFontFamily(aLangGroup
, aGenericFamily
);
1781 if (!pfl
->GetLocalizedFamilyName(fam
.mFamily
, result
)) {
1782 NS_WARNING("missing default font-family name");
1788 bool gfxPlatform::DownloadableFontsEnabled() {
1789 if (mAllowDownloadableFonts
== UNINITIALIZED_VALUE
) {
1790 mAllowDownloadableFonts
=
1791 Preferences::GetBool(GFX_DOWNLOADABLE_FONTS_ENABLED
, false);
1794 return mAllowDownloadableFonts
;
1797 bool gfxPlatform::UseCmapsDuringSystemFallback() {
1798 return StaticPrefs::gfx_font_rendering_fallback_always_use_cmaps();
1801 bool gfxPlatform::OpenTypeSVGEnabled() {
1802 return StaticPrefs::gfx_font_rendering_opentype_svg_enabled();
1805 uint32_t gfxPlatform::WordCacheCharLimit() {
1806 return StaticPrefs::gfx_font_rendering_wordcache_charlimit();
1809 uint32_t gfxPlatform::WordCacheMaxEntries() {
1810 return StaticPrefs::gfx_font_rendering_wordcache_maxentries();
1813 bool gfxPlatform::UseGraphiteShaping() {
1814 return StaticPrefs::gfx_font_rendering_graphite_enabled();
1817 bool gfxPlatform::IsFontFormatSupported(
1818 StyleFontFaceSourceFormatKeyword aFormatHint
,
1819 StyleFontFaceSourceTechFlags aTechFlags
) {
1820 // By default, font resources are assumed to be supported; but if the format
1821 // hint or technology flags explicitly indicate something we don't support,
1822 // then return false.
1823 switch (aFormatHint
) {
1824 case StyleFontFaceSourceFormatKeyword::None
:
1826 case StyleFontFaceSourceFormatKeyword::Collection
:
1828 case StyleFontFaceSourceFormatKeyword::Opentype
:
1829 case StyleFontFaceSourceFormatKeyword::Truetype
:
1831 case StyleFontFaceSourceFormatKeyword::EmbeddedOpentype
:
1833 case StyleFontFaceSourceFormatKeyword::Svg
:
1835 case StyleFontFaceSourceFormatKeyword::Woff
:
1837 case StyleFontFaceSourceFormatKeyword::Woff2
:
1839 case StyleFontFaceSourceFormatKeyword::Unknown
:
1842 MOZ_ASSERT_UNREACHABLE("bad format hint!");
1845 StyleFontFaceSourceTechFlags unsupportedTechnologies
=
1846 StyleFontFaceSourceTechFlags::INCREMENTAL
|
1847 StyleFontFaceSourceTechFlags::COLOR_SBIX
;
1848 if (!StaticPrefs::gfx_downloadable_fonts_keep_color_bitmaps()) {
1849 unsupportedTechnologies
|= StyleFontFaceSourceTechFlags::COLOR_CBDT
;
1851 if (!StaticPrefs::gfx_font_rendering_colr_v1_enabled()) {
1852 unsupportedTechnologies
|= StyleFontFaceSourceTechFlags::COLOR_COLRV1
;
1854 if (!StaticPrefs::layout_css_font_palette_enabled()) {
1855 unsupportedTechnologies
|= StyleFontFaceSourceTechFlags::PALETTES
;
1857 if (!StaticPrefs::layout_css_font_variations_enabled()) {
1858 unsupportedTechnologies
|= StyleFontFaceSourceTechFlags::VARIATIONS
;
1860 if (aTechFlags
& unsupportedTechnologies
) {
1866 bool gfxPlatform::IsKnownIconFontFamily(const nsAtom
* aFamilyName
) const {
1867 return gfxPlatformFontList::PlatformFontList()->IsKnownIconFontFamily(
1871 gfxFontEntry
* gfxPlatform::LookupLocalFont(nsPresContext
* aPresContext
,
1872 const nsACString
& aFontName
,
1873 WeightRange aWeightForEntry
,
1874 StretchRange aStretchForEntry
,
1875 SlantStyleRange aStyleForEntry
) {
1876 return gfxPlatformFontList::PlatformFontList()->LookupLocalFont(
1877 aPresContext
, aFontName
, aWeightForEntry
, aStretchForEntry
,
1881 gfxFontEntry
* gfxPlatform::MakePlatformFont(const nsACString
& aFontName
,
1882 WeightRange aWeightForEntry
,
1883 StretchRange aStretchForEntry
,
1884 SlantStyleRange aStyleForEntry
,
1885 const uint8_t* aFontData
,
1887 return gfxPlatformFontList::PlatformFontList()->MakePlatformFont(
1888 aFontName
, aWeightForEntry
, aStretchForEntry
, aStyleForEntry
, aFontData
,
1892 BackendPrefsData
gfxPlatform::GetBackendPrefs() const {
1893 BackendPrefsData data
;
1895 data
.mCanvasBitmask
= BackendTypeBit(BackendType::SKIA
);
1896 data
.mContentBitmask
= BackendTypeBit(BackendType::SKIA
);
1898 #ifdef MOZ_WIDGET_GTK
1899 data
.mCanvasBitmask
|= BackendTypeBit(BackendType::CAIRO
);
1900 data
.mContentBitmask
|= BackendTypeBit(BackendType::CAIRO
);
1903 data
.mCanvasDefault
= BackendType::SKIA
;
1904 data
.mContentDefault
= BackendType::SKIA
;
1909 void gfxPlatform::InitBackendPrefs(BackendPrefsData
&& aPrefsData
) {
1910 mPreferredCanvasBackend
= GetCanvasBackendPref(aPrefsData
.mCanvasBitmask
);
1911 if (mPreferredCanvasBackend
== BackendType::NONE
) {
1912 mPreferredCanvasBackend
= aPrefsData
.mCanvasDefault
;
1915 if (mPreferredCanvasBackend
== BackendType::DIRECT2D1_1
) {
1916 // Falling back to D2D 1.0 won't help us here. When D2D 1.1 DT creation
1917 // fails it means the surface was too big or there's something wrong with
1918 // the device. D2D 1.0 will encounter a similar situation.
1919 mFallbackCanvasBackend
= GetCanvasBackendPref(
1920 aPrefsData
.mCanvasBitmask
& ~(BackendTypeBit(mPreferredCanvasBackend
) |
1921 BackendTypeBit(BackendType::DIRECT2D
)));
1923 mFallbackCanvasBackend
= GetCanvasBackendPref(
1924 aPrefsData
.mCanvasBitmask
& ~BackendTypeBit(mPreferredCanvasBackend
));
1927 mContentBackendBitmask
= aPrefsData
.mContentBitmask
;
1928 mContentBackend
= GetContentBackendPref(mContentBackendBitmask
);
1929 if (mContentBackend
== BackendType::NONE
) {
1930 mContentBackend
= aPrefsData
.mContentDefault
;
1931 // mContentBackendBitmask is our canonical reference for supported
1932 // backends so we need to add the default if we are using it and
1933 // overriding the prefs.
1934 mContentBackendBitmask
|= BackendTypeBit(aPrefsData
.mContentDefault
);
1937 uint32_t swBackendBits
= BackendTypeBit(BackendType::SKIA
);
1938 #ifdef MOZ_WIDGET_GTK
1939 swBackendBits
|= BackendTypeBit(BackendType::CAIRO
);
1941 mSoftwareBackend
= GetContentBackendPref(swBackendBits
);
1942 if (mSoftwareBackend
== BackendType::NONE
) {
1943 mSoftwareBackend
= BackendType::SKIA
;
1946 // If we don't have a fallback canvas backend then use the same software
1947 // fallback as content.
1948 if (mFallbackCanvasBackend
== BackendType::NONE
) {
1949 mFallbackCanvasBackend
= mSoftwareBackend
;
1952 if (XRE_IsParentProcess()) {
1953 gfxVars::SetContentBackend(mContentBackend
);
1954 gfxVars::SetSoftwareBackend(mSoftwareBackend
);
1959 BackendType
gfxPlatform::GetCanvasBackendPref(uint32_t aBackendBitmask
) {
1960 return GetBackendPref("gfx.canvas.azure.backends", aBackendBitmask
);
1964 BackendType
gfxPlatform::GetContentBackendPref(uint32_t& aBackendBitmask
) {
1965 return GetBackendPref("gfx.content.azure.backends", aBackendBitmask
);
1969 BackendType
gfxPlatform::GetBackendPref(const char* aBackendPrefName
,
1970 uint32_t& aBackendBitmask
) {
1971 nsTArray
<nsCString
> backendList
;
1972 nsAutoCString prefString
;
1973 if (NS_SUCCEEDED(Preferences::GetCString(aBackendPrefName
, prefString
))) {
1974 ParseString(prefString
, ',', backendList
);
1977 uint32_t allowedBackends
= 0;
1978 BackendType result
= BackendType::NONE
;
1979 for (uint32_t i
= 0; i
< backendList
.Length(); ++i
) {
1980 BackendType type
= BackendTypeForName(backendList
[i
]);
1981 if (BackendTypeBit(type
) & aBackendBitmask
) {
1982 allowedBackends
|= BackendTypeBit(type
);
1983 if (result
== BackendType::NONE
) {
1989 aBackendBitmask
= allowedBackends
;
1993 bool gfxPlatform::InSafeMode() {
1994 static bool sSafeModeInitialized
= false;
1995 static bool sInSafeMode
= false;
1997 if (!sSafeModeInitialized
) {
1998 sSafeModeInitialized
= true;
1999 nsCOMPtr
<nsIXULRuntime
> xr
= do_GetService("@mozilla.org/xre/runtime;1");
2001 xr
->GetInSafeMode(&sInSafeMode
);
2007 bool gfxPlatform::OffMainThreadCompositingEnabled() {
2008 return UsesOffMainThreadCompositing();
2011 void gfxPlatform::SetCMSModeOverride(CMSMode aMode
) {
2012 MOZ_ASSERT(gCMSInitialized
);
2016 int gfxPlatform::GetRenderingIntent() {
2017 // StaticPrefList.yaml is using 0 as the default for the rendering
2018 // intent preference, based on that being the value for
2019 // QCMS_INTENT_DEFAULT. Assert here to catch if that ever
2020 // changes and we can then figure out what to do about it.
2021 MOZ_ASSERT(QCMS_INTENT_DEFAULT
== 0);
2023 /* Try to query the pref system for a rendering intent. */
2024 int32_t pIntent
= StaticPrefs::gfx_color_management_rendering_intent();
2025 if ((pIntent
< QCMS_INTENT_MIN
) || (pIntent
> QCMS_INTENT_MAX
)) {
2026 /* If the pref is out of range, use embedded profile. */
2032 DeviceColor
gfxPlatform::TransformPixel(const sRGBColor
& in
,
2033 qcms_transform
* transform
) {
2035 /* we want the bytes in RGB order */
2036 #ifdef IS_LITTLE_ENDIAN
2037 /* ABGR puts the bytes in |RGBA| order on little endian */
2038 uint32_t packed
= in
.ToABGR();
2039 qcms_transform_data(transform
, (uint8_t*)&packed
, (uint8_t*)&packed
, 1);
2040 auto out
= DeviceColor::FromABGR(packed
);
2042 /* ARGB puts the bytes in |ARGB| order on big endian */
2043 uint32_t packed
= in
.UnusualToARGB();
2044 /* add one to move past the alpha byte */
2045 qcms_transform_data(transform
, (uint8_t*)&packed
+ 1, (uint8_t*)&packed
+ 1,
2047 auto out
= DeviceColor::UnusualFromARGB(packed
);
2052 return DeviceColor(in
.r
, in
.g
, in
.b
, in
.a
);
2055 nsTArray
<uint8_t> gfxPlatform::GetPrefCMSOutputProfileData() {
2056 const auto mirror
= StaticPrefs::gfx_color_management_display_profile();
2057 const auto fname
= *mirror
;
2059 return nsTArray
<uint8_t>();
2062 void* mem
= nullptr;
2064 qcms_data_from_path(fname
.get(), &mem
, &size
);
2066 nsTArray
<uint8_t> result
;
2069 result
.AppendElements(static_cast<uint8_t*>(mem
), size
);
2076 const mozilla::gfx::ContentDeviceData
* gfxPlatform::GetInitContentDeviceData() {
2077 return gContentDeviceInitData
;
2080 Maybe
<nsTArray
<uint8_t>>& gfxPlatform::GetCMSOutputProfileData() {
2081 return gCMSOutputProfileData
;
2084 CMSMode
GfxColorManagementMode() {
2085 const auto mode
= StaticPrefs::gfx_color_management_mode();
2086 if (mode
>= 0 && mode
< UnderlyingValue(CMSMode::AllCount
)) {
2087 return CMSMode(mode
);
2089 return CMSMode::Off
;
2092 void gfxPlatform::InitializeCMS() {
2093 if (gCMSInitialized
) {
2097 if (XRE_IsGPUProcess()) {
2098 // Colors in the GPU process should already be managed, so we don't need to
2099 // perform color management there.
2100 gCMSInitialized
= true;
2104 MOZ_DIAGNOSTIC_ASSERT(NS_IsMainThread(),
2105 "CMS should be initialized on the main thread");
2106 if (MOZ_UNLIKELY(!NS_IsMainThread())) {
2110 gCMSMode
= GfxColorManagementMode();
2112 gCMSsRGBProfile
= qcms_profile_sRGB();
2114 /* Determine if we're using the internal override to force sRGB as
2115 an output profile for reftests. See Bug 452125.
2117 Note that we don't normally (outside of tests) set a default value
2118 of this preference, which means nsIPrefBranch::GetBoolPref will
2119 typically throw (and leave its out-param untouched).
2121 if (StaticPrefs::gfx_color_management_force_srgb() ||
2122 StaticPrefs::gfx_color_management_native_srgb()) {
2123 gCMSOutputProfile
= gCMSsRGBProfile
;
2126 if (!gCMSOutputProfile
) {
2127 nsTArray
<uint8_t> outputProfileData
=
2128 gfxPlatform::GetPlatform()->GetPlatformCMSOutputProfileData();
2129 if (!outputProfileData
.IsEmpty()) {
2130 gCMSOutputProfile
= qcms_profile_from_memory_curves_only(
2131 outputProfileData
.Elements(), outputProfileData
.Length());
2135 /* Determine if the profile looks bogus. If so, close the profile
2136 * and use sRGB instead. See bug 460629, */
2137 if (gCMSOutputProfile
&& qcms_profile_is_bogus(gCMSOutputProfile
)) {
2138 NS_ASSERTION(gCMSOutputProfile
!= gCMSsRGBProfile
,
2139 "Builtin sRGB profile tagged as bogus!!!");
2140 qcms_profile_release(gCMSOutputProfile
);
2141 gCMSOutputProfile
= nullptr;
2144 if (!gCMSOutputProfile
) {
2145 gCMSOutputProfile
= gCMSsRGBProfile
;
2148 /* Precache the LUT16 Interpolations for the output profile. See
2149 bug 444661 for details. */
2150 qcms_profile_precache_output_transform(gCMSOutputProfile
);
2152 // Create the RGB transform.
2154 qcms_transform_create(gCMSsRGBProfile
, QCMS_DATA_RGB_8
, gCMSOutputProfile
,
2155 QCMS_DATA_RGB_8
, QCMS_INTENT_PERCEPTUAL
);
2158 gCMSInverseRGBTransform
=
2159 qcms_transform_create(gCMSOutputProfile
, QCMS_DATA_RGB_8
, gCMSsRGBProfile
,
2160 QCMS_DATA_RGB_8
, QCMS_INTENT_PERCEPTUAL
);
2162 // The RGBA transform.
2163 gCMSRGBATransform
= qcms_transform_create(gCMSsRGBProfile
, QCMS_DATA_RGBA_8
,
2164 gCMSOutputProfile
, QCMS_DATA_RGBA_8
,
2165 QCMS_INTENT_PERCEPTUAL
);
2167 // And the BGRA one.
2168 gCMSBGRATransform
= qcms_transform_create(gCMSsRGBProfile
, QCMS_DATA_BGRA_8
,
2169 gCMSOutputProfile
, QCMS_DATA_BGRA_8
,
2170 QCMS_INTENT_PERCEPTUAL
);
2172 // FIXME: We only enable iccv4 after we create the platform profile, to
2173 // wallpaper over bug 1697787.
2175 // This should happen ideally right after setting gCMSMode.
2176 if (StaticPrefs::gfx_color_management_enablev4()) {
2177 qcms_enable_iccv4();
2180 gCMSInitialized
= true;
2183 qcms_transform
* gfxPlatform::GetCMSOSRGBATransform() {
2184 switch (SurfaceFormat::OS_RGBA
) {
2185 case SurfaceFormat::B8G8R8A8
:
2186 return GetCMSBGRATransform();
2187 case SurfaceFormat::R8G8B8A8
:
2188 return GetCMSRGBATransform();
2190 // We do not support color management with big endian.
2195 qcms_data_type
gfxPlatform::GetCMSOSRGBAType() {
2196 switch (SurfaceFormat::OS_RGBA
) {
2197 case SurfaceFormat::B8G8R8A8
:
2198 return QCMS_DATA_BGRA_8
;
2199 case SurfaceFormat::R8G8B8A8
:
2200 return QCMS_DATA_RGBA_8
;
2202 // We do not support color management with big endian.
2203 return QCMS_DATA_RGBA_8
;
2207 /* Shuts down various transforms and profiles for CMS. */
2208 void gfxPlatform::ShutdownCMS() {
2209 if (gCMSRGBTransform
) {
2210 qcms_transform_release(gCMSRGBTransform
);
2211 gCMSRGBTransform
= nullptr;
2213 if (gCMSInverseRGBTransform
) {
2214 qcms_transform_release(gCMSInverseRGBTransform
);
2215 gCMSInverseRGBTransform
= nullptr;
2217 if (gCMSRGBATransform
) {
2218 qcms_transform_release(gCMSRGBATransform
);
2219 gCMSRGBATransform
= nullptr;
2221 if (gCMSBGRATransform
) {
2222 qcms_transform_release(gCMSBGRATransform
);
2223 gCMSBGRATransform
= nullptr;
2225 if (gCMSOutputProfile
) {
2226 qcms_profile_release(gCMSOutputProfile
);
2228 // handle the aliased case
2229 if (gCMSsRGBProfile
== gCMSOutputProfile
) {
2230 gCMSsRGBProfile
= nullptr;
2232 gCMSOutputProfile
= nullptr;
2234 if (gCMSsRGBProfile
) {
2235 qcms_profile_release(gCMSsRGBProfile
);
2236 gCMSsRGBProfile
= nullptr;
2239 // Reset the state variables
2240 gCMSMode
= CMSMode::Off
;
2241 gCMSInitialized
= false;
2244 uint32_t gfxPlatform::GetBidiNumeralOption() {
2245 return StaticPrefs::bidi_numeral();
2249 void gfxPlatform::FlushFontAndWordCaches() {
2250 gfxFontCache
* fontCache
= gfxFontCache::GetCache();
2255 gfxPlatform::PurgeSkiaFontCache();
2259 void gfxPlatform::ForceGlobalReflow(NeedsReframe aNeedsReframe
,
2260 BroadcastToChildren aBroadcastToChildren
) {
2261 MOZ_ASSERT(NS_IsMainThread());
2262 const bool reframe
= aNeedsReframe
== NeedsReframe::Yes
;
2263 // Send a notification that will be observed by PresShells in this process
2265 if (nsCOMPtr
<nsIObserverService
> obs
= services::GetObserverService()) {
2266 char16_t needsReframe
[] = {char16_t(reframe
), 0};
2267 obs
->NotifyObservers(nullptr, "font-info-updated", needsReframe
);
2269 if (XRE_IsParentProcess() &&
2270 aBroadcastToChildren
== BroadcastToChildren::Yes
) {
2271 // Propagate the change to child processes.
2272 for (auto* process
:
2273 dom::ContentParent::AllProcesses(dom::ContentParent::eLive
)) {
2274 Unused
<< process
->SendForceGlobalReflow(reframe
);
2279 void gfxPlatform::FontsPrefsChanged(const char* aPref
) {
2280 NS_ASSERTION(aPref
!= nullptr, "null preference");
2281 if (!strcmp(GFX_DOWNLOADABLE_FONTS_ENABLED
, aPref
)) {
2282 mAllowDownloadableFonts
= UNINITIALIZED_VALUE
;
2283 } else if (!strcmp(GFX_PREF_WORD_CACHE_CHARLIMIT
, aPref
) ||
2284 !strcmp(GFX_PREF_WORD_CACHE_MAXENTRIES
, aPref
) ||
2285 !strcmp(GFX_PREF_GRAPHITE_SHAPING
, aPref
)) {
2286 FlushFontAndWordCaches();
2288 #if defined(XP_DARWIN)
2289 !strcmp(GFX_PREF_CORETEXT_SHAPING
, aPref
) ||
2291 !strcmp("gfx.font_rendering.ahem_antialias_none", aPref
)) {
2292 FlushFontAndWordCaches();
2293 } else if (!strcmp(GFX_PREF_OPENTYPE_SVG
, aPref
)) {
2294 gfxFontCache::GetCache()->Flush();
2295 gfxFontCache::GetCache()->NotifyGlyphsChanged();
2299 mozilla::LogModule
* gfxPlatform::GetLog(eGfxLog aWhichLog
) {
2300 // logs shared across gfx
2301 static LazyLogModule
sFontlistLog("fontlist");
2302 static LazyLogModule
sFontInitLog("fontinit");
2303 static LazyLogModule
sTextrunLog("textrun");
2304 static LazyLogModule
sTextrunuiLog("textrunui");
2305 static LazyLogModule
sCmapDataLog("cmapdata");
2306 static LazyLogModule
sTextPerfLog("textperf");
2308 switch (aWhichLog
) {
2309 case eGfxLog_fontlist
:
2310 return sFontlistLog
;
2311 case eGfxLog_fontinit
:
2312 return sFontInitLog
;
2313 case eGfxLog_textrun
:
2315 case eGfxLog_textrunui
:
2316 return sTextrunuiLog
;
2317 case eGfxLog_cmapdata
:
2318 return sCmapDataLog
;
2319 case eGfxLog_textperf
:
2320 return sTextPerfLog
;
2323 MOZ_ASSERT_UNREACHABLE("Unexpected log type");
2327 RefPtr
<mozilla::gfx::DrawTarget
> gfxPlatform::ScreenReferenceDrawTarget() {
2328 MOZ_ASSERT_IF(XRE_IsContentProcess(), NS_IsMainThread());
2329 return (mScreenReferenceDrawTarget
)
2330 ? mScreenReferenceDrawTarget
2331 : gPlatform
->CreateOffscreenContentDrawTarget(
2332 IntSize(1, 1), SurfaceFormat::B8G8R8A8
, true);
2335 /* static */ RefPtr
<mozilla::gfx::DrawTarget
>
2336 gfxPlatform::ThreadLocalScreenReferenceDrawTarget() {
2337 if (NS_IsMainThread() && gPlatform
) {
2338 return gPlatform
->ScreenReferenceDrawTarget();
2341 gfxPlatformWorker
* platformWorker
= gfxPlatformWorker::Get();
2342 if (platformWorker
) {
2343 return platformWorker
->ScreenReferenceDrawTarget();
2346 return Factory::CreateDrawTarget(BackendType::SKIA
, IntSize(1, 1),
2347 SurfaceFormat::B8G8R8A8
);
2350 mozilla::gfx::SurfaceFormat
gfxPlatform::Optimal2DFormatForContent(
2351 gfxContentType aContent
) {
2353 case gfxContentType::COLOR
:
2354 switch (GetOffscreenFormat()) {
2355 case SurfaceFormat::A8R8G8B8_UINT32
:
2356 return mozilla::gfx::SurfaceFormat::B8G8R8A8
;
2357 case SurfaceFormat::X8R8G8B8_UINT32
:
2358 return mozilla::gfx::SurfaceFormat::B8G8R8X8
;
2359 case SurfaceFormat::R5G6B5_UINT16
:
2360 return mozilla::gfx::SurfaceFormat::R5G6B5_UINT16
;
2362 MOZ_ASSERT_UNREACHABLE(
2363 "unknown gfxImageFormat for "
2364 "gfxContentType::COLOR");
2365 return mozilla::gfx::SurfaceFormat::B8G8R8A8
;
2367 case gfxContentType::ALPHA
:
2368 return mozilla::gfx::SurfaceFormat::A8
;
2369 case gfxContentType::COLOR_ALPHA
:
2370 return mozilla::gfx::SurfaceFormat::B8G8R8A8
;
2372 MOZ_ASSERT_UNREACHABLE("unknown gfxContentType");
2373 return mozilla::gfx::SurfaceFormat::B8G8R8A8
;
2377 gfxImageFormat
gfxPlatform::OptimalFormatForContent(gfxContentType aContent
) {
2379 case gfxContentType::COLOR
:
2380 return GetOffscreenFormat();
2381 case gfxContentType::ALPHA
:
2382 return SurfaceFormat::A8
;
2383 case gfxContentType::COLOR_ALPHA
:
2384 return SurfaceFormat::A8R8G8B8_UINT32
;
2386 MOZ_ASSERT_UNREACHABLE("unknown gfxContentType");
2387 return SurfaceFormat::A8R8G8B8_UINT32
;
2392 * There are a number of layers acceleration (or layers in general) preferences
2393 * that should be consistent for the lifetime of the application (bug 840967).
2394 * As such, we will evaluate them all as soon as one of them is evaluated
2395 * and remember the values. Changing these preferences during the run will
2396 * not have any effect until we restart.
2398 static mozilla::Atomic
<bool> sLayersSupportsHardwareVideoDecoding(false);
2399 static bool sLayersHardwareVideoDecodingFailed
= false;
2401 static mozilla::Atomic
<bool> sLayersAccelerationPrefsInitialized(false);
2403 static void VideoDecodingFailedChangedCallback(const char* aPref
, void*) {
2404 sLayersHardwareVideoDecodingFailed
= Preferences::GetBool(aPref
, false);
2405 gfxPlatform::GetPlatform()->UpdateCanUseHardwareVideoDecoding();
2408 void gfxPlatform::UpdateCanUseHardwareVideoDecoding() {
2409 if (XRE_IsParentProcess()) {
2410 gfxVars::SetCanUseHardwareVideoDecoding(CanUseHardwareVideoDecoding());
2414 void gfxPlatform::UpdateForceSubpixelAAWherePossible() {
2415 bool forceSubpixelAAWherePossible
=
2416 StaticPrefs::gfx_webrender_quality_force_subpixel_aa_where_possible();
2417 gfxVars::SetForceSubpixelAAWherePossible(forceSubpixelAAWherePossible
);
2420 void gfxPlatform::InitAcceleration() {
2421 if (sLayersAccelerationPrefsInitialized
) {
2425 InitCompositorAccelerationPrefs();
2427 // If this is called for the first time on a non-main thread, we're screwed.
2428 // At the moment there's no explicit guarantee that the main thread calls
2429 // this before the compositor thread, but let's at least make the assumption
2431 MOZ_ASSERT(NS_IsMainThread(), "can only initialize prefs on the main thread");
2433 #ifndef MOZ_WIDGET_GTK
2434 nsCOMPtr
<nsIGfxInfo
> gfxInfo
= components::GfxInfo::Service();
2435 nsCString discardFailureId
;
2439 if (XRE_IsParentProcess()) {
2440 gfxVars::SetBrowserTabsRemoteAutostart(BrowserTabsRemoteAutostart());
2441 gfxVars::SetOffscreenFormat(GetOffscreenFormat());
2442 gfxVars::SetRequiresAcceleratedGLContextForCompositorOGL(
2443 RequiresAcceleratedGLContextForCompositorOGL());
2446 gfxInfo
->GetFeatureStatus(nsIGfxInfo::FEATURE_D3D11_KEYED_MUTEX
,
2447 discardFailureId
, &status
))) {
2448 gfxVars::SetAllowD3D11KeyedMutex(status
== nsIGfxInfo::FEATURE_STATUS_OK
);
2450 // If we couldn't properly evaluate the status, err on the side
2451 // of caution and give this functionality to the user.
2452 gfxCriticalNote
<< "Cannot evaluate keyed mutex feature status";
2453 gfxVars::SetAllowD3D11KeyedMutex(true);
2455 if (StaticPrefs::gfx_direct3d11_use_double_buffering()) {
2456 gfxVars::SetUseDoubleBufferingWithCompositor(true);
2461 if (StaticPrefs::media_hardware_video_decoding_enabled_AtStartup()) {
2462 #ifdef MOZ_WIDGET_GTK
2463 sLayersSupportsHardwareVideoDecoding
=
2464 gfxPlatformGtk::GetPlatform()->InitVAAPIConfig(
2466 media_hardware_video_decoding_force_enabled_AtStartup() ||
2467 StaticPrefs::media_ffmpeg_vaapi_enabled_AtStartup());
2471 Preferences::GetBool("media.wmf.dxva.enabled", true) &&
2473 NS_SUCCEEDED(gfxInfo
->GetFeatureStatus(
2474 nsIGfxInfo::FEATURE_HARDWARE_VIDEO_DECODING
, discardFailureId
,
2476 if (status
== nsIGfxInfo::FEATURE_STATUS_OK
||
2478 media_hardware_video_decoding_force_enabled_AtStartup()) {
2479 sLayersSupportsHardwareVideoDecoding
= true;
2483 } else if (XRE_IsParentProcess()) {
2484 FeatureState
& feature
=
2485 gfxConfig::GetFeature(Feature::HARDWARE_VIDEO_DECODING
);
2486 feature
.EnableByDefault();
2487 feature
.UserDisable("User disabled via pref",
2488 "FEATURE_HARDWARE_VIDEO_DECODING_PREF_DISABLED"_ns
);
2491 sLayersAccelerationPrefsInitialized
= true;
2493 if (XRE_IsParentProcess()) {
2494 Preferences::RegisterCallbackAndCall(
2495 VideoDecodingFailedChangedCallback
,
2496 "media.hardware-video-decoding.failed");
2497 InitGPUProcessPrefs();
2499 FeatureState
& feature
= gfxConfig::GetFeature(Feature::REMOTE_CANVAS
);
2500 feature
.SetDefault(StaticPrefs::gfx_canvas_remote_AtStartup(),
2501 FeatureStatus::Disabled
, "Disabled via pref");
2503 if (!gfxConfig::IsEnabled(Feature::GPU_PROCESS
) &&
2504 !StaticPrefs::gfx_canvas_remote_allow_in_parent_AtStartup()) {
2505 feature
.Disable(FeatureStatus::UnavailableNoGpuProcess
,
2506 "Disabled without GPU process",
2507 "FEATURE_REMOTE_CANVAS_NO_GPU_PROCESS"_ns
);
2511 gfxConfig::ForceDisable(Feature::REMOTE_CANVAS
, FeatureStatus::Blocked
,
2512 "Platform not supported",
2513 "FEATURE_REMOTE_CANVAS_NOT_WINDOWS"_ns
);
2516 gfxVars::SetRemoteCanvasEnabled(feature
.IsEnabled());
2520 void gfxPlatform::InitGPUProcessPrefs() {
2521 // We want to hide this from about:support, so only set a default if the
2522 // pref is known to be true.
2523 if (!StaticPrefs::layers_gpu_process_enabled_AtStartup() &&
2524 !StaticPrefs::layers_gpu_process_force_enabled_AtStartup()) {
2528 FeatureState
& gpuProc
= gfxConfig::GetFeature(Feature::GPU_PROCESS
);
2530 // We require E10S - otherwise, there is very little benefit to the GPU
2531 // process, since the UI process must still use acceleration for
2533 if (!BrowserTabsRemoteAutostart()) {
2534 gpuProc
.DisableByDefault(FeatureStatus::Unavailable
,
2535 "Multi-process mode is not enabled",
2536 "FEATURE_FAILURE_NO_E10S"_ns
);
2538 gpuProc
.SetDefaultFromPref(
2539 StaticPrefs::GetPrefName_layers_gpu_process_enabled(), true,
2540 StaticPrefs::GetPrefDefault_layers_gpu_process_enabled());
2543 if (StaticPrefs::layers_gpu_process_force_enabled_AtStartup()) {
2544 gpuProc
.UserForceEnable("User force-enabled via pref");
2548 nsCString failureId
;
2549 if (!gfxPlatform::IsGfxInfoStatusOkay(nsIGfxInfo::FEATURE_GPU_PROCESS
,
2550 &message
, failureId
)) {
2551 gpuProc
.Disable(FeatureStatus::Blocklisted
, message
.get(), failureId
);
2556 gpuProc
.ForceDisable(FeatureStatus::Blocked
, "Headless mode is enabled",
2557 "FEATURE_FAILURE_HEADLESS_MODE"_ns
);
2561 InitPlatformGPUProcessPrefs();
2564 void gfxPlatform::InitCompositorAccelerationPrefs() {
2565 const char* acceleratedEnv
= PR_GetEnv("MOZ_ACCELERATED");
2567 FeatureState
& feature
= gfxConfig::GetFeature(Feature::HW_COMPOSITING
);
2569 // Base value - does the platform allow acceleration?
2570 if (feature
.SetDefault(AccelerateLayersByDefault(), FeatureStatus::Blocked
,
2571 "Acceleration blocked by platform")) {
2573 layers_acceleration_disabled_AtStartup_DoNotUseDirectly()) {
2574 feature
.UserDisable("Disabled by layers.acceleration.disabled=true",
2575 "FEATURE_FAILURE_COMP_PREF"_ns
);
2576 } else if (acceleratedEnv
&& *acceleratedEnv
== '0') {
2577 feature
.UserDisable("Disabled by envvar", "FEATURE_FAILURE_COMP_ENV"_ns
);
2580 if (acceleratedEnv
&& *acceleratedEnv
== '1') {
2581 feature
.UserEnable("Enabled by envvar");
2585 // This has specific meaning elsewhere, so we always record it.
2587 layers_acceleration_force_enabled_AtStartup_DoNotUseDirectly()) {
2588 feature
.UserForceEnable("Force-enabled by pref");
2591 // Safe, headless, and record/replay modes override everything.
2593 feature
.ForceDisable(FeatureStatus::Blocked
,
2594 "Acceleration blocked by safe-mode",
2595 "FEATURE_FAILURE_COMP_SAFEMODE"_ns
);
2598 feature
.ForceDisable(FeatureStatus::Blocked
,
2599 "Acceleration blocked by headless mode",
2600 "FEATURE_FAILURE_COMP_HEADLESSMODE"_ns
);
2605 bool gfxPlatform::WebRenderPrefEnabled() {
2606 return StaticPrefs::gfx_webrender_all_AtStartup();
2610 bool gfxPlatform::WebRenderEnvvarEnabled() {
2611 const char* env
= PR_GetEnv("MOZ_WEBRENDER");
2612 return (env
&& *env
== '1');
2615 /* static */ const char* gfxPlatform::WebRenderResourcePathOverride() {
2616 const char* resourcePath
= PR_GetEnv("WR_RESOURCE_PATH");
2617 if (!resourcePath
|| resourcePath
[0] == '\0') {
2620 return resourcePath
;
2623 void gfxPlatform::InitWebRenderConfig() {
2624 bool prefEnabled
= WebRenderPrefEnabled();
2625 bool envvarEnabled
= WebRenderEnvvarEnabled();
2627 // WR? WR+ => means WR was enabled on qualified hardware
2628 // WR! WR+ => means WR was enabled via gfx.webrender.{all,enabled} or
2629 // envvar, possibly on unqualified hardware
2630 // In all cases WR- means WR was not enabled, for one of many possible
2631 // reasons. Prior to bug 1523788 landing the gfx.webrender.{all,enabled}
2632 // prefs only worked on Nightly so keep that in mind when looking at older
2634 ScopedGfxFeatureReporter
reporter("WR", prefEnabled
|| envvarEnabled
);
2635 if (!XRE_IsParentProcess()) {
2636 // The parent process runs through all the real decision-making code
2637 // later in this function. For other processes we still want to report
2638 // the state of the feature for crash reports.
2639 reporter
.SetSuccessful();
2643 // Update the gfxConfig feature states.
2644 gfxConfigManager manager
;
2646 manager
.ConfigureWebRender();
2648 bool hasHardware
= gfxConfig::IsEnabled(Feature::WEBRENDER
);
2650 #ifdef MOZ_WIDGET_GTK
2651 // We require a hardware driver to back the GL context unless the user forced
2653 if (!gfxConfig::IsForcedOnByUser(Feature::WEBRENDER
) &&
2654 StaticPrefs::gfx_webrender_reject_software_driver_AtStartup()) {
2655 gfxVars::SetWebRenderRequiresHardwareDriver(true);
2660 if (gfxConfig::IsEnabled(Feature::WEBRENDER_ANGLE
)) {
2661 gfxVars::SetUseWebRenderANGLE(true);
2665 if (gfxConfig::IsEnabled(Feature::WEBRENDER_SHADER_CACHE
)) {
2666 gfxVars::SetUseWebRenderProgramBinaryDisk(true);
2669 gfxVars::SetUseWebRenderOptimizedShaders(
2670 gfxConfig::IsEnabled(Feature::WEBRENDER_OPTIMIZED_SHADERS
));
2672 gfxVars::SetUseSoftwareWebRender(!hasHardware
);
2674 Preferences::RegisterPrefixCallbackAndCall(SwapIntervalPrefChangeCallback
,
2675 "gfx.swap-interval");
2677 reporter
.SetSuccessful();
2679 Preferences::RegisterPrefixCallbackAndCall(WebRenderDebugPrefChangeCallback
,
2682 RegisterWebRenderBoolParamCallback();
2684 Preferences::RegisterPrefixCallbackAndCall(
2685 WebRendeProfilerUIPrefChangeCallback
, "gfx.webrender.debug.profiler-ui");
2686 Preferences::RegisterCallback(
2687 WebRenderQualityPrefChangeCallback
,
2690 GetPrefName_gfx_webrender_quality_force_subpixel_aa_where_possible()));
2692 Preferences::RegisterCallback(
2693 WebRenderBatchingPrefChangeCallback
,
2695 StaticPrefs::GetPrefName_gfx_webrender_batching_lookback()));
2697 Preferences::RegisterCallbackAndCall(
2698 WebRenderBlobTileSizePrefChangeCallback
,
2700 StaticPrefs::GetPrefName_gfx_webrender_blob_tile_size()));
2702 Preferences::RegisterCallbackAndCall(
2703 WebRenderUploadThresholdPrefChangeCallback
,
2705 StaticPrefs::GetPrefName_gfx_webrender_batched_upload_threshold()));
2707 if (WebRenderResourcePathOverride()) {
2708 CrashReporter::RecordAnnotationBool(
2709 CrashReporter::Annotation::IsWebRenderResourcePathOverridden
, true);
2712 UpdateForceSubpixelAAWherePossible();
2714 #if defined(MOZ_WIDGET_ANDROID) || defined(MOZ_WIDGET_GTK)
2715 if (StaticPrefs::gfx_webrender_software_opengl_AtStartup()) {
2716 gfxVars::SetAllowSoftwareWebRenderOGL(true);
2721 if (gfxConfig::IsEnabled(Feature::WEBRENDER_DCOMP_PRESENT
)) {
2722 gfxVars::SetUseWebRenderDCompWin(true);
2724 if (StaticPrefs::gfx_webrender_software_d3d11_AtStartup()) {
2725 gfxVars::SetAllowSoftwareWebRenderD3D11(true);
2728 const bool overlaySupported
=
2729 IsWin10AnniversaryUpdateOrLater() &&
2730 gfxConfig::IsEnabled(Feature::WEBRENDER_COMPOSITOR
);
2731 MOZ_ASSERT_IF(overlaySupported
,
2732 gfxConfig::IsEnabled(Feature::WEBRENDER_DCOMP_PRESENT
));
2734 bool useVideoHwOverlay
= false;
2735 if (StaticPrefs::gfx_webrender_dcomp_video_hw_overlay_win_AtStartup()) {
2736 if (overlaySupported
) {
2737 useVideoHwOverlay
= true;
2740 if (useVideoHwOverlay
&&
2742 gfx_webrender_dcomp_video_hw_overlay_win_force_enabled_AtStartup()) {
2743 nsCString failureId
;
2745 const nsCOMPtr
<nsIGfxInfo
> gfxInfo
= components::GfxInfo::Service();
2746 if (NS_FAILED(gfxInfo
->GetFeatureStatus(nsIGfxInfo::FEATURE_VIDEO_OVERLAY
,
2747 failureId
, &status
))) {
2748 FeatureState
& feature
=
2749 gfxConfig::GetFeature(Feature::VIDEO_HARDWARE_OVERLAY
);
2750 feature
.DisableByDefault(FeatureStatus::BlockedNoGfxInfo
,
2751 "gfxInfo is broken",
2752 "FEATURE_FAILURE_WR_NO_GFX_INFO"_ns
);
2753 useVideoHwOverlay
= false;
2755 if (status
!= nsIGfxInfo::FEATURE_STATUS_OK
) {
2756 FeatureState
& feature
=
2757 gfxConfig::GetFeature(Feature::VIDEO_HARDWARE_OVERLAY
);
2758 feature
.DisableByDefault(FeatureStatus::Blocked
,
2759 "Blocklisted by gfxInfo", failureId
);
2760 useVideoHwOverlay
= false;
2764 } else if (overlaySupported
) {
2765 FeatureState
& feature
=
2766 gfxConfig::GetFeature(Feature::VIDEO_HARDWARE_OVERLAY
);
2767 feature
.DisableByDefault(FeatureStatus::Blocked
, "Disabled by pref",
2768 "FEATURE_FAILURE_DISABLED_BY_PREF"_ns
);
2771 if (useVideoHwOverlay
) {
2772 FeatureState
& feature
=
2773 gfxConfig::GetFeature(Feature::VIDEO_HARDWARE_OVERLAY
);
2774 feature
.EnableByDefault();
2775 gfxVars::SetUseWebRenderDCompVideoHwOverlayWin(true);
2778 bool useVideoSwOverlay
= false;
2779 if (overlaySupported
&&
2780 StaticPrefs::gfx_webrender_dcomp_video_sw_overlay_win_AtStartup()) {
2781 useVideoSwOverlay
= true;
2783 if (useVideoSwOverlay
&&
2785 gfx_webrender_dcomp_video_sw_overlay_win_force_enabled_AtStartup()) {
2786 nsCString failureId
;
2788 const nsCOMPtr
<nsIGfxInfo
> gfxInfo
= components::GfxInfo::Service();
2789 if (NS_FAILED(gfxInfo
->GetFeatureStatus(
2790 nsIGfxInfo::FEATURE_VIDEO_SOFTWARE_OVERLAY
, failureId
,
2792 FeatureState
& feature
=
2793 gfxConfig::GetFeature(Feature::VIDEO_SOFTWARE_OVERLAY
);
2794 feature
.DisableByDefault(FeatureStatus::BlockedNoGfxInfo
,
2795 "gfxInfo is broken",
2796 "FEATURE_FAILURE_WR_NO_GFX_INFO"_ns
);
2797 useVideoSwOverlay
= false;
2799 if (status
!= nsIGfxInfo::FEATURE_STATUS_OK
) {
2800 FeatureState
& feature
=
2801 gfxConfig::GetFeature(Feature::VIDEO_SOFTWARE_OVERLAY
);
2802 feature
.DisableByDefault(FeatureStatus::Blocked
,
2803 "Blocklisted by gfxInfo", failureId
);
2804 useVideoSwOverlay
= false;
2808 } else if (overlaySupported
) {
2809 FeatureState
& feature
=
2810 gfxConfig::GetFeature(Feature::VIDEO_SOFTWARE_OVERLAY
);
2811 feature
.DisableByDefault(FeatureStatus::Blocked
, "Disabled by pref",
2812 "FEATURE_FAILURE_DISABLED_BY_PREF"_ns
);
2815 if (useVideoSwOverlay
) {
2816 FeatureState
& feature
=
2817 gfxConfig::GetFeature(Feature::VIDEO_SOFTWARE_OVERLAY
);
2818 feature
.EnableByDefault();
2819 gfxVars::SetUseWebRenderDCompVideoSwOverlayWin(true);
2822 bool useHwVideoZeroCopy
= false;
2823 if (StaticPrefs::media_wmf_zero_copy_nv12_textures_AtStartup()) {
2825 useHwVideoZeroCopy
= true;
2828 if (useHwVideoZeroCopy
&&
2830 media_wmf_zero_copy_nv12_textures_force_enabled_AtStartup()) {
2831 nsCString failureId
;
2833 const nsCOMPtr
<nsIGfxInfo
> gfxInfo
= components::GfxInfo::Service();
2834 if (NS_FAILED(gfxInfo
->GetFeatureStatus(
2835 nsIGfxInfo::FEATURE_HW_DECODED_VIDEO_ZERO_COPY
, failureId
,
2837 FeatureState
& feature
=
2838 gfxConfig::GetFeature(Feature::HW_DECODED_VIDEO_ZERO_COPY
);
2839 feature
.DisableByDefault(FeatureStatus::BlockedNoGfxInfo
,
2840 "gfxInfo is broken",
2841 "FEATURE_FAILURE_WR_NO_GFX_INFO"_ns
);
2842 useHwVideoZeroCopy
= false;
2844 if (status
!= nsIGfxInfo::FEATURE_ALLOW_ALWAYS
) {
2845 FeatureState
& feature
=
2846 gfxConfig::GetFeature(Feature::HW_DECODED_VIDEO_ZERO_COPY
);
2847 feature
.DisableByDefault(FeatureStatus::Blocked
,
2848 "Blocklisted by gfxInfo", failureId
);
2849 useHwVideoZeroCopy
= false;
2855 if (useHwVideoZeroCopy
) {
2856 FeatureState
& feature
=
2857 gfxConfig::GetFeature(Feature::HW_DECODED_VIDEO_ZERO_COPY
);
2858 feature
.EnableByDefault();
2859 gfxVars::SetHwDecodedVideoZeroCopy(true);
2862 bool reuseDecoderDevice
= false;
2863 if (StaticPrefs::gfx_direct3d11_reuse_decoder_device_AtStartup()) {
2864 reuseDecoderDevice
= true;
2866 if (reuseDecoderDevice
&&
2868 gfx_direct3d11_reuse_decoder_device_force_enabled_AtStartup()) {
2869 nsCString failureId
;
2871 const nsCOMPtr
<nsIGfxInfo
> gfxInfo
= components::GfxInfo::Service();
2872 if (NS_FAILED(gfxInfo
->GetFeatureStatus(
2873 nsIGfxInfo::FEATURE_REUSE_DECODER_DEVICE
, failureId
, &status
))) {
2874 FeatureState
& feature
=
2875 gfxConfig::GetFeature(Feature::REUSE_DECODER_DEVICE
);
2876 feature
.DisableByDefault(FeatureStatus::BlockedNoGfxInfo
,
2877 "gfxInfo is broken",
2878 "FEATURE_FAILURE_WR_NO_GFX_INFO"_ns
);
2879 reuseDecoderDevice
= false;
2881 if (status
!= nsIGfxInfo::FEATURE_STATUS_OK
) {
2882 FeatureState
& feature
=
2883 gfxConfig::GetFeature(Feature::REUSE_DECODER_DEVICE
);
2884 feature
.DisableByDefault(FeatureStatus::Blocked
,
2885 "Blocklisted by gfxInfo", failureId
);
2886 reuseDecoderDevice
= false;
2892 if (reuseDecoderDevice
) {
2893 FeatureState
& feature
=
2894 gfxConfig::GetFeature(Feature::REUSE_DECODER_DEVICE
);
2895 feature
.EnableByDefault();
2896 gfxVars::SetReuseDecoderDevice(true);
2899 if (Preferences::GetBool("gfx.webrender.flip-sequential", false)) {
2900 if (gfxVars::UseWebRenderANGLE()) {
2901 gfxVars::SetUseWebRenderFlipSequentialWin(true);
2904 if (Preferences::GetBool("gfx.webrender.triple-buffering.enabled", false)) {
2905 if (gfxVars::UseWebRenderDCompWin() ||
2906 gfxVars::UseWebRenderFlipSequentialWin()) {
2907 gfxVars::SetUseWebRenderTripleBufferingWin(true);
2912 bool allowOverlayVpAutoHDR
= false;
2913 if (StaticPrefs::gfx_webrender_overlay_vp_auto_hdr_AtStartup()) {
2914 allowOverlayVpAutoHDR
= true;
2916 nsCString failureId
;
2918 const nsCOMPtr
<nsIGfxInfo
> gfxInfo
= components::GfxInfo::Service();
2919 if (NS_FAILED(gfxInfo
->GetFeatureStatus(
2920 nsIGfxInfo::FEATURE_OVERLAY_VP_AUTO_HDR
, failureId
, &status
))) {
2921 allowOverlayVpAutoHDR
= false;
2923 if (status
!= nsIGfxInfo::FEATURE_STATUS_OK
) {
2924 allowOverlayVpAutoHDR
= false;
2929 if (allowOverlayVpAutoHDR
) {
2930 gfxVars::SetWebRenderOverlayVpAutoHDR(true);
2933 bool allowOverlayVpSuperResolution
= false;
2934 if (StaticPrefs::gfx_webrender_overlay_vp_super_resolution_AtStartup()) {
2935 allowOverlayVpSuperResolution
= true;
2937 nsCString failureId
;
2939 const nsCOMPtr
<nsIGfxInfo
> gfxInfo
= components::GfxInfo::Service();
2940 if (NS_FAILED(gfxInfo
->GetFeatureStatus(
2941 nsIGfxInfo::FEATURE_OVERLAY_VP_SUPER_RESOLUTION
, failureId
,
2943 allowOverlayVpSuperResolution
= false;
2945 if (status
!= nsIGfxInfo::FEATURE_STATUS_OK
) {
2946 allowOverlayVpSuperResolution
= false;
2951 if (allowOverlayVpSuperResolution
) {
2952 gfxVars::SetWebRenderOverlayVpSuperResolution(true);
2955 if (gfxConfig::IsEnabled(Feature::WEBRENDER_COMPOSITOR
)) {
2956 gfxVars::SetUseWebRenderCompositor(true);
2959 Telemetry::ScalarSet(
2960 Telemetry::ScalarID::GFX_OS_COMPOSITOR
,
2961 gfx::gfxConfig::IsEnabled(gfx::Feature::WEBRENDER_COMPOSITOR
));
2963 if (gfxConfig::IsEnabled(Feature::WEBRENDER_PARTIAL
)) {
2964 gfxVars::SetWebRenderMaxPartialPresentRects(
2965 StaticPrefs::gfx_webrender_max_partial_present_rects_AtStartup());
2968 // Set features that affect WR's RendererOptions
2969 gfxVars::SetUseGLSwizzle(
2970 IsFeatureSupported(nsIGfxInfo::FEATURE_GL_SWIZZLE
, true));
2971 gfxVars::SetUseWebRenderScissoredCacheClears(gfx::gfxConfig::IsEnabled(
2972 gfx::Feature::WEBRENDER_SCISSORED_CACHE_CLEARS
));
2974 // The RemoveShaderCacheFromDiskIfNecessary() needs to be called after
2975 // WebRenderConfig initialization.
2976 gfxUtils::RemoveShaderCacheFromDiskIfNecessary();
2979 void gfxPlatform::InitHardwareVideoConfig() {
2980 if (!XRE_IsParentProcess()) {
2984 #ifdef MOZ_WIDGET_GTK
2985 // We don't want to expose codec info if whole HW decoding is disabled.
2986 if (!sLayersSupportsHardwareVideoDecoding
) {
2992 nsCString failureId
;
2994 FeatureState
& featureVP8
= gfxConfig::GetFeature(Feature::VP8_HW_DECODE
);
2995 featureVP8
.EnableByDefault();
2997 if (!IsGfxInfoStatusOkay(nsIGfxInfo::FEATURE_VP8_HW_DECODE
, &message
,
2999 featureVP8
.Disable(FeatureStatus::Blocklisted
, message
.get(), failureId
);
3001 gfxVars::SetUseVP8HwDecode(featureVP8
.IsEnabled());
3003 FeatureState
& featureVP9
= gfxConfig::GetFeature(Feature::VP9_HW_DECODE
);
3004 featureVP9
.EnableByDefault();
3006 if (!IsGfxInfoStatusOkay(nsIGfxInfo::FEATURE_VP9_HW_DECODE
, &message
,
3008 featureVP9
.Disable(FeatureStatus::Blocklisted
, message
.get(), failureId
);
3010 gfxVars::SetUseVP9HwDecode(featureVP9
.IsEnabled());
3012 // H264_HW_DECODE/AV1_HW_DECODE is used on Linux only right now.
3013 #ifdef MOZ_WIDGET_GTK
3014 FeatureState
& featureH264
= gfxConfig::GetFeature(Feature::H264_HW_DECODE
);
3015 featureH264
.EnableByDefault();
3017 if (!IsGfxInfoStatusOkay(nsIGfxInfo::FEATURE_H264_HW_DECODE
, &message
,
3019 featureH264
.Disable(FeatureStatus::Blocklisted
, message
.get(), failureId
);
3021 gfxVars::SetUseH264HwDecode(featureH264
.IsEnabled());
3023 FeatureState
& featureAV1
= gfxConfig::GetFeature(Feature::AV1_HW_DECODE
);
3024 featureAV1
.EnableByDefault();
3026 if (!IsGfxInfoStatusOkay(nsIGfxInfo::FEATURE_AV1_HW_DECODE
, &message
,
3028 featureAV1
.Disable(FeatureStatus::Blocklisted
, message
.get(), failureId
);
3030 gfxVars::SetUseAV1HwDecode(featureAV1
.IsEnabled());
3034 void gfxPlatform::InitWebGLConfig() {
3035 if (!XRE_IsParentProcess()) return;
3037 const nsCOMPtr
<nsIGfxInfo
> gfxInfo
= components::GfxInfo::Service();
3039 const auto IsFeatureOk
= [&](const int32_t feature
) {
3040 nsCString discardFailureId
;
3042 MOZ_RELEASE_ASSERT(NS_SUCCEEDED(
3043 gfxInfo
->GetFeatureStatus(feature
, discardFailureId
, &status
)));
3044 return (status
== nsIGfxInfo::FEATURE_STATUS_OK
);
3047 gfxVars::SetAllowWebgl2(IsFeatureOk(nsIGfxInfo::FEATURE_WEBGL2
));
3048 gfxVars::SetWebglAllowWindowsNativeGl(
3049 IsFeatureOk(nsIGfxInfo::FEATURE_WEBGL_OPENGL
));
3050 gfxVars::SetAllowWebglAccelAngle(
3051 IsFeatureOk(nsIGfxInfo::FEATURE_WEBGL_ANGLE
));
3052 gfxVars::SetWebglUseHardware(
3053 IsFeatureOk(nsIGfxInfo::FEATURE_WEBGL_USE_HARDWARE
));
3056 // Avoid crash for Intel HD Graphics 3000 on OSX. (Bug 1413269)
3057 nsString vendorID
, deviceID
;
3058 gfxInfo
->GetAdapterVendorID(vendorID
);
3059 gfxInfo
->GetAdapterDeviceID(deviceID
);
3060 if (vendorID
.EqualsLiteral("0x8086") &&
3061 (deviceID
.EqualsLiteral("0x0116") ||
3062 deviceID
.EqualsLiteral("0x0126"))) {
3063 gfxVars::SetWebglAllowCoreProfile(false);
3067 bool allowWebGLOop
=
3068 IsFeatureOk(nsIGfxInfo::FEATURE_ALLOW_WEBGL_OUT_OF_PROCESS
);
3070 gfxVars::SetAllowWebglOop(allowWebGLOop
);
3072 // On android, enable out-of-process WebGL only when GPU process exists.
3073 gfxVars::SetAllowWebglOop(allowWebGLOop
&&
3074 gfxConfig::IsEnabled(Feature::GPU_PROCESS
));
3075 // Enable gl::SharedSurface of AndroidHardwareBuffer when API version is 26+
3076 // and out-of-process WebGL is enabled.
3077 #ifdef MOZ_WIDGET_ANDROID
3078 if (gfxVars::AllowWebglOop() && jni::GetAPIVersion() >= 26 &&
3079 StaticPrefs::webgl_out_of_process_enable_ahardwarebuffer_AtStartup()) {
3080 gfxVars::SetUseAHardwareBufferSharedSurfaceWebglOop(true);
3085 bool threadsafeGL
= IsFeatureOk(nsIGfxInfo::FEATURE_THREADSAFE_GL
);
3086 threadsafeGL
|= StaticPrefs::webgl_threadsafe_gl_force_enabled_AtStartup();
3087 threadsafeGL
&= !StaticPrefs::webgl_threadsafe_gl_force_disabled_AtStartup();
3088 gfxVars::SetSupportsThreadsafeGL(threadsafeGL
);
3090 FeatureState
& feature
=
3091 gfxConfig::GetFeature(Feature::CANVAS_RENDERER_THREAD
);
3092 if (!threadsafeGL
) {
3093 feature
.DisableByDefault(FeatureStatus::Blocked
, "Thread unsafe GL",
3094 "FEATURE_FAILURE_THREAD_UNSAFE_GL"_ns
);
3095 } else if (!StaticPrefs::webgl_use_canvas_render_thread_AtStartup()) {
3096 feature
.DisableByDefault(FeatureStatus::Blocked
, "Disabled by pref",
3097 "FEATURE_FAILURE_DISABLED_BY_PREF"_ns
);
3099 feature
.EnableByDefault();
3101 gfxVars::SetUseCanvasRenderThread(feature
.IsEnabled());
3103 bool webglOopAsyncPresentForceSync
=
3104 (threadsafeGL
&& !gfxVars::UseCanvasRenderThread()) ||
3105 StaticPrefs::webgl_out_of_process_async_present_force_sync();
3106 gfxVars::SetWebglOopAsyncPresentForceSync(webglOopAsyncPresentForceSync
);
3109 // Don't enable robust buffer access on Adreno 620 and 630 devices.
3110 // It causes the linking of some shaders to fail. See bug 1485441 and
3112 nsAutoString renderer
;
3113 gfxInfo
->GetAdapterDeviceID(renderer
);
3114 if ((renderer
.Find(u
"Adreno (TM) 620") != -1) ||
3115 (renderer
.Find(u
"Adreno (TM) 630") != -1)) {
3116 gfxVars::SetAllowEglRbab(false);
3121 nsCString discardFailureId
;
3123 FeatureState
& feature
=
3124 gfxConfig::GetFeature(Feature::DMABUF_SURFACE_EXPORT
);
3126 gfxInfo
->GetFeatureStatus(nsIGfxInfo::FEATURE_DMABUF_SURFACE_EXPORT
,
3127 discardFailureId
, &status
)) ||
3128 status
!= nsIGfxInfo::FEATURE_STATUS_OK
) {
3129 feature
.DisableByDefault(FeatureStatus::Blocked
, "Blocklisted by gfxInfo",
3131 gfxVars::SetUseDMABufSurfaceExport(false);
3133 feature
.EnableByDefault();
3138 void gfxPlatform::InitWebGPUConfig() {
3139 if (!XRE_IsParentProcess()) {
3143 FeatureState
& feature
= gfxConfig::GetFeature(Feature::WEBGPU
);
3144 feature
.EnableByDefault();
3147 nsCString failureId
;
3148 if (!IsGfxInfoStatusOkay(nsIGfxInfo::FEATURE_WEBGPU
, &message
, failureId
)) {
3149 if (StaticPrefs::gfx_webgpu_ignore_blocklist_AtStartup()) {
3150 feature
.UserForceEnable(
3151 "Ignoring blocklist entry because gfx.webgpu.ignore-blocklist is "
3155 feature
.Disable(FeatureStatus::Blocklisted
, message
.get(), failureId
);
3158 #ifdef RELEASE_OR_BETA
3159 feature
.ForceDisable(FeatureStatus::Blocked
,
3160 "WebGPU cannot be enabled in release or beta",
3161 "WEBGPU_DISABLE_RELEASE_OR_BETA"_ns
);
3164 gfxVars::SetAllowWebGPU(feature
.IsEnabled());
3167 if (IsWin10CreatorsUpdateOrLater() &&
3168 StaticPrefs::dom_webgpu_allow_present_without_readback()) {
3169 gfxVars::SetAllowWebGPUPresentWithoutReadback(true);
3175 static void WindowOcclusionPrefChangeCallback(const char* aPref
, void*) {
3176 const char* env
= PR_GetEnv("MOZ_WINDOW_OCCLUSION");
3178 // env has a higher priority than pref.
3182 FeatureState
& feature
= gfxConfig::GetFeature(Feature::WINDOW_OCCLUSION
);
3184 StaticPrefs::widget_windows_window_occlusion_tracking_enabled();
3186 printf_stderr("Dynamically enable window occlusion %d\n", enabled
);
3188 // Update feature before calling WinUtils::EnableWindowOcclusion()
3190 feature
.UserEnable("User enabled by pref");
3192 feature
.UserDisable("User disabled via pref",
3193 "FEATURE_FAILURE_PREF_DISABLED"_ns
);
3195 widget::WinUtils::EnableWindowOcclusion(enabled
);
3199 void gfxPlatform::InitWindowOcclusionConfig() {
3200 if (!XRE_IsParentProcess()) {
3204 FeatureState
& feature
= gfxConfig::GetFeature(Feature::WINDOW_OCCLUSION
);
3205 feature
.SetDefaultFromPref(
3207 GetPrefName_widget_windows_window_occlusion_tracking_enabled(),
3210 GetPrefDefault_widget_windows_window_occlusion_tracking_enabled());
3212 const char* env
= PR_GetEnv("MOZ_WINDOW_OCCLUSION");
3215 feature
.UserForceEnable("Force enabled by envvar");
3217 feature
.UserDisable("Force disabled by envvar",
3218 "FEATURE_FAILURE_OCCL_ENV"_ns
);
3222 Preferences::RegisterCallback(
3223 WindowOcclusionPrefChangeCallback
,
3226 GetPrefName_widget_windows_window_occlusion_tracking_enabled()));
3230 static void BackdropFilterPrefChangeCallback(const char*, void*) {
3231 FeatureState
& feature
= gfxConfig::GetFeature(Feature::BACKDROP_FILTER
);
3233 // We need to reset because the user status needs to be set before the
3234 // environment status, but the environment status comes from the blocklist,
3235 // and the user status can be updated after the fact.
3237 feature
.EnableByDefault();
3239 if (StaticPrefs::layout_css_backdrop_filter_force_enabled()) {
3240 feature
.UserForceEnable("Force enabled by pref");
3244 nsCString failureId
;
3245 if (!gfxPlatform::IsGfxInfoStatusOkay(nsIGfxInfo::FEATURE_BACKDROP_FILTER
,
3246 &message
, failureId
)) {
3247 feature
.Disable(FeatureStatus::Blocklisted
, message
.get(), failureId
);
3250 // This may still be gated by the layout.css.backdrop-filter.enabled pref but
3251 // the test infrastructure is very sensitive to how changes to that pref
3252 // propagate, so we don't include them in the gfxVars/gfxFeature.
3253 gfxVars::SetAllowBackdropFilter(feature
.IsEnabled());
3256 void gfxPlatform::InitBackdropFilterConfig() {
3257 // This would ideally be in the nsCSSProps code
3258 // but nsCSSProps is initialized before gfxPlatform
3259 // so it has to be done here.
3260 gfxVars::AddReceiver(&nsCSSProps::GfxVarReceiver());
3262 if (!XRE_IsParentProcess()) {
3263 // gfxVars doesn't notify receivers when initialized on content processes
3264 // we need to explicitly recompute backdrop-filter's enabled state here.
3265 nsCSSProps::RecomputeEnabledState(
3266 StaticPrefs::GetPrefName_layout_css_backdrop_filter_enabled());
3270 BackdropFilterPrefChangeCallback(nullptr, nullptr);
3272 Preferences::RegisterCallback(
3273 BackdropFilterPrefChangeCallback
,
3275 StaticPrefs::GetPrefName_layout_css_backdrop_filter_force_enabled()));
3278 static void AcceleratedCanvas2DPrefChangeCallback(const char*, void*) {
3279 FeatureState
& feature
= gfxConfig::GetFeature(Feature::ACCELERATED_CANVAS2D
);
3281 // Reset to track toggling prefs and ensure force-enable does not happen
3285 // gfx.canvas.accelerated pref controls whether platform enables the feature,
3286 // but it still allows blocklisting to override it later.
3287 feature
.SetDefaultFromPref(
3288 StaticPrefs::GetPrefName_gfx_canvas_accelerated(), true,
3289 StaticPrefs::GetPrefDefault_gfx_canvas_accelerated());
3291 // gfx.canvas.accelerated.force-enabled overrides the blocklist.
3292 if (StaticPrefs::gfx_canvas_accelerated_force_enabled()) {
3293 feature
.UserForceEnable("Force-enabled by pref");
3296 if (kIsAndroid
&& !gfxConfig::IsEnabled(Feature::GPU_PROCESS
)) {
3297 feature
.Disable(FeatureStatus::Blocked
, "Disabled by GPU Process disabled",
3298 "FEATURE_FAILURE_DISABLED_BY_GPU_PROCESS_DISABLED"_ns
);
3299 } else if (!gfxConfig::IsEnabled(Feature::WEBRENDER
)) {
3300 // There isn't much benefit to accelerating Canvas2D if we can't accelerate
3301 // WebRender itself.
3302 feature
.Disable(FeatureStatus::Blocked
, "Disabled by Software WebRender",
3303 "FEATURE_FAILURE_DISABLED_BY_SOFTWARE_WEBRENDER"_ns
);
3306 // Check if blocklisted despite the default pref.
3308 nsCString failureId
;
3309 if (!gfxPlatform::IsGfxInfoStatusOkay(
3310 nsIGfxInfo::FEATURE_ACCELERATED_CANVAS2D
, &message
, failureId
)) {
3311 feature
.Disable(FeatureStatus::Blocklisted
, message
.get(), failureId
);
3314 if (StaticPrefs::gfx_canvas_remote_worker_threads_AtStartup() != 0) {
3315 feature
.ForceDisable(FeatureStatus::Failed
,
3316 "Disabled with non-zero canvas worker threads",
3317 "FEATURE_FAILURE_DISABLE_BY_CANVAS_WORKER_THREADS"_ns
);
3320 gfxVars::SetUseAcceleratedCanvas2D(feature
.IsEnabled());
3323 void gfxPlatform::InitAcceleratedCanvas2DConfig() {
3324 if (!XRE_IsParentProcess()) {
3328 // Decide during pref changes whether or not to enable acceleration. This
3329 // allows easily toggling acceleration on and off to test performance.
3330 AcceleratedCanvas2DPrefChangeCallback(nullptr, nullptr);
3332 Preferences::RegisterCallback(
3333 AcceleratedCanvas2DPrefChangeCallback
,
3334 nsDependentCString(StaticPrefs::GetPrefName_gfx_canvas_accelerated()));
3335 Preferences::RegisterCallback(
3336 AcceleratedCanvas2DPrefChangeCallback
,
3338 StaticPrefs::GetPrefName_gfx_canvas_accelerated_force_enabled()));
3341 bool gfxPlatform::CanUseHardwareVideoDecoding() {
3342 // this function is called from the compositor thread, so it is not
3343 // safe to init the prefs etc. from here.
3344 MOZ_ASSERT(sLayersAccelerationPrefsInitialized
);
3345 return sLayersSupportsHardwareVideoDecoding
&&
3346 !sLayersHardwareVideoDecodingFailed
;
3349 bool gfxPlatform::AccelerateLayersByDefault() {
3350 #if defined(MOZ_GL_PROVIDER) || defined(MOZ_WIDGET_UIKIT)
3358 bool gfxPlatform::UsesOffMainThreadCompositing() {
3359 if (XRE_GetProcessType() == GeckoProcessType_GPU
) {
3363 static bool firstTime
= true;
3364 static bool result
= false;
3367 MOZ_ASSERT(sLayersAccelerationPrefsInitialized
);
3368 result
= gfxVars::BrowserTabsRemoteAutostart() ||
3370 layers_offmainthreadcomposition_force_disabled_AtStartup();
3371 #if defined(MOZ_WIDGET_GTK)
3372 // Linux users who chose OpenGL are being included in OMTC
3373 result
|= StaticPrefs::
3374 layers_acceleration_force_enabled_AtStartup_DoNotUseDirectly();
3383 RefPtr
<mozilla::VsyncDispatcher
> gfxPlatform::GetGlobalVsyncDispatcher() {
3384 MOZ_ASSERT(mVsyncDispatcher
,
3385 "mVsyncDispatcher should have been initialized by ReInitFrameRate "
3386 "during gfxPlatform init");
3387 MOZ_ASSERT(XRE_IsParentProcess());
3388 return mVsyncDispatcher
;
3391 already_AddRefed
<mozilla::gfx::VsyncSource
>
3392 gfxPlatform::GetGlobalHardwareVsyncSource() {
3393 if (!mGlobalHardwareVsyncSource
) {
3394 mGlobalHardwareVsyncSource
= CreateGlobalHardwareVsyncSource();
3396 return do_AddRef(mGlobalHardwareVsyncSource
);
3400 * The preference "layout.frame_rate" has 3 meanings depending on the value:
3402 * -1 = Auto (default), use hardware vsync or software vsync @ 60 hz if hw
3404 * 0 = ASAP mode - used during talos testing.
3405 * X = Software vsync at a rate of X times per second.
3407 already_AddRefed
<mozilla::gfx::VsyncSource
>
3408 gfxPlatform::GetSoftwareVsyncSource() {
3409 if (!mSoftwareVsyncSource
) {
3410 double rateInMS
= 1000.0 / (double)gfxPlatform::GetSoftwareVsyncRate();
3411 mSoftwareVsyncSource
= new mozilla::gfx::SoftwareVsyncSource(
3412 TimeDuration::FromMilliseconds(rateInMS
));
3414 return do_AddRef(mSoftwareVsyncSource
);
3418 bool gfxPlatform::IsInLayoutAsapMode() {
3419 // There are 2 modes of ASAP mode.
3420 // 1 is that the refresh driver and compositor are in lock step
3421 // the second is that the compositor goes ASAP and the refresh driver
3422 // goes at whatever the configurated rate is. This only checks the version
3423 // talos uses, which is the refresh driver and compositor are in lockstep.
3424 // Ignore privacy_resistFingerprinting to preserve ASAP mode there.
3425 return StaticPrefs::layout_frame_rate() == 0;
3428 static int LayoutFrameRateFromPrefs() {
3429 auto val
= StaticPrefs::layout_frame_rate();
3430 if (nsContentUtils::ShouldResistFingerprinting(
3431 "The frame rate is a global property.", RFPTarget::FrameRate
)) {
3438 bool gfxPlatform::ForceSoftwareVsync() {
3439 return LayoutFrameRateFromPrefs() > 0;
3443 int gfxPlatform::GetSoftwareVsyncRate() {
3444 int preferenceRate
= LayoutFrameRateFromPrefs();
3445 if (preferenceRate
<= 0) {
3446 return gfxPlatform::GetDefaultFrameRate();
3448 return preferenceRate
;
3452 int gfxPlatform::GetDefaultFrameRate() { return 60; }
3455 void gfxPlatform::ReInitFrameRate(const char* aPrefIgnored
,
3456 void* aDataIgnored
) {
3457 MOZ_RELEASE_ASSERT(XRE_IsParentProcess());
3459 if (gPlatform
->mSoftwareVsyncSource
) {
3460 // Update the rate of the existing software vsync source.
3461 double rateInMS
= 1000.0 / (double)gfxPlatform::GetSoftwareVsyncRate();
3462 gPlatform
->mSoftwareVsyncSource
->SetVsyncRate(
3463 TimeDuration::FromMilliseconds(rateInMS
));
3466 // Swap out the dispatcher's underlying source.
3467 RefPtr
<VsyncSource
> vsyncSource
=
3468 gfxPlatform::ForceSoftwareVsync()
3469 ? gPlatform
->GetSoftwareVsyncSource()
3470 : gPlatform
->GetGlobalHardwareVsyncSource();
3471 gPlatform
->mVsyncDispatcher
->SetVsyncSource(vsyncSource
);
3474 const char* gfxPlatform::GetAzureCanvasBackend() const {
3475 BackendType backend
{};
3477 if (gfxConfig::IsEnabled(Feature::GPU_PROCESS
)) {
3478 // Assume content process' backend prefs.
3479 BackendPrefsData data
= GetBackendPrefs();
3480 backend
= GetCanvasBackendPref(data
.mCanvasBitmask
);
3481 if (backend
== BackendType::NONE
) {
3482 backend
= data
.mCanvasDefault
;
3485 backend
= mPreferredCanvasBackend
;
3488 return GetBackendName(backend
);
3491 const char* gfxPlatform::GetAzureContentBackend() const {
3492 BackendType backend
{};
3494 if (gfxConfig::IsEnabled(Feature::GPU_PROCESS
)) {
3495 // Assume content process' backend prefs.
3496 BackendPrefsData data
= GetBackendPrefs();
3497 backend
= GetContentBackendPref(data
.mContentBitmask
);
3498 if (backend
== BackendType::NONE
) {
3499 backend
= data
.mContentDefault
;
3502 backend
= mContentBackend
;
3505 return GetBackendName(backend
);
3508 void gfxPlatform::GetAzureBackendInfo(mozilla::widget::InfoObject
& aObj
) {
3509 if (gfxConfig::IsEnabled(Feature::GPU_PROCESS
)) {
3510 aObj
.DefineProperty("AzureCanvasBackend (UI Process)",
3511 GetBackendName(mPreferredCanvasBackend
));
3512 aObj
.DefineProperty("AzureFallbackCanvasBackend (UI Process)",
3513 GetBackendName(mFallbackCanvasBackend
));
3514 aObj
.DefineProperty("AzureContentBackend (UI Process)",
3515 GetBackendName(mContentBackend
));
3517 aObj
.DefineProperty("AzureFallbackCanvasBackend",
3518 GetBackendName(mFallbackCanvasBackend
));
3521 aObj
.DefineProperty("AzureCanvasBackend", GetAzureCanvasBackend());
3522 aObj
.DefineProperty("AzureContentBackend", GetAzureContentBackend());
3525 void gfxPlatform::GetApzSupportInfo(mozilla::widget::InfoObject
& aObj
) {
3526 if (!gfxPlatform::AsyncPanZoomEnabled()) {
3530 if (SupportsApzWheelInput()) {
3531 aObj
.DefineProperty("ApzWheelInput", 1);
3534 if (SupportsApzTouchInput()) {
3535 aObj
.DefineProperty("ApzTouchInput", 1);
3538 if (SupportsApzDragInput()) {
3539 aObj
.DefineProperty("ApzDragInput", 1);
3542 if (SupportsApzKeyboardInput() &&
3543 !StaticPrefs::accessibility_browsewithcaret()) {
3544 aObj
.DefineProperty("ApzKeyboardInput", 1);
3547 if (SupportsApzAutoscrolling()) {
3548 aObj
.DefineProperty("ApzAutoscrollInput", 1);
3551 if (SupportsApzZooming()) {
3552 aObj
.DefineProperty("ApzZoomingInput", 1);
3556 void gfxPlatform::GetFrameStats(mozilla::widget::InfoObject
& aObj
) {
3558 for (FrameStats
& f
: mFrameStats
) {
3559 nsPrintfCString
name("Slow Frame #%02u", ++i
);
3561 nsPrintfCString
value(
3563 "(%s) CONTENT_FRAME_TIME %d - Transaction start %f, main-thread time "
3564 "%f, full paint time %f, Skipped composites %u, Composite start %f, "
3565 "Resource upload time %f, GPU cache upload time %f, Render time %f, "
3566 "Composite time %f",
3567 f
.id().mId
, f
.url().get(), f
.contentFrameTime(),
3568 (f
.transactionStart() - f
.refreshStart()).ToMilliseconds(),
3569 (f
.fwdTime() - f
.transactionStart()).ToMilliseconds(),
3571 ? (f
.sceneBuiltTime() - f
.transactionStart()).ToMilliseconds()
3573 f
.skippedComposites(),
3574 (f
.compositeStart() - f
.refreshStart()).ToMilliseconds(),
3575 f
.resourceUploadTime(), f
.gpuCacheUploadTime(),
3576 (f
.compositeEnd() - f
.renderStart()).ToMilliseconds(),
3577 (f
.compositeEnd() - f
.compositeStart()).ToMilliseconds());
3578 aObj
.DefineProperty(name
.get(), value
.get());
3582 void gfxPlatform::GetCMSSupportInfo(mozilla::widget::InfoObject
& aObj
) {
3583 nsTArray
<uint8_t> outputProfileData
=
3584 gfxPlatform::GetPlatform()->GetPlatformCMSOutputProfileData();
3585 if (outputProfileData
.IsEmpty()) {
3586 nsPrintfCString
msg("Empty profile data");
3587 aObj
.DefineProperty("CMSOutputProfile", msg
.get());
3591 // Some profiles can be quite large. We don't want to include giant profiles
3592 // by default in about:support. For now, we only accept less than 8kiB.
3593 const size_t kMaxProfileSize
= 8192;
3594 if (outputProfileData
.Length() >= kMaxProfileSize
) {
3595 nsPrintfCString
msg("%zu bytes, too large", outputProfileData
.Length());
3596 aObj
.DefineProperty("CMSOutputProfile", msg
.get());
3600 nsString encodedProfile
;
3602 Base64Encode(reinterpret_cast<const char*>(outputProfileData
.Elements()),
3603 outputProfileData
.Length(), encodedProfile
);
3604 if (!NS_SUCCEEDED(rv
)) {
3605 nsPrintfCString
msg("base64 encode failed 0x%08x",
3606 static_cast<uint32_t>(rv
));
3607 aObj
.DefineProperty("CMSOutputProfile", msg
.get());
3611 aObj
.DefineProperty("CMSOutputProfile", encodedProfile
);
3614 void gfxPlatform::GetDisplayInfo(mozilla::widget::InfoObject
& aObj
) {
3615 auto& screens
= widget::ScreenManager::GetSingleton().CurrentScreenList();
3616 aObj
.DefineProperty("DisplayCount", screens
.Length());
3619 for (auto& screen
: screens
) {
3620 const LayoutDeviceIntRect rect
= screen
->GetRect();
3621 nsPrintfCString
value("%dx%d@%dHz scales:%f|%f", rect
.width
, rect
.height
,
3622 screen
->GetRefreshRate(),
3623 screen
->GetContentsScaleFactor(),
3624 screen
->GetDefaultCSSScaleFactor());
3626 aObj
.DefineProperty(nsPrintfCString("Display%zu", i
++).get(),
3627 NS_ConvertUTF8toUTF16(value
));
3630 // Platform display info is only currently used for about:support and getting
3631 // it might fail in a child process anyway.
3632 if (XRE_IsParentProcess()) {
3633 GetPlatformDisplayInfo(aObj
);
3637 void gfxPlatform::GetOverlayInfo(mozilla::widget::InfoObject
& aObj
) {
3638 if (mOverlayInfo
.isNothing()) {
3642 auto toString
= [](mozilla::layers::OverlaySupportType aType
) -> const char* {
3644 case mozilla::layers::OverlaySupportType::None
:
3646 case mozilla::layers::OverlaySupportType::Software
:
3648 case mozilla::layers::OverlaySupportType::Direct
:
3650 case mozilla::layers::OverlaySupportType::Scaling
:
3653 MOZ_ASSERT_UNREACHABLE("Unexpected to be called");
3655 MOZ_CRASH("Incomplete switch");
3658 nsPrintfCString
value("NV12=%s YUV2=%s BGRA8=%s RGB10A2=%s",
3659 toString(mOverlayInfo
.ref().mNv12Overlay
),
3660 toString(mOverlayInfo
.ref().mYuy2Overlay
),
3661 toString(mOverlayInfo
.ref().mBgra8Overlay
),
3662 toString(mOverlayInfo
.ref().mRgb10a2Overlay
));
3664 aObj
.DefineProperty("OverlaySupport", NS_ConvertUTF8toUTF16(value
));
3667 void gfxPlatform::GetSwapChainInfo(mozilla::widget::InfoObject
& aObj
) {
3668 if (mSwapChainInfo
.isNothing()) {
3672 auto toString
= [](bool aTearingSupported
) -> const char* {
3673 if (aTearingSupported
) {
3676 return "Not Supported";
3679 nsPrintfCString
value("%s", toString(mSwapChainInfo
.ref().mTearingSupported
));
3681 aObj
.DefineProperty("SwapChainTearingSupport", NS_ConvertUTF8toUTF16(value
));
3684 class FrameStatsComparator
{
3686 bool Equals(const FrameStats
& aA
, const FrameStats
& aB
) const {
3687 return aA
.contentFrameTime() == aB
.contentFrameTime();
3689 // Reverse the condition here since we want the array sorted largest to
3691 bool LessThan(const FrameStats
& aA
, const FrameStats
& aB
) const {
3692 return aA
.contentFrameTime() > aB
.contentFrameTime();
3696 void gfxPlatform::NotifyFrameStats(nsTArray
<FrameStats
>&& aFrameStats
) {
3697 if (!StaticPrefs::gfx_logging_slow_frames_enabled_AtStartup()) {
3701 FrameStatsComparator comp
;
3702 for (FrameStats
& f
: aFrameStats
) {
3703 mFrameStats
.InsertElementSorted(f
, comp
);
3705 if (mFrameStats
.Length() > 10) {
3706 mFrameStats
.SetLength(10);
3711 uint32_t gfxPlatform::TargetFrameRate() {
3712 if (gPlatform
&& gPlatform
->mVsyncDispatcher
) {
3713 return round(1000.0 /
3714 gPlatform
->mVsyncDispatcher
->GetVsyncRate().ToMilliseconds());
3720 bool gfxPlatform::UseDesktopZoomingScrollbars() {
3721 return StaticPrefs::apz_allow_zooming() &&
3722 !StaticPrefs::apz_force_disable_desktop_zooming_scrollbars();
3726 bool gfxPlatform::AsyncPanZoomEnabled() {
3727 #if !defined(MOZ_WIDGET_ANDROID) && !defined(MOZ_WIDGET_UIKIT)
3728 // For XUL applications (everything but Firefox on Android)
3729 // we only want to use APZ when E10S is enabled. If
3730 // we ever get input events off the main thread we can consider relaxing
3731 // this requirement.
3732 if (!BrowserTabsRemoteAutostart()) {
3736 #ifdef MOZ_WIDGET_ANDROID
3739 // If Fission is enabled, OOP iframes require APZ for hittest. So, we
3740 // need to forcibly enable APZ in that case for avoiding users confused.
3741 if (FissionAutostart()) {
3744 return StaticPrefs::
3745 layers_async_pan_zoom_enabled_AtStartup_DoNotUseDirectly();
3750 bool gfxPlatform::PerfWarnings() {
3751 return StaticPrefs::gfx_perf_warnings_enabled();
3754 void gfxPlatform::NotifyCompositorCreated(LayersBackend aBackend
) {
3755 if (mCompositorBackend
== aBackend
) {
3759 if (mCompositorBackend
!= LayersBackend::LAYERS_NONE
) {
3760 gfxCriticalNote
<< "Compositors might be mixed (" << int(mCompositorBackend
)
3761 << "," << int(aBackend
) << ")";
3764 // Set the backend before we notify so it's available immediately.
3765 mCompositorBackend
= aBackend
;
3767 if (XRE_IsParentProcess()) {
3768 nsDependentCString
compositor(GetLayersBackendName(mCompositorBackend
));
3769 mozilla::glean::gfx_status::compositor
.Set(compositor
);
3771 nsCString geckoVersion
;
3772 nsCOMPtr
<nsIXULAppInfo
> app
= do_GetService("@mozilla.org/xre/app-info;1");
3774 app
->GetVersion(geckoVersion
);
3776 mozilla::glean::gfx_status::last_compositor_gecko_version
.Set(geckoVersion
);
3778 mozilla::glean::gfx_feature::webrender
.Set(
3779 gfxConfig::GetFeature(gfx::Feature::WEBRENDER
)
3780 .GetStatusAndFailureIdString());
3783 // Notify that we created a compositor, so telemetry can update.
3784 NS_DispatchToMainThread(
3785 NS_NewRunnableFunction("gfxPlatform::NotifyCompositorCreated", [] {
3786 if (nsCOMPtr
<nsIObserverService
> obsvc
=
3787 services::GetObserverService()) {
3788 obsvc
->NotifyObservers(nullptr, "compositor:created", nullptr);
3794 bool gfxPlatform::FallbackFromAcceleration(FeatureStatus aStatus
,
3795 const char* aMessage
,
3796 const nsACString
& aFailureId
,
3797 bool aCrashAfterFinalFallback
) {
3798 // We always want to ensure (Hardware) WebRender is disabled.
3799 if (gfxConfig::IsEnabled(Feature::WEBRENDER
)) {
3800 gfxConfig::GetFeature(Feature::WEBRENDER
)
3801 .ForceDisable(aStatus
, aMessage
, aFailureId
);
3804 // Determine whether or not we are allowed to use Software WebRender in
3805 // fallback without the GPU process. Either the pref is false, or the feature
3806 // is enabled and we are currently still using it.
3807 bool swglFallbackAllowed
=
3809 gfx_webrender_fallback_software_requires_gpu_process_AtStartup() ||
3810 gfxConfig::IsEnabled(Feature::GPU_PROCESS
);
3813 // Before we disable D3D11 and HW_COMPOSITING, we should check if we can
3814 // fallback from WebRender to Software WebRender + D3D11 compositing.
3815 if (swglFallbackAllowed
&& gfxVars::AllowSoftwareWebRenderD3D11() &&
3816 gfxConfig::IsEnabled(Feature::D3D11_COMPOSITING
) &&
3817 !gfxVars::UseSoftwareWebRender()) {
3818 // Fallback to Software WebRender + D3D11 compositing.
3819 gfxCriticalNote
<< "Fallback WR to SW-WR + D3D11";
3820 gfxVars::SetUseSoftwareWebRender(true);
3824 if (swglFallbackAllowed
&& gfxVars::AllowSoftwareWebRenderD3D11() &&
3825 gfxVars::UseSoftwareWebRender()) {
3826 // Fallback from Software WebRender + D3D11 to Software WebRender.
3827 gfxCriticalNote
<< "Fallback SW-WR + D3D11 to SW-WR";
3828 gfxVars::SetAllowSoftwareWebRenderD3D11(false);
3832 // We aren't using Software WebRender + D3D11 compositing, so turn off the
3834 if (gfxConfig::IsEnabled(Feature::DIRECT2D
)) {
3835 gfxConfig::GetFeature(Feature::DIRECT2D
)
3836 .ForceDisable(aStatus
, aMessage
, aFailureId
);
3838 if (gfxConfig::IsEnabled(Feature::D3D11_COMPOSITING
)) {
3839 gfxConfig::GetFeature(Feature::D3D11_COMPOSITING
)
3840 .ForceDisable(aStatus
, aMessage
, aFailureId
);
3844 #if defined(MOZ_WIDGET_ANDROID) || defined(MOZ_WIDGET_GTK)
3845 // Before we disable OpenGL and HW_COMPOSITING, we should check if we can
3846 // fallback from WebRender to Software WebRender + OpenGL compositing.
3847 if (swglFallbackAllowed
&& gfxVars::AllowSoftwareWebRenderOGL() &&
3848 gfxConfig::IsEnabled(Feature::OPENGL_COMPOSITING
) &&
3849 !gfxVars::UseSoftwareWebRender()) {
3850 // Fallback to Software WebRender + OpenGL compositing.
3851 gfxCriticalNote
<< "Fallback WR to SW-WR + OpenGL";
3852 gfxVars::SetUseSoftwareWebRender(true);
3856 // Android does not want to fallback to SW-WR.
3857 #ifdef MOZ_WIDGET_GTK
3858 if (swglFallbackAllowed
&& gfxVars::AllowSoftwareWebRenderOGL() &&
3859 gfxVars::UseSoftwareWebRender()) {
3860 // Fallback from Software WebRender + OpenGL to Software WebRender.
3861 gfxCriticalNote
<< "Fallback SW-WR + OpenGL to SW-WR";
3862 gfxVars::SetAllowSoftwareWebRenderOGL(false);
3867 #ifndef MOZ_WIDGET_ANDROID
3868 // Non-Android wants to fallback to Software WebRender or Basic. Android wants
3869 // to fallback to OpenGL.
3870 if (gfxConfig::IsEnabled(Feature::HW_COMPOSITING
)) {
3871 gfxConfig::GetFeature(Feature::HW_COMPOSITING
)
3872 .ForceDisable(aStatus
, aMessage
, aFailureId
);
3876 if (StaticPrefs::gfx_webrender_fallback_software_AtStartup() &&
3877 swglFallbackAllowed
&& !gfxVars::UseSoftwareWebRender()) {
3878 // Fallback from WebRender to Software WebRender.
3879 gfxCriticalNote
<< "Fallback WR to SW-WR";
3880 gfxVars::SetUseSoftwareWebRender(true);
3884 if (!gfxVars::UseSoftwareWebRender()) {
3885 // Software WebRender may be disabled due to a startup issue with the
3886 // blocklist, despite it being our only fallback option based on the prefs.
3887 // If WebRender is unable to be initialized, this means that user would
3888 // otherwise get stuck with WebRender. As such, force a switch to Software
3889 // WebRender in this case.
3890 gfxCriticalNoteOnce
<< "Fallback WR to SW-WR, forced";
3891 gfxVars::SetUseSoftwareWebRender(true);
3895 if (aCrashAfterFinalFallback
) {
3896 MOZ_CRASH("Fallback configurations exhausted");
3899 // Continue using Software WebRender (disabled fallback to Basic).
3900 gfxCriticalNoteOnce
<< "Fallback remains SW-WR";
3905 void gfxPlatform::DisableGPUProcess() {
3906 if (gfxVars::RemoteCanvasEnabled() &&
3907 !StaticPrefs::gfx_canvas_remote_allow_in_parent_AtStartup()) {
3909 Feature::REMOTE_CANVAS
, FeatureStatus::UnavailableNoGpuProcess
,
3910 "Disabled by GPU process disabled",
3911 "FEATURE_REMOTE_CANVAS_DISABLED_BY_GPU_PROCESS_DISABLED"_ns
);
3912 gfxVars::SetRemoteCanvasEnabled(false);
3916 // On android, enable out-of-process WebGL only when GPU process exists.
3917 gfxVars::SetAllowWebglOop(false);
3918 // On android, enable accelerated canvas only when GPU process exists.
3919 gfxVars::SetUseAcceleratedCanvas2D(false);
3920 gfxConfig::Disable(Feature::ACCELERATED_CANVAS2D
, FeatureStatus::Blocked
,
3921 "Disabled by GPU Process disabled",
3922 "FEATURE_FAILURE_DISABLED_BY_GPU_PROCESS_DISABLED"_ns
);
3925 RemoteTextureMap::Init();
3926 // We need to initialize the parent process to prepare for WebRender if we
3927 // did not end up disabling it, despite losing the GPU process.
3928 wr::RenderThread::Start(GPUProcessManager::Get()->AllocateNamespace());
3929 gfx::CanvasRenderThread::Start();
3930 image::ImageMemoryReporter::InitForWebRender();
3933 /* static */ void gfxPlatform::DisableRemoteCanvas() {
3934 if (gfxVars::RemoteCanvasEnabled()) {
3935 gfxConfig::ForceDisable(Feature::REMOTE_CANVAS
, FeatureStatus::Failed
,
3936 "Disabled by runtime error",
3937 "FEATURE_REMOTE_CANVAS_RUNTIME_ERROR"_ns
);
3938 gfxVars::SetRemoteCanvasEnabled(false);
3940 if (gfxVars::UseAcceleratedCanvas2D()) {
3941 gfxConfig::ForceDisable(Feature::ACCELERATED_CANVAS2D
,
3942 FeatureStatus::Failed
, "Disabled by runtime error",
3943 "FEATURE_ACCELERATED_CANVAS2D_RUNTIME_ERROR"_ns
);
3944 gfxVars::SetUseAcceleratedCanvas2D(false);
3948 void gfxPlatform::ImportCachedContentDeviceData() {
3949 MOZ_ASSERT(XRE_IsContentProcess());
3951 // Import the content device data if we've got some waiting.
3952 if (!gContentDeviceInitData
) {
3956 ImportContentDeviceData(*gContentDeviceInitData
);
3957 gContentDeviceInitData
= nullptr;
3960 void gfxPlatform::ImportContentDeviceData(
3961 const mozilla::gfx::ContentDeviceData
& aData
) {
3962 MOZ_ASSERT(XRE_IsContentProcess());
3964 const DevicePrefs
& prefs
= aData
.prefs();
3965 gfxConfig::Inherit(Feature::HW_COMPOSITING
, prefs
.hwCompositing());
3967 // We don't inherit Feature::OPENGL_COMPOSITING here, because platforms
3968 // will handle that (without imported data from the parent) in
3969 // InitOpenGLConfig.
3971 gCMSOutputProfileData
= Some(aData
.cmsOutputProfileData().Clone());
3974 void gfxPlatform::BuildContentDeviceData(
3975 mozilla::gfx::ContentDeviceData
* aOut
) {
3976 MOZ_ASSERT(XRE_IsParentProcess());
3978 // Make sure our settings are synchronized from the GPU process.
3979 DebugOnly
<nsresult
> rv
= GPUProcessManager::Get()->EnsureGPUReady();
3980 MOZ_ASSERT(rv
!= NS_ERROR_ILLEGAL_DURING_SHUTDOWN
);
3982 aOut
->prefs().hwCompositing() = gfxConfig::GetValue(Feature::HW_COMPOSITING
);
3983 aOut
->prefs().oglCompositing() =
3984 gfxConfig::GetValue(Feature::OPENGL_COMPOSITING
);
3987 void gfxPlatform::ImportGPUDeviceData(
3988 const mozilla::gfx::GPUDeviceData
& aData
) {
3989 MOZ_ASSERT(XRE_IsParentProcess());
3991 gfxConfig::ImportChange(Feature::OPENGL_COMPOSITING
, aData
.oglCompositing());
3994 bool gfxPlatform::SupportsApzTouchInput() const {
3995 return dom::TouchEvent::PrefEnabled(nullptr);
3998 bool gfxPlatform::SupportsApzDragInput() const {
3999 return StaticPrefs::apz_drag_enabled();
4002 bool gfxPlatform::SupportsApzKeyboardInput() const {
4003 return StaticPrefs::apz_keyboard_enabled_AtStartup();
4006 bool gfxPlatform::SupportsApzAutoscrolling() const {
4007 return StaticPrefs::apz_autoscroll_enabled();
4010 bool gfxPlatform::SupportsApzZooming() const {
4011 return StaticPrefs::apz_allow_zooming();
4014 void gfxPlatform::InitOpenGLConfig() {
4016 // Don't enable by default on Windows, since it could show up in about:support
4017 // even though it'll never get used. Only attempt if user enables the pref
4018 if (!Preferences::GetBool("layers.prefer-opengl")) {
4023 FeatureState
& openGLFeature
=
4024 gfxConfig::GetFeature(Feature::OPENGL_COMPOSITING
);
4026 // Check to see hw comp supported
4027 if (!gfxConfig::IsEnabled(Feature::HW_COMPOSITING
)) {
4028 openGLFeature
.DisableByDefault(FeatureStatus::Unavailable
,
4029 "Hardware compositing is disabled",
4030 "FEATURE_FAILURE_OPENGL_NEED_HWCOMP"_ns
);
4035 openGLFeature
.SetDefaultFromPref(
4036 StaticPrefs::GetPrefName_layers_prefer_opengl(), true,
4037 StaticPrefs::GetPrefDefault_layers_prefer_opengl());
4039 openGLFeature
.EnableByDefault();
4042 // When layers acceleration is force-enabled, enable it even for blocklisted
4045 layers_acceleration_force_enabled_AtStartup_DoNotUseDirectly()) {
4046 openGLFeature
.UserForceEnable("Force-enabled by pref");
4051 nsCString failureId
;
4052 if (!IsGfxInfoStatusOkay(nsIGfxInfo::FEATURE_OPENGL_LAYERS
, &message
,
4054 openGLFeature
.Disable(FeatureStatus::Blocklisted
, message
.get(), failureId
);
4058 bool gfxPlatform::IsGfxInfoStatusOkay(int32_t aFeature
, nsCString
* aOutMessage
,
4059 nsCString
& aFailureId
) {
4060 nsCOMPtr
<nsIGfxInfo
> gfxInfo
= components::GfxInfo::Service();
4066 if (NS_SUCCEEDED(gfxInfo
->GetFeatureStatus(aFeature
, aFailureId
, &status
)) &&
4067 status
!= nsIGfxInfo::FEATURE_STATUS_OK
) {
4068 aOutMessage
->AssignLiteral("#BLOCKLIST_");
4069 aOutMessage
->AppendASCII(aFailureId
.get());