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