@nativescript/canvas 2.0.0-beta.11 → 2.0.0-beta.12

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 (56) hide show
  1. package/Canvas/common.d.ts +8 -5
  2. package/Canvas/common.js +64 -40
  3. package/Canvas/common.js.map +1 -1
  4. package/Canvas/index.android.js +33 -70
  5. package/Canvas/index.android.js.map +1 -1
  6. package/Canvas/index.ios.d.ts +1 -0
  7. package/Canvas/index.ios.js +43 -48
  8. package/Canvas/index.ios.js.map +1 -1
  9. package/Canvas2D/CanvasRenderingContext2D/index.js +1 -10
  10. package/Canvas2D/CanvasRenderingContext2D/index.js.map +1 -1
  11. package/Canvas2D/ImageData/index.js +4 -6
  12. package/Canvas2D/ImageData/index.js.map +1 -1
  13. package/WebGL/WebGLRenderingContext/index.js +43 -26
  14. package/WebGL/WebGLRenderingContext/index.js.map +1 -1
  15. package/WebGL2/WebGL2RenderingContext/index.js +0 -2
  16. package/WebGL2/WebGL2RenderingContext/index.js.map +1 -1
  17. package/package.json +1 -1
  18. package/platforms/android/canvas-release.aar +0 -0
  19. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/CanvasNative +0 -0
  20. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Headers/CanvasNative-Swift.h +8 -10
  21. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Headers/canvas_ios.h +4 -4
  22. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Headers/canvas_native.h +35 -16
  23. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Info.plist +0 -0
  24. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Modules/CanvasNative.swiftmodule/Project/arm64-apple-ios.swiftsourceinfo +0 -0
  25. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios.abi.json +286 -316
  26. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios.private.swiftinterface +8 -10
  27. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios.swiftinterface +8 -10
  28. package/platforms/ios/CanvasNative.xcframework/ios-arm64/dSYMs/CanvasNative.framework.dSYM/Contents/Resources/DWARF/CanvasNative +0 -0
  29. package/platforms/ios/CanvasNative.xcframework/ios-arm64/dSYMs/CanvasNative.framework.dSYM/Contents/Resources/Relocations/aarch64/CanvasNative.yml +640 -644
  30. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/CanvasNative +0 -0
  31. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Headers/CanvasNative-Swift.h +16 -20
  32. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Headers/canvas_ios.h +4 -4
  33. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Headers/canvas_native.h +35 -16
  34. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Info.plist +0 -0
  35. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/Project/arm64-apple-ios-simulator.swiftsourceinfo +0 -0
  36. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/Project/x86_64-apple-ios-simulator.swiftsourceinfo +0 -0
  37. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios-simulator.abi.json +286 -316
  38. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios-simulator.private.swiftinterface +8 -10
  39. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios-simulator.swiftinterface +8 -10
  40. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/x86_64-apple-ios-simulator.abi.json +286 -316
  41. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/x86_64-apple-ios-simulator.private.swiftinterface +8 -10
  42. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/x86_64-apple-ios-simulator.swiftinterface +8 -10
  43. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/_CodeSignature/CodeResources +27 -27
  44. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/dSYMs/CanvasNative.framework.dSYM/Contents/Resources/DWARF/CanvasNative +0 -0
  45. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/dSYMs/CanvasNative.framework.dSYM/Contents/Resources/Relocations/aarch64/CanvasNative.yml +661 -662
  46. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/dSYMs/CanvasNative.framework.dSYM/Contents/Resources/Relocations/x86_64/CanvasNative.yml +646 -641
  47. package/platforms/ios/src/cpp/CanvasJSIModule.cpp +297 -397
  48. package/platforms/ios/src/cpp/Helpers.h +3 -4
  49. package/platforms/ios/src/cpp/ImageAssetImpl.cpp +8 -27
  50. package/platforms/ios/src/cpp/ImageAssetImpl.h +3 -3
  51. package/platforms/ios/src/cpp/URLImpl.cpp +73 -0
  52. package/platforms/ios/src/cpp/canvas2d/CanvasRenderingContext2DImpl.cpp +4 -4
  53. package/platforms/ios/src/cpp/webgl/WebGLRenderingContext.cpp +101 -120
  54. package/platforms/ios/src/cpp/webgl2/WebGL2RenderingContext.cpp +1766 -1659
  55. package/platforms/ios/src/cpp/PerIsolateData.cpp +0 -49
  56. package/platforms/ios/src/cpp/PerIsolateData.h +0 -54
