2 * Copyright (C) 2016 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
26 #ifndef DisplayListRecorder_h
27 #define DisplayListRecorder_h
29 #include "DisplayList.h"
30 #include "GraphicsContext.h" // For InterpolationQuality.
31 #include "Image.h" // For Image::TileRule.
32 #include "TextFlags.h"
33 #include <wtf/Noncopyable.h>
44 struct GraphicsContextState;
45 struct ImagePaintingOptions;
47 namespace DisplayList {
52 WTF_MAKE_NONCOPYABLE(Recorder);
54 Recorder(GraphicsContext&, DisplayList&, const FloatRect& initialClip, const AffineTransform&);
57 void updateState(const GraphicsContextState&, GraphicsContextState::StateChangeFlags);
60 void setLineCap(LineCap);
61 void setLineDash(const DashArray&, float dashOffset);
62 void setLineJoin(LineJoin);
63 void setMiterLimit(float);
65 void fillRect(const FloatRect&);
66 void fillRect(const FloatRect&, const Color&);
67 void fillRect(const FloatRect&, Gradient&);
68 void fillRect(const FloatRect&, const Color&, CompositeOperator, BlendMode);
69 void fillRoundedRect(const FloatRoundedRect&, const Color&, BlendMode);
70 void fillRectWithRoundedHole(const FloatRect&, const FloatRoundedRect& roundedHoleRect, const Color&);
71 void fillPath(const Path&);
72 void fillEllipse(const FloatRect&);
73 void strokeRect(const FloatRect&, float lineWidth);
74 void strokePath(const Path&);
75 void strokeEllipse(const FloatRect&);
76 void clearRect(const FloatRect&);
79 void applyStrokePattern();
80 void applyFillPattern();
83 void drawGlyphs(const Font&, const GlyphBuffer&, int from, int numGlyphs, const FloatPoint& anchorPoint, FontSmoothingMode);
85 void drawImage(Image&, const FloatRect& destination, const FloatRect& source, const ImagePaintingOptions&);
86 void drawTiledImage(Image&, const FloatRect& destination, const FloatPoint& source, const FloatSize& tileSize, const FloatSize& spacing, const ImagePaintingOptions&);
87 void drawTiledImage(Image&, const FloatRect& destination, const FloatRect& source, const FloatSize& tileScaleFactor, Image::TileRule hRule, Image::TileRule vRule, const ImagePaintingOptions&);
88 #if USE(CG) || USE(CAIRO)
89 void drawNativeImage(PassNativeImagePtr, const FloatSize& selfSize, const FloatRect& destRect, const FloatRect& srcRect, CompositeOperator, BlendMode, ImageOrientation);
91 void drawPattern(Image&, const FloatRect& srcRect, const AffineTransform&, const FloatPoint& phase, const FloatSize& spacing, CompositeOperator, const FloatRect& destRect, BlendMode = BlendModeNormal);
93 void drawRect(const FloatRect&, float borderThickness);
94 void drawLine(const FloatPoint&, const FloatPoint&);
95 void drawLinesForText(const FloatPoint&, const DashArray& widths, bool printing, bool doubleLines, float strokeThickness);
96 void drawLineForDocumentMarker(const FloatPoint&, float width, GraphicsContext::DocumentMarkerLineStyle);
97 void drawEllipse(const FloatRect&);
98 void drawPath(const Path&);
100 void drawFocusRing(const Path&, int width, int offset, const Color&);
101 void drawFocusRing(const Vector<IntRect>&, int width, int offset, const Color&);
106 void translate(float x, float y);
107 void rotate(float angleInRadians);
108 void scale(const FloatSize&);
109 void concatCTM(const AffineTransform&);
111 void beginTransparencyLayer(float opacity);
112 void endTransparencyLayer();
114 void clip(const FloatRect&);
115 void clipOut(const FloatRect&);
116 void clipOut(const Path&);
117 void clipPath(const Path&, WindRule);
119 void applyDeviceScaleFactor(float);
121 size_t itemCount() const { return m_displayList.itemCount(); }
124 Item& appendItem(Ref<Item>&&);
125 void willAppendItem(const Item&);
127 FloatRect extentFromLocalBounds(const FloatRect&) const;
128 void updateItemExtent(DrawingItem&) const;
130 const AffineTransform& ctm() const;
131 const FloatRect& clipBounds() const;
133 struct ContextState {
135 FloatRect clipBounds;
136 GraphicsContextStateChange stateChange;
137 GraphicsContextState lastDrawingState;
138 bool wasUsedForDrawing { false };
139 size_t saveItemIndex { 0 };
141 ContextState(const AffineTransform& transform, const FloatRect& clip)
147 ContextState cloneForSave(size_t saveIndex) const
149 ContextState state(ctm, clipBounds);
150 state.stateChange = stateChange;
151 state.lastDrawingState = lastDrawingState;
152 state.saveItemIndex = saveIndex;
156 void translate(float x, float y);
157 void rotate(float angleInRadians);
158 void scale(const FloatSize&);
159 void concatCTM(const AffineTransform&);
162 const ContextState& currentState() const;
163 ContextState& currentState();
165 GraphicsContext& m_graphicsContext;
166 DisplayList& m_displayList;
168 Vector<ContextState, 32> m_stateStack;
174 #endif // DisplayListRecorder_h