mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-01-22 09:12:13 -05:00
LibGfx+LibWeb: Specify bottom left origin for WebGL's PaintingSurface
By doing that we eliminate the need for the vertical flip flag. As a side effect it fixes the bug when doing: `canvasContext2d.drawImage(canvasWithWebGLContext, 0, 0);` produced a flipped image because we didn't account for different origin while serializing PaintingSurface into Gfx::Bitmap. Visual progress on https://ciechanow.ski/curves-and-surfaces/
This commit is contained in:
parent
28388f1fd2
commit
30d915c361
Notes:
github-actions[bot]
2024-12-20 19:48:39 +00:00
Author: https://github.com/kalenikaliaksandr Commit: https://github.com/LadybirdBrowser/ladybird/commit/30d915c361b Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2994
4 changed files with 20 additions and 19 deletions
|
@ -56,7 +56,7 @@ NonnullRefPtr<PaintingSurface> PaintingSurface::wrap_bitmap(Bitmap& bitmap)
|
|||
}
|
||||
|
||||
#ifdef AK_OS_MACOS
|
||||
NonnullRefPtr<PaintingSurface> PaintingSurface::wrap_iosurface(Core::IOSurfaceHandle const& iosurface_handle, RefPtr<SkiaBackendContext> context)
|
||||
NonnullRefPtr<PaintingSurface> PaintingSurface::wrap_iosurface(Core::IOSurfaceHandle const& iosurface_handle, RefPtr<SkiaBackendContext> context, Origin origin)
|
||||
{
|
||||
auto metal_texture = context->metal_context().create_texture_from_iosurface(iosurface_handle);
|
||||
IntSize const size { metal_texture->width(), metal_texture->height() };
|
||||
|
@ -64,7 +64,18 @@ NonnullRefPtr<PaintingSurface> PaintingSurface::wrap_iosurface(Core::IOSurfaceHa
|
|||
GrMtlTextureInfo mtl_info;
|
||||
mtl_info.fTexture = sk_ret_cfp(metal_texture->texture());
|
||||
auto backend_render_target = GrBackendRenderTargets::MakeMtl(metal_texture->width(), metal_texture->height(), mtl_info);
|
||||
auto surface = SkSurfaces::WrapBackendRenderTarget(context->sk_context(), backend_render_target, kTopLeft_GrSurfaceOrigin, kBGRA_8888_SkColorType, nullptr, nullptr);
|
||||
GrSurfaceOrigin sk_origin;
|
||||
switch (origin) {
|
||||
case Origin::TopLeft:
|
||||
sk_origin = kTopLeft_GrSurfaceOrigin;
|
||||
break;
|
||||
case Origin::BottomLeft:
|
||||
sk_origin = kBottomLeft_GrSurfaceOrigin;
|
||||
break;
|
||||
default:
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
auto surface = SkSurfaces::WrapBackendRenderTarget(context->sk_context(), backend_render_target, sk_origin, kBGRA_8888_SkColorType, nullptr, nullptr);
|
||||
return adopt_ref(*new PaintingSurface(make<Impl>(size, surface, nullptr, context)));
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -24,11 +24,16 @@ namespace Gfx {
|
|||
|
||||
class PaintingSurface : public RefCounted<PaintingSurface> {
|
||||
public:
|
||||
enum class Origin {
|
||||
TopLeft,
|
||||
BottomLeft,
|
||||
};
|
||||
|
||||
static NonnullRefPtr<PaintingSurface> create_with_size(RefPtr<SkiaBackendContext> context, Gfx::IntSize size, Gfx::BitmapFormat color_type, Gfx::AlphaType alpha_type);
|
||||
static NonnullRefPtr<PaintingSurface> wrap_bitmap(Bitmap&);
|
||||
|
||||
#ifdef AK_OS_MACOS
|
||||
static NonnullRefPtr<PaintingSurface> wrap_iosurface(Core::IOSurfaceHandle const&, RefPtr<SkiaBackendContext>);
|
||||
static NonnullRefPtr<PaintingSurface> wrap_iosurface(Core::IOSurfaceHandle const&, RefPtr<SkiaBackendContext>, Origin = Origin::TopLeft);
|
||||
#endif
|
||||
|
||||
void read_into_bitmap(Bitmap&);
|
||||
|
@ -47,9 +52,6 @@ public:
|
|||
|
||||
void flush() const;
|
||||
|
||||
bool flip_vertically() const { return m_flip_vertically; }
|
||||
void set_flip_vertically() { m_flip_vertically = true; }
|
||||
|
||||
~PaintingSurface();
|
||||
|
||||
private:
|
||||
|
@ -58,7 +60,6 @@ private:
|
|||
PaintingSurface(NonnullOwnPtr<Impl>&&);
|
||||
|
||||
NonnullOwnPtr<Impl> m_impl;
|
||||
bool m_flip_vertically { false };
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -152,17 +152,7 @@ void DisplayListPlayerSkia::draw_painting_surface(DrawPaintingSurface const& com
|
|||
auto& canvas = surface().canvas();
|
||||
auto image = sk_surface.makeImageSnapshot();
|
||||
SkPaint paint;
|
||||
if (command.surface->flip_vertically()) {
|
||||
canvas.save();
|
||||
SkMatrix matrix;
|
||||
matrix.setIdentity();
|
||||
matrix.preScale(1, -1, dst_rect.centerX(), dst_rect.centerY());
|
||||
canvas.concat(matrix);
|
||||
}
|
||||
canvas.drawImageRect(image, src_rect, dst_rect, to_skia_sampling_options(command.scaling_mode), &paint, SkCanvas::kStrict_SrcRectConstraint);
|
||||
if (command.surface->flip_vertically()) {
|
||||
canvas.restore();
|
||||
}
|
||||
}
|
||||
|
||||
void DisplayListPlayerSkia::draw_scaled_immutable_bitmap(DrawScaledImmutableBitmap const& command)
|
||||
|
|
|
@ -126,8 +126,7 @@ void OpenGLContext::allocate_painting_surface_if_needed()
|
|||
VERIFY(!m_size.is_empty());
|
||||
|
||||
auto iosurface = Core::IOSurfaceHandle::create(m_size.width(), m_size.height());
|
||||
m_painting_surface = Gfx::PaintingSurface::wrap_iosurface(iosurface, m_skia_backend_context);
|
||||
m_painting_surface->set_flip_vertically();
|
||||
m_painting_surface = Gfx::PaintingSurface::wrap_iosurface(iosurface, m_skia_backend_context, Gfx::PaintingSurface::Origin::BottomLeft);
|
||||
|
||||
auto width = m_size.width();
|
||||
auto height = m_size.height();
|
||||
|
|
Loading…
Reference in a new issue