From ab827ab177971b5f0f948d1c1feb3c6e5ff481eb Mon Sep 17 00:00:00 2001 From: Gurchetan Singh Date: Fri, 7 Jun 2019 17:30:11 -0700 Subject: gpu_buffer: add ability to get backend name This is useful for letting the guest know about host-specific features. BUG=chromium:924405 TEST=compile Change-Id: I0edc4280eec7235644c9ad8561dbe063276bb3bd Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1650288 Reviewed-by: Zach Reizner Tested-by: kokoro Tested-by: Gurchetan Singh Commit-Queue: Gurchetan Singh --- gpu_buffer/src/lib.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'gpu_buffer/src') diff --git a/gpu_buffer/src/lib.rs b/gpu_buffer/src/lib.rs index 16aae50..53fca92 100644 --- a/gpu_buffer/src/lib.rs +++ b/gpu_buffer/src/lib.rs @@ -35,10 +35,11 @@ mod raw; pub mod rendernode; use std::cmp::min; +use std::ffi::CStr; use std::fmt::{self, Display}; use std::fs::File; use std::isize; -use std::os::raw::c_void; +use std::os::raw::{c_char, c_void}; use std::os::unix::io::{AsRawFd, FromRawFd, RawFd}; use std::ptr::null_mut; use std::rc::Rc; @@ -379,6 +380,14 @@ impl Device { } } + /// Copies and returns name of GBM backend. + pub fn get_backend_name(&self) -> String { + let backend_name: *const c_char = unsafe { gbm_device_get_backend_name(self.0.gbm) }; + let c_str: &CStr = unsafe { CStr::from_ptr(backend_name) }; + let str_slice: &str = c_str.to_str().unwrap_or(""); + str_slice.to_owned() + } + /// Creates a new buffer with the given metadata. pub fn create_buffer( &self, -- cgit 1.4.1