Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decouple glutin from winit #1435

Merged
merged 8 commits into from
Sep 3, 2022
Merged

Conversation

kchibisov
Copy link
Member

Thit commit removes direct dependency on the winit and
using raw_window_handle crate instead

--

This is a draft for now given that macOs and Windows support is missing(and also ios, but I don't have a way to add it anyway). The examples are also lacking. However the public Api are unlikely to change (besides adding more config options).

The feedback is welcome!

glutin_wgl_sys/src/lib.rs Outdated Show resolved Hide resolved
@madsmtm
Copy link
Member

madsmtm commented Aug 12, 2022

I could probably do the macOS and iOS impls

@kchibisov kchibisov mentioned this pull request Aug 12, 2022
4 tasks
@kchibisov
Copy link
Member Author

I'm not quite sure how I keep the Api, but ios impl would be very welcome, since I don't really mind doing macOS one.

@madsmtm
Copy link
Member

madsmtm commented Aug 13, 2022

I'm not quite sure how I keep the Api, but ios impl would be very welcome, since I don't really mind doing macOS one.

'aight, I think I'll wait until you have progressed further.

I have to get a newer device set up anyhow, which will take a little while. While I can (since #1441) run glutin on my old iPad, it crashes for some reason I haven't (yet) figured out

@kchibisov kchibisov force-pushed the glutin-v2 branch 3 times, most recently from 525062b to 9c01848 Compare August 18, 2022 15:26
@kchibisov
Copy link
Member Author

I've pushed one more update and kind of settled on the final Api I want to use.

The current version has stabs for macOS/Wgl with todo! to implement. Similar could be done to ios.

In general once feeling the todo! for both platforms in api/wgl and api/cgl they should just work in the current infra.

All the cfg stuff and features is already wired up. And the directory layout is unlikely to change.

@kchibisov
Copy link
Member Author

kchibisov commented Aug 19, 2022

@madsmtm added macOS support, but something maybe missing here and there. Had to adjust Api a bit for it to work but at least example should show window.

Also I have no clue how to do error handling on it. With CGL you have some CGLError, but with cocoa apis I'm not sure.

glutin/src/api/egl/display.rs Show resolved Hide resolved
glutin/src/lib_loading.rs Outdated Show resolved Hide resolved
@rib
Copy link

rib commented Aug 20, 2022

Just made a first pass through the changes here and they definitely look like a good direction from my pov, while I'm currently stuck with being able to update the egui/eframe glow backend to destroy and recreate surface state on suspend + resume on Android, considering how Glutin currently tightly couples the Context with the Window.

Intuitively this is more the kind of design I had been expecting to find with a separate Surface type and then having make_current() accept a surface.

rib added a commit to rib/egui that referenced this pull request Aug 20, 2022
Conceptually the Winit `Resumed` event signifies that the application is
ready to run and render and since
rust-windowing/winit#2331 all platforms now
consistently emit a Resumed event that can be used to initialize
graphics state for an application.

On Android in particular it's important to wait until the application
has Resumed before initializing graphics state since it won't have an
associated SurfaceView while paused.

Without this change then Android applications are likely to just show
a black screen.

This updates the Wgpu+Winit and Glow+Winit integration for eframe but
it's worth noting that the Glow integration is still not able to fully
support Android due to limitations in with Glutin's API that mean
we can't destroy and create a Window without also destroying the
GL context, and therefore the entire application.

There is a plan (and progress on) to improve the Glutin API here:
rust-windowing/glutin#1435 and with that change
it should be an incremental change to enable Android support with Glow
later.

In the mean time the Glow changes keep the implementation consistent
with the wgpu integration and it should now at least be possible to
start an Android application - even though it won't be able to suspend
correctly.
rib added a commit to rib/egui that referenced this pull request Aug 21, 2022
Conceptually the Winit `Resumed` event signifies that the application is
ready to run and render and since
rust-windowing/winit#2331 all platforms now
consistently emit a Resumed event that can be used to initialize
graphics state for an application.

On Android in particular it's important to wait until the application
has Resumed before initializing graphics state since it won't have an
associated SurfaceView while paused.

Without this change then Android applications are likely to just show
a black screen.

This updates the Wgpu+Winit and Glow+Winit integration for eframe but
it's worth noting that the Glow integration is still not able to fully
support Android due to limitations in with Glutin's API that mean
we can't destroy and create a Window without also destroying the
GL context, and therefore the entire application.

There is a plan (and progress on) to improve the Glutin API here:
rust-windowing/glutin#1435 and with that change
it should be an incremental change to enable Android support with Glow
later.

In the mean time the Glow changes keep the implementation consistent
with the wgpu integration and it should now at least be possible to
start an Android application - even though it won't be able to suspend
correctly.
rib added a commit to rib/egui that referenced this pull request Aug 21, 2022
Conceptually the Winit `Resumed` event signifies that the application is
ready to run and render and since
rust-windowing/winit#2331 all platforms now
consistently emit a Resumed event that can be used to initialize
graphics state for an application.

On Android in particular it's important to wait until the application
has Resumed before initializing graphics state since it won't have an
associated SurfaceView while paused.

Without this change then Android applications are likely to just show
a black screen.

This updates the Wgpu+Winit and Glow+Winit integration for eframe but
it's worth noting that the Glow integration is still not able to fully
support Android due to limitations in with Glutin's API that mean
we can't destroy and create a Window without also destroying the
GL context, and therefore the entire application.

There is a plan (and progress on) to improve the Glutin API here:
rust-windowing/glutin#1435 and with that change
it should be an incremental change to enable Android support with Glow
later.

In the mean time the Glow changes keep the implementation consistent
with the wgpu integration and it should now at least be possible to
start an Android application - even though it won't be able to suspend
correctly.
glutin/src/api/egl/display.rs Show resolved Hide resolved
glutin/src/api/egl/display.rs Show resolved Hide resolved
glutin/src/api/egl/display.rs Show resolved Hide resolved
rib added a commit to rib/egui that referenced this pull request Aug 21, 2022
Conceptually the Winit `Resumed` event signifies that the application is
ready to run and render and since
rust-windowing/winit#2331 all platforms now
consistently emit a Resumed event that can be used to initialize
graphics state for an application.

On Android in particular it's important to wait until the application
has Resumed before initializing graphics state since it won't have an
associated SurfaceView while paused.

Without this change then Android applications are likely to just show
a black screen.

This updates the Wgpu+Winit and Glow+Winit integration for eframe but
it's worth noting that the Glow integration is still not able to fully
support Android due to limitations in with Glutin's API that mean
we can't destroy and create a Window without also destroying the
GL context, and therefore the entire application.

There is a plan (and progress on) to improve the Glutin API here:
rust-windowing/glutin#1435 and with that change
it should be an incremental change to enable Android support with Glow
later.

In the mean time the Glow changes keep the implementation consistent
with the wgpu integration and it should now at least be possible to
start an Android application - even though it won't be able to suspend
correctly.
rib added a commit to rib/egui that referenced this pull request Aug 21, 2022
Conceptually the Winit `Resumed` event signifies that the application is
ready to run and render and since
rust-windowing/winit#2331 all platforms now
consistently emit a Resumed event that can be used to initialize
graphics state for an application.

On Android in particular it's important to wait until the application
has Resumed before initializing graphics state since it won't have an
associated SurfaceView while paused.

Without this change then Android applications are likely to just show
a black screen.

This updates the Wgpu+Winit and Glow+Winit integration for eframe but
it's worth noting that the Glow integration is still not able to fully
support suspend and resume on Android due to limitations with Glutin's
API that mean we can't destroy and create a Window without also
destroying the GL context, and therefore (practically) the entire
application.

There is a plan (and progress on) to improve the Glutin API here:
rust-windowing/glutin#1435 and with that change
it should be an incremental change to enable Android suspend/resume
support with Glow later.

In the mean time the Glow changes keep the implementation consistent
with the wgpu integration and it should now at least be possible to
start an Android application - even though it won't be able to suspend
correctly.
rib added a commit to rib/egui that referenced this pull request Aug 21, 2022
Conceptually the Winit `Resumed` event signifies that the application is
ready to run and render and since
rust-windowing/winit#2331 all platforms now
consistently emit a Resumed event that can be used to initialize
graphics state for an application.

On Android in particular it's important to wait until the application
has Resumed before initializing graphics state since it won't have an
associated SurfaceView while paused.

Without this change then Android applications are likely to just show
a black screen.

This updates the Wgpu+Winit and Glow+Winit integration for eframe but
it's worth noting that the Glow integration is still not able to fully
support suspend and resume on Android due to limitations with Glutin's
API that mean we can't destroy and create a Window without also
destroying the GL context, and therefore (practically) the entire
application.

There is a plan (and progress on) to improve the Glutin API here:
rust-windowing/glutin#1435 and with that change
it should be an incremental change to enable Android suspend/resume
support with Glow later.

In the mean time the Glow changes keep the implementation consistent
with the wgpu integration and it should now at least be possible to
start an Android application - even though it won't be able to suspend
correctly.
rib added a commit to rib/egui that referenced this pull request Aug 21, 2022
Conceptually the Winit `Resumed` event signifies that the application is
ready to run and render and since
rust-windowing/winit#2331 all platforms now
consistently emit a Resumed event that can be used to initialize
graphics state for an application.

On Android in particular it's important to wait until the application
has Resumed before initializing graphics state since it won't have an
associated SurfaceView while paused.

Without this change then Android applications are likely to just show
a black screen.

This updates the Wgpu+Winit and Glow+Winit integration for eframe but
it's worth noting that the Glow integration is still not able to fully
support suspend and resume on Android due to limitations with Glutin's
API that mean we can't destroy and create a Window without also
destroying the GL context, and therefore (practically) the entire
application.

There is a plan (and progress on) to improve the Glutin API here:
rust-windowing/glutin#1435 and with that change
it should be an incremental change to enable Android suspend/resume
support with Glow later.

In the mean time the Glow changes keep the implementation consistent
with the wgpu integration and it should now at least be possible to
start an Android application - even though it won't be able to suspend
correctly.
rib added a commit to rib/egui that referenced this pull request Aug 21, 2022
Conceptually the Winit `Resumed` event signifies that the application is
ready to run and render and since
rust-windowing/winit#2331 all platforms now
consistently emit a Resumed event that can be used to initialize
graphics state for an application.

On Android in particular it's important to wait until the application
has Resumed before initializing graphics state since it won't have an
associated SurfaceView while paused.

Without this change then Android applications are likely to just show
a black screen.

This updates the Wgpu+Winit and Glow+Winit integration for eframe but
it's worth noting that the Glow integration is still not able to fully
support suspend and resume on Android due to limitations with Glutin's
API that mean we can't destroy and create a Window without also
destroying the GL context, and therefore (practically) the entire
application.

There is a plan (and progress on) to improve the Glutin API here:
rust-windowing/glutin#1435 and with that change
it should be an incremental change to enable Android suspend/resume
support with Glow later.

In the mean time the Glow changes keep the implementation consistent
with the wgpu integration and it should now at least be possible to
start an Android application - even though it won't be able to suspend
correctly.

Fixes emilk#1951
rib added a commit to rib/egui that referenced this pull request Aug 21, 2022
Conceptually the Winit `Resumed` event signifies that the application is
ready to run and render and since
rust-windowing/winit#2331 all platforms now
consistently emit a Resumed event that can be used to initialize
graphics state for an application.

On Android in particular it's important to wait until the application
has Resumed before initializing graphics state since it won't have an
associated SurfaceView while paused.

Without this change then Android applications are likely to just show
a black screen.

This updates the Wgpu+Winit and Glow+Winit integration for eframe but
it's worth noting that the Glow integration is still not able to fully
support suspend and resume on Android due to limitations with Glutin's
API that mean we can't destroy and create a Window without also
destroying the GL context, and therefore (practically) the entire
application.

There is a plan (and progress on) to improve the Glutin API here:
rust-windowing/glutin#1435 and with that change
it should be an incremental change to enable Android suspend/resume
support with Glow later.

In the mean time the Glow changes keep the implementation consistent
with the wgpu integration and it should now at least be possible to
start an Android application - even though it won't be able to suspend
correctly.

Fixes emilk#1951
rib added a commit to rib/egui that referenced this pull request Aug 21, 2022
Conceptually the Winit `Resumed` event signifies that the application is
ready to run and render and since
rust-windowing/winit#2331 all platforms now
consistently emit a Resumed event that can be used to initialize
graphics state for an application.

On Android in particular it's important to wait until the application
has Resumed before initializing graphics state since it won't have an
associated SurfaceView while paused.

Without this change then Android applications are likely to just show
a black screen.

This updates the Wgpu+Winit and Glow+Winit integration for eframe but
it's worth noting that the Glow integration is still not able to fully
support suspend and resume on Android due to limitations with Glutin's
API that mean we can't destroy and create a Window without also
destroying the GL context, and therefore (practically) the entire
application.

There is a plan (and progress on) to improve the Glutin API here:
rust-windowing/glutin#1435 and with that change
it should be an incremental change to enable Android suspend/resume
support with Glow later.

In the mean time the Glow changes keep the implementation consistent
with the wgpu integration and it should now at least be possible to
start an Android application - even though it won't be able to suspend
correctly.

Fixes emilk#1951
glutin/src/context.rs Outdated Show resolved Hide resolved
///
/// This must be used when building X11 window, so it'll be compatible with the underlying Api.
pub struct X11VisualInfo {
display: *mut Display,
Copy link
Contributor

Choose a reason for hiding this comment

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

How do we assert the display is valid for the lifetime of the visual info?

Copy link
Member Author

Choose a reason for hiding this comment

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

That's the problem in general with RawDisplayHandle, since it could in theory be dropped. We could open inner connection and has our own XDisplay. I'm actually not entirely sure how to handle that other than open another connection?

glutin/src/surface.rs Outdated Show resolved Hide resolved
glutin/src/surface.rs Show resolved Hide resolved
glutin/src/surface.rs Outdated Show resolved Hide resolved
This was referenced Sep 3, 2022
@madsmtm madsmtm mentioned this pull request Sep 3, 2022
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

7 participants