| 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 | 9 |
| 10 #include "SkBitmap.h" | 10 #include "SkBitmap.h" |
| (...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 #if SK_SUPPORT_GPU | 310 #if SK_SUPPORT_GPU |
| 311 if (source->isTextureBacked()) { | 311 if (source->isTextureBacked()) { |
| 312 GrContext* context = source->getContext(); | 312 GrContext* context = source->getContext(); |
| 313 | 313 |
| 314 sk_sp<GrTexture> colorTexture(color->asTextureRef(context)); | 314 sk_sp<GrTexture> colorTexture(color->asTextureRef(context)); |
| 315 sk_sp<GrTexture> displTexture(displ->asTextureRef(context)); | 315 sk_sp<GrTexture> displTexture(displ->asTextureRef(context)); |
| 316 if (!colorTexture || !displTexture) { | 316 if (!colorTexture || !displTexture) { |
| 317 return nullptr; | 317 return nullptr; |
| 318 } | 318 } |
| 319 | 319 |
| 320 GrSurfaceDesc desc; | |
| 321 desc.fFlags = kRenderTarget_GrSurfaceFlag; | |
| 322 desc.fWidth = bounds.width(); | |
| 323 desc.fHeight = bounds.height(); | |
| 324 desc.fConfig = kSkia8888_GrPixelConfig; | |
| 325 | |
| 326 sk_sp<GrTexture> dst(context->textureProvider()->createApproxTexture(des
c)); | |
| 327 if (!dst) { | |
| 328 return nullptr; | |
| 329 } | |
| 330 | |
| 331 GrPaint paint; | 320 GrPaint paint; |
| 332 SkMatrix offsetMatrix = GrCoordTransform::MakeDivByTextureWHMatrix(displ
Texture.get()); | 321 SkMatrix offsetMatrix = GrCoordTransform::MakeDivByTextureWHMatrix(displ
Texture.get()); |
| 333 offsetMatrix.preTranslate(SkIntToScalar(colorOffset.fX - displOffset.fX)
, | 322 offsetMatrix.preTranslate(SkIntToScalar(colorOffset.fX - displOffset.fX)
, |
| 334 SkIntToScalar(colorOffset.fY - displOffset.fY)
); | 323 SkIntToScalar(colorOffset.fY - displOffset.fY)
); |
| 335 | 324 |
| 336 paint.addColorFragmentProcessor( | 325 paint.addColorFragmentProcessor( |
| 337 GrDisplacementMapEffect::Create(fXChannelSelector, | 326 GrDisplacementMapEffect::Create(fXChannelSelector, |
| 338 fYChannelSelector, | 327 fYChannelSelector, |
| 339 scale, | 328 scale, |
| 340 displTexture.get(), | 329 displTexture.get(), |
| 341 offsetMatrix, | 330 offsetMatrix, |
| 342 colorTexture.get(), | 331 colorTexture.get(), |
| 343 SkISize::Make(color->width(), | 332 SkISize::Make(color->width(), |
| 344 color->height())))->un
ref(); | 333 color->height())))->un
ref(); |
| 345 paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode); | 334 paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode); |
| 346 SkMatrix matrix; | 335 SkMatrix matrix; |
| 347 matrix.setTranslate(-SkIntToScalar(colorBounds.x()), -SkIntToScalar(colo
rBounds.y())); | 336 matrix.setTranslate(-SkIntToScalar(colorBounds.x()), -SkIntToScalar(colo
rBounds.y())); |
| 348 | 337 |
| 349 sk_sp<GrDrawContext> drawContext(context->drawContext(sk_ref_sp(dst->asR
enderTarget()))); | 338 sk_sp<GrDrawContext> drawContext(context->newDrawContext(GrContext::kLoo
se_BackingFit, |
| 339 bounds.width(),
bounds.height(), |
| 340 kSkia8888_GrPix
elConfig)); |
| 350 if (!drawContext) { | 341 if (!drawContext) { |
| 351 return nullptr; | 342 return nullptr; |
| 352 } | 343 } |
| 353 | 344 |
| 354 drawContext->drawRect(GrClip::WideOpen(), paint, matrix, SkRect::Make(co
lorBounds)); | 345 drawContext->drawRect(GrClip::WideOpen(), paint, matrix, SkRect::Make(co
lorBounds)); |
| 355 | 346 |
| 356 offset->fX = bounds.left(); | 347 offset->fX = bounds.left(); |
| 357 offset->fY = bounds.top(); | 348 offset->fY = bounds.top(); |
| 358 return SkSpecialImage::MakeFromGpu(SkIRect::MakeWH(bounds.width(), bound
s.height()), | 349 return SkSpecialImage::MakeFromGpu(SkIRect::MakeWH(bounds.width(), bound
s.height()), |
| 359 kNeedNewImageUniqueID_SpecialImage, | 350 kNeedNewImageUniqueID_SpecialImage, |
| 360 std::move(dst)); | 351 drawContext->asTexture()); |
| 361 } | 352 } |
| 362 #endif | 353 #endif |
| 363 | 354 |
| 364 SkBitmap colorBM, displBM; | 355 SkBitmap colorBM, displBM; |
| 365 | 356 |
| 366 if (!color->getROPixels(&colorBM) || !displ->getROPixels(&displBM)) { | 357 if (!color->getROPixels(&colorBM) || !displ->getROPixels(&displBM)) { |
| 367 return nullptr; | 358 return nullptr; |
| 368 } | 359 } |
| 369 | 360 |
| 370 if ((colorBM.colorType() != kN32_SkColorType) || | 361 if ((colorBM.colorType() != kN32_SkColorType) || |
| (...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 626 void GrGLDisplacementMapEffect::GenKey(const GrProcessor& proc, | 617 void GrGLDisplacementMapEffect::GenKey(const GrProcessor& proc, |
| 627 const GrGLSLCaps&, GrProcessorKeyBuilder*
b) { | 618 const GrGLSLCaps&, GrProcessorKeyBuilder*
b) { |
| 628 const GrDisplacementMapEffect& displacementMap = proc.cast<GrDisplacementMap
Effect>(); | 619 const GrDisplacementMapEffect& displacementMap = proc.cast<GrDisplacementMap
Effect>(); |
| 629 | 620 |
| 630 uint32_t xKey = displacementMap.xChannelSelector(); | 621 uint32_t xKey = displacementMap.xChannelSelector(); |
| 631 uint32_t yKey = displacementMap.yChannelSelector() << kChannelSelectorKeyBit
s; | 622 uint32_t yKey = displacementMap.yChannelSelector() << kChannelSelectorKeyBit
s; |
| 632 | 623 |
| 633 b->add32(xKey | yKey); | 624 b->add32(xKey | yKey); |
| 634 } | 625 } |
| 635 #endif | 626 #endif |
| OLD | NEW |