| 1 | /* |
| 2 | * Copyright (C) 2006 Apple Inc. All rights reserved. |
| 3 | * Copyright (C) 2007 Alp Toker <alp@atoker.com> |
| 4 | * Copyright (C) 2008, 2009 Dirk Schulze <krit@webkit.org> |
| 5 | * Copyright (C) 2008 Nuanti Ltd. |
| 6 | * Copyright (C) 2009 Brent Fulgham <bfulgham@webkit.org> |
| 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 | |
| 42 | namespace WebCore { |
| 43 | |
| 44 | class AffineTransform; |
| 45 | class Color; |
| 46 | class FloatRect; |
| 47 | class FloatRoundedRect; |
| 48 | class FloatSize; |
| 49 | class Path; |
| 50 | class PlatformContextCairo; |
| 51 | |
| 52 | struct GraphicsContextState; |
| 53 | |
| 54 | namespace Cairo { |
| 55 | |
| 56 | namespace State { |
| 57 | |
| 58 | void setStrokeThickness(PlatformContextCairo&, float); |
| 59 | void setStrokeStyle(PlatformContextCairo&, StrokeStyle); |
| 60 | |
| 61 | void setCompositeOperation(PlatformContextCairo&, CompositeOperator, BlendMode); |
| 62 | void setShouldAntialias(PlatformContextCairo&, bool); |
| 63 | |
| 64 | void setCTM(PlatformContextCairo&, const AffineTransform&); |
| 65 | AffineTransform getCTM(PlatformContextCairo&); |
| 66 | |
| 67 | IntRect getClipBounds(PlatformContextCairo&); |
| 68 | FloatRect roundToDevicePixels(PlatformContextCairo&, const FloatRect&); |
| 69 | |
| 70 | bool isAcceleratedContext(PlatformContextCairo&); |
| 71 | |
| 72 | } // namespace State |
| 73 | |
| 74 | struct 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 | |
| 95 | struct 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 | |
| 108 | struct 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 | |
| 124 | void setLineCap(PlatformContextCairo&, LineCap); |
| 125 | void setLineDash(PlatformContextCairo&, const DashArray&, float); |
| 126 | void setLineJoin(PlatformContextCairo&, LineJoin); |
| 127 | void setMiterLimit(PlatformContextCairo&, float); |
| 128 | |
| 129 | void fillRect(PlatformContextCairo&, const FloatRect&, const FillSource&, const ShadowState&); |
| 130 | void fillRect(PlatformContextCairo&, const FloatRect&, const Color&, const ShadowState&); |
| 131 | void fillRect(PlatformContextCairo&, const FloatRect&, cairo_pattern_t*); |
| 132 | void fillRoundedRect(PlatformContextCairo&, const FloatRoundedRect&, const Color&, const ShadowState&); |
| 133 | void fillRectWithRoundedHole(PlatformContextCairo&, const FloatRect&, const FloatRoundedRect&, const FillSource&, const ShadowState&); |
| 134 | void fillPath(PlatformContextCairo&, const Path&, const FillSource&, const ShadowState&); |
| 135 | void strokeRect(PlatformContextCairo&, const FloatRect&, float, const StrokeSource&, const ShadowState&); |
| 136 | void strokePath(PlatformContextCairo&, const Path&, const StrokeSource&, const ShadowState&); |
| 137 | void clearRect(PlatformContextCairo&, const FloatRect&); |
| 138 | |
| 139 | void 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 | |
| 141 | void drawNativeImage(PlatformContextCairo&, cairo_surface_t*, const FloatRect&, const FloatRect&, CompositeOperator, BlendMode, ImageOrientation, InterpolationQuality, float, const ShadowState&); |
| 142 | void drawPattern(PlatformContextCairo&, cairo_surface_t*, const IntSize&, const FloatRect&, const FloatRect&, const AffineTransform&, const FloatPoint&, CompositeOperator, BlendMode); |
| 143 | WEBCORE_EXPORT void drawSurface(PlatformContextCairo&, cairo_surface_t*, const FloatRect&, const FloatRect&, InterpolationQuality, float, const ShadowState&); |
| 144 | |
| 145 | void drawRect(PlatformContextCairo&, const FloatRect&, float, const Color&, StrokeStyle, const Color&); |
| 146 | void drawLine(PlatformContextCairo&, const FloatPoint&, const FloatPoint&, StrokeStyle, const Color&, float, bool); |
| 147 | void drawLinesForText(PlatformContextCairo&, const FloatPoint&, float thickness, const DashArray&, bool, bool, const Color&); |
| 148 | void drawDotsForDocumentMarker(PlatformContextCairo&, const FloatRect&, DocumentMarkerLineStyle); |
| 149 | void drawEllipse(PlatformContextCairo&, const FloatRect&, const Color&, StrokeStyle, const Color&, float); |
| 150 | |
| 151 | void drawFocusRing(PlatformContextCairo&, const Path&, float, const Color&); |
| 152 | void drawFocusRing(PlatformContextCairo&, const Vector<FloatRect>&, float, const Color&); |
| 153 | |
| 154 | void save(PlatformContextCairo&); |
| 155 | void restore(PlatformContextCairo&); |
| 156 | |
| 157 | void translate(PlatformContextCairo&, float, float); |
| 158 | void rotate(PlatformContextCairo&, float); |
| 159 | void scale(PlatformContextCairo&, const FloatSize&); |
| 160 | void concatCTM(PlatformContextCairo&, const AffineTransform&); |
| 161 | |
| 162 | void beginTransparencyLayer(PlatformContextCairo&, float); |
| 163 | void endTransparencyLayer(PlatformContextCairo&); |
| 164 | |
| 165 | void clip(PlatformContextCairo&, const FloatRect&); |
| 166 | void clipOut(PlatformContextCairo&, const FloatRect&); |
| 167 | void clipOut(PlatformContextCairo&, const Path&); |
| 168 | void clipPath(PlatformContextCairo&, const Path&, WindRule); |
| 169 | |
| 170 | void clipToImageBuffer(PlatformContextCairo&, cairo_surface_t*, const FloatRect&); |
| 171 | |
| 172 | } // namespace Cairo |
| 173 | } // namespace WebCore |
| 174 | |
| 175 | #endif // USE(CAIRO) |
| 176 | |