@nativescript/canvas 2.0.0-rc.2 → 2.0.0-rc.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (125) hide show
  1. package/Canvas/common.d.ts +13 -6
  2. package/Canvas/common.js +257 -206
  3. package/Canvas/common.js.map +1 -1
  4. package/Canvas/index.android.d.ts +2 -0
  5. package/Canvas/index.android.js +23 -4
  6. package/Canvas/index.android.js.map +1 -1
  7. package/Canvas/index.d.ts +3 -0
  8. package/Canvas/index.ios.d.ts +2 -0
  9. package/Canvas/index.ios.js +16 -3
  10. package/Canvas/index.ios.js.map +1 -1
  11. package/Canvas/utils.js +2 -1
  12. package/Canvas/utils.js.map +1 -1
  13. package/Canvas2D/CanvasRenderingContext2D/index.d.ts +1 -0
  14. package/Canvas2D/CanvasRenderingContext2D/index.js +158 -6
  15. package/Canvas2D/CanvasRenderingContext2D/index.js.map +1 -1
  16. package/Canvas2D/DOMMatrix/index.js +280 -2
  17. package/Canvas2D/DOMMatrix/index.js.map +1 -1
  18. package/Canvas2D/Path2D/index.js.map +1 -1
  19. package/Fonts/FontFace.android.js +7 -3
  20. package/Fonts/FontFace.android.js.map +1 -1
  21. package/Fonts/FontFace.ios.d.ts +1 -0
  22. package/Fonts/FontFace.ios.js +10 -3
  23. package/Fonts/FontFace.ios.js.map +1 -1
  24. package/TextDecoder/index.d.ts +1 -0
  25. package/TextDecoder/index.js +17 -0
  26. package/TextDecoder/index.js.map +1 -1
  27. package/WebGL/WebGLRenderingContext/index.js +0 -1
  28. package/WebGL/WebGLRenderingContext/index.js.map +1 -1
  29. package/WebGPU/GPUCanvasContext.d.ts +0 -1
  30. package/WebGPU/GPUCanvasContext.js +6 -18
  31. package/WebGPU/GPUCanvasContext.js.map +1 -1
  32. package/WebGPU/GPUCommandEncoder.d.ts +1 -1
  33. package/WebGPU/GPUCommandEncoder.js +1 -1
  34. package/WebGPU/GPUCommandEncoder.js.map +1 -1
  35. package/WebGPU/GPUCompilationInfo.d.ts +10 -0
  36. package/WebGPU/GPUCompilationInfo.js +20 -0
  37. package/WebGPU/GPUCompilationInfo.js.map +1 -0
  38. package/WebGPU/GPUCompilationMessage.d.ts +11 -0
  39. package/WebGPU/GPUCompilationMessage.js +30 -0
  40. package/WebGPU/GPUCompilationMessage.js.map +1 -0
  41. package/WebGPU/GPUDevice.d.ts +2 -2
  42. package/WebGPU/GPUDevice.js.map +1 -1
  43. package/WebGPU/GPUQueue.js +1 -4
  44. package/WebGPU/GPUQueue.js.map +1 -1
  45. package/WebGPU/GPURenderPassEncoder.d.ts +1 -1
  46. package/WebGPU/GPURenderPassEncoder.js +2 -2
  47. package/WebGPU/GPURenderPassEncoder.js.map +1 -1
  48. package/WebGPU/GPUShaderModule.d.ts +2 -0
  49. package/WebGPU/GPUShaderModule.js +10 -0
  50. package/WebGPU/GPUShaderModule.js.map +1 -1
  51. package/WebGPU/Interfaces.d.ts +1 -0
  52. package/WebGPU/Types.d.ts +3 -3
  53. package/WebGPU/Utils.d.ts +1 -1
  54. package/WebGPU/Utils.js +67 -93
  55. package/WebGPU/Utils.js.map +1 -1
  56. package/WebGPU/index.d.ts +2 -0
  57. package/WebGPU/index.js +2 -0
  58. package/WebGPU/index.js.map +1 -1
  59. package/angular/fesm2022/nativescript-canvas-angular.mjs +5 -5
  60. package/angular/package.json +0 -2
  61. package/helpers.d.ts +3 -0
  62. package/helpers.js +9 -0
  63. package/helpers.js.map +1 -1
  64. package/index.js +6 -1
  65. package/index.js.map +1 -1
  66. package/package.json +1 -1
  67. package/platforms/android/canvas-release.aar +0 -0
  68. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/CanvasNative +0 -0
  69. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Headers/CanvasNative-Swift.h +10 -5
  70. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Headers/canvas_native.h +294 -47
  71. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Info.plist +0 -0
  72. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Modules/CanvasNative.swiftmodule/Project/arm64-apple-ios.swiftsourceinfo +0 -0
  73. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios.abi.json +11317 -11881
  74. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios.private.swiftinterface +55 -49
  75. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios.swiftdoc +0 -0
  76. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios.swiftinterface +55 -49
  77. package/platforms/ios/CanvasNative.xcframework/ios-arm64/dSYMs/CanvasNative.framework.dSYM/Contents/Resources/DWARF/CanvasNative +0 -0
  78. package/platforms/ios/CanvasNative.xcframework/ios-arm64/dSYMs/CanvasNative.framework.dSYM/Contents/Resources/Relocations/aarch64/CanvasNative.yml +954 -994
  79. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/CanvasNative +0 -0
  80. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Headers/CanvasNative-Swift.h +20 -10
  81. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Headers/canvas_native.h +294 -47
  82. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Info.plist +0 -0
  83. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/Project/arm64-apple-ios-simulator.swiftsourceinfo +0 -0
  84. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/Project/x86_64-apple-ios-simulator.swiftsourceinfo +0 -0
  85. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios-simulator.abi.json +11317 -11881
  86. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios-simulator.private.swiftinterface +55 -49
  87. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios-simulator.swiftdoc +0 -0
  88. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios-simulator.swiftinterface +55 -49
  89. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/x86_64-apple-ios-simulator.abi.json +11317 -11881
  90. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/x86_64-apple-ios-simulator.private.swiftinterface +55 -49
  91. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/x86_64-apple-ios-simulator.swiftdoc +0 -0
  92. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/x86_64-apple-ios-simulator.swiftinterface +55 -49
  93. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/_CodeSignature/CodeResources +29 -29
  94. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/dSYMs/CanvasNative.framework.dSYM/Contents/Resources/DWARF/CanvasNative +0 -0
  95. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/dSYMs/CanvasNative.framework.dSYM/Contents/Resources/Relocations/aarch64/CanvasNative.yml +955 -993
  96. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/dSYMs/CanvasNative.framework.dSYM/Contents/Resources/Relocations/x86_64/CanvasNative.yml +824 -1037
  97. package/platforms/ios/src/cpp/Caches.h +6 -0
  98. package/platforms/ios/src/cpp/CanvasJSIModule.cpp +1172 -1011
  99. package/platforms/ios/src/cpp/CanvasJSIModule.h +6 -0
  100. package/platforms/ios/src/cpp/Helpers.h +23 -2
  101. package/platforms/ios/src/cpp/NativeType.h +3 -1
  102. package/platforms/ios/src/cpp/OnRafCallback.cpp +15 -10
  103. package/platforms/ios/src/cpp/OnRafCallback.h +1 -0
  104. package/platforms/ios/src/cpp/PromiseCallback.h +42 -20
  105. package/platforms/ios/src/cpp/TextDecoderImpl.cpp +142 -0
  106. package/platforms/ios/src/cpp/TextDecoderImpl.h +2 -0
  107. package/platforms/ios/src/cpp/canvas2d/CanvasRenderingContext2DImpl.cpp +59 -15
  108. package/platforms/ios/src/cpp/canvas2d/Path2D.cpp +1 -1
  109. package/platforms/ios/src/cpp/webgpu/GPUAdapterImpl.cpp +4 -8
  110. package/platforms/ios/src/cpp/webgpu/GPUCanvasContextImpl.cpp +431 -326
  111. package/platforms/ios/src/cpp/webgpu/GPUCanvasContextImpl.h +98 -42
  112. package/platforms/ios/src/cpp/webgpu/GPUCommandEncoderImpl.cpp +1150 -1144
  113. package/platforms/ios/src/cpp/webgpu/GPUCompilationInfoImpl.cpp +88 -0
  114. package/platforms/ios/src/cpp/webgpu/GPUCompilationInfoImpl.h +49 -0
  115. package/platforms/ios/src/cpp/webgpu/GPUCompilationMessageImpl.cpp +193 -0
  116. package/platforms/ios/src/cpp/webgpu/GPUCompilationMessageImpl.h +64 -0
  117. package/platforms/ios/src/cpp/webgpu/GPUDeviceImpl.cpp +69 -34
  118. package/platforms/ios/src/cpp/webgpu/GPUQueueImpl.cpp +45 -18
  119. package/platforms/ios/src/cpp/webgpu/GPURenderPassEncoderImpl.cpp +22 -19
  120. package/platforms/ios/src/cpp/webgpu/GPUShaderModuleImpl.cpp +23 -0
  121. package/platforms/ios/src/cpp/webgpu/GPUShaderModuleImpl.h +2 -0
  122. package/platforms/ios/src/cpp/webgpu/GPUTextureImpl.cpp +11 -0
  123. package/platforms/ios/src/cpp/webgpu/GPUUtils.h +25 -15
  124. package/angular/esm2022/index.mjs +0 -17
  125. package/angular/esm2022/nativescript-canvas-angular.mjs +0 -5
