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#ifndef RenderSVGResourceMasker_h 21#define RenderSVGResourceMasker_h 22 23#include "GraphicsContext.h" 24#include "ImageBuffer.h" 25#include "IntSize.h" 26#include "RenderSVGResourceContainer.h" 27#include "SVGMaskElement.h" 28#include "SVGUnitTypes.h" 29 30#include <wtf/HashMap.h> 31 32namespace WebCore { 33 34struct MaskerData { 35 std::unique_ptr<ImageBuffer> maskImage; 36}; 37 38class RenderSVGResourceMasker final : public RenderSVGResourceContainer { 39public: 40 RenderSVGResourceMasker(SVGMaskElement&, PassRef<RenderStyle>); 41 virtual ~RenderSVGResourceMasker(); 42 43 SVGMaskElement& maskElement() const { return toSVGMaskElement(RenderSVGResourceContainer::element()); } 44 45 virtual void removeAllClientsFromCache(bool markForInvalidation = true) override; 46 virtual void removeClientFromCache(RenderElement&, bool markForInvalidation = true) override; 47 virtual bool applyResource(RenderElement&, const RenderStyle&, GraphicsContext*&, unsigned short resourceMode) override; 48 virtual FloatRect resourceBoundingBox(const RenderObject&) override; 49 50 SVGUnitTypes::SVGUnitType maskUnits() const { return maskElement().maskUnits(); } 51 SVGUnitTypes::SVGUnitType maskContentUnits() const { return maskElement().maskContentUnits(); } 52 53 virtual RenderSVGResourceType resourceType() const { return s_resourceType; } 54 static RenderSVGResourceType s_resourceType; 55 56private: 57 void element() const = delete; 58 59 virtual const char* renderName() const override { return "RenderSVGResourceMasker"; } 60 61 bool drawContentIntoMaskImage(MaskerData*, ColorSpace, RenderObject*); 62 void calculateMaskContentRepaintRect(); 63 64 FloatRect m_maskContentBoundaries; 65 HashMap<RenderObject*, std::unique_ptr<MaskerData>> m_masker; 66}; 67 68} 69 70#endif 71