Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
skwindow::internal::GraphiteDawnWindowContext Class Referenceabstract

#include <GraphiteDawnWindowContext.h>

Inheritance diagram for skwindow::internal::GraphiteDawnWindowContext:
skwindow::WindowContext

Public Member Functions

 GraphiteDawnWindowContext (const DisplayParams &, wgpu::TextureFormat swapChainFormat)
 
 ~GraphiteDawnWindowContext () override
 
sk_sp< SkSurfacegetBackbufferSurface () override
 
bool isValid () override
 
void setDisplayParams (const DisplayParams &params) override
 
- Public Member Functions inherited from skwindow::WindowContext
 WindowContext (const DisplayParams &)
 
virtual ~WindowContext ()
 
void swapBuffers ()
 
virtual void resize (int w, int h)=0
 
virtual void activate (bool isActive)
 
const DisplayParamsgetDisplayParams ()
 
GrDirectContextdirectContext () const
 
int width () const
 
int height () const
 
SkISize dimensions () const
 
int sampleCount () const
 
int stencilBits () const
 

Protected Member Functions

bool isGpuContext () override
 
void initializeContext (int width, int height)
 
wgpu::Device createDevice (wgpu::BackendType type)
 
wgpu::SwapChain createSwapChain ()
 
void destroyContext ()
 
virtual bool onInitializeContext ()=0
 
virtual void onDestroyContext ()=0
 
virtual GrSurfaceOrigin getRTOrigin () const
 
void onSwapBuffers () override
 

Protected Attributes

wgpu::TextureFormat fSwapChainFormat
 
std::unique_ptr< dawn::native::Instance > fInstance
 
wgpu::Device fDevice
 
wgpu::Queue fQueue
 
wgpu::Surface fSurface
 
wgpu::SwapChain fSwapChain
 
- Protected Attributes inherited from skwindow::WindowContext
sk_sp< GrDirectContextfContext
 
int fWidth
 
int fHeight
 
DisplayParams fDisplayParams
 
int fSampleCount = 1
 
int fStencilBits = 0
 

Detailed Description

Definition at line 16 of file GraphiteDawnWindowContext.h.

Constructor & Destructor Documentation

◆ GraphiteDawnWindowContext()

skwindow::internal::GraphiteDawnWindowContext::GraphiteDawnWindowContext ( const DisplayParams params,
wgpu::TextureFormat  swapChainFormat 
)

Definition at line 28 of file GraphiteDawnWindowContext.cpp.

31 , fSwapChainFormat(swapChainFormat) {
32 WGPUInstanceDescriptor desc{};
33 // need for WaitAny with timeout > 0
34 desc.features.timedWaitAnyEnable = true;
35 fInstance = std::make_unique<dawn::native::Instance>(&desc);
36}
WindowContext(const DisplayParams &)
std::unique_ptr< dawn::native::Instance > fInstance
const EmbeddedViewParams * params

◆ ~GraphiteDawnWindowContext()

skwindow::internal::GraphiteDawnWindowContext::~GraphiteDawnWindowContext ( )
overridedefault

Member Function Documentation

◆ createDevice()

wgpu::Device skwindow::internal::GraphiteDawnWindowContext::createDevice ( wgpu::BackendType  type)
protected

Definition at line 123 of file GraphiteDawnWindowContext.cpp.

123 {
124 DawnProcTable backendProcs = dawn::native::GetProcs();
125 dawnProcSetProcs(&backendProcs);
126
127 static constexpr const char* kToggles[] = {
128 "allow_unsafe_apis", // Needed for dual-source blending, BufferMapExtendedUsages.
129 "use_user_defined_labels_in_backend",
130 };
131 wgpu::DawnTogglesDescriptor togglesDesc;
132 togglesDesc.enabledToggleCount = std::size(kToggles);
133 togglesDesc.enabledToggles = kToggles;
134
135 wgpu::RequestAdapterOptions adapterOptions;
136 adapterOptions.backendType = type;
137 adapterOptions.nextInChain = &togglesDesc;
138
139 std::vector<dawn::native::Adapter> adapters = fInstance->EnumerateAdapters(&adapterOptions);
140 if (adapters.empty()) {
141 return nullptr;
142 }
143
144 wgpu::Adapter adapter = adapters[0].Get();
145
146 std::vector<wgpu::FeatureName> features;
147 features.push_back(wgpu::FeatureName::SurfaceCapabilities);
148 if (adapter.HasFeature(wgpu::FeatureName::MSAARenderToSingleSampled)) {
149 features.push_back(wgpu::FeatureName::MSAARenderToSingleSampled);
150 }
151 if (adapter.HasFeature(wgpu::FeatureName::TransientAttachments)) {
152 features.push_back(wgpu::FeatureName::TransientAttachments);
153 }
154 if (adapter.HasFeature(wgpu::FeatureName::Unorm16TextureFormats)) {
155 features.push_back(wgpu::FeatureName::Unorm16TextureFormats);
156 }
157 if (adapter.HasFeature(wgpu::FeatureName::DualSourceBlending)) {
158 features.push_back(wgpu::FeatureName::DualSourceBlending);
159 }
160 if (adapter.HasFeature(wgpu::FeatureName::FramebufferFetch)) {
161 features.push_back(wgpu::FeatureName::FramebufferFetch);
162 }
163 if (adapter.HasFeature(wgpu::FeatureName::BufferMapExtendedUsages)) {
164 features.push_back(wgpu::FeatureName::BufferMapExtendedUsages);
165 }
166 if (adapter.HasFeature(wgpu::FeatureName::TextureCompressionETC2)) {
167 features.push_back(wgpu::FeatureName::TextureCompressionETC2);
168 }
169 if (adapter.HasFeature(wgpu::FeatureName::TextureCompressionBC)) {
170 features.push_back(wgpu::FeatureName::TextureCompressionBC);
171 }
172 if (adapter.HasFeature(wgpu::FeatureName::R8UnormStorage)) {
173 features.push_back(wgpu::FeatureName::R8UnormStorage);
174 }
175
176 wgpu::DeviceDescriptor deviceDescriptor;
177 deviceDescriptor.requiredFeatures = features.data();
178 deviceDescriptor.requiredFeatureCount = features.size();
179
180 auto device = adapter.CreateDevice(&deviceDescriptor);
181 if (!device) {
182 return nullptr;
183 }
184
185 device.SetUncapturedErrorCallback(
186 [](WGPUErrorType type, const char* message, void*) {
187 SkDebugf("Device error: %s\n", message);
188 SkASSERT(false);
189 },
190 nullptr);
191 return device;
192}
#define SkASSERT(cond)
Definition SkAssert.h:116
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
VkDevice device
Definition main.cc:53
Win32Message message

◆ createSwapChain()

wgpu::SwapChain skwindow::internal::GraphiteDawnWindowContext::createSwapChain ( )
protected

Definition at line 194 of file GraphiteDawnWindowContext.cpp.

194 {
195 wgpu::SwapChainDescriptor swapChainDesc;
196 swapChainDesc.usage = wgpu::TextureUsage::RenderAttachment |
197 wgpu::TextureUsage::TextureBinding |
198 wgpu::TextureUsage::CopySrc |
199 wgpu::TextureUsage::CopyDst;
200 swapChainDesc.format = fSwapChainFormat;
201 swapChainDesc.width = fWidth;
202 swapChainDesc.height = fHeight;
203 swapChainDesc.presentMode =
204 fDisplayParams.fDisableVsync ? wgpu::PresentMode::Immediate : wgpu::PresentMode::Fifo;
205 auto swapChain = fDevice.CreateSwapChain(fSurface, &swapChainDesc);
206 SkASSERT(swapChain);
207 return swapChain;
208}
DisplayParams fDisplayParams

◆ destroyContext()

void skwindow::internal::GraphiteDawnWindowContext::destroyContext ( )
protected

Definition at line 70 of file GraphiteDawnWindowContext.cpp.

70 {
71 if (!fDevice.Get()) {
72 return;
73 }
74
75 this->onDestroyContext();
76
77 fGraphiteRecorder = nullptr;
78 fGraphiteContext = nullptr;
79 fSwapChain = nullptr;
80 fSurface = nullptr;
81 fDevice = nullptr;
82}

◆ getBackbufferSurface()

sk_sp< SkSurface > skwindow::internal::GraphiteDawnWindowContext::getBackbufferSurface ( )
overridevirtual

Implements skwindow::WindowContext.

Definition at line 84 of file GraphiteDawnWindowContext.cpp.

