@shopify/react-native-skia 0.1.202 → 0.1.204

Sign up to get free protection for your applications and to get access to all the features.
Files changed (167) hide show
  1. package/android/CMakeLists.txt +9 -9
  2. package/android/cpp/jni/include/JniSkiaBaseView.h +0 -56
  3. package/android/cpp/jni/include/JniSkiaDomView.h +12 -20
  4. package/android/cpp/jni/include/JniSkiaDrawView.h +14 -20
  5. package/android/cpp/jni/include/JniSkiaPictureView.h +15 -24
  6. package/android/cpp/rnskia-android/RNSkAndroidPlatformContext.h +11 -0
  7. package/android/src/main/java/com/shopify/reactnative/skia/SkiaBaseView.java +32 -77
  8. package/android/src/main/java/com/shopify/reactnative/skia/SkiaBaseViewManager.java +1 -0
  9. package/android/src/main/java/com/shopify/reactnative/skia/SkiaDomView.java +0 -3
  10. package/android/src/main/java/com/shopify/reactnative/skia/SkiaDrawView.java +0 -3
  11. package/android/src/main/java/com/shopify/reactnative/skia/SkiaPictureView.java +0 -4
  12. package/cpp/api/JsiSkApi.h +8 -0
  13. package/cpp/api/JsiSkFontMgr.h +54 -0
  14. package/cpp/api/JsiSkFontMgrFactory.h +40 -0
  15. package/cpp/api/JsiSkFontStyle.h +61 -0
  16. package/cpp/api/JsiSkTypeFaceFontProvider.h +80 -0
  17. package/cpp/api/JsiSkTypeFaceFontProviderFactory.h +32 -0
  18. package/cpp/rnskia/RNSkPlatformContext.h +6 -0
  19. package/ios/RNSkia-iOS/RNSkiOSPlatformContext.h +1 -0
  20. package/ios/RNSkia-iOS/RNSkiOSPlatformContext.mm +7 -0
  21. package/lib/commonjs/skia/core/Data.d.ts +2 -0
  22. package/lib/commonjs/skia/core/Data.js +29 -1
  23. package/lib/commonjs/skia/core/Data.js.map +1 -1
  24. package/lib/commonjs/skia/core/Font.d.ts +14 -1
  25. package/lib/commonjs/skia/core/Font.js +93 -1
  26. package/lib/commonjs/skia/core/Font.js.map +1 -1
  27. package/lib/commonjs/skia/types/Font/FontMgr.d.ts +8 -0
  28. package/lib/commonjs/skia/types/Font/FontMgr.js +6 -0
  29. package/lib/commonjs/skia/types/Font/FontMgr.js.map +1 -0
  30. package/lib/commonjs/skia/types/Font/FontMgrFactory.d.ts +4 -0
  31. package/lib/commonjs/skia/types/Font/FontMgrFactory.js +6 -0
  32. package/lib/commonjs/skia/types/Font/FontMgrFactory.js.map +1 -0
  33. package/lib/commonjs/skia/types/Font/index.d.ts +2 -0
  34. package/lib/commonjs/skia/types/Font/index.js +26 -0
  35. package/lib/commonjs/skia/types/Font/index.js.map +1 -1
  36. package/lib/commonjs/skia/types/Paragraph/TypefaceFontProvider.d.ts +10 -0
  37. package/lib/commonjs/skia/types/Paragraph/TypefaceFontProvider.js +6 -0
  38. package/lib/commonjs/skia/types/Paragraph/TypefaceFontProvider.js.map +1 -0
  39. package/lib/commonjs/skia/types/Paragraph/TypefaceFontProviderFactory.d.ts +4 -0
  40. package/lib/commonjs/skia/types/Paragraph/TypefaceFontProviderFactory.js +6 -0
  41. package/lib/commonjs/skia/types/Paragraph/TypefaceFontProviderFactory.js.map +1 -0
  42. package/lib/commonjs/skia/types/Skia.d.ts +4 -1
  43. package/lib/commonjs/skia/types/Skia.js.map +1 -1
  44. package/lib/commonjs/skia/web/Host.d.ts +1 -1
  45. package/lib/commonjs/skia/web/Host.js +0 -2
  46. package/lib/commonjs/skia/web/Host.js.map +1 -1
  47. package/lib/commonjs/skia/web/JsiSkFontMgr.d.ts +10 -0
  48. package/lib/commonjs/skia/web/JsiSkFontMgr.js +34 -0
  49. package/lib/commonjs/skia/web/JsiSkFontMgr.js.map +1 -0
  50. package/lib/commonjs/skia/web/JsiSkFontMgrFactory.d.ts +8 -0
  51. package/lib/commonjs/skia/web/JsiSkFontMgrFactory.js +32 -0
  52. package/lib/commonjs/skia/web/JsiSkFontMgrFactory.js.map +1 -0
  53. package/lib/commonjs/skia/web/JsiSkTypefaceFontProvider.d.ts +13 -0
  54. package/lib/commonjs/skia/web/JsiSkTypefaceFontProvider.js +90 -0
  55. package/lib/commonjs/skia/web/JsiSkTypefaceFontProvider.js.map +1 -0
  56. package/lib/commonjs/skia/web/JsiSkTypefaceFontProviderFactory.d.ts +7 -0
  57. package/lib/commonjs/skia/web/JsiSkTypefaceFontProviderFactory.js +25 -0
  58. package/lib/commonjs/skia/web/JsiSkTypefaceFontProviderFactory.js.map +1 -0
  59. package/lib/commonjs/skia/web/JsiSkia.js +7 -1
  60. package/lib/commonjs/skia/web/JsiSkia.js.map +1 -1
  61. package/lib/module/skia/core/Data.d.ts +2 -0
  62. package/lib/module/skia/core/Data.js +24 -1
  63. package/lib/module/skia/core/Data.js.map +1 -1
  64. package/lib/module/skia/core/Font.d.ts +14 -1
  65. package/lib/module/skia/core/Font.js +83 -1
  66. package/lib/module/skia/core/Font.js.map +1 -1
  67. package/lib/module/skia/types/Font/FontMgr.d.ts +8 -0
  68. package/lib/module/skia/types/Font/FontMgr.js +2 -0
  69. package/lib/module/skia/types/Font/FontMgr.js.map +1 -0
  70. package/lib/module/skia/types/Font/FontMgrFactory.d.ts +4 -0
  71. package/lib/module/skia/types/Font/FontMgrFactory.js +2 -0
  72. package/lib/module/skia/types/Font/FontMgrFactory.js.map +1 -0
  73. package/lib/module/skia/types/Font/index.d.ts +2 -0
  74. package/lib/module/skia/types/Font/index.js +2 -0
  75. package/lib/module/skia/types/Font/index.js.map +1 -1
  76. package/lib/module/skia/types/Paragraph/TypefaceFontProvider.d.ts +10 -0
  77. package/lib/module/skia/types/Paragraph/TypefaceFontProvider.js +2 -0
  78. package/lib/module/skia/types/Paragraph/TypefaceFontProvider.js.map +1 -0
  79. package/lib/module/skia/types/Paragraph/TypefaceFontProviderFactory.d.ts +4 -0
  80. package/lib/module/skia/types/Paragraph/TypefaceFontProviderFactory.js +2 -0
  81. package/lib/module/skia/types/Paragraph/TypefaceFontProviderFactory.js.map +1 -0
  82. package/lib/module/skia/types/Skia.d.ts +4 -1
  83. package/lib/module/skia/types/Skia.js.map +1 -1
  84. package/lib/module/skia/web/Host.d.ts +1 -1
  85. package/lib/module/skia/web/Host.js +0 -2
  86. package/lib/module/skia/web/Host.js.map +1 -1
  87. package/lib/module/skia/web/JsiSkFontMgr.d.ts +10 -0
  88. package/lib/module/skia/web/JsiSkFontMgr.js +24 -0
  89. package/lib/module/skia/web/JsiSkFontMgr.js.map +1 -0
  90. package/lib/module/skia/web/JsiSkFontMgrFactory.d.ts +8 -0
  91. package/lib/module/skia/web/JsiSkFontMgrFactory.js +21 -0
  92. package/lib/module/skia/web/JsiSkFontMgrFactory.js.map +1 -0
  93. package/lib/module/skia/web/JsiSkTypefaceFontProvider.d.ts +13 -0
  94. package/lib/module/skia/web/JsiSkTypefaceFontProvider.js +80 -0
  95. package/lib/module/skia/web/JsiSkTypefaceFontProvider.js.map +1 -0
  96. package/lib/module/skia/web/JsiSkTypefaceFontProviderFactory.d.ts +7 -0
  97. package/lib/module/skia/web/JsiSkTypefaceFontProviderFactory.js +14 -0
  98. package/lib/module/skia/web/JsiSkTypefaceFontProviderFactory.js.map +1 -0
  99. package/lib/module/skia/web/JsiSkia.js +5 -1
  100. package/lib/module/skia/web/JsiSkia.js.map +1 -1
  101. package/lib/typescript/src/skia/core/Data.d.ts +2 -0
  102. package/lib/typescript/src/skia/core/Font.d.ts +14 -1
  103. package/lib/typescript/src/skia/types/Font/FontMgr.d.ts +8 -0
  104. package/lib/typescript/src/skia/types/Font/FontMgrFactory.d.ts +4 -0
  105. package/lib/typescript/src/skia/types/Font/index.d.ts +2 -0
  106. package/lib/typescript/src/skia/types/Paragraph/TypefaceFontProvider.d.ts +10 -0
  107. package/lib/typescript/src/skia/types/Paragraph/TypefaceFontProviderFactory.d.ts +4 -0
  108. package/lib/typescript/src/skia/types/Skia.d.ts +4 -1
  109. package/lib/typescript/src/skia/web/Host.d.ts +1 -1
  110. package/lib/typescript/src/skia/web/JsiSkFontMgr.d.ts +10 -0
  111. package/lib/typescript/src/skia/web/JsiSkFontMgrFactory.d.ts +8 -0
  112. package/lib/typescript/src/skia/web/JsiSkTypefaceFontProvider.d.ts +13 -0
  113. package/lib/typescript/src/skia/web/JsiSkTypefaceFontProviderFactory.d.ts +7 -0
  114. package/libs/android/arm64-v8a/libskia.a +0 -0
  115. package/libs/android/arm64-v8a/libskottie.a +0 -0
  116. package/libs/android/arm64-v8a/libskparagraph.a +0 -0
  117. package/libs/android/arm64-v8a/libskshaper.a +0 -0
  118. package/libs/android/arm64-v8a/libskunicode.a +0 -0
  119. package/libs/android/armeabi-v7a/libskia.a +0 -0
  120. package/libs/android/armeabi-v7a/libskottie.a +0 -0
  121. package/libs/android/armeabi-v7a/libskparagraph.a +0 -0
  122. package/libs/android/armeabi-v7a/libskshaper.a +0 -0
  123. package/libs/android/armeabi-v7a/libskunicode.a +0 -0
  124. package/libs/android/x86/libskia.a +0 -0
  125. package/libs/android/x86/libskottie.a +0 -0
  126. package/libs/android/x86/libskparagraph.a +0 -0
  127. package/libs/android/x86/libskshaper.a +0 -0
  128. package/libs/android/x86/libskunicode.a +0 -0
  129. package/libs/android/x86_64/libskia.a +0 -0
  130. package/libs/android/x86_64/libskottie.a +0 -0
  131. package/libs/android/x86_64/libskparagraph.a +0 -0
  132. package/libs/android/x86_64/libskshaper.a +0 -0
  133. package/libs/android/x86_64/libskunicode.a +0 -0
  134. package/libs/ios/libskia.xcframework/Info.plist +5 -5
  135. package/libs/ios/libskia.xcframework/ios-arm64_arm64e/libskia.a +0 -0
  136. package/libs/ios/libskia.xcframework/ios-arm64_arm64e_x86_64-simulator/libskia.a +0 -0
  137. package/libs/ios/libskottie.xcframework/ios-arm64_arm64e/libskottie.a +0 -0
  138. package/libs/ios/libskottie.xcframework/ios-arm64_arm64e_x86_64-simulator/libskottie.a +0 -0
  139. package/libs/ios/libskparagraph.xcframework/Info.plist +42 -0
  140. package/libs/ios/libskparagraph.xcframework/ios-arm64_arm64e/libskparagraph.a +0 -0
  141. package/libs/ios/libskparagraph.xcframework/ios-arm64_arm64e_x86_64-simulator/libskparagraph.a +0 -0
  142. package/libs/ios/libsksg.xcframework/ios-arm64_arm64e/libsksg.a +0 -0
  143. package/libs/ios/libsksg.xcframework/ios-arm64_arm64e_x86_64-simulator/libsksg.a +0 -0
  144. package/libs/ios/libskshaper.xcframework/ios-arm64_arm64e/libskshaper.a +0 -0
  145. package/libs/ios/libskshaper.xcframework/ios-arm64_arm64e_x86_64-simulator/libskshaper.a +0 -0
  146. package/libs/ios/libskunicode.xcframework/Info.plist +42 -0
  147. package/libs/ios/libskunicode.xcframework/ios-arm64_arm64e/libskunicode.a +0 -0
  148. package/libs/ios/libskunicode.xcframework/ios-arm64_arm64e_x86_64-simulator/libskunicode.a +0 -0
  149. package/libs/ios/libsvg.xcframework/Info.plist +5 -5
  150. package/libs/ios/libsvg.xcframework/ios-arm64_arm64e/libsvg.a +0 -0
  151. package/libs/ios/libsvg.xcframework/ios-arm64_arm64e_x86_64-simulator/libsvg.a +0 -0
  152. package/package.json +3 -1
  153. package/react-native-skia.podspec +2 -2
  154. package/src/skia/core/Data.ts +31 -1
  155. package/src/skia/core/Font.ts +109 -2
  156. package/src/skia/types/Font/FontMgr.ts +10 -0
  157. package/src/skia/types/Font/FontMgrFactory.ts +5 -0
  158. package/src/skia/types/Font/index.ts +2 -0
  159. package/src/skia/types/Paragraph/TypefaceFontProvider.ts +11 -0
  160. package/src/skia/types/Paragraph/TypefaceFontProviderFactory.ts +5 -0
  161. package/src/skia/types/Skia.ts +4 -2
  162. package/src/skia/web/Host.ts +1 -1
  163. package/src/skia/web/JsiSkFontMgr.ts +26 -0
  164. package/src/skia/web/JsiSkFontMgrFactory.ts +22 -0
  165. package/src/skia/web/JsiSkTypefaceFontProvider.ts +89 -0
  166. package/src/skia/web/JsiSkTypefaceFontProviderFactory.ts +18 -0
  167. package/src/skia/web/JsiSkia.ts +4 -0
