Skip to content

Commit

Permalink
Add a test that verifies that grab_window() returns something when using
Browse files Browse the repository at this point in the history
the Skia OpenGL or FemtoVG renderer
  • Loading branch information
tronical committed Jun 26, 2024
1 parent 8aad009 commit b643844
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 0 deletions.
9 changes: 9 additions & 0 deletions internal/renderers/femtovg/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,12 @@ core-text = { version = "20.1.0" }
[target.'cfg(target_arch = "wasm32")'.dependencies]
web-sys = { version = "0.3", features=["console", "WebGlContextAttributes", "CanvasRenderingContext2d", "HtmlInputElement", "HtmlCanvasElement", "Window", "Document"] }
wasm-bindgen = { version = "0.2" }

[dev-dependencies]
slint = { workspace = true, default-features = true }
i-slint-backend-winit = { workspace = true, features = ["renderer-femtovg"] }

[[test]]
name = "screenshot"
path = "tests/screenshot.rs"
harness = false
48 changes: 48 additions & 0 deletions internal/renderers/femtovg/tests/screenshot.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Copyright © SixtyFPS GmbH <[email protected]>
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0

fn main() {
slint::platform::set_platform(Box::new(
i_slint_backend_winit::Backend::new_with_renderer_by_name(Some("femtovg")).unwrap(),
))
.unwrap();

slint::slint! {
export component App inherits Window {
Text { text: "Ok"; }
}
}

let app = App::new().unwrap();
let slint_window = app.window();
let app_weak = app.as_weak();

let mut rendered_once = false;
let screenshot = std::rc::Rc::new(std::cell::RefCell::new(None));

slint_window
.set_rendering_notifier({
let screenshot = screenshot.clone();
move |state, _| match state {
slint::RenderingState::BeforeRendering => {
if rendered_once {
*screenshot.borrow_mut() = Some(app_weak.unwrap().window().grab_window());
slint::quit_event_loop().unwrap();
}
}
slint::RenderingState::AfterRendering => {
rendered_once = true;
app_weak.unwrap().window().request_redraw();
}
_ => {}
}
})
.unwrap();

app.show().unwrap();
app.run().unwrap();

let screenshot = screenshot.borrow_mut().take().unwrap().unwrap();
assert!(screenshot.width() > 0);
assert!(screenshot.height() > 0);
}
9 changes: 9 additions & 0 deletions internal/renderers/skia/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,12 @@ skia-safe = { version = "0.75.0", features = ["gl"] }

[build-dependencies]
cfg_aliases = { workspace = true }

[dev-dependencies]
slint = { workspace = true, default-features = true }
i-slint-backend-winit = { workspace = true, features = ["renderer-skia"] }

[[test]]
name = "screenshot"
path = "tests/screenshot.rs"
harness = false
48 changes: 48 additions & 0 deletions internal/renderers/skia/tests/screenshot.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Copyright © SixtyFPS GmbH <[email protected]>
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0

fn main() {
slint::platform::set_platform(Box::new(
i_slint_backend_winit::Backend::new_with_renderer_by_name(Some("skia-opengl")).unwrap(),
))
.unwrap();

slint::slint! {
export component App inherits Window {
Text { text: "Ok"; }
}
}

let app = App::new().unwrap();
let slint_window = app.window();
let app_weak = app.as_weak();

let mut rendered_once = false;
let screenshot = std::rc::Rc::new(std::cell::RefCell::new(None));

slint_window
.set_rendering_notifier({
let screenshot = screenshot.clone();
move |state, _| match state {
slint::RenderingState::BeforeRendering => {
if rendered_once {
*screenshot.borrow_mut() = Some(app_weak.unwrap().window().grab_window());
slint::quit_event_loop().unwrap();
}
}
slint::RenderingState::AfterRendering => {
rendered_once = true;
app_weak.unwrap().window().request_redraw();
}
_ => {}
}
})
.unwrap();

app.show().unwrap();
app.run().unwrap();

let screenshot = screenshot.borrow_mut().take().unwrap().unwrap();
assert!(screenshot.width() > 0);
assert!(screenshot.height() > 0);
}

0 comments on commit b643844

Please sign in to comment.