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/. */
9 #include "mozilla/FontPropertyTypes.h"
10 #include "mozilla/gfx/Types.h"
14 #include "nsUnicodeScriptCodes.h"
16 #include "gfxTelemetry.h"
18 #include "gfxSkipChars.h"
22 #include "mozilla/RefPtr.h"
23 #include "GfxInfoCollector.h"
25 #include "mozilla/layers/CompositorTypes.h"
26 #include "mozilla/layers/LayersTypes.h"
27 #include "mozilla/layers/MemoryPressureObserver.h"
35 class gfxPlatformFontList
;
41 class SRGBOverrideObserver
;
42 class gfxTextPerfMetrics
;
43 typedef struct FT_LibraryRec_
* FT_Library
;
46 struct StyleFontFamilyList
;
54 class DataSourceSurface
;
57 class ContentDeviceData
;
61 inline uint32_t BackendTypeBit(BackendType b
) { return 1 << uint8_t(b
); }
65 class SystemFontListEntry
;
68 } // namespace mozilla
70 #define MOZ_PERFORMANCE_WARNING(module, ...) \
72 if (gfxPlatform::PerfWarnings()) { \
73 printf_stderr("[" module "] " __VA_ARGS__); \
77 enum class CMSMode
: int32_t {
78 Off
= 0, // No color management
79 All
= 1, // Color manage everything
80 TaggedOnly
= 2, // Color manage tagged Images Only
85 // all font enumerations, localized names, fullname/psnames, cmap loads
87 // timing info on font initialization
89 // dump text runs, font matching, system fallback for content
91 // dump text runs, font matching, system fallback for chrome
92 eGfxLog_textrunui
= 3,
93 // dump cmap coverage data as they are loaded
99 // Used during font matching to express a preference, if any, for whether
100 // to use a font that will present a color or monochrome glyph.
101 enum class eFontPresentation
: uint8_t {
102 // Character does not have the emoji property, so no special heuristics
103 // apply during font selection.
105 // Character is potentially emoji, but Text-style presentation has been
106 // explicitly requested using VS15.
108 // Character has Emoji-style presentation by default (but an author-
109 // provided webfont will be used even if it is not color).
111 // Character explicitly requires Emoji-style presentation due to VS16 or
112 // skin-tone codepoint.
116 inline bool PrefersColor(eFontPresentation aPresentation
) {
117 return aPresentation
>= eFontPresentation::EmojiDefault
;
120 // when searching through pref langs, max number of pref langs
121 const uint32_t kMaxLenPrefLangList
= 32;
123 #define UNINITIALIZED_VALUE (-1)
125 inline const char* GetBackendName(mozilla::gfx::BackendType aBackend
) {
127 case mozilla::gfx::BackendType::DIRECT2D
:
129 case mozilla::gfx::BackendType::CAIRO
:
131 case mozilla::gfx::BackendType::SKIA
:
133 case mozilla::gfx::BackendType::RECORDING
:
135 case mozilla::gfx::BackendType::DIRECT2D1_1
:
136 return "direct2d 1.1";
137 case mozilla::gfx::BackendType::WEBRENDER_TEXT
:
138 return "webrender text";
139 case mozilla::gfx::BackendType::NONE
:
141 case mozilla::gfx::BackendType::BACKEND_LAST
:
144 MOZ_CRASH("Incomplete switch");
147 enum class DeviceResetReason
{
149 HUNG
, // Windows specific, guilty device reset.
150 REMOVED
, // Windows specific, device removed or driver upgraded.
151 RESET
, // Guilty device reset.
152 DRIVER_ERROR
, // Innocent device reset.
153 INVALID_CALL
, // Windows specific, guilty device reset.
155 FORCED_RESET
, // Simulated device reset.
156 OTHER
, // Unrecognized reason for device reset.
157 D3D9_RESET
, // Windows specific, not used.
158 NVIDIA_VIDEO
, // Linux specific, NVIDIA video memory was reset.
159 UNKNOWN
, // GL specific, unknown if guilty or innocent.
162 enum class ForcedDeviceResetReason
{
163 OPENSHAREDHANDLE
= 0,
167 struct BackendPrefsData
{
168 uint32_t mCanvasBitmask
= 0;
169 mozilla::gfx::BackendType mCanvasDefault
= mozilla::gfx::BackendType::NONE
;
170 uint32_t mContentBitmask
= 0;
171 mozilla::gfx::BackendType mContentDefault
= mozilla::gfx::BackendType::NONE
;
174 class gfxPlatform
: public mozilla::layers::MemoryPressureListener
{
175 friend class SRGBOverrideObserver
;
178 typedef mozilla::StretchRange StretchRange
;
179 typedef mozilla::SlantStyleRange SlantStyleRange
;
180 typedef mozilla::WeightRange WeightRange
;
181 typedef mozilla::gfx::sRGBColor sRGBColor
;
182 typedef mozilla::gfx::DeviceColor DeviceColor
;
183 typedef mozilla::gfx::DataSourceSurface DataSourceSurface
;
184 typedef mozilla::gfx::DrawTarget DrawTarget
;
185 typedef mozilla::gfx::IntSize IntSize
;
186 typedef mozilla::gfx::SourceSurface SourceSurface
;
187 typedef mozilla::unicode::Script Script
;
190 * Return a pointer to the current active platform.
191 * This is a singleton; it contains mostly convenience
192 * functions to obtain platform-specific objects.
194 static gfxPlatform
* GetPlatform();
197 * Returns whether or not graphics has been initialized yet. This is
198 * intended for Telemetry where we don't necessarily want to initialize
199 * graphics just to observe its state.
201 static bool Initialized();
205 * Init() arranges for this to be called at an appropriate time.
207 static void Shutdown();
210 * Initialize gfxPlatform (if not already done) in a child process, with
211 * the provided ContentDeviceData.
213 static void InitChild(const mozilla::gfx::ContentDeviceData
& aData
);
215 static void InitLayersIPC();
216 static void ShutdownLayersIPC();
219 * Initialize ScrollMetadata statics. Does not depend on gfxPlatform.
221 static void InitNullMetadata();
223 static int32_t MaxTextureSize();
224 static int32_t MaxAllocSize();
225 static void InitMoz2DLogging();
227 static bool IsHeadless();
229 static bool UseWebRender();
231 static bool UseRemoteCanvas();
233 static bool IsBackendAccelerated(
234 const mozilla::gfx::BackendType aBackendType
);
236 static bool CanMigrateMacGPUs();
239 * Create an offscreen surface of the given dimensions
242 virtual already_AddRefed
<gfxASurface
> CreateOffscreenSurface(
243 const IntSize
& aSize
, gfxImageFormat aFormat
) = 0;
246 * Beware that this method may return DrawTargets which are not fully
247 * supported on the current platform and might fail silently in subtle ways.
248 * This is a massive potential footgun. You should only use these methods for
249 * canvas drawing really. Use extreme caution if you use them for content
250 * where you are not 100% sure we support the DrawTarget we get back. See
251 * SupportsAzureContentForDrawTarget.
253 static already_AddRefed
<DrawTarget
> CreateDrawTargetForSurface(
254 gfxASurface
* aSurface
, const mozilla::gfx::IntSize
& aSize
);
257 * Creates a SourceSurface for a gfxASurface. This function does no caching,
258 * so the caller should cache the gfxASurface if it will be used frequently.
259 * The returned surface keeps a reference to aTarget, so it is OK to keep the
260 * surface, even if aTarget changes.
261 * aTarget should not keep a reference to the returned surface because that
262 * will cause a cycle.
264 * This function is static so that it can be accessed from outside the main
267 * aIsPlugin is used to tell the backend that they can optimize this surface
268 * specifically because it's used for a plugin. This is mostly for Skia.
270 static already_AddRefed
<SourceSurface
> GetSourceSurfaceForSurface(
271 RefPtr
<mozilla::gfx::DrawTarget
> aTarget
, gfxASurface
* aSurface
,
272 bool aIsPlugin
= false);
274 static void ClearSourceSurfaceForSurface(gfxASurface
* aSurface
);
276 static already_AddRefed
<DataSourceSurface
> GetWrappedDataSourceSurface(
277 gfxASurface
* aSurface
);
279 already_AddRefed
<DrawTarget
> CreateOffscreenContentDrawTarget(
280 const mozilla::gfx::IntSize
& aSize
, mozilla::gfx::SurfaceFormat aFormat
,
281 bool aFallback
= false);
283 already_AddRefed
<DrawTarget
> CreateOffscreenCanvasDrawTarget(
284 const mozilla::gfx::IntSize
& aSize
, mozilla::gfx::SurfaceFormat aFormat
);
286 already_AddRefed
<DrawTarget
> CreateSimilarSoftwareDrawTarget(
287 DrawTarget
* aDT
, const IntSize
& aSize
,
288 mozilla::gfx::SurfaceFormat aFormat
);
290 static already_AddRefed
<DrawTarget
> CreateDrawTargetForData(
291 unsigned char* aData
, const mozilla::gfx::IntSize
& aSize
, int32_t aStride
,
292 mozilla::gfx::SurfaceFormat aFormat
, bool aUninitialized
= false);
295 * Returns true if we should use Azure to render content with aTarget. For
296 * example, it is possible that we are using Direct2D for rendering and thus
297 * using Azure. But we want to render to a CairoDrawTarget, in which case
298 * SupportsAzureContent will return true but SupportsAzureContentForDrawTarget
301 bool SupportsAzureContentForDrawTarget(mozilla::gfx::DrawTarget
* aTarget
);
303 bool SupportsAzureContentForType(mozilla::gfx::BackendType aType
) {
304 return BackendTypeBit(aType
) & mContentBackendBitmask
;
307 static bool AsyncPanZoomEnabled();
309 const char* GetAzureCanvasBackend() const;
310 const char* GetAzureContentBackend() const;
312 void GetAzureBackendInfo(mozilla::widget::InfoObject
& aObj
);
313 void GetApzSupportInfo(mozilla::widget::InfoObject
& aObj
);
314 void GetTilesSupportInfo(mozilla::widget::InfoObject
& aObj
);
315 void GetFrameStats(mozilla::widget::InfoObject
& aObj
);
316 void GetCMSSupportInfo(mozilla::widget::InfoObject
& aObj
);
317 void GetDisplayInfo(mozilla::widget::InfoObject
& aObj
);
319 // Get the default content backend that will be used with the default
320 // compositor. If the compositor is known when calling this function,
321 // GetContentBackendFor() should be called instead.
322 mozilla::gfx::BackendType
GetDefaultContentBackend() const {
323 return mContentBackend
;
326 /// Return the software backend to use by default.
327 mozilla::gfx::BackendType
GetSoftwareBackend() { return mSoftwareBackend
; }
329 // Return the best content backend available that is compatible with the
330 // given layers backend.
331 virtual mozilla::gfx::BackendType
GetContentBackendFor(
332 mozilla::layers::LayersBackend aLayers
) {
333 return mContentBackend
;
336 virtual mozilla::gfx::BackendType
GetPreferredCanvasBackend() {
337 return mPreferredCanvasBackend
;
339 mozilla::gfx::BackendType
GetFallbackCanvasBackend() {
340 return mFallbackCanvasBackend
;
348 * Fill aListOfFonts with the results of querying the list of font names
349 * that correspond to the given language group or generic font family
350 * (or both, or neither).
352 virtual nsresult
GetFontList(nsAtom
* aLangGroup
,
353 const nsACString
& aGenericFamily
,
354 nsTArray
<nsString
>& aListOfFonts
);
357 * Fill aFontList with a list of SystemFontListEntry records for the
358 * available fonts on the platform; used to pass the list from chrome to
359 * content process. Currently implemented only on MacOSX and Linux.
361 virtual void ReadSystemFontList(mozilla::dom::SystemFontList
*){};
364 * Rebuilds the system font lists (if aFullRebuild is true), or just notifies
365 * content that the list has changed but existing memory mappings are still
366 * valid (aFullRebuild is false).
368 nsresult
UpdateFontList(bool aFullRebuild
= true);
371 * Create the platform font-list object (gfxPlatformFontList concrete
372 * subclass). This function is responsible to create the appropriate subclass
373 * of gfxPlatformFontList *and* to call its InitFontList() method.
375 virtual bool CreatePlatformFontList() = 0;
378 * Resolving a font name to family name. The result MUST be in the result of
379 * GetFontList(). If the name doesn't in the system, aFamilyName will be empty
380 * string, but not failed.
382 void GetStandardFamilyName(const nsCString
& aFontName
,
383 nsACString
& aFamilyName
);
386 * Returns default font name (localized family name) for aLangGroup and
387 * aGenericFamily. The result is typically the first font in
388 * font.name-list.<aGenericFamily>.<aLangGroup>. However, if it's not
389 * available in the system, this may return second or later font in the
390 * pref. If there are no available fonts in the pref, returns empty string.
392 nsAutoCString
GetDefaultFontName(const nsACString
& aLangGroup
,
393 const nsACString
& aGenericFamily
);
396 * Create a gfxFontGroup based on the given family list and style.
398 gfxFontGroup
* CreateFontGroup(
399 nsPresContext
* aPresContext
,
400 const mozilla::StyleFontFamilyList
& aFontFamilyList
,
401 const gfxFontStyle
* aStyle
, nsAtom
* aLanguage
, bool aExplicitLanguage
,
402 gfxTextPerfMetrics
* aTextPerf
, gfxUserFontSet
* aUserFontSet
,
403 gfxFloat aDevToCssSize
) const;
406 * Look up a local platform font using the full font face name.
407 * (Needed to support @font-face src local().)
408 * Ownership of the returned gfxFontEntry is passed to the caller,
409 * who must either AddRef() or delete.
411 gfxFontEntry
* LookupLocalFont(nsPresContext
* aPresContext
,
412 const nsACString
& aFontName
,
413 WeightRange aWeightForEntry
,
414 StretchRange aStretchForEntry
,
415 SlantStyleRange aStyleForEntry
);
418 * Activate a platform font. (Needed to support @font-face src url().)
419 * aFontData is a NS_Malloc'ed block that must be freed by this function
420 * (or responsibility passed on) when it is no longer needed; the caller
422 * Ownership of the returned gfxFontEntry is passed to the caller,
423 * who must either AddRef() or delete.
425 gfxFontEntry
* MakePlatformFont(const nsACString
& aFontName
,
426 WeightRange aWeightForEntry
,
427 StretchRange aStretchForEntry
,
428 SlantStyleRange aStyleForEntry
,
429 const uint8_t* aFontData
, uint32_t aLength
);
432 * Whether to allow downloadable fonts via @font-face rules
434 bool DownloadableFontsEnabled();
437 * True when hinting should be enabled. This setting shouldn't
438 * change per gecko process, while the process is live. If so the
439 * results are not defined.
441 * NB: this bit is only honored by the FT2 backend, currently.
443 virtual bool FontHintingEnabled() { return true; }
446 * True when zooming should not require reflow, so glyph metrics and
447 * positioning should not be adjusted for device pixels.
448 * If this is TRUE, then FontHintingEnabled() should be FALSE,
449 * but the converse is not necessarily required;
451 * Like FontHintingEnabled (above), this setting shouldn't
452 * change per gecko process, while the process is live. If so the
453 * results are not defined.
455 * NB: this bit is only honored by the FT2 backend, currently.
457 virtual bool RequiresLinearZoom() { return false; }
460 * Whether the frame->StyleFont().mFont.smoothing field is respected by
461 * text rendering on this platform.
463 virtual bool RespectsFontStyleSmoothing() const { return false; }
466 * Whether to check all font cmaps during system font fallback
468 bool UseCmapsDuringSystemFallback();
471 * Whether to render SVG glyphs within an OpenType font wrapper
473 bool OpenTypeSVGEnabled();
476 * Max character length of words in the word cache
478 uint32_t WordCacheCharLimit();
481 * Max number of entries in word cache
483 uint32_t WordCacheMaxEntries();
486 * Whether to use the SIL Graphite rendering engine
487 * (for fonts that include Graphite tables)
489 bool UseGraphiteShaping();
491 // Check whether format is supported on a platform (if unclear, returns true).
492 // Default implementation checks for "common" formats that we support across
493 // all platforms, but individual platform implementations may override.
494 virtual bool IsFontFormatSupported(uint32_t aFormatFlags
);
496 virtual bool DidRenderingDeviceReset(
497 DeviceResetReason
* aResetReason
= nullptr) {
501 // returns a list of commonly used fonts for a given character
502 // these are *possible* matches, no cmap-checking is done at this level
503 virtual void GetCommonFallbackFonts(uint32_t /*aCh*/, Script
/*aRunScript*/,
504 eFontPresentation
/*aPresentation*/,
505 nsTArray
<const char*>& /*aFontList*/) {
506 // platform-specific override, by default do nothing
509 // Are we in safe mode?
510 static bool InSafeMode();
512 static bool OffMainThreadCompositingEnabled();
514 void UpdateCanUseHardwareVideoDecoding();
517 * Are we going to try color management?
519 static CMSMode
GetCMSMode() {
520 EnsureCMSInitialized();
525 * Used only for testing. Override the pref setting.
527 static void SetCMSModeOverride(CMSMode aMode
);
530 * Determines the rendering intent for color management.
532 * If the value in the pref gfx.color_management.rendering_intent is a
533 * valid rendering intent as defined in gfx/qcms/qcms.h, that
534 * value is returned. Otherwise, -1 is returned and the embedded intent
537 * See bug 444014 for details.
539 static int GetRenderingIntent();
542 * Convert a pixel using a cms transform in an endian-aware manner.
544 static DeviceColor
TransformPixel(const sRGBColor
& in
,
545 qcms_transform
* transform
);
548 * Return the output device ICC profile.
550 static qcms_profile
* GetCMSOutputProfile() {
551 EnsureCMSInitialized();
552 return gCMSOutputProfile
;
556 * Return the sRGB ICC profile.
558 static qcms_profile
* GetCMSsRGBProfile() {
559 EnsureCMSInitialized();
560 return gCMSsRGBProfile
;
564 * Return sRGB -> output device transform.
566 static qcms_transform
* GetCMSRGBTransform() {
567 EnsureCMSInitialized();
568 return gCMSRGBTransform
;
572 * Return output -> sRGB device transform.
574 static qcms_transform
* GetCMSInverseRGBTransform() {
575 MOZ_ASSERT(gCMSInitialized
);
576 return gCMSInverseRGBTransform
;
580 * Return sRGBA -> output device transform.
582 static qcms_transform
* GetCMSRGBATransform() {
583 MOZ_ASSERT(gCMSInitialized
);
584 return gCMSRGBATransform
;
588 * Return sBGRA -> output device transform.
590 static qcms_transform
* GetCMSBGRATransform() {
591 MOZ_ASSERT(gCMSInitialized
);
592 return gCMSBGRATransform
;
596 * Return OS RGBA -> output device transform.
598 static qcms_transform
* GetCMSOSRGBATransform();
601 * Return OS RGBA QCMS type.
603 static qcms_data_type
GetCMSOSRGBAType();
605 virtual void FontsPrefsChanged(const char* aPref
);
607 int32_t GetBidiNumeralOption();
610 * This is a bit ugly, but useful... force all presContexts to reflow,
611 * by toggling a preference that they observe. This is used when
612 * something about platform settings changes that might have an effect
613 * on layout, such as font rendering settings that influence metrics.
615 enum class NeedsReframe
: bool { No
, Yes
};
616 static void ForceGlobalReflow(NeedsReframe
);
618 static void FlushFontAndWordCaches();
621 * Returns a 1x1 DrawTarget that can be used for measuring text etc. as
622 * it would measure if rendered on-screen. Guaranteed to return a
623 * non-null and valid DrawTarget.
625 RefPtr
<mozilla::gfx::DrawTarget
> ScreenReferenceDrawTarget();
627 virtual mozilla::gfx::SurfaceFormat
Optimal2DFormatForContent(
628 gfxContentType aContent
);
630 virtual gfxImageFormat
OptimalFormatForContent(gfxContentType aContent
);
632 virtual gfxImageFormat
GetOffscreenFormat() {
633 return mozilla::gfx::SurfaceFormat::X8R8G8B8_UINT32
;
637 * Returns whether the current process should use tiling for layers.
639 virtual bool UsesTiling() const;
642 * Returns a logger if one is available and logging is enabled
644 static mozilla::LogModule
* GetLog(eGfxLog aWhichLog
);
646 int GetScreenDepth() const { return mScreenDepth
; }
647 mozilla::gfx::IntSize
GetScreenSize() const { return mScreenSize
; }
649 static void PurgeSkiaFontCache();
651 static bool UsesOffMainThreadCompositing();
654 * Get the hardware vsync source for each platform.
655 * Should only exist and be valid on the parent process
657 virtual mozilla::gfx::VsyncSource
* GetHardwareVsync() {
658 MOZ_ASSERT(mVsyncSource
!= nullptr);
659 MOZ_ASSERT(XRE_IsParentProcess());
664 * True if layout rendering should use ASAP mode, which means
665 * the refresh driver and compositor should render ASAP.
666 * Used for talos testing purposes
668 static bool IsInLayoutAsapMode();
671 * Returns whether or not a custom vsync rate is set.
673 static bool ForceSoftwareVsync();
676 * Returns the software vsync rate to use.
678 static int GetSoftwareVsyncRate();
681 * Returns the default frame rate for the refresh driver / software vsync.
683 static int GetDefaultFrameRate();
686 * Update the frame rate (called e.g. after pref changes).
688 static void ReInitFrameRate();
691 * Update force subpixel AA quality setting (called after pref
694 void UpdateForceSubpixelAAWherePossible();
697 * Used to test which input types are handled via APZ.
699 virtual bool SupportsApzWheelInput() const { return false; }
700 bool SupportsApzTouchInput() const;
701 bool SupportsApzDragInput() const;
702 bool SupportsApzKeyboardInput() const;
703 bool SupportsApzAutoscrolling() const;
704 bool SupportsApzZooming() const;
706 // If a device reset has occurred, schedule any necessary paints in the
707 // widget. This should only be used within nsRefreshDriver.
708 virtual void SchedulePaintIfDeviceReset() {}
711 * Helper method, creates a draw target for a specific Azure backend.
712 * Used by CreateOffscreenDrawTarget.
714 already_AddRefed
<DrawTarget
> CreateDrawTargetForBackend(
715 mozilla::gfx::BackendType aBackend
, const mozilla::gfx::IntSize
& aSize
,
716 mozilla::gfx::SurfaceFormat aFormat
);
719 * Wrapper around StaticPrefs::gfx_perf_warnings_enabled().
720 * Extracted into a function to avoid including StaticPrefs_gfx.h from this
723 static bool PerfWarnings();
725 static void DisableGPUProcess();
727 void NotifyCompositorCreated(mozilla::layers::LayersBackend aBackend
);
728 mozilla::layers::LayersBackend
GetCompositorBackend() const {
729 return mCompositorBackend
;
732 virtual void CompositorUpdated() {}
734 // Plugin async drawing support.
735 virtual bool SupportsPluginDirectBitmapDrawing() { return false; }
737 // Some platforms don't support CompositorOGL in an unaccelerated OpenGL
738 // context. These platforms should return true here.
739 virtual bool RequiresAcceleratedGLContextForCompositorOGL() const {
744 * Check the blocklist for a feature. Returns false if the feature is blocked
745 * with an appropriate message and failure ID.
747 static bool IsGfxInfoStatusOkay(int32_t aFeature
, nsCString
* aOutMessage
,
748 nsCString
& aFailureId
);
750 const gfxSkipChars
& EmptySkipChars() const { return kEmptySkipChars
; }
753 * Returns a buffer containing the CMS output profile data. The way this
754 * is obtained is platform-specific.
756 virtual nsTArray
<uint8_t> GetPlatformCMSOutputProfileData();
759 * Return information on how child processes should initialize graphics
762 virtual void BuildContentDeviceData(mozilla::gfx::ContentDeviceData
* aOut
);
765 * Imports settings from the GPU process. This should only be called through
766 * GPUProcessManager, in the UI process.
768 virtual void ImportGPUDeviceData(const mozilla::gfx::GPUDeviceData
& aData
);
770 bool HasVariationFontSupport() const { return mHasVariationFontSupport
; }
772 bool HasNativeColrFontSupport() const { return mHasNativeColrFontSupport
; }
774 // you probably want to use gfxVars::UseWebRender() instead of this
775 static bool WebRenderPrefEnabled();
776 // you probably want to use gfxVars::UseWebRender() instead of this
777 static bool WebRenderEnvvarEnabled();
779 static const char* WebRenderResourcePathOverride();
781 // Returns true if we would like to keep the GPU process if possible.
782 static bool FallbackFromAcceleration(mozilla::gfx::FeatureStatus aStatus
,
783 const char* aMessage
,
784 const nsACString
& aFailureId
);
786 void NotifyFrameStats(nsTArray
<mozilla::layers::FrameStats
>&& aFrameStats
);
788 virtual void OnMemoryPressure(
789 mozilla::layers::MemoryPressureReason aWhy
) override
;
791 virtual void EnsureDevicesInitialized(){};
792 virtual bool DevicesInitialized() { return true; };
794 virtual bool UseDMABufWebGL() { return false; }
795 virtual bool IsWaylandDisplay() { return false; }
797 static uint32_t TargetFrameRate();
799 static bool UseDesktopZoomingScrollbars();
803 virtual ~gfxPlatform();
805 virtual void InitAcceleration();
806 virtual void InitWebRenderConfig();
807 virtual void InitWebGLConfig();
808 virtual void InitWebGPUConfig();
810 virtual void GetPlatformDisplayInfo(mozilla::widget::InfoObject
& aObj
) {}
813 * Called immediately before deleting the gfxPlatform object.
815 virtual void WillShutdown();
818 * Initialized hardware vsync based on each platform.
820 virtual already_AddRefed
<mozilla::gfx::VsyncSource
>
821 CreateHardwareVsyncSource();
823 // Returns whether or not layers should be accelerated by default on this
825 virtual bool AccelerateLayersByDefault();
827 // Returns preferences of canvas and content backends.
828 virtual BackendPrefsData
GetBackendPrefs() const;
831 * Initialise the preferred and fallback canvas backends
832 * aBackendBitmask specifies the backends which are acceptable to the caller.
833 * The backend used is determined by aBackendBitmask and the order specified
834 * by the gfx.canvas.azure.backends pref.
836 void InitBackendPrefs(BackendPrefsData
&& aPrefsData
);
839 * Content-process only. Requests device preferences from the parent process
840 * and updates any cached settings.
842 void FetchAndImportContentDeviceData();
843 virtual void ImportContentDeviceData(
844 const mozilla::gfx::ContentDeviceData
& aData
);
847 * Returns the contents of the file pointed to by the
848 * gfx.color_management.display_profile pref, if set.
849 * Returns an empty array if not set, or if an error occurs
851 nsTArray
<uint8_t> GetPrefCMSOutputProfileData();
854 * If inside a child process and currently being initialized by the
855 * SetXPCOMProcessAttributes message, this can be used by subclasses to
856 * retrieve the ContentDeviceData passed by the message
858 * If not currently being initialized, will return nullptr. In this case,
859 * child should send a sync message to ask parent for color profile
861 const mozilla::gfx::ContentDeviceData
* GetInitContentDeviceData();
864 * Increase the global device counter after a device has been removed/reset.
866 void BumpDeviceCounter();
869 * returns the first backend named in the pref gfx.canvas.azure.backends
870 * which is a component of aBackendBitmask, a bitmask of backend types
872 static mozilla::gfx::BackendType
GetCanvasBackendPref(
873 uint32_t aBackendBitmask
);
876 * returns the first backend named in the pref gfx.content.azure.backend
877 * which is a component of aBackendBitmask, a bitmask of backend types
879 static mozilla::gfx::BackendType
GetContentBackendPref(
880 uint32_t& aBackendBitmask
);
883 * Will return the first backend named in aBackendPrefName
884 * allowed by aBackendBitmask, a bitmask of backend types.
885 * It also modifies aBackendBitmask to only include backends that are
886 * allowed given the prefs.
888 static mozilla::gfx::BackendType
GetBackendPref(const char* aBackendPrefName
,
889 uint32_t& aBackendBitmask
);
891 * Decode the backend enumberation from a string.
893 static mozilla::gfx::BackendType
BackendTypeForName(const nsCString
& aName
);
895 virtual bool CanUseHardwareVideoDecoding();
897 virtual bool CheckVariationFontSupport() = 0;
899 int8_t mAllowDownloadableFonts
;
900 int8_t mGraphiteShapingEnabled
;
901 int8_t mOpenTypeSVGEnabled
;
903 int8_t mBidiNumeralOption
;
905 // whether to always search font cmaps globally
906 // when doing system font fallback
907 int8_t mFallbackUsesCmaps
;
909 // Whether the platform supports rendering OpenType font variations
910 bool mHasVariationFontSupport
;
912 // Whether the platform font APIs have native support for COLR fonts.
913 // Set to true during initialization on platforms that implement this.
914 bool mHasNativeColrFontSupport
= false;
916 // max character limit for words in word cache
917 int32_t mWordCacheCharLimit
;
919 // max number of entries in word cache
920 int32_t mWordCacheMaxEntries
;
922 // Hardware vsync source. Only valid on parent process
923 RefPtr
<mozilla::gfx::VsyncSource
> mVsyncSource
;
925 RefPtr
<mozilla::gfx::DrawTarget
> mScreenReferenceDrawTarget
;
933 static void InitOpenGLConfig();
935 static mozilla::Atomic
<bool, mozilla::MemoryOrdering::ReleaseAcquire
>
937 static CMSMode gCMSMode
;
939 // These two may point to the same profile
940 static qcms_profile
* gCMSOutputProfile
;
941 static qcms_profile
* gCMSsRGBProfile
;
943 static qcms_transform
* gCMSRGBTransform
;
944 static qcms_transform
* gCMSInverseRGBTransform
;
945 static qcms_transform
* gCMSRGBATransform
;
946 static qcms_transform
* gCMSBGRATransform
;
948 inline static void EnsureCMSInitialized() {
949 if (MOZ_UNLIKELY(!gCMSInitialized
)) {
954 static void InitializeCMS();
955 static void ShutdownCMS();
958 * Calling this function will compute and set the ideal tile size for the
959 * platform. This will only have an effect in the parent process; child
960 * processes should be updated via SetTileSize to match the value computed in
963 void ComputeTileSize();
966 * This uses nsIScreenManager to determine the screen size and color depth
968 void PopulateScreenInfo();
970 void InitCompositorAccelerationPrefs();
971 void InitGPUProcessPrefs();
972 virtual void InitPlatformGPUProcessPrefs() {}
974 // Gather telemetry data about the Gfx Platform and send it
975 static void ReportTelemetry();
977 static bool IsDXInterop2Blocked();
978 static bool IsDXNV12Blocked();
979 static bool IsDXP010Blocked();
980 static bool IsDXP016Blocked();
982 RefPtr
<gfxASurface
> mScreenReferenceSurface
;
983 RefPtr
<mozilla::layers::MemoryPressureObserver
> mMemoryPressureObserver
;
985 // The preferred draw target backend to use for canvas
986 mozilla::gfx::BackendType mPreferredCanvasBackend
;
987 // The fallback draw target backend to use for canvas, if the preferred
989 mozilla::gfx::BackendType mFallbackCanvasBackend
;
990 // The backend to use for content
991 mozilla::gfx::BackendType mContentBackend
;
992 // The backend to use when we need it not to be accelerated.
993 mozilla::gfx::BackendType mSoftwareBackend
;
994 // Bitmask of backend types we can use to render content
995 uint32_t mContentBackendBitmask
;
997 mozilla::widget::GfxInfoCollector
<gfxPlatform
> mAzureCanvasBackendCollector
;
998 mozilla::widget::GfxInfoCollector
<gfxPlatform
> mApzSupportCollector
;
999 mozilla::widget::GfxInfoCollector
<gfxPlatform
> mTilesInfoCollector
;
1000 mozilla::widget::GfxInfoCollector
<gfxPlatform
> mFrameStatsCollector
;
1001 mozilla::widget::GfxInfoCollector
<gfxPlatform
> mCMSInfoCollector
;
1002 mozilla::widget::GfxInfoCollector
<gfxPlatform
> mDisplayInfoCollector
;
1004 nsTArray
<mozilla::layers::FrameStats
> mFrameStats
;
1006 // Backend that we are compositing with. NONE, if no compositor has been
1008 mozilla::layers::LayersBackend mCompositorBackend
;
1010 int32_t mScreenDepth
;
1011 mozilla::gfx::IntSize mScreenSize
;
1013 // An instance of gfxSkipChars which is empty. It is used as the
1014 // basis for error-case iterators.
1015 const gfxSkipChars kEmptySkipChars
;
1018 #endif /* GFX_PLATFORM_H */