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 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 return point; | 252 return point; |
253 }; | 253 }; |
254 | 254 |
255 void writePoint3(const SkPoint3& point, SkFlattenableWriteBuffer& buffer) { | 255 void writePoint3(const SkPoint3& point, SkFlattenableWriteBuffer& buffer) { |
256 buffer.writeScalar(point.fX); | 256 buffer.writeScalar(point.fX); |
257 buffer.writeScalar(point.fY); | 257 buffer.writeScalar(point.fY); |
258 buffer.writeScalar(point.fZ); | 258 buffer.writeScalar(point.fZ); |
259 }; | 259 }; |
260 | 260 |
261 class SkDiffuseLightingImageFilter : public SkLightingImageFilter { | 261 class SkDiffuseLightingImageFilter : public SkLightingImageFilter { |
| 262 typedef SkLightingImageFilter INHERITED; |
| 263 |
262 public: | 264 public: |
263 SkDiffuseLightingImageFilter(SkLight* light, SkScalar surfaceScale, | 265 SkDiffuseLightingImageFilter(SkLight* light, SkScalar surfaceScale, |
264 SkScalar kd, SkImageFilter* input, const SkIRec
t* cropRect); | 266 SkScalar kd, SkImageFilter* input, const SkIRec
t* cropRect); |
265 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkDiffuseLightingImageFi
lter) | 267 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkDiffuseLightingImageFi
lter) |
266 | 268 |
267 #if SK_SUPPORT_GPU | 269 #if SK_SUPPORT_GPU |
268 virtual bool asNewEffect(GrEffectRef** effect, GrTexture*, const SkMatrix& m
atrix) const SK_OVERRIDE; | 270 virtual bool asNewEffect(GrEffectRef** effect, GrTexture*, const SkMatrix& m
atrix) const SK_OVERRIDE; |
269 #endif | 271 #endif |
270 SkScalar kd() const { return fKD; } | 272 SkScalar kd() const { return fKD; } |
271 | 273 |
272 protected: | 274 protected: |
273 explicit SkDiffuseLightingImageFilter(SkFlattenableReadBuffer& buffer); | 275 explicit SkDiffuseLightingImageFilter(SkFlattenableReadBuffer& buffer); |
274 virtual void flatten(SkFlattenableWriteBuffer& buffer) const SK_OVERRIDE; | 276 virtual void flatten(SkFlattenableWriteBuffer& buffer) const SK_OVERRIDE; |
275 virtual bool onFilterImage(Proxy*, const SkBitmap& src, const SkMatrix&, | 277 virtual bool onFilterImage(Proxy*, const SkBitmap& src, const SkMatrix&, |
276 SkBitmap* result, SkIPoint* offset) SK_OVERRIDE; | 278 SkBitmap* result, SkIPoint* offset) SK_OVERRIDE; |
277 | 279 |
278 | 280 |
279 private: | 281 private: |
280 typedef SkLightingImageFilter INHERITED; | |
281 SkScalar fKD; | 282 SkScalar fKD; |
282 }; | 283 }; |
283 | 284 |
284 class SkSpecularLightingImageFilter : public SkLightingImageFilter { | 285 class SkSpecularLightingImageFilter : public SkLightingImageFilter { |
| 286 typedef SkLightingImageFilter INHERITED; |
| 287 |
285 public: | 288 public: |
286 SkSpecularLightingImageFilter(SkLight* light, SkScalar surfaceScale, SkScala
r ks, SkScalar shininess, SkImageFilter* input, const SkIRect* cropRect); | 289 SkSpecularLightingImageFilter(SkLight* light, SkScalar surfaceScale, SkScala
r ks, SkScalar shininess, SkImageFilter* input, const SkIRect* cropRect); |
287 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkSpecularLightingImageF
ilter) | 290 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkSpecularLightingImageF
ilter) |
288 | 291 |
289 #if SK_SUPPORT_GPU | 292 #if SK_SUPPORT_GPU |
290 virtual bool asNewEffect(GrEffectRef** effect, GrTexture*, const SkMatrix& m
atrix) const SK_OVERRIDE; | 293 virtual bool asNewEffect(GrEffectRef** effect, GrTexture*, const SkMatrix& m
atrix) const SK_OVERRIDE; |
291 #endif | 294 #endif |
292 | 295 |
293 SkScalar ks() const { return fKS; } | 296 SkScalar ks() const { return fKS; } |
294 SkScalar shininess() const { return fShininess; } | 297 SkScalar shininess() const { return fShininess; } |
295 | 298 |
296 protected: | 299 protected: |
297 explicit SkSpecularLightingImageFilter(SkFlattenableReadBuffer& buffer); | 300 explicit SkSpecularLightingImageFilter(SkFlattenableReadBuffer& buffer); |
298 virtual void flatten(SkFlattenableWriteBuffer& buffer) const SK_OVERRIDE; | 301 virtual void flatten(SkFlattenableWriteBuffer& buffer) const SK_OVERRIDE; |
299 virtual bool onFilterImage(Proxy*, const SkBitmap& src, const SkMatrix&, | 302 virtual bool onFilterImage(Proxy*, const SkBitmap& src, const SkMatrix&, |
300 SkBitmap* result, SkIPoint* offset) SK_OVERRIDE; | 303 SkBitmap* result, SkIPoint* offset) SK_OVERRIDE; |
301 | 304 |
302 private: | 305 private: |
303 typedef SkLightingImageFilter INHERITED; | |
304 SkScalar fKS; | 306 SkScalar fKS; |
305 SkScalar fShininess; | 307 SkScalar fShininess; |
306 }; | 308 }; |
307 | 309 |
308 #if SK_SUPPORT_GPU | 310 #if SK_SUPPORT_GPU |
309 | 311 |
310 class GrLightingEffect : public GrSingleTextureEffect { | 312 class GrLightingEffect : public GrSingleTextureEffect { |
311 public: | 313 public: |
312 GrLightingEffect(GrTexture* texture, const SkLight* light, SkScalar surfaceS
cale, const SkMatrix& matrix); | 314 GrLightingEffect(GrTexture* texture, const SkLight* light, SkScalar surfaceS
cale, const SkMatrix& matrix); |
313 virtual ~GrLightingEffect(); | 315 virtual ~GrLightingEffect(); |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
502 | 504 |
503 class GrGLLight; | 505 class GrGLLight; |
504 | 506 |
505 #endif | 507 #endif |
506 | 508 |
507 }; | 509 }; |
508 | 510 |
509 /////////////////////////////////////////////////////////////////////////////// | 511 /////////////////////////////////////////////////////////////////////////////// |
510 | 512 |
511 class SkLight : public SkFlattenable { | 513 class SkLight : public SkFlattenable { |
| 514 typedef SkFlattenable INHERITED; |
| 515 |
512 public: | 516 public: |
513 SK_DECLARE_INST_COUNT(SkLight) | 517 SK_DECLARE_INST_COUNT(SkLight) |
514 | 518 |
515 enum LightType { | 519 enum LightType { |
516 kDistant_LightType, | 520 kDistant_LightType, |
517 kPoint_LightType, | 521 kPoint_LightType, |
518 kSpot_LightType, | 522 kSpot_LightType, |
519 }; | 523 }; |
520 virtual LightType type() const = 0; | 524 virtual LightType type() const = 0; |
521 const SkPoint3& color() const { return fColor; } | 525 const SkPoint3& color() const { return fColor; } |
(...skipping 15 matching lines...) Expand all Loading... |
537 SkLight(SkFlattenableReadBuffer& buffer) | 541 SkLight(SkFlattenableReadBuffer& buffer) |
538 : INHERITED(buffer) { | 542 : INHERITED(buffer) { |
539 fColor = readPoint3(buffer); | 543 fColor = readPoint3(buffer); |
540 } | 544 } |
541 virtual void flatten(SkFlattenableWriteBuffer& buffer) const SK_OVERRIDE { | 545 virtual void flatten(SkFlattenableWriteBuffer& buffer) const SK_OVERRIDE { |
542 INHERITED::flatten(buffer); | 546 INHERITED::flatten(buffer); |
543 writePoint3(fColor, buffer); | 547 writePoint3(fColor, buffer); |
544 } | 548 } |
545 | 549 |
546 private: | 550 private: |
547 typedef SkFlattenable INHERITED; | |
548 SkPoint3 fColor; | 551 SkPoint3 fColor; |
549 }; | 552 }; |
550 | 553 |
551 SK_DEFINE_INST_COUNT(SkLight) | 554 SK_DEFINE_INST_COUNT(SkLight) |
552 | 555 |
553 /////////////////////////////////////////////////////////////////////////////// | 556 /////////////////////////////////////////////////////////////////////////////// |
554 | 557 |
555 class SkDistantLight : public SkLight { | 558 class SkDistantLight : public SkLight { |
| 559 typedef SkLight INHERITED; |
| 560 |
556 public: | 561 public: |
557 SkDistantLight(const SkPoint3& direction, SkColor color) | 562 SkDistantLight(const SkPoint3& direction, SkColor color) |
558 : INHERITED(color), fDirection(direction) { | 563 : INHERITED(color), fDirection(direction) { |
559 } | 564 } |
560 | 565 |
561 SkPoint3 surfaceToLight(int x, int y, int z, SkScalar surfaceScale) const { | 566 SkPoint3 surfaceToLight(int x, int y, int z, SkScalar surfaceScale) const { |
562 return fDirection; | 567 return fDirection; |
563 }; | 568 }; |
564 SkPoint3 lightColor(const SkPoint3&) const { return color(); } | 569 SkPoint3 lightColor(const SkPoint3&) const { return color(); } |
565 virtual LightType type() const { return kDistant_LightType; } | 570 virtual LightType type() const { return kDistant_LightType; } |
(...skipping 29 matching lines...) Expand all Loading... |
595 } | 600 } |
596 virtual SkLight* transform(const SkMatrix& matrix) const { | 601 virtual SkLight* transform(const SkMatrix& matrix) const { |
597 return new SkDistantLight(direction(), color()); | 602 return new SkDistantLight(direction(), color()); |
598 } | 603 } |
599 virtual void flatten(SkFlattenableWriteBuffer& buffer) const { | 604 virtual void flatten(SkFlattenableWriteBuffer& buffer) const { |
600 INHERITED::flatten(buffer); | 605 INHERITED::flatten(buffer); |
601 writePoint3(fDirection, buffer); | 606 writePoint3(fDirection, buffer); |
602 } | 607 } |
603 | 608 |
604 private: | 609 private: |
605 typedef SkLight INHERITED; | |
606 SkPoint3 fDirection; | 610 SkPoint3 fDirection; |
607 }; | 611 }; |
608 | 612 |
609 /////////////////////////////////////////////////////////////////////////////// | 613 /////////////////////////////////////////////////////////////////////////////// |
610 | 614 |
611 class SkPointLight : public SkLight { | 615 class SkPointLight : public SkLight { |
| 616 typedef SkLight INHERITED; |
| 617 |
612 public: | 618 public: |
613 SkPointLight(const SkPoint3& location, SkColor color) | 619 SkPointLight(const SkPoint3& location, SkColor color) |
614 : INHERITED(color), fLocation(location) {} | 620 : INHERITED(color), fLocation(location) {} |
615 | 621 |
616 SkPoint3 surfaceToLight(int x, int y, int z, SkScalar surfaceScale) const { | 622 SkPoint3 surfaceToLight(int x, int y, int z, SkScalar surfaceScale) const { |
617 SkPoint3 direction(fLocation.fX - SkIntToScalar(x), | 623 SkPoint3 direction(fLocation.fX - SkIntToScalar(x), |
618 fLocation.fY - SkIntToScalar(y), | 624 fLocation.fY - SkIntToScalar(y), |
619 fLocation.fZ - SkScalarMul(SkIntToScalar(z), surfaceS
cale)); | 625 fLocation.fZ - SkScalarMul(SkIntToScalar(z), surfaceS
cale)); |
620 direction.normalize(); | 626 direction.normalize(); |
621 return direction; | 627 return direction; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
654 fLocation = readPoint3(buffer); | 660 fLocation = readPoint3(buffer); |
655 } | 661 } |
656 SkPointLight(const SkPoint3& location, const SkPoint3& color) | 662 SkPointLight(const SkPoint3& location, const SkPoint3& color) |
657 : INHERITED(color), fLocation(location) {} | 663 : INHERITED(color), fLocation(location) {} |
658 virtual void flatten(SkFlattenableWriteBuffer& buffer) const { | 664 virtual void flatten(SkFlattenableWriteBuffer& buffer) const { |
659 INHERITED::flatten(buffer); | 665 INHERITED::flatten(buffer); |
660 writePoint3(fLocation, buffer); | 666 writePoint3(fLocation, buffer); |
661 } | 667 } |
662 | 668 |
663 private: | 669 private: |
664 typedef SkLight INHERITED; | |
665 SkPoint3 fLocation; | 670 SkPoint3 fLocation; |
666 }; | 671 }; |
667 | 672 |
668 /////////////////////////////////////////////////////////////////////////////// | 673 /////////////////////////////////////////////////////////////////////////////// |
669 | 674 |
670 class SkSpotLight : public SkLight { | 675 class SkSpotLight : public SkLight { |
| 676 typedef SkLight INHERITED; |
| 677 |
671 public: | 678 public: |
672 SkSpotLight(const SkPoint3& location, const SkPoint3& target, SkScalar specu
larExponent, SkScalar cutoffAngle, SkColor color) | 679 SkSpotLight(const SkPoint3& location, const SkPoint3& target, SkScalar specu
larExponent, SkScalar cutoffAngle, SkColor color) |
673 : INHERITED(color), | 680 : INHERITED(color), |
674 fLocation(location), | 681 fLocation(location), |
675 fTarget(target), | 682 fTarget(target), |
676 fSpecularExponent(SkScalarPin(specularExponent, kSpecularExponentMin, kSp
ecularExponentMax)) | 683 fSpecularExponent(SkScalarPin(specularExponent, kSpecularExponentMin, kSp
ecularExponentMax)) |
677 { | 684 { |
678 fS = target - location; | 685 fS = target - location; |
679 fS.normalize(); | 686 fS.normalize(); |
680 fCosOuterConeAngle = SkScalarCos(SkDegreesToRadians(cutoffAngle)); | 687 fCosOuterConeAngle = SkScalarCos(SkDegreesToRadians(cutoffAngle)); |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
774 fLocation == o.fLocation && | 781 fLocation == o.fLocation && |
775 fTarget == o.fTarget && | 782 fTarget == o.fTarget && |
776 fSpecularExponent == o.fSpecularExponent && | 783 fSpecularExponent == o.fSpecularExponent && |
777 fCosOuterConeAngle == o.fCosOuterConeAngle; | 784 fCosOuterConeAngle == o.fCosOuterConeAngle; |
778 } | 785 } |
779 | 786 |
780 private: | 787 private: |
781 static const SkScalar kSpecularExponentMin; | 788 static const SkScalar kSpecularExponentMin; |
782 static const SkScalar kSpecularExponentMax; | 789 static const SkScalar kSpecularExponentMax; |
783 | 790 |
784 typedef SkLight INHERITED; | |
785 SkPoint3 fLocation; | 791 SkPoint3 fLocation; |
786 SkPoint3 fTarget; | 792 SkPoint3 fTarget; |
787 SkScalar fSpecularExponent; | 793 SkScalar fSpecularExponent; |
788 SkScalar fCosOuterConeAngle; | 794 SkScalar fCosOuterConeAngle; |
789 SkScalar fCosInnerConeAngle; | 795 SkScalar fCosInnerConeAngle; |
790 SkScalar fConeScale; | 796 SkScalar fConeScale; |
791 SkPoint3 fS; | 797 SkPoint3 fS; |
792 }; | 798 }; |
793 | 799 |
794 // According to the spec, the specular term should be in the range [1, 128] : | 800 // According to the spec, the specular term should be in the range [1, 128] : |
(...skipping 777 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1572 | 1578 |
1573 #endif | 1579 #endif |
1574 | 1580 |
1575 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingImageFilter) | 1581 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingImageFilter) |
1576 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDiffuseLightingImageFilter) | 1582 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDiffuseLightingImageFilter) |
1577 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSpecularLightingImageFilter) | 1583 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSpecularLightingImageFilter) |
1578 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDistantLight) | 1584 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDistantLight) |
1579 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkPointLight) | 1585 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkPointLight) |
1580 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSpotLight) | 1586 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSpotLight) |
1581 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END | 1587 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END |
OLD | NEW |