Files
ladybird/Userland/Libraries/LibWeb/Painting/CommandExecutorSkia.h
Aliaksandr Kalenik d292152e2e LibWeb: Add Skia painting command executor
This change introduces Skia painter available under a flag. It's not
yet match capabilities of Gfx::Painter and is not ready to replace it.

Motivation:
- The current CPU painter is a performance bottleneck on most websites.
  Our own GPU painter implementation is very immature and has received
  relatively little attention.
- There is ongoing effort on building painter that supports affine
  transforms (AffineCommandExecutorCPU) but it is far from being on par
  with the default CPU painter. Skia will allow us to immediately get
  full transformation support for all painting commands.

GPU painting:
I experimented with Ganesh GPU-backend, however profiling revealed that
without sharing viewport texture between WebContent and Browser
processes, it won't bring much performance improvement compared to
CPU-backend. Therefore, I decided to keep this PR focused on
implementing most of painting commands and switch to GPU-backend in
future changes.

Text rendring:
Skia painter uses glyph bitmaps produced by LibGfx. Using Skia for text
rendering will require large refactoring of the font rendering
subsystem. Currently, it's impossible to construct SkFont right before
rendering because Gfx::VectorFont can't be serialized back into sequence
of bytes.

There is a problem with ugly include paths like:
`#include <core/SkBitmap.h>`.
I would prefer to have skia prefix in the path. There was an attempt to
fix that but PR was rejected https://github.com/microsoft/vcpkg/pull/32660

Regressions compared to Gfx::Painter:
- DrawText is not implemented
- PaintTextShadow is not implemented
- PaintRadialGradient and PaintLinearGradient do not support "transition
  hints" and repeat length
- PaintConicGradient is not implemented
- DrawTriangleWave is not implemented
- DrawLine does not account for line style property
- DrawScaledBitmap and DrawScaledImmutableBitmap do not account for
  scaling mode property
2024-06-18 21:05:50 +02:00

67 lines
3.0 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/RecordingPainter.h>
namespace Web::Painting {
class CommandExecutorSkia : public CommandExecutor {
public:
CommandResult draw_glyph_run(DrawGlyphRun const&) override;
CommandResult draw_text(DrawText 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 {};
CommandExecutorSkia(Gfx::Bitmap& bitmap);
virtual ~CommandExecutorSkia() override;
private:
class SkiaSurface;
SkiaSurface& surface() const;
OwnPtr<SkiaSurface> m_surface;
};
}