buffers: cleanup now dead sharedsurface impl

This commit is contained in:
Victoria Fischer 2024-12-14 15:32:07 +01:00
parent a0d524b825
commit 01fdc11552

View File

@ -6,7 +6,6 @@ use crate::render::{PixelView, Sample, Shader, Surface, Surfaces, HardwarePixel}
use crate::task::Task;
use std::fmt::Debug;
use std::io;
use std::ops::IndexMut;
use std::sync::atomic::AtomicBool;
@ -243,84 +242,6 @@ impl Task for BufferedSurfacePool {
}
}
#[derive(Clone)]
pub struct SharedSurface {
binding: Arc<Mutex<ShaderBinding>>
}
impl Default for SharedSurface {
fn default() -> Self {
Self {
binding: Arc::new(Mutex::new(ShaderBinding {
shader: None,
rect: Rectangle::everything(),
opacity: 255
})),
}
}
}
impl Surface for SharedSurface {
fn set_shader(&mut self, shader: Box<dyn Shader>) {
self.binding.lock().unwrap().shader = Some(shader);
}
fn clear_shader(&mut self) {
self.binding.lock().unwrap().shader = None;
}
fn set_rect(&mut self, rect: Rectangle<Virtual>) {
self.binding.lock().unwrap().rect = rect;
}
fn set_opacity(&mut self, opacity: u8) {
self.binding.lock().unwrap().opacity = opacity
}
}
#[derive(Clone)]
pub struct SurfacePool {
surfaces: Vec<SharedSurface>
}
impl SurfacePool {
pub const fn new() -> Self {
Self {
surfaces: Vec::new()
}
}
}
impl Surfaces for SurfacePool {
type Surface = SharedSurface;
type Error = io::Error;
fn new_surface(&mut self, area: Rectangle<Virtual>) -> Result<Self::Surface, Self::Error> {
let mut surface = SharedSurface::default();
surface.set_rect(area);
self.surfaces.push(surface.clone());
return Ok(surface);
}
fn render_to<Sampler: Sample>(&self, output: &mut Sampler, frame: usize) {
for surface in self.surfaces.iter() {
let binding = surface.binding.lock().unwrap();
let opacity = binding.opacity;
if opacity > 0 {
let rect = binding.rect;
let mut sample = output.sample(&rect);
if let Some(ref shader) = binding.shader {
while let Some((virt_coords, pixel)) = sample.next() {
*pixel = pixel.blend8(shader.draw(&virt_coords, frame).into(), opacity);
}
}
}
}
}
}
pub trait Pixbuf: AsMilliwatts + IndexMut<usize, Output=Self::Pixel> + Send {
type Pixel: HardwarePixel;
fn new() -> Self;