@shopify/react-native-skia 0.1.155 → 0.1.156

Sign up to get free protection for your applications and to get access to all the features.
Files changed (162) hide show
  1. package/android/cpp/jni/JniLoad.cpp +5 -5
  2. package/android/cpp/jni/JniPlatformContext.cpp +107 -119
  3. package/android/cpp/jni/JniSkiaManager.cpp +18 -20
  4. package/android/cpp/jni/include/JniPlatformContext.h +41 -45
  5. package/android/cpp/jni/include/JniSkiaBaseView.h +52 -55
  6. package/android/cpp/jni/include/JniSkiaDrawView.h +72 -77
  7. package/android/cpp/jni/include/JniSkiaManager.h +51 -53
  8. package/android/cpp/jni/include/JniSkiaPictureView.h +74 -78
  9. package/android/cpp/rnskia-android/RNSkAndroidPlatformContext.h +36 -45
  10. package/android/cpp/rnskia-android/RNSkAndroidView.h +87 -92
  11. package/android/cpp/rnskia-android/RNSkOpenGLCanvasProvider.cpp +62 -65
  12. package/android/cpp/rnskia-android/RNSkOpenGLCanvasProvider.h +20 -17
  13. package/android/cpp/rnskia-android/SkiaOpenGLRenderer.cpp +257 -313
  14. package/android/cpp/rnskia-android/SkiaOpenGLRenderer.h +107 -110
  15. package/cpp/api/JsiSkApi.h +66 -62
  16. package/cpp/api/JsiSkCanvas.h +38 -30
  17. package/cpp/api/JsiSkColor.h +58 -56
  18. package/cpp/api/JsiSkColorFilter.h +5 -3
  19. package/cpp/api/JsiSkColorFilterFactory.h +23 -21
  20. package/cpp/api/JsiSkContourMeasure.h +74 -85
  21. package/cpp/api/JsiSkContourMeasureIter.h +68 -75
  22. package/cpp/api/JsiSkData.h +16 -22
  23. package/cpp/api/JsiSkDataFactory.h +86 -79
  24. package/cpp/api/JsiSkFont.h +286 -311
  25. package/cpp/api/JsiSkHostObjects.h +15 -16
  26. package/cpp/api/JsiSkImage.h +107 -103
  27. package/cpp/api/JsiSkImageFactory.h +34 -36
  28. package/cpp/api/JsiSkImageFilter.h +5 -3
  29. package/cpp/api/JsiSkImageFilterFactory.h +71 -68
  30. package/cpp/api/JsiSkImageInfo.h +41 -38
  31. package/cpp/api/JsiSkMaskFilter.h +5 -3
  32. package/cpp/api/JsiSkMaskFilterFactory.h +2 -3
  33. package/cpp/api/JsiSkMatrix.h +26 -36
  34. package/cpp/api/JsiSkPaint.h +20 -13
  35. package/cpp/api/JsiSkPath.h +70 -85
  36. package/cpp/api/JsiSkPathEffect.h +5 -3
  37. package/cpp/api/JsiSkPathEffectFactory.h +33 -28
  38. package/cpp/api/JsiSkPathFactory.h +68 -67
  39. package/cpp/api/JsiSkPicture.h +28 -22
  40. package/cpp/api/JsiSkPictureFactory.h +13 -12
  41. package/cpp/api/JsiSkPictureRecorder.h +21 -19
  42. package/cpp/api/JsiSkPoint.h +6 -8
  43. package/cpp/api/JsiSkRRect.h +11 -7
  44. package/cpp/api/JsiSkRSXform.h +82 -85
  45. package/cpp/api/JsiSkRect.h +9 -9
  46. package/cpp/api/JsiSkRuntimeEffect.h +182 -186
  47. package/cpp/api/JsiSkRuntimeEffectFactory.h +10 -11
  48. package/cpp/api/JsiSkRuntimeShaderBuilder.h +64 -61
  49. package/cpp/api/JsiSkSVG.h +4 -5
  50. package/cpp/api/JsiSkSVGFactory.h +28 -27
  51. package/cpp/api/JsiSkShader.h +3 -2
  52. package/cpp/api/JsiSkShaderFactory.h +37 -25
  53. package/cpp/api/JsiSkSurface.h +44 -40
  54. package/cpp/api/JsiSkSurfaceFactory.h +22 -22
  55. package/cpp/api/JsiSkTextBlob.h +28 -31
  56. package/cpp/api/JsiSkTextBlobFactory.h +88 -87
  57. package/cpp/api/JsiSkTypeface.h +6 -5
  58. package/cpp/api/JsiSkTypefaceFactory.h +22 -21
  59. package/cpp/api/JsiSkVertices.h +137 -124
  60. package/cpp/api/third_party/CSSColorParser.cpp +161 -174
  61. package/cpp/api/third_party/CSSColorParser.h +172 -96
  62. package/cpp/jsi/JsiHostObject.cpp +11 -9
  63. package/cpp/jsi/JsiHostObject.h +31 -24
  64. package/cpp/jsi/JsiSimpleValueWrapper.h +74 -83
  65. package/cpp/jsi/JsiValueWrapper.h +52 -54
  66. package/cpp/rnskia/RNSkAnimation.h +26 -29
  67. package/cpp/rnskia/RNSkDispatchQueue.cpp +50 -61
  68. package/cpp/rnskia/RNSkDispatchQueue.h +3 -1
  69. package/cpp/rnskia/RNSkInfoParameter.h +12 -12
  70. package/cpp/rnskia/RNSkJsView.cpp +82 -81
  71. package/cpp/rnskia/RNSkJsView.h +45 -41
  72. package/cpp/rnskia/RNSkJsiViewApi.h +99 -89
  73. package/cpp/rnskia/RNSkManager.cpp +8 -7
  74. package/cpp/rnskia/RNSkManager.h +8 -6
  75. package/cpp/rnskia/RNSkPictureView.h +44 -37
  76. package/cpp/rnskia/RNSkPlatformContext.h +39 -28
  77. package/cpp/rnskia/RNSkValueApi.h +33 -34
  78. package/cpp/rnskia/RNSkView.h +108 -93
  79. package/cpp/rnskia/values/RNSkClockValue.h +63 -64
  80. package/cpp/rnskia/values/RNSkComputedValue.h +32 -30
  81. package/cpp/rnskia/values/RNSkReadonlyValue.h +60 -59
  82. package/cpp/rnskia/values/RNSkValue.h +38 -40
  83. package/cpp/utils/RNSkLog.h +9 -7
  84. package/cpp/utils/RNSkMeasureTime.h +7 -7
  85. package/cpp/utils/RNSkTimingInfo.h +27 -24
  86. package/ios/RNSkia-iOS/RNSkMetalCanvasProvider.h +8 -9
  87. package/ios/RNSkia-iOS/RNSkiOSPlatformContext.h +24 -23
  88. package/ios/RNSkia-iOS/RNSkiOSView.h +16 -13
  89. package/ios/RNSkia-iOS/SkiaUIView.h +9 -8
  90. package/lib/commonjs/dom/nodes/JsiSkDOM.js +6 -0
  91. package/lib/commonjs/dom/nodes/JsiSkDOM.js.map +1 -1
  92. package/lib/commonjs/dom/nodes/LayerNode.js +43 -0
  93. package/lib/commonjs/dom/nodes/LayerNode.js.map +1 -0
  94. package/lib/commonjs/dom/types/NodeType.js +1 -0
  95. package/lib/commonjs/dom/types/NodeType.js.map +1 -1
  96. package/lib/commonjs/dom/types/SkDOM.js.map +1 -1
  97. package/lib/commonjs/renderer/HostComponents.js +3 -0
  98. package/lib/commonjs/renderer/HostComponents.js.map +1 -1
  99. package/lib/commonjs/renderer/components/Group.js +19 -4
  100. package/lib/commonjs/renderer/components/Group.js.map +1 -1
  101. package/lib/commonjs/renderer/components/Paint.js +6 -1
  102. package/lib/commonjs/renderer/components/Paint.js.map +1 -1
  103. package/lib/commonjs/views/SkiaPictureView.js +3 -2
  104. package/lib/commonjs/views/SkiaPictureView.js.map +1 -1
  105. package/lib/commonjs/views/SkiaView.js +6 -3
  106. package/lib/commonjs/views/SkiaView.js.map +1 -1
  107. package/lib/module/dom/nodes/JsiSkDOM.js +5 -0
  108. package/lib/module/dom/nodes/JsiSkDOM.js.map +1 -1
  109. package/lib/module/dom/nodes/LayerNode.js +32 -0
  110. package/lib/module/dom/nodes/LayerNode.js.map +1 -0
  111. package/lib/module/dom/types/NodeType.js +1 -0
  112. package/lib/module/dom/types/NodeType.js.map +1 -1
  113. package/lib/module/dom/types/SkDOM.js.map +1 -1
  114. package/lib/module/renderer/HostComponents.js +3 -0
  115. package/lib/module/renderer/HostComponents.js.map +1 -1
  116. package/lib/module/renderer/components/Group.js +16 -3
  117. package/lib/module/renderer/components/Group.js.map +1 -1
  118. package/lib/module/renderer/components/Paint.js +7 -1
  119. package/lib/module/renderer/components/Paint.js.map +1 -1
  120. package/lib/module/views/SkiaPictureView.js +2 -2
  121. package/lib/module/views/SkiaPictureView.js.map +1 -1
  122. package/lib/module/views/SkiaView.js +4 -2
  123. package/lib/module/views/SkiaView.js.map +1 -1
  124. package/lib/typescript/src/dom/nodes/JsiSkDOM.d.ts +2 -0
  125. package/lib/typescript/src/dom/nodes/LayerNode.d.ts +8 -0
  126. package/lib/typescript/src/dom/types/NodeType.d.ts +1 -0
  127. package/lib/typescript/src/dom/types/SkDOM.d.ts +1 -0
  128. package/lib/typescript/src/renderer/HostComponents.d.ts +2 -1
  129. package/lib/typescript/src/renderer/components/Group.d.ts +5 -1
  130. package/lib/typescript/src/views/SkiaView.d.ts +3 -0
  131. package/libs/android/arm64-v8a/libskottie.a +0 -0
  132. package/libs/android/arm64-v8a/libsksg.a +0 -0
  133. package/libs/android/armeabi-v7a/libskottie.a +0 -0
  134. package/libs/android/armeabi-v7a/libsksg.a +0 -0
  135. package/libs/android/x86/libskottie.a +0 -0
  136. package/libs/android/x86/libsksg.a +0 -0
  137. package/libs/android/x86_64/libskottie.a +0 -0
  138. package/libs/android/x86_64/libsksg.a +0 -0
  139. package/libs/ios/libskia.xcframework/ios-arm64_arm64e/libskia.a +0 -0
  140. package/libs/ios/libskia.xcframework/ios-arm64_arm64e_x86_64-simulator/libskia.a +0 -0
  141. package/libs/ios/libskottie.xcframework/Info.plist +42 -0
  142. package/libs/ios/libskottie.xcframework/ios-arm64_arm64e/libskottie.a +0 -0
  143. package/libs/ios/libskottie.xcframework/ios-arm64_arm64e_x86_64-simulator/libskottie.a +0 -0
  144. package/libs/ios/libsksg.xcframework/Info.plist +42 -0
  145. package/libs/ios/libsksg.xcframework/ios-arm64_arm64e/libsksg.a +0 -0
  146. package/libs/ios/libsksg.xcframework/ios-arm64_arm64e_x86_64-simulator/libsksg.a +0 -0
  147. package/libs/ios/libskshaper.xcframework/Info.plist +5 -5
  148. package/libs/ios/libskshaper.xcframework/ios-arm64_arm64e/libskshaper.a +0 -0
  149. package/libs/ios/libskshaper.xcframework/ios-arm64_arm64e_x86_64-simulator/libskshaper.a +0 -0
  150. package/libs/ios/libsvg.xcframework/Info.plist +5 -5
  151. package/libs/ios/libsvg.xcframework/ios-arm64_arm64e/libsvg.a +0 -0
  152. package/libs/ios/libsvg.xcframework/ios-arm64_arm64e_x86_64-simulator/libsvg.a +0 -0
  153. package/package.json +3 -1
  154. package/src/dom/nodes/JsiSkDOM.ts +5 -0
  155. package/src/dom/nodes/LayerNode.ts +35 -0
  156. package/src/dom/types/NodeType.ts +1 -0
  157. package/src/dom/types/SkDOM.ts +1 -0
  158. package/src/renderer/HostComponents.ts +3 -0
  159. package/src/renderer/components/Group.tsx +16 -3
  160. package/src/renderer/components/Paint.tsx +7 -1
  161. package/src/views/SkiaPictureView.tsx +2 -3
  162. package/src/views/SkiaView.tsx +2 -2
@@ -2,13 +2,14 @@
2
2
 
3
3
  #include <RNSkLog.h>
4
4
 
5
+ #include "EGL/egl.h"
6
+ #include "GLES2/gl2.h"
5
7
  #include "android/native_window.h"
6
8
  #include <fbjni/fbjni.h>
7
9
  #include <jni.h>
8
- #include "EGL/egl.h"
9
- #include "GLES2/gl2.h"
10
10
 
11
11
  #include <condition_variable>
12
+ #include <memory>
12
13
  #include <thread>
13
14
  #include <unordered_map>
14
15
 
@@ -17,116 +18,112 @@
17
18
 
18
19
  #include "include/gpu/GrDirectContext.h"
19
20
  #include "include/gpu/gl/GrGLInterface.h"
20
- #include <SkColorSpace.h>
21
21
  #include <SkCanvas.h>
22
- #include <SkSurface.h>
22
+ #include <SkColorSpace.h>
23
23
  #include <SkPicture.h>
24
+ #include <SkSurface.h>
24
25
 
25
26
  #pragma clang diagnostic pop
26
27
 
27
-
28
- namespace RNSkia
29
- {
30
- using DrawingContext = struct
31
- {
32
- EGLContext glContext;
33
- EGLDisplay glDisplay;
34
- EGLConfig glConfig;
35
- sk_sp<GrDirectContext> skContext;
36
- };
37
-
38
- static std::unordered_map<std::thread::id, std::shared_ptr<DrawingContext>> threadContexts;
39
-
40
- enum RenderState : int {
41
- Initializing,
42
- Rendering,
43
- Finishing,
44
- Done,
45
- };
46
-
47
- class SkiaOpenGLRenderer
48
- {
49
- public:
50
- SkiaOpenGLRenderer(jobject surface);
51
- ~SkiaOpenGLRenderer();
52
-
53
- /**
54
- * Initializes, renders and tears down the render pipeline depending on the state of the
55
- * renderer. All OpenGL/Skia context operations are done on a separate thread which must
56
- * be the same for all calls to the render method.
57
- *
58
- * @param callback Render callback
59
- * @param width Width of surface to render if there is a picture
60
- * @param height Height of surface to render if there is a picture
61
- */
62
- void run(const std::function<void(SkCanvas*)> &cb, int width, int height);
63
-
64
- /**
65
- * Sets the state to finishing. Next time the renderer will be called it
66
- * will tear down and release its resources. It is important that this
67
- * is done on the same thread as the other OpenGL context stuff is handled.
68
- *
69
- * Teardown can be called fom whatever thread we want - but we must ensure that
70
- * at least one call to render on the render thread is done after calling
71
- * teardown.
72
- */
73
- void teardown();
74
-
75
- private:
76
- /**
77
- * Initializes all required OpenGL and Skia objects
78
- * @return True if initialization went well.
79
- */
80
- bool ensureInitialised();
81
-
82
- /**
83
- * Initializes the static OpenGL context that is shared between
84
- * all instances of the renderer.
85
- * @return True if initialization went well
86
- */
87
- bool initStaticGLContext();
88
-
89
- /**
90
- * Initializes the static Skia context that is shared between
91
- * all instances of the renderer
92
- * @return True if initialization went well
93
- */
94
- bool initStaticSkiaContext();
95
-
96
- /**
97
- * Inititalizes the OpenGL surface from the native view pointer we
98
- * got on initialization. Each renderer has its own OpenGL surface to
99
- * render on.
100
- * @return True if initialization went well
101
- */
102
- bool initGLSurface();
103
-
104
- /**
105
- * Ensures that we have a valid Skia surface to draw to. The surface will
106
- * be recreated if the width/height change.
107
- * @param width Width of the underlying view
108
- * @param height Height of the underlying view
109
- * @return True if initialization went well
110
- */
111
- bool ensureSkiaSurface(int width, int height);
112
-
113
- /**
114
- * To be able to use static contexts (and avoid reloading the skia context for each
115
- * new view, we track the OpenGL and Skia drawing context per thread.
116
- * @return The drawing context for the current thread
117
- */
118
- static std::shared_ptr<DrawingContext> getThreadDrawingContext();
119
-
120
- EGLSurface _glSurface = EGL_NO_SURFACE;
121
-
122
- ANativeWindow *_nativeWindow = nullptr;
123
- GrBackendRenderTarget _skRenderTarget;
124
- sk_sp<SkSurface> _skSurface;
125
-
126
- int _prevWidth = 0;
127
- int _prevHeight = 0;
128
-
129
- std::atomic<RenderState> _renderState = { RenderState::Initializing };
130
- };
131
-
132
- }
28
+ namespace RNSkia {
29
+ using DrawingContext = struct {
30
+ EGLContext glContext;
31
+ EGLDisplay glDisplay;
32
+ EGLConfig glConfig;
33
+ sk_sp<GrDirectContext> skContext;
34
+ };
35
+
36
+ static std::unordered_map<std::thread::id, std::shared_ptr<DrawingContext>>
37
+ threadContexts;
38
+
39
+ enum RenderState : int {
40
+ Initializing,
41
+ Rendering,
42
+ Finishing,
43
+ Done,
44
+ };
45
+
46
+ class SkiaOpenGLRenderer {
47
+ public:
48
+ explicit SkiaOpenGLRenderer(jobject surface);
49
+ ~SkiaOpenGLRenderer();
50
+
51
+ /**
52
+ * Initializes, renders and tears down the render pipeline depending on the
53
+ * state of the renderer. All OpenGL/Skia context operations are done on a
54
+ * separate thread which must be the same for all calls to the render method.
55
+ *
56
+ * @param callback Render callback
57
+ * @param width Width of surface to render if there is a picture
58
+ * @param height Height of surface to render if there is a picture
59
+ */
60
+ void run(const std::function<void(SkCanvas *)> &cb, int width, int height);
61
+
62
+ /**
63
+ * Sets the state to finishing. Next time the renderer will be called it
64
+ * will tear down and release its resources. It is important that this
65
+ * is done on the same thread as the other OpenGL context stuff is handled.
66
+ *
67
+ * Teardown can be called fom whatever thread we want - but we must ensure
68
+ * that at least one call to render on the render thread is done after calling
69
+ * teardown.
70
+ */
71
+ void teardown();
72
+
73
+ private:
74
+ /**
75
+ * Initializes all required OpenGL and Skia objects
76
+ * @return True if initialization went well.
77
+ */
78
+ bool ensureInitialised();
79
+
80
+ /**
81
+ * Initializes the static OpenGL context that is shared between
82
+ * all instances of the renderer.
83
+ * @return True if initialization went well
84
+ */
85
+ bool initStaticGLContext();
86
+
87
+ /**
88
+ * Initializes the static Skia context that is shared between
89
+ * all instances of the renderer
90
+ * @return True if initialization went well
91
+ */
92
+ bool initStaticSkiaContext();
93
+
94
+ /**
95
+ * Inititalizes the OpenGL surface from the native view pointer we
96
+ * got on initialization. Each renderer has its own OpenGL surface to
97
+ * render on.
98
+ * @return True if initialization went well
99
+ */
100
+ bool initGLSurface();
101
+
102
+ /**
103
+ * Ensures that we have a valid Skia surface to draw to. The surface will
104
+ * be recreated if the width/height change.
105
+ * @param width Width of the underlying view
106
+ * @param height Height of the underlying view
107
+ * @return True if initialization went well
108
+ */
109
+ bool ensureSkiaSurface(int width, int height);
110
+
111
+ /**
112
+ * To be able to use static contexts (and avoid reloading the skia context for
113
+ * each new view, we track the OpenGL and Skia drawing context per thread.
114
+ * @return The drawing context for the current thread
115
+ */
116
+ static std::shared_ptr<DrawingContext> getThreadDrawingContext();
117
+
118
+ EGLSurface _glSurface = EGL_NO_SURFACE;
119
+
120
+ ANativeWindow *_nativeWindow = nullptr;
121
+ GrBackendRenderTarget _skRenderTarget;
122
+ sk_sp<SkSurface> _skSurface;
123
+
124
+ int _prevWidth = 0;
125
+ int _prevHeight = 0;
126
+
127
+ std::atomic<RenderState> _renderState = {RenderState::Initializing};
128
+ };
129
+ } // namespace RNSkia
@@ -1,12 +1,16 @@
1
1
  #pragma once
