Bug 1924318 - Use std::array and mozilla::Span to avoid repeating array sizes r=emilio
Differential Revision: https://phabricator.services.mozilla.com/D225446
This commit is contained in:
@@ -79,7 +79,7 @@ FilterPrimitiveDescription SVGFEColorMatrixElement::GetPrimitiveDescription(
|
|||||||
type == SVG_FECOLORMATRIX_TYPE_SATURATE ||
|
type == SVG_FECOLORMATRIX_TYPE_SATURATE ||
|
||||||
type == SVG_FECOLORMATRIX_TYPE_HUE_ROTATE)) {
|
type == SVG_FECOLORMATRIX_TYPE_HUE_ROTATE)) {
|
||||||
atts.mType = (uint32_t)SVG_FECOLORMATRIX_TYPE_MATRIX;
|
atts.mType = (uint32_t)SVG_FECOLORMATRIX_TYPE_MATRIX;
|
||||||
static const float identityMatrix[] = {
|
static const auto identityMatrix = std::array{
|
||||||
// clang-format off
|
// clang-format off
|
||||||
1, 0, 0, 0, 0,
|
1, 0, 0, 0, 0,
|
||||||
0, 1, 0, 0, 0,
|
0, 1, 0, 0, 0,
|
||||||
@@ -87,7 +87,7 @@ FilterPrimitiveDescription SVGFEColorMatrixElement::GetPrimitiveDescription(
|
|||||||
0, 0, 0, 1, 0
|
0, 0, 0, 1, 0
|
||||||
// clang-format on
|
// clang-format on
|
||||||
};
|
};
|
||||||
atts.mValues.AppendElements(identityMatrix, 20);
|
atts.mValues.AppendElements(Span(identityMatrix));
|
||||||
} else {
|
} else {
|
||||||
atts.mType = type;
|
atts.mType = type;
|
||||||
if (values.Length()) {
|
if (values.Length()) {
|
||||||
|
|||||||
@@ -93,9 +93,9 @@ FilterPrimitiveDescription SVGFECompositeElement::GetPrimitiveDescription(
|
|||||||
atts.mOperator = op;
|
atts.mOperator = op;
|
||||||
|
|
||||||
if (op == SVG_FECOMPOSITE_OPERATOR_ARITHMETIC) {
|
if (op == SVG_FECOMPOSITE_OPERATOR_ARITHMETIC) {
|
||||||
float k[4];
|
std::array<float, 4> k;
|
||||||
GetAnimatedNumberValues(k, k + 1, k + 2, k + 3, nullptr);
|
GetAnimatedNumberValues(&k[0], &k[1], &k[2], &k[3], nullptr);
|
||||||
atts.mCoefficients.AppendElements(k, 4);
|
atts.mCoefficients.AppendElements(Span(k));
|
||||||
}
|
}
|
||||||
|
|
||||||
return FilterPrimitiveDescription(AsVariant(std::move(atts)));
|
return FilterPrimitiveDescription(AsVariant(std::move(atts)));
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
#include "DOMSVGAnimatedNumberList.h"
|
#include "DOMSVGAnimatedNumberList.h"
|
||||||
#include "mozilla/dom/Document.h"
|
#include "mozilla/dom/Document.h"
|
||||||
#include "mozilla/dom/BindContext.h"
|
#include "mozilla/dom/BindContext.h"
|
||||||
|
#include <numeric>
|
||||||
|
|
||||||
NS_IMPL_NS_NEW_SVG_ELEMENT(FEConvolveMatrix)
|
NS_IMPL_NS_NEW_SVG_ELEMENT(FEConvolveMatrix)
|
||||||
|
|
||||||
@@ -163,19 +164,13 @@ FilterPrimitiveDescription SVGFEConvolveMatrixElement::GetPrimitiveDescription(
|
|||||||
if (orderX > NS_SVG_OFFSCREEN_MAX_DIMENSION ||
|
if (orderX > NS_SVG_OFFSCREEN_MAX_DIMENSION ||
|
||||||
orderY > NS_SVG_OFFSCREEN_MAX_DIMENSION)
|
orderY > NS_SVG_OFFSCREEN_MAX_DIMENSION)
|
||||||
return failureDescription;
|
return failureDescription;
|
||||||
UniquePtr<float[]> kernel = MakeUniqueFallible<float[]>(orderX * orderY);
|
|
||||||
if (!kernel) return failureDescription;
|
|
||||||
for (uint32_t i = 0; i < kmLength; i++) {
|
|
||||||
kernel[kmLength - 1 - i] = kernelMatrix[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
float divisor;
|
float divisor;
|
||||||
if (mNumberAttributes[DIVISOR].IsExplicitlySet()) {
|
if (mNumberAttributes[DIVISOR].IsExplicitlySet()) {
|
||||||
divisor = mNumberAttributes[DIVISOR].GetAnimValue();
|
divisor = mNumberAttributes[DIVISOR].GetAnimValue();
|
||||||
if (divisor == 0) return failureDescription;
|
if (divisor == 0) return failureDescription;
|
||||||
} else {
|
} else {
|
||||||
divisor = kernel[0];
|
divisor = std::accumulate(kernelMatrix.begin(), kernelMatrix.end(), 0.0f);
|
||||||
for (uint32_t i = 1; i < kmLength; i++) divisor += kernel[i];
|
|
||||||
if (divisor == 0) divisor = 1;
|
if (divisor == 0) divisor = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -61,6 +61,13 @@ class SVGNumberList {
|
|||||||
|
|
||||||
const float& operator[](uint32_t aIndex) const { return mNumbers[aIndex]; }
|
const float& operator[](uint32_t aIndex) const { return mNumbers[aIndex]; }
|
||||||
|
|
||||||
|
[[nodiscard]] FallibleTArray<float>::const_iterator begin() const {
|
||||||
|
return mNumbers.begin();
|
||||||
|
}
|
||||||
|
[[nodiscard]] FallibleTArray<float>::const_iterator end() const {
|
||||||
|
return mNumbers.end();
|
||||||
|
}
|
||||||
|
|
||||||
bool operator==(const SVGNumberList& rhs) const {
|
bool operator==(const SVGNumberList& rhs) const {
|
||||||
return mNumbers == rhs.mNumbers;
|
return mNumbers == rhs.mNumbers;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -130,10 +130,10 @@ nsresult CSSFilterInstance::SetAttributesForBrightness(
|
|||||||
atts.mTypes[kChannelROrRGB] = (uint8_t)SVG_FECOMPONENTTRANSFER_TYPE_LINEAR;
|
atts.mTypes[kChannelROrRGB] = (uint8_t)SVG_FECOMPONENTTRANSFER_TYPE_LINEAR;
|
||||||
atts.mTypes[kChannelG] = (uint8_t)SVG_FECOMPONENTTRANSFER_SAME_AS_R;
|
atts.mTypes[kChannelG] = (uint8_t)SVG_FECOMPONENTTRANSFER_SAME_AS_R;
|
||||||
atts.mTypes[kChannelB] = (uint8_t)SVG_FECOMPONENTTRANSFER_SAME_AS_R;
|
atts.mTypes[kChannelB] = (uint8_t)SVG_FECOMPONENTTRANSFER_SAME_AS_R;
|
||||||
float slopeIntercept[2];
|
std::array<float, 2> slopeIntercept;
|
||||||
slopeIntercept[kComponentTransferSlopeIndex] = value;
|
slopeIntercept[kComponentTransferSlopeIndex] = value;
|
||||||
slopeIntercept[kComponentTransferInterceptIndex] = intercept;
|
slopeIntercept[kComponentTransferInterceptIndex] = intercept;
|
||||||
atts.mValues[kChannelROrRGB].AppendElements(slopeIntercept, 2);
|
atts.mValues[kChannelROrRGB].AppendElements(Span(slopeIntercept));
|
||||||
|
|
||||||
atts.mTypes[kChannelA] = (uint8_t)SVG_FECOMPONENTTRANSFER_TYPE_IDENTITY;
|
atts.mTypes[kChannelA] = (uint8_t)SVG_FECOMPONENTTRANSFER_TYPE_IDENTITY;
|
||||||
|
|
||||||
@@ -151,10 +151,10 @@ nsresult CSSFilterInstance::SetAttributesForContrast(
|
|||||||
atts.mTypes[kChannelROrRGB] = (uint8_t)SVG_FECOMPONENTTRANSFER_TYPE_LINEAR;
|
atts.mTypes[kChannelROrRGB] = (uint8_t)SVG_FECOMPONENTTRANSFER_TYPE_LINEAR;
|
||||||
atts.mTypes[kChannelG] = (uint8_t)SVG_FECOMPONENTTRANSFER_SAME_AS_R;
|
atts.mTypes[kChannelG] = (uint8_t)SVG_FECOMPONENTTRANSFER_SAME_AS_R;
|
||||||
atts.mTypes[kChannelB] = (uint8_t)SVG_FECOMPONENTTRANSFER_SAME_AS_R;
|
atts.mTypes[kChannelB] = (uint8_t)SVG_FECOMPONENTTRANSFER_SAME_AS_R;
|
||||||
float slopeIntercept[2];
|
std::array<float, 2> slopeIntercept;
|
||||||
slopeIntercept[kComponentTransferSlopeIndex] = value;
|
slopeIntercept[kComponentTransferSlopeIndex] = value;
|
||||||
slopeIntercept[kComponentTransferInterceptIndex] = intercept;
|
slopeIntercept[kComponentTransferInterceptIndex] = intercept;
|
||||||
atts.mValues[kChannelROrRGB].AppendElements(slopeIntercept, 2);
|
atts.mValues[kChannelROrRGB].AppendElements(Span(slopeIntercept));
|
||||||
|
|
||||||
atts.mTypes[kChannelA] = (uint8_t)SVG_FECOMPONENTTRANSFER_TYPE_IDENTITY;
|
atts.mTypes[kChannelA] = (uint8_t)SVG_FECOMPONENTTRANSFER_TYPE_IDENTITY;
|
||||||
|
|
||||||
@@ -191,9 +191,8 @@ nsresult CSSFilterInstance::SetAttributesForGrayscale(
|
|||||||
// Set color matrix type.
|
// Set color matrix type.
|
||||||
atts.mType = (uint32_t)SVG_FECOLORMATRIX_TYPE_SATURATE;
|
atts.mType = (uint32_t)SVG_FECOLORMATRIX_TYPE_SATURATE;
|
||||||
|
|
||||||
// Set color matrix values.
|
// Set color matrix value.
|
||||||
float value = 1 - ClampFactor(mFilter.AsGrayscale());
|
atts.mValues.AppendElement(1 - ClampFactor(mFilter.AsGrayscale()));
|
||||||
atts.mValues.AppendElements(&value, 1);
|
|
||||||
|
|
||||||
aDescr.Attributes() = AsVariant(std::move(atts));
|
aDescr.Attributes() = AsVariant(std::move(atts));
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
@@ -205,9 +204,8 @@ nsresult CSSFilterInstance::SetAttributesForHueRotate(
|
|||||||
// Set color matrix type.
|
// Set color matrix type.
|
||||||
atts.mType = (uint32_t)SVG_FECOLORMATRIX_TYPE_HUE_ROTATE;
|
atts.mType = (uint32_t)SVG_FECOLORMATRIX_TYPE_HUE_ROTATE;
|
||||||
|
|
||||||
// Set color matrix values.
|
// Set color matrix value.
|
||||||
float value = mFilter.AsHueRotate().ToDegrees();
|
atts.mValues.AppendElement(mFilter.AsHueRotate().ToDegrees());
|
||||||
atts.mValues.AppendElements(&value, 1);
|
|
||||||
|
|
||||||
aDescr.Attributes() = AsVariant(std::move(atts));
|
aDescr.Attributes() = AsVariant(std::move(atts));
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
@@ -219,15 +217,13 @@ nsresult CSSFilterInstance::SetAttributesForInvert(
|
|||||||
float value = ClampFactor(mFilter.AsInvert());
|
float value = ClampFactor(mFilter.AsInvert());
|
||||||
|
|
||||||
// Set transfer functions for RGB.
|
// Set transfer functions for RGB.
|
||||||
float invertTableValues[2];
|
std::array<float, 2> invertTableValues = {value, 1 - value};
|
||||||
invertTableValues[0] = value;
|
|
||||||
invertTableValues[1] = 1 - value;
|
|
||||||
|
|
||||||
// Set transfer functions for RGB.
|
// Set transfer functions for RGB.
|
||||||
atts.mTypes[kChannelROrRGB] = (uint8_t)SVG_FECOMPONENTTRANSFER_TYPE_TABLE;
|
atts.mTypes[kChannelROrRGB] = (uint8_t)SVG_FECOMPONENTTRANSFER_TYPE_TABLE;
|
||||||
atts.mTypes[kChannelG] = (uint8_t)SVG_FECOMPONENTTRANSFER_SAME_AS_R;
|
atts.mTypes[kChannelG] = (uint8_t)SVG_FECOMPONENTTRANSFER_SAME_AS_R;
|
||||||
atts.mTypes[kChannelB] = (uint8_t)SVG_FECOMPONENTTRANSFER_SAME_AS_R;
|
atts.mTypes[kChannelB] = (uint8_t)SVG_FECOMPONENTTRANSFER_SAME_AS_R;
|
||||||
atts.mValues[kChannelROrRGB].AppendElements(invertTableValues, 2);
|
atts.mValues[kChannelROrRGB].AppendElements(Span(invertTableValues));
|
||||||
|
|
||||||
atts.mTypes[kChannelA] = (uint8_t)SVG_FECOMPONENTTRANSFER_TYPE_IDENTITY;
|
atts.mTypes[kChannelA] = (uint8_t)SVG_FECOMPONENTTRANSFER_TYPE_IDENTITY;
|
||||||
|
|
||||||
@@ -251,9 +247,8 @@ nsresult CSSFilterInstance::SetAttributesForSaturate(
|
|||||||
// Set color matrix type.
|
// Set color matrix type.
|
||||||
atts.mType = (uint32_t)SVG_FECOLORMATRIX_TYPE_SATURATE;
|
atts.mType = (uint32_t)SVG_FECOLORMATRIX_TYPE_SATURATE;
|
||||||
|
|
||||||
// Set color matrix values.
|
// Set color matrix value.
|
||||||
float value = mFilter.AsSaturate();
|
atts.mValues.AppendElement(mFilter.AsSaturate());
|
||||||
atts.mValues.AppendElements(&value, 1);
|
|
||||||
|
|
||||||
aDescr.Attributes() = AsVariant(std::move(atts));
|
aDescr.Attributes() = AsVariant(std::move(atts));
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
@@ -265,9 +260,8 @@ nsresult CSSFilterInstance::SetAttributesForSepia(
|
|||||||
// Set color matrix type.
|
// Set color matrix type.
|
||||||
atts.mType = (uint32_t)SVG_FECOLORMATRIX_TYPE_SEPIA;
|
atts.mType = (uint32_t)SVG_FECOLORMATRIX_TYPE_SEPIA;
|
||||||
|
|
||||||
// Set color matrix values.
|
// Set color matrix value.
|
||||||
float value = ClampFactor(mFilter.AsSepia());
|
atts.mValues.AppendElement(ClampFactor(mFilter.AsSepia()));
|
||||||
atts.mValues.AppendElements(&value, 1);
|
|
||||||
|
|
||||||
aDescr.Attributes() = AsVariant(std::move(atts));
|
aDescr.Attributes() = AsVariant(std::move(atts));
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
|
|||||||
Reference in New Issue
Block a user