Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 | |
| 2 /* | |
| 3 * Copyright 2016 Google Inc. | |
| 4 * | |
| 5 * Use of this source code is governed by a BSD-style license that can be | |
| 6 * found in the LICENSE file. | |
| 7 */ | |
| 8 | |
| 9 #include "SkLights.h" | |
| 10 #include "SkReadBuffer.h" | |
| 11 | |
| 12 | |
| 13 | |
| 14 sk_sp<SkLights> SkLights::MakeFromBuffer(SkReadBuffer& buf) { | |
| 15 int numLights = buf.readInt(); | |
| 16 | |
| 17 Builder builder; | |
| 18 for (int l = 0; l < numLights; ++l) { | |
| 19 bool isAmbient = buf.readBool(); | |
| 20 bool isPoint = buf.readBool(); | |
| 21 | |
| 22 SkColor3f color; | |
| 23 if (!buf.readScalarArray(&color.fX, 3)) { | |
| 24 return nullptr; | |
| 25 } | |
| 26 | |
| 27 if (isAmbient) { | |
| 28 builder.add(Light::MakeAmbient(color)); | |
| 29 } else { | |
| 30 SkVector3 dirOrPos; | |
| 31 if (!buf.readScalarArray(&dirOrPos.fX, 3)) { | |
| 32 return nullptr; | |
| 33 } | |
| 34 | |
| 35 sk_sp<SkImage> depthMap; | |
| 36 bool hasShadowMap = buf.readBool(); | |
| 37 if (hasShadowMap) { | |
| 38 if (!(depthMap = sk_ref_sp<SkImage>(buf.readImage()))) { | |
| 39 return nullptr; | |
| 40 } | |
|
robertphillips
2016/08/12 14:27:49
Don't need this else clause - sk_sp self inits
vjiaoblack
2016/08/12 14:56:46
Done.
| |
| 41 } else { | |
| 42 depthMap = nullptr; | |
| 43 } | |
| 44 | |
| 45 if (isPoint) { | |
| 46 Light light = Light::MakePoint(color, dirOrPos); | |
| 47 light.setShadowMap(depthMap); | |
| 48 builder.add(light); | |
| 49 } else { | |
| 50 Light light = Light::MakeDirectional(color, dirOrPos); | |
| 51 light.setShadowMap(depthMap); | |
| 52 builder.add(light); | |
| 53 } | |
| 54 } | |
| 55 } | |
| 56 | |
| 57 return builder.finish(); | |
| 58 } | |
| 59 | |
| 60 void SkLights::flatten(SkWriteBuffer& buf) const { | |
| 61 | |
| 62 buf.writeInt(this->numLights()); | |
| 63 for (int l = 0; l < this->numLights(); ++l) { | |
| 64 const Light& light = this->light(l); | |
| 65 | |
| 66 bool isAmbient = Light::kAmbient_LightType == light.type(); | |
| 67 bool isPoint = Light::kPoint_LightType == light.type(); | |
| 68 | |
| 69 buf.writeBool(isAmbient); | |
| 70 buf.writeBool(isPoint); | |
| 71 buf.writeScalarArray(&light.color().fX, 3); | |
| 72 if (!isAmbient) { | |
| 73 buf.writeScalarArray(&light.dir().fX, 3); | |
| 74 } | |
| 75 | |
| 76 bool hasShadowMap = light.getShadowMap() != nullptr; | |
| 77 buf.writeBool(hasShadowMap); | |
| 78 if (hasShadowMap) { | |
| 79 buf.writeImage(light.getShadowMap()); | |
| 80 } | |
| 81 } | |
| 82 } | |
| OLD | NEW |