Use gfxConfig for D3D9 preferences. (bug 1270650, r=jrmuizel)
authorDavid Anderson <danderson@mozilla.com>
Fri, 06 May 2016 19:01:58 -0700
changeset 364734 22189fcd62df1f8eb75e62b01780c855ed45dfc7
parent 364733 6d6749bb5c263960571197795e1ca20c5bb9934e
child 364735 a7783f2b454880fe5ab29f164c14bb2a94fa730e
push id17559
push userbmo:gasolin@mozilla.com
push dateMon, 09 May 2016 08:55:35 +0000
reviewersjrmuizel
bugs1270650
milestone49.0a1
Use gfxConfig for D3D9 preferences. (bug 1270650, r=jrmuizel)
gfx/config/gfxFeature.cpp
gfx/config/gfxFeature.h
gfx/layers/d3d9/CompositorD3D9.cpp
gfx/thebes/gfxPlatform.cpp
gfx/thebes/gfxPlatform.h
gfx/thebes/gfxWindowsPlatform.cpp
gfx/thebes/gfxWindowsPlatform.h
--- a/gfx/config/gfxFeature.cpp
+++ b/gfx/config/gfxFeature.cpp
@@ -1,16 +1,17 @@
 /* -*- Mode: C++; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
 /* vim: set sts=2 ts=8 sw=2 tw=99 et: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 #include "mozilla/Preferences.h"
 #include "prprf.h"
 #include "gfxFeature.h"
+#include "nsString.h"
 
 namespace mozilla {
 namespace gfx {
 
 bool
 FeatureState::IsEnabled() const
 {
   return IsFeatureStatusSuccess(GetValue());
@@ -55,19 +56,23 @@ FeatureState::SetDefaultFromPref(const c
                                  bool aDefaultValue)
 {
   bool baseValue = Preferences::GetDefaultBool(aPrefName, aDefaultValue);
   SetDefault(baseValue == aIsEnablePref, FeatureStatus::Disabled, "Disabled by default");
 
   if (Preferences::HasUserValue(aPrefName)) {
     bool userValue = Preferences::GetBool(aPrefName, aDefaultValue);
     if (userValue == aIsEnablePref) {
-      UserEnable("Enabled by user preference");
+      nsCString message("Enabled via ");
+      message.AppendASCII(aPrefName);
+      UserEnable(message.get());
     } else {
-      UserDisable("Disabled by user preference");
+      nsCString message("Disabled via ");
+      message.AppendASCII(aPrefName);
+      UserDisable(message.get());
     }
   }
 }
 
 bool
 FeatureState::InitOrUpdate(bool aEnable,
                            FeatureStatus aDisableStatus,
                            const char* aDisableMessage)
--- a/gfx/config/gfxFeature.h
+++ b/gfx/config/gfxFeature.h
@@ -13,16 +13,17 @@
 
 namespace mozilla {
 namespace gfx {
 
 #define GFX_FEATURE_MAP(_)                                                        \
   /* Name,                        Type,         Description */                    \
   _(HW_COMPOSITING,               Feature,      "Compositing")                    \
   _(D3D11_COMPOSITING,            Feature,      "Direct3D11 Compositing")         \
