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" |
11 #include "SkDevice.h" | 11 #include "SkDevice.h" |
12 #include "SkPoint3.h" | 12 #include "SkPoint3.h" |
13 #include "SkReadBuffer.h" | 13 #include "SkReadBuffer.h" |
14 #include "SkTypes.h" | 14 #include "SkTypes.h" |
15 #include "SkWriteBuffer.h" | 15 #include "SkWriteBuffer.h" |
16 | 16 |
17 #if SK_SUPPORT_GPU | 17 #if SK_SUPPORT_GPU |
18 #include "GrContext.h" | 18 #include "GrContext.h" |
19 #include "GrDrawContext.h" | 19 #include "GrDrawContext.h" |
20 #include "GrFragmentProcessor.h" | 20 #include "GrFragmentProcessor.h" |
21 #include "GrInvariantOutput.h" | 21 #include "GrInvariantOutput.h" |
22 #include "GrPaint.h" | 22 #include "GrPaint.h" |
23 #include "effects/GrSingleTextureEffect.h" | 23 #include "effects/GrSingleTextureEffect.h" |
24 #include "gl/GrGLFragmentProcessor.h" | 24 #include "glsl/GrGLSLFragmentProcessor.h" |
25 #include "glsl/GrGLSLFragmentShaderBuilder.h" | 25 #include "glsl/GrGLSLFragmentShaderBuilder.h" |
26 #include "glsl/GrGLSLProgramBuilder.h" | 26 #include "glsl/GrGLSLProgramBuilder.h" |
27 #include "glsl/GrGLSLProgramDataManager.h" | 27 #include "glsl/GrGLSLProgramDataManager.h" |
28 | 28 |
29 class GrGLDiffuseLightingEffect; | 29 class GrGLDiffuseLightingEffect; |
30 class GrGLSpecularLightingEffect; | 30 class GrGLSpecularLightingEffect; |
31 | 31 |
32 // For brevity | 32 // For brevity |
33 typedef GrGLSLProgramDataManager::UniformHandle UniformHandle; | 33 typedef GrGLSLProgramDataManager::UniformHandle UniformHandle; |
34 #endif | 34 #endif |
(...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
524 SkScalar kd, | 524 SkScalar kd, |
525 BoundaryMode boundaryMode) { | 525 BoundaryMode boundaryMode) { |
526 return new GrDiffuseLightingEffect(texture, light, surfaceScale, matrix,
kd, boundaryMode); | 526 return new GrDiffuseLightingEffect(texture, light, surfaceScale, matrix,
kd, boundaryMode); |
527 } | 527 } |
528 | 528 |
529 const char* name() const override { return "DiffuseLighting"; } | 529 const char* name() const override { return "DiffuseLighting"; } |
530 | 530 |
531 SkScalar kd() const { return fKD; } | 531 SkScalar kd() const { return fKD; } |
532 | 532 |
533 private: | 533 private: |
534 GrGLFragmentProcessor* onCreateGLInstance() const override; | 534 GrGLSLFragmentProcessor* onCreateGLInstance() const override; |
535 | 535 |
536 void onGetGLProcessorKey(const GrGLSLCaps&, GrProcessorKeyBuilder*) const ov
erride; | 536 void onGetGLProcessorKey(const GrGLSLCaps&, GrProcessorKeyBuilder*) const ov
erride; |
537 | 537 |
538 bool onIsEqual(const GrFragmentProcessor&) const override; | 538 bool onIsEqual(const GrFragmentProcessor&) const override; |
539 | 539 |
540 GrDiffuseLightingEffect(GrTexture* texture, | 540 GrDiffuseLightingEffect(GrTexture* texture, |
541 const SkImageFilterLight* light, | 541 const SkImageFilterLight* light, |
542 SkScalar surfaceScale, | 542 SkScalar surfaceScale, |
543 const SkMatrix& matrix, | 543 const SkMatrix& matrix, |
544 SkScalar kd, | 544 SkScalar kd, |
(...skipping 12 matching lines...) Expand all Loading... |
557 const SkMatrix& matrix, | 557 const SkMatrix& matrix, |
558 SkScalar ks, | 558 SkScalar ks, |
559 SkScalar shininess, | 559 SkScalar shininess, |
560 BoundaryMode boundaryMode) { | 560 BoundaryMode boundaryMode) { |
561 return new GrSpecularLightingEffect(texture, light, surfaceScale, matrix
, ks, shininess, | 561 return new GrSpecularLightingEffect(texture, light, surfaceScale, matrix
, ks, shininess, |
562 boundaryMode); | 562 boundaryMode); |
563 } | 563 } |
564 | 564 |
565 const char* name() const override { return "SpecularLighting"; } | 565 const char* name() const override { return "SpecularLighting"; } |
566 | 566 |
567 GrGLFragmentProcessor* onCreateGLInstance() const override; | 567 GrGLSLFragmentProcessor* onCreateGLInstance() const override; |
568 | 568 |
569 SkScalar ks() const { return fKS; } | 569 SkScalar ks() const { return fKS; } |
570 SkScalar shininess() const { return fShininess; } | 570 SkScalar shininess() const { return fShininess; } |
571 | 571 |
572 private: | 572 private: |
573 void onGetGLProcessorKey(const GrGLSLCaps&, GrProcessorKeyBuilder*) const ov
erride; | 573 void onGetGLProcessorKey(const GrGLSLCaps&, GrProcessorKeyBuilder*) const ov
erride; |
574 | 574 |
575 bool onIsEqual(const GrFragmentProcessor&) const override; | 575 bool onIsEqual(const GrFragmentProcessor&) const override; |
576 | 576 |
577 GrSpecularLightingEffect(GrTexture* texture, | 577 GrSpecularLightingEffect(GrTexture* texture, |
(...skipping 923 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1501 break; | 1501 break; |
1502 default: | 1502 default: |
1503 SkASSERT(false); | 1503 SkASSERT(false); |
1504 break; | 1504 break; |
1505 } | 1505 } |
1506 return result; | 1506 return result; |
1507 } | 1507 } |
1508 | 1508 |
1509 } | 1509 } |
1510 | 1510 |
1511 class GrGLLightingEffect : public GrGLFragmentProcessor { | 1511 class GrGLLightingEffect : public GrGLSLFragmentProcessor { |
1512 public: | 1512 public: |
1513 GrGLLightingEffect(const GrProcessor&); | 1513 GrGLLightingEffect(const GrProcessor&); |
1514 virtual ~GrGLLightingEffect(); | 1514 virtual ~GrGLLightingEffect(); |
1515 | 1515 |
1516 void emitCode(EmitArgs&) override; | 1516 void emitCode(EmitArgs&) override; |
1517 | 1517 |
1518 static inline void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessor
KeyBuilder* b); | 1518 static inline void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessor
KeyBuilder* b); |
1519 | 1519 |
1520 protected: | 1520 protected: |
1521 /** | 1521 /** |
1522 * Subclasses of GrGLLightingEffect must call INHERITED::onSetData(); | 1522 * Subclasses of GrGLLightingEffect must call INHERITED::onSetData(); |
1523 */ | 1523 */ |
1524 void onSetData(const GrGLSLProgramDataManager&, const GrProcessor&) override
; | 1524 void onSetData(const GrGLSLProgramDataManager&, const GrProcessor&) override
; |
1525 | 1525 |
1526 virtual void emitLightFunc(GrGLSLFPBuilder*, SkString* funcName) = 0; | 1526 virtual void emitLightFunc(GrGLSLFPBuilder*, SkString* funcName) = 0; |
1527 | 1527 |
1528 private: | 1528 private: |
1529 typedef GrGLFragmentProcessor INHERITED; | 1529 typedef GrGLSLFragmentProcessor INHERITED; |
1530 | 1530 |
1531 UniformHandle fImageIncrementUni; | 1531 UniformHandle fImageIncrementUni; |
1532 UniformHandle fSurfaceScaleUni; | 1532 UniformHandle fSurfaceScaleUni; |
1533 GrGLLight* fLight; | 1533 GrGLLight* fLight; |
1534 BoundaryMode fBoundaryMode; | 1534 BoundaryMode fBoundaryMode; |
1535 }; | 1535 }; |
1536 | 1536 |
1537 /////////////////////////////////////////////////////////////////////////////// | 1537 /////////////////////////////////////////////////////////////////////////////// |
1538 | 1538 |
1539 class GrGLDiffuseLightingEffect : public GrGLLightingEffect { | 1539 class GrGLDiffuseLightingEffect : public GrGLLightingEffect { |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1612 const GrDiffuseLightingEffect& s = sBase.cast<GrDiffuseLightingEffect>(); | 1612 const GrDiffuseLightingEffect& s = sBase.cast<GrDiffuseLightingEffect>(); |
1613 return INHERITED::onIsEqual(sBase) && | 1613 return INHERITED::onIsEqual(sBase) && |
1614 this->kd() == s.kd(); | 1614 this->kd() == s.kd(); |
1615 } | 1615 } |
1616 | 1616 |
1617 void GrDiffuseLightingEffect::onGetGLProcessorKey(const GrGLSLCaps& caps, | 1617 void GrDiffuseLightingEffect::onGetGLProcessorKey(const GrGLSLCaps& caps, |
1618 GrProcessorKeyBuilder* b) cons
t { | 1618 GrProcessorKeyBuilder* b) cons
t { |
1619 GrGLDiffuseLightingEffect::GenKey(*this, caps, b); | 1619 GrGLDiffuseLightingEffect::GenKey(*this, caps, b); |
1620 } | 1620 } |
1621 | 1621 |
1622 GrGLFragmentProcessor* GrDiffuseLightingEffect::onCreateGLInstance() const { | 1622 GrGLSLFragmentProcessor* GrDiffuseLightingEffect::onCreateGLInstance() const { |
1623 return new GrGLDiffuseLightingEffect(*this); | 1623 return new GrGLDiffuseLightingEffect(*this); |
1624 } | 1624 } |
1625 | 1625 |
1626 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrDiffuseLightingEffect); | 1626 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrDiffuseLightingEffect); |
1627 | 1627 |
1628 const GrFragmentProcessor* GrDiffuseLightingEffect::TestCreate(GrProcessorTestDa
ta* d) { | 1628 const GrFragmentProcessor* GrDiffuseLightingEffect::TestCreate(GrProcessorTestDa
ta* d) { |
1629 SkScalar surfaceScale = d->fRandom->nextSScalar1(); | 1629 SkScalar surfaceScale = d->fRandom->nextSScalar1(); |
1630 SkScalar kd = d->fRandom->nextUScalar1(); | 1630 SkScalar kd = d->fRandom->nextUScalar1(); |
1631 SkAutoTUnref<SkImageFilterLight> light(create_random_light(d->fRandom)); | 1631 SkAutoTUnref<SkImageFilterLight> light(create_random_light(d->fRandom)); |
1632 SkMatrix matrix; | 1632 SkMatrix matrix; |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1813 return INHERITED::onIsEqual(sBase) && | 1813 return INHERITED::onIsEqual(sBase) && |
1814 this->ks() == s.ks() && | 1814 this->ks() == s.ks() && |
1815 this->shininess() == s.shininess(); | 1815 this->shininess() == s.shininess(); |
1816 } | 1816 } |
1817 | 1817 |
1818 void GrSpecularLightingEffect::onGetGLProcessorKey(const GrGLSLCaps& caps, | 1818 void GrSpecularLightingEffect::onGetGLProcessorKey(const GrGLSLCaps& caps, |
1819 GrProcessorKeyBuilder* b) con
st { | 1819 GrProcessorKeyBuilder* b) con
st { |
1820 GrGLSpecularLightingEffect::GenKey(*this, caps, b); | 1820 GrGLSpecularLightingEffect::GenKey(*this, caps, b); |
1821 } | 1821 } |
1822 | 1822 |
1823 GrGLFragmentProcessor* GrSpecularLightingEffect::onCreateGLInstance() const { | 1823 GrGLSLFragmentProcessor* GrSpecularLightingEffect::onCreateGLInstance() const { |
1824 return new GrGLSpecularLightingEffect(*this); | 1824 return new GrGLSpecularLightingEffect(*this); |
1825 } | 1825 } |
1826 | 1826 |
1827 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrSpecularLightingEffect); | 1827 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrSpecularLightingEffect); |
1828 | 1828 |
1829 const GrFragmentProcessor* GrSpecularLightingEffect::TestCreate(GrProcessorTestD
ata* d) { | 1829 const GrFragmentProcessor* GrSpecularLightingEffect::TestCreate(GrProcessorTestD
ata* d) { |
1830 SkScalar surfaceScale = d->fRandom->nextSScalar1(); | 1830 SkScalar surfaceScale = d->fRandom->nextSScalar1(); |
1831 SkScalar ks = d->fRandom->nextUScalar1(); | 1831 SkScalar ks = d->fRandom->nextUScalar1(); |
1832 SkScalar shininess = d->fRandom->nextUScalar1(); | 1832 SkScalar shininess = d->fRandom->nextUScalar1(); |
1833 SkAutoTUnref<SkImageFilterLight> light(create_random_light(d->fRandom)); | 1833 SkAutoTUnref<SkImageFilterLight> light(create_random_light(d->fRandom)); |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2014 | 2014 |
2015 fsBuilder->codeAppendf("%s(%s)", fLightColorFunc.c_str(), surfaceToLight); | 2015 fsBuilder->codeAppendf("%s(%s)", fLightColorFunc.c_str(), surfaceToLight); |
2016 } | 2016 } |
2017 | 2017 |
2018 #endif | 2018 #endif |
2019 | 2019 |
2020 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingImageFilter) | 2020 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingImageFilter) |
2021 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDiffuseLightingImageFilter) | 2021 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDiffuseLightingImageFilter) |
2022 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSpecularLightingImageFilter) | 2022 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSpecularLightingImageFilter) |
2023 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END | 2023 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END |
OLD | NEW |