@@ -7,7 +7,121 @@
7
7
  #include "JSIRuntime.h"
8
8
  #include "JSIReadFileCallback.h"
9
9
  #include "Helpers.h"
10
- #include "PerIsolateData.h"
10
+
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
+
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
+ }
124
+ };
11
125
 
12
126
  void CanvasJSIModule::install(v8::Isolate *isolate) {
13
127
 
@@ -37,45 +151,39 @@ void CanvasJSIModule::install(v8::Isolate *isolate) {
37
151
  TextMetricsImpl::Init(canvasMod, isolate);
38
152
  URLImpl::Init(canvasMod, isolate);
39
153
 
40
- // always use the last slot
41
- auto lastSlot = isolate->GetNumberOfDataSlots() - 1;
42
- auto data = new PerIsolateData(isolate);
43
- isolate->SetData(lastSlot, data);
44
-
45
- v8Global->Set(context, ConvertToV8String(isolate, "CanvasModule"), canvasMod);
154
+ v8Global->Set(context, ConvertToV8String(isolate, "CanvasModule"), canvasMod).FromJust();
46
155
  canvasMod->Set(context, ConvertToV8String(isolate, "create2DContext"),
47
156
  v8::FunctionTemplate::New(isolate, &Create2DContext)->GetFunction(
48
- context).ToLocalChecked());
157
+ context).ToLocalChecked()).FromJust();
49
158
  canvasMod->Set(context, ConvertToV8String(isolate, "createImageBitmap"),
50
159
  v8::FunctionTemplate::New(isolate, &CreateImageBitmap)->GetFunction(
51
- context).ToLocalChecked());
160
+ context).ToLocalChecked()).FromJust();
52
161
  canvasMod->Set(context, ConvertToV8String(isolate, "create2DContextWithPointer"),
53
162
  v8::FunctionTemplate::New(isolate, &Create2DContextWithPointer)->GetFunction(
54
- context).ToLocalChecked());
163
+ context).ToLocalChecked()).FromJust();
55
164
  canvasMod->Set(context, ConvertToV8String(isolate, "readFile"),
56
165
  v8::FunctionTemplate::New(isolate, &ReadFile)->GetFunction(
57
- context).ToLocalChecked());
166
+ context).ToLocalChecked()).FromJust();
58
167
 
59
168
  canvasMod->Set(context, ConvertToV8String(isolate, "createWebGLContext"),
60
169
  v8::FunctionTemplate::New(isolate, &CreateWebGLContext)->GetFunction(
61
- context).ToLocalChecked());
170
+ context).ToLocalChecked()).FromJust();
62
171
 
63
172
  canvasMod->Set(context, ConvertToV8String(isolate, "createWebGL2Context"),
64
173
  v8::FunctionTemplate::New(isolate, &CreateWebGL2Context)->GetFunction(
65
- context).ToLocalChecked());
174
+ context).ToLocalChecked()).FromJust();
66
175
 
67
176
 
68
177
  canvasMod->Set(context, ConvertToV8String(isolate, "__addFontFamily"),
69
178
  v8::FunctionTemplate::New(isolate, &AddFontFamily)->GetFunction(
70
- context).ToLocalChecked());
179
+ context).ToLocalChecked()).FromJust();
71
180
 
72
181
  global->Set(context,
73
- ConvertToV8String(isolate, "CanvasModule"), canvasMod);
182
+ ConvertToV8String(isolate, "CanvasModule"), canvasMod).FromJust();
74
183
 
75
184
  }
76
185
  }
77
186
 
78
-
79
187
  void CanvasJSIModule::AddFontFamily(const v8::FunctionCallbackInfo<v8::Value> &args) {
80
188
  auto isolate = args.GetIsolate();
81
189
  auto context = isolate->GetCurrentContext();
@@ -807,7 +915,7 @@ void CanvasJSIModule::CreateImageBitmap(const v8::FunctionCallbackInfo<v8::Value
807
915
  }
808
916
  }
809
917
 
810
- auto type = GetNativeType( image);
918
+ auto type = GetNativeType(image);
811
919
 
