#![cfg(any(
target_os = "linux",
target_os = "macos",
target_os = "ios",
target_os = "android",
target_os = "windows"
))]
#![cfg(feature = "opengl")]
#![cfg_attr(not(target_os = "linux"), allow(dead_code, unused_imports))]
macro_rules! function {
() => {{
fn f() {}
fn type_name_of<T>(_: T) -> &'static str {
std::any::type_name::<T>()
}
let name = type_name_of(f);
match &name[..name.len() - 3].rfind(':') {
Some(pos) => &name[pos + 1..name.len() - 3],
None => &name[..name.len() - 3],
}
}};
}
mod cache;
#[cfg(target_os = "linux")]
mod context;
#[cfg(target_os = "linux")]
mod dma_import;
mod core;
mod float_dispatch;
mod proto_dispatch;
mod render;
#[cfg(target_os = "android")]
mod ahardwarebuffer_import;
#[cfg(target_os = "windows")]
pub(super) mod d3d11_import;
#[cfg(target_os = "linux")]
mod fourcc;
#[cfg(any(target_os = "macos", target_os = "ios"))]
mod iosurface_import;
#[cfg(target_os = "android")]
mod native_fence;
mod platform;
mod processor;
mod resources;
mod shaders;
mod shaders_common;
mod tests;
mod threaded;
#[cfg(target_os = "linux")]
pub use context::probe_egl_displays;
pub use cache::{CacheStats, ConvertStats, GlCacheStats};
pub use threaded::GLProcessorThreaded;
pub(super) type Egl = edgefirst_egl::Instance<
edgefirst_egl::Dynamic<&'static libloading::Library, edgefirst_egl::EGL1_4>,
>;
#[cfg(unix)]
pub type CompletionFence = std::os::fd::OwnedFd;
#[cfg(windows)]
pub type CompletionFence = std::os::windows::io::OwnedHandle;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum EglDisplayKind {
Gbm,
PlatformDevice,
Default,
}
impl std::fmt::Display for EglDisplayKind {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
EglDisplayKind::Gbm => write!(f, "GBM"),
EglDisplayKind::PlatformDevice => write!(f, "PlatformDevice"),
EglDisplayKind::Default => write!(f, "Default"),
}
}
}
#[derive(Debug, Clone)]
pub struct EglDisplayInfo {
pub kind: EglDisplayKind,
pub description: String,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(crate) enum TransferBackend {
DmaBuf,
#[cfg(any(target_os = "macos", target_os = "ios"))]
IOSurface,
#[cfg(target_os = "android")]
AHardwareBuffer,
#[cfg(target_os = "windows")]
D3d11Texture,
Pbo,
Sync,
}
impl TransferBackend {
pub(crate) fn is_dma(self) -> bool {
self == TransferBackend::DmaBuf
}
pub(crate) fn is_zero_copy(self) -> bool {
#[cfg(any(target_os = "macos", target_os = "ios"))]
if self == TransferBackend::IOSurface {
return true;
}
#[cfg(target_os = "android")]
if self == TransferBackend::AHardwareBuffer {
return true;
}
#[cfg(target_os = "windows")]
if self == TransferBackend::D3d11Texture {
return true;
}
self == TransferBackend::DmaBuf
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Int8InterpolationMode {
Nearest,
Bilinear,
TwoPass,
}
#[derive(Debug, Clone, Copy)]
pub(super) struct RegionOfInterest {
pub(super) left: f32,
pub(super) top: f32,
pub(super) right: f32,
pub(super) bottom: f32,
}
impl RegionOfInterest {
pub(super) fn from_crop_clamped(crop: &crate::Rect, tex_w: usize, tex_h: usize) -> Self {
let half_x = 0.5 / tex_w as f32;
let half_y = 0.5 / tex_h as f32;
RegionOfInterest {
left: (crop.left as f32 / tex_w as f32 + half_x).clamp(0.0, 1.0),
top: ((crop.top + crop.height) as f32 / tex_h as f32 - half_y).clamp(0.0, 1.0),
right: ((crop.left + crop.width) as f32 / tex_w as f32 - half_x).clamp(0.0, 1.0),
bottom: (crop.top as f32 / tex_h as f32 + half_y).clamp(0.0, 1.0),
}
}
}
#[cfg(all(test, target_os = "windows"))]
mod d3d11_backend_tests {
use super::TransferBackend;
#[test]
fn d3d11_texture_is_zero_copy_and_not_dma() {
assert!(TransferBackend::D3d11Texture.is_zero_copy());
assert!(!TransferBackend::D3d11Texture.is_dma());
}
}