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

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

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