@nativescript/canvas 2.0.0-rc.2 → 2.0.0-rc.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Canvas/common.d.ts +13 -6
- package/Canvas/common.js +257 -206
- package/Canvas/common.js.map +1 -1
- package/Canvas/index.android.d.ts +2 -0
- package/Canvas/index.android.js +23 -4
- package/Canvas/index.android.js.map +1 -1
- package/Canvas/index.d.ts +3 -0
- package/Canvas/index.ios.d.ts +2 -0
- package/Canvas/index.ios.js +16 -3
- package/Canvas/index.ios.js.map +1 -1
- package/Canvas/utils.js +2 -1
- package/Canvas/utils.js.map +1 -1
- package/Canvas2D/CanvasRenderingContext2D/index.d.ts +1 -0
- package/Canvas2D/CanvasRenderingContext2D/index.js +158 -6
- package/Canvas2D/CanvasRenderingContext2D/index.js.map +1 -1
- package/Canvas2D/DOMMatrix/index.js +280 -2
- package/Canvas2D/DOMMatrix/index.js.map +1 -1
- package/Canvas2D/Path2D/index.js.map +1 -1
- package/Fonts/FontFace.android.js +7 -3
- package/Fonts/FontFace.android.js.map +1 -1
- package/Fonts/FontFace.ios.d.ts +1 -0
- package/Fonts/FontFace.ios.js +10 -3
- package/Fonts/FontFace.ios.js.map +1 -1
- package/TextDecoder/index.d.ts +1 -0
- package/TextDecoder/index.js +17 -0
- package/TextDecoder/index.js.map +1 -1
- package/WebGL/WebGLRenderingContext/index.js +0 -1
- package/WebGL/WebGLRenderingContext/index.js.map +1 -1
- package/WebGPU/GPUCanvasContext.d.ts +0 -1
- package/WebGPU/GPUCanvasContext.js +6 -18
- package/WebGPU/GPUCanvasContext.js.map +1 -1
- package/WebGPU/GPUCommandEncoder.d.ts +1 -1
- package/WebGPU/GPUCommandEncoder.js +1 -1
- package/WebGPU/GPUCommandEncoder.js.map +1 -1
- package/WebGPU/GPUCompilationInfo.d.ts +10 -0
- package/WebGPU/GPUCompilationInfo.js +20 -0
- package/WebGPU/GPUCompilationInfo.js.map +1 -0
- package/WebGPU/GPUCompilationMessage.d.ts +11 -0
- package/WebGPU/GPUCompilationMessage.js +30 -0
- package/WebGPU/GPUCompilationMessage.js.map +1 -0
- package/WebGPU/GPUDevice.d.ts +2 -2
- package/WebGPU/GPUDevice.js.map +1 -1
- package/WebGPU/GPUQueue.js +1 -4
- package/WebGPU/GPUQueue.js.map +1 -1
- package/WebGPU/GPURenderPassEncoder.d.ts +1 -1
- package/WebGPU/GPURenderPassEncoder.js +2 -2
- package/WebGPU/GPURenderPassEncoder.js.map +1 -1
- package/WebGPU/GPUShaderModule.d.ts +2 -0
- package/WebGPU/GPUShaderModule.js +10 -0
- package/WebGPU/GPUShaderModule.js.map +1 -1
- package/WebGPU/Interfaces.d.ts +1 -0
- package/WebGPU/Types.d.ts +3 -3
- package/WebGPU/Utils.d.ts +1 -1
- package/WebGPU/Utils.js +67 -93
- package/WebGPU/Utils.js.map +1 -1
- package/WebGPU/index.d.ts +2 -0
- package/WebGPU/index.js +2 -0
- package/WebGPU/index.js.map +1 -1
- package/angular/fesm2022/nativescript-canvas-angular.mjs +5 -5
- package/angular/package.json +0 -2
- package/helpers.d.ts +3 -0
- package/helpers.js +9 -0
- package/helpers.js.map +1 -1
- package/index.js +6 -1
- package/index.js.map +1 -1
- package/package.json +1 -1
- package/platforms/android/canvas-release.aar +0 -0
- package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/CanvasNative +0 -0
- package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Headers/CanvasNative-Swift.h +10 -5
- package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Headers/canvas_native.h +294 -47
- package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Info.plist +0 -0
- package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Modules/CanvasNative.swiftmodule/Project/arm64-apple-ios.swiftsourceinfo +0 -0
- package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios.abi.json +11317 -11881
- package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios.private.swiftinterface +55 -49
- package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios.swiftdoc +0 -0
- package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios.swiftinterface +55 -49
- package/platforms/ios/CanvasNative.xcframework/ios-arm64/dSYMs/CanvasNative.framework.dSYM/Contents/Resources/DWARF/CanvasNative +0 -0
- package/platforms/ios/CanvasNative.xcframework/ios-arm64/dSYMs/CanvasNative.framework.dSYM/Contents/Resources/Relocations/aarch64/CanvasNative.yml +954 -994
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/CanvasNative +0 -0
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Headers/CanvasNative-Swift.h +20 -10
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Headers/canvas_native.h +294 -47
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Info.plist +0 -0
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/Project/arm64-apple-ios-simulator.swiftsourceinfo +0 -0
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/Project/x86_64-apple-ios-simulator.swiftsourceinfo +0 -0
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios-simulator.abi.json +11317 -11881
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios-simulator.private.swiftinterface +55 -49
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios-simulator.swiftdoc +0 -0
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios-simulator.swiftinterface +55 -49
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/x86_64-apple-ios-simulator.abi.json +11317 -11881
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/x86_64-apple-ios-simulator.private.swiftinterface +55 -49
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/x86_64-apple-ios-simulator.swiftdoc +0 -0
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/x86_64-apple-ios-simulator.swiftinterface +55 -49
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/_CodeSignature/CodeResources +29 -29
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/dSYMs/CanvasNative.framework.dSYM/Contents/Resources/DWARF/CanvasNative +0 -0
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/dSYMs/CanvasNative.framework.dSYM/Contents/Resources/Relocations/aarch64/CanvasNative.yml +955 -993
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/dSYMs/CanvasNative.framework.dSYM/Contents/Resources/Relocations/x86_64/CanvasNative.yml +824 -1037
- package/platforms/ios/src/cpp/Caches.h +6 -0
- package/platforms/ios/src/cpp/CanvasJSIModule.cpp +1172 -1011
- package/platforms/ios/src/cpp/CanvasJSIModule.h +6 -0
- package/platforms/ios/src/cpp/Helpers.h +23 -2
- package/platforms/ios/src/cpp/NativeType.h +3 -1
- package/platforms/ios/src/cpp/OnRafCallback.cpp +15 -10
- package/platforms/ios/src/cpp/OnRafCallback.h +1 -0
- package/platforms/ios/src/cpp/PromiseCallback.h +42 -20
- package/platforms/ios/src/cpp/TextDecoderImpl.cpp +142 -0
- package/platforms/ios/src/cpp/TextDecoderImpl.h +2 -0
- package/platforms/ios/src/cpp/canvas2d/CanvasRenderingContext2DImpl.cpp +59 -15
- package/platforms/ios/src/cpp/canvas2d/Path2D.cpp +1 -1
- package/platforms/ios/src/cpp/webgpu/GPUAdapterImpl.cpp +4 -8
- package/platforms/ios/src/cpp/webgpu/GPUCanvasContextImpl.cpp +431 -326
- package/platforms/ios/src/cpp/webgpu/GPUCanvasContextImpl.h +98 -42
- package/platforms/ios/src/cpp/webgpu/GPUCommandEncoderImpl.cpp +1150 -1144
- package/platforms/ios/src/cpp/webgpu/GPUCompilationInfoImpl.cpp +88 -0
- package/platforms/ios/src/cpp/webgpu/GPUCompilationInfoImpl.h +49 -0
- package/platforms/ios/src/cpp/webgpu/GPUCompilationMessageImpl.cpp +193 -0
- package/platforms/ios/src/cpp/webgpu/GPUCompilationMessageImpl.h +64 -0
- package/platforms/ios/src/cpp/webgpu/GPUDeviceImpl.cpp +69 -34
- package/platforms/ios/src/cpp/webgpu/GPUQueueImpl.cpp +45 -18
- package/platforms/ios/src/cpp/webgpu/GPURenderPassEncoderImpl.cpp +22 -19
- package/platforms/ios/src/cpp/webgpu/GPUShaderModuleImpl.cpp +23 -0
- package/platforms/ios/src/cpp/webgpu/GPUShaderModuleImpl.h +2 -0
- package/platforms/ios/src/cpp/webgpu/GPUTextureImpl.cpp +11 -0
- package/platforms/ios/src/cpp/webgpu/GPUUtils.h +25 -15
- package/angular/esm2022/index.mjs +0 -17
- package/angular/esm2022/nativescript-canvas-angular.mjs +0 -5
|
@@ -8,372 +8,477 @@
|
|
|
8
8
|
#include "GPUUtils.h"
|
|
9
9
|
#include "GPUQueueImpl.h"
|
|
10
10
|
|
|
11
|
+
v8::CFunction GPUCanvasContextImpl::fast_start_raf_(
|
|
12
|
+
v8::CFunction::Make(GPUCanvasContextImpl::__FastStartRaf));
|
|
13
|
+
|
|
14
|
+
v8::CFunction GPUCanvasContextImpl::fast_stop_raf_(
|
|
15
|
+
v8::CFunction::Make(GPUCanvasContextImpl::__FastStopRaf));
|
|
16
|
+
|
|
17
|
+
|
|
11
18
|
GPUCanvasContextImpl::GPUCanvasContextImpl(const CanvasGPUCanvasContext *context) : context_(
|
|
12
|
-
|
|
19
|
+
context) {
|
|
20
|
+
auto ctx_ptr = reinterpret_cast<intptr_t>(reinterpret_cast<intptr_t *>(this));
|
|
21
|
+
auto raf_callback = new OnRafCallback(ctx_ptr, 3);
|
|
22
|
+
auto raf_callback_ptr = reinterpret_cast<intptr_t>(reinterpret_cast<intptr_t *>(raf_callback));
|
|
23
|
+
auto raf = canvas_native_raf_create(raf_callback_ptr, OnRafCallbackOnFrame);
|
|
24
|
+
|
|
25
|
+
this->SetRaf(std::make_shared<RafImpl>(raf_callback, raf_callback_ptr, raf));
|
|
26
|
+
|
|
27
|
+
auto _raf = this->GetRaf();
|
|
28
|
+
|
|
29
|
+
if (_raf != nullptr) {
|
|
30
|
+
canvas_native_raf_start(_raf->GetRaf());
|
|
31
|
+
}
|
|
32
|
+
}
|
|
13
33
|
|
|
14
34
|
const CanvasGPUCanvasContext *GPUCanvasContextImpl::GetContext() {
|
|
15
|
-
|
|
35
|
+
return this->context_;
|
|
16
36
|
}
|
|
17
37
|
|
|
18
38
|
|
|
19
39
|
void GPUCanvasContextImpl::Init(v8::Local<v8::Object> canvasModule, v8::Isolate *isolate) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
40
|
+
v8::Locker locker(isolate);
|
|
41
|
+
v8::Isolate::Scope isolate_scope(isolate);
|
|
42
|
+
v8::HandleScope handle_scope(isolate);
|
|
43
|
+
|
|
44
|
+
auto ctor = GetCtor(isolate);
|
|
45
|
+
auto context = isolate->GetCurrentContext();
|
|
46
|
+
auto func = ctor->GetFunction(context).ToLocalChecked();
|
|
47
|
+
|
|
48
|
+
canvasModule->Set(context, ConvertToV8String(isolate, "GPUCanvasContext"), func).FromJust();
|
|
29
49
|
}
|
|
30
50
|
|
|
31
51
|
GPUCanvasContextImpl *GPUCanvasContextImpl::GetPointer(const v8::Local<v8::Object> &object) {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
52
|
+
auto ptr = object->GetAlignedPointerFromInternalField(0);
|
|
53
|
+
if (ptr == nullptr) {
|
|
54
|
+
return nullptr;
|
|
55
|
+
}
|
|
56
|
+
return static_cast<GPUCanvasContextImpl *>(ptr);
|
|
37
57
|
}
|
|
38
58
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
ctorTmpl->InstanceTemplate()->SetInternalFieldCount(2);
|
|
48
|
-
ctorTmpl->SetClassName(ConvertToV8String(isolate, "GPUCanvasContext"));
|
|
49
|
-
|
|
50
|
-
auto tmpl = ctorTmpl->InstanceTemplate();
|
|
51
|
-
tmpl->SetInternalFieldCount(2);
|
|
52
|
-
|
|
59
|
+
void GPUCanvasContextImpl::StartRaf() {
|
|
60
|
+
auto raf = this->GetRaf();
|
|
61
|
+
if (raf != nullptr) {
|
|
62
|
+
if (!canvas_native_raf_get_started(raf->GetRaf())) {
|
|
63
|
+
canvas_native_raf_start(raf->GetRaf());
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
53
67
|
|
|
54
|
-
tmpl->Set(
|
|
55
|
-
ConvertToV8String(isolate, "configure"),
|
|
56
|
-
v8::FunctionTemplate::New(isolate, &Configure));
|
|
57
68
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
69
|
+
void GPUCanvasContextImpl::StopRaf() {
|
|
70
|
+
auto raf = this->GetRaf();
|
|
71
|
+
if (raf != nullptr) {
|
|
72
|
+
if (canvas_native_raf_get_started(raf->GetRaf())) {
|
|
73
|
+
canvas_native_raf_stop(raf->GetRaf());
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
61
77
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
78
|
+
void GPUCanvasContextImpl::SetRaf(std::shared_ptr<RafImpl> raf) {
|
|
79
|
+
this->raf_ = std::move(raf);
|
|
80
|
+
}
|
|
65
81
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
82
|
+
RafImpl *GPUCanvasContextImpl::GetRaf() {
|
|
83
|
+
return this->raf_.get();
|
|
84
|
+
}
|
|
69
85
|
|
|
70
|
-
tmpl->Set(
|
|
71
|
-
ConvertToV8String(isolate, "getCapabilities"),
|
|
72
|
-
v8::FunctionTemplate::New(isolate, &GetCapabilities));
|
|
73
86
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
87
|
+
void GPUCanvasContextImpl::__StartRaf(const v8::FunctionCallbackInfo<v8::Value> &args) {
|
|
88
|
+
GPUCanvasContextImpl *ptr = GetPointer(args.This());
|
|
89
|
+
if (ptr == nullptr) {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
ptr->StartRaf();
|
|
94
|
+
|
|
95
|
+
}
|
|
77
96
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
97
|
+
void GPUCanvasContextImpl::__StopRaf(const v8::FunctionCallbackInfo<v8::Value> &args) {
|
|
98
|
+
GPUCanvasContextImpl *ptr = GetPointer(args.This());
|
|
99
|
+
if (ptr == nullptr) {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
ptr->StopRaf();
|
|
104
|
+
|
|
81
105
|
}
|
|
82
106
|
|
|
83
|
-
void GPUCanvasContextImpl::Configure(const v8::FunctionCallbackInfo<v8::Value> &args) {
|
|
84
|
-
GPUCanvasContextImpl *ptr = GetPointer(args.This());
|
|
85
|
-
auto isolate = args.GetIsolate();
|
|
86
|
-
auto context = isolate->GetCurrentContext();
|
|
87
|
-
auto optionsValue = args[0];
|
|
88
|
-
if (ptr == nullptr) {
|
|
89
|
-
return;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
if (optionsValue->IsNullOrUndefined() || !optionsValue->IsObject()) {
|
|
93
|
-
return;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
auto options = optionsValue.As<v8::Object>();
|
|
97
|
-
|
|
98
|
-
v8::Local<v8::Value> deviceValue;
|
|
99
|
-
|
|
100
|
-
options->Get(context, ConvertToV8String(isolate, "device")).ToLocal(
|
|
101
|
-
&deviceValue);
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
if (deviceValue->IsNullOrUndefined() || !deviceValue->IsObject()) {
|
|
105
|
-
return;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
auto device = GPUDeviceImpl::GetPointer(deviceValue.As<v8::Object>());
|
|
109
|
-
|
|
110
|
-
if (device == nullptr) { return; }
|
|
111
|
-
|
|
112
|
-
CanvasGPUSurfaceConfiguration config{};
|
|
113
|
-
config.alphaMode = CanvasGPUSurfaceAlphaMode::CanvasGPUSurfaceAlphaModeOpaque;
|
|
114
|
-
config.presentMode = CanvasGPUPresentMode::CanvasGPUPresentModeFifo;
|
|
115
|
-
config.view_formats = nullptr;
|
|
116
|
-
config.view_formats_size = 0;
|
|
117
|
-
config.usage = 0x10;
|
|
118
|
-
config.format = CanvasOptionalGPUTextureFormat{
|
|
119
|
-
CanvasOptionalGPUTextureFormatNone
|
|
120
|
-
};
|
|
121
|
-
config.size = nullptr;
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
v8::Local<v8::Value> formatValue;
|
|
125
|
-
|
|
126
|
-
if (options->Get(context, ConvertToV8String(isolate, "format")).ToLocal(
|
|
127
|
-
&formatValue)) {
|
|
128
|
-
auto format = ConvertFromV8String(isolate, formatValue);
|
|
129
|
-
config.format = canvas_native_webgpu_enum_string_to_gpu_texture(format.c_str());
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
v8::Local<v8::Value> usageValue;
|
|
134
|
-
options->Get(context, ConvertToV8String(isolate, "usage")).ToLocal(
|
|
135
|
-
&usageValue);
|
|
136
|
-
|
|
137
|
-
if (!usageValue.IsEmpty() && usageValue->IsUint32()) {
|
|
138
|
-
config.usage = usageValue->Uint32Value(context).ToChecked();
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
v8::Local<v8::Value> presentModeValue;
|
|
143
|
-
|
|
144
|
-
if (options->Get(context, ConvertToV8String(isolate, "presentMode")).ToLocal(
|
|
145
|
-
&presentModeValue)) {
|
|
146
|
-
if (presentModeValue->IsString()) {
|
|
147
|
-
auto presentMode = ConvertFromV8String(isolate, presentModeValue);
|
|
148
|
-
if (strcmp(presentMode.c_str(), "autoVsync") == 0) {
|
|
149
|
-
config.presentMode = CanvasGPUPresentMode::CanvasGPUPresentModeAutoVsync;
|
|
150
|
-
} else if (strcmp(presentMode.c_str(), "autoNoVsync") == 0) {
|
|
151
|
-
config.presentMode = CanvasGPUPresentMode::CanvasGPUPresentModeAutoNoVsync;
|
|
152
|
-
} else if (strcmp(presentMode.c_str(), "fifo") == 0) {
|
|
153
|
-
config.presentMode = CanvasGPUPresentMode::CanvasGPUPresentModeFifo;
|
|
154
|
-
} else if (strcmp(presentMode.c_str(), "fifoRelaxed") == 0) {
|
|
155
|
-
config.presentMode = CanvasGPUPresentMode::CanvasGPUPresentModeFifoRelaxed;
|
|
156
|
-
} else if (strcmp(presentMode.c_str(), "immediate") == 0) {
|
|
157
|
-
config.presentMode = CanvasGPUPresentMode::CanvasGPUPresentModeImmediate;
|
|
158
|
-
} else if (strcmp(presentMode.c_str(), "mailbox") == 0) {
|
|
159
|
-
config.presentMode = CanvasGPUPresentMode::CanvasGPUPresentModeMailbox;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
} else if (presentModeValue->IsInt32()) {
|
|
163
|
-
config.presentMode = (CanvasGPUPresentMode) presentModeValue->Int32Value(
|
|
164
|
-
context).ToChecked();
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
v8::Local<v8::Value> alphaModeValue;
|
|
170
|
-
|
|
171
|
-
if (options->Get(context, ConvertToV8String(isolate, "alphaMode")).ToLocal(
|
|
172
|
-
&alphaModeValue)) {
|
|
173
|
-
if (alphaModeValue->IsString()) {
|
|
174
|
-
auto alphaMode = ConvertFromV8String(isolate, alphaModeValue);
|
|
175
|
-
if (strcmp(alphaMode.c_str(), "premultiplied") == 0) {
|
|
176
|
-
config.alphaMode = CanvasGPUSurfaceAlphaMode::CanvasGPUSurfaceAlphaModePreMultiplied;
|
|
177
|
-
} else if (strcmp(alphaMode.c_str(), "opaque") == 0) {
|
|
178
|
-
config.alphaMode = CanvasGPUSurfaceAlphaMode::CanvasGPUSurfaceAlphaModeOpaque;
|
|
179
|
-
} else if (strcmp(alphaMode.c_str(), "postmultiplied") == 0) {
|
|
180
|
-
config.alphaMode = CanvasGPUSurfaceAlphaMode::CanvasGPUSurfaceAlphaModePostMultiplied;
|
|
181
|
-
} else if (strcmp(alphaMode.c_str(), "inherit") == 0) {
|
|
182
|
-
config.alphaMode = CanvasGPUSurfaceAlphaMode::CanvasGPUSurfaceAlphaModeInherit;
|
|
183
|
-
} else if (strcmp(alphaMode.c_str(), "auto") == 0) {
|
|
184
|
-
config.alphaMode = CanvasGPUSurfaceAlphaMode::CanvasGPUSurfaceAlphaModeAuto;
|
|
185
|
-
}
|
|
186
|
-
} else if (alphaModeValue->IsInt32()) {
|
|
187
|
-
config.alphaMode = (CanvasGPUSurfaceAlphaMode) alphaModeValue->Int32Value(
|
|
188
|
-
context).ToChecked();
|
|
189
|
-
}
|
|
190
107
|
|
|
191
|
-
|
|
108
|
+
void GPUCanvasContextImpl::GetContinuousRenderMode(v8::Local<v8::String> property,
|
|
109
|
+
const v8::PropertyCallbackInfo<v8::Value> &info) {
|
|
110
|
+
GPUCanvasContextImpl *ptr = GetPointer(info.This());
|
|
111
|
+
if (ptr == nullptr) {
|
|
112
|
+
info.GetReturnValue().Set(false);
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
info.GetReturnValue().Set(ptr->continuousRender_);
|
|
116
|
+
}
|
|
192
117
|
|
|
118
|
+
void GPUCanvasContextImpl::SetContinuousRenderMode(v8::Local<v8::String> property,
|
|
119
|
+
v8::Local<v8::Value> value,
|
|
120
|
+
const v8::PropertyCallbackInfo<void> &info) {
|
|
121
|
+
GPUCanvasContextImpl *ptr = GetPointer(info.This());
|
|
122
|
+
if (ptr == nullptr) {
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
auto isolate = info.GetIsolate();
|
|
126
|
+
auto val = value->BooleanValue(isolate);
|
|
127
|
+
if (val == ptr->continuousRender_) {
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
if (val) {
|
|
131
|
+
ptr->StartRaf();
|
|
132
|
+
} else {
|
|
133
|
+
ptr->StopRaf();
|
|
134
|
+
}
|
|
135
|
+
ptr->continuousRender_ = val;
|
|
136
|
+
}
|
|
193
137
|
|
|
194
|
-
v8::Local<v8::Value> sizeValue;
|
|
195
|
-
options->Get(context, ConvertToV8String(isolate, "size")).ToLocal(
|
|
196
|
-
&sizeValue);
|
|
197
138
|
|
|
198
|
-
CanvasExtent3d size = ParseExtent3d(isolate, sizeValue);
|
|
199
139
|
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
140
|
+
v8::Local<v8::FunctionTemplate> GPUCanvasContextImpl::GetCtor(v8::Isolate *isolate) {
|
|
141
|
+
auto cache = Caches::Get(isolate);
|
|
142
|
+
auto ctor = cache->GPUCanvasContextTmpl.get();
|
|
143
|
+
if (ctor != nullptr) {
|
|
144
|
+
return ctor->Get(isolate);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
v8::Local<v8::FunctionTemplate> ctorTmpl = v8::FunctionTemplate::New(isolate);
|
|
148
|
+
ctorTmpl->InstanceTemplate()->SetInternalFieldCount(2);
|
|
149
|
+
ctorTmpl->SetClassName(ConvertToV8String(isolate, "GPUCanvasContext"));
|
|
150
|
+
|
|
151
|
+
auto tmpl = ctorTmpl->InstanceTemplate();
|
|
152
|
+
tmpl->SetInternalFieldCount(2);
|
|
153
|
+
|
|
154
|
+
SetFastMethod(isolate, tmpl, "__startRaf", __StartRaf, &fast_start_raf_,
|
|
155
|
+
v8::Local<v8::Value>());
|
|
156
|
+
|
|
157
|
+
SetFastMethod(isolate, tmpl, "__stopRaf", __StopRaf, &fast_stop_raf_,
|
|
158
|
+
v8::Local<v8::Value>());
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
tmpl->Set(
|
|
162
|
+
ConvertToV8String(isolate, "configure"),
|
|
163
|
+
v8::FunctionTemplate::New(isolate, &Configure));
|
|
164
|
+
|
|
165
|
+
tmpl->Set(
|
|
166
|
+
ConvertToV8String(isolate, "unconfigure"),
|
|
167
|
+
v8::FunctionTemplate::New(isolate, &UnConfigure));
|
|
168
|
+
|
|
169
|
+
tmpl->Set(
|
|
170
|
+
ConvertToV8String(isolate, "getCurrentTexture"),
|
|
171
|
+
v8::FunctionTemplate::New(isolate, &GetCurrentTexture));
|
|
172
|
+
|
|
173
|
+
tmpl->Set(
|
|
174
|
+
ConvertToV8String(isolate, "presentSurface"),
|
|
175
|
+
v8::FunctionTemplate::New(isolate, &PresentSurface));
|
|
176
|
+
|
|
177
|
+
tmpl->Set(
|
|
178
|
+
ConvertToV8String(isolate, "getCapabilities"),
|
|
179
|
+
v8::FunctionTemplate::New(isolate, &GetCapabilities));
|
|
180
|
+
|
|
181
|
+
tmpl->Set(
|
|
182
|
+
ConvertToV8String(isolate, "__toDataURL"),
|
|
183
|
+
v8::FunctionTemplate::New(isolate, &__ToDataURL));
|
|
184
|
+
|
|
185
|
+
tmpl->SetAccessor(ConvertToV8String(isolate, "continuousRenderMode"), GetContinuousRenderMode,
|
|
186
|
+
SetContinuousRenderMode);
|
|
187
|
+
|
|
188
|
+
cache->GPUCanvasContextTmpl =
|
|
189
|
+
std::make_unique<v8::Persistent<v8::FunctionTemplate>>(isolate, ctorTmpl);
|
|
190
|
+
return ctorTmpl;
|
|
191
|
+
}
|
|
205
192
|
|
|
193
|
+
void GPUCanvasContextImpl::Configure(const v8::FunctionCallbackInfo<v8::Value> &args) {
|
|
194
|
+
GPUCanvasContextImpl *ptr = GetPointer(args.This());
|
|
195
|
+
auto isolate = args.GetIsolate();
|
|
196
|
+
auto context = isolate->GetCurrentContext();
|
|
197
|
+
auto optionsValue = args[0];
|
|
198
|
+
if (ptr == nullptr) {
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
if (optionsValue->IsNullOrUndefined() || !optionsValue->IsObject()) {
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
auto options = optionsValue.As<v8::Object>();
|
|
207
|
+
|
|
208
|
+
v8::Local<v8::Value> deviceValue;
|
|
209
|
+
|
|
210
|
+
options->Get(context, ConvertToV8String(isolate, "device")).ToLocal(
|
|
211
|
+
&deviceValue);
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
if (deviceValue->IsNullOrUndefined() || !deviceValue->IsObject()) {
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
auto device = GPUDeviceImpl::GetPointer(deviceValue.As<v8::Object>());
|
|
219
|
+
|
|
220
|
+
if (device == nullptr) { return; }
|
|
221
|
+
|
|
222
|
+
CanvasGPUSurfaceConfiguration config{};
|
|
223
|
+
config.alphaMode = CanvasGPUSurfaceAlphaMode::CanvasGPUSurfaceAlphaModeOpaque;
|
|
224
|
+
config.presentMode = CanvasGPUPresentMode::CanvasGPUPresentModeFifo;
|
|
225
|
+
config.view_formats = nullptr;
|
|
226
|
+
config.view_formats_size = 0;
|
|
227
|
+
config.usage = 0x10;
|
|
228
|
+
config.format = CanvasOptionalGPUTextureFormat{
|
|
229
|
+
CanvasOptionalGPUTextureFormatNone
|
|
230
|
+
};
|
|
231
|
+
config.size = nullptr;
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
v8::Local<v8::Value> formatValue;
|
|
235
|
+
|
|
236
|
+
if (options->Get(context, ConvertToV8String(isolate, "format")).ToLocal(
|
|
237
|
+
&formatValue)) {
|
|
238
|
+
auto format = ConvertFromV8String(isolate, formatValue);
|
|
239
|
+
config.format = canvas_native_webgpu_enum_string_to_gpu_texture(format.c_str());
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
v8::Local<v8::Value> usageValue;
|
|
244
|
+
options->Get(context, ConvertToV8String(isolate, "usage")).ToLocal(
|
|
245
|
+
&usageValue);
|
|
246
|
+
|
|
247
|
+
if (!usageValue.IsEmpty() && usageValue->IsUint32()) {
|
|
248
|
+
config.usage = usageValue->Uint32Value(context).ToChecked();
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
|
|
252
|
+
v8::Local<v8::Value> presentModeValue;
|
|
253
|
+
|
|
254
|
+
if (options->Get(context, ConvertToV8String(isolate, "presentMode")).ToLocal(
|
|
255
|
+
&presentModeValue)) {
|
|
256
|
+
if (presentModeValue->IsString()) {
|
|
257
|
+
auto presentMode = ConvertFromV8String(isolate, presentModeValue);
|
|
258
|
+
if (strcmp(presentMode.c_str(), "autoVsync") == 0) {
|
|
259
|
+
config.presentMode = CanvasGPUPresentMode::CanvasGPUPresentModeAutoVsync;
|
|
260
|
+
} else if (strcmp(presentMode.c_str(), "autoNoVsync") == 0) {
|
|
261
|
+
config.presentMode = CanvasGPUPresentMode::CanvasGPUPresentModeAutoNoVsync;
|
|
262
|
+
} else if (strcmp(presentMode.c_str(), "fifo") == 0) {
|
|
263
|
+
config.presentMode = CanvasGPUPresentMode::CanvasGPUPresentModeFifo;
|
|
264
|
+
} else if (strcmp(presentMode.c_str(), "fifoRelaxed") == 0) {
|
|
265
|
+
config.presentMode = CanvasGPUPresentMode::CanvasGPUPresentModeFifoRelaxed;
|
|
266
|
+
} else if (strcmp(presentMode.c_str(), "immediate") == 0) {
|
|
267
|
+
config.presentMode = CanvasGPUPresentMode::CanvasGPUPresentModeImmediate;
|
|
268
|
+
} else if (strcmp(presentMode.c_str(), "mailbox") == 0) {
|
|
269
|
+
config.presentMode = CanvasGPUPresentMode::CanvasGPUPresentModeMailbox;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
} else if (presentModeValue->IsInt32()) {
|
|
273
|
+
config.presentMode = (CanvasGPUPresentMode) presentModeValue->Int32Value(
|
|
274
|
+
context).ToChecked();
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
|
|
279
|
+
v8::Local<v8::Value> alphaModeValue;
|
|
280
|
+
|
|
281
|
+
if (options->Get(context, ConvertToV8String(isolate, "alphaMode")).ToLocal(
|
|
282
|
+
&alphaModeValue)) {
|
|
283
|
+
if (alphaModeValue->IsString()) {
|
|
284
|
+
auto alphaMode = ConvertFromV8String(isolate, alphaModeValue);
|
|
285
|
+
if (strcmp(alphaMode.c_str(), "premultiplied") == 0) {
|
|
286
|
+
config.alphaMode = CanvasGPUSurfaceAlphaMode::CanvasGPUSurfaceAlphaModePreMultiplied;
|
|
287
|
+
} else if (strcmp(alphaMode.c_str(), "opaque") == 0) {
|
|
288
|
+
config.alphaMode = CanvasGPUSurfaceAlphaMode::CanvasGPUSurfaceAlphaModeOpaque;
|
|
289
|
+
} else if (strcmp(alphaMode.c_str(), "postmultiplied") == 0) {
|
|
290
|
+
config.alphaMode = CanvasGPUSurfaceAlphaMode::CanvasGPUSurfaceAlphaModePostMultiplied;
|
|
291
|
+
} else if (strcmp(alphaMode.c_str(), "inherit") == 0) {
|
|
292
|
+
config.alphaMode = CanvasGPUSurfaceAlphaMode::CanvasGPUSurfaceAlphaModeInherit;
|
|
293
|
+
} else if (strcmp(alphaMode.c_str(), "auto") == 0) {
|
|
294
|
+
config.alphaMode = CanvasGPUSurfaceAlphaMode::CanvasGPUSurfaceAlphaModeAuto;
|
|
295
|
+
}
|
|
296
|
+
} else if (alphaModeValue->IsInt32()) {
|
|
297
|
+
config.alphaMode = (CanvasGPUSurfaceAlphaMode) alphaModeValue->Int32Value(
|
|
298
|
+
context).ToChecked();
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
|
|
304
|
+
v8::Local<v8::Value> sizeValue;
|
|
305
|
+
options->Get(context, ConvertToV8String(isolate, "size")).ToLocal(
|
|
306
|
+
&sizeValue);
|
|
307
|
+
|
|
308
|
+
CanvasExtent3d size = ParseExtent3d(isolate, sizeValue);
|
|
309
|
+
|
|
310
|
+
if (size.width > 0) {
|
|
311
|
+
config.size = &size;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
canvas_native_webgpu_context_configure(ptr->GetContext(), device->GetGPUDevice(), &config);
|
|
315
|
+
|
|
206
316
|
}
|
|
207
317
|
|
|
208
318
|
void GPUCanvasContextImpl::UnConfigure(const v8::FunctionCallbackInfo<v8::Value> &args) {
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
319
|
+
GPUCanvasContextImpl *ptr = GetPointer(args.This());
|
|
320
|
+
if (ptr == nullptr) {
|
|
321
|
+
return;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
canvas_native_webgpu_context_unconfigure(ptr->GetContext());
|
|
325
|
+
|
|
216
326
|
}
|
|
217
327
|
|
|
218
328
|
void GPUCanvasContextImpl::__ToDataURL(const v8::FunctionCallbackInfo<v8::Value> &args) {
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
type.c_str(),
|
|
246
|
-
quality);
|
|
247
|
-
}else {
|
|
248
|
-
data = canvas_native_webgpu_to_data_url(
|
|
249
|
-
ptr->GetContext(), device->GetGPUDevice(), type.c_str(),
|
|
250
|
-
quality);
|
|
251
|
-
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
if(data == nullptr){
|
|
255
|
-
args.GetReturnValue().Set(ConvertToV8String(isolate, "data:,"));
|
|
256
|
-
return;
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
auto value = new OneByteStringResource((char *) data);
|
|
260
|
-
auto ret = v8::String::NewExternalOneByte(isolate, value);
|
|
261
|
-
args.GetReturnValue().Set(ret.ToLocalChecked());
|
|
262
|
-
} else {
|
|
263
|
-
args.GetReturnValue().Set(ConvertToV8String(isolate, "data:,"));
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
|
|
329
|
+
GPUCanvasContextImpl *ptr = GetPointer(args.This());
|
|
330
|
+
|
|
331
|
+
auto isolate = args.GetIsolate();
|
|
332
|
+
auto context = isolate->GetCurrentContext();
|
|
333
|
+
|
|
334
|
+
|
|
335
|
+
std::string type("image/png");
|
|
336
|
+
float quality = 0.92;
|
|
337
|
+
if (args[0]->IsString()) {
|
|
338
|
+
type = ConvertFromV8String(isolate, args[0]);
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
if (args[1]->IsNumber()) {
|
|
342
|
+
quality = (float) args[1]->NumberValue(context).ToChecked();
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
|
|
346
|
+
auto data = canvas_native_webgpu_to_data_url_with_fallback(
|
|
347
|
+
ptr->GetContext(), type.c_str(),
|
|
348
|
+
quality);
|
|
349
|
+
|
|
350
|
+
|
|
351
|
+
auto value = new OneByteStringResource((char *) data);
|
|
352
|
+
auto ret = v8::String::NewExternalOneByte(isolate, value);
|
|
353
|
+
args.GetReturnValue().Set(ret.ToLocalChecked());
|
|
354
|
+
|
|
267
355
|
}
|
|
268
356
|
|
|
269
357
|
void GPUCanvasContextImpl::GetCurrentTexture(const v8::FunctionCallbackInfo<v8::Value> &args) {
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
358
|
+
GPUCanvasContextImpl *ptr = GetPointer(args.This());
|
|
359
|
+
auto isolate = args.GetIsolate();
|
|
360
|
+
if (ptr == nullptr) {
|
|
361
|
+
args.GetReturnValue().SetUndefined();
|
|
362
|
+
return;
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
auto ctx = ptr->GetContext();
|
|
366
|
+
|
|
367
|
+
auto texture = canvas_native_webgpu_context_get_current_texture(ctx);
|
|
368
|
+
|
|
369
|
+
if (texture != nullptr) {
|
|
370
|
+
auto status = canvas_native_webgpu_texture_get_status(texture);
|
|
371
|
+
if (status == SurfaceGetCurrentTextureStatusSuccess) {
|
|
372
|
+
auto textureImpl = new GPUTextureImpl(texture);
|
|
373
|
+
auto ret = GPUTextureImpl::NewInstance(isolate, textureImpl);
|
|
374
|
+
args.GetReturnValue().Set(ret);
|
|
375
|
+
} else {
|
|
376
|
+
canvas_native_webgpu_texture_release(texture);
|
|
377
|
+
args.GetReturnValue().SetNull();
|
|
378
|
+
}
|
|
379
|
+
return;
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
args.GetReturnValue().SetUndefined();
|
|
295
383
|
}
|
|
296
384
|
|
|
297
385
|
void GPUCanvasContextImpl::PresentSurface(const v8::FunctionCallbackInfo<v8::Value> &args) {
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
386
|
+
GPUCanvasContextImpl *ptr = GetPointer(args.This());
|
|
387
|
+
if (ptr == nullptr) {
|
|
388
|
+
return;
|
|
389
|
+
}
|
|
390
|
+
auto context = ptr->GetContext();
|
|
391
|
+
if(canvas_native_webgpu_context_has_current_texture(context) && !canvas_native_webgpu_context_has_surface_presented(context)){
|
|
392
|
+
auto texture = canvas_native_webgpu_context_get_current_texture(context);
|
|
393
|
+
if(texture != nullptr){
|
|
394
|
+
canvas_native_webgpu_context_present_surface(context, texture);
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
|
|
312
399
|
}
|
|
313
400
|
|
|
314
401
|
void GPUCanvasContextImpl::GetCapabilities(const v8::FunctionCallbackInfo<v8::Value> &args) {
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
402
|
+
GPUCanvasContextImpl *ptr = GetPointer(args.This());
|
|
403
|
+
if (ptr == nullptr) {
|
|
404
|
+
return;
|
|
405
|
+
}
|
|
406
|
+
auto isolate = args.GetIsolate();
|
|
407
|
+
auto context = isolate->GetCurrentContext();
|
|
408
|
+
auto adapterVal = args[0];
|
|
409
|
+
auto ret = v8::Object::New(isolate);
|
|
410
|
+
|
|
411
|
+
if (!adapterVal.IsEmpty() && adapterVal->IsObject()) {
|
|
412
|
+
auto adapter = GPUAdapterImpl::GetPointer(adapterVal.As<v8::Object>());
|
|
413
|
+
auto ctx = ptr->GetContext();
|
|
414
|
+
|
|
415
|
+
if (adapter != nullptr) {
|
|
416
|
+
auto cap = canvas_native_webgpu_context_get_capabilities(ctx, adapter->GetGPUAdapter());
|
|
417
|
+
auto formats_len = canvas_native_string_buffer_get_length(cap->formats);
|
|
418
|
+
auto formats = v8::Array::New(isolate, (int) formats_len);
|
|
419
|
+
for (int i = 0; i < formats_len; i++) {
|
|
420
|
+
auto format = canvas_native_string_buffer_get_value_at(cap->formats, i);
|
|
421
|
+
formats->Set(context, i, ConvertToV8String(isolate, format)).FromJust();
|
|
422
|
+
canvas_native_string_destroy(format);
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
auto present_modes_len = canvas_native_string_buffer_get_length(cap->present_modes);
|
|
426
|
+
auto present_modes = v8::Array::New(isolate, (int) present_modes_len);
|
|
427
|
+
|
|
428
|
+
|
|
429
|
+
for (int i = 0; i < present_modes_len; i++) {
|
|
430
|
+
auto mode = canvas_native_string_buffer_get_value_at(cap->present_modes, i);
|
|
431
|
+
present_modes->Set(context, i, ConvertToV8String(isolate, mode)).FromJust();
|
|
432
|
+
canvas_native_string_destroy(mode);
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
auto alpha_modes_len = canvas_native_string_buffer_get_length(cap->alpha_modes);
|
|
436
|
+
auto alpha_modes = v8::Array::New(isolate, (int) alpha_modes_len);
|
|
437
|
+
|
|
438
|
+
|
|
439
|
+
for (int i = 0; i < alpha_modes_len; i++) {
|
|
440
|
+
auto mode = canvas_native_string_buffer_get_value_at(cap->alpha_modes, i);
|
|
441
|
+
alpha_modes->Set(context, i, ConvertToV8String(isolate, mode)).FromJust();
|
|
442
|
+
canvas_native_string_destroy(mode);
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
ret->Set(context, ConvertToV8String(isolate, "format"), formats).FromJust();
|
|
446
|
+
ret->Set(context, ConvertToV8String(isolate, "presentModes"), present_modes).FromJust();
|
|
447
|
+
ret->Set(context, ConvertToV8String(isolate, "alphaModes"), alpha_modes).FromJust();
|
|
448
|
+
ret->Set(context, ConvertToV8String(isolate, "usages"),
|
|
449
|
+
v8::Uint32::NewFromUnsigned(isolate, cap->usages)).FromJust();
|
|
450
|
+
|
|
451
|
+
canvas_native_webgpu_struct_surface_capabilities_release(cap);
|
|
452
|
+
|
|
453
|
+
args.GetReturnValue().Set(ret);
|
|
454
|
+
return;
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
ret->Set(context, ConvertToV8String(isolate, "format"), v8::Array::New(isolate)).FromJust();
|
|
461
|
+
ret->Set(context, ConvertToV8String(isolate, "presentModes"),
|
|
462
|
+
v8::Array::New(isolate)).FromJust();
|
|
463
|
+
ret->Set(context, ConvertToV8String(isolate, "alphaModes"), v8::Array::New(isolate)).FromJust();
|
|
464
|
+
ret->Set(context, ConvertToV8String(isolate, "usages"), v8::Uint32::New(isolate, 0)).FromJust();
|
|
465
|
+
args.GetReturnValue().Set(ret);
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
|
|
469
|
+
void GPUCanvasContextImpl::Flush() {
|
|
470
|
+
auto context = this->GetContext();
|
|
471
|
+
if(canvas_native_webgpu_context_has_current_texture(context) && !canvas_native_webgpu_context_has_surface_presented(context)){
|
|
472
|
+
auto texture = canvas_native_webgpu_context_get_current_texture(context);
|
|
473
|
+
if(texture != nullptr){
|
|
474
|
+
canvas_native_webgpu_context_present_surface(context, texture);
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
void GPUCanvasContextImpl::Flush(intptr_t context) {
|
|
480
|
+
auto ctx = reinterpret_cast<GPUCanvasContextImpl *>(reinterpret_cast<intptr_t *>(context));
|
|
481
|
+
if (ctx != nullptr) {
|
|
482
|
+
ctx->Flush();
|
|
483
|
+
}
|
|
379
484
|
}
|