812
920
  if (len == 1 || len == 2) {
813
921
  if (len == 2) {
@@ -1190,404 +1298,196 @@ void CanvasJSIModule::ReadFile(const v8::FunctionCallbackInfo<v8::Value> &args)
1190
1298
  }
1191
1299
 
1192
1300
  void CanvasJSIModule::CreateWebGLContext(const v8::FunctionCallbackInfo<v8::Value> &args) {
1193
- auto configValue = args[0];
1194
- auto isolate = args.GetIsolate();
1195
- auto context = isolate->GetCurrentContext();
1196
- if (!configValue->IsNullOrUndefined() && configValue->IsObject()) {
1197
- auto config = configValue.As<v8::Object>();
1198
- std::string version("none");
1199
- auto alpha = true;
1200
- auto antialias = true;
1201
- auto depth = true;
1202
- auto fail_if_major_performance_caveat = false;
1203
- std::string power_preference("default");
1204
- auto premultiplied_alpha = true;
1205
- auto preserve_drawing_buffer = false;
1206
- auto stencil = false;
1207
- auto desynchronized = false;
1208
- auto xr_compatible = false;
1209
-
1210
- auto last = isolate->GetNumberOfDataSlots() - 1;
1211
- auto data = isolate->GetData(last);
1212
-
1213
- if (data != nullptr) {
1214
- auto consts = static_cast<PerIsolateData *>(data);
1215
-
1216
- v8::Local<v8::Value> versionValue;
1217
-
1218
- config->Get(context, consts->VERSION_PERSISTENT->Get(isolate)).ToLocal(&versionValue);
1219
-
1220
- if (!versionValue.IsEmpty() && versionValue->IsString()) {
1221
- version = ConvertFromV8String(isolate, versionValue);
1222
- }
1223
-
1224
- v8::Local<v8::Value> alphaValue;
1225
-
1226
- config->Get(context, consts->ALPHA_PERSISTENT->Get(isolate)).ToLocal(&alphaValue);
1227
- if (!alphaValue.IsEmpty() && alphaValue->IsBoolean()) {
1228
- alpha = alphaValue->BooleanValue(isolate);
1229
- }
1230
-
1231
- v8::Local<v8::Value> antialiasValue;
1232
- config->Get(context, consts->ANTIALIAS_PERSISTENT->Get(isolate)).ToLocal(
1233
- &antialiasValue);
1234
- if (!antialiasValue.IsEmpty() && antialiasValue->IsBoolean()) {
1235
- antialias = antialiasValue->BooleanValue(isolate);
1236
- }
1237
-
1238
- v8::Local<v8::Value> failIfMajorPerformanceCaveatValue;
1239
- config->Get(context,
1240
- consts->FAIL_IF_MAJOR_PERFORMANCE_CAVEAT_PERSISTENT->Get(isolate)).ToLocal(
1241
- &failIfMajorPerformanceCaveatValue);
1242
- if (!failIfMajorPerformanceCaveatValue.IsEmpty() &&
1243
- failIfMajorPerformanceCaveatValue->IsBoolean()) {
1244
- fail_if_major_performance_caveat = failIfMajorPerformanceCaveatValue->BooleanValue(
1245
- isolate);
1246
- }
1247
-
1248
- v8::Local<v8::Value> powerPreferenceValue;
1249
- config->Get(context, consts->POWER_PREFERENCE_PERSISTENT->Get(isolate)).ToLocal(
1250
- &powerPreferenceValue);
1251
- if (!powerPreferenceValue.IsEmpty() && powerPreferenceValue->IsString()) {
1252
- power_preference = ConvertFromV8String(isolate, powerPreferenceValue);
1253
- }
1254
-
1255
- v8::Local<v8::Value> premultipliedAlphaValue;
1256
- config->Get(context,
1257
- consts->PREMULTIPLIED_ALPHA_PERSISTENT->Get(isolate)).ToLocal(
1258
- &premultipliedAlphaValue);
1259
- if (!premultipliedAlphaValue.IsEmpty() && premultipliedAlphaValue->IsBoolean()) {
1260
- premultiplied_alpha = premultipliedAlphaValue->BooleanValue(isolate);
1261
- }
1262
-
1263
- v8::Local<v8::Value> preserveDrawingBufferValue;
1264
- config->Get(context,
1265
- consts->PRESERVE_DRAWING_BUFFER_PERSISTENT->Get(isolate)).ToLocal(
1266
- &preserveDrawingBufferValue);
1267
- if (!preserveDrawingBufferValue.IsEmpty() && preserveDrawingBufferValue->IsBoolean()) {
1268
- preserve_drawing_buffer = preserveDrawingBufferValue->BooleanValue(isolate);
1269
- }
1270
-
1271
- v8::Local<v8::Value> stencilValue;
1272
- config->Get(context, consts->STENCIL_PERSISTENT->Get(isolate)).ToLocal(&stencilValue);
1273
- if (!stencilValue.IsEmpty() && stencilValue->IsBoolean()) {
1274
- stencil = stencilValue->BooleanValue(isolate);
1275
- }
1276
-
1277
- v8::Local<v8::Value> desynchronizedValue;
1278
- config->Get(context, consts->DESYNCHRONIZED_PERSISTENT->Get(isolate)).ToLocal(
1279
- &desynchronizedValue);
1280
- if (!desynchronizedValue.IsEmpty() && desynchronizedValue->IsBoolean()) {
1281
- desynchronized = desynchronizedValue->BooleanValue(isolate);
1282
- }
1283
-
1284
- v8::Local<v8::Value> xrCompatibleValue;
1285
- config->Get(context,
1286
- consts->XR_COMPATIBLE_PERSISTENT->Get(isolate)).ToLocal(&xrCompatibleValue);
1287
- if (!xrCompatibleValue.IsEmpty() && xrCompatibleValue->IsBoolean()) {
1288
- xr_compatible = xrCompatibleValue->BooleanValue(isolate);
1289
- }
1290
- }
1291
-
1292
1301
 
1293
- if (version !=
1294
- "v1") {
1295
- args.GetReturnValue().SetNull();
1296
- return;
1297
- } else {
1298
- auto count = args.Length();
1299
- if (count == 6) {
1300
- auto ctx = args[1].As<v8::BigInt>()->Int64Value();
1301
- // auto density = args[2]->NumberValue(context).ToChecked();
1302
- // auto fontColor = args[3]->NumberValue(context).ToChecked();
1303
- // auto ppi = args[4]->NumberValue(context).ToChecked();
1304
- // auto direction = args[5]->NumberValue(context).ToChecked();
1305
- auto webgl = canvas_native_webgl_create(
1306
- ctx,
1307
- version.c_str(),
1308
- alpha,
1309
- antialias,
1310
- depth,
1311
- fail_if_major_performance_caveat,
1312
- power_preference.c_str(),
1313
- premultiplied_alpha,
1314
- preserve_drawing_buffer,
1315
- stencil,
1316
- desynchronized,
1317
- xr_compatible
1318
- );
1319
-
1320
- auto renderingContext = WebGLRenderingContext::NewInstance(isolate,
1321
- new WebGLRenderingContext(
1322
- webgl));
1323
-
1324
- args.GetReturnValue().Set(renderingContext);
1325
- return;
1326
- } else if (count == 7) {
1327
- auto width = args[1]->NumberValue(context).ToChecked();
1328
- auto height = args[2]->NumberValue(context).ToChecked();
1329
- // auto density = args[3]->NumberValue(context).ToChecked();
1330
- // auto fontColor = args[4]->NumberValue(context).ToChecked();
1331
- // auto ppi = args[5]->NumberValue(context).ToChecked();
1332
- // auto direction = args[6]->NumberValue(context).ToChecked();
1333
- auto ctx = canvas_native_webgl_create_no_window(
1334
- (int32_t) width,
1335
- (int32_t) height,
1336
- version.c_str(),
1337
- alpha,
1338
- antialias,
1339
- depth,
1340
- fail_if_major_performance_caveat,
1341
- power_preference.c_str(),
1342
- premultiplied_alpha,
1343
- preserve_drawing_buffer,
1344
- stencil,
1345
- desynchronized,
1346
- xr_compatible,
1347
- false
1348
- );
1349
-
1350
- auto renderingContext = WebGLRenderingContext::NewInstance(isolate,
1351
- new WebGLRenderingContext(
1352
- ctx));
1353
-
1354
- args.GetReturnValue().Set(renderingContext);
1355
- return;
1302
+ auto options = GLOptions();
1303
+ options.parseGLOptions(args);
1356
1304
 
1357
- } else {
1358
- auto width = (int32_t) args[1]->NumberValue(context).ToChecked();
1359
- auto height = (int32_t) args[2]->NumberValue(context).ToChecked();
1360
-
1361
- auto ctx = canvas_native_webgl_create_no_window(
1362
- width,
1363
- height,
1364
- version.c_str(),
1365
- alpha,
1366
- antialias,
1367
- depth,
1368
- fail_if_major_performance_caveat,
1369
- power_preference.c_str(),
1370
- premultiplied_alpha,
1371
- preserve_drawing_buffer,
1372
- stencil,
1373
- desynchronized,
1374
- xr_compatible,
1375
- false
1376
- );
1377
-
1378
- auto renderingContext = WebGLRenderingContext::NewInstance(isolate,
1379
- new WebGLRenderingContext(
1380
- ctx));
1381
-
1382
- args.GetReturnValue().Set(renderingContext);
1383
- return;
1384
- }
1385
-
1386
- }
1305
+ if (options.version != 1) {
1306
+ args.GetReturnValue().SetNull();
1307
+ return;
1387
1308
  }
1388
- args.GetReturnValue().SetNull();
1389
- }
1390
1309
 
1391
- void CanvasJSIModule::CreateWebGL2Context(const v8::FunctionCallbackInfo<v8::Value> &args) {
1392
- auto configValue = args[0];
1393
1310
  auto isolate = args.GetIsolate();
1394
1311
  auto context = isolate->GetCurrentContext();
1395
- if (!configValue->IsNullOrUndefined() && configValue->IsObject()) {
1396
- auto config = configValue.As<v8::Object>();
1397
- std::string version("none");
1398
- auto alpha = true;
1399
- auto antialias = true;
1400
- auto depth = true;
1401
- auto fail_if_major_performance_caveat = false;
1402
- std::string power_preference("default");
1403
- auto premultiplied_alpha = true;
1404
- auto preserve_drawing_buffer = false;
1405
- auto stencil = false;
1406
- auto desynchronized = false;
1407
- auto xr_compatible = false;
1408
1312
 
1409
1313
 
1410
- auto last = isolate->GetNumberOfDataSlots() - 1;
1411
- auto data = isolate->GetData(last);
1412
-
1413
- if (data != nullptr) {
1414
- auto consts = static_cast<PerIsolateData *>(data);
1415
-
1416
- v8::Local<v8::Value> versionValue;
1417
-
1418
- config->Get(context, consts->VERSION_PERSISTENT->Get(isolate)).ToLocal(&versionValue);
1419
-
1420
- if (!versionValue.IsEmpty() && versionValue->IsString()) {
1421
- version = ConvertFromV8String(isolate, versionValue);
1422
- }
1423
-
1424
- v8::Local<v8::Value> alphaValue;
1425
-
1426
- config->Get(context, consts->ALPHA_PERSISTENT->Get(isolate)).ToLocal(&alphaValue);
1427
- if (!alphaValue.IsEmpty() && alphaValue->IsBoolean()) {
1428
- alpha = alphaValue->BooleanValue(isolate);
1429
- }
1430
-
1431
- v8::Local<v8::Value> antialiasValue;
1432
- config->Get(context, consts->ANTIALIAS_PERSISTENT->Get(isolate)).ToLocal(
1433
- &antialiasValue);
1434
- if (!antialiasValue.IsEmpty() && antialiasValue->IsBoolean()) {
1435
- antialias = antialiasValue->BooleanValue(isolate);
1436
- }
1314
+ auto count = args.Length();
1315
+ if (count == 6) {
1316
+ auto ctx = args[1].As<v8::BigInt>()->Int64Value();
1317
+ auto webgl = canvas_native_webgl_create(
1318
+ ctx,
1319
+ options.version,
1320
+ options.alpha,
1321
+ options.antialias,
1322
+ options.depth,
1323
+ options.failIfMajorPerformanceCaveat,
1324
+ options.powerPreference,
1325
+ options.premultipliedAlpha,
1326
+ options.preserveDrawingBuffer,
1327
+ options.stencil,
1328
+ options.desynchronized,
1329
+ options.xrCompatible
1330
+ );
1331
+
1332
+ auto renderingContext = WebGLRenderingContext::NewInstance(isolate,
1333
+ new WebGLRenderingContext(
1334
+ webgl));
1335
+
1336
+ args.GetReturnValue().Set(renderingContext);
1337
+ return;
1338
+ } else if (count == 7) {
1339
+ auto width = args[1]->NumberValue(context).ToChecked();
1340
+ auto height = args[2]->NumberValue(context).ToChecked();
1341
+ auto ctx = canvas_native_webgl_create_no_window(
1342
+ (int32_t) width,
1343
+ (int32_t) height,
1344
+ options.version,
1345
+ options.alpha,
1346
+ options.antialias,
1347
+ options.depth,
1348
+ options.failIfMajorPerformanceCaveat,
1349
+ options.powerPreference,
1350
+ options.premultipliedAlpha,
1351
+ options.preserveDrawingBuffer,
1352
+ options.stencil,
1353
+ options.desynchronized,
1354
+ options.xrCompatible,
1355
+ false
1356
+ );
1357
+
1358
+ auto renderingContext = WebGLRenderingContext::NewInstance(isolate,
1359
+ new WebGLRenderingContext(
1360
+ ctx));
1361
+
1362
+ args.GetReturnValue().Set(renderingContext);
1363
+ return;
1437
1364
 
1438
- v8::Local<v8::Value> failIfMajorPerformanceCaveatValue;
1439
- config->Get(context,
1440
- consts->FAIL_IF_MAJOR_PERFORMANCE_CAVEAT_PERSISTENT->Get(isolate)).ToLocal(
1441
- &failIfMajorPerformanceCaveatValue);
1442
- if (!failIfMajorPerformanceCaveatValue.IsEmpty() &&
1443
- failIfMajorPerformanceCaveatValue->IsBoolean()) {
1444
- fail_if_major_performance_caveat = failIfMajorPerformanceCaveatValue->BooleanValue(
1445
- isolate);
1446
- }
1365
+ } else {
1366
+ auto width = (int32_t) args[1]->NumberValue(context).ToChecked();
1367
+ auto height = (int32_t) args[2]->NumberValue(context).ToChecked();
1368
+
1369
+ auto ctx = canvas_native_webgl_create_no_window(
1370
+ width,
1371
+ height,
1372
+ options.version,
1373
+ options.alpha,
1374
+ options.antialias,
1375
+ options.depth,
1376
+ options.failIfMajorPerformanceCaveat,
1377
+ options.powerPreference,
1378
+ options.premultipliedAlpha,
1379
+ options.preserveDrawingBuffer,
1380
+ options.stencil,
1381
+ options.desynchronized,
1382
+ options.xrCompatible,
1383
+ false
1384
+ );
1385
+
1386
+ auto renderingContext = WebGLRenderingContext::NewInstance(isolate,
1387
+ new WebGLRenderingContext(
1388
+ ctx));
1389
+
1390
+ args.GetReturnValue().Set(renderingContext);
1391
+ return;
1392
+ }
1393
+ }
1447
1394
 
1448
- v8::Local<v8::Value> powerPreferenceValue;
1449
- config->Get(context, consts->POWER_PREFERENCE_PERSISTENT->Get(isolate)).ToLocal(
1450
- &powerPreferenceValue);
1451
- if (!powerPreferenceValue.IsEmpty() && powerPreferenceValue->IsString()) {
1452
- power_preference = ConvertFromV8String(isolate, powerPreferenceValue);
1453
- }
1395
+ void CanvasJSIModule::CreateWebGL2Context(const v8::FunctionCallbackInfo<v8::Value> &args) {
1454
1396
 
1455
- v8::Local<v8::Value> premultipliedAlphaValue;
1456
- config->Get(context,
1457
- consts->PREMULTIPLIED_ALPHA_PERSISTENT->Get(isolate)).ToLocal(
1458
- &premultipliedAlphaValue);
1459
- if (!premultipliedAlphaValue.IsEmpty() && premultipliedAlphaValue->IsBoolean()) {
1460
- premultiplied_alpha = premultipliedAlphaValue->BooleanValue(isolate);
1461
- }
1462
1397
 
1463
- v8::Local<v8::Value> preserveDrawingBufferValue;
1464
- config->Get(context,
1465
- consts->PRESERVE_DRAWING_BUFFER_PERSISTENT->Get(isolate)).ToLocal(
1466
- &preserveDrawingBufferValue);
1467
- if (!preserveDrawingBufferValue.IsEmpty() && preserveDrawingBufferValue->IsBoolean()) {
1468
- preserve_drawing_buffer = preserveDrawingBufferValue->BooleanValue(isolate);
1469
- }
1398
+ auto options = GLOptions();
1399
+ options.parseGLOptions(args);
1470
1400
 
1471
- v8::Local<v8::Value> stencilValue;
1472
- config->Get(context, consts->STENCIL_PERSISTENT->Get(isolate)).ToLocal(&stencilValue);
1473
- if (!stencilValue.IsEmpty() && stencilValue->IsBoolean()) {
1474
- stencil = stencilValue->BooleanValue(isolate);
1475
- }
1401
+ if (options.version != 2) {
1402
+ args.GetReturnValue().SetNull();
1403
+ return;
1404
+ }
1476
1405
 
1477
- v8::Local<v8::Value> desynchronizedValue;
1478
- config->Get(context, consts->DESYNCHRONIZED_PERSISTENT->Get(isolate)).ToLocal(
1479
- &desynchronizedValue);
1480
- if (!desynchronizedValue.IsEmpty() && desynchronizedValue->IsBoolean()) {
1481
- desynchronized = desynchronizedValue->BooleanValue(isolate);
1482
- }
1483
1406
 
1484
- v8::Local<v8::Value> xrCompatibleValue;
1485
- config->Get(context,
1486
- consts->XR_COMPATIBLE_PERSISTENT->Get(isolate)).ToLocal(&xrCompatibleValue);
1487
- if (!xrCompatibleValue.IsEmpty() && xrCompatibleValue->IsBoolean()) {
1488
- xr_compatible = xrCompatibleValue->BooleanValue(isolate);
1489
- }
1490
- }
1407
+ auto isolate = args.GetIsolate();
1408
+ auto context = isolate->GetCurrentContext();
1491
1409
 
1492
1410
 
1493
- if (version !=
1494
- "v2") {
1495
- args.GetReturnValue().SetNull();
1496
- return;
1497
- } else {
1498
- auto count = args.Length();
1499
- if (count == 6) {
1500
- auto ctx = args[1].As<v8::BigInt>()->Int64Value();
1501
- // auto density = args[2]->NumberValue(context).ToChecked();
1502
- // auto fontColor = args[3]->NumberValue(context).ToChecked();
1503
- // auto ppi = args[4]->NumberValue(context).ToChecked();
1504
- // auto direction = args[5]->NumberValue(context).ToChecked();
1505
-
1506
- auto webgl = canvas_native_webgl_create(
1507
- ctx,
1508
- version.c_str(),
1509
- alpha,
1510
- antialias,
1511
- depth,
1512
- fail_if_major_performance_caveat,
1513
- power_preference.c_str(),
1514
- premultiplied_alpha,
1515
- preserve_drawing_buffer,
1516
- stencil,
1517
- desynchronized,
1518
- xr_compatible
1519
- );
1520
-
1521
- auto renderingContext = WebGL2RenderingContext::NewInstance(isolate,
1522
- new WebGL2RenderingContext(
1523
- webgl,
1524
- WebGLRenderingVersion::V2));
1525
-
1526
- args.GetReturnValue().Set(renderingContext);
1527
- return;
1411
+ auto count = args.Length();
1412
+ if (count == 6) {
1413
+ auto ctx = args[1].As<v8::BigInt>()->Int64Value();
1414
+ auto webgl = canvas_native_webgl_create(
1415
+ ctx,
1416
+ options.version,
1417
+ options.alpha,
1418
+ options.antialias,
1419
+ options.depth,
1420
+ options.failIfMajorPerformanceCaveat,
1421
+ options.powerPreference,
1422
+ options.premultipliedAlpha,
1423
+ options.preserveDrawingBuffer,
1424
+ options.stencil,
1425
+ options.desynchronized,
1426
+ options.xrCompatible
1427
+ );
1428
+
1429
+ auto renderingContext = WebGL2RenderingContext::NewInstance(isolate,
1430
+ new WebGL2RenderingContext(
1431
+ webgl,
1432
+ WebGLRenderingVersion::V2));
1433
+
1434
+ args.GetReturnValue().Set(renderingContext);
1435
+ return;
1528
1436
 
1529
- } else if (count ==
1530
- 7) {
1531
- auto width = args[1]->NumberValue(context).ToChecked();
1532
- auto height = args[2]->NumberValue(context).ToChecked();
1533
- // auto density = args[3]->NumberValue(context).ToChecked();
1534
- // auto fontColor = args[4]->NumberValue(context).ToChecked();
1535
- // auto ppi = args[5]->NumberValue(context).ToChecked();
1536
- // auto direction = args[6]->NumberValue(context).ToChecked();
1537
- auto ctx = canvas_native_webgl_create_no_window(
1538
- (int32_t) width,
1539
- (int32_t) height,
1540
- version.c_str(),
1541
- alpha,
1542
- antialias,
1543
- depth,
1544
- fail_if_major_performance_caveat,
1545
- power_preference.c_str(),
1546
- premultiplied_alpha,
1547
- preserve_drawing_buffer,
1548
- stencil,
1549
- desynchronized,
1550
- xr_compatible,
1551
- false
1552
- );
1553
- auto renderingContext = WebGL2RenderingContext::NewInstance(isolate,
1554
- new WebGL2RenderingContext(
1555
- ctx,
1556
- WebGLRenderingVersion::V2));
1557
-
1558
- args.GetReturnValue().Set(renderingContext);
1559
- return;
1437
+ } else if (count ==
1438
+ 7) {
1439
+ auto width = args[1]->NumberValue(context).ToChecked();
1440
+ auto height = args[2]->NumberValue(context).ToChecked();
1441
+ auto ctx = canvas_native_webgl_create_no_window(
1442
+ (int32_t) width,
1443
+ (int32_t) height,
1444
+ options.version,
1445
+ options.alpha,
1446
+ options.antialias,
1447
+ options.depth,
1448
+ options.failIfMajorPerformanceCaveat,
1449
+ options.powerPreference,
1450
+ options.premultipliedAlpha,
1451
+ options.preserveDrawingBuffer,
1452
+ options.stencil,
1453
+ options.desynchronized,
1454
+ options.xrCompatible,
1455
+ false
1456
+ );
1457
+ auto renderingContext = WebGL2RenderingContext::NewInstance(isolate,
1458
+ new WebGL2RenderingContext(
1459
+ ctx,
1460
+ WebGLRenderingVersion::V2));
1461
+
1462
+ args.GetReturnValue().Set(renderingContext);
1463
+ return;
1560
1464
 
1561
- } else {
1562
- auto width = (int32_t) args[1]->NumberValue(context).ToChecked();
1563
- auto height = (int32_t) args[2]->NumberValue(context).ToChecked();
1564
- auto ctx = canvas_native_webgl_create_no_window(
1565
- width,
1566
- height,
1567
- version.c_str(),
1568
- alpha,
1569
- antialias,
1570
- depth,
1571
- fail_if_major_performance_caveat,
1572
- power_preference.c_str(),
1573
- premultiplied_alpha,
1574
- preserve_drawing_buffer,
1575
- stencil,
1576
- desynchronized,
1577
- xr_compatible,
1578
- false
1579
- );
1580
-
1581
- auto renderingContext = WebGL2RenderingContext::NewInstance(isolate,
1582
- new WebGL2RenderingContext(
1583
- ctx,
1584
- WebGLRenderingVersion::V2));
1585
-
1586
- args.GetReturnValue().Set(renderingContext);
1587
- return;
1588
- }
1589
- }
1465
+ } else {
1466
+ auto width = (int32_t) args[1]->NumberValue(context).ToChecked();
1467
+ auto height = (int32_t) args[2]->NumberValue(context).ToChecked();
1468
+ auto ctx = canvas_native_webgl_create_no_window(
1469
+ width,
1470
+ height,
1471
+ options.version,
1472
+ options.alpha,
1473
+ options.antialias,
1474
+ options.depth,
1475
+ options.failIfMajorPerformanceCaveat,
1476
+ options.powerPreference,
1477
+ options.premultipliedAlpha,
1478
+ options.preserveDrawingBuffer,
1479
+ options.stencil,
1480
+ options.desynchronized,
1481
+ options.xrCompatible,
1482
+ false
1483
+ );
1484
+
1485
+ auto renderingContext = WebGL2RenderingContext::NewInstance(isolate,
1486
+ new WebGL2RenderingContext(
1487
+ ctx,
1488
+ WebGLRenderingVersion::V2));
1489
+
1490
+ args.GetReturnValue().Set(renderingContext);
1491
+ return;
1590
1492
  }
1591
-
1592
- args.GetReturnValue().SetNull();
1593
1493
  }