~ubuntu-branches/ubuntu/raring/qtwebkit-source/raring-proposed

« back to all changes in this revision

Viewing changes to Source/WebCore/platform/graphics/filters/FilterEffect.h

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2013-02-18 14:24:18 UTC
  • Revision ID: package-import@ubuntu.com-20130218142418-eon0jmjg3nj438uy
Tags: upstream-2.3
ImportĀ upstreamĀ versionĀ 2.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 *
 
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.
 
10
 *
 
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.
 
15
 *
 
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.
 
20
 */
 
21
 
 
22
#ifndef FilterEffect_h
 
23
#define FilterEffect_h
 
24
 
 
25
#if ENABLE(FILTERS)
 
26
#include "ColorSpace.h"
 
27
#include "FloatRect.h"
 
28
#include "IntRect.h"
 
29
 
 
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>
 
35
 
 
36
#if ENABLE(OPENCL)
 
37
#include "FilterContextOpenCL.h"
 
38
#endif
 
39
 
 
40
static const float kMaxFilterSize = 5000.0f;
 
41
 
 
42
#if USE(SKIA)
 
43
class SkImageFilter;
 
44
#endif
 
45
 
 
46
namespace WebCore {
 
47
 
 
48
class Filter;
 
49
class FilterEffect;
 
50
class ImageBuffer;
 
51
class TextStream;
 
52
 
 
53
#if USE(SKIA)
 
54
class SkiaImageFilterBuilder;
 
55
#endif
 
56
 
 
57
typedef Vector<RefPtr<FilterEffect> > FilterEffectVector;
 
58
 
 
59
enum FilterEffectType {
 
60
    FilterEffectTypeUnknown,
 
61
    FilterEffectTypeImage,
 
62
    FilterEffectTypeTile,
 
63
    FilterEffectTypeSourceInput
 
64
};
 
65
 
 
66
class FilterEffect : public RefCounted<FilterEffect> {
 
67
public:
 
68
    virtual ~FilterEffect();
 
69
 
 
70
    void clearResult();
 
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&);
 
76
 
 
77
#if ENABLE(OPENCL)
 
78
    OpenCLHandle openCLImage() { return m_openCLImageResult; }
 
79
    void setOpenCLImage(OpenCLHandle openCLImage) { m_openCLImageResult = openCLImage; }
 
80
    ImageBuffer* openCLImageToImageBuffer();
 
81
#endif
 
82
 
 
83
    FilterEffectVector& inputEffects() { return m_inputEffects; }
 
84
    FilterEffect* inputEffect(unsigned) const;
 
85
    unsigned numberOfEffectInputs() const { return m_inputEffects.size(); }
 
86
    
 
87
    inline bool hasResult() const
 
88
    {
 
89
        // This function needs platform specific checks, if the memory managment is not done by FilterEffect.
 
90
        return m_imageBufferResult
 
91
#if ENABLE(OPENCL)
 
92
            || m_openCLImageResult
 
93
#endif
 
94
            || m_unmultipliedImageResult
 
95
            || m_premultipliedImageResult;
 
96
    }
 
97
 
 
98
    IntRect drawingRegionOfInputImage(const IntRect&) const;
 
99
    IntRect requestedRegionOfInputImageData(const IntRect&) const;
 
100
 
 
101
    // Solid black image with different alpha values.
 
102
    bool isAlphaImage() const { return m_alphaImage; }
 
103
    void setIsAlphaImage(bool alphaImage) { m_alphaImage = alphaImage; }
 
104
 
 
105
    IntRect absolutePaintRect() const { return m_absolutePaintRect; }
 
106
    void setAbsolutePaintRect(const IntRect& absolutePaintRect) { m_absolutePaintRect = absolutePaintRect; }
 
107
 
 
108
    FloatRect maxEffectRect() const { return m_maxEffectRect; }
 
109
    void setMaxEffectRect(const FloatRect& maxEffectRect) { m_maxEffectRect = maxEffectRect; } 
 
110
 
 
111
    void apply();
 
112
    
 
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() { }
 
117
 
 
118
    virtual void platformApplySoftware() = 0;
 
119
#if ENABLE(OPENCL)
 
120
    virtual bool platformApplyOpenCL();
 
121
#endif
 
122
#if USE(SKIA)
 
123
    virtual bool platformApplySkia() { return false; }
 
124
    virtual SkImageFilter* createImageFilter(SkiaImageFilterBuilder*) { return 0; }
 
125
#endif
 
126
    virtual void dump() = 0;
 
127
 
 
128
    virtual void determineAbsolutePaintRect();
 
129
 
 
130
    virtual FilterEffectType filterEffectType() const { return FilterEffectTypeUnknown; }
 
131
 
 
132
    virtual TextStream& externalRepresentation(TextStream&, int indention = 0) const;
 
133
 
 
134
public:
 
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; }
 
139
 
 
140
    bool hasY() const { return m_hasY; }
 
141
    void setHasY(bool value) { m_hasY = value; }
 
142
 
 
143
    bool hasWidth() const { return m_hasWidth; }
 
144
    void setHasWidth(bool value) { m_hasWidth = value; }
 
145
 
 
146
    bool hasHeight() const { return m_hasHeight; }
 
147
    void setHasHeight(bool value) { m_hasHeight = value; }
 
148
 
 
149
    FloatRect filterPrimitiveSubregion() const { return m_filterPrimitiveSubregion; }
 
150
    void setFilterPrimitiveSubregion(const FloatRect& filterPrimitiveSubregion) { m_filterPrimitiveSubregion = filterPrimitiveSubregion; }
 
151
 
 
152
    FloatRect effectBoundaries() const { return m_effectBoundaries; }
 
153
    void setEffectBoundaries(const FloatRect& effectBoundaries) { m_effectBoundaries = effectBoundaries; }
 
154
 
 
155
    Filter* filter() { return m_filter; }
 
156
 
 
157
    bool clipsToBounds() const { return m_clipsToBounds; }
 
158
    void setClipsToBounds(bool value) { m_clipsToBounds = value; }
 
159
 
 
160
    ColorSpace colorSpace() const { return m_colorSpace; }
 
161
    void setColorSpace(ColorSpace colorSpace) { m_colorSpace = colorSpace; }
 
162
    void transformResultColorSpace(ColorSpace);
 
163
 
 
164
protected:
 
165
    FilterEffect(Filter*);
 
166
 
 
167
    ImageBuffer* createImageBufferResult();
 
168
    Uint8ClampedArray* createUnmultipliedImageResult();
 
169
    Uint8ClampedArray* createPremultipliedImageResult();
 
170
#if ENABLE(OPENCL)
 
171
    OpenCLHandle createOpenCLImageResult(uint8_t* = 0);
 
172
#endif
 
173
 
 
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; }
 
177
 
 
178
    // If a pre-multiplied image, check every pixel for validity and correct if necessary.
 
179
    void forceValidPreMultipliedPixels();
 
180
 
 
181
private:
 
182
    OwnPtr<ImageBuffer> m_imageBufferResult;
 
183
    RefPtr<Uint8ClampedArray> m_unmultipliedImageResult;
 
184
    RefPtr<Uint8ClampedArray> m_premultipliedImageResult;
 
185
    FilterEffectVector m_inputEffects;
 
186
#if ENABLE(OPENCL)
 
187
    OpenCLHandle m_openCLImageResult;
 
188
#endif
 
189
 
 
190
    bool m_alphaImage;
 
191
 
 
192
    IntRect m_absolutePaintRect;
 
193
    
 
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;
 
197
    Filter* m_filter;
 
198
    
 
199
private:
 
200
    inline void copyImageBytes(Uint8ClampedArray* source, Uint8ClampedArray* destination, const IntRect&);
 
201
 
 
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.
 
204
 
 
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;
 
208
 
 
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;
 
212
    bool m_hasX;
 
213
    bool m_hasY;
 
214
    bool m_hasWidth;
 
215
    bool m_hasHeight;
 
216
 
 
217
    // Should the effect clip to its primitive region, or expand to use the combined region of its inputs.
 
218
    bool m_clipsToBounds;
 
219
 
 
220
    ColorSpace m_colorSpace;
 
221
    ColorSpace m_resultColorSpace;
 
222
};
 
223
 
 
224
} // namespace WebCore
 
225
 
 
226
#endif // ENABLE(FILTERS)
 
227
 
 
228
#endif // FilterEffect_h