Bug 1120294 - Modify the svg luminance calculating for reducing memcpy. r=longsonr
authorEthan Lin <etlin@mozilla.com>
Mon, 12 Jan 2015 21:51:00 -0500
changeset 250706 fba277ed63b8cb4b65d6978d2e02a64349bf169d
parent 250705 da63d41b57e9de3d91d1660e36fc16a1ef2fa189
child 250707 d8467e9bbae8fd4d894c2e31ae08cf6d128fabb4
push id4610
push userjlund@mozilla.com
push dateMon, 30 Mar 2015 18:32:55 +0000
treeherdermozilla-beta@4df54044d9ef [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerslongsonr
bugs1120294
milestone38.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1120294 - Modify the svg luminance calculating for reducing memcpy. r=longsonr
layout/svg/nsSVGMaskFrame.cpp
--- a/layout/svg/nsSVGMaskFrame.cpp
+++ b/layout/svg/nsSVGMaskFrame.cpp
@@ -120,36 +120,45 @@ ComputeLinearRGBLuminanceMask(const uint
   uint8_t *destPixel = aDestData;
 
   for (int32_t y = 0; y < aSize.height; y++) {
     for (int32_t x = 0; x < aSize.width; x++) {
       uint8_t a = sourcePixel[GFX_ARGB32_OFFSET_A];
 
       // unpremultiply
       if (a) {
-        uint8_t tempPixel[4];
-        memcpy(tempPixel, sourcePixel, 4);
-        if (a != 255) {
+        if (a == 255) {
+          /* sRGB -> linearRGB -> intensity */
+          *destPixel =
+            static_cast<uint8_t>
+                       ((gsRGBToLinearRGBMap[sourcePixel[GFX_ARGB32_OFFSET_R]] *
+                         redFactor +
+                         gsRGBToLinearRGBMap[sourcePixel[GFX_ARGB32_OFFSET_G]] *
+                         greenFactor +
+                         gsRGBToLinearRGBMap[sourcePixel[GFX_ARGB32_OFFSET_B]] *
+                         blueFactor) >> 8);
+        } else {
+          uint8_t tempPixel[4];
           tempPixel[GFX_ARGB32_OFFSET_B] =
-            (255 * tempPixel[GFX_ARGB32_OFFSET_B]) / a;
+            (255 * sourcePixel[GFX_ARGB32_OFFSET_B]) / a;
           tempPixel[GFX_ARGB32_OFFSET_G] =
-            (255 * tempPixel[GFX_ARGB32_OFFSET_G]) / a;
+            (255 * sourcePixel[GFX_ARGB32_OFFSET_G]) / a;
           tempPixel[GFX_ARGB32_OFFSET_R] =
-            (255 * tempPixel[GFX_ARGB32_OFFSET_R]) / a;
+            (255 * sourcePixel[GFX_ARGB32_OFFSET_R]) / a;
+
+          /* sRGB -> linearRGB -> intensity */
+          *destPixel =
+            static_cast<uint8_t>
+                       (((gsRGBToLinearRGBMap[tempPixel[GFX_ARGB32_OFFSET_R]] *
+                          redFactor +
+                          gsRGBToLinearRGBMap[tempPixel[GFX_ARGB32_OFFSET_G]] *
+                          greenFactor +
+                          gsRGBToLinearRGBMap[tempPixel[GFX_ARGB32_OFFSET_B]] *
+                          blueFactor) >> 8) * (a / 255.0f));
         }
-
-        /* sRGB -> linearRGB -> intensity */
-        *destPixel =
-          static_cast<uint8_t>
-                     (((gsRGBToLinearRGBMap[tempPixel[GFX_ARGB32_OFFSET_R]] *
-                        redFactor +
-                        gsRGBToLinearRGBMap[tempPixel[GFX_ARGB32_OFFSET_G]] *
-                        greenFactor +
-                        gsRGBToLinearRGBMap[tempPixel[GFX_ARGB32_OFFSET_B]] *
-                        blueFactor) >> 8) * (a / 255.0f));
       } else {
         *destPixel = 0;
       }
       sourcePixel += 4;
       destPixel++;
     }
     sourcePixel += sourceOffset;
     destPixel += destOffset;