| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright (C) 2008 Alex Mathews <possessedpenguinbob@gmail.com> | |
| 3 * Copyright (C) 2009 Dirk Schulze <krit@webkit.org> | |
| 4 * Copyright (C) Research In Motion Limited 2010. All rights reserved. | |
| 5 * Copyright (C) 2013 Google Inc. All rights reserved. | |
| 6 * | |
| 7 * This library is free software; you can redistribute it and/or | |
| 8 * modify it under the terms of the GNU Library General Public | |
| 9 * License as published by the Free Software Foundation; either | |
| 10 * version 2 of the License, or (at your option) any later version. | |
| 11 * | |
| 12 * This library is distributed in the hope that it will be useful, | |
| 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 15 * Library General Public License for more details. | |
| 16 * | |
| 17 * You should have received a copy of the GNU Library General Public License | |
| 18 * along with this library; see the file COPYING.LIB. If not, write to | |
| 19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | |
| 20 * Boston, MA 02110-1301, USA. | |
| 21 */ | |
| 22 | |
| 23 #ifndef FilterEffect_h | |
| 24 #define FilterEffect_h | |
| 25 | |
| 26 #include "platform/geometry/FloatRect.h" | |
| 27 #include "platform/geometry/IntRect.h" | |
| 28 #include "platform/graphics/ColorSpace.h" | |
| 29 | |
| 30 #include "third_party/skia/include/core/SkImageFilter.h" | |
| 31 | |
| 32 #include "wtf/PassOwnPtr.h" | |
| 33 #include "wtf/RefCounted.h" | |
| 34 #include "wtf/RefPtr.h" | |
| 35 #include "wtf/Uint8ClampedArray.h" | |
| 36 #include "wtf/Vector.h" | |
| 37 | |
| 38 static const float kMaxFilterSize = 5000.0f; | |
| 39 | |
| 40 namespace WebCore { | |
| 41 | |
| 42 class Filter; | |
| 43 class FilterEffect; | |
| 44 class ImageBuffer; | |
| 45 class TextStream; | |
| 46 | |
| 47 class SkiaImageFilterBuilder; | |
| 48 | |
| 49 typedef Vector<RefPtr<FilterEffect> > FilterEffectVector; | |
| 50 | |
| 51 enum FilterEffectType { | |
| 52 FilterEffectTypeUnknown, | |
| 53 FilterEffectTypeImage, | |
| 54 FilterEffectTypeTile, | |
| 55 FilterEffectTypeSourceInput | |
| 56 }; | |
| 57 | |
| 58 enum DetermineSubregionFlag { | |
| 59 DetermineSubregionNone = 0, | |
| 60 MapRectForward = 1, | |
| 61 ClipToFilterRegion = 1 << 1 | |
| 62 }; | |
| 63 | |
| 64 typedef int DetermineSubregionFlags; | |
| 65 | |
| 66 class FilterEffect : public RefCounted<FilterEffect> { | |
| 67 public: | |
| 68 virtual ~FilterEffect(); | |
| 69 | |
| 70 void clearResult(); | |
| 71 void clearResultsRecursive(); | |
| 72 | |
| 73 ImageBuffer* asImageBuffer(); | |
| 74 PassRefPtr<Uint8ClampedArray> asUnmultipliedImage(const IntRect&); | |
| 75 PassRefPtr<Uint8ClampedArray> asPremultipliedImage(const IntRect&); | |
| 76 void copyUnmultipliedImage(Uint8ClampedArray* destination, const IntRect&); | |
| 77 void copyPremultipliedImage(Uint8ClampedArray* destination, const IntRect&); | |
| 78 | |
| 79 FilterEffectVector& inputEffects() { return m_inputEffects; } | |
| 80 FilterEffect* inputEffect(unsigned) const; | |
| 81 unsigned numberOfEffectInputs() const { return m_inputEffects.size(); } | |
| 82 | |
| 83 inline bool hasResult() const | |
| 84 { | |
| 85 // This function needs platform specific checks, if the memory managment
is not done by FilterEffect. | |
| 86 return m_imageBufferResult | |
| 87 || m_unmultipliedImageResult | |
| 88 || m_premultipliedImageResult; | |
| 89 } | |
| 90 | |
| 91 IntRect drawingRegionOfInputImage(const IntRect&) const; | |
| 92 IntRect requestedRegionOfInputImageData(const IntRect&) const; | |
| 93 | |
| 94 // Solid black image with different alpha values. | |
| 95 bool isAlphaImage() const { return m_alphaImage; } | |
| 96 void setIsAlphaImage(bool alphaImage) { m_alphaImage = alphaImage; } | |
| 97 | |
| 98 IntRect absolutePaintRect() const { return m_absolutePaintRect; } | |
| 99 void setAbsolutePaintRect(const IntRect& absolutePaintRect) { m_absolutePain
tRect = absolutePaintRect; } | |
| 100 | |
| 101 FloatRect maxEffectRect() const { return m_maxEffectRect; } | |
| 102 void setMaxEffectRect(const FloatRect& maxEffectRect) { m_maxEffectRect = ma
xEffectRect; } | |
| 103 | |
| 104 void apply(); | |
| 105 | |
| 106 // Correct any invalid pixels, if necessary, in the result of a filter opera
tion. | |
| 107 // This method is used to ensure valid pixel values on filter inputs and the
final result. | |
| 108 // Only the arithmetic composite filter ever needs to perform correction. | |
| 109 virtual void correctFilterResultIfNeeded() { } | |
| 110 | |
| 111 virtual PassRefPtr<SkImageFilter> createImageFilter(SkiaImageFilterBuilder*)
; | |
| 112 | |
| 113 virtual void determineAbsolutePaintRect(); | |
| 114 | |
| 115 // Mapping a rect forwards determines which which destination pixels a | |
| 116 // given source rect would affect. Mapping a rect backwards determines | |
| 117 // which pixels from the source rect would be required to fill a given | |
| 118 // destination rect. Note that these are not necessarily the inverse of | |
| 119 // each other. For example, for FEGaussianBlur, they are the same | |
| 120 // transformation. | |
| 121 virtual FloatRect mapRect(const FloatRect& rect, bool forward = true) { retu
rn rect; } | |
| 122 FloatRect mapRectRecursive(const FloatRect&); | |
| 123 | |
| 124 // This is a recursive version of a backwards mapRect(), which also takes | |
| 125 // into account the filter primitive subregion of each effect. | |
| 126 FloatRect getSourceRect(const FloatRect& destRect, const FloatRect& clipRect
); | |
| 127 | |
| 128 virtual FilterEffectType filterEffectType() const { return FilterEffectTypeU
nknown; } | |
| 129 | |
| 130 virtual TextStream& externalRepresentation(TextStream&, int indention = 0) c
onst; | |
| 131 | |
| 132 // The following functions are SVG specific and will move to RenderSVGResour
ceFilterPrimitive. | |
| 133 // See bug https://bugs.webkit.org/show_bug.cgi?id=45614. | |
| 134 bool hasX() const { return m_hasX; } | |
| 135 void setHasX(bool value) { m_hasX = value; } | |
| 136 | |
| 137 bool hasY() const { return m_hasY; } | |
| 138 void setHasY(bool value) { m_hasY = value; } | |
| 139 | |
| 140 bool hasWidth() const { return m_hasWidth; } | |
| 141 void setHasWidth(bool value) { m_hasWidth = value; } | |
| 142 | |
| 143 bool hasHeight() const { return m_hasHeight; } | |
| 144 void setHasHeight(bool value) { m_hasHeight = value; } | |
| 145 | |
| 146 FloatRect filterPrimitiveSubregion() const { return m_filterPrimitiveSubregi
on; } | |
| 147 void setFilterPrimitiveSubregion(const FloatRect& filterPrimitiveSubregion)
{ m_filterPrimitiveSubregion = filterPrimitiveSubregion; } | |
| 148 | |
| 149 FloatRect effectBoundaries() const { return m_effectBoundaries; } | |
| 150 void setEffectBoundaries(const FloatRect& effectBoundaries) { m_effectBounda
ries = effectBoundaries; } | |
| 151 | |
| 152 Filter* filter() { return m_filter; } | |
| 153 const Filter* filter() const { return m_filter; } | |
| 154 | |
| 155 bool clipsToBounds() const { return m_clipsToBounds; } | |
| 156 void setClipsToBounds(bool value) { m_clipsToBounds = value; } | |
| 157 | |
| 158 ColorSpace operatingColorSpace() const { return m_operatingColorSpace; } | |
| 159 virtual void setOperatingColorSpace(ColorSpace colorSpace) { m_operatingColo
rSpace = colorSpace; } | |
| 160 ColorSpace resultColorSpace() const { return m_resultColorSpace; } | |
| 161 virtual void setResultColorSpace(ColorSpace colorSpace) { m_resultColorSpace
= colorSpace; } | |
| 162 | |
| 163 virtual void transformResultColorSpace(FilterEffect* in, const int) { in->tr
ansformResultColorSpace(m_operatingColorSpace); } | |
| 164 void transformResultColorSpace(ColorSpace); | |
| 165 | |
| 166 FloatRect determineFilterPrimitiveSubregion(DetermineSubregionFlags = Determ
ineSubregionNone); | |
| 167 | |
| 168 protected: | |
| 169 FilterEffect(Filter*); | |
| 170 | |
| 171 ImageBuffer* createImageBufferResult(); | |
| 172 Uint8ClampedArray* createUnmultipliedImageResult(); | |
| 173 Uint8ClampedArray* createPremultipliedImageResult(); | |
| 174 | |
| 175 // Return true if the filter will only operate correctly on valid RGBA value
s, with | |
| 176 // alpha in [0,255] and each color component in [0, alpha]. | |
| 177 virtual bool requiresValidPreMultipliedPixels() { return true; } | |
| 178 | |
| 179 // If a pre-multiplied image, check every pixel for validity and correct if
necessary. | |
| 180 void forceValidPreMultipliedPixels(); | |
| 181 SkImageFilter::CropRect getCropRect(const FloatSize& cropOffset) const; | |
| 182 | |
| 183 private: | |
| 184 virtual void applySoftware() = 0; | |
| 185 virtual bool applySkia() { return false; } | |
| 186 | |
| 187 inline void copyImageBytes(Uint8ClampedArray* source, Uint8ClampedArray* des
tination, const IntRect&); | |
| 188 | |
| 189 OwnPtr<ImageBuffer> m_imageBufferResult; | |
| 190 RefPtr<Uint8ClampedArray> m_unmultipliedImageResult; | |
| 191 RefPtr<Uint8ClampedArray> m_premultipliedImageResult; | |
| 192 FilterEffectVector m_inputEffects; | |
| 193 | |
| 194 bool m_alphaImage; | |
| 195 | |
| 196 IntRect m_absolutePaintRect; | |
| 197 | |
| 198 // The maximum size of a filter primitive. In SVG this is the primitive subr
egion in absolute coordinate space. | |
| 199 // The absolute paint rect should never be bigger than m_maxEffectRect. | |
| 200 FloatRect m_maxEffectRect; | |
| 201 Filter* m_filter; | |
| 202 | |
| 203 // The following member variables are SVG specific and will move to RenderSV
GResourceFilterPrimitive. | |
| 204 // See bug https://bugs.webkit.org/show_bug.cgi?id=45614. | |
| 205 | |
| 206 // The subregion of a filter primitive according to the SVG Filter specifica
tion in local coordinates. | |
| 207 // This is SVG specific and needs to move to RenderSVGResourceFilterPrimitiv
e. | |
| 208 FloatRect m_filterPrimitiveSubregion; | |
| 209 | |
| 210 // x, y, width and height of the actual SVGFE*Element. Is needed to determin
e the subregion of the | |
| 211 // filter primitive on a later step. | |
| 212 FloatRect m_effectBoundaries; | |
| 213 bool m_hasX; | |
| 214 bool m_hasY; | |
| 215 bool m_hasWidth; | |
| 216 bool m_hasHeight; | |
| 217 | |
| 218 // Should the effect clip to its primitive region, or expand to use the comb
ined region of its inputs. | |
| 219 bool m_clipsToBounds; | |
| 220 | |
| 221 ColorSpace m_operatingColorSpace; | |
| 222 ColorSpace m_resultColorSpace; | |
| 223 }; | |
| 224 | |
| 225 } // namespace WebCore | |
| 226 | |
| 227 #endif // FilterEffect_h | |
| OLD | NEW |