autocommit 2022-04-04 00:28:58 CEST
This commit is contained in:
parent
9ec1c5c995
commit
1f71290dab
21 changed files with 1217 additions and 132 deletions
|
|
@ -1,4 +1,4 @@
|
|||
use crate::backend::{Backend, Output, OutputId};
|
||||
use crate::backend::{Backend, Connector, ConnectorEvent, OutputId};
|
||||
use std::rc::Rc;
|
||||
|
||||
pub struct DummyBackend {}
|
||||
|
|
@ -13,21 +13,13 @@ pub struct DummyOutput {
|
|||
pub id: OutputId,
|
||||
}
|
||||
|
||||
impl Output for DummyOutput {
|
||||
impl Connector for DummyOutput {
|
||||
fn id(&self) -> OutputId {
|
||||
self.id
|
||||
}
|
||||
|
||||
fn removed(&self) -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
fn width(&self) -> i32 {
|
||||
100
|
||||
}
|
||||
|
||||
fn height(&self) -> i32 {
|
||||
100
|
||||
fn event(&self) -> Option<ConnectorEvent> {
|
||||
None
|
||||
}
|
||||
|
||||
fn on_change(&self, _cb: Rc<dyn Fn()>) {
|
||||
|
|
|
|||
|
|
@ -232,6 +232,7 @@ impl MetalBackend {
|
|||
}
|
||||
|
||||
fn handle_drm_change(self: &Rc<Self>, _dev: UdevDevice) -> Option<()> {
|
||||
// TODO: Handle monitor connections and connector hotplug
|
||||
None
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
use crate::async_engine::{AsyncFd, SpawnedFuture};
|
||||
use crate::backend::{BackendEvent, Output, OutputId};
|
||||
use crate::backend::{BackendEvent, Connector, ConnectorEvent, Mode, OutputId};
|
||||
use crate::backends::metal::{DrmId, MetalBackend, MetalError};
|
||||
use crate::drm::drm::{
|
||||
drm_mode_modeinfo, Change, ConnectorStatus, ConnectorType, DrmBlob, DrmConnector, DrmCrtc,
|
||||
|
|
@ -24,6 +24,7 @@ use std::ffi::CString;
|
|||
use std::fmt::{Debug, Formatter};
|
||||
use std::rc::Rc;
|
||||
use uapi::c;
|
||||
use crate::utils::syncqueue::SyncQueue;
|
||||
|
||||
pub struct PendingDrmDevice {
|
||||
pub id: DrmId,
|
||||
|
|
@ -77,6 +78,8 @@ pub struct MetalConnector {
|
|||
pub modes: Vec<DrmModeInfo>,
|
||||
pub mode: CloneCell<Option<Rc<DrmModeInfo>>>,
|
||||
|
||||
pub events: SyncQueue<ConnectorEvent>,
|
||||
|
||||
pub buffers: CloneCell<Option<Rc<[RenderBuffer; 2]>>>,
|
||||
pub next_buffer: NumCell<usize>,
|
||||
|
||||
|
|
@ -110,27 +113,13 @@ impl Debug for OnChange {
|
|||
}
|
||||
}
|
||||
|
||||
impl Output for MetalConnector {
|
||||
impl Connector for MetalConnector {
|
||||
fn id(&self) -> OutputId {
|
||||
self.output_id
|
||||
}
|
||||
|
||||
fn removed(&self) -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
fn width(&self) -> i32 {
|
||||
match self.mode.get() {
|
||||
Some(m) => m.hdisplay as _,
|
||||
_ => 0,
|
||||
}
|
||||
}
|
||||
|
||||
fn height(&self) -> i32 {
|
||||
match self.mode.get() {
|
||||
Some(m) => m.vdisplay as _,
|
||||
_ => 0,
|
||||
}
|
||||
fn event(&self) -> Option<ConnectorEvent> {
|
||||
self.events.pop()
|
||||
}
|
||||
|
||||
fn on_change(&self, cb: Rc<dyn Fn()>) {
|
||||
|
|
@ -223,12 +212,22 @@ fn create_connector(
|
|||
}
|
||||
}
|
||||
let props = collect_properties(&dev.master, connector)?;
|
||||
let mode = info.modes.first().cloned().map(Rc::new);
|
||||
let events = SyncQueue::default();
|
||||
if let Some(mode) = &mode {
|
||||
events.push(ConnectorEvent::ModeChanged(Mode {
|
||||
width: mode.hdisplay as _,
|
||||
height: mode.vdisplay as _,
|
||||
refresh_rate: mode.refresh_rate(),
|
||||
}));
|
||||
}
|
||||
Ok(MetalConnector {
|
||||
id: connector,
|
||||
master: dev.master.clone(),
|
||||
output_id: state.output_ids.next(),
|
||||
crtcs,
|
||||
mode: CloneCell::new(info.modes.first().cloned().map(Rc::new)),
|
||||
mode: CloneCell::new(mode),
|
||||
events,
|
||||
modes: info.modes,
|
||||
buffers: Default::default(),
|
||||
next_buffer: Default::default(),
|
||||
|
|
@ -486,6 +485,9 @@ impl MetalBackend {
|
|||
self.init_drm_device(&slf)?;
|
||||
|
||||
for connector in slf.connectors.values() {
|
||||
self.state
|
||||
.backend_events
|
||||
.push(BackendEvent::NewConnector(connector.clone()));
|
||||
if connector.primary_plane.get().is_some() {
|
||||
self.start_connector(connector);
|
||||
}
|
||||
|
|
@ -880,9 +882,6 @@ impl MetalBackend {
|
|||
|
||||
fn start_connector(&self, connector: &Rc<MetalConnector>) {
|
||||
let mode = connector.mode.get().unwrap();
|
||||
self.state
|
||||
.backend_events
|
||||
.push(BackendEvent::NewOutput(connector.clone()));
|
||||
log::info!(
|
||||
"Initialized connector {}-{} with mode {:?}",
|
||||
connector.connector_type,
|
||||
|
|
@ -905,7 +904,7 @@ impl MetalBackend {
|
|||
if let Some(node) = self.state.root.outputs.get(&connector.output_id) {
|
||||
buffer
|
||||
.egl
|
||||
.render(&*node, &self.state, Some(node.position.get()));
|
||||
.render(&*node, &self.state, Some(node.global.pos.get()));
|
||||
}
|
||||
let mut changes = connector.master.change();
|
||||
changes.change_object(plane.id, |c| {
|
||||
|
|
|
|||
|
|
@ -1,8 +1,5 @@
|
|||
use crate::async_engine::{Phase, SpawnedFuture};
|
||||
use crate::backend::{
|
||||
Backend, BackendEvent, InputDevice, InputDeviceAccelProfile, InputDeviceCapability,
|
||||
InputDeviceId, InputEvent, KeyState, Output, OutputId, ScrollAxis,
|
||||
};
|
||||
use crate::backend::{Backend, BackendEvent, InputDevice, InputDeviceAccelProfile, InputDeviceCapability, InputDeviceId, InputEvent, KeyState, Connector, OutputId, ScrollAxis, Mode, ConnectorEvent};
|
||||
use crate::drm::drm::{Drm, DrmError};
|
||||
use crate::drm::gbm::{GbmDevice, GbmError, GBM_BO_USE_RENDERING};
|
||||
use crate::drm::{ModifiedFormat, INVALID_MODIFIER};
|
||||
|
|
@ -42,6 +39,7 @@ use std::cell::{Cell, RefCell};
|
|||
use std::collections::VecDeque;
|
||||
use std::rc::Rc;
|
||||
use thiserror::Error;
|
||||
use crate::utils::syncqueue::SyncQueue;
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum XBackendError {
|
||||
|
|
@ -396,7 +394,7 @@ impl XBackendData {
|
|||
id: self.state.output_ids.next(),
|
||||
_backend: self.clone(),
|
||||
window: window_id,
|
||||
removed: Cell::new(false),
|
||||
events: Default::default(),
|
||||
width: Cell::new(0),
|
||||
height: Cell::new(0),
|
||||
serial: Default::default(),
|
||||
|
|
@ -479,7 +477,7 @@ impl XBackendData {
|
|||
self.outputs.set(window_id, output.clone());
|
||||
self.state
|
||||
.backend_events
|
||||
.push(BackendEvent::NewOutput(output.clone()));
|
||||
.push(BackendEvent::NewConnector(output.clone()));
|
||||
self.present(&output).await;
|
||||
Ok(())
|
||||
}
|
||||
|
|
@ -636,10 +634,6 @@ impl XBackendData {
|
|||
}
|
||||
|
||||
async fn present(&self, output: &Rc<XOutput>) {
|
||||
if output.removed.get() {
|
||||
return;
|
||||
}
|
||||
|
||||
let serial = output.serial.fetch_add(1);
|
||||
|
||||
let image = &output.images[output.next_image.fetch_add(1) % output.images.len()];
|
||||
|
|
@ -648,7 +642,7 @@ impl XBackendData {
|
|||
|
||||
if let Some(node) = self.state.root.outputs.get(&output.id) {
|
||||
let fb = image.fb.get();
|
||||
fb.render(&*node, &self.state, Some(node.position.get()));
|
||||
fb.render(&*node, &self.state, Some(node.global.pos.get()));
|
||||
}
|
||||
|
||||
let pp = PresentPixmap {
|
||||
|
|
@ -795,7 +789,7 @@ impl XBackendData {
|
|||
Some(o) => o,
|
||||
_ => return Ok(()),
|
||||
};
|
||||
output.removed.set(true);
|
||||
output.events.push(ConnectorEvent::Removed);
|
||||
output.changed();
|
||||
Ok(())
|
||||
}
|
||||
|
|
@ -820,6 +814,11 @@ impl XBackendData {
|
|||
old.fb.set(new.fb.get());
|
||||
old.pixmap.set(new.pixmap.get());
|
||||
}
|
||||
output.events.push(ConnectorEvent::ModeChanged(Mode {
|
||||
width,
|
||||
height,
|
||||
refresh_rate: 60, // TODO
|
||||
}));
|
||||
output.changed();
|
||||
}
|
||||
Ok(())
|
||||
|
|
@ -830,7 +829,7 @@ struct XOutput {
|
|||
id: OutputId,
|
||||
_backend: Rc<XBackendData>,
|
||||
window: u32,
|
||||
removed: Cell<bool>,
|
||||
events: SyncQueue<ConnectorEvent>,
|
||||
width: Cell<i32>,
|
||||
height: Cell<i32>,
|
||||
serial: NumCell<u32>,
|
||||
|
|
@ -856,21 +855,13 @@ impl XOutput {
|
|||
}
|
||||
}
|
||||
|
||||
impl Output for XOutput {
|
||||
impl Connector for XOutput {
|
||||
fn id(&self) -> OutputId {
|
||||
self.id
|
||||
}
|
||||
|
||||
fn removed(&self) -> bool {
|
||||
self.removed.get()
|
||||
}
|
||||
|
||||
fn width(&self) -> i32 {
|
||||
self.width.get()
|
||||
}
|
||||
|
||||
fn height(&self) -> i32 {
|
||||
self.height.get()
|
||||
fn event(&self) -> Option<ConnectorEvent> {
|
||||
self.events.pop()
|
||||
}
|
||||
|
||||
fn on_change(&self, cb: Rc<dyn Fn()>) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue