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 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 */ | 198 */ |
199 class GrMorphologyEffect : public Gr1DKernelEffect { | 199 class GrMorphologyEffect : public Gr1DKernelEffect { |
200 | 200 |
201 public: | 201 public: |
202 | 202 |
203 enum MorphologyType { | 203 enum MorphologyType { |
204 kErode_MorphologyType, | 204 kErode_MorphologyType, |
205 kDilate_MorphologyType, | 205 kDilate_MorphologyType, |
206 }; | 206 }; |
207 | 207 |
208 static GrFragmentProcessor* Create(GrProcessorDataManager* procDataManager,
GrTexture* tex, | 208 static GrFragmentProcessor* Create(GrTexture* tex, Direction dir, int radius
, |
209 Direction dir, int radius, MorphologyType
type) { | 209 MorphologyType type) { |
210 return new GrMorphologyEffect(procDataManager, tex, dir, radius, type); | 210 return new GrMorphologyEffect(tex, dir, radius, type); |
211 } | 211 } |
212 | 212 |
213 static GrFragmentProcessor* Create(GrProcessorDataManager* procDataManager,
GrTexture* tex, | 213 static GrFragmentProcessor* Create(GrTexture* tex, Direction dir, int radius
, |
214 Direction dir, int radius, MorphologyType
type, | 214 MorphologyType type, float bounds[2]) { |
215 float bounds[2]) { | 215 return new GrMorphologyEffect(tex, dir, radius, type, bounds); |
216 return new GrMorphologyEffect(procDataManager, tex, dir, radius, type, b
ounds); | |
217 } | 216 } |
218 | 217 |
219 virtual ~GrMorphologyEffect(); | 218 virtual ~GrMorphologyEffect(); |
220 | 219 |
221 MorphologyType type() const { return fType; } | 220 MorphologyType type() const { return fType; } |
222 bool useRange() const { return fUseRange; } | 221 bool useRange() const { return fUseRange; } |
223 const float* range() const { return fRange; } | 222 const float* range() const { return fRange; } |
224 | 223 |
225 const char* name() const override { return "Morphology"; } | 224 const char* name() const override { return "Morphology"; } |
226 | 225 |
227 protected: | 226 protected: |
228 | 227 |
229 MorphologyType fType; | 228 MorphologyType fType; |
230 bool fUseRange; | 229 bool fUseRange; |
231 float fRange[2]; | 230 float fRange[2]; |
232 | 231 |
233 private: | 232 private: |
234 GrGLFragmentProcessor* onCreateGLInstance() const override; | 233 GrGLFragmentProcessor* onCreateGLInstance() const override; |
235 | 234 |
236 void onGetGLProcessorKey(const GrGLSLCaps&, GrProcessorKeyBuilder*) const ov
erride; | 235 void onGetGLProcessorKey(const GrGLSLCaps&, GrProcessorKeyBuilder*) const ov
erride; |
237 | 236 |
238 bool onIsEqual(const GrFragmentProcessor&) const override; | 237 bool onIsEqual(const GrFragmentProcessor&) const override; |
239 | 238 |
240 void onComputeInvariantOutput(GrInvariantOutput* inout) const override; | 239 void onComputeInvariantOutput(GrInvariantOutput* inout) const override; |
241 | 240 |
242 GrMorphologyEffect(GrProcessorDataManager*, GrTexture*, Direction, int radiu
s, MorphologyType); | 241 GrMorphologyEffect(GrTexture*, Direction, int radius, MorphologyType); |
243 GrMorphologyEffect(GrProcessorDataManager*, GrTexture*, Direction, int radiu
s, MorphologyType, | 242 GrMorphologyEffect(GrTexture*, Direction, int radius, MorphologyType, |
244 float bounds[2]); | 243 float bounds[2]); |
245 | 244 |
246 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; | 245 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; |
247 | 246 |
248 typedef Gr1DKernelEffect INHERITED; | 247 typedef Gr1DKernelEffect INHERITED; |
249 }; | 248 }; |
250 | 249 |
251 /////////////////////////////////////////////////////////////////////////////// | 250 /////////////////////////////////////////////////////////////////////////////// |
252 | 251 |
253 class GrGLMorphologyEffect : public GrGLFragmentProcessor { | 252 class GrGLMorphologyEffect : public GrGLFragmentProcessor { |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
387 if (fDirection && texture.origin() == kBottomLeft_GrSurfaceOrigin) { | 386 if (fDirection && texture.origin() == kBottomLeft_GrSurfaceOrigin) { |
388 pdman.set2f(fRangeUni, 1.0f - range[1], 1.0f - range[0]); | 387 pdman.set2f(fRangeUni, 1.0f - range[1], 1.0f - range[0]); |
389 } else { | 388 } else { |
390 pdman.set2f(fRangeUni, range[0], range[1]); | 389 pdman.set2f(fRangeUni, range[0], range[1]); |
391 } | 390 } |
392 } | 391 } |
393 } | 392 } |
394 | 393 |
395 /////////////////////////////////////////////////////////////////////////////// | 394 /////////////////////////////////////////////////////////////////////////////// |
396 | 395 |
397 GrMorphologyEffect::GrMorphologyEffect(GrProcessorDataManager* procDataManager, | 396 GrMorphologyEffect::GrMorphologyEffect(GrTexture* texture, |
398 GrTexture* texture, | |
399 Direction direction, | 397 Direction direction, |
400 int radius, | 398 int radius, |
401 MorphologyType type) | 399 MorphologyType type) |
402 : INHERITED(procDataManager, texture, direction, radius) | 400 : INHERITED(texture, direction, radius) |
403 , fType(type), fUseRange(false) { | 401 , fType(type), fUseRange(false) { |
404 this->initClassID<GrMorphologyEffect>(); | 402 this->initClassID<GrMorphologyEffect>(); |
405 } | 403 } |
406 | 404 |
407 GrMorphologyEffect::GrMorphologyEffect(GrProcessorDataManager* procDataManager, | 405 GrMorphologyEffect::GrMorphologyEffect(GrTexture* texture, |
408 GrTexture* texture, | |
409 Direction direction, | 406 Direction direction, |
410 int radius, | 407 int radius, |
411 MorphologyType type, | 408 MorphologyType type, |
412 float range[2]) | 409 float range[2]) |
413 : INHERITED(procDataManager, texture, direction, radius) | 410 : INHERITED(texture, direction, radius) |
414 , fType(type), fUseRange(true) { | 411 , fType(type), fUseRange(true) { |
415 this->initClassID<GrMorphologyEffect>(); | 412 this->initClassID<GrMorphologyEffect>(); |
416 fRange[0] = range[0]; | 413 fRange[0] = range[0]; |
417 fRange[1] = range[1]; | 414 fRange[1] = range[1]; |
418 } | 415 } |
419 | 416 |
420 GrMorphologyEffect::~GrMorphologyEffect() { | 417 GrMorphologyEffect::~GrMorphologyEffect() { |
421 } | 418 } |
422 | 419 |
423 void GrMorphologyEffect::onGetGLProcessorKey(const GrGLSLCaps& caps, GrProcessor
KeyBuilder* b) const { | 420 void GrMorphologyEffect::onGetGLProcessorKey(const GrGLSLCaps& caps, GrProcessor
KeyBuilder* b) const { |
(...skipping 23 matching lines...) Expand all Loading... |
447 | 444 |
448 const GrFragmentProcessor* GrMorphologyEffect::TestCreate(GrProcessorTestData* d
) { | 445 const GrFragmentProcessor* GrMorphologyEffect::TestCreate(GrProcessorTestData* d
) { |
449 int texIdx = d->fRandom->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx
: | 446 int texIdx = d->fRandom->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx
: |
450 GrProcessorUnitTest::kAlphaTextureIdx; | 447 GrProcessorUnitTest::kAlphaTextureIdx; |
451 Direction dir = d->fRandom->nextBool() ? kX_Direction : kY_Direction; | 448 Direction dir = d->fRandom->nextBool() ? kX_Direction : kY_Direction; |
452 static const int kMaxRadius = 10; | 449 static const int kMaxRadius = 10; |
453 int radius = d->fRandom->nextRangeU(1, kMaxRadius); | 450 int radius = d->fRandom->nextRangeU(1, kMaxRadius); |
454 MorphologyType type = d->fRandom->nextBool() ? GrMorphologyEffect::kErode_Mo
rphologyType : | 451 MorphologyType type = d->fRandom->nextBool() ? GrMorphologyEffect::kErode_Mo
rphologyType : |
455 GrMorphologyEffect::kDilate_Morph
ologyType; | 452 GrMorphologyEffect::kDilate_Morph
ologyType; |
456 | 453 |
457 return GrMorphologyEffect::Create(d->fProcDataManager, d->fTextures[texIdx],
dir, radius, type); | 454 return GrMorphologyEffect::Create(d->fTextures[texIdx], dir, radius, type); |
458 } | 455 } |
459 | 456 |
460 namespace { | 457 namespace { |
461 | 458 |
462 | 459 |
463 void apply_morphology_rect(GrDrawContext* drawContext, | 460 void apply_morphology_rect(GrDrawContext* drawContext, |
464 GrRenderTarget* rt, | 461 GrRenderTarget* rt, |
465 const GrClip& clip, | 462 const GrClip& clip, |
466 GrTexture* texture, | 463 GrTexture* texture, |
467 const SkIRect& srcRect, | 464 const SkIRect& srcRect, |
468 const SkIRect& dstRect, | 465 const SkIRect& dstRect, |
469 int radius, | 466 int radius, |
470 GrMorphologyEffect::MorphologyType morphType, | 467 GrMorphologyEffect::MorphologyType morphType, |
471 float bounds[2], | 468 float bounds[2], |
472 Gr1DKernelEffect::Direction direction) { | 469 Gr1DKernelEffect::Direction direction) { |
473 GrPaint paint; | 470 GrPaint paint; |
474 paint.addColorFragmentProcessor(GrMorphologyEffect::Create(paint.getProcesso
rDataManager(), | 471 paint.addColorFragmentProcessor(GrMorphologyEffect::Create(texture, |
475 texture, | |
476 direction, | 472 direction, |
477 radius, | 473 radius, |
478 morphType, | 474 morphType, |
479 bounds))->unref()
; | 475 bounds))->unref()
; |
480 drawContext->drawNonAARectToRect(rt, clip, paint, SkMatrix::I(), SkRect::Mak
e(dstRect), | 476 drawContext->drawNonAARectToRect(rt, clip, paint, SkMatrix::I(), SkRect::Mak
e(dstRect), |
481 SkRect::Make(srcRect)); | 477 SkRect::Make(srcRect)); |
482 } | 478 } |
483 | 479 |
484 void apply_morphology_rect_no_bounds(GrDrawContext* drawContext, | 480 void apply_morphology_rect_no_bounds(GrDrawContext* drawContext, |
485 GrRenderTarget* rt, | 481 GrRenderTarget* rt, |
486 const GrClip& clip, | 482 const GrClip& clip, |
487 GrTexture* texture, | 483 GrTexture* texture, |
488 const SkIRect& srcRect, | 484 const SkIRect& srcRect, |
489 const SkIRect& dstRect, | 485 const SkIRect& dstRect, |
490 int radius, | 486 int radius, |
491 GrMorphologyEffect::MorphologyType morphTyp
e, | 487 GrMorphologyEffect::MorphologyType morphTyp
e, |
492 Gr1DKernelEffect::Direction direction) { | 488 Gr1DKernelEffect::Direction direction) { |
493 GrPaint paint; | 489 GrPaint paint; |
494 paint.addColorFragmentProcessor(GrMorphologyEffect::Create(paint.getProcesso
rDataManager(), | 490 paint.addColorFragmentProcessor(GrMorphologyEffect::Create(texture, |
495 texture, | |
496 direction, | 491 direction, |
497 radius, | 492 radius, |
498 morphType))->unre
f(); | 493 morphType))->unre
f(); |
499 drawContext->drawNonAARectToRect(rt, clip, paint, SkMatrix::I(), SkRect::Mak
e(dstRect), | 494 drawContext->drawNonAARectToRect(rt, clip, paint, SkMatrix::I(), SkRect::Mak
e(dstRect), |
500 SkRect::Make(srcRect)); | 495 SkRect::Make(srcRect)); |
501 } | 496 } |
502 | 497 |
503 void apply_morphology_pass(GrDrawContext* drawContext, | 498 void apply_morphology_pass(GrDrawContext* drawContext, |
504 GrRenderTarget* rt, | 499 GrRenderTarget* rt, |
505 const GrClip& clip, | 500 const GrClip& clip, |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
662 SkBitmap* result, SkIPoint* offset) con
st { | 657 SkBitmap* result, SkIPoint* offset) con
st { |
663 return this->filterImageGPUGeneric(true, proxy, src, ctx, result, offset); | 658 return this->filterImageGPUGeneric(true, proxy, src, ctx, result, offset); |
664 } | 659 } |
665 | 660 |
666 bool SkErodeImageFilter::filterImageGPU(Proxy* proxy, const SkBitmap& src, const
Context& ctx, | 661 bool SkErodeImageFilter::filterImageGPU(Proxy* proxy, const SkBitmap& src, const
Context& ctx, |
667 SkBitmap* result, SkIPoint* offset) cons
t { | 662 SkBitmap* result, SkIPoint* offset) cons
t { |
668 return this->filterImageGPUGeneric(false, proxy, src, ctx, result, offset); | 663 return this->filterImageGPUGeneric(false, proxy, src, ctx, result, offset); |
669 } | 664 } |
670 | 665 |
671 #endif | 666 #endif |
OLD | NEW |