OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkBitmapProcState.h" | 8 #include "SkBitmapProcState.h" |
9 #include "SkColor.h" | 9 #include "SkColor.h" |
10 #include "SkEmptyShader.h" | 10 #include "SkEmptyShader.h" |
(...skipping 588 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
599 SkVector3 dir; | 599 SkVector3 dir; |
600 if (!buf.readScalarArray(&dir.fX, 3)) { | 600 if (!buf.readScalarArray(&dir.fX, 3)) { |
601 return nullptr; | 601 return nullptr; |
602 } | 602 } |
603 builder.add(SkLight(color, dir)); | 603 builder.add(SkLight(color, dir)); |
604 } | 604 } |
605 } | 605 } |
606 | 606 |
607 SkAutoTUnref<const SkLightingShader::Lights> lights(builder.finish()); | 607 SkAutoTUnref<const SkLightingShader::Lights> lights(builder.finish()); |
608 | 608 |
609 return sk_make_sp<SkLightingShaderImpl>(diffuse, normal, lights, SkVector::M
ake(1.0f, 0.0f), | 609 SkVector invNormRotation = {1,0}; |
| 610 if (!buf.isVersionLT(SkReadBuffer::kLightingShaderWritesInvNormRotation)) { |
| 611 invNormRotation = buf.readPoint(); |
| 612 } |
| 613 |
| 614 return sk_make_sp<SkLightingShaderImpl>(diffuse, normal, lights, invNormRota
tion, |
610 &diffLocalM, &normLocalM); | 615 &diffLocalM, &normLocalM); |
611 } | 616 } |
612 | 617 |
613 void SkLightingShaderImpl::flatten(SkWriteBuffer& buf) const { | 618 void SkLightingShaderImpl::flatten(SkWriteBuffer& buf) const { |
614 this->INHERITED::flatten(buf); | 619 this->INHERITED::flatten(buf); |
615 | 620 |
616 bool hasNormLocalM = !fNormLocalMatrix.isIdentity(); | 621 bool hasNormLocalM = !fNormLocalMatrix.isIdentity(); |
617 buf.writeBool(hasNormLocalM); | 622 buf.writeBool(hasNormLocalM); |
618 if (hasNormLocalM) { | 623 if (hasNormLocalM) { |
619 buf.writeMatrix(fNormLocalMatrix); | 624 buf.writeMatrix(fNormLocalMatrix); |
620 } | 625 } |
621 | 626 |
622 buf.writeBitmap(fDiffuseMap); | 627 buf.writeBitmap(fDiffuseMap); |
623 buf.writeBitmap(fNormalMap); | 628 buf.writeBitmap(fNormalMap); |
624 | 629 |
625 buf.writeInt(fLights->numLights()); | 630 buf.writeInt(fLights->numLights()); |
626 for (int l = 0; l < fLights->numLights(); ++l) { | 631 for (int l = 0; l < fLights->numLights(); ++l) { |
627 const SkLight& light = fLights->light(l); | 632 const SkLight& light = fLights->light(l); |
628 | 633 |
629 bool isAmbient = SkLight::kAmbient_LightType == light.type(); | 634 bool isAmbient = SkLight::kAmbient_LightType == light.type(); |
630 | 635 |
631 buf.writeBool(isAmbient); | 636 buf.writeBool(isAmbient); |
632 buf.writeScalarArray(&light.color().fX, 3); | 637 buf.writeScalarArray(&light.color().fX, 3); |
633 if (!isAmbient) { | 638 if (!isAmbient) { |
634 buf.writeScalarArray(&light.dir().fX, 3); | 639 buf.writeScalarArray(&light.dir().fX, 3); |
635 } | 640 } |
636 } | 641 } |
| 642 buf.writePoint(fInvNormRotation); |
637 } | 643 } |
638 | 644 |
639 bool SkLightingShaderImpl::computeNormTotalInverse(const ContextRec& rec, | 645 bool SkLightingShaderImpl::computeNormTotalInverse(const ContextRec& rec, |
640 SkMatrix* normTotalInverse) c
onst { | 646 SkMatrix* normTotalInverse) c
onst { |
641 SkMatrix total; | 647 SkMatrix total; |
642 total.setConcat(*rec.fMatrix, fNormLocalMatrix); | 648 total.setConcat(*rec.fMatrix, fNormLocalMatrix); |
643 | 649 |
644 const SkMatrix* m = &total; | 650 const SkMatrix* m = &total; |
645 if (rec.fLocalMatrix) { | 651 if (rec.fLocalMatrix) { |
646 total.setConcat(*m, *rec.fLocalMatrix); | 652 total.setConcat(*m, *rec.fLocalMatrix); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
716 normLocalM); | 722 normLocalM); |
717 } | 723 } |
718 | 724 |
719 /////////////////////////////////////////////////////////////////////////////// | 725 /////////////////////////////////////////////////////////////////////////////// |
720 | 726 |
721 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingShader) | 727 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingShader) |
722 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkLightingShaderImpl) | 728 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkLightingShaderImpl) |
723 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END | 729 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END |
724 | 730 |
725 /////////////////////////////////////////////////////////////////////////////// | 731 /////////////////////////////////////////////////////////////////////////////// |
OLD | NEW |