gfx: add ShmGfxTexture
This commit is contained in:
parent
ed4ef3c8e7
commit
c968024905
10 changed files with 51 additions and 22 deletions
|
|
@ -328,7 +328,8 @@ impl CursorImageScaled {
|
|||
extents: Rect::new_sized(-xhot, -yhot, width, height).unwrap(),
|
||||
tex: ctx
|
||||
.clone()
|
||||
.shmem_texture(None, data, ARGB8888, width, height, width * 4, None)?,
|
||||
.shmem_texture(None, data, ARGB8888, width, height, width * 4, None)?
|
||||
.into_texture(),
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -531,6 +531,10 @@ pub trait GfxTexture: Debug {
|
|||
fn format(&self) -> &'static Format;
|
||||
}
|
||||
|
||||
pub trait ShmGfxTexture: GfxTexture {
|
||||
fn into_texture(self: Rc<Self>) -> Rc<dyn GfxTexture>;
|
||||
}
|
||||
|
||||
pub trait GfxContext: Debug {
|
||||
fn reset_status(&self) -> Option<ResetStatus>;
|
||||
|
||||
|
|
@ -546,14 +550,14 @@ pub trait GfxContext: Debug {
|
|||
|
||||
fn shmem_texture(
|
||||
self: Rc<Self>,
|
||||
old: Option<Rc<dyn GfxTexture>>,
|
||||
old: Option<Rc<dyn ShmGfxTexture>>,
|
||||
data: &[Cell<u8>],
|
||||
format: &'static Format,
|
||||
width: i32,
|
||||
height: i32,
|
||||
stride: i32,
|
||||
damage: Option<&[Rect]>,
|
||||
) -> Result<Rc<dyn GfxTexture>, GfxError>;
|
||||
) -> Result<Rc<dyn ShmGfxTexture>, GfxError>;
|
||||
|
||||
fn allocator(&self) -> Rc<dyn Allocator>;
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ use {
|
|||
format::{Format, XRGB8888},
|
||||
gfx_api::{
|
||||
BufferResvUser, GfxApiOpt, GfxContext, GfxError, GfxFormat, GfxFramebuffer, GfxImage,
|
||||
GfxTexture, ResetStatus,
|
||||
ResetStatus, ShmGfxTexture,
|
||||
},
|
||||
gfx_apis::gl::{
|
||||
egl::{context::EglContext, display::EglDisplay, image::EglImage},
|
||||
|
|
@ -265,17 +265,17 @@ impl GfxContext for GlRenderContext {
|
|||
|
||||
fn shmem_texture(
|
||||
self: Rc<Self>,
|
||||
_old: Option<Rc<dyn GfxTexture>>,
|
||||
_old: Option<Rc<dyn ShmGfxTexture>>,
|
||||
data: &[Cell<u8>],
|
||||
format: &'static Format,
|
||||
width: i32,
|
||||
height: i32,
|
||||
stride: i32,
|
||||
_damage: Option<&[Rect]>,
|
||||
) -> Result<Rc<dyn GfxTexture>, GfxError> {
|
||||
) -> Result<Rc<dyn ShmGfxTexture>, GfxError> {
|
||||
(&self)
|
||||
.shmem_texture(data, format, width, height, stride)
|
||||
.map(|w| w as Rc<dyn GfxTexture>)
|
||||
.map(|w| w as Rc<dyn ShmGfxTexture>)
|
||||
.map_err(|e| e.into())
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
use {
|
||||
crate::{
|
||||
format::Format,
|
||||
gfx_api::{GfxError, GfxTexture},
|
||||
gfx_api::{GfxError, GfxTexture, ShmGfxTexture},
|
||||
gfx_apis::gl::{
|
||||
gl::texture::GlTexture,
|
||||
renderer::{context::GlRenderContext, framebuffer::Framebuffer},
|
||||
|
|
@ -82,3 +82,9 @@ impl GfxTexture for Texture {
|
|||
self.format
|
||||
}
|
||||
}
|
||||
|
||||
impl ShmGfxTexture for Texture {
|
||||
fn into_texture(self: Rc<Self>) -> Rc<dyn GfxTexture> {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ use {
|
|||
async_engine::AsyncEngine,
|
||||
format::Format,
|
||||
gfx_api::{
|
||||
GfxContext, GfxError, GfxFormat, GfxFramebuffer, GfxImage, GfxTexture, ResetStatus,
|
||||
GfxContext, GfxError, GfxFormat, GfxFramebuffer, GfxImage, ResetStatus, ShmGfxTexture,
|
||||
},
|
||||
gfx_apis::vulkan::{
|
||||
image::VulkanImageMemory, instance::VulkanInstance, renderer::VulkanRenderer,
|
||||
|
|
@ -249,16 +249,16 @@ impl GfxContext for Context {
|
|||
|
||||
fn shmem_texture(
|
||||
self: Rc<Self>,
|
||||
old: Option<Rc<dyn GfxTexture>>,
|
||||
old: Option<Rc<dyn ShmGfxTexture>>,
|
||||
data: &[Cell<u8>],
|
||||
format: &'static Format,
|
||||
width: i32,
|
||||
height: i32,
|
||||
stride: i32,
|
||||
damage: Option<&[Rect]>,
|
||||
) -> Result<Rc<dyn GfxTexture>, GfxError> {
|
||||
) -> Result<Rc<dyn ShmGfxTexture>, GfxError> {
|
||||
if let Some(old) = old {
|
||||
let old = old.into_vk(&self.0.device.device);
|
||||
let old = old.into_texture().into_vk(&self.0.device.device);
|
||||
let shm = match &old.ty {
|
||||
VulkanImageMemory::DmaBuf(_) => unreachable!(),
|
||||
VulkanImageMemory::Internal(shm) => shm,
|
||||
|
|
|
|||
|
|
@ -1,7 +1,9 @@
|
|||
use {
|
||||
crate::{
|
||||
format::Format,
|
||||
gfx_api::{GfxApiOpt, GfxError, GfxFramebuffer, GfxImage, GfxTexture, SyncFile},
|
||||
gfx_api::{
|
||||
GfxApiOpt, GfxError, GfxFramebuffer, GfxImage, GfxTexture, ShmGfxTexture, SyncFile,
|
||||
},
|
||||
gfx_apis::vulkan::{
|
||||
allocator::VulkanAllocation, device::VulkanDevice, format::VulkanModifierLimits,
|
||||
renderer::VulkanRenderer, shm_image::VulkanShmImage, VulkanError,
|
||||
|
|
@ -530,3 +532,9 @@ impl GfxTexture for VulkanImage {
|
|||
self.format
|
||||
}
|
||||
}
|
||||
|
||||
impl ShmGfxTexture for VulkanImage {
|
||||
fn into_texture(self: Rc<Self>) -> Rc<dyn GfxTexture> {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -201,7 +201,7 @@ impl WlBuffer {
|
|||
match &*self.storage.borrow() {
|
||||
None => None,
|
||||
Some(s) => match s {
|
||||
WlBufferStorage::Shm { .. } => surface.shm_texture.get(),
|
||||
WlBufferStorage::Shm { .. } => surface.shm_texture.get().map(|t| t.into_texture()),
|
||||
WlBufferStorage::Dmabuf { tex, .. } => tex.clone(),
|
||||
},
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,7 +23,8 @@ use {
|
|||
drm_feedback::DrmFeedback,
|
||||
fixed::Fixed,
|
||||
gfx_api::{
|
||||
AcquireSync, BufferResv, BufferResvUser, GfxTexture, ReleaseSync, SampleRect, SyncFile,
|
||||
AcquireSync, BufferResv, BufferResvUser, ReleaseSync, SampleRect, ShmGfxTexture,
|
||||
SyncFile,
|
||||
},
|
||||
ifs::{
|
||||
wl_buffer::WlBuffer,
|
||||
|
|
@ -271,7 +272,7 @@ pub struct WlSurface {
|
|||
pub buffer: CloneCell<Option<Rc<SurfaceBuffer>>>,
|
||||
buffer_presented: Cell<bool>,
|
||||
buffer_had_frame_request: Cell<bool>,
|
||||
pub shm_texture: CloneCell<Option<Rc<dyn GfxTexture>>>,
|
||||
pub shm_texture: CloneCell<Option<Rc<dyn ShmGfxTexture>>>,
|
||||
pub buf_x: NumCell<i32>,
|
||||
pub buf_y: NumCell<i32>,
|
||||
pub children: RefCell<Option<Box<ParentData>>>,
|
||||
|
|
|
|||
|
|
@ -4,7 +4,8 @@ use {
|
|||
format::{Format, ARGB8888, XRGB8888},
|
||||
gfx_api::{
|
||||
CopyTexture, FillRect, FramebufferRect, GfxApiOpt, GfxContext, GfxError, GfxFormat,
|
||||
GfxFramebuffer, GfxImage, GfxTexture, GfxWriteModifier, ResetStatus, SyncFile,
|
||||
GfxFramebuffer, GfxImage, GfxTexture, GfxWriteModifier, ResetStatus, ShmGfxTexture,
|
||||
SyncFile,
|
||||
},
|
||||
rect::Rect,
|
||||
theme::Color,
|
||||
|
|
@ -108,14 +109,14 @@ impl GfxContext for TestGfxCtx {
|
|||
|
||||
fn shmem_texture(
|
||||
self: Rc<Self>,
|
||||
_old: Option<Rc<dyn GfxTexture>>,
|
||||
_old: Option<Rc<dyn ShmGfxTexture>>,
|
||||
data: &[Cell<u8>],
|
||||
format: &'static Format,
|
||||
width: i32,
|
||||
height: i32,
|
||||
stride: i32,
|
||||
_damage: Option<&[Rect]>,
|
||||
) -> Result<Rc<dyn GfxTexture>, GfxError> {
|
||||
) -> Result<Rc<dyn ShmGfxTexture>, GfxError> {
|
||||
assert!(stride >= width * 4);
|
||||
let size = (stride * height) as usize;
|
||||
assert!(data.len() >= size);
|
||||
|
|
@ -301,6 +302,12 @@ impl GfxTexture for TestGfxImage {
|
|||
}
|
||||
}
|
||||
|
||||
impl ShmGfxTexture for TestGfxImage {
|
||||
fn into_texture(self: Rc<Self>) -> Rc<dyn GfxTexture> {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl GfxImage for TestGfxImage {
|
||||
fn to_framebuffer(self: Rc<Self>) -> Result<Rc<dyn GfxFramebuffer>, GfxError> {
|
||||
Ok(Rc::new(TestGfxFb {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
use {
|
||||
crate::{
|
||||
format::ARGB8888,
|
||||
gfx_api::{GfxContext, GfxError, GfxTexture},
|
||||
gfx_api::{GfxContext, GfxError, GfxTexture, ShmGfxTexture},
|
||||
pango::{
|
||||
consts::{
|
||||
CAIRO_FORMAT_ARGB32, CAIRO_OPERATOR_SOURCE, PANGO_ELLIPSIZE_END, PANGO_SCALE,
|
||||
|
|
@ -73,6 +73,7 @@ impl<'a> Config<'a> {
|
|||
#[derive(Clone)]
|
||||
pub struct TextTexture {
|
||||
config: Rc<Config<'static>>,
|
||||
shm_texture: Rc<dyn ShmGfxTexture>,
|
||||
pub texture: Rc<dyn GfxTexture>,
|
||||
}
|
||||
|
||||
|
|
@ -210,7 +211,7 @@ fn render2(
|
|||
Ok(d) => d,
|
||||
Err(e) => return Err(TextError::ImageData(e)),
|
||||
};
|
||||
let old = old.map(|o| o.texture);
|
||||
let old = old.map(|o| o.shm_texture);
|
||||
match ctx.clone().shmem_texture(
|
||||
old,
|
||||
bytes,
|
||||
|
|
@ -222,7 +223,8 @@ fn render2(
|
|||
) {
|
||||
Ok(t) => Ok(TextTexture {
|
||||
config: Rc::new(config.to_static()),
|
||||
texture: t,
|
||||
texture: t.clone().into_texture(),
|
||||
shm_texture: t,
|
||||
}),
|
||||
Err(e) => Err(TextError::RenderError(e)),
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue