@nativescript/canvas 2.0.0-webgpu.4 → 2.0.0-webgpu.40
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 +5 -10
- package/Canvas/common.js +61 -144
- package/Canvas/common.js.map +1 -1
- package/Canvas/index.android.d.ts +6 -5
- package/Canvas/index.android.js +63 -42
- package/Canvas/index.android.js.map +1 -1
- package/Canvas/index.d.ts +13 -3
- package/Canvas/index.ios.d.ts +9 -1
- package/Canvas/index.ios.js +117 -66
- package/Canvas/index.ios.js.map +1 -1
- package/Canvas/utils.d.ts +3 -0
- package/Canvas/utils.js +85 -0
- package/Canvas/utils.js.map +1 -0
- package/Canvas2D/CanvasRenderingContext2D/index.d.ts +3 -1
- package/Canvas2D/CanvasRenderingContext2D/index.js +2 -4
- package/Canvas2D/CanvasRenderingContext2D/index.js.map +1 -1
- package/Dom/Group.d.ts +1 -2
- package/Dom/Group.js.map +1 -1
- package/Dom/Image.js +0 -1
- package/Dom/Image.js.map +1 -1
- package/Dom/Paint.d.ts +1 -1
- package/Dom/shapes/Path.d.ts +1 -1
- package/ImageAsset/index.d.ts +4 -2
- package/ImageAsset/index.js +151 -37
- package/ImageAsset/index.js.map +1 -1
- package/ImageBitmap/index.js +107 -20
- package/ImageBitmap/index.js.map +1 -1
- package/README.md +2 -4
- package/WebGL/WebGLRenderingContext/common.d.ts +1 -1
- package/WebGL/WebGLRenderingContext/index.js +76 -32
- package/WebGL/WebGLRenderingContext/index.js.map +1 -1
- package/WebGL2/WebGL2RenderingContext/index.js +5 -5
- 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 +6 -3
- package/WebGPU/GPUAdapter.js +31 -0
- package/WebGPU/GPUAdapter.js.map +1 -1
- package/WebGPU/GPUBindGroup.d.ts +1 -0
- package/WebGPU/GPUBindGroup.js +3 -0
- package/WebGPU/GPUBindGroup.js.map +1 -1
- package/WebGPU/GPUBindGroupLayout.d.ts +1 -0
- package/WebGPU/GPUBindGroupLayout.js +3 -0
- package/WebGPU/GPUBindGroupLayout.js.map +1 -1
- package/WebGPU/GPUBuffer.js +10 -2
- package/WebGPU/GPUBuffer.js.map +1 -1
- package/WebGPU/GPUCanvasContext.d.ts +5 -3
- package/WebGPU/GPUCanvasContext.js +52 -10
- package/WebGPU/GPUCanvasContext.js.map +1 -1
- package/WebGPU/GPUCommandBuffer.d.ts +1 -0
- package/WebGPU/GPUCommandBuffer.js +3 -0
- package/WebGPU/GPUCommandBuffer.js.map +1 -1
- package/WebGPU/GPUCommandEncoder.d.ts +3 -9
- package/WebGPU/GPUCommandEncoder.js +94 -41
- package/WebGPU/GPUCommandEncoder.js.map +1 -1
- package/WebGPU/GPUComputePassEncoder.d.ts +1 -0
- package/WebGPU/GPUComputePassEncoder.js +3 -0
- package/WebGPU/GPUComputePassEncoder.js.map +1 -1
- package/WebGPU/GPUComputePipeline.d.ts +1 -0
- package/WebGPU/GPUComputePipeline.js +3 -0
- package/WebGPU/GPUComputePipeline.js.map +1 -1
- package/WebGPU/GPUDevice.d.ts +17 -79
- package/WebGPU/GPUDevice.js +75 -91
- package/WebGPU/GPUDevice.js.map +1 -1
- package/WebGPU/GPUExternalTexture.d.ts +1 -0
- package/WebGPU/GPUExternalTexture.js +3 -0
- package/WebGPU/GPUExternalTexture.js.map +1 -1
- package/WebGPU/GPUPipelineLayout.d.ts +1 -0
- package/WebGPU/GPUPipelineLayout.js +3 -0
- package/WebGPU/GPUPipelineLayout.js.map +1 -1
- package/WebGPU/GPUQuerySet.d.ts +1 -0
- package/WebGPU/GPUQuerySet.js +3 -0
- package/WebGPU/GPUQuerySet.js.map +1 -1
- package/WebGPU/GPUQueue.d.ts +1 -0
- package/WebGPU/GPUQueue.js +65 -14
- package/WebGPU/GPUQueue.js.map +1 -1
- package/WebGPU/GPURenderBundle.d.ts +1 -0
- package/WebGPU/GPURenderBundle.js +3 -0
- package/WebGPU/GPURenderBundle.js.map +1 -1
- package/WebGPU/GPURenderBundleEncoder.d.ts +4 -2
- package/WebGPU/GPURenderBundleEncoder.js +7 -3
- package/WebGPU/GPURenderBundleEncoder.js.map +1 -1
- package/WebGPU/GPURenderPassEncoder.d.ts +5 -1
- package/WebGPU/GPURenderPassEncoder.js +14 -2
- package/WebGPU/GPURenderPassEncoder.js.map +1 -1
- package/WebGPU/GPURenderPipeline.d.ts +1 -0
- package/WebGPU/GPURenderPipeline.js +3 -0
- package/WebGPU/GPURenderPipeline.js.map +1 -1
- package/WebGPU/GPUSampler.d.ts +1 -0
- package/WebGPU/GPUSampler.js +3 -0
- package/WebGPU/GPUSampler.js.map +1 -1
- package/WebGPU/GPUShaderModule.d.ts +1 -1
- package/WebGPU/GPUShaderModule.js +2 -2
- package/WebGPU/GPUShaderModule.js.map +1 -1
- package/WebGPU/GPUTexture.d.ts +1 -0
- package/WebGPU/GPUTexture.js +3 -0
- package/WebGPU/GPUTexture.js.map +1 -1
- package/WebGPU/GPUTextureView.d.ts +1 -0
- package/WebGPU/GPUTextureView.js +3 -0
- package/WebGPU/GPUTextureView.js.map +1 -1
- package/WebGPU/Interfaces.d.ts +95 -4
- package/WebGPU/Types.d.ts +9 -1
- package/WebGPU/Utils.d.ts +6 -0
- package/WebGPU/Utils.js +226 -0
- package/WebGPU/Utils.js.map +1 -1
- package/angular/esm2022/index.mjs +4 -4
- package/angular/fesm2022/nativescript-canvas-angular.mjs +4 -4
- package/angular/fesm2022/nativescript-canvas-angular.mjs.map +1 -1
- package/common.js.map +1 -1
- package/index.d.ts +2 -1
- package/index.js +3 -2
- package/index.js.map +1 -1
- package/package.json +1 -1
- package/platforms/android/canvas-release.aar +0 -0
- package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/CanvasNative +0 -0
- package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Headers/CanvasNative-Swift.h +61 -30
- package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Headers/CanvasNative.h +1 -0
- package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Headers/NSCMTLView.h +32 -0
- package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Headers/canvas_ios.h +144 -176
- package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Headers/canvas_native.h +342 -72
- package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Info.plist +0 -0
- package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Modules/CanvasNative.swiftmodule/Project/arm64-apple-ios.swiftsourceinfo +0 -0
- package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios.abi.json +7997 -5995
- package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios.private.swiftinterface +85 -23
- package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios.swiftdoc +0 -0
- package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios.swiftinterface +85 -23
- package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/NSCCanvas.nib +0 -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 +681 -644
- 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 +122 -60
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Headers/CanvasNative.h +1 -0
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Headers/NSCMTLView.h +32 -0
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Headers/canvas_ios.h +144 -176
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Headers/canvas_native.h +342 -72
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Info.plist +0 -0
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/Project/arm64-apple-ios-simulator.swiftsourceinfo +0 -0
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/Project/x86_64-apple-ios-simulator.swiftsourceinfo +0 -0
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios-simulator.abi.json +7997 -5995
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios-simulator.private.swiftinterface +85 -23
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios-simulator.swiftdoc +0 -0
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios-simulator.swiftinterface +85 -23
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/x86_64-apple-ios-simulator.abi.json +7997 -5995
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/x86_64-apple-ios-simulator.private.swiftinterface +85 -23
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/x86_64-apple-ios-simulator.swiftdoc +0 -0
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/x86_64-apple-ios-simulator.swiftinterface +85 -23
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/NSCCanvas.nib +0 -0
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/_CodeSignature/CodeResources +40 -29
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/dSYMs/CanvasNative.framework.dSYM/Contents/Resources/DWARF/CanvasNative +0 -0
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/dSYMs/CanvasNative.framework.dSYM/Contents/Resources/Relocations/aarch64/CanvasNative.yml +683 -646
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/dSYMs/CanvasNative.framework.dSYM/Contents/Resources/Relocations/x86_64/CanvasNative.yml +736 -684
- 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 +310 -801
- package/platforms/ios/src/cpp/CanvasJSIModule.h +2 -0
- package/platforms/ios/src/cpp/ImageAssetImpl.cpp +578 -413
- package/platforms/ios/src/cpp/ImageAssetImpl.h +7 -3
- package/platforms/ios/src/cpp/ImageBitmapImpl.cpp +60 -3
- package/platforms/ios/src/cpp/ImageBitmapImpl.h +10 -3
- package/platforms/ios/src/cpp/PromiseCallback.h +1 -2
- package/platforms/ios/src/cpp/canvas2d/CanvasRenderingContext2DImpl.cpp +7 -11
- package/platforms/ios/src/cpp/canvas2d/CanvasRenderingContext2DImpl.h +3 -3
- package/platforms/ios/src/cpp/canvas2d/Path2D.h +5 -5
- package/platforms/ios/src/cpp/webgl/WebGLRenderingContext.cpp +106 -1
- package/platforms/ios/src/cpp/webgl/WebGLRenderingContextBase.cpp +6 -6
- package/platforms/ios/src/cpp/webgpu/GPUAdapterImpl.cpp +26 -23
- package/platforms/ios/src/cpp/webgpu/GPUBindGroupImpl.cpp +31 -5
- package/platforms/ios/src/cpp/webgpu/GPUBindGroupImpl.h +4 -1
- package/platforms/ios/src/cpp/webgpu/GPUBindGroupLayoutImpl.cpp +26 -0
- package/platforms/ios/src/cpp/webgpu/GPUBindGroupLayoutImpl.h +3 -0
- package/platforms/ios/src/cpp/webgpu/GPUBufferImpl.cpp +41 -7
- package/platforms/ios/src/cpp/webgpu/GPUBufferImpl.h +4 -0
- package/platforms/ios/src/cpp/webgpu/GPUCanvasContextImpl.cpp +11 -5
- package/platforms/ios/src/cpp/webgpu/GPUCommandBufferImpl.cpp +28 -1
- package/platforms/ios/src/cpp/webgpu/GPUCommandBufferImpl.h +3 -0
- package/platforms/ios/src/cpp/webgpu/GPUCommandEncoderImpl.cpp +75 -79
- package/platforms/ios/src/cpp/webgpu/GPUCommandEncoderImpl.h +4 -0
- package/platforms/ios/src/cpp/webgpu/GPUComputePassEncoderImpl.cpp +56 -23
- package/platforms/ios/src/cpp/webgpu/GPUComputePassEncoderImpl.h +3 -0
- package/platforms/ios/src/cpp/webgpu/GPUComputePipelineImpl.cpp +25 -0
- package/platforms/ios/src/cpp/webgpu/GPUComputePipelineImpl.h +2 -0
- package/platforms/ios/src/cpp/webgpu/GPUDeviceImpl.cpp +1606 -681
- package/platforms/ios/src/cpp/webgpu/GPUDeviceImpl.h +2 -0
- package/platforms/ios/src/cpp/webgpu/GPUImpl.cpp +2 -1
- package/platforms/ios/src/cpp/webgpu/GPUImpl.h +1 -1
- package/platforms/ios/src/cpp/webgpu/GPULabel.h +33 -0
- package/platforms/ios/src/cpp/webgpu/GPUPipelineLayoutImpl.cpp +26 -0
- package/platforms/ios/src/cpp/webgpu/GPUPipelineLayoutImpl.h +3 -1
- package/platforms/ios/src/cpp/webgpu/GPUQuerySetImpl.cpp +1 -2
- package/platforms/ios/src/cpp/webgpu/GPUQuerySetImpl.h +1 -1
- package/platforms/ios/src/cpp/webgpu/GPUQueueImpl.cpp +83 -14
- package/platforms/ios/src/cpp/webgpu/GPUQueueImpl.h +3 -0
- package/platforms/ios/src/cpp/webgpu/GPURenderBundleEncoderImpl.cpp +66 -34
- package/platforms/ios/src/cpp/webgpu/GPURenderBundleEncoderImpl.h +3 -0
- package/platforms/ios/src/cpp/webgpu/GPURenderBundleImpl.cpp +25 -0
- package/platforms/ios/src/cpp/webgpu/GPURenderBundleImpl.h +3 -0
- package/platforms/ios/src/cpp/webgpu/GPURenderPassEncoderImpl.cpp +151 -52
- package/platforms/ios/src/cpp/webgpu/GPURenderPassEncoderImpl.h +7 -0
- package/platforms/ios/src/cpp/webgpu/GPURenderPipelineImpl.cpp +25 -0
- package/platforms/ios/src/cpp/webgpu/GPURenderPipelineImpl.h +3 -0
- package/platforms/ios/src/cpp/webgpu/GPUSamplerImpl.cpp +26 -0
- package/platforms/ios/src/cpp/webgpu/GPUSamplerImpl.h +4 -1
- package/platforms/ios/src/cpp/webgpu/GPUShaderModuleImpl.cpp +24 -0
- package/platforms/ios/src/cpp/webgpu/GPUShaderModuleImpl.h +3 -0
- package/platforms/ios/src/cpp/webgpu/GPUTextureImpl.cpp +34 -8
- package/platforms/ios/src/cpp/webgpu/GPUTextureImpl.h +2 -0
- package/platforms/ios/src/cpp/webgpu/GPUTextureViewImpl.cpp +26 -0
- package/platforms/ios/src/cpp/webgpu/GPUTextureViewImpl.h +3 -0
- package/platforms/ios/src/cpp/webgpu/GPUUtils.h +511 -0
- package/utils.d.ts +1 -1
|
@@ -145,6 +145,7 @@ void CanvasJSIModule::install(v8::Isolate *isolate) {
|
|
|
145
145
|
Path2D::Init(canvasMod, isolate);
|
|
146
146
|
ImageDataImpl::Init(canvasMod, isolate);
|
|
147
147
|
ImageAssetImpl::Init(canvasMod, isolate);
|
|
148
|
+
ImageBitmapImpl::Init(canvasMod, isolate);
|
|
148
149
|
CanvasGradient::Init(canvasMod, isolate);
|
|
149
150
|
CanvasPattern::Init(canvasMod, isolate);
|
|
150
151
|
MatrixImpl::Init(canvasMod, isolate);
|
|
@@ -177,6 +178,10 @@ void CanvasJSIModule::install(v8::Isolate *isolate) {
|
|
|
177
178
|
v8::FunctionTemplate::New(isolate, &ReadFile)->GetFunction(
|
|
178
179
|
context).ToLocalChecked()).FromJust();
|
|
179
180
|
|
|
181
|
+
canvasMod->Set(context, ConvertToV8String(isolate, "getMime"),
|
|
182
|
+
v8::FunctionTemplate::New(isolate, &GetMime)->GetFunction(
|
|
183
|
+
context).ToLocalChecked()).FromJust();
|
|
184
|
+
|
|
180
185
|
canvasMod->Set(context, ConvertToV8String(isolate, "createWebGLContext"),
|
|
181
186
|
v8::FunctionTemplate::New(isolate, &CreateWebGLContext)->GetFunction(
|
|
182
187
|
context).ToLocalChecked()).FromJust();
|
|
@@ -231,19 +236,8 @@ void CanvasJSIModule::Create2DContext(const v8::FunctionCallbackInfo<v8::Value>
|
|
|
231
236
|
auto isolate = args.GetIsolate();
|
|
232
237
|
auto context = isolate->GetCurrentContext();
|
|
233
238
|
auto ptr = args[0].As<v8::BigInt>()->Int64Value();
|
|
234
|
-
|
|
235
|
-
auto
|
|
236
|
-
auto density = (float) args[3]->NumberValue(context).ToChecked();
|
|
237
|
-
auto samples = (int) args[4]->NumberValue(context).ToChecked();
|
|
238
|
-
auto alpha = (bool) args[5]->BooleanValue(isolate);
|
|
239
|
-
auto font_color = (int) args[6]->NumberValue(context).ToChecked();
|
|
240
|
-
auto ppi = (float) args[7]->NumberValue(context).ToChecked();
|
|
241
|
-
auto direction = (int) args[8]->NumberValue(context).ToChecked();
|
|
242
|
-
|
|
243
|
-
auto context_2d = canvas_native_context_create_gl(width, height, density,
|
|
244
|
-
ptr,
|
|
245
|
-
samples, alpha,
|
|
246
|
-
font_color, ppi, direction);
|
|
239
|
+
|
|
240
|
+
auto context_2d = static_cast<CanvasRenderingContext2D *>((void *) ptr);
|
|
247
241
|
|
|
248
242
|
auto ret = CanvasRenderingContext2DImpl::NewInstance(isolate, new CanvasRenderingContext2DImpl(
|
|
249
243
|
context_2d));
|
|
@@ -251,6 +245,32 @@ void CanvasJSIModule::Create2DContext(const v8::FunctionCallbackInfo<v8::Value>
|
|
|
251
245
|
args.GetReturnValue().Set(ret);
|
|
252
246
|
}
|
|
253
247
|
|
|
248
|
+
|
|
249
|
+
struct Rect {
|
|
250
|
+
float x;
|
|
251
|
+
float y;
|
|
252
|
+
float width;
|
|
253
|
+
float height;
|
|
254
|
+
};
|
|
255
|
+
|
|
256
|
+
struct ImageBitmapData {
|
|
257
|
+
char *error_;
|
|
258
|
+
const ImageAsset *asset_;
|
|
259
|
+
bool done_;
|
|
260
|
+
v8::Isolate *isolate_;
|
|
261
|
+
std::shared_ptr<v8::Persistent<v8::ArrayBufferView>> data_;
|
|
262
|
+
|
|
263
|
+
~ImageBitmapData() {
|
|
264
|
+
if (error_ != nullptr) {
|
|
265
|
+
canvas_native_string_destroy(error_);
|
|
266
|
+
error_ = nullptr;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
data_->Reset();
|
|
270
|
+
}
|
|
271
|
+
};
|
|
272
|
+
|
|
273
|
+
|
|
254
274
|
void CanvasJSIModule::CreateImageBitmap(const v8::FunctionCallbackInfo<v8::Value> &args) {
|
|
255
275
|
auto count = args.Length();
|
|
256
276
|
auto isolate = args.GetIsolate();
|
|
@@ -285,7 +305,7 @@ void CanvasJSIModule::CreateImageBitmap(const v8::FunctionCallbackInfo<v8::Value
|
|
|
285
305
|
|
|
286
306
|
if (image->IsNullOrUndefined()) {
|
|
287
307
|
v8::Local<v8::Value> ret[2] = {ConvertToV8String(isolate, "Failed to load image"),
|
|
288
|
-
v8::
|
|
308
|
+
v8::Null(isolate)};
|
|
289
309
|
|
|
290
310
|
cb.As<v8::Function>()->Call(context, context->Global(), 2, ret);
|
|
291
311
|
return;
|
|
@@ -295,7 +315,7 @@ void CanvasJSIModule::CreateImageBitmap(const v8::FunctionCallbackInfo<v8::Value
|
|
|
295
315
|
|
|
296
316
|
v8::Local<v8::Value> ret[2] = {ConvertToV8String(isolate,
|
|
297
317
|
"Failed to execute 'createImageBitmap' : The crop rect width is 0"),
|
|
298
|
-
v8::
|
|
318
|
+
v8::Null(isolate)};
|
|
299
319
|
|
|
300
320
|
cb.As<v8::Function>()->Call(context, context->Global(), 2, ret);
|
|
301
321
|
|
|
@@ -304,624 +324,134 @@ void CanvasJSIModule::CreateImageBitmap(const v8::FunctionCallbackInfo<v8::Value
|
|
|
304
324
|
if (len >= 5 && (sh->IsNumber() && sh->IsNumber() == 0)) {
|
|
305
325
|
v8::Local<v8::Value> ret[2] = {ConvertToV8String(isolate,
|
|
306
326
|
"Failed to execute 'createImageBitmap' : The crop rect height is 0"),
|
|
307
|
-
v8::
|
|
327
|
+
v8::Null(isolate)};
|
|
308
328
|
|
|
309
329
|
cb.As<v8::Function>()->Call(context, context->Global(), 2, ret);
|
|
310
330
|
return;
|
|
311
331
|
}
|
|
312
332
|
|
|
313
|
-
|
|
314
333
|
if (image->IsObject()) {
|
|
315
334
|
auto imageObject = image.As<v8::Object>();
|
|
316
335
|
auto isArrayBuffer = imageObject->IsArrayBuffer();
|
|
317
336
|
auto IsArrayBufferView = imageObject->IsArrayBufferView();
|
|
318
|
-
|
|
337
|
+
std::optional<Rect> rect = std::nullopt;
|
|
319
338
|
|
|
320
|
-
|
|
339
|
+
if (isArrayBuffer || IsArrayBufferView) {
|
|
340
|
+
if ((len == 1 || len == 2) || (len == 5 || len == 6)) {
|
|
321
341
|
if (len == 2) {
|
|
322
342
|
options = ImageBitmapImpl::HandleOptions(isolate, args[1]);
|
|
323
343
|
}
|
|
324
344
|
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
auto ret = new ImageBitmapImpl(asset);
|
|
330
|
-
|
|
345
|
+
if (len == 6) {
|
|
346
|
+
options = ImageBitmapImpl::HandleOptions(isolate, args[5]);
|
|
347
|
+
}
|
|
331
348
|
|
|
332
349
|
auto cbFunc = args[count - 1].As<v8::Function>();
|
|
333
|
-
auto data = v8::External::New(isolate, ret);
|
|
334
|
-
|
|
335
|
-
auto jsi_callback = new JSICallback(isolate, cbFunc, data);
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
#ifdef __ANDROID__
|
|
339
|
-
ALooper_addFd(jsi_callback->looper_,
|
|
340
|
-
jsi_callback->fd_[0],
|
|
341
|
-
ALOOPER_POLL_CALLBACK,
|
|
342
|
-
ALOOPER_EVENT_INPUT,
|
|
343
|
-
[](int fd, int events,
|
|
344
|
-
void *data) {
|
|
345
|
-
auto cb = static_cast<JSICallback *>(data);
|
|
346
|
-
bool done;
|
|
347
|
-
read(fd, &done,
|
|
348
|
-
sizeof(bool));
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
v8::Isolate *isolate = cb->isolate_;
|
|
352
|
-
v8::Locker locker(isolate);
|
|
353
|
-
v8::Isolate::Scope isolate_scope(isolate);
|
|
354
|
-
v8::HandleScope handle_scope(isolate);
|
|
355
|
-
v8::Local<v8::Function> callback = cb->callback_->Get(isolate);
|
|
356
|
-
v8::Local<v8::External> cbData = cb->data_->Get(
|
|
357
|
-
isolate).As<v8::External>();
|
|
358
|
-
v8::Local<v8::Context> context = callback->GetCreationContextChecked();
|
|
359
|
-
v8::Context::Scope context_scope(context);
|
|
360
|
-
|
|
361
|
-
auto ret = ImageBitmapImpl::NewInstance(isolate, cbData);
|
|
362
|
-
|
|
363
|
-
v8::Local<v8::Value> args[2];
|
|
364
|
-
|
|
365
|
-
if (done) {
|
|
366
|
-
args[0] = v8::Null(isolate);
|
|
367
|
-
args[1] = ret;
|
|
368
|
-
|
|
369
|
-
} else {
|
|
370
|
-
args[0] = v8::Exception::Error(
|
|
371
|
-
ConvertToV8String(isolate, "Failed to load image"));
|
|
372
|
-
args[1] = v8::Null(isolate);
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
callback->Call(context, context->Global(), 2, args);
|
|
377
|
-
|
|
378
|
-
delete static_cast<JSICallback *>(data);
|
|
379
|
-
return 0;
|
|
380
|
-
}, jsi_callback);
|
|
381
|
-
|
|
382
|
-
ALooper_wake(jsi_callback->looper_);
|
|
383
350
|
|
|
384
351
|
if (isArrayBuffer) {
|
|
385
352
|
auto arrayBuffer = imageObject.As<v8::ArrayBuffer>();
|
|
386
|
-
auto
|
|
387
|
-
|
|
388
|
-
v8::Global<v8::ArrayBuffer> ab(isolate, arrayBuffer);
|
|
389
|
-
std::thread thread(
|
|
390
|
-
[&dataBuffer, jsi_callback, &options, store, shared_asset](
|
|
391
|
-
v8::Global<v8::ArrayBuffer> ab, size_t size) {
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
auto done = canvas_native_image_bitmap_create_from_encoded_bytes_with_output(
|
|
395
|
-
dataBuffer, size,
|
|
396
|
-
options.flipY,
|
|
397
|
-
options.premultiplyAlpha,
|
|
398
|
-
options.colorSpaceConversion,
|
|
399
|
-
options.resizeQuality,
|
|
400
|
-
options.resizeWidth,
|
|
401
|
-
options.resizeHeight,
|
|
402
|
-
shared_asset);
|
|
403
|
-
|
|
404
|
-
canvas_native_image_asset_release(shared_asset);
|
|
405
|
-
|
|
406
|
-
write(jsi_callback->fd_[1],
|
|
407
|
-
&done,
|
|
408
|
-
sizeof(bool));
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
}, std::move(ab), arrayBuffer->ByteLength());
|
|
412
|
-
|
|
413
|
-
thread.detach();
|
|
414
|
-
return;
|
|
353
|
+
auto size = arrayBuffer->ByteLength();
|
|
354
|
+
imageObject = v8::Uint8Array::New(arrayBuffer, 0, size);
|
|
415
355
|
}
|
|
416
356
|
|
|
417
|
-
|
|
418
357
|
auto ta = imageObject.As<v8::ArrayBufferView>();
|
|
419
358
|
|
|
359
|
+
auto image_bitmap_async_data = new ImageBitmapData();
|
|
360
|
+
image_bitmap_async_data->isolate_ = isolate;
|
|
361
|
+
image_bitmap_async_data->data_ = std::make_shared<v8::Persistent<v8::ArrayBufferView>>(
|
|
362
|
+
isolate, ta);
|
|
420
363
|
|
|
421
|
-
auto
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
data_ptr, size,
|
|
435
|
-
options.flipY,
|
|
436
|
-
options.premultiplyAlpha,
|
|
437
|
-
options.colorSpaceConversion,
|
|
438
|
-
options.resizeQuality,
|
|
439
|
-
options.resizeWidth,
|
|
440
|
-
options.resizeHeight,
|
|
441
|
-
shared_asset);
|
|
442
|
-
|
|
443
|
-
canvas_native_image_asset_release(shared_asset);
|
|
444
|
-
|
|
445
|
-
write(jsi_callback->fd_[1],
|
|
446
|
-
&done,
|
|
447
|
-
sizeof(bool));
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
}, std::move(ab));
|
|
451
|
-
thread.detach();
|
|
452
|
-
|
|
453
|
-
#endif
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
#ifdef __APPLE__
|
|
457
|
-
|
|
458
|
-
auto current_queue = new NSOperationQueueWrapper(true);
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
if (isArrayBuffer) {
|
|
462
|
-
auto arrayBuffer = imageObject.As<v8::ArrayBuffer>();
|
|
463
|
-
auto store = arrayBuffer->GetBackingStore();
|
|
464
|
-
auto dataBuffer = (uint8_t *) store->Data();
|
|
465
|
-
v8::Global<v8::ArrayBuffer> ab(isolate, arrayBuffer);
|
|
466
|
-
|
|
467
|
-
std::thread thread(
|
|
468
|
-
[&dataBuffer, jsi_callback, &options, store, shared_asset, current_queue](
|
|
469
|
-
v8::Global<v8::ArrayBuffer> ab, size_t size
|
|
470
|
-
) {
|
|
471
|
-
|
|
472
|
-
auto done = canvas_native_image_bitmap_create_from_encoded_bytes_with_output(
|
|
473
|
-
dataBuffer, size,
|
|
474
|
-
options.flipY,
|
|
475
|
-
options.premultiplyAlpha,
|
|
476
|
-
options.colorSpaceConversion,
|
|
477
|
-
options.resizeQuality,
|
|
478
|
-
options.resizeWidth,
|
|
479
|
-
options.resizeHeight,
|
|
480
|
-
shared_asset);
|
|
481
|
-
|
|
482
|
-
canvas_native_image_asset_release(shared_asset);
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
auto main_task = [jsi_callback, current_queue, done]() {
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
v8::Isolate *isolate = jsi_callback->isolate_;
|
|
489
|
-
v8::Locker locker(isolate);
|
|
490
|
-
v8::Isolate::Scope isolate_scope(isolate);
|
|
491
|
-
v8::HandleScope handle_scope(isolate);
|
|
492
|
-
v8::Local<v8::Function> callback = jsi_callback->callback_->Get(isolate);
|
|
493
|
-
v8::Local<v8::External> cbData = jsi_callback->data_->Get(
|
|
494
|
-
isolate).As<v8::External>();
|
|
495
|
-
v8::Local<v8::Context> context = callback->GetCreationContextChecked();
|
|
496
|
-
v8::Context::Scope context_scope(context);
|
|
364
|
+
auto callback = new AsyncCallback(isolate, cbFunc, [](bool done, void *data) {
|
|
365
|
+
if (data == nullptr) { return; }
|
|
366
|
+
auto async_data = static_cast<AsyncCallback *>(data);
|
|
367
|
+
auto func = async_data->inner_.get();
|
|
368
|
+
if (func != nullptr && func->isolate_ != nullptr) {
|
|
369
|
+
v8::Isolate *isolate = func->isolate_;
|
|
370
|
+
v8::Locker locker(isolate);
|
|
371
|
+
v8::Isolate::Scope isolate_scope(isolate);
|
|
372
|
+
v8::HandleScope handle_scope(isolate);
|
|
373
|
+
v8::Local<v8::Function> callback = func->callback_.Get(
|
|
374
|
+
isolate);
|
|
375
|
+
v8::Local<v8::Context> context = callback->GetCreationContextChecked();
|
|
376
|
+
v8::Context::Scope context_scope(context);
|
|
497
377
|
|
|
498
|
-
|
|
378
|
+
if (func->data != nullptr) {
|
|
379
|
+
auto asset_data = static_cast<ImageBitmapData *>(func->data);
|
|
499
380
|
|
|
500
|
-
|
|
381
|
+
auto bitmap = new ImageBitmapImpl(asset_data->asset_);
|
|
382
|
+
auto external = v8::External::New(isolate, bitmap);
|
|
501
383
|
|
|
502
|
-
|
|
503
|
-
args[0] = v8::Null(isolate);
|
|
504
|
-
args[1] = ret;
|
|
384
|
+
auto ret = ImageBitmapImpl::NewInstance(isolate, external);
|
|
505
385
|
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
ConvertToV8String(isolate, "Failed to load image"));
|
|
509
|
-
args[1] = v8::Null(isolate);
|
|
510
|
-
}
|
|
386
|
+
v8::Local<v8::Value> args[2] = {
|
|
387
|
+
v8::Null(isolate), ret};
|
|
511
388
|
|
|
512
389
|
|
|
513
|
-
|
|
390
|
+
callback->Call(context, context->Global(),
|
|
391
|
+
2,
|
|
392
|
+
args); // ignore JS return value
|
|
514
393
|
|
|
394
|
+
delete asset_data;
|
|
515
395
|
|
|
516
|
-
|
|
517
|
-
|
|
396
|
+
} else {
|
|
397
|
+
v8::Local<v8::Value> args[1] = {
|
|
398
|
+
v8::Null(isolate)};
|
|
518
399
|
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
thread.detach();
|
|
525
|
-
|
|
526
|
-
return;
|
|
527
|
-
}
|
|
528
|
-
|
|
529
|
-
auto ta = imageObject.As<v8::ArrayBufferView>();
|
|
400
|
+
callback->Call(context, context->Global(),
|
|
401
|
+
1,
|
|
402
|
+
args); // ignore JS return value
|
|
403
|
+
}
|
|
530
404
|
|
|
405
|
+
}
|
|
406
|
+
delete static_cast<AsyncCallback *>(data);
|
|
407
|
+
});
|
|
531
408
|
|
|
532
|
-
|
|
409
|
+
callback->inner_->data = image_bitmap_async_data;
|
|
410
|
+
callback->prepare();
|
|
411
|
+
auto store = ta->Buffer()->GetBackingStore();
|
|
533
412
|
auto offset = ta->ByteOffset();
|
|
534
|
-
auto size = ta->ByteLength();
|
|
535
|
-
auto data_ptr = static_cast<uint8_t *>(array->GetBackingStore()->Data()) + offset;
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
v8::Global<v8::ArrayBufferView> ab(isolate, ta);
|
|
539
|
-
|
|
540
413
|
|
|
541
414
|
std::thread thread(
|
|
542
|
-
[
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
auto
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
auto main_task = [jsi_callback, current_queue, done]() {
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
v8::Isolate *isolate = jsi_callback->isolate_;
|
|
562
|
-
v8::Locker locker(isolate);
|
|
563
|
-
v8::Isolate::Scope isolate_scope(isolate);
|
|
564
|
-
v8::HandleScope handle_scope(isolate);
|
|
565
|
-
v8::Local<v8::Function> callback = jsi_callback->callback_->Get(isolate);
|
|
566
|
-
v8::Local<v8::External> cbData = jsi_callback->data_->Get(
|
|
567
|
-
isolate).As<v8::External>();
|
|
568
|
-
v8::Local<v8::Context> context = callback->GetCreationContextChecked();
|
|
569
|
-
v8::Context::Scope context_scope(context);
|
|
570
|
-
|
|
571
|
-
auto ret = ImageBitmapImpl::NewInstance(isolate, cbData);
|
|
572
|
-
|
|
573
|
-
v8::Local<v8::Value> args[2];
|
|
574
|
-
|
|
575
|
-
if (done) {
|
|
576
|
-
args[0] = v8::Null(isolate);
|
|
577
|
-
args[1] = ret;
|
|
578
|
-
} else {
|
|
579
|
-
args[0] = v8::Exception::Error(
|
|
580
|
-
ConvertToV8String(isolate, "Failed to load image"));
|
|
581
|
-
args[1] = v8::Null(isolate);
|
|
582
|
-
}
|
|
583
|
-
|
|
584
|
-
callback->Call(context, context->Global(), 2, args);
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
delete jsi_callback;
|
|
588
|
-
delete current_queue;
|
|
589
|
-
|
|
590
|
-
};
|
|
591
|
-
current_queue->addOperation(main_task);
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
}, std::move(ab));
|
|
596
|
-
thread.detach();
|
|
597
|
-
|
|
598
|
-
#endif
|
|
599
|
-
|
|
600
|
-
return;
|
|
601
|
-
} else if (len == 5 || len == 6) {
|
|
602
|
-
auto asset = canvas_native_image_asset_create();
|
|
603
|
-
|
|
604
|
-
auto shared_asset = canvas_native_image_asset_reference(asset);
|
|
605
|
-
|
|
606
|
-
auto ret = new ImageBitmapImpl(asset);
|
|
607
|
-
|
|
608
|
-
auto cbFunc = args[count - 1].As<v8::Function>();
|
|
609
|
-
auto data = v8::External::New(isolate, ret);
|
|
610
|
-
if (len == 6) {
|
|
611
|
-
options = ImageBitmapImpl::HandleOptions(isolate, args[5]);
|
|
612
|
-
}
|
|
613
|
-
|
|
614
|
-
auto jsi_callback = new JSICallback(isolate, cbFunc, data);
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
#ifdef __ANDROID__
|
|
618
|
-
ALooper_addFd(jsi_callback->looper_,
|
|
619
|
-
jsi_callback->fd_[0],
|
|
620
|
-
ALOOPER_POLL_CALLBACK,
|
|
621
|
-
ALOOPER_EVENT_INPUT,
|
|
622
|
-
[](int fd, int events,
|
|
623
|
-
void *data) {
|
|
624
|
-
auto cb = static_cast<JSICallback *>(data);
|
|
625
|
-
bool done;
|
|
626
|
-
read(fd, &done,
|
|
627
|
-
sizeof(bool));
|
|
628
|
-
|
|
629
|
-
v8::Isolate *isolate = cb->isolate_;
|
|
630
|
-
v8::Locker locker(isolate);
|
|
631
|
-
v8::Isolate::Scope isolate_scope(isolate);
|
|
632
|
-
v8::HandleScope handle_scope(isolate);
|
|
633
|
-
v8::Local<v8::Function> callback = cb->callback_->Get(isolate);
|
|
634
|
-
v8::Local<v8::External> cbData = cb->data_->Get(
|
|
635
|
-
isolate).As<v8::External>();
|
|
636
|
-
v8::Local<v8::Context> context = callback->GetCreationContextChecked();
|
|
637
|
-
v8::Context::Scope context_scope(context);
|
|
638
|
-
|
|
639
|
-
auto ret = ImageBitmapImpl::NewInstance(isolate, cbData);
|
|
640
|
-
|
|
641
|
-
v8::Local<v8::Value> args[2];
|
|
642
|
-
|
|
643
|
-
if (done) {
|
|
644
|
-
args[0] = v8::Null(isolate);
|
|
645
|
-
args[1] = ret;
|
|
646
|
-
} else {
|
|
647
|
-
args[0] = v8::Exception::Error(
|
|
648
|
-
ConvertToV8String(isolate, "Failed to load image"));
|
|
649
|
-
args[1] = v8::Null(isolate);
|
|
650
|
-
}
|
|
651
|
-
|
|
652
|
-
callback->Call(context, context->Global(), 2, args);
|
|
653
|
-
|
|
654
|
-
delete static_cast<JSICallback *>(data);
|
|
655
|
-
return 0;
|
|
656
|
-
}, jsi_callback);
|
|
657
|
-
|
|
658
|
-
ALooper_wake(jsi_callback->looper_);
|
|
659
|
-
|
|
660
|
-
auto bufferValue = args[0];
|
|
661
|
-
|
|
662
|
-
if (isArrayBuffer) {
|
|
663
|
-
auto arrayBuffer = bufferValue.As<v8::ArrayBuffer>();
|
|
664
|
-
auto dataBuffer = (uint8_t *) arrayBuffer->GetBackingStore()->Data();
|
|
665
|
-
v8::Global<v8::ArrayBuffer> ab(isolate, arrayBuffer);
|
|
666
|
-
std::thread thread(
|
|
667
|
-
[&dataBuffer, jsi_callback, &options, shared_asset](
|
|
668
|
-
float sx_or_options,
|
|
669
|
-
float sy,
|
|
670
|
-
float sw,
|
|
671
|
-
float sh,
|
|
672
|
-
v8::Global<v8::ArrayBuffer> ab,
|
|
673
|
-
size_t size
|
|
674
|
-
) {
|
|
675
|
-
|
|
676
|
-
auto done = canvas_native_image_bitmap_create_from_encoded_bytes_src_rect_with_output(
|
|
677
|
-
dataBuffer, size,
|
|
678
|
-
sx_or_options,
|
|
679
|
-
sy,
|
|
680
|
-
sw,
|
|
681
|
-
sh,
|
|
415
|
+
[callback, image_bitmap_async_data, offset, options, rect](
|
|
416
|
+
std::shared_ptr<v8::BackingStore> store) {
|
|
417
|
+
|
|
418
|
+
auto data = static_cast<uint8_t *>(store->Data()) + offset;
|
|
419
|
+
auto size = store->ByteLength();
|
|
420
|
+
|
|
421
|
+
auto asset = canvas_native_image_asset_create();
|
|
422
|
+
bool done;
|
|
423
|
+
if (rect.has_value()) {
|
|
424
|
+
|
|
425
|
+
done = canvas_native_image_bitmap_create_from_encoded_bytes_src_rect_with_output(
|
|
426
|
+
data, size,
|
|
427
|
+
rect.value().x,
|
|
428
|
+
rect.value().y,
|
|
429
|
+
rect.value().width,
|
|
430
|
+
rect.value().height,
|
|
682
431
|
options.flipY,
|
|
683
432
|
options.premultiplyAlpha,
|
|
684
433
|
options.colorSpaceConversion,
|
|
685
434
|
options.resizeQuality,
|
|
686
435
|
options.resizeWidth,
|
|
687
|
-
options.resizeHeight,
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
write(jsi_callback->fd_[1],
|
|
693
|
-
&done,
|
|
694
|
-
sizeof(bool));
|
|
695
|
-
|
|
696
|
-
},
|
|
697
|
-
(float) sx_or_options->NumberValue(context).ToChecked(),
|
|
698
|
-
(float) sy->NumberValue(context).ToChecked(),
|
|
699
|
-
(float) sw->NumberValue(context).ToChecked(),
|
|
700
|
-
(float) sh->NumberValue(context).ToChecked(), std::move(ab),
|
|
701
|
-
arrayBuffer->ByteLength());
|
|
702
|
-
|
|
703
|
-
thread.detach();
|
|
704
|
-
|
|
705
|
-
return;
|
|
706
|
-
}
|
|
707
|
-
|
|
708
|
-
auto ta = bufferValue.As<v8::ArrayBufferView>();
|
|
709
|
-
|
|
710
|
-
auto array = ta->Buffer();
|
|
711
|
-
auto offset = ta->ByteOffset();
|
|
712
|
-
auto size = ta->ByteLength();
|
|
713
|
-
auto data_ptr = static_cast<uint8_t *>(array->GetBackingStore()->Data()) + offset;
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
v8::Global<v8::ArrayBufferView> ab(isolate, ta);
|
|
717
|
-
std::thread thread(
|
|
718
|
-
[jsi_callback, &options, shared_asset, data_ptr, size](
|
|
719
|
-
float sx_or_options,
|
|
720
|
-
float sy,
|
|
721
|
-
float sw,
|
|
722
|
-
float sh,
|
|
723
|
-
v8::Global<v8::ArrayBufferView> ab
|
|
724
|
-
) {
|
|
725
|
-
|
|
726
|
-
auto done = canvas_native_image_bitmap_create_from_encoded_bytes_src_rect_with_output(
|
|
727
|
-
data_ptr, size,
|
|
728
|
-
sx_or_options,
|
|
729
|
-
sy,
|
|
730
|
-
sw,
|
|
731
|
-
sh,
|
|
732
|
-
options.flipY,
|
|
733
|
-
options.premultiplyAlpha,
|
|
734
|
-
options.colorSpaceConversion,
|
|
735
|
-
options.resizeQuality,
|
|
736
|
-
options.resizeWidth,
|
|
737
|
-
options.resizeHeight, shared_asset);
|
|
738
|
-
|
|
739
|
-
canvas_native_image_asset_release(shared_asset);
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
write(jsi_callback->fd_[1],
|
|
743
|
-
&done,
|
|
744
|
-
sizeof(bool));
|
|
745
|
-
|
|
746
|
-
},
|
|
747
|
-
(float) sx_or_options->NumberValue(context).ToChecked(),
|
|
748
|
-
(float) sy->NumberValue(context).ToChecked(),
|
|
749
|
-
(float) sw->NumberValue(context).ToChecked(),
|
|
750
|
-
(float) sh->NumberValue(context).ToChecked(), std::move(ab));
|
|
751
|
-
thread.detach();
|
|
752
|
-
|
|
753
|
-
#endif
|
|
754
|
-
|
|
755
|
-
#ifdef __APPLE__
|
|
756
|
-
|
|
757
|
-
auto current_queue = new NSOperationQueueWrapper(true);
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
auto bufferValue = args[0];
|
|
761
|
-
|
|
762
|
-
if (isArrayBuffer) {
|
|
763
|
-
auto arrayBuffer = bufferValue.As<v8::ArrayBuffer>();
|
|
764
|
-
auto dataBuffer = (uint8_t *) arrayBuffer->GetBackingStore()->Data();
|
|
765
|
-
v8::Global<v8::ArrayBuffer> ab(isolate, arrayBuffer);
|
|
766
|
-
std::thread thread(
|
|
767
|
-
[&dataBuffer, jsi_callback, &options, shared_asset, current_queue](
|
|
768
|
-
float sx_or_options,
|
|
769
|
-
float sy,
|
|
770
|
-
float sw,
|
|
771
|
-
float sh,
|
|
772
|
-
v8::Global<v8::ArrayBuffer> ab,
|
|
773
|
-
size_t size
|
|
774
|
-
) {
|
|
775
|
-
|
|
776
|
-
auto done = canvas_native_image_bitmap_create_from_encoded_bytes_src_rect_with_output(
|
|
777
|
-
dataBuffer, size,
|
|
778
|
-
sx_or_options,
|
|
779
|
-
sy,
|
|
780
|
-
sw,
|
|
781
|
-
sh,
|
|
436
|
+
options.resizeHeight, asset);
|
|
437
|
+
} else {
|
|
438
|
+
done = canvas_native_image_bitmap_create_from_encoded_bytes_with_output(
|
|
439
|
+
data, size,
|
|
782
440
|
options.flipY,
|
|
783
441
|
options.premultiplyAlpha,
|
|
784
442
|
options.colorSpaceConversion,
|
|
785
443
|
options.resizeQuality,
|
|
786
444
|
options.resizeWidth,
|
|
787
|
-
options.resizeHeight,
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
v8::Isolate *isolate = jsi_callback->isolate_;
|
|
796
|
-
v8::Locker locker(isolate);
|
|
797
|
-
v8::Isolate::Scope isolate_scope(isolate);
|
|
798
|
-
v8::HandleScope handle_scope(isolate);
|
|
799
|
-
v8::Local<v8::Function> callback = jsi_callback->callback_->Get(isolate);
|
|
800
|
-
v8::Local<v8::External> cbData = jsi_callback->data_->Get(
|
|
801
|
-
isolate).As<v8::External>();
|
|
802
|
-
v8::Local<v8::Context> context = callback->GetCreationContextChecked();
|
|
803
|
-
v8::Context::Scope context_scope(context);
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
auto ret = ImageBitmapImpl::NewInstance(isolate, cbData);
|
|
808
|
-
|
|
809
|
-
v8::Local<v8::Value> args[2];
|
|
810
|
-
|
|
811
|
-
if (done) {
|
|
812
|
-
args[0] = v8::Null(isolate);
|
|
813
|
-
args[1] = ret;
|
|
814
|
-
} else {
|
|
815
|
-
args[0] = v8::Exception::Error(
|
|
816
|
-
ConvertToV8String(isolate, "Failed to load image"));
|
|
817
|
-
args[1] = v8::Null(isolate);
|
|
818
|
-
}
|
|
819
|
-
|
|
820
|
-
callback->Call(context, context->Global(), 2, args);
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
delete jsi_callback;
|
|
824
|
-
delete current_queue;
|
|
825
|
-
|
|
826
|
-
};
|
|
827
|
-
current_queue->addOperation(main_task);
|
|
828
|
-
|
|
829
|
-
},
|
|
830
|
-
(float) sx_or_options->NumberValue(context).ToChecked(),
|
|
831
|
-
(float) sy->NumberValue(context).ToChecked(),
|
|
832
|
-
(float) sw->NumberValue(context).ToChecked(),
|
|
833
|
-
(float) sh->NumberValue(context).ToChecked(),
|
|
834
|
-
std::move(ab),
|
|
835
|
-
arrayBuffer->ByteLength());
|
|
836
|
-
|
|
837
|
-
thread.detach();
|
|
838
|
-
|
|
839
|
-
return;
|
|
840
|
-
}
|
|
841
|
-
|
|
842
|
-
auto ta = bufferValue.As<v8::ArrayBufferView>();
|
|
843
|
-
|
|
844
|
-
auto array = ta->Buffer();
|
|
845
|
-
auto offset = ta->ByteOffset();
|
|
846
|
-
auto size = ta->ByteLength();
|
|
847
|
-
auto data_ptr = static_cast<uint8_t*>(array->GetBackingStore()->Data()) + offset;
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
v8::Global<v8::ArrayBufferView> ab(isolate, ta);
|
|
852
|
-
std::thread thread(
|
|
853
|
-
[jsi_callback, &options, data_ptr, size, shared_asset, current_queue](
|
|
854
|
-
float sx_or_options,
|
|
855
|
-
float sy,
|
|
856
|
-
float sw,
|
|
857
|
-
float sh,
|
|
858
|
-
v8::Global<v8::ArrayBufferView> ab
|
|
859
|
-
) {
|
|
860
|
-
|
|
861
|
-
auto done = canvas_native_image_bitmap_create_from_encoded_bytes_src_rect_with_output(
|
|
862
|
-
data_ptr, size,
|
|
863
|
-
sx_or_options,
|
|
864
|
-
sy,
|
|
865
|
-
sw,
|
|
866
|
-
sh,
|
|
867
|
-
options.flipY,
|
|
868
|
-
options.premultiplyAlpha,
|
|
869
|
-
options.colorSpaceConversion,
|
|
870
|
-
options.resizeQuality,
|
|
871
|
-
options.resizeWidth,
|
|
872
|
-
options.resizeHeight, shared_asset);
|
|
873
|
-
|
|
874
|
-
canvas_native_image_asset_release(shared_asset);
|
|
875
|
-
|
|
876
|
-
auto main_task = [jsi_callback, current_queue, done]() {
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
v8::Isolate *isolate = jsi_callback->isolate_;
|
|
880
|
-
v8::Locker locker(isolate);
|
|
881
|
-
v8::Isolate::Scope isolate_scope(isolate);
|
|
882
|
-
v8::HandleScope handle_scope(isolate);
|
|
883
|
-
v8::Local<v8::Function> callback = jsi_callback->callback_->Get(isolate);
|
|
884
|
-
v8::Local<v8::External> cbData = jsi_callback->data_->Get(
|
|
885
|
-
isolate).As<v8::External>();
|
|
886
|
-
v8::Local<v8::Context> context = callback->GetCreationContextChecked();
|
|
887
|
-
v8::Context::Scope context_scope(context);
|
|
888
|
-
|
|
889
|
-
auto ret = ImageBitmapImpl::NewInstance(isolate, cbData);
|
|
890
|
-
|
|
891
|
-
v8::Local<v8::Value> args[2];
|
|
892
|
-
|
|
893
|
-
if (done) {
|
|
894
|
-
args[0] = v8::Null(isolate);
|
|
895
|
-
args[1] = ret;
|
|
896
|
-
} else {
|
|
897
|
-
args[0] = v8::Exception::Error(
|
|
898
|
-
ConvertToV8String(isolate, "Failed to load image"));
|
|
899
|
-
args[1] = v8::Null(isolate);
|
|
900
|
-
}
|
|
901
|
-
|
|
902
|
-
callback->Call(context, context->Global(), 2, args);
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
delete jsi_callback;
|
|
906
|
-
delete current_queue;
|
|
907
|
-
|
|
908
|
-
};
|
|
909
|
-
current_queue->addOperation(main_task);
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
},
|
|
914
|
-
(float) sx_or_options->NumberValue(context).ToChecked(),
|
|
915
|
-
(float) sy->NumberValue(context).ToChecked(),
|
|
916
|
-
(float) sw->NumberValue(context).ToChecked(),
|
|
917
|
-
(float) sh->NumberValue(context).ToChecked(), std::move(ab));
|
|
445
|
+
options.resizeHeight, asset);
|
|
446
|
+
}
|
|
447
|
+
if (callback != nullptr) {
|
|
448
|
+
image_bitmap_async_data->asset_ = asset;
|
|
449
|
+
callback->execute(done);
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
}, std::move(store));
|
|
918
453
|
thread.detach();
|
|
919
454
|
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
#endif
|
|
923
|
-
|
|
924
|
-
|
|
925
455
|
return;
|
|
926
456
|
}
|
|
927
457
|
}
|
|
@@ -1070,245 +600,251 @@ void CanvasJSIModule::Create2DContextWithPointer(const v8::FunctionCallbackInfo<
|
|
|
1070
600
|
args.GetReturnValue().Set(ret);
|
|
1071
601
|
}
|
|
1072
602
|
|
|
603
|
+
struct FileData {
|
|
604
|
+
char *error_;
|
|
605
|
+
U8Buffer *data;
|
|
606
|
+
|
|
607
|
+
~FileData() {
|
|
608
|
+
if (error_ != nullptr) {
|
|
609
|
+
canvas_native_string_destroy(error_);
|
|
610
|
+
error_ = nullptr;
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
};
|
|
614
|
+
|
|
1073
615
|
void CanvasJSIModule::ReadFile(const v8::FunctionCallbackInfo<v8::Value> &args) {
|
|
1074
616
|
auto isolate = args.GetIsolate();
|
|
1075
617
|
auto file = ConvertFromV8String(isolate, args[0]);
|
|
1076
618
|
auto cbFunc = args[1].As<v8::Function>();
|
|
1077
619
|
|
|
1078
|
-
auto
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
620
|
+
auto callback = new AsyncCallback(isolate, cbFunc, [](bool done, void *data) {
|
|
621
|
+
if (data == nullptr) { return; }
|
|
622
|
+
auto async_data = static_cast<AsyncCallback *>(data);
|
|
623
|
+
auto func = async_data->inner_.get();
|
|
624
|
+
if (func != nullptr && func->isolate_ != nullptr) {
|
|
625
|
+
v8::Isolate *isolate = func->isolate_;
|
|
626
|
+
v8::Locker locker(isolate);
|
|
627
|
+
v8::Isolate::Scope isolate_scope(isolate);
|
|
628
|
+
v8::HandleScope handle_scope(isolate);
|
|
629
|
+
v8::Local<v8::Function> callback = func->callback_.Get(
|
|
630
|
+
isolate);
|
|
631
|
+
v8::Local<v8::Context> context = callback->GetCreationContextChecked();
|
|
632
|
+
v8::Context::Scope context_scope(context);
|
|
633
|
+
|
|
634
|
+
if (func->data != nullptr) {
|
|
635
|
+
auto file_data = static_cast<FileData *>(func->data);
|
|
636
|
+
|
|
637
|
+
v8::Local<v8::Value> args[2];
|
|
638
|
+
|
|
639
|
+
if (done) {
|
|
640
|
+
args[0] = v8::Null(isolate);
|
|
641
|
+
|
|
642
|
+
auto buf = canvas_native_u8_buffer_get_bytes_mut(file_data->data);
|
|
643
|
+
auto size = (size_t) canvas_native_u8_buffer_get_length(file_data->data);
|
|
644
|
+
|
|
645
|
+
auto store = v8::ArrayBuffer::NewBackingStore((void *) buf, size,
|
|
646
|
+
[](void *data,
|
|
647
|
+
size_t length,
|
|
648
|
+
void *deleter_data) {
|
|
649
|
+
if (deleter_data !=
|
|
650
|
+
nullptr) {
|
|
651
|
+
delete static_cast<FileData *>(deleter_data);
|
|
652
|
+
|
|
653
|
+
}
|
|
654
|
+
},
|
|
655
|
+
func->data);
|
|
656
|
+
|
|
657
|
+
auto ret = v8::Object::New(isolate);
|
|
658
|
+
auto buffer = v8::ArrayBuffer::New(isolate, std::move(store));
|
|
659
|
+
ret->Set(context, ConvertToV8String(isolate, "buffer"), buffer);
|
|
660
|
+
auto mime = canvas_native_helper_get_mime(buf, size);
|
|
661
|
+
if (mime != nullptr) {
|
|
662
|
+
if (mime->mime_type != nullptr) {
|
|
663
|
+
ret->Set(context, ConvertToV8String(isolate, "mime"),
|
|
664
|
+
ConvertToV8String(isolate, mime->mime_type));
|
|
665
|
+
}
|
|
666
|
+
if (mime->extension != nullptr) {
|
|
667
|
+
ret->Set(context, ConvertToV8String(isolate, "extension"),
|
|
668
|
+
ConvertToV8String(isolate, mime->extension));
|
|
669
|
+
}
|
|
670
|
+
canvas_native_helper_release_mime(mime);
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
args[1] = ret;
|
|
674
|
+
} else {
|
|
675
|
+
auto error = file_data->error_;
|
|
676
|
+
args[0] = v8::Exception::Error(ConvertToV8String(isolate, error));
|
|
677
|
+
args[1] = v8::Null(isolate);
|
|
678
|
+
delete file_data;
|
|
679
|
+
}
|
|
680
|
+
|
|
681
|
+
v8::TryCatch tc(isolate);
|
|
682
|
+
v8::Local<v8::Value> result;
|
|
683
|
+
if (!callback->Call(context, context->Global(), 2, args).ToLocal(
|
|
684
|
+
&result)) {
|
|
685
|
+
if (tc.HasCaught()) {
|
|
686
|
+
|
|
687
|
+
// v8::Local<v8::Value> stack;
|
|
688
|
+
// bool success = tc.StackTrace(context).ToLocal(&stack);
|
|
689
|
+
// if (!success || stack.IsEmpty()) {
|
|
690
|
+
// if (!done) {
|
|
691
|
+
// delete async_data;
|
|
692
|
+
// }
|
|
693
|
+
// return;
|
|
694
|
+
// }
|
|
695
|
+
//
|
|
696
|
+
// v8::Local<v8::String> stackV8Str;
|
|
697
|
+
// success = stack->ToDetailString(context).ToLocal(&stackV8Str);
|
|
698
|
+
// if (!success || stackV8Str.IsEmpty()) {
|
|
699
|
+
// if (!done) {
|
|
700
|
+
// delete async_data;
|
|
701
|
+
// }
|
|
702
|
+
// return;
|
|
703
|
+
// }
|
|
704
|
+
|
|
705
|
+
}
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
delete async_data;
|
|
709
|
+
|
|
710
|
+
}
|
|
711
|
+
}
|
|
712
|
+
});
|
|
713
|
+
|
|
714
|
+
callback->prepare();
|
|
1169
715
|
|
|
1170
716
|
std::thread thread(
|
|
1171
|
-
[
|
|
717
|
+
[callback, file]() {
|
|
1172
718
|
bool done = false;
|
|
1173
719
|
auto ret = canvas_native_helper_read_file(file.c_str());
|
|
1174
720
|
|
|
1175
721
|
if (!canvas_native_helper_read_file_has_error(ret)) {
|
|
1176
|
-
auto buf =
|
|
1177
|
-
|
|
1178
|
-
jsi_callback->SetData(buf);
|
|
1179
|
-
|
|
722
|
+
auto buf = canvas_native_helper_read_file_take_data(ret);
|
|
723
|
+
callback->inner_->data = new FileData{nullptr, buf};
|
|
1180
724
|
done = true;
|
|
1181
725
|
} else {
|
|
1182
726
|
auto error = canvas_native_helper_read_file_get_error(ret);
|
|
1183
|
-
|
|
1184
|
-
jsi_callback->SetError(const_cast<char *>(error));
|
|
727
|
+
callback->inner_->data = new FileData{const_cast<char *>(error), nullptr};
|
|
1185
728
|
}
|
|
1186
729
|
canvas_native_helper_release(ret);
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
&done,
|
|
1190
|
-
sizeof(bool));
|
|
1191
|
-
|
|
1192
|
-
}, std::move(file));
|
|
730
|
+
callback->execute(done);
|
|
731
|
+
});
|
|
1193
732
|
|
|
1194
733
|
thread.detach();
|
|
1195
734
|
|
|
1196
|
-
#endif
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
#ifdef __APPLE__
|
|
1200
|
-
|
|
1201
|
-
auto current_queue = new NSOperationQueueWrapper(true);
|
|
1202
|
-
|
|
1203
|
-
auto queue = new NSOperationQueueWrapper(false);
|
|
1204
|
-
|
|
1205
|
-
auto task = [jsi_callback, current_queue, queue, file]() {
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
bool done = false;
|
|
1210
|
-
auto ret = canvas_native_helper_read_file(file.c_str());
|
|
1211
735
|
|
|
1212
|
-
|
|
1213
|
-
auto buf = canvas_native_helper_read_file_get_data(ret);
|
|
1214
|
-
|
|
1215
|
-
jsi_callback->SetData(buf);
|
|
1216
|
-
|
|
1217
|
-
done = true;
|
|
1218
|
-
} else {
|
|
1219
|
-
auto error = canvas_native_helper_read_file_get_error(ret);
|
|
736
|
+
}
|
|
1220
737
|
|
|
1221
|
-
jsi_callback->SetError((char*)error);
|
|
1222
|
-
}
|
|
1223
738
|
|
|
1224
|
-
|
|
739
|
+
void CanvasJSIModule::GetMime(const v8::FunctionCallbackInfo<v8::Value> &args) {
|
|
740
|
+
auto isolate = args.GetIsolate();
|
|
741
|
+
auto file = ConvertFromV8String(isolate, args[0]);
|
|
742
|
+
auto cbFunc = args[1].As<v8::Function>();
|
|
1225
743
|
|
|
1226
|
-
auto main_task = [jsi_callback, current_queue, queue, done]() {
|
|
1227
744
|
|
|
1228
|
-
|
|
745
|
+
auto callback = new AsyncCallback(isolate, cbFunc, [](bool done, void *data) {
|
|
746
|
+
if (data == nullptr) { return; }
|
|
747
|
+
auto async_data = static_cast<AsyncCallback *>(data);
|
|
748
|
+
auto func = async_data->inner_.get();
|
|
749
|
+
if (func != nullptr && func->isolate_ != nullptr) {
|
|
750
|
+
v8::Isolate *isolate = func->isolate_;
|
|
1229
751
|
v8::Locker locker(isolate);
|
|
1230
752
|
v8::Isolate::Scope isolate_scope(isolate);
|
|
1231
753
|
v8::HandleScope handle_scope(isolate);
|
|
1232
|
-
v8::Local<v8::Function> callback =
|
|
754
|
+
v8::Local<v8::Function> callback = func->callback_.Get(
|
|
755
|
+
isolate);
|
|
1233
756
|
v8::Local<v8::Context> context = callback->GetCreationContextChecked();
|
|
1234
757
|
v8::Context::Scope context_scope(context);
|
|
1235
758
|
|
|
1236
|
-
|
|
759
|
+
if (func->data != nullptr) {
|
|
760
|
+
auto file_data = static_cast<FileData *>(func->data);
|
|
1237
761
|
|
|
1238
|
-
|
|
1239
|
-
args[0] = v8::Null(isolate);
|
|
762
|
+
v8::Local<v8::Value> args[2];
|
|
1240
763
|
|
|
1241
|
-
|
|
764
|
+
if (done) {
|
|
765
|
+
args[0] = v8::Null(isolate);
|
|
1242
766
|
|
|
767
|
+
auto buf = (void *) canvas_native_u8_buffer_get_bytes_mut(file_data->data);
|
|
768
|
+
auto size = (size_t) canvas_native_u8_buffer_get_length(file_data->data);
|
|
1243
769
|
|
|
1244
|
-
|
|
770
|
+
auto store = v8::ArrayBuffer::NewBackingStore(buf, size,
|
|
771
|
+
[](void *data,
|
|
772
|
+
size_t length,
|
|
773
|
+
void *deleter_data) {
|
|
774
|
+
if (deleter_data !=
|
|
775
|
+
nullptr) {
|
|
776
|
+
delete static_cast<FileData *>(deleter_data);
|
|
1245
777
|
|
|
1246
|
-
|
|
778
|
+
}
|
|
779
|
+
},
|
|
780
|
+
func->data);
|
|
1247
781
|
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
delete static_cast<JSIReadFileCallback *>(deleter_data);
|
|
1256
|
-
}
|
|
1257
|
-
},
|
|
1258
|
-
jsi_callback);
|
|
782
|
+
args[1] = v8::ArrayBuffer::New(isolate, std::move(store));
|
|
783
|
+
} else {
|
|
784
|
+
auto error = file_data->error_;
|
|
785
|
+
args[0] = v8::Exception::Error(ConvertToV8String(isolate, error));
|
|
786
|
+
args[1] = v8::Null(isolate);
|
|
787
|
+
delete file_data;
|
|
788
|
+
}
|
|
1259
789
|
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
790
|
+
v8::TryCatch tc(isolate);
|
|
791
|
+
v8::Local<v8::Value> result;
|
|
792
|
+
if (!callback->Call(context, context->Global(), 2, args).ToLocal(
|
|
793
|
+
&result)) {
|
|
794
|
+
if (tc.HasCaught()) {
|
|
795
|
+
|
|
796
|
+
// v8::Local<v8::Value> stack;
|
|
797
|
+
// bool success = tc.StackTrace(context).ToLocal(&stack);
|
|
798
|
+
// if (!success || stack.IsEmpty()) {
|
|
799
|
+
// if (!done) {
|
|
800
|
+
// delete async_data;
|
|
801
|
+
// }
|
|
802
|
+
// return;
|
|
803
|
+
// }
|
|
804
|
+
//
|
|
805
|
+
// v8::Local<v8::String> stackV8Str;
|
|
806
|
+
// success = stack->ToDetailString(context).ToLocal(&stackV8Str);
|
|
807
|
+
// if (!success || stackV8Str.IsEmpty()) {
|
|
808
|
+
// if (!done) {
|
|
809
|
+
// delete async_data;
|
|
810
|
+
// }
|
|
811
|
+
// return;
|
|
812
|
+
// }
|
|
1266
813
|
|
|
1267
|
-
v8::TryCatch tc(isolate);
|
|
1268
|
-
v8::Local<v8::Value> result;
|
|
1269
|
-
if (!callback->Call(context, context->Global(), 2, args).ToLocal(
|
|
1270
|
-
&result)) {
|
|
1271
|
-
if (tc.HasCaught()) {
|
|
1272
|
-
|
|
1273
|
-
v8::Local<v8::Value> stack;
|
|
1274
|
-
bool success = tc.StackTrace(context).ToLocal(&stack);
|
|
1275
|
-
if (!success || stack.IsEmpty()) {
|
|
1276
|
-
if (!done) {
|
|
1277
|
-
delete jsi_callback;
|
|
1278
|
-
}
|
|
1279
|
-
return;
|
|
1280
814
|
}
|
|
815
|
+
}
|
|
1281
816
|
|
|
1282
|
-
|
|
1283
|
-
success = stack->ToDetailString(context).ToLocal(&stackV8Str);
|
|
1284
|
-
if (!success || stackV8Str.IsEmpty()) {
|
|
1285
|
-
if (!done) {
|
|
1286
|
-
delete jsi_callback;
|
|
1287
|
-
}
|
|
1288
|
-
return;
|
|
1289
|
-
}
|
|
1290
|
-
LogToConsole(ConvertFromV8String(isolate, stackV8Str));
|
|
817
|
+
delete async_data;
|
|
1291
818
|
|
|
1292
|
-
}
|
|
1293
819
|
}
|
|
820
|
+
}
|
|
821
|
+
});
|
|
1294
822
|
|
|
1295
|
-
|
|
1296
|
-
delete jsi_callback;
|
|
1297
|
-
}
|
|
823
|
+
callback->prepare();
|
|
1298
824
|
|
|
1299
|
-
|
|
1300
|
-
|
|
825
|
+
std::thread thread(
|
|
826
|
+
[callback, file]() {
|
|
827
|
+
bool done = false;
|
|
828
|
+
auto ret = canvas_native_helper_read_file(file.c_str());
|
|
1301
829
|
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
830
|
+
if (!canvas_native_helper_read_file_has_error(ret)) {
|
|
831
|
+
auto buf = canvas_native_helper_read_file_take_data(ret);
|
|
832
|
+
callback->inner_->data = new FileData{nullptr, buf};
|
|
833
|
+
done = true;
|
|
834
|
+
} else {
|
|
835
|
+
auto error = canvas_native_helper_read_file_get_error(ret);
|
|
836
|
+
callback->inner_->data = new FileData{const_cast<char *>(error), nullptr};
|
|
837
|
+
}
|
|
838
|
+
canvas_native_helper_release(ret);
|
|
839
|
+
callback->execute(done);
|
|
840
|
+
});
|
|
1305
841
|
|
|
1306
|
-
|
|
1307
|
-
#endif
|
|
842
|
+
thread.detach();
|
|
1308
843
|
|
|
1309
844
|
|
|
1310
845
|
}
|
|
1311
846
|
|
|
847
|
+
|
|
1312
848
|
void CanvasJSIModule::CreateWebGLContext(const v8::FunctionCallbackInfo<v8::Value> &args) {
|
|
1313
849
|
|
|
1314
850
|
auto options = GLOptions();
|
|
@@ -1326,20 +862,7 @@ void CanvasJSIModule::CreateWebGLContext(const v8::FunctionCallbackInfo<v8::Valu
|
|
|
1326
862
|
auto count = args.Length();
|
|
1327
863
|
if (count == 6) {
|
|
1328
864
|
auto ctx = args[1].As<v8::BigInt>()->Int64Value();
|
|
1329
|
-
auto webgl =
|
|
1330
|
-
ctx,
|
|
1331
|
-
options.version,
|
|
1332
|
-
options.alpha,
|
|
1333
|
-
options.antialias,
|
|
1334
|
-
options.depth,
|
|
1335
|
-
options.failIfMajorPerformanceCaveat,
|
|
1336
|
-
options.powerPreference,
|
|
1337
|
-
options.premultipliedAlpha,
|
|
1338
|
-
options.preserveDrawingBuffer,
|
|
1339
|
-
options.stencil,
|
|
1340
|
-
options.desynchronized,
|
|
1341
|
-
options.xrCompatible
|
|
1342
|
-
);
|
|
865
|
+
auto webgl = (WebGLState *) ctx;
|
|
1343
866
|
|
|
1344
867
|
auto renderingContext = WebGLRenderingContext::NewInstance(isolate,
|
|
1345
868
|
new WebGLRenderingContext(
|
|
@@ -1423,21 +946,7 @@ void CanvasJSIModule::CreateWebGL2Context(const v8::FunctionCallbackInfo<v8::Val
|
|
|
1423
946
|
auto count = args.Length();
|
|
1424
947
|
if (count == 6) {
|
|
1425
948
|
auto ctx = args[1].As<v8::BigInt>()->Int64Value();
|
|
1426
|
-
auto webgl =
|
|
1427
|
-
ctx,
|
|
1428
|
-
options.version,
|
|
1429
|
-
options.alpha,
|
|
1430
|
-
options.antialias,
|
|
1431
|
-
options.depth,
|
|
1432
|
-
options.failIfMajorPerformanceCaveat,
|
|
1433
|
-
options.powerPreference,
|
|
1434
|
-
options.premultipliedAlpha,
|
|
1435
|
-
options.preserveDrawingBuffer,
|
|
1436
|
-
options.stencil,
|
|
1437
|
-
options.desynchronized,
|
|
1438
|
-
options.xrCompatible
|
|
1439
|
-
);
|
|
1440
|
-
|
|
949
|
+
auto webgl = (WebGLState *) ctx;
|
|
1441
950
|
auto renderingContext = WebGL2RenderingContext::NewInstance(isolate,
|
|
1442
951
|
new WebGL2RenderingContext(
|
|
1443
952
|
webgl,
|