• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2019 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 DawnWindowContext_DEFINED
8 #define DawnWindowContext_DEFINED
9 
10 #include "include/core/SkRefCnt.h"
11 #include "include/core/SkSurface.h"
12 
13 #include "tools/sk_app/WindowContext.h"
14 #include "dawn/webgpu_cpp.h"
15 #include "dawn_native/DawnNative.h"
16 #include "dawn/dawn_wsi.h"
17 
18 namespace sk_app {
19 
20 class DawnWindowContext : public WindowContext {
21 public:
22     DawnWindowContext(const DisplayParams&, wgpu::TextureFormat swapChainFormat);
23     ~DawnWindowContext() override;
24     sk_sp<SkSurface> getBackbufferSurface() override;
25     void swapBuffers() override;
isValid()26     bool isValid() override { return SkToBool(fDevice.Get()); }
27 
28     void resize(int w, int h) override;
29 
30     void setDisplayParams(const DisplayParams& params) override;
31 
32 protected:
isGpuContext()33     bool isGpuContext() override { return true; }
34     void initializeContext(int width, int height);
35     wgpu::Device createDevice(dawn_native::BackendType type);
36     virtual wgpu::Device onInitializeContext() = 0;
37     virtual void onDestroyContext() = 0;
38     virtual void onSwapBuffers() = 0;
getRTOrigin()39     virtual GrSurfaceOrigin getRTOrigin() const { return kTopLeft_GrSurfaceOrigin; }
40     void destroyContext();
41     virtual DawnSwapChainImplementation createSwapChainImplementation( int width, int height,
42         const DisplayParams& params) = 0;
43 
44     sk_sp<SkSurface>              fSurface;
45     DawnSwapChainImplementation   fSwapChainImplementation;
46     wgpu::TextureFormat           fSwapChainFormat;
47     wgpu::SwapChain               fSwapChain;
48     wgpu::Device                  fDevice;
49     std::unique_ptr<dawn_native::Instance> fInstance;
50 };
51 
52 }   // namespace sk_app
53 
54 #endif
55