Remove `layers.omtp.force-sync` preference (bug 1416941, r=dvander) draft
authorRyan Hunt <rhunt@eqrion.net>
Tue, 14 Nov 2017 14:05:55 -0500
changeset 697831 15b995a1b40f55950fffe21530143449754fd02d
parent 697830 309536e6c69c7d2bcb0db255edfd8687afe48d64
child 740217 35517f86de6ed47ab964df5b5b4d95465d2d7d51
push id89107
push userbmo:rhunt@eqrion.net
push dateTue, 14 Nov 2017 19:09:19 +0000
reviewersdvander
bugs1416941
milestone59.0a1
Remove `layers.omtp.force-sync` preference (bug 1416941, r=dvander) This commit removes the `layers.omtp.force-sync` preference and replaces it with a preprocessor define that is commented out. This commit also changes the behavior of force-sync so that it also does synchronization with CompositorBridgeChild like normal OMTP. This simplifies the code and makes using a preprocessor define easier. MozReview-Commit-ID: 6RfuFTFBdMh
gfx/layers/PaintThread.cpp
gfx/thebes/gfxPrefs.h
modules/libpref/init/all.js
--- a/gfx/layers/PaintThread.cpp
+++ b/gfx/layers/PaintThread.cpp
@@ -11,16 +11,21 @@
 #include "GeckoProfiler.h"
 #include "mozilla/layers/CompositorBridgeChild.h"
 #include "mozilla/layers/ShadowLayers.h"
 #include "mozilla/layers/SyncObject.h"
 #include "mozilla/gfx/2D.h"
 #include "mozilla/Preferences.h"
 #include "mozilla/SyncRunnable.h"
 
