Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
GraphiteDawnD3D12WindowContext_win.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2022 Google LLC
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
10
13
14namespace {
15
16class GraphiteDawnD3D12WindowContext_win : public GraphiteDawnWindowContext {
17public:
18 GraphiteDawnD3D12WindowContext_win(HWND hwnd, const DisplayParams& params);
19
20 ~GraphiteDawnD3D12WindowContext_win() override;
21
22 bool onInitializeContext() override;
23 void onDestroyContext() override;
24 void resize(int w, int h) override;
25
26private:
27 HWND fWindow;
28};
29
30GraphiteDawnD3D12WindowContext_win::GraphiteDawnD3D12WindowContext_win(HWND hwnd,
31 const DisplayParams& params)
32 : GraphiteDawnWindowContext(params, wgpu::TextureFormat::BGRA8Unorm), fWindow(hwnd) {
33 RECT rect;
34 GetClientRect(hwnd, &rect);
35 this->initializeContext(rect.right - rect.left, rect.bottom - rect.top);
36}
37
38GraphiteDawnD3D12WindowContext_win::~GraphiteDawnD3D12WindowContext_win() {
39 this->destroyContext();
40}
41
42bool GraphiteDawnD3D12WindowContext_win::onInitializeContext() {
43 SkASSERT(!!fWindow);
44
45 auto device = this->createDevice(wgpu::BackendType::D3D12);
46 if (!device) {
48 return false;
49 }
50
51 wgpu::SurfaceDescriptorFromWindowsHWND surfaceChainedDesc;
52 surfaceChainedDesc.hwnd = fWindow;
53 surfaceChainedDesc.hinstance = GetModuleHandle(nullptr);
54 wgpu::SurfaceDescriptor surfaceDesc;
55 surfaceDesc.nextInChain = &surfaceChainedDesc;
56
57 auto surface = wgpu::Instance(fInstance->Get()).CreateSurface(&surfaceDesc);
58 if (!surface) {
59 SkASSERT(false);
60 return false;
61 }
62
63 fDevice = std::move(device);
64 fSurface = std::move(surface);
65 fSwapChain = this->createSwapChain();
66
67 return true;
68}
69
70void GraphiteDawnD3D12WindowContext_win::onDestroyContext() {}
71
72void GraphiteDawnD3D12WindowContext_win::resize(int w, int h) {
73 fSwapChain = this->createSwapChain();
74}
75
76} // anonymous namespace
77
78namespace skwindow {
79
80std::unique_ptr<WindowContext> MakeGraphiteDawnD3D12ForWin(HWND hwnd, const DisplayParams& params) {
81 std::unique_ptr<WindowContext> ctx(new GraphiteDawnD3D12WindowContext_win(hwnd, params));
82 if (!ctx->isValid()) {
83 return nullptr;
84 }
85 return ctx;
86}
87
88} // namespace skwindow
#define SkASSERT(cond)
Definition SkAssert.h:116
virtual void resize(int w, int h)=0
const EmbeddedViewParams * params
VkDevice device
Definition main.cc:53
VkSurfaceKHR surface
Definition main.cc:49
sk_sp< SkBlender > blender SkRect rect
Definition SkRecords.h:350
SkScalar w
SkScalar h