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