diff --git a/.gitignore b/.gitignore index 4c4071f5b..79f56b260 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,5 @@ Cargo.lock .idea snapshot_before.png snapshot_after.png -documents_example \ No newline at end of file +documents_example +bacon.toml diff --git a/crates/testing/src/test_handler.rs b/crates/testing/src/test_handler.rs index 3b4876622..e778182a6 100644 --- a/crates/testing/src/test_handler.rs +++ b/crates/testing/src/test_handler.rs @@ -15,6 +15,7 @@ use freya_core::prelude::{ use freya_engine::prelude::{ raster_n32_premul, Color, + Data, EncodedImageFormat, FontCollection, FontMgr, @@ -299,8 +300,8 @@ impl TestingHandler { self.utils.sdom() } - /// Render the app into a canvas and save it into a file. - pub fn save_snapshot(&mut self, snapshot_path: impl Into) { + /// Render the app into a canvas and make a snapshot of it. + pub fn create_snapshot(&mut self) -> Data { let fdom = self.utils.sdom.get(); let (width, height) = self.config.size.to_i32().to_tuple(); @@ -341,16 +342,19 @@ impl TestingHandler { // Capture snapshot let image = surface.image_snapshot(); let mut context = surface.direct_context(); - let snapshot_data = image + image .encode(context.as_mut(), EncodedImageFormat::PNG, None) - .expect("Failed to encode the snapshot."); + .expect("Failed to encode the snapshot.") + } - // Save snapshot + /// Render the app into a canvas and save it into a file. + pub fn save_snapshot(&mut self, snapshot_path: impl Into) { let mut snapshot_file = File::create(snapshot_path.into()).expect("Failed to create the snapshot file."); - let snapshot_bytes = snapshot_data.as_bytes(); + let snapshot_data = self.create_snapshot(); + snapshot_file - .write_all(snapshot_bytes) + .write_all(&snapshot_data) .expect("Failed to save the snapshot file."); }