@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.
Files changed (125) hide show
  1. package/Canvas/common.d.ts +13 -6
  2. package/Canvas/common.js +257 -206
  3. package/Canvas/common.js.map +1 -1
  4. package/Canvas/index.android.d.ts +2 -0
  5. package/Canvas/index.android.js +23 -4
  6. package/Canvas/index.android.js.map +1 -1
  7. package/Canvas/index.d.ts +3 -0
  8. package/Canvas/index.ios.d.ts +2 -0
  9. package/Canvas/index.ios.js +16 -3
  10. package/Canvas/index.ios.js.map +1 -1
  11. package/Canvas/utils.js +2 -1
  12. package/Canvas/utils.js.map +1 -1
  13. package/Canvas2D/CanvasRenderingContext2D/index.d.ts +1 -0
  14. package/Canvas2D/CanvasRenderingContext2D/index.js +158 -6
  15. package/Canvas2D/CanvasRenderingContext2D/index.js.map +1 -1
  16. package/Canvas2D/DOMMatrix/index.js +280 -2
  17. package/Canvas2D/DOMMatrix/index.js.map +1 -1
  18. package/Canvas2D/Path2D/index.js.map +1 -1
  19. package/Fonts/FontFace.android.js +7 -3
  20. package/Fonts/FontFace.android.js.map +1 -1
  21. package/Fonts/FontFace.ios.d.ts +1 -0
  22. package/Fonts/FontFace.ios.js +10 -3
  23. package/Fonts/FontFace.ios.js.map +1 -1
  24. package/TextDecoder/index.d.ts +1 -0
  25. package/TextDecoder/index.js +17 -0
  26. package/TextDecoder/index.js.map +1 -1
  27. package/WebGL/WebGLRenderingContext/index.js +0 -1
  28. package/WebGL/WebGLRenderingContext/index.js.map +1 -1
  29. package/WebGPU/GPUCanvasContext.d.ts +0 -1
  30. package/WebGPU/GPUCanvasContext.js +6 -18
  31. package/WebGPU/GPUCanvasContext.js.map +1 -1
  32. package/WebGPU/GPUCommandEncoder.d.ts +1 -1
  33. package/WebGPU/GPUCommandEncoder.js +1 -1
  34. package/WebGPU/GPUCommandEncoder.js.map +1 -1
  35. package/WebGPU/GPUCompilationInfo.d.ts +10 -0
  36. package/WebGPU/GPUCompilationInfo.js +20 -0
  37. package/WebGPU/GPUCompilationInfo.js.map +1 -0
  38. package/WebGPU/GPUCompilationMessage.d.ts +11 -0
  39. package/WebGPU/GPUCompilationMessage.js +30 -0
  40. package/WebGPU/GPUCompilationMessage.js.map +1 -0
  41. package/WebGPU/GPUDevice.d.ts +2 -2
  42. package/WebGPU/GPUDevice.js.map +1 -1
  43. package/WebGPU/GPUQueue.js +1 -4
  44. package/WebGPU/GPUQueue.js.map +1 -1
  45. package/WebGPU/GPURenderPassEncoder.d.ts +1 -1
  46. package/WebGPU/GPURenderPassEncoder.js +2 -2
  47. package/WebGPU/GPURenderPassEncoder.js.map +1 -1
  48. package/WebGPU/GPUShaderModule.d.ts +2 -0
  49. package/WebGPU/GPUShaderModule.js +10 -0
  50. package/WebGPU/GPUShaderModule.js.map +1 -1
  51. package/WebGPU/Interfaces.d.ts +1 -0
  52. package/WebGPU/Types.d.ts +3 -3
  53. package/WebGPU/Utils.d.ts +1 -1
  54. package/WebGPU/Utils.js +67 -93
  55. package/WebGPU/Utils.js.map +1 -1
  56. package/WebGPU/index.d.ts +2 -0
  57. package/WebGPU/index.js +2 -0
  58. package/WebGPU/index.js.map +1 -1
  59. package/angular/fesm2022/nativescript-canvas-angular.mjs +5 -5
  60. package/angular/package.json +0 -2
  61. package/helpers.d.ts +3 -0
  62. package/helpers.js +9 -0
  63. package/helpers.js.map +1 -1
  64. package/index.js +6 -1
  65. package/index.js.map +1 -1
  66. package/package.json +1 -1
  67. package/platforms/android/canvas-release.aar +0 -0
  68. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/CanvasNative +0 -0
  69. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Headers/CanvasNative-Swift.h +10 -5
  70. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Headers/canvas_native.h +294 -47
  71. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Info.plist +0 -0
  72. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Modules/CanvasNative.swiftmodule/Project/arm64-apple-ios.swiftsourceinfo +0 -0
  73. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios.abi.json +11317 -11881
  74. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios.private.swiftinterface +55 -49
  75. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios.swiftdoc +0 -0
  76. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios.swiftinterface +55 -49
  77. package/platforms/ios/CanvasNative.xcframework/ios-arm64/dSYMs/CanvasNative.framework.dSYM/Contents/Resources/DWARF/CanvasNative +0 -0
  78. package/platforms/ios/CanvasNative.xcframework/ios-arm64/dSYMs/CanvasNative.framework.dSYM/Contents/Resources/Relocations/aarch64/CanvasNative.yml +954 -994
  79. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/CanvasNative +0 -0
  80. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Headers/CanvasNative-Swift.h +20 -10
  81. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Headers/canvas_native.h +294 -47
  82. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Info.plist +0 -0
  83. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/Project/arm64-apple-ios-simulator.swiftsourceinfo +0 -0
  84. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/Project/x86_64-apple-ios-simulator.swiftsourceinfo +0 -0
  85. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios-simulator.abi.json +11317 -11881
  86. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios-simulator.private.swiftinterface +55 -49
  87. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios-simulator.swiftdoc +0 -0
  88. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios-simulator.swiftinterface +55 -49
  89. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/x86_64-apple-ios-simulator.abi.json +11317 -11881
  90. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/x86_64-apple-ios-simulator.private.swiftinterface +55 -49
  91. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/x86_64-apple-ios-simulator.swiftdoc +0 -0
  92. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/x86_64-apple-ios-simulator.swiftinterface +55 -49
  93. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/_CodeSignature/CodeResources +29 -29
  94. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/dSYMs/CanvasNative.framework.dSYM/Contents/Resources/DWARF/CanvasNative +0 -0
  95. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/dSYMs/CanvasNative.framework.dSYM/Contents/Resources/Relocations/aarch64/CanvasNative.yml +955 -993
  96. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/dSYMs/CanvasNative.framework.dSYM/Contents/Resources/Relocations/x86_64/CanvasNative.yml +824 -1037
  97. package/platforms/ios/src/cpp/Caches.h +6 -0
  98. package/platforms/ios/src/cpp/CanvasJSIModule.cpp +1172 -1011
  99. package/platforms/ios/src/cpp/CanvasJSIModule.h +6 -0
  100. package/platforms/ios/src/cpp/Helpers.h +23 -2
  101. package/platforms/ios/src/cpp/NativeType.h +3 -1
  102. package/platforms/ios/src/cpp/OnRafCallback.cpp +15 -10
  103. package/platforms/ios/src/cpp/OnRafCallback.h +1 -0
  104. package/platforms/ios/src/cpp/PromiseCallback.h +42 -20
  105. package/platforms/ios/src/cpp/TextDecoderImpl.cpp +142 -0
  106. package/platforms/ios/src/cpp/TextDecoderImpl.h +2 -0
  107. package/platforms/ios/src/cpp/canvas2d/CanvasRenderingContext2DImpl.cpp +59 -15
  108. package/platforms/ios/src/cpp/canvas2d/Path2D.cpp +1 -1
  109. package/platforms/ios/src/cpp/webgpu/GPUAdapterImpl.cpp +4 -8
  110. package/platforms/ios/src/cpp/webgpu/GPUCanvasContextImpl.cpp +431 -326
  111. package/platforms/ios/src/cpp/webgpu/GPUCanvasContextImpl.h +98 -42
  112. package/platforms/ios/src/cpp/webgpu/GPUCommandEncoderImpl.cpp +1150 -1144
  113. package/platforms/ios/src/cpp/webgpu/GPUCompilationInfoImpl.cpp +88 -0
  114. package/platforms/ios/src/cpp/webgpu/GPUCompilationInfoImpl.h +49 -0
  115. package/platforms/ios/src/cpp/webgpu/GPUCompilationMessageImpl.cpp +193 -0
  116. package/platforms/ios/src/cpp/webgpu/GPUCompilationMessageImpl.h +64 -0
  117. package/platforms/ios/src/cpp/webgpu/GPUDeviceImpl.cpp +69 -34
  118. package/platforms/ios/src/cpp/webgpu/GPUQueueImpl.cpp +45 -18
  119. package/platforms/ios/src/cpp/webgpu/GPURenderPassEncoderImpl.cpp +22 -19
  120. package/platforms/ios/src/cpp/webgpu/GPUShaderModuleImpl.cpp +23 -0
  121. package/platforms/ios/src/cpp/webgpu/GPUShaderModuleImpl.h +2 -0
  122. package/platforms/ios/src/cpp/webgpu/GPUTextureImpl.cpp +11 -0
  123. package/platforms/ios/src/cpp/webgpu/GPUUtils.h +25 -15
  124. package/angular/esm2022/index.mjs +0 -17
  125. 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
- 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
-
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
- 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
- config->Get(context, ConvertToV8String(isolate, "version")).ToLocal(&versionValue);
53
-
54
- if (!versionValue.IsEmpty() && versionValue->IsInt32()) {
55
- versionValue->Int32Value(context).To(&this->version);
56
- }
57
-
58
- v8::Local<v8::Value> alphaValue;
59
-
60
- config->Get(context, ConvertToV8String(isolate, "alpha")).ToLocal(&alphaValue);
61
- if (!alphaValue.IsEmpty() && alphaValue->IsBoolean()) {
62
- this->alpha = alphaValue->BooleanValue(isolate);
63
- }
64
-
65
- v8::Local<v8::Value> antialiasValue;
66
- config->Get(context, ConvertToV8String(isolate, "antialias")).ToLocal(
67
- &antialiasValue);
68
- if (!antialiasValue.IsEmpty() && antialiasValue->IsBoolean()) {
69
- this->antialias = antialiasValue->BooleanValue(isolate);
70
- }
71
-
72
- v8::Local<v8::Value> failIfMajorPerformanceCaveatValue;
73
- config->Get(context, ConvertToV8String(isolate, "failIfMajorPerformanceCaveat")).ToLocal(
74
- &failIfMajorPerformanceCaveatValue);
75
- if (!failIfMajorPerformanceCaveatValue.IsEmpty() &&
76
- failIfMajorPerformanceCaveatValue->IsBoolean()) {
77
- this->failIfMajorPerformanceCaveat = failIfMajorPerformanceCaveatValue->BooleanValue(
78
- isolate);
79
- }
80
-
81
- v8::Local<v8::Value> powerPreferenceValue;
82
- config->Get(context, ConvertToV8String(isolate, "powerPreference")).ToLocal(
83
- &powerPreferenceValue);
84
- if (!powerPreferenceValue.IsEmpty() && powerPreferenceValue->IsInt32()) {
85
- powerPreferenceValue->Int32Value(context).To(&this->powerPreference);
86
- }
87
-
88
- v8::Local<v8::Value> premultipliedAlphaValue;
89
- config->Get(context,
90
- ConvertToV8String(isolate, "premultipliedAlpha")).ToLocal(
91
- &premultipliedAlphaValue);
92
- if (!premultipliedAlphaValue.IsEmpty() && premultipliedAlphaValue->IsBoolean()) {
93
- this->premultipliedAlpha = premultipliedAlphaValue->BooleanValue(isolate);
94
- }
95
-
96
- v8::Local<v8::Value> preserveDrawingBufferValue;
97
- config->Get(context,
98
- ConvertToV8String(isolate, "preserveDrawingBuffer")).ToLocal(
99
- &preserveDrawingBufferValue);
100
- if (!preserveDrawingBufferValue.IsEmpty() && preserveDrawingBufferValue->IsBoolean()) {
101
- this->preserveDrawingBuffer = preserveDrawingBufferValue->BooleanValue(isolate);
102
- }
103
-
104
- v8::Local<v8::Value> stencilValue;
105
- config->Get(context, ConvertToV8String(isolate, "stencil")).ToLocal(&stencilValue);
106
- if (!stencilValue.IsEmpty() && stencilValue->IsBoolean()) {
107
- this->stencil = stencilValue->BooleanValue(isolate);
108
- }
109
-
110
- v8::Local<v8::Value> desynchronizedValue;
111
- config->Get(context, ConvertToV8String(isolate, "desynchronized")).ToLocal(
112
- &desynchronizedValue);
113
- if (!desynchronizedValue.IsEmpty() && desynchronizedValue->IsBoolean()) {
114
- this->desynchronized = desynchronizedValue->BooleanValue(isolate);
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
- auto context = isolate->GetCurrentContext();
129
- auto global = context->Global();
130
-
131
- if (!global->
132
- HasOwnProperty(context, ConvertToV8String(isolate, "CanvasJSIModule")).FromMaybe(
133
- false)) {
134
-
135
-
136
- v8::Locker locker(isolate);
137
- v8::Isolate::Scope isolate_scope(isolate);
138
- v8::HandleScope handle_scope(isolate);
139
-
140
- auto v8Global = context->Global();
141
-
142
- auto canvasMod = v8::Object::New(isolate);
143
- TextDecoderImpl::Init(canvasMod, isolate);
144
- TextEncoderImpl::Init(canvasMod, isolate);
145
- Path2D::Init(canvasMod, isolate);
146
- ImageDataImpl::Init(canvasMod, isolate);
147
- ImageAssetImpl::Init(canvasMod, isolate);
148
- ImageBitmapImpl::Init(canvasMod, isolate);
149
- CanvasGradient::Init(canvasMod, isolate);
150
- CanvasPattern::Init(canvasMod, isolate);
151
- MatrixImpl::Init(canvasMod, isolate);
152
- TextMetricsImpl::Init(canvasMod, isolate);
153
-
154
-
155
- GPUImpl::Init(canvasMod, isolate);
156
- GPUSupportedLimitsImpl::Init(canvasMod, isolate);
157
- GPUDeviceImpl::Init(canvasMod, isolate);
158
- GPUQueueImpl::Init(canvasMod, isolate);
159
-
160
- v8Global->Set(context, ConvertToV8String(isolate, "CanvasModule"), canvasMod).FromJust();
161
- canvasMod->Set(context, ConvertToV8String(isolate, "create2DContext"),
162
- v8::FunctionTemplate::New(isolate, &Create2DContext)->GetFunction(
163
- context).ToLocalChecked()).FromJust();
164
- canvasMod->Set(context, ConvertToV8String(isolate, "createImageBitmap"),
165
- v8::FunctionTemplate::New(isolate, &CreateImageBitmap)->GetFunction(
166
- context).ToLocalChecked()).FromJust();
167
- canvasMod->Set(context, ConvertToV8String(isolate, "create2DContextWithPointer"),
168
- v8::FunctionTemplate::New(isolate, &Create2DContextWithPointer)->GetFunction(
169
- context).ToLocalChecked()).FromJust();
170
-
171
- canvasMod->Set(context, ConvertToV8String(isolate, "createWebGPUContextWithPointer"),
172
- v8::FunctionTemplate::New(isolate,
173
- &CreateWebGPUContextWithPointer)->GetFunction(
174
- context).ToLocalChecked()).FromJust();
175
-
176
-
177
- canvasMod->Set(context, ConvertToV8String(isolate, "readFile"),
178
- v8::FunctionTemplate::New(isolate, &ReadFile)->GetFunction(
179
- context).ToLocalChecked()).FromJust();
180
-
181
- canvasMod->Set(context, ConvertToV8String(isolate, "getMime"),
182
- v8::FunctionTemplate::New(isolate, &GetMime)->GetFunction(
183
- context).ToLocalChecked()).FromJust();
184
-
185
- canvasMod->Set(context, ConvertToV8String(isolate, "createWebGLContext"),
186
- v8::FunctionTemplate::New(isolate, &CreateWebGLContext)->GetFunction(
187
- context).ToLocalChecked()).FromJust();
188
-
189
- canvasMod->Set(context, ConvertToV8String(isolate, "createWebGL2Context"),
190
- v8::FunctionTemplate::New(isolate, &CreateWebGL2Context)->GetFunction(
191
- context).ToLocalChecked()).FromJust();
192
-
193
-
194
- canvasMod->Set(context, ConvertToV8String(isolate, "__addFontFamily"),
195
- v8::FunctionTemplate::New(isolate, &AddFontFamily)->GetFunction(
196
- context).ToLocalChecked()).FromJust();
197
-
198
- canvasMod->Set(context, ConvertToV8String(isolate, "__addFontData"),
199
- v8::FunctionTemplate::New(isolate, &AddFontData)->GetFunction(
200
- context).ToLocalChecked()).FromJust();
201
-
202
- global->Set(context,
203
- ConvertToV8String(isolate, "CanvasModule"), canvasMod).FromJust();
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
- auto isolate = args.GetIsolate();
210
- auto context = isolate->GetCurrentContext();
211
- auto aliasValue = args[0];
212
- auto familyValue = args[1];
213
-
214
- // todo improve
215
- if (familyValue->IsArray()) {
216
- auto family = familyValue.As<v8::Array>();
217
- auto len = family->Length();
218
- std::vector<std::string> buf;
219
- std::vector<const char *> buffer;
220
- buf.reserve(len);
221
-
222
- for (uint32_t i = 0; i < len; i++) {
223
- buf.emplace_back(
224
- ConvertFromV8String(isolate, family->Get(context, i).ToLocalChecked()));
225
- buffer.emplace_back(buf[0].c_str());
226
- }
227
-
228
- if (aliasValue->IsString()) {
229
- auto alias = ConvertFromV8String(isolate, aliasValue);
230
- canvas_native_font_add_family(alias.c_str(), buffer.data(), buffer.size());
231
- } else {
232
- canvas_native_font_add_family(nullptr, buffer.data(), buffer.size());
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
- auto isolate = args.GetIsolate();
241
- auto context = isolate->GetCurrentContext();
242
- auto aliasValue = args[0];
243
- auto dataValue = args[1];
244
-
245
- // todo improve
246
- if (dataValue->IsArrayBuffer()) {
247
-
248
- if (aliasValue->IsString()) {
249
- auto alias = ConvertFromV8String(isolate, aliasValue);
250
- auto data = dataValue.As<v8::ArrayBuffer>();
251
- auto store = data->GetBackingStore();
252
- canvas_native_font_add_family_with_bytes(alias.c_str(), (uint8_t *) store->Data(),
253
- store->ByteLength());
254
- } else {
255
- auto data = dataValue.As<v8::ArrayBuffer>();
256
- auto store = data->GetBackingStore();
257
- canvas_native_font_add_family_with_bytes(nullptr, (uint8_t *) store->Data(),
258
- store->ByteLength());
259
- }
260
-
261
- } else if (dataValue->IsTypedArray()) {
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
- if (aliasValue->IsString()) {
264
- auto alias = ConvertFromV8String(isolate, aliasValue);
265
- auto data = dataValue.As<v8::TypedArray>();
266
- auto buffer = data->Buffer();
267
- auto store = buffer->GetBackingStore();
268
- canvas_native_font_add_family_with_bytes(alias.c_str(), (uint8_t *) store->Data(),
269
- store->ByteLength());
270
- } else {
271
- auto data = dataValue.As<v8::TypedArray>();
272
- auto buffer = data->Buffer();
273
- auto store = buffer->GetBackingStore();
274
- canvas_native_font_add_family_with_bytes(nullptr, (uint8_t *) store->Data(),
275
- store->ByteLength());
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
- auto isolate = args.GetIsolate();
284
- auto context = isolate->GetCurrentContext();
285
- auto ptr = args[0].As<v8::BigInt>()->Int64Value();
286
-
287
- auto context_2d = static_cast<CanvasRenderingContext2D *>((void *) ptr);
288
-
289
- auto ret = CanvasRenderingContext2DImpl::NewInstance(isolate, new CanvasRenderingContext2DImpl(
290
- context_2d));
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
- float x;
298
- float y;
299
- float width;
300
- float height;
458
+ float x;
459
+ float y;
460
+ float width;
461
+ float height;
301
462
  };
302
463
 
303
464
  struct ImageBitmapData {
304
- char *error_;
305
- const ImageAsset *asset_;
306
- bool done_;
307
- v8::Isolate *isolate_;
308
- std::shared_ptr<v8::Persistent<v8::ArrayBufferView>> data_;
309
-
310
- ~ImageBitmapData() {
311
- if (error_ != nullptr) {
312
- canvas_native_string_destroy(error_);
313
- error_ = nullptr;
314
- }
315
-
316
- data_->Reset();
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
- auto count = args.Length();
323
- auto isolate = args.GetIsolate();
324
- auto context = isolate->GetCurrentContext();
325
-
326
- auto image = args[0];
327
- auto sx_or_options = args[1];
328
- auto sy = args[2];
329
- auto sw = args[3];
330
- auto sh = args[4];
331
-
332
- auto len = count - 1;
333
- auto cb = args[count - 1];
334
-
335
- if ((len == 1 && !image->IsObject()) || image->IsFunction()) {
336
- isolate->ThrowError("Illegal constructor");
337
- return;
338
- }
339
-
340
- Options options;
341
-
342
- if (len == 0) {
343
- isolate->ThrowError("Illegal constructor");
344
- return;
345
- }
346
-
347
- if (!cb->IsObject() && !cb->IsFunction()) {
348
- isolate->ThrowError("Illegal constructor");
349
- return;
350
- }
351
-
352
-
353
- if (image->IsNullOrUndefined()) {
354
- v8::Local<v8::Value> ret[2] = {ConvertToV8String(isolate, "Failed to load image"),
355
- v8::Null(isolate)};
356
-
357
- cb.As<v8::Function>()->Call(context, context->Global(), 2, ret);
358
- return;
359
- }
360
-
361
- if (len >= 4 && (sw->IsNumber() && sw->IsNumber() == 0)) {
362
-
363
- v8::Local<v8::Value> ret[2] = {ConvertToV8String(isolate,
364
- "Failed to execute 'createImageBitmap' : The crop rect width is 0"),
365
- v8::Null(isolate)};
366
-
367
- cb.As<v8::Function>()->Call(context, context->Global(), 2, ret);
368
-
369
- return;
370
- }
371
- if (len >= 5 && (sh->IsNumber() && sh->IsNumber() == 0)) {
372
- v8::Local<v8::Value> ret[2] = {ConvertToV8String(isolate,
373
- "Failed to execute 'createImageBitmap' : The crop rect height is 0"),
374
- v8::Null(isolate)};
375
-
376
- cb.As<v8::Function>()->Call(context, context->Global(), 2, ret);
377
- return;
378
- }
379
-
380
- if (image->IsObject()) {
381
- auto imageObject = image.As<v8::Object>();
382
- auto isArrayBuffer = imageObject->IsArrayBuffer();
383
- auto IsArrayBufferView = imageObject->IsArrayBufferView();
384
- std::optional<Rect> rect = std::nullopt;
385
-
386
- if (isArrayBuffer || IsArrayBufferView) {
387
- if ((len == 1 || len == 2) || (len == 5 || len == 6)) {
388
- if (len == 2) {
389
- options = ImageBitmapImpl::HandleOptions(isolate, args[1]);
390
- }
391
-
392
- if (len == 6) {
393
- options = ImageBitmapImpl::HandleOptions(isolate, args[5]);
394
- }
395
-
396
- auto cbFunc = args[count - 1].As<v8::Function>();
397
-
398
- if (isArrayBuffer) {
399
- auto arrayBuffer = imageObject.As<v8::ArrayBuffer>();
400
- auto size = arrayBuffer->ByteLength();
401
- imageObject = v8::Uint8Array::New(arrayBuffer, 0, size);
402
- }
403
-
404
- auto ta = imageObject.As<v8::ArrayBufferView>();
405
-
406
- auto image_bitmap_async_data = new ImageBitmapData();
407
- image_bitmap_async_data->isolate_ = isolate;
408
- image_bitmap_async_data->data_ = std::make_shared<v8::Persistent<v8::ArrayBufferView>>(
409
- isolate, ta);
410
-
411
- auto callback = new AsyncCallback(isolate, cbFunc, [](bool done, void *data) {
412
- if (data == nullptr) { return; }
413
- auto async_data = static_cast<AsyncCallback *>(data);
414
- auto func = async_data->inner_.get();
415
- if (func != nullptr && func->isolate_ != nullptr) {
416
- v8::Isolate *isolate = func->isolate_;
417
- v8::Locker locker(isolate);
418
- v8::Isolate::Scope isolate_scope(isolate);
419
- v8::HandleScope handle_scope(isolate);
420
- v8::Local<v8::Function> callback = func->callback_.Get(
421
- isolate);
422
- v8::Local<v8::Context> context = callback->GetCreationContextChecked();
423
- v8::Context::Scope context_scope(context);
424
-
425
- if (func->data != nullptr) {
426
- auto asset_data = static_cast<ImageBitmapData *>(func->data);
427
-
428
- auto bitmap = new ImageBitmapImpl(asset_data->asset_);
429
- auto external = v8::External::New(isolate, bitmap);
430
-
431
- auto ret = ImageBitmapImpl::NewInstance(isolate, external);
432
-
433
- v8::Local<v8::Value> args[2] = {
434
- v8::Null(isolate), ret};
435
-
436
-
437
- callback->Call(context, context->Global(),
438
- 2,
439
- args); // ignore JS return value
440
-
441
- delete asset_data;
442
-
443
- } else {
444
- v8::Local<v8::Value> args[1] = {
445
- v8::Null(isolate)};
446
-
447
- callback->Call(context, context->Global(),
448
- 1,
449
- args); // ignore JS return value
450
- }
451
-
452
- }
453
- delete static_cast<AsyncCallback *>(data);
454
- });
455
-
456
- callback->inner_->data = image_bitmap_async_data;
457
- callback->prepare();
458
- auto store = ta->Buffer()->GetBackingStore();
459
- auto offset = ta->ByteOffset();
460
-
461
- std::thread thread(
462
- [callback, image_bitmap_async_data, offset, options, rect](
463
- std::shared_ptr<v8::BackingStore> store) {
464
-
465
- auto data = static_cast<uint8_t *>(store->Data()) + offset;
466
- auto size = store->ByteLength();
467
-
468
- auto asset = canvas_native_image_asset_create();
469
- bool done;
470
- if (rect.has_value()) {
471
-
472
- done = canvas_native_image_bitmap_create_from_encoded_bytes_src_rect_with_output(
473
- data, size,
474
- rect.value().x,
475
- rect.value().y,
476
- rect.value().width,
477
- rect.value().height,
478
- options.flipY,
479
- options.premultiplyAlpha,
480
- options.colorSpaceConversion,
481
- options.resizeQuality,
482
- options.resizeWidth,
483
- options.resizeHeight, asset);
484
- } else {
485
- done = canvas_native_image_bitmap_create_from_encoded_bytes_with_output(
486
- data, size,
487
- options.flipY,
488
- options.premultiplyAlpha,
489
- options.colorSpaceConversion,
490
- options.resizeQuality,
491
- options.resizeWidth,
492
- options.resizeHeight, asset);
493
- }
494
- if (callback != nullptr) {
495
- image_bitmap_async_data->asset_ = asset;
496
- callback->execute(done);
497
- }
498
-
499
- }, std::move(store));
500
- thread.detach();
501
-
502
- return;
503
- }
504
- }
505
- }
506
-
507
- auto type = ObjectWrapperImpl::GetNativeType(image);
508
-
509
- if (len == 1 || len == 2) {
510
- if (len == 2) {
511
- options = ImageBitmapImpl::HandleOptions(isolate, args[1]);
512
- }
513
-
514
- v8::Local<v8::Value> retArgs[2];
515
- retArgs[0] = v8::Null(isolate);
516
-
517
- switch (type) {
518
- case NativeType::ImageAsset: {
519
- auto image_asset = ImageAssetImpl::GetPointer(image.As<v8::Object>());
520
- auto ret = canvas_native_image_bitmap_create_from_asset(
521
- image_asset->GetImageAsset(),
522
- options.flipY,
523
- options.premultiplyAlpha,
524
- options.colorSpaceConversion,
525
- options.resizeQuality,
526
- options.resizeWidth,
527
- options.resizeHeight);
528
-
529
-
530
- auto bitmap = new ImageBitmapImpl(ret);
531
- auto data = v8::External::New(isolate, bitmap);
532
-
533
- auto object = ImageBitmapImpl::NewInstance(isolate, data);
534
-
535
- retArgs[1] = object;
536
- }
537
- break;
538
- case NativeType::ImageBitmap: {
539
- auto image_bitmap = ImageBitmapImpl::GetPointer(image.As<v8::Object>());
540
- auto ret = canvas_native_image_bitmap_create_from_asset(
541
- image_bitmap->GetImageAsset(),
542
- options.flipY,
543
- options.premultiplyAlpha,
544
- options.colorSpaceConversion,
545
- options.resizeQuality,
546
- options.resizeWidth,
547
- options.resizeHeight);
548
-
549
-
550
- auto bitmap = new ImageBitmapImpl(ret);
551
- auto data = v8::External::New(isolate, bitmap);
552
- auto object = ImageBitmapImpl::NewInstance(isolate, data);
553
-
554
- retArgs[1] = object;
555
-
556
- }
557
- break;
558
- default:
559
- break;
560
- }
561
-
562
- cb.As<v8::Function>()->Call(context, context->Global(), 2, retArgs);
563
-
564
- return;
565
- } else if (len == 5 || len == 6) {
566
-
567
- if (len == 6) {
568
- options = ImageBitmapImpl::HandleOptions(isolate, args[5]);
569
- }
570
-
571
- v8::Local<v8::Value> retArgs[2];
572
- retArgs[0] = v8::Null(isolate);
573
-
574
-
575
- switch (type) {
576
- case NativeType::ImageAsset: {
577
- auto image_asset = ImageBitmapImpl::GetPointer(image.As<v8::Object>());
578
- auto ret = canvas_native_image_bitmap_create_from_asset_src_rect(
579
- image_asset->GetImageAsset(),
580
- (float) sx_or_options->NumberValue(context).ToChecked(),
581
- (float) sy->NumberValue(context).ToChecked(),
582
- (float) sw->NumberValue(context).ToChecked(),
583
- (float) sh->NumberValue(context).ToChecked(),
584
- options.flipY,
585
- options.premultiplyAlpha,
586
- options.colorSpaceConversion,
587
- options.resizeQuality,
588
- options.resizeWidth,
589
- options.resizeHeight);
590
-
591
-
592
- auto bitmap = new ImageBitmapImpl(ret);
593
- auto data = v8::External::New(isolate, bitmap);
594
- auto object = ImageBitmapImpl::NewInstance(isolate, data);
595
-
596
- retArgs[1] = object;
597
- }
598
- break;
599
- case NativeType::ImageBitmap: {
600
- auto image_bitmap = ImageBitmapImpl::GetPointer(image.As<v8::Object>());
601
- auto ret = canvas_native_image_bitmap_create_from_asset_src_rect(
602
- image_bitmap->GetImageAsset(),
603
- (float) sx_or_options->NumberValue(context).ToChecked(),
604
- (float) sy->NumberValue(context).ToChecked(),
605
- (float) sw->NumberValue(context).ToChecked(),
606
- (float) sh->NumberValue(context).ToChecked(),
607
- options.flipY,
608
- options.premultiplyAlpha,
609
- options.colorSpaceConversion,
610
- options.resizeQuality,
611
- options.resizeWidth,
612
- options.resizeHeight);
613
-
614
-
615
- auto bitmap = new ImageBitmapImpl(ret);
616
- auto data = v8::External::New(isolate, bitmap);
617
- auto object = ImageBitmapImpl::NewInstance(isolate, data);
618
-
619
- retArgs[1] = object;
620
-
621
- }
622
- break;
623
- default:
624
- break;
625
- }
626
-
627
-
628
- cb.As<v8::Function>()->Call(context, context->Global(), 2, retArgs);
629
-
630
- return;
631
- }
632
-
633
-
634
- args.GetReturnValue().SetUndefined();
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
- auto isolate = args.GetIsolate();
640
- auto context = isolate->GetCurrentContext();
641
- auto ptr = args[0]->ToBigInt(context).ToLocalChecked()->Int64Value();
642
-
643
- auto context_2d = canvas_native_context_create_with_pointer(ptr);
644
-
645
- auto ret = CanvasRenderingContext2DImpl::NewInstance(isolate, new CanvasRenderingContext2DImpl(
646
- context_2d));
647
- args.GetReturnValue().Set(ret);
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
- char *error_;
652
- U8Buffer *data;
653
-
654
- ~FileData() {
655
- if (error_ != nullptr) {
656
- canvas_native_string_destroy(error_);
657
- error_ = nullptr;
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
- auto isolate = args.GetIsolate();
664
- auto file = ConvertFromV8String(isolate, args[0]);
665
- auto cbFunc = args[1].As<v8::Function>();
666
-
667
- auto callback = new AsyncCallback(isolate, cbFunc, [](bool done, void *data) {
668
- if (data == nullptr) { return; }
669
- auto async_data = static_cast<AsyncCallback *>(data);
670
- auto func = async_data->inner_.get();
671
- if (func != nullptr && func->isolate_ != nullptr) {
672
- v8::Isolate *isolate = func->isolate_;
673
- v8::Locker locker(isolate);
674
- v8::Isolate::Scope isolate_scope(isolate);
675
- v8::HandleScope handle_scope(isolate);
676
- v8::Local<v8::Function> callback = func->callback_.Get(
677
- isolate);
678
- v8::Local<v8::Context> context = callback->GetCreationContextChecked();
679
- v8::Context::Scope context_scope(context);
680
-
681
- if (func->data != nullptr) {
682
- auto file_data = static_cast<FileData *>(func->data);
683
-
684
- v8::Local<v8::Value> args[2];
685
-
686
- if (done) {
687
- args[0] = v8::Null(isolate);
688
-
689
- auto buf = canvas_native_u8_buffer_get_bytes_mut(file_data->data);
690
- auto size = (size_t) canvas_native_u8_buffer_get_length(file_data->data);
691
-
692
- auto store = v8::ArrayBuffer::NewBackingStore((void *) buf, size,
693
- [](void *data,
694
- size_t length,
695
- void *deleter_data) {
696
- if (deleter_data !=
697
- nullptr) {
698
- delete static_cast<FileData *>(deleter_data);
699
-
700
- }
701
- },
702
- func->data);
703
-
704
- auto ret = v8::Object::New(isolate);
705
- auto buffer = v8::ArrayBuffer::New(isolate, std::move(store));
706
- ret->Set(context, ConvertToV8String(isolate, "buffer"), buffer);
707
- auto mime = canvas_native_helper_get_mime(buf, size);
708
- if (mime != nullptr) {
709
- if (mime->mime_type != nullptr) {
710
- ret->Set(context, ConvertToV8String(isolate, "mime"),
711
- ConvertToV8String(isolate, mime->mime_type));
712
- }
713
- if (mime->extension != nullptr) {
714
- ret->Set(context, ConvertToV8String(isolate, "extension"),
715
- ConvertToV8String(isolate, mime->extension));
716
- }
717
- canvas_native_helper_release_mime(mime);
718
- }
719
-
720
- args[1] = ret;
721
- } else {
722
- auto error = file_data->error_;
723
- args[0] = v8::Exception::Error(ConvertToV8String(isolate, error));
724
- args[1] = v8::Null(isolate);
725
- delete file_data;
726
- }
727
-
728
- v8::TryCatch tc(isolate);
729
- v8::Local<v8::Value> result;
730
- if (!callback->Call(context, context->Global(), 2, args).ToLocal(
731
- &result)) {
732
- if (tc.HasCaught()) {
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
- delete async_data;
756
-
757
- }
758
- }
759
- });
760
-
761
- callback->prepare();
762
-
763
- std::thread thread(
764
- [callback, file]() {
765
- bool done = false;
766
- auto ret = canvas_native_helper_read_file(file.c_str());
767
-
768
- if (!canvas_native_helper_read_file_has_error(ret)) {
769
- auto buf = canvas_native_helper_read_file_take_data(ret);
770
- callback->inner_->data = new FileData{nullptr, buf};
771
- done = true;
772
- } else {
773
- auto error = canvas_native_helper_read_file_get_error(ret);
774
- callback->inner_->data = new FileData{const_cast<char *>(error), nullptr};
775
- }
776
- canvas_native_helper_release(ret);
777
- callback->execute(done);
778
- });
779
-
780
- thread.detach();
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
- auto isolate = args.GetIsolate();
788
- auto file = ConvertFromV8String(isolate, args[0]);
789
- auto cbFunc = args[1].As<v8::Function>();
790
-
791
-
792
- auto callback = new AsyncCallback(isolate, cbFunc, [](bool done, void *data) {
793
- if (data == nullptr) { return; }
794
- auto async_data = static_cast<AsyncCallback *>(data);
795
- auto func = async_data->inner_.get();
796
- if (func != nullptr && func->isolate_ != nullptr) {
797
- v8::Isolate *isolate = func->isolate_;
798
- v8::Locker locker(isolate);
799
- v8::Isolate::Scope isolate_scope(isolate);
800
- v8::HandleScope handle_scope(isolate);
801
- v8::Local<v8::Function> callback = func->callback_.Get(
802
- isolate);
803
- v8::Local<v8::Context> context = callback->GetCreationContextChecked();
804
- v8::Context::Scope context_scope(context);
805
-
806
- if (func->data != nullptr) {
807
- auto file_data = static_cast<FileData *>(func->data);
808
-
809
- v8::Local<v8::Value> args[2];
810
-
811
- if (done) {
812
- args[0] = v8::Null(isolate);
813
-
814
- auto buf = (void *) canvas_native_u8_buffer_get_bytes_mut(file_data->data);
815
- auto size = (size_t) canvas_native_u8_buffer_get_length(file_data->data);
816
-
817
- auto store = v8::ArrayBuffer::NewBackingStore(buf, size,
818
- [](void *data,
819
- size_t length,
820
- void *deleter_data) {
821
- if (deleter_data !=
822
- nullptr) {
823
- delete static_cast<FileData *>(deleter_data);
824
-
825
- }
826
- },
827
- func->data);
828
-
829
- args[1] = v8::ArrayBuffer::New(isolate, std::move(store));
830
- } else {
831
- auto error = file_data->error_;
832
- args[0] = v8::Exception::Error(ConvertToV8String(isolate, error));
833
- args[1] = v8::Null(isolate);
834
- delete file_data;
835
- }
836
-
837
- v8::TryCatch tc(isolate);
838
- v8::Local<v8::Value> result;
839
- if (!callback->Call(context, context->Global(), 2, args).ToLocal(
840
- &result)) {
841
- if (tc.HasCaught()) {
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
- delete async_data;
865
-
866
- }
867
- }
868
- });
869
-
870
- callback->prepare();
871
-
872
- std::thread thread(
873
- [callback, file]() {
874
- bool done = false;
875
- auto ret = canvas_native_helper_read_file(file.c_str());
876
-
877
- if (!canvas_native_helper_read_file_has_error(ret)) {
878
- auto buf = canvas_native_helper_read_file_take_data(ret);
879
- callback->inner_->data = new FileData{nullptr, buf};
880
- done = true;
881
- } else {
882
- auto error = canvas_native_helper_read_file_get_error(ret);
883
- callback->inner_->data = new FileData{const_cast<char *>(error), nullptr};
884
- }
885
- canvas_native_helper_release(ret);
886
- callback->execute(done);
887
- });
888
-
889
- thread.detach();
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
- auto options = GLOptions();
898
- options.parseGLOptions(args);
899
-
900
- if (options.version != 1) {
901
- args.GetReturnValue().SetNull();
902
- return;
903
- }
904
-
905
- auto isolate = args.GetIsolate();
906
- auto context = isolate->GetCurrentContext();
907
-
908
-
909
- auto count = args.Length();
910
- if (count == 6) {
911
- auto ctx = args[1].As<v8::BigInt>()->Int64Value();
912
- auto webgl = (WebGLState *) ctx;
913
-
914
- auto renderingContext = WebGLRenderingContext::NewInstance(isolate,
915
- new WebGLRenderingContext(
916
- webgl));
917
-
918
- args.GetReturnValue().Set(renderingContext);
919
- return;
920
- } else if (count == 7) {
921
- auto width = args[1]->NumberValue(context).ToChecked();
922
- auto height = args[2]->NumberValue(context).ToChecked();
923
- auto ctx = canvas_native_webgl_create_no_window(
924
- (int32_t) width,
925
- (int32_t) height,
926
- options.version,
927
- options.alpha,
928
- options.antialias,
929
- options.depth,
930
- options.failIfMajorPerformanceCaveat,
931
- options.powerPreference,
932
- options.premultipliedAlpha,
933
- options.preserveDrawingBuffer,
934
- options.stencil,
935
- options.desynchronized,
936
- options.xrCompatible,
937
- false
938
- );
939
-
940
- auto renderingContext = WebGLRenderingContext::NewInstance(isolate,
941
- new WebGLRenderingContext(
942
- ctx));
943
-
944
- args.GetReturnValue().Set(renderingContext);
945
- return;
946
-
947
- } else {
948
- auto width = (int32_t) args[1]->NumberValue(context).ToChecked();
949
- auto height = (int32_t) args[2]->NumberValue(context).ToChecked();
950
-
951
- auto ctx = canvas_native_webgl_create_no_window(
952
- width,
953
- height,
954
- options.version,
955
- options.alpha,
956
- options.antialias,
957
- options.depth,
958
- options.failIfMajorPerformanceCaveat,
959
- options.powerPreference,
960
- options.premultipliedAlpha,
961
- options.preserveDrawingBuffer,
962
- options.stencil,
963
- options.desynchronized,
964
- options.xrCompatible,
965
- false
966
- );
967
-
968
- auto renderingContext = WebGLRenderingContext::NewInstance(isolate,
969
- new WebGLRenderingContext(
970
- ctx));
971
-
972
- args.GetReturnValue().Set(renderingContext);
973
- return;
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
- auto options = GLOptions();
981
- options.parseGLOptions(args);
982
-
983
- if (options.version != 2) {
984
- args.GetReturnValue().SetNull();
985
- return;
986
- }
987
-
988
-
989
- auto isolate = args.GetIsolate();
990
- auto context = isolate->GetCurrentContext();
991
-
992
-
993
- auto count = args.Length();
994
- if (count == 6) {
995
- auto ctx = args[1].As<v8::BigInt>()->Int64Value();
996
- auto webgl = (WebGLState *) ctx;
997
- auto renderingContext = WebGL2RenderingContext::NewInstance(isolate,
998
- new WebGL2RenderingContext(
999
- webgl,
1000
- WebGLRenderingVersion::V2));
1001
-
1002
- args.GetReturnValue().Set(renderingContext);
1003
- return;
1004
-
1005
- } else if (count ==
1006
- 7) {
1007
- auto width = args[1]->NumberValue(context).ToChecked();
1008
- auto height = args[2]->NumberValue(context).ToChecked();
1009
- auto ctx = canvas_native_webgl_create_no_window(
1010
- (int32_t) width,
1011
- (int32_t) height,
1012
- options.version,
1013
- options.alpha,
1014
- options.antialias,
1015
- options.depth,
1016
- options.failIfMajorPerformanceCaveat,
1017
- options.powerPreference,
1018
- options.premultipliedAlpha,
1019
- options.preserveDrawingBuffer,
1020
- options.stencil,
1021
- options.desynchronized,
1022
- options.xrCompatible,
1023
- false
1024
- );
1025
- auto renderingContext = WebGL2RenderingContext::NewInstance(isolate,
1026
- new WebGL2RenderingContext(
1027
- ctx,
1028
- WebGLRenderingVersion::V2));
1029
-
1030
- args.GetReturnValue().Set(renderingContext);
1031
- return;
1032
-
1033
- } else {
1034
- auto width = (int32_t) args[1]->NumberValue(context).ToChecked();
1035
- auto height = (int32_t) args[2]->NumberValue(context).ToChecked();
1036
- auto ctx = canvas_native_webgl_create_no_window(
1037
- width,
1038
- height,
1039
- options.version,
1040
- options.alpha,
1041
- options.antialias,
1042
- options.depth,
1043
- options.failIfMajorPerformanceCaveat,
1044
- options.powerPreference,
1045
- options.premultipliedAlpha,
1046
- options.preserveDrawingBuffer,
1047
- options.stencil,
1048
- options.desynchronized,
1049
- options.xrCompatible,
1050
- false
1051
- );
1052
-
1053
- auto renderingContext = WebGL2RenderingContext::NewInstance(isolate,
1054
- new WebGL2RenderingContext(
1055
- ctx,
1056
- WebGLRenderingVersion::V2));
1057
-
1058
- args.GetReturnValue().Set(renderingContext);
1059
- return;
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
- auto isolate = args.GetIsolate();
1066
- auto context = isolate->GetCurrentContext();
1067
- auto ptr = args[0]->ToBigInt(context).ToLocalChecked()->Int64Value();
1068
-
1069
- auto wgpu = static_cast<CanvasGPUCanvasContext *>((void *) ptr);
1070
-
1071
- auto ret = GPUCanvasContextImpl::NewInstance(isolate, new GPUCanvasContextImpl(
1072
- wgpu));
1073
- args.GetReturnValue().Set(ret);
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
  }