gpui: Add wgpu Surface element and GPU device requirements API for Linux (#39)
This commit is contained in:
@@ -180,6 +180,7 @@ pub struct X11ClientState {
|
||||
|
||||
pub(crate) gpu_context: GpuContext,
|
||||
pub(crate) compositor_gpu: Option<CompositorGpuHint>,
|
||||
pub(crate) gpu_requirements: Option<gpui_wgpu::WgpuDeviceRequirements>,
|
||||
|
||||
pub(crate) scale_factor: f32,
|
||||
|
||||
@@ -523,6 +524,7 @@ impl X11Client {
|
||||
pinch_scale: 1.0,
|
||||
gpu_context: Rc::new(RefCell::new(None)),
|
||||
compositor_gpu,
|
||||
gpu_requirements: None,
|
||||
scale_factor,
|
||||
|
||||
xkb_context,
|
||||
@@ -1586,6 +1588,14 @@ impl LinuxClient for X11Client {
|
||||
gpui::scap_screen_capture::scap_screen_sources(&self.0.borrow().common.foreground_executor)
|
||||
}
|
||||
|
||||
fn set_gpu_requirements(&self, requirements: Box<dyn std::any::Any>) {
|
||||
if let Ok(reqs) = requirements.downcast::<gpui_wgpu::WgpuDeviceRequirements>() {
|
||||
self.0.borrow_mut().gpu_requirements = Some(*reqs);
|
||||
} else {
|
||||
log::warn!("set_gpu_requirements: unexpected type, expected WgpuDeviceRequirements");
|
||||
}
|
||||
}
|
||||
|
||||
fn open_window(
|
||||
&self,
|
||||
handle: AnyWindowHandle,
|
||||
@@ -1608,6 +1618,7 @@ impl LinuxClient for X11Client {
|
||||
let scale_factor = state.scale_factor;
|
||||
let appearance = state.common.appearance;
|
||||
let compositor_gpu = state.compositor_gpu.take();
|
||||
let gpu_requirements = state.gpu_requirements.clone();
|
||||
let supports_xinput_gestures = state.supports_xinput_gestures;
|
||||
let is_bgr = state
|
||||
.resource_database
|
||||
@@ -1619,6 +1630,7 @@ impl LinuxClient for X11Client {
|
||||
state.common.foreground_executor.clone(),
|
||||
state.gpu_context.clone(),
|
||||
compositor_gpu,
|
||||
gpu_requirements,
|
||||
params,
|
||||
&xcb_connection,
|
||||
client_side_decorations_supported,
|
||||
|
||||
@@ -416,6 +416,7 @@ impl X11WindowState {
|
||||
executor: ForegroundExecutor,
|
||||
gpu_context: gpui_wgpu::GpuContext,
|
||||
compositor_gpu: Option<CompositorGpuHint>,
|
||||
gpu_requirements: Option<gpui_wgpu::WgpuDeviceRequirements>,
|
||||
params: WindowParams,
|
||||
xcb: &Rc<XCBConnection>,
|
||||
client_side_decorations_supported: bool,
|
||||
@@ -724,7 +725,13 @@ impl X11WindowState {
|
||||
transparent: false,
|
||||
preferred_present_mode: None,
|
||||
};
|
||||
WgpuRenderer::new(gpu_context, &raw_window, config, compositor_gpu)?
|
||||
WgpuRenderer::new(
|
||||
gpu_context,
|
||||
&raw_window,
|
||||
config,
|
||||
compositor_gpu,
|
||||
gpu_requirements,
|
||||
)?
|
||||
};
|
||||
|
||||
renderer.set_subpixel_layout(is_bgr);
|
||||
@@ -878,6 +885,7 @@ impl X11Window {
|
||||
executor: ForegroundExecutor,
|
||||
gpu_context: gpui_wgpu::GpuContext,
|
||||
compositor_gpu: Option<CompositorGpuHint>,
|
||||
gpu_requirements: Option<gpui_wgpu::WgpuDeviceRequirements>,
|
||||
params: WindowParams,
|
||||
xcb: &Rc<XCBConnection>,
|
||||
client_side_decorations_supported: bool,
|
||||
@@ -897,6 +905,7 @@ impl X11Window {
|
||||
executor,
|
||||
gpu_context,
|
||||
compositor_gpu,
|
||||
gpu_requirements,
|
||||
params,
|
||||
xcb,
|
||||
client_side_decorations_supported,
|
||||
@@ -1887,6 +1896,11 @@ impl PlatformWindow for X11Window {
|
||||
self.0.state.borrow().renderer.gpu_specs().into()
|
||||
}
|
||||
|
||||
fn gpu_context(&self) -> Option<Box<dyn std::any::Any>> {
|
||||
let (device, queue) = self.0.state.borrow().renderer.gpu_context();
|
||||
Some(Box::new((device, queue)))
|
||||
}
|
||||
|
||||
fn play_system_bell(&self) {
|
||||
// Volume 0% means don't increase or decrease from system volume
|
||||
let _ = self.0.xcb.bell(0);
|
||||
|
||||
Reference in New Issue
Block a user