| 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 #include "SkBitmap.h" | 9 #include "SkBitmap.h" |
| 10 #include "SkColorPriv.h" | 10 #include "SkColorPriv.h" |
| (...skipping 529 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 540 morphType, bounds, direction); | 540 morphType, bounds, direction); |
| 541 apply_morphology_rect_no_bounds(drawContext, clip, texture, middleSrcRec
t, middleDstRect, | 541 apply_morphology_rect_no_bounds(drawContext, clip, texture, middleSrcRec
t, middleDstRect, |
| 542 radius, morphType, direction); | 542 radius, morphType, direction); |
| 543 } | 543 } |
| 544 } | 544 } |
| 545 | 545 |
| 546 bool apply_morphology(const SkBitmap& input, | 546 bool apply_morphology(const SkBitmap& input, |
| 547 const SkIRect& rect, | 547 const SkIRect& rect, |
| 548 GrMorphologyEffect::MorphologyType morphType, | 548 GrMorphologyEffect::MorphologyType morphType, |
| 549 SkISize radius, | 549 SkISize radius, |
| 550 SkBitmap* dst) { | 550 SkBitmap* dst, |
| 551 GrTextureProvider::SizeConstraint constraint) { |
| 551 SkAutoTUnref<GrTexture> srcTexture(SkRef(input.getTexture())); | 552 SkAutoTUnref<GrTexture> srcTexture(SkRef(input.getTexture())); |
| 552 SkASSERT(srcTexture); | 553 SkASSERT(srcTexture); |
| 553 GrContext* context = srcTexture->getContext(); | 554 GrContext* context = srcTexture->getContext(); |
| 554 | 555 |
| 555 // setup new clip | 556 // setup new clip |
| 556 GrClip clip(SkRect::MakeWH(SkIntToScalar(srcTexture->width()), | 557 GrClip clip(SkRect::MakeWH(SkIntToScalar(srcTexture->width()), |
| 557 SkIntToScalar(srcTexture->height()))); | 558 SkIntToScalar(srcTexture->height()))); |
| 558 | 559 |
| 559 SkIRect dstRect = SkIRect::MakeWH(rect.width(), rect.height()); | 560 SkIRect dstRect = SkIRect::MakeWH(rect.width(), rect.height()); |
| 560 GrSurfaceDesc desc; | 561 GrSurfaceDesc desc; |
| 561 desc.fFlags = kRenderTarget_GrSurfaceFlag; | 562 desc.fFlags = kRenderTarget_GrSurfaceFlag; |
| 562 desc.fWidth = rect.width(); | 563 desc.fWidth = rect.width(); |
| 563 desc.fHeight = rect.height(); | 564 desc.fHeight = rect.height(); |
| 564 desc.fConfig = kSkia8888_GrPixelConfig; | 565 desc.fConfig = kSkia8888_GrPixelConfig; |
| 565 SkIRect srcRect = rect; | 566 SkIRect srcRect = rect; |
| 566 | 567 |
| 567 if (radius.fWidth > 0) { | 568 if (radius.fWidth > 0) { |
| 568 GrTexture* scratch = context->textureProvider()->createApproxTexture(des
c); | 569 GrTexture* scratch = context->textureProvider()->createTexture(desc, con
straint); |
| 569 if (nullptr == scratch) { | 570 if (nullptr == scratch) { |
| 570 return false; | 571 return false; |
| 571 } | 572 } |
| 572 SkAutoTUnref<GrDrawContext> dstDrawContext( | 573 SkAutoTUnref<GrDrawContext> dstDrawContext( |
| 573 context->drawContext(scratch->as
RenderTarget())); | 574 context->drawContext(scratch->as
RenderTarget())); |
| 574 if (!dstDrawContext) { | 575 if (!dstDrawContext) { |
| 575 return false; | 576 return false; |
| 576 } | 577 } |
| 577 | 578 |
| 578 apply_morphology_pass(dstDrawContext, clip, srcTexture, | 579 apply_morphology_pass(dstDrawContext, clip, srcTexture, |
| 579 srcRect, dstRect, radius.fWidth, morphType, | 580 srcRect, dstRect, radius.fWidth, morphType, |
| 580 Gr1DKernelEffect::kX_Direction); | 581 Gr1DKernelEffect::kX_Direction); |
| 581 SkIRect clearRect = SkIRect::MakeXYWH(dstRect.fLeft, dstRect.fBottom, | 582 SkIRect clearRect = SkIRect::MakeXYWH(dstRect.fLeft, dstRect.fBottom, |
| 582 dstRect.width(), radius.fHeight); | 583 dstRect.width(), radius.fHeight); |
| 583 GrColor clearColor = GrMorphologyEffect::kErode_MorphologyType == morphT
ype ? | 584 GrColor clearColor = GrMorphologyEffect::kErode_MorphologyType == morphT
ype ? |
| 584 SK_ColorWHITE : | 585 SK_ColorWHITE : |
| 585 SK_ColorTRANSPARENT; | 586 SK_ColorTRANSPARENT; |
| 586 dstDrawContext->clear(&clearRect, clearColor, false); | 587 dstDrawContext->clear(&clearRect, clearColor, false); |
| 587 | 588 |
| 588 srcTexture.reset(scratch); | 589 srcTexture.reset(scratch); |
| 589 srcRect = dstRect; | 590 srcRect = dstRect; |
| 590 } | 591 } |
| 591 if (radius.fHeight > 0) { | 592 if (radius.fHeight > 0) { |
| 592 GrTexture* scratch = context->textureProvider()->createApproxTexture(des
c); | 593 GrTexture* scratch = context->textureProvider()->createTexture(desc, con
straint); |
| 593 if (nullptr == scratch) { | 594 if (nullptr == scratch) { |
| 594 return false; | 595 return false; |
| 595 } | 596 } |
| 596 SkAutoTUnref<GrDrawContext> dstDrawContext( | 597 SkAutoTUnref<GrDrawContext> dstDrawContext( |
| 597 context->drawContext(scratch->as
RenderTarget())); | 598 context->drawContext(scratch->as
RenderTarget())); |
| 598 if (!dstDrawContext) { | 599 if (!dstDrawContext) { |
| 599 return false; | 600 return false; |
| 600 } | 601 } |
| 601 | 602 |
| 602 apply_morphology_pass(dstDrawContext, clip, srcTexture, | 603 apply_morphology_pass(dstDrawContext, clip, srcTexture, |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 640 srcBounds.offset(-srcOffset); | 641 srcBounds.offset(-srcOffset); |
| 641 if (width == 0 && height == 0) { | 642 if (width == 0 && height == 0) { |
| 642 input.extractSubset(result, srcBounds); | 643 input.extractSubset(result, srcBounds); |
| 643 offset->fX = bounds.left(); | 644 offset->fX = bounds.left(); |
| 644 offset->fY = bounds.top(); | 645 offset->fY = bounds.top(); |
| 645 return true; | 646 return true; |
| 646 } | 647 } |
| 647 | 648 |
| 648 GrMorphologyEffect::MorphologyType type = dilate ? GrMorphologyEffect::kDila
te_MorphologyType | 649 GrMorphologyEffect::MorphologyType type = dilate ? GrMorphologyEffect::kDila
te_MorphologyType |
| 649 : GrMorphologyEffect::kErod
e_MorphologyType; | 650 : GrMorphologyEffect::kErod
e_MorphologyType; |
| 650 if (!apply_morphology(input, srcBounds, type, SkISize::Make(width, height),
result)) { | 651 if (!apply_morphology(input, srcBounds, type, SkISize::Make(width, height),
result, |
| 652 proxy->getSizeConstraint())) { |
| 651 return false; | 653 return false; |
| 652 } | 654 } |
| 653 offset->fX = bounds.left(); | 655 offset->fX = bounds.left(); |
| 654 offset->fY = bounds.top(); | 656 offset->fY = bounds.top(); |
| 655 return true; | 657 return true; |
| 656 } | 658 } |
| 657 | 659 |
| 658 bool SkDilateImageFilter::filterImageGPU(Proxy* proxy, const SkBitmap& src, cons
t Context& ctx, | 660 bool SkDilateImageFilter::filterImageGPU(Proxy* proxy, const SkBitmap& src, cons
t Context& ctx, |
| 659 SkBitmap* result, SkIPoint* offset) con
st { | 661 SkBitmap* result, SkIPoint* offset) con
st { |
| 660 return this->filterImageGPUGeneric(true, proxy, src, ctx, result, offset); | 662 return this->filterImageGPUGeneric(true, proxy, src, ctx, result, offset); |
| 661 } | 663 } |
| 662 | 664 |
| 663 bool SkErodeImageFilter::filterImageGPU(Proxy* proxy, const SkBitmap& src, const
Context& ctx, | 665 bool SkErodeImageFilter::filterImageGPU(Proxy* proxy, const SkBitmap& src, const
Context& ctx, |
| 664 SkBitmap* result, SkIPoint* offset) cons
t { | 666 SkBitmap* result, SkIPoint* offset) cons
t { |
| 665 return this->filterImageGPUGeneric(false, proxy, src, ctx, result, offset); | 667 return this->filterImageGPUGeneric(false, proxy, src, ctx, result, offset); |
| 666 } | 668 } |
| 667 | 669 |
| 668 #endif | 670 #endif |
| OLD | NEW |