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 "SkDevice.h" | 9 #include "SkDevice.h" |
10 #include "SkReadBuffer.h" | 10 #include "SkReadBuffer.h" |
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 }; | 328 }; |
329 | 329 |
330 /////////////////////////////////////////////////////////////////////////////// | 330 /////////////////////////////////////////////////////////////////////////////// |
331 | 331 |
332 class GrDisplacementMapEffect : public GrFragmentProcessor { | 332 class GrDisplacementMapEffect : public GrFragmentProcessor { |
333 public: | 333 public: |
334 static GrFragmentProcessor* Create( | 334 static GrFragmentProcessor* Create( |
335 SkDisplacementMapEffect::ChannelSelectorType xChannelSelector, | 335 SkDisplacementMapEffect::ChannelSelectorType xChannelSelector, |
336 SkDisplacementMapEffect::ChannelSelectorType yChannelSelector, SkVec
tor scale, | 336 SkDisplacementMapEffect::ChannelSelectorType yChannelSelector, SkVec
tor scale, |
337 GrTexture* displacement, const SkMatrix& offsetMatrix, GrTexture* co
lor, | 337 GrTexture* displacement, const SkMatrix& offsetMatrix, GrTexture* co
lor, |
338 const SkISize& colorDimensions) { | 338 const SkISize& colorDimensions, GrRenderTarget* dst) { |
339 return new GrDisplacementMapEffect(xChannelSelector, yChannelSelector, s
cale, displacement, | 339 return new GrDisplacementMapEffect(xChannelSelector, yChannelSelector, |
340 offsetMatrix, color, colorDimensions)
; | 340 scale, displacement, offsetMatrix, co
lor, |
| 341 colorDimensions, dst); |
341 } | 342 } |
342 | 343 |
343 virtual ~GrDisplacementMapEffect(); | 344 virtual ~GrDisplacementMapEffect(); |
344 | 345 |
345 SkDisplacementMapEffect::ChannelSelectorType xChannelSelector() const | 346 SkDisplacementMapEffect::ChannelSelectorType xChannelSelector() const |
346 { return fXChannelSelector; } | 347 { return fXChannelSelector; } |
347 SkDisplacementMapEffect::ChannelSelectorType yChannelSelector() const | 348 SkDisplacementMapEffect::ChannelSelectorType yChannelSelector() const |
348 { return fYChannelSelector; } | 349 { return fYChannelSelector; } |
349 const SkVector& scale() const { return fScale; } | 350 const SkVector& scale() const { return fScale; } |
350 | 351 |
(...skipping 12 matching lines...) Expand all Loading... |
363 | 364 |
364 bool onIsEqual(const GrFragmentProcessor&) const override; | 365 bool onIsEqual(const GrFragmentProcessor&) const override; |
365 | 366 |
366 void onComputeInvariantOutput(GrInvariantOutput* inout) const override; | 367 void onComputeInvariantOutput(GrInvariantOutput* inout) const override; |
367 | 368 |
368 GrDisplacementMapEffect(SkDisplacementMapEffect::ChannelSelectorType xChanne
lSelector, | 369 GrDisplacementMapEffect(SkDisplacementMapEffect::ChannelSelectorType xChanne
lSelector, |
369 SkDisplacementMapEffect::ChannelSelectorType yChanne
lSelector, | 370 SkDisplacementMapEffect::ChannelSelectorType yChanne
lSelector, |
370 const SkVector& scale, | 371 const SkVector& scale, |
371 GrTexture* displacement, const SkMatrix& offsetMatri
x, | 372 GrTexture* displacement, const SkMatrix& offsetMatri
x, |
372 GrTexture* color, | 373 GrTexture* color, |
373 const SkISize& colorDimensions); | 374 const SkISize& colorDimensions, GrRenderTarget* dst)
; |
374 | 375 |
375 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; | 376 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; |
376 | 377 |
377 GrCoordTransform fDisplacementTransform; | 378 GrCoordTransform fDisplacementTransform; |
378 GrTextureAccess fDisplacementAccess; | 379 GrTextureAccess fDisplacementAccess; |
379 GrCoordTransform fColorTransform; | 380 GrCoordTransform fColorTransform; |
380 GrTextureDomain fDomain; | 381 GrTextureDomain fDomain; |
381 GrTextureAccess fColorAccess; | 382 GrTextureAccess fColorAccess; |
382 SkDisplacementMapEffect::ChannelSelectorType fXChannelSelector; | 383 SkDisplacementMapEffect::ChannelSelectorType fXChannelSelector; |
383 SkDisplacementMapEffect::ChannelSelectorType fYChannelSelector; | 384 SkDisplacementMapEffect::ChannelSelectorType fYChannelSelector; |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
437 offsetMatrix.preTranslate(SkIntToScalar(colorOffset.fX - displacementOffset.
fX), | 438 offsetMatrix.preTranslate(SkIntToScalar(colorOffset.fX - displacementOffset.
fX), |
438 SkIntToScalar(colorOffset.fY - displacementOffset.
fY)); | 439 SkIntToScalar(colorOffset.fY - displacementOffset.
fY)); |
439 | 440 |
440 paint.addColorFragmentProcessor( | 441 paint.addColorFragmentProcessor( |
441 GrDisplacementMapEffect::Create(fXChannelSelector, | 442 GrDisplacementMapEffect::Create(fXChannelSelector, |
442 fYChannelSelector, | 443 fYChannelSelector, |
443 scale, | 444 scale, |
444 displacement, | 445 displacement, |
445 offsetMatrix, | 446 offsetMatrix, |
446 color, | 447 color, |
447 colorBM.dimensions()))->unref(); | 448 colorBM.dimensions(), dst->asRenderTarge
t()))->unref(); |
448 SkIRect colorBounds = bounds; | 449 SkIRect colorBounds = bounds; |
449 colorBounds.offset(-colorOffset); | 450 colorBounds.offset(-colorOffset); |
450 SkMatrix matrix; | 451 SkMatrix matrix; |
451 matrix.setTranslate(-SkIntToScalar(colorBounds.x()), | 452 matrix.setTranslate(-SkIntToScalar(colorBounds.x()), |
452 -SkIntToScalar(colorBounds.y())); | 453 -SkIntToScalar(colorBounds.y())); |
453 | 454 |
454 SkAutoTUnref<GrDrawContext> drawContext(context->drawContext(dst->asRenderTa
rget())); | 455 SkAutoTUnref<GrDrawContext> drawContext(context->drawContext(dst->asRenderTa
rget())); |
455 if (!drawContext) { | 456 if (!drawContext) { |
456 return false; | 457 return false; |
457 } | 458 } |
458 | 459 |
459 drawContext->drawRect(GrClip::WideOpen(), paint, matrix, SkRect::Make(colorB
ounds)); | 460 drawContext->drawRect(GrClip::WideOpen(), paint, matrix, SkRect::Make(colorB
ounds)); |
460 offset->fX = bounds.left(); | 461 offset->fX = bounds.left(); |
461 offset->fY = bounds.top(); | 462 offset->fY = bounds.top(); |
462 WrapTexture(dst, bounds.width(), bounds.height(), result); | 463 WrapTexture(dst, bounds.width(), bounds.height(), result); |
463 return true; | 464 return true; |
464 } | 465 } |
465 | 466 |
466 /////////////////////////////////////////////////////////////////////////////// | 467 /////////////////////////////////////////////////////////////////////////////// |
467 | 468 |
468 GrDisplacementMapEffect::GrDisplacementMapEffect( | 469 GrDisplacementMapEffect::GrDisplacementMapEffect( |
469 SkDisplacementMapEffect::ChannelSelectorType xChann
elSelector, | 470 SkDisplacementMapEffect::ChannelSelectorType xChann
elSelector, |
470 SkDisplacementMapEffect::ChannelSelectorType yChann
elSelector, | 471 SkDisplacementMapEffect::ChannelSelectorType yChann
elSelector, |
471 const SkVector& scale, | 472 const SkVector& scale, |
472 GrTexture* displacement, | 473 GrTexture* displacement, |
473 const SkMatrix& offsetMatrix, | 474 const SkMatrix& offsetMatrix, |
474 GrTexture* color, | 475 GrTexture* color, |
475 const SkISize& colorDimensions) | 476 const SkISize& colorDimensions, GrRenderTarget* dst
) |
476 : fDisplacementTransform(kLocal_GrCoordSet, offsetMatrix, displacement, | 477 : fDisplacementTransform(kLocal_GrCoordSet, offsetMatrix, displacement, |
477 GrTextureParams::kNone_FilterMode) | 478 GrTextureParams::kNone_FilterMode) |
478 , fDisplacementAccess(displacement) | 479 , fDisplacementAccess(displacement, GrTextureParams::kNone_FilterMode,SkShad
er::kClamp_TileMode, dst) |
479 , fColorTransform(kLocal_GrCoordSet, color, GrTextureParams::kNone_FilterMod
e) | 480 , fColorTransform(kLocal_GrCoordSet, color, GrTextureParams::kNone_FilterMod
e) |
480 , fDomain(GrTextureDomain::MakeTexelDomain(color, SkIRect::MakeSize(colorDim
ensions)), | 481 , fDomain(GrTextureDomain::MakeTexelDomain(color, SkIRect::MakeSize(colorDim
ensions)), |
481 GrTextureDomain::kDecal_Mode) | 482 GrTextureDomain::kDecal_Mode) |
482 , fColorAccess(color) | 483 , fColorAccess(color, GrTextureParams::kNone_FilterMode,SkShader::kClamp_Til
eMode, dst) |
483 , fXChannelSelector(xChannelSelector) | 484 , fXChannelSelector(xChannelSelector) |
484 , fYChannelSelector(yChannelSelector) | 485 , fYChannelSelector(yChannelSelector) |
485 , fScale(scale) { | 486 , fScale(scale) { |
486 this->initClassID<GrDisplacementMapEffect>(); | 487 this->initClassID<GrDisplacementMapEffect>(); |
487 this->addCoordTransform(&fDisplacementTransform); | 488 this->addCoordTransform(&fDisplacementTransform); |
488 this->addTextureAccess(&fDisplacementAccess); | 489 this->addTextureAccess(&fDisplacementAccess); |
489 this->addCoordTransform(&fColorTransform); | 490 this->addCoordTransform(&fColorTransform); |
490 this->addTextureAccess(&fColorAccess); | 491 this->addTextureAccess(&fColorAccess); |
491 } | 492 } |
492 | 493 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
525 SkDisplacementMapEffect::ChannelSelectorType yChannelSelector = | 526 SkDisplacementMapEffect::ChannelSelectorType yChannelSelector = |
526 static_cast<SkDisplacementMapEffect::ChannelSelectorType>( | 527 static_cast<SkDisplacementMapEffect::ChannelSelectorType>( |
527 d->fRandom->nextRangeU(1, kMaxComponent)); | 528 d->fRandom->nextRangeU(1, kMaxComponent)); |
528 SkVector scale = SkVector::Make(d->fRandom->nextRangeScalar(0, 100.0f), | 529 SkVector scale = SkVector::Make(d->fRandom->nextRangeScalar(0, 100.0f), |
529 d->fRandom->nextRangeScalar(0, 100.0f)); | 530 d->fRandom->nextRangeScalar(0, 100.0f)); |
530 SkISize colorDimensions; | 531 SkISize colorDimensions; |
531 colorDimensions.fWidth = d->fRandom->nextRangeU(0, d->fTextures[texIdxColor]
->width()); | 532 colorDimensions.fWidth = d->fRandom->nextRangeU(0, d->fTextures[texIdxColor]
->width()); |
532 colorDimensions.fHeight = d->fRandom->nextRangeU(0, d->fTextures[texIdxColor
]->height()); | 533 colorDimensions.fHeight = d->fRandom->nextRangeU(0, d->fTextures[texIdxColor
]->height()); |
533 return GrDisplacementMapEffect::Create(xChannelSelector, yChannelSelector, s
cale, | 534 return GrDisplacementMapEffect::Create(xChannelSelector, yChannelSelector, s
cale, |
534 d->fTextures[texIdxDispl], SkMatrix::
I(), | 535 d->fTextures[texIdxDispl], SkMatrix::
I(), |
535 d->fTextures[texIdxColor], colorDimen
sions); | 536 d->fTextures[texIdxColor], colorDimen
sions, NULL); |
536 } | 537 } |
537 | 538 |
538 /////////////////////////////////////////////////////////////////////////////// | 539 /////////////////////////////////////////////////////////////////////////////// |
539 | 540 |
540 GrGLDisplacementMapEffect::GrGLDisplacementMapEffect(const GrProcessor& proc) | 541 GrGLDisplacementMapEffect::GrGLDisplacementMapEffect(const GrProcessor& proc) |
541 : fXChannelSelector(proc.cast<GrDisplacementMapEffect>().xChannelSelector()) | 542 : fXChannelSelector(proc.cast<GrDisplacementMapEffect>().xChannelSelector()) |
542 , fYChannelSelector(proc.cast<GrDisplacementMapEffect>().yChannelSelector())
{ | 543 , fYChannelSelector(proc.cast<GrDisplacementMapEffect>().yChannelSelector())
{ |
543 } | 544 } |
544 | 545 |
545 GrGLDisplacementMapEffect::~GrGLDisplacementMapEffect() { | 546 GrGLDisplacementMapEffect::~GrGLDisplacementMapEffect() { |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
628 const GrGLSLCaps&, GrProcessorKeyBuilder*
b) { | 629 const GrGLSLCaps&, GrProcessorKeyBuilder*
b) { |
629 const GrDisplacementMapEffect& displacementMap = proc.cast<GrDisplacementMap
Effect>(); | 630 const GrDisplacementMapEffect& displacementMap = proc.cast<GrDisplacementMap
Effect>(); |
630 | 631 |
631 uint32_t xKey = displacementMap.xChannelSelector(); | 632 uint32_t xKey = displacementMap.xChannelSelector(); |
632 uint32_t yKey = displacementMap.yChannelSelector() << kChannelSelectorKeyBit
s; | 633 uint32_t yKey = displacementMap.yChannelSelector() << kChannelSelectorKeyBit
s; |
633 | 634 |
634 b->add32(xKey | yKey); | 635 b->add32(xKey | yKey); |
635 } | 636 } |
636 #endif | 637 #endif |
637 | 638 |
OLD | NEW |