OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2015 Google Inc. | 3 * Copyright 2015 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 #include "SkBitmapProcState.h" | 9 #include "SkBitmapProcState.h" |
10 #include "SkColor.h" | 10 #include "SkColor.h" |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 fLightColor.fX = 0.0f; | 169 fLightColor.fX = 0.0f; |
170 fAmbientColor.fX = 0.0f; | 170 fAmbientColor.fX = 0.0f; |
171 fInvNormRotation.set(0.0f, 0.0f); | 171 fInvNormRotation.set(0.0f, 0.0f); |
172 } | 172 } |
173 | 173 |
174 void emitCode(EmitArgs& args) override { | 174 void emitCode(EmitArgs& args) override { |
175 | 175 |
176 GrGLFragmentBuilder* fpb = args.fBuilder->getFragmentShaderBuilder()
; | 176 GrGLFragmentBuilder* fpb = args.fBuilder->getFragmentShaderBuilder()
; |
177 | 177 |
178 // add uniforms | 178 // add uniforms |
179 const char* lightDirUniName = NULL; | 179 const char* lightDirUniName = nullptr; |
180 fLightDirUni = args.fBuilder->addUniform(GrGLProgramBuilder::kFragme
nt_Visibility, | 180 fLightDirUni = args.fBuilder->addUniform(GrGLProgramBuilder::kFragme
nt_Visibility, |
181 kVec3f_GrSLType, kDefault_G
rSLPrecision, | 181 kVec3f_GrSLType, kDefault_G
rSLPrecision, |
182 "LightDir", &lightDirUniNam
e); | 182 "LightDir", &lightDirUniNam
e); |
183 | 183 |
184 const char* lightColorUniName = NULL; | 184 const char* lightColorUniName = nullptr; |
185 fLightColorUni = args.fBuilder->addUniform(GrGLProgramBuilder::kFrag
ment_Visibility, | 185 fLightColorUni = args.fBuilder->addUniform(GrGLProgramBuilder::kFrag
ment_Visibility, |
186 kVec3f_GrSLType, kDefault
_GrSLPrecision, | 186 kVec3f_GrSLType, kDefault
_GrSLPrecision, |
187 "LightColor", &lightColor
UniName); | 187 "LightColor", &lightColor
UniName); |
188 | 188 |
189 const char* ambientColorUniName = NULL; | 189 const char* ambientColorUniName = nullptr; |
190 fAmbientColorUni = args.fBuilder->addUniform(GrGLProgramBuilder::kFr
agment_Visibility, | 190 fAmbientColorUni = args.fBuilder->addUniform(GrGLProgramBuilder::kFr
agment_Visibility, |
191 kVec3f_GrSLType, kDefau
lt_GrSLPrecision, | 191 kVec3f_GrSLType, kDefau
lt_GrSLPrecision, |
192 "AmbientColor", &ambien
tColorUniName); | 192 "AmbientColor", &ambien
tColorUniName); |
193 | 193 |
194 const char* xformUniName = NULL; | 194 const char* xformUniName = nullptr; |
195 fXformUni = args.fBuilder->addUniform(GrGLProgramBuilder::kFragment_
Visibility, | 195 fXformUni = args.fBuilder->addUniform(GrGLProgramBuilder::kFragment_
Visibility, |
196 kVec2f_GrSLType, kDefault_GrSL
Precision, | 196 kVec2f_GrSLType, kDefault_GrSL
Precision, |
197 "Xform", &xformUniName); | 197 "Xform", &xformUniName); |
198 | 198 |
199 fpb->codeAppend("vec4 diffuseColor = "); | 199 fpb->codeAppend("vec4 diffuseColor = "); |
200 fpb->appendTextureLookupAndModulate(args.fInputColor, args.fSamplers
[0], | 200 fpb->appendTextureLookupAndModulate(args.fInputColor, args.fSamplers
[0], |
201 args.fCoords[0].c_str(), | 201 args.fCoords[0].c_str(), |
202 args.fCoords[0].getType()); | 202 args.fCoords[0].getType()); |
203 fpb->codeAppend(";"); | 203 fpb->codeAppend(";"); |
204 | 204 |
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
571 SkMatrix normLocalM; | 571 SkMatrix normLocalM; |
572 bool hasNormLocalM = buf.readBool(); | 572 bool hasNormLocalM = buf.readBool(); |
573 if (hasNormLocalM) { | 573 if (hasNormLocalM) { |
574 buf.readMatrix(&normLocalM); | 574 buf.readMatrix(&normLocalM); |
575 } else { | 575 } else { |
576 normLocalM.reset(); | 576 normLocalM.reset(); |
577 } | 577 } |
578 | 578 |
579 SkBitmap diffuse; | 579 SkBitmap diffuse; |
580 if (!buf.readBitmap(&diffuse)) { | 580 if (!buf.readBitmap(&diffuse)) { |
581 return NULL; | 581 return nullptr; |
582 } | 582 } |
583 diffuse.setImmutable(); | 583 diffuse.setImmutable(); |
584 | 584 |
585 SkBitmap normal; | 585 SkBitmap normal; |
586 if (!buf.readBitmap(&normal)) { | 586 if (!buf.readBitmap(&normal)) { |
587 return NULL; | 587 return nullptr; |
588 } | 588 } |
589 normal.setImmutable(); | 589 normal.setImmutable(); |
590 | 590 |
591 int numLights = buf.readInt(); | 591 int numLights = buf.readInt(); |
592 | 592 |
593 SkLightingShader::Lights::Builder builder; | 593 SkLightingShader::Lights::Builder builder; |
594 | 594 |
595 for (int l = 0; l < numLights; ++l) { | 595 for (int l = 0; l < numLights; ++l) { |
596 bool isAmbient = buf.readBool(); | 596 bool isAmbient = buf.readBool(); |
597 | 597 |
598 SkColor3f color; | 598 SkColor3f color; |
599 if (!buf.readScalarArray(&color.fX, 3)) { | 599 if (!buf.readScalarArray(&color.fX, 3)) { |
600 return NULL; | 600 return nullptr; |
601 } | 601 } |
602 | 602 |
603 if (isAmbient) { | 603 if (isAmbient) { |
604 builder.add(SkLight(color)); | 604 builder.add(SkLight(color)); |
605 } else { | 605 } else { |
606 SkVector3 dir; | 606 SkVector3 dir; |
607 if (!buf.readScalarArray(&dir.fX, 3)) { | 607 if (!buf.readScalarArray(&dir.fX, 3)) { |
608 return NULL; | 608 return nullptr; |
609 } | 609 } |
610 builder.add(SkLight(color, dir)); | 610 builder.add(SkLight(color, dir)); |
611 } | 611 } |
612 } | 612 } |
613 | 613 |
614 SkAutoTUnref<const SkLightingShader::Lights> lights(builder.finish()); | 614 SkAutoTUnref<const SkLightingShader::Lights> lights(builder.finish()); |
615 | 615 |
616 return new SkLightingShaderImpl(diffuse, normal, lights, SkVector::Make(1.0f
, 0.0f), | 616 return new SkLightingShaderImpl(diffuse, normal, lights, SkVector::Make(1.0f
, 0.0f), |
617 &diffLocalM, &normLocalM); | 617 &diffLocalM, &normLocalM); |
618 } | 618 } |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
658 | 658 |
659 SkShader::Context* SkLightingShaderImpl::onCreateContext(const ContextRec& rec, | 659 SkShader::Context* SkLightingShaderImpl::onCreateContext(const ContextRec& rec, |
660 void* storage) const { | 660 void* storage) const { |
661 | 661 |
662 SkMatrix diffTotalInv; | 662 SkMatrix diffTotalInv; |
663 // computeTotalInverse was called in SkShader::createContext so we know it w
ill succeed | 663 // computeTotalInverse was called in SkShader::createContext so we know it w
ill succeed |
664 SkAssertResult(this->computeTotalInverse(rec, &diffTotalInv)); | 664 SkAssertResult(this->computeTotalInverse(rec, &diffTotalInv)); |
665 | 665 |
666 SkMatrix normTotalInv; | 666 SkMatrix normTotalInv; |
667 if (!this->computeNormTotalInverse(rec, &normTotalInv)) { | 667 if (!this->computeNormTotalInverse(rec, &normTotalInv)) { |
668 return NULL; | 668 return nullptr; |
669 } | 669 } |
670 | 670 |
671 void* diffuseStateStorage = (char*)storage + sizeof(LightingShaderContext); | 671 void* diffuseStateStorage = (char*)storage + sizeof(LightingShaderContext); |
672 SkBitmapProcState* diffuseState = new (diffuseStateStorage) SkBitmapProcStat
e; | 672 SkBitmapProcState* diffuseState = new (diffuseStateStorage) SkBitmapProcStat
e; |
673 SkASSERT(diffuseState); | 673 SkASSERT(diffuseState); |
674 | 674 |
675 diffuseState->fTileModeX = SkShader::kClamp_TileMode; | 675 diffuseState->fTileModeX = SkShader::kClamp_TileMode; |
676 diffuseState->fTileModeY = SkShader::kClamp_TileMode; | 676 diffuseState->fTileModeY = SkShader::kClamp_TileMode; |
677 diffuseState->fOrigBitmap = fDiffuseMap; | 677 diffuseState->fOrigBitmap = fDiffuseMap; |
678 if (!diffuseState->chooseProcs(diffTotalInv, *rec.fPaint)) { | 678 if (!diffuseState->chooseProcs(diffTotalInv, *rec.fPaint)) { |
679 diffuseState->~SkBitmapProcState(); | 679 diffuseState->~SkBitmapProcState(); |
680 return NULL; | 680 return nullptr; |
681 } | 681 } |
682 | 682 |
683 void* normalStateStorage = (char*)storage + sizeof(LightingShaderContext) +
sizeof(SkBitmapProcState); | 683 void* normalStateStorage = (char*)storage + sizeof(LightingShaderContext) +
sizeof(SkBitmapProcState); |
684 SkBitmapProcState* normalState = new (normalStateStorage) SkBitmapProcState; | 684 SkBitmapProcState* normalState = new (normalStateStorage) SkBitmapProcState; |
685 SkASSERT(normalState); | 685 SkASSERT(normalState); |
686 | 686 |
687 normalState->fTileModeX = SkShader::kClamp_TileMode; | 687 normalState->fTileModeX = SkShader::kClamp_TileMode; |
688 normalState->fTileModeY = SkShader::kClamp_TileMode; | 688 normalState->fTileModeY = SkShader::kClamp_TileMode; |
689 normalState->fOrigBitmap = fNormalMap; | 689 normalState->fOrigBitmap = fNormalMap; |
690 if (!normalState->chooseProcs(normTotalInv, *rec.fPaint)) { | 690 if (!normalState->chooseProcs(normTotalInv, *rec.fPaint)) { |
691 diffuseState->~SkBitmapProcState(); | 691 diffuseState->~SkBitmapProcState(); |
692 normalState->~SkBitmapProcState(); | 692 normalState->~SkBitmapProcState(); |
693 return NULL; | 693 return nullptr; |
694 } | 694 } |
695 | 695 |
696 return new (storage) LightingShaderContext(*this, rec, diffuseState, normalS
tate); | 696 return new (storage) LightingShaderContext(*this, rec, diffuseState, normalS
tate); |
697 } | 697 } |
698 | 698 |
699 /////////////////////////////////////////////////////////////////////////////// | 699 /////////////////////////////////////////////////////////////////////////////// |
700 | 700 |
701 static bool bitmap_is_too_big(const SkBitmap& bm) { | 701 static bool bitmap_is_too_big(const SkBitmap& bm) { |
702 // SkBitmapProcShader stores bitmap coordinates in a 16bit buffer, as it | 702 // SkBitmapProcShader stores bitmap coordinates in a 16bit buffer, as it |
703 // communicates between its matrix-proc and its sampler-proc. Until we can | 703 // communicates between its matrix-proc and its sampler-proc. Until we can |
(...skipping 21 matching lines...) Expand all Loading... |
725 normLocalM); | 725 normLocalM); |
726 } | 726 } |
727 | 727 |
728 /////////////////////////////////////////////////////////////////////////////// | 728 /////////////////////////////////////////////////////////////////////////////// |
729 | 729 |
730 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingShader) | 730 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingShader) |
731 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkLightingShaderImpl) | 731 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkLightingShaderImpl) |
732 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END | 732 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END |
733 | 733 |
734 /////////////////////////////////////////////////////////////////////////////// | 734 /////////////////////////////////////////////////////////////////////////////// |
OLD | NEW |