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 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
299 SkLightingImageFilterInternal(SkLight* light, | 299 SkLightingImageFilterInternal(SkLight* light, |
300 SkScalar surfaceScale, | 300 SkScalar surfaceScale, |
301 SkImageFilter* input, | 301 SkImageFilter* input, |
302 const CropRect* cropRect) | 302 const CropRect* cropRect) |
303 : INHERITED(light, surfaceScale, input, cropRect) {} | 303 : INHERITED(light, surfaceScale, input, cropRect) {} |
304 | 304 |
305 #if SK_SUPPORT_GPU | 305 #if SK_SUPPORT_GPU |
306 bool canFilterImageGPU() const override { return true; } | 306 bool canFilterImageGPU() const override { return true; } |
307 bool filterImageGPU(Proxy*, const SkBitmap& src, const Context&, | 307 bool filterImageGPU(Proxy*, const SkBitmap& src, const Context&, |
308 SkBitmap* result, SkIPoint* offset) const override; | 308 SkBitmap* result, SkIPoint* offset) const override; |
309 virtual GrFragmentProcessor* getFragmentProcessor(GrTexture*, | 309 virtual GrFragmentProcessor* getFragmentProcessor(GrProcessorDataManager*, |
| 310 GrTexture*, |
310 const SkMatrix&, | 311 const SkMatrix&, |
311 const SkIRect& bounds, | 312 const SkIRect& bounds, |
312 BoundaryMode boundaryMode)
const = 0; | 313 BoundaryMode boundaryMode)
const = 0; |
313 #endif | 314 #endif |
314 private: | 315 private: |
315 #if SK_SUPPORT_GPU | 316 #if SK_SUPPORT_GPU |
316 void drawRect(GrDrawContext* drawContext, | 317 void drawRect(GrDrawContext* drawContext, |
317 GrTexture* src, | 318 GrTexture* src, |
318 GrTexture* dst, | 319 GrTexture* dst, |
319 const SkMatrix& matrix, | 320 const SkMatrix& matrix, |
320 const GrClip& clip, | 321 const GrClip& clip, |
321 const SkRect& dstRect, | 322 const SkRect& dstRect, |
322 BoundaryMode boundaryMode, | 323 BoundaryMode boundaryMode, |
323 const SkIRect& bounds) const; | 324 const SkIRect& bounds) const; |
324 #endif | 325 #endif |
325 typedef SkLightingImageFilter INHERITED; | 326 typedef SkLightingImageFilter INHERITED; |
326 }; | 327 }; |
327 | 328 |
328 #if SK_SUPPORT_GPU | 329 #if SK_SUPPORT_GPU |
329 void SkLightingImageFilterInternal::drawRect(GrDrawContext* drawContext, | 330 void SkLightingImageFilterInternal::drawRect(GrDrawContext* drawContext, |
330 GrTexture* src, | 331 GrTexture* src, |
331 GrTexture* dst, | 332 GrTexture* dst, |
332 const SkMatrix& matrix, | 333 const SkMatrix& matrix, |
333 const GrClip& clip, | 334 const GrClip& clip, |
334 const SkRect& dstRect, | 335 const SkRect& dstRect, |
335 BoundaryMode boundaryMode, | 336 BoundaryMode boundaryMode, |
336 const SkIRect& bounds) const { | 337 const SkIRect& bounds) const { |
337 SkRect srcRect = dstRect.makeOffset(SkIntToScalar(bounds.x()), SkIntToScalar
(bounds.y())); | 338 SkRect srcRect = dstRect.makeOffset(SkIntToScalar(bounds.x()), SkIntToScalar
(bounds.y())); |
338 GrFragmentProcessor* fp = this->getFragmentProcessor(src, matrix, bounds, bo
undaryMode); | |
339 GrPaint paint; | 339 GrPaint paint; |
| 340 GrFragmentProcessor* fp = this->getFragmentProcessor(paint.getProcessorDataM
anager(), src, |
| 341 matrix, bounds, boundar
yMode); |
340 paint.addColorProcessor(fp)->unref(); | 342 paint.addColorProcessor(fp)->unref(); |
341 drawContext->drawNonAARectToRect(dst->asRenderTarget(), clip, paint, SkMatri
x::I(), | 343 drawContext->drawNonAARectToRect(dst->asRenderTarget(), clip, paint, SkMatri
x::I(), |
342 dstRect, srcRect); | 344 dstRect, srcRect); |
343 } | 345 } |
344 | 346 |
345 bool SkLightingImageFilterInternal::filterImageGPU(Proxy* proxy, | 347 bool SkLightingImageFilterInternal::filterImageGPU(Proxy* proxy, |
346 const SkBitmap& src, | 348 const SkBitmap& src, |
347 const Context& ctx, | 349 const Context& ctx, |
348 SkBitmap* result, | 350 SkBitmap* result, |
349 SkIPoint* offset) const { | 351 SkIPoint* offset) const { |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
425 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkDiffuseLightingImageFi
lter) | 427 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkDiffuseLightingImageFi
lter) |
426 SkScalar kd() const { return fKD; } | 428 SkScalar kd() const { return fKD; } |
427 | 429 |
428 protected: | 430 protected: |
429 SkDiffuseLightingImageFilter(SkLight* light, SkScalar surfaceScale, | 431 SkDiffuseLightingImageFilter(SkLight* light, SkScalar surfaceScale, |
430 SkScalar kd, SkImageFilter* input, const CropRe
ct* cropRect); | 432 SkScalar kd, SkImageFilter* input, const CropRe
ct* cropRect); |
431 void flatten(SkWriteBuffer& buffer) const override; | 433 void flatten(SkWriteBuffer& buffer) const override; |
432 bool onFilterImage(Proxy*, const SkBitmap& src, const Context&, | 434 bool onFilterImage(Proxy*, const SkBitmap& src, const Context&, |
433 SkBitmap* result, SkIPoint* offset) const override; | 435 SkBitmap* result, SkIPoint* offset) const override; |
434 #if SK_SUPPORT_GPU | 436 #if SK_SUPPORT_GPU |
435 GrFragmentProcessor* getFragmentProcessor(GrTexture*, const SkMatrix&, | 437 GrFragmentProcessor* getFragmentProcessor(GrProcessorDataManager*, GrTexture
*, const SkMatrix&, |
436 const SkIRect& bounds, BoundaryMod
e) const override; | 438 const SkIRect& bounds, BoundaryMod
e) const override; |
437 #endif | 439 #endif |
438 | 440 |
439 private: | 441 private: |
440 friend class SkLightingImageFilter; | 442 friend class SkLightingImageFilter; |
441 typedef SkLightingImageFilterInternal INHERITED; | 443 typedef SkLightingImageFilterInternal INHERITED; |
442 SkScalar fKD; | 444 SkScalar fKD; |
443 }; | 445 }; |
444 | 446 |
445 class SkSpecularLightingImageFilter : public SkLightingImageFilterInternal { | 447 class SkSpecularLightingImageFilter : public SkLightingImageFilterInternal { |
446 public: | 448 public: |
447 static SkImageFilter* Create(SkLight* light, SkScalar surfaceScale, | 449 static SkImageFilter* Create(SkLight* light, SkScalar surfaceScale, |
448 SkScalar ks, SkScalar shininess, SkImageFilter*
, const CropRect*); | 450 SkScalar ks, SkScalar shininess, SkImageFilter*
, const CropRect*); |
449 | 451 |
450 SK_TO_STRING_OVERRIDE() | 452 SK_TO_STRING_OVERRIDE() |
451 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkSpecularLightingImageF
ilter) | 453 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkSpecularLightingImageF
ilter) |
452 | 454 |
453 SkScalar ks() const { return fKS; } | 455 SkScalar ks() const { return fKS; } |
454 SkScalar shininess() const { return fShininess; } | 456 SkScalar shininess() const { return fShininess; } |
455 | 457 |
456 protected: | 458 protected: |
457 SkSpecularLightingImageFilter(SkLight* light, SkScalar surfaceScale, SkScala
r ks, | 459 SkSpecularLightingImageFilter(SkLight* light, SkScalar surfaceScale, SkScala
r ks, |
458 SkScalar shininess, SkImageFilter* input, cons
t CropRect*); | 460 SkScalar shininess, SkImageFilter* input, cons
t CropRect*); |
459 void flatten(SkWriteBuffer& buffer) const override; | 461 void flatten(SkWriteBuffer& buffer) const override; |
460 bool onFilterImage(Proxy*, const SkBitmap& src, const Context&, | 462 bool onFilterImage(Proxy*, const SkBitmap& src, const Context&, |
461 SkBitmap* result, SkIPoint* offset) const override; | 463 SkBitmap* result, SkIPoint* offset) const override; |
462 #if SK_SUPPORT_GPU | 464 #if SK_SUPPORT_GPU |
463 GrFragmentProcessor* getFragmentProcessor(GrTexture*, const SkMatrix&, | 465 GrFragmentProcessor* getFragmentProcessor(GrProcessorDataManager*, GrTexture
*, const SkMatrix&, |
464 const SkIRect& bounds, BoundaryMod
e) const override; | 466 const SkIRect& bounds, BoundaryMod
e) const override; |
465 #endif | 467 #endif |
466 | 468 |
467 private: | 469 private: |
468 SkScalar fKS; | 470 SkScalar fKS; |
469 SkScalar fShininess; | 471 SkScalar fShininess; |
470 friend class SkLightingImageFilter; | 472 friend class SkLightingImageFilter; |
471 typedef SkLightingImageFilterInternal INHERITED; | 473 typedef SkLightingImageFilterInternal INHERITED; |
472 }; | 474 }; |
473 | 475 |
474 #if SK_SUPPORT_GPU | 476 #if SK_SUPPORT_GPU |
475 | 477 |
476 class GrLightingEffect : public GrSingleTextureEffect { | 478 class GrLightingEffect : public GrSingleTextureEffect { |
477 public: | 479 public: |
478 GrLightingEffect(GrTexture* texture, const SkLight* light, SkScalar surfaceS
cale, | 480 GrLightingEffect(GrProcessorDataManager*, GrTexture* texture, const SkLight*
light, |
479 const SkMatrix& matrix, BoundaryMode boundaryMode); | 481 SkScalar surfaceScale, const SkMatrix& matrix, BoundaryMode
boundaryMode); |
480 virtual ~GrLightingEffect(); | 482 virtual ~GrLightingEffect(); |
481 | 483 |
482 const SkLight* light() const { return fLight; } | 484 const SkLight* light() const { return fLight; } |
483 SkScalar surfaceScale() const { return fSurfaceScale; } | 485 SkScalar surfaceScale() const { return fSurfaceScale; } |
484 const SkMatrix& filterMatrix() const { return fFilterMatrix; } | 486 const SkMatrix& filterMatrix() const { return fFilterMatrix; } |
485 BoundaryMode boundaryMode() const { return fBoundaryMode; } | 487 BoundaryMode boundaryMode() const { return fBoundaryMode; } |
486 | 488 |
487 protected: | 489 protected: |
488 bool onIsEqual(const GrFragmentProcessor&) const override; | 490 bool onIsEqual(const GrFragmentProcessor&) const override; |
489 | 491 |
490 void onComputeInvariantOutput(GrInvariantOutput* inout) const override { | 492 void onComputeInvariantOutput(GrInvariantOutput* inout) const override { |
491 // lighting shaders are complicated. We just throw up our hands. | 493 // lighting shaders are complicated. We just throw up our hands. |
492 inout->mulByUnknownFourComponents(); | 494 inout->mulByUnknownFourComponents(); |
493 } | 495 } |
494 | 496 |
495 private: | 497 private: |
496 typedef GrSingleTextureEffect INHERITED; | 498 typedef GrSingleTextureEffect INHERITED; |
497 const SkLight* fLight; | 499 const SkLight* fLight; |
498 SkScalar fSurfaceScale; | 500 SkScalar fSurfaceScale; |
499 SkMatrix fFilterMatrix; | 501 SkMatrix fFilterMatrix; |
500 BoundaryMode fBoundaryMode; | 502 BoundaryMode fBoundaryMode; |
501 }; | 503 }; |
502 | 504 |
503 class GrDiffuseLightingEffect : public GrLightingEffect { | 505 class GrDiffuseLightingEffect : public GrLightingEffect { |
504 public: | 506 public: |
505 static GrFragmentProcessor* Create(GrTexture* texture, | 507 static GrFragmentProcessor* Create(GrProcessorDataManager* procDataManager, |
| 508 GrTexture* texture, |
506 const SkLight* light, | 509 const SkLight* light, |
507 SkScalar surfaceScale, | 510 SkScalar surfaceScale, |
508 const SkMatrix& matrix, | 511 const SkMatrix& matrix, |
509 SkScalar kd, | 512 SkScalar kd, |
510 BoundaryMode boundaryMode) { | 513 BoundaryMode boundaryMode) { |
511 return SkNEW_ARGS(GrDiffuseLightingEffect, (texture, | 514 return SkNEW_ARGS(GrDiffuseLightingEffect, (procDataManager, |
| 515 texture, |
512 light, | 516 light, |
513 surfaceScale, | 517 surfaceScale, |
514 matrix, | 518 matrix, |
515 kd, | 519 kd, |
516 boundaryMode)); | 520 boundaryMode)); |
517 } | 521 } |
518 | 522 |
519 const char* name() const override { return "DiffuseLighting"; } | 523 const char* name() const override { return "DiffuseLighting"; } |
520 | 524 |
521 void getGLProcessorKey(const GrGLSLCaps&, GrProcessorKeyBuilder*) const over
ride; | 525 void getGLProcessorKey(const GrGLSLCaps&, GrProcessorKeyBuilder*) const over
ride; |
522 | 526 |
523 GrGLFragmentProcessor* createGLInstance() const override; | 527 GrGLFragmentProcessor* createGLInstance() const override; |
524 | 528 |
525 SkScalar kd() const { return fKD; } | 529 SkScalar kd() const { return fKD; } |
526 | 530 |
527 private: | 531 private: |
528 bool onIsEqual(const GrFragmentProcessor&) const override; | 532 bool onIsEqual(const GrFragmentProcessor&) const override; |
529 | 533 |
530 GrDiffuseLightingEffect(GrTexture* texture, | 534 GrDiffuseLightingEffect(GrProcessorDataManager*, |
| 535 GrTexture* texture, |
531 const SkLight* light, | 536 const SkLight* light, |
532 SkScalar surfaceScale, | 537 SkScalar surfaceScale, |
533 const SkMatrix& matrix, | 538 const SkMatrix& matrix, |
534 SkScalar kd, | 539 SkScalar kd, |
535 BoundaryMode boundaryMode); | 540 BoundaryMode boundaryMode); |
536 | 541 |
537 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; | 542 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; |
538 typedef GrLightingEffect INHERITED; | 543 typedef GrLightingEffect INHERITED; |
539 SkScalar fKD; | 544 SkScalar fKD; |
540 }; | 545 }; |
541 | 546 |
542 class GrSpecularLightingEffect : public GrLightingEffect { | 547 class GrSpecularLightingEffect : public GrLightingEffect { |
543 public: | 548 public: |
544 static GrFragmentProcessor* Create(GrTexture* texture, | 549 static GrFragmentProcessor* Create(GrProcessorDataManager* procDataManager, |
| 550 GrTexture* texture, |
545 const SkLight* light, | 551 const SkLight* light, |
546 SkScalar surfaceScale, | 552 SkScalar surfaceScale, |
547 const SkMatrix& matrix, | 553 const SkMatrix& matrix, |
548 SkScalar ks, | 554 SkScalar ks, |
549 SkScalar shininess, | 555 SkScalar shininess, |
550 BoundaryMode boundaryMode) { | 556 BoundaryMode boundaryMode) { |
551 return SkNEW_ARGS(GrSpecularLightingEffect, (texture, | 557 return SkNEW_ARGS(GrSpecularLightingEffect, (procDataManager, |
| 558 texture, |
552 light, | 559 light, |
553 surfaceScale, | 560 surfaceScale, |
554 matrix, | 561 matrix, |
555 ks, | 562 ks, |
556 shininess, | 563 shininess, |
557 boundaryMode)); | 564 boundaryMode)); |
558 } | 565 } |
559 | 566 |
560 const char* name() const override { return "SpecularLighting"; } | 567 const char* name() const override { return "SpecularLighting"; } |
561 | 568 |
562 void getGLProcessorKey(const GrGLSLCaps&, GrProcessorKeyBuilder*) const over
ride; | 569 void getGLProcessorKey(const GrGLSLCaps&, GrProcessorKeyBuilder*) const over
ride; |
563 | 570 |
564 GrGLFragmentProcessor* createGLInstance() const override; | 571 GrGLFragmentProcessor* createGLInstance() const override; |
565 | 572 |
566 SkScalar ks() const { return fKS; } | 573 SkScalar ks() const { return fKS; } |
567 SkScalar shininess() const { return fShininess; } | 574 SkScalar shininess() const { return fShininess; } |
568 | 575 |
569 private: | 576 private: |
570 bool onIsEqual(const GrFragmentProcessor&) const override; | 577 bool onIsEqual(const GrFragmentProcessor&) const override; |
571 | 578 |
572 GrSpecularLightingEffect(GrTexture* texture, | 579 GrSpecularLightingEffect(GrProcessorDataManager*, |
| 580 GrTexture* texture, |
573 const SkLight* light, | 581 const SkLight* light, |
574 SkScalar surfaceScale, | 582 SkScalar surfaceScale, |
575 const SkMatrix& matrix, | 583 const SkMatrix& matrix, |
576 SkScalar ks, | 584 SkScalar ks, |
577 SkScalar shininess, | 585 SkScalar shininess, |
578 BoundaryMode boundaryMode); | 586 BoundaryMode boundaryMode); |
579 | 587 |
580 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; | 588 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; |
581 typedef GrLightingEffect INHERITED; | 589 typedef GrLightingEffect INHERITED; |
582 SkScalar fKS; | 590 SkScalar fKS; |
(...skipping 635 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1218 #ifndef SK_IGNORE_TO_STRING | 1226 #ifndef SK_IGNORE_TO_STRING |
1219 void SkDiffuseLightingImageFilter::toString(SkString* str) const { | 1227 void SkDiffuseLightingImageFilter::toString(SkString* str) const { |
1220 str->appendf("SkDiffuseLightingImageFilter: ("); | 1228 str->appendf("SkDiffuseLightingImageFilter: ("); |
1221 str->appendf("kD: %f\n", fKD); | 1229 str->appendf("kD: %f\n", fKD); |
1222 str->append(")"); | 1230 str->append(")"); |
1223 } | 1231 } |
1224 #endif | 1232 #endif |
1225 | 1233 |
1226 #if SK_SUPPORT_GPU | 1234 #if SK_SUPPORT_GPU |
1227 GrFragmentProcessor* SkDiffuseLightingImageFilter::getFragmentProcessor( | 1235 GrFragmentProcessor* SkDiffuseLightingImageFilter::getFragmentProcessor( |
1228 GrTexture* texture, | 1236 GrProcessorDataManager* procD
ataManager, |
1229 const SkMatrix& matrix, | 1237 GrTexture* texture, |
1230 const SkIRect&, | 1238 const SkMatrix& matrix, |
1231 BoundaryMode boundaryMode | 1239 const SkIRect&, |
| 1240 BoundaryMode boundaryMode |
1232 ) const { | 1241 ) const { |
1233 SkScalar scale = SkScalarMul(surfaceScale(), SkIntToScalar(255)); | 1242 SkScalar scale = SkScalarMul(this->surfaceScale(), SkIntToScalar(255)); |
1234 return GrDiffuseLightingEffect::Create(texture, light(), scale, matrix, kd()
, boundaryMode); | 1243 return GrDiffuseLightingEffect::Create(procDataManager, texture, this->light
(), scale, matrix, |
| 1244 this->kd(), boundaryMode); |
1235 } | 1245 } |
1236 #endif | 1246 #endif |
1237 | 1247 |
1238 /////////////////////////////////////////////////////////////////////////////// | 1248 /////////////////////////////////////////////////////////////////////////////// |
1239 | 1249 |
1240 SkImageFilter* SkSpecularLightingImageFilter::Create(SkLight* light, SkScalar su
rfaceScale, | 1250 SkImageFilter* SkSpecularLightingImageFilter::Create(SkLight* light, SkScalar su
rfaceScale, |
1241 SkScalar ks, SkScalar shininess, SkImageFilter* input, const Cro
pRect* cropRect) { | 1251 SkScalar ks, SkScalar shininess, SkImageFilter* input, const Cro
pRect* cropRect) { |
1242 if (NULL == light) { | 1252 if (NULL == light) { |
1243 return NULL; | 1253 return NULL; |
1244 } | 1254 } |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1352 #ifndef SK_IGNORE_TO_STRING | 1362 #ifndef SK_IGNORE_TO_STRING |
1353 void SkSpecularLightingImageFilter::toString(SkString* str) const { | 1363 void SkSpecularLightingImageFilter::toString(SkString* str) const { |
1354 str->appendf("SkSpecularLightingImageFilter: ("); | 1364 str->appendf("SkSpecularLightingImageFilter: ("); |
1355 str->appendf("kS: %f shininess: %f", fKS, fShininess); | 1365 str->appendf("kS: %f shininess: %f", fKS, fShininess); |
1356 str->append(")"); | 1366 str->append(")"); |
1357 } | 1367 } |
1358 #endif | 1368 #endif |
1359 | 1369 |
1360 #if SK_SUPPORT_GPU | 1370 #if SK_SUPPORT_GPU |
1361 GrFragmentProcessor* SkSpecularLightingImageFilter::getFragmentProcessor( | 1371 GrFragmentProcessor* SkSpecularLightingImageFilter::getFragmentProcessor( |
1362 GrTexture* texture, | 1372 GrProcessorDataManager* proc
DataManager, |
1363 const SkMatrix& matrix, | 1373 GrTexture* texture, |
1364 const SkIRect&, | 1374 const SkMatrix& matrix, |
1365 BoundaryMode boundaryMo
de) const { | 1375 const SkIRect&, |
1366 SkScalar scale = SkScalarMul(surfaceScale(), SkIntToScalar(255)); | 1376 BoundaryMode boundaryMode) c
onst { |
1367 return GrSpecularLightingEffect::Create(texture, light(), scale, matrix, ks(
), shininess(), | 1377 SkScalar scale = SkScalarMul(this->surfaceScale(), SkIntToScalar(255)); |
1368 boundaryMode); | 1378 return GrSpecularLightingEffect::Create(procDataManager, texture, this->ligh
t(), scale, matrix, |
| 1379 this->ks(), this->shininess(), bound
aryMode); |
1369 } | 1380 } |
1370 #endif | 1381 #endif |
1371 | 1382 |
1372 /////////////////////////////////////////////////////////////////////////////// | 1383 /////////////////////////////////////////////////////////////////////////////// |
1373 | 1384 |
1374 #if SK_SUPPORT_GPU | 1385 #if SK_SUPPORT_GPU |
1375 | 1386 |
1376 namespace { | 1387 namespace { |
1377 SkPoint3 random_point3(SkRandom* random) { | 1388 SkPoint3 random_point3(SkRandom* random) { |
1378 return SkPoint3(SkScalarToFloat(random->nextSScalar1()), | 1389 return SkPoint3(SkScalarToFloat(random->nextSScalar1()), |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1534 | 1545 |
1535 private: | 1546 private: |
1536 typedef GrGLLightingEffect INHERITED; | 1547 typedef GrGLLightingEffect INHERITED; |
1537 | 1548 |
1538 UniformHandle fKSUni; | 1549 UniformHandle fKSUni; |
1539 UniformHandle fShininessUni; | 1550 UniformHandle fShininessUni; |
1540 }; | 1551 }; |
1541 | 1552 |
1542 /////////////////////////////////////////////////////////////////////////////// | 1553 /////////////////////////////////////////////////////////////////////////////// |
1543 | 1554 |
1544 GrLightingEffect::GrLightingEffect(GrTexture* texture, | 1555 GrLightingEffect::GrLightingEffect(GrProcessorDataManager* procDataManager, |
| 1556 GrTexture* texture, |
1545 const SkLight* light, | 1557 const SkLight* light, |
1546 SkScalar surfaceScale, | 1558 SkScalar surfaceScale, |
1547 const SkMatrix& matrix, | 1559 const SkMatrix& matrix, |
1548 BoundaryMode boundaryMode) | 1560 BoundaryMode boundaryMode) |
1549 : INHERITED(texture, GrCoordTransform::MakeDivByTextureWHMatrix(texture)) | 1561 : INHERITED(procDataManager, texture, GrCoordTransform::MakeDivByTextureWHMa
trix(texture)) |
1550 , fLight(light) | 1562 , fLight(light) |
1551 , fSurfaceScale(surfaceScale) | 1563 , fSurfaceScale(surfaceScale) |
1552 , fFilterMatrix(matrix) | 1564 , fFilterMatrix(matrix) |
1553 , fBoundaryMode(boundaryMode) { | 1565 , fBoundaryMode(boundaryMode) { |
1554 fLight->ref(); | 1566 fLight->ref(); |
1555 if (light->requiresFragmentPosition()) { | 1567 if (light->requiresFragmentPosition()) { |
1556 this->setWillReadFragmentPosition(); | 1568 this->setWillReadFragmentPosition(); |
1557 } | 1569 } |
1558 } | 1570 } |
1559 | 1571 |
1560 GrLightingEffect::~GrLightingEffect() { | 1572 GrLightingEffect::~GrLightingEffect() { |
1561 fLight->unref(); | 1573 fLight->unref(); |
1562 } | 1574 } |
1563 | 1575 |
1564 bool GrLightingEffect::onIsEqual(const GrFragmentProcessor& sBase) const { | 1576 bool GrLightingEffect::onIsEqual(const GrFragmentProcessor& sBase) const { |
1565 const GrLightingEffect& s = sBase.cast<GrLightingEffect>(); | 1577 const GrLightingEffect& s = sBase.cast<GrLightingEffect>(); |
1566 return fLight->isEqual(*s.fLight) && | 1578 return fLight->isEqual(*s.fLight) && |
1567 fSurfaceScale == s.fSurfaceScale && | 1579 fSurfaceScale == s.fSurfaceScale && |
1568 fBoundaryMode == s.fBoundaryMode; | 1580 fBoundaryMode == s.fBoundaryMode; |
1569 } | 1581 } |
1570 | 1582 |
1571 /////////////////////////////////////////////////////////////////////////////// | 1583 /////////////////////////////////////////////////////////////////////////////// |
1572 | 1584 |
1573 GrDiffuseLightingEffect::GrDiffuseLightingEffect(GrTexture* texture, | 1585 GrDiffuseLightingEffect::GrDiffuseLightingEffect(GrProcessorDataManager* procDat
aManager, |
| 1586 GrTexture* texture, |
1574 const SkLight* light, | 1587 const SkLight* light, |
1575 SkScalar surfaceScale, | 1588 SkScalar surfaceScale, |
1576 const SkMatrix& matrix, | 1589 const SkMatrix& matrix, |
1577 SkScalar kd, | 1590 SkScalar kd, |
1578 BoundaryMode boundaryMode) | 1591 BoundaryMode boundaryMode) |
1579 : INHERITED(texture, light, surfaceScale, matrix, boundaryMode), fKD(kd) { | 1592 : INHERITED(procDataManager, texture, light, surfaceScale, matrix, boundaryM
ode), fKD(kd) { |
1580 this->initClassID<GrDiffuseLightingEffect>(); | 1593 this->initClassID<GrDiffuseLightingEffect>(); |
1581 } | 1594 } |
1582 | 1595 |
1583 bool GrDiffuseLightingEffect::onIsEqual(const GrFragmentProcessor& sBase) const
{ | 1596 bool GrDiffuseLightingEffect::onIsEqual(const GrFragmentProcessor& sBase) const
{ |
1584 const GrDiffuseLightingEffect& s = sBase.cast<GrDiffuseLightingEffect>(); | 1597 const GrDiffuseLightingEffect& s = sBase.cast<GrDiffuseLightingEffect>(); |
1585 return INHERITED::onIsEqual(sBase) && | 1598 return INHERITED::onIsEqual(sBase) && |
1586 this->kd() == s.kd(); | 1599 this->kd() == s.kd(); |
1587 } | 1600 } |
1588 | 1601 |
1589 void GrDiffuseLightingEffect::getGLProcessorKey(const GrGLSLCaps& caps, | 1602 void GrDiffuseLightingEffect::getGLProcessorKey(const GrGLSLCaps& caps, |
1590 GrProcessorKeyBuilder* b) const
{ | 1603 GrProcessorKeyBuilder* b) const
{ |
1591 GrGLDiffuseLightingEffect::GenKey(*this, caps, b); | 1604 GrGLDiffuseLightingEffect::GenKey(*this, caps, b); |
1592 } | 1605 } |
1593 | 1606 |
1594 GrGLFragmentProcessor* GrDiffuseLightingEffect::createGLInstance() const { | 1607 GrGLFragmentProcessor* GrDiffuseLightingEffect::createGLInstance() const { |
1595 return SkNEW_ARGS(GrGLDiffuseLightingEffect, (*this)); | 1608 return SkNEW_ARGS(GrGLDiffuseLightingEffect, (*this)); |
1596 } | 1609 } |
1597 | 1610 |
1598 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrDiffuseLightingEffect); | 1611 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrDiffuseLightingEffect); |
1599 | 1612 |
1600 GrFragmentProcessor* GrDiffuseLightingEffect::TestCreate(GrProcessorTestData* d)
{ | 1613 GrFragmentProcessor* GrDiffuseLightingEffect::TestCreate(GrProcessorTestData* d)
{ |
1601 SkScalar surfaceScale = d->fRandom->nextSScalar1(); | 1614 SkScalar surfaceScale = d->fRandom->nextSScalar1(); |
1602 SkScalar kd = d->fRandom->nextUScalar1(); | 1615 SkScalar kd = d->fRandom->nextUScalar1(); |
1603 SkAutoTUnref<SkLight> light(create_random_light(d->fRandom)); | 1616 SkAutoTUnref<SkLight> light(create_random_light(d->fRandom)); |
1604 SkMatrix matrix; | 1617 SkMatrix matrix; |
1605 for (int i = 0; i < 9; i++) { | 1618 for (int i = 0; i < 9; i++) { |
1606 matrix[i] = d->fRandom->nextUScalar1(); | 1619 matrix[i] = d->fRandom->nextUScalar1(); |
1607 } | 1620 } |
1608 BoundaryMode mode = static_cast<BoundaryMode>(d->fRandom->nextU() % kBoundar
yModeCount); | 1621 BoundaryMode mode = static_cast<BoundaryMode>(d->fRandom->nextU() % kBoundar
yModeCount); |
1609 return GrDiffuseLightingEffect::Create(d->fTextures[GrProcessorUnitTest::kAl
phaTextureIdx], | 1622 return GrDiffuseLightingEffect::Create(d->fProcDataManager, |
| 1623 d->fTextures[GrProcessorUnitTest::kAl
phaTextureIdx], |
1610 light, surfaceScale, matrix, kd, mode
); | 1624 light, surfaceScale, matrix, kd, mode
); |
1611 } | 1625 } |
1612 | 1626 |
1613 | 1627 |
1614 /////////////////////////////////////////////////////////////////////////////// | 1628 /////////////////////////////////////////////////////////////////////////////// |
1615 | 1629 |
1616 GrGLLightingEffect::GrGLLightingEffect(const GrProcessor& fp) { | 1630 GrGLLightingEffect::GrGLLightingEffect(const GrProcessor& fp) { |
1617 const GrLightingEffect& m = fp.cast<GrLightingEffect>(); | 1631 const GrLightingEffect& m = fp.cast<GrLightingEffect>(); |
1618 fLight = m.light()->createGLLight(); | 1632 fLight = m.light()->createGLLight(); |
1619 fBoundaryMode = m.boundaryMode(); | 1633 fBoundaryMode = m.boundaryMode(); |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1764 | 1778 |
1765 void GrGLDiffuseLightingEffect::setData(const GrGLProgramDataManager& pdman, | 1779 void GrGLDiffuseLightingEffect::setData(const GrGLProgramDataManager& pdman, |
1766 const GrProcessor& proc) { | 1780 const GrProcessor& proc) { |
1767 INHERITED::setData(pdman, proc); | 1781 INHERITED::setData(pdman, proc); |
1768 const GrDiffuseLightingEffect& diffuse = proc.cast<GrDiffuseLightingEffect>(
); | 1782 const GrDiffuseLightingEffect& diffuse = proc.cast<GrDiffuseLightingEffect>(
); |
1769 pdman.set1f(fKDUni, diffuse.kd()); | 1783 pdman.set1f(fKDUni, diffuse.kd()); |
1770 } | 1784 } |
1771 | 1785 |
1772 /////////////////////////////////////////////////////////////////////////////// | 1786 /////////////////////////////////////////////////////////////////////////////// |
1773 | 1787 |
1774 GrSpecularLightingEffect::GrSpecularLightingEffect(GrTexture* texture, | 1788 GrSpecularLightingEffect::GrSpecularLightingEffect(GrProcessorDataManager* procD
ataManager, |
| 1789 GrTexture* texture, |
1775 const SkLight* light, | 1790 const SkLight* light, |
1776 SkScalar surfaceScale, | 1791 SkScalar surfaceScale, |
1777 const SkMatrix& matrix, | 1792 const SkMatrix& matrix, |
1778 SkScalar ks, | 1793 SkScalar ks, |
1779 SkScalar shininess, | 1794 SkScalar shininess, |
1780 BoundaryMode boundaryMode) | 1795 BoundaryMode boundaryMode) |
1781 : INHERITED(texture, light, surfaceScale, matrix, boundaryMode), | 1796 : INHERITED(procDataManager, texture, light, surfaceScale, matrix, boundaryM
ode), |
1782 fKS(ks), | 1797 fKS(ks), |
1783 fShininess(shininess) { | 1798 fShininess(shininess) { |
1784 this->initClassID<GrSpecularLightingEffect>(); | 1799 this->initClassID<GrSpecularLightingEffect>(); |
1785 } | 1800 } |
1786 | 1801 |
1787 bool GrSpecularLightingEffect::onIsEqual(const GrFragmentProcessor& sBase) const
{ | 1802 bool GrSpecularLightingEffect::onIsEqual(const GrFragmentProcessor& sBase) const
{ |
1788 const GrSpecularLightingEffect& s = sBase.cast<GrSpecularLightingEffect>(); | 1803 const GrSpecularLightingEffect& s = sBase.cast<GrSpecularLightingEffect>(); |
1789 return INHERITED::onIsEqual(sBase) && | 1804 return INHERITED::onIsEqual(sBase) && |
1790 this->ks() == s.ks() && | 1805 this->ks() == s.ks() && |
1791 this->shininess() == s.shininess(); | 1806 this->shininess() == s.shininess(); |
(...skipping 13 matching lines...) Expand all Loading... |
1805 GrFragmentProcessor* GrSpecularLightingEffect::TestCreate(GrProcessorTestData* d
) { | 1820 GrFragmentProcessor* GrSpecularLightingEffect::TestCreate(GrProcessorTestData* d
) { |
1806 SkScalar surfaceScale = d->fRandom->nextSScalar1(); | 1821 SkScalar surfaceScale = d->fRandom->nextSScalar1(); |
1807 SkScalar ks = d->fRandom->nextUScalar1(); | 1822 SkScalar ks = d->fRandom->nextUScalar1(); |
1808 SkScalar shininess = d->fRandom->nextUScalar1(); | 1823 SkScalar shininess = d->fRandom->nextUScalar1(); |
1809 SkAutoTUnref<SkLight> light(create_random_light(d->fRandom)); | 1824 SkAutoTUnref<SkLight> light(create_random_light(d->fRandom)); |
1810 SkMatrix matrix; | 1825 SkMatrix matrix; |
1811 for (int i = 0; i < 9; i++) { | 1826 for (int i = 0; i < 9; i++) { |
1812 matrix[i] = d->fRandom->nextUScalar1(); | 1827 matrix[i] = d->fRandom->nextUScalar1(); |
1813 } | 1828 } |
1814 BoundaryMode mode = static_cast<BoundaryMode>(d->fRandom->nextU() % kBoundar
yModeCount); | 1829 BoundaryMode mode = static_cast<BoundaryMode>(d->fRandom->nextU() % kBoundar
yModeCount); |
1815 return GrSpecularLightingEffect::Create(d->fTextures[GrProcessorUnitTest::kA
lphaTextureIdx], | 1830 return GrSpecularLightingEffect::Create(d->fProcDataManager, |
| 1831 d->fTextures[GrProcessorUnitTest::kA
lphaTextureIdx], |
1816 light, surfaceScale, matrix, ks, shi
niness, mode); | 1832 light, surfaceScale, matrix, ks, shi
niness, mode); |
1817 } | 1833 } |
1818 | 1834 |
1819 /////////////////////////////////////////////////////////////////////////////// | 1835 /////////////////////////////////////////////////////////////////////////////// |
1820 | 1836 |
1821 GrGLSpecularLightingEffect::GrGLSpecularLightingEffect(const GrProcessor& proc) | 1837 GrGLSpecularLightingEffect::GrGLSpecularLightingEffect(const GrProcessor& proc) |
1822 : INHERITED(proc) { | 1838 : INHERITED(proc) { |
1823 } | 1839 } |
1824 | 1840 |
1825 void GrGLSpecularLightingEffect::emitLightFunc(GrGLFPBuilder* builder, SkString*
funcName) { | 1841 void GrGLSpecularLightingEffect::emitLightFunc(GrGLFPBuilder* builder, SkString*
funcName) { |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1990 | 2006 |
1991 fsBuilder->codeAppendf("%s(%s)", fLightColorFunc.c_str(), surfaceToLight); | 2007 fsBuilder->codeAppendf("%s(%s)", fLightColorFunc.c_str(), surfaceToLight); |
1992 } | 2008 } |
1993 | 2009 |
1994 #endif | 2010 #endif |
1995 | 2011 |
1996 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingImageFilter) | 2012 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingImageFilter) |
1997 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDiffuseLightingImageFilter) | 2013 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDiffuseLightingImageFilter) |
1998 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSpecularLightingImageFilter) | 2014 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSpecularLightingImageFilter) |
1999 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END | 2015 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END |
OLD | NEW |