1 | /* |
2 | * Copyright (C) Research In Motion Limited 2009-2010. All rights reserved. |
3 | * |
4 | * This library is free software; you can redistribute it and/or |
5 | * modify it under the terms of the GNU Library General Public |
6 | * License as published by the Free Software Foundation; either |
7 | * version 2 of the License, or (at your option) any later version. |
8 | * |
9 | * This library is distributed in the hope that it will be useful, |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 | * Library General Public License for more details. |
13 | * |
14 | * You should have received a copy of the GNU Library General Public License |
15 | * along with this library; see the file COPYING.LIB. If not, write to |
16 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
17 | * Boston, MA 02110-1301, USA. |
18 | */ |
19 | |
20 | #pragma once |
21 | |
22 | #include "ImageBuffer.h" |
23 | #include "RenderSVGResourceContainer.h" |
24 | #include "SVGMaskElement.h" |
25 | #include "SVGUnitTypes.h" |
26 | |
27 | #include <wtf/HashMap.h> |
28 | |
29 | namespace WebCore { |
30 | |
31 | class GraphicsContext; |
32 | |
33 | struct MaskerData { |
34 | std::unique_ptr<ImageBuffer> maskImage; |
35 | }; |
36 | |
37 | class RenderSVGResourceMasker final : public RenderSVGResourceContainer { |
38 | WTF_MAKE_ISO_ALLOCATED(RenderSVGResourceMasker); |
39 | public: |
40 | RenderSVGResourceMasker(SVGMaskElement&, RenderStyle&&); |
41 | virtual ~RenderSVGResourceMasker(); |
42 | |
43 | SVGMaskElement& maskElement() const { return downcast<SVGMaskElement>(RenderSVGResourceContainer::element()); } |
44 | |
45 | void removeAllClientsFromCache(bool markForInvalidation = true) override; |
46 | void removeClientFromCache(RenderElement&, bool markForInvalidation = true) override; |
47 | bool applyResource(RenderElement&, const RenderStyle&, GraphicsContext*&, OptionSet<RenderSVGResourceMode>) override; |
48 | FloatRect resourceBoundingBox(const RenderObject&) override; |
49 | |
50 | SVGUnitTypes::SVGUnitType maskUnits() const { return maskElement().maskUnits(); } |
51 | SVGUnitTypes::SVGUnitType maskContentUnits() const { return maskElement().maskContentUnits(); } |
52 | |
53 | RenderSVGResourceType resourceType() const override { return MaskerResourceType; } |
54 | |
55 | private: |
56 | void element() const = delete; |
57 | |
58 | const char* renderName() const override { return "RenderSVGResourceMasker" ; } |
59 | |
60 | bool drawContentIntoMaskImage(MaskerData*, ColorSpace, RenderObject*); |
61 | void calculateMaskContentRepaintRect(); |
62 | |
63 | FloatRect m_maskContentBoundaries; |
64 | HashMap<RenderObject*, std::unique_ptr<MaskerData>> m_masker; |
65 | }; |
66 | |
67 | } |
68 | |
69 | SPECIALIZE_TYPE_TRAITS_RENDER_SVG_RESOURCE(RenderSVGResourceMasker, MaskerResourceType) |
70 | |