From 4930e7e8b2996ff6afb4b0a54390cdf9a354762d Mon Sep 17 00:00:00 2001 From: Victor Brekenfeld Date: Fri, 12 Jun 2020 21:20:47 +0200 Subject: [PATCH] anvil: create a texture per backend --- anvil/src/glium_drawer.rs | 15 ++++++++++----- anvil/src/shell.rs | 5 +++-- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/anvil/src/glium_drawer.rs b/anvil/src/glium_drawer.rs index 8e67afe..9f436a8 100644 --- a/anvil/src/glium_drawer.rs +++ b/anvil/src/glium_drawer.rs @@ -1,6 +1,7 @@ use std::{ cell::{Ref, RefCell}, rc::Rc, + sync::atomic::{AtomicUsize, Ordering}, }; use glium::{ @@ -38,6 +39,8 @@ use smithay::{ use crate::shaders; use crate::shell::{MyCompositorToken, MyWindowMap, SurfaceData}; +pub static BACKEND_COUNTER: AtomicUsize = AtomicUsize::new(0); + #[derive(Copy, Clone)] struct Vertex { position: [f32; 2], @@ -52,6 +55,7 @@ mod implement_vertex { } pub struct GliumDrawer { + id: usize, display: GliumGraphicsBackend, vertex_buffer: glium::VertexBuffer, index_buffer: glium::IndexBuffer, @@ -107,6 +111,7 @@ impl> + GLGraphicsBackend + 'static> GliumDrawer let programs = opengl_programs!(&display); GliumDrawer { + id: BACKEND_COUNTER.fetch_add(1, Ordering::AcqRel), display, vertex_buffer, index_buffer, @@ -151,6 +156,7 @@ impl> + GLGraphicsBackend + 'static> GliumDrawer let programs = opengl_programs!(&display); GliumDrawer { + id: BACKEND_COUNTER.fetch_add(1, Ordering::AcqRel), display, vertex_buffer, index_buffer, @@ -321,7 +327,7 @@ impl GliumDrawer { // Pull a new buffer if available if let Some(data) = attributes.user_data.get::>() { let mut data = data.borrow_mut(); - if data.texture.is_none() { + if !data.texture.contains_key(&self.id) { if let Some(buffer) = data.current_state.buffer.take() { if let Ok(m) = self.texture_from_buffer(buffer.clone()) { // release the buffer if it was an SHM buffer @@ -335,8 +341,7 @@ impl GliumDrawer { { buffer.release(); } - - data.texture = Some(m); + data.texture.insert(self.id, m); } else { // there was an error reading the buffer, release it, we // already logged the error @@ -345,7 +350,7 @@ impl GliumDrawer { } } // Now, should we be drawn ? - if data.texture.is_some() { + if data.texture.contains_key(&self.id) { // if yes, also process the children if Role::::has(role) { x += data.current_state.sub_location.0; @@ -364,7 +369,7 @@ impl GliumDrawer { |_surface, attributes, role, &(mut x, mut y)| { if let Some(ref data) = attributes.user_data.get::>() { let data = data.borrow(); - if let Some(ref metadata) = data.texture { + if let Some(ref metadata) = data.texture.get(&self.id) { // we need to re-extract the subsurface offset, as the previous closure // only passes it to our children if Role::::has(role) { diff --git a/anvil/src/shell.rs b/anvil/src/shell.rs index d960393..a239c97 100644 --- a/anvil/src/shell.rs +++ b/anvil/src/shell.rs @@ -1,5 +1,6 @@ use std::{ cell::RefCell, + collections::HashMap, rc::Rc, sync::{Arc, Mutex}, }; @@ -654,7 +655,7 @@ pub struct CommitedState { #[derive(Default)] pub struct SurfaceData { - pub texture: Option, + pub texture: HashMap, pub geometry: Option, pub resize_state: ResizeState, /// Minimum width and height, as requested by the surface. @@ -673,7 +674,7 @@ impl SurfaceData { /// Apply a next state into the surface current state pub fn apply_state(&mut self, next_state: CommitedState) { if Self::merge_state(&mut self.current_state, next_state) { - self.texture = None; + self.texture.clear(); } }