1/*
2 * Copyright (C) 2006 Nikolas Zimmermann <zimmermann@kde.org>
3 * Copyright (C) 2008 Eric Seidel <eric@webkit.org>
4 * Copyright (C) Research In Motion Limited 2010. All rights reserved.
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
15 *
16 * You should have received a copy of the GNU Library General Public License
17 * along with this library; see the file COPYING.LIB. If not, write to
18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
20 */
21
22#pragma once
23
24#include "Gradient.h"
25#include "ImageBuffer.h"
26#include "RenderSVGResourceContainer.h"
27#include "SVGGradientElement.h"
28#include <memory>
29#include <wtf/HashMap.h>
30
31namespace WebCore {
32
33struct GradientData {
34 WTF_MAKE_FAST_ALLOCATED;
35public:
36 RefPtr<Gradient> gradient;
37 AffineTransform userspaceTransform;
38};
39
40class GraphicsContext;
41
42class RenderSVGResourceGradient : public RenderSVGResourceContainer {
43 WTF_MAKE_ISO_ALLOCATED(RenderSVGResourceGradient);
44public:
45 SVGGradientElement& gradientElement() const { return static_cast<SVGGradientElement&>(RenderSVGResourceContainer::element()); }
46
47 void removeAllClientsFromCache(bool markForInvalidation = true) final;
48 void removeClientFromCache(RenderElement&, bool markForInvalidation = true) final;
49
50 bool applyResource(RenderElement&, const RenderStyle&, GraphicsContext*&, OptionSet<RenderSVGResourceMode>) final;
51 void postApplyResource(RenderElement&, GraphicsContext*&, OptionSet<RenderSVGResourceMode>, const Path*, const RenderSVGShape*) final;
52 FloatRect resourceBoundingBox(const RenderObject&) final { return FloatRect(); }
53
54protected:
55 RenderSVGResourceGradient(SVGGradientElement&, RenderStyle&&);
56
57 void element() const = delete;
58
59 void addStops(GradientData*, const Vector<Gradient::ColorStop>&, const RenderStyle&) const;
60
61 virtual SVGUnitTypes::SVGUnitType gradientUnits() const = 0;
62 virtual void calculateGradientTransform(AffineTransform&) = 0;
63 virtual bool collectGradientAttributes() = 0;
64 virtual void buildGradient(GradientData*, const RenderStyle&) const = 0;
65
66 GradientSpreadMethod platformSpreadMethodFromSVGType(SVGSpreadMethodType) const;
67
68private:
69 HashMap<RenderObject*, std::unique_ptr<GradientData>> m_gradientMap;
70
71#if USE(CG)
72 GraphicsContext* m_savedContext { nullptr };
73 std::unique_ptr<ImageBuffer> m_imageBuffer;
74#endif
75
76 bool m_shouldCollectGradientAttributes { true };
77};
78
79} // namespace WebCore
80