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#ifndef RenderSVGResourcePattern_h
22#define RenderSVGResourcePattern_h
23
24#include "ImageBuffer.h"
25#include "Pattern.h"
26#include "PatternAttributes.h"
27#include "RenderSVGResourceContainer.h"
28#include "SVGPatternElement.h"
29#include "SVGUnitTypes.h"
30#include <memory>
31#include <wtf/HashMap.h>
32
33namespace WebCore {
34
35struct PatternData {
36    WTF_MAKE_FAST_ALLOCATED;
37public:
38    RefPtr<Pattern> pattern;
39    AffineTransform transform;
40};
41
42class RenderSVGResourcePattern final : public RenderSVGResourceContainer {
43public:
44    RenderSVGResourcePattern(SVGPatternElement&, PassRef<RenderStyle>);
45    SVGPatternElement& patternElement() const;
46
47    virtual void removeAllClientsFromCache(bool markForInvalidation = true) override;
48    virtual void removeClientFromCache(RenderElement&, bool markForInvalidation = true) override;
49
50    virtual bool applyResource(RenderElement&, const RenderStyle&, GraphicsContext*&, unsigned short resourceMode) override;
51    virtual void postApplyResource(RenderElement&, GraphicsContext*&, unsigned short resourceMode, const Path*, const RenderSVGShape*) override;
52    virtual FloatRect resourceBoundingBox(const RenderObject&) override { return FloatRect(); }
53
54    virtual RenderSVGResourceType resourceType() const { return s_resourceType; }
55    static RenderSVGResourceType s_resourceType;
56
57private:
58    void element() const = delete;
59    virtual const char* renderName() const override { return "RenderSVGResourcePattern"; }
60
61    bool buildTileImageTransform(RenderElement&, const PatternAttributes&, const SVGPatternElement&, FloatRect& patternBoundaries, AffineTransform& tileImageTransform) const;
62
63    std::unique_ptr<ImageBuffer> createTileImage(const PatternAttributes&, const FloatRect& tileBoundaries, const FloatRect& absoluteTileBoundaries, const AffineTransform& tileImageTransform, FloatRect& clampedAbsoluteTileBoundaries) const;
64
65    PatternData* buildPattern(RenderElement&, unsigned short resourceMode);
66
67    bool m_shouldCollectPatternAttributes : 1;
68    PatternAttributes m_attributes;
69    HashMap<RenderElement*, std::unique_ptr<PatternData>> m_patternMap;
70};
71
72}
73
74#endif
75