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; isValid()22 bool isValid() override { return SkToBool(fDevice.Get()); } 23 void setDisplayParams(std::unique_ptr<const DisplayParams> params) override; 24 25 protected: isGpuContext()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; getRTOrigin()34 virtual GrSurfaceOrigin getRTOrigin() const { return kTopLeft_GrSurfaceOrigin; } 35 36 void onSwapBuffers() override; 37 38 wgpu::TextureFormat fSurfaceFormat; 39 std::unique_ptr<dawn::native::Instance> fInstance; 40 wgpu::Device fDevice; 41 wgpu::Queue fQueue; 42 wgpu::Surface fSurface; 43 }; 44 45 } // namespace skwindow::internal 46 47 #endif 48