| 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 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 377 } | 377 } |
| 378 if (!bounds.intersect(displBounds)) { | 378 if (!bounds.intersect(displBounds)) { |
| 379 return false; | 379 return false; |
| 380 } | 380 } |
| 381 GrTexture* color = colorBM.getTexture(); | 381 GrTexture* color = colorBM.getTexture(); |
| 382 GrTexture* displacement = displacementBM.getTexture(); | 382 GrTexture* displacement = displacementBM.getTexture(); |
| 383 GrContext* context = color->getContext(); | 383 GrContext* context = color->getContext(); |
| 384 | 384 |
| 385 GrTextureDesc desc; | 385 GrTextureDesc desc; |
| 386 desc.fFlags = kRenderTarget_GrTextureFlagBit | kNoStencil_GrTextureFlagBit; | 386 desc.fFlags = kRenderTarget_GrTextureFlagBit | kNoStencil_GrTextureFlagBit; |
| 387 desc.fWidth = colorBM.width(); | 387 desc.fWidth = bounds.width(); |
| 388 desc.fHeight = colorBM.height(); | 388 desc.fHeight = bounds.height(); |
| 389 desc.fConfig = kSkia8888_GrPixelConfig; | 389 desc.fConfig = kSkia8888_GrPixelConfig; |
| 390 | 390 |
| 391 GrAutoScratchTexture ast(context, desc); | 391 GrAutoScratchTexture ast(context, desc); |
| 392 SkAutoTUnref<GrTexture> dst(ast.detach()); | 392 SkAutoTUnref<GrTexture> dst(ast.detach()); |
| 393 | 393 |
| 394 GrContext::AutoRenderTarget art(context, dst->asRenderTarget()); | 394 GrContext::AutoRenderTarget art(context, dst->asRenderTarget()); |
| 395 | 395 |
| 396 SkVector scale = SkVector::Make(fScale, fScale); | 396 SkVector scale = SkVector::Make(fScale, fScale); |
| 397 ctx.ctm().mapVectors(&scale, 1); | 397 ctx.ctm().mapVectors(&scale, 1); |
| 398 | 398 |
| 399 GrPaint paint; | 399 GrPaint paint; |
| 400 SkMatrix offsetMatrix = GrEffect::MakeDivByTextureWHMatrix(displacement); | 400 SkMatrix offsetMatrix = GrEffect::MakeDivByTextureWHMatrix(displacement); |
| 401 offsetMatrix.preTranslate(SkIntToScalar(colorOffset.fX - displacementOffset.
fX), | 401 offsetMatrix.preTranslate(SkIntToScalar(colorOffset.fX - displacementOffset.
fX), |
| 402 SkIntToScalar(colorOffset.fY - displacementOffset.
fY)); | 402 SkIntToScalar(colorOffset.fY - displacementOffset.
fY)); |
| 403 | 403 |
| 404 paint.addColorEffect( | 404 paint.addColorEffect( |
| 405 GrDisplacementMapEffect::Create(fXChannelSelector, | 405 GrDisplacementMapEffect::Create(fXChannelSelector, |
| 406 fYChannelSelector, | 406 fYChannelSelector, |
| 407 scale, | 407 scale, |
| 408 displacement, | 408 displacement, |
| 409 offsetMatrix, | 409 offsetMatrix, |
| 410 color))->unref(); | 410 color))->unref(); |
| 411 SkIRect colorBounds = bounds; | 411 SkIRect colorBounds = bounds; |
| 412 colorBounds.offset(-colorOffset); | 412 colorBounds.offset(-colorOffset); |
| 413 GrContext::AutoMatrix am; |
| 414 am.setIdentity(context); |
| 413 SkMatrix matrix; | 415 SkMatrix matrix; |
| 414 matrix.setTranslate(-SkIntToScalar(colorBounds.x()), | 416 matrix.setTranslate(-SkIntToScalar(colorBounds.x()), |
| 415 -SkIntToScalar(colorBounds.y())); | 417 -SkIntToScalar(colorBounds.y())); |
| 416 context->concatMatrix(matrix); | 418 context->concatMatrix(matrix); |
| 417 context->drawRect(paint, SkRect::Make(colorBounds)); | 419 context->drawRect(paint, SkRect::Make(colorBounds)); |
| 418 offset->fX = bounds.left(); | 420 offset->fX = bounds.left(); |
| 419 offset->fY = bounds.top(); | 421 offset->fY = bounds.top(); |
| 420 WrapTexture(dst, bounds.width(), bounds.height(), result); | 422 WrapTexture(dst, bounds.width(), bounds.height(), result); |
| 421 return true; | 423 return true; |
| 422 } | 424 } |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 602 const GrGLCaps&) { | 604 const GrGLCaps&) { |
| 603 const GrDisplacementMapEffect& displacementMap = | 605 const GrDisplacementMapEffect& displacementMap = |
| 604 drawEffect.castEffect<GrDisplacementMapEffect>(); | 606 drawEffect.castEffect<GrDisplacementMapEffect>(); |
| 605 | 607 |
| 606 EffectKey xKey = displacementMap.xChannelSelector(); | 608 EffectKey xKey = displacementMap.xChannelSelector(); |
| 607 EffectKey yKey = displacementMap.yChannelSelector() << kChannelSelectorKeyBi
ts; | 609 EffectKey yKey = displacementMap.yChannelSelector() << kChannelSelectorKeyBi
ts; |
| 608 | 610 |
| 609 return xKey | yKey; | 611 return xKey | yKey; |
| 610 } | 612 } |
| 611 #endif | 613 #endif |
| OLD | NEW |