Skip to content

Commit 401f2f6

Browse files
committed
store page layers as Drawables
- each layer's Drawable is wrapped in a Picture, keeping the Page api constant, but Picture clones now just duplicate the reference to the Drawable, not the entire contents of the draw-list - addresses #261
1 parent b9a9632 commit 401f2f6

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/context/page.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,18 @@ impl PageRecorder{
113113

114114
pub fn get_page(&mut self) -> Page{
115115
if self.changed {
116-
// stop and restart the recorder while adding its content as a new layer
117-
if let Some(palimpsest) = self.current.finish_recording_as_picture(Some(&self.bounds)) {
118-
self.layers.push(palimpsest);
119-
}
116+
// store layer as a drawable (so copies are deduplicated) wrapped in a picture (so it can be sent to other threads)
117+
self.current
118+
.finish_recording_as_drawable()
119+
.and_then(|mut drawable|{
120+
let mut wrapper = PictureRecorder::new();
121+
wrapper.begin_recording(self.bounds, None).draw_drawable(&mut drawable, None);
122+
wrapper.finish_recording_as_picture(None)
123+
}).map(|pict|
124+
self.layers.push(pict)
125+
);
126+
127+
// resume recording
120128
self.current.begin_recording(self.bounds, None);
121129
self.changed = false;
122130
self.restore();

0 commit comments

Comments
 (0)