Skip to content

Commit e4be3c1

Browse files
committed
Add missing backdrop handling in CTM cmd; more consistent ordering of savelayer props for readability
1 parent fc6edf3 commit e4be3c1

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

packages/skia/cpp/api/recorder/Paint.h

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ SkMatrix processTransform(std::optional<SkMatrix> &matrix,
4141
}
4242

4343
struct SaveLayerProps {
44-
std::optional<SkCanvas::SaveLayerFlags> saveLayerFlags;
4544
std::optional<sk_sp<SkImageFilter>> backdropFilter;
45+
std::optional<SkCanvas::SaveLayerFlags> saveLayerFlags;
4646
}
4747

4848
class SaveLayerCmd : public Command {
@@ -53,10 +53,10 @@ class SaveLayerCmd : public Command {
5353
SaveLayerCmd(jsi::Runtime &runtime, const jsi::Object &object,
5454
Variables &variables)
5555
: Command(CommandType::SaveLayer) {
56-
convertProperty(runtime, object, "saveLayerFlags", props.saveLayerFlags,
57-
variables);
5856
convertProperty(runtime, object, "backdropFilter", props.backdropFilter,
5957
variables);
58+
convertProperty(runtime, object, "saveLayerFlags", props.saveLayerFlags,
59+
variables);
6060
}
6161

6262
void saveLayer(DrawingCtx *ctx) {
@@ -92,6 +92,8 @@ class SaveCTMCmd : public Command {
9292
convertProperty(runtime, object, "clip", props.clip, variables);
9393
convertProperty(runtime, object, "invertClip", props.invertClip, variables);
9494
convertProperty(runtime, object, "layer", props.layer, variables);
95+
convertProperty(runtime, object, "backdropFilter", props.backdropFilter,
96+
variables);
9597
convertProperty(runtime, object, "saveLayerFlags", props.saveLayerFlags,
9698
variables);
9799
}
@@ -100,6 +102,7 @@ class SaveCTMCmd : public Command {
100102
auto clip = props.clip;
101103
auto invertClip = props.invertClip;
102104
auto layer = props.layer;
105+
auto backdropFilter = props.backdropFilter;
103106
auto saveLayerFlags = props.saveLayerFlags;
104107
auto hasTransform = props.matrix.has_value() || props.transform.has_value();
105108
auto hasClip = clip.has_value();
@@ -112,9 +115,9 @@ class SaveCTMCmd : public Command {
112115
if (layer.has_value()) {
113116
SkCanvas::SaveLayerRec layerRec;
114117
layerRec.fPaint = std::get_if<SkPaint>(layer.value());
115-
if (saveLayerFlags.has_value()) {
116-
layerRec.fSaveLayerFlags = saveLayerFlags.value();
117-
}
118+
layerRec.fBackdropFilter = backdropFilter.value_or(nullptr);
119+
layerRec.fSaveLayerFlags = saveLayerFlags.value_or(0);
120+
118121
ctx->canvas->saveLayer(layerRec);
119122
} else {
120123
ctx->canvas->save();

packages/skia/src/renderer/components/Group.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export const Group = ({
1717
if (isValidElement(layer) && typeof layer === "object") {
1818
return (
1919
// keep the saveLayerFlags on whichever node triggers saveLayer
20-
<skLayer saveLayerFlags={saveLayerFlags} backdropFilter={backdropFilter}>
20+
<skLayer backdropFilter={backdropFilter} saveLayerFlags={saveLayerFlags}>
2121
{layer}
2222
<skGroup {...props} />
2323
</skLayer>

packages/skia/src/sksg/Recorder/commands/CTM.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export const saveCTM = (ctx: DrawingContext, props: CTMProps) => {
3939
transform,
4040
origin,
4141
layer,
42+
backdropFilter,
4243
saveLayerFlags,
4344
} = props;
4445
const hasTransform = matrix !== undefined || transform !== undefined;
@@ -50,7 +51,7 @@ export const saveCTM = (ctx: DrawingContext, props: CTMProps) => {
5051
if (shouldSave) {
5152
if (layer) {
5253
const paint = typeof layer === "boolean" ? undefined : layer;
53-
canvas.saveLayer(paint, null, null, saveLayerFlags);
54+
canvas.saveLayer(paint, null, backdropFilter, saveLayerFlags);
5455
} else {
5556
canvas.save();
5657
}

0 commit comments

Comments
 (0)