Skip to content

Fix #1672 #1673

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/backend/renderer/gles/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1788,6 +1788,24 @@ impl GlesRenderer {
Ok(func(&self.gl))
}

/// Run custom code in the GL context owned by this renderer after turning
/// the given target into the current framebuffer.
///
/// The OpenGL state of the renderer is considered an implementation detail
/// and no guarantee is made about what can or cannot be changed,
/// as such you should reset everything you change back to its previous value
/// or check the source code of the version of Smithay you are using to ensure
/// your changes don't interfere with the renderer's behavior.
/// Doing otherwise can lead to rendering errors while using other functions of this renderer.
#[instrument(level = "trace", parent = &self.span, skip_all)]
pub fn with_context_bound_fb<F, R>(&mut self, fb: &GlesTarget<'_>, func: F) -> Result<R, GlesError>
where
F: FnOnce(&ffi::Gles2) -> R,
{
fb.0.make_current(&self.gl, &self.egl)?;
Ok(func(&self.gl))
}

/// Compile a custom pixel shader for rendering with [`GlesFrame::render_pixel_shader_to`].
///
/// Pixel shaders can be used for completely shader-driven drawing into a given region.
Expand Down
17 changes: 17 additions & 0 deletions src/backend/renderer/glow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,23 @@ impl GlowRenderer {
}
Ok(func(&self.glow))
}

/// Run custom code in the GL context owned by this renderer after turning
/// the given target into the current framebuffer.
///
/// The OpenGL state of the renderer is considered an implementation detail
/// and no guarantee is made about what can or cannot be changed,
/// as such you should reset everything you change back to its previous value
/// or check the source code of the version of Smithay you are using to ensure
/// your changes don't interfere with the renderer's behavior.
/// Doing otherwise can lead to rendering errors while using other functions of this renderer.
pub fn with_context_bound_fb<F, R>(&mut self, fb: &GlesTarget<'_>, func: F) -> Result<R, GlesError>
where
F: FnOnce(&Arc<Context>) -> R,
{
fb.0.make_current(&self.gl.gl, &self.gl.egl_context());
Ok(func(&self.glow))
}
}

impl GlowFrame<'_, '_> {
Expand Down
22 changes: 16 additions & 6 deletions src/backend/winit/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
//! The other types in this module are the instances of the associated types of these
//! two traits for the winit backend.

use std::borrow::BorrowMut;
use std::io::Error as IoError;
use std::sync::Arc;
use std::time::Duration;
Expand Down Expand Up @@ -251,7 +252,7 @@ pub struct WinitGraphicsBackend<R> {

impl<R> WinitGraphicsBackend<R>
where
R: Bind<EGLSurface>,
R: Bind<EGLSurface> + BorrowMut<GlesRenderer>,
crate::backend::SwapBuffersError: From<R::Error>,
{
/// Window size of the underlying window
Expand Down Expand Up @@ -304,15 +305,24 @@ where

/// Retrieve the buffer age of the current backbuffer of the window.
///
/// This will only return a meaningful value, if this `WinitGraphicsBackend`
/// is currently bound (by previously calling [`WinitGraphicsBackend::bind`]).
///
/// Otherwise and on error this function returns `None`.
/// On error this function returns `None`.
/// If you are using this value actively e.g. for damage-tracking you should
/// likely interpret an error just as if "0" was returned.
#[instrument(level = "trace", parent = &self.span, skip(self))]
pub fn buffer_age(&self) -> Option<usize> {
pub fn buffer_age(&mut self) -> Option<usize> {
if self.damage_tracking {
{
let window_size = self.window_size();
if Some(window_size) != self.bind_size {
self.egl_surface.resize(window_size.w, window_size.h, 0, 0);
}
self.bind_size = Some(window_size);

let gles = self.renderer.borrow_mut();
let fb = gles.bind(&mut self.egl_surface).ok()?;
gles.with_context_bound_fb(&fb, |_| {}).ok()?;
// We know the gles renderer doesn't unbind the framebuffer from dropping
}
self.egl_surface.buffer_age().map(|x| x as usize)
} else {
Some(0)
Expand Down
Loading