@@ -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
- #set (SKIA_SKPARAGRAPH_LIB "skparagraph")
13
- #set (SKIA_SKUNICODE_LIB "skunicode")
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
- #cpp/skia/modules/skparagraph/include/
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
- #add_library(skparagraph STATIC IMPORTED)
117
- #set_property(TARGET skparagraph PROPERTY IMPORTED_LOCATION "${SKIA_LIBS_PATH}/libskparagraph.a")
116
+ add_library(skparagraph STATIC IMPORTED)
117
+ set_property(TARGET skparagraph PROPERTY IMPORTED_LOCATION "${SKIA_LIBS_PATH}/libskparagraph.a")
118
118
 
119
- #add_library(skunicode STATIC IMPORTED)
120
- #set_property(TARGET skunicode PROPERTY IMPORTED_LOCATION "${SKIA_LIBS_PATH}/libskunicode.a")
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
- #${SKIA_SKPARAGRAPH_LIB}
206
- #${SKIA_SKUNICODE_LIB}
205
+ ${SKIA_SKPARAGRAPH_LIB}
206
+ ${SKIA_SKUNICODE_LIB}
207
207
  ${SKIA_LIB}
208
208
  -ljnigraphics
209
209
  -lGLESv2
@@ -62,62 +62,6 @@ protected:
62
62
  _skiaAndroidView->viewDidUnmount();
