| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
| 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 "SkDisplacementMapEffect.h" | 8 #include "SkDisplacementMapEffect.h" |
| 9 #include "SkReadBuffer.h" | 9 #include "SkReadBuffer.h" |
| 10 #include "SkWriteBuffer.h" | 10 #include "SkWriteBuffer.h" |
| (...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 321 GrTextureDomain::GLDomain fGLDomain; | 321 GrTextureDomain::GLDomain fGLDomain; |
| 322 | 322 |
| 323 typedef GrGLFragmentProcessor INHERITED; | 323 typedef GrGLFragmentProcessor INHERITED; |
| 324 }; | 324 }; |
| 325 | 325 |
| 326 /////////////////////////////////////////////////////////////////////////////// | 326 /////////////////////////////////////////////////////////////////////////////// |
| 327 | 327 |
| 328 class GrDisplacementMapEffect : public GrFragmentProcessor { | 328 class GrDisplacementMapEffect : public GrFragmentProcessor { |
| 329 public: | 329 public: |
| 330 static GrFragmentProcessor* Create( | 330 static GrFragmentProcessor* Create( |
| 331 GrProcessorDataManager* procDataManager, | |
| 332 SkDisplacementMapEffect::ChannelSelectorType xChannelSelector, | 331 SkDisplacementMapEffect::ChannelSelectorType xChannelSelector, |
| 333 SkDisplacementMapEffect::ChannelSelectorType yChannelSelector, SkVec
tor scale, | 332 SkDisplacementMapEffect::ChannelSelectorType yChannelSelector, SkVec
tor scale, |
| 334 GrTexture* displacement, const SkMatrix& offsetMatrix, GrTexture* co
lor, | 333 GrTexture* displacement, const SkMatrix& offsetMatrix, GrTexture* co
lor, |
| 335 const SkISize& colorDimensions) { | 334 const SkISize& colorDimensions) { |
| 336 return new GrDisplacementMapEffect(procDataManager, xChannelSelector, yC
hannelSelector, | 335 return new GrDisplacementMapEffect(xChannelSelector, yChannelSelector, s
cale, displacement, |
| 337 scale, displacement, offsetMatrix, co
lor, | 336 offsetMatrix, color, colorDimensions)
; |
| 338 colorDimensions); | |
| 339 } | 337 } |
| 340 | 338 |
| 341 virtual ~GrDisplacementMapEffect(); | 339 virtual ~GrDisplacementMapEffect(); |
| 342 | 340 |
| 343 SkDisplacementMapEffect::ChannelSelectorType xChannelSelector() const | 341 SkDisplacementMapEffect::ChannelSelectorType xChannelSelector() const |
| 344 { return fXChannelSelector; } | 342 { return fXChannelSelector; } |
| 345 SkDisplacementMapEffect::ChannelSelectorType yChannelSelector() const | 343 SkDisplacementMapEffect::ChannelSelectorType yChannelSelector() const |
| 346 { return fYChannelSelector; } | 344 { return fYChannelSelector; } |
| 347 const SkVector& scale() const { return fScale; } | 345 const SkVector& scale() const { return fScale; } |
| 348 | 346 |
| 349 const char* name() const override { return "DisplacementMap"; } | 347 const char* name() const override { return "DisplacementMap"; } |
| 350 const GrTextureDomain& domain() const { return fDomain; } | 348 const GrTextureDomain& domain() const { return fDomain; } |
| 351 | 349 |
| 352 private: | 350 private: |
| 353 GrGLFragmentProcessor* onCreateGLInstance() const override { | 351 GrGLFragmentProcessor* onCreateGLInstance() const override { |
| 354 return new GrGLDisplacementMapEffect(*this); | 352 return new GrGLDisplacementMapEffect(*this); |
| 355 } | 353 } |
| 356 | 354 |
| 357 virtual void onGetGLProcessorKey(const GrGLSLCaps& caps, | 355 virtual void onGetGLProcessorKey(const GrGLSLCaps& caps, |
| 358 GrProcessorKeyBuilder* b) const override { | 356 GrProcessorKeyBuilder* b) const override { |
| 359 GrGLDisplacementMapEffect::GenKey(*this, caps, b); | 357 GrGLDisplacementMapEffect::GenKey(*this, caps, b); |
| 360 } | 358 } |
| 361 | 359 |
| 362 bool onIsEqual(const GrFragmentProcessor&) const override; | 360 bool onIsEqual(const GrFragmentProcessor&) const override; |
| 363 | 361 |
| 364 void onComputeInvariantOutput(GrInvariantOutput* inout) const override; | 362 void onComputeInvariantOutput(GrInvariantOutput* inout) const override; |
| 365 | 363 |
| 366 GrDisplacementMapEffect(GrProcessorDataManager*, | 364 GrDisplacementMapEffect(SkDisplacementMapEffect::ChannelSelectorType xChanne
lSelector, |
| 367 SkDisplacementMapEffect::ChannelSelectorType xChanne
lSelector, | |
| 368 SkDisplacementMapEffect::ChannelSelectorType yChanne
lSelector, | 365 SkDisplacementMapEffect::ChannelSelectorType yChanne
lSelector, |
| 369 const SkVector& scale, | 366 const SkVector& scale, |
| 370 GrTexture* displacement, const SkMatrix& offsetMatri
x, | 367 GrTexture* displacement, const SkMatrix& offsetMatri
x, |
| 371 GrTexture* color, | 368 GrTexture* color, |
| 372 const SkISize& colorDimensions); | 369 const SkISize& colorDimensions); |
| 373 | 370 |
| 374 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; | 371 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; |
| 375 | 372 |
| 376 GrCoordTransform fDisplacementTransform; | 373 GrCoordTransform fDisplacementTransform; |
| 377 GrTextureAccess fDisplacementAccess; | 374 GrTextureAccess fDisplacementAccess; |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 432 | 429 |
| 433 SkVector scale = SkVector::Make(fScale, fScale); | 430 SkVector scale = SkVector::Make(fScale, fScale); |
| 434 ctx.ctm().mapVectors(&scale, 1); | 431 ctx.ctm().mapVectors(&scale, 1); |
| 435 | 432 |
| 436 GrPaint paint; | 433 GrPaint paint; |
| 437 SkMatrix offsetMatrix = GrCoordTransform::MakeDivByTextureWHMatrix(displacem
ent); | 434 SkMatrix offsetMatrix = GrCoordTransform::MakeDivByTextureWHMatrix(displacem
ent); |
| 438 offsetMatrix.preTranslate(SkIntToScalar(colorOffset.fX - displacementOffset.
fX), | 435 offsetMatrix.preTranslate(SkIntToScalar(colorOffset.fX - displacementOffset.
fX), |
| 439 SkIntToScalar(colorOffset.fY - displacementOffset.
fY)); | 436 SkIntToScalar(colorOffset.fY - displacementOffset.
fY)); |
| 440 | 437 |
| 441 paint.addColorFragmentProcessor( | 438 paint.addColorFragmentProcessor( |
| 442 GrDisplacementMapEffect::Create(paint.getProcessorDataManager(), | 439 GrDisplacementMapEffect::Create(fXChannelSelector, |
| 443 fXChannelSelector, | |
| 444 fYChannelSelector, | 440 fYChannelSelector, |
| 445 scale, | 441 scale, |
| 446 displacement, | 442 displacement, |
| 447 offsetMatrix, | 443 offsetMatrix, |
| 448 color, | 444 color, |
| 449 colorBM.dimensions()))->unref(); | 445 colorBM.dimensions()))->unref(); |
| 450 SkIRect colorBounds = bounds; | 446 SkIRect colorBounds = bounds; |
| 451 colorBounds.offset(-colorOffset); | 447 colorBounds.offset(-colorOffset); |
| 452 SkMatrix matrix; | 448 SkMatrix matrix; |
| 453 matrix.setTranslate(-SkIntToScalar(colorBounds.x()), | 449 matrix.setTranslate(-SkIntToScalar(colorBounds.x()), |
| 454 -SkIntToScalar(colorBounds.y())); | 450 -SkIntToScalar(colorBounds.y())); |
| 455 | 451 |
| 456 SkAutoTUnref<GrDrawContext> drawContext(context->drawContext()); | 452 SkAutoTUnref<GrDrawContext> drawContext(context->drawContext()); |
| 457 if (!drawContext) { | 453 if (!drawContext) { |
| 458 return false; | 454 return false; |
| 459 } | 455 } |
| 460 | 456 |
| 461 drawContext->drawRect(dst->asRenderTarget(), GrClip::WideOpen(), paint, matr
ix, | 457 drawContext->drawRect(dst->asRenderTarget(), GrClip::WideOpen(), paint, matr
ix, |
| 462 SkRect::Make(colorBounds)); | 458 SkRect::Make(colorBounds)); |
| 463 offset->fX = bounds.left(); | 459 offset->fX = bounds.left(); |
| 464 offset->fY = bounds.top(); | 460 offset->fY = bounds.top(); |
| 465 WrapTexture(dst, bounds.width(), bounds.height(), result); | 461 WrapTexture(dst, bounds.width(), bounds.height(), result); |
| 466 return true; | 462 return true; |
| 467 } | 463 } |
| 468 | 464 |
| 469 /////////////////////////////////////////////////////////////////////////////// | 465 /////////////////////////////////////////////////////////////////////////////// |
| 470 | 466 |
| 471 GrDisplacementMapEffect::GrDisplacementMapEffect( | 467 GrDisplacementMapEffect::GrDisplacementMapEffect( |
| 472 GrProcessorDataManager*, | |
| 473 SkDisplacementMapEffect::ChannelSelectorType xChann
elSelector, | 468 SkDisplacementMapEffect::ChannelSelectorType xChann
elSelector, |
| 474 SkDisplacementMapEffect::ChannelSelectorType yChann
elSelector, | 469 SkDisplacementMapEffect::ChannelSelectorType yChann
elSelector, |
| 475 const SkVector& scale, | 470 const SkVector& scale, |
| 476 GrTexture* displacement, | 471 GrTexture* displacement, |
| 477 const SkMatrix& offsetMatrix, | 472 const SkMatrix& offsetMatrix, |
| 478 GrTexture* color, | 473 GrTexture* color, |
| 479 const SkISize& colorDimensions) | 474 const SkISize& colorDimensions) |
| 480 : fDisplacementTransform(kLocal_GrCoordSet, offsetMatrix, displacement, | 475 : fDisplacementTransform(kLocal_GrCoordSet, offsetMatrix, displacement, |
| 481 GrTextureParams::kNone_FilterMode) | 476 GrTextureParams::kNone_FilterMode) |
| 482 , fDisplacementAccess(displacement) | 477 , fDisplacementAccess(displacement) |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 527 static_cast<SkDisplacementMapEffect::ChannelSelectorType>( | 522 static_cast<SkDisplacementMapEffect::ChannelSelectorType>( |
| 528 d->fRandom->nextRangeU(1, kMaxComponent)); | 523 d->fRandom->nextRangeU(1, kMaxComponent)); |
| 529 SkDisplacementMapEffect::ChannelSelectorType yChannelSelector = | 524 SkDisplacementMapEffect::ChannelSelectorType yChannelSelector = |
| 530 static_cast<SkDisplacementMapEffect::ChannelSelectorType>( | 525 static_cast<SkDisplacementMapEffect::ChannelSelectorType>( |
| 531 d->fRandom->nextRangeU(1, kMaxComponent)); | 526 d->fRandom->nextRangeU(1, kMaxComponent)); |
| 532 SkVector scale = SkVector::Make(d->fRandom->nextRangeScalar(0, 100.0f), | 527 SkVector scale = SkVector::Make(d->fRandom->nextRangeScalar(0, 100.0f), |
| 533 d->fRandom->nextRangeScalar(0, 100.0f)); | 528 d->fRandom->nextRangeScalar(0, 100.0f)); |
| 534 SkISize colorDimensions; | 529 SkISize colorDimensions; |
| 535 colorDimensions.fWidth = d->fRandom->nextRangeU(0, d->fTextures[texIdxColor]
->width()); | 530 colorDimensions.fWidth = d->fRandom->nextRangeU(0, d->fTextures[texIdxColor]
->width()); |
| 536 colorDimensions.fHeight = d->fRandom->nextRangeU(0, d->fTextures[texIdxColor
]->height()); | 531 colorDimensions.fHeight = d->fRandom->nextRangeU(0, d->fTextures[texIdxColor
]->height()); |
| 537 return GrDisplacementMapEffect::Create(d->fProcDataManager, | 532 return GrDisplacementMapEffect::Create(xChannelSelector, yChannelSelector, s
cale, |
| 538 xChannelSelector, yChannelSelector, s
cale, | |
| 539 d->fTextures[texIdxDispl], SkMatrix::
I(), | 533 d->fTextures[texIdxDispl], SkMatrix::
I(), |
| 540 d->fTextures[texIdxColor], colorDimen
sions); | 534 d->fTextures[texIdxColor], colorDimen
sions); |
| 541 } | 535 } |
| 542 | 536 |
| 543 /////////////////////////////////////////////////////////////////////////////// | 537 /////////////////////////////////////////////////////////////////////////////// |
| 544 | 538 |
| 545 GrGLDisplacementMapEffect::GrGLDisplacementMapEffect(const GrProcessor& proc) | 539 GrGLDisplacementMapEffect::GrGLDisplacementMapEffect(const GrProcessor& proc) |
| 546 : fXChannelSelector(proc.cast<GrDisplacementMapEffect>().xChannelSelector()) | 540 : fXChannelSelector(proc.cast<GrDisplacementMapEffect>().xChannelSelector()) |
| 547 , fYChannelSelector(proc.cast<GrDisplacementMapEffect>().yChannelSelector())
{ | 541 , fYChannelSelector(proc.cast<GrDisplacementMapEffect>().yChannelSelector())
{ |
| 548 } | 542 } |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 633 const GrGLSLCaps&, GrProcessorKeyBuilder*
b) { | 627 const GrGLSLCaps&, GrProcessorKeyBuilder*
b) { |
| 634 const GrDisplacementMapEffect& displacementMap = proc.cast<GrDisplacementMap
Effect>(); | 628 const GrDisplacementMapEffect& displacementMap = proc.cast<GrDisplacementMap
Effect>(); |
| 635 | 629 |
| 636 uint32_t xKey = displacementMap.xChannelSelector(); | 630 uint32_t xKey = displacementMap.xChannelSelector(); |
| 637 uint32_t yKey = displacementMap.yChannelSelector() << kChannelSelectorKeyBit
s; | 631 uint32_t yKey = displacementMap.yChannelSelector() << kChannelSelectorKeyBit
s; |
| 638 | 632 |
| 639 b->add32(xKey | yKey); | 633 b->add32(xKey | yKey); |
| 640 } | 634 } |
| 641 #endif | 635 #endif |
| 642 | 636 |
| OLD | NEW |