OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 The Android Open Source Project | 2 * Copyright 2012 The Android Open Source Project |
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 "SkLightingImageFilter.h" | 8 #include "SkLightingImageFilter.h" |
9 #include "SkBitmap.h" | 9 #include "SkBitmap.h" |
10 #include "SkColorPriv.h" | 10 #include "SkColorPriv.h" |
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
440 typedef SkRefCnt INHERITED; | 440 typedef SkRefCnt INHERITED; |
441 }; | 441 }; |
442 | 442 |
443 /////////////////////////////////////////////////////////////////////////////// | 443 /////////////////////////////////////////////////////////////////////////////// |
444 | 444 |
445 class GrGLDistantLight : public GrGLLight { | 445 class GrGLDistantLight : public GrGLLight { |
446 public: | 446 public: |
447 virtual ~GrGLDistantLight() {} | 447 virtual ~GrGLDistantLight() {} |
448 virtual void setData(const GrGLUniformManager&, const SkLight* light) const
SK_OVERRIDE; | 448 virtual void setData(const GrGLUniformManager&, const SkLight* light) const
SK_OVERRIDE; |
449 virtual void emitSurfaceToLight(GrGLShaderBuilder*, const char* z) SK_OVERRI
DE; | 449 virtual void emitSurfaceToLight(GrGLShaderBuilder*, const char* z) SK_OVERRI
DE; |
| 450 |
450 private: | 451 private: |
451 typedef GrGLLight INHERITED; | 452 typedef GrGLLight INHERITED; |
452 UniformHandle fDirectionUni; | 453 UniformHandle fDirectionUni; |
453 }; | 454 }; |
454 | 455 |
455 /////////////////////////////////////////////////////////////////////////////// | 456 /////////////////////////////////////////////////////////////////////////////// |
456 | 457 |
457 class GrGLPointLight : public GrGLLight { | 458 class GrGLPointLight : public GrGLLight { |
458 public: | 459 public: |
459 virtual ~GrGLPointLight() {} | 460 virtual ~GrGLPointLight() {} |
460 virtual void setData(const GrGLUniformManager&, const SkLight* light) const
SK_OVERRIDE; | 461 virtual void setData(const GrGLUniformManager&, const SkLight* light) const
SK_OVERRIDE; |
461 virtual void emitSurfaceToLight(GrGLShaderBuilder*, const char* z) SK_OVERRI
DE; | 462 virtual void emitSurfaceToLight(GrGLShaderBuilder*, const char* z) SK_OVERRI
DE; |
| 463 |
462 private: | 464 private: |
463 typedef GrGLLight INHERITED; | 465 typedef GrGLLight INHERITED; |
464 SkPoint3 fLocation; | 466 SkPoint3 fLocation; |
465 UniformHandle fLocationUni; | 467 UniformHandle fLocationUni; |
466 }; | 468 }; |
467 | 469 |
468 /////////////////////////////////////////////////////////////////////////////// | 470 /////////////////////////////////////////////////////////////////////////////// |
469 | 471 |
470 class GrGLSpotLight : public GrGLLight { | 472 class GrGLSpotLight : public GrGLLight { |
471 public: | 473 public: |
472 virtual ~GrGLSpotLight() {} | 474 virtual ~GrGLSpotLight() {} |
473 virtual void setData(const GrGLUniformManager&, const SkLight* light) const
SK_OVERRIDE; | 475 virtual void setData(const GrGLUniformManager&, const SkLight* light) const
SK_OVERRIDE; |
474 virtual void emitSurfaceToLight(GrGLShaderBuilder*, const char* z) SK_OVERRI
DE; | 476 virtual void emitSurfaceToLight(GrGLShaderBuilder*, const char* z) SK_OVERRI
DE; |
475 virtual void emitLightColor(GrGLShaderBuilder*, const char *surfaceToLight)
SK_OVERRIDE; | 477 virtual void emitLightColor(GrGLShaderBuilder*, const char *surfaceToLight)
SK_OVERRIDE; |
| 478 |
476 private: | 479 private: |
477 typedef GrGLLight INHERITED; | 480 typedef GrGLLight INHERITED; |
478 | 481 |
479 SkString fLightColorFunc; | 482 SkString fLightColorFunc; |
480 UniformHandle fLocationUni; | 483 UniformHandle fLocationUni; |
481 UniformHandle fExponentUni; | 484 UniformHandle fExponentUni; |
482 UniformHandle fCosOuterConeAngleUni; | 485 UniformHandle fCosOuterConeAngleUni; |
483 UniformHandle fCosInnerConeAngleUni; | 486 UniformHandle fCosInnerConeAngleUni; |
484 UniformHandle fConeScaleUni; | 487 UniformHandle fConeScaleUni; |
485 UniformHandle fSUni; | 488 UniformHandle fSUni; |
(...skipping 16 matching lines...) Expand all Loading... |
502 kDistant_LightType, | 505 kDistant_LightType, |
503 kPoint_LightType, | 506 kPoint_LightType, |
504 kSpot_LightType, | 507 kSpot_LightType, |
505 }; | 508 }; |
506 virtual LightType type() const = 0; | 509 virtual LightType type() const = 0; |
507 const SkPoint3& color() const { return fColor; } | 510 const SkPoint3& color() const { return fColor; } |
508 virtual GrGLLight* createGLLight() const = 0; | 511 virtual GrGLLight* createGLLight() const = 0; |
509 virtual bool isEqual(const SkLight& other) const { | 512 virtual bool isEqual(const SkLight& other) const { |
510 return fColor == other.fColor; | 513 return fColor == other.fColor; |
511 } | 514 } |
| 515 // Called to know whether the generated GrGLLight will require access to the
fragment position. |
| 516 virtual bool requiresFragmentPosition() const = 0; |
512 | 517 |
513 protected: | 518 protected: |
514 SkLight(SkColor color) | 519 SkLight(SkColor color) |
515 : fColor(SkIntToScalar(SkColorGetR(color)), | 520 : fColor(SkIntToScalar(SkColorGetR(color)), |
516 SkIntToScalar(SkColorGetG(color)), | 521 SkIntToScalar(SkColorGetG(color)), |
517 SkIntToScalar(SkColorGetB(color))) {} | 522 SkIntToScalar(SkColorGetB(color))) {} |
518 SkLight(SkFlattenableReadBuffer& buffer) | 523 SkLight(SkFlattenableReadBuffer& buffer) |
519 : INHERITED(buffer) { | 524 : INHERITED(buffer) { |
520 fColor = readPoint3(buffer); | 525 fColor = readPoint3(buffer); |
521 } | 526 } |
(...skipping 24 matching lines...) Expand all Loading... |
546 virtual LightType type() const { return kDistant_LightType; } | 551 virtual LightType type() const { return kDistant_LightType; } |
547 const SkPoint3& direction() const { return fDirection; } | 552 const SkPoint3& direction() const { return fDirection; } |
548 virtual GrGLLight* createGLLight() const SK_OVERRIDE { | 553 virtual GrGLLight* createGLLight() const SK_OVERRIDE { |
549 #if SK_SUPPORT_GPU | 554 #if SK_SUPPORT_GPU |
550 return SkNEW(GrGLDistantLight); | 555 return SkNEW(GrGLDistantLight); |
551 #else | 556 #else |
552 SkDEBUGFAIL("Should not call in GPU-less build"); | 557 SkDEBUGFAIL("Should not call in GPU-less build"); |
553 return NULL; | 558 return NULL; |
554 #endif | 559 #endif |
555 } | 560 } |
| 561 virtual bool requiresFragmentPosition() const SK_OVERRIDE { return false; } |
| 562 |
556 virtual bool isEqual(const SkLight& other) const SK_OVERRIDE { | 563 virtual bool isEqual(const SkLight& other) const SK_OVERRIDE { |
557 if (other.type() != kDistant_LightType) { | 564 if (other.type() != kDistant_LightType) { |
558 return false; | 565 return false; |
559 } | 566 } |
560 | 567 |
561 const SkDistantLight& o = static_cast<const SkDistantLight&>(other); | 568 const SkDistantLight& o = static_cast<const SkDistantLight&>(other); |
562 return INHERITED::isEqual(other) && | 569 return INHERITED::isEqual(other) && |
563 fDirection == o.fDirection; | 570 fDirection == o.fDirection; |
564 } | 571 } |
565 | 572 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
597 virtual LightType type() const { return kPoint_LightType; } | 604 virtual LightType type() const { return kPoint_LightType; } |
598 const SkPoint3& location() const { return fLocation; } | 605 const SkPoint3& location() const { return fLocation; } |
599 virtual GrGLLight* createGLLight() const SK_OVERRIDE { | 606 virtual GrGLLight* createGLLight() const SK_OVERRIDE { |
600 #if SK_SUPPORT_GPU | 607 #if SK_SUPPORT_GPU |
601 return SkNEW(GrGLPointLight); | 608 return SkNEW(GrGLPointLight); |
602 #else | 609 #else |
603 SkDEBUGFAIL("Should not call in GPU-less build"); | 610 SkDEBUGFAIL("Should not call in GPU-less build"); |
604 return NULL; | 611 return NULL; |
605 #endif | 612 #endif |
606 } | 613 } |
| 614 virtual bool requiresFragmentPosition() const SK_OVERRIDE { return true; } |
607 virtual bool isEqual(const SkLight& other) const SK_OVERRIDE { | 615 virtual bool isEqual(const SkLight& other) const SK_OVERRIDE { |
608 if (other.type() != kPoint_LightType) { | 616 if (other.type() != kPoint_LightType) { |
609 return false; | 617 return false; |
610 } | 618 } |
611 const SkPointLight& o = static_cast<const SkPointLight&>(other); | 619 const SkPointLight& o = static_cast<const SkPointLight&>(other); |
612 return INHERITED::isEqual(other) && | 620 return INHERITED::isEqual(other) && |
613 fLocation == o.fLocation; | 621 fLocation == o.fLocation; |
614 } | 622 } |
615 | 623 |
616 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkPointLight) | 624 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkPointLight) |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
667 return color() * scale; | 675 return color() * scale; |
668 } | 676 } |
669 virtual GrGLLight* createGLLight() const SK_OVERRIDE { | 677 virtual GrGLLight* createGLLight() const SK_OVERRIDE { |
670 #if SK_SUPPORT_GPU | 678 #if SK_SUPPORT_GPU |
671 return SkNEW(GrGLSpotLight); | 679 return SkNEW(GrGLSpotLight); |
672 #else | 680 #else |
673 SkDEBUGFAIL("Should not call in GPU-less build"); | 681 SkDEBUGFAIL("Should not call in GPU-less build"); |
674 return NULL; | 682 return NULL; |
675 #endif | 683 #endif |
676 } | 684 } |
| 685 virtual bool requiresFragmentPosition() const SK_OVERRIDE { return true; } |
677 virtual LightType type() const { return kSpot_LightType; } | 686 virtual LightType type() const { return kSpot_LightType; } |
678 const SkPoint3& location() const { return fLocation; } | 687 const SkPoint3& location() const { return fLocation; } |
679 const SkPoint3& target() const { return fTarget; } | 688 const SkPoint3& target() const { return fTarget; } |
680 SkScalar specularExponent() const { return fSpecularExponent; } | 689 SkScalar specularExponent() const { return fSpecularExponent; } |
681 SkScalar cosInnerConeAngle() const { return fCosInnerConeAngle; } | 690 SkScalar cosInnerConeAngle() const { return fCosInnerConeAngle; } |
682 SkScalar cosOuterConeAngle() const { return fCosOuterConeAngle; } | 691 SkScalar cosOuterConeAngle() const { return fCosOuterConeAngle; } |
683 SkScalar coneScale() const { return fConeScale; } | 692 SkScalar coneScale() const { return fConeScale; } |
684 const SkPoint3& s() const { return fS; } | 693 const SkPoint3& s() const { return fS; } |
685 | 694 |
686 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkSpotLight) | 695 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkSpotLight) |
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1037 UniformHandle fShininessUni; | 1046 UniformHandle fShininessUni; |
1038 }; | 1047 }; |
1039 | 1048 |
1040 /////////////////////////////////////////////////////////////////////////////// | 1049 /////////////////////////////////////////////////////////////////////////////// |
1041 | 1050 |
1042 GrLightingEffect::GrLightingEffect(GrTexture* texture, const SkLight* light, SkS
calar surfaceScale) | 1051 GrLightingEffect::GrLightingEffect(GrTexture* texture, const SkLight* light, SkS
calar surfaceScale) |
1043 : INHERITED(texture, MakeDivByTextureWHMatrix(texture)) | 1052 : INHERITED(texture, MakeDivByTextureWHMatrix(texture)) |
1044 , fLight(light) | 1053 , fLight(light) |
1045 , fSurfaceScale(surfaceScale) { | 1054 , fSurfaceScale(surfaceScale) { |
1046 fLight->ref(); | 1055 fLight->ref(); |
| 1056 if (light->requiresFragmentPosition()) { |
| 1057 this->setWillReadFragmentPosition(); |
| 1058 } |
1047 } | 1059 } |
1048 | 1060 |
1049 GrLightingEffect::~GrLightingEffect() { | 1061 GrLightingEffect::~GrLightingEffect() { |
1050 fLight->unref(); | 1062 fLight->unref(); |
1051 } | 1063 } |
1052 | 1064 |
1053 bool GrLightingEffect::onIsEqual(const GrEffect& sBase) const { | 1065 bool GrLightingEffect::onIsEqual(const GrEffect& sBase) const { |
1054 const GrLightingEffect& s = CastEffect<GrLightingEffect>(sBase); | 1066 const GrLightingEffect& s = CastEffect<GrLightingEffect>(sBase); |
1055 return this->texture(0) == s.texture(0) && | 1067 return this->texture(0) == s.texture(0) && |
1056 fLight->isEqual(*s.fLight) && | 1068 fLight->isEqual(*s.fLight) && |
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1466 | 1478 |
1467 #endif | 1479 #endif |
1468 | 1480 |
1469 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingImageFilter) | 1481 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingImageFilter) |
1470 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDiffuseLightingImageFilter) | 1482 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDiffuseLightingImageFilter) |
1471 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSpecularLightingImageFilter) | 1483 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSpecularLightingImageFilter) |
1472 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDistantLight) | 1484 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDistantLight) |
1473 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkPointLight) | 1485 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkPointLight) |
1474 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSpotLight) | 1486 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSpotLight) |
1475 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END | 1487 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END |
OLD | NEW |