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 "SkFlattenableBuffers.h" | 9 #include "SkFlattenableBuffers.h" |
10 #include "SkUnPreMultiply.h" | 10 #include "SkUnPreMultiply.h" |
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 | 268 |
269 GrTextureAccess fDisplacementAccess; | 269 GrTextureAccess fDisplacementAccess; |
270 GrTextureAccess fColorAccess; | 270 GrTextureAccess fColorAccess; |
271 SkDisplacementMapEffect::ChannelSelectorType fXChannelSelector; | 271 SkDisplacementMapEffect::ChannelSelectorType fXChannelSelector; |
272 SkDisplacementMapEffect::ChannelSelectorType fYChannelSelector; | 272 SkDisplacementMapEffect::ChannelSelectorType fYChannelSelector; |
273 SkScalar fScale; | 273 SkScalar fScale; |
274 | 274 |
275 typedef GrEffect INHERITED; | 275 typedef GrEffect INHERITED; |
276 }; | 276 }; |
277 | 277 |
278 bool SkDisplacementMapEffect::filterImageGPU(Proxy* proxy, const SkBitmap& src,
SkBitmap* result) { | 278 bool SkDisplacementMapEffect::filterImageGPU(Proxy* proxy, const SkBitmap& src,
SkBitmap* result, |
| 279 SkIPoint* offset) { |
279 SkBitmap colorBM; | 280 SkBitmap colorBM; |
280 if (!SkImageFilterUtils::GetInputResultGPU(getColorInput(), proxy, src, &col
orBM)) { | 281 SkIPoint colorOffset = SkIPoint::Make(0, 0); |
| 282 if (!SkImageFilterUtils::GetInputResultGPU(getColorInput(), proxy, src, &col
orBM, |
| 283 &colorOffset)) { |
281 return false; | 284 return false; |
282 } | 285 } |
283 GrTexture* color = colorBM.getTexture(); | 286 GrTexture* color = colorBM.getTexture(); |
284 SkBitmap displacementBM; | 287 SkBitmap displacementBM; |
285 if (!SkImageFilterUtils::GetInputResultGPU(getDisplacementInput(), proxy, sr
c, &displacementBM)) { | 288 SkIPoint displacementOffset = SkIPoint::Make(0, 0); |
| 289 if (!SkImageFilterUtils::GetInputResultGPU(getDisplacementInput(), proxy, sr
c, &displacementBM, |
| 290 &displacementOffset)) { |
286 return false; | 291 return false; |
287 } | 292 } |
288 GrTexture* displacement = displacementBM.getTexture(); | 293 GrTexture* displacement = displacementBM.getTexture(); |
289 GrContext* context = color->getContext(); | 294 GrContext* context = color->getContext(); |
290 | 295 |
291 GrTextureDesc desc; | 296 GrTextureDesc desc; |
292 desc.fFlags = kRenderTarget_GrTextureFlagBit | kNoStencil_GrTextureFlagBit; | 297 desc.fFlags = kRenderTarget_GrTextureFlagBit | kNoStencil_GrTextureFlagBit; |
293 desc.fWidth = src.width(); | 298 desc.fWidth = src.width(); |
294 desc.fHeight = src.height(); | 299 desc.fHeight = src.height(); |
295 desc.fConfig = kSkia8888_GrPixelConfig; | 300 desc.fConfig = kSkia8888_GrPixelConfig; |
296 | 301 |
297 GrAutoScratchTexture ast(context, desc); | 302 GrAutoScratchTexture ast(context, desc); |
298 SkAutoTUnref<GrTexture> dst(ast.detach()); | 303 SkAutoTUnref<GrTexture> dst(ast.detach()); |
299 | 304 |
300 GrContext::AutoRenderTarget art(context, dst->asRenderTarget()); | 305 GrContext::AutoRenderTarget art(context, dst->asRenderTarget()); |
301 | 306 |
302 GrPaint paint; | 307 GrPaint paint; |
303 paint.colorStage(0)->setEffect( | 308 paint.colorStage(0)->setEffect( |
304 GrDisplacementMapEffect::Create(fXChannelSelector, | 309 GrDisplacementMapEffect::Create(fXChannelSelector, |
305 fYChannelSelector, | 310 fYChannelSelector, |
306 fScale, | 311 fScale, |
307 displacement, | 312 displacement, |
308 color))->unref(); | 313 color))->unref(); |
309 SkRect srcRect; | 314 SkRect srcRect; |
310 src.getBounds(&srcRect); | 315 src.getBounds(&srcRect); |
311 context->drawRect(paint, srcRect); | 316 SkRect dstRect = srcRect; |
| 317 dstRect.offset(SkIntToScalar(colorOffset.fX), SkIntToScalar(colorOffset.fY))
; |
| 318 context->drawRectToRect(paint, srcRect, dstRect); |
312 return SkImageFilterUtils::WrapTexture(dst, src.width(), src.height(), resul
t); | 319 return SkImageFilterUtils::WrapTexture(dst, src.width(), src.height(), resul
t); |
313 } | 320 } |
314 | 321 |
315 /////////////////////////////////////////////////////////////////////////////// | 322 /////////////////////////////////////////////////////////////////////////////// |
316 | 323 |
317 GrDisplacementMapEffect::GrDisplacementMapEffect( | 324 GrDisplacementMapEffect::GrDisplacementMapEffect( |
318 SkDisplacementMapEffect::ChannelSelectorType xChann
elSelector, | 325 SkDisplacementMapEffect::ChannelSelectorType xChann
elSelector, |
319 SkDisplacementMapEffect::ChannelSelectorType yChann
elSelector, | 326 SkDisplacementMapEffect::ChannelSelectorType yChann
elSelector, |
320 SkScalar scale, | 327 SkScalar scale, |
321 GrTexture* displacement, | 328 GrTexture* displacement, |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
525 colorTex); | 532 colorTex); |
526 | 533 |
527 colorKey <<= GrGLEffectMatrix::kKeyBits; | 534 colorKey <<= GrGLEffectMatrix::kKeyBits; |
528 EffectKey xKey = displacementMap.xChannelSelector() << (2 * GrGLEffectMatrix
::kKeyBits); | 535 EffectKey xKey = displacementMap.xChannelSelector() << (2 * GrGLEffectMatrix
::kKeyBits); |
529 EffectKey yKey = displacementMap.yChannelSelector() << (2 * GrGLEffectMatrix
::kKeyBits + | 536 EffectKey yKey = displacementMap.yChannelSelector() << (2 * GrGLEffectMatrix
::kKeyBits + |
530 SkDisplacementMapEff
ect::kKeyBits); | 537 SkDisplacementMapEff
ect::kKeyBits); |
531 | 538 |
532 return xKey | yKey | displKey | colorKey; | 539 return xKey | yKey | displKey | colorKey; |
533 } | 540 } |
534 #endif | 541 #endif |
OLD | NEW |