Changeset 225088 in webkit
- Timestamp:
- Nov 21, 2017, 5:02:24 PM (7 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r225087 r225088 1 2017-11-21 Simon Fraser <simon.fraser@apple.com> 2 3 Some FELighting cleanup 4 https://bugs.webkit.org/show_bug.cgi?id=179924 5 6 Reviewed by Sam Weinig. 7 8 Make the normal-computation functions const and have them return an IntSize. 9 Replace bit shifting with multiply by two (compilers know how to do this, folks). 10 11 * platform/graphics/filters/FELighting.cpp: 12 (WebCore::FELighting::LightingData::topLeftNormal const): 13 (WebCore::FELighting::LightingData::topRowNormal const): 14 (WebCore::FELighting::LightingData::topRightNormal const): 15 (WebCore::FELighting::LightingData::leftColumnNormal const): 16 (WebCore::FELighting::LightingData::interiorNormal const): 17 (WebCore::FELighting::LightingData::rightColumnNormal const): 18 (WebCore::FELighting::LightingData::bottomLeftNormal const): 19 (WebCore::FELighting::LightingData::bottomRowNormal const): 20 (WebCore::FELighting::LightingData::bottomRightNormal const): 21 (WebCore::FELighting::inlineSetPixel): 22 (WebCore::FELighting::setPixel): 23 (WebCore::FELighting::platformApplyGenericPaint): 24 (WebCore::FELighting::drawLighting): 25 (WebCore::FELighting::LightingData::topLeft): Deleted. 26 (WebCore::FELighting::LightingData::topRow): Deleted. 27 (WebCore::FELighting::LightingData::topRight): Deleted. 28 (WebCore::FELighting::LightingData::leftColumn): Deleted. 29 (WebCore::FELighting::LightingData::interior): Deleted. 30 (WebCore::FELighting::LightingData::rightColumn): Deleted. 31 (WebCore::FELighting::LightingData::bottomLeft): Deleted. 32 (WebCore::FELighting::LightingData::bottomRow): Deleted. 33 (WebCore::FELighting::LightingData::bottomRight): Deleted. 34 * platform/graphics/filters/FELighting.h: 35 1 36 2017-11-21 Christopher Reid <chris.reid@sony.com> 2 37 -
trunk/Source/WebCore/platform/graphics/filters/FELighting.cpp
r225026 r225088 86 86 const static int cAlphaChannelOffset = 3; 87 87 const static unsigned char cOpaqueAlpha = static_cast<unsigned char>(0xff); 88 89 // These factors and the normal coefficients come from the table under https://www.w3.org/TR/SVG/filters.html#feDiffuseLightingElement. 88 90 const static float cFactor1div2 = -1 / 2.f; 89 91 const static float cFactor1div3 = -1 / 3.f; … … 91 93 const static float cFactor2div3 = -2 / 3.f; 92 94 93 // << 1 is signed multiply by 2 94 inline void FELighting::LightingData::topLeft(int offset, IntPoint& normalVector) 95 inline IntSize FELighting::LightingData::topLeftNormal(int offset) const 95 96 { 96 97 int center = static_cast<int>(pixels->item(offset + cAlphaChannelOffset)); … … 99 100 int bottom = static_cast<int>(pixels->item(offset + cAlphaChannelOffset)); 100 101 int bottomRight = static_cast<int>(pixels->item(offset + cPixelSize + cAlphaChannelOffset)); 101 normalVector.setX(-(center << 1) + (right << 1) - bottom + bottomRight); 102 normalVector.setY(-(center << 1) - right + (bottom << 1) + bottomRight); 103 } 104 105 inline void FELighting::LightingData::topRow(int offset, IntPoint& normalVector) 102 return { 103 -2 * center + 2 * right - bottom + bottomRight, 104 -2 * center - right + 2 * bottom + bottomRight 105 }; 106 } 107 108 inline IntSize FELighting::LightingData::topRowNormal(int offset) const 106 109 { 107 110 int left = static_cast<int>(pixels->item(offset - cPixelSize + cAlphaChannelOffset)); … … 112 115 int bottom = static_cast<int>(pixels->item(offset + cAlphaChannelOffset)); 113 116 int bottomRight = static_cast<int>(pixels->item(offset + cPixelSize + cAlphaChannelOffset)); 114 normalVector.setX(-(left << 1) + (right << 1) - bottomLeft + bottomRight); 115 normalVector.setY(-left - (center << 1) - right + bottomLeft + (bottom << 1) + bottomRight); 116 } 117 118 inline void FELighting::LightingData::topRight(int offset, IntPoint& normalVector) 117 return { 118 -2 * left + 2 * right - bottomLeft + bottomRight, 119 -left - 2 * center - right + bottomLeft + 2 * bottom + bottomRight 120 }; 121 } 122 123 inline IntSize FELighting::LightingData::topRightNormal(int offset) const 119 124 { 120 125 int left = static_cast<int>(pixels->item(offset - cPixelSize + cAlphaChannelOffset)); … … 123 128 int bottomLeft = static_cast<int>(pixels->item(offset - cPixelSize + cAlphaChannelOffset)); 124 129 int bottom = static_cast<int>(pixels->item(offset + cAlphaChannelOffset)); 125 normalVector.setX(-(left << 1) + (center << 1) - bottomLeft + bottom); 126 normalVector.setY(-left - (center << 1) + bottomLeft + (bottom << 1)); 127 } 128 129 inline void FELighting::LightingData::leftColumn(int offset, IntPoint& normalVector) 130 return { 131 -2 * left + 2 * center - bottomLeft + bottom, 132 -left - 2 * center + bottomLeft + 2 * bottom 133 }; 134 } 135 136 inline IntSize FELighting::LightingData::leftColumnNormal(int offset) const 130 137 { 131 138 int center = static_cast<int>(pixels->item(offset + cAlphaChannelOffset)); … … 134 141 int top = static_cast<int>(pixels->item(offset + cAlphaChannelOffset)); 135 142 int topRight = static_cast<int>(pixels->item(offset + cPixelSize + cAlphaChannelOffset)); 136 offset += widthMultipliedByPixelSize << 1;143 offset += 2 * widthMultipliedByPixelSize; 137 144 int bottom = static_cast<int>(pixels->item(offset + cAlphaChannelOffset)); 138 145 int bottomRight = static_cast<int>(pixels->item(offset + cPixelSize + cAlphaChannelOffset)); 139 normalVector.setX(-top + topRight - (center << 1) + (right << 1) - bottom + bottomRight); 140 normalVector.setY(-(top << 1) - topRight + (bottom << 1) + bottomRight); 141 } 142 143 inline void FELighting::LightingData::interior(int offset, IntPoint& normalVector) 146 return { 147 -top + topRight - 2 * center + 2 * right - bottom + bottomRight, 148 -2 * top - topRight + 2 * bottom + bottomRight 149 }; 150 } 151 152 inline IntSize FELighting::LightingData::interiorNormal(int offset) const 144 153 { 145 154 int left = static_cast<int>(pixels->item(offset - cPixelSize + cAlphaChannelOffset)); … … 149 158 int top = static_cast<int>(pixels->item(offset + cAlphaChannelOffset)); 150 159 int topRight = static_cast<int>(pixels->item(offset + cPixelSize + cAlphaChannelOffset)); 151 offset += widthMultipliedByPixelSize << 1;160 offset += 2 * widthMultipliedByPixelSize; 152 161 int bottomLeft = static_cast<int>(pixels->item(offset - cPixelSize + cAlphaChannelOffset)); 153 162 int bottom = static_cast<int>(pixels->item(offset + cAlphaChannelOffset)); 154 163 int bottomRight = static_cast<int>(pixels->item(offset + cPixelSize + cAlphaChannelOffset)); 155 normalVector.setX(-topLeft + topRight - (left << 1) + (right << 1) - bottomLeft + bottomRight); 156 normalVector.setY(-topLeft - (top << 1) - topRight + bottomLeft + (bottom << 1) + bottomRight); 157 } 158 159 inline void FELighting::LightingData::rightColumn(int offset, IntPoint& normalVector) 164 return { 165 -topLeft + topRight - 2 * left + 2 * right - bottomLeft + bottomRight, 166 -topLeft - 2 * top - topRight + bottomLeft + 2 * bottom + bottomRight 167 }; 168 } 169 170 inline IntSize FELighting::LightingData::rightColumnNormal(int offset) const 160 171 { 161 172 int left = static_cast<int>(pixels->item(offset - cPixelSize + cAlphaChannelOffset)); … … 164 175 int topLeft = static_cast<int>(pixels->item(offset - cPixelSize + cAlphaChannelOffset)); 165 176 int top = static_cast<int>(pixels->item(offset + cAlphaChannelOffset)); 166 offset += widthMultipliedByPixelSize << 1;177 offset += 2 * widthMultipliedByPixelSize; 167 178 int bottomLeft = static_cast<int>(pixels->item(offset - cPixelSize + cAlphaChannelOffset)); 168 179 int bottom = static_cast<int>(pixels->item(offset + cAlphaChannelOffset)); 169 normalVector.setX(-topLeft + top - (left << 1) + (center << 1) - bottomLeft + bottom); 170 normalVector.setY(-topLeft - (top << 1) + bottomLeft + (bottom << 1)); 171 } 172 173 inline void FELighting::LightingData::bottomLeft(int offset, IntPoint& normalVector) 180 return { 181 -topLeft + top - 2 * left + 2 * center - bottomLeft + bottom, 182 -topLeft - 2 * top + bottomLeft + 2 * bottom 183 }; 184 } 185 186 inline IntSize FELighting::LightingData::bottomLeftNormal(int offset) const 174 187 { 175 188 int center = static_cast<int>(pixels->item(offset + cAlphaChannelOffset)); … … 178 191 int top = static_cast<int>(pixels->item(offset + cAlphaChannelOffset)); 179 192 int topRight = static_cast<int>(pixels->item(offset + cPixelSize + cAlphaChannelOffset)); 180 normalVector.setX(-top + topRight - (center << 1) + (right << 1)); 181 normalVector.setY(-(top << 1) - topRight + (center << 1) + right); 182 } 183 184 inline void FELighting::LightingData::bottomRow(int offset, IntPoint& normalVector) 193 return { 194 -top + topRight - 2 * center + 2 * right, 195 -2 * top - topRight + 2 * center + right 196 }; 197 } 198 199 inline IntSize FELighting::LightingData::bottomRowNormal(int offset) const 185 200 { 186 201 int left = static_cast<int>(pixels->item(offset - cPixelSize + cAlphaChannelOffset)); … … 191 206 int top = static_cast<int>(pixels->item(offset + cAlphaChannelOffset)); 192 207 int topRight = static_cast<int>(pixels->item(offset + cPixelSize + cAlphaChannelOffset)); 193 normalVector.setX(-topLeft + topRight - (left << 1) + (right << 1)); 194 normalVector.setY(-topLeft - (top << 1) - topRight + left + (center << 1) + right); 195 } 196 197 inline void FELighting::LightingData::bottomRight(int offset, IntPoint& normalVector) 208 return { 209 -topLeft + topRight - 2 * left + 2 * right, 210 -topLeft - 2 * top - topRight + left + 2 * center + right 211 }; 212 } 213 214 inline IntSize FELighting::LightingData::bottomRightNormal(int offset) const 198 215 { 199 216 int left = static_cast<int>(pixels->item(offset - cPixelSize + cAlphaChannelOffset)); … … 202 219 int topLeft = static_cast<int>(pixels->item(offset - cPixelSize + cAlphaChannelOffset)); 203 220 int top = static_cast<int>(pixels->item(offset + cAlphaChannelOffset)); 204 normalVector.setX(-topLeft + top - (left << 1) + (center << 1)); 205 normalVector.setY(-topLeft - (top << 1) + left + (center << 1)); 206 } 207 208 inline void FELighting::inlineSetPixel(int offset, LightingData& data, LightSource::PaintingData& paintingData, 209 int lightX, int lightY, float factorX, float factorY, IntPoint& normal2DVector) 221 return { 222 -topLeft + top - 2 * left + 2 * center, 223 topLeft - 2 * top + left + 2 * center 224 }; 225 } 226 227 inline void FELighting::inlineSetPixel(int offset, LightingData& data, LightSource::PaintingData& paintingData, int lightX, int lightY, float factorX, float factorY, IntSize normal2DVector) 210 228 { 211 229 m_lightSource->updatePaintingData(paintingData, lightX, lightY, static_cast<float>(data.pixels->item(offset + cAlphaChannelOffset)) * data.surfaceScale); 212 230 213 231 float lightStrength; 214 if ( !normal2DVector.x() && !normal2DVector.y()) {232 if (normal2DVector.isZero()) { 215 233 // Normal vector is (0, 0, 1). This is a quite frequent case. 216 234 if (m_lightingType == FELighting::DiffuseLighting) … … 227 245 } else { 228 246 FloatPoint3D normalVector; 229 normalVector.setX(factorX * static_cast<float>(normal2DVector. x()) * data.surfaceScale);230 normalVector.setY(factorY * static_cast<float>(normal2DVector. y()) * data.surfaceScale);247 normalVector.setX(factorX * static_cast<float>(normal2DVector.width()) * data.surfaceScale); 248 normalVector.setY(factorY * static_cast<float>(normal2DVector.height()) * data.surfaceScale); 231 249 normalVector.setZ(1); 232 250 float normalVectorLength = normalVector.length(); … … 255 273 } 256 274 257 void FELighting::setPixel(int offset, LightingData& data, LightSource::PaintingData& paintingData, 258 int lightX, int lightY, float factorX, float factorY, IntPoint& normalVector) 275 void FELighting::setPixel(int offset, LightingData& data, LightSource::PaintingData& paintingData, int lightX, int lightY, float factorX, float factorY, IntSize normalVector) 259 276 { 260 277 inlineSetPixel(offset, data, paintingData, lightX, lightY, factorX, factorY, normalVector); … … 263 280 inline void FELighting::platformApplyGenericPaint(LightingData& data, LightSource::PaintingData& paintingData, int startY, int endY) 264 281 { 265 IntPoint normalVector;266 int offset = 0;267 268 282 for (int y = startY; y < endY; ++y) { 269 offset = y * data.widthMultipliedByPixelSize + cPixelSize;283 int offset = y * data.widthMultipliedByPixelSize + cPixelSize; 270 284 for (int x = 1; x < data.widthDecreasedByOne; ++x, offset += cPixelSize) { 271 data.interior(offset, normalVector); 272 inlineSetPixel(offset, data, paintingData, x, y, cFactor1div4, cFactor1div4, normalVector); 285 inlineSetPixel(offset, data, paintingData, x, y, cFactor1div4, cFactor1div4, data.interiorNormal(offset)); 273 286 } 274 287 } … … 342 355 m_lightSource->initPaintingData(paintingData); 343 356 344 // Top/Left corner. 345 IntPoint normalVector; 357 // Top left. 346 358 int offset = 0; 347 data.topLeft(offset, normalVector); 348 setPixel(offset, data, paintingData, 0, 0, cFactor2div3, cFactor2div3, normalVector); 349 350 // Top/Right pixel. 359 setPixel(offset, data, paintingData, 0, 0, cFactor2div3, cFactor2div3, data.topLeftNormal(offset)); 360 361 // Top right. 351 362 offset = data.widthMultipliedByPixelSize - cPixelSize; 352 data.topRight(offset, normalVector); 353 setPixel(offset, data, paintingData, data.widthDecreasedByOne, 0, cFactor2div3, cFactor2div3, normalVector); 354 355 // Bottom/Left pixel. 363 setPixel(offset, data, paintingData, data.widthDecreasedByOne, 0, cFactor2div3, cFactor2div3, data.topRightNormal(offset)); 364 365 // Bottom left. 356 366 offset = data.heightDecreasedByOne * data.widthMultipliedByPixelSize; 357 data.bottomLeft(offset, normalVector); 358 setPixel(offset, data, paintingData, 0, data.heightDecreasedByOne, cFactor2div3, cFactor2div3, normalVector); 359 360 // Bottom/Right pixel. 367 setPixel(offset, data, paintingData, 0, data.heightDecreasedByOne, cFactor2div3, cFactor2div3, data.bottomLeftNormal(offset)); 368 369 // Bottom right. 361 370 offset = height * data.widthMultipliedByPixelSize - cPixelSize; 362 data.bottomRight(offset, normalVector); 363 setPixel(offset, data, paintingData, data.widthDecreasedByOne, data.heightDecreasedByOne, cFactor2div3, cFactor2div3, normalVector); 371 setPixel(offset, data, paintingData, data.widthDecreasedByOne, data.heightDecreasedByOne, cFactor2div3, cFactor2div3, data.bottomRightNormal(offset)); 364 372 365 373 if (width >= 3) { 366 374 // Top row. 367 375 offset = cPixelSize; 368 for (int x = 1; x < data.widthDecreasedByOne; ++x, offset += cPixelSize) { 369 data.topRow(offset, normalVector); 370 inlineSetPixel(offset, data, paintingData, x, 0, cFactor1div3, cFactor1div2, normalVector); 371 } 376 for (int x = 1; x < data.widthDecreasedByOne; ++x, offset += cPixelSize) 377 inlineSetPixel(offset, data, paintingData, x, 0, cFactor1div3, cFactor1div2, data.topRowNormal(offset)); 378 372 379 // Bottom row. 373 380 offset = data.heightDecreasedByOne * data.widthMultipliedByPixelSize + cPixelSize; 374 for (int x = 1; x < data.widthDecreasedByOne; ++x, offset += cPixelSize) { 375 data.bottomRow(offset, normalVector); 376 inlineSetPixel(offset, data, paintingData, x, data.heightDecreasedByOne, cFactor1div3, cFactor1div2, normalVector); 377 } 381 for (int x = 1; x < data.widthDecreasedByOne; ++x, offset += cPixelSize) 382 inlineSetPixel(offset, data, paintingData, x, data.heightDecreasedByOne, cFactor1div3, cFactor1div2, data.bottomRowNormal(offset)); 378 383 } 379 384 … … 381 386 // Left column. 382 387 offset = data.widthMultipliedByPixelSize; 383 for (int y = 1; y < data.heightDecreasedByOne; ++y, offset += data.widthMultipliedByPixelSize) { 384 data.leftColumn(offset, normalVector); 385 inlineSetPixel(offset, data, paintingData, 0, y, cFactor1div2, cFactor1div3, normalVector); 386 } 388 for (int y = 1; y < data.heightDecreasedByOne; ++y, offset += data.widthMultipliedByPixelSize) 389 inlineSetPixel(offset, data, paintingData, 0, y, cFactor1div2, cFactor1div3, data.leftColumnNormal(offset)); 390 387 391 // Right column. 388 offset = (data.widthMultipliedByPixelSize << 1) - cPixelSize; 389 for (int y = 1; y < data.heightDecreasedByOne; ++y, offset += data.widthMultipliedByPixelSize) { 390 data.rightColumn(offset, normalVector); 391 inlineSetPixel(offset, data, paintingData, data.widthDecreasedByOne, y, cFactor1div2, cFactor1div3, normalVector); 392 } 392 offset = 2 * data.widthMultipliedByPixelSize - cPixelSize; 393 for (int y = 1; y < data.heightDecreasedByOne; ++y, offset += data.widthMultipliedByPixelSize) 394 inlineSetPixel(offset, data, paintingData, data.widthDecreasedByOne, y, cFactor1div2, cFactor1div3, data.rightColumnNormal(offset)); 393 395 } 394 396 -
trunk/Source/WebCore/platform/graphics/filters/FELighting.h
r225026 r225088 73 73 int heightDecreasedByOne; 74 74 75 inline void topLeft(int offset, IntPoint& normalVector);76 inline void topRow(int offset, IntPoint& normalVector);77 inline void topRight(int offset, IntPoint& normalVector);78 inline void leftColumn(int offset, IntPoint& normalVector);79 inline void interior(int offset, IntPoint& normalVector);80 inline void rightColumn(int offset, IntPoint& normalVector);81 inline void bottomLeft(int offset, IntPoint& normalVector);82 inline void bottomRow(int offset, IntPoint& normalVector);83 inline void bottomRight(int offset, IntPoint& normalVector);75 inline IntSize topLeftNormal(int offset) const; 76 inline IntSize topRowNormal(int offset) const; 77 inline IntSize topRightNormal(int offset) const; 78 inline IntSize leftColumnNormal(int offset) const; 79 inline IntSize interiorNormal(int offset) const; 80 inline IntSize rightColumnNormal(int offset) const; 81 inline IntSize bottomLeftNormal(int offset) const; 82 inline IntSize bottomRowNormal(int offset) const; 83 inline IntSize bottomRightNormal(int offset) const; 84 84 }; 85 85 … … 102 102 bool drawLighting(Uint8ClampedArray*, int, int); 103 103 inline void inlineSetPixel(int offset, LightingData&, LightSource::PaintingData&, 104 int lightX, int lightY, float factorX, float factorY, IntPoint&normalVector);104 int lightX, int lightY, float factorX, float factorY, IntSize normalVector); 105 105 106 106 // Not worth to inline every occurence of setPixel. 107 107 void setPixel(int offset, LightingData&, LightSource::PaintingData&, 108 int lightX, int lightY, float factorX, float factorY, IntPoint&normalVector);108 int lightX, int lightY, float factorX, float factorY, IntSize normalVector); 109 109 110 110 void platformApplySoftware() override; … … 115 115 inline void platformApplyGeneric(LightingData&, LightSource::PaintingData&); 116 116 117 #if CPU(ARM_NEON) && CPU(ARM_TRADITIONAL) && COMPILER(GCC_OR_CLANG) 117 118 static int getPowerCoefficients(float exponent); 118 119 inline void platformApplyNeon(LightingData&, LightSource::PaintingData&); 120 #endif 119 121 120 122 LightingType m_lightingType;
Note:
See TracChangeset
for help on using the changeset viewer.