mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-16 23:08:05 +08:00
Improve rendering efficiency and add caching (#95)
Fixes #84 *Reduce heap allocations * Add caching for rendering svgs * Deduplicate UpdateCanvas Responses
This commit is contained in:
committed by
Keavon Chambers
parent
457c465342
commit
fc10575dfa
@@ -33,6 +33,7 @@ pub enum Event {
|
||||
#[repr(C)]
|
||||
pub enum ToolResponse {
|
||||
SetActiveTool { tool_name: String },
|
||||
UpdateCanvas { document: String },
|
||||
}
|
||||
|
||||
impl fmt::Display for ToolResponse {
|
||||
@@ -41,6 +42,7 @@ impl fmt::Display for ToolResponse {
|
||||
|
||||
let name = match_variant_name!(match (self) {
|
||||
SetActiveTool,
|
||||
UpdateCanvas,
|
||||
});
|
||||
|
||||
formatter.write_str(name)
|
||||
|
||||
@@ -107,13 +107,29 @@ impl Dispatcher {
|
||||
}
|
||||
}
|
||||
|
||||
let (tool_responses, operations) = editor_state
|
||||
let (mut tool_responses, operations) = editor_state
|
||||
.tool_state
|
||||
.tool_data
|
||||
.active_tool()?
|
||||
.handle_input(event, &editor_state.document, &editor_state.tool_state.document_tool_data);
|
||||
|
||||
let document_responses = self.dispatch_operations(&mut editor_state.document, operations);
|
||||
let mut document_responses = self.dispatch_operations(&mut editor_state.document, operations);
|
||||
//let changes = document_responses.drain_filter(|x| x == DocumentResponse::DocumentChanged);
|
||||
let mut canvas_dirty = false;
|
||||
let mut i = 0;
|
||||
while i < document_responses.len() {
|
||||
if matches!(document_responses[i], DocumentResponse::DocumentChanged) {
|
||||
canvas_dirty = true;
|
||||
document_responses.remove(i);
|
||||
} else {
|
||||
i += 1;
|
||||
}
|
||||
}
|
||||
if canvas_dirty {
|
||||
tool_responses.push(ToolResponse::UpdateCanvas {
|
||||
document: editor_state.document.render_root(),
|
||||
})
|
||||
}
|
||||
self.dispatch_responses(tool_responses);
|
||||
self.dispatch_responses(document_responses);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user