Bug 1586396 - Add WebGPUThreading mock r=jgilbert

Differential Revision: https://phabricator.services.mozilla.com/D48229

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Dzmitry Malyshau 2019-10-15 21:57:37 +00:00
parent 38f4dd72f0
commit f072f15267
10 changed files with 148 additions and 1 deletions

View File

@ -5,13 +5,17 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
with Files('**'):
BUG_COMPONENT = ('Core', 'Canvas: WebGL')
BUG_COMPONENT = ('Core', 'Graphics: WebGPU')
MOCHITEST_MANIFESTS += [
'mochitest/mochitest-no-pref.ini',
'mochitest/mochitest.ini',
]
DIRS += [
'thread',
]
h_and_cpp = [
'Adapter',
'BindGroup',

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=80: */
/* 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 "WebGPUThreading.h"
#include "mtransport/runnable_utils.h"
namespace mozilla {
namespace webgpu {
static StaticRefPtr<WebGPUThreading> sWebGPUThread;
WebGPUThreading::WebGPUThreading(base::Thread* aThread)
: mThread(aThread) {}
WebGPUThreading::~WebGPUThreading() {
delete mThread;
}
// static
void WebGPUThreading::Start() {
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(!sWebGPUThread);
base::Thread* thread = new base::Thread("WebGPU");
base::Thread::Options options;
if (!thread->StartWithOptions(options)) {
delete thread;
return;
}
sWebGPUThread = new WebGPUThreading(thread);
const auto fnInit = []() {};
RefPtr<Runnable> runnable = NS_NewRunnableFunction(
"WebGPUThreading fnInit", fnInit);
sWebGPUThread->GetLoop()->PostTask(runnable.forget());
}
// static
void WebGPUThreading::ShutDown() {
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(sWebGPUThread);
const auto fnExit = []() {
};
RefPtr<Runnable> runnable = NS_NewRunnableFunction(
"WebGPUThreading fnExit", fnExit);
sWebGPUThread->GetLoop()->PostTask(runnable.forget());
sWebGPUThread = nullptr;
}
// static
MessageLoop* WebGPUThreading::GetLoop() {
return sWebGPUThread ? sWebGPUThread->mThread->message_loop() : nullptr;
}
} // namespace webgpu
} // namespace mozilla

View File

@ -0,0 +1,41 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* 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_WEBGPU_THREADING_H
#define MOZILLA_WEBGPU_THREADING_H
#include "ThreadSafeRefcountingWithMainThreadDestruction.h"
#include "base/thread.h" // for Thread
#include "mozilla/layers/SynchronousTask.h"
namespace mozilla {
namespace webgpu {
class WebGPUThreading final {
NS_INLINE_DECL_THREADSAFE_REFCOUNTING_WITH_MAIN_THREAD_DESTRUCTION(WebGPUThreading)
public:
/// Can only be called from the main thread.
static void Start();
/// Can only be called from the main thread.
static void ShutDown();
/// Can be called from any thread. Returns `nullptr` if
/// the threading is not initialized.
static MessageLoop* GetLoop();
private:
explicit WebGPUThreading(base::Thread* aThread);
~WebGPUThreading();
base::Thread* const mThread;
};
}
}
#endif // MOZILLA_WEBGPU_THREADING_H

View File

@ -0,0 +1,18 @@
# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
# vim: set filetype=python:
# 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/.
h_and_cpp = [
'WebGPUThreading',
]
EXPORTS.mozilla.webgpu += [x + '.h' for x in h_and_cpp]
UNIFIED_SOURCES += [x + '.cpp' for x in h_and_cpp]
LOCAL_INCLUDES += [
'/ipc/chromium/src',
]
FINAL_LIBRARY = 'xul'

View File

@ -28,6 +28,7 @@ namespace gfx {
_(WEBRENDER_QUALIFIED, Feature, "WebRender qualified") \
_(OMTP, Feature, "Off Main Thread Painting") \
_(ADVANCED_LAYERS, Feature, "Advanced Layers") \
_(WEBGPU, Feature, "WebGPU") \
/* Add new entries above this comment */
enum class Feature : uint32_t {

View File

@ -49,6 +49,7 @@ void GPUChild::Init() {
gfxConfig::GetValue(Feature::OPENGL_COMPOSITING);
devicePrefs.advancedLayers() = gfxConfig::GetValue(Feature::ADVANCED_LAYERS);
devicePrefs.useD2D1() = gfxConfig::GetValue(Feature::DIRECT2D);
devicePrefs.webGPU() = gfxConfig::GetValue(Feature::WEBGPU);
nsTArray<LayerTreeIdMapping> mappings;
LayerTreeOwnerTracker::Get()->Iterate(

View File

@ -22,6 +22,7 @@
#include "mozilla/RemoteDecoderManagerChild.h"
#include "mozilla/RemoteDecoderManagerParent.h"
#include "mozilla/dom/MemoryReportRequest.h"
#include "mozilla/webgpu/WebGPUThreading.h"
#include "mozilla/gfx/2D.h"
#include "mozilla/gfx/gfxVars.h"
#include "mozilla/image/ImageMemoryReporter.h"
@ -179,6 +180,7 @@ mozilla::ipc::IPCResult GPUParent::RecvInit(
gfxConfig::Inherit(Feature::OPENGL_COMPOSITING, devicePrefs.oglCompositing());
gfxConfig::Inherit(Feature::ADVANCED_LAYERS, devicePrefs.advancedLayers());
gfxConfig::Inherit(Feature::DIRECT2D, devicePrefs.useD2D1());
gfxConfig::Inherit(Feature::WEBGPU, devicePrefs.webGPU());
{ // Let the crash reporter know if we've got WR enabled or not. For other
// processes this happens in gfxPlatform::InitWebRenderConfig.
@ -265,6 +267,10 @@ mozilla::ipc::IPCResult GPUParent::RecvInit(
}
#endif
if (gfxConfig::IsEnabled(Feature::WEBGPU)) {
webgpu::WebGPUThreading::Start();
}
VRManager::ManagerInit();
// Send a message to the UI process that we're done.
GPUDeviceData data;
@ -531,6 +537,10 @@ void GPUParent::ActorDestroy(ActorDestroyReason aWhy) {
image::ImageMemoryReporter::ShutdownForWebRender();
if (gfxConfig::IsEnabled(Feature::WEBGPU)) {
webgpu::WebGPUThreading::ShutDown();
}
// Shut down the default GL context provider.
gl::GLContextProvider::Shutdown();

View File

@ -34,6 +34,7 @@ struct DevicePrefs
FeatureStatus oglCompositing;
FeatureStatus advancedLayers;
FeatureStatus useD2D1;
FeatureStatus webGPU;
};
struct ContentDeviceData
@ -58,6 +59,7 @@ struct GPUDeviceData
FeatureFailure? oglCompositing;
FeatureFailure? advancedLayers;
D3D11DeviceStatus? gpuDevice;
FeatureFailure? webGPU;
};
union GfxVarValue

View File

@ -3136,6 +3136,11 @@ void gfxPlatform::InitWebRenderConfig() {
gfxUtils::RemoveShaderCacheFromDiskIfNecessary();
}
void gfxPlatform::InitWebGPUConfig() {
FeatureState& feature = gfxConfig::GetFeature(Feature::WEBGPU);
feature.SetDefaultFromPref("dom.webgpu.enable", true, false);
}
void gfxPlatform::InitOMTPConfig() {
ScopedGfxFeatureReporter reporter("OMTP");

View File

@ -748,6 +748,7 @@ class gfxPlatform : public mozilla::layers::MemoryPressureListener {
virtual void InitAcceleration();
virtual void InitWebRenderConfig();
virtual void InitWebGPUConfig();
/**
* Called immediately before deleting the gfxPlatform object.