Update glium integration to allow mutable borrowing
This commit is contained in:
parent
c6109f41ba
commit
bdb653042c
|
@ -174,7 +174,7 @@ impl DrmHandler<Card> for DrmHandlerImpl {
|
||||||
frame.clear_color(0.8, 0.8, 0.9, 1.0);
|
frame.clear_color(0.8, 0.8, 0.9, 1.0);
|
||||||
// redraw the frame, in a simple but inneficient way
|
// 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
|
self.window_map
|
||||||
.borrow()
|
.borrow()
|
||||||
.with_windows_from_bottom_to_top(|toplevel_surface, initial_place| {
|
.with_windows_from_bottom_to_top(|toplevel_surface, initial_place| {
|
||||||
|
|
|
@ -6,7 +6,7 @@ use smithay::backend::graphics::egl::EGLGraphicsBackend;
|
||||||
use smithay::backend::graphics::egl::error::Result as EGLResult;
|
use smithay::backend::graphics::egl::error::Result as EGLResult;
|
||||||
use smithay::backend::graphics::egl::wayland::{EGLDisplay, EGLImages, EGLWaylandExtensions, Format};
|
use smithay::backend::graphics::egl::wayland::{EGLDisplay, EGLImages, EGLWaylandExtensions, Format};
|
||||||
use smithay::backend::graphics::glium::GliumGraphicsBackend;
|
use smithay::backend::graphics::glium::GliumGraphicsBackend;
|
||||||
use std::borrow::Borrow;
|
use std::cell::Ref;
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
use wayland_server::Display;
|
use wayland_server::Display;
|
||||||
|
|
||||||
|
@ -25,16 +25,8 @@ pub struct GliumDrawer<F: EGLGraphicsBackend + 'static> {
|
||||||
program: glium::Program,
|
program: glium::Program,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<F: EGLGraphicsBackend + 'static> Deref for GliumDrawer<F> {
|
impl<F: EGLGraphicsBackend + 'static> GliumDrawer<F> {
|
||||||
type Target = F;
|
pub fn borrow(&self) -> Ref<F> {
|
||||||
|
|
||||||
fn deref(&self) -> &F {
|
|
||||||
self.borrow()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<F: EGLGraphicsBackend + 'static> Borrow<F> for GliumDrawer<F> {
|
|
||||||
fn borrow(&self) -> &F {
|
|
||||||
self.display.borrow()
|
self.display.borrow()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -439,6 +439,7 @@ impl UdevHandlerImpl {
|
||||||
|
|
||||||
// create cursor
|
// create cursor
|
||||||
renderer
|
renderer
|
||||||
|
.borrow()
|
||||||
.set_cursor_representation(&self.pointer_image, (2, 2))
|
.set_cursor_representation(&self.pointer_image, (2, 2))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -518,13 +519,15 @@ impl DrmHandler<SessionFdDrmDevice> for DrmHandlerImpl {
|
||||||
if let Some(drawer) = self.backends.borrow().get(&crtc) {
|
if let Some(drawer) = self.backends.borrow().get(&crtc) {
|
||||||
{
|
{
|
||||||
let (x, y) = *self.pointer_location.borrow();
|
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();
|
let mut frame = drawer.draw();
|
||||||
frame.clear_color(0.8, 0.8, 0.9, 1.0);
|
frame.clear_color(0.8, 0.8, 0.9, 1.0);
|
||||||
// redraw the frame, in a simple but inneficient way
|
// 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(
|
self.window_map.borrow().with_windows_from_bottom_to_top(
|
||||||
|toplevel_surface, initial_place| {
|
|toplevel_surface, initial_place| {
|
||||||
if let Some(wl_surface) = toplevel_surface.get_surface() {
|
if let Some(wl_surface) = toplevel_surface.get_surface() {
|
||||||
|
|
|
@ -241,7 +241,7 @@ fn main() {
|
||||||
frame.clear(None, Some((0.8, 0.8, 0.9, 1.0)), false, Some(1.0), None);
|
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
|
// 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
|
window_map
|
||||||
.borrow()
|
.borrow()
|
||||||
.with_windows_from_bottom_to_top(|toplevel_surface, initial_place| {
|
.with_windows_from_bottom_to_top(|toplevel_surface, initial_place| {
|
||||||
|
|
|
@ -7,7 +7,7 @@ use glium::Frame;
|
||||||
use glium::SwapBuffersError as GliumSwapBuffersError;
|
use glium::SwapBuffersError as GliumSwapBuffersError;
|
||||||
use glium::backend::{Backend, Context, Facade};
|
use glium::backend::{Backend, Context, Facade};
|
||||||
use glium::debug::DebugCallbackBehavior;
|
use glium::debug::DebugCallbackBehavior;
|
||||||
use std::borrow::Borrow;
|
use std::cell::{Ref, RefCell, RefMut};
|
||||||
use std::os::raw::c_void;
|
use std::os::raw::c_void;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use wayland_server::Display;
|
use wayland_server::Display;
|
||||||
|
@ -28,11 +28,11 @@ pub struct GliumGraphicsBackend<T: EGLGraphicsBackend> {
|
||||||
backend: Rc<InternalBackend<T>>,
|
backend: Rc<InternalBackend<T>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
struct InternalBackend<T: EGLGraphicsBackend>(T);
|
struct InternalBackend<T: EGLGraphicsBackend>(RefCell<T>);
|
||||||
|
|
||||||
impl<T: EGLGraphicsBackend + 'static> GliumGraphicsBackend<T> {
|
impl<T: EGLGraphicsBackend + 'static> GliumGraphicsBackend<T> {
|
||||||
fn new(backend: T) -> GliumGraphicsBackend<T> {
|
fn new(backend: T) -> GliumGraphicsBackend<T> {
|
||||||
let internal = Rc::new(InternalBackend(backend));
|
let internal = Rc::new(InternalBackend(RefCell::new(backend)));
|
||||||
|
|
||||||
GliumGraphicsBackend {
|
GliumGraphicsBackend {
|
||||||
// cannot fail
|
// cannot fail
|
||||||
|
@ -56,11 +56,24 @@ impl<T: EGLGraphicsBackend + 'static> GliumGraphicsBackend<T> {
|
||||||
self.backend.get_framebuffer_dimensions(),
|
self.backend.get_framebuffer_dimensions(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
impl<T: EGLGraphicsBackend> Borrow<T> for GliumGraphicsBackend<T> {
|
/// Borrow the underlying backend.
|
||||||
fn borrow(&self) -> &T {
|
///
|
||||||
&self.backend.0
|
/// 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>
|
for GliumGraphicsBackend<T>
|
||||||
{
|
{
|
||||||
fn bind_wl_display(&self, display: &Display) -> EGLResult<EGLDisplay> {
|
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> {
|
unsafe impl<T: EGLGraphicsBackend> Backend for InternalBackend<T> {
|
||||||
fn swap_buffers(&self) -> Result<(), GliumSwapBuffersError> {
|
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 {
|
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) {
|
fn get_framebuffer_dimensions(&self) -> (u32, u32) {
|
||||||
self.0.get_framebuffer_dimensions()
|
self.0.borrow().get_framebuffer_dimensions()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_current(&self) -> bool {
|
fn is_current(&self) -> bool {
|
||||||
self.0.is_current()
|
self.0.borrow().is_current()
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe fn make_current(&self) {
|
unsafe fn make_current(&self) {
|
||||||
self.0.make_current().expect("Context was lost")
|
self.0.borrow().make_current().expect("Context was lost")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue