Line data Source code
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 0 : 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 0 : class FilterNodeSoftware : public FilterNode,
38 : public FilterInvalidationListener
39 : {
40 : public:
41 0 : MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeSoftware, override)
42 : virtual ~FilterNodeSoftware();
43 :
44 : // Factory method, intended to be called from DrawTarget*::CreateFilter.
45 : static already_AddRefed<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 0 : virtual FilterBackend GetBackendType() override { return FILTER_BACKEND_SOFTWARE; }
52 : virtual void SetInput(uint32_t aIndex, SourceSurface *aSurface) override;
53 : virtual void SetInput(uint32_t aIndex, FilterNode *aFilter) override;
54 :
55 0 : 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) override;
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 0 : 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 already_AddRefed<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 0 : 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 already_AddRefed<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 : already_AddRefed<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 0 : class FilterNodeTransformSoftware : public FilterNodeSoftware
219 : {
220 : public:
221 0 : MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeTransformSoftware, override)
222 : FilterNodeTransformSoftware();
223 0 : virtual const char* GetName() override { return "Transform"; }
224 : using FilterNodeSoftware::SetAttribute;
225 : virtual void SetAttribute(uint32_t aIndex, uint32_t aGraphicsFilter) override;
226 : virtual void SetAttribute(uint32_t aIndex, const Matrix &aMatrix) override;
227 :
228 : protected:
229 : virtual already_AddRefed<DataSourceSurface> Render(const IntRect& aRect) override;
230 : virtual IntRect GetOutputRectInRect(const IntRect& aRect) override;
231 : virtual int32_t InputIndex(uint32_t aInputEnumIndex) override;
232 : virtual void RequestFromInputsForRect(const IntRect &aRect) override;
233 : IntRect SourceRectForOutputRect(const IntRect &aRect);
234 :
235 : private:
236 : Matrix mMatrix;
237 : SamplingFilter mSamplingFilter;
238 : };
239 :
240 0 : class FilterNodeBlendSoftware : public FilterNodeSoftware
241 : {
242 : public:
243 0 : MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeBlendSoftware, override)
244 : FilterNodeBlendSoftware();
245 0 : virtual const char* GetName() override { return "Blend"; }
246 : using FilterNodeSoftware::SetAttribute;
247 : virtual void SetAttribute(uint32_t aIndex, uint32_t aBlendMode) override;
248 :
249 : protected:
250 : virtual already_AddRefed<DataSourceSurface> Render(const IntRect& aRect) override;
251 : virtual IntRect GetOutputRectInRect(const IntRect& aRect) override;
252 : virtual int32_t InputIndex(uint32_t aInputEnumIndex) override;
253 : virtual void RequestFromInputsForRect(const IntRect &aRect) override;
254 :
255 : private:
256 : BlendMode mBlendMode;
257 : };
258 :
259 0 : class FilterNodeMorphologySoftware : public FilterNodeSoftware
260 : {
261 : public:
262 0 : MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeMorphologySoftware, override)
263 : FilterNodeMorphologySoftware();
264 0 : virtual const char* GetName() override { return "Morphology"; }
265 : using FilterNodeSoftware::SetAttribute;
266 : virtual void SetAttribute(uint32_t aIndex, const IntSize &aRadii) override;
267 : virtual void SetAttribute(uint32_t aIndex, uint32_t aOperator) override;
268 :
269 : protected:
270 : virtual already_AddRefed<DataSourceSurface> Render(const IntRect& aRect) override;
271 : virtual IntRect GetOutputRectInRect(const IntRect& aRect) override;
272 : virtual int32_t InputIndex(uint32_t aInputEnumIndex) override;
273 : virtual void RequestFromInputsForRect(const IntRect &aRect) override;
274 :
275 : private:
276 : IntSize mRadii;
277 : MorphologyOperator mOperator;
278 : };
279 :
280 0 : class FilterNodeColorMatrixSoftware : public FilterNodeSoftware
281 : {
282 : public:
283 0 : MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeColorMatrixSoftware, override)
284 0 : virtual const char* GetName() override { return "ColorMatrix"; }
285 : using FilterNodeSoftware::SetAttribute;
286 : virtual void SetAttribute(uint32_t aIndex, const Matrix5x4 &aMatrix) override;
287 : virtual void SetAttribute(uint32_t aIndex, uint32_t aAlphaMode) override;
288 :
289 : protected:
290 : virtual already_AddRefed<DataSourceSurface> Render(const IntRect& aRect) override;
291 : virtual IntRect GetOutputRectInRect(const IntRect& aRect) override;
292 : virtual int32_t InputIndex(uint32_t aInputEnumIndex) override;
293 : virtual void RequestFromInputsForRect(const IntRect &aRect) override;
294 :
295 : private:
296 : Matrix5x4 mMatrix;
297 : AlphaMode mAlphaMode;
298 : };
299 :
300 0 : class FilterNodeFloodSoftware : public FilterNodeSoftware
301 : {
302 : public:
303 0 : MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeFloodSoftware, override)
304 0 : virtual const char* GetName() override { return "Flood"; }
305 : using FilterNodeSoftware::SetAttribute;
306 : virtual void SetAttribute(uint32_t aIndex, const Color &aColor) override;
307 :
308 : protected:
309 : virtual already_AddRefed<DataSourceSurface> GetOutput(const IntRect &aRect) override;
310 : virtual already_AddRefed<DataSourceSurface> Render(const IntRect& aRect) override;
311 : virtual IntRect GetOutputRectInRect(const IntRect& aRect) override;
312 :
313 : private:
314 : Color mColor;
315 : };
316 :
317 0 : class FilterNodeTileSoftware : public FilterNodeSoftware
318 : {
319 : public:
320 0 : MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeTileSoftware, override)
321 0 : virtual const char* GetName() override { return "Tile"; }
322 : using FilterNodeSoftware::SetAttribute;
323 : virtual void SetAttribute(uint32_t aIndex, const IntRect &aSourceRect) override;
324 :
325 : protected:
326 : virtual already_AddRefed<DataSourceSurface> Render(const IntRect& aRect) override;
327 : virtual IntRect GetOutputRectInRect(const IntRect& aRect) override;
328 : virtual int32_t InputIndex(uint32_t aInputEnumIndex) override;
329 : virtual void RequestFromInputsForRect(const IntRect &aRect) override;
330 :
331 : private:
332 : IntRect mSourceRect;
333 : };
334 :
335 : /**
336 : * Baseclass for the four different component transfer filters.
337 : */
338 0 : class FilterNodeComponentTransferSoftware : public FilterNodeSoftware
339 : {
340 : public:
341 0 : MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeComponentTransferSoftware, override)
342 : FilterNodeComponentTransferSoftware();
343 :
344 : using FilterNodeSoftware::SetAttribute;
345 : virtual void SetAttribute(uint32_t aIndex, bool aDisable) override;
346 :
347 : protected:
348 : virtual already_AddRefed<DataSourceSurface> Render(const IntRect& aRect) override;
349 : virtual IntRect GetOutputRectInRect(const IntRect& aRect) override;
350 : virtual int32_t InputIndex(uint32_t aInputEnumIndex) override;
351 : virtual void RequestFromInputsForRect(const IntRect &aRect) 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 0 : class FilterNodeTableTransferSoftware : public FilterNodeComponentTransferSoftware
363 : {
364 : public:
365 0 : MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeTableTransferSoftware, override)
366 0 : virtual const char* GetName() override { return "TableTransfer"; }
367 : using FilterNodeComponentTransferSoftware::SetAttribute;
368 : virtual void SetAttribute(uint32_t aIndex, const Float* aFloat, uint32_t aSize) override;
369 :
370 : protected:
371 : virtual void FillLookupTable(ptrdiff_t aComponent, uint8_t aTable[256]) 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 0 : class FilterNodeDiscreteTransferSoftware : public FilterNodeComponentTransferSoftware
383 : {
384 : public:
385 0 : MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeDiscreteTransferSoftware, override)
386 0 : virtual const char* GetName() override { return "DiscreteTransfer"; }
387 : using FilterNodeComponentTransferSoftware::SetAttribute;
388 : virtual void SetAttribute(uint32_t aIndex, const Float* aFloat, uint32_t aSize) override;
389 :
390 : protected:
391 : virtual void FillLookupTable(ptrdiff_t aComponent, uint8_t aTable[256]) 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 0 : class FilterNodeLinearTransferSoftware : public FilterNodeComponentTransferSoftware
403 : {
404 : public:
405 0 : MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeLinearTransformSoftware, override)
406 : FilterNodeLinearTransferSoftware();
407 0 : virtual const char* GetName() override { return "LinearTransfer"; }
408 : using FilterNodeComponentTransferSoftware::SetAttribute;
409 : virtual void SetAttribute(uint32_t aIndex, Float aValue) override;
410 :
411 : protected:
412 : virtual void FillLookupTable(ptrdiff_t aComponent, uint8_t aTable[256]) 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 0 : class FilterNodeGammaTransferSoftware : public FilterNodeComponentTransferSoftware
428 : {
429 : public:
430 0 : MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeGammaTransferSoftware, override)
431 : FilterNodeGammaTransferSoftware();
432 0 : virtual const char* GetName() override { return "GammaTransfer"; }
433 : using FilterNodeComponentTransferSoftware::SetAttribute;
434 : virtual void SetAttribute(uint32_t aIndex, Float aValue) override;
435 :
436 : protected:
437 : virtual void FillLookupTable(ptrdiff_t aComponent, uint8_t aTable[256]) 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 0 : class FilterNodeConvolveMatrixSoftware : public FilterNodeSoftware
457 : {
458 : public:
459 0 : MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeConvolveMatrixSoftware, override)
460 : FilterNodeConvolveMatrixSoftware();
461 0 : virtual const char* GetName() override { return "ConvolveMatrix"; }
462 : using FilterNodeSoftware::SetAttribute;
463 : virtual void SetAttribute(uint32_t aIndex, const IntSize &aKernelSize) override;
464 : virtual void SetAttribute(uint32_t aIndex, const Float* aMatrix, uint32_t aSize) override;
465 : virtual void SetAttribute(uint32_t aIndex, Float aValue) override;
466 : virtual void SetAttribute(uint32_t aIndex, const Size &aKernelUnitLength) override;
467 : virtual void SetAttribute(uint32_t aIndex, const IntRect &aSourceRect) override;
468 : virtual void SetAttribute(uint32_t aIndex, const IntPoint &aTarget) override;
469 : virtual void SetAttribute(uint32_t aIndex, uint32_t aEdgeMode) override;
470 : virtual void SetAttribute(uint32_t aIndex, bool aPreserveAlpha) override;
471 :
472 : protected:
473 : virtual already_AddRefed<DataSourceSurface> Render(const IntRect& aRect) override;
474 : virtual IntRect GetOutputRectInRect(const IntRect& aRect) override;
475 : virtual int32_t InputIndex(uint32_t aInputEnumIndex) override;
476 : virtual void RequestFromInputsForRect(const IntRect &aRect) override;
477 :
478 : private:
479 : template<typename CoordType>
480 : already_AddRefed<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 0 : class FilterNodeDisplacementMapSoftware : public FilterNodeSoftware
499 : {
500 : public:
501 0 : MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeDisplacementMapSoftware, override)
502 : FilterNodeDisplacementMapSoftware();
503 0 : virtual const char* GetName() override { return "DisplacementMap"; }
504 : using FilterNodeSoftware::SetAttribute;
505 : virtual void SetAttribute(uint32_t aIndex, Float aScale) override;
506 : virtual void SetAttribute(uint32_t aIndex, uint32_t aValue) override;
507 :
508 : protected:
509 : virtual already_AddRefed<DataSourceSurface> Render(const IntRect& aRect) override;
510 : virtual IntRect GetOutputRectInRect(const IntRect& aRect) override;
511 : virtual int32_t InputIndex(uint32_t aInputEnumIndex) override;
512 : virtual void RequestFromInputsForRect(const IntRect &aRect) override;
513 :
514 : private:
515 : IntRect InflatedSourceOrDestRect(const IntRect &aDestOrSourceRect);
516 :
517 : Float mScale;
518 : ColorChannel mChannelX;
519 : ColorChannel mChannelY;
520 : };
521 :
522 0 : class FilterNodeTurbulenceSoftware : public FilterNodeSoftware
523 : {
524 : public:
525 0 : MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeTurbulenceSoftware, override)
526 : FilterNodeTurbulenceSoftware();
527 0 : virtual const char* GetName() override { return "Turbulence"; }
528 : using FilterNodeSoftware::SetAttribute;
529 : virtual void SetAttribute(uint32_t aIndex, const Size &aSize) override;
530 : virtual void SetAttribute(uint32_t aIndex, const IntRect &aRenderRect) override;
531 : virtual void SetAttribute(uint32_t aIndex, bool aStitchable) override;
532 : virtual void SetAttribute(uint32_t aIndex, uint32_t aValue) override;
533 :
534 : protected:
535 : virtual already_AddRefed<DataSourceSurface> Render(const IntRect& aRect) override;
536 : virtual IntRect GetOutputRectInRect(const IntRect& aRect) override;
537 : virtual int32_t InputIndex(uint32_t aInputEnumIndex) 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 0 : class FilterNodeArithmeticCombineSoftware : public FilterNodeSoftware
549 : {
550 : public:
551 0 : MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeArithmeticCombineSoftware, override)
552 : FilterNodeArithmeticCombineSoftware();
553 0 : virtual const char* GetName() override { return "ArithmeticCombine"; }
554 : using FilterNodeSoftware::SetAttribute;
555 : virtual void SetAttribute(uint32_t aIndex, const Float* aFloat, uint32_t aSize) override;
556 :
557 : protected:
558 : virtual already_AddRefed<DataSourceSurface> Render(const IntRect& aRect) override;
559 : virtual IntRect GetOutputRectInRect(const IntRect& aRect) override;
560 : virtual int32_t InputIndex(uint32_t aInputEnumIndex) override;
561 : virtual void RequestFromInputsForRect(const IntRect &aRect) override;
562 :
563 : private:
564 : Float mK1;
565 : Float mK2;
566 : Float mK3;
567 : Float mK4;
568 : };
569 :
570 0 : class FilterNodeCompositeSoftware : public FilterNodeSoftware
571 : {
572 : public:
573 0 : MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeCompositeSoftware, override)
574 : FilterNodeCompositeSoftware();
575 0 : virtual const char* GetName() override { return "Composite"; }
576 : using FilterNodeSoftware::SetAttribute;
577 : virtual void SetAttribute(uint32_t aIndex, uint32_t aOperator) override;
578 :
579 : protected:
580 : virtual already_AddRefed<DataSourceSurface> Render(const IntRect& aRect) override;
581 : virtual IntRect GetOutputRectInRect(const IntRect& aRect) override;
582 : virtual int32_t InputIndex(uint32_t aInputEnumIndex) override;
583 : virtual void RequestFromInputsForRect(const IntRect &aRect) override;
584 :
585 : private:
586 : CompositeOperator mOperator;
587 : };
588 :
589 : // Base class for FilterNodeGaussianBlurSoftware and
590 : // FilterNodeDirectionalBlurSoftware.
591 0 : class FilterNodeBlurXYSoftware : public FilterNodeSoftware
592 : {
593 : public:
594 0 : MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeBlurXYSoftware, override)
595 : protected:
596 : virtual already_AddRefed<DataSourceSurface> Render(const IntRect& aRect) override;
597 : virtual IntRect GetOutputRectInRect(const IntRect& aRect) override;
598 : virtual int32_t InputIndex(uint32_t aInputEnumIndex) override;
599 : IntRect InflatedSourceOrDestRect(const IntRect &aDestRect);
600 : virtual void RequestFromInputsForRect(const IntRect &aRect) override;
601 :
602 : // Implemented by subclasses.
603 : virtual Size StdDeviationXY() = 0;
604 : };
605 :
606 0 : class FilterNodeGaussianBlurSoftware : public FilterNodeBlurXYSoftware
607 : {
608 : public:
609 0 : MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeGaussianBlurSoftware, override)
610 : FilterNodeGaussianBlurSoftware();
611 0 : virtual const char* GetName() override { return "GaussianBlur"; }
612 : using FilterNodeSoftware::SetAttribute;
613 : virtual void SetAttribute(uint32_t aIndex, Float aStdDeviation) override;
614 :
615 : protected:
616 : virtual Size StdDeviationXY() override;
617 :
618 : private:
619 : Float mStdDeviation;
620 : };
621 :
622 0 : class FilterNodeDirectionalBlurSoftware : public FilterNodeBlurXYSoftware
623 : {
624 : public:
625 0 : MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeDirectionalBlurSoftware, override)
626 : FilterNodeDirectionalBlurSoftware();
627 0 : virtual const char* GetName() override { return "DirectionalBlur"; }
628 : using FilterNodeSoftware::SetAttribute;
629 : virtual void SetAttribute(uint32_t aIndex, Float aStdDeviation) override;
630 : virtual void SetAttribute(uint32_t aIndex, uint32_t aBlurDirection) override;
631 :
632 : protected:
633 : virtual Size StdDeviationXY() override;
634 :
635 : private:
636 : Float mStdDeviation;
637 : BlurDirection mBlurDirection;
638 : };
639 :
640 0 : class FilterNodeCropSoftware : public FilterNodeSoftware
641 : {
642 : public:
643 0 : MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeCropSoftware, override)
644 0 : virtual const char* GetName() override { return "Crop"; }
645 : using FilterNodeSoftware::SetAttribute;
646 : virtual void SetAttribute(uint32_t aIndex, const Rect &aSourceRect) override;
647 :
648 : protected:
649 : virtual already_AddRefed<DataSourceSurface> Render(const IntRect& aRect) override;
650 : virtual IntRect GetOutputRectInRect(const IntRect& aRect) override;
651 : virtual int32_t InputIndex(uint32_t aInputEnumIndex) override;
652 : virtual void RequestFromInputsForRect(const IntRect &aRect) override;
653 :
654 : private:
655 : IntRect mCropRect;
656 : };
657 :
658 0 : class FilterNodePremultiplySoftware : public FilterNodeSoftware
659 : {
660 : public:
661 0 : MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodePremultiplySoftware, override)
662 0 : virtual const char* GetName() override { return "Premultiply"; }
663 : protected:
664 : virtual already_AddRefed<DataSourceSurface> Render(const IntRect& aRect) override;
665 : virtual IntRect GetOutputRectInRect(const IntRect& aRect) override;
666 : virtual int32_t InputIndex(uint32_t aInputEnumIndex) override;
667 : virtual void RequestFromInputsForRect(const IntRect &aRect) override;
668 : };
669 :
670 0 : class FilterNodeUnpremultiplySoftware : public FilterNodeSoftware
671 : {
672 : public:
673 0 : MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeUnpremultiplySoftware, override)
674 0 : virtual const char* GetName() override { return "Unpremultiply"; }
675 : protected:
676 : virtual already_AddRefed<DataSourceSurface> Render(const IntRect& aRect) override;
677 : virtual IntRect GetOutputRectInRect(const IntRect& aRect) override;
678 : virtual int32_t InputIndex(uint32_t aInputEnumIndex) override;
679 : virtual void RequestFromInputsForRect(const IntRect &aRect) override;
680 : };
681 :
682 : template<typename LightType, typename LightingType>
683 0 : 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 0 : virtual const char* typeName() const override { return mTypeName; }
689 0 : virtual size_t typeSize() const override { return sizeof(*this); }
690 : #endif
691 : explicit FilterNodeLightingSoftware(const char* aTypeName);
692 0 : virtual const char* GetName() override { return "Lighting"; }
693 : using FilterNodeSoftware::SetAttribute;
694 : virtual void SetAttribute(uint32_t aIndex, Float) override;
695 : virtual void SetAttribute(uint32_t aIndex, const Size &) override;
696 : virtual void SetAttribute(uint32_t aIndex, const Point3D &) override;
697 : virtual void SetAttribute(uint32_t aIndex, const Color &) override;
698 :
699 : protected:
700 : virtual already_AddRefed<DataSourceSurface> Render(const IntRect& aRect) override;
701 : virtual IntRect GetOutputRectInRect(const IntRect& aRect) override;
702 : virtual int32_t InputIndex(uint32_t aInputEnumIndex) override;
703 : virtual void RequestFromInputsForRect(const IntRect &aRect) override;
704 :
705 : private:
706 : template<typename CoordType>
707 : already_AddRefed<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 : } // namespace gfx
722 : } // namespace mozilla
723 :
724 : #endif // _MOZILLA_GFX_FILTERNODESOFTWARE_H_
|