config: generate graphics-initialized event in the frontend
This commit is contained in:
parent
c30f4d7266
commit
5e21e00059
17 changed files with 56 additions and 29 deletions
|
|
@ -121,7 +121,6 @@ pub enum InputDeviceAccelProfile {
|
|||
}
|
||||
|
||||
pub enum BackendEvent {
|
||||
GraphicsInitialized,
|
||||
NewConnector(Rc<dyn Connector>),
|
||||
NewInputDevice(Rc<dyn InputDevice>),
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,8 +6,8 @@ use {
|
|||
crate::{
|
||||
async_engine::{AsyncError, AsyncFd, SpawnedFuture},
|
||||
backend::{
|
||||
Backend, BackendEvent, InputDevice, InputDeviceAccelProfile, InputDeviceCapability,
|
||||
InputDeviceId, InputEvent, KeyState, TransformMatrix,
|
||||
Backend, InputDevice, InputDeviceAccelProfile, InputDeviceCapability, InputDeviceId,
|
||||
InputEvent, KeyState, TransformMatrix,
|
||||
},
|
||||
backends::metal::video::{MetalDrmDevice, MetalRenderContext, PendingDrmDevice},
|
||||
dbus::{DbusError, SignalHandler},
|
||||
|
|
@ -141,9 +141,6 @@ impl MetalBackend {
|
|||
if let Err(e) = self.enumerate_devices() {
|
||||
return Err(MetalError::Enumerate(Box::new(e)));
|
||||
}
|
||||
self.state
|
||||
.backend_events
|
||||
.push(BackendEvent::GraphicsInitialized);
|
||||
pending().await
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -266,10 +266,6 @@ pub struct XBackend {
|
|||
|
||||
impl XBackend {
|
||||
async fn run(self: Rc<Self>) -> Result<(), XBackendError> {
|
||||
self.state
|
||||
.backend_events
|
||||
.push(BackendEvent::GraphicsInitialized);
|
||||
|
||||
self.query_devices(INPUT_DEVICE_ALL_MASTER).await?;
|
||||
|
||||
let _events = self.state.eng.spawn(self.clone().event_handler());
|
||||
|
|
|
|||
|
|
@ -128,6 +128,7 @@ fn start_compositor2(
|
|||
el: el.clone(),
|
||||
render_ctx: Default::default(),
|
||||
render_ctx_version: NumCell::new(1),
|
||||
render_ctx_ever_initialized: Cell::new(false),
|
||||
cursors: Default::default(),
|
||||
wheel,
|
||||
clients: Clients::new(),
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ use {
|
|||
errorfmt::ErrorFmt,
|
||||
},
|
||||
video::dmabuf::DmaBuf,
|
||||
wire::{jay_screenshot::Dmabuf, wl_buffer::*, WlBufferId},
|
||||
wire::{wl_buffer::*, WlBufferId},
|
||||
},
|
||||
std::{
|
||||
cell::{Cell, RefCell},
|
||||
|
|
|
|||
|
|
@ -8,12 +8,12 @@ use {
|
|||
},
|
||||
compositor::TestFuture,
|
||||
fixed::Fixed,
|
||||
it::test_error::TestResult,
|
||||
render::{RenderContext, RenderError},
|
||||
state::State,
|
||||
time::Time,
|
||||
utils::{
|
||||
clonecell::CloneCell, copyhashmap::CopyHashMap, errorfmt::ErrorFmt, oserror::OsError,
|
||||
syncqueue::SyncQueue,
|
||||
clonecell::CloneCell, copyhashmap::CopyHashMap, oserror::OsError, syncqueue::SyncQueue,
|
||||
},
|
||||
video::drm::{ConnectorType, Drm},
|
||||
},
|
||||
|
|
@ -41,6 +41,7 @@ pub struct TestBackend {
|
|||
pub default_connector: Rc<TestConnector>,
|
||||
pub default_mouse: Rc<TestBackendMouse>,
|
||||
pub default_kb: Rc<TestBackendKb>,
|
||||
pub render_context_installed: Cell<bool>,
|
||||
}
|
||||
|
||||
impl TestBackend {
|
||||
|
|
@ -92,10 +93,21 @@ impl TestBackend {
|
|||
default_connector,
|
||||
default_mouse,
|
||||
default_kb,
|
||||
render_context_installed: Cell::new(false),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn install_default(&self) {
|
||||
pub fn install_render_context(&self) -> TestResult {
|
||||
if self.render_context_installed.get() {
|
||||
return Ok(());
|
||||
}
|
||||
self.create_render_context()?;
|
||||
self.render_context_installed.set(true);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn install_default(&self) -> TestResult {
|
||||
self.install_render_context()?;
|
||||
self.state
|
||||
.backend_events
|
||||
.push(BackendEvent::NewConnector(self.default_connector.clone()));
|
||||
|
|
@ -121,6 +133,7 @@ impl TestBackend {
|
|||
self.state
|
||||
.backend_events
|
||||
.push(BackendEvent::NewInputDevice(self.default_mouse.clone()));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn create_render_context(&self) -> Result<(), TestBackendError> {
|
||||
|
|
@ -175,11 +188,7 @@ impl TestBackend {
|
|||
impl Backend for TestBackend {
|
||||
fn run(self: Rc<Self>) -> SpawnedFuture<Result<(), Box<dyn std::error::Error>>> {
|
||||
let future = (self.test_future)(&self.state);
|
||||
let slf = self.clone();
|
||||
self.state.eng.spawn(async move {
|
||||
if let Err(e) = slf.create_render_context() {
|
||||
log::error!("Could not create render context: {}", ErrorFmt(e));
|
||||
}
|
||||
let future: Pin<_> = future.into();
|
||||
future.await;
|
||||
Ok(())
|
||||
|
|
|
|||
|
|
@ -38,6 +38,7 @@ where
|
|||
srv: Cell::new(None),
|
||||
responses: Default::default(),
|
||||
invoked_shortcuts: Default::default(),
|
||||
graphics_initialized: Cell::new(false),
|
||||
});
|
||||
let old = CONFIG;
|
||||
CONFIG = tc.deref();
|
||||
|
|
@ -99,7 +100,7 @@ unsafe extern "C" fn handle_msg(data: *const u8, msg: *const u8, size: usize) {
|
|||
ServerMessage::NewConnector { .. } => {}
|
||||
ServerMessage::DelConnector { .. } => {}
|
||||
ServerMessage::TimerExpired { .. } => {}
|
||||
ServerMessage::GraphicsInitialized => {}
|
||||
ServerMessage::GraphicsInitialized => tc.graphics_initialized.set(true),
|
||||
ServerMessage::Clear => tc.clear(),
|
||||
}
|
||||
}
|
||||
|
|
@ -115,6 +116,7 @@ pub struct TestConfig {
|
|||
srv: Cell<Option<ServerData>>,
|
||||
responses: Stack<Response>,
|
||||
pub invoked_shortcuts: CopyHashMap<(SeatId, ModifiedKeySym), ()>,
|
||||
pub graphics_initialized: Cell<bool>,
|
||||
}
|
||||
|
||||
macro_rules! get_response {
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ impl<T> TestExpectedEvent<T> {
|
|||
}
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn last(&self) -> TestResult<T> {
|
||||
match self.data.events.borrow_mut().pop_back() {
|
||||
Some(t) => Ok(t),
|
||||
|
|
|
|||
|
|
@ -105,7 +105,7 @@ impl TestRun {
|
|||
}
|
||||
|
||||
pub async fn create_default_setup(&self) -> Result<DefaultSetup, TestError> {
|
||||
self.backend.install_default();
|
||||
self.backend.install_default()?;
|
||||
let seat = self.get_seat("default")?;
|
||||
self.state.eng.yield_now().await;
|
||||
let output = match self.state.outputs.lock().values().next() {
|
||||
|
|
|
|||
|
|
@ -38,6 +38,7 @@ mod t0009_tab_focus;
|
|||
mod t0010_fullscreen_focus;
|
||||
mod t0011_set_keymap;
|
||||
mod t0012_subsurface_focus;
|
||||
mod t0013_graphics_initialized;
|
||||
|
||||
pub trait TestCase: Sync {
|
||||
fn name(&self) -> &'static str;
|
||||
|
|
@ -68,5 +69,6 @@ pub fn tests() -> Vec<&'static dyn TestCase> {
|
|||
t0010_fullscreen_focus,
|
||||
t0011_set_keymap,
|
||||
t0012_subsurface_focus,
|
||||
t0013_graphics_initialized,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ testcase!();
|
|||
|
||||
/// Create and map a single surface
|
||||
async fn test(run: Rc<TestRun>) -> Result<(), TestError> {
|
||||
run.backend.install_default();
|
||||
run.backend.install_default()?;
|
||||
|
||||
let client = run.create_client().await?;
|
||||
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ testcase!();
|
|||
|
||||
/// Create and map two surfaces
|
||||
async fn test(run: Rc<TestRun>) -> Result<(), TestError> {
|
||||
run.backend.install_default();
|
||||
run.backend.install_default()?;
|
||||
|
||||
let client = run.create_client().await?;
|
||||
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ testcase!();
|
|||
|
||||
/// Test subsurface positioning
|
||||
async fn test(run: Rc<TestRun>) -> Result<(), TestError> {
|
||||
run.backend.install_default();
|
||||
run.backend.install_default()?;
|
||||
|
||||
let seat = run.get_seat("default")?;
|
||||
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ async fn test(run: Rc<TestRun>) -> TestResult {
|
|||
|
||||
run.cfg.set_fullscreen(ds.seat.id(), true)?;
|
||||
client.sync().await;
|
||||
window.map().await;
|
||||
window.map().await?;
|
||||
|
||||
ds.mouse.rel(-1000.0, -1000.0);
|
||||
|
||||
|
|
|
|||
18
src/it/tests/t0013_graphics_initialized.rs
Normal file
18
src/it/tests/t0013_graphics_initialized.rs
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
use {
|
||||
crate::it::{test_error::TestResult, testrun::TestRun},
|
||||
std::rc::Rc,
|
||||
};
|
||||
|
||||
testcase!();
|
||||
|
||||
async fn test(run: Rc<TestRun>) -> TestResult {
|
||||
run.sync().await;
|
||||
|
||||
tassert!(!run.cfg.graphics_initialized.get());
|
||||
|
||||
run.backend.install_render_context()?;
|
||||
|
||||
tassert!(run.cfg.graphics_initialized.get());
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
@ -63,6 +63,7 @@ pub struct State {
|
|||
pub el: Rc<EventLoop>,
|
||||
pub render_ctx: CloneCell<Option<Rc<RenderContext>>>,
|
||||
pub render_ctx_version: NumCell<u32>,
|
||||
pub render_ctx_ever_initialized: Cell<bool>,
|
||||
pub cursors: CloneCell<Option<Rc<ServerCursors>>>,
|
||||
pub wheel: Rc<Wheel>,
|
||||
pub clients: Clients,
|
||||
|
|
@ -251,6 +252,12 @@ impl State {
|
|||
for seat in seats.values() {
|
||||
seat.render_ctx_changed();
|
||||
}
|
||||
|
||||
if ctx.is_some() && !self.render_ctx_ever_initialized.replace(true) {
|
||||
if let Some(config) = self.config.get() {
|
||||
config.graphics_initialized();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn add_global<T: WaylandGlobal>(&self, global: &Rc<T>) {
|
||||
|
|
|
|||
|
|
@ -23,11 +23,6 @@ impl BackendEventHandler {
|
|||
match event {
|
||||
BackendEvent::NewConnector(connector) => connector::handle(&self.state, &connector),
|
||||
BackendEvent::NewInputDevice(s) => input_device::handle(&self.state, s),
|
||||
BackendEvent::GraphicsInitialized => {
|
||||
if let Some(config) = self.state.config.get() {
|
||||
config.graphics_initialized();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue