render/element: Support converting gl-textures

This commit is contained in:
Victoria Brekenfeld 2026-06-11 13:17:11 +02:00 committed by Victoria Brekenfeld
parent 1f0456a5af
commit c92b91221c

View file

@ -8,20 +8,27 @@ use crate::{
use smithay::backend::renderer::element::texture::TextureRenderElement; use smithay::backend::renderer::element::texture::TextureRenderElement;
use smithay::{ use smithay::{
backend::{ backend::{
allocator::dmabuf::Dmabuf, allocator::{Fourcc, dmabuf::Dmabuf},
drm::DrmDeviceFd,
renderer::{ renderer::{
Bind, Blit, ExportMem, ImportAll, ImportMem, Offscreen, Renderer, Bind, Blit, ContextId, ExportMem, Frame as _, FrameContext, ImportAll, ImportMem,
Offscreen, Renderer, RendererSuper,
element::{ element::{
Element, Id, Kind, RenderElement, UnderlyingStorage, Element, Id, Kind, RenderElement, UnderlyingStorage,
utils::{CropRenderElement, Relocate, RelocateRenderElement, RescaleRenderElement}, utils::{CropRenderElement, Relocate, RelocateRenderElement, RescaleRenderElement},
}, },
gles::{GlesError, GlesRenderbuffer, GlesTexture, element::TextureShaderElement}, gles::{GlesError, GlesRenderbuffer, GlesTexture, element::TextureShaderElement},
glow::{GlowFrame, GlowRenderer}, glow::{GlowFrame, GlowRenderer},
multigpu::{
MultiTexture,
gbm::{GbmGlesBackend, GbmGlesDevice},
},
utils::{CommitCounter, DamageSet, OpaqueRegions}, utils::{CommitCounter, DamageSet, OpaqueRegions},
}, },
}, },
utils::{ utils::{
Buffer as BufferCoords, Logical, Physical, Point, Rectangle, Scale, user_data::UserDataMap, Buffer as BufferCoords, Logical, Physical, Point, Rectangle, Scale, Size,
user_data::UserDataMap,
}, },
}; };
@ -396,6 +403,11 @@ pub trait AsGlowRenderer:
fn glow_frame_mut<'a, 'frame, 'buffer>( fn glow_frame_mut<'a, 'frame, 'buffer>(
frame: &'a mut Self::Frame<'frame, 'buffer>, frame: &'a mut Self::Frame<'frame, 'buffer>,
) -> &'a mut GlowFrame<'frame, 'buffer>; ) -> &'a mut GlowFrame<'frame, 'buffer>;
fn tex_from_gl(context: &ContextId<GlesTexture>, texture: GlesTexture) -> Self::TextureId;
fn tex_to_gl(
context: &ContextId<GlesTexture>,
texture: &Self::TextureId,
) -> Option<GlesTexture>;
fn from_gles_error(err: GlesError) -> Self::Error; fn from_gles_error(err: GlesError) -> Self::Error;
} }
@ -416,6 +428,15 @@ impl AsGlowRenderer for GlowRenderer {
) -> &'a mut GlowFrame<'frame, 'buffer> { ) -> &'a mut GlowFrame<'frame, 'buffer> {
frame frame
} }
fn tex_from_gl(_context: &ContextId<GlesTexture>, texture: GlesTexture) -> Self::TextureId {
texture
}
fn tex_to_gl(
_context: &ContextId<GlesTexture>,
texture: &Self::TextureId,
) -> Option<GlesTexture> {
Some(texture.clone())
}
fn from_gles_error(err: GlesError) -> Self::Error { fn from_gles_error(err: GlesError) -> Self::Error {
err err
} }
@ -438,6 +459,15 @@ impl AsGlowRenderer for GlMultiRenderer<'_> {
) -> &'b mut GlowFrame<'frame, 'buffer> { ) -> &'b mut GlowFrame<'frame, 'buffer> {
frame.as_mut() frame.as_mut()
} }
fn tex_from_gl(context: &ContextId<GlesTexture>, texture: GlesTexture) -> Self::TextureId {
MultiTexture::from_native_texture::<GbmGlowBackend<DrmDeviceFd>>(context, texture).unwrap()
}
fn tex_to_gl(
context: &ContextId<GlesTexture>,
texture: &Self::TextureId,
) -> Option<GlesTexture> {
texture.get::<GbmGlowBackend<DrmDeviceFd>>(context)
}
fn from_gles_error(err: GlesError) -> Self::Error { fn from_gles_error(err: GlesError) -> Self::Error {
GlMultiError::Render(err) GlMultiError::Render(err)
} }