Bug 1369549 - Bootstrap a painting thread for OMTP. r=dvander

--HG--
extra : rebase_source : bae591cdace1197a6b4d3a489a46bdaab5293d23
This commit is contained in:
domfarolino@gmail.com 2017-06-09 16:30:00 -04:00
parent e218041b0a
commit 5450eab623
4 changed files with 121 additions and 12 deletions

View File

@ -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

33
gfx/layers/PaintThread.h Normal file
View File

@ -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

View File

@ -196,6 +196,7 @@ EXPORTS.mozilla.layers += [
'opengl/MacIOSurfaceTextureHostOGL.h',
'opengl/TextureClientOGL.h',
'opengl/TextureHostOGL.h',
'PaintThread.h',
'PersistentBufferProvider.h',
'RenderTrace.h',
'SourceSurfaceSharedData.h',
@ -392,6 +393,7 @@ UNIFIED_SOURCES += [
'opengl/TextureClientOGL.cpp',
'opengl/TextureHostOGL.cpp',
'opengl/TexturePoolOGL.cpp',
'PaintThread.cpp',
'protobuf/LayerScopePacket.pb.cc',
'ReadbackProcessor.cpp',
'RenderTrace.cpp',

View File

@ -8,6 +8,7 @@
#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"
@ -943,18 +944,22 @@ gfxPlatform::Shutdown()
/* static */ void
gfxPlatform::InitLayersIPC()
{
if (sLayersIPCIsUp) {
return;
}
sLayersIPCIsUp = true;
if (sLayersIPCIsUp) {
return;
}
sLayersIPCIsUp = true;
if (XRE_IsParentProcess())
{
if (gfxVars::UseWebRender()) {
wr::RenderThread::Start();
}
layers::CompositorThreadHolder::Start();
if (XRE_IsContentProcess()) {
if (gfxVars::UseOMTP()) {
layers::PaintThread::Start();
}
} else if (XRE_IsParentProcess()) {
if (gfxVars::UseWebRender()) {
wr::RenderThread::Start();
}
layers::CompositorThreadHolder::Start();
}
}
/* static */ void
@ -972,6 +977,10 @@ gfxPlatform::ShutdownLayersIPC()
layers::CompositorBridgeChild::ShutDown();
layers::ImageBridgeChild::ShutDown();
}
if (gfxVars::UseOMTP()) {
layers::PaintThread::Shutdown();
}
} else if (XRE_IsParentProcess()) {
gfx::VRManagerChild::ShutDown();
layers::CompositorBridgeChild::ShutDown();
@ -979,8 +988,9 @@ gfxPlatform::ShutdownLayersIPC()
// 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.
@ -2430,7 +2440,7 @@ gfxPlatform::InitOMTPConfig()
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"));
}