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 * Lock guarding mRequestedRect, mCachedRect, and mCachedOutput. All uses
208 * of those members must aquire this lock.
213 * Stores the rect which we want to render and cache on the next call to
216 IntRect mRequestedRect
;
219 * Stores our cached output.
222 RefPtr
<DataSourceSurface
> mCachedOutput
;
225 // Subclasses for specific filters.
227 class FilterNodeTransformSoftware
: public FilterNodeSoftware
{
229 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeTransformSoftware
, override
)
230 FilterNodeTransformSoftware();
231 const char* GetName() override
{ return "Transform"; }
232 using FilterNodeSoftware::SetAttribute
;
233 void SetAttribute(uint32_t aIndex
, uint32_t aGraphicsFilter
) override
;
234 void SetAttribute(uint32_t aIndex
, const Matrix
& aMatrix
) override
;
235 IntRect
MapRectToSource(const IntRect
& aRect
, const IntRect
& aMax
,
236 FilterNode
* aSourceNode
) override
;
239 already_AddRefed
<DataSourceSurface
> Render(const IntRect
& aRect
) override
;
240 IntRect
GetOutputRectInRect(const IntRect
& aRect
) override
;
241 int32_t InputIndex(uint32_t aInputEnumIndex
) override
;
242 void RequestFromInputsForRect(const IntRect
& aRect
) override
;
243 IntRect
SourceRectForOutputRect(const IntRect
& aRect
);
247 SamplingFilter mSamplingFilter
;
250 class FilterNodeBlendSoftware
: public FilterNodeSoftware
{
252 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeBlendSoftware
, override
)
253 FilterNodeBlendSoftware();
254 const char* GetName() override
{ return "Blend"; }
255 using FilterNodeSoftware::SetAttribute
;
256 void SetAttribute(uint32_t aIndex
, uint32_t aBlendMode
) override
;
257 IntRect
MapRectToSource(const IntRect
& aRect
, const IntRect
& aMax
,
258 FilterNode
* aSourceNode
) override
;
261 already_AddRefed
<DataSourceSurface
> Render(const IntRect
& aRect
) override
;
262 IntRect
GetOutputRectInRect(const IntRect
& aRect
) override
;
263 int32_t InputIndex(uint32_t aInputEnumIndex
) override
;
264 void RequestFromInputsForRect(const IntRect
& aRect
) override
;
267 BlendMode mBlendMode
;
270 class FilterNodeMorphologySoftware
: public FilterNodeSoftware
{
272 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeMorphologySoftware
,
274 FilterNodeMorphologySoftware();
275 const char* GetName() override
{ return "Morphology"; }
276 using FilterNodeSoftware::SetAttribute
;
277 void SetAttribute(uint32_t aIndex
, const IntSize
& aRadii
) override
;
278 void SetAttribute(uint32_t aIndex
, uint32_t aOperator
) override
;
281 already_AddRefed
<DataSourceSurface
> Render(const IntRect
& aRect
) override
;
282 IntRect
GetOutputRectInRect(const IntRect
& aRect
) override
;
283 int32_t InputIndex(uint32_t aInputEnumIndex
) override
;
284 void RequestFromInputsForRect(const IntRect
& aRect
) override
;
288 MorphologyOperator mOperator
;
291 class FilterNodeColorMatrixSoftware
: public FilterNodeSoftware
{
293 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeColorMatrixSoftware
,
295 const char* GetName() override
{ return "ColorMatrix"; }
296 using FilterNodeSoftware::SetAttribute
;
297 void SetAttribute(uint32_t aIndex
, const Matrix5x4
& aMatrix
) override
;
298 void SetAttribute(uint32_t aIndex
, uint32_t aAlphaMode
) override
;
301 already_AddRefed
<DataSourceSurface
> Render(const IntRect
& aRect
) override
;
302 IntRect
GetOutputRectInRect(const IntRect
& aRect
) override
;
303 int32_t InputIndex(uint32_t aInputEnumIndex
) override
;
304 void RequestFromInputsForRect(const IntRect
& aRect
) override
;
305 IntRect
MapRectToSource(const IntRect
& aRect
, const IntRect
& aMax
,
306 FilterNode
* aSourceNode
) override
;
310 AlphaMode mAlphaMode
;
313 class FilterNodeFloodSoftware
: public FilterNodeSoftware
{
315 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeFloodSoftware
, override
)
316 const char* GetName() override
{ return "Flood"; }
317 using FilterNodeSoftware::SetAttribute
;
318 void SetAttribute(uint32_t aIndex
, const DeviceColor
& aColor
) override
;
319 IntRect
MapRectToSource(const IntRect
& aRect
, const IntRect
& aMax
,
320 FilterNode
* aSourceNode
) override
;
323 already_AddRefed
<DataSourceSurface
> GetOutput(const IntRect
& aRect
) override
;
324 already_AddRefed
<DataSourceSurface
> Render(const IntRect
& aRect
) override
;
325 IntRect
GetOutputRectInRect(const IntRect
& aRect
) override
;
331 class FilterNodeTileSoftware
: public FilterNodeSoftware
{
333 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeTileSoftware
, override
)
334 const char* GetName() override
{ return "Tile"; }
335 using FilterNodeSoftware::SetAttribute
;
336 void SetAttribute(uint32_t aIndex
, const IntRect
& aSourceRect
) override
;
339 already_AddRefed
<DataSourceSurface
> Render(const IntRect
& aRect
) override
;
340 IntRect
GetOutputRectInRect(const IntRect
& aRect
) override
;
341 int32_t InputIndex(uint32_t aInputEnumIndex
) override
;
342 void RequestFromInputsForRect(const IntRect
& aRect
) override
;
349 * Baseclass for the four different component transfer filters.
351 class FilterNodeComponentTransferSoftware
: public FilterNodeSoftware
{
353 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeComponentTransferSoftware
,
355 FilterNodeComponentTransferSoftware();
357 using FilterNodeSoftware::SetAttribute
;
358 void SetAttribute(uint32_t aIndex
, bool aDisable
) override
;
359 IntRect
MapRectToSource(const IntRect
& aRect
, const IntRect
& aMax
,
360 FilterNode
* aSourceNode
) override
;
363 already_AddRefed
<DataSourceSurface
> Render(const IntRect
& aRect
) override
;
364 IntRect
GetOutputRectInRect(const IntRect
& aRect
) override
;
365 int32_t InputIndex(uint32_t aInputEnumIndex
) override
;
366 void RequestFromInputsForRect(const IntRect
& aRect
) override
;
367 virtual void GenerateLookupTable(ptrdiff_t aComponent
,
368 uint8_t aTables
[4][256], bool aDisabled
);
369 virtual void FillLookupTable(ptrdiff_t aComponent
, uint8_t aTable
[256]) = 0;
377 class FilterNodeTableTransferSoftware
378 : public FilterNodeComponentTransferSoftware
{
380 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeTableTransferSoftware
,
382 const char* GetName() override
{ return "TableTransfer"; }
383 using FilterNodeComponentTransferSoftware::SetAttribute
;
384 void SetAttribute(uint32_t aIndex
, const Float
* aFloat
,
385 uint32_t aSize
) override
;
388 void FillLookupTable(ptrdiff_t aComponent
, uint8_t aTable
[256]) override
;
391 void FillLookupTableImpl(std::vector
<Float
>& aTableValues
,
392 uint8_t aTable
[256]);
394 std::vector
<Float
> mTableR
;
395 std::vector
<Float
> mTableG
;
396 std::vector
<Float
> mTableB
;
397 std::vector
<Float
> mTableA
;
400 class FilterNodeDiscreteTransferSoftware
401 : public FilterNodeComponentTransferSoftware
{
403 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeDiscreteTransferSoftware
,
405 const char* GetName() override
{ return "DiscreteTransfer"; }
406 using FilterNodeComponentTransferSoftware::SetAttribute
;
407 void SetAttribute(uint32_t aIndex
, const Float
* aFloat
,
408 uint32_t aSize
) override
;
411 void FillLookupTable(ptrdiff_t aComponent
, uint8_t aTable
[256]) override
;
414 void FillLookupTableImpl(std::vector
<Float
>& aTableValues
,
415 uint8_t aTable
[256]);
417 std::vector
<Float
> mTableR
;
418 std::vector
<Float
> mTableG
;
419 std::vector
<Float
> mTableB
;
420 std::vector
<Float
> mTableA
;
423 class FilterNodeLinearTransferSoftware
424 : public FilterNodeComponentTransferSoftware
{
426 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeLinearTransformSoftware
,
428 FilterNodeLinearTransferSoftware();
429 const char* GetName() override
{ return "LinearTransfer"; }
430 using FilterNodeComponentTransferSoftware::SetAttribute
;
431 void SetAttribute(uint32_t aIndex
, Float aValue
) override
;
434 void FillLookupTable(ptrdiff_t aComponent
, uint8_t aTable
[256]) override
;
437 void FillLookupTableImpl(Float aSlope
, Float aIntercept
, uint8_t aTable
[256]);
449 class FilterNodeGammaTransferSoftware
450 : public FilterNodeComponentTransferSoftware
{
452 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeGammaTransferSoftware
,
454 FilterNodeGammaTransferSoftware();
455 const char* GetName() override
{ return "GammaTransfer"; }
456 using FilterNodeComponentTransferSoftware::SetAttribute
;
457 void SetAttribute(uint32_t aIndex
, Float aValue
) override
;
460 void FillLookupTable(ptrdiff_t aComponent
, uint8_t aTable
[256]) override
;
463 void FillLookupTableImpl(Float aAmplitude
, Float aExponent
, Float aOffset
,
464 uint8_t aTable
[256]);
480 class FilterNodeConvolveMatrixSoftware
: public FilterNodeSoftware
{
482 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeConvolveMatrixSoftware
,
484 FilterNodeConvolveMatrixSoftware();
485 const char* GetName() override
{ return "ConvolveMatrix"; }
486 using FilterNodeSoftware::SetAttribute
;
487 void SetAttribute(uint32_t aIndex
, const IntSize
& aKernelSize
) override
;
488 void SetAttribute(uint32_t aIndex
, const Float
* aMatrix
,
489 uint32_t aSize
) override
;
490 void SetAttribute(uint32_t aIndex
, Float aValue
) override
;
491 void SetAttribute(uint32_t aIndex
, const Size
& aKernelUnitLength
) override
;
492 void SetAttribute(uint32_t aIndex
, const IntRect
& aSourceRect
) override
;
493 void SetAttribute(uint32_t aIndex
, const IntPoint
& aTarget
) override
;
494 void SetAttribute(uint32_t aIndex
, uint32_t aEdgeMode
) override
;
495 void SetAttribute(uint32_t aIndex
, bool aPreserveAlpha
) override
;
496 IntRect
MapRectToSource(const IntRect
& aRect
, const IntRect
& aMax
,
497 FilterNode
* aSourceNode
) override
;
500 already_AddRefed
<DataSourceSurface
> Render(const IntRect
& aRect
) override
;
501 IntRect
GetOutputRectInRect(const IntRect
& aRect
) override
;
502 int32_t InputIndex(uint32_t aInputEnumIndex
) override
;
503 void RequestFromInputsForRect(const IntRect
& aRect
) override
;
506 template <typename CoordType
>
507 already_AddRefed
<DataSourceSurface
> DoRender(const IntRect
& aRect
,
508 CoordType aKernelUnitLengthX
,
509 CoordType aKernelUnitLengthY
);
511 IntRect
InflatedSourceRect(const IntRect
& aDestRect
);
512 IntRect
InflatedDestRect(const IntRect
& aSourceRect
);
515 std::vector
<Float
> mKernelMatrix
;
520 ConvolveMatrixEdgeMode mEdgeMode
;
521 Size mKernelUnitLength
;
525 class FilterNodeDisplacementMapSoftware
: public FilterNodeSoftware
{
527 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeDisplacementMapSoftware
,
529 FilterNodeDisplacementMapSoftware();
530 const char* GetName() override
{ return "DisplacementMap"; }
531 using FilterNodeSoftware::SetAttribute
;
532 void SetAttribute(uint32_t aIndex
, Float aScale
) override
;
533 void SetAttribute(uint32_t aIndex
, uint32_t aValue
) override
;
534 IntRect
MapRectToSource(const IntRect
& aRect
, const IntRect
& aMax
,
535 FilterNode
* aSourceNode
) override
;
538 already_AddRefed
<DataSourceSurface
> Render(const IntRect
& aRect
) override
;
539 IntRect
GetOutputRectInRect(const IntRect
& aRect
) override
;
540 int32_t InputIndex(uint32_t aInputEnumIndex
) override
;
541 void RequestFromInputsForRect(const IntRect
& aRect
) override
;
544 IntRect
InflatedSourceOrDestRect(const IntRect
& aDestOrSourceRect
);
547 ColorChannel mChannelX
;
548 ColorChannel mChannelY
;
551 class FilterNodeTurbulenceSoftware
: public FilterNodeSoftware
{
553 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeTurbulenceSoftware
,
555 FilterNodeTurbulenceSoftware();
556 const char* GetName() override
{ return "Turbulence"; }
557 using FilterNodeSoftware::SetAttribute
;
558 void SetAttribute(uint32_t aIndex
, const Size
& aSize
) override
;
559 void SetAttribute(uint32_t aIndex
, const IntRect
& aRenderRect
) override
;
560 void SetAttribute(uint32_t aIndex
, bool aStitchable
) override
;
561 void SetAttribute(uint32_t aIndex
, uint32_t aValue
) override
;
562 IntRect
MapRectToSource(const IntRect
& aRect
, const IntRect
& aMax
,
563 FilterNode
* aSourceNode
) override
;
566 already_AddRefed
<DataSourceSurface
> Render(const IntRect
& aRect
) override
;
567 IntRect
GetOutputRectInRect(const IntRect
& aRect
) override
;
568 int32_t InputIndex(uint32_t aInputEnumIndex
) override
;
573 uint32_t mNumOctaves
;
576 TurbulenceType mType
;
579 class FilterNodeArithmeticCombineSoftware
: public FilterNodeSoftware
{
581 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeArithmeticCombineSoftware
,
583 FilterNodeArithmeticCombineSoftware();
584 const char* GetName() override
{ return "ArithmeticCombine"; }
585 using FilterNodeSoftware::SetAttribute
;
586 void SetAttribute(uint32_t aIndex
, const Float
* aFloat
,
587 uint32_t aSize
) override
;
588 IntRect
MapRectToSource(const IntRect
& aRect
, const IntRect
& aMax
,
589 FilterNode
* aSourceNode
) override
;
592 already_AddRefed
<DataSourceSurface
> Render(const IntRect
& aRect
) override
;
593 IntRect
GetOutputRectInRect(const IntRect
& aRect
) override
;
594 int32_t InputIndex(uint32_t aInputEnumIndex
) override
;
595 void RequestFromInputsForRect(const IntRect
& aRect
) override
;
604 class FilterNodeCompositeSoftware
: public FilterNodeSoftware
{
606 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeCompositeSoftware
, override
)
607 FilterNodeCompositeSoftware();
608 const char* GetName() override
{ return "Composite"; }
609 using FilterNodeSoftware::SetAttribute
;
610 void SetAttribute(uint32_t aIndex
, uint32_t aOperator
) override
;
613 already_AddRefed
<DataSourceSurface
> Render(const IntRect
& aRect
) override
;
614 IntRect
GetOutputRectInRect(const IntRect
& aRect
) override
;
615 int32_t InputIndex(uint32_t aInputEnumIndex
) override
;
616 void RequestFromInputsForRect(const IntRect
& aRect
) override
;
617 IntRect
MapRectToSource(const IntRect
& aRect
, const IntRect
& aMax
,
618 FilterNode
* aSourceNode
) override
;
621 CompositeOperator mOperator
;
624 // Base class for FilterNodeGaussianBlurSoftware and
625 // FilterNodeDirectionalBlurSoftware.
626 class FilterNodeBlurXYSoftware
: public FilterNodeSoftware
{
628 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeBlurXYSoftware
, override
)
630 already_AddRefed
<DataSourceSurface
> Render(const IntRect
& aRect
) override
;
631 IntRect
GetOutputRectInRect(const IntRect
& aRect
) override
;
632 int32_t InputIndex(uint32_t aInputEnumIndex
) override
;
633 IntRect
InflatedSourceOrDestRect(const IntRect
& aDestRect
);
634 void RequestFromInputsForRect(const IntRect
& aRect
) override
;
635 IntRect
MapRectToSource(const IntRect
& aRect
, const IntRect
& aMax
,
636 FilterNode
* aSourceNode
) override
;
638 // Implemented by subclasses.
639 virtual Size
StdDeviationXY() = 0;
642 class FilterNodeGaussianBlurSoftware
: public FilterNodeBlurXYSoftware
{
644 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeGaussianBlurSoftware
,
646 FilterNodeGaussianBlurSoftware();
647 const char* GetName() override
{ return "GaussianBlur"; }
648 using FilterNodeSoftware::SetAttribute
;
649 void SetAttribute(uint32_t aIndex
, Float aStdDeviation
) override
;
652 Size
StdDeviationXY() override
;
658 class FilterNodeDirectionalBlurSoftware
: public FilterNodeBlurXYSoftware
{
660 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeDirectionalBlurSoftware
,
662 FilterNodeDirectionalBlurSoftware();
663 const char* GetName() override
{ return "DirectionalBlur"; }
664 using FilterNodeSoftware::SetAttribute
;
665 void SetAttribute(uint32_t aIndex
, Float aStdDeviation
) override
;
666 void SetAttribute(uint32_t aIndex
, uint32_t aBlurDirection
) override
;
669 Size
StdDeviationXY() override
;
673 BlurDirection mBlurDirection
;
676 class FilterNodeCropSoftware
: public FilterNodeSoftware
{
678 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeCropSoftware
, override
)
679 const char* GetName() override
{ return "Crop"; }
680 using FilterNodeSoftware::SetAttribute
;
681 void SetAttribute(uint32_t aIndex
, const Rect
& aSourceRect
) override
;
684 already_AddRefed
<DataSourceSurface
> Render(const IntRect
& aRect
) override
;
685 IntRect
GetOutputRectInRect(const IntRect
& aRect
) override
;
686 int32_t InputIndex(uint32_t aInputEnumIndex
) override
;
687 void RequestFromInputsForRect(const IntRect
& aRect
) override
;
688 IntRect
MapRectToSource(const IntRect
& aRect
, const IntRect
& aMax
,
689 FilterNode
* aSourceNode
) override
;
695 class FilterNodePremultiplySoftware
: public FilterNodeSoftware
{
697 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodePremultiplySoftware
,
699 const char* GetName() override
{ return "Premultiply"; }
702 already_AddRefed
<DataSourceSurface
> Render(const IntRect
& aRect
) override
;
703 IntRect
GetOutputRectInRect(const IntRect
& aRect
) override
;
704 int32_t InputIndex(uint32_t aInputEnumIndex
) override
;
705 void RequestFromInputsForRect(const IntRect
& aRect
) override
;
706 IntRect
MapRectToSource(const IntRect
& aRect
, const IntRect
& aMax
,
707 FilterNode
* aSourceNode
) override
;
710 class FilterNodeUnpremultiplySoftware
: public FilterNodeSoftware
{
712 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeUnpremultiplySoftware
,
714 const char* GetName() override
{ return "Unpremultiply"; }
717 already_AddRefed
<DataSourceSurface
> Render(const IntRect
& aRect
) override
;
718 IntRect
GetOutputRectInRect(const IntRect
& aRect
) override
;
719 int32_t InputIndex(uint32_t aInputEnumIndex
) override
;
720 void RequestFromInputsForRect(const IntRect
& aRect
) override
;
721 IntRect
MapRectToSource(const IntRect
& aRect
, const IntRect
& aMax
,
722 FilterNode
* aSourceNode
) override
;
725 class FilterNodeOpacitySoftware
: public FilterNodeSoftware
{
727 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeOpacitySoftware
, override
)
728 const char* GetName() override
{ return "Opacity"; }
729 using FilterNodeSoftware::SetAttribute
;
730 void SetAttribute(uint32_t aIndex
, Float aValue
) override
;
731 IntRect
MapRectToSource(const IntRect
& aRect
, const IntRect
& aMax
,
732 FilterNode
* aSourceNode
) override
;
735 already_AddRefed
<DataSourceSurface
> Render(const IntRect
& aRect
) override
;
736 IntRect
GetOutputRectInRect(const IntRect
& aRect
) override
;
737 int32_t InputIndex(uint32_t aInputEnumIndex
) override
;
738 void RequestFromInputsForRect(const IntRect
& aRect
) override
;
743 template <typename LightType
, typename LightingType
>
744 class FilterNodeLightingSoftware
: public FilterNodeSoftware
{
746 #if defined(MOZILLA_INTERNAL_API) && \
747 (defined(DEBUG) || defined(FORCE_BUILD_REFCNT_LOGGING))
748 // Helpers for refcounted
749 const char* typeName() const override
{ return mTypeName
; }
750 size_t typeSize() const override
{ return sizeof(*this); }
752 explicit FilterNodeLightingSoftware(const char* aTypeName
);
753 const char* GetName() override
{ return "Lighting"; }
754 using FilterNodeSoftware::SetAttribute
;
755 void SetAttribute(uint32_t aIndex
, Float
) override
;
756 void SetAttribute(uint32_t aIndex
, const Size
&) override
;
757 void SetAttribute(uint32_t aIndex
, const Point3D
&) override
;
758 void SetAttribute(uint32_t aIndex
, const DeviceColor
&) override
;
759 IntRect
MapRectToSource(const IntRect
& aRect
, const IntRect
& aMax
,
760 FilterNode
* aSourceNode
) override
;
763 already_AddRefed
<DataSourceSurface
> Render(const IntRect
& aRect
) override
;
764 IntRect
GetOutputRectInRect(const IntRect
& aRect
) override
;
765 int32_t InputIndex(uint32_t aInputEnumIndex
) override
;
766 void RequestFromInputsForRect(const IntRect
& aRect
) override
;
769 template <typename CoordType
>
770 already_AddRefed
<DataSourceSurface
> DoRender(const IntRect
& aRect
,
771 CoordType aKernelUnitLengthX
,
772 CoordType aKernelUnitLengthY
);
776 LightingType mLighting
;
778 Size mKernelUnitLength
;
780 #if defined(MOZILLA_INTERNAL_API) && \
781 (defined(DEBUG) || defined(FORCE_BUILD_REFCNT_LOGGING))
782 const char* mTypeName
;
787 } // namespace mozilla
789 #endif // _MOZILLA_GFX_FILTERNODESOFTWARE_H_