1/*
2 * Copyright (C) 2006 Apple Inc. All rights reserved.
3 * Copyright (C) 2007 Alp Toker <[email protected]>
4 * Copyright (C) 2008, 2009 Dirk Schulze <[email protected]>
5 * Copyright (C) 2008 Nuanti Ltd.
6 * Copyright (C) 2009 Brent Fulgham <[email protected]>
7 * Copyright (C) 2010, 2011 Igalia S.L.
8 * Copyright (C) Research In Motion Limited 2010. All rights reserved.
9 * Copyright (C) 2012, Intel Corporation
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 *
20 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
21 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
24 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
28 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32
33#pragma once
34
35#if USE(CAIRO)
36
37#include "DashArray.h"
38#include "GraphicsContext.h"
39#include "GraphicsTypes.h"
40#include <cairo.h>
41
42namespace WebCore {
43
44class AffineTransform;
45class Color;
46class FloatRect;
47class FloatRoundedRect;
48class FloatSize;
49class Path;
50class PlatformContextCairo;
51
52struct GraphicsContextState;
53
54namespace Cairo {
55
56namespace State {
57
58void setStrokeThickness(PlatformContextCairo&, float);
59void setStrokeStyle(PlatformContextCairo&, StrokeStyle);
60
61void setCompositeOperation(PlatformContextCairo&, CompositeOperator, BlendMode);
62void setShouldAntialias(PlatformContextCairo&, bool);
63
64void setCTM(PlatformContextCairo&, const AffineTransform&);
65AffineTransform getCTM(PlatformContextCairo&);
66
67IntRect getClipBounds(PlatformContextCairo&);
68FloatRect roundToDevicePixels(PlatformContextCairo&, const FloatRect&);
69
70bool isAcceleratedContext(PlatformContextCairo&);
71
72} // namespace State
73
74struct FillSource {
75 FillSource() = default;
76 explicit FillSource(const GraphicsContextState&);
77
78 float globalAlpha { 0 };
79 struct {
80 RefPtr<cairo_pattern_t> object;
81 FloatSize size;
82 AffineTransform transform;
83 bool repeatX { false };
84 bool repeatY { false };
85 } pattern;
86 struct {
87 RefPtr<cairo_pattern_t> base;
88 RefPtr<cairo_pattern_t> alphaAdjusted;
89 } gradient;
90 Color color;
91
92 WindRule fillRule { WindRule::NonZero };
93};
94
95struct StrokeSource {
96 StrokeSource() = default;
97 explicit StrokeSource(const GraphicsContextState&);
98
99 float globalAlpha { 0 };
100 RefPtr<cairo_pattern_t> pattern;
101 struct {
102 RefPtr<cairo_pattern_t> base;
103 RefPtr<cairo_pattern_t> alphaAdjusted;
104 } gradient;
105 Color color;
106};
107
108struct ShadowState {
109 ShadowState() = default;
110 WEBCORE_EXPORT explicit ShadowState(const GraphicsContextState&);
111
112 bool isVisible() const;
113 bool isRequired(PlatformContextCairo&) const;
114
115 FloatSize offset;
116 float blur { 0 };
117 Color color;
118 bool ignoreTransforms { false };
119
120 float globalAlpha { 1.0 };
121 CompositeOperator globalCompositeOperator { CompositeSourceOver };
122};
123
124void setLineCap(PlatformContextCairo&, LineCap);
125void setLineDash(PlatformContextCairo&, const DashArray&, float);
126void setLineJoin(PlatformContextCairo&, LineJoin);
127void setMiterLimit(PlatformContextCairo&, float);
128
129void fillRect(PlatformContextCairo&, const FloatRect&, const FillSource&, const ShadowState&);
130void fillRect(PlatformContextCairo&, const FloatRect&, const Color&, const ShadowState&);
131void fillRect(PlatformContextCairo&, const FloatRect&, cairo_pattern_t*);
132void fillRoundedRect(PlatformContextCairo&, const FloatRoundedRect&, const Color&, const ShadowState&);
133void fillRectWithRoundedHole(PlatformContextCairo&, const FloatRect&, const FloatRoundedRect&, const FillSource&, const ShadowState&);
134void fillPath(PlatformContextCairo&, const Path&, const FillSource&, const ShadowState&);
135void strokeRect(PlatformContextCairo&, const FloatRect&, float, const StrokeSource&, const ShadowState&);
136void strokePath(PlatformContextCairo&, const Path&, const StrokeSource&, const ShadowState&);
137void clearRect(PlatformContextCairo&, const FloatRect&);
138
139void drawGlyphs(PlatformContextCairo&, const FillSource&, const StrokeSource&, const ShadowState&, const FloatPoint&, cairo_scaled_font_t*, double, const Vector<cairo_glyph_t>&, float, TextDrawingModeFlags, float, const FloatSize&, const Color&);
140
141void drawNativeImage(PlatformContextCairo&, cairo_surface_t*, const FloatRect&, const FloatRect&, CompositeOperator, BlendMode, ImageOrientation, InterpolationQuality, float, const ShadowState&);
142void drawPattern(PlatformContextCairo&, cairo_surface_t*, const IntSize&, const FloatRect&, const FloatRect&, const AffineTransform&, const FloatPoint&, CompositeOperator, BlendMode);
143WEBCORE_EXPORT void drawSurface(PlatformContextCairo&, cairo_surface_t*, const FloatRect&, const FloatRect&, InterpolationQuality, float, const ShadowState&);
144
145void drawRect(PlatformContextCairo&, const FloatRect&, float, const Color&, StrokeStyle, const Color&);
146void drawLine(PlatformContextCairo&, const FloatPoint&, const FloatPoint&, StrokeStyle, const Color&, float, bool);
147void drawLinesForText(PlatformContextCairo&, const FloatPoint&, float thickness, const DashArray&, bool, bool, const Color&);
148void drawDotsForDocumentMarker(PlatformContextCairo&, const FloatRect&, DocumentMarkerLineStyle);
149void drawEllipse(PlatformContextCairo&, const FloatRect&, const Color&, StrokeStyle, const Color&, float);
150
151void drawFocusRing(PlatformContextCairo&, const Path&, float, const Color&);
152void drawFocusRing(PlatformContextCairo&, const Vector<FloatRect>&, float, const Color&);
153
154void save(PlatformContextCairo&);
155void restore(PlatformContextCairo&);
156
157void translate(PlatformContextCairo&, float, float);
158void rotate(PlatformContextCairo&, float);
159void scale(PlatformContextCairo&, const FloatSize&);
160void concatCTM(PlatformContextCairo&, const AffineTransform&);
161
162void beginTransparencyLayer(PlatformContextCairo&, float);
163void endTransparencyLayer(PlatformContextCairo&);
164
165void clip(PlatformContextCairo&, const FloatRect&);
166void clipOut(PlatformContextCairo&, const FloatRect&);
167void clipOut(PlatformContextCairo&, const Path&);
168void clipPath(PlatformContextCairo&, const Path&, WindRule);
169
170void clipToImageBuffer(PlatformContextCairo&, cairo_surface_t*, const FloatRect&);
171
172} // namespace Cairo
173} // namespace WebCore
174
175#endif // USE(CAIRO)
176