diff --git a/Libraries/LibWeb/WebGL/OpenGLContext.cpp b/Libraries/LibWeb/WebGL/OpenGLContext.cpp index 062efa0ca37..d61745f7bb9 100644 --- a/Libraries/LibWeb/WebGL/OpenGLContext.cpp +++ b/Libraries/LibWeb/WebGL/OpenGLContext.cpp @@ -13,7 +13,10 @@ #ifdef AK_OS_MACOS # include # include +# define EGL_EGLEXT_PROTOTYPES 1 +extern "C" { # include +} # define GL_GLEXT_PROTOTYPES 1 # include # include @@ -245,6 +248,28 @@ void OpenGLContext::make_current() #endif } +void OpenGLContext::present(bool preserve_drawing_buffer) +{ + make_current(); + + // "Before the drawing buffer is presented for compositing the implementation shall ensure that all rendering operations have been flushed to the drawing buffer." + // With Metal, glFlush flushes the command buffer, but without waiting for it to be scheduled or completed. + // eglWaitUntilWorkScheduledANGLE flushes the command buffer, and waits until it has been scheduled, hence the name. + // eglWaitUntilWorkScheduledANGLE only has an effect on CGL and Metal backends, so we only use it on macOS. +#ifdef AK_OS_MACOS + eglWaitUntilWorkScheduledANGLE(m_impl->display); +#else + // FIXME: When enabling WebGL for Linux, we need to use glFlush() here. +#endif + + // "By default, after compositing the contents of the drawing buffer shall be cleared to their default values, as shown in the table above. + // This default behavior can be changed by setting the preserveDrawingBuffer attribute of the WebGLContextAttributes object. + // If this flag is true, the contents of the drawing buffer shall be preserved until the author either clears or overwrites them." + if (!preserve_drawing_buffer) { + clear_buffer_to_default_values(); + } +} + RefPtr OpenGLContext::surface() { return m_painting_surface; diff --git a/Libraries/LibWeb/WebGL/OpenGLContext.h b/Libraries/LibWeb/WebGL/OpenGLContext.h index a66c4c838c0..013a558b66f 100644 --- a/Libraries/LibWeb/WebGL/OpenGLContext.h +++ b/Libraries/LibWeb/WebGL/OpenGLContext.h @@ -31,6 +31,8 @@ public: void make_current(); + void present(bool preserve_drawing_buffer); + void set_size(Gfx::IntSize const&); RefPtr surface(); diff --git a/Libraries/LibWeb/WebGL/WebGL2RenderingContext.cpp b/Libraries/LibWeb/WebGL/WebGL2RenderingContext.cpp index e86c02c94b3..5ee2d035bac 100644 --- a/Libraries/LibWeb/WebGL/WebGL2RenderingContext.cpp +++ b/Libraries/LibWeb/WebGL/WebGL2RenderingContext.cpp @@ -84,16 +84,7 @@ void WebGL2RenderingContext::present() return; m_should_present = false; - - // "Before the drawing buffer is presented for compositing the implementation shall ensure that all rendering operations have been flushed to the drawing buffer." - glFlush(); - - // "By default, after compositing the contents of the drawing buffer shall be cleared to their default values, as shown in the table above. - // This default behavior can be changed by setting the preserveDrawingBuffer attribute of the WebGLContextAttributes object. - // If this flag is true, the contents of the drawing buffer shall be preserved until the author either clears or overwrites them." - if (!m_context_creation_parameters.preserve_drawing_buffer) { - context().clear_buffer_to_default_values(); - } + context().present(m_context_creation_parameters.preserve_drawing_buffer); } GC::Ref WebGL2RenderingContext::canvas_for_binding() const diff --git a/Libraries/LibWeb/WebGL/WebGLRenderingContext.cpp b/Libraries/LibWeb/WebGL/WebGLRenderingContext.cpp index cdc63b01ca7..c059307337e 100644 --- a/Libraries/LibWeb/WebGL/WebGLRenderingContext.cpp +++ b/Libraries/LibWeb/WebGL/WebGLRenderingContext.cpp @@ -106,16 +106,7 @@ void WebGLRenderingContext::present() return; m_should_present = false; - - // "Before the drawing buffer is presented for compositing the implementation shall ensure that all rendering operations have been flushed to the drawing buffer." - glFlush(); - - // "By default, after compositing the contents of the drawing buffer shall be cleared to their default values, as shown in the table above. - // This default behavior can be changed by setting the preserveDrawingBuffer attribute of the WebGLContextAttributes object. - // If this flag is true, the contents of the drawing buffer shall be preserved until the author either clears or overwrites them." - if (!m_context_creation_parameters.preserve_drawing_buffer) { - context().clear_buffer_to_default_values(); - } + context().present(m_context_creation_parameters.preserve_drawing_buffer); } GC::Ref WebGLRenderingContext::canvas_for_binding() const