2
2
 
3
+ #include <memory>
4
+
3
5
  #include "RNSkPlatformContext.h"
4
6
 
5
7
  #include "JsiSkHostObjects.h"
6
8
 
7
- #include "JsiSkRuntimeEffect.h"
9
+ #include "JsiSkColor.h"
8
10
  #include "JsiSkColorFilter.h"
9
11
  #include "JsiSkColorFilterFactory.h"
12
+ #include "JsiSkContourMeasureIter.h"
13
+ #include "JsiSkDataFactory.h"
10
14
  #include "JsiSkFont.h"
11
15
  #include "JsiSkImage.h"
12
16
  #include "JsiSkImageFactory.h"
@@ -16,86 +20,86 @@
16
20
  #include "JsiSkMaskFilterFactory.h"
17
21
  #include "JsiSkMatrix.h"
18
22
  #include "JsiSkPaint.h"
19
- #include "JsiSkRSXform.h"
20
23
  #include "JsiSkPath.h"
21
24
  #include "JsiSkPathEffect.h"
22
25
  #include "JsiSkPathEffectFactory.h"
23
26
  #include "JsiSkPathFactory.h"
27
+ #include "JsiSkPictureFactory.h"
28
+ #include "JsiSkPictureRecorder.h"
24
29
  #include "JsiSkPoint.h"
25
30
  #include "JsiSkRRect.h"
31
+ #include "JsiSkRSXform.h"
26
32
  #include "JsiSkRect.h"
33
+ #include "JsiSkRuntimeEffect.h"
27
34
  #include "JsiSkRuntimeEffectFactory.h"
28
- #include "JsiSkShader.h"
29
- #include "JsiSkShaderFactory.h"
35
+ #include "JsiSkRuntimeShaderBuilder.h"
30
36
  #include "JsiSkSVG.h"
31
37
  #include "JsiSkSVGFactory.h"
32
- #include "JsiSkTypeface.h"
33
- #include "JsiSkVertices.h"
34
- #include "JsiSkTypefaceFactory.h"
35
- #include "JsiSkDataFactory.h"
38
+ #include "JsiSkShader.h"
39
+ #include "JsiSkShaderFactory.h"
36
40
  #include "JsiSkSurfaceFactory.h"
37
41
  #include "JsiSkTextBlobFactory.h"
38
- #include "JsiSkContourMeasureIter.h"
39
- #include "JsiSkPictureRecorder.h"
40
- #include "JsiSkPictureFactory.h"
41
- #include "JsiSkRuntimeShaderBuilder.h"
42
- #include "JsiSkColor.h"
42
+ #include "JsiSkTypeface.h"
43
+ #include "JsiSkTypefaceFactory.h"
44
+ #include "JsiSkVertices.h"
43
45
 
