Home | History | Annotate | Download | only in svg
      1 /*
      2  * Copyright (C) 2004, 2005, 2006, 2007 Nikolas Zimmermann <zimmermann (at) kde.org>
      3  * Copyright (C) 2004, 2005 Rob Buis <buis (at) kde.org>
      4  * Copyright (C) 2005 Eric Seidel <eric (at) webkit.org>
      5  * Copyright (C) 2009 Dirk Schulze <krit (at) webkit.org>
      6  * Copyright (C) Research In Motion Limited 2010. All rights reserved.
      7  *
      8  * This library is free software; you can redistribute it and/or
      9  * modify it under the terms of the GNU Library General Public
     10  * License as published by the Free Software Foundation; either
     11  * version 2 of the License, or (at your option) any later version.
     12  *
     13  * This library is distributed in the hope that it will be useful,
     14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     16  * Library General Public License for more details.
     17  *
     18  * You should have received a copy of the GNU Library General Public License
     19  * along with this library; see the file COPYING.LIB.  If not, write to
     20  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
     21  * Boston, MA 02110-1301, USA.
     22  */
     23 
     24 #ifndef RenderSVGResourceFilter_h
     25 #define RenderSVGResourceFilter_h
     26 
     27 #include "core/rendering/svg/RenderSVGResourceContainer.h"
     28 #include "core/svg/SVGFilterElement.h"
     29 #include "core/svg/graphics/filters/SVGFilter.h"
     30 #include "core/svg/graphics/filters/SVGFilterBuilder.h"
     31 
     32 namespace WebCore {
     33 
     34 struct FilterData {
     35     WTF_MAKE_FAST_ALLOCATED;
     36 public:
     37     enum FilterDataState { PaintingSource, Applying, Built, CycleDetected, MarkedForRemoval };
     38 
     39     FilterData()
     40         : savedContext(0)
     41         , state(PaintingSource)
     42     {
     43     }
     44 
     45     RefPtr<SVGFilter> filter;
     46     RefPtr<SVGFilterBuilder> builder;
     47     OwnPtr<ImageBuffer> sourceGraphicBuffer;
     48     GraphicsContext* savedContext;
     49     AffineTransform shearFreeAbsoluteTransform;
     50     FloatRect boundaries;
     51     FloatRect drawingRegion;
     52     FloatSize scale;
     53     FilterDataState state;
     54 };
     55 
     56 class GraphicsContext;
     57 
     58 class RenderSVGResourceFilter FINAL : public RenderSVGResourceContainer {
     59 public:
     60     RenderSVGResourceFilter(SVGFilterElement*);
     61     virtual ~RenderSVGResourceFilter();
     62 
     63     virtual const char* renderName() const { return "RenderSVGResourceFilter"; }
     64     virtual bool isSVGResourceFilter() const OVERRIDE { return true; }
     65 
     66     virtual void removeAllClientsFromCache(bool markForInvalidation = true);
     67     virtual void removeClientFromCache(RenderObject*, bool markForInvalidation = true);
     68 
     69     virtual bool applyResource(RenderObject*, RenderStyle*, GraphicsContext*&, unsigned short resourceMode);
     70     virtual void postApplyResource(RenderObject*, GraphicsContext*&, unsigned short resourceMode, const Path*, const RenderSVGShape*);
     71 
     72     virtual FloatRect resourceBoundingBox(RenderObject*);
     73 
     74     PassRefPtr<SVGFilterBuilder> buildPrimitives(SVGFilter*);
     75 
     76     SVGUnitTypes::SVGUnitType filterUnits() const { return toSVGFilterElement(node())->filterUnitsCurrentValue(); }
     77     SVGUnitTypes::SVGUnitType primitiveUnits() const { return toSVGFilterElement(node())->primitiveUnitsCurrentValue(); }
     78 
     79     void primitiveAttributeChanged(RenderObject*, const QualifiedName&);
     80 
     81     virtual RenderSVGResourceType resourceType() const { return s_resourceType; }
     82     static RenderSVGResourceType s_resourceType;
     83 
     84     FloatRect drawingRegion(RenderObject*) const;
     85 private:
     86     bool fitsInMaximumImageSize(const FloatSize&, FloatSize&);
     87 
     88     HashMap<RenderObject*, FilterData*> m_filter;
     89 };
     90 
     91 inline RenderSVGResourceFilter* toRenderSVGFilter(RenderObject* object)
     92 {
     93     ASSERT_WITH_SECURITY_IMPLICATION(!object || object->isSVGResourceFilter());
     94     return static_cast<RenderSVGResourceFilter*>(object);
     95 }
     96 
     97 }
     98 
     99 #endif
    100