Bug 1890689 accumulate input in LargerReceiverBlockSizeThanDesiredBuffering GTest...
[gecko.git] / gfx / 2d / FilterNodeSoftware.h
blob25b2481bfeb5d74ed9520df7adf3776e88fb9b31
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_
10 #include "Filters.h"
11 #include "mozilla/Mutex.h"
12 #include <vector>
14 namespace mozilla {
15 namespace gfx {
17 class DataSourceSurface;
18 class DrawTarget;
19 struct DrawOptions;
20 class FilterNodeSoftware;
22 /**
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 {
29 public:
30 virtual void FilterInvalidated(FilterNodeSoftware* aFilter) = 0;
33 /**
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 {
40 public:
41 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeSoftware, override)
42 FilterNodeSoftware();
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;
64 protected:
65 // The following methods are intended to be overriden by subclasses.
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.
73 virtual int32_t InputIndex(uint32_t aInputEnumIndex) { return -1; }
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.
82 virtual IntRect GetOutputRectInRect(const IntRect& aInRect) = 0;
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.
93 virtual already_AddRefed<DataSourceSurface> Render(const IntRect& aRect) = 0;
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.
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
133 * transparent black.
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
147 * with aInRect.
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.
173 void Invalidate();
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
178 * filters.
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
185 * be null.
187 void SetInput(uint32_t aIndex, SourceSurface* aSurface,
188 FilterNodeSoftware* aFilter);
190 protected:
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
208 * GetOutput.
210 IntRect mRequestedRect;
213 * Stores our cached output.
215 IntRect mCachedRect;
216 RefPtr<DataSourceSurface> mCachedOutput;
219 // Subclasses for specific filters.
221 class FilterNodeTransformSoftware : public FilterNodeSoftware {
222 public:
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;
232 protected:
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);
239 private:
240 Matrix mMatrix;
241 SamplingFilter mSamplingFilter;
244 class FilterNodeBlendSoftware : public FilterNodeSoftware {
245 public:
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;
254 protected:
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;
260 private:
261 BlendMode mBlendMode;
264 class FilterNodeMorphologySoftware : public FilterNodeSoftware {
265 public:
266 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeMorphologySoftware,
267 override)
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;
274 protected:
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;
280 private:
281 IntSize mRadii;
282 MorphologyOperator mOperator;
285 class FilterNodeColorMatrixSoftware : public FilterNodeSoftware {
286 public:
287 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeColorMatrixSoftware,
288 override)
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;
294 protected:
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;
302 private:
303 Matrix5x4 mMatrix;
304 AlphaMode mAlphaMode;
307 class FilterNodeFloodSoftware : public FilterNodeSoftware {
308 public:
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;
316 protected:
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;
321 private:
322 DeviceColor mColor;
325 class FilterNodeTileSoftware : public FilterNodeSoftware {
326 public:
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;
332 protected:
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;
338 private:
339 IntRect mSourceRect;
343 * Baseclass for the four different component transfer filters.
345 class FilterNodeComponentTransferSoftware : public FilterNodeSoftware {
346 public:
347 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeComponentTransferSoftware,
348 override)
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;
356 protected:
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;
365 bool mDisableR;
366 bool mDisableG;
367 bool mDisableB;
368 bool mDisableA;
371 class FilterNodeTableTransferSoftware
372 : public FilterNodeComponentTransferSoftware {
373 public:
374 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeTableTransferSoftware,
375 override)
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;
381 protected:
382 void FillLookupTable(ptrdiff_t aComponent, uint8_t aTable[256]) override;
384 private:
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 {
396 public:
397 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeDiscreteTransferSoftware,
398 override)
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;
404 protected:
405 void FillLookupTable(ptrdiff_t aComponent, uint8_t aTable[256]) override;
407 private:
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 {
419 public:
420 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeLinearTransformSoftware,
421 override)
422 FilterNodeLinearTransferSoftware();
423 const char* GetName() override { return "LinearTransfer"; }
424 using FilterNodeComponentTransferSoftware::SetAttribute;
425 void SetAttribute(uint32_t aIndex, Float aValue) override;
427 protected:
428 void FillLookupTable(ptrdiff_t aComponent, uint8_t aTable[256]) override;
430 private:
431 void FillLookupTableImpl(Float aSlope, Float aIntercept, uint8_t aTable[256]);
433 Float mSlopeR;
434 Float mSlopeG;
435 Float mSlopeB;
436 Float mSlopeA;
437 Float mInterceptR;
438 Float mInterceptG;
439 Float mInterceptB;
440 Float mInterceptA;
443 class FilterNodeGammaTransferSoftware
444 : public FilterNodeComponentTransferSoftware {
445 public:
446 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeGammaTransferSoftware,
447 override)
448 FilterNodeGammaTransferSoftware();
449 const char* GetName() override { return "GammaTransfer"; }
450 using FilterNodeComponentTransferSoftware::SetAttribute;
451 void SetAttribute(uint32_t aIndex, Float aValue) override;
453 protected:
454 void FillLookupTable(ptrdiff_t aComponent, uint8_t aTable[256]) override;
456 private:
457 void FillLookupTableImpl(Float aAmplitude, Float aExponent, Float aOffset,
458 uint8_t aTable[256]);
460 Float mAmplitudeR;
461 Float mAmplitudeG;
462 Float mAmplitudeB;
463 Float mAmplitudeA;
464 Float mExponentR;
465 Float mExponentG;
466 Float mExponentB;
467 Float mExponentA;
468 Float mOffsetR;
469 Float mOffsetG;
470 Float mOffsetB;
471 Float mOffsetA;
474 class FilterNodeConvolveMatrixSoftware : public FilterNodeSoftware {
475 public:
476 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeConvolveMatrixSoftware,
477 override)
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;
493 protected:
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;
499 private:
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);
508 IntSize mKernelSize;
509 std::vector<Float> mKernelMatrix;
510 Float mDivisor;
511 Float mBias;
512 IntPoint mTarget;
513 IntRect mSourceRect;
514 ConvolveMatrixEdgeMode mEdgeMode;
515 Size mKernelUnitLength;
516 bool mPreserveAlpha;
519 class FilterNodeDisplacementMapSoftware : public FilterNodeSoftware {
520 public:
521 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeDisplacementMapSoftware,
522 override)
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;
531 protected:
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;
537 private:
538 IntRect InflatedSourceOrDestRect(const IntRect& aDestOrSourceRect);
540 Float mScale;
541 ColorChannel mChannelX;
542 ColorChannel mChannelY;
545 class FilterNodeTurbulenceSoftware : public FilterNodeSoftware {
546 public:
547 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeTurbulenceSoftware,
548 override)
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;
559 protected:
560 already_AddRefed<DataSourceSurface> Render(const IntRect& aRect) override;
561 IntRect GetOutputRectInRect(const IntRect& aRect) override;
562 int32_t InputIndex(uint32_t aInputEnumIndex) override;
564 private:
565 IntRect mRenderRect;
566 Size mBaseFrequency;
567 uint32_t mNumOctaves;
568 uint32_t mSeed;
569 bool mStitchable;
570 TurbulenceType mType;
573 class FilterNodeArithmeticCombineSoftware : public FilterNodeSoftware {
574 public:
575 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeArithmeticCombineSoftware,
576 override)
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;
585 protected:
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;
591 private:
592 Float mK1;
593 Float mK2;
594 Float mK3;
595 Float mK4;
598 class FilterNodeCompositeSoftware : public FilterNodeSoftware {
599 public:
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;
606 protected:
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;
614 private:
615 CompositeOperator mOperator;
618 // Base class for FilterNodeGaussianBlurSoftware and
619 // FilterNodeDirectionalBlurSoftware.
620 class FilterNodeBlurXYSoftware : public FilterNodeSoftware {
621 public:
622 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeBlurXYSoftware, override)
623 protected:
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 {
637 public:
638 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeGaussianBlurSoftware,
639 override)
640 FilterNodeGaussianBlurSoftware();
641 const char* GetName() override { return "GaussianBlur"; }
642 using FilterNodeSoftware::SetAttribute;
643 void SetAttribute(uint32_t aIndex, Float aStdDeviation) override;
645 protected:
646 Size StdDeviationXY() override;
648 private:
649 Float mStdDeviation;
652 class FilterNodeDirectionalBlurSoftware : public FilterNodeBlurXYSoftware {
653 public:
654 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeDirectionalBlurSoftware,
655 override)
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;
662 protected:
663 Size StdDeviationXY() override;
665 private:
666 Float mStdDeviation;
667 BlurDirection mBlurDirection;
670 class FilterNodeCropSoftware : public FilterNodeSoftware {
671 public:
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;
677 protected:
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;
685 private:
686 IntRect mCropRect;
689 class FilterNodePremultiplySoftware : public FilterNodeSoftware {
690 public:
691 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodePremultiplySoftware,
692 override)
693 const char* GetName() override { return "Premultiply"; }
695 protected:
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 {
705 public:
706 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeUnpremultiplySoftware,
707 override)
708 const char* GetName() override { return "Unpremultiply"; }
710 protected:
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 {
720 public:
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;
728 protected:
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;
734 Float mValue = 1.0f;
737 template <typename LightType, typename LightingType>
738 class FilterNodeLightingSoftware : public FilterNodeSoftware {
739 public:
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); }
744 #endif
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;
755 protected:
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;
761 private:
762 template <typename CoordType>
763 already_AddRefed<DataSourceSurface> DoRender(const IntRect& aRect,
764 CoordType aKernelUnitLengthX,
765 CoordType aKernelUnitLengthY);
767 LightType mLight;
768 LightingType mLighting;
769 Float mSurfaceScale;
770 Size mKernelUnitLength;
771 DeviceColor mColor;
772 #if defined(MOZILLA_INTERNAL_API) && defined(NS_BUILD_REFCNT_LOGGING)
773 const char* mTypeName;
774 #endif
777 } // namespace gfx
778 } // namespace mozilla
780 #endif // _MOZILLA_GFX_FILTERNODESOFTWARE_H_