44
- namespace RNSkia
45
- {
46
+ namespace RNSkia {
46
47
 
47
- using namespace facebook;
48
+ namespace jsi = facebook::jsi;
48
49
 
49
- class JsiSkApi : public JsiSkHostObject
50
- {
51
- public:
52
- /**
50
+ class JsiSkApi : public JsiSkHostObject {
51
+ public:
52
+ /**
53
53
  * Constructs the Skia Api object that can be installed into a runtime
54
54
  * and provide functions for accessing and creating the Skia wrapper objects
55
55
  * @param context Platform context
56
56
  */
57
- JsiSkApi(jsi::Runtime &runtime, std::shared_ptr<RNSkPlatformContext> context)
58
- : JsiSkHostObject(context)
59
- {
57
+ JsiSkApi(jsi::Runtime &runtime, std::shared_ptr<RNSkPlatformContext> context)
58
+ : JsiSkHostObject(context) {
60
59
 
61
- installFunction("Font", JsiSkFont::createCtor(context));
62
- installFunction("Paint", JsiSkPaint::createCtor(context));
63
- installFunction("RSXform", JsiSkRSXform::createCtor(context));
64
- installFunction("Matrix", JsiSkMatrix::createCtor(context));
65
- installFunction("XYWHRect", JsiSkRect::createCtor(context));
66
- installFunction("RRectXY", JsiSkRRect::createCtor(context));
67
- installFunction("Point", JsiSkPoint::createCtor(context));
68
- installFunction("RuntimeShaderBuilder", JsiSkRuntimeShaderBuilder::createCtor(context));
69
- installFunction("ContourMeasureIter", JsiSkContourMeasureIter::createCtor(context));
70
- installFunction("MakeVertices", JsiSkVertices::createCtor(context));
71
- installFunction("PictureRecorder", JsiSkPictureRecorder::createCtor(context));
72
- installFunction("Color", JsiSkColor::createCtor());
60
+ installFunction("Font", JsiSkFont::createCtor(context));
61
+ installFunction("Paint", JsiSkPaint::createCtor(context));
62
+ installFunction("RSXform", JsiSkRSXform::createCtor(context));
63
+ installFunction("Matrix", JsiSkMatrix::createCtor(context));
64
+ installFunction("XYWHRect", JsiSkRect::createCtor(context));
65
+ installFunction("RRectXY", JsiSkRRect::createCtor(context));
66
+ installFunction("Point", JsiSkPoint::createCtor(context));
67
+ installFunction("RuntimeShaderBuilder",
68
+ JsiSkRuntimeShaderBuilder::createCtor(context));
69
+ installFunction("ContourMeasureIter",
70
+ JsiSkContourMeasureIter::createCtor(context));
71
+ installFunction("MakeVertices", JsiSkVertices::createCtor(context));
72
+ installFunction("PictureRecorder",
73
+ JsiSkPictureRecorder::createCtor(context));
74
+ installFunction("Color", JsiSkColor::createCtor());
73
75
 
74
- installReadonlyProperty("SVG",
75
- std::make_shared<JsiSkSVGFactory>(context));
76
- installReadonlyProperty("Image",
77
- std::make_shared<JsiSkImageFactory>(context));
78
- installReadonlyProperty("Typeface",
79
- std::make_shared<JsiSkTypefaceFactory>(context));
80
- installReadonlyProperty("Data",
81
- std::make_shared<JsiSkDataFactory>(context));
82
- installReadonlyProperty("ImageFilter",
83
- std::make_shared<JsiSkImageFilterFactory>(context));
84
- installReadonlyProperty("PathEffect",
85
- std::make_shared<JsiSkPathEffectFactory>(context));
86
- installReadonlyProperty("Path",
87
- std::make_shared<JsiSkPathFactory>(context));
88
- installReadonlyProperty("ColorFilter",
89
- std::make_shared<JsiSkColorFilterFactory>(context));
90
- installReadonlyProperty("MaskFilter",
91
- std::make_shared<JsiSkMaskFilterFactory>(context));
92
- installReadonlyProperty(
93
- "RuntimeEffect", std::make_shared<JsiSkRuntimeEffectFactory>(context));
94
- installReadonlyProperty("Shader",
95
- std::make_shared<JsiSkShaderFactory>(context));
96
- installReadonlyProperty("TextBlob", std::make_shared<JsiSkTextBlobFactory>(context));
97
- installReadonlyProperty("Surface", std::make_shared<JsiSkSurfaceFactory>(context));
98
- installReadonlyProperty("Picture", std::make_shared<JsiSkPictureFactory>(context));
99
- };
100
- };
76
+ installReadonlyProperty("SVG", std::make_shared<JsiSkSVGFactory>(context));
77
+ installReadonlyProperty("Image",
78
+ std::make_shared<JsiSkImageFactory>(context));
79
+ installReadonlyProperty("Typeface",
80
+ std::make_shared<JsiSkTypefaceFactory>(context));
81
+ installReadonlyProperty("Data",
82
+ std::make_shared<JsiSkDataFactory>(context));
83
+ installReadonlyProperty("ImageFilter",
84
+ std::make_shared<JsiSkImageFilterFactory>(context));
85
+ installReadonlyProperty("PathEffect",
86
+ std::make_shared<JsiSkPathEffectFactory>(context));
87
+ installReadonlyProperty("Path",
88
+ std::make_shared<JsiSkPathFactory>(context));
89
+ installReadonlyProperty("ColorFilter",
90
+ std::make_shared<JsiSkColorFilterFactory>(context));
91
+ installReadonlyProperty("MaskFilter",
92
+ std::make_shared<JsiSkMaskFilterFactory>(context));
93
+ installReadonlyProperty(
94
+ "RuntimeEffect", std::make_shared<JsiSkRuntimeEffectFactory>(context));
95
+ installReadonlyProperty("Shader",
96
+ std::make_shared<JsiSkShaderFactory>(context));
97
+ installReadonlyProperty("TextBlob",
98
+ std::make_shared<JsiSkTextBlobFactory>(context));
99
+ installReadonlyProperty("Surface",
100
+ std::make_shared<JsiSkSurfaceFactory>(context));
101
+ installReadonlyProperty("Picture",
102
+ std::make_shared<JsiSkPictureFactory>(context));
103
+ }
104
+ };
101
105
  } // namespace RNSkia
@@ -10,12 +10,12 @@
10
10
  #include "JsiSkMatrix.h"
11
11
  #include "JsiSkPaint.h"
12
12
  #include "JsiSkPath.h"
13
+ #include "JsiSkPicture.h"
13
14
  #include "JsiSkPoint.h"
14
15
  #include "JsiSkRRect.h"
15
16
  #include "JsiSkSVG.h"
16
- #include "JsiSkVertices.h"
17
17
  #include "JsiSkTextBlob.h"
18
- #include "JsiSkPicture.h"
18
+ #include "JsiSkVertices.h"
19
19
 
20
20
  #include <jsi/jsi.h>
21
21
 
@@ -26,15 +26,15 @@
26
26
  #include <SkFont.h>
27
27
  #include <SkPaint.h>
28
28
  #include <SkPath.h>
29
+ #include <SkPicture.h>
29
30
  #include <SkRegion.h>
30
31
  #include <SkSurface.h>
31
32
  #include <SkTypeface.h>
32
- #include <SkPicture.h>
33
33
 
34
34
  #pragma clang diagnostic pop
35
35
 
36
36
  namespace RNSkia {
37
- using namespace facebook;
37
+ namespace jsi = facebook::jsi;
38
38
 
39
39
  class JsiSkCanvas : public JsiSkHostObject {
40
40
  public:
@@ -97,7 +97,7 @@ public:
97
97
  paint = JsiSkPaint::fromValue(runtime, arguments[5]);
98
98
  }
99
99
  }
100
- _canvas->drawImage(image, x, y, SkSamplingOptions({ B, C }), paint.get());
100
+ _canvas->drawImage(image, x, y, SkSamplingOptions({B, C}), paint.get());
101
101
  return jsi::Value::undefined();
102
102
  }
103
103
 
@@ -128,7 +128,8 @@ public:
128
128
  paint = JsiSkPaint::fromValue(runtime, arguments[4]);
129
129
  }
130
130
  }
131
- _canvas->drawImageNine(image.get(), center->round(), *dest, fm, paint.get());
131
+ _canvas->drawImageNine(image.get(), center->round(), *dest, fm,
132
+ paint.get());
132
133
  return jsi::Value::undefined();
133
134
  }
134
135
 
@@ -144,8 +145,10 @@ public:
144
145
  paint = JsiSkPaint::fromValue(runtime, arguments[5]);
145
146
  }
146
147
  }
147
- auto constraint = SkCanvas::kStrict_SrcRectConstraint; // TODO: get from caller
148
- _canvas->drawImageRect(image.get(), *src, *dest, SkSamplingOptions({ B, C }), paint.get(), constraint);
148
+ auto constraint =
149
+ SkCanvas::kStrict_SrcRectConstraint; // TODO: get from caller
150
+ _canvas->drawImageRect(image.get(), *src, *dest, SkSamplingOptions({B, C}),
151
+ paint.get(), constraint);
149
152
  return jsi::Value::undefined();
150
153
  }
151
154
 
@@ -162,7 +165,8 @@ public:
162
165
  }
163
166
  }
164
167
  auto constraint = SkCanvas::kStrict_SrcRectConstraint;
165
- _canvas->drawImageRect(image.get(), *src, *dest, {filter, mipmap}, paint.get(), constraint);
168
+ _canvas->drawImageRect(image.get(), *src, *dest, {filter, mipmap},
169
+ paint.get(), constraint);
166
170
  return jsi::Value::undefined();
167
171
  }
168
172
 
@@ -250,7 +254,6 @@ public:
250
254
  return jsi::Value::undefined();
251
255
  }
252
256
 
253
-
254
257
  JSI_HOST_FUNCTION(drawVertices) {
255
258
  auto vertices = JsiSkVertices::fromValue(runtime, arguments[0]);
256
259
  auto blendMode = (SkBlendMode)arguments[1].getNumber();
@@ -278,7 +281,8 @@ public:
278
281
  auto colorsSize = jsiColors.size(runtime);
279
282
  colors.reserve(colorsSize);
280
283
  for (int i = 0; i < colorsSize; i++) {
281
- SkColor color = JsiSkColor::fromValue(runtime, jsiColors.getValueAtIndex(runtime, i));
284
+ SkColor color = JsiSkColor::fromValue(
285
+ runtime, jsiColors.getValueAtIndex(runtime, i));
282
286
  colors.push_back(color);
283
287
  }
284
288
  }
@@ -289,14 +293,16 @@ public:
289
293
  texs.reserve(texsSize);
290
294
  for (int i = 0; i < texsSize; i++) {
291
295
  auto point = JsiSkPoint::fromValue(
292
- runtime, jsiTexs.getValueAtIndex(runtime, i).asObject(runtime));
296
+ runtime, jsiTexs.getValueAtIndex(runtime, i).asObject(runtime));
293
297
  texs.push_back(*point.get());
294
298
  }
295
299
  }
296
300
 
297
- auto paint = count >= 4 ? JsiSkPaint::fromValue(runtime, arguments[4]) : nullptr;
301
+ auto paint =
302
+ count >= 4 ? JsiSkPaint::fromValue(runtime, arguments[4]) : nullptr;
298
303
  auto blendMode = static_cast<SkBlendMode>(arguments[3].asNumber());
299
- _canvas->drawPatch(cubics.data(), colors.data(), texs.data(), blendMode, *paint);
304
+ _canvas->drawPatch(cubics.data(), colors.data(), texs.data(), blendMode,
305
+ *paint);
300
306
  return jsi::Value::undefined();
301
307
  }
302
308
 
@@ -347,7 +353,7 @@ public:
347
353
  positions.reserve(pointsSize);
348
354
  for (int i = 0; i < pointsSize; i++) {
349
355
  std::shared_ptr<SkPoint> point = JsiSkPoint::fromValue(
350
- runtime, jsiPositions.getValueAtIndex(runtime, i).asObject(runtime));
356
+ runtime, jsiPositions.getValueAtIndex(runtime, i).asObject(runtime));
351
357
  positions.push_back(*point.get());
352
358
  }
353
359
 
@@ -358,14 +364,8 @@ public:
358
364
  glyphs.push_back(jsiGlyphs.getValueAtIndex(runtime, i).asNumber());
359
365
  }
360
366
 
361
- _canvas->drawGlyphs(
362
- glyphsSize,
363
- glyphs.data(),
364
- positions.data(),
365
- origin,
366
- *font,
367
- *paint
368
- );
367
+ _canvas->drawGlyphs(glyphsSize, glyphs.data(), positions.data(), origin,
368
+ *font, *paint);
369
369
 
370
370
  return jsi::Value::undefined();
371
371
  }
@@ -412,10 +412,17 @@ public:
412
412
  JSI_HOST_FUNCTION(save) { return jsi::Value(_canvas->save()); }
413
413
 
414
414
  JSI_HOST_FUNCTION(saveLayer) {
415
- SkPaint *paint = (count >= 1 && !arguments[0].isUndefined()) ?
416
- JsiSkPaint::fromValue(runtime, arguments[0]).get() : nullptr;
417
- SkRect *bounds = count >= 2 && !arguments[1].isNull() && !arguments[1].isUndefined() ? JsiSkRect::fromValue(runtime, arguments[1]).get() : nullptr;
418
- SkImageFilter *backdrop = count >= 3 && !arguments[2].isNull() && !arguments[2].isUndefined() ? JsiSkImageFilter::fromValue(runtime, arguments[2]).get() : nullptr;
415
+ SkPaint *paint = (count >= 1 && !arguments[0].isUndefined())
416
+ ? JsiSkPaint::fromValue(runtime, arguments[0]).get()
417
+ : nullptr;
418
+ SkRect *bounds =
419
+ count >= 2 && !arguments[1].isNull() && !arguments[1].isUndefined()
420
+ ? JsiSkRect::fromValue(runtime, arguments[1]).get()
421
+ : nullptr;
422
+ SkImageFilter *backdrop =
423
+ count >= 3 && !arguments[2].isNull() && !arguments[2].isUndefined()
424
+ ? JsiSkImageFilter::fromValue(runtime, arguments[2]).get()
425
+ : nullptr;
419
426
  SkCanvas::SaveLayerFlags flags = count >= 4 ? arguments[3].asNumber() : 0;
420
427
  return jsi::Value(_canvas->saveLayer(
421
428
  SkCanvas::SaveLayerRec(bounds, paint, backdrop, flags)));
@@ -477,7 +484,7 @@ public:
477
484
  _canvas->concat(*matrix.get());
478
485
  return jsi::Value::undefined();
479
486
  }
480
-
487
+
481
488
  JSI_HOST_FUNCTION(drawPicture) {
482
489
  auto picture = JsiSkPicture::fromValue(runtime, arguments[0]);
483
490
  _canvas->drawPicture(picture);
@@ -524,10 +531,11 @@ public:
524
531
  JSI_EXPORT_FUNC(JsiSkCanvas, concat),
525
532
  JSI_EXPORT_FUNC(JsiSkCanvas, drawPicture))
526
533
 
527
- JsiSkCanvas(std::shared_ptr<RNSkPlatformContext> context)
534
+ explicit JsiSkCanvas(std::shared_ptr<RNSkPlatformContext> context)
528
535
  : JsiSkHostObject(std::move(context)) {}
529
536
 
530
- JsiSkCanvas(std::shared_ptr<RNSkPlatformContext> context, SkCanvas* canvas): JsiSkCanvas(std::move(context)) {
537
+ JsiSkCanvas(std::shared_ptr<RNSkPlatformContext> context, SkCanvas *canvas)
538
+ : JsiSkCanvas(std::move(context)) {
531
539
  setCanvas(canvas);
532
540
  }
533
541