diff --git a/packages/canvas/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/CanvasNative b/packages/canvas/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/CanvasNative index 3ff7a594..a8c41e15 100755 Binary files a/packages/canvas/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/CanvasNative and b/packages/canvas/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/CanvasNative differ diff --git a/packages/canvas/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Headers/CanvasNative.h b/packages/canvas/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Headers/CanvasNative.h index 510776d3..178b9692 100644 --- a/packages/canvas/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Headers/CanvasNative.h +++ b/packages/canvas/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Headers/CanvasNative.h @@ -4,13 +4,18 @@ // // Created by Osei Fortune on 30/09/2020. // -#import "canvas_native.h" -#import "canvas_ios.h" -#ifdef __OBJC__ +#ifdef __cplusplus +extern "C" { +#endif + #import +#import "canvas_native.h" +#import "canvas_ios.h" + //! Project version number for CanvasNative. + FOUNDATION_EXPORT double CanvasNativeVersionNumber; //! Project version string for CanvasNative. @@ -18,4 +23,7 @@ FOUNDATION_EXPORT const unsigned char CanvasNativeVersionString[]; // In this header, you should import all the public headers of your framework using statements like #import +#ifdef __cplusplus +} #endif + diff --git a/packages/canvas/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Headers/canvas_native.h b/packages/canvas/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Headers/canvas_native.h index cc45f904..9b65c215 100644 --- a/packages/canvas/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Headers/canvas_native.h +++ b/packages/canvas/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Headers/canvas_native.h @@ -1056,7 +1056,7 @@ struct ImageData *canvas_native_image_data_get_shared_instance(struct ImageData struct ImageAsset *canvas_native_image_asset_create(void); -struct ImageAsset *canvas_native_image_asset_shared_clone(const struct ImageAsset *asset); +struct ImageAsset *canvas_native_image_asset_shared_clone(struct ImageAsset *asset); bool canvas_native_image_asset_load_from_fd(struct ImageAsset *asset, int fd); @@ -1633,8 +1633,8 @@ struct ContextAttributes *canvas_native_webgl_get_context_attributes(struct WebG uint32_t canvas_native_webgl_get_error(struct WebGLState *state); -const struct WebGLExtension *canvas_native_webgl_get_extension(const char *name, - struct WebGLState *state); +struct WebGLExtension *canvas_native_webgl_get_extension(const char *name, + struct WebGLState *state); struct WebGLFramebufferAttachmentParameter *canvas_native_webgl_get_framebuffer_attachment_parameter(uint32_t target, uint32_t attachment, @@ -1804,6 +1804,22 @@ void canvas_native_webgl_tex_image2d_image_none(int32_t target, int32_t image_type, struct WebGLState *state); +void canvas_native_webgl_tex_image2d_canvas2d(int32_t target, + int32_t level, + int32_t internalformat, + int32_t format, + int32_t image_type, + struct CanvasRenderingContext2D *canvas, + struct WebGLState *state); + +void canvas_native_webgl_tex_image2d_webgl(int32_t target, + int32_t level, + int32_t _internalformat, + int32_t _format, + int32_t _image_type, + struct WebGLState *webgl, + struct WebGLState *state); + void canvas_native_webgl_tex_image2d(int32_t target, int32_t level, int32_t internalformat, @@ -1826,6 +1842,14 @@ void canvas_native_webgl_tex_image2d_none(int32_t target, int32_t image_type, struct WebGLState *state); +void canvas_native_webgl_tex_image2d_image_asset(int32_t target, + int32_t level, + int32_t internalformat, + int32_t format, + int32_t image_type, + struct ImageAsset *image_asset, + struct WebGLState *state); + void canvas_native_webgl_tex_parameterf(uint32_t target, uint32_t pname, float param, @@ -2667,4 +2691,10 @@ uintptr_t canvas_native_f32_buffer_mut_get_length(const struct F32Buffer *buffer uintptr_t canvas_native_f32_buffer_get_length(const struct F32Buffer *buffer); +uintptr_t canvas_native_string_buffer_get_length(const struct StringBuffer *buffer); + +char *canvas_native_string_buffer_get_value_at(const struct StringBuffer *buffer, uintptr_t index); + +void canvas_native_string_buffer_destroy(struct StringBuffer *buffer); + #endif /* CANVAS_C_H */ diff --git a/packages/canvas/platforms/ios/CanvasNative.xcframework/ios-arm64/dSYMs/CanvasNative.framework.dSYM/Contents/Resources/DWARF/CanvasNative b/packages/canvas/platforms/ios/CanvasNative.xcframework/ios-arm64/dSYMs/CanvasNative.framework.dSYM/Contents/Resources/DWARF/CanvasNative index 4f81a612..ed2b3920 100644 Binary files a/packages/canvas/platforms/ios/CanvasNative.xcframework/ios-arm64/dSYMs/CanvasNative.framework.dSYM/Contents/Resources/DWARF/CanvasNative and b/packages/canvas/platforms/ios/CanvasNative.xcframework/ios-arm64/dSYMs/CanvasNative.framework.dSYM/Contents/Resources/DWARF/CanvasNative differ diff --git a/packages/canvas/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/CanvasNative b/packages/canvas/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/CanvasNative index 5ffccdcf..887e1f59 100755 Binary files a/packages/canvas/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/CanvasNative and b/packages/canvas/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/CanvasNative differ diff --git a/packages/canvas/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Headers/CanvasNative.h b/packages/canvas/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Headers/CanvasNative.h index 510776d3..178b9692 100644 --- a/packages/canvas/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Headers/CanvasNative.h +++ b/packages/canvas/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Headers/CanvasNative.h @@ -4,13 +4,18 @@ // // Created by Osei Fortune on 30/09/2020. // -#import "canvas_native.h" -#import "canvas_ios.h" -#ifdef __OBJC__ +#ifdef __cplusplus +extern "C" { +#endif + #import +#import "canvas_native.h" +#import "canvas_ios.h" + //! Project version number for CanvasNative. + FOUNDATION_EXPORT double CanvasNativeVersionNumber; //! Project version string for CanvasNative. @@ -18,4 +23,7 @@ FOUNDATION_EXPORT const unsigned char CanvasNativeVersionString[]; // In this header, you should import all the public headers of your framework using statements like #import +#ifdef __cplusplus +} #endif + diff --git a/packages/canvas/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Headers/canvas_native.h b/packages/canvas/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Headers/canvas_native.h index cc45f904..9b65c215 100644 --- a/packages/canvas/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Headers/canvas_native.h +++ b/packages/canvas/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Headers/canvas_native.h @@ -1056,7 +1056,7 @@ struct ImageData *canvas_native_image_data_get_shared_instance(struct ImageData struct ImageAsset *canvas_native_image_asset_create(void); -struct ImageAsset *canvas_native_image_asset_shared_clone(const struct ImageAsset *asset); +struct ImageAsset *canvas_native_image_asset_shared_clone(struct ImageAsset *asset); bool canvas_native_image_asset_load_from_fd(struct ImageAsset *asset, int fd); @@ -1633,8 +1633,8 @@ struct ContextAttributes *canvas_native_webgl_get_context_attributes(struct WebG uint32_t canvas_native_webgl_get_error(struct WebGLState *state); -const struct WebGLExtension *canvas_native_webgl_get_extension(const char *name, - struct WebGLState *state); +struct WebGLExtension *canvas_native_webgl_get_extension(const char *name, + struct WebGLState *state); struct WebGLFramebufferAttachmentParameter *canvas_native_webgl_get_framebuffer_attachment_parameter(uint32_t target, uint32_t attachment, @@ -1804,6 +1804,22 @@ void canvas_native_webgl_tex_image2d_image_none(int32_t target, int32_t image_type, struct WebGLState *state); +void canvas_native_webgl_tex_image2d_canvas2d(int32_t target, + int32_t level, + int32_t internalformat, + int32_t format, + int32_t image_type, + struct CanvasRenderingContext2D *canvas, + struct WebGLState *state); + +void canvas_native_webgl_tex_image2d_webgl(int32_t target, + int32_t level, + int32_t _internalformat, + int32_t _format, + int32_t _image_type, + struct WebGLState *webgl, + struct WebGLState *state); + void canvas_native_webgl_tex_image2d(int32_t target, int32_t level, int32_t internalformat, @@ -1826,6 +1842,14 @@ void canvas_native_webgl_tex_image2d_none(int32_t target, int32_t image_type, struct WebGLState *state); +void canvas_native_webgl_tex_image2d_image_asset(int32_t target, + int32_t level, + int32_t internalformat, + int32_t format, + int32_t image_type, + struct ImageAsset *image_asset, + struct WebGLState *state); + void canvas_native_webgl_tex_parameterf(uint32_t target, uint32_t pname, float param, @@ -2667,4 +2691,10 @@ uintptr_t canvas_native_f32_buffer_mut_get_length(const struct F32Buffer *buffer uintptr_t canvas_native_f32_buffer_get_length(const struct F32Buffer *buffer); +uintptr_t canvas_native_string_buffer_get_length(const struct StringBuffer *buffer); + +char *canvas_native_string_buffer_get_value_at(const struct StringBuffer *buffer, uintptr_t index); + +void canvas_native_string_buffer_destroy(struct StringBuffer *buffer); + #endif /* CANVAS_C_H */ diff --git a/packages/canvas/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/_CodeSignature/CodeResources b/packages/canvas/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/_CodeSignature/CodeResources index 9a60ce2b..a1834083 100644 --- a/packages/canvas/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/_CodeSignature/CodeResources +++ b/packages/canvas/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/_CodeSignature/CodeResources @@ -10,7 +10,7 @@ Headers/CanvasNative.h - Fpy7Hlc8UqNId8jgtgKz5mOFBCU= + /f1joB+88Yli7N3M7UJmfZD+wrM= Headers/canvas_ios.h @@ -18,7 +18,7 @@ Headers/canvas_native.h - KjmIpBZrkmZPbZiPxYeDVFudctM= + kZAeynopf9HWpp2VwLjaus5M/hc= Info.plist @@ -94,7 +94,7 @@ hash2 - U94BOYW6ZUckumKy0f6esxE3QgCyRx/QAGTXLd+jBpU= + etIfFZplh+fbBvYN1m/bsCHh1B91DXsoX2FOvSfQ5Vw= Headers/canvas_ios.h @@ -108,7 +108,7 @@ hash2 - W14HFr1pFaToaWIQbCgrX4F1bw4RkCQFUOi0DiyMlww= + odQ0lZFQBS/l6gW2trmXrYsj7pbov7rXinUgSLQNp0Q= Modules/CanvasNative.swiftmodule/Project/arm64-apple-ios-simulator.swiftsourceinfo diff --git a/packages/canvas/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/dSYMs/CanvasNative.framework.dSYM/Contents/Resources/DWARF/CanvasNative b/packages/canvas/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/dSYMs/CanvasNative.framework.dSYM/Contents/Resources/DWARF/CanvasNative index e30cb344..3816887d 100644 Binary files a/packages/canvas/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/dSYMs/CanvasNative.framework.dSYM/Contents/Resources/DWARF/CanvasNative and b/packages/canvas/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/dSYMs/CanvasNative.framework.dSYM/Contents/Resources/DWARF/CanvasNative differ diff --git a/packages/canvas/platforms/ios/build.xcconfig b/packages/canvas/platforms/ios/build.xcconfig index 4622aca7..27818a1e 100644 --- a/packages/canvas/platforms/ios/build.xcconfig +++ b/packages/canvas/platforms/ios/build.xcconfig @@ -1,4 +1,4 @@ -OTHER_LDFLAGS[sdk=*] = $(inherited) -framework CanvasNative -framework OpenGLES -framework GLKit +OTHER_LDFLAGS[sdk=*] = $(inherited) -framework Foundation -framework CanvasNative -framework OpenGLES -framework GLKit HEADER_SEARCH_PATHS = $(inherited) "$(BUILD_DIR)/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)/NativeScript.framework/Headers" "$(BUILD_DIR)/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)/NativeScript.framework/Headers/include" diff --git a/packages/canvas/platforms/ios/src/NSOperationQueueWrapper.h b/packages/canvas/platforms/ios/src/NSOperationQueueWrapper.h index 2807c49c..375ea07a 100644 --- a/packages/canvas/platforms/ios/src/NSOperationQueueWrapper.h +++ b/packages/canvas/platforms/ios/src/NSOperationQueueWrapper.h @@ -1,13 +1,11 @@ -#import - - +#include class NSOperationQueueWrapper { public: NSOperationQueueWrapper(bool currentQueue); ~NSOperationQueueWrapper(); - void addOperation(void (*task)()); + void addOperation(std::function task); private: - NSOperationQueue *operationQueue; +void *operationQueue; }; diff --git a/packages/canvas/platforms/ios/src/NSOperationQueueWrapper.mm b/packages/canvas/platforms/ios/src/NSOperationQueueWrapper.mm index 8ae593e9..7e40c0f9 100644 --- a/packages/canvas/platforms/ios/src/NSOperationQueueWrapper.mm +++ b/packages/canvas/platforms/ios/src/NSOperationQueueWrapper.mm @@ -1,8 +1,5 @@ #import "NSOperationQueueWrapper.h" - - -#import -#import "NSOperationQueueWrapper.h" +#include @interface NSOperationQueueWrapperObjC : NSObject - (void)addOperation:(void (^)())task; @@ -28,13 +25,10 @@ -(instancetype)initWithCurrentQueue { return self; } -- (void)dealloc { - // In ARC, there's no need to manually release -} +- (void)dealloc {} - (void)addOperation:(void (^)())task { NSBlockOperation* operation = [NSBlockOperation blockOperationWithBlock:^{ - // Call the C++ task task(); }]; @@ -51,18 +45,29 @@ - (NSOperationQueue*)getOperationQueue { NSOperationQueueWrapper::NSOperationQueueWrapper(bool currentQueue) { if (currentQueue) { NSOperationQueueWrapperObjC* objcWrapper = [[NSOperationQueueWrapperObjC alloc] initWithCurrentQueue]; - operationQueue = [objcWrapper getOperationQueue]; + + CFTypeRef ptr = (__bridge_retained CFTypeRef)objcWrapper; + + operationQueue = (void*)ptr; }else { - NSOperationQueueWrapperObjC* objcWrapper = [NSOperationQueueWrapperObjC init]; - operationQueue = [objcWrapper getOperationQueue]; + NSOperationQueueWrapperObjC* objcWrapper = [[NSOperationQueueWrapperObjC alloc] init]; + CFTypeRef ptr = (__bridge_retained CFTypeRef)objcWrapper; + operationQueue = (void*)ptr; } } -NSOperationQueueWrapper::~NSOperationQueueWrapper() {} +NSOperationQueueWrapper::~NSOperationQueueWrapper() { + if(operationQueue != nullptr){ + CFBridgingRelease(operationQueue); + operationQueue = nullptr; + } +} -void NSOperationQueueWrapper::addOperation(void (*task)()) { - NSOperationQueueWrapperObjC* queue = static_cast(operationQueue); +void NSOperationQueueWrapper::addOperation(std::function task) { + + auto queue = (__bridge NSOperationQueueWrapperObjC*)(operationQueue); + [queue addOperation:^{ task(); }]; diff --git a/packages/canvas/platforms/ios/src/cpp/CanvasJSIModule.cpp b/packages/canvas/platforms/ios/src/cpp/CanvasJSIModule.cpp index 601a952a..10cdf954 100644 --- a/packages/canvas/platforms/ios/src/cpp/CanvasJSIModule.cpp +++ b/packages/canvas/platforms/ios/src/cpp/CanvasJSIModule.cpp @@ -160,11 +160,10 @@ void CanvasJSIModule::CreateImageBitmap(const v8::FunctionCallbackInfo(); auto data = v8::External::New(isolate, ret); @@ -296,10 +295,9 @@ void CanvasJSIModule::CreateImageBitmap(const v8::FunctionCallbackInfo(); auto data = v8::External::New(isolate, ret); @@ -449,77 +447,177 @@ void CanvasJSIModule::CreateImageBitmap(const v8::FunctionCallbackInfo( - runtime, arguments[1]); - - auto jsi_callback = new JSIReadFileCallback( - std::shared_ptr( - cbFunc)); - - - auto queue = [NSOperationQueue new]; - [queue addOperationWithBlock:^{ - - - bool done = false; - auto ret = canvas_native_helper_read_file( - rust::Str(file.c_str())); - - if (!canvas_native_helper_read_file_has_error(*ret)) { - auto buf = canvas_native_helper_read_file_get_data( - std::move(ret)); - - auto vec_buffer = std::make_shared>( - std::move(buf)); - - jsi_callback->data_ = std::make_shared(runtime, jsi::ArrayBuffer( - runtime, - vec_buffer)); - done = true; - } else { - auto error = canvas_native_helper_read_file_get_error( - *ret); - - jsi_callback->data_ = std::make_shared(runtime,jsi::String::createFromAscii( - runtime, - error.c_str())); - } - - - - - [current_queue addOperationWithBlock:^{ - + auto current_queue = new NSOperationQueueWrapper(true); + + + auto bufferValue = args[0]; - auto func = jsi_callback->value_->asObject( - runtime).asFunction( - runtime); + if (isArrayBuffer) { + auto arrayBuffer = bufferValue.As(); + auto dataBuffer = (uint8_t *) arrayBuffer->GetBackingStore()->Data(); + v8::Global ab(isolate, arrayBuffer); + std::thread thread( + [&dataBuffer, jsi_callback, &options, shared_asset, current_queue]( + float sx_or_options, + float sy, + float sw, + float sh, + v8::Global ab, + size_t size + ) { + auto done = canvas_native_image_bitmap_create_from_encoded_bytes_src_rect_with_output( + dataBuffer, size, + sx_or_options, + sy, + sw, + sh, + options.flipY, + options.premultiplyAlpha, + options.colorSpaceConversion, + options.resizeQuality, + options.resizeWidth, + options.resizeHeight, shared_asset); + + + auto main_task = [jsi_callback, current_queue, done]() { + + + v8::Isolate *isolate = jsi_callback->isolate_; + v8::Locker locker(isolate); + v8::Isolate::Scope isolate_scope(isolate); + v8::HandleScope handle_scope(isolate); + v8::Local callback = jsi_callback->callback_->Get(isolate); + v8::Local cbData = jsi_callback->data_->Get( + isolate).As(); + v8::Local context = callback->GetCreationContextChecked(); + v8::Context::Scope context_scope(context); + + auto ret = ImageBitmapImpl::GetCtor(isolate)->GetFunction( + context).ToLocalChecked()->NewInstance( + context).ToLocalChecked(); + + SetNativeType(isolate, ret, NativeType::ImageBitmap); + + ret->SetInternalField(0, cbData); + + v8::Local args[2]; + + if (done) { + args[0] = v8::Null(isolate); + args[1] = ret; + } else { + args[0] = v8::Exception::Error( + ConvertToV8String(isolate, "Failed to load image")); + args[1] = v8::Null(isolate); + } + + callback->Call(context, context->Global(), 2, args); + + + delete jsi_callback; + delete current_queue; + + }; + current_queue->addOperation(main_task); + + }, + (float) sx_or_options->NumberValue(context).ToChecked(), + (float) sy->NumberValue(context).ToChecked(), + (float) sw->NumberValue(context).ToChecked(), + (float) sh->NumberValue(context).ToChecked(), + std::move(ab), + arrayBuffer->ByteLength()); + thread.detach(); - if (done) { - auto buf = jsi_callback->data_->asObject(runtime).getArrayBuffer(runtime); - func.call(runtime, {jsi::Value::null(), std::move(buf)}); - } else { - auto error = jsi_callback->data_->asString(runtime); - func.call(runtime, {std::move(error), jsi::Value::null()}); + return; } - delete static_cast(jsi_callback); - - - }]; - }]; - + auto ta = bufferValue.As(); + + auto array = ta->Buffer(); + auto offset = ta->ByteOffset(); + auto size = ta->Length(); + auto data_ptr = (uint8_t*) array->GetBackingStore()->Data() + offset; + + + + v8::Global ab(isolate, ta); + std::thread thread( + [jsi_callback, &options, data_ptr, size, shared_asset, current_queue]( + float sx_or_options, + float sy, + float sw, + float sh, + v8::Global ab + ) { - */ + auto done = canvas_native_image_bitmap_create_from_encoded_bytes_src_rect_with_output( + data_ptr, size, + sx_or_options, + sy, + sw, + sh, + options.flipY, + options.premultiplyAlpha, + options.colorSpaceConversion, + options.resizeQuality, + options.resizeWidth, + options.resizeHeight, shared_asset); + + + auto main_task = [jsi_callback, current_queue, done]() { + + + v8::Isolate *isolate = jsi_callback->isolate_; + v8::Locker locker(isolate); + v8::Isolate::Scope isolate_scope(isolate); + v8::HandleScope handle_scope(isolate); + v8::Local callback = jsi_callback->callback_->Get(isolate); + v8::Local cbData = jsi_callback->data_->Get( + isolate).As(); + v8::Local context = callback->GetCreationContextChecked(); + v8::Context::Scope context_scope(context); + + auto ret = ImageBitmapImpl::GetCtor(isolate)->GetFunction( + context).ToLocalChecked()->NewInstance( + context).ToLocalChecked(); + + SetNativeType(isolate, ret, NativeType::ImageBitmap); + + ret->SetInternalField(0, cbData); + + v8::Local args[2]; + + if (done) { + args[0] = v8::Null(isolate); + args[1] = ret; + } else { + args[0] = v8::Exception::Error( + ConvertToV8String(isolate, "Failed to load image")); + args[1] = v8::Null(isolate); + } + + callback->Call(context, context->Global(), 2, args); + + + delete jsi_callback; + delete current_queue; + + }; + current_queue->addOperation(main_task); + + + + }, + (float) sx_or_options->NumberValue(context).ToChecked(), + (float) sy->NumberValue(context).ToChecked(), + (float) sw->NumberValue(context).ToChecked(), + (float) sh->NumberValue(context).ToChecked(), std::move(ab)); + thread.detach(); + + #endif @@ -810,6 +908,120 @@ void CanvasJSIModule::ReadFile(const v8::FunctionCallbackInfo &args) thread.detach(); #endif + + + +#ifdef __APPLE__ + + auto current_queue = new NSOperationQueueWrapper(true); + + auto queue = new NSOperationQueueWrapper(false); + + auto task = [jsi_callback, current_queue, queue, file]() { + + + + bool done = false; + auto ret = canvas_native_helper_read_file(file.c_str()); + + if (!canvas_native_helper_read_file_has_error(ret)) { + auto buf = canvas_native_helper_read_file_get_data(ret); + + jsi_callback->SetData(buf); + + done = true; + } else { + auto error = canvas_native_helper_read_file_get_error(ret); + + jsi_callback->SetError((char*)error); + } + + canvas_native_helper_destroy(ret); + + + + + auto main_task = [jsi_callback, current_queue, queue, done]() { + + + v8::Isolate *isolate = jsi_callback->isolate_; + v8::Locker locker(isolate); + v8::Isolate::Scope isolate_scope(isolate); + v8::HandleScope handle_scope(isolate); + v8::Local callback = jsi_callback->callback_.Get(isolate); + v8::Local context = callback->GetCreationContextChecked(); + v8::Context::Scope context_scope(context); + + v8::Local args[2]; + + if (done) { + args[0] = v8::Null(isolate); + + auto vec = jsi_callback->data_; + + + auto buf = (void*)canvas_native_u8_buffer_get_bytes(vec); + auto size = (size_t)canvas_native_u8_buffer_get_length(vec); + + + auto store = v8::ArrayBuffer::NewBackingStore(buf, size, + [](void *data, + size_t length, + void *deleter_data) { + if (deleter_data != + nullptr) { + // a little extreme :'D + delete static_cast(deleter_data); + } + }, + jsi_callback); + + args[1] = v8::ArrayBuffer::New(isolate, std::move(store)); + } else { + auto error = jsi_callback->error_; + args[0] = v8::Exception::Error(ConvertToV8String(isolate, error)); + args[1] = v8::Null(isolate); + } + + v8::TryCatch tc(isolate); + v8::Local result; + if (!callback->Call(context, context->Global(), 2, args).ToLocal( + &result)) { + if (tc.HasCaught()) { + + v8::Local stack; + bool success = tc.StackTrace(context).ToLocal(&stack); + if (!success || stack.IsEmpty()) { + delete jsi_callback; + return; + } + + v8::Local stackV8Str; + success = stack->ToDetailString(context).ToLocal(&stackV8Str); + if (!success || stackV8Str.IsEmpty()) { + delete jsi_callback; + return; + } + LogToConsole(ConvertFromV8String(isolate, stackV8Str)); + + } + } + + if (!done) { + delete jsi_callback; + } + + delete queue; + delete current_queue; + + }; + current_queue->addOperation(main_task); + }; + + queue->addOperation(task); +#endif + + } diff --git a/packages/canvas/platforms/ios/src/cpp/Common.h b/packages/canvas/platforms/ios/src/cpp/Common.h index 82ec33db..e3714cd6 100644 --- a/packages/canvas/platforms/ios/src/cpp/Common.h +++ b/packages/canvas/platforms/ios/src/cpp/Common.h @@ -8,7 +8,17 @@ #ifdef __APPLE__ #include -#include + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + +#ifdef __cplusplus +} +#endif #endif #ifdef __ANDROID__ diff --git a/packages/canvas/platforms/ios/src/cpp/Helpers.h b/packages/canvas/platforms/ios/src/cpp/Helpers.h index 6a112f1b..3a0e43de 100644 --- a/packages/canvas/platforms/ios/src/cpp/Helpers.h +++ b/packages/canvas/platforms/ios/src/cpp/Helpers.h @@ -19,8 +19,8 @@ -const char *LOG_TAG = "JS"; -int m_maxLogcatObjectSize = 4096; +static const char *LOG_TAG = "JS"; +static int m_maxLogcatObjectSize = 4096; #ifdef __ANDROID__ static void sendToADBLogcat(const std::string &message, android_LogPriority logPriority) { @@ -238,7 +238,7 @@ inline static NativeType GetNativeType(v8::Isolate *isolate, const v8::Local that, const char* name, v8::FunctionCallback slow_callback, @@ -283,7 +283,7 @@ static void SetFastMethod(v8::Local context, that->Set(context, name_string, function).Check(); } -void SetFastMethodNoSideEffect(v8::Local context, +static void SetFastMethodNoSideEffect(v8::Local context, v8::Local that, const char* name, v8::FunctionCallback slow_callback, @@ -306,7 +306,7 @@ void SetFastMethodNoSideEffect(v8::Local context, v8::String::NewFromUtf8(isolate, name, type).ToLocalChecked(); that->Set(context, name_string, function).Check(); } -void SetFastMethodNoSideEffect(v8::Isolate* isolate, +static void SetFastMethodNoSideEffect(v8::Isolate* isolate, v8::Local that, const char* name, v8::FunctionCallback slow_callback, diff --git a/packages/canvas/platforms/ios/src/cpp/ImageAssetImpl.cpp b/packages/canvas/platforms/ios/src/cpp/ImageAssetImpl.cpp index 92687e56..c2c1c3f0 100644 --- a/packages/canvas/platforms/ios/src/cpp/ImageAssetImpl.cpp +++ b/packages/canvas/platforms/ios/src/cpp/ImageAssetImpl.cpp @@ -7,7 +7,7 @@ #include "JSIRuntime.h" #include "JSICallback.h" #include "Caches.h" -#include "NSOperationQueueWrapper.h" + #include "Helpers.h" #include "Common.h" @@ -15,8 +15,8 @@ ImageAssetImpl::ImageAssetImpl(ImageAsset * asset): asset_(asset) { } ImageAssetImpl::~ImageAssetImpl() { - canvas_native_image_asset_destroy(this->GetImageAsset()); - asset_ = nullptr; + // canvas_native_image_asset_destroy(this->GetImageAsset()); + // asset_ = nullptr; } void ImageAssetImpl::Init(v8::Local canvasModule, v8::Isolate *isolate) { @@ -116,7 +116,7 @@ void ImageAssetImpl::Ctor(const v8::FunctionCallbackInfo &args) { auto image_asset = canvas_native_image_asset_create(); - auto object = new ImageAssetImpl(std::move(image_asset)); + auto object = new ImageAssetImpl(image_asset); auto ext = v8::External::New(isolate, object); @@ -255,14 +255,14 @@ void ImageAssetImpl::FromUrlCb(const v8::FunctionCallbackInfo &args) std::thread thread( [jsi_callback, asset]( - const std::string &url) { - auto done = canvas_native_image_asset_load_from_url(asset, url.c_str()); - - write(jsi_callback->fd_[1], - &done, - sizeof(bool)); - - }, std::move(url)); + const std::string &url) { + auto done = canvas_native_image_asset_load_from_url(asset, url.c_str()); + + write(jsi_callback->fd_[1], + &done, + sizeof(bool)); + + }, std::move(url)); thread.detach(); @@ -276,11 +276,59 @@ void ImageAssetImpl::FromUrlCb(const v8::FunctionCallbackInfo &args) auto queue = new NSOperationQueueWrapper(false); - auto task = [&jsi_callback, ¤t_queue, &queue, &asset, &url]() { + + + /* std::thread task([jsi_callback, current_queue, asset](std::string url) { + + + auto done = canvas_native_image_asset_load_from_url(asset, url.c_str()); + + + auto main_task = [jsi_callback, current_queue, url, done]() { + + + v8::Isolate *isolate = jsi_callback->isolate_; + v8::Locker locker(isolate); + v8::Isolate::Scope isolate_scope(isolate); + v8::HandleScope handle_scope(isolate); + v8::Local callback = jsi_callback->callback_->Get(isolate); + v8::Local context = callback->GetCreationContextChecked(); + v8::Context::Scope context_scope(context); + + v8::Local args[1] = {v8::Boolean::New(isolate, done)}; + + // v8::TryCatch tc(isolate); + + callback->Call(context, context->Global(), 1, + args); // ignore JS return value + + + delete jsi_callback; + // delete queue; + delete current_queue; + + + }; + + current_queue->addOperation(main_task); + + + }, std::move(url)); + + task.detach(); + + */ + + + + + + auto task = [jsi_callback, current_queue, queue, asset, url]() { auto done = canvas_native_image_asset_load_from_url(asset, url.c_str()); canvas_native_image_asset_destroy(asset); - auto main_task = [&jsi_callback, ¤t_queue, &queue, &url, &done]() { + + auto main_task = [jsi_callback, current_queue, queue, url, done]() { v8::Isolate *isolate = jsi_callback->isolate_; @@ -306,13 +354,14 @@ void ImageAssetImpl::FromUrlCb(const v8::FunctionCallbackInfo &args) }; + current_queue->addOperation(main_task); + }; -#endif - - + queue->addOperation(task); +#endif } @@ -390,15 +439,15 @@ void ImageAssetImpl::FromFileCb(const v8::FunctionCallbackInfo &args) std::thread thread( [jsi_callback, asset]( - const std::string &path) { - - auto done = canvas_native_image_asset_load_from_path(asset, path.c_str()); - - write(jsi_callback->fd_[1], - &done, - sizeof(bool)); - - }, std::move(path)); + const std::string &path) { + + auto done = canvas_native_image_asset_load_from_path(asset, path.c_str()); + + write(jsi_callback->fd_[1], + &done, + sizeof(bool)); + + }, std::move(path)); thread.detach(); @@ -412,14 +461,14 @@ void ImageAssetImpl::FromFileCb(const v8::FunctionCallbackInfo &args) auto queue = new NSOperationQueueWrapper(false); - auto task = [&jsi_callback, ¤t_queue, &queue, &asset, &path]() { + auto task = [jsi_callback, current_queue, queue, asset, path]() { auto done = canvas_native_image_asset_load_from_path(asset, path.c_str()); - - canvas_native_image_asset_destroy(asset); - auto main_task = [&jsi_callback, ¤t_queue, &queue, &done]() { + canvas_native_image_asset_destroy(asset); + auto main_task = [jsi_callback, current_queue, queue, done]() { + v8::Isolate *isolate = jsi_callback->isolate_; v8::Locker locker(isolate); v8::Isolate::Scope isolate_scope(isolate); @@ -443,7 +492,11 @@ void ImageAssetImpl::FromFileCb(const v8::FunctionCallbackInfo &args) }; + current_queue->addOperation(main_task); + }; + + queue->addOperation(task); #endif } @@ -493,7 +546,7 @@ void ImageAssetImpl::FromBytesCb(const v8::FunctionCallbackInfo &args auto data = (uint8_t *) bytes->GetBackingStore()->Data(); auto asset = canvas_native_image_asset_shared_clone(ptr->GetImageAsset()); - + auto callback = args[1].As(); auto jsi_callback = new JSICallback(isolate, callback); @@ -535,9 +588,9 @@ void ImageAssetImpl::FromBytesCb(const v8::FunctionCallbackInfo &args std::thread thread( [jsi_callback, asset, data, size]() { - + auto done = canvas_native_image_asset_load_from_raw(asset, data, size); - + write(jsi_callback->fd_[1], &done, sizeof(bool)); @@ -561,10 +614,10 @@ void ImageAssetImpl::FromBytesCb(const v8::FunctionCallbackInfo &args auto task = [jsi_callback, current_queue, queue, asset, data, size]() { auto done = canvas_native_image_asset_load_from_raw(asset, data, size); - + canvas_native_image_asset_destroy(asset); - auto main_task = [&jsi_callback, ¤t_queue, &queue, &done]() { + auto main_task = [jsi_callback, current_queue, queue, done]() { v8::Isolate *isolate = jsi_callback->isolate_; @@ -590,7 +643,11 @@ void ImageAssetImpl::FromBytesCb(const v8::FunctionCallbackInfo &args }; + current_queue->addOperation(main_task); + }; + + queue->addOperation(task); #endif } @@ -672,18 +729,18 @@ void ImageAssetImpl::SaveCb(const v8::FunctionCallbackInfo &args) { std::thread thread( [jsi_callback, asset, format]( - const std::string &path) { - - auto done = canvas_native_image_asset_save_path(asset, - path.c_str(), - format); - - - write(jsi_callback->fd_[1], - &done, - sizeof(bool)); - - }, std::move(path), format); + const std::string &path) { + + auto done = canvas_native_image_asset_save_path(asset, + path.c_str(), + format); + + + write(jsi_callback->fd_[1], + &done, + sizeof(bool)); + + }, std::move(path), format); thread.detach(); @@ -697,13 +754,13 @@ void ImageAssetImpl::SaveCb(const v8::FunctionCallbackInfo &args) { auto queue = new NSOperationQueueWrapper(false); - auto task = [&jsi_callback, ¤t_queue, &queue, &asset, &path, &format]() { + auto task = [jsi_callback, current_queue, queue, asset, path, format]() { auto done = canvas_native_image_asset_save_path(asset, path.c_str(), format); - + canvas_native_image_asset_destroy(asset); - auto main_task = [&jsi_callback, ¤t_queue, &queue, &done]() { + auto main_task = [jsi_callback, current_queue, queue, done]() { v8::Isolate *isolate = jsi_callback->isolate_; @@ -728,8 +785,10 @@ void ImageAssetImpl::SaveCb(const v8::FunctionCallbackInfo &args) { }; - + current_queue->addOperation(main_task); }; + + queue->addOperation(task); #endif diff --git a/packages/canvas/platforms/ios/src/cpp/ImageAssetImpl.h b/packages/canvas/platforms/ios/src/cpp/ImageAssetImpl.h index f8eca050..dd8e35ba 100644 --- a/packages/canvas/platforms/ios/src/cpp/ImageAssetImpl.h +++ b/packages/canvas/platforms/ios/src/cpp/ImageAssetImpl.h @@ -9,6 +9,7 @@ #include #include "Helpers.h" #include "Common.h" +#include "NSOperationQueueWrapper.h" class ImageAssetImpl{ public: diff --git a/packages/canvas/platforms/ios/src/cpp/ImageBitmapImpl.cpp b/packages/canvas/platforms/ios/src/cpp/ImageBitmapImpl.cpp index 7f8352d1..3c866f5c 100644 --- a/packages/canvas/platforms/ios/src/cpp/ImageBitmapImpl.cpp +++ b/packages/canvas/platforms/ios/src/cpp/ImageBitmapImpl.cpp @@ -3,7 +3,6 @@ // #include "ImageBitmapImpl.h" -#include "ImageAssetImpl.h" #include "Caches.h" ImageBitmapImpl::ImageBitmapImpl(ImageAsset* asset) diff --git a/packages/canvas/platforms/ios/src/cpp/ImageBitmapImpl.h b/packages/canvas/platforms/ios/src/cpp/ImageBitmapImpl.h index a6c79f7b..9b089302 100644 --- a/packages/canvas/platforms/ios/src/cpp/ImageBitmapImpl.h +++ b/packages/canvas/platforms/ios/src/cpp/ImageBitmapImpl.h @@ -4,6 +4,7 @@ #pragma once +#include "ImageAssetImpl.h" #include "Helpers.h" #include diff --git a/packages/canvas/platforms/ios/src/cpp/TextEncoderImpl.cpp b/packages/canvas/platforms/ios/src/cpp/TextEncoderImpl.cpp index a141107d..7838d9d4 100644 --- a/packages/canvas/platforms/ios/src/cpp/TextEncoderImpl.cpp +++ b/packages/canvas/platforms/ios/src/cpp/TextEncoderImpl.cpp @@ -114,6 +114,7 @@ void TextEncoderImpl::Encode(const v8::FunctionCallbackInfo &args) { auto encoded = canvas_native_text_encoder_encode(ptr->GetTextEncoder(), ConvertFromV8String(isolate, text).c_str()); + auto data = canvas_native_u8_buffer_get_bytes_mut(encoded); auto length = canvas_native_u8_buffer_get_length(encoded); diff --git a/packages/canvas/platforms/ios/src/cpp/webgl/WebGLRenderingContext.cpp b/packages/canvas/platforms/ios/src/cpp/webgl/WebGLRenderingContext.cpp index 61f34d08..3789ec14 100644 --- a/packages/canvas/platforms/ios/src/cpp/webgl/WebGLRenderingContext.cpp +++ b/packages/canvas/platforms/ios/src/cpp/webgl/WebGLRenderingContext.cpp @@ -199,7 +199,7 @@ v8::Local WebGLRenderingContext::GetParameterInternal(v8::Isolate *is canvas_native_i32_buffer_destroy((I32Buffer *) deleter_data); } }, - buf); + ret); auto arraybuffer = v8::ArrayBuffer::New(isolate, std::move(store)); @@ -370,7 +370,7 @@ void WebGLRenderingContext::BindAttribLocation(const v8::FunctionCallbackInfoGetProgram(), index, - rust::Str(name.c_str()), + name.c_str(), ptr->GetState() ); @@ -662,40 +662,64 @@ void WebGLRenderingContext::BufferData(const v8::FunctionCallbackInfo auto sizeOrBuf = args[1]; if (sizeOrBuf->IsArrayBufferView()) { if (sizeOrBuf->IsUint16Array()) { - auto array = sizeOrBuf.As(); - auto buf = GetTypedArrayData(array); + auto buf = sizeOrBuf.As(); + + auto array = buf->Buffer(); + auto offset = buf->ByteOffset(); + auto size = buf->Length(); + auto data_ptr = (uint8_t*) array->GetBackingStore()->Data() + offset; + auto data = static_cast((void*) data_ptr); canvas_native_webgl_buffer_data_u16( target, - buf, + data, size, usage, ptr->GetState() ); } else if (sizeOrBuf->IsFloat32Array()) { - auto array = sizeOrBuf.As(); - auto buf = GetTypedArrayData(array); + auto buf = sizeOrBuf.As(); + + auto array = buf->Buffer(); + auto offset = buf->ByteOffset(); + auto size = buf->Length(); + auto data_ptr = (uint8_t*) array->GetBackingStore()->Data() + offset; + auto data = static_cast((void*) data_ptr); + canvas_native_webgl_buffer_data_f32( target, - buf, + data, size, usage, ptr->GetState() ); } else { - auto array = sizeOrBuf.As(); - auto buf = GetTypedArrayData(array); + auto buf = sizeOrBuf.As(); + + auto array = buf->Buffer(); + auto offset = buf->ByteOffset(); + auto size = buf->Length(); + auto data_ptr = (uint8_t*) array->GetBackingStore()->Data() + offset; + auto data = static_cast((void*) data_ptr); + + canvas_native_webgl_buffer_data( target, - buf, + data, size, usage, ptr->GetState() ); } } else if (sizeOrBuf->IsArrayBuffer()) { - auto buffer = sizeOrBuf.As(); - auto data = GetArrayBufferData(buffer); + auto array = sizeOrBuf.As(); + + auto size = array->ByteLength(); + auto data = (uint8_t*) array->GetBackingStore()->Data(); + + + + canvas_native_webgl_buffer_data( target, - data, + data, size, usage, ptr->GetState() ); @@ -740,23 +764,35 @@ void WebGLRenderingContext::BufferSubData(const v8::FunctionCallbackInfoIsTypedArray()) { - auto array = buf.As(); - auto buff = GetTypedArrayData(array); + auto buff = buf.As(); + + auto array = buff->Buffer(); + auto offset = buff->ByteOffset(); + auto size = buff->Length(); + auto data_ptr = (uint8_t*) array->GetBackingStore()->Data() + offset; + auto data = static_cast((void*) data_ptr); + + + canvas_native_webgl_buffer_sub_data( target, static_cast(offset), - buff, + data, size, ptr->GetState() ); } else if (buf->IsArrayBuffer()) { auto arrayBuffer = buf.As(); - auto data = GetArrayBufferData(arrayBuffer); + + auto size = arrayBuffer->ByteLength(); + auto data = (uint8_t*) arrayBuffer->GetBackingStore()->Data(); + + canvas_native_webgl_buffer_sub_data( target, - static_cast(offset), - data, + static_cast(offset), + data, size, ptr->GetState() ); } @@ -917,7 +953,6 @@ void WebGLRenderingContext::CompileShader(const v8::FunctionCallbackInfoGetCurrentContext(); if (args.Length() > 0) { auto shader = WebGLShader::GetPointer(args[0].As()); @@ -968,8 +1003,15 @@ void WebGLRenderingContext::CompressedTexImage2D(const v8::FunctionCallbackInfo< auto pixels = args[6]; if (pixels->IsObject()) { if (pixels->IsTypedArray()) { - auto array = pixels.As(); - auto buf = GetTypedArrayData(array); + auto buf = pixels.As(); + + auto array = buf->Buffer(); + auto offset = buf->ByteOffset(); + auto size = buf->Length(); + auto data_ptr = (uint8_t*) array->GetBackingStore()->Data() + offset; + auto data = static_cast((void*) data_ptr); + + canvas_native_webgl_compressed_tex_image2d( target, level, @@ -977,13 +1019,16 @@ void WebGLRenderingContext::CompressedTexImage2D(const v8::FunctionCallbackInfo< width, height, border, - buf, + data, size, ptr->GetState() ); } else if (pixels->IsArrayBuffer()) { - auto ab = pixels.As(); - auto buf = GetArrayBufferData(ab); - + auto array = pixels.As(); + + auto size = array->ByteLength(); + auto data = (uint8_t*) array->GetBackingStore()->Data(); + + canvas_native_webgl_compressed_tex_image2d( target, level, @@ -991,7 +1036,7 @@ void WebGLRenderingContext::CompressedTexImage2D(const v8::FunctionCallbackInfo< width, height, border, - buf, + data, size, ptr->GetState() ); } @@ -1023,8 +1068,15 @@ WebGLRenderingContext::CompressedTexSubImage2D(const v8::FunctionCallbackInfoIsObject()) { auto pixels = args[7]; if (pixels->IsTypedArray()) { - auto px = pixels.As(); - auto buf = GetTypedArrayData(px); + auto buf = pixels.As(); + auto array = buf->Buffer(); + auto offset = buf->ByteOffset(); + auto size = buf->Length(); + auto data_ptr = (uint8_t*) array->GetBackingStore()->Data() + offset; + auto data = static_cast((void*) data_ptr); + + + canvas_native_webgl_compressed_tex_sub_image2d( target, level, @@ -1033,12 +1085,13 @@ WebGLRenderingContext::CompressedTexSubImage2D(const v8::FunctionCallbackInfoGetState() ); } else if (pixels->IsArrayBuffer()) { - auto buffer = pixels.As(); - auto buf = GetArrayBufferData(buffer); + auto array = pixels.As(); + auto size = array->ByteLength(); + auto data = (uint8_t*) array->GetBackingStore()->Data(); canvas_native_webgl_compressed_tex_sub_image2d( target, @@ -1048,7 +1101,7 @@ WebGLRenderingContext::CompressedTexSubImage2D(const v8::FunctionCallbackInfoGetState() ); } @@ -1187,7 +1240,6 @@ void WebGLRenderingContext::CreateProgram(const v8::FunctionCallbackInfoGetCurrentContext(); auto program = canvas_native_webgl_create_program( @@ -1211,7 +1263,6 @@ void WebGLRenderingContext::CreateRenderbuffer(const v8::FunctionCallbackInfoGetCurrentContext(); auto buffer = canvas_native_webgl_create_renderbuffer( @@ -1869,15 +1920,19 @@ void WebGLRenderingContext::GetAttachedShaders(const v8::FunctionCallbackInfoGetProgram(), ptr->GetState() ); - auto len = info.size(); + + auto len = canvas_native_u32_buffer_get_length(info); + auto buf = canvas_native_u32_buffer_get_bytes(info); auto array = v8::Array::New( isolate, (int) len); for (int i = 0; i < len; ++i) { auto shader = WebGLShader::NewInstance(isolate, new WebGLShader( - info[i])); + buf[i])); array->Set(context, i, shader); } args.GetReturnValue().Set(array); + + canvas_native_u32_buffer_destroy(info); return; } } @@ -1894,7 +1949,6 @@ void WebGLRenderingContext::GetAttribLocation(const v8::FunctionCallbackInfoGetCurrentContext(); auto programValue = args[0]; auto type = GetNativeType(isolate, programValue); @@ -1905,8 +1959,7 @@ void WebGLRenderingContext::GetAttribLocation(const v8::FunctionCallbackInfoGetProgram(), - rust::Str( - name.c_str()), + name.c_str(), ptr->GetState() ); args.GetReturnValue().Set(location); @@ -1963,65 +2016,68 @@ void WebGLRenderingContext::GetContextAttributes(const v8::FunctionCallbackInfo< auto ret = v8::Object::New(isolate); auto alpha = canvas_native_webgl_context_attribute_get_get_alpha( - *attr); + attr); + ret->Set(context, ConvertToV8String(isolate, "alpha"), v8::Boolean::New(isolate, alpha)); auto antialias = canvas_native_webgl_context_attribute_get_get_antialias( - *attr); + attr); ret->Set(context, ConvertToV8String(isolate, "antialias"), v8::Boolean::New(isolate, antialias)); auto depth = canvas_native_webgl_context_attribute_get_get_depth( - *attr); + attr); ret->Set(context, ConvertToV8String(isolate, "depth"), v8::Boolean::New(isolate, depth)); auto fail_if_major_performance_caveat = canvas_native_webgl_context_attribute_get_get_fail_if_major_performance_caveat( - *attr); + attr); ret->Set(context, ConvertToV8String(isolate, "failIfMajorPerformanceCaveat"), v8::Boolean::New(isolate, fail_if_major_performance_caveat)); auto power_preference = canvas_native_webgl_context_attribute_get_get_power_preference( - *attr); + attr); ret->Set(context, ConvertToV8String(isolate, "powerPreference"), - ConvertToV8OneByteString(isolate, std::move(power_preference))); + ConvertToV8OneByteString(isolate, (char*)power_preference)); auto premultiplied_alpha = canvas_native_webgl_context_attribute_get_get_premultiplied_alpha( - *attr); + attr); ret->Set(context, ConvertToV8String(isolate, "premultipliedAlpha"), v8::Boolean::New(isolate, premultiplied_alpha)); auto preserve_drawing_buffer = canvas_native_webgl_context_attribute_get_get_preserve_drawing_buffer( - *attr); + attr); ret->Set(context, ConvertToV8String(isolate, "preserveDrawingBuffer"), v8::Boolean::New(isolate, preserve_drawing_buffer)); auto stencil = canvas_native_webgl_context_attribute_get_get_stencil( - *attr); + attr); ret->Set(context, ConvertToV8String(isolate, "stencil"), v8::Boolean::New(isolate, stencil)); auto desynchronized = canvas_native_webgl_context_attribute_get_get_desynchronized( - *attr); + attr); ret->Set(context, ConvertToV8String(isolate, "desynchronized"), v8::Boolean::New(isolate, desynchronized)); auto xr_compatible = canvas_native_webgl_context_attribute_get_get_xr_compatible( - *attr); + attr); ret->Set(context, ConvertToV8String(isolate, "xrCompatible"), v8::Boolean::New(isolate, xr_compatible)); + + canvas_native_context_attributes_destroy(attr); args.GetReturnValue().Set(ret); @@ -2035,7 +2091,6 @@ void WebGLRenderingContext::GetError(const v8::FunctionCallbackInfo & } auto isolate = args.GetIsolate(); - auto context = isolate->GetCurrentContext(); auto ret = canvas_native_webgl_get_error( ptr->GetState()); @@ -2064,107 +2119,118 @@ void WebGLRenderingContext::GetExtension(const v8::FunctionCallbackInfoGetState()); if (canvas_native_webgl_context_extension_is_none( - *ext)) { + ext)) { + canvas_native_webgl_extension_destroy(ext); args.GetReturnValue().SetNull(); return; } auto type = canvas_native_webgl_context_extension_get_type( - *ext); + ext); switch (type) { - case WebGLExtensionType::OES_fbo_render_mipmap: { + case WebGLExtensionType::WebGLExtensionTypeOES_fbo_render_mipmap: { auto ret = OES_fbo_render_mipmapImpl::NewInstance(isolate, new OES_fbo_render_mipmapImpl()); args.GetReturnValue().Set(ret); + canvas_native_webgl_extension_destroy(ext); return; } - case WebGLExtensionType::EXT_blend_minmax: { + case WebGLExtensionType::WebGLExtensionTypeEXT_blend_minmax: { auto ret = EXT_blend_minmaxImpl::NewInstance(isolate, new EXT_blend_minmaxImpl()); args.GetReturnValue().Set(ret); + canvas_native_webgl_extension_destroy(ext); return; } - case WebGLExtensionType::EXT_color_buffer_half_float: { + case WebGLExtensionType::WebGLExtensionTypeEXT_color_buffer_half_float: { auto ret = EXT_color_buffer_half_floatImpl::NewInstance(isolate, new EXT_color_buffer_half_floatImpl()); args.GetReturnValue().Set(ret); + canvas_native_webgl_extension_destroy(ext); return; } - case WebGLExtensionType::EXT_disjoint_timer_query: { - auto ret = canvas_native_webgl_context_extension_to_ext_disjoint_timer_query( - std::move(ext)); + case WebGLExtensionType::WebGLExtensionTypeEXT_disjoint_timer_query: { + auto ret = canvas_native_webgl_context_extension_to_ext_disjoint_timer_query(ext); auto query = EXT_disjoint_timer_queryImpl::NewInstance(isolate, - new EXT_disjoint_timer_queryImpl( - std::move(ret))); + new EXT_disjoint_timer_queryImpl(ret)); args.GetReturnValue().Set(query); + canvas_native_webgl_extension_destroy(ext); return; } - case WebGLExtensionType::EXT_sRGB: { + case WebGLExtensionType::WebGLExtensionTypeEXT_sRGB: { auto ret = EXT_sRGBImpl::NewInstance(isolate, new EXT_sRGBImpl()); args.GetReturnValue().Set(ret); + canvas_native_webgl_extension_destroy(ext); return; } - case WebGLExtensionType::EXT_shader_texture_lod: { + case WebGLExtensionType::WebGLExtensionTypeEXT_shader_texture_lod: { auto ret = EXT_shader_texture_lodImpl::NewInstance(isolate, new EXT_shader_texture_lodImpl()); args.GetReturnValue().Set(ret); + canvas_native_webgl_extension_destroy(ext); return; } - case WebGLExtensionType::EXT_texture_filter_anisotropic: { + case WebGLExtensionType::WebGLExtensionTypeEXT_texture_filter_anisotropic: { auto ret = EXT_texture_filter_anisotropicImpl::NewInstance(isolate, new EXT_texture_filter_anisotropicImpl()); args.GetReturnValue().Set(ret); + canvas_native_webgl_extension_destroy(ext); return; } - case WebGLExtensionType::OES_element_index_uint: { + case WebGLExtensionType::WebGLExtensionTypeOES_element_index_uint: { auto ret = OES_element_index_uintImpl::NewInstance(isolate, new OES_element_index_uintImpl()); args.GetReturnValue().Set(ret); + canvas_native_webgl_extension_destroy(ext); return; } - case WebGLExtensionType::OES_standard_derivatives: { + case WebGLExtensionType::WebGLExtensionTypeOES_standard_derivatives: { auto ret = OES_standard_derivativesImpl::NewInstance( isolate, new OES_standard_derivativesImpl()); args.GetReturnValue().Set(ret); + canvas_native_webgl_extension_destroy(ext); return; } - case WebGLExtensionType::OES_texture_float: { + case WebGLExtensionType::WebGLExtensionTypeOES_texture_float: { auto ret = OES_texture_floatImpl::NewInstance(isolate, new OES_texture_floatImpl()); args.GetReturnValue().Set(ret); + canvas_native_webgl_extension_destroy(ext); return; } - case WebGLExtensionType::OES_texture_float_linear: { + case WebGLExtensionType::WebGLExtensionTypeOES_texture_float_linear: { auto ret = OES_texture_float_linearImpl::NewInstance(isolate, new OES_texture_float_linearImpl()); args.GetReturnValue().Set(ret); + canvas_native_webgl_extension_destroy(ext); return; } - case WebGLExtensionType::OES_texture_half_float: { + case WebGLExtensionType::WebGLExtensionTypeOES_texture_half_float: { auto ret = OES_texture_half_floatImpl::NewInstance(isolate, new OES_texture_half_floatImpl()); args.GetReturnValue().Set(ret); + canvas_native_webgl_extension_destroy(ext); return; } - case WebGLExtensionType::OES_texture_half_float_linear: { + case WebGLExtensionType::WebGLExtensionTypeOES_texture_half_float_linear: { auto ret = OES_texture_half_float_linearImpl::NewInstance(isolate, new OES_texture_half_float_linearImpl()); args.GetReturnValue().Set(ret); + canvas_native_webgl_extension_destroy(ext); return; } - case WebGLExtensionType::OES_vertex_array_object: { - auto ret = canvas_native_webgl_context_extension_to_oes_vertex_array_object( - std::move(ext)); + case WebGLExtensionType::WebGLExtensionTypeOES_vertex_array_object: { + auto ret = canvas_native_webgl_context_extension_to_oes_vertex_array_object(ext); auto array = OES_vertex_array_objectImpl::NewInstance(isolate, - new OES_vertex_array_objectImpl( - std::move(ret))); + new OES_vertex_array_objectImpl(ret)); args.GetReturnValue().Set(array); + canvas_native_webgl_extension_destroy(ext); return; } - case WebGLExtensionType::WEBGL_color_buffer_float: { + case WebGLExtensionType::WebGLExtensionTypeWEBGL_color_buffer_float: { auto ret = WEBGL_color_buffer_floatImpl::NewInstance(isolate, new WEBGL_color_buffer_floatImpl()); if (ptr->GetVersion() == @@ -2173,82 +2239,90 @@ void WebGLRenderingContext::GetExtension(const v8::FunctionCallbackInfoGetState() ); + + if (canvas_native_webgl_framebuffer_attachment_parameter_get_is_texture( - *ret)) { + ret)) { auto value = canvas_native_webgl_framebuffer_attachment_parameter_get_value( - *ret); + ret); + auto texture = WebGLTexture::NewInstance(isolate, new WebGLTexture( value)); args.GetReturnValue().Set(texture); + + canvas_native_webgl_framebuffer_attachment_parameter_destroy(ret); return; } if (canvas_native_webgl_framebuffer_attachment_parameter_get_is_renderbuffer( - *ret)) { + ret)) { auto value = canvas_native_webgl_framebuffer_attachment_parameter_get_value( - *ret); + ret); auto object = WebGLRenderbuffer::NewInstance(isolate, new WebGLRenderbuffer( value)); @@ -2301,12 +2380,16 @@ void WebGLRenderingContext::GetFramebufferAttachmentParameter( v8::Boolean::New(isolate, true)); args.GetReturnValue().Set(object); + + canvas_native_webgl_framebuffer_attachment_parameter_destroy(ret); return; } args.GetReturnValue().Set(canvas_native_webgl_framebuffer_attachment_parameter_get_value( - *ret)); + ret)); + + canvas_native_webgl_framebuffer_attachment_parameter_destroy(ret); } @@ -2346,7 +2429,6 @@ void WebGLRenderingContext::GetProgramInfoLog(const v8::FunctionCallbackInfoGetCurrentContext(); if (args.Length() > 0) { auto programValue = args[0]; @@ -2358,14 +2440,15 @@ void WebGLRenderingContext::GetProgramInfoLog(const v8::FunctionCallbackInfoGetProgram(), ptr->GetState() ); - - - if (log.empty()) { + + + if (strlen(log) == 0) { args.GetReturnValue().SetEmptyString(); + canvas_native_string_destroy((char*) log); return; } - args.GetReturnValue().Set(ConvertToV8OneByteString(isolate, std::move(log))); + args.GetReturnValue().Set(ConvertToV8OneByteString(isolate, (char*)log)); return; } } @@ -2398,10 +2481,13 @@ void WebGLRenderingContext::GetProgramParameter(const v8::FunctionCallbackInfoGetState() ); + if (canvas_native_webgl_result_get_is_none( - *ret)) { + ret)) { args.GetReturnValue().SetNull(); + + canvas_native_webgl_WebGLResult_destroy(ret); return; } switch (pname) { @@ -2409,11 +2495,14 @@ void WebGLRenderingContext::GetProgramParameter(const v8::FunctionCallbackInfoGetCurrentContext(); if (args.Length() > 0) { auto value = args[0]; @@ -2473,8 +2561,14 @@ void WebGLRenderingContext::GetShaderInfoLog(const v8::FunctionCallbackInfoGetShader(), ptr->GetState() ); + + if(strlen(log) == 0){ + args.GetReturnValue().SetEmptyString(); + canvas_native_string_destroy((char*) log); + return; + } - args.GetReturnValue().Set(ConvertToV8OneByteString(isolate, std::move(log))); + args.GetReturnValue().Set(ConvertToV8OneByteString(isolate, (char*)log)); return; } @@ -2510,8 +2604,10 @@ void WebGLRenderingContext::GetShaderParameter(const v8::FunctionCallbackInfoGetCurrentContext(); if (args.Length() > 0) { auto value = args[0]; @@ -2589,8 +2688,14 @@ void WebGLRenderingContext::GetShaderSource(const v8::FunctionCallbackInfoGetShader(), ptr->GetState() ); + + if(strlen(source) == 0){ + args.GetReturnValue().SetEmptyString(); + canvas_native_string_destroy((char*) source); + return; + } - args.GetReturnValue().Set(ConvertToV8OneByteString(isolate, std::move(source))); + args.GetReturnValue().Set(ConvertToV8OneByteString(isolate, (char*)source)); return; } } @@ -2614,14 +2719,21 @@ WebGLRenderingContext::GetSupportedExtensions(const v8::FunctionCallbackInfoGetState()); - auto len = exts.size(); + + auto len = canvas_native_string_buffer_get_length(exts); + auto array = v8::Array::New(isolate, (int) len); for (int i = 0; i < len; ++i) { - auto item = exts[i]; - array->Set(context, i, ConvertToV8OneByteString(isolate, std::move(item))); + auto item = canvas_native_string_buffer_get_value_at(exts, i); + if(item != nullptr){ + array->Set(context, i, ConvertToV8OneByteString(isolate, (char*)item)); + } + } args.GetReturnValue().Set(array); + + canvas_native_string_buffer_destroy(exts); } void @@ -2633,13 +2745,13 @@ WebGLRenderingContext::__GetSupportedExtensions(const v8::FunctionCallbackInfoGetCurrentContext(); auto exts = canvas_native_webgl_get_supported_extensions_to_string( ptr->GetState()); + - args.GetReturnValue().Set(ConvertToV8OneByteString(isolate, std::move(exts))); + args.GetReturnValue().Set(ConvertToV8OneByteString(isolate, (char*)exts)); } void @@ -2693,8 +2805,7 @@ WebGLRenderingContext::GetUniformLocation(const v8::FunctionCallbackInfoGetProgram(), - rust::Str( - name.c_str()), + name.c_str(), ptr->GetState() ); @@ -2743,31 +2854,35 @@ WebGLRenderingContext::GetUniform(const v8::FunctionCallbackInfo &arg ptr->GetState()); switch (canvas_native_webgl_result_get_type( - *val)) { - case WebGLResultType::Boolean: + val)) { + case WebGLResultType::WebGLResultTypeBoolean: args.GetReturnValue().Set(canvas_native_webgl_result_get_bool( - *val)); + val)); + canvas_native_webgl_WebGLResult_destroy(val); return; - case WebGLResultType::None: + case WebGLResultType::WebGLResultTypeNone: args.GetReturnValue().SetNull(); + canvas_native_webgl_WebGLResult_destroy(val); return; - case WebGLResultType::String: { + case WebGLResultType::WebGLResultTypeString: { auto str = canvas_native_webgl_result_get_string( - *val); + val); args.GetReturnValue().Set( - ConvertToV8OneByteString(isolate, std::move(str))); + ConvertToV8OneByteString(isolate, (char*)str)); + canvas_native_webgl_WebGLResult_destroy(val); return; } - case WebGLResultType::BooleanArray: { + case WebGLResultType::WebGLResultTypeBooleanArray: { auto ret = canvas_native_webgl_result_get_bool_array( - *val); - auto len = ret.size(); + val); + auto len = canvas_native_u8_buffer_get_length(ret); + auto buf = canvas_native_u8_buffer_get_bytes(ret); auto array = v8::Array::New( isolate, (int) len); for (int i = 0; i < len; ++i) { - auto item = ret[i]; + auto item = buf[i]; array->Set( context, i, v8::Boolean::New(isolate, @@ -2775,105 +2890,122 @@ WebGLRenderingContext::GetUniform(const v8::FunctionCallbackInfo &arg 1)); } args.GetReturnValue().Set(array); + canvas_native_webgl_WebGLResult_destroy(val); return; } - case WebGLResultType::F32Array: { + case WebGLResultType::WebGLResultTypeF32Array: { auto ret = canvas_native_webgl_result_get_f32_array( - *val); + val); - auto buf = new VecMutableBuffer( - std::move( - ret)); + + auto buf = (uint8_t*)canvas_native_f32_buffer_get_bytes(ret); + auto size = canvas_native_f32_buffer_get_length(ret); + auto bytes_size = size * sizeof(float); + - auto store = v8::ArrayBuffer::NewBackingStore(buf->data(), - buf->size(), + auto store = v8::ArrayBuffer::NewBackingStore(buf, + bytes_size, [](void *data, size_t length, void *deleter_data) { if (deleter_data != nullptr) { - delete (VecMutableBuffer *) deleter_data; + canvas_native_f32_buffer_destroy((F32Buffer *) deleter_data); } }, - buf); + ret); auto arraybuffer = v8::ArrayBuffer::New(isolate, std::move(store)); args.GetReturnValue().Set( - v8::Float32Array::New(arraybuffer, 0, buf->buffer_size()) + v8::Float32Array::New(arraybuffer, 0, size) ); + + canvas_native_webgl_WebGLResult_destroy(val); return; } - case WebGLResultType::I32Array: { + case WebGLResultType::WebGLResultTypeI32Array: { auto ret = canvas_native_webgl_result_get_i32_array( - *val); - - auto buf = new VecMutableBuffer( - std::move( - ret)); + val); + + auto buf = (uint8_t*)canvas_native_i32_buffer_get_bytes(ret); + auto size = canvas_native_i32_buffer_get_length(ret); + auto bytes_size = size * sizeof(int32_t); + - auto store = v8::ArrayBuffer::NewBackingStore(buf->data(), - buf->size(), + auto store = v8::ArrayBuffer::NewBackingStore(buf, bytes_size, [](void *data, size_t length, void *deleter_data) { - if (deleter_data != - nullptr) { - delete (VecMutableBuffer *) deleter_data; + if (deleter_data != nullptr) { + canvas_native_i32_buffer_destroy((I32Buffer *) deleter_data); } }, - buf); + ret); auto arraybuffer = v8::ArrayBuffer::New(isolate, std::move(store)); args.GetReturnValue().Set( - v8::Int32Array::New(arraybuffer, 0, buf->buffer_size()) + v8::Int32Array::New(arraybuffer, 0, size) ); + + canvas_native_webgl_WebGLResult_destroy(val); + return; } - case WebGLResultType::U32Array: { + case WebGLResultType::WebGLResultTypeU32Array: { auto ret = canvas_native_webgl_result_get_u32_array( - *val); + val); + + auto buf = (uint8_t*)canvas_native_u32_buffer_get_bytes(ret); + auto size = canvas_native_u32_buffer_get_length(ret); + auto bytes_size = size * sizeof(uint32_t); - auto buf = new VecMutableBuffer( - std::move( - ret)); - - auto store = v8::ArrayBuffer::NewBackingStore(buf->data(), - buf->size(), + auto store = v8::ArrayBuffer::NewBackingStore(buf, bytes_size, [](void *data, size_t length, void *deleter_data) { if (deleter_data != nullptr) { - delete (VecMutableBuffer *) deleter_data; + canvas_native_u32_buffer_destroy((U32Buffer *) deleter_data); } }, - buf); + ret); auto arraybuffer = v8::ArrayBuffer::New(isolate, std::move(store)); args.GetReturnValue().Set( - v8::Uint32Array::New(arraybuffer, 0, buf->buffer_size()) + v8::Uint32Array::New(arraybuffer, 0, size) ); + + + canvas_native_webgl_WebGLResult_destroy(val); + + return; } - case WebGLResultType::F32: + case WebGLResultType::WebGLResultTypeF32: args.GetReturnValue().Set((double) canvas_native_webgl_result_get_f32( - *val)); + val)); + + canvas_native_webgl_WebGLResult_destroy(val); return; - case WebGLResultType::I32: + case WebGLResultType::WebGLResultTypeI32: args.GetReturnValue().Set(canvas_native_webgl_result_get_i32( - *val)); + val)); + + canvas_native_webgl_WebGLResult_destroy(val); return; - case WebGLResultType::U32: - args.GetReturnValue().Set((int32_t) canvas_native_webgl_result_get_u32( - *val)); + case WebGLResultType::WebGLResultTypeU32: + args.GetReturnValue().Set(canvas_native_webgl_result_get_u32( + val)); + + canvas_native_webgl_WebGLResult_destroy(val); return; } } @@ -2937,26 +3069,27 @@ WebGLRenderingContext::GetVertexAttrib(const v8::FunctionCallbackInfo if (pname == GL_CURRENT_VERTEX_ATTRIB) { auto val = canvas_native_webgl_result_get_f32_array( - *ret); - - auto buf = new VecMutableBuffer( - std::move(val)); + ret); + + auto buf = (uint8_t*)canvas_native_f32_buffer_get_bytes(val); + auto size = canvas_native_f32_buffer_get_length(val); + auto bytes_size = size * sizeof(float); - auto store = v8::ArrayBuffer::NewBackingStore(buf->data(), buf->size(), + auto store = v8::ArrayBuffer::NewBackingStore(buf, bytes_size, [](void *data, size_t length, void *deleter_data) { if (deleter_data != nullptr) { - delete (VecMutableBuffer *) deleter_data; + canvas_native_f32_buffer_destroy((F32Buffer *) deleter_data); } }, - buf); + val); auto arraybuffer = v8::ArrayBuffer::New(isolate, std::move(store)); args.GetReturnValue().Set( - v8::Float32Array::New(arraybuffer, 0, buf->buffer_size()) + v8::Float32Array::New(arraybuffer, 0, size) ); return; @@ -2965,11 +3098,11 @@ WebGLRenderingContext::GetVertexAttrib(const v8::FunctionCallbackInfo pname == GL_VERTEX_ATTRIB_ARRAY_NORMALIZED) { args.GetReturnValue().Set(canvas_native_webgl_result_get_bool( - *ret)); + ret)); return; } else { args.GetReturnValue().Set(canvas_native_webgl_result_get_i32( - *ret)); + ret)); return; } } @@ -3009,7 +3142,6 @@ WebGLRenderingContext::IsBuffer(const v8::FunctionCallbackInfo &args) } auto isolate = args.GetIsolate(); - auto context = isolate->GetCurrentContext(); auto value = args[0]; auto type = GetNativeType(isolate, value); @@ -3036,8 +3168,6 @@ WebGLRenderingContext::IsContextLost(const v8::FunctionCallbackInfo & return; } - auto isolate = args.GetIsolate(); - auto context = isolate->GetCurrentContext(); auto ret = canvas_native_webgl_get_is_context_lost( ptr->GetState()); @@ -3075,7 +3205,6 @@ WebGLRenderingContext::IsFramebuffer(const v8::FunctionCallbackInfo & } auto isolate = args.GetIsolate(); - auto context = isolate->GetCurrentContext(); auto value = args[0]; auto type = GetNativeType(isolate, value); @@ -3103,7 +3232,6 @@ WebGLRenderingContext::IsProgram(const v8::FunctionCallbackInfo &args } auto isolate = args.GetIsolate(); - auto context = isolate->GetCurrentContext(); auto value = args[0]; auto type = GetNativeType(isolate, value); @@ -3132,7 +3260,6 @@ WebGLRenderingContext::IsRenderbuffer(const v8::FunctionCallbackInfo } auto isolate = args.GetIsolate(); - auto context = isolate->GetCurrentContext(); auto value = args[0]; auto type = GetNativeType(isolate, value); @@ -3161,7 +3288,6 @@ WebGLRenderingContext::IsShader(const v8::FunctionCallbackInfo &args) } auto isolate = args.GetIsolate(); - auto context = isolate->GetCurrentContext(); auto value = args[0]; auto type = GetNativeType(isolate, value); @@ -3189,7 +3315,6 @@ WebGLRenderingContext::IsTexture(const v8::FunctionCallbackInfo &args } auto isolate = args.GetIsolate(); - auto context = isolate->GetCurrentContext(); auto value = args[0]; auto type = GetNativeType(isolate, value); @@ -3236,8 +3361,6 @@ WebGLRenderingContext::LinkProgram(const v8::FunctionCallbackInfo &ar } auto isolate = args.GetIsolate(); - auto context = isolate->GetCurrentContext(); - auto value = args[0]; auto type = GetNativeType(isolate, value); if (type == NativeType::WebGLProgram) { @@ -3335,7 +3458,16 @@ WebGLRenderingContext::ReadPixels(const v8::FunctionCallbackInfo &arg auto pixels = args[6]; if (pixels->IsTypedArray()) { auto buf = pixels.As(); - auto slice = GetTypedArrayData(buf); + + auto array = buf->Buffer(); + auto offset = buf->ByteOffset(); + auto size = buf->Length(); + auto data_ptr = (uint8_t*) array->GetBackingStore()->Data() + offset; + auto data = static_cast((void*) data_ptr); + + + + canvas_native_webgl_read_pixels_u8( x, y, @@ -3343,7 +3475,7 @@ WebGLRenderingContext::ReadPixels(const v8::FunctionCallbackInfo &arg height, format, type, - slice, + data, size, ptr->GetState() ); return; @@ -3351,8 +3483,11 @@ WebGLRenderingContext::ReadPixels(const v8::FunctionCallbackInfo &arg if (pixels->IsArrayBuffer()) { - auto buf = pixels.As(); - auto slice = GetArrayBufferData(buf); + auto array = pixels.As(); + + auto size = array->ByteLength(); + auto data = (uint8_t*) array->GetBackingStore()->Data(); + canvas_native_webgl_read_pixels_u8( x, y, @@ -3360,7 +3495,7 @@ WebGLRenderingContext::ReadPixels(const v8::FunctionCallbackInfo &arg height, format, type, - slice, + data, size, ptr->GetState() ); } @@ -3459,7 +3594,6 @@ WebGLRenderingContext::ShaderSource(const v8::FunctionCallbackInfo &a } auto isolate = args.GetIsolate(); - auto context = isolate->GetCurrentContext(); auto value = args[0]; auto type = GetNativeType(isolate, value); @@ -3470,8 +3604,7 @@ WebGLRenderingContext::ShaderSource(const v8::FunctionCallbackInfo &a if (shader != nullptr) { canvas_native_webgl_shader_source( shader->GetShader(), - rust::Str( - source.c_str()), + source.c_str(), ptr->GetState()); } } @@ -3695,6 +3828,7 @@ WebGLRenderingContext::TexImage2D(const v8::FunctionCallbackInfo &arg if (image_asset != nullptr) { + canvas_native_webgl_tex_image2d_image_asset( target, @@ -3823,8 +3957,15 @@ WebGLRenderingContext::TexImage2D(const v8::FunctionCallbackInfo &arg ptr->GetState() ); } else if (value->IsTypedArray()) { - auto typedArray = value.As(); - auto buf = GetTypedArrayData(typedArray); + auto buf = value.As(); + + auto array = buf->Buffer(); + auto offset = buf->ByteOffset(); + auto size = buf->Length(); + auto data_ptr = (uint8_t*) array->GetBackingStore()->Data() + offset; + auto data = static_cast((void*) data_ptr); + + canvas_native_webgl_tex_image2d( target, level, @@ -3834,13 +3975,17 @@ WebGLRenderingContext::TexImage2D(const v8::FunctionCallbackInfo &arg border, format, type, - buf, + data, size, ptr->GetState() ); return; } else if (value->IsArrayBuffer()) { auto array = value.As(); - auto buf = GetArrayBufferData(array); + + auto size = array->ByteLength(); + auto data = (uint8_t*) array->GetBackingStore()->Data(); + + canvas_native_webgl_tex_image2d( target, level, @@ -3850,7 +3995,7 @@ WebGLRenderingContext::TexImage2D(const v8::FunctionCallbackInfo &arg border, format, type, - buf, + data, size, ptr->GetState() ); return; @@ -4037,8 +4182,15 @@ WebGLRenderingContext::TexSubImage2D(const v8::FunctionCallbackInfo & if (pixels->IsTypedArray()) { - auto array = pixels.As(); - auto buf = GetTypedArrayData(array); + auto buf = pixels.As(); + + auto array = buf->Buffer(); + auto offset = buf->ByteOffset(); + auto size = buf->Length(); + auto data_ptr = (uint8_t*) array->GetBackingStore()->Data() + offset; + auto data = static_cast((void*) data_ptr); + + canvas_native_webgl_tex_sub_image2d( target, level, @@ -4048,12 +4200,16 @@ WebGLRenderingContext::TexSubImage2D(const v8::FunctionCallbackInfo & height, format, type, - buf, + data, size, ptr->GetState() ); } else if (pixels->IsArrayBuffer()) { auto array = pixels.As(); - auto buf = GetArrayBufferData(array); + + auto size = array->ByteLength(); + auto data = (uint8_t*) array->GetBackingStore()->Data(); + + canvas_native_webgl_tex_sub_image2d( target, level, @@ -4063,7 +4219,7 @@ WebGLRenderingContext::TexSubImage2D(const v8::FunctionCallbackInfo & height, format, type, - buf, + data, size, ptr->GetState() ); } @@ -4187,10 +4343,17 @@ WebGLRenderingContext::VertexAttrib1fv(const v8::FunctionCallbackInfo auto value = args[1]; if (value->IsFloat32Array()) { - auto array = value.As(); - auto buf = GetTypedArrayData(array); + auto buf = value.As(); + + auto array = buf->Buffer(); + auto offset = buf->ByteOffset(); + auto size = buf->Length(); + auto data_ptr = (uint8_t*) array->GetBackingStore()->Data() + offset; + auto data = static_cast((void*) data_ptr); + + canvas_native_webgl_vertex_attrib1fv( - index, buf, + index, data, size, ptr->GetState()); } } @@ -4212,10 +4375,18 @@ WebGLRenderingContext::VertexAttrib2fv(const v8::FunctionCallbackInfo auto value = args[1]; if (value->IsFloat32Array()) { - auto array = value.As(); - auto buf = GetTypedArrayData(array); + auto buf = value.As(); + + auto array = buf->Buffer(); + auto offset = buf->ByteOffset(); + auto size = buf->Length(); + auto data_ptr = (uint8_t*) array->GetBackingStore()->Data() + offset; + auto data = static_cast((void*) data_ptr); + + + canvas_native_webgl_vertex_attrib2fv( - index, buf, + index, data, size, ptr->GetState()); } } @@ -4237,10 +4408,17 @@ WebGLRenderingContext::VertexAttrib3fv(const v8::FunctionCallbackInfo auto value = args[1]; if (value->IsFloat32Array()) { - auto array = value.As(); - auto buf = GetTypedArrayData(array); + auto buf = value.As(); + + auto array = buf->Buffer(); + auto offset = buf->ByteOffset(); + auto size = buf->Length(); + auto data_ptr = (uint8_t*) array->GetBackingStore()->Data() + offset; + auto data = static_cast((void*) data_ptr); + + canvas_native_webgl_vertex_attrib3fv( - index, buf, + index, data, size, ptr->GetState()); } } @@ -4262,10 +4440,17 @@ WebGLRenderingContext::VertexAttrib4fv(const v8::FunctionCallbackInfo auto value = args[1]; if (value->IsFloat32Array()) { - auto array = value.As(); - auto buf = GetTypedArrayData(array); + auto buf = value.As(); + + auto array = buf->Buffer(); + auto offset = buf->ByteOffset(); + auto size = buf->Length(); + auto data_ptr = (uint8_t*) array->GetBackingStore()->Data() + offset; + auto data = static_cast((void*) data_ptr); + + canvas_native_webgl_vertex_attrib4fv( - index, buf, + index, data, size, ptr->GetState()); } } @@ -4446,11 +4631,18 @@ WebGLRenderingContext::Uniform1fv(const v8::FunctionCallbackInfo &arg if (location != nullptr) { if (v0Value->IsFloat32Array()) { - auto array = v0Value.As(); - auto buf = GetTypedArrayData(array); + auto buf = v0Value.As(); + + auto array = buf->Buffer(); + auto offset = buf->ByteOffset(); + auto size = buf->Length(); + auto data_ptr = (uint8_t*) array->GetBackingStore()->Data() + offset; + auto data = static_cast((void*) data_ptr); + + canvas_native_webgl_uniform1fv( location->GetUniformLocation(), - buf, + data, size, ptr->GetState()); } else if (v0Value->IsArray()) { auto array = v0Value.As(); @@ -4471,12 +4663,10 @@ WebGLRenderingContext::Uniform1fv(const v8::FunctionCallbackInfo &arg static_cast(value)); } } - rust::Slice slice( - buf.data(), - buf.size()); + canvas_native_webgl_uniform1fv( location->GetUniformLocation(), - slice, + buf.data(), buf.size(), ptr->GetState()); } } @@ -4503,11 +4693,18 @@ WebGLRenderingContext::Uniform2fv(const v8::FunctionCallbackInfo &arg if (location != nullptr) { if (v0Value->IsFloat32Array()) { - auto array = v0Value.As(); - auto buf = GetTypedArrayData(array); + auto buf = v0Value.As(); + + auto array = buf->Buffer(); + auto offset = buf->ByteOffset(); + auto size = buf->Length(); + auto data_ptr = (uint8_t*) array->GetBackingStore()->Data() + offset; + auto data = static_cast((void*) data_ptr); + + canvas_native_webgl_uniform2fv( location->GetUniformLocation(), - buf, + data, size, ptr->GetState()); } else if (v0Value->IsArray()) { auto array = v0Value.As(); @@ -4528,12 +4725,10 @@ WebGLRenderingContext::Uniform2fv(const v8::FunctionCallbackInfo &arg static_cast(value)); } } - rust::Slice slice( - buf.data(), - buf.size()); + canvas_native_webgl_uniform2fv( location->GetUniformLocation(), - slice, + buf.data(), buf.size(), ptr->GetState()); } } @@ -4560,11 +4755,18 @@ WebGLRenderingContext::Uniform3fv(const v8::FunctionCallbackInfo &arg if (location != nullptr) { if (v0Value->IsFloat32Array()) { - auto array = v0Value.As(); - auto buf = GetTypedArrayData(array); + auto buf = v0Value.As(); + + auto array = buf->Buffer(); + auto offset = buf->ByteOffset(); + auto size = buf->Length(); + auto data_ptr = (uint8_t*) array->GetBackingStore()->Data() + offset; + auto data = static_cast((void*) data_ptr); + + canvas_native_webgl_uniform3fv( location->GetUniformLocation(), - buf, + data, size, ptr->GetState()); } else if (v0Value->IsArray()) { auto array = v0Value.As(); @@ -4585,12 +4787,9 @@ WebGLRenderingContext::Uniform3fv(const v8::FunctionCallbackInfo &arg static_cast(value)); } } - rust::Slice slice( - buf.data(), - buf.size()); canvas_native_webgl_uniform3fv( location->GetUniformLocation(), - slice, + buf.data(), buf.size(), ptr->GetState()); } } @@ -4617,11 +4816,18 @@ WebGLRenderingContext::Uniform4fv(const v8::FunctionCallbackInfo &arg if (location != nullptr) { if (v0Value->IsFloat32Array()) { - auto array = v0Value.As(); - auto buf = GetTypedArrayData(array); + auto buf = v0Value.As(); + + auto array = buf->Buffer(); + auto offset = buf->ByteOffset(); + auto size = buf->Length(); + auto data_ptr = (uint8_t*) array->GetBackingStore()->Data() + offset; + auto data = static_cast((void*) data_ptr); + + canvas_native_webgl_uniform4fv( location->GetUniformLocation(), - buf, + data, size, ptr->GetState()); } else if (v0Value->IsArray()) { auto array = v0Value.As(); @@ -4642,12 +4848,10 @@ WebGLRenderingContext::Uniform4fv(const v8::FunctionCallbackInfo &arg static_cast(value)); } } - rust::Slice slice( - buf.data(), - buf.size()); canvas_native_webgl_uniform4fv( location->GetUniformLocation(), - slice, + buf.data(), + buf.size(), ptr->GetState()); } } @@ -4800,11 +5004,18 @@ WebGLRenderingContext::Uniform1iv(const v8::FunctionCallbackInfo &arg if (location != nullptr) { if (v0Value->IsInt32Array()) { - auto array = v0Value.As(); - auto buf = GetTypedArrayData(array); + auto buf = v0Value.As(); + + auto array = buf->Buffer(); + auto offset = buf->ByteOffset(); + auto size = buf->Length(); + auto data_ptr = (uint8_t*) array->GetBackingStore()->Data() + offset; + auto data = static_cast((void*) data_ptr); + + canvas_native_webgl_uniform1iv( location->GetUniformLocation(), - buf, + data, size, ptr->GetState()); } else if (v0Value->IsArray()) { auto array = v0Value.As(); @@ -4821,12 +5032,10 @@ WebGLRenderingContext::Uniform1iv(const v8::FunctionCallbackInfo &arg buf.push_back( static_cast(value)); } - rust::Slice slice( - buf.data(), - buf.size()); canvas_native_webgl_uniform1iv( location->GetUniformLocation(), - slice, + buf.data(), + buf.size(), ptr->GetState()); } } @@ -4853,11 +5062,17 @@ WebGLRenderingContext::Uniform2iv(const v8::FunctionCallbackInfo &arg if (location != nullptr) { if (v0Value->IsInt32Array()) { - auto array = v0Value.As(); - auto buf = GetTypedArrayData(array); + auto buf = v0Value.As(); + + auto array = buf->Buffer(); + auto offset = buf->ByteOffset(); + auto size = buf->Length(); + auto data_ptr = (uint8_t*) array->GetBackingStore()->Data() + offset; + auto data = static_cast((void*) data_ptr); + canvas_native_webgl_uniform2iv( location->GetUniformLocation(), - buf, + data, size, ptr->GetState()); } else if (v0Value->IsArray()) { auto array = v0Value.As(); @@ -4874,12 +5089,10 @@ WebGLRenderingContext::Uniform2iv(const v8::FunctionCallbackInfo &arg buf.push_back( static_cast(value)); } - rust::Slice slice( - buf.data(), - buf.size()); canvas_native_webgl_uniform2iv( location->GetUniformLocation(), - slice, + buf.data(), + buf.size(), ptr->GetState()); } } @@ -4906,11 +5119,17 @@ WebGLRenderingContext::Uniform3iv(const v8::FunctionCallbackInfo &arg if (location != nullptr) { if (v0Value->IsInt32Array()) { - auto array = v0Value.As(); - auto buf = GetTypedArrayData(array); + auto buf = v0Value.As(); + auto array = buf->Buffer(); + auto offset = buf->ByteOffset(); + auto size = buf->Length(); + auto data_ptr = (uint8_t*) array->GetBackingStore()->Data() + offset; + auto data = static_cast((void*) data_ptr); + + canvas_native_webgl_uniform3iv( location->GetUniformLocation(), - buf, + data, size, ptr->GetState()); } else if (v0Value->IsArray()) { auto array = v0Value.As(); @@ -4927,12 +5146,11 @@ WebGLRenderingContext::Uniform3iv(const v8::FunctionCallbackInfo &arg buf.push_back( static_cast(value)); } - rust::Slice slice( - buf.data(), - buf.size()); + canvas_native_webgl_uniform3iv( location->GetUniformLocation(), - slice, + buf.data(), + buf.size(), ptr->GetState()); } } @@ -4959,11 +5177,17 @@ WebGLRenderingContext::Uniform4iv(const v8::FunctionCallbackInfo &arg if (location != nullptr) { if (v0Value->IsInt32Array()) { - auto array = v0Value.As(); - auto buf = GetTypedArrayData(array); + auto buf = v0Value.As(); + auto array = buf->Buffer(); + auto offset = buf->ByteOffset(); + auto size = buf->Length(); + auto data_ptr = (uint8_t*) array->GetBackingStore()->Data() + offset; + auto data = static_cast((void*) data_ptr); + + canvas_native_webgl_uniform4iv( location->GetUniformLocation(), - buf, + data, size, ptr->GetState()); } else if (v0Value->IsArray()) { auto array = v0Value.As(); @@ -4980,12 +5204,10 @@ WebGLRenderingContext::Uniform4iv(const v8::FunctionCallbackInfo &arg buf.push_back( static_cast(value)); } - rust::Slice slice( - buf.data(), - buf.size()); canvas_native_webgl_uniform4iv( location->GetUniformLocation(), - slice, + buf.data(), + buf.size(), ptr->GetState()); } } @@ -5012,11 +5234,16 @@ WebGLRenderingContext::UniformMatrix2fv(const v8::FunctionCallbackInfoIsFloat32Array()) { - auto array = value.As(); - auto buf = GetTypedArrayData(array); + auto buf = value.As(); + auto array = buf->Buffer(); + auto offset = buf->ByteOffset(); + auto size = buf->Length(); + auto data_ptr = (uint8_t*) array->GetBackingStore()->Data() + offset; + auto data = static_cast((void*) data_ptr); + canvas_native_webgl_uniform_matrix2fv( location->GetUniformLocation(), - transpose, buf, + transpose, data, size, ptr->GetState()); } else if (value->IsArray()) { auto array = value.As(); @@ -5038,12 +5265,10 @@ WebGLRenderingContext::UniformMatrix2fv(const v8::FunctionCallbackInfo slice( - buf.data(), - buf.size()); canvas_native_webgl_uniform_matrix2fv( location->GetUniformLocation(), - transpose, slice, + transpose, buf.data(), + buf.size(), ptr->GetState()); } } @@ -5070,11 +5295,17 @@ WebGLRenderingContext::UniformMatrix3fv(const v8::FunctionCallbackInfoIsFloat32Array()) { - auto array = value.As(); - auto buf = GetTypedArrayData(array); + auto buf = value.As(); + + auto array = buf->Buffer(); + auto offset = buf->ByteOffset(); + auto size = buf->Length(); + auto data_ptr = (uint8_t*) array->GetBackingStore()->Data() + offset; + auto data = static_cast((void*) data_ptr); + canvas_native_webgl_uniform_matrix3fv( location->GetUniformLocation(), - transpose, buf, + transpose, data, size, ptr->GetState()); } else if (value->IsArray()) { auto array = value.As(); @@ -5096,12 +5327,11 @@ WebGLRenderingContext::UniformMatrix3fv(const v8::FunctionCallbackInfo slice( - buf.data(), - buf.size()); + canvas_native_webgl_uniform_matrix3fv( location->GetUniformLocation(), - transpose, slice, + transpose, buf.data(), + buf.size(), ptr->GetState()); } } @@ -5128,11 +5358,18 @@ WebGLRenderingContext::UniformMatrix4fv(const v8::FunctionCallbackInfoIsFloat32Array()) { - auto array = value.As(); - auto buf = GetTypedArrayData(array); + auto buf = value.As(); + + auto array = buf->Buffer(); + auto offset = buf->ByteOffset(); + auto size = buf->Length(); + auto data_ptr = (uint8_t*) array->GetBackingStore()->Data() + offset; + auto data = static_cast((void*) data_ptr); + + canvas_native_webgl_uniform_matrix4fv( location->GetUniformLocation(), - transpose, buf, + transpose, data, size, ptr->GetState()); } else if (value->IsArray()) { auto array = value.As(); @@ -5154,12 +5391,11 @@ WebGLRenderingContext::UniformMatrix4fv(const v8::FunctionCallbackInfo slice( - buf.data(), - buf.size()); + canvas_native_webgl_uniform_matrix4fv( location->GetUniformLocation(), - transpose, slice, + transpose, buf.data(), + buf.size(), ptr->GetState()); } } @@ -5174,7 +5410,6 @@ WebGLRenderingContext::UseProgram(const v8::FunctionCallbackInfo &arg } auto isolate = args.GetIsolate(); - auto context = isolate->GetCurrentContext(); if (args.Length() > 0) { auto value = args[0]; @@ -5207,7 +5442,6 @@ WebGLRenderingContext::ValidateProgram(const v8::FunctionCallbackInfo } auto isolate = args.GetIsolate(); - auto context = isolate->GetCurrentContext(); auto value = args[0]; auto type = GetNativeType(isolate, value); @@ -5276,9 +5510,9 @@ WebGLRenderingContext::__ToDataURL(const v8::FunctionCallbackInfo &ar auto data = canvas_native_webgl_to_data_url( ptr->GetState(), - rust::Str(type.c_str()), + type.c_str(), quality); - args.GetReturnValue().Set(ConvertToV8OneByteString(isolate, std::move(data))); + args.GetReturnValue().Set(ConvertToV8OneByteString(isolate, (char*) data)); } diff --git a/packages/canvas/platforms/ios/src/cpp/webgl2/WebGL2RenderingContext.cpp b/packages/canvas/platforms/ios/src/cpp/webgl2/WebGL2RenderingContext.cpp index 5daf78db..8853ae0a 100644 --- a/packages/canvas/platforms/ios/src/cpp/webgl2/WebGL2RenderingContext.cpp +++ b/packages/canvas/platforms/ios/src/cpp/webgl2/WebGL2RenderingContext.cpp @@ -560,7 +560,8 @@ WebGL2RenderingContext::CompressedTexSubImage3D(const v8::FunctionCallbackInfoGetState() @@ -1437,22 +1438,9 @@ void WebGL2RenderingContext::GetInternalformatParameter( case GL_RGBA32UI: case GL_RGBA32I: { // empty - - auto value = std::vector(); - auto buf = new VecMutableBuffer( - std::move(value)); - - auto store = v8::ArrayBuffer::NewBackingStore(buf->data(), buf->size(), - [](void *data, size_t length, - void *deleter_data) { - if (deleter_data != nullptr) { - delete (VecMutableBuffer *) deleter_data; - } - }, - buf); - - auto arraybuffer = v8::ArrayBuffer::New(isolate, std::move(store)); - args.GetReturnValue().Set(v8::Int32Array::New(arraybuffer, 0, buf->buffer_size())); + auto arraybuffer = v8::ArrayBuffer::New(isolate, 0); + + args.GetReturnValue().Set(v8::Int32Array::New(arraybuffer, 0, 0)); return; } case GL_R8: @@ -1495,20 +1483,21 @@ void WebGL2RenderingContext::GetInternalformatParameter( if (pname == GL_SAMPLES) { auto value = canvas_native_webgl_result_get_i32_array(ret); - auto buf = new VecMutableBuffer( - std::move(value)); + auto buf = (uint8_t*)canvas_native_i32_buffer_get_bytes(value); + auto size = canvas_native_i32_buffer_get_length(value); + auto bytes_size = size * sizeof(int32_t); - auto store = v8::ArrayBuffer::NewBackingStore(buf->data(), buf->size(), + auto store = v8::ArrayBuffer::NewBackingStore(buf, bytes_size, [](void *data, size_t length, void *deleter_data) { if (deleter_data != nullptr) { - delete (VecMutableBuffer *) deleter_data; + canvas_native_i32_buffer_destroy((I32Buffer *) deleter_data); } }, - buf); + value); auto arraybuffer = v8::ArrayBuffer::New(isolate, std::move(store)); - args.GetReturnValue().Set(v8::Int32Array::New(arraybuffer, 0, buf->buffer_size())); + args.GetReturnValue().Set(v8::Int32Array::New(arraybuffer, 0, size)); canvas_native_webgl_WebGLResult_destroy(ret); return; } else { @@ -1584,14 +1573,19 @@ void WebGL2RenderingContext::GetQueryParameter(const v8::FunctionCallbackInfoGetState()); if (pname == GL_QUERY_RESULT) { args.GetReturnValue().Set(canvas_native_webgl_result_get_bool( - *ret)); + ret)); + canvas_native_webgl_WebGLResult_destroy(ret); return; } else if (pname == GL_QUERY_RESULT_AVAILABLE) { args.GetReturnValue().Set((int32_t) canvas_native_webgl_result_get_u32( - *ret)); + ret)); + canvas_native_webgl_WebGLResult_destroy(ret); return; } + //clean up + canvas_native_webgl_WebGLResult_destroy(ret); + } } @@ -1619,9 +1613,12 @@ void WebGL2RenderingContext::GetQuery(const v8::FunctionCallbackInfo ptr->GetState()); if (pname == GL_CURRENT_QUERY) { args.GetReturnValue().Set(canvas_native_webgl_result_get_i32( - *ret)); + ret)); + canvas_native_webgl_WebGLResult_destroy(ret); return; } + // clean up + canvas_native_webgl_WebGLResult_destroy(ret); } args.GetReturnValue().SetNull(); @@ -1654,7 +1651,8 @@ void WebGL2RenderingContext::GetSamplerParameter(const v8::FunctionCallbackInfo< case GL_TEXTURE_MIN_LOD: args.GetReturnValue().Set( static_cast(canvas_native_webgl_result_get_f32( - *ret))); + ret))); + canvas_native_webgl_WebGLResult_destroy(ret); return; case GL_TEXTURE_COMPARE_FUNC: case GL_TEXTURE_COMPARE_MODE: @@ -1664,10 +1662,12 @@ void WebGL2RenderingContext::GetSamplerParameter(const v8::FunctionCallbackInfo< case GL_TEXTURE_WRAP_S: case GL_TEXTURE_WRAP_T: args.GetReturnValue().Set(canvas_native_webgl_result_get_i32( - *ret)); + ret)); + canvas_native_webgl_WebGLResult_destroy(ret); return; default: args.GetReturnValue().SetNull(); + canvas_native_webgl_WebGLResult_destroy(ret); return; } } @@ -1704,10 +1704,13 @@ void WebGL2RenderingContext::GetSyncParameter(const v8::FunctionCallbackInfoGetProgram(), - rust::Str(index.c_str()), + index.c_str(), ptr->GetState()); args.GetReturnValue().Set((int) ret); return; @@ -1808,27 +1811,36 @@ void WebGL2RenderingContext::GetUniformIndices(const v8::FunctionCallbackInfoIsArray()) { auto uniformNames = uniformNamesObject.As(); auto len = uniformNames->Length(); - std::vector store; + + std::vector store; store.reserve(len); + for (int j = 0; j < len; ++j) { auto name = ConvertFromV8String(isolate, uniformNames->Get( context, j).ToLocalChecked()); - rust::Str val(name.data(), - name.size()); - store.push_back(val); + + store.push_back(name); } - rust::Slice slice( - store.data(), - store.size()); + + + const char* cStrings[store.size()]; + for (size_t i = 0; i < store.size(); ++i) { + cStrings[i] = store[i].c_str(); + } + + auto ret = canvas_native_webgl2_get_uniform_indices( program->GetProgram(), - slice, + cStrings, + store.size(), ptr->GetState()); + - auto retSize = ret.size(); + auto retSize = canvas_native_u32_buffer_get_length(ret); + auto buf = canvas_native_u32_buffer_get_bytes(ret); auto result = v8::Array::New(isolate, (int) retSize); for (int j = 0; j < retSize; ++j) { - auto item = ret[j]; + auto item = buf[j]; result->Set(context, j, v8::Number::New(isolate, @@ -1836,6 +1848,7 @@ void WebGL2RenderingContext::GetUniformIndices(const v8::FunctionCallbackInfo slice( - buf.data(), buf.size()); canvas_native_webgl2_invalidate_framebuffer( - target, slice, + target, buf.data(), buf.size(), ptr->GetState()); } } @@ -1903,16 +1914,14 @@ WebGL2RenderingContext::InvalidateSubFramebuffer(const v8::FunctionCallbackInfo< std::vector buf; buf.reserve(len); for (int j = 0; j < len; ++j) { - auto item = (uint) array->Get( + auto item = (uint32_t) array->Get( context, j).ToLocalChecked()->NumberValue(context).ToChecked(); buf.push_back(item); } - rust::Slice slice( - buf.data(), buf.size()); - + canvas_native_webgl2_invalidate_sub_framebuffer( target, - slice, + buf.data(), buf.size(), x, y, width, @@ -2229,9 +2238,14 @@ void WebGL2RenderingContext::TexImage3D(const v8::FunctionCallbackInfoIsTypedArray()) { auto buf = imageOrPixelsOrOffset.As(); - auto slice = GetTypedArrayData(buf); - - + + auto array = buf->Buffer(); + auto offset = buf->ByteOffset(); + auto size = buf->Length(); + auto data_ptr = (uint8_t*) array->GetBackingStore()->Data() + offset; + auto data = static_cast((void*) data_ptr); + + canvas_native_webgl2_tex_image3d( target, level, @@ -2242,7 +2256,8 @@ void WebGL2RenderingContext::TexImage3D(const v8::FunctionCallbackInfoGetState() ); return; @@ -2329,9 +2344,13 @@ void WebGL2RenderingContext::TexImage3D(const v8::FunctionCallbackInfoIsTypedArray()) { auto buf = imageOrPixelsOrOffset.As(); + + auto array = buf->Buffer(); + auto offset = buf->ByteOffset(); auto size = buf->Length(); - auto array = GetTypedArrayData(buf); - + auto data_ptr = (uint8_t*) array->GetBackingStore()->Data() + offset; + auto data = static_cast((void*) data_ptr); + srcOffsetValue = srcOffsetValue * size; if (srcOffsetValue > @@ -2349,7 +2368,7 @@ void WebGL2RenderingContext::TexImage3D(const v8::FunctionCallbackInfoGetState() ); @@ -2479,9 +2498,16 @@ void WebGL2RenderingContext::TexSubImage3D(const v8::FunctionCallbackInfoIsTypedArray()) { - auto array = imageOrPixelsOrOffsetObject.As(); - auto slice = GetTypedArrayData(array); - + auto buf = imageOrPixelsOrOffsetObject.As(); + + auto array = buf->Buffer(); + auto offset = buf->ByteOffset(); + auto size = buf->Length(); + auto data_ptr = (uint8_t*) array->GetBackingStore()->Data() + offset; + auto data = static_cast((void*) data_ptr); + + + canvas_native_webgl2_tex_sub_image3d( target, level, @@ -2493,7 +2519,7 @@ void WebGL2RenderingContext::TexSubImage3D(const v8::FunctionCallbackInfoGetState() ); @@ -2557,18 +2583,21 @@ void WebGL2RenderingContext::TexSubImage3D(const v8::FunctionCallbackInfoIsTypedArray()) { - auto array = imageOrPixelsOrOffsetObject.As(); - auto buf = GetTypedArrayData(array); - auto size = array->Length(); + auto buf = imageOrPixelsOrOffsetObject.As(); + + auto array = buf->Buffer(); + auto offset = buf->ByteOffset(); + auto size = buf->Length(); + auto data_ptr = (uint8_t*) array->GetBackingStore()->Data() + offset; + auto data = static_cast((void*) data_ptr); + + srcOffsetValue = srcOffsetValue * size; if (srcOffsetValue > size) { return; } - rust::Slice slice( - buf.data(), - buf.size()); canvas_native_webgl2_tex_sub_image3d_offset( target, @@ -2581,7 +2610,7 @@ void WebGL2RenderingContext::TexSubImage3D(const v8::FunctionCallbackInfoGetState() ); @@ -2611,22 +2640,27 @@ WebGL2RenderingContext::TransformFeedbackVaryings(const v8::FunctionCallbackInfo varyingsObject->IsArray()) { auto varyings = varyingsObject.As(); auto len = varyings->Length(); - std::vector buf; - buf.reserve(len); + + + std::vector store; + store.reserve(len); + for (int j = 0; j < len; ++j) { auto name = ConvertFromV8String(isolate, varyings->Get( context, j).ToLocalChecked()); - rust::Str val(name.data(), - name.size()); - buf.emplace_back(val); + + store.push_back(name); } - - rust::Slice slice( - buf.data(), buf.size()); - + + + const char* cStrings[store.size()]; + for (size_t i = 0; i < store.size(); ++i) { + cStrings[i] = store[i].c_str(); + } + canvas_native_webgl2_transform_feedback_varyings( program->GetProgram(), - slice, + cStrings, store.size(), bufferMode, ptr->GetState() ); @@ -2798,11 +2832,17 @@ void WebGL2RenderingContext::Uniform1uiv(const v8::FunctionCallbackInfoIsUint32Array()) { - auto array = data.As(); - auto slice = GetTypedArrayData(array); + auto buf = data.As(); + auto array = buf->Buffer(); + auto offset = buf->ByteOffset(); + auto size = buf->Length(); + auto data_ptr = (uint8_t*) array->GetBackingStore()->Data() + offset; + auto data = static_cast((void*) data_ptr); + + canvas_native_webgl2_uniform1uiv( location->GetUniformLocation(), - slice, + data, size, ptr->GetState() ); } else { @@ -2817,11 +2857,10 @@ void WebGL2RenderingContext::Uniform1uiv(const v8::FunctionCallbackInfo slice( - buf.data(), buf.size()); + canvas_native_webgl2_uniform1uiv( location->GetUniformLocation(), - slice, + buf.data(), buf.size(), ptr->GetState() ); } @@ -2851,11 +2890,18 @@ void WebGL2RenderingContext::Uniform2uiv(const v8::FunctionCallbackInfoIsUint32Array()) { - auto array = data.As(); - auto slice = GetTypedArrayData(array); + auto buf = data.As(); + auto array = buf->Buffer(); + auto offset = buf->ByteOffset(); + auto size = buf->Length(); + auto data_ptr = (uint8_t*) array->GetBackingStore()->Data() + offset; + auto data = static_cast((void*) data_ptr); + + + canvas_native_webgl2_uniform2uiv( location->GetUniformLocation(), - slice, + data, size, ptr->GetState() ); } else { @@ -2870,11 +2916,9 @@ void WebGL2RenderingContext::Uniform2uiv(const v8::FunctionCallbackInfo slice( - buf.data(), buf.size()); canvas_native_webgl2_uniform2uiv( location->GetUniformLocation(), - slice, + buf.data(), buf.size(), ptr->GetState() ); } @@ -2904,11 +2948,18 @@ void WebGL2RenderingContext::Uniform3uiv(const v8::FunctionCallbackInfoIsUint32Array()) { - auto array = data.As(); - auto slice = GetTypedArrayData(array); + auto buf = data.As(); + + auto array = buf->Buffer(); + auto offset = buf->ByteOffset(); + auto size = buf->Length(); + auto data_ptr = (uint8_t*) array->GetBackingStore()->Data() + offset; + auto data = static_cast((void*) data_ptr); + + canvas_native_webgl2_uniform3uiv( location->GetUniformLocation(), - slice, + data, size, ptr->GetState() ); } else { @@ -2923,11 +2974,9 @@ void WebGL2RenderingContext::Uniform3uiv(const v8::FunctionCallbackInfo slice( - buf.data(), buf.size()); canvas_native_webgl2_uniform3uiv( location->GetUniformLocation(), - slice, + buf.data(), buf.size(), ptr->GetState() ); } @@ -2957,11 +3006,18 @@ void WebGL2RenderingContext::Uniform4uiv(const v8::FunctionCallbackInfoIsUint32Array()) { - auto array = data.As(); - auto slice = GetTypedArrayData(array); + auto buf = data.As(); + + auto array = buf->Buffer(); + auto offset = buf->ByteOffset(); + auto size = buf->Length(); + auto data_ptr = (uint8_t*) array->GetBackingStore()->Data() + offset; + auto data = static_cast((void*) data_ptr); + + canvas_native_webgl2_uniform4uiv( location->GetUniformLocation(), - slice, + data, size, ptr->GetState() ); } else { @@ -2976,11 +3032,10 @@ void WebGL2RenderingContext::Uniform4uiv(const v8::FunctionCallbackInfo slice( - buf.data(), buf.size()); + canvas_native_webgl2_uniform4uiv( location->GetUniformLocation(), - slice, + buf.data(), buf.size(), ptr->GetState() ); } @@ -3042,12 +3097,18 @@ void WebGL2RenderingContext::UniformMatrix2x3fv(const v8::FunctionCallbackInfoIsFloat32Array()) { - auto array = data.As(); - auto slice = GetTypedArrayData(array); + auto buf = data.As(); + auto array = buf->Buffer(); + auto offset = buf->ByteOffset(); + auto size = buf->Length(); + auto data_ptr = (uint8_t*) array->GetBackingStore()->Data() + offset; + auto data = static_cast((void*) data_ptr); + + canvas_native_webgl2_uniform_matrix2x3fv( location->GetUniformLocation(), transpose, - slice, + data, size, ptr->GetState() ); } else if (data->IsArray()) { @@ -3067,13 +3128,11 @@ void WebGL2RenderingContext::UniformMatrix2x3fv(const v8::FunctionCallbackInfo slice( - buf.data(), buf.size()); - + canvas_native_webgl2_uniform_matrix2x3fv( location->GetUniformLocation(), transpose, - slice, + buf.data(), buf.size(), ptr->GetState() ); } @@ -3103,12 +3162,19 @@ void WebGL2RenderingContext::UniformMatrix2x4fv(const v8::FunctionCallbackInfoIsFloat32Array()) { - auto array = data.As(); - auto slice = GetTypedArrayData(array); + auto buf = data.As(); + + auto array = buf->Buffer(); + auto offset = buf->ByteOffset(); + auto size = buf->Length(); + auto data_ptr = (uint8_t*) array->GetBackingStore()->Data() + offset; + auto data = static_cast((void*) data_ptr); + + canvas_native_webgl2_uniform_matrix2x4fv( location->GetUniformLocation(), transpose, - slice, + data, size, ptr->GetState() ); } else if (data->IsArray()) { @@ -3128,13 +3194,12 @@ void WebGL2RenderingContext::UniformMatrix2x4fv(const v8::FunctionCallbackInfo slice( - buf.data(), buf.size()); + canvas_native_webgl2_uniform_matrix2x4fv( location->GetUniformLocation(), transpose, - slice, + buf.data(), buf.size(), ptr->GetState() ); } @@ -3164,12 +3229,20 @@ void WebGL2RenderingContext::UniformMatrix3x2fv(const v8::FunctionCallbackInfoIsFloat32Array()) { - auto array = data.As(); - auto slice = GetTypedArrayData(array); + auto buf = data.As(); + + + auto array = buf->Buffer(); + auto offset = buf->ByteOffset(); + auto size = buf->Length(); + auto data_ptr = (uint8_t*) array->GetBackingStore()->Data() + offset; + auto data = static_cast((void*) data_ptr); + + canvas_native_webgl2_uniform_matrix3x2fv( location->GetUniformLocation(), transpose, - slice, + data, size, ptr->GetState() ); } else if (data->IsArray()) { @@ -3189,13 +3262,12 @@ void WebGL2RenderingContext::UniformMatrix3x2fv(const v8::FunctionCallbackInfo slice( - buf.data(), buf.size()); + canvas_native_webgl2_uniform_matrix3x2fv( location->GetUniformLocation(), transpose, - slice, + buf.data(), buf.size(), ptr->GetState() ); } @@ -3225,12 +3297,18 @@ void WebGL2RenderingContext::UniformMatrix3x4fv(const v8::FunctionCallbackInfoIsFloat32Array()) { - auto array = data.As(); - auto slice = GetTypedArrayData(array); + auto buf = data.As(); + auto array = buf->Buffer(); + auto offset = buf->ByteOffset(); + auto size = buf->Length(); + auto data_ptr = (uint8_t*) array->GetBackingStore()->Data() + offset; + auto data = static_cast((void*) data_ptr); + + canvas_native_webgl2_uniform_matrix3x4fv( location->GetUniformLocation(), transpose, - slice, + data, size, ptr->GetState() ); } else if (data->IsArray()) { @@ -3250,13 +3328,12 @@ void WebGL2RenderingContext::UniformMatrix3x4fv(const v8::FunctionCallbackInfo slice( - buf.data(), buf.size()); + canvas_native_webgl2_uniform_matrix3x4fv( location->GetUniformLocation(), transpose, - slice, + buf.data(), buf.size(), ptr->GetState() ); } @@ -3286,12 +3363,18 @@ void WebGL2RenderingContext::UniformMatrix4x2fv(const v8::FunctionCallbackInfoIsFloat32Array()) { - auto array = data.As(); - auto slice = GetTypedArrayData(array); + auto buf = data.As(); + + auto array = buf->Buffer(); + auto offset = buf->ByteOffset(); + auto size = buf->Length(); + auto data_ptr = (uint8_t*) array->GetBackingStore()->Data() + offset; + auto data = static_cast((void*) data_ptr); + canvas_native_webgl2_uniform_matrix4x2fv( location->GetUniformLocation(), transpose, - slice, + data, size, ptr->GetState() ); } else if (data->IsArray()) { @@ -3311,13 +3394,12 @@ void WebGL2RenderingContext::UniformMatrix4x2fv(const v8::FunctionCallbackInfo slice( - buf.data(), buf.size()); + canvas_native_webgl2_uniform_matrix4x2fv( location->GetUniformLocation(), transpose, - slice, + buf.data(), buf.size(), ptr->GetState() ); } @@ -3347,12 +3429,17 @@ void WebGL2RenderingContext::UniformMatrix4x3fv(const v8::FunctionCallbackInfoIsFloat32Array()) { - auto array = data.As(); - auto slice = GetTypedArrayData(array); + auto buf = data.As(); + auto array = buf->Buffer(); + auto offset = buf->ByteOffset(); + auto size = buf->Length(); + auto data_ptr = (uint8_t*) array->GetBackingStore()->Data() + offset; + auto data = static_cast((void*) data_ptr); + canvas_native_webgl2_uniform_matrix4x3fv( location->GetUniformLocation(), transpose, - slice, + data, size, ptr->GetState() ); } else if (data->IsArray()) { @@ -3372,13 +3459,11 @@ void WebGL2RenderingContext::UniformMatrix4x3fv(const v8::FunctionCallbackInfo slice( - buf.data(), buf.size()); - + canvas_native_webgl2_uniform_matrix4x3fv( location->GetUniformLocation(), transpose, - slice, + buf.data(), buf.size(), ptr->GetState() ); } @@ -3461,11 +3546,18 @@ void WebGL2RenderingContext::VertexAttribI4iv(const v8::FunctionCallbackInfoIsInt32Array()) { - auto array = value.As(); - auto slice = GetTypedArrayData(array); + auto buf = value.As(); + + auto array = buf->Buffer(); + auto offset = buf->ByteOffset(); + auto size = buf->Length(); + auto data_ptr = (uint8_t*) array->GetBackingStore()->Data() + offset; + auto data = static_cast((void*) data_ptr); + + canvas_native_webgl2_vertex_attrib_i4iv( index, - slice, + data, size, ptr->GetState() ); } else if (value->IsArray()) { @@ -3481,12 +3573,10 @@ void WebGL2RenderingContext::VertexAttribI4iv(const v8::FunctionCallbackInfo slice( - buf.data(), buf.size()); - + canvas_native_webgl2_vertex_attrib_i4iv( index, - slice, + buf.data(), buf.size(), ptr->GetState() ); } @@ -3544,11 +3634,17 @@ void WebGL2RenderingContext::VertexAttribI4uiv(const v8::FunctionCallbackInfoIsUint32Array()) { - auto array = value.As(); - auto slice = GetTypedArrayData(array); + auto buf = value.As(); + auto array = buf->Buffer(); + auto offset = buf->ByteOffset(); + auto size = buf->Length(); + auto data_ptr = (uint8_t*) array->GetBackingStore()->Data() + offset; + auto data = static_cast((void*) data_ptr); + + canvas_native_webgl2_vertex_attrib_i4uiv( index, - slice, + data, size, ptr->GetState() ); } else if (value->IsArray()) { diff --git a/packages/canvas/src-native/canvas-ios/CanvasNative.xcodeproj/project.pbxproj b/packages/canvas/src-native/canvas-ios/CanvasNative.xcodeproj/project.pbxproj index 36c445aa..cbe28c67 100644 --- a/packages/canvas/src-native/canvas-ios/CanvasNative.xcodeproj/project.pbxproj +++ b/packages/canvas/src-native/canvas-ios/CanvasNative.xcodeproj/project.pbxproj @@ -533,6 +533,7 @@ "IPHONEOS_DEPLOYMENT_TARGET[sdk=iphonesimulator*][arch=arm64]" = 11.0; "IPHONEOS_DEPLOYMENT_TARGET[sdk=iphonesimulator*][arch=x86_64]" = 11.0; "IPHONEOS_DEPLOYMENT_TARGET[sdk=macosx*]" = 14.2; + KEEP_PRIVATE_EXTERNS = NO; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", @@ -575,6 +576,8 @@ OTHER_SWIFT_FLAGS = "-Xcc -Wno-error=non-modular-include-in-framework-module"; PRODUCT_BUNDLE_IDENTIFIER = com.github.triniwiz.CanvasNative; PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; + REEXPORTED_LIBRARY_NAMES = ""; + SEPARATE_SYMBOL_EDIT = NO; SKIP_INSTALL = YES; STRIP_INSTALLED_PRODUCT = YES; STRIP_SWIFT_SYMBOLS = YES; @@ -616,6 +619,7 @@ "IPHONEOS_DEPLOYMENT_TARGET[sdk=iphonesimulator*][arch=arm64]" = 11.0; "IPHONEOS_DEPLOYMENT_TARGET[sdk=iphonesimulator*][arch=x86_64]" = 11.0; "IPHONEOS_DEPLOYMENT_TARGET[sdk=macosx*]" = 14.2; + KEEP_PRIVATE_EXTERNS = NO; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", @@ -657,6 +661,8 @@ OTHER_SWIFT_FLAGS = "-Xcc -Wno-error=non-modular-include-in-framework-module"; PRODUCT_BUNDLE_IDENTIFIER = com.github.triniwiz.CanvasNative; PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; + REEXPORTED_LIBRARY_NAMES = ""; + SEPARATE_SYMBOL_EDIT = NO; SKIP_INSTALL = YES; STRIP_INSTALLED_PRODUCT = YES; STRIP_SWIFT_SYMBOLS = YES; diff --git a/packages/canvas/src-native/canvas-ios/CanvasNative.xcodeproj/project.xcworkspace/xcuserdata/triniwiz.xcuserdatad/UserInterfaceState.xcuserstate b/packages/canvas/src-native/canvas-ios/CanvasNative.xcodeproj/project.xcworkspace/xcuserdata/triniwiz.xcuserdatad/UserInterfaceState.xcuserstate index a40b2512..30600960 100644 Binary files a/packages/canvas/src-native/canvas-ios/CanvasNative.xcodeproj/project.xcworkspace/xcuserdata/triniwiz.xcuserdatad/UserInterfaceState.xcuserstate and b/packages/canvas/src-native/canvas-ios/CanvasNative.xcodeproj/project.xcworkspace/xcuserdata/triniwiz.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/packages/canvas/src-native/canvas-ios/CanvasNative/CanvasNative.h b/packages/canvas/src-native/canvas-ios/CanvasNative/CanvasNative.h index 510776d3..178b9692 100644 --- a/packages/canvas/src-native/canvas-ios/CanvasNative/CanvasNative.h +++ b/packages/canvas/src-native/canvas-ios/CanvasNative/CanvasNative.h @@ -4,13 +4,18 @@ // // Created by Osei Fortune on 30/09/2020. // -#import "canvas_native.h" -#import "canvas_ios.h" -#ifdef __OBJC__ +#ifdef __cplusplus +extern "C" { +#endif + #import +#import "canvas_native.h" +#import "canvas_ios.h" + //! Project version number for CanvasNative. + FOUNDATION_EXPORT double CanvasNativeVersionNumber; //! Project version string for CanvasNative. @@ -18,4 +23,7 @@ FOUNDATION_EXPORT const unsigned char CanvasNativeVersionString[]; // In this header, you should import all the public headers of your framework using statements like #import +#ifdef __cplusplus +} #endif + diff --git a/packages/canvas/src-native/canvas-ios/CanvasNative/include/canvas_native.h b/packages/canvas/src-native/canvas-ios/CanvasNative/include/canvas_native.h index cc45f904..9b65c215 100644 --- a/packages/canvas/src-native/canvas-ios/CanvasNative/include/canvas_native.h +++ b/packages/canvas/src-native/canvas-ios/CanvasNative/include/canvas_native.h @@ -1056,7 +1056,7 @@ struct ImageData *canvas_native_image_data_get_shared_instance(struct ImageData struct ImageAsset *canvas_native_image_asset_create(void); -struct ImageAsset *canvas_native_image_asset_shared_clone(const struct ImageAsset *asset); +struct ImageAsset *canvas_native_image_asset_shared_clone(struct ImageAsset *asset); bool canvas_native_image_asset_load_from_fd(struct ImageAsset *asset, int fd); @@ -1633,8 +1633,8 @@ struct ContextAttributes *canvas_native_webgl_get_context_attributes(struct WebG uint32_t canvas_native_webgl_get_error(struct WebGLState *state); -const struct WebGLExtension *canvas_native_webgl_get_extension(const char *name, - struct WebGLState *state); +struct WebGLExtension *canvas_native_webgl_get_extension(const char *name, + struct WebGLState *state); struct WebGLFramebufferAttachmentParameter *canvas_native_webgl_get_framebuffer_attachment_parameter(uint32_t target, uint32_t attachment, @@ -1804,6 +1804,22 @@ void canvas_native_webgl_tex_image2d_image_none(int32_t target, int32_t image_type, struct WebGLState *state); +void canvas_native_webgl_tex_image2d_canvas2d(int32_t target, + int32_t level, + int32_t internalformat, + int32_t format, + int32_t image_type, + struct CanvasRenderingContext2D *canvas, + struct WebGLState *state); + +void canvas_native_webgl_tex_image2d_webgl(int32_t target, + int32_t level, + int32_t _internalformat, + int32_t _format, + int32_t _image_type, + struct WebGLState *webgl, + struct WebGLState *state); + void canvas_native_webgl_tex_image2d(int32_t target, int32_t level, int32_t internalformat, @@ -1826,6 +1842,14 @@ void canvas_native_webgl_tex_image2d_none(int32_t target, int32_t image_type, struct WebGLState *state); +void canvas_native_webgl_tex_image2d_image_asset(int32_t target, + int32_t level, + int32_t internalformat, + int32_t format, + int32_t image_type, + struct ImageAsset *image_asset, + struct WebGLState *state); + void canvas_native_webgl_tex_parameterf(uint32_t target, uint32_t pname, float param, @@ -2667,4 +2691,10 @@ uintptr_t canvas_native_f32_buffer_mut_get_length(const struct F32Buffer *buffer uintptr_t canvas_native_f32_buffer_get_length(const struct F32Buffer *buffer); +uintptr_t canvas_native_string_buffer_get_length(const struct StringBuffer *buffer); + +char *canvas_native_string_buffer_get_value_at(const struct StringBuffer *buffer, uintptr_t index); + +void canvas_native_string_buffer_destroy(struct StringBuffer *buffer); + #endif /* CANVAS_C_H */ diff --git a/packages/canvas/src-native/canvas-ios/dist/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/CanvasNative b/packages/canvas/src-native/canvas-ios/dist/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/CanvasNative index 3ff7a594..a8c41e15 100755 Binary files a/packages/canvas/src-native/canvas-ios/dist/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/CanvasNative and b/packages/canvas/src-native/canvas-ios/dist/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/CanvasNative differ diff --git a/packages/canvas/src-native/canvas-ios/dist/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Headers/CanvasNative.h b/packages/canvas/src-native/canvas-ios/dist/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Headers/CanvasNative.h index 510776d3..178b9692 100644 --- a/packages/canvas/src-native/canvas-ios/dist/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Headers/CanvasNative.h +++ b/packages/canvas/src-native/canvas-ios/dist/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Headers/CanvasNative.h @@ -4,13 +4,18 @@ // // Created by Osei Fortune on 30/09/2020. // -#import "canvas_native.h" -#import "canvas_ios.h" -#ifdef __OBJC__ +#ifdef __cplusplus +extern "C" { +#endif + #import +#import "canvas_native.h" +#import "canvas_ios.h" + //! Project version number for CanvasNative. + FOUNDATION_EXPORT double CanvasNativeVersionNumber; //! Project version string for CanvasNative. @@ -18,4 +23,7 @@ FOUNDATION_EXPORT const unsigned char CanvasNativeVersionString[]; // In this header, you should import all the public headers of your framework using statements like #import +#ifdef __cplusplus +} #endif + diff --git a/packages/canvas/src-native/canvas-ios/dist/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Headers/canvas_native.h b/packages/canvas/src-native/canvas-ios/dist/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Headers/canvas_native.h index cc45f904..9b65c215 100644 --- a/packages/canvas/src-native/canvas-ios/dist/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Headers/canvas_native.h +++ b/packages/canvas/src-native/canvas-ios/dist/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Headers/canvas_native.h @@ -1056,7 +1056,7 @@ struct ImageData *canvas_native_image_data_get_shared_instance(struct ImageData struct ImageAsset *canvas_native_image_asset_create(void); -struct ImageAsset *canvas_native_image_asset_shared_clone(const struct ImageAsset *asset); +struct ImageAsset *canvas_native_image_asset_shared_clone(struct ImageAsset *asset); bool canvas_native_image_asset_load_from_fd(struct ImageAsset *asset, int fd); @@ -1633,8 +1633,8 @@ struct ContextAttributes *canvas_native_webgl_get_context_attributes(struct WebG uint32_t canvas_native_webgl_get_error(struct WebGLState *state); -const struct WebGLExtension *canvas_native_webgl_get_extension(const char *name, - struct WebGLState *state); +struct WebGLExtension *canvas_native_webgl_get_extension(const char *name, + struct WebGLState *state); struct WebGLFramebufferAttachmentParameter *canvas_native_webgl_get_framebuffer_attachment_parameter(uint32_t target, uint32_t attachment, @@ -1804,6 +1804,22 @@ void canvas_native_webgl_tex_image2d_image_none(int32_t target, int32_t image_type, struct WebGLState *state); +void canvas_native_webgl_tex_image2d_canvas2d(int32_t target, + int32_t level, + int32_t internalformat, + int32_t format, + int32_t image_type, + struct CanvasRenderingContext2D *canvas, + struct WebGLState *state); + +void canvas_native_webgl_tex_image2d_webgl(int32_t target, + int32_t level, + int32_t _internalformat, + int32_t _format, + int32_t _image_type, + struct WebGLState *webgl, + struct WebGLState *state); + void canvas_native_webgl_tex_image2d(int32_t target, int32_t level, int32_t internalformat, @@ -1826,6 +1842,14 @@ void canvas_native_webgl_tex_image2d_none(int32_t target, int32_t image_type, struct WebGLState *state); +void canvas_native_webgl_tex_image2d_image_asset(int32_t target, + int32_t level, + int32_t internalformat, + int32_t format, + int32_t image_type, + struct ImageAsset *image_asset, + struct WebGLState *state); + void canvas_native_webgl_tex_parameterf(uint32_t target, uint32_t pname, float param, @@ -2667,4 +2691,10 @@ uintptr_t canvas_native_f32_buffer_mut_get_length(const struct F32Buffer *buffer uintptr_t canvas_native_f32_buffer_get_length(const struct F32Buffer *buffer); +uintptr_t canvas_native_string_buffer_get_length(const struct StringBuffer *buffer); + +char *canvas_native_string_buffer_get_value_at(const struct StringBuffer *buffer, uintptr_t index); + +void canvas_native_string_buffer_destroy(struct StringBuffer *buffer); + #endif /* CANVAS_C_H */ diff --git a/packages/canvas/src-native/canvas-ios/dist/CanvasNative.xcframework/ios-arm64/dSYMs/CanvasNative.framework.dSYM/Contents/Resources/DWARF/CanvasNative b/packages/canvas/src-native/canvas-ios/dist/CanvasNative.xcframework/ios-arm64/dSYMs/CanvasNative.framework.dSYM/Contents/Resources/DWARF/CanvasNative index 4f81a612..ed2b3920 100644 Binary files a/packages/canvas/src-native/canvas-ios/dist/CanvasNative.xcframework/ios-arm64/dSYMs/CanvasNative.framework.dSYM/Contents/Resources/DWARF/CanvasNative and b/packages/canvas/src-native/canvas-ios/dist/CanvasNative.xcframework/ios-arm64/dSYMs/CanvasNative.framework.dSYM/Contents/Resources/DWARF/CanvasNative differ diff --git a/packages/canvas/src-native/canvas-ios/dist/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/CanvasNative b/packages/canvas/src-native/canvas-ios/dist/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/CanvasNative index 5ffccdcf..887e1f59 100755 Binary files a/packages/canvas/src-native/canvas-ios/dist/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/CanvasNative and b/packages/canvas/src-native/canvas-ios/dist/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/CanvasNative differ diff --git a/packages/canvas/src-native/canvas-ios/dist/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Headers/CanvasNative.h b/packages/canvas/src-native/canvas-ios/dist/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Headers/CanvasNative.h index 510776d3..178b9692 100644 --- a/packages/canvas/src-native/canvas-ios/dist/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Headers/CanvasNative.h +++ b/packages/canvas/src-native/canvas-ios/dist/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Headers/CanvasNative.h @@ -4,13 +4,18 @@ // // Created by Osei Fortune on 30/09/2020. // -#import "canvas_native.h" -#import "canvas_ios.h" -#ifdef __OBJC__ +#ifdef __cplusplus +extern "C" { +#endif + #import +#import "canvas_native.h" +#import "canvas_ios.h" + //! Project version number for CanvasNative. + FOUNDATION_EXPORT double CanvasNativeVersionNumber; //! Project version string for CanvasNative. @@ -18,4 +23,7 @@ FOUNDATION_EXPORT const unsigned char CanvasNativeVersionString[]; // In this header, you should import all the public headers of your framework using statements like #import +#ifdef __cplusplus +} #endif + diff --git a/packages/canvas/src-native/canvas-ios/dist/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Headers/canvas_native.h b/packages/canvas/src-native/canvas-ios/dist/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Headers/canvas_native.h index cc45f904..9b65c215 100644 --- a/packages/canvas/src-native/canvas-ios/dist/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Headers/canvas_native.h +++ b/packages/canvas/src-native/canvas-ios/dist/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Headers/canvas_native.h @@ -1056,7 +1056,7 @@ struct ImageData *canvas_native_image_data_get_shared_instance(struct ImageData struct ImageAsset *canvas_native_image_asset_create(void); -struct ImageAsset *canvas_native_image_asset_shared_clone(const struct ImageAsset *asset); +struct ImageAsset *canvas_native_image_asset_shared_clone(struct ImageAsset *asset); bool canvas_native_image_asset_load_from_fd(struct ImageAsset *asset, int fd); @@ -1633,8 +1633,8 @@ struct ContextAttributes *canvas_native_webgl_get_context_attributes(struct WebG uint32_t canvas_native_webgl_get_error(struct WebGLState *state); -const struct WebGLExtension *canvas_native_webgl_get_extension(const char *name, - struct WebGLState *state); +struct WebGLExtension *canvas_native_webgl_get_extension(const char *name, + struct WebGLState *state); struct WebGLFramebufferAttachmentParameter *canvas_native_webgl_get_framebuffer_attachment_parameter(uint32_t target, uint32_t attachment, @@ -1804,6 +1804,22 @@ void canvas_native_webgl_tex_image2d_image_none(int32_t target, int32_t image_type, struct WebGLState *state); +void canvas_native_webgl_tex_image2d_canvas2d(int32_t target, + int32_t level, + int32_t internalformat, + int32_t format, + int32_t image_type, + struct CanvasRenderingContext2D *canvas, + struct WebGLState *state); + +void canvas_native_webgl_tex_image2d_webgl(int32_t target, + int32_t level, + int32_t _internalformat, + int32_t _format, + int32_t _image_type, + struct WebGLState *webgl, + struct WebGLState *state); + void canvas_native_webgl_tex_image2d(int32_t target, int32_t level, int32_t internalformat, @@ -1826,6 +1842,14 @@ void canvas_native_webgl_tex_image2d_none(int32_t target, int32_t image_type, struct WebGLState *state); +void canvas_native_webgl_tex_image2d_image_asset(int32_t target, + int32_t level, + int32_t internalformat, + int32_t format, + int32_t image_type, + struct ImageAsset *image_asset, + struct WebGLState *state); + void canvas_native_webgl_tex_parameterf(uint32_t target, uint32_t pname, float param, @@ -2667,4 +2691,10 @@ uintptr_t canvas_native_f32_buffer_mut_get_length(const struct F32Buffer *buffer uintptr_t canvas_native_f32_buffer_get_length(const struct F32Buffer *buffer); +uintptr_t canvas_native_string_buffer_get_length(const struct StringBuffer *buffer); + +char *canvas_native_string_buffer_get_value_at(const struct StringBuffer *buffer, uintptr_t index); + +void canvas_native_string_buffer_destroy(struct StringBuffer *buffer); + #endif /* CANVAS_C_H */ diff --git a/packages/canvas/src-native/canvas-ios/dist/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/_CodeSignature/CodeResources b/packages/canvas/src-native/canvas-ios/dist/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/_CodeSignature/CodeResources index 9a60ce2b..a1834083 100644 --- a/packages/canvas/src-native/canvas-ios/dist/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/_CodeSignature/CodeResources +++ b/packages/canvas/src-native/canvas-ios/dist/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/_CodeSignature/CodeResources @@ -10,7 +10,7 @@ Headers/CanvasNative.h - Fpy7Hlc8UqNId8jgtgKz5mOFBCU= + /f1joB+88Yli7N3M7UJmfZD+wrM= Headers/canvas_ios.h @@ -18,7 +18,7 @@ Headers/canvas_native.h - KjmIpBZrkmZPbZiPxYeDVFudctM= + kZAeynopf9HWpp2VwLjaus5M/hc= Info.plist @@ -94,7 +94,7 @@ hash2 - U94BOYW6ZUckumKy0f6esxE3QgCyRx/QAGTXLd+jBpU= + etIfFZplh+fbBvYN1m/bsCHh1B91DXsoX2FOvSfQ5Vw= Headers/canvas_ios.h @@ -108,7 +108,7 @@ hash2 - W14HFr1pFaToaWIQbCgrX4F1bw4RkCQFUOi0DiyMlww= + odQ0lZFQBS/l6gW2trmXrYsj7pbov7rXinUgSLQNp0Q= Modules/CanvasNative.swiftmodule/Project/arm64-apple-ios-simulator.swiftsourceinfo diff --git a/packages/canvas/src-native/canvas-ios/dist/CanvasNative.xcframework/ios-arm64_x86_64-simulator/dSYMs/CanvasNative.framework.dSYM/Contents/Resources/DWARF/CanvasNative b/packages/canvas/src-native/canvas-ios/dist/CanvasNative.xcframework/ios-arm64_x86_64-simulator/dSYMs/CanvasNative.framework.dSYM/Contents/Resources/DWARF/CanvasNative index e30cb344..3816887d 100644 Binary files a/packages/canvas/src-native/canvas-ios/dist/CanvasNative.xcframework/ios-arm64_x86_64-simulator/dSYMs/CanvasNative.framework.dSYM/Contents/Resources/DWARF/CanvasNative and b/packages/canvas/src-native/canvas-ios/dist/CanvasNative.xcframework/ios-arm64_x86_64-simulator/dSYMs/CanvasNative.framework.dSYM/Contents/Resources/DWARF/CanvasNative differ diff --git a/packages/canvas/src-native/canvas-native/canvas-c/src/buffers.rs b/packages/canvas/src-native/canvas-native/canvas-c/src/buffers.rs index bcbe0f8e..0b4dfca8 100644 --- a/packages/canvas/src-native/canvas-native/canvas-c/src/buffers.rs +++ b/packages/canvas/src-native/canvas-native/canvas-c/src/buffers.rs @@ -1,4 +1,5 @@ use bytes::BytesMut; +use std::ffi::{c_char, CString}; #[derive(Clone)] enum U8BufferInner { @@ -212,13 +213,13 @@ impl<'a> StringRefBuffer<'a> { #[no_mangle] pub extern "C" fn canvas_native_u8_buffer_get_bytes(buffer: *const U8Buffer) -> *const u8 { - assert!(buffer.is_null()); + assert!(!buffer.is_null()); let buffer = unsafe { &*buffer }; buffer.get_buffer().as_ptr() } #[no_mangle] pub extern "C" fn canvas_native_u8_buffer_get_bytes_mut(buffer: *mut U8Buffer) -> *mut u8 { - assert!(buffer.is_null()); + assert!(!buffer.is_null()); let buffer = unsafe { &mut *buffer }; buffer.get_buffer_mut().as_mut_ptr() } @@ -235,27 +236,27 @@ pub extern "C" fn canvas_native_u8_buffer_destroy(buffer: *mut U8Buffer) { #[no_mangle] pub extern "C" fn canvas_native_u8_buffer_mut_get_length(buffer: *const U8Buffer) -> usize { - assert!(buffer.is_null()); + assert!(!buffer.is_null()); let buffer = unsafe { &*buffer }; buffer.length() } #[no_mangle] pub extern "C" fn canvas_native_u8_buffer_get_length(buffer: *const U8Buffer) -> usize { - assert!(buffer.is_null()); + assert!(!buffer.is_null()); let buffer = unsafe { &*buffer }; buffer.length() } #[no_mangle] pub extern "C" fn canvas_native_u16_buffer_get_bytes(buffer: *const U16Buffer) -> *const u16 { - assert!(buffer.is_null()); + assert!(!buffer.is_null()); let buffer = unsafe { &*buffer }; buffer.get_buffer().as_ptr() } #[no_mangle] pub extern "C" fn canvas_native_u16_buffer_get_bytes_mut(buffer: *mut U16Buffer) -> *mut u16 { - assert!(buffer.is_null()); + assert!(!buffer.is_null()); let buffer = unsafe { &mut *buffer }; buffer.get_buffer_mut().as_mut_ptr() } @@ -272,27 +273,27 @@ pub extern "C" fn canvas_native_u16_buffer_destroy(buffer: *mut U16Buffer) { #[no_mangle] pub extern "C" fn canvas_native_u16_buffer_mut_get_length(buffer: *const U16Buffer) -> usize { - assert!(buffer.is_null()); + assert!(!buffer.is_null()); let buffer = unsafe { &*buffer }; buffer.length() } #[no_mangle] pub extern "C" fn canvas_native_u16_buffer_get_length(buffer: *const U16Buffer) -> usize { - assert!(buffer.is_null()); + assert!(!buffer.is_null()); let buffer = unsafe { &*buffer }; buffer.length() } #[no_mangle] pub extern "C" fn canvas_native_u32_buffer_get_bytes(buffer: *const U32Buffer) -> *const u32 { - assert!(buffer.is_null()); + assert!(!buffer.is_null()); let buffer = unsafe { &*buffer }; buffer.get_buffer().as_ptr() } #[no_mangle] pub extern "C" fn canvas_native_u32_buffer_get_bytes_mut(buffer: *mut U32Buffer) -> *mut u32 { - assert!(buffer.is_null()); + assert!(!buffer.is_null()); let buffer = unsafe { &mut *buffer }; buffer.get_buffer_mut().as_mut_ptr() } @@ -309,27 +310,27 @@ pub extern "C" fn canvas_native_u32_buffer_destroy(buffer: *mut U32Buffer) { #[no_mangle] pub extern "C" fn canvas_native_u32_buffer_mut_get_length(buffer: *const U32Buffer) -> usize { - assert!(buffer.is_null()); + assert!(!buffer.is_null()); let buffer = unsafe { &*buffer }; buffer.length() } #[no_mangle] pub extern "C" fn canvas_native_u32_buffer_get_length(buffer: *const U32Buffer) -> usize { - assert!(buffer.is_null()); + assert!(!buffer.is_null()); let buffer = unsafe { &*buffer }; buffer.length() } #[no_mangle] pub extern "C" fn canvas_native_i32_buffer_get_bytes(buffer: *const I32Buffer) -> *const i32 { - assert!(buffer.is_null()); + assert!(!buffer.is_null()); let buffer = unsafe { &*buffer }; buffer.get_buffer().as_ptr() } #[no_mangle] pub extern "C" fn canvas_native_i32_buffer_get_bytes_mut(buffer: *mut I32Buffer) -> *mut i32 { - assert!(buffer.is_null()); + assert!(!buffer.is_null()); let buffer = unsafe { &mut *buffer }; buffer.get_buffer_mut().as_mut_ptr() } @@ -346,27 +347,27 @@ pub extern "C" fn canvas_native_i32_buffer_destroy(buffer: *mut I32Buffer) { #[no_mangle] pub extern "C" fn canvas_native_i32_buffer_mut_get_length(buffer: *const I32Buffer) -> usize { - assert!(buffer.is_null()); + assert!(!buffer.is_null()); let buffer = unsafe { &*buffer }; buffer.length() } #[no_mangle] pub extern "C" fn canvas_native_i32_buffer_get_length(buffer: *const I32Buffer) -> usize { - assert!(buffer.is_null()); + assert!(!buffer.is_null()); let buffer = unsafe { &*buffer }; buffer.length() } #[no_mangle] pub extern "C" fn canvas_native_f32_buffer_get_bytes(buffer: *const F32Buffer) -> *const f32 { - assert!(buffer.is_null()); + assert!(!buffer.is_null()); let buffer = unsafe { &*buffer }; buffer.get_buffer().as_ptr() } #[no_mangle] pub extern "C" fn canvas_native_f32_buffer_get_bytes_mut(buffer: *mut F32Buffer) -> *mut f32 { - assert!(buffer.is_null()); + assert!(!buffer.is_null()); let buffer = unsafe { &mut *buffer }; buffer.get_buffer_mut().as_mut_ptr() } @@ -383,14 +384,44 @@ pub extern "C" fn canvas_native_f32_buffer_destroy(buffer: *mut F32Buffer) { #[no_mangle] pub extern "C" fn canvas_native_f32_buffer_mut_get_length(buffer: *const F32Buffer) -> usize { - assert!(buffer.is_null()); + assert!(!buffer.is_null()); let buffer = unsafe { &*buffer }; buffer.length() } #[no_mangle] pub extern "C" fn canvas_native_f32_buffer_get_length(buffer: *const F32Buffer) -> usize { - assert!(buffer.is_null()); + assert!(!buffer.is_null()); let buffer = unsafe { &*buffer }; buffer.length() } + +#[no_mangle] +pub extern "C" fn canvas_native_string_buffer_get_length(buffer: *const StringBuffer) -> usize { + assert!(!buffer.is_null()); + let buffer = unsafe { &*buffer }; + buffer.length() +} + +#[no_mangle] +pub extern "C" fn canvas_native_string_buffer_get_value_at( + buffer: *const StringBuffer, + index: usize, +) -> *mut c_char { + assert!(!buffer.is_null()); + let buffer = unsafe { &*buffer }; + match buffer.0.get(index) { + None => std::ptr::null_mut(), + Some(value) => CString::new(value.to_string()).unwrap().into_raw(), + } +} + +#[no_mangle] +pub extern "C" fn canvas_native_string_buffer_destroy(buffer: *mut StringBuffer) { + if buffer.is_null() { + return; + } + unsafe { + let _ = Box::from_raw(buffer); + } +} \ No newline at end of file diff --git a/packages/canvas/src-native/canvas-native/canvas-c/src/lib.rs b/packages/canvas/src-native/canvas-native/canvas-c/src/lib.rs index 66737e9c..3695ef16 100644 --- a/packages/canvas/src-native/canvas-native/canvas-c/src/lib.rs +++ b/packages/canvas/src-native/canvas-native/canvas-c/src/lib.rs @@ -144,7 +144,7 @@ pub extern "C" fn canvas_native_helper_destroy(value: *mut FileHelper) { #[no_mangle] pub extern "C" fn canvas_native_helper_read_file(path: *const c_char) -> *mut FileHelper { - assert!(path.is_null()); + assert!(!path.is_null()); let path = unsafe { CStr::from_ptr(path) }; let path = path.to_string_lossy(); let mut ret = FileHelper::default(); @@ -174,7 +174,7 @@ pub unsafe extern "C" fn canvas_native_helper_read_file_has_error(file: *const F pub unsafe extern "C" fn canvas_native_helper_read_file_get_data( file: *mut FileHelper, ) -> *mut U8Buffer { - assert!(file.is_null()); + assert!(!file.is_null()); let file = &*file; let data = match &file.data { None => U8Buffer::default(), @@ -311,7 +311,7 @@ impl PaintStyle { } pub fn new_with_color(color: *const c_char) -> Self { - assert!(color.is_null()); + assert!(!color.is_null()); let color = unsafe { CStr::from_ptr(color) }; let color = color.to_string_lossy(); Self( @@ -831,7 +831,7 @@ pub extern "C" fn canvas_native_context_set_miter_limit( pub extern "C" fn canvas_native_context_get_shadow_color( context: *const CanvasRenderingContext2D, ) -> *const c_char { - assert!(context.is_null()); + assert!(!context.is_null()); let context = unsafe { &*context }; let value = context.get_context().shadow_color(); let ret = to_parsed_color(value); @@ -842,7 +842,7 @@ pub extern "C" fn canvas_native_context_get_shadow_color( pub extern "C" fn canvas_native_context_get_shadow_color_buf( context: *const CanvasRenderingContext2D, ) -> *mut U8Buffer { - assert!(context.is_null()); + assert!(!context.is_null()); let context = unsafe { &*context }; let value = context.get_context().shadow_color(); Box::into_raw(Box::new(U8Buffer::from( @@ -858,7 +858,7 @@ pub extern "C" fn canvas_native_context_get_shadow_color_rgba( b: &mut u8, a: &mut u8, ) { - assert!(context.is_null()); + assert!(!context.is_null()); let context = unsafe { &*context }; context.get_context().shadow_color_rgba(r, g, b, a); } @@ -868,8 +868,8 @@ pub extern "C" fn canvas_native_context_set_shadow_color( context: *mut CanvasRenderingContext2D, color: *const c_char, ) { - assert!(context.is_null()); - assert!(color.is_null()); + assert!(!context.is_null()); + assert!(!color.is_null()); let context = unsafe { &mut *context }; let mut lock = context.get_context_mut(); let color = unsafe { CStr::from_ptr(color) }; @@ -886,7 +886,7 @@ pub extern "C" fn canvas_native_context_set_shadow_color_rgba( b: u8, a: u8, ) { - assert!(context.is_null()); + assert!(!context.is_null()); let context = unsafe { &mut *context }; let mut lock = context.get_context_mut(); lock.set_shadow_color_rgba(r, g, b, a); @@ -896,7 +896,7 @@ pub extern "C" fn canvas_native_context_set_shadow_color_rgba( pub extern "C" fn canvas_native_context_get_shadow_blur( context: *const CanvasRenderingContext2D, ) -> f32 { - assert!(context.is_null()); + assert!(!context.is_null()); let context = unsafe { &*context }; context.get_context().shadow_blur() } @@ -906,7 +906,7 @@ pub extern "C" fn canvas_native_context_set_shadow_blur( context: *mut CanvasRenderingContext2D, blur: f32, ) { - assert!(context.is_null()); + assert!(!context.is_null()); let context = unsafe { &mut *context }; context.get_context_mut().set_shadow_blur(blur) } @@ -915,7 +915,7 @@ pub extern "C" fn canvas_native_context_set_shadow_blur( pub extern "C" fn canvas_native_context_get_shadow_offset_x( context: *const CanvasRenderingContext2D, ) -> f32 { - assert!(context.is_null()); + assert!(!context.is_null()); let context = unsafe { &*context }; context.get_context().shadow_offset_x() } @@ -925,7 +925,7 @@ pub extern "C" fn canvas_native_context_set_shadow_offset_x( context: *mut CanvasRenderingContext2D, x: f32, ) { - assert!(context.is_null()); + assert!(!context.is_null()); let context = unsafe { &mut *context }; context.get_context_mut().set_shadow_offset_x(x) } @@ -934,7 +934,7 @@ pub extern "C" fn canvas_native_context_set_shadow_offset_x( pub extern "C" fn canvas_native_context_get_shadow_offset_y( context: *const CanvasRenderingContext2D, ) -> f32 { - assert!(context.is_null()); + assert!(!context.is_null()); let context = unsafe { &*context }; context.get_context().shadow_offset_y() } @@ -1122,7 +1122,7 @@ pub extern "C" fn canvas_native_paint_style_get_color_string( pub extern "C" fn canvas_native_paint_style_get_current_stroke_color_string( context: *const CanvasRenderingContext2D, ) -> *const c_char { - assert!(context.is_null()); + assert!(!context.is_null()); let context = unsafe { &*context }; let lock = context.get_context(); match lock.stroke_style() { @@ -1207,7 +1207,7 @@ pub extern "C" fn canvas_native_paint_style_get_current_fill_color_r_g_b_a( pub extern "C" fn canvas_native_paint_style_get_current_fill_color_string( context: *const CanvasRenderingContext2D, ) -> *const c_char { - assert!(context.is_null()); + assert!(!context.is_null()); let context = unsafe { &*context }; let lock = context.get_context(); match lock.fill_style() { @@ -1227,7 +1227,7 @@ pub extern "C" fn canvas_native_paint_style_get_current_fill_color_string( pub extern "C" fn canvas_native_paint_style_get_current_fill_color_buf( context: *mut CanvasRenderingContext2D, ) -> *mut U8Buffer { - assert!(context.is_null()); + assert!(!context.is_null()); let context = unsafe { &*context }; let lock = context.get_context(); let ret = match lock.fill_style() { @@ -1246,7 +1246,7 @@ pub extern "C" fn canvas_native_paint_style_get_current_fill_color_buf( #[no_mangle] pub extern "C" fn canvas_native_context_get_style_type(style: *const PaintStyle) -> PaintStyleType { - assert!(style.is_null()); + assert!(!style.is_null()); let style = unsafe { &*style }; style.style_type() } @@ -1255,7 +1255,7 @@ pub extern "C" fn canvas_native_context_get_style_type(style: *const PaintStyle) pub extern "C" fn canvas_native_context_get_current_fill_style_type( context: *mut CanvasRenderingContext2D, ) -> PaintStyleType { - assert!(context.is_null()); + assert!(!context.is_null()); let context = unsafe { &*context }; let lock = context.get_context(); return match lock.fill_style() { @@ -1275,7 +1275,7 @@ pub extern "C" fn canvas_native_context_get_current_fill_style_type( pub extern "C" fn canvas_native_context_get_current_stroke_style_type( context: *mut CanvasRenderingContext2D, ) -> PaintStyleType { - assert!(context.is_null()); + assert!(!context.is_null()); let context = unsafe { &*context }; let lock = context.get_context(); return match lock.fill_style() { @@ -1296,7 +1296,7 @@ pub extern "C" fn canvas_native_context_get_current_stroke_style_type( pub extern "C" fn canvas_native_context_get_fill_style( context: *const CanvasRenderingContext2D, ) -> *mut PaintStyle { - assert!(context.is_null()); + assert!(!context.is_null()); let context = unsafe { &*context }; Box::into_raw(Box::new(PaintStyle(Some( context.get_context().fill_style().clone(), @@ -1309,8 +1309,8 @@ pub extern "C" fn canvas_native_context_set_fill_style( context: *mut CanvasRenderingContext2D, style: *const PaintStyle, ) { - assert!(context.is_null()); - assert!(style.is_null()); + assert!(!context.is_null()); + assert!(!style.is_null()); let context = unsafe { &mut *context }; let style = unsafe { &*style }; if !style.is_empty() { @@ -1325,7 +1325,7 @@ pub extern "C" fn canvas_native_context_set_fill_style( pub extern "C" fn canvas_native_context_get_stroke_style( context: *const CanvasRenderingContext2D, ) -> *mut PaintStyle { - assert!(context.is_null()); + assert!(!context.is_null()); let context = unsafe { &*context }; Box::into_raw(Box::new(PaintStyle(Some( context.get_context().stroke_style().clone(), @@ -1338,8 +1338,8 @@ pub extern "C" fn canvas_native_context_set_stroke_style( context: *mut CanvasRenderingContext2D, style: *const PaintStyle, ) { - assert!(context.is_null()); - assert!(style.is_null()); + assert!(!context.is_null()); + assert!(!style.is_null()); let context = unsafe { &mut *context }; let style = unsafe { &*style }; if !style.is_empty() { @@ -1353,7 +1353,7 @@ pub extern "C" fn canvas_native_context_set_stroke_style( pub extern "C" fn canvas_native_context_get_line_width( context: *const CanvasRenderingContext2D, ) -> f32 { - assert!(context.is_null()); + assert!(!context.is_null()); let context = unsafe { &*context }; context.get_context().line_width() } @@ -1363,7 +1363,7 @@ pub extern "C" fn canvas_native_context_set_line_width( context: *mut CanvasRenderingContext2D, width: f32, ) { - assert!(context.is_null()); + assert!(!context.is_null()); let context = unsafe { &mut *context }; context.get_context_mut().set_line_width(width); } @@ -1372,7 +1372,7 @@ pub extern "C" fn canvas_native_context_set_line_width( pub extern "C" fn canvas_native_context_get_line_dash_offset( context: *const CanvasRenderingContext2D, ) -> f32 { - assert!(context.is_null()); + assert!(!context.is_null()); let context = unsafe { &*context }; context.get_context().line_dash_offset() } @@ -1382,7 +1382,7 @@ pub extern "C" fn canvas_native_context_set_line_dash_offset( context: *mut CanvasRenderingContext2D, offset: f32, ) { - assert!(context.is_null()); + assert!(!context.is_null()); let context = unsafe { &mut *context }; context.get_context_mut().set_line_dash_offset(offset) } @@ -1391,7 +1391,7 @@ pub extern "C" fn canvas_native_context_set_line_dash_offset( pub extern "C" fn canvas_native_context_get_line_dash( context: *const CanvasRenderingContext2D, ) -> *mut F32Buffer { - assert!(context.is_null()); + assert!(!context.is_null()); let context = unsafe { &*context }; Box::into_raw(Box::new(F32Buffer::from( context.get_context().line_dash().to_vec(), @@ -1404,8 +1404,8 @@ pub extern "C" fn canvas_native_context_set_line_dash( dash: *const f32, size: usize, ) { - assert!(context.is_null()); - assert!(dash.is_null()); + assert!(!context.is_null()); + assert!(!dash.is_null()); let context = unsafe { &mut *context }; let dash = unsafe { std::slice::from_raw_parts(dash, size) }; context.get_context_mut().set_line_dash(dash) @@ -1421,7 +1421,7 @@ pub extern "C" fn canvas_native_context_arc( end_angle: f32, anticlockwise: bool, ) { - assert!(context.is_null()); + assert!(!context.is_null()); let context = unsafe { &mut *context }; context .get_context_mut() @@ -1483,7 +1483,7 @@ pub extern "C" fn canvas_native_context_clip( path: *mut Path, rule: *const c_char, ) { - assert!(rule.is_null()); + assert!(!rule.is_null()); let rule = unsafe { CStr::from_ptr(rule) }; let path = unsafe { &mut *path }; if let Ok(rule) = FillRule::try_from(rule.to_string_lossy().as_ref()) { @@ -1500,8 +1500,8 @@ pub extern "C" fn canvas_native_context_clip_rule( context: *mut CanvasRenderingContext2D, rule: *const c_char, ) { - assert!(context.is_null()); - assert!(rule.is_null()); + assert!(!context.is_null()); + assert!(!rule.is_null()); let context = unsafe { &mut *context }; let rule = unsafe { CStr::from_ptr(rule) }; if let Ok(rule) = FillRule::try_from(rule.to_string_lossy().as_ref()) { @@ -1513,7 +1513,7 @@ pub extern "C" fn canvas_native_context_clip_rule( #[inline(always)] #[no_mangle] pub extern "C" fn canvas_native_context_close_path(context: *mut CanvasRenderingContext2D) { - assert!(context.is_null()); + assert!(!context.is_null()); let context = unsafe { &mut *context }; context.get_context_mut().close_path() } @@ -1535,7 +1535,7 @@ pub extern "C" fn canvas_native_context_create_image_data_with_data( data: *const u8, size: usize, ) -> *mut ImageData { - assert!(data.is_null()); + assert!(!data.is_null()); let data = unsafe { std::slice::from_raw_parts(data, size) }; Box::into_raw(Box::new(ImageData::new( canvas_2d::context::pixel_manipulation::image_data::ImageData::new_with_data( @@ -1552,7 +1552,7 @@ pub extern "C" fn canvas_native_context_create_linear_gradient( x1: f32, y1: f32, ) -> *mut PaintStyle { - assert!(context.is_null()); + assert!(!context.is_null()); let context = unsafe { &mut *context }; Box::into_raw(Box::new(PaintStyle(Some( canvas_2d::context::fill_and_stroke_styles::paint::PaintStyle::Gradient( @@ -1570,9 +1570,9 @@ pub extern "C" fn canvas_native_context_create_pattern( height: i32, repetition: *const c_char, ) -> *mut PaintStyle { - assert!(context.is_null()); - assert!(repetition.is_null()); - assert!(data.is_null()); + assert!(!context.is_null()); + assert!(!repetition.is_null()); + assert!(!data.is_null()); let context = unsafe { &mut *context }; let data = unsafe { std::slice::from_raw_parts(data, size) }; let repetition = unsafe { CStr::from_ptr(repetition) }; @@ -1593,9 +1593,9 @@ pub extern "C" fn canvas_native_context_create_pattern_asset( asset: *mut ImageAsset, repetition: *const c_char, ) -> *mut PaintStyle { - assert!(context.is_null()); - assert!(asset.is_null()); - assert!(repetition.is_null()); + assert!(!context.is_null()); + assert!(!asset.is_null()); + assert!(!repetition.is_null()); let context = unsafe { &*context }; let asset = unsafe { &*asset }; let repetition = unsafe { CStr::from_ptr(repetition) }; @@ -1639,9 +1639,9 @@ pub extern "C" fn canvas_native_context_create_pattern_encoded( size: usize, repetition: *const c_char, ) -> *mut PaintStyle { - assert!(context.is_null()); - assert!(repetition.is_null()); - assert!(data.is_null()); + assert!(!context.is_null()); + assert!(!repetition.is_null()); + assert!(!data.is_null()); let context = unsafe { &*context }; let repetition = unsafe { CStr::from_ptr(repetition) }; let repetition = repetition.to_string_lossy(); @@ -1663,9 +1663,9 @@ pub extern "C" fn canvas_native_context_create_pattern_canvas2d( context: *mut CanvasRenderingContext2D, repetition: *const c_char, ) -> *mut PaintStyle { - assert!(source.is_null()); - assert!(context.is_null()); - assert!(repetition.is_null()); + assert!(!source.is_null()); + assert!(!context.is_null()); + assert!(!repetition.is_null()); let source = unsafe { &*source }; let context = unsafe { &*context }; let repetition = unsafe { CStr::from_ptr(repetition) }; @@ -1745,7 +1745,7 @@ pub extern "C" fn canvas_native_context_create_radial_gradient( y1: f32, r1: f32, ) -> *mut PaintStyle { - assert!(context.is_null()); + assert!(!context.is_null()); let context = unsafe { &*context }; Box::into_raw(Box::new(PaintStyle(Some( canvas_2d::context::fill_and_stroke_styles::paint::PaintStyle::Gradient( @@ -1761,7 +1761,7 @@ pub extern "C" fn canvas_native_context_draw_paint( context: *mut CanvasRenderingContext2D, color: *const c_char, ) { - assert!(color.is_null()); + assert!(!color.is_null()); let color = unsafe { CStr::from_ptr(color) }; let color = color.to_string_lossy(); let context = unsafe { &mut *context }; @@ -1775,7 +1775,7 @@ pub extern "C" fn canvas_native_context_draw_point( x: f32, y: f32, ) { - assert!(context.is_null()); + assert!(!context.is_null()); let context = unsafe { &mut *context }; context.make_current(); context.get_context_mut().draw_point(x, y); @@ -1788,8 +1788,8 @@ pub extern "C" fn canvas_native_context_draw_points( points: *const f32, size: usize, ) { - assert!(context.is_null()); - assert!(points.is_null()); + assert!(!context.is_null()); + assert!(!points.is_null()); let points = unsafe { std::slice::from_raw_parts(points, size) }; let context = unsafe { &mut *context }; context.make_current(); @@ -1848,7 +1848,7 @@ pub extern "C" fn canvas_native_context_draw_image( d_width: f32, d_height: f32, ) { - assert!(data.is_null()); + assert!(!data.is_null()); let data = unsafe { std::slice::from_raw_parts(data, size) }; if let Some(image) = from_image_slice(data, width as i32, height as i32) { let context = unsafe { &mut *context }; @@ -1867,7 +1867,7 @@ pub extern "C" fn canvas_native_context_draw_image_encoded_dx_dy( dx: f32, dy: f32, ) { - assert!(data.is_null()); + assert!(!data.is_null()); let data = unsafe { std::slice::from_raw_parts(data, size) }; if let Some(image) = from_image_slice_encoded(data) { let context = unsafe { &mut *context }; @@ -1890,7 +1890,7 @@ pub extern "C" fn canvas_native_context_draw_image_encoded_dx_dy_dw_dh( d_width: f32, d_height: f32, ) { - assert!(data.is_null()); + assert!(!data.is_null()); let data = unsafe { std::slice::from_raw_parts(data, size) }; if let Some(image) = from_image_slice_encoded(data) { let context = unsafe { &mut *context }; @@ -1917,7 +1917,7 @@ pub extern "C" fn canvas_native_context_draw_image_encoded( d_width: f32, d_height: f32, ) { - assert!(data.is_null()); + assert!(!data.is_null()); let data = unsafe { std::slice::from_raw_parts(data, size) }; if let Some(image) = from_image_slice_encoded(data) { let context = unsafe { &mut *context }; @@ -1957,7 +1957,7 @@ pub extern "C" fn canvas_native_context_draw_image_dx_dy_dw_dh_asset( d_width: f32, d_height: f32, ) { - assert!(asset.is_null()); + assert!(!asset.is_null()); let width: f32; let height: f32; { @@ -1983,8 +1983,8 @@ pub extern "C" fn canvas_native_context_draw_image_asset( d_width: f32, d_height: f32, ) { - assert!(context.is_null()); - assert!(asset.is_null()); + assert!(!context.is_null()); + assert!(!asset.is_null()); let context = unsafe { &mut *context }; let asset = unsafe { &*asset }; @@ -2017,7 +2017,7 @@ pub extern "C" fn canvas_native_context_draw_image_dx_dy_context( dx: f32, dy: f32, ) { - assert!(source.is_null()); + assert!(!source.is_null()); let device; { let source = unsafe { &*source }; @@ -2042,8 +2042,8 @@ pub extern "C" fn canvas_native_context_draw_image_dx_dy_dw_dh_context( d_width: f32, d_height: f32, ) { - assert!(context.is_null()); - assert!(source.is_null()); + assert!(!context.is_null()); + assert!(!source.is_null()); let device; { @@ -2072,8 +2072,8 @@ pub extern "C" fn canvas_native_context_draw_image_context( d_width: f32, d_height: f32, ) { - assert!(context.is_null()); - assert!(source.is_null()); + assert!(!context.is_null()); + assert!(!source.is_null()); let context = unsafe { &mut *context }; let source = unsafe { &*source }; source.make_current(); @@ -2391,7 +2391,7 @@ pub extern "C" fn canvas_native_context_round_rect( radii: *const f32, size: usize, ) { - assert!(radii.is_null()); + assert!(!radii.is_null()); let radii = unsafe { std::slice::from_raw_parts(radii, size) }; let context = unsafe { &mut *context }; if radii.len() == 8 { @@ -2680,7 +2680,7 @@ pub extern "C" fn canvas_native_image_bitmap_create_from_encoded_bytes( resize_width: f32, resize_height: f32, ) -> *mut ImageAsset { - assert!(bytes.is_null()); + assert!(!bytes.is_null()); let bytes = unsafe { std::slice::from_raw_parts(bytes, size) }; Box::into_raw(Box::new(ImageAsset( canvas_2d::image_bitmap::create_image_asset_encoded( @@ -2708,8 +2708,8 @@ pub extern "C" fn canvas_native_image_bitmap_create_from_encoded_bytes_with_outp resize_height: f32, output: *mut ImageAsset, ) -> bool { - assert!(output.is_null()); - assert!(bytes.is_null()); + assert!(!output.is_null()); + assert!(!bytes.is_null()); let bytes = unsafe { std::slice::from_raw_parts(bytes, size) }; let output = unsafe { &mut *output }; canvas_2d::image_bitmap::create_image_asset_with_output( @@ -2742,7 +2742,7 @@ pub extern "C" fn canvas_native_image_bitmap_create_from_encoded_bytes_src_rect( resize_width: f32, resize_height: f32, ) -> *mut ImageAsset { - assert!(bytes.is_null()); + assert!(!bytes.is_null()); let bytes = unsafe { std::slice::from_raw_parts(bytes, size) }; Box::into_raw(Box::new(ImageAsset( canvas_2d::image_bitmap::create_image_asset_encoded( @@ -2774,8 +2774,8 @@ pub extern "C" fn canvas_native_image_bitmap_create_from_encoded_bytes_src_rect_ resize_height: f32, output: *mut ImageAsset, ) -> bool { - assert!(output.is_null()); - assert!(bytes.is_null()); + assert!(!output.is_null()); + assert!(!bytes.is_null()); let bytes = unsafe { std::slice::from_raw_parts(bytes, size) }; let output = unsafe { &mut *output }; canvas_2d::image_bitmap::create_image_asset_with_output( @@ -3010,8 +3010,8 @@ pub extern "C" fn canvas_native_path_round_rect( radii: *const f32, size: usize, ) { - assert!(path.is_null()); - assert!(radii.is_null()); + assert!(!path.is_null()); + assert!(!radii.is_null()); let radii = unsafe { std::slice::from_raw_parts(radii, size) }; let path = unsafe { &mut *path }; @@ -3092,7 +3092,7 @@ pub extern "C" fn canvas_native_path_round_rect_tl_tr_br_bl( bottom_right: f32, bottom_left: f32, ) { - assert!(path.is_null()); + assert!(!path.is_null()); let path = unsafe { &mut *path }; path.0.round_rect( @@ -3147,8 +3147,8 @@ pub extern "C" fn canvas_native_matrix_create() -> *mut Matrix { #[no_mangle] pub extern "C" fn canvas_native_matrix_update(matrix: *mut Matrix, slice: *const f32, size: usize) { - assert!(matrix.is_null()); - assert!(slice.is_null()); + assert!(!matrix.is_null()); + assert!(!slice.is_null()); let slice = unsafe { std::slice::from_raw_parts(slice, size) }; let matrix = unsafe { &mut *matrix }; let mut affine = [0f32; 6]; @@ -3162,8 +3162,8 @@ pub extern "C" fn canvas_native_matrix_update_3d( slice: *const f32, size: usize, ) { - assert!(matrix.is_null()); - assert!(slice.is_null()); + assert!(!matrix.is_null()); + assert!(!slice.is_null()); let slice = unsafe { std::slice::from_raw_parts(slice, size) }; assert_eq!(slice.len(), 16); let matrix = unsafe { &mut *matrix }; @@ -3591,11 +3591,9 @@ pub extern "C" fn canvas_native_image_asset_create() -> *mut ImageAsset { #[no_mangle] pub extern "C" fn canvas_native_image_asset_shared_clone( - asset: *const ImageAsset, + asset: *mut ImageAsset, ) -> *mut ImageAsset { - if asset.is_null() { - return std::ptr::null_mut(); - } + assert!(!asset.is_null()); let asset = unsafe { &*asset }; Box::into_raw(Box::new(asset.clone())) } @@ -3637,7 +3635,7 @@ pub extern "C" fn canvas_native_image_asset_load_from_raw( array: *const u8, size: usize, ) -> bool { - assert!(array.is_null()); + assert!(!array.is_null()); let array = unsafe { std::slice::from_raw_parts(array, size) }; let asset = unsafe { &mut *asset }; asset.load_from_bytes(array) @@ -3653,8 +3651,8 @@ pub extern "C" fn canvas_native_image_asset_load_from_url( } let asset = unsafe { &mut *asset }; let url = unsafe { CStr::from_ptr(url) }; - let url = url.to_string_lossy(); - canvas_native_image_asset_load_from_url_internal(&mut asset.0, url.as_ref()) + let url = url.to_string_lossy().to_string(); + canvas_native_image_asset_load_from_url_internal(&mut asset.0, url.as_str()) } pub(crate) fn canvas_native_image_asset_load_from_url_internal( @@ -3673,17 +3671,22 @@ pub(crate) fn canvas_native_image_asset_load_from_url_internal( if res.status() != 200 { return false; } - assert!(res.has("Content-Length")); + // assert!(!res.has("Content-Length")); let len: usize; - if let Ok(length) = res.header("Content-Length").unwrap().parse::() { - len = length; - } else { + + if let Some(value) = res.header("Content-Length") { + if let Ok(length) = value.parse::() { + len = length; + }else { + return false; + } + }else { return false; } let mut bytes: Vec = Vec::with_capacity(len); if let Ok(_) = res.into_reader().read_to_end(&mut bytes) { - assert_eq!(bytes.len(), len); + // assert_eq!(bytes.len(), len); } else { return false; } @@ -3932,8 +3935,8 @@ pub extern "C" fn canvas_native_paint_style_from_bytes( bytes: *const u8, size: usize, ) -> *mut PaintStyle { - assert!(context.is_null()); - assert!(bytes.is_null()); + assert!(!context.is_null()); + assert!(!bytes.is_null()); let context = unsafe { &*context }; let bytes = unsafe { std::slice::from_raw_parts(bytes, size) }; Box::into_raw(Box::new(PaintStyle( @@ -4011,7 +4014,7 @@ pub extern "C" fn canvas_native_pattern_set_transform( /* TextDecoder */ #[no_mangle] pub extern "C" fn canvas_native_text_decoder_create(decoding: *const c_char) -> *mut TextDecoder { - assert!(decoding.is_null()); + assert!(!decoding.is_null()); let decoding = unsafe { CStr::from_ptr(decoding) }; let decoding = decoding.to_string_lossy(); Box::into_raw(Box::new(TextDecoder( @@ -4025,8 +4028,8 @@ pub extern "C" fn canvas_native_text_decoder_decode( data: *const u8, size: usize, ) -> *const c_char { - assert!(decoder.is_null()); - assert!(data.is_null()); + assert!(!decoder.is_null()); + assert!(!data.is_null()); let data = unsafe { std::slice::from_raw_parts(data, size) }; let decoder = unsafe { &*decoder }; CString::new(decoder.0.decode_to_string(data)) @@ -4038,7 +4041,7 @@ pub extern "C" fn canvas_native_text_decoder_decode( pub extern "C" fn canvas_native_text_decoder_get_encoding( decoder: *const TextDecoder, ) -> *const c_char { - assert!(decoder.is_null()); + assert!(!decoder.is_null()); let decoder = unsafe { &*decoder }; CString::new(decoder.0.encoding().to_string().to_lowercase()) .unwrap() @@ -4049,7 +4052,7 @@ pub extern "C" fn canvas_native_text_decoder_get_encoding( /* TextEncoder */ #[no_mangle] pub extern "C" fn canvas_native_text_encoder_create(encoding: *const c_char) -> *mut TextEncoder { - assert!(encoding.is_null()); + assert!(!encoding.is_null()); let encoding = unsafe { CStr::from_ptr(encoding) }; let encoding = encoding.to_string_lossy(); @@ -4063,8 +4066,8 @@ pub extern "C" fn canvas_native_text_encoder_encode( encoder: *const TextEncoder, text: *const c_char, ) -> *mut U8Buffer { - assert!(encoder.is_null()); - assert!(text.is_null()); + assert!(!encoder.is_null()); + assert!(!text.is_null()); let encoder = unsafe { &*encoder }; let text = unsafe { CStr::from_ptr(text) }; let text = text.to_string_lossy(); @@ -4076,7 +4079,7 @@ pub extern "C" fn canvas_native_text_encoder_encode( pub extern "C" fn canvas_native_text_encoder_get_encoding( encoder: *const TextEncoder, ) -> *const c_char { - assert!(encoder.is_null()); + assert!(!encoder.is_null()); let encoder = unsafe { &*encoder }; CString::new(encoder.0.encoding().to_string().to_lowercase()) .unwrap() @@ -4090,7 +4093,7 @@ pub extern "C" fn canvas_native_text_encoder_get_encoding( pub extern "C" fn canvas_native_context_gl_make_current( context: *const CanvasRenderingContext2D, ) -> bool { - assert!(context.is_null()); + assert!(!context.is_null()); let context = unsafe { &*context }; context.make_current() } @@ -4099,7 +4102,7 @@ pub extern "C" fn canvas_native_context_gl_make_current( pub extern "C" fn canvas_native_context_gl_swap_buffers( context: *const CanvasRenderingContext2D, ) -> bool { - assert!(context.is_null()); + assert!(!context.is_null()); let context = unsafe { &*context }; context.swap_buffers() } @@ -4230,9 +4233,9 @@ pub extern "C" fn canvas_native_context_create_pattern_webgl( context: *mut CanvasRenderingContext2D, repetition: *const c_char, ) -> *mut PaintStyle { - assert!(context.is_null()); - assert!(repetition.is_null()); - assert!(source.is_null()); + assert!(!context.is_null()); + assert!(!repetition.is_null()); + assert!(!source.is_null()); let context = unsafe { &mut *context }; let repetition = unsafe { CStr::from_ptr(repetition) }; let repetition = repetition.to_string_lossy(); @@ -4276,14 +4279,14 @@ pub extern "C" fn canvas_native_context_create_pattern_webgl( #[no_mangle] pub extern "C" fn canvas_native_webgl_make_current(state: *mut WebGLState) -> bool { - assert!(state.is_null()); + assert!(!state.is_null()); let state = unsafe { &mut *state }; state.get_inner().make_current() } #[no_mangle] pub extern "C" fn canvas_native_webgl_swap_buffers(state: *mut WebGLState) -> bool { - assert!(state.is_null()); + assert!(!state.is_null()); let state = unsafe { &mut *state }; state.get_inner().swap_buffers() } @@ -4302,8 +4305,8 @@ pub extern "C" fn canvas_native_webgl_to_data_url( format: *const c_char, quality: u32, ) -> *const c_char { - assert!(state.is_null()); - assert!(format.is_null()); + assert!(!state.is_null()); + assert!(!format.is_null()); let format = unsafe { CStr::from_ptr(format) }; let format = format.to_string_lossy(); let state = unsafe { &mut *state }; @@ -5109,7 +5112,7 @@ pub extern "C" fn canvas_native_webgl_context_attribute_get_get_xr_compatible( pub extern "C" fn canvas_native_webgl_context_extension_is_none( extension: *const WebGLExtension, ) -> bool { - assert!(extension.is_null()); + assert!(!extension.is_null()); let extension = unsafe { &*extension }; extension.is_none() } @@ -5169,7 +5172,7 @@ pub extern "C" fn canvas_native_webgl_context_extension_to_oes_vertex_array_obje pub extern "C" fn canvas_native_webgl_result_get_type( result: *const WebGLResult, ) -> WebGLResultType { - assert!(result.is_null()); + assert!(!result.is_null()); let result = unsafe { &*result }; match result.0 { canvas_webgl::prelude::WebGLResult::Boolean(_) => WebGLResultType::WebGLResultTypeBoolean, @@ -5492,8 +5495,8 @@ pub extern "C" fn canvas_native_webgl_draw_buffers_draw_buffers_webgl( size: usize, context: *const WEBGL_draw_buffers, ) { - assert!(buffers.is_null()); - assert!(context.is_null()); + assert!(!buffers.is_null()); + assert!(!context.is_null()); let buffers = unsafe { std::slice::from_raw_parts(buffers, size) }; let context = unsafe { &*context }; context.0.draw_buffers_webgl(buffers); @@ -5854,8 +5857,8 @@ pub extern "C" fn canvas_native_webgl_buffer_data( usage: u32, state: *mut WebGLState, ) { - assert!(state.is_null()); - assert!(src_data.is_null()); + assert!(!state.is_null()); + assert!(!src_data.is_null()); let src_data = unsafe { std::slice::from_raw_parts(src_data, size) }; let state = unsafe { &mut *state }; canvas_webgl::webgl::canvas_native_webgl_buffer_data( @@ -5874,8 +5877,8 @@ pub extern "C" fn canvas_native_webgl_buffer_data_u16( usage: u32, state: *mut WebGLState, ) { - assert!(state.is_null()); - assert!(src_data.is_null()); + assert!(!state.is_null()); + assert!(!src_data.is_null()); let src_data = unsafe { std::slice::from_raw_parts(src_data, size) }; let state = unsafe { &mut *state }; canvas_webgl::webgl::canvas_native_webgl_buffer_data_u16( @@ -5894,7 +5897,7 @@ pub extern "C" fn canvas_native_webgl_buffer_data_f32( usage: u32, state: *mut WebGLState, ) { - assert!(src_data.is_null()); + assert!(!src_data.is_null()); let src_data = unsafe { std::slice::from_raw_parts(src_data, size) }; let state = unsafe { &mut *state }; canvas_webgl::webgl::canvas_native_webgl_buffer_data_f32( @@ -5929,8 +5932,8 @@ pub extern "C" fn canvas_native_webgl_buffer_sub_data( size: usize, state: *mut WebGLState, ) { - assert!(state.is_null()); - assert!(src_data.is_null()); + assert!(!state.is_null()); + assert!(!src_data.is_null()); let src_data = unsafe { std::slice::from_raw_parts(src_data, size) }; let state = unsafe { &mut *state }; canvas_webgl::webgl::canvas_native_webgl_buffer_sub_data( @@ -6044,8 +6047,8 @@ pub extern "C" fn canvas_native_webgl_compressed_tex_image2d( size: usize, state: *mut WebGLState, ) { - assert!(state.is_null()); - assert!(pixels.is_null()); + assert!(!state.is_null()); + assert!(!pixels.is_null()); let pixels = unsafe { std::slice::from_raw_parts(pixels, size) }; let state = unsafe { &mut *state }; canvas_webgl::webgl::canvas_native_webgl_compressed_tex_image2d( @@ -6095,8 +6098,8 @@ pub extern "C" fn canvas_native_webgl_compressed_tex_sub_image2d( size: usize, state: *mut WebGLState, ) { - assert!(state.is_null()); - assert!(pixels.is_null()); + assert!(!state.is_null()); + assert!(!pixels.is_null()); let pixels = unsafe { std::slice::from_raw_parts(pixels, size) }; let state = unsafe { &mut *state }; canvas_webgl::webgl::canvas_native_webgl_compressed_tex_sub_image2d( @@ -6463,7 +6466,7 @@ pub extern "C" fn canvas_native_webgl_get_attrib_location( name: *const c_char, state: *mut WebGLState, ) -> i32 { - assert!(state.is_null()); + assert!(!state.is_null()); let name = unsafe { CStr::from_ptr(name) }; let name = name.to_string_lossy(); let state = unsafe { &mut *state }; @@ -6508,8 +6511,8 @@ pub extern "C" fn canvas_native_webgl_get_error(state: *mut WebGLState) -> u32 { pub extern "C" fn canvas_native_webgl_get_extension( name: *const c_char, state: *mut WebGLState, -) -> *const WebGLExtension { - assert!(state.is_null()); +) -> *mut WebGLExtension { + assert!(!state.is_null()); let name = unsafe { CStr::from_ptr(name) }; let name = name.to_string_lossy(); let state = unsafe { &mut *state }; @@ -6543,7 +6546,7 @@ pub extern "C" fn canvas_native_webgl_get_framebuffer_attachment_parameter( pub extern "C" fn canvas_native_webgl_framebuffer_attachment_parameter_get_is_texture( param: *const WebGLFramebufferAttachmentParameter, ) -> bool { - assert!(param.is_null()); + assert!(!param.is_null()); let param = unsafe { &*param }; param.get_is_texture() } @@ -6552,7 +6555,7 @@ pub extern "C" fn canvas_native_webgl_framebuffer_attachment_parameter_get_is_te pub extern "C" fn canvas_native_webgl_framebuffer_attachment_parameter_get_is_renderbuffer( param: *const WebGLFramebufferAttachmentParameter, ) -> bool { - assert!(param.is_null()); + assert!(!param.is_null()); let param = unsafe { &*param }; param.get_is_renderbuffer() @@ -6562,7 +6565,7 @@ pub extern "C" fn canvas_native_webgl_framebuffer_attachment_parameter_get_is_re pub extern "C" fn canvas_native_webgl_framebuffer_attachment_parameter_get_value( param: *const WebGLFramebufferAttachmentParameter, ) -> i32 { - assert!(param.is_null()); + assert!(!param.is_null()); let param = unsafe { &*param }; param.get_value() } @@ -6720,8 +6723,8 @@ pub extern "C" fn canvas_native_webgl_get_uniform_location( name: *const c_char, state: *mut WebGLState, ) -> i32 { - assert!(state.is_null()); - assert!(name.is_null()); + assert!(!state.is_null()); + assert!(!name.is_null()); let name = unsafe { CStr::from_ptr(name) }; let name = name.to_string_lossy(); let state = unsafe { &mut *state }; @@ -6863,7 +6866,7 @@ pub extern "C" fn canvas_native_webgl_polygon_offset( units: f32, state: *mut WebGLState, ) { - assert!(state.is_null()); + assert!(!state.is_null()); let state = unsafe { &mut *state }; canvas_webgl::webgl::canvas_native_webgl_polygon_offset(factor, units, state.get_inner_mut()) } @@ -6880,8 +6883,8 @@ pub extern "C" fn canvas_native_webgl_read_pixels_u8( size: usize, state: *mut WebGLState, ) { - assert!(pixels.is_null()); - assert!(state.is_null()); + assert!(!pixels.is_null()); + assert!(!state.is_null()); let state = unsafe { &mut *state }; let pixels = unsafe { std::slice::from_raw_parts_mut(pixels, size) }; canvas_webgl::webgl::canvas_native_webgl_read_pixels_u8( @@ -6908,8 +6911,8 @@ pub extern "C" fn canvas_native_webgl_read_pixels_u16( size: usize, state: *mut WebGLState, ) { - assert!(state.is_null()); - assert!(pixels.is_null()); + assert!(!state.is_null()); + assert!(!pixels.is_null()); let state = unsafe { &mut *state }; let pixels = unsafe { std::slice::from_raw_parts_mut(pixels, size) }; canvas_webgl::webgl::canvas_native_webgl_read_pixels_u16( @@ -6936,8 +6939,8 @@ pub extern "C" fn canvas_native_webgl_read_pixels_f32( size: usize, state: *mut WebGLState, ) { - assert!(state.is_null()); - assert!(pixels.is_null()); + assert!(!state.is_null()); + assert!(!pixels.is_null()); let state = unsafe { &mut *state }; let pixels = unsafe { std::slice::from_raw_parts_mut(pixels, size) }; canvas_webgl::webgl::canvas_native_webgl_read_pixels_f32( @@ -6960,7 +6963,7 @@ pub extern "C" fn canvas_native_webgl_renderbuffer_storage( height: i32, state: *mut WebGLState, ) { - assert!(state.is_null()); + assert!(!state.is_null()); let state = unsafe { &mut *state }; canvas_webgl::webgl::canvas_native_webgl_renderbuffer_storage( target, @@ -6977,7 +6980,7 @@ pub extern "C" fn canvas_native_webgl_sample_coverage( invert: bool, state: *mut WebGLState, ) { - assert!(state.is_null()); + assert!(!state.is_null()); let state = unsafe { &mut *state }; canvas_webgl::webgl::canvas_native_webgl_sample_coverage(value, invert, state.get_inner_mut()) } @@ -6990,7 +6993,7 @@ pub extern "C" fn canvas_native_webgl_scissor( height: i32, state: *mut WebGLState, ) { - assert!(state.is_null()); + assert!(!state.is_null()); let state = unsafe { &mut *state }; canvas_webgl::webgl::canvas_native_webgl_scissor(x, y, width, height, state.get_inner_mut()) } @@ -7001,8 +7004,8 @@ pub extern "C" fn canvas_native_webgl_shader_source( source: *const c_char, state: *mut WebGLState, ) { - assert!(state.is_null()); - assert!(source.is_null()); + assert!(!state.is_null()); + assert!(!source.is_null()); let source = unsafe { CStr::from_ptr(source) }; let source = source.to_string_lossy(); let state = unsafe { &mut *state }; @@ -7020,7 +7023,7 @@ pub extern "C" fn canvas_native_webgl_stencil_func( mask: u32, state: *mut WebGLState, ) { - assert!(state.is_null()); + assert!(!state.is_null()); let state = unsafe { &mut *state }; canvas_webgl::webgl::canvas_native_webgl_stencil_func( func, @@ -7050,7 +7053,7 @@ pub extern "C" fn canvas_native_webgl_stencil_func_separate( #[no_mangle] pub extern "C" fn canvas_native_webgl_stencil_mask(mask: u32, state: *mut WebGLState) { - assert!(state.is_null()); + assert!(!state.is_null()); let state = unsafe { &mut *state }; canvas_webgl::webgl::canvas_native_webgl_stencil_mask(mask, state.get_inner_mut()) } @@ -7061,7 +7064,7 @@ pub extern "C" fn canvas_native_webgl_stencil_mask_separate( mask: u32, state: *mut WebGLState, ) { - assert!(state.is_null()); + assert!(!state.is_null()); let state = unsafe { &mut *state }; canvas_webgl::webgl::canvas_native_webgl_stencil_mask_separate( face, @@ -7077,7 +7080,7 @@ pub extern "C" fn canvas_native_webgl_stencil_op( zpass: u32, state: *mut WebGLState, ) { - assert!(state.is_null()); + assert!(!state.is_null()); let state = unsafe { &*state }; canvas_webgl::webgl::canvas_native_webgl_stencil_op(fail, zfail, zpass, state.get_inner()) } @@ -7120,7 +7123,8 @@ pub extern "C" fn canvas_native_webgl_tex_image2d_image_none( ) } -fn canvas_native_webgl_tex_image2d_canvas2d( +#[no_mangle] +pub extern "C" fn canvas_native_webgl_tex_image2d_canvas2d( target: i32, level: i32, internalformat: i32, @@ -7129,8 +7133,8 @@ fn canvas_native_webgl_tex_image2d_canvas2d( canvas: *mut CanvasRenderingContext2D, state: *mut WebGLState, ) { - assert!(state.is_null()); - assert!(state.is_null()); + assert!(!state.is_null()); + assert!(!state.is_null()); let canvas = unsafe { &mut *canvas }; let state = unsafe { &mut *state }; { @@ -7174,7 +7178,8 @@ fn canvas_native_webgl_tex_image2d_canvas2d( ); } -fn canvas_native_webgl_tex_image2d_webgl( +#[no_mangle] +pub extern "C" fn canvas_native_webgl_tex_image2d_webgl( target: i32, level: i32, _internalformat: i32, @@ -7183,8 +7188,8 @@ fn canvas_native_webgl_tex_image2d_webgl( webgl: *mut WebGLState, state: *mut WebGLState, ) { - assert!(state.is_null()); - assert!(webgl.is_null()); + assert!(!state.is_null()); + assert!(!webgl.is_null()); let state = unsafe { &mut *state }; let webgl = unsafe { &mut *webgl }; let mut pixels = @@ -7222,8 +7227,8 @@ pub extern "C" fn canvas_native_webgl_tex_image2d( size: usize, state: *mut WebGLState, ) { - assert!(buf.is_null()); - assert!(state.is_null()); + assert!(!buf.is_null()); + assert!(!state.is_null()); let state = unsafe { &mut *state }; let buf = unsafe { std::slice::from_raw_parts(buf, size) }; canvas_webgl::webgl::canvas_native_webgl_tex_image2d( @@ -7252,7 +7257,7 @@ pub extern "C" fn canvas_native_webgl_tex_image2d_none( image_type: i32, state: *mut WebGLState, ) { - assert!(state.is_null()); + assert!(!state.is_null()); let state = unsafe { &mut *state }; canvas_webgl::webgl::canvas_native_webgl_tex_image2d_none( target, @@ -7267,7 +7272,8 @@ pub extern "C" fn canvas_native_webgl_tex_image2d_none( ) } -fn canvas_native_webgl_tex_image2d_image_asset( +#[no_mangle] +pub extern "C" fn canvas_native_webgl_tex_image2d_image_asset( target: i32, level: i32, internalformat: i32, @@ -7276,8 +7282,8 @@ fn canvas_native_webgl_tex_image2d_image_asset( image_asset: *mut ImageAsset, state: *mut WebGLState, ) { - assert!(state.is_null()); - assert!(image_asset.is_null()); + assert!(!state.is_null()); + assert!(!image_asset.is_null()); let image_asset = unsafe { &*image_asset }; let state = unsafe { &mut *state }; canvas_webgl::webgl::canvas_native_webgl_tex_image2d_asset( @@ -7298,7 +7304,7 @@ pub extern "C" fn canvas_native_webgl_tex_parameterf( param: f32, state: *mut WebGLState, ) { - assert!(state.is_null()); + assert!(!state.is_null()); let state = unsafe { &*state }; canvas_webgl::webgl::canvas_native_webgl_tex_parameterf(target, pname, param, state.get_inner()) } @@ -7310,7 +7316,7 @@ pub extern "C" fn canvas_native_webgl_tex_parameteri( param: i32, state: *mut WebGLState, ) { - assert!(state.is_null()); + assert!(!state.is_null()); let state = unsafe { &*state }; canvas_webgl::webgl::canvas_native_webgl_tex_parameteri(target, pname, param, state.get_inner()) } @@ -7326,8 +7332,8 @@ pub extern "C" fn canvas_native_webgl_tex_sub_image2d_asset( asset: *mut ImageAsset, state: *mut WebGLState, ) { - assert!(state.is_null()); - assert!(asset.is_null()); + assert!(!state.is_null()); + assert!(!asset.is_null()); let asset = unsafe { &*asset }; let state = unsafe { &*state }; canvas_webgl::webgl::canvas_native_webgl_tex_sub_image2d_asset( @@ -7353,8 +7359,8 @@ pub extern "C" fn canvas_native_webgl_tex_sub_image2d_canvas2d( canvas: *mut CanvasRenderingContext2D, state: *mut WebGLState, ) { - assert!(state.is_null()); - assert!(canvas.is_null()); + assert!(!state.is_null()); + assert!(!canvas.is_null()); let state = unsafe { &mut *state }; let canvas = unsafe { &mut *canvas }; { @@ -7409,8 +7415,8 @@ pub extern "C" fn canvas_native_webgl_tex_sub_image2d_webgl( webgl: *mut WebGLState, state: *mut WebGLState, ) { - assert!(state.is_null()); - assert!(webgl.is_null()); + assert!(!state.is_null()); + assert!(!webgl.is_null()); let state = unsafe { &mut *state }; let webgl = unsafe { &mut *webgl }; { @@ -7455,8 +7461,8 @@ pub extern "C" fn canvas_native_webgl_tex_sub_image2d( size: usize, state: *mut WebGLState, ) { - assert!(state.is_null()); - assert!(buf.is_null()); + assert!(!state.is_null()); + assert!(!buf.is_null()); let buf = unsafe { std::slice::from_raw_parts(buf, size) }; let state = unsafe { &mut *state }; canvas_webgl::webgl::canvas_native_webgl_tex_sub_image2d( @@ -7475,7 +7481,7 @@ pub extern "C" fn canvas_native_webgl_tex_sub_image2d( #[no_mangle] pub extern "C" fn canvas_native_webgl_uniform1f(location: i32, v0: f32, state: *mut WebGLState) { - assert!(state.is_null()); + assert!(!state.is_null()); let state = unsafe { &*state }; canvas_webgl::webgl::canvas_native_webgl_uniform1f(location, v0, state.get_inner()) } @@ -7487,8 +7493,8 @@ pub extern "C" fn canvas_native_webgl_uniform1fv( size: usize, state: *mut WebGLState, ) { - assert!(state.is_null()); - assert!(value.is_null()); + assert!(!state.is_null()); + assert!(!value.is_null()); let value = unsafe { std::slice::from_raw_parts(value, size) }; let state = unsafe { &*state }; canvas_webgl::webgl::canvas_native_webgl_uniform1fv(location, value, state.get_inner()) @@ -7496,7 +7502,7 @@ pub extern "C" fn canvas_native_webgl_uniform1fv( #[no_mangle] pub extern "C" fn canvas_native_webgl_uniform1i(location: i32, v0: i32, state: *mut WebGLState) { - assert!(state.is_null()); + assert!(!state.is_null()); let state = unsafe { &*state }; canvas_webgl::webgl::canvas_native_webgl_uniform1i(location, v0, state.get_inner()) } @@ -7508,8 +7514,8 @@ pub extern "C" fn canvas_native_webgl_uniform1iv( size: usize, state: *mut WebGLState, ) { - assert!(state.is_null()); - assert!(value.is_null()); + assert!(!state.is_null()); + assert!(!value.is_null()); let value = unsafe { std::slice::from_raw_parts(value, size) }; let state = unsafe { &*state }; canvas_webgl::webgl::canvas_native_webgl_uniform1iv(location, value, state.get_inner()) @@ -7522,7 +7528,7 @@ pub extern "C" fn canvas_native_webgl_uniform2f( v1: f32, state: *mut WebGLState, ) { - assert!(state.is_null()); + assert!(!state.is_null()); let state = unsafe { &*state }; canvas_webgl::webgl::canvas_native_webgl_uniform2f(location, v0, v1, state.get_inner()) } @@ -7534,8 +7540,8 @@ pub extern "C" fn canvas_native_webgl_uniform2fv( size: usize, state: *mut WebGLState, ) { - assert!(state.is_null()); - assert!(value.is_null()); + assert!(!state.is_null()); + assert!(!value.is_null()); let value = unsafe { std::slice::from_raw_parts(value, size) }; let state = unsafe { &*state }; @@ -7549,7 +7555,7 @@ pub extern "C" fn canvas_native_webgl_uniform2i( v1: i32, state: *mut WebGLState, ) { - assert!(state.is_null()); + assert!(!state.is_null()); let state = unsafe { &*state }; canvas_webgl::webgl::canvas_native_webgl_uniform2i(location, v0, v1, state.get_inner()) } @@ -7561,8 +7567,8 @@ pub extern "C" fn canvas_native_webgl_uniform2iv( size: usize, state: *mut WebGLState, ) { - assert!(state.is_null()); - assert!(value.is_null()); + assert!(!state.is_null()); + assert!(!value.is_null()); let value = unsafe { std::slice::from_raw_parts(value, size) }; let state = unsafe { &*state }; canvas_webgl::webgl::canvas_native_webgl_uniform2iv(location, value, state.get_inner()) @@ -7587,8 +7593,8 @@ pub extern "C" fn canvas_native_webgl_uniform3fv( size: usize, state: *mut WebGLState, ) { - assert!(state.is_null()); - assert!(value.is_null()); + assert!(!state.is_null()); + assert!(!value.is_null()); let value = unsafe { std::slice::from_raw_parts(value, size) }; let state = unsafe { &*state }; canvas_webgl::webgl::canvas_native_webgl_uniform3fv(location, value, state.get_inner()) @@ -7613,8 +7619,8 @@ pub extern "C" fn canvas_native_webgl_uniform3iv( size: usize, state: *mut WebGLState, ) { - assert!(state.is_null()); - assert!(value.is_null()); + assert!(!state.is_null()); + assert!(!value.is_null()); let value = unsafe { std::slice::from_raw_parts(value, size) }; let state = unsafe { &*state }; canvas_webgl::webgl::canvas_native_webgl_uniform3iv(location, value, state.get_inner()) @@ -7640,8 +7646,8 @@ pub extern "C" fn canvas_native_webgl_uniform4fv( size: usize, state: *mut WebGLState, ) { - assert!(state.is_null()); - assert!(value.is_null()); + assert!(!state.is_null()); + assert!(!value.is_null()); let value = unsafe { std::slice::from_raw_parts(value, size) }; let state = unsafe { &mut *state }; canvas_webgl::webgl::canvas_native_webgl_uniform4fv(location, value, state.get_inner_mut()) @@ -7674,8 +7680,8 @@ pub extern "C" fn canvas_native_webgl_uniform4iv( size: usize, state: *mut WebGLState, ) { - assert!(state.is_null()); - assert!(value.is_null()); + assert!(!state.is_null()); + assert!(!value.is_null()); let value = unsafe { std::slice::from_raw_parts(value, size) }; let state = unsafe { &mut *state }; canvas_webgl::webgl::canvas_native_webgl_uniform4iv(location, value, state.get_inner_mut()) @@ -7689,7 +7695,7 @@ pub extern "C" fn canvas_native_webgl_uniform_matrix2fv( size: usize, state: *mut WebGLState, ) { - assert!(value.is_null()); + assert!(!value.is_null()); let value = unsafe { std::slice::from_raw_parts(value, size) }; let state = unsafe { &mut *state }; canvas_webgl::webgl::canvas_native_webgl_uniform_matrix2fv( @@ -7708,7 +7714,7 @@ pub extern "C" fn canvas_native_webgl_uniform_matrix3fv( size: usize, state: *mut WebGLState, ) { - assert!(value.is_null()); + assert!(!value.is_null()); let value = unsafe { std::slice::from_raw_parts(value, size) }; let state = unsafe { &mut *state }; canvas_webgl::webgl::canvas_native_webgl_uniform_matrix3fv( @@ -7727,7 +7733,7 @@ pub extern "C" fn canvas_native_webgl_uniform_matrix4fv( size: usize, state: *mut WebGLState, ) { - assert!(value.is_null()); + assert!(!value.is_null()); let value = unsafe { std::slice::from_raw_parts(value, size) }; let state = unsafe { &mut *state }; canvas_webgl::webgl::canvas_native_webgl_uniform_matrix4fv( @@ -7763,7 +7769,7 @@ pub extern "C" fn canvas_native_webgl_vertex_attrib1fv( size: usize, state: *mut WebGLState, ) { - assert!(value.is_null()); + assert!(!value.is_null()); let value = unsafe { std::slice::from_raw_parts(value, size) }; let state = unsafe { &mut *state }; canvas_webgl::webgl::canvas_native_webgl_vertex_attrib1fv(index, value, state.get_inner_mut()) @@ -7787,7 +7793,7 @@ pub extern "C" fn canvas_native_webgl_vertex_attrib2fv( size: usize, state: *mut WebGLState, ) { - assert!(value.is_null()); + assert!(!value.is_null()); let value = unsafe { std::slice::from_raw_parts(value, size) }; let state = unsafe { &mut *state }; canvas_webgl::webgl::canvas_native_webgl_vertex_attrib2fv(index, value, state.get_inner_mut()) @@ -7818,7 +7824,7 @@ pub extern "C" fn canvas_native_webgl_vertex_attrib3fv( size: usize, state: *mut WebGLState, ) { - assert!(value.is_null()); + assert!(!value.is_null()); let value = unsafe { std::slice::from_raw_parts(value, size) }; let state = unsafe { &mut *state }; canvas_webgl::webgl::canvas_native_webgl_vertex_attrib3fv(index, value, state.get_inner_mut()) @@ -7851,7 +7857,7 @@ pub extern "C" fn canvas_native_webgl_vertex_attrib4fv( size: usize, state: *mut WebGLState, ) { - assert!(value.is_null()); + assert!(!value.is_null()); let value = unsafe { std::slice::from_raw_parts(value, size) }; let state = unsafe { &mut *state }; canvas_webgl::webgl::canvas_native_webgl_vertex_attrib4fv(index, value, state.get_inner_mut()) @@ -7986,7 +7992,7 @@ pub extern "C" fn canvas_native_webgl2_bind_sampler( sampler: u32, state: *mut WebGLState, ) { - assert!(state.is_null()); + assert!(!state.is_null()); let state = unsafe { &mut *state }; canvas_webgl::webgl2::canvas_native_webgl2_bind_sampler(unit, sampler, state.get_inner_mut()) } @@ -7997,7 +8003,7 @@ pub extern "C" fn canvas_native_webgl2_bind_transform_feedback( transform_feedback: u32, state: *mut WebGLState, ) { - assert!(state.is_null()); + assert!(!state.is_null()); let state = unsafe { &mut *state }; canvas_webgl::webgl2::canvas_native_webgl2_bind_sampler( target, @@ -8011,7 +8017,7 @@ pub extern "C" fn canvas_native_webgl2_bind_vertex_array( vertex_array: u32, state: *mut WebGLState, ) { - assert!(state.is_null()); + assert!(!state.is_null()); let state = unsafe { &mut *state }; canvas_webgl::webgl2::canvas_native_webgl2_bind_vertex_array( vertex_array, @@ -8033,7 +8039,7 @@ pub extern "C" fn canvas_native_webgl2_blit_framebuffer( filter: u32, state: *mut WebGLState, ) { - assert!(state.is_null()); + assert!(!state.is_null()); let state = unsafe { &mut *state }; canvas_webgl::webgl2::canvas_native_webgl2_blit_framebuffer( src_x0, @@ -8058,7 +8064,7 @@ pub extern "C" fn canvas_native_webgl2_clear_bufferfi( stencil: i32, state: *mut WebGLState, ) { - assert!(state.is_null()); + assert!(!state.is_null()); let state = unsafe { &mut *state }; canvas_webgl::webgl2::canvas_native_webgl2_clear_bufferfi( buffer, @@ -8077,8 +8083,8 @@ pub extern "C" fn canvas_native_webgl2_clear_bufferfv( size: usize, state: *mut WebGLState, ) { - assert!(state.is_null()); - assert!(values.is_null()); + assert!(!state.is_null()); + assert!(!values.is_null()); let values = unsafe { std::slice::from_raw_parts(values, size) }; let state = unsafe { &mut *state }; canvas_webgl::webgl2::canvas_native_webgl2_clear_bufferfv( @@ -8097,8 +8103,8 @@ pub extern "C" fn canvas_native_webgl2_clear_bufferiv( size: usize, state: *mut WebGLState, ) { - assert!(state.is_null()); - assert!(values.is_null()); + assert!(!state.is_null()); + assert!(!values.is_null()); let values = unsafe { std::slice::from_raw_parts(values, size) }; let state = unsafe { &mut *state }; canvas_webgl::webgl2::canvas_native_webgl2_clear_bufferiv( @@ -8117,8 +8123,8 @@ pub extern "C" fn canvas_native_webgl2_clear_bufferuiv( size: usize, state: *mut WebGLState, ) { - assert!(state.is_null()); - assert!(values.is_null()); + assert!(!state.is_null()); + assert!(!values.is_null()); let values = unsafe { std::slice::from_raw_parts(values, size) }; let state = unsafe { &mut *state }; canvas_webgl::webgl2::canvas_native_webgl2_clear_bufferuiv( @@ -8194,7 +8200,7 @@ pub extern "C" fn canvas_native_webgl2_compressed_tex_sub_image3d( src_length_override: usize, state: *mut WebGLState, ) { - assert!(src.is_null()); + assert!(!src.is_null()); let src = unsafe { std::slice::from_raw_parts(src, size) }; let state = unsafe { &mut *state }; canvas_webgl::webgl2::canvas_native_webgl2_compressed_tex_sub_image3d( @@ -8361,8 +8367,8 @@ pub extern "C" fn canvas_native_webgl2_draw_buffers( size: usize, state: *mut WebGLState, ) { - assert!(state.is_null()); - assert!(buffers.is_null()); + assert!(!state.is_null()); + assert!(!buffers.is_null()); let buffers = unsafe { std::slice::from_raw_parts(buffers, size) }; let state = unsafe { &mut *state }; canvas_webgl::webgl2::canvas_native_webgl2_draw_buffers(buffers, state.get_inner_mut()) @@ -8502,8 +8508,8 @@ pub extern "C" fn canvas_native_webgl2_get_active_uniforms( pname: u32, state: *mut WebGLState, ) -> *mut WebGLResult { - assert!(state.is_null()); - assert!(uniform_indices.is_null()); + assert!(!state.is_null()); + assert!(!uniform_indices.is_null()); let uniform_indices = unsafe { std::slice::from_raw_parts(uniform_indices, size) }; let state = unsafe { &mut *state }; Box::into_raw(Box::new(WebGLResult( @@ -8526,8 +8532,8 @@ pub extern "C" fn canvas_native_webgl2_get_buffer_sub_data( length: usize, state: *mut WebGLState, ) { - assert!(state.is_null()); - assert!(dst_data.is_null()); + assert!(!state.is_null()); + assert!(!dst_data.is_null()); let state = unsafe { &mut *state }; let dst_data = unsafe { std::slice::from_raw_parts_mut(dst_data, size) }; canvas_webgl::webgl2::canvas_native_webgl2_get_buffer_sub_data( @@ -8546,7 +8552,7 @@ pub extern "C" fn canvas_native_webgl2_get_frag_data_location( name: *const c_char, state: *mut WebGLState, ) -> i32 { - assert!(name.is_null()); + assert!(!name.is_null()); let name = unsafe { CStr::from_ptr(name) }; let name = name.to_string_lossy(); let state = unsafe { &mut *state }; @@ -8652,8 +8658,8 @@ pub extern "C" fn canvas_native_webgl2_get_sync_parameter( pname: u32, state: *mut WebGLState, ) -> *mut WebGLResult { - assert!(sync.is_null()); - assert!(state.is_null()); + assert!(!sync.is_null()); + assert!(!state.is_null()); let sync = unsafe { &*sync }; let state = unsafe { &mut *state }; Box::into_raw(Box::new(WebGLResult( @@ -8687,7 +8693,7 @@ pub extern "C" fn canvas_native_webgl2_get_uniform_block_index( uniform_block_name: *const c_char, state: *mut WebGLState, ) -> u32 { - assert!(uniform_block_name.is_null()); + assert!(!uniform_block_name.is_null()); let uniform_block_name = unsafe { CStr::from_ptr(uniform_block_name) }; let uniform_block_name = uniform_block_name.to_string_lossy(); let state = unsafe { &mut *state }; @@ -8705,8 +8711,8 @@ pub extern "C" fn canvas_native_webgl2_get_uniform_indices( size: usize, state: *mut WebGLState, ) -> *mut U32Buffer { - assert!(state.is_null()); - assert!(uniform_names.is_null()); + assert!(!state.is_null()); + assert!(!uniform_names.is_null()); let state = unsafe { &mut *state }; Box::into_raw(Box::new(U32Buffer::from( canvas_webgl::webgl2::canvas_native_webgl2_get_uniform_indices_raw( @@ -8725,8 +8731,8 @@ pub extern "C" fn canvas_native_webgl2_invalidate_framebuffer( size: usize, state: *mut WebGLState, ) { - assert!(state.is_null()); - assert!(attachments.is_null()); + assert!(!state.is_null()); + assert!(!attachments.is_null()); let attachments = unsafe { std::slice::from_raw_parts(attachments, size) }; let state = unsafe { &mut *state }; canvas_webgl::webgl2::canvas_native_webgl2_invalidate_framebuffer( @@ -8747,8 +8753,8 @@ pub extern "C" fn canvas_native_webgl2_invalidate_sub_framebuffer( height: i32, state: *mut WebGLState, ) { - assert!(state.is_null()); - assert!(attachments.is_null()); + assert!(!state.is_null()); + assert!(!attachments.is_null()); let attachments = unsafe { std::slice::from_raw_parts(attachments, size) }; let state = unsafe { &mut *state }; canvas_webgl::webgl2::canvas_native_webgl2_invalidate_sub_framebuffer( @@ -8946,7 +8952,7 @@ pub extern "C" fn canvas_native_webgl2_tex_image3d( size: usize, state: *mut WebGLState, ) { - assert!(buf.is_null()); + assert!(!buf.is_null()); let buf = unsafe { std::slice::from_raw_parts(buf, size) }; let state = unsafe { &mut *state }; canvas_webgl::webgl2::canvas_native_webgl2_tex_image3d( @@ -8980,7 +8986,7 @@ pub extern "C" fn canvas_native_webgl2_tex_image3d_offset( offset: usize, state: *mut WebGLState, ) { - assert!(buf.is_null()); + assert!(!buf.is_null()); let buf = unsafe { std::slice::from_raw_parts(buf, size) }; let state = unsafe { &mut *state }; canvas_webgl::webgl2::canvas_native_webgl2_tex_image3d_offset( @@ -9089,7 +9095,7 @@ pub extern "C" fn canvas_native_webgl2_tex_sub_image3d( size: usize, state: *mut WebGLState, ) { - assert!(buf.is_null()); + assert!(!buf.is_null()); let buf = unsafe { std::slice::from_raw_parts(buf, size) }; let state = unsafe { &mut *state }; canvas_webgl::webgl2::canvas_native_webgl2_tex_sub_image3d( @@ -9157,7 +9163,7 @@ pub extern "C" fn canvas_native_webgl2_tex_sub_image3d_offset( offset: usize, state: *mut WebGLState, ) { - assert!(buf.is_null()); + assert!(!buf.is_null()); let buf = unsafe { std::slice::from_raw_parts(buf, size) }; let state = unsafe { &mut *state }; canvas_webgl::webgl2::canvas_native_webgl2_tex_sub_image3d_offset( @@ -9185,8 +9191,8 @@ pub extern "C" fn canvas_native_webgl2_transform_feedback_varyings( buffer_mode: u32, state: *mut WebGLState, ) { - assert!(state.is_null()); - assert!(varyings.is_null()); + assert!(!state.is_null()); + assert!(!varyings.is_null()); let state = unsafe { &mut *state }; canvas_webgl::webgl2::canvas_native_webgl2_transform_feedback_varyings_raw( program, @@ -9210,8 +9216,8 @@ pub extern "C" fn canvas_native_webgl2_uniform1uiv( size: usize, state: *mut WebGLState, ) { - assert!(state.is_null()); - assert!(data.is_null()); + assert!(!state.is_null()); + assert!(!data.is_null()); let data = unsafe { std::slice::from_raw_parts(data, size) }; let state = unsafe { &mut *state }; canvas_webgl::webgl2::canvas_native_webgl2_uniform1uiv(location, data, state.get_inner_mut()) @@ -9235,8 +9241,8 @@ pub extern "C" fn canvas_native_webgl2_uniform2uiv( size: usize, state: *mut WebGLState, ) { - assert!(state.is_null()); - assert!(data.is_null()); + assert!(!state.is_null()); + assert!(!data.is_null()); let data = unsafe { std::slice::from_raw_parts(data, size) }; let state = unsafe { &mut *state }; canvas_webgl::webgl2::canvas_native_webgl2_uniform2uiv(location, data, state.get_inner_mut()) @@ -9267,8 +9273,8 @@ pub extern "C" fn canvas_native_webgl2_uniform3uiv( size: usize, state: *mut WebGLState, ) { - assert!(state.is_null()); - assert!(data.is_null()); + assert!(!state.is_null()); + assert!(!data.is_null()); let data = unsafe { std::slice::from_raw_parts(data, size) }; let state = unsafe { &mut *state }; canvas_webgl::webgl2::canvas_native_webgl2_uniform3uiv(location, data, state.get_inner_mut()) @@ -9301,8 +9307,8 @@ pub extern "C" fn canvas_native_webgl2_uniform4uiv( size: usize, state: *mut WebGLState, ) { - assert!(state.is_null()); - assert!(data.is_null()); + assert!(!state.is_null()); + assert!(!data.is_null()); let data = unsafe { std::slice::from_raw_parts(data, size) }; let state = unsafe { &mut *state }; canvas_webgl::webgl2::canvas_native_webgl2_uniform4uiv(location, data, state.get_inner_mut()) @@ -9332,7 +9338,7 @@ pub extern "C" fn canvas_native_webgl2_uniform_matrix2x3fv( size: usize, state: *mut WebGLState, ) { - assert!(data.is_null()); + assert!(!data.is_null()); let data = unsafe { std::slice::from_raw_parts(data, size) }; let state = unsafe { &mut *state }; canvas_webgl::webgl2::canvas_native_webgl2_uniform_matrix2x3fv( @@ -9351,7 +9357,7 @@ pub extern "C" fn canvas_native_webgl2_uniform_matrix2x4fv( size: usize, state: *mut WebGLState, ) { - assert!(data.is_null()); + assert!(!data.is_null()); let data = unsafe { std::slice::from_raw_parts(data, size) }; let state = unsafe { &mut *state }; canvas_webgl::webgl2::canvas_native_webgl2_uniform_matrix2x4fv( @@ -9370,7 +9376,7 @@ pub extern "C" fn canvas_native_webgl2_uniform_matrix3x2fv( size: usize, state: *mut WebGLState, ) { - assert!(data.is_null()); + assert!(!data.is_null()); let data = unsafe { std::slice::from_raw_parts(data, size) }; let state = unsafe { &mut *state }; canvas_webgl::webgl2::canvas_native_webgl2_uniform_matrix3x2fv( @@ -9389,7 +9395,7 @@ pub extern "C" fn canvas_native_webgl2_uniform_matrix3x4fv( size: usize, state: *mut WebGLState, ) { - assert!(data.is_null()); + assert!(!data.is_null()); let data = unsafe { std::slice::from_raw_parts(data, size) }; let state = unsafe { &mut *state }; canvas_webgl::webgl2::canvas_native_webgl2_uniform_matrix3x4fv( @@ -9408,7 +9414,7 @@ pub extern "C" fn canvas_native_webgl2_uniform_matrix4x2fv( size: usize, state: *mut WebGLState, ) { - assert!(data.is_null()); + assert!(!data.is_null()); let data = unsafe { std::slice::from_raw_parts(data, size) }; let state = unsafe { &mut *state }; canvas_webgl::webgl2::canvas_native_webgl2_uniform_matrix4x2fv( @@ -9427,7 +9433,7 @@ pub extern "C" fn canvas_native_webgl2_uniform_matrix4x3fv( size: usize, state: *mut WebGLState, ) { - assert!(data.is_null()); + assert!(!data.is_null()); let data = unsafe { std::slice::from_raw_parts(data, size) }; let state = unsafe { &mut *state }; canvas_webgl::webgl2::canvas_native_webgl2_uniform_matrix4x3fv( @@ -9479,8 +9485,8 @@ pub extern "C" fn canvas_native_webgl2_vertex_attrib_i4iv( size: usize, state: *mut WebGLState, ) { - assert!(state.is_null()); - assert!(value.is_null()); + assert!(!state.is_null()); + assert!(!value.is_null()); let value = unsafe { std::slice::from_raw_parts(value, size) }; let state = unsafe { &mut *state }; canvas_webgl::webgl2::canvas_native_webgl2_vertex_attrib_i4iv( @@ -9517,8 +9523,8 @@ pub extern "C" fn canvas_native_webgl2_vertex_attrib_i4uiv( size: usize, state: *mut WebGLState, ) { - assert!(state.is_null()); - assert!(value.is_null()); + assert!(!state.is_null()); + assert!(!value.is_null()); let value = unsafe { std::slice::from_raw_parts(value, size) }; let state = unsafe { &mut *state }; canvas_webgl::webgl2::canvas_native_webgl2_vertex_attrib_i4uiv( diff --git a/tools/demo/canvas/index.ts b/tools/demo/canvas/index.ts index 0e13e2bd..fabcc542 100644 --- a/tools/demo/canvas/index.ts +++ b/tools/demo/canvas/index.ts @@ -1,6 +1,5 @@ import { DemoSharedBase } from '../utils'; import { ImageSource, ObservableArray, Screen, Color, Application, knownFolders, path as filePath } from '@nativescript/core'; -import Chart from 'chart.js'; let Matter; import { Canvas } from '@nativescript/canvas'; @@ -52,13 +51,14 @@ import { } from './canvas2d'; //const CanvasWorker = require('nativescript-worker-loader!./canvas.worker.js'); -import Vex from 'vexflow'; import { handleVideo, cancelInteractiveCube, cancelMain, cubeRotation, cubeRotationRotation, drawElements, drawModes, imageFilter, interactiveCube, main, textures, points, triangle, scaleTriangle } from './webgl'; import { cancelEnvironmentMap, cancelFog, draw_image_space, draw_instanced, environmentMap, fog } from './webgl2'; // declare var com, java; let zen3d; import * as Svg from '@nativescript/canvas/SVG'; import { issue54 } from './issues'; +var Chart; +var Vex; export class DemoSharedCanvas extends DemoSharedBase { private canvas: any; private svg: Svg.Svg; @@ -66,6 +66,12 @@ export class DemoSharedCanvas extends DemoSharedBase { private svg3: Svg.Svg; private svg4: Svg.Svg; + constructor() { + super(); + Chart = require('chart.js'); + Vex = require('vexflow'); + } + canvasLoaded(args) { this.canvas = args.object; console.log('canvas ready'); @@ -504,7 +510,7 @@ export class DemoSharedCanvas extends DemoSharedBase { // Unmoved square ctx.fillStyle = 'gray'; ctx.fillRect(0, 0, 80, 80); */ - filterBlur(this.canvas); + //filterBlur(this.canvas); //handleVideo(this.canvas); // const worker = new CanvasWorker(); // canvas.parent.on(GestureTypes.touch as any, (args: TouchGestureEventData) => { @@ -606,7 +612,7 @@ export class DemoSharedCanvas extends DemoSharedBase { //rainbowOctopus(this.canvas); //particlesColor(this.canvas); //cloth(this.canvas); - //touchParticles(this.canvas); + touchParticles(this.canvas); //swarm(this.canvas); //textures(this.canvas) //drawModes(this.canvas,'triangles'); @@ -1741,21 +1747,21 @@ export class DemoSharedCanvas extends DemoSharedBase { var moon = new global.ImageAsset(); var earth = new global.ImageAsset(); - await Promise.all([sun.fromUrl('https://github.com/mdn/content/raw/main/files/en-us/web/api/canvas_api/tutorial/basic_animations/canvas_sun.png'), moon.fromUrl('https://github.com/mdn/content/raw/main/files/en-us/web/api/canvas_api/tutorial/basic_animations/canvas_moon.png'), earth.fromUrl('https://github.com/mdn/content/raw/main/files/en-us/web/api/canvas_api/tutorial/basic_animations/canvas_earth.png')]); + //await Promise.all([sun.fromUrl('https://github.com/mdn/content/raw/main/files/en-us/web/api/canvas_api/tutorial/basic_animations/canvas_sun.png'), moon.fromUrl('https://github.com/mdn/content/raw/main/files/en-us/web/api/canvas_api/tutorial/basic_animations/canvas_moon.png'), earth.fromUrl('https://github.com/mdn/content/raw/main/files/en-us/web/api/canvas_api/tutorial/basic_animations/canvas_earth.png')]); // sun.fromUrlSync('https://github.com/mdn/content/raw/main/files/en-us/web/api/canvas_api/tutorial/basic_animations/canvas_sun.png'); // moon.fromUrlSync('https://github.com/mdn/content/raw/main/files/en-us/web/api/canvas_api/tutorial/basic_animations/canvas_moon.png'); // earth.fromUrlSync('https://github.com/mdn/content/raw/main/files/en-us/web/api/canvas_api/tutorial/basic_animations/canvas_earth.png'); - // sun.loadFromUrl('https://mdn.mozillademos.org/files/1456/Canvas_sun.png') - // .then(done =>{ - // console.log('sun', done); - // return moon.loadFromUrl('https://mdn.mozillademos.org/files/1443/Canvas_moon.png') - // }).then(done =>{ - // console.log('moon', done); - // return earth.loadFromUrl('https://mdn.mozillademos.org/files/1429/Canvas_earth.png'); - // }).then(done =>{ - // console.log('earth', done); - // }) + sun.fromUrl('https://github.com/mdn/content/raw/main/files/en-us/web/api/canvas_api/tutorial/basic_animations/canvas_sun.png') + .then(done =>{ + console.log('sun', done); + return moon.fromUrl('https://github.com/mdn/content/raw/main/files/en-us/web/api/canvas_api/tutorial/basic_animations/canvas_moon.png') + }).then(done =>{ + console.log('moon', done); + return earth.fromUrl('https://github.com/mdn/content/raw/main/files/en-us/web/api/canvas_api/tutorial/basic_animations/canvas_earth.png'); + }).then(done =>{ + console.log('earth', done); + }) //console.log(sun.width, moon.width, earth.width); var ctx = canvas.getContext('2d') as CanvasRenderingContext2D;