Skip to content

examples: Simplify Skia example#70

Merged
Velli20 merged 1 commit intomainfrom
skia-example
Feb 4, 2026
Merged

examples: Simplify Skia example#70
Velli20 merged 1 commit intomainfrom
skia-example

Conversation

@Velli20
Copy link
Owner

@Velli20 Velli20 commented Feb 4, 2026

No description provided.

Copilot AI review requested due to automatic review settings February 4, 2026 19:39
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors the Skia example to use proper error handling with thiserror, removes unnecessary complexity, and modernizes the code structure. The example is now more maintainable and easier to understand.

Changes:

  • Introduced a comprehensive AppError enum using thiserror for proper error handling
  • Converted main() to return Result<(), AppError> instead of panicking
  • Simplified the code structure by removing unnecessary abstractions (AppSettings, frame rate control, trait-based rendering)
  • Refactored GL context creation into a dedicated function with proper documentation
  • Changed event loop to use ControlFlow::Wait for better efficiency (event-driven instead of time-based)

Reviewed changes

Copilot reviewed 2 out of 3 changed files in this pull request and generated 3 comments.

File Description
examples/skia.rs Complete refactoring with proper error handling, simplified structure, and cleaner event handling
examples/Cargo.toml Added thiserror = "2" dependency for error handling
Cargo.lock Updated lock file with thiserror 2.0.12 dependency

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +154 to +170
match self
.gpu_state
.create_target_surface(size.width as i32, size.height as i32)
{
Ok(s) => self.surface = s,
Err(e) => {
self.render_error = Some(e.into());
event_loop.exit();
return;
}
}
if let (Some(w), Some(h)) =
(NonZeroU32::new(size.width), NonZeroU32::new(size.height))
{
self.gl_surface.resize(&self.gl_context, w, h);
}
self.window.request_redraw();
Copy link

Copilot AI Feb 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The GL surface resize is only performed when both width and height are non-zero, but the Skia target surface is always recreated regardless of dimensions. This inconsistency could lead to a mismatch between the GL surface and Skia surface dimensions when the window is minimized (resulting in zero dimensions). Consider either skipping both operations when dimensions are zero, or handling the zero-dimension case consistently for both surfaces.

Suggested change
match self
.gpu_state
.create_target_surface(size.width as i32, size.height as i32)
{
Ok(s) => self.surface = s,
Err(e) => {
self.render_error = Some(e.into());
event_loop.exit();
return;
}
}
if let (Some(w), Some(h)) =
(NonZeroU32::new(size.width), NonZeroU32::new(size.height))
{
self.gl_surface.resize(&self.gl_context, w, h);
}
self.window.request_redraw();
if let (Some(w), Some(h)) =
(NonZeroU32::new(size.width), NonZeroU32::new(size.height))
{
match self
.gpu_state
.create_target_surface(w.get() as i32, h.get() as i32)
{
Ok(s) => self.surface = s,
Err(e) => {
self.render_error = Some(e.into());
event_loop.exit();
return;
}
}
self.gl_surface.resize(&self.gl_context, w, h);
self.window.request_redraw();
}

Copilot uses AI. Check for mistakes.
examples/skia.rs Outdated
Comment on lines 274 to 276
/// # Safety
///
/// This function uses unsafe internally because OpenGL context creation and
Copy link

Copilot AI Feb 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The # Safety section in the documentation is typically reserved for unsafe functions to document their safety requirements for callers. Since create_gl_context_and_surface is not an unsafe function, this section might confuse readers. Consider rephrasing this as a regular documentation comment explaining that the function encapsulates unsafe OpenGL operations, or using a different heading like # Implementation Notes.

Suggested change
/// # Safety
///
/// This function uses unsafe internally because OpenGL context creation and
/// # Implementation Notes
///
/// This function uses `unsafe` internally because OpenGL context creation and

Copilot uses AI. Check for mistakes.
Comment on lines +220 to +222
let dominated = b.supports_transparency().unwrap_or(false)
&& !a.supports_transparency().unwrap_or(false);
if dominated || b.num_samples() < a.num_samples() {
Copy link

Copilot AI Feb 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable name dominated is unclear in this context. The logic is selecting a GL config where b has transparency and a doesn't, which could be more clearly named as b_has_better_transparency or prefer_b_transparency to make the selection criteria more obvious.

Suggested change
let dominated = b.supports_transparency().unwrap_or(false)
&& !a.supports_transparency().unwrap_or(false);
if dominated || b.num_samples() < a.num_samples() {
let b_has_preferred_transparency = b.supports_transparency().unwrap_or(false)
&& !a.supports_transparency().unwrap_or(false);
if b_has_preferred_transparency || b.num_samples() < a.num_samples() {

Copilot uses AI. Check for mistakes.
@Velli20 Velli20 merged commit 2ee1149 into main Feb 4, 2026
2 checks passed
@Velli20 Velli20 deleted the skia-example branch February 4, 2026 19:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant