Repository: LadybirdBrowser/ladybird
File: Libraries/LibGfx/PainterSkia.cpp (C++)

Code before:
    }
}

static void apply_filter(SkPaint& paint, Gfx::Filter const& filter)
{
    paint.setImageFilter(to_skia_image_filter(filter));
}

static SkPaint to_skia_paint(Gfx::PaintStyle const& style, Optional<Gfx::Filter const&> filter)
{
    SkPaint paint;

    apply_paint_style(paint, style);

    if (filter.has_value())
        apply_filter(paint, move(filter.value()));

    return paint;
}

PainterSkia::PainterSkia(NonnullRefPtr<Gfx::PaintingSurface> painting_surface)
    : m_impl(adopt_own(*new Impl { move(painting_surface) }))
{
    m_impl->with_canvas([this](auto& canvas) {
        m_initial_save_count = canvas.getSaveCount();
        canvas.save();
    });
}

PainterSkia::~PainterSkia() = default;

void PainterSkia::clear_rect(Gfx::FloatRect const& rect, Gfx::Color color)
{
    impl().with_canvas([&](auto& canvas) {
        canvas.save();
        canvas.clipRect(to_skia_rect(rect));
        canvas.clear(to_skia_color(color));
        canvas.restore();
    });
}

void PainterSkia::fill_rect(Gfx::FloatRect const& rect, Color color)
{
    SkPaint paint;
    paint.setColor(to_skia_color(color));
    impl().with_canvas([&](auto& canvas) {
        canvas.drawRect(to_skia_rect(rect), paint);
    });
}

void PainterSkia::draw_bitmap(Gfx::FloatRect const& dst_rect, Gfx::ImmutableBitmap const& src_bitmap, Gfx::IntRect const& src_rect, Gfx::ScalingMode scaling_mode, Optional<Gfx::Filter> filter, float global_alpha, Gfx::CompositingAndBlendingOperator compositing_and_blending_operator)

Review comment (suggestion):
I think you can just do

```
m_initial_save_count = canvas.save();
```

here. Returns the same value.

Code after:
        auto image = canvas_pattern->image();
        if (!image)
            return;
        auto const* sk_image = image->sk_image();

        auto repetition = canvas_pattern->repetition();
        auto repeat_x = first_is_one_of(repetition, CanvasPatternPaintStyle::Repetition::Repeat, CanvasPatternPaintStyle::Repetition::RepeatX);
        auto repeat_y = first_is_one_of(repetition, CanvasPatternPaintStyle::Repetition::Repeat, CanvasPatternPaintStyle::Repetition::RepeatY);

        // FIXME: Implement sampling configuration.
        SkSamplingOptions sk_sampling_options { SkFilterMode::kLinear };

        auto shader = sk_image->makeShader(
            repeat_x ? SkTileMode::kRepeat : SkTileMode::kDecal,
            repeat_y ? SkTileMode::kRepeat : SkTileMode::kDecal,
            sk_sampling_options);
        paint.setShader(shader);
    } else {
        dbgln("FIXME: Unsupported PaintStyle");
    }
}

static void apply_filter(SkPaint& paint, Gfx::Filter const& filter)
{
    paint.setImageFilter(to_skia_image_filter(filter));
}

static SkPaint to_skia_paint(Gfx::PaintStyle const& style, Optional<Gfx::Filter const&> filter)
{
    SkPaint paint;

    apply_paint_style(paint, style);

    if (filter.has_value())
        apply_filter(paint, move(filter.value()));

    return paint;
}

PainterSkia::PainterSkia(NonnullRefPtr<Gfx::PaintingSurface> painting_surface)
    : m_impl(adopt_own(*new Impl { move(painting_surface) }))
{
    m_impl->with_canvas([this](auto& canvas) {
        m_initial_save_count = canvas.save();
    });
}

PainterSkia::~PainterSkia() = default;

void PainterSkia::clear_rect(Gfx::FloatRect const& rect, Gfx::Color color)
{