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