@nativescript/canvas 2.0.0-webgpu.2 → 2.0.0-webgpu.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Canvas/common.d.ts +3 -4
- package/Canvas/common.js +35 -125
- package/Canvas/common.js.map +1 -1
- package/Canvas/index.android.d.ts +0 -1
- package/Canvas/index.android.js +45 -38
- package/Canvas/index.android.js.map +1 -1
- package/Canvas/index.d.ts +11 -3
- package/Canvas/index.ios.js +49 -40
- 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 +1 -0
- package/Canvas2D/CanvasRenderingContext2D/index.js +1 -0
- 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.js +77 -33
- 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/index.js +73 -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 +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 +3 -2
- 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 +72 -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 +45 -7
- 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 +2 -1
- package/WebGPU/GPURenderPassEncoder.js +5 -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 +221 -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/package.json +20 -0
- package/package.json +1 -3
- package/platforms/android/canvas-release.aar +0 -0
- package/platforms/ios/CanvasNative.xcframework/Info.plist +5 -5
- 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 +9 -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 +226 -61
- 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 +6871 -5995
- package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios.private.swiftinterface +7 -0
- package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios.swiftinterface +7 -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 +656 -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 +18 -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 +226 -61
- 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 +6871 -5995
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios-simulator.private.swiftinterface +7 -0
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios-simulator.swiftinterface +7 -0
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/x86_64-apple-ios-simulator.abi.json +6871 -5995
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/x86_64-apple-ios-simulator.private.swiftinterface +7 -0
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/x86_64-apple-ios-simulator.swiftinterface +7 -0
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/_CodeSignature/CodeResources +27 -27
- 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 +658 -646
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/dSYMs/CanvasNative.framework.dSYM/Contents/Resources/Relocations/x86_64/CanvasNative.yml +696 -684
- package/platforms/ios/src/NSOperationQueueWrapper.h +3 -1
- package/platforms/ios/src/NSOperationQueueWrapper.mm +41 -9
- package/platforms/ios/src/cpp/AsyncCallback.h +214 -0
- package/platforms/ios/src/cpp/CanvasJSIModule.cpp +123 -47
- package/platforms/ios/src/cpp/Helpers.h +2 -164
- package/platforms/ios/src/cpp/ImageAssetImpl.cpp +18 -26
- package/platforms/ios/src/cpp/ImageAssetImpl.h +3 -3
- package/platforms/ios/src/cpp/ImageBitmapImpl.cpp +60 -3
- package/platforms/ios/src/cpp/ImageBitmapImpl.h +12 -4
- package/platforms/ios/src/cpp/NativeType.h +87 -0
- package/platforms/ios/src/cpp/ObjectWrapperImpl.h +50 -0
- package/platforms/ios/src/cpp/PromiseCallback.h +197 -0
- package/platforms/ios/src/cpp/canvas2d/CanvasGradient.h +7 -6
- package/platforms/ios/src/cpp/canvas2d/CanvasPattern.cpp +1 -1
- package/platforms/ios/src/cpp/canvas2d/CanvasPattern.h +1 -1
- package/platforms/ios/src/cpp/canvas2d/CanvasRenderingContext2DImpl.cpp +6 -6
- package/platforms/ios/src/cpp/canvas2d/CanvasRenderingContext2DImpl.h +18 -13
- package/platforms/ios/src/cpp/canvas2d/ImageDataImpl.cpp +2 -2
- package/platforms/ios/src/cpp/canvas2d/ImageDataImpl.h +1 -1
- package/platforms/ios/src/cpp/canvas2d/MatrixImpl.cpp +10 -10
- package/platforms/ios/src/cpp/canvas2d/Path2D.cpp +6 -3
- package/platforms/ios/src/cpp/canvas2d/Path2D.h +5 -5
- package/platforms/ios/src/cpp/webgl/WebGLActiveInfoImpl.h +1 -1
- package/platforms/ios/src/cpp/webgl/WebGLBuffer.h +1 -1
- package/platforms/ios/src/cpp/webgl/WebGLFramebuffer.h +1 -1
- package/platforms/ios/src/cpp/webgl/WebGLProgram.h +3 -3
- package/platforms/ios/src/cpp/webgl/WebGLRenderbuffer.h +3 -3
- package/platforms/ios/src/cpp/webgl/WebGLRenderingContext.cpp +106 -1
- package/platforms/ios/src/cpp/webgl/WebGLRenderingContext.h +1 -1
- package/platforms/ios/src/cpp/webgl/WebGLShader.h +1 -1
- package/platforms/ios/src/cpp/webgl/WebGLShaderPrecisionFormatImpl.h +5 -5
- package/platforms/ios/src/cpp/webgl/WebGLTexture.h +3 -2
- package/platforms/ios/src/cpp/webgl/WebGLUniformLocation.h +2 -2
- package/platforms/ios/src/cpp/webgl/extensions/ANGLE_instanced_arraysImpl.h +1 -1
- package/platforms/ios/src/cpp/webgl/extensions/EXT_blend_minmaxImpl.h +1 -1
- package/platforms/ios/src/cpp/webgl/extensions/EXT_color_buffer_half_floatImpl.h +1 -1
- package/platforms/ios/src/cpp/webgl/extensions/EXT_disjoint_timer_queryImpl.h +1 -1
- package/platforms/ios/src/cpp/webgl/extensions/EXT_sRGBImpl.h +1 -1
- package/platforms/ios/src/cpp/webgl/extensions/EXT_shader_texture_lodImpl.h +1 -1
- package/platforms/ios/src/cpp/webgl/extensions/EXT_texture_filter_anisotropicImpl.h +1 -1
- package/platforms/ios/src/cpp/webgl/extensions/OES_element_index_uintImpl.h +2 -2
- package/platforms/ios/src/cpp/webgl/extensions/OES_fbo_render_mipmap.h +5 -5
- package/platforms/ios/src/cpp/webgl/extensions/OES_standard_derivativesImpl.h +1 -1
- package/platforms/ios/src/cpp/webgl/extensions/OES_texture_floatImpl.h +1 -1
- package/platforms/ios/src/cpp/webgl/extensions/OES_texture_float_linearImpl.h +1 -1
- package/platforms/ios/src/cpp/webgl/extensions/OES_texture_half_floatImpl.h +1 -1
- package/platforms/ios/src/cpp/webgl/extensions/OES_texture_half_float_linearImpl.h +1 -1
- package/platforms/ios/src/cpp/webgl/extensions/OES_vertex_array_objectImpl.h +1 -1
- package/platforms/ios/src/cpp/webgl/extensions/WEBGL_color_buffer_floatImpl.h +1 -1
- package/platforms/ios/src/cpp/webgl/extensions/WEBGL_compressed_texture_atcImpl.h +1 -1
- package/platforms/ios/src/cpp/webgl/extensions/WEBGL_compressed_texture_etc1Impl.h +1 -1
- package/platforms/ios/src/cpp/webgl/extensions/WEBGL_compressed_texture_etcImpl.h +2 -2
- package/platforms/ios/src/cpp/webgl/extensions/WEBGL_compressed_texture_pvrtcImpl.h +1 -1
- package/platforms/ios/src/cpp/webgl/extensions/WEBGL_compressed_texture_s3tcImpl.h +1 -1
- package/platforms/ios/src/cpp/webgl/extensions/WEBGL_compressed_texture_s3tc_srgbImpl.h +1 -1
- package/platforms/ios/src/cpp/webgl/extensions/WEBGL_depth_textureImpl.h +1 -1
- package/platforms/ios/src/cpp/webgl/extensions/WEBGL_draw_buffersImpl.h +1 -1
- package/platforms/ios/src/cpp/webgl/extensions/WEBGL_lose_contextImpl.h +1 -1
- package/platforms/ios/src/cpp/webgl2/WebGL2RenderingContext.h +1 -1
- package/platforms/ios/src/cpp/webgl2/WebGLQuery.h +1 -1
- package/platforms/ios/src/cpp/webgl2/WebGLSampler.h +1 -1
- package/platforms/ios/src/cpp/webgl2/WebGLSyncImpl.h +1 -1
- package/platforms/ios/src/cpp/webgl2/WebGLTransformFeedback.h +1 -1
- package/platforms/ios/src/cpp/webgl2/WebGLVertexArrayObject.h +2 -2
- package/platforms/ios/src/cpp/webgpu/GPUAdapterImpl.cpp +142 -73
- package/platforms/ios/src/cpp/webgpu/GPUAdapterImpl.h +1 -1
- package/platforms/ios/src/cpp/webgpu/GPUAdapterInfoImpl.cpp +1 -1
- package/platforms/ios/src/cpp/webgpu/GPUAdapterInfoImpl.h +1 -1
- package/platforms/ios/src/cpp/webgpu/GPUBindGroupImpl.cpp +32 -6
- package/platforms/ios/src/cpp/webgpu/GPUBindGroupImpl.h +5 -2
- package/platforms/ios/src/cpp/webgpu/GPUBindGroupLayoutImpl.cpp +27 -1
- package/platforms/ios/src/cpp/webgpu/GPUBindGroupLayoutImpl.h +4 -1
- package/platforms/ios/src/cpp/webgpu/GPUBufferImpl.cpp +80 -32
- package/platforms/ios/src/cpp/webgpu/GPUBufferImpl.h +8 -4
- package/platforms/ios/src/cpp/webgpu/GPUCanvasContextImpl.cpp +11 -5
- package/platforms/ios/src/cpp/webgpu/GPUCanvasContextImpl.h +1 -1
- package/platforms/ios/src/cpp/webgpu/GPUCommandBufferImpl.cpp +29 -2
- package/platforms/ios/src/cpp/webgpu/GPUCommandBufferImpl.h +4 -1
- package/platforms/ios/src/cpp/webgpu/GPUCommandEncoderImpl.cpp +101 -106
- package/platforms/ios/src/cpp/webgpu/GPUCommandEncoderImpl.h +5 -1
- package/platforms/ios/src/cpp/webgpu/GPUComputePassEncoderImpl.cpp +42 -14
- package/platforms/ios/src/cpp/webgpu/GPUComputePassEncoderImpl.h +4 -1
- package/platforms/ios/src/cpp/webgpu/GPUComputePipelineImpl.cpp +26 -1
- package/platforms/ios/src/cpp/webgpu/GPUComputePipelineImpl.h +3 -1
- package/platforms/ios/src/cpp/webgpu/GPUDeviceImpl.cpp +1683 -733
- package/platforms/ios/src/cpp/webgpu/GPUDeviceImpl.h +3 -1
- package/platforms/ios/src/cpp/webgpu/GPUImpl.cpp +53 -39
- package/platforms/ios/src/cpp/webgpu/GPUImpl.h +2 -2
- package/platforms/ios/src/cpp/webgpu/GPULabel.h +33 -0
- package/platforms/ios/src/cpp/webgpu/GPUPipelineLayoutImpl.cpp +27 -1
- package/platforms/ios/src/cpp/webgpu/GPUPipelineLayoutImpl.h +8 -5
- package/platforms/ios/src/cpp/webgpu/GPUQuerySetImpl.cpp +2 -3
- package/platforms/ios/src/cpp/webgpu/GPUQuerySetImpl.h +2 -2
- package/platforms/ios/src/cpp/webgpu/GPUQueueImpl.cpp +88 -36
- package/platforms/ios/src/cpp/webgpu/GPUQueueImpl.h +4 -1
- package/platforms/ios/src/cpp/webgpu/GPURenderBundleEncoderImpl.cpp +43 -14
- package/platforms/ios/src/cpp/webgpu/GPURenderBundleEncoderImpl.h +4 -1
- package/platforms/ios/src/cpp/webgpu/GPURenderBundleImpl.cpp +26 -1
- package/platforms/ios/src/cpp/webgpu/GPURenderBundleImpl.h +4 -1
- package/platforms/ios/src/cpp/webgpu/GPURenderPassEncoderImpl.cpp +40 -14
- package/platforms/ios/src/cpp/webgpu/GPURenderPassEncoderImpl.h +4 -1
- package/platforms/ios/src/cpp/webgpu/GPURenderPipelineImpl.cpp +26 -1
- package/platforms/ios/src/cpp/webgpu/GPURenderPipelineImpl.h +4 -1
- package/platforms/ios/src/cpp/webgpu/GPUSamplerImpl.cpp +27 -1
- package/platforms/ios/src/cpp/webgpu/GPUSamplerImpl.h +5 -2
- package/platforms/ios/src/cpp/webgpu/GPUShaderModuleImpl.cpp +25 -1
- package/platforms/ios/src/cpp/webgpu/GPUShaderModuleImpl.h +5 -2
- package/platforms/ios/src/cpp/webgpu/GPUSupportedLimitsImpl.cpp +2 -2
- package/platforms/ios/src/cpp/webgpu/GPUSupportedLimitsImpl.h +2 -2
- package/platforms/ios/src/cpp/webgpu/GPUTextureImpl.cpp +34 -8
- package/platforms/ios/src/cpp/webgpu/GPUTextureImpl.h +6 -4
- package/platforms/ios/src/cpp/webgpu/GPUTextureViewImpl.cpp +27 -1
- package/platforms/ios/src/cpp/webgpu/GPUTextureViewImpl.h +5 -2
- package/platforms/ios/src/cpp/webgpu/GPUUtils.h +511 -0
- package/utils.d.ts +1 -1
|
@@ -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() {
|
|
@@ -122,12 +122,12 @@ void ImageAssetImpl::Ctor(const v8::FunctionCallbackInfo<v8::Value> &args) {
|
|
|
122
122
|
|
|
123
123
|
auto ret = args.This();
|
|
124
124
|
|
|
125
|
-
SetNativeType(ret, NativeType::ImageAsset);
|
|
126
|
-
|
|
127
125
|
auto image_asset = canvas_native_image_asset_create();
|
|
128
126
|
|
|
129
127
|
auto object = new ImageAssetImpl(image_asset);
|
|
130
128
|
|
|
129
|
+
SetNativeType(object, NativeType::ImageAsset);
|
|
130
|
+
|
|
131
131
|
ret->SetAlignedPointerInInternalField(0, object);
|
|
132
132
|
|
|
133
133
|
object->BindFinalizer(isolate, ret);
|
|
@@ -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
|
|
|
@@ -19,11 +19,11 @@
|
|
|
19
19
|
class ImageAssetImpl : ObjectWrapperImpl {
|
|
20
20
|
public:
|
|
21
21
|
|
|
22
|
-
explicit ImageAssetImpl(ImageAsset *asset);
|
|
22
|
+
explicit ImageAssetImpl(const ImageAsset *asset);
|
|
23
23
|
|
|
24
24
|
~ImageAssetImpl();
|
|
25
25
|
|
|
26
|
-
ImageAsset *GetImageAsset();
|
|
26
|
+
const ImageAsset *GetImageAsset();
|
|
27
27
|
|
|
28
28
|
static void Init(v8::Local<v8::Object> canvasModule, v8::Isolate *isolate);
|
|
29
29
|
|
|
@@ -67,5 +67,5 @@ public:
|
|
|
67
67
|
|
|
68
68
|
|
|
69
69
|
private:
|
|
70
|
-
ImageAsset *asset_;
|
|
70
|
+
const ImageAsset *asset_;
|
|
71
71
|
};
|
|
@@ -5,10 +5,10 @@
|
|
|
5
5
|
#include "ImageBitmapImpl.h"
|
|
6
6
|
#include "Caches.h"
|
|
7
7
|
|
|
8
|
-
ImageBitmapImpl::ImageBitmapImpl(ImageAsset*
|
|
8
|
+
ImageBitmapImpl::ImageBitmapImpl(const ImageAsset *asset)
|
|
9
9
|
: bitmap_(asset) {}
|
|
10
10
|
|
|
11
|
-
ImageBitmapImpl::~ImageBitmapImpl(){
|
|
11
|
+
ImageBitmapImpl::~ImageBitmapImpl() {
|
|
12
12
|
canvas_native_image_asset_release(bitmap_);
|
|
13
13
|
this->bitmap_ = nullptr;
|
|
14
14
|
}
|
|
@@ -26,6 +26,23 @@ void ImageBitmapImpl::Init(v8::Local<v8::Object> canvasModule, v8::Isolate *isol
|
|
|
26
26
|
canvasModule->Set(context, ConvertToV8String(isolate, "ImageBitmap"), func);
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
+
|
|
30
|
+
void ImageBitmapImpl::FromAsset(const v8::FunctionCallbackInfo<v8::Value> &args) {
|
|
31
|
+
auto asset = args[0];
|
|
32
|
+
auto type = GetNativeType(asset);
|
|
33
|
+
auto isolate = args.GetIsolate();
|
|
34
|
+
if (type == NativeType::ImageAsset){
|
|
35
|
+
auto ptr = ImageAssetImpl::GetPointer(asset.As<v8::Object>());
|
|
36
|
+
auto ret = canvas_native_image_asset_reference(ptr->GetImageAsset());
|
|
37
|
+
auto bitmap = new ImageBitmapImpl(ret);
|
|
38
|
+
auto data = v8::External::New(isolate, bitmap);
|
|
39
|
+
auto object = ImageBitmapImpl::NewInstance(isolate, data);
|
|
40
|
+
args.GetReturnValue().Set(object);
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
args.GetReturnValue().SetNull();
|
|
44
|
+
}
|
|
45
|
+
|
|
29
46
|
ImageBitmapImpl *ImageBitmapImpl::GetPointer(v8::Local<v8::Object> object) {
|
|
30
47
|
auto ptr = object->GetAlignedPointerFromInternalField(0);
|
|
31
48
|
if (ptr == nullptr) {
|
|
@@ -45,7 +62,10 @@ v8::Local<v8::FunctionTemplate> ImageBitmapImpl::GetCtor(v8::Isolate *isolate) {
|
|
|
45
62
|
ctorTmpl->InstanceTemplate()->SetInternalFieldCount(2);
|
|
46
63
|
ctorTmpl->SetClassName(ConvertToV8String(isolate, "ImageBitmap"));
|
|
47
64
|
|
|
65
|
+
ctorTmpl->Set(ConvertToV8String(isolate, "fromAsset"), v8::FunctionTemplate::New(isolate, FromAsset));
|
|
66
|
+
|
|
48
67
|
auto tmpl = ctorTmpl->InstanceTemplate();
|
|
68
|
+
|
|
49
69
|
tmpl->SetInternalFieldCount(2);
|
|
50
70
|
tmpl->SetAccessor(
|
|
51
71
|
ConvertToV8String(isolate, "width"), GetWidth);
|
|
@@ -56,6 +76,13 @@ v8::Local<v8::FunctionTemplate> ImageBitmapImpl::GetCtor(v8::Isolate *isolate) {
|
|
|
56
76
|
tmpl->Set(
|
|
57
77
|
ConvertToV8String(isolate, "close"), v8::FunctionTemplate::New(isolate, Close));
|
|
58
78
|
|
|
79
|
+
tmpl->SetAccessor(
|
|
80
|
+
ConvertToV8String(isolate, "__addr"),
|
|
81
|
+
GetAddr);
|
|
82
|
+
|
|
83
|
+
tmpl->Set(
|
|
84
|
+
ConvertToV8String(isolate, "__getRef"),
|
|
85
|
+
v8::FunctionTemplate::New(isolate, GetReference));
|
|
59
86
|
|
|
60
87
|
cache->ImageBitmapTmpl =
|
|
61
88
|
std::make_unique<v8::Persistent<v8::FunctionTemplate>>(isolate, ctorTmpl);
|
|
@@ -93,6 +120,8 @@ void ImageBitmapImpl::Close(const v8::FunctionCallbackInfo<v8::Value> &args) {
|
|
|
93
120
|
return;
|
|
94
121
|
}
|
|
95
122
|
|
|
123
|
+
canvas_native_image_asset_close(ptr->GetImageAsset());
|
|
124
|
+
|
|
96
125
|
ptr->closed_ = true;
|
|
97
126
|
}
|
|
98
127
|
|
|
@@ -184,6 +213,34 @@ ImageBitmapImpl::HandleOptions(v8::Isolate *isolate, const v8::Local<v8::Value>
|
|
|
184
213
|
return ret;
|
|
185
214
|
}
|
|
186
215
|
|
|
187
|
-
|
|
216
|
+
|
|
217
|
+
void
|
|
218
|
+
ImageBitmapImpl::GetAddr(v8::Local<v8::String> name,
|
|
219
|
+
const v8::PropertyCallbackInfo<v8::Value> &info) {
|
|
220
|
+
auto ptr = GetPointer(info.This());
|
|
221
|
+
if (ptr != nullptr) {
|
|
222
|
+
auto isolate = info.GetIsolate();
|
|
223
|
+
auto ret = std::to_string(canvas_native_image_asset_get_addr(ptr->GetImageAsset()));
|
|
224
|
+
info.GetReturnValue().Set(ConvertToV8String(isolate, ret));
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
info.GetReturnValue().SetEmptyString();
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
void
|
|
231
|
+
ImageBitmapImpl::GetReference(const v8::FunctionCallbackInfo<v8::Value> &args) {
|
|
232
|
+
auto ptr = GetPointer(args.This());
|
|
233
|
+
if (ptr != nullptr) {
|
|
234
|
+
auto isolate = args.GetIsolate();
|
|
235
|
+
auto reference = canvas_native_image_asset_reference(ptr->GetImageAsset());
|
|
236
|
+
auto ret = std::to_string(canvas_native_image_asset_get_addr(reference));
|
|
237
|
+
args.GetReturnValue().Set(ConvertToV8String(isolate, ret));
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
args.GetReturnValue().SetEmptyString();
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
const ImageAsset *ImageBitmapImpl::GetImageAsset() {
|
|
188
245
|
return this->bitmap_;
|
|
189
246
|
}
|
|
@@ -21,7 +21,7 @@ struct Options {
|
|
|
21
21
|
|
|
22
22
|
class ImageBitmapImpl : public ObjectWrapperImpl {
|
|
23
23
|
public:
|
|
24
|
-
explicit ImageBitmapImpl(ImageAsset *asset);
|
|
24
|
+
explicit ImageBitmapImpl(const ImageAsset *asset);
|
|
25
25
|
|
|
26
26
|
~ImageBitmapImpl();
|
|
27
27
|
|
|
@@ -30,11 +30,12 @@ public:
|
|
|
30
30
|
v8::EscapableHandleScope scope(isolate);
|
|
31
31
|
auto object = ImageBitmapImpl::GetCtor(isolate)->GetFunction(
|
|
32
32
|
context).ToLocalChecked()->NewInstance(context).ToLocalChecked();
|
|
33
|
-
SetNativeType(object, NativeType::ImageBitmap);
|
|
34
33
|
|
|
35
34
|
auto ptr = asset->Value();
|
|
36
35
|
auto impl = static_cast<ObjectWrapperImpl *>(ptr);
|
|
37
36
|
|
|
37
|
+
SetNativeType(impl, NativeType::ImageBitmap);
|
|
38
|
+
|
|
38
39
|
|
|
39
40
|
object->SetAlignedPointerInInternalField(0, ptr);
|
|
40
41
|
|
|
@@ -45,7 +46,7 @@ public:
|
|
|
45
46
|
|
|
46
47
|
static Options HandleOptions(v8::Isolate *isolate, const v8::Local<v8::Value> &options);
|
|
47
48
|
|
|
48
|
-
ImageAsset *GetImageAsset();
|
|
49
|
+
const ImageAsset *GetImageAsset();
|
|
49
50
|
|
|
50
51
|
static void Init(v8::Local<v8::Object> canvasModule, v8::Isolate *isolate);
|
|
51
52
|
|
|
@@ -59,9 +60,16 @@ public:
|
|
|
59
60
|
static void GetHeight(v8::Local<v8::String> name,
|
|
60
61
|
const v8::PropertyCallbackInfo<v8::Value> &info);
|
|
61
62
|
|
|
63
|
+
static void GetReference(const v8::FunctionCallbackInfo<v8::Value> &args);
|
|
64
|
+
|
|
65
|
+
static void GetAddr(v8::Local<v8::String> name,
|
|
66
|
+
const v8::PropertyCallbackInfo<v8::Value> &info);
|
|
67
|
+
|
|
62
68
|
static void Close(const v8::FunctionCallbackInfo<v8::Value> &args);
|
|
63
69
|
|
|
70
|
+
static void FromAsset(const v8::FunctionCallbackInfo<v8::Value> &args);
|
|
71
|
+
|
|
64
72
|
private:
|
|
65
|
-
ImageAsset *bitmap_;
|
|
73
|
+
const ImageAsset *bitmap_;
|
|
66
74
|
bool closed_ = false;
|
|
67
75
|
};
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Created by Osei Fortune on 06/08/2024.
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
#ifndef CANVAS_ANDROID_NATIVETYPE_H
|
|
6
|
+
#define CANVAS_ANDROID_NATIVETYPE_H
|
|
7
|
+
|
|
8
|
+
enum class NativeType {
|
|
9
|
+
None,
|
|
10
|
+
CanvasGradient,
|
|
11
|
+
CanvasPattern,
|
|
12
|
+
ImageData,
|
|
13
|
+
ImageAsset,
|
|
14
|
+
CanvasRenderingContext2D,
|
|
15
|
+
WebGLRenderingContextBase,
|
|
16
|
+
Path2D,
|
|
17
|
+
Matrix,
|
|
18
|
+
ImageBitmap,
|
|
19
|
+
TextMetrics,
|
|
20
|
+
|
|
21
|
+
WebGLQuery,
|
|
22
|
+
WebGLProgram,
|
|
23
|
+
WebGLShader,
|
|
24
|
+
WebGLBuffer,
|
|
25
|
+
WebGLFramebuffer,
|
|
26
|
+
WebGLRenderbuffer,
|
|
27
|
+
WebGLTexture,
|
|
28
|
+
WebGLActiveInfo,
|
|
29
|
+
OES_fbo_render_mipmap,
|
|
30
|
+
EXT_blend_minmax,
|
|
31
|
+
EXT_color_buffer_half_float,
|
|
32
|
+
EXT_disjoint_timer_query,
|
|
33
|
+
EXT_sRGB,
|
|
34
|
+
EXT_shader_texture_lod,
|
|
35
|
+
EXT_texture_filter_anisotropic,
|
|
36
|
+
OES_element_index_uint,
|
|
37
|
+
OES_standard_derivatives,
|
|
38
|
+
OES_texture_float,
|
|
39
|
+
OES_texture_float_linear,
|
|
40
|
+
OES_texture_half_float_linear,
|
|
41
|
+
OES_texture_half_float,
|
|
42
|
+
WEBGL_color_buffer_float,
|
|
43
|
+
OES_vertex_array_object,
|
|
44
|
+
WebGLVertexArrayObject,
|
|
45
|
+
WEBGL_compressed_texture_atc,
|
|
46
|
+
WEBGL_compressed_texture_etc1,
|
|
47
|
+
WEBGL_compressed_texture_s3tc,
|
|
48
|
+
WEBGL_compressed_texture_s3tc_srgb,
|
|
49
|
+
WEBGL_compressed_texture_etc,
|
|
50
|
+
WEBGL_compressed_texture_pvrtc,
|
|
51
|
+
WEBGL_lose_context,
|
|
52
|
+
ANGLE_instanced_arrays,
|
|
53
|
+
WEBGL_depth_texture,
|
|
54
|
+
WEBGL_draw_buffers,
|
|
55
|
+
WebGLShaderPrecisionFormat,
|
|
56
|
+
WebGLUniformLocation,
|
|
57
|
+
WebGLSampler,
|
|
58
|
+
WebGLTransformFeedback,
|
|
59
|
+
WebGLSync,
|
|
60
|
+
|
|
61
|
+
GPUAdapter,
|
|
62
|
+
GPUSupportedLimits,
|
|
63
|
+
GPUDevice,
|
|
64
|
+
GPUQueue,
|
|
65
|
+
GPUBuffer,
|
|
66
|
+
GPUInstance,
|
|
67
|
+
GPUCanvasContext,
|
|
68
|
+
GPUTexture,
|
|
69
|
+
GPUAdapterInfo,
|
|
70
|
+
GPUCommandEncoder,
|
|
71
|
+
GPUComputePass,
|
|
72
|
+
GPUQuerySet,
|
|
73
|
+
GPUShaderModule,
|
|
74
|
+
GPUPipelineLayout,
|
|
75
|
+
GPURenderPipeline,
|
|
76
|
+
GPUBindGroupLayout,
|
|
77
|
+
GPUTextureView,
|
|
78
|
+
GPURenderPassEncoder,
|
|
79
|
+
GPUCommandBuffer,
|
|
80
|
+
GPUBindGroup,
|
|
81
|
+
GPUComputePipeline,
|
|
82
|
+
GPUSampler,
|
|
83
|
+
GPURenderBundleEncoder,
|
|
84
|
+
GPURenderBundle
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
#endif //CANVAS_ANDROID_NATIVETYPE_H
|
|
@@ -9,9 +9,11 @@
|
|
|
9
9
|
#define ObjectWrapperImpl_h
|
|
10
10
|
|
|
11
11
|
#include "Common.h"
|
|
12
|
+
#include "NativeType.h"
|
|
12
13
|
|
|
13
14
|
class ObjectWrapperImpl {
|
|
14
15
|
public:
|
|
16
|
+
NativeType type_ = NativeType::None;
|
|
15
17
|
|
|
16
18
|
static void Finalizer(const v8::WeakCallbackInfo<ObjectWrapperImpl> &data) {
|
|
17
19
|
auto *pThis = data.GetParameter();
|
|
@@ -25,6 +27,54 @@ public:
|
|
|
25
27
|
weakHandle_.SetWeak(this, Finalizer, v8::WeakCallbackType::kParameter);
|
|
26
28
|
}
|
|
27
29
|
|
|
30
|
+
|
|
31
|
+
/*
|
|
32
|
+
static void SetNativeType(const v8::Local<v8::Object> &obj, NativeType type) {
|
|
33
|
+
if (!obj.IsEmpty() && !obj->IsNullOrUndefined() && obj->IsObject() &&
|
|
34
|
+
obj.As<v8::Object>()->InternalFieldCount() > 1) {
|
|
35
|
+
auto wrapper = obj.As<v8::Object>()->GetAlignedPointerFromInternalField(0);
|
|
36
|
+
if (wrapper != nullptr) {
|
|
37
|
+
((ObjectWrapperImpl *) wrapper)->type_ = type;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
*/
|
|
42
|
+
|
|
43
|
+
inline static NativeType GetNativeType(const v8::Local<v8::Value> &obj) {
|
|
44
|
+
if (!obj.IsEmpty() && !obj->IsNullOrUndefined() && obj->IsObject() &&
|
|
45
|
+
obj.As<v8::Object>()->InternalFieldCount() > 1) {
|
|
46
|
+
auto info = obj.As<v8::Object>()->GetAlignedPointerFromInternalField(0);
|
|
47
|
+
|
|
48
|
+
if (info != nullptr) {
|
|
49
|
+
auto value = static_cast<ObjectWrapperImpl *>(info);
|
|
50
|
+
return value->type_;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return NativeType::None;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
static void SetNativeType(ObjectWrapperImpl *obj, NativeType type) {
|
|
58
|
+
if (obj != nullptr) {
|
|
59
|
+
obj->type_ = type;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
static NativeType GetNativeType(const ObjectWrapperImpl *obj) {
|
|
64
|
+
if (obj != nullptr) {
|
|
65
|
+
return obj->type_;
|
|
66
|
+
}
|
|
67
|
+
return NativeType::None;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
static void SetNativeType(ObjectWrapperImpl &obj, NativeType type) {
|
|
71
|
+
obj.type_ = type;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
static NativeType GetNativeType(const ObjectWrapperImpl &obj) {
|
|
75
|
+
return obj.type_;
|
|
76
|
+
}
|
|
77
|
+
|
|
28
78
|
private:
|
|
29
79
|
v8::Global<v8::Object> weakHandle_;
|
|
30
80
|
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Created by Osei Fortune on 05/08/2024.
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
#pragma once
|
|
6
|
+
|
|
7
|
+
#include "Common.h"
|
|
8
|
+
#include <thread>
|
|
9
|
+
|
|
10
|
+
#ifdef __ANDROID__
|
|
11
|
+
|
|
12
|
+
#include <android/looper.h>
|
|
13
|
+
#include <cassert>
|
|
14
|
+
|
|
15
|
+
#endif
|
|
16
|
+
|
|
17
|
+
#ifdef __APPLE__
|
|
18
|
+
#include "NSOperationQueueWrapper.h"
|
|
19
|
+
#endif
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
#include <unistd.h>
|
|
23
|
+
#include <fcntl.h>
|
|
24
|
+
|
|
25
|
+
typedef void(*CompleteCallback)(bool success, void *data);
|
|
26
|
+
|
|
27
|
+
#ifdef __APPLE__
|
|
28
|
+
struct PromiseCallback {
|
|
29
|
+
struct Inner {
|
|
30
|
+
NSOperationQueueWrapper* current_queue = nullptr;
|
|
31
|
+
v8::Isolate *isolate_;
|
|
32
|
+
v8::Persistent<v8::Promise::Resolver> callback_;
|
|
33
|
+
v8::Persistent<v8::Value> error_;
|
|
34
|
+
CompleteCallback completeCallback_;
|
|
35
|
+
CompleteCallback completeCallbackWrapper_;
|
|
36
|
+
bool isPrepared_ = false;
|
|
37
|
+
void* data;
|
|
38
|
+
|
|
39
|
+
Inner(v8::Isolate *isolate, v8::Local<v8::Promise::Resolver> callback,
|
|
40
|
+
CompleteCallback completeCallback) : isolate_(isolate),
|
|
41
|
+
callback_(v8::Persistent<v8::Promise::Resolver>(
|
|
42
|
+
isolate,
|
|
43
|
+
callback)) {
|
|
44
|
+
this->completeCallback_ = completeCallback;
|
|
45
|
+
this->completeCallbackWrapper_ = [](bool success, void *data){
|
|
46
|
+
if(data != nullptr){
|
|
47
|
+
auto* callback = static_cast<PromiseCallback*>(data);
|
|
48
|
+
auto inner = callback->inner_.get();
|
|
49
|
+
if(inner == nullptr || inner->current_queue != nullptr){
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
inner->current_queue->addOperation([success, data, inner, callback](){
|
|
54
|
+
inner->completeCallback_(success, data);
|
|
55
|
+
// delete callback;
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
void prepare(){
|
|
62
|
+
current_queue = new NSOperationQueueWrapper(true);
|
|
63
|
+
isPrepared_ = true;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
void execute(bool complete, PromiseCallback* callback){
|
|
67
|
+
completeCallbackWrapper_(complete, callback);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
~Inner(){
|
|
71
|
+
callback_.Reset();
|
|
72
|
+
error_.Reset();
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
std::shared_ptr<Inner> inner_;
|
|
77
|
+
|
|
78
|
+
void prepare(){
|
|
79
|
+
auto inner = this->inner_.get();
|
|
80
|
+
if(inner == nullptr){return;}
|
|
81
|
+
inner->prepare();
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
void execute(bool complete) {
|
|
85
|
+
auto inner = this->inner_.get();
|
|
86
|
+
if (inner == nullptr) { return; }
|
|
87
|
+
inner->execute(complete, this);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
explicit PromiseCallback(std::shared_ptr<Inner> inner) : inner_(std::move(inner)) {}
|
|
91
|
+
|
|
92
|
+
PromiseCallback(v8::Isolate *isolate, v8::Local<v8::Promise::Resolver> callback,
|
|
93
|
+
CompleteCallback completeCallback) : inner_(
|
|
94
|
+
std::make_shared<Inner>(isolate, callback, completeCallback)) {}
|
|
95
|
+
};
|
|
96
|
+
#endif
|
|
97
|
+
|
|
98
|
+
#ifdef __ANDROID__
|
|
99
|
+
|
|
100
|
+
struct PromiseCallback {
|
|
101
|
+
struct Inner {
|
|
102
|
+
int fd_[2];
|
|
103
|
+
ALooper *looper_ = nullptr;
|
|
104
|
+
v8::Isolate *isolate_;
|
|
105
|
+
v8::Persistent<v8::Promise::Resolver> callback_;
|
|
106
|
+
void *data = nullptr;
|
|
107
|
+
CompleteCallback completeCallback_;
|
|
108
|
+
bool isPrepared_ = false;
|
|
109
|
+
|
|
110
|
+
Inner(v8::Isolate *isolate, v8::Local<v8::Promise::Resolver> callback,
|
|
111
|
+
CompleteCallback completeCallback) : isolate_(isolate),
|
|
112
|
+
callback_(v8::Persistent<v8::Promise::Resolver>(
|
|
113
|
+
isolate,
|
|
114
|
+
callback)) {
|
|
115
|
+
this->completeCallback_ = completeCallback;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
void prepare() {
|
|
119
|
+
// release previous looper
|
|
120
|
+
if (isPrepared_) {
|
|
121
|
+
ALooper_removeFd(looper_, fd_[0]);
|
|
122
|
+
close(fd_[0]);
|
|
123
|
+
fd_[0] = -1;
|
|
124
|
+
fd_[1] = -1;
|
|
125
|
+
ALooper_release(looper_);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
auto res = pipe(fd_);
|
|
129
|
+
assert(res != -1);
|
|
130
|
+
res = fcntl(fd_[1], F_SETFL, O_NONBLOCK);
|
|
131
|
+
assert(res != -1);
|
|
132
|
+
looper_ = ALooper_prepare(0);
|
|
133
|
+
ALooper_acquire(looper_);
|
|
134
|
+
|
|
135
|
+
isPrepared_ = true;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
void execute(bool complete) const {
|
|
139
|
+
if (!isPrepared_) { return; }
|
|
140
|
+
write(fd_[1],
|
|
141
|
+
&complete,
|
|
142
|
+
sizeof(bool));
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
~Inner() {
|
|
147
|
+
if (!isPrepared_) {
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
ALooper_removeFd(looper_, fd_[0]);
|
|
151
|
+
close(fd_[0]);
|
|
152
|
+
ALooper_release(looper_);
|
|
153
|
+
callback_.Reset();
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
void prepare() const {
|
|
158
|
+
auto inner = this->inner_.get();
|
|
159
|
+
if (inner == nullptr) { return; }
|
|
160
|
+
inner->prepare();
|
|
161
|
+
auto looper = inner->looper_;
|
|
162
|
+
auto fd = inner->fd_[0];
|
|
163
|
+
auto data = new PromiseCallback(this->inner_);
|
|
164
|
+
ALooper_addFd(looper,
|
|
165
|
+
fd,
|
|
166
|
+
0,
|
|
167
|
+
ALOOPER_EVENT_INPUT,
|
|
168
|
+
[](int fd, int events,
|
|
169
|
+
void *data) {
|
|
170
|
+
auto cb = static_cast<PromiseCallback *>(data);
|
|
171
|
+
bool done = false;
|
|
172
|
+
read(fd, &done,
|
|
173
|
+
sizeof(bool));
|
|
174
|
+
cb->inner_->completeCallback_(done, data);
|
|
175
|
+
return 0;
|
|
176
|
+
}, (void *) data);
|
|
177
|
+
|
|
178
|
+
inner->isPrepared_ = true;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
void execute(bool complete) const {
|
|
182
|
+
auto inner = this->inner_.get();
|
|
183
|
+
if (inner == nullptr) { return; }
|
|
184
|
+
inner->execute(complete);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
std::shared_ptr<Inner> inner_;
|
|
188
|
+
|
|
189
|
+
explicit PromiseCallback(std::shared_ptr<Inner> inner) : inner_(std::move(inner)) {}
|
|
190
|
+
|
|
191
|
+
PromiseCallback(v8::Isolate *isolate, v8::Local<v8::Promise::Resolver> callback,
|
|
192
|
+
CompleteCallback completeCallback) : inner_(
|
|
193
|
+
std::make_shared<Inner>(isolate, callback, completeCallback)) {}
|
|
194
|
+
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
#endif
|