+  _(D3D9_COMPOSITING,             Feature,      "Direct3D9 Compositing")          \
   _(DIRECT2D,                     Feature,      "Direct2D")                       \
   /* Add new entries above this comment */
 
 enum class Feature : uint32_t {
 #define MAKE_ENUM(name, type, desc) name,
   GFX_FEATURE_MAP(MAKE_ENUM)
 #undef MAKE_ENUM
   NumValues
--- a/gfx/layers/d3d9/CompositorD3D9.cpp
+++ b/gfx/layers/d3d9/CompositorD3D9.cpp
@@ -37,18 +37,16 @@ CompositorD3D9::~CompositorD3D9()
   mDeviceManager = nullptr;
 }
 
 bool
 CompositorD3D9::Initialize()
 {
   ScopedGfxFeatureReporter reporter("D3D9 Layers");
 
-  MOZ_ASSERT(gfxPlatform::CanUseDirect3D9());
-
   mDeviceManager = gfxWindowsPlatform::GetPlatform()->GetD3D9DeviceManager();
   if (!mDeviceManager) {
     return false;
   }
 
   mSwapChain = mDeviceManager->CreateSwapChain(mWidget->AsWindowsProxy()->GetHwnd());
   if (!mSwapChain) {
     return false;
--- a/gfx/thebes/gfxPlatform.cpp
+++ b/gfx/thebes/gfxPlatform.cpp
@@ -2050,17 +2050,16 @@ gfxPlatform::OptimalFormatForContent(gfx
 
 /**
  * There are a number of layers acceleration (or layers in general) preferences
  * that should be consistent for the lifetime of the application (bug 840967).
  * As such, we will evaluate them all as soon as one of them is evaluated
  * and remember the values.  Changing these preferences during the run will
  * not have any effect until we restart.
  */
-static bool sLayersSupportsD3D9 = false;
 bool gANGLESupportsD3D11 = false;
 static bool sLayersSupportsHardwareVideoDecoding = false;
 static bool sLayersHardwareVideoDecodingFailed = false;
 static bool sBufferRotationCheckPref = true;
 static bool sPrefBrowserTabsRemoteAutostart = false;
 
 static bool sLayersAccelerationPrefsInitialized = false;
 
@@ -2081,25 +2080,17 @@ gfxPlatform::InitAcceleration()
 
   gfxPrefs::GetSingleton();
   sPrefBrowserTabsRemoteAutostart = BrowserTabsRemoteAutostart();
 
   nsCOMPtr<nsIGfxInfo> gfxInfo = services::GetGfxInfo();
   nsCString discardFailureId;
   int32_t status;
 #ifdef XP_WIN
-  if (gfxConfig::IsForcedOnByUser(Feature::HW_COMPOSITING)) {
-    sLayersSupportsD3D9 = true;
-  } else if (!gfxPrefs::LayersAccelerationDisabledDoNotUseDirectly() && gfxInfo) {
-    if (NS_SUCCEEDED(gfxInfo->GetFeatureStatus(nsIGfxInfo::FEATURE_DIRECT3D_9_LAYERS, discardFailureId, &status))) {
-      if (status == nsIGfxInfo::FEATURE_STATUS_OK) {
-        MOZ_ASSERT(!sPrefBrowserTabsRemoteAutostart || IsVistaOrLater());
-        sLayersSupportsD3D9 = true;
-      }
-    }
+  if (!gfxPrefs::LayersAccelerationDisabledDoNotUseDirectly() && gfxInfo) {
     if (NS_SUCCEEDED(gfxInfo->GetFeatureStatus(nsIGfxInfo::FEATURE_DIRECT3D_11_ANGLE, discardFailureId, &status))) {
       if (status == nsIGfxInfo::FEATURE_STATUS_OK) {
         gANGLESupportsD3D11 = true;
       }
     }
   }
 #endif
 
@@ -2151,25 +2142,16 @@ gfxPlatform::InitCompositorAccelerationP
 
   // Safe mode trumps everything.
   if (InSafeMode()) {
     feature.ForceDisable(FeatureStatus::Blocked, "Acceleration blocked by safe-mode");
   }
 }
 
 bool
-gfxPlatform::CanUseDirect3D9()
-{
-  // this function is called from the compositor thread, so it is not
-  // safe to init the prefs etc. from here.
-  MOZ_ASSERT(sLayersAccelerationPrefsInitialized);
-  return sLayersSupportsD3D9;
-}
-
-bool
 gfxPlatform::CanUseHardwareVideoDecoding()
 {
   // this function is called from the compositor thread, so it is not
   // safe to init the prefs etc. from here.
   MOZ_ASSERT(sLayersAccelerationPrefsInitialized);
   return sLayersSupportsHardwareVideoDecoding && !sLayersHardwareVideoDecodingFailed;
 }
 
--- a/gfx/thebes/gfxPlatform.h
+++ b/gfx/thebes/gfxPlatform.h
@@ -444,17 +444,16 @@ public:
         // platform-specific override, by default do nothing
     }
 
     // Are we in safe mode?
     static bool InSafeMode();
 
     static bool OffMainThreadCompositingEnabled();
 
-    static bool CanUseDirect3D9();
     virtual bool CanUseHardwareVideoDecoding();
     virtual bool CanUseDirect3D11ANGLE() { return false; }
 
     // Returns a prioritized list of all available compositor backends.
     void GetCompositorBackends(bool useAcceleration, nsTArray<mozilla::layers::LayersBackend>& aBackends);
 
     /**
      * Is it possible to use buffer rotation.  Note that these
--- a/gfx/thebes/gfxWindowsPlatform.cpp
+++ b/gfx/thebes/gfxWindowsPlatform.cpp
@@ -1951,21 +1951,52 @@ IsWARPStable()
 void
 gfxWindowsPlatform::InitializeConfig()
 {
   if (!XRE_IsParentProcess()) {
     // Child processes init their configuration via UpdateDeviceInitData().
     return;
   }
 
+  InitializeD3D9Config();
   InitializeD3D11Config();
   InitializeD2DConfig();
 }
 
 void
+gfxWindowsPlatform::InitializeD3D9Config()
+{
+  MOZ_ASSERT(XRE_IsParentProcess());
+
+  FeatureState& d3d9 = gfxConfig::GetFeature(Feature::D3D9_COMPOSITING);
+
+  if (!IsVistaOrLater()) {
+    d3d9.EnableByDefault();
+  } else {
+    d3d9.SetDefaultFromPref(
+      gfxPrefs::GetLayersAllowD3D9FallbackPrefName(),
+      true,
+      gfxPrefs::GetLayersAllowD3D9FallbackPrefDefault());
+
+    if (!d3d9.IsEnabled() && gfxPrefs::LayersPreferD3D9()) {
+      d3d9.UserEnable("Direct3D9 enabled via layers.prefer-d3d9");
+    }
+  }
+
+  nsCString message;
+  if (!IsGfxInfoStatusOkay(nsIGfxInfo::FEATURE_DIRECT3D_9_LAYERS, &message)) {
+    d3d9.Disable(FeatureStatus::Blacklisted, message.get());
+  }
+
+  if (gfxConfig::IsForcedOnByUser(Feature::HW_COMPOSITING)) {
+    d3d9.UserForceEnable("Hardware compositing is force-enabled");
+  }
+}
+
+void
 gfxWindowsPlatform::InitializeD3D11Config()
 {
   MOZ_ASSERT(XRE_IsParentProcess());
 
   FeatureState& d3d11 = gfxConfig::GetFeature(Feature::D3D11_COMPOSITING);
 
   if (!gfxConfig::IsEnabled(Feature::HW_COMPOSITING)) {
     d3d11.DisableByDefault(FeatureStatus::Unavailable, "Hardware compositing is disabled");
@@ -2884,33 +2915,28 @@ gfxWindowsPlatform::SupportsApzTouchInpu
 
 void
 gfxWindowsPlatform::GetAcceleratedCompositorBackends(nsTArray<LayersBackend>& aBackends)
 {
   if (gfxPrefs::LayersPreferOpenGL()) {
     aBackends.AppendElement(LayersBackend::LAYERS_OPENGL);
   }
 
-  bool allowTryingD3D9 = false;
-  if (!gfxPrefs::LayersPreferD3D9()) {
-    if (mD3D11Device) {
-      aBackends.AppendElement(LayersBackend::LAYERS_D3D11);
-    } else {
-      allowTryingD3D9 = gfxPrefs::LayersAllowD3D9Fallback();
-      NS_WARNING("Direct3D 11-accelerated layers are not supported on this system.");
-    }
+  if (gfxConfig::IsEnabled(Feature::D3D9_COMPOSITING) && gfxPrefs::LayersPreferD3D9()) {
+    aBackends.AppendElement(LayersBackend::LAYERS_D3D9);
   }
 
-  if (gfxPrefs::LayersPreferD3D9() || !IsVistaOrLater() || allowTryingD3D9) {
-    // We don't want D3D9 except on Windows XP, unless we failed to get D3D11
-    if (gfxPlatform::CanUseDirect3D9()) {
-      aBackends.AppendElement(LayersBackend::LAYERS_D3D9);
-    } else {
-      NS_WARNING("Direct3D 9-accelerated layers are not supported on this system.");
-    }
+  if (mD3D11Device) {
+    aBackends.AppendElement(LayersBackend::LAYERS_D3D11);
+  } else {
+    NS_WARNING("Direct3D 11-accelerated layers are not supported on this system.");
+  }
+
+  if (gfxConfig::IsEnabled(Feature::D3D9_COMPOSITING) && !gfxPrefs::LayersPreferD3D9()) {
+    aBackends.AppendElement(LayersBackend::LAYERS_D3D9);
   }
 }
 
 unsigned
 gfxWindowsPlatform::GetD3D11Version()
 {
   RefPtr<ID3D11Device> device;
   if (!GetD3D11Device(&device)) {
--- a/gfx/thebes/gfxWindowsPlatform.h
+++ b/gfx/thebes/gfxWindowsPlatform.h
@@ -285,16 +285,17 @@ private:
     void InitializeDevices();
     void InitializeD3D11();
     void InitializeD2D();
     bool InitDWriteSupport();
 
     void DisableD2D(mozilla::gfx::FeatureStatus aStatus, const char* aMessage);
 
     void InitializeConfig();
+    void InitializeD3D9Config();
     void InitializeD3D11Config();
     void InitializeD2DConfig();
 
     void AttemptD3D11DeviceCreation(mozilla::gfx::FeatureState& d3d11);
     bool AttemptD3D11DeviceCreationHelper(
         IDXGIAdapter1* aAdapter,
         RefPtr<ID3D11Device>& aOutDevice,
         HRESULT& aResOut);