| Differences between
and this patch
- a/Source/WebCore/ChangeLog +49 lines
Lines 1-3 a/Source/WebCore/ChangeLog_sec1
1
2020-03-09  Carlos Garcia Campos  <cgarcia@igalia.com>
2
3
        [Cairo] Remove PlatformPathCairo
4
        https://bugs.webkit.org/show_bug.cgi?id=208807
5
6
        Reviewed by Darin Adler.
7
8
        We have a class CairoPath defined in PlatformPathCairo.h that simply wraps a cairo_t. We can use the cairo_t
9
        directly as PlatformPath and simplify the cairo path implementation.
10
11
        * platform/SourcesCairo.txt:
12
        * platform/graphics/Path.h:
13
        (WebCore::Path::platformPath const):
14
        * platform/graphics/cairo/CairoOperations.cpp:
15
        (WebCore::Cairo::fillRectWithRoundedHole):
16
        (WebCore::Cairo::fillPath):
17
        (WebCore::Cairo::strokePath):
18
        (WebCore::Cairo::clipPath):
19
        * platform/graphics/cairo/CairoUtilities.cpp:
20
        (WebCore::appendWebCorePathToCairoContext):
21
        * platform/graphics/cairo/FontCairo.cpp:
22
        (WebCore::Font::platformPathForGlyph const):
23
        * platform/graphics/cairo/PathCairo.cpp:
24
        (WebCore::Path::Path):
25
        (WebCore::Path::ensurePlatformPath):
26
        (WebCore::Path::operator=):
27
        (WebCore::Path::clear):
28
        (WebCore::Path::isEmptySlowCase const):
29
        (WebCore::Path::currentPointSlowCase const):
30
        (WebCore::Path::translate):
31
        (WebCore::Path::moveToSlowCase):
32
        (WebCore::Path::addLineToSlowCase):
33
        (WebCore::Path::addRect):
34
        (WebCore::Path::addQuadCurveTo):
35
        (WebCore::Path::addBezierCurveTo):
36
        (WebCore::Path::addArcSlowCase):
37
        (WebCore::Path::addArcTo):
38
        (WebCore::Path::addEllipse):
39
        (WebCore::Path::addPath):
40
        (WebCore::Path::closeSubpath):
41
        (WebCore::Path::boundingRectSlowCase const):
42
        (WebCore::Path::strokeBoundingRect const):
43
        (WebCore::Path::contains const):
44
        (WebCore::Path::strokeContains const):
45
        (WebCore::Path::applySlowCase const):
46
        (WebCore::Path::transform):
47
        * platform/graphics/cairo/PlatformPathCairo.cpp: Removed.
48
        * platform/graphics/cairo/PlatformPathCairo.h: Removed.
49
1
2020-03-10  Philippe Normand  <pnormand@igalia.com>
50
2020-03-10  Philippe Normand  <pnormand@igalia.com>
2
51
3
        Unreviewed, !USE(GSTREAMER_GL) build fix after r258197.
52
        Unreviewed, !USE(GSTREAMER_GL) build fix after r258197.
- a/Source/WebCore/platform/SourcesCairo.txt -1 lines
Lines 40-44 platform/graphics/cairo/NativeImageCairo.cpp a/Source/WebCore/platform/SourcesCairo.txt_sec1
40
platform/graphics/cairo/PathCairo.cpp
40
platform/graphics/cairo/PathCairo.cpp
41
platform/graphics/cairo/PatternCairo.cpp
41
platform/graphics/cairo/PatternCairo.cpp
42
platform/graphics/cairo/PlatformContextCairo.cpp
42
platform/graphics/cairo/PlatformContextCairo.cpp
43
platform/graphics/cairo/PlatformPathCairo.cpp
44
platform/graphics/cairo/RefPtrCairo.cpp
43
platform/graphics/cairo/RefPtrCairo.cpp
- a/Source/WebCore/platform/graphics/Path.h -5 / +14 lines
Lines 55-65 class PlatformContextDirect2D; a/Source/WebCore/platform/graphics/Path.h_sec1
55
}
55
}
56
56
57
#elif USE(CAIRO)
57
#elif USE(CAIRO)
58
58
#include "RefPtrCairo.h"
59
namespace WebCore {
60
class CairoPath;
61
}
62
typedef WebCore::CairoPath PlatformPath;
63
59
64
#elif USE(WINGDI)
60
#elif USE(WINGDI)
65
61
Lines 74-79 typedef void PlatformPath; a/Source/WebCore/platform/graphics/Path.h_sec2
74
70
75
#endif
71
#endif
76
72
73
#if !USE(CAIRO)
77
typedef PlatformPath* PlatformPathPtr;
74
typedef PlatformPath* PlatformPathPtr;
78
75
79
#if USE(CG)
76
#if USE(CG)
Lines 83-88 using PlatformPathStorageType = COMPtr<ID2D1GeometryGroup>; a/Source/WebCore/platform/graphics/Path.h_sec3
83
#else
80
#else
84
using PlatformPathStorageType = PlatformPathPtr;
81
using PlatformPathStorageType = PlatformPathPtr;
85
#endif
82
#endif
83
#endif
86
84
87
namespace WTF {
85
namespace WTF {
88
class TextStream;
86
class TextStream;
Lines 188-198 public: a/Source/WebCore/platform/graphics/Path.h_sec4
188
    PlatformPathPtr platformPath() const { return m_path.get(); }
186
    PlatformPathPtr platformPath() const { return m_path.get(); }
189
#elif USE(CG)
187
#elif USE(CG)
190
    WEBCORE_EXPORT PlatformPathPtr platformPath() const;
188
    WEBCORE_EXPORT PlatformPathPtr platformPath() const;
189
#elif USE(CAIRO)
190
    cairo_t* cairoPath() const { return m_path.get(); }
191
#else
191
#else
192
    PlatformPathPtr platformPath() const { return m_path; }
192
    PlatformPathPtr platformPath() const { return m_path; }
193
#endif
193
#endif
194
194
    // ensurePlatformPath() will allocate a PlatformPath if it has not yet been and will never return null.
195
    // ensurePlatformPath() will allocate a PlatformPath if it has not yet been and will never return null.
196
#if USE(CAIRO)
197
    cairo_t* ensureCairoPath();
198
#else
195
    WEBCORE_EXPORT PlatformPathPtr ensurePlatformPath();
199
    WEBCORE_EXPORT PlatformPathPtr ensurePlatformPath();
200
#endif
196
201
197
    WEBCORE_EXPORT void apply(const PathApplierFunction&) const;
202
    WEBCORE_EXPORT void apply(const PathApplierFunction&) const;
198
    void transform(const AffineTransform&);
203
    void transform(const AffineTransform&);
Lines 251-257 private: a/Source/WebCore/platform/graphics/Path.h_sec5
251
    void swap(Path&);
256
    void swap(Path&);
252
#endif
257
#endif
253
258
259
#if USE(CAIRO)
260
    RefPtr<cairo_t> m_path;
261
#else
254
    mutable PlatformPathStorageType m_path;
262
    mutable PlatformPathStorageType m_path;
263
#endif
255
264
256
#if USE(DIRECT2D)
265
#if USE(DIRECT2D)
257
    Vector<ID2D1Geometry*> m_geometries;
266
    Vector<ID2D1Geometry*> m_geometries;
- a/Source/WebCore/platform/graphics/cairo/CairoOperations.cpp -5 / +4 lines
Lines 46-52 a/Source/WebCore/platform/graphics/cairo/CairoOperations.cpp_sec1
46
#include "ImageBuffer.h"
46
#include "ImageBuffer.h"
47
#include "Path.h"
47
#include "Path.h"
48
#include "PlatformContextCairo.h"
48
#include "PlatformContextCairo.h"
49
#include "PlatformPathCairo.h"
50
#include "ShadowBlur.h"
49
#include "ShadowBlur.h"
51
#include <algorithm>
50
#include <algorithm>
52
#include <cairo.h>
51
#include <cairo.h>
Lines 780-786 void fillRectWithRoundedHole(PlatformContextCairo& platformContext, const FloatR a/Source/WebCore/platform/graphics/cairo/CairoOperations.cpp_sec2
780
    cairo_t* cr = platformContext.cr();
779
    cairo_t* cr = platformContext.cr();
781
780
782
    cairo_save(cr);
781
    cairo_save(cr);
783
    setPathOnCairoContext(platformContext.cr(), path.platformPath()->context());
782
    setPathOnCairoContext(platformContext.cr(), path.cairoPath());
784
    fillCurrentCairoPath(platformContext, fillSource);
783
    fillCurrentCairoPath(platformContext, fillSource);
785
    cairo_restore(cr);
784
    cairo_restore(cr);
786
}
785
}
Lines 789-795 void fillPath(PlatformContextCairo& platformContext, const Path& path, const Fil a/Source/WebCore/platform/graphics/cairo/CairoOperations.cpp_sec3
789
{
788
{
790
    cairo_t* cr = platformContext.cr();
789
    cairo_t* cr = platformContext.cr();
791
790
792
    setPathOnCairoContext(cr, path.platformPath()->context());
791
    setPathOnCairoContext(cr, path.cairoPath());
793
    drawPathShadow(platformContext, fillSource, { }, shadowState, Fill);
792
    drawPathShadow(platformContext, fillSource, { }, shadowState, Fill);
794
    fillCurrentCairoPath(platformContext, fillSource);
793
    fillCurrentCairoPath(platformContext, fillSource);
795
}
794
}
Lines 812-818 void strokePath(PlatformContextCairo& platformContext, const Path& path, const S a/Source/WebCore/platform/graphics/cairo/CairoOperations.cpp_sec4
812
{
811
{
813
    cairo_t* cr = platformContext.cr();
812
    cairo_t* cr = platformContext.cr();
814
813
815
    setPathOnCairoContext(cr, path.platformPath()->context());
814
    setPathOnCairoContext(cr, path.cairoPath());
816
    drawPathShadow(platformContext, { }, strokeSource, shadowState, Stroke);
815
    drawPathShadow(platformContext, { }, strokeSource, shadowState, Stroke);
817
    prepareForStroking(cr, strokeSource, PreserveAlpha);
816
    prepareForStroking(cr, strokeSource, PreserveAlpha);
818
    cairo_stroke(cr);
817
    cairo_stroke(cr);
Lines 1285-1291 void clipPath(PlatformContextCairo& platformContext, const Path& path, WindRule a/Source/WebCore/platform/graphics/cairo/CairoOperations.cpp_sec5
1285
    cairo_t* cr = platformContext.cr();
1284
    cairo_t* cr = platformContext.cr();
1286
1285
1287
    if (!path.isNull())
1286
    if (!path.isNull())
1288
        setPathOnCairoContext(cr, path.platformPath()->context());
1287
        setPathOnCairoContext(cr, path.cairoPath());
1289
1288
1290
    cairo_fill_rule_t savedFillRule = cairo_get_fill_rule(cr);
1289
    cairo_fill_rule_t savedFillRule = cairo_get_fill_rule(cr);
1291
    cairo_set_fill_rule(cr, clipRule == WindRule::EvenOdd ? CAIRO_FILL_RULE_EVEN_ODD : CAIRO_FILL_RULE_WINDING);
1290
    cairo_set_fill_rule(cr, clipRule == WindRule::EvenOdd ? CAIRO_FILL_RULE_EVEN_ODD : CAIRO_FILL_RULE_WINDING);
- a/Source/WebCore/platform/graphics/cairo/CairoUtilities.cpp -2 / +1 lines
Lines 35-41 a/Source/WebCore/platform/graphics/cairo/CairoUtilities.cpp_sec1
35
#include "FloatRect.h"
35
#include "FloatRect.h"
36
#include "IntRect.h"
36
#include "IntRect.h"
37
#include "Path.h"
37
#include "Path.h"
38
#include "PlatformPathCairo.h"
39
#include "RefPtrCairo.h"
38
#include "RefPtrCairo.h"
40
#include "Region.h"
39
#include "Region.h"
41
#include <wtf/Assertions.h>
40
#include <wtf/Assertions.h>
Lines 109-115 void appendWebCorePathToCairoContext(cairo_t* context, const Path& path) a/Source/WebCore/platform/graphics/cairo/CairoUtilities.cpp_sec2
109
{
108
{
110
    if (path.isEmpty())
109
    if (path.isEmpty())
111
        return;
110
        return;
112
    appendPathToCairoContext(context, path.platformPath()->context());
111
    appendPathToCairoContext(context, path.cairoPath());
113
}
112
}
114
113
115
void appendRegionToCairoContext(cairo_t* to, const cairo_region_t* region)
114
void appendRegionToCairoContext(cairo_t* to, const cairo_region_t* region)
- a/Source/WebCore/platform/graphics/cairo/FontCairo.cpp -6 / +5 lines
Lines 43-49 a/Source/WebCore/platform/graphics/cairo/FontCairo.cpp_sec1
43
#include "ImageBuffer.h"
43
#include "ImageBuffer.h"
44
#include "Pattern.h"
44
#include "Pattern.h"
45
#include "PlatformContextCairo.h"
45
#include "PlatformContextCairo.h"
46
#include "PlatformPathCairo.h"
47
#include "ShadowBlur.h"
46
#include "ShadowBlur.h"
48
47
49
namespace WebCore {
48
namespace WebCore {
Lines 83-98 void FontCascade::drawGlyphs(GraphicsContext& context, const Font& font, const G a/Source/WebCore/platform/graphics/cairo/FontCairo.cpp_sec2
83
Path Font::platformPathForGlyph(Glyph glyph) const
82
Path Font::platformPathForGlyph(Glyph glyph) const
84
{
83
{
85
    Path path;
84
    Path path;
86
    path.ensurePlatformPath();
85
    cairo_t* cr = path.ensureCairoPath();
87
86
88
    cairo_glyph_t cairoGlyph = { glyph, 0, 0 };
87
    cairo_glyph_t cairoGlyph = { glyph, 0, 0 };
89
    cairo_set_scaled_font(path.platformPath()->context(), platformData().scaledFont());
88
    cairo_set_scaled_font(cr, platformData().scaledFont());
90
    cairo_glyph_path(path.platformPath()->context(), &cairoGlyph, 1);
89
    cairo_glyph_path(cr, &cairoGlyph, 1);
91
90
92
    float syntheticBoldOffset = this->syntheticBoldOffset();
91
    float syntheticBoldOffset = this->syntheticBoldOffset();
93
    if (syntheticBoldOffset) {
92
    if (syntheticBoldOffset) {
94
        cairo_translate(path.platformPath()->context(), syntheticBoldOffset, 0);
93
        cairo_translate(cr, syntheticBoldOffset, 0);
95
        cairo_glyph_path(path.platformPath()->context(), &cairoGlyph, 1);
94
        cairo_glyph_path(cr, &cairoGlyph, 1);
96
    }
95
    }
97
    return path;
96
    return path;
98
}
97
}
- a/Source/WebCore/platform/graphics/cairo/PathCairo.cpp -100 / +57 lines
Lines 5-11 a/Source/WebCore/platform/graphics/cairo/PathCairo.cpp_sec1
5
                  2005, 2007 Apple Inc. All Rights reserved.
5
                  2005, 2007 Apple Inc. All Rights reserved.
6
                  2007 Alp Toker <alp@atoker.com>
6
                  2007 Alp Toker <alp@atoker.com>
7
                  2008 Dirk Schulze <krit@webkit.org>
7
                  2008 Dirk Schulze <krit@webkit.org>
8
                  2011 Igalia S.L.
8
                  2011, 2020 Igalia S.L.
9
9
10
    This library is free software; you can redistribute it and/or
10
    This library is free software; you can redistribute it and/or
11
    modify it under the terms of the GNU Library General Public
11
    modify it under the terms of the GNU Library General Public
Lines 31-37 a/Source/WebCore/platform/graphics/cairo/PathCairo.cpp_sec2
31
#include "CairoUtilities.h"
31
#include "CairoUtilities.h"
32
#include "FloatRect.h"
32
#include "FloatRect.h"
33
#include "GraphicsContextImplCairo.h"
33
#include "GraphicsContextImplCairo.h"
34
#include "PlatformPathCairo.h"
35
#include "StrokeStyleApplier.h"
34
#include "StrokeStyleApplier.h"
36
#include <math.h>
35
#include <math.h>
37
#include <wtf/MathExtras.h>
36
#include <wtf/MathExtras.h>
Lines 39-78 a/Source/WebCore/platform/graphics/cairo/PathCairo.cpp_sec3
39
38
40
namespace WebCore {
39
namespace WebCore {
41
40
42
Path::Path()
41
Path::Path() = default;
43
    : m_path(0)
44
{
45
}
46
42
47
Path::~Path()
43
Path::~Path() = default;
48
{
44
49
    if (m_path)
45
Path::Path(Path&&) = default;
50
        delete m_path;
46
51
}
47
Path& Path::operator=(Path&&) = default;
52
48
53
Path::Path(const Path& other)
49
Path::Path(const Path& other)
54
    : m_path(0)
55
{
50
{
56
    if (other.isNull())
51
    if (other.isNull())
57
        return;
52
        return;
58
53
59
    cairo_t* cr = ensurePlatformPath()->context();
54
    cairo_t* cr = ensureCairoPath();
60
    auto pathCopy = cairo_copy_path(other.platformPath()->context());
55
    auto pathCopy = cairo_copy_path(other.m_path.get());
61
    cairo_append_path(cr, pathCopy);
56
    cairo_append_path(cr, pathCopy);
62
    cairo_path_destroy(pathCopy);
57
    cairo_path_destroy(pathCopy);
63
}
58
}
64
    
65
Path::Path(Path&& other)
66
{
67
    m_path = other.m_path;
68
    other.m_path = nullptr;
69
}
70
59
71
PlatformPathPtr Path::ensurePlatformPath()
60
cairo_t* Path::ensureCairoPath()
72
{
61
{
73
    if (!m_path)
62
    if (!m_path)
74
        m_path = new CairoPath();
63
        m_path = adoptRef(cairo_create(adoptRef(cairo_image_surface_create(CAIRO_FORMAT_A8, 1, 1)).get()));
75
    return m_path;
64
    return m_path.get();
76
}
65
}
77
66
78
Path& Path::operator=(const Path& other)
67
Path& Path::operator=(const Path& other)
Lines 81-109 Path& Path::operator=(const Path& other) a/Source/WebCore/platform/graphics/cairo/PathCairo.cpp_sec4
81
        return *this;
70
        return *this;
82
71
83
    if (other.isNull()) {
72
    if (other.isNull()) {
84
        if (m_path) {
73
        m_path = nullptr;
85
            delete m_path;
74
        return *this;
86
            m_path = 0;
87
        }
88
    } else {
89
        clear();
90
        cairo_t* cr = ensurePlatformPath()->context();
91
        auto pathCopy = cairo_copy_path(other.platformPath()->context());
92
        cairo_append_path(cr, pathCopy);
93
        cairo_path_destroy(pathCopy);
94
    }
75
    }
95
76
96
    return *this;
77
    clear();
97
}
78
    cairo_t* cr = ensureCairoPath();
98
    
79
    auto pathCopy = cairo_copy_path(other.m_path.get());
99
Path& Path::operator=(Path&& other)
80
    cairo_append_path(cr, pathCopy);
100
{
81
    cairo_path_destroy(pathCopy);
101
    if (this == &other)
82
102
        return *this;
103
    if (m_path)
104
        delete m_path;
105
    m_path = other.m_path;
106
    other.m_path = nullptr;
107
    return *this;
83
    return *this;
108
}
84
}
109
85
Lines 112-125 void Path::clear() a/Source/WebCore/platform/graphics/cairo/PathCairo.cpp_sec5
112
    if (isNull())
88
    if (isNull())
113
        return;
89
        return;
114
90
115
    cairo_t* cr = platformPath()->context();
91
    cairo_identity_matrix(m_path.get());
116
    cairo_identity_matrix(cr);
92
    cairo_new_path(m_path.get());
117
    cairo_new_path(cr);
118
}
93
}
119
94
120
bool Path::isEmptySlowCase() const
95
bool Path::isEmptySlowCase() const
121
{
96
{
122
    return !cairo_has_current_point(platformPath()->context());
97
    return !cairo_has_current_point(m_path.get());
123
}
98
}
124
99
125
FloatPoint Path::currentPointSlowCase() const
100
FloatPoint Path::currentPointSlowCase() const
Lines 127-189 FloatPoint Path::currentPointSlowCase() const a/Source/WebCore/platform/graphics/cairo/PathCairo.cpp_sec6
127
    // FIXME: Is this the correct way?
102
    // FIXME: Is this the correct way?
128
    double x;
103
    double x;
129
    double y;
104
    double y;
130
    cairo_get_current_point(platformPath()->context(), &x, &y);
105
    cairo_get_current_point(m_path.get(), &x, &y);
131
    return FloatPoint(x, y);
106
    return FloatPoint(x, y);
132
}
107
}
133
108
134
void Path::translate(const FloatSize& p)
109
void Path::translate(const FloatSize& p)
135
{
110
{
136
    cairo_t* cr = ensurePlatformPath()->context();
111
    cairo_translate(ensureCairoPath(), -p.width(), -p.height());
137
    cairo_translate(cr, -p.width(), -p.height());
138
}
112
}
139
113
140
void Path::moveToSlowCase(const FloatPoint& p)
114
void Path::moveToSlowCase(const FloatPoint& p)
141
{
115
{
142
    cairo_t* cr = ensurePlatformPath()->context();
116
    cairo_move_to(ensureCairoPath(), p.x(), p.y());
143
    cairo_move_to(cr, p.x(), p.y());
144
}
117
}
145
118
146
void Path::addLineToSlowCase(const FloatPoint& p)
119
void Path::addLineToSlowCase(const FloatPoint& p)
147
{
120
{
148
    cairo_t* cr = ensurePlatformPath()->context();
121
    cairo_line_to(ensureCairoPath(), p.x(), p.y());
149
    cairo_line_to(cr, p.x(), p.y());
150
}
122
}
151
123
152
void Path::addRect(const FloatRect& rect)
124
void Path::addRect(const FloatRect& rect)
153
{
125
{
154
    cairo_t* cr = ensurePlatformPath()->context();
126
    cairo_rectangle(ensureCairoPath(), rect.x(), rect.y(), rect.width(), rect.height());
155
    cairo_rectangle(cr, rect.x(), rect.y(), rect.width(), rect.height());
156
}
127
}
157
128
158
/*
159
 * inspired by libsvg-cairo
160
 */
161
void Path::addQuadCurveToSlowCase(const FloatPoint& controlPoint, const FloatPoint& point)
129
void Path::addQuadCurveToSlowCase(const FloatPoint& controlPoint, const FloatPoint& point)
162
{
130
{
163
    cairo_t* cr = ensurePlatformPath()->context();
164
    double x, y;
131
    double x, y;
165
    double x1 = controlPoint.x();
132
    double x1 = controlPoint.x();
166
    double y1 = controlPoint.y();
133
    double y1 = controlPoint.y();
167
    double x2 = point.x();
134
    double x2 = point.x();
168
    double y2 = point.y();
135
    double y2 = point.y();
136
    cairo_t* cr = ensureCairoPath();
169
    cairo_get_current_point(cr, &x, &y);
137
    cairo_get_current_point(cr, &x, &y);
170
    cairo_curve_to(cr,
138
    cairo_curve_to(cr,
171
                   x  + 2.0 / 3.0 * (x1 - x),  y  + 2.0 / 3.0 * (y1 - y),
139
        x  + 2.0 / 3.0 * (x1 - x),  y  + 2.0 / 3.0 * (y1 - y),
172
                   x2 + 2.0 / 3.0 * (x1 - x2), y2 + 2.0 / 3.0 * (y1 - y2),
140
        x2 + 2.0 / 3.0 * (x1 - x2), y2 + 2.0 / 3.0 * (y1 - y2),
173
                   x2, y2);
141
        x2, y2);
174
}
142
}
175
143
176
void Path::addBezierCurveToSlowCase(const FloatPoint& controlPoint1, const FloatPoint& controlPoint2, const FloatPoint& controlPoint3)
144
void Path::addBezierCurveToSlowCase(const FloatPoint& controlPoint1, const FloatPoint& controlPoint2, const FloatPoint& controlPoint3)
177
{
145
{
178
    cairo_t* cr = ensurePlatformPath()->context();
146
    cairo_curve_to(ensureCairoPath(), controlPoint1.x(), controlPoint1.y(),
179
    cairo_curve_to(cr, controlPoint1.x(), controlPoint1.y(),
147
        controlPoint2.x(), controlPoint2.y(), controlPoint3.x(), controlPoint3.y());
180
                   controlPoint2.x(), controlPoint2.y(),
181
                   controlPoint3.x(), controlPoint3.y());
182
}
148
}
183
149
184
void Path::addArcSlowCase(const FloatPoint& p, float r, float startAngle, float endAngle, bool anticlockwise)
150
void Path::addArcSlowCase(const FloatPoint& p, float r, float startAngle, float endAngle, bool anticlockwise)
185
{
151
{
186
    cairo_t* cr = ensurePlatformPath()->context();
152
    cairo_t* cr = ensureCairoPath();
187
    float sweep = endAngle - startAngle;
153
    float sweep = endAngle - startAngle;
188
    const float twoPI = 2 * piFloat;
154
    const float twoPI = 2 * piFloat;
189
    if ((sweep <= -twoPI || sweep >= twoPI)
155
    if ((sweep <= -twoPI || sweep >= twoPI)
Lines 213-229 void Path::addArcTo(const FloatPoint& p1, const FloatPoint& p2, float radius) a/Source/WebCore/platform/graphics/cairo/PathCairo.cpp_sec7
213
    if (isEmpty())
179
    if (isEmpty())
214
        return;
180
        return;
215
181
216
    cairo_t* cr = platformPath()->context();
217
218
    double x0, y0;
182
    double x0, y0;
219
    cairo_get_current_point(cr, &x0, &y0);
183
    cairo_get_current_point(m_path.get(), &x0, &y0);
220
    FloatPoint p0(x0, y0);
184
    FloatPoint p0(x0, y0);
221
185
222
    // Draw only a straight line to p1 if any of the points are equal or the radius is zero
186
    // Draw only a straight line to p1 if any of the points are equal or the radius is zero
223
    // or the points are collinear (triangle that the points form has area of zero value).
187
    // or the points are collinear (triangle that the points form has area of zero value).
224
    if ((p1.x() == p0.x() && p1.y() == p0.y()) || (p1.x() == p2.x() && p1.y() == p2.y()) || !radius
188
    if ((p1.x() == p0.x() && p1.y() == p0.y()) || (p1.x() == p2.x() && p1.y() == p2.y()) || !radius
225
        || !areaOfTriangleFormedByPoints(p0, p1, p2)) {
189
        || !areaOfTriangleFormedByPoints(p0, p1, p2)) {
226
        cairo_line_to(cr, p1.x(), p1.y());
190
        cairo_line_to(m_path.get(), p1.x(), p1.y());
227
        return;
191
        return;
228
    }
192
    }
229
193
Lines 231-241 void Path::addArcTo(const FloatPoint& p1, const FloatPoint& p2, float radius) a/Source/WebCore/platform/graphics/cairo/PathCairo.cpp_sec8
231
    FloatPoint p1p2((p2.x() - p1.x()),(p2.y() - p1.y()));
195
    FloatPoint p1p2((p2.x() - p1.x()),(p2.y() - p1.y()));
232
    float p1p0_length = std::hypot(p1p0.x(), p1p0.y());
196
    float p1p0_length = std::hypot(p1p0.x(), p1p0.y());
233
    float p1p2_length = std::hypot(p1p2.x(), p1p2.y());
197
    float p1p2_length = std::hypot(p1p2.x(), p1p2.y());
234
235
    double cos_phi = (p1p0.x() * p1p2.x() + p1p0.y() * p1p2.y()) / (p1p0_length * p1p2_length);
198
    double cos_phi = (p1p0.x() * p1p2.x() + p1p0.y() * p1p2.y()) / (p1p0_length * p1p2_length);
236
    // all points on a line logic
199
    // all points on a line logic
237
    if (cos_phi == -1) {
200
    if (cos_phi == -1) {
238
        cairo_line_to(cr, p1.x(), p1.y());
201
        cairo_line_to(m_path.get(), p1.x(), p1.y());
239
        return;
202
        return;
240
    }
203
    }
241
    if (cos_phi == 1) {
204
    if (cos_phi == 1) {
Lines 243-249 void Path::addArcTo(const FloatPoint& p1, const FloatPoint& p2, float radius) a/Source/WebCore/platform/graphics/cairo/PathCairo.cpp_sec9
243
        unsigned int max_length = 65535;
206
        unsigned int max_length = 65535;
244
        double factor_max = max_length / p1p0_length;
207
        double factor_max = max_length / p1p0_length;
245
        FloatPoint ep((p0.x() + factor_max * p1p0.x()), (p0.y() + factor_max * p1p0.y()));
208
        FloatPoint ep((p0.x() + factor_max * p1p0.x()), (p0.y() + factor_max * p1p0.y()));
246
        cairo_line_to(cr, ep.x(), ep.y());
209
        cairo_line_to(m_path.get(), ep.x(), ep.y());
247
        return;
210
        return;
248
    }
211
    }
249
212
Lines 283-296 void Path::addArcTo(const FloatPoint& p1, const FloatPoint& p2, float radius) a/Source/WebCore/platform/graphics/cairo/PathCairo.cpp_sec10
283
    if ((sa < ea) && ((ea - sa) > piDouble))
246
    if ((sa < ea) && ((ea - sa) > piDouble))
284
        anticlockwise = true;
247
        anticlockwise = true;
285
248
286
    cairo_line_to(cr, t_p1p0.x(), t_p1p0.y());
249
    cairo_line_to(m_path.get(), t_p1p0.x(), t_p1p0.y());
287
250
288
    addArc(p, radius, sa, ea, anticlockwise);
251
    addArc(p, radius, sa, ea, anticlockwise);
289
}
252
}
290
253
291
void Path::addEllipse(FloatPoint point, float radiusX, float radiusY, float rotation, float startAngle, float endAngle, bool anticlockwise)
254
void Path::addEllipse(FloatPoint point, float radiusX, float radiusY, float rotation, float startAngle, float endAngle, bool anticlockwise)
292
{
255
{
293
    cairo_t* cr = ensurePlatformPath()->context();
256
    cairo_t* cr = ensureCairoPath();
294
    cairo_save(cr);
257
    cairo_save(cr);
295
    cairo_translate(cr, point.x(), point.y());
258
    cairo_translate(cr, point.x(), point.y());
296
    cairo_rotate(cr, rotation);
259
    cairo_rotate(cr, rotation);
Lines 306-312 void Path::addEllipse(FloatPoint point, float radiusX, float radiusY, float rota a/Source/WebCore/platform/graphics/cairo/PathCairo.cpp_sec11
306
269
307
void Path::addEllipse(const FloatRect& rect)
270
void Path::addEllipse(const FloatRect& rect)
308
{
271
{
309
    cairo_t* cr = ensurePlatformPath()->context();
272
    cairo_t* cr = ensureCairoPath();
310
    cairo_save(cr);
273
    cairo_save(cr);
311
    float yRadius = .5 * rect.height();
274
    float yRadius = .5 * rect.height();
312
    float xRadius = .5 * rect.width();
275
    float xRadius = .5 * rect.width();
Lines 325-350 void Path::addPath(const Path& path, const AffineTransform& transform) a/Source/WebCore/platform/graphics/cairo/PathCairo.cpp_sec12
325
    if (cairo_matrix_invert(&matrix) != CAIRO_STATUS_SUCCESS)
288
    if (cairo_matrix_invert(&matrix) != CAIRO_STATUS_SUCCESS)
326
        return;
289
        return;
327
290
328
    cairo_t* cr = path.platformPath()->context();
291
    cairo_t* cr = path.cairoPath();
329
    cairo_save(cr);
292
    cairo_save(cr);
330
    cairo_transform(cr, &matrix);
293
    cairo_transform(cr, &matrix);
331
    auto pathCopy = cairo_copy_path(cr);
294
    auto pathCopy = cairo_copy_path(cr);
332
    cairo_restore(cr);
295
    cairo_restore(cr);
333
    cairo_append_path(ensurePlatformPath()->context(), pathCopy);
296
    cairo_append_path(ensureCairoPath(), pathCopy);
334
    cairo_path_destroy(pathCopy);
297
    cairo_path_destroy(pathCopy);
335
}
298
}
336
299
337
void Path::closeSubpath()
300
void Path::closeSubpath()
338
{
301
{
339
    cairo_t* cr = ensurePlatformPath()->context();
302
    cairo_close_path(ensureCairoPath());
340
    cairo_close_path(cr);
341
}
303
}
342
304
343
FloatRect Path::boundingRectSlowCase() const
305
FloatRect Path::boundingRectSlowCase() const
344
{
306
{
345
    cairo_t* cr = platformPath()->context();
346
    double x0, x1, y0, y1;
307
    double x0, x1, y0, y1;
347
    cairo_path_extents(cr, &x0, &y0, &x1, &y1);
308
    cairo_path_extents(m_path.get(), &x0, &y0, &x1, &y1);
348
    return FloatRect(x0, y0, x1 - x0, y1 - y0);
309
    return FloatRect(x0, y0, x1 - x0, y1 - y0);
349
}
310
}
350
311
Lines 354-367 FloatRect Path::strokeBoundingRect(StrokeStyleApplier* applier) const a/Source/WebCore/platform/graphics/cairo/PathCairo.cpp_sec13
354
    if (isNull())
315
    if (isNull())
355
        return FloatRect();
316
        return FloatRect();
356
317
357
    cairo_t* cr = platformPath()->context();
358
    if (applier) {
318
    if (applier) {
359
        GraphicsContext gc(GraphicsContextImplCairo::createFactory(cr));
319
        GraphicsContext gc(GraphicsContextImplCairo::createFactory(m_path.get()));
360
        applier->strokeStyle(&gc);
320
        applier->strokeStyle(&gc);
361
    }
321
    }
362
322
363
    double x0, x1, y0, y1;
323
    double x0, x1, y0, y1;
364
    cairo_stroke_extents(cr, &x0, &y0, &x1, &y1);
324
    cairo_stroke_extents(m_path.get(), &x0, &y0, &x1, &y1);
365
    return FloatRect(x0, y0, x1 - x0, y1 - y0);
325
    return FloatRect(x0, y0, x1 - x0, y1 - y0);
366
}
326
}
367
327
Lines 369-379 bool Path::contains(const FloatPoint& point, WindRule rule) const a/Source/WebCore/platform/graphics/cairo/PathCairo.cpp_sec14
369
{
329
{
370
    if (isNull() || !std::isfinite(point.x()) || !std::isfinite(point.y()))
330
    if (isNull() || !std::isfinite(point.x()) || !std::isfinite(point.y()))
371
        return false;
331
        return false;
372
    cairo_t* cr = platformPath()->context();
332
373
    cairo_fill_rule_t cur = cairo_get_fill_rule(cr);
333
    cairo_fill_rule_t cur = cairo_get_fill_rule(m_path.get());
374
    cairo_set_fill_rule(cr, rule == WindRule::EvenOdd ? CAIRO_FILL_RULE_EVEN_ODD : CAIRO_FILL_RULE_WINDING);
334
    cairo_set_fill_rule(m_path.get(), rule == WindRule::EvenOdd ? CAIRO_FILL_RULE_EVEN_ODD : CAIRO_FILL_RULE_WINDING);
375
    bool contains = cairo_in_fill(cr, point.x(), point.y());
335
    bool contains = cairo_in_fill(m_path.get(), point.x(), point.y());
376
    cairo_set_fill_rule(cr, cur);
336
    cairo_set_fill_rule(m_path.get(), cur);
377
    return contains;
337
    return contains;
378
}
338
}
379
339
Lines 382-400 bool Path::strokeContains(StrokeStyleApplier& applier, const FloatPoint& point) a/Source/WebCore/platform/graphics/cairo/PathCairo.cpp_sec15
382
    if (isNull())
342
    if (isNull())
383
        return false;
343
        return false;
384
344
385
    cairo_t* cr = platformPath()->context();
386
    {
345
    {
387
        GraphicsContext graphicsContext(GraphicsContextImplCairo::createFactory(cr));
346
        GraphicsContext graphicsContext(GraphicsContextImplCairo::createFactory(m_path.get()));
388
        applier.strokeStyle(&graphicsContext);
347
        applier.strokeStyle(&graphicsContext);
389
    }
348
    }
390
349
391
    return cairo_in_stroke(cr, point.x(), point.y());
350
    return cairo_in_stroke(m_path.get(), point.x(), point.y());
392
}
351
}
393
352
394
void Path::applySlowCase(const PathApplierFunction& function) const
353
void Path::applySlowCase(const PathApplierFunction& function) const
395
{
354
{
396
    cairo_t* cr = platformPath()->context();
355
    auto pathCopy = cairo_copy_path(m_path.get());
397
    auto pathCopy = cairo_copy_path(cr);
398
    cairo_path_data_t* data;
356
    cairo_path_data_t* data;
399
    PathElement pathElement;
357
    PathElement pathElement;
400
358
Lines 434-443 FloatRect Path::fastBoundingRectSlowCase() const a/Source/WebCore/platform/graphics/cairo/PathCairo.cpp_sec16
434
392
435
void Path::transform(const AffineTransform& transform)
393
void Path::transform(const AffineTransform& transform)
436
{
394
{
437
    cairo_t* cr = ensurePlatformPath()->context();
438
    cairo_matrix_t matrix = toCairoMatrix(transform);
395
    cairo_matrix_t matrix = toCairoMatrix(transform);
439
    cairo_matrix_invert(&matrix);
396
    cairo_matrix_invert(&matrix);
440
    cairo_transform(cr, &matrix);
397
    cairo_transform(ensureCairoPath(), &matrix);
441
}
398
}
442
399
443
bool Path::isNull() const
400
bool Path::isNull() const
- a/Source/WebCore/platform/graphics/cairo/PlatformPathCairo.cpp -38 lines
Lines 1-38 a/Source/WebCore/platform/graphics/cairo/PlatformPathCairo.cpp_sec1
1
/*
2
 * Copyright (C) 2011 Collabora Ltd.
3
 *
4
 * This library is free software; you can redistribute it and/or
5
 * modify it under the terms of the GNU Library General Public
6
 * License as published by the Free Software Foundation; either
7
 * version 2 of the License, or (at your option) any later version.
8
 *
9
 * This library is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12
 * Library General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU Library General Public License
15
 * along with this library; see the file COPYING.LIB.  If not, write to
16
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17
 * Boston, MA 02110-1301, USA.
18
 */
19
20
#include "config.h"
21
#include "PlatformPathCairo.h"
22
23
#if USE(CAIRO)
24
25
#include <cairo.h>
26
27
namespace WebCore {
28
29
CairoPath::CairoPath()
30
{
31
    // cairo_t takes its own reference of the surface, meaning we don't have to keep one.
32
    auto surface = adoptRef(cairo_image_surface_create(CAIRO_FORMAT_A8, 1, 1));
33
    m_context = adoptRef(cairo_create(surface.get()));
34
}
35
36
} // namespace WebCore
37
38
#endif // USE(CAIRO)
- a/Source/WebCore/platform/graphics/cairo/PlatformPathCairo.h -43 lines
Lines 1-43 a/Source/WebCore/platform/graphics/cairo/PlatformPathCairo.h_sec1
1
/*
2
 *  Copyright (C) 2007 Alp Toker <alp.toker@collabora.co.uk>
3
 *  Copyright (C) 2010 Igalia S.L.
4
 *
5
 * This library is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU Library General Public
7
 * License as published by the Free Software Foundation; either
8
 * version 2 of the License, or (at your option) any later version.
9
 *
10
 * This library is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
 * Library General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU Library General Public License
16
 * along with this library; see the file COPYING.LIB.  If not, write to
17
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18
 * Boston, MA 02110-1301, USA.
19
 */
20
21
#pragma once
22
23
#if USE(CAIRO)
24
25
#include "RefPtrCairo.h"
26
27
namespace WebCore {
28
29
// This is necessary since cairo_path_fixed_t isn't exposed in Cairo's public API.
30
class CairoPath {
31
public:
32
    CairoPath();
33
    ~CairoPath() = default;
34
35
    cairo_t* context() { return m_context.get(); }
36
37
private:
38
    RefPtr<cairo_t> m_context;
39
};
40
41
} // namespace WebCore
42
43
#endif // USE(CAIRO)

Return to Bug 208807