Bug 1539892 - replace FeatureChange and GPUDeviceStatus IPDL unions with native Maybe syntax; r=mattwoodrow
authorAlex Gaynor <agaynor@mozilla.com>
Thu, 28 Mar 2019 21:13:53 +0000
changeset 466775 5a70120ae2d349d2ad8a8ac3530f4bd390677d92
parent 466774 62c0925f8e1dd9b6f17016ccf553ac7b0248a304
child 466776 65f80cb57b308ce1aa3120fabb8135b2f659a8b4
push id35780
push useropoprus@mozilla.com
push dateFri, 29 Mar 2019 21:53:01 +0000
treeherdermozilla-central@414f37afbe07 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmattwoodrow
bugs1539892
milestone68.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1539892 - replace FeatureChange and GPUDeviceStatus IPDL unions with native Maybe syntax; r=mattwoodrow Differential Revision: https://phabricator.services.mozilla.com/D25259
gfx/config/gfxConfig.cpp
gfx/config/gfxConfig.h
gfx/ipc/GPUParent.cpp
gfx/ipc/GraphicsMessages.ipdlh
gfx/thebes/gfxWindowsPlatform.cpp
--- a/gfx/config/gfxConfig.cpp
+++ b/gfx/config/gfxConfig.cpp
@@ -235,22 +235,23 @@ void gfxConfig::ForEachFallbackImpl(cons
 }
 
 /* static */ const nsCString& gfxConfig::GetFailureId(Feature aFeature) {
   const FeatureState& state = sConfig->GetState(aFeature);
   return state.GetFailureId();
 }
 
 /* static */
