Bug 1867925 - Mark some storage-access-api tests as intermittent after wpt-sync....
[gecko.git] / layout / svg / CSSFilterInstance.h
blobcdf21ee2bfc285290adefa9cc4d8fdc9f113b328
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 LAYOUT_SVG_CSSFILTERINSTANCE_H_
8 #define LAYOUT_SVG_CSSFILTERINSTANCE_H_
10 #include "FilterSupport.h"
11 #include "gfxMatrix.h"
12 #include "gfxRect.h"
13 #include "mozilla/gfx/Point.h"
14 #include "mozilla/gfx/Types.h"
15 #include "nsColor.h"
16 #include "mozilla/ServoStyleConsts.h"
18 namespace mozilla {
20 /**
21 * This class helps FilterInstance build its filter graph. It turns a CSS
22 * filter function (e.g. blur(3px)) from the style system into a
23 * FilterPrimitiveDescription connected to the filter graph.
25 class CSSFilterInstance {
26 using sRGBColor = gfx::sRGBColor;
27 using FilterPrimitiveDescription = gfx::FilterPrimitiveDescription;
28 using IntPoint = gfx::IntPoint;
29 using Size = gfx::Size;
31 public:
32 /**
33 * @param aFilter The CSS filter from the style system. This class stores
34 * aFilter by reference, so callers should avoid modifying or deleting
35 * aFilter during the lifetime of CSSFilterInstance.
36 * @param aShadowFallbackColor The color that should be used for
37 * drop-shadow() filters that don't specify a shadow color.
38 * @param aTargetBoundsInFilterSpace The pre-filter ink overflow rect of
39 * the frame being filtered, in filter space.
40 * @param aFrameSpaceInCSSPxToFilterSpaceTransform The transformation from
41 * the filtered element's frame space in CSS pixels to filter space.
43 CSSFilterInstance(const StyleFilter& aFilter, nscolor aShadowFallbackColor,
44 const nsIntRect& aTargetBoundsInFilterSpace,
45 const gfxMatrix& aFrameSpaceInCSSPxToFilterSpaceTransform);
47 /**
48 * Creates at least one new FilterPrimitiveDescription based on the filter
49 * from the style system. Appends the new FilterPrimitiveDescription(s) to the
50 * aPrimitiveDescrs list.
51 * aInputIsTainted describes whether the input to this filter is tainted, i.e.
52 * whether it contains security-sensitive content. This is needed to propagate
53 * taintedness to the FilterPrimitive that take tainted inputs. Something
54 * being tainted means that it contains security sensitive content. The input
55 * to this filter is the previous filter's output, i.e. the last element in
56 * aPrimitiveDescrs, or the SourceGraphic input if this is the first filter in
57 * the filter chain.
59 nsresult BuildPrimitives(
60 nsTArray<FilterPrimitiveDescription>& aPrimitiveDescrs,
61 bool aInputIsTainted);
63 private:
64 /**
65 * Returns a new FilterPrimitiveDescription with its basic properties set up.
66 * See the comment above BuildPrimitives for the meaning of aInputIsTainted.
68 FilterPrimitiveDescription CreatePrimitiveDescription(
69 const nsTArray<FilterPrimitiveDescription>& aPrimitiveDescrs,
70 bool aInputIsTainted);
72 /**
73 * Sets aDescr's attributes using the style info in mFilter.
75 nsresult SetAttributesForBlur(FilterPrimitiveDescription& aDescr);
76 nsresult SetAttributesForBrightness(FilterPrimitiveDescription& aDescr);
77 nsresult SetAttributesForContrast(FilterPrimitiveDescription& aDescr);
78 nsresult SetAttributesForDropShadow(FilterPrimitiveDescription& aDescr);
79 nsresult SetAttributesForGrayscale(FilterPrimitiveDescription& aDescr);
80 nsresult SetAttributesForHueRotate(FilterPrimitiveDescription& aDescr);
81 nsresult SetAttributesForInvert(FilterPrimitiveDescription& aDescr);
82 nsresult SetAttributesForOpacity(FilterPrimitiveDescription& aDescr);
83 nsresult SetAttributesForSaturate(FilterPrimitiveDescription& aDescr);
84 nsresult SetAttributesForSepia(FilterPrimitiveDescription& aDescr);
86 /**
87 * Returns the index of the last result in the aPrimitiveDescrs, which we'll
88 * use as the input to this CSS filter.
90 int32_t GetLastResultIndex(
91 const nsTArray<FilterPrimitiveDescription>& aPrimitiveDescrs);
93 /**
94 * Sets aDescr's filter region and primitive subregion to appropriate values
95 * based on this CSS filter's input and its attributes. For example, a CSS
96 * blur filter will have bounds equal to its input bounds, inflated by the
97 * blur extents.
99 void SetBounds(FilterPrimitiveDescription& aDescr,
100 const nsTArray<FilterPrimitiveDescription>& aPrimitiveDescrs);
103 * Converts an nscolor to a Color, suitable for use as a
104 * FilterPrimitiveDescription attribute.
106 sRGBColor ToAttributeColor(nscolor aColor);
109 * Converts a blur radius in frame space to filter space.
111 Size BlurRadiusToFilterSpace(nscoord aRadiusInFrameSpace);
114 * Converts a point defined by a pair of nscoord x, y coordinates from frame
115 * space to filter space.
117 IntPoint OffsetToFilterSpace(nscoord aXOffsetInFrameSpace,
118 nscoord aYOffsetInFrameSpace);
121 * The CSS filter originally from the style system.
123 const StyleFilter& mFilter;
126 * The color that should be used for drop-shadow() filters that don't
127 * specify a shadow color.
129 nscolor mShadowFallbackColor;
132 * The pre-filter overflow rect of the frame being filtered, in filter space.
133 * Used for input bounds if this CSS filter is the first in the filter chain.
135 nsIntRect mTargetBoundsInFilterSpace;
138 * The transformation from the filtered element's frame space in CSS pixels to
139 * filter space. Used to transform style values to filter space.
141 gfxMatrix mFrameSpaceInCSSPxToFilterSpaceTransform;
144 } // namespace mozilla
146 #endif // LAYOUT_SVG_CSSFILTERINSTANCE_H_