| 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 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 SkScalar kd, SkImageFilter* input, const CropRe
ct* cropRect); | 267 SkScalar kd, SkImageFilter* input, const CropRe
ct* cropRect); |
| 268 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkDiffuseLightingImageFi
lter) | 268 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkDiffuseLightingImageFi
lter) |
| 269 SkScalar kd() const { return fKD; } | 269 SkScalar kd() const { return fKD; } |
| 270 | 270 |
| 271 protected: | 271 protected: |
| 272 explicit SkDiffuseLightingImageFilter(SkReadBuffer& buffer); | 272 explicit SkDiffuseLightingImageFilter(SkReadBuffer& buffer); |
| 273 virtual void flatten(SkWriteBuffer& buffer) const SK_OVERRIDE; | 273 virtual void flatten(SkWriteBuffer& buffer) const SK_OVERRIDE; |
| 274 virtual bool onFilterImage(Proxy*, const SkBitmap& src, const Context&, | 274 virtual bool onFilterImage(Proxy*, const SkBitmap& src, const Context&, |
| 275 SkBitmap* result, SkIPoint* offset) const SK_OVER
RIDE; | 275 SkBitmap* result, SkIPoint* offset) const SK_OVER
RIDE; |
| 276 #if SK_SUPPORT_GPU | 276 #if SK_SUPPORT_GPU |
| 277 virtual bool asNewEffect(GrEffectRef** effect, GrTexture*, const SkMatrix& m
atrix, const SkIRect& bounds) const SK_OVERRIDE; | 277 virtual bool asNewEffect(GrEffect** effect, GrTexture*, const SkMatrix& matr
ix, |
| 278 const SkIRect& bounds) const SK_OVERRIDE; |
| 278 #endif | 279 #endif |
| 279 | 280 |
| 280 private: | 281 private: |
| 281 typedef SkLightingImageFilter INHERITED; | 282 typedef SkLightingImageFilter INHERITED; |
| 282 SkScalar fKD; | 283 SkScalar fKD; |
| 283 }; | 284 }; |
| 284 | 285 |
| 285 class SkSpecularLightingImageFilter : public SkLightingImageFilter { | 286 class SkSpecularLightingImageFilter : public SkLightingImageFilter { |
| 286 public: | 287 public: |
| 287 SkSpecularLightingImageFilter(SkLight* light, SkScalar surfaceScale, SkScala
r ks, SkScalar shininess, SkImageFilter* input, const CropRect* cropRect); | 288 SkSpecularLightingImageFilter(SkLight* light, SkScalar surfaceScale, SkScala
r ks, SkScalar shininess, SkImageFilter* input, const CropRect* cropRect); |
| 288 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkSpecularLightingImageF
ilter) | 289 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkSpecularLightingImageF
ilter) |
| 289 | 290 |
| 290 SkScalar ks() const { return fKS; } | 291 SkScalar ks() const { return fKS; } |
| 291 SkScalar shininess() const { return fShininess; } | 292 SkScalar shininess() const { return fShininess; } |
| 292 | 293 |
| 293 protected: | 294 protected: |
| 294 explicit SkSpecularLightingImageFilter(SkReadBuffer& buffer); | 295 explicit SkSpecularLightingImageFilter(SkReadBuffer& buffer); |
| 295 virtual void flatten(SkWriteBuffer& buffer) const SK_OVERRIDE; | 296 virtual void flatten(SkWriteBuffer& buffer) const SK_OVERRIDE; |
| 296 virtual bool onFilterImage(Proxy*, const SkBitmap& src, const Context&, | 297 virtual bool onFilterImage(Proxy*, const SkBitmap& src, const Context&, |
| 297 SkBitmap* result, SkIPoint* offset) const SK_OVER
RIDE; | 298 SkBitmap* result, SkIPoint* offset) const SK_OVER
RIDE; |
| 298 #if SK_SUPPORT_GPU | 299 #if SK_SUPPORT_GPU |
| 299 virtual bool asNewEffect(GrEffectRef** effect, GrTexture*, const SkMatrix& m
atrix, const SkIRect& bounds) const SK_OVERRIDE; | 300 virtual bool asNewEffect(GrEffect** effect, GrTexture*, const SkMatrix& matr
ix, |
| 301 const SkIRect& bounds) const SK_OVERRIDE; |
| 300 #endif | 302 #endif |
| 301 | 303 |
| 302 private: | 304 private: |
| 303 typedef SkLightingImageFilter INHERITED; | 305 typedef SkLightingImageFilter INHERITED; |
| 304 SkScalar fKS; | 306 SkScalar fKS; |
| 305 SkScalar fShininess; | 307 SkScalar fShininess; |
| 306 }; | 308 }; |
| 307 | 309 |
| 308 #if SK_SUPPORT_GPU | 310 #if SK_SUPPORT_GPU |
| 309 | 311 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 327 | 329 |
| 328 private: | 330 private: |
| 329 typedef GrSingleTextureEffect INHERITED; | 331 typedef GrSingleTextureEffect INHERITED; |
| 330 const SkLight* fLight; | 332 const SkLight* fLight; |
| 331 SkScalar fSurfaceScale; | 333 SkScalar fSurfaceScale; |
| 332 SkMatrix fFilterMatrix; | 334 SkMatrix fFilterMatrix; |
| 333 }; | 335 }; |
| 334 | 336 |
| 335 class GrDiffuseLightingEffect : public GrLightingEffect { | 337 class GrDiffuseLightingEffect : public GrLightingEffect { |
| 336 public: | 338 public: |
| 337 static GrEffectRef* Create(GrTexture* texture, | 339 static GrEffect* Create(GrTexture* texture, |
| 338 const SkLight* light, | 340 const SkLight* light, |
| 339 SkScalar surfaceScale, | 341 SkScalar surfaceScale, |
| 340 const SkMatrix& matrix, | 342 const SkMatrix& matrix, |
| 341 SkScalar kd) { | 343 SkScalar kd) { |
| 342 return SkNEW_ARGS(GrDiffuseLightingEffect, (texture, | 344 return SkNEW_ARGS(GrDiffuseLightingEffect, (texture, |
| 343 light, | 345 light, |
| 344 surfaceScale, | 346 surfaceScale, |
| 345 matrix, | 347 matrix, |
| 346 kd)); | 348 kd)); |
| 347 } | 349 } |
| 348 | 350 |
| 349 static const char* Name() { return "DiffuseLighting"; } | 351 static const char* Name() { return "DiffuseLighting"; } |
| 350 | 352 |
| 351 typedef GrGLDiffuseLightingEffect GLEffect; | 353 typedef GrGLDiffuseLightingEffect GLEffect; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 362 const SkMatrix& matrix, | 364 const SkMatrix& matrix, |
| 363 SkScalar kd); | 365 SkScalar kd); |
| 364 | 366 |
| 365 GR_DECLARE_EFFECT_TEST; | 367 GR_DECLARE_EFFECT_TEST; |
| 366 typedef GrLightingEffect INHERITED; | 368 typedef GrLightingEffect INHERITED; |
| 367 SkScalar fKD; | 369 SkScalar fKD; |
| 368 }; | 370 }; |
| 369 | 371 |
| 370 class GrSpecularLightingEffect : public GrLightingEffect { | 372 class GrSpecularLightingEffect : public GrLightingEffect { |
| 371 public: | 373 public: |
| 372 static GrEffectRef* Create(GrTexture* texture, | 374 static GrEffect* Create(GrTexture* texture, |
| 373 const SkLight* light, | 375 const SkLight* light, |
| 374 SkScalar surfaceScale, | 376 SkScalar surfaceScale, |
| 375 const SkMatrix& matrix, | 377 const SkMatrix& matrix, |
| 376 SkScalar ks, | 378 SkScalar ks, |
| 377 SkScalar shininess) { | 379 SkScalar shininess) { |
| 378 return SkNEW_ARGS(GrSpecularLightingEffect, (texture, | 380 return SkNEW_ARGS(GrSpecularLightingEffect, (texture, |
| 379 light, | 381 light, |
| 380 surfaceScale, | 382 surfaceScale, |
| 381 matrix, | 383 matrix, |
| 382 ks, | 384 ks, |
| 383 shininess)); | 385 shininess)); |
| 384 } | 386 } |
| 385 static const char* Name() { return "SpecularLighting"; } | 387 static const char* Name() { return "SpecularLighting"; } |
| 386 | 388 |
| 387 typedef GrGLSpecularLightingEffect GLEffect; | 389 typedef GrGLSpecularLightingEffect GLEffect; |
| (...skipping 589 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 977 break; | 979 break; |
| 978 case SkLight::kSpot_LightType: | 980 case SkLight::kSpot_LightType: |
| 979 lightBitmap<DiffuseLightingType, SkSpotLight>(lightingType, transfor
medLight, src, dst, surfaceScale(), bounds); | 981 lightBitmap<DiffuseLightingType, SkSpotLight>(lightingType, transfor
medLight, src, dst, surfaceScale(), bounds); |
| 980 break; | 982 break; |
| 981 } | 983 } |
| 982 | 984 |
| 983 return true; | 985 return true; |
| 984 } | 986 } |
| 985 | 987 |
| 986 #if SK_SUPPORT_GPU | 988 #if SK_SUPPORT_GPU |
| 987 bool SkDiffuseLightingImageFilter::asNewEffect(GrEffectRef** effect, GrTexture*
texture, const SkMatrix& matrix, const SkIRect&) const { | 989 bool SkDiffuseLightingImageFilter::asNewEffect(GrEffect** effect, GrTexture* tex
ture, |
| 990 const SkMatrix& matrix, const SkI
Rect&) const { |
| 988 if (effect) { | 991 if (effect) { |
| 989 SkScalar scale = SkScalarMul(surfaceScale(), SkIntToScalar(255)); | 992 SkScalar scale = SkScalarMul(surfaceScale(), SkIntToScalar(255)); |
| 990 *effect = GrDiffuseLightingEffect::Create(texture, light(), scale, matri
x, kd()); | 993 *effect = GrDiffuseLightingEffect::Create(texture, light(), scale, matri
x, kd()); |
| 991 } | 994 } |
| 992 return true; | 995 return true; |
| 993 } | 996 } |
| 994 #endif | 997 #endif |
| 995 | 998 |
| 996 /////////////////////////////////////////////////////////////////////////////// | 999 /////////////////////////////////////////////////////////////////////////////// |
| 997 | 1000 |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1066 lightBitmap<SpecularLightingType, SkPointLight>(lightingType, transf
ormedLight, src, dst, surfaceScale(), bounds); | 1069 lightBitmap<SpecularLightingType, SkPointLight>(lightingType, transf
ormedLight, src, dst, surfaceScale(), bounds); |
| 1067 break; | 1070 break; |
| 1068 case SkLight::kSpot_LightType: | 1071 case SkLight::kSpot_LightType: |
| 1069 lightBitmap<SpecularLightingType, SkSpotLight>(lightingType, transfo
rmedLight, src, dst, surfaceScale(), bounds); | 1072 lightBitmap<SpecularLightingType, SkSpotLight>(lightingType, transfo
rmedLight, src, dst, surfaceScale(), bounds); |
| 1070 break; | 1073 break; |
| 1071 } | 1074 } |
| 1072 return true; | 1075 return true; |
| 1073 } | 1076 } |
| 1074 | 1077 |
| 1075 #if SK_SUPPORT_GPU | 1078 #if SK_SUPPORT_GPU |
| 1076 bool SkSpecularLightingImageFilter::asNewEffect(GrEffectRef** effect, GrTexture*
texture, const SkMatrix& matrix, const SkIRect&) const { | 1079 bool SkSpecularLightingImageFilter::asNewEffect(GrEffect** effect, GrTexture* te
xture, |
| 1080 const SkMatrix& matrix, const Sk
IRect&) const { |
| 1077 if (effect) { | 1081 if (effect) { |
| 1078 SkScalar scale = SkScalarMul(surfaceScale(), SkIntToScalar(255)); | 1082 SkScalar scale = SkScalarMul(surfaceScale(), SkIntToScalar(255)); |
| 1079 *effect = GrSpecularLightingEffect::Create(texture, light(), scale, matr
ix, ks(), shininess()); | 1083 *effect = GrSpecularLightingEffect::Create(texture, light(), scale, matr
ix, ks(), shininess()); |
| 1080 } | 1084 } |
| 1081 return true; | 1085 return true; |
| 1082 } | 1086 } |
| 1083 #endif | 1087 #endif |
| 1084 | 1088 |
| 1085 /////////////////////////////////////////////////////////////////////////////// | 1089 /////////////////////////////////////////////////////////////////////////////// |
| 1086 | 1090 |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1222 } | 1226 } |
| 1223 | 1227 |
| 1224 bool GrDiffuseLightingEffect::onIsEqual(const GrEffect& sBase) const { | 1228 bool GrDiffuseLightingEffect::onIsEqual(const GrEffect& sBase) const { |
| 1225 const GrDiffuseLightingEffect& s = CastEffect<GrDiffuseLightingEffect>(sBase
); | 1229 const GrDiffuseLightingEffect& s = CastEffect<GrDiffuseLightingEffect>(sBase
); |
| 1226 return INHERITED::onIsEqual(sBase) && | 1230 return INHERITED::onIsEqual(sBase) && |
| 1227 this->kd() == s.kd(); | 1231 this->kd() == s.kd(); |
| 1228 } | 1232 } |
| 1229 | 1233 |
| 1230 GR_DEFINE_EFFECT_TEST(GrDiffuseLightingEffect); | 1234 GR_DEFINE_EFFECT_TEST(GrDiffuseLightingEffect); |
| 1231 | 1235 |
| 1232 GrEffectRef* GrDiffuseLightingEffect::TestCreate(SkRandom* random, | 1236 GrEffect* GrDiffuseLightingEffect::TestCreate(SkRandom* random, |
| 1233 GrContext* context, | 1237 GrContext* context, |
| 1234 const GrDrawTargetCaps&, | 1238 const GrDrawTargetCaps&, |
| 1235 GrTexture* textures[]) { | 1239 GrTexture* textures[]) { |
| 1236 SkScalar surfaceScale = random->nextSScalar1(); | 1240 SkScalar surfaceScale = random->nextSScalar1(); |
| 1237 SkScalar kd = random->nextUScalar1(); | 1241 SkScalar kd = random->nextUScalar1(); |
| 1238 SkAutoTUnref<SkLight> light(create_random_light(random)); | 1242 SkAutoTUnref<SkLight> light(create_random_light(random)); |
| 1239 SkMatrix matrix; | 1243 SkMatrix matrix; |
| 1240 for (int i = 0; i < 9; i++) { | 1244 for (int i = 0; i < 9; i++) { |
| 1241 matrix[i] = random->nextUScalar1(); | 1245 matrix[i] = random->nextUScalar1(); |
| 1242 } | 1246 } |
| 1243 return GrDiffuseLightingEffect::Create(textures[GrEffectUnitTest::kAlphaText
ureIdx], | 1247 return GrDiffuseLightingEffect::Create(textures[GrEffectUnitTest::kAlphaText
ureIdx], |
| 1244 light, surfaceScale, matrix, kd); | 1248 light, surfaceScale, matrix, kd); |
| 1245 } | 1249 } |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1428 | 1432 |
| 1429 bool GrSpecularLightingEffect::onIsEqual(const GrEffect& sBase) const { | 1433 bool GrSpecularLightingEffect::onIsEqual(const GrEffect& sBase) const { |
| 1430 const GrSpecularLightingEffect& s = CastEffect<GrSpecularLightingEffect>(sBa
se); | 1434 const GrSpecularLightingEffect& s = CastEffect<GrSpecularLightingEffect>(sBa
se); |
| 1431 return INHERITED::onIsEqual(sBase) && | 1435 return INHERITED::onIsEqual(sBase) && |
| 1432 this->ks() == s.ks() && | 1436 this->ks() == s.ks() && |
| 1433 this->shininess() == s.shininess(); | 1437 this->shininess() == s.shininess(); |
| 1434 } | 1438 } |
| 1435 | 1439 |
| 1436 GR_DEFINE_EFFECT_TEST(GrSpecularLightingEffect); | 1440 GR_DEFINE_EFFECT_TEST(GrSpecularLightingEffect); |
| 1437 | 1441 |
| 1438 GrEffectRef* GrSpecularLightingEffect::TestCreate(SkRandom* random, | 1442 GrEffect* GrSpecularLightingEffect::TestCreate(SkRandom* random, |
| 1439 GrContext* context, | 1443 GrContext* context, |
| 1440 const GrDrawTargetCaps&, | 1444 const GrDrawTargetCaps&, |
| 1441 GrTexture* textures[]) { | 1445 GrTexture* textures[]) { |
| 1442 SkScalar surfaceScale = random->nextSScalar1(); | 1446 SkScalar surfaceScale = random->nextSScalar1(); |
| 1443 SkScalar ks = random->nextUScalar1(); | 1447 SkScalar ks = random->nextUScalar1(); |
| 1444 SkScalar shininess = random->nextUScalar1(); | 1448 SkScalar shininess = random->nextUScalar1(); |
| 1445 SkAutoTUnref<SkLight> light(create_random_light(random)); | 1449 SkAutoTUnref<SkLight> light(create_random_light(random)); |
| 1446 SkMatrix matrix; | 1450 SkMatrix matrix; |
| 1447 for (int i = 0; i < 9; i++) { | 1451 for (int i = 0; i < 9; i++) { |
| 1448 matrix[i] = random->nextUScalar1(); | 1452 matrix[i] = random->nextUScalar1(); |
| 1449 } | 1453 } |
| 1450 return GrSpecularLightingEffect::Create(textures[GrEffectUnitTest::kAlphaTex
tureIdx], | 1454 return GrSpecularLightingEffect::Create(textures[GrEffectUnitTest::kAlphaTex
tureIdx], |
| 1451 light, surfaceScale, matrix, ks, shi
niness); | 1455 light, surfaceScale, matrix, ks, shi
niness); |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1610 | 1614 |
| 1611 builder->fsCodeAppendf("%s(%s)", fLightColorFunc.c_str(), surfaceToLight); | 1615 builder->fsCodeAppendf("%s(%s)", fLightColorFunc.c_str(), surfaceToLight); |
| 1612 } | 1616 } |
| 1613 | 1617 |
| 1614 #endif | 1618 #endif |
| 1615 | 1619 |
| 1616 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingImageFilter) | 1620 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingImageFilter) |
| 1617 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDiffuseLightingImageFilter) | 1621 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDiffuseLightingImageFilter) |
| 1618 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSpecularLightingImageFilter) | 1622 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSpecularLightingImageFilter) |
| 1619 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END | 1623 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END |
| OLD | NEW |