From 4c54523e5c009ba7c621a8f2b4592dedd56dbfe7 Mon Sep 17 00:00:00 2001 From: Alan Jeffrey Date: Wed, 25 Mar 2020 16:13:31 -0500 Subject: [PATCH] Support surfaceless back end on Linux --- surfman/src/platform/unix/default.rs | 41 +++++++++++++++++++++------- 1 file changed, 31 insertions(+), 10 deletions(-) diff --git a/surfman/src/platform/unix/default.rs b/surfman/src/platform/unix/default.rs index dbce5aa..b606921 100644 --- a/surfman/src/platform/unix/default.rs +++ b/surfman/src/platform/unix/default.rs @@ -1,23 +1,33 @@ // surfman/src/platform/unix/default.rs // -//! The default backend for Unix, which dynamically switches between Wayland and X11. +//! The default backend for Unix, which dynamically switches between Wayland, X11 and surfaceless. /// Wayland or X11 display server connections. pub mod connection { use crate::platform::generic::multi::connection::Connection as MultiConnection; + use crate::platform::generic::multi::connection::NativeConnection as MultiNativeConnection; use crate::platform::unix::wayland::device::Device as WaylandDevice; use crate::platform::unix::x11::device::Device as X11Device; + use crate::platform::unix::generic::device::Device as SWDevice; + use crate::platform::generic::multi::device::Device as MultiDevice; + type HWDevice = MultiDevice; /// Either a Wayland or an X11 display server connection. - pub type Connection = MultiConnection; + pub type Connection = MultiConnection; + + pub type NativeConnection = MultiNativeConnection; } /// OpenGL rendering contexts. pub mod context { use crate::platform::generic::multi::context::Context as MultiContext; use crate::platform::generic::multi::context::ContextDescriptor as MultiContextDescriptor; + use crate::platform::generic::multi::context::NativeContext as MultiNativeContext; use crate::platform::unix::wayland::device::Device as WaylandDevice; use crate::platform::unix::x11::device::Device as X11Device; + use crate::platform::unix::generic::device::Device as SWDevice; + use crate::platform::generic::multi::device::Device as MultiDevice; + type HWDevice = MultiDevice; /// Represents an OpenGL rendering context. /// @@ -36,31 +46,39 @@ pub mod context { /// allow for sharing of texture data. Contexts are local to a single thread and device. /// /// A context must be explicitly destroyed with `destroy_context()`, or a panic will occur. - pub type Context = MultiContext; + pub type Context = MultiContext; /// Information needed to create a context. Some APIs call this a "config" or a "pixel format". /// /// These are local to a device. - pub type ContextDescriptor = MultiContextDescriptor; + pub type ContextDescriptor = MultiContextDescriptor; + + pub type NativeContext = MultiNativeContext; } /// Thread-local handles to devices. pub mod device { use crate::platform::generic::multi::device::Adapter as MultiAdapter; - use crate::platform::generic::multi::device::Device as MultiDevice; + use crate::platform::generic::multi::device::NativeDevice as MultiNativeDevice; use crate::platform::unix::wayland::device::Device as WaylandDevice; use crate::platform::unix::x11::device::Device as X11Device; + use crate::platform::unix::generic::device::Device as SWDevice; + + use crate::platform::generic::multi::device::Device as MultiDevice; + type HWDevice = MultiDevice; /// Represents a hardware display adapter that can be used for rendering (including the CPU). /// /// Adapters can be sent between threads. To render with an adapter, open a thread-local /// `Device`. - pub type Adapter = MultiAdapter; + pub type Adapter = MultiAdapter; /// A thread-local handle to a device. /// /// Devices contain most of the relevant surface management methods. - pub type Device = MultiDevice; + pub type Device = MultiDevice; + + pub type NativeDevice = MultiNativeDevice; } /// Hardware buffers of pixels. @@ -70,9 +88,12 @@ pub mod surface { use crate::platform::generic::multi::surface::SurfaceTexture as MultiSurfaceTexture; use crate::platform::unix::wayland::device::Device as WaylandDevice; use crate::platform::unix::x11::device::Device as X11Device; + use crate::platform::unix::generic::device::Device as SWDevice; + use crate::platform::generic::multi::device::Device as MultiDevice; + type HWDevice = MultiDevice; /// A wrapper for a Wayland surface or an X11 `Window`, as appropriate. - pub type NativeWidget = MultiNativeWidget; + pub type NativeWidget = MultiNativeWidget; /// Represents a hardware buffer of pixels that can be rendered to via the CPU or GPU and /// either displayed in a native widget or bound to a texture for reading. @@ -90,7 +111,7 @@ pub mod surface { /// Depending on the platform, each surface may be internally double-buffered. /// /// Surfaces must be destroyed with the `destroy_surface()` method, or a panic will occur. - pub type Surface = MultiSurface; + pub type Surface = MultiSurface; /// Represents an OpenGL texture that wraps a surface. /// @@ -101,7 +122,7 @@ pub mod surface { /// Surface textures are local to a context, but that context does not have to be the same /// context as that associated with the underlying surface. The texture must be destroyed with /// the `destroy_surface_texture()` method, or a panic will occur. - pub type SurfaceTexture = MultiSurfaceTexture; + pub type SurfaceTexture = MultiSurfaceTexture; // FIXME(pcwalton): Revamp how this works. #[doc(hidden)]