Skip to content

Commit

Permalink
Return Unimplemented error on other platforms
Browse files Browse the repository at this point in the history
Add line to docs about unsupported platforms

Test fixes
  • Loading branch information
notgull committed May 19, 2023
1 parent d5ca690 commit c92a99c
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/cg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ impl CGImpl {

/// Fetch the buffer from the window.
pub fn fetch(&mut self) -> Result<Vec<u32>, SoftBufferError> {
todo!()
Err(SoftBufferError::Unimplemented)
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ pub enum SoftBufferError {

#[error("Platform error")]
PlatformError(Option<String>, Option<Box<dyn Error>>),

#[error("This function is unimplemented on this platform")]
Unimplemented,
}

/// Convenient wrapper to cast errors into SoftBufferError.
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@ impl Surface {
/// ## Platform Dependent Behavior
///
/// - On X11, the window must be visible.
/// - On macOS, Redox and Wayland, this function is unimplemented.
pub fn fetch(&mut self) -> Result<Vec<u32>, SoftBufferError> {
self.surface_impl.fetch()
}
Expand Down
2 changes: 1 addition & 1 deletion src/orbital.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ impl OrbitalImpl {

/// Fetch the buffer from the window.
pub fn fetch(&mut self) -> Result<Vec<u32>, SoftBufferError> {
todo!()
Err(SoftBufferError::Unimplemented)
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/wayland/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ impl WaylandImpl {

/// Fetch the buffer from the window.
pub fn fetch(&mut self) -> Result<Vec<u32>, SoftBufferError> {
todo!()
Err(SoftBufferError::Unimplemented)
}
}

Expand Down
6 changes: 5 additions & 1 deletion tests/present_and_fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ fn all_red(elwt: &EventLoopWindowTarget<()>) {
}

// winit does not wait for the window to be mapped... sigh
#[cfg(not(target_arch = "wasm32"))]
std::thread::sleep(std::time::Duration::from_millis(1));

let context = unsafe { Context::new(elwt) }.unwrap();
Expand All @@ -43,7 +44,10 @@ fn all_red(elwt: &EventLoopWindowTarget<()>) {
buffer.present().unwrap();

// Check that all pixels are red.
let screen_contents = surface.fetch().unwrap();
let screen_contents = match surface.fetch() {
Err(softbuffer::SoftBufferError::Unimplemented) => return,
cont => cont.unwrap(),
};
for pixel in screen_contents.iter() {
assert_eq!(*pixel, 0xFF000000);
}
Expand Down

0 comments on commit c92a99c

Please sign in to comment.