1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef __NS_CSSFILTERINSTANCE_H__
7 #define __NS_CSSFILTERINSTANCE_H__
9 #include "FilterSupport.h"
10 #include "gfxMatrix.h"
12 #include "mozilla/gfx/Point.h"
13 #include "mozilla/gfx/Types.h"
18 template<class T
> class nsTArray
;
21 * This class helps nsFilterInstance 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 nsCSSFilterInstance
27 typedef mozilla::gfx::Color Color
;
28 typedef mozilla::gfx::FilterPrimitiveDescription FilterPrimitiveDescription
;
29 typedef mozilla::gfx::IntPoint IntPoint
;
30 typedef mozilla::gfx::PrimitiveType PrimitiveType
;
31 typedef mozilla::gfx::Size Size
;
35 * @param aFilter The CSS filter from the style system. This class stores
36 * aFilter by reference, so callers should avoid modifying or deleting
37 * aFilter during the lifetime of nsCSSFilterInstance.
38 * @param mTargetBBoxInFilterSpace The frame of element being filtered, in
40 * @param aFrameSpaceInCSSPxToFilterSpaceTransform The transformation from
41 * the filtered element's frame space in CSS pixels to filter space.
43 nsCSSFilterInstance(const nsStyleFilter
& aFilter
,
44 nsIFrame
*aTargetFrame
,
45 const nsIntRect
& mTargetBBoxInFilterSpace
,
46 const gfxMatrix
& aFrameSpaceInCSSPxToFilterSpaceTransform
);
49 * Creates at least one new FilterPrimitiveDescription based on the filter
50 * from the style system. Appends the new FilterPrimitiveDescription(s) to the
51 * aPrimitiveDescrs list.
53 nsresult
BuildPrimitives(nsTArray
<FilterPrimitiveDescription
>& aPrimitiveDescrs
);
57 * Returns a new FilterPrimitiveDescription with its basic properties set up.
59 FilterPrimitiveDescription
CreatePrimitiveDescription(PrimitiveType aType
,
60 const nsTArray
<FilterPrimitiveDescription
>& aPrimitiveDescrs
);
63 * Sets aDescr's attributes using the style info in mFilter.
65 nsresult
SetAttributesForBlur(FilterPrimitiveDescription
& aDescr
);
66 nsresult
SetAttributesForBrightness(FilterPrimitiveDescription
& aDescr
);
67 nsresult
SetAttributesForContrast(FilterPrimitiveDescription
& aDescr
);
68 nsresult
SetAttributesForDropShadow(FilterPrimitiveDescription
& aDescr
);
69 nsresult
SetAttributesForGrayscale(FilterPrimitiveDescription
& aDescr
);
70 nsresult
SetAttributesForHueRotate(FilterPrimitiveDescription
& aDescr
);
71 nsresult
SetAttributesForInvert(FilterPrimitiveDescription
& aDescr
);
72 nsresult
SetAttributesForOpacity(FilterPrimitiveDescription
& aDescr
);
73 nsresult
SetAttributesForSaturate(FilterPrimitiveDescription
& aDescr
);
74 nsresult
SetAttributesForSepia(FilterPrimitiveDescription
& aDescr
);
77 * Returns the index of the last result in the aPrimitiveDescrs, which we'll
78 * use as the input to this CSS filter.
80 int32_t GetLastResultIndex(const nsTArray
<FilterPrimitiveDescription
>& aPrimitiveDescrs
);
83 * Sets aDescr's filter region and primitive subregion to appropriate values
84 * based on this CSS filter's input and its attributes. For example, a CSS
85 * blur filter will have bounds equal to its input bounds, inflated by the
88 void SetBounds(FilterPrimitiveDescription
& aDescr
,
89 const nsTArray
<FilterPrimitiveDescription
>& aPrimitiveDescrs
);
92 * Converts an nscolor to a Color, suitable for use as a
93 * FilterPrimitiveDescription attribute.
95 Color
ToAttributeColor(nscolor aColor
);
98 * Converts a blur radius in frame space to filter space.
100 Size
BlurRadiusToFilterSpace(nscoord aRadiusInFrameSpace
);
103 * Converts a point defined by a pair of nscoord x, y coordinates from frame
104 * space to filter space.
106 IntPoint
OffsetToFilterSpace(nscoord aXOffsetInFrameSpace
,
107 nscoord aYOffsetInFrameSpace
);
110 * The CSS filter originally from the style system.
112 const nsStyleFilter
& mFilter
;
115 * The frame for the element that is currently being filtered.
117 nsIFrame
* mTargetFrame
;
120 * The bounding box of the element being filtered, in filter space. Used for
121 * input bounds if this CSS filter is the first in the filter chain.
123 nsIntRect mTargetBBoxInFilterSpace
;
126 * The transformation from the filtered element's frame space in CSS pixels to
127 * filter space. Used to transform style values to filter space.
129 gfxMatrix mFrameSpaceInCSSPxToFilterSpaceTransform
;