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.
6
* This library is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU Library General Public
8
* License as published by the Free Software Foundation; either
9
* version 2 of the License, or (at your option) any later version.
11
* This library is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
* Library General Public License for more details.
16
* You should have received a copy of the GNU Library General Public License
17
* along with this library; see the file COPYING.LIB. If not, write to
18
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19
* Boston, MA 02110-1301, USA.
22
#ifndef FilterEffect_h
23
#define FilterEffect_h
26
#include "ColorSpace.h"
27
#include "FloatRect.h"
30
#include <wtf/PassOwnPtr.h>
31
#include <wtf/RefCounted.h>
32
#include <wtf/RefPtr.h>
33
#include <wtf/Uint8ClampedArray.h>
34
#include <wtf/Vector.h>
37
#include "FilterContextOpenCL.h"
40
static const float kMaxFilterSize = 5000.0f;
54
class SkiaImageFilterBuilder;
57
typedef Vector<RefPtr<FilterEffect> > FilterEffectVector;
59
enum FilterEffectType {
60
FilterEffectTypeUnknown,
61
FilterEffectTypeImage,
63
FilterEffectTypeSourceInput
66
class FilterEffect : public RefCounted<FilterEffect> {
68
virtual ~FilterEffect();
71
ImageBuffer* asImageBuffer();
72
PassRefPtr<Uint8ClampedArray> asUnmultipliedImage(const IntRect&);
73
PassRefPtr<Uint8ClampedArray> asPremultipliedImage(const IntRect&);
74
void copyUnmultipliedImage(Uint8ClampedArray* destination, const IntRect&);
75
void copyPremultipliedImage(Uint8ClampedArray* destination, const IntRect&);
78
OpenCLHandle openCLImage() { return m_openCLImageResult; }
79
void setOpenCLImage(OpenCLHandle openCLImage) { m_openCLImageResult = openCLImage; }
80
ImageBuffer* openCLImageToImageBuffer();
83
FilterEffectVector& inputEffects() { return m_inputEffects; }
84
FilterEffect* inputEffect(unsigned) const;
85
unsigned numberOfEffectInputs() const { return m_inputEffects.size(); }
87
inline bool hasResult() const
89
// This function needs platform specific checks, if the memory managment is not done by FilterEffect.
90
return m_imageBufferResult
92
|| m_openCLImageResult
94
|| m_unmultipliedImageResult
95
|| m_premultipliedImageResult;
98
IntRect drawingRegionOfInputImage(const IntRect&) const;
99
IntRect requestedRegionOfInputImageData(const IntRect&) const;
101
// Solid black image with different alpha values.
102
bool isAlphaImage() const { return m_alphaImage; }
103
void setIsAlphaImage(bool alphaImage) { m_alphaImage = alphaImage; }
105
IntRect absolutePaintRect() const { return m_absolutePaintRect; }
106
void setAbsolutePaintRect(const IntRect& absolutePaintRect) { m_absolutePaintRect = absolutePaintRect; }
108
FloatRect maxEffectRect() const { return m_maxEffectRect; }
109
void setMaxEffectRect(const FloatRect& maxEffectRect) { m_maxEffectRect = maxEffectRect; }
113
// Correct any invalid pixels, if necessary, in the result of a filter operation.
114
// This method is used to ensure valid pixel values on filter inputs and the final result.
115
// Only the arithmetic composite filter ever needs to perform correction.
116
virtual void correctFilterResultIfNeeded() { }
118
virtual void platformApplySoftware() = 0;
120
virtual bool platformApplyOpenCL();
123
virtual bool platformApplySkia() { return false; }
124
virtual SkImageFilter* createImageFilter(SkiaImageFilterBuilder*) { return 0; }
126
virtual void dump() = 0;
128
virtual void determineAbsolutePaintRect();
130
virtual FilterEffectType filterEffectType() const { return FilterEffectTypeUnknown; }
132
virtual TextStream& externalRepresentation(TextStream&, int indention = 0) const;
135
// The following functions are SVG specific and will move to RenderSVGResourceFilterPrimitive.
136
// See bug https://bugs.webkit.org/show_bug.cgi?id=45614.
137
bool hasX() const { return m_hasX; }
138
void setHasX(bool value) { m_hasX = value; }
140
bool hasY() const { return m_hasY; }
141
void setHasY(bool value) { m_hasY = value; }
143
bool hasWidth() const { return m_hasWidth; }
144
void setHasWidth(bool value) { m_hasWidth = value; }
146
bool hasHeight() const { return m_hasHeight; }
147
void setHasHeight(bool value) { m_hasHeight = value; }
149
FloatRect filterPrimitiveSubregion() const { return m_filterPrimitiveSubregion; }
150
void setFilterPrimitiveSubregion(const FloatRect& filterPrimitiveSubregion) { m_filterPrimitiveSubregion = filterPrimitiveSubregion; }
152
FloatRect effectBoundaries() const { return m_effectBoundaries; }
153
void setEffectBoundaries(const FloatRect& effectBoundaries) { m_effectBoundaries = effectBoundaries; }
155
Filter* filter() { return m_filter; }
157
bool clipsToBounds() const { return m_clipsToBounds; }
158
void setClipsToBounds(bool value) { m_clipsToBounds = value; }
160
ColorSpace colorSpace() const { return m_colorSpace; }
161
void setColorSpace(ColorSpace colorSpace) { m_colorSpace = colorSpace; }
162
void transformResultColorSpace(ColorSpace);
165
FilterEffect(Filter*);
167
ImageBuffer* createImageBufferResult();
168
Uint8ClampedArray* createUnmultipliedImageResult();
169
Uint8ClampedArray* createPremultipliedImageResult();
171
OpenCLHandle createOpenCLImageResult(uint8_t* = 0);
174
// Return true if the filter will only operate correctly on valid RGBA values, with
175
// alpha in [0,255] and each color component in [0, alpha].
176
virtual bool requiresValidPreMultipliedPixels() { return true; }
178
// If a pre-multiplied image, check every pixel for validity and correct if necessary.
179
void forceValidPreMultipliedPixels();
182
OwnPtr<ImageBuffer> m_imageBufferResult;
183
RefPtr<Uint8ClampedArray> m_unmultipliedImageResult;
184
RefPtr<Uint8ClampedArray> m_premultipliedImageResult;
185
FilterEffectVector m_inputEffects;
187
OpenCLHandle m_openCLImageResult;
192
IntRect m_absolutePaintRect;
194
// The maximum size of a filter primitive. In SVG this is the primitive subregion in absolute coordinate space.
195
// The absolute paint rect should never be bigger than m_maxEffectRect.
196
FloatRect m_maxEffectRect;
200
inline void copyImageBytes(Uint8ClampedArray* source, Uint8ClampedArray* destination, const IntRect&);
202
// The following member variables are SVG specific and will move to RenderSVGResourceFilterPrimitive.
203
// See bug https://bugs.webkit.org/show_bug.cgi?id=45614.
205
// The subregion of a filter primitive according to the SVG Filter specification in local coordinates.
206
// This is SVG specific and needs to move to RenderSVGResourceFilterPrimitive.
207
FloatRect m_filterPrimitiveSubregion;
209
// x, y, width and height of the actual SVGFE*Element. Is needed to determine the subregion of the
210
// filter primitive on a later step.
211
FloatRect m_effectBoundaries;
217
// Should the effect clip to its primitive region, or expand to use the combined region of its inputs.
218
bool m_clipsToBounds;
220
ColorSpace m_colorSpace;
221
ColorSpace m_resultColorSpace;
224
} // namespace WebCore
226
#endif // ENABLE(FILTERS)
228
#endif // FilterEffect_h