Truly independent web browser
LibGfx+Compositor: Check row alignment only for decoded frames
sideshowbarkeraf4fd683f654
diff --git a/Libraries/LibGfx/MetalContext.h b/Libraries/LibGfx/MetalContext.hindex 28045ee8741..027a8e5980b 100644--- a/Libraries/LibGfx/MetalContext.h+++ b/Libraries/LibGfx/MetalContext.h@@ -42,6 +42,8 @@ public:virtual void const* queue() const = 0;virtual OwnPtr<MetalTexture> create_texture_from_iosurface(Core::IOSurfaceHandle const&, MetalTextureFormat, size_t plane) = 0;+ // Whether the rows of the surface's plane are aligned as the GPU needs the rows of a linear texture in that format.+ virtual bool rows_have_linear_texture_alignment(Core::IOSurfaceHandle const&, MetalTextureFormat, size_t plane) const = 0;// Calls back on a Metal thread.virtual void when_committed_work_is_scheduled(Function<void()>&&) = 0;diff --git a/Libraries/LibGfx/MetalContext.mm b/Libraries/LibGfx/MetalContext.mmindex c94f3322a96..56e8098f417 100644--- a/Libraries/LibGfx/MetalContext.mm+++ b/Libraries/LibGfx/MetalContext.mm@@ -69,11 +69,6 @@ public:OwnPtr<MetalTexture> create_texture_from_iosurface(Core::IOSurfaceHandle const& iosurface, MetalTextureFormat format, size_t plane) override{auto pixel_format = metal_pixel_format(format);- // NB: The surface may come from another process, which need not have aligned its rows as the GPU needs them.- auto bytes_per_row = iosurface.plane_count() > 0 ? iosurface.bytes_per_row_of_plane(plane) : iosurface.bytes_per_row();- if (bytes_per_row % [m_device minimumLinearTextureAlignmentForPixelFormat:pixel_format] != 0)- return {};-auto* const descriptor = [[MTLTextureDescriptor alloc] init];descriptor.pixelFormat = pixel_format;descriptor.width = iosurface.plane_count() > 0 ? iosurface.plane_width(plane) : iosurface.width();@@ -88,6 +83,12 @@ public:return make<MetalTextureImpl>(texture);}+ bool rows_have_linear_texture_alignment(Core::IOSurfaceHandle const& iosurface, MetalTextureFormat format, size_t plane) const override+ {+ auto bytes_per_row = iosurface.plane_count() > 0 ? iosurface.bytes_per_row_of_plane(plane) : iosurface.bytes_per_row();+ return bytes_per_row % [m_device minimumLinearTextureAlignmentForPixelFormat:metal_pixel_format(format)] == 0;+ }+void when_committed_work_is_scheduled(Function<void()>&& callback) override{// The queue schedules its command buffers in the order they were committed.diff --git a/Services/Compositor/SkiaUtils.cpp b/Services/Compositor/SkiaUtils.cppindex b9dae18c38a..a8267857233 100644--- a/Services/Compositor/SkiaUtils.cpp+++ b/Services/Compositor/SkiaUtils.cpp@@ -494,7 +494,12 @@ sk_sp<SkImage> sk_texture_image_sharing_pixels_of_decoded_image_frame([[maybe_unreturn nullptr;auto texture_format = first_is_one_of(frame.format(), BitmapFormat::RGBA8888, BitmapFormat::RGBx8888) ? MetalTextureFormat::RGBA8 : MetalTextureFormat::BGRA8;- auto metal_texture = skia_backend_context.metal_context().create_texture_from_iosurface(*iosurface, texture_format, 0);+ // The frame's surface may come from another process, which need not have aligned its rows as the GPU needs them,+ // so such a frame is uploaded instead.+ auto& metal_context = skia_backend_context.metal_context();+ if (!metal_context.rows_have_linear_texture_alignment(*iosurface, texture_format, 0))+ return nullptr;+ auto metal_texture = metal_context.create_texture_from_iosurface(*iosurface, texture_format, 0);if (!metal_texture)return nullptr;