-void gfxConfig::ImportChange(Feature aFeature, const FeatureChange& aChange) {
-  if (aChange.type() == FeatureChange::Tnull_t) {
+void gfxConfig::ImportChange(Feature aFeature,
+                             const Maybe<FeatureFailure>& aChange) {
+  if (aChange.isNothing()) {
     return;
   }
 
-  const FeatureFailure& failure = aChange.get_FeatureFailure();
+  const FeatureFailure& failure = aChange.ref();
   gfxConfig::SetFailed(aFeature, failure.status(), failure.message().get(),
                        failure.failureId());
 }
 
 /* static */
 void gfxConfig::Init() { sConfig = mozilla::MakeUnique<gfxConfig>(); }
 
 /* static */
--- a/gfx/config/gfxConfig.h
+++ b/gfx/config/gfxConfig.h
@@ -5,22 +5,23 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 #ifndef mozilla_gfx_config_gfxConfig_h
 #define mozilla_gfx_config_gfxConfig_h
 
 #include <functional>
 #include "gfxFeature.h"
 #include "gfxFallback.h"
 #include "mozilla/Assertions.h"
+#include "mozilla/Maybe.h"
 
 namespace mozilla {
 namespace gfx {
 
 // Defined in GraphicsMessages.ipdlh.
-class FeatureChange;
+class FeatureFailure;
 
 // Manages the history and state of a graphics feature. The flow of a feature
 // is:
 //   - A default value, set by all.js, gfxPrefs, or gfxPlatform.
 //   - A user value, set by an external value or user pref.
 //   - An environment value, determined by system/hardware factors or
 //   nsIGfxInfo.
 //   - A runtime value, determined by any failures encountered after enabling
@@ -166,17 +167,18 @@ class gfxConfig {
   // Run a callback for each enabled fallback.
   typedef std::function<void(const char* aName, const char* aMsg)>
       FallbackIterCallback;
   static void ForEachFallback(const FallbackIterCallback& aCallback);
 
   // Get the most descriptive failure id message for this feature.
   static const nsCString& GetFailureId(Feature aFeature);
 
-  static void ImportChange(Feature aFeature, const FeatureChange& aChange);
+  static void ImportChange(Feature aFeature,
+                           const Maybe<FeatureFailure>& aChange);
 
   static void Init();
   static void Shutdown();
 
  private:
   void ForEachFallbackImpl(const FallbackIterCallback& aCallback);
 
  private:
--- a/gfx/ipc/GPUParent.cpp
+++ b/gfx/ipc/GPUParent.cpp
@@ -316,50 +316,51 @@ mozilla::ipc::IPCResult GPUParent::RecvU
   return IPC_OK();
 }
 
 mozilla::ipc::IPCResult GPUParent::RecvUpdateVar(const GfxVarUpdate& aUpdate) {
   gfxVars::ApplyUpdate(aUpdate);
   return IPC_OK();
 }
 
-static void CopyFeatureChange(Feature aFeature, FeatureChange* aOut) {
+static void CopyFeatureChange(Feature aFeature, Maybe<FeatureFailure>* aOut) {
   FeatureState& feature = gfxConfig::GetFeature(aFeature);
   if (feature.DisabledByDefault() || feature.IsEnabled()) {
     // No change:
     //   - Disabled-by-default means the parent process told us not to use this
     //   feature.
     //   - Enabled means we were told to use this feature, and we didn't
     //   discover anything
     //     that would prevent us from doing so.
-    *aOut = null_t();
+    *aOut = Nothing();
     return;
   }
 
   MOZ_ASSERT(!feature.IsEnabled());
 
   nsCString message;
   message.AssignASCII(feature.GetFailureMessage());
 
-  *aOut = FeatureFailure(feature.GetValue(), message, feature.GetFailureId());
+  *aOut =
+      Some(FeatureFailure(feature.GetValue(), message, feature.GetFailureId()));
 }
 
 mozilla::ipc::IPCResult GPUParent::RecvGetDeviceStatus(GPUDeviceData* aOut) {
   CopyFeatureChange(Feature::D3D11_COMPOSITING, &aOut->d3d11Compositing());
   CopyFeatureChange(Feature::OPENGL_COMPOSITING, &aOut->oglCompositing());
   CopyFeatureChange(Feature::ADVANCED_LAYERS, &aOut->advancedLayers());
 
 #if defined(XP_WIN)
   if (DeviceManagerDx* dm = DeviceManagerDx::Get()) {
     D3D11DeviceStatus deviceStatus;
     dm->ExportDeviceInfo(&deviceStatus);
-    aOut->gpuDevice() = deviceStatus;
+    aOut->gpuDevice() = Some(deviceStatus);
   }
 #else
-  aOut->gpuDevice() = null_t();
+  aOut->gpuDevice() = Nothing();
 #endif
 
   return IPC_OK();
 }
 
 mozilla::ipc::IPCResult GPUParent::RecvSimulateDeviceReset(
     GPUDeviceData* aOut) {
 #if defined(XP_WIN)
--- a/gfx/ipc/GraphicsMessages.ipdlh
+++ b/gfx/ipc/GraphicsMessages.ipdlh
@@ -58,36 +58,24 @@ struct ContentDeviceData
 // Represents the state of a feature that has failed to initialize.
 struct FeatureFailure
 {
   FeatureStatus status;
   nsCString message;
   nsCString failureId;
 };
 
-// If a feature state has changed from Enabled -> Failure, this will be non-
-// null.
-union FeatureChange
-{
-  null_t;
-  FeatureFailure;
-};
-
-union GPUDeviceStatus
-{
-  null_t;
-  D3D11DeviceStatus;
-};
-
 struct GPUDeviceData
 {
-  FeatureChange d3d11Compositing;
-  FeatureChange oglCompositing;
-  FeatureChange advancedLayers;
-  GPUDeviceStatus gpuDevice;
+  // If a feature state has changed from Enabled -> Failure, these will be non-
+  // null.
+  FeatureFailure? d3d11Compositing;
+  FeatureFailure? oglCompositing;
+  FeatureFailure? advancedLayers;
+  D3D11DeviceStatus? gpuDevice;
 };
 
 union GfxVarValue
 {
   BackendType;
   bool;
   gfxImageFormat;
   IntSize;
--- a/gfx/thebes/gfxWindowsPlatform.cpp
+++ b/gfx/thebes/gfxWindowsPlatform.cpp
@@ -1958,17 +1958,17 @@ void gfxWindowsPlatform::ImportGPUDevice
   MOZ_ASSERT(XRE_IsParentProcess());
 
   gfxPlatform::ImportGPUDeviceData(aData);
 
   gfxConfig::ImportChange(Feature::D3D11_COMPOSITING, aData.d3d11Compositing());
 
   DeviceManagerDx* dm = DeviceManagerDx::Get();
   if (gfxConfig::IsEnabled(Feature::D3D11_COMPOSITING)) {
-    dm->ImportDeviceInfo(aData.gpuDevice().get_D3D11DeviceStatus());
+    dm->ImportDeviceInfo(aData.gpuDevice().ref());
   } else {
     // There should be no devices, so this just takes away the device status.
     dm->ResetDevices();
 
     // Make sure we disable D2D if content processes might use it.
     FeatureState& d2d1 = gfxConfig::GetFeature(Feature::DIRECT2D);
     if (d2d1.IsEnabled()) {
       d2d1.SetFailed(FeatureStatus::Unavailable,