drm: add more logging

This commit is contained in:
Drakulix 2017-09-14 23:12:16 +02:00
parent 73d262e292
commit 10fd94f963
2 changed files with 57 additions and 28 deletions

View File

@ -105,8 +105,9 @@ impl DrmBackendInternal {
I: Into<Vec<connector::Handle>>, I: Into<Vec<connector::Handle>>,
L: Into<Option<::slog::Logger>>, L: Into<Option<::slog::Logger>>,
{ {
let log = ::slog_or_stdlog(logger).new(o!("smithay_module" => "backend_drm")); // logger already initialized by the DrmDevice
info!(log, "Initializing a drm backend"); let log = ::slog_or_stdlog(logger);
info!(log, "Initializing DrmBackend");
let connectors = connectors.into(); let connectors = connectors.into();
@ -122,12 +123,8 @@ impl DrmBackendInternal {
let (w, h) = mode.size(); let (w, h) = mode.size();
info!(log, "Drm Backend initializing");
Ok(DrmBackendInternal { Ok(DrmBackendInternal {
graphics: Graphics::try_new(context, |context| { graphics: Graphics::try_new(context, |context| {
debug!(log, "GBM EGLContext initialized");
Ok(GbmTypes { Ok(GbmTypes {
cursor: { cursor: {
// Create an unused cursor buffer (we don't want an Option here) // Create an unused cursor buffer (we don't want an Option here)
@ -138,19 +135,23 @@ impl DrmBackendInternal {
&[BufferObjectFlags::Cursor, BufferObjectFlags::Write], &[BufferObjectFlags::Cursor, BufferObjectFlags::Write],
)? )?
}, },
surface: Surface::try_new( surface: Surface::try_new({
// create a gbm surface debug!(log, "Creating GbmSurface");
Box::new(context.devices.gbm.create_surface( // create a gbm surface
w as u32, Box::new(context.devices.gbm.create_surface(
h as u32, w as u32,
GbmFormat::XRGB8888, h as u32,
&[BufferObjectFlags::Scanout, BufferObjectFlags::Rendering], GbmFormat::XRGB8888,
)?), &[BufferObjectFlags::Scanout, BufferObjectFlags::Rendering],
)?)
},
|surface| { |surface| {
// create an egl surface from the gbm one // create an egl surface from the gbm one
debug!(log, "Creating EGLSurface");
let egl_surface = context.egl.create_surface(&surface)?; let egl_surface = context.egl.create_surface(&surface)?;
// set it to be able to use `crtc::set` once // make it active for the first `crtc::set`
// (which is needed before the first page_flip)
unsafe { egl_surface.make_current()? }; unsafe { egl_surface.make_current()? };
egl_surface.swap_buffers()?; egl_surface.swap_buffers()?;
@ -160,6 +161,8 @@ impl DrmBackendInternal {
debug!(log, "FrontBuffer color format: {:?}", front_bo.format()); debug!(log, "FrontBuffer color format: {:?}", front_bo.format());
// we need a framebuffer per front buffer // we need a framebuffer per front buffer
let fb = framebuffer::create(context.devices.drm, &*front_bo)?; let fb = framebuffer::create(context.devices.drm, &*front_bo)?;
debug!(log, "Initialize screen");
crtc::set( crtc::set(
context.devices.drm, context.devices.drm,
crtc, crtc,
@ -197,6 +200,7 @@ impl DrmBackendInternal {
let next_bo = egl.buffers.next_buffer.replace(None); let next_bo = egl.buffers.next_buffer.replace(None);
if let Some(next_buffer) = next_bo { if let Some(next_buffer) = next_bo {
trace!(self.logger, "Releasing all front buffer");
egl.buffers.front_buffer.set(next_buffer); egl.buffers.front_buffer.set(next_buffer);
// drop and release the old buffer // drop and release the old buffer
} else { } else {
@ -225,6 +229,7 @@ impl DrmBackend {
// check if the connector can handle the current mode // check if the connector can handle the current mode
let mut internal = self.0.borrow_mut(); let mut internal = self.0.borrow_mut();
if info.modes().contains(&internal.mode) { if info.modes().contains(&internal.mode) {
info!(self.0.borrow().logger, "Adding new connector: {:?}", info.connector_type());
internal.connectors.push(connector); internal.connectors.push(connector);
Ok(()) Ok(())
} else { } else {
@ -240,6 +245,12 @@ impl DrmBackend {
/// Removes a currently set connector /// Removes a currently set connector
pub fn remove_connector(&mut self, connector: connector::Handle) { pub fn remove_connector(&mut self, connector: connector::Handle) {
if let Ok(info) = connector::Info::load_from_device(self.0.borrow().graphics.head().head().head(), connector) {
info!(self.0.borrow().logger, "Removing connector: {:?}", info.connector_type());
} else {
info!(self.0.borrow().logger, "Removeing unknown connector");
}
self.0.borrow_mut().connectors.retain(|x| *x != connector); self.0.borrow_mut().connectors.retain(|x| *x != connector);
} }
@ -275,17 +286,23 @@ impl DrmBackend {
.rent_all_mut(|graphics| -> Result<(), DrmError> { .rent_all_mut(|graphics| -> Result<(), DrmError> {
// Recreate the surface and the related resources to match the new // Recreate the surface and the related resources to match the new
// resolution. // resolution.
graphics.gbm.surface = Surface::try_new( debug!(logger, "Reinitializing surface for new mode: {}:{}", w, h);
Box::new(graphics.context.devices.gbm.create_surface( graphics.gbm.surface = Surface::try_new({
w as u32, // create a new gbm surface
h as u32, debug!(logger, "Creating GbmSurface");
GbmFormat::XRGB8888, Box::new(graphics.context.devices.gbm.create_surface(
&[BufferObjectFlags::Scanout, BufferObjectFlags::Rendering], w as u32,
)?), h as u32,
GbmFormat::XRGB8888,
&[BufferObjectFlags::Scanout, BufferObjectFlags::Rendering],
)?)
},
|surface| { |surface| {
// create an egl surface from the gbm one
debug!(logger, "Creating EGLSurface");
let egl_surface = graphics.context.egl.create_surface(&surface)?; let egl_surface = graphics.context.egl.create_surface(&surface)?;
// make it active for the first crtc::set // make it active for the first `crtc::set`
// (which is needed before the first page_flip) // (which is needed before the first page_flip)
unsafe { egl_surface.make_current()? }; unsafe { egl_surface.make_current()? };
egl_surface.swap_buffers()?; egl_surface.swap_buffers()?;
@ -294,7 +311,8 @@ impl DrmBackend {
debug!(logger, "FrontBuffer color format: {:?}", front_bo.format()); debug!(logger, "FrontBuffer color format: {:?}", front_bo.format());
// we need a framebuffer per front_buffer // we need a framebuffer per front_buffer
let fb = framebuffer::create(graphics.context.devices.drm, &*front_bo)?; let fb = framebuffer::create(graphics.context.devices.drm, &*front_bo)?;
// init the first screen
debug!(logger, "Initialize screen");
crtc::set( crtc::set(
graphics.context.devices.drm, graphics.context.devices.drm,
crtc, crtc,
@ -318,6 +336,7 @@ impl DrmBackend {
Ok(()) Ok(())
})?; })?;
info!(logger, "Setting new mode: {:?}", mode.name());
internal.mode = mode; internal.mode = mode;
Ok(()) Ok(())
} }
@ -336,6 +355,7 @@ impl GraphicsBackend for DrmBackend {
type Error = DrmError; type Error = DrmError;
fn set_cursor_position(&self, x: u32, y: u32) -> Result<(), DrmError> { fn set_cursor_position(&self, x: u32, y: u32) -> Result<(), DrmError> {
trace!(self.0.borrow().logger, "Move the cursor to {},{}", x, y);
crtc::move_cursor( crtc::move_cursor(
self.0.borrow().graphics.head().head().head(), self.0.borrow().graphics.head().head().head(),
self.0.borrow().crtc, self.0.borrow().crtc,
@ -346,6 +366,7 @@ impl GraphicsBackend for DrmBackend {
fn set_cursor_representation(&self, buffer: ImageBuffer<Rgba<u8>, Vec<u8>>, hotspot: (u32, u32)) fn set_cursor_representation(&self, buffer: ImageBuffer<Rgba<u8>, Vec<u8>>, hotspot: (u32, u32))
-> Result<(), DrmError> { -> Result<(), DrmError> {
let (w, h) = buffer.dimensions(); let (w, h) = buffer.dimensions();
debug!(self.0.borrow().logger, "Importing cursor");
/// import the cursor into a buffer we can render /// import the cursor into a buffer we can render
self.0 self.0
.borrow_mut() .borrow_mut()
@ -364,6 +385,7 @@ impl GraphicsBackend for DrmBackend {
Ok(()) Ok(())
})?; })?;
trace!(self.0.borrow().logger, "Set the new imported cursor");
// and set it // and set it
if crtc::set_cursor2( if crtc::set_cursor2(
self.0.borrow().graphics.head().head().head(), self.0.borrow().graphics.head().head().head(),
@ -401,6 +423,7 @@ impl EGLGraphicsBackend for DrmBackend {
egl.buffers.next_buffer.set(next); egl.buffers.next_buffer.set(next);
res res
}) { }) {
warn!(self.0.borrow().logger, "Tried to swap a DrmBackend with a queued flip");
return Err(SwapBuffersError::AlreadySwapped); return Err(SwapBuffersError::AlreadySwapped);
} }
@ -426,7 +449,7 @@ impl EGLGraphicsBackend for DrmBackend {
}; };
surface.egl.buffers.next_buffer.set(Some(next_bo)); surface.egl.buffers.next_buffer.set(Some(next_bo));
trace!(self.0.borrow().logger, "Page flip queued"); trace!(self.0.borrow().logger, "Queueing Page flip");
let id: Id = self.0.borrow().own_id; let id: Id = self.0.borrow().own_id;

View File

@ -298,7 +298,7 @@ impl<H: DrmHandler + 'static> DrmDevice<H> {
where where
L: Into<Option<::slog::Logger>>, L: Into<Option<::slog::Logger>>,
{ {
let log = ::slog_or_stdlog(logger).new(o!("smithay_module" => "backend_drm", "drm" => "device")); let log = ::slog_or_stdlog(logger).new(o!("smithay_module" => "backend_drm"));
/* GBM will load a dri driver, but even though they need symbols from /* GBM will load a dri driver, but even though they need symbols from
* libglapi, in some version of Mesa they are not linked to it. Since * libglapi, in some version of Mesa they are not linked to it. Since
@ -313,13 +313,17 @@ impl<H: DrmHandler + 'static> DrmDevice<H> {
); );
} }
info!(log, "DrmDevice initializing");
// Open the gbm device from the drm device and create a context based on that // Open the gbm device from the drm device and create a context based on that
Ok(DrmDevice { Ok(DrmDevice {
context: Rc::new(Context::try_new( context: Rc::new(Context::try_new(
Box::new(Devices::try_new(Box::new(drm), |drm| { Box::new(Devices::try_new(Box::new(drm), |drm| {
debug!(log, "Creating gbm device");
GbmDevice::new_from_drm::<DrmDevice<H>>(drm).map_err(DrmError::from) GbmDevice::new_from_drm::<DrmDevice<H>>(drm).map_err(DrmError::from)
})?), })?),
|devices| { |devices| {
debug!(log, "Creating egl context from gbm device");
EGLContext::new_from_gbm( EGLContext::new_from_gbm(
devices.gbm, devices.gbm,
attributes, attributes,
@ -357,9 +361,9 @@ impl<H: DrmHandler + 'static> DrmDevice<H> {
} }
} }
let logger = self.logger
.new(o!("drm" => "backend", "crtc" => format!("{:?}", crtc)));
let own_id = self.backends.len(); let own_id = self.backends.len();
let logger = self.logger
.new(o!("id" => format!("{}", own_id), "crtc" => format!("{:?}", crtc)));
let backend = Rc::new(RefCell::new(DrmBackendInternal::new( let backend = Rc::new(RefCell::new(DrmBackendInternal::new(
self.context.clone(), self.context.clone(),
@ -435,6 +439,7 @@ impl<H: DrmHandler + 'static> FdEventSourceHandler for DrmDevice<H> {
let id: Id = *userdata.downcast().unwrap(); let id: Id = *userdata.downcast().unwrap();
if let Some(backend) = self.0.backends[id.raw()].upgrade() { if let Some(backend) = self.0.backends[id.raw()].upgrade() {
// we can now unlock the buffer // we can now unlock the buffer
trace!(self.0.logger, "Handling event for backend {:?}", id.raw());
backend.borrow().unlock_buffer(); backend.borrow().unlock_buffer();
if let Some(handler) = self.0.handler.as_mut() { if let Some(handler) = self.0.handler.as_mut() {
// and then call the user to render the next frame // and then call the user to render the next frame
@ -455,6 +460,7 @@ impl<H: DrmHandler + 'static> FdEventSourceHandler for DrmDevice<H> {
fn error(&mut self, evlh: &mut EventLoopHandle, _fd: RawFd, error: IoError) { fn error(&mut self, evlh: &mut EventLoopHandle, _fd: RawFd, error: IoError) {
if let Some(handler) = self.handler.as_mut() { if let Some(handler) = self.handler.as_mut() {
warn!(self.logger, "DrmDevice errored: {}", error);
handler.error(evlh, error) handler.error(evlh, error)
} }
} }