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:
|
|
|
|
#include "nsCSSFilterInstance.h"
|
|
|
|
|
|
|
|
// Keep others in (case-insensitive) order:
|
|
|
|
#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;
|
|
|
|
using namespace mozilla::gfx;
|
|
|
|
|
2014-08-21 21:17:09 +04:00
|
|
|
static float ClampFactor(float aFactor)
|
|
|
|
{
|
|
|
|
if (aFactor > 1) {
|
|
|
|
return 1;
|
|
|
|
} else if (aFactor < 0) {
|
|
|
|
NS_NOTREACHED("A negative value should not have been parsed.");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return aFactor;
|
|
|
|
}
|
|
|
|
|
2014-08-06 21:48:47 +04:00
|
|
|
nsCSSFilterInstance::nsCSSFilterInstance(const nsStyleFilter& aFilter,
|
2014-09-15 14:12:51 +04:00
|
|
|
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)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2016-10-19 18:32:02 +03:00
|
|
|
nsCSSFilterInstance::BuildPrimitives(nsTArray<FilterPrimitiveDescription>& aPrimitiveDescrs,
|
|
|
|
bool aInputIsTainted)
|
2014-08-06 21:48:47 +04:00
|
|
|
{
|
|
|
|
FilterPrimitiveDescription descr;
|
|
|
|
nsresult result;
|
|
|
|
|
|
|
|
switch(mFilter.GetType()) {
|
|
|
|
case NS_STYLE_FILTER_BLUR:
|
2016-10-19 18:32:02 +03:00
|
|
|
descr = CreatePrimitiveDescription(PrimitiveType::GaussianBlur,
|
|
|
|
aPrimitiveDescrs,
|
|
|
|
aInputIsTainted);
|
2014-08-06 21:48:47 +04:00
|
|
|
result = SetAttributesForBlur(descr);
|
|
|
|
break;
|
|
|
|
case NS_STYLE_FILTER_BRIGHTNESS:
|
2016-10-19 18:32:02 +03:00
|
|
|
descr = CreatePrimitiveDescription(PrimitiveType::ComponentTransfer,
|
|
|
|
aPrimitiveDescrs,
|
|
|
|
aInputIsTainted);
|
2014-08-25 23:23:20 +04:00
|
|
|
result = SetAttributesForBrightness(descr);
|
|
|
|
break;
|
2014-08-06 21:48:47 +04:00
|
|
|
case NS_STYLE_FILTER_CONTRAST:
|
2016-10-19 18:32:02 +03:00
|
|
|
descr = CreatePrimitiveDescription(PrimitiveType::ComponentTransfer,
|
|
|
|
aPrimitiveDescrs,
|
|
|
|
aInputIsTainted);
|
2014-08-25 23:23:21 +04:00
|
|
|
result = SetAttributesForContrast(descr);
|
|
|
|
break;
|
2014-08-06 21:48:47 +04:00
|
|
|
case NS_STYLE_FILTER_DROP_SHADOW:
|
2016-10-19 18:32:02 +03:00
|
|
|
descr = CreatePrimitiveDescription(PrimitiveType::DropShadow,
|
|
|
|
aPrimitiveDescrs,
|
|
|
|
aInputIsTainted);
|
2014-08-14 22:29:56 +04:00
|
|
|
result = SetAttributesForDropShadow(descr);
|
|
|
|
break;
|
2014-08-06 21:48:47 +04:00
|
|
|
case NS_STYLE_FILTER_GRAYSCALE:
|
2016-10-19 18:32:02 +03:00
|
|
|
descr = CreatePrimitiveDescription(PrimitiveType::ColorMatrix,
|
|
|
|
aPrimitiveDescrs,
|
|
|
|
aInputIsTainted);
|
2014-08-21 21:17:09 +04:00
|
|
|
result = SetAttributesForGrayscale(descr);
|
|
|
|
break;
|
2014-08-06 21:48:47 +04:00
|
|
|
case NS_STYLE_FILTER_HUE_ROTATE:
|
2016-10-19 18:32:02 +03:00
|
|
|
descr = CreatePrimitiveDescription(PrimitiveType::ColorMatrix,
|
|
|
|
aPrimitiveDescrs,
|
|
|
|
aInputIsTainted);
|
2014-08-21 02:46:59 +04:00
|
|
|
result = SetAttributesForHueRotate(descr);
|
|
|
|
break;
|
2014-08-06 21:48:47 +04:00
|
|
|
case NS_STYLE_FILTER_INVERT:
|
2016-10-19 18:32:02 +03:00
|
|
|
descr = CreatePrimitiveDescription(PrimitiveType::ComponentTransfer,
|
|
|
|
aPrimitiveDescrs,
|
|
|
|
aInputIsTainted);
|
2014-08-25 23:23:19 +04:00
|
|
|
result = SetAttributesForInvert(descr);
|
|
|
|
break;
|
2014-08-06 21:48:47 +04:00
|
|
|
case NS_STYLE_FILTER_OPACITY:
|
2016-10-19 18:32:02 +03:00
|
|
|
descr = CreatePrimitiveDescription(PrimitiveType::ComponentTransfer,
|
|
|
|
aPrimitiveDescrs,
|
|
|
|
aInputIsTainted);
|
2014-08-25 23:23:22 +04:00
|
|
|
result = SetAttributesForOpacity(descr);
|
|
|
|
break;
|
2014-08-06 21:48:47 +04:00
|
|
|
case NS_STYLE_FILTER_SATURATE:
|
2016-10-19 18:32:02 +03:00
|
|
|
descr = CreatePrimitiveDescription(PrimitiveType::ColorMatrix,
|
|
|
|
aPrimitiveDescrs,
|
|
|
|
aInputIsTainted);
|
2014-08-21 04:52:28 +04:00
|
|
|
result = SetAttributesForSaturate(descr);
|
|
|
|
break;
|
2014-08-06 21:48:47 +04:00
|
|
|
case NS_STYLE_FILTER_SEPIA:
|
2016-10-19 18:32:02 +03:00
|
|
|
descr = CreatePrimitiveDescription(PrimitiveType::ColorMatrix,
|
|
|
|
aPrimitiveDescrs,
|
|
|
|
aInputIsTainted);
|
2014-08-21 21:17:12 +04:00
|
|
|
result = SetAttributesForSepia(descr);
|
|
|
|
break;
|
2014-08-06 21:48:47 +04:00
|
|
|
default:
|
|
|
|
NS_NOTREACHED("not a valid CSS filter type");
|
|
|
|
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.
|
|
|
|
aPrimitiveDescrs.AppendElement(descr);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
FilterPrimitiveDescription
|
|
|
|
nsCSSFilterInstance::CreatePrimitiveDescription(PrimitiveType aType,
|
2016-10-19 18:32:02 +03:00
|
|
|
const nsTArray<FilterPrimitiveDescription>& aPrimitiveDescrs,
|
|
|
|
bool aInputIsTainted) {
|
2014-08-06 21:48:47 +04:00
|
|
|
FilterPrimitiveDescription descr(aType);
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsCSSFilterInstance::SetAttributesForBlur(FilterPrimitiveDescription& aDescr)
|
|
|
|
{
|
2014-08-14 22:29:56 +04:00
|
|
|
const nsStyleCoord& radiusInFrameSpace = mFilter.GetFilterParameter();
|
|
|
|
if (radiusInFrameSpace.GetUnit() != eStyleUnit_Coord) {
|
2014-08-06 21:48:47 +04:00
|
|
|
NS_NOTREACHED("unexpected unit");
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2014-08-14 22:29:56 +04:00
|
|
|
Size radiusInFilterSpace = BlurRadiusToFilterSpace(radiusInFrameSpace.GetCoordValue());
|
|
|
|
aDescr.Attributes().Set(eGaussianBlurStdDeviation, radiusInFilterSpace);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-08-25 23:23:20 +04:00
|
|
|
nsresult
|
|
|
|
nsCSSFilterInstance::SetAttributesForBrightness(FilterPrimitiveDescription& aDescr)
|
|
|
|
{
|
|
|
|
const nsStyleCoord& styleValue = mFilter.GetFilterParameter();
|
|
|
|
float value = styleValue.GetFactorOrPercentValue();
|
|
|
|
|
|
|
|
// Set transfer functions for RGB.
|
|
|
|
AttributeMap brightnessAttrs;
|
|
|
|
brightnessAttrs.Set(eComponentTransferFunctionType,
|
|
|
|
(uint32_t)SVG_FECOMPONENTTRANSFER_TYPE_LINEAR);
|
|
|
|
brightnessAttrs.Set(eComponentTransferFunctionSlope, value);
|
|
|
|
brightnessAttrs.Set(eComponentTransferFunctionIntercept, 0.0f);
|
|
|
|
aDescr.Attributes().Set(eComponentTransferFunctionR, brightnessAttrs);
|
|
|
|
aDescr.Attributes().Set(eComponentTransferFunctionG, brightnessAttrs);
|
|
|
|
aDescr.Attributes().Set(eComponentTransferFunctionB, brightnessAttrs);
|
|
|
|
|
|
|
|
// Set identity transfer function for A.
|
|
|
|
AttributeMap identityAttrs;
|
|
|
|
identityAttrs.Set(eComponentTransferFunctionType,
|
|
|
|
(uint32_t)SVG_FECOMPONENTTRANSFER_TYPE_IDENTITY);
|
|
|
|
aDescr.Attributes().Set(eComponentTransferFunctionA, identityAttrs);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-08-25 23:23:21 +04:00
|
|
|
nsresult
|
|
|
|
nsCSSFilterInstance::SetAttributesForContrast(FilterPrimitiveDescription& aDescr)
|
|
|
|
{
|
|
|
|
const nsStyleCoord& styleValue = mFilter.GetFilterParameter();
|
|
|
|
float value = styleValue.GetFactorOrPercentValue();
|
|
|
|
float intercept = -(0.5 * value) + 0.5;
|
|
|
|
|
|
|
|
// Set transfer functions for RGB.
|
|
|
|
AttributeMap contrastAttrs;
|
|
|
|
contrastAttrs.Set(eComponentTransferFunctionType,
|
|
|
|
(uint32_t)SVG_FECOMPONENTTRANSFER_TYPE_LINEAR);
|
|
|
|
contrastAttrs.Set(eComponentTransferFunctionSlope, value);
|
|
|
|
contrastAttrs.Set(eComponentTransferFunctionIntercept, intercept);
|
|
|
|
aDescr.Attributes().Set(eComponentTransferFunctionR, contrastAttrs);
|
|
|
|
aDescr.Attributes().Set(eComponentTransferFunctionG, contrastAttrs);
|
|
|
|
aDescr.Attributes().Set(eComponentTransferFunctionB, contrastAttrs);
|
|
|
|
|
|
|
|
// Set identity transfer function for A.
|
|
|
|
AttributeMap identityAttrs;
|
|
|
|
identityAttrs.Set(eComponentTransferFunctionType,
|
|
|
|
(uint32_t)SVG_FECOMPONENTTRANSFER_TYPE_IDENTITY);
|
|
|
|
aDescr.Attributes().Set(eComponentTransferFunctionA, identityAttrs);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-08-14 22:29:56 +04:00
|
|
|
nsresult
|
|
|
|
nsCSSFilterInstance::SetAttributesForDropShadow(FilterPrimitiveDescription& aDescr)
|
|
|
|
{
|
|
|
|
nsCSSShadowArray* shadows = mFilter.GetDropShadow();
|
|
|
|
if (!shadows || shadows->Length() != 1) {
|
|
|
|
NS_NOTREACHED("Exactly one drop shadow should have been parsed.");
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCSSShadowItem* shadow = shadows->ShadowAt(0);
|
|
|
|
|
|
|
|
// Set drop shadow blur radius.
|
|
|
|
Size radiusInFilterSpace = BlurRadiusToFilterSpace(shadow->mRadius);
|
|
|
|
aDescr.Attributes().Set(eDropShadowStdDeviation, radiusInFilterSpace);
|
|
|
|
|
|
|
|
// Set offset.
|
|
|
|
IntPoint offsetInFilterSpace = OffsetToFilterSpace(shadow->mXOffset, shadow->mYOffset);
|
|
|
|
aDescr.Attributes().Set(eDropShadowOffset, offsetInFilterSpace);
|
|
|
|
|
|
|
|
// Set color. If unspecified, use the CSS color property.
|
2018-06-19 07:18:33 +03:00
|
|
|
nscolor shadowColor = shadow->mColor.CalcColor(mShadowFallbackColor);
|
2014-08-14 22:29:56 +04:00
|
|
|
aDescr.Attributes().Set(eDropShadowColor, ToAttributeColor(shadowColor));
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-08-21 21:17:09 +04:00
|
|
|
nsresult
|
|
|
|
nsCSSFilterInstance::SetAttributesForGrayscale(FilterPrimitiveDescription& aDescr)
|
|
|
|
{
|
|
|
|
// Set color matrix type.
|
|
|
|
aDescr.Attributes().Set(eColorMatrixType, (uint32_t)SVG_FECOLORMATRIX_TYPE_SATURATE);
|
|
|
|
|
|
|
|
// Set color matrix values.
|
|
|
|
const nsStyleCoord& styleValue = mFilter.GetFilterParameter();
|
|
|
|
float value = 1 - ClampFactor(styleValue.GetFactorOrPercentValue());
|
|
|
|
aDescr.Attributes().Set(eColorMatrixValues, &value, 1);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-08-21 02:46:59 +04:00
|
|
|
nsresult
|
|
|
|
nsCSSFilterInstance::SetAttributesForHueRotate(FilterPrimitiveDescription& aDescr)
|
|
|
|
{
|
|
|
|
// Set color matrix type.
|
|
|
|
aDescr.Attributes().Set(eColorMatrixType, (uint32_t)SVG_FECOLORMATRIX_TYPE_HUE_ROTATE);
|
|
|
|
|
|
|
|
// Set color matrix values.
|
|
|
|
const nsStyleCoord& styleValue = mFilter.GetFilterParameter();
|
|
|
|
float value = styleValue.GetAngleValueInDegrees();
|
|
|
|
aDescr.Attributes().Set(eColorMatrixValues, &value, 1);
|
2014-08-21 04:52:28 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-08-25 23:23:19 +04:00
|
|
|
nsresult
|
|
|
|
nsCSSFilterInstance::SetAttributesForInvert(FilterPrimitiveDescription& aDescr)
|
|
|
|
{
|
|
|
|
const nsStyleCoord& styleValue = mFilter.GetFilterParameter();
|
|
|
|
float value = ClampFactor(styleValue.GetFactorOrPercentValue());
|
|
|
|
|
|
|
|
// Set transfer functions for RGB.
|
|
|
|
AttributeMap invertAttrs;
|
|
|
|
float invertTableValues[2];
|
|
|
|
invertTableValues[0] = value;
|
|
|
|
invertTableValues[1] = 1 - value;
|
|
|
|
invertAttrs.Set(eComponentTransferFunctionType,
|
|
|
|
(uint32_t)SVG_FECOMPONENTTRANSFER_TYPE_TABLE);
|
|
|
|
invertAttrs.Set(eComponentTransferFunctionTableValues, invertTableValues, 2);
|
|
|
|
aDescr.Attributes().Set(eComponentTransferFunctionR, invertAttrs);
|
|
|
|
aDescr.Attributes().Set(eComponentTransferFunctionG, invertAttrs);
|
|
|
|
aDescr.Attributes().Set(eComponentTransferFunctionB, invertAttrs);
|
|
|
|
|
|
|
|
// Set identity transfer function for A.
|
|
|
|
AttributeMap identityAttrs;
|
|
|
|
identityAttrs.Set(eComponentTransferFunctionType,
|
|
|
|
(uint32_t)SVG_FECOMPONENTTRANSFER_TYPE_IDENTITY);
|
|
|
|
aDescr.Attributes().Set(eComponentTransferFunctionA, identityAttrs);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-08-25 23:23:22 +04:00
|
|
|
nsresult
|
|
|
|
nsCSSFilterInstance::SetAttributesForOpacity(FilterPrimitiveDescription& aDescr)
|
|
|
|
{
|
|
|
|
const nsStyleCoord& styleValue = mFilter.GetFilterParameter();
|
|
|
|
float value = ClampFactor(styleValue.GetFactorOrPercentValue());
|
|
|
|
|
|
|
|
// Set identity transfer functions for RGB.
|
|
|
|
AttributeMap identityAttrs;
|
|
|
|
identityAttrs.Set(eComponentTransferFunctionType,
|
|
|
|
(uint32_t)SVG_FECOMPONENTTRANSFER_TYPE_IDENTITY);
|
|
|
|
aDescr.Attributes().Set(eComponentTransferFunctionR, identityAttrs);
|
|
|
|
aDescr.Attributes().Set(eComponentTransferFunctionG, identityAttrs);
|
|
|
|
aDescr.Attributes().Set(eComponentTransferFunctionB, identityAttrs);
|
|
|
|
|
|
|
|
// Set transfer function for A.
|
|
|
|
AttributeMap opacityAttrs;
|
|
|
|
float opacityTableValues[2];
|
|
|
|
opacityTableValues[0] = 0;
|
|
|
|
opacityTableValues[1] = value;
|
|
|
|
opacityAttrs.Set(eComponentTransferFunctionType,
|
|
|
|
(uint32_t)SVG_FECOMPONENTTRANSFER_TYPE_TABLE);
|
|
|
|
opacityAttrs.Set(eComponentTransferFunctionTableValues, opacityTableValues, 2);
|
|
|
|
aDescr.Attributes().Set(eComponentTransferFunctionA, opacityAttrs);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-08-21 04:52:28 +04:00
|
|
|
nsresult
|
|
|
|
nsCSSFilterInstance::SetAttributesForSaturate(FilterPrimitiveDescription& aDescr)
|
|
|
|
{
|
|
|
|
// Set color matrix type.
|
|
|
|
aDescr.Attributes().Set(eColorMatrixType, (uint32_t)SVG_FECOLORMATRIX_TYPE_SATURATE);
|
|
|
|
|
|
|
|
// Set color matrix values.
|
|
|
|
const nsStyleCoord& styleValue = mFilter.GetFilterParameter();
|
|
|
|
float value = styleValue.GetFactorOrPercentValue();
|
|
|
|
aDescr.Attributes().Set(eColorMatrixValues, &value, 1);
|
2014-08-21 21:17:12 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsCSSFilterInstance::SetAttributesForSepia(FilterPrimitiveDescription& aDescr)
|
|
|
|
{
|
|
|
|
// Set color matrix type.
|
|
|
|
aDescr.Attributes().Set(eColorMatrixType, (uint32_t)SVG_FECOLORMATRIX_TYPE_SEPIA);
|
|
|
|
|
|
|
|
// Set color matrix values.
|
|
|
|
const nsStyleCoord& styleValue = mFilter.GetFilterParameter();
|
|
|
|
float value = ClampFactor(styleValue.GetFactorOrPercentValue());
|
|
|
|
aDescr.Attributes().Set(eColorMatrixValues, &value, 1);
|
2014-08-21 02:46:59 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-08-14 22:29:56 +04:00
|
|
|
Size
|
|
|
|
nsCSSFilterInstance::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 =
|
|
|
|
mFrameSpaceInCSSPxToFilterSpaceTransform.ScaleFactors(true);
|
|
|
|
radiusInFilterSpace.Scale(frameSpaceInCSSPxToFilterSpaceScale.width,
|
|
|
|
frameSpaceInCSSPxToFilterSpaceScale.height);
|
|
|
|
|
|
|
|
// Check the radius limits.
|
|
|
|
if (radiusInFilterSpace.width < 0 || radiusInFilterSpace.height < 0) {
|
|
|
|
NS_NOTREACHED("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
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
|
|
|
IntPoint
|
|
|
|
nsCSSFilterInstance::OffsetToFilterSpace(nscoord aXOffsetInFrameSpace,
|
|
|
|
nscoord aYOffsetInFrameSpace)
|
|
|
|
{
|
|
|
|
gfxPoint offsetInFilterSpace(nsPresContext::AppUnitsToFloatCSSPixels(aXOffsetInFrameSpace),
|
|
|
|
nsPresContext::AppUnitsToFloatCSSPixels(aYOffsetInFrameSpace));
|
|
|
|
|
|
|
|
// Convert the radius to filter space.
|
|
|
|
gfxSize frameSpaceInCSSPxToFilterSpaceScale =
|
|
|
|
mFrameSpaceInCSSPxToFilterSpaceTransform.ScaleFactors(true);
|
|
|
|
offsetInFilterSpace.x *= frameSpaceInCSSPxToFilterSpaceScale.width;
|
|
|
|
offsetInFilterSpace.y *= frameSpaceInCSSPxToFilterSpaceScale.height;
|
|
|
|
|
|
|
|
return IntPoint(int32_t(offsetInFilterSpace.x), int32_t(offsetInFilterSpace.y));
|
|
|
|
}
|
|
|
|
|
|
|
|
Color
|
|
|
|
nsCSSFilterInstance::ToAttributeColor(nscolor aColor)
|
|
|
|
{
|
|
|
|
return Color(
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
int32_t
|
|
|
|
nsCSSFilterInstance::GetLastResultIndex(const nsTArray<FilterPrimitiveDescription>& aPrimitiveDescrs)
|
|
|
|
{
|
|
|
|
uint32_t numPrimitiveDescrs = aPrimitiveDescrs.Length();
|
|
|
|
return !numPrimitiveDescrs ?
|
|
|
|
FilterPrimitiveDescription::kPrimitiveIndexSourceGraphic :
|
|
|
|
numPrimitiveDescrs - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsCSSFilterInstance::SetBounds(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 = (inputIndex < 0) ?
|
2015-05-28 22:51:58 +03:00
|
|
|
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);
|
|
|
|
}
|