anvil: create a texture per backend

This commit is contained in:
Victor Brekenfeld 2020-06-12 21:20:47 +02:00
parent f84d6cb180
commit 4930e7e8b2
2 changed files with 13 additions and 7 deletions

View File

@ -1,6 +1,7 @@
use std::{ use std::{
cell::{Ref, RefCell}, cell::{Ref, RefCell},
rc::Rc, rc::Rc,
sync::atomic::{AtomicUsize, Ordering},
}; };
use glium::{ use glium::{
@ -38,6 +39,8 @@ use smithay::{
use crate::shaders; use crate::shaders;
use crate::shell::{MyCompositorToken, MyWindowMap, SurfaceData}; use crate::shell::{MyCompositorToken, MyWindowMap, SurfaceData};
pub static BACKEND_COUNTER: AtomicUsize = AtomicUsize::new(0);
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
struct Vertex { struct Vertex {
position: [f32; 2], position: [f32; 2],
@ -52,6 +55,7 @@ mod implement_vertex {
} }
pub struct GliumDrawer<F: GLGraphicsBackend + 'static> { pub struct GliumDrawer<F: GLGraphicsBackend + 'static> {
id: usize,
display: GliumGraphicsBackend<F>, display: GliumGraphicsBackend<F>,
vertex_buffer: glium::VertexBuffer<Vertex>, vertex_buffer: glium::VertexBuffer<Vertex>,
index_buffer: glium::IndexBuffer<u16>, index_buffer: glium::IndexBuffer<u16>,
@ -107,6 +111,7 @@ impl<T: Into<GliumGraphicsBackend<T>> + GLGraphicsBackend + 'static> GliumDrawer
let programs = opengl_programs!(&display); let programs = opengl_programs!(&display);
GliumDrawer { GliumDrawer {
id: BACKEND_COUNTER.fetch_add(1, Ordering::AcqRel),
display, display,
vertex_buffer, vertex_buffer,
index_buffer, index_buffer,
@ -151,6 +156,7 @@ impl<T: Into<GliumGraphicsBackend<T>> + GLGraphicsBackend + 'static> GliumDrawer
let programs = opengl_programs!(&display); let programs = opengl_programs!(&display);
GliumDrawer { GliumDrawer {
id: BACKEND_COUNTER.fetch_add(1, Ordering::AcqRel),
display, display,
vertex_buffer, vertex_buffer,
index_buffer, index_buffer,
@ -321,7 +327,7 @@ impl<F: GLGraphicsBackend + 'static> GliumDrawer<F> {
// Pull a new buffer if available // Pull a new buffer if available
if let Some(data) = attributes.user_data.get::<RefCell<SurfaceData>>() { if let Some(data) = attributes.user_data.get::<RefCell<SurfaceData>>() {
let mut data = data.borrow_mut(); 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 Some(buffer) = data.current_state.buffer.take() {
if let Ok(m) = self.texture_from_buffer(buffer.clone()) { if let Ok(m) = self.texture_from_buffer(buffer.clone()) {
// release the buffer if it was an SHM buffer // release the buffer if it was an SHM buffer
@ -335,8 +341,7 @@ impl<F: GLGraphicsBackend + 'static> GliumDrawer<F> {
{ {
buffer.release(); buffer.release();
} }
data.texture.insert(self.id, m);
data.texture = Some(m);
} else { } else {
// there was an error reading the buffer, release it, we // there was an error reading the buffer, release it, we
// already logged the error // already logged the error
@ -345,7 +350,7 @@ impl<F: GLGraphicsBackend + 'static> GliumDrawer<F> {
} }
} }
// Now, should we be drawn ? // Now, should we be drawn ?
if data.texture.is_some() { if data.texture.contains_key(&self.id) {
// if yes, also process the children // if yes, also process the children
if Role::<SubsurfaceRole>::has(role) { if Role::<SubsurfaceRole>::has(role) {
x += data.current_state.sub_location.0; x += data.current_state.sub_location.0;
@ -364,7 +369,7 @@ impl<F: GLGraphicsBackend + 'static> GliumDrawer<F> {
|_surface, attributes, role, &(mut x, mut y)| { |_surface, attributes, role, &(mut x, mut y)| {
if let Some(ref data) = attributes.user_data.get::<RefCell<SurfaceData>>() { if let Some(ref data) = attributes.user_data.get::<RefCell<SurfaceData>>() {
let data = data.borrow(); 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 // we need to re-extract the subsurface offset, as the previous closure
// only passes it to our children // only passes it to our children
if Role::<SubsurfaceRole>::has(role) { if Role::<SubsurfaceRole>::has(role) {

View File

@ -1,5 +1,6 @@
use std::{ use std::{
cell::RefCell, cell::RefCell,
collections::HashMap,
rc::Rc, rc::Rc,
sync::{Arc, Mutex}, sync::{Arc, Mutex},
}; };
@ -654,7 +655,7 @@ pub struct CommitedState {
#[derive(Default)] #[derive(Default)]
pub struct SurfaceData { pub struct SurfaceData {
pub texture: Option<crate::glium_drawer::TextureMetadata>, pub texture: HashMap<usize, crate::glium_drawer::TextureMetadata>,
pub geometry: Option<Rectangle>, pub geometry: Option<Rectangle>,
pub resize_state: ResizeState, pub resize_state: ResizeState,
/// Minimum width and height, as requested by the surface. /// Minimum width and height, as requested by the surface.
@ -673,7 +674,7 @@ impl SurfaceData {
/// Apply a next state into the surface current state /// Apply a next state into the surface current state
pub fn apply_state(&mut self, next_state: CommitedState) { pub fn apply_state(&mut self, next_state: CommitedState) {
if Self::merge_state(&mut self.current_state, next_state) { if Self::merge_state(&mut self.current_state, next_state) {
self.texture = None; self.texture.clear();
} }
} }