|
1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- |
|
2 * This Source Code Form is subject to the terms of the Mozilla Public |
|
3 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
5 |
|
6 #ifndef _MOZILLA_GFX_FILTERNODESOFTWARE_H_ |
|
7 #define _MOZILLA_GFX_FILTERNODESOFTWARE_H_ |
|
8 |
|
9 #include "Filters.h" |
|
10 #include <vector> |
|
11 |
|
12 namespace mozilla { |
|
13 namespace gfx { |
|
14 |
|
15 class DataSourceSurface; |
|
16 class DrawTarget; |
|
17 struct DrawOptions; |
|
18 class FilterNodeSoftware; |
|
19 |
|
20 /** |
|
21 * Can be attached to FilterNodeSoftware instances using |
|
22 * AddInvalidationListener. FilterInvalidated is called whenever the output of |
|
23 * the observed filter may have changed; that is, whenever cached GetOutput() |
|
24 * results (and results derived from them) need to discarded. |
|
25 */ |
|
26 class FilterInvalidationListener |
|
27 { |
|
28 public: |
|
29 virtual void FilterInvalidated(FilterNodeSoftware* aFilter) = 0; |
|
30 }; |
|
31 |
|
32 /** |
|
33 * This is the base class for the software (i.e. pure CPU, non-accelerated) |
|
34 * FilterNode implementation. The software implementation is backend-agnostic, |
|
35 * so it can be used as a fallback for all DrawTarget implementations. |
|
36 */ |
|
37 class FilterNodeSoftware : public FilterNode, |
|
38 public FilterInvalidationListener |
|
39 { |
|
40 public: |
|
41 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeSoftware) |
|
42 virtual ~FilterNodeSoftware(); |
|
43 |
|
44 // Factory method, intended to be called from DrawTarget*::CreateFilter. |
|
45 static TemporaryRef<FilterNode> Create(FilterType aType); |
|
46 |
|
47 // Draw the filter, intended to be called by DrawTarget*::DrawFilter. |
|
48 void Draw(DrawTarget* aDrawTarget, const Rect &aSourceRect, |
|
49 const Point &aDestPoint, const DrawOptions &aOptions); |
|
50 |
|
51 virtual FilterBackend GetBackendType() MOZ_OVERRIDE { return FILTER_BACKEND_SOFTWARE; } |
|
52 virtual void SetInput(uint32_t aIndex, SourceSurface *aSurface) MOZ_OVERRIDE; |
|
53 virtual void SetInput(uint32_t aIndex, FilterNode *aFilter) MOZ_OVERRIDE; |
|
54 |
|
55 virtual const char* GetName() { return "Unknown"; } |
|
56 |
|
57 virtual void AddInvalidationListener(FilterInvalidationListener* aListener); |
|
58 virtual void RemoveInvalidationListener(FilterInvalidationListener* aListener); |
|
59 |
|
60 // FilterInvalidationListener implementation |
|
61 virtual void FilterInvalidated(FilterNodeSoftware* aFilter); |
|
62 |
|
63 protected: |
|
64 |
|
65 // The following methods are intended to be overriden by subclasses. |
|
66 |
|
67 /** |
|
68 * Translates a *FilterInputs enum value into an index for the |
|
69 * mInputFilters / mInputSurfaces arrays. Returns -1 for invalid inputs. |
|
70 * If somebody calls SetInput(enumValue, input) with an enumValue for which |
|
71 * InputIndex(enumValue) is -1, we abort. |
|
72 */ |
|
73 virtual int32_t InputIndex(uint32_t aInputEnumIndex) { return -1; } |
|
74 |
|
75 /** |
|
76 * Every filter node has an output rect, which can also be infinite. The |
|
77 * output rect can depend on the values of any set attributes and on the |
|
78 * output rects of any input filters or surfaces. |
|
79 * This method returns the intersection of the filter's output rect with |
|
80 * aInRect. Filters with unconstrained output always return aInRect. |
|
81 */ |
|
82 virtual IntRect GetOutputRectInRect(const IntRect& aInRect) = 0; |
|
83 |
|
84 /** |
|
85 * Return a surface with the rendered output which is of size aRect.Size(). |
|
86 * aRect is required to be a subrect of this filter's output rect; in other |
|
87 * words, aRect == GetOutputRectInRect(aRect) must always be true. |
|
88 * May return nullptr in error conditions or for an empty aRect. |
|
89 * Implementations are not required to allocate a new surface and may even |
|
90 * pass through input surfaces unchanged. |
|
91 * Callers need to treat the returned surface as immutable. |
|
92 */ |
|
93 virtual TemporaryRef<DataSourceSurface> Render(const IntRect& aRect) = 0; |
|
94 |
|
95 /** |
|
96 * Call RequestRect (see below) on any input filters with the desired input |
|
97 * rect, so that the input filter knows what to cache the next time it |
|
98 * renders. |
|
99 */ |
|
100 virtual void RequestFromInputsForRect(const IntRect &aRect) {} |
|
101 |
|
102 /** |
|
103 * This method provides a caching default implementation but can be overriden |
|
104 * by subclasses that don't want to cache their output. Those classes should |
|
105 * call Render(aRect) directly from here. |
|
106 */ |
|
107 virtual TemporaryRef<DataSourceSurface> GetOutput(const IntRect &aRect); |
|
108 |
|
109 // The following methods are non-virtual helper methods. |
|
110 |
|
111 /** |
|
112 * Format hints for GetInputDataSourceSurface. Some callers of |
|
113 * GetInputDataSourceSurface can handle both B8G8R8A8 and A8 surfaces, these |
|
114 * should pass CAN_HANDLE_A8 in order to avoid unnecessary conversions. |
|
115 * Callers that can only handle B8G8R8A8 surfaces pass NEED_COLOR_CHANNELS. |
|
116 */ |
|
117 enum FormatHint { |
|
118 CAN_HANDLE_A8, |
|
119 NEED_COLOR_CHANNELS |
|
120 }; |
|
121 |
|
122 /** |
|
123 * Returns SurfaceFormat::B8G8R8A8 or SurfaceFormat::A8, depending on the current surface |
|
124 * format and the format hint. |
|
125 */ |
|
126 SurfaceFormat DesiredFormat(SurfaceFormat aCurrentFormat, |
|
127 FormatHint aFormatHint); |
|
128 |
|
129 /** |
|
130 * Intended to be called by FilterNodeSoftware::Render implementations. |
|
131 * Returns a surface of size aRect.Size() or nullptr in error conditions. The |
|
132 * returned surface contains the output of the specified input filter or |
|
133 * input surface in aRect. If aRect extends beyond the input filter's output |
|
134 * rect (or the input surface's dimensions), the remaining area is filled |
|
135 * according to aEdgeMode: The default, EDGE_MODE_NONE, simply pads with |
|
136 * transparent black. |
|
137 * If non-null, the returned surface is guaranteed to be of SurfaceFormat::A8 or |
|
138 * SurfaceFormat::B8G8R8A8. If aFormatHint is NEED_COLOR_CHANNELS, the returned |
|
139 * surface is guaranteed to be of SurfaceFormat::B8G8R8A8 always. |
|
140 * Each pixel row of the returned surface is guaranteed to be 16-byte aligned. |
|
141 */ |
|
142 TemporaryRef<DataSourceSurface> |
|
143 GetInputDataSourceSurface(uint32_t aInputEnumIndex, const IntRect& aRect, |
|
144 FormatHint aFormatHint = CAN_HANDLE_A8, |
|
145 ConvolveMatrixEdgeMode aEdgeMode = EDGE_MODE_NONE, |
|
146 const IntRect *aTransparencyPaddedSourceRect = nullptr); |
|
147 |
|
148 /** |
|
149 * Returns the intersection of the input filter's or surface's output rect |
|
150 * with aInRect. |
|
151 */ |
|
152 IntRect GetInputRectInRect(uint32_t aInputEnumIndex, const IntRect& aInRect); |
|
153 |
|
154 /** |
|
155 * Calls RequestRect on the specified input, if it's a filter. |
|
156 */ |
|
157 void RequestInputRect(uint32_t aInputEnumIndex, const IntRect& aRect); |
|
158 |
|
159 /** |
|
160 * Returns the number of set input filters or surfaces. Needed for filters |
|
161 * which can have an arbitrary number of inputs. |
|
162 */ |
|
163 size_t NumberOfSetInputs(); |
|
164 |
|
165 /** |
|
166 * Discard the cached surface that was stored in the GetOutput default |
|
167 * implementation. Needs to be called whenever attributes or inputs are set |
|
168 * that might change the result of a Render() call. |
|
169 */ |
|
170 void Invalidate(); |
|
171 |
|
172 /** |
|
173 * Called in order to let this filter know what to cache during the next |
|
174 * GetOutput call. Expected to call RequestRect on this filter's input |
|
175 * filters. |
|
176 */ |
|
177 void RequestRect(const IntRect &aRect); |
|
178 |
|
179 /** |
|
180 * Set input filter and clear input surface for this input index, or set |
|
181 * input surface and clear input filter. One of aSurface and aFilter should |
|
182 * be null. |
|
183 */ |
|
184 void SetInput(uint32_t aIndex, SourceSurface *aSurface, |
|
185 FilterNodeSoftware *aFilter); |
|
186 |
|
187 protected: |
|
188 /** |
|
189 * mInputSurfaces / mInputFilters: For each input index, either a surface or |
|
190 * a filter is set, and the other is null. |
|
191 */ |
|
192 std::vector<RefPtr<SourceSurface> > mInputSurfaces; |
|
193 std::vector<RefPtr<FilterNodeSoftware> > mInputFilters; |
|
194 |
|
195 /** |
|
196 * Weak pointers to our invalidation listeners, i.e. to those filters who |
|
197 * have this filter as an input. Invalidation listeners are required to |
|
198 * unsubscribe themselves from us when they let go of their reference to us. |
|
199 * This ensures that the pointers in this array are never stale. |
|
200 */ |
|
201 std::vector<FilterInvalidationListener*> mInvalidationListeners; |
|
202 |
|
203 /** |
|
204 * Stores the rect which we want to render and cache on the next call to |
|
205 * GetOutput. |
|
206 */ |
|
207 IntRect mRequestedRect; |
|
208 |
|
209 /** |
|
210 * Stores our cached output. |
|
211 */ |
|
212 IntRect mCachedRect; |
|
213 RefPtr<DataSourceSurface> mCachedOutput; |
|
214 }; |
|
215 |
|
216 // Subclasses for specific filters. |
|
217 |
|
218 class FilterNodeTransformSoftware : public FilterNodeSoftware |
|
219 { |
|
220 public: |
|
221 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeTransformSoftware) |
|
222 FilterNodeTransformSoftware(); |
|
223 virtual const char* GetName() MOZ_OVERRIDE { return "Transform"; } |
|
224 using FilterNodeSoftware::SetAttribute; |
|
225 virtual void SetAttribute(uint32_t aIndex, uint32_t aGraphicsFilter) MOZ_OVERRIDE; |
|
226 virtual void SetAttribute(uint32_t aIndex, const Matrix &aMatrix) MOZ_OVERRIDE; |
|
227 |
|
228 protected: |
|
229 virtual TemporaryRef<DataSourceSurface> Render(const IntRect& aRect) MOZ_OVERRIDE; |
|
230 virtual IntRect GetOutputRectInRect(const IntRect& aRect) MOZ_OVERRIDE; |
|
231 virtual int32_t InputIndex(uint32_t aInputEnumIndex) MOZ_OVERRIDE; |
|
232 virtual void RequestFromInputsForRect(const IntRect &aRect) MOZ_OVERRIDE; |
|
233 IntRect SourceRectForOutputRect(const IntRect &aRect); |
|
234 |
|
235 private: |
|
236 Matrix mMatrix; |
|
237 Filter mFilter; |
|
238 }; |
|
239 |
|
240 class FilterNodeBlendSoftware : public FilterNodeSoftware |
|
241 { |
|
242 public: |
|
243 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeBlendSoftware) |
|
244 FilterNodeBlendSoftware(); |
|
245 virtual const char* GetName() MOZ_OVERRIDE { return "Blend"; } |
|
246 using FilterNodeSoftware::SetAttribute; |
|
247 virtual void SetAttribute(uint32_t aIndex, uint32_t aBlendMode) MOZ_OVERRIDE; |
|
248 |
|
249 protected: |
|
250 virtual TemporaryRef<DataSourceSurface> Render(const IntRect& aRect) MOZ_OVERRIDE; |
|
251 virtual IntRect GetOutputRectInRect(const IntRect& aRect) MOZ_OVERRIDE; |
|
252 virtual int32_t InputIndex(uint32_t aInputEnumIndex) MOZ_OVERRIDE; |
|
253 virtual void RequestFromInputsForRect(const IntRect &aRect) MOZ_OVERRIDE; |
|
254 |
|
255 private: |
|
256 BlendMode mBlendMode; |
|
257 }; |
|
258 |
|
259 class FilterNodeMorphologySoftware : public FilterNodeSoftware |
|
260 { |
|
261 public: |
|
262 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeMorphologySoftware) |
|
263 FilterNodeMorphologySoftware(); |
|
264 virtual const char* GetName() MOZ_OVERRIDE { return "Morphology"; } |
|
265 using FilterNodeSoftware::SetAttribute; |
|
266 virtual void SetAttribute(uint32_t aIndex, const IntSize &aRadii) MOZ_OVERRIDE; |
|
267 virtual void SetAttribute(uint32_t aIndex, uint32_t aOperator) MOZ_OVERRIDE; |
|
268 |
|
269 protected: |
|
270 virtual TemporaryRef<DataSourceSurface> Render(const IntRect& aRect) MOZ_OVERRIDE; |
|
271 virtual IntRect GetOutputRectInRect(const IntRect& aRect) MOZ_OVERRIDE; |
|
272 virtual int32_t InputIndex(uint32_t aInputEnumIndex) MOZ_OVERRIDE; |
|
273 virtual void RequestFromInputsForRect(const IntRect &aRect) MOZ_OVERRIDE; |
|
274 |
|
275 private: |
|
276 IntSize mRadii; |
|
277 MorphologyOperator mOperator; |
|
278 }; |
|
279 |
|
280 class FilterNodeColorMatrixSoftware : public FilterNodeSoftware |
|
281 { |
|
282 public: |
|
283 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeColorMatrixSoftware) |
|
284 virtual const char* GetName() MOZ_OVERRIDE { return "ColorMatrix"; } |
|
285 using FilterNodeSoftware::SetAttribute; |
|
286 virtual void SetAttribute(uint32_t aIndex, const Matrix5x4 &aMatrix) MOZ_OVERRIDE; |
|
287 virtual void SetAttribute(uint32_t aIndex, uint32_t aAlphaMode) MOZ_OVERRIDE; |
|
288 |
|
289 protected: |
|
290 virtual TemporaryRef<DataSourceSurface> Render(const IntRect& aRect) MOZ_OVERRIDE; |
|
291 virtual IntRect GetOutputRectInRect(const IntRect& aRect) MOZ_OVERRIDE; |
|
292 virtual int32_t InputIndex(uint32_t aInputEnumIndex) MOZ_OVERRIDE; |
|
293 virtual void RequestFromInputsForRect(const IntRect &aRect) MOZ_OVERRIDE; |
|
294 |
|
295 private: |
|
296 Matrix5x4 mMatrix; |
|
297 AlphaMode mAlphaMode; |
|
298 }; |
|
299 |
|
300 class FilterNodeFloodSoftware : public FilterNodeSoftware |
|
301 { |
|
302 public: |
|
303 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeFloodSoftware) |
|
304 virtual const char* GetName() MOZ_OVERRIDE { return "Flood"; } |
|
305 using FilterNodeSoftware::SetAttribute; |
|
306 virtual void SetAttribute(uint32_t aIndex, const Color &aColor) MOZ_OVERRIDE; |
|
307 |
|
308 protected: |
|
309 virtual TemporaryRef<DataSourceSurface> GetOutput(const IntRect &aRect) MOZ_OVERRIDE; |
|
310 virtual TemporaryRef<DataSourceSurface> Render(const IntRect& aRect) MOZ_OVERRIDE; |
|
311 virtual IntRect GetOutputRectInRect(const IntRect& aRect) MOZ_OVERRIDE; |
|
312 |
|
313 private: |
|
314 Color mColor; |
|
315 }; |
|
316 |
|
317 class FilterNodeTileSoftware : public FilterNodeSoftware |
|
318 { |
|
319 public: |
|
320 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeTileSoftware) |
|
321 virtual const char* GetName() MOZ_OVERRIDE { return "Tile"; } |
|
322 using FilterNodeSoftware::SetAttribute; |
|
323 virtual void SetAttribute(uint32_t aIndex, const IntRect &aSourceRect) MOZ_OVERRIDE; |
|
324 |
|
325 protected: |
|
326 virtual TemporaryRef<DataSourceSurface> Render(const IntRect& aRect) MOZ_OVERRIDE; |
|
327 virtual IntRect GetOutputRectInRect(const IntRect& aRect) MOZ_OVERRIDE; |
|
328 virtual int32_t InputIndex(uint32_t aInputEnumIndex) MOZ_OVERRIDE; |
|
329 virtual void RequestFromInputsForRect(const IntRect &aRect) MOZ_OVERRIDE; |
|
330 |
|
331 private: |
|
332 IntRect mSourceRect; |
|
333 }; |
|
334 |
|
335 /** |
|
336 * Baseclass for the four different component transfer filters. |
|
337 */ |
|
338 class FilterNodeComponentTransferSoftware : public FilterNodeSoftware |
|
339 { |
|
340 public: |
|
341 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeComponentTransferSoftware) |
|
342 FilterNodeComponentTransferSoftware(); |
|
343 |
|
344 using FilterNodeSoftware::SetAttribute; |
|
345 virtual void SetAttribute(uint32_t aIndex, bool aDisable) MOZ_OVERRIDE; |
|
346 |
|
347 protected: |
|
348 virtual TemporaryRef<DataSourceSurface> Render(const IntRect& aRect) MOZ_OVERRIDE; |
|
349 virtual IntRect GetOutputRectInRect(const IntRect& aRect) MOZ_OVERRIDE; |
|
350 virtual int32_t InputIndex(uint32_t aInputEnumIndex) MOZ_OVERRIDE; |
|
351 virtual void RequestFromInputsForRect(const IntRect &aRect) MOZ_OVERRIDE; |
|
352 virtual void GenerateLookupTable(ptrdiff_t aComponent, uint8_t aTables[4][256], |
|
353 bool aDisabled); |
|
354 virtual void FillLookupTable(ptrdiff_t aComponent, uint8_t aTable[256]) = 0; |
|
355 |
|
356 bool mDisableR; |
|
357 bool mDisableG; |
|
358 bool mDisableB; |
|
359 bool mDisableA; |
|
360 }; |
|
361 |
|
362 class FilterNodeTableTransferSoftware : public FilterNodeComponentTransferSoftware |
|
363 { |
|
364 public: |
|
365 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeTableTransferSoftware) |
|
366 virtual const char* GetName() MOZ_OVERRIDE { return "TableTransfer"; } |
|
367 using FilterNodeComponentTransferSoftware::SetAttribute; |
|
368 virtual void SetAttribute(uint32_t aIndex, const Float* aFloat, uint32_t aSize) MOZ_OVERRIDE; |
|
369 |
|
370 protected: |
|
371 virtual void FillLookupTable(ptrdiff_t aComponent, uint8_t aTable[256]) MOZ_OVERRIDE; |
|
372 |
|
373 private: |
|
374 void FillLookupTableImpl(std::vector<Float>& aTableValues, uint8_t aTable[256]); |
|
375 |
|
376 std::vector<Float> mTableR; |
|
377 std::vector<Float> mTableG; |
|
378 std::vector<Float> mTableB; |
|
379 std::vector<Float> mTableA; |
|
380 }; |
|
381 |
|
382 class FilterNodeDiscreteTransferSoftware : public FilterNodeComponentTransferSoftware |
|
383 { |
|
384 public: |
|
385 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeDiscreteTransferSoftware) |
|
386 virtual const char* GetName() MOZ_OVERRIDE { return "DiscreteTransfer"; } |
|
387 using FilterNodeComponentTransferSoftware::SetAttribute; |
|
388 virtual void SetAttribute(uint32_t aIndex, const Float* aFloat, uint32_t aSize) MOZ_OVERRIDE; |
|
389 |
|
390 protected: |
|
391 virtual void FillLookupTable(ptrdiff_t aComponent, uint8_t aTable[256]) MOZ_OVERRIDE; |
|
392 |
|
393 private: |
|
394 void FillLookupTableImpl(std::vector<Float>& aTableValues, uint8_t aTable[256]); |
|
395 |
|
396 std::vector<Float> mTableR; |
|
397 std::vector<Float> mTableG; |
|
398 std::vector<Float> mTableB; |
|
399 std::vector<Float> mTableA; |
|
400 }; |
|
401 |
|
402 class FilterNodeLinearTransferSoftware : public FilterNodeComponentTransferSoftware |
|
403 { |
|
404 public: |
|
405 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeLinearTransformSoftware) |
|
406 FilterNodeLinearTransferSoftware(); |
|
407 virtual const char* GetName() MOZ_OVERRIDE { return "LinearTransfer"; } |
|
408 using FilterNodeComponentTransferSoftware::SetAttribute; |
|
409 virtual void SetAttribute(uint32_t aIndex, Float aValue) MOZ_OVERRIDE; |
|
410 |
|
411 protected: |
|
412 virtual void FillLookupTable(ptrdiff_t aComponent, uint8_t aTable[256]) MOZ_OVERRIDE; |
|
413 |
|
414 private: |
|
415 void FillLookupTableImpl(Float aSlope, Float aIntercept, uint8_t aTable[256]); |
|
416 |
|
417 Float mSlopeR; |
|
418 Float mSlopeG; |
|
419 Float mSlopeB; |
|
420 Float mSlopeA; |
|
421 Float mInterceptR; |
|
422 Float mInterceptG; |
|
423 Float mInterceptB; |
|
424 Float mInterceptA; |
|
425 }; |
|
426 |
|
427 class FilterNodeGammaTransferSoftware : public FilterNodeComponentTransferSoftware |
|
428 { |
|
429 public: |
|
430 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeGammaTransferSoftware) |
|
431 FilterNodeGammaTransferSoftware(); |
|
432 virtual const char* GetName() MOZ_OVERRIDE { return "GammaTransfer"; } |
|
433 using FilterNodeComponentTransferSoftware::SetAttribute; |
|
434 virtual void SetAttribute(uint32_t aIndex, Float aValue) MOZ_OVERRIDE; |
|
435 |
|
436 protected: |
|
437 virtual void FillLookupTable(ptrdiff_t aComponent, uint8_t aTable[256]) MOZ_OVERRIDE; |
|
438 |
|
439 private: |
|
440 void FillLookupTableImpl(Float aAmplitude, Float aExponent, Float aOffset, uint8_t aTable[256]); |
|
441 |
|
442 Float mAmplitudeR; |
|
443 Float mAmplitudeG; |
|
444 Float mAmplitudeB; |
|
445 Float mAmplitudeA; |
|
446 Float mExponentR; |
|
447 Float mExponentG; |
|
448 Float mExponentB; |
|
449 Float mExponentA; |
|
450 Float mOffsetR; |
|
451 Float mOffsetG; |
|
452 Float mOffsetB; |
|
453 Float mOffsetA; |
|
454 }; |
|
455 |
|
456 class FilterNodeConvolveMatrixSoftware : public FilterNodeSoftware |
|
457 { |
|
458 public: |
|
459 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeConvolveMatrixSoftware) |
|
460 FilterNodeConvolveMatrixSoftware(); |
|
461 virtual const char* GetName() MOZ_OVERRIDE { return "ConvolveMatrix"; } |
|
462 using FilterNodeSoftware::SetAttribute; |
|
463 virtual void SetAttribute(uint32_t aIndex, const IntSize &aKernelSize) MOZ_OVERRIDE; |
|
464 virtual void SetAttribute(uint32_t aIndex, const Float* aMatrix, uint32_t aSize) MOZ_OVERRIDE; |
|
465 virtual void SetAttribute(uint32_t aIndex, Float aValue) MOZ_OVERRIDE; |
|
466 virtual void SetAttribute(uint32_t aIndex, const Size &aKernelUnitLength) MOZ_OVERRIDE; |
|
467 virtual void SetAttribute(uint32_t aIndex, const IntRect &aSourceRect) MOZ_OVERRIDE; |
|
468 virtual void SetAttribute(uint32_t aIndex, const IntPoint &aTarget) MOZ_OVERRIDE; |
|
469 virtual void SetAttribute(uint32_t aIndex, uint32_t aEdgeMode) MOZ_OVERRIDE; |
|
470 virtual void SetAttribute(uint32_t aIndex, bool aPreserveAlpha) MOZ_OVERRIDE; |
|
471 |
|
472 protected: |
|
473 virtual TemporaryRef<DataSourceSurface> Render(const IntRect& aRect) MOZ_OVERRIDE; |
|
474 virtual IntRect GetOutputRectInRect(const IntRect& aRect) MOZ_OVERRIDE; |
|
475 virtual int32_t InputIndex(uint32_t aInputEnumIndex) MOZ_OVERRIDE; |
|
476 virtual void RequestFromInputsForRect(const IntRect &aRect) MOZ_OVERRIDE; |
|
477 |
|
478 private: |
|
479 template<typename CoordType> |
|
480 TemporaryRef<DataSourceSurface> DoRender(const IntRect& aRect, |
|
481 CoordType aKernelUnitLengthX, |
|
482 CoordType aKernelUnitLengthY); |
|
483 |
|
484 IntRect InflatedSourceRect(const IntRect &aDestRect); |
|
485 IntRect InflatedDestRect(const IntRect &aSourceRect); |
|
486 |
|
487 IntSize mKernelSize; |
|
488 std::vector<Float> mKernelMatrix; |
|
489 Float mDivisor; |
|
490 Float mBias; |
|
491 IntPoint mTarget; |
|
492 IntRect mSourceRect; |
|
493 ConvolveMatrixEdgeMode mEdgeMode; |
|
494 Size mKernelUnitLength; |
|
495 bool mPreserveAlpha; |
|
496 }; |
|
497 |
|
498 class FilterNodeDisplacementMapSoftware : public FilterNodeSoftware |
|
499 { |
|
500 public: |
|
501 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeDisplacementMapSoftware) |
|
502 FilterNodeDisplacementMapSoftware(); |
|
503 virtual const char* GetName() MOZ_OVERRIDE { return "DisplacementMap"; } |
|
504 using FilterNodeSoftware::SetAttribute; |
|
505 virtual void SetAttribute(uint32_t aIndex, Float aScale) MOZ_OVERRIDE; |
|
506 virtual void SetAttribute(uint32_t aIndex, uint32_t aValue) MOZ_OVERRIDE; |
|
507 |
|
508 protected: |
|
509 virtual TemporaryRef<DataSourceSurface> Render(const IntRect& aRect) MOZ_OVERRIDE; |
|
510 virtual IntRect GetOutputRectInRect(const IntRect& aRect) MOZ_OVERRIDE; |
|
511 virtual int32_t InputIndex(uint32_t aInputEnumIndex) MOZ_OVERRIDE; |
|
512 virtual void RequestFromInputsForRect(const IntRect &aRect) MOZ_OVERRIDE; |
|
513 |
|
514 private: |
|
515 IntRect InflatedSourceOrDestRect(const IntRect &aDestOrSourceRect); |
|
516 |
|
517 Float mScale; |
|
518 ColorChannel mChannelX; |
|
519 ColorChannel mChannelY; |
|
520 }; |
|
521 |
|
522 class FilterNodeTurbulenceSoftware : public FilterNodeSoftware |
|
523 { |
|
524 public: |
|
525 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeTurbulenceSoftware) |
|
526 FilterNodeTurbulenceSoftware(); |
|
527 virtual const char* GetName() MOZ_OVERRIDE { return "Turbulence"; } |
|
528 using FilterNodeSoftware::SetAttribute; |
|
529 virtual void SetAttribute(uint32_t aIndex, const Size &aSize) MOZ_OVERRIDE; |
|
530 virtual void SetAttribute(uint32_t aIndex, const IntRect &aRenderRect) MOZ_OVERRIDE; |
|
531 virtual void SetAttribute(uint32_t aIndex, bool aStitchable) MOZ_OVERRIDE; |
|
532 virtual void SetAttribute(uint32_t aIndex, uint32_t aValue) MOZ_OVERRIDE; |
|
533 |
|
534 protected: |
|
535 virtual TemporaryRef<DataSourceSurface> Render(const IntRect& aRect) MOZ_OVERRIDE; |
|
536 virtual IntRect GetOutputRectInRect(const IntRect& aRect) MOZ_OVERRIDE; |
|
537 virtual int32_t InputIndex(uint32_t aInputEnumIndex) MOZ_OVERRIDE; |
|
538 |
|
539 private: |
|
540 IntRect mRenderRect; |
|
541 Size mBaseFrequency; |
|
542 uint32_t mNumOctaves; |
|
543 uint32_t mSeed; |
|
544 bool mStitchable; |
|
545 TurbulenceType mType; |
|
546 }; |
|
547 |
|
548 class FilterNodeArithmeticCombineSoftware : public FilterNodeSoftware |
|
549 { |
|
550 public: |
|
551 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeArithmeticCombineSoftware) |
|
552 FilterNodeArithmeticCombineSoftware(); |
|
553 virtual const char* GetName() MOZ_OVERRIDE { return "ArithmeticCombine"; } |
|
554 using FilterNodeSoftware::SetAttribute; |
|
555 virtual void SetAttribute(uint32_t aIndex, const Float* aFloat, uint32_t aSize) MOZ_OVERRIDE; |
|
556 |
|
557 protected: |
|
558 virtual TemporaryRef<DataSourceSurface> Render(const IntRect& aRect) MOZ_OVERRIDE; |
|
559 virtual IntRect GetOutputRectInRect(const IntRect& aRect) MOZ_OVERRIDE; |
|
560 virtual int32_t InputIndex(uint32_t aInputEnumIndex) MOZ_OVERRIDE; |
|
561 virtual void RequestFromInputsForRect(const IntRect &aRect) MOZ_OVERRIDE; |
|
562 |
|
563 private: |
|
564 Float mK1; |
|
565 Float mK2; |
|
566 Float mK3; |
|
567 Float mK4; |
|
568 }; |
|
569 |
|
570 class FilterNodeCompositeSoftware : public FilterNodeSoftware |
|
571 { |
|
572 public: |
|
573 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeCompositeSoftware) |
|
574 FilterNodeCompositeSoftware(); |
|
575 virtual const char* GetName() MOZ_OVERRIDE { return "Composite"; } |
|
576 using FilterNodeSoftware::SetAttribute; |
|
577 virtual void SetAttribute(uint32_t aIndex, uint32_t aOperator) MOZ_OVERRIDE; |
|
578 |
|
579 protected: |
|
580 virtual TemporaryRef<DataSourceSurface> Render(const IntRect& aRect) MOZ_OVERRIDE; |
|
581 virtual IntRect GetOutputRectInRect(const IntRect& aRect) MOZ_OVERRIDE; |
|
582 virtual int32_t InputIndex(uint32_t aInputEnumIndex) MOZ_OVERRIDE; |
|
583 virtual void RequestFromInputsForRect(const IntRect &aRect) MOZ_OVERRIDE; |
|
584 |
|
585 private: |
|
586 CompositeOperator mOperator; |
|
587 }; |
|
588 |
|
589 // Base class for FilterNodeGaussianBlurSoftware and |
|
590 // FilterNodeDirectionalBlurSoftware. |
|
591 class FilterNodeBlurXYSoftware : public FilterNodeSoftware |
|
592 { |
|
593 public: |
|
594 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeBlurXYSoftware) |
|
595 protected: |
|
596 virtual TemporaryRef<DataSourceSurface> Render(const IntRect& aRect) MOZ_OVERRIDE; |
|
597 virtual IntRect GetOutputRectInRect(const IntRect& aRect) MOZ_OVERRIDE; |
|
598 virtual int32_t InputIndex(uint32_t aInputEnumIndex) MOZ_OVERRIDE; |
|
599 IntRect InflatedSourceOrDestRect(const IntRect &aDestRect); |
|
600 virtual void RequestFromInputsForRect(const IntRect &aRect) MOZ_OVERRIDE; |
|
601 |
|
602 // Implemented by subclasses. |
|
603 virtual Size StdDeviationXY() = 0; |
|
604 }; |
|
605 |
|
606 class FilterNodeGaussianBlurSoftware : public FilterNodeBlurXYSoftware |
|
607 { |
|
608 public: |
|
609 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeGaussianBlurSoftware) |
|
610 FilterNodeGaussianBlurSoftware(); |
|
611 virtual const char* GetName() MOZ_OVERRIDE { return "GaussianBlur"; } |
|
612 using FilterNodeSoftware::SetAttribute; |
|
613 virtual void SetAttribute(uint32_t aIndex, Float aStdDeviation) MOZ_OVERRIDE; |
|
614 |
|
615 protected: |
|
616 virtual Size StdDeviationXY() MOZ_OVERRIDE; |
|
617 |
|
618 private: |
|
619 Float mStdDeviation; |
|
620 }; |
|
621 |
|
622 class FilterNodeDirectionalBlurSoftware : public FilterNodeBlurXYSoftware |
|
623 { |
|
624 public: |
|
625 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeDirectionalBlurSoftware) |
|
626 FilterNodeDirectionalBlurSoftware(); |
|
627 virtual const char* GetName() MOZ_OVERRIDE { return "DirectionalBlur"; } |
|
628 using FilterNodeSoftware::SetAttribute; |
|
629 virtual void SetAttribute(uint32_t aIndex, Float aStdDeviation) MOZ_OVERRIDE; |
|
630 virtual void SetAttribute(uint32_t aIndex, uint32_t aBlurDirection) MOZ_OVERRIDE; |
|
631 |
|
632 protected: |
|
633 virtual Size StdDeviationXY() MOZ_OVERRIDE; |
|
634 |
|
635 private: |
|
636 Float mStdDeviation; |
|
637 BlurDirection mBlurDirection; |
|
638 }; |
|
639 |
|
640 class FilterNodeCropSoftware : public FilterNodeSoftware |
|
641 { |
|
642 public: |
|
643 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeCropSoftware) |
|
644 virtual const char* GetName() MOZ_OVERRIDE { return "Crop"; } |
|
645 using FilterNodeSoftware::SetAttribute; |
|
646 virtual void SetAttribute(uint32_t aIndex, const Rect &aSourceRect) MOZ_OVERRIDE; |
|
647 |
|
648 protected: |
|
649 virtual TemporaryRef<DataSourceSurface> Render(const IntRect& aRect) MOZ_OVERRIDE; |
|
650 virtual IntRect GetOutputRectInRect(const IntRect& aRect) MOZ_OVERRIDE; |
|
651 virtual int32_t InputIndex(uint32_t aInputEnumIndex) MOZ_OVERRIDE; |
|
652 virtual void RequestFromInputsForRect(const IntRect &aRect) MOZ_OVERRIDE; |
|
653 |
|
654 private: |
|
655 IntRect mCropRect; |
|
656 }; |
|
657 |
|
658 class FilterNodePremultiplySoftware : public FilterNodeSoftware |
|
659 { |
|
660 public: |
|
661 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodePremultiplySoftware) |
|
662 virtual const char* GetName() MOZ_OVERRIDE { return "Premultiply"; } |
|
663 protected: |
|
664 virtual TemporaryRef<DataSourceSurface> Render(const IntRect& aRect) MOZ_OVERRIDE; |
|
665 virtual IntRect GetOutputRectInRect(const IntRect& aRect) MOZ_OVERRIDE; |
|
666 virtual int32_t InputIndex(uint32_t aInputEnumIndex) MOZ_OVERRIDE; |
|
667 virtual void RequestFromInputsForRect(const IntRect &aRect) MOZ_OVERRIDE; |
|
668 }; |
|
669 |
|
670 class FilterNodeUnpremultiplySoftware : public FilterNodeSoftware |
|
671 { |
|
672 public: |
|
673 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeUnpremultiplySoftware) |
|
674 virtual const char* GetName() MOZ_OVERRIDE { return "Unpremultiply"; } |
|
675 protected: |
|
676 virtual TemporaryRef<DataSourceSurface> Render(const IntRect& aRect) MOZ_OVERRIDE; |
|
677 virtual IntRect GetOutputRectInRect(const IntRect& aRect) MOZ_OVERRIDE; |
|
678 virtual int32_t InputIndex(uint32_t aInputEnumIndex) MOZ_OVERRIDE; |
|
679 virtual void RequestFromInputsForRect(const IntRect &aRect) MOZ_OVERRIDE; |
|
680 }; |
|
681 |
|
682 template<typename LightType, typename LightingType> |
|
683 class FilterNodeLightingSoftware : public FilterNodeSoftware |
|
684 { |
|
685 public: |
|
686 #if defined(MOZILLA_INTERNAL_API) && (defined(DEBUG) || defined(FORCE_BUILD_REFCNT_LOGGING)) |
|
687 // Helpers for refcounted |
|
688 virtual const char* typeName() const MOZ_OVERRIDE { return mTypeName; } |
|
689 virtual size_t typeSize() const MOZ_OVERRIDE { return sizeof(*this); } |
|
690 #endif |
|
691 explicit FilterNodeLightingSoftware(const char* aTypeName); |
|
692 virtual const char* GetName() MOZ_OVERRIDE { return "Lighting"; } |
|
693 using FilterNodeSoftware::SetAttribute; |
|
694 virtual void SetAttribute(uint32_t aIndex, Float) MOZ_OVERRIDE; |
|
695 virtual void SetAttribute(uint32_t aIndex, const Size &) MOZ_OVERRIDE; |
|
696 virtual void SetAttribute(uint32_t aIndex, const Point3D &) MOZ_OVERRIDE; |
|
697 virtual void SetAttribute(uint32_t aIndex, const Color &) MOZ_OVERRIDE; |
|
698 |
|
699 protected: |
|
700 virtual TemporaryRef<DataSourceSurface> Render(const IntRect& aRect) MOZ_OVERRIDE; |
|
701 virtual IntRect GetOutputRectInRect(const IntRect& aRect) MOZ_OVERRIDE; |
|
702 virtual int32_t InputIndex(uint32_t aInputEnumIndex) MOZ_OVERRIDE; |
|
703 virtual void RequestFromInputsForRect(const IntRect &aRect) MOZ_OVERRIDE; |
|
704 |
|
705 private: |
|
706 template<typename CoordType> |
|
707 TemporaryRef<DataSourceSurface> DoRender(const IntRect& aRect, |
|
708 CoordType aKernelUnitLengthX, |
|
709 CoordType aKernelUnitLengthY); |
|
710 |
|
711 LightType mLight; |
|
712 LightingType mLighting; |
|
713 Float mSurfaceScale; |
|
714 Size mKernelUnitLength; |
|
715 Color mColor; |
|
716 #if defined(MOZILLA_INTERNAL_API) && (defined(DEBUG) || defined(FORCE_BUILD_REFCNT_LOGGING)) |
|
717 const char* mTypeName; |
|
718 #endif |
|
719 }; |
|
720 |
|
721 } |
|
722 } |
|
723 |
|
724 #endif // _MOZILLA_GFX_FILTERNODESOFTWARE_H_ |