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 __FilterDescription_h
8 #define __FilterDescription_h
10 #include "FilterSupport.h"
11 #include "mozilla/Variant.h"
12 #include "mozilla/gfx/Rect.h"
15 namespace mozilla::gfx
{
16 class FilterPrimitiveDescription
;
19 MOZ_DECLARE_RELOCATE_USING_MOVE_CONSTRUCTOR(
20 mozilla::gfx::FilterPrimitiveDescription
)
22 namespace mozilla::gfx
{
24 EmptyAttributes
, BlendAttributes
, MorphologyAttributes
,
25 ColorMatrixAttributes
, FloodAttributes
, TileAttributes
,
26 ComponentTransferAttributes
, OpacityAttributes
, ConvolveMatrixAttributes
,
27 OffsetAttributes
, DisplacementMapAttributes
, TurbulenceAttributes
,
28 CompositeAttributes
, MergeAttributes
, ImageAttributes
,
29 GaussianBlurAttributes
, DropShadowAttributes
, DiffuseLightingAttributes
,
30 SpecularLightingAttributes
, ToAlphaAttributes
>
34 * A data structure to carry attributes for a given primitive that's part of a
35 * filter. Will be serializable via IPDL, so it must not contain complex
37 * Used as part of a FilterDescription.
39 class FilterPrimitiveDescription final
{
42 kPrimitiveIndexSourceGraphic
= -1,
43 kPrimitiveIndexSourceAlpha
= -2,
44 kPrimitiveIndexFillPaint
= -3,
45 kPrimitiveIndexStrokePaint
= -4
48 FilterPrimitiveDescription();
49 explicit FilterPrimitiveDescription(PrimitiveAttributes
&& aAttributes
);
50 FilterPrimitiveDescription(FilterPrimitiveDescription
&& aOther
) = default;
51 FilterPrimitiveDescription
& operator=(FilterPrimitiveDescription
&& aOther
) =
53 FilterPrimitiveDescription(const FilterPrimitiveDescription
& aOther
)
54 : mAttributes(aOther
.mAttributes
),
55 mInputPrimitives(aOther
.mInputPrimitives
.Clone()),
56 mFilterPrimitiveSubregion(aOther
.mFilterPrimitiveSubregion
),
57 mFilterSpaceBounds(aOther
.mFilterSpaceBounds
),
58 mInputColorSpaces(aOther
.mInputColorSpaces
.Clone()),
59 mOutputColorSpace(aOther
.mOutputColorSpace
),
60 mIsTainted(aOther
.mIsTainted
) {}
62 const PrimitiveAttributes
& Attributes() const { return mAttributes
; }
63 PrimitiveAttributes
& Attributes() { return mAttributes
; }
65 IntRect
PrimitiveSubregion() const { return mFilterPrimitiveSubregion
; }
66 IntRect
FilterSpaceBounds() const { return mFilterSpaceBounds
; }
67 bool IsTainted() const { return mIsTainted
; }
69 size_t NumberOfInputs() const { return mInputPrimitives
.Length(); }
70 int32_t InputPrimitiveIndex(size_t aInputIndex
) const {
71 return aInputIndex
< mInputPrimitives
.Length()
72 ? mInputPrimitives
[aInputIndex
]
76 ColorSpace
InputColorSpace(size_t aInputIndex
) const {
77 return aInputIndex
< mInputColorSpaces
.Length()
78 ? mInputColorSpaces
[aInputIndex
]
82 ColorSpace
OutputColorSpace() const { return mOutputColorSpace
; }
84 void SetPrimitiveSubregion(const IntRect
& aRect
) {
85 mFilterPrimitiveSubregion
= aRect
;
88 void SetFilterSpaceBounds(const IntRect
& aRect
) {
89 mFilterSpaceBounds
= aRect
;
92 void SetIsTainted(bool aIsTainted
) { mIsTainted
= aIsTainted
; }
94 void SetInputPrimitive(size_t aInputIndex
, int32_t aInputPrimitiveIndex
) {
95 mInputPrimitives
.EnsureLengthAtLeast(aInputIndex
+ 1);
96 mInputPrimitives
[aInputIndex
] = aInputPrimitiveIndex
;
99 void SetInputColorSpace(size_t aInputIndex
, ColorSpace aColorSpace
) {
100 mInputColorSpaces
.EnsureLengthAtLeast(aInputIndex
+ 1);
101 mInputColorSpaces
[aInputIndex
] = aColorSpace
;
104 void SetOutputColorSpace(const ColorSpace
& aColorSpace
) {
105 mOutputColorSpace
= aColorSpace
;
108 bool operator==(const FilterPrimitiveDescription
& aOther
) const;
109 bool operator!=(const FilterPrimitiveDescription
& aOther
) const {
110 return !(*this == aOther
);
114 PrimitiveAttributes mAttributes
;
115 AutoTArray
<int32_t, 2> mInputPrimitives
;
116 IntRect mFilterPrimitiveSubregion
;
117 IntRect mFilterSpaceBounds
;
118 AutoTArray
<ColorSpace
, 2> mInputColorSpaces
;
119 ColorSpace mOutputColorSpace
;
124 * A data structure that contains one or more FilterPrimitiveDescriptions.
125 * Designed to be serializable via IPDL, so it must not contain complex
128 struct FilterDescription final
{
129 FilterDescription() = default;
130 explicit FilterDescription(nsTArray
<FilterPrimitiveDescription
>&& aPrimitives
)
131 : mPrimitives(std::move(aPrimitives
)) {}
133 bool operator==(const FilterDescription
& aOther
) const;
134 bool operator!=(const FilterDescription
& aOther
) const {
135 return !(*this == aOther
);
138 CopyableTArray
<FilterPrimitiveDescription
> mPrimitives
;
140 } // namespace mozilla::gfx
142 #endif // __FilterSupport_h