Index: src/core/SkLights.cpp |
diff --git a/src/core/SkLights.cpp b/src/core/SkLights.cpp |
index 7d8f9ed7a58407c7a877d4089ae0741d0107a10c..962997fc31436c4a3b4428a194210b227d9cef24 100644 |
--- a/src/core/SkLights.cpp |
+++ b/src/core/SkLights.cpp |
@@ -10,11 +10,18 @@ |
#include "SkReadBuffer.h" |
sk_sp<SkLights> SkLights::MakeFromBuffer(SkReadBuffer& buf) { |
+ Builder builder; |
+ |
+ SkColor3f ambColor; |
+ if (!buf.readScalarArray(&ambColor.fX, 3)) { |
+ return nullptr; |
+ } |
+ |
+ builder.setAmbientLightColor(ambColor); |
+ |
int numLights = buf.readInt(); |
- Builder builder; |
for (int l = 0; l < numLights; ++l) { |
- bool isAmbient = buf.readBool(); |
bool isPoint = buf.readBool(); |
SkColor3f color; |
@@ -22,35 +29,29 @@ sk_sp<SkLights> SkLights::MakeFromBuffer(SkReadBuffer& buf) { |
return nullptr; |
} |
- if (isAmbient) { |
- builder.add(Light::MakeAmbient(color)); |
- } else { |
- SkVector3 dirOrPos; |
- if (!buf.readScalarArray(&dirOrPos.fX, 3)) { |
- return nullptr; |
- } |
- SkScalar intensity = 0.0f; |
- if (isPoint) { |
- intensity = buf.readScalar(); |
- } |
+ SkVector3 dirOrPos; |
+ if (!buf.readScalarArray(&dirOrPos.fX, 3)) { |
+ return nullptr; |
+ } |
- sk_sp<SkImage> depthMap; |
- bool hasShadowMap = buf.readBool(); |
- if (hasShadowMap) { |
- if (!(depthMap = buf.readImage())) { |
- return nullptr; |
- } |
+ sk_sp<SkImage> depthMap; |
+ bool hasShadowMap = buf.readBool(); |
+ if (hasShadowMap) { |
+ if (!(depthMap = buf.readImage())) { |
+ return nullptr; |
} |
+ } |
- if (isPoint) { |
- Light light = Light::MakePoint(color, dirOrPos, intensity); |
- light.setShadowMap(depthMap); |
- builder.add(light); |
- } else { |
- Light light = Light::MakeDirectional(color, dirOrPos); |
- light.setShadowMap(depthMap); |
- builder.add(light); |
- } |
+ if (isPoint) { |
+ SkScalar intensity = 0.0f; |
+ intensity = buf.readScalar(); |
+ Light light = Light::MakePoint(color, dirOrPos, intensity); |
+ light.setShadowMap(depthMap); |
+ builder.add(light); |
+ } else { |
+ Light light = Light::MakeDirectional(color, dirOrPos); |
+ light.setShadowMap(depthMap); |
+ builder.add(light); |
} |
} |
@@ -58,29 +59,24 @@ sk_sp<SkLights> SkLights::MakeFromBuffer(SkReadBuffer& buf) { |
} |
void SkLights::flatten(SkWriteBuffer& buf) const { |
+ buf.writeScalarArray(&this->ambientLightColor().fX, 3); |
buf.writeInt(this->numLights()); |
for (int l = 0; l < this->numLights(); ++l) { |
const Light& light = this->light(l); |
- bool isAmbient = Light::kAmbient_LightType == light.type(); |
bool isPoint = Light::kPoint_LightType == light.type(); |
- buf.writeBool(isAmbient); |
buf.writeBool(isPoint); |
buf.writeScalarArray(&light.color().fX, 3); |
- if (!isAmbient) { |
- if (isPoint) { |
- buf.writeScalarArray(&light.pos().fX, 3); |
- buf.writeScalar(light.intensity()); |
- } else { |
- buf.writeScalarArray(&light.dir().fX, 3); |
- } |
- bool hasShadowMap = light.getShadowMap() != nullptr; |
- buf.writeBool(hasShadowMap); |
- if (hasShadowMap) { |
- buf.writeImage(light.getShadowMap()); |
- } |
+ buf.writeScalarArray(&light.dir().fX, 3); |
+ bool hasShadowMap = light.getShadowMap() != nullptr; |
+ buf.writeBool(hasShadowMap); |
+ if (hasShadowMap) { |
+ buf.writeImage(light.getShadowMap()); |
+ } |
+ if (isPoint) { |
+ buf.writeScalar(light.intensity()); |
} |
} |
} |