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 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
344 class GrLightingEffect : public GrSingleTextureEffect { | 344 class GrLightingEffect : public GrSingleTextureEffect { |
345 public: | 345 public: |
346 GrLightingEffect(GrTexture* texture, const SkLight* light, SkScalar surfaceS
cale, const SkMatrix& matrix); | 346 GrLightingEffect(GrTexture* texture, const SkLight* light, SkScalar surfaceS
cale, const SkMatrix& matrix); |
347 virtual ~GrLightingEffect(); | 347 virtual ~GrLightingEffect(); |
348 | 348 |
349 const SkLight* light() const { return fLight; } | 349 const SkLight* light() const { return fLight; } |
350 SkScalar surfaceScale() const { return fSurfaceScale; } | 350 SkScalar surfaceScale() const { return fSurfaceScale; } |
351 const SkMatrix& filterMatrix() const { return fFilterMatrix; } | 351 const SkMatrix& filterMatrix() const { return fFilterMatrix; } |
352 | 352 |
353 protected: | 353 protected: |
354 virtual bool onIsEqual(const GrProcessor&) const SK_OVERRIDE; | 354 virtual bool onIsEqual(const GrFragmentProcessor&) const SK_OVERRIDE; |
355 | 355 |
356 virtual void onComputeInvariantOutput(InvariantOutput* inout) const SK_OVERR
IDE { | 356 virtual void onComputeInvariantOutput(InvariantOutput* inout) const SK_OVERR
IDE { |
357 // lighting shaders are complicated. We just throw up our hands. | 357 // lighting shaders are complicated. We just throw up our hands. |
358 inout->mulByUnknownColor(); | 358 inout->mulByUnknownColor(); |
359 } | 359 } |
360 | 360 |
361 private: | 361 private: |
362 typedef GrSingleTextureEffect INHERITED; | 362 typedef GrSingleTextureEffect INHERITED; |
363 const SkLight* fLight; | 363 const SkLight* fLight; |
364 SkScalar fSurfaceScale; | 364 SkScalar fSurfaceScale; |
(...skipping 15 matching lines...) Expand all Loading... |
380 } | 380 } |
381 | 381 |
382 static const char* Name() { return "DiffuseLighting"; } | 382 static const char* Name() { return "DiffuseLighting"; } |
383 | 383 |
384 typedef GrGLDiffuseLightingEffect GLProcessor; | 384 typedef GrGLDiffuseLightingEffect GLProcessor; |
385 | 385 |
386 virtual const GrBackendFragmentProcessorFactory& getFactory() const SK_OVERR
IDE; | 386 virtual const GrBackendFragmentProcessorFactory& getFactory() const SK_OVERR
IDE; |
387 SkScalar kd() const { return fKD; } | 387 SkScalar kd() const { return fKD; } |
388 | 388 |
389 private: | 389 private: |
390 virtual bool onIsEqual(const GrProcessor&) const SK_OVERRIDE; | 390 virtual bool onIsEqual(const GrFragmentProcessor&) const SK_OVERRIDE; |
391 | 391 |
392 GrDiffuseLightingEffect(GrTexture* texture, | 392 GrDiffuseLightingEffect(GrTexture* texture, |
393 const SkLight* light, | 393 const SkLight* light, |
394 SkScalar surfaceScale, | 394 SkScalar surfaceScale, |
395 const SkMatrix& matrix, | 395 const SkMatrix& matrix, |
396 SkScalar kd); | 396 SkScalar kd); |
397 | 397 |
398 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; | 398 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; |
399 typedef GrLightingEffect INHERITED; | 399 typedef GrLightingEffect INHERITED; |
400 SkScalar fKD; | 400 SkScalar fKD; |
(...skipping 16 matching lines...) Expand all Loading... |
417 } | 417 } |
418 static const char* Name() { return "SpecularLighting"; } | 418 static const char* Name() { return "SpecularLighting"; } |
419 | 419 |
420 typedef GrGLSpecularLightingEffect GLProcessor; | 420 typedef GrGLSpecularLightingEffect GLProcessor; |
421 | 421 |
422 virtual const GrBackendFragmentProcessorFactory& getFactory() const SK_OVERR
IDE; | 422 virtual const GrBackendFragmentProcessorFactory& getFactory() const SK_OVERR
IDE; |
423 SkScalar ks() const { return fKS; } | 423 SkScalar ks() const { return fKS; } |
424 SkScalar shininess() const { return fShininess; } | 424 SkScalar shininess() const { return fShininess; } |
425 | 425 |
426 private: | 426 private: |
427 virtual bool onIsEqual(const GrProcessor&) const SK_OVERRIDE; | 427 virtual bool onIsEqual(const GrFragmentProcessor&) const SK_OVERRIDE; |
428 | 428 |
429 GrSpecularLightingEffect(GrTexture* texture, | 429 GrSpecularLightingEffect(GrTexture* texture, |
430 const SkLight* light, | 430 const SkLight* light, |
431 SkScalar surfaceScale, | 431 SkScalar surfaceScale, |
432 const SkMatrix& matrix, | 432 const SkMatrix& matrix, |
433 SkScalar ks, | 433 SkScalar ks, |
434 SkScalar shininess); | 434 SkScalar shininess); |
435 | 435 |
436 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; | 436 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; |
437 typedef GrLightingEffect INHERITED; | 437 typedef GrLightingEffect INHERITED; |
(...skipping 857 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1295 fLight->ref(); | 1295 fLight->ref(); |
1296 if (light->requiresFragmentPosition()) { | 1296 if (light->requiresFragmentPosition()) { |
1297 this->setWillReadFragmentPosition(); | 1297 this->setWillReadFragmentPosition(); |
1298 } | 1298 } |
1299 } | 1299 } |
1300 | 1300 |
1301 GrLightingEffect::~GrLightingEffect() { | 1301 GrLightingEffect::~GrLightingEffect() { |
1302 fLight->unref(); | 1302 fLight->unref(); |
1303 } | 1303 } |
1304 | 1304 |
1305 bool GrLightingEffect::onIsEqual(const GrProcessor& sBase) const { | 1305 bool GrLightingEffect::onIsEqual(const GrFragmentProcessor& sBase) const { |
1306 const GrLightingEffect& s = sBase.cast<GrLightingEffect>(); | 1306 const GrLightingEffect& s = sBase.cast<GrLightingEffect>(); |
1307 return this->texture(0) == s.texture(0) && | 1307 return this->texture(0) == s.texture(0) && |
1308 fLight->isEqual(*s.fLight) && | 1308 fLight->isEqual(*s.fLight) && |
1309 fSurfaceScale == s.fSurfaceScale; | 1309 fSurfaceScale == s.fSurfaceScale; |
1310 } | 1310 } |
1311 | 1311 |
1312 /////////////////////////////////////////////////////////////////////////////// | 1312 /////////////////////////////////////////////////////////////////////////////// |
1313 | 1313 |
1314 GrDiffuseLightingEffect::GrDiffuseLightingEffect(GrTexture* texture, | 1314 GrDiffuseLightingEffect::GrDiffuseLightingEffect(GrTexture* texture, |
1315 const SkLight* light, | 1315 const SkLight* light, |
1316 SkScalar surfaceScale, | 1316 SkScalar surfaceScale, |
1317 const SkMatrix& matrix, | 1317 const SkMatrix& matrix, |
1318 SkScalar kd) | 1318 SkScalar kd) |
1319 : INHERITED(texture, light, surfaceScale, matrix), fKD(kd) { | 1319 : INHERITED(texture, light, surfaceScale, matrix), fKD(kd) { |
1320 } | 1320 } |
1321 | 1321 |
1322 const GrBackendFragmentProcessorFactory& GrDiffuseLightingEffect::getFactory() c
onst { | 1322 const GrBackendFragmentProcessorFactory& GrDiffuseLightingEffect::getFactory() c
onst { |
1323 return GrTBackendFragmentProcessorFactory<GrDiffuseLightingEffect>::getInsta
nce(); | 1323 return GrTBackendFragmentProcessorFactory<GrDiffuseLightingEffect>::getInsta
nce(); |
1324 } | 1324 } |
1325 | 1325 |
1326 bool GrDiffuseLightingEffect::onIsEqual(const GrProcessor& sBase) const { | 1326 bool GrDiffuseLightingEffect::onIsEqual(const GrFragmentProcessor& sBase) const
{ |
1327 const GrDiffuseLightingEffect& s = sBase.cast<GrDiffuseLightingEffect>(); | 1327 const GrDiffuseLightingEffect& s = sBase.cast<GrDiffuseLightingEffect>(); |
1328 return INHERITED::onIsEqual(sBase) && | 1328 return INHERITED::onIsEqual(sBase) && |
1329 this->kd() == s.kd(); | 1329 this->kd() == s.kd(); |
1330 } | 1330 } |
1331 | 1331 |
1332 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrDiffuseLightingEffect); | 1332 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrDiffuseLightingEffect); |
1333 | 1333 |
1334 GrFragmentProcessor* GrDiffuseLightingEffect::TestCreate(SkRandom* random, | 1334 GrFragmentProcessor* GrDiffuseLightingEffect::TestCreate(SkRandom* random, |
1335 GrContext* context, | 1335 GrContext* context, |
1336 const GrDrawTargetCaps&, | 1336 const GrDrawTargetCaps&, |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1522 SkScalar shininess) | 1522 SkScalar shininess) |
1523 : INHERITED(texture, light, surfaceScale, matrix), | 1523 : INHERITED(texture, light, surfaceScale, matrix), |
1524 fKS(ks), | 1524 fKS(ks), |
1525 fShininess(shininess) { | 1525 fShininess(shininess) { |
1526 } | 1526 } |
1527 | 1527 |
1528 const GrBackendFragmentProcessorFactory& GrSpecularLightingEffect::getFactory()
const { | 1528 const GrBackendFragmentProcessorFactory& GrSpecularLightingEffect::getFactory()
const { |
1529 return GrTBackendFragmentProcessorFactory<GrSpecularLightingEffect>::getInst
ance(); | 1529 return GrTBackendFragmentProcessorFactory<GrSpecularLightingEffect>::getInst
ance(); |
1530 } | 1530 } |
1531 | 1531 |
1532 bool GrSpecularLightingEffect::onIsEqual(const GrProcessor& sBase) const { | 1532 bool GrSpecularLightingEffect::onIsEqual(const GrFragmentProcessor& sBase) const
{ |
1533 const GrSpecularLightingEffect& s = sBase.cast<GrSpecularLightingEffect>(); | 1533 const GrSpecularLightingEffect& s = sBase.cast<GrSpecularLightingEffect>(); |
1534 return INHERITED::onIsEqual(sBase) && | 1534 return INHERITED::onIsEqual(sBase) && |
1535 this->ks() == s.ks() && | 1535 this->ks() == s.ks() && |
1536 this->shininess() == s.shininess(); | 1536 this->shininess() == s.shininess(); |
1537 } | 1537 } |
1538 | 1538 |
1539 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrSpecularLightingEffect); | 1539 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrSpecularLightingEffect); |
1540 | 1540 |
1541 GrFragmentProcessor* GrSpecularLightingEffect::TestCreate(SkRandom* random, | 1541 GrFragmentProcessor* GrSpecularLightingEffect::TestCreate(SkRandom* random, |
1542 GrContext* context, | 1542 GrContext* context, |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1718 | 1718 |
1719 fsBuilder->codeAppendf("%s(%s)", fLightColorFunc.c_str(), surfaceToLight); | 1719 fsBuilder->codeAppendf("%s(%s)", fLightColorFunc.c_str(), surfaceToLight); |
1720 } | 1720 } |
1721 | 1721 |
1722 #endif | 1722 #endif |
1723 | 1723 |
1724 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingImageFilter) | 1724 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingImageFilter) |
1725 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDiffuseLightingImageFilter) | 1725 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDiffuseLightingImageFilter) |
1726 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSpecularLightingImageFilter) | 1726 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSpecularLightingImageFilter) |
1727 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END | 1727 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END |
OLD | NEW |