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