cargo fmt

This commit is contained in:
Victoria Brekenfeld 2022-07-04 16:00:29 +02:00
parent 43062c1754
commit 39de286d51
40 changed files with 1557 additions and 1080 deletions

View file

@ -14,18 +14,14 @@ use crate::{
use anyhow::{Context, Result};
use smithay::{
backend::{
allocator::{
dmabuf::Dmabuf,
gbm::GbmDevice,
Format,
},
allocator::{dmabuf::Dmabuf, gbm::GbmDevice, Format},
drm::{DrmDevice, DrmEvent, DrmEventTime, DrmNode, GbmBufferedSurface, NodeType},
egl::{EGLContext, EGLDevice, EGLDisplay},
input::InputEvent,
libinput::{LibinputInputBackend, LibinputSessionInterface},
renderer::{
multigpu::{egl::EglGlesBackend, GpuManager},
gles2::Gles2Renderbuffer,
multigpu::{egl::EglGlesBackend, GpuManager},
Bind,
},
session::{auto::AutoSession, Session, Signal},
@ -40,8 +36,8 @@ use smithay::{
input::Libinput,
nix::{fcntl::OFlag, sys::stat::dev_t},
wayland_server::{
DisplayHandle, Resource,
protocol::{wl_output, wl_surface::WlSurface},
DisplayHandle, Resource,
},
},
utils::signaling::{Linkable, SignalToken, Signaler},
@ -99,7 +95,11 @@ pub struct Surface {
fps: Fps,
}
pub fn init_backend(dh: &DisplayHandle, event_loop: &mut EventLoop<'static, Data>, state: &mut State) -> Result<()> {
pub fn init_backend(
dh: &DisplayHandle,
event_loop: &mut EventLoop<'static, Data>,
state: &mut State,
) -> Result<()> {
let (session, notifier) = AutoSession::new(None).context("Failed to acquire session")?;
let signaler = notifier.signaler();
@ -118,14 +118,20 @@ pub fn init_backend(dh: &DisplayHandle, event_loop: &mut EventLoop<'static, Data
if let &mut InputEvent::DeviceAdded { ref mut device } = &mut event {
data.state.common.config.read_device(device);
}
data.state.process_input_event(&data.display.handle(), event);
data.state
.process_input_event(&data.display.handle(), event);
for output in data.state.common.shell.outputs() {
if let Err(err) = data.state
if let Err(err) = data
.state
.backend
.kms()
.schedule_render(&data.state.common.event_loop_handle, output)
{
slog_scope::crit!("Error scheduling event loop for output {}: {:?}", output.name(), err);
slog_scope::crit!(
"Error scheduling event loop for output {}: {:?}",
output.name(),
err
);
}
}
})
@ -167,13 +173,16 @@ pub fn init_backend(dh: &DisplayHandle, event_loop: &mut EventLoop<'static, Data
let udev_dispatcher = Dispatcher::new(udev_backend, move |event, _, data: &mut Data| {
match match event {
UdevEvent::Added { device_id, path } => data.state
UdevEvent::Added { device_id, path } => data
.state
.device_added(device_id, path, &data.display.handle())
.with_context(|| format!("Failed to add drm device: {}", device_id)),
UdevEvent::Changed { device_id } => data.state
UdevEvent::Changed { device_id } => data
.state
.device_changed(device_id)
.with_context(|| format!("Failed to update drm device: {}", device_id)),
UdevEvent::Removed { device_id } => data.state
UdevEvent::Removed { device_id } => data
.state
.device_removed(device_id, &data.display.handle())
.with_context(|| format!("Failed to remove drm device: {}", device_id)),
} {
@ -218,7 +227,10 @@ pub fn init_backend(dh: &DisplayHandle, event_loop: &mut EventLoop<'static, Data
);
}
} else {
if let Err(err) = data.state.device_added(dev, path.into(), &data.display.handle()) {
if let Err(err) =
data.state
.device_added(dev, path.into(), &data.display.handle())
{
slog_scope::error!(
"Failed to add drm device {}: {}",
path.display(),
@ -227,10 +239,7 @@ pub fn init_backend(dh: &DisplayHandle, event_loop: &mut EventLoop<'static, Data
}
}
}
data.state
.common
.output_configuration_state
.update();
data.state.common.output_configuration_state.update();
data.state.common.config.read_outputs(
data.state.common.output_configuration_state.outputs(),
@ -244,7 +253,8 @@ pub fn init_backend(dh: &DisplayHandle, event_loop: &mut EventLoop<'static, Data
.config
.write_outputs(data.state.common.output_configuration_state.outputs());
for surface in data.state
for surface in data
.state
.backend
.kms()
.devices
@ -254,12 +264,17 @@ pub fn init_backend(dh: &DisplayHandle, event_loop: &mut EventLoop<'static, Data
surface.pending = false;
}
for output in data.state.common.shell.outputs() {
if let Err(err) = data.state
if let Err(err) = data
.state
.backend
.kms()
.schedule_render(&data.state.common.event_loop_handle, output)
{
slog_scope::crit!("Error scheduling event loop for output {}: {:?}", output.name(), err);
slog_scope::crit!(
"Error scheduling event loop for output {}: {:?}",
output.name(),
err
);
}
}
});
@ -358,7 +373,8 @@ impl State {
.active_space_mut(&surface.output)
.space
.send_frames(
data.state.common.start_time.elapsed().as_millis() as u32
data.state.common.start_time.elapsed().as_millis()
as u32,
);
}
Some(Err(err)) => {
@ -422,10 +438,10 @@ impl State {
}
self.backend.kms().devices.insert(drm_node, device);
self.common.output_configuration_state.add_heads(wl_outputs.iter());
self.common
.output_configuration_state
.update();
.add_heads(wl_outputs.iter());
self.common.output_configuration_state.update();
for output in wl_outputs {
if let Err(err) = self.backend.kms().apply_config_for_output(
&output,
@ -487,8 +503,12 @@ impl State {
}
}
self.common.output_configuration_state.remove_heads(outputs_removed.iter());
self.common.output_configuration_state.add_heads(outputs_added.iter());
self.common
.output_configuration_state
.remove_heads(outputs_removed.iter());
self.common
.output_configuration_state
.add_heads(outputs_added.iter());
for output in outputs_added {
if let Err(err) = self.backend.kms().apply_config_for_output(
&output,
@ -499,9 +519,7 @@ impl State {
slog_scope::warn!("Failed to initialize output: {}", err);
}
}
self.common
.output_configuration_state
.update();
self.common.output_configuration_state.update();
self.common.config.read_outputs(
self.common.output_configuration_state.outputs(),
&mut self.backend,
@ -531,14 +549,16 @@ impl State {
}
if let Some(socket) = device.socket.take() {
self.common.event_loop_handle.remove(socket.token);
self.common.dmabuf_state.destroy_global::<State>(dh, socket.dmabuf_global);
self.common
.dmabuf_state
.destroy_global::<State>(dh, socket.dmabuf_global);
dh.remove_global(socket.drm_global);
}
}
self.common.output_configuration_state.remove_heads(outputs_removed.iter());
self.common
.output_configuration_state
.update();
.remove_heads(outputs_removed.iter());
self.common.output_configuration_state.update();
if self.backend.kms().session.is_active() {
self.common.config.read_outputs(
@ -672,35 +692,42 @@ impl Device {
const MAX_CPU_COPIES: usize = 3;
fn render_node_for_output(dh: &DisplayHandle, output: &Output, target_node: DrmNode, shell: &Shell) -> DrmNode {
fn render_node_for_output(
dh: &DisplayHandle,
output: &Output,
target_node: DrmNode,
shell: &Shell,
) -> DrmNode {
let workspace = shell.active_space(output);
let nodes = workspace
.get_fullscreen(output)
.map(|w| vec![w])
.unwrap_or_else(|| workspace.space.windows().collect::<Vec<_>>())
.into_iter()
.flat_map(|w| {
dh.get_client(w.toplevel().wl_surface().id()).ok()?
.get_data::<ClientState>().unwrap()
.drm_node
.clone()
let nodes = workspace
.get_fullscreen(output)
.map(|w| vec![w])
.unwrap_or_else(|| workspace.space.windows().collect::<Vec<_>>())
.into_iter()
.flat_map(|w| {
dh.get_client(w.toplevel().wl_surface().id())
.ok()?
.get_data::<ClientState>()
.unwrap()
.drm_node
.clone()
})
.collect::<Vec<_>>();
if nodes.contains(&target_node) || nodes.len() < MAX_CPU_COPIES {
target_node
} else {
nodes
.iter()
.fold(HashMap::new(), |mut count_map, node| {
let count = count_map.entry(node).or_insert(0);
*count += 1;
count_map
})
.collect::<Vec<_>>();
if nodes.contains(&target_node) || nodes.len() < MAX_CPU_COPIES {
target_node
} else {
nodes
.iter()
.fold(HashMap::new(), |mut count_map, node| {
let count = count_map.entry(node).or_insert(0);
*count += 1;
count_map
})
.into_iter()
.reduce(|a, b| if a.1 > b.1 { a } else { b })
.map(|(node, _)| *node)
.unwrap_or(target_node)
}
.into_iter()
.reduce(|a, b| if a.1 > b.1 { a } else { b })
.map(|(node, _)| *node)
.unwrap_or(target_node)
}
}
impl Surface {
@ -851,19 +878,36 @@ impl KmsState {
shell.refresh_outputs();
if recreated {
if let Err(err) = self.schedule_render(loop_handle, output) {
slog_scope::crit!("Error scheduling event loop for output {}: {:?}", output.name(), err);
slog_scope::crit!(
"Error scheduling event loop for output {}: {:?}",
output.name(),
err
);
}
}
Ok(())
}
pub fn target_node_for_output(&self, output: &Output) -> Option<DrmNode> {
self.devices.iter().find(|(_, dev)| dev.surfaces.values().any(|s| s.output == *output)).map(|(target, _)| target).copied()
self.devices
.iter()
.find(|(_, dev)| dev.surfaces.values().any(|s| s.output == *output))
.map(|(target, _)| target)
.copied()
}
pub fn try_early_import(&mut self, dh: &DisplayHandle, surface: &WlSurface, output: &Output, target: DrmNode, shell: &Shell) {
pub fn try_early_import(
&mut self,
dh: &DisplayHandle,
surface: &WlSurface,
output: &Output,
target: DrmNode,
shell: &Shell,
) {
let render = render_node_for_output(dh, &output, target, &shell);
if let Err(err) = self.api.early_import(
dh.get_client(surface.id()).ok().and_then(|c| c.get_data::<ClientState>().unwrap().drm_node.clone()),
dh.get_client(surface.id())
.ok()
.and_then(|c| c.get_data::<ClientState>().unwrap().drm_node.clone()),
render,
surface,
) {
@ -871,12 +915,24 @@ impl KmsState {
}
}
pub fn dmabuf_imported(&mut self, _dh: &DisplayHandle, global: &DmabufGlobal, dmabuf: Dmabuf) -> Result<()> {
pub fn dmabuf_imported(
&mut self,
_dh: &DisplayHandle,
global: &DmabufGlobal,
dmabuf: Dmabuf,
) -> Result<()> {
use smithay::backend::renderer::ImportDma;
for device in self.devices.values() {
if device.socket.as_ref().map(|s| &s.dmabuf_global == global).unwrap_or(false) {
return self.api.renderer::<Gles2Renderbuffer>(&device.render_node, &device.render_node)?
if device
.socket
.as_ref()
.map(|s| &s.dmabuf_global == global)
.unwrap_or(false)
{
return self
.api
.renderer::<Gles2Renderbuffer>(&device.render_node, &device.render_node)?
.import_dmabuf(&dmabuf, None)
.map(|_| ())
.map_err(Into::into);
@ -919,10 +975,9 @@ impl KmsState {
let crtc = *crtc;
surface.render_timer_token = Some(loop_handle.insert_source(
//if surface.vrr || instant.is_none() {
Timer::immediate()
/*} else {
Timer::from_deadline(instant.unwrap())
}*/,
Timer::immediate(), /*} else {
Timer::from_deadline(instant.unwrap())
}*/
move |_time, _, data| {
let backend = data.state.backend.kms();
if let Some(device) = backend.devices.get_mut(&device) {

View file

@ -8,12 +8,9 @@ use smithay::{
},
reexports::{
calloop::RegistrationToken,
wayland_server::{Client, DisplayHandle, backend::GlobalId},
},
wayland::{
dmabuf::DmabufGlobal,
socket::ListeningSocketSource,
wayland_server::{backend::GlobalId, Client, DisplayHandle},
},
wayland::{dmabuf::DmabufGlobal, socket::ListeningSocketSource},
};
use std::sync::Arc;
@ -53,50 +50,45 @@ impl State {
dev_id == render_node
};
let dmabuf_global = self.common.dmabuf_state.create_global_with_filter::<State, _, _>(
dh,
formats.clone(),
filter,
None,
);
let dmabuf_global = self
.common
.dmabuf_state
.create_global_with_filter::<State, _, _>(dh, formats.clone(), filter, None);
let drm_global_id = self
.common
.wl_drm_state
.create_global_with_filter::<State, _>(
dh,
render_node
.dev_path_with_type(NodeType::Render)
.or_else(|| render_node.dev_path())
.ok_or(anyhow!(
"Could not determine path for gpu node: {}",
render_node
))?,
formats,
&dmabuf_global,
filter,
);
let drm_global_id = self.common.wl_drm_state.create_global_with_filter::<State, _>(
dh,
render_node
.dev_path_with_type(NodeType::Render)
.or_else(|| render_node.dev_path())
.ok_or(anyhow!("Could not determine path for gpu node: {}", render_node))?,
formats,
&dmabuf_global,
filter,
);
// add a special socket for the gpu
let listener = ListeningSocketSource::with_name(&socket_name, None)
.with_context(|| format!("Failed to bind socket to {}", socket_name))?;
let token = self
.common
.event_loop_handle
.insert_source(
listener,
move |client_stream, _, data: &mut Data| {
if let Err(err) = data
.display
.handle()
.insert_client(client_stream, Arc::new(data.state.new_client_state_with_node(render_node)))
{
slog_scope::warn!("Error adding wayland client ({}): {}", render_node, err);
}
.insert_source(listener, move |client_stream, _, data: &mut Data| {
if let Err(err) = data.display.handle().insert_client(
client_stream,
Arc::new(data.state.new_client_state_with_node(render_node)),
) {
slog_scope::warn!("Error adding wayland client ({}): {}", render_node, err);
}
)
})
.context("Failed to add gpu-wayland socket to the event loop")?;
slog_scope::info!(
"Added socket at {} for gpu {}",
socket_name,
render_node,
);
slog_scope::info!("Added socket at {} for gpu {}", socket_name, render_node,);
Ok(Socket {
token,

View file

@ -2,10 +2,7 @@
use crate::state::{Data, State};
use anyhow::Result;
use smithay::reexports::{
calloop::EventLoop,
wayland_server::DisplayHandle,
};
use smithay::reexports::{calloop::EventLoop, wayland_server::DisplayHandle};
pub mod render;

View file

@ -1,14 +1,11 @@
// SPDX-License-Identifier: GPL-3.0-only
use crate::{
wayland::handlers::data_device::get_dnd_icon,
utils::prelude::*,
};
use crate::{utils::prelude::*, wayland::handlers::data_device::get_dnd_icon};
use smithay::{
backend::renderer::{Frame, ImportAll, ImportMem, Renderer, Texture},
desktop::space::{RenderElement, SpaceOutputTuple, SurfaceTree},
reexports::wayland_server::protocol::wl_surface,
utils::{IsAlive, Logical, Physical, Point, Rectangle, Size, Scale, Transform},
utils::{IsAlive, Logical, Physical, Point, Rectangle, Scale, Size, Transform},
wayland::{
compositor::{get_role, with_states},
seat::{CursorImageAttributes, CursorImageStatus, Seat},
@ -198,7 +195,9 @@ where
}
fn geometry(&self, scale: impl Into<Scale<f64>>) -> Rectangle<i32, Physical> {
Rectangle::from_loc_and_size(self.position, self.size.to_f64()).to_physical(scale).to_i32_round()
Rectangle::from_loc_and_size(self.position, self.size.to_f64())
.to_physical(scale)
.to_i32_round()
}
fn accumulated_damage(
@ -207,7 +206,10 @@ where
_: Option<SpaceOutputTuple<'_, '_>>,
) -> Vec<Rectangle<i32, Physical>> {
if self.new_frame {
vec![Rectangle::from_loc_and_size((0, 0), self.size.to_physical_precise_round(scale))]
vec![Rectangle::from_loc_and_size(
(0, 0),
self.size.to_physical_precise_round(scale),
)]
} else {
vec![]
}
@ -323,7 +325,8 @@ where
pointer_images.push((frame.clone(), Box::new(texture.clone())));
texture
});
let hotspot = Point::<i32, Logical>::from((frame.xhot as i32, frame.yhot as i32)).to_f64();
let hotspot =
Point::<i32, Logical>::from((frame.xhot as i32, frame.yhot as i32)).to_f64();
*state.current_image.borrow_mut() = Some(frame);
Some(PointerElement::new(pointer_image.clone(), location - hotspot, new_frame).into())

View file

@ -6,7 +6,7 @@ use crate::{
debug::{debug_ui, fps_ui, log_ui, EguiFrame},
state::Fps,
utils::prelude::*,
};
};
use slog::Logger;
use smithay::{
@ -19,7 +19,8 @@ use smithay::{
},
},
desktop::{
draw_layer_surface, draw_layer_popups, draw_window, draw_window_popups, layer_map_for_output,
draw_layer_popups, draw_layer_surface, draw_window, draw_window_popups,
layer_map_for_output,
space::{RenderElement, RenderError, SpaceOutputTuple, SurfaceTree},
utils::damage_from_surface_tree,
Window,
@ -201,13 +202,22 @@ where
.unwrap_or(Rectangle::from_loc_and_size((0, 0), (0, 0)));
let scale = output.current_scale().fractional_scale();
let fps_overlay = fps_ui(_gpu, state, fps, output_geo.to_f64().to_physical(scale), scale);
let fps_overlay = fps_ui(
_gpu,
state,
fps,
output_geo.to_f64().to_physical(scale),
scale,
);
custom_elements.push(fps_overlay.into());
let area = Rectangle::<f64, smithay::utils::Logical>::from_loc_and_size(
state.shell.space_relative_output_geometry((0.0f64, 0.0f64), output),
state
.shell
.space_relative_output_geometry((0.0f64, 0.0f64), output),
state.shell.global_space().to_f64().size,
).to_physical(scale);
)
.to_physical(scale);
if let Some(log_ui) = log_ui(state, area, scale, output_geo.size.w as f32 * 0.6) {
custom_elements.push(log_ui.into());
}
@ -272,7 +282,9 @@ where
_gpu,
state,
fps,
Rectangle::from_loc_and_size((0, 0), output_geo.size).to_f64().to_physical(scale),
Rectangle::from_loc_and_size((0, 0), output_geo.size)
.to_f64()
.to_physical(scale),
scale,
);
custom_elements.push(fps_overlay.into());
@ -311,10 +323,7 @@ where
&window,
scale,
(0.0, 0.0),
&[Rectangle::from_loc_and_size(
(0, 0),
mode.size,
)],
&[Rectangle::from_loc_and_size((0, 0), mode.size)],
&slog_scope::logger(),
)?;
draw_window_popups(
@ -323,10 +332,7 @@ where
&window,
scale,
(0.0, 0.0),
&[Rectangle::from_loc_and_size(
(0, 0),
mode.size,
)],
&[Rectangle::from_loc_and_size((0, 0), mode.size)],
&slog_scope::logger(),
)?;
let layer_map = layer_map_for_output(output);
@ -338,7 +344,10 @@ where
layer_surface,
scale,
geo.loc.to_f64().to_physical(scale),
&[Rectangle::from_loc_and_size((0, 0), geo.size.to_physical_precise_round(scale))],
&[Rectangle::from_loc_and_size(
(0, 0),
geo.size.to_physical_precise_round(scale),
)],
&slog_scope::logger(),
)?;
draw_layer_popups(
@ -347,10 +356,18 @@ where
layer_surface,
scale,
geo.loc.to_f64().to_physical(scale),
&[Rectangle::from_loc_and_size((0, 0), geo.size.to_physical_precise_round(scale))],
&[Rectangle::from_loc_and_size(
(0, 0),
geo.size.to_physical_precise_round(scale),
)],
&slog_scope::logger(),
)?;
damage.extend(damage_from_surface_tree(layer_surface.wl_surface(), geo.loc.to_f64().to_physical(scale), scale, None));
damage.extend(damage_from_surface_tree(
layer_surface.wl_surface(),
geo.loc.to_f64().to_physical(scale),
scale,
None,
));
}
for elem in custom_elements {
let loc = elem.location(scale);

View file

@ -43,7 +43,9 @@ impl WinitState {
self.reset_buffers();
}
self.backend.bind().with_context(|| "Failed to bind buffer")?;
self.backend
.bind()
.with_context(|| "Failed to bind buffer")?;
let age = if self.age_reset > 0 {
self.age_reset -= 1;
0
@ -110,7 +112,11 @@ impl WinitState {
}
}
pub fn init_backend(dh: &DisplayHandle, event_loop: &mut EventLoop<Data>, state: &mut State) -> Result<()> {
pub fn init_backend(
dh: &DisplayHandle,
event_loop: &mut EventLoop<Data>,
state: &mut State,
) -> Result<()> {
let (mut backend, mut input) =
winit::init(None).map_err(|_| anyhow!("Failed to initilize winit backend"))?;
@ -158,9 +164,12 @@ pub fn init_backend(dh: &DisplayHandle, event_loop: &mut EventLoop<Data>, state:
event_loop
.handle()
.insert_source(render_source, move |_, _, data| {
if let Err(err) = data.state.backend.winit().render_output(
&mut data.state.common
) {
if let Err(err) = data
.state
.backend
.winit()
.render_output(&mut data.state.common)
{
slog_scope::error!("Failed to render frame: {}", err);
render_ping.ping();
}
@ -171,13 +180,10 @@ pub fn init_backend(dh: &DisplayHandle, event_loop: &mut EventLoop<Data>, state:
event_loop
.handle()
.insert_source(event_source, move |_, _, data| {
match input
.dispatch_new_events(|event| data.state.process_winit_event(
&data.display.handle(),
event,
&render_ping_handle
))
{
match input.dispatch_new_events(|event| {
data.state
.process_winit_event(&data.display.handle(), event, &render_ping_handle)
}) {
Ok(_) => {
event_ping_handle.ping();
render_ping_handle.ping();
@ -201,11 +207,11 @@ pub fn init_backend(dh: &DisplayHandle, event_loop: &mut EventLoop<Data>, state:
fps: Fps::default(),
age_reset: 0,
});
state.common.output_configuration_state.add_heads(std::iter::once(&output));
state
.common
.output_configuration_state
.update();
.add_heads(std::iter::once(&output));
state.common.output_configuration_state.update();
state.common.shell.add_output(&output);
state.common.config.read_outputs(
std::iter::once(&output),
@ -233,11 +239,10 @@ fn init_egl_client_side(
.dmabuf_formats()
.cloned()
.collect::<Vec<_>>();
state.common.dmabuf_state.create_global::<State, _>(
dh,
dmabuf_formats,
None,
);
state
.common
.dmabuf_state
.create_global::<State, _>(dh, dmabuf_formats, None);
}
Err(err) => slog_scope::warn!("Unable to initialize bind display to EGL: {}", err),
};
@ -246,7 +251,12 @@ fn init_egl_client_side(
}
impl State {
pub fn process_winit_event(&mut self, dh: &DisplayHandle, event: WinitEvent, render_ping: &ping::Ping) {
pub fn process_winit_event(
&mut self,
dh: &DisplayHandle,
event: WinitEvent,
render_ping: &ping::Ping,
) {
// here we can handle special cases for winit inputs
match event {
WinitEvent::Focus(true) => {
@ -278,9 +288,7 @@ impl State {
output.set_preferred(mode);
output.change_current_state(Some(mode), None, None, None);
layer_map_for_output(output).arrange(dh);
self.common
.output_configuration_state
.update();
self.common.output_configuration_state.update();
self.common.shell.refresh_outputs();
render_ping.ping();
}

View file

@ -93,8 +93,8 @@ impl X11State {
.iter_mut()
.find(|s| s.output == output_ref)
{
if let Err(err) = surface
.render_output(&mut x11_state.renderer, &mut data.state.common)
if let Err(err) =
surface.render_output(&mut x11_state.renderer, &mut data.state.common)
{
slog_scope::error!("Error rendering: {}", err);
}
@ -218,7 +218,11 @@ impl Surface {
}
}
pub fn init_backend(dh: &DisplayHandle, event_loop: &mut EventLoop<Data>, state: &mut State) -> Result<()> {
pub fn init_backend(
dh: &DisplayHandle,
event_loop: &mut EventLoop<Data>,
state: &mut State,
) -> Result<()> {
let backend = X11Backend::new(None).with_context(|| "Failed to initilize X11 backend")?;
let handle = backend.handle();
@ -253,11 +257,11 @@ pub fn init_backend(dh: &DisplayHandle, event_loop: &mut EventLoop<Data>, state:
.x11()
.add_window(event_loop.handle())
.with_context(|| "Failed to create wl_output")?;
state.common.output_configuration_state.add_heads(std::iter::once(&output));
state
.common
.output_configuration_state
.update();
.add_heads(std::iter::once(&output));
state.common.output_configuration_state.update();
state.common.shell.add_output(&output);
state.common.config.read_outputs(
std::iter::once(&output),
@ -303,7 +307,8 @@ pub fn init_backend(dh: &DisplayHandle, event_loop: &mut EventLoop<Data>, state:
size,
refresh: 60_000,
};
if let Some(surface) = data.state
if let Some(surface) = data
.state
.backend
.x11()
.surfaces
@ -324,10 +329,7 @@ pub fn init_backend(dh: &DisplayHandle, event_loop: &mut EventLoop<Data>, state:
output.change_current_state(Some(mode), None, None, None);
output.set_preferred(mode);
layer_map_for_output(output).arrange(&data.display.handle());
data.state
.common
.output_configuration_state
.update();
data.state.common.output_configuration_state.update();
data.state.common.shell.refresh_outputs();
surface.dirty = true;
if !surface.pending {
@ -358,20 +360,20 @@ pub fn init_backend(dh: &DisplayHandle, event_loop: &mut EventLoop<Data>, state:
Ok(())
}
fn init_egl_client_side(dh: &DisplayHandle, state: &mut State, renderer: &mut Gles2Renderer) -> Result<()> {
fn init_egl_client_side(
dh: &DisplayHandle,
state: &mut State,
renderer: &mut Gles2Renderer,
) -> Result<()> {
let bind_result = renderer.bind_wl_display(dh);
match bind_result {
Ok(_) => {
slog_scope::info!("EGL hardware-acceleration enabled");
let dmabuf_formats = renderer
.dmabuf_formats()
.cloned()
.collect::<Vec<_>>();
state.common.dmabuf_state.create_global::<State, _>(
dh,
dmabuf_formats,
None,
);
let dmabuf_formats = renderer.dmabuf_formats().cloned().collect::<Vec<_>>();
state
.common
.dmabuf_state
.create_global::<State, _>(dh, dmabuf_formats, None);
}
Err(err) => slog_scope::warn!("Unable to initialize bind display to EGL: {}", err),
};