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 456 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
467 } | 467 } |
468 } | 468 } |
469 | 469 |
470 static sk_sp<SkSpecialImage> apply_morphology(GrContext* context, | 470 static sk_sp<SkSpecialImage> apply_morphology(GrContext* context, |
471 SkSpecialImage* input, | 471 SkSpecialImage* input, |
472 const SkIRect& rect, | 472 const SkIRect& rect, |
473 GrMorphologyEffect::MorphologyType
morphType, | 473 GrMorphologyEffect::MorphologyType
morphType, |
474 SkISize radius) { | 474 SkISize radius) { |
475 sk_sp<GrTexture> srcTexture(input->asTextureRef(context)); | 475 sk_sp<GrTexture> srcTexture(input->asTextureRef(context)); |
476 SkASSERT(srcTexture); | 476 SkASSERT(srcTexture); |
| 477 sk_sp<SkColorSpace> colorSpace = sk_ref_sp(input->getColorSpace()); |
477 | 478 |
478 // setup new clip | 479 // setup new clip |
479 const GrFixedClip clip(SkIRect::MakeWH(srcTexture->width(), srcTexture->heig
ht())); | 480 const GrFixedClip clip(SkIRect::MakeWH(srcTexture->width(), srcTexture->heig
ht())); |
480 | 481 |
481 const SkIRect dstRect = SkIRect::MakeWH(rect.width(), rect.height()); | 482 const SkIRect dstRect = SkIRect::MakeWH(rect.width(), rect.height()); |
482 SkIRect srcRect = rect; | 483 SkIRect srcRect = rect; |
483 | 484 |
484 SkASSERT(radius.width() > 0 || radius.height() > 0); | 485 SkASSERT(radius.width() > 0 || radius.height() > 0); |
485 | 486 |
486 if (radius.fWidth > 0) { | 487 if (radius.fWidth > 0) { |
487 sk_sp<GrDrawContext> dstDrawContext(context->newDrawContext(SkBackingFit
::kApprox, | 488 sk_sp<GrDrawContext> dstDrawContext(context->newDrawContext(SkBackingFit
::kApprox, |
488 rect.width()
, rect.height(), | 489 rect.width()
, rect.height(), |
489 kSkia8888_Gr
PixelConfig)); | 490 kSkia8888_Gr
PixelConfig, |
| 491 colorSpace))
; |
490 if (!dstDrawContext) { | 492 if (!dstDrawContext) { |
491 return nullptr; | 493 return nullptr; |
492 } | 494 } |
493 | 495 |
494 apply_morphology_pass(dstDrawContext.get(), clip, srcTexture.get(), | 496 apply_morphology_pass(dstDrawContext.get(), clip, srcTexture.get(), |
495 srcRect, dstRect, radius.fWidth, morphType, | 497 srcRect, dstRect, radius.fWidth, morphType, |
496 Gr1DKernelEffect::kX_Direction); | 498 Gr1DKernelEffect::kX_Direction); |
497 SkIRect clearRect = SkIRect::MakeXYWH(dstRect.fLeft, dstRect.fBottom, | 499 SkIRect clearRect = SkIRect::MakeXYWH(dstRect.fLeft, dstRect.fBottom, |
498 dstRect.width(), radius.fHeight); | 500 dstRect.width(), radius.fHeight); |
499 GrColor clearColor = GrMorphologyEffect::kErode_MorphologyType == morphT
ype | 501 GrColor clearColor = GrMorphologyEffect::kErode_MorphologyType == morphT
ype |
500 ? SK_ColorWHITE | 502 ? SK_ColorWHITE |
501 : SK_ColorTRANSPARENT; | 503 : SK_ColorTRANSPARENT; |
502 dstDrawContext->clear(&clearRect, clearColor, false); | 504 dstDrawContext->clear(&clearRect, clearColor, false); |
503 | 505 |
504 srcTexture = dstDrawContext->asTexture(); | 506 srcTexture = dstDrawContext->asTexture(); |
505 srcRect = dstRect; | 507 srcRect = dstRect; |
506 } | 508 } |
507 if (radius.fHeight > 0) { | 509 if (radius.fHeight > 0) { |
508 sk_sp<GrDrawContext> dstDrawContext(context->newDrawContext(SkBackingFit
::kApprox, | 510 sk_sp<GrDrawContext> dstDrawContext(context->newDrawContext(SkBackingFit
::kApprox, |
509 rect.width()
, rect.height(), | 511 rect.width()
, rect.height(), |
510 kSkia8888_Gr
PixelConfig)); | 512 kSkia8888_Gr
PixelConfig, |
| 513 colorSpace))
; |
511 if (!dstDrawContext) { | 514 if (!dstDrawContext) { |
512 return nullptr; | 515 return nullptr; |
513 } | 516 } |
514 | 517 |
515 apply_morphology_pass(dstDrawContext.get(), clip, srcTexture.get(), | 518 apply_morphology_pass(dstDrawContext.get(), clip, srcTexture.get(), |
516 srcRect, dstRect, radius.fHeight, morphType, | 519 srcRect, dstRect, radius.fHeight, morphType, |
517 Gr1DKernelEffect::kY_Direction); | 520 Gr1DKernelEffect::kY_Direction); |
518 | 521 |
519 srcTexture = dstDrawContext->asTexture(); | 522 srcTexture = dstDrawContext->asTexture(); |
520 } | 523 } |
521 | 524 |
522 // TODO: Get the colorSpace from the drawContext (once it has one) | |
523 return SkSpecialImage::MakeFromGpu(SkIRect::MakeWH(rect.width(), rect.height
()), | 525 return SkSpecialImage::MakeFromGpu(SkIRect::MakeWH(rect.width(), rect.height
()), |
524 kNeedNewImageUniqueID_SpecialImage, | 526 kNeedNewImageUniqueID_SpecialImage, |
525 std::move(srcTexture), sk_ref_sp(input->g
etColorSpace()), | 527 std::move(srcTexture), std::move(colorSpa
ce), |
526 &input->props()); | 528 &input->props()); |
527 } | 529 } |
528 #endif | 530 #endif |
529 | 531 |
530 sk_sp<SkSpecialImage> SkMorphologyImageFilter::onFilterImage(SkSpecialImage* sou
rce, | 532 sk_sp<SkSpecialImage> SkMorphologyImageFilter::onFilterImage(SkSpecialImage* sou
rce, |
531 const Context& ctx, | 533 const Context& ctx, |
532 SkIPoint* offset) c
onst { | 534 SkIPoint* offset) c
onst { |
533 SkIPoint inputOffset = SkIPoint::Make(0, 0); | 535 SkIPoint inputOffset = SkIPoint::Make(0, 0); |
534 sk_sp<SkSpecialImage> input(this->filterInput(0, source, ctx, &inputOffset))
; | 536 sk_sp<SkSpecialImage> input(this->filterInput(0, source, ctx, &inputOffset))
; |
535 if (!input) { | 537 if (!input) { |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
627 inputBM.getAddr32(srcBounds.left(), srcBounds.top()), | 629 inputBM.getAddr32(srcBounds.left(), srcBounds.top()), |
628 inputBM.rowBytesAsPixels(), | 630 inputBM.rowBytesAsPixels(), |
629 &dst, height, srcBounds); | 631 &dst, height, srcBounds); |
630 } | 632 } |
631 offset->fX = bounds.left(); | 633 offset->fX = bounds.left(); |
632 offset->fY = bounds.top(); | 634 offset->fY = bounds.top(); |
633 | 635 |
634 return SkSpecialImage::MakeFromRaster(SkIRect::MakeWH(bounds.width(), bounds
.height()), | 636 return SkSpecialImage::MakeFromRaster(SkIRect::MakeWH(bounds.width(), bounds
.height()), |
635 dst, &source->props()); | 637 dst, &source->props()); |
636 } | 638 } |
OLD | NEW |