63
63
  }
64
64
 
65
- /**
66
- * Android specific method for rendering an offscreen GPU buffer to an Android
67
- * bitmap. The result can be used to render the first frame of the Skia render
68
- * to avoid flickering on android.
69
- */
70
- /*
71
- // TODO: Remove if we find another solution for first frame rendering
72
- // protected native Object renderToBitmap(Object bitmap, int width, int
73
- height); virtual jobject renderToBitmap(jobject bitmapIn, int width, int
74
- height) { auto platformContext = getSkiaManager()->getPlatformContext(); auto
75
- provider = std::make_shared<RNSkOffscreenCanvasProvider>( platformContext,
76
- []() {}, width, height);
77
-
78
- // Render into a gpu backed buffer
79
- _skiaAndroidView->getSkiaView()->getRenderer()->renderImmediate(provider);
80
- auto rect = SkRect::MakeXYWH(0, 0, width, height);
81
- auto image = provider->makeSnapshot(&rect);
82
-
83
- AndroidBitmapInfo infoIn;
84
- auto env = facebook::jni::Environment::current();
85
- void *pixels;
86
-
87
- // Get image info
88
- if (AndroidBitmap_getInfo(env, bitmapIn, &infoIn) !=
89
- ANDROID_BITMAP_RESULT_SUCCESS) {
90
- return env->NewStringUTF("failed");
91
- }
92
-
93
- // Check image
94
- if (infoIn.format != ANDROID_BITMAP_FORMAT_RGBA_8888 &&
95
- infoIn.format != ANDROID_BITMAP_FORMAT_RGB_565) {
96
- return env->NewStringUTF("Only support ANDROID_BITMAP_FORMAT_RGBA_8888 "
97
- "and ANDROID_BITMAP_FORMAT_RGB_565");
98
- }
99
-
100
- auto imageInfo = SkImageInfo::Make(image->width(), image->height(),
101
- image->colorType(), image->alphaType());
102
-
103
- // Lock all images
104
- if (AndroidBitmap_lockPixels(env, bitmapIn, &pixels) !=
105
- ANDROID_BITMAP_RESULT_SUCCESS) {
106
- return env->NewStringUTF("AndroidBitmap_lockPixels failed!");
107
- }
108
-
109
- // Set pixels from SkImage
110
- image->readPixels(imageInfo, pixels, imageInfo.minRowBytes(), 0, 0);
111
-
112
- // Unlocks everything
113
- AndroidBitmap_unlockPixels(env, bitmapIn);
114
-
115
- image = nullptr;
116
- provider = nullptr;
117
-
118
- return bitmapIn;
119
- }*/
120
-
121
65
  private:
