Minor cleanup of SkLightingShader
authorrobertphillips <robertphillips@google.com>
Thu, 30 Jul 2015 17:11:42 +0000 (10:11 -0700)
committerCommit bot <commit-bot@chromium.org>
Thu, 30 Jul 2015 17:11:42 +0000 (10:11 -0700)
Fix:
  PM component swizzling on Macs
  Serialization

Review URL: https://codereview.chromium.org/1270533003

src/effects/SkLightingShader.cpp
src/ports/SkGlobalInitialization_chromium.cpp
src/ports/SkGlobalInitialization_default.cpp

index 7dcba959416751a22327e4a2186e3125dc23b30c..7b55626f55a3d5ae5e6b287b5fe74c17be40b65d 100644 (file)
@@ -15,7 +15,7 @@
 #include "SkReadBuffer.h"
 #include "SkWriteBuffer.h"
 
-///////////////////////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////////
 
 /*
    SkLightingShader TODOs:
@@ -93,7 +93,7 @@ public:
     };
 
     SK_TO_STRING_OVERRIDE()
-    SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(LightingShader)
+    SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkLightingShaderImpl)
 
 protected:
     void flatten(SkWriteBuffer&) const override;
@@ -105,6 +105,8 @@ private:
     SkLightingShader::Light fLight;
     SkColor                 fAmbientColor;  // linear (unpremul) color
 
+    friend class SkLightingShader;
+
     typedef SkShader INHERITED;
 };
 
@@ -447,9 +449,9 @@ void SkLightingShaderImpl::LightingShaderContext::shadeSpan(int x, int y,
 
         for (int i = 0; i < n; ++i) {
             SkASSERT(0xFF == SkColorGetA(tmpNormal2[i]));  // opaque -> unpremul
-            norm.set(SkIntToScalar(SkColorGetR(tmpNormal2[i]))-127.0f,
-                     SkIntToScalar(SkColorGetG(tmpNormal2[i]))-127.0f,
-                     SkIntToScalar(SkColorGetB(tmpNormal2[i]))-127.0f);
+            norm.set(SkIntToScalar(SkGetPackedR32(tmpNormal2[i]))-127.0f,
+                     SkIntToScalar(SkGetPackedG32(tmpNormal2[i]))-127.0f,
+                     SkIntToScalar(SkGetPackedB32(tmpNormal2[i]))-127.0f);
             norm.normalize();
 
             SkColor diffColor = SkUnPreMultiply::PMColorToColor(tmpColor2[i]);
@@ -582,3 +584,9 @@ SkShader* SkLightingShader::Create(const SkBitmap& diffuse, const SkBitmap& norm
 }
 
 ///////////////////////////////////////////////////////////////////////////////
+
+SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingShader)
+    SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkLightingShaderImpl)
+SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END
+
+///////////////////////////////////////////////////////////////////////////////
index b3eb3aa74352be5366bb2919d5e3acaeeceaeecb..3aecbd5471c71eb2a299b9c0f5486c5c64e2dfb4 100644 (file)
@@ -41,6 +41,7 @@
 #include "SkLayerRasterizer.h"
 #include "SkLerpXfermode.h"
 #include "SkLightingImageFilter.h"
+#include "../effects/SkLightingShader.h"
 #include "SkLocalMatrixShader.h"
 #include "SkLumaColorFilter.h"
 #include "SkMagnifierImageFilter.h"
@@ -132,6 +133,7 @@ public:
         SkColorFilter::InitializeFlattenables();
         SkGradientShader::InitializeFlattenables();
         SkLightingImageFilter::InitializeFlattenables();
+        SkLightingShader::InitializeFlattenables();
         SkTableColorFilter::InitializeFlattenables();
         SkXfermode::InitializeFlattenables();
     }
index fb496f65cb8ab07967b5811ab7fe0021c8dd5189..47b00b96f16bfb7a2f6874f0a1e5ed5d0534e5c7 100644 (file)
@@ -37,6 +37,7 @@
 #include "SkLayerRasterizer.h"
 #include "SkLerpXfermode.h"
 #include "SkLightingImageFilter.h"
+#include "../effects/SkLightingShader.h"
 #include "SkLocalMatrixShader.h"
 #include "SkLumaColorFilter.h"
 #include "SkMagnifierImageFilter.h"
@@ -111,6 +112,7 @@ public:
         SkColorFilter::InitializeFlattenables();
         SkGradientShader::InitializeFlattenables();
         SkLightingImageFilter::InitializeFlattenables();
+        SkLightingShader::InitializeFlattenables();
         SkTableColorFilter::InitializeFlattenables();
         SkXfermode::InitializeFlattenables();
     }