Update glium integration to allow mutable borrowing

This commit is contained in:
Drakulix 2018-02-26 18:29:52 +01:00 committed by Victor Berger
parent c6109f41ba
commit bdb653042c
5 changed files with 36 additions and 28 deletions

View File

@ -174,7 +174,7 @@ impl DrmHandler<Card> for DrmHandlerImpl {
frame.clear_color(0.8, 0.8, 0.9, 1.0);
// redraw the frame, in a simple but inneficient way
{
let screen_dimensions = self.drawer.get_framebuffer_dimensions();
let screen_dimensions = self.drawer.borrow().get_framebuffer_dimensions();
self.window_map
.borrow()
.with_windows_from_bottom_to_top(|toplevel_surface, initial_place| {

View File

@ -6,7 +6,7 @@ use smithay::backend::graphics::egl::EGLGraphicsBackend;
use smithay::backend::graphics::egl::error::Result as EGLResult;
use smithay::backend::graphics::egl::wayland::{EGLDisplay, EGLImages, EGLWaylandExtensions, Format};
use smithay::backend::graphics::glium::GliumGraphicsBackend;
use std::borrow::Borrow;
use std::cell::Ref;
use std::ops::Deref;
use wayland_server::Display;
@ -25,16 +25,8 @@ pub struct GliumDrawer<F: EGLGraphicsBackend + 'static> {
program: glium::Program,
}
impl<F: EGLGraphicsBackend + 'static> Deref for GliumDrawer<F> {
type Target = F;
fn deref(&self) -> &F {
self.borrow()
}
}
impl<F: EGLGraphicsBackend + 'static> Borrow<F> for GliumDrawer<F> {
fn borrow(&self) -> &F {
impl<F: EGLGraphicsBackend + 'static> GliumDrawer<F> {
pub fn borrow(&self) -> Ref<F> {
self.display.borrow()
}
}

View File

@ -439,6 +439,7 @@ impl UdevHandlerImpl {
// create cursor
renderer
.borrow()
.set_cursor_representation(&self.pointer_image, (2, 2))
.unwrap();
@ -518,13 +519,15 @@ impl DrmHandler<SessionFdDrmDevice> for DrmHandlerImpl {
if let Some(drawer) = self.backends.borrow().get(&crtc) {
{
let (x, y) = *self.pointer_location.borrow();
let _ = drawer.set_cursor_position(x.trunc().abs() as u32, y.trunc().abs() as u32);
let _ = drawer
.borrow()
.set_cursor_position(x.trunc().abs() as u32, y.trunc().abs() as u32);
}
let mut frame = drawer.draw();
frame.clear_color(0.8, 0.8, 0.9, 1.0);
// redraw the frame, in a simple but inneficient way
{
let screen_dimensions = drawer.get_framebuffer_dimensions();
let screen_dimensions = drawer.borrow().get_framebuffer_dimensions();
self.window_map.borrow().with_windows_from_bottom_to_top(
|toplevel_surface, initial_place| {
if let Some(wl_surface) = toplevel_surface.get_surface() {

View File

@ -241,7 +241,7 @@ fn main() {
frame.clear(None, Some((0.8, 0.8, 0.9, 1.0)), false, Some(1.0), None);
// redraw the frame, in a simple but inneficient way
{
let screen_dimensions = drawer.get_framebuffer_dimensions();
let screen_dimensions = drawer.borrow().get_framebuffer_dimensions();
window_map
.borrow()
.with_windows_from_bottom_to_top(|toplevel_surface, initial_place| {

View File

@ -7,7 +7,7 @@ use glium::Frame;
use glium::SwapBuffersError as GliumSwapBuffersError;
use glium::backend::{Backend, Context, Facade};
use glium::debug::DebugCallbackBehavior;
use std::borrow::Borrow;
use std::cell::{Ref, RefCell, RefMut};
use std::os::raw::c_void;
use std::rc::Rc;
use wayland_server::Display;
@ -28,11 +28,11 @@ pub struct GliumGraphicsBackend<T: EGLGraphicsBackend> {
backend: Rc<InternalBackend<T>>,
}
struct InternalBackend<T: EGLGraphicsBackend>(T);
struct InternalBackend<T: EGLGraphicsBackend>(RefCell<T>);
impl<T: EGLGraphicsBackend + 'static> GliumGraphicsBackend<T> {
fn new(backend: T) -> GliumGraphicsBackend<T> {
let internal = Rc::new(InternalBackend(backend));
let internal = Rc::new(InternalBackend(RefCell::new(backend)));
GliumGraphicsBackend {
// cannot fail
@ -56,11 +56,24 @@ impl<T: EGLGraphicsBackend + 'static> GliumGraphicsBackend<T> {
self.backend.get_framebuffer_dimensions(),
)
}
}
impl<T: EGLGraphicsBackend> Borrow<T> for GliumGraphicsBackend<T> {
fn borrow(&self) -> &T {
&self.backend.0
/// Borrow the underlying backend.
///
/// This follows the same semantics as `std::cell:RefCell`.
/// Multiple read-only borrows are possible. Borrowing the
/// backend while there is a mutable reference will panic.
pub fn borrow(&self) -> Ref<T> {
self.backend.0.borrow()
}
/// Borrow the underlying backend mutably.
///
/// This follows the same semantics as `std::cell:RefCell`.
/// Holding any other borrow while trying to borrow the backend
/// mutably will panic. Note that glium will borrow the backend
/// (not mutably) during rendering.
pub fn borrow_mut(&mut self) -> RefMut<T> {
self.backend.0.borrow_mut()
}
}
@ -80,28 +93,28 @@ impl<T: EGLGraphicsBackend + EGLWaylandExtensions + 'static> EGLWaylandExtension
for GliumGraphicsBackend<T>
{
fn bind_wl_display(&self, display: &Display) -> EGLResult<EGLDisplay> {
(*self.backend).0.bind_wl_display(display)
(*self.backend).0.borrow().bind_wl_display(display)
}
}
unsafe impl<T: EGLGraphicsBackend> Backend for InternalBackend<T> {
fn swap_buffers(&self) -> Result<(), GliumSwapBuffersError> {
self.0.swap_buffers().map_err(Into::into)
self.0.borrow().swap_buffers().map_err(Into::into)
}
unsafe fn get_proc_address(&self, symbol: &str) -> *const c_void {
self.0.get_proc_address(symbol) as *const c_void
self.0.borrow().get_proc_address(symbol) as *const c_void
}
fn get_framebuffer_dimensions(&self) -> (u32, u32) {
self.0.get_framebuffer_dimensions()
self.0.borrow().get_framebuffer_dimensions()
}
fn is_current(&self) -> bool {
self.0.is_current()
self.0.borrow().is_current()
}
unsafe fn make_current(&self) {
self.0.make_current().expect("Context was lost")
self.0.borrow().make_current().expect("Context was lost")
}
}