From a7469062a2b25541cfe887f55441284553659ea0 Mon Sep 17 00:00:00 2001 From: Kaiyi Li Date: Tue, 5 May 2020 14:07:36 -0700 Subject: Extract the DisplayBackend build process into BackendKind build function All 3 different virtio gpu backends share the same process of creating the GpuDisplay instance, so move that process out of their separate build functions and put it in the shared BackendKind build function. BUG=None TEST=build_test Change-Id: Ie15bae48c8f1b75df49ba066a677020ec5dbf744 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2182041 Reviewed-by: Jason Macnak Reviewed-by: Zach Reizner Tested-by: kokoro Commit-Queue: Kaiyi Li --- gpu_display/src/lib.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'gpu_display') diff --git a/gpu_display/src/lib.rs b/gpu_display/src/lib.rs index 07358a0..dccf1c7 100644 --- a/gpu_display/src/lib.rs +++ b/gpu_display/src/lib.rs @@ -171,6 +171,7 @@ trait DisplayT: AsRawFd { /// descriptor. When the connection is readable, `dispatch_events` can be called to process it. pub struct GpuDisplay { inner: Box, + is_x: bool, } impl GpuDisplay { @@ -183,7 +184,7 @@ impl GpuDisplay { None => gpu_display_x::DisplayX::open_display(None)?, }; let inner = Box::new(display); - Ok(GpuDisplay { inner }) + Ok(GpuDisplay { inner, is_x: true }) } #[cfg(not(feature = "x"))] Err(GpuDisplayError::Unsupported) @@ -198,13 +199,18 @@ impl GpuDisplay { None => gpu_display_wl::DisplayWl::new(None)?, }; let inner = Box::new(display); - Ok(GpuDisplay { inner }) + Ok(GpuDisplay { inner, is_x: false }) } pub fn open_stub() -> Result { let display = gpu_display_stub::DisplayStub::new()?; let inner = Box::new(display); - Ok(GpuDisplay { inner }) + Ok(GpuDisplay { inner, is_x: false }) + } + + /// Return whether this display is an X display + pub fn is_x(&self) -> bool { + self.is_x } /// Imports a dmabuf to the compositor for use as a surface buffer and returns a handle to it. -- cgit 1.4.1