summaryrefslogtreecommitdiffstats
path: root/layout/svg/CSSFilterInstance.h
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
commit26a029d407be480d791972afb5975cf62c9360a6 (patch)
treef435a8308119effd964b339f76abb83a57c29483 /layout/svg/CSSFilterInstance.h
parentInitial commit. (diff)
downloadfirefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz
firefox-26a029d407be480d791972afb5975cf62c9360a6.zip
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'layout/svg/CSSFilterInstance.h')
-rw-r--r--layout/svg/CSSFilterInstance.h146
1 files changed, 146 insertions, 0 deletions
diff --git a/layout/svg/CSSFilterInstance.h b/layout/svg/CSSFilterInstance.h
new file mode 100644
index 0000000000..cdf21ee2bf
--- /dev/null
+++ b/layout/svg/CSSFilterInstance.h
@@ -0,0 +1,146 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=8 sts=2 et sw=2 tw=80: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef LAYOUT_SVG_CSSFILTERINSTANCE_H_
+#define LAYOUT_SVG_CSSFILTERINSTANCE_H_
+
+#include "FilterSupport.h"
+#include "gfxMatrix.h"
+#include "gfxRect.h"
+#include "mozilla/gfx/Point.h"
+#include "mozilla/gfx/Types.h"
+#include "nsColor.h"
+#include "mozilla/ServoStyleConsts.h"
+
+namespace mozilla {
+
+/**
+ * This class helps FilterInstance build its filter graph. It turns a CSS
+ * filter function (e.g. blur(3px)) from the style system into a
+ * FilterPrimitiveDescription connected to the filter graph.
+ */
+class CSSFilterInstance {
+ using sRGBColor = gfx::sRGBColor;
+ using FilterPrimitiveDescription = gfx::FilterPrimitiveDescription;
+ using IntPoint = gfx::IntPoint;
+ using Size = gfx::Size;
+
+ public:
+ /**
+ * @param aFilter The CSS filter from the style system. This class stores
+ * aFilter by reference, so callers should avoid modifying or deleting
+ * aFilter during the lifetime of CSSFilterInstance.
+ * @param aShadowFallbackColor The color that should be used for
+ * drop-shadow() filters that don't specify a shadow color.
+ * @param aTargetBoundsInFilterSpace The pre-filter ink overflow rect of
+ * the frame being filtered, in filter space.
+ * @param aFrameSpaceInCSSPxToFilterSpaceTransform The transformation from
+ * the filtered element's frame space in CSS pixels to filter space.
+ */
+ CSSFilterInstance(const StyleFilter& aFilter, nscolor aShadowFallbackColor,
+ const nsIntRect& aTargetBoundsInFilterSpace,
+ const gfxMatrix& aFrameSpaceInCSSPxToFilterSpaceTransform);
+
+ /**
+ * Creates at least one new FilterPrimitiveDescription based on the filter
+ * from the style system. Appends the new FilterPrimitiveDescription(s) to the
+ * aPrimitiveDescrs list.
+ * aInputIsTainted describes whether the input to this filter is tainted, i.e.
+ * whether it contains security-sensitive content. This is needed to propagate
+ * taintedness to the FilterPrimitive that take tainted inputs. Something
+ * being tainted means that it contains security sensitive content. The input
+ * to this filter is the previous filter's output, i.e. the last element in
+ * aPrimitiveDescrs, or the SourceGraphic input if this is the first filter in
+ * the filter chain.
+ */
+ nsresult BuildPrimitives(
+ nsTArray<FilterPrimitiveDescription>& aPrimitiveDescrs,
+ bool aInputIsTainted);
+
+ private:
+ /**
+ * Returns a new FilterPrimitiveDescription with its basic properties set up.
+ * See the comment above BuildPrimitives for the meaning of aInputIsTainted.
+ */
+ FilterPrimitiveDescription CreatePrimitiveDescription(
+ const nsTArray<FilterPrimitiveDescription>& aPrimitiveDescrs,
+ bool aInputIsTainted);
+
+ /**
+ * Sets aDescr's attributes using the style info in mFilter.
+ */
+ nsresult SetAttributesForBlur(FilterPrimitiveDescription& aDescr);
+ nsresult SetAttributesForBrightness(FilterPrimitiveDescription& aDescr);
+ nsresult SetAttributesForContrast(FilterPrimitiveDescription& aDescr);
+ nsresult SetAttributesForDropShadow(FilterPrimitiveDescription& aDescr);
+ nsresult SetAttributesForGrayscale(FilterPrimitiveDescription& aDescr);
+ nsresult SetAttributesForHueRotate(FilterPrimitiveDescription& aDescr);
+ nsresult SetAttributesForInvert(FilterPrimitiveDescription& aDescr);
+ nsresult SetAttributesForOpacity(FilterPrimitiveDescription& aDescr);
+ nsresult SetAttributesForSaturate(FilterPrimitiveDescription& aDescr);
+ nsresult SetAttributesForSepia(FilterPrimitiveDescription& aDescr);
+
+ /**
+ * Returns the index of the last result in the aPrimitiveDescrs, which we'll
+ * use as the input to this CSS filter.
+ */
+ int32_t GetLastResultIndex(
+ const nsTArray<FilterPrimitiveDescription>& aPrimitiveDescrs);
+
+ /**
+ * Sets aDescr's filter region and primitive subregion to appropriate values
+ * based on this CSS filter's input and its attributes. For example, a CSS
+ * blur filter will have bounds equal to its input bounds, inflated by the
+ * blur extents.
+ */
+ void SetBounds(FilterPrimitiveDescription& aDescr,
+ const nsTArray<FilterPrimitiveDescription>& aPrimitiveDescrs);
+
+ /**
+ * Converts an nscolor to a Color, suitable for use as a
+ * FilterPrimitiveDescription attribute.
+ */
+ sRGBColor ToAttributeColor(nscolor aColor);
+
+ /**
+ * Converts a blur radius in frame space to filter space.
+ */
+ Size BlurRadiusToFilterSpace(nscoord aRadiusInFrameSpace);
+
+ /**
+ * Converts a point defined by a pair of nscoord x, y coordinates from frame
+ * space to filter space.
+ */
+ IntPoint OffsetToFilterSpace(nscoord aXOffsetInFrameSpace,
+ nscoord aYOffsetInFrameSpace);
+
+ /**
+ * The CSS filter originally from the style system.
+ */
+ const StyleFilter& mFilter;
+
+ /**
+ * The color that should be used for drop-shadow() filters that don't
+ * specify a shadow color.
+ */
+ nscolor mShadowFallbackColor;
+
+ /**
+ * The pre-filter overflow rect of the frame being filtered, in filter space.
+ * Used for input bounds if this CSS filter is the first in the filter chain.
+ */
+ nsIntRect mTargetBoundsInFilterSpace;
+
+ /**
+ * The transformation from the filtered element's frame space in CSS pixels to
+ * filter space. Used to transform style values to filter space.
+ */
+ gfxMatrix mFrameSpaceInCSSPxToFilterSpaceTransform;
+};
+
+} // namespace mozilla
+
+#endif // LAYOUT_SVG_CSSFILTERINSTANCE_H_