Skip to content

Commit f2f1d6e

Browse files
committed
TMP
1 parent 36c222a commit f2f1d6e

File tree

6 files changed

+1244
-5
lines changed

6 files changed

+1244
-5
lines changed

Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,19 @@ x11 = [
4040
"winit/x11",
4141
]
4242
x11-dlopen = ["tiny-xlib/dlopen", "x11rb/dl-libxcb"]
43+
f16 = ["half"]
4344

4445
[dependencies]
4546
raw_window_handle = { package = "raw-window-handle", version = "0.6", features = [
4647
"std",
4748
] }
4849
tracing = { version = "0.1.41", default-features = false }
4950

51+
# For f16 support in pixel conversions.
52+
# TODO: Use standard library's f16 once stable:
53+
# https://github.com/rust-lang/rust/issues/116909
54+
half = { version = "2.7.1", optional = true }
55+
5056
[target.'cfg(target_os = "android")'.dependencies]
5157
bytemuck = "1.12.3"
5258
ndk = "0.9.0"

src/backend_interface.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Interface implemented by backends
22
3-
use crate::{AlphaMode, InitError, Rect, SoftBufferError};
3+
use crate::{AlphaMode, InitError, PixelFormat, Rect, SoftBufferError};
44

55
use raw_window_handle::{HasDisplayHandle, HasWindowHandle};
66
use std::num::NonZeroU32;
@@ -29,12 +29,15 @@ pub(crate) trait SurfaceInterface<D: HasDisplayHandle + ?Sized, W: HasWindowHand
2929
fn alpha_mode(&self) -> AlphaMode;
3030

3131
/// Reconfigure the internal buffer(s).
32+
///
33+
/// Returns `Some(byte_stride)` if the buffer was successfully resized, or `None` if the surface does not support the given pixel format.
3234
fn configure(
3335
&mut self,
3436
width: NonZeroU32,
3537
height: NonZeroU32,
3638
alpha_mode: AlphaMode,
37-
) -> Result<(), SoftBufferError>;
39+
pixel_format: PixelFormat,
40+
) -> Result<Option<u32>, SoftBufferError>;
3841

3942
/// Get a mutable reference to the buffer.
4043
fn buffer_mut(&mut self) -> Result<Self::Buffer<'_>, SoftBufferError>;

src/backends/web.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use web_sys::{CanvasRenderingContext2d, HtmlCanvasElement};
1010
use web_sys::{OffscreenCanvas, OffscreenCanvasRenderingContext2d};
1111

1212
use crate::backend_interface::*;
13+
use crate::convert::FALLBACK_FORMAT;
1314
use crate::error::{InitError, SwResultExt};
1415
use crate::{util, NoDisplayHandle, NoWindowHandle, Rect, SoftBufferError};
1516
use std::marker::PhantomData;
@@ -231,6 +232,8 @@ impl SurfaceExtWeb for crate::Surface<NoDisplayHandle, NoWindowHandle> {
231232
let imple = crate::SurfaceDispatch::Web(WebImpl::from_canvas(canvas, NoWindowHandle(()))?);
232233

233234
Ok(Self {
235+
pixel_format: FALLBACK_FORMAT,
236+
fallback_buffer: None,
234237
surface_impl: Box::new(imple),
235238
_marker: PhantomData,
236239
})
@@ -243,6 +246,8 @@ impl SurfaceExtWeb for crate::Surface<NoDisplayHandle, NoWindowHandle> {
243246
)?);
244247

245248
Ok(Self {
249+
pixel_format: FALLBACK_FORMAT,
250+
fallback_buffer: None,
246251
surface_impl: Box::new(imple),
247252
_marker: PhantomData,
248253
})

0 commit comments

Comments
 (0)