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 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 const CropRect*, uint32_t uniqueID = 0); | 283 const CropRect*, uint32_t uniqueID = 0); |
284 | 284 |
285 SK_TO_STRING_OVERRIDE() | 285 SK_TO_STRING_OVERRIDE() |
286 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkDiffuseLightingImageFi
lter) | 286 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkDiffuseLightingImageFi
lter) |
287 SkScalar kd() const { return fKD; } | 287 SkScalar kd() const { return fKD; } |
288 | 288 |
289 protected: | 289 protected: |
290 SkDiffuseLightingImageFilter(SkLight* light, SkScalar surfaceScale, | 290 SkDiffuseLightingImageFilter(SkLight* light, SkScalar surfaceScale, |
291 SkScalar kd, SkImageFilter* input, const CropRe
ct* cropRect, | 291 SkScalar kd, SkImageFilter* input, const CropRe
ct* cropRect, |
292 uint32_t uniqueID); | 292 uint32_t uniqueID); |
293 virtual void flatten(SkWriteBuffer& buffer) const SK_OVERRIDE; | 293 void flatten(SkWriteBuffer& buffer) const SK_OVERRIDE; |
294 virtual bool onFilterImage(Proxy*, const SkBitmap& src, const Context&, | 294 virtual bool onFilterImage(Proxy*, const SkBitmap& src, const Context&, |
295 SkBitmap* result, SkIPoint* offset) const SK_OVER
RIDE; | 295 SkBitmap* result, SkIPoint* offset) const SK_OVER
RIDE; |
296 #if SK_SUPPORT_GPU | 296 #if SK_SUPPORT_GPU |
297 virtual bool asFragmentProcessor(GrFragmentProcessor**, GrTexture*, const Sk
Matrix&, | 297 virtual bool asFragmentProcessor(GrFragmentProcessor**, GrTexture*, const Sk
Matrix&, |
298 const SkIRect& bounds) const SK_OVERRIDE; | 298 const SkIRect& bounds) const SK_OVERRIDE; |
299 #endif | 299 #endif |
300 | 300 |
301 private: | 301 private: |
302 friend class SkLightingImageFilter; | 302 friend class SkLightingImageFilter; |
303 typedef SkLightingImageFilter INHERITED; | 303 typedef SkLightingImageFilter INHERITED; |
304 SkScalar fKD; | 304 SkScalar fKD; |
305 }; | 305 }; |
306 | 306 |
307 class SkSpecularLightingImageFilter : public SkLightingImageFilter { | 307 class SkSpecularLightingImageFilter : public SkLightingImageFilter { |
308 public: | 308 public: |
309 static SkImageFilter* Create(SkLight* light, SkScalar surfaceScale, | 309 static SkImageFilter* Create(SkLight* light, SkScalar surfaceScale, |
310 SkScalar ks, SkScalar shininess, SkImageFilter*
, const CropRect*, | 310 SkScalar ks, SkScalar shininess, SkImageFilter*
, const CropRect*, |
311 uint32_t uniqueID = 0); | 311 uint32_t uniqueID = 0); |
312 | 312 |
313 SK_TO_STRING_OVERRIDE() | 313 SK_TO_STRING_OVERRIDE() |
314 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkSpecularLightingImageF
ilter) | 314 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkSpecularLightingImageF
ilter) |
315 | 315 |
316 SkScalar ks() const { return fKS; } | 316 SkScalar ks() const { return fKS; } |
317 SkScalar shininess() const { return fShininess; } | 317 SkScalar shininess() const { return fShininess; } |
318 | 318 |
319 protected: | 319 protected: |
320 SkSpecularLightingImageFilter(SkLight* light, SkScalar surfaceScale, SkScala
r ks, | 320 SkSpecularLightingImageFilter(SkLight* light, SkScalar surfaceScale, SkScala
r ks, |
321 SkScalar shininess, SkImageFilter* input, cons
t CropRect*, | 321 SkScalar shininess, SkImageFilter* input, cons
t CropRect*, |
322 uint32_t uniqueID); | 322 uint32_t uniqueID); |
323 virtual void flatten(SkWriteBuffer& buffer) const SK_OVERRIDE; | 323 void flatten(SkWriteBuffer& buffer) const SK_OVERRIDE; |
324 virtual bool onFilterImage(Proxy*, const SkBitmap& src, const Context&, | 324 virtual bool onFilterImage(Proxy*, const SkBitmap& src, const Context&, |
325 SkBitmap* result, SkIPoint* offset) const SK_OVER
RIDE; | 325 SkBitmap* result, SkIPoint* offset) const SK_OVER
RIDE; |
326 #if SK_SUPPORT_GPU | 326 #if SK_SUPPORT_GPU |
327 virtual bool asFragmentProcessor(GrFragmentProcessor**, GrTexture*, const Sk
Matrix&, | 327 virtual bool asFragmentProcessor(GrFragmentProcessor**, GrTexture*, const Sk
Matrix&, |
328 const SkIRect& bounds) const SK_OVERRIDE; | 328 const SkIRect& bounds) const SK_OVERRIDE; |
329 #endif | 329 #endif |
330 | 330 |
331 private: | 331 private: |
332 SkScalar fKS; | 332 SkScalar fKS; |
333 SkScalar fShininess; | 333 SkScalar fShininess; |
334 friend class SkLightingImageFilter; | 334 friend class SkLightingImageFilter; |
335 typedef SkLightingImageFilter INHERITED; | 335 typedef SkLightingImageFilter INHERITED; |
336 }; | 336 }; |
337 | 337 |
338 #if SK_SUPPORT_GPU | 338 #if SK_SUPPORT_GPU |
339 | 339 |
340 class GrLightingEffect : public GrSingleTextureEffect { | 340 class GrLightingEffect : public GrSingleTextureEffect { |
341 public: | 341 public: |
342 GrLightingEffect(GrTexture* texture, const SkLight* light, SkScalar surfaceS
cale, const SkMatrix& matrix); | 342 GrLightingEffect(GrTexture* texture, const SkLight* light, SkScalar surfaceS
cale, const SkMatrix& matrix); |
343 virtual ~GrLightingEffect(); | 343 virtual ~GrLightingEffect(); |
344 | 344 |
345 const SkLight* light() const { return fLight; } | 345 const SkLight* light() const { return fLight; } |
346 SkScalar surfaceScale() const { return fSurfaceScale; } | 346 SkScalar surfaceScale() const { return fSurfaceScale; } |
347 const SkMatrix& filterMatrix() const { return fFilterMatrix; } | 347 const SkMatrix& filterMatrix() const { return fFilterMatrix; } |
348 | 348 |
349 protected: | 349 protected: |
350 virtual bool onIsEqual(const GrFragmentProcessor&) const SK_OVERRIDE; | 350 bool onIsEqual(const GrFragmentProcessor&) const SK_OVERRIDE; |
351 | 351 |
352 virtual void onComputeInvariantOutput(GrInvariantOutput* inout) const SK_OVE
RRIDE { | 352 void onComputeInvariantOutput(GrInvariantOutput* inout) const SK_OVERRIDE { |
353 // lighting shaders are complicated. We just throw up our hands. | 353 // lighting shaders are complicated. We just throw up our hands. |
354 inout->mulByUnknownFourComponents(); | 354 inout->mulByUnknownFourComponents(); |
355 } | 355 } |
356 | 356 |
357 private: | 357 private: |
358 typedef GrSingleTextureEffect INHERITED; | 358 typedef GrSingleTextureEffect INHERITED; |
359 const SkLight* fLight; | 359 const SkLight* fLight; |
360 SkScalar fSurfaceScale; | 360 SkScalar fSurfaceScale; |
361 SkMatrix fFilterMatrix; | 361 SkMatrix fFilterMatrix; |
362 }; | 362 }; |
363 | 363 |
364 class GrDiffuseLightingEffect : public GrLightingEffect { | 364 class GrDiffuseLightingEffect : public GrLightingEffect { |
365 public: | 365 public: |
366 static GrFragmentProcessor* Create(GrTexture* texture, | 366 static GrFragmentProcessor* Create(GrTexture* texture, |
367 const SkLight* light, | 367 const SkLight* light, |
368 SkScalar surfaceScale, | 368 SkScalar surfaceScale, |
369 const SkMatrix& matrix, | 369 const SkMatrix& matrix, |
370 SkScalar kd) { | 370 SkScalar kd) { |
371 return SkNEW_ARGS(GrDiffuseLightingEffect, (texture, | 371 return SkNEW_ARGS(GrDiffuseLightingEffect, (texture, |
372 light, | 372 light, |
373 surfaceScale, | 373 surfaceScale, |
374 matrix, | 374 matrix, |
375 kd)); | 375 kd)); |
376 } | 376 } |
377 | 377 |
378 virtual const char* name() const SK_OVERRIDE { return "DiffuseLighting"; } | 378 const char* name() const SK_OVERRIDE { return "DiffuseLighting"; } |
379 | 379 |
380 virtual void getGLProcessorKey(const GrGLCaps&, GrProcessorKeyBuilder*) cons
t SK_OVERRIDE; | 380 void getGLProcessorKey(const GrGLCaps&, GrProcessorKeyBuilder*) const SK_OVE
RRIDE; |
381 | 381 |
382 virtual GrGLFragmentProcessor* createGLInstance() const SK_OVERRIDE; | 382 GrGLFragmentProcessor* createGLInstance() const SK_OVERRIDE; |
383 | 383 |
384 SkScalar kd() const { return fKD; } | 384 SkScalar kd() const { return fKD; } |
385 | 385 |
386 private: | 386 private: |
387 virtual bool onIsEqual(const GrFragmentProcessor&) const SK_OVERRIDE; | 387 bool onIsEqual(const GrFragmentProcessor&) const SK_OVERRIDE; |
388 | 388 |
389 GrDiffuseLightingEffect(GrTexture* texture, | 389 GrDiffuseLightingEffect(GrTexture* texture, |
390 const SkLight* light, | 390 const SkLight* light, |
391 SkScalar surfaceScale, | 391 SkScalar surfaceScale, |
392 const SkMatrix& matrix, | 392 const SkMatrix& matrix, |
393 SkScalar kd); | 393 SkScalar kd); |
394 | 394 |
395 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; | 395 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; |
396 typedef GrLightingEffect INHERITED; | 396 typedef GrLightingEffect INHERITED; |
397 SkScalar fKD; | 397 SkScalar fKD; |
398 }; | 398 }; |
399 | 399 |
400 class GrSpecularLightingEffect : public GrLightingEffect { | 400 class GrSpecularLightingEffect : public GrLightingEffect { |
401 public: | 401 public: |
402 static GrFragmentProcessor* Create(GrTexture* texture, | 402 static GrFragmentProcessor* Create(GrTexture* texture, |
403 const SkLight* light, | 403 const SkLight* light, |
404 SkScalar surfaceScale, | 404 SkScalar surfaceScale, |
405 const SkMatrix& matrix, | 405 const SkMatrix& matrix, |
406 SkScalar ks, | 406 SkScalar ks, |
407 SkScalar shininess) { | 407 SkScalar shininess) { |
408 return SkNEW_ARGS(GrSpecularLightingEffect, (texture, | 408 return SkNEW_ARGS(GrSpecularLightingEffect, (texture, |
409 light, | 409 light, |
410 surfaceScale, | 410 surfaceScale, |
411 matrix, | 411 matrix, |
412 ks, | 412 ks, |
413 shininess)); | 413 shininess)); |
414 } | 414 } |
415 | 415 |
416 virtual const char* name() const SK_OVERRIDE { return "SpecularLighting"; } | 416 const char* name() const SK_OVERRIDE { return "SpecularLighting"; } |
417 | 417 |
418 virtual void getGLProcessorKey(const GrGLCaps&, GrProcessorKeyBuilder*) cons
t SK_OVERRIDE; | 418 void getGLProcessorKey(const GrGLCaps&, GrProcessorKeyBuilder*) const SK_OVE
RRIDE; |
419 | 419 |
420 virtual GrGLFragmentProcessor* createGLInstance() const SK_OVERRIDE; | 420 GrGLFragmentProcessor* createGLInstance() const SK_OVERRIDE; |
421 | 421 |
422 SkScalar ks() const { return fKS; } | 422 SkScalar ks() const { return fKS; } |
423 SkScalar shininess() const { return fShininess; } | 423 SkScalar shininess() const { return fShininess; } |
424 | 424 |
425 private: | 425 private: |
426 virtual bool onIsEqual(const GrFragmentProcessor&) const SK_OVERRIDE; | 426 bool onIsEqual(const GrFragmentProcessor&) const SK_OVERRIDE; |
427 | 427 |
428 GrSpecularLightingEffect(GrTexture* texture, | 428 GrSpecularLightingEffect(GrTexture* texture, |
429 const SkLight* light, | 429 const SkLight* light, |
430 SkScalar surfaceScale, | 430 SkScalar surfaceScale, |
431 const SkMatrix& matrix, | 431 const SkMatrix& matrix, |
432 SkScalar ks, | 432 SkScalar ks, |
433 SkScalar shininess); | 433 SkScalar shininess); |
434 | 434 |
435 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; | 435 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; |
436 typedef GrLightingEffect INHERITED; | 436 typedef GrLightingEffect INHERITED; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
479 typedef SkRefCnt INHERITED; | 479 typedef SkRefCnt INHERITED; |
480 }; | 480 }; |
481 | 481 |
482 /////////////////////////////////////////////////////////////////////////////// | 482 /////////////////////////////////////////////////////////////////////////////// |
483 | 483 |
484 class GrGLDistantLight : public GrGLLight { | 484 class GrGLDistantLight : public GrGLLight { |
485 public: | 485 public: |
486 virtual ~GrGLDistantLight() {} | 486 virtual ~GrGLDistantLight() {} |
487 virtual void setData(const GrGLProgramDataManager&, | 487 virtual void setData(const GrGLProgramDataManager&, |
488 const SkLight* light) const SK_OVERRIDE; | 488 const SkLight* light) const SK_OVERRIDE; |
489 virtual void emitSurfaceToLight(GrGLFPBuilder*, const char* z) SK_OVERRIDE; | 489 void emitSurfaceToLight(GrGLFPBuilder*, const char* z) SK_OVERRIDE; |
490 | 490 |
491 private: | 491 private: |
492 typedef GrGLLight INHERITED; | 492 typedef GrGLLight INHERITED; |
493 UniformHandle fDirectionUni; | 493 UniformHandle fDirectionUni; |
494 }; | 494 }; |
495 | 495 |
496 /////////////////////////////////////////////////////////////////////////////// | 496 /////////////////////////////////////////////////////////////////////////////// |
497 | 497 |
498 class GrGLPointLight : public GrGLLight { | 498 class GrGLPointLight : public GrGLLight { |
499 public: | 499 public: |
500 virtual ~GrGLPointLight() {} | 500 virtual ~GrGLPointLight() {} |
501 virtual void setData(const GrGLProgramDataManager&, | 501 virtual void setData(const GrGLProgramDataManager&, |
502 const SkLight* light) const SK_OVERRIDE; | 502 const SkLight* light) const SK_OVERRIDE; |
503 virtual void emitSurfaceToLight(GrGLFPBuilder*, const char* z) SK_OVERRIDE; | 503 void emitSurfaceToLight(GrGLFPBuilder*, const char* z) SK_OVERRIDE; |
504 | 504 |
505 private: | 505 private: |
506 typedef GrGLLight INHERITED; | 506 typedef GrGLLight INHERITED; |
507 UniformHandle fLocationUni; | 507 UniformHandle fLocationUni; |
508 }; | 508 }; |
509 | 509 |
510 /////////////////////////////////////////////////////////////////////////////// | 510 /////////////////////////////////////////////////////////////////////////////// |
511 | 511 |
512 class GrGLSpotLight : public GrGLLight { | 512 class GrGLSpotLight : public GrGLLight { |
513 public: | 513 public: |
514 virtual ~GrGLSpotLight() {} | 514 virtual ~GrGLSpotLight() {} |
515 virtual void setData(const GrGLProgramDataManager&, | 515 virtual void setData(const GrGLProgramDataManager&, |
516 const SkLight* light) const SK_OVERRIDE; | 516 const SkLight* light) const SK_OVERRIDE; |
517 virtual void emitSurfaceToLight(GrGLFPBuilder*, const char* z) SK_OVERRIDE; | 517 void emitSurfaceToLight(GrGLFPBuilder*, const char* z) SK_OVERRIDE; |
518 virtual void emitLightColor(GrGLFPBuilder*, const char *surfaceToLight) SK_O
VERRIDE; | 518 void emitLightColor(GrGLFPBuilder*, const char *surfaceToLight) SK_OVERRIDE; |
519 | 519 |
520 private: | 520 private: |
521 typedef GrGLLight INHERITED; | 521 typedef GrGLLight INHERITED; |
522 | 522 |
523 SkString fLightColorFunc; | 523 SkString fLightColorFunc; |
524 UniformHandle fLocationUni; | 524 UniformHandle fLocationUni; |
525 UniformHandle fExponentUni; | 525 UniformHandle fExponentUni; |
526 UniformHandle fCosOuterConeAngleUni; | 526 UniformHandle fCosOuterConeAngleUni; |
527 UniformHandle fCosInnerConeAngleUni; | 527 UniformHandle fCosInnerConeAngleUni; |
528 UniformHandle fConeScaleUni; | 528 UniformHandle fConeScaleUni; |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
585 class SkDistantLight : public SkLight { | 585 class SkDistantLight : public SkLight { |
586 public: | 586 public: |
587 SkDistantLight(const SkPoint3& direction, SkColor color) | 587 SkDistantLight(const SkPoint3& direction, SkColor color) |
588 : INHERITED(color), fDirection(direction) { | 588 : INHERITED(color), fDirection(direction) { |
589 } | 589 } |
590 | 590 |
591 SkPoint3 surfaceToLight(int x, int y, int z, SkScalar surfaceScale) const { | 591 SkPoint3 surfaceToLight(int x, int y, int z, SkScalar surfaceScale) const { |
592 return fDirection; | 592 return fDirection; |
593 }; | 593 }; |
594 SkPoint3 lightColor(const SkPoint3&) const { return color(); } | 594 SkPoint3 lightColor(const SkPoint3&) const { return color(); } |
595 virtual LightType type() const SK_OVERRIDE { return kDistant_LightType; } | 595 LightType type() const SK_OVERRIDE { return kDistant_LightType; } |
596 const SkPoint3& direction() const { return fDirection; } | 596 const SkPoint3& direction() const { return fDirection; } |
597 virtual GrGLLight* createGLLight() const SK_OVERRIDE { | 597 GrGLLight* createGLLight() const SK_OVERRIDE { |
598 #if SK_SUPPORT_GPU | 598 #if SK_SUPPORT_GPU |
599 return SkNEW(GrGLDistantLight); | 599 return SkNEW(GrGLDistantLight); |
600 #else | 600 #else |
601 SkDEBUGFAIL("Should not call in GPU-less build"); | 601 SkDEBUGFAIL("Should not call in GPU-less build"); |
602 return NULL; | 602 return NULL; |
603 #endif | 603 #endif |
604 } | 604 } |
605 virtual bool requiresFragmentPosition() const SK_OVERRIDE { return false; } | 605 bool requiresFragmentPosition() const SK_OVERRIDE { return false; } |
606 | 606 |
607 virtual bool isEqual(const SkLight& other) const SK_OVERRIDE { | 607 bool isEqual(const SkLight& other) const SK_OVERRIDE { |
608 if (other.type() != kDistant_LightType) { | 608 if (other.type() != kDistant_LightType) { |
609 return false; | 609 return false; |
610 } | 610 } |
611 | 611 |
612 const SkDistantLight& o = static_cast<const SkDistantLight&>(other); | 612 const SkDistantLight& o = static_cast<const SkDistantLight&>(other); |
613 return INHERITED::isEqual(other) && | 613 return INHERITED::isEqual(other) && |
614 fDirection == o.fDirection; | 614 fDirection == o.fDirection; |
615 } | 615 } |
616 | 616 |
617 SkDistantLight(SkReadBuffer& buffer) : INHERITED(buffer) { | 617 SkDistantLight(SkReadBuffer& buffer) : INHERITED(buffer) { |
618 fDirection = readPoint3(buffer); | 618 fDirection = readPoint3(buffer); |
619 } | 619 } |
620 | 620 |
621 protected: | 621 protected: |
622 SkDistantLight(const SkPoint3& direction, const SkPoint3& color) | 622 SkDistantLight(const SkPoint3& direction, const SkPoint3& color) |
623 : INHERITED(color), fDirection(direction) { | 623 : INHERITED(color), fDirection(direction) { |
624 } | 624 } |
625 virtual SkLight* transform(const SkMatrix& matrix) const SK_OVERRIDE { | 625 SkLight* transform(const SkMatrix& matrix) const SK_OVERRIDE { |
626 return new SkDistantLight(direction(), color()); | 626 return new SkDistantLight(direction(), color()); |
627 } | 627 } |
628 virtual void onFlattenLight(SkWriteBuffer& buffer) const SK_OVERRIDE { | 628 void onFlattenLight(SkWriteBuffer& buffer) const SK_OVERRIDE { |
629 writePoint3(fDirection, buffer); | 629 writePoint3(fDirection, buffer); |
630 } | 630 } |
631 | 631 |
632 private: | 632 private: |
633 typedef SkLight INHERITED; | 633 typedef SkLight INHERITED; |
634 SkPoint3 fDirection; | 634 SkPoint3 fDirection; |
635 }; | 635 }; |
636 | 636 |
637 /////////////////////////////////////////////////////////////////////////////// | 637 /////////////////////////////////////////////////////////////////////////////// |
638 | 638 |
639 class SkPointLight : public SkLight { | 639 class SkPointLight : public SkLight { |
640 public: | 640 public: |
641 SkPointLight(const SkPoint3& location, SkColor color) | 641 SkPointLight(const SkPoint3& location, SkColor color) |
642 : INHERITED(color), fLocation(location) {} | 642 : INHERITED(color), fLocation(location) {} |
643 | 643 |
644 SkPoint3 surfaceToLight(int x, int y, int z, SkScalar surfaceScale) const { | 644 SkPoint3 surfaceToLight(int x, int y, int z, SkScalar surfaceScale) const { |
645 SkPoint3 direction(fLocation.fX - SkIntToScalar(x), | 645 SkPoint3 direction(fLocation.fX - SkIntToScalar(x), |
646 fLocation.fY - SkIntToScalar(y), | 646 fLocation.fY - SkIntToScalar(y), |
647 fLocation.fZ - SkScalarMul(SkIntToScalar(z), surfaceS
cale)); | 647 fLocation.fZ - SkScalarMul(SkIntToScalar(z), surfaceS
cale)); |
648 direction.normalize(); | 648 direction.normalize(); |
649 return direction; | 649 return direction; |
650 }; | 650 }; |
651 SkPoint3 lightColor(const SkPoint3&) const { return color(); } | 651 SkPoint3 lightColor(const SkPoint3&) const { return color(); } |
652 virtual LightType type() const SK_OVERRIDE { return kPoint_LightType; } | 652 LightType type() const SK_OVERRIDE { return kPoint_LightType; } |
653 const SkPoint3& location() const { return fLocation; } | 653 const SkPoint3& location() const { return fLocation; } |
654 virtual GrGLLight* createGLLight() const SK_OVERRIDE { | 654 GrGLLight* createGLLight() const SK_OVERRIDE { |
655 #if SK_SUPPORT_GPU | 655 #if SK_SUPPORT_GPU |
656 return SkNEW(GrGLPointLight); | 656 return SkNEW(GrGLPointLight); |
657 #else | 657 #else |
658 SkDEBUGFAIL("Should not call in GPU-less build"); | 658 SkDEBUGFAIL("Should not call in GPU-less build"); |
659 return NULL; | 659 return NULL; |
660 #endif | 660 #endif |
661 } | 661 } |
662 virtual bool requiresFragmentPosition() const SK_OVERRIDE { return true; } | 662 bool requiresFragmentPosition() const SK_OVERRIDE { return true; } |
663 virtual bool isEqual(const SkLight& other) const SK_OVERRIDE { | 663 bool isEqual(const SkLight& other) const SK_OVERRIDE { |
664 if (other.type() != kPoint_LightType) { | 664 if (other.type() != kPoint_LightType) { |
665 return false; | 665 return false; |
666 } | 666 } |
667 const SkPointLight& o = static_cast<const SkPointLight&>(other); | 667 const SkPointLight& o = static_cast<const SkPointLight&>(other); |
668 return INHERITED::isEqual(other) && | 668 return INHERITED::isEqual(other) && |
669 fLocation == o.fLocation; | 669 fLocation == o.fLocation; |
670 } | 670 } |
671 virtual SkLight* transform(const SkMatrix& matrix) const SK_OVERRIDE { | 671 SkLight* transform(const SkMatrix& matrix) const SK_OVERRIDE { |
672 SkPoint location2 = SkPoint::Make(fLocation.fX, fLocation.fY); | 672 SkPoint location2 = SkPoint::Make(fLocation.fX, fLocation.fY); |
673 matrix.mapPoints(&location2, 1); | 673 matrix.mapPoints(&location2, 1); |
674 // Use X scale and Y scale on Z and average the result | 674 // Use X scale and Y scale on Z and average the result |
675 SkPoint locationZ = SkPoint::Make(fLocation.fZ, fLocation.fZ); | 675 SkPoint locationZ = SkPoint::Make(fLocation.fZ, fLocation.fZ); |
676 matrix.mapVectors(&locationZ, 1); | 676 matrix.mapVectors(&locationZ, 1); |
677 SkPoint3 location(location2.fX, location2.fY, SkScalarAve(locationZ.fX,
locationZ.fY)); | 677 SkPoint3 location(location2.fX, location2.fY, SkScalarAve(locationZ.fX,
locationZ.fY)); |
678 return new SkPointLight(location, color()); | 678 return new SkPointLight(location, color()); |
679 } | 679 } |
680 | 680 |
681 SkPointLight(SkReadBuffer& buffer) : INHERITED(buffer) { | 681 SkPointLight(SkReadBuffer& buffer) : INHERITED(buffer) { |
682 fLocation = readPoint3(buffer); | 682 fLocation = readPoint3(buffer); |
683 } | 683 } |
684 | 684 |
685 protected: | 685 protected: |
686 SkPointLight(const SkPoint3& location, const SkPoint3& color) | 686 SkPointLight(const SkPoint3& location, const SkPoint3& color) |
687 : INHERITED(color), fLocation(location) {} | 687 : INHERITED(color), fLocation(location) {} |
688 virtual void onFlattenLight(SkWriteBuffer& buffer) const SK_OVERRIDE { | 688 void onFlattenLight(SkWriteBuffer& buffer) const SK_OVERRIDE { |
689 writePoint3(fLocation, buffer); | 689 writePoint3(fLocation, buffer); |
690 } | 690 } |
691 | 691 |
692 private: | 692 private: |
693 typedef SkLight INHERITED; | 693 typedef SkLight INHERITED; |
694 SkPoint3 fLocation; | 694 SkPoint3 fLocation; |
695 }; | 695 }; |
696 | 696 |
697 /////////////////////////////////////////////////////////////////////////////// | 697 /////////////////////////////////////////////////////////////////////////////// |
698 | 698 |
699 class SkSpotLight : public SkLight { | 699 class SkSpotLight : public SkLight { |
700 public: | 700 public: |
701 SkSpotLight(const SkPoint3& location, const SkPoint3& target, SkScalar specu
larExponent, SkScalar cutoffAngle, SkColor color) | 701 SkSpotLight(const SkPoint3& location, const SkPoint3& target, SkScalar specu
larExponent, SkScalar cutoffAngle, SkColor color) |
702 : INHERITED(color), | 702 : INHERITED(color), |
703 fLocation(location), | 703 fLocation(location), |
704 fTarget(target), | 704 fTarget(target), |
705 fSpecularExponent(SkScalarPin(specularExponent, kSpecularExponentMin, kSp
ecularExponentMax)) | 705 fSpecularExponent(SkScalarPin(specularExponent, kSpecularExponentMin, kSp
ecularExponentMax)) |
706 { | 706 { |
707 fS = target - location; | 707 fS = target - location; |
708 fS.normalize(); | 708 fS.normalize(); |
709 fCosOuterConeAngle = SkScalarCos(SkDegreesToRadians(cutoffAngle)); | 709 fCosOuterConeAngle = SkScalarCos(SkDegreesToRadians(cutoffAngle)); |
710 const SkScalar antiAliasThreshold = 0.016f; | 710 const SkScalar antiAliasThreshold = 0.016f; |
711 fCosInnerConeAngle = fCosOuterConeAngle + antiAliasThreshold; | 711 fCosInnerConeAngle = fCosOuterConeAngle + antiAliasThreshold; |
712 fConeScale = SkScalarInvert(antiAliasThreshold); | 712 fConeScale = SkScalarInvert(antiAliasThreshold); |
713 } | 713 } |
714 | 714 |
715 virtual SkLight* transform(const SkMatrix& matrix) const SK_OVERRIDE { | 715 SkLight* transform(const SkMatrix& matrix) const SK_OVERRIDE { |
716 SkPoint location2 = SkPoint::Make(fLocation.fX, fLocation.fY); | 716 SkPoint location2 = SkPoint::Make(fLocation.fX, fLocation.fY); |
717 matrix.mapPoints(&location2, 1); | 717 matrix.mapPoints(&location2, 1); |
718 // Use X scale and Y scale on Z and average the result | 718 // Use X scale and Y scale on Z and average the result |
719 SkPoint locationZ = SkPoint::Make(fLocation.fZ, fLocation.fZ); | 719 SkPoint locationZ = SkPoint::Make(fLocation.fZ, fLocation.fZ); |
720 matrix.mapVectors(&locationZ, 1); | 720 matrix.mapVectors(&locationZ, 1); |
721 SkPoint3 location(location2.fX, location2.fY, SkScalarAve(locationZ.fX,
locationZ.fY)); | 721 SkPoint3 location(location2.fX, location2.fY, SkScalarAve(locationZ.fX,
locationZ.fY)); |
722 SkPoint target2 = SkPoint::Make(fTarget.fX, fTarget.fY); | 722 SkPoint target2 = SkPoint::Make(fTarget.fX, fTarget.fY); |
723 matrix.mapPoints(&target2, 1); | 723 matrix.mapPoints(&target2, 1); |
724 SkPoint targetZ = SkPoint::Make(fTarget.fZ, fTarget.fZ); | 724 SkPoint targetZ = SkPoint::Make(fTarget.fZ, fTarget.fZ); |
725 matrix.mapVectors(&targetZ, 1); | 725 matrix.mapVectors(&targetZ, 1); |
(...skipping 15 matching lines...) Expand all Loading... |
741 if (cosAngle < fCosOuterConeAngle) { | 741 if (cosAngle < fCosOuterConeAngle) { |
742 return SkPoint3(0, 0, 0); | 742 return SkPoint3(0, 0, 0); |
743 } | 743 } |
744 SkScalar scale = SkScalarPow(cosAngle, fSpecularExponent); | 744 SkScalar scale = SkScalarPow(cosAngle, fSpecularExponent); |
745 if (cosAngle < fCosInnerConeAngle) { | 745 if (cosAngle < fCosInnerConeAngle) { |
746 scale = SkScalarMul(scale, cosAngle - fCosOuterConeAngle); | 746 scale = SkScalarMul(scale, cosAngle - fCosOuterConeAngle); |
747 return color() * SkScalarMul(scale, fConeScale); | 747 return color() * SkScalarMul(scale, fConeScale); |
748 } | 748 } |
749 return color() * scale; | 749 return color() * scale; |
750 } | 750 } |
751 virtual GrGLLight* createGLLight() const SK_OVERRIDE { | 751 GrGLLight* createGLLight() const SK_OVERRIDE { |
752 #if SK_SUPPORT_GPU | 752 #if SK_SUPPORT_GPU |
753 return SkNEW(GrGLSpotLight); | 753 return SkNEW(GrGLSpotLight); |
754 #else | 754 #else |
755 SkDEBUGFAIL("Should not call in GPU-less build"); | 755 SkDEBUGFAIL("Should not call in GPU-less build"); |
756 return NULL; | 756 return NULL; |
757 #endif | 757 #endif |
758 } | 758 } |
759 virtual bool requiresFragmentPosition() const SK_OVERRIDE { return true; } | 759 bool requiresFragmentPosition() const SK_OVERRIDE { return true; } |
760 virtual LightType type() const SK_OVERRIDE { return kSpot_LightType; } | 760 LightType type() const SK_OVERRIDE { return kSpot_LightType; } |
761 const SkPoint3& location() const { return fLocation; } | 761 const SkPoint3& location() const { return fLocation; } |
762 const SkPoint3& target() const { return fTarget; } | 762 const SkPoint3& target() const { return fTarget; } |
763 SkScalar specularExponent() const { return fSpecularExponent; } | 763 SkScalar specularExponent() const { return fSpecularExponent; } |
764 SkScalar cosInnerConeAngle() const { return fCosInnerConeAngle; } | 764 SkScalar cosInnerConeAngle() const { return fCosInnerConeAngle; } |
765 SkScalar cosOuterConeAngle() const { return fCosOuterConeAngle; } | 765 SkScalar cosOuterConeAngle() const { return fCosOuterConeAngle; } |
766 SkScalar coneScale() const { return fConeScale; } | 766 SkScalar coneScale() const { return fConeScale; } |
767 const SkPoint3& s() const { return fS; } | 767 const SkPoint3& s() const { return fS; } |
768 | 768 |
769 SkSpotLight(SkReadBuffer& buffer) : INHERITED(buffer) { | 769 SkSpotLight(SkReadBuffer& buffer) : INHERITED(buffer) { |
770 fLocation = readPoint3(buffer); | 770 fLocation = readPoint3(buffer); |
(...skipping 13 matching lines...) Expand all Loading... |
784 : INHERITED(color), | 784 : INHERITED(color), |
785 fLocation(location), | 785 fLocation(location), |
786 fTarget(target), | 786 fTarget(target), |
787 fSpecularExponent(specularExponent), | 787 fSpecularExponent(specularExponent), |
788 fCosOuterConeAngle(cosOuterConeAngle), | 788 fCosOuterConeAngle(cosOuterConeAngle), |
789 fCosInnerConeAngle(cosInnerConeAngle), | 789 fCosInnerConeAngle(cosInnerConeAngle), |
790 fConeScale(coneScale), | 790 fConeScale(coneScale), |
791 fS(s) | 791 fS(s) |
792 { | 792 { |
793 } | 793 } |
794 virtual void onFlattenLight(SkWriteBuffer& buffer) const SK_OVERRIDE { | 794 void onFlattenLight(SkWriteBuffer& buffer) const SK_OVERRIDE { |
795 writePoint3(fLocation, buffer); | 795 writePoint3(fLocation, buffer); |
796 writePoint3(fTarget, buffer); | 796 writePoint3(fTarget, buffer); |
797 buffer.writeScalar(fSpecularExponent); | 797 buffer.writeScalar(fSpecularExponent); |
798 buffer.writeScalar(fCosOuterConeAngle); | 798 buffer.writeScalar(fCosOuterConeAngle); |
799 buffer.writeScalar(fCosInnerConeAngle); | 799 buffer.writeScalar(fCosInnerConeAngle); |
800 buffer.writeScalar(fConeScale); | 800 buffer.writeScalar(fConeScale); |
801 writePoint3(fS, buffer); | 801 writePoint3(fS, buffer); |
802 } | 802 } |
803 | 803 |
804 virtual bool isEqual(const SkLight& other) const SK_OVERRIDE { | 804 bool isEqual(const SkLight& other) const SK_OVERRIDE { |
805 if (other.type() != kSpot_LightType) { | 805 if (other.type() != kSpot_LightType) { |
806 return false; | 806 return false; |
807 } | 807 } |
808 | 808 |
809 const SkSpotLight& o = static_cast<const SkSpotLight&>(other); | 809 const SkSpotLight& o = static_cast<const SkSpotLight&>(other); |
810 return INHERITED::isEqual(other) && | 810 return INHERITED::isEqual(other) && |
811 fLocation == o.fLocation && | 811 fLocation == o.fLocation && |
812 fTarget == o.fTarget && | 812 fTarget == o.fTarget && |
813 fSpecularExponent == o.fSpecularExponent && | 813 fSpecularExponent == o.fSpecularExponent && |
814 fCosOuterConeAngle == o.fCosOuterConeAngle; | 814 fCosOuterConeAngle == o.fCosOuterConeAngle; |
(...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1218 const char* outputColor, | 1218 const char* outputColor, |
1219 const char* inputColor, | 1219 const char* inputColor, |
1220 const TransformedCoordsArray&, | 1220 const TransformedCoordsArray&, |
1221 const TextureSamplerArray&) SK_OVERRIDE; | 1221 const TextureSamplerArray&) SK_OVERRIDE; |
1222 | 1222 |
1223 static inline void GenKey(const GrProcessor&, const GrGLCaps&, GrProcessorKe
yBuilder* b); | 1223 static inline void GenKey(const GrProcessor&, const GrGLCaps&, GrProcessorKe
yBuilder* b); |
1224 | 1224 |
1225 /** | 1225 /** |
1226 * Subclasses of GrGLLightingEffect must call INHERITED::setData(); | 1226 * Subclasses of GrGLLightingEffect must call INHERITED::setData(); |
1227 */ | 1227 */ |
1228 virtual void setData(const GrGLProgramDataManager&, const GrProcessor&) SK_O
VERRIDE; | 1228 void setData(const GrGLProgramDataManager&, const GrProcessor&) SK_OVERRIDE; |
1229 | 1229 |
1230 protected: | 1230 protected: |
1231 virtual void emitLightFunc(GrGLFPBuilder*, SkString* funcName) = 0; | 1231 virtual void emitLightFunc(GrGLFPBuilder*, SkString* funcName) = 0; |
1232 | 1232 |
1233 private: | 1233 private: |
1234 typedef GrGLFragmentProcessor INHERITED; | 1234 typedef GrGLFragmentProcessor INHERITED; |
1235 | 1235 |
1236 UniformHandle fImageIncrementUni; | 1236 UniformHandle fImageIncrementUni; |
1237 UniformHandle fSurfaceScaleUni; | 1237 UniformHandle fSurfaceScaleUni; |
1238 GrGLLight* fLight; | 1238 GrGLLight* fLight; |
1239 }; | 1239 }; |
1240 | 1240 |
1241 /////////////////////////////////////////////////////////////////////////////// | 1241 /////////////////////////////////////////////////////////////////////////////// |
1242 | 1242 |
1243 class GrGLDiffuseLightingEffect : public GrGLLightingEffect { | 1243 class GrGLDiffuseLightingEffect : public GrGLLightingEffect { |
1244 public: | 1244 public: |
1245 GrGLDiffuseLightingEffect(const GrProcessor&); | 1245 GrGLDiffuseLightingEffect(const GrProcessor&); |
1246 virtual void emitLightFunc(GrGLFPBuilder*, SkString* funcName) SK_OVERRIDE; | 1246 void emitLightFunc(GrGLFPBuilder*, SkString* funcName) SK_OVERRIDE; |
1247 virtual void setData(const GrGLProgramDataManager&, const GrProcessor&) SK_O
VERRIDE; | 1247 void setData(const GrGLProgramDataManager&, const GrProcessor&) SK_OVERRIDE; |
1248 | 1248 |
1249 private: | 1249 private: |
1250 typedef GrGLLightingEffect INHERITED; | 1250 typedef GrGLLightingEffect INHERITED; |
1251 | 1251 |
1252 UniformHandle fKDUni; | 1252 UniformHandle fKDUni; |
1253 }; | 1253 }; |
1254 | 1254 |
1255 /////////////////////////////////////////////////////////////////////////////// | 1255 /////////////////////////////////////////////////////////////////////////////// |
1256 | 1256 |
1257 class GrGLSpecularLightingEffect : public GrGLLightingEffect { | 1257 class GrGLSpecularLightingEffect : public GrGLLightingEffect { |
1258 public: | 1258 public: |
1259 GrGLSpecularLightingEffect(const GrProcessor&); | 1259 GrGLSpecularLightingEffect(const GrProcessor&); |
1260 virtual void emitLightFunc(GrGLFPBuilder*, SkString* funcName) SK_OVERRIDE; | 1260 void emitLightFunc(GrGLFPBuilder*, SkString* funcName) SK_OVERRIDE; |
1261 virtual void setData(const GrGLProgramDataManager&, const GrProcessor&) SK_O
VERRIDE; | 1261 void setData(const GrGLProgramDataManager&, const GrProcessor&) SK_OVERRIDE; |
1262 | 1262 |
1263 private: | 1263 private: |
1264 typedef GrGLLightingEffect INHERITED; | 1264 typedef GrGLLightingEffect INHERITED; |
1265 | 1265 |
1266 UniformHandle fKSUni; | 1266 UniformHandle fKSUni; |
1267 UniformHandle fShininessUni; | 1267 UniformHandle fShininessUni; |
1268 }; | 1268 }; |
1269 | 1269 |
1270 /////////////////////////////////////////////////////////////////////////////// | 1270 /////////////////////////////////////////////////////////////////////////////// |
1271 | 1271 |
(...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1716 | 1716 |
1717 fsBuilder->codeAppendf("%s(%s)", fLightColorFunc.c_str(), surfaceToLight); | 1717 fsBuilder->codeAppendf("%s(%s)", fLightColorFunc.c_str(), surfaceToLight); |
1718 } | 1718 } |
1719 | 1719 |
1720 #endif | 1720 #endif |
1721 | 1721 |
1722 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingImageFilter) | 1722 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingImageFilter) |
1723 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDiffuseLightingImageFilter) | 1723 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDiffuseLightingImageFilter) |
1724 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSpecularLightingImageFilter) | 1724 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSpecularLightingImageFilter) |
1725 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END | 1725 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END |
OLD | NEW |