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