gfxPlatform.h (35600B)
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/. */ 5 6 #ifndef GFX_PLATFORM_H 7 #define GFX_PLATFORM_H 8 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" 15 16 #include "gfxTelemetry.h" 17 #include "gfxTypes.h" 18 #include "gfxSkipChars.h" 19 20 #include "qcms.h" 21 22 #include "mozilla/RefPtr.h" 23 #include "GfxInfoCollector.h" 24 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" 30 31 class FontVisibilityProvider; 32 class gfxASurface; 33 class gfxFont; 34 class gfxFontGroup; 35 struct gfxFontStyle; 36 class gfxUserFontSet; 37 class gfxFontEntry; 38 class gfxPlatformFontList; 39 class gfxTextRun; 40 class nsIURI; 41 class nsAtom; 42 class nsIObserver; 43 class SRGBOverrideObserver; 44 class gfxTextPerfMetrics; 45 typedef struct FT_LibraryRec_* FT_Library; 46 47 namespace mozilla { 48 struct StyleFontFamilyList; 49 class LogModule; 50 class VsyncDispatcher; 51 namespace layers { 52 class FrameStats; 53 } 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; 64 65 inline uint32_t BackendTypeBit(BackendType b) { return 1 << uint8_t(b); } 66 67 } // namespace gfx 68 namespace dom { 69 class SystemFontListEntry; 70 class SystemFontList; 71 } // namespace dom 72 } // namespace mozilla 73 74 #define MOZ_PERFORMANCE_WARNING(module, ...) \ 75 do { \ 76 if (gfxPlatform::PerfWarnings()) { \ 77 printf_stderr("[" module "] " __VA_ARGS__); \ 78 } \ 79 } while (0) 80 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 _ENUM_MAX = TaggedOnly 86 }; 87 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 101 }; 102 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 FontPresentation : 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 its default presentation is text. 110 TextDefault, 111 // Character is potentially emoji, but Text-style presentation has been 112 // explicitly requested using VS15. 113 TextExplicit, 114 // Character has Emoji-style presentation by default (but an author- 115 // provided webfont may be used even if it is not color). 116 EmojiDefault, 117 // Character explicitly requires Emoji-style presentation due to VS16 or 118 // skin-tone codepoint. 119 EmojiExplicit, 120 }; 121 122 inline bool PrefersColor(FontPresentation aPresentation) { 123 return aPresentation >= FontPresentation::EmojiDefault; 124 } 125 126 inline bool IsExplicitPresentation(FontPresentation aPresentation) { 127 return aPresentation == FontPresentation::TextExplicit || 128 aPresentation == FontPresentation::EmojiExplicit; 129 } 130 131 // when searching through pref langs, max number of pref langs 132 const uint32_t kMaxLenPrefLangList = 32; 133 134 #define UNINITIALIZED_VALUE (-1) 135 136 inline const char* GetBackendName(mozilla::gfx::BackendType aBackend) { 137 switch (aBackend) { 138 case mozilla::gfx::BackendType::CAIRO: 139 return "cairo"; 140 case mozilla::gfx::BackendType::SKIA: 141 return "skia"; 142 case mozilla::gfx::BackendType::RECORDING: 143 return "recording"; 144 case mozilla::gfx::BackendType::WEBRENDER_TEXT: 145 return "webrender text"; 146 case mozilla::gfx::BackendType::NONE: 147 return "none"; 148 case mozilla::gfx::BackendType::WEBGL: 149 return "webgl"; 150 case mozilla::gfx::BackendType::BACKEND_LAST: 151 return "invalid"; 152 } 153 MOZ_CRASH("Incomplete switch"); 154 } 155 156 struct BackendPrefsData { 157 uint32_t mCanvasBitmask = 0; 158 mozilla::gfx::BackendType mCanvasDefault = mozilla::gfx::BackendType::NONE; 159 uint32_t mContentBitmask = 0; 160 mozilla::gfx::BackendType mContentDefault = mozilla::gfx::BackendType::NONE; 161 }; 162 163 class gfxPlatform : public mozilla::layers::MemoryPressureListener { 164 friend class SRGBOverrideObserver; 165 166 public: 167 typedef mozilla::StretchRange StretchRange; 168 typedef mozilla::SlantStyleRange SlantStyleRange; 169 typedef mozilla::WeightRange WeightRange; 170 typedef mozilla::gfx::sRGBColor sRGBColor; 171 typedef mozilla::gfx::DeviceColor DeviceColor; 172 typedef mozilla::gfx::DataSourceSurface DataSourceSurface; 173 typedef mozilla::gfx::DrawTarget DrawTarget; 174 typedef mozilla::gfx::IntSize IntSize; 175 typedef mozilla::gfx::SourceSurface SourceSurface; 176 typedef mozilla::intl::Script Script; 177 178 /** 179 * Return a pointer to the current active platform. 180 * This is a singleton; it contains mostly convenience 181 * functions to obtain platform-specific objects. 182 */ 183 static gfxPlatform* GetPlatform() { 184 if (MOZ_UNLIKELY(!gPlatform)) { 185 Init(); 186 } 187 return gPlatform; 188 } 189 190 /** 191 * Returns whether or not graphics has been initialized yet. This is 192 * intended for Telemetry where we don't necessarily want to initialize 193 * graphics just to observe its state. 194 */ 195 static bool Initialized(); 196 197 /** 198 * Shut down Thebes. 199 * Init() arranges for this to be called at an appropriate time. 200 */ 201 static void Shutdown(); 202 203 /** 204 * Initialize gfxPlatform (if not already done) in a child process, with 205 * the provided ContentDeviceData. 206 */ 207 static void InitChild(const mozilla::gfx::ContentDeviceData& aData); 208 209 static void InitLayersIPC(); 210 static void ShutdownLayersIPC(); 211 212 /** 213 * Initialize ScrollMetadata statics. Does not depend on gfxPlatform. 214 */ 215 static void InitNullMetadata(); 216 217 static int32_t MaxTextureSize(); 218 static int32_t MaxAllocSize(); 219 static void InitMoz2DLogging(); 220 221 static void InitMemoryReportersForGPUProcess(); 222 223 static bool IsHeadless(); 224 225 static bool UseRemoteCanvas(); 226 227 static bool IsBackendAccelerated( 228 const mozilla::gfx::BackendType aBackendType); 229 230 /** 231 * Create an offscreen surface of the given dimensions 232 * and image format. 233 */ 234 virtual already_AddRefed<gfxASurface> CreateOffscreenSurface( 235 const IntSize& aSize, gfxImageFormat aFormat) = 0; 236 237 /** 238 * Beware that this method may return DrawTargets which are not fully 239 * supported on the current platform and might fail silently in subtle ways. 240 * This is a massive potential footgun. You should only use these methods for 241 * canvas drawing really. Use extreme caution if you use them for content 242 * where you are not 100% sure we support the DrawTarget we get back. See 243 * SupportsAzureContentForDrawTarget. 244 */ 245 static already_AddRefed<DrawTarget> CreateDrawTargetForSurface( 246 gfxASurface* aSurface, const mozilla::gfx::IntSize& aSize); 247 248 /* 249 * Creates a SourceSurface for a gfxASurface. This function does no caching, 250 * so the caller should cache the gfxASurface if it will be used frequently. 251 * The returned surface keeps a reference to aTarget, so it is OK to keep the 252 * surface, even if aTarget changes. 253 * aTarget should not keep a reference to the returned surface because that 254 * will cause a cycle. 255 * 256 * This function is static so that it can be accessed from outside the main 257 * process. 258 * 259 * aIsPlugin is used to tell the backend that they can optimize this surface 260 * specifically because it's used for a plugin. This is mostly for Skia. 261 */ 262 static already_AddRefed<SourceSurface> GetSourceSurfaceForSurface( 263 RefPtr<mozilla::gfx::DrawTarget> aTarget, gfxASurface* aSurface, 264 bool aIsPlugin = false); 265 266 static void ClearSourceSurfaceForSurface(gfxASurface* aSurface); 267 268 static already_AddRefed<DataSourceSurface> GetWrappedDataSourceSurface( 269 gfxASurface* aSurface); 270 271 already_AddRefed<DrawTarget> CreateOffscreenContentDrawTarget( 272 const mozilla::gfx::IntSize& aSize, mozilla::gfx::SurfaceFormat aFormat, 273 bool aFallback = false); 274 275 already_AddRefed<DrawTarget> CreateOffscreenCanvasDrawTarget( 276 const mozilla::gfx::IntSize& aSize, mozilla::gfx::SurfaceFormat aFormat, 277 bool aRequireSoftwareRender = false); 278 279 already_AddRefed<DrawTarget> CreateSimilarSoftwareDrawTarget( 280 DrawTarget* aDT, const IntSize& aSize, 281 mozilla::gfx::SurfaceFormat aFormat); 282 283 static already_AddRefed<DrawTarget> CreateDrawTargetForData( 284 unsigned char* aData, const mozilla::gfx::IntSize& aSize, int32_t aStride, 285 mozilla::gfx::SurfaceFormat aFormat, bool aUninitialized = false, 286 bool aIsClear = false); 287 288 /** 289 * Returns true if we should use Azure to render content with aTarget. For 290 * example, it is possible that we are using Direct2D for rendering and thus 291 * using Azure. But we want to render to a CairoDrawTarget, in which case 292 * SupportsAzureContent will return true but SupportsAzureContentForDrawTarget 293 * will return false. 294 */ 295 bool SupportsAzureContentForDrawTarget(mozilla::gfx::DrawTarget* aTarget); 296 297 bool SupportsAzureContentForType(mozilla::gfx::BackendType aType) { 298 return BackendTypeBit(aType) & mContentBackendBitmask; 299 } 300 301 static bool AsyncPanZoomEnabled(); 302 303 const char* GetAzureCanvasBackend() const; 304 const char* GetAzureContentBackend() const; 305 306 void GetAzureBackendInfo(mozilla::widget::InfoObject& aObj); 307 void GetApzSupportInfo(mozilla::widget::InfoObject& aObj); 308 void GetFrameStats(mozilla::widget::InfoObject& aObj); 309 void GetCMSSupportInfo(mozilla::widget::InfoObject& aObj); 310 void GetDisplayInfo(mozilla::widget::InfoObject& aObj); 311 void GetOverlayInfo(mozilla::widget::InfoObject& aObj); 312 void GetSwapChainInfo(mozilla::widget::InfoObject& aObj); 313 314 // Get the default content backend that will be used with the default 315 // compositor. If the compositor is known when calling this function, 316 // GetContentBackendFor() should be called instead. 317 mozilla::gfx::BackendType GetDefaultContentBackend() const { 318 return mContentBackend; 319 } 320 321 /// Return the software backend to use by default. 322 mozilla::gfx::BackendType GetSoftwareBackend() { return mSoftwareBackend; } 323 324 // Return the best content backend available that is compatible with the 325 // given layers backend. 326 virtual mozilla::gfx::BackendType GetContentBackendFor( 327 mozilla::layers::LayersBackend aLayers) { 328 return mContentBackend; 329 } 330 331 virtual mozilla::gfx::BackendType GetPreferredCanvasBackend() { 332 return mPreferredCanvasBackend; 333 } 334 mozilla::gfx::BackendType GetFallbackCanvasBackend() { 335 return mFallbackCanvasBackend; 336 } 337 338 /* 339 * Font bits 340 */ 341 342 /** 343 * Fill aListOfFonts with the results of querying the list of font names 344 * that correspond to the given language group or generic font family 345 * (or both, or neither). 346 */ 347 virtual nsresult GetFontList(nsAtom* aLangGroup, 348 const nsACString& aGenericFamily, 349 nsTArray<nsString>& aListOfFonts); 350 351 /** 352 * Fill aFontList with a list of SystemFontListEntry records for the 353 * available fonts on the platform; used to pass the list from chrome to 354 * content process. Currently implemented only on MacOSX and Linux. 355 */ 356 virtual void ReadSystemFontList(mozilla::dom::SystemFontList*) {}; 357 358 /** 359 * Rebuilds the system font lists (if aFullRebuild is true), or just notifies 360 * content that the list has changed but existing memory mappings are still 361 * valid (aFullRebuild is false). 362 */ 363 nsresult UpdateFontList(bool aFullRebuild = true); 364 365 /** 366 * Create the platform font-list object (gfxPlatformFontList concrete 367 * subclass). This function is responsible to create the appropriate subclass 368 * of gfxPlatformFontList *and* to call its InitFontList() method. 369 */ 370 virtual bool CreatePlatformFontList() = 0; 371 372 /** 373 * Resolving a font name to family name. The result MUST be in the result of 374 * GetFontList(). If the name doesn't in the system, aFamilyName will be empty 375 * string, but not failed. 376 */ 377 void GetStandardFamilyName(const nsCString& aFontName, 378 nsACString& aFamilyName); 379 380 /** 381 * Returns default font name (localized family name) for aLangGroup and 382 * aGenericFamily. The result is typically the first font in 383 * font.name-list.<aGenericFamily>.<aLangGroup>. However, if it's not 384 * available in the system, this may return second or later font in the 385 * pref. If there are no available fonts in the pref, returns empty string. 386 */ 387 nsAutoCString GetDefaultFontName(const nsACString& aLangGroup, 388 const nsACString& aGenericFamily); 389 390 /** 391 * Look up a local platform font using the full font face name. 392 * (Needed to support @font-face src local().) 393 * Ownership of the returned gfxFontEntry is passed to the caller, 394 * who must either AddRef() or delete. 395 */ 396 gfxFontEntry* LookupLocalFont(FontVisibilityProvider* aFontVisibilityProvider, 397 const nsACString& aFontName, 398 WeightRange aWeightForEntry, 399 StretchRange aStretchForEntry, 400 SlantStyleRange aStyleForEntry); 401 402 /** 403 * Activate a platform font. (Needed to support @font-face src url().) 404 * aFontData is a NS_Malloc'ed block that must be freed by this function 405 * (or responsibility passed on) when it is no longer needed; the caller 406 * will NOT free it. 407 * Ownership of the returned gfxFontEntry is passed to the caller, 408 * who must either AddRef() or delete. 409 */ 410 gfxFontEntry* MakePlatformFont(const nsACString& aFontName, 411 WeightRange aWeightForEntry, 412 StretchRange aStretchForEntry, 413 SlantStyleRange aStyleForEntry, 414 const uint8_t* aFontData, uint32_t aLength); 415 416 /** 417 * Whether to allow downloadable fonts via @font-face rules 418 */ 419 bool DownloadableFontsEnabled(); 420 421 /** 422 * True when hinting should be enabled. This setting shouldn't 423 * change per gecko process, while the process is live. If so the 424 * results are not defined. 425 * 426 * NB: this bit is only honored by the FT2 backend, currently. 427 */ 428 virtual bool FontHintingEnabled() { return true; } 429 430 /** 431 * True when zooming should not require reflow, so glyph metrics and 432 * positioning should not be adjusted for device pixels. 433 * If this is TRUE, then FontHintingEnabled() should be FALSE, 434 * but the converse is not necessarily required; 435 * 436 * Like FontHintingEnabled (above), this setting shouldn't 437 * change per gecko process, while the process is live. If so the 438 * results are not defined. 439 * 440 * NB: this bit is only honored by the FT2 backend, currently. 441 */ 442 virtual bool RequiresLinearZoom() { return false; } 443 444 /** 445 * Whether the frame->StyleFont().mFont.smoothing field is respected by 446 * text rendering on this platform. 447 */ 448 virtual bool RespectsFontStyleSmoothing() const { return false; } 449 450 /** 451 * Whether to check all font cmaps during system font fallback 452 */ 453 bool UseCmapsDuringSystemFallback(); 454 455 /** 456 * Whether to render SVG glyphs within an OpenType font wrapper 457 */ 458 bool OpenTypeSVGEnabled(); 459 460 /** 461 * Max character length of words in the word cache 462 */ 463 uint32_t WordCacheCharLimit(); 464 465 /** 466 * Max number of entries in word cache 467 */ 468 uint32_t WordCacheMaxEntries(); 469 470 /** 471 * Whether to use the SIL Graphite rendering engine 472 * (for fonts that include Graphite tables) 473 */ 474 bool UseGraphiteShaping(); 475 476 // Check whether format is supported on a platform (if unclear, returns true). 477 // Default implementation checks for "common" formats that we support across 478 // all platforms, but individual platform implementations may override. 479 virtual bool IsFontFormatSupported( 480 mozilla::StyleFontFaceSourceFormatKeyword aFormatHint, 481 mozilla::StyleFontFaceSourceTechFlags aTechFlags); 482 483 bool IsKnownIconFontFamily(const nsAtom* aFamilyName) const; 484 485 virtual bool DidRenderingDeviceReset( 486 mozilla::gfx::DeviceResetReason* aResetReason = nullptr) { 487 return false; 488 } 489 490 // returns a list of commonly used fonts for a given character 491 // these are *possible* matches, no cmap-checking is done at this level 492 virtual void GetCommonFallbackFonts(uint32_t /*aCh*/, Script /*aRunScript*/, 493 FontPresentation /*aPresentation*/, 494 nsTArray<const char*>& /*aFontList*/) { 495 // platform-specific override, by default do nothing 496 } 497 498 // Are we in safe mode? 499 static bool InSafeMode(); 500 501 static bool OffMainThreadCompositingEnabled(); 502 503 inline static void EnsureCMSInitialized() { 504 if (MOZ_UNLIKELY(!gCMSInitialized)) { 505 MaybeInitializeCMS(); 506 MOZ_ASSERT(gCMSInitialized); 507 } 508 } 509 510 /** 511 * Are we going to try color management? 512 */ 513 static CMSMode GetCMSMode() { 514 EnsureCMSInitialized(); 515 return gCMSMode; 516 } 517 518 /** 519 * Used only for testing. Override the pref setting. 520 */ 521 static void SetCMSModeOverride(CMSMode aMode); 522 523 /** 524 * Determines the rendering intent for color management. 525 * 526 * If the value in the pref gfx.color_management.rendering_intent is a 527 * valid rendering intent as defined in gfx/qcms/qcms.h, that 528 * value is returned. Otherwise, -1 is returned and the embedded intent 529 * should be used. 530 * 531 * See bug 444014 for details. 532 */ 533 static int GetRenderingIntent(); 534 535 /** 536 * Convert a pixel using a cms transform in an endian-aware manner. 537 */ 538 static DeviceColor TransformPixel(const sRGBColor& in, 539 qcms_transform* transform); 540 541 /** 542 * Return the output device ICC profile. 543 */ 544 static qcms_profile* GetCMSOutputProfile() { 545 return GetPlatform()->mCMSOutputProfile; 546 } 547 548 /** 549 * Return the sRGB ICC profile. 550 */ 551 static qcms_profile* GetCMSsRGBProfile() { 552 return GetPlatform()->mCMSsRGBProfile; 553 } 554 555 /** 556 * Return sRGB -> output device transform. 557 */ 558 static qcms_transform* GetCMSRGBTransform() { 559 return GetPlatform()->mCMSRGBTransform; 560 } 561 562 /** 563 * Return output -> sRGB device transform. 564 */ 565 static qcms_transform* GetCMSInverseRGBTransform() { 566 return GetPlatform()->mCMSInverseRGBTransform; 567 } 568 569 /** 570 * Return sRGBA -> output device transform. 571 */ 572 static qcms_transform* GetCMSRGBATransform() { 573 return GetPlatform()->mCMSRGBATransform; 574 } 575 576 /** 577 * Return sBGRA -> output device transform. 578 */ 579 static qcms_transform* GetCMSBGRATransform() { 580 return GetPlatform()->mCMSBGRATransform; 581 } 582 583 /** 584 * Return OS RGBA -> output device transform. 585 */ 586 static qcms_transform* GetCMSOSRGBATransform(); 587 588 /** 589 * Return OS RGBA QCMS type. 590 */ 591 static qcms_data_type GetCMSOSRGBAType(); 592 593 virtual void FontsPrefsChanged(const char* aPref); 594 595 uint32_t GetBidiNumeralOption(); 596 597 /** 598 * Force all presContexts to reflow (and reframe if needed). 599 * 600 * This is used when something about platform settings changes that might have 601 * an effect on layout, such as font rendering settings that influence 602 * metrics, or installed fonts. 603 * 604 * Normally this is initiated in the parent process, and also broadcast to 605 * child processes, but some callers might not need this if they implement 606 * their own notification. 607 */ 608 enum class GlobalReflowFlags : uint8_t { 609 None = 0, 610 // Font data has been updated such that new fonts and/or character coverage 611 // may be available; existing font-lookup caches should be invalidated and 612 // font selection re-done. 613 FontsChanged = (1 << 0), 614 // Content should be fully reframed; this is used when font entry records 615 // may have been invalidated such that existing textruns in the frame tree 616 // are no longer safe to work with. Rather than reflow the existing frame 617 // tree we will discard and re-create it. 618 NeedsReframe = (1 << 1), 619 // (If this is the parent process), broadcast this reflow request to all 620 // child processes. 621 BroadcastToChildren = (1 << 2), 622 // For serialization. 623 ALL_BITS = FontsChanged | NeedsReframe | BroadcastToChildren, 624 }; 625 static void ForceGlobalReflow(GlobalReflowFlags aFlags); 626 627 static void FlushFontAndWordCaches(); 628 629 /** 630 * Returns a 1x1 DrawTarget that can be used for measuring text etc. as 631 * it would measure if rendered on-screen. Guaranteed to return a 632 * non-null and valid DrawTarget. 633 */ 634 RefPtr<mozilla::gfx::DrawTarget> ScreenReferenceDrawTarget(); 635 636 static RefPtr<mozilla::gfx::DrawTarget> 637 ThreadLocalScreenReferenceDrawTarget(); 638 639 virtual mozilla::gfx::SurfaceFormat Optimal2DFormatForContent( 640 gfxContentType aContent); 641 642 virtual gfxImageFormat OptimalFormatForContent(gfxContentType aContent); 643 644 virtual gfxImageFormat GetOffscreenFormat() { 645 return mozilla::gfx::SurfaceFormat::X8R8G8B8_UINT32; 646 } 647 648 /** 649 * Returns a logger if one is available and logging is enabled 650 */ 651 static mozilla::LogModule* GetLog(eGfxLog aWhichLog); 652 653 static void PurgeSkiaFontCache(); 654 655 static bool UsesOffMainThreadCompositing(); 656 657 /** 658 * Returns the global vsync dispatcher. There is only one global vsync 659 * dispatcher and it stays around for the entire lifetime of the process. 660 * Must only be called in the parent process. 661 */ 662 RefPtr<mozilla::VsyncDispatcher> GetGlobalVsyncDispatcher(); 663 664 /** 665 * True if layout rendering should use ASAP mode, which means 666 * the refresh driver and compositor should render ASAP. 667 * Used for talos testing purposes 668 */ 669 static bool IsInLayoutAsapMode(); 670 671 /** 672 * Returns whether or not a custom vsync rate is set. 673 */ 674 static bool ForceSoftwareVsync(); 675 676 /** 677 * Returns the software vsync rate to use. 678 */ 679 static int GetSoftwareVsyncRate(); 680 681 /** 682 * Returns the default frame rate for the refresh driver / software vsync. 683 */ 684 static int GetDefaultFrameRate(); 685 686 /** 687 * Update the frame rate (called e.g. after pref changes). 688 */ 689 static void ReInitFrameRate(const char* aPrefIgnored, void* aDataIgnored); 690 691 /** 692 * Reset the global hardware vsync source. The next call to ReInitFrameRate 693 * will attempt to reestablish it, and fall back to software if needed. 694 */ 695 static void ResetHardwareVsyncSource(); 696 697 /** 698 * Update force subpixel AA quality setting (called after pref 699 * changes). 700 */ 701 void UpdateForceSubpixelAAWherePossible(); 702 703 /** 704 * Used to test which input types are handled via APZ. 705 */ 706 virtual bool SupportsApzWheelInput() const { return false; } 707 bool SupportsApzTouchInput() const; 708 bool SupportsApzDragInput() const; 709 bool SupportsApzKeyboardInput() const; 710 bool SupportsApzAutoscrolling() const; 711 bool SupportsApzZooming() const; 712 713 // If a device reset has occurred, schedule any necessary paints in the 714 // widget. This should only be used within nsRefreshDriver. 715 virtual void SchedulePaintIfDeviceReset() {} 716 717 /** 718 * Helper method, creates a draw target for a specific Azure backend. 719 * Used by CreateOffscreenDrawTarget. 720 */ 721 already_AddRefed<DrawTarget> CreateDrawTargetForBackend( 722 mozilla::gfx::BackendType aBackend, const mozilla::gfx::IntSize& aSize, 723 mozilla::gfx::SurfaceFormat aFormat); 724 725 /** 726 * Wrapper around StaticPrefs::gfx_perf_warnings_enabled(). 727 * Extracted into a function to avoid including StaticPrefs_gfx.h from this 728 * file. 729 */ 730 static bool PerfWarnings(); 731 732 static void DisableAcceleratedCanvasForFallback( 733 mozilla::gfx::FeatureStatus aStatus, const char* aMessage, 734 const nsACString& aFailureId); 735 736 static void DisableAllCanvasForFallback(mozilla::gfx::FeatureStatus aStatus, 737 const char* aMessage, 738 const nsACString& aFailureId); 739 static void DisableGPUProcess(); 740 741 void NotifyCompositorCreated(mozilla::layers::LayersBackend aBackend); 742 mozilla::layers::LayersBackend GetCompositorBackend() const { 743 return mCompositorBackend; 744 } 745 746 virtual void CompositorUpdated() {} 747 748 // Plugin async drawing support. 749 virtual bool SupportsPluginDirectBitmapDrawing() { return false; } 750 751 // Some platforms don't support CompositorOGL in an unaccelerated OpenGL 752 // context. These platforms should return true here. 753 virtual bool RequiresAcceleratedGLContextForCompositorOGL() const { 754 return false; 755 } 756 757 /** 758 * Check the blocklist for a feature. Returns false if the feature is blocked 759 * with an appropriate message and failure ID. 760 * */ 761 static bool IsGfxInfoStatusOkay(int32_t aFeature, nsCString* aOutMessage, 762 nsCString& aFailureId); 763 764 const gfxSkipChars& EmptySkipChars() const { return kEmptySkipChars; } 765 766 /** 767 * Returns a buffer containing the CMS output profile data. The way this 768 * is obtained is platform-specific. 769 */ 770 virtual nsTArray<uint8_t> GetPlatformCMSOutputProfileData() { 771 return GetPrefCMSOutputProfileData(); 772 } 773 774 /** 775 * Return information on how child processes should initialize graphics 776 * devices. 777 */ 778 virtual void BuildContentDeviceData(mozilla::gfx::ContentDeviceData* aOut); 779 780 /** 781 * Imports settings from the GPU process. This should only be called through 782 * GPUProcessManager, in the UI process. 783 */ 784 virtual void ImportGPUDeviceData(const mozilla::gfx::GPUDeviceData& aData); 785 786 void SetOverlayInfo(const mozilla::layers::OverlayInfo& aInfo) { 787 mOverlayInfo = mozilla::Some(aInfo); 788 } 789 790 void SetSwapChainInfo(const mozilla::layers::SwapChainInfo& aInfo) { 791 mSwapChainInfo = mozilla::Some(aInfo); 792 } 793 794 static void DisableRemoteCanvas(); 795 796 static bool HasVariationFontSupport(); 797 798 // you probably want to use gfxVars::UseWebRender() instead of this 799 static bool WebRenderPrefEnabled(); 800 // you probably want to use gfxVars::UseWebRender() instead of this 801 static bool WebRenderEnvvarEnabled(); 802 803 static const char* WebRenderResourcePathOverride(); 804 805 // Returns true if we would like to keep the GPU process if possible. 806 // If aCrashAfterFinalFallback is true then crash if we have already 807 // exhausted all of our fallback options. Otherwise we remain on the final 808 // fallback configuration. 809 static bool FallbackFromAcceleration(mozilla::gfx::FeatureStatus aStatus, 810 const char* aMessage, 811 const nsACString& aFailureId, 812 bool aCrashAfterFinalFallback = false); 813 814 void NotifyFrameStats(nsTArray<mozilla::layers::FrameStats>&& aFrameStats); 815 816 virtual void OnMemoryPressure( 817 mozilla::layers::MemoryPressureReason aWhy) override; 818 819 virtual void EnsureDevicesInitialized() {}; 820 virtual bool DevicesInitialized() { return true; }; 821 822 virtual bool IsWaylandDisplay() { return false; } 823 824 static uint32_t TargetFrameRate(); 825 826 static bool UseDesktopZoomingScrollbars(); 827 828 protected: 829 gfxPlatform(); 830 virtual ~gfxPlatform(); 831 832 virtual void InitAcceleration(); 833 virtual void InitWebRenderConfig(); 834 void InitHardwareVideoConfig(); 835 virtual void InitWebGLConfig(); 836 virtual void InitWebGPUConfig(); 837 virtual void InitWindowOcclusionConfig(); 838 void InitBackdropFilterConfig(); 839 void InitAcceleratedCanvas2DConfig(); 840 841 virtual void GetPlatformDisplayInfo(mozilla::widget::InfoObject& aObj) {} 842 843 /** 844 * Called immediately before deleting the gfxPlatform object. 845 */ 846 virtual void WillShutdown(); 847 848 // Return a hardware vsync source for this platform. 849 already_AddRefed<mozilla::gfx::VsyncSource> GetGlobalHardwareVsyncSource(); 850 851 // Return a software vsync source (which uses a timer internally). 852 // Can be used as a fallback for platforms without hardware vsync, 853 // and when the layout.frame_rate pref is set to a non-negative value. 854 already_AddRefed<mozilla::gfx::VsyncSource> GetSoftwareVsyncSource(); 855 856 // Create the platform-specific global vsync source. Can fall back to 857 // GetSoftwareVsyncSource(). 858 virtual already_AddRefed<mozilla::gfx::VsyncSource> 859 CreateGlobalHardwareVsyncSource() = 0; 860 861 // Returns whether or not layers should be accelerated by default on this 862 // platform. 863 virtual bool AccelerateLayersByDefault(); 864 865 // Returns preferences of canvas and content backends. 866 virtual BackendPrefsData GetBackendPrefs() const; 867 868 /** 869 * Initialise the preferred and fallback canvas backends 870 * aBackendBitmask specifies the backends which are acceptable to the caller. 871 * The backend used is determined by aBackendBitmask and the order specified 872 * by the gfx.canvas.azure.backends pref. 873 */ 874 void InitBackendPrefs(BackendPrefsData&& aPrefsData); 875 876 /** 877 * Content-process only. Updates device preferences from the parent process, 878 * if we've received any. 879 */ 880 void ImportCachedContentDeviceData(); 881 virtual void ImportContentDeviceData( 882 const mozilla::gfx::ContentDeviceData& aData); 883 884 public: 885 /** 886 * Returns the contents of the file pointed to by the 887 * gfx.color_management.display_profile pref, if set. 888 * Returns an empty array if not set, or if an error occurs 889 */ 890 static nsTArray<uint8_t> GetPrefCMSOutputProfileData(); 891 892 protected: 893 /** 894 * If inside a child process and have ever received a 895 * SetXPCOMProcessAttributes message, this contains the cmsOutputProfileData 896 * from that message. 897 */ 898 mozilla::Maybe<nsTArray<uint8_t>>& GetCMSOutputProfileData(); 899 900 /** 901 * Increase the global device counter after a device has been removed/reset. 902 */ 903 void BumpDeviceCounter(); 904 905 /** 906 * returns the first backend named in the pref gfx.canvas.azure.backends 907 * which is a component of aBackendBitmask, a bitmask of backend types 908 */ 909 static mozilla::gfx::BackendType GetCanvasBackendPref( 910 uint32_t aBackendBitmask); 911 912 /** 913 * returns the first backend named in the pref gfx.content.azure.backend 914 * which is a component of aBackendBitmask, a bitmask of backend types 915 */ 916 static mozilla::gfx::BackendType GetContentBackendPref( 917 uint32_t& aBackendBitmask); 918 919 /** 920 * Will return the first backend named in aBackendPrefName 921 * allowed by aBackendBitmask, a bitmask of backend types. 922 * It also modifies aBackendBitmask to only include backends that are 923 * allowed given the prefs. 924 */ 925 static mozilla::gfx::BackendType GetBackendPref(const char* aBackendPrefName, 926 uint32_t& aBackendBitmask); 927 /** 928 * Decode the backend enumberation from a string. 929 */ 930 static mozilla::gfx::BackendType BackendTypeForName(const nsCString& aName); 931 932 int8_t mAllowDownloadableFonts; 933 934 // Whether the platform supports rendering OpenType font variations 935 static std::atomic<int8_t> sHasVariationFontSupport; 936 937 // The global vsync dispatcher. Only non-null in the parent process. 938 // Its underlying VsyncSource is either mGlobalHardwareVsyncSource 939 // or mSoftwareVsyncSource. 940 RefPtr<mozilla::VsyncDispatcher> mVsyncDispatcher; 941 942 // Cached software vsync source. Only non-null in the parent process, 943 // and only after the first time GetHardwareVsyncSource has been called. 944 RefPtr<mozilla::gfx::VsyncSource> mGlobalHardwareVsyncSource; 945 946 // Cached software vsync source. Only non-null in the parent process, 947 // and only after the first time GetSoftwareVsyncSource has been called. 948 // Used as a fallback source if hardware vsync is not available, 949 // or when the layout.frame_rate pref is set. 950 RefPtr<mozilla::gfx::SoftwareVsyncSource> mSoftwareVsyncSource; 951 952 RefPtr<mozilla::gfx::DrawTarget> mScreenReferenceDrawTarget; 953 954 private: 955 /** 956 * Start up Thebes. 957 */ 958 static void Init(); 959 960 static void InitOpenGLConfig(); 961 962 static void VideoDecodingFailedChangedCallback(const char* aPref, void*); 963 964 static void HWDRMFailedChangedCallback(const char* aPref, void*); 965 966 static gfxPlatform* gPlatform; 967 968 void InitializeCMS(); 969 void ShutdownCMS(); 970 971 /** 972 * This uses nsIScreenManager to determine the primary screen color depth 973 */ 974 void PopulateScreenInfo(); 975 976 void InitCompositorAccelerationPrefs(); 977 void InitGPUProcessPrefs(); 978 virtual void InitPlatformGPUProcessPrefs() {} 979 virtual void InitPlatformHardwareVideoConfig() {} 980 virtual void InitPlatformHardwarDRMConfig() {} 981 982 // Gather telemetry data about the Gfx Platform and send it 983 static void ReportTelemetry(); 984 985 static bool IsDXInterop2Blocked(); 986 static bool IsDXNV12Blocked(); 987 static bool IsDXP010Blocked(); 988 static bool IsDXP016Blocked(); 989 990 static void MaybeInitializeCMS(); 991 992 // We need these to be static because we might call them in the GPU process, 993 // even if we don't do color management there. 994 static mozilla::Atomic<bool, mozilla::ReleaseAcquire> gCMSInitialized; 995 static CMSMode gCMSMode; 996 997 // These two may point to the same profile 998 qcms_profile* mCMSOutputProfile = nullptr; 999 qcms_profile* mCMSsRGBProfile = nullptr; 1000 1001 qcms_transform* mCMSRGBTransform = nullptr; 1002 qcms_transform* mCMSInverseRGBTransform = nullptr; 1003 qcms_transform* mCMSRGBATransform = nullptr; 1004 qcms_transform* mCMSBGRATransform = nullptr; 1005 mozilla::Maybe<nsTArray<uint8_t>> mCMSOutputProfileData; 1006 1007 RefPtr<gfxASurface> mScreenReferenceSurface; 1008 RefPtr<mozilla::layers::MemoryPressureObserver> mMemoryPressureObserver; 1009 1010 // The preferred draw target backend to use for canvas 1011 mozilla::gfx::BackendType mPreferredCanvasBackend; 1012 // The fallback draw target backend to use for canvas, if the preferred 1013 // backend fails 1014 mozilla::gfx::BackendType mFallbackCanvasBackend; 1015 // The backend to use for content 1016 mozilla::gfx::BackendType mContentBackend; 1017 // The backend to use when we need it not to be accelerated. 1018 mozilla::gfx::BackendType mSoftwareBackend; 1019 // Bitmask of backend types we can use to render content 1020 uint32_t mContentBackendBitmask; 1021 1022 mozilla::widget::GfxInfoCollector<gfxPlatform> mAzureCanvasBackendCollector; 1023 mozilla::widget::GfxInfoCollector<gfxPlatform> mApzSupportCollector; 1024 mozilla::widget::GfxInfoCollector<gfxPlatform> mFrameStatsCollector; 1025 mozilla::widget::GfxInfoCollector<gfxPlatform> mCMSInfoCollector; 1026 mozilla::widget::GfxInfoCollector<gfxPlatform> mDisplayInfoCollector; 1027 mozilla::widget::GfxInfoCollector<gfxPlatform> mOverlayInfoCollector; 1028 mozilla::widget::GfxInfoCollector<gfxPlatform> mSwapChainInfoCollector; 1029 1030 nsTArray<mozilla::layers::FrameStats> mFrameStats; 1031 1032 // Backend that we are compositing with. NONE, if no compositor has been 1033 // created yet. 1034 mozilla::layers::LayersBackend mCompositorBackend; 1035 1036 mozilla::Maybe<mozilla::layers::OverlayInfo> mOverlayInfo; 1037 mozilla::Maybe<mozilla::layers::SwapChainInfo> mSwapChainInfo; 1038 1039 // An instance of gfxSkipChars which is empty. It is used as the 1040 // basis for error-case iterators. 1041 const gfxSkipChars kEmptySkipChars; 1042 }; 1043 1044 MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(gfxPlatform::GlobalReflowFlags) 1045 1046 CMSMode GfxColorManagementMode(); 1047 1048 #endif /* GFX_PLATFORM_H */