| 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 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 388 SkDisplacementMapEffect::ChannelSelectorType fYChannelSelector; | 388 SkDisplacementMapEffect::ChannelSelectorType fYChannelSelector; |
| 389 SkVector fScale; | 389 SkVector fScale; |
| 390 | 390 |
| 391 typedef GrFragmentProcessor INHERITED; | 391 typedef GrFragmentProcessor INHERITED; |
| 392 }; | 392 }; |
| 393 | 393 |
| 394 bool SkDisplacementMapEffect::filterImageGPU(Proxy* proxy, const SkBitmap& src,
const Context& ctx, | 394 bool SkDisplacementMapEffect::filterImageGPU(Proxy* proxy, const SkBitmap& src,
const Context& ctx, |
| 395 SkBitmap* result, SkIPoint* offset)
const { | 395 SkBitmap* result, SkIPoint* offset)
const { |
| 396 SkBitmap colorBM = src; | 396 SkBitmap colorBM = src; |
| 397 SkIPoint colorOffset = SkIPoint::Make(0, 0); | 397 SkIPoint colorOffset = SkIPoint::Make(0, 0); |
| 398 if (getColorInput() && !getColorInput()->getInputResultGPU(proxy, src, ctx,
&colorBM, | 398 if (this->getColorInput() && |
| 399 &colorOffset)) { | 399 !this->getColorInput()->getInputResultGPU(proxy, src, ctx, &colorBM, &co
lorOffset)) { |
| 400 return false; | 400 return false; |
| 401 } | 401 } |
| 402 SkBitmap displacementBM = src; | 402 SkBitmap displacementBM = src; |
| 403 SkIPoint displacementOffset = SkIPoint::Make(0, 0); | 403 SkIPoint displacementOffset = SkIPoint::Make(0, 0); |
| 404 if (getDisplacementInput() && | 404 if (this->getDisplacementInput() && |
| 405 !getDisplacementInput()->getInputResultGPU(proxy, src, ctx, &displacemen
tBM, | 405 !this->getDisplacementInput()->getInputResultGPU(proxy, src, ctx, &displ
acementBM, |
| 406 &displacementOffset)) { | 406 &displacementOffset)) { |
| 407 return false; | 407 return false; |
| 408 } | 408 } |
| 409 SkIRect bounds; | 409 SkIRect bounds; |
| 410 // Since GrDisplacementMapEffect does bounds checking on color pixel access,
we don't need to | 410 // Since GrDisplacementMapEffect does bounds checking on color pixel access,
we don't need to |
| 411 // pad the color bitmap to bounds here. | 411 // pad the color bitmap to bounds here. |
| 412 if (!this->applyCropRect(ctx, colorBM, colorOffset, &bounds)) { | 412 if (!this->applyCropRect(ctx, colorBM, colorOffset, &bounds)) { |
| 413 return false; | 413 return false; |
| 414 } | 414 } |
| 415 SkIRect displBounds; | 415 SkIRect displBounds; |
| 416 if (!this->applyCropRect(ctx, proxy, displacementBM, | 416 if (!this->applyCropRect(ctx, proxy, displacementBM, |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 452 displacement, | 452 displacement, |
| 453 offsetMatrix, | 453 offsetMatrix, |
| 454 color, | 454 color, |
| 455 colorBM.dimensions()))->unref(); | 455 colorBM.dimensions()))->unref(); |
| 456 SkIRect colorBounds = bounds; | 456 SkIRect colorBounds = bounds; |
| 457 colorBounds.offset(-colorOffset); | 457 colorBounds.offset(-colorOffset); |
| 458 SkMatrix matrix; | 458 SkMatrix matrix; |
| 459 matrix.setTranslate(-SkIntToScalar(colorBounds.x()), | 459 matrix.setTranslate(-SkIntToScalar(colorBounds.x()), |
| 460 -SkIntToScalar(colorBounds.y())); | 460 -SkIntToScalar(colorBounds.y())); |
| 461 | 461 |
| 462 GrDrawContext* drawContext = context->drawContext(); | 462 GrDrawContext* drawContext = context->drawContext(dst->asRenderTarget()); |
| 463 if (!drawContext) { | 463 if (!drawContext) { |
| 464 return false; | 464 return false; |
| 465 } | 465 } |
| 466 drawContext->uses(displacement); |
| 467 drawContext->uses(color); |
| 466 | 468 |
| 467 drawContext->drawRect(dst->asRenderTarget(), GrClip::WideOpen(), paint, matr
ix, | 469 drawContext->drawRect(dst->asRenderTarget(), GrClip::WideOpen(), paint, matr
ix, |
| 468 SkRect::Make(colorBounds)); | 470 SkRect::Make(colorBounds)); |
| 469 offset->fX = bounds.left(); | 471 offset->fX = bounds.left(); |
| 470 offset->fY = bounds.top(); | 472 offset->fY = bounds.top(); |
| 471 WrapTexture(dst, bounds.width(), bounds.height(), result); | 473 WrapTexture(dst, bounds.width(), bounds.height(), result); |
| 472 return true; | 474 return true; |
| 473 } | 475 } |
| 474 | 476 |
| 475 /////////////////////////////////////////////////////////////////////////////// | 477 /////////////////////////////////////////////////////////////////////////////// |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 644 const GrGLSLCaps&, GrProcessorKeyBuilder*
b) { | 646 const GrGLSLCaps&, GrProcessorKeyBuilder*
b) { |
| 645 const GrDisplacementMapEffect& displacementMap = proc.cast<GrDisplacementMap
Effect>(); | 647 const GrDisplacementMapEffect& displacementMap = proc.cast<GrDisplacementMap
Effect>(); |
| 646 | 648 |
| 647 uint32_t xKey = displacementMap.xChannelSelector(); | 649 uint32_t xKey = displacementMap.xChannelSelector(); |
| 648 uint32_t yKey = displacementMap.yChannelSelector() << kChannelSelectorKeyBit
s; | 650 uint32_t yKey = displacementMap.yChannelSelector() << kChannelSelectorKeyBit
s; |
| 649 | 651 |
| 650 b->add32(xKey | yKey); | 652 b->add32(xKey | yKey); |
| 651 } | 653 } |
| 652 #endif | 654 #endif |
| 653 | 655 |
| OLD | NEW |