Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/gfx/vr/ipc/VRParent.cpp
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
3
/* This Source Code Form is subject to the terms of the Mozilla Public
4
 * License, v. 2.0. If a copy of the MPL was not distributed with this
5
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7
#include "VRParent.h"
8
#include "VRGPUParent.h"
9
#include "VRManager.h"
10
#include "gfxConfig.h"
11
12
#include "mozilla/gfx/gfxVars.h"
13
#include "mozilla/ipc/ProcessChild.h"
14
15
#if defined(XP_WIN)
16
#include "mozilla/gfx/DeviceManagerDx.h"
17
#endif
18
19
namespace mozilla {
20
namespace gfx {
21
22
using mozilla::ipc::IPCResult;
23
24
VRParent::VRParent()
25
 : mVRGPUParent(nullptr)
26
0
{
27
0
}
28
29
IPCResult
30
VRParent::RecvNewGPUVRManager(Endpoint<PVRGPUParent>&& aEndpoint)
31
0
{
32
0
  RefPtr<VRGPUParent> vrGPUParent = VRGPUParent::CreateForGPU(std::move(aEndpoint));
33
0
  if (!vrGPUParent) {
34
0
    return IPC_FAIL_NO_REASON(this);
35
0
  }
36
0
37
0
  mVRGPUParent = std::move(vrGPUParent);
38
0
  return IPC_OK();
39
0
}
40
41
IPCResult
42
VRParent::RecvInit(nsTArray<GfxPrefSetting>&& prefs,
43
                   nsTArray<GfxVarUpdate>&& vars,
44
                   const DevicePrefs& devicePrefs)
45
0
{
46
0
  const nsTArray<gfxPrefs::Pref*>& globalPrefs = gfxPrefs::all();
47
0
  for (auto& setting : prefs) {
48
0
    gfxPrefs::Pref* pref = globalPrefs[setting.index()];
49
0
    pref->SetCachedValue(setting.value());
50
0
  }
51
0
  for (const auto& var : vars) {
52
0
    gfxVars::ApplyUpdate(var);
53
0
  }
54
0
55
0
  // Inherit device preferences.
56
0
  gfxConfig::Inherit(Feature::HW_COMPOSITING, devicePrefs.hwCompositing());
57
0
  gfxConfig::Inherit(Feature::D3D11_COMPOSITING, devicePrefs.d3d11Compositing());
58
0
  gfxConfig::Inherit(Feature::OPENGL_COMPOSITING, devicePrefs.oglCompositing());
59
0
  gfxConfig::Inherit(Feature::ADVANCED_LAYERS, devicePrefs.advancedLayers());
60
0
  gfxConfig::Inherit(Feature::DIRECT2D, devicePrefs.useD2D1());
61
0
62
#if defined(XP_WIN)
63
  if (gfxConfig::IsEnabled(Feature::D3D11_COMPOSITING)) {
64
    DeviceManagerDx::Get()->CreateCompositorDevices();
65
  }
66
#endif
67
0
  return IPC_OK();
68
0
}
69
70
IPCResult
71
VRParent::RecvNotifyVsync(const TimeStamp& vsyncTimestamp)
72
0
{
73
0
  VRManager* vm = VRManager::Get();
74
0
  vm->NotifyVsync(vsyncTimestamp);
75
0
  return IPC_OK();
76
0
}
77
78
IPCResult
79
VRParent::RecvUpdatePref(const GfxPrefSetting& setting)
80
0
{
81
0
  gfxPrefs::Pref* pref = gfxPrefs::all()[setting.index()];
82
0
  pref->SetCachedValue(setting.value());
83
0
  return IPC_OK();
84
0
}
85
86
IPCResult
87
VRParent::RecvUpdateVar(const GfxVarUpdate& aUpdate)
88
0
{
89
0
  gfxVars::ApplyUpdate(aUpdate);
90
0
  return IPC_OK();
91
0
}
92
93
void
94
VRParent::ActorDestroy(ActorDestroyReason aWhy)
95
0
{
96
0
  if (AbnormalShutdown == aWhy) {
97
0
    NS_WARNING("Shutting down VR process early due to a crash!");
98
0
    ProcessChild::QuickExit();
99
0
  }
100
0
101
0
  mVRGPUParent->Close();
102
#if defined(XP_WIN)
103
  DeviceManagerDx::Shutdown();
104
#endif
105
  gfxVars::Shutdown();
106
0
  gfxConfig::Shutdown();
107
0
  gfxPrefs::DestroySingleton();
108
0
  XRE_ShutdownChildProcess();
109
0
}
110
111
bool
112
VRParent::Init(base::ProcessId aParentPid,
113
               const char* aParentBuildID,
114
               MessageLoop* aIOLoop,
115
               IPC::Channel* aChannel)
116
0
{
117
0
  // Now it's safe to start IPC.
118
0
  if (NS_WARN_IF(!Open(aChannel, aParentPid, aIOLoop))) {
119
0
    return false;
120
0
  }
121
0
122
0
  // This must be checked before any IPDL message, which may hit sentinel
123
0
  // errors due to parent and content processes having different
124
0
  // versions.
125
0
  MessageChannel* channel = GetIPCChannel();
126
0
  if (channel && !channel->SendBuildIDsMatchMessage(aParentBuildID)) {
127
0
    // We need to quit this process if the buildID doesn't match the parent's.
128
0
    // This can occur when an update occurred in the background.
129
0
    ProcessChild::QuickExit();
130
0
  }
131
0
132
0
  // Ensure gfxPrefs are initialized.
133
0
  gfxPrefs::GetSingleton();
134
0
  gfxConfig::Init();
135
0
  gfxVars::Initialize();
136
#if defined(XP_WIN)
137
  DeviceManagerDx::Init();
138
#endif
139
  return true;
140
0
}
141
142
} // namespace gfx
143
} // namespace mozilla