@nativescript/canvas 2.0.0-webgpu.29 → 2.0.0-webgpu.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/platforms/android/canvas-release.aar +0 -0
- package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/CanvasNative +0 -0
- package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Headers/canvas_native.h +1 -1
- package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios.abi.json +8061 -7381
- package/platforms/ios/CanvasNative.xcframework/ios-arm64/dSYMs/CanvasNative.framework.dSYM/Contents/Resources/DWARF/CanvasNative +0 -0
- package/platforms/ios/CanvasNative.xcframework/ios-arm64/dSYMs/CanvasNative.framework.dSYM/Contents/Resources/Relocations/aarch64/CanvasNative.yml +690 -690
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/CanvasNative +0 -0
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Headers/canvas_native.h +1 -1
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios-simulator.abi.json +8061 -7381
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/x86_64-apple-ios-simulator.abi.json +8061 -7381
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/_CodeSignature/CodeResources +2 -2
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/dSYMs/CanvasNative.framework.dSYM/Contents/Resources/DWARF/CanvasNative +0 -0
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/dSYMs/CanvasNative.framework.dSYM/Contents/Resources/Relocations/aarch64/CanvasNative.yml +692 -692
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/dSYMs/CanvasNative.framework.dSYM/Contents/Resources/Relocations/x86_64/CanvasNative.yml +730 -730
- package/platforms/ios/src/cpp/CanvasJSIModule.cpp +208 -865
- package/platforms/ios/src/cpp/ImageAssetImpl.cpp +5 -7
|
@@ -252,6 +252,32 @@ void CanvasJSIModule::Create2DContext(const v8::FunctionCallbackInfo<v8::Value>
|
|
|
252
252
|
args.GetReturnValue().Set(ret);
|
|
253
253
|
}
|
|
254
254
|
|
|
255
|
+
|
|
256
|
+
struct Rect {
|
|
257
|
+
float x;
|
|
258
|
+
float y;
|
|
259
|
+
float width;
|
|
260
|
+
float height;
|
|
261
|
+
};
|
|
262
|
+
|
|
263
|
+
struct ImageBitmapData {
|
|
264
|
+
char *error_;
|
|
265
|
+
const ImageAsset *asset_;
|
|
266
|
+
bool done_;
|
|
267
|
+
v8::Isolate *isolate_;
|
|
268
|
+
std::shared_ptr<v8::Persistent<v8::ArrayBufferView>> data_;
|
|
269
|
+
|
|
270
|
+
~ImageBitmapData() {
|
|
271
|
+
if (error_ != nullptr) {
|
|
272
|
+
canvas_native_string_destroy(error_);
|
|
273
|
+
error_ = nullptr;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
data_->Reset();
|
|
277
|
+
}
|
|
278
|
+
};
|
|
279
|
+
|
|
280
|
+
|
|
255
281
|
void CanvasJSIModule::CreateImageBitmap(const v8::FunctionCallbackInfo<v8::Value> &args) {
|
|
256
282
|
auto count = args.Length();
|
|
257
283
|
auto isolate = args.GetIsolate();
|
|
@@ -311,692 +337,128 @@ void CanvasJSIModule::CreateImageBitmap(const v8::FunctionCallbackInfo<v8::Value
|
|
|
311
337
|
return;
|
|
312
338
|
}
|
|
313
339
|
|
|
314
|
-
|
|
315
340
|
if (image->IsObject()) {
|
|
316
341
|
auto imageObject = image.As<v8::Object>();
|
|
317
342
|
auto isArrayBuffer = imageObject->IsArrayBuffer();
|
|
318
343
|
auto IsArrayBufferView = imageObject->IsArrayBufferView();
|
|
319
|
-
|
|
344
|
+
std::optional<Rect> rect = std::nullopt;
|
|
320
345
|
|
|
321
|
-
|
|
346
|
+
if (isArrayBuffer || IsArrayBufferView) {
|
|
347
|
+
if ((len == 1 || len == 2) || (len == 5 || len == 6)) {
|
|
322
348
|
if (len == 2) {
|
|
323
349
|
options = ImageBitmapImpl::HandleOptions(isolate, args[1]);
|
|
324
350
|
}
|
|
325
351
|
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
auto ret = new ImageBitmapImpl(asset);
|
|
331
|
-
|
|
352
|
+
if (len == 6) {
|
|
353
|
+
options = ImageBitmapImpl::HandleOptions(isolate, args[5]);
|
|
354
|
+
}
|
|
332
355
|
|
|
333
356
|
auto cbFunc = args[count - 1].As<v8::Function>();
|
|
334
|
-
auto data = v8::External::New(isolate, ret);
|
|
335
|
-
|
|
336
|
-
auto jsi_callback = new JSICallback(isolate, cbFunc, data);
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
#ifdef __ANDROID__
|
|
340
|
-
ALooper_addFd(jsi_callback->looper_,
|
|
341
|
-
jsi_callback->fd_[0],
|
|
342
|
-
0,
|
|
343
|
-
ALOOPER_EVENT_INPUT,
|
|
344
|
-
[](int fd, int events,
|
|
345
|
-
void *data) {
|
|
346
|
-
if(data == nullptr){
|
|
347
|
-
return 1;
|
|
348
|
-
}
|
|
349
|
-
auto cb = static_cast<JSICallback *>(data);
|
|
350
|
-
bool done;
|
|
351
|
-
read(fd, &done,
|
|
352
|
-
sizeof(bool));
|
|
353
|
-
|
|
354
|
-
v8::Isolate *isolate = cb->isolate_;
|
|
355
|
-
v8::Locker locker(isolate);
|
|
356
|
-
v8::Isolate::Scope isolate_scope(isolate);
|
|
357
|
-
v8::HandleScope handle_scope(isolate);
|
|
358
|
-
v8::Local<v8::Function> callback = cb->callback_->Get(isolate);
|
|
359
|
-
v8::Local<v8::External> cbData = cb->data_->Get(
|
|
360
|
-
isolate).As<v8::External>();
|
|
361
|
-
v8::Local<v8::Context> context = callback->GetCreationContextChecked();
|
|
362
|
-
v8::Context::Scope context_scope(context);
|
|
363
|
-
|
|
364
|
-
auto ret = ImageBitmapImpl::NewInstance(isolate, cbData);
|
|
365
|
-
|
|
366
|
-
v8::Local<v8::Value> args[2];
|
|
367
|
-
|
|
368
|
-
if (done) {
|
|
369
|
-
args[0] = v8::Null(isolate);
|
|
370
|
-
args[1] = ret;
|
|
371
|
-
|
|
372
|
-
} else {
|
|
373
|
-
args[0] = v8::Exception::Error(
|
|
374
|
-
ConvertToV8String(isolate, "Failed to load image"));
|
|
375
|
-
args[1] = v8::Null(isolate);
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
callback->Call(context, context->Global(), 2, args);
|
|
379
|
-
|
|
380
|
-
delete static_cast<JSICallback *>(data);
|
|
381
|
-
return 0;
|
|
382
|
-
}, jsi_callback);
|
|
383
357
|
|
|
384
358
|
if (isArrayBuffer) {
|
|
385
|
-
// converting to Uint8Array
|
|
386
359
|
auto arrayBuffer = imageObject.As<v8::ArrayBuffer>();
|
|
387
360
|
auto size = arrayBuffer->ByteLength();
|
|
388
361
|
imageObject = v8::Uint8Array::New(arrayBuffer, 0, size);
|
|
389
|
-
/* auto store = arrayBuffer->GetBackingStore();
|
|
390
|
-
auto dataBuffer = (uint8_t *) store->Data();
|
|
391
|
-
|
|
392
|
-
std::thread thread(
|
|
393
|
-
[&dataBuffer, jsi_callback, &options, store, shared_asset, size](
|
|
394
|
-
v8::Global<v8::ArrayBuffer> ab) {
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
auto done = canvas_native_image_bitmap_create_from_encoded_bytes_with_output(
|
|
398
|
-
dataBuffer, size,
|
|
399
|
-
options.flipY,
|
|
400
|
-
options.premultiplyAlpha,
|
|
401
|
-
options.colorSpaceConversion,
|
|
402
|
-
options.resizeQuality,
|
|
403
|
-
options.resizeWidth,
|
|
404
|
-
options.resizeHeight,
|
|
405
|
-
shared_asset);
|
|
406
|
-
|
|
407
|
-
write(jsi_callback->fd_[1],
|
|
408
|
-
&done,
|
|
409
|
-
sizeof(bool));
|
|
410
|
-
|
|
411
|
-
// canvas_native_image_asset_release(shared_asset);
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
});
|
|
415
|
-
|
|
416
|
-
thread.detach();
|
|
417
|
-
return;
|
|
418
|
-
|
|
419
|
-
*/
|
|
420
362
|
}
|
|
421
363
|
|
|
422
|
-
|
|
423
364
|
auto ta = imageObject.As<v8::ArrayBufferView>();
|
|
424
365
|
|
|
425
|
-
auto
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
auto size = arrayBuffer->ByteLength();
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
auto thread_queue = new NSOperationQueueWrapper(false);
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
thread_queue->addOperation([&dataBuffer, jsi_callback, &options, store, shared_asset, current_queue, &ab, size]() {
|
|
478
|
-
|
|
479
|
-
auto done = canvas_native_image_bitmap_create_from_encoded_bytes_with_output(
|
|
480
|
-
dataBuffer, size,
|
|
481
|
-
options.flipY,
|
|
482
|
-
options.premultiplyAlpha,
|
|
483
|
-
options.colorSpaceConversion,
|
|
484
|
-
options.resizeQuality,
|
|
485
|
-
options.resizeWidth,
|
|
486
|
-
options.resizeHeight,
|
|
487
|
-
shared_asset);
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
auto main_task = [jsi_callback, current_queue, done, shared_asset]() {
|
|
492
|
-
|
|
493
|
-
v8::Isolate *isolate = jsi_callback->isolate_;
|
|
494
|
-
v8::Locker locker(isolate);
|
|
495
|
-
v8::Isolate::Scope isolate_scope(isolate);
|
|
496
|
-
v8::HandleScope handle_scope(isolate);
|
|
497
|
-
v8::Local<v8::Function> callback = jsi_callback->callback_->Get(isolate);
|
|
498
|
-
v8::Local<v8::External> cbData = jsi_callback->data_->Get(
|
|
499
|
-
isolate).As<v8::External>();
|
|
500
|
-
v8::Local<v8::Context> context = callback->GetCreationContextChecked();
|
|
501
|
-
v8::Context::Scope context_scope(context);
|
|
502
|
-
|
|
503
|
-
auto ret = ImageBitmapImpl::NewInstance(isolate, cbData);
|
|
504
|
-
|
|
505
|
-
v8::Local<v8::Value> args[2];
|
|
506
|
-
|
|
507
|
-
if (done) {
|
|
508
|
-
args[0] = v8::Null(isolate);
|
|
509
|
-
args[1] = ret;
|
|
510
|
-
|
|
511
|
-
} else {
|
|
512
|
-
args[0] = v8::Exception::Error(
|
|
513
|
-
ConvertToV8String(isolate, "Failed to load image"));
|
|
514
|
-
args[1] = v8::Null(isolate);
|
|
515
|
-
}
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
callback->Call(context, context->Global(), 2, args);
|
|
519
|
-
|
|
520
|
-
delete jsi_callback;
|
|
521
|
-
delete current_queue;
|
|
522
|
-
|
|
523
|
-
canvas_native_image_asset_release(shared_asset);
|
|
524
|
-
|
|
525
|
-
};
|
|
526
|
-
current_queue->addOperation(main_task);
|
|
527
|
-
|
|
528
|
-
});
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
/*
|
|
536
|
-
std::thread thread(
|
|
537
|
-
[&dataBuffer, jsi_callback, &options, store, &shared_asset, current_queue, size](
|
|
538
|
-
v8::Global<v8::ArrayBuffer> ab
|
|
539
|
-
) {
|
|
540
|
-
|
|
541
|
-
auto done = canvas_native_image_bitmap_create_from_encoded_bytes_with_output(
|
|
542
|
-
dataBuffer, size,
|
|
543
|
-
options.flipY,
|
|
544
|
-
options.premultiplyAlpha,
|
|
545
|
-
options.colorSpaceConversion,
|
|
546
|
-
options.resizeQuality,
|
|
547
|
-
options.resizeWidth,
|
|
548
|
-
options.resizeHeight,
|
|
549
|
-
shared_asset);
|
|
550
|
-
|
|
551
|
-
auto main_task = [jsi_callback, current_queue, done, shared_asset]() {
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
v8::Isolate *isolate = jsi_callback->isolate_;
|
|
555
|
-
v8::Locker locker(isolate);
|
|
556
|
-
v8::Isolate::Scope isolate_scope(isolate);
|
|
557
|
-
v8::HandleScope handle_scope(isolate);
|
|
558
|
-
v8::Local<v8::Function> callback = jsi_callback->callback_->Get(isolate);
|
|
559
|
-
v8::Local<v8::External> cbData = jsi_callback->data_->Get(
|
|
560
|
-
isolate).As<v8::External>();
|
|
561
|
-
v8::Local<v8::Context> context = callback->GetCreationContextChecked();
|
|
562
|
-
v8::Context::Scope context_scope(context);
|
|
563
|
-
|
|
564
|
-
auto ret = ImageBitmapImpl::NewInstance(isolate, cbData);
|
|
565
|
-
|
|
566
|
-
v8::Local<v8::Value> args[2];
|
|
567
|
-
|
|
568
|
-
if (done) {
|
|
569
|
-
args[0] = v8::Null(isolate);
|
|
570
|
-
args[1] = ret;
|
|
571
|
-
|
|
572
|
-
} else {
|
|
573
|
-
args[0] = v8::Exception::Error(
|
|
574
|
-
ConvertToV8String(isolate, "Failed to load image"));
|
|
575
|
-
args[1] = v8::Null(isolate);
|
|
576
|
-
}
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
callback->Call(context, context->Global(), 2, args);
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
delete jsi_callback;
|
|
583
|
-
delete current_queue;
|
|
584
|
-
|
|
585
|
-
canvas_native_image_asset_release(shared_asset);
|
|
586
|
-
|
|
587
|
-
};
|
|
588
|
-
current_queue->addOperation(main_task);
|
|
589
|
-
|
|
590
|
-
}, std::move(ab));
|
|
591
|
-
|
|
592
|
-
thread.detach();
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
*/
|
|
596
|
-
|
|
597
|
-
return;
|
|
598
|
-
}
|
|
599
|
-
|
|
600
|
-
auto ta = imageObject.As<v8::ArrayBufferView>();
|
|
366
|
+
auto image_bitmap_async_data = new ImageBitmapData();
|
|
367
|
+
image_bitmap_async_data->isolate_ = isolate;
|
|
368
|
+
image_bitmap_async_data->data_ = std::make_shared<v8::Persistent<v8::ArrayBufferView>>(
|
|
369
|
+
isolate, ta);
|
|
370
|
+
|
|
371
|
+
auto callback = new AsyncCallback(isolate, cbFunc, [](bool done, void *data) {
|
|
372
|
+
if(data == nullptr){return;}
|
|
373
|
+
auto async_data = static_cast<AsyncCallback *>(data);
|
|
374
|
+
auto func = async_data->inner_.get();
|
|
375
|
+
if (func != nullptr && func->isolate_ != nullptr) {
|
|
376
|
+
v8::Isolate *isolate = func->isolate_;
|
|
377
|
+
v8::Locker locker(isolate);
|
|
378
|
+
v8::Isolate::Scope isolate_scope(isolate);
|
|
379
|
+
v8::HandleScope handle_scope(isolate);
|
|
380
|
+
v8::Local<v8::Function> callback = func->callback_.Get(
|
|
381
|
+
isolate);
|
|
382
|
+
v8::Local<v8::Context> context = callback->GetCreationContextChecked();
|
|
383
|
+
v8::Context::Scope context_scope(context);
|
|
384
|
+
|
|
385
|
+
if (func->data != nullptr) {
|
|
386
|
+
auto asset_data = static_cast<ImageBitmapData *>(func->data);
|
|
387
|
+
|
|
388
|
+
auto bitmap = new ImageBitmapImpl(asset_data->asset_);
|
|
389
|
+
auto external = v8::External::New(isolate, bitmap);
|
|
390
|
+
|
|
391
|
+
auto ret = ImageBitmapImpl::NewInstance(isolate, external);
|
|
392
|
+
|
|
393
|
+
v8::Local<v8::Value> args[2] = {
|
|
394
|
+
v8::Null(isolate), ret};
|
|
395
|
+
|
|
396
|
+
|
|
397
|
+
callback->Call(context, context->Global(),
|
|
398
|
+
2,
|
|
399
|
+
args); // ignore JS return value
|
|
400
|
+
|
|
401
|
+
delete asset_data;
|
|
402
|
+
|
|
403
|
+
} else {
|
|
404
|
+
v8::Local<v8::Value> args[1] = {
|
|
405
|
+
v8::Null(isolate)};
|
|
406
|
+
|
|
407
|
+
callback->Call(context, context->Global(),
|
|
408
|
+
1,
|
|
409
|
+
args); // ignore JS return value
|
|
410
|
+
}
|
|
601
411
|
|
|
412
|
+
}
|
|
413
|
+
delete static_cast<AsyncCallback *>(data);
|
|
414
|
+
});
|
|
602
415
|
|
|
603
|
-
|
|
416
|
+
callback->inner_->data = image_bitmap_async_data;
|
|
417
|
+
callback->prepare();
|
|
418
|
+
auto store = ta->Buffer()->GetBackingStore();
|
|
604
419
|
auto offset = ta->ByteOffset();
|
|
605
|
-
auto size = ta->ByteLength();
|
|
606
|
-
auto data_ptr = static_cast<uint8_t *>(array->GetBackingStore()->Data()) + offset;
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
v8::Global<v8::ArrayBufferView> ab(isolate, ta);
|
|
610
|
-
|
|
611
420
|
|
|
612
421
|
std::thread thread(
|
|
613
|
-
[
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
auto
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
v8::Isolate *isolate = jsi_callback->isolate_;
|
|
632
|
-
v8::Locker locker(isolate);
|
|
633
|
-
v8::Isolate::Scope isolate_scope(isolate);
|
|
634
|
-
v8::HandleScope handle_scope(isolate);
|
|
635
|
-
v8::Local<v8::Function> callback = jsi_callback->callback_->Get(isolate);
|
|
636
|
-
v8::Local<v8::External> cbData = jsi_callback->data_->Get(
|
|
637
|
-
isolate).As<v8::External>();
|
|
638
|
-
v8::Local<v8::Context> context = callback->GetCreationContextChecked();
|
|
639
|
-
v8::Context::Scope context_scope(context);
|
|
640
|
-
|
|
641
|
-
auto ret = ImageBitmapImpl::NewInstance(isolate, cbData);
|
|
642
|
-
|
|
643
|
-
v8::Local<v8::Value> args[2];
|
|
644
|
-
|
|
645
|
-
if (done) {
|
|
646
|
-
args[0] = v8::Null(isolate);
|
|
647
|
-
args[1] = ret;
|
|
648
|
-
} else {
|
|
649
|
-
args[0] = v8::Exception::Error(
|
|
650
|
-
ConvertToV8String(isolate, "Failed to load image"));
|
|
651
|
-
args[1] = v8::Null(isolate);
|
|
652
|
-
}
|
|
653
|
-
|
|
654
|
-
callback->Call(context, context->Global(), 2, args);
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
delete jsi_callback;
|
|
658
|
-
delete current_queue;
|
|
659
|
-
|
|
660
|
-
canvas_native_image_asset_release(shared_asset);
|
|
661
|
-
|
|
662
|
-
};
|
|
663
|
-
current_queue->addOperation(main_task);
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
}, std::move(ab));
|
|
668
|
-
thread.detach();
|
|
669
|
-
|
|
670
|
-
#endif
|
|
671
|
-
|
|
672
|
-
return;
|
|
673
|
-
} else if (len == 5 || len == 6) {
|
|
674
|
-
auto asset = canvas_native_image_asset_create();
|
|
675
|
-
|
|
676
|
-
auto shared_asset = canvas_native_image_asset_reference(asset);
|
|
677
|
-
|
|
678
|
-
auto ret = new ImageBitmapImpl(asset);
|
|
679
|
-
|
|
680
|
-
auto cbFunc = args[count - 1].As<v8::Function>();
|
|
681
|
-
auto data = v8::External::New(isolate, ret);
|
|
682
|
-
if (len == 6) {
|
|
683
|
-
options = ImageBitmapImpl::HandleOptions(isolate, args[5]);
|
|
684
|
-
}
|
|
685
|
-
|
|
686
|
-
auto jsi_callback = new JSICallback(isolate, cbFunc, data);
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
#ifdef __ANDROID__
|
|
690
|
-
ALooper_addFd(jsi_callback->looper_,
|
|
691
|
-
jsi_callback->fd_[0],
|
|
692
|
-
0,
|
|
693
|
-
ALOOPER_EVENT_INPUT,
|
|
694
|
-
[](int fd, int events,
|
|
695
|
-
void *data) {
|
|
696
|
-
auto cb = static_cast<JSICallback *>(data);
|
|
697
|
-
bool done;
|
|
698
|
-
read(fd, &done,
|
|
699
|
-
sizeof(bool));
|
|
700
|
-
|
|
701
|
-
v8::Isolate *isolate = cb->isolate_;
|
|
702
|
-
v8::Locker locker(isolate);
|
|
703
|
-
v8::Isolate::Scope isolate_scope(isolate);
|
|
704
|
-
v8::HandleScope handle_scope(isolate);
|
|
705
|
-
v8::Local<v8::Function> callback = cb->callback_->Get(isolate);
|
|
706
|
-
v8::Local<v8::External> cbData = cb->data_->Get(
|
|
707
|
-
isolate).As<v8::External>();
|
|
708
|
-
v8::Local<v8::Context> context = callback->GetCreationContextChecked();
|
|
709
|
-
v8::Context::Scope context_scope(context);
|
|
710
|
-
|
|
711
|
-
auto ret = ImageBitmapImpl::NewInstance(isolate, cbData);
|
|
712
|
-
|
|
713
|
-
v8::Local<v8::Value> args[2];
|
|
714
|
-
|
|
715
|
-
if (done) {
|
|
716
|
-
args[0] = v8::Null(isolate);
|
|
717
|
-
args[1] = ret;
|
|
718
|
-
} else {
|
|
719
|
-
args[0] = v8::Exception::Error(
|
|
720
|
-
ConvertToV8String(isolate, "Failed to load image"));
|
|
721
|
-
args[1] = v8::Null(isolate);
|
|
722
|
-
}
|
|
723
|
-
|
|
724
|
-
callback->Call(context, context->Global(), 2, args);
|
|
725
|
-
|
|
726
|
-
delete static_cast<JSICallback *>(data);
|
|
727
|
-
return 0;
|
|
728
|
-
}, jsi_callback);
|
|
729
|
-
|
|
730
|
-
auto bufferValue = args[0];
|
|
731
|
-
|
|
732
|
-
if (isArrayBuffer) {
|
|
733
|
-
auto arrayBuffer = bufferValue.As<v8::ArrayBuffer>();
|
|
734
|
-
auto size = arrayBuffer->ByteLength();
|
|
735
|
-
imageObject = v8::Uint8Array::New(arrayBuffer, 0, size);
|
|
736
|
-
/*
|
|
737
|
-
auto arrayBuffer = bufferValue.As<v8::ArrayBuffer>();
|
|
738
|
-
auto dataBuffer = (uint8_t *) arrayBuffer->GetBackingStore()->Data();
|
|
739
|
-
v8::Global<v8::ArrayBuffer> ab(isolate, arrayBuffer);
|
|
740
|
-
std::thread thread(
|
|
741
|
-
[&dataBuffer, jsi_callback, &options, shared_asset](
|
|
742
|
-
float sx_or_options,
|
|
743
|
-
float sy,
|
|
744
|
-
float sw,
|
|
745
|
-
float sh,
|
|
746
|
-
v8::Global<v8::ArrayBuffer> ab,
|
|
747
|
-
size_t size
|
|
748
|
-
) {
|
|
749
|
-
|
|
750
|
-
auto done = canvas_native_image_bitmap_create_from_encoded_bytes_src_rect_with_output(
|
|
751
|
-
dataBuffer, size,
|
|
752
|
-
sx_or_options,
|
|
753
|
-
sy,
|
|
754
|
-
sw,
|
|
755
|
-
sh,
|
|
422
|
+
[callback, image_bitmap_async_data, offset, options, rect](
|
|
423
|
+
std::shared_ptr<v8::BackingStore> store) {
|
|
424
|
+
|
|
425
|
+
auto data = static_cast<uint8_t *>(store->Data()) + offset;
|
|
426
|
+
auto size = store->ByteLength();
|
|
427
|
+
|
|
428
|
+
auto asset = canvas_native_image_asset_create();
|
|
429
|
+
bool done;
|
|
430
|
+
if (rect.has_value()) {
|
|
431
|
+
|
|
432
|
+
done = canvas_native_image_bitmap_create_from_encoded_bytes_src_rect_with_output(
|
|
433
|
+
data, size,
|
|
434
|
+
rect.value().x,
|
|
435
|
+
rect.value().y,
|
|
436
|
+
rect.value().width,
|
|
437
|
+
rect.value().height,
|
|
756
438
|
options.flipY,
|
|
757
439
|
options.premultiplyAlpha,
|
|
758
440
|
options.colorSpaceConversion,
|
|
759
441
|
options.resizeQuality,
|
|
760
442
|
options.resizeWidth,
|
|
761
|
-
options.resizeHeight,
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
sizeof(bool));
|
|
766
|
-
|
|
767
|
-
canvas_native_image_asset_release(shared_asset);
|
|
768
|
-
|
|
769
|
-
},
|
|
770
|
-
(float) sx_or_options->NumberValue(context).ToChecked(),
|
|
771
|
-
(float) sy->NumberValue(context).ToChecked(),
|
|
772
|
-
(float) sw->NumberValue(context).ToChecked(),
|
|
773
|
-
(float) sh->NumberValue(context).ToChecked(), std::move(ab),
|
|
774
|
-
arrayBuffer->ByteLength());
|
|
775
|
-
|
|
776
|
-
thread.detach();
|
|
777
|
-
|
|
778
|
-
return;
|
|
779
|
-
*/
|
|
780
|
-
}
|
|
781
|
-
|
|
782
|
-
auto ta = bufferValue.As<v8::ArrayBufferView>();
|
|
783
|
-
|
|
784
|
-
auto array = ta->Buffer();
|
|
785
|
-
auto offset = ta->ByteOffset();
|
|
786
|
-
auto size = ta->ByteLength();
|
|
787
|
-
auto data_ptr = static_cast<uint8_t *>(array->GetBackingStore()->Data()) + offset;
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
v8::Global<v8::ArrayBufferView> ab(isolate, ta);
|
|
791
|
-
std::thread thread(
|
|
792
|
-
[jsi_callback, &options, shared_asset, data_ptr, size](
|
|
793
|
-
float sx_or_options,
|
|
794
|
-
float sy,
|
|
795
|
-
float sw,
|
|
796
|
-
float sh,
|
|
797
|
-
v8::Global<v8::ArrayBufferView> ab
|
|
798
|
-
) {
|
|
799
|
-
|
|
800
|
-
auto done = canvas_native_image_bitmap_create_from_encoded_bytes_src_rect_with_output(
|
|
801
|
-
data_ptr, size,
|
|
802
|
-
sx_or_options,
|
|
803
|
-
sy,
|
|
804
|
-
sw,
|
|
805
|
-
sh,
|
|
806
|
-
options.flipY,
|
|
807
|
-
options.premultiplyAlpha,
|
|
808
|
-
options.colorSpaceConversion,
|
|
809
|
-
options.resizeQuality,
|
|
810
|
-
options.resizeWidth,
|
|
811
|
-
options.resizeHeight, shared_asset);
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
write(jsi_callback->fd_[1],
|
|
815
|
-
&done,
|
|
816
|
-
sizeof(bool));
|
|
817
|
-
|
|
818
|
-
canvas_native_image_asset_release(shared_asset);
|
|
819
|
-
|
|
820
|
-
},
|
|
821
|
-
(float) sx_or_options->NumberValue(context).ToChecked(),
|
|
822
|
-
(float) sy->NumberValue(context).ToChecked(),
|
|
823
|
-
(float) sw->NumberValue(context).ToChecked(),
|
|
824
|
-
(float) sh->NumberValue(context).ToChecked(), std::move(ab));
|
|
825
|
-
thread.detach();
|
|
826
|
-
|
|
827
|
-
#endif
|
|
828
|
-
|
|
829
|
-
#ifdef __APPLE__
|
|
830
|
-
|
|
831
|
-
auto current_queue = new NSOperationQueueWrapper(true);
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
auto bufferValue = args[0];
|
|
835
|
-
|
|
836
|
-
if (isArrayBuffer) {
|
|
837
|
-
auto arrayBuffer = bufferValue.As<v8::ArrayBuffer>();
|
|
838
|
-
auto dataBuffer = (uint8_t *) arrayBuffer->GetBackingStore()->Data();
|
|
839
|
-
v8::Global<v8::ArrayBuffer> ab(isolate, arrayBuffer);
|
|
840
|
-
std::thread thread(
|
|
841
|
-
[&dataBuffer, jsi_callback, &options, shared_asset, current_queue](
|
|
842
|
-
float sx_or_options,
|
|
843
|
-
float sy,
|
|
844
|
-
float sw,
|
|
845
|
-
float sh,
|
|
846
|
-
v8::Global<v8::ArrayBuffer> ab,
|
|
847
|
-
size_t size
|
|
848
|
-
) {
|
|
849
|
-
|
|
850
|
-
auto done = canvas_native_image_bitmap_create_from_encoded_bytes_src_rect_with_output(
|
|
851
|
-
dataBuffer, size,
|
|
852
|
-
sx_or_options,
|
|
853
|
-
sy,
|
|
854
|
-
sw,
|
|
855
|
-
sh,
|
|
443
|
+
options.resizeHeight, asset);
|
|
444
|
+
} else {
|
|
445
|
+
done = canvas_native_image_bitmap_create_from_encoded_bytes_with_output(
|
|
446
|
+
data, size,
|
|
856
447
|
options.flipY,
|
|
857
448
|
options.premultiplyAlpha,
|
|
858
449
|
options.colorSpaceConversion,
|
|
859
450
|
options.resizeQuality,
|
|
860
451
|
options.resizeWidth,
|
|
861
|
-
options.resizeHeight,
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
v8::Isolate *isolate = jsi_callback->isolate_;
|
|
868
|
-
v8::Locker locker(isolate);
|
|
869
|
-
v8::Isolate::Scope isolate_scope(isolate);
|
|
870
|
-
v8::HandleScope handle_scope(isolate);
|
|
871
|
-
v8::Local<v8::Function> callback = jsi_callback->callback_->Get(isolate);
|
|
872
|
-
v8::Local<v8::External> cbData = jsi_callback->data_->Get(
|
|
873
|
-
isolate).As<v8::External>();
|
|
874
|
-
v8::Local<v8::Context> context = callback->GetCreationContextChecked();
|
|
875
|
-
v8::Context::Scope context_scope(context);
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
auto ret = ImageBitmapImpl::NewInstance(isolate, cbData);
|
|
880
|
-
|
|
881
|
-
v8::Local<v8::Value> args[2];
|
|
882
|
-
|
|
883
|
-
if (done) {
|
|
884
|
-
args[0] = v8::Null(isolate);
|
|
885
|
-
args[1] = ret;
|
|
886
|
-
} else {
|
|
887
|
-
args[0] = v8::Exception::Error(
|
|
888
|
-
ConvertToV8String(isolate, "Failed to load image"));
|
|
889
|
-
args[1] = v8::Null(isolate);
|
|
890
|
-
}
|
|
891
|
-
|
|
892
|
-
callback->Call(context, context->Global(), 2, args);
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
delete jsi_callback;
|
|
896
|
-
delete current_queue;
|
|
897
|
-
|
|
898
|
-
canvas_native_image_asset_release(shared_asset);
|
|
899
|
-
|
|
900
|
-
};
|
|
901
|
-
current_queue->addOperation(main_task);
|
|
902
|
-
|
|
903
|
-
},
|
|
904
|
-
(float) sx_or_options->NumberValue(context).ToChecked(),
|
|
905
|
-
(float) sy->NumberValue(context).ToChecked(),
|
|
906
|
-
(float) sw->NumberValue(context).ToChecked(),
|
|
907
|
-
(float) sh->NumberValue(context).ToChecked(),
|
|
908
|
-
std::move(ab),
|
|
909
|
-
arrayBuffer->ByteLength());
|
|
910
|
-
|
|
911
|
-
thread.detach();
|
|
912
|
-
|
|
913
|
-
return;
|
|
914
|
-
}
|
|
915
|
-
|
|
916
|
-
auto ta = bufferValue.As<v8::ArrayBufferView>();
|
|
917
|
-
|
|
918
|
-
auto array = ta->Buffer();
|
|
919
|
-
auto offset = ta->ByteOffset();
|
|
920
|
-
auto size = ta->ByteLength();
|
|
921
|
-
auto data_ptr = static_cast<uint8_t*>(array->GetBackingStore()->Data()) + offset;
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
v8::Global<v8::ArrayBufferView> ab(isolate, ta);
|
|
926
|
-
std::thread thread(
|
|
927
|
-
[jsi_callback, &options, data_ptr, size, shared_asset, current_queue](
|
|
928
|
-
float sx_or_options,
|
|
929
|
-
float sy,
|
|
930
|
-
float sw,
|
|
931
|
-
float sh,
|
|
932
|
-
v8::Global<v8::ArrayBufferView> ab
|
|
933
|
-
) {
|
|
934
|
-
|
|
935
|
-
auto done = canvas_native_image_bitmap_create_from_encoded_bytes_src_rect_with_output(
|
|
936
|
-
data_ptr, size,
|
|
937
|
-
sx_or_options,
|
|
938
|
-
sy,
|
|
939
|
-
sw,
|
|
940
|
-
sh,
|
|
941
|
-
options.flipY,
|
|
942
|
-
options.premultiplyAlpha,
|
|
943
|
-
options.colorSpaceConversion,
|
|
944
|
-
options.resizeQuality,
|
|
945
|
-
options.resizeWidth,
|
|
946
|
-
options.resizeHeight, shared_asset);
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
auto main_task = [jsi_callback, current_queue, done, shared_asset]() {
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
v8::Isolate *isolate = jsi_callback->isolate_;
|
|
953
|
-
v8::Locker locker(isolate);
|
|
954
|
-
v8::Isolate::Scope isolate_scope(isolate);
|
|
955
|
-
v8::HandleScope handle_scope(isolate);
|
|
956
|
-
v8::Local<v8::Function> callback = jsi_callback->callback_->Get(isolate);
|
|
957
|
-
v8::Local<v8::External> cbData = jsi_callback->data_->Get(
|
|
958
|
-
isolate).As<v8::External>();
|
|
959
|
-
v8::Local<v8::Context> context = callback->GetCreationContextChecked();
|
|
960
|
-
v8::Context::Scope context_scope(context);
|
|
961
|
-
|
|
962
|
-
auto ret = ImageBitmapImpl::NewInstance(isolate, cbData);
|
|
963
|
-
|
|
964
|
-
v8::Local<v8::Value> args[2];
|
|
965
|
-
|
|
966
|
-
if (done) {
|
|
967
|
-
args[0] = v8::Null(isolate);
|
|
968
|
-
args[1] = ret;
|
|
969
|
-
} else {
|
|
970
|
-
args[0] = v8::Exception::Error(
|
|
971
|
-
ConvertToV8String(isolate, "Failed to load image"));
|
|
972
|
-
args[1] = v8::Null(isolate);
|
|
973
|
-
}
|
|
974
|
-
|
|
975
|
-
callback->Call(context, context->Global(), 2, args);
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
delete jsi_callback;
|
|
979
|
-
delete current_queue;
|
|
980
|
-
|
|
981
|
-
canvas_native_image_asset_release(shared_asset);
|
|
982
|
-
|
|
983
|
-
};
|
|
984
|
-
current_queue->addOperation(main_task);
|
|
985
|
-
|
|
986
|
-
|
|
452
|
+
options.resizeHeight, asset);
|
|
453
|
+
}
|
|
454
|
+
if (callback != nullptr) {
|
|
455
|
+
image_bitmap_async_data->asset_ = asset;
|
|
456
|
+
callback->execute(done);
|
|
457
|
+
}
|
|
987
458
|
|
|
988
|
-
},
|
|
989
|
-
(float) sx_or_options->NumberValue(context).ToChecked(),
|
|
990
|
-
(float) sy->NumberValue(context).ToChecked(),
|
|
991
|
-
(float) sw->NumberValue(context).ToChecked(),
|
|
992
|
-
(float) sh->NumberValue(context).ToChecked(), std::move(ab));
|
|
459
|
+
}, std::move(store));
|
|
993
460
|
thread.detach();
|
|
994
461
|
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
#endif
|
|
998
|
-
|
|
999
|
-
|
|
1000
462
|
return;
|
|
1001
463
|
}
|
|
1002
464
|
}
|
|
@@ -1145,243 +607,124 @@ void CanvasJSIModule::Create2DContextWithPointer(const v8::FunctionCallbackInfo<
|
|
|
1145
607
|
args.GetReturnValue().Set(ret);
|
|
1146
608
|
}
|
|
1147
609
|
|
|
610
|
+
struct FileData {
|
|
611
|
+
char *error_;
|
|
612
|
+
U8Buffer* data;
|
|
613
|
+
|
|
614
|
+
~FileData() {
|
|
615
|
+
if (error_ != nullptr) {
|
|
616
|
+
canvas_native_string_destroy(error_);
|
|
617
|
+
error_ = nullptr;
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
};
|
|
621
|
+
|
|
1148
622
|
void CanvasJSIModule::ReadFile(const v8::FunctionCallbackInfo<v8::Value> &args) {
|
|
1149
623
|
auto isolate = args.GetIsolate();
|
|
1150
624
|
auto file = ConvertFromV8String(isolate, args[0]);
|
|
1151
625
|
auto cbFunc = args[1].As<v8::Function>();
|
|
626
|
+
|
|
627
|
+
|
|
628
|
+
auto callback = new AsyncCallback(isolate, cbFunc, [](bool done, void *data) {
|
|
629
|
+
if(data == nullptr){return;}
|
|
630
|
+
auto async_data = static_cast<AsyncCallback *>(data);
|
|
631
|
+
auto func = async_data->inner_.get();
|
|
632
|
+
if (func != nullptr && func->isolate_ != nullptr) {
|
|
633
|
+
v8::Isolate *isolate = func->isolate_;
|
|
634
|
+
v8::Locker locker(isolate);
|
|
635
|
+
v8::Isolate::Scope isolate_scope(isolate);
|
|
636
|
+
v8::HandleScope handle_scope(isolate);
|
|
637
|
+
v8::Local<v8::Function> callback = func->callback_.Get(
|
|
638
|
+
isolate);
|
|
639
|
+
v8::Local<v8::Context> context = callback->GetCreationContextChecked();
|
|
640
|
+
v8::Context::Scope context_scope(context);
|
|
641
|
+
|
|
642
|
+
if (func->data != nullptr) {
|
|
643
|
+
auto file_data = static_cast<FileData*>(func->data);
|
|
644
|
+
|
|
645
|
+
v8::Local<v8::Value> args[2];
|
|
646
|
+
|
|
647
|
+
if (done) {
|
|
648
|
+
args[0] = v8::Null(isolate);
|
|
649
|
+
|
|
650
|
+
auto buf = (void *) canvas_native_u8_buffer_get_bytes_mut(file_data->data);
|
|
651
|
+
auto size = (size_t) canvas_native_u8_buffer_get_length(file_data->data);
|
|
652
|
+
|
|
653
|
+
auto store = v8::ArrayBuffer::NewBackingStore(buf, size,
|
|
654
|
+
[](void *data,
|
|
655
|
+
size_t length,
|
|
656
|
+
void *deleter_data) {
|
|
657
|
+
if (deleter_data !=
|
|
658
|
+
nullptr) {
|
|
659
|
+
delete static_cast<FileData *>(deleter_data);
|
|
660
|
+
|
|
661
|
+
}
|
|
662
|
+
},
|
|
663
|
+
func->data);
|
|
664
|
+
|
|
665
|
+
args[1] = v8::ArrayBuffer::New(isolate, std::move(store));
|
|
666
|
+
} else {
|
|
667
|
+
auto error = file_data->error_;
|
|
668
|
+
args[0] = v8::Exception::Error(ConvertToV8String(isolate, error));
|
|
669
|
+
args[1] = v8::Null(isolate);
|
|
670
|
+
delete file_data;
|
|
671
|
+
}
|
|
1152
672
|
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
673
|
+
v8::TryCatch tc(isolate);
|
|
674
|
+
v8::Local<v8::Value> result;
|
|
675
|
+
if (!callback->Call(context, context->Global(), 2, args).ToLocal(
|
|
676
|
+
&result)) {
|
|
677
|
+
if (tc.HasCaught()) {
|
|
678
|
+
|
|
679
|
+
// v8::Local<v8::Value> stack;
|
|
680
|
+
// bool success = tc.StackTrace(context).ToLocal(&stack);
|
|
681
|
+
// if (!success || stack.IsEmpty()) {
|
|
682
|
+
// if (!done) {
|
|
683
|
+
// delete async_data;
|
|
684
|
+
// }
|
|
685
|
+
// return;
|
|
686
|
+
// }
|
|
687
|
+
//
|
|
688
|
+
// v8::Local<v8::String> stackV8Str;
|
|
689
|
+
// success = stack->ToDetailString(context).ToLocal(&stackV8Str);
|
|
690
|
+
// if (!success || stackV8Str.IsEmpty()) {
|
|
691
|
+
// if (!done) {
|
|
692
|
+
// delete async_data;
|
|
693
|
+
// }
|
|
694
|
+
// return;
|
|
695
|
+
// }
|
|
1166
696
|
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
read(fd, &done,
|
|
1170
|
-
sizeof(bool));
|
|
1171
|
-
|
|
1172
|
-
if (cb->data_ == nullptr) {
|
|
1173
|
-
return 1;
|
|
1174
|
-
}
|
|
1175
|
-
|
|
1176
|
-
v8::Isolate *isolate = cb->isolate_;
|
|
1177
|
-
v8::Locker locker(isolate);
|
|
1178
|
-
v8::Isolate::Scope isolate_scope(isolate);
|
|
1179
|
-
v8::HandleScope handle_scope(isolate);
|
|
1180
|
-
v8::Local<v8::Function> callback = cb->callback_.Get(isolate);
|
|
1181
|
-
v8::Local<v8::Context> context = callback->GetCreationContextChecked();
|
|
1182
|
-
v8::Context::Scope context_scope(context);
|
|
1183
|
-
|
|
1184
|
-
v8::Local<v8::Value> args[2];
|
|
1185
|
-
|
|
1186
|
-
if (done) {
|
|
1187
|
-
args[0] = v8::Null(isolate);
|
|
1188
|
-
|
|
1189
|
-
auto vec = cb->data_;
|
|
1190
|
-
|
|
1191
|
-
auto buf = (void *) canvas_native_u8_buffer_get_bytes_mut(vec);
|
|
1192
|
-
auto size = (size_t) canvas_native_u8_buffer_get_length(vec);
|
|
1193
|
-
|
|
1194
|
-
auto store = v8::ArrayBuffer::NewBackingStore(buf, size,
|
|
1195
|
-
[](void *data,
|
|
1196
|
-
size_t length,
|
|
1197
|
-
void *deleter_data) {
|
|
1198
|
-
if (deleter_data !=
|
|
1199
|
-
nullptr) {
|
|
1200
|
-
// a little extreme :'D
|
|
1201
|
-
delete static_cast<JSIReadFileCallback *>(deleter_data);
|
|
1202
|
-
}
|
|
1203
|
-
},
|
|
1204
|
-
data);
|
|
1205
|
-
|
|
1206
|
-
args[1] = v8::ArrayBuffer::New(isolate, std::move(store));
|
|
1207
|
-
} else {
|
|
1208
|
-
auto error = cb->error_;
|
|
1209
|
-
args[0] = v8::Exception::Error(ConvertToV8String(isolate, error));
|
|
1210
|
-
args[1] = v8::Null(isolate);
|
|
1211
|
-
}
|
|
1212
|
-
|
|
1213
|
-
v8::TryCatch tc(isolate);
|
|
1214
|
-
v8::Local<v8::Value> result;
|
|
1215
|
-
if (!callback->Call(context, context->Global(), 2, args).ToLocal(
|
|
1216
|
-
&result)) {
|
|
1217
|
-
if (tc.HasCaught()) {
|
|
1218
|
-
|
|
1219
|
-
v8::Local<v8::Value> stack;
|
|
1220
|
-
bool success = tc.StackTrace(context).ToLocal(&stack);
|
|
1221
|
-
if (!success || stack.IsEmpty()) {
|
|
1222
|
-
if (!done) {
|
|
1223
|
-
delete cb;
|
|
1224
|
-
}
|
|
1225
|
-
return 0;
|
|
1226
|
-
}
|
|
1227
|
-
|
|
1228
|
-
v8::Local<v8::String> stackV8Str;
|
|
1229
|
-
success = stack->ToDetailString(context).ToLocal(&stackV8Str);
|
|
1230
|
-
if (!success || stackV8Str.IsEmpty()) {
|
|
1231
|
-
if (!done) {
|
|
1232
|
-
delete cb;
|
|
1233
|
-
}
|
|
1234
|
-
return 0;
|
|
1235
|
-
}
|
|
1236
|
-
|
|
1237
|
-
}
|
|
1238
|
-
}
|
|
1239
|
-
|
|
1240
|
-
if (!done) {
|
|
1241
|
-
delete cb;
|
|
1242
|
-
}
|
|
1243
|
-
return 0;
|
|
1244
|
-
}, jsi_callback);
|
|
697
|
+
}
|
|
698
|
+
}
|
|
1245
699
|
|
|
700
|
+
delete async_data;
|
|
701
|
+
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
});
|
|
705
|
+
|
|
706
|
+
callback->prepare();
|
|
707
|
+
|
|
1246
708
|
std::thread thread(
|
|
1247
|
-
[
|
|
709
|
+
[callback, file]() {
|
|
1248
710
|
bool done = false;
|
|
1249
711
|
auto ret = canvas_native_helper_read_file(file.c_str());
|
|
1250
712
|
|
|
1251
713
|
if (!canvas_native_helper_read_file_has_error(ret)) {
|
|
1252
714
|
auto buf = canvas_native_helper_read_file_take_data(ret);
|
|
1253
|
-
|
|
1254
|
-
jsi_callback->SetData(buf);
|
|
1255
|
-
|
|
715
|
+
callback->inner_->data = new FileData {nullptr, buf};
|
|
1256
716
|
done = true;
|
|
1257
717
|
} else {
|
|
1258
718
|
auto error = canvas_native_helper_read_file_get_error(ret);
|
|
1259
|
-
|
|
1260
|
-
jsi_callback->SetError(const_cast<char *>(error));
|
|
719
|
+
callback->inner_->data = new FileData {const_cast<char *>(error), nullptr};
|
|
1261
720
|
}
|
|
1262
721
|
canvas_native_helper_release(ret);
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
&done,
|
|
1266
|
-
sizeof(bool));
|
|
1267
|
-
|
|
1268
|
-
}, std::move(file));
|
|
722
|
+
callback->execute(done);
|
|
723
|
+
});
|
|
1269
724
|
|
|
1270
725
|
thread.detach();
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
#ifdef __APPLE__
|
|
1276
|
-
|
|
1277
|
-
auto current_queue = new NSOperationQueueWrapper(true);
|
|
1278
|
-
|
|
1279
|
-
auto queue = new NSOperationQueueWrapper(false);
|
|
1280
|
-
|
|
1281
|
-
auto task = [jsi_callback, current_queue, queue, file]() {
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
bool done = false;
|
|
1286
|
-
auto ret = canvas_native_helper_read_file(file.c_str());
|
|
1287
|
-
|
|
1288
|
-
if (!canvas_native_helper_read_file_has_error(ret)) {
|
|
1289
|
-
auto buf = canvas_native_helper_read_file_get_data(ret);
|
|
1290
|
-
|
|
1291
|
-
jsi_callback->SetData(buf);
|
|
1292
|
-
|
|
1293
|
-
done = true;
|
|
1294
|
-
} else {
|
|
1295
|
-
auto error = canvas_native_helper_read_file_get_error(ret);
|
|
1296
|
-
|
|
1297
|
-
jsi_callback->SetError((char*)error);
|
|
1298
|
-
}
|
|
1299
|
-
|
|
1300
|
-
canvas_native_helper_release(ret);
|
|
1301
|
-
|
|
1302
|
-
auto main_task = [jsi_callback, current_queue, queue, done]() {
|
|
1303
|
-
|
|
1304
|
-
v8::Isolate *isolate = jsi_callback->isolate_;
|
|
1305
|
-
v8::Locker locker(isolate);
|
|
1306
|
-
v8::Isolate::Scope isolate_scope(isolate);
|
|
1307
|
-
v8::HandleScope handle_scope(isolate);
|
|
1308
|
-
v8::Local<v8::Function> callback = jsi_callback->callback_.Get(isolate);
|
|
1309
|
-
v8::Local<v8::Context> context = callback->GetCreationContextChecked();
|
|
1310
|
-
v8::Context::Scope context_scope(context);
|
|
1311
|
-
|
|
1312
|
-
v8::Local<v8::Value> args[2];
|
|
1313
|
-
|
|
1314
|
-
if (done) {
|
|
1315
|
-
args[0] = v8::Null(isolate);
|
|
1316
|
-
|
|
1317
|
-
auto vec = jsi_callback->data_;
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
auto buf = (void*)canvas_native_u8_buffer_get_bytes_mut(vec);
|
|
1321
|
-
|
|
1322
|
-
auto size = (size_t)canvas_native_u8_buffer_get_length(vec);
|
|
1323
|
-
|
|
1324
|
-
auto store = v8::ArrayBuffer::NewBackingStore(buf, size,
|
|
1325
|
-
[](void *data,
|
|
1326
|
-
size_t length,
|
|
1327
|
-
void *deleter_data) {
|
|
1328
|
-
if (deleter_data !=
|
|
1329
|
-
nullptr) {
|
|
1330
|
-
// a little extreme :'D
|
|
1331
|
-
delete static_cast<JSIReadFileCallback *>(deleter_data);
|
|
1332
|
-
}
|
|
1333
|
-
},
|
|
1334
|
-
jsi_callback);
|
|
1335
|
-
|
|
1336
|
-
args[1] = v8::ArrayBuffer::New(isolate, std::move(store));
|
|
1337
|
-
} else {
|
|
1338
|
-
auto error = jsi_callback->error_;
|
|
1339
|
-
args[0] = v8::Exception::Error(ConvertToV8String(isolate, error));
|
|
1340
|
-
args[1] = v8::Null(isolate);
|
|
1341
|
-
}
|
|
1342
|
-
|
|
1343
|
-
v8::TryCatch tc(isolate);
|
|
1344
|
-
v8::Local<v8::Value> result;
|
|
1345
|
-
if (!callback->Call(context, context->Global(), 2, args).ToLocal(
|
|
1346
|
-
&result)) {
|
|
1347
|
-
if (tc.HasCaught()) {
|
|
1348
|
-
|
|
1349
|
-
v8::Local<v8::Value> stack;
|
|
1350
|
-
bool success = tc.StackTrace(context).ToLocal(&stack);
|
|
1351
|
-
if (!success || stack.IsEmpty()) {
|
|
1352
|
-
if (!done) {
|
|
1353
|
-
delete jsi_callback;
|
|
1354
|
-
}
|
|
1355
|
-
return;
|
|
1356
|
-
}
|
|
1357
|
-
|
|
1358
|
-
v8::Local<v8::String> stackV8Str;
|
|
1359
|
-
success = stack->ToDetailString(context).ToLocal(&stackV8Str);
|
|
1360
|
-
if (!success || stackV8Str.IsEmpty()) {
|
|
1361
|
-
if (!done) {
|
|
1362
|
-
delete jsi_callback;
|
|
1363
|
-
}
|
|
1364
|
-
return;
|
|
1365
|
-
}
|
|
1366
|
-
LogToConsole(ConvertFromV8String(isolate, stackV8Str));
|
|
1367
|
-
|
|
1368
|
-
}
|
|
1369
|
-
}
|
|
1370
|
-
|
|
1371
|
-
if (!done) {
|
|
1372
|
-
delete jsi_callback;
|
|
1373
|
-
}
|
|
1374
|
-
|
|
1375
|
-
delete queue;
|
|
1376
|
-
delete current_queue;
|
|
1377
|
-
|
|
1378
|
-
};
|
|
1379
|
-
current_queue->addOperation(main_task);
|
|
1380
|
-
};
|
|
1381
|
-
|
|
1382
|
-
queue->addOperation(task);
|
|
1383
|
-
#endif
|
|
1384
|
-
|
|
726
|
+
|
|
727
|
+
|
|
1385
728
|
|
|
1386
729
|
}
|
|
1387
730
|
|