@shopify/react-native-skia 0.1.201 → 0.1.203
Sign up to get free protection for your applications and to get access to all the features.
- package/android/CMakeLists.txt +9 -9
- package/android/cpp/rnskia-android/RNSkAndroidPlatformContext.h +11 -0
- package/cpp/api/JsiSkApi.h +8 -0
- package/cpp/api/JsiSkFontMgr.h +54 -0
- package/cpp/api/JsiSkFontMgrFactory.h +40 -0
- package/cpp/api/JsiSkFontStyle.h +61 -0
- package/cpp/api/JsiSkTypeFaceFontProvider.h +80 -0
- package/cpp/api/JsiSkTypeFaceFontProviderFactory.h +32 -0
- package/cpp/rnskia/RNSkPlatformContext.h +6 -0
- package/cpp/rnskia/RNSkView.h +5 -2
- package/cpp/skia/include/core/SkColorTable.h +1 -1
- package/ios/RNSkia-iOS/RNSkMetalCanvasProvider.h +5 -14
- package/ios/RNSkia-iOS/RNSkMetalCanvasProvider.mm +7 -56
- package/ios/RNSkia-iOS/RNSkiOSPlatformContext.h +1 -0
- package/ios/RNSkia-iOS/RNSkiOSPlatformContext.mm +9 -2
- package/ios/RNSkia-iOS/SkiaMetalSurfaceFactory.h +31 -0
- package/ios/RNSkia-iOS/SkiaMetalSurfaceFactory.mm +105 -0
- package/lib/commonjs/skia/core/Data.d.ts +2 -0
- package/lib/commonjs/skia/core/Data.js +29 -1
- package/lib/commonjs/skia/core/Data.js.map +1 -1
- package/lib/commonjs/skia/core/Font.d.ts +14 -1
- package/lib/commonjs/skia/core/Font.js +93 -1
- package/lib/commonjs/skia/core/Font.js.map +1 -1
- package/lib/commonjs/skia/types/Font/FontMgr.d.ts +8 -0
- package/lib/commonjs/skia/types/Font/FontMgr.js +6 -0
- package/lib/commonjs/skia/types/Font/FontMgr.js.map +1 -0
- package/lib/commonjs/skia/types/Font/FontMgrFactory.d.ts +4 -0
- package/lib/commonjs/skia/types/Font/FontMgrFactory.js +6 -0
- package/lib/commonjs/skia/types/Font/FontMgrFactory.js.map +1 -0
- package/lib/commonjs/skia/types/Font/index.d.ts +2 -0
- package/lib/commonjs/skia/types/Font/index.js +26 -0
- package/lib/commonjs/skia/types/Font/index.js.map +1 -1
- package/lib/commonjs/skia/types/Paragraph/TypefaceFontProvider.d.ts +10 -0
- package/lib/commonjs/skia/types/Paragraph/TypefaceFontProvider.js +6 -0
- package/lib/commonjs/skia/types/Paragraph/TypefaceFontProvider.js.map +1 -0
- package/lib/commonjs/skia/types/Paragraph/TypefaceFontProviderFactory.d.ts +4 -0
- package/lib/commonjs/skia/types/Paragraph/TypefaceFontProviderFactory.js +6 -0
- package/lib/commonjs/skia/types/Paragraph/TypefaceFontProviderFactory.js.map +1 -0
- package/lib/commonjs/skia/types/Skia.d.ts +4 -1
- package/lib/commonjs/skia/types/Skia.js.map +1 -1
- package/lib/commonjs/skia/web/Host.d.ts +1 -1
- package/lib/commonjs/skia/web/Host.js +0 -2
- package/lib/commonjs/skia/web/Host.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkFontMgr.d.ts +10 -0
- package/lib/commonjs/skia/web/JsiSkFontMgr.js +34 -0
- package/lib/commonjs/skia/web/JsiSkFontMgr.js.map +1 -0
- package/lib/commonjs/skia/web/JsiSkFontMgrFactory.d.ts +8 -0
- package/lib/commonjs/skia/web/JsiSkFontMgrFactory.js +32 -0
- package/lib/commonjs/skia/web/JsiSkFontMgrFactory.js.map +1 -0
- package/lib/commonjs/skia/web/JsiSkTypefaceFontProvider.d.ts +13 -0
- package/lib/commonjs/skia/web/JsiSkTypefaceFontProvider.js +90 -0
- package/lib/commonjs/skia/web/JsiSkTypefaceFontProvider.js.map +1 -0
- package/lib/commonjs/skia/web/JsiSkTypefaceFontProviderFactory.d.ts +7 -0
- package/lib/commonjs/skia/web/JsiSkTypefaceFontProviderFactory.js +25 -0
- package/lib/commonjs/skia/web/JsiSkTypefaceFontProviderFactory.js.map +1 -0
- package/lib/commonjs/skia/web/JsiSkia.js +7 -1
- package/lib/commonjs/skia/web/JsiSkia.js.map +1 -1
- package/lib/module/skia/core/Data.d.ts +2 -0
- package/lib/module/skia/core/Data.js +24 -1
- package/lib/module/skia/core/Data.js.map +1 -1
- package/lib/module/skia/core/Font.d.ts +14 -1
- package/lib/module/skia/core/Font.js +83 -1
- package/lib/module/skia/core/Font.js.map +1 -1
- package/lib/module/skia/types/Font/FontMgr.d.ts +8 -0
- package/lib/module/skia/types/Font/FontMgr.js +2 -0
- package/lib/module/skia/types/Font/FontMgr.js.map +1 -0
- package/lib/module/skia/types/Font/FontMgrFactory.d.ts +4 -0
- package/lib/module/skia/types/Font/FontMgrFactory.js +2 -0
- package/lib/module/skia/types/Font/FontMgrFactory.js.map +1 -0
- package/lib/module/skia/types/Font/index.d.ts +2 -0
- package/lib/module/skia/types/Font/index.js +2 -0
- package/lib/module/skia/types/Font/index.js.map +1 -1
- package/lib/module/skia/types/Paragraph/TypefaceFontProvider.d.ts +10 -0
- package/lib/module/skia/types/Paragraph/TypefaceFontProvider.js +2 -0
- package/lib/module/skia/types/Paragraph/TypefaceFontProvider.js.map +1 -0
- package/lib/module/skia/types/Paragraph/TypefaceFontProviderFactory.d.ts +4 -0
- package/lib/module/skia/types/Paragraph/TypefaceFontProviderFactory.js +2 -0
- package/lib/module/skia/types/Paragraph/TypefaceFontProviderFactory.js.map +1 -0
- package/lib/module/skia/types/Skia.d.ts +4 -1
- package/lib/module/skia/types/Skia.js.map +1 -1
- package/lib/module/skia/web/Host.d.ts +1 -1
- package/lib/module/skia/web/Host.js +0 -2
- package/lib/module/skia/web/Host.js.map +1 -1
- package/lib/module/skia/web/JsiSkFontMgr.d.ts +10 -0
- package/lib/module/skia/web/JsiSkFontMgr.js +24 -0
- package/lib/module/skia/web/JsiSkFontMgr.js.map +1 -0
- package/lib/module/skia/web/JsiSkFontMgrFactory.d.ts +8 -0
- package/lib/module/skia/web/JsiSkFontMgrFactory.js +21 -0
- package/lib/module/skia/web/JsiSkFontMgrFactory.js.map +1 -0
- package/lib/module/skia/web/JsiSkTypefaceFontProvider.d.ts +13 -0
- package/lib/module/skia/web/JsiSkTypefaceFontProvider.js +80 -0
- package/lib/module/skia/web/JsiSkTypefaceFontProvider.js.map +1 -0
- package/lib/module/skia/web/JsiSkTypefaceFontProviderFactory.d.ts +7 -0
- package/lib/module/skia/web/JsiSkTypefaceFontProviderFactory.js +14 -0
- package/lib/module/skia/web/JsiSkTypefaceFontProviderFactory.js.map +1 -0
- package/lib/module/skia/web/JsiSkia.js +5 -1
- package/lib/module/skia/web/JsiSkia.js.map +1 -1
- package/lib/typescript/src/skia/core/Data.d.ts +2 -0
- package/lib/typescript/src/skia/core/Font.d.ts +14 -1
- package/lib/typescript/src/skia/types/Font/FontMgr.d.ts +8 -0
- package/lib/typescript/src/skia/types/Font/FontMgrFactory.d.ts +4 -0
- package/lib/typescript/src/skia/types/Font/index.d.ts +2 -0
- package/lib/typescript/src/skia/types/Paragraph/TypefaceFontProvider.d.ts +10 -0
- package/lib/typescript/src/skia/types/Paragraph/TypefaceFontProviderFactory.d.ts +4 -0
- package/lib/typescript/src/skia/types/Skia.d.ts +4 -1
- package/lib/typescript/src/skia/web/Host.d.ts +1 -1
- package/lib/typescript/src/skia/web/JsiSkFontMgr.d.ts +10 -0
- package/lib/typescript/src/skia/web/JsiSkFontMgrFactory.d.ts +8 -0
- package/lib/typescript/src/skia/web/JsiSkTypefaceFontProvider.d.ts +13 -0
- package/lib/typescript/src/skia/web/JsiSkTypefaceFontProviderFactory.d.ts +7 -0
- package/libs/android/arm64-v8a/libskia.a +0 -0
- package/libs/android/arm64-v8a/libskottie.a +0 -0
- package/libs/android/arm64-v8a/libskparagraph.a +0 -0
- package/libs/android/arm64-v8a/libskshaper.a +0 -0
- package/libs/android/arm64-v8a/libskunicode.a +0 -0
- package/libs/android/armeabi-v7a/libskia.a +0 -0
- package/libs/android/armeabi-v7a/libskottie.a +0 -0
- package/libs/android/armeabi-v7a/libskparagraph.a +0 -0
- package/libs/android/armeabi-v7a/libskshaper.a +0 -0
- package/libs/android/armeabi-v7a/libskunicode.a +0 -0
- package/libs/android/x86/libskia.a +0 -0
- package/libs/android/x86/libskottie.a +0 -0
- package/libs/android/x86/libskparagraph.a +0 -0
- package/libs/android/x86/libskshaper.a +0 -0
- package/libs/android/x86/libskunicode.a +0 -0
- package/libs/android/x86_64/libskia.a +0 -0
- package/libs/android/x86_64/libskottie.a +0 -0
- package/libs/android/x86_64/libskparagraph.a +0 -0
- package/libs/android/x86_64/libskshaper.a +0 -0
- package/libs/android/x86_64/libskunicode.a +0 -0
- package/libs/ios/libskia.xcframework/Info.plist +5 -5
- package/libs/ios/libskia.xcframework/ios-arm64_arm64e/libskia.a +0 -0
- package/libs/ios/libskia.xcframework/ios-arm64_arm64e_x86_64-simulator/libskia.a +0 -0
- package/libs/ios/libskottie.xcframework/ios-arm64_arm64e/libskottie.a +0 -0
- package/libs/ios/libskottie.xcframework/ios-arm64_arm64e_x86_64-simulator/libskottie.a +0 -0
- package/libs/ios/libskparagraph.xcframework/Info.plist +42 -0
- package/libs/ios/libskparagraph.xcframework/ios-arm64_arm64e/libskparagraph.a +0 -0
- package/libs/ios/libskparagraph.xcframework/ios-arm64_arm64e_x86_64-simulator/libskparagraph.a +0 -0
- package/libs/ios/libsksg.xcframework/ios-arm64_arm64e/libsksg.a +0 -0
- package/libs/ios/libsksg.xcframework/ios-arm64_arm64e_x86_64-simulator/libsksg.a +0 -0
- package/libs/ios/libskshaper.xcframework/ios-arm64_arm64e/libskshaper.a +0 -0
- package/libs/ios/libskshaper.xcframework/ios-arm64_arm64e_x86_64-simulator/libskshaper.a +0 -0
- package/libs/ios/libskunicode.xcframework/Info.plist +42 -0
- package/libs/ios/libskunicode.xcframework/ios-arm64_arm64e/libskunicode.a +0 -0
- package/libs/ios/libskunicode.xcframework/ios-arm64_arm64e_x86_64-simulator/libskunicode.a +0 -0
- package/libs/ios/libsvg.xcframework/Info.plist +5 -5
- package/libs/ios/libsvg.xcframework/ios-arm64_arm64e/libsvg.a +0 -0
- package/libs/ios/libsvg.xcframework/ios-arm64_arm64e_x86_64-simulator/libsvg.a +0 -0
- package/package.json +3 -1
- package/react-native-skia.podspec +2 -2
- package/src/skia/core/Data.ts +31 -1
- package/src/skia/core/Font.ts +109 -2
- package/src/skia/types/Font/FontMgr.ts +10 -0
- package/src/skia/types/Font/FontMgrFactory.ts +5 -0
- package/src/skia/types/Font/index.ts +2 -0
- package/src/skia/types/Paragraph/TypefaceFontProvider.ts +11 -0
- package/src/skia/types/Paragraph/TypefaceFontProviderFactory.ts +5 -0
- package/src/skia/types/Skia.ts +4 -2
- package/src/skia/web/Host.ts +1 -1
- package/src/skia/web/JsiSkFontMgr.ts +26 -0
- package/src/skia/web/JsiSkFontMgrFactory.ts +22 -0
- package/src/skia/web/JsiSkTypefaceFontProvider.ts +89 -0
- package/src/skia/web/JsiSkTypefaceFontProviderFactory.ts +18 -0
- package/src/skia/web/JsiSkia.ts +4 -0
- package/ios/RNSkia-iOS/SkiaMetalRenderer.h +0 -5
- package/ios/RNSkia-iOS/SkiaMetalRenderer.mm +0 -55
package/android/CMakeLists.txt
CHANGED
@@ -9,8 +9,8 @@ set (PACKAGE_NAME "rnskia")
|
|
9
9
|
set (SKIA_LIB "skia")
|
10
10
|
set (SKIA_SVG_LIB "svg")
|
11
11
|
set (SKIA_SKSHAPER_LIB "skshaper")
|
12
|
-
|
13
|
-
|
12
|
+
set (SKIA_SKPARAGRAPH_LIB "skparagraph")
|
13
|
+
set (SKIA_SKUNICODE_LIB "skunicode")
|
14
14
|
|
15
15
|
# Clear some variables
|
16
16
|
unset(LIBRN_DIR CACHE)
|
@@ -84,7 +84,7 @@ target_include_directories(
|
|
84
84
|
../cpp/skia/include/utils/
|
85
85
|
../cpp/skia/include/pathops/
|
86
86
|
../cpp/skia/modules/
|
87
|
-
|
87
|
+
../cpp/skia/modules/skparagraph/include/
|
88
88
|
../cpp/skia/include/
|
89
89
|
../cpp/skia
|
90
90
|
|
@@ -113,11 +113,11 @@ set_property(TARGET svg PROPERTY IMPORTED_LOCATION "${SKIA_LIBS_PATH}/libsvg.a")
|
|
113
113
|
add_library(skshaper STATIC IMPORTED)
|
114
114
|
set_property(TARGET skshaper PROPERTY IMPORTED_LOCATION "${SKIA_LIBS_PATH}/libskshaper.a")
|
115
115
|
|
116
|
-
|
117
|
-
|
116
|
+
add_library(skparagraph STATIC IMPORTED)
|
117
|
+
set_property(TARGET skparagraph PROPERTY IMPORTED_LOCATION "${SKIA_LIBS_PATH}/libskparagraph.a")
|
118
118
|
|
119
|
-
|
120
|
-
|
119
|
+
add_library(skunicode STATIC IMPORTED)
|
120
|
+
set_property(TARGET skunicode PROPERTY IMPORTED_LOCATION "${SKIA_LIBS_PATH}/libskunicode.a")
|
121
121
|
|
122
122
|
|
123
123
|
find_library(
|
@@ -202,8 +202,8 @@ target_link_libraries(
|
|
202
202
|
${TURBOMODULES_LIB}
|
203
203
|
${SKIA_SVG_LIB}
|
204
204
|
${SKIA_SKSHAPER_LIB}
|
205
|
-
|
206
|
-
|
205
|
+
${SKIA_SKPARAGRAPH_LIB}
|
206
|
+
${SKIA_SKUNICODE_LIB}
|
207
207
|
${SKIA_LIB}
|
208
208
|
-ljnigraphics
|
209
209
|
-lGLESv2
|
@@ -9,6 +9,13 @@
|
|
9
9
|
#include <RNSkPlatformContext.h>
|
10
10
|
#include <SkiaOpenGLSurfaceFactory.h>
|
11
11
|
|
12
|
+
#pragma clang diagnostic push
|
13
|
+
#pragma clang diagnostic ignored "-Wdocumentation"
|
14
|
+
|
15
|
+
#include "include/ports/SkFontMgr_android.h"
|
16
|
+
|
17
|
+
#pragma clang diagnostic pop
|
18
|
+
|
12
19
|
namespace RNSkia {
|
13
20
|
namespace jsi = facebook::jsi;
|
14
21
|
|
@@ -41,6 +48,10 @@ public:
|
|
41
48
|
return SkiaOpenGLSurfaceFactory::makeOffscreenSurface(width, height);
|
42
49
|
}
|
43
50
|
|
51
|
+
sk_sp<SkFontMgr> createFontMgr() override {
|
52
|
+
return SkFontMgr_New_Android(nullptr);
|
53
|
+
}
|
54
|
+
|
44
55
|
void runOnMainThread(std::function<void()> task) override {
|
45
56
|
_jniPlatformContext->runTaskOnMainThread(task);
|
46
57
|
}
|
package/cpp/api/JsiSkApi.h
CHANGED
@@ -12,6 +12,8 @@
|
|
12
12
|
#include "JsiSkContourMeasureIter.h"
|
13
13
|
#include "JsiSkDataFactory.h"
|
14
14
|
#include "JsiSkFont.h"
|
15
|
+
#include "JsiSkFontMgr.h"
|
16
|
+
#include "JsiSkFontMgrFactory.h"
|
15
17
|
#include "JsiSkImage.h"
|
16
18
|
#include "JsiSkImageFactory.h"
|
17
19
|
#include "JsiSkImageFilter.h"
|
@@ -39,6 +41,7 @@
|
|
39
41
|
#include "JsiSkShaderFactory.h"
|
40
42
|
#include "JsiSkSurfaceFactory.h"
|
41
43
|
#include "JsiSkTextBlobFactory.h"
|
44
|
+
#include "JsiSkTypeFaceFontProviderFactory.h"
|
42
45
|
#include "JsiSkTypeface.h"
|
43
46
|
#include "JsiSkTypefaceFactory.h"
|
44
47
|
#include "JsiSkVertices.h"
|
@@ -100,6 +103,11 @@ public:
|
|
100
103
|
std::make_shared<JsiSkSurfaceFactory>(context));
|
101
104
|
installReadonlyProperty("Picture",
|
102
105
|
std::make_shared<JsiSkPictureFactory>(context));
|
106
|
+
installReadonlyProperty("FontMgr",
|
107
|
+
std::make_shared<JsiSkFontMgrFactory>(context));
|
108
|
+
installReadonlyProperty(
|
109
|
+
"TypefaceFontProvider",
|
110
|
+
std::make_shared<JsiSkTypefaceFontProviderFactory>(context));
|
103
111
|
}
|
104
112
|
};
|
105
113
|
} // namespace RNSkia
|
@@ -0,0 +1,54 @@
|
|
1
|
+
#pragma once
|
2
|
+
|
3
|
+
#include <memory>
|
4
|
+
#include <numeric>
|
5
|
+
#include <utility>
|
6
|
+
#include <vector>
|
7
|
+
|
8
|
+
#include "JsiSkFontStyle.h"
|
9
|
+
#include "JsiSkHostObjects.h"
|
10
|
+
#include "RNSkLog.h"
|
11
|
+
#include <jsi/jsi.h>
|
12
|
+
|
13
|
+
#pragma clang diagnostic push
|
14
|
+
#pragma clang diagnostic ignored "-Wdocumentation"
|
15
|
+
|
16
|
+
#include "SkFontMgr.h"
|
17
|
+
|
18
|
+
#pragma clang diagnostic pop
|
19
|
+
|
20
|
+
namespace RNSkia {
|
21
|
+
|
22
|
+
namespace jsi = facebook::jsi;
|
23
|
+
|
24
|
+
class JsiSkFontMgr : public JsiSkWrappingSkPtrHostObject<SkFontMgr> {
|
25
|
+
public:
|
26
|
+
EXPORT_JSI_API_TYPENAME(JsiSkFontMgr, "FontMgr")
|
27
|
+
|
28
|
+
JsiSkFontMgr(std::shared_ptr<RNSkPlatformContext> context,
|
29
|
+
sk_sp<SkFontMgr> fontMgr)
|
30
|
+
: JsiSkWrappingSkPtrHostObject(std::move(context), fontMgr) {}
|
31
|
+
|
32
|
+
JSI_HOST_FUNCTION(countFamilies) { return getObject()->countFamilies(); }
|
33
|
+
|
34
|
+
JSI_HOST_FUNCTION(getFamilyName) {
|
35
|
+
auto i = static_cast<int>(arguments[0].asNumber());
|
36
|
+
SkString name;
|
37
|
+
getObject()->getFamilyName(i, &name);
|
38
|
+
return jsi::String::createFromUtf8(runtime, name.c_str());
|
39
|
+
}
|
40
|
+
|
41
|
+
JSI_HOST_FUNCTION(matchFamilyStyle) {
|
42
|
+
auto name = arguments[0].asString(runtime).utf8(runtime);
|
43
|
+
auto fontStyle = JsiSkFontStyle::fromValue(runtime, arguments[1]);
|
44
|
+
auto typeface = getObject()->matchFamilyStyle(name.c_str(), *fontStyle);
|
45
|
+
return jsi::Object::createFromHostObject(
|
46
|
+
runtime, std::make_shared<JsiSkTypeface>(getContext(), typeface));
|
47
|
+
}
|
48
|
+
|
49
|
+
JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkFontMgr, countFamilies),
|
50
|
+
JSI_EXPORT_FUNC(JsiSkFontMgr, getFamilyName),
|
51
|
+
JSI_EXPORT_FUNC(JsiSkFontMgr, matchFamilyStyle))
|
52
|
+
};
|
53
|
+
|
54
|
+
} // namespace RNSkia
|
@@ -0,0 +1,40 @@
|
|
1
|
+
#pragma once
|
2
|
+
|
3
|
+
#include <memory>
|
4
|
+
#include <utility>
|
5
|
+
#include <vector>
|
6
|
+
|
7
|
+
#include <jsi/jsi.h>
|
8
|
+
|
9
|
+
#include "JsiSkHostObjects.h"
|
10
|
+
|
11
|
+
#pragma clang diagnostic push
|
12
|
+
#pragma clang diagnostic ignored "-Wdocumentation"
|
13
|
+
|
14
|
+
#include "SkFontMgr.h"
|
15
|
+
#include "include/ports/SkFontMgr_data.h"
|
16
|
+
|
17
|
+
#pragma clang diagnostic pop
|
18
|
+
|
19
|
+
namespace RNSkia {
|
20
|
+
|
21
|
+
namespace jsi = facebook::jsi;
|
22
|
+
|
23
|
+
class JsiSkFontMgrFactory : public JsiSkHostObject {
|
24
|
+
public:
|
25
|
+
JSI_HOST_FUNCTION(System) {
|
26
|
+
auto context = getContext();
|
27
|
+
static SkOnce once;
|
28
|
+
static sk_sp<SkFontMgr> fontMgr;
|
29
|
+
once([&context, &runtime] { fontMgr = context->createFontMgr(); });
|
30
|
+
return jsi::Object::createFromHostObject(
|
31
|
+
runtime, std::make_shared<JsiSkFontMgr>(std::move(context), fontMgr));
|
32
|
+
}
|
33
|
+
|
34
|
+
JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkFontMgrFactory, System))
|
35
|
+
|
36
|
+
explicit JsiSkFontMgrFactory(std::shared_ptr<RNSkPlatformContext> context)
|
37
|
+
: JsiSkHostObject(std::move(context)) {}
|
38
|
+
};
|
39
|
+
|
40
|
+
} // namespace RNSkia
|
@@ -0,0 +1,61 @@
|
|
1
|
+
#pragma once
|
2
|
+
|
3
|
+
#include <memory>
|
4
|
+
#include <utility>
|
5
|
+
|
6
|
+
#include <jsi/jsi.h>
|
7
|
+
|
8
|
+
#include "JsiSkHostObjects.h"
|
9
|
+
|
10
|
+
#pragma clang diagnostic push
|
11
|
+
#pragma clang diagnostic ignored "-Wdocumentation"
|
12
|
+
|
13
|
+
#include "SkFontStyle.h"
|
14
|
+
|
15
|
+
#pragma clang diagnostic pop
|
16
|
+
|
17
|
+
namespace RNSkia {
|
18
|
+
|
19
|
+
namespace jsi = facebook::jsi;
|
20
|
+
|
21
|
+
class JsiSkFontStyle : public JsiSkWrappingSharedPtrHostObject<SkFontStyle> {
|
22
|
+
public:
|
23
|
+
JSI_API_TYPENAME("FontStyle");
|
24
|
+
|
25
|
+
JsiSkFontStyle(std::shared_ptr<RNSkPlatformContext> context,
|
26
|
+
const SkFontStyle &fontStyle)
|
27
|
+
: JsiSkWrappingSharedPtrHostObject<SkFontStyle>(
|
28
|
+
std::move(context), std::make_shared<SkFontStyle>(fontStyle)) {}
|
29
|
+
|
30
|
+
/**
|
31
|
+
Returns the underlying object from a host object of this type
|
32
|
+
*/
|
33
|
+
static std::shared_ptr<SkFontStyle> fromValue(jsi::Runtime &runtime,
|
34
|
+
const jsi::Value &obj) {
|
35
|
+
const auto &object = obj.asObject(runtime);
|
36
|
+
if (object.isHostObject(runtime)) {
|
37
|
+
return object.asHostObject<JsiSkFontStyle>(runtime)->getObject();
|
38
|
+
} else {
|
39
|
+
auto weight =
|
40
|
+
static_cast<int>(object.getProperty(runtime, "weight").asNumber());
|
41
|
+
auto width =
|
42
|
+
static_cast<int>(object.getProperty(runtime, "width").asNumber());
|
43
|
+
auto slant = static_cast<SkFontStyle::Slant>(
|
44
|
+
object.getProperty(runtime, "slant").asNumber());
|
45
|
+
SkFontStyle style(weight, width, slant);
|
46
|
+
return std::make_shared<SkFontStyle>(style);
|
47
|
+
}
|
48
|
+
}
|
49
|
+
|
50
|
+
/**
|
51
|
+
Returns the jsi object from a host object of this type
|
52
|
+
*/
|
53
|
+
static jsi::Value toValue(jsi::Runtime &runtime,
|
54
|
+
std::shared_ptr<RNSkPlatformContext> context,
|
55
|
+
const SkFontStyle &fontStyle) {
|
56
|
+
return jsi::Object::createFromHostObject(
|
57
|
+
runtime,
|
58
|
+
std::make_shared<JsiSkFontStyle>(std::move(context), fontStyle));
|
59
|
+
}
|
60
|
+
};
|
61
|
+
} // namespace RNSkia
|
@@ -0,0 +1,80 @@
|
|
1
|
+
#pragma once
|
2
|
+
|
3
|
+
#include <memory>
|
4
|
+
#include <utility>
|
5
|
+
|
6
|
+
#include <jsi/jsi.h>
|
7
|
+
|
8
|
+
#include "JsiSkFontStyle.h"
|
9
|
+
#include "JsiSkHostObjects.h"
|
10
|
+
#include "JsiSkTypeface.h"
|
11
|
+
|
12
|
+
#include "RNSkLog.h"
|
13
|
+
|
14
|
+
#pragma clang diagnostic push
|
15
|
+
#pragma clang diagnostic ignored "-Wdocumentation"
|
16
|
+
|
17
|
+
#include "SkFont.h"
|
18
|
+
#include "skparagraph/include/TypefaceFontProvider.h"
|
19
|
+
|
20
|
+
#pragma clang diagnostic pop
|
21
|
+
|
22
|
+
namespace RNSkia {
|
23
|
+
|
24
|
+
namespace jsi = facebook::jsi;
|
25
|
+
namespace para = skia::textlayout;
|
26
|
+
|
27
|
+
class JsiSkTypefaceFontProvider
|
28
|
+
: public JsiSkWrappingSkPtrHostObject<para::TypefaceFontProvider> {
|
29
|
+
public:
|
30
|
+
EXPORT_JSI_API_TYPENAME(JsiSkTypefaceFontProvider, "FontMgr")
|
31
|
+
JSI_EXPORT_FUNCTIONS(
|
32
|
+
JSI_EXPORT_FUNC(JsiSkTypefaceFontProvider, dispose),
|
33
|
+
JSI_EXPORT_FUNC(JsiSkTypefaceFontProvider, registerFont),
|
34
|
+
JSI_EXPORT_FUNC(JsiSkTypefaceFontProvider, matchFamilyStyle),
|
35
|
+
JSI_EXPORT_FUNC(JsiSkTypefaceFontProvider, countFamilies),
|
36
|
+
JSI_EXPORT_FUNC(JsiSkTypefaceFontProvider, getFamilyName))
|
37
|
+
|
38
|
+
JSI_HOST_FUNCTION(registerFont) {
|
39
|
+
sk_sp<SkTypeface> typeface =
|
40
|
+
JsiSkTypeface::fromValue(runtime, arguments[0]);
|
41
|
+
SkString familyName(arguments[1].asString(runtime).utf8(runtime).c_str());
|
42
|
+
auto result = getObject()->registerTypeface(typeface, familyName);
|
43
|
+
return jsi::Value::undefined();
|
44
|
+
}
|
45
|
+
|
46
|
+
JSI_HOST_FUNCTION(matchFamilyStyle) {
|
47
|
+
auto name = arguments[0].asString(runtime).utf8(runtime);
|
48
|
+
auto fontStyle = JsiSkFontStyle::fromValue(runtime, arguments[1]);
|
49
|
+
auto typeface = getObject()->matchFamilyStyle(name.c_str(), *fontStyle);
|
50
|
+
return jsi::Object::createFromHostObject(
|
51
|
+
runtime, std::make_shared<JsiSkTypeface>(getContext(), typeface));
|
52
|
+
}
|
53
|
+
|
54
|
+
JSI_HOST_FUNCTION(countFamilies) { return getObject()->countFamilies(); }
|
55
|
+
|
56
|
+
JSI_HOST_FUNCTION(getFamilyName) {
|
57
|
+
auto i = static_cast<int>(arguments[0].asNumber());
|
58
|
+
SkString name;
|
59
|
+
getObject()->getFamilyName(i, &name);
|
60
|
+
return jsi::String::createFromUtf8(runtime, name.c_str());
|
61
|
+
}
|
62
|
+
|
63
|
+
JsiSkTypefaceFontProvider(std::shared_ptr<RNSkPlatformContext> context,
|
64
|
+
sk_sp<para::TypefaceFontProvider> tfProvider)
|
65
|
+
: JsiSkWrappingSkPtrHostObject(std::move(context),
|
66
|
+
std::move(tfProvider)) {}
|
67
|
+
|
68
|
+
/**
|
69
|
+
Returns the jsi object from a host object of this type
|
70
|
+
*/
|
71
|
+
static jsi::Value toValue(jsi::Runtime &runtime,
|
72
|
+
std::shared_ptr<RNSkPlatformContext> context,
|
73
|
+
sk_sp<para::TypefaceFontProvider> tfProvider) {
|
74
|
+
return jsi::Object::createFromHostObject(
|
75
|
+
runtime, std::make_shared<JsiSkTypefaceFontProvider>(
|
76
|
+
std::move(context), std::move(tfProvider)));
|
77
|
+
}
|
78
|
+
};
|
79
|
+
|
80
|
+
} // namespace RNSkia
|
@@ -0,0 +1,32 @@
|
|
1
|
+
#pragma once
|
2
|
+
|
3
|
+
#include <memory>
|
4
|
+
#include <utility>
|
5
|
+
|
6
|
+
#include <jsi/jsi.h>
|
7
|
+
|
8
|
+
#include "JsiSkData.h"
|
9
|
+
#include "JsiSkHostObjects.h"
|
10
|
+
#include "JsiSkTypefaceFontProvider.h"
|
11
|
+
|
12
|
+
namespace RNSkia {
|
13
|
+
|
14
|
+
namespace jsi = facebook::jsi;
|
15
|
+
namespace para = skia::textlayout;
|
16
|
+
|
17
|
+
class JsiSkTypefaceFontProviderFactory : public JsiSkHostObject {
|
18
|
+
public:
|
19
|
+
JSI_HOST_FUNCTION(Make) {
|
20
|
+
return jsi::Object::createFromHostObject(
|
21
|
+
runtime, std::make_shared<JsiSkTypefaceFontProvider>(
|
22
|
+
getContext(), sk_make_sp<para::TypefaceFontProvider>()));
|
23
|
+
}
|
24
|
+
|
25
|
+
JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkTypefaceFontProviderFactory, Make))
|
26
|
+
|
27
|
+
explicit JsiSkTypefaceFontProviderFactory(
|
28
|
+
std::shared_ptr<RNSkPlatformContext> context)
|
29
|
+
: JsiSkHostObject(std::move(context)) {}
|
30
|
+
};
|
31
|
+
|
32
|
+
} // namespace RNSkia
|
@@ -15,6 +15,7 @@
|
|
15
15
|
#pragma clang diagnostic ignored "-Wdocumentation"
|
16
16
|
|
17
17
|
#include "SkData.h"
|
18
|
+
#include "SkFontMgr.h"
|
18
19
|
#include "SkImage.h"
|
19
20
|
#include "SkStream.h"
|
20
21
|
#include "SkSurface.h"
|
@@ -132,6 +133,11 @@ public:
|
|
132
133
|
*/
|
133
134
|
virtual sk_sp<SkSurface> makeOffscreenSurface(int width, int height) = 0;
|
134
135
|
|
136
|
+
/**
|
137
|
+
* Return the Platform specific font manager
|
138
|
+
*/
|
139
|
+
virtual sk_sp<SkFontMgr> createFontMgr() = 0;
|
140
|
+
|
135
141
|
/**
|
136
142
|
* Creates an skImage containing the screenshot of a native view and its
|
137
143
|
* children.
|
package/cpp/rnskia/RNSkView.h
CHANGED
@@ -93,6 +93,7 @@ public:
|
|
93
93
|
float height)
|
94
94
|
: RNSkCanvasProvider(requestRedraw), _width(width), _height(height) {
|
95
95
|
_surface = context->makeOffscreenSurface(_width, _height);
|
96
|
+
_pd = context->getPixelDensity();
|
96
97
|
}
|
97
98
|
|
98
99
|
/**
|
@@ -101,8 +102,9 @@ public:
|
|
101
102
|
sk_sp<SkImage> makeSnapshot(SkRect *bounds) {
|
102
103
|
sk_sp<SkImage> image;
|
103
104
|
if (bounds != nullptr) {
|
104
|
-
SkIRect b =
|
105
|
-
|
105
|
+
SkIRect b =
|
106
|
+
SkIRect::MakeXYWH(bounds->x() * _pd, bounds->y() * _pd,
|
107
|
+
bounds->width() * _pd, bounds->height() * _pd);
|
106
108
|
image = _surface->makeImageSnapshot(b);
|
107
109
|
} else {
|
108
110
|
image = _surface->makeImageSnapshot();
|
@@ -131,6 +133,7 @@ public:
|
|
131
133
|
private:
|
132
134
|
float _width;
|
133
135
|
float _height;
|
136
|
+
float _pd = 1.0f;
|
134
137
|
sk_sp<SkSurface> _surface;
|
135
138
|
};
|
136
139
|
|
@@ -19,7 +19,7 @@ class SkWriteBuffer;
|
|
19
19
|
* of `SkColorFilters::Table`, and provides a way to share the table data between client code and
|
20
20
|
* the returned SkColorFilter. Once created, an SkColorTable is immutable.
|
21
21
|
*/
|
22
|
-
class SkColorTable : public SkRefCnt {
|
22
|
+
class SK_API SkColorTable : public SkRefCnt {
|
23
23
|
public:
|
24
24
|
// Creates a new SkColorTable with 'table' used for all four channels. The table is copied into
|
25
25
|
// the SkColorTable.
|
@@ -6,13 +6,12 @@
|
|
6
6
|
#import <MetalKit/MetalKit.h>
|
7
7
|
#import <QuartzCore/CAMetalLayer.h>
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
9
|
+
#pragma clang diagnostic push
|
10
|
+
#pragma clang diagnostic ignored "-Wdocumentation"
|
11
|
+
|
12
|
+
#import <include/gpu/GrDirectContext.h>
|
13
13
|
|
14
|
-
|
15
|
-
renderContexts;
|
14
|
+
#pragma clang diagnostic pop
|
16
15
|
|
17
16
|
class RNSkMetalCanvasProvider : public RNSkia::RNSkCanvasProvider {
|
18
17
|
public:
|
@@ -27,17 +26,9 @@ public:
|
|
27
26
|
bool renderToCanvas(const std::function<void(SkCanvas *)> &cb) override;
|
28
27
|
|
29
28
|
void setSize(int width, int height);
|
30
|
-
|
31
29
|
CALayer *getLayer();
|
32
30
|
|
33
31
|
private:
|
34
|
-
/**
|
35
|
-
* To be able to use static contexts (and avoid reloading the skia context for
|
36
|
-
* each new view, we track the Skia drawing context per thread.
|
37
|
-
* @return The drawing context for the current thread
|
38
|
-
*/
|
39
|
-
static std::shared_ptr<MetalRenderContext> getMetalRenderContext();
|
40
|
-
|
41
32
|
std::shared_ptr<RNSkia::RNSkPlatformContext> _context;
|
42
33
|
float _width = -1;
|
43
34
|
float _height = -1;
|
@@ -1,5 +1,6 @@
|
|
1
1
|
#import <RNSkLog.h>
|
2
2
|
#import <RNSkMetalCanvasProvider.h>
|
3
|
+
#import <SkiaMetalSurfaceFactory.h>
|
3
4
|
|
4
5
|
#pragma clang diagnostic push
|
5
6
|
#pragma clang diagnostic ignored "-Wdocumentation"
|
@@ -14,19 +15,6 @@
|
|
14
15
|
|
15
16
|
#pragma clang diagnostic pop
|
16
17
|
|
17
|
-
/** Static members */
|
18
|
-
std::shared_ptr<MetalRenderContext>
|
19
|
-
RNSkMetalCanvasProvider::getMetalRenderContext() {
|
20
|
-
auto threadId = std::this_thread::get_id();
|
21
|
-
if (renderContexts.count(threadId) == 0) {
|
22
|
-
auto drawingContext = std::make_shared<MetalRenderContext>();
|
23
|
-
drawingContext->commandQueue = nullptr;
|
24
|
-
drawingContext->skContext = nullptr;
|
25
|
-
renderContexts.emplace(threadId, drawingContext);
|
26
|
-
}
|
27
|
-
return renderContexts.at(threadId);
|
28
|
-
}
|
29
|
-
|
30
18
|
RNSkMetalCanvasProvider::RNSkMetalCanvasProvider(
|
31
19
|
std::function<void()> requestRedraw,
|
32
20
|
std::shared_ptr<RNSkia::RNSkPlatformContext> context)
|
@@ -35,11 +23,8 @@ RNSkMetalCanvasProvider::RNSkMetalCanvasProvider(
|
|
35
23
|
#pragma clang diagnostic ignored "-Wunguarded-availability-new"
|
36
24
|
_layer = [CAMetalLayer layer];
|
37
25
|
#pragma clang diagnostic pop
|
38
|
-
|
39
|
-
auto device = MTLCreateSystemDefaultDevice();
|
40
|
-
|
41
26
|
_layer.framebufferOnly = NO;
|
42
|
-
_layer.device =
|
27
|
+
_layer.device = MTLCreateSystemDefaultDevice();
|
43
28
|
_layer.opaque = false;
|
44
29
|
_layer.contentsScale = _context->getPixelDensity();
|
45
30
|
_layer.pixelFormat = MTLPixelFormatBGRA8Unorm;
|
@@ -87,52 +72,18 @@ bool RNSkMetalCanvasProvider::renderToCanvas(
|
|
87
72
|
return false;
|
88
73
|
}
|
89
74
|
}
|
90
|
-
|
91
|
-
// Get render context for current thread
|
92
|
-
auto renderContext = getMetalRenderContext();
|
93
|
-
|
94
|
-
if (renderContext->skContext == nullptr) {
|
95
|
-
auto device = MTLCreateSystemDefaultDevice();
|
96
|
-
renderContext->commandQueue =
|
97
|
-
id<MTLCommandQueue>(CFRetain((GrMTLHandle)[device newCommandQueue]));
|
98
|
-
renderContext->skContext = GrDirectContext::MakeMetal(
|
99
|
-
(__bridge void *)device, (__bridge void *)renderContext->commandQueue);
|
100
|
-
}
|
101
|
-
|
102
75
|
// Wrap in auto release pool since we want the system to clean up after
|
103
76
|
// rendering and not wait until later - we've seen some example of memory
|
104
77
|
// usage growing very fast in the simulator without this.
|
105
78
|
@autoreleasepool {
|
106
|
-
|
107
|
-
/* It is super important that we use the pattern of calling nextDrawable
|
108
|
-
inside this autoreleasepool and not depend on Skia's
|
109
|
-
SkSurface::MakeFromCAMetalLayer to encapsulate since we're seeing a lot of
|
110
|
-
drawables leaking if they're not done this way.
|
111
|
-
|
112
|
-
This is now reverted from:
|
113
|
-
(https://github.com/Shopify/react-native-skia/commit/2e2290f8e6dfc6921f97b79f779d920fbc1acceb)
|
114
|
-
back to the original implementation.
|
115
|
-
*/
|
116
79
|
id<CAMetalDrawable> currentDrawable = [_layer nextDrawable];
|
117
80
|
if (currentDrawable == nullptr) {
|
118
81
|
return false;
|
119
82
|
}
|
120
83
|
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
GrBackendRenderTarget backendRT(_layer.drawableSize.width,
|
125
|
-
_layer.drawableSize.height, 1, fbInfo);
|
126
|
-
|
127
|
-
auto skSurface = SkSurfaces::WrapBackendRenderTarget(
|
128
|
-
renderContext->skContext.get(), backendRT, kTopLeft_GrSurfaceOrigin,
|
129
|
-
kBGRA_8888_SkColorType, nullptr, nullptr);
|
130
|
-
|
131
|
-
if (skSurface == nullptr || skSurface->getCanvas() == nullptr) {
|
132
|
-
RNSkia::RNSkLogger::logToConsole(
|
133
|
-
"Skia surface could not be created from parameters.");
|
134
|
-
return false;
|
135
|
-
}
|
84
|
+
auto skSurface = SkiaMetalSurfaceFactory::makeWindowedSurface(
|
85
|
+
currentDrawable.texture, _layer.drawableSize.width,
|
86
|
+
_layer.drawableSize.height);
|
136
87
|
|
137
88
|
SkCanvas *canvas = skSurface->getCanvas();
|
138
89
|
cb(canvas);
|
@@ -140,11 +91,11 @@ bool RNSkMetalCanvasProvider::renderToCanvas(
|
|
140
91
|
skSurface->flushAndSubmit();
|
141
92
|
|
142
93
|
id<MTLCommandBuffer> commandBuffer(
|
143
|
-
[
|
94
|
+
[ThreadContextHolder::ThreadSkiaMetalContext
|
95
|
+
.commandQueue commandBuffer]);
|
144
96
|
[commandBuffer presentDrawable:currentDrawable];
|
145
97
|
[commandBuffer commit];
|
146
98
|
}
|
147
|
-
|
148
99
|
return true;
|
149
100
|
};
|
150
101
|
|
@@ -64,6 +64,7 @@ public:
|
|
64
64
|
|
65
65
|
void raiseError(const std::exception &err) override;
|
66
66
|
sk_sp<SkSurface> makeOffscreenSurface(int width, int height) override;
|
67
|
+
sk_sp<SkFontMgr> createFontMgr() override;
|
67
68
|
|
68
69
|
void willInvalidateModules() {
|
69
70
|
// We need to do some house-cleaning here!
|
@@ -4,13 +4,16 @@
|
|
4
4
|
#include <thread>
|
5
5
|
#include <utility>
|
6
6
|
|
7
|
-
#include <
|
7
|
+
#include <SkiaMetalSurfaceFactory.h>
|
8
8
|
|
9
9
|
#pragma clang diagnostic push
|
10
10
|
#pragma clang diagnostic ignored "-Wdocumentation"
|
11
11
|
|
12
|
+
#include "SkFontMgr.h"
|
12
13
|
#include "SkSurface.h"
|
13
14
|
|
15
|
+
#include "include/ports/SkFontMgr_mac_ct.h"
|
16
|
+
|
14
17
|
#pragma clang diagnostic pop
|
15
18
|
|
16
19
|
namespace RNSkia {
|
@@ -59,7 +62,11 @@ void RNSkiOSPlatformContext::raiseError(const std::exception &err) {
|
|
59
62
|
|
60
63
|
sk_sp<SkSurface> RNSkiOSPlatformContext::makeOffscreenSurface(int width,
|
61
64
|
int height) {
|
62
|
-
return
|
65
|
+
return SkiaMetalSurfaceFactory::makeOffscreenSurface(width, height);
|
66
|
+
}
|
67
|
+
|
68
|
+
sk_sp<SkFontMgr> RNSkiOSPlatformContext::createFontMgr() {
|
69
|
+
return SkFontMgr_New_CoreText(nullptr);
|
63
70
|
}
|
64
71
|
|
65
72
|
void RNSkiOSPlatformContext::runOnMainThread(std::function<void()> func) {
|
@@ -0,0 +1,31 @@
|
|
1
|
+
#import <MetalKit/MetalKit.h>
|
2
|
+
|
3
|
+
#pragma clang diagnostic push
|
4
|
+
#pragma clang diagnostic ignored "-Wdocumentation"
|
5
|
+
|
6
|
+
#import "SkCanvas.h"
|
7
|
+
#import <include/gpu/GrDirectContext.h>
|
8
|
+
|
9
|
+
#pragma clang diagnostic pop
|
10
|
+
|
11
|
+
using SkiaMetalContext = struct SkiaMetalContext {
|
12
|
+
id<MTLCommandQueue> commandQueue = nullptr;
|
13
|
+
sk_sp<GrDirectContext> skContext = nullptr;
|
14
|
+
};
|
15
|
+
|
16
|
+
class ThreadContextHolder {
|
17
|
+
public:
|
18
|
+
static thread_local SkiaMetalContext ThreadSkiaMetalContext;
|
19
|
+
};
|
20
|
+
|
21
|
+
class SkiaMetalSurfaceFactory {
|
22
|
+
public:
|
23
|
+
static sk_sp<SkSurface> makeWindowedSurface(id<MTLTexture> texture, int width,
|
24
|
+
int height);
|
25
|
+
static sk_sp<SkSurface> makeOffscreenSurface(int width, int height);
|
26
|
+
|
27
|
+
private:
|
28
|
+
static id<MTLDevice> device;
|
29
|
+
static bool
|
30
|
+
createSkiaDirectContextIfNecessary(SkiaMetalContext *threadContext);
|
31
|
+
};
|