Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 17 additions & 15 deletions src/angle/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//! implicit in the Win32 API, and as such this type is a no-op.

use super::adapter::AngleAdapter;
use super::device::{Device, NativeDevice, VendorPreference};
use super::device::{AngleDevice, NativeDevice, VendorPreference};
use crate::egl::types::EGLDisplay;
use crate::{Adapter, AdapterPreferences, Error, GLApi, PowerPreference, RenderingPreference};

Expand All @@ -22,7 +22,7 @@ const INTEL_PCI_ID: UINT = 0x8086;
/// thread-safe. So we need to use the DXGI/Direct3D concept of a connection instead. These are
/// implicit in the Win32 API, and as such this type is a no-op.
#[derive(Clone)]
pub struct Connection;
pub struct AngleConnection;

/// An empty placeholder for native connections.
///
Expand All @@ -33,17 +33,17 @@ pub struct Connection;
#[derive(Clone)]
pub struct NativeConnection;

impl Connection {
impl AngleConnection {
/// Connects to the default display.
#[inline]
pub fn new() -> Result<Connection, Error> {
Ok(Connection)
pub fn new() -> Result<AngleConnection, Error> {
Ok(AngleConnection)
}

/// An alias for `Connection::new()`, present for consistency with other backends.
#[inline]
pub unsafe fn from_native_connection(_: NativeConnection) -> Result<Connection, Error> {
Connection::new()
pub unsafe fn from_native_connection(_: NativeConnection) -> Result<AngleConnection, Error> {
AngleConnection::new()
}

/// Returns the underlying native connection.
Expand Down Expand Up @@ -76,17 +76,17 @@ impl Connection {
///
/// Device handles are local to a single thread.
#[inline]
pub fn create_device(&self, adapter: &Adapter) -> Result<Device, Error> {
Device::new(adapter.angle()?)
pub fn create_device(&self, adapter: &Adapter) -> Result<AngleDevice, Error> {
AngleDevice::new(adapter.angle()?)
}

/// Wraps a `NativeDevice` in a `Device` and returns it.
#[inline]
pub unsafe fn create_device_from_native_device(
&self,
native_device: NativeDevice,
) -> Result<Device, Error> {
Device::from_native_device(native_device)
) -> Result<AngleDevice, Error> {
AngleDevice::from_native_device(native_device)
}

/// Wraps an ANGLE `EGLDisplay`, along with the associated Direct3D device, in a `Device` and
Expand All @@ -99,13 +99,15 @@ impl Connection {
pub unsafe fn create_device_from_egl_display(
&self,
egl_display: EGLDisplay,
) -> Result<Device, Error> {
Device::from_egl_display(egl_display)
) -> Result<AngleDevice, Error> {
AngleDevice::from_egl_display(egl_display)
}

/// Opens the display connection corresponding to the given `DisplayHandle`.
pub fn from_display_handle(_: raw_window_handle::DisplayHandle) -> Result<Connection, Error> {
Connection::new()
pub fn from_display_handle(
_: raw_window_handle::DisplayHandle,
) -> Result<AngleConnection, Error> {
AngleConnection::new()
}
}

Expand Down
18 changes: 9 additions & 9 deletions src/angle/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const SURFACE_GL_TEXTURE_TARGET: u32 = gl::TEXTURE_2D;
/// A thread-local handle to a device.
///
/// Devices contain most of the relevant surface management methods.
pub struct Device {
pub struct AngleDevice {
pub(crate) egl_display: EGLDisplay,
pub(crate) d3d11_device: ComPtr<ID3D11Device>,
pub(crate) d3d_driver_type: D3D_DRIVER_TYPE,
Expand All @@ -72,9 +72,9 @@ pub struct NativeDevice {
pub d3d_driver_type: D3D_DRIVER_TYPE,
}

impl Device {
impl AngleDevice {
#[allow(non_snake_case)]
pub(crate) fn new(adapter: &AngleAdapter) -> Result<Device, Error> {
pub(crate) fn new(adapter: &AngleAdapter) -> Result<AngleDevice, Error> {
let d3d_driver_type = adapter.d3d_driver_type;
unsafe {
let mut d3d11_device = ptr::null_mut();
Expand Down Expand Up @@ -126,7 +126,7 @@ impl Device {
let result = egl.Initialize(egl_display, &mut major_version, &mut minor_version);
assert_ne!(result, egl::FALSE);

Ok(Device {
Ok(AngleDevice {
egl_display,
d3d11_device,
d3d_driver_type,
Expand All @@ -136,10 +136,10 @@ impl Device {
}
}

pub(crate) fn from_native_device(native_device: NativeDevice) -> Result<Device, Error> {
pub(crate) fn from_native_device(native_device: NativeDevice) -> Result<AngleDevice, Error> {
unsafe {
(*native_device.d3d11_device).AddRef();
Ok(Device {
Ok(AngleDevice {
egl_display: native_device.egl_display,
d3d11_device: ComPtr::from_raw(native_device.d3d11_device),
d3d_driver_type: native_device.d3d_driver_type,
Expand All @@ -149,7 +149,7 @@ impl Device {
}

#[allow(non_snake_case)]
pub(crate) fn from_egl_display(egl_display: EGLDisplay) -> Result<Device, Error> {
pub(crate) fn from_egl_display(egl_display: EGLDisplay) -> Result<AngleDevice, Error> {
let eglQueryDisplayAttribEXT = EGL_EXTENSION_FUNCTIONS
.QueryDisplayAttribEXT
.expect("Where's the `EGL_EXT_device_query` extension?");
Expand Down Expand Up @@ -178,7 +178,7 @@ impl Device {

unsafe {
(*d3d11_device).AddRef();
Ok(Device {
Ok(AngleDevice {
egl_display: egl_display,
d3d11_device: ComPtr::from_raw(d3d11_device),
d3d_driver_type: D3D_DRIVER_TYPE_UNKNOWN,
Expand Down Expand Up @@ -1102,7 +1102,7 @@ impl Device {
}
}

impl Drop for Device {
impl Drop for AngleDevice {
fn drop(&mut self) {
unsafe {
if self.display_is_owned {
Expand Down
6 changes: 5 additions & 1 deletion src/angle/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@ pub mod context;
pub mod device;
pub mod surface;

crate::implement_interfaces!();
crate::implement_interfaces!(AngleConnection, AngleDevice);

#[cfg(test)]
use self::connection::AngleConnection as Connection;
#[cfg(test)]
use self::device::AngleDevice as Device;
#[cfg(test)]
#[path = "../tests.rs"]
mod tests;
4 changes: 2 additions & 2 deletions src/angle/surface.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Surface management for Direct3D 11 on Windows using the ANGLE library as a frontend.

use super::device::Device;
use super::device::AngleDevice;
use crate::base::egl::device::EGL_FUNCTIONS;
use crate::context::ContextID;
use crate::egl::types::EGLSurface;
Expand Down Expand Up @@ -98,7 +98,7 @@ impl AngleSurface {
}
}

pub(crate) fn present(&self, device: &Device) -> Result<(), Error> {
pub(crate) fn present(&self, device: &AngleDevice) -> Result<(), Error> {
match self.win32_objects {
Win32Objects::Window { .. } => {}
_ => return Err(Error::NoWidgetAttached),
Expand Down
26 changes: 13 additions & 13 deletions src/cgl/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//! Connection types are zero-sized on macOS, because the system APIs automatically manage the
//! global window server connection.

use super::device::Device;
use super::device::CglDevice;
use crate::adapter::{Adapter, AdapterPreferences};
use crate::base::io_surface::connection::Connection as SystemConnection;
use crate::base::io_surface::device::NativeDevice;
Expand All @@ -14,21 +14,21 @@ pub use crate::base::io_surface::connection::NativeConnection;

/// A connection to the display server.
#[derive(Clone)]
pub struct Connection(pub SystemConnection);
pub struct CglConnection(pub SystemConnection);

impl Connection {
impl CglConnection {
/// Connects to the default display.
#[inline]
pub fn new() -> Result<Connection, Error> {
SystemConnection::new().map(Connection)
pub fn new() -> Result<CglConnection, Error> {
SystemConnection::new().map(CglConnection)
}

/// An alias for `Connection::new()`, present for consistency with other backends.
#[inline]
pub unsafe fn from_native_connection(
native_connection: NativeConnection,
) -> Result<Connection, Error> {
SystemConnection::from_native_connection(native_connection).map(Connection)
) -> Result<CglConnection, Error> {
SystemConnection::from_native_connection(native_connection).map(CglConnection)
}

/// Returns the underlying native connection.
Expand All @@ -53,25 +53,25 @@ impl Connection {
///
/// Device handles are local to a single thread.
#[inline]
pub fn create_device(&self, adapter: &Adapter) -> Result<Device, Error> {
self.0.create_device(adapter.apple()?).map(Device)
pub fn create_device(&self, adapter: &Adapter) -> Result<CglDevice, Error> {
self.0.create_device(adapter.apple()?).map(CglDevice)
}

/// An alias for `connection.create_device()` with the default adapter.
#[inline]
pub unsafe fn create_device_from_native_device(
&self,
native_device: NativeDevice,
) -> Result<Device, Error> {
) -> Result<CglDevice, Error> {
self.0
.create_device_from_native_device(native_device)
.map(Device)
.map(CglDevice)
}

/// Opens the display connection corresponding to the given `DisplayHandle`.
pub fn from_display_handle(
handle: raw_window_handle::DisplayHandle,
) -> Result<Connection, Error> {
SystemConnection::from_display_handle(handle).map(Connection)
) -> Result<CglConnection, Error> {
SystemConnection::from_display_handle(handle).map(CglConnection)
}
}
4 changes: 2 additions & 2 deletions src/cgl/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ thread_local! {
///
/// Devices contain most of the relevant surface management methods.
#[derive(Clone)]
pub struct Device(pub(crate) SystemDevice);
pub struct CglDevice(pub(crate) SystemDevice);

impl Device {
impl CglDevice {
/// Returns the native device corresponding to this device.
#[inline]
pub fn native_device(&self) -> NativeDevice {
Expand Down
6 changes: 5 additions & 1 deletion src/cgl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@ pub mod surface;
mod error;
mod ffi;

crate::implement_interfaces!();
crate::implement_interfaces!(CglConnection, CglDevice);

#[cfg(test)]
use self::connection::CglConnection as Connection;
#[cfg(test)]
use self::device::CglDevice as Device;
#[cfg(test)]
#[path = "../tests.rs"]
mod tests;
30 changes: 17 additions & 13 deletions src/hardware_buffer/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,30 @@
//! FIXME(pcwalton): Should this instead wrap `EGLDisplay`? Is that thread-safe on Android?

use super::adapter::HardwareBufferAdapter;
use super::device::{Device, NativeDevice};
use super::device::{HardwareBufferDevice, NativeDevice};
use crate::{Adapter, AdapterPreferences, Error, GLApi};

/// A connection to the display server.
#[derive(Clone)]
pub struct Connection;
pub struct HardwareBufferConnection;

/// An empty placeholder for native connections.
#[derive(Clone)]
pub struct NativeConnection;

impl Connection {
impl HardwareBufferConnection {
/// Connects to the default display.
#[inline]
pub fn new() -> Result<Connection, Error> {
Ok(Connection)
pub fn new() -> Result<HardwareBufferConnection, Error> {
Ok(HardwareBufferConnection)
}

/// An alias for `Connection::new()`, present for consistency with other backends.
#[inline]
pub unsafe fn from_native_connection(_: NativeConnection) -> Result<Connection, Error> {
Connection::new()
pub unsafe fn from_native_connection(
_: NativeConnection,
) -> Result<HardwareBufferConnection, Error> {
HardwareBufferConnection::new()
}

/// Returns the underlying native connection.
Expand All @@ -49,8 +51,8 @@ impl Connection {
///
/// Device handles are local to a single thread.
#[inline]
pub fn create_device(&self, _: &Adapter) -> Result<Device, Error> {
Device::new()
pub fn create_device(&self, _: &Adapter) -> Result<HardwareBufferDevice, Error> {
HardwareBufferDevice::new()
}

/// Wraps an Android `EGLDisplay` in a device and returns it.
Expand All @@ -62,16 +64,18 @@ impl Connection {
pub unsafe fn create_device_from_native_device(
&self,
native_device: NativeDevice,
) -> Result<Device, Error> {
Ok(Device {
) -> Result<HardwareBufferDevice, Error> {
Ok(HardwareBufferDevice {
egl_display: native_device.0,
display_is_owned: false,
})
}

/// Opens the display connection corresponding to the given `DisplayHandle`.
pub fn from_display_handle(_: raw_window_handle::DisplayHandle) -> Result<Connection, Error> {
Ok(Connection)
pub fn from_display_handle(
_: raw_window_handle::DisplayHandle,
) -> Result<HardwareBufferConnection, Error> {
Ok(HardwareBufferConnection)
}
}

Expand Down
10 changes: 5 additions & 5 deletions src/hardware_buffer/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use std::os::raw::c_void;
/// A thread-local handle to a device.
///
/// Devices contain most of the relevant surface management methods.
pub struct Device {
pub struct HardwareBufferDevice {
pub(crate) egl_display: EGLDisplay,
pub(crate) display_is_owned: bool,
}
Expand All @@ -30,7 +30,7 @@ pub struct Device {
#[derive(Clone, Copy)]
pub struct NativeDevice(pub EGLDisplay);

impl Drop for Device {
impl Drop for HardwareBufferDevice {
fn drop(&mut self) {
EGL_FUNCTIONS.with(|egl| unsafe {
if !self.display_is_owned {
Expand All @@ -52,9 +52,9 @@ impl NativeDevice {
}
}

impl Device {
impl HardwareBufferDevice {
#[inline]
pub(crate) fn new() -> Result<Device, Error> {
pub(crate) fn new() -> Result<HardwareBufferDevice, Error> {
EGL_FUNCTIONS.with(|egl| {
unsafe {
let egl_display = egl.GetDisplay(egl::DEFAULT_DISPLAY);
Expand All @@ -65,7 +65,7 @@ impl Device {
let result = egl.Initialize(egl_display, &mut major_version, &mut minor_version);
assert_ne!(result, egl::FALSE);

Ok(Device {
Ok(HardwareBufferDevice {
egl_display,
display_is_owned: true,
})
Expand Down
Loading
Loading