@@ -148,87 +148,85 @@ std::shared_ptr<SkPath> processPath(jsi::Runtime &runtime,
148
148
}
149
149
150
150
// Function to process uniforms and return SkData for PushShaderCmd
151
- inline sk_sp<SkData> processUniforms (
152
- const sk_sp<SkRuntimeEffect>& effect,
153
- const Uniforms& uniforms) {
154
-
155
- size_t uniformSize = effect->uniformSize ();
156
- auto uniformsData = SkData::MakeUninitialized (uniformSize);
157
- auto uniformDataPtr = static_cast <float *>(uniformsData->writable_data ());
158
-
159
- const auto & sourceUniforms = effect->uniforms ();
160
- for (const auto & uniform : sourceUniforms) {
161
- auto it = uniforms.find (std::string (uniform.name ));
162
- if (it == uniforms.end ()) {
163
- throw std::runtime_error (" Missing uniform value for: " +
164
- std::string (uniform.name ));
165
- }
151
+ inline sk_sp<SkData> processUniforms (const sk_sp<SkRuntimeEffect> &effect,
152
+ const Uniforms &uniforms) {
153
+
154
+ size_t uniformSize = effect->uniformSize ();
155
+ auto uniformsData = SkData::MakeUninitialized (uniformSize);
156
+ auto uniformDataPtr = static_cast <float *>(uniformsData->writable_data ());
157
+
158
+ const auto &sourceUniforms = effect->uniforms ();
159
+ for (const auto &uniform : sourceUniforms) {
160
+ auto it = uniforms.find (std::string (uniform.name ));
161
+ if (it == uniforms.end ()) {
162
+ throw std::runtime_error (" Missing uniform value for: " +
163
+ std::string (uniform.name ));
164
+ }
166
165
167
- const auto & uniformValues = it->second ;
168
- RuntimeEffectUniform reu = JsiSkRuntimeEffect::fromUniform (uniform);
169
- size_t expectedSize = reu.columns * reu.rows ;
170
-
171
- if (uniformValues.size () != expectedSize) {
172
- throw std::runtime_error (" Incorrect uniform size for: " +
173
- std::string (uniform.name ) + " . Expected " +
174
- std::to_string (expectedSize) + " got " +
175
- std::to_string (uniformValues.size ()));
176
- }
166
+ const auto &uniformValues = it->second ;
167
+ RuntimeEffectUniform reu = JsiSkRuntimeEffect::fromUniform (uniform);
168
+ size_t expectedSize = reu.columns * reu.rows ;
177
169
178
- // Process each element in the uniform
179
- for (std::size_t j = 0 ; j < expectedSize; ++j) {
180
- const std::size_t offset = reu.slot + j;
181
- float fValue = uniformValues[j];
182
-
183
- if (reu.isInteger ) {
184
- int iValue = static_cast <int >(fValue );
185
- uniformDataPtr[offset] = SkBits2Float (iValue);
186
- } else {
187
- uniformDataPtr[offset] = fValue ;
188
- }
189
- }
170
+ if (uniformValues.size () != expectedSize) {
171
+ throw std::runtime_error (
172
+ " Incorrect uniform size for: " + std::string (uniform.name ) +
173
+ " . Expected " + std::to_string (expectedSize) + " got " +
174
+ std::to_string (uniformValues.size ()));
175
+ }
176
+
177
+ // Process each element in the uniform
178
+ for (std::size_t j = 0 ; j < expectedSize; ++j) {
179
+ const std::size_t offset = reu.slot + j;
180
+ float fValue = uniformValues[j];
181
+
182
+ if (reu.isInteger ) {
183
+ int iValue = static_cast <int >(fValue );
184
+ uniformDataPtr[offset] = SkBits2Float (iValue);
185
+ } else {
186
+ uniformDataPtr[offset] = fValue ;
187
+ }
190
188
}
189
+ }
191
190
192
- return uniformsData;
191
+ return uniformsData;
193
192
}
194
193
195
- inline void processUniforms (
196
- SkRuntimeShaderBuilder& builder,
197
- const sk_sp<SkRuntimeEffect>& effect,
198
- const Uniforms& uniforms) {
199
-
200
- const auto & sourceUniforms = effect->uniforms ();
201
- for (const auto & uniform : sourceUniforms) {
202
- auto it = uniforms.find (std::string (uniform.name ));
203
- if (it == uniforms.end ()) {
204
- throw std::runtime_error (" Missing uniform value for: " +
205
- std::string (uniform.name ));
206
- }
194
+ inline void processUniforms (SkRuntimeShaderBuilder &builder,
195
+ const sk_sp<SkRuntimeEffect> &effect,
196
+ const Uniforms &uniforms) {
207
197
208
- const auto & uniformValues = it->second ;
209
- RuntimeEffectUniform reu = JsiSkRuntimeEffect::fromUniform (uniform);
210
- size_t expectedSize = reu.columns * reu.rows ;
211
-
212
- if (uniformValues.size () != expectedSize) {
213
- throw std::runtime_error (" Incorrect uniform size for: " +
214
- std::string (uniform.name ) + " . Expected " +
215
- std::to_string (expectedSize) + " got " +
216
- std::to_string (uniformValues.size ()));
217
- }
198
+ const auto &sourceUniforms = effect->uniforms ();
199
+ for (const auto &uniform : sourceUniforms) {
200
+ auto it = uniforms.find (std::string (uniform.name ));
201
+ if (it == uniforms.end ()) {
202
+ throw std::runtime_error (" Missing uniform value for: " +
203
+ std::string (uniform.name ));
204
+ }
218
205
219
- auto builderUniform = builder.uniform (uniform.name );
220
-
221
- if (reu.isInteger ) {
222
- std::vector<float > convertedValues (uniformValues.size ());
223
- for (size_t i = 0 ; i < uniformValues.size (); ++i) {
224
- int iValue = static_cast <int >(uniformValues[i]);
225
- convertedValues[i] = SkBits2Float (iValue);
226
- }
227
- builderUniform.set (convertedValues.data (), convertedValues.size ());
228
- } else {
229
- builderUniform.set (uniformValues.data (), uniformValues.size ());
230
- }
206
+ const auto &uniformValues = it->second ;
207
+ RuntimeEffectUniform reu = JsiSkRuntimeEffect::fromUniform (uniform);
208
+ size_t expectedSize = reu.columns * reu.rows ;
209
+
210
+ if (uniformValues.size () != expectedSize) {
211
+ throw std::runtime_error (
212
+ " Incorrect uniform size for: " + std::string (uniform.name ) +
213
+ " . Expected " + std::to_string (expectedSize) + " got " +
214
+ std::to_string (uniformValues.size ()));
215
+ }
216
+
217
+ auto builderUniform = builder.uniform (uniform.name );
218
+
219
+ if (reu.isInteger ) {
220
+ std::vector<float > convertedValues (uniformValues.size ());
221
+ for (size_t i = 0 ; i < uniformValues.size (); ++i) {
222
+ int iValue = static_cast <int >(uniformValues[i]);
223
+ convertedValues[i] = SkBits2Float (iValue);
224
+ }
225
+ builderUniform.set (convertedValues.data (), convertedValues.size ());
226
+ } else {
227
+ builderUniform.set (uniformValues.data (), uniformValues.size ());
231
228
}
229
+ }
232
230
}
233
231
234
232
} // namespace RNSkia
0 commit comments