| 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 486 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 497 radius, | 497 radius, |
| 498 morphType))->unref(); | 498 morphType))->unref(); |
| 499 context->drawRectToRect(paint, SkRect::Make(dstRect), SkRect::Make(srcRect))
; | 499 context->drawRectToRect(paint, SkRect::Make(dstRect), SkRect::Make(srcRect))
; |
| 500 } | 500 } |
| 501 | 501 |
| 502 bool apply_morphology(const SkBitmap& input, | 502 bool apply_morphology(const SkBitmap& input, |
| 503 const SkIRect& rect, | 503 const SkIRect& rect, |
| 504 GrMorphologyEffect::MorphologyType morphType, | 504 GrMorphologyEffect::MorphologyType morphType, |
| 505 SkISize radius, | 505 SkISize radius, |
| 506 SkBitmap* dst) { | 506 SkBitmap* dst) { |
| 507 GrTexture* srcTexture = input.getTexture(); | 507 SkAutoTUnref<GrTexture> srcTexture(SkRef(input.getTexture())); |
| 508 SkASSERT(srcTexture); | 508 SkASSERT(srcTexture); |
| 509 GrContext* context = srcTexture->getContext(); | 509 GrContext* context = srcTexture->getContext(); |
| 510 srcTexture->ref(); | |
| 511 SkAutoTUnref<GrTexture> src(srcTexture); | |
| 512 | 510 |
| 513 GrContext::AutoMatrix am; | 511 GrContext::AutoMatrix am; |
| 514 am.setIdentity(context); | 512 am.setIdentity(context); |
| 515 | 513 |
| 516 GrContext::AutoClip acs(context, SkRect::MakeWH(SkIntToScalar(srcTexture->wi
dth()), | 514 GrContext::AutoClip acs(context, SkRect::MakeWH(SkIntToScalar(srcTexture->wi
dth()), |
| 517 SkIntToScalar(srcTexture->he
ight()))); | 515 SkIntToScalar(srcTexture->he
ight()))); |
| 518 | 516 |
| 519 SkIRect dstRect = SkIRect::MakeWH(rect.width(), rect.height()); | 517 SkIRect dstRect = SkIRect::MakeWH(rect.width(), rect.height()); |
| 520 GrTextureDesc desc; | 518 GrTextureDesc desc; |
| 521 desc.fFlags = kRenderTarget_GrTextureFlagBit | kNoStencil_GrTextureFlagBit; | 519 desc.fFlags = kRenderTarget_GrTextureFlagBit | kNoStencil_GrTextureFlagBit; |
| 522 desc.fWidth = rect.width(); | 520 desc.fWidth = rect.width(); |
| 523 desc.fHeight = rect.height(); | 521 desc.fHeight = rect.height(); |
| 524 desc.fConfig = kSkia8888_GrPixelConfig; | 522 desc.fConfig = kSkia8888_GrPixelConfig; |
| 525 SkIRect srcRect = rect; | 523 SkIRect srcRect = rect; |
| 526 | 524 |
| 527 if (radius.fWidth > 0) { | 525 if (radius.fWidth > 0) { |
| 528 GrAutoScratchTexture ast(context, desc); | 526 GrTexture* texture = context->refScratchTexture(desc, GrContext::kApprox
_ScratchTexMatch); |
| 529 if (NULL == ast.texture()) { | 527 if (NULL == texture) { |
| 530 return false; | 528 return false; |
| 531 } | 529 } |
| 532 GrContext::AutoRenderTarget art(context, ast.texture()->asRenderTarget()
); | 530 GrContext::AutoRenderTarget art(context, texture->asRenderTarget()); |
| 533 apply_morphology_pass(context, src, srcRect, dstRect, radius.fWidth, | 531 apply_morphology_pass(context, srcTexture, srcRect, dstRect, radius.fWid
th, |
| 534 morphType, Gr1DKernelEffect::kX_Direction); | 532 morphType, Gr1DKernelEffect::kX_Direction); |
| 535 SkIRect clearRect = SkIRect::MakeXYWH(dstRect.fLeft, dstRect.fBottom, | 533 SkIRect clearRect = SkIRect::MakeXYWH(dstRect.fLeft, dstRect.fBottom, |
| 536 dstRect.width(), radius.fHeight); | 534 dstRect.width(), radius.fHeight); |
| 537 context->clear(&clearRect, GrMorphologyEffect::kErode_MorphologyType ==
morphType ? | 535 context->clear(&clearRect, GrMorphologyEffect::kErode_MorphologyType ==
morphType ? |
| 538 SK_ColorWHITE : | 536 SK_ColorWHITE : |
| 539 SK_ColorTRANSPARENT, false); | 537 SK_ColorTRANSPARENT, false); |
| 540 src.reset(ast.detach()); | 538 srcTexture.reset(texture); |
| 541 srcRect = dstRect; | 539 srcRect = dstRect; |
| 542 } | 540 } |
| 543 if (radius.fHeight > 0) { | 541 if (radius.fHeight > 0) { |
| 544 GrAutoScratchTexture ast(context, desc); | 542 GrTexture* texture = context->refScratchTexture(desc, GrContext::kApprox
_ScratchTexMatch); |
| 545 if (NULL == ast.texture()) { | 543 if (NULL == texture) { |
| 546 return false; | 544 return false; |
| 547 } | 545 } |
| 548 GrContext::AutoRenderTarget art(context, ast.texture()->asRenderTarget()
); | 546 GrContext::AutoRenderTarget art(context, texture->asRenderTarget()); |
| 549 apply_morphology_pass(context, src, srcRect, dstRect, radius.fHeight, | 547 apply_morphology_pass(context, srcTexture, srcRect, dstRect, radius.fHei
ght, |
| 550 morphType, Gr1DKernelEffect::kY_Direction); | 548 morphType, Gr1DKernelEffect::kY_Direction); |
| 551 src.reset(ast.detach()); | 549 srcTexture.reset(texture); |
| 552 } | 550 } |
| 553 SkImageFilter::WrapTexture(src, rect.width(), rect.height(), dst); | 551 SkImageFilter::WrapTexture(srcTexture, rect.width(), rect.height(), dst); |
| 554 return true; | 552 return true; |
| 555 } | 553 } |
| 556 | 554 |
| 557 }; | 555 }; |
| 558 | 556 |
| 559 bool SkMorphologyImageFilter::filterImageGPUGeneric(bool dilate, | 557 bool SkMorphologyImageFilter::filterImageGPUGeneric(bool dilate, |
| 560 Proxy* proxy, | 558 Proxy* proxy, |
| 561 const SkBitmap& src, | 559 const SkBitmap& src, |
| 562 const Context& ctx, | 560 const Context& ctx, |
| 563 SkBitmap* result, | 561 SkBitmap* result, |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 604 SkBitmap* result, SkIPoint* offset) con
st { | 602 SkBitmap* result, SkIPoint* offset) con
st { |
| 605 return this->filterImageGPUGeneric(true, proxy, src, ctx, result, offset); | 603 return this->filterImageGPUGeneric(true, proxy, src, ctx, result, offset); |
| 606 } | 604 } |
| 607 | 605 |
| 608 bool SkErodeImageFilter::filterImageGPU(Proxy* proxy, const SkBitmap& src, const
Context& ctx, | 606 bool SkErodeImageFilter::filterImageGPU(Proxy* proxy, const SkBitmap& src, const
Context& ctx, |
| 609 SkBitmap* result, SkIPoint* offset) cons
t { | 607 SkBitmap* result, SkIPoint* offset) cons
t { |
| 610 return this->filterImageGPUGeneric(false, proxy, src, ctx, result, offset); | 608 return this->filterImageGPUGeneric(false, proxy, src, ctx, result, offset); |
| 611 } | 609 } |
| 612 | 610 |
| 613 #endif | 611 #endif |
| OLD | NEW |