1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef _MOZILLA_GFX_FILTERNODESOFTWARE_H_
8 #define _MOZILLA_GFX_FILTERNODESOFTWARE_H_
11 #include "mozilla/Mutex.h"
17 class DataSourceSurface
;
20 class FilterNodeSoftware
;
23 * Can be attached to FilterNodeSoftware instances using
24 * AddInvalidationListener. FilterInvalidated is called whenever the output of
25 * the observed filter may have changed; that is, whenever cached GetOutput()
26 * results (and results derived from them) need to discarded.
28 class FilterInvalidationListener
{
30 virtual void FilterInvalidated(FilterNodeSoftware
* aFilter
) = 0;
34 * This is the base class for the software (i.e. pure CPU, non-accelerated)
35 * FilterNode implementation. The software implementation is backend-agnostic,
36 * so it can be used as a fallback for all DrawTarget implementations.
38 class FilterNodeSoftware
: public FilterNode
,
39 public FilterInvalidationListener
{
41 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeSoftware
, override
)
43 virtual ~FilterNodeSoftware();
45 // Factory method, intended to be called from DrawTarget*::CreateFilter.
46 static already_AddRefed
<FilterNode
> Create(FilterType aType
);
48 // Draw the filter, intended to be called by DrawTarget*::DrawFilter.
49 void Draw(DrawTarget
* aDrawTarget
, const Rect
& aSourceRect
,
50 const Point
& aDestPoint
, const DrawOptions
& aOptions
);
52 FilterBackend
GetBackendType() override
{ return FILTER_BACKEND_SOFTWARE
; }
53 void SetInput(uint32_t aIndex
, SourceSurface
* aSurface
) override
;
54 void SetInput(uint32_t aIndex
, FilterNode
* aFilter
) override
;
56 virtual const char* GetName() { return "Unknown"; }
58 void AddInvalidationListener(FilterInvalidationListener
* aListener
);
59 void RemoveInvalidationListener(FilterInvalidationListener
* aListener
);
61 // FilterInvalidationListener implementation
62 void FilterInvalidated(FilterNodeSoftware
* aFilter
) override
;
65 // The following methods are intended to be overriden by subclasses.
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.
73 virtual int32_t InputIndex(uint32_t aInputEnumIndex
) { return -1; }
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.
82 virtual IntRect
GetOutputRectInRect(const IntRect
& aInRect
) = 0;
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.
93 virtual already_AddRefed
<DataSourceSurface
> Render(const IntRect
& aRect
) = 0;
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
100 virtual void RequestFromInputsForRect(const IntRect
& aRect
) {}
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.
107 virtual already_AddRefed
<DataSourceSurface
> GetOutput(const IntRect
& aRect
);
109 // The following methods are non-virtual helper methods.
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.
117 enum FormatHint
{ CAN_HANDLE_A8
, NEED_COLOR_CHANNELS
};
120 * Returns SurfaceFormat::B8G8R8A8 or SurfaceFormat::A8, depending on the
121 * current surface format and the format hint.
123 SurfaceFormat
DesiredFormat(SurfaceFormat aCurrentFormat
,
124 FormatHint aFormatHint
);
127 * Intended to be called by FilterNodeSoftware::Render implementations.
128 * Returns a surface of size aRect.Size() or nullptr in error conditions. The
129 * returned surface contains the output of the specified input filter or
130 * input surface in aRect. If aRect extends beyond the input filter's output
131 * rect (or the input surface's dimensions), the remaining area is filled
132 * according to aEdgeMode: The default, EDGE_MODE_NONE, simply pads with
134 * If non-null, the returned surface is guaranteed to be of SurfaceFormat::A8
135 * or SurfaceFormat::B8G8R8A8. If aFormatHint is NEED_COLOR_CHANNELS, the
136 * returned surface is guaranteed to be of SurfaceFormat::B8G8R8A8 always.
137 * Each pixel row of the returned surface is guaranteed to be 16-byte aligned.
139 already_AddRefed
<DataSourceSurface
> GetInputDataSourceSurface(
140 uint32_t aInputEnumIndex
, const IntRect
& aRect
,
141 FormatHint aFormatHint
= CAN_HANDLE_A8
,
142 ConvolveMatrixEdgeMode aEdgeMode
= EDGE_MODE_NONE
,
143 const IntRect
* aTransparencyPaddedSourceRect
= nullptr);
146 * Returns the intersection of the input filter's or surface's output rect
149 IntRect
GetInputRectInRect(uint32_t aInputEnumIndex
, const IntRect
& aInRect
);
152 * Calls RequestRect on the specified input, if it's a filter.
154 void RequestInputRect(uint32_t aInputEnumIndex
, const IntRect
& aRect
);
157 * Calls MapRectToSource on the specified input, if it's a filter.
159 IntRect
MapInputRectToSource(uint32_t aInputEnumIndex
, const IntRect
& aRect
,
160 const IntRect
& aMax
, FilterNode
* aSourceNode
);
163 * Returns the number of set input filters or surfaces. Needed for filters
164 * which can have an arbitrary number of inputs.
166 size_t NumberOfSetInputs();
169 * Discard the cached surface that was stored in the GetOutput default
170 * implementation. Needs to be called whenever attributes or inputs are set
171 * that might change the result of a Render() call.
176 * Called in order to let this filter know what to cache during the next
177 * GetOutput call. Expected to call RequestRect on this filter's input
180 void RequestRect(const IntRect
& aRect
);
183 * Set input filter and clear input surface for this input index, or set
184 * input surface and clear input filter. One of aSurface and aFilter should
187 void SetInput(uint32_t aIndex
, SourceSurface
* aSurface
,
188 FilterNodeSoftware
* aFilter
);
192 * mInputSurfaces / mInputFilters: For each input index, either a surface or
193 * a filter is set, and the other is null.
195 std::vector
<RefPtr
<SourceSurface
> > mInputSurfaces
;
196 std::vector
<RefPtr
<FilterNodeSoftware
> > mInputFilters
;
199 * Weak pointers to our invalidation listeners, i.e. to those filters who
200 * have this filter as an input. Invalidation listeners are required to
201 * unsubscribe themselves from us when they let go of their reference to us.
202 * This ensures that the pointers in this array are never stale.
204 std::vector
<FilterInvalidationListener
*> mInvalidationListeners
;
207 * Stores the rect which we want to render and cache on the next call to
210 IntRect mRequestedRect
;
213 * Stores our cached output.
216 RefPtr
<DataSourceSurface
> mCachedOutput
;
219 // Subclasses for specific filters.
221 class FilterNodeTransformSoftware
: public FilterNodeSoftware
{
223 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeTransformSoftware
, override
)
224 FilterNodeTransformSoftware();
225 const char* GetName() override
{ return "Transform"; }
226 using FilterNodeSoftware::SetAttribute
;
227 void SetAttribute(uint32_t aIndex
, uint32_t aGraphicsFilter
) override
;
228 void SetAttribute(uint32_t aIndex
, const Matrix
& aMatrix
) override
;
229 IntRect
MapRectToSource(const IntRect
& aRect
, const IntRect
& aMax
,
230 FilterNode
* aSourceNode
) override
;
233 already_AddRefed
<DataSourceSurface
> Render(const IntRect
& aRect
) override
;
234 IntRect
GetOutputRectInRect(const IntRect
& aRect
) override
;
235 int32_t InputIndex(uint32_t aInputEnumIndex
) override
;
236 void RequestFromInputsForRect(const IntRect
& aRect
) override
;
237 IntRect
SourceRectForOutputRect(const IntRect
& aRect
);
241 SamplingFilter mSamplingFilter
;
244 class FilterNodeBlendSoftware
: public FilterNodeSoftware
{
246 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeBlendSoftware
, override
)
247 FilterNodeBlendSoftware();
248 const char* GetName() override
{ return "Blend"; }
249 using FilterNodeSoftware::SetAttribute
;
250 void SetAttribute(uint32_t aIndex
, uint32_t aBlendMode
) override
;
251 IntRect
MapRectToSource(const IntRect
& aRect
, const IntRect
& aMax
,
252 FilterNode
* aSourceNode
) override
;
255 already_AddRefed
<DataSourceSurface
> Render(const IntRect
& aRect
) override
;
256 IntRect
GetOutputRectInRect(const IntRect
& aRect
) override
;
257 int32_t InputIndex(uint32_t aInputEnumIndex
) override
;
258 void RequestFromInputsForRect(const IntRect
& aRect
) override
;
261 BlendMode mBlendMode
;
264 class FilterNodeMorphologySoftware
: public FilterNodeSoftware
{
266 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeMorphologySoftware
,
268 FilterNodeMorphologySoftware();
269 const char* GetName() override
{ return "Morphology"; }
270 using FilterNodeSoftware::SetAttribute
;
271 void SetAttribute(uint32_t aIndex
, const IntSize
& aRadii
) override
;
272 void SetAttribute(uint32_t aIndex
, uint32_t aOperator
) override
;
275 already_AddRefed
<DataSourceSurface
> Render(const IntRect
& aRect
) override
;
276 IntRect
GetOutputRectInRect(const IntRect
& aRect
) override
;
277 int32_t InputIndex(uint32_t aInputEnumIndex
) override
;
278 void RequestFromInputsForRect(const IntRect
& aRect
) override
;
282 MorphologyOperator mOperator
;
285 class FilterNodeColorMatrixSoftware
: public FilterNodeSoftware
{
287 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeColorMatrixSoftware
,
289 const char* GetName() override
{ return "ColorMatrix"; }
290 using FilterNodeSoftware::SetAttribute
;
291 void SetAttribute(uint32_t aIndex
, const Matrix5x4
& aMatrix
) override
;
292 void SetAttribute(uint32_t aIndex
, uint32_t aAlphaMode
) override
;
295 already_AddRefed
<DataSourceSurface
> Render(const IntRect
& aRect
) override
;
296 IntRect
GetOutputRectInRect(const IntRect
& aRect
) override
;
297 int32_t InputIndex(uint32_t aInputEnumIndex
) override
;
298 void RequestFromInputsForRect(const IntRect
& aRect
) override
;
299 IntRect
MapRectToSource(const IntRect
& aRect
, const IntRect
& aMax
,
300 FilterNode
* aSourceNode
) override
;
304 AlphaMode mAlphaMode
;
307 class FilterNodeFloodSoftware
: public FilterNodeSoftware
{
309 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeFloodSoftware
, override
)
310 const char* GetName() override
{ return "Flood"; }
311 using FilterNodeSoftware::SetAttribute
;
312 void SetAttribute(uint32_t aIndex
, const DeviceColor
& aColor
) override
;
313 IntRect
MapRectToSource(const IntRect
& aRect
, const IntRect
& aMax
,
314 FilterNode
* aSourceNode
) override
;
317 already_AddRefed
<DataSourceSurface
> GetOutput(const IntRect
& aRect
) override
;
318 already_AddRefed
<DataSourceSurface
> Render(const IntRect
& aRect
) override
;
319 IntRect
GetOutputRectInRect(const IntRect
& aRect
) override
;
325 class FilterNodeTileSoftware
: public FilterNodeSoftware
{
327 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeTileSoftware
, override
)
328 const char* GetName() override
{ return "Tile"; }
329 using FilterNodeSoftware::SetAttribute
;
330 void SetAttribute(uint32_t aIndex
, const IntRect
& aSourceRect
) override
;
333 already_AddRefed
<DataSourceSurface
> Render(const IntRect
& aRect
) override
;
334 IntRect
GetOutputRectInRect(const IntRect
& aRect
) override
;
335 int32_t InputIndex(uint32_t aInputEnumIndex
) override
;
336 void RequestFromInputsForRect(const IntRect
& aRect
) override
;
343 * Baseclass for the four different component transfer filters.
345 class FilterNodeComponentTransferSoftware
: public FilterNodeSoftware
{
347 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeComponentTransferSoftware
,
349 FilterNodeComponentTransferSoftware();
351 using FilterNodeSoftware::SetAttribute
;
352 void SetAttribute(uint32_t aIndex
, bool aDisable
) override
;
353 IntRect
MapRectToSource(const IntRect
& aRect
, const IntRect
& aMax
,
354 FilterNode
* aSourceNode
) override
;
357 already_AddRefed
<DataSourceSurface
> Render(const IntRect
& aRect
) override
;
358 IntRect
GetOutputRectInRect(const IntRect
& aRect
) override
;
359 int32_t InputIndex(uint32_t aInputEnumIndex
) override
;
360 void RequestFromInputsForRect(const IntRect
& aRect
) override
;
361 virtual void GenerateLookupTable(ptrdiff_t aComponent
,
362 uint8_t aTables
[4][256], bool aDisabled
);
363 virtual void FillLookupTable(ptrdiff_t aComponent
, uint8_t aTable
[256]) = 0;
371 class FilterNodeTableTransferSoftware
372 : public FilterNodeComponentTransferSoftware
{
374 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeTableTransferSoftware
,
376 const char* GetName() override
{ return "TableTransfer"; }
377 using FilterNodeComponentTransferSoftware::SetAttribute
;
378 void SetAttribute(uint32_t aIndex
, const Float
* aFloat
,
379 uint32_t aSize
) override
;
382 void FillLookupTable(ptrdiff_t aComponent
, uint8_t aTable
[256]) override
;
385 void FillLookupTableImpl(std::vector
<Float
>& aTableValues
,
386 uint8_t aTable
[256]);
388 std::vector
<Float
> mTableR
;
389 std::vector
<Float
> mTableG
;
390 std::vector
<Float
> mTableB
;
391 std::vector
<Float
> mTableA
;
394 class FilterNodeDiscreteTransferSoftware
395 : public FilterNodeComponentTransferSoftware
{
397 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeDiscreteTransferSoftware
,
399 const char* GetName() override
{ return "DiscreteTransfer"; }
400 using FilterNodeComponentTransferSoftware::SetAttribute
;
401 void SetAttribute(uint32_t aIndex
, const Float
* aFloat
,
402 uint32_t aSize
) override
;
405 void FillLookupTable(ptrdiff_t aComponent
, uint8_t aTable
[256]) override
;
408 void FillLookupTableImpl(std::vector
<Float
>& aTableValues
,
409 uint8_t aTable
[256]);
411 std::vector
<Float
> mTableR
;
412 std::vector
<Float
> mTableG
;
413 std::vector
<Float
> mTableB
;
414 std::vector
<Float
> mTableA
;
417 class FilterNodeLinearTransferSoftware
418 : public FilterNodeComponentTransferSoftware
{
420 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeLinearTransformSoftware
,
422 FilterNodeLinearTransferSoftware();
423 const char* GetName() override
{ return "LinearTransfer"; }
424 using FilterNodeComponentTransferSoftware::SetAttribute
;
425 void SetAttribute(uint32_t aIndex
, Float aValue
) override
;
428 void FillLookupTable(ptrdiff_t aComponent
, uint8_t aTable
[256]) override
;
431 void FillLookupTableImpl(Float aSlope
, Float aIntercept
, uint8_t aTable
[256]);
443 class FilterNodeGammaTransferSoftware
444 : public FilterNodeComponentTransferSoftware
{
446 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeGammaTransferSoftware
,
448 FilterNodeGammaTransferSoftware();
449 const char* GetName() override
{ return "GammaTransfer"; }
450 using FilterNodeComponentTransferSoftware::SetAttribute
;
451 void SetAttribute(uint32_t aIndex
, Float aValue
) override
;
454 void FillLookupTable(ptrdiff_t aComponent
, uint8_t aTable
[256]) override
;
457 void FillLookupTableImpl(Float aAmplitude
, Float aExponent
, Float aOffset
,
458 uint8_t aTable
[256]);
474 class FilterNodeConvolveMatrixSoftware
: public FilterNodeSoftware
{
476 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeConvolveMatrixSoftware
,
478 FilterNodeConvolveMatrixSoftware();
479 const char* GetName() override
{ return "ConvolveMatrix"; }
480 using FilterNodeSoftware::SetAttribute
;
481 void SetAttribute(uint32_t aIndex
, const IntSize
& aKernelSize
) override
;
482 void SetAttribute(uint32_t aIndex
, const Float
* aMatrix
,
483 uint32_t aSize
) override
;
484 void SetAttribute(uint32_t aIndex
, Float aValue
) override
;
485 void SetAttribute(uint32_t aIndex
, const Size
& aKernelUnitLength
) override
;
486 void SetAttribute(uint32_t aIndex
, const IntRect
& aSourceRect
) override
;
487 void SetAttribute(uint32_t aIndex
, const IntPoint
& aTarget
) override
;
488 void SetAttribute(uint32_t aIndex
, uint32_t aEdgeMode
) override
;
489 void SetAttribute(uint32_t aIndex
, bool aPreserveAlpha
) override
;
490 IntRect
MapRectToSource(const IntRect
& aRect
, const IntRect
& aMax
,
491 FilterNode
* aSourceNode
) override
;
494 already_AddRefed
<DataSourceSurface
> Render(const IntRect
& aRect
) override
;
495 IntRect
GetOutputRectInRect(const IntRect
& aRect
) override
;
496 int32_t InputIndex(uint32_t aInputEnumIndex
) override
;
497 void RequestFromInputsForRect(const IntRect
& aRect
) override
;
500 template <typename CoordType
>
501 already_AddRefed
<DataSourceSurface
> DoRender(const IntRect
& aRect
,
502 CoordType aKernelUnitLengthX
,
503 CoordType aKernelUnitLengthY
);
505 IntRect
InflatedSourceRect(const IntRect
& aDestRect
);
506 IntRect
InflatedDestRect(const IntRect
& aSourceRect
);
509 std::vector
<Float
> mKernelMatrix
;
514 ConvolveMatrixEdgeMode mEdgeMode
;
515 Size mKernelUnitLength
;
519 class FilterNodeDisplacementMapSoftware
: public FilterNodeSoftware
{
521 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeDisplacementMapSoftware
,
523 FilterNodeDisplacementMapSoftware();
524 const char* GetName() override
{ return "DisplacementMap"; }
525 using FilterNodeSoftware::SetAttribute
;
526 void SetAttribute(uint32_t aIndex
, Float aScale
) override
;
527 void SetAttribute(uint32_t aIndex
, uint32_t aValue
) override
;
528 IntRect
MapRectToSource(const IntRect
& aRect
, const IntRect
& aMax
,
529 FilterNode
* aSourceNode
) override
;
532 already_AddRefed
<DataSourceSurface
> Render(const IntRect
& aRect
) override
;
533 IntRect
GetOutputRectInRect(const IntRect
& aRect
) override
;
534 int32_t InputIndex(uint32_t aInputEnumIndex
) override
;
535 void RequestFromInputsForRect(const IntRect
& aRect
) override
;
538 IntRect
InflatedSourceOrDestRect(const IntRect
& aDestOrSourceRect
);
541 ColorChannel mChannelX
;
542 ColorChannel mChannelY
;
545 class FilterNodeTurbulenceSoftware
: public FilterNodeSoftware
{
547 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeTurbulenceSoftware
,
549 FilterNodeTurbulenceSoftware();
550 const char* GetName() override
{ return "Turbulence"; }
551 using FilterNodeSoftware::SetAttribute
;
552 void SetAttribute(uint32_t aIndex
, const Size
& aSize
) override
;
553 void SetAttribute(uint32_t aIndex
, const IntRect
& aRenderRect
) override
;
554 void SetAttribute(uint32_t aIndex
, bool aStitchable
) override
;
555 void SetAttribute(uint32_t aIndex
, uint32_t aValue
) override
;
556 IntRect
MapRectToSource(const IntRect
& aRect
, const IntRect
& aMax
,
557 FilterNode
* aSourceNode
) override
;
560 already_AddRefed
<DataSourceSurface
> Render(const IntRect
& aRect
) override
;
561 IntRect
GetOutputRectInRect(const IntRect
& aRect
) override
;
562 int32_t InputIndex(uint32_t aInputEnumIndex
) override
;
567 uint32_t mNumOctaves
;
570 TurbulenceType mType
;
573 class FilterNodeArithmeticCombineSoftware
: public FilterNodeSoftware
{
575 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeArithmeticCombineSoftware
,
577 FilterNodeArithmeticCombineSoftware();
578 const char* GetName() override
{ return "ArithmeticCombine"; }
579 using FilterNodeSoftware::SetAttribute
;
580 void SetAttribute(uint32_t aIndex
, const Float
* aFloat
,
581 uint32_t aSize
) override
;
582 IntRect
MapRectToSource(const IntRect
& aRect
, const IntRect
& aMax
,
583 FilterNode
* aSourceNode
) override
;
586 already_AddRefed
<DataSourceSurface
> Render(const IntRect
& aRect
) override
;
587 IntRect
GetOutputRectInRect(const IntRect
& aRect
) override
;
588 int32_t InputIndex(uint32_t aInputEnumIndex
) override
;
589 void RequestFromInputsForRect(const IntRect
& aRect
) override
;
598 class FilterNodeCompositeSoftware
: public FilterNodeSoftware
{
600 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeCompositeSoftware
, override
)
601 FilterNodeCompositeSoftware();
602 const char* GetName() override
{ return "Composite"; }
603 using FilterNodeSoftware::SetAttribute
;
604 void SetAttribute(uint32_t aIndex
, uint32_t aOperator
) override
;
607 already_AddRefed
<DataSourceSurface
> Render(const IntRect
& aRect
) override
;
608 IntRect
GetOutputRectInRect(const IntRect
& aRect
) override
;
609 int32_t InputIndex(uint32_t aInputEnumIndex
) override
;
610 void RequestFromInputsForRect(const IntRect
& aRect
) override
;
611 IntRect
MapRectToSource(const IntRect
& aRect
, const IntRect
& aMax
,
612 FilterNode
* aSourceNode
) override
;
615 CompositeOperator mOperator
;
618 // Base class for FilterNodeGaussianBlurSoftware and
619 // FilterNodeDirectionalBlurSoftware.
620 class FilterNodeBlurXYSoftware
: public FilterNodeSoftware
{
622 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeBlurXYSoftware
, override
)
624 already_AddRefed
<DataSourceSurface
> Render(const IntRect
& aRect
) override
;
625 IntRect
GetOutputRectInRect(const IntRect
& aRect
) override
;
626 int32_t InputIndex(uint32_t aInputEnumIndex
) override
;
627 IntRect
InflatedSourceOrDestRect(const IntRect
& aDestRect
);
628 void RequestFromInputsForRect(const IntRect
& aRect
) override
;
629 IntRect
MapRectToSource(const IntRect
& aRect
, const IntRect
& aMax
,
630 FilterNode
* aSourceNode
) override
;
632 // Implemented by subclasses.
633 virtual Size
StdDeviationXY() = 0;
636 class FilterNodeGaussianBlurSoftware
: public FilterNodeBlurXYSoftware
{
638 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeGaussianBlurSoftware
,
640 FilterNodeGaussianBlurSoftware();
641 const char* GetName() override
{ return "GaussianBlur"; }
642 using FilterNodeSoftware::SetAttribute
;
643 void SetAttribute(uint32_t aIndex
, Float aStdDeviation
) override
;
646 Size
StdDeviationXY() override
;
652 class FilterNodeDirectionalBlurSoftware
: public FilterNodeBlurXYSoftware
{
654 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeDirectionalBlurSoftware
,
656 FilterNodeDirectionalBlurSoftware();
657 const char* GetName() override
{ return "DirectionalBlur"; }
658 using FilterNodeSoftware::SetAttribute
;
659 void SetAttribute(uint32_t aIndex
, Float aStdDeviation
) override
;
660 void SetAttribute(uint32_t aIndex
, uint32_t aBlurDirection
) override
;
663 Size
StdDeviationXY() override
;
667 BlurDirection mBlurDirection
;
670 class FilterNodeCropSoftware
: public FilterNodeSoftware
{
672 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeCropSoftware
, override
)
673 const char* GetName() override
{ return "Crop"; }
674 using FilterNodeSoftware::SetAttribute
;
675 void SetAttribute(uint32_t aIndex
, const Rect
& aSourceRect
) override
;
678 already_AddRefed
<DataSourceSurface
> Render(const IntRect
& aRect
) override
;
679 IntRect
GetOutputRectInRect(const IntRect
& aRect
) override
;
680 int32_t InputIndex(uint32_t aInputEnumIndex
) override
;
681 void RequestFromInputsForRect(const IntRect
& aRect
) override
;
682 IntRect
MapRectToSource(const IntRect
& aRect
, const IntRect
& aMax
,
683 FilterNode
* aSourceNode
) override
;
689 class FilterNodePremultiplySoftware
: public FilterNodeSoftware
{
691 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodePremultiplySoftware
,
693 const char* GetName() override
{ return "Premultiply"; }
696 already_AddRefed
<DataSourceSurface
> Render(const IntRect
& aRect
) override
;
697 IntRect
GetOutputRectInRect(const IntRect
& aRect
) override
;
698 int32_t InputIndex(uint32_t aInputEnumIndex
) override
;
699 void RequestFromInputsForRect(const IntRect
& aRect
) override
;
700 IntRect
MapRectToSource(const IntRect
& aRect
, const IntRect
& aMax
,
701 FilterNode
* aSourceNode
) override
;
704 class FilterNodeUnpremultiplySoftware
: public FilterNodeSoftware
{
706 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeUnpremultiplySoftware
,
708 const char* GetName() override
{ return "Unpremultiply"; }
711 already_AddRefed
<DataSourceSurface
> Render(const IntRect
& aRect
) override
;
712 IntRect
GetOutputRectInRect(const IntRect
& aRect
) override
;
713 int32_t InputIndex(uint32_t aInputEnumIndex
) override
;
714 void RequestFromInputsForRect(const IntRect
& aRect
) override
;
715 IntRect
MapRectToSource(const IntRect
& aRect
, const IntRect
& aMax
,
716 FilterNode
* aSourceNode
) override
;
719 class FilterNodeOpacitySoftware
: public FilterNodeSoftware
{
721 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeOpacitySoftware
, override
)
722 const char* GetName() override
{ return "Opacity"; }
723 using FilterNodeSoftware::SetAttribute
;
724 void SetAttribute(uint32_t aIndex
, Float aValue
) override
;
725 IntRect
MapRectToSource(const IntRect
& aRect
, const IntRect
& aMax
,
726 FilterNode
* aSourceNode
) override
;
729 already_AddRefed
<DataSourceSurface
> Render(const IntRect
& aRect
) override
;
730 IntRect
GetOutputRectInRect(const IntRect
& aRect
) override
;
731 int32_t InputIndex(uint32_t aInputEnumIndex
) override
;
732 void RequestFromInputsForRect(const IntRect
& aRect
) override
;
737 template <typename LightType
, typename LightingType
>
738 class FilterNodeLightingSoftware
: public FilterNodeSoftware
{
740 #if defined(MOZILLA_INTERNAL_API) && defined(NS_BUILD_REFCNT_LOGGING)
741 // Helpers for refcounted
742 const char* typeName() const override
{ return mTypeName
; }
743 size_t typeSize() const override
{ return sizeof(*this); }
745 explicit FilterNodeLightingSoftware(const char* aTypeName
);
746 const char* GetName() override
{ return "Lighting"; }
747 using FilterNodeSoftware::SetAttribute
;
748 void SetAttribute(uint32_t aIndex
, Float
) override
;
749 void SetAttribute(uint32_t aIndex
, const Size
&) override
;
750 void SetAttribute(uint32_t aIndex
, const Point3D
&) override
;
751 void SetAttribute(uint32_t aIndex
, const DeviceColor
&) override
;
752 IntRect
MapRectToSource(const IntRect
& aRect
, const IntRect
& aMax
,
753 FilterNode
* aSourceNode
) override
;
756 already_AddRefed
<DataSourceSurface
> Render(const IntRect
& aRect
) override
;
757 IntRect
GetOutputRectInRect(const IntRect
& aRect
) override
;
758 int32_t InputIndex(uint32_t aInputEnumIndex
) override
;
759 void RequestFromInputsForRect(const IntRect
& aRect
) override
;
762 template <typename CoordType
>
763 already_AddRefed
<DataSourceSurface
> DoRender(const IntRect
& aRect
,
764 CoordType aKernelUnitLengthX
,
765 CoordType aKernelUnitLengthY
);
768 LightingType mLighting
;
770 Size mKernelUnitLength
;
772 #if defined(MOZILLA_INTERNAL_API) && defined(NS_BUILD_REFCNT_LOGGING)
773 const char* mTypeName
;
778 } // namespace mozilla
780 #endif // _MOZILLA_GFX_FILTERNODESOFTWARE_H_