Merge mozilla-central to autoland. CLOSED TREE
[gecko.git] / gfx / thebes / gfxPlatform.h
blob452e7208b42466957c57f530734c888e235d4185
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 #ifndef GFX_PLATFORM_H
7 #define GFX_PLATFORM_H
9 #include "mozilla/FontPropertyTypes.h"
10 #include "mozilla/gfx/Types.h"
11 #include "mozilla/intl/UnicodeScriptCodes.h"
12 #include "nsTArray.h"
13 #include "nsString.h"
14 #include "nsCOMPtr.h"
16 #include "gfxTelemetry.h"
17 #include "gfxTypes.h"
18 #include "gfxSkipChars.h"
20 #include "qcms.h"
22 #include "mozilla/RefPtr.h"
23 #include "GfxInfoCollector.h"
25 #include "mozilla/Maybe.h"
26 #include "mozilla/layers/CompositorTypes.h"
27 #include "mozilla/layers/LayersTypes.h"
28 #include "mozilla/layers/MemoryPressureObserver.h"
29 #include "mozilla/layers/OverlayInfo.h"
31 class gfxASurface;
32 class gfxFont;
33 class gfxFontGroup;
34 struct gfxFontStyle;
35 class gfxUserFontSet;
36 class gfxFontEntry;
37 class gfxPlatformFontList;
38 class gfxTextRun;
39 class nsIURI;
40 class nsAtom;
41 class nsIObserver;
42 class nsPresContext;
43 class SRGBOverrideObserver;
44 class gfxTextPerfMetrics;
45 typedef struct FT_LibraryRec_* FT_Library;
47 namespace mozilla {
48 struct StyleFontFamilyList;
49 class LogModule;
50 class VsyncDispatcher;
51 namespace layers {
52 class FrameStats;
54 namespace gfx {
55 class DrawTarget;
56 class SourceSurface;
57 class DataSourceSurface;
58 class ScaledFont;
59 class VsyncSource;
60 class SoftwareVsyncSource;
61 class ContentDeviceData;
62 class GPUDeviceData;
63 class FeatureState;
65 inline uint32_t BackendTypeBit(BackendType b) { return 1 << uint8_t(b); }
67 } // namespace gfx
68 namespace dom {
69 class SystemFontListEntry;
70 class SystemFontList;
71 } // namespace dom
72 } // namespace mozilla
74 #define MOZ_PERFORMANCE_WARNING(module, ...) \
75 do { \
76 if (gfxPlatform::PerfWarnings()) { \
77 printf_stderr("[" module "] " __VA_ARGS__); \
78 } \
79 } while (0)
81 enum class CMSMode : int32_t {
82 Off = 0, // No color management
83 All = 1, // Color manage everything
84 TaggedOnly = 2, // Color manage tagged Images Only
85 AllCount = 3
88 enum eGfxLog {
89 // all font enumerations, localized names, fullname/psnames, cmap loads
90 eGfxLog_fontlist = 0,
91 // timing info on font initialization
92 eGfxLog_fontinit = 1,
93 // dump text runs, font matching, system fallback for content
94 eGfxLog_textrun = 2,
95 // dump text runs, font matching, system fallback for chrome
96 eGfxLog_textrunui = 3,
97 // dump cmap coverage data as they are loaded
98 eGfxLog_cmapdata = 4,
99 // text perf data
100 eGfxLog_textperf = 5
103 // Used during font matching to express a preference, if any, for whether
104 // to use a font that will present a color or monochrome glyph.
105 enum class eFontPresentation : uint8_t {
106 // Character does not have the emoji property, so no special heuristics
107 // apply during font selection.
108 Any = 0,
109 // Character is potentially emoji, but Text-style presentation has been
110 // explicitly requested using VS15.
111 Text = 1,
112 // Character has Emoji-style presentation by default (but an author-
113 // provided webfont will be used even if it is not color).
114 EmojiDefault = 2,
115 // Character explicitly requires Emoji-style presentation due to VS16 or
116 // skin-tone codepoint.
117 EmojiExplicit = 3
120 inline bool PrefersColor(eFontPresentation aPresentation) {
121 return aPresentation >= eFontPresentation::EmojiDefault;
124 // when searching through pref langs, max number of pref langs
125 const uint32_t kMaxLenPrefLangList = 32;
127 #define UNINITIALIZED_VALUE (-1)
129 inline const char* GetBackendName(mozilla::gfx::BackendType aBackend) {
130 switch (aBackend) {
131 case mozilla::gfx::BackendType::DIRECT2D:
132 return "direct2d";
133 case mozilla::gfx::BackendType::CAIRO:
134 return "cairo";
135 case mozilla::gfx::BackendType::SKIA:
136 return "skia";
137 case mozilla::gfx::BackendType::RECORDING:
138 return "recording";
139 case mozilla::gfx::BackendType::DIRECT2D1_1:
140 return "direct2d 1.1";
141 case mozilla::gfx::BackendType::WEBRENDER_TEXT:
142 return "webrender text";
143 case mozilla::gfx::BackendType::NONE:
144 return "none";
145 case mozilla::gfx::BackendType::WEBGL:
146 return "webgl";
147 case mozilla::gfx::BackendType::BACKEND_LAST:
148 return "invalid";
150 MOZ_CRASH("Incomplete switch");
153 enum class DeviceResetReason {
154 OK = 0, // No reset.
155 HUNG, // Windows specific, guilty device reset.
156 REMOVED, // Windows specific, device removed or driver upgraded.
157 RESET, // Guilty device reset.
158 DRIVER_ERROR, // Innocent device reset.
159 INVALID_CALL, // Windows specific, guilty device reset.
160 OUT_OF_MEMORY,
161 FORCED_RESET, // Simulated device reset.
162 OTHER, // Unrecognized reason for device reset.
163 D3D9_RESET, // Windows specific, not used.
164 NVIDIA_VIDEO, // Linux specific, NVIDIA video memory was reset.
165 UNKNOWN, // GL specific, unknown if guilty or innocent.
168 enum class ForcedDeviceResetReason {
169 OPENSHAREDHANDLE = 0,
170 COMPOSITOR_UPDATED,
173 struct BackendPrefsData {
174 uint32_t mCanvasBitmask = 0;
175 mozilla::gfx::BackendType mCanvasDefault = mozilla::gfx::BackendType::NONE;
176 uint32_t mContentBitmask = 0;
177 mozilla::gfx::BackendType mContentDefault = mozilla::gfx::BackendType::NONE;
180 class gfxPlatform : public mozilla::layers::MemoryPressureListener {
181 friend class SRGBOverrideObserver;
183 public:
184 typedef mozilla::StretchRange StretchRange;
185 typedef mozilla::SlantStyleRange SlantStyleRange;
186 typedef mozilla::WeightRange WeightRange;
187 typedef mozilla::gfx::sRGBColor sRGBColor;
188 typedef mozilla::gfx::DeviceColor DeviceColor;
189 typedef mozilla::gfx::DataSourceSurface DataSourceSurface;
190 typedef mozilla::gfx::DrawTarget DrawTarget;
191 typedef mozilla::gfx::IntSize IntSize;
192 typedef mozilla::gfx::SourceSurface SourceSurface;
193 typedef mozilla::intl::Script Script;
196 * Return a pointer to the current active platform.
197 * This is a singleton; it contains mostly convenience
198 * functions to obtain platform-specific objects.
200 static gfxPlatform* GetPlatform();
203 * Returns whether or not graphics has been initialized yet. This is
204 * intended for Telemetry where we don't necessarily want to initialize
205 * graphics just to observe its state.
207 static bool Initialized();
210 * Shut down Thebes.
211 * Init() arranges for this to be called at an appropriate time.
213 static void Shutdown();
216 * Initialize gfxPlatform (if not already done) in a child process, with
217 * the provided ContentDeviceData.
219 static void InitChild(const mozilla::gfx::ContentDeviceData& aData);
221 static void InitLayersIPC();
222 static void ShutdownLayersIPC();
225 * Initialize ScrollMetadata statics. Does not depend on gfxPlatform.
227 static void InitNullMetadata();
229 static int32_t MaxTextureSize();
230 static int32_t MaxAllocSize();
231 static void InitMoz2DLogging();
233 static bool IsHeadless();
235 static bool UseRemoteCanvas();
237 static bool IsBackendAccelerated(
238 const mozilla::gfx::BackendType aBackendType);
240 static bool CanMigrateMacGPUs();
243 * Create an offscreen surface of the given dimensions
244 * and image format.
246 virtual already_AddRefed<gfxASurface> CreateOffscreenSurface(
247 const IntSize& aSize, gfxImageFormat aFormat) = 0;
250 * Beware that this method may return DrawTargets which are not fully
251 * supported on the current platform and might fail silently in subtle ways.
252 * This is a massive potential footgun. You should only use these methods for
253 * canvas drawing really. Use extreme caution if you use them for content
254 * where you are not 100% sure we support the DrawTarget we get back. See
255 * SupportsAzureContentForDrawTarget.
257 static already_AddRefed<DrawTarget> CreateDrawTargetForSurface(
258 gfxASurface* aSurface, const mozilla::gfx::IntSize& aSize);
261 * Creates a SourceSurface for a gfxASurface. This function does no caching,
262 * so the caller should cache the gfxASurface if it will be used frequently.
263 * The returned surface keeps a reference to aTarget, so it is OK to keep the
264 * surface, even if aTarget changes.
265 * aTarget should not keep a reference to the returned surface because that
266 * will cause a cycle.
268 * This function is static so that it can be accessed from outside the main
269 * process.
271 * aIsPlugin is used to tell the backend that they can optimize this surface
272 * specifically because it's used for a plugin. This is mostly for Skia.
274 static already_AddRefed<SourceSurface> GetSourceSurfaceForSurface(
275 RefPtr<mozilla::gfx::DrawTarget> aTarget, gfxASurface* aSurface,
276 bool aIsPlugin = false);
278 static void ClearSourceSurfaceForSurface(gfxASurface* aSurface);
280 static already_AddRefed<DataSourceSurface> GetWrappedDataSourceSurface(
281 gfxASurface* aSurface);
283 already_AddRefed<DrawTarget> CreateOffscreenContentDrawTarget(
284 const mozilla::gfx::IntSize& aSize, mozilla::gfx::SurfaceFormat aFormat,
285 bool aFallback = false);
287 already_AddRefed<DrawTarget> CreateOffscreenCanvasDrawTarget(
288 const mozilla::gfx::IntSize& aSize, mozilla::gfx::SurfaceFormat aFormat);
290 already_AddRefed<DrawTarget> CreateSimilarSoftwareDrawTarget(
291 DrawTarget* aDT, const IntSize& aSize,
292 mozilla::gfx::SurfaceFormat aFormat);
294 static already_AddRefed<DrawTarget> CreateDrawTargetForData(
295 unsigned char* aData, const mozilla::gfx::IntSize& aSize, int32_t aStride,
296 mozilla::gfx::SurfaceFormat aFormat, bool aUninitialized = false);
299 * Returns true if we should use Azure to render content with aTarget. For
300 * example, it is possible that we are using Direct2D for rendering and thus
301 * using Azure. But we want to render to a CairoDrawTarget, in which case
302 * SupportsAzureContent will return true but SupportsAzureContentForDrawTarget
303 * will return false.
305 bool SupportsAzureContentForDrawTarget(mozilla::gfx::DrawTarget* aTarget);
307 bool SupportsAzureContentForType(mozilla::gfx::BackendType aType) {
308 return BackendTypeBit(aType) & mContentBackendBitmask;
311 static bool AsyncPanZoomEnabled();
313 const char* GetAzureCanvasBackend() const;
314 const char* GetAzureContentBackend() const;
316 void GetAzureBackendInfo(mozilla::widget::InfoObject& aObj);
317 void GetApzSupportInfo(mozilla::widget::InfoObject& aObj);
318 void GetFrameStats(mozilla::widget::InfoObject& aObj);
319 void GetCMSSupportInfo(mozilla::widget::InfoObject& aObj);
320 void GetDisplayInfo(mozilla::widget::InfoObject& aObj);
321 void GetOverlayInfo(mozilla::widget::InfoObject& aObj);
322 void GetSwapChainInfo(mozilla::widget::InfoObject& aObj);
324 // Get the default content backend that will be used with the default
325 // compositor. If the compositor is known when calling this function,
326 // GetContentBackendFor() should be called instead.
327 mozilla::gfx::BackendType GetDefaultContentBackend() const {
328 return mContentBackend;
331 /// Return the software backend to use by default.
332 mozilla::gfx::BackendType GetSoftwareBackend() { return mSoftwareBackend; }
334 // Return the best content backend available that is compatible with the
335 // given layers backend.
336 virtual mozilla::gfx::BackendType GetContentBackendFor(
337 mozilla::layers::LayersBackend aLayers) {
338 return mContentBackend;
341 virtual mozilla::gfx::BackendType GetPreferredCanvasBackend() {
342 return mPreferredCanvasBackend;
344 mozilla::gfx::BackendType GetFallbackCanvasBackend() {
345 return mFallbackCanvasBackend;
349 * Font bits
353 * Fill aListOfFonts with the results of querying the list of font names
354 * that correspond to the given language group or generic font family
355 * (or both, or neither).
357 virtual nsresult GetFontList(nsAtom* aLangGroup,
358 const nsACString& aGenericFamily,
359 nsTArray<nsString>& aListOfFonts);
362 * Fill aFontList with a list of SystemFontListEntry records for the
363 * available fonts on the platform; used to pass the list from chrome to
364 * content process. Currently implemented only on MacOSX and Linux.
366 virtual void ReadSystemFontList(mozilla::dom::SystemFontList*){};
369 * Rebuilds the system font lists (if aFullRebuild is true), or just notifies
370 * content that the list has changed but existing memory mappings are still
371 * valid (aFullRebuild is false).
373 nsresult UpdateFontList(bool aFullRebuild = true);
376 * Create the platform font-list object (gfxPlatformFontList concrete
377 * subclass). This function is responsible to create the appropriate subclass
378 * of gfxPlatformFontList *and* to call its InitFontList() method.
380 virtual bool CreatePlatformFontList() = 0;
383 * Resolving a font name to family name. The result MUST be in the result of
384 * GetFontList(). If the name doesn't in the system, aFamilyName will be empty
385 * string, but not failed.
387 void GetStandardFamilyName(const nsCString& aFontName,
388 nsACString& aFamilyName);
391 * Returns default font name (localized family name) for aLangGroup and
392 * aGenericFamily. The result is typically the first font in
393 * font.name-list.<aGenericFamily>.<aLangGroup>. However, if it's not
394 * available in the system, this may return second or later font in the
395 * pref. If there are no available fonts in the pref, returns empty string.
397 nsAutoCString GetDefaultFontName(const nsACString& aLangGroup,
398 const nsACString& aGenericFamily);
401 * Look up a local platform font using the full font face name.
402 * (Needed to support @font-face src local().)
403 * Ownership of the returned gfxFontEntry is passed to the caller,
404 * who must either AddRef() or delete.
406 gfxFontEntry* LookupLocalFont(nsPresContext* aPresContext,
407 const nsACString& aFontName,
408 WeightRange aWeightForEntry,
409 StretchRange aStretchForEntry,
410 SlantStyleRange aStyleForEntry);
413 * Activate a platform font. (Needed to support @font-face src url().)
414 * aFontData is a NS_Malloc'ed block that must be freed by this function
415 * (or responsibility passed on) when it is no longer needed; the caller
416 * will NOT free it.
417 * Ownership of the returned gfxFontEntry is passed to the caller,
418 * who must either AddRef() or delete.
420 gfxFontEntry* MakePlatformFont(const nsACString& aFontName,
421 WeightRange aWeightForEntry,
422 StretchRange aStretchForEntry,
423 SlantStyleRange aStyleForEntry,
424 const uint8_t* aFontData, uint32_t aLength);
427 * Whether to allow downloadable fonts via @font-face rules
429 bool DownloadableFontsEnabled();
432 * True when hinting should be enabled. This setting shouldn't
433 * change per gecko process, while the process is live. If so the
434 * results are not defined.
436 * NB: this bit is only honored by the FT2 backend, currently.
438 virtual bool FontHintingEnabled() { return true; }
441 * True when zooming should not require reflow, so glyph metrics and
442 * positioning should not be adjusted for device pixels.
443 * If this is TRUE, then FontHintingEnabled() should be FALSE,
444 * but the converse is not necessarily required;
446 * Like FontHintingEnabled (above), this setting shouldn't
447 * change per gecko process, while the process is live. If so the
448 * results are not defined.
450 * NB: this bit is only honored by the FT2 backend, currently.
452 virtual bool RequiresLinearZoom() { return false; }
455 * Whether the frame->StyleFont().mFont.smoothing field is respected by
456 * text rendering on this platform.
458 virtual bool RespectsFontStyleSmoothing() const { return false; }
461 * Whether to check all font cmaps during system font fallback
463 bool UseCmapsDuringSystemFallback();
466 * Whether to render SVG glyphs within an OpenType font wrapper
468 bool OpenTypeSVGEnabled();
471 * Max character length of words in the word cache
473 uint32_t WordCacheCharLimit();
476 * Max number of entries in word cache
478 uint32_t WordCacheMaxEntries();
481 * Whether to use the SIL Graphite rendering engine
482 * (for fonts that include Graphite tables)
484 bool UseGraphiteShaping();
486 // Check whether format is supported on a platform (if unclear, returns true).
487 // Default implementation checks for "common" formats that we support across
488 // all platforms, but individual platform implementations may override.
489 virtual bool IsFontFormatSupported(
490 mozilla::StyleFontFaceSourceFormatKeyword aFormatHint,
491 mozilla::StyleFontFaceSourceTechFlags aTechFlags);
493 bool IsKnownIconFontFamily(const nsAtom* aFamilyName) const;
495 virtual bool DidRenderingDeviceReset(
496 DeviceResetReason* aResetReason = nullptr) {
497 return false;
500 // returns a list of commonly used fonts for a given character
501 // these are *possible* matches, no cmap-checking is done at this level
502 virtual void GetCommonFallbackFonts(uint32_t /*aCh*/, Script /*aRunScript*/,
503 eFontPresentation /*aPresentation*/,
504 nsTArray<const char*>& /*aFontList*/) {
505 // platform-specific override, by default do nothing
508 // Are we in safe mode?
509 static bool InSafeMode();
511 static bool OffMainThreadCompositingEnabled();
513 void UpdateCanUseHardwareVideoDecoding();
516 * Are we going to try color management?
518 static CMSMode GetCMSMode() {
519 EnsureCMSInitialized();
520 return gCMSMode;
524 * Used only for testing. Override the pref setting.
526 static void SetCMSModeOverride(CMSMode aMode);
529 * Determines the rendering intent for color management.
531 * If the value in the pref gfx.color_management.rendering_intent is a
532 * valid rendering intent as defined in gfx/qcms/qcms.h, that
533 * value is returned. Otherwise, -1 is returned and the embedded intent
534 * should be used.
536 * See bug 444014 for details.
538 static int GetRenderingIntent();
541 * Convert a pixel using a cms transform in an endian-aware manner.
543 static DeviceColor TransformPixel(const sRGBColor& in,
544 qcms_transform* transform);
547 * Return the output device ICC profile.
549 static qcms_profile* GetCMSOutputProfile() {
550 EnsureCMSInitialized();
551 return gCMSOutputProfile;
555 * Return the sRGB ICC profile.
557 static qcms_profile* GetCMSsRGBProfile() {
558 EnsureCMSInitialized();
559 return gCMSsRGBProfile;
563 * Return sRGB -> output device transform.
565 static qcms_transform* GetCMSRGBTransform() {
566 EnsureCMSInitialized();
567 return gCMSRGBTransform;
571 * Return output -> sRGB device transform.
573 static qcms_transform* GetCMSInverseRGBTransform() {
574 MOZ_ASSERT(gCMSInitialized);
575 return gCMSInverseRGBTransform;
579 * Return sRGBA -> output device transform.
581 static qcms_transform* GetCMSRGBATransform() {
582 MOZ_ASSERT(gCMSInitialized);
583 return gCMSRGBATransform;
587 * Return sBGRA -> output device transform.
589 static qcms_transform* GetCMSBGRATransform() {
590 MOZ_ASSERT(gCMSInitialized);
591 return gCMSBGRATransform;
595 * Return OS RGBA -> output device transform.
597 static qcms_transform* GetCMSOSRGBATransform();
600 * Return OS RGBA QCMS type.
602 static qcms_data_type GetCMSOSRGBAType();
604 virtual void FontsPrefsChanged(const char* aPref);
606 uint32_t GetBidiNumeralOption();
609 * Force all presContexts to reflow (and reframe if needed).
611 * This is used when something about platform settings changes that might have
612 * an effect on layout, such as font rendering settings that influence
613 * metrics, or installed fonts.
615 * By default it also broadcast it to child processes, but some callers might
616 * not need it if they implement their own notification.
618 enum class NeedsReframe : bool { No, Yes };
619 enum class BroadcastToChildren : bool { No, Yes };
620 static void ForceGlobalReflow(NeedsReframe,
621 BroadcastToChildren = BroadcastToChildren::Yes);
623 static void FlushFontAndWordCaches();
626 * Returns a 1x1 DrawTarget that can be used for measuring text etc. as
627 * it would measure if rendered on-screen. Guaranteed to return a
628 * non-null and valid DrawTarget.
630 RefPtr<mozilla::gfx::DrawTarget> ScreenReferenceDrawTarget();
632 static RefPtr<mozilla::gfx::DrawTarget>
633 ThreadLocalScreenReferenceDrawTarget();
635 virtual mozilla::gfx::SurfaceFormat Optimal2DFormatForContent(
636 gfxContentType aContent);
638 virtual gfxImageFormat OptimalFormatForContent(gfxContentType aContent);
640 virtual gfxImageFormat GetOffscreenFormat() {
641 return mozilla::gfx::SurfaceFormat::X8R8G8B8_UINT32;
645 * Returns a logger if one is available and logging is enabled
647 static mozilla::LogModule* GetLog(eGfxLog aWhichLog);
649 static void PurgeSkiaFontCache();
651 static bool UsesOffMainThreadCompositing();
654 * Returns the global vsync dispatcher. There is only one global vsync
655 * dispatcher and it stays around for the entire lifetime of the process.
656 * Must only be called in the parent process.
658 RefPtr<mozilla::VsyncDispatcher> GetGlobalVsyncDispatcher();
661 * True if layout rendering should use ASAP mode, which means
662 * the refresh driver and compositor should render ASAP.
663 * Used for talos testing purposes
665 static bool IsInLayoutAsapMode();
668 * Returns whether or not a custom vsync rate is set.
670 static bool ForceSoftwareVsync();
673 * Returns the software vsync rate to use.
675 static int GetSoftwareVsyncRate();
678 * Returns the default frame rate for the refresh driver / software vsync.
680 static int GetDefaultFrameRate();
683 * Update the frame rate (called e.g. after pref changes).
685 static void ReInitFrameRate(const char* aPrefIgnored, void* aDataIgnored);
688 * Update force subpixel AA quality setting (called after pref
689 * changes).
691 void UpdateForceSubpixelAAWherePossible();
694 * Used to test which input types are handled via APZ.
696 virtual bool SupportsApzWheelInput() const { return false; }
697 bool SupportsApzTouchInput() const;
698 bool SupportsApzDragInput() const;
699 bool SupportsApzKeyboardInput() const;
700 bool SupportsApzAutoscrolling() const;
701 bool SupportsApzZooming() const;
703 // If a device reset has occurred, schedule any necessary paints in the
704 // widget. This should only be used within nsRefreshDriver.
705 virtual void SchedulePaintIfDeviceReset() {}
708 * Helper method, creates a draw target for a specific Azure backend.
709 * Used by CreateOffscreenDrawTarget.
711 already_AddRefed<DrawTarget> CreateDrawTargetForBackend(
712 mozilla::gfx::BackendType aBackend, const mozilla::gfx::IntSize& aSize,
713 mozilla::gfx::SurfaceFormat aFormat);
716 * Wrapper around StaticPrefs::gfx_perf_warnings_enabled().
717 * Extracted into a function to avoid including StaticPrefs_gfx.h from this
718 * file.
720 static bool PerfWarnings();
722 static void DisableGPUProcess();
724 void NotifyCompositorCreated(mozilla::layers::LayersBackend aBackend);
725 mozilla::layers::LayersBackend GetCompositorBackend() const {
726 return mCompositorBackend;
729 virtual void CompositorUpdated() {}
731 // Plugin async drawing support.
732 virtual bool SupportsPluginDirectBitmapDrawing() { return false; }
734 // Some platforms don't support CompositorOGL in an unaccelerated OpenGL
735 // context. These platforms should return true here.
736 virtual bool RequiresAcceleratedGLContextForCompositorOGL() const {
737 return false;
741 * Check the blocklist for a feature. Returns false if the feature is blocked
742 * with an appropriate message and failure ID.
743 * */
744 static bool IsGfxInfoStatusOkay(int32_t aFeature, nsCString* aOutMessage,
745 nsCString& aFailureId);
747 const gfxSkipChars& EmptySkipChars() const { return kEmptySkipChars; }
750 * Returns a buffer containing the CMS output profile data. The way this
751 * is obtained is platform-specific.
753 virtual nsTArray<uint8_t> GetPlatformCMSOutputProfileData() {
754 return GetPrefCMSOutputProfileData();
758 * Return information on how child processes should initialize graphics
759 * devices.
761 virtual void BuildContentDeviceData(mozilla::gfx::ContentDeviceData* aOut);
764 * Imports settings from the GPU process. This should only be called through
765 * GPUProcessManager, in the UI process.
767 virtual void ImportGPUDeviceData(const mozilla::gfx::GPUDeviceData& aData);
769 void SetOverlayInfo(const mozilla::layers::OverlayInfo& aInfo) {
770 mOverlayInfo = mozilla::Some(aInfo);
773 void SetSwapChainInfo(const mozilla::layers::SwapChainInfo& aInfo) {
774 mSwapChainInfo = mozilla::Some(aInfo);
777 static void DisableRemoteCanvas();
779 static bool HasVariationFontSupport();
781 // you probably want to use gfxVars::UseWebRender() instead of this
782 static bool WebRenderPrefEnabled();
783 // you probably want to use gfxVars::UseWebRender() instead of this
784 static bool WebRenderEnvvarEnabled();
786 static const char* WebRenderResourcePathOverride();
788 // Returns true if we would like to keep the GPU process if possible.
789 // If aCrashAfterFinalFallback is true then crash if we have already
790 // exhausted all of our fallback options. Otherwise we remain on the final
791 // fallback configuration.
792 static bool FallbackFromAcceleration(mozilla::gfx::FeatureStatus aStatus,
793 const char* aMessage,
794 const nsACString& aFailureId,
795 bool aCrashAfterFinalFallback = false);
797 void NotifyFrameStats(nsTArray<mozilla::layers::FrameStats>&& aFrameStats);
799 virtual void OnMemoryPressure(
800 mozilla::layers::MemoryPressureReason aWhy) override;
802 virtual void EnsureDevicesInitialized(){};
803 virtual bool DevicesInitialized() { return true; };
805 virtual bool IsWaylandDisplay() { return false; }
807 static uint32_t TargetFrameRate();
809 static bool UseDesktopZoomingScrollbars();
811 protected:
812 gfxPlatform();
813 virtual ~gfxPlatform();
815 virtual void InitAcceleration();
816 virtual void InitWebRenderConfig();
817 void InitHardwareVideoConfig();
818 virtual void InitWebGLConfig();
819 virtual void InitWebGPUConfig();
820 virtual void InitWindowOcclusionConfig();
821 void InitBackdropFilterConfig();
822 void InitAcceleratedCanvas2DConfig();
824 virtual void GetPlatformDisplayInfo(mozilla::widget::InfoObject& aObj) {}
827 * Called immediately before deleting the gfxPlatform object.
829 virtual void WillShutdown();
831 // Return a hardware vsync source for this platform.
832 already_AddRefed<mozilla::gfx::VsyncSource> GetGlobalHardwareVsyncSource();
834 // Return a software vsync source (which uses a timer internally).
835 // Can be used as a fallback for platforms without hardware vsync,
836 // and when the layout.frame_rate pref is set to a non-negative value.
837 already_AddRefed<mozilla::gfx::VsyncSource> GetSoftwareVsyncSource();
839 // Create the platform-specific global vsync source. Can fall back to
840 // GetSoftwareVsyncSource().
841 virtual already_AddRefed<mozilla::gfx::VsyncSource>
842 CreateGlobalHardwareVsyncSource() = 0;
844 // Returns whether or not layers should be accelerated by default on this
845 // platform.
846 virtual bool AccelerateLayersByDefault();
848 // Returns preferences of canvas and content backends.
849 virtual BackendPrefsData GetBackendPrefs() const;
852 * Initialise the preferred and fallback canvas backends
853 * aBackendBitmask specifies the backends which are acceptable to the caller.
854 * The backend used is determined by aBackendBitmask and the order specified
855 * by the gfx.canvas.azure.backends pref.
857 void InitBackendPrefs(BackendPrefsData&& aPrefsData);
860 * Content-process only. Updates device preferences from the parent process,
861 * if we've received any.
863 void ImportCachedContentDeviceData();
864 virtual void ImportContentDeviceData(
865 const mozilla::gfx::ContentDeviceData& aData);
867 public:
869 * Returns the contents of the file pointed to by the
870 * gfx.color_management.display_profile pref, if set.
871 * Returns an empty array if not set, or if an error occurs
873 static nsTArray<uint8_t> GetPrefCMSOutputProfileData();
875 protected:
877 * If inside a child process and currently being initialized by the
878 * SetXPCOMProcessAttributes message, this can be used by subclasses to
879 * retrieve the ContentDeviceData passed by the message
881 * If not currently being initialized, will return nullptr. In this case,
882 * child should send a sync message to ask parent for color profile
884 const mozilla::gfx::ContentDeviceData* GetInitContentDeviceData();
887 * If inside a child process and have ever received a
888 * SetXPCOMProcessAttributes message, this contains the cmsOutputProfileData
889 * from that message.
891 mozilla::Maybe<nsTArray<uint8_t>>& GetCMSOutputProfileData();
894 * Increase the global device counter after a device has been removed/reset.
896 void BumpDeviceCounter();
899 * returns the first backend named in the pref gfx.canvas.azure.backends
900 * which is a component of aBackendBitmask, a bitmask of backend types
902 static mozilla::gfx::BackendType GetCanvasBackendPref(
903 uint32_t aBackendBitmask);
906 * returns the first backend named in the pref gfx.content.azure.backend
907 * which is a component of aBackendBitmask, a bitmask of backend types
909 static mozilla::gfx::BackendType GetContentBackendPref(
910 uint32_t& aBackendBitmask);
913 * Will return the first backend named in aBackendPrefName
914 * allowed by aBackendBitmask, a bitmask of backend types.
915 * It also modifies aBackendBitmask to only include backends that are
916 * allowed given the prefs.
918 static mozilla::gfx::BackendType GetBackendPref(const char* aBackendPrefName,
919 uint32_t& aBackendBitmask);
921 * Decode the backend enumberation from a string.
923 static mozilla::gfx::BackendType BackendTypeForName(const nsCString& aName);
925 virtual bool CanUseHardwareVideoDecoding();
927 int8_t mAllowDownloadableFonts;
929 // Whether the platform supports rendering OpenType font variations
930 static std::atomic<int8_t> sHasVariationFontSupport;
932 // The global vsync dispatcher. Only non-null in the parent process.
933 // Its underlying VsyncSource is either mGlobalHardwareVsyncSource
934 // or mSoftwareVsyncSource.
935 RefPtr<mozilla::VsyncDispatcher> mVsyncDispatcher;
937 // Cached software vsync source. Only non-null in the parent process,
938 // and only after the first time GetHardwareVsyncSource has been called.
939 RefPtr<mozilla::gfx::VsyncSource> mGlobalHardwareVsyncSource;
941 // Cached software vsync source. Only non-null in the parent process,
942 // and only after the first time GetSoftwareVsyncSource has been called.
943 // Used as a fallback source if hardware vsync is not available,
944 // or when the layout.frame_rate pref is set.
945 RefPtr<mozilla::gfx::SoftwareVsyncSource> mSoftwareVsyncSource;
947 RefPtr<mozilla::gfx::DrawTarget> mScreenReferenceDrawTarget;
949 private:
951 * Start up Thebes.
953 static void Init();
955 static void InitOpenGLConfig();
957 static mozilla::Atomic<bool, mozilla::MemoryOrdering::ReleaseAcquire>
958 gCMSInitialized;
959 static CMSMode gCMSMode;
961 // These two may point to the same profile
962 static qcms_profile* gCMSOutputProfile;
963 static qcms_profile* gCMSsRGBProfile;
965 static qcms_transform* gCMSRGBTransform;
966 static qcms_transform* gCMSInverseRGBTransform;
967 static qcms_transform* gCMSRGBATransform;
968 static qcms_transform* gCMSBGRATransform;
970 inline static void EnsureCMSInitialized() {
971 if (MOZ_UNLIKELY(!gCMSInitialized)) {
972 InitializeCMS();
976 static void InitializeCMS();
977 static void ShutdownCMS();
980 * This uses nsIScreenManager to determine the primary screen color depth
982 void PopulateScreenInfo();
984 void InitCompositorAccelerationPrefs();
985 void InitGPUProcessPrefs();
986 virtual void InitPlatformGPUProcessPrefs() {}
988 // Gather telemetry data about the Gfx Platform and send it
989 static void ReportTelemetry();
991 static bool IsDXInterop2Blocked();
992 static bool IsDXNV12Blocked();
993 static bool IsDXP010Blocked();
994 static bool IsDXP016Blocked();
996 RefPtr<gfxASurface> mScreenReferenceSurface;
997 RefPtr<mozilla::layers::MemoryPressureObserver> mMemoryPressureObserver;
999 // The preferred draw target backend to use for canvas
1000 mozilla::gfx::BackendType mPreferredCanvasBackend;
1001 // The fallback draw target backend to use for canvas, if the preferred
1002 // backend fails
1003 mozilla::gfx::BackendType mFallbackCanvasBackend;
1004 // The backend to use for content
1005 mozilla::gfx::BackendType mContentBackend;
1006 // The backend to use when we need it not to be accelerated.
1007 mozilla::gfx::BackendType mSoftwareBackend;
1008 // Bitmask of backend types we can use to render content
1009 uint32_t mContentBackendBitmask;
1011 mozilla::widget::GfxInfoCollector<gfxPlatform> mAzureCanvasBackendCollector;
1012 mozilla::widget::GfxInfoCollector<gfxPlatform> mApzSupportCollector;
1013 mozilla::widget::GfxInfoCollector<gfxPlatform> mFrameStatsCollector;
1014 mozilla::widget::GfxInfoCollector<gfxPlatform> mCMSInfoCollector;
1015 mozilla::widget::GfxInfoCollector<gfxPlatform> mDisplayInfoCollector;
1016 mozilla::widget::GfxInfoCollector<gfxPlatform> mOverlayInfoCollector;
1017 mozilla::widget::GfxInfoCollector<gfxPlatform> mSwapChainInfoCollector;
1019 nsTArray<mozilla::layers::FrameStats> mFrameStats;
1021 // Backend that we are compositing with. NONE, if no compositor has been
1022 // created yet.
1023 mozilla::layers::LayersBackend mCompositorBackend;
1025 mozilla::Maybe<mozilla::layers::OverlayInfo> mOverlayInfo;
1026 mozilla::Maybe<mozilla::layers::SwapChainInfo> mSwapChainInfo;
1028 // An instance of gfxSkipChars which is empty. It is used as the
1029 // basis for error-case iterators.
1030 const gfxSkipChars kEmptySkipChars;
1033 CMSMode GfxColorManagementMode();
1035 #endif /* GFX_PLATFORM_H */