Added files that didn't get added, removed empty file

This commit is contained in:
Seaotatop 2023-06-07 12:39:58 -05:00
parent 8f5c55d3a0
commit 65760b2434
5 changed files with 202 additions and 1 deletions

86
src/backend/udev.rs Normal file
View file

@ -0,0 +1,86 @@
use std::collections::HashMap;
use smithay::{
backend::{
allocator::gbm::{GbmAllocator, GbmDevice},
drm::{compositor::DrmCompositor, DrmDeviceFd, DrmNode, GbmBufferedSurface},
renderer::{
damage::OutputDamageTracker,
gles::GlesRenderer,
multigpu::{gbm::GbmGlesBackend, GpuManager},
},
session::libseat::LibSeatSession,
},
desktop::utils::OutputPresentationFeedback,
output::Output,
reexports::{
drm::control::crtc,
wayland_server::{backend::GlobalId, protocol::wl_surface::WlSurface, DisplayHandle},
},
};
use crate::state::State;
use super::Backend;
pub struct UdevData {
session: LibSeatSession,
display_handle: DisplayHandle,
primary_gpu: DrmNode,
gpu_manager: GpuManager<GbmGlesBackend<GlesRenderer>>,
backends: HashMap<DrmNode, BackendData>,
}
impl Backend for UdevData {
fn seat_name(&self) -> String {
todo!()
}
fn reset_buffers(&mut self, output: &Output) {
todo!()
}
fn early_import(&mut self, surface: &WlSurface) {
todo!()
}
}
struct BackendData {
surfaces: HashMap<crtc::Handle, SurfaceData>,
gbm_device: GbmDevice<DrmDeviceFd>,
}
struct SurfaceData {
global: Option<GlobalId>,
display_handle: DisplayHandle,
device_id: DrmNode,
render_node: DrmNode,
compositor: SurfaceComposition,
// TODO: dmabuf_feedback
}
impl Drop for SurfaceData {
fn drop(&mut self) {
if let Some(global) = self.global.take() {
self.display_handle.remove_global::<State<UdevData>>(global);
}
}
}
type RenderSurface =
GbmBufferedSurface<GbmAllocator<DrmDeviceFd>, Option<OutputPresentationFeedback>>;
type GbmDrmCompositor = DrmCompositor<
GbmAllocator<DrmDeviceFd>,
GbmDevice<DrmDeviceFd>,
Option<OutputPresentationFeedback>,
DrmDeviceFd,
>;
enum SurfaceComposition {
Surface {
surface: RenderSurface,
damage_tracker: OutputDamageTracker,
},
Compositor(GbmDrmCompositor),
}

View file

@ -6,7 +6,6 @@ mod layout;
mod pointer;
mod render;
mod state;
mod tag;
mod window;
mod xdg;

26
src/render.rs Normal file
View file

@ -0,0 +1,26 @@
use smithay::{
backend::renderer::{
element::{surface::WaylandSurfaceRenderElement, Wrap},
ImportAll, ImportMem,
},
desktop::space::SpaceRenderElements,
render_elements,
};
use self::pointer::PointerRenderElement;
pub mod pointer;
render_elements! {
pub CustomRenderElements<R> where R: ImportAll + ImportMem;
Pointer=PointerRenderElement<R>,
Surface=WaylandSurfaceRenderElement<R>,
}
render_elements! {
pub OutputRenderElements<R, E> where R: ImportAll + ImportMem;
Space=SpaceRenderElements<R, E>,
Window=Wrap<E>,
Custom=CustomRenderElements<R>,
// TODO: preview
}

90
src/render/pointer.rs Normal file
View file

@ -0,0 +1,90 @@
use smithay::{
backend::renderer::{
element::{
surface::{self, WaylandSurfaceRenderElement},
texture::{TextureBuffer, TextureRenderElement},
AsRenderElements,
},
ImportAll, Renderer, Texture,
},
input::pointer::CursorImageStatus,
render_elements,
utils::{Physical, Point, Scale},
};
pub struct PointerElement<T: Texture> {
texture: Option<TextureBuffer<T>>,
status: CursorImageStatus,
}
impl<T: Texture> Default for PointerElement<T> {
fn default() -> Self {
Self {
texture: Default::default(),
status: CursorImageStatus::Default,
}
}
}
impl<T: Texture> PointerElement<T> {
pub fn new() -> Self {
Default::default()
}
pub fn set_status(&mut self, status: CursorImageStatus) {
self.status = status;
}
pub fn set_texture(&mut self, texture: TextureBuffer<T>) {
self.texture = Some(texture);
}
}
render_elements! {
pub PointerRenderElement<R> where R: ImportAll;
Surface=WaylandSurfaceRenderElement<R>,
Texture=TextureRenderElement<<R as Renderer>::TextureId>,
}
impl<T, R> AsRenderElements<R> for PointerElement<T>
where
T: Texture + Clone + 'static,
R: Renderer<TextureId = T> + ImportAll,
{
type RenderElement = PointerRenderElement<R>;
fn render_elements<C: From<Self::RenderElement>>(
&self,
renderer: &mut R,
location: Point<i32, Physical>,
scale: Scale<f64>,
alpha: f32,
) -> Vec<C> {
match &self.status {
CursorImageStatus::Hidden => vec![],
CursorImageStatus::Default => {
if let Some(texture) = self.texture.as_ref() {
vec![PointerRenderElement::<R>::from(
TextureRenderElement::from_texture_buffer(
location.to_f64(),
texture,
None,
None,
None,
),
)
.into()]
} else {
vec![]
}
}
CursorImageStatus::Surface(surface) => {
let elements: Vec<PointerRenderElement<R>> =
surface::render_elements_from_surface_tree(
renderer, surface, location, scale, alpha,
);
elements.into_iter().map(C::from).collect()
}
}
}
}

View file