122
66
  JniSkiaManager *_manager;
123
67
  std::shared_ptr<RNSkBaseAndroidView> _skiaAndroidView;
@@ -34,21 +34,18 @@ public:
34
34
  }
35
35
 
36
36
  static void registerNatives() {
37
- registerHybrid({
38
- makeNativeMethod("initHybrid", JniSkiaDomView::initHybrid),
39
- makeNativeMethod("surfaceAvailable", JniSkiaDomView::surfaceAvailable),
40
- makeNativeMethod("surfaceDestroyed", JniSkiaDomView::surfaceDestroyed),
41
- makeNativeMethod("surfaceSizeChanged",
42
- JniSkiaDomView::surfaceSizeChanged),
43
- makeNativeMethod("setMode", JniSkiaDomView::setMode),
44
- makeNativeMethod("setDebugMode", JniSkiaDomView::setDebugMode),
45
- makeNativeMethod("updateTouchPoints",
46
- JniSkiaDomView::updateTouchPoints),
47
- makeNativeMethod("registerView", JniSkiaDomView::registerView),
48
- makeNativeMethod("unregisterView", JniSkiaDomView::unregisterView)
49
- // TODO: Remove if we find another solution for first frame rendering
50
- // makeNativeMethod("renderToBitmap", JniSkiaDomView::renderToBitmap)
51
- });
37
+ registerHybrid(
38
+ {makeNativeMethod("initHybrid", JniSkiaDomView::initHybrid),
39
+ makeNativeMethod("surfaceAvailable", JniSkiaDomView::surfaceAvailable),
40
+ makeNativeMethod("surfaceDestroyed", JniSkiaDomView::surfaceDestroyed),
41
+ makeNativeMethod("surfaceSizeChanged",
42
+ JniSkiaDomView::surfaceSizeChanged),
43
+ makeNativeMethod("setMode", JniSkiaDomView::setMode),
44
+ makeNativeMethod("setDebugMode", JniSkiaDomView::setDebugMode),
45
+ makeNativeMethod("updateTouchPoints",
46
+ JniSkiaDomView::updateTouchPoints),
47
+ makeNativeMethod("registerView", JniSkiaDomView::registerView),
48
+ makeNativeMethod("unregisterView", JniSkiaDomView::unregisterView)});
52
49
  }
53
50
 
54
51
  protected:
@@ -76,11 +73,6 @@ protected:
76
73
 
77
74
  void unregisterView() override { JniSkiaBaseView::unregisterView(); }
78
75
 
79
- // TODO: Remove if we find another solution for first frame rendering
80
- /*jobject renderToBitmap(jobject bitmap, int width, int height) override {
81
- return JniSkiaBaseView::renderToBitmap(bitmap, width, height);
82
- }*/
83
-
84
76
  private:
85
77
  friend HybridBase;
86
78
 
@@ -33,21 +33,20 @@ public:
33
33
  }
34
34
 
35
35
  static void registerNatives() {
36
- registerHybrid({
37
- makeNativeMethod("initHybrid", JniSkiaDrawView::initHybrid),
38
- makeNativeMethod("surfaceAvailable", JniSkiaDrawView::surfaceAvailable),
39
- makeNativeMethod("surfaceDestroyed", JniSkiaDrawView::surfaceDestroyed),
40
- makeNativeMethod("surfaceSizeChanged",
41
- JniSkiaDrawView::surfaceSizeChanged),
42
- makeNativeMethod("setMode", JniSkiaDrawView::setMode),
43
- makeNativeMethod("setDebugMode", JniSkiaDrawView::setDebugMode),
44
- makeNativeMethod("updateTouchPoints",
45
- JniSkiaDrawView::updateTouchPoints),
46
- makeNativeMethod("registerView", JniSkiaDrawView::registerView),
47
- makeNativeMethod("unregisterView", JniSkiaDrawView::unregisterView),
48
- // TODO: Remove if we find another solution for first frame rendering
49
- // makeNativeMethod("renderToBitmap", JniSkiaDrawView::renderToBitmap)
50
- });
36
+ registerHybrid(
37
+ {makeNativeMethod("initHybrid", JniSkiaDrawView::initHybrid),
38
+ makeNativeMethod("surfaceAvailable",
39
+ JniSkiaDrawView::surfaceAvailable),
40
+ makeNativeMethod("surfaceDestroyed",
41
+ JniSkiaDrawView::surfaceDestroyed),
42
+ makeNativeMethod("surfaceSizeChanged",
43
+ JniSkiaDrawView::surfaceSizeChanged),
44
+ makeNativeMethod("setMode", JniSkiaDrawView::setMode),
45
+ makeNativeMethod("setDebugMode", JniSkiaDrawView::setDebugMode),
46
+ makeNativeMethod("updateTouchPoints",
47
+ JniSkiaDrawView::updateTouchPoints),
48
+ makeNativeMethod("registerView", JniSkiaDrawView::registerView),
49
+ makeNativeMethod("unregisterView", JniSkiaDrawView::unregisterView)});
51
50
  }
