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::{
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<F: GLGraphicsBackend + 'static> {
id: usize,
display: GliumGraphicsBackend<F>,
vertex_buffer: glium::VertexBuffer<Vertex>,
index_buffer: glium::IndexBuffer<u16>,
@ -107,6 +111,7 @@ impl<T: Into<GliumGraphicsBackend<T>> + 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<T: Into<GliumGraphicsBackend<T>> + 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<F: GLGraphicsBackend + 'static> GliumDrawer<F> {
// Pull a new buffer if available
if let Some(data) = attributes.user_data.get::<RefCell<SurfaceData>>() {
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<F: GLGraphicsBackend + 'static> GliumDrawer<F> {
{
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<F: GLGraphicsBackend + 'static> GliumDrawer<F> {
}
}
// 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::<SubsurfaceRole>::has(role) {
x += data.current_state.sub_location.0;
@ -364,7 +369,7 @@ impl<F: GLGraphicsBackend + 'static> GliumDrawer<F> {
|_surface, attributes, role, &(mut x, mut y)| {
if let Some(ref data) = attributes.user_data.get::<RefCell<SurfaceData>>() {
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::<SubsurfaceRole>::has(role) {

View File

@ -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<crate::glium_drawer::TextureMetadata>,
pub texture: HashMap<usize, crate::glium_drawer::TextureMetadata>,
pub geometry: Option<Rectangle>,
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();
}
}