1 | /* |
2 | * Copyright (C) 2006 Nikolas Zimmermann <zimmermann@kde.org> |
3 | * Copyright (C) Research In Motion Limited 2010. All rights reserved. |
4 | * |
5 | * This library is free software; you can redistribute it and/or |
6 | * modify it under the terms of the GNU Library General Public |
7 | * License as published by the Free Software Foundation; either |
8 | * version 2 of the License, or (at your option) any later version. |
9 | * |
10 | * This library is distributed in the hope that it will be useful, |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | * Library General Public License for more details. |
14 | * |
15 | * You should have received a copy of the GNU Library General Public License |
16 | * along with this library; see the file COPYING.LIB. If not, write to |
17 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
18 | * Boston, MA 02110-1301, USA. |
19 | */ |
20 | |
21 | #pragma once |
22 | |
23 | #include "ImageBuffer.h" |
24 | #include "Pattern.h" |
25 | #include "PatternAttributes.h" |
26 | #include "RenderSVGResourceContainer.h" |
27 | #include "SVGPatternElement.h" |
28 | #include <memory> |
29 | #include <wtf/IsoMallocInlines.h> |
30 | #include <wtf/HashMap.h> |
31 | |
32 | namespace WebCore { |
33 | |
34 | struct PatternData { |
35 | WTF_MAKE_FAST_ALLOCATED; |
36 | public: |
37 | RefPtr<Pattern> pattern; |
38 | AffineTransform transform; |
39 | }; |
40 | |
41 | class RenderSVGResourcePattern final : public RenderSVGResourceContainer { |
42 | WTF_MAKE_ISO_ALLOCATED(RenderSVGResourcePattern); |
43 | public: |
44 | RenderSVGResourcePattern(SVGPatternElement&, RenderStyle&&); |
45 | SVGPatternElement& patternElement() const; |
46 | |
47 | void removeAllClientsFromCache(bool markForInvalidation = true) override; |
48 | void removeClientFromCache(RenderElement&, bool markForInvalidation = true) override; |
49 | |
50 | bool applyResource(RenderElement&, const RenderStyle&, GraphicsContext*&, OptionSet<RenderSVGResourceMode>) override; |
51 | void postApplyResource(RenderElement&, GraphicsContext*&, OptionSet<RenderSVGResourceMode>, const Path*, const RenderSVGShape*) override; |
52 | FloatRect resourceBoundingBox(const RenderObject&) override { return FloatRect(); } |
53 | |
54 | RenderSVGResourceType resourceType() const override { return PatternResourceType; } |
55 | |
56 | void collectPatternAttributes(PatternAttributes&) const; |
57 | |
58 | private: |
59 | void element() const = delete; |
60 | const char* renderName() const override { return "RenderSVGResourcePattern" ; } |
61 | |
62 | bool buildTileImageTransform(RenderElement&, const PatternAttributes&, const SVGPatternElement&, FloatRect& patternBoundaries, AffineTransform& tileImageTransform) const; |
63 | |
64 | std::unique_ptr<ImageBuffer> createTileImage(const PatternAttributes&, const FloatRect& tileBoundaries, const FloatRect& absoluteTileBoundaries, const AffineTransform& tileImageTransform, FloatRect& clampedAbsoluteTileBoundaries, RenderingMode) const; |
65 | |
66 | PatternData* buildPattern(RenderElement&, OptionSet<RenderSVGResourceMode>, GraphicsContext&); |
67 | |
68 | PatternAttributes m_attributes; |
69 | HashMap<RenderElement*, std::unique_ptr<PatternData>> m_patternMap; |
70 | bool m_shouldCollectPatternAttributes { true }; |
71 | }; |
72 | |
73 | } // namespace WebCore |
74 | |
75 | SPECIALIZE_TYPE_TRAITS_RENDER_SVG_RESOURCE(RenderSVGResourcePattern, PatternResourceType) |
76 | |