From 46cbbda9445d14ed0900a854bd81fe9766f112c1 Mon Sep 17 00:00:00 2001 From: Aliaksandr Kalenik Date: Fri, 29 Nov 2024 23:15:43 +0100 Subject: [PATCH] LibWeb: Increase SkSurface's generation id when it's modified by WebGL Skia is not aware of surface modifications done by WebGL, so we need to manually increase generation id whenver WebGL invokes a writing function. --- Libraries/LibGfx/PaintingSurface.cpp | 5 +++++ Libraries/LibGfx/PaintingSurface.h | 2 ++ Libraries/LibWeb/WebGL/OpenGLContext.cpp | 5 +++++ Libraries/LibWeb/WebGL/OpenGLContext.h | 1 + .../CodeGenerators/LibWeb/GenerateWebGLRenderingContext.cpp | 4 ++++ 5 files changed, 17 insertions(+) diff --git a/Libraries/LibGfx/PaintingSurface.cpp b/Libraries/LibGfx/PaintingSurface.cpp index c23b524678f..48a554f7326 100644 --- a/Libraries/LibGfx/PaintingSurface.cpp +++ b/Libraries/LibGfx/PaintingSurface.cpp @@ -114,6 +114,11 @@ SkSurface& PaintingSurface::sk_surface() const return *m_impl->surface; } +void PaintingSurface::notify_content_will_change() +{ + m_impl->surface->notifyContentWillChange(SkSurface::kDiscard_ContentChangeMode); +} + template<> sk_sp PaintingSurface::sk_image_snapshot() const { diff --git a/Libraries/LibGfx/PaintingSurface.h b/Libraries/LibGfx/PaintingSurface.h index ea5e84dc56e..33797606be3 100644 --- a/Libraries/LibGfx/PaintingSurface.h +++ b/Libraries/LibGfx/PaintingSurface.h @@ -34,6 +34,8 @@ public: void read_into_bitmap(Bitmap&); void write_from_bitmap(Bitmap&); + void notify_content_will_change(); + IntSize size() const; IntRect rect() const; diff --git a/Libraries/LibWeb/WebGL/OpenGLContext.cpp b/Libraries/LibWeb/WebGL/OpenGLContext.cpp index bf9a3d0684d..95a6504c112 100644 --- a/Libraries/LibWeb/WebGL/OpenGLContext.cpp +++ b/Libraries/LibWeb/WebGL/OpenGLContext.cpp @@ -108,6 +108,11 @@ OwnPtr OpenGLContext::create(NonnullRefPtrnotify_content_will_change(); +} + void OpenGLContext::clear_buffer_to_default_values() { } diff --git a/Libraries/LibWeb/WebGL/OpenGLContext.h b/Libraries/LibWeb/WebGL/OpenGLContext.h index c5554816f4f..d9c15601d89 100644 --- a/Libraries/LibWeb/WebGL/OpenGLContext.h +++ b/Libraries/LibWeb/WebGL/OpenGLContext.h @@ -15,6 +15,7 @@ class OpenGLContext { public: static OwnPtr create(NonnullRefPtr); + void notify_content_will_change(); void clear_buffer_to_default_values(); void allocate_painting_surface_if_needed(); diff --git a/Meta/Lagom/Tools/CodeGenerators/LibWeb/GenerateWebGLRenderingContext.cpp b/Meta/Lagom/Tools/CodeGenerators/LibWeb/GenerateWebGLRenderingContext.cpp index 25dce0c5d92..08fc720e25e 100644 --- a/Meta/Lagom/Tools/CodeGenerators/LibWeb/GenerateWebGLRenderingContext.cpp +++ b/Meta/Lagom/Tools/CodeGenerators/LibWeb/GenerateWebGLRenderingContext.cpp @@ -205,6 +205,10 @@ public: m_context->make_current(); )~~~"); + if (gl_function_modifies_framebuffer(function.name)) { + function_impl_generator.append(" m_context->notify_content_will_change();\n"sv); + } + Vector gl_call_arguments; for (size_t i = 0; i < function.parameters.size(); ++i) { auto const& parameter = function.parameters[i];