@@ -48,5 +48,11 @@ public:
48
48
  static void AddFontFamily(const v8::FunctionCallbackInfo<v8::Value> &args);
49
49
 
50
50
  static void AddFontData(const v8::FunctionCallbackInfo<v8::Value> &args);
51
+
52
+ static void Base64Encode(const v8::FunctionCallbackInfo<v8::Value> &args);
53
+
54
+ static void Base64Decode(const v8::FunctionCallbackInfo<v8::Value> &args);
55
+
56
+ static void Base64DecodeAsync(const v8::FunctionCallbackInfo<v8::Value> &args);
51
57
  };
52
58
 
@@ -112,7 +112,6 @@ ConvertFromV8String(v8::Isolate *isolate, const v8::Local<v8::Value> &value) {
112
112
  return {*result};
113
113
  }
114
114
 
115
-
116
115
  inline static std::string_view
117
116
  ConvertFromV8StringView(v8::Isolate *isolate, const v8::Local<v8::Value> &value) {
118
117
  if (value.IsEmpty()) {
@@ -121,7 +120,29 @@ ConvertFromV8StringView(v8::Isolate *isolate, const v8::Local<v8::Value> &value)
121
120
 
122
121
  if (value->IsStringObject()) {
123
122
  v8::Local<v8::String> obj = value.As<v8::StringObject>()->ValueOf();
124
- return ConvertFromV8String(isolate, obj);
123
+ return ConvertFromV8StringView(isolate, obj);
124
+ }
125
+
126
+ v8::String::Utf8Value result(isolate, value);
127
+
128
+ const char *val = *result;
129
+
130
+ if (val == nullptr) {
131
+ return {};
132
+ }
133
+
134
+ return {*result};
135
+ }
136
+
137
+ inline static std::string_view
138
+ ConvertFromV8StringViewValue(v8::Isolate *isolate, v8::Local<v8::Value> value) {
139
+ if (value.IsEmpty()) {
140
+ return {};
141
+ }
142
+
143
+ if (value->IsStringObject()) {
144
+ v8::Local<v8::String> obj = value.As<v8::StringObject>()->ValueOf();
145
+ return ConvertFromV8StringViewValue(isolate, obj);
125
146
  }
126
147
 
127
148
  v8::String::Utf8Value result(isolate, value);
@@ -81,7 +81,9 @@ enum class NativeType {
81
81
  GPUComputePipeline,
82
82
  GPUSampler,
83
83
  GPURenderBundleEncoder,
84
- GPURenderBundle
84
+ GPURenderBundle,
85
+ GPUCompilationInfo,
86
+ GPUCompilationMessage
85
87
  };
86
88
 
87
89
  #endif //CANVAS_ANDROID_NATIVETYPE_H
@@ -5,21 +5,26 @@
5
5
  #include "OnRafCallback.h"
6
6
  #include "canvas2d/CanvasRenderingContext2DImpl.h"
7
7
  #include "webgl/WebGLRenderingContextBase.h"
8
+ #include "webgpu/GPUCanvasContextImpl.h"
8
9
 
9
10
  OnRafCallback::OnRafCallback(intptr_t context, uint32_t version) : context_(context),
10
- version_(version) {}
11
+ version_(version) {}
11
12
 
12
13
  void OnRafCallback::OnFrame(int64_t ts) const {
13
- if (this->version_ == 0) {
14
- CanvasRenderingContext2DImpl::Flush(this->context_);
15
- }
16
-
17
- if (this->version_ == 1 || this->version_ == 2) {
18
- WebGLRenderingContextBase::Flush(this->context_);
19
- }
14
+ if (this->version_ == 0) {
15
+ CanvasRenderingContext2DImpl::Flush(this->context_);
16
+ }
17
+
18
+ if (this->version_ == 1 || this->version_ == 2) {
19
+ WebGLRenderingContextBase::Flush(this->context_);
20
+ }
21
+
22
+ if(this->version_ == 3){
23
+ GPUCanvasContextImpl::Flush(this->context_);
24
+ }
20
25
  }
21
26
 
22
27
  void OnRafCallbackOnFrame(intptr_t callback, int64_t ts) {
23
- auto ptr = reinterpret_cast<OnRafCallback *>(reinterpret_cast<intptr_t *>(callback));
24
- ptr->OnFrame(ts);
28
+ auto ptr = reinterpret_cast<OnRafCallback *>(reinterpret_cast<intptr_t *>(callback));
29
+ ptr->OnFrame(ts);
25
30
  }
@@ -11,6 +11,7 @@ class OnRafCallback {
11
11
  // 0 2d
12
12
  // 1 gl
13
13
  // 2 gl2
14
+ // 3 gpu
14
15
  public:
15
16
  OnRafCallback(intptr_t context, uint32_t version);
16
17
 
@@ -35,6 +35,7 @@ struct PromiseCallback {
35
35
  CompleteCallback completeCallbackWrapper_;
36
36
  bool isPrepared_ = false;
37
37
  void* data;
38
+ mutable std::mutex mtx;
38
39
 
39
40
  Inner(v8::Isolate *isolate, v8::Local<v8::Promise::Resolver> callback,
40
41
  CompleteCallback completeCallback) : isolate_(isolate),
@@ -45,25 +46,37 @@ struct PromiseCallback {
45
46
  this->completeCallbackWrapper_ = [](bool success, void *data){
46
47
  if(data != nullptr){
47
48
  auto* callback = static_cast<PromiseCallback*>(data);
48
- auto inner = callback->inner_.get();
49
- if(inner == nullptr || inner->current_queue != nullptr){
49
+ if(callback->inner_ == nullptr || callback->inner_->current_queue == nullptr){
50
50
  return;
51
51
  }
52
52
 
53
- inner->current_queue->addOperation([success, data, inner, callback](){
54
- inner->completeCallback_(success, data);
53
+ callback->inner_->current_queue->addOperation([success, data, callback](){
54
+ callback->inner_->completeCallback_(success, data);
55
55
  // delete callback;
56
56
  });
57
57
  }
58
58
  };
59
59
  }
60
60
 
61
+ void setData(void* newData) {
62
+ std::lock_guard<std::mutex> lock(mtx);
63
+ data = newData;
64
+ }
65
+
66
+
67
+ void* getData() {
68
+ std::lock_guard<std::mutex> lock(mtx);
69
+ return data;
70
+ }
71
+
61
72
  void prepare(){
73
+ std::lock_guard<std::mutex> lock(mtx);
62
74
  current_queue = new NSOperationQueueWrapper(true);
63
75
  isPrepared_ = true;
64
76
  }
65
77
 
66
78
  void execute(bool complete, PromiseCallback* callback){
79
+ std::lock_guard<std::mutex> lock(mtx);
67
80
  completeCallbackWrapper_(complete, callback);
68
81
  }
69
82
 
@@ -76,15 +89,13 @@ struct PromiseCallback {
76
89
  std::shared_ptr<Inner> inner_;
77
90
 
78
91
  void prepare(){
79
- auto inner = this->inner_.get();
80
- if(inner == nullptr){return;}
81
- inner->prepare();
92
+ if( this->inner_ == nullptr){return;}
93
+ this->inner_->prepare();
82
94
  }
83
95
 
84
96
  void execute(bool complete) {
85
- auto inner = this->inner_.get();
86
- if (inner == nullptr) { return; }
87
- inner->execute(complete, this);
97
+ if (this->inner_ == nullptr) { return; }
98
+ this->inner_->execute(complete, this);
88
99
  }
89
100
 
90
101
  explicit PromiseCallback(std::shared_ptr<Inner> inner) : inner_(std::move(inner)) {}
@@ -106,6 +117,7 @@ struct PromiseCallback {
106
117
  void *data = nullptr;
107
118
  CompleteCallback completeCallback_;
108
119
  bool isPrepared_ = false;
120
+ mutable std::mutex mtx;
109
121
 
110
122
  Inner(v8::Isolate *isolate, v8::Local<v8::Promise::Resolver> callback,
111
123
  CompleteCallback completeCallback) : isolate_(isolate),
@@ -135,13 +147,25 @@ struct PromiseCallback {
135
147
  isPrepared_ = true;
136
148
  }
137
149
 
138
- void execute(bool complete) const {
150
+ void execute(bool complete, [[maybe_unused]] PromiseCallback *callback) const {
139
151
  if (!isPrepared_) { return; }
140
152
  write(fd_[1],
141
153
  &complete,
142
154
  sizeof(bool));
143
155
  }
144
156
 
157
+ void setData(void *newData) {
158
+ std::lock_guard<std::mutex> lock(mtx);
159
+ data = newData;
160
+ }
161
+
162
+
163
+ void *getData() {
164
+ std::lock_guard<std::mutex> lock(mtx);
165
+ return data;
166
+ }
167
+
168
+
145
169
 
146
170
  ~Inner() {
147
171
  if (!isPrepared_) {
@@ -155,11 +179,10 @@ struct PromiseCallback {
155
179
  };
156
180
 
157
181
  void prepare() const {
158
- auto inner = this->inner_.get();
159
- if (inner == nullptr) { return; }
160
- inner->prepare();
161
- auto looper = inner->looper_;
162
- auto fd = inner->fd_[0];
182
+ if (inner_ == nullptr) { return; }
183
+ inner_->prepare();
184
+ auto looper = inner_->looper_;
185
+ auto fd = inner_->fd_[0];
163
186
  auto data = new PromiseCallback(this->inner_);
164
187
  ALooper_addFd(looper,
165
188
  fd,
@@ -175,13 +198,12 @@ struct PromiseCallback {
175
198
  return 0;
176
199
  }, (void *) data);
177
200
 
178
- inner->isPrepared_ = true;
201
+ inner_->isPrepared_ = true;
179
202
  }
180
203
 
181
204
  void execute(bool complete) const {
182
- auto inner = this->inner_.get();
183
- if (inner == nullptr) { return; }
184
- inner->execute(complete);
205
+ if (this->inner_ == nullptr) { return; }
206
+ this->inner_->execute(complete, nullptr);
185
207
  }
186
208
 
187
209
  std::shared_ptr<Inner> inner_;
@@ -52,6 +52,12 @@ v8::Local<v8::FunctionTemplate> TextDecoderImpl::GetCtor(v8::Isolate *isolate) {
52
52
  tmpl->Set(
53
53
  ConvertToV8String(isolate, "decode"),
54
54
  v8::FunctionTemplate::New(isolate, &Decode));
55
+
56
+ tmpl->Set(
57
+ ConvertToV8String(isolate, "decodeAsync"),
58
+ v8::FunctionTemplate::New(isolate, &DecodeAsync));
59
+
60
+
55
61
  cache->TextDecoderTmpl =
56
62
  std::make_unique<v8::Persistent<v8::FunctionTemplate>>(isolate, ctorTmpl);
57
63
  return ctorTmpl;
@@ -185,3 +191,139 @@ void TextDecoderImpl::Decode(const v8::FunctionCallbackInfo<v8::Value> &args) {
185
191
 
186
192
  args.GetReturnValue().SetEmptyString();
187
193
  }
194
+
195
+ struct DecodeAsyncData {
196
+ v8::Persistent<v8::Object>* buffer;
197
+ uint8_t* data;
198
+ size_t size;
199
+ };
200
+
201
+ void TextDecoderImpl::DecodeAsync(const v8::FunctionCallbackInfo<v8::Value> &args) {
202
+ auto isolate = args.GetIsolate();
203
+
204
+ auto resolver = v8::Promise::Resolver::New(isolate->GetCurrentContext()).ToLocalChecked();
205
+ args.GetReturnValue().Set(resolver->GetPromise());
206
+
207
+ auto context = isolate->GetCurrentContext();
208
+
209
+ auto value = args[0];
210
+ if (value->IsNull() ||
211
+ value->IsUndefined() ||
212
+ !value->IsObject()) {
213
+
214
+ auto msg = v8::Exception::Error(ConvertToV8String(isolate, "Failed to execute 'decode' on 'TextDecoder': The provided value is not of type '(ArrayBuffer or ArrayBufferView)'"));
215
+
216
+ resolver->Reject(context, msg);
217
+
218
+ return;
219
+ }
220
+
221
+ TextDecoderImpl *ptr = GetPointer(args.This());
222
+ if (ptr == nullptr) {
223
+ resolver->Resolve(context, v8::String::Empty(isolate));
224
+ return;
225
+ }
226
+
227
+ if(!value->IsArrayBufferView() && !value->IsArrayBuffer()){
228
+
229
+ auto msg = v8::Exception::Error(ConvertToV8String(isolate, "Failed to execute 'decode' on 'TextDecoder': The provided value is not of type '(ArrayBuffer or ArrayBufferView)'"));
230
+
231
+ resolver->Reject(context, msg);
232
+ return;
233
+ }
234
+
235
+
236
+ auto callback = new PromiseCallback{
237
+ isolate,
238
+ resolver,
239
+ [](bool done, void *data) {
240
+ auto async_data = static_cast<PromiseCallback *>(data);
241
+ auto func = async_data->inner_;
242
+ if (func != nullptr && func->isolate_ != nullptr) {
243
+ v8::Isolate *isolate = func->isolate_;
244
+ v8::Locker locker(isolate);
245
+ v8::Isolate::Scope isolate_scope(
246
+ isolate);
247
+ v8::HandleScope handle_scope(
248
+ isolate);
249
+ v8::Local<v8::Promise::Resolver> callback = func->callback_.Get(
250
+ isolate);
251
+ v8::Local<v8::Context> context = callback->GetCreationContextChecked();
252
+ v8::Context::Scope context_scope(
253
+ context);
254
+
255
+ auto funcData = func->getData();
256
+
257
+ if (funcData == nullptr) {
258
+ callback->Resolve(context, v8::String::Empty(isolate));
259
+ } else {
260
+ auto decoded = static_cast<CCow *>(funcData);
261
+
262
+ auto returnValue = new OneByteStringResource(decoded);
263
+ auto ret = v8::String::NewExternalOneByte(isolate, returnValue);
264
+ v8::Local<v8::Value> value;
265
+ func->setData(nullptr);
266
+
267
+
268
+ if (ret.ToLocal(&value)){
269
+ callback->Resolve(context, value).IsJust();
270
+ } else {
271
+ callback->Resolve(context, v8::String::Empty(isolate)).IsJust();
272
+ }
273
+ }
274
+ }
275
+
276
+ delete static_cast<PromiseCallback *>(data);
277
+ }
278
+ };
279
+ callback->prepare();
280
+
281
+
282
+ auto buf = value.As<v8::Object>();
283
+
284
+ auto bufferPer = new v8::Persistent<v8::Object>(isolate, buf);
285
+
286
+ uint8_t* data = nullptr;
287
+ size_t size;
288
+
289
+ if (buf->IsArrayBuffer()) {
290
+ auto buffer = buf.As<v8::ArrayBuffer>();
291
+ data = static_cast<u_int8_t *>(buffer->GetBackingStore()->Data());
292
+ size = buffer->ByteLength();
293
+ }
294
+
295
+
296
+ if (buf->IsArrayBufferView()) {
297
+ auto buffer = buf.As<v8::ArrayBufferView>();
298
+
299
+ auto store = buffer->Buffer()->GetBackingStore();
300
+ data = static_cast<uint8_t *>(store->Data()) + buffer->ByteOffset();
301
+
302
+ size = buffer->ByteLength();
303
+ }
304
+
305
+ DecodeAsyncData asyncData{
306
+ bufferPer,
307
+ data,
308
+ size
309
+ };
310
+
311
+
312
+ std::thread thread(
313
+ [callback, asyncData, ptr]() {
314
+ if (callback->inner_ != nullptr) {
315
+
316
+ auto decoded = canvas_native_text_decoder_decode_as_cow(
317
+ ptr->GetTextDecoder(),
318
+ asyncData.data, asyncData.size);
319
+
320
+ callback->inner_->setData(decoded);
321
+ callback->inner_->execute(true, callback);
322
+ }
323
+ asyncData.buffer->Reset();
324
+ delete asyncData.buffer;
325
+
326
+ });
327
+ thread.detach();
328
+
329
+ }
@@ -29,6 +29,8 @@ public:
29
29
  static void Ctor(const v8::FunctionCallbackInfo<v8::Value> &args);
30
30
 
31
31
  static void Decode(const v8::FunctionCallbackInfo<v8::Value> &args);
32
+
33
+ static void DecodeAsync(const v8::FunctionCallbackInfo<v8::Value> &args);
32
34
 
33
35
  static void
34
36
  Encoding(v8::Local<v8::String> name, const v8::PropertyCallbackInfo<v8::Value> &info);
@@ -1147,11 +1147,8 @@ void CanvasRenderingContext2DImpl::GetGlobalCompositeOperation(v8::Local<v8::Str
1147
1147
  info.GetReturnValue().Set(0);
1148
1148
  return;
1149
1149
  }
1150
- auto operation = canvas_native_context_get_global_composition(ptr->GetContext());
1151
- info.GetReturnValue().Set(
1152
- ConvertToV8String(info.GetIsolate(), operation));
1153
-
1154
- canvas_native_string_destroy((char *) operation);
1150
+ auto operation = canvas_native_context_get_global_composition_int(ptr->GetContext());
1151
+ info.GetReturnValue().Set(operation);
1155
1152
  }
1156
1153
 
1157
1154
  void CanvasRenderingContext2DImpl::SetGlobalCompositeOperation(v8::Local<v8::String> property,
@@ -1162,8 +1159,15 @@ void CanvasRenderingContext2DImpl::SetGlobalCompositeOperation(v8::Local<v8::Str
1162
1159
  return;
1163
1160
  }
1164
1161
  auto isolate = info.GetIsolate();
1165
- auto operation = ConvertFromV8String(isolate, value);
1166
- canvas_native_context_set_global_composition(ptr->GetContext(), operation.c_str());
1162
+
1163
+ uint32_t operation = 0;
1164
+ auto context = isolate->GetCurrentContext();
1165
+ if (value->Uint32Value(context).To(&operation)) {
1166
+ canvas_native_context_set_global_composition_int(ptr->GetContext(), operation);
1167
+ }
1168
+
1169
+ // auto operation = ConvertFromV8String(isolate, value);
1170
+ // canvas_native_context_set_global_composition(ptr->GetContext(), operation.c_str());
1167
1171
  }
1168
1172
 
1169
1173
 
@@ -1220,10 +1224,33 @@ void CanvasRenderingContext2DImpl::SetFillStyle(v8::Local<v8::String> property,
1220
1224
  auto isolate = info.GetIsolate();
1221
1225
 
1222
1226
  if (value->IsString()) {
1223
- auto style = ConvertFromV8String(isolate, value);
1224
- canvas_native_paint_style_set_fill_color_with_c_string(ptr->GetContext(),
1225
- style.c_str());
1226
- } else if (value->IsObject()) {
1227
+ // auto style = ConvertFromV8String(isolate, value);
1228
+
1229
+ auto val = value.As<v8::String>();
1230
+ int len = val->Utf8Length(isolate) + 1;
1231
+ char buffer [len];
1232
+ val->WriteUtf8(isolate, buffer, len, nullptr, v8::String::WriteOptions::PRESERVE_ONE_BYTE_NULL);
1233
+
1234
+ // v8::String::Utf8Value result(isolate, value);
1235
+
1236
+ // const char *val = *result;
1237
+
1238
+ // if (buffer == nullptr) {
1239
+ // return;
1240
+ // }
1241
+
1242
+ canvas_native_paint_style_set_fill_color_with_c_string(ptr->GetContext(), buffer);
1243
+ }else if(value->IsStringObject()){
1244
+
1245
+ auto val = value.As<v8::StringObject>()->ValueOf();
1246
+
1247
+ int len = val->Utf8Length(isolate) + 1;
1248
+ char buffer [len];
1249
+ val->WriteUtf8(isolate, buffer, len, nullptr, v8::String::WriteOptions::PRESERVE_ONE_BYTE_NULL);
1250
+
1251
+ canvas_native_paint_style_set_fill_color_with_c_string(ptr->GetContext(), buffer);
1252
+
1253
+ } else if (value->IsObject()) {
1227
1254
 
1228
1255
  auto type = GetNativeType(value);
1229
1256
 
@@ -1300,10 +1327,27 @@ void CanvasRenderingContext2DImpl::SetStrokeStyle(v8::Local<v8::String> property
1300
1327
  auto isolate = info.GetIsolate();
1301
1328
 
1302
1329
  if (value->IsString()) {
1303
- auto style = ConvertFromV8String(isolate, value);
1304
- canvas_native_paint_style_set_stroke_color_with_c_string(ptr->GetContext(),
1305
- style.c_str());
1306
- } else if (value->IsObject()) {
1330
+ // auto style = ConvertFromV8String(isolate, value);
1331
+
1332
+ auto val = value.As<v8::String>();
1333
+
1334
+ int len = val->Utf8Length(isolate) + 1;
1335
+ char buffer [len];
1336
+ val->WriteUtf8(isolate, buffer, len, nullptr, v8::String::WriteOptions::PRESERVE_ONE_BYTE_NULL);
1337
+
1338
+
1339
+ canvas_native_paint_style_set_stroke_color_with_c_string(ptr->GetContext(), buffer);
1340
+
1341
+ }else if(value->IsStringObject()){
1342
+ auto val = value.As<v8::StringObject>()->ValueOf();
1343
+
1344
+ int len = val->Utf8Length(isolate) + 1;
1345
+ char buffer [len];
1346
+ val->WriteUtf8(isolate, buffer, len, nullptr, v8::String::WriteOptions::PRESERVE_ONE_BYTE_NULL);
1347
+
1348
+
1349
+ canvas_native_paint_style_set_stroke_color_with_c_string(ptr->GetContext(), buffer);
1350
+ } else if (value->IsObject()) {
1307
1351
 
1308
1352
  auto type = GetNativeType(value);
1309
1353
 
@@ -355,7 +355,7 @@ void Path2D::RoundRect(const v8::FunctionCallbackInfo<v8::Value> &args) {
355
355
  auto array = radii.As<v8::Array>();
356
356
  auto size = array->Length();
357
357
 
358
- if (size > 1) {
358
+ if (size >= 1) {
359
359
  std::vector<float> store;
360
360
  store.reserve(size);
361
361
  for (int i = 0;
@@ -209,11 +209,8 @@ void GPUAdapterImpl::RequestDevice(const v8::FunctionCallbackInfo<v8::Value> &ar
209
209
 
210
210
  v8::Local<v8::Value> requiredFeaturesValue;
211
211
 
212
- options->Get(context, ConvertToV8String(isolate, "requiredFeatures")).ToLocal(
213
- &requiredFeaturesValue);
214
-
215
-
216
- if (!requiredFeaturesValue.IsEmpty() && requiredFeaturesValue->IsArray()) {
212
+ if ( options->Get(context, ConvertToV8String(isolate, "requiredFeatures")).ToLocal(
213
+ &requiredFeaturesValue) && requiredFeaturesValue->IsArray()) {
217
214
  v8::Local<v8::Array> requiredFeatures = requiredFeaturesValue.As<v8::Array>();
218
215
  auto len = requiredFeatures->Length();
219
216
  for (int i = 0; i < len; i++) {
@@ -229,10 +226,9 @@ void GPUAdapterImpl::RequestDevice(const v8::FunctionCallbackInfo<v8::Value> &ar
229
226
 
230
227
  v8::Local<v8::Value> limitsValue;
231
228
 
232
- options->Get(context, ConvertToV8String(isolate, "requiredLimits")).ToLocal(
233
- &limitsValue);
234
229
 
235
- if (!limitsValue.IsEmpty() && limitsValue->IsObject()) {
230
+ if (options->Get(context, ConvertToV8String(isolate, "requiredLimits")).ToLocal(
231
+ &limitsValue) && limitsValue->IsObject()) {
236
232
  auto limits_ptr = GPUSupportedLimitsImpl::GetPointer(limitsValue.As<v8::Object>());
237
233
  if (limits_ptr != nullptr) {
238
234
  limits = limits_ptr->GetLimits();