Lokathor/beryllium

Re-implement raw-window-handle?

Closed this issue · 7 comments

Since the rewrite, raw-window-handle is no longer supported.

oh yeah, this would be a good idea.

Alright, so in Lokathor/fermium@7cff0fd#diff-734ab7743dd3366691ab07617b15575e5743e0ee0987b7b9d8e7a219b200d7a8 I added fermium level support for converting SDL2's info into the raw-window-handle info, and if that looks correct I'll publish an actual release of fermium with that, and then beryllium can just call the function and use that converstion.

It looks like this implementation will have the same problem as the one described in Rust-SDL2/rust-sdl2#1116 and gfx-rs/wgpu#1500

I tried to prototype how I would use this (currently testing on Windows 11) and ran into the issue that RawWindowHandle does not implement the HasRawWindowHandle trait. So I created a newtype:

struct Rwh(RawWindowHandle);

unsafe impl HasRawWindowHandle for Rwh {
    fn raw_window_handle(&self) -> RawWindowHandle {
        self.0
    }
}

What I ended up with (using just fermium) is basically this:

let mut pixels = {
    let mut width = 0;
    let mut height = 0;
    let rwh = unsafe {
        let mut window_info = SDL_SysWMinfo::default();
        assert_eq!(SDL_GetWindowWMInfo(window, &mut window_info), SDL_TRUE);
        SDL_GetWindowSize(window, &mut width, &mut height);

        Rwh(window_info.try_into().unwrap())
    };

    let surface_texture = SurfaceTexture::new(width as u32, height as u32, &rwh);
    Pixels::new(WIDTH, HEIGHT, surface_texture)?
};

All said, it works, but it's weird having to create a newtype to get the trait impl.

Is there any workaround for this until this feature is implemented again? My project remotia is relying on a rev version of beryllium, 0.3.2 and 0.3.3 still fail on my machine (I'm running Mesa drivers on AMD) and I guess 0.4.0 is an already reworked version that do not implement the raw-window-handle feature.

oh, uh, i can finish and publish the change probably later today.

given that the latest version of things probably lacks other elements too I'm not entirely sure you want to upgrade immediately anyway, but i think I can sort out the raw window handle thing pretty quick.

Alright, 0.7.6 should have raw-window-handle support under the slightly unfortunate alternate name use-raw-window-handle.

Since turning on raw-window-handle in beryllium requires that we turn it on in fermium, and since a feature can't be named the same as an optional dep, and since namespaced deps and features are nightly only, this is the universe we get.

But, again, I'd like to stress that most likely no one should actually use this crate. Even I don't particularly use this crate. It is chronically incomplete.

It is chronically incomplete.

Can confirm!