Skip to content

Commit c026636

Browse files
authored
fix(🐛): fix conflicting header name on iOS (#2924)
1 parent 9ca4df0 commit c026636

File tree

7 files changed

+122
-116
lines changed

7 files changed

+122
-116
lines changed

Diff for: packages/skia/cpp/api/recorder/Convertor.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -781,7 +781,8 @@ SkRect getPropertyValue(jsi::Runtime &runtime, const jsi::Value &value) {
781781
}
782782

783783
template <>
784-
std::variant<SkRect, SkRRect> getPropertyValue(jsi::Runtime &runtime, const jsi::Value &value) {
784+
std::variant<SkRect, SkRRect> getPropertyValue(jsi::Runtime &runtime,
785+
const jsi::Value &value) {
785786
if (value.isObject()) {
786787
auto rect = processRect(runtime, value);
787788
if (rect) {

Diff for: packages/skia/cpp/api/recorder/DataTypes.h

+70-72
Original file line numberDiff line numberDiff line change
@@ -148,87 +148,85 @@ std::shared_ptr<SkPath> processPath(jsi::Runtime &runtime,
148148
}
149149

150150
// 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+
}
166165

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;
177169

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+
}
190188
}
189+
}
191190

192-
return uniformsData;
191+
return uniformsData;
193192
}
194193

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) {
207197

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+
}
218205

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());
231228
}
229+
}
232230
}
233231

234232
} // namespace RNSkia

Diff for: packages/skia/cpp/api/recorder/Drawings.h

+25-24
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#include "Command.h"
66
#include "Convertor.h"
77
#include "DrawingCtx.h"
8-
#include "Image.h"
8+
#include "ImageFit.h"
99

