Home | History | Annotate | Download | only in svg
      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 "core/platform/graphics/FloatRect.h"
     24 #include "core/platform/graphics/GraphicsContext.h"
     25 #include "core/platform/graphics/ImageBuffer.h"
     26 #include "core/platform/graphics/IntSize.h"
     27 #include "core/rendering/svg/RenderSVGResourceContainer.h"
     28 #include "core/svg/SVGMaskElement.h"
     29 #include "core/svg/SVGUnitTypes.h"
     30 
     31 #include "wtf/HashMap.h"
     32 #include "wtf/OwnPtr.h"
     33 
     34 namespace WebCore {
     35 
     36 struct MaskerData {
     37     OwnPtr<ImageBuffer> maskImage;
     38 };
     39 
     40 class RenderSVGResourceMasker FINAL : public RenderSVGResourceContainer {
     41 public:
     42     RenderSVGResourceMasker(SVGMaskElement*);
     43     virtual ~RenderSVGResourceMasker();
     44 
     45     virtual const char* renderName() const { return "RenderSVGResourceMasker"; }
     46 
     47     virtual void removeAllClientsFromCache(bool markForInvalidation = true);
     48     virtual void removeClientFromCache(RenderObject*, bool markForInvalidation = true);
     49     virtual bool applyResource(RenderObject*, RenderStyle*, GraphicsContext*&, unsigned short resourceMode);
     50     virtual FloatRect resourceBoundingBox(RenderObject*);
     51 
     52     SVGUnitTypes::SVGUnitType maskUnits() const { return toSVGMaskElement(node())->maskUnitsCurrentValue(); }
     53     SVGUnitTypes::SVGUnitType maskContentUnits() const { return toSVGMaskElement(node())->maskContentUnitsCurrentValue(); }
     54 
     55     virtual RenderSVGResourceType resourceType() const { return s_resourceType; }
     56     static RenderSVGResourceType s_resourceType;
     57 
     58 private:
     59     bool drawContentIntoMaskImage(MaskerData*, ColorSpace, const SVGMaskElement*, RenderObject*);
     60     void calculateMaskContentRepaintRect();
     61 
     62     FloatRect m_maskContentBoundaries;
     63     HashMap<RenderObject*, MaskerData*> m_masker;
     64 };
     65 
     66 }
     67 
     68 #endif
     69