2016-06-11 05:27:24 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/* 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 "GPUParent.h"
|
|
|
|
#include "gfxConfig.h"
|
2016-07-20 07:11:44 +03:00
|
|
|
#include "gfxPlatform.h"
|
2016-06-27 09:33:20 +03:00
|
|
|
#include "gfxPrefs.h"
|
2016-06-11 05:27:24 +03:00
|
|
|
#include "GPUProcessHost.h"
|
|
|
|
#include "mozilla/Assertions.h"
|
2016-08-04 21:33:42 +03:00
|
|
|
#include "mozilla/gfx/gfxVars.h"
|
2016-06-11 05:27:24 +03:00
|
|
|
#include "mozilla/ipc/ProcessChild.h"
|
2016-08-29 16:18:00 +03:00
|
|
|
#include "mozilla/layers/APZThreadUtils.h"
|
2016-08-31 23:00:00 +03:00
|
|
|
#include "mozilla/layers/APZCTreeManager.h"
|
2016-07-18 07:24:28 +03:00
|
|
|
#include "mozilla/layers/CompositorBridgeParent.h"
|
|
|
|
#include "mozilla/layers/CompositorThread.h"
|
2016-07-20 10:19:27 +03:00
|
|
|
#include "mozilla/layers/ImageBridgeParent.h"
|
2016-08-23 08:57:36 +03:00
|
|
|
#include "nsDebugImpl.h"
|
2016-08-16 23:59:13 +03:00
|
|
|
#include "mozilla/layers/LayerTreeOwnerTracker.h"
|
2016-08-24 22:47:11 +03:00
|
|
|
#include "ProcessUtils.h"
|
2016-08-30 08:05:00 +03:00
|
|
|
#include "prenv.h"
|
2016-07-21 10:14:59 +03:00
|
|
|
#include "VRManager.h"
|
|
|
|
#include "VRManagerParent.h"
|
|
|
|
#include "VsyncBridgeParent.h"
|
2016-08-21 06:59:10 +03:00
|
|
|
#if defined(XP_WIN)
|
2016-08-23 03:25:52 +03:00
|
|
|
# include "DeviceManagerD3D9.h"
|
2016-08-24 01:18:55 +03:00
|
|
|
# include "mozilla/gfx/DeviceManagerDx.h"
|
2016-08-21 06:59:10 +03:00
|
|
|
#endif
|
2016-08-30 08:05:00 +03:00
|
|
|
#ifdef MOZ_WIDGET_GTK
|
|
|
|
# include <gtk/gtk.h>
|
|
|
|
#endif
|
2016-06-11 05:27:24 +03:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace gfx {
|
|
|
|
|
|
|
|
using namespace ipc;
|
2016-07-18 07:24:28 +03:00
|
|
|
using namespace layers;
|
2016-06-11 05:27:24 +03:00
|
|
|
|
|
|
|
GPUParent::GPUParent()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
GPUParent::~GPUParent()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
GPUParent::Init(base::ProcessId aParentPid,
|
|
|
|
MessageLoop* aIOLoop,
|
|
|
|
IPC::Channel* aChannel)
|
|
|
|
{
|
|
|
|
if (NS_WARN_IF(!Open(aChannel, aParentPid, aIOLoop))) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-08-23 08:57:36 +03:00
|
|
|
nsDebugImpl::SetMultiprocessMode("GPU");
|
|
|
|
|
2016-06-27 09:33:20 +03:00
|
|
|
// Ensure gfxPrefs are initialized.
|
|
|
|
gfxPrefs::GetSingleton();
|
2016-08-13 22:25:18 +03:00
|
|
|
gfxConfig::Init();
|
2016-08-04 21:33:42 +03:00
|
|
|
gfxVars::Initialize();
|
2016-08-23 08:57:36 +03:00
|
|
|
gfxPlatform::InitNullMetadata();
|
2016-08-21 06:59:10 +03:00
|
|
|
#if defined(XP_WIN)
|
2016-08-24 01:18:55 +03:00
|
|
|
DeviceManagerDx::Init();
|
2016-08-23 03:25:52 +03:00
|
|
|
DeviceManagerD3D9::Init();
|
2016-08-21 06:59:10 +03:00
|
|
|
#endif
|
2016-08-23 08:57:36 +03:00
|
|
|
if (NS_FAILED(NS_InitMinimalXPCOM())) {
|
|
|
|
return false;
|
|
|
|
}
|
2016-07-18 07:24:28 +03:00
|
|
|
CompositorThreadHolder::Start();
|
2016-08-29 16:18:00 +03:00
|
|
|
APZThreadUtils::SetControllerThread(CompositorThreadHolder::Loop());
|
2016-08-31 23:00:00 +03:00
|
|
|
APZCTreeManager::InitializeGlobalState();
|
2016-07-21 10:14:59 +03:00
|
|
|
VRManager::ManagerInit();
|
2016-08-16 23:59:13 +03:00
|
|
|
LayerTreeOwnerTracker::Initialize();
|
2016-08-24 22:47:11 +03:00
|
|
|
mozilla::ipc::SetThisProcessName("GPU Process");
|
2016-06-27 09:33:20 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2016-08-04 21:33:42 +03:00
|
|
|
GPUParent::RecvInit(nsTArray<GfxPrefSetting>&& prefs,
|
2016-08-21 06:59:10 +03:00
|
|
|
nsTArray<GfxVarUpdate>&& vars,
|
|
|
|
const DevicePrefs& devicePrefs)
|
2016-06-27 09:33:20 +03:00
|
|
|
{
|
2016-07-20 23:55:07 +03:00
|
|
|
const nsTArray<gfxPrefs::Pref*>& globalPrefs = gfxPrefs::all();
|
|
|
|
for (auto& setting : prefs) {
|
|
|
|
gfxPrefs::Pref* pref = globalPrefs[setting.index()];
|
2016-06-27 09:33:20 +03:00
|
|
|
pref->SetCachedValue(setting.value());
|
|
|
|
}
|
2016-08-04 21:33:42 +03:00
|
|
|
for (const auto& var : vars) {
|
|
|
|
gfxVars::ApplyUpdate(var);
|
|
|
|
}
|
2016-08-21 06:59:10 +03:00
|
|
|
|
|
|
|
// Inherit device preferences.
|
|
|
|
gfxConfig::Inherit(Feature::HW_COMPOSITING, devicePrefs.hwCompositing());
|
|
|
|
gfxConfig::Inherit(Feature::D3D11_COMPOSITING, devicePrefs.d3d11Compositing());
|
|
|
|
gfxConfig::Inherit(Feature::D3D9_COMPOSITING, devicePrefs.d3d9Compositing());
|
|
|
|
gfxConfig::Inherit(Feature::OPENGL_COMPOSITING, devicePrefs.oglCompositing());
|
|
|
|
gfxConfig::Inherit(Feature::DIRECT2D, devicePrefs.useD2D1());
|
|
|
|
|
|
|
|
#if defined(XP_WIN)
|
|
|
|
if (gfxConfig::IsEnabled(Feature::D3D11_COMPOSITING)) {
|
2016-08-24 01:18:55 +03:00
|
|
|
DeviceManagerDx::Get()->CreateCompositorDevices();
|
2016-08-21 06:59:10 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-08-30 08:05:00 +03:00
|
|
|
#if defined(MOZ_WIDGET_GTK)
|
|
|
|
char* display_name = PR_GetEnv("DISPLAY");
|
|
|
|
if (display_name) {
|
|
|
|
int argc = 3;
|
|
|
|
char option_name[] = "--display";
|
|
|
|
char* argv[] = {
|
|
|
|
// argv0 is unused because g_set_prgname() was called in
|
|
|
|
// XRE_InitChildProcess().
|
|
|
|
nullptr,
|
|
|
|
option_name,
|
|
|
|
display_name,
|
|
|
|
nullptr
|
|
|
|
};
|
|
|
|
char** argvp = argv;
|
|
|
|
gtk_init(&argc, &argvp);
|
|
|
|
} else {
|
|
|
|
gtk_init(nullptr, nullptr);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-08-21 06:59:11 +03:00
|
|
|
// Send a message to the UI process that we're done.
|
|
|
|
GPUDeviceData data;
|
|
|
|
RecvGetDeviceStatus(&data);
|
|
|
|
Unused << SendInitComplete(data);
|
|
|
|
|
2016-07-19 21:56:06 +03:00
|
|
|
return true;
|
|
|
|
}
|
2016-06-27 09:33:20 +03:00
|
|
|
|
2016-07-19 21:56:06 +03:00
|
|
|
bool
|
|
|
|
GPUParent::RecvInitVsyncBridge(Endpoint<PVsyncBridgeParent>&& aVsyncEndpoint)
|
|
|
|
{
|
|
|
|
VsyncBridgeParent::Start(Move(aVsyncEndpoint));
|
2016-06-11 05:27:24 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-07-20 10:19:27 +03:00
|
|
|
bool
|
|
|
|
GPUParent::RecvInitImageBridge(Endpoint<PImageBridgeParent>&& aEndpoint)
|
|
|
|
{
|
|
|
|
ImageBridgeParent::CreateForGPUProcess(Move(aEndpoint));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-07-21 10:14:59 +03:00
|
|
|
bool
|
|
|
|
GPUParent::RecvInitVRManager(Endpoint<PVRManagerParent>&& aEndpoint)
|
|
|
|
{
|
|
|
|
VRManagerParent::CreateForGPUProcess(Move(aEndpoint));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-06-11 05:27:24 +03:00
|
|
|
bool
|
2016-06-27 09:33:20 +03:00
|
|
|
GPUParent::RecvUpdatePref(const GfxPrefSetting& setting)
|
2016-06-11 05:27:24 +03:00
|
|
|
{
|
2016-06-27 09:33:20 +03:00
|
|
|
gfxPrefs::Pref* pref = gfxPrefs::all()[setting.index()];
|
|
|
|
pref->SetCachedValue(setting.value());
|
2016-06-11 05:27:24 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-08-04 21:33:42 +03:00
|
|
|
bool
|
|
|
|
GPUParent::RecvUpdateVar(const GfxVarUpdate& aUpdate)
|
|
|
|
{
|
|
|
|
gfxVars::ApplyUpdate(aUpdate);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-08-21 06:59:11 +03:00
|
|
|
static void
|
|
|
|
CopyFeatureChange(Feature aFeature, FeatureChange* 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();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_ASSERT(!feature.IsEnabled());
|
|
|
|
|
|
|
|
nsCString message;
|
|
|
|
message.AssignASCII(feature.GetFailureMessage());
|
|
|
|
|
|
|
|
*aOut = FeatureFailure(feature.GetValue(), message, feature.GetFailureId());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
GPUParent::RecvGetDeviceStatus(GPUDeviceData* aOut)
|
|
|
|
{
|
|
|
|
CopyFeatureChange(Feature::D3D11_COMPOSITING, &aOut->d3d11Compositing());
|
|
|
|
CopyFeatureChange(Feature::D3D9_COMPOSITING, &aOut->d3d9Compositing());
|
|
|
|
CopyFeatureChange(Feature::OPENGL_COMPOSITING, &aOut->oglCompositing());
|
|
|
|
|
|
|
|
#if defined(XP_WIN)
|
2016-08-24 01:18:55 +03:00
|
|
|
if (DeviceManagerDx* dm = DeviceManagerDx::Get()) {
|
2016-08-26 23:37:00 +03:00
|
|
|
D3D11DeviceStatus deviceStatus;
|
|
|
|
dm->ExportDeviceInfo(&deviceStatus);
|
|
|
|
aOut->gpuDevice() = deviceStatus;
|
2016-08-21 06:59:11 +03:00
|
|
|
}
|
2016-08-26 23:37:00 +03:00
|
|
|
#else
|
|
|
|
aOut->gpuDevice() = null_t();
|
2016-08-21 06:59:11 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-07-18 07:24:28 +03:00
|
|
|
static void
|
|
|
|
OpenParent(RefPtr<CompositorBridgeParent> aParent,
|
|
|
|
Endpoint<PCompositorBridgeParent>&& aEndpoint)
|
|
|
|
{
|
|
|
|
if (!aParent->Bind(Move(aEndpoint))) {
|
|
|
|
MOZ_CRASH("Failed to bind compositor");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
GPUParent::RecvNewWidgetCompositor(Endpoint<layers::PCompositorBridgeParent>&& aEndpoint,
|
|
|
|
const CSSToLayoutDeviceScale& aScale,
|
2016-07-26 11:57:11 +03:00
|
|
|
const TimeDuration& aVsyncRate,
|
2016-07-18 07:24:28 +03:00
|
|
|
const bool& aUseExternalSurfaceSize,
|
|
|
|
const IntSize& aSurfaceSize)
|
|
|
|
{
|
|
|
|
RefPtr<CompositorBridgeParent> cbp =
|
2016-07-26 11:57:11 +03:00
|
|
|
new CompositorBridgeParent(aScale, aVsyncRate, aUseExternalSurfaceSize, aSurfaceSize);
|
2016-07-18 07:24:28 +03:00
|
|
|
|
|
|
|
MessageLoop* loop = CompositorThreadHolder::Loop();
|
|
|
|
loop->PostTask(NewRunnableFunction(OpenParent, cbp, Move(aEndpoint)));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-07-18 07:24:28 +03:00
|
|
|
bool
|
|
|
|
GPUParent::RecvNewContentCompositorBridge(Endpoint<PCompositorBridgeParent>&& aEndpoint)
|
|
|
|
{
|
|
|
|
return CompositorBridgeParent::CreateForContent(Move(aEndpoint));
|
|
|
|
}
|
|
|
|
|
2016-07-20 10:19:27 +03:00
|
|
|
bool
|
|
|
|
GPUParent::RecvNewContentImageBridge(Endpoint<PImageBridgeParent>&& aEndpoint)
|
|
|
|
{
|
|
|
|
return ImageBridgeParent::CreateForContent(Move(aEndpoint));
|
|
|
|
}
|
|
|
|
|
2016-07-21 10:14:59 +03:00
|
|
|
bool
|
|
|
|
GPUParent::RecvNewContentVRManager(Endpoint<PVRManagerParent>&& aEndpoint)
|
|
|
|
{
|
|
|
|
return VRManagerParent::CreateForContent(Move(aEndpoint));
|
|
|
|
}
|
|
|
|
|
2016-08-17 19:11:00 +03:00
|
|
|
bool
|
|
|
|
GPUParent::RecvDeallocateLayerTreeId(const uint64_t& aLayersId)
|
|
|
|
{
|
|
|
|
CompositorBridgeParent::DeallocateLayerTreeId(aLayersId);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-08-16 23:59:13 +03:00
|
|
|
bool
|
|
|
|
GPUParent::RecvAddLayerTreeIdMapping(const uint64_t& aLayersId, const ProcessId& aOwnerId)
|
|
|
|
{
|
|
|
|
LayerTreeOwnerTracker::Get()->Map(aLayersId, aOwnerId);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-06-11 05:27:24 +03:00
|
|
|
void
|
|
|
|
GPUParent::ActorDestroy(ActorDestroyReason aWhy)
|
|
|
|
{
|
|
|
|
if (AbnormalShutdown == aWhy) {
|
|
|
|
NS_WARNING("Shutting down GPU process early due to a crash!");
|
|
|
|
ProcessChild::QuickExit();
|
|
|
|
}
|
|
|
|
|
2016-06-11 05:37:03 +03:00
|
|
|
#ifndef NS_FREE_PERMANENT_DATA
|
|
|
|
// No point in going through XPCOM shutdown because we don't keep persistent
|
2016-08-23 03:25:52 +03:00
|
|
|
// state.
|
2016-06-11 05:37:03 +03:00
|
|
|
ProcessChild::QuickExit();
|
|
|
|
#endif
|
2016-07-18 07:24:28 +03:00
|
|
|
|
2016-07-19 21:56:06 +03:00
|
|
|
if (mVsyncBridge) {
|
|
|
|
mVsyncBridge->Shutdown();
|
|
|
|
}
|
2016-07-18 07:24:28 +03:00
|
|
|
CompositorThreadHolder::Shutdown();
|
2016-08-21 06:59:10 +03:00
|
|
|
#if defined(XP_WIN)
|
2016-08-24 01:18:55 +03:00
|
|
|
DeviceManagerDx::Shutdown();
|
2016-08-23 03:25:52 +03:00
|
|
|
DeviceManagerD3D9::Shutdown();
|
2016-08-21 06:59:10 +03:00
|
|
|
#endif
|
2016-08-16 23:59:13 +03:00
|
|
|
LayerTreeOwnerTracker::Shutdown();
|
2016-08-13 22:25:18 +03:00
|
|
|
gfxVars::Shutdown();
|
|
|
|
gfxConfig::Shutdown();
|
|
|
|
gfxPrefs::DestroySingleton();
|
2016-08-23 08:57:36 +03:00
|
|
|
NS_ShutdownXPCOM(nullptr);
|
2016-07-18 07:24:28 +03:00
|
|
|
XRE_ShutdownChildProcess();
|
2016-06-11 05:27:24 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace gfx
|
|
|
|
} // namespace mozilla
|