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 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 surfaceToLight = l->surfaceToLight(x, y, m[4], surfaceScale); | 242 surfaceToLight = l->surfaceToLight(x, y, m[4], surfaceScale); |
243 *dptr++ = lightingType.light(bottomRightNormal(m, surfaceScale), surface
ToLight, l->lightColor(surfaceToLight)); | 243 *dptr++ = lightingType.light(bottomRightNormal(m, surfaceScale), surface
ToLight, l->lightColor(surfaceToLight)); |
244 } | 244 } |
245 } | 245 } |
246 | 246 |
247 SkPoint3 readPoint3(SkFlattenableReadBuffer& buffer) { | 247 SkPoint3 readPoint3(SkFlattenableReadBuffer& buffer) { |
248 SkPoint3 point; | 248 SkPoint3 point; |
249 point.fX = buffer.readScalar(); | 249 point.fX = buffer.readScalar(); |
250 point.fY = buffer.readScalar(); | 250 point.fY = buffer.readScalar(); |
251 point.fZ = buffer.readScalar(); | 251 point.fZ = buffer.readScalar(); |
| 252 buffer.validate(SkScalarIsFinite(point.fX) && |
| 253 SkScalarIsFinite(point.fY) && |
| 254 SkScalarIsFinite(point.fZ)); |
252 return point; | 255 return point; |
253 }; | 256 }; |
254 | 257 |
255 void writePoint3(const SkPoint3& point, SkFlattenableWriteBuffer& buffer) { | 258 void writePoint3(const SkPoint3& point, SkFlattenableWriteBuffer& buffer) { |
256 buffer.writeScalar(point.fX); | 259 buffer.writeScalar(point.fX); |
257 buffer.writeScalar(point.fY); | 260 buffer.writeScalar(point.fY); |
258 buffer.writeScalar(point.fZ); | 261 buffer.writeScalar(point.fZ); |
259 }; | 262 }; |
260 | 263 |
261 class SkDiffuseLightingImageFilter : public SkLightingImageFilter { | 264 class SkDiffuseLightingImageFilter : public SkLightingImageFilter { |
| 265 typedef SkLightingImageFilter INHERITED; |
| 266 |
262 public: | 267 public: |
263 SkDiffuseLightingImageFilter(SkLight* light, SkScalar surfaceScale, | 268 SkDiffuseLightingImageFilter(SkLight* light, SkScalar surfaceScale, |
264 SkScalar kd, SkImageFilter* input, const SkIRec
t* cropRect); | 269 SkScalar kd, SkImageFilter* input, const SkIRec
t* cropRect); |
265 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkDiffuseLightingImageFi
lter) | 270 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkDiffuseLightingImageFi
lter) |
266 | 271 |
267 #if SK_SUPPORT_GPU | 272 #if SK_SUPPORT_GPU |
268 virtual bool asNewEffect(GrEffectRef** effect, GrTexture*, const SkMatrix& m
atrix) const SK_OVERRIDE; | 273 virtual bool asNewEffect(GrEffectRef** effect, GrTexture*, const SkMatrix& m
atrix) const SK_OVERRIDE; |
269 #endif | 274 #endif |
270 SkScalar kd() const { return fKD; } | 275 SkScalar kd() const { return fKD; } |
271 | 276 |
272 protected: | 277 protected: |
273 explicit SkDiffuseLightingImageFilter(SkFlattenableReadBuffer& buffer); | 278 explicit SkDiffuseLightingImageFilter(SkFlattenableReadBuffer& buffer); |
274 virtual void flatten(SkFlattenableWriteBuffer& buffer) const SK_OVERRIDE; | 279 virtual void flatten(SkFlattenableWriteBuffer& buffer) const SK_OVERRIDE; |
275 virtual bool onFilterImage(Proxy*, const SkBitmap& src, const SkMatrix&, | 280 virtual bool onFilterImage(Proxy*, const SkBitmap& src, const SkMatrix&, |
276 SkBitmap* result, SkIPoint* offset) SK_OVERRIDE; | 281 SkBitmap* result, SkIPoint* offset) SK_OVERRIDE; |
277 | 282 |
278 | 283 |
279 private: | 284 private: |
280 typedef SkLightingImageFilter INHERITED; | |
281 SkScalar fKD; | 285 SkScalar fKD; |
282 }; | 286 }; |
283 | 287 |
284 class SkSpecularLightingImageFilter : public SkLightingImageFilter { | 288 class SkSpecularLightingImageFilter : public SkLightingImageFilter { |
| 289 typedef SkLightingImageFilter INHERITED; |
| 290 |
285 public: | 291 public: |
286 SkSpecularLightingImageFilter(SkLight* light, SkScalar surfaceScale, SkScala
r ks, SkScalar shininess, SkImageFilter* input, const SkIRect* cropRect); | 292 SkSpecularLightingImageFilter(SkLight* light, SkScalar surfaceScale, SkScala
r ks, SkScalar shininess, SkImageFilter* input, const SkIRect* cropRect); |
287 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkSpecularLightingImageF
ilter) | 293 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkSpecularLightingImageF
ilter) |
288 | 294 |
289 #if SK_SUPPORT_GPU | 295 #if SK_SUPPORT_GPU |
290 virtual bool asNewEffect(GrEffectRef** effect, GrTexture*, const SkMatrix& m
atrix) const SK_OVERRIDE; | 296 virtual bool asNewEffect(GrEffectRef** effect, GrTexture*, const SkMatrix& m
atrix) const SK_OVERRIDE; |
291 #endif | 297 #endif |
292 | 298 |
293 SkScalar ks() const { return fKS; } | 299 SkScalar ks() const { return fKS; } |
294 SkScalar shininess() const { return fShininess; } | 300 SkScalar shininess() const { return fShininess; } |
295 | 301 |
296 protected: | 302 protected: |
297 explicit SkSpecularLightingImageFilter(SkFlattenableReadBuffer& buffer); | 303 explicit SkSpecularLightingImageFilter(SkFlattenableReadBuffer& buffer); |
298 virtual void flatten(SkFlattenableWriteBuffer& buffer) const SK_OVERRIDE; | 304 virtual void flatten(SkFlattenableWriteBuffer& buffer) const SK_OVERRIDE; |
299 virtual bool onFilterImage(Proxy*, const SkBitmap& src, const SkMatrix&, | 305 virtual bool onFilterImage(Proxy*, const SkBitmap& src, const SkMatrix&, |
300 SkBitmap* result, SkIPoint* offset) SK_OVERRIDE; | 306 SkBitmap* result, SkIPoint* offset) SK_OVERRIDE; |
301 | 307 |
302 private: | 308 private: |
303 typedef SkLightingImageFilter INHERITED; | |
304 SkScalar fKS; | 309 SkScalar fKS; |
305 SkScalar fShininess; | 310 SkScalar fShininess; |
306 }; | 311 }; |
307 | 312 |
308 #if SK_SUPPORT_GPU | 313 #if SK_SUPPORT_GPU |
309 | 314 |
310 class GrLightingEffect : public GrSingleTextureEffect { | 315 class GrLightingEffect : public GrSingleTextureEffect { |
311 public: | 316 public: |
312 GrLightingEffect(GrTexture* texture, const SkLight* light, SkScalar surfaceS
cale, const SkMatrix& matrix); | 317 GrLightingEffect(GrTexture* texture, const SkLight* light, SkScalar surfaceS
cale, const SkMatrix& matrix); |
313 virtual ~GrLightingEffect(); | 318 virtual ~GrLightingEffect(); |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
502 | 507 |
503 class GrGLLight; | 508 class GrGLLight; |
504 | 509 |
505 #endif | 510 #endif |
506 | 511 |
507 }; | 512 }; |
508 | 513 |
509 /////////////////////////////////////////////////////////////////////////////// | 514 /////////////////////////////////////////////////////////////////////////////// |
510 | 515 |
511 class SkLight : public SkFlattenable { | 516 class SkLight : public SkFlattenable { |
| 517 typedef SkFlattenable INHERITED; |
| 518 |
512 public: | 519 public: |
513 SK_DECLARE_INST_COUNT(SkLight) | 520 SK_DECLARE_INST_COUNT(SkLight) |
514 | 521 |
515 enum LightType { | 522 enum LightType { |
516 kDistant_LightType, | 523 kDistant_LightType, |
517 kPoint_LightType, | 524 kPoint_LightType, |
518 kSpot_LightType, | 525 kSpot_LightType, |
519 }; | 526 }; |
520 virtual LightType type() const = 0; | 527 virtual LightType type() const = 0; |
521 const SkPoint3& color() const { return fColor; } | 528 const SkPoint3& color() const { return fColor; } |
522 virtual GrGLLight* createGLLight() const = 0; | 529 virtual GrGLLight* createGLLight() const = 0; |
523 virtual bool isEqual(const SkLight& other) const { | 530 virtual bool isEqual(const SkLight& other) const { |
524 return fColor == other.fColor; | 531 return fColor == other.fColor; |
525 } | 532 } |
526 // Called to know whether the generated GrGLLight will require access to the
fragment position. | 533 // Called to know whether the generated GrGLLight will require access to the
fragment position. |
527 virtual bool requiresFragmentPosition() const = 0; | 534 virtual bool requiresFragmentPosition() const = 0; |
528 virtual SkLight* transform(const SkMatrix& matrix) const = 0; | 535 virtual SkLight* transform(const SkMatrix& matrix) const = 0; |
529 | 536 |
| 537 SK_DEFINE_FLATTENABLE_TYPE(SkLight) |
| 538 |
530 protected: | 539 protected: |
531 SkLight(SkColor color) | 540 SkLight(SkColor color) |
532 : fColor(SkIntToScalar(SkColorGetR(color)), | 541 : fColor(SkIntToScalar(SkColorGetR(color)), |
533 SkIntToScalar(SkColorGetG(color)), | 542 SkIntToScalar(SkColorGetG(color)), |
534 SkIntToScalar(SkColorGetB(color))) {} | 543 SkIntToScalar(SkColorGetB(color))) {} |
535 SkLight(const SkPoint3& color) | 544 SkLight(const SkPoint3& color) |
536 : fColor(color) {} | 545 : fColor(color) {} |
537 SkLight(SkFlattenableReadBuffer& buffer) | 546 SkLight(SkFlattenableReadBuffer& buffer) |
538 : INHERITED(buffer) { | 547 : INHERITED(buffer) { |
539 fColor = readPoint3(buffer); | 548 fColor = readPoint3(buffer); |
540 } | 549 } |
541 virtual void flatten(SkFlattenableWriteBuffer& buffer) const SK_OVERRIDE { | 550 virtual void flatten(SkFlattenableWriteBuffer& buffer) const SK_OVERRIDE { |
542 INHERITED::flatten(buffer); | 551 INHERITED::flatten(buffer); |
543 writePoint3(fColor, buffer); | 552 writePoint3(fColor, buffer); |
544 } | 553 } |
545 | 554 |
546 private: | 555 private: |
547 typedef SkFlattenable INHERITED; | |
548 SkPoint3 fColor; | 556 SkPoint3 fColor; |
549 }; | 557 }; |
550 | 558 |
551 SK_DEFINE_INST_COUNT(SkLight) | 559 SK_DEFINE_INST_COUNT(SkLight) |
552 | 560 |
553 /////////////////////////////////////////////////////////////////////////////// | 561 /////////////////////////////////////////////////////////////////////////////// |
554 | 562 |
555 class SkDistantLight : public SkLight { | 563 class SkDistantLight : public SkLight { |
| 564 typedef SkLight INHERITED; |
| 565 |
556 public: | 566 public: |
557 SkDistantLight(const SkPoint3& direction, SkColor color) | 567 SkDistantLight(const SkPoint3& direction, SkColor color) |
558 : INHERITED(color), fDirection(direction) { | 568 : INHERITED(color), fDirection(direction) { |
559 } | 569 } |
560 | 570 |
561 SkPoint3 surfaceToLight(int x, int y, int z, SkScalar surfaceScale) const { | 571 SkPoint3 surfaceToLight(int x, int y, int z, SkScalar surfaceScale) const { |
562 return fDirection; | 572 return fDirection; |
563 }; | 573 }; |
564 SkPoint3 lightColor(const SkPoint3&) const { return color(); } | 574 SkPoint3 lightColor(const SkPoint3&) const { return color(); } |
565 virtual LightType type() const { return kDistant_LightType; } | 575 virtual LightType type() const { return kDistant_LightType; } |
(...skipping 29 matching lines...) Expand all Loading... |
595 } | 605 } |
596 virtual SkLight* transform(const SkMatrix& matrix) const { | 606 virtual SkLight* transform(const SkMatrix& matrix) const { |
597 return new SkDistantLight(direction(), color()); | 607 return new SkDistantLight(direction(), color()); |
598 } | 608 } |
599 virtual void flatten(SkFlattenableWriteBuffer& buffer) const { | 609 virtual void flatten(SkFlattenableWriteBuffer& buffer) const { |
600 INHERITED::flatten(buffer); | 610 INHERITED::flatten(buffer); |
601 writePoint3(fDirection, buffer); | 611 writePoint3(fDirection, buffer); |
602 } | 612 } |
603 | 613 |
604 private: | 614 private: |
605 typedef SkLight INHERITED; | |
606 SkPoint3 fDirection; | 615 SkPoint3 fDirection; |
607 }; | 616 }; |
608 | 617 |
609 /////////////////////////////////////////////////////////////////////////////// | 618 /////////////////////////////////////////////////////////////////////////////// |
610 | 619 |
611 class SkPointLight : public SkLight { | 620 class SkPointLight : public SkLight { |
| 621 typedef SkLight INHERITED; |
| 622 |
612 public: | 623 public: |
613 SkPointLight(const SkPoint3& location, SkColor color) | 624 SkPointLight(const SkPoint3& location, SkColor color) |
614 : INHERITED(color), fLocation(location) {} | 625 : INHERITED(color), fLocation(location) {} |
615 | 626 |
616 SkPoint3 surfaceToLight(int x, int y, int z, SkScalar surfaceScale) const { | 627 SkPoint3 surfaceToLight(int x, int y, int z, SkScalar surfaceScale) const { |
617 SkPoint3 direction(fLocation.fX - SkIntToScalar(x), | 628 SkPoint3 direction(fLocation.fX - SkIntToScalar(x), |
618 fLocation.fY - SkIntToScalar(y), | 629 fLocation.fY - SkIntToScalar(y), |
619 fLocation.fZ - SkScalarMul(SkIntToScalar(z), surfaceS
cale)); | 630 fLocation.fZ - SkScalarMul(SkIntToScalar(z), surfaceS
cale)); |
620 direction.normalize(); | 631 direction.normalize(); |
621 return direction; | 632 return direction; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
654 fLocation = readPoint3(buffer); | 665 fLocation = readPoint3(buffer); |
655 } | 666 } |
656 SkPointLight(const SkPoint3& location, const SkPoint3& color) | 667 SkPointLight(const SkPoint3& location, const SkPoint3& color) |
657 : INHERITED(color), fLocation(location) {} | 668 : INHERITED(color), fLocation(location) {} |
658 virtual void flatten(SkFlattenableWriteBuffer& buffer) const { | 669 virtual void flatten(SkFlattenableWriteBuffer& buffer) const { |
659 INHERITED::flatten(buffer); | 670 INHERITED::flatten(buffer); |
660 writePoint3(fLocation, buffer); | 671 writePoint3(fLocation, buffer); |
661 } | 672 } |
662 | 673 |
663 private: | 674 private: |
664 typedef SkLight INHERITED; | |
665 SkPoint3 fLocation; | 675 SkPoint3 fLocation; |
666 }; | 676 }; |
667 | 677 |
668 /////////////////////////////////////////////////////////////////////////////// | 678 /////////////////////////////////////////////////////////////////////////////// |
669 | 679 |
670 class SkSpotLight : public SkLight { | 680 class SkSpotLight : public SkLight { |
| 681 typedef SkLight INHERITED; |
| 682 |
671 public: | 683 public: |
672 SkSpotLight(const SkPoint3& location, const SkPoint3& target, SkScalar specu
larExponent, SkScalar cutoffAngle, SkColor color) | 684 SkSpotLight(const SkPoint3& location, const SkPoint3& target, SkScalar specu
larExponent, SkScalar cutoffAngle, SkColor color) |
673 : INHERITED(color), | 685 : INHERITED(color), |
674 fLocation(location), | 686 fLocation(location), |
675 fTarget(target), | 687 fTarget(target), |
676 fSpecularExponent(SkScalarPin(specularExponent, kSpecularExponentMin, kSp
ecularExponentMax)) | 688 fSpecularExponent(SkScalarPin(specularExponent, kSpecularExponentMin, kSp
ecularExponentMax)) |
677 { | 689 { |
678 fS = target - location; | 690 fS = target - location; |
679 fS.normalize(); | 691 fS.normalize(); |
680 fCosOuterConeAngle = SkScalarCos(SkDegreesToRadians(cutoffAngle)); | 692 fCosOuterConeAngle = SkScalarCos(SkDegreesToRadians(cutoffAngle)); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
734 | 746 |
735 protected: | 747 protected: |
736 SkSpotLight(SkFlattenableReadBuffer& buffer) : INHERITED(buffer) { | 748 SkSpotLight(SkFlattenableReadBuffer& buffer) : INHERITED(buffer) { |
737 fLocation = readPoint3(buffer); | 749 fLocation = readPoint3(buffer); |
738 fTarget = readPoint3(buffer); | 750 fTarget = readPoint3(buffer); |
739 fSpecularExponent = buffer.readScalar(); | 751 fSpecularExponent = buffer.readScalar(); |
740 fCosOuterConeAngle = buffer.readScalar(); | 752 fCosOuterConeAngle = buffer.readScalar(); |
741 fCosInnerConeAngle = buffer.readScalar(); | 753 fCosInnerConeAngle = buffer.readScalar(); |
742 fConeScale = buffer.readScalar(); | 754 fConeScale = buffer.readScalar(); |
743 fS = readPoint3(buffer); | 755 fS = readPoint3(buffer); |
| 756 buffer.validate(SkScalarIsFinite(fSpecularExponent) && |
| 757 SkScalarIsFinite(fCosOuterConeAngle) && |
| 758 SkScalarIsFinite(fCosInnerConeAngle) && |
| 759 SkScalarIsFinite(fConeScale)); |
744 } | 760 } |
745 SkSpotLight(const SkPoint3& location, const SkPoint3& target, SkScalar specu
larExponent, SkScalar cosOuterConeAngle, SkScalar cosInnerConeAngle, SkScalar co
neScale, const SkPoint3& s, const SkPoint3& color) | 761 SkSpotLight(const SkPoint3& location, const SkPoint3& target, SkScalar specu
larExponent, SkScalar cosOuterConeAngle, SkScalar cosInnerConeAngle, SkScalar co
neScale, const SkPoint3& s, const SkPoint3& color) |
746 : INHERITED(color), | 762 : INHERITED(color), |
747 fLocation(location), | 763 fLocation(location), |
748 fTarget(target), | 764 fTarget(target), |
749 fSpecularExponent(specularExponent), | 765 fSpecularExponent(specularExponent), |
750 fCosOuterConeAngle(cosOuterConeAngle), | 766 fCosOuterConeAngle(cosOuterConeAngle), |
751 fCosInnerConeAngle(cosInnerConeAngle), | 767 fCosInnerConeAngle(cosInnerConeAngle), |
752 fConeScale(coneScale), | 768 fConeScale(coneScale), |
753 fS(s) | 769 fS(s) |
(...skipping 20 matching lines...) Expand all Loading... |
774 fLocation == o.fLocation && | 790 fLocation == o.fLocation && |
775 fTarget == o.fTarget && | 791 fTarget == o.fTarget && |
776 fSpecularExponent == o.fSpecularExponent && | 792 fSpecularExponent == o.fSpecularExponent && |
777 fCosOuterConeAngle == o.fCosOuterConeAngle; | 793 fCosOuterConeAngle == o.fCosOuterConeAngle; |
778 } | 794 } |
779 | 795 |
780 private: | 796 private: |
781 static const SkScalar kSpecularExponentMin; | 797 static const SkScalar kSpecularExponentMin; |
782 static const SkScalar kSpecularExponentMax; | 798 static const SkScalar kSpecularExponentMax; |
783 | 799 |
784 typedef SkLight INHERITED; | |
785 SkPoint3 fLocation; | 800 SkPoint3 fLocation; |
786 SkPoint3 fTarget; | 801 SkPoint3 fTarget; |
787 SkScalar fSpecularExponent; | 802 SkScalar fSpecularExponent; |
788 SkScalar fCosOuterConeAngle; | 803 SkScalar fCosOuterConeAngle; |
789 SkScalar fCosInnerConeAngle; | 804 SkScalar fCosInnerConeAngle; |
790 SkScalar fConeScale; | 805 SkScalar fConeScale; |
791 SkPoint3 fS; | 806 SkPoint3 fS; |
792 }; | 807 }; |
793 | 808 |
794 // According to the spec, the specular term should be in the range [1, 128] : | 809 // According to the spec, the specular term should be in the range [1, 128] : |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
854 SkImageFilter* SkLightingImageFilter::CreateSpotLitSpecular( | 869 SkImageFilter* SkLightingImageFilter::CreateSpotLitSpecular( |
855 const SkPoint3& location, const SkPoint3& target, | 870 const SkPoint3& location, const SkPoint3& target, |
856 SkScalar specularExponent, SkScalar cutoffAngle, | 871 SkScalar specularExponent, SkScalar cutoffAngle, |
857 SkColor lightColor, SkScalar surfaceScale, | 872 SkColor lightColor, SkScalar surfaceScale, |
858 SkScalar ks, SkScalar shininess, SkImageFilter* input, const SkIRect* cropRe
ct) { | 873 SkScalar ks, SkScalar shininess, SkImageFilter* input, const SkIRect* cropRe
ct) { |
859 return SkNEW_ARGS(SkSpecularLightingImageFilter, | 874 return SkNEW_ARGS(SkSpecularLightingImageFilter, |
860 (SkNEW_ARGS(SkSpotLight, (location, target, specularExponent, cutoffAngl
e, lightColor)), | 875 (SkNEW_ARGS(SkSpotLight, (location, target, specularExponent, cutoffAngl
e, lightColor)), |
861 surfaceScale, ks, shininess, input, cropRect)); | 876 surfaceScale, ks, shininess, input, cropRect)); |
862 } | 877 } |
863 | 878 |
| 879 SkFlattenable::Factory SkLightingImageFilter::GetFactory(SkFlattenable::Type typ
e) { |
| 880 switch(type) { |
| 881 case SkFlattenable::kSkDiffuseLightingImageFilter: |
| 882 return SkDiffuseLightingImageFilter::CreateProc; |
| 883 case SkFlattenable::kSkDistantLight: |
| 884 return SkDistantLight::CreateProc; |
| 885 case SkFlattenable::kSkPointLight: |
| 886 return SkPointLight::CreateProc; |
| 887 case SkFlattenable::kSkSpecularLightingImageFilter: |
| 888 return SkSpecularLightingImageFilter::CreateProc; |
| 889 case SkFlattenable::kSkSpotLight: |
| 890 return SkSpotLight::CreateProc; |
| 891 default: |
| 892 break; |
| 893 } |
| 894 return NULL; |
| 895 } |
| 896 |
| 897 SkFlattenable::TypeCheck SkLightingImageFilter::GetTypeCheck(SkFlattenable::Type
type) { |
| 898 switch(type) { |
| 899 case SkFlattenable::kSkDiffuseLightingImageFilter: |
| 900 return SkDiffuseLightingImageFilter::IsA; |
| 901 case SkFlattenable::kSkDistantLight: |
| 902 return SkDistantLight::IsA; |
| 903 case SkFlattenable::kSkPointLight: |
| 904 return SkPointLight::IsA; |
| 905 case SkFlattenable::kSkSpecularLightingImageFilter: |
| 906 return SkSpecularLightingImageFilter::IsA; |
| 907 case SkFlattenable::kSkSpotLight: |
| 908 return SkSpotLight::IsA; |
| 909 default: |
| 910 break; |
| 911 } |
| 912 return NULL; |
| 913 } |
| 914 |
864 SkLightingImageFilter::~SkLightingImageFilter() { | 915 SkLightingImageFilter::~SkLightingImageFilter() { |
865 fLight->unref(); | 916 fLight->unref(); |
866 } | 917 } |
867 | 918 |
868 SkLightingImageFilter::SkLightingImageFilter(SkFlattenableReadBuffer& buffer) | 919 SkLightingImageFilter::SkLightingImageFilter(SkFlattenableReadBuffer& buffer) |
869 : INHERITED(buffer) | 920 : INHERITED(buffer) |
870 { | 921 { |
871 fLight = buffer.readFlattenableT<SkLight>(); | 922 fLight = buffer.readFlattenableT<SkLight>(); |
872 fSurfaceScale = buffer.readScalar(); | 923 fSurfaceScale = buffer.readScalar(); |
| 924 buffer.validate(SkScalarIsFinite(fSurfaceScale)); |
873 } | 925 } |
874 | 926 |
875 void SkLightingImageFilter::flatten(SkFlattenableWriteBuffer& buffer) const { | 927 void SkLightingImageFilter::flatten(SkFlattenableWriteBuffer& buffer) const { |
876 this->INHERITED::flatten(buffer); | 928 this->INHERITED::flatten(buffer); |
877 buffer.writeFlattenable(fLight); | 929 buffer.writeFlattenable(fLight); |
878 buffer.writeScalar(fSurfaceScale); | 930 buffer.writeScalar(fSurfaceScale); |
879 } | 931 } |
880 | 932 |
881 /////////////////////////////////////////////////////////////////////////////// | 933 /////////////////////////////////////////////////////////////////////////////// |
882 | 934 |
883 SkDiffuseLightingImageFilter::SkDiffuseLightingImageFilter(SkLight* light, SkSca
lar surfaceScale, SkScalar kd, SkImageFilter* input, const SkIRect* cropRect = N
ULL) | 935 SkDiffuseLightingImageFilter::SkDiffuseLightingImageFilter(SkLight* light, SkSca
lar surfaceScale, SkScalar kd, SkImageFilter* input, const SkIRect* cropRect = N
ULL) |
884 : SkLightingImageFilter(light, surfaceScale, input, cropRect), | 936 : SkLightingImageFilter(light, surfaceScale, input, cropRect), |
885 fKD(kd) | 937 fKD(kd) |
886 { | 938 { |
887 } | 939 } |
888 | 940 |
889 SkDiffuseLightingImageFilter::SkDiffuseLightingImageFilter(SkFlattenableReadBuff
er& buffer) | 941 SkDiffuseLightingImageFilter::SkDiffuseLightingImageFilter(SkFlattenableReadBuff
er& buffer) |
890 : INHERITED(buffer) | 942 : INHERITED(buffer) |
891 { | 943 { |
892 fKD = buffer.readScalar(); | 944 fKD = buffer.readScalar(); |
| 945 buffer.validate(SkScalarIsFinite(fKD)); |
893 } | 946 } |
894 | 947 |
895 void SkDiffuseLightingImageFilter::flatten(SkFlattenableWriteBuffer& buffer) con
st { | 948 void SkDiffuseLightingImageFilter::flatten(SkFlattenableWriteBuffer& buffer) con
st { |
896 this->INHERITED::flatten(buffer); | 949 this->INHERITED::flatten(buffer); |
897 buffer.writeScalar(fKD); | 950 buffer.writeScalar(fKD); |
898 } | 951 } |
899 | 952 |
900 bool SkDiffuseLightingImageFilter::onFilterImage(Proxy*, | 953 bool SkDiffuseLightingImageFilter::onFilterImage(Proxy*, |
901 const SkBitmap& src, | 954 const SkBitmap& src, |
902 const SkMatrix& ctm, | 955 const SkMatrix& ctm, |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
960 fKS(ks), | 1013 fKS(ks), |
961 fShininess(shininess) | 1014 fShininess(shininess) |
962 { | 1015 { |
963 } | 1016 } |
964 | 1017 |
965 SkSpecularLightingImageFilter::SkSpecularLightingImageFilter(SkFlattenableReadBu
ffer& buffer) | 1018 SkSpecularLightingImageFilter::SkSpecularLightingImageFilter(SkFlattenableReadBu
ffer& buffer) |
966 : INHERITED(buffer) | 1019 : INHERITED(buffer) |
967 { | 1020 { |
968 fKS = buffer.readScalar(); | 1021 fKS = buffer.readScalar(); |
969 fShininess = buffer.readScalar(); | 1022 fShininess = buffer.readScalar(); |
| 1023 buffer.validate(SkScalarIsFinite(fKS) && |
| 1024 SkScalarIsFinite(fShininess)); |
970 } | 1025 } |
971 | 1026 |
972 void SkSpecularLightingImageFilter::flatten(SkFlattenableWriteBuffer& buffer) co
nst { | 1027 void SkSpecularLightingImageFilter::flatten(SkFlattenableWriteBuffer& buffer) co
nst { |
973 this->INHERITED::flatten(buffer); | 1028 this->INHERITED::flatten(buffer); |
974 buffer.writeScalar(fKS); | 1029 buffer.writeScalar(fKS); |
975 buffer.writeScalar(fShininess); | 1030 buffer.writeScalar(fShininess); |
976 } | 1031 } |
977 | 1032 |
978 bool SkSpecularLightingImageFilter::onFilterImage(Proxy*, | 1033 bool SkSpecularLightingImageFilter::onFilterImage(Proxy*, |
979 const SkBitmap& src, | 1034 const SkBitmap& src, |
(...skipping 592 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1572 | 1627 |
1573 #endif | 1628 #endif |
1574 | 1629 |
1575 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingImageFilter) | 1630 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingImageFilter) |
1576 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDiffuseLightingImageFilter) | 1631 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDiffuseLightingImageFilter) |
1577 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSpecularLightingImageFilter) | 1632 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSpecularLightingImageFilter) |
1578 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDistantLight) | 1633 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDistantLight) |
1579 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkPointLight) | 1634 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkPointLight) |
1580 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSpotLight) | 1635 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSpotLight) |
1581 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END | 1636 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END |
OLD | NEW |