1010
namespace RNSkia {
1111

@@ -355,35 +355,35 @@ class BoxCmd : public Command {
355355
std::vector<BoxShadowCmdProps> shadows;
356356

357357
// Helper function to inflate RRect (deflate is just negative inflation)
358-
SkRRect inflate(const SkRRect& box, float dx, float dy, float tx = 0, float ty = 0) {
359-
const auto& rect = box.rect();
360-
SkRect newRect = SkRect::MakeXYWH(
361-
rect.x() - dx + tx,
362-
rect.y() - dy + ty,
363-
rect.width() + 2 * dx,
364-
rect.height() + 2 * dy
365-
);
366-
358+
SkRRect inflate(const SkRRect &box, float dx, float dy, float tx = 0,
359+
float ty = 0) {
360+
const auto &rect = box.rect();
361+
SkRect newRect =
362+
SkRect::MakeXYWH(rect.x() - dx + tx, rect.y() - dy + ty,
363+
rect.width() + 2 * dx, rect.height() + 2 * dy);
364+
367365
SkRRect result;
368366
result.setRectXY(newRect, box.radii()[0].fX + dx, box.radii()[0].fY + dy);
369367
return result;
370368
}
371369

372-
SkRRect deflate(const SkRRect& box, float dx, float dy, float tx = 0, float ty = 0) {
370+
SkRRect deflate(const SkRRect &box, float dx, float dy, float tx = 0,
371+
float ty = 0) {
373372
return inflate(box, -dx, -dy, tx, ty);
374373
}
375374

376375
public:
377-
BoxCmd(jsi::Runtime &runtime, const jsi::Object &object, const jsi::Array &shadowsArray,
378-
Variables &variables)
376+
BoxCmd(jsi::Runtime &runtime, const jsi::Object &object,
377+
const jsi::Array &shadowsArray, Variables &variables)
379378
: Command(CommandType::DrawBox) {
380-
379+
381380
convertProperty(runtime, object, "box", props.box, variables);
382381
size_t shadowCount = shadowsArray.size(runtime);
383382
shadows.reserve(shadowCount);
384-
383+
385384
for (size_t i = 0; i < shadowCount; i++) {
386-
auto shadowObj = shadowsArray.getValueAtIndex(runtime, i).asObject(runtime);
385+
auto shadowObj =
386+
shadowsArray.getValueAtIndex(runtime, i).asObject(runtime);
387387
BoxShadowCmdProps shadow;
388388

389389
convertProperty(runtime, shadowObj, "dx", shadow.dx, variables);
@@ -399,7 +399,6 @@ class BoxCmd : public Command {
399399

400400
void draw(DrawingCtx *ctx) {
401401

402-
403402
// Get current paint properties
404403
auto paint = ctx->getPaint();
405404
float opacity = paint.getAlphaf();
@@ -414,16 +413,17 @@ class BoxCmd : public Command {
414413
}
415414

416415
// Draw outer shadows first
417-
for (const auto& shadow : shadows) {
416+
for (const auto &shadow : shadows) {
418417
if (!shadow.inner.value_or(false)) {
419418
SkPaint shadowPaint;
420419
shadowPaint.setAntiAlias(true);
421420
shadowPaint.setColor(shadow.color.value_or(SK_ColorBLACK));
422421
shadowPaint.setAlphaf(opacity);
423422
shadowPaint.setMaskFilter(SkMaskFilter::MakeBlur(
424-
SkBlurStyle::kNormal_SkBlurStyle, shadow.blur, true));
423+
SkBlurStyle::kNormal_SkBlurStyle, shadow.blur, true));
425424

426-
auto shadowBox = inflate(box, shadow.spread, shadow.spread, shadow.dx, shadow.dy);
425+
auto shadowBox =
426+
inflate(box, shadow.spread, shadow.spread, shadow.dx, shadow.dy);
427427
ctx->canvas->drawRRect(shadowBox, shadowPaint);
428428
}
429429
}
@@ -432,10 +432,10 @@ class BoxCmd : public Command {
432432
ctx->canvas->drawRRect(box, paint);
433433

434434
// Draw inner shadows
435-
for (const auto& shadow : shadows) {
435+
for (const auto &shadow : shadows) {
436436
if (shadow.inner.value_or(false)) {
437437
ctx->canvas->save();
438-
438+
439439
// Clip to box bounds
440440
ctx->canvas->clipRRect(box, SkClipOp::kIntersect, true);
441441

@@ -444,11 +444,12 @@ class BoxCmd : public Command {
444444
shadowPaint.setColor(shadow.color.value_or(SK_ColorBLACK));
445445
shadowPaint.setAlphaf(opacity);
446446
shadowPaint.setMaskFilter(SkMaskFilter::MakeBlur(
447-
SkBlurStyle::kNormal_SkBlurStyle, shadow.blur, true));
447+
SkBlurStyle::kNormal_SkBlurStyle, shadow.blur, true));
448448

449449
// Calculate shadow bounds
450450
float delta = 10 + std::max(std::abs(shadow.dx), std::abs(shadow.dy));
451-
auto inner = deflate(box, shadow.spread, shadow.spread, shadow.dx, shadow.dy);
451+
auto inner =
452+
deflate(box, shadow.spread, shadow.spread, shadow.dx, shadow.dy);
452453
auto outer = inflate(box, delta, delta);
453454

454455
ctx->canvas->drawDRRect(outer, inner, shadowPaint);
File renamed without changes.

Diff for: packages/skia/cpp/api/recorder/RNRecorder.h

+12-10
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,10 @@ class Recorder {
6262
} else if (nodeType == "skTwoPointConicalGradient") {
6363
commands.push_back(std::make_unique<TwoPointConicalGradientCmd>(
6464
runtime, props, variables));
65-
// TODO: should receive skBlendShader here
65+
// TODO: should receive skBlendShader here
6666
} else if (nodeType == "skBlend") {
67-
commands.push_back(std::make_unique<BlendShaderCmd>(runtime, props, variables));
67+
commands.push_back(
68+
std::make_unique<BlendShaderCmd>(runtime, props, variables));
6869
}
6970
}
7071

@@ -204,8 +205,10 @@ class Recorder {
204205
commands.push_back(std::make_unique<Command>(CommandType::DrawPaint));
205206
}
206207

207-
void drawBox(jsi::Runtime &runtime, const jsi::Object &props, const jsi::Array &shadows) {
208-
commands.push_back(std::make_unique<BoxCmd>(runtime, props, shadows, variables));
208+
void drawBox(jsi::Runtime &runtime, const jsi::Object &props,
209+
const jsi::Array &shadows) {
210+
commands.push_back(
211+
std::make_unique<BoxCmd>(runtime, props, shadows, variables));
209212
}
210213

211214
void drawImage(jsi::Runtime &runtime, const jsi::Object &props) {
@@ -376,11 +379,10 @@ class Recorder {
376379
static_cast<TwoPointConicalGradientCmd *>(cmd.get());
377380
twoPointConicalGradientCmd->pushShader(ctx);
378381
} else if (nodeType == "skBlendShader") {
379-
auto *blendShaderCmd =
380-
static_cast<BlendShaderCmd *>(cmd.get());
382+
auto *blendShaderCmd = static_cast<BlendShaderCmd *>(cmd.get());
381383
blendShaderCmd->pushShader(ctx);
382384
} else {
383-
throw std::runtime_error("Invalid shader type: " + nodeType);
385+
throw std::runtime_error("Invalid shader type: " + nodeType);
384386
}
385387
break;
386388
}
@@ -442,8 +444,8 @@ class Recorder {
442444
auto *line2DCmd = static_cast<Line2DPathEffectCmd *>(cmd.get());
443445
line2DCmd->pushPathEffect(ctx);
444446
} else {
445-
throw std::runtime_error("Invalid path effect type: " + nodeType);
446-
}
447+
throw std::runtime_error("Invalid path effect type: " + nodeType);
448+
}
447449
break;
448450
}
449451

@@ -470,7 +472,7 @@ class Recorder {
470472
auto *lerpCmd = static_cast<LerpColorFilterCmd *>(cmd.get());
471473
lerpCmd->pushColorFilter(ctx);
472474
} else {
473-
throw std::runtime_error("Invalid color filter type: " + nodeType);
475+
throw std::runtime_error("Invalid color filter type: " + nodeType);
474476
}
475477
break;
476478
}

Diff for: packages/skia/cpp/api/recorder/Shaders.h

+5-5
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include "Command.h"
1010
#include "Convertor.h"
1111
#include "DrawingCtx.h"
12-
#include "Image.h"
12+
#include "ImageFit.h"
1313

1414
namespace RNSkia {
1515

@@ -41,7 +41,7 @@ class PushShaderCmd : public Command {
4141

4242
std::vector<sk_sp<SkShader>> children = ctx->popAllShaders();
4343
auto shader = source->makeShader(std::move(uniformsData), children.data(),
44-
children.size(), &m3);
44+
children.size(), &m3);
4545

4646
ctx->shaders.push_back(shader);
4747
}
@@ -384,17 +384,17 @@ class BlendShaderCmd : public Command {
384384
void pushShader(DrawingCtx *ctx) {
385385
// Get all existing shaders from the context
386386
std::vector<sk_sp<SkShader>> shaders = ctx->popAllShaders();
387-
387+
388388
// We need at least 2 shaders to blend
389389
if (shaders.size() >= 2) {
390390
// Start from the last shader and blend backwards
391391
sk_sp<SkShader> blendedShader = shaders.back();
392-
392+
393393
// Iterate from second-to-last to first shader
394394
for (int i = shaders.size() - 2; i >= 0; i--) {
395395
blendedShader = SkShaders::Blend(props.mode, shaders[i], blendedShader);
396396
}
397-
397+
398398
ctx->shaders.push_back(blendedShader);
399399
} else if (shaders.size() == 1) {
400400
// If only one shader, just push it back

0 commit comments

Comments
 (0)