52
51
 
53
52
  protected:
@@ -75,11 +74,6 @@ protected:
75
74
 
76
75
  void unregisterView() override { JniSkiaBaseView::unregisterView(); }
77
76
 
78
- // TODO: Remove if we find another solution for first frame rendering
79
- /*jobject renderToBitmap(jobject bitmap, int width, int height) override {
80
- return JniSkiaBaseView::renderToBitmap(bitmap, width, height);
81
- }*/
82
-
83
77
  private:
84
78
  friend HybridBase;
85
79
 
@@ -33,24 +33,21 @@ public:
33
33
  }
34
34
 
35
35
  static void registerNatives() {
36
- registerHybrid({
37
- makeNativeMethod("initHybrid", JniSkiaPictureView::initHybrid),
38
- makeNativeMethod("surfaceAvailable",
39
- JniSkiaPictureView::surfaceAvailable),
40
- makeNativeMethod("surfaceDestroyed",
41
- JniSkiaPictureView::surfaceDestroyed),
42
- makeNativeMethod("surfaceSizeChanged",
43
- JniSkiaPictureView::surfaceSizeChanged),
44
- makeNativeMethod("setMode", JniSkiaPictureView::setMode),
45
- makeNativeMethod("setDebugMode", JniSkiaPictureView::setDebugMode),
46
- makeNativeMethod("updateTouchPoints",
47
- JniSkiaPictureView::updateTouchPoints),
48
- makeNativeMethod("registerView", JniSkiaPictureView::registerView),
49
- makeNativeMethod("unregisterView", JniSkiaPictureView::unregisterView),
50
- // TODO: Remove if we find another solution for first frame rendering
51
- // makeNativeMethod("renderToBitmap",
52
- // JniSkiaPictureView::renderToBitmap)
53
- });
36
+ registerHybrid(
37
+ {makeNativeMethod("initHybrid", JniSkiaPictureView::initHybrid),
38
+ makeNativeMethod("surfaceAvailable",
39
+ JniSkiaPictureView::surfaceAvailable),
40
+ makeNativeMethod("surfaceDestroyed",
41
+ JniSkiaPictureView::surfaceDestroyed),
42
+ makeNativeMethod("surfaceSizeChanged",
43
+ JniSkiaPictureView::surfaceSizeChanged),
44
+ makeNativeMethod("setMode", JniSkiaPictureView::setMode),
45
+ makeNativeMethod("setDebugMode", JniSkiaPictureView::setDebugMode),
46
+ makeNativeMethod("updateTouchPoints",
47
+ JniSkiaPictureView::updateTouchPoints),
48
+ makeNativeMethod("registerView", JniSkiaPictureView::registerView),
49
+ makeNativeMethod("unregisterView",
50
+ JniSkiaPictureView::unregisterView)});
54
51
  }
55
52
 
56
53
  protected:
