Commit 30787df1 authored by Rafael Cintron's avatar Rafael Cintron Committed by Commit Bot

Make SkiaRenderer/Dawn/D3D12 run within GPU sandbox

D3D12 requires that we use flip model swap chains. Flip swap chains
require that the swap chain be connected with DWM. DWM requires that
the rendering windows are owned by the process that's currently doing
the rendering.

To workaround this problem, we use gl::ChildWindowWin to create a window
that is reparented by the browser to be a child of its window.

Bug: 1071458
Change-Id: I212df12ec21f3fbc00e08b63a741b05b14771c04
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2223371
Commit-Queue: Rafael Cintron <rafael.cintron@microsoft.com>
Reviewed-by: default avatarkylechar <kylechar@chromium.org>
Reviewed-by: default avatarSunny Sachanandani <sunnyps@chromium.org>
Cr-Commit-Position: refs/heads/master@{#774742}
parent 387f9c4d
...@@ -409,7 +409,7 @@ viz_source_set("gpu_service_dependencies") { ...@@ -409,7 +409,7 @@ viz_source_set("gpu_service_dependencies") {
deps += [ "//ui/gfx/x" ] deps += [ "//ui/gfx/x" ]
} }
if (skia_use_dawn) { if (skia_use_dawn && is_win) {
sources += [ sources += [
"display_embedder/skia_output_device_dawn.cc", "display_embedder/skia_output_device_dawn.cc",
"display_embedder/skia_output_device_dawn.h", "display_embedder/skia_output_device_dawn.h",
......
...@@ -6,17 +6,11 @@ ...@@ -6,17 +6,11 @@
#include "base/check_op.h" #include "base/check_op.h"
#include "base/notreached.h" #include "base/notreached.h"
#include "build/build_config.h"
#include "components/viz/common/gpu/dawn_context_provider.h" #include "components/viz/common/gpu/dawn_context_provider.h"
#include "third_party/dawn/src/include/dawn_native/D3D12Backend.h"
#include "ui/gfx/presentation_feedback.h" #include "ui/gfx/presentation_feedback.h"
#include "ui/gfx/vsync_provider.h" #include "ui/gfx/vsync_provider.h"
#if defined(OS_WIN)
#include "third_party/dawn/src/include/dawn_native/D3D12Backend.h"
#include "ui/gl/vsync_provider_win.h" #include "ui/gl/vsync_provider_win.h"
#elif defined(OS_LINUX)
#include "third_party/dawn/src/include/dawn_native/VulkanBackend.h"
#endif
namespace viz { namespace viz {
...@@ -41,7 +35,7 @@ SkiaOutputDeviceDawn::SkiaOutputDeviceDawn( ...@@ -41,7 +35,7 @@ SkiaOutputDeviceDawn::SkiaOutputDeviceDawn(
DidSwapBufferCompleteCallback did_swap_buffer_complete_callback) DidSwapBufferCompleteCallback did_swap_buffer_complete_callback)
: SkiaOutputDevice(memory_tracker, did_swap_buffer_complete_callback), : SkiaOutputDevice(memory_tracker, did_swap_buffer_complete_callback),
context_provider_(context_provider), context_provider_(context_provider),
widget_(widget) { child_window_(widget) {
capabilities_.output_surface_origin = origin; capabilities_.output_surface_origin = origin;
capabilities_.uses_default_gl_framebuffer = false; capabilities_.uses_default_gl_framebuffer = false;
capabilities_.supports_post_sub_buffer = false; capabilities_.supports_post_sub_buffer = false;
...@@ -51,13 +45,16 @@ SkiaOutputDeviceDawn::SkiaOutputDeviceDawn( ...@@ -51,13 +45,16 @@ SkiaOutputDeviceDawn::SkiaOutputDeviceDawn(
context_provider_->GetGrContext()->defaultBackendFormat( context_provider_->GetGrContext()->defaultBackendFormat(
kSurfaceColorType, GrRenderable::kYes); kSurfaceColorType, GrRenderable::kYes);
#if defined(OS_WIN) vsync_provider_ = std::make_unique<gl::VSyncProviderWin>(widget);
vsync_provider_ = std::make_unique<gl::VSyncProviderWin>(widget_); child_window_.Initialize();
#endif
} }
SkiaOutputDeviceDawn::~SkiaOutputDeviceDawn() = default; SkiaOutputDeviceDawn::~SkiaOutputDeviceDawn() = default;
gpu::SurfaceHandle SkiaOutputDeviceDawn::GetChildSurfaceHandle() const {
return child_window_.window();
}
bool SkiaOutputDeviceDawn::Reshape(const gfx::Size& size, bool SkiaOutputDeviceDawn::Reshape(const gfx::Size& size,
float device_scale_factor, float device_scale_factor,
const gfx::ColorSpace& color_space, const gfx::ColorSpace& color_space,
...@@ -136,13 +133,8 @@ void SkiaOutputDeviceDawn::EndPaint() { ...@@ -136,13 +133,8 @@ void SkiaOutputDeviceDawn::EndPaint() {
} }
void SkiaOutputDeviceDawn::CreateSwapChainImplementation() { void SkiaOutputDeviceDawn::CreateSwapChainImplementation() {
#if defined(OS_WIN)
swap_chain_implementation_ = dawn_native::d3d12::CreateNativeSwapChainImpl( swap_chain_implementation_ = dawn_native::d3d12::CreateNativeSwapChainImpl(
context_provider_->GetDevice().Get(), widget_); context_provider_->GetDevice().Get(), child_window_.window());
#else
NOTREACHED();
ALLOW_UNUSED_LOCAL(widget_);
#endif
} }
} // namespace viz } // namespace viz
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#ifndef COMPONENTS_VIZ_SERVICE_DISPLAY_EMBEDDER_SKIA_OUTPUT_DEVICE_DAWN_H_ #ifndef COMPONENTS_VIZ_SERVICE_DISPLAY_EMBEDDER_SKIA_OUTPUT_DEVICE_DAWN_H_
#define COMPONENTS_VIZ_SERVICE_DISPLAY_EMBEDDER_SKIA_OUTPUT_DEVICE_DAWN_H_ #define COMPONENTS_VIZ_SERVICE_DISPLAY_EMBEDDER_SKIA_OUTPUT_DEVICE_DAWN_H_
#include "build/build_config.h"
#include "components/viz/service/display_embedder/skia_output_device.h" #include "components/viz/service/display_embedder/skia_output_device.h"
#include "third_party/dawn/src/include/dawn/dawn_wsi.h" #include "third_party/dawn/src/include/dawn/dawn_wsi.h"
#include "third_party/dawn/src/include/dawn/webgpu.h" #include "third_party/dawn/src/include/dawn/webgpu.h"
...@@ -13,6 +14,7 @@ ...@@ -13,6 +14,7 @@
#include "third_party/skia/include/core/SkImageInfo.h" #include "third_party/skia/include/core/SkImageInfo.h"
#include "third_party/skia/include/gpu/GrBackendSurface.h" #include "third_party/skia/include/gpu/GrBackendSurface.h"
#include "ui/gfx/native_widget_types.h" #include "ui/gfx/native_widget_types.h"
#include "ui/gl/child_window_win.h"
namespace viz { namespace viz {
...@@ -28,6 +30,8 @@ class SkiaOutputDeviceDawn : public SkiaOutputDevice { ...@@ -28,6 +30,8 @@ class SkiaOutputDeviceDawn : public SkiaOutputDevice {
DidSwapBufferCompleteCallback did_swap_buffer_complete_callback); DidSwapBufferCompleteCallback did_swap_buffer_complete_callback);
~SkiaOutputDeviceDawn() override; ~SkiaOutputDeviceDawn() override;
gpu::SurfaceHandle GetChildSurfaceHandle() const;
// SkiaOutputDevice implementation: // SkiaOutputDevice implementation:
bool Reshape(const gfx::Size& size, bool Reshape(const gfx::Size& size,
float device_scale_factor, float device_scale_factor,
...@@ -45,7 +49,6 @@ class SkiaOutputDeviceDawn : public SkiaOutputDevice { ...@@ -45,7 +49,6 @@ class SkiaOutputDeviceDawn : public SkiaOutputDevice {
void CreateSwapChainImplementation(); void CreateSwapChainImplementation();
DawnContextProvider* const context_provider_; DawnContextProvider* const context_provider_;
gfx::AcceleratedWidget widget_;
DawnSwapChainImplementation swap_chain_implementation_; DawnSwapChainImplementation swap_chain_implementation_;
wgpu::SwapChain swap_chain_; wgpu::SwapChain swap_chain_;
wgpu::Texture texture_; wgpu::Texture texture_;
...@@ -56,6 +59,13 @@ class SkiaOutputDeviceDawn : public SkiaOutputDevice { ...@@ -56,6 +59,13 @@ class SkiaOutputDeviceDawn : public SkiaOutputDevice {
sk_sp<SkColorSpace> sk_color_space_; sk_sp<SkColorSpace> sk_color_space_;
GrBackendTexture backend_texture_; GrBackendTexture backend_texture_;
// D3D12 requires that we use flip model swap chains. Flip swap chains
// require that the swap chain be connected with DWM. DWM requires that
// the rendering windows are owned by the process that's currently doing
// the rendering. gl::ChildWindowWin creates and owns a window which is
// reparented by the browser to be a child of its window.
gl::ChildWindowWin child_window_;
DISALLOW_COPY_AND_ASSIGN(SkiaOutputDeviceDawn); DISALLOW_COPY_AND_ASSIGN(SkiaOutputDeviceDawn);
}; };
......
...@@ -83,8 +83,10 @@ ...@@ -83,8 +83,10 @@
#if BUILDFLAG(SKIA_USE_DAWN) #if BUILDFLAG(SKIA_USE_DAWN)
#include "components/viz/common/gpu/dawn_context_provider.h" #include "components/viz/common/gpu/dawn_context_provider.h"
#if defined(OS_WIN)
#include "components/viz/service/display_embedder/skia_output_device_dawn.h" #include "components/viz/service/display_embedder/skia_output_device_dawn.h"
#endif #endif
#endif
namespace viz { namespace viz {
...@@ -1626,11 +1628,20 @@ bool SkiaOutputSurfaceImplOnGpu::InitializeForDawn() { ...@@ -1626,11 +1628,20 @@ bool SkiaOutputSurfaceImplOnGpu::InitializeForDawn() {
output_device_ = std::make_unique<SkiaOutputDeviceX11>( output_device_ = std::make_unique<SkiaOutputDeviceX11>(
context_state_, dependency_->GetSurfaceHandle(), memory_tracker_.get(), context_state_, dependency_->GetSurfaceHandle(), memory_tracker_.get(),
did_swap_buffer_complete_callback_); did_swap_buffer_complete_callback_);
#elif defined(OS_WIN)
std::unique_ptr<SkiaOutputDeviceDawn> output_device =
std::make_unique<SkiaOutputDeviceDawn>(
dawn_context_provider_, dependency_->GetSurfaceHandle(),
gfx::SurfaceOrigin::kTopLeft, memory_tracker_.get(),
did_swap_buffer_complete_callback_);
const gpu::SurfaceHandle child_surface_handle =
output_device->GetChildSurfaceHandle();
DidCreateAcceleratedSurfaceChildWindow(dependency_->GetSurfaceHandle(),
child_surface_handle);
output_device_ = std::move(output_device);
#else #else
output_device_ = std::make_unique<SkiaOutputDeviceDawn>( NOTREACHED();
dawn_context_provider_, dependency_->GetSurfaceHandle(), return false;
gfx::SurfaceOrigin::kTopLeft, memory_tracker_.get(),
did_swap_buffer_complete_callback_);
#endif #endif
} }
#endif #endif
......
...@@ -124,9 +124,9 @@ void DestroyWindowsOnThread(HWND child_window, HWND hidden_popup_window) { ...@@ -124,9 +124,9 @@ void DestroyWindowsOnThread(HWND child_window, HWND hidden_popup_window) {
ChildWindowWin::ChildWindowWin(HWND parent_window) ChildWindowWin::ChildWindowWin(HWND parent_window)
: parent_window_(parent_window) {} : parent_window_(parent_window) {}
bool ChildWindowWin::Initialize() { void ChildWindowWin::Initialize() {
if (window_) if (window_)
return true; return;
thread_ = std::make_unique<base::Thread>("Window owner thread"); thread_ = std::make_unique<base::Thread>("Window owner thread");
base::Thread::Options options(base::MessagePumpType::UI, 0); base::Thread::Options options(base::MessagePumpType::UI, 0);
...@@ -143,8 +143,6 @@ bool ChildWindowWin::Initialize() { ...@@ -143,8 +143,6 @@ bool ChildWindowWin::Initialize() {
base::BindOnce(&CreateWindowsOnThread, gfx::Rect(window_rect).size(), base::BindOnce(&CreateWindowsOnThread, gfx::Rect(window_rect).size(),
&event, &window_, &initial_parent_window_)); &event, &window_, &initial_parent_window_));
event.Wait(); event.Wait();
return true;
} }
ChildWindowWin::~ChildWindowWin() { ChildWindowWin::~ChildWindowWin() {
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "base/task_runner.h" #include "base/task_runner.h"
#include "base/threading/thread.h" #include "base/threading/thread.h"
#include "ui/gl/gl_export.h"
#include <windows.h> #include <windows.h>
...@@ -16,12 +17,12 @@ namespace gl { ...@@ -16,12 +17,12 @@ namespace gl {
// The window DirectComposition renders into needs to be owned by the process // The window DirectComposition renders into needs to be owned by the process
// that's currently doing the rendering. The class creates and owns a window // that's currently doing the rendering. The class creates and owns a window
// which is reparented by the browser to be a child of its window. // which is reparented by the browser to be a child of its window.
class ChildWindowWin { class GL_EXPORT ChildWindowWin {
public: public:
explicit ChildWindowWin(HWND parent_window); explicit ChildWindowWin(HWND parent_window);
~ChildWindowWin(); ~ChildWindowWin();
bool Initialize(); void Initialize();
HWND window() const { return window_; } HWND window() const { return window_; }
scoped_refptr<base::TaskRunner> GetTaskRunnerForTesting(); scoped_refptr<base::TaskRunner> GetTaskRunnerForTesting();
......
...@@ -585,10 +585,8 @@ bool DirectCompositionSurfaceWin::Initialize(GLSurfaceFormat format) { ...@@ -585,10 +585,8 @@ bool DirectCompositionSurfaceWin::Initialize(GLSurfaceFormat format) {
return false; return false;
} }
if (!child_window_.Initialize()) { child_window_.Initialize();
DLOG(ERROR) << "Failed to initialize native window";
return false;
}
window_ = child_window_.window(); window_ = child_window_.window();
if (!layer_tree_->Initialize(window_, d3d11_device_, dcomp_device_)) if (!layer_tree_->Initialize(window_, d3d11_device_, dcomp_device_))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment