| 1 | /* |
| 2 | * Copyright (C) 2017 Metrological Group B.V. |
| 3 | * Copyright (C) 2017 Igalia S.L. |
| 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions |
| 7 | * are met: |
| 8 | * 1. Redistributions of source code must retain the above copyright |
| 9 | * notice, this list of conditions and the following disclaimer. |
| 10 | * 2. Redistributions in binary form must reproduce the above copyright |
| 11 | * notice, this list of conditions and the following disclaimer in the |
| 12 | * documentation and/or other materials provided with the distribution. |
| 13 | * |
| 14 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY |
| 15 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 17 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR |
| 18 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 19 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 20 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 21 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
| 22 | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 24 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 25 | */ |
| 26 | |
| 27 | #pragma once |
| 28 | |
| 29 | #if USE(CAIRO) |
| 30 | |
| 31 | #include "GraphicsContextImpl.h" |
| 32 | |
| 33 | typedef struct _cairo cairo_t; |
| 34 | |
| 35 | namespace WebCore { |
| 36 | |
| 37 | class PlatformContextCairo; |
| 38 | |
| 39 | class GraphicsContextImplCairo final : public GraphicsContextImpl { |
| 40 | public: |
| 41 | WEBCORE_EXPORT static GraphicsContext::GraphicsContextImplFactory createFactory(PlatformContextCairo&); |
| 42 | WEBCORE_EXPORT static GraphicsContext::GraphicsContextImplFactory createFactory(cairo_t*); |
| 43 | |
| 44 | GraphicsContextImplCairo(GraphicsContext&, PlatformContextCairo&); |
| 45 | GraphicsContextImplCairo(GraphicsContext&, cairo_t*); |
| 46 | virtual ~GraphicsContextImplCairo(); |
| 47 | |
| 48 | bool hasPlatformContext() const override; |
| 49 | PlatformContextCairo* platformContext() const override; |
| 50 | |
| 51 | void updateState(const GraphicsContextState&, GraphicsContextState::StateChangeFlags) override; |
| 52 | void clearShadow() override; |
| 53 | |
| 54 | void setLineCap(LineCap) override; |
| 55 | void setLineDash(const DashArray&, float) override; |
| 56 | void setLineJoin(LineJoin) override; |
| 57 | void setMiterLimit(float) override; |
| 58 | |
| 59 | void fillRect(const FloatRect&) override; |
| 60 | void fillRect(const FloatRect&, const Color&) override; |
| 61 | void fillRect(const FloatRect&, Gradient&) override; |
| 62 | void fillRect(const FloatRect&, const Color&, CompositeOperator, BlendMode) override; |
| 63 | void fillRoundedRect(const FloatRoundedRect&, const Color&, BlendMode) override; |
| 64 | void fillRectWithRoundedHole(const FloatRect&, const FloatRoundedRect&, const Color&) override; |
| 65 | void fillPath(const Path&) override; |
| 66 | void fillEllipse(const FloatRect&) override; |
| 67 | void strokeRect(const FloatRect&, float) override; |
| 68 | void strokePath(const Path&) override; |
| 69 | void strokeEllipse(const FloatRect&) override; |
| 70 | void clearRect(const FloatRect&) override; |
| 71 | |
| 72 | void drawGlyphs(const Font&, const GlyphBuffer&, unsigned, unsigned, const FloatPoint&, FontSmoothingMode) override; |
| 73 | |
| 74 | ImageDrawResult drawImage(Image&, const FloatRect&, const FloatRect&, const ImagePaintingOptions&) override; |
| 75 | ImageDrawResult drawTiledImage(Image&, const FloatRect&, const FloatPoint&, const FloatSize&, const FloatSize&, const ImagePaintingOptions&) override; |
| 76 | ImageDrawResult drawTiledImage(Image&, const FloatRect&, const FloatRect&, const FloatSize&, Image::TileRule, Image::TileRule, const ImagePaintingOptions&) override; |
| 77 | void drawNativeImage(const NativeImagePtr&, const FloatSize&, const FloatRect&, const FloatRect&, CompositeOperator, BlendMode, ImageOrientation) override; |
| 78 | void drawPattern(Image&, const FloatRect&, const FloatRect&, const AffineTransform&, const FloatPoint&, const FloatSize&, CompositeOperator, BlendMode = BlendMode::Normal) override; |
| 79 | |
| 80 | void drawRect(const FloatRect&, float) override; |
| 81 | void drawLine(const FloatPoint&, const FloatPoint&) override; |
| 82 | void drawLinesForText(const FloatPoint&, float thickness, const DashArray&, bool, bool) override; |
| 83 | void drawDotsForDocumentMarker(const FloatRect&, DocumentMarkerLineStyle) override; |
| 84 | void drawEllipse(const FloatRect&) override; |
| 85 | void drawPath(const Path&) override; |
| 86 | |
| 87 | void drawFocusRing(const Path&, float, float, const Color&) override; |
| 88 | void drawFocusRing(const Vector<FloatRect>&, float, float, const Color&) override; |
| 89 | |
| 90 | void save() override; |
| 91 | void restore() override; |
| 92 | |
| 93 | void translate(float, float) override; |
| 94 | void rotate(float) override; |
| 95 | void scale(const FloatSize&) override; |
| 96 | void concatCTM(const AffineTransform&) override; |
| 97 | void setCTM(const AffineTransform&) override; |
| 98 | AffineTransform getCTM(GraphicsContext::IncludeDeviceScale) override; |
| 99 | |
| 100 | void beginTransparencyLayer(float) override; |
| 101 | void endTransparencyLayer() override; |
| 102 | |
| 103 | void clip(const FloatRect&) override; |
| 104 | void clipOut(const FloatRect&) override; |
| 105 | void clipOut(const Path&) override; |
| 106 | void clipPath(const Path&, WindRule) override; |
| 107 | IntRect clipBounds() override; |
| 108 | void clipToImageBuffer(ImageBuffer&, const FloatRect&) override; |
| 109 | |
| 110 | void applyDeviceScaleFactor(float) override; |
| 111 | |
| 112 | FloatRect roundToDevicePixels(const FloatRect&, GraphicsContext::RoundingMode) override; |
| 113 | |
| 114 | private: |
| 115 | std::unique_ptr<PlatformContextCairo> m_ownedPlatformContext; |
| 116 | PlatformContextCairo& m_platformContext; |
| 117 | |
| 118 | std::unique_ptr<GraphicsContextPlatformPrivate> m_private; |
| 119 | }; |
| 120 | |
| 121 | } // namespace WebCore |
| 122 | |
| 123 | #endif // USE(CAIRO) |
| 124 | |