Bug 1686855 [wpt PR 27197] - PlzDedicatedWorker: WPT for clients.matchAll() with...
[gecko.git] / gfx / 2d / FilterNodeSoftware.h
blob1897c3206f2231eecfbe059d91f3f44f2dd3330f
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 * Lock guarding mRequestedRect, mCachedRect, and mCachedOutput. All uses
208 * of those members must aquire this lock.
210 Mutex mCacheMutex;
213 * Stores the rect which we want to render and cache on the next call to
214 * GetOutput.
216 IntRect mRequestedRect;
219 * Stores our cached output.
221 IntRect mCachedRect;
222 RefPtr<DataSourceSurface> mCachedOutput;
225 // Subclasses for specific filters.
227 class FilterNodeTransformSoftware : public FilterNodeSoftware {
228 public:
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;
238 protected:
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);
245 private:
246 Matrix mMatrix;
247 SamplingFilter mSamplingFilter;
250 class FilterNodeBlendSoftware : public FilterNodeSoftware {
251 public:
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;
260 protected:
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;
266 private:
267 BlendMode mBlendMode;
270 class FilterNodeMorphologySoftware : public FilterNodeSoftware {
271 public:
272 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeMorphologySoftware,
273 override)
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;
280 protected:
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;
286 private:
287 IntSize mRadii;
288 MorphologyOperator mOperator;
291 class FilterNodeColorMatrixSoftware : public FilterNodeSoftware {
292 public:
293 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeColorMatrixSoftware,
294 override)
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;
300 protected:
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;
308 private:
309 Matrix5x4 mMatrix;
310 AlphaMode mAlphaMode;
313 class FilterNodeFloodSoftware : public FilterNodeSoftware {
314 public:
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;
322 protected:
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;
327 private:
328 DeviceColor mColor;
331 class FilterNodeTileSoftware : public FilterNodeSoftware {
332 public:
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;
338 protected:
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;
344 private:
345 IntRect mSourceRect;
349 * Baseclass for the four different component transfer filters.
351 class FilterNodeComponentTransferSoftware : public FilterNodeSoftware {
352 public:
353 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeComponentTransferSoftware,
354 override)
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;
362 protected:
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;
371 bool mDisableR;
372 bool mDisableG;
373 bool mDisableB;
374 bool mDisableA;
377 class FilterNodeTableTransferSoftware
378 : public FilterNodeComponentTransferSoftware {
379 public:
380 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeTableTransferSoftware,
381 override)
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;
387 protected:
388 void FillLookupTable(ptrdiff_t aComponent, uint8_t aTable[256]) override;
390 private:
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 {
402 public:
403 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeDiscreteTransferSoftware,
404 override)
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;
410 protected:
411 void FillLookupTable(ptrdiff_t aComponent, uint8_t aTable[256]) override;
413 private:
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 {
425 public:
426 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeLinearTransformSoftware,
427 override)
428 FilterNodeLinearTransferSoftware();
429 const char* GetName() override { return "LinearTransfer"; }
430 using FilterNodeComponentTransferSoftware::SetAttribute;
431 void SetAttribute(uint32_t aIndex, Float aValue) override;
433 protected:
434 void FillLookupTable(ptrdiff_t aComponent, uint8_t aTable[256]) override;
436 private:
437 void FillLookupTableImpl(Float aSlope, Float aIntercept, uint8_t aTable[256]);
439 Float mSlopeR;
440 Float mSlopeG;
441 Float mSlopeB;
442 Float mSlopeA;
443 Float mInterceptR;
444 Float mInterceptG;
445 Float mInterceptB;
446 Float mInterceptA;
449 class FilterNodeGammaTransferSoftware
450 : public FilterNodeComponentTransferSoftware {
451 public:
452 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeGammaTransferSoftware,
453 override)
454 FilterNodeGammaTransferSoftware();
455 const char* GetName() override { return "GammaTransfer"; }
456 using FilterNodeComponentTransferSoftware::SetAttribute;
457 void SetAttribute(uint32_t aIndex, Float aValue) override;
459 protected:
460 void FillLookupTable(ptrdiff_t aComponent, uint8_t aTable[256]) override;
462 private:
463 void FillLookupTableImpl(Float aAmplitude, Float aExponent, Float aOffset,
464 uint8_t aTable[256]);
466 Float mAmplitudeR;
467 Float mAmplitudeG;
468 Float mAmplitudeB;
469 Float mAmplitudeA;
470 Float mExponentR;
471 Float mExponentG;
472 Float mExponentB;
473 Float mExponentA;
474 Float mOffsetR;
475 Float mOffsetG;
476 Float mOffsetB;
477 Float mOffsetA;
480 class FilterNodeConvolveMatrixSoftware : public FilterNodeSoftware {
481 public:
482 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeConvolveMatrixSoftware,
483 override)
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;
499 protected:
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;
505 private:
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);
514 IntSize mKernelSize;
515 std::vector<Float> mKernelMatrix;
516 Float mDivisor;
517 Float mBias;
518 IntPoint mTarget;
519 IntRect mSourceRect;
520 ConvolveMatrixEdgeMode mEdgeMode;
521 Size mKernelUnitLength;
522 bool mPreserveAlpha;
525 class FilterNodeDisplacementMapSoftware : public FilterNodeSoftware {
526 public:
527 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeDisplacementMapSoftware,
528 override)
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;
537 protected:
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;
543 private:
544 IntRect InflatedSourceOrDestRect(const IntRect& aDestOrSourceRect);
546 Float mScale;
547 ColorChannel mChannelX;
548 ColorChannel mChannelY;
551 class FilterNodeTurbulenceSoftware : public FilterNodeSoftware {
552 public:
553 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeTurbulenceSoftware,
554 override)
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;
565 protected:
566 already_AddRefed<DataSourceSurface> Render(const IntRect& aRect) override;
567 IntRect GetOutputRectInRect(const IntRect& aRect) override;
568 int32_t InputIndex(uint32_t aInputEnumIndex) override;
570 private:
571 IntRect mRenderRect;
572 Size mBaseFrequency;
573 uint32_t mNumOctaves;
574 uint32_t mSeed;
575 bool mStitchable;
576 TurbulenceType mType;
579 class FilterNodeArithmeticCombineSoftware : public FilterNodeSoftware {
580 public:
581 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeArithmeticCombineSoftware,
582 override)
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;
591 protected:
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;
597 private:
598 Float mK1;
599 Float mK2;
600 Float mK3;
601 Float mK4;
604 class FilterNodeCompositeSoftware : public FilterNodeSoftware {
605 public:
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;
612 protected:
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;
620 private:
621 CompositeOperator mOperator;
624 // Base class for FilterNodeGaussianBlurSoftware and
625 // FilterNodeDirectionalBlurSoftware.
626 class FilterNodeBlurXYSoftware : public FilterNodeSoftware {
627 public:
628 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeBlurXYSoftware, override)
629 protected:
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 {
643 public:
644 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeGaussianBlurSoftware,
645 override)
646 FilterNodeGaussianBlurSoftware();
647 const char* GetName() override { return "GaussianBlur"; }
648 using FilterNodeSoftware::SetAttribute;
649 void SetAttribute(uint32_t aIndex, Float aStdDeviation) override;
651 protected:
652 Size StdDeviationXY() override;
654 private:
655 Float mStdDeviation;
658 class FilterNodeDirectionalBlurSoftware : public FilterNodeBlurXYSoftware {
659 public:
660 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeDirectionalBlurSoftware,
661 override)
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;
668 protected:
669 Size StdDeviationXY() override;
671 private:
672 Float mStdDeviation;
673 BlurDirection mBlurDirection;
676 class FilterNodeCropSoftware : public FilterNodeSoftware {
677 public:
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;
683 protected:
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;
691 private:
692 IntRect mCropRect;
695 class FilterNodePremultiplySoftware : public FilterNodeSoftware {
696 public:
697 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodePremultiplySoftware,
698 override)
699 const char* GetName() override { return "Premultiply"; }
701 protected:
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 {
711 public:
712 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeUnpremultiplySoftware,
713 override)
714 const char* GetName() override { return "Unpremultiply"; }
716 protected:
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 {
726 public:
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;
734 protected:
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;
740 Float mValue = 1.0f;
743 template <typename LightType, typename LightingType>
744 class FilterNodeLightingSoftware : public FilterNodeSoftware {
745 public:
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); }
751 #endif
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;
762 protected:
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;
768 private:
769 template <typename CoordType>
770 already_AddRefed<DataSourceSurface> DoRender(const IntRect& aRect,
771 CoordType aKernelUnitLengthX,
772 CoordType aKernelUnitLengthY);
774 Mutex mLock;
775 LightType mLight;
776 LightingType mLighting;
777 Float mSurfaceScale;
778 Size mKernelUnitLength;
779 DeviceColor mColor;
780 #if defined(MOZILLA_INTERNAL_API) && \
781 (defined(DEBUG) || defined(FORCE_BUILD_REFCNT_LOGGING))
782 const char* mTypeName;
783 #endif
786 } // namespace gfx
787 } // namespace mozilla
789 #endif // _MOZILLA_GFX_FILTERNODESOFTWARE_H_