Skip to content

Commit f7688b4

Browse files
authored
Use dummy pbuffer on unix egl and various fixups (#332)
* Pass gl to `ContextDescriptor::from_egl_context` * Remove make_current call in `from_egl_context` it was needed before for version query, but it should not be needed anymore as we use glow's cached version this will probably fix servo/servo#29463 * error on not current * flush * Use pbuffer on EGL * --test-threads 1 Signed-off-by: sagudev <[email protected]> * Update main.yml --------- Signed-off-by: sagudev <[email protected]>
1 parent a8079ee commit f7688b4

File tree

8 files changed

+52
-44
lines changed

8 files changed

+52
-44
lines changed

.github/workflows/main.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ jobs:
6767
if: ${{ matrix.platform.test && startsWith(matrix.platform.os, 'ubuntu') }}
6868
run: |
6969
weston --no-config --socket=wl-test-env --backend=headless &
70-
WAYLAND_DISPLAY=wl-test-env xvfb-run cargo test --features "${{ matrix.features }}" --target ${{ matrix.platform.target }}
70+
WAYLAND_DISPLAY=wl-test-env xvfb-run cargo test --features "${{ matrix.features }}" --target ${{ matrix.platform.target }} -- --test-threads 1
7171
- name: Test
7272
if: ${{ matrix.platform.test && !startsWith(matrix.platform.os, 'ubuntu') }}
7373
run: |
@@ -115,7 +115,7 @@ jobs:
115115
script: |
116116
cargo dinghy all-platforms
117117
cargo dinghy all-devices
118-
cargo dinghy -p auto-android-x86_64-api30 --env RUST_BACKTRACE=${{ env.RUST_BACKTRACE }} test --features "${{ matrix.features }}" -- --test-threads 1
118+
cargo dinghy -p auto-android-x86_64-api30 --env RUST_BACKTRACE=${{ env.RUST_BACKTRACE }} test --features "${{ matrix.features }}" -- --test-threads 1 --nocapture
119119
120120
Format:
121121
name: Run `rustfmt`

src/platform/egl/context.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ impl Device {
105105
)?;
106106

107107
// Create a dummy pbuffer.
108-
let pbuffer = context::create_dummy_pbuffer(egl_display, egl_context);
108+
let pbuffer = context::create_dummy_pbuffer(egl_display, egl_context).unwrap();
109109

110110
EGL_FUNCTIONS.with(|egl| {
111111
if egl.MakeCurrent(egl_display, pbuffer, pbuffer, egl_context) == egl::FALSE {
@@ -141,7 +141,8 @@ impl Device {
141141
let mut next_context_id = CREATE_CONTEXT_MUTEX.lock().unwrap();
142142

143143
// Create a dummy pbuffer.
144-
let pbuffer = context::create_dummy_pbuffer(self.egl_display, native_context.egl_context);
144+
let pbuffer =
145+
context::create_dummy_pbuffer(self.egl_display, native_context.egl_context).unwrap();
145146

146147
// Create the context.
147148
let context = Context {
@@ -202,11 +203,7 @@ impl Device {
202203
/// Returns the descriptor that this context was created with.
203204
pub fn context_descriptor(&self, context: &Context) -> ContextDescriptor {
204205
unsafe {
205-
ContextDescriptor::from_egl_context(
206-
context::get_proc_address,
207-
self.egl_display,
208-
context.egl_context,
209-
)
206+
ContextDescriptor::from_egl_context(&context.gl, self.egl_display, context.egl_context)
210207
}
211208
}
212209

src/platform/generic/egl/context.rs

+36-23
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use crate::egl::types::{EGLConfig, EGLContext, EGLDisplay, EGLSurface, EGLint};
1313
use crate::surface::Framebuffer;
1414
use crate::{ContextAttributeFlags, ContextAttributes, ContextID, Error, GLApi, GLVersion};
1515
use crate::{Gl, SurfaceInfo};
16+
use glow::HasContext;
1617

1718
use std::ffi::CString;
1819
use std::mem;
@@ -27,6 +28,7 @@ const RGB_CHANNEL_BIT_DEPTH: EGLint = 8;
2728
pub(crate) struct EGLBackedContext {
2829
pub(crate) egl_context: EGLContext,
2930
pub(crate) id: ContextID,
31+
pbuffer: EGLSurface,
3032
framebuffer: Framebuffer<EGLBackedSurface, ExternalEGLSurfaces>,
3133
context_is_owned: bool,
3234
}
@@ -101,12 +103,16 @@ impl EGLBackedContext {
101103
gl_api,
102104
)?;
103105

106+
// Create a dummy pbuffer.
107+
let pbuffer = create_dummy_pbuffer(egl_display, egl_context).unwrap_or(egl::NO_SURFACE);
108+
104109
// Wrap and return it.
105110
let context = EGLBackedContext {
106111
egl_context,
107112
id: *next_context_id,
108113
framebuffer: Framebuffer::None,
109114
context_is_owned: true,
115+
pbuffer,
110116
};
111117
next_context_id.0 += 1;
112118
Ok(context)
@@ -122,13 +128,20 @@ impl EGLBackedContext {
122128
read: native_context.egl_read_surface,
123129
}),
124130
context_is_owned: false,
131+
pbuffer: egl::NO_SURFACE,
125132
};
126133
next_context_id.0 += 1;
127134
context
128135
}
129136

130137
pub(crate) unsafe fn destroy(&mut self, egl_display: EGLDisplay) {
131138
EGL_FUNCTIONS.with(|egl| {
139+
if self.pbuffer != egl::NO_SURFACE {
140+
let result = egl.DestroySurface(egl_display, self.pbuffer);
141+
assert_ne!(result, egl::FALSE);
142+
self.pbuffer = egl::NO_SURFACE;
143+
}
144+
132145
egl.MakeCurrent(
133146
egl_display,
134147
egl::NO_SURFACE,
@@ -163,7 +176,10 @@ impl EGLBackedContext {
163176
let egl_surfaces = match self.framebuffer {
164177
Framebuffer::Surface(ref surface) => surface.egl_surfaces(),
165178
Framebuffer::External(ref surfaces) => (*surfaces).clone(),
166-
Framebuffer::None => ExternalEGLSurfaces::default(),
179+
Framebuffer::None => ExternalEGLSurfaces {
180+
draw: self.pbuffer,
181+
read: self.pbuffer,
182+
},
167183
};
168184

169185
EGL_FUNCTIONS.with(|egl| {
@@ -214,6 +230,9 @@ impl EGLBackedContext {
214230
gl: &Gl,
215231
egl_display: EGLDisplay,
216232
) -> Result<Option<EGLBackedSurface>, Error> {
233+
// Flush to avoid races on Mesa/Intel and possibly other GPUs.
234+
gl.flush();
235+
217236
match self.framebuffer {
218237
Framebuffer::None => return Ok(None),
219238
Framebuffer::Surface(_) => {}
@@ -382,29 +401,20 @@ impl ContextDescriptor {
382401
})
383402
}
384403

385-
pub(crate) unsafe fn from_egl_context<F>(
386-
get_proc_address: F,
404+
pub(crate) unsafe fn from_egl_context(
405+
gl: &Gl,
387406
egl_display: EGLDisplay,
388407
egl_context: EGLContext,
389-
) -> ContextDescriptor
390-
where
391-
F: FnMut(&str) -> *const c_void,
392-
{
408+
) -> ContextDescriptor {
393409
let egl_config_id = get_context_attr(egl_display, egl_context, egl::CONFIG_ID as EGLint);
410+
let gl_version = GLVersion::current(&gl);
411+
let compatibility_profile = context::current_context_uses_compatibility_profile(&gl);
394412

395-
EGL_FUNCTIONS.with(|egl| {
396-
let _guard = CurrentContextGuard::new();
397-
egl.MakeCurrent(egl_display, egl::NO_SURFACE, egl::NO_SURFACE, egl_context);
398-
let gl = unsafe { Gl::from_loader_function(get_proc_address) };
399-
let gl_version = GLVersion::current(&gl);
400-
let compatibility_profile = context::current_context_uses_compatibility_profile(&gl);
401-
402-
ContextDescriptor {
403-
egl_config_id,
404-
gl_version,
405-
compatibility_profile,
406-
}
407-
})
413+
ContextDescriptor {
414+
egl_config_id,
415+
gl_version,
416+
compatibility_profile,
417+
}
408418
}
409419

410420
#[allow(dead_code)]
@@ -609,7 +619,7 @@ pub(crate) fn get_proc_address(symbol_name: &str) -> *const c_void {
609619
pub(crate) unsafe fn create_dummy_pbuffer(
610620
egl_display: EGLDisplay,
611621
egl_context: EGLContext,
612-
) -> EGLSurface {
622+
) -> Option<EGLSurface> {
613623
let egl_config_id = get_context_attr(egl_display, egl_context, egl::CONFIG_ID as EGLint);
614624
let egl_config = egl_config_from_id(egl_display, egl_config_id);
615625

@@ -627,7 +637,10 @@ pub(crate) unsafe fn create_dummy_pbuffer(
627637
EGL_FUNCTIONS.with(|egl| {
628638
let pbuffer =
629639
egl.CreatePbufferSurface(egl_display, egl_config, pbuffer_attributes.as_ptr());
630-
assert_ne!(pbuffer, egl::NO_SURFACE);
631-
pbuffer
640+
if pbuffer == egl::NO_SURFACE {
641+
None
642+
} else {
643+
Some(pbuffer)
644+
}
632645
})
633646
}

src/platform/generic/egl/surface.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,12 @@ impl EGLBackedSurface {
271271
let _guard = CurrentContextGuard::new();
272272

273273
EGL_FUNCTIONS.with(|egl| {
274-
egl.MakeCurrent(egl_display, egl_surface, egl_surface, egl_context);
274+
let result =
275+
egl.MakeCurrent(egl_display, egl_surface, egl_surface, egl_context);
276+
if result == egl::FALSE {
277+
let err = egl.GetError().to_windowing_api_error();
278+
return Err(Error::MakeCurrentFailed(err));
279+
}
275280

276281
let ok = egl.SwapBuffers(egl_display, egl_surface);
277282
if ok != egl::FALSE {
@@ -324,9 +329,6 @@ impl EGLBackedSurface {
324329
return;
325330
}
326331

327-
// Flush to avoid races on Mesa/Intel and possibly other GPUs.
328-
gl.flush();
329-
330332
egl.MakeCurrent(egl_display, egl::NO_SURFACE, egl::NO_SURFACE, egl_context);
331333

332334
match self.objects {

src/platform/unix/generic/context.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ impl Device {
126126
pub fn context_descriptor(&self, context: &Context) -> ContextDescriptor {
127127
unsafe {
128128
ContextDescriptor::from_egl_context(
129-
context::get_proc_address,
129+
&context.1,
130130
self.native_connection.egl_display,
131131
context.0.egl_context,
132132
)

src/platform/unix/wayland/context.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ impl Device {
124124
pub fn context_descriptor(&self, context: &Context) -> ContextDescriptor {
125125
unsafe {
126126
ContextDescriptor::from_egl_context(
127-
context::get_proc_address,
127+
&context.1,
128128
self.native_connection.egl_display,
129129
context.0.egl_context,
130130
)

src/platform/unix/x11/context.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ impl Device {
124124
pub fn context_descriptor(&self, context: &Context) -> ContextDescriptor {
125125
unsafe {
126126
ContextDescriptor::from_egl_context(
127-
context::get_proc_address,
127+
&context.1,
128128
self.native_connection.egl_display,
129129
context.0.egl_context,
130130
)

src/platform/windows/angle/context.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -187,11 +187,7 @@ impl Device {
187187
/// Returns the descriptor that this context was created with.
188188
pub fn context_descriptor(&self, context: &Context) -> ContextDescriptor {
189189
unsafe {
190-
ContextDescriptor::from_egl_context(
191-
context::get_proc_address,
192-
self.egl_display,
193-
context.egl_context,
194-
)
190+
ContextDescriptor::from_egl_context(&context.gl, self.egl_display, context.egl_context)
195191
}
196192
}
197193

0 commit comments

Comments
 (0)