| 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 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 sk_sp<SkImageFilter> input, | 352 sk_sp<SkImageFilter> input, |
| 353 const CropRect* cropRect) | 353 const CropRect* cropRect) |
| 354 : INHERITED(std::move(light), surfaceScale, std::move(input), cropRect)
{ | 354 : INHERITED(std::move(light), surfaceScale, std::move(input), cropRect)
{ |
| 355 } | 355 } |
| 356 | 356 |
| 357 #if SK_SUPPORT_GPU | 357 #if SK_SUPPORT_GPU |
| 358 sk_sp<SkSpecialImage> filterImageGPU(SkSpecialImage* source, | 358 sk_sp<SkSpecialImage> filterImageGPU(SkSpecialImage* source, |
| 359 SkSpecialImage* input, | 359 SkSpecialImage* input, |
| 360 const SkIRect& bounds, | 360 const SkIRect& bounds, |
| 361 const SkMatrix& matrix) const; | 361 const SkMatrix& matrix) const; |
| 362 virtual GrFragmentProcessor* getFragmentProcessor(GrTexture*, | 362 virtual sk_sp<GrFragmentProcessor> makeFragmentProcessor(GrTexture*, |
| 363 const SkMatrix&, | 363 const SkMatrix&, |
| 364 const SkIRect* srcBounds, | 364 const SkIRect* srcB
ounds, |
| 365 BoundaryMode boundaryMode)
const = 0; | 365 BoundaryMode bounda
ryMode) const = 0; |
| 366 #endif | 366 #endif |
| 367 private: | 367 private: |
| 368 #if SK_SUPPORT_GPU | 368 #if SK_SUPPORT_GPU |
| 369 void drawRect(GrDrawContext* drawContext, | 369 void drawRect(GrDrawContext* drawContext, |
| 370 GrTexture* src, | 370 GrTexture* src, |
| 371 const SkMatrix& matrix, | 371 const SkMatrix& matrix, |
| 372 const GrClip& clip, | 372 const GrClip& clip, |
| 373 const SkRect& dstRect, | 373 const SkRect& dstRect, |
| 374 BoundaryMode boundaryMode, | 374 BoundaryMode boundaryMode, |
| 375 const SkIRect* srcBounds, | 375 const SkIRect* srcBounds, |
| 376 const SkIRect& bounds) const; | 376 const SkIRect& bounds) const; |
| 377 #endif | 377 #endif |
| 378 typedef SkLightingImageFilter INHERITED; | 378 typedef SkLightingImageFilter INHERITED; |
| 379 }; | 379 }; |
| 380 | 380 |
| 381 #if SK_SUPPORT_GPU | 381 #if SK_SUPPORT_GPU |
| 382 void SkLightingImageFilterInternal::drawRect(GrDrawContext* drawContext, | 382 void SkLightingImageFilterInternal::drawRect(GrDrawContext* drawContext, |
| 383 GrTexture* src, | 383 GrTexture* src, |
| 384 const SkMatrix& matrix, | 384 const SkMatrix& matrix, |
| 385 const GrClip& clip, | 385 const GrClip& clip, |
| 386 const SkRect& dstRect, | 386 const SkRect& dstRect, |
| 387 BoundaryMode boundaryMode, | 387 BoundaryMode boundaryMode, |
| 388 const SkIRect* srcBounds, | 388 const SkIRect* srcBounds, |
| 389 const SkIRect& bounds) const { | 389 const SkIRect& bounds) const { |
| 390 SkRect srcRect = dstRect.makeOffset(SkIntToScalar(bounds.x()), SkIntToScalar
(bounds.y())); | 390 SkRect srcRect = dstRect.makeOffset(SkIntToScalar(bounds.x()), SkIntToScalar
(bounds.y())); |
| 391 GrPaint paint; | 391 GrPaint paint; |
| 392 // SRGBTODO: AllowSRGBInputs? | 392 // SRGBTODO: AllowSRGBInputs? |
| 393 GrFragmentProcessor* fp = this->getFragmentProcessor(src, matrix, srcBounds,
boundaryMode); | 393 sk_sp<GrFragmentProcessor> fp(this->makeFragmentProcessor(src, matrix, srcBo
unds, |
| 394 paint.addColorFragmentProcessor(fp)->unref(); | 394 boundaryMode)); |
| 395 paint.addColorFragmentProcessor(std::move(fp)); |
| 395 paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode); | 396 paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode); |
| 396 drawContext->fillRectToRect(clip, paint, SkMatrix::I(), dstRect, srcRect); | 397 drawContext->fillRectToRect(clip, paint, SkMatrix::I(), dstRect, srcRect); |
| 397 } | 398 } |
| 398 | 399 |
| 399 sk_sp<SkSpecialImage> SkLightingImageFilterInternal::filterImageGPU(SkSpecialIma
ge* source, | 400 sk_sp<SkSpecialImage> SkLightingImageFilterInternal::filterImageGPU(SkSpecialIma
ge* source, |
| 400 SkSpecialIma
ge* input, | 401 SkSpecialIma
ge* input, |
| 401 const SkIRec
t& offsetBounds, | 402 const SkIRec
t& offsetBounds, |
| 402 const SkMatr
ix& matrix) const { | 403 const SkMatr
ix& matrix) const { |
| 403 SkASSERT(source->isTextureBacked()); | 404 SkASSERT(source->isTextureBacked()); |
| 404 | 405 |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 473 protected: | 474 protected: |
| 474 SkDiffuseLightingImageFilter(sk_sp<SkImageFilterLight> light, SkScalar surfa
ceScale, | 475 SkDiffuseLightingImageFilter(sk_sp<SkImageFilterLight> light, SkScalar surfa
ceScale, |
| 475 SkScalar kd, | 476 SkScalar kd, |
| 476 sk_sp<SkImageFilter> input, const CropRect* cro
pRect); | 477 sk_sp<SkImageFilter> input, const CropRect* cro
pRect); |
| 477 void flatten(SkWriteBuffer& buffer) const override; | 478 void flatten(SkWriteBuffer& buffer) const override; |
| 478 | 479 |
| 479 sk_sp<SkSpecialImage> onFilterImage(SkSpecialImage* source, const Context&, | 480 sk_sp<SkSpecialImage> onFilterImage(SkSpecialImage* source, const Context&, |
| 480 SkIPoint* offset) const override; | 481 SkIPoint* offset) const override; |
| 481 | 482 |
| 482 #if SK_SUPPORT_GPU | 483 #if SK_SUPPORT_GPU |
| 483 GrFragmentProcessor* getFragmentProcessor(GrTexture*, const SkMatrix&, const
SkIRect* bounds, | 484 sk_sp<GrFragmentProcessor> makeFragmentProcessor(GrTexture*, const SkMatrix&
, |
| 484 BoundaryMode) const override; | 485 const SkIRect* bounds, |
| 486 BoundaryMode) const overrid
e; |
| 485 #endif | 487 #endif |
| 486 | 488 |
| 487 private: | 489 private: |
| 488 friend class SkLightingImageFilter; | 490 friend class SkLightingImageFilter; |
| 489 SkScalar fKD; | 491 SkScalar fKD; |
| 490 | 492 |
| 491 typedef SkLightingImageFilterInternal INHERITED; | 493 typedef SkLightingImageFilterInternal INHERITED; |
| 492 }; | 494 }; |
| 493 | 495 |
| 494 class SkSpecularLightingImageFilter : public SkLightingImageFilterInternal { | 496 class SkSpecularLightingImageFilter : public SkLightingImageFilterInternal { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 508 SkSpecularLightingImageFilter(sk_sp<SkImageFilterLight> light, | 510 SkSpecularLightingImageFilter(sk_sp<SkImageFilterLight> light, |
| 509 SkScalar surfaceScale, SkScalar ks, | 511 SkScalar surfaceScale, SkScalar ks, |
| 510 SkScalar shininess, | 512 SkScalar shininess, |
| 511 sk_sp<SkImageFilter> input, const CropRect*); | 513 sk_sp<SkImageFilter> input, const CropRect*); |
| 512 void flatten(SkWriteBuffer& buffer) const override; | 514 void flatten(SkWriteBuffer& buffer) const override; |
| 513 | 515 |
| 514 sk_sp<SkSpecialImage> onFilterImage(SkSpecialImage* source, const Context&, | 516 sk_sp<SkSpecialImage> onFilterImage(SkSpecialImage* source, const Context&, |
| 515 SkIPoint* offset) const override; | 517 SkIPoint* offset) const override; |
| 516 | 518 |
| 517 #if SK_SUPPORT_GPU | 519 #if SK_SUPPORT_GPU |
| 518 GrFragmentProcessor* getFragmentProcessor(GrTexture*, const SkMatrix&, const
SkIRect* bounds, | 520 sk_sp<GrFragmentProcessor> makeFragmentProcessor(GrTexture*, const SkMatrix&
, |
| 519 BoundaryMode) const override; | 521 const SkIRect* bounds, |
| 522 BoundaryMode) const overrid
e; |
| 520 #endif | 523 #endif |
| 521 | 524 |
| 522 private: | 525 private: |
| 523 SkScalar fKS; | 526 SkScalar fKS; |
| 524 SkScalar fShininess; | 527 SkScalar fShininess; |
| 525 friend class SkLightingImageFilter; | 528 friend class SkLightingImageFilter; |
| 526 typedef SkLightingImageFilterInternal INHERITED; | 529 typedef SkLightingImageFilterInternal INHERITED; |
| 527 }; | 530 }; |
| 528 | 531 |
| 529 #if SK_SUPPORT_GPU | 532 #if SK_SUPPORT_GPU |
| (...skipping 23 matching lines...) Expand all Loading... |
| 553 SkScalar fSurfaceScale; | 556 SkScalar fSurfaceScale; |
| 554 SkMatrix fFilterMatrix; | 557 SkMatrix fFilterMatrix; |
| 555 BoundaryMode fBoundaryMode; | 558 BoundaryMode fBoundaryMode; |
| 556 GrTextureDomain fDomain; | 559 GrTextureDomain fDomain; |
| 557 | 560 |
| 558 typedef GrSingleTextureEffect INHERITED; | 561 typedef GrSingleTextureEffect INHERITED; |
| 559 }; | 562 }; |
| 560 | 563 |
| 561 class GrDiffuseLightingEffect : public GrLightingEffect { | 564 class GrDiffuseLightingEffect : public GrLightingEffect { |
| 562 public: | 565 public: |
| 563 static GrFragmentProcessor* Create(GrTexture* texture, | 566 static sk_sp<GrFragmentProcessor> Make(GrTexture* texture, |
| 564 const SkImageFilterLight* light, | 567 const SkImageFilterLight* light, |
| 565 SkScalar surfaceScale, | 568 SkScalar surfaceScale, |
| 566 const SkMatrix& matrix, | 569 const SkMatrix& matrix, |
| 567 SkScalar kd, | 570 SkScalar kd, |
| 568 BoundaryMode boundaryMode, | 571 BoundaryMode boundaryMode, |
| 569 const SkIRect* srcBounds) { | 572 const SkIRect* srcBounds) { |
| 570 return new GrDiffuseLightingEffect(texture, light, surfaceScale, matrix,
kd, boundaryMode, | 573 return sk_sp<GrFragmentProcessor>( |
| 571 srcBounds); | 574 new GrDiffuseLightingEffect(texture, light, surfaceScale, matrix, kd
, boundaryMode, |
| 575 srcBounds)); |
| 572 } | 576 } |
| 573 | 577 |
| 574 const char* name() const override { return "DiffuseLighting"; } | 578 const char* name() const override { return "DiffuseLighting"; } |
| 575 | 579 |
| 576 SkScalar kd() const { return fKD; } | 580 SkScalar kd() const { return fKD; } |
| 577 | 581 |
| 578 private: | 582 private: |
| 579 GrGLSLFragmentProcessor* onCreateGLSLInstance() const override; | 583 GrGLSLFragmentProcessor* onCreateGLSLInstance() const override; |
| 580 | 584 |
| 581 void onGetGLSLProcessorKey(const GrGLSLCaps&, GrProcessorKeyBuilder*) const
override; | 585 void onGetGLSLProcessorKey(const GrGLSLCaps&, GrProcessorKeyBuilder*) const
override; |
| 582 | 586 |
| 583 bool onIsEqual(const GrFragmentProcessor&) const override; | 587 bool onIsEqual(const GrFragmentProcessor&) const override; |
| 584 | 588 |
| 585 GrDiffuseLightingEffect(GrTexture* texture, | 589 GrDiffuseLightingEffect(GrTexture* texture, |
| 586 const SkImageFilterLight* light, | 590 const SkImageFilterLight* light, |
| 587 SkScalar surfaceScale, | 591 SkScalar surfaceScale, |
| 588 const SkMatrix& matrix, | 592 const SkMatrix& matrix, |
| 589 SkScalar kd, | 593 SkScalar kd, |
| 590 BoundaryMode boundaryMode, | 594 BoundaryMode boundaryMode, |
| 591 const SkIRect* srcBounds); | 595 const SkIRect* srcBounds); |
| 592 | 596 |
| 593 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; | 597 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; |
| 594 typedef GrLightingEffect INHERITED; | 598 typedef GrLightingEffect INHERITED; |
| 595 SkScalar fKD; | 599 SkScalar fKD; |
| 596 }; | 600 }; |
| 597 | 601 |
| 598 class GrSpecularLightingEffect : public GrLightingEffect { | 602 class GrSpecularLightingEffect : public GrLightingEffect { |
| 599 public: | 603 public: |
| 600 static GrFragmentProcessor* Create(GrTexture* texture, | 604 static sk_sp<GrFragmentProcessor> Make(GrTexture* texture, |
| 601 const SkImageFilterLight* light, | 605 const SkImageFilterLight* light, |
| 602 SkScalar surfaceScale, | 606 SkScalar surfaceScale, |
| 603 const SkMatrix& matrix, | 607 const SkMatrix& matrix, |
| 604 SkScalar ks, | 608 SkScalar ks, |
| 605 SkScalar shininess, | 609 SkScalar shininess, |
| 606 BoundaryMode boundaryMode, | 610 BoundaryMode boundaryMode, |
| 607 const SkIRect* srcBounds) { | 611 const SkIRect* srcBounds) { |
| 608 return new GrSpecularLightingEffect(texture, light, surfaceScale, matrix
, ks, shininess, | 612 return sk_sp<GrFragmentProcessor>( |
| 609 boundaryMode, srcBounds); | 613 new GrSpecularLightingEffect(texture, light, surfaceScale, matrix, k
s, shininess, |
| 614 boundaryMode, srcBounds)); |
| 610 } | 615 } |
| 611 | 616 |
| 612 const char* name() const override { return "SpecularLighting"; } | 617 const char* name() const override { return "SpecularLighting"; } |
| 613 | 618 |
| 614 GrGLSLFragmentProcessor* onCreateGLSLInstance() const override; | 619 GrGLSLFragmentProcessor* onCreateGLSLInstance() const override; |
| 615 | 620 |
| 616 SkScalar ks() const { return fKS; } | 621 SkScalar ks() const { return fKS; } |
| 617 SkScalar shininess() const { return fShininess; } | 622 SkScalar shininess() const { return fShininess; } |
| 618 | 623 |
| 619 private: | 624 private: |
| (...skipping 703 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1323 | 1328 |
| 1324 #ifndef SK_IGNORE_TO_STRING | 1329 #ifndef SK_IGNORE_TO_STRING |
| 1325 void SkDiffuseLightingImageFilter::toString(SkString* str) const { | 1330 void SkDiffuseLightingImageFilter::toString(SkString* str) const { |
| 1326 str->appendf("SkDiffuseLightingImageFilter: ("); | 1331 str->appendf("SkDiffuseLightingImageFilter: ("); |
| 1327 str->appendf("kD: %f\n", fKD); | 1332 str->appendf("kD: %f\n", fKD); |
| 1328 str->append(")"); | 1333 str->append(")"); |
| 1329 } | 1334 } |
| 1330 #endif | 1335 #endif |
| 1331 | 1336 |
| 1332 #if SK_SUPPORT_GPU | 1337 #if SK_SUPPORT_GPU |
| 1333 GrFragmentProcessor* SkDiffuseLightingImageFilter::getFragmentProcessor( | 1338 sk_sp<GrFragmentProcessor> SkDiffuseLightingImageFilter::makeFragmentProcessor( |
| 1334 GrTexture* texture, | 1339 GrTexture* texture, |
| 1335 const SkMatrix& matrix, | 1340 const SkMatrix& matrix, |
| 1336 const SkIRect* srcBounds, | 1341 const SkIRect* srcBounds, |
| 1337 BoundaryMode boundaryMode) co
nst { | 1342 BoundaryMode boundaryMode) co
nst { |
| 1338 SkScalar scale = SkScalarMul(this->surfaceScale(), SkIntToScalar(255)); | 1343 SkScalar scale = SkScalarMul(this->surfaceScale(), SkIntToScalar(255)); |
| 1339 return GrDiffuseLightingEffect::Create(texture, this->light(), scale, matrix
, this->kd(), | 1344 return GrDiffuseLightingEffect::Make(texture, this->light(), scale, matrix,
this->kd(), |
| 1340 boundaryMode, srcBounds); | 1345 boundaryMode, srcBounds); |
| 1341 } | 1346 } |
| 1342 #endif | 1347 #endif |
| 1343 | 1348 |
| 1344 /////////////////////////////////////////////////////////////////////////////// | 1349 /////////////////////////////////////////////////////////////////////////////// |
| 1345 | 1350 |
| 1346 sk_sp<SkImageFilter> SkSpecularLightingImageFilter::Make(sk_sp<SkImageFilterLigh
t> light, | 1351 sk_sp<SkImageFilter> SkSpecularLightingImageFilter::Make(sk_sp<SkImageFilterLigh
t> light, |
| 1347 SkScalar surfaceScale, | 1352 SkScalar surfaceScale, |
| 1348 SkScalar ks, | 1353 SkScalar ks, |
| 1349 SkScalar shininess, | 1354 SkScalar shininess, |
| 1350 sk_sp<SkImageFilter> in
put, | 1355 sk_sp<SkImageFilter> in
put, |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1488 | 1493 |
| 1489 #ifndef SK_IGNORE_TO_STRING | 1494 #ifndef SK_IGNORE_TO_STRING |
| 1490 void SkSpecularLightingImageFilter::toString(SkString* str) const { | 1495 void SkSpecularLightingImageFilter::toString(SkString* str) const { |
| 1491 str->appendf("SkSpecularLightingImageFilter: ("); | 1496 str->appendf("SkSpecularLightingImageFilter: ("); |
| 1492 str->appendf("kS: %f shininess: %f", fKS, fShininess); | 1497 str->appendf("kS: %f shininess: %f", fKS, fShininess); |
| 1493 str->append(")"); | 1498 str->append(")"); |
| 1494 } | 1499 } |
| 1495 #endif | 1500 #endif |
| 1496 | 1501 |
| 1497 #if SK_SUPPORT_GPU | 1502 #if SK_SUPPORT_GPU |
| 1498 GrFragmentProcessor* SkSpecularLightingImageFilter::getFragmentProcessor( | 1503 sk_sp<GrFragmentProcessor> SkSpecularLightingImageFilter::makeFragmentProcessor( |
| 1499 GrTexture* texture, | 1504 GrTexture* texture, |
| 1500 const SkMatrix& matrix, | 1505 const SkMatrix& matrix, |
| 1501 const SkIRect* srcBounds, | 1506 const SkIRect* srcBounds, |
| 1502 BoundaryMode boundaryMode) c
onst { | 1507 BoundaryMode boundaryMode) c
onst { |
| 1503 SkScalar scale = SkScalarMul(this->surfaceScale(), SkIntToScalar(255)); | 1508 SkScalar scale = SkScalarMul(this->surfaceScale(), SkIntToScalar(255)); |
| 1504 return GrSpecularLightingEffect::Create(texture, this->light(), scale, matri
x, this->ks(), | 1509 return GrSpecularLightingEffect::Make(texture, this->light(), scale, matrix,
this->ks(), |
| 1505 this->shininess(), boundaryMode, src
Bounds); | 1510 this->shininess(), boundaryMode, srcBo
unds); |
| 1506 } | 1511 } |
| 1507 #endif | 1512 #endif |
| 1508 | 1513 |
| 1509 /////////////////////////////////////////////////////////////////////////////// | 1514 /////////////////////////////////////////////////////////////////////////////// |
| 1510 | 1515 |
| 1511 #if SK_SUPPORT_GPU | 1516 #if SK_SUPPORT_GPU |
| 1512 | 1517 |
| 1513 namespace { | 1518 namespace { |
| 1514 SkPoint3 random_point3(SkRandom* random) { | 1519 SkPoint3 random_point3(SkRandom* random) { |
| 1515 return SkPoint3::Make(SkScalarToFloat(random->nextSScalar1()), | 1520 return SkPoint3::Make(SkScalarToFloat(random->nextSScalar1()), |
| (...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1739 GrProcessorKeyBuilder* b) co
nst { | 1744 GrProcessorKeyBuilder* b) co
nst { |
| 1740 GrGLDiffuseLightingEffect::GenKey(*this, caps, b); | 1745 GrGLDiffuseLightingEffect::GenKey(*this, caps, b); |
| 1741 } | 1746 } |
| 1742 | 1747 |
| 1743 GrGLSLFragmentProcessor* GrDiffuseLightingEffect::onCreateGLSLInstance() const { | 1748 GrGLSLFragmentProcessor* GrDiffuseLightingEffect::onCreateGLSLInstance() const { |
| 1744 return new GrGLDiffuseLightingEffect; | 1749 return new GrGLDiffuseLightingEffect; |
| 1745 } | 1750 } |
| 1746 | 1751 |
| 1747 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrDiffuseLightingEffect); | 1752 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrDiffuseLightingEffect); |
| 1748 | 1753 |
| 1749 const GrFragmentProcessor* GrDiffuseLightingEffect::TestCreate(GrProcessorTestDa
ta* d) { | 1754 sk_sp<GrFragmentProcessor> GrDiffuseLightingEffect::TestCreate(GrProcessorTestDa
ta* d) { |
| 1750 int texIdx = d->fRandom->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx
: | 1755 int texIdx = d->fRandom->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx
: |
| 1751 GrProcessorUnitTest::kAlphaTextureIdx; | 1756 GrProcessorUnitTest::kAlphaTextureIdx; |
| 1752 GrTexture* tex = d->fTextures[texIdx]; | 1757 GrTexture* tex = d->fTextures[texIdx]; |
| 1753 SkScalar surfaceScale = d->fRandom->nextSScalar1(); | 1758 SkScalar surfaceScale = d->fRandom->nextSScalar1(); |
| 1754 SkScalar kd = d->fRandom->nextUScalar1(); | 1759 SkScalar kd = d->fRandom->nextUScalar1(); |
| 1755 SkAutoTUnref<SkImageFilterLight> light(create_random_light(d->fRandom)); | 1760 SkAutoTUnref<SkImageFilterLight> light(create_random_light(d->fRandom)); |
| 1756 SkMatrix matrix; | 1761 SkMatrix matrix; |
| 1757 for (int i = 0; i < 9; i++) { | 1762 for (int i = 0; i < 9; i++) { |
| 1758 matrix[i] = d->fRandom->nextUScalar1(); | 1763 matrix[i] = d->fRandom->nextUScalar1(); |
| 1759 } | 1764 } |
| 1760 SkIRect srcBounds = SkIRect::MakeXYWH(d->fRandom->nextRangeU(0, tex->width()
), | 1765 SkIRect srcBounds = SkIRect::MakeXYWH(d->fRandom->nextRangeU(0, tex->width()
), |
| 1761 d->fRandom->nextRangeU(0, tex->height(
)), | 1766 d->fRandom->nextRangeU(0, tex->height(
)), |
| 1762 d->fRandom->nextRangeU(0, tex->width()
), | 1767 d->fRandom->nextRangeU(0, tex->width()
), |
| 1763 d->fRandom->nextRangeU(0, tex->height(
))); | 1768 d->fRandom->nextRangeU(0, tex->height(
))); |
| 1764 BoundaryMode mode = static_cast<BoundaryMode>(d->fRandom->nextU() % kBoundar
yModeCount); | 1769 BoundaryMode mode = static_cast<BoundaryMode>(d->fRandom->nextU() % kBoundar
yModeCount); |
| 1765 return GrDiffuseLightingEffect::Create(tex, light, surfaceScale, matrix, kd,
mode, &srcBounds); | 1770 return GrDiffuseLightingEffect::Make(tex, light, surfaceScale, matrix, kd, m
ode, &srcBounds); |
| 1766 } | 1771 } |
| 1767 | 1772 |
| 1768 | 1773 |
| 1769 /////////////////////////////////////////////////////////////////////////////// | 1774 /////////////////////////////////////////////////////////////////////////////// |
| 1770 | 1775 |
| 1771 void GrGLLightingEffect::emitCode(EmitArgs& args) { | 1776 void GrGLLightingEffect::emitCode(EmitArgs& args) { |
| 1772 const GrLightingEffect& le = args.fFp.cast<GrLightingEffect>(); | 1777 const GrLightingEffect& le = args.fFp.cast<GrLightingEffect>(); |
| 1773 if (!fLight) { | 1778 if (!fLight) { |
| 1774 fLight = le.light()->createGLLight(); | 1779 fLight = le.light()->createGLLight(); |
| 1775 } | 1780 } |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1956 GrProcessorKeyBuilder* b) c
onst { | 1961 GrProcessorKeyBuilder* b) c
onst { |
| 1957 GrGLSpecularLightingEffect::GenKey(*this, caps, b); | 1962 GrGLSpecularLightingEffect::GenKey(*this, caps, b); |
| 1958 } | 1963 } |
| 1959 | 1964 |
| 1960 GrGLSLFragmentProcessor* GrSpecularLightingEffect::onCreateGLSLInstance() const
{ | 1965 GrGLSLFragmentProcessor* GrSpecularLightingEffect::onCreateGLSLInstance() const
{ |
| 1961 return new GrGLSpecularLightingEffect; | 1966 return new GrGLSpecularLightingEffect; |
| 1962 } | 1967 } |
| 1963 | 1968 |
| 1964 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrSpecularLightingEffect); | 1969 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrSpecularLightingEffect); |
| 1965 | 1970 |
| 1966 const GrFragmentProcessor* GrSpecularLightingEffect::TestCreate(GrProcessorTestD
ata* d) { | 1971 sk_sp<GrFragmentProcessor> GrSpecularLightingEffect::TestCreate(GrProcessorTestD
ata* d) { |
| 1967 int texIdx = d->fRandom->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx
: | 1972 int texIdx = d->fRandom->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx
: |
| 1968 GrProcessorUnitTest::kAlphaTextureIdx; | 1973 GrProcessorUnitTest::kAlphaTextureIdx; |
| 1969 GrTexture* tex = d->fTextures[texIdx]; | 1974 GrTexture* tex = d->fTextures[texIdx]; |
| 1970 SkScalar surfaceScale = d->fRandom->nextSScalar1(); | 1975 SkScalar surfaceScale = d->fRandom->nextSScalar1(); |
| 1971 SkScalar ks = d->fRandom->nextUScalar1(); | 1976 SkScalar ks = d->fRandom->nextUScalar1(); |
| 1972 SkScalar shininess = d->fRandom->nextUScalar1(); | 1977 SkScalar shininess = d->fRandom->nextUScalar1(); |
| 1973 SkAutoTUnref<SkImageFilterLight> light(create_random_light(d->fRandom)); | 1978 SkAutoTUnref<SkImageFilterLight> light(create_random_light(d->fRandom)); |
| 1974 SkMatrix matrix; | 1979 SkMatrix matrix; |
| 1975 for (int i = 0; i < 9; i++) { | 1980 for (int i = 0; i < 9; i++) { |
| 1976 matrix[i] = d->fRandom->nextUScalar1(); | 1981 matrix[i] = d->fRandom->nextUScalar1(); |
| 1977 } | 1982 } |
| 1978 BoundaryMode mode = static_cast<BoundaryMode>(d->fRandom->nextU() % kBoundar
yModeCount); | 1983 BoundaryMode mode = static_cast<BoundaryMode>(d->fRandom->nextU() % kBoundar
yModeCount); |
| 1979 SkIRect srcBounds = SkIRect::MakeXYWH(d->fRandom->nextRangeU(0, tex->width()
), | 1984 SkIRect srcBounds = SkIRect::MakeXYWH(d->fRandom->nextRangeU(0, tex->width()
), |
| 1980 d->fRandom->nextRangeU(0, tex->height(
)), | 1985 d->fRandom->nextRangeU(0, tex->height(
)), |
| 1981 d->fRandom->nextRangeU(0, tex->width()
), | 1986 d->fRandom->nextRangeU(0, tex->width()
), |
| 1982 d->fRandom->nextRangeU(0, tex->height(
))); | 1987 d->fRandom->nextRangeU(0, tex->height(
))); |
| 1983 return GrSpecularLightingEffect::Create(d->fTextures[GrProcessorUnitTest::kA
lphaTextureIdx], | 1988 return GrSpecularLightingEffect::Make(d->fTextures[GrProcessorUnitTest::kAlp
haTextureIdx], |
| 1984 light, surfaceScale, matrix, ks, shi
niness, mode, | 1989 light, surfaceScale, matrix, ks, shini
ness, mode, |
| 1985 &srcBounds); | 1990 &srcBounds); |
| 1986 } | 1991 } |
| 1987 | 1992 |
| 1988 /////////////////////////////////////////////////////////////////////////////// | 1993 /////////////////////////////////////////////////////////////////////////////// |
| 1989 | 1994 |
| 1990 void GrGLSpecularLightingEffect::emitLightFunc(GrGLSLUniformHandler* uniformHand
ler, | 1995 void GrGLSpecularLightingEffect::emitLightFunc(GrGLSLUniformHandler* uniformHand
ler, |
| 1991 GrGLSLFPFragmentBuilder* fragBuil
der, | 1996 GrGLSLFPFragmentBuilder* fragBuil
der, |
| 1992 SkString* funcName) { | 1997 SkString* funcName) { |
| 1993 const char* ks; | 1998 const char* ks; |
| 1994 const char* shininess; | 1999 const char* shininess; |
| 1995 | 2000 |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2163 | 2168 |
| 2164 fragBuilder->codeAppendf("%s(%s)", fLightColorFunc.c_str(), surfaceToLight); | 2169 fragBuilder->codeAppendf("%s(%s)", fLightColorFunc.c_str(), surfaceToLight); |
| 2165 } | 2170 } |
| 2166 | 2171 |
| 2167 #endif | 2172 #endif |
| 2168 | 2173 |
| 2169 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingImageFilter) | 2174 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingImageFilter) |
| 2170 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDiffuseLightingImageFilter) | 2175 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDiffuseLightingImageFilter) |
| 2171 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSpecularLightingImageFilter) | 2176 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSpecularLightingImageFilter) |
| 2172 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END | 2177 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END |
| OLD | NEW |