Debian Codegraph @

tools/window/GraphiteDawnWindowContext.h

raw
1 /*
2 * Copyright 2022 Google Inc.
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 #ifndef GraphiteDawnWindowContext_DEFINED
8 #define GraphiteDawnWindowContext_DEFINED
9
10 #include "tools/window/WindowContext.h"
11 #include "webgpu/webgpu_cpp.h" // NO_G3_REWRITE
12 #include "dawn/native/DawnNative.h"
13
14 namespace skwindow::internal {
15
16 class GraphiteDawnWindowContext : public WindowContext {
17 public:
18 GraphiteDawnWindowContext(std::unique_ptr<const DisplayParams>,
19 wgpu::TextureFormat surfaceFormat);
20 ~GraphiteDawnWindowContext() override;
21 sk_sp<SkSurface> getBackbufferSurface() override;
22 bool isValid() override { return SkToBool(fDevice.Get()); }
23 void setDisplayParams(std::unique_ptr<const DisplayParams> params) override;
24
25 protected:
26 bool isGpuContext() override { return true; }
27 void initializeContext(int width, int height);
28 wgpu::Device createDevice(wgpu::BackendType type);
29 void configureSurface();
30 void destroyContext();
31
32 virtual bool onInitializeContext() = 0;
33 virtual void onDestroyContext() = 0;
34
35 void onSwapBuffers() override;
36
37 wgpu::TextureFormat fSurfaceFormat;
38 std::unique_ptr<dawn::native::Instance> fInstance;
39 wgpu::Device fDevice;
40 wgpu::Queue fQueue;
41 wgpu::Surface fSurface;
42 };
43
44 } // namespace skwindow::internal
45
46 #endif