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) 2010 Zoltan Herczeg <zherczeg (at) webkit.org> 6 * Copyright (C) 2013 Google Inc. 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 FEConvolveMatrix_h 25 #define FEConvolveMatrix_h 26 27 #include "platform/geometry/FloatPoint.h" 28 #include "platform/geometry/FloatSize.h" 29 #include "platform/graphics/filters/Filter.h" 30 #include "platform/graphics/filters/FilterEffect.h" 31 #include "wtf/Vector.h" 32 33 namespace WebCore { 34 35 enum EdgeModeType { 36 EDGEMODE_UNKNOWN = 0, 37 EDGEMODE_DUPLICATE = 1, 38 EDGEMODE_WRAP = 2, 39 EDGEMODE_NONE = 3 40 }; 41 42 class PLATFORM_EXPORT FEConvolveMatrix : public FilterEffect { 43 public: 44 static PassRefPtr<FEConvolveMatrix> create(Filter*, const IntSize&, 45 float, float, const IntPoint&, EdgeModeType, const FloatPoint&, 46 bool, const Vector<float>&); 47 48 IntSize kernelSize() const; 49 void setKernelSize(const IntSize&); 50 51 const Vector<float>& kernel() const; 52 void setKernel(const Vector<float>&); 53 54 float divisor() const; 55 bool setDivisor(float); 56 57 float bias() const; 58 bool setBias(float); 59 60 IntPoint targetOffset() const; 61 bool setTargetOffset(const IntPoint&); 62 63 EdgeModeType edgeMode() const; 64 bool setEdgeMode(EdgeModeType); 65 66 FloatPoint kernelUnitLength() const; 67 bool setKernelUnitLength(const FloatPoint&); 68 69 bool preserveAlpha() const; 70 bool setPreserveAlpha(bool); 71 72 virtual PassRefPtr<SkImageFilter> createImageFilter(SkiaImageFilterBuilder*) OVERRIDE; 73 74 virtual FloatRect mapPaintRect(const FloatRect&, bool forward = true) OVERRIDE FINAL; 75 76 virtual TextStream& externalRepresentation(TextStream&, int indention) const OVERRIDE; 77 78 private: 79 80 struct PaintingData { 81 Uint8ClampedArray* srcPixelArray; 82 Uint8ClampedArray* dstPixelArray; 83 int width; 84 int height; 85 float bias; 86 }; 87 88 FEConvolveMatrix(Filter*, const IntSize&, float, float, 89 const IntPoint&, EdgeModeType, const FloatPoint&, bool, const Vector<float>&); 90 91 virtual void applySoftware() OVERRIDE; 92 93 template<bool preserveAlphaValues> 94 ALWAYS_INLINE void fastSetInteriorPixels(PaintingData&, int clipRight, int clipBottom, int yStart, int yEnd); 95 96 ALWAYS_INLINE int getPixelValue(PaintingData&, int x, int y); 97 98 template<bool preserveAlphaValues> 99 void fastSetOuterPixels(PaintingData&, int x1, int y1, int x2, int y2); 100 101 // Wrapper functions 102 ALWAYS_INLINE void setInteriorPixels(PaintingData&, int clipRight, int clipBottom, int yStart, int yEnd); 103 ALWAYS_INLINE void setOuterPixels(PaintingData&, int x1, int y1, int x2, int y2); 104 105 // Parallelization parts 106 static const int s_minimalRectDimension = (100 * 100); // Empirical data limit for parallel jobs 107 108 template<typename Type> 109 friend class ParallelJobs; 110 111 struct InteriorPixelParameters { 112 FEConvolveMatrix* filter; 113 PaintingData* paintingData; 114 int clipBottom; 115 int clipRight; 116 int yStart; 117 int yEnd; 118 }; 119 120 static void setInteriorPixelsWorker(InteriorPixelParameters*); 121 122 IntSize m_kernelSize; 123 float m_divisor; 124 float m_bias; 125 IntPoint m_targetOffset; 126 EdgeModeType m_edgeMode; 127 FloatPoint m_kernelUnitLength; 128 bool m_preserveAlpha; 129 Vector<float> m_kernelMatrix; 130 }; 131 132 } // namespace WebCore 133 134 #endif // FEConvolveMatrix_h 135