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 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
320 const CropRect* cropRect) | 320 const CropRect* cropRect) |
321 : INHERITED(light, surfaceScale, input, cropRect) {} | 321 : INHERITED(light, surfaceScale, input, cropRect) {} |
322 | 322 |
323 #if SK_SUPPORT_GPU | 323 #if SK_SUPPORT_GPU |
324 bool canFilterImageGPU() const override { return true; } | 324 bool canFilterImageGPU() const override { return true; } |
325 bool filterImageGPU(Proxy*, const SkBitmap& src, const Context&, | 325 bool filterImageGPU(Proxy*, const SkBitmap& src, const Context&, |
326 SkBitmap* result, SkIPoint* offset) const override; | 326 SkBitmap* result, SkIPoint* offset) const override; |
327 virtual GrFragmentProcessor* getFragmentProcessor(GrTexture*, | 327 virtual GrFragmentProcessor* getFragmentProcessor(GrTexture*, |
328 const SkMatrix&, | 328 const SkMatrix&, |
329 const SkIRect& bounds, | 329 const SkIRect& bounds, |
330 BoundaryMode boundaryMode)
const = 0; | 330 BoundaryMode boundaryMode,
GrRenderTarget* dst) const = 0; |
331 #endif | 331 #endif |
332 private: | 332 private: |
333 #if SK_SUPPORT_GPU | 333 #if SK_SUPPORT_GPU |
334 void drawRect(GrDrawContext* drawContext, | 334 void drawRect(GrDrawContext* drawContext, |
335 GrTexture* src, | 335 GrTexture* src, |
336 const SkMatrix& matrix, | 336 const SkMatrix& matrix, |
337 const GrClip& clip, | 337 const GrClip& clip, |
338 const SkRect& dstRect, | 338 const SkRect& dstRect, |
339 BoundaryMode boundaryMode, | 339 BoundaryMode boundaryMode, |
340 const SkIRect& bounds) const; | 340 const SkIRect& bounds) const; |
341 #endif | 341 #endif |
342 typedef SkLightingImageFilter INHERITED; | 342 typedef SkLightingImageFilter INHERITED; |
343 }; | 343 }; |
344 | 344 |
345 #if SK_SUPPORT_GPU | 345 #if SK_SUPPORT_GPU |
346 void SkLightingImageFilterInternal::drawRect(GrDrawContext* drawContext, | 346 void SkLightingImageFilterInternal::drawRect(GrDrawContext* drawContext, |
347 GrTexture* src, | 347 GrTexture* src, |
348 const SkMatrix& matrix, | 348 const SkMatrix& matrix, |
349 const GrClip& clip, | 349 const GrClip& clip, |
350 const SkRect& dstRect, | 350 const SkRect& dstRect, |
351 BoundaryMode boundaryMode, | 351 BoundaryMode boundaryMode, |
352 const SkIRect& bounds) const { | 352 const SkIRect& bounds) const { |
353 SkRect srcRect = dstRect.makeOffset(SkIntToScalar(bounds.x()), SkIntToScalar
(bounds.y())); | 353 SkRect srcRect = dstRect.makeOffset(SkIntToScalar(bounds.x()), SkIntToScalar
(bounds.y())); |
354 GrPaint paint; | 354 GrPaint paint; |
355 GrFragmentProcessor* fp = this->getFragmentProcessor(src, matrix, bounds, bo
undaryMode); | 355 GrFragmentProcessor* fp = this->getFragmentProcessor(src, |
| 356 matrix, bounds, boundar
yMode, drawContext->rt_remove_me()); |
356 paint.addColorFragmentProcessor(fp)->unref(); | 357 paint.addColorFragmentProcessor(fp)->unref(); |
357 drawContext->fillRectToRect(clip, paint, SkMatrix::I(), dstRect, srcRect); | 358 drawContext->fillRectToRect(clip, paint, SkMatrix::I(), dstRect, srcRect); |
358 } | 359 } |
359 | 360 |
| 361 |
360 bool SkLightingImageFilterInternal::filterImageGPU(Proxy* proxy, | 362 bool SkLightingImageFilterInternal::filterImageGPU(Proxy* proxy, |
361 const SkBitmap& src, | 363 const SkBitmap& src, |
362 const Context& ctx, | 364 const Context& ctx, |
363 SkBitmap* result, | 365 SkBitmap* result, SkIPoint* o
ffset) const { |
364 SkIPoint* offset) const { | 366 |
365 SkBitmap input = src; | 367 SkBitmap input = src; |
366 SkIPoint srcOffset = SkIPoint::Make(0, 0); | 368 SkIPoint srcOffset = SkIPoint::Make(0, 0); |
367 if (!this->filterInputGPU(0, proxy, src, ctx, &input, &srcOffset)) { | 369 if (!this->filterInputGPU(0, proxy, src, ctx, &input, &srcOffset)) { |
368 return false; | 370 return false; |
369 } | 371 } |
370 SkIRect bounds; | 372 SkIRect bounds; |
371 if (!this->applyCropRect(ctx, proxy, input, &srcOffset, &bounds, &input)) { | 373 if (!this->applyCropRect(ctx, proxy, input, &srcOffset, &bounds, &input)) { |
372 return false; | 374 return false; |
373 } | 375 } |
374 SkRect dstRect = SkRect::MakeWH(SkIntToScalar(bounds.width()), | 376 SkRect dstRect = SkRect::MakeWH(SkIntToScalar(bounds.width()), |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
417 bounds); | 419 bounds); |
418 this->drawRect(drawContext, srcTexture, matrix, clip, left, kLeft_BoundaryMo
de, bounds); | 420 this->drawRect(drawContext, srcTexture, matrix, clip, left, kLeft_BoundaryMo
de, bounds); |
419 this->drawRect(drawContext, srcTexture, matrix, clip, interior, kInterior_Bo
undaryMode, | 421 this->drawRect(drawContext, srcTexture, matrix, clip, interior, kInterior_Bo
undaryMode, |
420 bounds); | 422 bounds); |
421 this->drawRect(drawContext, srcTexture, matrix, clip, right, kRight_Boundary
Mode, bounds); | 423 this->drawRect(drawContext, srcTexture, matrix, clip, right, kRight_Boundary
Mode, bounds); |
422 this->drawRect(drawContext, srcTexture, matrix, clip, bottomLeft, kBottomLef
t_BoundaryMode, | 424 this->drawRect(drawContext, srcTexture, matrix, clip, bottomLeft, kBottomLef
t_BoundaryMode, |
423 bounds); | 425 bounds); |
424 this->drawRect(drawContext, srcTexture, matrix, clip, bottom, kBottom_Bounda
ryMode, bounds); | 426 this->drawRect(drawContext, srcTexture, matrix, clip, bottom, kBottom_Bounda
ryMode, bounds); |
425 this->drawRect(drawContext, srcTexture, matrix, clip, bottomRight, | 427 this->drawRect(drawContext, srcTexture, matrix, clip, bottomRight, |
426 kBottomRight_BoundaryMode, bounds); | 428 kBottomRight_BoundaryMode, bounds); |
| 429 |
427 WrapTexture(dst, bounds.width(), bounds.height(), result); | 430 WrapTexture(dst, bounds.width(), bounds.height(), result); |
428 return true; | 431 return true; |
429 } | 432 } |
430 #endif | 433 #endif |
431 | 434 |
432 class SkDiffuseLightingImageFilter : public SkLightingImageFilterInternal { | 435 class SkDiffuseLightingImageFilter : public SkLightingImageFilterInternal { |
433 public: | 436 public: |
434 static SkImageFilter* Create(SkImageFilterLight* light, SkScalar surfaceScal
e, | 437 static SkImageFilter* Create(SkImageFilterLight* light, SkScalar surfaceScal
e, |
435 SkScalar kd, SkImageFilter*, | 438 SkScalar kd, SkImageFilter*, |
436 const CropRect*); | 439 const CropRect*); |
437 | 440 |
438 SK_TO_STRING_OVERRIDE() | 441 SK_TO_STRING_OVERRIDE() |
439 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkDiffuseLightingImageFi
lter) | 442 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkDiffuseLightingImageFi
lter) |
440 SkScalar kd() const { return fKD; } | 443 SkScalar kd() const { return fKD; } |
441 | 444 |
442 protected: | 445 protected: |
443 SkDiffuseLightingImageFilter(SkImageFilterLight* light, SkScalar surfaceScal
e, | 446 SkDiffuseLightingImageFilter(SkImageFilterLight* light, SkScalar surfaceScal
e, |
444 SkScalar kd, SkImageFilter* input, const CropRe
ct* cropRect); | 447 SkScalar kd, SkImageFilter* input, const CropRe
ct* cropRect); |
445 void flatten(SkWriteBuffer& buffer) const override; | 448 void flatten(SkWriteBuffer& buffer) const override; |
446 bool onFilterImage(Proxy*, const SkBitmap& src, const Context&, | 449 bool onFilterImage(Proxy*, const SkBitmap& src, const Context&, |
447 SkBitmap* result, SkIPoint* offset) const override; | 450 SkBitmap* result, SkIPoint* offset) const override; |
448 #if SK_SUPPORT_GPU | 451 #if SK_SUPPORT_GPU |
449 GrFragmentProcessor* getFragmentProcessor(GrTexture*, const SkMatrix&, const
SkIRect& bounds, | 452 GrFragmentProcessor* getFragmentProcessor(GrTexture*, const SkMatrix&, const
SkIRect& bounds, |
450 BoundaryMode) const override; | 453 BoundaryMode, GrRenderTarget* dst)
const override; |
451 #endif | 454 #endif |
452 | 455 |
453 private: | 456 private: |
454 friend class SkLightingImageFilter; | 457 friend class SkLightingImageFilter; |
455 typedef SkLightingImageFilterInternal INHERITED; | 458 typedef SkLightingImageFilterInternal INHERITED; |
456 SkScalar fKD; | 459 SkScalar fKD; |
457 }; | 460 }; |
458 | 461 |
459 class SkSpecularLightingImageFilter : public SkLightingImageFilterInternal { | 462 class SkSpecularLightingImageFilter : public SkLightingImageFilterInternal { |
460 public: | 463 public: |
461 static SkImageFilter* Create(SkImageFilterLight* light, SkScalar surfaceScal
e, | 464 static SkImageFilter* Create(SkImageFilterLight* light, SkScalar surfaceScal
e, |
462 SkScalar ks, SkScalar shininess, SkImageFilter*
, const CropRect*); | 465 SkScalar ks, SkScalar shininess, SkImageFilter*
, const CropRect*); |
463 | 466 |
464 SK_TO_STRING_OVERRIDE() | 467 SK_TO_STRING_OVERRIDE() |
465 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkSpecularLightingImageF
ilter) | 468 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkSpecularLightingImageF
ilter) |
466 | 469 |
467 SkScalar ks() const { return fKS; } | 470 SkScalar ks() const { return fKS; } |
468 SkScalar shininess() const { return fShininess; } | 471 SkScalar shininess() const { return fShininess; } |
469 | 472 |
470 protected: | 473 protected: |
471 SkSpecularLightingImageFilter(SkImageFilterLight* light, SkScalar surfaceSca
le, SkScalar ks, | 474 SkSpecularLightingImageFilter(SkImageFilterLight* light, SkScalar surfaceSca
le, SkScalar ks, |
472 SkScalar shininess, SkImageFilter* input, cons
t CropRect*); | 475 SkScalar shininess, SkImageFilter* input, cons
t CropRect*); |
473 void flatten(SkWriteBuffer& buffer) const override; | 476 void flatten(SkWriteBuffer& buffer) const override; |
474 bool onFilterImage(Proxy*, const SkBitmap& src, const Context&, | 477 bool onFilterImage(Proxy*, const SkBitmap& src, const Context&, |
475 SkBitmap* result, SkIPoint* offset) const override; | 478 SkBitmap* result, SkIPoint* offset) const override; |
476 #if SK_SUPPORT_GPU | 479 #if SK_SUPPORT_GPU |
477 GrFragmentProcessor* getFragmentProcessor(GrTexture*, const SkMatrix&, const
SkIRect& bounds, | 480 GrFragmentProcessor* getFragmentProcessor(GrTexture*, const SkMatrix&, |
478 BoundaryMode) const override; | 481 const SkIRect& bounds, BoundaryMod
e, GrRenderTarget* dst) const override; |
479 #endif | 482 #endif |
480 | 483 |
481 private: | 484 private: |
482 SkScalar fKS; | 485 SkScalar fKS; |
483 SkScalar fShininess; | 486 SkScalar fShininess; |
484 friend class SkLightingImageFilter; | 487 friend class SkLightingImageFilter; |
485 typedef SkLightingImageFilterInternal INHERITED; | 488 typedef SkLightingImageFilterInternal INHERITED; |
486 }; | 489 }; |
487 | 490 |
488 #if SK_SUPPORT_GPU | 491 #if SK_SUPPORT_GPU |
489 | 492 |
490 class GrLightingEffect : public GrSingleTextureEffect { | 493 class GrLightingEffect : public GrSingleTextureEffect { |
491 public: | 494 public: |
492 GrLightingEffect(GrTexture* texture, const SkImageFilterLight* light, SkScal
ar surfaceScale, | 495 GrLightingEffect(GrTexture* texture, const SkImageFilterLight* light, |
493 const SkMatrix& matrix, BoundaryMode boundaryMode); | 496 SkScalar surfaceScale, const SkMatrix& matrix, BoundaryMode
boundaryMode, GrRenderTarget* dst); |
494 virtual ~GrLightingEffect(); | 497 virtual ~GrLightingEffect(); |
495 | 498 |
496 const SkImageFilterLight* light() const { return fLight; } | 499 const SkImageFilterLight* light() const { return fLight; } |
497 SkScalar surfaceScale() const { return fSurfaceScale; } | 500 SkScalar surfaceScale() const { return fSurfaceScale; } |
498 const SkMatrix& filterMatrix() const { return fFilterMatrix; } | 501 const SkMatrix& filterMatrix() const { return fFilterMatrix; } |
499 BoundaryMode boundaryMode() const { return fBoundaryMode; } | 502 BoundaryMode boundaryMode() const { return fBoundaryMode; } |
500 | 503 |
501 protected: | 504 protected: |
502 bool onIsEqual(const GrFragmentProcessor&) const override; | 505 bool onIsEqual(const GrFragmentProcessor&) const override; |
503 | 506 |
(...skipping 11 matching lines...) Expand all Loading... |
515 typedef GrSingleTextureEffect INHERITED; | 518 typedef GrSingleTextureEffect INHERITED; |
516 }; | 519 }; |
517 | 520 |
518 class GrDiffuseLightingEffect : public GrLightingEffect { | 521 class GrDiffuseLightingEffect : public GrLightingEffect { |
519 public: | 522 public: |
520 static GrFragmentProcessor* Create(GrTexture* texture, | 523 static GrFragmentProcessor* Create(GrTexture* texture, |
521 const SkImageFilterLight* light, | 524 const SkImageFilterLight* light, |
522 SkScalar surfaceScale, | 525 SkScalar surfaceScale, |
523 const SkMatrix& matrix, | 526 const SkMatrix& matrix, |
524 SkScalar kd, | 527 SkScalar kd, |
525 BoundaryMode boundaryMode) { | 528 BoundaryMode boundaryMode, GrRenderTarget
* dst) { |
526 return new GrDiffuseLightingEffect(texture, light, surfaceScale, matrix,
kd, boundaryMode); | 529 return new GrDiffuseLightingEffect(texture, light, surfaceScale, matrix, |
| 530 kd, boundaryMode, dst); |
527 } | 531 } |
528 | 532 |
529 const char* name() const override { return "DiffuseLighting"; } | 533 const char* name() const override { return "DiffuseLighting"; } |
530 | 534 |
531 SkScalar kd() const { return fKD; } | 535 SkScalar kd() const { return fKD; } |
532 | 536 |
533 private: | 537 private: |
534 GrGLFragmentProcessor* onCreateGLInstance() const override; | 538 GrGLFragmentProcessor* onCreateGLInstance() const override; |
535 | 539 |
536 void onGetGLProcessorKey(const GrGLSLCaps&, GrProcessorKeyBuilder*) const ov
erride; | 540 void onGetGLProcessorKey(const GrGLSLCaps&, GrProcessorKeyBuilder*) const ov
erride; |
537 | 541 |
538 bool onIsEqual(const GrFragmentProcessor&) const override; | 542 bool onIsEqual(const GrFragmentProcessor&) const override; |
539 | 543 |
540 GrDiffuseLightingEffect(GrTexture* texture, | 544 GrDiffuseLightingEffect(GrTexture* texture, |
541 const SkImageFilterLight* light, | 545 const SkImageFilterLight* light, |
542 SkScalar surfaceScale, | 546 SkScalar surfaceScale, |
543 const SkMatrix& matrix, | 547 const SkMatrix& matrix, |
544 SkScalar kd, | 548 SkScalar kd, |
545 BoundaryMode boundaryMode); | 549 BoundaryMode boundaryMode, GrRenderTarget* dst); |
546 | 550 |
547 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; | 551 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; |
548 typedef GrLightingEffect INHERITED; | 552 typedef GrLightingEffect INHERITED; |
549 SkScalar fKD; | 553 SkScalar fKD; |
550 }; | 554 }; |
551 | 555 |
552 class GrSpecularLightingEffect : public GrLightingEffect { | 556 class GrSpecularLightingEffect : public GrLightingEffect { |
553 public: | 557 public: |
554 static GrFragmentProcessor* Create(GrTexture* texture, | 558 static GrFragmentProcessor* Create(GrTexture* texture, |
555 const SkImageFilterLight* light, | 559 const SkImageFilterLight* light, |
556 SkScalar surfaceScale, | 560 SkScalar surfaceScale, |
557 const SkMatrix& matrix, | 561 const SkMatrix& matrix, |
558 SkScalar ks, | 562 SkScalar ks, |
559 SkScalar shininess, | 563 SkScalar shininess, |
560 BoundaryMode boundaryMode) { | 564 BoundaryMode boundaryMode, GrRenderTarget
* dst) { |
561 return new GrSpecularLightingEffect(texture, light, surfaceScale, matrix
, ks, shininess, | 565 return new GrSpecularLightingEffect(texture, light, surfaceScale, matrix
, |
562 boundaryMode); | 566 ks, shininess, boundaryMode, dst); |
563 } | 567 } |
564 | 568 |
565 const char* name() const override { return "SpecularLighting"; } | 569 const char* name() const override { return "SpecularLighting"; } |
566 | 570 |
567 GrGLFragmentProcessor* onCreateGLInstance() const override; | 571 GrGLFragmentProcessor* onCreateGLInstance() const override; |
568 | 572 |
569 SkScalar ks() const { return fKS; } | 573 SkScalar ks() const { return fKS; } |
570 SkScalar shininess() const { return fShininess; } | 574 SkScalar shininess() const { return fShininess; } |
571 | 575 |
572 private: | 576 private: |
573 void onGetGLProcessorKey(const GrGLSLCaps&, GrProcessorKeyBuilder*) const ov
erride; | 577 void onGetGLProcessorKey(const GrGLSLCaps&, GrProcessorKeyBuilder*) const ov
erride; |
574 | 578 |
575 bool onIsEqual(const GrFragmentProcessor&) const override; | 579 bool onIsEqual(const GrFragmentProcessor&) const override; |
576 | 580 |
577 GrSpecularLightingEffect(GrTexture* texture, | 581 GrSpecularLightingEffect(GrTexture* texture, |
578 const SkImageFilterLight* light, | 582 const SkImageFilterLight* light, |
579 SkScalar surfaceScale, | 583 SkScalar surfaceScale, |
580 const SkMatrix& matrix, | 584 const SkMatrix& matrix, |
581 SkScalar ks, | 585 SkScalar ks, |
582 SkScalar shininess, | 586 SkScalar shininess, |
583 BoundaryMode boundaryMode); | 587 BoundaryMode boundaryMode, GrRenderTarget* dst); |
584 | 588 |
585 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; | 589 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; |
586 typedef GrLightingEffect INHERITED; | 590 typedef GrLightingEffect INHERITED; |
587 SkScalar fKS; | 591 SkScalar fKS; |
588 SkScalar fShininess; | 592 SkScalar fShininess; |
589 }; | 593 }; |
590 | 594 |
591 /////////////////////////////////////////////////////////////////////////////// | 595 /////////////////////////////////////////////////////////////////////////////// |
592 | 596 |
593 class GrGLLight { | 597 class GrGLLight { |
(...skipping 651 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1245 str->appendf("kD: %f\n", fKD); | 1249 str->appendf("kD: %f\n", fKD); |
1246 str->append(")"); | 1250 str->append(")"); |
1247 } | 1251 } |
1248 #endif | 1252 #endif |
1249 | 1253 |
1250 #if SK_SUPPORT_GPU | 1254 #if SK_SUPPORT_GPU |
1251 GrFragmentProcessor* SkDiffuseLightingImageFilter::getFragmentProcessor( | 1255 GrFragmentProcessor* SkDiffuseLightingImageFilter::getFragmentProcessor( |
1252 GrTexture* texture, | 1256 GrTexture* texture, |
1253 const SkMatrix& matrix, | 1257 const SkMatrix& matrix, |
1254 const SkIRect&, | 1258 const SkIRect&, |
1255 BoundaryMode boundaryMode | 1259 BoundaryMode boundaryMode, |
1256 ) const { | 1260 GrRenderTarget* dst) const { |
1257 SkScalar scale = SkScalarMul(this->surfaceScale(), SkIntToScalar(255)); | 1261 SkScalar scale = SkScalarMul(this->surfaceScale(), SkIntToScalar(255)); |
1258 return GrDiffuseLightingEffect::Create(texture, this->light(), scale, matrix
, this->kd(), | 1262 return GrDiffuseLightingEffect::Create(texture, this->light(), scale, matrix
, |
1259 boundaryMode); | 1263 this->kd(), boundaryMode, dst); |
1260 } | 1264 } |
1261 #endif | 1265 #endif |
1262 | 1266 |
1263 /////////////////////////////////////////////////////////////////////////////// | 1267 /////////////////////////////////////////////////////////////////////////////// |
1264 | 1268 |
1265 SkImageFilter* SkSpecularLightingImageFilter::Create(SkImageFilterLight* light, | 1269 SkImageFilter* SkSpecularLightingImageFilter::Create(SkImageFilterLight* light, |
1266 SkScalar surfaceScale, | 1270 SkScalar surfaceScale, |
1267 SkScalar ks, | 1271 SkScalar ks, |
1268 SkScalar shininess, | 1272 SkScalar shininess, |
1269 SkImageFilter* input, | 1273 SkImageFilter* input, |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1387 str->appendf("kS: %f shininess: %f", fKS, fShininess); | 1391 str->appendf("kS: %f shininess: %f", fKS, fShininess); |
1388 str->append(")"); | 1392 str->append(")"); |
1389 } | 1393 } |
1390 #endif | 1394 #endif |
1391 | 1395 |
1392 #if SK_SUPPORT_GPU | 1396 #if SK_SUPPORT_GPU |
1393 GrFragmentProcessor* SkSpecularLightingImageFilter::getFragmentProcessor( | 1397 GrFragmentProcessor* SkSpecularLightingImageFilter::getFragmentProcessor( |
1394 GrTexture* texture, | 1398 GrTexture* texture, |
1395 const SkMatrix& matrix, | 1399 const SkMatrix& matrix, |
1396 const SkIRect&, | 1400 const SkIRect&, |
1397 BoundaryMode boundaryMode) c
onst { | 1401 BoundaryMode boundaryMode, G
rRenderTarget* dst) const { |
1398 SkScalar scale = SkScalarMul(this->surfaceScale(), SkIntToScalar(255)); | 1402 SkScalar scale = SkScalarMul(this->surfaceScale(), SkIntToScalar(255)); |
1399 return GrSpecularLightingEffect::Create(texture, this->light(), scale, matri
x, this->ks(), | 1403 return GrSpecularLightingEffect::Create(texture, this->light(), scale, matri
x, |
1400 this->shininess(), boundaryMode); | 1404 this->ks(), this->shininess(), bound
aryMode, dst); |
1401 } | 1405 } |
1402 #endif | 1406 #endif |
1403 | 1407 |
1404 /////////////////////////////////////////////////////////////////////////////// | 1408 /////////////////////////////////////////////////////////////////////////////// |
1405 | 1409 |
1406 #if SK_SUPPORT_GPU | 1410 #if SK_SUPPORT_GPU |
1407 | 1411 |
1408 namespace { | 1412 namespace { |
1409 SkPoint3 random_point3(SkRandom* random) { | 1413 SkPoint3 random_point3(SkRandom* random) { |
1410 return SkPoint3::Make(SkScalarToFloat(random->nextSScalar1()), | 1414 return SkPoint3::Make(SkScalarToFloat(random->nextSScalar1()), |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1566 UniformHandle fKSUni; | 1570 UniformHandle fKSUni; |
1567 UniformHandle fShininessUni; | 1571 UniformHandle fShininessUni; |
1568 }; | 1572 }; |
1569 | 1573 |
1570 /////////////////////////////////////////////////////////////////////////////// | 1574 /////////////////////////////////////////////////////////////////////////////// |
1571 | 1575 |
1572 GrLightingEffect::GrLightingEffect(GrTexture* texture, | 1576 GrLightingEffect::GrLightingEffect(GrTexture* texture, |
1573 const SkImageFilterLight* light, | 1577 const SkImageFilterLight* light, |
1574 SkScalar surfaceScale, | 1578 SkScalar surfaceScale, |
1575 const SkMatrix& matrix, | 1579 const SkMatrix& matrix, |
1576 BoundaryMode boundaryMode) | 1580 BoundaryMode boundaryMode, GrRenderTarget* ds
t) |
1577 : INHERITED(texture, GrCoordTransform::MakeDivByTextureWHMatrix(texture)) | 1581 : INHERITED(texture, GrCoordTransform::MakeDivByTextureWHMatrix(texture), kL
ocal_GrCoordSet, dst) |
1578 , fLight(light) | 1582 , fLight(light) |
1579 , fSurfaceScale(surfaceScale) | 1583 , fSurfaceScale(surfaceScale) |
1580 , fFilterMatrix(matrix) | 1584 , fFilterMatrix(matrix) |
1581 , fBoundaryMode(boundaryMode) { | 1585 , fBoundaryMode(boundaryMode) { |
1582 fLight->ref(); | 1586 fLight->ref(); |
1583 if (light->requiresFragmentPosition()) { | 1587 if (light->requiresFragmentPosition()) { |
1584 this->setWillReadFragmentPosition(); | 1588 this->setWillReadFragmentPosition(); |
1585 } | 1589 } |
1586 } | 1590 } |
1587 | 1591 |
1588 GrLightingEffect::~GrLightingEffect() { | 1592 GrLightingEffect::~GrLightingEffect() { |
1589 fLight->unref(); | 1593 fLight->unref(); |
1590 } | 1594 } |
1591 | 1595 |
1592 bool GrLightingEffect::onIsEqual(const GrFragmentProcessor& sBase) const { | 1596 bool GrLightingEffect::onIsEqual(const GrFragmentProcessor& sBase) const { |
1593 const GrLightingEffect& s = sBase.cast<GrLightingEffect>(); | 1597 const GrLightingEffect& s = sBase.cast<GrLightingEffect>(); |
1594 return fLight->isEqual(*s.fLight) && | 1598 return fLight->isEqual(*s.fLight) && |
1595 fSurfaceScale == s.fSurfaceScale && | 1599 fSurfaceScale == s.fSurfaceScale && |
1596 fBoundaryMode == s.fBoundaryMode; | 1600 fBoundaryMode == s.fBoundaryMode; |
1597 } | 1601 } |
1598 | 1602 |
1599 /////////////////////////////////////////////////////////////////////////////// | 1603 /////////////////////////////////////////////////////////////////////////////// |
1600 | 1604 |
1601 GrDiffuseLightingEffect::GrDiffuseLightingEffect(GrTexture* texture, | 1605 GrDiffuseLightingEffect::GrDiffuseLightingEffect(GrTexture* texture, |
1602 const SkImageFilterLight* light
, | 1606 const SkImageFilterLight* light
, |
1603 SkScalar surfaceScale, | 1607 SkScalar surfaceScale, |
1604 const SkMatrix& matrix, | 1608 const SkMatrix& matrix, |
1605 SkScalar kd, | 1609 SkScalar kd, |
1606 BoundaryMode boundaryMode) | 1610 BoundaryMode boundaryMode, GrRe
nderTarget* dst) |
1607 : INHERITED(texture, light, surfaceScale, matrix, boundaryMode), fKD(kd) { | 1611 : INHERITED(texture, light, surfaceScale, matrix, boundaryMode, dst), fKD(kd
) { |
1608 this->initClassID<GrDiffuseLightingEffect>(); | 1612 this->initClassID<GrDiffuseLightingEffect>(); |
1609 } | 1613 } |
1610 | 1614 |
1611 bool GrDiffuseLightingEffect::onIsEqual(const GrFragmentProcessor& sBase) const
{ | 1615 bool GrDiffuseLightingEffect::onIsEqual(const GrFragmentProcessor& sBase) const
{ |
1612 const GrDiffuseLightingEffect& s = sBase.cast<GrDiffuseLightingEffect>(); | 1616 const GrDiffuseLightingEffect& s = sBase.cast<GrDiffuseLightingEffect>(); |
1613 return INHERITED::onIsEqual(sBase) && | 1617 return INHERITED::onIsEqual(sBase) && |
1614 this->kd() == s.kd(); | 1618 this->kd() == s.kd(); |
1615 } | 1619 } |
1616 | 1620 |
1617 void GrDiffuseLightingEffect::onGetGLProcessorKey(const GrGLSLCaps& caps, | 1621 void GrDiffuseLightingEffect::onGetGLProcessorKey(const GrGLSLCaps& caps, |
(...skipping 10 matching lines...) Expand all Loading... |
1628 const GrFragmentProcessor* GrDiffuseLightingEffect::TestCreate(GrProcessorTestDa
ta* d) { | 1632 const GrFragmentProcessor* GrDiffuseLightingEffect::TestCreate(GrProcessorTestDa
ta* d) { |
1629 SkScalar surfaceScale = d->fRandom->nextSScalar1(); | 1633 SkScalar surfaceScale = d->fRandom->nextSScalar1(); |
1630 SkScalar kd = d->fRandom->nextUScalar1(); | 1634 SkScalar kd = d->fRandom->nextUScalar1(); |
1631 SkAutoTUnref<SkImageFilterLight> light(create_random_light(d->fRandom)); | 1635 SkAutoTUnref<SkImageFilterLight> light(create_random_light(d->fRandom)); |
1632 SkMatrix matrix; | 1636 SkMatrix matrix; |
1633 for (int i = 0; i < 9; i++) { | 1637 for (int i = 0; i < 9; i++) { |
1634 matrix[i] = d->fRandom->nextUScalar1(); | 1638 matrix[i] = d->fRandom->nextUScalar1(); |
1635 } | 1639 } |
1636 BoundaryMode mode = static_cast<BoundaryMode>(d->fRandom->nextU() % kBoundar
yModeCount); | 1640 BoundaryMode mode = static_cast<BoundaryMode>(d->fRandom->nextU() % kBoundar
yModeCount); |
1637 return GrDiffuseLightingEffect::Create(d->fTextures[GrProcessorUnitTest::kAl
phaTextureIdx], | 1641 return GrDiffuseLightingEffect::Create(d->fTextures[GrProcessorUnitTest::kAl
phaTextureIdx], |
1638 light, surfaceScale, matrix, kd, mode
); | 1642 light, surfaceScale, matrix, kd, mode
, NULL); |
1639 } | 1643 } |
1640 | 1644 |
1641 | 1645 |
1642 /////////////////////////////////////////////////////////////////////////////// | 1646 /////////////////////////////////////////////////////////////////////////////// |
1643 | 1647 |
1644 GrGLLightingEffect::GrGLLightingEffect(const GrProcessor& fp) { | 1648 GrGLLightingEffect::GrGLLightingEffect(const GrProcessor& fp) { |
1645 const GrLightingEffect& m = fp.cast<GrLightingEffect>(); | 1649 const GrLightingEffect& m = fp.cast<GrLightingEffect>(); |
1646 fLight = m.light()->createGLLight(); | 1650 fLight = m.light()->createGLLight(); |
1647 fBoundaryMode = m.boundaryMode(); | 1651 fBoundaryMode = m.boundaryMode(); |
1648 } | 1652 } |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1794 } | 1798 } |
1795 | 1799 |
1796 /////////////////////////////////////////////////////////////////////////////// | 1800 /////////////////////////////////////////////////////////////////////////////// |
1797 | 1801 |
1798 GrSpecularLightingEffect::GrSpecularLightingEffect(GrTexture* texture, | 1802 GrSpecularLightingEffect::GrSpecularLightingEffect(GrTexture* texture, |
1799 const SkImageFilterLight* lig
ht, | 1803 const SkImageFilterLight* lig
ht, |
1800 SkScalar surfaceScale, | 1804 SkScalar surfaceScale, |
1801 const SkMatrix& matrix, | 1805 const SkMatrix& matrix, |
1802 SkScalar ks, | 1806 SkScalar ks, |
1803 SkScalar shininess, | 1807 SkScalar shininess, |
1804 BoundaryMode boundaryMode) | 1808 BoundaryMode boundaryMode, Gr
RenderTarget* dst) |
1805 : INHERITED(texture, light, surfaceScale, matrix, boundaryMode) | 1809 : INHERITED(texture, light, surfaceScale, matrix, boundaryMode, dst) |
1806 , fKS(ks) | 1810 , fKS(ks) |
1807 , fShininess(shininess) { | 1811 , fShininess(shininess) { |
1808 this->initClassID<GrSpecularLightingEffect>(); | 1812 this->initClassID<GrSpecularLightingEffect>(); |
1809 } | 1813 } |
1810 | 1814 |
1811 bool GrSpecularLightingEffect::onIsEqual(const GrFragmentProcessor& sBase) const
{ | 1815 bool GrSpecularLightingEffect::onIsEqual(const GrFragmentProcessor& sBase) const
{ |
1812 const GrSpecularLightingEffect& s = sBase.cast<GrSpecularLightingEffect>(); | 1816 const GrSpecularLightingEffect& s = sBase.cast<GrSpecularLightingEffect>(); |
1813 return INHERITED::onIsEqual(sBase) && | 1817 return INHERITED::onIsEqual(sBase) && |
1814 this->ks() == s.ks() && | 1818 this->ks() == s.ks() && |
1815 this->shininess() == s.shininess(); | 1819 this->shininess() == s.shininess(); |
(...skipping 14 matching lines...) Expand all Loading... |
1830 SkScalar surfaceScale = d->fRandom->nextSScalar1(); | 1834 SkScalar surfaceScale = d->fRandom->nextSScalar1(); |
1831 SkScalar ks = d->fRandom->nextUScalar1(); | 1835 SkScalar ks = d->fRandom->nextUScalar1(); |
1832 SkScalar shininess = d->fRandom->nextUScalar1(); | 1836 SkScalar shininess = d->fRandom->nextUScalar1(); |
1833 SkAutoTUnref<SkImageFilterLight> light(create_random_light(d->fRandom)); | 1837 SkAutoTUnref<SkImageFilterLight> light(create_random_light(d->fRandom)); |
1834 SkMatrix matrix; | 1838 SkMatrix matrix; |
1835 for (int i = 0; i < 9; i++) { | 1839 for (int i = 0; i < 9; i++) { |
1836 matrix[i] = d->fRandom->nextUScalar1(); | 1840 matrix[i] = d->fRandom->nextUScalar1(); |
1837 } | 1841 } |
1838 BoundaryMode mode = static_cast<BoundaryMode>(d->fRandom->nextU() % kBoundar
yModeCount); | 1842 BoundaryMode mode = static_cast<BoundaryMode>(d->fRandom->nextU() % kBoundar
yModeCount); |
1839 return GrSpecularLightingEffect::Create(d->fTextures[GrProcessorUnitTest::kA
lphaTextureIdx], | 1843 return GrSpecularLightingEffect::Create(d->fTextures[GrProcessorUnitTest::kA
lphaTextureIdx], |
1840 light, surfaceScale, matrix, ks, shi
niness, mode); | 1844 light, surfaceScale, matrix, ks, shi
niness, mode, NULL); |
1841 } | 1845 } |
1842 | 1846 |
1843 /////////////////////////////////////////////////////////////////////////////// | 1847 /////////////////////////////////////////////////////////////////////////////// |
1844 | 1848 |
1845 GrGLSpecularLightingEffect::GrGLSpecularLightingEffect(const GrProcessor& proc) | 1849 GrGLSpecularLightingEffect::GrGLSpecularLightingEffect(const GrProcessor& proc) |
1846 : INHERITED(proc) { | 1850 : INHERITED(proc) { |
1847 } | 1851 } |
1848 | 1852 |
1849 void GrGLSpecularLightingEffect::emitLightFunc(GrGLSLFPBuilder* builder, SkStrin
g* funcName) { | 1853 void GrGLSpecularLightingEffect::emitLightFunc(GrGLSLFPBuilder* builder, SkStrin
g* funcName) { |
1850 const char* ks; | 1854 const char* ks; |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2014 | 2018 |
2015 fsBuilder->codeAppendf("%s(%s)", fLightColorFunc.c_str(), surfaceToLight); | 2019 fsBuilder->codeAppendf("%s(%s)", fLightColorFunc.c_str(), surfaceToLight); |
2016 } | 2020 } |
2017 | 2021 |
2018 #endif | 2022 #endif |
2019 | 2023 |
2020 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingImageFilter) | 2024 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingImageFilter) |
2021 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDiffuseLightingImageFilter) | 2025 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDiffuseLightingImageFilter) |
2022 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSpecularLightingImageFilter) | 2026 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSpecularLightingImageFilter) |
2023 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END | 2027 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END |
OLD | NEW |