| 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 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 buffer.writeScalar(point.fX); | 275 buffer.writeScalar(point.fX); |
| 276 buffer.writeScalar(point.fY); | 276 buffer.writeScalar(point.fY); |
| 277 buffer.writeScalar(point.fZ); | 277 buffer.writeScalar(point.fZ); |
| 278 }; | 278 }; |
| 279 | 279 |
| 280 class SkDiffuseLightingImageFilter : public SkLightingImageFilter { | 280 class SkDiffuseLightingImageFilter : public SkLightingImageFilter { |
| 281 public: | 281 public: |
| 282 static SkImageFilter* Create(SkLight* light, SkScalar surfaceScale, SkScalar
kd, SkImageFilter*, | 282 static SkImageFilter* Create(SkLight* light, SkScalar surfaceScale, SkScalar
kd, SkImageFilter*, |
| 283 const CropRect*, uint32_t uniqueID = 0); | 283 const CropRect*, uint32_t uniqueID = 0); |
| 284 | 284 |
| 285 SK_TO_STRING_OVERRIDE() |
| 285 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkDiffuseLightingImageFi
lter) | 286 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkDiffuseLightingImageFi
lter) |
| 286 SkScalar kd() const { return fKD; } | 287 SkScalar kd() const { return fKD; } |
| 287 | 288 |
| 288 protected: | 289 protected: |
| 289 SkDiffuseLightingImageFilter(SkLight* light, SkScalar surfaceScale, | 290 SkDiffuseLightingImageFilter(SkLight* light, SkScalar surfaceScale, |
| 290 SkScalar kd, SkImageFilter* input, const CropRe
ct* cropRect, | 291 SkScalar kd, SkImageFilter* input, const CropRe
ct* cropRect, |
| 291 uint32_t uniqueID); | 292 uint32_t uniqueID); |
| 292 virtual void flatten(SkWriteBuffer& buffer) const SK_OVERRIDE; | 293 virtual void flatten(SkWriteBuffer& buffer) const SK_OVERRIDE; |
| 293 virtual bool onFilterImage(Proxy*, const SkBitmap& src, const Context&, | 294 virtual bool onFilterImage(Proxy*, const SkBitmap& src, const Context&, |
| 294 SkBitmap* result, SkIPoint* offset) const SK_OVER
RIDE; | 295 SkBitmap* result, SkIPoint* offset) const SK_OVER
RIDE; |
| 295 #if SK_SUPPORT_GPU | 296 #if SK_SUPPORT_GPU |
| 296 virtual bool asFragmentProcessor(GrFragmentProcessor**, GrTexture*, const Sk
Matrix&, | 297 virtual bool asFragmentProcessor(GrFragmentProcessor**, GrTexture*, const Sk
Matrix&, |
| 297 const SkIRect& bounds) const SK_OVERRIDE; | 298 const SkIRect& bounds) const SK_OVERRIDE; |
| 298 #endif | 299 #endif |
| 299 | 300 |
| 300 private: | 301 private: |
| 301 friend class SkLightingImageFilter; | 302 friend class SkLightingImageFilter; |
| 302 typedef SkLightingImageFilter INHERITED; | 303 typedef SkLightingImageFilter INHERITED; |
| 303 SkScalar fKD; | 304 SkScalar fKD; |
| 304 }; | 305 }; |
| 305 | 306 |
| 306 class SkSpecularLightingImageFilter : public SkLightingImageFilter { | 307 class SkSpecularLightingImageFilter : public SkLightingImageFilter { |
| 307 public: | 308 public: |
| 308 static SkImageFilter* Create(SkLight* light, SkScalar surfaceScale, | 309 static SkImageFilter* Create(SkLight* light, SkScalar surfaceScale, |
| 309 SkScalar ks, SkScalar shininess, SkImageFilter*
, const CropRect*, | 310 SkScalar ks, SkScalar shininess, SkImageFilter*
, const CropRect*, |
| 310 uint32_t uniqueID = 0); | 311 uint32_t uniqueID = 0); |
| 311 | 312 |
| 313 SK_TO_STRING_OVERRIDE() |
| 312 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkSpecularLightingImageF
ilter) | 314 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkSpecularLightingImageF
ilter) |
| 313 | 315 |
| 314 SkScalar ks() const { return fKS; } | 316 SkScalar ks() const { return fKS; } |
| 315 SkScalar shininess() const { return fShininess; } | 317 SkScalar shininess() const { return fShininess; } |
| 316 | 318 |
| 317 protected: | 319 protected: |
| 318 SkSpecularLightingImageFilter(SkLight* light, SkScalar surfaceScale, SkScala
r ks, | 320 SkSpecularLightingImageFilter(SkLight* light, SkScalar surfaceScale, SkScala
r ks, |
| 319 SkScalar shininess, SkImageFilter* input, cons
t CropRect*, | 321 SkScalar shininess, SkImageFilter* input, cons
t CropRect*, |
| 320 uint32_t uniqueID); | 322 uint32_t uniqueID); |
| 321 virtual void flatten(SkWriteBuffer& buffer) const SK_OVERRIDE; | 323 virtual void flatten(SkWriteBuffer& buffer) const SK_OVERRIDE; |
| (...skipping 706 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1028 lightBitmap<DiffuseLightingType, SkPointLight>(lightingType, transfo
rmedLight, src, dst, surfaceScale(), bounds); | 1030 lightBitmap<DiffuseLightingType, SkPointLight>(lightingType, transfo
rmedLight, src, dst, surfaceScale(), bounds); |
| 1029 break; | 1031 break; |
| 1030 case SkLight::kSpot_LightType: | 1032 case SkLight::kSpot_LightType: |
| 1031 lightBitmap<DiffuseLightingType, SkSpotLight>(lightingType, transfor
medLight, src, dst, surfaceScale(), bounds); | 1033 lightBitmap<DiffuseLightingType, SkSpotLight>(lightingType, transfor
medLight, src, dst, surfaceScale(), bounds); |
| 1032 break; | 1034 break; |
| 1033 } | 1035 } |
| 1034 | 1036 |
| 1035 return true; | 1037 return true; |
| 1036 } | 1038 } |
| 1037 | 1039 |
| 1040 #ifndef SK_IGNORE_TO_STRING |
| 1041 void SkDiffuseLightingImageFilter::toString(SkString* str) const { |
| 1042 str->appendf("SkDiffuseLightingImageFilter: ("); |
| 1043 str->appendf("kD: %f\n", fKD); |
| 1044 str->append(")"); |
| 1045 } |
| 1046 #endif |
| 1047 |
| 1038 #if SK_SUPPORT_GPU | 1048 #if SK_SUPPORT_GPU |
| 1039 bool SkDiffuseLightingImageFilter::asFragmentProcessor(GrFragmentProcessor** fp, | 1049 bool SkDiffuseLightingImageFilter::asFragmentProcessor(GrFragmentProcessor** fp, |
| 1040 GrTexture* texture, | 1050 GrTexture* texture, |
| 1041 const SkMatrix& matrix, | 1051 const SkMatrix& matrix, |
| 1042 const SkIRect&) const { | 1052 const SkIRect&) const { |
| 1043 if (fp) { | 1053 if (fp) { |
| 1044 SkScalar scale = SkScalarMul(surfaceScale(), SkIntToScalar(255)); | 1054 SkScalar scale = SkScalarMul(surfaceScale(), SkIntToScalar(255)); |
| 1045 *fp = GrDiffuseLightingEffect::Create(texture, light(), scale, matrix, k
d()); | 1055 *fp = GrDiffuseLightingEffect::Create(texture, light(), scale, matrix, k
d()); |
| 1046 } | 1056 } |
| 1047 return true; | 1057 return true; |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1135 case SkLight::kPoint_LightType: | 1145 case SkLight::kPoint_LightType: |
| 1136 lightBitmap<SpecularLightingType, SkPointLight>(lightingType, transf
ormedLight, src, dst, surfaceScale(), bounds); | 1146 lightBitmap<SpecularLightingType, SkPointLight>(lightingType, transf
ormedLight, src, dst, surfaceScale(), bounds); |
| 1137 break; | 1147 break; |
| 1138 case SkLight::kSpot_LightType: | 1148 case SkLight::kSpot_LightType: |
| 1139 lightBitmap<SpecularLightingType, SkSpotLight>(lightingType, transfo
rmedLight, src, dst, surfaceScale(), bounds); | 1149 lightBitmap<SpecularLightingType, SkSpotLight>(lightingType, transfo
rmedLight, src, dst, surfaceScale(), bounds); |
| 1140 break; | 1150 break; |
| 1141 } | 1151 } |
| 1142 return true; | 1152 return true; |
| 1143 } | 1153 } |
| 1144 | 1154 |
| 1155 #ifndef SK_IGNORE_TO_STRING |
| 1156 void SkSpecularLightingImageFilter::toString(SkString* str) const { |
| 1157 str->appendf("SkSpecularLightingImageFilter: ("); |
| 1158 str->appendf("kS: %f shininess: %f", fKS, fShininess); |
| 1159 str->append(")"); |
| 1160 } |
| 1161 #endif |
| 1162 |
| 1145 #if SK_SUPPORT_GPU | 1163 #if SK_SUPPORT_GPU |
| 1146 bool SkSpecularLightingImageFilter::asFragmentProcessor(GrFragmentProcessor** fp
, | 1164 bool SkSpecularLightingImageFilter::asFragmentProcessor(GrFragmentProcessor** fp
, |
| 1147 GrTexture* texture, | 1165 GrTexture* texture, |
| 1148 const SkMatrix& matrix, | 1166 const SkMatrix& matrix, |
| 1149 const SkIRect&) const { | 1167 const SkIRect&) const { |
| 1150 if (fp) { | 1168 if (fp) { |
| 1151 SkScalar scale = SkScalarMul(surfaceScale(), SkIntToScalar(255)); | 1169 SkScalar scale = SkScalarMul(surfaceScale(), SkIntToScalar(255)); |
| 1152 *fp = GrSpecularLightingEffect::Create(texture, light(), scale, matrix,
ks(), shininess()); | 1170 *fp = GrSpecularLightingEffect::Create(texture, light(), scale, matrix,
ks(), shininess()); |
| 1153 } | 1171 } |
| 1154 return true; | 1172 return true; |
| (...skipping 543 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1698 | 1716 |
| 1699 fsBuilder->codeAppendf("%s(%s)", fLightColorFunc.c_str(), surfaceToLight); | 1717 fsBuilder->codeAppendf("%s(%s)", fLightColorFunc.c_str(), surfaceToLight); |
| 1700 } | 1718 } |
| 1701 | 1719 |
| 1702 #endif | 1720 #endif |
| 1703 | 1721 |
| 1704 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingImageFilter) | 1722 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingImageFilter) |
| 1705 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDiffuseLightingImageFilter) | 1723 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDiffuseLightingImageFilter) |
| 1706 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSpecularLightingImageFilter) | 1724 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSpecularLightingImageFilter) |
| 1707 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END | 1725 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END |
| OLD | NEW |