mirror of
https://github.com/penpot/penpot.git
synced 2025-01-06 14:50:20 -05:00
♻️ Refactor rendering fills
This commit is contained in:
parent
58c4e53ee4
commit
df6727f186
1 changed files with 22 additions and 19 deletions
|
@ -5,9 +5,8 @@ use std::collections::HashMap;
|
|||
use uuid::Uuid;
|
||||
|
||||
use crate::debug;
|
||||
use crate::shapes::Fill;
|
||||
use crate::shapes::Shape;
|
||||
use crate::shapes::{draw_image_in_container, Image};
|
||||
use crate::math::Rect;
|
||||
use crate::shapes::{draw_image_in_container, Fill, Image, Shape};
|
||||
use crate::view::Viewbox;
|
||||
|
||||
struct GpuState {
|
||||
|
@ -225,22 +224,7 @@ impl RenderState {
|
|||
self.drawing_surface.canvas().concat(&matrix);
|
||||
|
||||
for fill in shape.fills().rev() {
|
||||
if let Fill::Image(image_fill) = fill {
|
||||
let image = self.images.get(&image_fill.id());
|
||||
if let Some(image) = image {
|
||||
draw_image_in_container(
|
||||
&self.drawing_surface.canvas(),
|
||||
&image,
|
||||
image_fill.size(),
|
||||
shape.selrect,
|
||||
&fill.to_paint(&shape.selrect),
|
||||
);
|
||||
}
|
||||
} else {
|
||||
self.drawing_surface
|
||||
.canvas()
|
||||
.draw_rect(shape.selrect, &fill.to_paint(&shape.selrect));
|
||||
}
|
||||
self.render_fill(fill, shape.selrect);
|
||||
}
|
||||
|
||||
let mut paint = skia::Paint::default();
|
||||
|
@ -297,6 +281,25 @@ impl RenderState {
|
|||
self.flush();
|
||||
}
|
||||
|
||||
fn render_fill(&mut self, fill: &Fill, selrect: Rect) {
|
||||
if let Fill::Image(image_fill) = fill {
|
||||
let image = self.images.get(&image_fill.id());
|
||||
if let Some(image) = image {
|
||||
draw_image_in_container(
|
||||
&self.drawing_surface.canvas(),
|
||||
&image,
|
||||
image_fill.size(),
|
||||
selrect,
|
||||
&fill.to_paint(&selrect),
|
||||
);
|
||||
}
|
||||
} else {
|
||||
self.drawing_surface
|
||||
.canvas()
|
||||
.draw_rect(selrect, &fill.to_paint(&selrect));
|
||||
}
|
||||
}
|
||||
|
||||
fn render_all_from_cache(&mut self) -> Result<(), String> {
|
||||
self.reset_canvas();
|
||||
|
||||
|
|
Loading…
Reference in a new issue