84 {
85 auto texture = fSwapChain.GetCurrentTexture();
86 skgpu::graphite::DawnTextureInfo info(/*sampleCount=*/1,
87 skgpu::Mipmapped::kNo,
89 texture.GetUsage(),
90 wgpu::TextureAspect::All);
92 SkASSERT(this->graphiteRecorder());
93 auto surface = SkSurfaces::WrapBackendTexture(this->graphiteRecorder(),
94 backendTex,
99 return surface;
100}
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition DM.cpp:213
@ kBGRA_8888_SkColorType
pixel with 8 bits for blue, green, red, alpha; in 32-bit word
Definition SkColorType.h:26
VkSurfaceKHR surface
Definition main.cc:49
FlTexture * texture
SK_API sk_sp< SkSurface > WrapBackendTexture(GrRecordingContext *context, const GrBackendTexture &backendTexture, GrSurfaceOrigin origin, int sampleCnt, SkColorType colorType, sk_sp< SkColorSpace > colorSpace, const SkSurfaceProps *surfaceProps, TextureReleaseProc textureReleaseProc=nullptr, ReleaseContext releaseContext=nullptr)
SkSurfaceProps fSurfaceProps
sk_sp< SkColorSpace > fColorSpace

◆ getRTOrigin()

virtual GrSurfaceOrigin skwindow::internal::GraphiteDawnWindowContext::getRTOrigin ( ) const
inlineprotectedvirtual

Definition at line 33 of file GraphiteDawnWindowContext.h.

@ kTopLeft_GrSurfaceOrigin
Definition GrTypes.h:148

◆ initializeContext()

void skwindow::internal::GraphiteDawnWindowContext::initializeContext ( int  width,
int  height 
)
protected

Definition at line 38 of file GraphiteDawnWindowContext.cpp.

38 {
40
41 fWidth = width;
43
45 return;
46
50
52 backendContext.fInstance = wgpu::Instance(fInstance->Get());
53 backendContext.fDevice = fDevice;
54 backendContext.fQueue = fDevice.GetQueue();
55 // Needed to make synchronous readPixels work:
56 fDisplayParams.fGraphiteContextOptions.fPriv.fStoreContextRefInRecorder = true;
58 backendContext, fDisplayParams.fGraphiteContextOptions.fOptions);
59 if (!fGraphiteContext) {
60 SkASSERT(false);
61 return;
62 }
63
64 fGraphiteRecorder = fGraphiteContext->makeRecorder(ToolUtils::CreateTestingRecorderOptions());
65 SkASSERT(fGraphiteRecorder);
66}
sk_sp< GrDirectContext > fContext
SK_API std::unique_ptr< Context > MakeDawn(const DawnBackendContext &, const ContextOptions &)

◆ isGpuContext()

bool skwindow::internal::GraphiteDawnWindowContext::isGpuContext ( )
inlineoverrideprotectedvirtual

Reimplemented from skwindow::WindowContext.

Definition at line 25 of file GraphiteDawnWindowContext.h.

25{ return true; }

◆ isValid()

bool skwindow::internal::GraphiteDawnWindowContext::isValid ( )
inlineoverridevirtual

Implements skwindow::WindowContext.

Definition at line 21 of file GraphiteDawnWindowContext.h.

21{ return SkToBool(fDevice.Get()); }
static constexpr bool SkToBool(const T &x)
Definition SkTo.h:35

◆ onDestroyContext()

virtual void skwindow::internal::GraphiteDawnWindowContext::onDestroyContext ( )
protectedpure virtual

◆ onInitializeContext()

virtual bool skwindow::internal::GraphiteDawnWindowContext::onInitializeContext ( )
protectedpure virtual

◆ onSwapBuffers()

void skwindow::internal::GraphiteDawnWindowContext::onSwapBuffers ( )
overrideprotectedvirtual

Implements skwindow::WindowContext.

Definition at line 102 of file GraphiteDawnWindowContext.cpp.

102 {
103 if (fGraphiteContext) {
104 SkASSERT(fGraphiteRecorder);
105 std::unique_ptr<skgpu::graphite::Recording> recording = fGraphiteRecorder->snap();
106 if (recording) {
108 info.fRecording = recording.get();
109 fGraphiteContext->insertRecording(info);
110 fGraphiteContext->submit(skgpu::graphite::SyncToCpu::kNo);
111 }
112 }
113
114 fSwapChain.Present();
115}

◆ setDisplayParams()

void skwindow::internal::GraphiteDawnWindowContext::setDisplayParams ( const DisplayParams params)
overridevirtual

Member Data Documentation

◆ fDevice

wgpu::Device skwindow::internal::GraphiteDawnWindowContext::fDevice
protected

Definition at line 39 of file GraphiteDawnWindowContext.h.

◆ fInstance

std::unique_ptr<dawn::native::Instance> skwindow::internal::GraphiteDawnWindowContext::fInstance
protected

Definition at line 38 of file GraphiteDawnWindowContext.h.

◆ fQueue

wgpu::Queue skwindow::internal::GraphiteDawnWindowContext::fQueue
protected

Definition at line 40 of file GraphiteDawnWindowContext.h.

◆ fSurface

wgpu::Surface skwindow::internal::GraphiteDawnWindowContext::fSurface
protected

Definition at line 41 of file GraphiteDawnWindowContext.h.

◆ fSwapChain

wgpu::SwapChain skwindow::internal::GraphiteDawnWindowContext::fSwapChain
protected

Definition at line 42 of file GraphiteDawnWindowContext.h.

◆ fSwapChainFormat

wgpu::TextureFormat skwindow::internal::GraphiteDawnWindowContext::fSwapChainFormat
protected

Definition at line 37 of file GraphiteDawnWindowContext.h.


The documentation for this class was generated from the following files: