-
Notifications
You must be signed in to change notification settings - Fork 604
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a test that verifies that grab_window() returns something when using
the Skia OpenGL or FemtoVG renderer
- Loading branch information
Showing
4 changed files
with
114 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |