Coverage Report

Created: 2026-06-07 07:41

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/serenity/Userland/Libraries/LibGfx/AntiAliasingPainter.h
Line
Count
Source
1
/*
2
 * Copyright (c) 2021, Ali Mohammad Pur <mpfard@serenityos.org>
3
 *
4
 * SPDX-License-Identifier: BSD-2-Clause
5
 */
6
7
#pragma once
8
9
#include <LibGfx/Color.h>
10
#include <LibGfx/CornerRadius.h>
11
#include <LibGfx/EdgeFlagPathRasterizer.h>
12
#include <LibGfx/Forward.h>
13
#include <LibGfx/LineStyle.h>
14
#include <LibGfx/PaintStyle.h>
15
#include <LibGfx/Path.h>
16
#include <LibGfx/Quad.h>
17
#include <LibGfx/WindingRule.h>
18
19
namespace Gfx {
20
21
class AntiAliasingPainter {
22
public:
23
    explicit AntiAliasingPainter(Painter& painter)
24
414
        : m_underlying_painter(painter)
25
414
    {
26
414
    }
27
28
    void draw_line(IntPoint, IntPoint, Color, float thickness = 1, LineStyle style = LineStyle::Solid, Color alternate_color = Color::Transparent);
29
    void draw_line(FloatPoint, FloatPoint, Color, float thickness = 1, LineStyle style = LineStyle::Solid, Color alternate_color = Color::Transparent);
30
    void draw_line(FloatLine line, Color color, float thickness = 1, LineStyle style = LineStyle::Solid, Color alternate_color = Color::Transparent)
31
0
    {
32
0
        draw_line(line.a(), line.b(), color, thickness, style, alternate_color);
33
0
    }
34
35
    template<typename SampleMode = Sample32xAA>
36
    void fill_path(Path const& path, Color color, WindingRule winding_rule = WindingRule::Nonzero)
37
62.1k
    {
38
62.1k
        EdgeFlagPathRasterizer<SampleMode> rasterizer(path_bounds(path));
39
62.1k
        rasterizer.fill(m_underlying_painter, path, color, winding_rule, m_transform.translation());
40
62.1k
    }
41
42
    template<typename SampleMode = Sample32xAA>
43
    void fill_path(Path const& path, PaintStyle const& paint_style, float opacity = 1.0f, WindingRule winding_rule = WindingRule::Nonzero)
44
1.04M
    {
45
1.04M
        EdgeFlagPathRasterizer<SampleMode> rasterizer(path_bounds(path));
46
1.04M
        rasterizer.fill(m_underlying_painter, path, paint_style, opacity, winding_rule, m_transform.translation());
47
1.04M
    }
48
49
    void stroke_path(Path const&, Color, Path::StrokeStyle const& stroke_style);
50
    void stroke_path(Path const&, PaintStyle const& paint_style, Path::StrokeStyle const&, float opacity = 1.0f);
51
52
0
    void translate(float dx, float dy) { m_transform.translate(dx, dy); }
53
0
    void translate(FloatPoint delta) { m_transform.translate(delta); }
54
55
    void draw_ellipse(IntRect const& a_rect, Color, int thickness);
56
57
    enum class BlendMode {
58
        Normal,
59
        AlphaSubtract
60
    };
61
62
    void fill_rect(FloatRect const&, Color);
63
64
    void fill_circle(IntPoint center, int radius, Color, BlendMode blend_mode = BlendMode::Normal);
65
    void fill_ellipse(IntRect const& a_rect, Color, BlendMode blend_mode = BlendMode::Normal);
66
67
    void fill_rect_with_rounded_corners(IntRect const&, Color, int radius);
68
    void fill_rect_with_rounded_corners(IntRect const&, Color, int top_left_radius, int top_right_radius, int bottom_right_radius, int bottom_left_radius);
69
    void fill_rect_with_rounded_corners(IntRect const&, Color, CornerRadius top_left, CornerRadius top_right, CornerRadius bottom_right, CornerRadius bottom_left, BlendMode blend_mode = BlendMode::Normal);
70
71
0
    Gfx::Painter& underlying_painter() { return m_underlying_painter; }
72
73
private:
74
    struct Range {
75
        int min;
76
        int max;
77
78
        inline bool contains_inclusive(int n) const
79
0
        {
80
0
            return n >= min && n <= max;
81
0
        }
82
    };
83
84
    Range draw_ellipse_part(IntPoint a_rect, int radius_a, int radius_b, Color alternate_color, bool flip_x_and_y, Optional<Range> x_clip, BlendMode blend_mode);
85
86
    Painter& m_underlying_painter;
87
    AffineTransform m_transform;
88
};
89
90
}