Changeset 275471 in webkit
- Timestamp:
- Apr 5, 2021 6:45:37 PM (3 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 16 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r275466 r275471 1 2021-04-05 Simon Fraser <simon.fraser@apple.com> 2 3 Wasted vector capacity in FEColorMatrix and filters 4 https://bugs.webkit.org/show_bug.cgi?id=224169 5 6 Reviewed by Said Abou-Hallawa. 7 8 When building filter effects, avoid the inputEffects() having a larger 9 capacity than needed. 10 11 Shrink the Vector<float> which is input to FEColorMatrix. 12 13 This saves around 40KB on facebook.com feed pages. 14 15 * platform/graphics/filters/FEColorMatrix.cpp: 16 (WebCore::FEColorMatrix::FEColorMatrix): 17 (WebCore::FEColorMatrix::create): 18 * platform/graphics/filters/FEColorMatrix.h: 19 * rendering/CSSFilter.cpp: 20 (WebCore::CSSFilter::build): 21 (WebCore::endMatrixRow): Deleted. 22 (WebCore::lastMatrixRow): Deleted. 23 * rendering/svg/RenderSVGResourceFilter.cpp: 24 (WebCore::RenderSVGResourceFilter::buildPrimitives const): 25 * svg/SVGFEColorMatrixElement.cpp: 26 (WebCore::SVGFEColorMatrixElement::build const): 27 * svg/SVGFEComponentTransferElement.cpp: 28 (WebCore::SVGFEComponentTransferElement::build const): 29 * svg/SVGFEConvolveMatrixElement.cpp: 30 (WebCore::SVGFEConvolveMatrixElement::build const): 31 * svg/SVGFEDiffuseLightingElement.cpp: 32 (WebCore::SVGFEDiffuseLightingElement::build const): 33 * svg/SVGFEDropShadowElement.cpp: 34 (WebCore::SVGFEDropShadowElement::build const): 35 * svg/SVGFEGaussianBlurElement.cpp: 36 (WebCore::SVGFEGaussianBlurElement::build const): 37 * svg/SVGFEMergeElement.cpp: 38 (WebCore::SVGFEMergeElement::build const): 39 * svg/SVGFEMorphologyElement.cpp: 40 (WebCore::SVGFEMorphologyElement::build const): 41 * svg/SVGFEOffsetElement.cpp: 42 (WebCore::SVGFEOffsetElement::build const): 43 * svg/SVGFESpecularLightingElement.cpp: 44 (WebCore::SVGFESpecularLightingElement::build const): 45 * svg/SVGFETileElement.cpp: 46 (WebCore::SVGFETileElement::build const): 47 1 48 2021-04-05 Saam Barati <sbarati@apple.com> 2 49 -
trunk/Source/WebCore/platform/graphics/filters/FEColorMatrix.cpp
r275206 r275471 36 36 namespace WebCore { 37 37 38 FEColorMatrix::FEColorMatrix(Filter& filter, ColorMatrixType type, const Vector<float>& values)38 FEColorMatrix::FEColorMatrix(Filter& filter, ColorMatrixType type, Vector<float>&& values) 39 39 : FilterEffect(filter, Type::ColorMatrix) 40 40 , m_type(type) 41 , m_values( values)42 { 43 } 44 45 Ref<FEColorMatrix> FEColorMatrix::create(Filter& filter, ColorMatrixType type, const Vector<float>& values)46 { 47 return adoptRef(*new FEColorMatrix(filter, type, values));41 , m_values(WTFMove(values)) 42 { 43 } 44 45 Ref<FEColorMatrix> FEColorMatrix::create(Filter& filter, ColorMatrixType type, Vector<float>&& values) 46 { 47 return adoptRef(*new FEColorMatrix(filter, type, WTFMove(values))); 48 48 } 49 49 -
trunk/Source/WebCore/platform/graphics/filters/FEColorMatrix.h
r266542 r275471 39 39 class FEColorMatrix : public FilterEffect { 40 40 public: 41 static Ref<FEColorMatrix> create(Filter&, ColorMatrixType, const Vector<float>&);41 static Ref<FEColorMatrix> create(Filter&, ColorMatrixType, Vector<float>&&); 42 42 43 43 ColorMatrixType type() const { return m_type; } … … 51 51 52 52 private: 53 FEColorMatrix(Filter&, ColorMatrixType, const Vector<float>&);53 FEColorMatrix(Filter&, ColorMatrixType, Vector<float>&&); 54 54 55 55 const char* filterName() const final { return "FEColorMatrix"; } -
trunk/Source/WebCore/rendering/CSSFilter.cpp
r272475 r275471 53 53 namespace WebCore { 54 54 55 static inline void endMatrixRow(Vector<float>& parameters)56 {57 parameters.append(0);58 parameters.append(0);59 }60 61 static inline void lastMatrixRow(Vector<float>& parameters)62 {63 parameters.append(0);64 parameters.append(0);65 parameters.append(0);66 parameters.append(1);67 parameters.append(0);68 }69 70 55 Ref<CSSFilter> CSSFilter::create() 71 56 { … … 156 141 case FilterOperation::GRAYSCALE: { 157 142 auto& colorMatrixOperation = downcast<BasicColorMatrixFilterOperation>(filterOperation); 158 Vector<float> inputParameters;159 143 double oneMinusAmount = clampTo(1 - colorMatrixOperation.amount(), 0.0, 1.0); 160 144 … … 162 146 // for information on parameters. 163 147 164 inputParameters.append(narrowPrecisionToFloat(0.2126 + 0.7874 * oneMinusAmount)); 165 inputParameters.append(narrowPrecisionToFloat(0.7152 - 0.7152 * oneMinusAmount)); 166 inputParameters.append(narrowPrecisionToFloat(0.0722 - 0.0722 * oneMinusAmount)); 167 endMatrixRow(inputParameters); 168 169 inputParameters.append(narrowPrecisionToFloat(0.2126 - 0.2126 * oneMinusAmount)); 170 inputParameters.append(narrowPrecisionToFloat(0.7152 + 0.2848 * oneMinusAmount)); 171 inputParameters.append(narrowPrecisionToFloat(0.0722 - 0.0722 * oneMinusAmount)); 172 endMatrixRow(inputParameters); 173 174 inputParameters.append(narrowPrecisionToFloat(0.2126 - 0.2126 * oneMinusAmount)); 175 inputParameters.append(narrowPrecisionToFloat(0.7152 - 0.7152 * oneMinusAmount)); 176 inputParameters.append(narrowPrecisionToFloat(0.0722 + 0.9278 * oneMinusAmount)); 177 endMatrixRow(inputParameters); 178 179 lastMatrixRow(inputParameters); 180 181 effect = FEColorMatrix::create(*this, FECOLORMATRIX_TYPE_MATRIX, inputParameters); 148 Vector<float> inputParameters { 149 narrowPrecisionToFloat(0.2126 + 0.7874 * oneMinusAmount), 150 narrowPrecisionToFloat(0.7152 - 0.7152 * oneMinusAmount), 151 narrowPrecisionToFloat(0.0722 - 0.0722 * oneMinusAmount), 152 0, 153 0, 154 155 narrowPrecisionToFloat(0.2126 - 0.2126 * oneMinusAmount), 156 narrowPrecisionToFloat(0.7152 + 0.2848 * oneMinusAmount), 157 narrowPrecisionToFloat(0.0722 - 0.0722 * oneMinusAmount), 158 0, 159 0, 160 161 narrowPrecisionToFloat(0.2126 - 0.2126 * oneMinusAmount), 162 narrowPrecisionToFloat(0.7152 - 0.7152 * oneMinusAmount), 163 narrowPrecisionToFloat(0.0722 + 0.9278 * oneMinusAmount), 164 0, 165 0, 166 167 0, 168 0, 169 0, 170 1, 171 0, 172 }; 173 174 effect = FEColorMatrix::create(*this, FECOLORMATRIX_TYPE_MATRIX, WTFMove(inputParameters)); 182 175 break; 183 176 } 184 177 case FilterOperation::SEPIA: { 185 178 auto& colorMatrixOperation = downcast<BasicColorMatrixFilterOperation>(filterOperation); 186 Vector<float> inputParameters;187 179 double oneMinusAmount = clampTo(1 - colorMatrixOperation.amount(), 0.0, 1.0); 188 180 … … 190 182 // for information on parameters. 191 183 192 inputParameters.append(narrowPrecisionToFloat(0.393 + 0.607 * oneMinusAmount)); 193 inputParameters.append(narrowPrecisionToFloat(0.769 - 0.769 * oneMinusAmount)); 194 inputParameters.append(narrowPrecisionToFloat(0.189 - 0.189 * oneMinusAmount)); 195 endMatrixRow(inputParameters); 196 197 inputParameters.append(narrowPrecisionToFloat(0.349 - 0.349 * oneMinusAmount)); 198 inputParameters.append(narrowPrecisionToFloat(0.686 + 0.314 * oneMinusAmount)); 199 inputParameters.append(narrowPrecisionToFloat(0.168 - 0.168 * oneMinusAmount)); 200 endMatrixRow(inputParameters); 201 202 inputParameters.append(narrowPrecisionToFloat(0.272 - 0.272 * oneMinusAmount)); 203 inputParameters.append(narrowPrecisionToFloat(0.534 - 0.534 * oneMinusAmount)); 204 inputParameters.append(narrowPrecisionToFloat(0.131 + 0.869 * oneMinusAmount)); 205 endMatrixRow(inputParameters); 206 207 lastMatrixRow(inputParameters); 208 209 effect = FEColorMatrix::create(*this, FECOLORMATRIX_TYPE_MATRIX, inputParameters); 184 Vector<float> inputParameters { 185 narrowPrecisionToFloat(0.393 + 0.607 * oneMinusAmount), 186 narrowPrecisionToFloat(0.769 - 0.769 * oneMinusAmount), 187 narrowPrecisionToFloat(0.189 - 0.189 * oneMinusAmount), 188 0, 189 0, 190 191 narrowPrecisionToFloat(0.349 - 0.349 * oneMinusAmount), 192 narrowPrecisionToFloat(0.686 + 0.314 * oneMinusAmount), 193 narrowPrecisionToFloat(0.168 - 0.168 * oneMinusAmount), 194 0, 195 0, 196 197 narrowPrecisionToFloat(0.272 - 0.272 * oneMinusAmount), 198 narrowPrecisionToFloat(0.534 - 0.534 * oneMinusAmount), 199 narrowPrecisionToFloat(0.131 + 0.869 * oneMinusAmount), 200 0, 201 0, 202 203 0, 204 0, 205 0, 206 1, 207 0, 208 }; 209 210 effect = FEColorMatrix::create(*this, FECOLORMATRIX_TYPE_MATRIX, WTFMove(inputParameters)); 210 211 break; 211 212 } 212 213 case FilterOperation::SATURATE: { 213 214 auto& colorMatrixOperation = downcast<BasicColorMatrixFilterOperation>(filterOperation); 214 Vector<float> inputParameters; 215 inputParameters.append(narrowPrecisionToFloat(colorMatrixOperation.amount())); 216 effect = FEColorMatrix::create(*this, FECOLORMATRIX_TYPE_SATURATE, inputParameters); 215 Vector<float> inputParameters { narrowPrecisionToFloat(colorMatrixOperation.amount()) }; 216 effect = FEColorMatrix::create(*this, FECOLORMATRIX_TYPE_SATURATE, WTFMove(inputParameters)); 217 217 break; 218 218 } 219 219 case FilterOperation::HUE_ROTATE: { 220 220 auto& colorMatrixOperation = downcast<BasicColorMatrixFilterOperation>(filterOperation); 221 Vector<float> inputParameters; 222 inputParameters.append(narrowPrecisionToFloat(colorMatrixOperation.amount())); 223 effect = FEColorMatrix::create(*this, FECOLORMATRIX_TYPE_HUEROTATE, inputParameters); 221 Vector<float> inputParameters { narrowPrecisionToFloat(colorMatrixOperation.amount()) }; 222 effect = FEColorMatrix::create(*this, FECOLORMATRIX_TYPE_HUEROTATE, WTFMove(inputParameters)); 224 223 break; 225 224 } … … 297 296 298 297 if (filterOperation.type() != FilterOperation::REFERENCE) { 299 effect->inputEffects() .append(WTFMove(previousEffect));298 effect->inputEffects() = { WTFMove(previousEffect) }; 300 299 m_effects.append(*effect); 301 300 } … … 307 306 if (m_effects.isEmpty()) 308 307 return false; 308 309 m_effects.shrinkToFit(); 309 310 310 311 setMaxEffectRects(m_sourceDrawingRegion); -
trunk/Source/WebCore/rendering/svg/RenderSVGResourceFilter.cpp
r272475 r275471 95 95 96 96 for (auto& element : childrenOfType<SVGFilterPrimitiveStandardAttributes>(filterElement())) { 97 RefPtr<FilterEffect>effect = element.build(builder.get(), filter);97 auto effect = element.build(builder.get(), filter); 98 98 if (!effect) { 99 99 builder->clearEffects(); -
trunk/Source/WebCore/svg/SVGFEColorMatrixElement.cpp
r246490 r275471 114 114 if (!hasAttribute(SVGNames::valuesAttr)) { 115 115 switch (filterType) { 116 case FECOLORMATRIX_TYPE_MATRIX: 117 for (size_t i = 0; i < 20; i++) 118 filterValues.append((i % 6) ? 0 : 1); 116 case FECOLORMATRIX_TYPE_MATRIX: { 117 static constexpr unsigned matrixValueCount = 20; 118 filterValues.reserveInitialCapacity(matrixValueCount); 119 for (size_t i = 0; i < matrixValueCount; i++) 120 filterValues.uncheckedAppend((i % 6) ? 0 : 1); 119 121 break; 122 } 120 123 case FECOLORMATRIX_TYPE_HUEROTATE: 121 filterValues .append(0);124 filterValues = { 0 }; 122 125 break; 123 126 case FECOLORMATRIX_TYPE_SATURATE: 124 filterValues .append(1);127 filterValues = { 1 }; 125 128 break; 126 129 default: … … 136 139 137 140 filterValues = values(); 141 filterValues.shrinkToFit(); 138 142 } 139 143 140 auto effect = FEColorMatrix::create(filter, filterType, filterValues);141 effect->inputEffects() .append(input1);144 auto effect = FEColorMatrix::create(filter, filterType, WTFMove(filterValues)); 145 effect->inputEffects() = { input1 }; 142 146 return effect; 143 147 } -
trunk/Source/WebCore/svg/SVGFEComponentTransferElement.cpp
r246490 r275471 87 87 88 88 auto effect = FEComponentTransfer::create(filter, red, green, blue, alpha); 89 effect->inputEffects() .append(input1);89 effect->inputEffects() = { input1 }; 90 90 return effect; 91 91 } -
trunk/Source/WebCore/svg/SVGFEConvolveMatrixElement.cpp
r263334 r275471 247 247 248 248 auto effect = FEConvolveMatrix::create(filter, IntSize(orderXValue, orderYValue), divisorValue, bias(), IntPoint(targetXValue, targetYValue), edgeMode(), FloatPoint(kernelUnitLengthXValue, kernelUnitLengthYValue), preserveAlpha(), kernelMatrix); 249 effect->inputEffects() .append(input1);249 effect->inputEffects() = { input1 }; 250 250 return effect; 251 251 } -
trunk/Source/WebCore/svg/SVGFEDiffuseLightingElement.cpp
r263334 r275471 172 172 173 173 auto effect = FEDiffuseLighting::create(filter, color, surfaceScale(), diffuseConstant(), kernelUnitLengthX(), kernelUnitLengthY(), WTFMove(lightSource)); 174 effect->inputEffects() .append(input1);174 effect->inputEffects() = { input1 }; 175 175 return effect; 176 176 } -
trunk/Source/WebCore/svg/SVGFEDropShadowElement.cpp
r263334 r275471 117 117 118 118 auto effect = FEDropShadow::create(filter, stdDeviationX(), stdDeviationY(), dx(), dy(), color, opacity); 119 effect->inputEffects() .append(input1);119 effect->inputEffects() = { input1 }; 120 120 return effect; 121 121 } -
trunk/Source/WebCore/svg/SVGFEGaussianBlurElement.cpp
r263334 r275471 99 99 { 100 100 auto input1 = filterBuilder->getEffectById(in1()); 101 102 101 if (!input1) 103 102 return nullptr; … … 107 106 108 107 auto effect = FEGaussianBlur::create(filter, stdDeviationX(), stdDeviationY(), edgeMode()); 109 effect->inputEffects() .append(input1);108 effect->inputEffects() = { input1 }; 110 109 return effect; 111 110 } -
trunk/Source/WebCore/svg/SVGFEMergeElement.cpp
r243185 r275471 48 48 { 49 49 auto effect = FEMerge::create(filter); 50 FilterEffectVector& mergeInputs = effect->inputEffects();50 auto& mergeInputs = effect->inputEffects(); 51 51 52 52 for (auto& mergeNode : childrenOfType<SVGFEMergeNodeElement>(*this)) { … … 57 57 } 58 58 59 mergeInputs.shrinkToFit(); 60 59 61 if (mergeInputs.isEmpty()) 60 62 return nullptr; -
trunk/Source/WebCore/svg/SVGFEMorphologyElement.cpp
r263334 r275471 128 128 129 129 auto effect = FEMorphology::create(filter, svgOperator(), xRadius, yRadius); 130 effect->inputEffects() .append(input1);130 effect->inputEffects() = { input1 }; 131 131 return effect; 132 132 } -
trunk/Source/WebCore/svg/SVGFEOffsetElement.cpp
r246490 r275471 90 90 91 91 auto effect = FEOffset::create(filter, dx(), dy()); 92 effect->inputEffects() .append(input1);92 effect->inputEffects() = { input1 }; 93 93 return effect; 94 94 } -
trunk/Source/WebCore/svg/SVGFESpecularLightingElement.cpp
r263334 r275471 181 181 182 182 auto effect = FESpecularLighting::create(filter, color, surfaceScale(), specularConstant(), specularExponent(), kernelUnitLengthX(), kernelUnitLengthY(), WTFMove(lightSource)); 183 effect->inputEffects() .append(input1);183 effect->inputEffects() = { input1 }; 184 184 return effect; 185 185 } -
trunk/Source/WebCore/svg/SVGFETileElement.cpp
r246490 r275471 79 79 80 80 auto effect = FETile::create(filter); 81 effect->inputEffects() .append(input1);81 effect->inputEffects() = { input1 }; 82 82 return effect; 83 83 }
Note: See TracChangeset
for help on using the changeset viewer.