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 "nsIGfxInfo.h"
152 #include "nsIXULRuntime.h"
153 #include "VsyncSource.h"
154 #include "SoftwareVsyncSource.h"
155 #include "nscore.h" // for NS_FREE_PERMANENT_DATA
156 #include "mozilla/dom/ContentChild.h"
157 #include "mozilla/dom/ContentParent.h"
158 #include "mozilla/dom/TouchEvent.h"
160 #include "VRManager.h"
161 #include "VRManagerChild.h"
162 #include "mozilla/gfx/GPUParent.h"
163 #include "prsystem.h"
165 #include "mozilla/gfx/2D.h"
166 #include "mozilla/gfx/SourceSurfaceCairo.h"
168 using namespace mozilla
;
169 using namespace mozilla::layers
;
170 using namespace mozilla::gl
;
171 using namespace mozilla::gfx
;
173 static bool gEverInitialized
= false;
174 gfxPlatform
* gfxPlatform::gPlatform
= nullptr;
176 Atomic
<bool, ReleaseAcquire
> gfxPlatform::gCMSInitialized
;
177 CMSMode
gfxPlatform::gCMSMode
= CMSMode::Off
;
179 const ContentDeviceData
* gContentDeviceInitData
= nullptr;
181 /// This override of the LogForwarder, initially used for the critical graphics
182 /// errors, is sending the log to the crash annotations as well, but only
183 /// if the capacity set with the method below is >= 2. We always retain the
184 /// very first critical message, and the latest capacity-1 messages are
185 /// rotated through. Note that we don't expect the total number of times
186 /// this gets called to be large - it is meant for critical errors only.
188 class CrashStatsLogForwarder
: public mozilla::gfx::LogForwarder
{
190 explicit CrashStatsLogForwarder(CrashReporter::Annotation aKey
);
191 void Log(const std::string
& aString
) override
;
192 void CrashAction(LogReason aReason
) override
;
193 bool UpdateStringsVector(const std::string
& aString
) override
;
195 LoggingRecord
LoggingRecordCopy() override
;
197 void SetCircularBufferSize(uint32_t aCapacity
);
200 // Helper for the Log()
201 void UpdateCrashReport();
204 LoggingRecord mBuffer
;
205 CrashReporter::Annotation mCrashCriticalKey
;
206 uint32_t mMaxCapacity
;
208 Mutex mMutex MOZ_UNANNOTATED
;
211 CrashStatsLogForwarder::CrashStatsLogForwarder(CrashReporter::Annotation aKey
)
212 : mCrashCriticalKey(aKey
),
215 mMutex("CrashStatsLogForwarder") {}
217 void CrashStatsLogForwarder::SetCircularBufferSize(uint32_t aCapacity
) {
218 MutexAutoLock
lock(mMutex
);
220 mMaxCapacity
= aCapacity
;
221 mBuffer
.reserve(static_cast<size_t>(aCapacity
));
224 LoggingRecord
CrashStatsLogForwarder::LoggingRecordCopy() {
225 MutexAutoLock
lock(mMutex
);
229 bool CrashStatsLogForwarder::UpdateStringsVector(const std::string
& aString
) {
230 // We want at least the first one and the last one. Otherwise, no point.
231 if (mMaxCapacity
< 2) {
236 MOZ_ASSERT(mIndex
>= 0);
238 // index will count 0, 1, 2, ..., max-1, 1, 2, ..., max-1, 1, 2, ...
239 int32_t index
= mIndex
? (mIndex
- 1) % (mMaxCapacity
- 1) + 1 : 0;
240 MOZ_ASSERT(index
>= 0 && index
< (int32_t)mMaxCapacity
);
241 MOZ_ASSERT(index
<= mIndex
&& index
<= (int32_t)mBuffer
.size());
243 double tStamp
= (TimeStamp::NowLoRes() - TimeStamp::ProcessCreation())
244 .ToSecondsSigDigits();
246 // Checking for index >= mBuffer.size(), rather than index == mBuffer.size()
247 // just out of paranoia, but we know index <= mBuffer.size().
248 LoggingRecordEntry
newEntry(mIndex
, aString
, tStamp
);
249 if (index
>= static_cast<int32_t>(mBuffer
.size())) {
250 mBuffer
.push_back(newEntry
);
252 mBuffer
[index
] = newEntry
;
257 void CrashStatsLogForwarder::UpdateCrashReport() {
258 std::stringstream message
;
259 std::string logAnnotation
;
261 switch (XRE_GetProcessType()) {
262 case GeckoProcessType_Default
:
263 logAnnotation
= "|[";
265 case GeckoProcessType_Content
:
266 logAnnotation
= "|[C";
268 case GeckoProcessType_GPU
:
269 logAnnotation
= "|[G";
272 logAnnotation
= "|[X";
276 for (auto& it
: mBuffer
) {
277 message
<< logAnnotation
<< std::get
<0>(it
) << "]" << std::get
<1>(it
)
278 << " (t=" << std::get
<2>(it
) << ") ";
281 nsresult annotated
= CrashReporter::RecordAnnotationCString(
282 mCrashCriticalKey
, message
.str().c_str());
284 if (annotated
!= NS_OK
) {
285 printf("Crash Annotation %s: %s",
286 CrashReporter::AnnotationToString(mCrashCriticalKey
),
287 message
.str().c_str());
291 class LogForwarderEvent
: public Runnable
{
292 virtual ~LogForwarderEvent() = default;
295 NS_INLINE_DECL_REFCOUNTING_INHERITED(LogForwarderEvent
, Runnable
)
297 explicit LogForwarderEvent(const nsCString
& aMessage
)
298 : mozilla::Runnable("LogForwarderEvent"), mMessage(aMessage
) {}
300 NS_IMETHOD
Run() override
{
301 MOZ_ASSERT(NS_IsMainThread() &&
302 (XRE_IsContentProcess() || XRE_IsGPUProcess()));
304 if (XRE_IsContentProcess()) {
305 dom::ContentChild
* cc
= dom::ContentChild::GetSingleton();
306 Unused
<< cc
->SendGraphicsError(mMessage
);
307 } else if (XRE_IsGPUProcess()) {
308 GPUParent
* gp
= GPUParent::GetSingleton();
309 Unused
<< gp
->SendGraphicsError(mMessage
);
319 void CrashStatsLogForwarder::Log(const std::string
& aString
) {
320 MutexAutoLock
lock(mMutex
);
321 PROFILER_MARKER_TEXT("gfx::CriticalError", GRAPHICS
, {},
322 nsDependentCString(aString
.c_str()));
324 if (UpdateStringsVector(aString
)) {
328 // Add it to the parent strings
329 if (!XRE_IsParentProcess()) {
330 nsCString
stringToSend(aString
.c_str());
331 if (NS_IsMainThread()) {
332 if (XRE_IsContentProcess()) {
333 dom::ContentChild
* cc
= dom::ContentChild::GetSingleton();
334 Unused
<< cc
->SendGraphicsError(stringToSend
);
335 } else if (XRE_IsGPUProcess()) {
336 GPUParent
* gp
= GPUParent::GetSingleton();
337 Unused
<< gp
->SendGraphicsError(stringToSend
);
340 nsCOMPtr
<nsIRunnable
> r1
= new LogForwarderEvent(stringToSend
);
341 NS_DispatchToMainThread(r1
);
346 class CrashTelemetryEvent
: public Runnable
{
347 virtual ~CrashTelemetryEvent() = default;
350 NS_INLINE_DECL_REFCOUNTING_INHERITED(CrashTelemetryEvent
, Runnable
)
352 explicit CrashTelemetryEvent(uint32_t aReason
)
353 : mozilla::Runnable("CrashTelemetryEvent"), mReason(aReason
) {}
355 NS_IMETHOD
Run() override
{
356 MOZ_ASSERT(NS_IsMainThread());
357 Telemetry::Accumulate(Telemetry::GFX_CRASH
, mReason
);
365 void CrashStatsLogForwarder::CrashAction(LogReason aReason
) {
366 #ifndef RELEASE_OR_BETA
367 // Non-release builds crash by default, but will use telemetry
368 // if this environment variable is present.
369 static bool useTelemetry
= gfxEnv::MOZ_GFX_CRASH_TELEMETRY();
371 // Release builds use telemetry by default, but will crash instead
372 // if this environment variable is present.
373 static bool useTelemetry
= !gfxEnv::MOZ_GFX_CRASH_MOZ_CRASH();
377 // The callers need to assure that aReason is in the range
378 // that the telemetry call below supports.
379 if (NS_IsMainThread()) {
380 Telemetry::Accumulate(Telemetry::GFX_CRASH
, (uint32_t)aReason
);
382 nsCOMPtr
<nsIRunnable
> r1
= new CrashTelemetryEvent((uint32_t)aReason
);
383 NS_DispatchToMainThread(r1
);
386 // ignoring aReason, we can get the information we need from the stack
387 MOZ_CRASH("GFX_CRASH");
391 #define GFX_DOWNLOADABLE_FONTS_ENABLED "gfx.downloadable_fonts.enabled"
393 #define GFX_PREF_FALLBACK_USE_CMAPS \
394 "gfx.font_rendering.fallback.always_use_cmaps"
396 #define GFX_PREF_OPENTYPE_SVG "gfx.font_rendering.opentype_svg.enabled"
398 #define GFX_PREF_WORD_CACHE_CHARLIMIT "gfx.font_rendering.wordcache.charlimit"
399 #define GFX_PREF_WORD_CACHE_MAXENTRIES "gfx.font_rendering.wordcache.maxentries"
401 #define GFX_PREF_GRAPHITE_SHAPING "gfx.font_rendering.graphite.enabled"
402 #if defined(XP_DARWIN)
403 # define GFX_PREF_CORETEXT_SHAPING "gfx.font_rendering.coretext.enabled"
406 #define FONT_VARIATIONS_PREF "layout.css.font-variations.enabled"
408 static const char* kObservedPrefs
[] = {"gfx.downloadable_fonts.",
409 "gfx.font_rendering.", nullptr};
411 static void FontPrefChanged(const char* aPref
, void* aData
) {
413 NS_ASSERTION(gfxPlatform::GetPlatform(), "the singleton instance has gone");
414 gfxPlatform::GetPlatform()->FontsPrefsChanged(aPref
);
417 void gfxPlatform::OnMemoryPressure(layers::MemoryPressureReason aWhy
) {
418 Factory::PurgeAllCaches();
419 gfxGradientCache::PurgeAllCaches();
420 gfxFontMissingGlyphs::Purge();
421 PurgeSkiaFontCache();
422 if (XRE_IsParentProcess()) {
423 layers::CompositorManagerChild
* manager
=
424 CompositorManagerChild::GetInstance();
426 manager
->SendNotifyMemoryPressure();
431 gfxPlatform::gfxPlatform()
432 : mAzureCanvasBackendCollector(this, &gfxPlatform::GetAzureBackendInfo
),
433 mApzSupportCollector(this, &gfxPlatform::GetApzSupportInfo
),
434 mFrameStatsCollector(this, &gfxPlatform::GetFrameStats
),
435 mCMSInfoCollector(this, &gfxPlatform::GetCMSSupportInfo
),
436 mDisplayInfoCollector(this, &gfxPlatform::GetDisplayInfo
),
437 mOverlayInfoCollector(this, &gfxPlatform::GetOverlayInfo
),
438 mSwapChainInfoCollector(this, &gfxPlatform::GetSwapChainInfo
),
439 mCompositorBackend(layers::LayersBackend::LAYERS_NONE
) {
440 mAllowDownloadableFonts
= UNINITIALIZED_VALUE
;
442 InitBackendPrefs(GetBackendPrefs());
443 VRManager::ManagerInit();
446 bool gfxPlatform::Initialized() { return !!gPlatform
; }
449 void gfxPlatform::InitChild(const ContentDeviceData
& aData
) {
450 MOZ_ASSERT(XRE_IsContentProcess());
451 MOZ_ASSERT(!gPlatform
,
452 "InitChild() should be called before first GetPlatform()");
453 // Make the provided initial ContentDeviceData available to the init
455 gContentDeviceInitData
= &aData
;
457 gContentDeviceInitData
= nullptr;
460 #define WR_DEBUG_PREF "gfx.webrender.debug"
462 static void SwapIntervalPrefChangeCallback(const char* aPrefName
, void*) {
463 bool egl
= Preferences::GetBool("gfx.swap-interval.egl", false);
464 bool glx
= Preferences::GetBool("gfx.swap-interval.glx", false);
465 gfxVars::SetSwapIntervalEGL(egl
);
466 gfxVars::SetSwapIntervalGLX(glx
);
469 static void WebRendeProfilerUIPrefChangeCallback(const char* aPrefName
, void*) {
471 if (NS_SUCCEEDED(Preferences::GetCString("gfx.webrender.debug.profiler-ui",
473 gfxVars::SetWebRenderProfilerUI(uiString
);
477 // List of boolean dynamic parameter for WebRender.
479 // The parameters in this list are:
481 // - The BoolParameter enum variant (see webrender_api/src/lib.rs)
482 // - A default value.
483 #define WR_BOOL_PARAMETER_LIST(_) \
484 _("gfx.webrender.batched-texture-uploads", \
485 wr::BoolParameter::BatchedUploads, true) \
486 _("gfx.webrender.draw-calls-for-texture-copy", \
487 wr::BoolParameter::DrawCallsForTextureCopy, true) \
488 _("gfx.webrender.pbo-uploads", wr::BoolParameter::PboUploads, true) \
489 _("gfx.webrender.multithreading", wr::BoolParameter::Multithreading, true)
491 static void WebRenderBoolParameterChangeCallback(const char*, void*) {
494 #define WR_BOOL_PARAMETER(name, key, default_val) \
495 if (Preferences::GetBool(name, default_val)) { \
496 bits |= 1 << (uint32_t)key; \
499 WR_BOOL_PARAMETER_LIST(WR_BOOL_PARAMETER
)
500 #undef WR_BOOL_PARAMETER
502 gfx::gfxVars::SetWebRenderBoolParameters(bits
);
505 static void RegisterWebRenderBoolParamCallback() {
506 #define WR_BOOL_PARAMETER(name, _key, _default_val) \
507 Preferences::RegisterCallback(WebRenderBoolParameterChangeCallback, name);
509 WR_BOOL_PARAMETER_LIST(WR_BOOL_PARAMETER
)
510 #undef WR_BOOL_PARAMETER
512 WebRenderBoolParameterChangeCallback(nullptr, nullptr);
515 static void WebRenderDebugPrefChangeCallback(const char* aPrefName
, void*) {
516 wr::DebugFlags flags
{0};
517 #define GFX_WEBRENDER_DEBUG(suffix, bit) \
518 if (Preferences::GetBool(WR_DEBUG_PREF suffix, false)) { \
522 GFX_WEBRENDER_DEBUG(".profiler", wr::DebugFlags::PROFILER_DBG
)
523 GFX_WEBRENDER_DEBUG(".render-targets", wr::DebugFlags::RENDER_TARGET_DBG
)
524 GFX_WEBRENDER_DEBUG(".texture-cache", wr::DebugFlags::TEXTURE_CACHE_DBG
)
525 GFX_WEBRENDER_DEBUG(".gpu-time-queries", wr::DebugFlags::GPU_TIME_QUERIES
)
526 GFX_WEBRENDER_DEBUG(".gpu-sample-queries", wr::DebugFlags::GPU_SAMPLE_QUERIES
)
527 GFX_WEBRENDER_DEBUG(".disable-batching", wr::DebugFlags::DISABLE_BATCHING
)
528 GFX_WEBRENDER_DEBUG(".epochs", wr::DebugFlags::EPOCHS
)
529 GFX_WEBRENDER_DEBUG(".smart-profiler", wr::DebugFlags::SMART_PROFILER
)
530 GFX_WEBRENDER_DEBUG(".echo-driver-messages",
531 wr::DebugFlags::ECHO_DRIVER_MESSAGES
)
532 GFX_WEBRENDER_DEBUG(".show-overdraw", wr::DebugFlags::SHOW_OVERDRAW
)
533 GFX_WEBRENDER_DEBUG(".gpu-cache", wr::DebugFlags::GPU_CACHE_DBG
)
534 GFX_WEBRENDER_DEBUG(".texture-cache.clear-evicted",
535 wr::DebugFlags::TEXTURE_CACHE_DBG_CLEAR_EVICTED
)
536 GFX_WEBRENDER_DEBUG(".picture-caching", wr::DebugFlags::PICTURE_CACHING_DBG
)
537 GFX_WEBRENDER_DEBUG(".picture-borders", wr::DebugFlags::PICTURE_BORDERS
)
538 GFX_WEBRENDER_DEBUG(".force-picture-invalidation",
539 wr::DebugFlags::FORCE_PICTURE_INVALIDATION
)
540 GFX_WEBRENDER_DEBUG(".primitives", wr::DebugFlags::PRIMITIVE_DBG
)
541 // Bit 18 is for the zoom display, which requires the mouse position and thus
542 // currently only works in wrench.
543 GFX_WEBRENDER_DEBUG(".small-screen", wr::DebugFlags::SMALL_SCREEN
)
544 GFX_WEBRENDER_DEBUG(".disable-opaque-pass",
545 wr::DebugFlags::DISABLE_OPAQUE_PASS
)
546 GFX_WEBRENDER_DEBUG(".disable-alpha-pass", wr::DebugFlags::DISABLE_ALPHA_PASS
)
547 GFX_WEBRENDER_DEBUG(".disable-clip-masks", wr::DebugFlags::DISABLE_CLIP_MASKS
)
548 GFX_WEBRENDER_DEBUG(".disable-text-prims", wr::DebugFlags::DISABLE_TEXT_PRIMS
)
549 GFX_WEBRENDER_DEBUG(".disable-gradient-prims",
550 wr::DebugFlags::DISABLE_GRADIENT_PRIMS
)
551 GFX_WEBRENDER_DEBUG(".obscure-images", wr::DebugFlags::OBSCURE_IMAGES
)
552 GFX_WEBRENDER_DEBUG(".glyph-flashing", wr::DebugFlags::GLYPH_FLASHING
)
553 GFX_WEBRENDER_DEBUG(".capture-profiler", wr::DebugFlags::PROFILER_CAPTURE
)
554 GFX_WEBRENDER_DEBUG(".window-visibility",
555 wr::DebugFlags::WINDOW_VISIBILITY_DBG
)
556 GFX_WEBRENDER_DEBUG(".restrict-blob-size", wr::DebugFlags::RESTRICT_BLOB_SIZE
)
557 GFX_WEBRENDER_DEBUG(".surface-promotion-logging",
558 wr::DebugFlags::SURFACE_PROMOTION_LOGGING
)
559 #undef GFX_WEBRENDER_DEBUG
560 gfx::gfxVars::SetWebRenderDebugFlags(flags
._0
);
562 uint32_t threshold
= Preferences::GetFloat(
563 StaticPrefs::GetPrefName_gfx_webrender_debug_slow_cpu_frame_threshold(),
565 gfx::gfxVars::SetWebRenderSlowCpuFrameThreshold(threshold
);
568 static void WebRenderQualityPrefChangeCallback(const char* aPref
, void*) {
569 gfxPlatform::GetPlatform()->UpdateForceSubpixelAAWherePossible();
572 static void WebRenderBatchingPrefChangeCallback(const char* aPrefName
, void*) {
573 uint32_t count
= Preferences::GetUint(
574 StaticPrefs::GetPrefName_gfx_webrender_batching_lookback(), 10);
576 gfx::gfxVars::SetWebRenderBatchingLookback(count
);
579 static void WebRenderBlobTileSizePrefChangeCallback(const char* aPrefName
,
581 uint32_t tileSize
= Preferences::GetUint(
582 StaticPrefs::GetPrefName_gfx_webrender_blob_tile_size(), 256);
583 gfx::gfxVars::SetWebRenderBlobTileSize(tileSize
);
586 static void WebRenderUploadThresholdPrefChangeCallback(const char* aPrefName
,
588 int value
= Preferences::GetInt(
589 StaticPrefs::GetPrefName_gfx_webrender_batched_upload_threshold(),
592 gfxVars::SetWebRenderBatchedUploadThreshold(value
);
595 static uint32_t GetSkiaGlyphCacheSize() {
596 // Only increase font cache size on non-android to save memory.
597 #if !defined(MOZ_WIDGET_ANDROID)
598 // 10mb as the default pref cache size on desktop due to talos perf tweaking.
599 // Chromium uses 20mb and skia default uses 2mb.
600 // We don't need to change the font cache count since we usually
601 // cache thrash due to asian character sets in talos.
602 // Only increase memory on the content process
604 StaticPrefs::gfx_content_skia_font_cache_size_AtStartup() * 1024 * 1024;
605 if (mozilla::BrowserTabsRemoteAutostart()) {
606 return XRE_IsContentProcess() ? cacheSize
: kDefaultGlyphCacheSize
;
611 return kDefaultGlyphCacheSize
;
612 #endif // MOZ_WIDGET_ANDROID
615 class WebRenderMemoryReporter final
: public nsIMemoryReporter
{
618 NS_DECL_NSIMEMORYREPORTER
621 ~WebRenderMemoryReporter() = default;
624 // Memory reporter for WebRender.
626 // The reporting within WebRender is manual and incomplete. We could do a much
627 // more thorough job by depending on the malloc_size_of crate, but integrating
628 // that into WebRender is tricky [1].
630 // So the idea is to start with manual reporting for the large allocations
631 // detected by DMD, and see how much that can cover in practice (which may
632 // require a few rounds of iteration). If that approach turns out to be
633 // fundamentally insufficient, we can either duplicate more of the
634 // malloc_size_of functionality in WebRender, or deal with the complexity of a
635 // gecko-only crate dependency.
637 // [1] See https://bugzilla.mozilla.org/show_bug.cgi?id=1480293#c1
638 struct WebRenderMemoryReporterHelper
{
639 WebRenderMemoryReporterHelper(nsIHandleReportCallback
* aCallback
,
641 : mCallback(aCallback
), mData(aData
) {}
642 nsCOMPtr
<nsIHandleReportCallback
> mCallback
;
643 nsCOMPtr
<nsISupports
> mData
;
645 void Report(size_t aBytes
, const char* aName
) const {
646 nsPrintfCString
path("explicit/gfx/webrender/%s", aName
);
647 nsCString
desc("CPU heap memory used by WebRender"_ns
);
648 ReportInternal(aBytes
, path
, desc
, nsIMemoryReporter::KIND_HEAP
);
651 void ReportTexture(size_t aBytes
, const char* aName
) const {
652 nsPrintfCString
path("gfx/webrender/textures/%s", aName
);
653 nsCString
desc("GPU texture memory used by WebRender"_ns
);
654 ReportInternal(aBytes
, path
, desc
, nsIMemoryReporter::KIND_OTHER
);
657 void ReportTotalGPUBytes(size_t aBytes
) const {
658 nsCString
path("gfx/webrender/total-gpu-bytes"_ns
);
659 nsCString
desc(nsLiteralCString(
660 "Total GPU bytes used by WebRender (should match textures/ sum)"));
661 ReportInternal(aBytes
, path
, desc
, nsIMemoryReporter::KIND_OTHER
);
664 void ReportInternal(size_t aBytes
, nsACString
& aPath
, nsACString
& aDesc
,
665 int32_t aKind
) const {
666 // Generally, memory reporters pass the empty string as the process name to
667 // indicate "current process". However, if we're using a GPU process, the
668 // measurements will actually take place in that process, and it's easier to
669 // just note that here rather than trying to invoke the memory reporter in
671 nsAutoCString processName
;
672 if (gfxConfig::IsEnabled(Feature::GPU_PROCESS
)) {
673 GPUParent::GetGPUProcessName(processName
);
676 mCallback
->Callback(processName
, aPath
, aKind
,
677 nsIMemoryReporter::UNITS_BYTES
, aBytes
, aDesc
, mData
);
681 static void FinishAsyncMemoryReport() {
682 nsCOMPtr
<nsIMemoryReporterManager
> imgr
=
683 do_GetService("@mozilla.org/memory-reporter-manager;1");
690 // (For some reason, clang-format gets the second macro right, but totally mangles the first).
691 #define REPORT_INTERNER(id) \
692 helper.Report(aReport.interning.interners.id, \
693 "interning/" #id "/interners");
696 #define REPORT_DATA_STORE(id) \
697 helper.Report(aReport.interning.data_stores.id, \
698 "interning/" #id "/data-stores");
700 NS_IMPL_ISUPPORTS(WebRenderMemoryReporter
, nsIMemoryReporter
)
703 WebRenderMemoryReporter::CollectReports(nsIHandleReportCallback
* aHandleReport
,
704 nsISupports
* aData
, bool aAnonymize
) {
705 MOZ_ASSERT(XRE_IsParentProcess());
706 MOZ_ASSERT(NS_IsMainThread());
707 layers::CompositorManagerChild
* manager
=
708 CompositorManagerChild::GetInstance();
710 FinishAsyncMemoryReport();
714 WebRenderMemoryReporterHelper
helper(aHandleReport
, aData
);
715 manager
->SendReportMemory(
716 [=](wr::MemoryReport aReport
) {
718 helper
.Report(aReport
.clip_stores
, "clip-stores");
719 helper
.Report(aReport
.gpu_cache_metadata
, "gpu-cache/metadata");
720 helper
.Report(aReport
.gpu_cache_cpu_mirror
, "gpu-cache/cpu-mirror");
721 helper
.Report(aReport
.hit_testers
, "hit-testers");
722 helper
.Report(aReport
.fonts
, "resource-cache/fonts");
723 helper
.Report(aReport
.weak_fonts
, "resource-cache/weak-fonts");
724 helper
.Report(aReport
.images
, "resource-cache/images");
725 helper
.Report(aReport
.rasterized_blobs
,
726 "resource-cache/rasterized-blobs");
727 helper
.Report(aReport
.texture_cache_structures
,
728 "texture-cache/structures");
729 helper
.Report(aReport
.shader_cache
, "shader-cache");
730 helper
.Report(aReport
.display_list
, "display-list");
731 helper
.Report(aReport
.swgl
, "swgl");
732 helper
.Report(aReport
.upload_staging_memory
, "upload-stagin-memory");
733 helper
.Report(aReport
.frame_allocator
, "frame-allocator");
734 helper
.Report(aReport
.render_tasks
, "frame-allocator/render-tasks");
736 WEBRENDER_FOR_EACH_INTERNER(REPORT_INTERNER
, );
737 WEBRENDER_FOR_EACH_INTERNER(REPORT_DATA_STORE
, );
740 helper
.ReportTexture(aReport
.gpu_cache_textures
, "gpu-cache");
741 helper
.ReportTexture(aReport
.vertex_data_textures
, "vertex-data");
742 helper
.ReportTexture(aReport
.render_target_textures
, "render-targets");
743 helper
.ReportTexture(aReport
.depth_target_textures
, "depth-targets");
744 helper
.ReportTexture(aReport
.picture_tile_textures
, "picture-tiles");
745 helper
.ReportTexture(aReport
.atlas_textures
, "texture-cache/atlas");
746 helper
.ReportTexture(aReport
.standalone_textures
,
747 "texture-cache/standalone");
748 helper
.ReportTexture(aReport
.texture_upload_pbos
,
749 "texture-upload-pbos");
750 helper
.ReportTexture(aReport
.swap_chain
, "swap-chains");
751 helper
.ReportTexture(aReport
.render_texture_hosts
,
752 "render-texture-hosts");
753 helper
.ReportTexture(aReport
.upload_staging_textures
,
754 "upload-staging-textures");
756 FinishAsyncMemoryReport();
758 [](mozilla::ipc::ResponseRejectReason
&& aReason
) {
759 FinishAsyncMemoryReport();
765 #undef REPORT_INTERNER
766 #undef REPORT_DATA_STORE
768 std::atomic
<int8_t> gfxPlatform::sHasVariationFontSupport
= -1;
770 bool gfxPlatform::HasVariationFontSupport() {
771 // We record the status here: 0 for not supported, 1 for supported.
772 if (sHasVariationFontSupport
< 0) {
773 // It doesn't actually matter if we race with another thread setting this,
774 // as any thread will set it to the same value.
776 sHasVariationFontSupport
= gfxWindowsPlatform::CheckVariationFontSupport();
777 #elif defined(XP_DARWIN)
778 sHasVariationFontSupport
= gfxPlatformMac::CheckVariationFontSupport();
779 #elif defined(MOZ_WIDGET_GTK)
780 sHasVariationFontSupport
= gfxPlatformGtk::CheckVariationFontSupport();
781 #elif defined(ANDROID)
782 sHasVariationFontSupport
= gfxAndroidPlatform::CheckVariationFontSupport();
784 # error "No gfxPlatform implementation available"
787 return sHasVariationFontSupport
> 0;
790 void gfxPlatform::Init() {
791 AUTO_PROFILER_MARKER_TEXT("gfxPlatform", GRAPHICS
, {},
792 "gfxPlatform::Init"_ns
);
793 MOZ_RELEASE_ASSERT(!XRE_IsGPUProcess(), "GFX: Not allowed in GPU process.");
794 MOZ_RELEASE_ASSERT(!XRE_IsRDDProcess(), "GFX: Not allowed in RDD process.");
795 MOZ_RELEASE_ASSERT(NS_IsMainThread(), "GFX: Not in main thread.");
796 MOZ_RELEASE_ASSERT(!gEverInitialized
);
797 if (XRE_IsContentProcess()) {
798 MOZ_RELEASE_ASSERT(gContentDeviceInitData
,
799 "Content Process should cal InitChild() before "
800 "first GetPlatform()");
802 gEverInitialized
= true;
804 gfxVars::Initialize();
808 if (XRE_IsParentProcess()) {
809 GPUProcessManager::Initialize();
810 RDDProcessManager::Initialize();
812 nsCOMPtr
<nsIFile
> file
;
813 nsresult rv
= NS_GetSpecialDirectory(NS_GRE_DIR
, getter_AddRefs(file
));
815 gfxVars::SetGREDirectory(nsString());
819 gfxVars::SetGREDirectory(nsString(path
));
823 if (XRE_IsParentProcess()) {
824 nsCOMPtr
<nsIFile
> profDir
;
825 nsresult rv
= NS_GetSpecialDirectory(NS_APP_PROFILE_DIR_STARTUP
,
826 getter_AddRefs(profDir
));
828 gfxVars::SetProfDirectory(nsString());
831 profDir
->GetPath(path
);
832 gfxVars::SetProfDirectory(nsString(path
));
836 Preferences::GetCString("layers.windowrecording.path", path
);
837 gfxVars::SetLayersWindowRecordingPath(path
);
840 gfxVars::SetFxREmbedded(true);
844 // Drop a note in the crash report if we end up forcing an option that could
845 // destabilize things. New items should be appended at the end (of an
846 // existing or in a new section), so that we don't have to know the version to
847 // interpret these cryptic strings.
849 nsAutoCString forcedPrefs
;
851 forcedPrefs
.AppendPrintf(
852 "FP(D%d%d", StaticPrefs::gfx_direct2d_disabled_AtStartup(),
853 StaticPrefs::gfx_direct2d_force_enabled_AtStartup());
855 forcedPrefs
.AppendPrintf(
857 StaticPrefs::layers_amd_switchable_gfx_enabled_AtStartup(),
858 StaticPrefs::layers_acceleration_disabled_AtStartup_DoNotUseDirectly(),
860 layers_acceleration_force_enabled_AtStartup_DoNotUseDirectly(),
861 StaticPrefs::layers_d3d11_force_warp_AtStartup());
863 forcedPrefs
.AppendPrintf(
864 "-W%d%d%d%d%d%d%d", StaticPrefs::webgl_angle_force_d3d11(),
865 StaticPrefs::webgl_angle_force_warp(), StaticPrefs::webgl_disabled(),
866 StaticPrefs::webgl_disable_angle(), StaticPrefs::webgl_dxgl_enabled(),
867 StaticPrefs::webgl_force_enabled(), StaticPrefs::webgl_msaa_force());
868 // Prefs that don't fit into any of the other sections
869 forcedPrefs
.AppendPrintf("-T%d%d) ",
870 StaticPrefs::gfx_android_rgb16_force_AtStartup(),
871 StaticPrefs::gfx_canvas_accelerated());
872 ScopedGfxFeatureReporter::AppNote(forcedPrefs
);
877 /* Initialize the GfxInfo service.
878 * Note: we can't call functions on GfxInfo that depend
879 * on gPlatform until after it has been initialized
880 * below. GfxInfo initialization annotates our
881 * crash reports so we want to do it before
882 * we try to load any drivers and do device detection
883 * incase that code crashes. See bug #591561. */
884 nsCOMPtr
<nsIGfxInfo
> gfxInfo
;
885 /* this currently will only succeed on Windows */
886 gfxInfo
= components::GfxInfo::Service();
888 if (XRE_IsParentProcess()) {
889 // Some gfxVars must be initialized prior gPlatform for coherent results.
890 gfxVars::SetDXInterop2Blocked(IsDXInterop2Blocked());
891 gfxVars::SetDXNV12Blocked(IsDXNV12Blocked());
892 gfxVars::SetDXP010Blocked(IsDXP010Blocked());
893 gfxVars::SetDXP016Blocked(IsDXP016Blocked());
897 gPlatform
= new gfxWindowsPlatform
;
898 #elif defined(XP_DARWIN)
899 gPlatform
= new gfxPlatformMac
;
900 #elif defined(MOZ_WIDGET_GTK)
901 gPlatform
= new gfxPlatformGtk
;
902 #elif defined(ANDROID)
903 gPlatform
= new gfxAndroidPlatform
;
905 # error "No gfxPlatform implementation available"
907 gPlatform
->PopulateScreenInfo();
908 gPlatform
->InitAcceleration();
909 gPlatform
->InitWebRenderConfig();
911 gPlatform
->InitHardwareVideoConfig();
912 gPlatform
->InitWebGLConfig();
913 gPlatform
->InitWebGPUConfig();
914 gPlatform
->InitWindowOcclusionConfig();
915 gPlatform
->InitBackdropFilterConfig();
916 gPlatform
->InitAcceleratedCanvas2DConfig();
919 // When using WebRender, we defer initialization of the D3D11 devices until
920 // the (rare) cases where they're used. Note that the GPU process where
921 // WebRender runs doesn't initialize gfxPlatform and performs explicit
922 // initialization of the bits it needs.
923 if (XRE_IsParentProcess() && !gfxConfig::IsEnabled(Feature::GPU_PROCESS
) &&
925 gfx_webrender_enabled_no_gpu_process_with_angle_win_AtStartup()) {
926 gPlatform
->EnsureDevicesInitialized();
930 if (XRE_IsParentProcess()) {
931 mozilla::glean::gpu_process::feature_status
.Set(
932 gfxConfig::GetFeature(Feature::GPU_PROCESS
)
933 .GetStatusAndFailureIdString());
936 if (gfxConfig::IsEnabled(Feature::GPU_PROCESS
)) {
937 GPUProcessManager
* gpu
= GPUProcessManager::Get();
938 Unused
<< gpu
->LaunchGPUProcess();
941 if (XRE_IsParentProcess()) {
942 // Create the global vsync source and dispatcher.
943 RefPtr
<VsyncSource
> vsyncSource
=
944 gfxPlatform::ForceSoftwareVsync()
945 ? gPlatform
->GetSoftwareVsyncSource()
946 : gPlatform
->GetGlobalHardwareVsyncSource();
947 gPlatform
->mVsyncDispatcher
= new VsyncDispatcher(vsyncSource
);
949 // Listen for layout.frame_rate pref changes.
950 Preferences::RegisterCallback(
951 gfxPlatform::ReInitFrameRate
,
952 nsDependentCString(StaticPrefs::GetPrefName_layout_frame_rate()));
953 Preferences::RegisterCallback(
954 gfxPlatform::ReInitFrameRate
,
956 StaticPrefs::GetPrefName_privacy_resistFingerprinting()));
959 // Create the sRGB to output display profile transforms. They can be accessed
960 // off the main thread so we want to avoid a race condition.
961 gPlatform
->InitializeCMS();
964 #ifdef MOZ_ENABLE_FREETYPE
965 SkInitCairoFT(gPlatform
->FontHintingEnabled());
967 gfxGradientCache::Init();
971 // This *create* the platform font list instance, but may not *initialize* it
972 // yet if the gfx.font-list.lazy-init.enabled pref is set. The first *use*
973 // of the list will ensure it is initialized.
974 if (!gPlatform
->CreatePlatformFontList()) {
975 MOZ_CRASH("Could not initialize gfxPlatformFontList");
978 gPlatform
->mScreenReferenceDrawTarget
=
979 gPlatform
->CreateOffscreenContentDrawTarget(IntSize(1, 1),
980 SurfaceFormat::B8G8R8A8
);
981 if (!gPlatform
->mScreenReferenceDrawTarget
||
982 !gPlatform
->mScreenReferenceDrawTarget
->IsValid()) {
983 // If TDR is detected, create a draw target with software backend
984 // and it should be replaced later when the process gets the device
985 // reset notification.
986 if (!gPlatform
->DidRenderingDeviceReset()) {
987 gfxCriticalError() << "Could not initialize mScreenReferenceDrawTarget";
991 if (NS_FAILED(gfxFontCache::Init())) {
992 MOZ_CRASH("Could not initialize gfxFontCache");
995 Preferences::RegisterPrefixCallbacks(FontPrefChanged
, kObservedPrefs
);
997 GLContext::PlatformStartup();
999 // Listen to memory pressure event so we can purge DrawTarget caches
1000 gPlatform
->mMemoryPressureObserver
=
1001 layers::MemoryPressureObserver::Create(gPlatform
);
1003 // Request the imgITools service, implicitly initializing ImageLib.
1004 nsCOMPtr
<imgITools
> imgTools
= do_GetService("@mozilla.org/image/tools;1");
1006 MOZ_CRASH("Could not initialize ImageLib");
1009 RegisterStrongMemoryReporter(new GfxMemoryImageReporter());
1010 if (XRE_IsParentProcess()) {
1011 RegisterStrongAsyncMemoryReporter(new WebRenderMemoryReporter());
1014 RegisterStrongMemoryReporter(new SkMemoryReporter());
1016 uint32_t skiaCacheSize
= GetSkiaGlyphCacheSize();
1017 if (skiaCacheSize
!= kDefaultGlyphCacheSize
) {
1018 SkGraphics::SetFontCacheLimit(skiaCacheSize
);
1024 if (XRE_IsParentProcess()) {
1025 Preferences::Unlock(FONT_VARIATIONS_PREF
);
1026 if (!gfxPlatform::HasVariationFontSupport()) {
1027 // Ensure variation fonts are disabled and the pref is locked.
1028 Preferences::SetBool(FONT_VARIATIONS_PREF
, false, PrefValueKind::Default
);
1029 Preferences::SetBool(FONT_VARIATIONS_PREF
, false);
1030 Preferences::Lock(FONT_VARIATIONS_PREF
);
1034 if (XRE_IsParentProcess()) {
1038 nsCOMPtr
<nsIObserverService
> obs
= services::GetObserverService();
1040 obs
->NotifyObservers(nullptr, "gfx-features-ready", nullptr);
1044 void gfxPlatform::ReportTelemetry() {
1045 MOZ_RELEASE_ASSERT(XRE_IsParentProcess(),
1046 "GFX: Only allowed to be called from parent process.");
1048 nsCOMPtr
<nsIGfxInfo
> gfxInfo
= components::GfxInfo::Service();
1051 auto& screenManager
= widget::ScreenManager::GetSingleton();
1052 const uint32_t screenCount
= screenManager
.CurrentScreenList().Length();
1053 RefPtr
<widget::Screen
> primaryScreen
= screenManager
.GetPrimaryScreen();
1054 const LayoutDeviceIntRect rect
= primaryScreen
->GetRect();
1056 mozilla::glean::gfx_display::count
.Set(screenCount
);
1057 mozilla::glean::gfx_display::primary_height
.Set(rect
.Height());
1058 mozilla::glean::gfx_display::primary_width
.Set(rect
.Width());
1060 // Check if any screen known by screenManager supports HDR.
1061 bool supportsHDR
= false;
1062 for (const auto& screen
: screenManager
.CurrentScreenList()) {
1063 supportsHDR
|= screen
->GetIsHDR();
1065 glean::gfx::supports_hdr
.Set(supportsHDR
);
1068 nsString adapterDesc
;
1069 gfxInfo
->GetAdapterDescription(adapterDesc
);
1071 // Android description is constructed in a way that makes it possible to exceed
1072 // the metric's length limit.
1073 #if defined(ANDROID)
1074 if (!adapterDesc
.IsEmpty()) {
1075 adapterDesc
.Truncate(99);
1079 mozilla::glean::gfx_adapter_primary::description
.Set(
1080 NS_ConvertUTF16toUTF8(adapterDesc
));
1082 nsString adapterVendorId
;
1083 gfxInfo
->GetAdapterVendorID(adapterVendorId
);
1084 mozilla::glean::gfx_adapter_primary::vendor_id
.Set(
1085 NS_ConvertUTF16toUTF8(adapterVendorId
));
1087 nsString adapterDeviceId
;
1088 gfxInfo
->GetAdapterDeviceID(adapterDeviceId
);
1089 mozilla::glean::gfx_adapter_primary::device_id
.Set(
1090 NS_ConvertUTF16toUTF8(adapterDeviceId
));
1092 nsString adapterSubsystemId
;
1093 gfxInfo
->GetAdapterSubsysID(adapterSubsystemId
);
1094 mozilla::glean::gfx_adapter_primary::subsystem_id
.Set(
1095 NS_ConvertUTF16toUTF8(adapterSubsystemId
));
1097 uint32_t adapterRam
= 0;
1098 gfxInfo
->GetAdapterRAM(&adapterRam
);
1099 mozilla::glean::gfx_adapter_primary::ram
.Set(adapterRam
);
1101 nsString adapterDriver
;
1102 gfxInfo
->GetAdapterDriver(adapterDriver
);
1103 mozilla::glean::gfx_adapter_primary::driver_files
.Set(
1104 NS_ConvertUTF16toUTF8(adapterDriver
));
1106 nsString adapterDriverVendor
;
1107 gfxInfo
->GetAdapterDriverVendor(adapterDriverVendor
);
1108 mozilla::glean::gfx_adapter_primary::driver_vendor
.Set(
1109 NS_ConvertUTF16toUTF8(adapterDriverVendor
));
1111 nsString adapterDriverVersion
;
1112 gfxInfo
->GetAdapterDriverVersion(adapterDriverVersion
);
1113 mozilla::glean::gfx_adapter_primary::driver_version
.Set(
1114 NS_ConvertUTF16toUTF8(adapterDriverVersion
));
1116 nsString adapterDriverDate
;
1117 gfxInfo
->GetAdapterDriverDate(adapterDriverDate
);
1118 mozilla::glean::gfx_adapter_primary::driver_date
.Set(
1119 NS_ConvertUTF16toUTF8(adapterDriverDate
));
1121 mozilla::glean::gfx_status::headless
.Set(IsHeadless());
1124 static bool IsFeatureSupported(long aFeature
, bool aDefault
) {
1125 nsCOMPtr
<nsIGfxInfo
> gfxInfo
= components::GfxInfo::Service();
1128 if (!NS_SUCCEEDED(gfxInfo
->GetFeatureStatus(aFeature
, blockId
, &status
))) {
1131 return status
== nsIGfxInfo::FEATURE_STATUS_OK
;
1135 bool gfxPlatform::IsDXInterop2Blocked() {
1136 return !IsFeatureSupported(nsIGfxInfo::FEATURE_DX_INTEROP2
, false);
1140 bool gfxPlatform::IsDXNV12Blocked() {
1141 return !IsFeatureSupported(nsIGfxInfo::FEATURE_DX_NV12
, false);
1145 bool gfxPlatform::IsDXP010Blocked() {
1146 return !IsFeatureSupported(nsIGfxInfo::FEATURE_DX_P010
, false);
1150 bool gfxPlatform::IsDXP016Blocked() {
1151 return !IsFeatureSupported(nsIGfxInfo::FEATURE_DX_P016
, false);
1155 int32_t gfxPlatform::MaxTextureSize() {
1156 // Make sure we don't completely break rendering because of a typo in the
1158 const int32_t kMinSizePref
= 2048;
1161 StaticPrefs::gfx_max_texture_size_AtStartup_DoNotUseDirectly());
1165 int32_t gfxPlatform::MaxAllocSize() {
1166 // Make sure we don't completely break rendering because of a typo in the
1168 const int32_t kMinAllocPref
= 10000000;
1169 return std::max(kMinAllocPref
,
1170 StaticPrefs::gfx_max_alloc_size_AtStartup_DoNotUseDirectly());
1173 void gfxPlatform::MaybeInitializeCMS() {
1174 if (XRE_IsGPUProcess()) {
1175 // Colors in the GPU process should already be managed, so we don't need to
1176 // perform color management there.
1177 gCMSInitialized
= true;
1180 Unused
<< GetPlatform();
1184 void gfxPlatform::InitMoz2DLogging() {
1185 auto fwd
= new CrashStatsLogForwarder(
1186 CrashReporter::Annotation::GraphicsCriticalError
);
1187 fwd
->SetCircularBufferSize(StaticPrefs::gfx_logging_crash_length_AtStartup());
1189 mozilla::gfx::Config cfg
;
1190 cfg
.mLogForwarder
= fwd
;
1191 cfg
.mMaxTextureSize
= gfxPlatform::MaxTextureSize();
1192 cfg
.mMaxAllocSize
= gfxPlatform::MaxAllocSize();
1194 gfx::Factory::Init(cfg
);
1198 bool gfxPlatform::IsHeadless() {
1199 static bool initialized
= false;
1200 static bool headless
= false;
1203 headless
= PR_GetEnv("MOZ_HEADLESS");
1209 bool gfxPlatform::UseRemoteCanvas() {
1210 return XRE_IsContentProcess() && (gfx::gfxVars::RemoteCanvasEnabled() ||
1211 gfx::gfxVars::UseAcceleratedCanvas2D());
1215 bool gfxPlatform::IsBackendAccelerated(
1216 const mozilla::gfx::BackendType aBackendType
) {
1217 return aBackendType
== BackendType::DIRECT2D
||
1218 aBackendType
== BackendType::DIRECT2D1_1
;
1222 bool gfxPlatform::CanMigrateMacGPUs() {
1223 int32_t pMigration
= StaticPrefs::gfx_compositor_gpu_migration();
1225 bool forceDisable
= pMigration
== 0;
1226 bool forceEnable
= pMigration
== 2;
1228 return forceEnable
|| !forceDisable
;
1231 static bool sLayersIPCIsUp
= false;
1234 void gfxPlatform::InitNullMetadata() {
1235 ScrollMetadata::sNullMetadata
= new ScrollMetadata();
1236 ClearOnShutdown(&ScrollMetadata::sNullMetadata
);
1239 void gfxPlatform::Shutdown() {
1240 // In some cases, gPlatform may not be created but Shutdown() called,
1241 // e.g., during xpcshell tests.
1246 MOZ_ASSERT(!sLayersIPCIsUp
);
1248 // These may be called before the corresponding subsystems have actually
1249 // started up. That's OK, they can handle it.
1250 gfxFontCache::Shutdown();
1251 gfxGradientCache::Shutdown();
1252 gfxAlphaBoxBlur::ShutdownBlurCache();
1253 gfxGraphiteShaper::Shutdown();
1254 gfxPlatformFontList::Shutdown();
1255 gfxFontMissingGlyphs::Shutdown();
1257 // Free the various non-null transforms and loaded profiles
1258 gPlatform
->ShutdownCMS();
1260 Preferences::UnregisterPrefixCallbacks(FontPrefChanged
, kObservedPrefs
);
1262 NS_ASSERTION(gPlatform
->mMemoryPressureObserver
,
1263 "mMemoryPressureObserver has already gone");
1264 if (gPlatform
->mMemoryPressureObserver
) {
1265 gPlatform
->mMemoryPressureObserver
->Unregister();
1266 gPlatform
->mMemoryPressureObserver
= nullptr;
1269 if (XRE_IsParentProcess()) {
1270 if (gPlatform
->mGlobalHardwareVsyncSource
) {
1271 gPlatform
->mGlobalHardwareVsyncSource
->Shutdown();
1273 if (gPlatform
->mSoftwareVsyncSource
&&
1274 gPlatform
->mSoftwareVsyncSource
!=
1275 gPlatform
->mGlobalHardwareVsyncSource
) {
1276 gPlatform
->mSoftwareVsyncSource
->Shutdown();
1280 gPlatform
->mGlobalHardwareVsyncSource
= nullptr;
1281 gPlatform
->mSoftwareVsyncSource
= nullptr;
1282 gPlatform
->mVsyncDispatcher
= nullptr;
1284 // Shut down the default GL context provider.
1285 GLContextProvider::Shutdown();
1288 // The above shutdown calls operate on the available context providers on
1289 // most platforms. Windows is a "special snowflake", though, and has three
1290 // context providers available, so we have to shut all of them down.
1291 // We should only support the default GL provider on Windows; then, this
1292 // could go away. Unfortunately, we currently support WGL (the default) for
1293 // WebGL on Optimus.
1294 GLContextProviderEGL::Shutdown();
1297 if (XRE_IsParentProcess()) {
1298 GPUProcessManager::Shutdown();
1299 VRProcessManager::Shutdown();
1300 RDDProcessManager::Shutdown();
1303 gfx::Factory::ShutDown();
1304 gfxVars::Shutdown();
1305 gfxFont::DestroySingletons();
1307 gfxConfig::Shutdown();
1309 gPlatform
->WillShutdown();
1312 gPlatform
= nullptr;
1316 void gfxPlatform::InitLayersIPC() {
1317 if (sLayersIPCIsUp
) {
1320 sLayersIPCIsUp
= true;
1322 if (XRE_IsParentProcess()) {
1324 if (gfxConfig::IsEnabled(gfx::Feature::WINDOW_OCCLUSION
)) {
1325 widget::WinWindowOcclusionTracker::Ensure();
1328 if (!gfxConfig::IsEnabled(Feature::GPU_PROCESS
)) {
1329 RemoteTextureMap::Init();
1330 wr::RenderThread::Start(GPUProcessManager::Get()->AllocateNamespace());
1331 image::ImageMemoryReporter::InitForWebRender();
1334 layers::CompositorThreadHolder::Start();
1336 if (!gfxConfig::IsEnabled(Feature::GPU_PROCESS
)) {
1337 gfx::CanvasRenderThread::Start();
1343 void gfxPlatform::ShutdownLayersIPC() {
1344 if (!sLayersIPCIsUp
) {
1347 sLayersIPCIsUp
= false;
1349 if (XRE_IsContentProcess()) {
1350 gfx::VRManagerChild::ShutDown();
1351 gfx::CanvasShutdownManager::Shutdown();
1352 layers::CompositorManagerChild::Shutdown();
1353 layers::ImageBridgeChild::ShutDown();
1354 } else if (XRE_IsParentProcess()) {
1355 VideoBridgeParent::Shutdown();
1356 RDDProcessManager::RDDProcessShutdown();
1357 gfx::VRManagerChild::ShutDown();
1358 gfx::CanvasShutdownManager::Shutdown();
1359 layers::CompositorManagerChild::Shutdown();
1360 layers::ImageBridgeChild::ShutDown();
1361 // This could be running on either the Compositor thread, the Renderer
1362 // thread, or the dedicated CanvasRender thread, so we need to shutdown
1363 // before the former two.
1364 gfx::CanvasRenderThread::Shutdown();
1365 // This has to happen after shutting down the child protocols.
1366 layers::CompositorThreadHolder::Shutdown();
1367 RemoteTextureMap::Shutdown();
1368 image::ImageMemoryReporter::ShutdownForWebRender();
1369 // There is a case that RenderThread exists when UseWebRender() is
1370 // false. This could happen when WebRender was fallbacked to compositor.
1371 if (wr::RenderThread::Get()) {
1372 wr::RenderThread::ShutDown();
1374 Preferences::UnregisterCallback(WebRenderDebugPrefChangeCallback
,
1376 Preferences::UnregisterCallback(WebRendeProfilerUIPrefChangeCallback
,
1377 "gfx.webrender.debug.profiler-ui");
1378 Preferences::UnregisterCallback(
1379 WebRenderBlobTileSizePrefChangeCallback
,
1381 StaticPrefs::GetPrefName_gfx_webrender_blob_tile_size()));
1384 widget::WinWindowOcclusionTracker::ShutDown();
1387 // TODO: There are other kind of processes and we should make sure gfx
1388 // stuff is either not created there or shut down properly.
1392 void gfxPlatform::WillShutdown() {
1393 // Destoy these first in case they depend on backend-specific resources.
1394 // Otherwise, the backend's destructor would be called before the
1395 // base gfxPlatform destructor.
1396 mScreenReferenceSurface
= nullptr;
1397 mScreenReferenceDrawTarget
= nullptr;
1399 // Always clear out the Skia font cache here, in case it is referencing any
1400 // SharedFTFaces that would otherwise outlive destruction of the FT_Library
1402 SkGraphics::PurgeFontCache();
1404 // The cairo folks think we should only clean up in debug builds,
1405 // but we're generally in the habit of trying to shut down as
1406 // cleanly as possible even in production code, so call this
1407 // cairo_debug_* function unconditionally.
1409 // because cairo can assert and thus crash on shutdown, don't do this in
1411 #ifdef NS_FREE_PERMANENT_DATA
1412 cairo_debug_reset_static_data();
1416 gfxPlatform::~gfxPlatform() = default;
1419 already_AddRefed
<DrawTarget
> gfxPlatform::CreateDrawTargetForSurface(
1420 gfxASurface
* aSurface
, const IntSize
& aSize
) {
1421 SurfaceFormat format
= aSurface
->GetSurfaceFormat();
1422 RefPtr
<DrawTarget
> drawTarget
= Factory::CreateDrawTargetForCairoSurface(
1423 aSurface
->CairoSurface(), aSize
, &format
);
1425 gfxWarning() << "gfxPlatform::CreateDrawTargetForSurface failed in "
1426 "CreateDrawTargetForCairoSurface";
1429 return drawTarget
.forget();
1432 cairo_user_data_key_t kSourceSurface
;
1435 * Record the backend that was used to construct the SourceSurface.
1436 * When getting the cached SourceSurface for a gfxASurface/DrawTarget pair,
1437 * we check to make sure the DrawTarget's backend matches the backend
1438 * for the cached SourceSurface, and only use it if they match. This
1439 * can avoid expensive and unnecessary readbacks.
1441 struct SourceSurfaceUserData
{
1442 RefPtr
<SourceSurface
> mSrcSurface
;
1443 BackendType mBackendType
;
1446 static void SourceBufferDestroy(void* srcSurfUD
) {
1447 delete static_cast<SourceSurfaceUserData
*>(srcSurfUD
);
1450 UserDataKey kThebesSurface
;
1452 struct DependentSourceSurfaceUserData
{
1453 RefPtr
<gfxASurface
> mSurface
;
1456 static void SourceSurfaceDestroyed(void* aData
) {
1457 delete static_cast<DependentSourceSurfaceUserData
*>(aData
);
1460 void gfxPlatform::ClearSourceSurfaceForSurface(gfxASurface
* aSurface
) {
1461 aSurface
->SetData(&kSourceSurface
, nullptr, nullptr);
1465 already_AddRefed
<SourceSurface
> gfxPlatform::GetSourceSurfaceForSurface(
1466 RefPtr
<DrawTarget
> aTarget
, gfxASurface
* aSurface
, bool aIsPlugin
) {
1467 if (!aSurface
->CairoSurface() || aSurface
->CairoStatus()) {
1472 aTarget
= gfxPlatform::GetPlatform()->ScreenReferenceDrawTarget();
1475 void* userData
= aSurface
->GetData(&kSourceSurface
);
1478 SourceSurfaceUserData
* surf
= static_cast<SourceSurfaceUserData
*>(userData
);
1480 if (surf
->mSrcSurface
->IsValid() &&
1481 surf
->mBackendType
== aTarget
->GetBackendType()) {
1482 RefPtr
<SourceSurface
> srcSurface(surf
->mSrcSurface
);
1483 return srcSurface
.forget();
1485 // We can just continue here as when setting new user data the destroy
1486 // function will be called for the old user data.
1489 SurfaceFormat format
= aSurface
->GetSurfaceFormat();
1491 if (aTarget
->GetBackendType() == BackendType::CAIRO
) {
1492 // If we're going to be used with a CAIRO DrawTarget, then just create a
1493 // SourceSurfaceCairo since we don't know the underlying type of the CAIRO
1494 // DrawTarget and can't pick a better surface type. Doing this also avoids
1495 // readback of aSurface's surface into memory if, for example, aSurface
1496 // wraps an xlib cairo surface (which can be important to avoid a major
1499 // We return here regardless of whether CreateSourceSurfaceFromNativeSurface
1500 // succeeds or not since we don't expect to be able to do any better below
1503 // Note that the returned SourceSurfaceCairo holds a strong reference to
1504 // the cairo_surface_t* that it wraps, which essencially means it holds a
1505 // strong reference to aSurface since aSurface shares its
1506 // cairo_surface_t*'s reference count variable. As a result we can't cache
1507 // srcBuffer on aSurface (see below) since aSurface would then hold a
1508 // strong reference back to srcBuffer, creating a reference loop and a
1509 // memory leak. Not caching is fine since wrapping is cheap enough (no
1510 // copying) so we can just wrap again next time we're called.
1511 return Factory::CreateSourceSurfaceForCairoSurface(
1512 aSurface
->CairoSurface(), aSurface
->GetSize(), format
);
1515 RefPtr
<SourceSurface
> srcBuffer
;
1517 // Currently no other DrawTarget types implement
1518 // CreateSourceSurfaceFromNativeSurface
1521 // If aSurface wraps data, we can create a SourceSurfaceRawData that wraps
1522 // the same data, then optimize it for aTarget:
1523 RefPtr
<DataSourceSurface
> surf
= GetWrappedDataSourceSurface(aSurface
);
1525 srcBuffer
= aIsPlugin
1526 ? aTarget
->OptimizeSourceSurfaceForUnknownAlpha(surf
)
1527 : aTarget
->OptimizeSourceSurface(surf
);
1529 if (srcBuffer
== surf
) {
1530 // GetWrappedDataSourceSurface returns a SourceSurface that holds a
1531 // strong reference to aSurface since it wraps aSurface's data and
1532 // needs it to stay alive. As a result we can't cache srcBuffer on
1533 // aSurface (below) since aSurface would then hold a strong reference
1534 // back to srcBuffer, creating a reference loop and a memory leak. Not
1535 // caching is fine since wrapping is cheap enough (no copying) so we
1536 // can just wrap again next time we're called.
1538 // Note that the check below doesn't catch this since srcBuffer will be
1539 // a SourceSurfaceRawData object (even if aSurface is not a
1540 // gfxImageSurface object), which is why we need this separate check.
1541 return srcBuffer
.forget();
1547 MOZ_ASSERT(aTarget
->GetBackendType() != BackendType::CAIRO
,
1548 "We already tried CreateSourceSurfaceFromNativeSurface with a "
1549 "DrawTargetCairo above");
1550 // We've run out of performant options. We now try creating a SourceSurface
1551 // using a temporary DrawTargetCairo and then optimizing it to aTarget's
1552 // actual type. The CreateSourceSurfaceFromNativeSurface() call will
1553 // likely create a DataSourceSurface (possibly involving copying and/or
1554 // readback), and the OptimizeSourceSurface may well copy again and upload
1555 // to the GPU. So, while this code path is rarely hit, hitting it may be
1557 srcBuffer
= Factory::CreateSourceSurfaceForCairoSurface(
1558 aSurface
->CairoSurface(), aSurface
->GetSize(), format
);
1560 srcBuffer
= aTarget
->OptimizeSourceSurface(srcBuffer
);
1568 if ((srcBuffer
->GetType() == SurfaceType::CAIRO
&&
1569 static_cast<SourceSurfaceCairo
*>(srcBuffer
.get())->GetSurface() ==
1570 aSurface
->CairoSurface()) ||
1571 (srcBuffer
->GetType() == SurfaceType::CAIRO_IMAGE
&&
1572 static_cast<DataSourceSurfaceCairo
*>(srcBuffer
.get())->GetSurface() ==
1573 aSurface
->CairoSurface())) {
1574 // See the "Note that the returned SourceSurfaceCairo..." comment above.
1575 return srcBuffer
.forget();
1578 // Add user data to aSurface so we can cache lookups in the future.
1579 auto* srcSurfUD
= new SourceSurfaceUserData
;
1580 srcSurfUD
->mBackendType
= aTarget
->GetBackendType();
1581 srcSurfUD
->mSrcSurface
= srcBuffer
;
1582 aSurface
->SetData(&kSourceSurface
, srcSurfUD
, SourceBufferDestroy
);
1584 return srcBuffer
.forget();
1587 already_AddRefed
<DataSourceSurface
> gfxPlatform::GetWrappedDataSourceSurface(
1588 gfxASurface
* aSurface
) {
1589 RefPtr
<gfxImageSurface
> image
= aSurface
->GetAsImageSurface();
1593 RefPtr
<DataSourceSurface
> result
= Factory::CreateWrappingDataSourceSurface(
1594 image
->Data(), image
->Stride(), image
->GetSize(),
1595 ImageFormatToSurfaceFormat(image
->Format()));
1601 // If we wrapped the underlying data of aSurface, then we need to add user
1602 // data to make sure aSurface stays alive until we are done with the data.
1603 auto* srcSurfUD
= new DependentSourceSurfaceUserData
;
1604 srcSurfUD
->mSurface
= aSurface
;
1605 result
->AddUserData(&kThebesSurface
, srcSurfUD
, SourceSurfaceDestroyed
);
1607 return result
.forget();
1610 void gfxPlatform::PopulateScreenInfo() {
1611 // We're only going to set some gfxVars here, which is only possible from
1612 // the parent process.
1613 if (!XRE_IsParentProcess()) {
1617 nsCOMPtr
<nsIScreenManager
> manager
=
1618 do_GetService("@mozilla.org/gfx/screenmanager;1");
1619 MOZ_ASSERT(manager
, "failed to get nsIScreenManager");
1621 nsCOMPtr
<nsIScreen
> screen
;
1622 manager
->GetPrimaryScreen(getter_AddRefs(screen
));
1624 // This can happen in xpcshell, for instance
1628 int32_t screenDepth
;
1629 screen
->GetColorDepth(&screenDepth
);
1630 gfxVars::SetPrimaryScreenDepth(screenDepth
);
1633 bool gfxPlatform::SupportsAzureContentForDrawTarget(DrawTarget
* aTarget
) {
1634 if (!aTarget
|| !aTarget
->IsValid()) {
1638 return SupportsAzureContentForType(aTarget
->GetBackendType());
1641 void gfxPlatform::PurgeSkiaFontCache() {
1642 if (gfxPlatform::GetPlatform()->GetDefaultContentBackend() ==
1643 BackendType::SKIA
) {
1644 SkGraphics::PurgeFontCache();
1648 already_AddRefed
<DrawTarget
> gfxPlatform::CreateDrawTargetForBackend(
1649 BackendType aBackend
, const IntSize
& aSize
, SurfaceFormat aFormat
) {
1650 // There is a bunch of knowledge in the gfxPlatform heirarchy about how to
1651 // create the best offscreen surface for the current system and situation. We
1652 // can easily take advantage of this for the Cairo backend, so that's what we
1654 // mozilla::gfx::Factory can get away without having all this knowledge for
1655 // now, but this might need to change in the future (using
1656 // CreateOffscreenSurface() and CreateDrawTargetForSurface() for all
1658 if (aBackend
== BackendType::CAIRO
) {
1659 RefPtr
<gfxASurface
> surf
=
1660 CreateOffscreenSurface(aSize
, SurfaceFormatToImageFormat(aFormat
));
1661 if (!surf
|| surf
->CairoStatus()) {
1664 return CreateDrawTargetForSurface(surf
, aSize
);
1666 return Factory::CreateDrawTarget(aBackend
, aSize
, aFormat
);
1669 already_AddRefed
<DrawTarget
> gfxPlatform::CreateOffscreenCanvasDrawTarget(
1670 const IntSize
& aSize
, SurfaceFormat aFormat
, bool aRequireSoftwareRender
) {
1671 NS_ASSERTION(mPreferredCanvasBackend
!= BackendType::NONE
, "No backend.");
1673 BackendType backend
= mFallbackCanvasBackend
;
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 backend
= mPreferredCanvasBackend
;
1682 if (aRequireSoftwareRender
) {
1683 backend
= gfxPlatform::IsBackendAccelerated(mPreferredCanvasBackend
)
1684 ? mFallbackCanvasBackend
1685 : mPreferredCanvasBackend
;
1689 // On Windows, the fallback backend (Cairo) should use its image backend.
1690 RefPtr
<DrawTarget
> target
=
1691 Factory::CreateDrawTarget(backend
, aSize
, aFormat
);
1693 RefPtr
<DrawTarget
> target
=
1694 CreateDrawTargetForBackend(backend
, aSize
, aFormat
);
1697 if (target
|| mFallbackCanvasBackend
== BackendType::NONE
) {
1698 return target
.forget();
1702 // On Windows, the fallback backend (Cairo) should use its image backend.
1703 return Factory::CreateDrawTarget(mFallbackCanvasBackend
, aSize
, aFormat
);
1705 return CreateDrawTargetForBackend(mFallbackCanvasBackend
, aSize
, aFormat
);
1709 already_AddRefed
<DrawTarget
> gfxPlatform::CreateOffscreenContentDrawTarget(
1710 const IntSize
& aSize
, SurfaceFormat aFormat
, bool aFallback
) {
1711 BackendType backend
= (aFallback
) ? mSoftwareBackend
: mContentBackend
;
1712 NS_ASSERTION(backend
!= BackendType::NONE
, "No backend.");
1713 RefPtr
<DrawTarget
> dt
= CreateDrawTargetForBackend(backend
, aSize
, aFormat
);
1719 // We'd prefer this to take proper care and return a CaptureDT, but for the
1720 // moment since we can't and this means we're going to be drawing on the main
1721 // thread force it's initialization. See bug 1526045 and bug 1521368.
1722 dt
->ClearRect(gfx::Rect());
1723 if (!dt
->IsValid()) {
1729 already_AddRefed
<DrawTarget
> gfxPlatform::CreateSimilarSoftwareDrawTarget(
1730 DrawTarget
* aDT
, const IntSize
& aSize
, SurfaceFormat aFormat
) {
1731 RefPtr
<DrawTarget
> dt
;
1733 if (Factory::DoesBackendSupportDataDrawtarget(aDT
->GetBackendType())) {
1734 dt
= aDT
->CreateSimilarDrawTarget(aSize
, aFormat
);
1736 BackendType backendType
= BackendType::SKIA
;
1737 dt
= Factory::CreateDrawTarget(backendType
, aSize
, aFormat
);
1744 already_AddRefed
<DrawTarget
> gfxPlatform::CreateDrawTargetForData(
1745 unsigned char* aData
, const IntSize
& aSize
, int32_t aStride
,
1746 SurfaceFormat aFormat
, bool aUninitialized
) {
1747 BackendType backendType
= gfxVars::ContentBackend();
1748 NS_ASSERTION(backendType
!= BackendType::NONE
, "No backend.");
1750 if (!Factory::DoesBackendSupportDataDrawtarget(backendType
)) {
1751 backendType
= BackendType::SKIA
;
1754 RefPtr
<DrawTarget
> dt
= Factory::CreateDrawTargetForData(
1755 backendType
, aData
, aSize
, aStride
, aFormat
, aUninitialized
);
1761 BackendType
gfxPlatform::BackendTypeForName(const nsCString
& aName
) {
1762 if (aName
.EqualsLiteral("cairo")) return BackendType::CAIRO
;
1763 if (aName
.EqualsLiteral("skia")) return BackendType::SKIA
;
1764 if (aName
.EqualsLiteral("direct2d")) return BackendType::DIRECT2D
;
1765 if (aName
.EqualsLiteral("direct2d1.1")) return BackendType::DIRECT2D1_1
;
1766 return BackendType::NONE
;
1769 nsresult
gfxPlatform::GetFontList(nsAtom
* aLangGroup
,
1770 const nsACString
& aGenericFamily
,
1771 nsTArray
<nsString
>& aListOfFonts
) {
1772 gfxPlatformFontList::PlatformFontList()->GetFontList(
1773 aLangGroup
, aGenericFamily
, aListOfFonts
);
1777 nsresult
gfxPlatform::UpdateFontList(bool aFullRebuild
) {
1778 gfxPlatformFontList::PlatformFontList()->UpdateFontList(aFullRebuild
);
1782 void gfxPlatform::GetStandardFamilyName(const nsCString
& aFontName
,
1783 nsACString
& aFamilyName
) {
1784 gfxPlatformFontList::PlatformFontList()->GetStandardFamilyName(aFontName
,
1788 nsAutoCString
gfxPlatform::GetDefaultFontName(
1789 const nsACString
& aLangGroup
, const nsACString
& aGenericFamily
) {
1790 // To benefit from Return Value Optimization, all paths here must return
1791 // this one variable:
1792 nsAutoCString result
;
1794 auto* pfl
= gfxPlatformFontList::PlatformFontList();
1795 FamilyAndGeneric fam
= pfl
->GetDefaultFontFamily(aLangGroup
, aGenericFamily
);
1796 if (!pfl
->GetLocalizedFamilyName(fam
.mFamily
, result
)) {
1797 NS_WARNING("missing default font-family name");
1803 bool gfxPlatform::DownloadableFontsEnabled() {
1804 if (mAllowDownloadableFonts
== UNINITIALIZED_VALUE
) {
1805 mAllowDownloadableFonts
=
1806 Preferences::GetBool(GFX_DOWNLOADABLE_FONTS_ENABLED
, false);
1809 return mAllowDownloadableFonts
;
1812 bool gfxPlatform::UseCmapsDuringSystemFallback() {
1813 return StaticPrefs::gfx_font_rendering_fallback_always_use_cmaps();
1816 bool gfxPlatform::OpenTypeSVGEnabled() {
1817 return StaticPrefs::gfx_font_rendering_opentype_svg_enabled();
1820 uint32_t gfxPlatform::WordCacheCharLimit() {
1821 return StaticPrefs::gfx_font_rendering_wordcache_charlimit();
1824 uint32_t gfxPlatform::WordCacheMaxEntries() {
1825 return StaticPrefs::gfx_font_rendering_wordcache_maxentries();
1828 bool gfxPlatform::UseGraphiteShaping() {
1829 return StaticPrefs::gfx_font_rendering_graphite_enabled();
1832 bool gfxPlatform::IsFontFormatSupported(
1833 StyleFontFaceSourceFormatKeyword aFormatHint
,
1834 StyleFontFaceSourceTechFlags aTechFlags
) {
1835 // By default, font resources are assumed to be supported; but if the format
1836 // hint or technology flags explicitly indicate something we don't support,
1837 // then return false.
1838 switch (aFormatHint
) {
1839 case StyleFontFaceSourceFormatKeyword::None
:
1841 case StyleFontFaceSourceFormatKeyword::Collection
:
1843 case StyleFontFaceSourceFormatKeyword::Opentype
:
1844 case StyleFontFaceSourceFormatKeyword::Truetype
:
1846 case StyleFontFaceSourceFormatKeyword::EmbeddedOpentype
:
1848 case StyleFontFaceSourceFormatKeyword::Svg
:
1850 case StyleFontFaceSourceFormatKeyword::Woff
:
1852 case StyleFontFaceSourceFormatKeyword::Woff2
:
1854 case StyleFontFaceSourceFormatKeyword::Unknown
:
1857 MOZ_ASSERT_UNREACHABLE("bad format hint!");
1860 StyleFontFaceSourceTechFlags unsupportedTechnologies
=
1861 StyleFontFaceSourceTechFlags::INCREMENTAL
|
1862 StyleFontFaceSourceTechFlags::COLOR_SBIX
;
1863 if (!StaticPrefs::gfx_downloadable_fonts_keep_color_bitmaps()) {
1864 unsupportedTechnologies
|= StyleFontFaceSourceTechFlags::COLOR_CBDT
;
1866 if (!StaticPrefs::gfx_font_rendering_colr_v1_enabled()) {
1867 unsupportedTechnologies
|= StyleFontFaceSourceTechFlags::COLOR_COLRV1
;
1869 if (!StaticPrefs::layout_css_font_palette_enabled()) {
1870 unsupportedTechnologies
|= StyleFontFaceSourceTechFlags::PALETTES
;
1872 if (!StaticPrefs::layout_css_font_variations_enabled()) {
1873 unsupportedTechnologies
|= StyleFontFaceSourceTechFlags::VARIATIONS
;
1875 if (aTechFlags
& unsupportedTechnologies
) {
1881 bool gfxPlatform::IsKnownIconFontFamily(const nsAtom
* aFamilyName
) const {
1882 return gfxPlatformFontList::PlatformFontList()->IsKnownIconFontFamily(
1886 gfxFontEntry
* gfxPlatform::LookupLocalFont(nsPresContext
* aPresContext
,
1887 const nsACString
& aFontName
,
1888 WeightRange aWeightForEntry
,
1889 StretchRange aStretchForEntry
,
1890 SlantStyleRange aStyleForEntry
) {
1891 return gfxPlatformFontList::PlatformFontList()->LookupLocalFont(
1892 aPresContext
, aFontName
, aWeightForEntry
, aStretchForEntry
,
1896 gfxFontEntry
* gfxPlatform::MakePlatformFont(const nsACString
& aFontName
,
1897 WeightRange aWeightForEntry
,
1898 StretchRange aStretchForEntry
,
1899 SlantStyleRange aStyleForEntry
,
1900 const uint8_t* aFontData
,
1902 return gfxPlatformFontList::PlatformFontList()->MakePlatformFont(
1903 aFontName
, aWeightForEntry
, aStretchForEntry
, aStyleForEntry
, aFontData
,
1907 BackendPrefsData
gfxPlatform::GetBackendPrefs() const {
1908 BackendPrefsData data
;
1910 data
.mCanvasBitmask
= BackendTypeBit(BackendType::SKIA
);
1911 data
.mContentBitmask
= BackendTypeBit(BackendType::SKIA
);
1913 #ifdef MOZ_WIDGET_GTK
1914 data
.mCanvasBitmask
|= BackendTypeBit(BackendType::CAIRO
);
1915 data
.mContentBitmask
|= BackendTypeBit(BackendType::CAIRO
);
1918 data
.mCanvasDefault
= BackendType::SKIA
;
1919 data
.mContentDefault
= BackendType::SKIA
;
1924 void gfxPlatform::InitBackendPrefs(BackendPrefsData
&& aPrefsData
) {
1925 mPreferredCanvasBackend
= GetCanvasBackendPref(aPrefsData
.mCanvasBitmask
);
1926 if (mPreferredCanvasBackend
== BackendType::NONE
) {
1927 mPreferredCanvasBackend
= aPrefsData
.mCanvasDefault
;
1930 if (mPreferredCanvasBackend
== BackendType::DIRECT2D1_1
) {
1931 // Falling back to D2D 1.0 won't help us here. When D2D 1.1 DT creation
1932 // fails it means the surface was too big or there's something wrong with
1933 // the device. D2D 1.0 will encounter a similar situation.
1934 mFallbackCanvasBackend
= GetCanvasBackendPref(
1935 aPrefsData
.mCanvasBitmask
& ~(BackendTypeBit(mPreferredCanvasBackend
) |
1936 BackendTypeBit(BackendType::DIRECT2D
)));
1938 mFallbackCanvasBackend
= GetCanvasBackendPref(
1939 aPrefsData
.mCanvasBitmask
& ~BackendTypeBit(mPreferredCanvasBackend
));
1942 mContentBackendBitmask
= aPrefsData
.mContentBitmask
;
1943 mContentBackend
= GetContentBackendPref(mContentBackendBitmask
);
1944 if (mContentBackend
== BackendType::NONE
) {
1945 mContentBackend
= aPrefsData
.mContentDefault
;
1946 // mContentBackendBitmask is our canonical reference for supported
1947 // backends so we need to add the default if we are using it and
1948 // overriding the prefs.
1949 mContentBackendBitmask
|= BackendTypeBit(aPrefsData
.mContentDefault
);
1952 uint32_t swBackendBits
= BackendTypeBit(BackendType::SKIA
);
1953 #ifdef MOZ_WIDGET_GTK
1954 swBackendBits
|= BackendTypeBit(BackendType::CAIRO
);
1956 mSoftwareBackend
= GetContentBackendPref(swBackendBits
);
1957 if (mSoftwareBackend
== BackendType::NONE
) {
1958 mSoftwareBackend
= BackendType::SKIA
;
1961 // If we don't have a fallback canvas backend then use the same software
1962 // fallback as content.
1963 if (mFallbackCanvasBackend
== BackendType::NONE
) {
1964 mFallbackCanvasBackend
= mSoftwareBackend
;
1967 if (XRE_IsParentProcess()) {
1968 gfxVars::SetContentBackend(mContentBackend
);
1969 gfxVars::SetSoftwareBackend(mSoftwareBackend
);
1974 BackendType
gfxPlatform::GetCanvasBackendPref(uint32_t aBackendBitmask
) {
1975 return GetBackendPref("gfx.canvas.azure.backends", aBackendBitmask
);
1979 BackendType
gfxPlatform::GetContentBackendPref(uint32_t& aBackendBitmask
) {
1980 return GetBackendPref("gfx.content.azure.backends", aBackendBitmask
);
1984 BackendType
gfxPlatform::GetBackendPref(const char* aBackendPrefName
,
1985 uint32_t& aBackendBitmask
) {
1986 nsTArray
<nsCString
> backendList
;
1987 nsAutoCString prefString
;
1988 if (NS_SUCCEEDED(Preferences::GetCString(aBackendPrefName
, prefString
))) {
1989 ParseString(prefString
, ',', backendList
);
1992 uint32_t allowedBackends
= 0;
1993 BackendType result
= BackendType::NONE
;
1994 for (uint32_t i
= 0; i
< backendList
.Length(); ++i
) {
1995 BackendType type
= BackendTypeForName(backendList
[i
]);
1996 if (BackendTypeBit(type
) & aBackendBitmask
) {
1997 allowedBackends
|= BackendTypeBit(type
);
1998 if (result
== BackendType::NONE
) {
2004 aBackendBitmask
= allowedBackends
;
2008 bool gfxPlatform::InSafeMode() {
2009 static bool sSafeModeInitialized
= false;
2010 static bool sInSafeMode
= false;
2012 if (!sSafeModeInitialized
) {
2013 sSafeModeInitialized
= true;
2014 nsCOMPtr
<nsIXULRuntime
> xr
= do_GetService("@mozilla.org/xre/runtime;1");
2016 xr
->GetInSafeMode(&sInSafeMode
);
2022 bool gfxPlatform::OffMainThreadCompositingEnabled() {
2023 return UsesOffMainThreadCompositing();
2026 void gfxPlatform::SetCMSModeOverride(CMSMode aMode
) { gCMSMode
= aMode
; }
2028 int gfxPlatform::GetRenderingIntent() {
2029 // StaticPrefList.yaml is using 0 as the default for the rendering
2030 // intent preference, based on that being the value for
2031 // QCMS_INTENT_DEFAULT. Assert here to catch if that ever
2032 // changes and we can then figure out what to do about it.
2033 MOZ_ASSERT(QCMS_INTENT_DEFAULT
== 0);
2035 /* Try to query the pref system for a rendering intent. */
2036 int32_t pIntent
= StaticPrefs::gfx_color_management_rendering_intent();
2037 if ((pIntent
< QCMS_INTENT_MIN
) || (pIntent
> QCMS_INTENT_MAX
)) {
2038 /* If the pref is out of range, use embedded profile. */
2044 DeviceColor
gfxPlatform::TransformPixel(const sRGBColor
& in
,
2045 qcms_transform
* transform
) {
2047 /* we want the bytes in RGB order */
2048 #ifdef IS_LITTLE_ENDIAN
2049 /* ABGR puts the bytes in |RGBA| order on little endian */
2050 uint32_t packed
= in
.ToABGR();
2051 qcms_transform_data(transform
, (uint8_t*)&packed
, (uint8_t*)&packed
, 1);
2052 auto out
= DeviceColor::FromABGR(packed
);
2054 /* ARGB puts the bytes in |ARGB| order on big endian */
2055 uint32_t packed
= in
.UnusualToARGB();
2056 /* add one to move past the alpha byte */
2057 qcms_transform_data(transform
, (uint8_t*)&packed
+ 1, (uint8_t*)&packed
+ 1,
2059 auto out
= DeviceColor::UnusualFromARGB(packed
);
2064 return DeviceColor(in
.r
, in
.g
, in
.b
, in
.a
);
2067 nsTArray
<uint8_t> gfxPlatform::GetPrefCMSOutputProfileData() {
2068 const auto mirror
= StaticPrefs::gfx_color_management_display_profile();
2069 const auto fname
= *mirror
;
2071 return nsTArray
<uint8_t>();
2074 void* mem
= nullptr;
2076 qcms_data_from_path(fname
.get(), &mem
, &size
);
2078 nsTArray
<uint8_t> result
;
2081 result
.AppendElements(static_cast<uint8_t*>(mem
), size
);
2088 Maybe
<nsTArray
<uint8_t>>& gfxPlatform::GetCMSOutputProfileData() {
2089 return mCMSOutputProfileData
;
2092 CMSMode
GfxColorManagementMode() {
2093 const auto mode
= StaticPrefs::gfx_color_management_mode();
2094 if (mode
>= 0 && mode
<= UnderlyingValue(CMSMode::_ENUM_MAX
)) {
2095 return CMSMode(mode
);
2097 return CMSMode::Off
;
2100 void gfxPlatform::InitializeCMS() {
2101 gCMSInitialized
= true;
2102 gCMSMode
= GfxColorManagementMode();
2104 mCMSsRGBProfile
= qcms_profile_sRGB();
2106 /* Determine if we're using the internal override to force sRGB as
2107 an output profile for reftests. See Bug 452125.
2109 Note that we don't normally (outside of tests) set a default value
2110 of this preference, which means nsIPrefBranch::GetBoolPref will
2111 typically throw (and leave its out-param untouched).
2113 if (StaticPrefs::gfx_color_management_force_srgb() ||
2114 StaticPrefs::gfx_color_management_native_srgb()) {
2115 mCMSOutputProfile
= mCMSsRGBProfile
;
2118 if (!mCMSOutputProfile
) {
2119 nsTArray
<uint8_t> outputProfileData
= GetPlatformCMSOutputProfileData();
2120 if (!outputProfileData
.IsEmpty()) {
2121 mCMSOutputProfile
= qcms_profile_from_memory_curves_only(
2122 outputProfileData
.Elements(), outputProfileData
.Length());
2126 /* Determine if the profile looks bogus. If so, close the profile
2127 * and use sRGB instead. See bug 460629, */
2128 if (mCMSOutputProfile
&& qcms_profile_is_bogus(mCMSOutputProfile
)) {
2129 NS_ASSERTION(mCMSOutputProfile
!= mCMSsRGBProfile
,
2130 "Builtin sRGB profile tagged as bogus!!!");
2131 qcms_profile_release(mCMSOutputProfile
);
2132 mCMSOutputProfile
= nullptr;
2135 if (!mCMSOutputProfile
) {
2136 mCMSOutputProfile
= mCMSsRGBProfile
;
2139 /* Precache the LUT16 Interpolations for the output profile. See
2140 bug 444661 for details. */
2141 qcms_profile_precache_output_transform(mCMSOutputProfile
);
2143 // Create the RGB transform.
2145 qcms_transform_create(mCMSsRGBProfile
, QCMS_DATA_RGB_8
, mCMSOutputProfile
,
2146 QCMS_DATA_RGB_8
, QCMS_INTENT_PERCEPTUAL
);
2149 mCMSInverseRGBTransform
=
2150 qcms_transform_create(mCMSOutputProfile
, QCMS_DATA_RGB_8
, mCMSsRGBProfile
,
2151 QCMS_DATA_RGB_8
, QCMS_INTENT_PERCEPTUAL
);
2153 // The RGBA transform.
2154 mCMSRGBATransform
= qcms_transform_create(mCMSsRGBProfile
, QCMS_DATA_RGBA_8
,
2155 mCMSOutputProfile
, QCMS_DATA_RGBA_8
,
2156 QCMS_INTENT_PERCEPTUAL
);
2158 // And the BGRA one.
2159 mCMSBGRATransform
= qcms_transform_create(mCMSsRGBProfile
, QCMS_DATA_BGRA_8
,
2160 mCMSOutputProfile
, QCMS_DATA_BGRA_8
,
2161 QCMS_INTENT_PERCEPTUAL
);
2163 // FIXME: We only enable iccv4 after we create the platform profile, to
2164 // wallpaper over bug 1697787.
2166 // This should happen ideally right after setting gCMSMode.
2167 if (StaticPrefs::gfx_color_management_enablev4()) {
2168 qcms_enable_iccv4();
2172 qcms_transform
* gfxPlatform::GetCMSOSRGBATransform() {
2173 switch (SurfaceFormat::OS_RGBA
) {
2174 case SurfaceFormat::B8G8R8A8
:
2175 return GetCMSBGRATransform();
2176 case SurfaceFormat::R8G8B8A8
:
2177 return GetCMSRGBATransform();
2179 // We do not support color management with big endian.
2184 qcms_data_type
gfxPlatform::GetCMSOSRGBAType() {
2185 switch (SurfaceFormat::OS_RGBA
) {
2186 case SurfaceFormat::B8G8R8A8
:
2187 return QCMS_DATA_BGRA_8
;
2188 case SurfaceFormat::R8G8B8A8
:
2189 return QCMS_DATA_RGBA_8
;
2191 // We do not support color management with big endian.
2192 return QCMS_DATA_RGBA_8
;
2196 /* Shuts down various transforms and profiles for CMS. */
2197 void gfxPlatform::ShutdownCMS() {
2198 if (mCMSRGBTransform
) {
2199 qcms_transform_release(mCMSRGBTransform
);
2200 mCMSRGBTransform
= nullptr;
2202 if (mCMSInverseRGBTransform
) {
2203 qcms_transform_release(mCMSInverseRGBTransform
);
2204 mCMSInverseRGBTransform
= nullptr;
2206 if (mCMSRGBATransform
) {
2207 qcms_transform_release(mCMSRGBATransform
);
2208 mCMSRGBATransform
= nullptr;
2210 if (mCMSBGRATransform
) {
2211 qcms_transform_release(mCMSBGRATransform
);
2212 mCMSBGRATransform
= nullptr;
2214 if (mCMSOutputProfile
) {
2215 // handle the aliased case
2216 if (mCMSsRGBProfile
== mCMSOutputProfile
) {
2217 mCMSsRGBProfile
= nullptr;
2220 qcms_profile_release(mCMSOutputProfile
);
2221 mCMSOutputProfile
= nullptr;
2223 if (mCMSsRGBProfile
) {
2224 qcms_profile_release(mCMSsRGBProfile
);
2225 mCMSsRGBProfile
= nullptr;
2228 // Reset the state variables
2229 gCMSMode
= CMSMode::Off
;
2232 uint32_t gfxPlatform::GetBidiNumeralOption() {
2233 return StaticPrefs::bidi_numeral();
2237 void gfxPlatform::FlushFontAndWordCaches() {
2238 gfxFontCache
* fontCache
= gfxFontCache::GetCache();
2243 gfxPlatform::PurgeSkiaFontCache();
2247 void gfxPlatform::ForceGlobalReflow(NeedsReframe aNeedsReframe
,
2248 BroadcastToChildren aBroadcastToChildren
) {
2249 MOZ_ASSERT(NS_IsMainThread());
2250 const bool reframe
= aNeedsReframe
== NeedsReframe::Yes
;
2251 // Send a notification that will be observed by PresShells in this process
2253 if (nsCOMPtr
<nsIObserverService
> obs
= services::GetObserverService()) {
2254 char16_t needsReframe
[] = {char16_t(reframe
), 0};
2255 obs
->NotifyObservers(nullptr, "font-info-updated", needsReframe
);
2257 if (XRE_IsParentProcess() &&
2258 aBroadcastToChildren
== BroadcastToChildren::Yes
) {
2259 // Propagate the change to child processes.
2260 for (auto* process
:
2261 dom::ContentParent::AllProcesses(dom::ContentParent::eLive
)) {
2262 Unused
<< process
->SendForceGlobalReflow(reframe
);
2267 void gfxPlatform::FontsPrefsChanged(const char* aPref
) {
2268 NS_ASSERTION(aPref
!= nullptr, "null preference");
2269 if (!strcmp(GFX_DOWNLOADABLE_FONTS_ENABLED
, aPref
)) {
2270 mAllowDownloadableFonts
= UNINITIALIZED_VALUE
;
2271 } else if (!strcmp(GFX_PREF_WORD_CACHE_CHARLIMIT
, aPref
) ||
2272 !strcmp(GFX_PREF_WORD_CACHE_MAXENTRIES
, aPref
) ||
2273 !strcmp(GFX_PREF_GRAPHITE_SHAPING
, aPref
)) {
2274 FlushFontAndWordCaches();
2276 #if defined(XP_DARWIN)
2277 !strcmp(GFX_PREF_CORETEXT_SHAPING
, aPref
) ||
2279 !strcmp("gfx.font_rendering.ahem_antialias_none", aPref
)) {
2280 FlushFontAndWordCaches();
2281 } else if (!strcmp(GFX_PREF_OPENTYPE_SVG
, aPref
)) {
2282 gfxFontCache::GetCache()->Flush();
2283 gfxFontCache::GetCache()->NotifyGlyphsChanged();
2287 mozilla::LogModule
* gfxPlatform::GetLog(eGfxLog aWhichLog
) {
2288 // logs shared across gfx
2289 static LazyLogModule
sFontlistLog("fontlist");
2290 static LazyLogModule
sFontInitLog("fontinit");
2291 static LazyLogModule
sTextrunLog("textrun");
2292 static LazyLogModule
sTextrunuiLog("textrunui");
2293 static LazyLogModule
sCmapDataLog("cmapdata");
2294 static LazyLogModule
sTextPerfLog("textperf");
2296 switch (aWhichLog
) {
2297 case eGfxLog_fontlist
:
2298 return sFontlistLog
;
2299 case eGfxLog_fontinit
:
2300 return sFontInitLog
;
2301 case eGfxLog_textrun
:
2303 case eGfxLog_textrunui
:
2304 return sTextrunuiLog
;
2305 case eGfxLog_cmapdata
:
2306 return sCmapDataLog
;
2307 case eGfxLog_textperf
:
2308 return sTextPerfLog
;
2311 MOZ_ASSERT_UNREACHABLE("Unexpected log type");
2315 RefPtr
<mozilla::gfx::DrawTarget
> gfxPlatform::ScreenReferenceDrawTarget() {
2316 MOZ_ASSERT_IF(XRE_IsContentProcess(), NS_IsMainThread());
2317 return (mScreenReferenceDrawTarget
)
2318 ? mScreenReferenceDrawTarget
2319 : gPlatform
->CreateOffscreenContentDrawTarget(
2320 IntSize(1, 1), SurfaceFormat::B8G8R8A8
, true);
2323 /* static */ RefPtr
<mozilla::gfx::DrawTarget
>
2324 gfxPlatform::ThreadLocalScreenReferenceDrawTarget() {
2325 if (NS_IsMainThread() && gPlatform
) {
2326 return gPlatform
->ScreenReferenceDrawTarget();
2329 gfxPlatformWorker
* platformWorker
= gfxPlatformWorker::Get();
2330 if (platformWorker
) {
2331 return platformWorker
->ScreenReferenceDrawTarget();
2334 return Factory::CreateDrawTarget(BackendType::SKIA
, IntSize(1, 1),
2335 SurfaceFormat::B8G8R8A8
);
2338 mozilla::gfx::SurfaceFormat
gfxPlatform::Optimal2DFormatForContent(
2339 gfxContentType aContent
) {
2341 case gfxContentType::COLOR
:
2342 switch (GetOffscreenFormat()) {
2343 case SurfaceFormat::A8R8G8B8_UINT32
:
2344 return mozilla::gfx::SurfaceFormat::B8G8R8A8
;
2345 case SurfaceFormat::X8R8G8B8_UINT32
:
2346 return mozilla::gfx::SurfaceFormat::B8G8R8X8
;
2347 case SurfaceFormat::R5G6B5_UINT16
:
2348 return mozilla::gfx::SurfaceFormat::R5G6B5_UINT16
;
2350 MOZ_ASSERT_UNREACHABLE(
2351 "unknown gfxImageFormat for "
2352 "gfxContentType::COLOR");
2353 return mozilla::gfx::SurfaceFormat::B8G8R8A8
;
2355 case gfxContentType::ALPHA
:
2356 return mozilla::gfx::SurfaceFormat::A8
;
2357 case gfxContentType::COLOR_ALPHA
:
2358 return mozilla::gfx::SurfaceFormat::B8G8R8A8
;
2360 MOZ_ASSERT_UNREACHABLE("unknown gfxContentType");
2361 return mozilla::gfx::SurfaceFormat::B8G8R8A8
;
2365 gfxImageFormat
gfxPlatform::OptimalFormatForContent(gfxContentType aContent
) {
2367 case gfxContentType::COLOR
:
2368 return GetOffscreenFormat();
2369 case gfxContentType::ALPHA
:
2370 return SurfaceFormat::A8
;
2371 case gfxContentType::COLOR_ALPHA
:
2372 return SurfaceFormat::A8R8G8B8_UINT32
;
2374 MOZ_ASSERT_UNREACHABLE("unknown gfxContentType");
2375 return SurfaceFormat::A8R8G8B8_UINT32
;
2380 * There are a number of layers acceleration (or layers in general) preferences
2381 * that should be consistent for the lifetime of the application (bug 840967).
2382 * As such, we will evaluate them all as soon as one of them is evaluated
2383 * and remember the values. Changing these preferences during the run will
2384 * not have any effect until we restart.
2386 static mozilla::Atomic
<bool> sLayersSupportsHardwareVideoDecoding(false);
2387 static bool sLayersHardwareVideoDecodingFailed
= false;
2389 static mozilla::Atomic
<bool> sLayersAccelerationPrefsInitialized(false);
2391 static void VideoDecodingFailedChangedCallback(const char* aPref
, void*) {
2392 sLayersHardwareVideoDecodingFailed
= Preferences::GetBool(aPref
, false);
2393 gfxPlatform::GetPlatform()->UpdateCanUseHardwareVideoDecoding();
2396 void gfxPlatform::UpdateCanUseHardwareVideoDecoding() {
2397 if (XRE_IsParentProcess()) {
2398 gfxVars::SetCanUseHardwareVideoDecoding(CanUseHardwareVideoDecoding());
2402 void gfxPlatform::UpdateForceSubpixelAAWherePossible() {
2403 bool forceSubpixelAAWherePossible
=
2404 StaticPrefs::gfx_webrender_quality_force_subpixel_aa_where_possible();
2405 gfxVars::SetForceSubpixelAAWherePossible(forceSubpixelAAWherePossible
);
2408 void gfxPlatform::InitAcceleration() {
2409 if (sLayersAccelerationPrefsInitialized
) {
2413 InitCompositorAccelerationPrefs();
2415 // If this is called for the first time on a non-main thread, we're screwed.
2416 // At the moment there's no explicit guarantee that the main thread calls
2417 // this before the compositor thread, but let's at least make the assumption
2419 MOZ_ASSERT(NS_IsMainThread(), "can only initialize prefs on the main thread");
2421 #ifndef MOZ_WIDGET_GTK
2422 nsCOMPtr
<nsIGfxInfo
> gfxInfo
= components::GfxInfo::Service();
2423 nsCString discardFailureId
;
2427 if (XRE_IsParentProcess()) {
2428 gfxVars::SetBrowserTabsRemoteAutostart(BrowserTabsRemoteAutostart());
2429 gfxVars::SetOffscreenFormat(GetOffscreenFormat());
2430 gfxVars::SetRequiresAcceleratedGLContextForCompositorOGL(
2431 RequiresAcceleratedGLContextForCompositorOGL());
2434 gfxInfo
->GetFeatureStatus(nsIGfxInfo::FEATURE_D3D11_KEYED_MUTEX
,
2435 discardFailureId
, &status
))) {
2436 gfxVars::SetAllowD3D11KeyedMutex(status
== nsIGfxInfo::FEATURE_STATUS_OK
);
2438 // If we couldn't properly evaluate the status, err on the side
2439 // of caution and give this functionality to the user.
2440 gfxCriticalNote
<< "Cannot evaluate keyed mutex feature status";
2441 gfxVars::SetAllowD3D11KeyedMutex(true);
2443 if (StaticPrefs::gfx_direct3d11_use_double_buffering()) {
2444 gfxVars::SetUseDoubleBufferingWithCompositor(true);
2449 if (StaticPrefs::media_hardware_video_decoding_enabled_AtStartup()) {
2450 #ifdef MOZ_WIDGET_GTK
2451 sLayersSupportsHardwareVideoDecoding
=
2452 gfxPlatformGtk::GetPlatform()->InitVAAPIConfig(
2454 media_hardware_video_decoding_force_enabled_AtStartup() ||
2455 StaticPrefs::media_ffmpeg_vaapi_enabled_AtStartup());
2459 Preferences::GetBool("media.wmf.dxva.enabled", true) &&
2461 NS_SUCCEEDED(gfxInfo
->GetFeatureStatus(
2462 nsIGfxInfo::FEATURE_HARDWARE_VIDEO_DECODING
, discardFailureId
,
2464 if (status
== nsIGfxInfo::FEATURE_STATUS_OK
||
2466 media_hardware_video_decoding_force_enabled_AtStartup()) {
2467 sLayersSupportsHardwareVideoDecoding
= true;
2471 } else if (XRE_IsParentProcess()) {
2472 FeatureState
& feature
=
2473 gfxConfig::GetFeature(Feature::HARDWARE_VIDEO_DECODING
);
2474 feature
.EnableByDefault();
2475 feature
.UserDisable("User disabled via pref",
2476 "FEATURE_HARDWARE_VIDEO_DECODING_PREF_DISABLED"_ns
);
2479 sLayersAccelerationPrefsInitialized
= true;
2481 if (XRE_IsParentProcess()) {
2482 Preferences::RegisterCallbackAndCall(
2483 VideoDecodingFailedChangedCallback
,
2484 "media.hardware-video-decoding.failed");
2485 InitGPUProcessPrefs();
2487 FeatureState
& feature
= gfxConfig::GetFeature(Feature::REMOTE_CANVAS
);
2488 feature
.SetDefault(StaticPrefs::gfx_canvas_remote_AtStartup(),
2489 FeatureStatus::Disabled
, "Disabled via pref");
2491 if (!gfxConfig::IsEnabled(Feature::GPU_PROCESS
) &&
2492 !StaticPrefs::gfx_canvas_remote_allow_in_parent_AtStartup()) {
2493 feature
.Disable(FeatureStatus::UnavailableNoGpuProcess
,
2494 "Disabled without GPU process",
2495 "FEATURE_REMOTE_CANVAS_NO_GPU_PROCESS"_ns
);
2499 // If D2D is explicitly disabled on Windows, then don't use remote canvas.
2500 // This prevents it from interfering with Accelerated Canvas2D.
2501 if (StaticPrefs::gfx_direct2d_disabled_AtStartup() &&
2502 !StaticPrefs::gfx_direct2d_force_enabled_AtStartup()) {
2503 gfxConfig::ForceDisable(Feature::REMOTE_CANVAS
, FeatureStatus::Blocked
,
2504 "Disabled without Direct2D",
2505 "FEATURE_REMOTE_CANVAS_NO_DIRECT2D"_ns
);
2508 gfxConfig::ForceDisable(Feature::REMOTE_CANVAS
, FeatureStatus::Blocked
,
2509 "Platform not supported",
2510 "FEATURE_REMOTE_CANVAS_NOT_WINDOWS"_ns
);
2513 gfxVars::SetRemoteCanvasEnabled(feature
.IsEnabled());
2517 void gfxPlatform::InitGPUProcessPrefs() {
2518 // We want to hide this from about:support, so only set a default if the
2519 // pref is known to be true.
2520 if (!StaticPrefs::layers_gpu_process_enabled_AtStartup() &&
2521 !StaticPrefs::layers_gpu_process_force_enabled_AtStartup()) {
2525 FeatureState
& gpuProc
= gfxConfig::GetFeature(Feature::GPU_PROCESS
);
2527 // We require E10S - otherwise, there is very little benefit to the GPU
2528 // process, since the UI process must still use acceleration for
2530 if (!BrowserTabsRemoteAutostart()) {
2531 gpuProc
.DisableByDefault(FeatureStatus::Unavailable
,
2532 "Multi-process mode is not enabled",
2533 "FEATURE_FAILURE_NO_E10S"_ns
);
2535 gpuProc
.SetDefaultFromPref(
2536 StaticPrefs::GetPrefName_layers_gpu_process_enabled(), true,
2537 StaticPrefs::GetPrefDefault_layers_gpu_process_enabled());
2540 if (StaticPrefs::layers_gpu_process_force_enabled_AtStartup()) {
2541 gpuProc
.UserForceEnable("User force-enabled via pref");
2545 nsCString failureId
;
2546 if (!gfxPlatform::IsGfxInfoStatusOkay(nsIGfxInfo::FEATURE_GPU_PROCESS
,
2547 &message
, failureId
)) {
2548 gpuProc
.Disable(FeatureStatus::Blocklisted
, message
.get(), failureId
);
2553 gpuProc
.ForceDisable(FeatureStatus::Blocked
, "Headless mode is enabled",
2554 "FEATURE_FAILURE_HEADLESS_MODE"_ns
);
2558 InitPlatformGPUProcessPrefs();
2561 void gfxPlatform::InitCompositorAccelerationPrefs() {
2562 const char* acceleratedEnv
= PR_GetEnv("MOZ_ACCELERATED");
2564 FeatureState
& feature
= gfxConfig::GetFeature(Feature::HW_COMPOSITING
);
2566 // Base value - does the platform allow acceleration?
2567 if (feature
.SetDefault(AccelerateLayersByDefault(), FeatureStatus::Blocked
,
2568 "Acceleration blocked by platform")) {
2570 layers_acceleration_disabled_AtStartup_DoNotUseDirectly()) {
2571 feature
.UserDisable("Disabled by layers.acceleration.disabled=true",
2572 "FEATURE_FAILURE_COMP_PREF"_ns
);
2573 } else if (acceleratedEnv
&& *acceleratedEnv
== '0') {
2574 feature
.UserDisable("Disabled by envvar", "FEATURE_FAILURE_COMP_ENV"_ns
);
2577 if (acceleratedEnv
&& *acceleratedEnv
== '1') {
2578 feature
.UserEnable("Enabled by envvar");
2582 // This has specific meaning elsewhere, so we always record it.
2584 layers_acceleration_force_enabled_AtStartup_DoNotUseDirectly()) {
2585 feature
.UserForceEnable("Force-enabled by pref");
2588 // Safe, headless, and record/replay modes override everything.
2590 feature
.ForceDisable(FeatureStatus::Blocked
,
2591 "Acceleration blocked by safe-mode",
2592 "FEATURE_FAILURE_COMP_SAFEMODE"_ns
);
2595 feature
.ForceDisable(FeatureStatus::Blocked
,
2596 "Acceleration blocked by headless mode",
2597 "FEATURE_FAILURE_COMP_HEADLESSMODE"_ns
);
2602 bool gfxPlatform::WebRenderPrefEnabled() {
2603 return StaticPrefs::gfx_webrender_all_AtStartup();
2607 bool gfxPlatform::WebRenderEnvvarEnabled() {
2608 const char* env
= PR_GetEnv("MOZ_WEBRENDER");
2609 return (env
&& *env
== '1');
2612 /* static */ const char* gfxPlatform::WebRenderResourcePathOverride() {
2613 const char* resourcePath
= PR_GetEnv("WR_RESOURCE_PATH");
2614 if (!resourcePath
|| resourcePath
[0] == '\0') {
2617 return resourcePath
;
2620 void gfxPlatform::InitWebRenderConfig() {
2621 bool prefEnabled
= WebRenderPrefEnabled();
2622 bool envvarEnabled
= WebRenderEnvvarEnabled();
2624 // WR? WR+ => means WR was enabled on qualified hardware
2625 // WR! WR+ => means WR was enabled via gfx.webrender.{all,enabled} or
2626 // envvar, possibly on unqualified hardware
2627 // In all cases WR- means WR was not enabled, for one of many possible
2628 // reasons. Prior to bug 1523788 landing the gfx.webrender.{all,enabled}
2629 // prefs only worked on Nightly so keep that in mind when looking at older
2631 ScopedGfxFeatureReporter
reporter("WR", prefEnabled
|| envvarEnabled
);
2632 if (!XRE_IsParentProcess()) {
2633 // The parent process runs through all the real decision-making code
2634 // later in this function. For other processes we still want to report
2635 // the state of the feature for crash reports.
2636 reporter
.SetSuccessful();
2640 // Update the gfxConfig feature states.
2641 gfxConfigManager manager
;
2643 manager
.ConfigureWebRender();
2645 if (gfxConfig::IsEnabled(Feature::GPU_PROCESS
)) {
2646 gfxVars::SetGPUProcessEnabled(true);
2649 bool hasHardware
= gfxConfig::IsEnabled(Feature::WEBRENDER
);
2651 #ifdef MOZ_WIDGET_GTK
2652 // We require a hardware driver to back the GL context unless the user forced
2654 if (!gfxConfig::IsForcedOnByUser(Feature::WEBRENDER
) &&
2655 StaticPrefs::gfx_webrender_reject_software_driver_AtStartup()) {
2656 gfxVars::SetWebRenderRequiresHardwareDriver(true);
2661 if (gfxConfig::IsEnabled(Feature::WEBRENDER_ANGLE
)) {
2662 gfxVars::SetUseWebRenderANGLE(true);
2666 if (gfxConfig::IsEnabled(Feature::WEBRENDER_SHADER_CACHE
)) {
2667 gfxVars::SetUseWebRenderProgramBinaryDisk(true);
2670 gfxVars::SetUseWebRenderOptimizedShaders(
2671 gfxConfig::IsEnabled(Feature::WEBRENDER_OPTIMIZED_SHADERS
));
2673 gfxVars::SetUseSoftwareWebRender(!hasHardware
);
2675 Preferences::RegisterPrefixCallbackAndCall(SwapIntervalPrefChangeCallback
,
2676 "gfx.swap-interval");
2678 reporter
.SetSuccessful();
2680 Preferences::RegisterPrefixCallbackAndCall(WebRenderDebugPrefChangeCallback
,
2683 RegisterWebRenderBoolParamCallback();
2685 Preferences::RegisterPrefixCallbackAndCall(
2686 WebRendeProfilerUIPrefChangeCallback
, "gfx.webrender.debug.profiler-ui");
2687 Preferences::RegisterCallback(
2688 WebRenderQualityPrefChangeCallback
,
2691 GetPrefName_gfx_webrender_quality_force_subpixel_aa_where_possible()));
2693 Preferences::RegisterCallback(
2694 WebRenderBatchingPrefChangeCallback
,
2696 StaticPrefs::GetPrefName_gfx_webrender_batching_lookback()));
2698 Preferences::RegisterCallbackAndCall(
2699 WebRenderBlobTileSizePrefChangeCallback
,
2701 StaticPrefs::GetPrefName_gfx_webrender_blob_tile_size()));
2703 Preferences::RegisterCallbackAndCall(
2704 WebRenderUploadThresholdPrefChangeCallback
,
2706 StaticPrefs::GetPrefName_gfx_webrender_batched_upload_threshold()));
2708 if (WebRenderResourcePathOverride()) {
2709 CrashReporter::RecordAnnotationBool(
2710 CrashReporter::Annotation::IsWebRenderResourcePathOverridden
, true);
2713 UpdateForceSubpixelAAWherePossible();
2715 #if defined(MOZ_WIDGET_ANDROID) || defined(MOZ_WIDGET_GTK)
2716 if (StaticPrefs::gfx_webrender_software_opengl_AtStartup()) {
2717 gfxVars::SetAllowSoftwareWebRenderOGL(true);
2722 if (gfxConfig::IsEnabled(Feature::WEBRENDER_DCOMP_PRESENT
)) {
2723 gfxVars::SetUseWebRenderDCompWin(true);
2725 if (StaticPrefs::gfx_webrender_software_d3d11_AtStartup()) {
2726 gfxVars::SetAllowSoftwareWebRenderD3D11(true);
2729 const bool overlaySupported
=
2730 IsWin10AnniversaryUpdateOrLater() &&
2731 gfxConfig::IsEnabled(Feature::WEBRENDER_COMPOSITOR
);
2732 MOZ_ASSERT_IF(overlaySupported
,
2733 gfxConfig::IsEnabled(Feature::WEBRENDER_DCOMP_PRESENT
));
2735 bool useVideoHwOverlay
= false;
2736 if (StaticPrefs::gfx_webrender_dcomp_video_hw_overlay_win_AtStartup()) {
2737 if (overlaySupported
) {
2738 useVideoHwOverlay
= true;
2741 if (useVideoHwOverlay
&&
2743 gfx_webrender_dcomp_video_hw_overlay_win_force_enabled_AtStartup()) {
2744 nsCString failureId
;
2746 const nsCOMPtr
<nsIGfxInfo
> gfxInfo
= components::GfxInfo::Service();
2747 if (NS_FAILED(gfxInfo
->GetFeatureStatus(nsIGfxInfo::FEATURE_VIDEO_OVERLAY
,
2748 failureId
, &status
))) {
2749 FeatureState
& feature
=
2750 gfxConfig::GetFeature(Feature::VIDEO_HARDWARE_OVERLAY
);
2751 feature
.DisableByDefault(FeatureStatus::BlockedNoGfxInfo
,
2752 "gfxInfo is broken",
2753 "FEATURE_FAILURE_WR_NO_GFX_INFO"_ns
);
2754 useVideoHwOverlay
= false;
2756 if (status
!= nsIGfxInfo::FEATURE_STATUS_OK
) {
2757 FeatureState
& feature
=
2758 gfxConfig::GetFeature(Feature::VIDEO_HARDWARE_OVERLAY
);
2759 feature
.DisableByDefault(FeatureStatus::Blocked
,
2760 "Blocklisted by gfxInfo", failureId
);
2761 useVideoHwOverlay
= false;
2765 } else if (overlaySupported
) {
2766 FeatureState
& feature
=
2767 gfxConfig::GetFeature(Feature::VIDEO_HARDWARE_OVERLAY
);
2768 feature
.DisableByDefault(FeatureStatus::Blocked
, "Disabled by pref",
2769 "FEATURE_FAILURE_DISABLED_BY_PREF"_ns
);
2772 if (useVideoHwOverlay
) {
2773 FeatureState
& feature
=
2774 gfxConfig::GetFeature(Feature::VIDEO_HARDWARE_OVERLAY
);
2775 feature
.EnableByDefault();
2776 gfxVars::SetUseWebRenderDCompVideoHwOverlayWin(true);
2779 bool useVideoSwOverlay
= false;
2780 if (overlaySupported
&&
2781 StaticPrefs::gfx_webrender_dcomp_video_sw_overlay_win_AtStartup()) {
2782 useVideoSwOverlay
= true;
2784 if (useVideoSwOverlay
&&
2786 gfx_webrender_dcomp_video_sw_overlay_win_force_enabled_AtStartup()) {
2787 nsCString failureId
;
2789 const nsCOMPtr
<nsIGfxInfo
> gfxInfo
= components::GfxInfo::Service();
2790 if (NS_FAILED(gfxInfo
->GetFeatureStatus(
2791 nsIGfxInfo::FEATURE_VIDEO_SOFTWARE_OVERLAY
, failureId
,
2793 FeatureState
& feature
=
2794 gfxConfig::GetFeature(Feature::VIDEO_SOFTWARE_OVERLAY
);
2795 feature
.DisableByDefault(FeatureStatus::BlockedNoGfxInfo
,
2796 "gfxInfo is broken",
2797 "FEATURE_FAILURE_WR_NO_GFX_INFO"_ns
);
2798 useVideoSwOverlay
= false;
2800 if (status
!= nsIGfxInfo::FEATURE_STATUS_OK
) {
2801 FeatureState
& feature
=
2802 gfxConfig::GetFeature(Feature::VIDEO_SOFTWARE_OVERLAY
);
2803 feature
.DisableByDefault(FeatureStatus::Blocked
,
2804 "Blocklisted by gfxInfo", failureId
);
2805 useVideoSwOverlay
= false;
2809 } else if (overlaySupported
) {
2810 FeatureState
& feature
=
2811 gfxConfig::GetFeature(Feature::VIDEO_SOFTWARE_OVERLAY
);
2812 feature
.DisableByDefault(FeatureStatus::Blocked
, "Disabled by pref",
2813 "FEATURE_FAILURE_DISABLED_BY_PREF"_ns
);
2816 if (useVideoSwOverlay
) {
2817 FeatureState
& feature
=
2818 gfxConfig::GetFeature(Feature::VIDEO_SOFTWARE_OVERLAY
);
2819 feature
.EnableByDefault();
2820 gfxVars::SetUseWebRenderDCompVideoSwOverlayWin(true);
2823 bool useHwVideoZeroCopy
= false;
2824 if (StaticPrefs::media_wmf_zero_copy_nv12_textures_AtStartup()) {
2826 useHwVideoZeroCopy
= true;
2829 if (useHwVideoZeroCopy
&&
2831 media_wmf_zero_copy_nv12_textures_force_enabled_AtStartup()) {
2832 nsCString failureId
;
2834 const nsCOMPtr
<nsIGfxInfo
> gfxInfo
= components::GfxInfo::Service();
2835 if (NS_FAILED(gfxInfo
->GetFeatureStatus(
2836 nsIGfxInfo::FEATURE_HW_DECODED_VIDEO_ZERO_COPY
, failureId
,
2838 FeatureState
& feature
=
2839 gfxConfig::GetFeature(Feature::HW_DECODED_VIDEO_ZERO_COPY
);
2840 feature
.DisableByDefault(FeatureStatus::BlockedNoGfxInfo
,
2841 "gfxInfo is broken",
2842 "FEATURE_FAILURE_WR_NO_GFX_INFO"_ns
);
2843 useHwVideoZeroCopy
= false;
2845 if (status
!= nsIGfxInfo::FEATURE_ALLOW_ALWAYS
) {
2846 FeatureState
& feature
=
2847 gfxConfig::GetFeature(Feature::HW_DECODED_VIDEO_ZERO_COPY
);
2848 feature
.DisableByDefault(FeatureStatus::Blocked
,
2849 "Blocklisted by gfxInfo", failureId
);
2850 useHwVideoZeroCopy
= false;
2856 if (useHwVideoZeroCopy
) {
2857 FeatureState
& feature
=
2858 gfxConfig::GetFeature(Feature::HW_DECODED_VIDEO_ZERO_COPY
);
2859 feature
.EnableByDefault();
2860 gfxVars::SetHwDecodedVideoZeroCopy(true);
2863 bool reuseDecoderDevice
= false;
2864 if (StaticPrefs::gfx_direct3d11_reuse_decoder_device_AtStartup()) {
2865 reuseDecoderDevice
= true;
2867 if (reuseDecoderDevice
&&
2869 gfx_direct3d11_reuse_decoder_device_force_enabled_AtStartup()) {
2870 nsCString failureId
;
2872 const nsCOMPtr
<nsIGfxInfo
> gfxInfo
= components::GfxInfo::Service();
2873 if (NS_FAILED(gfxInfo
->GetFeatureStatus(
2874 nsIGfxInfo::FEATURE_REUSE_DECODER_DEVICE
, failureId
, &status
))) {
2875 FeatureState
& feature
=
2876 gfxConfig::GetFeature(Feature::REUSE_DECODER_DEVICE
);
2877 feature
.DisableByDefault(FeatureStatus::BlockedNoGfxInfo
,
2878 "gfxInfo is broken",
2879 "FEATURE_FAILURE_WR_NO_GFX_INFO"_ns
);
2880 reuseDecoderDevice
= false;
2882 if (status
!= nsIGfxInfo::FEATURE_STATUS_OK
) {
2883 FeatureState
& feature
=
2884 gfxConfig::GetFeature(Feature::REUSE_DECODER_DEVICE
);
2885 feature
.DisableByDefault(FeatureStatus::Blocked
,
2886 "Blocklisted by gfxInfo", failureId
);
2887 reuseDecoderDevice
= false;
2893 if (reuseDecoderDevice
) {
2894 FeatureState
& feature
=
2895 gfxConfig::GetFeature(Feature::REUSE_DECODER_DEVICE
);
2896 feature
.EnableByDefault();
2897 gfxVars::SetReuseDecoderDevice(true);
2900 if (Preferences::GetBool("gfx.webrender.flip-sequential", false)) {
2901 if (gfxVars::UseWebRenderANGLE()) {
2902 gfxVars::SetUseWebRenderFlipSequentialWin(true);
2905 if (Preferences::GetBool("gfx.webrender.triple-buffering.enabled", false)) {
2906 if (gfxVars::UseWebRenderDCompWin() ||
2907 gfxVars::UseWebRenderFlipSequentialWin()) {
2908 gfxVars::SetUseWebRenderTripleBufferingWin(true);
2913 bool allowOverlayVpAutoHDR
= false;
2914 if (StaticPrefs::gfx_webrender_overlay_vp_auto_hdr_AtStartup()) {
2915 allowOverlayVpAutoHDR
= true;
2917 nsCString failureId
;
2919 const nsCOMPtr
<nsIGfxInfo
> gfxInfo
= components::GfxInfo::Service();
2920 if (NS_FAILED(gfxInfo
->GetFeatureStatus(
2921 nsIGfxInfo::FEATURE_OVERLAY_VP_AUTO_HDR
, failureId
, &status
))) {
2922 allowOverlayVpAutoHDR
= false;
2924 if (status
!= nsIGfxInfo::FEATURE_STATUS_OK
) {
2925 allowOverlayVpAutoHDR
= false;
2930 if (allowOverlayVpAutoHDR
) {
2931 gfxVars::SetWebRenderOverlayVpAutoHDR(true);
2934 bool allowOverlayVpSuperResolution
= false;
2935 if (StaticPrefs::gfx_webrender_overlay_vp_super_resolution_AtStartup()) {
2936 allowOverlayVpSuperResolution
= true;
2938 nsCString failureId
;
2940 const nsCOMPtr
<nsIGfxInfo
> gfxInfo
= components::GfxInfo::Service();
2941 if (NS_FAILED(gfxInfo
->GetFeatureStatus(
2942 nsIGfxInfo::FEATURE_OVERLAY_VP_SUPER_RESOLUTION
, failureId
,
2944 allowOverlayVpSuperResolution
= false;
2946 if (status
!= nsIGfxInfo::FEATURE_STATUS_OK
) {
2947 allowOverlayVpSuperResolution
= false;
2952 if (allowOverlayVpSuperResolution
) {
2953 gfxVars::SetWebRenderOverlayVpSuperResolution(true);
2956 if (gfxConfig::IsEnabled(Feature::WEBRENDER_COMPOSITOR
)) {
2957 gfxVars::SetUseWebRenderCompositor(true);
2960 glean::gfx::os_compositor
.Set(
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);
3120 #ifdef MOZ_WIDGET_GTK
3122 FeatureState
& feature
=
3123 gfxConfig::GetFeature(Feature::DMABUF_SURFACE_EXPORT
);
3124 feature
.EnableByDefault();
3125 nsCString discardFailureId
;
3128 gfxInfo
->GetFeatureStatus(nsIGfxInfo::FEATURE_DMABUF_SURFACE_EXPORT
,
3129 discardFailureId
, &status
)) ||
3130 status
!= nsIGfxInfo::FEATURE_STATUS_OK
) {
3131 feature
.Disable(FeatureStatus::Blocked
, "Blocklisted by gfxInfo",
3134 gfxVars::SetUseDMABufSurfaceExport(feature
.IsEnabled());
3138 FeatureState
& feature
= gfxConfig::GetFeature(Feature::DMABUF_WEBGL
);
3139 feature
.EnableByDefault();
3140 if (!StaticPrefs::widget_dmabuf_webgl_enabled_AtStartup()) {
3141 feature
.UserDisable("Disabled by pref",
3142 "FEATURE_FAILURE_DISABLED_BY_PREF"_ns
);
3144 nsCString discardFailureId
;
3146 if (NS_FAILED(gfxInfo
->GetFeatureStatus(nsIGfxInfo::FEATURE_DMABUF_WEBGL
,
3147 discardFailureId
, &status
)) ||
3148 status
!= nsIGfxInfo::FEATURE_STATUS_OK
) {
3149 feature
.Disable(FeatureStatus::Blocked
, "Blocklisted by gfxInfo",
3152 gfxVars::SetUseDMABufWebGL(feature
.IsEnabled());
3157 void gfxPlatform::InitWebGPUConfig() {
3158 if (!XRE_IsParentProcess()) {
3162 FeatureState
& feature
= gfxConfig::GetFeature(Feature::WEBGPU
);
3163 feature
.EnableByDefault();
3166 nsCString failureId
;
3167 if (!IsGfxInfoStatusOkay(nsIGfxInfo::FEATURE_WEBGPU
, &message
, failureId
)) {
3168 if (StaticPrefs::gfx_webgpu_ignore_blocklist_AtStartup()) {
3169 feature
.UserForceEnable(
3170 "Ignoring blocklist entry because gfx.webgpu.ignore-blocklist is "
3174 feature
.Disable(FeatureStatus::Blocklisted
, message
.get(), failureId
);
3177 #ifdef RELEASE_OR_BETA
3178 feature
.ForceDisable(FeatureStatus::Blocked
,
3179 "WebGPU cannot be enabled in release or beta",
3180 "WEBGPU_DISABLE_RELEASE_OR_BETA"_ns
);
3183 gfxVars::SetAllowWebGPU(feature
.IsEnabled());
3185 if (StaticPrefs::dom_webgpu_allow_present_without_readback()
3187 && IsWin10CreatorsUpdateOrLater()
3190 gfxVars::SetAllowWebGPUPresentWithoutReadback(true);
3195 static void WindowOcclusionPrefChangeCallback(const char* aPref
, void*) {
3196 const char* env
= PR_GetEnv("MOZ_WINDOW_OCCLUSION");
3198 // env has a higher priority than pref.
3202 FeatureState
& feature
= gfxConfig::GetFeature(Feature::WINDOW_OCCLUSION
);
3204 StaticPrefs::widget_windows_window_occlusion_tracking_enabled();
3206 printf_stderr("Dynamically enable window occlusion %d\n", enabled
);
3208 // Update feature before calling WinUtils::EnableWindowOcclusion()
3210 feature
.UserEnable("User enabled by pref");
3212 feature
.UserDisable("User disabled via pref",
3213 "FEATURE_FAILURE_PREF_DISABLED"_ns
);
3215 widget::WinUtils::EnableWindowOcclusion(enabled
);
3219 void gfxPlatform::InitWindowOcclusionConfig() {
3220 if (!XRE_IsParentProcess()) {
3224 FeatureState
& feature
= gfxConfig::GetFeature(Feature::WINDOW_OCCLUSION
);
3225 feature
.SetDefaultFromPref(
3227 GetPrefName_widget_windows_window_occlusion_tracking_enabled(),
3230 GetPrefDefault_widget_windows_window_occlusion_tracking_enabled());
3232 const char* env
= PR_GetEnv("MOZ_WINDOW_OCCLUSION");
3235 feature
.UserForceEnable("Force enabled by envvar");
3237 feature
.UserDisable("Force disabled by envvar",
3238 "FEATURE_FAILURE_OCCL_ENV"_ns
);
3242 Preferences::RegisterCallback(
3243 WindowOcclusionPrefChangeCallback
,
3246 GetPrefName_widget_windows_window_occlusion_tracking_enabled()));
3250 static void BackdropFilterPrefChangeCallback(const char*, void*) {
3251 FeatureState
& feature
= gfxConfig::GetFeature(Feature::BACKDROP_FILTER
);
3253 // We need to reset because the user status needs to be set before the
3254 // environment status, but the environment status comes from the blocklist,
3255 // and the user status can be updated after the fact.
3257 feature
.EnableByDefault();
3259 if (StaticPrefs::layout_css_backdrop_filter_force_enabled()) {
3260 feature
.UserForceEnable("Force enabled by pref");
3264 nsCString failureId
;
3265 if (!gfxPlatform::IsGfxInfoStatusOkay(nsIGfxInfo::FEATURE_BACKDROP_FILTER
,
3266 &message
, failureId
)) {
3267 feature
.Disable(FeatureStatus::Blocklisted
, message
.get(), failureId
);
3270 // This may still be gated by the layout.css.backdrop-filter.enabled pref but
3271 // the test infrastructure is very sensitive to how changes to that pref
3272 // propagate, so we don't include them in the gfxVars/gfxFeature.
3273 gfxVars::SetAllowBackdropFilter(feature
.IsEnabled());
3276 void gfxPlatform::InitBackdropFilterConfig() {
3277 // This would ideally be in the nsCSSProps code
3278 // but nsCSSProps is initialized before gfxPlatform
3279 // so it has to be done here.
3280 gfxVars::AddReceiver(&nsCSSProps::GfxVarReceiver());
3282 if (!XRE_IsParentProcess()) {
3283 // gfxVars doesn't notify receivers when initialized on content processes
3284 // we need to explicitly recompute backdrop-filter's enabled state here.
3285 nsCSSProps::RecomputeEnabledState(
3286 StaticPrefs::GetPrefName_layout_css_backdrop_filter_enabled());
3290 BackdropFilterPrefChangeCallback(nullptr, nullptr);
3292 Preferences::RegisterCallback(
3293 BackdropFilterPrefChangeCallback
,
3295 StaticPrefs::GetPrefName_layout_css_backdrop_filter_force_enabled()));
3298 static void AcceleratedCanvas2DPrefChangeCallback(const char*, void*) {
3299 FeatureState
& feature
= gfxConfig::GetFeature(Feature::ACCELERATED_CANVAS2D
);
3301 // Reset to track toggling prefs and ensure force-enable does not happen
3305 // gfx.canvas.accelerated pref controls whether platform enables the feature,
3306 // but it still allows blocklisting to override it later.
3307 feature
.SetDefaultFromPref(
3308 StaticPrefs::GetPrefName_gfx_canvas_accelerated(), true,
3309 StaticPrefs::GetPrefDefault_gfx_canvas_accelerated());
3311 // gfx.canvas.accelerated.force-enabled overrides the blocklist.
3312 if (StaticPrefs::gfx_canvas_accelerated_force_enabled()) {
3313 feature
.UserForceEnable("Force-enabled by pref");
3316 if (kIsAndroid
&& !gfxConfig::IsEnabled(Feature::GPU_PROCESS
)) {
3317 feature
.Disable(FeatureStatus::Blocked
, "Disabled by GPU Process disabled",
3318 "FEATURE_FAILURE_DISABLED_BY_GPU_PROCESS_DISABLED"_ns
);
3319 } else if (!gfxConfig::IsEnabled(Feature::WEBRENDER
)) {
3320 // There isn't much benefit to accelerating Canvas2D if we can't accelerate
3321 // WebRender itself.
3322 feature
.Disable(FeatureStatus::Blocked
, "Disabled by Software WebRender",
3323 "FEATURE_FAILURE_DISABLED_BY_SOFTWARE_WEBRENDER"_ns
);
3326 // Check if blocklisted despite the default pref.
3328 nsCString failureId
;
3329 if (!gfxPlatform::IsGfxInfoStatusOkay(
3330 nsIGfxInfo::FEATURE_ACCELERATED_CANVAS2D
, &message
, failureId
)) {
3331 feature
.Disable(FeatureStatus::Blocklisted
, message
.get(), failureId
);
3334 if (gfxVars::RemoteCanvasEnabled()) {
3335 feature
.ForceDisable(FeatureStatus::Failed
, "Disabled by Remote Canvas",
3336 "FEATURE_FAILURE_DISABLED_BY_REMOTE_CANVAS"_ns
);
3339 gfxVars::SetUseAcceleratedCanvas2D(feature
.IsEnabled());
3342 void gfxPlatform::InitAcceleratedCanvas2DConfig() {
3343 if (!XRE_IsParentProcess()) {
3347 // Decide during pref changes whether or not to enable acceleration. This
3348 // allows easily toggling acceleration on and off to test performance.
3349 AcceleratedCanvas2DPrefChangeCallback(nullptr, nullptr);
3351 Preferences::RegisterCallback(
3352 AcceleratedCanvas2DPrefChangeCallback
,
3353 nsDependentCString(StaticPrefs::GetPrefName_gfx_canvas_accelerated()));
3354 Preferences::RegisterCallback(
3355 AcceleratedCanvas2DPrefChangeCallback
,
3357 StaticPrefs::GetPrefName_gfx_canvas_accelerated_force_enabled()));
3360 bool gfxPlatform::CanUseHardwareVideoDecoding() {
3361 // this function is called from the compositor thread, so it is not
3362 // safe to init the prefs etc. from here.
3363 MOZ_ASSERT(sLayersAccelerationPrefsInitialized
);
3364 return sLayersSupportsHardwareVideoDecoding
&&
3365 !sLayersHardwareVideoDecodingFailed
;
3368 bool gfxPlatform::AccelerateLayersByDefault() {
3369 #if defined(MOZ_GL_PROVIDER) || defined(MOZ_WIDGET_UIKIT)
3377 bool gfxPlatform::UsesOffMainThreadCompositing() {
3378 if (XRE_GetProcessType() == GeckoProcessType_GPU
) {
3382 static bool firstTime
= true;
3383 static bool result
= false;
3386 MOZ_ASSERT(sLayersAccelerationPrefsInitialized
);
3387 result
= gfxVars::BrowserTabsRemoteAutostart() ||
3389 layers_offmainthreadcomposition_force_disabled_AtStartup();
3390 #if defined(MOZ_WIDGET_GTK)
3391 // Linux users who chose OpenGL are being included in OMTC
3392 result
|= StaticPrefs::
3393 layers_acceleration_force_enabled_AtStartup_DoNotUseDirectly();
3402 RefPtr
<mozilla::VsyncDispatcher
> gfxPlatform::GetGlobalVsyncDispatcher() {
3403 MOZ_ASSERT(mVsyncDispatcher
,
3404 "mVsyncDispatcher should have been initialized by ReInitFrameRate "
3405 "during gfxPlatform init");
3406 MOZ_ASSERT(XRE_IsParentProcess());
3407 return mVsyncDispatcher
;
3410 already_AddRefed
<mozilla::gfx::VsyncSource
>
3411 gfxPlatform::GetGlobalHardwareVsyncSource() {
3412 if (!mGlobalHardwareVsyncSource
) {
3413 mGlobalHardwareVsyncSource
= CreateGlobalHardwareVsyncSource();
3415 return do_AddRef(mGlobalHardwareVsyncSource
);
3419 * The preference "layout.frame_rate" has 3 meanings depending on the value:
3421 * -1 = Auto (default), use hardware vsync or software vsync @ 60 hz if hw
3423 * 0 = ASAP mode - used during talos testing.
3424 * X = Software vsync at a rate of X times per second.
3426 already_AddRefed
<mozilla::gfx::VsyncSource
>
3427 gfxPlatform::GetSoftwareVsyncSource() {
3428 if (!mSoftwareVsyncSource
) {
3429 double rateInMS
= 1000.0 / (double)gfxPlatform::GetSoftwareVsyncRate();
3430 mSoftwareVsyncSource
= new mozilla::gfx::SoftwareVsyncSource(
3431 TimeDuration::FromMilliseconds(rateInMS
));
3433 return do_AddRef(mSoftwareVsyncSource
);
3437 bool gfxPlatform::IsInLayoutAsapMode() {
3438 // There are 2 modes of ASAP mode.
3439 // 1 is that the refresh driver and compositor are in lock step
3440 // the second is that the compositor goes ASAP and the refresh driver
3441 // goes at whatever the configurated rate is. This only checks the version
3442 // talos uses, which is the refresh driver and compositor are in lockstep.
3443 // Ignore privacy_resistFingerprinting to preserve ASAP mode there.
3444 return StaticPrefs::layout_frame_rate() == 0;
3447 static int LayoutFrameRateFromPrefs() {
3448 auto val
= StaticPrefs::layout_frame_rate();
3449 if (nsContentUtils::ShouldResistFingerprinting(
3450 "The frame rate is a global property.", RFPTarget::FrameRate
)) {
3457 bool gfxPlatform::ForceSoftwareVsync() {
3458 return LayoutFrameRateFromPrefs() > 0;
3462 int gfxPlatform::GetSoftwareVsyncRate() {
3463 int preferenceRate
= LayoutFrameRateFromPrefs();
3464 if (preferenceRate
<= 0) {
3465 return gfxPlatform::GetDefaultFrameRate();
3467 return preferenceRate
;
3471 int gfxPlatform::GetDefaultFrameRate() { return 60; }
3474 void gfxPlatform::ReInitFrameRate(const char* aPrefIgnored
,
3475 void* aDataIgnored
) {
3476 MOZ_RELEASE_ASSERT(XRE_IsParentProcess());
3478 if (gPlatform
->mSoftwareVsyncSource
) {
3479 // Update the rate of the existing software vsync source.
3480 double rateInMS
= 1000.0 / (double)gfxPlatform::GetSoftwareVsyncRate();
3481 gPlatform
->mSoftwareVsyncSource
->SetVsyncRate(
3482 TimeDuration::FromMilliseconds(rateInMS
));
3485 // Swap out the dispatcher's underlying source.
3486 RefPtr
<VsyncSource
> vsyncSource
=
3487 gfxPlatform::ForceSoftwareVsync()
3488 ? gPlatform
->GetSoftwareVsyncSource()
3489 : gPlatform
->GetGlobalHardwareVsyncSource();
3490 gPlatform
->mVsyncDispatcher
->SetVsyncSource(vsyncSource
);
3493 const char* gfxPlatform::GetAzureCanvasBackend() const {
3494 BackendType backend
{};
3496 if (gfxConfig::IsEnabled(Feature::GPU_PROCESS
)) {
3497 // Assume content process' backend prefs.
3498 BackendPrefsData data
= GetBackendPrefs();
3499 backend
= GetCanvasBackendPref(data
.mCanvasBitmask
);
3500 if (backend
== BackendType::NONE
) {
3501 backend
= data
.mCanvasDefault
;
3504 backend
= mPreferredCanvasBackend
;
3507 return GetBackendName(backend
);
3510 const char* gfxPlatform::GetAzureContentBackend() const {
3511 BackendType backend
{};
3513 if (gfxConfig::IsEnabled(Feature::GPU_PROCESS
)) {
3514 // Assume content process' backend prefs.
3515 BackendPrefsData data
= GetBackendPrefs();
3516 backend
= GetContentBackendPref(data
.mContentBitmask
);
3517 if (backend
== BackendType::NONE
) {
3518 backend
= data
.mContentDefault
;
3521 backend
= mContentBackend
;
3524 return GetBackendName(backend
);
3527 void gfxPlatform::GetAzureBackendInfo(mozilla::widget::InfoObject
& aObj
) {
3528 if (gfxConfig::IsEnabled(Feature::GPU_PROCESS
)) {
3529 aObj
.DefineProperty("AzureCanvasBackend (UI Process)",
3530 GetBackendName(mPreferredCanvasBackend
));
3531 aObj
.DefineProperty("AzureFallbackCanvasBackend (UI Process)",
3532 GetBackendName(mFallbackCanvasBackend
));
3533 aObj
.DefineProperty("AzureContentBackend (UI Process)",
3534 GetBackendName(mContentBackend
));
3536 aObj
.DefineProperty("AzureFallbackCanvasBackend",
3537 GetBackendName(mFallbackCanvasBackend
));
3540 aObj
.DefineProperty("AzureCanvasBackend", GetAzureCanvasBackend());
3541 aObj
.DefineProperty("AzureContentBackend", GetAzureContentBackend());
3544 void gfxPlatform::GetApzSupportInfo(mozilla::widget::InfoObject
& aObj
) {
3545 if (!gfxPlatform::AsyncPanZoomEnabled()) {
3549 if (SupportsApzWheelInput()) {
3550 aObj
.DefineProperty("ApzWheelInput", 1);
3553 if (SupportsApzTouchInput()) {
3554 aObj
.DefineProperty("ApzTouchInput", 1);
3557 if (SupportsApzDragInput()) {
3558 aObj
.DefineProperty("ApzDragInput", 1);
3561 if (SupportsApzKeyboardInput() &&
3562 !StaticPrefs::accessibility_browsewithcaret()) {
3563 aObj
.DefineProperty("ApzKeyboardInput", 1);
3566 if (SupportsApzAutoscrolling()) {
3567 aObj
.DefineProperty("ApzAutoscrollInput", 1);
3570 if (SupportsApzZooming()) {
3571 aObj
.DefineProperty("ApzZoomingInput", 1);
3575 void gfxPlatform::GetFrameStats(mozilla::widget::InfoObject
& aObj
) {
3577 for (FrameStats
& f
: mFrameStats
) {
3578 nsPrintfCString
name("Slow Frame #%02u", ++i
);
3580 nsPrintfCString
value(
3582 "(%s) CONTENT_FRAME_TIME %d - Transaction start %f, main-thread time "
3583 "%f, full paint time %f, Skipped composites %u, Composite start %f, "
3584 "Resource upload time %f, GPU cache upload time %f, Render time %f, "
3585 "Composite time %f",
3586 f
.id().mId
, f
.url().get(), f
.contentFrameTime(),
3587 (f
.transactionStart() - f
.refreshStart()).ToMilliseconds(),
3588 (f
.fwdTime() - f
.transactionStart()).ToMilliseconds(),
3590 ? (f
.sceneBuiltTime() - f
.transactionStart()).ToMilliseconds()
3592 f
.skippedComposites(),
3593 (f
.compositeStart() - f
.refreshStart()).ToMilliseconds(),
3594 f
.resourceUploadTime(), f
.gpuCacheUploadTime(),
3595 (f
.compositeEnd() - f
.renderStart()).ToMilliseconds(),
3596 (f
.compositeEnd() - f
.compositeStart()).ToMilliseconds());
3597 aObj
.DefineProperty(name
.get(), value
.get());
3601 void gfxPlatform::GetCMSSupportInfo(mozilla::widget::InfoObject
& aObj
) {
3602 nsTArray
<uint8_t> outputProfileData
=
3603 gfxPlatform::GetPlatform()->GetPlatformCMSOutputProfileData();
3604 if (outputProfileData
.IsEmpty()) {
3605 nsPrintfCString
msg("Empty profile data");
3606 aObj
.DefineProperty("CMSOutputProfile", msg
.get());
3610 // Some profiles can be quite large. We don't want to include giant profiles
3611 // by default in about:support. For now, we only accept less than 8kiB.
3612 const size_t kMaxProfileSize
= 8192;
3613 if (outputProfileData
.Length() >= kMaxProfileSize
) {
3614 nsPrintfCString
msg("%zu bytes, too large", outputProfileData
.Length());
3615 aObj
.DefineProperty("CMSOutputProfile", msg
.get());
3619 nsString encodedProfile
;
3621 Base64Encode(reinterpret_cast<const char*>(outputProfileData
.Elements()),
3622 outputProfileData
.Length(), encodedProfile
);
3623 if (!NS_SUCCEEDED(rv
)) {
3624 nsPrintfCString
msg("base64 encode failed 0x%08x",
3625 static_cast<uint32_t>(rv
));
3626 aObj
.DefineProperty("CMSOutputProfile", msg
.get());
3630 aObj
.DefineProperty("CMSOutputProfile", encodedProfile
);
3633 void gfxPlatform::GetDisplayInfo(mozilla::widget::InfoObject
& aObj
) {
3634 auto& screens
= widget::ScreenManager::GetSingleton().CurrentScreenList();
3635 aObj
.DefineProperty("DisplayCount", screens
.Length());
3638 for (auto& screen
: screens
) {
3639 const LayoutDeviceIntRect rect
= screen
->GetRect();
3640 nsPrintfCString
value("%dx%d@%dHz scales:%f|%f", rect
.width
, rect
.height
,
3641 screen
->GetRefreshRate(),
3642 screen
->GetContentsScaleFactor(),
3643 screen
->GetDefaultCSSScaleFactor());
3645 aObj
.DefineProperty(nsPrintfCString("Display%zu", i
++).get(),
3646 NS_ConvertUTF8toUTF16(value
));
3649 // Platform display info is only currently used for about:support and getting
3650 // it might fail in a child process anyway.
3651 if (XRE_IsParentProcess()) {
3652 GetPlatformDisplayInfo(aObj
);
3656 void gfxPlatform::GetOverlayInfo(mozilla::widget::InfoObject
& aObj
) {
3657 if (mOverlayInfo
.isNothing()) {
3661 auto toString
= [](mozilla::layers::OverlaySupportType aType
) -> const char* {
3663 case mozilla::layers::OverlaySupportType::None
:
3665 case mozilla::layers::OverlaySupportType::Software
:
3667 case mozilla::layers::OverlaySupportType::Direct
:
3669 case mozilla::layers::OverlaySupportType::Scaling
:
3672 MOZ_ASSERT_UNREACHABLE("Unexpected to be called");
3674 MOZ_CRASH("Incomplete switch");
3677 auto toStringBool
= [](bool aSupported
) -> const char* {
3681 return "Not Supported";
3684 nsPrintfCString
value(
3685 "NV12=%s YUV2=%s BGRA8=%s RGB10A2=%s VpSR=%s VpAutoHDR=%s",
3686 toString(mOverlayInfo
.ref().mNv12Overlay
),
3687 toString(mOverlayInfo
.ref().mYuy2Overlay
),
3688 toString(mOverlayInfo
.ref().mBgra8Overlay
),
3689 toString(mOverlayInfo
.ref().mRgb10a2Overlay
),
3690 toStringBool(mOverlayInfo
.ref().mSupportsVpSuperResolution
),
3691 toStringBool(mOverlayInfo
.ref().mSupportsVpAutoHDR
));
3693 aObj
.DefineProperty("OverlaySupport", NS_ConvertUTF8toUTF16(value
));
3696 void gfxPlatform::GetSwapChainInfo(mozilla::widget::InfoObject
& aObj
) {
3697 if (mSwapChainInfo
.isNothing()) {
3701 auto toString
= [](bool aTearingSupported
) -> const char* {
3702 if (aTearingSupported
) {
3705 return "Not Supported";
3708 nsPrintfCString
value("%s", toString(mSwapChainInfo
.ref().mTearingSupported
));
3710 aObj
.DefineProperty("SwapChainTearingSupport", NS_ConvertUTF8toUTF16(value
));
3713 class FrameStatsComparator
{
3715 bool Equals(const FrameStats
& aA
, const FrameStats
& aB
) const {
3716 return aA
.contentFrameTime() == aB
.contentFrameTime();
3718 // Reverse the condition here since we want the array sorted largest to
3720 bool LessThan(const FrameStats
& aA
, const FrameStats
& aB
) const {
3721 return aA
.contentFrameTime() > aB
.contentFrameTime();
3725 void gfxPlatform::NotifyFrameStats(nsTArray
<FrameStats
>&& aFrameStats
) {
3726 if (!StaticPrefs::gfx_logging_slow_frames_enabled_AtStartup()) {
3730 FrameStatsComparator comp
;
3731 for (FrameStats
& f
: aFrameStats
) {
3732 mFrameStats
.InsertElementSorted(f
, comp
);
3734 if (mFrameStats
.Length() > 10) {
3735 mFrameStats
.SetLength(10);
3740 uint32_t gfxPlatform::TargetFrameRate() {
3741 if (gPlatform
&& gPlatform
->mVsyncDispatcher
) {
3742 return round(1000.0 /
3743 gPlatform
->mVsyncDispatcher
->GetVsyncRate().ToMilliseconds());
3749 bool gfxPlatform::UseDesktopZoomingScrollbars() {
3750 return StaticPrefs::apz_allow_zooming();
3754 bool gfxPlatform::AsyncPanZoomEnabled() {
3755 #if !defined(MOZ_WIDGET_ANDROID) && !defined(MOZ_WIDGET_UIKIT)
3756 // For XUL applications (everything but Firefox on Android)
3757 // we only want to use APZ when E10S is enabled. If
3758 // we ever get input events off the main thread we can consider relaxing
3759 // this requirement.
3760 if (!BrowserTabsRemoteAutostart()) {
3764 #ifdef MOZ_WIDGET_ANDROID
3767 // If Fission is enabled, OOP iframes require APZ for hittest. So, we
3768 // need to forcibly enable APZ in that case for avoiding users confused.
3769 if (FissionAutostart()) {
3772 return StaticPrefs::
3773 layers_async_pan_zoom_enabled_AtStartup_DoNotUseDirectly();
3778 bool gfxPlatform::PerfWarnings() {
3779 return StaticPrefs::gfx_perf_warnings_enabled();
3782 void gfxPlatform::NotifyCompositorCreated(LayersBackend aBackend
) {
3783 if (mCompositorBackend
== aBackend
) {
3787 if (mCompositorBackend
!= LayersBackend::LAYERS_NONE
) {
3788 gfxCriticalNote
<< "Compositors might be mixed (" << int(mCompositorBackend
)
3789 << "," << int(aBackend
) << ")";
3792 // Set the backend before we notify so it's available immediately.
3793 mCompositorBackend
= aBackend
;
3795 if (XRE_IsParentProcess()) {
3796 nsDependentCString
compositor(GetLayersBackendName(mCompositorBackend
));
3797 mozilla::glean::gfx_status::compositor
.Set(compositor
);
3799 nsCString geckoVersion
;
3800 nsCOMPtr
<nsIXULAppInfo
> app
= do_GetService("@mozilla.org/xre/app-info;1");
3802 app
->GetVersion(geckoVersion
);
3804 mozilla::glean::gfx_status::last_compositor_gecko_version
.Set(geckoVersion
);
3806 mozilla::glean::gfx_feature::webrender
.Set(
3807 gfxConfig::GetFeature(gfx::Feature::WEBRENDER
)
3808 .GetStatusAndFailureIdString());
3811 // Notify that we created a compositor, so telemetry can update.
3812 NS_DispatchToMainThread(
3813 NS_NewRunnableFunction("gfxPlatform::NotifyCompositorCreated", [] {
3814 if (nsCOMPtr
<nsIObserverService
> obsvc
=
3815 services::GetObserverService()) {
3816 obsvc
->NotifyObservers(nullptr, "compositor:created", nullptr);
3822 bool gfxPlatform::FallbackFromAcceleration(FeatureStatus aStatus
,
3823 const char* aMessage
,
3824 const nsACString
& aFailureId
,
3825 bool aCrashAfterFinalFallback
) {
3826 // We always want to ensure (Hardware) WebRender is disabled.
3827 if (gfxConfig::IsEnabled(Feature::WEBRENDER
)) {
3828 gfxConfig::GetFeature(Feature::WEBRENDER
)
3829 .ForceDisable(aStatus
, aMessage
, aFailureId
);
3832 // Determine whether or not we are allowed to use Software WebRender in
3833 // fallback without the GPU process. Either the pref is false, or the feature
3834 // is enabled and we are currently still using it.
3835 bool swglFallbackAllowed
=
3837 gfx_webrender_fallback_software_requires_gpu_process_AtStartup() ||
3838 gfxConfig::IsEnabled(Feature::GPU_PROCESS
);
3841 // Before we disable D3D11 and HW_COMPOSITING, we should check if we can
3842 // fallback from WebRender to Software WebRender + D3D11 compositing.
3843 if (swglFallbackAllowed
&& gfxVars::AllowSoftwareWebRenderD3D11() &&
3844 gfxConfig::IsEnabled(Feature::D3D11_COMPOSITING
) &&
3845 !gfxVars::UseSoftwareWebRender()) {
3846 // Fallback to Software WebRender + D3D11 compositing.
3847 gfxCriticalNote
<< "Fallback WR to SW-WR + D3D11";
3848 gfxVars::SetUseSoftwareWebRender(true);
3852 if (swglFallbackAllowed
&& gfxVars::AllowSoftwareWebRenderD3D11() &&
3853 gfxVars::UseSoftwareWebRender()) {
3854 // Fallback from Software WebRender + D3D11 to Software WebRender.
3855 gfxCriticalNote
<< "Fallback SW-WR + D3D11 to SW-WR";
3856 gfxVars::SetAllowSoftwareWebRenderD3D11(false);
3860 // We aren't using Software WebRender + D3D11 compositing, so turn off the
3862 if (gfxConfig::IsEnabled(Feature::DIRECT2D
)) {
3863 gfxConfig::GetFeature(Feature::DIRECT2D
)
3864 .ForceDisable(aStatus
, aMessage
, aFailureId
);
3866 if (gfxConfig::IsEnabled(Feature::D3D11_COMPOSITING
)) {
3867 gfxConfig::GetFeature(Feature::D3D11_COMPOSITING
)
3868 .ForceDisable(aStatus
, aMessage
, aFailureId
);
3872 #if defined(MOZ_WIDGET_ANDROID) || defined(MOZ_WIDGET_GTK)
3873 // Before we disable OpenGL and HW_COMPOSITING, we should check if we can
3874 // fallback from WebRender to Software WebRender + OpenGL compositing.
3875 if (swglFallbackAllowed
&& gfxVars::AllowSoftwareWebRenderOGL() &&
3876 gfxConfig::IsEnabled(Feature::OPENGL_COMPOSITING
) &&
3877 !gfxVars::UseSoftwareWebRender()) {
3878 // Fallback to Software WebRender + OpenGL compositing.
3879 gfxCriticalNote
<< "Fallback WR to SW-WR + OpenGL";
3880 gfxVars::SetUseSoftwareWebRender(true);
3884 // Android does not want to fallback to SW-WR.
3885 #ifdef MOZ_WIDGET_GTK
3886 if (swglFallbackAllowed
&& gfxVars::AllowSoftwareWebRenderOGL() &&
3887 gfxVars::UseSoftwareWebRender()) {
3888 // Fallback from Software WebRender + OpenGL to Software WebRender.
3889 gfxCriticalNote
<< "Fallback SW-WR + OpenGL to SW-WR";
3890 gfxVars::SetAllowSoftwareWebRenderOGL(false);
3895 #ifndef MOZ_WIDGET_ANDROID
3896 // Non-Android wants to fallback to Software WebRender or Basic. Android wants
3897 // to fallback to OpenGL.
3898 if (gfxConfig::IsEnabled(Feature::HW_COMPOSITING
)) {
3899 gfxConfig::GetFeature(Feature::HW_COMPOSITING
)
3900 .ForceDisable(aStatus
, aMessage
, aFailureId
);
3904 if (StaticPrefs::gfx_webrender_fallback_software_AtStartup() &&
3905 swglFallbackAllowed
&& !gfxVars::UseSoftwareWebRender()) {
3906 // Fallback from WebRender to Software WebRender.
3907 gfxCriticalNote
<< "Fallback WR to SW-WR";
3908 gfxVars::SetUseSoftwareWebRender(true);
3912 if (!gfxVars::UseSoftwareWebRender()) {
3913 // Software WebRender may be disabled due to a startup issue with the
3914 // blocklist, despite it being our only fallback option based on the prefs.
3915 // If WebRender is unable to be initialized, this means that user would
3916 // otherwise get stuck with WebRender. As such, force a switch to Software
3917 // WebRender in this case.
3918 gfxCriticalNoteOnce
<< "Fallback WR to SW-WR, forced";
3919 gfxVars::SetUseSoftwareWebRender(true);
3923 if (aCrashAfterFinalFallback
) {
3924 MOZ_CRASH("Fallback configurations exhausted");
3927 // Continue using Software WebRender (disabled fallback to Basic).
3928 gfxCriticalNoteOnce
<< "Fallback remains SW-WR";
3933 void gfxPlatform::DisableGPUProcess() {
3934 if (gfxVars::RemoteCanvasEnabled() &&
3935 !StaticPrefs::gfx_canvas_remote_allow_in_parent_AtStartup()) {
3937 Feature::REMOTE_CANVAS
, FeatureStatus::UnavailableNoGpuProcess
,
3938 "Disabled by GPU process disabled",
3939 "FEATURE_REMOTE_CANVAS_DISABLED_BY_GPU_PROCESS_DISABLED"_ns
);
3940 gfxVars::SetRemoteCanvasEnabled(false);
3944 // On android, enable out-of-process WebGL only when GPU process exists.
3945 gfxVars::SetAllowWebglOop(false);
3946 // On android, enable accelerated canvas only when GPU process exists.
3947 gfxVars::SetUseAcceleratedCanvas2D(false);
3948 gfxConfig::Disable(Feature::ACCELERATED_CANVAS2D
, FeatureStatus::Blocked
,
3949 "Disabled by GPU Process disabled",
3950 "FEATURE_FAILURE_DISABLED_BY_GPU_PROCESS_DISABLED"_ns
);
3953 RemoteTextureMap::Init();
3954 // We need to initialize the parent process to prepare for WebRender if we
3955 // did not end up disabling it, despite losing the GPU process.
3956 wr::RenderThread::Start(GPUProcessManager::Get()->AllocateNamespace());
3957 gfx::CanvasRenderThread::Start();
3958 image::ImageMemoryReporter::InitForWebRender();
3961 /* static */ void gfxPlatform::DisableRemoteCanvas() {
3962 if (gfxVars::RemoteCanvasEnabled()) {
3963 gfxConfig::ForceDisable(Feature::REMOTE_CANVAS
, FeatureStatus::Failed
,
3964 "Disabled by runtime error",
3965 "FEATURE_REMOTE_CANVAS_RUNTIME_ERROR"_ns
);
3966 gfxVars::SetRemoteCanvasEnabled(false);
3968 if (gfxVars::UseAcceleratedCanvas2D()) {
3969 gfxConfig::ForceDisable(Feature::ACCELERATED_CANVAS2D
,
3970 FeatureStatus::Failed
, "Disabled by runtime error",
3971 "FEATURE_ACCELERATED_CANVAS2D_RUNTIME_ERROR"_ns
);
3972 gfxVars::SetUseAcceleratedCanvas2D(false);
3976 void gfxPlatform::ImportCachedContentDeviceData() {
3977 MOZ_ASSERT(XRE_IsContentProcess());
3979 // Import the content device data if we've got some waiting.
3980 if (!gContentDeviceInitData
) {
3984 ImportContentDeviceData(*gContentDeviceInitData
);
3985 gContentDeviceInitData
= nullptr;
3988 void gfxPlatform::ImportContentDeviceData(
3989 const mozilla::gfx::ContentDeviceData
& aData
) {
3990 MOZ_ASSERT(XRE_IsContentProcess());
3992 const DevicePrefs
& prefs
= aData
.prefs();
3993 gfxConfig::Inherit(Feature::HW_COMPOSITING
, prefs
.hwCompositing());
3995 // We don't inherit Feature::OPENGL_COMPOSITING here, because platforms
3996 // will handle that (without imported data from the parent) in
3997 // InitOpenGLConfig.
3998 mCMSOutputProfileData
= Some(aData
.cmsOutputProfileData().Clone());
4001 void gfxPlatform::BuildContentDeviceData(
4002 mozilla::gfx::ContentDeviceData
* aOut
) {
4003 MOZ_ASSERT(XRE_IsParentProcess());
4005 // Make sure our settings are synchronized from the GPU process.
4006 DebugOnly
<nsresult
> rv
= GPUProcessManager::Get()->EnsureGPUReady();
4007 MOZ_ASSERT(rv
!= NS_ERROR_ILLEGAL_DURING_SHUTDOWN
);
4009 aOut
->prefs().hwCompositing() = gfxConfig::GetValue(Feature::HW_COMPOSITING
);
4010 aOut
->prefs().oglCompositing() =
4011 gfxConfig::GetValue(Feature::OPENGL_COMPOSITING
);
4014 void gfxPlatform::ImportGPUDeviceData(
4015 const mozilla::gfx::GPUDeviceData
& aData
) {
4016 MOZ_ASSERT(XRE_IsParentProcess());
4018 gfxConfig::ImportChange(Feature::OPENGL_COMPOSITING
, aData
.oglCompositing());
4021 bool gfxPlatform::SupportsApzTouchInput() const {
4022 return dom::TouchEvent::PrefEnabled(nullptr);
4025 bool gfxPlatform::SupportsApzDragInput() const {
4026 return StaticPrefs::apz_drag_enabled();
4029 bool gfxPlatform::SupportsApzKeyboardInput() const {
4030 return StaticPrefs::apz_keyboard_enabled_AtStartup();
4033 bool gfxPlatform::SupportsApzAutoscrolling() const {
4034 return StaticPrefs::apz_autoscroll_enabled();
4037 bool gfxPlatform::SupportsApzZooming() const {
4038 return StaticPrefs::apz_allow_zooming();
4041 void gfxPlatform::InitOpenGLConfig() {
4043 // Don't enable by default on Windows, since it could show up in
4044 // about:support even though it'll never get used. Only attempt if user
4046 if (!Preferences::GetBool("layers.prefer-opengl")) {
4051 FeatureState
& openGLFeature
=
4052 gfxConfig::GetFeature(Feature::OPENGL_COMPOSITING
);
4054 // Check to see hw comp supported
4055 if (!gfxConfig::IsEnabled(Feature::HW_COMPOSITING
)) {
4056 openGLFeature
.DisableByDefault(FeatureStatus::Unavailable
,
4057 "Hardware compositing is disabled",
4058 "FEATURE_FAILURE_OPENGL_NEED_HWCOMP"_ns
);
4063 openGLFeature
.SetDefaultFromPref(
4064 StaticPrefs::GetPrefName_layers_prefer_opengl(), true,
4065 StaticPrefs::GetPrefDefault_layers_prefer_opengl());
4067 openGLFeature
.EnableByDefault();
4070 // When layers acceleration is force-enabled, enable it even for blocklisted
4073 layers_acceleration_force_enabled_AtStartup_DoNotUseDirectly()) {
4074 openGLFeature
.UserForceEnable("Force-enabled by pref");
4079 nsCString failureId
;
4080 if (!IsGfxInfoStatusOkay(nsIGfxInfo::FEATURE_OPENGL_LAYERS
, &message
,
4082 openGLFeature
.Disable(FeatureStatus::Blocklisted
, message
.get(), failureId
);
4086 bool gfxPlatform::IsGfxInfoStatusOkay(int32_t aFeature
, nsCString
* aOutMessage
,
4087 nsCString
& aFailureId
) {
4088 nsCOMPtr
<nsIGfxInfo
> gfxInfo
= components::GfxInfo::Service();
4094 if (NS_SUCCEEDED(gfxInfo
->GetFeatureStatus(aFeature
, aFailureId
, &status
)) &&
4095 status
!= nsIGfxInfo::FEATURE_STATUS_OK
) {
4096 aOutMessage
->AssignLiteral("#BLOCKLIST_");
4097 aOutMessage
->AppendASCII(aFailureId
.get());