2019-08-02 19:04:52 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2019 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "tools/sk_app/DawnWindowContext.h"
|
|
|
|
#include "tools/sk_app/win/WindowContextFactory_win.h"
|
2019-12-04 14:57:48 +00:00
|
|
|
#include "dawn/webgpu_cpp.h"
|
2019-08-02 19:04:52 +00:00
|
|
|
#include "dawn/dawn_wsi.h"
|
|
|
|
#include "dawn_native/DawnNative.h"
|
|
|
|
#include "dawn_native/D3D12Backend.h"
|
|
|
|
#include "common/SwapChainUtils.h"
|
|
|
|
|
|
|
|
namespace sk_app {
|
|
|
|
|
|
|
|
class DawnD3D12WindowContext : public DawnWindowContext {
|
|
|
|
public:
|
|
|
|
DawnD3D12WindowContext(HWND hwnd, const DisplayParams& params);
|
2019-11-07 15:17:03 +00:00
|
|
|
~DawnD3D12WindowContext() override;
|
2019-10-30 13:56:23 +00:00
|
|
|
wgpu::Device onInitializeContext() override;
|
2019-08-02 19:04:52 +00:00
|
|
|
void onDestroyContext() override;
|
|
|
|
DawnSwapChainImplementation createSwapChainImplementation(
|
|
|
|
int width, int height, const DisplayParams& params) override;
|
|
|
|
void onSwapBuffers() override;
|
|
|
|
private:
|
|
|
|
HWND fWindow;
|
|
|
|
};
|
|
|
|
|
|
|
|
// NOTE: this texture format must match the one in D3D12's swap chain impl
|
|
|
|
DawnD3D12WindowContext::DawnD3D12WindowContext(HWND hwnd, const DisplayParams& params)
|
2019-10-30 13:56:23 +00:00
|
|
|
: DawnWindowContext(params, wgpu::TextureFormat::RGBA8Unorm)
|
2019-08-02 19:04:52 +00:00
|
|
|
, fWindow(hwnd) {
|
|
|
|
RECT rect;
|
|
|
|
GetClientRect(hwnd, &rect);
|
|
|
|
this->initializeContext(rect.right - rect.left, rect.bottom - rect.top);
|
|
|
|
}
|
|
|
|
|
|
|
|
DawnD3D12WindowContext::~DawnD3D12WindowContext() {
|
|
|
|
this->destroyContext();
|
|
|
|
}
|
|
|
|
|
|
|
|
DawnSwapChainImplementation DawnD3D12WindowContext::createSwapChainImplementation(
|
|
|
|
int width, int height, const DisplayParams& params) {
|
|
|
|
return dawn_native::d3d12::CreateNativeSwapChainImpl(fDevice.Get(), fWindow);
|
|
|
|
}
|
|
|
|
|
2019-10-30 13:56:23 +00:00
|
|
|
wgpu::Device DawnD3D12WindowContext::onInitializeContext() {
|
2019-08-02 19:04:52 +00:00
|
|
|
return this->createDevice(dawn_native::BackendType::D3D12);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DawnD3D12WindowContext::onDestroyContext() {
|
|
|
|
}
|
|
|
|
|
|
|
|
void DawnD3D12WindowContext::onSwapBuffers() {
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace window_context_factory {
|
|
|
|
|
|
|
|
std::unique_ptr<WindowContext> MakeDawnD3D12ForWin(HWND hwnd,
|
|
|
|
const DisplayParams& params) {
|
|
|
|
std::unique_ptr<WindowContext> ctx(new DawnD3D12WindowContext(hwnd, params));
|
|
|
|
if (!ctx->isValid()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return ctx;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} //namespace sk_app
|