Changeset 225009 in webkit
- Timestamp:
- Nov 17, 2017, 6:32:00 PM (8 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 2 added
- 5 edited
-
ChangeLog (modified) (1 diff)
-
Sources.txt (modified) (1 diff)
-
WebCore.xcodeproj/project.pbxproj (modified) (2 diffs)
-
platform/graphics/ColorUtilities.cpp (added)
-
platform/graphics/ColorUtilities.h (added)
-
platform/graphics/filters/FETurbulence.cpp (modified) (8 diffs)
-
platform/graphics/filters/FETurbulence.h (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r225008 r225009 1 2017-11-17 Simon Fraser <simon.fraser@apple.com> 2 3 FETurbulence: compute all 4 channels at once 4 https://bugs.webkit.org/show_bug.cgi?id=179833 5 6 Reviewed by Sam Weinig. 7 8 Introduce some new helper classes for storing float color components, and use 9 them in calculateTurbulenceValueForPoint() and noise2D() for all the channels in one 10 pass. This makes FETurbulence about twice as fast. 11 12 * Sources.txt: 13 * WebCore.xcodeproj/project.pbxproj: 14 * platform/graphics/ColorUtilities.cpp: Added. 15 (WebCore::ColorComponents::ColorComponents): 16 * platform/graphics/ColorUtilities.h: Added. 17 (WebCore::FloatComponents::FloatComponents): 18 (WebCore::FloatComponents::operator +=): 19 (WebCore::FloatComponents::operator + const): 20 (WebCore::FloatComponents::operator / const): 21 (WebCore::FloatComponents::operator * const): 22 (WebCore::FloatComponents::abs const): 23 (WebCore::clampedColorComponent): 24 * platform/graphics/filters/FETurbulence.cpp: 25 (WebCore::FETurbulence::noise2D): 26 (WebCore::FETurbulence::calculateTurbulenceValueForPoint): 27 (WebCore::FETurbulence::fillRegion): 28 (WebCore::FETurbulence::platformApplySoftware): 29 * platform/graphics/filters/FETurbulence.h: 30 1 31 2017-11-17 Chris Dumez <cdumez@apple.com> 2 32 -
trunk/Source/WebCore/Sources.txt
r224929 r225009 1482 1482 platform/graphics/BitmapImage.cpp 1483 1483 platform/graphics/Color.cpp 1484 platform/graphics/ColorUtilities.cpp 1484 1485 platform/graphics/ComplexTextController.cpp 1485 1486 platform/graphics/CrossfadeGeneratedImage.cpp -
trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj
r224957 r225009 5499 5499 0FE5FBD01C3DD51E0007A2CA /* DisplayListReplayer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = DisplayListReplayer.cpp; path = displaylists/DisplayListReplayer.cpp; sourceTree = "<group>"; }; 5500 5500 0FE5FBD11C3DD51E0007A2CA /* DisplayListReplayer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = DisplayListReplayer.h; path = displaylists/DisplayListReplayer.h; sourceTree = "<group>"; }; 5501 0FE6C76B1FBFB7A60025C053 /* ColorUtilities.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = ColorUtilities.cpp; sourceTree = "<group>"; }; 5502 0FE6C76C1FBFB7A60025C053 /* ColorUtilities.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ColorUtilities.h; sourceTree = "<group>"; }; 5501 5503 0FE71403142170B800DB33BA /* ScrollbarThemeMock.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ScrollbarThemeMock.cpp; sourceTree = "<group>"; }; 5502 5504 0FE71404142170B800DB33BA /* ScrollbarThemeMock.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ScrollbarThemeMock.h; sourceTree = "<group>"; }; … … 22594 22596 3103B7DE1DB01556008BB890 /* ColorHash.h */, 22595 22597 9382DF5710A8D5C900925652 /* ColorSpace.h */, 22598 0FE6C76B1FBFB7A60025C053 /* ColorUtilities.cpp */, 22599 0FE6C76C1FBFB7A60025C053 /* ColorUtilities.h */, 22596 22600 C2F4E7881E45AEDF006D7105 /* ComplexTextController.cpp */, 22597 22601 C2F4E7891E45AEDF006D7105 /* ComplexTextController.h */, -
trunk/Source/WebCore/platform/graphics/filters/FETurbulence.cpp
r224996 r225009 6 6 * Copyright (C) 2010 Renata Hodovan <reni@inf.u-szeged.hu> 7 7 * Copyright (C) 2011 Gabor Loki <loki@webkit.org> 8 * Copyright (C) 2017 Apple Inc. 8 9 * 9 10 * This library is free software; you can redistribute it and/or … … 187 188 } 188 189 189 float FETurbulence::noise2D(int channel,const PaintingData& paintingData, StitchData& stitchData, const FloatPoint& noiseVector)190 FloatComponents FETurbulence::noise2D(const PaintingData& paintingData, StitchData& stitchData, const FloatPoint& noiseVector) 190 191 { 191 192 struct Noise { … … 217 218 float sx = smoothCurve(noiseX.noisePositionFractionValue); 218 219 float sy = smoothCurve(noiseY.noisePositionFractionValue); 219 float a, b, u, v; 220 221 // This is taken 1:1 from SVG spec: http://www.w3.org/TR/SVG11/filters.html#feTurbulenceElement. 222 int temp = paintingData.latticeSelector[latticeIndex + noiseY.noisePositionIntegerValue]; 223 const float* q = paintingData.gradient[channel][temp]; 224 u = noiseX.noisePositionFractionValue * q[0] + noiseY.noisePositionFractionValue * q[1]; 225 temp = paintingData.latticeSelector[nextLatticeIndex + noiseY.noisePositionIntegerValue]; 226 q = paintingData.gradient[channel][temp]; 227 v = (noiseX.noisePositionFractionValue - 1) * q[0] + noiseY.noisePositionFractionValue * q[1]; 228 a = linearInterpolation(sx, u, v); 229 temp = paintingData.latticeSelector[latticeIndex + noiseY.noisePositionIntegerValue + 1]; 230 q = paintingData.gradient[channel][temp]; 231 u = noiseX.noisePositionFractionValue * q[0] + (noiseY.noisePositionFractionValue - 1) * q[1]; 232 temp = paintingData.latticeSelector[nextLatticeIndex + noiseY.noisePositionIntegerValue + 1]; 233 q = paintingData.gradient[channel][temp]; 234 v = (noiseX.noisePositionFractionValue - 1) * q[0] + (noiseY.noisePositionFractionValue - 1) * q[1]; 235 b = linearInterpolation(sx, u, v); 236 return linearInterpolation(sy, a, b); 237 } 238 239 unsigned char FETurbulence::calculateTurbulenceValueForPoint(int channel, const PaintingData& paintingData, StitchData& stitchData, const FloatPoint& point) 220 221 auto noiseForChannel = [&](int channel) { 222 // This is taken 1:1 from SVG spec: http://www.w3.org/TR/SVG11/filters.html#feTurbulenceElement. 223 int temp = paintingData.latticeSelector[latticeIndex + noiseY.noisePositionIntegerValue]; 224 const float* q = paintingData.gradient[channel][temp]; 225 226 float u = noiseX.noisePositionFractionValue * q[0] + noiseY.noisePositionFractionValue * q[1]; 227 temp = paintingData.latticeSelector[nextLatticeIndex + noiseY.noisePositionIntegerValue]; 228 q = paintingData.gradient[channel][temp]; 229 float v = (noiseX.noisePositionFractionValue - 1) * q[0] + noiseY.noisePositionFractionValue * q[1]; 230 float a = linearInterpolation(sx, u, v); 231 temp = paintingData.latticeSelector[latticeIndex + noiseY.noisePositionIntegerValue + 1]; 232 q = paintingData.gradient[channel][temp]; 233 u = noiseX.noisePositionFractionValue * q[0] + (noiseY.noisePositionFractionValue - 1) * q[1]; 234 temp = paintingData.latticeSelector[nextLatticeIndex + noiseY.noisePositionIntegerValue + 1]; 235 q = paintingData.gradient[channel][temp]; 236 v = (noiseX.noisePositionFractionValue - 1) * q[0] + (noiseY.noisePositionFractionValue - 1) * q[1]; 237 float b = linearInterpolation(sx, u, v); 238 239 return linearInterpolation(sy, a, b); 240 }; 241 242 return { 243 noiseForChannel(0), 244 noiseForChannel(1), 245 noiseForChannel(2), 246 noiseForChannel(3) 247 }; 248 } 249 250 ColorComponents FETurbulence::calculateTurbulenceValueForPoint(const PaintingData& paintingData, StitchData& stitchData, const FloatPoint& point) 240 251 { 241 252 float tileWidth = paintingData.filterSize.width(); … … 244 255 float baseFrequencyX = m_baseFrequencyX; 245 256 float baseFrequencyY = m_baseFrequencyY; 257 246 258 // Adjust the base frequencies if necessary for stitching. 247 259 if (m_stitchTiles) { … … 272 284 } 273 285 274 float turbulenceFunctionResult = 0;286 FloatComponents turbulenceFunctionResult; 275 287 FloatPoint noiseVector(point.x() * baseFrequencyX, point.y() * baseFrequencyY); 276 288 float ratio = 1; 277 289 for (int octave = 0; octave < m_numOctaves; ++octave) { 278 290 if (m_type == FETURBULENCE_TYPE_FRACTALNOISE) 279 turbulenceFunctionResult += noise2D( channel,paintingData, stitchData, noiseVector) / ratio;291 turbulenceFunctionResult += noise2D(paintingData, stitchData, noiseVector) / ratio; 280 292 else 281 turbulenceFunctionResult += fabsf(noise2D(channel, paintingData, stitchData, noiseVector)) / ratio; 293 turbulenceFunctionResult += noise2D(paintingData, stitchData, noiseVector).abs() / ratio; 294 282 295 noiseVector.setX(noiseVector.x() * 2); 283 296 noiseVector.setY(noiseVector.y() * 2); 284 297 ratio *= 2; 298 285 299 if (m_stitchTiles) { 286 300 // Update stitch values. Subtracting s_perlinNoiseoise before the multiplication and … … 297 311 if (m_type == FETURBULENCE_TYPE_FRACTALNOISE) 298 312 turbulenceFunctionResult = turbulenceFunctionResult * 0.5f + 0.5f; 299 // Clamp result 300 turbulenceFunctionResult = std::max(std::min(turbulenceFunctionResult, 1.f), 0.f); 301 return static_cast<unsigned char>(turbulenceFunctionResult * 255); 313 314 return turbulenceFunctionResult; 302 315 } 303 316 … … 316 329 point.setX(point.x() + 1); 317 330 FloatPoint localPoint = inverseTransfrom.mapPoint(point); 318 for (int channel = 0; channel < 4; ++channel, ++indexOfPixelChannel) 319 pixelArray->set(indexOfPixelChannel, calculateTurbulenceValueForPoint(channel, paintingData, stitchData, localPoint)); 331 ColorComponents values = calculateTurbulenceValueForPoint(paintingData, stitchData, localPoint); 332 pixelArray->set(indexOfPixelChannel++, values.components[0]); 333 pixelArray->set(indexOfPixelChannel++, values.components[1]); 334 pixelArray->set(indexOfPixelChannel++, values.components[2]); 335 pixelArray->set(indexOfPixelChannel++, values.components[3]); 320 336 } 321 337 } … … 356 372 int startY = 0; 357 373 for (; i > 0; --i) { 358 FillRegionParameters& params = parallelJobs.parameter(i -1);374 FillRegionParameters& params = parallelJobs.parameter(i - 1); 359 375 params.filter = this; 360 376 params.pixelArray = pixelArray; -
trunk/Source/WebCore/platform/graphics/filters/FETurbulence.h
r225005 r225009 5 5 * Copyright (C) 2009 Dirk Schulze <krit@webkit.org> 6 6 * Copyright (C) 2010 Renata Hodovan <reni@inf.u-szeged.hu> 7 * Copyright (C) 2017 Apple Inc. 7 8 * 8 9 * This library is free software; you can redistribute it and/or … … 22 23 */ 23 24 24 #ifndef FETurbulence_h 25 #define FETurbulence_h 25 #pragma once 26 26 27 #include "ColorUtilities.h" 27 28 #include "FilterEffect.h" 28 29 #include "Filter.h" … … 119 120 120 121 void initPaint(PaintingData&); 121 float noise2D(int channel,const PaintingData&, StitchData&, const FloatPoint&);122 unsigned char calculateTurbulenceValueForPoint(int channel,const PaintingData&, StitchData&, const FloatPoint&);122 FloatComponents noise2D(const PaintingData&, StitchData&, const FloatPoint&); 123 ColorComponents calculateTurbulenceValueForPoint(const PaintingData&, StitchData&, const FloatPoint&); 123 124 void fillRegion(Uint8ClampedArray*, const PaintingData&, int, int); 124 125 … … 133 134 } // namespace WebCore 134 135 135 #endif // FETurbulence_h
Note:
See TracChangeset
for help on using the changeset viewer.