@nativescript/canvas 2.0.0-rc.2 → 2.0.0-rc.20
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
|
@@ -9,1066 +9,1227 @@
|
|
|
9
9
|
#include "Helpers.h"
|
|
10
10
|
|
|
11
11
|
struct GLOptions {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
12
|
+
int32_t version;
|
|
13
|
+
bool alpha;
|
|
14
|
+
bool antialias;
|
|
15
|
+
bool depth;
|
|
16
|
+
bool failIfMajorPerformanceCaveat;
|
|
17
|
+
int32_t powerPreference;
|
|
18
|
+
bool premultipliedAlpha;
|
|
19
|
+
bool preserveDrawingBuffer;
|
|
20
|
+
bool stencil;
|
|
21
|
+
bool desynchronized;
|
|
22
|
+
bool xrCompatible;
|
|
23
|
+
|
|
24
24
|
public:
|
|
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
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
v8::Local<v8::Value> xrCompatibleValue;
|
|
118
|
-
config->Get(context, ConvertToV8String(isolate, "xrCompatible")).ToLocal(
|
|
119
|
-
&xrCompatibleValue);
|
|
120
|
-
if (!xrCompatibleValue.IsEmpty() && xrCompatibleValue->IsBoolean()) {
|
|
121
|
-
this->xrCompatible = xrCompatibleValue->BooleanValue(isolate);
|
|
122
|
-
}
|
|
123
|
-
}
|
|
25
|
+
GLOptions() {
|
|
26
|
+
this->version = 0;
|
|
27
|
+
this->alpha = true;
|
|
28
|
+
this->antialias = true;
|
|
29
|
+
this->depth = true;
|
|
30
|
+
this->failIfMajorPerformanceCaveat = false;
|
|
31
|
+
this->powerPreference = 0;
|
|
32
|
+
this->premultipliedAlpha = true;
|
|
33
|
+
this->preserveDrawingBuffer = false;
|
|
34
|
+
this->stencil = false;
|
|
35
|
+
this->desynchronized = false;
|
|
36
|
+
this->xrCompatible = false;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
void parseGLOptions(const v8::FunctionCallbackInfo<v8::Value> &args) {
|
|
40
|
+
auto configValue = args[0];
|
|
41
|
+
|
|
42
|
+
if (!(!configValue->IsNullOrUndefined() && configValue->IsObject())) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
auto isolate = args.GetIsolate();
|
|
47
|
+
auto context = isolate->GetCurrentContext();
|
|
48
|
+
auto config = configValue.As<v8::Object>();
|
|
49
|
+
|
|
50
|
+
v8::Local<v8::Value> versionValue;
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
if (config->Get(context, ConvertToV8String(isolate, "version")).ToLocal(&versionValue) && versionValue->IsInt32()) {
|
|
54
|
+
this->version = versionValue->Int32Value(context).FromJust();
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
v8::Local<v8::Value> alphaValue;
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
if (config->Get(context, ConvertToV8String(isolate, "alpha")).ToLocal(&alphaValue) && alphaValue->IsBoolean()) {
|
|
61
|
+
this->alpha = alphaValue->BooleanValue(isolate);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
v8::Local<v8::Value> antialiasValue;
|
|
65
|
+
if (config->Get(context, ConvertToV8String(isolate, "antialias")).ToLocal(
|
|
66
|
+
&antialiasValue) && antialiasValue->IsBoolean()) {
|
|
67
|
+
this->antialias = antialiasValue->BooleanValue(isolate);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
v8::Local<v8::Value> failIfMajorPerformanceCaveatValue;
|
|
71
|
+
if (config->Get(context, ConvertToV8String(isolate, "failIfMajorPerformanceCaveat")).ToLocal(
|
|
72
|
+
&failIfMajorPerformanceCaveatValue) &&
|
|
73
|
+
failIfMajorPerformanceCaveatValue->IsBoolean()) {
|
|
74
|
+
this->failIfMajorPerformanceCaveat = failIfMajorPerformanceCaveatValue->BooleanValue(
|
|
75
|
+
isolate);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
v8::Local<v8::Value> powerPreferenceValue;
|
|
79
|
+
if (!config->Get(context, ConvertToV8String(isolate, "powerPreference")).ToLocal(
|
|
80
|
+
&powerPreferenceValue) && powerPreferenceValue->IsInt32()) {
|
|
81
|
+
this->powerPreference = powerPreferenceValue->Int32Value(context).FromJust();
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
v8::Local<v8::Value> premultipliedAlphaValue;
|
|
85
|
+
if (config->Get(context,
|
|
86
|
+
ConvertToV8String(isolate, "premultipliedAlpha")).ToLocal(
|
|
87
|
+
&premultipliedAlphaValue) && premultipliedAlphaValue->IsBoolean()) {
|
|
88
|
+
this->premultipliedAlpha = premultipliedAlphaValue->BooleanValue(isolate);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
v8::Local<v8::Value> preserveDrawingBufferValue;
|
|
92
|
+
if ( config->Get(context,
|
|
93
|
+
ConvertToV8String(isolate, "preserveDrawingBuffer")).ToLocal(
|
|
94
|
+
&preserveDrawingBufferValue) && preserveDrawingBufferValue->IsBoolean()) {
|
|
95
|
+
this->preserveDrawingBuffer = preserveDrawingBufferValue->BooleanValue(isolate);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
v8::Local<v8::Value> stencilValue;
|
|
99
|
+
if ( config->Get(context, ConvertToV8String(isolate, "stencil")).ToLocal(&stencilValue) && stencilValue->IsBoolean()) {
|
|
100
|
+
this->stencil = stencilValue->BooleanValue(isolate);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
v8::Local<v8::Value> desynchronizedValue;
|
|
104
|
+
if (config->Get(context, ConvertToV8String(isolate, "desynchronized")).ToLocal(
|
|
105
|
+
&desynchronizedValue) && desynchronizedValue->IsBoolean()) {
|
|
106
|
+
this->desynchronized = desynchronizedValue->BooleanValue(isolate);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
v8::Local<v8::Value> xrCompatibleValue;
|
|
110
|
+
if (config->Get(context, ConvertToV8String(isolate, "xrCompatible")).ToLocal(
|
|
111
|
+
&xrCompatibleValue) && xrCompatibleValue->IsBoolean()) {
|
|
112
|
+
this->xrCompatible = xrCompatibleValue->BooleanValue(isolate);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
124
115
|
};
|
|
125
116
|
|
|
126
117
|
void CanvasJSIModule::install(v8::Isolate *isolate) {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
118
|
+
|
|
119
|
+
auto context = isolate->GetCurrentContext();
|
|
120
|
+
auto global = context->Global();
|
|
121
|
+
|
|
122
|
+
if (!global->
|
|
123
|
+
HasOwnProperty(context, ConvertToV8String(isolate, "CanvasJSIModule")).FromMaybe(
|
|
124
|
+
false)) {
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
v8::Locker locker(isolate);
|
|
128
|
+
v8::Isolate::Scope isolate_scope(isolate);
|
|
129
|
+
v8::HandleScope handle_scope(isolate);
|
|
130
|
+
|
|
131
|
+
auto v8Global = context->Global();
|
|
132
|
+
|
|
133
|
+
auto canvasMod = v8::Object::New(isolate);
|
|
134
|
+
TextDecoderImpl::Init(canvasMod, isolate);
|
|
135
|
+
TextEncoderImpl::Init(canvasMod, isolate);
|
|
136
|
+
Path2D::Init(canvasMod, isolate);
|
|
137
|
+
ImageDataImpl::Init(canvasMod, isolate);
|
|
138
|
+
ImageAssetImpl::Init(canvasMod, isolate);
|
|
139
|
+
ImageBitmapImpl::Init(canvasMod, isolate);
|
|
140
|
+
CanvasGradient::Init(canvasMod, isolate);
|
|
141
|
+
CanvasPattern::Init(canvasMod, isolate);
|
|
142
|
+
MatrixImpl::Init(canvasMod, isolate);
|
|
143
|
+
TextMetricsImpl::Init(canvasMod, isolate);
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
GPUImpl::Init(canvasMod, isolate);
|
|
147
|
+
GPUSupportedLimitsImpl::Init(canvasMod, isolate);
|
|
148
|
+
GPUDeviceImpl::Init(canvasMod, isolate);
|
|
149
|
+
GPUQueueImpl::Init(canvasMod, isolate);
|
|
150
|
+
|
|
151
|
+
v8Global->Set(context, ConvertToV8String(isolate, "CanvasModule"), canvasMod).FromJust();
|
|
152
|
+
canvasMod->Set(context, ConvertToV8String(isolate, "create2DContext"),
|
|
153
|
+
v8::FunctionTemplate::New(isolate, &Create2DContext)->GetFunction(
|
|
154
|
+
context).ToLocalChecked()).FromJust();
|
|
155
|
+
canvasMod->Set(context, ConvertToV8String(isolate, "createImageBitmap"),
|
|
156
|
+
v8::FunctionTemplate::New(isolate, &CreateImageBitmap)->GetFunction(
|
|
157
|
+
context).ToLocalChecked()).FromJust();
|
|
158
|
+
canvasMod->Set(context, ConvertToV8String(isolate, "create2DContextWithPointer"),
|
|
159
|
+
v8::FunctionTemplate::New(isolate, &Create2DContextWithPointer)->GetFunction(
|
|
160
|
+
context).ToLocalChecked()).FromJust();
|
|
161
|
+
|
|
162
|
+
canvasMod->Set(context, ConvertToV8String(isolate, "createWebGPUContextWithPointer"),
|
|
163
|
+
v8::FunctionTemplate::New(isolate,
|
|
164
|
+
&CreateWebGPUContextWithPointer)->GetFunction(
|
|
165
|
+
context).ToLocalChecked()).FromJust();
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
canvasMod->Set(context, ConvertToV8String(isolate, "readFile"),
|
|
169
|
+
v8::FunctionTemplate::New(isolate, &ReadFile)->GetFunction(
|
|
170
|
+
context).ToLocalChecked()).FromJust();
|
|
171
|
+
|
|
172
|
+
canvasMod->Set(context, ConvertToV8String(isolate, "getMime"),
|
|
173
|
+
v8::FunctionTemplate::New(isolate, &GetMime)->GetFunction(
|
|
174
|
+
context).ToLocalChecked()).FromJust();
|
|
175
|
+
|
|
176
|
+
canvasMod->Set(context, ConvertToV8String(isolate, "createWebGLContext"),
|
|
177
|
+
v8::FunctionTemplate::New(isolate, &CreateWebGLContext)->GetFunction(
|
|
178
|
+
context).ToLocalChecked()).FromJust();
|
|
179
|
+
|
|
180
|
+
canvasMod->Set(context, ConvertToV8String(isolate, "createWebGL2Context"),
|
|
181
|
+
v8::FunctionTemplate::New(isolate, &CreateWebGL2Context)->GetFunction(
|
|
182
|
+
context).ToLocalChecked()).FromJust();
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
canvasMod->Set(context, ConvertToV8String(isolate, "__addFontFamily"),
|
|
186
|
+
v8::FunctionTemplate::New(isolate, &AddFontFamily)->GetFunction(
|
|
187
|
+
context).ToLocalChecked()).FromJust();
|
|
188
|
+
|
|
189
|
+
canvasMod->Set(context, ConvertToV8String(isolate, "__addFontData"),
|
|
190
|
+
v8::FunctionTemplate::New(isolate, &AddFontData)->GetFunction(
|
|
191
|
+
context).ToLocalChecked()).FromJust();
|
|
192
|
+
|
|
193
|
+
canvasMod->Set(context, ConvertToV8String(isolate, "__base64Encode"),
|
|
194
|
+
v8::FunctionTemplate::New(isolate, &Base64Encode)->GetFunction(
|
|
195
|
+
context).ToLocalChecked()).FromJust();
|
|
196
|
+
|
|
197
|
+
canvasMod->Set(context, ConvertToV8String(isolate, "__base64Decode"),
|
|
198
|
+
v8::FunctionTemplate::New(isolate, &Base64Decode)->GetFunction(
|
|
199
|
+
context).ToLocalChecked()).FromJust();
|
|
200
|
+
|
|
201
|
+
canvasMod->Set(context, ConvertToV8String(isolate, "__base64DecodeAsync"),
|
|
202
|
+
v8::FunctionTemplate::New(isolate, &Base64DecodeAsync)->GetFunction(
|
|
203
|
+
context).ToLocalChecked()).FromJust();
|
|
204
|
+
|
|
205
|
+
global->Set(context,
|
|
206
|
+
ConvertToV8String(isolate, "CanvasModule"), canvasMod).FromJust();
|
|
207
|
+
|
|
208
|
+
}
|
|
206
209
|
}
|
|
207
210
|
|
|
208
211
|
void CanvasJSIModule::AddFontFamily(const v8::FunctionCallbackInfo<v8::Value> &args) {
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
212
|
+
auto isolate = args.GetIsolate();
|
|
213
|
+
auto context = isolate->GetCurrentContext();
|
|
214
|
+
auto aliasValue = args[0];
|
|
215
|
+
auto familyValue = args[1];
|
|
216
|
+
|
|
217
|
+
// todo improve
|
|
218
|
+
if (familyValue->IsArray()) {
|
|
219
|
+
auto family = familyValue.As<v8::Array>();
|
|
220
|
+
auto len = family->Length();
|
|
221
|
+
std::vector<std::string> buf;
|
|
222
|
+
std::vector<const char *> buffer;
|
|
223
|
+
buf.reserve(len);
|
|
224
|
+
|
|
225
|
+
for (uint32_t i = 0; i < len; i++) {
|
|
226
|
+
buf.emplace_back(
|
|
227
|
+
ConvertFromV8String(isolate, family->Get(context, i).ToLocalChecked()));
|
|
228
|
+
buffer.emplace_back(buf[0].c_str());
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
if (aliasValue->IsString()) {
|
|
232
|
+
auto alias = ConvertFromV8String(isolate, aliasValue);
|
|
233
|
+
canvas_native_font_add_family(alias.c_str(), buffer.data(), buffer.size());
|
|
234
|
+
} else {
|
|
235
|
+
canvas_native_font_add_family(nullptr, buffer.data(), buffer.size());
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
}
|
|
239
|
+
|
|
237
240
|
}
|
|
238
241
|
|
|
239
242
|
void CanvasJSIModule::AddFontData(const v8::FunctionCallbackInfo<v8::Value> &args) {
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
243
|
+
auto isolate = args.GetIsolate();
|
|
244
|
+
auto aliasValue = args[0];
|
|
245
|
+
auto dataValue = args[1];
|
|
246
|
+
|
|
247
|
+
// todo improve
|
|
248
|
+
if (dataValue->IsArrayBuffer()) {
|
|
249
|
+
|
|
250
|
+
if (aliasValue->IsString()) {
|
|
251
|
+
auto alias = ConvertFromV8String(isolate, aliasValue);
|
|
252
|
+
auto data = dataValue.As<v8::ArrayBuffer>();
|
|
253
|
+
auto store = data->GetBackingStore();
|
|
254
|
+
canvas_native_font_add_family_with_bytes(alias.c_str(), (uint8_t *) store->Data(),
|
|
255
|
+
store->ByteLength());
|
|
256
|
+
} else {
|
|
257
|
+
auto data = dataValue.As<v8::ArrayBuffer>();
|
|
258
|
+
auto store = data->GetBackingStore();
|
|
259
|
+
canvas_native_font_add_family_with_bytes(nullptr, (uint8_t *) store->Data(),
|
|
260
|
+
store->ByteLength());
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
} else if (dataValue->IsTypedArray()) {
|
|
264
|
+
|
|
265
|
+
if (aliasValue->IsString()) {
|
|
266
|
+
auto alias = ConvertFromV8String(isolate, aliasValue);
|
|
267
|
+
auto data = dataValue.As<v8::TypedArray>();
|
|
268
|
+
auto buffer = data->Buffer();
|
|
269
|
+
auto store = buffer->GetBackingStore();
|
|
270
|
+
canvas_native_font_add_family_with_bytes(alias.c_str(), (uint8_t *) store->Data(),
|
|
271
|
+
store->ByteLength());
|
|
272
|
+
} else {
|
|
273
|
+
auto data = dataValue.As<v8::TypedArray>();
|
|
274
|
+
auto buffer = data->Buffer();
|
|
275
|
+
auto store = buffer->GetBackingStore();
|
|
276
|
+
canvas_native_font_add_family_with_bytes(nullptr, (uint8_t *) store->Data(),
|
|
277
|
+
store->ByteLength());
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
}
|
|
262
283
|
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
284
|
+
void CanvasJSIModule::Base64Encode(const v8::FunctionCallbackInfo<v8::Value> &args) {
|
|
285
|
+
auto isolate = args.GetIsolate();
|
|
286
|
+
auto dataValue = args[0];
|
|
287
|
+
|
|
288
|
+
auto data = ConvertFromV8StringView(isolate, dataValue);
|
|
289
|
+
|
|
290
|
+
if (data.empty()) {
|
|
291
|
+
args.GetReturnValue().SetEmptyString();
|
|
292
|
+
} else {
|
|
293
|
+
auto encoded = canvas_native_helper_base64_encode((const uint8_t *) data.data(),
|
|
294
|
+
data.size());
|
|
295
|
+
if (encoded == nullptr) {
|
|
296
|
+
args.GetReturnValue().SetEmptyString();
|
|
297
|
+
return;
|
|
298
|
+
}
|
|
299
|
+
auto returnValue = new OneByteStringResource(encoded);
|
|
300
|
+
auto ret = v8::String::NewExternalOneByte(isolate, returnValue);
|
|
301
|
+
v8::Local<v8::Value> value;
|
|
302
|
+
if (ret.ToLocal(&value)) {
|
|
303
|
+
args.GetReturnValue().Set(value);
|
|
304
|
+
} else {
|
|
305
|
+
args.GetReturnValue().SetEmptyString();
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
}
|
|
309
|
+
}
|
|
277
310
|
|
|
278
|
-
|
|
311
|
+
void CanvasJSIModule::Base64Decode(const v8::FunctionCallbackInfo<v8::Value> &args) {
|
|
312
|
+
auto isolate = args.GetIsolate();
|
|
313
|
+
auto dataValue = args[0];
|
|
314
|
+
|
|
315
|
+
auto data = ConvertFromV8StringView(isolate, dataValue);
|
|
316
|
+
|
|
317
|
+
if (data.empty()) {
|
|
318
|
+
args.GetReturnValue().SetEmptyString();
|
|
319
|
+
} else {
|
|
320
|
+
auto decoded = canvas_native_helper_base64_decode((const uint8_t *) data.data(),
|
|
321
|
+
data.size());
|
|
322
|
+
if (decoded == nullptr) {
|
|
323
|
+
args.GetReturnValue().SetEmptyString();
|
|
324
|
+
return;
|
|
325
|
+
}
|
|
326
|
+
auto returnValue = new OneByteStringResource(decoded);
|
|
327
|
+
auto ret = v8::String::NewExternalOneByte(isolate, returnValue);
|
|
328
|
+
v8::Local<v8::Value> value;
|
|
329
|
+
auto decoded_clone = canvas_native_u8_buffer_clone(decoded);
|
|
330
|
+
auto buffer_ptr = canvas_native_u8_buffer_get_bytes(decoded_clone);
|
|
331
|
+
auto buffer_len = canvas_native_u8_buffer_get_length(decoded_clone);
|
|
332
|
+
auto buffer = v8::ArrayBuffer::NewBackingStore((void *) buffer_ptr, buffer_len,
|
|
333
|
+
[](void *data,
|
|
334
|
+
size_t length,
|
|
335
|
+
void *deleter_data) {
|
|
336
|
+
if (deleter_data !=
|
|
337
|
+
nullptr) {
|
|
338
|
+
canvas_native_u8_buffer_release(
|
|
339
|
+
(U8Buffer *) deleter_data);
|
|
340
|
+
}
|
|
341
|
+
},
|
|
342
|
+
(void *) decoded_clone);
|
|
343
|
+
|
|
344
|
+
if (ret.ToLocal(&value)) {
|
|
345
|
+
v8::Local<v8::Value> retArgs[2] = {value,
|
|
346
|
+
v8::ArrayBuffer::New(isolate, std::move(buffer))};
|
|
347
|
+
args.GetReturnValue().Set(v8::Array::New(isolate, retArgs, 2));
|
|
348
|
+
} else {
|
|
349
|
+
args.GetReturnValue().Set(v8::Array::New(isolate));
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
}
|
|
353
|
+
}
|
|
279
354
|
|
|
355
|
+
void CanvasJSIModule::Base64DecodeAsync(const v8::FunctionCallbackInfo<v8::Value> &args) {
|
|
356
|
+
auto isolate = args.GetIsolate();
|
|
357
|
+
auto dataValue = args[0];
|
|
358
|
+
|
|
359
|
+
auto resolver = v8::Promise::Resolver::New(isolate->GetCurrentContext()).ToLocalChecked();
|
|
360
|
+
args.GetReturnValue().Set(resolver->GetPromise());
|
|
361
|
+
|
|
362
|
+
v8::String::Utf8Value utf8(isolate, dataValue);
|
|
363
|
+
std::string data(*utf8);
|
|
364
|
+
|
|
365
|
+
auto callback = new PromiseCallback{
|
|
366
|
+
isolate,
|
|
367
|
+
resolver,
|
|
368
|
+
[](bool done, void *data) {
|
|
369
|
+
auto async_data = static_cast<PromiseCallback *>(data);
|
|
370
|
+
auto func = async_data->inner_;
|
|
371
|
+
if (func != nullptr && func->isolate_ != nullptr) {
|
|
372
|
+
v8::Isolate *isolate = func->isolate_;
|
|
373
|
+
v8::Locker locker(isolate);
|
|
374
|
+
v8::Isolate::Scope isolate_scope(
|
|
375
|
+
isolate);
|
|
376
|
+
v8::HandleScope handle_scope(
|
|
377
|
+
isolate);
|
|
378
|
+
v8::Local<v8::Promise::Resolver> callback = func->callback_.Get(
|
|
379
|
+
isolate);
|
|
380
|
+
v8::Local<v8::Context> context = callback->GetCreationContextChecked();
|
|
381
|
+
v8::Context::Scope context_scope(
|
|
382
|
+
context);
|
|
383
|
+
|
|
384
|
+
auto funcData = func->getData();
|
|
385
|
+
|
|
386
|
+
if (funcData == nullptr) {
|
|
387
|
+
callback->Resolve(context, v8::String::Empty(isolate));
|
|
388
|
+
} else {
|
|
389
|
+
auto decoded = static_cast<U8Buffer *>(funcData);
|
|
390
|
+
|
|
391
|
+
auto returnValue = new OneByteStringResource(decoded);
|
|
392
|
+
auto ret = v8::String::NewExternalOneByte(isolate, returnValue);
|
|
393
|
+
v8::Local<v8::Value> value;
|
|
394
|
+
auto decoded_clone = canvas_native_u8_buffer_clone(decoded);
|
|
395
|
+
|
|
396
|
+
func->setData(nullptr);
|
|
397
|
+
|
|
398
|
+
auto buffer_ptr = canvas_native_u8_buffer_get_bytes(decoded_clone);
|
|
399
|
+
auto buffer_len = canvas_native_u8_buffer_get_length(decoded_clone);
|
|
400
|
+
auto buffer = v8::ArrayBuffer::NewBackingStore((void *) buffer_ptr,
|
|
401
|
+
buffer_len,
|
|
402
|
+
[](void *data,
|
|
403
|
+
size_t length,
|
|
404
|
+
void *deleter_data) {
|
|
405
|
+
if (deleter_data !=
|
|
406
|
+
nullptr) {
|
|
407
|
+
canvas_native_u8_buffer_release(
|
|
408
|
+
(U8Buffer *) deleter_data);
|
|
409
|
+
}
|
|
410
|
+
},
|
|
411
|
+
(void *) decoded_clone);
|
|
412
|
+
|
|
413
|
+
if (ret.ToLocal(&value)) {
|
|
414
|
+
v8::Local<v8::Value> retArgs[2] = {value,
|
|
415
|
+
v8::ArrayBuffer::New(isolate,
|
|
416
|
+
std::move(
|
|
417
|
+
buffer))};
|
|
418
|
+
callback->Resolve(context,
|
|
419
|
+
v8::Array::New(isolate, retArgs, 2)).IsJust();
|
|
420
|
+
} else {
|
|
421
|
+
callback->Resolve(context, v8::Array::New(isolate)).IsJust();
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
delete static_cast<PromiseCallback *>(data);
|
|
427
|
+
}
|
|
428
|
+
};
|
|
429
|
+
callback->prepare();
|
|
430
|
+
|
|
431
|
+
std::thread thread(
|
|
432
|
+
[callback](std::string data) {
|
|
433
|
+
if (callback->inner_ != nullptr) {
|
|
434
|
+
auto decoded = canvas_native_helper_base64_decode((const uint8_t *) data.data(),
|
|
435
|
+
data.size());
|
|
436
|
+
callback->inner_->setData(decoded);
|
|
437
|
+
callback->inner_->execute(true, callback);
|
|
438
|
+
}
|
|
439
|
+
}, std::move(data));
|
|
440
|
+
thread.detach();
|
|
441
|
+
|
|
280
442
|
}
|
|
281
443
|
|
|
282
444
|
void CanvasJSIModule::Create2DContext(const v8::FunctionCallbackInfo<v8::Value> &args) {
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
args.GetReturnValue().Set(ret);
|
|
445
|
+
auto isolate = args.GetIsolate();
|
|
446
|
+
auto ptr = args[0].As<v8::BigInt>()->Int64Value();
|
|
447
|
+
|
|
448
|
+
auto context_2d = static_cast<CanvasRenderingContext2D *>((void *) ptr);
|
|
449
|
+
|
|
450
|
+
auto ret = CanvasRenderingContext2DImpl::NewInstance(isolate, new CanvasRenderingContext2DImpl(
|
|
451
|
+
context_2d));
|
|
452
|
+
|
|
453
|
+
args.GetReturnValue().Set(ret);
|
|
293
454
|
}
|
|
294
455
|
|
|
295
456
|
|
|
296
457
|
struct Rect {
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
458
|
+
float x;
|
|
459
|
+
float y;
|
|
460
|
+
float width;
|
|
461
|
+
float height;
|
|
301
462
|
};
|
|
302
463
|
|
|
303
464
|
struct ImageBitmapData {
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
465
|
+
char *error_;
|
|
466
|
+
const ImageAsset *asset_;
|
|
467
|
+
bool done_;
|
|
468
|
+
v8::Isolate *isolate_;
|
|
469
|
+
std::shared_ptr<v8::Persistent<v8::ArrayBufferView>> data_;
|
|
470
|
+
|
|
471
|
+
~ImageBitmapData() {
|
|
472
|
+
if (error_ != nullptr) {
|
|
473
|
+
canvas_native_string_destroy(error_);
|
|
474
|
+
error_ = nullptr;
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
data_->Reset();
|
|
478
|
+
}
|
|
318
479
|
};
|
|
319
480
|
|
|
320
481
|
|
|
321
482
|
void CanvasJSIModule::CreateImageBitmap(const v8::FunctionCallbackInfo<v8::Value> &args) {
|
|
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
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
483
|
+
auto count = args.Length();
|
|
484
|
+
auto isolate = args.GetIsolate();
|
|
485
|
+
auto context = isolate->GetCurrentContext();
|
|
486
|
+
|
|
487
|
+
auto image = args[0];
|
|
488
|
+
auto sx_or_options = args[1];
|
|
489
|
+
auto sy = args[2];
|
|
490
|
+
auto sw = args[3];
|
|
491
|
+
auto sh = args[4];
|
|
492
|
+
|
|
493
|
+
auto len = count - 1;
|
|
494
|
+
auto cb = args[count - 1];
|
|
495
|
+
|
|
496
|
+
if ((len == 1 && !image->IsObject()) || image->IsFunction()) {
|
|
497
|
+
isolate->ThrowError("Illegal constructor");
|
|
498
|
+
return;
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
Options options;
|
|
502
|
+
|
|
503
|
+
if (len == 0) {
|
|
504
|
+
isolate->ThrowError("Illegal constructor");
|
|
505
|
+
return;
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
if (!cb->IsObject() && !cb->IsFunction()) {
|
|
509
|
+
isolate->ThrowError("Illegal constructor");
|
|
510
|
+
return;
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
|
|
514
|
+
if (image->IsNullOrUndefined()) {
|
|
515
|
+
v8::Local<v8::Value> ret[2] = {ConvertToV8String(isolate, "Failed to load image"),
|
|
516
|
+
v8::Null(isolate)};
|
|
517
|
+
|
|
518
|
+
cb.As<v8::Function>()->Call(context, context->Global(), 2, ret);
|
|
519
|
+
return;
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
if (len >= 4 && (sw->IsNumber() && sw->IsNumber() == 0)) {
|
|
523
|
+
|
|
524
|
+
v8::Local<v8::Value> ret[2] = {ConvertToV8String(isolate,
|
|
525
|
+
"Failed to execute 'createImageBitmap' : The crop rect width is 0"),
|
|
526
|
+
v8::Null(isolate)};
|
|
527
|
+
|
|
528
|
+
cb.As<v8::Function>()->Call(context, context->Global(), 2, ret);
|
|
529
|
+
|
|
530
|
+
return;
|
|
531
|
+
}
|
|
532
|
+
if (len >= 5 && (sh->IsNumber() && sh->IsNumber() == 0)) {
|
|
533
|
+
v8::Local<v8::Value> ret[2] = {ConvertToV8String(isolate,
|
|
534
|
+
"Failed to execute 'createImageBitmap' : The crop rect height is 0"),
|
|
535
|
+
v8::Null(isolate)};
|
|
536
|
+
|
|
537
|
+
cb.As<v8::Function>()->Call(context, context->Global(), 2, ret);
|
|
538
|
+
return;
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
if (image->IsObject()) {
|
|
542
|
+
auto imageObject = image.As<v8::Object>();
|
|
543
|
+
auto isArrayBuffer = imageObject->IsArrayBuffer();
|
|
544
|
+
auto IsArrayBufferView = imageObject->IsArrayBufferView();
|
|
545
|
+
std::optional<Rect> rect = std::nullopt;
|
|
546
|
+
|
|
547
|
+
if (isArrayBuffer || IsArrayBufferView) {
|
|
548
|
+
if ((len == 1 || len == 2) || (len == 5 || len == 6)) {
|
|
549
|
+
if (len == 2) {
|
|
550
|
+
options = ImageBitmapImpl::HandleOptions(isolate, args[1]);
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
if (len == 6) {
|
|
554
|
+
options = ImageBitmapImpl::HandleOptions(isolate, args[5]);
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
auto cbFunc = args[count - 1].As<v8::Function>();
|
|
558
|
+
|
|
559
|
+
if (isArrayBuffer) {
|
|
560
|
+
auto arrayBuffer = imageObject.As<v8::ArrayBuffer>();
|
|
561
|
+
auto size = arrayBuffer->ByteLength();
|
|
562
|
+
imageObject = v8::Uint8Array::New(arrayBuffer, 0, size);
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
auto ta = imageObject.As<v8::ArrayBufferView>();
|
|
566
|
+
|
|
567
|
+
auto image_bitmap_async_data = new ImageBitmapData();
|
|
568
|
+
image_bitmap_async_data->isolate_ = isolate;
|
|
569
|
+
image_bitmap_async_data->data_ = std::make_shared<v8::Persistent<v8::ArrayBufferView>>(
|
|
570
|
+
isolate, ta);
|
|
571
|
+
|
|
572
|
+
auto callback = new AsyncCallback(isolate, cbFunc, [](bool done, void *data) {
|
|
573
|
+
if (data == nullptr) { return; }
|
|
574
|
+
auto async_data = static_cast<AsyncCallback *>(data);
|
|
575
|
+
auto func = async_data->inner_.get();
|
|
576
|
+
if (func != nullptr && func->isolate_ != nullptr) {
|
|
577
|
+
v8::Isolate *isolate = func->isolate_;
|
|
578
|
+
v8::Locker locker(isolate);
|
|
579
|
+
v8::Isolate::Scope isolate_scope(isolate);
|
|
580
|
+
v8::HandleScope handle_scope(isolate);
|
|
581
|
+
v8::Local<v8::Function> callback = func->callback_.Get(
|
|
582
|
+
isolate);
|
|
583
|
+
v8::Local<v8::Context> context = callback->GetCreationContextChecked();
|
|
584
|
+
v8::Context::Scope context_scope(context);
|
|
585
|
+
|
|
586
|
+
if (func->data != nullptr) {
|
|
587
|
+
auto asset_data = static_cast<ImageBitmapData *>(func->data);
|
|
588
|
+
|
|
589
|
+
auto bitmap = new ImageBitmapImpl(asset_data->asset_);
|
|
590
|
+
auto external = v8::External::New(isolate, bitmap);
|
|
591
|
+
|
|
592
|
+
auto ret = ImageBitmapImpl::NewInstance(isolate, external);
|
|
593
|
+
|
|
594
|
+
v8::Local<v8::Value> args[2] = {
|
|
595
|
+
v8::Null(isolate), ret};
|
|
596
|
+
|
|
597
|
+
|
|
598
|
+
callback->Call(context, context->Global(),
|
|
599
|
+
2,
|
|
600
|
+
args); // ignore JS return value
|
|
601
|
+
|
|
602
|
+
delete asset_data;
|
|
603
|
+
|
|
604
|
+
} else {
|
|
605
|
+
v8::Local<v8::Value> args[1] = {
|
|
606
|
+
v8::Null(isolate)};
|
|
607
|
+
|
|
608
|
+
callback->Call(context, context->Global(),
|
|
609
|
+
1,
|
|
610
|
+
args); // ignore JS return value
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
}
|
|
614
|
+
delete static_cast<AsyncCallback *>(data);
|
|
615
|
+
});
|
|
616
|
+
|
|
617
|
+
callback->inner_->data = image_bitmap_async_data;
|
|
618
|
+
callback->prepare();
|
|
619
|
+
auto store = ta->Buffer()->GetBackingStore();
|
|
620
|
+
auto offset = ta->ByteOffset();
|
|
621
|
+
|
|
622
|
+
std::thread thread(
|
|
623
|
+
[callback, image_bitmap_async_data, offset, options, rect](
|
|
624
|
+
std::shared_ptr<v8::BackingStore> store) {
|
|
625
|
+
|
|
626
|
+
auto data = static_cast<uint8_t *>(store->Data()) + offset;
|
|
627
|
+
auto size = store->ByteLength();
|
|
628
|
+
|
|
629
|
+
auto asset = canvas_native_image_asset_create();
|
|
630
|
+
bool done;
|
|
631
|
+
if (rect.has_value()) {
|
|
632
|
+
|
|
633
|
+
done = canvas_native_image_bitmap_create_from_encoded_bytes_src_rect_with_output(
|
|
634
|
+
data, size,
|
|
635
|
+
rect.value().x,
|
|
636
|
+
rect.value().y,
|
|
637
|
+
rect.value().width,
|
|
638
|
+
rect.value().height,
|
|
639
|
+
options.flipY,
|
|
640
|
+
options.premultiplyAlpha,
|
|
641
|
+
options.colorSpaceConversion,
|
|
642
|
+
options.resizeQuality,
|
|
643
|
+
options.resizeWidth,
|
|
644
|
+
options.resizeHeight, asset);
|
|
645
|
+
} else {
|
|
646
|
+
done = canvas_native_image_bitmap_create_from_encoded_bytes_with_output(
|
|
647
|
+
data, size,
|
|
648
|
+
options.flipY,
|
|
649
|
+
options.premultiplyAlpha,
|
|
650
|
+
options.colorSpaceConversion,
|
|
651
|
+
options.resizeQuality,
|
|
652
|
+
options.resizeWidth,
|
|
653
|
+
options.resizeHeight, asset);
|
|
654
|
+
}
|
|
655
|
+
if (callback != nullptr) {
|
|
656
|
+
image_bitmap_async_data->asset_ = asset;
|
|
657
|
+
callback->execute(done);
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
}, std::move(store));
|
|
661
|
+
thread.detach();
|
|
662
|
+
|
|
663
|
+
return;
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
auto type = ObjectWrapperImpl::GetNativeType(image);
|
|
669
|
+
|
|
670
|
+
if (len == 1 || len == 2) {
|
|
671
|
+
if (len == 2) {
|
|
672
|
+
options = ImageBitmapImpl::HandleOptions(isolate, args[1]);
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
v8::Local<v8::Value> retArgs[2];
|
|
676
|
+
retArgs[0] = v8::Null(isolate);
|
|
677
|
+
|
|
678
|
+
switch (type) {
|
|
679
|
+
case NativeType::ImageAsset: {
|
|
680
|
+
auto image_asset = ImageAssetImpl::GetPointer(image.As<v8::Object>());
|
|
681
|
+
auto ret = canvas_native_image_bitmap_create_from_asset(
|
|
682
|
+
image_asset->GetImageAsset(),
|
|
683
|
+
options.flipY,
|
|
684
|
+
options.premultiplyAlpha,
|
|
685
|
+
options.colorSpaceConversion,
|
|
686
|
+
options.resizeQuality,
|
|
687
|
+
options.resizeWidth,
|
|
688
|
+
options.resizeHeight);
|
|
689
|
+
|
|
690
|
+
|
|
691
|
+
auto bitmap = new ImageBitmapImpl(ret);
|
|
692
|
+
auto data = v8::External::New(isolate, bitmap);
|
|
693
|
+
|
|
694
|
+
auto object = ImageBitmapImpl::NewInstance(isolate, data);
|
|
695
|
+
|
|
696
|
+
retArgs[1] = object;
|
|
697
|
+
}
|
|
698
|
+
break;
|
|
699
|
+
case NativeType::ImageBitmap: {
|
|
700
|
+
auto image_bitmap = ImageBitmapImpl::GetPointer(image.As<v8::Object>());
|
|
701
|
+
auto ret = canvas_native_image_bitmap_create_from_asset(
|
|
702
|
+
image_bitmap->GetImageAsset(),
|
|
703
|
+
options.flipY,
|
|
704
|
+
options.premultiplyAlpha,
|
|
705
|
+
options.colorSpaceConversion,
|
|
706
|
+
options.resizeQuality,
|
|
707
|
+
options.resizeWidth,
|
|
708
|
+
options.resizeHeight);
|
|
709
|
+
|
|
710
|
+
|
|
711
|
+
auto bitmap = new ImageBitmapImpl(ret);
|
|
712
|
+
auto data = v8::External::New(isolate, bitmap);
|
|
713
|
+
auto object = ImageBitmapImpl::NewInstance(isolate, data);
|
|
714
|
+
|
|
715
|
+
retArgs[1] = object;
|
|
716
|
+
|
|
717
|
+
}
|
|
718
|
+
break;
|
|
719
|
+
default:
|
|
720
|
+
break;
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
cb.As<v8::Function>()->Call(context, context->Global(), 2, retArgs);
|
|
724
|
+
|
|
725
|
+
return;
|
|
726
|
+
} else if (len == 5 || len == 6) {
|
|
727
|
+
|
|
728
|
+
if (len == 6) {
|
|
729
|
+
options = ImageBitmapImpl::HandleOptions(isolate, args[5]);
|
|
730
|
+
}
|
|
731
|
+
|
|
732
|
+
v8::Local<v8::Value> retArgs[2];
|
|
733
|
+
retArgs[0] = v8::Null(isolate);
|
|
734
|
+
|
|
735
|
+
|
|
736
|
+
switch (type) {
|
|
737
|
+
case NativeType::ImageAsset: {
|
|
738
|
+
auto image_asset = ImageBitmapImpl::GetPointer(image.As<v8::Object>());
|
|
739
|
+
auto ret = canvas_native_image_bitmap_create_from_asset_src_rect(
|
|
740
|
+
image_asset->GetImageAsset(),
|
|
741
|
+
(float) sx_or_options->NumberValue(context).ToChecked(),
|
|
742
|
+
(float) sy->NumberValue(context).ToChecked(),
|
|
743
|
+
(float) sw->NumberValue(context).ToChecked(),
|
|
744
|
+
(float) sh->NumberValue(context).ToChecked(),
|
|
745
|
+
options.flipY,
|
|
746
|
+
options.premultiplyAlpha,
|
|
747
|
+
options.colorSpaceConversion,
|
|
748
|
+
options.resizeQuality,
|
|
749
|
+
options.resizeWidth,
|
|
750
|
+
options.resizeHeight);
|
|
751
|
+
|
|
752
|
+
|
|
753
|
+
auto bitmap = new ImageBitmapImpl(ret);
|
|
754
|
+
auto data = v8::External::New(isolate, bitmap);
|
|
755
|
+
auto object = ImageBitmapImpl::NewInstance(isolate, data);
|
|
756
|
+
|
|
757
|
+
retArgs[1] = object;
|
|
758
|
+
}
|
|
759
|
+
break;
|
|
760
|
+
case NativeType::ImageBitmap: {
|
|
761
|
+
auto image_bitmap = ImageBitmapImpl::GetPointer(image.As<v8::Object>());
|
|
762
|
+
auto ret = canvas_native_image_bitmap_create_from_asset_src_rect(
|
|
763
|
+
image_bitmap->GetImageAsset(),
|
|
764
|
+
(float) sx_or_options->NumberValue(context).ToChecked(),
|
|
765
|
+
(float) sy->NumberValue(context).ToChecked(),
|
|
766
|
+
(float) sw->NumberValue(context).ToChecked(),
|
|
767
|
+
(float) sh->NumberValue(context).ToChecked(),
|
|
768
|
+
options.flipY,
|
|
769
|
+
options.premultiplyAlpha,
|
|
770
|
+
options.colorSpaceConversion,
|
|
771
|
+
options.resizeQuality,
|
|
772
|
+
options.resizeWidth,
|
|
773
|
+
options.resizeHeight);
|
|
774
|
+
|
|
775
|
+
|
|
776
|
+
auto bitmap = new ImageBitmapImpl(ret);
|
|
777
|
+
auto data = v8::External::New(isolate, bitmap);
|
|
778
|
+
auto object = ImageBitmapImpl::NewInstance(isolate, data);
|
|
779
|
+
|
|
780
|
+
retArgs[1] = object;
|
|
781
|
+
|
|
782
|
+
}
|
|
783
|
+
break;
|
|
784
|
+
default:
|
|
785
|
+
break;
|
|
786
|
+
}
|
|
787
|
+
|
|
788
|
+
|
|
789
|
+
cb.As<v8::Function>()->Call(context, context->Global(), 2, retArgs);
|
|
790
|
+
|
|
791
|
+
return;
|
|
792
|
+
}
|
|
793
|
+
|
|
794
|
+
|
|
795
|
+
args.GetReturnValue().SetUndefined();
|
|
796
|
+
|
|
636
797
|
}
|
|
637
798
|
|
|
638
799
|
void CanvasJSIModule::Create2DContextWithPointer(const v8::FunctionCallbackInfo<v8::Value> &args) {
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
800
|
+
auto isolate = args.GetIsolate();
|
|
801
|
+
auto context = isolate->GetCurrentContext();
|
|
802
|
+
auto ptr = args[0]->ToBigInt(context).ToLocalChecked()->Int64Value();
|
|
803
|
+
|
|
804
|
+
auto context_2d = canvas_native_context_create_with_pointer(ptr);
|
|
805
|
+
|
|
806
|
+
auto ret = CanvasRenderingContext2DImpl::NewInstance(isolate, new CanvasRenderingContext2DImpl(
|
|
807
|
+
context_2d));
|
|
808
|
+
args.GetReturnValue().Set(ret);
|
|
648
809
|
}
|
|
649
810
|
|
|
650
811
|
struct FileData {
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
812
|
+
char *error_;
|
|
813
|
+
U8Buffer *data;
|
|
814
|
+
|
|
815
|
+
~FileData() {
|
|
816
|
+
if (error_ != nullptr) {
|
|
817
|
+
canvas_native_string_destroy(error_);
|
|
818
|
+
error_ = nullptr;
|
|
819
|
+
}
|
|
820
|
+
}
|
|
660
821
|
};
|
|
661
822
|
|
|
662
823
|
void CanvasJSIModule::ReadFile(const v8::FunctionCallbackInfo<v8::Value> &args) {
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
// v8::Local<v8::Value> stack;
|
|
735
|
-
// bool success = tc.StackTrace(context).ToLocal(&stack);
|
|
736
|
-
// if (!success || stack.IsEmpty()) {
|
|
737
|
-
// if (!done) {
|
|
738
|
-
// delete async_data;
|
|
739
|
-
// }
|
|
740
|
-
// return;
|
|
741
|
-
// }
|
|
742
|
-
//
|
|
743
|
-
// v8::Local<v8::String> stackV8Str;
|
|
744
|
-
// success = stack->ToDetailString(context).ToLocal(&stackV8Str);
|
|
745
|
-
// if (!success || stackV8Str.IsEmpty()) {
|
|
746
|
-
// if (!done) {
|
|
747
|
-
// delete async_data;
|
|
748
|
-
// }
|
|
749
|
-
// return;
|
|
750
|
-
// }
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
824
|
+
auto isolate = args.GetIsolate();
|
|
825
|
+
auto file = ConvertFromV8String(isolate, args[0]);
|
|
826
|
+
auto cbFunc = args[1].As<v8::Function>();
|
|
827
|
+
|
|
828
|
+
auto callback = new AsyncCallback(isolate, cbFunc, [](bool done, void *data) {
|
|
829
|
+
if (data == nullptr) { return; }
|
|
830
|
+
auto async_data = static_cast<AsyncCallback *>(data);
|
|
831
|
+
auto func = async_data->inner_.get();
|
|
832
|
+
if (func != nullptr && func->isolate_ != nullptr) {
|
|
833
|
+
v8::Isolate *isolate = func->isolate_;
|
|
834
|
+
v8::Locker locker(isolate);
|
|
835
|
+
v8::Isolate::Scope isolate_scope(isolate);
|
|
836
|
+
v8::HandleScope handle_scope(isolate);
|
|
837
|
+
v8::Local<v8::Function> callback = func->callback_.Get(
|
|
838
|
+
isolate);
|
|
839
|
+
v8::Local<v8::Context> context = callback->GetCreationContextChecked();
|
|
840
|
+
v8::Context::Scope context_scope(context);
|
|
841
|
+
|
|
842
|
+
if (func->data != nullptr) {
|
|
843
|
+
auto file_data = static_cast<FileData *>(func->data);
|
|
844
|
+
|
|
845
|
+
v8::Local<v8::Value> args[2];
|
|
846
|
+
|
|
847
|
+
if (done) {
|
|
848
|
+
args[0] = v8::Null(isolate);
|
|
849
|
+
|
|
850
|
+
auto buf = canvas_native_u8_buffer_get_bytes_mut(file_data->data);
|
|
851
|
+
auto size = (size_t) canvas_native_u8_buffer_get_length(file_data->data);
|
|
852
|
+
|
|
853
|
+
auto store = v8::ArrayBuffer::NewBackingStore((void *) buf, size,
|
|
854
|
+
[](void *data,
|
|
855
|
+
size_t length,
|
|
856
|
+
void *deleter_data) {
|
|
857
|
+
if (deleter_data !=
|
|
858
|
+
nullptr) {
|
|
859
|
+
delete static_cast<FileData *>(deleter_data);
|
|
860
|
+
|
|
861
|
+
}
|
|
862
|
+
},
|
|
863
|
+
func->data);
|
|
864
|
+
|
|
865
|
+
auto ret = v8::Object::New(isolate);
|
|
866
|
+
auto buffer = v8::ArrayBuffer::New(isolate, std::move(store));
|
|
867
|
+
ret->Set(context, ConvertToV8String(isolate, "buffer"), buffer);
|
|
868
|
+
auto mime = canvas_native_helper_get_mime(buf, size);
|
|
869
|
+
if (mime != nullptr) {
|
|
870
|
+
if (mime->mime_type != nullptr) {
|
|
871
|
+
ret->Set(context, ConvertToV8String(isolate, "mime"),
|
|
872
|
+
ConvertToV8String(isolate, mime->mime_type));
|
|
873
|
+
}
|
|
874
|
+
if (mime->extension != nullptr) {
|
|
875
|
+
ret->Set(context, ConvertToV8String(isolate, "extension"),
|
|
876
|
+
ConvertToV8String(isolate, mime->extension));
|
|
877
|
+
}
|
|
878
|
+
canvas_native_helper_release_mime(mime);
|
|
879
|
+
}
|
|
880
|
+
|
|
881
|
+
args[1] = ret;
|
|
882
|
+
} else {
|
|
883
|
+
auto error = file_data->error_;
|
|
884
|
+
args[0] = v8::Exception::Error(ConvertToV8String(isolate, error));
|
|
885
|
+
args[1] = v8::Null(isolate);
|
|
886
|
+
delete file_data;
|
|
887
|
+
}
|
|
888
|
+
|
|
889
|
+
v8::TryCatch tc(isolate);
|
|
890
|
+
v8::Local<v8::Value> result;
|
|
891
|
+
if (!callback->Call(context, context->Global(), 2, args).ToLocal(
|
|
892
|
+
&result)) {
|
|
893
|
+
if (tc.HasCaught()) {
|
|
894
|
+
|
|
895
|
+
// v8::Local<v8::Value> stack;
|
|
896
|
+
// bool success = tc.StackTrace(context).ToLocal(&stack);
|
|
897
|
+
// if (!success || stack.IsEmpty()) {
|
|
898
|
+
// if (!done) {
|
|
899
|
+
// delete async_data;
|
|
900
|
+
// }
|
|
901
|
+
// return;
|
|
902
|
+
// }
|
|
903
|
+
//
|
|
904
|
+
// v8::Local<v8::String> stackV8Str;
|
|
905
|
+
// success = stack->ToDetailString(context).ToLocal(&stackV8Str);
|
|
906
|
+
// if (!success || stackV8Str.IsEmpty()) {
|
|
907
|
+
// if (!done) {
|
|
908
|
+
// delete async_data;
|
|
909
|
+
// }
|
|
910
|
+
// return;
|
|
911
|
+
// }
|
|
912
|
+
|
|
913
|
+
}
|
|
914
|
+
}
|
|
915
|
+
|
|
916
|
+
delete async_data;
|
|
917
|
+
|
|
918
|
+
}
|
|
919
|
+
}
|
|
920
|
+
});
|
|
921
|
+
|
|
922
|
+
callback->prepare();
|
|
923
|
+
|
|
924
|
+
std::thread thread(
|
|
925
|
+
[callback, file]() {
|
|
926
|
+
bool done = false;
|
|
927
|
+
auto ret = canvas_native_helper_read_file(file.c_str());
|
|
928
|
+
|
|
929
|
+
if (!canvas_native_helper_read_file_has_error(ret)) {
|
|
930
|
+
auto buf = canvas_native_helper_read_file_take_data(ret);
|
|
931
|
+
callback->inner_->data = new FileData{nullptr, buf};
|
|
932
|
+
done = true;
|
|
933
|
+
} else {
|
|
934
|
+
auto error = canvas_native_helper_read_file_get_error(ret);
|
|
935
|
+
callback->inner_->data = new FileData{const_cast<char *>(error), nullptr};
|
|
936
|
+
}
|
|
937
|
+
canvas_native_helper_release(ret);
|
|
938
|
+
callback->execute(done);
|
|
939
|
+
});
|
|
940
|
+
|
|
941
|
+
thread.detach();
|
|
942
|
+
|
|
943
|
+
|
|
783
944
|
}
|
|
784
945
|
|
|
785
946
|
|
|
786
947
|
void CanvasJSIModule::GetMime(const v8::FunctionCallbackInfo<v8::Value> &args) {
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
// v8::Local<v8::Value> stack;
|
|
844
|
-
// bool success = tc.StackTrace(context).ToLocal(&stack);
|
|
845
|
-
// if (!success || stack.IsEmpty()) {
|
|
846
|
-
// if (!done) {
|
|
847
|
-
// delete async_data;
|
|
848
|
-
// }
|
|
849
|
-
// return;
|
|
850
|
-
// }
|
|
851
|
-
//
|
|
852
|
-
// v8::Local<v8::String> stackV8Str;
|
|
853
|
-
// success = stack->ToDetailString(context).ToLocal(&stackV8Str);
|
|
854
|
-
// if (!success || stackV8Str.IsEmpty()) {
|
|
855
|
-
// if (!done) {
|
|
856
|
-
// delete async_data;
|
|
857
|
-
// }
|
|
858
|
-
// return;
|
|
859
|
-
// }
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
948
|
+
auto isolate = args.GetIsolate();
|
|
949
|
+
auto file = ConvertFromV8String(isolate, args[0]);
|
|
950
|
+
auto cbFunc = args[1].As<v8::Function>();
|
|
951
|
+
|
|
952
|
+
|
|
953
|
+
auto callback = new AsyncCallback(isolate, cbFunc, [](bool done, void *data) {
|
|
954
|
+
if (data == nullptr) { return; }
|
|
955
|
+
auto async_data = static_cast<AsyncCallback *>(data);
|
|
956
|
+
auto func = async_data->inner_.get();
|
|
957
|
+
if (func != nullptr && func->isolate_ != nullptr) {
|
|
958
|
+
v8::Isolate *isolate = func->isolate_;
|
|
959
|
+
v8::Locker locker(isolate);
|
|
960
|
+
v8::Isolate::Scope isolate_scope(isolate);
|
|
961
|
+
v8::HandleScope handle_scope(isolate);
|
|
962
|
+
v8::Local<v8::Function> callback = func->callback_.Get(
|
|
963
|
+
isolate);
|
|
964
|
+
v8::Local<v8::Context> context = callback->GetCreationContextChecked();
|
|
965
|
+
v8::Context::Scope context_scope(context);
|
|
966
|
+
|
|
967
|
+
if (func->data != nullptr) {
|
|
968
|
+
auto file_data = static_cast<FileData *>(func->data);
|
|
969
|
+
|
|
970
|
+
v8::Local<v8::Value> args[2];
|
|
971
|
+
|
|
972
|
+
if (done) {
|
|
973
|
+
args[0] = v8::Null(isolate);
|
|
974
|
+
|
|
975
|
+
auto buf = (void *) canvas_native_u8_buffer_get_bytes_mut(file_data->data);
|
|
976
|
+
auto size = (size_t) canvas_native_u8_buffer_get_length(file_data->data);
|
|
977
|
+
|
|
978
|
+
auto store = v8::ArrayBuffer::NewBackingStore(buf, size,
|
|
979
|
+
[](void *data,
|
|
980
|
+
size_t length,
|
|
981
|
+
void *deleter_data) {
|
|
982
|
+
if (deleter_data !=
|
|
983
|
+
nullptr) {
|
|
984
|
+
delete static_cast<FileData *>(deleter_data);
|
|
985
|
+
|
|
986
|
+
}
|
|
987
|
+
},
|
|
988
|
+
func->data);
|
|
989
|
+
|
|
990
|
+
args[1] = v8::ArrayBuffer::New(isolate, std::move(store));
|
|
991
|
+
} else {
|
|
992
|
+
auto error = file_data->error_;
|
|
993
|
+
args[0] = v8::Exception::Error(ConvertToV8String(isolate, error));
|
|
994
|
+
args[1] = v8::Null(isolate);
|
|
995
|
+
delete file_data;
|
|
996
|
+
}
|
|
997
|
+
|
|
998
|
+
v8::TryCatch tc(isolate);
|
|
999
|
+
v8::Local<v8::Value> result;
|
|
1000
|
+
if (!callback->Call(context, context->Global(), 2, args).ToLocal(
|
|
1001
|
+
&result)) {
|
|
1002
|
+
if (tc.HasCaught()) {
|
|
1003
|
+
|
|
1004
|
+
// v8::Local<v8::Value> stack;
|
|
1005
|
+
// bool success = tc.StackTrace(context).ToLocal(&stack);
|
|
1006
|
+
// if (!success || stack.IsEmpty()) {
|
|
1007
|
+
// if (!done) {
|
|
1008
|
+
// delete async_data;
|
|
1009
|
+
// }
|
|
1010
|
+
// return;
|
|
1011
|
+
// }
|
|
1012
|
+
//
|
|
1013
|
+
// v8::Local<v8::String> stackV8Str;
|
|
1014
|
+
// success = stack->ToDetailString(context).ToLocal(&stackV8Str);
|
|
1015
|
+
// if (!success || stackV8Str.IsEmpty()) {
|
|
1016
|
+
// if (!done) {
|
|
1017
|
+
// delete async_data;
|
|
1018
|
+
// }
|
|
1019
|
+
// return;
|
|
1020
|
+
// }
|
|
1021
|
+
|
|
1022
|
+
}
|
|
1023
|
+
}
|
|
1024
|
+
|
|
1025
|
+
delete async_data;
|
|
1026
|
+
|
|
1027
|
+
}
|
|
1028
|
+
}
|
|
1029
|
+
});
|
|
1030
|
+
|
|
1031
|
+
callback->prepare();
|
|
1032
|
+
|
|
1033
|
+
std::thread thread(
|
|
1034
|
+
[callback, file]() {
|
|
1035
|
+
bool done = false;
|
|
1036
|
+
auto ret = canvas_native_helper_read_file(file.c_str());
|
|
1037
|
+
|
|
1038
|
+
if (!canvas_native_helper_read_file_has_error(ret)) {
|
|
1039
|
+
auto buf = canvas_native_helper_read_file_take_data(ret);
|
|
1040
|
+
callback->inner_->data = new FileData{nullptr, buf};
|
|
1041
|
+
done = true;
|
|
1042
|
+
} else {
|
|
1043
|
+
auto error = canvas_native_helper_read_file_get_error(ret);
|
|
1044
|
+
callback->inner_->data = new FileData{const_cast<char *>(error), nullptr};
|
|
1045
|
+
}
|
|
1046
|
+
canvas_native_helper_release(ret);
|
|
1047
|
+
callback->execute(done);
|
|
1048
|
+
});
|
|
1049
|
+
|
|
1050
|
+
thread.detach();
|
|
1051
|
+
|
|
1052
|
+
|
|
892
1053
|
}
|
|
893
1054
|
|
|
894
1055
|
|
|
895
1056
|
void CanvasJSIModule::CreateWebGLContext(const v8::FunctionCallbackInfo<v8::Value> &args) {
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
1057
|
+
|
|
1058
|
+
auto options = GLOptions();
|
|
1059
|
+
options.parseGLOptions(args);
|
|
1060
|
+
|
|
1061
|
+
if (options.version != 1) {
|
|
1062
|
+
args.GetReturnValue().SetNull();
|
|
1063
|
+
return;
|
|
1064
|
+
}
|
|
1065
|
+
|
|
1066
|
+
auto isolate = args.GetIsolate();
|
|
1067
|
+
auto context = isolate->GetCurrentContext();
|
|
1068
|
+
|
|
1069
|
+
|
|
1070
|
+
auto count = args.Length();
|
|
1071
|
+
if (count == 6) {
|
|
1072
|
+
auto ctx = args[1].As<v8::BigInt>()->Int64Value();
|
|
1073
|
+
auto webgl = (WebGLState *) ctx;
|
|
1074
|
+
|
|
1075
|
+
auto renderingContext = WebGLRenderingContext::NewInstance(isolate,
|
|
1076
|
+
new WebGLRenderingContext(
|
|
1077
|
+
webgl));
|
|
1078
|
+
|
|
1079
|
+
args.GetReturnValue().Set(renderingContext);
|
|
1080
|
+
return;
|
|
1081
|
+
} else if (count == 7) {
|
|
1082
|
+
auto width = args[1]->NumberValue(context).ToChecked();
|
|
1083
|
+
auto height = args[2]->NumberValue(context).ToChecked();
|
|
1084
|
+
auto ctx = canvas_native_webgl_create_no_window(
|
|
1085
|
+
(int32_t) width,
|
|
1086
|
+
(int32_t) height,
|
|
1087
|
+
options.version,
|
|
1088
|
+
options.alpha,
|
|
1089
|
+
options.antialias,
|
|
1090
|
+
options.depth,
|
|
1091
|
+
options.failIfMajorPerformanceCaveat,
|
|
1092
|
+
options.powerPreference,
|
|
1093
|
+
options.premultipliedAlpha,
|
|
1094
|
+
options.preserveDrawingBuffer,
|
|
1095
|
+
options.stencil,
|
|
1096
|
+
options.desynchronized,
|
|
1097
|
+
options.xrCompatible,
|
|
1098
|
+
false
|
|
1099
|
+
);
|
|
1100
|
+
|
|
1101
|
+
auto renderingContext = WebGLRenderingContext::NewInstance(isolate,
|
|
1102
|
+
new WebGLRenderingContext(
|
|
1103
|
+
ctx));
|
|
1104
|
+
|
|
1105
|
+
args.GetReturnValue().Set(renderingContext);
|
|
1106
|
+
return;
|
|
1107
|
+
|
|
1108
|
+
} else {
|
|
1109
|
+
auto width = (int32_t) args[1]->NumberValue(context).ToChecked();
|
|
1110
|
+
auto height = (int32_t) args[2]->NumberValue(context).ToChecked();
|
|
1111
|
+
|
|
1112
|
+
auto ctx = canvas_native_webgl_create_no_window(
|
|
1113
|
+
width,
|
|
1114
|
+
height,
|
|
1115
|
+
options.version,
|
|
1116
|
+
options.alpha,
|
|
1117
|
+
options.antialias,
|
|
1118
|
+
options.depth,
|
|
1119
|
+
options.failIfMajorPerformanceCaveat,
|
|
1120
|
+
options.powerPreference,
|
|
1121
|
+
options.premultipliedAlpha,
|
|
1122
|
+
options.preserveDrawingBuffer,
|
|
1123
|
+
options.stencil,
|
|
1124
|
+
options.desynchronized,
|
|
1125
|
+
options.xrCompatible,
|
|
1126
|
+
false
|
|
1127
|
+
);
|
|
1128
|
+
|
|
1129
|
+
auto renderingContext = WebGLRenderingContext::NewInstance(isolate,
|
|
1130
|
+
new WebGLRenderingContext(
|
|
1131
|
+
ctx));
|
|
1132
|
+
|
|
1133
|
+
args.GetReturnValue().Set(renderingContext);
|
|
1134
|
+
return;
|
|
1135
|
+
}
|
|
975
1136
|
}
|
|
976
1137
|
|
|
977
1138
|
void CanvasJSIModule::CreateWebGL2Context(const v8::FunctionCallbackInfo<v8::Value> &args) {
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1139
|
+
|
|
1140
|
+
|
|
1141
|
+
auto options = GLOptions();
|
|
1142
|
+
options.parseGLOptions(args);
|
|
1143
|
+
|
|
1144
|
+
if (options.version != 2) {
|
|
1145
|
+
args.GetReturnValue().SetNull();
|
|
1146
|
+
return;
|
|
1147
|
+
}
|
|
1148
|
+
|
|
1149
|
+
|
|
1150
|
+
auto isolate = args.GetIsolate();
|
|
1151
|
+
auto context = isolate->GetCurrentContext();
|
|
1152
|
+
|
|
1153
|
+
|
|
1154
|
+
auto count = args.Length();
|
|
1155
|
+
if (count == 6) {
|
|
1156
|
+
auto ctx = args[1].As<v8::BigInt>()->Int64Value();
|
|
1157
|
+
auto webgl = (WebGLState *) ctx;
|
|
1158
|
+
auto renderingContext = WebGL2RenderingContext::NewInstance(isolate,
|
|
1159
|
+
new WebGL2RenderingContext(
|
|
1160
|
+
webgl,
|
|
1161
|
+
WebGLRenderingVersion::V2));
|
|
1162
|
+
|
|
1163
|
+
args.GetReturnValue().Set(renderingContext);
|
|
1164
|
+
return;
|
|
1165
|
+
|
|
1166
|
+
} else if (count ==
|
|
1167
|
+
7) {
|
|
1168
|
+
auto width = args[1]->NumberValue(context).ToChecked();
|
|
1169
|
+
auto height = args[2]->NumberValue(context).ToChecked();
|
|
1170
|
+
auto ctx = canvas_native_webgl_create_no_window(
|
|
1171
|
+
(int32_t) width,
|
|
1172
|
+
(int32_t) height,
|
|
1173
|
+
options.version,
|
|
1174
|
+
options.alpha,
|
|
1175
|
+
options.antialias,
|
|
1176
|
+
options.depth,
|
|
1177
|
+
options.failIfMajorPerformanceCaveat,
|
|
1178
|
+
options.powerPreference,
|
|
1179
|
+
options.premultipliedAlpha,
|
|
1180
|
+
options.preserveDrawingBuffer,
|
|
1181
|
+
options.stencil,
|
|
1182
|
+
options.desynchronized,
|
|
1183
|
+
options.xrCompatible,
|
|
1184
|
+
false
|
|
1185
|
+
);
|
|
1186
|
+
auto renderingContext = WebGL2RenderingContext::NewInstance(isolate,
|
|
1187
|
+
new WebGL2RenderingContext(
|
|
1188
|
+
ctx,
|
|
1189
|
+
WebGLRenderingVersion::V2));
|
|
1190
|
+
|
|
1191
|
+
args.GetReturnValue().Set(renderingContext);
|
|
1192
|
+
return;
|
|
1193
|
+
|
|
1194
|
+
} else {
|
|
1195
|
+
auto width = (int32_t) args[1]->NumberValue(context).ToChecked();
|
|
1196
|
+
auto height = (int32_t) args[2]->NumberValue(context).ToChecked();
|
|
1197
|
+
auto ctx = canvas_native_webgl_create_no_window(
|
|
1198
|
+
width,
|
|
1199
|
+
height,
|
|
1200
|
+
options.version,
|
|
1201
|
+
options.alpha,
|
|
1202
|
+
options.antialias,
|
|
1203
|
+
options.depth,
|
|
1204
|
+
options.failIfMajorPerformanceCaveat,
|
|
1205
|
+
options.powerPreference,
|
|
1206
|
+
options.premultipliedAlpha,
|
|
1207
|
+
options.preserveDrawingBuffer,
|
|
1208
|
+
options.stencil,
|
|
1209
|
+
options.desynchronized,
|
|
1210
|
+
options.xrCompatible,
|
|
1211
|
+
false
|
|
1212
|
+
);
|
|
1213
|
+
|
|
1214
|
+
auto renderingContext = WebGL2RenderingContext::NewInstance(isolate,
|
|
1215
|
+
new WebGL2RenderingContext(
|
|
1216
|
+
ctx,
|
|
1217
|
+
WebGLRenderingVersion::V2));
|
|
1218
|
+
|
|
1219
|
+
args.GetReturnValue().Set(renderingContext);
|
|
1220
|
+
return;
|
|
1221
|
+
}
|
|
1061
1222
|
}
|
|
1062
1223
|
|
|
1063
1224
|
void
|
|
1064
1225
|
CanvasJSIModule::CreateWebGPUContextWithPointer(const v8::FunctionCallbackInfo<v8::Value> &args) {
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1226
|
+
auto isolate = args.GetIsolate();
|
|
1227
|
+
auto context = isolate->GetCurrentContext();
|
|
1228
|
+
auto ptr = args[0]->ToBigInt(context).ToLocalChecked()->Int64Value();
|
|
1229
|
+
|
|
1230
|
+
auto wgpu = static_cast<CanvasGPUCanvasContext *>((void *) ptr);
|
|
1231
|
+
|
|
1232
|
+
auto ret = GPUCanvasContextImpl::NewInstance(isolate, new GPUCanvasContextImpl(
|
|
1233
|
+
wgpu));
|
|
1234
|
+
args.GetReturnValue().Set(ret);
|
|
1074
1235
|
}
|