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

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

Issue 1034733002: Implement approx-match support in image filter saveLayer() offscreen. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix empty/out-of-range rects in GrTextureDomain Clamp mode Created 5 years, 8 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/core/SkCanvas.cpp ('k') | src/effects/SkMagnifierImageFilter.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 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 SkScalarIsFinite(point.fZ)); 270 SkScalarIsFinite(point.fZ));
271 return point; 271 return point;
272 }; 272 };
273 273
274 void writePoint3(const SkPoint3& point, SkWriteBuffer& buffer) { 274 void writePoint3(const SkPoint3& point, SkWriteBuffer& buffer) {
275 buffer.writeScalar(point.fX); 275 buffer.writeScalar(point.fX);
276 buffer.writeScalar(point.fY); 276 buffer.writeScalar(point.fY);
277 buffer.writeScalar(point.fZ); 277 buffer.writeScalar(point.fZ);
278 }; 278 };
279 279
280 class SkDiffuseLightingImageFilter : public SkLightingImageFilter { 280 enum BoundaryMode {
281 kTopLeft_BoundaryMode,
282 kTop_BoundaryMode,
283 kTopRight_BoundaryMode,
284 kLeft_BoundaryMode,
285 kInterior_BoundaryMode,
286 kRight_BoundaryMode,
287 kBottomLeft_BoundaryMode,
288 kBottom_BoundaryMode,
289 kBottomRight_BoundaryMode,
290
291 kBoundaryModeCount,
292 };
293
294 class SkLightingImageFilterInternal : public SkLightingImageFilter {
295 protected:
296 SkLightingImageFilterInternal(SkLight* light,
297 SkScalar surfaceScale,
298 SkImageFilter* input,
299 const CropRect* cropRect)
300 : INHERITED(light, surfaceScale, input, cropRect) {}
301
302 #if SK_SUPPORT_GPU
303 bool canFilterImageGPU() const override { return true; }
304 bool filterImageGPU(Proxy*, const SkBitmap& src, const Context&,
305 SkBitmap* result, SkIPoint* offset) const override;
306 virtual GrFragmentProcessor* getFragmentProcessor(GrTexture*,
307 const SkMatrix&,
308 const SkIRect& bounds,
309 BoundaryMode boundaryMode) const = 0;
310 #endif
311 private:
312 #if SK_SUPPORT_GPU
313 void drawRect(GrContext* context,
314 GrTexture* src,
315 GrTexture* dst,
316 const SkMatrix& matrix,
317 const GrClip& clip,
318 const SkRect& dstRect,
319 BoundaryMode boundaryMode,
320 const SkIRect& bounds) const;
321 #endif
322 typedef SkLightingImageFilter INHERITED;
323 };
324
325 #if SK_SUPPORT_GPU
326 void SkLightingImageFilterInternal::drawRect(GrContext* context,
327 GrTexture* src,
328 GrTexture* dst,
329 const SkMatrix& matrix,
330 const GrClip& clip,
331 const SkRect& dstRect,
332 BoundaryMode boundaryMode,
333 const SkIRect& bounds) const {
334 SkRect srcRect = dstRect.makeOffset(SkIntToScalar(bounds.x()), SkIntToScalar (bounds.y()));
335 GrFragmentProcessor* fp = this->getFragmentProcessor(src, matrix, bounds, bo undaryMode);
336 GrPaint paint;
337 paint.addColorProcessor(fp)->unref();
338 context->drawNonAARectToRect(dst->asRenderTarget(), clip, paint, SkMatrix::I (),
339 dstRect, srcRect);
340 }
341
342 bool SkLightingImageFilterInternal::filterImageGPU(Proxy* proxy,
343 const SkBitmap& src,
344 const Context& ctx,
345 SkBitmap* result,
346 SkIPoint* offset) const {
347 SkBitmap input = src;
348 SkIPoint srcOffset = SkIPoint::Make(0, 0);
349 if (this->getInput(0) &&
350 !this->getInput(0)->getInputResultGPU(proxy, src, ctx, &input, &srcOffse t)) {
351 return false;
352 }
353 SkIRect bounds;
354 if (!this->applyCropRect(ctx, proxy, input, &srcOffset, &bounds, &input)) {
355 return false;
356 }
357 SkRect dstRect = SkRect::MakeWH(SkIntToScalar(bounds.width()),
358 SkIntToScalar(bounds.height()));
359 GrTexture* srcTexture = input.getTexture();
360 GrContext* context = srcTexture->getContext();
361
362 GrSurfaceDesc desc;
363 desc.fFlags = kRenderTarget_GrSurfaceFlag,
364 desc.fWidth = bounds.width();
365 desc.fHeight = bounds.height();
366 desc.fConfig = kRGBA_8888_GrPixelConfig;
367
368 SkAutoTUnref<GrTexture> dst(
369 context->refScratchTexture(desc, GrContext::kApprox_ScratchTexMatch));
370 if (!dst) {
371 return false;
372 }
373
374 // setup new clip
375 GrClip clip(dstRect);
376
377 offset->fX = bounds.left();
378 offset->fY = bounds.top();
379 SkMatrix matrix(ctx.ctm());
380 matrix.postTranslate(SkIntToScalar(-bounds.left()), SkIntToScalar(-bounds.to p()));
381 bounds.offset(-srcOffset);
382 SkRect topLeft = SkRect::MakeXYWH(0, 0, 1, 1);
383 SkRect top = SkRect::MakeXYWH(1, 0, dstRect.width() - 2, 1);
384 SkRect topRight = SkRect::MakeXYWH(dstRect.width() - 1, 0, 1, 1);
385 SkRect left = SkRect::MakeXYWH(0, 1, 1, dstRect.height() - 2);
386 SkRect interior = dstRect.makeInset(1, 1);
387 SkRect right = SkRect::MakeXYWH(dstRect.width() - 1, 1, 1, dstRect.height() - 2);
388 SkRect bottomLeft = SkRect::MakeXYWH(0, dstRect.height() - 1, 1, 1);
389 SkRect bottom = SkRect::MakeXYWH(1, dstRect.height() - 1, dstRect.width() - 2, 1);
390 SkRect bottomRight = SkRect::MakeXYWH(dstRect.width() - 1, dstRect.height() - 1, 1, 1);
391 this->drawRect(context, srcTexture, dst, matrix, clip, topLeft, kTopLeft_Bou ndaryMode, bounds);
392 this->drawRect(context, srcTexture, dst, matrix, clip, top, kTop_BoundaryMod e, bounds);
393 this->drawRect(context, srcTexture, dst, matrix, clip, topRight, kTopRight_B oundaryMode,
394 bounds);
395 this->drawRect(context, srcTexture, dst, matrix, clip, left, kLeft_BoundaryM ode, bounds);
396 this->drawRect(context, srcTexture, dst, matrix, clip, interior, kInterior_B oundaryMode,
397 bounds);
398 this->drawRect(context, srcTexture, dst, matrix, clip, right, kRight_Boundar yMode, bounds);
399 this->drawRect(context, srcTexture, dst, matrix, clip, bottomLeft, kBottomLe ft_BoundaryMode,
400 bounds);
401 this->drawRect(context, srcTexture, dst, matrix, clip, bottom, kBottom_Bound aryMode, bounds);
402 this->drawRect(context, srcTexture, dst, matrix, clip, bottomRight, kBottomR ight_BoundaryMode,
403 bounds);
404 WrapTexture(dst, bounds.width(), bounds.height(), result);
405 return true;
406 }
407 #endif
408
409 class SkDiffuseLightingImageFilter : public SkLightingImageFilterInternal {
281 public: 410 public:
282 static SkImageFilter* Create(SkLight* light, SkScalar surfaceScale, SkScalar kd, SkImageFilter*, 411 static SkImageFilter* Create(SkLight* light, SkScalar surfaceScale, SkScalar kd, SkImageFilter*,
283 const CropRect*); 412 const CropRect*);
284 413
285 SK_TO_STRING_OVERRIDE() 414 SK_TO_STRING_OVERRIDE()
286 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkDiffuseLightingImageFi lter) 415 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkDiffuseLightingImageFi lter)
287 SkScalar kd() const { return fKD; } 416 SkScalar kd() const { return fKD; }
288 417
289 protected: 418 protected:
290 SkDiffuseLightingImageFilter(SkLight* light, SkScalar surfaceScale, 419 SkDiffuseLightingImageFilter(SkLight* light, SkScalar surfaceScale,
291 SkScalar kd, SkImageFilter* input, const CropRe ct* cropRect); 420 SkScalar kd, SkImageFilter* input, const CropRe ct* cropRect);
292 void flatten(SkWriteBuffer& buffer) const override; 421 void flatten(SkWriteBuffer& buffer) const override;
293 virtual bool onFilterImage(Proxy*, const SkBitmap& src, const Context&, 422 bool onFilterImage(Proxy*, const SkBitmap& src, const Context&,
294 SkBitmap* result, SkIPoint* offset) const overrid e; 423 SkBitmap* result, SkIPoint* offset) const override;
295 #if SK_SUPPORT_GPU 424 #if SK_SUPPORT_GPU
296 virtual bool asFragmentProcessor(GrFragmentProcessor**, GrTexture*, const Sk Matrix&, 425 GrFragmentProcessor* getFragmentProcessor(GrTexture*, const SkMatrix&,
297 const SkIRect& bounds) const override; 426 const SkIRect& bounds, BoundaryMod e) const override;
298 #endif 427 #endif
299 428
300 private: 429 private:
301 friend class SkLightingImageFilter; 430 friend class SkLightingImageFilter;
302 typedef SkLightingImageFilter INHERITED; 431 typedef SkLightingImageFilterInternal INHERITED;
303 SkScalar fKD; 432 SkScalar fKD;
304 }; 433 };
305 434
306 class SkSpecularLightingImageFilter : public SkLightingImageFilter { 435 class SkSpecularLightingImageFilter : public SkLightingImageFilterInternal {
307 public: 436 public:
308 static SkImageFilter* Create(SkLight* light, SkScalar surfaceScale, 437 static SkImageFilter* Create(SkLight* light, SkScalar surfaceScale,
309 SkScalar ks, SkScalar shininess, SkImageFilter* , const CropRect*); 438 SkScalar ks, SkScalar shininess, SkImageFilter* , const CropRect*);
310 439
311 SK_TO_STRING_OVERRIDE() 440 SK_TO_STRING_OVERRIDE()
312 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkSpecularLightingImageF ilter) 441 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkSpecularLightingImageF ilter)
313 442
314 SkScalar ks() const { return fKS; } 443 SkScalar ks() const { return fKS; }
315 SkScalar shininess() const { return fShininess; } 444 SkScalar shininess() const { return fShininess; }
316 445
317 protected: 446 protected:
318 SkSpecularLightingImageFilter(SkLight* light, SkScalar surfaceScale, SkScala r ks, 447 SkSpecularLightingImageFilter(SkLight* light, SkScalar surfaceScale, SkScala r ks,
319 SkScalar shininess, SkImageFilter* input, cons t CropRect*); 448 SkScalar shininess, SkImageFilter* input, cons t CropRect*);
320 void flatten(SkWriteBuffer& buffer) const override; 449 void flatten(SkWriteBuffer& buffer) const override;
321 virtual bool onFilterImage(Proxy*, const SkBitmap& src, const Context&, 450 bool onFilterImage(Proxy*, const SkBitmap& src, const Context&,
322 SkBitmap* result, SkIPoint* offset) const overrid e; 451 SkBitmap* result, SkIPoint* offset) const override;
323 #if SK_SUPPORT_GPU 452 #if SK_SUPPORT_GPU
324 virtual bool asFragmentProcessor(GrFragmentProcessor**, GrTexture*, const Sk Matrix&, 453 GrFragmentProcessor* getFragmentProcessor(GrTexture*, const SkMatrix&,
325 const SkIRect& bounds) const override; 454 const SkIRect& bounds, BoundaryMod e) const override;
326 #endif 455 #endif
327 456
328 private: 457 private:
329 SkScalar fKS; 458 SkScalar fKS;
330 SkScalar fShininess; 459 SkScalar fShininess;
331 friend class SkLightingImageFilter; 460 friend class SkLightingImageFilter;
332 typedef SkLightingImageFilter INHERITED; 461 typedef SkLightingImageFilterInternal INHERITED;
333 }; 462 };
334 463
335 #if SK_SUPPORT_GPU 464 #if SK_SUPPORT_GPU
336 465
337 class GrLightingEffect : public GrSingleTextureEffect { 466 class GrLightingEffect : public GrSingleTextureEffect {
338 public: 467 public:
339 GrLightingEffect(GrTexture* texture, const SkLight* light, SkScalar surfaceS cale, const SkMatrix& matrix); 468 GrLightingEffect(GrTexture* texture, const SkLight* light, SkScalar surfaceS cale,
469 const SkMatrix& matrix, BoundaryMode boundaryMode);
340 virtual ~GrLightingEffect(); 470 virtual ~GrLightingEffect();
341 471
342 const SkLight* light() const { return fLight; } 472 const SkLight* light() const { return fLight; }
343 SkScalar surfaceScale() const { return fSurfaceScale; } 473 SkScalar surfaceScale() const { return fSurfaceScale; }
344 const SkMatrix& filterMatrix() const { return fFilterMatrix; } 474 const SkMatrix& filterMatrix() const { return fFilterMatrix; }
475 BoundaryMode boundaryMode() const { return fBoundaryMode; }
345 476
346 protected: 477 protected:
347 bool onIsEqual(const GrFragmentProcessor&) const override; 478 bool onIsEqual(const GrFragmentProcessor&) const override;
348 479
349 void onComputeInvariantOutput(GrInvariantOutput* inout) const override { 480 void onComputeInvariantOutput(GrInvariantOutput* inout) const override {
350 // lighting shaders are complicated. We just throw up our hands. 481 // lighting shaders are complicated. We just throw up our hands.
351 inout->mulByUnknownFourComponents(); 482 inout->mulByUnknownFourComponents();
352 } 483 }
353 484
354 private: 485 private:
355 typedef GrSingleTextureEffect INHERITED; 486 typedef GrSingleTextureEffect INHERITED;
356 const SkLight* fLight; 487 const SkLight* fLight;
357 SkScalar fSurfaceScale; 488 SkScalar fSurfaceScale;
358 SkMatrix fFilterMatrix; 489 SkMatrix fFilterMatrix;
490 BoundaryMode fBoundaryMode;
359 }; 491 };
360 492
361 class GrDiffuseLightingEffect : public GrLightingEffect { 493 class GrDiffuseLightingEffect : public GrLightingEffect {
362 public: 494 public:
363 static GrFragmentProcessor* Create(GrTexture* texture, 495 static GrFragmentProcessor* Create(GrTexture* texture,
364 const SkLight* light, 496 const SkLight* light,
365 SkScalar surfaceScale, 497 SkScalar surfaceScale,
366 const SkMatrix& matrix, 498 const SkMatrix& matrix,
367 SkScalar kd) { 499 SkScalar kd,
500 BoundaryMode boundaryMode) {
368 return SkNEW_ARGS(GrDiffuseLightingEffect, (texture, 501 return SkNEW_ARGS(GrDiffuseLightingEffect, (texture,
369 light, 502 light,
370 surfaceScale, 503 surfaceScale,
371 matrix, 504 matrix,
372 kd)); 505 kd,
506 boundaryMode));
373 } 507 }
374 508
375 const char* name() const override { return "DiffuseLighting"; } 509 const char* name() const override { return "DiffuseLighting"; }
376 510
377 void getGLProcessorKey(const GrGLCaps&, GrProcessorKeyBuilder*) const overri de; 511 void getGLProcessorKey(const GrGLCaps&, GrProcessorKeyBuilder*) const overri de;
378 512
379 GrGLFragmentProcessor* createGLInstance() const override; 513 GrGLFragmentProcessor* createGLInstance() const override;
380 514
381 SkScalar kd() const { return fKD; } 515 SkScalar kd() const { return fKD; }
382 516
383 private: 517 private:
384 bool onIsEqual(const GrFragmentProcessor&) const override; 518 bool onIsEqual(const GrFragmentProcessor&) const override;
385 519
386 GrDiffuseLightingEffect(GrTexture* texture, 520 GrDiffuseLightingEffect(GrTexture* texture,
387 const SkLight* light, 521 const SkLight* light,
388 SkScalar surfaceScale, 522 SkScalar surfaceScale,
389 const SkMatrix& matrix, 523 const SkMatrix& matrix,
390 SkScalar kd); 524 SkScalar kd,
525 BoundaryMode boundaryMode);
391 526
392 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; 527 GR_DECLARE_FRAGMENT_PROCESSOR_TEST;
393 typedef GrLightingEffect INHERITED; 528 typedef GrLightingEffect INHERITED;
394 SkScalar fKD; 529 SkScalar fKD;
395 }; 530 };
396 531
397 class GrSpecularLightingEffect : public GrLightingEffect { 532 class GrSpecularLightingEffect : public GrLightingEffect {
398 public: 533 public:
399 static GrFragmentProcessor* Create(GrTexture* texture, 534 static GrFragmentProcessor* Create(GrTexture* texture,
400 const SkLight* light, 535 const SkLight* light,
401 SkScalar surfaceScale, 536 SkScalar surfaceScale,
402 const SkMatrix& matrix, 537 const SkMatrix& matrix,
403 SkScalar ks, 538 SkScalar ks,
404 SkScalar shininess) { 539 SkScalar shininess,
540 BoundaryMode boundaryMode) {
405 return SkNEW_ARGS(GrSpecularLightingEffect, (texture, 541 return SkNEW_ARGS(GrSpecularLightingEffect, (texture,
406 light, 542 light,
407 surfaceScale, 543 surfaceScale,
408 matrix, 544 matrix,
409 ks, 545 ks,
410 shininess)); 546 shininess,
547 boundaryMode));
411 } 548 }
412 549
413 const char* name() const override { return "SpecularLighting"; } 550 const char* name() const override { return "SpecularLighting"; }
414 551
415 void getGLProcessorKey(const GrGLCaps&, GrProcessorKeyBuilder*) const overri de; 552 void getGLProcessorKey(const GrGLCaps&, GrProcessorKeyBuilder*) const overri de;
416 553
417 GrGLFragmentProcessor* createGLInstance() const override; 554 GrGLFragmentProcessor* createGLInstance() const override;
418 555
419 SkScalar ks() const { return fKS; } 556 SkScalar ks() const { return fKS; }
420 SkScalar shininess() const { return fShininess; } 557 SkScalar shininess() const { return fShininess; }
421 558
422 private: 559 private:
423 bool onIsEqual(const GrFragmentProcessor&) const override; 560 bool onIsEqual(const GrFragmentProcessor&) const override;
424 561
425 GrSpecularLightingEffect(GrTexture* texture, 562 GrSpecularLightingEffect(GrTexture* texture,
426 const SkLight* light, 563 const SkLight* light,
427 SkScalar surfaceScale, 564 SkScalar surfaceScale,
428 const SkMatrix& matrix, 565 const SkMatrix& matrix,
429 SkScalar ks, 566 SkScalar ks,
430 SkScalar shininess); 567 SkScalar shininess,
568 BoundaryMode boundaryMode);
431 569
432 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; 570 GR_DECLARE_FRAGMENT_PROCESSOR_TEST;
433 typedef GrLightingEffect INHERITED; 571 typedef GrLightingEffect INHERITED;
434 SkScalar fKS; 572 SkScalar fKS;
435 SkScalar fShininess; 573 SkScalar fShininess;
436 }; 574 };
437 575
438 /////////////////////////////////////////////////////////////////////////////// 576 ///////////////////////////////////////////////////////////////////////////////
439 577
440 class GrGLLight { 578 class GrGLLight {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 UniformHandle fColorUni; 612 UniformHandle fColorUni;
475 613
476 typedef SkRefCnt INHERITED; 614 typedef SkRefCnt INHERITED;
477 }; 615 };
478 616
479 /////////////////////////////////////////////////////////////////////////////// 617 ///////////////////////////////////////////////////////////////////////////////
480 618
481 class GrGLDistantLight : public GrGLLight { 619 class GrGLDistantLight : public GrGLLight {
482 public: 620 public:
483 virtual ~GrGLDistantLight() {} 621 virtual ~GrGLDistantLight() {}
484 virtual void setData(const GrGLProgramDataManager&, 622 void setData(const GrGLProgramDataManager&, const SkLight* light) const over ride;
485 const SkLight* light) const override;
486 void emitSurfaceToLight(GrGLFPBuilder*, const char* z) override; 623 void emitSurfaceToLight(GrGLFPBuilder*, const char* z) override;
487 624
488 private: 625 private:
489 typedef GrGLLight INHERITED; 626 typedef GrGLLight INHERITED;
490 UniformHandle fDirectionUni; 627 UniformHandle fDirectionUni;
491 }; 628 };
492 629
493 /////////////////////////////////////////////////////////////////////////////// 630 ///////////////////////////////////////////////////////////////////////////////
494 631
495 class GrGLPointLight : public GrGLLight { 632 class GrGLPointLight : public GrGLLight {
496 public: 633 public:
497 virtual ~GrGLPointLight() {} 634 virtual ~GrGLPointLight() {}
498 virtual void setData(const GrGLProgramDataManager&, 635 void setData(const GrGLProgramDataManager&, const SkLight* light) const over ride;
499 const SkLight* light) const override;
500 void emitSurfaceToLight(GrGLFPBuilder*, const char* z) override; 636 void emitSurfaceToLight(GrGLFPBuilder*, const char* z) override;
501 637
502 private: 638 private:
503 typedef GrGLLight INHERITED; 639 typedef GrGLLight INHERITED;
504 UniformHandle fLocationUni; 640 UniformHandle fLocationUni;
505 }; 641 };
506 642
507 /////////////////////////////////////////////////////////////////////////////// 643 ///////////////////////////////////////////////////////////////////////////////
508 644
509 class GrGLSpotLight : public GrGLLight { 645 class GrGLSpotLight : public GrGLLight {
510 public: 646 public:
511 virtual ~GrGLSpotLight() {} 647 virtual ~GrGLSpotLight() {}
512 virtual void setData(const GrGLProgramDataManager&, 648 void setData(const GrGLProgramDataManager&, const SkLight* light) const over ride;
513 const SkLight* light) const override;
514 void emitSurfaceToLight(GrGLFPBuilder*, const char* z) override; 649 void emitSurfaceToLight(GrGLFPBuilder*, const char* z) override;
515 void emitLightColor(GrGLFPBuilder*, const char *surfaceToLight) override; 650 void emitLightColor(GrGLFPBuilder*, const char *surfaceToLight) override;
516 651
517 private: 652 private:
518 typedef GrGLLight INHERITED; 653 typedef GrGLLight INHERITED;
519 654
520 SkString fLightColorFunc; 655 SkString fLightColorFunc;
521 UniformHandle fLocationUni; 656 UniformHandle fLocationUni;
522 UniformHandle fExponentUni; 657 UniformHandle fExponentUni;
523 UniformHandle fCosOuterConeAngleUni; 658 UniformHandle fCosOuterConeAngleUni;
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
688 823
689 private: 824 private:
690 typedef SkLight INHERITED; 825 typedef SkLight INHERITED;
691 SkPoint3 fLocation; 826 SkPoint3 fLocation;
692 }; 827 };
693 828
694 /////////////////////////////////////////////////////////////////////////////// 829 ///////////////////////////////////////////////////////////////////////////////
695 830
696 class SkSpotLight : public SkLight { 831 class SkSpotLight : public SkLight {
697 public: 832 public:
698 SkSpotLight(const SkPoint3& location, const SkPoint3& target, SkScalar specu larExponent, SkScalar cutoffAngle, SkColor color) 833 SkSpotLight(const SkPoint3& location,
834 const SkPoint3& target,
835 SkScalar specularExponent,
836 SkScalar cutoffAngle,
837 SkColor color)
699 : INHERITED(color), 838 : INHERITED(color),
700 fLocation(location), 839 fLocation(location),
701 fTarget(target), 840 fTarget(target),
702 fSpecularExponent(SkScalarPin(specularExponent, kSpecularExponentMin, kSp ecularExponentMax)) 841 fSpecularExponent(SkScalarPin(specularExponent, kSpecularExponentMin, kSp ecularExponentMax))
703 { 842 {
704 fS = target - location; 843 fS = target - location;
705 fS.normalize(); 844 fS.normalize();
706 fCosOuterConeAngle = SkScalarCos(SkDegreesToRadians(cutoffAngle)); 845 fCosOuterConeAngle = SkScalarCos(SkDegreesToRadians(cutoffAngle));
707 const SkScalar antiAliasThreshold = 0.016f; 846 const SkScalar antiAliasThreshold = 0.016f;
708 fCosInnerConeAngle = fCosOuterConeAngle + antiAliasThreshold; 847 fCosInnerConeAngle = fCosOuterConeAngle + antiAliasThreshold;
709 fConeScale = SkScalarInvert(antiAliasThreshold); 848 fConeScale = SkScalarInvert(antiAliasThreshold);
710 } 849 }
711 850
712 SkLight* transform(const SkMatrix& matrix) const override { 851 SkLight* transform(const SkMatrix& matrix) const override {
713 SkPoint location2 = SkPoint::Make(fLocation.fX, fLocation.fY); 852 SkPoint location2 = SkPoint::Make(fLocation.fX, fLocation.fY);
714 matrix.mapPoints(&location2, 1); 853 matrix.mapPoints(&location2, 1);
715 // Use X scale and Y scale on Z and average the result 854 // Use X scale and Y scale on Z and average the result
716 SkPoint locationZ = SkPoint::Make(fLocation.fZ, fLocation.fZ); 855 SkPoint locationZ = SkPoint::Make(fLocation.fZ, fLocation.fZ);
717 matrix.mapVectors(&locationZ, 1); 856 matrix.mapVectors(&locationZ, 1);
718 SkPoint3 location(location2.fX, location2.fY, SkScalarAve(locationZ.fX, locationZ.fY)); 857 SkPoint3 location(location2.fX, location2.fY, SkScalarAve(locationZ.fX, locationZ.fY));
719 SkPoint target2 = SkPoint::Make(fTarget.fX, fTarget.fY); 858 SkPoint target2 = SkPoint::Make(fTarget.fX, fTarget.fY);
720 matrix.mapPoints(&target2, 1); 859 matrix.mapPoints(&target2, 1);
721 SkPoint targetZ = SkPoint::Make(fTarget.fZ, fTarget.fZ); 860 SkPoint targetZ = SkPoint::Make(fTarget.fZ, fTarget.fZ);
722 matrix.mapVectors(&targetZ, 1); 861 matrix.mapVectors(&targetZ, 1);
723 SkPoint3 target(target2.fX, target2.fY, SkScalarAve(targetZ.fX, targetZ. fY)); 862 SkPoint3 target(target2.fX, target2.fY, SkScalarAve(targetZ.fX, targetZ. fY));
724 SkPoint3 s = target - location; 863 SkPoint3 s = target - location;
725 s.normalize(); 864 s.normalize();
726 return new SkSpotLight(location, target, fSpecularExponent, fCosOuterCon eAngle, fCosInnerConeAngle, fConeScale, s, color()); 865 return new SkSpotLight(location,
866 target,
867 fSpecularExponent,
868 fCosOuterConeAngle,
869 fCosInnerConeAngle,
870 fConeScale,
871 s,
872 color());
727 } 873 }
728 874
729 SkPoint3 surfaceToLight(int x, int y, int z, SkScalar surfaceScale) const { 875 SkPoint3 surfaceToLight(int x, int y, int z, SkScalar surfaceScale) const {
730 SkPoint3 direction(fLocation.fX - SkIntToScalar(x), 876 SkPoint3 direction(fLocation.fX - SkIntToScalar(x),
731 fLocation.fY - SkIntToScalar(y), 877 fLocation.fY - SkIntToScalar(y),
732 fLocation.fZ - SkScalarMul(SkIntToScalar(z), surfaceS cale)); 878 fLocation.fZ - SkScalarMul(SkIntToScalar(z), surfaceS cale));
733 direction.normalize(); 879 direction.normalize();
734 return direction; 880 return direction;
735 }; 881 };
736 SkPoint3 lightColor(const SkPoint3& surfaceToLight) const { 882 SkPoint3 lightColor(const SkPoint3& surfaceToLight) const {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
770 fCosOuterConeAngle = buffer.readScalar(); 916 fCosOuterConeAngle = buffer.readScalar();
771 fCosInnerConeAngle = buffer.readScalar(); 917 fCosInnerConeAngle = buffer.readScalar();
772 fConeScale = buffer.readScalar(); 918 fConeScale = buffer.readScalar();
773 fS = readPoint3(buffer); 919 fS = readPoint3(buffer);
774 buffer.validate(SkScalarIsFinite(fSpecularExponent) && 920 buffer.validate(SkScalarIsFinite(fSpecularExponent) &&
775 SkScalarIsFinite(fCosOuterConeAngle) && 921 SkScalarIsFinite(fCosOuterConeAngle) &&
776 SkScalarIsFinite(fCosInnerConeAngle) && 922 SkScalarIsFinite(fCosInnerConeAngle) &&
777 SkScalarIsFinite(fConeScale)); 923 SkScalarIsFinite(fConeScale));
778 } 924 }
779 protected: 925 protected:
780 SkSpotLight(const SkPoint3& location, const SkPoint3& target, SkScalar specu larExponent, SkScalar cosOuterConeAngle, SkScalar cosInnerConeAngle, SkScalar co neScale, const SkPoint3& s, const SkPoint3& color) 926 SkSpotLight(const SkPoint3& location,
927 const SkPoint3& target,
928 SkScalar specularExponent,
929 SkScalar cosOuterConeAngle,
930 SkScalar cosInnerConeAngle,
931 SkScalar coneScale,
932 const SkPoint3& s,
933 const SkPoint3& color)
781 : INHERITED(color), 934 : INHERITED(color),
782 fLocation(location), 935 fLocation(location),
783 fTarget(target), 936 fTarget(target),
784 fSpecularExponent(specularExponent), 937 fSpecularExponent(specularExponent),
785 fCosOuterConeAngle(cosOuterConeAngle), 938 fCosOuterConeAngle(cosOuterConeAngle),
786 fCosInnerConeAngle(cosInnerConeAngle), 939 fCosInnerConeAngle(cosInnerConeAngle),
787 fConeScale(coneScale), 940 fConeScale(coneScale),
788 fS(s) 941 fS(s)
789 { 942 {
790 } 943 }
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
953 return NULL; 1106 return NULL;
954 } 1107 }
955 // According to the spec, kd can be any non-negative number : 1108 // According to the spec, kd can be any non-negative number :
956 // http://www.w3.org/TR/SVG/filters.html#feDiffuseLightingElement 1109 // http://www.w3.org/TR/SVG/filters.html#feDiffuseLightingElement
957 if (kd < 0) { 1110 if (kd < 0) {
958 return NULL; 1111 return NULL;
959 } 1112 }
960 return SkNEW_ARGS(SkDiffuseLightingImageFilter, (light, surfaceScale, kd, in put, cropRect)); 1113 return SkNEW_ARGS(SkDiffuseLightingImageFilter, (light, surfaceScale, kd, in put, cropRect));
961 } 1114 }
962 1115
963 SkDiffuseLightingImageFilter::SkDiffuseLightingImageFilter(SkLight* light, SkSca lar surfaceScale, SkScalar kd, SkImageFilter* input, const CropRect* cropRect) 1116 SkDiffuseLightingImageFilter::SkDiffuseLightingImageFilter(SkLight* light,
964 : SkLightingImageFilter(light, surfaceScale, input, cropRect), 1117 SkScalar surfaceScale ,
1118 SkScalar kd,
1119 SkImageFilter* input,
1120 const CropRect* cropR ect)
1121 : INHERITED(light, surfaceScale, input, cropRect),
965 fKD(kd) 1122 fKD(kd)
966 { 1123 {
967 } 1124 }
968 1125
969 SkFlattenable* SkDiffuseLightingImageFilter::CreateProc(SkReadBuffer& buffer) { 1126 SkFlattenable* SkDiffuseLightingImageFilter::CreateProc(SkReadBuffer& buffer) {
970 SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 1); 1127 SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 1);
971 SkAutoTUnref<SkLight> light(SkLight::UnflattenLight(buffer)); 1128 SkAutoTUnref<SkLight> light(SkLight::UnflattenLight(buffer));
972 SkScalar surfaceScale = buffer.readScalar(); 1129 SkScalar surfaceScale = buffer.readScalar();
973 SkScalar kd = buffer.readScalar(); 1130 SkScalar kd = buffer.readScalar();
974 return Create(light, surfaceScale, kd, common.getInput(0), &common.cropRect( )); 1131 return Create(light, surfaceScale, kd, common.getInput(0), &common.cropRect( ));
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1013 } 1170 }
1014 1171
1015 SkAutoTUnref<SkLight> transformedLight(light()->transform(ctx.ctm())); 1172 SkAutoTUnref<SkLight> transformedLight(light()->transform(ctx.ctm()));
1016 1173
1017 DiffuseLightingType lightingType(fKD); 1174 DiffuseLightingType lightingType(fKD);
1018 offset->fX = bounds.left(); 1175 offset->fX = bounds.left();
1019 offset->fY = bounds.top(); 1176 offset->fY = bounds.top();
1020 bounds.offset(-srcOffset); 1177 bounds.offset(-srcOffset);
1021 switch (transformedLight->type()) { 1178 switch (transformedLight->type()) {
1022 case SkLight::kDistant_LightType: 1179 case SkLight::kDistant_LightType:
1023 lightBitmap<DiffuseLightingType, SkDistantLight>(lightingType, trans formedLight, src, dst, surfaceScale(), bounds); 1180 lightBitmap<DiffuseLightingType, SkDistantLight>(lightingType,
1181 transformedLight,
1182 src,
1183 dst,
1184 surfaceScale(),
1185 bounds);
1024 break; 1186 break;
1025 case SkLight::kPoint_LightType: 1187 case SkLight::kPoint_LightType:
1026 lightBitmap<DiffuseLightingType, SkPointLight>(lightingType, transfo rmedLight, src, dst, surfaceScale(), bounds); 1188 lightBitmap<DiffuseLightingType, SkPointLight>(lightingType,
1189 transformedLight,
1190 src,
1191 dst,
1192 surfaceScale(),
1193 bounds);
1027 break; 1194 break;
1028 case SkLight::kSpot_LightType: 1195 case SkLight::kSpot_LightType:
1029 lightBitmap<DiffuseLightingType, SkSpotLight>(lightingType, transfor medLight, src, dst, surfaceScale(), bounds); 1196 lightBitmap<DiffuseLightingType, SkSpotLight>(lightingType,
1197 transformedLight,
1198 src,
1199 dst,
1200 surfaceScale(),
1201 bounds);
1030 break; 1202 break;
1031 } 1203 }
1032 1204
1033 return true; 1205 return true;
1034 } 1206 }
1035 1207
1036 #ifndef SK_IGNORE_TO_STRING 1208 #ifndef SK_IGNORE_TO_STRING
1037 void SkDiffuseLightingImageFilter::toString(SkString* str) const { 1209 void SkDiffuseLightingImageFilter::toString(SkString* str) const {
1038 str->appendf("SkDiffuseLightingImageFilter: ("); 1210 str->appendf("SkDiffuseLightingImageFilter: (");
1039 str->appendf("kD: %f\n", fKD); 1211 str->appendf("kD: %f\n", fKD);
1040 str->append(")"); 1212 str->append(")");
1041 } 1213 }
1042 #endif 1214 #endif
1043 1215
1044 #if SK_SUPPORT_GPU 1216 #if SK_SUPPORT_GPU
1045 bool SkDiffuseLightingImageFilter::asFragmentProcessor(GrFragmentProcessor** fp, 1217 GrFragmentProcessor* SkDiffuseLightingImageFilter::getFragmentProcessor(
1046 GrTexture* texture, 1218 GrTexture* texture,
1047 const SkMatrix& matrix, 1219 const SkMatrix& matrix,
1048 const SkIRect&) const { 1220 const SkIRect&,
1049 if (fp) { 1221 BoundaryMode boundaryMode
1050 SkScalar scale = SkScalarMul(surfaceScale(), SkIntToScalar(255)); 1222 ) const {
1051 *fp = GrDiffuseLightingEffect::Create(texture, light(), scale, matrix, k d()); 1223 SkScalar scale = SkScalarMul(surfaceScale(), SkIntToScalar(255));
1052 } 1224 return GrDiffuseLightingEffect::Create(texture, light(), scale, matrix, kd() , boundaryMode);
1053 return true;
1054 } 1225 }
1055 #endif 1226 #endif
1056 1227
1057 /////////////////////////////////////////////////////////////////////////////// 1228 ///////////////////////////////////////////////////////////////////////////////
1058 1229
1059 SkImageFilter* SkSpecularLightingImageFilter::Create(SkLight* light, SkScalar su rfaceScale, 1230 SkImageFilter* SkSpecularLightingImageFilter::Create(SkLight* light, SkScalar su rfaceScale,
1060 SkScalar ks, SkScalar shininess, SkImageFilter* input, const Cro pRect* cropRect) { 1231 SkScalar ks, SkScalar shininess, SkImageFilter* input, const Cro pRect* cropRect) {
1061 if (NULL == light) { 1232 if (NULL == light) {
1062 return NULL; 1233 return NULL;
1063 } 1234 }
1064 if (!SkScalarIsFinite(surfaceScale) || !SkScalarIsFinite(ks) || !SkScalarIsF inite(shininess)) { 1235 if (!SkScalarIsFinite(surfaceScale) || !SkScalarIsFinite(ks) || !SkScalarIsF inite(shininess)) {
1065 return NULL; 1236 return NULL;
1066 } 1237 }
1067 // According to the spec, ks can be any non-negative number : 1238 // According to the spec, ks can be any non-negative number :
1068 // http://www.w3.org/TR/SVG/filters.html#feSpecularLightingElement 1239 // http://www.w3.org/TR/SVG/filters.html#feSpecularLightingElement
1069 if (ks < 0) { 1240 if (ks < 0) {
1070 return NULL; 1241 return NULL;
1071 } 1242 }
1072 return SkNEW_ARGS(SkSpecularLightingImageFilter, 1243 return SkNEW_ARGS(SkSpecularLightingImageFilter,
1073 (light, surfaceScale, ks, shininess, input, cropRect)); 1244 (light, surfaceScale, ks, shininess, input, cropRect));
1074 } 1245 }
1075 1246
1076 SkSpecularLightingImageFilter::SkSpecularLightingImageFilter(SkLight* light, SkS calar surfaceScale, SkScalar ks, SkScalar shininess, SkImageFilter* input, const CropRect* cropRect) 1247 SkSpecularLightingImageFilter::SkSpecularLightingImageFilter(SkLight* light,
1077 : SkLightingImageFilter(light, surfaceScale, input, cropRect), 1248 SkScalar surfaceSca le,
1249 SkScalar ks,
1250 SkScalar shininess,
1251 SkImageFilter* inpu t,
1252 const CropRect* cro pRect)
1253 : INHERITED(light, surfaceScale, input, cropRect),
1078 fKS(ks), 1254 fKS(ks),
1079 fShininess(shininess) 1255 fShininess(shininess)
1080 { 1256 {
1081 } 1257 }
1082 1258
1083 SkFlattenable* SkSpecularLightingImageFilter::CreateProc(SkReadBuffer& buffer) { 1259 SkFlattenable* SkSpecularLightingImageFilter::CreateProc(SkReadBuffer& buffer) {
1084 SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 1); 1260 SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 1);
1085 SkAutoTUnref<SkLight> light(SkLight::UnflattenLight(buffer)); 1261 SkAutoTUnref<SkLight> light(SkLight::UnflattenLight(buffer));
1086 SkScalar surfaceScale = buffer.readScalar(); 1262 SkScalar surfaceScale = buffer.readScalar();
1087 SkScalar ks = buffer.readScalar(); 1263 SkScalar ks = buffer.readScalar();
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1129 return false; 1305 return false;
1130 } 1306 }
1131 1307
1132 SpecularLightingType lightingType(fKS, fShininess); 1308 SpecularLightingType lightingType(fKS, fShininess);
1133 offset->fX = bounds.left(); 1309 offset->fX = bounds.left();
1134 offset->fY = bounds.top(); 1310 offset->fY = bounds.top();
1135 bounds.offset(-srcOffset); 1311 bounds.offset(-srcOffset);
1136 SkAutoTUnref<SkLight> transformedLight(light()->transform(ctx.ctm())); 1312 SkAutoTUnref<SkLight> transformedLight(light()->transform(ctx.ctm()));
1137 switch (transformedLight->type()) { 1313 switch (transformedLight->type()) {
1138 case SkLight::kDistant_LightType: 1314 case SkLight::kDistant_LightType:
1139 lightBitmap<SpecularLightingType, SkDistantLight>(lightingType, tran sformedLight, src, dst, surfaceScale(), bounds); 1315 lightBitmap<SpecularLightingType, SkDistantLight>(lightingType,
1316 transformedLight,
1317 src,
1318 dst,
1319 surfaceScale(),
1320 bounds);
1140 break; 1321 break;
1141 case SkLight::kPoint_LightType: 1322 case SkLight::kPoint_LightType:
1142 lightBitmap<SpecularLightingType, SkPointLight>(lightingType, transf ormedLight, src, dst, surfaceScale(), bounds); 1323 lightBitmap<SpecularLightingType, SkPointLight>(lightingType,
1324 transformedLight,
1325 src,
1326 dst,
1327 surfaceScale(),
1328 bounds);
1143 break; 1329 break;
1144 case SkLight::kSpot_LightType: 1330 case SkLight::kSpot_LightType:
1145 lightBitmap<SpecularLightingType, SkSpotLight>(lightingType, transfo rmedLight, src, dst, surfaceScale(), bounds); 1331 lightBitmap<SpecularLightingType, SkSpotLight>(lightingType,
1332 transformedLight,
1333 src,
1334 dst,
1335 surfaceScale(),
1336 bounds);
1146 break; 1337 break;
1147 } 1338 }
1148 return true; 1339 return true;
1149 } 1340 }
1150 1341
1151 #ifndef SK_IGNORE_TO_STRING 1342 #ifndef SK_IGNORE_TO_STRING
1152 void SkSpecularLightingImageFilter::toString(SkString* str) const { 1343 void SkSpecularLightingImageFilter::toString(SkString* str) const {
1153 str->appendf("SkSpecularLightingImageFilter: ("); 1344 str->appendf("SkSpecularLightingImageFilter: (");
1154 str->appendf("kS: %f shininess: %f", fKS, fShininess); 1345 str->appendf("kS: %f shininess: %f", fKS, fShininess);
1155 str->append(")"); 1346 str->append(")");
1156 } 1347 }
1157 #endif 1348 #endif
1158 1349
1159 #if SK_SUPPORT_GPU 1350 #if SK_SUPPORT_GPU
1160 bool SkSpecularLightingImageFilter::asFragmentProcessor(GrFragmentProcessor** fp , 1351 GrFragmentProcessor* SkSpecularLightingImageFilter::getFragmentProcessor(
1161 GrTexture* texture, 1352 GrTexture* texture,
1162 const SkMatrix& matrix, 1353 const SkMatrix& matrix,
1163 const SkIRect&) const { 1354 const SkIRect&,
1164 if (fp) { 1355 BoundaryMode boundaryMo de) const {
1165 SkScalar scale = SkScalarMul(surfaceScale(), SkIntToScalar(255)); 1356 SkScalar scale = SkScalarMul(surfaceScale(), SkIntToScalar(255));
1166 *fp = GrSpecularLightingEffect::Create(texture, light(), scale, matrix, ks(), shininess()); 1357 return GrSpecularLightingEffect::Create(texture, light(), scale, matrix, ks( ), shininess(),
1167 } 1358 boundaryMode);
1168 return true;
1169 } 1359 }
1170 #endif 1360 #endif
1171 1361
1172 /////////////////////////////////////////////////////////////////////////////// 1362 ///////////////////////////////////////////////////////////////////////////////
1173 1363
1174 #if SK_SUPPORT_GPU 1364 #if SK_SUPPORT_GPU
1175 1365
1176 namespace { 1366 namespace {
1177 SkPoint3 random_point3(SkRandom* random) { 1367 SkPoint3 random_point3(SkRandom* random) {
1178 return SkPoint3(SkScalarToFloat(random->nextSScalar1()), 1368 return SkPoint3(SkScalarToFloat(random->nextSScalar1()),
(...skipping 16 matching lines...) Expand all
1195 random->nextUScalar1(), 1385 random->nextUScalar1(),
1196 random->nextUScalar1(), 1386 random->nextUScalar1(),
1197 random->nextU())); 1387 random->nextU()));
1198 } 1388 }
1199 default: 1389 default:
1200 SkFAIL("Unexpected value."); 1390 SkFAIL("Unexpected value.");
1201 return NULL; 1391 return NULL;
1202 } 1392 }
1203 } 1393 }
1204 1394
1395 SkString emitNormalFunc(BoundaryMode mode,
1396 const char* pointToNormalName,
1397 const char* sobelFuncName) {
1398 SkString result;
1399 switch (mode) {
1400 case kTopLeft_BoundaryMode:
1401 result.printf("\treturn %s(%s(0.0, 0.0, m[4], m[5], m[7], m[8], %g),\n"
1402 "\t %s(0.0, 0.0, m[4], m[7], m[5], m[8], %g),\n"
1403 "\t surfaceScale);\n",
1404 pointToNormalName, sobelFuncName, gTwoThirds,
1405 sobelFuncName, gTwoThirds);
1406 break;
1407 case kTop_BoundaryMode:
1408 result.printf("\treturn %s(%s(0.0, 0.0, m[3], m[5], m[6], m[8], %g),\n"
1409 "\t %s(0.0, 0.0, m[4], m[7], m[5], m[8], %g),\n"
1410 "\t surfaceScale);\n",
1411 pointToNormalName, sobelFuncName, gOneThird,
1412 sobelFuncName, gOneHalf);
1413 break;
1414 case kTopRight_BoundaryMode:
1415 result.printf("\treturn %s(%s( 0.0, 0.0, m[3], m[4], m[6], m[7], %g),\n "
1416 "\t %s(m[3], m[6], m[4], m[7], 0.0, 0.0, %g),\n "
1417 "\t surfaceScale);\n",
1418 pointToNormalName, sobelFuncName, gTwoThirds,
1419 sobelFuncName, gTwoThirds);
1420 break;
1421 case kLeft_BoundaryMode:
1422 result.printf("\treturn %s(%s(m[1], m[2], m[4], m[5], m[7], m[8], %g),\n "
1423 "\t %s( 0.0, 0.0, m[1], m[7], m[2], m[8], %g),\n "
1424 "\t surfaceScale);\n",
1425 pointToNormalName, sobelFuncName, gOneHalf,
1426 sobelFuncName, gOneThird);
1427 break;
1428 case kInterior_BoundaryMode:
1429 result.printf("\treturn %s(%s(m[0], m[2], m[3], m[5], m[6], m[8], %g),\n "
1430 "\t %s(m[0], m[6], m[1], m[7], m[2], m[8], %g),\n "
1431 "\t surfaceScale);\n",
1432 pointToNormalName, sobelFuncName, gOneQuarter,
1433 sobelFuncName, gOneQuarter);
1434 break;
1435 case kRight_BoundaryMode:
1436 result.printf("\treturn %s(%s(m[0], m[1], m[3], m[4], m[6], m[7], %g),\n "
1437 "\t %s(m[0], m[6], m[1], m[7], 0.0, 0.0, %g),\n "
1438 "\t surfaceScale);\n",
1439 pointToNormalName, sobelFuncName, gOneHalf,
1440 sobelFuncName, gOneThird);
1441 break;
1442 case kBottomLeft_BoundaryMode:
1443 result.printf("\treturn %s(%s(m[1], m[2], m[4], m[5], 0.0, 0.0, %g),\n "
1444 "\t %s( 0.0, 0.0, m[1], m[4], m[2], m[5], %g),\n "
1445 "\t surfaceScale);\n",
1446 pointToNormalName, sobelFuncName, gTwoThirds,
1447 sobelFuncName, gTwoThirds);
1448 break;
1449 case kBottom_BoundaryMode:
1450 result.printf("\treturn %s(%s(m[0], m[2], m[3], m[5], 0.0, 0.0, %g),\n "
1451 "\t %s(m[0], m[3], m[1], m[4], m[2], m[5], %g),\n "
1452 "\t surfaceScale);\n",
1453 pointToNormalName, sobelFuncName, gOneThird,
1454 sobelFuncName, gOneHalf);
1455 break;
1456 case kBottomRight_BoundaryMode:
1457 result.printf("\treturn %s(%s(m[0], m[1], m[3], m[4], 0.0, 0.0, %g),\n "
1458 "\t %s(m[0], m[3], m[1], m[4], 0.0, 0.0, %g),\n "
1459 "\t surfaceScale);\n",
1460 pointToNormalName, sobelFuncName, gTwoThirds,
1461 sobelFuncName, gTwoThirds);
1462 break;
1463 default:
1464 SkASSERT(false);
1465 break;
1466 }
1467 return result;
1468 }
1469
1205 } 1470 }
1206 1471
1207 class GrGLLightingEffect : public GrGLFragmentProcessor { 1472 class GrGLLightingEffect : public GrGLFragmentProcessor {
1208 public: 1473 public:
1209 GrGLLightingEffect(const GrProcessor&); 1474 GrGLLightingEffect(const GrProcessor&);
1210 virtual ~GrGLLightingEffect(); 1475 virtual ~GrGLLightingEffect();
1211 1476
1212 virtual void emitCode(GrGLFPBuilder*, 1477 void emitCode(GrGLFPBuilder*,
1213 const GrFragmentProcessor&, 1478 const GrFragmentProcessor&,
1214 const char* outputColor, 1479 const char* outputColor,
1215 const char* inputColor, 1480 const char* inputColor,
1216 const TransformedCoordsArray&, 1481 const TransformedCoordsArray&,
1217 const TextureSamplerArray&) override; 1482 const TextureSamplerArray&) override;
1218 1483
1219 static inline void GenKey(const GrProcessor&, const GrGLCaps&, GrProcessorKe yBuilder* b); 1484 static inline void GenKey(const GrProcessor&, const GrGLCaps&, GrProcessorKe yBuilder* b);
1220 1485
1221 /** 1486 /**
1222 * Subclasses of GrGLLightingEffect must call INHERITED::setData(); 1487 * Subclasses of GrGLLightingEffect must call INHERITED::setData();
1223 */ 1488 */
1224 void setData(const GrGLProgramDataManager&, const GrProcessor&) override; 1489 void setData(const GrGLProgramDataManager&, const GrProcessor&) override;
1225 1490
1226 protected: 1491 protected:
1227 virtual void emitLightFunc(GrGLFPBuilder*, SkString* funcName) = 0; 1492 virtual void emitLightFunc(GrGLFPBuilder*, SkString* funcName) = 0;
1228 1493
1229 private: 1494 private:
1230 typedef GrGLFragmentProcessor INHERITED; 1495 typedef GrGLFragmentProcessor INHERITED;
1231 1496
1232 UniformHandle fImageIncrementUni; 1497 UniformHandle fImageIncrementUni;
1233 UniformHandle fSurfaceScaleUni; 1498 UniformHandle fSurfaceScaleUni;
1234 GrGLLight* fLight; 1499 GrGLLight* fLight;
1500 BoundaryMode fBoundaryMode;
1235 }; 1501 };
1236 1502
1237 /////////////////////////////////////////////////////////////////////////////// 1503 ///////////////////////////////////////////////////////////////////////////////
1238 1504
1239 class GrGLDiffuseLightingEffect : public GrGLLightingEffect { 1505 class GrGLDiffuseLightingEffect : public GrGLLightingEffect {
1240 public: 1506 public:
1241 GrGLDiffuseLightingEffect(const GrProcessor&); 1507 GrGLDiffuseLightingEffect(const GrProcessor&);
1242 void emitLightFunc(GrGLFPBuilder*, SkString* funcName) override; 1508 void emitLightFunc(GrGLFPBuilder*, SkString* funcName) override;
1243 void setData(const GrGLProgramDataManager&, const GrProcessor&) override; 1509 void setData(const GrGLProgramDataManager&, const GrProcessor&) override;
1244 1510
(...skipping 16 matching lines...) Expand all
1261 1527
1262 UniformHandle fKSUni; 1528 UniformHandle fKSUni;
1263 UniformHandle fShininessUni; 1529 UniformHandle fShininessUni;
1264 }; 1530 };
1265 1531
1266 /////////////////////////////////////////////////////////////////////////////// 1532 ///////////////////////////////////////////////////////////////////////////////
1267 1533
1268 GrLightingEffect::GrLightingEffect(GrTexture* texture, 1534 GrLightingEffect::GrLightingEffect(GrTexture* texture,
1269 const SkLight* light, 1535 const SkLight* light,
1270 SkScalar surfaceScale, 1536 SkScalar surfaceScale,
1271 const SkMatrix& matrix) 1537 const SkMatrix& matrix,
1538 BoundaryMode boundaryMode)
1272 : INHERITED(texture, GrCoordTransform::MakeDivByTextureWHMatrix(texture)) 1539 : INHERITED(texture, GrCoordTransform::MakeDivByTextureWHMatrix(texture))
1273 , fLight(light) 1540 , fLight(light)
1274 , fSurfaceScale(surfaceScale) 1541 , fSurfaceScale(surfaceScale)
1275 , fFilterMatrix(matrix) { 1542 , fFilterMatrix(matrix)
1543 , fBoundaryMode(boundaryMode) {
1276 fLight->ref(); 1544 fLight->ref();
1277 if (light->requiresFragmentPosition()) { 1545 if (light->requiresFragmentPosition()) {
1278 this->setWillReadFragmentPosition(); 1546 this->setWillReadFragmentPosition();
1279 } 1547 }
1280 } 1548 }
1281 1549
1282 GrLightingEffect::~GrLightingEffect() { 1550 GrLightingEffect::~GrLightingEffect() {
1283 fLight->unref(); 1551 fLight->unref();
1284 } 1552 }
1285 1553
1286 bool GrLightingEffect::onIsEqual(const GrFragmentProcessor& sBase) const { 1554 bool GrLightingEffect::onIsEqual(const GrFragmentProcessor& sBase) const {
1287 const GrLightingEffect& s = sBase.cast<GrLightingEffect>(); 1555 const GrLightingEffect& s = sBase.cast<GrLightingEffect>();
1288 return fLight->isEqual(*s.fLight) && 1556 return fLight->isEqual(*s.fLight) &&
1289 fSurfaceScale == s.fSurfaceScale; 1557 fSurfaceScale == s.fSurfaceScale &&
1558 fBoundaryMode == s.fBoundaryMode;
1290 } 1559 }
1291 1560
1292 /////////////////////////////////////////////////////////////////////////////// 1561 ///////////////////////////////////////////////////////////////////////////////
1293 1562
1294 GrDiffuseLightingEffect::GrDiffuseLightingEffect(GrTexture* texture, 1563 GrDiffuseLightingEffect::GrDiffuseLightingEffect(GrTexture* texture,
1295 const SkLight* light, 1564 const SkLight* light,
1296 SkScalar surfaceScale, 1565 SkScalar surfaceScale,
1297 const SkMatrix& matrix, 1566 const SkMatrix& matrix,
1298 SkScalar kd) 1567 SkScalar kd,
1299 : INHERITED(texture, light, surfaceScale, matrix), fKD(kd) { 1568 BoundaryMode boundaryMode)
1569 : INHERITED(texture, light, surfaceScale, matrix, boundaryMode), fKD(kd) {
1300 this->initClassID<GrDiffuseLightingEffect>(); 1570 this->initClassID<GrDiffuseLightingEffect>();
1301 } 1571 }
1302 1572
1303 bool GrDiffuseLightingEffect::onIsEqual(const GrFragmentProcessor& sBase) const { 1573 bool GrDiffuseLightingEffect::onIsEqual(const GrFragmentProcessor& sBase) const {
1304 const GrDiffuseLightingEffect& s = sBase.cast<GrDiffuseLightingEffect>(); 1574 const GrDiffuseLightingEffect& s = sBase.cast<GrDiffuseLightingEffect>();
1305 return INHERITED::onIsEqual(sBase) && 1575 return INHERITED::onIsEqual(sBase) &&
1306 this->kd() == s.kd(); 1576 this->kd() == s.kd();
1307 } 1577 }
1308 1578
1309 void GrDiffuseLightingEffect::getGLProcessorKey(const GrGLCaps& caps, 1579 void GrDiffuseLightingEffect::getGLProcessorKey(const GrGLCaps& caps,
(...skipping 11 matching lines...) Expand all
1321 GrContext* context, 1591 GrContext* context,
1322 const GrDrawTargetCaps&, 1592 const GrDrawTargetCaps&,
1323 GrTexture* textures[]) { 1593 GrTexture* textures[]) {
1324 SkScalar surfaceScale = random->nextSScalar1(); 1594 SkScalar surfaceScale = random->nextSScalar1();
1325 SkScalar kd = random->nextUScalar1(); 1595 SkScalar kd = random->nextUScalar1();
1326 SkAutoTUnref<SkLight> light(create_random_light(random)); 1596 SkAutoTUnref<SkLight> light(create_random_light(random));
1327 SkMatrix matrix; 1597 SkMatrix matrix;
1328 for (int i = 0; i < 9; i++) { 1598 for (int i = 0; i < 9; i++) {
1329 matrix[i] = random->nextUScalar1(); 1599 matrix[i] = random->nextUScalar1();
1330 } 1600 }
1601 BoundaryMode mode = static_cast<BoundaryMode>(random->nextU() % kBoundaryMod eCount);
1331 return GrDiffuseLightingEffect::Create(textures[GrProcessorUnitTest::kAlphaT extureIdx], 1602 return GrDiffuseLightingEffect::Create(textures[GrProcessorUnitTest::kAlphaT extureIdx],
1332 light, surfaceScale, matrix, kd); 1603 light, surfaceScale, matrix, kd, mode );
1333 } 1604 }
1334 1605
1335 1606
1336 /////////////////////////////////////////////////////////////////////////////// 1607 ///////////////////////////////////////////////////////////////////////////////
1337 1608
1338 GrGLLightingEffect::GrGLLightingEffect(const GrProcessor& fp) { 1609 GrGLLightingEffect::GrGLLightingEffect(const GrProcessor& fp) {
1339 const GrLightingEffect& m = fp.cast<GrLightingEffect>(); 1610 const GrLightingEffect& m = fp.cast<GrLightingEffect>();
1340 fLight = m.light()->createGLLight(); 1611 fLight = m.light()->createGLLight();
1612 fBoundaryMode = m.boundaryMode();
1341 } 1613 }
1342 1614
1343 GrGLLightingEffect::~GrGLLightingEffect() { 1615 GrGLLightingEffect::~GrGLLightingEffect() {
1344 delete fLight; 1616 delete fLight;
1345 } 1617 }
1346 1618
1347 void GrGLLightingEffect::emitCode(GrGLFPBuilder* builder, 1619 void GrGLLightingEffect::emitCode(GrGLFPBuilder* builder,
1348 const GrFragmentProcessor&, 1620 const GrFragmentProcessor&,
1349 const char* outputColor, 1621 const char* outputColor,
1350 const char* inputColor, 1622 const char* inputColor,
(...skipping 30 matching lines...) Expand all
1381 static const GrGLShaderVar gPointToNormalArgs[] = { 1653 static const GrGLShaderVar gPointToNormalArgs[] = {
1382 GrGLShaderVar("x", kFloat_GrSLType), 1654 GrGLShaderVar("x", kFloat_GrSLType),
1383 GrGLShaderVar("y", kFloat_GrSLType), 1655 GrGLShaderVar("y", kFloat_GrSLType),
1384 GrGLShaderVar("scale", kFloat_GrSLType), 1656 GrGLShaderVar("scale", kFloat_GrSLType),
1385 }; 1657 };
1386 SkString pointToNormalName; 1658 SkString pointToNormalName;
1387 fsBuilder->emitFunction(kVec3f_GrSLType, 1659 fsBuilder->emitFunction(kVec3f_GrSLType,
1388 "pointToNormal", 1660 "pointToNormal",
1389 SK_ARRAY_COUNT(gPointToNormalArgs), 1661 SK_ARRAY_COUNT(gPointToNormalArgs),
1390 gPointToNormalArgs, 1662 gPointToNormalArgs,
1391 "\treturn normalize(vec3(-x * scale, y * scale, 1)); \n", 1663 "\treturn normalize(vec3(-x * scale, -y * scale, 1)) ;\n",
1392 &pointToNormalName); 1664 &pointToNormalName);
1393 1665
1394 static const GrGLShaderVar gInteriorNormalArgs[] = { 1666 static const GrGLShaderVar gInteriorNormalArgs[] = {
1395 GrGLShaderVar("m", kFloat_GrSLType, 9), 1667 GrGLShaderVar("m", kFloat_GrSLType, 9),
1396 GrGLShaderVar("surfaceScale", kFloat_GrSLType), 1668 GrGLShaderVar("surfaceScale", kFloat_GrSLType),
1397 }; 1669 };
1398 SkString interiorNormalBody; 1670 SkString normalBody = emitNormalFunc(fBoundaryMode,
1399 interiorNormalBody.appendf("\treturn %s(%s(m[0], m[2], m[3], m[5], m[6], m[8 ], 0.25),\n" 1671 pointToNormalName.c_str(),
1400 "\t %s(m[0], m[6], m[1], m[7], m[2], m[8], 0.25),\n" 1672 sobelFuncName.c_str());
1401 "\t surfaceScale);\n", 1673 SkString normalName;
1402 pointToNormalName.c_str(),
1403 sobelFuncName.c_str(),
1404 sobelFuncName.c_str());
1405 SkString interiorNormalName;
1406 fsBuilder->emitFunction(kVec3f_GrSLType, 1674 fsBuilder->emitFunction(kVec3f_GrSLType,
1407 "interiorNormal", 1675 "normal",
1408 SK_ARRAY_COUNT(gInteriorNormalArgs), 1676 SK_ARRAY_COUNT(gInteriorNormalArgs),
1409 gInteriorNormalArgs, 1677 gInteriorNormalArgs,
1410 interiorNormalBody.c_str(), 1678 normalBody.c_str(),
1411 &interiorNormalName); 1679 &normalName);
1412 1680
1413 fsBuilder->codeAppendf("\t\tvec2 coord = %s;\n", coords2D.c_str()); 1681 fsBuilder->codeAppendf("\t\tvec2 coord = %s;\n", coords2D.c_str());
1414 fsBuilder->codeAppend("\t\tfloat m[9];\n"); 1682 fsBuilder->codeAppend("\t\tfloat m[9];\n");
1415 1683
1416 const char* imgInc = builder->getUniformCStr(fImageIncrementUni); 1684 const char* imgInc = builder->getUniformCStr(fImageIncrementUni);
1417 const char* surfScale = builder->getUniformCStr(fSurfaceScaleUni); 1685 const char* surfScale = builder->getUniformCStr(fSurfaceScaleUni);
1418 1686
1419 int index = 0; 1687 int index = 0;
1420 for (int dy = -1; dy <= 1; dy++) { 1688 for (int dy = 1; dy >= -1; dy--) {
1421 for (int dx = -1; dx <= 1; dx++) { 1689 for (int dx = -1; dx <= 1; dx++) {
1422 SkString texCoords; 1690 SkString texCoords;
1423 texCoords.appendf("coord + vec2(%d, %d) * %s", dx, dy, imgInc); 1691 texCoords.appendf("coord + vec2(%d, %d) * %s", dx, dy, imgInc);
1424 fsBuilder->codeAppendf("\t\tm[%d] = ", index++); 1692 fsBuilder->codeAppendf("\t\tm[%d] = ", index++);
1425 fsBuilder->appendTextureLookup(samplers[0], texCoords.c_str()); 1693 fsBuilder->appendTextureLookup(samplers[0], texCoords.c_str());
1426 fsBuilder->codeAppend(".a;\n"); 1694 fsBuilder->codeAppend(".a;\n");
1427 } 1695 }
1428 } 1696 }
1429 fsBuilder->codeAppend("\t\tvec3 surfaceToLight = "); 1697 fsBuilder->codeAppend("\t\tvec3 surfaceToLight = ");
1430 SkString arg; 1698 SkString arg;
1431 arg.appendf("%s * m[4]", surfScale); 1699 arg.appendf("%s * m[4]", surfScale);
1432 fLight->emitSurfaceToLight(builder, arg.c_str()); 1700 fLight->emitSurfaceToLight(builder, arg.c_str());
1433 fsBuilder->codeAppend(";\n"); 1701 fsBuilder->codeAppend(";\n");
1434 fsBuilder->codeAppendf("\t\t%s = %s(%s(m, %s), surfaceToLight, ", 1702 fsBuilder->codeAppendf("\t\t%s = %s(%s(m, %s), surfaceToLight, ",
1435 outputColor, lightFunc.c_str(), interiorNormalName.c_ str(), surfScale); 1703 outputColor, lightFunc.c_str(), normalName.c_str(), s urfScale);
1436 fLight->emitLightColor(builder, "surfaceToLight"); 1704 fLight->emitLightColor(builder, "surfaceToLight");
1437 fsBuilder->codeAppend(");\n"); 1705 fsBuilder->codeAppend(");\n");
1438 SkString modulate; 1706 SkString modulate;
1439 GrGLSLMulVarBy4f(&modulate, outputColor, inputColor); 1707 GrGLSLMulVarBy4f(&modulate, outputColor, inputColor);
1440 fsBuilder->codeAppend(modulate.c_str()); 1708 fsBuilder->codeAppend(modulate.c_str());
1441 } 1709 }
1442 1710
1443 void GrGLLightingEffect::GenKey(const GrProcessor& proc, 1711 void GrGLLightingEffect::GenKey(const GrProcessor& proc,
1444 const GrGLCaps& caps, GrProcessorKeyBuilder* b) { 1712 const GrGLCaps& caps, GrProcessorKeyBuilder* b) {
1445 b->add32(proc.cast<GrLightingEffect>().light()->type()); 1713 const GrLightingEffect& lighting = proc.cast<GrLightingEffect>();
1714 b->add32(lighting.boundaryMode() << 2 | lighting.light()->type());
1446 } 1715 }
1447 1716
1448 void GrGLLightingEffect::setData(const GrGLProgramDataManager& pdman, 1717 void GrGLLightingEffect::setData(const GrGLProgramDataManager& pdman,
1449 const GrProcessor& proc) { 1718 const GrProcessor& proc) {
1450 const GrLightingEffect& lighting = proc.cast<GrLightingEffect>(); 1719 const GrLightingEffect& lighting = proc.cast<GrLightingEffect>();
1451 GrTexture* texture = lighting.texture(0); 1720 GrTexture* texture = lighting.texture(0);
1452 float ySign = texture->origin() == kTopLeft_GrSurfaceOrigin ? -1.0f : 1.0f; 1721 float ySign = texture->origin() == kTopLeft_GrSurfaceOrigin ? -1.0f : 1.0f;
1453 pdman.set2f(fImageIncrementUni, 1.0f / texture->width(), ySign / texture->he ight()); 1722 pdman.set2f(fImageIncrementUni, 1.0f / texture->width(), ySign / texture->he ight());
1454 pdman.set1f(fSurfaceScaleUni, lighting.surfaceScale()); 1723 pdman.set1f(fSurfaceScaleUni, lighting.surfaceScale());
1455 SkAutoTUnref<SkLight> transformedLight(lighting.light()->transform(lighting. filterMatrix())); 1724 SkAutoTUnref<SkLight> transformedLight(lighting.light()->transform(lighting. filterMatrix()));
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1493 pdman.set1f(fKDUni, diffuse.kd()); 1762 pdman.set1f(fKDUni, diffuse.kd());
1494 } 1763 }
1495 1764
1496 /////////////////////////////////////////////////////////////////////////////// 1765 ///////////////////////////////////////////////////////////////////////////////
1497 1766
1498 GrSpecularLightingEffect::GrSpecularLightingEffect(GrTexture* texture, 1767 GrSpecularLightingEffect::GrSpecularLightingEffect(GrTexture* texture,
1499 const SkLight* light, 1768 const SkLight* light,
1500 SkScalar surfaceScale, 1769 SkScalar surfaceScale,
1501 const SkMatrix& matrix, 1770 const SkMatrix& matrix,
1502 SkScalar ks, 1771 SkScalar ks,
1503 SkScalar shininess) 1772 SkScalar shininess,
1504 : INHERITED(texture, light, surfaceScale, matrix), 1773 BoundaryMode boundaryMode)
1774 : INHERITED(texture, light, surfaceScale, matrix, boundaryMode),
1505 fKS(ks), 1775 fKS(ks),
1506 fShininess(shininess) { 1776 fShininess(shininess) {
1507 this->initClassID<GrSpecularLightingEffect>(); 1777 this->initClassID<GrSpecularLightingEffect>();
1508 } 1778 }
1509 1779
1510 bool GrSpecularLightingEffect::onIsEqual(const GrFragmentProcessor& sBase) const { 1780 bool GrSpecularLightingEffect::onIsEqual(const GrFragmentProcessor& sBase) const {
1511 const GrSpecularLightingEffect& s = sBase.cast<GrSpecularLightingEffect>(); 1781 const GrSpecularLightingEffect& s = sBase.cast<GrSpecularLightingEffect>();
1512 return INHERITED::onIsEqual(sBase) && 1782 return INHERITED::onIsEqual(sBase) &&
1513 this->ks() == s.ks() && 1783 this->ks() == s.ks() &&
1514 this->shininess() == s.shininess(); 1784 this->shininess() == s.shininess();
(...skipping 15 matching lines...) Expand all
1530 const GrDrawTargetCaps &, 1800 const GrDrawTargetCaps &,
1531 GrTexture* textures[]) { 1801 GrTexture* textures[]) {
1532 SkScalar surfaceScale = random->nextSScalar1(); 1802 SkScalar surfaceScale = random->nextSScalar1();
1533 SkScalar ks = random->nextUScalar1(); 1803 SkScalar ks = random->nextUScalar1();
1534 SkScalar shininess = random->nextUScalar1(); 1804 SkScalar shininess = random->nextUScalar1();
1535 SkAutoTUnref<SkLight> light(create_random_light(random)); 1805 SkAutoTUnref<SkLight> light(create_random_light(random));
1536 SkMatrix matrix; 1806 SkMatrix matrix;
1537 for (int i = 0; i < 9; i++) { 1807 for (int i = 0; i < 9; i++) {
1538 matrix[i] = random->nextUScalar1(); 1808 matrix[i] = random->nextUScalar1();
1539 } 1809 }
1810 BoundaryMode mode = static_cast<BoundaryMode>(random->nextU() % kBoundaryMod eCount);
1540 return GrSpecularLightingEffect::Create(textures[GrProcessorUnitTest::kAlpha TextureIdx], 1811 return GrSpecularLightingEffect::Create(textures[GrProcessorUnitTest::kAlpha TextureIdx],
1541 light, surfaceScale, matrix, ks, shi niness); 1812 light, surfaceScale, matrix, ks, shi niness, mode);
1542 } 1813 }
1543 1814
1544 /////////////////////////////////////////////////////////////////////////////// 1815 ///////////////////////////////////////////////////////////////////////////////
1545 1816
1546 GrGLSpecularLightingEffect::GrGLSpecularLightingEffect(const GrProcessor& proc) 1817 GrGLSpecularLightingEffect::GrGLSpecularLightingEffect(const GrProcessor& proc)
1547 : INHERITED(proc) { 1818 : INHERITED(proc) {
1548 } 1819 }
1549 1820
1550 void GrGLSpecularLightingEffect::emitLightFunc(GrGLFPBuilder* builder, SkString* funcName) { 1821 void GrGLSpecularLightingEffect::emitLightFunc(GrGLFPBuilder* builder, SkString* funcName) {
1551 const char* ks; 1822 const char* ks;
1552 const char* shininess; 1823 const char* shininess;
1553 1824
1554 fKSUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visibility, 1825 fKSUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visibility,
1555 kFloat_GrSLType, kDefault_GrSLPrecision, "KS", &ks); 1826 kFloat_GrSLType, kDefault_GrSLPrecision, "KS", &ks);
1556 fShininessUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visibility , 1827 fShininessUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visibility ,
1557 kFloat_GrSLType, kDefault_GrSLPrecision, "Shininess", &shininess); 1828 kFloat_GrSLType,
1829 kDefault_GrSLPrecision,
1830 "Shininess",
1831 &shininess);
1558 1832
1559 static const GrGLShaderVar gLightArgs[] = { 1833 static const GrGLShaderVar gLightArgs[] = {
1560 GrGLShaderVar("normal", kVec3f_GrSLType), 1834 GrGLShaderVar("normal", kVec3f_GrSLType),
1561 GrGLShaderVar("surfaceToLight", kVec3f_GrSLType), 1835 GrGLShaderVar("surfaceToLight", kVec3f_GrSLType),
1562 GrGLShaderVar("lightColor", kVec3f_GrSLType) 1836 GrGLShaderVar("lightColor", kVec3f_GrSLType)
1563 }; 1837 };
1564 SkString lightBody; 1838 SkString lightBody;
1565 lightBody.appendf("\tvec3 halfDir = vec3(normalize(surfaceToLight + vec3(0, 0, 1)));\n"); 1839 lightBody.appendf("\tvec3 halfDir = vec3(normalize(surfaceToLight + vec3(0, 0, 1)));\n");
1566 lightBody.appendf("\tfloat colorScale = %s * pow(dot(normal, halfDir), %s);\ n", ks, shininess); 1840 lightBody.appendf("\tfloat colorScale = %s * pow(dot(normal, halfDir), %s);\ n", ks, shininess);
1567 lightBody.appendf("\tvec3 color = lightColor * clamp(colorScale, 0.0, 1.0);\ n"); 1841 lightBody.appendf("\tvec3 color = lightColor * clamp(colorScale, 0.0, 1.0);\ n");
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
1712 1986
1713 fsBuilder->codeAppendf("%s(%s)", fLightColorFunc.c_str(), surfaceToLight); 1987 fsBuilder->codeAppendf("%s(%s)", fLightColorFunc.c_str(), surfaceToLight);
1714 } 1988 }
1715 1989
1716 #endif 1990 #endif
1717 1991
1718 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingImageFilter) 1992 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingImageFilter)
1719 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDiffuseLightingImageFilter) 1993 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDiffuseLightingImageFilter)
1720 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSpecularLightingImageFilter) 1994 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSpecularLightingImageFilter)
1721 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END 1995 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END
OLDNEW
« no previous file with comments | « src/core/SkCanvas.cpp ('k') | src/effects/SkMagnifierImageFilter.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698