mirror of
https://github.com/fergalmoran/ladybird.git
synced 2025-12-22 09:19:03 +00:00
If Metal context and IOSurface are available, Skia painter will use Ganesh GPU backend on macOS, which is noticeably faster than the default CPU backend. Painting pipeline: 1. (WebContent) Allocate IOSurface for backing store 2. (WebContent) Allocate MTLTexture that wraps IOSurface 3. (WebContent) Paint into MTLTexture using Skia 4. (Browser) Wrap IOSurface into Gfx::Painter and use QPainter/CoreGraphics to blit backing store into viewport. Things we should improve in the future: 1. Upload textures for images in advance instead of doing that before every repaint. 2. Teach AppKit client to read directly from IOSurface instead of copying.
89 lines
3.5 KiB
C++
89 lines
3.5 KiB
C++
/*
|
|
* Copyright (c) 2024, Aliaksandr Kalenik <kalenik.aliaksandr@gmail.com>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <LibGfx/Bitmap.h>
|
|
#include <LibWeb/Painting/DisplayListRecorder.h>
|
|
|
|
#ifdef AK_OS_MACOS
|
|
# include <LibCore/IOSurface.h>
|
|
# include <LibCore/MetalContext.h>
|
|
#endif
|
|
|
|
namespace Web::Painting {
|
|
|
|
class SkiaBackendContext {
|
|
AK_MAKE_NONCOPYABLE(SkiaBackendContext);
|
|
AK_MAKE_NONMOVABLE(SkiaBackendContext);
|
|
|
|
public:
|
|
SkiaBackendContext() {};
|
|
virtual ~SkiaBackendContext() {};
|
|
|
|
virtual void flush_and_submit() {};
|
|
};
|
|
|
|
class DisplayListPlayerSkia : public DisplayListPlayer {
|
|
public:
|
|
CommandResult draw_glyph_run(DrawGlyphRun const&) override;
|
|
CommandResult fill_rect(FillRect const&) override;
|
|
CommandResult draw_scaled_bitmap(DrawScaledBitmap const&) override;
|
|
CommandResult draw_scaled_immutable_bitmap(DrawScaledImmutableBitmap const&) override;
|
|
CommandResult add_clip_rect(AddClipRect const&) override;
|
|
CommandResult save(Save const&) override;
|
|
CommandResult restore(Restore const&) override;
|
|
CommandResult push_stacking_context(PushStackingContext const&) override;
|
|
CommandResult pop_stacking_context(PopStackingContext const&) override;
|
|
CommandResult paint_linear_gradient(PaintLinearGradient const&) override;
|
|
CommandResult paint_outer_box_shadow(PaintOuterBoxShadow const&) override;
|
|
CommandResult paint_inner_box_shadow(PaintInnerBoxShadow const&) override;
|
|
CommandResult paint_text_shadow(PaintTextShadow const&) override;
|
|
CommandResult fill_rect_with_rounded_corners(FillRectWithRoundedCorners const&) override;
|
|
CommandResult fill_path_using_color(FillPathUsingColor const&) override;
|
|
CommandResult fill_path_using_paint_style(FillPathUsingPaintStyle const&) override;
|
|
CommandResult stroke_path_using_color(StrokePathUsingColor const&) override;
|
|
CommandResult stroke_path_using_paint_style(StrokePathUsingPaintStyle const&) override;
|
|
CommandResult draw_ellipse(DrawEllipse const&) override;
|
|
CommandResult fill_ellipse(FillEllipse const&) override;
|
|
CommandResult draw_line(DrawLine const&) override;
|
|
CommandResult apply_backdrop_filter(ApplyBackdropFilter const&) override;
|
|
CommandResult draw_rect(DrawRect const&) override;
|
|
CommandResult paint_radial_gradient(PaintRadialGradient const&) override;
|
|
CommandResult paint_conic_gradient(PaintConicGradient const&) override;
|
|
CommandResult draw_triangle_wave(DrawTriangleWave const&) override;
|
|
CommandResult sample_under_corners(SampleUnderCorners const&) override;
|
|
CommandResult blit_corner_clipping(BlitCornerClipping const&) override;
|
|
|
|
bool would_be_fully_clipped_by_painter(Gfx::IntRect) const override;
|
|
|
|
bool needs_prepare_glyphs_texture() const override { return false; }
|
|
void prepare_glyph_texture(HashMap<Gfx::Font const*, HashTable<u32>> const&) override {};
|
|
|
|
virtual void prepare_to_execute(size_t corner_clip_max_depth) override;
|
|
|
|
bool needs_update_immutable_bitmap_texture_cache() const override { return false; }
|
|
void update_immutable_bitmap_texture_cache(HashMap<u32, Gfx::ImmutableBitmap const*>&) override {};
|
|
|
|
DisplayListPlayerSkia(Gfx::Bitmap&);
|
|
|
|
#ifdef AK_OS_MACOS
|
|
static OwnPtr<SkiaBackendContext> create_metal_context(Core::MetalContext const&);
|
|
DisplayListPlayerSkia(SkiaBackendContext&, Core::MetalTexture&);
|
|
#endif
|
|
|
|
virtual ~DisplayListPlayerSkia() override;
|
|
|
|
private:
|
|
class SkiaSurface;
|
|
SkiaSurface& surface() const;
|
|
|
|
OwnPtr<SkiaSurface> m_surface;
|
|
Function<void()> m_flush_context;
|
|
};
|
|
|
|
}
|