Skip to content

Truly independent web browser

Compositor: Draw a canvas too large for a GPU texture from memory

sideshowbarkerfe6b51642fc2
diff --git a/Services/Compositor/SkiaBackendContext.cpp b/Services/Compositor/SkiaBackendContext.cpp
index 118fa248fad..0423fb3c8e7 100644
--- a/Services/Compositor/SkiaBackendContext.cpp
+++ b/Services/Compositor/SkiaBackendContext.cpp
@@ -193,6 +193,15 @@ size_t SkiaBackendContext::resource_cache_bytes() const
return bytes;
}
+bool SkiaBackendContext::can_hold_texture_of_size(IntSize size) const
+{
+ auto* context = sk_context();
+ if (!context)
+ return false;
+ auto max_texture_size = context->maxTextureSize();
+ return size.width() <= max_texture_size && size.height() <= max_texture_size;
+}
+
void SkiaBackendContext::initialize_gpu_backend(Optional<GpuDeviceIdentity> const& preferred_device)
{
VERIFY(!main_thread_context());
diff --git a/Services/Compositor/SkiaBackendContext.h b/Services/Compositor/SkiaBackendContext.h
index c0f70a9ded3..9fec798bba1 100644
--- a/Services/Compositor/SkiaBackendContext.h
+++ b/Services/Compositor/SkiaBackendContext.h
@@ -12,6 +12,7 @@
#include <AK/Optional.h>
#include <LibCore/Timer.h>
#include <LibGfx/GpuDeviceIdentity.h>
+#include <LibGfx/Size.h>
#ifdef USE_DIRECTX
# include <LibGfx/Direct3DContext.h>
@@ -66,6 +67,9 @@ public:
void flush_and_submit_async(Function<void()>&&);
void check_async_work_completion();
size_t resource_cache_bytes() const;
+ // Whether a texture of this size fits within the largest the GPU allows. On macOS, asking Metal for a larger
+ // texture over an IOSurface aborts the process, rather than failing.
+ bool can_hold_texture_of_size(IntSize) const;
virtual GrDirectContext* sk_context() const = 0;
virtual MetalContext& metal_context() = 0;
diff --git a/Services/Compositor/WindowServer.cpp b/Services/Compositor/WindowServer.cpp
index 2970b71a68f..759e70e69f0 100644
--- a/Services/Compositor/WindowServer.cpp
+++ b/Services/Compositor/WindowServer.cpp
@@ -4,6 +4,7 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
+#include <Compositor/SkiaBackendContext.h>
#include <Compositor/WindowServer.h>
#include <stdlib.h>
@@ -26,8 +27,12 @@ RefPtr<WindowServer> WindowServer::try_create_for_presentation()
#endif
}
-ErrorOr<RefPtr<PresentableSurface>> WindowServer::try_create_presentable_surface_for_sublayers([[maybe_unused]] Gfx::IntSize size, [[maybe_unused]] Gfx::SkiaBackendContext& skia_backend_context)
+ErrorOr<RefPtr<PresentableSurface>> WindowServer::try_create_presentable_surface_for_sublayers(Gfx::IntSize size, Gfx::SkiaBackendContext& skia_backend_context)
{
+ // NB: A surface larger than the GPU's largest texture can't be a sublayer of its own, so it's drawn into the frame
+ // from memory instead.
+ if (!skia_backend_context.can_hold_texture_of_size(size))
+ return nullptr;
#ifdef AK_OS_MACOS
return RefPtr<PresentableSurface> { TRY(CoreAnimationWindowServer::try_create_presentable_surface_over_new_iosurface(size, skia_backend_context)) };
#elif defined(AK_OS_WINDOWS) && defined(USE_DIRECTX)