Home | History | Annotate | Download | only in filters
      1 /*
      2  * Copyright (C) 2009 Dirk Schulze <krit (at) webkit.org>
      3  * Copyright (C) 2013 Google Inc. 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 Filter_h
     22 #define Filter_h
     23 
     24 #include "platform/PlatformExport.h"
     25 #include "platform/geometry/FloatRect.h"
     26 #include "platform/geometry/FloatSize.h"
     27 #include "platform/graphics/ImageBuffer.h"
     28 #include "wtf/RefCounted.h"
     29 
     30 namespace WebCore {
     31 
     32 class FilterEffect;
     33 
     34 class PLATFORM_EXPORT Filter : public RefCounted<Filter> {
     35 public:
     36     Filter(const AffineTransform& absoluteTransform) : m_isAccelerated(false), m_absoluteTransform(absoluteTransform) { }
     37     virtual ~Filter() { }
     38 
     39     void setSourceImage(PassOwnPtr<ImageBuffer> sourceImage) { m_sourceImage = sourceImage; }
     40     ImageBuffer* sourceImage() { return m_sourceImage.get(); }
     41 
     42     FloatSize filterResolution() const { return m_filterResolution; }
     43     void setFilterResolution(const FloatSize& filterResolution) { m_filterResolution = filterResolution; }
     44 
     45     const AffineTransform& absoluteTransform() const { return m_absoluteTransform; }
     46     void setAbsoluteTransform(const AffineTransform& absoluteTransform) { m_absoluteTransform = absoluteTransform; }
     47     FloatPoint mapAbsolutePointToLocalPoint(const FloatPoint& point) const { return m_absoluteTransform.inverse().mapPoint(point); }
     48 
     49     bool isAccelerated() const { return m_isAccelerated; }
     50     void setIsAccelerated(bool isAccelerated) { m_isAccelerated = isAccelerated; }
     51 
     52     virtual float applyHorizontalScale(float value) const
     53     {
     54         float filterRegionScale = absoluteFilterRegion().isEmpty() || filterRegion().isEmpty() ?
     55             1.0f : absoluteFilterRegion().width() / filterRegion().width();
     56         return value * m_filterResolution.width() * filterRegionScale;
     57     }
     58     virtual float applyVerticalScale(float value) const
     59     {
     60         float filterRegionScale = absoluteFilterRegion().isEmpty() || filterRegion().isEmpty() ?
     61             1.0f : absoluteFilterRegion().height() / filterRegion().height();
     62         return value * m_filterResolution.height() * filterRegionScale;
     63     }
     64 
     65     virtual FloatRect sourceImageRect() const = 0;
     66 
     67     FloatRect absoluteFilterRegion() const { return m_absoluteFilterRegion; }
     68     void setAbsoluteFilterRegion(const FloatRect& rect) { m_absoluteFilterRegion = rect; }
     69 
     70     FloatRect filterRegion() const { return m_filterRegion; }
     71     void setFilterRegion(const FloatRect& rect) { m_filterRegion = rect; }
     72 
     73 private:
     74     OwnPtr<ImageBuffer> m_sourceImage;
     75     FloatSize m_filterResolution;
     76     bool m_isAccelerated;
     77     AffineTransform m_absoluteTransform;
     78     FloatRect m_absoluteFilterRegion;
     79     FloatRect m_filterRegion;
     80 };
     81 
     82 } // namespace WebCore
     83 
     84 #endif // Filter_h
     85