@@ -78,12 +75,6 @@ protected:
78
75
 
79
76
  void unregisterView() override { JniSkiaBaseView::unregisterView(); }
80
77
 
81
- /*
82
- TODO: Remove if we find another solution for first frame rendering
83
- jobject renderToBitmap(jobject bitmap, int width, int height) override {
84
- return JniSkiaBaseView::renderToBitmap(bitmap, width, height);
85
- }*/
86
-
87
78
  private:
88
79
  friend HybridBase;
89
80
 
@@ -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
  }
@@ -9,53 +9,51 @@ import android.view.TextureView;
9
9
 
10
10
  import com.facebook.jni.annotations.DoNotStrip;
11
11
  import com.facebook.react.views.view.ReactViewGroup;
12
+
12
13
  public abstract class SkiaBaseView extends ReactViewGroup implements TextureView.SurfaceTextureListener {
13
14
 
14
15
  @DoNotStrip
15
16
  private Surface mSurface;
16
17
  private TextureView mTexture;
17
18
 
19
+ private String tag = "SkiaView";
20
+
18
21
  public SkiaBaseView(Context context) {
19
22
  super(context);
20
- // TODO: Remove if we find another solution for first frame rendering
21
- //setWillNotDraw(!shouldRenderFirstFrameAsBitmap());
22
23
  mTexture = new TextureView(context);
23
24
  mTexture.setSurfaceTextureListener(this);
24
25
  mTexture.setOpaque(false);
25
26
  addView(mTexture);
26
27
  }
27
28
 
28
- /*@Override
29
- TODO: Remove if we find another solution for first frame rendering
30
- protected void onDraw(Canvas canvas) {
31
- super.onDraw(canvas);
32
-
33
- // If we haven't got a surface yet, let's ask the view to
34
- // draw into a bitmap and then render the bitmap. This method
35
- // is typically only called once - for the first frame, and
36
- // then the surface will be available and all rendering will
37
- // be done directly to the surface itself.
38
- if (shouldRenderFirstFrameAsBitmap() && mSurface == null) {
39
- int width = getWidth();
40
- int height = getHeight();
41
-
42
- if (width > 0 && height > 0) {
43
- Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
44
- Bitmap result = (Bitmap) renderToBitmap(bitmap, width, height);
45
-
46
- canvas.drawBitmap(
47
- result,
48
- new Rect(0, 0, width, height),
49
- new Rect(0, 0, width, height),
50
- null);
51
-
52
- bitmap.recycle();
53
- }
29
+ public void destroySurface() {
30
+ Log.i(tag, "destroySurface");
31
+ surfaceDestroyed();
32
+ mSurface.release();
33
+ mSurface = null;
34
+ }
35
+
36
+ private void createSurfaceTexture() {
37
+ // This API Level is >= 26, we created our own SurfaceTexture to have a faster time to first frame
38
+ if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
39
+ Log.i(tag, "Create SurfaceTexture");
40
+ SurfaceTexture surface = new SurfaceTexture(false);
41
+ mTexture.setSurfaceTexture(surface);
42
+ this.onSurfaceTextureAvailable(surface, this.getMeasuredWidth(), this.getMeasuredHeight());
43
+ }
44
+ }
45
+
46
+ @Override
47
+ protected void onAttachedToWindow() {
48
+ super.onAttachedToWindow();
49
+ if (this.getMeasuredWidth() == 0) {
50
+ createSurfaceTexture();
54
51
  }
55
- }*/
52
+ }
56
53
 
57
54
  @Override
58
55
  protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
56
+ Log.i(tag, "onLayout " + this.getMeasuredWidth() + "/" + this.getMeasuredHeight());
59
57
  super.onLayout(changed, left, top, right, bottom);
60
58
  mTexture.layout(0, 0, this.getMeasuredWidth(), this.getMeasuredHeight());
61
59
  }
@@ -132,52 +130,23 @@ public abstract class SkiaBaseView extends ReactViewGroup implements TextureView
132
130
 
133
131
  @Override
134
132
  public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) {
135
- Log.i("SkiaBaseView", "onSurfaceTextureAvailable " + width + "/" + height);
133
+ Log.i(tag, "onSurfaceTextureAvailable " + width + "/" + height);
136
134
  mSurface = new Surface(surface);
137
135
  surfaceAvailable(mSurface, width, height);
138
-
139
- /*
140
- TODO: Remove if we find another solution for first frame rendering
141
- // Clear rendered bitmap when the surface texture has rendered
142
- // We'll post a message to the main loop asking to invalidate
143
- if (shouldRenderFirstFrameAsBitmap()) {
144
- postUpdate(new AtomicInteger());
145
- }*/
146
136
  }
