| 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 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 | 253 |
| 254 void writePoint3(const SkPoint3& point, SkFlattenableWriteBuffer& buffer) { | 254 void writePoint3(const SkPoint3& point, SkFlattenableWriteBuffer& buffer) { |
| 255 buffer.writeScalar(point.fX); | 255 buffer.writeScalar(point.fX); |
| 256 buffer.writeScalar(point.fY); | 256 buffer.writeScalar(point.fY); |
| 257 buffer.writeScalar(point.fZ); | 257 buffer.writeScalar(point.fZ); |
| 258 }; | 258 }; |
| 259 | 259 |
| 260 class SkDiffuseLightingImageFilter : public SkLightingImageFilter { | 260 class SkDiffuseLightingImageFilter : public SkLightingImageFilter { |
| 261 public: | 261 public: |
| 262 SkDiffuseLightingImageFilter(SkLight* light, SkScalar surfaceScale, | 262 SkDiffuseLightingImageFilter(SkLight* light, SkScalar surfaceScale, |
| 263 SkScalar kd, SkImageFilter* input, const SkIRec
t* cropRect); | 263 SkScalar kd, SkImageFilter* input, const CropRe
ct* cropRect); |
| 264 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkDiffuseLightingImageFi
lter) | 264 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkDiffuseLightingImageFi
lter) |
| 265 | 265 |
| 266 #if SK_SUPPORT_GPU | 266 #if SK_SUPPORT_GPU |
| 267 virtual bool asNewEffect(GrEffectRef** effect, GrTexture*, const SkMatrix& m
atrix) const SK_OVERRIDE; | 267 virtual bool asNewEffect(GrEffectRef** effect, GrTexture*, const SkMatrix& m
atrix) const SK_OVERRIDE; |
| 268 #endif | 268 #endif |
| 269 SkScalar kd() const { return fKD; } | 269 SkScalar kd() const { return fKD; } |
| 270 | 270 |
| 271 protected: | 271 protected: |
| 272 explicit SkDiffuseLightingImageFilter(SkFlattenableReadBuffer& buffer); | 272 explicit SkDiffuseLightingImageFilter(SkFlattenableReadBuffer& buffer); |
| 273 virtual void flatten(SkFlattenableWriteBuffer& buffer) const SK_OVERRIDE; | 273 virtual void flatten(SkFlattenableWriteBuffer& buffer) const SK_OVERRIDE; |
| 274 virtual bool onFilterImage(Proxy*, const SkBitmap& src, const SkMatrix&, | 274 virtual bool onFilterImage(Proxy*, const SkBitmap& src, const SkMatrix&, |
| 275 SkBitmap* result, SkIPoint* offset) SK_OVERRIDE; | 275 SkBitmap* result, SkIPoint* offset) SK_OVERRIDE; |
| 276 | 276 |
| 277 | 277 |
| 278 private: | 278 private: |
| 279 typedef SkLightingImageFilter INHERITED; | 279 typedef SkLightingImageFilter INHERITED; |
| 280 SkScalar fKD; | 280 SkScalar fKD; |
| 281 }; | 281 }; |
| 282 | 282 |
| 283 class SkSpecularLightingImageFilter : public SkLightingImageFilter { | 283 class SkSpecularLightingImageFilter : public SkLightingImageFilter { |
| 284 public: | 284 public: |
| 285 SkSpecularLightingImageFilter(SkLight* light, SkScalar surfaceScale, SkScala
r ks, SkScalar shininess, SkImageFilter* input, const SkIRect* cropRect); | 285 SkSpecularLightingImageFilter(SkLight* light, SkScalar surfaceScale, SkScala
r ks, SkScalar shininess, SkImageFilter* input, const CropRect* cropRect); |
| 286 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkSpecularLightingImageF
ilter) | 286 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkSpecularLightingImageF
ilter) |
| 287 | 287 |
| 288 #if SK_SUPPORT_GPU | 288 #if SK_SUPPORT_GPU |
| 289 virtual bool asNewEffect(GrEffectRef** effect, GrTexture*, const SkMatrix& m
atrix) const SK_OVERRIDE; | 289 virtual bool asNewEffect(GrEffectRef** effect, GrTexture*, const SkMatrix& m
atrix) const SK_OVERRIDE; |
| 290 #endif | 290 #endif |
| 291 | 291 |
| 292 SkScalar ks() const { return fKS; } | 292 SkScalar ks() const { return fKS; } |
| 293 SkScalar shininess() const { return fShininess; } | 293 SkScalar shininess() const { return fShininess; } |
| 294 | 294 |
| 295 protected: | 295 protected: |
| (...skipping 494 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 790 SkPoint3 fS; | 790 SkPoint3 fS; |
| 791 }; | 791 }; |
| 792 | 792 |
| 793 // According to the spec, the specular term should be in the range [1, 128] : | 793 // According to the spec, the specular term should be in the range [1, 128] : |
| 794 // http://www.w3.org/TR/SVG/filters.html#feSpecularLightingSpecularExponentAttri
bute | 794 // http://www.w3.org/TR/SVG/filters.html#feSpecularLightingSpecularExponentAttri
bute |
| 795 const SkScalar SkSpotLight::kSpecularExponentMin = SkFloatToScalar(1.0f); | 795 const SkScalar SkSpotLight::kSpecularExponentMin = SkFloatToScalar(1.0f); |
| 796 const SkScalar SkSpotLight::kSpecularExponentMax = SkFloatToScalar(128.0f); | 796 const SkScalar SkSpotLight::kSpecularExponentMax = SkFloatToScalar(128.0f); |
| 797 | 797 |
| 798 /////////////////////////////////////////////////////////////////////////////// | 798 /////////////////////////////////////////////////////////////////////////////// |
| 799 | 799 |
| 800 SkLightingImageFilter::SkLightingImageFilter(SkLight* light, SkScalar surfaceSca
le, SkImageFilter* input, const SkIRect* cropRect) | 800 SkLightingImageFilter::SkLightingImageFilter(SkLight* light, SkScalar surfaceSca
le, SkImageFilter* input, const CropRect* cropRect) |
| 801 : INHERITED(input, cropRect), | 801 : INHERITED(input, cropRect), |
| 802 fLight(light), | 802 fLight(light), |
| 803 fSurfaceScale(SkScalarDiv(surfaceScale, SkIntToScalar(255))) | 803 fSurfaceScale(SkScalarDiv(surfaceScale, SkIntToScalar(255))) |
| 804 { | 804 { |
| 805 SkASSERT(fLight); | 805 SkASSERT(fLight); |
| 806 // our caller knows that we take ownership of the light, so we don't | 806 // our caller knows that we take ownership of the light, so we don't |
| 807 // need to call ref() here. | 807 // need to call ref() here. |
| 808 } | 808 } |
| 809 | 809 |
| 810 SkImageFilter* SkLightingImageFilter::CreateDistantLitDiffuse( | 810 SkImageFilter* SkLightingImageFilter::CreateDistantLitDiffuse( |
| 811 const SkPoint3& direction, SkColor lightColor, SkScalar surfaceScale, | 811 const SkPoint3& direction, SkColor lightColor, SkScalar surfaceScale, |
| 812 SkScalar kd, SkImageFilter* input, const SkIRect* cropRect) { | 812 SkScalar kd, SkImageFilter* input, const CropRect* cropRect) { |
| 813 return SkNEW_ARGS(SkDiffuseLightingImageFilter, | 813 return SkNEW_ARGS(SkDiffuseLightingImageFilter, |
| 814 (SkNEW_ARGS(SkDistantLight, (direction, lightColor)), surfaceScale, kd, | 814 (SkNEW_ARGS(SkDistantLight, (direction, lightColor)), surfaceScale, kd, |
| 815 input, cropRect)); | 815 input, cropRect)); |
| 816 } | 816 } |
| 817 | 817 |
| 818 SkImageFilter* SkLightingImageFilter::CreatePointLitDiffuse( | 818 SkImageFilter* SkLightingImageFilter::CreatePointLitDiffuse( |
| 819 const SkPoint3& location, SkColor lightColor, SkScalar surfaceScale, | 819 const SkPoint3& location, SkColor lightColor, SkScalar surfaceScale, |
| 820 SkScalar kd, SkImageFilter* input, const SkIRect* cropRect) { | 820 SkScalar kd, SkImageFilter* input, const CropRect* cropRect) { |
| 821 return SkNEW_ARGS(SkDiffuseLightingImageFilter, | 821 return SkNEW_ARGS(SkDiffuseLightingImageFilter, |
| 822 (SkNEW_ARGS(SkPointLight, (location, lightColor)), surfaceScale, kd, | 822 (SkNEW_ARGS(SkPointLight, (location, lightColor)), surfaceScale, kd, |
| 823 input, cropRect)); | 823 input, cropRect)); |
| 824 } | 824 } |
| 825 | 825 |
| 826 SkImageFilter* SkLightingImageFilter::CreateSpotLitDiffuse( | 826 SkImageFilter* SkLightingImageFilter::CreateSpotLitDiffuse( |
| 827 const SkPoint3& location, const SkPoint3& target, | 827 const SkPoint3& location, const SkPoint3& target, |
| 828 SkScalar specularExponent, SkScalar cutoffAngle, | 828 SkScalar specularExponent, SkScalar cutoffAngle, |
| 829 SkColor lightColor, SkScalar surfaceScale, SkScalar kd, | 829 SkColor lightColor, SkScalar surfaceScale, SkScalar kd, |
| 830 SkImageFilter* input, const SkIRect* cropRect) { | 830 SkImageFilter* input, const CropRect* cropRect) { |
| 831 return SkNEW_ARGS(SkDiffuseLightingImageFilter, | 831 return SkNEW_ARGS(SkDiffuseLightingImageFilter, |
| 832 (SkNEW_ARGS(SkSpotLight, (location, target, specularExponent, | 832 (SkNEW_ARGS(SkSpotLight, (location, target, specularExponent, |
| 833 cutoffAngle, lightColor)), | 833 cutoffAngle, lightColor)), |
| 834 surfaceScale, kd, input, cropRect)); | 834 surfaceScale, kd, input, cropRect)); |
| 835 } | 835 } |
| 836 | 836 |
| 837 SkImageFilter* SkLightingImageFilter::CreateDistantLitSpecular( | 837 SkImageFilter* SkLightingImageFilter::CreateDistantLitSpecular( |
| 838 const SkPoint3& direction, SkColor lightColor, SkScalar surfaceScale, | 838 const SkPoint3& direction, SkColor lightColor, SkScalar surfaceScale, |
| 839 SkScalar ks, SkScalar shininess, SkImageFilter* input, const SkIRect* cropRe
ct) { | 839 SkScalar ks, SkScalar shininess, SkImageFilter* input, const CropRect* cropR
ect) { |
| 840 return SkNEW_ARGS(SkSpecularLightingImageFilter, | 840 return SkNEW_ARGS(SkSpecularLightingImageFilter, |
| 841 (SkNEW_ARGS(SkDistantLight, (direction, lightColor)), | 841 (SkNEW_ARGS(SkDistantLight, (direction, lightColor)), |
| 842 surfaceScale, ks, shininess, input, cropRect)); | 842 surfaceScale, ks, shininess, input, cropRect)); |
| 843 } | 843 } |
| 844 | 844 |
| 845 SkImageFilter* SkLightingImageFilter::CreatePointLitSpecular( | 845 SkImageFilter* SkLightingImageFilter::CreatePointLitSpecular( |
| 846 const SkPoint3& location, SkColor lightColor, SkScalar surfaceScale, | 846 const SkPoint3& location, SkColor lightColor, SkScalar surfaceScale, |
| 847 SkScalar ks, SkScalar shininess, SkImageFilter* input, const SkIRect* cropRe
ct) { | 847 SkScalar ks, SkScalar shininess, SkImageFilter* input, const CropRect* cropR
ect) { |
| 848 return SkNEW_ARGS(SkSpecularLightingImageFilter, | 848 return SkNEW_ARGS(SkSpecularLightingImageFilter, |
| 849 (SkNEW_ARGS(SkPointLight, (location, lightColor)), | 849 (SkNEW_ARGS(SkPointLight, (location, lightColor)), |
| 850 surfaceScale, ks, shininess, input, cropRect)); | 850 surfaceScale, ks, shininess, input, cropRect)); |
| 851 } | 851 } |
| 852 | 852 |
| 853 SkImageFilter* SkLightingImageFilter::CreateSpotLitSpecular( | 853 SkImageFilter* SkLightingImageFilter::CreateSpotLitSpecular( |
| 854 const SkPoint3& location, const SkPoint3& target, | 854 const SkPoint3& location, const SkPoint3& target, |
| 855 SkScalar specularExponent, SkScalar cutoffAngle, | 855 SkScalar specularExponent, SkScalar cutoffAngle, |
| 856 SkColor lightColor, SkScalar surfaceScale, | 856 SkColor lightColor, SkScalar surfaceScale, |
| 857 SkScalar ks, SkScalar shininess, SkImageFilter* input, const SkIRect* cropRe
ct) { | 857 SkScalar ks, SkScalar shininess, SkImageFilter* input, const CropRect* cropR
ect) { |
| 858 return SkNEW_ARGS(SkSpecularLightingImageFilter, | 858 return SkNEW_ARGS(SkSpecularLightingImageFilter, |
| 859 (SkNEW_ARGS(SkSpotLight, (location, target, specularExponent, cutoffAngl
e, lightColor)), | 859 (SkNEW_ARGS(SkSpotLight, (location, target, specularExponent, cutoffAngl
e, lightColor)), |
| 860 surfaceScale, ks, shininess, input, cropRect)); | 860 surfaceScale, ks, shininess, input, cropRect)); |
| 861 } | 861 } |
| 862 | 862 |
| 863 SkLightingImageFilter::~SkLightingImageFilter() { | 863 SkLightingImageFilter::~SkLightingImageFilter() { |
| 864 fLight->unref(); | 864 fLight->unref(); |
| 865 } | 865 } |
| 866 | 866 |
| 867 SkLightingImageFilter::SkLightingImageFilter(SkFlattenableReadBuffer& buffer) | 867 SkLightingImageFilter::SkLightingImageFilter(SkFlattenableReadBuffer& buffer) |
| 868 : INHERITED(buffer) | 868 : INHERITED(buffer) |
| 869 { | 869 { |
| 870 fLight = buffer.readFlattenableT<SkLight>(); | 870 fLight = buffer.readFlattenableT<SkLight>(); |
| 871 fSurfaceScale = buffer.readScalar(); | 871 fSurfaceScale = buffer.readScalar(); |
| 872 } | 872 } |
| 873 | 873 |
| 874 void SkLightingImageFilter::flatten(SkFlattenableWriteBuffer& buffer) const { | 874 void SkLightingImageFilter::flatten(SkFlattenableWriteBuffer& buffer) const { |
| 875 this->INHERITED::flatten(buffer); | 875 this->INHERITED::flatten(buffer); |
| 876 buffer.writeFlattenable(fLight); | 876 buffer.writeFlattenable(fLight); |
| 877 buffer.writeScalar(fSurfaceScale); | 877 buffer.writeScalar(fSurfaceScale); |
| 878 } | 878 } |
| 879 | 879 |
| 880 /////////////////////////////////////////////////////////////////////////////// | 880 /////////////////////////////////////////////////////////////////////////////// |
| 881 | 881 |
| 882 SkDiffuseLightingImageFilter::SkDiffuseLightingImageFilter(SkLight* light, SkSca
lar surfaceScale, SkScalar kd, SkImageFilter* input, const SkIRect* cropRect = N
ULL) | 882 SkDiffuseLightingImageFilter::SkDiffuseLightingImageFilter(SkLight* light, SkSca
lar surfaceScale, SkScalar kd, SkImageFilter* input, const CropRect* cropRect =
NULL) |
| 883 : SkLightingImageFilter(light, surfaceScale, input, cropRect), | 883 : SkLightingImageFilter(light, surfaceScale, input, cropRect), |
| 884 fKD(kd) | 884 fKD(kd) |
| 885 { | 885 { |
| 886 } | 886 } |
| 887 | 887 |
| 888 SkDiffuseLightingImageFilter::SkDiffuseLightingImageFilter(SkFlattenableReadBuff
er& buffer) | 888 SkDiffuseLightingImageFilter::SkDiffuseLightingImageFilter(SkFlattenableReadBuff
er& buffer) |
| 889 : INHERITED(buffer) | 889 : INHERITED(buffer) |
| 890 { | 890 { |
| 891 fKD = buffer.readScalar(); | 891 fKD = buffer.readScalar(); |
| 892 } | 892 } |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 947 if (effect) { | 947 if (effect) { |
| 948 SkScalar scale = SkScalarMul(surfaceScale(), SkIntToScalar(255)); | 948 SkScalar scale = SkScalarMul(surfaceScale(), SkIntToScalar(255)); |
| 949 *effect = GrDiffuseLightingEffect::Create(texture, light(), scale, matri
x, kd()); | 949 *effect = GrDiffuseLightingEffect::Create(texture, light(), scale, matri
x, kd()); |
| 950 } | 950 } |
| 951 return true; | 951 return true; |
| 952 } | 952 } |
| 953 #endif | 953 #endif |
| 954 | 954 |
| 955 /////////////////////////////////////////////////////////////////////////////// | 955 /////////////////////////////////////////////////////////////////////////////// |
| 956 | 956 |
| 957 SkSpecularLightingImageFilter::SkSpecularLightingImageFilter(SkLight* light, SkS
calar surfaceScale, SkScalar ks, SkScalar shininess, SkImageFilter* input, const
SkIRect* cropRect) | 957 SkSpecularLightingImageFilter::SkSpecularLightingImageFilter(SkLight* light, SkS
calar surfaceScale, SkScalar ks, SkScalar shininess, SkImageFilter* input, const
CropRect* cropRect) |
| 958 : SkLightingImageFilter(light, surfaceScale, input, cropRect), | 958 : SkLightingImageFilter(light, surfaceScale, input, cropRect), |
| 959 fKS(ks), | 959 fKS(ks), |
| 960 fShininess(shininess) | 960 fShininess(shininess) |
| 961 { | 961 { |
| 962 } | 962 } |
| 963 | 963 |
| 964 SkSpecularLightingImageFilter::SkSpecularLightingImageFilter(SkFlattenableReadBu
ffer& buffer) | 964 SkSpecularLightingImageFilter::SkSpecularLightingImageFilter(SkFlattenableReadBu
ffer& buffer) |
| 965 : INHERITED(buffer) | 965 : INHERITED(buffer) |
| 966 { | 966 { |
| 967 fKS = buffer.readScalar(); | 967 fKS = buffer.readScalar(); |
| (...skipping 591 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1559 | 1559 |
| 1560 #endif | 1560 #endif |
| 1561 | 1561 |
| 1562 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingImageFilter) | 1562 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingImageFilter) |
| 1563 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDiffuseLightingImageFilter) | 1563 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDiffuseLightingImageFilter) |
| 1564 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSpecularLightingImageFilter) | 1564 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSpecularLightingImageFilter) |
| 1565 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDistantLight) | 1565 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDistantLight) |
| 1566 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkPointLight) | 1566 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkPointLight) |
| 1567 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSpotLight) | 1567 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSpotLight) |
| 1568 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END | 1568 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END |
| OLD | NEW |