2017-10-27 20:33:53 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2014-08-06 21:48:47 +04:00
|
|
|
/* 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/. */
|
|
|
|
|
|
|
|
// Main header first:
|
2020-06-30 21:11:50 +03:00
|
|
|
#include "CSSFilterInstance.h"
|
2014-08-06 21:48:47 +04:00
|
|
|
|
|
|
|
// Keep others in (case-insensitive) order:
|
2020-07-21 11:39:35 +03:00
|
|
|
#include "FilterDescription.h"
|
2014-08-06 21:48:47 +04:00
|
|
|
#include "gfx2DGlue.h"
|
|
|
|
#include "gfxUtils.h"
|
2014-08-14 22:29:56 +04:00
|
|
|
#include "nsIFrame.h"
|
2014-08-06 21:48:47 +04:00
|
|
|
#include "nsStyleStruct.h"
|
|
|
|
#include "nsTArray.h"
|
|
|
|
|
|
|
|
using namespace mozilla::gfx;
|
|
|
|
|
2020-06-30 21:11:50 +03:00
|
|
|
namespace mozilla {
|
|
|
|
|
2014-08-21 21:17:09 +04:00
|
|
|
static float ClampFactor(float aFactor) {
|
|
|
|
if (aFactor > 1) {
|
|
|
|
return 1;
|
2019-04-20 13:26:19 +03:00
|
|
|
}
|
|
|
|
if (aFactor < 0) {
|
2018-06-18 08:43:11 +03:00
|
|
|
MOZ_ASSERT_UNREACHABLE("A negative value should not have been parsed.");
|
2014-08-21 21:17:09 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return aFactor;
|
|
|
|
}
|
|
|
|
|
2020-06-30 21:11:50 +03:00
|
|
|
CSSFilterInstance::CSSFilterInstance(
|
2019-05-27 15:37:37 +03:00
|
|
|
const StyleFilter& aFilter, nscolor aShadowFallbackColor,
|
2015-05-28 22:51:58 +03:00
|
|
|
const nsIntRect& aTargetBoundsInFilterSpace,
|
2014-08-06 21:48:47 +04:00
|
|
|
const gfxMatrix& aFrameSpaceInCSSPxToFilterSpaceTransform)
|
|
|
|
: mFilter(aFilter),
|
2014-09-15 14:12:51 +04:00
|
|
|
mShadowFallbackColor(aShadowFallbackColor),
|
2015-05-28 22:51:58 +03:00
|
|
|
mTargetBoundsInFilterSpace(aTargetBoundsInFilterSpace),
|
2014-08-06 21:48:47 +04:00
|
|
|
mFrameSpaceInCSSPxToFilterSpaceTransform(
|
|
|
|
aFrameSpaceInCSSPxToFilterSpaceTransform) {}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2020-06-30 21:11:50 +03:00
|
|
|
nsresult CSSFilterInstance::BuildPrimitives(
|
2016-10-19 18:32:02 +03:00
|
|
|
nsTArray<FilterPrimitiveDescription>& aPrimitiveDescrs,
|
|
|
|
bool aInputIsTainted) {
|
2018-09-19 20:18:44 +03:00
|
|
|
FilterPrimitiveDescription descr =
|
|
|
|
CreatePrimitiveDescription(aPrimitiveDescrs, aInputIsTainted);
|
2014-08-06 21:48:47 +04:00
|
|
|
nsresult result;
|
2019-05-27 15:37:37 +03:00
|
|
|
switch (mFilter.tag) {
|
|
|
|
case StyleFilter::Tag::Blur:
|
2014-08-06 21:48:47 +04:00
|
|
|
result = SetAttributesForBlur(descr);
|
|
|
|
break;
|
2019-05-27 15:37:37 +03:00
|
|
|
case StyleFilter::Tag::Brightness:
|
2014-08-25 23:23:20 +04:00
|
|
|
result = SetAttributesForBrightness(descr);
|
|
|
|
break;
|
2019-05-27 15:37:37 +03:00
|
|
|
case StyleFilter::Tag::Contrast:
|
2014-08-25 23:23:21 +04:00
|
|
|
result = SetAttributesForContrast(descr);
|
|
|
|
break;
|
2019-05-27 15:37:37 +03:00
|
|
|
case StyleFilter::Tag::DropShadow:
|
2014-08-14 22:29:56 +04:00
|
|
|
result = SetAttributesForDropShadow(descr);
|
|
|
|
break;
|
2019-05-27 15:37:37 +03:00
|
|
|
case StyleFilter::Tag::Grayscale:
|
2014-08-21 21:17:09 +04:00
|
|
|
result = SetAttributesForGrayscale(descr);
|
|
|
|
break;
|
2019-05-27 15:37:37 +03:00
|
|
|
case StyleFilter::Tag::HueRotate:
|
2014-08-21 02:46:59 +04:00
|
|
|
result = SetAttributesForHueRotate(descr);
|
|
|
|
break;
|
2019-05-27 15:37:37 +03:00
|
|
|
case StyleFilter::Tag::Invert:
|
2014-08-25 23:23:19 +04:00
|
|
|
result = SetAttributesForInvert(descr);
|
|
|
|
break;
|
2019-05-27 15:37:37 +03:00
|
|
|
case StyleFilter::Tag::Opacity:
|
2014-08-25 23:23:22 +04:00
|
|
|
result = SetAttributesForOpacity(descr);
|
|
|
|
break;
|
2019-05-27 15:37:37 +03:00
|
|
|
case StyleFilter::Tag::Saturate:
|
2014-08-21 04:52:28 +04:00
|
|
|
result = SetAttributesForSaturate(descr);
|
|
|
|
break;
|
2019-05-27 15:37:37 +03:00
|
|
|
case StyleFilter::Tag::Sepia:
|
2014-08-21 21:17:12 +04:00
|
|
|
result = SetAttributesForSepia(descr);
|
|
|
|
break;
|
2014-08-06 21:48:47 +04:00
|
|
|
default:
|
2018-06-18 08:43:11 +03:00
|
|
|
MOZ_ASSERT_UNREACHABLE("not a valid CSS filter type");
|
2014-08-06 21:48:47 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NS_FAILED(result)) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Compute the primitive's bounds now that we've determined its attributes.
|
|
|
|
// Some attributes like blur radius can influence the bounds.
|
|
|
|
SetBounds(descr, aPrimitiveDescrs);
|
|
|
|
|
|
|
|
// Add this primitive to the filter chain.
|
2018-09-19 20:17:43 +03:00
|
|
|
aPrimitiveDescrs.AppendElement(std::move(descr));
|
2014-08-06 21:48:47 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2020-06-30 21:11:50 +03:00
|
|
|
FilterPrimitiveDescription CSSFilterInstance::CreatePrimitiveDescription(
|
2018-09-19 20:18:44 +03:00
|
|
|
const nsTArray<FilterPrimitiveDescription>& aPrimitiveDescrs,
|
2016-10-19 18:32:02 +03:00
|
|
|
bool aInputIsTainted) {
|
2018-09-19 20:18:44 +03:00
|
|
|
FilterPrimitiveDescription descr;
|
2014-08-06 21:48:47 +04:00
|
|
|
int32_t inputIndex = GetLastResultIndex(aPrimitiveDescrs);
|
|
|
|
descr.SetInputPrimitive(0, inputIndex);
|
2016-10-19 18:32:02 +03:00
|
|
|
descr.SetIsTainted(inputIndex < 0 ? aInputIsTainted
|
|
|
|
: aPrimitiveDescrs[inputIndex].IsTainted());
|
2014-08-06 21:48:47 +04:00
|
|
|
descr.SetInputColorSpace(0, ColorSpace::SRGB);
|
|
|
|
descr.SetOutputColorSpace(ColorSpace::SRGB);
|
|
|
|
return descr;
|
|
|
|
}
|
|
|
|
|
2020-06-30 21:11:50 +03:00
|
|
|
nsresult CSSFilterInstance::SetAttributesForBlur(
|
2014-08-06 21:48:47 +04:00
|
|
|
FilterPrimitiveDescription& aDescr) {
|
2019-05-27 15:37:37 +03:00
|
|
|
const Length& radiusInFrameSpace = mFilter.AsBlur();
|
2014-08-14 22:29:56 +04:00
|
|
|
Size radiusInFilterSpace =
|
2019-05-27 15:37:37 +03:00
|
|
|
BlurRadiusToFilterSpace(radiusInFrameSpace.ToAppUnits());
|
2018-09-19 20:18:16 +03:00
|
|
|
GaussianBlurAttributes atts;
|
|
|
|
atts.mStdDeviation = radiusInFilterSpace;
|
|
|
|
aDescr.Attributes() = AsVariant(atts);
|
2014-08-14 22:29:56 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2020-06-30 21:11:50 +03:00
|
|
|
nsresult CSSFilterInstance::SetAttributesForBrightness(
|
2014-08-25 23:23:20 +04:00
|
|
|
FilterPrimitiveDescription& aDescr) {
|
2019-05-27 15:37:37 +03:00
|
|
|
float value = mFilter.AsBrightness();
|
2018-09-19 20:18:16 +03:00
|
|
|
float intercept = 0.0f;
|
|
|
|
ComponentTransferAttributes atts;
|
2014-08-25 23:23:20 +04:00
|
|
|
|
|
|
|
// Set transfer functions for RGB.
|
2018-09-19 20:18:16 +03:00
|
|
|
atts.mTypes[kChannelROrRGB] = (uint8_t)SVG_FECOMPONENTTRANSFER_TYPE_LINEAR;
|
2020-05-08 02:39:56 +03:00
|
|
|
atts.mTypes[kChannelG] = (uint8_t)SVG_FECOMPONENTTRANSFER_SAME_AS_R;
|
|
|
|
atts.mTypes[kChannelB] = (uint8_t)SVG_FECOMPONENTTRANSFER_SAME_AS_R;
|
2018-09-19 20:18:16 +03:00
|
|
|
float slopeIntercept[2];
|
|
|
|
slopeIntercept[kComponentTransferSlopeIndex] = value;
|
|
|
|
slopeIntercept[kComponentTransferInterceptIndex] = intercept;
|
|
|
|
atts.mValues[kChannelROrRGB].AppendElements(slopeIntercept, 2);
|
|
|
|
|
|
|
|
atts.mTypes[kChannelA] = (uint8_t)SVG_FECOMPONENTTRANSFER_TYPE_IDENTITY;
|
|
|
|
|
|
|
|
aDescr.Attributes() = AsVariant(std::move(atts));
|
2014-08-25 23:23:20 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2020-06-30 21:11:50 +03:00
|
|
|
nsresult CSSFilterInstance::SetAttributesForContrast(
|
2014-08-25 23:23:21 +04:00
|
|
|
FilterPrimitiveDescription& aDescr) {
|
2019-05-27 15:37:37 +03:00
|
|
|
float value = mFilter.AsContrast();
|
2014-08-25 23:23:21 +04:00
|
|
|
float intercept = -(0.5 * value) + 0.5;
|
2018-09-19 20:18:16 +03:00
|
|
|
ComponentTransferAttributes atts;
|
2014-08-25 23:23:21 +04:00
|
|
|
|
|
|
|
// Set transfer functions for RGB.
|
2018-09-19 20:18:16 +03:00
|
|
|
atts.mTypes[kChannelROrRGB] = (uint8_t)SVG_FECOMPONENTTRANSFER_TYPE_LINEAR;
|
2020-05-08 02:39:56 +03:00
|
|
|
atts.mTypes[kChannelG] = (uint8_t)SVG_FECOMPONENTTRANSFER_SAME_AS_R;
|
|
|
|
atts.mTypes[kChannelB] = (uint8_t)SVG_FECOMPONENTTRANSFER_SAME_AS_R;
|
2018-09-19 20:18:16 +03:00
|
|
|
float slopeIntercept[2];
|
|
|
|
slopeIntercept[kComponentTransferSlopeIndex] = value;
|
|
|
|
slopeIntercept[kComponentTransferInterceptIndex] = intercept;
|
|
|
|
atts.mValues[kChannelROrRGB].AppendElements(slopeIntercept, 2);
|
|
|
|
|
|
|
|
atts.mTypes[kChannelA] = (uint8_t)SVG_FECOMPONENTTRANSFER_TYPE_IDENTITY;
|
|
|
|
|
|
|
|
aDescr.Attributes() = AsVariant(std::move(atts));
|
2014-08-25 23:23:21 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2020-06-30 21:11:50 +03:00
|
|
|
nsresult CSSFilterInstance::SetAttributesForDropShadow(
|
2014-08-14 22:29:56 +04:00
|
|
|
FilterPrimitiveDescription& aDescr) {
|
2019-05-27 15:37:37 +03:00
|
|
|
const auto& shadow = mFilter.AsDropShadow();
|
2014-08-14 22:29:56 +04:00
|
|
|
|
2018-09-19 20:18:16 +03:00
|
|
|
DropShadowAttributes atts;
|
2014-08-14 22:29:56 +04:00
|
|
|
|
|
|
|
// Set drop shadow blur radius.
|
2019-05-17 02:04:32 +03:00
|
|
|
Size radiusInFilterSpace = BlurRadiusToFilterSpace(shadow.blur.ToAppUnits());
|
2018-09-19 20:18:16 +03:00
|
|
|
atts.mStdDeviation = radiusInFilterSpace;
|
2014-08-14 22:29:56 +04:00
|
|
|
|
|
|
|
// Set offset.
|
2019-05-17 02:04:32 +03:00
|
|
|
IntPoint offsetInFilterSpace = OffsetToFilterSpace(
|
|
|
|
shadow.horizontal.ToAppUnits(), shadow.vertical.ToAppUnits());
|
2018-09-19 20:18:16 +03:00
|
|
|
atts.mOffset = offsetInFilterSpace;
|
2014-08-14 22:29:56 +04:00
|
|
|
|
|
|
|
// Set color. If unspecified, use the CSS color property.
|
2019-05-17 02:04:32 +03:00
|
|
|
nscolor shadowColor = shadow.color.CalcColor(mShadowFallbackColor);
|
2018-09-19 20:18:16 +03:00
|
|
|
atts.mColor = ToAttributeColor(shadowColor);
|
2014-08-14 22:29:56 +04:00
|
|
|
|
2018-09-19 20:18:16 +03:00
|
|
|
aDescr.Attributes() = AsVariant(std::move(atts));
|
2014-08-14 22:29:56 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2020-06-30 21:11:50 +03:00
|
|
|
nsresult CSSFilterInstance::SetAttributesForGrayscale(
|
2014-08-21 21:17:09 +04:00
|
|
|
FilterPrimitiveDescription& aDescr) {
|
2018-09-19 20:18:16 +03:00
|
|
|
ColorMatrixAttributes atts;
|
2014-08-21 21:17:09 +04:00
|
|
|
// Set color matrix type.
|
2018-09-19 20:18:16 +03:00
|
|
|
atts.mType = (uint32_t)SVG_FECOLORMATRIX_TYPE_SATURATE;
|
2014-08-21 21:17:09 +04:00
|
|
|
|
|
|
|
// Set color matrix values.
|
2019-05-27 15:37:37 +03:00
|
|
|
float value = 1 - ClampFactor(mFilter.AsGrayscale());
|
2018-09-19 20:18:16 +03:00
|
|
|
atts.mValues.AppendElements(&value, 1);
|
2014-08-21 21:17:09 +04:00
|
|
|
|
2018-09-19 20:18:16 +03:00
|
|
|
aDescr.Attributes() = AsVariant(std::move(atts));
|
2014-08-21 21:17:09 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2020-06-30 21:11:50 +03:00
|
|
|
nsresult CSSFilterInstance::SetAttributesForHueRotate(
|
2014-08-21 02:46:59 +04:00
|
|
|
FilterPrimitiveDescription& aDescr) {
|
2018-09-19 20:18:16 +03:00
|
|
|
ColorMatrixAttributes atts;
|
2014-08-21 02:46:59 +04:00
|
|
|
// Set color matrix type.
|
2018-09-19 20:18:16 +03:00
|
|
|
atts.mType = (uint32_t)SVG_FECOLORMATRIX_TYPE_HUE_ROTATE;
|
2014-08-21 02:46:59 +04:00
|
|
|
|
|
|
|
// Set color matrix values.
|
2019-05-27 15:37:37 +03:00
|
|
|
float value = mFilter.AsHueRotate().ToDegrees();
|
2018-09-19 20:18:16 +03:00
|
|
|
atts.mValues.AppendElements(&value, 1);
|
2014-08-21 04:52:28 +04:00
|
|
|
|
2018-09-19 20:18:16 +03:00
|
|
|
aDescr.Attributes() = AsVariant(std::move(atts));
|
2014-08-21 04:52:28 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2020-06-30 21:11:50 +03:00
|
|
|
nsresult CSSFilterInstance::SetAttributesForInvert(
|
2014-08-25 23:23:19 +04:00
|
|
|
FilterPrimitiveDescription& aDescr) {
|
2018-09-19 20:18:16 +03:00
|
|
|
ComponentTransferAttributes atts;
|
2019-05-27 15:37:37 +03:00
|
|
|
float value = ClampFactor(mFilter.AsInvert());
|
2014-08-25 23:23:19 +04:00
|
|
|
|
|
|
|
// Set transfer functions for RGB.
|
|
|
|
float invertTableValues[2];
|
|
|
|
invertTableValues[0] = value;
|
|
|
|
invertTableValues[1] = 1 - value;
|
|
|
|
|
2018-09-19 20:18:16 +03:00
|
|
|
// Set transfer functions for RGB.
|
|
|
|
atts.mTypes[kChannelROrRGB] = (uint8_t)SVG_FECOMPONENTTRANSFER_TYPE_TABLE;
|
2020-05-08 02:39:56 +03:00
|
|
|
atts.mTypes[kChannelG] = (uint8_t)SVG_FECOMPONENTTRANSFER_SAME_AS_R;
|
|
|
|
atts.mTypes[kChannelB] = (uint8_t)SVG_FECOMPONENTTRANSFER_SAME_AS_R;
|
2018-09-19 20:18:16 +03:00
|
|
|
atts.mValues[kChannelROrRGB].AppendElements(invertTableValues, 2);
|
|
|
|
|
|
|
|
atts.mTypes[kChannelA] = (uint8_t)SVG_FECOMPONENTTRANSFER_TYPE_IDENTITY;
|
2014-08-25 23:23:19 +04:00
|
|
|
|
2018-09-19 20:18:16 +03:00
|
|
|
aDescr.Attributes() = AsVariant(std::move(atts));
|
2014-08-25 23:23:19 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2020-06-30 21:11:50 +03:00
|
|
|
nsresult CSSFilterInstance::SetAttributesForOpacity(
|
2014-08-25 23:23:22 +04:00
|
|
|
FilterPrimitiveDescription& aDescr) {
|
2018-09-19 20:18:16 +03:00
|
|
|
OpacityAttributes atts;
|
2019-05-27 15:37:37 +03:00
|
|
|
float value = ClampFactor(mFilter.AsOpacity());
|
2014-08-25 23:23:22 +04:00
|
|
|
|
2018-09-19 20:18:16 +03:00
|
|
|
atts.mOpacity = value;
|
|
|
|
aDescr.Attributes() = AsVariant(std::move(atts));
|
2014-08-25 23:23:22 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2020-06-30 21:11:50 +03:00
|
|
|
nsresult CSSFilterInstance::SetAttributesForSaturate(
|
2014-08-21 04:52:28 +04:00
|
|
|
FilterPrimitiveDescription& aDescr) {
|
2018-09-19 20:18:16 +03:00
|
|
|
ColorMatrixAttributes atts;
|
2014-08-21 04:52:28 +04:00
|
|
|
// Set color matrix type.
|
2018-09-19 20:18:16 +03:00
|
|
|
atts.mType = (uint32_t)SVG_FECOLORMATRIX_TYPE_SATURATE;
|
2014-08-21 04:52:28 +04:00
|
|
|
|
|
|
|
// Set color matrix values.
|
2019-05-27 15:37:37 +03:00
|
|
|
float value = mFilter.AsSaturate();
|
2018-09-19 20:18:16 +03:00
|
|
|
atts.mValues.AppendElements(&value, 1);
|
2014-08-21 21:17:12 +04:00
|
|
|
|
2018-09-19 20:18:16 +03:00
|
|
|
aDescr.Attributes() = AsVariant(std::move(atts));
|
2014-08-21 21:17:12 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2020-06-30 21:11:50 +03:00
|
|
|
nsresult CSSFilterInstance::SetAttributesForSepia(
|
2014-08-21 21:17:12 +04:00
|
|
|
FilterPrimitiveDescription& aDescr) {
|
2018-09-19 20:18:16 +03:00
|
|
|
ColorMatrixAttributes atts;
|
2014-08-21 21:17:12 +04:00
|
|
|
// Set color matrix type.
|
2018-09-19 20:18:16 +03:00
|
|
|
atts.mType = (uint32_t)SVG_FECOLORMATRIX_TYPE_SEPIA;
|
2014-08-21 21:17:12 +04:00
|
|
|
|
|
|
|
// Set color matrix values.
|
2019-05-27 15:37:37 +03:00
|
|
|
float value = ClampFactor(mFilter.AsSepia());
|
2018-09-19 20:18:16 +03:00
|
|
|
atts.mValues.AppendElements(&value, 1);
|
2014-08-21 02:46:59 +04:00
|
|
|
|
2018-09-19 20:18:16 +03:00
|
|
|
aDescr.Attributes() = AsVariant(std::move(atts));
|
2014-08-21 02:46:59 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2020-06-30 21:11:50 +03:00
|
|
|
Size CSSFilterInstance::BlurRadiusToFilterSpace(nscoord aRadiusInFrameSpace) {
|
2014-08-06 21:48:47 +04:00
|
|
|
float radiusInFrameSpaceInCSSPx =
|
2014-08-14 22:29:56 +04:00
|
|
|
nsPresContext::AppUnitsToFloatCSSPixels(aRadiusInFrameSpace);
|
2014-08-06 21:48:47 +04:00
|
|
|
|
|
|
|
// Convert the radius to filter space.
|
2015-11-09 07:23:54 +03:00
|
|
|
Size radiusInFilterSpace(radiusInFrameSpaceInCSSPx,
|
|
|
|
radiusInFrameSpaceInCSSPx);
|
2014-08-06 21:48:47 +04:00
|
|
|
gfxSize frameSpaceInCSSPxToFilterSpaceScale =
|
2020-11-18 21:53:01 +03:00
|
|
|
mFrameSpaceInCSSPxToFilterSpaceTransform.ScaleFactors();
|
2014-08-06 21:48:47 +04:00
|
|
|
radiusInFilterSpace.Scale(frameSpaceInCSSPxToFilterSpaceScale.width,
|
|
|
|
frameSpaceInCSSPxToFilterSpaceScale.height);
|
|
|
|
|
|
|
|
// Check the radius limits.
|
|
|
|
if (radiusInFilterSpace.width < 0 || radiusInFilterSpace.height < 0) {
|
2018-06-18 08:43:11 +03:00
|
|
|
MOZ_ASSERT_UNREACHABLE(
|
|
|
|
"we shouldn't have parsed a negative radius in the "
|
|
|
|
"style");
|
2014-08-14 22:29:56 +04:00
|
|
|
return Size();
|
2014-08-06 21:48:47 +04:00
|
|
|
}
|
2018-06-18 08:43:11 +03:00
|
|
|
|
2015-11-09 07:23:54 +03:00
|
|
|
Float maxStdDeviation = (Float)kMaxStdDeviation;
|
2014-08-06 21:48:47 +04:00
|
|
|
radiusInFilterSpace.width =
|
|
|
|
std::min(radiusInFilterSpace.width, maxStdDeviation);
|
|
|
|
radiusInFilterSpace.height =
|
|
|
|
std::min(radiusInFilterSpace.height, maxStdDeviation);
|
|
|
|
|
2015-11-09 07:23:54 +03:00
|
|
|
return radiusInFilterSpace;
|
2014-08-14 22:29:56 +04:00
|
|
|
}
|
|
|
|
|
2020-06-30 21:11:50 +03:00
|
|
|
IntPoint CSSFilterInstance::OffsetToFilterSpace(nscoord aXOffsetInFrameSpace,
|
|
|
|
nscoord aYOffsetInFrameSpace) {
|
2014-08-14 22:29:56 +04:00
|
|
|
gfxPoint offsetInFilterSpace(
|
|
|
|
nsPresContext::AppUnitsToFloatCSSPixels(aXOffsetInFrameSpace),
|
|
|
|
nsPresContext::AppUnitsToFloatCSSPixels(aYOffsetInFrameSpace));
|
|
|
|
|
|
|
|
// Convert the radius to filter space.
|
|
|
|
gfxSize frameSpaceInCSSPxToFilterSpaceScale =
|
2020-11-18 21:53:01 +03:00
|
|
|
mFrameSpaceInCSSPxToFilterSpaceTransform.ScaleFactors();
|
2014-08-14 22:29:56 +04:00
|
|
|
offsetInFilterSpace.x *= frameSpaceInCSSPxToFilterSpaceScale.width;
|
|
|
|
offsetInFilterSpace.y *= frameSpaceInCSSPxToFilterSpaceScale.height;
|
|
|
|
|
|
|
|
return IntPoint(int32_t(offsetInFilterSpace.x),
|
|
|
|
int32_t(offsetInFilterSpace.y));
|
|
|
|
}
|
|
|
|
|
2020-06-30 21:11:50 +03:00
|
|
|
sRGBColor CSSFilterInstance::ToAttributeColor(nscolor aColor) {
|
2020-03-09 17:16:17 +03:00
|
|
|
return sRGBColor(NS_GET_R(aColor) / 255.0, NS_GET_G(aColor) / 255.0,
|
|
|
|
NS_GET_B(aColor) / 255.0, NS_GET_A(aColor) / 255.0);
|
2014-08-06 21:48:47 +04:00
|
|
|
}
|
|
|
|
|
2020-06-30 21:11:50 +03:00
|
|
|
int32_t CSSFilterInstance::GetLastResultIndex(
|
2014-08-06 21:48:47 +04:00
|
|
|
const nsTArray<FilterPrimitiveDescription>& aPrimitiveDescrs) {
|
|
|
|
uint32_t numPrimitiveDescrs = aPrimitiveDescrs.Length();
|
|
|
|
return !numPrimitiveDescrs
|
|
|
|
? FilterPrimitiveDescription::kPrimitiveIndexSourceGraphic
|
|
|
|
: numPrimitiveDescrs - 1;
|
|
|
|
}
|
|
|
|
|
2020-06-30 21:11:50 +03:00
|
|
|
void CSSFilterInstance::SetBounds(
|
2014-08-06 21:48:47 +04:00
|
|
|
FilterPrimitiveDescription& aDescr,
|
2014-09-04 21:31:02 +04:00
|
|
|
const nsTArray<FilterPrimitiveDescription>& aPrimitiveDescrs) {
|
2014-08-06 21:48:47 +04:00
|
|
|
int32_t inputIndex = GetLastResultIndex(aPrimitiveDescrs);
|
|
|
|
nsIntRect inputBounds =
|
2015-05-28 22:51:58 +03:00
|
|
|
(inputIndex < 0) ? mTargetBoundsInFilterSpace
|
|
|
|
: aPrimitiveDescrs[inputIndex].PrimitiveSubregion();
|
2014-08-06 21:48:47 +04:00
|
|
|
|
|
|
|
nsTArray<nsIntRegion> inputExtents;
|
|
|
|
inputExtents.AppendElement(inputBounds);
|
|
|
|
|
|
|
|
nsIntRegion outputExtents =
|
|
|
|
FilterSupport::PostFilterExtentsForPrimitive(aDescr, inputExtents);
|
2015-04-21 18:22:30 +03:00
|
|
|
IntRect outputBounds = outputExtents.GetBounds();
|
2014-08-06 21:48:47 +04:00
|
|
|
|
|
|
|
aDescr.SetPrimitiveSubregion(outputBounds);
|
|
|
|
aDescr.SetFilterSpaceBounds(outputBounds);
|
|
|
|
}
|
2020-06-30 21:11:50 +03:00
|
|
|
|
|
|
|
} // namespace mozilla
|