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