-
Notifications
You must be signed in to change notification settings - Fork 58
Expand file tree
/
Copy pathGPUCanvasContext.cpp
More file actions
52 lines (46 loc) · 1.69 KB
/
GPUCanvasContext.cpp
File metadata and controls
52 lines (46 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include "GPUCanvasContext.h"
#include "Convertors.h"
#include "RNWebGPUManager.h"
namespace rnwgpu {
void GPUCanvasContext::configure(
std::shared_ptr<GPUCanvasConfiguration> configuration) {
Convertor conv;
wgpu::SurfaceConfiguration surfaceConfiguration;
surfaceConfiguration.device = configuration->device->get();
if (configuration->viewFormats.has_value()) {
if (!conv(surfaceConfiguration.viewFormats,
surfaceConfiguration.viewFormatCount,
configuration->viewFormats.value())) {
throw std::runtime_error("Error with SurfaceConfiguration");
}
}
if (!conv(surfaceConfiguration.usage, configuration->usage) ||
!conv(surfaceConfiguration.format, configuration->format)) {
throw std::runtime_error("Error with SurfaceConfiguration");
}
surfaceConfiguration.alphaMode = configuration->alphaMode;
_surfaceInfo->configure(surfaceConfiguration);
}
void GPUCanvasContext::unconfigure() {}
std::shared_ptr<GPUTexture> GPUCanvasContext::getCurrentTexture() {
auto prevSize = _surfaceInfo->getConfig();
auto width = _canvas->getWidth();
auto height = _canvas->getHeight();
auto sizeHasChanged = prevSize.width != width || prevSize.height != height;
if (sizeHasChanged) {
_surfaceInfo->reconfigure(width, height);
}
auto texture = _surfaceInfo->getCurrentTexture();
return std::make_shared<GPUTexture>(texture, "");
}
void GPUCanvasContext::present() {
#ifdef __APPLE__
dawn::native::metal::WaitForCommandsToBeScheduled(
_surfaceInfo->getDevice().Get());
#endif
auto size = _surfaceInfo->getSize();
_canvas->setClientWidth(size.width);
_canvas->setClientHeight(size.height);
_surfaceInfo->present();
}
} // namespace rnwgpu