0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-03-24 05:31:25 -05:00

Merge pull request #5667 from penpot/superalex-fix-blend-modes-render-wasm

🐛 Fix blend modes for wasm render
This commit is contained in:
Belén Albeza 2025-01-27 11:00:38 +01:00 committed by GitHub
commit 2726fa04c0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 31 additions and 22 deletions

View file

@ -493,7 +493,9 @@
id (dm/get-prop shape :id)
type (dm/get-prop shape :type)
selrect (dm/get-prop shape :selrect)
clip-content (not (dm/get-prop shape :show-content))
clip-content (if (= type :frame)
(not (dm/get-prop shape :show-content))
false)
rotation (dm/get-prop shape :rotation)
transform (dm/get-prop shape :transform)
fills (if (= type :group)

View file

@ -115,7 +115,9 @@
:bool-type (api/set-shape-bool-type v)
:bool-content (api/set-shape-bool-content v)
:selrect (api/set-shape-selrect v)
:show-content (api/set-shape-clip-content (not v))
:show-content (if (= (:type self) :frame)
(api/set-shape-clip-content (not v))
(api/set-shape-clip-content false))
:rotation (api/set-shape-rotation v)
:transform (api/set-shape-transform v)
:fills (api/set-shape-fills v)

View file

@ -142,7 +142,7 @@ impl RenderState {
pub fn reset_canvas(&mut self) {
self.drawing_surface
.canvas()
.clear(skia::Color::TRANSPARENT)
.clear(self.background_color)
.reset_matrix();
self.final_surface
.canvas()
@ -154,7 +154,20 @@ impl RenderState {
.reset_matrix();
}
pub fn render_shape(&mut self, shape: &mut Shape) {
pub fn apply_drawing_to_final_canvas(&mut self) {
self.drawing_surface.draw(
&mut self.final_surface.canvas(),
(0.0, 0.0),
skia::SamplingOptions::new(skia::FilterMode::Linear, skia::MipmapMode::Nearest),
Some(&skia::Paint::default()),
);
self.drawing_surface
.canvas()
.clear(skia::Color::TRANSPARENT);
}
pub fn render_shape(&mut self, shape: &mut Shape, clip: bool) {
let transform = shape.transform.to_skia_matrix();
// Check transform-matrix code from common/src/app/common/geom/shapes/transforms.cljc
@ -195,16 +208,13 @@ impl RenderState {
}
};
self.drawing_surface.draw(
&mut self.final_surface.canvas(),
(0.0, 0.0),
skia::SamplingOptions::new(skia::FilterMode::Linear, skia::MipmapMode::Nearest),
Some(&skia::Paint::default()),
);
if clip {
self.drawing_surface
.canvas()
.clip_rect(shape.bounds(), skia::ClipOp::Intersect, true);
}
self.drawing_surface
.canvas()
.clear(skia::Color::TRANSPARENT);
self.apply_drawing_to_final_canvas();
}
pub fn zoom(&mut self, tree: &HashMap<Uuid, Shape>) -> Result<(), String> {
@ -325,17 +335,12 @@ impl RenderState {
let layer_rec = skia::canvas::SaveLayerRec::default().paint(&paint);
// This is needed so the next non-children shape does not carry this shape's transform
self.final_surface.canvas().save_layer(&layer_rec);
self.drawing_surface.canvas().save();
self.drawing_surface.canvas().save();
if !root_id.is_nil() {
self.render_shape(&mut element.clone());
if element.clip() {
self.drawing_surface.canvas().clip_rect(
element.bounds(),
skia::ClipOp::Intersect,
true,
);
}
self.render_shape(&mut element.clone(), element.clip());
} else {
self.apply_drawing_to_final_canvas();
}
self.drawing_surface.canvas().restore();