1
0
Fork 0
forked from wry/wry

gfx-api: add GfxApi

This commit is contained in:
Julian Orth 2026-02-24 19:56:51 +01:00
parent b604192bf0
commit ca6e3891af
15 changed files with 72 additions and 61 deletions

View file

@ -9,7 +9,7 @@ use {
drm_feedback::DrmFeedback,
fixed::Fixed,
format::Format,
gfx_api::{GfxFramebuffer, SyncFile},
gfx_api::{GfxApi, GfxFramebuffer, SyncFile},
ifs::{
wl_output::OutputId,
wl_seat::{
@ -28,7 +28,7 @@ use {
HDMI_EOTF_TRADITIONAL_GAMMA_SDR,
},
},
jay_config::{input::SwitchEvent, video::GfxApi},
jay_config::input::SwitchEvent,
linearize::Linearize,
std::{
any::Any,

View file

@ -26,7 +26,7 @@ use {
drm_feedback::DrmFeedback,
edid::{CtaDataBlock, Descriptor, EdidExtension},
format::{Format, XRGB8888},
gfx_api::{GfxContext, GfxFramebuffer, SyncFile},
gfx_api::{GfxApi, GfxContext, GfxFramebuffer, SyncFile},
ifs::{
wl_output::OutputId,
wp_presentation_feedback::{KIND_HW_COMPLETION, KIND_VSYNC, KIND_ZERO_COPY},
@ -57,7 +57,6 @@ use {
bstr::{BString, ByteSlice},
indexmap::{IndexSet, indexset},
isnt::std_1::collections::IsntHashMapExt,
jay_config::video::GfxApi,
std::{
cell::{Cell, OnceCell, RefCell},
collections::hash_map::Entry,

View file

@ -17,7 +17,9 @@ use {
cmm::cmm_primaries::Primaries,
fixed::Fixed,
format::{Format, XRGB8888},
gfx_api::{AcquireSync, GfxContext, GfxError, GfxFramebuffer, GfxTexture, ReleaseSync},
gfx_api::{
AcquireSync, GfxApi, GfxContext, GfxError, GfxFramebuffer, GfxTexture, ReleaseSync,
},
ifs::wl_output::OutputId,
state::State,
time::Time,
@ -57,7 +59,6 @@ use {
},
},
ahash::AHashMap,
jay_config::video::GfxApi,
std::{
any::Any,
borrow::Cow,

View file

@ -28,6 +28,7 @@ use {
ei::ei_client::EiClients,
forker,
format::XRGB8888,
gfx_api::GfxApi,
globals::Globals,
ifs::{
head_management::{
@ -81,11 +82,7 @@ use {
},
ahash::AHashSet,
forker::ForkerProxy,
jay_config::{
_private::DEFAULT_SEAT_NAME,
video::{GfxApi, Transform},
workspace::WorkspaceDisplayOrder,
},
jay_config::{_private::DEFAULT_SEAT_NAME, video::Transform, workspace::WorkspaceDisplayOrder},
std::{
cell::{Cell, RefCell},
env,

View file

@ -954,6 +954,9 @@ impl ConfigProxyHandler {
}
fn handle_set_gfx_api(&self, device: Option<DrmDevice>, api: GfxApi) -> Result<(), CphError> {
let Ok(api) = api.try_into() else {
return Err(CphError::UnknownGfxApi(api));
};
match device {
Some(dev) => self.get_drm_device(dev)?.dev.set_gfx_api(api),
_ => self.state.default_gfx_api.set(api),
@ -3532,6 +3535,8 @@ enum CphError {
UnknownBlendSpace(ConfigBlendSpace),
#[error("Unknown bar position {0:?}")]
UnknownBarPosition(BarPosition),
#[error("Unknown gfx API {0:?}")]
UnknownGfxApi(GfxApi),
}
trait WithRequestName {

View file

@ -18,7 +18,8 @@ use {
},
ahash::AHashMap,
indexmap::{IndexMap, IndexSet},
jay_config::video::{GfxApi, Transform},
jay_config::video::{GfxApi as ConfigGfxApi, Transform},
linearize::Linearize,
std::{
any::Any,
cell::Cell,
@ -33,6 +34,51 @@ use {
uapi::OwnedFd,
};
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq, Linearize)]
pub enum GfxApi {
OpenGl,
Vulkan,
}
impl TryFrom<ConfigGfxApi> for GfxApi {
type Error = ();
fn try_from(value: ConfigGfxApi) -> Result<Self, Self::Error> {
let v = match value {
ConfigGfxApi::OpenGl => GfxApi::OpenGl,
ConfigGfxApi::Vulkan => GfxApi::Vulkan,
_ => return Err(()),
};
Ok(v)
}
}
impl Into<ConfigGfxApi> for GfxApi {
fn into(self) -> ConfigGfxApi {
match self {
GfxApi::OpenGl => ConfigGfxApi::OpenGl,
GfxApi::Vulkan => ConfigGfxApi::Vulkan,
}
}
}
impl GfxApi {
pub fn to_str(&self) -> &'static str {
match self {
GfxApi::OpenGl => "OpenGl",
GfxApi::Vulkan => "Vulkan",
}
}
pub fn from_str_lossy(s: &str) -> Option<Self> {
match &*s.to_ascii_lowercase() {
"opengl" => Some(Self::OpenGl),
"vulkan" => Some(Self::Vulkan),
_ => None,
}
}
}
pub enum GfxApiOpt {
Sync,
FillRect(FillRect),

View file

@ -2,13 +2,12 @@ pub use vulkan::create_vulkan_allocator;
use {
crate::{
async_engine::AsyncEngine,
gfx_api::{GfxContext, GfxError},
gfx_api::{GfxApi, GfxContext, GfxError},
io_uring::IoUring,
pr_caps::PrCapsThread,
utils::errorfmt::ErrorFmt,
video::drm::Drm,
},
jay_config::video::GfxApi,
std::rc::Rc,
};
@ -57,6 +56,5 @@ fn create_gfx_context_(
match api {
GfxApi::OpenGl => gl::create_gfx_context(drm, software),
GfxApi::Vulkan => vulkan::create_graphics_context(eng, ring, drm, caps_thread, software),
_ => unreachable!(),
}
}

View file

@ -4,8 +4,9 @@ use {
cpu_worker::CpuWorker,
format::{Format, XRGB8888},
gfx_api::{
AsyncShmGfxTexture, BufferResvUser, GfxBlendBuffer, GfxContext, GfxError, GfxFormat,
GfxFramebuffer, GfxImage, GfxInternalFramebuffer, ResetStatus, ShmGfxTexture,
AsyncShmGfxTexture, BufferResvUser, GfxApi, GfxBlendBuffer, GfxContext, GfxError,
GfxFormat, GfxFramebuffer, GfxImage, GfxInternalFramebuffer, ResetStatus,
ShmGfxTexture,
},
gfx_apis::gl::{
GfxGlState, RenderError, Texture,
@ -24,7 +25,6 @@ use {
},
},
ahash::AHashMap,
jay_config::video::GfxApi,
linearize::{Linearize, StaticMap, static_map},
std::{
cell::{Cell, RefCell},

View file

@ -30,7 +30,7 @@ use {
cpu_worker::{CpuWorker, jobs::read_write::ReadWriteJobError},
format::Format,
gfx_api::{
AsyncShmGfxTexture, GfxBlendBuffer, GfxBuffer, GfxContext, GfxError, GfxFormat,
AsyncShmGfxTexture, GfxApi, GfxBlendBuffer, GfxBuffer, GfxContext, GfxError, GfxFormat,
GfxImage, GfxInternalFramebuffer, GfxStagingBuffer, GfxTexture, ResetStatus,
STAGING_DOWNLOAD, STAGING_UPLOAD, ShmGfxTexture, StagingBufferUsecase,
},
@ -51,7 +51,6 @@ use {
ahash::AHashMap,
ash::vk,
gpu_alloc::{AllocationError, MapError},
jay_config::video::GfxApi,
log::Level,
std::{
cell::Cell,

View file

@ -4,18 +4,17 @@ use {
client::{Client, ClientError},
compositor::MAX_EXTENTS,
format::named_formats,
gfx_api::GfxApi,
ifs::wl_output,
leaks::Tracker,
object::{Object, Version},
scale::Scale,
state::{ConnectorData, DrmDevData, OutputData, State},
tree::{OutputNode, TearingMode, VrrMode},
utils::{errorfmt::ErrorFmt, gfx_api_ext::GfxApiExt, transform_ext::TransformExt},
utils::{errorfmt::ErrorFmt, transform_ext::TransformExt},
wire::{JayRandrId, jay_randr::*},
},
jay_config::video::{
GfxApi, TearingMode as ConfigTearingMode, Transform, VrrMode as ConfigVrrMode,
},
jay_config::video::{TearingMode as ConfigTearingMode, Transform, VrrMode as ConfigVrrMode},
linearize::LinearizeExt,
std::rc::Rc,
thiserror::Error,

View file

@ -6,7 +6,7 @@ use {
format::{ARGB8888, Format, XRGB8888},
gfx_api::{
AcquireSync, AsyncShmGfxTexture, AsyncShmGfxTextureCallback, CopyTexture, FillRect,
FramebufferRect, GfxApiOpt, GfxBlendBuffer, GfxContext, GfxError, GfxFormat,
FramebufferRect, GfxApi, GfxApiOpt, GfxBlendBuffer, GfxContext, GfxError, GfxFormat,
GfxFramebuffer, GfxImage, GfxInternalFramebuffer, GfxStagingBuffer, GfxTexture,
GfxWriteModifier, PendingShmTransfer, ReleaseSync, ResetStatus, ShmGfxTexture,
ShmMemory, SyncFile,
@ -17,7 +17,6 @@ use {
},
ahash::AHashMap,
indexmap::IndexSet,
jay_config::video::GfxApi,
std::{
any::Any,
cell::{Cell, RefCell},

View file

@ -1,6 +1,6 @@
use {
crate::{
gfx_api::{GfxFormat, cross_intersect_formats},
gfx_api::{GfxApi, GfxFormat, cross_intersect_formats},
gfx_apis::create_gfx_context,
ifs::wl_seat::POINTER,
object::Version,
@ -46,7 +46,6 @@ use {
},
},
ahash::AHashMap,
jay_config::video::GfxApi,
std::{
cell::{Cell, RefCell},
ops::Deref,

View file

@ -31,7 +31,7 @@ use {
forker::ForkerProxy,
format::Format,
gfx_api::{
AcquireSync, AlphaMode, BufferResv, GfxBlendBuffer, GfxContext, GfxError,
AcquireSync, AlphaMode, BufferResv, GfxApi, GfxBlendBuffer, GfxContext, GfxError,
GfxFramebuffer, GfxTexture, PendingShmTransfer, ReleaseSync, STAGING_DOWNLOAD,
SampleRect, SyncFile,
},
@ -135,12 +135,7 @@ use {
},
ahash::AHashMap,
bstr::ByteSlice,
jay_config::{
PciId,
video::{GfxApi, Transform},
window::TileState,
workspace::WorkspaceDisplayOrder,
},
jay_config::{PciId, video::Transform, window::TileState, workspace::WorkspaceDisplayOrder},
std::{
cell::{Cell, RefCell},
fmt::{Debug, Formatter},

View file

@ -21,7 +21,6 @@ pub mod event_listener;
pub mod fdcloser;
pub mod free_list;
pub mod geometric_decay;
pub mod gfx_api_ext;
pub mod hash_map_ext;
pub mod line_logger;
pub mod linkedlist;

View file

@ -1,25 +0,0 @@
use jay_config::video::GfxApi;
pub trait GfxApiExt: Sized {
fn to_str(&self) -> &'static str;
fn from_str_lossy(s: &str) -> Option<Self>;
}
impl GfxApiExt for GfxApi {
fn to_str(&self) -> &'static str {
match self {
GfxApi::OpenGl => "OpenGl",
GfxApi::Vulkan => "Vulkan",
_ => "unknown",
}
}
fn from_str_lossy(s: &str) -> Option<Self> {
match &*s.to_ascii_lowercase() {
"opengl" => Some(Self::OpenGl),
"vulkan" => Some(Self::Vulkan),
_ => None,
}
}
}