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" |
11 #include "SkReadBuffer.h" | 11 #include "SkReadBuffer.h" |
12 #include "SkWriteBuffer.h" | 12 #include "SkWriteBuffer.h" |
13 #include "SkRect.h" | 13 #include "SkRect.h" |
14 #include "SkMorphology_opts.h" | 14 #include "SkMorphology_opts.h" |
15 #if SK_SUPPORT_GPU | 15 #if SK_SUPPORT_GPU |
16 #include "GrContext.h" | 16 #include "GrContext.h" |
17 #include "GrTexture.h" | 17 #include "GrTexture.h" |
18 #include "GrTBackendEffectFactory.h" | 18 #include "GrTBackendEffectFactory.h" |
19 #include "gl/GrGLEffect.h" | 19 #include "gl/GrGLEffect.h" |
20 #include "effects/Gr1DKernelEffect.h" | 20 #include "effects/Gr1DKernelEffect.h" |
21 #include "SkImageFilterUtils.h" | |
22 #endif | 21 #endif |
23 | 22 |
24 SkMorphologyImageFilter::SkMorphologyImageFilter(SkReadBuffer& buffer) | 23 SkMorphologyImageFilter::SkMorphologyImageFilter(SkReadBuffer& buffer) |
25 : INHERITED(1, buffer) { | 24 : INHERITED(1, buffer) { |
26 fRadius.fWidth = buffer.readInt(); | 25 fRadius.fWidth = buffer.readInt(); |
27 fRadius.fHeight = buffer.readInt(); | 26 fRadius.fHeight = buffer.readInt(); |
28 buffer.validate((fRadius.fWidth >= 0) && | 27 buffer.validate((fRadius.fWidth >= 0) && |
29 (fRadius.fHeight >= 0)); | 28 (fRadius.fHeight >= 0)); |
30 } | 29 } |
31 | 30 |
(...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
523 src.reset(ast.detach()); | 522 src.reset(ast.detach()); |
524 srcRect = dstRect; | 523 srcRect = dstRect; |
525 } | 524 } |
526 if (radius.fHeight > 0) { | 525 if (radius.fHeight > 0) { |
527 GrAutoScratchTexture ast(context, desc); | 526 GrAutoScratchTexture ast(context, desc); |
528 GrContext::AutoRenderTarget art(context, ast.texture()->asRenderTarget()
); | 527 GrContext::AutoRenderTarget art(context, ast.texture()->asRenderTarget()
); |
529 apply_morphology_pass(context, src, srcRect, dstRect, radius.fHeight, | 528 apply_morphology_pass(context, src, srcRect, dstRect, radius.fHeight, |
530 morphType, Gr1DKernelEffect::kY_Direction); | 529 morphType, Gr1DKernelEffect::kY_Direction); |
531 src.reset(ast.detach()); | 530 src.reset(ast.detach()); |
532 } | 531 } |
533 return SkImageFilterUtils::WrapTexture(src, rect.width(), rect.height(), dst
); | 532 SkImageFilter::WrapTexture(src, rect.width(), rect.height(), dst); |
| 533 return true; |
534 } | 534 } |
535 | 535 |
536 }; | 536 }; |
537 | 537 |
538 bool SkMorphologyImageFilter::filterImageGPUGeneric(bool dilate, | 538 bool SkMorphologyImageFilter::filterImageGPUGeneric(bool dilate, |
539 Proxy* proxy, | 539 Proxy* proxy, |
540 const SkBitmap& src, | 540 const SkBitmap& src, |
541 const SkMatrix& ctm, | 541 const SkMatrix& ctm, |
542 SkBitmap* result, | 542 SkBitmap* result, |
543 SkIPoint* offset) const { | 543 SkIPoint* offset) const { |
544 SkBitmap input; | 544 SkBitmap input = src; |
545 SkIPoint srcOffset = SkIPoint::Make(0, 0); | 545 SkIPoint srcOffset = SkIPoint::Make(0, 0); |
546 if (!SkImageFilterUtils::GetInputResultGPU(getInput(0), proxy, src, ctm, &in
put, &srcOffset)) { | 546 if (getInput(0) && !getInput(0)->getInputResultGPU(proxy, src, ctm, &input,
&srcOffset)) { |
547 return false; | 547 return false; |
548 } | 548 } |
549 SkIRect bounds; | 549 SkIRect bounds; |
550 input.getBounds(&bounds); | 550 input.getBounds(&bounds); |
551 bounds.offset(srcOffset); | 551 bounds.offset(srcOffset); |
552 if (!this->applyCropRect(&bounds, ctm)) { | 552 if (!this->applyCropRect(&bounds, ctm)) { |
553 return false; | 553 return false; |
554 } | 554 } |
555 SkVector radius = SkVector::Make(SkIntToScalar(this->radius().width()), | 555 SkVector radius = SkVector::Make(SkIntToScalar(this->radius().width()), |
556 SkIntToScalar(this->radius().height())); | 556 SkIntToScalar(this->radius().height())); |
(...skipping 28 matching lines...) Expand all Loading... |
585 SkBitmap* result, SkIPoint* offset) con
st { | 585 SkBitmap* result, SkIPoint* offset) con
st { |
586 return this->filterImageGPUGeneric(true, proxy, src, ctm, result, offset); | 586 return this->filterImageGPUGeneric(true, proxy, src, ctm, result, offset); |
587 } | 587 } |
588 | 588 |
589 bool SkErodeImageFilter::filterImageGPU(Proxy* proxy, const SkBitmap& src, const
SkMatrix& ctm, | 589 bool SkErodeImageFilter::filterImageGPU(Proxy* proxy, const SkBitmap& src, const
SkMatrix& ctm, |
590 SkBitmap* result, SkIPoint* offset) cons
t { | 590 SkBitmap* result, SkIPoint* offset) cons
t { |
591 return this->filterImageGPUGeneric(false, proxy, src, ctm, result, offset); | 591 return this->filterImageGPUGeneric(false, proxy, src, ctm, result, offset); |
592 } | 592 } |
593 | 593 |
594 #endif | 594 #endif |
OLD | NEW |