Skip to content

Commit 7d12a5b

Browse files
committed
WIP winit git
I wanted to see how the changes in Winit git would work here. So of course this depends on that being released. Depends on #1514. It doesn't seem to pose a particular challenge beyond that. Updating compositors for that change will be needed to test this... Anvil changes broken in rebase; needs update...
1 parent 9af960d commit 7d12a5b

File tree

4 files changed

+179
-133
lines changed

4 files changed

+179
-133
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ wayland-protocols-misc = { version = "0.3.1", features = ["server"], optional =
6262
wayland-server = { version = "0.31.0", optional = true }
6363
wayland-sys = { version = "0.31", optional = true }
6464
wayland-backend = { version = "0.3.5", optional = true }
65-
winit = { version = "0.30.0", default-features = false, features = ["wayland", "wayland-dlopen", "x11", "rwh_06"], optional = true }
65+
winit = { git = "https://github.com/rust-windowing/winit", default-features = false, features = ["wayland", "wayland-dlopen", "x11"], optional = true }
6666
x11rb = { version = "0.13.0", optional = true }
6767
xkbcommon = { version = "0.8.0", features = ["wayland"]}
6868
encoding_rs = { version = "0.8.33", optional = true }

anvil/src/winit.rs

+91-81
Original file line numberDiff line numberDiff line change
@@ -99,93 +99,13 @@ pub fn run_winit() {
9999
let mut display_handle = display.handle();
100100

101101
#[cfg_attr(not(feature = "egl"), allow(unused_mut))]
102-
let (mut backend, mut winit) = match winit::init::<GlesRenderer>() {
102+
let mut winit = match winit::init::<GlesRenderer>() {
103103
Ok(ret) => ret,
104104
Err(err) => {
105105
error!("Failed to initialize Winit backend: {}", err);
106106
return;
107107
}
108108
};
109-
let size = backend.window_size();
110-
111-
let mode = Mode {
112-
size,
113-
refresh: 60_000,
114-
};
115-
let output = Output::new(
116-
OUTPUT_NAME.to_string(),
117-
PhysicalProperties {
118-
size: (0, 0).into(),
119-
subpixel: Subpixel::Unknown,
120-
make: "Smithay".into(),
121-
model: "Winit".into(),
122-
},
123-
);
124-
let _global = output.create_global::<AnvilState<WinitData>>(&display.handle());
125-
output.change_current_state(Some(mode), Some(Transform::Flipped180), None, Some((0, 0).into()));
126-
output.set_preferred(mode);
127-
128-
#[cfg(feature = "debug")]
129-
#[allow(deprecated)]
130-
let fps_image =
131-
image::io::Reader::with_format(std::io::Cursor::new(FPS_NUMBERS_PNG), image::ImageFormat::Png)
132-
.decode()
133-
.unwrap();
134-
#[cfg(feature = "debug")]
135-
let fps_texture = backend
136-
.renderer()
137-
.import_memory(
138-
&fps_image.to_rgba8(),
139-
Fourcc::Abgr8888,
140-
(fps_image.width() as i32, fps_image.height() as i32).into(),
141-
false,
142-
)
143-
.expect("Unable to upload FPS texture");
144-
#[cfg(feature = "debug")]
145-
let mut fps_element = FpsElement::new(fps_texture);
146-
147-
let render_node = EGLDevice::device_for_display(backend.renderer().egl_context().display())
148-
.and_then(|device| device.try_get_render_node());
149-
150-
let dmabuf_default_feedback = match render_node {
151-
Ok(Some(node)) => {
152-
let dmabuf_formats = backend.renderer().dmabuf_formats();
153-
let dmabuf_default_feedback = DmabufFeedbackBuilder::new(node.dev_id(), dmabuf_formats)
154-
.build()
155-
.unwrap();
156-
Some(dmabuf_default_feedback)
157-
}
158-
Ok(None) => {
159-
warn!("failed to query render node, dmabuf will use v3");
160-
None
161-
}
162-
Err(err) => {
163-
warn!(?err, "failed to egl device for display, dmabuf will use v3");
164-
None
165-
}
166-
};
167-
168-
// if we failed to build dmabuf feedback we fall back to dmabuf v3
169-
// Note: egl on Mesa requires either v4 or wl_drm (initialized with bind_wl_display)
170-
let dmabuf_state = if let Some(default_feedback) = dmabuf_default_feedback {
171-
let mut dmabuf_state = DmabufState::new();
172-
let dmabuf_global = dmabuf_state.create_global_with_default_feedback::<AnvilState<WinitData>>(
173-
&display.handle(),
174-
&default_feedback,
175-
);
176-
(dmabuf_state, dmabuf_global, Some(default_feedback))
177-
} else {
178-
let dmabuf_formats = backend.renderer().dmabuf_formats();
179-
let mut dmabuf_state = DmabufState::new();
180-
let dmabuf_global =
181-
dmabuf_state.create_global::<AnvilState<WinitData>>(&display.handle(), dmabuf_formats);
182-
(dmabuf_state, dmabuf_global, None)
183-
};
184-
185-
#[cfg(feature = "egl")]
186-
if backend.renderer().bind_wl_display(&display.handle()).is_ok() {
187-
info!("EGL hardware-acceleration enabled");
188-
};
189109

190110
let data = {
191111
let damage_tracker = OutputDamageTracker::from_output(&output);
@@ -214,6 +134,96 @@ pub fn run_winit() {
214134

215135
while state.running.load(Ordering::SeqCst) {
216136
let status = winit.dispatch_new_events(|event| match event {
137+
WinitEvent::WindowCreated(backend) => {
138+
let size = backend.window_size();
139+
140+
let mode = Mode {
141+
size,
142+
refresh: 60_000,
143+
};
144+
let output = Output::new(
145+
OUTPUT_NAME.to_string(),
146+
PhysicalProperties {
147+
size: (0, 0).into(),
148+
subpixel: Subpixel::Unknown,
149+
make: "Smithay".into(),
150+
model: "Winit".into(),
151+
},
152+
);
153+
let _global = output.create_global::<AnvilState<WinitData>>(&display.handle());
154+
output.change_current_state(
155+
Some(mode),
156+
Some(Transform::Flipped180),
157+
None,
158+
Some((0, 0).into()),
159+
);
160+
output.set_preferred(mode);
161+
162+
#[cfg(feature = "debug")]
163+
let fps_image = image::ImageReader::with_format(
164+
std::io::Cursor::new(FPS_NUMBERS_PNG),
165+
image::ImageFormat::Png,
166+
)
167+
.decode()
168+
.unwrap();
169+
#[cfg(feature = "debug")]
170+
let fps_texture = backend
171+
.renderer()
172+
.import_memory(
173+
&fps_image.to_rgba8(),
174+
Fourcc::Abgr8888,
175+
(fps_image.width() as i32, fps_image.height() as i32).into(),
176+
false,
177+
)
178+
.expect("Unable to upload FPS texture");
179+
#[cfg(feature = "debug")]
180+
let mut fps_element = FpsElement::new(fps_texture);
181+
182+
let render_node = EGLDevice::device_for_display(backend.renderer().egl_context().display())
183+
.and_then(|device| device.try_get_render_node());
184+
185+
let dmabuf_default_feedback = match render_node {
186+
Ok(Some(node)) => {
187+
let dmabuf_formats = backend.renderer().dmabuf_formats();
188+
let dmabuf_default_feedback =
189+
DmabufFeedbackBuilder::new(node.dev_id(), dmabuf_formats)
190+
.build()
191+
.unwrap();
192+
Some(dmabuf_default_feedback)
193+
}
194+
Ok(None) => {
195+
warn!("failed to query render node, dmabuf will use v3");
196+
None
197+
}
198+
Err(err) => {
199+
warn!(?err, "failed to egl device for display, dmabuf will use v3");
200+
None
201+
}
202+
};
203+
204+
// if we failed to build dmabuf feedback we fall back to dmabuf v3
205+
// Note: egl on Mesa requires either v4 or wl_drm (initialized with bind_wl_display)
206+
let dmabuf_state = if let Some(default_feedback) = dmabuf_default_feedback {
207+
let mut dmabuf_state = DmabufState::new();
208+
let dmabuf_global = dmabuf_state
209+
.create_global_with_default_feedback::<AnvilState<WinitData>>(
210+
&display.handle(),
211+
&default_feedback,
212+
);
213+
(dmabuf_state, dmabuf_global, Some(default_feedback))
214+
} else {
215+
let dmabuf_formats = backend.renderer().dmabuf_formats();
216+
let mut dmabuf_state = DmabufState::new();
217+
let dmabuf_global = dmabuf_state
218+
.create_global::<AnvilState<WinitData>>(&display.handle(), dmabuf_formats);
219+
(dmabuf_state, dmabuf_global, None)
220+
};
221+
222+
#[cfg(feature = "egl")]
223+
if backend.renderer().bind_wl_display(&display.handle()).is_ok() {
224+
info!("EGL hardware-acceleration enabled");
225+
};
226+
}
217227
WinitEvent::Resized { size, .. } => {
218228
// We only have one output
219229
let output = state.space.outputs().next().unwrap().clone();

src/backend/egl/native.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ impl<A: AsFd + Send + 'static> EGLNativeDisplay for GbmDevice<A> {
160160
}
161161

162162
#[cfg(feature = "backend_winit")]
163-
impl EGLNativeDisplay for Arc<WinitWindow> {
163+
impl EGLNativeDisplay for Arc<dyn WinitWindow> {
164164
fn supported_platforms(&self) -> Vec<EGLPlatform<'_>> {
165165
use winit::raw_window_handle::{self, HasDisplayHandle};
166166

0 commit comments

Comments
 (0)