# HG changeset patch # User sotaro # Date 1521092934 -32400 # Node ID c71ee5e970f63c9e433ecad757a1145a78bad3ea # Parent a47886635d7b215dc59a0ec2adb970b424ac7b80 Bug 1432039 - Improve assumption of content process's back-end prefs r=jrmuizel diff --git a/gfx/thebes/gfxPlatform.cpp b/gfx/thebes/gfxPlatform.cpp --- a/gfx/thebes/gfxPlatform.cpp +++ b/gfx/thebes/gfxPlatform.cpp @@ -513,24 +513,17 @@ gfxPlatform::gfxPlatform() mWordCacheCharLimit = UNINITIALIZED_VALUE; mWordCacheMaxEntries = UNINITIALIZED_VALUE; mGraphiteShapingEnabled = UNINITIALIZED_VALUE; mOpenTypeSVGEnabled = UNINITIALIZED_VALUE; mBidiNumeralOption = UNINITIALIZED_VALUE; mSkiaGlue = nullptr; - uint32_t canvasMask = BackendTypeBit(BackendType::CAIRO); - uint32_t contentMask = BackendTypeBit(BackendType::CAIRO); -#ifdef USE_SKIA - canvasMask |= BackendTypeBit(BackendType::SKIA); - contentMask |= BackendTypeBit(BackendType::SKIA); -#endif - InitBackendPrefs(canvasMask, BackendType::CAIRO, - contentMask, BackendType::CAIRO); + InitBackendPrefs(GetBackendPrefs()); mTotalSystemMemory = PR_GetPhysicalMemorySize(); VRManager::ManagerInit(); } gfxPlatform* gfxPlatform::GetPlatform() @@ -1801,46 +1794,62 @@ gfxPlatform::GetLayerDiagnosticTypes() type |= mozilla::layers::DiagnosticTypes::BIGIMAGE_BORDERS; } if (gfxPrefs::FlashLayerBorders()) { type |= mozilla::layers::DiagnosticTypes::FLASH_BORDERS; } return type; } -void -gfxPlatform::InitBackendPrefs(uint32_t aCanvasBitmask, BackendType aCanvasDefault, - uint32_t aContentBitmask, BackendType aContentDefault) +BackendPrefsData +gfxPlatform::GetBackendPrefs() { - mPreferredCanvasBackend = GetCanvasBackendPref(aCanvasBitmask); + BackendPrefsData data; + + data.mCanvasBitmask = BackendTypeBit(BackendType::CAIRO); + data.mContentBitmask = BackendTypeBit(BackendType::CAIRO); +#ifdef USE_SKIA + data.mCanvasBitmask |= BackendTypeBit(BackendType::SKIA); + data.mContentBitmask |= BackendTypeBit(BackendType::SKIA); +#endif + data.mCanvasDefault = BackendType::CAIRO; + data.mContentDefault = BackendType::CAIRO; + + return mozilla::Move(data); +} + +void +gfxPlatform::InitBackendPrefs(BackendPrefsData&& aPrefsData) +{ + mPreferredCanvasBackend = GetCanvasBackendPref(aPrefsData.mCanvasBitmask); if (mPreferredCanvasBackend == BackendType::NONE) { - mPreferredCanvasBackend = aCanvasDefault; + mPreferredCanvasBackend = aPrefsData.mCanvasDefault; } if (mPreferredCanvasBackend == BackendType::DIRECT2D1_1) { // Falling back to D2D 1.0 won't help us here. When D2D 1.1 DT creation // fails it means the surface was too big or there's something wrong with // the device. D2D 1.0 will encounter a similar situation. mFallbackCanvasBackend = - GetCanvasBackendPref(aCanvasBitmask & + GetCanvasBackendPref(aPrefsData.mCanvasBitmask & ~(BackendTypeBit(mPreferredCanvasBackend) | BackendTypeBit(BackendType::DIRECT2D))); } else { mFallbackCanvasBackend = - GetCanvasBackendPref(aCanvasBitmask & ~BackendTypeBit(mPreferredCanvasBackend)); + GetCanvasBackendPref(aPrefsData.mCanvasBitmask & ~BackendTypeBit(mPreferredCanvasBackend)); } - mContentBackendBitmask = aContentBitmask; + mContentBackendBitmask = aPrefsData.mContentBitmask; mContentBackend = GetContentBackendPref(mContentBackendBitmask); if (mContentBackend == BackendType::NONE) { - mContentBackend = aContentDefault; + mContentBackend = aPrefsData.mContentDefault; // mContentBackendBitmask is our canonical reference for supported // backends so we need to add the default if we are using it and // overriding the prefs. - mContentBackendBitmask |= BackendTypeBit(aContentDefault); + mContentBackendBitmask |= BackendTypeBit(aPrefsData.mContentDefault); } uint32_t swBackendBits = BackendTypeBit(BackendType::SKIA) | BackendTypeBit(BackendType::CAIRO); mSoftwareBackend = GetContentBackendPref(swBackendBits); if (XRE_IsParentProcess()) { gfxVars::SetContentBackend(mContentBackend); @@ -2726,20 +2735,28 @@ gfxPlatform::GetDefaultFrameRate() void gfxPlatform::GetAzureBackendInfo(mozilla::widget::InfoObject& aObj) { if (gfxConfig::IsEnabled(Feature::GPU_PROCESS)) { aObj.DefineProperty("AzureCanvasBackend (UI Process)", GetBackendName(mPreferredCanvasBackend)); aObj.DefineProperty("AzureFallbackCanvasBackend (UI Process)", GetBackendName(mFallbackCanvasBackend)); aObj.DefineProperty("AzureContentBackend (UI Process)", GetBackendName(mContentBackend)); - if (gfxConfig::IsEnabled(gfx::Feature::DIRECT2D)) { - aObj.DefineProperty("AzureCanvasBackend", "Direct2D 1.1"); - aObj.DefineProperty("AzureContentBackend", "Direct2D 1.1"); + // Assume content process' backend prefs. + BackendPrefsData data = GetBackendPrefs(); + BackendType canvasBackend = GetCanvasBackendPref(data.mCanvasBitmask); + if (canvasBackend == BackendType::NONE) { + canvasBackend = data.mCanvasDefault; } + BackendType contentBackend = GetContentBackendPref(data.mContentBitmask); + if (contentBackend == BackendType::NONE) { + contentBackend = data.mContentDefault; + } + aObj.DefineProperty("AzureCanvasBackend", GetBackendName(canvasBackend)); + aObj.DefineProperty("AzureContentBackend", GetBackendName(contentBackend)); } else { aObj.DefineProperty("AzureCanvasBackend", GetBackendName(mPreferredCanvasBackend)); aObj.DefineProperty("AzureFallbackCanvasBackend", GetBackendName(mFallbackCanvasBackend)); aObj.DefineProperty("AzureContentBackend", GetBackendName(mContentBackend)); } aObj.DefineProperty("AzureCanvasAccelerated", AllowOpenGLCanvas()); } diff --git a/gfx/thebes/gfxPlatform.h b/gfx/thebes/gfxPlatform.h --- a/gfx/thebes/gfxPlatform.h +++ b/gfx/thebes/gfxPlatform.h @@ -141,16 +141,24 @@ enum class DeviceResetReason }; enum class ForcedDeviceResetReason { OPENSHAREDHANDLE = 0, COMPOSITOR_UPDATED, }; +struct BackendPrefsData +{ + uint32_t mCanvasBitmask = 0; + mozilla::gfx::BackendType mCanvasDefault = mozilla::gfx::BackendType::NONE; + uint32_t mContentBitmask = 0; + mozilla::gfx::BackendType mContentDefault = mozilla::gfx::BackendType::NONE; +}; + class gfxPlatform { friend class SRGBOverrideObserver; public: typedef mozilla::gfx::Color Color; typedef mozilla::gfx::DataSourceSurface DataSourceSurface; typedef mozilla::gfx::DrawTarget DrawTarget; typedef mozilla::gfx::IntSize IntSize; @@ -733,24 +741,26 @@ protected: virtual already_AddRefed CreateHardwareVsyncSource(); // Returns whether or not layers should be accelerated by default on this platform. virtual bool AccelerateLayersByDefault(); // Returns a prioritized list of available compositor backends for acceleration. virtual void GetAcceleratedCompositorBackends(nsTArray& aBackends); + // Returns preferences of canvas and content backends. + virtual BackendPrefsData GetBackendPrefs(); + /** * Initialise the preferred and fallback canvas backends * aBackendBitmask specifies the backends which are acceptable to the caller. * The backend used is determined by aBackendBitmask and the order specified * by the gfx.canvas.azure.backends pref. */ - void InitBackendPrefs(uint32_t aCanvasBitmask, mozilla::gfx::BackendType aCanvasDefault, - uint32_t aContentBitmask, mozilla::gfx::BackendType aContentDefault); + void InitBackendPrefs(BackendPrefsData&& aPrefsData); /** * Content-process only. Requests device preferences from the parent process * and updates any cached settings. */ void FetchAndImportContentDeviceData(); virtual void ImportContentDeviceData(const mozilla::gfx::ContentDeviceData& aData); diff --git a/gfx/thebes/gfxPlatformGtk.cpp b/gfx/thebes/gfxPlatformGtk.cpp --- a/gfx/thebes/gfxPlatformGtk.cpp +++ b/gfx/thebes/gfxPlatformGtk.cpp @@ -80,24 +80,17 @@ gfxPlatformGtk::gfxPlatformGtk() if (GDK_IS_X11_DISPLAY(gdk_display_get_default()) && mozilla::Preferences::GetBool("gfx.xrender.enabled")) { gfxVars::SetUseXRender(true); } } #endif - uint32_t canvasMask = BackendTypeBit(BackendType::CAIRO); - uint32_t contentMask = BackendTypeBit(BackendType::CAIRO); -#ifdef USE_SKIA - canvasMask |= BackendTypeBit(BackendType::SKIA); - contentMask |= BackendTypeBit(BackendType::SKIA); -#endif - InitBackendPrefs(canvasMask, BackendType::CAIRO, - contentMask, BackendType::CAIRO); + InitBackendPrefs(GetBackendPrefs()); #ifdef MOZ_X11 if (gfxPlatform::IsHeadless() && GDK_IS_X11_DISPLAY(gdk_display_get_default())) { mCompositorDisplay = XOpenDisplay(nullptr); MOZ_ASSERT(mCompositorDisplay, "Failed to create compositor display!"); } else { mCompositorDisplay = nullptr; } diff --git a/gfx/thebes/gfxPlatformMac.cpp b/gfx/thebes/gfxPlatformMac.cpp --- a/gfx/thebes/gfxPlatformMac.cpp +++ b/gfx/thebes/gfxPlatformMac.cpp @@ -73,29 +73,39 @@ DisableFontActivation() } } gfxPlatformMac::gfxPlatformMac() { DisableFontActivation(); mFontAntiAliasingThreshold = ReadAntiAliasingThreshold(); - uint32_t canvasMask = BackendTypeBit(BackendType::SKIA); - uint32_t contentMask = BackendTypeBit(BackendType::SKIA); - InitBackendPrefs(canvasMask, BackendType::SKIA, - contentMask, BackendType::SKIA); + InitBackendPrefs(GetBackendPrefs()); MacIOSurfaceLib::LoadLibrary(); } gfxPlatformMac::~gfxPlatformMac() { gfxCoreTextShaper::Shutdown(); } +BackendPrefsData +gfxPlatformMac::GetBackendPrefs() +{ + BackendPrefsData data; + + data.mCanvasBitmask = BackendTypeBit(BackendType::SKIA); + data.mContentBitmask = BackendTypeBit(BackendType::SKIA); + data.mCanvasDefault = BackendType::SKIA; + data.mContentDefault = BackendType::SKIA; + + return mozilla::Move(data); +} + bool gfxPlatformMac::UsesTiling() const { // The non-tiling ContentClient requires CrossProcessSemaphore which // isn't implemented for OSX. return true; } diff --git a/gfx/thebes/gfxPlatformMac.h b/gfx/thebes/gfxPlatformMac.h --- a/gfx/thebes/gfxPlatformMac.h +++ b/gfx/thebes/gfxPlatformMac.h @@ -78,16 +78,18 @@ public: virtual already_AddRefed CreateHardwareVsyncSource() override; // lower threshold on font anti-aliasing uint32_t GetAntiAliasingThreshold() { return mFontAntiAliasingThreshold; } protected: bool AccelerateLayersByDefault() override; + BackendPrefsData GetBackendPrefs() override; + private: virtual void GetPlatformCMSOutputProfile(void* &mem, size_t &size) override; // read in the pref value for the lower threshold on font anti-aliasing static uint32_t ReadAntiAliasingThreshold(); uint32_t mFontAntiAliasingThreshold; }; diff --git a/gfx/thebes/gfxWindowsPlatform.cpp b/gfx/thebes/gfxWindowsPlatform.cpp --- a/gfx/thebes/gfxWindowsPlatform.cpp +++ b/gfx/thebes/gfxWindowsPlatform.cpp @@ -433,31 +433,53 @@ gfxWindowsPlatform::HandleDeviceReset() gfxConfig::Reset(Feature::DIRECT2D); InitializeConfig(); InitializeDevices(); UpdateANGLEConfig(); return true; } +BackendPrefsData +gfxWindowsPlatform::GetBackendPrefs() +{ + BackendPrefsData data; + + data.mCanvasBitmask = BackendTypeBit(BackendType::CAIRO) | + BackendTypeBit(BackendType::SKIA); + data.mContentBitmask = BackendTypeBit(BackendType::CAIRO) | + BackendTypeBit(BackendType::SKIA); + data.mCanvasDefault = BackendType::SKIA; + data.mContentDefault = BackendType::SKIA; + + if (gfxConfig::IsEnabled(Feature::DIRECT2D) && !gfxVars::UseWebRender()) { + data.mCanvasBitmask |= BackendTypeBit(BackendType::DIRECT2D1_1); + data.mContentBitmask |= BackendTypeBit(BackendType::DIRECT2D1_1); + data.mCanvasDefault = BackendType::DIRECT2D1_1; + data.mContentDefault = BackendType::DIRECT2D1_1; + } + return mozilla::Move(data); +} + void gfxWindowsPlatform::UpdateBackendPrefs() { - uint32_t canvasMask = BackendTypeBit(BackendType::CAIRO) | - BackendTypeBit(BackendType::SKIA); - uint32_t contentMask = BackendTypeBit(BackendType::CAIRO) | - BackendTypeBit(BackendType::SKIA); - BackendType defaultBackend = BackendType::SKIA; - if (gfxConfig::IsEnabled(Feature::DIRECT2D) && - Factory::HasD2D1Device() && !gfxVars::UseWebRender()) { - contentMask |= BackendTypeBit(BackendType::DIRECT2D1_1); - canvasMask |= BackendTypeBit(BackendType::DIRECT2D1_1); - defaultBackend = BackendType::DIRECT2D1_1; + BackendPrefsData data = GetBackendPrefs(); + // Remove DIRECT2D1 preference if D2D1Device does not exist. + if (!Factory::HasD2D1Device()) { + data.mCanvasBitmask &= ~BackendTypeBit(BackendType::DIRECT2D1_1); + data.mContentBitmask &= ~BackendTypeBit(BackendType::DIRECT2D1_1); + if (data.mCanvasDefault == BackendType::DIRECT2D1_1) { + data.mCanvasDefault = BackendType::SKIA; + } + if (data.mContentDefault == BackendType::DIRECT2D1_1) { + data.mContentDefault = BackendType::SKIA; + } } - InitBackendPrefs(canvasMask, defaultBackend, contentMask, defaultBackend); + InitBackendPrefs(mozilla::Move(data)); } bool gfxWindowsPlatform::IsDirect2DBackend() { return GetDefaultContentBackend() == BackendType::DIRECT2D1_1; } diff --git a/gfx/thebes/gfxWindowsPlatform.h b/gfx/thebes/gfxWindowsPlatform.h --- a/gfx/thebes/gfxWindowsPlatform.h +++ b/gfx/thebes/gfxWindowsPlatform.h @@ -226,16 +226,18 @@ protected: } void GetAcceleratedCompositorBackends(nsTArray& aBackends) override; virtual void GetPlatformCMSOutputProfile(void* &mem, size_t &size) override; void ImportGPUDeviceData(const mozilla::gfx::GPUDeviceData& aData) override; void ImportContentDeviceData(const mozilla::gfx::ContentDeviceData& aData) override; void BuildContentDeviceData(mozilla::gfx::ContentDeviceData* aOut) override; + BackendPrefsData GetBackendPrefs() override; + protected: RenderMode mRenderMode; private: void Init(); void InitAcceleration() override; void InitWebRenderConfig() override;