@nativescript/canvas 2.0.0-webgpu.11 → 2.0.0-webgpu.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Canvas/common.d.ts +3 -1
- package/Canvas/common.js +10 -0
- package/Canvas/common.js.map +1 -1
- package/Canvas/index.android.js +7 -7
- package/Canvas/index.android.js.map +1 -1
- package/Canvas/index.d.ts +11 -3
- package/Canvas/index.ios.js +14 -3
- package/Canvas/index.ios.js.map +1 -1
- package/ImageAsset/index.js +39 -17
- package/ImageAsset/index.js.map +1 -1
- package/ImageBitmap/index.js +18 -21
- package/ImageBitmap/index.js.map +1 -1
- package/WebGL/WebGLRenderingContext/index.js +74 -31
- package/WebGL/WebGLRenderingContext/index.js.map +1 -1
- package/WebGL2/WebGL2RenderingContext/index.js +4 -4
- package/WebGL2/WebGL2RenderingContext/index.js.map +1 -1
- package/WebGPU/GPU.js +4 -3
- package/WebGPU/GPU.js.map +1 -1
- package/WebGPU/GPUAdapter.d.ts +3 -2
- package/WebGPU/GPUAdapter.js +28 -0
- package/WebGPU/GPUAdapter.js.map +1 -1
- package/WebGPU/GPUCanvasContext.d.ts +1 -0
- package/WebGPU/GPUCanvasContext.js +17 -0
- package/WebGPU/GPUCanvasContext.js.map +1 -1
- package/WebGPU/GPUDevice.d.ts +3 -3
- package/WebGPU/GPUDevice.js +53 -13
- package/WebGPU/GPUDevice.js.map +1 -1
- package/angular/esm2022/index.mjs +4 -4
- package/angular/fesm2022/nativescript-canvas-angular.mjs +4 -4
- package/package.json +1 -1
- package/platforms/android/canvas-release.aar +0 -0
- package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/CanvasNative +0 -0
- package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Headers/CanvasNative-Swift.h +1 -0
- package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Headers/canvas_ios.h +7 -0
- package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Headers/canvas_native.h +170 -55
- package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Modules/CanvasNative.swiftmodule/Project/arm64-apple-ios.swiftsourceinfo +0 -0
- package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios.abi.json +6146 -6699
- package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios.private.swiftinterface +1 -0
- package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios.swiftinterface +1 -0
- 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 +647 -645
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/CanvasNative +0 -0
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Headers/CanvasNative-Swift.h +2 -0
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Headers/canvas_ios.h +7 -0
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Headers/canvas_native.h +170 -55
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/Project/arm64-apple-ios-simulator.swiftsourceinfo +0 -0
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/Project/x86_64-apple-ios-simulator.swiftsourceinfo +0 -0
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios-simulator.abi.json +6146 -6699
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios-simulator.private.swiftinterface +1 -0
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios-simulator.swiftinterface +1 -0
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/x86_64-apple-ios-simulator.abi.json +6146 -6699
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/x86_64-apple-ios-simulator.private.swiftinterface +1 -0
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/x86_64-apple-ios-simulator.swiftinterface +1 -0
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/_CodeSignature/CodeResources +26 -26
- 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 +649 -647
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/dSYMs/CanvasNative.framework.dSYM/Contents/Resources/Relocations/x86_64/CanvasNative.yml +687 -685
- package/platforms/ios/src/NSOperationQueueWrapper.h +1 -1
- package/platforms/ios/src/NSOperationQueueWrapper.mm +41 -9
- package/platforms/ios/src/cpp/AsyncCallback.h +16 -8
- package/platforms/ios/src/cpp/CanvasJSIModule.cpp +116 -44
- package/platforms/ios/src/cpp/ImageAssetImpl.cpp +16 -24
- package/platforms/ios/src/cpp/ImageAssetImpl.h +3 -3
- package/platforms/ios/src/cpp/ImageBitmapImpl.cpp +22 -3
- package/platforms/ios/src/cpp/ImageBitmapImpl.h +6 -3
- package/platforms/ios/src/cpp/PromiseCallback.h +1 -2
- package/platforms/ios/src/cpp/canvas2d/CanvasRenderingContext2DImpl.h +3 -3
- package/platforms/ios/src/cpp/webgl/WebGLRenderingContext.cpp +106 -1
- package/platforms/ios/src/cpp/webgpu/GPUAdapterImpl.cpp +7 -6
- package/platforms/ios/src/cpp/webgpu/GPUCommandEncoderImpl.cpp +437 -439
- package/platforms/ios/src/cpp/webgpu/GPUDeviceImpl.cpp +35 -55
- package/platforms/ios/src/cpp/webgpu/GPUImpl.cpp +2 -1
- package/platforms/ios/src/cpp/webgpu/GPULabel.h +33 -0
- package/platforms/ios/src/cpp/webgpu/GPUQueueImpl.cpp +23 -9
|
@@ -7,12 +7,16 @@
|
|
|
7
7
|
|
|
8
8
|
@implementation NSOperationQueueWrapperObjC {
|
|
9
9
|
NSOperationQueue* operationQueue;
|
|
10
|
+
__CFRunLoop* current;
|
|
11
|
+
BOOL isSerial;
|
|
10
12
|
}
|
|
11
13
|
|
|
12
14
|
- (instancetype)init {
|
|
13
15
|
self = [super init];
|
|
14
16
|
if (self) {
|
|
15
|
-
|
|
17
|
+
isSerial = false;
|
|
18
|
+
operationQueue = NULL;
|
|
19
|
+
current = NULL;
|
|
16
20
|
}
|
|
17
21
|
return self;
|
|
18
22
|
}
|
|
@@ -20,7 +24,15 @@
|
|
|
20
24
|
-(instancetype)initWithCurrentQueue {
|
|
21
25
|
self = [super init];
|
|
22
26
|
if (self) {
|
|
23
|
-
|
|
27
|
+
current = CFRunLoopGetCurrent();
|
|
28
|
+
}
|
|
29
|
+
return self;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
-(instancetype)initWithSerial:(BOOL)serial {
|
|
33
|
+
self = [super init];
|
|
34
|
+
if (self) {
|
|
35
|
+
isSerial = serial;
|
|
24
36
|
}
|
|
25
37
|
return self;
|
|
26
38
|
}
|
|
@@ -28,11 +40,32 @@
|
|
|
28
40
|
- (void)dealloc {}
|
|
29
41
|
|
|
30
42
|
- (void)addOperation:(void (^)())task {
|
|
31
|
-
NSBlockOperation* operation = [NSBlockOperation blockOperationWithBlock:^{
|
|
32
|
-
task();
|
|
33
|
-
}];
|
|
34
43
|
|
|
35
|
-
|
|
44
|
+
if(current != NULL){
|
|
45
|
+
if(current == CFRunLoopGetCurrent()){
|
|
46
|
+
task();
|
|
47
|
+
}else {
|
|
48
|
+
CFRunLoopPerformBlock(current, kCFRunLoopDefaultMode, ^{
|
|
49
|
+
task();
|
|
50
|
+
});
|
|
51
|
+
CFRunLoopWakeUp(current);
|
|
52
|
+
}
|
|
53
|
+
}else if(operationQueue != NULL){
|
|
54
|
+
NSBlockOperation* operation = [NSBlockOperation blockOperationWithBlock:^{
|
|
55
|
+
task();
|
|
56
|
+
}];
|
|
57
|
+
|
|
58
|
+
[operationQueue addOperation:operation];
|
|
59
|
+
}else if(isSerial){
|
|
60
|
+
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_SERIAL, 0), ^{
|
|
61
|
+
task();
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
}else {
|
|
65
|
+
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
|
|
66
|
+
task();
|
|
67
|
+
});
|
|
68
|
+
}
|
|
36
69
|
}
|
|
37
70
|
|
|
38
71
|
- (NSOperationQueue*)getOperationQueue {
|
|
@@ -42,7 +75,7 @@
|
|
|
42
75
|
|
|
43
76
|
@end
|
|
44
77
|
|
|
45
|
-
NSOperationQueueWrapper::NSOperationQueueWrapper(bool currentQueue) {
|
|
78
|
+
NSOperationQueueWrapper::NSOperationQueueWrapper(bool currentQueue, bool serial) {
|
|
46
79
|
if (currentQueue) {
|
|
47
80
|
NSOperationQueueWrapperObjC* objcWrapper = [[NSOperationQueueWrapperObjC alloc] initWithCurrentQueue];
|
|
48
81
|
|
|
@@ -50,11 +83,10 @@ NSOperationQueueWrapper::NSOperationQueueWrapper(bool currentQueue) {
|
|
|
50
83
|
|
|
51
84
|
operationQueue = (void*)ptr;
|
|
52
85
|
}else {
|
|
53
|
-
NSOperationQueueWrapperObjC* objcWrapper = [[NSOperationQueueWrapperObjC alloc]
|
|
86
|
+
NSOperationQueueWrapperObjC* objcWrapper = [[NSOperationQueueWrapperObjC alloc] initWithSerial: serial];
|
|
54
87
|
CFTypeRef ptr = (__bridge_retained CFTypeRef)objcWrapper;
|
|
55
88
|
operationQueue = (void*)ptr;
|
|
56
89
|
}
|
|
57
|
-
|
|
58
90
|
}
|
|
59
91
|
|
|
60
92
|
NSOperationQueueWrapper::~NSOperationQueueWrapper() {
|
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
|
|
20
20
|
#include <unistd.h>
|
|
21
21
|
#include <fcntl.h>
|
|
22
|
+
#include <thread>
|
|
22
23
|
|
|
23
24
|
typedef void(*CompleteCallback)(bool success, void *data);
|
|
24
25
|
|
|
@@ -45,14 +46,23 @@ struct AsyncCallback {
|
|
|
45
46
|
this->completeCallbackWrapper_ = [](bool success, void *data){
|
|
46
47
|
if(data != nullptr){
|
|
47
48
|
auto* callback = static_cast<AsyncCallback*>(data);
|
|
48
|
-
|
|
49
|
-
if(inner == nullptr || inner->current_queue == nullptr){
|
|
49
|
+
if(callback->inner_->current_queue == nullptr){
|
|
50
50
|
return;
|
|
51
51
|
}
|
|
52
|
-
|
|
52
|
+
|
|
53
|
+
auto inner = std::shared_ptr<Inner>(callback->inner_);
|
|
54
|
+
|
|
55
|
+
std::thread thread([success, data, callback](std::shared_ptr<Inner> inner){
|
|
56
|
+
inner->current_queue = nullptr;
|
|
53
57
|
inner->completeCallback_(success, data);
|
|
54
|
-
|
|
55
|
-
|
|
58
|
+
}, std::move(inner));
|
|
59
|
+
|
|
60
|
+
thread.detach();
|
|
61
|
+
|
|
62
|
+
// callback->inner_->current_queue->addOperation([success, data, callback, inner_ptr](){
|
|
63
|
+
// inner_ptr->completeCallback_(success, data);
|
|
64
|
+
// // delete callback;
|
|
65
|
+
// });
|
|
56
66
|
}
|
|
57
67
|
};
|
|
58
68
|
}
|
|
@@ -170,7 +180,7 @@ struct AsyncCallback {
|
|
|
170
180
|
auto data = new AsyncCallback(this->inner_);
|
|
171
181
|
ALooper_addFd(looper,
|
|
172
182
|
fd,
|
|
173
|
-
|
|
183
|
+
0,
|
|
174
184
|
ALOOPER_EVENT_INPUT,
|
|
175
185
|
[](int fd, int events,
|
|
176
186
|
void *data) {
|
|
@@ -181,8 +191,6 @@ struct AsyncCallback {
|
|
|
181
191
|
cb->inner_->completeCallback_(done, data);
|
|
182
192
|
return 0;
|
|
183
193
|
}, (void *) data);
|
|
184
|
-
|
|
185
|
-
ALooper_wake(looper);
|
|
186
194
|
}
|
|
187
195
|
|
|
188
196
|
void execute(bool complete) const {
|
|
@@ -285,7 +285,7 @@ void CanvasJSIModule::CreateImageBitmap(const v8::FunctionCallbackInfo<v8::Value
|
|
|
285
285
|
|
|
286
286
|
if (image->IsNullOrUndefined()) {
|
|
287
287
|
v8::Local<v8::Value> ret[2] = {ConvertToV8String(isolate, "Failed to load image"),
|
|
288
|
-
v8::
|
|
288
|
+
v8::Null(isolate)};
|
|
289
289
|
|
|
290
290
|
cb.As<v8::Function>()->Call(context, context->Global(), 2, ret);
|
|
291
291
|
return;
|
|
@@ -295,7 +295,7 @@ void CanvasJSIModule::CreateImageBitmap(const v8::FunctionCallbackInfo<v8::Value
|
|
|
295
295
|
|
|
296
296
|
v8::Local<v8::Value> ret[2] = {ConvertToV8String(isolate,
|
|
297
297
|
"Failed to execute 'createImageBitmap' : The crop rect width is 0"),
|
|
298
|
-
v8::
|
|
298
|
+
v8::Null(isolate)};
|
|
299
299
|
|
|
300
300
|
cb.As<v8::Function>()->Call(context, context->Global(), 2, ret);
|
|
301
301
|
|
|
@@ -304,7 +304,7 @@ void CanvasJSIModule::CreateImageBitmap(const v8::FunctionCallbackInfo<v8::Value
|
|
|
304
304
|
if (len >= 5 && (sh->IsNumber() && sh->IsNumber() == 0)) {
|
|
305
305
|
v8::Local<v8::Value> ret[2] = {ConvertToV8String(isolate,
|
|
306
306
|
"Failed to execute 'createImageBitmap' : The crop rect height is 0"),
|
|
307
|
-
v8::
|
|
307
|
+
v8::Null(isolate)};
|
|
308
308
|
|
|
309
309
|
cb.As<v8::Function>()->Call(context, context->Global(), 2, ret);
|
|
310
310
|
return;
|
|
@@ -338,16 +338,18 @@ void CanvasJSIModule::CreateImageBitmap(const v8::FunctionCallbackInfo<v8::Value
|
|
|
338
338
|
#ifdef __ANDROID__
|
|
339
339
|
ALooper_addFd(jsi_callback->looper_,
|
|
340
340
|
jsi_callback->fd_[0],
|
|
341
|
-
|
|
341
|
+
0,
|
|
342
342
|
ALOOPER_EVENT_INPUT,
|
|
343
343
|
[](int fd, int events,
|
|
344
344
|
void *data) {
|
|
345
|
+
if(data == nullptr){
|
|
346
|
+
return 1;
|
|
347
|
+
}
|
|
345
348
|
auto cb = static_cast<JSICallback *>(data);
|
|
346
349
|
bool done;
|
|
347
350
|
read(fd, &done,
|
|
348
351
|
sizeof(bool));
|
|
349
352
|
|
|
350
|
-
|
|
351
353
|
v8::Isolate *isolate = cb->isolate_;
|
|
352
354
|
v8::Locker locker(isolate);
|
|
353
355
|
v8::Isolate::Scope isolate_scope(isolate);
|
|
@@ -372,23 +374,23 @@ void CanvasJSIModule::CreateImageBitmap(const v8::FunctionCallbackInfo<v8::Value
|
|
|
372
374
|
args[1] = v8::Null(isolate);
|
|
373
375
|
}
|
|
374
376
|
|
|
375
|
-
|
|
376
377
|
callback->Call(context, context->Global(), 2, args);
|
|
377
378
|
|
|
378
379
|
delete static_cast<JSICallback *>(data);
|
|
379
380
|
return 0;
|
|
380
381
|
}, jsi_callback);
|
|
381
382
|
|
|
382
|
-
ALooper_wake(jsi_callback->looper_);
|
|
383
|
-
|
|
384
383
|
if (isArrayBuffer) {
|
|
384
|
+
// converting to Uint8Array
|
|
385
385
|
auto arrayBuffer = imageObject.As<v8::ArrayBuffer>();
|
|
386
|
-
auto
|
|
386
|
+
auto size = arrayBuffer->ByteLength();
|
|
387
|
+
imageObject = v8::Uint8Array::New(arrayBuffer, 0, size);
|
|
388
|
+
/* auto store = arrayBuffer->GetBackingStore();
|
|
387
389
|
auto dataBuffer = (uint8_t *) store->Data();
|
|
388
|
-
|
|
390
|
+
|
|
389
391
|
std::thread thread(
|
|
390
|
-
[&dataBuffer, jsi_callback, &options, store, shared_asset](
|
|
391
|
-
v8::Global<v8::ArrayBuffer> ab
|
|
392
|
+
[&dataBuffer, jsi_callback, &options, store, shared_asset, size](
|
|
393
|
+
v8::Global<v8::ArrayBuffer> ab) {
|
|
392
394
|
|
|
393
395
|
|
|
394
396
|
auto done = canvas_native_image_bitmap_create_from_encoded_bytes_with_output(
|
|
@@ -401,23 +403,24 @@ void CanvasJSIModule::CreateImageBitmap(const v8::FunctionCallbackInfo<v8::Value
|
|
|
401
403
|
options.resizeHeight,
|
|
402
404
|
shared_asset);
|
|
403
405
|
|
|
404
|
-
canvas_native_image_asset_release(shared_asset);
|
|
405
|
-
|
|
406
406
|
write(jsi_callback->fd_[1],
|
|
407
407
|
&done,
|
|
408
408
|
sizeof(bool));
|
|
409
409
|
|
|
410
|
+
// canvas_native_image_asset_release(shared_asset);
|
|
410
411
|
|
|
411
|
-
|
|
412
|
+
|
|
413
|
+
});
|
|
412
414
|
|
|
413
415
|
thread.detach();
|
|
414
416
|
return;
|
|
417
|
+
|
|
418
|
+
*/
|
|
415
419
|
}
|
|
416
420
|
|
|
417
421
|
|
|
418
422
|
auto ta = imageObject.As<v8::ArrayBufferView>();
|
|
419
423
|
|
|
420
|
-
|
|
421
424
|
auto array = ta->Buffer();
|
|
422
425
|
auto offset = ta->ByteOffset();
|
|
423
426
|
auto size = ta->ByteLength();
|
|
@@ -440,12 +443,12 @@ void CanvasJSIModule::CreateImageBitmap(const v8::FunctionCallbackInfo<v8::Value
|
|
|
440
443
|
options.resizeHeight,
|
|
441
444
|
shared_asset);
|
|
442
445
|
|
|
443
|
-
canvas_native_image_asset_release(shared_asset);
|
|
444
|
-
|
|
445
446
|
write(jsi_callback->fd_[1],
|
|
446
447
|
&done,
|
|
447
448
|
sizeof(bool));
|
|
448
449
|
|
|
450
|
+
// canvas_native_image_asset_release(shared_asset);
|
|
451
|
+
|
|
449
452
|
|
|
450
453
|
}, std::move(ab));
|
|
451
454
|
thread.detach();
|
|
@@ -464,9 +467,74 @@ void CanvasJSIModule::CreateImageBitmap(const v8::FunctionCallbackInfo<v8::Value
|
|
|
464
467
|
auto dataBuffer = (uint8_t *) store->Data();
|
|
465
468
|
v8::Global<v8::ArrayBuffer> ab(isolate, arrayBuffer);
|
|
466
469
|
|
|
470
|
+
auto size = arrayBuffer->ByteLength();
|
|
471
|
+
|
|
472
|
+
|
|
473
|
+
auto thread_queue = new NSOperationQueueWrapper(false);
|
|
474
|
+
|
|
475
|
+
|
|
476
|
+
thread_queue->addOperation([&dataBuffer, jsi_callback, &options, store, shared_asset, current_queue, &ab, size]() {
|
|
477
|
+
|
|
478
|
+
auto done = canvas_native_image_bitmap_create_from_encoded_bytes_with_output(
|
|
479
|
+
dataBuffer, size,
|
|
480
|
+
options.flipY,
|
|
481
|
+
options.premultiplyAlpha,
|
|
482
|
+
options.colorSpaceConversion,
|
|
483
|
+
options.resizeQuality,
|
|
484
|
+
options.resizeWidth,
|
|
485
|
+
options.resizeHeight,
|
|
486
|
+
shared_asset);
|
|
487
|
+
|
|
488
|
+
|
|
489
|
+
|
|
490
|
+
auto main_task = [jsi_callback, current_queue, done, shared_asset]() {
|
|
491
|
+
|
|
492
|
+
v8::Isolate *isolate = jsi_callback->isolate_;
|
|
493
|
+
v8::Locker locker(isolate);
|
|
494
|
+
v8::Isolate::Scope isolate_scope(isolate);
|
|
495
|
+
v8::HandleScope handle_scope(isolate);
|
|
496
|
+
v8::Local<v8::Function> callback = jsi_callback->callback_->Get(isolate);
|
|
497
|
+
v8::Local<v8::External> cbData = jsi_callback->data_->Get(
|
|
498
|
+
isolate).As<v8::External>();
|
|
499
|
+
v8::Local<v8::Context> context = callback->GetCreationContextChecked();
|
|
500
|
+
v8::Context::Scope context_scope(context);
|
|
501
|
+
|
|
502
|
+
auto ret = ImageBitmapImpl::NewInstance(isolate, cbData);
|
|
503
|
+
|
|
504
|
+
v8::Local<v8::Value> args[2];
|
|
505
|
+
|
|
506
|
+
if (done) {
|
|
507
|
+
args[0] = v8::Null(isolate);
|
|
508
|
+
args[1] = ret;
|
|
509
|
+
|
|
510
|
+
} else {
|
|
511
|
+
args[0] = v8::Exception::Error(
|
|
512
|
+
ConvertToV8String(isolate, "Failed to load image"));
|
|
513
|
+
args[1] = v8::Null(isolate);
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
|
|
517
|
+
callback->Call(context, context->Global(), 2, args);
|
|
518
|
+
|
|
519
|
+
delete jsi_callback;
|
|
520
|
+
delete current_queue;
|
|
521
|
+
|
|
522
|
+
canvas_native_image_asset_release(shared_asset);
|
|
523
|
+
|
|
524
|
+
};
|
|
525
|
+
current_queue->addOperation(main_task);
|
|
526
|
+
|
|
527
|
+
});
|
|
528
|
+
|
|
529
|
+
|
|
530
|
+
|
|
531
|
+
|
|
532
|
+
|
|
533
|
+
|
|
534
|
+
/*
|
|
467
535
|
std::thread thread(
|
|
468
|
-
[&dataBuffer, jsi_callback, &options, store, shared_asset, current_queue](
|
|
469
|
-
v8::Global<v8::ArrayBuffer> ab
|
|
536
|
+
[&dataBuffer, jsi_callback, &options, store, &shared_asset, current_queue, size](
|
|
537
|
+
v8::Global<v8::ArrayBuffer> ab
|
|
470
538
|
) {
|
|
471
539
|
|
|
472
540
|
auto done = canvas_native_image_bitmap_create_from_encoded_bytes_with_output(
|
|
@@ -479,10 +547,7 @@ void CanvasJSIModule::CreateImageBitmap(const v8::FunctionCallbackInfo<v8::Value
|
|
|
479
547
|
options.resizeHeight,
|
|
480
548
|
shared_asset);
|
|
481
549
|
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
auto main_task = [jsi_callback, current_queue, done]() {
|
|
550
|
+
auto main_task = [jsi_callback, current_queue, done, shared_asset]() {
|
|
486
551
|
|
|
487
552
|
|
|
488
553
|
v8::Isolate *isolate = jsi_callback->isolate_;
|
|
@@ -516,12 +581,17 @@ void CanvasJSIModule::CreateImageBitmap(const v8::FunctionCallbackInfo<v8::Value
|
|
|
516
581
|
delete jsi_callback;
|
|
517
582
|
delete current_queue;
|
|
518
583
|
|
|
584
|
+
canvas_native_image_asset_release(shared_asset);
|
|
585
|
+
|
|
519
586
|
};
|
|
520
587
|
current_queue->addOperation(main_task);
|
|
521
588
|
|
|
522
|
-
}, std::move(ab)
|
|
589
|
+
}, std::move(ab));
|
|
523
590
|
|
|
524
|
-
|
|
591
|
+
thread.detach();
|
|
592
|
+
|
|
593
|
+
|
|
594
|
+
*/
|
|
525
595
|
|
|
526
596
|
return;
|
|
527
597
|
}
|
|
@@ -553,9 +623,8 @@ void CanvasJSIModule::CreateImageBitmap(const v8::FunctionCallbackInfo<v8::Value
|
|
|
553
623
|
options.resizeHeight,
|
|
554
624
|
shared_asset);
|
|
555
625
|
|
|
556
|
-
canvas_native_image_asset_release(shared_asset);
|
|
557
626
|
|
|
558
|
-
auto main_task = [jsi_callback, current_queue, done]() {
|
|
627
|
+
auto main_task = [jsi_callback, current_queue, done, shared_asset]() {
|
|
559
628
|
|
|
560
629
|
|
|
561
630
|
v8::Isolate *isolate = jsi_callback->isolate_;
|
|
@@ -587,6 +656,8 @@ void CanvasJSIModule::CreateImageBitmap(const v8::FunctionCallbackInfo<v8::Value
|
|
|
587
656
|
delete jsi_callback;
|
|
588
657
|
delete current_queue;
|
|
589
658
|
|
|
659
|
+
canvas_native_image_asset_release(shared_asset);
|
|
660
|
+
|
|
590
661
|
};
|
|
591
662
|
current_queue->addOperation(main_task);
|
|
592
663
|
|
|
@@ -617,7 +688,7 @@ void CanvasJSIModule::CreateImageBitmap(const v8::FunctionCallbackInfo<v8::Value
|
|
|
617
688
|
#ifdef __ANDROID__
|
|
618
689
|
ALooper_addFd(jsi_callback->looper_,
|
|
619
690
|
jsi_callback->fd_[0],
|
|
620
|
-
|
|
691
|
+
0,
|
|
621
692
|
ALOOPER_EVENT_INPUT,
|
|
622
693
|
[](int fd, int events,
|
|
623
694
|
void *data) {
|
|
@@ -655,11 +726,13 @@ void CanvasJSIModule::CreateImageBitmap(const v8::FunctionCallbackInfo<v8::Value
|
|
|
655
726
|
return 0;
|
|
656
727
|
}, jsi_callback);
|
|
657
728
|
|
|
658
|
-
ALooper_wake(jsi_callback->looper_);
|
|
659
|
-
|
|
660
729
|
auto bufferValue = args[0];
|
|
661
730
|
|
|
662
731
|
if (isArrayBuffer) {
|
|
732
|
+
auto arrayBuffer = bufferValue.As<v8::ArrayBuffer>();
|
|
733
|
+
auto size = arrayBuffer->ByteLength();
|
|
734
|
+
imageObject = v8::Uint8Array::New(arrayBuffer, 0, size);
|
|
735
|
+
/*
|
|
663
736
|
auto arrayBuffer = bufferValue.As<v8::ArrayBuffer>();
|
|
664
737
|
auto dataBuffer = (uint8_t *) arrayBuffer->GetBackingStore()->Data();
|
|
665
738
|
v8::Global<v8::ArrayBuffer> ab(isolate, arrayBuffer);
|
|
@@ -686,13 +759,12 @@ void CanvasJSIModule::CreateImageBitmap(const v8::FunctionCallbackInfo<v8::Value
|
|
|
686
759
|
options.resizeWidth,
|
|
687
760
|
options.resizeHeight, shared_asset);
|
|
688
761
|
|
|
689
|
-
canvas_native_image_asset_release(shared_asset);
|
|
690
|
-
|
|
691
|
-
|
|
692
762
|
write(jsi_callback->fd_[1],
|
|
693
763
|
&done,
|
|
694
764
|
sizeof(bool));
|
|
695
765
|
|
|
766
|
+
canvas_native_image_asset_release(shared_asset);
|
|
767
|
+
|
|
696
768
|
},
|
|
697
769
|
(float) sx_or_options->NumberValue(context).ToChecked(),
|
|
698
770
|
(float) sy->NumberValue(context).ToChecked(),
|
|
@@ -703,6 +775,7 @@ void CanvasJSIModule::CreateImageBitmap(const v8::FunctionCallbackInfo<v8::Value
|
|
|
703
775
|
thread.detach();
|
|
704
776
|
|
|
705
777
|
return;
|
|
778
|
+
*/
|
|
706
779
|
}
|
|
707
780
|
|
|
708
781
|
auto ta = bufferValue.As<v8::ArrayBufferView>();
|
|
@@ -736,13 +809,13 @@ void CanvasJSIModule::CreateImageBitmap(const v8::FunctionCallbackInfo<v8::Value
|
|
|
736
809
|
options.resizeWidth,
|
|
737
810
|
options.resizeHeight, shared_asset);
|
|
738
811
|
|
|
739
|
-
canvas_native_image_asset_release(shared_asset);
|
|
740
|
-
|
|
741
812
|
|
|
742
813
|
write(jsi_callback->fd_[1],
|
|
743
814
|
&done,
|
|
744
815
|
sizeof(bool));
|
|
745
816
|
|
|
817
|
+
canvas_native_image_asset_release(shared_asset);
|
|
818
|
+
|
|
746
819
|
},
|
|
747
820
|
(float) sx_or_options->NumberValue(context).ToChecked(),
|
|
748
821
|
(float) sy->NumberValue(context).ToChecked(),
|
|
@@ -786,10 +859,8 @@ void CanvasJSIModule::CreateImageBitmap(const v8::FunctionCallbackInfo<v8::Value
|
|
|
786
859
|
options.resizeWidth,
|
|
787
860
|
options.resizeHeight, shared_asset);
|
|
788
861
|
|
|
789
|
-
canvas_native_image_asset_release(shared_asset);
|
|
790
|
-
|
|
791
862
|
|
|
792
|
-
auto main_task = [jsi_callback, current_queue, done]() {
|
|
863
|
+
auto main_task = [jsi_callback, current_queue, done,shared_asset]() {
|
|
793
864
|
|
|
794
865
|
|
|
795
866
|
v8::Isolate *isolate = jsi_callback->isolate_;
|
|
@@ -823,6 +894,8 @@ void CanvasJSIModule::CreateImageBitmap(const v8::FunctionCallbackInfo<v8::Value
|
|
|
823
894
|
delete jsi_callback;
|
|
824
895
|
delete current_queue;
|
|
825
896
|
|
|
897
|
+
canvas_native_image_asset_release(shared_asset);
|
|
898
|
+
|
|
826
899
|
};
|
|
827
900
|
current_queue->addOperation(main_task);
|
|
828
901
|
|
|
@@ -871,9 +944,8 @@ void CanvasJSIModule::CreateImageBitmap(const v8::FunctionCallbackInfo<v8::Value
|
|
|
871
944
|
options.resizeWidth,
|
|
872
945
|
options.resizeHeight, shared_asset);
|
|
873
946
|
|
|
874
|
-
canvas_native_image_asset_release(shared_asset);
|
|
875
947
|
|
|
876
|
-
auto main_task = [jsi_callback, current_queue, done]() {
|
|
948
|
+
auto main_task = [jsi_callback, current_queue, done, shared_asset]() {
|
|
877
949
|
|
|
878
950
|
|
|
879
951
|
v8::Isolate *isolate = jsi_callback->isolate_;
|
|
@@ -905,6 +977,8 @@ void CanvasJSIModule::CreateImageBitmap(const v8::FunctionCallbackInfo<v8::Value
|
|
|
905
977
|
delete jsi_callback;
|
|
906
978
|
delete current_queue;
|
|
907
979
|
|
|
980
|
+
canvas_native_image_asset_release(shared_asset);
|
|
981
|
+
|
|
908
982
|
};
|
|
909
983
|
current_queue->addOperation(main_task);
|
|
910
984
|
|
|
@@ -1080,7 +1154,7 @@ void CanvasJSIModule::ReadFile(const v8::FunctionCallbackInfo<v8::Value> &args)
|
|
|
1080
1154
|
#ifdef __ANDROID__
|
|
1081
1155
|
ALooper_addFd(jsi_callback->looper_,
|
|
1082
1156
|
jsi_callback->fd_[0],
|
|
1083
|
-
|
|
1157
|
+
0,
|
|
1084
1158
|
ALOOPER_EVENT_INPUT,
|
|
1085
1159
|
[](int fd, int events,
|
|
1086
1160
|
void *data) {
|
|
@@ -1165,8 +1239,6 @@ void CanvasJSIModule::ReadFile(const v8::FunctionCallbackInfo<v8::Value> &args)
|
|
|
1165
1239
|
return 0;
|
|
1166
1240
|
}, jsi_callback);
|
|
1167
1241
|
|
|
1168
|
-
ALooper_wake(jsi_callback->looper_);
|
|
1169
|
-
|
|
1170
1242
|
std::thread thread(
|
|
1171
1243
|
[jsi_callback](const std::string &file) {
|
|
1172
1244
|
bool done = false;
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
#include "Helpers.h"
|
|
12
12
|
#include "Common.h"
|
|
13
13
|
|
|
14
|
-
ImageAssetImpl::ImageAssetImpl(ImageAsset *asset) : asset_(asset) {
|
|
14
|
+
ImageAssetImpl::ImageAssetImpl(const ImageAsset *asset) : asset_(asset) {
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
ImageAssetImpl::~ImageAssetImpl() {
|
|
@@ -240,7 +240,7 @@ void ImageAssetImpl::FromUrlCb(const v8::FunctionCallbackInfo<v8::Value> &args)
|
|
|
240
240
|
|
|
241
241
|
ALooper_addFd(jsi_callback->looper_,
|
|
242
242
|
jsi_callback->fd_[0],
|
|
243
|
-
|
|
243
|
+
0,
|
|
244
244
|
ALOOPER_EVENT_INPUT,
|
|
245
245
|
[](int fd, int events,
|
|
246
246
|
void *data) {
|
|
@@ -269,8 +269,6 @@ void ImageAssetImpl::FromUrlCb(const v8::FunctionCallbackInfo<v8::Value> &args)
|
|
|
269
269
|
return 0;
|
|
270
270
|
}, jsi_callback);
|
|
271
271
|
|
|
272
|
-
ALooper_wake(jsi_callback->looper_);
|
|
273
|
-
|
|
274
272
|
|
|
275
273
|
std::thread thread(
|
|
276
274
|
[jsi_callback, asset](
|
|
@@ -412,19 +410,17 @@ void ImageAssetImpl::FromFileCb(const v8::FunctionCallbackInfo<v8::Value> &args)
|
|
|
412
410
|
|
|
413
411
|
auto path = ConvertFromV8String(isolate, args[0]);
|
|
414
412
|
|
|
415
|
-
auto asset = canvas_native_image_asset_reference(
|
|
416
|
-
ptr->GetImageAsset());
|
|
413
|
+
auto asset = canvas_native_image_asset_reference(ptr->GetImageAsset());
|
|
417
414
|
|
|
418
415
|
auto callback = args[1].As<v8::Function>();
|
|
419
416
|
|
|
420
|
-
|
|
421
417
|
auto jsi_callback = new JSICallback(isolate, callback);
|
|
422
418
|
|
|
423
419
|
#ifdef __ANDROID__
|
|
424
420
|
|
|
425
421
|
ALooper_addFd(jsi_callback->looper_,
|
|
426
422
|
jsi_callback->fd_[0],
|
|
427
|
-
|
|
423
|
+
0,
|
|
428
424
|
ALOOPER_EVENT_INPUT,
|
|
429
425
|
[](int fd, int events,
|
|
430
426
|
void *data) {
|
|
@@ -443,7 +439,7 @@ void ImageAssetImpl::FromFileCb(const v8::FunctionCallbackInfo<v8::Value> &args)
|
|
|
443
439
|
|
|
444
440
|
v8::Local<v8::Value> args[1] = {v8::Boolean::New(isolate, done)};
|
|
445
441
|
|
|
446
|
-
|
|
442
|
+
v8::TryCatch tc(isolate);
|
|
447
443
|
|
|
448
444
|
callback->Call(context, context->Global(), 1,
|
|
449
445
|
args); // ignore JS return value
|
|
@@ -452,23 +448,23 @@ void ImageAssetImpl::FromFileCb(const v8::FunctionCallbackInfo<v8::Value> &args)
|
|
|
452
448
|
return 0;
|
|
453
449
|
}, jsi_callback);
|
|
454
450
|
|
|
455
|
-
ALooper_wake(jsi_callback->looper_);
|
|
456
|
-
|
|
457
451
|
|
|
458
452
|
std::thread thread(
|
|
459
453
|
[jsi_callback, asset](
|
|
460
|
-
const std::string
|
|
454
|
+
const std::string path) {
|
|
461
455
|
|
|
462
456
|
auto done = canvas_native_image_asset_load_from_path(asset, path.c_str());
|
|
463
457
|
|
|
464
|
-
canvas_native_image_asset_release(asset);
|
|
465
|
-
|
|
466
458
|
write(jsi_callback->fd_[1],
|
|
467
459
|
&done,
|
|
468
460
|
sizeof(bool));
|
|
469
461
|
|
|
462
|
+
canvas_native_image_asset_release(asset);
|
|
463
|
+
|
|
470
464
|
}, std::move(path));
|
|
471
465
|
|
|
466
|
+
thread.detach();
|
|
467
|
+
|
|
472
468
|
#endif
|
|
473
469
|
|
|
474
470
|
|
|
@@ -481,7 +477,7 @@ void ImageAssetImpl::FromFileCb(const v8::FunctionCallbackInfo<v8::Value> &args)
|
|
|
481
477
|
auto task = [jsi_callback, current_queue, queue, asset, path]() {
|
|
482
478
|
|
|
483
479
|
auto done = canvas_native_image_asset_load_from_path(asset, path.c_str());
|
|
484
|
-
|
|
480
|
+
|
|
485
481
|
canvas_native_image_asset_release(asset);
|
|
486
482
|
|
|
487
483
|
auto main_task = [jsi_callback, current_queue, queue, done]() {
|
|
@@ -514,6 +510,8 @@ void ImageAssetImpl::FromFileCb(const v8::FunctionCallbackInfo<v8::Value> &args)
|
|
|
514
510
|
};
|
|
515
511
|
|
|
516
512
|
queue->addOperation(task);
|
|
513
|
+
|
|
514
|
+
|
|
517
515
|
#endif
|
|
518
516
|
}
|
|
519
517
|
|
|
@@ -572,7 +570,7 @@ void ImageAssetImpl::FromBytesCb(const v8::FunctionCallbackInfo<v8::Value> &args
|
|
|
572
570
|
|
|
573
571
|
ALooper_addFd(jsi_callback->looper_,
|
|
574
572
|
jsi_callback->fd_[0],
|
|
575
|
-
|
|
573
|
+
0,
|
|
576
574
|
ALOOPER_EVENT_INPUT,
|
|
577
575
|
[](int fd, int events,
|
|
578
576
|
void *data) {
|
|
@@ -600,9 +598,6 @@ void ImageAssetImpl::FromBytesCb(const v8::FunctionCallbackInfo<v8::Value> &args
|
|
|
600
598
|
return 0;
|
|
601
599
|
}, jsi_callback);
|
|
602
600
|
|
|
603
|
-
ALooper_wake(jsi_callback->looper_);
|
|
604
|
-
|
|
605
|
-
|
|
606
601
|
std::thread thread(
|
|
607
602
|
[jsi_callback, asset, data, size]() {
|
|
608
603
|
|
|
@@ -713,7 +708,7 @@ void ImageAssetImpl::SaveCb(const v8::FunctionCallbackInfo<v8::Value> &args) {
|
|
|
713
708
|
|
|
714
709
|
ALooper_addFd(jsi_callback->looper_,
|
|
715
710
|
jsi_callback->fd_[0],
|
|
716
|
-
|
|
711
|
+
0,
|
|
717
712
|
ALOOPER_EVENT_INPUT,
|
|
718
713
|
[](int fd, int events,
|
|
719
714
|
void *data) {
|
|
@@ -741,9 +736,6 @@ void ImageAssetImpl::SaveCb(const v8::FunctionCallbackInfo<v8::Value> &args) {
|
|
|
741
736
|
return 0;
|
|
742
737
|
}, jsi_callback);
|
|
743
738
|
|
|
744
|
-
ALooper_wake(jsi_callback->looper_);
|
|
745
|
-
|
|
746
|
-
|
|
747
739
|
std::thread thread(
|
|
748
740
|
[jsi_callback, asset, format](
|
|
749
741
|
const std::string &path) {
|
|
@@ -813,7 +805,7 @@ void ImageAssetImpl::SaveCb(const v8::FunctionCallbackInfo<v8::Value> &args) {
|
|
|
813
805
|
}
|
|
814
806
|
*/
|
|
815
807
|
|
|
816
|
-
ImageAsset *ImageAssetImpl::GetImageAsset() {
|
|
808
|
+
const ImageAsset *ImageAssetImpl::GetImageAsset() {
|
|
817
809
|
return this->asset_;
|
|
818
810
|
}
|
|
819
811
|
|