Bug 1369549 - Bootstrap a painting thread for OMTP. r=dvander
authordomfarolino@gmail.com <domfarolino@gmail.com>
Fri, 09 Jun 2017 16:30:00 -0400
changeset 363983 9a0520e85036
parent 363982 64a340c2f80a
child 363984 b9041ef8daa5
push id32029
push userarchaeopteryx@coole-files.de
push dateThu, 15 Jun 2017 08:54:25 +0000
treeherdermozilla-central@dced94de288a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdvander
bugs1369549
milestone56.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 1369549 - Bootstrap a painting thread for OMTP. r=dvander
gfx/layers/PaintThread.cpp
gfx/layers/PaintThread.h
gfx/layers/moz.build
gfx/thebes/gfxPlatform.cpp
new file mode 100644
--- /dev/null
+++ b/gfx/layers/PaintThread.cpp
@@ -0,0 +1,64 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=8 sts=2 et sw=2 tw=99: */
+/* 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 "PaintThread.h"
+
+namespace mozilla {
+namespace layers {
+
+StaticAutoPtr<PaintThread> PaintThread::sSingleton;
+
+bool
+PaintThread::Init()
+{
+  MOZ_ASSERT(NS_IsMainThread());
+  nsresult rv = NS_NewNamedThread("PaintThread", getter_AddRefs(PaintThread::sSingleton->mThread));
+
+  if (NS_FAILED(rv)) {
+    return false;
+  }
+
+  return true;
+}
+
+/* static */ void
+PaintThread::Start()
+{
+  PaintThread::sSingleton = new PaintThread();
+
+  if (!PaintThread::sSingleton->Init()) {
+    gfxCriticalNote << "Unable to start paint thread";
+    PaintThread::sSingleton = nullptr;
+  }
+}
+
+/* static */ PaintThread*
+PaintThread::Get()
+{
+  MOZ_ASSERT(NS_IsMainThread());
+  return PaintThread::sSingleton.get();
+}
+
+/* static */ void
+PaintThread::Shutdown()
+{
+  if (!PaintThread::sSingleton) {
+    return;
+  }
+
+  PaintThread::sSingleton->ShutdownImpl();
+  PaintThread::sSingleton = nullptr;
+}
+
+void
+PaintThread::ShutdownImpl()
+{
+  MOZ_ASSERT(NS_IsMainThread());
+  PaintThread::sSingleton->mThread->AsyncShutdown();
+}
+
+} // namespace layers
+} // namespace mozilla
\ No newline at end of file
new file mode 100644
--- /dev/null
+++ b/gfx/layers/PaintThread.h
@@ -0,0 +1,33 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set sw=2 sts=2 ts=8 et tw=99 : */
+/* 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/. */
+
+#ifndef MOZILLA_LAYERS_PAINTTHREAD_H
+#define MOZILLA_LAYERS_PAINTTHREAD_H
+
+#include "mozilla/StaticPtr.h"
+#include "nsThreadUtils.h"
+
+namespace mozilla {
+namespace layers {
+
+class PaintThread final
+{
+public:
+  static void Start();
+  static void Shutdown();
+  static PaintThread* Get();
+
+private:
+  bool Init();
+  void ShutdownImpl();
+  static StaticAutoPtr<PaintThread> sSingleton;
+  RefPtr<nsIThread> mThread;
+};
+
+} // namespace layers
+} // namespace mozilla
+
+#endif
\ No newline at end of file
--- a/gfx/layers/moz.build
+++ b/gfx/layers/moz.build
@@ -191,16 +191,17 @@ EXPORTS.mozilla.layers += [
     'LayerMetricsWrapper.h',
     'LayersTypes.h',
     'opengl/CompositingRenderTargetOGL.h',
     'opengl/CompositorOGL.h',
     'opengl/MacIOSurfaceTextureClientOGL.h',
     'opengl/MacIOSurfaceTextureHostOGL.h',
     'opengl/TextureClientOGL.h',
     'opengl/TextureHostOGL.h',
+    'PaintThread.h',
     'PersistentBufferProvider.h',
     'RenderTrace.h',
     'SourceSurfaceSharedData.h',
     'SourceSurfaceVolatileData.h',
     'TextureSourceProvider.h',
     'TextureWrapperImage.h',
     'TransactionIdAllocator.h',
     'UpdateImageHelper.h',
@@ -387,16 +388,17 @@ UNIFIED_SOURCES += [
     'LayersTypes.cpp',
     'opengl/CompositingRenderTargetOGL.cpp',
     'opengl/CompositorOGL.cpp',
     'opengl/GLBlitTextureImageHelper.cpp',
     'opengl/OGLShaderProgram.cpp',
     'opengl/TextureClientOGL.cpp',
     'opengl/TextureHostOGL.cpp',
     'opengl/TexturePoolOGL.cpp',
+    'PaintThread.cpp',
     'protobuf/LayerScopePacket.pb.cc',
     'ReadbackProcessor.cpp',
     'RenderTrace.cpp',
     'RotatedBuffer.cpp',
     'ShareableCanvasLayer.cpp',
     'SourceSurfaceSharedData.cpp',
     'SourceSurfaceVolatileData.cpp',
     'TextureSourceProvider.cpp',
--- a/gfx/thebes/gfxPlatform.cpp
+++ b/gfx/thebes/gfxPlatform.cpp
@@ -3,16 +3,17 @@
  * 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/layers/CompositorBridgeChild.h"
 #include "mozilla/layers/CompositorThread.h"
 #include "mozilla/layers/ImageBridgeChild.h"
 #include "mozilla/layers/ISurfaceAllocator.h"     // for GfxMemoryImageReporter
 #include "mozilla/webrender/RenderThread.h"
+#include "mozilla/layers/PaintThread.h"
 #include "mozilla/gfx/gfxVars.h"
 #include "mozilla/gfx/GPUProcessManager.h"
 #include "mozilla/gfx/GraphicsMessages.h"
 #include "mozilla/ClearOnShutdown.h"
 #include "mozilla/Telemetry.h"
 #include "mozilla/TimeStamp.h"
 #include "mozilla/Unused.h"
 
@@ -938,28 +939,32 @@ gfxPlatform::Shutdown()
 
     delete gPlatform;
     gPlatform = nullptr;
 }
 
 /* static */ void
 gfxPlatform::InitLayersIPC()
 {
-    if (sLayersIPCIsUp) {
-      return;
+  if (sLayersIPCIsUp) {
+    return;
+  }
+  sLayersIPCIsUp = true;
+
+  if (XRE_IsContentProcess()) {
+    if (gfxVars::UseOMTP()) {
+      layers::PaintThread::Start();
     }
-    sLayersIPCIsUp = true;
-
-    if (XRE_IsParentProcess())
-    {
-        if (gfxVars::UseWebRender()) {
-            wr::RenderThread::Start();
-        }
-        layers::CompositorThreadHolder::Start();
+  } else if (XRE_IsParentProcess()) {
+    if (gfxVars::UseWebRender()) {
+      wr::RenderThread::Start();
     }
+
+    layers::CompositorThreadHolder::Start();
+  }
 }
 
 /* static */ void
 gfxPlatform::ShutdownLayersIPC()
 {
     if (!sLayersIPCIsUp) {
       return;
     }
@@ -967,25 +972,30 @@ gfxPlatform::ShutdownLayersIPC()
 
     if (XRE_IsContentProcess()) {
         gfx::VRManagerChild::ShutDown();
         // cf bug 1215265.
         if (gfxPrefs::ChildProcessShutdown()) {
           layers::CompositorBridgeChild::ShutDown();
           layers::ImageBridgeChild::ShutDown();
         }
+
+        if (gfxVars::UseOMTP()) {
+          layers::PaintThread::Shutdown();
+        }
     } else if (XRE_IsParentProcess()) {
         gfx::VRManagerChild::ShutDown();
         layers::CompositorBridgeChild::ShutDown();
         layers::ImageBridgeChild::ShutDown();
         // This has to happen after shutting down the child protocols.
         layers::CompositorThreadHolder::Shutdown();
         if (gfxVars::UseWebRender()) {
-            wr::RenderThread::ShutDown();
+          wr::RenderThread::ShutDown();
         }
+
     } else {
       // TODO: There are other kind of processes and we should make sure gfx
       // stuff is either not created there or shut down properly.
     }
 }
 
 void
 gfxPlatform::WillShutdown()
@@ -2425,17 +2435,17 @@ gfxPlatform::InitOMTPConfig()
   featureOMTP.DisableByDefault(
       FeatureStatus::OptIn,
       "OMTP is an opt-in feature",
       NS_LITERAL_CSTRING("FEATURE_FAILURE_DEFAULT_OFF"));
 
   featureOMTP.UserEnable("Enabled by pref");
 
   if (InSafeMode()) {
-    featureOMTP.ForceDisable(FeatureStatus::Blocked, "OMTP  blocked by safe-mode",
+    featureOMTP.ForceDisable(FeatureStatus::Blocked, "OMTP blocked by safe-mode",
                          NS_LITERAL_CSTRING("FEATURE_FAILURE_COMP_SAFEMODE"));
   }
 
   if (gfxConfig::IsEnabled(Feature::OMTP)) {
     gfxVars::SetUseOMTP(true);
     reporter.SetSuccessful();
   }
 }