Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(61)

Side by Side Diff: src/effects/SkLightingImageFilter.cpp

Issue 1388113002: Bye bye processor data manager (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: remove files Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/effects/SkGpuBlurUtils.cpp ('k') | src/effects/SkLumaColorFilter.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 SkLightingImageFilterInternal(SkImageFilterLight* light, 314 SkLightingImageFilterInternal(SkImageFilterLight* light,
315 SkScalar surfaceScale, 315 SkScalar surfaceScale,
316 SkImageFilter* input, 316 SkImageFilter* input,
317 const CropRect* cropRect) 317 const CropRect* cropRect)
318 : INHERITED(light, surfaceScale, input, cropRect) {} 318 : INHERITED(light, surfaceScale, input, cropRect) {}
319 319
320 #if SK_SUPPORT_GPU 320 #if SK_SUPPORT_GPU
321 bool canFilterImageGPU() const override { return true; } 321 bool canFilterImageGPU() const override { return true; }
322 bool filterImageGPU(Proxy*, const SkBitmap& src, const Context&, 322 bool filterImageGPU(Proxy*, const SkBitmap& src, const Context&,
323 SkBitmap* result, SkIPoint* offset) const override; 323 SkBitmap* result, SkIPoint* offset) const override;
324 virtual GrFragmentProcessor* getFragmentProcessor(GrProcessorDataManager*, 324 virtual GrFragmentProcessor* getFragmentProcessor(GrTexture*,
325 GrTexture*,
326 const SkMatrix&, 325 const SkMatrix&,
327 const SkIRect& bounds, 326 const SkIRect& bounds,
328 BoundaryMode boundaryMode) const = 0; 327 BoundaryMode boundaryMode) const = 0;
329 #endif 328 #endif
330 private: 329 private:
331 #if SK_SUPPORT_GPU 330 #if SK_SUPPORT_GPU
332 void drawRect(GrDrawContext* drawContext, 331 void drawRect(GrDrawContext* drawContext,
333 GrTexture* src, 332 GrTexture* src,
334 GrTexture* dst, 333 GrTexture* dst,
335 const SkMatrix& matrix, 334 const SkMatrix& matrix,
336 const GrClip& clip, 335 const GrClip& clip,
337 const SkRect& dstRect, 336 const SkRect& dstRect,
338 BoundaryMode boundaryMode, 337 BoundaryMode boundaryMode,
339 const SkIRect& bounds) const; 338 const SkIRect& bounds) const;
340 #endif 339 #endif
341 typedef SkLightingImageFilter INHERITED; 340 typedef SkLightingImageFilter INHERITED;
342 }; 341 };
343 342
344 #if SK_SUPPORT_GPU 343 #if SK_SUPPORT_GPU
345 void SkLightingImageFilterInternal::drawRect(GrDrawContext* drawContext, 344 void SkLightingImageFilterInternal::drawRect(GrDrawContext* drawContext,
346 GrTexture* src, 345 GrTexture* src,
347 GrTexture* dst, 346 GrTexture* dst,
348 const SkMatrix& matrix, 347 const SkMatrix& matrix,
349 const GrClip& clip, 348 const GrClip& clip,
350 const SkRect& dstRect, 349 const SkRect& dstRect,
351 BoundaryMode boundaryMode, 350 BoundaryMode boundaryMode,
352 const SkIRect& bounds) const { 351 const SkIRect& bounds) const {
353 SkRect srcRect = dstRect.makeOffset(SkIntToScalar(bounds.x()), SkIntToScalar (bounds.y())); 352 SkRect srcRect = dstRect.makeOffset(SkIntToScalar(bounds.x()), SkIntToScalar (bounds.y()));
354 GrPaint paint; 353 GrPaint paint;
355 GrFragmentProcessor* fp = this->getFragmentProcessor(paint.getProcessorDataM anager(), src, 354 GrFragmentProcessor* fp = this->getFragmentProcessor(src, matrix, bounds, bo undaryMode);
356 matrix, bounds, boundar yMode);
357 paint.addColorFragmentProcessor(fp)->unref(); 355 paint.addColorFragmentProcessor(fp)->unref();
358 drawContext->drawNonAARectToRect(dst->asRenderTarget(), clip, paint, SkMatri x::I(), 356 drawContext->drawNonAARectToRect(dst->asRenderTarget(), clip, paint, SkMatri x::I(),
359 dstRect, srcRect); 357 dstRect, srcRect);
360 } 358 }
361 359
362 bool SkLightingImageFilterInternal::filterImageGPU(Proxy* proxy, 360 bool SkLightingImageFilterInternal::filterImageGPU(Proxy* proxy,
363 const SkBitmap& src, 361 const SkBitmap& src,
364 const Context& ctx, 362 const Context& ctx,
365 SkBitmap* result, 363 SkBitmap* result,
366 SkIPoint* offset) const { 364 SkIPoint* offset) const {
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
442 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkDiffuseLightingImageFi lter) 440 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkDiffuseLightingImageFi lter)
443 SkScalar kd() const { return fKD; } 441 SkScalar kd() const { return fKD; }
444 442
445 protected: 443 protected:
446 SkDiffuseLightingImageFilter(SkImageFilterLight* light, SkScalar surfaceScal e, 444 SkDiffuseLightingImageFilter(SkImageFilterLight* light, SkScalar surfaceScal e,
447 SkScalar kd, SkImageFilter* input, const CropRe ct* cropRect); 445 SkScalar kd, SkImageFilter* input, const CropRe ct* cropRect);
448 void flatten(SkWriteBuffer& buffer) const override; 446 void flatten(SkWriteBuffer& buffer) const override;
449 bool onFilterImage(Proxy*, const SkBitmap& src, const Context&, 447 bool onFilterImage(Proxy*, const SkBitmap& src, const Context&,
450 SkBitmap* result, SkIPoint* offset) const override; 448 SkBitmap* result, SkIPoint* offset) const override;
451 #if SK_SUPPORT_GPU 449 #if SK_SUPPORT_GPU
452 GrFragmentProcessor* getFragmentProcessor(GrProcessorDataManager*, GrTexture *, const SkMatrix&, 450 GrFragmentProcessor* getFragmentProcessor(GrTexture*, const SkMatrix&, const SkIRect& bounds,
453 const SkIRect& bounds, BoundaryMod e) const override; 451 BoundaryMode) const override;
454 #endif 452 #endif
455 453
456 private: 454 private:
457 friend class SkLightingImageFilter; 455 friend class SkLightingImageFilter;
458 typedef SkLightingImageFilterInternal INHERITED; 456 typedef SkLightingImageFilterInternal INHERITED;
459 SkScalar fKD; 457 SkScalar fKD;
460 }; 458 };
461 459
462 class SkSpecularLightingImageFilter : public SkLightingImageFilterInternal { 460 class SkSpecularLightingImageFilter : public SkLightingImageFilterInternal {
463 public: 461 public:
464 static SkImageFilter* Create(SkImageFilterLight* light, SkScalar surfaceScal e, 462 static SkImageFilter* Create(SkImageFilterLight* light, SkScalar surfaceScal e,
465 SkScalar ks, SkScalar shininess, SkImageFilter* , const CropRect*); 463 SkScalar ks, SkScalar shininess, SkImageFilter* , const CropRect*);
466 464
467 SK_TO_STRING_OVERRIDE() 465 SK_TO_STRING_OVERRIDE()
468 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkSpecularLightingImageF ilter) 466 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkSpecularLightingImageF ilter)
469 467
470 SkScalar ks() const { return fKS; } 468 SkScalar ks() const { return fKS; }
471 SkScalar shininess() const { return fShininess; } 469 SkScalar shininess() const { return fShininess; }
472 470
473 protected: 471 protected:
474 SkSpecularLightingImageFilter(SkImageFilterLight* light, SkScalar surfaceSca le, SkScalar ks, 472 SkSpecularLightingImageFilter(SkImageFilterLight* light, SkScalar surfaceSca le, SkScalar ks,
475 SkScalar shininess, SkImageFilter* input, cons t CropRect*); 473 SkScalar shininess, SkImageFilter* input, cons t CropRect*);
476 void flatten(SkWriteBuffer& buffer) const override; 474 void flatten(SkWriteBuffer& buffer) const override;
477 bool onFilterImage(Proxy*, const SkBitmap& src, const Context&, 475 bool onFilterImage(Proxy*, const SkBitmap& src, const Context&,
478 SkBitmap* result, SkIPoint* offset) const override; 476 SkBitmap* result, SkIPoint* offset) const override;
479 #if SK_SUPPORT_GPU 477 #if SK_SUPPORT_GPU
480 GrFragmentProcessor* getFragmentProcessor(GrProcessorDataManager*, GrTexture *, const SkMatrix&, 478 GrFragmentProcessor* getFragmentProcessor(GrTexture*, const SkMatrix&, const SkIRect& bounds,
481 const SkIRect& bounds, BoundaryMod e) const override; 479 BoundaryMode) const override;
482 #endif 480 #endif
483 481
484 private: 482 private:
485 SkScalar fKS; 483 SkScalar fKS;
486 SkScalar fShininess; 484 SkScalar fShininess;
487 friend class SkLightingImageFilter; 485 friend class SkLightingImageFilter;
488 typedef SkLightingImageFilterInternal INHERITED; 486 typedef SkLightingImageFilterInternal INHERITED;
489 }; 487 };
490 488
491 #if SK_SUPPORT_GPU 489 #if SK_SUPPORT_GPU
492 490
493 class GrLightingEffect : public GrSingleTextureEffect { 491 class GrLightingEffect : public GrSingleTextureEffect {
494 public: 492 public:
495 GrLightingEffect(GrProcessorDataManager*, GrTexture* texture, const SkImageF ilterLight* light, 493 GrLightingEffect(GrTexture* texture, const SkImageFilterLight* light, SkScal ar surfaceScale,
496 SkScalar surfaceScale, const SkMatrix& matrix, BoundaryMode boundaryMode); 494 const SkMatrix& matrix, BoundaryMode boundaryMode);
497 virtual ~GrLightingEffect(); 495 virtual ~GrLightingEffect();
498 496
499 const SkImageFilterLight* light() const { return fLight; } 497 const SkImageFilterLight* light() const { return fLight; }
500 SkScalar surfaceScale() const { return fSurfaceScale; } 498 SkScalar surfaceScale() const { return fSurfaceScale; }
501 const SkMatrix& filterMatrix() const { return fFilterMatrix; } 499 const SkMatrix& filterMatrix() const { return fFilterMatrix; }
502 BoundaryMode boundaryMode() const { return fBoundaryMode; } 500 BoundaryMode boundaryMode() const { return fBoundaryMode; }
503 501
504 protected: 502 protected:
505 bool onIsEqual(const GrFragmentProcessor&) const override; 503 bool onIsEqual(const GrFragmentProcessor&) const override;
506 504
507 void onComputeInvariantOutput(GrInvariantOutput* inout) const override { 505 void onComputeInvariantOutput(GrInvariantOutput* inout) const override {
508 // lighting shaders are complicated. We just throw up our hands. 506 // lighting shaders are complicated. We just throw up our hands.
509 inout->mulByUnknownFourComponents(); 507 inout->mulByUnknownFourComponents();
510 } 508 }
511 509
512 private: 510 private:
513 const SkImageFilterLight* fLight; 511 const SkImageFilterLight* fLight;
514 SkScalar fSurfaceScale; 512 SkScalar fSurfaceScale;
515 SkMatrix fFilterMatrix; 513 SkMatrix fFilterMatrix;
516 BoundaryMode fBoundaryMode; 514 BoundaryMode fBoundaryMode;
517 515
518 typedef GrSingleTextureEffect INHERITED; 516 typedef GrSingleTextureEffect INHERITED;
519 }; 517 };
520 518
521 class GrDiffuseLightingEffect : public GrLightingEffect { 519 class GrDiffuseLightingEffect : public GrLightingEffect {
522 public: 520 public:
523 static GrFragmentProcessor* Create(GrProcessorDataManager* procDataManager, 521 static GrFragmentProcessor* Create(GrTexture* texture,
524 GrTexture* texture,
525 const SkImageFilterLight* light, 522 const SkImageFilterLight* light,
526 SkScalar surfaceScale, 523 SkScalar surfaceScale,
527 const SkMatrix& matrix, 524 const SkMatrix& matrix,
528 SkScalar kd, 525 SkScalar kd,
529 BoundaryMode boundaryMode) { 526 BoundaryMode boundaryMode) {
530 return new GrDiffuseLightingEffect(procDataManager, texture, light, surf aceScale, matrix, 527 return new GrDiffuseLightingEffect(texture, light, surfaceScale, matrix, kd, boundaryMode);
531 kd, boundaryMode);
532 } 528 }
533 529
534 const char* name() const override { return "DiffuseLighting"; } 530 const char* name() const override { return "DiffuseLighting"; }
535 531
536 SkScalar kd() const { return fKD; } 532 SkScalar kd() const { return fKD; }
537 533
538 private: 534 private:
539 GrGLFragmentProcessor* onCreateGLInstance() const override; 535 GrGLFragmentProcessor* onCreateGLInstance() const override;
540 536
541 void onGetGLProcessorKey(const GrGLSLCaps&, GrProcessorKeyBuilder*) const ov erride; 537 void onGetGLProcessorKey(const GrGLSLCaps&, GrProcessorKeyBuilder*) const ov erride;
542 538
543 bool onIsEqual(const GrFragmentProcessor&) const override; 539 bool onIsEqual(const GrFragmentProcessor&) const override;
544 540
545 GrDiffuseLightingEffect(GrProcessorDataManager*, 541 GrDiffuseLightingEffect(GrTexture* texture,
546 GrTexture* texture,
547 const SkImageFilterLight* light, 542 const SkImageFilterLight* light,
548 SkScalar surfaceScale, 543 SkScalar surfaceScale,
549 const SkMatrix& matrix, 544 const SkMatrix& matrix,
550 SkScalar kd, 545 SkScalar kd,
551 BoundaryMode boundaryMode); 546 BoundaryMode boundaryMode);
552 547
553 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; 548 GR_DECLARE_FRAGMENT_PROCESSOR_TEST;
554 typedef GrLightingEffect INHERITED; 549 typedef GrLightingEffect INHERITED;
555 SkScalar fKD; 550 SkScalar fKD;
556 }; 551 };
557 552
558 class GrSpecularLightingEffect : public GrLightingEffect { 553 class GrSpecularLightingEffect : public GrLightingEffect {
559 public: 554 public:
560 static GrFragmentProcessor* Create(GrProcessorDataManager* procDataManager, 555 static GrFragmentProcessor* Create(GrTexture* texture,
561 GrTexture* texture,
562 const SkImageFilterLight* light, 556 const SkImageFilterLight* light,
563 SkScalar surfaceScale, 557 SkScalar surfaceScale,
564 const SkMatrix& matrix, 558 const SkMatrix& matrix,
565 SkScalar ks, 559 SkScalar ks,
566 SkScalar shininess, 560 SkScalar shininess,
567 BoundaryMode boundaryMode) { 561 BoundaryMode boundaryMode) {
568 return new GrSpecularLightingEffect(procDataManager, texture, light, sur faceScale, matrix, 562 return new GrSpecularLightingEffect(texture, light, surfaceScale, matrix , ks, shininess,
569 ks, shininess, boundaryMode); 563 boundaryMode);
570 } 564 }
571 565
572 const char* name() const override { return "SpecularLighting"; } 566 const char* name() const override { return "SpecularLighting"; }
573 567
574 GrGLFragmentProcessor* onCreateGLInstance() const override; 568 GrGLFragmentProcessor* onCreateGLInstance() const override;
575 569
576 SkScalar ks() const { return fKS; } 570 SkScalar ks() const { return fKS; }
577 SkScalar shininess() const { return fShininess; } 571 SkScalar shininess() const { return fShininess; }
578 572
579 private: 573 private:
580 void onGetGLProcessorKey(const GrGLSLCaps&, GrProcessorKeyBuilder*) const ov erride; 574 void onGetGLProcessorKey(const GrGLSLCaps&, GrProcessorKeyBuilder*) const ov erride;
581 575
582 bool onIsEqual(const GrFragmentProcessor&) const override; 576 bool onIsEqual(const GrFragmentProcessor&) const override;
583 577
584 GrSpecularLightingEffect(GrProcessorDataManager*, 578 GrSpecularLightingEffect(GrTexture* texture,
585 GrTexture* texture,
586 const SkImageFilterLight* light, 579 const SkImageFilterLight* light,
587 SkScalar surfaceScale, 580 SkScalar surfaceScale,
588 const SkMatrix& matrix, 581 const SkMatrix& matrix,
589 SkScalar ks, 582 SkScalar ks,
590 SkScalar shininess, 583 SkScalar shininess,
591 BoundaryMode boundaryMode); 584 BoundaryMode boundaryMode);
592 585
593 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; 586 GR_DECLARE_FRAGMENT_PROCESSOR_TEST;
594 typedef GrLightingEffect INHERITED; 587 typedef GrLightingEffect INHERITED;
595 SkScalar fKS; 588 SkScalar fKS;
(...skipping 652 matching lines...) Expand 10 before | Expand all | Expand 10 after
1248 #ifndef SK_IGNORE_TO_STRING 1241 #ifndef SK_IGNORE_TO_STRING
1249 void SkDiffuseLightingImageFilter::toString(SkString* str) const { 1242 void SkDiffuseLightingImageFilter::toString(SkString* str) const {
1250 str->appendf("SkDiffuseLightingImageFilter: ("); 1243 str->appendf("SkDiffuseLightingImageFilter: (");
1251 str->appendf("kD: %f\n", fKD); 1244 str->appendf("kD: %f\n", fKD);
1252 str->append(")"); 1245 str->append(")");
1253 } 1246 }
1254 #endif 1247 #endif
1255 1248
1256 #if SK_SUPPORT_GPU 1249 #if SK_SUPPORT_GPU
1257 GrFragmentProcessor* SkDiffuseLightingImageFilter::getFragmentProcessor( 1250 GrFragmentProcessor* SkDiffuseLightingImageFilter::getFragmentProcessor(
1258 GrProcessorDataManager* procD ataManager,
1259 GrTexture* texture, 1251 GrTexture* texture,
1260 const SkMatrix& matrix, 1252 const SkMatrix& matrix,
1261 const SkIRect&, 1253 const SkIRect&,
1262 BoundaryMode boundaryMode 1254 BoundaryMode boundaryMode
1263 ) const { 1255 ) const {
1264 SkScalar scale = SkScalarMul(this->surfaceScale(), SkIntToScalar(255)); 1256 SkScalar scale = SkScalarMul(this->surfaceScale(), SkIntToScalar(255));
1265 return GrDiffuseLightingEffect::Create(procDataManager, texture, this->light (), scale, matrix, 1257 return GrDiffuseLightingEffect::Create(texture, this->light(), scale, matrix , this->kd(),
1266 this->kd(), boundaryMode); 1258 boundaryMode);
1267 } 1259 }
1268 #endif 1260 #endif
1269 1261
1270 /////////////////////////////////////////////////////////////////////////////// 1262 ///////////////////////////////////////////////////////////////////////////////
1271 1263
1272 SkImageFilter* SkSpecularLightingImageFilter::Create(SkImageFilterLight* light, 1264 SkImageFilter* SkSpecularLightingImageFilter::Create(SkImageFilterLight* light,
1273 SkScalar surfaceScale, 1265 SkScalar surfaceScale,
1274 SkScalar ks, 1266 SkScalar ks,
1275 SkScalar shininess, 1267 SkScalar shininess,
1276 SkImageFilter* input, 1268 SkImageFilter* input,
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
1389 #ifndef SK_IGNORE_TO_STRING 1381 #ifndef SK_IGNORE_TO_STRING
1390 void SkSpecularLightingImageFilter::toString(SkString* str) const { 1382 void SkSpecularLightingImageFilter::toString(SkString* str) const {
1391 str->appendf("SkSpecularLightingImageFilter: ("); 1383 str->appendf("SkSpecularLightingImageFilter: (");
1392 str->appendf("kS: %f shininess: %f", fKS, fShininess); 1384 str->appendf("kS: %f shininess: %f", fKS, fShininess);
1393 str->append(")"); 1385 str->append(")");
1394 } 1386 }
1395 #endif 1387 #endif
1396 1388
1397 #if SK_SUPPORT_GPU 1389 #if SK_SUPPORT_GPU
1398 GrFragmentProcessor* SkSpecularLightingImageFilter::getFragmentProcessor( 1390 GrFragmentProcessor* SkSpecularLightingImageFilter::getFragmentProcessor(
1399 GrProcessorDataManager* proc DataManager,
1400 GrTexture* texture, 1391 GrTexture* texture,
1401 const SkMatrix& matrix, 1392 const SkMatrix& matrix,
1402 const SkIRect&, 1393 const SkIRect&,
1403 BoundaryMode boundaryMode) c onst { 1394 BoundaryMode boundaryMode) c onst {
1404 SkScalar scale = SkScalarMul(this->surfaceScale(), SkIntToScalar(255)); 1395 SkScalar scale = SkScalarMul(this->surfaceScale(), SkIntToScalar(255));
1405 return GrSpecularLightingEffect::Create(procDataManager, texture, this->ligh t(), scale, matrix, 1396 return GrSpecularLightingEffect::Create(texture, this->light(), scale, matri x, this->ks(),
1406 this->ks(), this->shininess(), bound aryMode); 1397 this->shininess(), boundaryMode);
1407 } 1398 }
1408 #endif 1399 #endif
1409 1400
1410 /////////////////////////////////////////////////////////////////////////////// 1401 ///////////////////////////////////////////////////////////////////////////////
1411 1402
1412 #if SK_SUPPORT_GPU 1403 #if SK_SUPPORT_GPU
1413 1404
1414 namespace { 1405 namespace {
1415 SkPoint3 random_point3(SkRandom* random) { 1406 SkPoint3 random_point3(SkRandom* random) {
1416 return SkPoint3::Make(SkScalarToFloat(random->nextSScalar1()), 1407 return SkPoint3::Make(SkScalarToFloat(random->nextSScalar1()),
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
1568 1559
1569 private: 1560 private:
1570 typedef GrGLLightingEffect INHERITED; 1561 typedef GrGLLightingEffect INHERITED;
1571 1562
1572 UniformHandle fKSUni; 1563 UniformHandle fKSUni;
1573 UniformHandle fShininessUni; 1564 UniformHandle fShininessUni;
1574 }; 1565 };
1575 1566
1576 /////////////////////////////////////////////////////////////////////////////// 1567 ///////////////////////////////////////////////////////////////////////////////
1577 1568
1578 GrLightingEffect::GrLightingEffect(GrProcessorDataManager* procDataManager, 1569 GrLightingEffect::GrLightingEffect(GrTexture* texture,
1579 GrTexture* texture,
1580 const SkImageFilterLight* light, 1570 const SkImageFilterLight* light,
1581 SkScalar surfaceScale, 1571 SkScalar surfaceScale,
1582 const SkMatrix& matrix, 1572 const SkMatrix& matrix,
1583 BoundaryMode boundaryMode) 1573 BoundaryMode boundaryMode)
1584 : INHERITED(procDataManager, texture, GrCoordTransform::MakeDivByTextureWHMa trix(texture)) 1574 : INHERITED(texture, GrCoordTransform::MakeDivByTextureWHMatrix(texture))
1585 , fLight(light) 1575 , fLight(light)
1586 , fSurfaceScale(surfaceScale) 1576 , fSurfaceScale(surfaceScale)
1587 , fFilterMatrix(matrix) 1577 , fFilterMatrix(matrix)
1588 , fBoundaryMode(boundaryMode) { 1578 , fBoundaryMode(boundaryMode) {
1589 fLight->ref(); 1579 fLight->ref();
1590 if (light->requiresFragmentPosition()) { 1580 if (light->requiresFragmentPosition()) {
1591 this->setWillReadFragmentPosition(); 1581 this->setWillReadFragmentPosition();
1592 } 1582 }
1593 } 1583 }
1594 1584
1595 GrLightingEffect::~GrLightingEffect() { 1585 GrLightingEffect::~GrLightingEffect() {
1596 fLight->unref(); 1586 fLight->unref();
1597 } 1587 }
1598 1588
1599 bool GrLightingEffect::onIsEqual(const GrFragmentProcessor& sBase) const { 1589 bool GrLightingEffect::onIsEqual(const GrFragmentProcessor& sBase) const {
1600 const GrLightingEffect& s = sBase.cast<GrLightingEffect>(); 1590 const GrLightingEffect& s = sBase.cast<GrLightingEffect>();
1601 return fLight->isEqual(*s.fLight) && 1591 return fLight->isEqual(*s.fLight) &&
1602 fSurfaceScale == s.fSurfaceScale && 1592 fSurfaceScale == s.fSurfaceScale &&
1603 fBoundaryMode == s.fBoundaryMode; 1593 fBoundaryMode == s.fBoundaryMode;
1604 } 1594 }
1605 1595
1606 /////////////////////////////////////////////////////////////////////////////// 1596 ///////////////////////////////////////////////////////////////////////////////
1607 1597
1608 GrDiffuseLightingEffect::GrDiffuseLightingEffect(GrProcessorDataManager* procDat aManager, 1598 GrDiffuseLightingEffect::GrDiffuseLightingEffect(GrTexture* texture,
1609 GrTexture* texture,
1610 const SkImageFilterLight* light , 1599 const SkImageFilterLight* light ,
1611 SkScalar surfaceScale, 1600 SkScalar surfaceScale,
1612 const SkMatrix& matrix, 1601 const SkMatrix& matrix,
1613 SkScalar kd, 1602 SkScalar kd,
1614 BoundaryMode boundaryMode) 1603 BoundaryMode boundaryMode)
1615 : INHERITED(procDataManager, texture, light, surfaceScale, matrix, boundaryM ode), fKD(kd) { 1604 : INHERITED(texture, light, surfaceScale, matrix, boundaryMode), fKD(kd) {
1616 this->initClassID<GrDiffuseLightingEffect>(); 1605 this->initClassID<GrDiffuseLightingEffect>();
1617 } 1606 }
1618 1607
1619 bool GrDiffuseLightingEffect::onIsEqual(const GrFragmentProcessor& sBase) const { 1608 bool GrDiffuseLightingEffect::onIsEqual(const GrFragmentProcessor& sBase) const {
1620 const GrDiffuseLightingEffect& s = sBase.cast<GrDiffuseLightingEffect>(); 1609 const GrDiffuseLightingEffect& s = sBase.cast<GrDiffuseLightingEffect>();
1621 return INHERITED::onIsEqual(sBase) && 1610 return INHERITED::onIsEqual(sBase) &&
1622 this->kd() == s.kd(); 1611 this->kd() == s.kd();
1623 } 1612 }
1624 1613
1625 void GrDiffuseLightingEffect::onGetGLProcessorKey(const GrGLSLCaps& caps, 1614 void GrDiffuseLightingEffect::onGetGLProcessorKey(const GrGLSLCaps& caps,
1626 GrProcessorKeyBuilder* b) const { 1615 GrProcessorKeyBuilder* b) const {
1627 GrGLDiffuseLightingEffect::GenKey(*this, caps, b); 1616 GrGLDiffuseLightingEffect::GenKey(*this, caps, b);
1628 } 1617 }
1629 1618
1630 GrGLFragmentProcessor* GrDiffuseLightingEffect::onCreateGLInstance() const { 1619 GrGLFragmentProcessor* GrDiffuseLightingEffect::onCreateGLInstance() const {
1631 return new GrGLDiffuseLightingEffect(*this); 1620 return new GrGLDiffuseLightingEffect(*this);
1632 } 1621 }
1633 1622
1634 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrDiffuseLightingEffect); 1623 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrDiffuseLightingEffect);
1635 1624
1636 const GrFragmentProcessor* GrDiffuseLightingEffect::TestCreate(GrProcessorTestDa ta* d) { 1625 const GrFragmentProcessor* GrDiffuseLightingEffect::TestCreate(GrProcessorTestDa ta* d) {
1637 SkScalar surfaceScale = d->fRandom->nextSScalar1(); 1626 SkScalar surfaceScale = d->fRandom->nextSScalar1();
1638 SkScalar kd = d->fRandom->nextUScalar1(); 1627 SkScalar kd = d->fRandom->nextUScalar1();
1639 SkAutoTUnref<SkImageFilterLight> light(create_random_light(d->fRandom)); 1628 SkAutoTUnref<SkImageFilterLight> light(create_random_light(d->fRandom));
1640 SkMatrix matrix; 1629 SkMatrix matrix;
1641 for (int i = 0; i < 9; i++) { 1630 for (int i = 0; i < 9; i++) {
1642 matrix[i] = d->fRandom->nextUScalar1(); 1631 matrix[i] = d->fRandom->nextUScalar1();
1643 } 1632 }
1644 BoundaryMode mode = static_cast<BoundaryMode>(d->fRandom->nextU() % kBoundar yModeCount); 1633 BoundaryMode mode = static_cast<BoundaryMode>(d->fRandom->nextU() % kBoundar yModeCount);
1645 return GrDiffuseLightingEffect::Create(d->fProcDataManager, 1634 return GrDiffuseLightingEffect::Create(d->fTextures[GrProcessorUnitTest::kAl phaTextureIdx],
1646 d->fTextures[GrProcessorUnitTest::kAl phaTextureIdx],
1647 light, surfaceScale, matrix, kd, mode ); 1635 light, surfaceScale, matrix, kd, mode );
1648 } 1636 }
1649 1637
1650 1638
1651 /////////////////////////////////////////////////////////////////////////////// 1639 ///////////////////////////////////////////////////////////////////////////////
1652 1640
1653 GrGLLightingEffect::GrGLLightingEffect(const GrProcessor& fp) { 1641 GrGLLightingEffect::GrGLLightingEffect(const GrProcessor& fp) {
1654 const GrLightingEffect& m = fp.cast<GrLightingEffect>(); 1642 const GrLightingEffect& m = fp.cast<GrLightingEffect>();
1655 fLight = m.light()->createGLLight(); 1643 fLight = m.light()->createGLLight();
1656 fBoundaryMode = m.boundaryMode(); 1644 fBoundaryMode = m.boundaryMode();
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
1797 1785
1798 void GrGLDiffuseLightingEffect::onSetData(const GrGLProgramDataManager& pdman, 1786 void GrGLDiffuseLightingEffect::onSetData(const GrGLProgramDataManager& pdman,
1799 const GrProcessor& proc) { 1787 const GrProcessor& proc) {
1800 INHERITED::onSetData(pdman, proc); 1788 INHERITED::onSetData(pdman, proc);
1801 const GrDiffuseLightingEffect& diffuse = proc.cast<GrDiffuseLightingEffect>( ); 1789 const GrDiffuseLightingEffect& diffuse = proc.cast<GrDiffuseLightingEffect>( );
1802 pdman.set1f(fKDUni, diffuse.kd()); 1790 pdman.set1f(fKDUni, diffuse.kd());
1803 } 1791 }
1804 1792
1805 /////////////////////////////////////////////////////////////////////////////// 1793 ///////////////////////////////////////////////////////////////////////////////
1806 1794
1807 GrSpecularLightingEffect::GrSpecularLightingEffect(GrProcessorDataManager* procD ataManager, 1795 GrSpecularLightingEffect::GrSpecularLightingEffect(GrTexture* texture,
1808 GrTexture* texture,
1809 const SkImageFilterLight* lig ht, 1796 const SkImageFilterLight* lig ht,
1810 SkScalar surfaceScale, 1797 SkScalar surfaceScale,
1811 const SkMatrix& matrix, 1798 const SkMatrix& matrix,
1812 SkScalar ks, 1799 SkScalar ks,
1813 SkScalar shininess, 1800 SkScalar shininess,
1814 BoundaryMode boundaryMode) 1801 BoundaryMode boundaryMode)
1815 : INHERITED(procDataManager, texture, light, surfaceScale, matrix, boundaryM ode) 1802 : INHERITED(texture, light, surfaceScale, matrix, boundaryMode)
1816 , fKS(ks) 1803 , fKS(ks)
1817 , fShininess(shininess) { 1804 , fShininess(shininess) {
1818 this->initClassID<GrSpecularLightingEffect>(); 1805 this->initClassID<GrSpecularLightingEffect>();
1819 } 1806 }
1820 1807
1821 bool GrSpecularLightingEffect::onIsEqual(const GrFragmentProcessor& sBase) const { 1808 bool GrSpecularLightingEffect::onIsEqual(const GrFragmentProcessor& sBase) const {
1822 const GrSpecularLightingEffect& s = sBase.cast<GrSpecularLightingEffect>(); 1809 const GrSpecularLightingEffect& s = sBase.cast<GrSpecularLightingEffect>();
1823 return INHERITED::onIsEqual(sBase) && 1810 return INHERITED::onIsEqual(sBase) &&
1824 this->ks() == s.ks() && 1811 this->ks() == s.ks() &&
1825 this->shininess() == s.shininess(); 1812 this->shininess() == s.shininess();
(...skipping 13 matching lines...) Expand all
1839 const GrFragmentProcessor* GrSpecularLightingEffect::TestCreate(GrProcessorTestD ata* d) { 1826 const GrFragmentProcessor* GrSpecularLightingEffect::TestCreate(GrProcessorTestD ata* d) {
1840 SkScalar surfaceScale = d->fRandom->nextSScalar1(); 1827 SkScalar surfaceScale = d->fRandom->nextSScalar1();
1841 SkScalar ks = d->fRandom->nextUScalar1(); 1828 SkScalar ks = d->fRandom->nextUScalar1();
1842 SkScalar shininess = d->fRandom->nextUScalar1(); 1829 SkScalar shininess = d->fRandom->nextUScalar1();
1843 SkAutoTUnref<SkImageFilterLight> light(create_random_light(d->fRandom)); 1830 SkAutoTUnref<SkImageFilterLight> light(create_random_light(d->fRandom));
1844 SkMatrix matrix; 1831 SkMatrix matrix;
1845 for (int i = 0; i < 9; i++) { 1832 for (int i = 0; i < 9; i++) {
1846 matrix[i] = d->fRandom->nextUScalar1(); 1833 matrix[i] = d->fRandom->nextUScalar1();
1847 } 1834 }
1848 BoundaryMode mode = static_cast<BoundaryMode>(d->fRandom->nextU() % kBoundar yModeCount); 1835 BoundaryMode mode = static_cast<BoundaryMode>(d->fRandom->nextU() % kBoundar yModeCount);
1849 return GrSpecularLightingEffect::Create(d->fProcDataManager, 1836 return GrSpecularLightingEffect::Create(d->fTextures[GrProcessorUnitTest::kA lphaTextureIdx],
1850 d->fTextures[GrProcessorUnitTest::kA lphaTextureIdx],
1851 light, surfaceScale, matrix, ks, shi niness, mode); 1837 light, surfaceScale, matrix, ks, shi niness, mode);
1852 } 1838 }
1853 1839
1854 /////////////////////////////////////////////////////////////////////////////// 1840 ///////////////////////////////////////////////////////////////////////////////
1855 1841
1856 GrGLSpecularLightingEffect::GrGLSpecularLightingEffect(const GrProcessor& proc) 1842 GrGLSpecularLightingEffect::GrGLSpecularLightingEffect(const GrProcessor& proc)
1857 : INHERITED(proc) { 1843 : INHERITED(proc) {
1858 } 1844 }
1859 1845
1860 void GrGLSpecularLightingEffect::emitLightFunc(GrGLFPBuilder* builder, SkString* funcName) { 1846 void GrGLSpecularLightingEffect::emitLightFunc(GrGLFPBuilder* builder, SkString* funcName) {
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
2025 2011
2026 fsBuilder->codeAppendf("%s(%s)", fLightColorFunc.c_str(), surfaceToLight); 2012 fsBuilder->codeAppendf("%s(%s)", fLightColorFunc.c_str(), surfaceToLight);
2027 } 2013 }
2028 2014
2029 #endif 2015 #endif
2030 2016
2031 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingImageFilter) 2017 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingImageFilter)
2032 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDiffuseLightingImageFilter) 2018 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDiffuseLightingImageFilter)
2033 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSpecularLightingImageFilter) 2019 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSpecularLightingImageFilter)
2034 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END 2020 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END
OLDNEW
« no previous file with comments | « src/effects/SkGpuBlurUtils.cpp ('k') | src/effects/SkLumaColorFilter.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698