@nativescript/canvas 2.0.0-beta.7 → 2.0.0-beta.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Canvas/common.js +3 -0
- package/Canvas/common.js.map +1 -1
- package/Canvas/index.ios.js +0 -1
- package/Canvas/index.ios.js.map +1 -1
- package/Canvas2D/CanvasRenderingContext2D/index.d.ts +12 -0
- package/Canvas2D/CanvasRenderingContext2D/index.js +170 -1
- package/Canvas2D/CanvasRenderingContext2D/index.js.map +1 -1
- package/Dom/Group.d.ts +5 -1
- package/Dom/Group.js +14 -1
- package/Dom/Group.js.map +1 -1
- package/Dom/Paint.js +3 -2
- package/Dom/Paint.js.map +1 -1
- package/Dom/shapes/Atlas.d.ts +22 -0
- package/Dom/shapes/Atlas.js +60 -0
- package/Dom/shapes/Atlas.js.map +1 -0
- package/Dom/shapes/index.d.ts +12 -0
- package/Dom/shapes/index.js +27 -0
- package/Dom/shapes/index.js.map +1 -1
- package/package.json +1 -1
- package/platforms/android/canvas-release.aar +0 -0
- package/platforms/ios/CanvasNative.xcframework/Info.plist +5 -5
- package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/CanvasNative +0 -0
- package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Headers/canvas_native.h +34 -0
- package/platforms/ios/CanvasNative.xcframework/ios-arm64/dSYMs/CanvasNative.framework.dSYM/Contents/Resources/DWARF/CanvasNative +0 -0
- package/platforms/ios/CanvasNative.xcframework/ios-arm64/dSYMs/CanvasNative.framework.dSYM/Contents/Resources/Relocations/aarch64/CanvasNative.yml +171 -168
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/CanvasNative +0 -0
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Headers/canvas_native.h +34 -0
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/_CodeSignature/CodeResources +2 -2
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/dSYMs/CanvasNative.framework.dSYM/Contents/Resources/DWARF/CanvasNative +0 -0
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/dSYMs/CanvasNative.framework.dSYM/Contents/Resources/Relocations/aarch64/CanvasNative.yml +663 -663
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/dSYMs/CanvasNative.framework.dSYM/Contents/Resources/Relocations/x86_64/CanvasNative.yml +642 -642
- package/platforms/ios/src/cpp/ImageAssetImpl.cpp +22 -3
- package/platforms/ios/src/cpp/ImageAssetImpl.h +5 -2
- package/platforms/ios/src/cpp/canvas2d/CanvasRenderingContext2DImpl.cpp +154 -9
- package/platforms/ios/src/cpp/canvas2d/CanvasRenderingContext2DImpl.h +47 -0
|
@@ -15,8 +15,8 @@ ImageAssetImpl::ImageAssetImpl(ImageAsset *asset) : asset_(asset) {
|
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
ImageAssetImpl::~ImageAssetImpl() {
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
canvas_native_image_asset_destroy(this->GetImageAsset());
|
|
19
|
+
asset_ = nullptr;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
void ImageAssetImpl::Init(v8::Local<v8::Object> canvasModule, v8::Isolate *isolate) {
|
|
@@ -62,6 +62,10 @@ v8::Local<v8::FunctionTemplate> ImageAssetImpl::GetCtor(v8::Isolate *isolate) {
|
|
|
62
62
|
ConvertToV8String(isolate, "error"),
|
|
63
63
|
GetError);
|
|
64
64
|
|
|
65
|
+
tmpl->SetAccessor(
|
|
66
|
+
ConvertToV8String(isolate, "__addr"),
|
|
67
|
+
GetAddr);
|
|
68
|
+
|
|
65
69
|
tmpl->Set(
|
|
66
70
|
ConvertToV8String(isolate, "scale"),
|
|
67
71
|
v8::FunctionTemplate::New(isolate, &Scale));
|
|
@@ -112,7 +116,7 @@ void ImageAssetImpl::Ctor(const v8::FunctionCallbackInfo<v8::Value> &args) {
|
|
|
112
116
|
|
|
113
117
|
auto ret = args.This();
|
|
114
118
|
|
|
115
|
-
SetNativeType(
|
|
119
|
+
SetNativeType(ret, NativeType::ImageAsset);
|
|
116
120
|
|
|
117
121
|
auto image_asset = canvas_native_image_asset_create();
|
|
118
122
|
|
|
@@ -149,6 +153,21 @@ ImageAssetImpl::GetHeight(v8::Local<v8::String> name,
|
|
|
149
153
|
info.GetReturnValue().Set(0);
|
|
150
154
|
}
|
|
151
155
|
|
|
156
|
+
|
|
157
|
+
void
|
|
158
|
+
ImageAssetImpl::GetAddr(v8::Local<v8::String> name,
|
|
159
|
+
const v8::PropertyCallbackInfo<v8::Value> &info) {
|
|
160
|
+
auto ptr = GetPointer(info.This());
|
|
161
|
+
if (ptr != nullptr) {
|
|
162
|
+
auto isolate = info.GetIsolate();
|
|
163
|
+
auto addr = static_cast<intptr_t *>(static_cast<void *>(ptr->GetImageAsset()));
|
|
164
|
+
auto ret = std::to_string(*addr);
|
|
165
|
+
info.GetReturnValue().Set(ConvertToV8String(isolate, ret.c_str()));
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
info.GetReturnValue().SetEmptyString();
|
|
169
|
+
}
|
|
170
|
+
|
|
152
171
|
void
|
|
153
172
|
ImageAssetImpl::GetError(v8::Local<v8::String> name,
|
|
154
173
|
const v8::PropertyCallbackInfo<v8::Value> &info) {
|
|
@@ -16,13 +16,13 @@
|
|
|
16
16
|
|
|
17
17
|
class ImageAssetImpl: ObjectWrapperImpl{
|
|
18
18
|
public:
|
|
19
|
-
|
|
19
|
+
|
|
20
20
|
ImageAssetImpl(ImageAsset* asset);
|
|
21
21
|
|
|
22
22
|
~ImageAssetImpl();
|
|
23
23
|
|
|
24
24
|
ImageAsset* GetImageAsset();
|
|
25
|
-
|
|
25
|
+
|
|
26
26
|
static void Init(v8::Local<v8::Object> canvasModule, v8::Isolate *isolate);
|
|
27
27
|
|
|
28
28
|
static ImageAssetImpl *GetPointer(const v8::Local<v8::Object>& object);
|
|
@@ -37,6 +37,9 @@ public:
|
|
|
37
37
|
static void GetHeight(v8::Local<v8::String> name,
|
|
38
38
|
const v8::PropertyCallbackInfo<v8::Value> &info);
|
|
39
39
|
|
|
40
|
+
static void GetAddr(v8::Local<v8::String> name,
|
|
41
|
+
const v8::PropertyCallbackInfo<v8::Value> &info);
|
|
42
|
+
|
|
40
43
|
static void GetError(v8::Local<v8::String> name,
|
|
41
44
|
const v8::PropertyCallbackInfo<v8::Value> &info);
|
|
42
45
|
|
|
@@ -15,6 +15,10 @@ v8::CFunction CanvasRenderingContext2DImpl::fast_stop_raf_(
|
|
|
15
15
|
v8::CFunction CanvasRenderingContext2DImpl::fast_draw_point_(
|
|
16
16
|
v8::CFunction::Make(CanvasRenderingContext2DImpl::FastDrawPoint));
|
|
17
17
|
|
|
18
|
+
//v8::CFunction CanvasRenderingContext2DImpl::fast_draw_atlas_(
|
|
19
|
+
// v8::CFunction::Make(CanvasRenderingContext2DImpl::FastDrawAtlas));
|
|
20
|
+
|
|
21
|
+
|
|
18
22
|
v8::CFunction CanvasRenderingContext2DImpl::fast_ellipse_(
|
|
19
23
|
v8::CFunction::Make(CanvasRenderingContext2DImpl::FastEllipse));
|
|
20
24
|
|
|
@@ -389,6 +393,12 @@ v8::Local<v8::FunctionTemplate> CanvasRenderingContext2DImpl::GetCtor(v8::Isolat
|
|
|
389
393
|
tmpl->Set(ConvertToV8String(isolate, "drawFocusIfNeeded"),
|
|
390
394
|
v8::FunctionTemplate::New(isolate, &DrawFocusIfNeeded));
|
|
391
395
|
|
|
396
|
+
tmpl->Set(ConvertToV8String(isolate, "drawAtlas"),
|
|
397
|
+
v8::FunctionTemplate::New(isolate, &DrawAtlas));
|
|
398
|
+
|
|
399
|
+
|
|
400
|
+
// SetFastMethod(isolate, tmpl, "drawAtlas", DrawAtlas, &fast_draw_atlas_, v8::Local<v8::Value>());
|
|
401
|
+
|
|
392
402
|
SetFastMethodWithOverLoads(isolate, tmpl, "drawImage", DrawImage, fast_draw_overloads_,
|
|
393
403
|
v8::Local<v8::Value>());
|
|
394
404
|
|
|
@@ -596,30 +606,30 @@ void CanvasRenderingContext2DImpl::DrawPoints(const v8::FunctionCallbackInfo<v8:
|
|
|
596
606
|
auto points = args[1].As<v8::Array>();
|
|
597
607
|
auto size = points->Length();
|
|
598
608
|
|
|
599
|
-
if (size == 0){return;}
|
|
609
|
+
if (size == 0) { return; }
|
|
600
610
|
uint32_t pointMode = 0;
|
|
601
|
-
if(mode->IsUint32() && mode->Uint32Value(context).To(&pointMode)){
|
|
611
|
+
if (mode->IsUint32() && mode->Uint32Value(context).To(&pointMode)) {
|
|
602
612
|
std::vector<float> store;
|
|
603
613
|
auto len = size * 2;
|
|
604
614
|
store.reserve(len);
|
|
605
615
|
for (int i = 0; i < size; i++) {
|
|
606
616
|
|
|
607
617
|
auto object = points->Get(
|
|
608
|
-
|
|
618
|
+
context, i).ToLocalChecked().As<v8::Object>();
|
|
609
619
|
|
|
610
620
|
auto x = object->Get(context,
|
|
611
621
|
ConvertToV8String(isolate, "x")).ToLocalChecked()->NumberValue(
|
|
612
|
-
|
|
622
|
+
context).ToChecked();
|
|
613
623
|
auto y = object->Get(context,
|
|
614
624
|
ConvertToV8String(isolate, "y")).ToLocalChecked()->NumberValue(
|
|
615
|
-
|
|
625
|
+
context).ToChecked();
|
|
616
626
|
store.emplace_back((float) x);
|
|
617
627
|
store.emplace_back((float) y);
|
|
618
628
|
}
|
|
619
629
|
|
|
620
630
|
canvas_native_context_draw_points(
|
|
621
|
-
|
|
622
|
-
|
|
631
|
+
ptr->GetContext(), pointMode,
|
|
632
|
+
store.data(), store.size());
|
|
623
633
|
|
|
624
634
|
|
|
625
635
|
ptr->UpdateInvalidateState();
|
|
@@ -1876,6 +1886,143 @@ CanvasRenderingContext2DImpl::DrawFocusIfNeeded(const v8::FunctionCallbackInfo<v
|
|
|
1876
1886
|
}
|
|
1877
1887
|
|
|
1878
1888
|
|
|
1889
|
+
void
|
|
1890
|
+
CanvasRenderingContext2DImpl::DrawAtlas(const v8::FunctionCallbackInfo<v8::Value> &args) {
|
|
1891
|
+
|
|
1892
|
+
CanvasRenderingContext2DImpl *ptr = GetPointer(args.This());
|
|
1893
|
+
if (ptr == nullptr) {
|
|
1894
|
+
return;
|
|
1895
|
+
}
|
|
1896
|
+
|
|
1897
|
+
auto count = args.Length();
|
|
1898
|
+
auto value = args[0];
|
|
1899
|
+
|
|
1900
|
+
if (value->IsNullOrUndefined() || !value->IsObject()) {
|
|
1901
|
+
return;
|
|
1902
|
+
}
|
|
1903
|
+
|
|
1904
|
+
auto isolate = args.GetIsolate();
|
|
1905
|
+
auto context = isolate->GetCurrentContext();
|
|
1906
|
+
auto image = value.As<v8::Object>();
|
|
1907
|
+
auto imageType = GetNativeType(image);
|
|
1908
|
+
|
|
1909
|
+
|
|
1910
|
+
auto xformValue = args[1];
|
|
1911
|
+
auto texValue = args[2];
|
|
1912
|
+
auto colorsValue = args[3];
|
|
1913
|
+
auto blendValue = args[4];
|
|
1914
|
+
|
|
1915
|
+
if (xformValue->IsArray() && texValue->IsArray()) {
|
|
1916
|
+
|
|
1917
|
+
std::vector<float> xform;
|
|
1918
|
+
std::vector<float> tex;
|
|
1919
|
+
|
|
1920
|
+
v8::Local<v8::Array> xformArray = xformValue.As<v8::Array>();
|
|
1921
|
+
v8::Local<v8::Array> texArray = texValue.As<v8::Array>();
|
|
1922
|
+
|
|
1923
|
+
auto xformLen = xformArray->Length();
|
|
1924
|
+
xform.reserve(xformLen);
|
|
1925
|
+
auto texLen = texArray->Length();
|
|
1926
|
+
tex.reserve(texLen);
|
|
1927
|
+
|
|
1928
|
+
|
|
1929
|
+
for (int i = 0; i < xformLen; i++) {
|
|
1930
|
+
xform.emplace_back((float) xformArray->Get(context, i).ToLocalChecked()->NumberValue(
|
|
1931
|
+
context).ToChecked());
|
|
1932
|
+
}
|
|
1933
|
+
|
|
1934
|
+
for (int i = 0; i < texLen; i++) {
|
|
1935
|
+
tex.emplace_back((float) texArray->Get(context, i).ToLocalChecked()->NumberValue(
|
|
1936
|
+
context).ToChecked());
|
|
1937
|
+
}
|
|
1938
|
+
|
|
1939
|
+
std::vector<std::string> colors;
|
|
1940
|
+
std::vector<const char *> colors_ref;
|
|
1941
|
+
|
|
1942
|
+
// dst-over
|
|
1943
|
+
int32_t mode = 4;
|
|
1944
|
+
|
|
1945
|
+
if (blendValue->IsInt32()) {
|
|
1946
|
+
blendValue->Int32Value(context).To(&mode);
|
|
1947
|
+
}
|
|
1948
|
+
|
|
1949
|
+
if (colorsValue->IsArray()) {
|
|
1950
|
+
auto colorsArray = colorsValue.As<v8::Array>();
|
|
1951
|
+
auto colorsLen = colorsArray->Length();
|
|
1952
|
+
colors.reserve(colorsLen);
|
|
1953
|
+
colors_ref.reserve(colorsLen);
|
|
1954
|
+
for (int i = 0; i < colorsLen; i++) {
|
|
1955
|
+
auto str = ConvertFromV8String(isolate, texArray->Get(context, i).ToLocalChecked());
|
|
1956
|
+
colors.emplace_back(str);
|
|
1957
|
+
colors_ref.emplace_back(str.c_str());
|
|
1958
|
+
}
|
|
1959
|
+
}
|
|
1960
|
+
|
|
1961
|
+
switch (imageType) {
|
|
1962
|
+
case NativeType::ImageAsset: {
|
|
1963
|
+
auto image_asset = ImageAssetImpl::GetPointer(image);
|
|
1964
|
+
|
|
1965
|
+
if (image_asset != nullptr) {
|
|
1966
|
+
|
|
1967
|
+
if (colors.empty()) {
|
|
1968
|
+
canvas_native_context_draw_atlas_asset(ptr->GetContext(),
|
|
1969
|
+
image_asset->GetImageAsset(),
|
|
1970
|
+
xform.data(), xform.size(),
|
|
1971
|
+
tex.data(),
|
|
1972
|
+
tex.size(), nullptr,
|
|
1973
|
+
0, mode);
|
|
1974
|
+
} else {
|
|
1975
|
+
canvas_native_context_draw_atlas_asset(ptr->GetContext(),
|
|
1976
|
+
image_asset->GetImageAsset(),
|
|
1977
|
+
xform.data(), xform.size(),
|
|
1978
|
+
tex.data(),
|
|
1979
|
+
tex.size(), colors_ref.data(),
|
|
1980
|
+
colors_ref.size(), mode);
|
|
1981
|
+
}
|
|
1982
|
+
|
|
1983
|
+
|
|
1984
|
+
ptr->UpdateInvalidateState();
|
|
1985
|
+
}
|
|
1986
|
+
}
|
|
1987
|
+
break;
|
|
1988
|
+
case NativeType::ImageBitmap: {
|
|
1989
|
+
auto image_bitmap = ImageBitmapImpl::GetPointer(image);
|
|
1990
|
+
if (image_bitmap != nullptr) {
|
|
1991
|
+
if (colors.empty()) {
|
|
1992
|
+
canvas_native_context_draw_atlas_asset(ptr->GetContext(),
|
|
1993
|
+
image_bitmap->GetImageAsset(),
|
|
1994
|
+
xform.data(), xform.size(),
|
|
1995
|
+
tex.data(),
|
|
1996
|
+
tex.size(), nullptr,
|
|
1997
|
+
0, mode);
|
|
1998
|
+
} else {
|
|
1999
|
+
canvas_native_context_draw_atlas_asset(ptr->GetContext(),
|
|
2000
|
+
image_bitmap->GetImageAsset(),
|
|
2001
|
+
xform.data(), xform.size(),
|
|
2002
|
+
tex.data(),
|
|
2003
|
+
tex.size(), colors_ref.data(),
|
|
2004
|
+
colors_ref.size(), mode);
|
|
2005
|
+
}
|
|
2006
|
+
}
|
|
2007
|
+
}
|
|
2008
|
+
break;
|
|
2009
|
+
case NativeType::CanvasRenderingContext2D: {
|
|
2010
|
+
auto image_canvas = CanvasRenderingContext2DImpl::GetPointer(image);
|
|
2011
|
+
if (image_canvas != nullptr) {
|
|
2012
|
+
|
|
2013
|
+
ptr->UpdateInvalidateState();
|
|
2014
|
+
}
|
|
2015
|
+
}
|
|
2016
|
+
break;
|
|
2017
|
+
default:
|
|
2018
|
+
break;
|
|
2019
|
+
}
|
|
2020
|
+
}
|
|
2021
|
+
|
|
2022
|
+
|
|
2023
|
+
}
|
|
2024
|
+
|
|
2025
|
+
|
|
1879
2026
|
void
|
|
1880
2027
|
CanvasRenderingContext2DImpl::DrawImage(const v8::FunctionCallbackInfo<v8::Value> &args) {
|
|
1881
2028
|
|
|
@@ -2802,8 +2949,6 @@ CanvasRenderingContext2DImpl::StrokeOval(const v8::FunctionCallbackInfo<v8::Valu
|
|
|
2802
2949
|
}
|
|
2803
2950
|
|
|
2804
2951
|
|
|
2805
|
-
|
|
2806
|
-
|
|
2807
2952
|
void
|
|
2808
2953
|
CanvasRenderingContext2DImpl::Transform(const v8::FunctionCallbackInfo<v8::Value> &args) {
|
|
2809
2954
|
CanvasRenderingContext2DImpl *ptr = GetPointer(args.This());
|
|
@@ -126,6 +126,8 @@ public:
|
|
|
126
126
|
|
|
127
127
|
static v8::CFunction fast_translate_;
|
|
128
128
|
|
|
129
|
+
static v8::CFunction fast_draw_atlas_;
|
|
130
|
+
|
|
129
131
|
|
|
130
132
|
CanvasRenderingContext2DImpl(CanvasRenderingContext2D *context);
|
|
131
133
|
|
|
@@ -573,6 +575,51 @@ public:
|
|
|
573
575
|
|
|
574
576
|
static void DrawFocusIfNeeded(const v8::FunctionCallbackInfo<v8::Value> &args);
|
|
575
577
|
|
|
578
|
+
|
|
579
|
+
static void DrawAtlas(const v8::FunctionCallbackInfo<v8::Value> &args);
|
|
580
|
+
|
|
581
|
+
/*
|
|
582
|
+
static void FastDrawAtlas(v8::Local<v8::Object> receiver_obj, v8::Local<v8::Object> image_obj, v8::Local<v8::Array> xform, v8::Local<v8::Array> tex, v8::Local<v8::Array> xform) {
|
|
583
|
+
CanvasRenderingContext2DImpl *ptr = GetPointer(receiver_obj);
|
|
584
|
+
if (ptr == nullptr) {
|
|
585
|
+
return;
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
|
|
589
|
+
auto len = array->Length();
|
|
590
|
+
std::vector<float> buf;
|
|
591
|
+
buf.reserve(len);
|
|
592
|
+
|
|
593
|
+
auto copied = v8::TryToCopyAndConvertArrayToCppBuffer<v8::CTypeInfoBuilder<float>::Build().GetId(), float>(
|
|
594
|
+
array, buf.data(), len);
|
|
595
|
+
|
|
596
|
+
if (copied) {
|
|
597
|
+
|
|
598
|
+
auto imageType = GetNativeType(image_obj);
|
|
599
|
+
switch (imageType) {
|
|
600
|
+
case NativeType::ImageAsset: {
|
|
601
|
+
auto asset = ImageAssetImpl::GetPointer(image_obj);
|
|
602
|
+
|
|
603
|
+
}
|
|
604
|
+
break;
|
|
605
|
+
case NativeType::ImageBitmap: {
|
|
606
|
+
auto asset = ImageBitmapImpl::GetPointer(image_obj);
|
|
607
|
+
}
|
|
608
|
+
break;
|
|
609
|
+
case NativeType::CanvasRenderingContext2D: {
|
|
610
|
+
auto context = CanvasRenderingContext2DImpl::GetPointer(image_obj);
|
|
611
|
+
|
|
612
|
+
}
|
|
613
|
+
break;
|
|
614
|
+
default:
|
|
615
|
+
break;
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
|
|
619
|
+
ptr->UpdateInvalidateState();
|
|
620
|
+
}
|
|
621
|
+
*/
|
|
622
|
+
|
|
576
623
|
static void DrawImage(const v8::FunctionCallbackInfo<v8::Value> &args);
|
|
577
624
|
|
|
578
625
|
static void
|