1cb93a386Sopenharmony_ci/* 2cb93a386Sopenharmony_ci * Copyright 2019 Google Inc. 3cb93a386Sopenharmony_ci * 4cb93a386Sopenharmony_ci * Use of this source code is governed by a BSD-style license that can be 5cb93a386Sopenharmony_ci * found in the LICENSE file. 6cb93a386Sopenharmony_ci */ 7cb93a386Sopenharmony_ci#ifndef DawnWindowContext_DEFINED 8cb93a386Sopenharmony_ci#define DawnWindowContext_DEFINED 9cb93a386Sopenharmony_ci 10cb93a386Sopenharmony_ci#include "include/core/SkRefCnt.h" 11cb93a386Sopenharmony_ci#include "include/core/SkSurface.h" 12cb93a386Sopenharmony_ci 13cb93a386Sopenharmony_ci#include "tools/sk_app/WindowContext.h" 14cb93a386Sopenharmony_ci#include "dawn/webgpu_cpp.h" 15cb93a386Sopenharmony_ci#include "dawn_native/DawnNative.h" 16cb93a386Sopenharmony_ci#include "dawn/dawn_wsi.h" 17cb93a386Sopenharmony_ci 18cb93a386Sopenharmony_cinamespace sk_app { 19cb93a386Sopenharmony_ci 20cb93a386Sopenharmony_ciclass DawnWindowContext : public WindowContext { 21cb93a386Sopenharmony_cipublic: 22cb93a386Sopenharmony_ci DawnWindowContext(const DisplayParams&, wgpu::TextureFormat swapChainFormat); 23cb93a386Sopenharmony_ci ~DawnWindowContext() override; 24cb93a386Sopenharmony_ci sk_sp<SkSurface> getBackbufferSurface() override; 25cb93a386Sopenharmony_ci void swapBuffers() override; 26cb93a386Sopenharmony_ci bool isValid() override { return SkToBool(fDevice.Get()); } 27cb93a386Sopenharmony_ci 28cb93a386Sopenharmony_ci void resize(int w, int h) override; 29cb93a386Sopenharmony_ci 30cb93a386Sopenharmony_ci void setDisplayParams(const DisplayParams& params) override; 31cb93a386Sopenharmony_ci 32cb93a386Sopenharmony_ciprotected: 33cb93a386Sopenharmony_ci bool isGpuContext() override { return true; } 34cb93a386Sopenharmony_ci void initializeContext(int width, int height); 35cb93a386Sopenharmony_ci wgpu::Device createDevice(dawn_native::BackendType type); 36cb93a386Sopenharmony_ci virtual wgpu::Device onInitializeContext() = 0; 37cb93a386Sopenharmony_ci virtual void onDestroyContext() = 0; 38cb93a386Sopenharmony_ci virtual void onSwapBuffers() = 0; 39cb93a386Sopenharmony_ci virtual GrSurfaceOrigin getRTOrigin() const { return kTopLeft_GrSurfaceOrigin; } 40cb93a386Sopenharmony_ci void destroyContext(); 41cb93a386Sopenharmony_ci virtual DawnSwapChainImplementation createSwapChainImplementation( int width, int height, 42cb93a386Sopenharmony_ci const DisplayParams& params) = 0; 43cb93a386Sopenharmony_ci 44cb93a386Sopenharmony_ci sk_sp<SkSurface> fSurface; 45cb93a386Sopenharmony_ci DawnSwapChainImplementation fSwapChainImplementation; 46cb93a386Sopenharmony_ci wgpu::TextureFormat fSwapChainFormat; 47cb93a386Sopenharmony_ci wgpu::SwapChain fSwapChain; 48cb93a386Sopenharmony_ci wgpu::Device fDevice; 49cb93a386Sopenharmony_ci std::unique_ptr<dawn_native::Instance> fInstance; 50cb93a386Sopenharmony_ci}; 51cb93a386Sopenharmony_ci 52cb93a386Sopenharmony_ci} // namespace sk_app 53cb93a386Sopenharmony_ci 54cb93a386Sopenharmony_ci#endif 55