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(const DisplayParams&, wgpu::TextureFormat swapChainFormat); 19 ~GraphiteDawnWindowContext() override; 20 sk_sp<SkSurface> getBackbufferSurface() override; isValid()21 bool isValid() override { return SkToBool(fDevice.Get()); } 22 void setDisplayParams(const DisplayParams& params) override; 23 24 protected: isGpuContext()25 bool isGpuContext() override { return true; } 26 void initializeContext(int width, int height); 27 wgpu::Device createDevice(wgpu::BackendType type); 28 wgpu::SwapChain createSwapChain(); 29 void destroyContext(); 30 31 virtual bool onInitializeContext() = 0; 32 virtual void onDestroyContext() = 0; getRTOrigin()33 virtual GrSurfaceOrigin getRTOrigin() const { return kTopLeft_GrSurfaceOrigin; } 34 35 void onSwapBuffers() override; 36 37 wgpu::TextureFormat fSwapChainFormat; 38 std::unique_ptr<dawn::native::Instance> fInstance; 39 wgpu::Device fDevice; 40 wgpu::Queue fQueue; 41 wgpu::Surface fSurface; 42 wgpu::SwapChain fSwapChain; 43 }; 44 45 } // namespace skwindow::internal 46 47 #endif 48