Skip to content

Commit

Permalink
Merge pull request #43 from gabm/improve-rendering-performance
Browse files Browse the repository at this point in the history
improve rendering performance a bit
  • Loading branch information
gabm authored Feb 19, 2024
2 parents 8d6f5dc + e2768e7 commit 06061c2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
25 changes: 19 additions & 6 deletions src/renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,33 @@ use crate::tools::Drawable;
use crate::tools::Tool;

pub struct Renderer {
original_image: Pixbuf,
original_image: ImageSurface,
crop_tool: Rc<RefCell<CropTool>>,
drawables: Vec<Box<dyn Drawable>>,
redo_stack: Vec<Box<dyn Drawable>>,
}

impl Renderer {
pub fn new(original_image: Pixbuf, crop_tool: Rc<RefCell<CropTool>>) -> Self {
Self {
original_image,
pub fn new(original_image: Pixbuf, crop_tool: Rc<RefCell<CropTool>>) -> Result<Self> {
let original_image_surface = ImageSurface::create(
Format::ARgb32,
original_image.width(),
original_image.height(),
)?;

// render background image
let cx: Context = Context::new(original_image_surface.clone())?;
cx.set_operator(Operator::Over);

cx.set_source_pixbuf(&original_image, 0.0, 0.0);
cx.paint()?;

Ok(Self {
original_image: original_image_surface,
drawables: Vec::new(),
redo_stack: Vec::new(),
crop_tool,
}
})
}

pub fn render_full_size(
Expand All @@ -45,7 +58,7 @@ impl Renderer {
cx.set_operator(Operator::Over);

// render background image
cx.set_source_pixbuf(&self.original_image, 0.0, 0.0);
cx.set_source_surface(&self.original_image, 0.0, 0.0)?;
cx.paint()?;

// render comitted drawables
Expand Down
2 changes: 1 addition & 1 deletion src/sketch_board.rs
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ impl Component for SketchBoard {
handler: DrawHandler::new(),
active_tool: tools.get(&config.initial_tool()),
style: Style::default(),
renderer: Renderer::new(image, tools.get_crop_tool()),
renderer: Renderer::new(image, tools.get_crop_tool()).expect("Can't create renderer"),
scale_factor: 1.0,
tools,
};
Expand Down

0 comments on commit 06061c2

Please sign in to comment.