@shopify/react-native-skia 0.1.164 → 0.1.165

Sign up to get free protection for your applications and to get access to all the features.
Files changed (197) hide show
  1. package/cpp/api/JsiSkRuntimeEffect.h +7 -2
  2. package/cpp/rnskia/RNSkDomView.cpp +1 -1
  3. package/cpp/rnskia/RNSkPlatformContext.h +2 -6
  4. package/cpp/rnskia/dom/base/DrawingContext.cpp +5 -38
  5. package/cpp/rnskia/dom/base/DrawingContext.h +3 -17
  6. package/cpp/rnskia/dom/nodes/JsiCircleNode.h +0 -2
  7. package/cpp/rnskia/dom/nodes/JsiCustomDrawingNode.h +1 -3
  8. package/cpp/rnskia/dom/nodes/JsiImageFilterNodes.h +2 -2
  9. package/cpp/rnskia/dom/props/CircleProp.h +2 -0
  10. package/cpp/rnskia/dom/props/ColorProp.h +9 -4
  11. package/cpp/rnskia/dom/props/ImageProps.h +3 -2
  12. package/cpp/rnskia/dom/props/PaintProps.h +15 -6
  13. package/cpp/rnskia/dom/props/RectProp.h +11 -4
  14. package/cpp/rnskia/dom/props/UniformsProp.h +86 -123
  15. package/cpp/rnskia/values/RNSkReadonlyValue.h +2 -6
  16. package/lib/commonjs/dom/nodes/datatypes/Circle.js +6 -1
  17. package/lib/commonjs/dom/nodes/datatypes/Circle.js.map +1 -1
  18. package/lib/commonjs/dom/nodes/datatypes/Rect.js +3 -3
  19. package/lib/commonjs/dom/nodes/datatypes/Rect.js.map +1 -1
  20. package/lib/commonjs/dom/nodes/drawings/ImageNode.js +2 -2
  21. package/lib/commonjs/dom/nodes/drawings/ImageNode.js.map +1 -1
  22. package/lib/commonjs/dom/types/Common.js.map +1 -1
  23. package/lib/commonjs/dom/types/Drawings.js.map +1 -1
  24. package/lib/commonjs/renderer/components/Mask.js +2 -6
  25. package/lib/commonjs/renderer/components/Mask.js.map +1 -1
  26. package/lib/commonjs/renderer/components/image/Image.js +0 -5
  27. package/lib/commonjs/renderer/components/image/Image.js.map +1 -1
  28. package/lib/commonjs/renderer/components/image/ImageShader.js +20 -10
  29. package/lib/commonjs/renderer/components/image/ImageShader.js.map +1 -1
  30. package/lib/commonjs/renderer/components/imageFilters/Blur.js +10 -5
  31. package/lib/commonjs/renderer/components/imageFilters/Blur.js.map +1 -1
  32. package/lib/commonjs/renderer/components/imageFilters/Morphology.js +10 -5
  33. package/lib/commonjs/renderer/components/imageFilters/Morphology.js.map +1 -1
  34. package/lib/commonjs/renderer/components/imageFilters/Offset.js +12 -6
  35. package/lib/commonjs/renderer/components/imageFilters/Offset.js.map +1 -1
  36. package/lib/commonjs/renderer/components/maskFilters/Blur.js +12 -6
  37. package/lib/commonjs/renderer/components/maskFilters/Blur.js.map +1 -1
  38. package/lib/commonjs/renderer/components/pathEffects/Discrete.js +10 -5
  39. package/lib/commonjs/renderer/components/pathEffects/Discrete.js.map +1 -1
  40. package/lib/commonjs/renderer/components/shaders/FractalNoise.js +14 -7
  41. package/lib/commonjs/renderer/components/shaders/FractalNoise.js.map +1 -1
  42. package/lib/commonjs/renderer/components/shaders/Shader.js +10 -5
  43. package/lib/commonjs/renderer/components/shaders/Shader.js.map +1 -1
  44. package/lib/commonjs/renderer/components/shaders/Turbulence.js +14 -7
  45. package/lib/commonjs/renderer/components/shaders/Turbulence.js.map +1 -1
  46. package/lib/commonjs/renderer/components/shapes/Circle.js +0 -6
  47. package/lib/commonjs/renderer/components/shapes/Circle.js.map +1 -1
  48. package/lib/commonjs/renderer/components/shapes/FitBox.js +1 -4
  49. package/lib/commonjs/renderer/components/shapes/FitBox.js.map +1 -1
  50. package/lib/commonjs/renderer/components/shapes/Oval.js +0 -4
  51. package/lib/commonjs/renderer/components/shapes/Oval.js.map +1 -1
  52. package/lib/commonjs/renderer/components/shapes/Path.js +12 -6
  53. package/lib/commonjs/renderer/components/shapes/Path.js.map +1 -1
  54. package/lib/commonjs/renderer/components/shapes/Points.js +10 -5
  55. package/lib/commonjs/renderer/components/shapes/Points.js.map +1 -1
  56. package/lib/commonjs/renderer/components/shapes/RoundedRect.js +0 -3
  57. package/lib/commonjs/renderer/components/shapes/RoundedRect.js.map +1 -1
  58. package/lib/commonjs/renderer/components/shapes/Vertices.js +10 -5
  59. package/lib/commonjs/renderer/components/shapes/Vertices.js.map +1 -1
  60. package/lib/commonjs/renderer/components/text/Glyphs.js +12 -6
  61. package/lib/commonjs/renderer/components/text/Glyphs.js.map +1 -1
  62. package/lib/commonjs/renderer/components/text/Text.js +12 -6
  63. package/lib/commonjs/renderer/components/text/Text.js.map +1 -1
  64. package/lib/commonjs/renderer/components/text/TextBlob.js +12 -6
  65. package/lib/commonjs/renderer/components/text/TextBlob.js.map +1 -1
  66. package/lib/commonjs/renderer/components/text/TextPath.js +10 -5
  67. package/lib/commonjs/renderer/components/text/TextPath.js.map +1 -1
  68. package/lib/commonjs/renderer/processors/Animations/Animations.js.map +1 -1
  69. package/lib/commonjs/skia/types/RuntimeEffect/RuntimeEffect.js.map +1 -1
  70. package/lib/commonjs/skia/types/Shader/Shader.js +3 -2
  71. package/lib/commonjs/skia/types/Shader/Shader.js.map +1 -1
  72. package/lib/commonjs/skia/web/JsiSkRuntimeEffect.js +6 -1
  73. package/lib/commonjs/skia/web/JsiSkRuntimeEffect.js.map +1 -1
  74. package/lib/commonjs/skia/web/JsiSkRuntimeEffectFactory.js +1 -1
  75. package/lib/commonjs/skia/web/JsiSkRuntimeEffectFactory.js.map +1 -1
  76. package/lib/module/dom/nodes/datatypes/Circle.js +8 -1
  77. package/lib/module/dom/nodes/datatypes/Circle.js.map +1 -1
  78. package/lib/module/dom/nodes/datatypes/Rect.js +7 -3
  79. package/lib/module/dom/nodes/datatypes/Rect.js.map +1 -1
  80. package/lib/module/dom/nodes/drawings/ImageNode.js +4 -2
  81. package/lib/module/dom/nodes/drawings/ImageNode.js.map +1 -1
  82. package/lib/module/dom/types/Common.js.map +1 -1
  83. package/lib/module/dom/types/Drawings.js.map +1 -1
  84. package/lib/module/renderer/components/Mask.js +2 -6
  85. package/lib/module/renderer/components/Mask.js.map +1 -1
  86. package/lib/module/renderer/components/image/Image.js +0 -5
  87. package/lib/module/renderer/components/image/Image.js.map +1 -1
  88. package/lib/module/renderer/components/image/ImageShader.js +20 -10
  89. package/lib/module/renderer/components/image/ImageShader.js.map +1 -1
  90. package/lib/module/renderer/components/imageFilters/Blur.js +10 -5
  91. package/lib/module/renderer/components/imageFilters/Blur.js.map +1 -1
  92. package/lib/module/renderer/components/imageFilters/Morphology.js +10 -5
  93. package/lib/module/renderer/components/imageFilters/Morphology.js.map +1 -1
  94. package/lib/module/renderer/components/imageFilters/Offset.js +12 -6
  95. package/lib/module/renderer/components/imageFilters/Offset.js.map +1 -1
  96. package/lib/module/renderer/components/maskFilters/Blur.js +12 -6
  97. package/lib/module/renderer/components/maskFilters/Blur.js.map +1 -1
  98. package/lib/module/renderer/components/pathEffects/Discrete.js +10 -5
  99. package/lib/module/renderer/components/pathEffects/Discrete.js.map +1 -1
  100. package/lib/module/renderer/components/shaders/FractalNoise.js +14 -7
  101. package/lib/module/renderer/components/shaders/FractalNoise.js.map +1 -1
  102. package/lib/module/renderer/components/shaders/Shader.js +10 -5
  103. package/lib/module/renderer/components/shaders/Shader.js.map +1 -1
  104. package/lib/module/renderer/components/shaders/Turbulence.js +14 -7
  105. package/lib/module/renderer/components/shaders/Turbulence.js.map +1 -1
  106. package/lib/module/renderer/components/shapes/Circle.js +0 -6
  107. package/lib/module/renderer/components/shapes/Circle.js.map +1 -1
  108. package/lib/module/renderer/components/shapes/FitBox.js +1 -4
  109. package/lib/module/renderer/components/shapes/FitBox.js.map +1 -1
  110. package/lib/module/renderer/components/shapes/Oval.js +0 -4
  111. package/lib/module/renderer/components/shapes/Oval.js.map +1 -1
  112. package/lib/module/renderer/components/shapes/Path.js +12 -6
  113. package/lib/module/renderer/components/shapes/Path.js.map +1 -1
  114. package/lib/module/renderer/components/shapes/Points.js +10 -5
  115. package/lib/module/renderer/components/shapes/Points.js.map +1 -1
  116. package/lib/module/renderer/components/shapes/RoundedRect.js +0 -3
  117. package/lib/module/renderer/components/shapes/RoundedRect.js.map +1 -1
  118. package/lib/module/renderer/components/shapes/Vertices.js +10 -5
  119. package/lib/module/renderer/components/shapes/Vertices.js.map +1 -1
  120. package/lib/module/renderer/components/text/Glyphs.js +12 -6
  121. package/lib/module/renderer/components/text/Glyphs.js.map +1 -1
  122. package/lib/module/renderer/components/text/Text.js +12 -6
  123. package/lib/module/renderer/components/text/Text.js.map +1 -1
  124. package/lib/module/renderer/components/text/TextBlob.js +12 -6
  125. package/lib/module/renderer/components/text/TextBlob.js.map +1 -1
  126. package/lib/module/renderer/components/text/TextPath.js +10 -5
  127. package/lib/module/renderer/components/text/TextPath.js.map +1 -1
  128. package/lib/module/renderer/processors/Animations/Animations.js.map +1 -1
  129. package/lib/module/skia/types/RuntimeEffect/RuntimeEffect.js.map +1 -1
  130. package/lib/module/skia/types/Shader/Shader.js +3 -2
  131. package/lib/module/skia/types/Shader/Shader.js.map +1 -1
  132. package/lib/module/skia/web/JsiSkRuntimeEffect.js +6 -1
  133. package/lib/module/skia/web/JsiSkRuntimeEffect.js.map +1 -1
  134. package/lib/module/skia/web/JsiSkRuntimeEffectFactory.js +1 -1
  135. package/lib/module/skia/web/JsiSkRuntimeEffectFactory.js.map +1 -1
  136. package/lib/typescript/src/dom/nodes/datatypes/Circle.d.ts +4 -1
  137. package/lib/typescript/src/dom/types/Common.d.ts +4 -4
  138. package/lib/typescript/src/dom/types/Drawings.d.ts +1 -1
  139. package/lib/typescript/src/renderer/components/Mask.d.ts +3 -9
  140. package/lib/typescript/src/renderer/components/image/Image.d.ts +1 -8
  141. package/lib/typescript/src/renderer/components/image/ImageShader.d.ts +2 -12
  142. package/lib/typescript/src/renderer/components/imageFilters/Blur.d.ts +2 -7
  143. package/lib/typescript/src/renderer/components/imageFilters/Morphology.d.ts +2 -7
  144. package/lib/typescript/src/renderer/components/imageFilters/Offset.d.ts +2 -8
  145. package/lib/typescript/src/renderer/components/maskFilters/Blur.d.ts +2 -8
  146. package/lib/typescript/src/renderer/components/pathEffects/Discrete.d.ts +2 -7
  147. package/lib/typescript/src/renderer/components/shaders/FractalNoise.d.ts +2 -9
  148. package/lib/typescript/src/renderer/components/shaders/Shader.d.ts +2 -7
  149. package/lib/typescript/src/renderer/components/shaders/Turbulence.d.ts +2 -9
  150. package/lib/typescript/src/renderer/components/shapes/Circle.d.ts +1 -9
  151. package/lib/typescript/src/renderer/components/shapes/FitBox.d.ts +2 -7
  152. package/lib/typescript/src/renderer/components/shapes/Oval.d.ts +1 -7
  153. package/lib/typescript/src/renderer/components/shapes/Path.d.ts +2 -8
  154. package/lib/typescript/src/renderer/components/shapes/Points.d.ts +2 -7
  155. package/lib/typescript/src/renderer/components/shapes/RoundedRect.d.ts +1 -6
  156. package/lib/typescript/src/renderer/components/shapes/Vertices.d.ts +2 -7
  157. package/lib/typescript/src/renderer/components/text/Glyphs.d.ts +2 -8
  158. package/lib/typescript/src/renderer/components/text/Text.d.ts +2 -8
  159. package/lib/typescript/src/renderer/components/text/TextBlob.d.ts +2 -8
  160. package/lib/typescript/src/renderer/components/text/TextPath.d.ts +2 -7
  161. package/lib/typescript/src/renderer/processors/Animations/Animations.d.ts +5 -0
  162. package/lib/typescript/src/skia/types/RuntimeEffect/RuntimeEffect.d.ts +4 -0
  163. package/lib/typescript/src/skia/types/Shader/Shader.d.ts +1 -1
  164. package/lib/typescript/src/skia/web/JsiSkRuntimeEffect.d.ts +3 -1
  165. package/package.json +1 -1
  166. package/src/dom/nodes/datatypes/Circle.ts +1 -1
  167. package/src/dom/nodes/datatypes/Rect.ts +3 -3
  168. package/src/dom/nodes/drawings/ImageNode.ts +2 -1
  169. package/src/dom/types/Common.ts +4 -4
  170. package/src/dom/types/Drawings.ts +1 -1
  171. package/src/renderer/components/Mask.tsx +8 -8
  172. package/src/renderer/components/image/Image.tsx +0 -6
  173. package/src/renderer/components/image/ImageShader.tsx +24 -12
  174. package/src/renderer/components/imageFilters/Blur.tsx +6 -7
  175. package/src/renderer/components/imageFilters/Morphology.tsx +6 -7
  176. package/src/renderer/components/imageFilters/Offset.tsx +7 -8
  177. package/src/renderer/components/maskFilters/Blur.tsx +7 -8
  178. package/src/renderer/components/pathEffects/Discrete.tsx +6 -9
  179. package/src/renderer/components/shaders/FractalNoise.tsx +18 -9
  180. package/src/renderer/components/shaders/Shader.tsx +6 -7
  181. package/src/renderer/components/shaders/Turbulence.tsx +15 -9
  182. package/src/renderer/components/shapes/Circle.tsx +0 -4
  183. package/src/renderer/components/shapes/FitBox.tsx +2 -6
  184. package/src/renderer/components/shapes/Oval.tsx +0 -5
  185. package/src/renderer/components/shapes/Path.tsx +7 -8
  186. package/src/renderer/components/shapes/Points.tsx +6 -7
  187. package/src/renderer/components/shapes/RoundedRect.tsx +0 -4
  188. package/src/renderer/components/shapes/Vertices.tsx +6 -7
  189. package/src/renderer/components/text/Glyphs.tsx +7 -8
  190. package/src/renderer/components/text/Text.tsx +7 -8
  191. package/src/renderer/components/text/TextBlob.tsx +7 -8
  192. package/src/renderer/components/text/TextPath.tsx +6 -7
  193. package/src/renderer/processors/Animations/Animations.ts +9 -3
  194. package/src/skia/types/RuntimeEffect/RuntimeEffect.ts +5 -0
  195. package/src/skia/types/Shader/Shader.ts +5 -3
  196. package/src/skia/web/JsiSkRuntimeEffect.ts +5 -1
  197. package/src/skia/web/JsiSkRuntimeEffectFactory.ts +1 -1
@@ -117,6 +117,10 @@ public:
117
117
  return result;
118
118
  }
119
119
 
120
+ JSI_HOST_FUNCTION(source) {
121
+ return jsi::String::createFromAscii(runtime, getObject()->source());
122
+ }
123
+
120
124
  JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkRuntimeEffect, makeShader),
121
125
  JSI_EXPORT_FUNC(JsiSkRuntimeEffect,
122
126
  makeShaderWithChildren),
@@ -124,7 +128,8 @@ public:
124
128
  JSI_EXPORT_FUNC(JsiSkRuntimeEffect,
125
129
  getUniformFloatCount),
126
130
  JSI_EXPORT_FUNC(JsiSkRuntimeEffect, getUniformName),
127
- JSI_EXPORT_FUNC(JsiSkRuntimeEffect, getUniform))
131
+ JSI_EXPORT_FUNC(JsiSkRuntimeEffect, getUniform),
132
+ JSI_EXPORT_FUNC(JsiSkRuntimeEffect, source))
128
133
 
129
134
  JsiSkRuntimeEffect(std::shared_ptr<RNSkPlatformContext> context,
130
135
  sk_sp<SkRuntimeEffect> rt)
@@ -206,7 +211,7 @@ private:
206
211
  const std::size_t offset = reu.slot + j;
207
212
  float fValue = jsiUniforms.getValueAtIndex(runtime, offset).asNumber();
208
213
  int iValue = static_cast<int>(fValue);
209
- auto value = reu.isInteger ? iValue : fValue;
214
+ auto value = reu.isInteger ? SkBits2Float(iValue) : fValue;
210
215
  memcpy(SkTAddOffset<void>(uniforms->writable_data(),
211
216
  offset * sizeof(value)),
212
217
  &value, sizeof(value));
@@ -86,7 +86,7 @@ void RNSkDomRenderer::renderCanvas(SkCanvas *canvas, float scaledWidth,
86
86
  if (_drawingContext == nullptr) {
87
87
  auto paint = std::make_shared<SkPaint>();
88
88
  paint->setAntiAlias(true);
89
- _drawingContext = std::make_shared<DrawingContext>(paint, 1.0f);
89
+ _drawingContext = std::make_shared<DrawingContext>(paint);
90
90
 
91
91
  _drawingContext->setRequestRedraw([weakSelf = weak_from_this()]() {
92
92
  auto self = weakSelf.lock();
@@ -178,12 +178,8 @@ public:
178
178
  if (!_isValid) {
179
179
  return;
180
180
  }
181
- std::unordered_map<size_t, std::function<void(bool)>> tmp;
182
- {
183
- std::lock_guard<std::mutex> lock(_drawCallbacksLock);
184
- tmp.insert(_drawCallbacks.cbegin(), _drawCallbacks.cend());
185
- }
186
- for (auto it = tmp.begin(); it != tmp.end(); it++) {
181
+ std::lock_guard<std::mutex> lock(_drawCallbacksLock);
182
+ for (auto it = _drawCallbacks.begin(); it != _drawCallbacks.end(); it++) {
187
183
  it->second(invalidated);
188
184
  }
189
185
  }
@@ -2,10 +2,9 @@
2
2
 
3
3
  namespace RNSkia {
4
4
 
5
- DrawingContext::DrawingContext(std::shared_ptr<SkPaint> paint, double opacity)
5
+ DrawingContext::DrawingContext(std::shared_ptr<SkPaint> paint)
6
6
  : DrawingContext("root") {
7
7
  _paint = paint;
8
- _opacity = opacity;
9
8
  }
10
9
 
11
10
  DrawingContext::DrawingContext(DrawingContext *parent, const char *source)
@@ -43,7 +42,8 @@ std::string DrawingContext::getDebugDescription() {
43
42
  v += " blendMode:" + std::to_string(static_cast<size_t>(blendMode));
44
43
  }
45
44
 
46
- v += " opacity:" + std::to_string(_opacity);
45
+ auto opacity = _paint->getAlphaf();
46
+ v += " opacity:" + std::to_string(opacity);
47
47
 
48
48
  if (_paint->getPathEffect() != nullptr) {
49
49
  v += " [PathEffect]";
@@ -148,7 +148,6 @@ std::shared_ptr<SkPaint> DrawingContext::getMutablePaint() {
148
148
  if (_paint == nullptr) {
149
149
  auto parentPaint = _parent->getPaint();
150
150
  _paint = std::make_shared<SkPaint>(*parentPaint);
151
- _opacity = _parent->getOpacity();
152
151
  }
153
152
  // Calling the getMutablePaint accessor implies that the paint
154
153
  // is about to be mutatet and will therefore invalidate
@@ -165,40 +164,6 @@ void DrawingContext::setMutablePaint(std::shared_ptr<SkPaint> paint) {
165
164
  _paint = paint;
166
165
  }
167
166
 
168
- /**
169
- Getd the opacity value
170
- */
171
- double DrawingContext::getOpacity() {
172
- if (_paint == nullptr) {
173
- return _parent->getOpacity();
174
- }
175
- return _opacity;
176
- }
177
-
178
- /**
179
- Sets the opacity value
180
- */
181
- void DrawingContext::setOpacity(double opacity) {
182
- auto currentOpacity = opacity;
183
- if (_parent != nullptr) {
184
- currentOpacity *= _parent->getOpacity();
185
- }
186
- getMutablePaint()->setAlphaf(currentOpacity);
187
- _opacity = currentOpacity;
188
- }
189
-
190
- /**
191
- Clears the opacity value
192
- */
193
- void DrawingContext::clearOpacity() {
194
- if (_parent != nullptr) {
195
- _opacity = _parent->getOpacity();
196
- } else {
197
- _opacity = 1.0;
198
- }
199
- markChildrenAsChanged();
200
- }
201
-
202
167
  float DrawingContext::getScaledWidth() {
203
168
  if (_parent != nullptr) {
204
169
  return _parent->getScaledWidth();
@@ -213,6 +178,8 @@ float DrawingContext::getScaledHeight() {
213
178
  return _scaledHeight;
214
179
  }
215
180
 
181
+ DrawingContext *DrawingContext::getParent() { return _parent; }
182
+
216
183
  void DrawingContext::setScaledWidth(float v) { _scaledWidth = v; }
217
184
  void DrawingContext::setScaledHeight(float v) { _scaledHeight = v; }
218
185
 
@@ -22,7 +22,7 @@ public:
22
22
  /**
23
23
  Creates a root drawing context with paint and opacity
24
24
  */
25
- DrawingContext(std::shared_ptr<SkPaint> paint, double opacity);
25
+ explicit DrawingContext(std::shared_ptr<SkPaint> paint);
26
26
 
27
27
  /**
28
28
  Initilalizes a new draw context.
@@ -87,21 +87,6 @@ public:
87
87
  */
88
88
  void setMutablePaint(std::shared_ptr<SkPaint> paint);
89
89
 
90
- /**
91
- Getd the opacity value
92
- */
93
- double getOpacity();
94
-
95
- /**
96
- Sets the opacity value
97
- */
98
- void setOpacity(double opacity);
99
-
100
- /**
101
- Clears the opacity
102
- */
103
- void clearOpacity();
104
-
105
90
  float getScaledWidth();
106
91
 
107
92
  float getScaledHeight();
@@ -112,6 +97,8 @@ public:
112
97
  void setRequestRedraw(std::function<void()> &&requestRedraw);
113
98
  const std::function<void()> &getRequestRedraw();
114
99
 
100
+ DrawingContext *getParent();
101
+
115
102
  private:
116
103
  explicit DrawingContext(const char *source);
117
104
 
@@ -120,7 +107,6 @@ private:
120
107
  bool _isChanged = true;
121
108
 
122
109
  std::shared_ptr<SkPaint> _paint;
123
- double _opacity = 1.0f;
124
110
 
125
111
  SkCanvas *_canvas = nullptr;
126
112
  const char *_source;
@@ -24,8 +24,6 @@ protected:
24
24
  JsiDomDrawingNode::defineProperties(container);
25
25
  _circleProp = container->defineProperty<CircleProp>();
26
26
  _radiusProp = container->defineProperty<NodeProp>("r");
27
-
28
- _circleProp->require();
29
27
  _radiusProp->require();
30
28
  }
31
29
 
@@ -28,7 +28,6 @@ protected:
28
28
  float scaledWidth = context->getScaledWidth();
29
29
  float scaledHeight = context->getScaledHeight();
30
30
  auto paint = context->getPaint();
31
- auto opacity = context->getOpacity();
32
31
  auto platformContext = getContext();
33
32
  auto requestRedraw = context->getRequestRedraw();
34
33
 
@@ -44,7 +43,7 @@ protected:
44
43
  }
45
44
 
46
45
  // Run rendering on the javascript thread
47
- getContext()->runOnJavascriptThread([this, platformContext, opacity,
46
+ getContext()->runOnJavascriptThread([this, platformContext,
48
47
  requestRedraw, scaledWidth,
49
48
  scaledHeight]() {
50
49
  // Get the runtime
@@ -65,7 +64,6 @@ protected:
65
64
  *runtime, "paint",
66
65
  jsi::Object::createFromHostObject(*runtime, this->_jsiPaint));
67
66
 
68
- jsiCtx.setProperty(*runtime, "opacity", opacity);
69
67
  jsiCtx.setProperty(
70
68
  *runtime, "canvas",
71
69
  jsi::Object::createFromHostObject(*runtime, jsiCanvas));
@@ -384,14 +384,14 @@ protected:
384
384
  JsiBaseDomDeclarationNode::defineProperties(container);
385
385
  _sourceProp = container->defineProperty<NodeProp>("source");
386
386
  _uniformsProp =
387
- container->defineProperty<SimpleUniformsProp>("uniforms", _sourceProp);
387
+ container->defineProperty<UniformsProp>("uniforms", _sourceProp);
388
388
 
389
389
  _sourceProp->require();
390
390
  }
391
391
 
392
392
  private:
393
393
  NodeProp *_sourceProp;
394
- SimpleUniformsProp *_uniformsProp;
394
+ UniformsProp *_uniformsProp;
395
395
  };
396
396
 
397
397
  } // namespace RNSkia
@@ -34,6 +34,8 @@ public:
34
34
  _cy->value().getAsNumber()));
35
35
  } else if (_c->isSet()) {
36
36
  setDerivedValue(_c->getDerivedValue());
37
+ } else {
38
+ setDerivedValue(SkPoint::Make(0.0, 0.0));
37
39
  }
38
40
  }
39
41
 
@@ -9,6 +9,11 @@
9
9
 
10
10
  namespace RNSkia {
11
11
 
12
+ static PropId PropName0 = JsiPropId::get("0");
13
+ static PropId PropName1 = JsiPropId::get("1");
14
+ static PropId PropName2 = JsiPropId::get("2");
15
+ static PropId PropName3 = JsiPropId::get("3");
16
+
12
17
  class ColorProp : public DerivedProp<SkColor> {
13
18
  public:
14
19
  explicit ColorProp(PropId name) : DerivedProp<SkColor>() {
@@ -28,10 +33,10 @@ public:
28
33
  static SkColor parseColorValue(const JsiValue &color) {
29
34
  if (color.getType() == PropType::Object) {
30
35
  // Float array
31
- auto r = color.getValue(JsiPropId::get("0"));
32
- auto g = color.getValue(JsiPropId::get("1"));
33
- auto b = color.getValue(JsiPropId::get("2"));
34
- auto a = color.getValue(JsiPropId::get("3"));
36
+ auto r = color.getValue(PropName0);
37
+ auto g = color.getValue(PropName1);
38
+ auto b = color.getValue(PropName2);
39
+ auto a = color.getValue(PropName3);
35
40
  return SkColorSetARGB(a.getAsNumber() * 255.0f, r.getAsNumber() * 255.0f,
36
41
  g.getAsNumber() * 255.0f, b.getAsNumber() * 255.0f);
37
42
 
@@ -30,7 +30,8 @@ public:
30
30
  }
31
31
 
32
32
  void updateDerivedValue() override {
33
- if (_imageProp->value().getType() != PropType::HostObject) {
33
+ if (!_imageProp->isSet() ||
34
+ _imageProp->value().getType() != PropType::HostObject) {
34
35
  throw std::runtime_error("Expected SkImage object for the " +
35
36
  std::string(getName()) + " property.");
36
37
  }
@@ -67,7 +68,7 @@ public:
67
68
 
68
69
  auto rect = _rectProp->getDerivedValue() ? *_rectProp->getDerivedValue()
69
70
  : imageRect;
70
- auto fit = _fitProp->isSet() ? _fitProp->value().getAsString() : "none";
71
+ auto fit = _fitProp->isSet() ? _fitProp->value().getAsString() : "contain";
71
72
 
72
73
  setDerivedValue(fitRects(fit, imageRect, rect));
73
74
  }
@@ -92,22 +92,31 @@ public:
92
92
 
93
93
  // Opacity
94
94
  if (_opacity->isChanged() || context->isChanged()) {
95
+ auto parent = context->getParent();
96
+ auto paint = context->getMutablePaint();
95
97
  if (_opacity->isSet()) {
96
- context->setOpacity(_opacity->value().getAsNumber());
98
+ auto currentOpacity = _opacity->value().getAsNumber();
99
+ auto parent = context->getParent();
100
+ if (parent != nullptr) {
101
+ currentOpacity *= parent->getPaint()->getAlphaf();
102
+ }
103
+ paint->setAlphaf(currentOpacity);
97
104
  } else {
98
- context->clearOpacity();
105
+ if (parent != nullptr) {
106
+ paint->setAlphaf(parent->getPaint()->getAlphaf());
107
+ } else {
108
+ paint->setAlphaf(1.0);
109
+ }
99
110
  }
100
111
  }
101
112
 
102
113
  // COLOR
103
114
  if (_color->isSet() && (_color->isChanged() || context->isChanged())) {
104
115
  auto paint = context->getMutablePaint();
116
+ auto opacity = paint->getAlphaf();
105
117
  paint->setShader(nullptr);
106
118
  paint->setColor(*_color->getDerivedValue());
107
- paint->setAlphaf(context->getOpacity() * paint->getColor4f().fA);
108
- } else if (context->isChanged()) {
109
- auto paint = context->getMutablePaint();
110
- paint->setAlphaf(context->getOpacity());
119
+ paint->setAlphaf(opacity * paint->getColor4f().fA);
111
120
  }
112
121
 
113
122
  // Style
@@ -76,10 +76,17 @@ public:
76
76
  }
77
77
 
78
78
  void updateDerivedValue() override {
79
- if (_x->isSet() && _y->isSet() && _width->isSet() && _height->isSet()) {
80
- setDerivedValue(SkRect::MakeXYWH(
81
- _x->value().getAsNumber(), _y->value().getAsNumber(),
82
- _width->value().getAsNumber(), _height->value().getAsNumber()));
79
+ if (_width->isSet() && _height->isSet()) {
80
+ auto x = 0.0;
81
+ auto y = 0.0;
82
+ if (_x->isSet()) {
83
+ x = _x->value().getAsNumber();
84
+ }
85
+ if (_y->isSet()) {
86
+ y = _y->value().getAsNumber();
87
+ }
88
+ setDerivedValue(SkRect::MakeXYWH(x, y, _width->value().getAsNumber(),
89
+ _height->value().getAsNumber()));
83
90
  }
84
91
  }
85
92
 
@@ -16,6 +16,68 @@
16
16
 
17
17
  namespace RNSkia {
18
18
 
19
+ bool isJSPoint(const JsiValue &value) {
20
+ return value.getType() == PropType::Object && value.hasValue(PropNameX) &&
21
+ value.hasValue(PropNameY);
22
+ }
23
+
24
+ bool isSkPoint(const JsiValue &value) {
25
+ return value.getType() == PropType::HostObject &&
26
+ std::dynamic_pointer_cast<JsiSkPoint>(value.getAsHostObject()) !=
27
+ nullptr;
28
+ }
29
+
30
+ bool isIndexable(const JsiValue &value) {
31
+ return value.getType() == PropType::Object && value.hasValue(PropName0);
32
+ }
33
+
34
+ void processValue(std::vector<SkScalar> &values, const JsiValue &value) {
35
+ if (value.getType() == PropType::Number) {
36
+ auto n = value.getAsNumber();
37
+ values.push_back(n);
38
+ } else if (value.getType() == PropType::Array) {
39
+ auto arrayValue = value.getAsArray();
40
+ for (size_t i = 0; i < arrayValue.size(); ++i) {
41
+ auto a = arrayValue[i];
42
+ processValue(values, a);
43
+ }
44
+ } else if (isJSPoint(value) || isSkPoint(value)) {
45
+ auto pointValue = PointProp::processValue(value);
46
+ values.push_back(pointValue.x());
47
+ values.push_back(pointValue.y());
48
+ } else if (isIndexable(value)) {
49
+ auto length = value.getKeys().size();
50
+ for (size_t i = 0; i < length; ++i) {
51
+ values.push_back(
52
+ value.getValue(JsiPropId::get(std::to_string(i))).getAsNumber());
53
+ }
54
+ }
55
+ }
56
+
57
+ void processUniform(std::vector<SkScalar> &values, SkRuntimeEffect *source,
58
+ const JsiValue &uniforms, SkRuntimeShaderBuilder *rtb) {
59
+ auto uniformsCount = source->uniforms().size();
60
+ for (size_t i = 0; i < uniformsCount; ++i) {
61
+ auto it = source->uniforms().begin() + i;
62
+ auto name = JsiPropId::get(std::string(it->name));
63
+ if (!uniforms.hasValue(name)) {
64
+ throw std::runtime_error("The runtime effect has the uniform value \"" +
65
+ std::string(name) +
66
+ "\" declared, but it is missing from the "
67
+ "uniforms property of the Runtime effect.");
68
+ }
69
+ auto value = uniforms.getValue(name);
70
+ if (rtb == nullptr) {
71
+ processValue(values, value);
72
+ } else {
73
+ std::vector<SkScalar> uniformValue;
74
+ processValue(uniformValue, value);
75
+ rtb->uniform(name).set(uniformValue.data(),
76
+ static_cast<int>(uniformValue.size()));
77
+ }
78
+ }
79
+ }
80
+
19
81
  class UniformsProp : public DerivedSkProp<SkData> {
20
82
  public:
21
83
  UniformsProp(PropId name, NodeProp *sourceProp) : DerivedSkProp<SkData>() {
@@ -32,7 +94,9 @@ public:
32
94
  auto source = _sourceProp->value().getAs<JsiSkRuntimeEffect>()->getObject();
33
95
 
34
96
  // Flatten uniforms from property
35
- auto uniformValues = flattenUniforms(source.get(), _uniformsProp->value());
97
+ std::vector<SkScalar> uniformValues;
98
+ processUniform(uniformValues, source.get(), _uniformsProp->value(),
99
+ nullptr);
36
100
 
37
101
  // Cast uniforms according to the declaration in the shader
38
102
  auto uniformsData = castUniforms(source.get(), uniformValues);
@@ -41,11 +105,30 @@ public:
41
105
  setDerivedValue(uniformsData);
42
106
  }
43
107
 
108
+ void processUniforms(SkRuntimeShaderBuilder &rtb) {
109
+ if (!_uniformsProp->isSet()) {
110
+ return;
111
+ }
112
+
113
+ // Get the effect
114
+ auto source = _sourceProp->value().getAs<JsiSkRuntimeEffect>()->getObject();
115
+ // Flatten uniforms from property
116
+ std::vector<SkScalar> uniformValues;
117
+ processUniform(uniformValues, source.get(), _uniformsProp->value(), &rtb);
118
+ }
119
+
44
120
  private:
45
121
  sk_sp<SkData> castUniforms(SkRuntimeEffect *source,
46
122
  const std::vector<SkScalar> &values) {
47
123
  // Create memory for uniforms
48
- auto uniformsData = SkData::MakeUninitialized(source->uniformSize());
124
+ auto uniformSize = source->uniformSize();
125
+ if (values.size() * sizeof(float) != uniformSize) {
126
+ throw std::runtime_error(
127
+ "Uniforms size differs from effect's uniform size. Received " +
128
+ std::to_string(values.size()) + " expected " +
129
+ std::to_string(uniformSize / sizeof(float)));
130
+ }
131
+ auto uniformsData = SkData::MakeUninitialized(uniformSize);
49
132
 
50
133
  // Loop through all uniforms in the effect and load data from the flattened
51
134
  // array of values
@@ -57,7 +140,7 @@ private:
57
140
  const std::size_t offset = reu.slot + j;
58
141
  float fValue = values.at(offset);
59
142
  int iValue = static_cast<int>(fValue);
60
- auto value = reu.isInteger ? iValue : fValue;
143
+ auto value = reu.isInteger ? SkBits2Float(iValue) : fValue;
61
144
  memcpy(SkTAddOffset<void>(uniformsData->writable_data(),
62
145
  offset * sizeof(value)),
63
146
  &value, sizeof(value));
@@ -67,126 +150,6 @@ private:
67
150
  return uniformsData;
68
151
  }
69
152
 
70
- std::vector<SkScalar> flattenUniforms(SkRuntimeEffect *source,
71
- const JsiValue &propObject) {
72
- auto uniformsCount = source->uniforms().size();
73
- std::vector<SkScalar> uniformValues;
74
-
75
- for (size_t i = 0; i < uniformsCount; ++i) {
76
- auto it = source->uniforms().begin() + i;
77
- auto name = JsiPropId::get(std::string(it->name));
78
-
79
- if (!propObject.hasValue(name)) {
80
- throw std::runtime_error("The runtime effect has the uniform value \"" +
81
- std::string(name) +
82
- "\" declared, but it is missing from the "
83
- "uniforms property of the Runtime effect.");
84
- }
85
-
86
- auto value = propObject.getValue(name);
87
-
88
- // A uniform value can be a single number, a vector or an array of numbers
89
- // Or an array of the above
90
- if (value.getType() == PropType::Number) {
91
- // Set numeric uniform
92
- uniformValues.push_back(value.getAsNumber());
93
- } else if (value.getType() == PropType::Array) {
94
- // Array
95
- auto arrayValue = value.getAsArray();
96
- for (size_t n = 0; n < arrayValue.size(); ++n) {
97
- auto a = arrayValue[n];
98
- if (a.getType() == PropType::Number) {
99
- uniformValues.push_back(a.getAsNumber());
100
- } else {
101
- for (size_t j = 0; j < a.getAsArray().size(); ++j) {
102
- uniformValues.push_back(a.getAsArray()[j].getAsNumber());
103
- }
104
- }
105
- }
106
- } else if (value.getType() == PropType::HostObject ||
107
- value.getType() == PropType::Object) {
108
- // Vector (JsiSkPoint / JsiSkRect)
109
- auto pointValue = PointProp::processValue(value);
110
- uniformValues.push_back(pointValue.x());
111
- uniformValues.push_back(pointValue.y());
112
- }
113
- }
114
- return uniformValues;
115
- }
116
-
117
- NodeProp *_uniformsProp;
118
- NodeProp *_sourceProp;
119
- };
120
-
121
- class SimpleUniformsProp : public BaseDerivedProp {
122
- public:
123
- SimpleUniformsProp(PropId name, NodeProp *sourceProp) : BaseDerivedProp() {
124
- _uniformsProp = addProperty(std::make_shared<NodeProp>(name));
125
- _sourceProp = sourceProp;
126
- }
127
-
128
- void processUniforms(SkRuntimeShaderBuilder &rtb) {
129
- if (!_uniformsProp->isSet()) {
130
- return;
131
- }
132
-
133
- auto propObject = _uniformsProp->value();
134
- auto source = _sourceProp->value().getAs<JsiSkRuntimeEffect>()->getObject();
135
-
136
- auto uniformsCount = source->uniforms().size();
137
-
138
- for (size_t i = 0; i < uniformsCount; ++i) {
139
- auto it = source->uniforms().begin() + i;
140
- auto name = JsiPropId::get(std::string(it->name));
141
-
142
- if (!propObject.hasValue(name)) {
143
- throw std::runtime_error("The runtime effect has the uniform value \"" +
144
- std::string(name) +
145
- "\" declared, but it is missing from the "
146
- "uniforms property of the Runtime effect.");
147
- }
148
-
149
- auto value = propObject.getValue(name);
150
-
151
- // A uniform value can be a single number, a vector or an array of numbers
152
- // Or an array of the above
153
- if (value.getType() == PropType::Number) {
154
- // Set numeric uniform
155
- rtb.uniform(name) = value.getAsNumber();
156
- } else if (value.getType() == PropType::Array) {
157
- // Array
158
- auto arrayValue = value.getAsArray();
159
- std::vector<SkScalar> set;
160
- for (size_t n = 0; n < arrayValue.size(); ++n) {
161
- auto a = arrayValue[n];
162
- if (a.getType() == PropType::Number) {
163
- set.push_back(a.getAsNumber());
164
- } else {
165
- for (size_t j = 0; j < a.getAsArray().size(); ++j) {
166
- set.push_back(a.getAsArray()[j].getAsNumber());
167
- }
168
- }
169
- }
170
- rtb.uniform(name).set(set.data(), static_cast<int>(set.size()));
171
-
172
- } else if (value.getType() == PropType::HostObject ||
173
- value.getType() == PropType::Object) {
174
- // Vector (JsiSkPoint / JsiSkRect)
175
- auto pointValue = PointProp::processValue(value);
176
- std::vector<SkScalar> set = {pointValue.x(), pointValue.y()};
177
-
178
- rtb.uniform(name).set(set.data(), static_cast<int>(set.size()));
179
- } else {
180
- throw std::runtime_error("Unexpected type for uniform prop \"" +
181
- std::string(name) + "\". Got " +
182
- value.getTypeAsString(value.getType()));
183
- }
184
- }
185
- }
186
-
187
- void updateDerivedValue() override {}
188
-
189
- private:
190
153
  NodeProp *_uniformsProp;
191
154
  NodeProp *_sourceProp;
192
155
  };
@@ -142,12 +142,8 @@ protected:
142
142
  @param runtime Current JS Runtime
143
143
  */
144
144
  void notifyListeners(jsi::Runtime &runtime) {
145
- std::unordered_map<long, std::function<void(jsi::Runtime &)>> tmp;
146
- {
147
- std::lock_guard<std::mutex> lock(_mutex);
148
- tmp.insert(_listeners.cbegin(), _listeners.cend());
149
- }
150
- for (const auto &listener : tmp) {
145
+ std::lock_guard<std::mutex> lock(_mutex);
146
+ for (const auto &listener : _listeners) {
151
147
  listener.second(runtime);
152
148
  }
153
149
  }
@@ -19,7 +19,12 @@ const processCircle = (Skia, def) => {
19
19
  };
20
20
  }
21
21
 
22
- return def;
22
+ return { ...def,
23
+ c: def.c ?? {
24
+ x: 0,
25
+ y: 0
26
+ }
27
+ };
23
28
  };
24
29
 
25
30
  exports.processCircle = processCircle;
@@ -1 +1 @@
1
- {"version":3,"names":["isCircleScalarDef","def","cx","undefined","processCircle","Skia","c","Point","cy","r"],"sources":["Circle.ts"],"sourcesContent":["import type { Skia } from \"../../../skia/types\";\nimport type { CircleDef, ScalarCircleDef } from \"../../types\";\n\nexport const isCircleScalarDef = (def: CircleDef): def is ScalarCircleDef =>\n // We have an issue to check property existence on JSI backed instances\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (def as any).cx !== undefined;\n\nexport const processCircle = (Skia: Skia, def: CircleDef) => {\n if (isCircleScalarDef(def)) {\n return { c: Skia.Point(def.cx, def.cy), r: def.r };\n }\n return def;\n};\n"],"mappings":";;;;;;;AAGO,MAAMA,iBAAiB,GAAIC,GAAD,IAC/B;AACA;AACCA,GAAD,CAAaC,EAAb,KAAoBC,SAHf;;;;AAKA,MAAMC,aAAa,GAAG,CAACC,IAAD,EAAaJ,GAAb,KAAgC;EAC3D,IAAID,iBAAiB,CAACC,GAAD,CAArB,EAA4B;IAC1B,OAAO;MAAEK,CAAC,EAAED,IAAI,CAACE,KAAL,CAAWN,GAAG,CAACC,EAAf,EAAmBD,GAAG,CAACO,EAAvB,CAAL;MAAiCC,CAAC,EAAER,GAAG,CAACQ;IAAxC,CAAP;EACD;;EACD,OAAOR,GAAP;AACD,CALM"}
1
+ {"version":3,"names":["isCircleScalarDef","def","cx","undefined","processCircle","Skia","c","Point","cy","r","x","y"],"sources":["Circle.ts"],"sourcesContent":["import type { Skia } from \"../../../skia/types\";\nimport type { CircleDef, ScalarCircleDef } from \"../../types\";\n\nexport const isCircleScalarDef = (def: CircleDef): def is ScalarCircleDef =>\n // We have an issue to check property existence on JSI backed instances\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (def as any).cx !== undefined;\n\nexport const processCircle = (Skia: Skia, def: CircleDef) => {\n if (isCircleScalarDef(def)) {\n return { c: Skia.Point(def.cx, def.cy), r: def.r };\n }\n return { ...def, c: def.c ?? { x: 0, y: 0 } };\n};\n"],"mappings":";;;;;;;AAGO,MAAMA,iBAAiB,GAAIC,GAAD,IAC/B;AACA;AACCA,GAAD,CAAaC,EAAb,KAAoBC,SAHf;;;;AAKA,MAAMC,aAAa,GAAG,CAACC,IAAD,EAAaJ,GAAb,KAAgC;EAC3D,IAAID,iBAAiB,CAACC,GAAD,CAArB,EAA4B;IAC1B,OAAO;MAAEK,CAAC,EAAED,IAAI,CAACE,KAAL,CAAWN,GAAG,CAACC,EAAf,EAAmBD,GAAG,CAACO,EAAvB,CAAL;MAAiCC,CAAC,EAAER,GAAG,CAACQ;IAAxC,CAAP;EACD;;EACD,OAAO,EAAE,GAAGR,GAAL;IAAUK,CAAC,EAAEL,GAAG,CAACK,CAAJ,IAAS;MAAEI,CAAC,EAAE,CAAL;MAAQC,CAAC,EAAE;IAAX;EAAtB,CAAP;AACD,CALM"}
@@ -20,7 +20,7 @@ const isRectCtor = def => def.rect === undefined;
20
20
 
21
21
  const processRect = (Skia, def) => {
22
22
  if (isRectCtor(def)) {
23
- return Skia.XYWHRect(def.x, def.y, def.width, def.height);
23
+ return Skia.XYWHRect(def.x ?? 0, def.y ?? 0, def.width, def.height);
24
24
  } else {
25
25
  return def.rect;
26
26
  }
@@ -30,8 +30,8 @@ exports.processRect = processRect;
30
30
 
31
31
  const processRRect = (Skia, def) => {
32
32
  if (isRRectCtor(def)) {
33
- const r = (0, _Radius.processRadius)(Skia, def.r);
34
- return Skia.RRectXY(Skia.XYWHRect(def.x, def.y, def.width, def.height), r.x, r.y);
33
+ const r = (0, _Radius.processRadius)(Skia, def.r ?? 0);
34
+ return Skia.RRectXY(Skia.XYWHRect(def.x ?? 0, def.y ?? 0, def.width, def.height), r.x, r.y);
35
35
  } else {
36
36
  return def.rect;
37
37
  }