| 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 12 matching lines...) Expand all Loading... |
| 23 class GrGLSpecularLightingEffect; | 23 class GrGLSpecularLightingEffect; |
| 24 | 24 |
| 25 // For brevity | 25 // For brevity |
| 26 typedef GrGLUniformManager::UniformHandle UniformHandle; | 26 typedef GrGLUniformManager::UniformHandle UniformHandle; |
| 27 #endif | 27 #endif |
| 28 | 28 |
| 29 namespace { | 29 namespace { |
| 30 | 30 |
| 31 const SkScalar gOneThird = SkScalarInvert(SkIntToScalar(3)); | 31 const SkScalar gOneThird = SkScalarInvert(SkIntToScalar(3)); |
| 32 const SkScalar gTwoThirds = SkScalarDiv(SkIntToScalar(2), SkIntToScalar(3)); | 32 const SkScalar gTwoThirds = SkScalarDiv(SkIntToScalar(2), SkIntToScalar(3)); |
| 33 const SkScalar gOneHalf = SkFloatToScalar(0.5f); | 33 const SkScalar gOneHalf = 0.5f; |
| 34 const SkScalar gOneQuarter = SkFloatToScalar(0.25f); | 34 const SkScalar gOneQuarter = 0.25f; |
| 35 | 35 |
| 36 #if SK_SUPPORT_GPU | 36 #if SK_SUPPORT_GPU |
| 37 void setUniformPoint3(const GrGLUniformManager& uman, UniformHandle uni, const S
kPoint3& point) { | 37 void setUniformPoint3(const GrGLUniformManager& uman, UniformHandle uni, const S
kPoint3& point) { |
| 38 GR_STATIC_ASSERT(sizeof(SkPoint3) == 3 * sizeof(GrGLfloat)); | 38 GR_STATIC_ASSERT(sizeof(SkPoint3) == 3 * sizeof(GrGLfloat)); |
| 39 uman.set3fv(uni, 1, &point.fX); | 39 uman.set3fv(uni, 1, &point.fX); |
| 40 } | 40 } |
| 41 | 41 |
| 42 void setUniformNormal3(const GrGLUniformManager& uman, UniformHandle uni, const
SkPoint3& point) { | 42 void setUniformNormal3(const GrGLUniformManager& uman, UniformHandle uni, const
SkPoint3& point) { |
| 43 setUniformPoint3(uman, uni, SkPoint3(point.fX, point.fY, point.fZ)); | 43 setUniformPoint3(uman, uni, SkPoint3(point.fX, point.fY, point.fZ)); |
| 44 } | 44 } |
| (...skipping 623 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 668 public: | 668 public: |
| 669 SkSpotLight(const SkPoint3& location, const SkPoint3& target, SkScalar specu
larExponent, SkScalar cutoffAngle, SkColor color) | 669 SkSpotLight(const SkPoint3& location, const SkPoint3& target, SkScalar specu
larExponent, SkScalar cutoffAngle, SkColor color) |
| 670 : INHERITED(color), | 670 : INHERITED(color), |
| 671 fLocation(location), | 671 fLocation(location), |
| 672 fTarget(target), | 672 fTarget(target), |
| 673 fSpecularExponent(SkScalarPin(specularExponent, kSpecularExponentMin, kSp
ecularExponentMax)) | 673 fSpecularExponent(SkScalarPin(specularExponent, kSpecularExponentMin, kSp
ecularExponentMax)) |
| 674 { | 674 { |
| 675 fS = target - location; | 675 fS = target - location; |
| 676 fS.normalize(); | 676 fS.normalize(); |
| 677 fCosOuterConeAngle = SkScalarCos(SkDegreesToRadians(cutoffAngle)); | 677 fCosOuterConeAngle = SkScalarCos(SkDegreesToRadians(cutoffAngle)); |
| 678 const SkScalar antiAliasThreshold = SkFloatToScalar(0.016f); | 678 const SkScalar antiAliasThreshold = 0.016f; |
| 679 fCosInnerConeAngle = fCosOuterConeAngle + antiAliasThreshold; | 679 fCosInnerConeAngle = fCosOuterConeAngle + antiAliasThreshold; |
| 680 fConeScale = SkScalarInvert(antiAliasThreshold); | 680 fConeScale = SkScalarInvert(antiAliasThreshold); |
| 681 } | 681 } |
| 682 | 682 |
| 683 virtual SkLight* transform(const SkMatrix& matrix) const { | 683 virtual SkLight* transform(const SkMatrix& matrix) const { |
| 684 SkPoint location2 = SkPoint::Make(fLocation.fX, fLocation.fY); | 684 SkPoint location2 = SkPoint::Make(fLocation.fX, fLocation.fY); |
| 685 matrix.mapPoints(&location2, 1); | 685 matrix.mapPoints(&location2, 1); |
| 686 SkPoint3 location(location2.fX, location2.fY, fLocation.fZ); | 686 SkPoint3 location(location2.fX, location2.fY, fLocation.fZ); |
| 687 SkPoint target2 = SkPoint::Make(fTarget.fX, fTarget.fY); | 687 SkPoint target2 = SkPoint::Make(fTarget.fX, fTarget.fY); |
| 688 matrix.mapPoints(&target2, 1); | 688 matrix.mapPoints(&target2, 1); |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 784 SkPoint3 fTarget; | 784 SkPoint3 fTarget; |
| 785 SkScalar fSpecularExponent; | 785 SkScalar fSpecularExponent; |
| 786 SkScalar fCosOuterConeAngle; | 786 SkScalar fCosOuterConeAngle; |
| 787 SkScalar fCosInnerConeAngle; | 787 SkScalar fCosInnerConeAngle; |
| 788 SkScalar fConeScale; | 788 SkScalar fConeScale; |
| 789 SkPoint3 fS; | 789 SkPoint3 fS; |
| 790 }; | 790 }; |
| 791 | 791 |
| 792 // According to the spec, the specular term should be in the range [1, 128] : | 792 // According to the spec, the specular term should be in the range [1, 128] : |
| 793 // http://www.w3.org/TR/SVG/filters.html#feSpecularLightingSpecularExponentAttri
bute | 793 // http://www.w3.org/TR/SVG/filters.html#feSpecularLightingSpecularExponentAttri
bute |
| 794 const SkScalar SkSpotLight::kSpecularExponentMin = SkFloatToScalar(1.0f); | 794 const SkScalar SkSpotLight::kSpecularExponentMin = 1.0f; |
| 795 const SkScalar SkSpotLight::kSpecularExponentMax = SkFloatToScalar(128.0f); | 795 const SkScalar SkSpotLight::kSpecularExponentMax = 128.0f; |
| 796 | 796 |
| 797 /////////////////////////////////////////////////////////////////////////////// | 797 /////////////////////////////////////////////////////////////////////////////// |
| 798 | 798 |
| 799 void SkLight::flattenLight(SkFlattenableWriteBuffer& buffer) const { | 799 void SkLight::flattenLight(SkFlattenableWriteBuffer& buffer) const { |
| 800 // Write type first, then baseclass, then subclass. | 800 // Write type first, then baseclass, then subclass. |
| 801 buffer.writeInt(this->type()); | 801 buffer.writeInt(this->type()); |
| 802 writePoint3(fColor, buffer); | 802 writePoint3(fColor, buffer); |
| 803 this->onFlattenLight(buffer); | 803 this->onFlattenLight(buffer); |
| 804 } | 804 } |
| 805 | 805 |
| (...skipping 787 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1593 | 1593 |
| 1594 builder->fsCodeAppendf("%s(%s)", fLightColorFunc.c_str(), surfaceToLight); | 1594 builder->fsCodeAppendf("%s(%s)", fLightColorFunc.c_str(), surfaceToLight); |
| 1595 } | 1595 } |
| 1596 | 1596 |
| 1597 #endif | 1597 #endif |
| 1598 | 1598 |
| 1599 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingImageFilter) | 1599 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingImageFilter) |
| 1600 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDiffuseLightingImageFilter) | 1600 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDiffuseLightingImageFilter) |
| 1601 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSpecularLightingImageFilter) | 1601 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSpecularLightingImageFilter) |
| 1602 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END | 1602 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END |
| OLD | NEW |