diff --git a/src/implementation/connection.rs b/src/implementation/connection.rs deleted file mode 100644 index 7324dc7b..00000000 --- a/src/implementation/connection.rs +++ /dev/null @@ -1,113 +0,0 @@ -// surfman/surfman/src/implementation/connection.rs -// -//! This is an included private module that automatically produces the implementation of the -//! `Connection` trait for a backend. - -use super::super::connection::{Connection, NativeConnection}; -use super::super::device::{Adapter, Device, NativeDevice}; -use super::super::surface::NativeWidget; -use crate::connection::Connection as ConnectionInterface; -use crate::info::GLApi; -use crate::Error; - -use euclid::default::Size2D; - -use std::os::raw::c_void; - -#[deny(unconditional_recursion)] -impl ConnectionInterface for Connection { - type Adapter = Adapter; - type Device = Device; - type NativeConnection = NativeConnection; - type NativeDevice = NativeDevice; - type NativeWidget = NativeWidget; - - #[inline] - fn new() -> Result { - Connection::new() - } - - #[inline] - fn native_connection(&self) -> Self::NativeConnection { - Connection::native_connection(self) - } - - #[inline] - fn gl_api(&self) -> GLApi { - Connection::gl_api(self) - } - - #[inline] - fn create_adapter(&self) -> Result { - Connection::create_adapter(self) - } - - #[inline] - fn create_hardware_adapter(&self) -> Result { - Connection::create_hardware_adapter(self) - } - - #[inline] - fn create_low_power_adapter(&self) -> Result { - Connection::create_low_power_adapter(self) - } - - #[inline] - fn create_software_adapter(&self) -> Result { - Connection::create_software_adapter(self) - } - - #[inline] - fn create_device(&self, adapter: &Adapter) -> Result { - Connection::create_device(self, adapter) - } - - #[inline] - unsafe fn create_device_from_native_device( - &self, - native_device: Self::NativeDevice, - ) -> Result { - Connection::create_device_from_native_device(self, native_device) - } - - #[inline] - #[cfg(feature = "sm-raw-window-handle-05")] - fn from_raw_display_handle(raw_handle: rwh_05::RawDisplayHandle) -> Result { - Connection::from_raw_display_handle(raw_handle) - } - - #[inline] - #[cfg(feature = "sm-raw-window-handle-06")] - fn from_display_handle(handle: rwh_06::DisplayHandle) -> Result { - Connection::from_display_handle(handle) - } - - #[inline] - unsafe fn create_native_widget_from_ptr( - &self, - raw: *mut c_void, - size: Size2D, - ) -> NativeWidget { - Connection::create_native_widget_from_ptr(self, raw, size) - } - - #[inline] - #[cfg(feature = "sm-raw-window-handle-05")] - fn create_native_widget_from_raw_window_handle( - &self, - window: rwh_05::RawWindowHandle, - size: Size2D, - ) -> Result { - Connection::create_native_widget_from_raw_window_handle(self, window, size) - } - - #[inline] - #[cfg(feature = "sm-raw-window-handle-06")] - fn create_native_widget_from_window_handle( - &self, - window: rwh_06::WindowHandle, - size: Size2D, - ) -> Result { - Connection::create_native_widget_from_window_handle(self, window, size) - } -} diff --git a/src/implementation/device.rs b/src/implementation/device.rs deleted file mode 100644 index 01c2c78b..00000000 --- a/src/implementation/device.rs +++ /dev/null @@ -1,214 +0,0 @@ -// surfman/surfman/src/implementation/device.rs -// -//! This is an included private module that automatically produces the implementation of the -//! `Device` trait for a backend. - -use super::super::connection::Connection; -use super::super::context::{Context, ContextDescriptor, NativeContext}; -use super::super::device::{Adapter, Device}; -use super::super::surface::{NativeWidget, Surface, SurfaceTexture}; -use crate::connection::Connection as ConnectionInterface; -use crate::device::Device as DeviceInterface; -use crate::gl::types::{GLenum, GLuint}; -use crate::{ContextAttributes, ContextID, Error, GLApi, SurfaceAccess, SurfaceInfo, SurfaceType}; -use euclid::default::Size2D; - -use std::os::raw::c_void; - -#[deny(unconditional_recursion)] -impl DeviceInterface for Device { - type Connection = Connection; - type Context = Context; - type ContextDescriptor = ContextDescriptor; - type NativeContext = NativeContext; - type Surface = Surface; - type SurfaceTexture = SurfaceTexture; - - // device.rs - - /// Returns the native device associated with this device. - #[inline] - fn native_device(&self) -> ::NativeDevice { - Device::native_device(self) - } - - #[inline] - fn connection(&self) -> Connection { - Device::connection(self) - } - - #[inline] - fn adapter(&self) -> Adapter { - Device::adapter(self) - } - - #[inline] - fn gl_api(&self) -> GLApi { - Device::gl_api(self) - } - - // context.rs - - #[inline] - fn create_context_descriptor( - &self, - attributes: &ContextAttributes, - ) -> Result { - Device::create_context_descriptor(self, attributes) - } - - #[inline] - fn create_context( - &mut self, - descriptor: &Self::ContextDescriptor, - share_with: Option<&Self::Context>, - ) -> Result { - Device::create_context(self, descriptor, share_with) - } - - #[inline] - unsafe fn create_context_from_native_context( - &self, - native_context: Self::NativeContext, - ) -> Result { - Device::create_context_from_native_context(self, native_context) - } - - #[inline] - fn destroy_context(&self, context: &mut Self::Context) -> Result<(), Error> { - Device::destroy_context(self, context) - } - - #[inline] - fn context_descriptor(&self, context: &Self::Context) -> Self::ContextDescriptor { - Device::context_descriptor(self, context) - } - - #[inline] - fn make_context_current(&self, context: &Self::Context) -> Result<(), Error> { - Device::make_context_current(self, context) - } - - #[inline] - fn make_no_context_current(&self) -> Result<(), Error> { - Device::make_no_context_current(self) - } - - #[inline] - fn context_descriptor_attributes( - &self, - context_descriptor: &Self::ContextDescriptor, - ) -> ContextAttributes { - Device::context_descriptor_attributes(self, context_descriptor) - } - - #[inline] - fn get_proc_address(&self, context: &Self::Context, symbol_name: &str) -> *const c_void { - Device::get_proc_address(self, context, symbol_name) - } - - #[inline] - fn bind_surface_to_context( - &self, - context: &mut Self::Context, - surface: Self::Surface, - ) -> Result<(), (Error, Self::Surface)> { - Device::bind_surface_to_context(self, context, surface) - } - - #[inline] - fn unbind_surface_from_context( - &self, - context: &mut Self::Context, - ) -> Result, Error> { - Device::unbind_surface_from_context(self, context) - } - - #[inline] - fn context_id(&self, context: &Self::Context) -> ContextID { - Device::context_id(self, context) - } - - #[inline] - fn context_surface_info(&self, context: &Self::Context) -> Result, Error> { - Device::context_surface_info(self, context) - } - - #[inline] - fn native_context(&self, context: &Self::Context) -> Self::NativeContext { - Device::native_context(self, context) - } - - // surface.rs - - #[inline] - fn create_surface( - &mut self, - context: &Self::Context, - surface_access: SurfaceAccess, - surface_type: SurfaceType, - ) -> Result { - Device::create_surface(self, context, surface_access, surface_type) - } - - #[inline] - fn create_surface_texture( - &self, - context: &mut Self::Context, - surface: Self::Surface, - ) -> Result { - Device::create_surface_texture(self, context, surface) - } - - #[inline] - fn destroy_surface( - &self, - context: &mut Self::Context, - surface: &mut Self::Surface, - ) -> Result<(), Error> { - Device::destroy_surface(self, context, surface) - } - - #[inline] - fn destroy_surface_texture( - &self, - context: &mut Self::Context, - surface_texture: Self::SurfaceTexture, - ) -> Result { - Device::destroy_surface_texture(self, context, surface_texture) - } - - #[inline] - fn surface_gl_texture_target(&self) -> GLenum { - Device::surface_gl_texture_target(self) - } - - #[inline] - fn present_surface( - &self, - context: &Self::Context, - surface: &mut Self::Surface, - ) -> Result<(), Error> { - Device::present_surface(self, context, surface) - } - - #[inline] - fn resize_surface( - &self, - context: &Context, - surface: &mut Surface, - size: Size2D, - ) -> Result<(), Error> { - Device::resize_surface(self, context, surface, size) - } - - #[inline] - fn surface_info(&self, surface: &Self::Surface) -> SurfaceInfo { - Device::surface_info(self, surface) - } - - #[inline] - fn surface_texture_object(&self, surface_texture: &Self::SurfaceTexture) -> GLuint { - Device::surface_texture_object(self, surface_texture) - } -} diff --git a/src/implementation/mod.rs b/src/implementation/mod.rs deleted file mode 100644 index db3a56a9..00000000 --- a/src/implementation/mod.rs +++ /dev/null @@ -1,7 +0,0 @@ -// surfman/surfman/src/implementation/mod.rs -// -//! This is an included private module that automatically produces the implementations of the -//! various traits for a backend. - -mod connection; -mod device; diff --git a/src/lib.rs b/src/lib.rs index d1de5fe5..8826577c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -54,6 +54,7 @@ mod surface; pub use crate::surface::{SurfaceAccess, SurfaceID, SurfaceInfo, SurfaceType, SystemSurfaceInfo}; pub mod macros; +pub(crate) use macros::implement_interfaces; #[cfg(not(any(target_os = "android", target_env = "ohos")))] pub(crate) use crate::gl::Gl; diff --git a/src/macros.rs b/src/macros.rs index 3a54be9d..36dbbf83 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -31,3 +31,328 @@ macro_rules! declare_surfman { pub static mut AmdPowerXpressRequestHighPerformance: i32 = 1; }; } + +/// Internal macro used for generating implementations of the `Connection` and `Device` traits. +macro_rules! implement_interfaces { + () => { + mod implementation { + use super::connection::{Connection, NativeConnection}; + use super::context::{Context, ContextDescriptor, NativeContext}; + use super::device::{Adapter, Device, NativeDevice}; + use super::surface::{NativeWidget, Surface, SurfaceTexture}; + use euclid::default::Size2D; + use std::os::raw::c_void; + use $crate::connection::Connection as ConnectionInterface; + use $crate::device::Device as DeviceInterface; + use $crate::gl::types::{GLenum, GLuint}; + use $crate::info::GLApi; + use $crate::Error; + use $crate::{ContextAttributes, ContextID, SurfaceAccess, SurfaceInfo, SurfaceType}; + + impl ConnectionInterface for Connection { + type Adapter = Adapter; + type Device = Device; + type NativeConnection = NativeConnection; + type NativeDevice = NativeDevice; + type NativeWidget = NativeWidget; + + #[inline] + fn new() -> Result { + Connection::new() + } + + #[inline] + fn native_connection(&self) -> Self::NativeConnection { + Connection::native_connection(self) + } + + #[inline] + fn gl_api(&self) -> GLApi { + Connection::gl_api(self) + } + + #[inline] + fn create_adapter(&self) -> Result { + Connection::create_adapter(self) + } + + #[inline] + fn create_hardware_adapter(&self) -> Result { + Connection::create_hardware_adapter(self) + } + + #[inline] + fn create_low_power_adapter(&self) -> Result { + Connection::create_low_power_adapter(self) + } + + #[inline] + fn create_software_adapter(&self) -> Result { + Connection::create_software_adapter(self) + } + + #[inline] + fn create_device(&self, adapter: &Adapter) -> Result { + Connection::create_device(self, adapter) + } + + #[inline] + unsafe fn create_device_from_native_device( + &self, + native_device: Self::NativeDevice, + ) -> Result { + Connection::create_device_from_native_device(self, native_device) + } + + #[inline] + #[cfg(feature = "sm-raw-window-handle-05")] + fn from_raw_display_handle( + raw_handle: rwh_05::RawDisplayHandle, + ) -> Result { + Connection::from_raw_display_handle(raw_handle) + } + + #[inline] + #[cfg(feature = "sm-raw-window-handle-06")] + fn from_display_handle(handle: rwh_06::DisplayHandle) -> Result { + Connection::from_display_handle(handle) + } + + #[inline] + unsafe fn create_native_widget_from_ptr( + &self, + raw: *mut c_void, + size: Size2D, + ) -> Self::NativeWidget { + Connection::create_native_widget_from_ptr(self, raw, size) + } + + #[inline] + #[cfg(feature = "sm-raw-window-handle-05")] + fn create_native_widget_from_raw_window_handle( + &self, + window: rwh_05::RawWindowHandle, + size: Size2D, + ) -> Result { + Connection::create_native_widget_from_raw_window_handle(self, window, size) + } + + #[inline] + #[cfg(feature = "sm-raw-window-handle-06")] + fn create_native_widget_from_window_handle( + &self, + window: rwh_06::WindowHandle, + size: Size2D, + ) -> Result { + Connection::create_native_widget_from_window_handle(self, window, size) + } + } + + impl DeviceInterface for Device { + type Connection = Connection; + type Context = Context; + type ContextDescriptor = ContextDescriptor; + type NativeContext = NativeContext; + type Surface = Surface; + type SurfaceTexture = SurfaceTexture; + + // device.rs + + /// Returns the native device associated with this device. + #[inline] + fn native_device(&self) -> ::NativeDevice { + Device::native_device(self) + } + + #[inline] + fn connection(&self) -> Connection { + Device::connection(self) + } + + #[inline] + fn adapter(&self) -> Adapter { + Device::adapter(self) + } + + #[inline] + fn gl_api(&self) -> GLApi { + Device::gl_api(self) + } + + // context.rs + + #[inline] + fn create_context_descriptor( + &self, + attributes: &ContextAttributes, + ) -> Result { + Device::create_context_descriptor(self, attributes) + } + + #[inline] + fn create_context( + &mut self, + descriptor: &Self::ContextDescriptor, + share_with: Option<&Self::Context>, + ) -> Result { + Device::create_context(self, descriptor, share_with) + } + + #[inline] + unsafe fn create_context_from_native_context( + &self, + native_context: Self::NativeContext, + ) -> Result { + Device::create_context_from_native_context(self, native_context) + } + + #[inline] + fn destroy_context(&self, context: &mut Self::Context) -> Result<(), Error> { + Device::destroy_context(self, context) + } + + #[inline] + fn context_descriptor(&self, context: &Self::Context) -> Self::ContextDescriptor { + Device::context_descriptor(self, context) + } + + #[inline] + fn make_context_current(&self, context: &Self::Context) -> Result<(), Error> { + Device::make_context_current(self, context) + } + + #[inline] + fn make_no_context_current(&self) -> Result<(), Error> { + Device::make_no_context_current(self) + } + + #[inline] + fn context_descriptor_attributes( + &self, + context_descriptor: &Self::ContextDescriptor, + ) -> ContextAttributes { + Device::context_descriptor_attributes(self, context_descriptor) + } + + #[inline] + fn get_proc_address( + &self, + context: &Self::Context, + symbol_name: &str, + ) -> *const c_void { + Device::get_proc_address(self, context, symbol_name) + } + + #[inline] + fn bind_surface_to_context( + &self, + context: &mut Self::Context, + surface: Self::Surface, + ) -> Result<(), (Error, Self::Surface)> { + Device::bind_surface_to_context(self, context, surface) + } + + #[inline] + fn unbind_surface_from_context( + &self, + context: &mut Self::Context, + ) -> Result, Error> { + Device::unbind_surface_from_context(self, context) + } + + #[inline] + fn context_id(&self, context: &Self::Context) -> ContextID { + Device::context_id(self, context) + } + + #[inline] + fn context_surface_info( + &self, + context: &Self::Context, + ) -> Result, Error> { + Device::context_surface_info(self, context) + } + + #[inline] + fn native_context(&self, context: &Self::Context) -> Self::NativeContext { + Device::native_context(self, context) + } + + // surface.rs + + #[inline] + fn create_surface( + &mut self, + context: &Self::Context, + surface_access: SurfaceAccess, + surface_type: SurfaceType, + ) -> Result { + Device::create_surface(self, context, surface_access, surface_type) + } + + #[inline] + fn create_surface_texture( + &self, + context: &mut Self::Context, + surface: Self::Surface, + ) -> Result { + Device::create_surface_texture(self, context, surface) + } + + #[inline] + fn destroy_surface( + &self, + context: &mut Self::Context, + surface: &mut Self::Surface, + ) -> Result<(), Error> { + Device::destroy_surface(self, context, surface) + } + + #[inline] + fn destroy_surface_texture( + &self, + context: &mut Self::Context, + surface_texture: Self::SurfaceTexture, + ) -> Result { + Device::destroy_surface_texture(self, context, surface_texture) + } + + #[inline] + fn surface_gl_texture_target(&self) -> GLenum { + Device::surface_gl_texture_target(self) + } + + #[inline] + fn present_surface( + &self, + context: &Self::Context, + surface: &mut Self::Surface, + ) -> Result<(), Error> { + Device::present_surface(self, context, surface) + } + + #[inline] + fn resize_surface( + &self, + context: &Context, + surface: &mut Surface, + size: Size2D, + ) -> Result<(), Error> { + Device::resize_surface(self, context, surface, size) + } + + #[inline] + fn surface_info(&self, surface: &Self::Surface) -> SurfaceInfo { + Device::surface_info(self, surface) + } + + #[inline] + fn surface_texture_object(&self, surface_texture: &Self::SurfaceTexture) -> GLuint { + Device::surface_texture_object(self, surface_texture) + } + } + } + }; +} + +pub(crate) use implement_interfaces; diff --git a/src/platform/egl/mod.rs b/src/platform/egl/mod.rs index bdff8c7c..da72e8c8 100644 --- a/src/platform/egl/mod.rs +++ b/src/platform/egl/mod.rs @@ -13,8 +13,7 @@ mod android_ffi; #[cfg(ohos_platform)] mod ohos_ffi; -#[path = "../../implementation/mod.rs"] -mod implementation; +crate::implement_interfaces!(); #[cfg(feature = "sm-test")] #[path = "../../tests.rs"] diff --git a/src/platform/macos/cgl/mod.rs b/src/platform/macos/cgl/mod.rs index 23857b99..d2dd3f1e 100644 --- a/src/platform/macos/cgl/mod.rs +++ b/src/platform/macos/cgl/mod.rs @@ -10,8 +10,7 @@ pub mod surface; mod error; mod ffi; -#[path = "../../../implementation/mod.rs"] -mod implementation; +crate::implement_interfaces!(); #[cfg(test)] #[path = "../../../tests.rs"] diff --git a/src/platform/unix/generic/mod.rs b/src/platform/unix/generic/mod.rs index 1a819d65..7f407c93 100644 --- a/src/platform/unix/generic/mod.rs +++ b/src/platform/unix/generic/mod.rs @@ -8,8 +8,7 @@ pub mod context; pub mod device; pub mod surface; -#[path = "../../../implementation/mod.rs"] -mod implementation; +crate::implement_interfaces!(); #[cfg(test)] #[path = "../../../tests.rs"] diff --git a/src/platform/unix/wayland/mod.rs b/src/platform/unix/wayland/mod.rs index 9eaf28e2..eb165a77 100644 --- a/src/platform/unix/wayland/mod.rs +++ b/src/platform/unix/wayland/mod.rs @@ -7,8 +7,7 @@ pub mod context; pub mod device; pub mod surface; -#[path = "../../../implementation/mod.rs"] -mod implementation; +crate::implement_interfaces!(); #[cfg(test)] #[path = "../../../tests.rs"] diff --git a/src/platform/unix/x11/mod.rs b/src/platform/unix/x11/mod.rs index 8bce13ca..f3f80f21 100644 --- a/src/platform/unix/x11/mod.rs +++ b/src/platform/unix/x11/mod.rs @@ -7,8 +7,7 @@ pub mod context; pub mod device; pub mod surface; -#[path = "../../../implementation/mod.rs"] -mod implementation; +crate::implement_interfaces!(); #[cfg(test)] #[path = "../../../tests.rs"] diff --git a/src/platform/windows/angle/mod.rs b/src/platform/windows/angle/mod.rs index b6dab2fa..11976325 100644 --- a/src/platform/windows/angle/mod.rs +++ b/src/platform/windows/angle/mod.rs @@ -7,8 +7,7 @@ pub mod context; pub mod device; pub mod surface; -#[path = "../../../implementation/mod.rs"] -mod implementation; +crate::implement_interfaces!(); #[cfg(test)] #[path = "../../../tests.rs"] diff --git a/src/platform/windows/wgl/mod.rs b/src/platform/windows/wgl/mod.rs index 50057f54..5f6a4522 100644 --- a/src/platform/windows/wgl/mod.rs +++ b/src/platform/windows/wgl/mod.rs @@ -7,8 +7,7 @@ pub mod context; pub mod device; pub mod surface; -#[path = "../../../implementation/mod.rs"] -mod implementation; +crate::implement_interfaces!(); #[cfg(test)] #[path = "../../../tests.rs"]