diff --git a/include/test/mir/test/doubles/mock_gl.h b/include/test/mir/test/doubles/mock_gl.h index 9e8a1563a8..585a124059 100644 --- a/include/test/mir/test/doubles/mock_gl.h +++ b/include/test/mir/test/doubles/mock_gl.h @@ -65,6 +65,7 @@ class MockGL MOCK_METHOD(void, glEnable, (GLenum)); MOCK_METHOD(void, glEnableVertexAttribArray, (GLuint)); MOCK_METHOD(void, glFinish, ()); + MOCK_METHOD(void, glFlush, ()); MOCK_METHOD(void, glFramebufferRenderbuffer, (GLenum, GLenum, GLenum, GLuint)); MOCK_METHOD(void, glFramebufferTexture2D, diff --git a/src/platforms/common/server/shm_buffer.cpp b/src/platforms/common/server/shm_buffer.cpp index 7459edd353..52f4e9c86b 100644 --- a/src/platforms/common/server/shm_buffer.cpp +++ b/src/platforms/common/server/shm_buffer.cpp @@ -111,7 +111,7 @@ auto get_tex_id_on_context(mgc::EGLContextExecutor& egl_executor) -> std::shared // Paranoia: Save the current value for the GL state that we're modifying... GLint previous_texture; - glGetIntegerv(GL_TEXTURE_2D, &previous_texture); + glGetIntegerv(GL_TEXTURE_BINDING_2D, &previous_texture); glBindTexture(GL_TEXTURE_2D, tex); // The ShmBuffer *should* be immutable, so we can just set up the properties once @@ -122,6 +122,16 @@ auto get_tex_id_on_context(mgc::EGLContextExecutor& egl_executor) -> std::shared // ...and then restore the previous GL state. glBindTexture(GL_TEXTURE_2D, static_cast(previous_texture)); + + /* We need these commands to be in the driver command stream before + * anything which uses them can be executed (which will likely be + * on another thread, in another EGLContext). + * + * glFlush() before the promise synchronisation point will ensure + * those commands are visible to the driver before we try and use + * their results. + */ + glFlush(); tex_promise->set_value(tex); }); return tex_promise->get_future(); diff --git a/tests/mir_test_doubles/mock_gl.cpp b/tests/mir_test_doubles/mock_gl.cpp index 8daf138983..f62e8f31bd 100644 --- a/tests/mir_test_doubles/mock_gl.cpp +++ b/tests/mir_test_doubles/mock_gl.cpp @@ -450,6 +450,12 @@ void glFinish() global_mock_gl->glFinish(); } +void glFlush() +{ + CHECK_GLOBAL_VOID_MOCK(); + global_mock_gl->glFlush(); +} + void glGenerateMipmap(GLenum target) { CHECK_GLOBAL_VOID_MOCK();