+// Uncomment the following line to dispatch sync runnables when
+// painting so that rasterization happens synchronously from
+// the perspective of the main thread
+// #define OMTP_FORCE_SYNC
+
 namespace mozilla {
 namespace layers {
 
 using namespace gfx;
 
 bool
 CapturedBufferState::Copy::CopyBuffer()
 {
@@ -91,20 +96,17 @@ struct MOZ_STACK_CLASS AutoCapturedPaint
     mTarget->SetTransform(aState->mCapture->GetTransform());
     mTarget->SetPermitSubpixelAA(aState->mCapture->GetPermitSubpixelAA());
   }
 
   ~AutoCapturedPaintSetup()
   {
     mTarget->SetTransform(mOldTransform);
     mTarget->SetPermitSubpixelAA(mRestorePermitsSubpixelAA);
-
-    if (mBridge) {
-      mBridge->NotifyFinishedAsyncPaint(mState);
-    }
+    mBridge->NotifyFinishedAsyncPaint(mState);
   }
 
   RefPtr<CapturedPaintState> mState;
   RefPtr<DrawTarget> mTarget;
   bool mRestorePermitsSubpixelAA;
   Matrix mOldTransform;
   RefPtr<CompositorBridgeChild> mBridge;
 };
@@ -214,36 +216,34 @@ void
 PaintThread::PrepareBuffer(CapturedBufferState* aState)
 {
   MOZ_ASSERT(NS_IsMainThread());
   MOZ_ASSERT(aState);
 
   // If painting asynchronously, we need to acquire the compositor bridge which
   // owns the underlying MessageChannel. Otherwise we leave it null and use
   // synchronous dispatch.
-  RefPtr<CompositorBridgeChild> cbc;
-  if (!gfxPrefs::LayersOMTPForceSync()) {
-    cbc = CompositorBridgeChild::Get();
-    cbc->NotifyBeginAsyncPrepareBuffer(aState);
-  }
+  RefPtr<CompositorBridgeChild> cbc(CompositorBridgeChild::Get());
   RefPtr<CapturedBufferState> state(aState);
 
+  cbc->NotifyBeginAsyncPrepareBuffer(state);
+
   RefPtr<PaintThread> self = this;
   RefPtr<Runnable> task = NS_NewRunnableFunction("PaintThread::PrepareBuffer",
     [self, cbc, state]() -> void
   {
     self->AsyncPrepareBuffer(cbc,
                              state);
   });
 
-  if (cbc) {
-    sThread->Dispatch(task.forget());
-  } else {
-    SyncRunnable::DispatchToThread(sThread, task);
-  }
+#ifndef OMTP_FORCE_SYNC
+  sThread->Dispatch(task.forget());
+#else
+  SyncRunnable::DispatchToThread(sThread, task);
+#endif
 }
 
 void
 PaintThread::AsyncPrepareBuffer(CompositorBridgeChild* aBridge,
                                 CapturedBufferState* aState)
 {
   MOZ_ASSERT(IsOnPaintThread());
   MOZ_ASSERT(aState);
@@ -252,52 +252,45 @@ PaintThread::AsyncPrepareBuffer(Composit
     mInAsyncPaintGroup = true;
     PROFILER_TRACING("Paint", "Rasterize", TRACING_INTERVAL_START);
   }
 
   if (!aState->PrepareBuffer()) {
     gfxCriticalNote << "Failed to prepare buffers on the paint thread.";
   }
 
-  if (aBridge) {
-    aBridge->NotifyFinishedAsyncPrepareBuffer(aState);
-  }
+  aBridge->NotifyFinishedAsyncPrepareBuffer(aState);
 }
 
 void
 PaintThread::PaintContents(CapturedPaintState* aState,
                            PrepDrawTargetForPaintingCallback aCallback)
 {
   MOZ_ASSERT(NS_IsMainThread());
   MOZ_ASSERT(aState);
 
-  // If painting asynchronously, we need to acquire the compositor bridge which
-  // owns the underlying MessageChannel. Otherwise we leave it null and use
-  // synchronous dispatch.
-  RefPtr<CompositorBridgeChild> cbc;
-  if (!gfxPrefs::LayersOMTPForceSync()) {
-    cbc = CompositorBridgeChild::Get();
-    cbc->NotifyBeginAsyncPaint(aState);
-  }
+  RefPtr<CompositorBridgeChild> cbc(CompositorBridgeChild::Get());
   RefPtr<CapturedPaintState> state(aState);
 
+  cbc->NotifyBeginAsyncPaint(state);
+
   RefPtr<PaintThread> self = this;
   RefPtr<Runnable> task = NS_NewRunnableFunction("PaintThread::PaintContents",
     [self, cbc, state, aCallback]() -> void
   {
     self->AsyncPaintContents(cbc,
                              state,
                              aCallback);
   });
 
-  if (cbc) {
-    sThread->Dispatch(task.forget());
-  } else {
-    SyncRunnable::DispatchToThread(sThread, task);
-  }
+#ifndef OMTP_FORCE_SYNC
+  sThread->Dispatch(task.forget());
+#else
+  SyncRunnable::DispatchToThread(sThread, task);
+#endif
 }
 
 void
 PaintThread::AsyncPaintContents(CompositorBridgeChild* aBridge,
                                 CapturedPaintState* aState,
                                 PrepDrawTargetForPaintingCallback aCallback)
 {
   MOZ_ASSERT(IsOnPaintThread());
@@ -338,21 +331,21 @@ PaintThread::EndLayer()
 
   RefPtr<PaintThread> self = this;
   RefPtr<Runnable> task = NS_NewRunnableFunction("PaintThread::AsyncEndLayer",
   [self]() -> void
   {
     self->AsyncEndLayer();
   });
 
-  if (!gfxPrefs::LayersOMTPForceSync()) {
-    sThread->Dispatch(task.forget());
-  } else {
-    SyncRunnable::DispatchToThread(sThread, task);
-  }
+#ifndef OMTP_FORCE_SYNC
+  sThread->Dispatch(task.forget());
+#else
+  SyncRunnable::DispatchToThread(sThread, task);
+#endif
 }
 
 void
 PaintThread::AsyncEndLayer()
 {
   MOZ_ASSERT(IsOnPaintThread());
   // Textureclient forces a flush once we "end paint", so
   // users of this texture expect all the drawing to be complete.
@@ -364,50 +357,46 @@ PaintThread::AsyncEndLayer()
   mDrawTargetsToFlush.Clear();
 }
 
 void
 PaintThread::EndLayerTransaction(SyncObjectClient* aSyncObject)
 {
   MOZ_ASSERT(NS_IsMainThread());
 
-  RefPtr<CompositorBridgeChild> cbc;
-  if (!gfxPrefs::LayersOMTPForceSync()) {
-    cbc = CompositorBridgeChild::Get();
-    cbc->NotifyBeginAsyncEndLayerTransaction();
-  }
+  RefPtr<CompositorBridgeChild> cbc(CompositorBridgeChild::Get());
+  RefPtr<SyncObjectClient> syncObject(aSyncObject);
 
-  RefPtr<SyncObjectClient> syncObject(aSyncObject);
+  cbc->NotifyBeginAsyncEndLayerTransaction();
+
   RefPtr<PaintThread> self = this;
   RefPtr<Runnable> task = NS_NewRunnableFunction("PaintThread::AsyncEndLayerTransaction",
     [self, cbc, syncObject]() -> void
   {
     self->AsyncEndLayerTransaction(cbc, syncObject);
   });
 
-  if (cbc) {
-    sThread->Dispatch(task.forget());
-  } else {
-    SyncRunnable::DispatchToThread(sThread, task);
-  }
+#ifndef OMTP_FORCE_SYNC
+  sThread->Dispatch(task.forget());
+#else
+  SyncRunnable::DispatchToThread(sThread, task);
+#endif
 }
 
 void
 PaintThread::AsyncEndLayerTransaction(CompositorBridgeChild* aBridge,
                                       SyncObjectClient* aSyncObject)
 {
   MOZ_ASSERT(IsOnPaintThread());
   MOZ_ASSERT(mInAsyncPaintGroup);
 
   if (aSyncObject) {
     aSyncObject->Synchronize();
   }
 
   mInAsyncPaintGroup = false;
   PROFILER_TRACING("Paint", "Rasterize", TRACING_INTERVAL_END);
 
-  if (aBridge) {
-    aBridge->NotifyFinishedAsyncEndLayerTransaction();
-  }
+  aBridge->NotifyFinishedAsyncEndLayerTransaction();
 }
 
 } // namespace layers
 } // namespace mozilla
--- a/gfx/thebes/gfxPrefs.h
+++ b/gfx/thebes/gfxPrefs.h
@@ -593,17 +593,16 @@ private:
   DECL_GFX_PREF(Once, "layers.mlgpu.enable-clear-view",        AdvancedLayersEnableClearView, bool, true);
   DECL_GFX_PREF(Once, "layers.mlgpu.enable-cpu-occlusion",     AdvancedLayersEnableCPUOcclusion, bool, true);
   DECL_GFX_PREF(Once, "layers.mlgpu.enable-depth-buffer",      AdvancedLayersEnableDepthBuffer, bool, false);
   DECL_GFX_PREF(Live, "layers.mlgpu.enable-invalidation",      AdvancedLayersUseInvalidation, bool, true);
   DECL_GFX_PREF(Once, "layers.mlgpu.enable-on-windows7",       AdvancedLayersEnableOnWindows7, bool, false);
   DECL_GFX_PREF(Once, "layers.mlgpu.enable-container-resizing", AdvancedLayersEnableContainerResizing, bool, true);
   DECL_GFX_PREF(Once, "layers.offmainthreadcomposition.force-disabled", LayersOffMainThreadCompositionForceDisabled, bool, false);
   DECL_GFX_PREF(Live, "layers.offmainthreadcomposition.frame-rate", LayersCompositionFrameRate, int32_t,-1);
-  DECL_GFX_PREF(Live, "layers.omtp.force-sync",                LayersOMTPForceSync, bool, false);
   DECL_GFX_PREF(Live, "layers.omtp.release-capture-on-main-thread", LayersOMTPReleaseCaptureOnMainThread, bool, false);
   DECL_GFX_PREF(Live, "layers.orientation.sync.timeout",       OrientationSyncMillis, uint32_t, (uint32_t)0);
   DECL_GFX_PREF(Once, "layers.prefer-opengl",                  LayersPreferOpenGL, bool, false);
   DECL_GFX_PREF(Live, "layers.progressive-paint",              ProgressivePaint, bool, false);
   DECL_GFX_PREF(Live, "layers.shared-buffer-provider.enabled", PersistentBufferProviderSharedEnabled, bool, false);
   DECL_GFX_PREF(Live, "layers.single-tile.enabled",            LayersSingleTileEnabled, bool, true);
   DECL_GFX_PREF(Live, "layers.force-synchronous-resize",       LayersForceSynchronousResize, bool, true);
 
--- a/modules/libpref/init/all.js
+++ b/modules/libpref/init/all.js
@@ -5898,9 +5898,8 @@ pref("toolkit.crashreporter.include_cont
 pref("dom.noopener.newprocess.enabled", true);
 
 #ifdef XP_WIN
 pref("layers.omtp.enabled", true);
 #else
 pref("layers.omtp.enabled", false);
 #endif
 pref("layers.omtp.release-capture-on-main-thread", false);
-pref("layers.omtp.force-sync", false);