OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 The Android Open Source Project | 2 * Copyright 2012 The Android Open Source Project |
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 "SkMorphologyImageFilter.h" | 8 #include "SkMorphologyImageFilter.h" |
9 | 9 |
10 #include "SkBitmap.h" | 10 #include "SkBitmap.h" |
(...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
471 | 471 |
472 static sk_sp<SkSpecialImage> apply_morphology(GrContext* context, | 472 static sk_sp<SkSpecialImage> apply_morphology(GrContext* context, |
473 SkSpecialImage* input, | 473 SkSpecialImage* input, |
474 const SkIRect& rect, | 474 const SkIRect& rect, |
475 GrMorphologyEffect::MorphologyType
morphType, | 475 GrMorphologyEffect::MorphologyType
morphType, |
476 SkISize radius) { | 476 SkISize radius) { |
477 sk_sp<GrTexture> srcTexture(input->asTextureRef(context)); | 477 sk_sp<GrTexture> srcTexture(input->asTextureRef(context)); |
478 SkASSERT(srcTexture); | 478 SkASSERT(srcTexture); |
479 | 479 |
480 // setup new clip | 480 // setup new clip |
481 const GrClip clip(SkRect::MakeWH(SkIntToScalar(srcTexture->width()), | 481 GrClip clip(SkRect::MakeWH(SkIntToScalar(srcTexture->width()), |
482 SkIntToScalar(srcTexture->height()))); | 482 SkIntToScalar(srcTexture->height()))); |
483 | 483 |
484 const SkIRect dstRect = SkIRect::MakeWH(rect.width(), rect.height()); | 484 SkIRect dstRect = SkIRect::MakeWH(rect.width(), rect.height()); |
| 485 GrSurfaceDesc desc; |
| 486 desc.fFlags = kRenderTarget_GrSurfaceFlag; |
| 487 desc.fWidth = rect.width(); |
| 488 desc.fHeight = rect.height(); |
| 489 desc.fConfig = kSkia8888_GrPixelConfig; |
485 SkIRect srcRect = rect; | 490 SkIRect srcRect = rect; |
486 | 491 |
487 SkASSERT(radius.width() > 0 || radius.height() > 0); | 492 SkASSERT(radius.width() > 0 || radius.height() > 0); |
488 | 493 |
489 if (radius.fWidth > 0) { | 494 if (radius.fWidth > 0) { |
490 sk_sp<GrDrawContext> dstDrawContext(context->newDrawContext(GrContext::k
Loose_BackingFit, | 495 GrTexture* scratch = context->textureProvider()->createApproxTexture(des
c); |
491 rect.width()
, rect.height(), | 496 if (!scratch) { |
492 kSkia8888_Gr
PixelConfig)); | 497 return nullptr; |
| 498 } |
| 499 sk_sp<GrDrawContext> dstDrawContext( |
| 500 context->drawContext(sk_ref_sp(scratch->as
RenderTarget()))); |
493 if (!dstDrawContext) { | 501 if (!dstDrawContext) { |
494 return nullptr; | 502 return nullptr; |
495 } | 503 } |
496 | 504 |
497 apply_morphology_pass(dstDrawContext.get(), clip, srcTexture.get(), | 505 apply_morphology_pass(dstDrawContext.get(), clip, srcTexture.get(), |
498 srcRect, dstRect, radius.fWidth, morphType, | 506 srcRect, dstRect, radius.fWidth, morphType, |
499 Gr1DKernelEffect::kX_Direction); | 507 Gr1DKernelEffect::kX_Direction); |
500 SkIRect clearRect = SkIRect::MakeXYWH(dstRect.fLeft, dstRect.fBottom, | 508 SkIRect clearRect = SkIRect::MakeXYWH(dstRect.fLeft, dstRect.fBottom, |
501 dstRect.width(), radius.fHeight); | 509 dstRect.width(), radius.fHeight); |
502 GrColor clearColor = GrMorphologyEffect::kErode_MorphologyType == morphT
ype | 510 GrColor clearColor = GrMorphologyEffect::kErode_MorphologyType == morphT
ype ? |
503 ? SK_ColorWHITE | 511 SK_ColorWHITE : |
504 : SK_ColorTRANSPARENT; | 512 SK_ColorTRANSPARENT; |
505 dstDrawContext->clear(&clearRect, clearColor, false); | 513 dstDrawContext->clear(&clearRect, clearColor, false); |
506 | 514 |
507 srcTexture = dstDrawContext->asTexture(); | 515 srcTexture.reset(scratch); |
508 srcRect = dstRect; | 516 srcRect = dstRect; |
509 } | 517 } |
510 if (radius.fHeight > 0) { | 518 if (radius.fHeight > 0) { |
511 sk_sp<GrDrawContext> dstDrawContext(context->newDrawContext(GrContext::k
Loose_BackingFit, | 519 GrTexture* scratch = context->textureProvider()->createApproxTexture(des
c); |
512 rect.width()
, rect.height(), | 520 if (!scratch) { |
513 kSkia8888_Gr
PixelConfig)); | 521 return nullptr; |
| 522 } |
| 523 sk_sp<GrDrawContext> dstDrawContext( |
| 524 context->drawContext(sk_ref_sp(scratch->as
RenderTarget()))); |
514 if (!dstDrawContext) { | 525 if (!dstDrawContext) { |
515 return nullptr; | 526 return nullptr; |
516 } | 527 } |
517 | 528 |
518 apply_morphology_pass(dstDrawContext.get(), clip, srcTexture.get(), | 529 apply_morphology_pass(dstDrawContext.get(), clip, srcTexture.get(), |
519 srcRect, dstRect, radius.fHeight, morphType, | 530 srcRect, dstRect, radius.fHeight, morphType, |
520 Gr1DKernelEffect::kY_Direction); | 531 Gr1DKernelEffect::kY_Direction); |
521 | 532 |
522 srcTexture = dstDrawContext->asTexture(); | 533 srcTexture.reset(scratch); |
523 } | 534 } |
524 | 535 |
525 return SkSpecialImage::MakeFromGpu(SkIRect::MakeWH(rect.width(), rect.height
()), | 536 return SkSpecialImage::MakeFromGpu(SkIRect::MakeWH(rect.width(), rect.height
()), |
526 kNeedNewImageUniqueID_SpecialImage, | 537 kNeedNewImageUniqueID_SpecialImage, |
527 std::move(srcTexture), &input->props()); | 538 std::move(srcTexture), &input->props()); |
528 } | 539 } |
529 #endif | 540 #endif |
530 | 541 |
531 sk_sp<SkSpecialImage> SkMorphologyImageFilter::onFilterImage(SkSpecialImage* sou
rce, | 542 sk_sp<SkSpecialImage> SkMorphologyImageFilter::onFilterImage(SkSpecialImage* sou
rce, |
532 const Context& ctx, | 543 const Context& ctx, |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
628 inputBM.getAddr32(srcBounds.left(), srcBounds.top()), | 639 inputBM.getAddr32(srcBounds.left(), srcBounds.top()), |
629 inputBM.rowBytesAsPixels(), | 640 inputBM.rowBytesAsPixels(), |
630 &dst, height, srcBounds); | 641 &dst, height, srcBounds); |
631 } | 642 } |
632 offset->fX = bounds.left(); | 643 offset->fX = bounds.left(); |
633 offset->fY = bounds.top(); | 644 offset->fY = bounds.top(); |
634 | 645 |
635 return SkSpecialImage::MakeFromRaster(SkIRect::MakeWH(bounds.width(), bounds
.height()), | 646 return SkSpecialImage::MakeFromRaster(SkIRect::MakeWH(bounds.width(), bounds
.height()), |
636 dst, &source->props()); | 647 dst, &source->props()); |
637 } | 648 } |
OLD | NEW |