147
137
 
148
- /**
149
- * This method is a way for us to clear the bitmap rendered on the first frame
150
- * after at least 16 frames have passed - to avoid seeing blinks on the screen caused by
151
- * TextureView frame sync issues. This is a hack to avoid those pesky blinks. Have no
152
- * idea on how to sync the TextureView OpenGL updates.
153
- * @param counter
154
- */
155
- /*
156
- TODO: Remove if we find another solution for first frame rendering
157
- void postUpdate(AtomicInteger counter) {
158
- counter.getAndIncrement();
159
- if (counter.get() > 16) {
160
- invalidate();
161
- } else {
162
- this.post(() -> {
163
- postUpdate(counter);
164
- });
165
- }
166
- }*/
167
-
168
138
  @Override
169
139
  public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) {
170
- Log.i("SkiaBaseView", "onSurfaceTextureSizeChanged " + width + "/" + height);
140
+ Log.i(tag, "onSurfaceTextureSizeChanged " + width + "/" + height);
171
141
  surfaceSizeChanged(width, height);
172
142
  }
173
143
 
174
144
  @Override
175
145
  public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
176
- Log.i("SkiaBaseView", "onSurfaceTextureDestroyed");
146
+ Log.i(tag, "onSurfaceTextureDestroyed");
177
147
  // https://developer.android.com/reference/android/view/TextureView.SurfaceTextureListener#onSurfaceTextureDestroyed(android.graphics.SurfaceTexture)
178
- surfaceDestroyed();
179
- mSurface.release();
180
- mSurface = null;
148
+ destroySurface();
149
+ createSurfaceTexture();
181
150
  return false;
182
151
  }
183
152
 
@@ -186,17 +155,6 @@ public abstract class SkiaBaseView extends ReactViewGroup implements TextureView
186
155
  // Nothing special to do here
187
156
  }
188
157
 
189
- /**
190
- * Returns true if the view is able to directly render on the
191
- * main thread. This can f.ex then be used to create a first frame
192
- * render of the view. Returns true by default - override if not.
193
- */
194
- /*
195
- TODO: Remove if we find another solution for first frame rendering
196
- protected boolean shouldRenderFirstFrameAsBitmap() {
197
- return false;
198
- }*/
199
-
200
158
  protected abstract void surfaceAvailable(Object surface, int width, int height);
201
159
 
202
160
  protected abstract void surfaceSizeChanged(int width, int height);
@@ -212,7 +170,4 @@ public abstract class SkiaBaseView extends ReactViewGroup implements TextureView
212
170
  protected abstract void registerView(int nativeId);
213
171
 
214
172
  protected abstract void unregisterView();
215
-
216
- // TODO: Remove if we find another solution for first frame rendering
217
- // protected native Object renderToBitmap(Object bitmap, int width, int height);
218
173
  }
@@ -30,5 +30,6 @@ public abstract class SkiaBaseViewManager extends ReactViewManager {
30
30
  public void onDropViewInstance(@NonNull ReactViewGroup view) {
31
31
  super.onDropViewInstance(view);
32
32
  ((SkiaBaseView)view).unregisterView();
33
+ ((SkiaBaseView)view).destroySurface();
33
34
  }
34
35
  }
@@ -41,7 +41,4 @@ public class SkiaDomView extends SkiaBaseView {
41
41
  protected native void registerView(int nativeId);
42
42
 
43
43
  protected native void unregisterView();
44
-
45
- // TODO: Remove if we find another solution for first frame rendering
46
- // protected native Object renderToBitmap(Object bitmap, int width, int height);
47
44
  }
@@ -41,7 +41,4 @@ public class SkiaDrawView extends SkiaBaseView {
41
41
  protected native void registerView(int nativeId);
42
42
 
43
43
  protected native void unregisterView();
44
-
45
- // TODO: Remove if we find another solution for first frame rendering
46
- // protected native Object renderToBitmap(Object bitmap, int width, int height);
47
44
  }
@@ -41,8 +41,4 @@ public class SkiaPictureView extends SkiaBaseView {
41
41
  protected native void registerView(int nativeId);
42
42
 
43
43
  protected native void unregisterView();
44
-
45
- // TODO: Remove if we find another solution for first frame rendering
46
- // protected native Object renderToBitmap(Object bitmap, int width, int height);
47
-
48
44
  }
@@ -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