| 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" |
| 11 #include "SkUnPreMultiply.h" | 11 #include "SkUnPreMultiply.h" |
| 12 #include "SkColorPriv.h" | 12 #include "SkColorPriv.h" |
| 13 #if SK_SUPPORT_GPU | 13 #if SK_SUPPORT_GPU |
| 14 #include "GrContext.h" | 14 #include "GrContext.h" |
| 15 #include "GrCoordTransform.h" | 15 #include "GrCoordTransform.h" |
| 16 #include "gl/GrGLEffect.h" | 16 #include "gl/GrGLEffect.h" |
| 17 #include "GrTBackendEffectFactory.h" | 17 #include "GrTBackendEffectFactory.h" |
| 18 #include "SkImageFilterUtils.h" | |
| 19 #endif | 18 #endif |
| 20 | 19 |
| 21 namespace { | 20 namespace { |
| 22 | 21 |
| 23 template<SkDisplacementMapEffect::ChannelSelectorType type> | 22 template<SkDisplacementMapEffect::ChannelSelectorType type> |
| 24 uint32_t getValue(SkColor, const SkUnPreMultiply::Scale*) { | 23 uint32_t getValue(SkColor, const SkUnPreMultiply::Scale*) { |
| 25 SkDEBUGFAIL("Unknown channel selector"); | 24 SkDEBUGFAIL("Unknown channel selector"); |
| 26 return 0; | 25 return 0; |
| 27 } | 26 } |
| 28 | 27 |
| (...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 342 GrTextureAccess fColorAccess; | 341 GrTextureAccess fColorAccess; |
| 343 SkDisplacementMapEffect::ChannelSelectorType fXChannelSelector; | 342 SkDisplacementMapEffect::ChannelSelectorType fXChannelSelector; |
| 344 SkDisplacementMapEffect::ChannelSelectorType fYChannelSelector; | 343 SkDisplacementMapEffect::ChannelSelectorType fYChannelSelector; |
| 345 SkVector fScale; | 344 SkVector fScale; |
| 346 | 345 |
| 347 typedef GrEffect INHERITED; | 346 typedef GrEffect INHERITED; |
| 348 }; | 347 }; |
| 349 | 348 |
| 350 bool SkDisplacementMapEffect::filterImageGPU(Proxy* proxy, const SkBitmap& src,
const SkMatrix& ctm, | 349 bool SkDisplacementMapEffect::filterImageGPU(Proxy* proxy, const SkBitmap& src,
const SkMatrix& ctm, |
| 351 SkBitmap* result, SkIPoint* offset)
const { | 350 SkBitmap* result, SkIPoint* offset)
const { |
| 352 SkBitmap colorBM; | 351 SkBitmap colorBM = src; |
| 353 SkIPoint colorOffset = SkIPoint::Make(0, 0); | 352 SkIPoint colorOffset = SkIPoint::Make(0, 0); |
| 354 if (!SkImageFilterUtils::GetInputResultGPU(getColorInput(), proxy, src, ctm,
&colorBM, | 353 if (getColorInput() && !getColorInput()->getInputResultGPU(proxy, src, ctm,
&colorBM, |
| 355 &colorOffset)) { | 354 &colorOffset)) { |
| 356 return false; | 355 return false; |
| 357 } | 356 } |
| 358 GrTexture* color = colorBM.getTexture(); | 357 GrTexture* color = colorBM.getTexture(); |
| 359 SkBitmap displacementBM; | 358 SkBitmap displacementBM = src; |
| 360 SkIPoint displacementOffset = SkIPoint::Make(0, 0); | 359 SkIPoint displacementOffset = SkIPoint::Make(0, 0); |
| 361 if (!SkImageFilterUtils::GetInputResultGPU(getDisplacementInput(), proxy, sr
c, ctm, | 360 if (getDisplacementInput() && |
| 362 &displacementBM, &displacementOff
set)) { | 361 !getDisplacementInput()->getInputResultGPU(proxy, src, ctm, &displacemen
tBM, |
| 362 &displacementOffset)) { |
| 363 return false; | 363 return false; |
| 364 } | 364 } |
| 365 GrTexture* displacement = displacementBM.getTexture(); | 365 GrTexture* displacement = displacementBM.getTexture(); |
| 366 GrContext* context = color->getContext(); | 366 GrContext* context = color->getContext(); |
| 367 | 367 |
| 368 GrTextureDesc desc; | 368 GrTextureDesc desc; |
| 369 desc.fFlags = kRenderTarget_GrTextureFlagBit | kNoStencil_GrTextureFlagBit; | 369 desc.fFlags = kRenderTarget_GrTextureFlagBit | kNoStencil_GrTextureFlagBit; |
| 370 desc.fWidth = colorBM.width(); | 370 desc.fWidth = colorBM.width(); |
| 371 desc.fHeight = colorBM.height(); | 371 desc.fHeight = colorBM.height(); |
| 372 desc.fConfig = kSkia8888_GrPixelConfig; | 372 desc.fConfig = kSkia8888_GrPixelConfig; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 408 color))->unref(); | 408 color))->unref(); |
| 409 SkIRect colorBounds = bounds; | 409 SkIRect colorBounds = bounds; |
| 410 colorBounds.offset(-colorOffset); | 410 colorBounds.offset(-colorOffset); |
| 411 SkMatrix matrix; | 411 SkMatrix matrix; |
| 412 matrix.setTranslate(-SkIntToScalar(colorBounds.x()), | 412 matrix.setTranslate(-SkIntToScalar(colorBounds.x()), |
| 413 -SkIntToScalar(colorBounds.y())); | 413 -SkIntToScalar(colorBounds.y())); |
| 414 context->concatMatrix(matrix); | 414 context->concatMatrix(matrix); |
| 415 context->drawRect(paint, SkRect::Make(colorBounds)); | 415 context->drawRect(paint, SkRect::Make(colorBounds)); |
| 416 offset->fX = bounds.left(); | 416 offset->fX = bounds.left(); |
| 417 offset->fY = bounds.top(); | 417 offset->fY = bounds.top(); |
| 418 return SkImageFilterUtils::WrapTexture(dst, bounds.width(), bounds.height(),
result); | 418 WrapTexture(dst, bounds.width(), bounds.height(), result); |
| 419 return true; |
| 419 } | 420 } |
| 420 | 421 |
| 421 /////////////////////////////////////////////////////////////////////////////// | 422 /////////////////////////////////////////////////////////////////////////////// |
| 422 | 423 |
| 423 GrDisplacementMapEffect::GrDisplacementMapEffect( | 424 GrDisplacementMapEffect::GrDisplacementMapEffect( |
| 424 SkDisplacementMapEffect::ChannelSelectorType xChann
elSelector, | 425 SkDisplacementMapEffect::ChannelSelectorType xChann
elSelector, |
| 425 SkDisplacementMapEffect::ChannelSelectorType yChann
elSelector, | 426 SkDisplacementMapEffect::ChannelSelectorType yChann
elSelector, |
| 426 const SkVector& scale, | 427 const SkVector& scale, |
| 427 GrTexture* displacement, | 428 GrTexture* displacement, |
| 428 const SkMatrix& offsetMatrix, | 429 const SkMatrix& offsetMatrix, |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 599 const GrGLCaps&) { | 600 const GrGLCaps&) { |
| 600 const GrDisplacementMapEffect& displacementMap = | 601 const GrDisplacementMapEffect& displacementMap = |
| 601 drawEffect.castEffect<GrDisplacementMapEffect>(); | 602 drawEffect.castEffect<GrDisplacementMapEffect>(); |
| 602 | 603 |
| 603 EffectKey xKey = displacementMap.xChannelSelector(); | 604 EffectKey xKey = displacementMap.xChannelSelector(); |
| 604 EffectKey yKey = displacementMap.yChannelSelector() << SkDisplacementMapEffe
ct::kKeyBits; | 605 EffectKey yKey = displacementMap.yChannelSelector() << SkDisplacementMapEffe
ct::kKeyBits; |
| 605 | 606 |
| 606 return xKey | yKey; | 607 return xKey | yKey; |
| 607 } | 608 } |
| 608 #endif | 609 #endif |
| OLD | NEW |