| 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 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 */ | 291 */ |
| 292 class GrMorphologyEffect : public Gr1DKernelEffect { | 292 class GrMorphologyEffect : public Gr1DKernelEffect { |
| 293 | 293 |
| 294 public: | 294 public: |
| 295 | 295 |
| 296 enum MorphologyType { | 296 enum MorphologyType { |
| 297 kErode_MorphologyType, | 297 kErode_MorphologyType, |
| 298 kDilate_MorphologyType, | 298 kDilate_MorphologyType, |
| 299 }; | 299 }; |
| 300 | 300 |
| 301 static GrFragmentProcessor* Create(GrTexture* tex, Direction dir, int radius
, | 301 static GrFragmentProcessor* Create(GrProcessorDataManager* procDataManager,
GrTexture* tex, |
| 302 MorphologyType type) { | 302 Direction dir, int radius, MorphologyType
type) { |
| 303 return SkNEW_ARGS(GrMorphologyEffect, (tex, dir, radius, type)); | 303 return SkNEW_ARGS(GrMorphologyEffect, (procDataManager, tex, dir, radius
, type)); |
| 304 } | 304 } |
| 305 | 305 |
| 306 static GrFragmentProcessor* Create(GrTexture* tex, Direction dir, int radius
, | 306 static GrFragmentProcessor* Create(GrProcessorDataManager* procDataManager,
GrTexture* tex, |
| 307 MorphologyType type, float bounds[2]) { | 307 Direction dir, int radius, MorphologyType
type, |
| 308 return SkNEW_ARGS(GrMorphologyEffect, (tex, dir, radius, type, bounds)); | 308 float bounds[2]) { |
| 309 return SkNEW_ARGS(GrMorphologyEffect, (procDataManager, tex, dir, radius
, type, bounds)); |
| 309 } | 310 } |
| 310 | 311 |
| 311 virtual ~GrMorphologyEffect(); | 312 virtual ~GrMorphologyEffect(); |
| 312 | 313 |
| 313 MorphologyType type() const { return fType; } | 314 MorphologyType type() const { return fType; } |
| 314 bool useRange() const { return fUseRange; } | 315 bool useRange() const { return fUseRange; } |
| 315 const float* range() const { return fRange; } | 316 const float* range() const { return fRange; } |
| 316 | 317 |
| 317 const char* name() const override { return "Morphology"; } | 318 const char* name() const override { return "Morphology"; } |
| 318 | 319 |
| 319 void getGLProcessorKey(const GrGLSLCaps&, GrProcessorKeyBuilder*) const over
ride; | 320 void getGLProcessorKey(const GrGLSLCaps&, GrProcessorKeyBuilder*) const over
ride; |
| 320 | 321 |
| 321 GrGLFragmentProcessor* createGLInstance() const override; | 322 GrGLFragmentProcessor* createGLInstance() const override; |
| 322 | 323 |
| 323 protected: | 324 protected: |
| 324 | 325 |
| 325 MorphologyType fType; | 326 MorphologyType fType; |
| 326 bool fUseRange; | 327 bool fUseRange; |
| 327 float fRange[2]; | 328 float fRange[2]; |
| 328 | 329 |
| 329 private: | 330 private: |
| 330 bool onIsEqual(const GrFragmentProcessor&) const override; | 331 bool onIsEqual(const GrFragmentProcessor&) const override; |
| 331 | 332 |
| 332 void onComputeInvariantOutput(GrInvariantOutput* inout) const override; | 333 void onComputeInvariantOutput(GrInvariantOutput* inout) const override; |
| 333 | 334 |
| 334 GrMorphologyEffect(GrTexture*, Direction, int radius, MorphologyType); | 335 GrMorphologyEffect(GrProcessorDataManager*, GrTexture*, Direction, int radiu
s, MorphologyType); |
| 335 GrMorphologyEffect(GrTexture*, Direction, int radius, MorphologyType, float
bounds[2]); | 336 GrMorphologyEffect(GrProcessorDataManager*, GrTexture*, Direction, int radiu
s, MorphologyType, |
| 337 float bounds[2]); |
| 336 | 338 |
| 337 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; | 339 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; |
| 338 | 340 |
| 339 typedef Gr1DKernelEffect INHERITED; | 341 typedef Gr1DKernelEffect INHERITED; |
| 340 }; | 342 }; |
| 341 | 343 |
| 342 /////////////////////////////////////////////////////////////////////////////// | 344 /////////////////////////////////////////////////////////////////////////////// |
| 343 | 345 |
| 344 class GrGLMorphologyEffect : public GrGLFragmentProcessor { | 346 class GrGLMorphologyEffect : public GrGLFragmentProcessor { |
| 345 public: | 347 public: |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 487 if (fDirection && texture.origin() == kBottomLeft_GrSurfaceOrigin) { | 489 if (fDirection && texture.origin() == kBottomLeft_GrSurfaceOrigin) { |
| 488 pdman.set2f(fRangeUni, 1.0f - range[1], 1.0f - range[0]); | 490 pdman.set2f(fRangeUni, 1.0f - range[1], 1.0f - range[0]); |
| 489 } else { | 491 } else { |
| 490 pdman.set2f(fRangeUni, range[0], range[1]); | 492 pdman.set2f(fRangeUni, range[0], range[1]); |
| 491 } | 493 } |
| 492 } | 494 } |
| 493 } | 495 } |
| 494 | 496 |
| 495 /////////////////////////////////////////////////////////////////////////////// | 497 /////////////////////////////////////////////////////////////////////////////// |
| 496 | 498 |
| 497 GrMorphologyEffect::GrMorphologyEffect(GrTexture* texture, | 499 GrMorphologyEffect::GrMorphologyEffect(GrProcessorDataManager* procDataManager, |
| 500 GrTexture* texture, |
| 498 Direction direction, | 501 Direction direction, |
| 499 int radius, | 502 int radius, |
| 500 MorphologyType type) | 503 MorphologyType type) |
| 501 : Gr1DKernelEffect(texture, direction, radius) | 504 : INHERITED(procDataManager, texture, direction, radius) |
| 502 , fType(type), fUseRange(false) { | 505 , fType(type), fUseRange(false) { |
| 503 this->initClassID<GrMorphologyEffect>(); | 506 this->initClassID<GrMorphologyEffect>(); |
| 504 } | 507 } |
| 505 | 508 |
| 506 GrMorphologyEffect::GrMorphologyEffect(GrTexture* texture, | 509 GrMorphologyEffect::GrMorphologyEffect(GrProcessorDataManager* procDataManager, |
| 510 GrTexture* texture, |
| 507 Direction direction, | 511 Direction direction, |
| 508 int radius, | 512 int radius, |
| 509 MorphologyType type, | 513 MorphologyType type, |
| 510 float range[2]) | 514 float range[2]) |
| 511 : Gr1DKernelEffect(texture, direction, radius) | 515 : INHERITED(procDataManager, texture, direction, radius) |
| 512 , fType(type), fUseRange(true) { | 516 , fType(type), fUseRange(true) { |
| 513 this->initClassID<GrMorphologyEffect>(); | 517 this->initClassID<GrMorphologyEffect>(); |
| 514 fRange[0] = range[0]; | 518 fRange[0] = range[0]; |
| 515 fRange[1] = range[1]; | 519 fRange[1] = range[1]; |
| 516 } | 520 } |
| 517 | 521 |
| 518 GrMorphologyEffect::~GrMorphologyEffect() { | 522 GrMorphologyEffect::~GrMorphologyEffect() { |
| 519 } | 523 } |
| 520 | 524 |
| 521 void GrMorphologyEffect::getGLProcessorKey(const GrGLSLCaps& caps, GrProcessorKe
yBuilder* b) const { | 525 void GrMorphologyEffect::getGLProcessorKey(const GrGLSLCaps& caps, GrProcessorKe
yBuilder* b) const { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 545 | 549 |
| 546 GrFragmentProcessor* GrMorphologyEffect::TestCreate(GrProcessorTestData* d) { | 550 GrFragmentProcessor* GrMorphologyEffect::TestCreate(GrProcessorTestData* d) { |
| 547 int texIdx = d->fRandom->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx
: | 551 int texIdx = d->fRandom->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx
: |
| 548 GrProcessorUnitTest::kAlphaTextureIdx; | 552 GrProcessorUnitTest::kAlphaTextureIdx; |
| 549 Direction dir = d->fRandom->nextBool() ? kX_Direction : kY_Direction; | 553 Direction dir = d->fRandom->nextBool() ? kX_Direction : kY_Direction; |
| 550 static const int kMaxRadius = 10; | 554 static const int kMaxRadius = 10; |
| 551 int radius = d->fRandom->nextRangeU(1, kMaxRadius); | 555 int radius = d->fRandom->nextRangeU(1, kMaxRadius); |
| 552 MorphologyType type = d->fRandom->nextBool() ? GrMorphologyEffect::kErode_Mo
rphologyType : | 556 MorphologyType type = d->fRandom->nextBool() ? GrMorphologyEffect::kErode_Mo
rphologyType : |
| 553 GrMorphologyEffect::kDilate_Morph
ologyType; | 557 GrMorphologyEffect::kDilate_Morph
ologyType; |
| 554 | 558 |
| 555 return GrMorphologyEffect::Create(d->fTextures[texIdx], dir, radius, type); | 559 return GrMorphologyEffect::Create(d->fProcDataManager, d->fTextures[texIdx],
dir, radius, type); |
| 556 } | 560 } |
| 557 | 561 |
| 558 namespace { | 562 namespace { |
| 559 | 563 |
| 560 | 564 |
| 561 void apply_morphology_rect(GrDrawContext* drawContext, | 565 void apply_morphology_rect(GrDrawContext* drawContext, |
| 562 GrRenderTarget* rt, | 566 GrRenderTarget* rt, |
| 563 const GrClip& clip, | 567 const GrClip& clip, |
| 564 GrTexture* texture, | 568 GrTexture* texture, |
| 565 const SkIRect& srcRect, | 569 const SkIRect& srcRect, |
| 566 const SkIRect& dstRect, | 570 const SkIRect& dstRect, |
| 567 int radius, | 571 int radius, |
| 568 GrMorphologyEffect::MorphologyType morphType, | 572 GrMorphologyEffect::MorphologyType morphType, |
| 569 float bounds[2], | 573 float bounds[2], |
| 570 Gr1DKernelEffect::Direction direction) { | 574 Gr1DKernelEffect::Direction direction) { |
| 571 GrPaint paint; | 575 GrPaint paint; |
| 572 paint.addColorProcessor(GrMorphologyEffect::Create(texture, | 576 paint.addColorProcessor(GrMorphologyEffect::Create(paint.getProcessorDataMan
ager(), |
| 577 texture, |
| 573 direction, | 578 direction, |
| 574 radius, | 579 radius, |
| 575 morphType, | 580 morphType, |
| 576 bounds))->unref(); | 581 bounds))->unref(); |
| 577 drawContext->drawNonAARectToRect(rt, clip, paint, SkMatrix::I(), SkRect::Mak
e(dstRect), | 582 drawContext->drawNonAARectToRect(rt, clip, paint, SkMatrix::I(), SkRect::Mak
e(dstRect), |
| 578 SkRect::Make(srcRect)); | 583 SkRect::Make(srcRect)); |
| 579 } | 584 } |
| 580 | 585 |
| 581 void apply_morphology_rect_no_bounds(GrDrawContext* drawContext, | 586 void apply_morphology_rect_no_bounds(GrDrawContext* drawContext, |
| 582 GrRenderTarget* rt, | 587 GrRenderTarget* rt, |
| 583 const GrClip& clip, | 588 const GrClip& clip, |
| 584 GrTexture* texture, | 589 GrTexture* texture, |
| 585 const SkIRect& srcRect, | 590 const SkIRect& srcRect, |
| 586 const SkIRect& dstRect, | 591 const SkIRect& dstRect, |
| 587 int radius, | 592 int radius, |
| 588 GrMorphologyEffect::MorphologyType morphTyp
e, | 593 GrMorphologyEffect::MorphologyType morphTyp
e, |
| 589 Gr1DKernelEffect::Direction direction) { | 594 Gr1DKernelEffect::Direction direction) { |
| 590 GrPaint paint; | 595 GrPaint paint; |
| 591 paint.addColorProcessor(GrMorphologyEffect::Create(texture, | 596 paint.addColorProcessor(GrMorphologyEffect::Create(paint.getProcessorDataMan
ager(), |
| 597 texture, |
| 592 direction, | 598 direction, |
| 593 radius, | 599 radius, |
| 594 morphType))->unref(); | 600 morphType))->unref(); |
| 595 drawContext->drawNonAARectToRect(rt, clip, paint, SkMatrix::I(), SkRect::Mak
e(dstRect), | 601 drawContext->drawNonAARectToRect(rt, clip, paint, SkMatrix::I(), SkRect::Mak
e(dstRect), |
| 596 SkRect::Make(srcRect)); | 602 SkRect::Make(srcRect)); |
| 597 } | 603 } |
| 598 | 604 |
| 599 void apply_morphology_pass(GrDrawContext* drawContext, | 605 void apply_morphology_pass(GrDrawContext* drawContext, |
| 600 GrRenderTarget* rt, | 606 GrRenderTarget* rt, |
| 601 const GrClip& clip, | 607 const GrClip& clip, |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 752 SkBitmap* result, SkIPoint* offset) con
st { | 758 SkBitmap* result, SkIPoint* offset) con
st { |
| 753 return this->filterImageGPUGeneric(true, proxy, src, ctx, result, offset); | 759 return this->filterImageGPUGeneric(true, proxy, src, ctx, result, offset); |
| 754 } | 760 } |
| 755 | 761 |
| 756 bool SkErodeImageFilter::filterImageGPU(Proxy* proxy, const SkBitmap& src, const
Context& ctx, | 762 bool SkErodeImageFilter::filterImageGPU(Proxy* proxy, const SkBitmap& src, const
Context& ctx, |
| 757 SkBitmap* result, SkIPoint* offset) cons
t { | 763 SkBitmap* result, SkIPoint* offset) cons
t { |
| 758 return this->filterImageGPUGeneric(false, proxy, src, ctx, result, offset); | 764 return this->filterImageGPUGeneric(false, proxy, src, ctx, result, offset); |
| 759 } | 765 } |
| 760 | 766 |
| 761 #endif | 767 #endif |
| OLD | NEW |