Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(266)

Side by Side Diff: src/effects/SkLightingImageFilter.cpp

Issue 1291783003: Update SkLightingShader to support rotation (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix gyp file Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/core/SkPoint3.cpp ('k') | src/effects/SkLightingShader.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 sobel(m[0], m[3], m[1], m[4], m[2], m[5], gOneHalf), 174 sobel(m[0], m[3], m[1], m[4], m[2], m[5], gOneHalf),
175 surfaceScale); 175 surfaceScale);
176 } 176 }
177 177
178 inline SkPoint3 bottomRightNormal(int m[9], SkScalar surfaceScale) { 178 inline SkPoint3 bottomRightNormal(int m[9], SkScalar surfaceScale) {
179 return pointToNormal(sobel(m[0], m[1], m[3], m[4], 0, 0, gTwoThirds), 179 return pointToNormal(sobel(m[0], m[1], m[3], m[4], 0, 0, gTwoThirds),
180 sobel(m[0], m[3], m[1], m[4], 0, 0, gTwoThirds), 180 sobel(m[0], m[3], m[1], m[4], 0, 0, gTwoThirds),
181 surfaceScale); 181 surfaceScale);
182 } 182 }
183 183
184 template <class LightingType, class LightType> void lightBitmap( 184 template <class LightingType, class LightType> void lightBitmap(const LightingTy pe& lightingType,
185 const LightingType& lightingType, const SkLight* light, const SkBitmap& src, SkBitmap* dst, 185 const SkImageFil terLight* light,
186 SkScalar surfaceScale, const SkIRect& bounds) { 186 const SkBitmap& src,
187 SkBitmap* dst,
188 SkScalar surface Scale,
189 const SkIRect& b ounds) {
187 SkASSERT(dst->width() == bounds.width() && dst->height() == bounds.height()) ; 190 SkASSERT(dst->width() == bounds.width() && dst->height() == bounds.height()) ;
188 const LightType* l = static_cast<const LightType*>(light); 191 const LightType* l = static_cast<const LightType*>(light);
189 int left = bounds.left(), right = bounds.right(); 192 int left = bounds.left(), right = bounds.right();
190 int bottom = bounds.bottom(); 193 int bottom = bounds.bottom();
191 int y = bounds.top(); 194 int y = bounds.top();
192 SkPMColor* dptr = dst->getAddr32(0, 0); 195 SkPMColor* dptr = dst->getAddr32(0, 0);
193 { 196 {
194 int x = left; 197 int x = left;
195 const SkPMColor* row1 = src.getAddr32(x, y); 198 const SkPMColor* row1 = src.getAddr32(x, y);
196 const SkPMColor* row2 = src.getAddr32(x, y + 1); 199 const SkPMColor* row2 = src.getAddr32(x, y + 1);
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 kRight_BoundaryMode, 304 kRight_BoundaryMode,
302 kBottomLeft_BoundaryMode, 305 kBottomLeft_BoundaryMode,
303 kBottom_BoundaryMode, 306 kBottom_BoundaryMode,
304 kBottomRight_BoundaryMode, 307 kBottomRight_BoundaryMode,
305 308
306 kBoundaryModeCount, 309 kBoundaryModeCount,
307 }; 310 };
308 311
309 class SkLightingImageFilterInternal : public SkLightingImageFilter { 312 class SkLightingImageFilterInternal : public SkLightingImageFilter {
310 protected: 313 protected:
311 SkLightingImageFilterInternal(SkLight* light, 314 SkLightingImageFilterInternal(SkImageFilterLight* light,
312 SkScalar surfaceScale, 315 SkScalar surfaceScale,
313 SkImageFilter* input, 316 SkImageFilter* input,
314 const CropRect* cropRect) 317 const CropRect* cropRect)
315 : INHERITED(light, surfaceScale, input, cropRect) {} 318 : INHERITED(light, surfaceScale, input, cropRect) {}
316 319
317 #if SK_SUPPORT_GPU 320 #if SK_SUPPORT_GPU
318 bool canFilterImageGPU() const override { return true; } 321 bool canFilterImageGPU() const override { return true; }
319 bool filterImageGPU(Proxy*, const SkBitmap& src, const Context&, 322 bool filterImageGPU(Proxy*, const SkBitmap& src, const Context&,
320 SkBitmap* result, SkIPoint* offset) const override; 323 SkBitmap* result, SkIPoint* offset) const override;
321 virtual GrFragmentProcessor* getFragmentProcessor(GrProcessorDataManager*, 324 virtual GrFragmentProcessor* getFragmentProcessor(GrProcessorDataManager*,
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 this->drawRect(drawContext, srcTexture, dst, matrix, clip, bottom, kBottom_B oundaryMode, bounds); 427 this->drawRect(drawContext, srcTexture, dst, matrix, clip, bottom, kBottom_B oundaryMode, bounds);
425 this->drawRect(drawContext, srcTexture, dst, matrix, clip, bottomRight, 428 this->drawRect(drawContext, srcTexture, dst, matrix, clip, bottomRight,
426 kBottomRight_BoundaryMode, bounds); 429 kBottomRight_BoundaryMode, bounds);
427 WrapTexture(dst, bounds.width(), bounds.height(), result); 430 WrapTexture(dst, bounds.width(), bounds.height(), result);
428 return true; 431 return true;
429 } 432 }
430 #endif 433 #endif
431 434
432 class SkDiffuseLightingImageFilter : public SkLightingImageFilterInternal { 435 class SkDiffuseLightingImageFilter : public SkLightingImageFilterInternal {
433 public: 436 public:
434 static SkImageFilter* Create(SkLight* light, SkScalar surfaceScale, SkScalar kd, SkImageFilter*, 437 static SkImageFilter* Create(SkImageFilterLight* light, SkScalar surfaceScal e,
438 SkScalar kd, SkImageFilter*,
435 const CropRect*); 439 const CropRect*);
436 440
437 SK_TO_STRING_OVERRIDE() 441 SK_TO_STRING_OVERRIDE()
438 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkDiffuseLightingImageFi lter) 442 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkDiffuseLightingImageFi lter)
439 SkScalar kd() const { return fKD; } 443 SkScalar kd() const { return fKD; }
440 444
441 protected: 445 protected:
442 SkDiffuseLightingImageFilter(SkLight* light, SkScalar surfaceScale, 446 SkDiffuseLightingImageFilter(SkImageFilterLight* light, SkScalar surfaceScal e,
443 SkScalar kd, SkImageFilter* input, const CropRe ct* cropRect); 447 SkScalar kd, SkImageFilter* input, const CropRe ct* cropRect);
444 void flatten(SkWriteBuffer& buffer) const override; 448 void flatten(SkWriteBuffer& buffer) const override;
445 bool onFilterImage(Proxy*, const SkBitmap& src, const Context&, 449 bool onFilterImage(Proxy*, const SkBitmap& src, const Context&,
446 SkBitmap* result, SkIPoint* offset) const override; 450 SkBitmap* result, SkIPoint* offset) const override;
447 #if SK_SUPPORT_GPU 451 #if SK_SUPPORT_GPU
448 GrFragmentProcessor* getFragmentProcessor(GrProcessorDataManager*, GrTexture *, const SkMatrix&, 452 GrFragmentProcessor* getFragmentProcessor(GrProcessorDataManager*, GrTexture *, const SkMatrix&,
449 const SkIRect& bounds, BoundaryMod e) const override; 453 const SkIRect& bounds, BoundaryMod e) const override;
450 #endif 454 #endif
451 455
452 private: 456 private:
453 friend class SkLightingImageFilter; 457 friend class SkLightingImageFilter;
454 typedef SkLightingImageFilterInternal INHERITED; 458 typedef SkLightingImageFilterInternal INHERITED;
455 SkScalar fKD; 459 SkScalar fKD;
456 }; 460 };
457 461
458 class SkSpecularLightingImageFilter : public SkLightingImageFilterInternal { 462 class SkSpecularLightingImageFilter : public SkLightingImageFilterInternal {
459 public: 463 public:
460 static SkImageFilter* Create(SkLight* light, SkScalar surfaceScale, 464 static SkImageFilter* Create(SkImageFilterLight* light, SkScalar surfaceScal e,
461 SkScalar ks, SkScalar shininess, SkImageFilter* , const CropRect*); 465 SkScalar ks, SkScalar shininess, SkImageFilter* , const CropRect*);
462 466
463 SK_TO_STRING_OVERRIDE() 467 SK_TO_STRING_OVERRIDE()
464 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkSpecularLightingImageF ilter) 468 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkSpecularLightingImageF ilter)
465 469
466 SkScalar ks() const { return fKS; } 470 SkScalar ks() const { return fKS; }
467 SkScalar shininess() const { return fShininess; } 471 SkScalar shininess() const { return fShininess; }
468 472
469 protected: 473 protected:
470 SkSpecularLightingImageFilter(SkLight* light, SkScalar surfaceScale, SkScala r ks, 474 SkSpecularLightingImageFilter(SkImageFilterLight* light, SkScalar surfaceSca le, SkScalar ks,
471 SkScalar shininess, SkImageFilter* input, cons t CropRect*); 475 SkScalar shininess, SkImageFilter* input, cons t CropRect*);
472 void flatten(SkWriteBuffer& buffer) const override; 476 void flatten(SkWriteBuffer& buffer) const override;
473 bool onFilterImage(Proxy*, const SkBitmap& src, const Context&, 477 bool onFilterImage(Proxy*, const SkBitmap& src, const Context&,
474 SkBitmap* result, SkIPoint* offset) const override; 478 SkBitmap* result, SkIPoint* offset) const override;
475 #if SK_SUPPORT_GPU 479 #if SK_SUPPORT_GPU
476 GrFragmentProcessor* getFragmentProcessor(GrProcessorDataManager*, GrTexture *, const SkMatrix&, 480 GrFragmentProcessor* getFragmentProcessor(GrProcessorDataManager*, GrTexture *, const SkMatrix&,
477 const SkIRect& bounds, BoundaryMod e) const override; 481 const SkIRect& bounds, BoundaryMod e) const override;
478 #endif 482 #endif
479 483
480 private: 484 private:
481 SkScalar fKS; 485 SkScalar fKS;
482 SkScalar fShininess; 486 SkScalar fShininess;
483 friend class SkLightingImageFilter; 487 friend class SkLightingImageFilter;
484 typedef SkLightingImageFilterInternal INHERITED; 488 typedef SkLightingImageFilterInternal INHERITED;
485 }; 489 };
486 490
487 #if SK_SUPPORT_GPU 491 #if SK_SUPPORT_GPU
488 492
489 class GrLightingEffect : public GrSingleTextureEffect { 493 class GrLightingEffect : public GrSingleTextureEffect {
490 public: 494 public:
491 GrLightingEffect(GrProcessorDataManager*, GrTexture* texture, const SkLight* light, 495 GrLightingEffect(GrProcessorDataManager*, GrTexture* texture, const SkImageF ilterLight* light,
492 SkScalar surfaceScale, const SkMatrix& matrix, BoundaryMode boundaryMode); 496 SkScalar surfaceScale, const SkMatrix& matrix, BoundaryMode boundaryMode);
493 virtual ~GrLightingEffect(); 497 virtual ~GrLightingEffect();
494 498
495 const SkLight* light() const { return fLight; } 499 const SkImageFilterLight* light() const { return fLight; }
496 SkScalar surfaceScale() const { return fSurfaceScale; } 500 SkScalar surfaceScale() const { return fSurfaceScale; }
497 const SkMatrix& filterMatrix() const { return fFilterMatrix; } 501 const SkMatrix& filterMatrix() const { return fFilterMatrix; }
498 BoundaryMode boundaryMode() const { return fBoundaryMode; } 502 BoundaryMode boundaryMode() const { return fBoundaryMode; }
499 503
500 protected: 504 protected:
501 bool onIsEqual(const GrFragmentProcessor&) const override; 505 bool onIsEqual(const GrFragmentProcessor&) const override;
502 506
503 void onComputeInvariantOutput(GrInvariantOutput* inout) const override { 507 void onComputeInvariantOutput(GrInvariantOutput* inout) const override {
504 // lighting shaders are complicated. We just throw up our hands. 508 // lighting shaders are complicated. We just throw up our hands.
505 inout->mulByUnknownFourComponents(); 509 inout->mulByUnknownFourComponents();
506 } 510 }
507 511
508 private: 512 private:
509 typedef GrSingleTextureEffect INHERITED; 513 const SkImageFilterLight* fLight;
510 const SkLight* fLight;
511 SkScalar fSurfaceScale; 514 SkScalar fSurfaceScale;
512 SkMatrix fFilterMatrix; 515 SkMatrix fFilterMatrix;
513 BoundaryMode fBoundaryMode; 516 BoundaryMode fBoundaryMode;
517
518 typedef GrSingleTextureEffect INHERITED;
514 }; 519 };
515 520
516 class GrDiffuseLightingEffect : public GrLightingEffect { 521 class GrDiffuseLightingEffect : public GrLightingEffect {
517 public: 522 public:
518 static GrFragmentProcessor* Create(GrProcessorDataManager* procDataManager, 523 static GrFragmentProcessor* Create(GrProcessorDataManager* procDataManager,
519 GrTexture* texture, 524 GrTexture* texture,
520 const SkLight* light, 525 const SkImageFilterLight* light,
521 SkScalar surfaceScale, 526 SkScalar surfaceScale,
522 const SkMatrix& matrix, 527 const SkMatrix& matrix,
523 SkScalar kd, 528 SkScalar kd,
524 BoundaryMode boundaryMode) { 529 BoundaryMode boundaryMode) {
525 return SkNEW_ARGS(GrDiffuseLightingEffect, (procDataManager, 530 return SkNEW_ARGS(GrDiffuseLightingEffect, (procDataManager,
526 texture, 531 texture,
527 light, 532 light,
528 surfaceScale, 533 surfaceScale,
529 matrix, 534 matrix,
530 kd, 535 kd,
531 boundaryMode)); 536 boundaryMode));
532 } 537 }
533 538
534 const char* name() const override { return "DiffuseLighting"; } 539 const char* name() const override { return "DiffuseLighting"; }
535 540
536 SkScalar kd() const { return fKD; } 541 SkScalar kd() const { return fKD; }
537 542
538 private: 543 private:
539 GrGLFragmentProcessor* onCreateGLInstance() const override; 544 GrGLFragmentProcessor* onCreateGLInstance() const override;
540 545
541 void onGetGLProcessorKey(const GrGLSLCaps&, GrProcessorKeyBuilder*) const ov erride; 546 void onGetGLProcessorKey(const GrGLSLCaps&, GrProcessorKeyBuilder*) const ov erride;
542 547
543 bool onIsEqual(const GrFragmentProcessor&) const override; 548 bool onIsEqual(const GrFragmentProcessor&) const override;
544 549
545 GrDiffuseLightingEffect(GrProcessorDataManager*, 550 GrDiffuseLightingEffect(GrProcessorDataManager*,
546 GrTexture* texture, 551 GrTexture* texture,
547 const SkLight* light, 552 const SkImageFilterLight* light,
548 SkScalar surfaceScale, 553 SkScalar surfaceScale,
549 const SkMatrix& matrix, 554 const SkMatrix& matrix,
550 SkScalar kd, 555 SkScalar kd,
551 BoundaryMode boundaryMode); 556 BoundaryMode boundaryMode);
552 557
553 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; 558 GR_DECLARE_FRAGMENT_PROCESSOR_TEST;
554 typedef GrLightingEffect INHERITED; 559 typedef GrLightingEffect INHERITED;
555 SkScalar fKD; 560 SkScalar fKD;
556 }; 561 };
557 562
558 class GrSpecularLightingEffect : public GrLightingEffect { 563 class GrSpecularLightingEffect : public GrLightingEffect {
559 public: 564 public:
560 static GrFragmentProcessor* Create(GrProcessorDataManager* procDataManager, 565 static GrFragmentProcessor* Create(GrProcessorDataManager* procDataManager,
561 GrTexture* texture, 566 GrTexture* texture,
562 const SkLight* light, 567 const SkImageFilterLight* light,
563 SkScalar surfaceScale, 568 SkScalar surfaceScale,
564 const SkMatrix& matrix, 569 const SkMatrix& matrix,
565 SkScalar ks, 570 SkScalar ks,
566 SkScalar shininess, 571 SkScalar shininess,
567 BoundaryMode boundaryMode) { 572 BoundaryMode boundaryMode) {
568 return SkNEW_ARGS(GrSpecularLightingEffect, (procDataManager, 573 return SkNEW_ARGS(GrSpecularLightingEffect, (procDataManager,
569 texture, 574 texture,
570 light, 575 light,
571 surfaceScale, 576 surfaceScale,
572 matrix, 577 matrix,
573 ks, 578 ks,
574 shininess, 579 shininess,
575 boundaryMode)); 580 boundaryMode));
576 } 581 }
577 582
578 const char* name() const override { return "SpecularLighting"; } 583 const char* name() const override { return "SpecularLighting"; }
579 584
580 GrGLFragmentProcessor* onCreateGLInstance() const override; 585 GrGLFragmentProcessor* onCreateGLInstance() const override;
581 586
582 SkScalar ks() const { return fKS; } 587 SkScalar ks() const { return fKS; }
583 SkScalar shininess() const { return fShininess; } 588 SkScalar shininess() const { return fShininess; }
584 589
585 private: 590 private:
586 void onGetGLProcessorKey(const GrGLSLCaps&, GrProcessorKeyBuilder*) const ov erride; 591 void onGetGLProcessorKey(const GrGLSLCaps&, GrProcessorKeyBuilder*) const ov erride;
587 592
588 bool onIsEqual(const GrFragmentProcessor&) const override; 593 bool onIsEqual(const GrFragmentProcessor&) const override;
589 594
590 GrSpecularLightingEffect(GrProcessorDataManager*, 595 GrSpecularLightingEffect(GrProcessorDataManager*,
591 GrTexture* texture, 596 GrTexture* texture,
592 const SkLight* light, 597 const SkImageFilterLight* light,
593 SkScalar surfaceScale, 598 SkScalar surfaceScale,
594 const SkMatrix& matrix, 599 const SkMatrix& matrix,
595 SkScalar ks, 600 SkScalar ks,
596 SkScalar shininess, 601 SkScalar shininess,
597 BoundaryMode boundaryMode); 602 BoundaryMode boundaryMode);
598 603
599 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; 604 GR_DECLARE_FRAGMENT_PROCESSOR_TEST;
600 typedef GrLightingEffect INHERITED; 605 typedef GrLightingEffect INHERITED;
601 SkScalar fKS; 606 SkScalar fKS;
602 SkScalar fShininess; 607 SkScalar fShininess;
(...skipping 17 matching lines...) Expand all
620 * the light. The expression will be used in the FS. emitLightColor writes a n expression into 625 * the light. The expression will be used in the FS. emitLightColor writes a n expression into
621 * the FS that is the color of the light. Either function may add functions and/or uniforms to 626 * the FS that is the color of the light. Either function may add functions and/or uniforms to
622 * the FS. The default of emitLightColor appends the name of the constant li ght color uniform 627 * the FS. The default of emitLightColor appends the name of the constant li ght color uniform
623 * and so this function only needs to be overridden if the light color varie s spatially. 628 * and so this function only needs to be overridden if the light color varie s spatially.
624 */ 629 */
625 virtual void emitSurfaceToLight(GrGLFPBuilder*, const char* z) = 0; 630 virtual void emitSurfaceToLight(GrGLFPBuilder*, const char* z) = 0;
626 virtual void emitLightColor(GrGLFPBuilder*, const char *surfaceToLight); 631 virtual void emitLightColor(GrGLFPBuilder*, const char *surfaceToLight);
627 632
628 // This is called from GrGLLightingEffect's setData(). Subclasses of GrGLLig ht must call 633 // This is called from GrGLLightingEffect's setData(). Subclasses of GrGLLig ht must call
629 // INHERITED::setData(). 634 // INHERITED::setData().
630 virtual void setData(const GrGLProgramDataManager&, 635 virtual void setData(const GrGLProgramDataManager&, const SkImageFilterLight * light) const;
631 const SkLight* light) const;
632 636
633 protected: 637 protected:
634 /** 638 /**
635 * Gets the constant light color uniform. Subclasses can use this in their e mitLightColor 639 * Gets the constant light color uniform. Subclasses can use this in their e mitLightColor
636 * function. 640 * function.
637 */ 641 */
638 UniformHandle lightColorUni() const { return fColorUni; } 642 UniformHandle lightColorUni() const { return fColorUni; }
639 643
640 private: 644 private:
641 UniformHandle fColorUni; 645 UniformHandle fColorUni;
642 646
643 typedef SkRefCnt INHERITED; 647 typedef SkRefCnt INHERITED;
644 }; 648 };
645 649
646 /////////////////////////////////////////////////////////////////////////////// 650 ///////////////////////////////////////////////////////////////////////////////
647 651
648 class GrGLDistantLight : public GrGLLight { 652 class GrGLDistantLight : public GrGLLight {
649 public: 653 public:
650 virtual ~GrGLDistantLight() {} 654 virtual ~GrGLDistantLight() {}
651 void setData(const GrGLProgramDataManager&, const SkLight* light) const over ride; 655 void setData(const GrGLProgramDataManager&, const SkImageFilterLight* light) const override;
652 void emitSurfaceToLight(GrGLFPBuilder*, const char* z) override; 656 void emitSurfaceToLight(GrGLFPBuilder*, const char* z) override;
653 657
654 private: 658 private:
655 typedef GrGLLight INHERITED; 659 typedef GrGLLight INHERITED;
656 UniformHandle fDirectionUni; 660 UniformHandle fDirectionUni;
657 }; 661 };
658 662
659 /////////////////////////////////////////////////////////////////////////////// 663 ///////////////////////////////////////////////////////////////////////////////
660 664
661 class GrGLPointLight : public GrGLLight { 665 class GrGLPointLight : public GrGLLight {
662 public: 666 public:
663 virtual ~GrGLPointLight() {} 667 virtual ~GrGLPointLight() {}
664 void setData(const GrGLProgramDataManager&, const SkLight* light) const over ride; 668 void setData(const GrGLProgramDataManager&, const SkImageFilterLight* light) const override;
665 void emitSurfaceToLight(GrGLFPBuilder*, const char* z) override; 669 void emitSurfaceToLight(GrGLFPBuilder*, const char* z) override;
666 670
667 private: 671 private:
668 typedef GrGLLight INHERITED; 672 typedef GrGLLight INHERITED;
669 UniformHandle fLocationUni; 673 UniformHandle fLocationUni;
670 }; 674 };
671 675
672 /////////////////////////////////////////////////////////////////////////////// 676 ///////////////////////////////////////////////////////////////////////////////
673 677
674 class GrGLSpotLight : public GrGLLight { 678 class GrGLSpotLight : public GrGLLight {
675 public: 679 public:
676 virtual ~GrGLSpotLight() {} 680 virtual ~GrGLSpotLight() {}
677 void setData(const GrGLProgramDataManager&, const SkLight* light) const over ride; 681 void setData(const GrGLProgramDataManager&, const SkImageFilterLight* light) const override;
678 void emitSurfaceToLight(GrGLFPBuilder*, const char* z) override; 682 void emitSurfaceToLight(GrGLFPBuilder*, const char* z) override;
679 void emitLightColor(GrGLFPBuilder*, const char *surfaceToLight) override; 683 void emitLightColor(GrGLFPBuilder*, const char *surfaceToLight) override;
680 684
681 private: 685 private:
682 typedef GrGLLight INHERITED; 686 typedef GrGLLight INHERITED;
683 687
684 SkString fLightColorFunc; 688 SkString fLightColorFunc;
685 UniformHandle fLocationUni; 689 UniformHandle fLocationUni;
686 UniformHandle fExponentUni; 690 UniformHandle fExponentUni;
687 UniformHandle fCosOuterConeAngleUni; 691 UniformHandle fCosOuterConeAngleUni;
688 UniformHandle fCosInnerConeAngleUni; 692 UniformHandle fCosInnerConeAngleUni;
689 UniformHandle fConeScaleUni; 693 UniformHandle fConeScaleUni;
690 UniformHandle fSUni; 694 UniformHandle fSUni;
691 }; 695 };
692 #else 696 #else
693 697
694 class GrGLLight; 698 class GrGLLight;
695 699
696 #endif 700 #endif
697 701
698 }; 702 };
699 703
700 /////////////////////////////////////////////////////////////////////////////// 704 ///////////////////////////////////////////////////////////////////////////////
701 705
702 class SkLight : public SkRefCnt { 706 class SkImageFilterLight : public SkRefCnt {
703 public: 707 public:
704 708
705 709
706 enum LightType { 710 enum LightType {
707 kDistant_LightType, 711 kDistant_LightType,
708 kPoint_LightType, 712 kPoint_LightType,
709 kSpot_LightType, 713 kSpot_LightType,
710 }; 714 };
711 virtual LightType type() const = 0; 715 virtual LightType type() const = 0;
712 const SkPoint3& color() const { return fColor; } 716 const SkPoint3& color() const { return fColor; }
713 virtual GrGLLight* createGLLight() const = 0; 717 virtual GrGLLight* createGLLight() const = 0;
714 virtual bool isEqual(const SkLight& other) const { 718 virtual bool isEqual(const SkImageFilterLight& other) const {
715 return fColor == other.fColor; 719 return fColor == other.fColor;
716 } 720 }
717 // Called to know whether the generated GrGLLight will require access to the fragment position. 721 // Called to know whether the generated GrGLLight will require access to the fragment position.
718 virtual bool requiresFragmentPosition() const = 0; 722 virtual bool requiresFragmentPosition() const = 0;
719 virtual SkLight* transform(const SkMatrix& matrix) const = 0; 723 virtual SkImageFilterLight* transform(const SkMatrix& matrix) const = 0;
720 724
721 // Defined below SkLight's subclasses. 725 // Defined below SkLight's subclasses.
722 void flattenLight(SkWriteBuffer& buffer) const; 726 void flattenLight(SkWriteBuffer& buffer) const;
723 static SkLight* UnflattenLight(SkReadBuffer& buffer); 727 static SkImageFilterLight* UnflattenLight(SkReadBuffer& buffer);
724 728
725 protected: 729 protected:
726 SkLight(SkColor color) { 730 SkImageFilterLight(SkColor color) {
727 fColor = SkPoint3::Make(SkIntToScalar(SkColorGetR(color)), 731 fColor = SkPoint3::Make(SkIntToScalar(SkColorGetR(color)),
728 SkIntToScalar(SkColorGetG(color)), 732 SkIntToScalar(SkColorGetG(color)),
729 SkIntToScalar(SkColorGetB(color))); 733 SkIntToScalar(SkColorGetB(color)));
730 } 734 }
731 SkLight(const SkPoint3& color) 735 SkImageFilterLight(const SkPoint3& color)
732 : fColor(color) {} 736 : fColor(color) {}
733 SkLight(SkReadBuffer& buffer) { 737 SkImageFilterLight(SkReadBuffer& buffer) {
734 fColor = readPoint3(buffer); 738 fColor = readPoint3(buffer);
735 } 739 }
736 740
737 virtual void onFlattenLight(SkWriteBuffer& buffer) const = 0; 741 virtual void onFlattenLight(SkWriteBuffer& buffer) const = 0;
738 742
739 743
740 private: 744 private:
741 typedef SkRefCnt INHERITED; 745 typedef SkRefCnt INHERITED;
742 SkPoint3 fColor; 746 SkPoint3 fColor;
743 }; 747 };
744 748
745 /////////////////////////////////////////////////////////////////////////////// 749 ///////////////////////////////////////////////////////////////////////////////
746 750
747 class SkDistantLight : public SkLight { 751 class SkDistantLight : public SkImageFilterLight {
748 public: 752 public:
749 SkDistantLight(const SkPoint3& direction, SkColor color) 753 SkDistantLight(const SkPoint3& direction, SkColor color)
750 : INHERITED(color), fDirection(direction) { 754 : INHERITED(color), fDirection(direction) {
751 } 755 }
752 756
753 SkPoint3 surfaceToLight(int x, int y, int z, SkScalar surfaceScale) const { 757 SkPoint3 surfaceToLight(int x, int y, int z, SkScalar surfaceScale) const {
754 return fDirection; 758 return fDirection;
755 }; 759 };
756 const SkPoint3& lightColor(const SkPoint3&) const { return this->color(); } 760 const SkPoint3& lightColor(const SkPoint3&) const { return this->color(); }
757 LightType type() const override { return kDistant_LightType; } 761 LightType type() const override { return kDistant_LightType; }
758 const SkPoint3& direction() const { return fDirection; } 762 const SkPoint3& direction() const { return fDirection; }
759 GrGLLight* createGLLight() const override { 763 GrGLLight* createGLLight() const override {
760 #if SK_SUPPORT_GPU 764 #if SK_SUPPORT_GPU
761 return SkNEW(GrGLDistantLight); 765 return SkNEW(GrGLDistantLight);
762 #else 766 #else
763 SkDEBUGFAIL("Should not call in GPU-less build"); 767 SkDEBUGFAIL("Should not call in GPU-less build");
764 return NULL; 768 return NULL;
765 #endif 769 #endif
766 } 770 }
767 bool requiresFragmentPosition() const override { return false; } 771 bool requiresFragmentPosition() const override { return false; }
768 772
769 bool isEqual(const SkLight& other) const override { 773 bool isEqual(const SkImageFilterLight& other) const override {
770 if (other.type() != kDistant_LightType) { 774 if (other.type() != kDistant_LightType) {
771 return false; 775 return false;
772 } 776 }
773 777
774 const SkDistantLight& o = static_cast<const SkDistantLight&>(other); 778 const SkDistantLight& o = static_cast<const SkDistantLight&>(other);
775 return INHERITED::isEqual(other) && 779 return INHERITED::isEqual(other) &&
776 fDirection == o.fDirection; 780 fDirection == o.fDirection;
777 } 781 }
778 782
779 SkDistantLight(SkReadBuffer& buffer) : INHERITED(buffer) { 783 SkDistantLight(SkReadBuffer& buffer) : INHERITED(buffer) {
780 fDirection = readPoint3(buffer); 784 fDirection = readPoint3(buffer);
781 } 785 }
782 786
783 protected: 787 protected:
784 SkDistantLight(const SkPoint3& direction, const SkPoint3& color) 788 SkDistantLight(const SkPoint3& direction, const SkPoint3& color)
785 : INHERITED(color), fDirection(direction) { 789 : INHERITED(color), fDirection(direction) {
786 } 790 }
787 SkLight* transform(const SkMatrix& matrix) const override { 791 SkImageFilterLight* transform(const SkMatrix& matrix) const override {
788 return new SkDistantLight(direction(), color()); 792 return new SkDistantLight(direction(), color());
789 } 793 }
790 void onFlattenLight(SkWriteBuffer& buffer) const override { 794 void onFlattenLight(SkWriteBuffer& buffer) const override {
791 writePoint3(fDirection, buffer); 795 writePoint3(fDirection, buffer);
792 } 796 }
793 797
794 private: 798 private:
795 typedef SkLight INHERITED;
796 SkPoint3 fDirection; 799 SkPoint3 fDirection;
800
801 typedef SkImageFilterLight INHERITED;
797 }; 802 };
798 803
799 /////////////////////////////////////////////////////////////////////////////// 804 ///////////////////////////////////////////////////////////////////////////////
800 805
801 class SkPointLight : public SkLight { 806 class SkPointLight : public SkImageFilterLight {
802 public: 807 public:
803 SkPointLight(const SkPoint3& location, SkColor color) 808 SkPointLight(const SkPoint3& location, SkColor color)
804 : INHERITED(color), fLocation(location) {} 809 : INHERITED(color), fLocation(location) {}
805 810
806 SkPoint3 surfaceToLight(int x, int y, int z, SkScalar surfaceScale) const { 811 SkPoint3 surfaceToLight(int x, int y, int z, SkScalar surfaceScale) const {
807 SkPoint3 direction = SkPoint3::Make(fLocation.fX - SkIntToScalar(x), 812 SkPoint3 direction = SkPoint3::Make(fLocation.fX - SkIntToScalar(x),
808 fLocation.fY - SkIntToScalar(y), 813 fLocation.fY - SkIntToScalar(y),
809 fLocation.fZ - SkScalarMul(SkIntToSc alar(z), 814 fLocation.fZ - SkScalarMul(SkIntToSc alar(z),
810 surfaceSc ale)); 815 surfaceSc ale));
811 fast_normalize(&direction); 816 fast_normalize(&direction);
812 return direction; 817 return direction;
813 }; 818 };
814 const SkPoint3& lightColor(const SkPoint3&) const { return this->color(); } 819 const SkPoint3& lightColor(const SkPoint3&) const { return this->color(); }
815 LightType type() const override { return kPoint_LightType; } 820 LightType type() const override { return kPoint_LightType; }
816 const SkPoint3& location() const { return fLocation; } 821 const SkPoint3& location() const { return fLocation; }
817 GrGLLight* createGLLight() const override { 822 GrGLLight* createGLLight() const override {
818 #if SK_SUPPORT_GPU 823 #if SK_SUPPORT_GPU
819 return SkNEW(GrGLPointLight); 824 return SkNEW(GrGLPointLight);
820 #else 825 #else
821 SkDEBUGFAIL("Should not call in GPU-less build"); 826 SkDEBUGFAIL("Should not call in GPU-less build");
822 return NULL; 827 return NULL;
823 #endif 828 #endif
824 } 829 }
825 bool requiresFragmentPosition() const override { return true; } 830 bool requiresFragmentPosition() const override { return true; }
826 bool isEqual(const SkLight& other) const override { 831 bool isEqual(const SkImageFilterLight& other) const override {
827 if (other.type() != kPoint_LightType) { 832 if (other.type() != kPoint_LightType) {
828 return false; 833 return false;
829 } 834 }
830 const SkPointLight& o = static_cast<const SkPointLight&>(other); 835 const SkPointLight& o = static_cast<const SkPointLight&>(other);
831 return INHERITED::isEqual(other) && 836 return INHERITED::isEqual(other) &&
832 fLocation == o.fLocation; 837 fLocation == o.fLocation;
833 } 838 }
834 SkLight* transform(const SkMatrix& matrix) const override { 839 SkImageFilterLight* transform(const SkMatrix& matrix) const override {
835 SkPoint location2 = SkPoint::Make(fLocation.fX, fLocation.fY); 840 SkPoint location2 = SkPoint::Make(fLocation.fX, fLocation.fY);
836 matrix.mapPoints(&location2, 1); 841 matrix.mapPoints(&location2, 1);
837 // Use X scale and Y scale on Z and average the result 842 // Use X scale and Y scale on Z and average the result
838 SkPoint locationZ = SkPoint::Make(fLocation.fZ, fLocation.fZ); 843 SkPoint locationZ = SkPoint::Make(fLocation.fZ, fLocation.fZ);
839 matrix.mapVectors(&locationZ, 1); 844 matrix.mapVectors(&locationZ, 1);
840 SkPoint3 location = SkPoint3::Make(location2.fX, 845 SkPoint3 location = SkPoint3::Make(location2.fX,
841 location2.fY, 846 location2.fY,
842 SkScalarAve(locationZ.fX, locationZ.f Y)); 847 SkScalarAve(locationZ.fX, locationZ.f Y));
843 return new SkPointLight(location, color()); 848 return new SkPointLight(location, color());
844 } 849 }
845 850
846 SkPointLight(SkReadBuffer& buffer) : INHERITED(buffer) { 851 SkPointLight(SkReadBuffer& buffer) : INHERITED(buffer) {
847 fLocation = readPoint3(buffer); 852 fLocation = readPoint3(buffer);
848 } 853 }
849 854
850 protected: 855 protected:
851 SkPointLight(const SkPoint3& location, const SkPoint3& color) 856 SkPointLight(const SkPoint3& location, const SkPoint3& color)
852 : INHERITED(color), fLocation(location) {} 857 : INHERITED(color), fLocation(location) {}
853 void onFlattenLight(SkWriteBuffer& buffer) const override { 858 void onFlattenLight(SkWriteBuffer& buffer) const override {
854 writePoint3(fLocation, buffer); 859 writePoint3(fLocation, buffer);
855 } 860 }
856 861
857 private: 862 private:
858 typedef SkLight INHERITED;
859 SkPoint3 fLocation; 863 SkPoint3 fLocation;
864
865 typedef SkImageFilterLight INHERITED;
860 }; 866 };
861 867
862 /////////////////////////////////////////////////////////////////////////////// 868 ///////////////////////////////////////////////////////////////////////////////
863 869
864 class SkSpotLight : public SkLight { 870 class SkSpotLight : public SkImageFilterLight {
865 public: 871 public:
866 SkSpotLight(const SkPoint3& location, 872 SkSpotLight(const SkPoint3& location,
867 const SkPoint3& target, 873 const SkPoint3& target,
868 SkScalar specularExponent, 874 SkScalar specularExponent,
869 SkScalar cutoffAngle, 875 SkScalar cutoffAngle,
870 SkColor color) 876 SkColor color)
871 : INHERITED(color), 877 : INHERITED(color),
872 fLocation(location), 878 fLocation(location),
873 fTarget(target), 879 fTarget(target),
874 fSpecularExponent(SkScalarPin(specularExponent, kSpecularExponentMin, kSp ecularExponentMax)) 880 fSpecularExponent(SkScalarPin(specularExponent, kSpecularExponentMin, kSp ecularExponentMax))
875 { 881 {
876 fS = target - location; 882 fS = target - location;
877 fast_normalize(&fS); 883 fast_normalize(&fS);
878 fCosOuterConeAngle = SkScalarCos(SkDegreesToRadians(cutoffAngle)); 884 fCosOuterConeAngle = SkScalarCos(SkDegreesToRadians(cutoffAngle));
879 const SkScalar antiAliasThreshold = 0.016f; 885 const SkScalar antiAliasThreshold = 0.016f;
880 fCosInnerConeAngle = fCosOuterConeAngle + antiAliasThreshold; 886 fCosInnerConeAngle = fCosOuterConeAngle + antiAliasThreshold;
881 fConeScale = SkScalarInvert(antiAliasThreshold); 887 fConeScale = SkScalarInvert(antiAliasThreshold);
882 } 888 }
883 889
884 SkLight* transform(const SkMatrix& matrix) const override { 890 SkImageFilterLight* transform(const SkMatrix& matrix) const override {
885 SkPoint location2 = SkPoint::Make(fLocation.fX, fLocation.fY); 891 SkPoint location2 = SkPoint::Make(fLocation.fX, fLocation.fY);
886 matrix.mapPoints(&location2, 1); 892 matrix.mapPoints(&location2, 1);
887 // Use X scale and Y scale on Z and average the result 893 // Use X scale and Y scale on Z and average the result
888 SkPoint locationZ = SkPoint::Make(fLocation.fZ, fLocation.fZ); 894 SkPoint locationZ = SkPoint::Make(fLocation.fZ, fLocation.fZ);
889 matrix.mapVectors(&locationZ, 1); 895 matrix.mapVectors(&locationZ, 1);
890 SkPoint3 location = SkPoint3::Make(location2.fX, location2.fY, 896 SkPoint3 location = SkPoint3::Make(location2.fX, location2.fY,
891 SkScalarAve(locationZ.fX, locationZ.f Y)); 897 SkScalarAve(locationZ.fX, locationZ.f Y));
892 SkPoint target2 = SkPoint::Make(fTarget.fX, fTarget.fY); 898 SkPoint target2 = SkPoint::Make(fTarget.fX, fTarget.fY);
893 matrix.mapPoints(&target2, 1); 899 matrix.mapPoints(&target2, 1);
894 SkPoint targetZ = SkPoint::Make(fTarget.fZ, fTarget.fZ); 900 SkPoint targetZ = SkPoint::Make(fTarget.fZ, fTarget.fZ);
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
980 void onFlattenLight(SkWriteBuffer& buffer) const override { 986 void onFlattenLight(SkWriteBuffer& buffer) const override {
981 writePoint3(fLocation, buffer); 987 writePoint3(fLocation, buffer);
982 writePoint3(fTarget, buffer); 988 writePoint3(fTarget, buffer);
983 buffer.writeScalar(fSpecularExponent); 989 buffer.writeScalar(fSpecularExponent);
984 buffer.writeScalar(fCosOuterConeAngle); 990 buffer.writeScalar(fCosOuterConeAngle);
985 buffer.writeScalar(fCosInnerConeAngle); 991 buffer.writeScalar(fCosInnerConeAngle);
986 buffer.writeScalar(fConeScale); 992 buffer.writeScalar(fConeScale);
987 writePoint3(fS, buffer); 993 writePoint3(fS, buffer);
988 } 994 }
989 995
990 bool isEqual(const SkLight& other) const override { 996 bool isEqual(const SkImageFilterLight& other) const override {
991 if (other.type() != kSpot_LightType) { 997 if (other.type() != kSpot_LightType) {
992 return false; 998 return false;
993 } 999 }
994 1000
995 const SkSpotLight& o = static_cast<const SkSpotLight&>(other); 1001 const SkSpotLight& o = static_cast<const SkSpotLight&>(other);
996 return INHERITED::isEqual(other) && 1002 return INHERITED::isEqual(other) &&
997 fLocation == o.fLocation && 1003 fLocation == o.fLocation &&
998 fTarget == o.fTarget && 1004 fTarget == o.fTarget &&
999 fSpecularExponent == o.fSpecularExponent && 1005 fSpecularExponent == o.fSpecularExponent &&
1000 fCosOuterConeAngle == o.fCosOuterConeAngle; 1006 fCosOuterConeAngle == o.fCosOuterConeAngle;
1001 } 1007 }
1002 1008
1003 private: 1009 private:
1004 static const SkScalar kSpecularExponentMin; 1010 static const SkScalar kSpecularExponentMin;
1005 static const SkScalar kSpecularExponentMax; 1011 static const SkScalar kSpecularExponentMax;
1006 1012
1007 typedef SkLight INHERITED;
1008 SkPoint3 fLocation; 1013 SkPoint3 fLocation;
1009 SkPoint3 fTarget; 1014 SkPoint3 fTarget;
1010 SkScalar fSpecularExponent; 1015 SkScalar fSpecularExponent;
1011 SkScalar fCosOuterConeAngle; 1016 SkScalar fCosOuterConeAngle;
1012 SkScalar fCosInnerConeAngle; 1017 SkScalar fCosInnerConeAngle;
1013 SkScalar fConeScale; 1018 SkScalar fConeScale;
1014 SkPoint3 fS; 1019 SkPoint3 fS;
1020
1021 typedef SkImageFilterLight INHERITED;
1015 }; 1022 };
1016 1023
1017 // According to the spec, the specular term should be in the range [1, 128] : 1024 // According to the spec, the specular term should be in the range [1, 128] :
1018 // http://www.w3.org/TR/SVG/filters.html#feSpecularLightingSpecularExponentAttri bute 1025 // http://www.w3.org/TR/SVG/filters.html#feSpecularLightingSpecularExponentAttri bute
1019 const SkScalar SkSpotLight::kSpecularExponentMin = 1.0f; 1026 const SkScalar SkSpotLight::kSpecularExponentMin = 1.0f;
1020 const SkScalar SkSpotLight::kSpecularExponentMax = 128.0f; 1027 const SkScalar SkSpotLight::kSpecularExponentMax = 128.0f;
1021 1028
1022 /////////////////////////////////////////////////////////////////////////////// 1029 ///////////////////////////////////////////////////////////////////////////////
1023 1030
1024 void SkLight::flattenLight(SkWriteBuffer& buffer) const { 1031 void SkImageFilterLight::flattenLight(SkWriteBuffer& buffer) const {
1025 // Write type first, then baseclass, then subclass. 1032 // Write type first, then baseclass, then subclass.
1026 buffer.writeInt(this->type()); 1033 buffer.writeInt(this->type());
1027 writePoint3(fColor, buffer); 1034 writePoint3(fColor, buffer);
1028 this->onFlattenLight(buffer); 1035 this->onFlattenLight(buffer);
1029 } 1036 }
1030 1037
1031 /*static*/ SkLight* SkLight::UnflattenLight(SkReadBuffer& buffer) { 1038 /*static*/ SkImageFilterLight* SkImageFilterLight::UnflattenLight(SkReadBuffer& buffer) {
1032 // Read type first. 1039 // Read type first.
1033 const SkLight::LightType type = (SkLight::LightType)buffer.readInt(); 1040 const SkImageFilterLight::LightType type = (SkImageFilterLight::LightType)bu ffer.readInt();
1034 switch (type) { 1041 switch (type) {
1035 // Each of these constructors must first call SkLight's, so we'll read t he baseclass 1042 // Each of these constructors must first call SkLight's, so we'll read t he baseclass
1036 // then subclass, same order as flattenLight. 1043 // then subclass, same order as flattenLight.
1037 case SkLight::kDistant_LightType: return SkNEW_ARGS(SkDistantLight, (buf fer)); 1044 case SkImageFilterLight::kDistant_LightType: return SkNEW_ARGS(SkDistant Light, (buffer));
1038 case SkLight::kPoint_LightType: return SkNEW_ARGS(SkPointLight, (buffe r)); 1045 case SkImageFilterLight::kPoint_LightType: return SkNEW_ARGS(SkPointLi ght, (buffer));
1039 case SkLight::kSpot_LightType: return SkNEW_ARGS(SkSpotLight, (buffer )); 1046 case SkImageFilterLight::kSpot_LightType: return SkNEW_ARGS(SkSpotLig ht, (buffer));
1040 default: 1047 default:
1041 SkDEBUGFAIL("Unknown LightType."); 1048 SkDEBUGFAIL("Unknown LightType.");
1042 buffer.validate(false); 1049 buffer.validate(false);
1043 return NULL; 1050 return NULL;
1044 } 1051 }
1045 } 1052 }
1046 /////////////////////////////////////////////////////////////////////////////// 1053 ///////////////////////////////////////////////////////////////////////////////
1047 1054
1048 SkLightingImageFilter::SkLightingImageFilter(SkLight* light, SkScalar surfaceSca le, 1055 SkLightingImageFilter::SkLightingImageFilter(SkImageFilterLight* light, SkScalar surfaceScale,
1049 SkImageFilter* input, const CropRec t* cropRect) 1056 SkImageFilter* input, const CropRec t* cropRect)
1050 : INHERITED(1, &input, cropRect) 1057 : INHERITED(1, &input, cropRect)
1051 , fLight(SkRef(light)) 1058 , fLight(SkRef(light))
1052 , fSurfaceScale(surfaceScale / 255) 1059 , fSurfaceScale(surfaceScale / 255)
1053 {} 1060 {}
1054 1061
1055 SkImageFilter* SkLightingImageFilter::CreateDistantLitDiffuse(const SkPoint3& di rection, 1062 SkImageFilter* SkLightingImageFilter::CreateDistantLitDiffuse(const SkPoint3& di rection,
1056 SkColor lightColor , 1063 SkColor lightColor ,
1057 SkScalar surfaceSc ale, 1064 SkScalar surfaceSc ale,
1058 SkScalar kd, 1065 SkScalar kd,
1059 SkImageFilter* inp ut, 1066 SkImageFilter* inp ut,
1060 const CropRect* cr opRect) { 1067 const CropRect* cr opRect) {
1061 SkAutoTUnref<SkLight> light(SkNEW_ARGS(SkDistantLight, (direction, lightColo r))); 1068 SkAutoTUnref<SkImageFilterLight> light(SkNEW_ARGS(SkDistantLight, (direction , lightColor)));
1062 return SkDiffuseLightingImageFilter::Create(light, surfaceScale, kd, input, cropRect); 1069 return SkDiffuseLightingImageFilter::Create(light, surfaceScale, kd, input, cropRect);
1063 } 1070 }
1064 1071
1065 SkImageFilter* SkLightingImageFilter::CreatePointLitDiffuse(const SkPoint3& loca tion, 1072 SkImageFilter* SkLightingImageFilter::CreatePointLitDiffuse(const SkPoint3& loca tion,
1066 SkColor lightColor, 1073 SkColor lightColor,
1067 SkScalar surfaceScal e, 1074 SkScalar surfaceScal e,
1068 SkScalar kd, 1075 SkScalar kd,
1069 SkImageFilter* input , 1076 SkImageFilter* input ,
1070 const CropRect* crop Rect) { 1077 const CropRect* crop Rect) {
1071 SkAutoTUnref<SkLight> light(SkNEW_ARGS(SkPointLight, (location, lightColor)) ); 1078 SkAutoTUnref<SkImageFilterLight> light(SkNEW_ARGS(SkPointLight, (location, l ightColor)));
1072 return SkDiffuseLightingImageFilter::Create(light, surfaceScale, kd, input, cropRect); 1079 return SkDiffuseLightingImageFilter::Create(light, surfaceScale, kd, input, cropRect);
1073 } 1080 }
1074 1081
1075 SkImageFilter* SkLightingImageFilter::CreateSpotLitDiffuse(const SkPoint3& locat ion, 1082 SkImageFilter* SkLightingImageFilter::CreateSpotLitDiffuse(const SkPoint3& locat ion,
1076 const SkPoint3& targe t, 1083 const SkPoint3& targe t,
1077 SkScalar specularExpo nent, 1084 SkScalar specularExpo nent,
1078 SkScalar cutoffAngle, 1085 SkScalar cutoffAngle,
1079 SkColor lightColor, 1086 SkColor lightColor,
1080 SkScalar surfaceScale , 1087 SkScalar surfaceScale ,
1081 SkScalar kd, 1088 SkScalar kd,
1082 SkImageFilter* input, 1089 SkImageFilter* input,
1083 const CropRect* cropR ect) { 1090 const CropRect* cropR ect) {
1084 SkAutoTUnref<SkLight> light(SkNEW_ARGS(SkSpotLight, (location, target, specu larExponent, 1091 SkAutoTUnref<SkImageFilterLight> light(SkNEW_ARGS(SkSpotLight, (location, ta rget,
1085 cutoffAngle, lightColor ))); 1092 specularExpo nent,
1093 cutoffAngle, lightColor)));
1086 return SkDiffuseLightingImageFilter::Create(light, surfaceScale, kd, input, cropRect); 1094 return SkDiffuseLightingImageFilter::Create(light, surfaceScale, kd, input, cropRect);
1087 } 1095 }
1088 1096
1089 SkImageFilter* SkLightingImageFilter::CreateDistantLitSpecular(const SkPoint3& d irection, 1097 SkImageFilter* SkLightingImageFilter::CreateDistantLitSpecular(const SkPoint3& d irection,
1090 SkColor lightColo r, 1098 SkColor lightColo r,
1091 SkScalar surfaceS cale, 1099 SkScalar surfaceS cale,
1092 SkScalar ks, 1100 SkScalar ks,
1093 SkScalar shine, 1101 SkScalar shine,
1094 SkImageFilter* in put, 1102 SkImageFilter* in put,
1095 const CropRect* c ropRect) { 1103 const CropRect* c ropRect) {
1096 SkAutoTUnref<SkLight> light(SkNEW_ARGS(SkDistantLight, (direction, lightColo r))); 1104 SkAutoTUnref<SkImageFilterLight> light(SkNEW_ARGS(SkDistantLight, (direction , lightColor)));
1097 return SkSpecularLightingImageFilter::Create(light, surfaceScale, ks, shine, input, cropRect); 1105 return SkSpecularLightingImageFilter::Create(light, surfaceScale, ks, shine, input, cropRect);
1098 } 1106 }
1099 1107
1100 SkImageFilter* SkLightingImageFilter::CreatePointLitSpecular(const SkPoint3& loc ation, 1108 SkImageFilter* SkLightingImageFilter::CreatePointLitSpecular(const SkPoint3& loc ation,
1101 SkColor lightColor, 1109 SkColor lightColor,
1102 SkScalar surfaceSca le, 1110 SkScalar surfaceSca le,
1103 SkScalar ks, 1111 SkScalar ks,
1104 SkScalar shine, 1112 SkScalar shine,
1105 SkImageFilter* inpu t, 1113 SkImageFilter* inpu t,
1106 const CropRect* cro pRect) { 1114 const CropRect* cro pRect) {
1107 SkAutoTUnref<SkLight> light(SkNEW_ARGS(SkPointLight, (location, lightColor)) ); 1115 SkAutoTUnref<SkImageFilterLight> light(SkNEW_ARGS(SkPointLight, (location, l ightColor)));
1108 return SkSpecularLightingImageFilter::Create(light, surfaceScale, ks, shine, input, cropRect); 1116 return SkSpecularLightingImageFilter::Create(light, surfaceScale, ks, shine, input, cropRect);
1109 } 1117 }
1110 1118
1111 SkImageFilter* SkLightingImageFilter::CreateSpotLitSpecular(const SkPoint3& loca tion, 1119 SkImageFilter* SkLightingImageFilter::CreateSpotLitSpecular(const SkPoint3& loca tion,
1112 const SkPoint3& targ et, 1120 const SkPoint3& targ et,
1113 SkScalar specularExp onent, 1121 SkScalar specularExp onent,
1114 SkScalar cutoffAngle , 1122 SkScalar cutoffAngle ,
1115 SkColor lightColor, 1123 SkColor lightColor,
1116 SkScalar surfaceScal e, 1124 SkScalar surfaceScal e,
1117 SkScalar ks, 1125 SkScalar ks,
1118 SkScalar shine, 1126 SkScalar shine,
1119 SkImageFilter* input , 1127 SkImageFilter* input ,
1120 const CropRect* crop Rect) { 1128 const CropRect* crop Rect) {
1121 SkAutoTUnref<SkLight> light(SkNEW_ARGS(SkSpotLight, (location, target, specu larExponent, 1129 SkAutoTUnref<SkImageFilterLight> light(SkNEW_ARGS(SkSpotLight, (location, ta rget,
1122 cutoffAngle, lightColor ))); 1130 specularExpo nent,
1131 cutoffAngle, lightColor)));
1123 return SkSpecularLightingImageFilter::Create(light, surfaceScale, ks, shine, input, cropRect); 1132 return SkSpecularLightingImageFilter::Create(light, surfaceScale, ks, shine, input, cropRect);
1124 } 1133 }
1125 1134
1126 SkLightingImageFilter::~SkLightingImageFilter() {} 1135 SkLightingImageFilter::~SkLightingImageFilter() {}
1127 1136
1128 void SkLightingImageFilter::flatten(SkWriteBuffer& buffer) const { 1137 void SkLightingImageFilter::flatten(SkWriteBuffer& buffer) const {
1129 this->INHERITED::flatten(buffer); 1138 this->INHERITED::flatten(buffer);
1130 fLight->flattenLight(buffer); 1139 fLight->flattenLight(buffer);
1131 buffer.writeScalar(fSurfaceScale * 255); 1140 buffer.writeScalar(fSurfaceScale * 255);
1132 } 1141 }
1133 1142
1134 /////////////////////////////////////////////////////////////////////////////// 1143 ///////////////////////////////////////////////////////////////////////////////
1135 1144
1136 SkImageFilter* SkDiffuseLightingImageFilter::Create(SkLight* light, SkScalar sur faceScale, 1145 SkImageFilter* SkDiffuseLightingImageFilter::Create(SkImageFilterLight* light,
1137 SkScalar kd, SkImageFilter* input, const Cro pRect* cropRect) { 1146 SkScalar surfaceScale,
1147 SkScalar kd,
1148 SkImageFilter* input,
1149 const CropRect* cropRect) {
1138 if (NULL == light) { 1150 if (NULL == light) {
1139 return NULL; 1151 return NULL;
1140 } 1152 }
1141 if (!SkScalarIsFinite(surfaceScale) || !SkScalarIsFinite(kd)) { 1153 if (!SkScalarIsFinite(surfaceScale) || !SkScalarIsFinite(kd)) {
1142 return NULL; 1154 return NULL;
1143 } 1155 }
1144 // According to the spec, kd can be any non-negative number : 1156 // According to the spec, kd can be any non-negative number :
1145 // http://www.w3.org/TR/SVG/filters.html#feDiffuseLightingElement 1157 // http://www.w3.org/TR/SVG/filters.html#feDiffuseLightingElement
1146 if (kd < 0) { 1158 if (kd < 0) {
1147 return NULL; 1159 return NULL;
1148 } 1160 }
1149 return SkNEW_ARGS(SkDiffuseLightingImageFilter, (light, surfaceScale, kd, in put, cropRect)); 1161 return SkNEW_ARGS(SkDiffuseLightingImageFilter, (light, surfaceScale, kd, in put, cropRect));
1150 } 1162 }
1151 1163
1152 SkDiffuseLightingImageFilter::SkDiffuseLightingImageFilter(SkLight* light, 1164 SkDiffuseLightingImageFilter::SkDiffuseLightingImageFilter(SkImageFilterLight* l ight,
1153 SkScalar surfaceScale , 1165 SkScalar surfaceScale ,
1154 SkScalar kd, 1166 SkScalar kd,
1155 SkImageFilter* input, 1167 SkImageFilter* input,
1156 const CropRect* cropR ect) 1168 const CropRect* cropR ect)
1157 : INHERITED(light, surfaceScale, input, cropRect), 1169 : INHERITED(light, surfaceScale, input, cropRect),
1158 fKD(kd) 1170 fKD(kd)
1159 { 1171 {
1160 } 1172 }
1161 1173
1162 SkFlattenable* SkDiffuseLightingImageFilter::CreateProc(SkReadBuffer& buffer) { 1174 SkFlattenable* SkDiffuseLightingImageFilter::CreateProc(SkReadBuffer& buffer) {
1163 SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 1); 1175 SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 1);
1164 SkAutoTUnref<SkLight> light(SkLight::UnflattenLight(buffer)); 1176 SkAutoTUnref<SkImageFilterLight> light(SkImageFilterLight::UnflattenLight(bu ffer));
1165 SkScalar surfaceScale = buffer.readScalar(); 1177 SkScalar surfaceScale = buffer.readScalar();
1166 SkScalar kd = buffer.readScalar(); 1178 SkScalar kd = buffer.readScalar();
1167 return Create(light, surfaceScale, kd, common.getInput(0), &common.cropRect( )); 1179 return Create(light, surfaceScale, kd, common.getInput(0), &common.cropRect( ));
1168 } 1180 }
1169 1181
1170 void SkDiffuseLightingImageFilter::flatten(SkWriteBuffer& buffer) const { 1182 void SkDiffuseLightingImageFilter::flatten(SkWriteBuffer& buffer) const {
1171 this->INHERITED::flatten(buffer); 1183 this->INHERITED::flatten(buffer);
1172 buffer.writeScalar(fKD); 1184 buffer.writeScalar(fKD);
1173 } 1185 }
1174 1186
(...skipping 23 matching lines...) Expand all
1198 1210
1199 SkAutoLockPixels alp(src); 1211 SkAutoLockPixels alp(src);
1200 if (!src.getPixels()) { 1212 if (!src.getPixels()) {
1201 return false; 1213 return false;
1202 } 1214 }
1203 1215
1204 if (!dst->tryAllocPixels(src.info().makeWH(bounds.width(), bounds.height())) ) { 1216 if (!dst->tryAllocPixels(src.info().makeWH(bounds.width(), bounds.height())) ) {
1205 return false; 1217 return false;
1206 } 1218 }
1207 1219
1208 SkAutoTUnref<SkLight> transformedLight(light()->transform(ctx.ctm())); 1220 SkAutoTUnref<SkImageFilterLight> transformedLight(light()->transform(ctx.ctm ()));
1209 1221
1210 DiffuseLightingType lightingType(fKD); 1222 DiffuseLightingType lightingType(fKD);
1211 offset->fX = bounds.left(); 1223 offset->fX = bounds.left();
1212 offset->fY = bounds.top(); 1224 offset->fY = bounds.top();
1213 bounds.offset(-srcOffset); 1225 bounds.offset(-srcOffset);
1214 switch (transformedLight->type()) { 1226 switch (transformedLight->type()) {
1215 case SkLight::kDistant_LightType: 1227 case SkImageFilterLight::kDistant_LightType:
1216 lightBitmap<DiffuseLightingType, SkDistantLight>(lightingType, 1228 lightBitmap<DiffuseLightingType, SkDistantLight>(lightingType,
1217 transformedLight, 1229 transformedLight,
1218 src, 1230 src,
1219 dst, 1231 dst,
1220 surfaceScale(), 1232 surfaceScale(),
1221 bounds); 1233 bounds);
1222 break; 1234 break;
1223 case SkLight::kPoint_LightType: 1235 case SkImageFilterLight::kPoint_LightType:
1224 lightBitmap<DiffuseLightingType, SkPointLight>(lightingType, 1236 lightBitmap<DiffuseLightingType, SkPointLight>(lightingType,
1225 transformedLight, 1237 transformedLight,
1226 src, 1238 src,
1227 dst, 1239 dst,
1228 surfaceScale(), 1240 surfaceScale(),
1229 bounds); 1241 bounds);
1230 break; 1242 break;
1231 case SkLight::kSpot_LightType: 1243 case SkImageFilterLight::kSpot_LightType:
1232 lightBitmap<DiffuseLightingType, SkSpotLight>(lightingType, 1244 lightBitmap<DiffuseLightingType, SkSpotLight>(lightingType,
1233 transformedLight, 1245 transformedLight,
1234 src, 1246 src,
1235 dst, 1247 dst,
1236 surfaceScale(), 1248 surfaceScale(),
1237 bounds); 1249 bounds);
1238 break; 1250 break;
1239 } 1251 }
1240 1252
1241 return true; 1253 return true;
(...skipping 16 matching lines...) Expand all
1258 BoundaryMode boundaryMode 1270 BoundaryMode boundaryMode
1259 ) const { 1271 ) const {
1260 SkScalar scale = SkScalarMul(this->surfaceScale(), SkIntToScalar(255)); 1272 SkScalar scale = SkScalarMul(this->surfaceScale(), SkIntToScalar(255));
1261 return GrDiffuseLightingEffect::Create(procDataManager, texture, this->light (), scale, matrix, 1273 return GrDiffuseLightingEffect::Create(procDataManager, texture, this->light (), scale, matrix,
1262 this->kd(), boundaryMode); 1274 this->kd(), boundaryMode);
1263 } 1275 }
1264 #endif 1276 #endif
1265 1277
1266 /////////////////////////////////////////////////////////////////////////////// 1278 ///////////////////////////////////////////////////////////////////////////////
1267 1279
1268 SkImageFilter* SkSpecularLightingImageFilter::Create(SkLight* light, SkScalar su rfaceScale, 1280 SkImageFilter* SkSpecularLightingImageFilter::Create(SkImageFilterLight* light,
1269 SkScalar ks, SkScalar shininess, SkImageFilter* input, const Cro pRect* cropRect) { 1281 SkScalar surfaceScale,
1282 SkScalar ks,
1283 SkScalar shininess,
1284 SkImageFilter* input,
1285 const CropRect* cropRect) {
1270 if (NULL == light) { 1286 if (NULL == light) {
1271 return NULL; 1287 return NULL;
1272 } 1288 }
1273 if (!SkScalarIsFinite(surfaceScale) || !SkScalarIsFinite(ks) || !SkScalarIsF inite(shininess)) { 1289 if (!SkScalarIsFinite(surfaceScale) || !SkScalarIsFinite(ks) || !SkScalarIsF inite(shininess)) {
1274 return NULL; 1290 return NULL;
1275 } 1291 }
1276 // According to the spec, ks can be any non-negative number : 1292 // According to the spec, ks can be any non-negative number :
1277 // http://www.w3.org/TR/SVG/filters.html#feSpecularLightingElement 1293 // http://www.w3.org/TR/SVG/filters.html#feSpecularLightingElement
1278 if (ks < 0) { 1294 if (ks < 0) {
1279 return NULL; 1295 return NULL;
1280 } 1296 }
1281 return SkNEW_ARGS(SkSpecularLightingImageFilter, 1297 return SkNEW_ARGS(SkSpecularLightingImageFilter,
1282 (light, surfaceScale, ks, shininess, input, cropRect)); 1298 (light, surfaceScale, ks, shininess, input, cropRect));
1283 } 1299 }
1284 1300
1285 SkSpecularLightingImageFilter::SkSpecularLightingImageFilter(SkLight* light, 1301 SkSpecularLightingImageFilter::SkSpecularLightingImageFilter(SkImageFilterLight* light,
1286 SkScalar surfaceSca le, 1302 SkScalar surfaceSca le,
1287 SkScalar ks, 1303 SkScalar ks,
1288 SkScalar shininess, 1304 SkScalar shininess,
1289 SkImageFilter* inpu t, 1305 SkImageFilter* inpu t,
1290 const CropRect* cro pRect) 1306 const CropRect* cro pRect)
1291 : INHERITED(light, surfaceScale, input, cropRect), 1307 : INHERITED(light, surfaceScale, input, cropRect),
1292 fKS(ks), 1308 fKS(ks),
1293 fShininess(shininess) 1309 fShininess(shininess)
1294 { 1310 {
1295 } 1311 }
1296 1312
1297 SkFlattenable* SkSpecularLightingImageFilter::CreateProc(SkReadBuffer& buffer) { 1313 SkFlattenable* SkSpecularLightingImageFilter::CreateProc(SkReadBuffer& buffer) {
1298 SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 1); 1314 SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 1);
1299 SkAutoTUnref<SkLight> light(SkLight::UnflattenLight(buffer)); 1315 SkAutoTUnref<SkImageFilterLight> light(SkImageFilterLight::UnflattenLight(bu ffer));
1300 SkScalar surfaceScale = buffer.readScalar(); 1316 SkScalar surfaceScale = buffer.readScalar();
1301 SkScalar ks = buffer.readScalar(); 1317 SkScalar ks = buffer.readScalar();
1302 SkScalar shine = buffer.readScalar(); 1318 SkScalar shine = buffer.readScalar();
1303 return Create(light, surfaceScale, ks, shine, common.getInput(0), &common.cr opRect()); 1319 return Create(light, surfaceScale, ks, shine, common.getInput(0), &common.cr opRect());
1304 } 1320 }
1305 1321
1306 void SkSpecularLightingImageFilter::flatten(SkWriteBuffer& buffer) const { 1322 void SkSpecularLightingImageFilter::flatten(SkWriteBuffer& buffer) const {
1307 this->INHERITED::flatten(buffer); 1323 this->INHERITED::flatten(buffer);
1308 buffer.writeScalar(fKS); 1324 buffer.writeScalar(fKS);
1309 buffer.writeScalar(fShininess); 1325 buffer.writeScalar(fShininess);
(...skipping 30 matching lines...) Expand all
1340 } 1356 }
1341 1357
1342 if (!dst->tryAllocPixels(src.info().makeWH(bounds.width(), bounds.height())) ) { 1358 if (!dst->tryAllocPixels(src.info().makeWH(bounds.width(), bounds.height())) ) {
1343 return false; 1359 return false;
1344 } 1360 }
1345 1361
1346 SpecularLightingType lightingType(fKS, fShininess); 1362 SpecularLightingType lightingType(fKS, fShininess);
1347 offset->fX = bounds.left(); 1363 offset->fX = bounds.left();
1348 offset->fY = bounds.top(); 1364 offset->fY = bounds.top();
1349 bounds.offset(-srcOffset); 1365 bounds.offset(-srcOffset);
1350 SkAutoTUnref<SkLight> transformedLight(light()->transform(ctx.ctm())); 1366 SkAutoTUnref<SkImageFilterLight> transformedLight(light()->transform(ctx.ctm ()));
1351 switch (transformedLight->type()) { 1367 switch (transformedLight->type()) {
1352 case SkLight::kDistant_LightType: 1368 case SkImageFilterLight::kDistant_LightType:
1353 lightBitmap<SpecularLightingType, SkDistantLight>(lightingType, 1369 lightBitmap<SpecularLightingType, SkDistantLight>(lightingType,
1354 transformedLight, 1370 transformedLight,
1355 src, 1371 src,
1356 dst, 1372 dst,
1357 surfaceScale(), 1373 surfaceScale(),
1358 bounds); 1374 bounds);
1359 break; 1375 break;
1360 case SkLight::kPoint_LightType: 1376 case SkImageFilterLight::kPoint_LightType:
1361 lightBitmap<SpecularLightingType, SkPointLight>(lightingType, 1377 lightBitmap<SpecularLightingType, SkPointLight>(lightingType,
1362 transformedLight, 1378 transformedLight,
1363 src, 1379 src,
1364 dst, 1380 dst,
1365 surfaceScale(), 1381 surfaceScale(),
1366 bounds); 1382 bounds);
1367 break; 1383 break;
1368 case SkLight::kSpot_LightType: 1384 case SkImageFilterLight::kSpot_LightType:
1369 lightBitmap<SpecularLightingType, SkSpotLight>(lightingType, 1385 lightBitmap<SpecularLightingType, SkSpotLight>(lightingType,
1370 transformedLight, 1386 transformedLight,
1371 src, 1387 src,
1372 dst, 1388 dst,
1373 surfaceScale(), 1389 surfaceScale(),
1374 bounds); 1390 bounds);
1375 break; 1391 break;
1376 } 1392 }
1377 return true; 1393 return true;
1378 } 1394 }
(...skipping 23 matching lines...) Expand all
1402 1418
1403 #if SK_SUPPORT_GPU 1419 #if SK_SUPPORT_GPU
1404 1420
1405 namespace { 1421 namespace {
1406 SkPoint3 random_point3(SkRandom* random) { 1422 SkPoint3 random_point3(SkRandom* random) {
1407 return SkPoint3::Make(SkScalarToFloat(random->nextSScalar1()), 1423 return SkPoint3::Make(SkScalarToFloat(random->nextSScalar1()),
1408 SkScalarToFloat(random->nextSScalar1()), 1424 SkScalarToFloat(random->nextSScalar1()),
1409 SkScalarToFloat(random->nextSScalar1())); 1425 SkScalarToFloat(random->nextSScalar1()));
1410 } 1426 }
1411 1427
1412 SkLight* create_random_light(SkRandom* random) { 1428 SkImageFilterLight* create_random_light(SkRandom* random) {
1413 int type = random->nextULessThan(3); 1429 int type = random->nextULessThan(3);
1414 switch (type) { 1430 switch (type) {
1415 case 0: { 1431 case 0: {
1416 return SkNEW_ARGS(SkDistantLight, (random_point3(random), random->ne xtU())); 1432 return SkNEW_ARGS(SkDistantLight, (random_point3(random), random->ne xtU()));
1417 } 1433 }
1418 case 1: { 1434 case 1: {
1419 return SkNEW_ARGS(SkPointLight, (random_point3(random), random->next U())); 1435 return SkNEW_ARGS(SkPointLight, (random_point3(random), random->next U()));
1420 } 1436 }
1421 case 2: { 1437 case 2: {
1422 return SkNEW_ARGS(SkSpotLight, (random_point3(random), 1438 return SkNEW_ARGS(SkSpotLight, (random_point3(random),
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
1564 typedef GrGLLightingEffect INHERITED; 1580 typedef GrGLLightingEffect INHERITED;
1565 1581
1566 UniformHandle fKSUni; 1582 UniformHandle fKSUni;
1567 UniformHandle fShininessUni; 1583 UniformHandle fShininessUni;
1568 }; 1584 };
1569 1585
1570 /////////////////////////////////////////////////////////////////////////////// 1586 ///////////////////////////////////////////////////////////////////////////////
1571 1587
1572 GrLightingEffect::GrLightingEffect(GrProcessorDataManager* procDataManager, 1588 GrLightingEffect::GrLightingEffect(GrProcessorDataManager* procDataManager,
1573 GrTexture* texture, 1589 GrTexture* texture,
1574 const SkLight* light, 1590 const SkImageFilterLight* light,
1575 SkScalar surfaceScale, 1591 SkScalar surfaceScale,
1576 const SkMatrix& matrix, 1592 const SkMatrix& matrix,
1577 BoundaryMode boundaryMode) 1593 BoundaryMode boundaryMode)
1578 : INHERITED(procDataManager, texture, GrCoordTransform::MakeDivByTextureWHMa trix(texture)) 1594 : INHERITED(procDataManager, texture, GrCoordTransform::MakeDivByTextureWHMa trix(texture))
1579 , fLight(light) 1595 , fLight(light)
1580 , fSurfaceScale(surfaceScale) 1596 , fSurfaceScale(surfaceScale)
1581 , fFilterMatrix(matrix) 1597 , fFilterMatrix(matrix)
1582 , fBoundaryMode(boundaryMode) { 1598 , fBoundaryMode(boundaryMode) {
1583 fLight->ref(); 1599 fLight->ref();
1584 if (light->requiresFragmentPosition()) { 1600 if (light->requiresFragmentPosition()) {
1585 this->setWillReadFragmentPosition(); 1601 this->setWillReadFragmentPosition();
1586 } 1602 }
1587 } 1603 }
1588 1604
1589 GrLightingEffect::~GrLightingEffect() { 1605 GrLightingEffect::~GrLightingEffect() {
1590 fLight->unref(); 1606 fLight->unref();
1591 } 1607 }
1592 1608
1593 bool GrLightingEffect::onIsEqual(const GrFragmentProcessor& sBase) const { 1609 bool GrLightingEffect::onIsEqual(const GrFragmentProcessor& sBase) const {
1594 const GrLightingEffect& s = sBase.cast<GrLightingEffect>(); 1610 const GrLightingEffect& s = sBase.cast<GrLightingEffect>();
1595 return fLight->isEqual(*s.fLight) && 1611 return fLight->isEqual(*s.fLight) &&
1596 fSurfaceScale == s.fSurfaceScale && 1612 fSurfaceScale == s.fSurfaceScale &&
1597 fBoundaryMode == s.fBoundaryMode; 1613 fBoundaryMode == s.fBoundaryMode;
1598 } 1614 }
1599 1615
1600 /////////////////////////////////////////////////////////////////////////////// 1616 ///////////////////////////////////////////////////////////////////////////////
1601 1617
1602 GrDiffuseLightingEffect::GrDiffuseLightingEffect(GrProcessorDataManager* procDat aManager, 1618 GrDiffuseLightingEffect::GrDiffuseLightingEffect(GrProcessorDataManager* procDat aManager,
1603 GrTexture* texture, 1619 GrTexture* texture,
1604 const SkLight* light, 1620 const SkImageFilterLight* light ,
1605 SkScalar surfaceScale, 1621 SkScalar surfaceScale,
1606 const SkMatrix& matrix, 1622 const SkMatrix& matrix,
1607 SkScalar kd, 1623 SkScalar kd,
1608 BoundaryMode boundaryMode) 1624 BoundaryMode boundaryMode)
1609 : INHERITED(procDataManager, texture, light, surfaceScale, matrix, boundaryM ode), fKD(kd) { 1625 : INHERITED(procDataManager, texture, light, surfaceScale, matrix, boundaryM ode), fKD(kd) {
1610 this->initClassID<GrDiffuseLightingEffect>(); 1626 this->initClassID<GrDiffuseLightingEffect>();
1611 } 1627 }
1612 1628
1613 bool GrDiffuseLightingEffect::onIsEqual(const GrFragmentProcessor& sBase) const { 1629 bool GrDiffuseLightingEffect::onIsEqual(const GrFragmentProcessor& sBase) const {
1614 const GrDiffuseLightingEffect& s = sBase.cast<GrDiffuseLightingEffect>(); 1630 const GrDiffuseLightingEffect& s = sBase.cast<GrDiffuseLightingEffect>();
1615 return INHERITED::onIsEqual(sBase) && 1631 return INHERITED::onIsEqual(sBase) &&
1616 this->kd() == s.kd(); 1632 this->kd() == s.kd();
1617 } 1633 }
1618 1634
1619 void GrDiffuseLightingEffect::onGetGLProcessorKey(const GrGLSLCaps& caps, 1635 void GrDiffuseLightingEffect::onGetGLProcessorKey(const GrGLSLCaps& caps,
1620 GrProcessorKeyBuilder* b) const { 1636 GrProcessorKeyBuilder* b) const {
1621 GrGLDiffuseLightingEffect::GenKey(*this, caps, b); 1637 GrGLDiffuseLightingEffect::GenKey(*this, caps, b);
1622 } 1638 }
1623 1639
1624 GrGLFragmentProcessor* GrDiffuseLightingEffect::onCreateGLInstance() const { 1640 GrGLFragmentProcessor* GrDiffuseLightingEffect::onCreateGLInstance() const {
1625 return SkNEW_ARGS(GrGLDiffuseLightingEffect, (*this)); 1641 return SkNEW_ARGS(GrGLDiffuseLightingEffect, (*this));
1626 } 1642 }
1627 1643
1628 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrDiffuseLightingEffect); 1644 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrDiffuseLightingEffect);
1629 1645
1630 GrFragmentProcessor* GrDiffuseLightingEffect::TestCreate(GrProcessorTestData* d) { 1646 GrFragmentProcessor* GrDiffuseLightingEffect::TestCreate(GrProcessorTestData* d) {
1631 SkScalar surfaceScale = d->fRandom->nextSScalar1(); 1647 SkScalar surfaceScale = d->fRandom->nextSScalar1();
1632 SkScalar kd = d->fRandom->nextUScalar1(); 1648 SkScalar kd = d->fRandom->nextUScalar1();
1633 SkAutoTUnref<SkLight> light(create_random_light(d->fRandom)); 1649 SkAutoTUnref<SkImageFilterLight> light(create_random_light(d->fRandom));
1634 SkMatrix matrix; 1650 SkMatrix matrix;
1635 for (int i = 0; i < 9; i++) { 1651 for (int i = 0; i < 9; i++) {
1636 matrix[i] = d->fRandom->nextUScalar1(); 1652 matrix[i] = d->fRandom->nextUScalar1();
1637 } 1653 }
1638 BoundaryMode mode = static_cast<BoundaryMode>(d->fRandom->nextU() % kBoundar yModeCount); 1654 BoundaryMode mode = static_cast<BoundaryMode>(d->fRandom->nextU() % kBoundar yModeCount);
1639 return GrDiffuseLightingEffect::Create(d->fProcDataManager, 1655 return GrDiffuseLightingEffect::Create(d->fProcDataManager,
1640 d->fTextures[GrProcessorUnitTest::kAl phaTextureIdx], 1656 d->fTextures[GrProcessorUnitTest::kAl phaTextureIdx],
1641 light, surfaceScale, matrix, kd, mode ); 1657 light, surfaceScale, matrix, kd, mode );
1642 } 1658 }
1643 1659
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
1747 b->add32(lighting.boundaryMode() << 2 | lighting.light()->type()); 1763 b->add32(lighting.boundaryMode() << 2 | lighting.light()->type());
1748 } 1764 }
1749 1765
1750 void GrGLLightingEffect::onSetData(const GrGLProgramDataManager& pdman, 1766 void GrGLLightingEffect::onSetData(const GrGLProgramDataManager& pdman,
1751 const GrProcessor& proc) { 1767 const GrProcessor& proc) {
1752 const GrLightingEffect& lighting = proc.cast<GrLightingEffect>(); 1768 const GrLightingEffect& lighting = proc.cast<GrLightingEffect>();
1753 GrTexture* texture = lighting.texture(0); 1769 GrTexture* texture = lighting.texture(0);
1754 float ySign = texture->origin() == kTopLeft_GrSurfaceOrigin ? -1.0f : 1.0f; 1770 float ySign = texture->origin() == kTopLeft_GrSurfaceOrigin ? -1.0f : 1.0f;
1755 pdman.set2f(fImageIncrementUni, 1.0f / texture->width(), ySign / texture->he ight()); 1771 pdman.set2f(fImageIncrementUni, 1.0f / texture->width(), ySign / texture->he ight());
1756 pdman.set1f(fSurfaceScaleUni, lighting.surfaceScale()); 1772 pdman.set1f(fSurfaceScaleUni, lighting.surfaceScale());
1757 SkAutoTUnref<SkLight> transformedLight(lighting.light()->transform(lighting. filterMatrix())); 1773 SkAutoTUnref<SkImageFilterLight> transformedLight(
1774 lighting.light()->transform(lighting .filterMatrix()));
1758 fLight->setData(pdman, transformedLight); 1775 fLight->setData(pdman, transformedLight);
1759 } 1776 }
1760 1777
1761 /////////////////////////////////////////////////////////////////////////////// 1778 ///////////////////////////////////////////////////////////////////////////////
1762 1779
1763 /////////////////////////////////////////////////////////////////////////////// 1780 ///////////////////////////////////////////////////////////////////////////////
1764 1781
1765 GrGLDiffuseLightingEffect::GrGLDiffuseLightingEffect(const GrProcessor& proc) 1782 GrGLDiffuseLightingEffect::GrGLDiffuseLightingEffect(const GrProcessor& proc)
1766 : INHERITED(proc) { 1783 : INHERITED(proc) {
1767 } 1784 }
(...skipping 24 matching lines...) Expand all
1792 const GrProcessor& proc) { 1809 const GrProcessor& proc) {
1793 INHERITED::onSetData(pdman, proc); 1810 INHERITED::onSetData(pdman, proc);
1794 const GrDiffuseLightingEffect& diffuse = proc.cast<GrDiffuseLightingEffect>( ); 1811 const GrDiffuseLightingEffect& diffuse = proc.cast<GrDiffuseLightingEffect>( );
1795 pdman.set1f(fKDUni, diffuse.kd()); 1812 pdman.set1f(fKDUni, diffuse.kd());
1796 } 1813 }
1797 1814
1798 /////////////////////////////////////////////////////////////////////////////// 1815 ///////////////////////////////////////////////////////////////////////////////
1799 1816
1800 GrSpecularLightingEffect::GrSpecularLightingEffect(GrProcessorDataManager* procD ataManager, 1817 GrSpecularLightingEffect::GrSpecularLightingEffect(GrProcessorDataManager* procD ataManager,
1801 GrTexture* texture, 1818 GrTexture* texture,
1802 const SkLight* light, 1819 const SkImageFilterLight* lig ht,
1803 SkScalar surfaceScale, 1820 SkScalar surfaceScale,
1804 const SkMatrix& matrix, 1821 const SkMatrix& matrix,
1805 SkScalar ks, 1822 SkScalar ks,
1806 SkScalar shininess, 1823 SkScalar shininess,
1807 BoundaryMode boundaryMode) 1824 BoundaryMode boundaryMode)
1808 : INHERITED(procDataManager, texture, light, surfaceScale, matrix, boundaryM ode), 1825 : INHERITED(procDataManager, texture, light, surfaceScale, matrix, boundaryM ode)
1809 fKS(ks), 1826 , fKS(ks)
1810 fShininess(shininess) { 1827 , fShininess(shininess) {
1811 this->initClassID<GrSpecularLightingEffect>(); 1828 this->initClassID<GrSpecularLightingEffect>();
1812 } 1829 }
1813 1830
1814 bool GrSpecularLightingEffect::onIsEqual(const GrFragmentProcessor& sBase) const { 1831 bool GrSpecularLightingEffect::onIsEqual(const GrFragmentProcessor& sBase) const {
1815 const GrSpecularLightingEffect& s = sBase.cast<GrSpecularLightingEffect>(); 1832 const GrSpecularLightingEffect& s = sBase.cast<GrSpecularLightingEffect>();
1816 return INHERITED::onIsEqual(sBase) && 1833 return INHERITED::onIsEqual(sBase) &&
1817 this->ks() == s.ks() && 1834 this->ks() == s.ks() &&
1818 this->shininess() == s.shininess(); 1835 this->shininess() == s.shininess();
1819 } 1836 }
1820 1837
1821 void GrSpecularLightingEffect::onGetGLProcessorKey(const GrGLSLCaps& caps, 1838 void GrSpecularLightingEffect::onGetGLProcessorKey(const GrGLSLCaps& caps,
1822 GrProcessorKeyBuilder* b) const { 1839 GrProcessorKeyBuilder* b) const {
1823 GrGLSpecularLightingEffect::GenKey(*this, caps, b); 1840 GrGLSpecularLightingEffect::GenKey(*this, caps, b);
1824 } 1841 }
1825 1842
1826 GrGLFragmentProcessor* GrSpecularLightingEffect::onCreateGLInstance() const { 1843 GrGLFragmentProcessor* GrSpecularLightingEffect::onCreateGLInstance() const {
1827 return SkNEW_ARGS(GrGLSpecularLightingEffect, (*this)); 1844 return SkNEW_ARGS(GrGLSpecularLightingEffect, (*this));
1828 } 1845 }
1829 1846
1830 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrSpecularLightingEffect); 1847 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrSpecularLightingEffect);
1831 1848
1832 GrFragmentProcessor* GrSpecularLightingEffect::TestCreate(GrProcessorTestData* d ) { 1849 GrFragmentProcessor* GrSpecularLightingEffect::TestCreate(GrProcessorTestData* d ) {
1833 SkScalar surfaceScale = d->fRandom->nextSScalar1(); 1850 SkScalar surfaceScale = d->fRandom->nextSScalar1();
1834 SkScalar ks = d->fRandom->nextUScalar1(); 1851 SkScalar ks = d->fRandom->nextUScalar1();
1835 SkScalar shininess = d->fRandom->nextUScalar1(); 1852 SkScalar shininess = d->fRandom->nextUScalar1();
1836 SkAutoTUnref<SkLight> light(create_random_light(d->fRandom)); 1853 SkAutoTUnref<SkImageFilterLight> light(create_random_light(d->fRandom));
1837 SkMatrix matrix; 1854 SkMatrix matrix;
1838 for (int i = 0; i < 9; i++) { 1855 for (int i = 0; i < 9; i++) {
1839 matrix[i] = d->fRandom->nextUScalar1(); 1856 matrix[i] = d->fRandom->nextUScalar1();
1840 } 1857 }
1841 BoundaryMode mode = static_cast<BoundaryMode>(d->fRandom->nextU() % kBoundar yModeCount); 1858 BoundaryMode mode = static_cast<BoundaryMode>(d->fRandom->nextU() % kBoundar yModeCount);
1842 return GrSpecularLightingEffect::Create(d->fProcDataManager, 1859 return GrSpecularLightingEffect::Create(d->fProcDataManager,
1843 d->fTextures[GrProcessorUnitTest::kA lphaTextureIdx], 1860 d->fTextures[GrProcessorUnitTest::kA lphaTextureIdx],
1844 light, surfaceScale, matrix, ks, shi niness, mode); 1861 light, surfaceScale, matrix, ks, shi niness, mode);
1845 } 1862 }
1846 1863
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1892 void GrGLLight::emitLightColorUniform(GrGLFPBuilder* builder) { 1909 void GrGLLight::emitLightColorUniform(GrGLFPBuilder* builder) {
1893 fColorUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visibility, 1910 fColorUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visibility,
1894 kVec3f_GrSLType, kDefault_GrSLPrecision, 1911 kVec3f_GrSLType, kDefault_GrSLPrecision,
1895 "LightColor"); 1912 "LightColor");
1896 } 1913 }
1897 1914
1898 void GrGLLight::emitLightColor(GrGLFPBuilder* builder, const char *surfaceToLigh t) { 1915 void GrGLLight::emitLightColor(GrGLFPBuilder* builder, const char *surfaceToLigh t) {
1899 builder->getFragmentShaderBuilder()->codeAppend(builder->getUniformCStr(this ->lightColorUni())); 1916 builder->getFragmentShaderBuilder()->codeAppend(builder->getUniformCStr(this ->lightColorUni()));
1900 } 1917 }
1901 1918
1902 void GrGLLight::setData(const GrGLProgramDataManager& pdman, const SkLight* ligh t) const { 1919 void GrGLLight::setData(const GrGLProgramDataManager& pdman,
1920 const SkImageFilterLight* light) const {
1903 setUniformPoint3(pdman, fColorUni, 1921 setUniformPoint3(pdman, fColorUni,
1904 light->color().makeScale(SkScalarInvert(SkIntToScalar(255)) )); 1922 light->color().makeScale(SkScalarInvert(SkIntToScalar(255)) ));
1905 } 1923 }
1906 1924
1907 /////////////////////////////////////////////////////////////////////////////// 1925 ///////////////////////////////////////////////////////////////////////////////
1908 1926
1909 void GrGLDistantLight::setData(const GrGLProgramDataManager& pdman, 1927 void GrGLDistantLight::setData(const GrGLProgramDataManager& pdman,
1910 const SkLight* light) const { 1928 const SkImageFilterLight* light) const {
1911 INHERITED::setData(pdman, light); 1929 INHERITED::setData(pdman, light);
1912 SkASSERT(light->type() == SkLight::kDistant_LightType); 1930 SkASSERT(light->type() == SkImageFilterLight::kDistant_LightType);
1913 const SkDistantLight* distantLight = static_cast<const SkDistantLight*>(ligh t); 1931 const SkDistantLight* distantLight = static_cast<const SkDistantLight*>(ligh t);
1914 setUniformNormal3(pdman, fDirectionUni, distantLight->direction()); 1932 setUniformNormal3(pdman, fDirectionUni, distantLight->direction());
1915 } 1933 }
1916 1934
1917 void GrGLDistantLight::emitSurfaceToLight(GrGLFPBuilder* builder, const char* z) { 1935 void GrGLDistantLight::emitSurfaceToLight(GrGLFPBuilder* builder, const char* z) {
1918 const char* dir; 1936 const char* dir;
1919 fDirectionUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visibility , 1937 fDirectionUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visibility ,
1920 kVec3f_GrSLType, kDefault_GrSLPrecision, 1938 kVec3f_GrSLType, kDefault_GrSLPrecision,
1921 "LightDirection", &dir); 1939 "LightDirection", &dir);
1922 builder->getFragmentShaderBuilder()->codeAppend(dir); 1940 builder->getFragmentShaderBuilder()->codeAppend(dir);
1923 } 1941 }
1924 1942
1925 /////////////////////////////////////////////////////////////////////////////// 1943 ///////////////////////////////////////////////////////////////////////////////
1926 1944
1927 void GrGLPointLight::setData(const GrGLProgramDataManager& pdman, 1945 void GrGLPointLight::setData(const GrGLProgramDataManager& pdman,
1928 const SkLight* light) const { 1946 const SkImageFilterLight* light) const {
1929 INHERITED::setData(pdman, light); 1947 INHERITED::setData(pdman, light);
1930 SkASSERT(light->type() == SkLight::kPoint_LightType); 1948 SkASSERT(light->type() == SkImageFilterLight::kPoint_LightType);
1931 const SkPointLight* pointLight = static_cast<const SkPointLight*>(light); 1949 const SkPointLight* pointLight = static_cast<const SkPointLight*>(light);
1932 setUniformPoint3(pdman, fLocationUni, pointLight->location()); 1950 setUniformPoint3(pdman, fLocationUni, pointLight->location());
1933 } 1951 }
1934 1952
1935 void GrGLPointLight::emitSurfaceToLight(GrGLFPBuilder* builder, const char* z) { 1953 void GrGLPointLight::emitSurfaceToLight(GrGLFPBuilder* builder, const char* z) {
1936 const char* loc; 1954 const char* loc;
1937 fLocationUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visibility, 1955 fLocationUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visibility,
1938 kVec3f_GrSLType, kDefault_GrSLPrecision, 1956 kVec3f_GrSLType, kDefault_GrSLPrecision,
1939 "LightLocation", &loc); 1957 "LightLocation", &loc);
1940 GrGLFragmentBuilder* fsBuilder = builder->getFragmentShaderBuilder(); 1958 GrGLFragmentBuilder* fsBuilder = builder->getFragmentShaderBuilder();
1941 fsBuilder->codeAppendf("normalize(%s - vec3(%s.xy, %s))", 1959 fsBuilder->codeAppendf("normalize(%s - vec3(%s.xy, %s))",
1942 loc, fsBuilder->fragmentPosition(), z); 1960 loc, fsBuilder->fragmentPosition(), z);
1943 } 1961 }
1944 1962
1945 /////////////////////////////////////////////////////////////////////////////// 1963 ///////////////////////////////////////////////////////////////////////////////
1946 1964
1947 void GrGLSpotLight::setData(const GrGLProgramDataManager& pdman, 1965 void GrGLSpotLight::setData(const GrGLProgramDataManager& pdman,
1948 const SkLight* light) const { 1966 const SkImageFilterLight* light) const {
1949 INHERITED::setData(pdman, light); 1967 INHERITED::setData(pdman, light);
1950 SkASSERT(light->type() == SkLight::kSpot_LightType); 1968 SkASSERT(light->type() == SkImageFilterLight::kSpot_LightType);
1951 const SkSpotLight* spotLight = static_cast<const SkSpotLight *>(light); 1969 const SkSpotLight* spotLight = static_cast<const SkSpotLight *>(light);
1952 setUniformPoint3(pdman, fLocationUni, spotLight->location()); 1970 setUniformPoint3(pdman, fLocationUni, spotLight->location());
1953 pdman.set1f(fExponentUni, spotLight->specularExponent()); 1971 pdman.set1f(fExponentUni, spotLight->specularExponent());
1954 pdman.set1f(fCosInnerConeAngleUni, spotLight->cosInnerConeAngle()); 1972 pdman.set1f(fCosInnerConeAngleUni, spotLight->cosInnerConeAngle());
1955 pdman.set1f(fCosOuterConeAngleUni, spotLight->cosOuterConeAngle()); 1973 pdman.set1f(fCosOuterConeAngleUni, spotLight->cosOuterConeAngle());
1956 pdman.set1f(fConeScaleUni, spotLight->coneScale()); 1974 pdman.set1f(fConeScaleUni, spotLight->coneScale());
1957 setUniformNormal3(pdman, fSUni, spotLight->s()); 1975 setUniformNormal3(pdman, fSUni, spotLight->s());
1958 } 1976 }
1959 1977
1960 void GrGLSpotLight::emitSurfaceToLight(GrGLFPBuilder* builder, const char* z) { 1978 void GrGLSpotLight::emitSurfaceToLight(GrGLFPBuilder* builder, const char* z) {
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
2017 2035
2018 fsBuilder->codeAppendf("%s(%s)", fLightColorFunc.c_str(), surfaceToLight); 2036 fsBuilder->codeAppendf("%s(%s)", fLightColorFunc.c_str(), surfaceToLight);
2019 } 2037 }
2020 2038
2021 #endif 2039 #endif
2022 2040
2023 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingImageFilter) 2041 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingImageFilter)
2024 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDiffuseLightingImageFilter) 2042 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDiffuseLightingImageFilter)
2025 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSpecularLightingImageFilter) 2043 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSpecularLightingImageFilter)
2026 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END 2044 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END
OLDNEW
« no previous file with comments | « src/core/SkPoint3.cpp ('k') | src/effects/SkLightingShader.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698