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

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

Issue 1698913004: Remove 6-param applyCropRect() from lighting filters (GPU path). (Closed) Base URL: https://skia.googlesource.com/skia.git@apply-crop-rect6-remove-lighting
Patch Set: Fix whitespace, bugs Created 4 years, 10 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 | « no previous file | no next file » | 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"
11 #include "SkDevice.h" 11 #include "SkDevice.h"
12 #include "SkPoint3.h" 12 #include "SkPoint3.h"
13 #include "SkReadBuffer.h" 13 #include "SkReadBuffer.h"
14 #include "SkTypes.h" 14 #include "SkTypes.h"
15 #include "SkWriteBuffer.h" 15 #include "SkWriteBuffer.h"
16 16
17 #if SK_SUPPORT_GPU 17 #if SK_SUPPORT_GPU
18 #include "GrContext.h" 18 #include "GrContext.h"
19 #include "GrDrawContext.h" 19 #include "GrDrawContext.h"
20 #include "GrFragmentProcessor.h" 20 #include "GrFragmentProcessor.h"
21 #include "GrInvariantOutput.h" 21 #include "GrInvariantOutput.h"
22 #include "GrPaint.h" 22 #include "GrPaint.h"
23 #include "SkGr.h" 23 #include "SkGr.h"
24 #include "effects/GrSingleTextureEffect.h" 24 #include "effects/GrSingleTextureEffect.h"
25 #include "effects/GrTextureDomain.h"
25 #include "glsl/GrGLSLFragmentProcessor.h" 26 #include "glsl/GrGLSLFragmentProcessor.h"
26 #include "glsl/GrGLSLFragmentShaderBuilder.h" 27 #include "glsl/GrGLSLFragmentShaderBuilder.h"
27 #include "glsl/GrGLSLProgramDataManager.h" 28 #include "glsl/GrGLSLProgramDataManager.h"
28 #include "glsl/GrGLSLUniformHandler.h" 29 #include "glsl/GrGLSLUniformHandler.h"
29 30
30 class GrGLDiffuseLightingEffect; 31 class GrGLDiffuseLightingEffect;
31 class GrGLSpecularLightingEffect; 32 class GrGLSpecularLightingEffect;
32 33
33 // For brevity 34 // For brevity
34 typedef GrGLSLProgramDataManager::UniformHandle UniformHandle; 35 typedef GrGLSLProgramDataManager::UniformHandle UniformHandle;
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 SkImageFilter* input, 352 SkImageFilter* input,
352 const CropRect* cropRect) 353 const CropRect* cropRect)
353 : INHERITED(light, surfaceScale, input, cropRect) {} 354 : INHERITED(light, surfaceScale, input, cropRect) {}
354 355
355 #if SK_SUPPORT_GPU 356 #if SK_SUPPORT_GPU
356 bool canFilterImageGPU() const override { return true; } 357 bool canFilterImageGPU() const override { return true; }
357 bool filterImageGPU(Proxy*, const SkBitmap& src, const Context&, 358 bool filterImageGPU(Proxy*, const SkBitmap& src, const Context&,
358 SkBitmap* result, SkIPoint* offset) const override; 359 SkBitmap* result, SkIPoint* offset) const override;
359 virtual GrFragmentProcessor* getFragmentProcessor(GrTexture*, 360 virtual GrFragmentProcessor* getFragmentProcessor(GrTexture*,
360 const SkMatrix&, 361 const SkMatrix&,
361 const SkIRect& bounds, 362 const SkIRect* srcBounds,
362 BoundaryMode boundaryMode) const = 0; 363 BoundaryMode boundaryMode) const = 0;
363 #endif 364 #endif
364 private: 365 private:
365 #if SK_SUPPORT_GPU 366 #if SK_SUPPORT_GPU
366 void drawRect(GrDrawContext* drawContext, 367 void drawRect(GrDrawContext* drawContext,
367 GrTexture* src, 368 GrTexture* src,
368 const SkMatrix& matrix, 369 const SkMatrix& matrix,
369 const GrClip& clip, 370 const GrClip& clip,
370 const SkRect& dstRect, 371 const SkRect& dstRect,
371 BoundaryMode boundaryMode, 372 BoundaryMode boundaryMode,
373 const SkIRect* srcBounds,
372 const SkIRect& bounds) const; 374 const SkIRect& bounds) const;
373 #endif 375 #endif
374 typedef SkLightingImageFilter INHERITED; 376 typedef SkLightingImageFilter INHERITED;
375 }; 377 };
376 378
377 #if SK_SUPPORT_GPU 379 #if SK_SUPPORT_GPU
378 void SkLightingImageFilterInternal::drawRect(GrDrawContext* drawContext, 380 void SkLightingImageFilterInternal::drawRect(GrDrawContext* drawContext,
379 GrTexture* src, 381 GrTexture* src,
380 const SkMatrix& matrix, 382 const SkMatrix& matrix,
381 const GrClip& clip, 383 const GrClip& clip,
382 const SkRect& dstRect, 384 const SkRect& dstRect,
383 BoundaryMode boundaryMode, 385 BoundaryMode boundaryMode,
386 const SkIRect* srcBounds,
384 const SkIRect& bounds) const { 387 const SkIRect& bounds) const {
385 SkRect srcRect = dstRect.makeOffset(SkIntToScalar(bounds.x()), SkIntToScalar (bounds.y())); 388 SkRect srcRect = dstRect.makeOffset(SkIntToScalar(bounds.x()), SkIntToScalar (bounds.y()));
386 GrPaint paint; 389 GrPaint paint;
387 GrFragmentProcessor* fp = this->getFragmentProcessor(src, matrix, bounds, bo undaryMode); 390 GrFragmentProcessor* fp = this->getFragmentProcessor(src, matrix, srcBounds, boundaryMode);
388 paint.addColorFragmentProcessor(fp)->unref(); 391 paint.addColorFragmentProcessor(fp)->unref();
389 paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode); 392 paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode);
390 drawContext->fillRectToRect(clip, paint, SkMatrix::I(), dstRect, srcRect); 393 drawContext->fillRectToRect(clip, paint, SkMatrix::I(), dstRect, srcRect);
391 } 394 }
392 395
393 bool SkLightingImageFilterInternal::filterImageGPU(Proxy* proxy, 396 bool SkLightingImageFilterInternal::filterImageGPU(Proxy* proxy,
394 const SkBitmap& src, 397 const SkBitmap& src,
395 const Context& ctx, 398 const Context& ctx,
396 SkBitmap* result, 399 SkBitmap* result,
397 SkIPoint* offset) const { 400 SkIPoint* offset) const {
398 SkBitmap input = src; 401 SkBitmap input = src;
399 SkIPoint srcOffset = SkIPoint::Make(0, 0); 402 SkIPoint srcOffset = SkIPoint::Make(0, 0);
400 if (!this->filterInputGPU(0, proxy, src, ctx, &input, &srcOffset)) { 403 if (!this->filterInputGPU(0, proxy, src, ctx, &input, &srcOffset)) {
401 return false; 404 return false;
402 } 405 }
406 SkIRect srcBounds = input.bounds();
407 srcBounds.offset(srcOffset);
403 SkIRect bounds; 408 SkIRect bounds;
404 if (!this->applyCropRect(ctx, proxy, input, &srcOffset, &bounds, &input)) { 409 if (!this->applyCropRect(ctx, srcBounds, &bounds)) {
405 return false; 410 return false;
406 } 411 }
407 SkRect dstRect = SkRect::MakeWH(SkIntToScalar(bounds.width()), 412 SkRect dstRect = SkRect::MakeWH(SkIntToScalar(bounds.width()),
408 SkIntToScalar(bounds.height())); 413 SkIntToScalar(bounds.height()));
409 GrTexture* srcTexture = input.getTexture(); 414 GrTexture* srcTexture = input.getTexture();
410 GrContext* context = srcTexture->getContext(); 415 GrContext* context = srcTexture->getContext();
411 416
412 GrSurfaceDesc desc; 417 GrSurfaceDesc desc;
413 desc.fFlags = kRenderTarget_GrSurfaceFlag, 418 desc.fFlags = kRenderTarget_GrSurfaceFlag,
414 desc.fWidth = bounds.width(); 419 desc.fWidth = bounds.width();
415 desc.fHeight = bounds.height(); 420 desc.fHeight = bounds.height();
416 desc.fConfig = kRGBA_8888_GrPixelConfig; 421 desc.fConfig = kRGBA_8888_GrPixelConfig;
417 422
418 SkAutoTUnref<GrTexture> dst(context->textureProvider()->createApproxTexture( desc)); 423 SkAutoTUnref<GrTexture> dst(context->textureProvider()->createApproxTexture( desc));
419 if (!dst) { 424 if (!dst) {
420 return false; 425 return false;
421 } 426 }
422 427
423 // setup new clip 428 // setup new clip
424 GrClip clip(dstRect); 429 GrClip clip(dstRect);
425 430
426 offset->fX = bounds.left(); 431 offset->fX = bounds.left();
427 offset->fY = bounds.top(); 432 offset->fY = bounds.top();
428 SkMatrix matrix(ctx.ctm()); 433 SkMatrix matrix(ctx.ctm());
429 matrix.postTranslate(SkIntToScalar(-bounds.left()), SkIntToScalar(-bounds.to p())); 434 matrix.postTranslate(SkIntToScalar(-bounds.left()), SkIntToScalar(-bounds.to p()));
430 bounds.offset(-srcOffset); 435 bounds.offset(-srcOffset);
436 srcBounds.offset(-srcOffset);
431 SkRect topLeft = SkRect::MakeXYWH(0, 0, 1, 1); 437 SkRect topLeft = SkRect::MakeXYWH(0, 0, 1, 1);
432 SkRect top = SkRect::MakeXYWH(1, 0, dstRect.width() - 2, 1); 438 SkRect top = SkRect::MakeXYWH(1, 0, dstRect.width() - 2, 1);
433 SkRect topRight = SkRect::MakeXYWH(dstRect.width() - 1, 0, 1, 1); 439 SkRect topRight = SkRect::MakeXYWH(dstRect.width() - 1, 0, 1, 1);
434 SkRect left = SkRect::MakeXYWH(0, 1, 1, dstRect.height() - 2); 440 SkRect left = SkRect::MakeXYWH(0, 1, 1, dstRect.height() - 2);
435 SkRect interior = dstRect.makeInset(1, 1); 441 SkRect interior = dstRect.makeInset(1, 1);
436 SkRect right = SkRect::MakeXYWH(dstRect.width() - 1, 1, 1, dstRect.height() - 2); 442 SkRect right = SkRect::MakeXYWH(dstRect.width() - 1, 1, 1, dstRect.height() - 2);
437 SkRect bottomLeft = SkRect::MakeXYWH(0, dstRect.height() - 1, 1, 1); 443 SkRect bottomLeft = SkRect::MakeXYWH(0, dstRect.height() - 1, 1, 1);
438 SkRect bottom = SkRect::MakeXYWH(1, dstRect.height() - 1, dstRect.width() - 2, 1); 444 SkRect bottom = SkRect::MakeXYWH(1, dstRect.height() - 1, dstRect.width() - 2, 1);
439 SkRect bottomRight = SkRect::MakeXYWH(dstRect.width() - 1, dstRect.height() - 1, 1, 1); 445 SkRect bottomRight = SkRect::MakeXYWH(dstRect.width() - 1, dstRect.height() - 1, 1, 1);
440 446
441 SkAutoTUnref<GrDrawContext> drawContext(context->drawContext(dst->asRenderTa rget())); 447 SkAutoTUnref<GrDrawContext> drawContext(context->drawContext(dst->asRenderTa rget()));
442 if (!drawContext) { 448 if (!drawContext) {
443 return false; 449 return false;
444 } 450 }
445 451
446 this->drawRect(drawContext, srcTexture, matrix, clip, topLeft, kTopLeft_Boun daryMode, bounds); 452 const SkIRect* pSrcBounds = srcBounds.contains(bounds) ? nullptr : &srcBound s;
447 this->drawRect(drawContext, srcTexture, matrix, clip, top, kTop_BoundaryMode , bounds); 453 this->drawRect(drawContext, srcTexture, matrix, clip, topLeft, kTopLeft_Boun daryMode,
454 pSrcBounds, bounds);
455 this->drawRect(drawContext, srcTexture, matrix, clip, top, kTop_BoundaryMode ,
456 pSrcBounds, bounds);
448 this->drawRect(drawContext, srcTexture, matrix, clip, topRight, kTopRight_Bo undaryMode, 457 this->drawRect(drawContext, srcTexture, matrix, clip, topRight, kTopRight_Bo undaryMode,
449 bounds); 458 pSrcBounds, bounds);
450 this->drawRect(drawContext, srcTexture, matrix, clip, left, kLeft_BoundaryMo de, bounds); 459 this->drawRect(drawContext, srcTexture, matrix, clip, left, kLeft_BoundaryMo de,
460 pSrcBounds, bounds);
451 this->drawRect(drawContext, srcTexture, matrix, clip, interior, kInterior_Bo undaryMode, 461 this->drawRect(drawContext, srcTexture, matrix, clip, interior, kInterior_Bo undaryMode,
452 bounds); 462 pSrcBounds, bounds);
453 this->drawRect(drawContext, srcTexture, matrix, clip, right, kRight_Boundary Mode, bounds); 463 this->drawRect(drawContext, srcTexture, matrix, clip, right, kRight_Boundary Mode,
464 pSrcBounds, bounds);
454 this->drawRect(drawContext, srcTexture, matrix, clip, bottomLeft, kBottomLef t_BoundaryMode, 465 this->drawRect(drawContext, srcTexture, matrix, clip, bottomLeft, kBottomLef t_BoundaryMode,
455 bounds); 466 pSrcBounds, bounds);
456 this->drawRect(drawContext, srcTexture, matrix, clip, bottom, kBottom_Bounda ryMode, bounds); 467 this->drawRect(drawContext, srcTexture, matrix, clip, bottom, kBottom_Bounda ryMode,
468 pSrcBounds, bounds);
457 this->drawRect(drawContext, srcTexture, matrix, clip, bottomRight, 469 this->drawRect(drawContext, srcTexture, matrix, clip, bottomRight,
458 kBottomRight_BoundaryMode, bounds); 470 kBottomRight_BoundaryMode, pSrcBounds, bounds);
459 GrWrapTextureInBitmap(dst, bounds.width(), bounds.height(), false, result); 471 GrWrapTextureInBitmap(dst, bounds.width(), bounds.height(), false, result);
460 return true; 472 return true;
461 } 473 }
462 #endif 474 #endif
463 475
464 class SkDiffuseLightingImageFilter : public SkLightingImageFilterInternal { 476 class SkDiffuseLightingImageFilter : public SkLightingImageFilterInternal {
465 public: 477 public:
466 static SkImageFilter* Create(SkImageFilterLight* light, SkScalar surfaceScal e, 478 static SkImageFilter* Create(SkImageFilterLight* light, SkScalar surfaceScal e,
467 SkScalar kd, SkImageFilter*, 479 SkScalar kd, SkImageFilter*,
468 const CropRect*); 480 const CropRect*);
469 481
470 SK_TO_STRING_OVERRIDE() 482 SK_TO_STRING_OVERRIDE()
471 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkDiffuseLightingImageFi lter) 483 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkDiffuseLightingImageFi lter)
472 SkScalar kd() const { return fKD; } 484 SkScalar kd() const { return fKD; }
473 485
474 protected: 486 protected:
475 SkDiffuseLightingImageFilter(SkImageFilterLight* light, SkScalar surfaceScal e, 487 SkDiffuseLightingImageFilter(SkImageFilterLight* light, SkScalar surfaceScal e,
476 SkScalar kd, SkImageFilter* input, const CropRe ct* cropRect); 488 SkScalar kd, SkImageFilter* input, const CropRe ct* cropRect);
477 void flatten(SkWriteBuffer& buffer) const override; 489 void flatten(SkWriteBuffer& buffer) const override;
478 bool onFilterImage(Proxy*, const SkBitmap& src, const Context&, 490 bool onFilterImage(Proxy*, const SkBitmap& src, const Context&,
479 SkBitmap* result, SkIPoint* offset) const override; 491 SkBitmap* result, SkIPoint* offset) const override;
480 #if SK_SUPPORT_GPU 492 #if SK_SUPPORT_GPU
481 GrFragmentProcessor* getFragmentProcessor(GrTexture*, const SkMatrix&, const SkIRect& bounds, 493 GrFragmentProcessor* getFragmentProcessor(GrTexture*, const SkMatrix&, const SkIRect* bounds,
482 BoundaryMode) const override; 494 BoundaryMode) const override;
483 #endif 495 #endif
484 496
485 private: 497 private:
486 friend class SkLightingImageFilter; 498 friend class SkLightingImageFilter;
487 typedef SkLightingImageFilterInternal INHERITED; 499 typedef SkLightingImageFilterInternal INHERITED;
488 SkScalar fKD; 500 SkScalar fKD;
489 }; 501 };
490 502
491 class SkSpecularLightingImageFilter : public SkLightingImageFilterInternal { 503 class SkSpecularLightingImageFilter : public SkLightingImageFilterInternal {
492 public: 504 public:
493 static SkImageFilter* Create(SkImageFilterLight* light, SkScalar surfaceScal e, 505 static SkImageFilter* Create(SkImageFilterLight* light, SkScalar surfaceScal e,
494 SkScalar ks, SkScalar shininess, SkImageFilter* , const CropRect*); 506 SkScalar ks, SkScalar shininess, SkImageFilter* , const CropRect*);
495 507
496 SK_TO_STRING_OVERRIDE() 508 SK_TO_STRING_OVERRIDE()
497 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkSpecularLightingImageF ilter) 509 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkSpecularLightingImageF ilter)
498 510
499 SkScalar ks() const { return fKS; } 511 SkScalar ks() const { return fKS; }
500 SkScalar shininess() const { return fShininess; } 512 SkScalar shininess() const { return fShininess; }
501 513
502 protected: 514 protected:
503 SkSpecularLightingImageFilter(SkImageFilterLight* light, SkScalar surfaceSca le, SkScalar ks, 515 SkSpecularLightingImageFilter(SkImageFilterLight* light, SkScalar surfaceSca le, SkScalar ks,
504 SkScalar shininess, SkImageFilter* input, cons t CropRect*); 516 SkScalar shininess, SkImageFilter* input, cons t CropRect*);
505 void flatten(SkWriteBuffer& buffer) const override; 517 void flatten(SkWriteBuffer& buffer) const override;
506 bool onFilterImage(Proxy*, const SkBitmap& src, const Context&, 518 bool onFilterImage(Proxy*, const SkBitmap& src, const Context&,
507 SkBitmap* result, SkIPoint* offset) const override; 519 SkBitmap* result, SkIPoint* offset) const override;
508 #if SK_SUPPORT_GPU 520 #if SK_SUPPORT_GPU
509 GrFragmentProcessor* getFragmentProcessor(GrTexture*, const SkMatrix&, const SkIRect& bounds, 521 GrFragmentProcessor* getFragmentProcessor(GrTexture*, const SkMatrix&, const SkIRect* bounds,
510 BoundaryMode) const override; 522 BoundaryMode) const override;
511 #endif 523 #endif
512 524
513 private: 525 private:
514 SkScalar fKS; 526 SkScalar fKS;
515 SkScalar fShininess; 527 SkScalar fShininess;
516 friend class SkLightingImageFilter; 528 friend class SkLightingImageFilter;
517 typedef SkLightingImageFilterInternal INHERITED; 529 typedef SkLightingImageFilterInternal INHERITED;
518 }; 530 };
519 531
520 #if SK_SUPPORT_GPU 532 #if SK_SUPPORT_GPU
521 533
522 class GrLightingEffect : public GrSingleTextureEffect { 534 class GrLightingEffect : public GrSingleTextureEffect {
523 public: 535 public:
524 GrLightingEffect(GrTexture* texture, const SkImageFilterLight* light, SkScal ar surfaceScale, 536 GrLightingEffect(GrTexture* texture, const SkImageFilterLight* light, SkScal ar surfaceScale,
525 const SkMatrix& matrix, BoundaryMode boundaryMode); 537 const SkMatrix& matrix, BoundaryMode boundaryMode, const Sk IRect* srcBounds);
526 ~GrLightingEffect() override; 538 ~GrLightingEffect() override;
527 539
528 const SkImageFilterLight* light() const { return fLight; } 540 const SkImageFilterLight* light() const { return fLight; }
529 SkScalar surfaceScale() const { return fSurfaceScale; } 541 SkScalar surfaceScale() const { return fSurfaceScale; }
530 const SkMatrix& filterMatrix() const { return fFilterMatrix; } 542 const SkMatrix& filterMatrix() const { return fFilterMatrix; }
531 BoundaryMode boundaryMode() const { return fBoundaryMode; } 543 BoundaryMode boundaryMode() const { return fBoundaryMode; }
544 const GrTextureDomain& domain() const { return fDomain; }
532 545
533 protected: 546 protected:
534 bool onIsEqual(const GrFragmentProcessor&) const override; 547 bool onIsEqual(const GrFragmentProcessor&) const override;
535 548
536 void onComputeInvariantOutput(GrInvariantOutput* inout) const override { 549 void onComputeInvariantOutput(GrInvariantOutput* inout) const override {
537 // lighting shaders are complicated. We just throw up our hands. 550 // lighting shaders are complicated. We just throw up our hands.
538 inout->mulByUnknownFourComponents(); 551 inout->mulByUnknownFourComponents();
539 } 552 }
540 553
541 private: 554 private:
542 const SkImageFilterLight* fLight; 555 const SkImageFilterLight* fLight;
543 SkScalar fSurfaceScale; 556 SkScalar fSurfaceScale;
544 SkMatrix fFilterMatrix; 557 SkMatrix fFilterMatrix;
545 BoundaryMode fBoundaryMode; 558 BoundaryMode fBoundaryMode;
559 GrTextureDomain fDomain;
546 560
547 typedef GrSingleTextureEffect INHERITED; 561 typedef GrSingleTextureEffect INHERITED;
548 }; 562 };
549 563
550 class GrDiffuseLightingEffect : public GrLightingEffect { 564 class GrDiffuseLightingEffect : public GrLightingEffect {
551 public: 565 public:
552 static GrFragmentProcessor* Create(GrTexture* texture, 566 static GrFragmentProcessor* Create(GrTexture* texture,
553 const SkImageFilterLight* light, 567 const SkImageFilterLight* light,
554 SkScalar surfaceScale, 568 SkScalar surfaceScale,
555 const SkMatrix& matrix, 569 const SkMatrix& matrix,
556 SkScalar kd, 570 SkScalar kd,
557 BoundaryMode boundaryMode) { 571 BoundaryMode boundaryMode,
558 return new GrDiffuseLightingEffect(texture, light, surfaceScale, matrix, kd, boundaryMode); 572 const SkIRect* srcBounds) {
573 return new GrDiffuseLightingEffect(texture, light, surfaceScale, matrix, kd, boundaryMode,
574 srcBounds);
559 } 575 }
560 576
561 const char* name() const override { return "DiffuseLighting"; } 577 const char* name() const override { return "DiffuseLighting"; }
562 578
563 SkScalar kd() const { return fKD; } 579 SkScalar kd() const { return fKD; }
564 580
565 private: 581 private:
566 GrGLSLFragmentProcessor* onCreateGLSLInstance() const override; 582 GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;
567 583
568 void onGetGLSLProcessorKey(const GrGLSLCaps&, GrProcessorKeyBuilder*) const override; 584 void onGetGLSLProcessorKey(const GrGLSLCaps&, GrProcessorKeyBuilder*) const override;
569 585
570 bool onIsEqual(const GrFragmentProcessor&) const override; 586 bool onIsEqual(const GrFragmentProcessor&) const override;
571 587
572 GrDiffuseLightingEffect(GrTexture* texture, 588 GrDiffuseLightingEffect(GrTexture* texture,
573 const SkImageFilterLight* light, 589 const SkImageFilterLight* light,
574 SkScalar surfaceScale, 590 SkScalar surfaceScale,
575 const SkMatrix& matrix, 591 const SkMatrix& matrix,
576 SkScalar kd, 592 SkScalar kd,
577 BoundaryMode boundaryMode); 593 BoundaryMode boundaryMode,
594 const SkIRect* srcBounds);
578 595
579 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; 596 GR_DECLARE_FRAGMENT_PROCESSOR_TEST;
580 typedef GrLightingEffect INHERITED; 597 typedef GrLightingEffect INHERITED;
581 SkScalar fKD; 598 SkScalar fKD;
582 }; 599 };
583 600
584 class GrSpecularLightingEffect : public GrLightingEffect { 601 class GrSpecularLightingEffect : public GrLightingEffect {
585 public: 602 public:
586 static GrFragmentProcessor* Create(GrTexture* texture, 603 static GrFragmentProcessor* Create(GrTexture* texture,
587 const SkImageFilterLight* light, 604 const SkImageFilterLight* light,
588 SkScalar surfaceScale, 605 SkScalar surfaceScale,
589 const SkMatrix& matrix, 606 const SkMatrix& matrix,
590 SkScalar ks, 607 SkScalar ks,
591 SkScalar shininess, 608 SkScalar shininess,
592 BoundaryMode boundaryMode) { 609 BoundaryMode boundaryMode,
610 const SkIRect* srcBounds) {
593 return new GrSpecularLightingEffect(texture, light, surfaceScale, matrix , ks, shininess, 611 return new GrSpecularLightingEffect(texture, light, surfaceScale, matrix , ks, shininess,
594 boundaryMode); 612 boundaryMode, srcBounds);
595 } 613 }
596 614
597 const char* name() const override { return "SpecularLighting"; } 615 const char* name() const override { return "SpecularLighting"; }
598 616
599 GrGLSLFragmentProcessor* onCreateGLSLInstance() const override; 617 GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;
600 618
601 SkScalar ks() const { return fKS; } 619 SkScalar ks() const { return fKS; }
602 SkScalar shininess() const { return fShininess; } 620 SkScalar shininess() const { return fShininess; }
603 621
604 private: 622 private:
605 void onGetGLSLProcessorKey(const GrGLSLCaps&, GrProcessorKeyBuilder*) const override; 623 void onGetGLSLProcessorKey(const GrGLSLCaps&, GrProcessorKeyBuilder*) const override;
606 624
607 bool onIsEqual(const GrFragmentProcessor&) const override; 625 bool onIsEqual(const GrFragmentProcessor&) const override;
608 626
609 GrSpecularLightingEffect(GrTexture* texture, 627 GrSpecularLightingEffect(GrTexture* texture,
610 const SkImageFilterLight* light, 628 const SkImageFilterLight* light,
611 SkScalar surfaceScale, 629 SkScalar surfaceScale,
612 const SkMatrix& matrix, 630 const SkMatrix& matrix,
613 SkScalar ks, 631 SkScalar ks,
614 SkScalar shininess, 632 SkScalar shininess,
615 BoundaryMode boundaryMode); 633 BoundaryMode boundaryMode,
634 const SkIRect* srcBounds);
616 635
617 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; 636 GR_DECLARE_FRAGMENT_PROCESSOR_TEST;
618 typedef GrLightingEffect INHERITED; 637 typedef GrLightingEffect INHERITED;
619 SkScalar fKS; 638 SkScalar fKS;
620 SkScalar fShininess; 639 SkScalar fShininess;
621 }; 640 };
622 641
623 /////////////////////////////////////////////////////////////////////////////// 642 ///////////////////////////////////////////////////////////////////////////////
624 643
625 class GrGLLight { 644 class GrGLLight {
(...skipping 658 matching lines...) Expand 10 before | Expand all | Expand 10 after
1284 str->appendf("SkDiffuseLightingImageFilter: ("); 1303 str->appendf("SkDiffuseLightingImageFilter: (");
1285 str->appendf("kD: %f\n", fKD); 1304 str->appendf("kD: %f\n", fKD);
1286 str->append(")"); 1305 str->append(")");
1287 } 1306 }
1288 #endif 1307 #endif
1289 1308
1290 #if SK_SUPPORT_GPU 1309 #if SK_SUPPORT_GPU
1291 GrFragmentProcessor* SkDiffuseLightingImageFilter::getFragmentProcessor( 1310 GrFragmentProcessor* SkDiffuseLightingImageFilter::getFragmentProcessor(
1292 GrTexture* texture, 1311 GrTexture* texture,
1293 const SkMatrix& matrix, 1312 const SkMatrix& matrix,
1294 const SkIRect&, 1313 const SkIRect* srcBounds,
1295 BoundaryMode boundaryMode 1314 BoundaryMode boundaryMode) co nst {
1296 ) const {
1297 SkScalar scale = SkScalarMul(this->surfaceScale(), SkIntToScalar(255)); 1315 SkScalar scale = SkScalarMul(this->surfaceScale(), SkIntToScalar(255));
1298 return GrDiffuseLightingEffect::Create(texture, this->light(), scale, matrix , this->kd(), 1316 return GrDiffuseLightingEffect::Create(texture, this->light(), scale, matrix , this->kd(),
1299 boundaryMode); 1317 boundaryMode, srcBounds);
1300 } 1318 }
1301 #endif 1319 #endif
1302 1320
1303 /////////////////////////////////////////////////////////////////////////////// 1321 ///////////////////////////////////////////////////////////////////////////////
1304 1322
1305 SkImageFilter* SkSpecularLightingImageFilter::Create(SkImageFilterLight* light, 1323 SkImageFilter* SkSpecularLightingImageFilter::Create(SkImageFilterLight* light,
1306 SkScalar surfaceScale, 1324 SkScalar surfaceScale,
1307 SkScalar ks, 1325 SkScalar ks,
1308 SkScalar shininess, 1326 SkScalar shininess,
1309 SkImageFilter* input, 1327 SkImageFilter* input,
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
1428 str->appendf("SkSpecularLightingImageFilter: ("); 1446 str->appendf("SkSpecularLightingImageFilter: (");
1429 str->appendf("kS: %f shininess: %f", fKS, fShininess); 1447 str->appendf("kS: %f shininess: %f", fKS, fShininess);
1430 str->append(")"); 1448 str->append(")");
1431 } 1449 }
1432 #endif 1450 #endif
1433 1451
1434 #if SK_SUPPORT_GPU 1452 #if SK_SUPPORT_GPU
1435 GrFragmentProcessor* SkSpecularLightingImageFilter::getFragmentProcessor( 1453 GrFragmentProcessor* SkSpecularLightingImageFilter::getFragmentProcessor(
1436 GrTexture* texture, 1454 GrTexture* texture,
1437 const SkMatrix& matrix, 1455 const SkMatrix& matrix,
1438 const SkIRect&, 1456 const SkIRect* srcBounds,
1439 BoundaryMode boundaryMode) c onst { 1457 BoundaryMode boundaryMode) c onst {
1440 SkScalar scale = SkScalarMul(this->surfaceScale(), SkIntToScalar(255)); 1458 SkScalar scale = SkScalarMul(this->surfaceScale(), SkIntToScalar(255));
1441 return GrSpecularLightingEffect::Create(texture, this->light(), scale, matri x, this->ks(), 1459 return GrSpecularLightingEffect::Create(texture, this->light(), scale, matri x, this->ks(),
1442 this->shininess(), boundaryMode); 1460 this->shininess(), boundaryMode, src Bounds);
1443 } 1461 }
1444 #endif 1462 #endif
1445 1463
1446 /////////////////////////////////////////////////////////////////////////////// 1464 ///////////////////////////////////////////////////////////////////////////////
1447 1465
1448 #if SK_SUPPORT_GPU 1466 #if SK_SUPPORT_GPU
1449 1467
1450 namespace { 1468 namespace {
1451 SkPoint3 random_point3(SkRandom* random) { 1469 SkPoint3 random_point3(SkRandom* random) {
1452 return SkPoint3::Make(SkScalarToFloat(random->nextSScalar1()), 1470 return SkPoint3::Make(SkScalarToFloat(random->nextSScalar1()),
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
1565 */ 1583 */
1566 void onSetData(const GrGLSLProgramDataManager&, const GrProcessor&) override ; 1584 void onSetData(const GrGLSLProgramDataManager&, const GrProcessor&) override ;
1567 1585
1568 virtual void emitLightFunc(GrGLSLUniformHandler*, 1586 virtual void emitLightFunc(GrGLSLUniformHandler*,
1569 GrGLSLFragmentBuilder*, 1587 GrGLSLFragmentBuilder*,
1570 SkString* funcName) = 0; 1588 SkString* funcName) = 0;
1571 1589
1572 private: 1590 private:
1573 typedef GrGLSLFragmentProcessor INHERITED; 1591 typedef GrGLSLFragmentProcessor INHERITED;
1574 1592
1575 UniformHandle fImageIncrementUni; 1593 UniformHandle fImageIncrementUni;
1576 UniformHandle fSurfaceScaleUni; 1594 UniformHandle fSurfaceScaleUni;
1577 GrGLLight* fLight; 1595 GrTextureDomain::GLDomain fDomain;
1596 GrGLLight* fLight;
1578 }; 1597 };
1579 1598
1580 /////////////////////////////////////////////////////////////////////////////// 1599 ///////////////////////////////////////////////////////////////////////////////
1581 1600
1582 class GrGLDiffuseLightingEffect : public GrGLLightingEffect { 1601 class GrGLDiffuseLightingEffect : public GrGLLightingEffect {
1583 public: 1602 public:
1584 void emitLightFunc(GrGLSLUniformHandler*, GrGLSLFragmentBuilder*, SkString* funcName) override; 1603 void emitLightFunc(GrGLSLUniformHandler*, GrGLSLFragmentBuilder*, SkString* funcName) override;
1585 1604
1586 protected: 1605 protected:
1587 void onSetData(const GrGLSLProgramDataManager&, const GrProcessor&) override ; 1606 void onSetData(const GrGLSLProgramDataManager&, const GrProcessor&) override ;
(...skipping 15 matching lines...) Expand all
1603 1622
1604 private: 1623 private:
1605 typedef GrGLLightingEffect INHERITED; 1624 typedef GrGLLightingEffect INHERITED;
1606 1625
1607 UniformHandle fKSUni; 1626 UniformHandle fKSUni;
1608 UniformHandle fShininessUni; 1627 UniformHandle fShininessUni;
1609 }; 1628 };
1610 1629
1611 /////////////////////////////////////////////////////////////////////////////// 1630 ///////////////////////////////////////////////////////////////////////////////
1612 1631
1632 namespace {
1633
1634 GrTextureDomain create_domain(GrTexture* texture, const SkIRect* srcBounds,
1635 GrTextureDomain::Mode mode) {
1636 if (srcBounds) {
1637 SkRect texelDomain = GrTextureDomain::MakeTexelDomainForMode(texture, *s rcBounds, mode);
1638 return GrTextureDomain(texelDomain, mode);
1639 } else {
1640 return GrTextureDomain(SkRect::MakeEmpty(), GrTextureDomain::kIgnore_Mod e);
1641 }
1642 }
1643
1644 };
1645
1613 GrLightingEffect::GrLightingEffect(GrTexture* texture, 1646 GrLightingEffect::GrLightingEffect(GrTexture* texture,
1614 const SkImageFilterLight* light, 1647 const SkImageFilterLight* light,
1615 SkScalar surfaceScale, 1648 SkScalar surfaceScale,
1616 const SkMatrix& matrix, 1649 const SkMatrix& matrix,
1617 BoundaryMode boundaryMode) 1650 BoundaryMode boundaryMode,
1651 const SkIRect* srcBounds)
1618 : INHERITED(texture, GrCoordTransform::MakeDivByTextureWHMatrix(texture)) 1652 : INHERITED(texture, GrCoordTransform::MakeDivByTextureWHMatrix(texture))
1619 , fLight(light) 1653 , fLight(light)
1620 , fSurfaceScale(surfaceScale) 1654 , fSurfaceScale(surfaceScale)
1621 , fFilterMatrix(matrix) 1655 , fFilterMatrix(matrix)
1622 , fBoundaryMode(boundaryMode) { 1656 , fBoundaryMode(boundaryMode)
1657 , fDomain(create_domain(texture, srcBounds, GrTextureDomain::kDecal_Mode)) {
1623 fLight->ref(); 1658 fLight->ref();
1624 if (light->requiresFragmentPosition()) { 1659 if (light->requiresFragmentPosition()) {
1625 this->setWillReadFragmentPosition(); 1660 this->setWillReadFragmentPosition();
1626 } 1661 }
1627 } 1662 }
1628 1663
1629 GrLightingEffect::~GrLightingEffect() { 1664 GrLightingEffect::~GrLightingEffect() {
1630 fLight->unref(); 1665 fLight->unref();
1631 } 1666 }
1632 1667
1633 bool GrLightingEffect::onIsEqual(const GrFragmentProcessor& sBase) const { 1668 bool GrLightingEffect::onIsEqual(const GrFragmentProcessor& sBase) const {
1634 const GrLightingEffect& s = sBase.cast<GrLightingEffect>(); 1669 const GrLightingEffect& s = sBase.cast<GrLightingEffect>();
1635 return fLight->isEqual(*s.fLight) && 1670 return fLight->isEqual(*s.fLight) &&
1636 fSurfaceScale == s.fSurfaceScale && 1671 fSurfaceScale == s.fSurfaceScale &&
1637 fBoundaryMode == s.fBoundaryMode; 1672 fBoundaryMode == s.fBoundaryMode;
1638 } 1673 }
1639 1674
1640 /////////////////////////////////////////////////////////////////////////////// 1675 ///////////////////////////////////////////////////////////////////////////////
1641 1676
1642 GrDiffuseLightingEffect::GrDiffuseLightingEffect(GrTexture* texture, 1677 GrDiffuseLightingEffect::GrDiffuseLightingEffect(GrTexture* texture,
1643 const SkImageFilterLight* light , 1678 const SkImageFilterLight* light ,
1644 SkScalar surfaceScale, 1679 SkScalar surfaceScale,
1645 const SkMatrix& matrix, 1680 const SkMatrix& matrix,
1646 SkScalar kd, 1681 SkScalar kd,
1647 BoundaryMode boundaryMode) 1682 BoundaryMode boundaryMode,
1648 : INHERITED(texture, light, surfaceScale, matrix, boundaryMode), fKD(kd) { 1683 const SkIRect* srcBounds)
1684 : INHERITED(texture, light, surfaceScale, matrix, boundaryMode, srcBounds), fKD(kd) {
1649 this->initClassID<GrDiffuseLightingEffect>(); 1685 this->initClassID<GrDiffuseLightingEffect>();
1650 } 1686 }
1651 1687
1652 bool GrDiffuseLightingEffect::onIsEqual(const GrFragmentProcessor& sBase) const { 1688 bool GrDiffuseLightingEffect::onIsEqual(const GrFragmentProcessor& sBase) const {
1653 const GrDiffuseLightingEffect& s = sBase.cast<GrDiffuseLightingEffect>(); 1689 const GrDiffuseLightingEffect& s = sBase.cast<GrDiffuseLightingEffect>();
1654 return INHERITED::onIsEqual(sBase) && this->kd() == s.kd(); 1690 return INHERITED::onIsEqual(sBase) && this->kd() == s.kd();
1655 } 1691 }
1656 1692
1657 void GrDiffuseLightingEffect::onGetGLSLProcessorKey(const GrGLSLCaps& caps, 1693 void GrDiffuseLightingEffect::onGetGLSLProcessorKey(const GrGLSLCaps& caps,
1658 GrProcessorKeyBuilder* b) co nst { 1694 GrProcessorKeyBuilder* b) co nst {
1659 GrGLDiffuseLightingEffect::GenKey(*this, caps, b); 1695 GrGLDiffuseLightingEffect::GenKey(*this, caps, b);
1660 } 1696 }
1661 1697
1662 GrGLSLFragmentProcessor* GrDiffuseLightingEffect::onCreateGLSLInstance() const { 1698 GrGLSLFragmentProcessor* GrDiffuseLightingEffect::onCreateGLSLInstance() const {
1663 return new GrGLDiffuseLightingEffect; 1699 return new GrGLDiffuseLightingEffect;
1664 } 1700 }
1665 1701
1666 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrDiffuseLightingEffect); 1702 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrDiffuseLightingEffect);
1667 1703
1668 const GrFragmentProcessor* GrDiffuseLightingEffect::TestCreate(GrProcessorTestDa ta* d) { 1704 const GrFragmentProcessor* GrDiffuseLightingEffect::TestCreate(GrProcessorTestDa ta* d) {
1705 int texIdx = d->fRandom->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx :
1706 GrProcessorUnitTest::kAlphaTextureIdx;
1707 GrTexture* tex = d->fTextures[texIdx];
1669 SkScalar surfaceScale = d->fRandom->nextSScalar1(); 1708 SkScalar surfaceScale = d->fRandom->nextSScalar1();
1670 SkScalar kd = d->fRandom->nextUScalar1(); 1709 SkScalar kd = d->fRandom->nextUScalar1();
1671 SkAutoTUnref<SkImageFilterLight> light(create_random_light(d->fRandom)); 1710 SkAutoTUnref<SkImageFilterLight> light(create_random_light(d->fRandom));
1672 SkMatrix matrix; 1711 SkMatrix matrix;
1673 for (int i = 0; i < 9; i++) { 1712 for (int i = 0; i < 9; i++) {
1674 matrix[i] = d->fRandom->nextUScalar1(); 1713 matrix[i] = d->fRandom->nextUScalar1();
1675 } 1714 }
1715 SkIRect srcBounds = SkIRect::MakeXYWH(d->fRandom->nextRangeU(0, tex->width() ),
1716 d->fRandom->nextRangeU(0, tex->height( )),
1717 d->fRandom->nextRangeU(0, tex->width() ),
1718 d->fRandom->nextRangeU(0, tex->height( )));
1676 BoundaryMode mode = static_cast<BoundaryMode>(d->fRandom->nextU() % kBoundar yModeCount); 1719 BoundaryMode mode = static_cast<BoundaryMode>(d->fRandom->nextU() % kBoundar yModeCount);
1677 return GrDiffuseLightingEffect::Create(d->fTextures[GrProcessorUnitTest::kAl phaTextureIdx], 1720 return GrDiffuseLightingEffect::Create(tex, light, surfaceScale, matrix, kd, mode, &srcBounds);
1678 light, surfaceScale, matrix, kd, mode );
1679 } 1721 }
1680 1722
1681 1723
1682 /////////////////////////////////////////////////////////////////////////////// 1724 ///////////////////////////////////////////////////////////////////////////////
1683 1725
1684 void GrGLLightingEffect::emitCode(EmitArgs& args) { 1726 void GrGLLightingEffect::emitCode(EmitArgs& args) {
1685 const GrLightingEffect& le = args.fFp.cast<GrLightingEffect>(); 1727 const GrLightingEffect& le = args.fFp.cast<GrLightingEffect>();
1686 if (!fLight) { 1728 if (!fLight) {
1687 fLight = le.light()->createGLLight(); 1729 fLight = le.light()->createGLLight();
1688 } 1730 }
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
1748 fragBuilder->codeAppend("\t\tfloat m[9];\n"); 1790 fragBuilder->codeAppend("\t\tfloat m[9];\n");
1749 1791
1750 const char* imgInc = uniformHandler->getUniformCStr(fImageIncrementUni); 1792 const char* imgInc = uniformHandler->getUniformCStr(fImageIncrementUni);
1751 const char* surfScale = uniformHandler->getUniformCStr(fSurfaceScaleUni); 1793 const char* surfScale = uniformHandler->getUniformCStr(fSurfaceScaleUni);
1752 1794
1753 int index = 0; 1795 int index = 0;
1754 for (int dy = 1; dy >= -1; dy--) { 1796 for (int dy = 1; dy >= -1; dy--) {
1755 for (int dx = -1; dx <= 1; dx++) { 1797 for (int dx = -1; dx <= 1; dx++) {
1756 SkString texCoords; 1798 SkString texCoords;
1757 texCoords.appendf("coord + vec2(%d, %d) * %s", dx, dy, imgInc); 1799 texCoords.appendf("coord + vec2(%d, %d) * %s", dx, dy, imgInc);
1758 fragBuilder->codeAppendf("\t\tm[%d] = ", index++); 1800 SkString temp;
1759 fragBuilder->appendTextureLookup(args.fSamplers[0], texCoords.c_str( )); 1801 temp.appendf("temp%d", index);
1760 fragBuilder->codeAppend(".a;\n"); 1802 fragBuilder->codeAppendf("vec4 %s;", temp.c_str());
1803 fDomain.sampleTexture(fragBuilder,
1804 args.fUniformHandler,
1805 args.fGLSLCaps,
1806 le.domain(),
1807 temp.c_str(),
1808 texCoords,
1809 args.fSamplers[0]);
1810 fragBuilder->codeAppendf("m[%d] = %s.a;", index, temp.c_str());
1811 index++;
1761 } 1812 }
1762 } 1813 }
1763 fragBuilder->codeAppend("\t\tvec3 surfaceToLight = "); 1814 fragBuilder->codeAppend("\t\tvec3 surfaceToLight = ");
1764 SkString arg; 1815 SkString arg;
1765 arg.appendf("%s * m[4]", surfScale); 1816 arg.appendf("%s * m[4]", surfScale);
1766 fLight->emitSurfaceToLight(uniformHandler, fragBuilder, arg.c_str()); 1817 fLight->emitSurfaceToLight(uniformHandler, fragBuilder, arg.c_str());
1767 fragBuilder->codeAppend(";\n"); 1818 fragBuilder->codeAppend(";\n");
1768 fragBuilder->codeAppendf("\t\t%s = %s(%s(m, %s), surfaceToLight, ", 1819 fragBuilder->codeAppendf("\t\t%s = %s(%s(m, %s), surfaceToLight, ",
1769 args.fOutputColor, lightFunc.c_str(), normalName.c_ str(), surfScale); 1820 args.fOutputColor, lightFunc.c_str(), normalName.c_ str(), surfScale);
1770 fLight->emitLightColor(uniformHandler, fragBuilder, "surfaceToLight"); 1821 fLight->emitLightColor(uniformHandler, fragBuilder, "surfaceToLight");
1771 fragBuilder->codeAppend(");\n"); 1822 fragBuilder->codeAppend(");\n");
1772 SkString modulate; 1823 SkString modulate;
1773 GrGLSLMulVarBy4f(&modulate, args.fOutputColor, args.fInputColor); 1824 GrGLSLMulVarBy4f(&modulate, args.fOutputColor, args.fInputColor);
1774 fragBuilder->codeAppend(modulate.c_str()); 1825 fragBuilder->codeAppend(modulate.c_str());
1775 } 1826 }
1776 1827
1777 void GrGLLightingEffect::GenKey(const GrProcessor& proc, 1828 void GrGLLightingEffect::GenKey(const GrProcessor& proc,
1778 const GrGLSLCaps& caps, GrProcessorKeyBuilder* b ) { 1829 const GrGLSLCaps& caps, GrProcessorKeyBuilder* b ) {
1779 const GrLightingEffect& lighting = proc.cast<GrLightingEffect>(); 1830 const GrLightingEffect& lighting = proc.cast<GrLightingEffect>();
1780 b->add32(lighting.boundaryMode() << 2 | lighting.light()->type()); 1831 b->add32(lighting.boundaryMode() << 2 | lighting.light()->type());
1832 b->add32(GrTextureDomain::GLDomain::DomainKey(lighting.domain()));
1781 } 1833 }
1782 1834
1783 void GrGLLightingEffect::onSetData(const GrGLSLProgramDataManager& pdman, 1835 void GrGLLightingEffect::onSetData(const GrGLSLProgramDataManager& pdman,
1784 const GrProcessor& proc) { 1836 const GrProcessor& proc) {
1785 const GrLightingEffect& lighting = proc.cast<GrLightingEffect>(); 1837 const GrLightingEffect& lighting = proc.cast<GrLightingEffect>();
1786 if (!fLight) { 1838 if (!fLight) {
1787 fLight = lighting.light()->createGLLight(); 1839 fLight = lighting.light()->createGLLight();
1788 } 1840 }
1789 1841
1790 GrTexture* texture = lighting.texture(0); 1842 GrTexture* texture = lighting.texture(0);
1791 float ySign = texture->origin() == kTopLeft_GrSurfaceOrigin ? -1.0f : 1.0f; 1843 float ySign = texture->origin() == kTopLeft_GrSurfaceOrigin ? -1.0f : 1.0f;
1792 pdman.set2f(fImageIncrementUni, 1.0f / texture->width(), ySign / texture->he ight()); 1844 pdman.set2f(fImageIncrementUni, 1.0f / texture->width(), ySign / texture->he ight());
1793 pdman.set1f(fSurfaceScaleUni, lighting.surfaceScale()); 1845 pdman.set1f(fSurfaceScaleUni, lighting.surfaceScale());
1794 SkAutoTUnref<SkImageFilterLight> transformedLight( 1846 SkAutoTUnref<SkImageFilterLight> transformedLight(
1795 lighting.light()->transform(lighting .filterMatrix())); 1847 lighting.light()->transform(lighting .filterMatrix()));
1848 fDomain.setData(pdman, lighting.domain(), texture->origin());
1796 fLight->setData(pdman, transformedLight); 1849 fLight->setData(pdman, transformedLight);
1797 } 1850 }
1798 1851
1799 /////////////////////////////////////////////////////////////////////////////// 1852 ///////////////////////////////////////////////////////////////////////////////
1800 1853
1801 /////////////////////////////////////////////////////////////////////////////// 1854 ///////////////////////////////////////////////////////////////////////////////
1802 1855
1803 void GrGLDiffuseLightingEffect::emitLightFunc(GrGLSLUniformHandler* uniformHandl er, 1856 void GrGLDiffuseLightingEffect::emitLightFunc(GrGLSLUniformHandler* uniformHandl er,
1804 GrGLSLFragmentBuilder* fragBuilder , 1857 GrGLSLFragmentBuilder* fragBuilder ,
1805 SkString* funcName) { 1858 SkString* funcName) {
(...skipping 26 matching lines...) Expand all
1832 } 1885 }
1833 1886
1834 /////////////////////////////////////////////////////////////////////////////// 1887 ///////////////////////////////////////////////////////////////////////////////
1835 1888
1836 GrSpecularLightingEffect::GrSpecularLightingEffect(GrTexture* texture, 1889 GrSpecularLightingEffect::GrSpecularLightingEffect(GrTexture* texture,
1837 const SkImageFilterLight* lig ht, 1890 const SkImageFilterLight* lig ht,
1838 SkScalar surfaceScale, 1891 SkScalar surfaceScale,
1839 const SkMatrix& matrix, 1892 const SkMatrix& matrix,
1840 SkScalar ks, 1893 SkScalar ks,
1841 SkScalar shininess, 1894 SkScalar shininess,
1842 BoundaryMode boundaryMode) 1895 BoundaryMode boundaryMode,
1843 : INHERITED(texture, light, surfaceScale, matrix, boundaryMode) 1896 const SkIRect* srcBounds)
1897 : INHERITED(texture, light, surfaceScale, matrix, boundaryMode, srcBounds)
1844 , fKS(ks) 1898 , fKS(ks)
1845 , fShininess(shininess) { 1899 , fShininess(shininess) {
1846 this->initClassID<GrSpecularLightingEffect>(); 1900 this->initClassID<GrSpecularLightingEffect>();
1847 } 1901 }
1848 1902
1849 bool GrSpecularLightingEffect::onIsEqual(const GrFragmentProcessor& sBase) const { 1903 bool GrSpecularLightingEffect::onIsEqual(const GrFragmentProcessor& sBase) const {
1850 const GrSpecularLightingEffect& s = sBase.cast<GrSpecularLightingEffect>(); 1904 const GrSpecularLightingEffect& s = sBase.cast<GrSpecularLightingEffect>();
1851 return INHERITED::onIsEqual(sBase) && 1905 return INHERITED::onIsEqual(sBase) &&
1852 this->ks() == s.ks() && 1906 this->ks() == s.ks() &&
1853 this->shininess() == s.shininess(); 1907 this->shininess() == s.shininess();
1854 } 1908 }
1855 1909
1856 void GrSpecularLightingEffect::onGetGLSLProcessorKey(const GrGLSLCaps& caps, 1910 void GrSpecularLightingEffect::onGetGLSLProcessorKey(const GrGLSLCaps& caps,
1857 GrProcessorKeyBuilder* b) c onst { 1911 GrProcessorKeyBuilder* b) c onst {
1858 GrGLSpecularLightingEffect::GenKey(*this, caps, b); 1912 GrGLSpecularLightingEffect::GenKey(*this, caps, b);
1859 } 1913 }
1860 1914
1861 GrGLSLFragmentProcessor* GrSpecularLightingEffect::onCreateGLSLInstance() const { 1915 GrGLSLFragmentProcessor* GrSpecularLightingEffect::onCreateGLSLInstance() const {
1862 return new GrGLSpecularLightingEffect; 1916 return new GrGLSpecularLightingEffect;
1863 } 1917 }
1864 1918
1865 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrSpecularLightingEffect); 1919 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrSpecularLightingEffect);
1866 1920
1867 const GrFragmentProcessor* GrSpecularLightingEffect::TestCreate(GrProcessorTestD ata* d) { 1921 const GrFragmentProcessor* GrSpecularLightingEffect::TestCreate(GrProcessorTestD ata* d) {
1922 int texIdx = d->fRandom->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx :
1923 GrProcessorUnitTest::kAlphaTextureIdx;
1924 GrTexture* tex = d->fTextures[texIdx];
1868 SkScalar surfaceScale = d->fRandom->nextSScalar1(); 1925 SkScalar surfaceScale = d->fRandom->nextSScalar1();
1869 SkScalar ks = d->fRandom->nextUScalar1(); 1926 SkScalar ks = d->fRandom->nextUScalar1();
1870 SkScalar shininess = d->fRandom->nextUScalar1(); 1927 SkScalar shininess = d->fRandom->nextUScalar1();
1871 SkAutoTUnref<SkImageFilterLight> light(create_random_light(d->fRandom)); 1928 SkAutoTUnref<SkImageFilterLight> light(create_random_light(d->fRandom));
1872 SkMatrix matrix; 1929 SkMatrix matrix;
1873 for (int i = 0; i < 9; i++) { 1930 for (int i = 0; i < 9; i++) {
1874 matrix[i] = d->fRandom->nextUScalar1(); 1931 matrix[i] = d->fRandom->nextUScalar1();
1875 } 1932 }
1876 BoundaryMode mode = static_cast<BoundaryMode>(d->fRandom->nextU() % kBoundar yModeCount); 1933 BoundaryMode mode = static_cast<BoundaryMode>(d->fRandom->nextU() % kBoundar yModeCount);
1934 SkIRect srcBounds = SkIRect::MakeXYWH(d->fRandom->nextRangeU(0, tex->width() ),
1935 d->fRandom->nextRangeU(0, tex->height( )),
1936 d->fRandom->nextRangeU(0, tex->width() ),
1937 d->fRandom->nextRangeU(0, tex->height( )));
1877 return GrSpecularLightingEffect::Create(d->fTextures[GrProcessorUnitTest::kA lphaTextureIdx], 1938 return GrSpecularLightingEffect::Create(d->fTextures[GrProcessorUnitTest::kA lphaTextureIdx],
1878 light, surfaceScale, matrix, ks, shi niness, mode); 1939 light, surfaceScale, matrix, ks, shi niness, mode,
1940 &srcBounds);
1879 } 1941 }
1880 1942
1881 /////////////////////////////////////////////////////////////////////////////// 1943 ///////////////////////////////////////////////////////////////////////////////
1882 1944
1883 void GrGLSpecularLightingEffect::emitLightFunc(GrGLSLUniformHandler* uniformHand ler, 1945 void GrGLSpecularLightingEffect::emitLightFunc(GrGLSLUniformHandler* uniformHand ler,
1884 GrGLSLFragmentBuilder* fragBuilde r, 1946 GrGLSLFragmentBuilder* fragBuilde r,
1885 SkString* funcName) { 1947 SkString* funcName) {
1886 const char* ks; 1948 const char* ks;
1887 const char* shininess; 1949 const char* shininess;
1888 1950
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
2056 2118
2057 fragBuilder->codeAppendf("%s(%s)", fLightColorFunc.c_str(), surfaceToLight); 2119 fragBuilder->codeAppendf("%s(%s)", fLightColorFunc.c_str(), surfaceToLight);
2058 } 2120 }
2059 2121
2060 #endif 2122 #endif
2061 2123
2062 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingImageFilter) 2124 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingImageFilter)
2063 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDiffuseLightingImageFilter) 2125 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDiffuseLightingImageFilter)
2064 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSpecularLightingImageFilter) 2126 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSpecularLightingImageFilter)
2065 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END 2127 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698