From 20ebb70d30209b5a3e272b98990a3a08a695b98a Mon Sep 17 00:00:00 2001 From: Christian Meissl Date: Fri, 15 Sep 2023 12:16:31 +0200 Subject: [PATCH] multigpu: allow to specify the egl context priority --- src/backend/renderer/multigpu/egl.rs | 20 ++++++++++++++++++-- src/backend/renderer/multigpu/gbm.rs | 20 ++++++++++++++++++-- 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/src/backend/renderer/multigpu/egl.rs b/src/backend/renderer/multigpu/egl.rs index 91ad1f5daca1..52465a7dd4ff 100644 --- a/src/backend/renderer/multigpu/egl.rs +++ b/src/backend/renderer/multigpu/egl.rs @@ -7,7 +7,7 @@ use wayland_server::protocol::wl_buffer; use crate::backend::{ drm::{CreateDrmNodeError, DrmNode}, - egl::{EGLContext, EGLDevice, EGLDisplay, Error as EGLError}, + egl::{context::ContextPriority, EGLContext, EGLDevice, EGLDisplay, Error as EGLError}, renderer::{ gles::{GlesError, GlesRenderer}, multigpu::{ApiDevice, Error as MultiError, GraphicsApi}, @@ -58,6 +58,7 @@ type Factory = Box Result>; /// A [`GraphicsApi`] utilizing EGL for device enumeration and OpenGL ES for rendering. pub struct EglGlesBackend { factory: Option, + context_priority: Option, _renderer: std::marker::PhantomData, } @@ -71,6 +72,7 @@ impl Default for EglGlesBackend { fn default() -> Self { EglGlesBackend { factory: None, + context_priority: None, _renderer: std::marker::PhantomData, } } @@ -87,6 +89,18 @@ impl EglGlesBackend { ..Default::default() } } + + /// Initialize a new [`EglGlesBackend`] with a [`ContextPriority`] for instantiating [`GlesRenderer`]s + /// + /// Note: This is mutually exclusive with [`EglGlesBackend::with_factory`](EglGlesBackend::with_factory), + /// but you can create an [`EGLContext`] with a specific [`ContextPriority`] within your factory. + /// See [`EGLContext::new_with_priority`] for more information. + pub fn with_context_priority(priority: ContextPriority) -> Self { + Self { + context_priority: Some(priority), + ..Default::default() + } + } } impl + Renderer> GraphicsApi for EglGlesBackend { @@ -113,7 +127,9 @@ impl + Renderer> GraphicsApi for EglGle let renderer = if let Some(factory) = self.factory.as_ref() { factory(&display)?.into() } else { - let context = EGLContext::new(&display).map_err(Error::Egl)?; + let context = + EGLContext::new_with_priority(&display, self.context_priority.unwrap_or_default()) + .map_err(Error::Egl)?; unsafe { GlesRenderer::new(context).map_err(Error::Gl)? }.into() }; diff --git a/src/backend/renderer/multigpu/gbm.rs b/src/backend/renderer/multigpu/gbm.rs index d57cc7e8b6cf..08e548b45834 100644 --- a/src/backend/renderer/multigpu/gbm.rs +++ b/src/backend/renderer/multigpu/gbm.rs @@ -7,7 +7,7 @@ use wayland_server::protocol::wl_buffer; use crate::backend::{ drm::{CreateDrmNodeError, DrmNode}, - egl::{EGLContext, EGLDisplay, Error as EGLError}, + egl::{context::ContextPriority, EGLContext, EGLDisplay, Error as EGLError}, renderer::{ gles::{GlesError, GlesRenderer}, multigpu::{ApiDevice, Error as MultiError, GraphicsApi}, @@ -61,6 +61,7 @@ type Factory = Box Result>; pub struct GbmGlesBackend { devices: HashMap, factory: Option, + context_priority: Option, _renderer: std::marker::PhantomData, } @@ -77,6 +78,7 @@ impl Default for GbmGlesBackend { GbmGlesBackend { devices: HashMap::new(), factory: None, + context_priority: None, _renderer: std::marker::PhantomData, } } @@ -94,6 +96,18 @@ impl GbmGlesBackend { } } + /// Initialize a new [`GbmGlesBackend`] with a [`ContextPriority`] for instantiating [`GlesRenderer`]s + /// + /// Note: This is mutually exclusive with [`GbmGlesBackend::with_factory`](GbmGlesBackend::with_factory), + /// but you can create an [`EGLContext`] with a specific [`ContextPriority`] within your factory. + /// See [`EGLContext::new_with_priority`] for more information. + pub fn with_context_priority(priority: ContextPriority) -> Self { + Self { + context_priority: Some(priority), + ..Default::default() + } + } + /// Add a new GBM device for a given node to the api pub fn add_node( &mut self, @@ -135,7 +149,9 @@ impl + Renderer> GraphicsApi for GbmGle let renderer = if let Some(factory) = self.factory.as_ref() { factory(display)?.into() } else { - let context = EGLContext::new(display).map_err(Error::Egl)?; + let context = + EGLContext::new_with_priority(display, self.context_priority.unwrap_or_default()) + .map_err(Error::Egl)?; unsafe { GlesRenderer::new(context).map_err(Error::Gl)? }.into() };