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 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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(GrTexture* tex, Direction dir, int radius
, |
302 MorphologyType type) { | 302 MorphologyType type) { |
303 return SkNEW_ARGS(GrMorphologyEffect, (tex, dir, radius, type)); | 303 return SkNEW_ARGS(GrMorphologyEffect, (tex, dir, radius, type)); |
304 } | 304 } |
305 | 305 |
306 static GrFragmentProcessor* Create(GrTexture* tex, Direction dir, int radius
, | |
307 MorphologyType type, float bounds[2]) { | |
308 return SkNEW_ARGS(GrMorphologyEffect, (tex, dir, radius, type, bounds)); | |
309 } | |
310 | |
311 virtual ~GrMorphologyEffect(); | 306 virtual ~GrMorphologyEffect(); |
312 | 307 |
313 MorphologyType type() const { return fType; } | 308 MorphologyType type() const { return fType; } |
314 bool useRange() const { return fUseRange; } | |
315 const float* range() const { return fRange; } | |
316 | 309 |
317 const char* name() const SK_OVERRIDE { return "Morphology"; } | 310 const char* name() const SK_OVERRIDE { return "Morphology"; } |
318 | 311 |
319 void getGLProcessorKey(const GrGLCaps&, GrProcessorKeyBuilder*) const SK_OVE
RRIDE; | 312 void getGLProcessorKey(const GrGLCaps&, GrProcessorKeyBuilder*) const SK_OVE
RRIDE; |
320 | 313 |
321 GrGLFragmentProcessor* createGLInstance() const SK_OVERRIDE; | 314 GrGLFragmentProcessor* createGLInstance() const SK_OVERRIDE; |
322 | 315 |
323 protected: | 316 protected: |
324 | 317 |
325 MorphologyType fType; | 318 MorphologyType fType; |
326 bool fUseRange; | |
327 float fRange[2]; | |
328 | 319 |
329 private: | 320 private: |
330 bool onIsEqual(const GrFragmentProcessor&) const SK_OVERRIDE; | 321 bool onIsEqual(const GrFragmentProcessor&) const SK_OVERRIDE; |
331 | 322 |
332 void onComputeInvariantOutput(GrInvariantOutput* inout) const SK_OVERRIDE; | 323 void onComputeInvariantOutput(GrInvariantOutput* inout) const SK_OVERRIDE; |
333 | 324 |
334 GrMorphologyEffect(GrTexture*, Direction, int radius, MorphologyType); | 325 GrMorphologyEffect(GrTexture*, Direction, int radius, MorphologyType); |
335 GrMorphologyEffect(GrTexture*, Direction, int radius, MorphologyType, float
bounds[2]); | |
336 | 326 |
337 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; | 327 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; |
338 | 328 |
339 typedef Gr1DKernelEffect INHERITED; | 329 typedef Gr1DKernelEffect INHERITED; |
340 }; | 330 }; |
341 | 331 |
342 /////////////////////////////////////////////////////////////////////////////// | 332 /////////////////////////////////////////////////////////////////////////////// |
343 | 333 |
344 class GrGLMorphologyEffect : public GrGLFragmentProcessor { | 334 class GrGLMorphologyEffect : public GrGLFragmentProcessor { |
345 public: | 335 public: |
346 GrGLMorphologyEffect(const GrProcessor&); | 336 GrGLMorphologyEffect(const GrProcessor&); |
347 | 337 |
348 virtual void emitCode(GrGLFPBuilder*, | 338 virtual void emitCode(GrGLFPBuilder*, |
349 const GrFragmentProcessor&, | 339 const GrFragmentProcessor&, |
350 const char* outputColor, | 340 const char* outputColor, |
351 const char* inputColor, | 341 const char* inputColor, |
352 const TransformedCoordsArray&, | 342 const TransformedCoordsArray&, |
353 const TextureSamplerArray&) SK_OVERRIDE; | 343 const TextureSamplerArray&) SK_OVERRIDE; |
354 | 344 |
355 static inline void GenKey(const GrProcessor&, const GrGLCaps&, GrProcessorKe
yBuilder* b); | 345 static inline void GenKey(const GrProcessor&, const GrGLCaps&, GrProcessorKe
yBuilder* b); |
356 | 346 |
357 void setData(const GrGLProgramDataManager&, const GrProcessor&) SK_OVERRIDE; | 347 void setData(const GrGLProgramDataManager&, const GrProcessor&) SK_OVERRIDE; |
358 | 348 |
359 private: | 349 private: |
360 int width() const { return GrMorphologyEffect::WidthFromRadius(fRadius); } | 350 int width() const { return GrMorphologyEffect::WidthFromRadius(fRadius); } |
361 | 351 |
362 int fRadius; | 352 int fRadius; |
363 Gr1DKernelEffect::Direction fDirection; | |
364 bool fUseRange; | |
365 GrMorphologyEffect::MorphologyType fType; | 353 GrMorphologyEffect::MorphologyType fType; |
366 GrGLProgramDataManager::UniformHandle fPixelSizeUni; | 354 GrGLProgramDataManager::UniformHandle fImageIncrementUni; |
367 GrGLProgramDataManager::UniformHandle fRangeUni; | |
368 | 355 |
369 typedef GrGLFragmentProcessor INHERITED; | 356 typedef GrGLFragmentProcessor INHERITED; |
370 }; | 357 }; |
371 | 358 |
372 GrGLMorphologyEffect::GrGLMorphologyEffect(const GrProcessor& proc) { | 359 GrGLMorphologyEffect::GrGLMorphologyEffect(const GrProcessor& proc) { |
373 const GrMorphologyEffect& m = proc.cast<GrMorphologyEffect>(); | 360 const GrMorphologyEffect& m = proc.cast<GrMorphologyEffect>(); |
374 fRadius = m.radius(); | 361 fRadius = m.radius(); |
375 fDirection = m.direction(); | |
376 fUseRange = m.useRange(); | |
377 fType = m.type(); | 362 fType = m.type(); |
378 } | 363 } |
379 | 364 |
380 void GrGLMorphologyEffect::emitCode(GrGLFPBuilder* builder, | 365 void GrGLMorphologyEffect::emitCode(GrGLFPBuilder* builder, |
381 const GrFragmentProcessor&, | 366 const GrFragmentProcessor&, |
382 const char* outputColor, | 367 const char* outputColor, |
383 const char* inputColor, | 368 const char* inputColor, |
384 const TransformedCoordsArray& coords, | 369 const TransformedCoordsArray& coords, |
385 const TextureSamplerArray& samplers) { | 370 const TextureSamplerArray& samplers) { |
386 fPixelSizeUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visibility
, | 371 fImageIncrementUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visib
ility, |
387 kFloat_GrSLType, kDefault_GrSLPrecis
ion, | 372 kVec2f_GrSLType, kDefault_GrSLPreci
sion, |
388 "PixelSize"); | 373 "ImageIncrement"); |
389 const char* pixelSizeInc = builder->getUniformCStr(fPixelSizeUni); | |
390 fRangeUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visibility, | |
391 kVec2f_GrSLType, kDefault_GrSLPrecis
ion, | |
392 "Range"); | |
393 const char* range = builder->getUniformCStr(fRangeUni); | |
394 | 374 |
395 GrGLFPFragmentBuilder* fsBuilder = builder->getFragmentShaderBuilder(); | 375 GrGLFPFragmentBuilder* fsBuilder = builder->getFragmentShaderBuilder(); |
396 SkString coords2D = fsBuilder->ensureFSCoords2D(coords, 0); | 376 SkString coords2D = fsBuilder->ensureFSCoords2D(coords, 0); |
397 const char* func; | 377 const char* func; |
398 switch (fType) { | 378 switch (fType) { |
399 case GrMorphologyEffect::kErode_MorphologyType: | 379 case GrMorphologyEffect::kErode_MorphologyType: |
400 fsBuilder->codeAppendf("\t\t%s = vec4(1, 1, 1, 1);\n", outputColor); | 380 fsBuilder->codeAppendf("\t\t%s = vec4(1, 1, 1, 1);\n", outputColor); |
401 func = "min"; | 381 func = "min"; |
402 break; | 382 break; |
403 case GrMorphologyEffect::kDilate_MorphologyType: | 383 case GrMorphologyEffect::kDilate_MorphologyType: |
404 fsBuilder->codeAppendf("\t\t%s = vec4(0, 0, 0, 0);\n", outputColor); | 384 fsBuilder->codeAppendf("\t\t%s = vec4(0, 0, 0, 0);\n", outputColor); |
405 func = "max"; | 385 func = "max"; |
406 break; | 386 break; |
407 default: | 387 default: |
408 SkFAIL("Unexpected type"); | 388 SkFAIL("Unexpected type"); |
409 func = ""; // suppress warning | 389 func = ""; // suppress warning |
410 break; | 390 break; |
411 } | 391 } |
| 392 const char* imgInc = builder->getUniformCStr(fImageIncrementUni); |
412 | 393 |
413 const char* dir; | 394 fsBuilder->codeAppendf("\t\tvec2 coord = %s - %d.0 * %s;\n", coords2D.c_str(
), fRadius, imgInc); |
414 switch (fDirection) { | 395 fsBuilder->codeAppendf("\t\tfor (int i = 0; i < %d; i++) {\n", this->width()
); |
415 case Gr1DKernelEffect::kX_Direction: | |
416 dir = "x"; | |
417 break; | |
418 case Gr1DKernelEffect::kY_Direction: | |
419 dir = "y"; | |
420 break; | |
421 default: | |
422 SkFAIL("Unknown filter direction."); | |
423 dir = ""; // suppress warning | |
424 } | |
425 | |
426 // vec2 coord = coord2D; | |
427 fsBuilder->codeAppendf("\t\tvec2 coord = %s;\n", coords2D.c_str()); | |
428 // coord.x -= radius * pixelSize; | |
429 fsBuilder->codeAppendf("\t\tcoord.%s -= %d.0 * %s; \n", dir, fRadius, pixelS
izeInc); | |
430 if (fUseRange) { | |
431 // highBound = min(highBound, coord.x + (width-1) * pixelSize); | |
432 fsBuilder->codeAppendf("\t\tfloat highBound = min(%s.y, coord.%s + %d *
%s);", | |
433 range, dir, width() - 1, pixelSizeInc); | |
434 // coord.x = max(lowBound, coord.x); | |
435 fsBuilder->codeAppendf("\t\tcoord.%s = max(%s.x, coord.%s);", dir, range
, dir); | |
436 } | |
437 fsBuilder->codeAppendf("\t\tfor (int i = 0; i < %d; i++) {\n", width()); | |
438 fsBuilder->codeAppendf("\t\t\t%s = %s(%s, ", outputColor, func, outputColor)
; | 396 fsBuilder->codeAppendf("\t\t\t%s = %s(%s, ", outputColor, func, outputColor)
; |
439 fsBuilder->appendTextureLookup(samplers[0], "coord"); | 397 fsBuilder->appendTextureLookup(samplers[0], "coord"); |
440 fsBuilder->codeAppend(");\n"); | 398 fsBuilder->codeAppend(");\n"); |
441 // coord.x += pixelSize; | 399 fsBuilder->codeAppendf("\t\t\tcoord += %s;\n", imgInc); |
442 fsBuilder->codeAppendf("\t\t\tcoord.%s += %s;\n", dir, pixelSizeInc); | |
443 if (fUseRange) { | |
444 // coord.x = min(highBound, coord.x); | |
445 fsBuilder->codeAppendf("\t\t\tcoord.%s = min(highBound, coord.%s);", dir
, dir); | |
446 } | |
447 fsBuilder->codeAppend("\t\t}\n"); | 400 fsBuilder->codeAppend("\t\t}\n"); |
448 SkString modulate; | 401 SkString modulate; |
449 GrGLSLMulVarBy4f(&modulate, outputColor, inputColor); | 402 GrGLSLMulVarBy4f(&modulate, outputColor, inputColor); |
450 fsBuilder->codeAppend(modulate.c_str()); | 403 fsBuilder->codeAppend(modulate.c_str()); |
451 } | 404 } |
452 | 405 |
453 void GrGLMorphologyEffect::GenKey(const GrProcessor& proc, | 406 void GrGLMorphologyEffect::GenKey(const GrProcessor& proc, |
454 const GrGLCaps&, GrProcessorKeyBuilder* b) { | 407 const GrGLCaps&, GrProcessorKeyBuilder* b) { |
455 const GrMorphologyEffect& m = proc.cast<GrMorphologyEffect>(); | 408 const GrMorphologyEffect& m = proc.cast<GrMorphologyEffect>(); |
456 uint32_t key = static_cast<uint32_t>(m.radius()); | 409 uint32_t key = static_cast<uint32_t>(m.radius()); |
457 key |= (m.type() << 8); | 410 key |= (m.type() << 8); |
458 key |= (m.direction() << 9); | |
459 if (m.useRange()) key |= 1 << 10; | |
460 b->add32(key); | 411 b->add32(key); |
461 } | 412 } |
462 | 413 |
463 void GrGLMorphologyEffect::setData(const GrGLProgramDataManager& pdman, | 414 void GrGLMorphologyEffect::setData(const GrGLProgramDataManager& pdman, |
464 const GrProcessor& proc) { | 415 const GrProcessor& proc) { |
465 const GrMorphologyEffect& m = proc.cast<GrMorphologyEffect>(); | 416 const Gr1DKernelEffect& kern = proc.cast<Gr1DKernelEffect>(); |
466 GrTexture& texture = *m.texture(0); | 417 GrTexture& texture = *kern.texture(0); |
467 // the code we generated was for a specific kernel radius, direction and bou
nd usage | 418 // the code we generated was for a specific kernel radius |
468 SkASSERT(m.radius() == fRadius); | 419 SkASSERT(kern.radius() == fRadius); |
469 SkASSERT(m.direction() == fDirection); | 420 float imageIncrement[2] = { 0 }; |
470 SkASSERT(m.useRange() == fUseRange); | 421 switch (kern.direction()) { |
471 | |
472 float pixelSize = 0.0f; | |
473 switch (fDirection) { | |
474 case Gr1DKernelEffect::kX_Direction: | 422 case Gr1DKernelEffect::kX_Direction: |
475 pixelSize = 1.0f / texture.width(); | 423 imageIncrement[0] = 1.0f / texture.width(); |
476 break; | 424 break; |
477 case Gr1DKernelEffect::kY_Direction: | 425 case Gr1DKernelEffect::kY_Direction: |
478 pixelSize = 1.0f / texture.height(); | 426 imageIncrement[1] = 1.0f / texture.height(); |
479 break; | 427 break; |
480 default: | 428 default: |
481 SkFAIL("Unknown filter direction."); | 429 SkFAIL("Unknown filter direction."); |
482 } | 430 } |
483 pdman.set1f(fPixelSizeUni, pixelSize); | 431 pdman.set2fv(fImageIncrementUni, 1, imageIncrement); |
484 | |
485 if (fUseRange) { | |
486 const float* range = m.range(); | |
487 if (fDirection && texture.origin() == kBottomLeft_GrSurfaceOrigin) { | |
488 pdman.set2f(fRangeUni, 1.0f - range[1], 1.0f - range[0]); | |
489 } else { | |
490 pdman.set2f(fRangeUni, range[0], range[1]); | |
491 } | |
492 } | |
493 } | 432 } |
494 | 433 |
495 /////////////////////////////////////////////////////////////////////////////// | 434 /////////////////////////////////////////////////////////////////////////////// |
496 | 435 |
497 GrMorphologyEffect::GrMorphologyEffect(GrTexture* texture, | 436 GrMorphologyEffect::GrMorphologyEffect(GrTexture* texture, |
498 Direction direction, | 437 Direction direction, |
499 int radius, | 438 int radius, |
500 MorphologyType type) | 439 MorphologyType type) |
501 : Gr1DKernelEffect(texture, direction, radius) | 440 : Gr1DKernelEffect(texture, direction, radius) |
502 , fType(type), fUseRange(false) { | 441 , fType(type) { |
503 this->initClassID<GrMorphologyEffect>(); | 442 this->initClassID<GrMorphologyEffect>(); |
504 } | 443 } |
505 | 444 |
506 GrMorphologyEffect::GrMorphologyEffect(GrTexture* texture, | |
507 Direction direction, | |
508 int radius, | |
509 MorphologyType type, | |
510 float range[2]) | |
511 : Gr1DKernelEffect(texture, direction, radius) | |
512 , fType(type), fUseRange(true) { | |
513 this->initClassID<GrMorphologyEffect>(); | |
514 fRange[0] = range[0]; | |
515 fRange[1] = range[1]; | |
516 } | |
517 | |
518 GrMorphologyEffect::~GrMorphologyEffect() { | 445 GrMorphologyEffect::~GrMorphologyEffect() { |
519 } | 446 } |
520 | 447 |
521 void GrMorphologyEffect::getGLProcessorKey(const GrGLCaps& caps, GrProcessorKeyB
uilder* b) const { | 448 void GrMorphologyEffect::getGLProcessorKey(const GrGLCaps& caps, GrProcessorKeyB
uilder* b) const { |
522 GrGLMorphologyEffect::GenKey(*this, caps, b); | 449 GrGLMorphologyEffect::GenKey(*this, caps, b); |
523 } | 450 } |
524 | 451 |
525 GrGLFragmentProcessor* GrMorphologyEffect::createGLInstance() const { | 452 GrGLFragmentProcessor* GrMorphologyEffect::createGLInstance() const { |
526 return SkNEW_ARGS(GrGLMorphologyEffect, (*this)); | 453 return SkNEW_ARGS(GrGLMorphologyEffect, (*this)); |
527 } | 454 } |
528 bool GrMorphologyEffect::onIsEqual(const GrFragmentProcessor& sBase) const { | 455 bool GrMorphologyEffect::onIsEqual(const GrFragmentProcessor& sBase) const { |
529 const GrMorphologyEffect& s = sBase.cast<GrMorphologyEffect>(); | 456 const GrMorphologyEffect& s = sBase.cast<GrMorphologyEffect>(); |
530 return (this->radius() == s.radius() && | 457 return (this->radius() == s.radius() && |
531 this->direction() == s.direction() && | 458 this->direction() == s.direction() && |
532 this->useRange() == s.useRange() && | |
533 this->type() == s.type()); | 459 this->type() == s.type()); |
534 } | 460 } |
535 | 461 |
536 void GrMorphologyEffect::onComputeInvariantOutput(GrInvariantOutput* inout) cons
t { | 462 void GrMorphologyEffect::onComputeInvariantOutput(GrInvariantOutput* inout) cons
t { |
537 // This is valid because the color components of the result of the kernel al
l come | 463 // This is valid because the color components of the result of the kernel al
l come |
538 // exactly from existing values in the source texture. | 464 // exactly from existing values in the source texture. |
539 this->updateInvariantOutputForModulation(inout); | 465 this->updateInvariantOutputForModulation(inout); |
540 } | 466 } |
541 | 467 |
542 /////////////////////////////////////////////////////////////////////////////// | 468 /////////////////////////////////////////////////////////////////////////////// |
(...skipping 10 matching lines...) Expand all Loading... |
553 static const int kMaxRadius = 10; | 479 static const int kMaxRadius = 10; |
554 int radius = random->nextRangeU(1, kMaxRadius); | 480 int radius = random->nextRangeU(1, kMaxRadius); |
555 MorphologyType type = random->nextBool() ? GrMorphologyEffect::kErode_Morpho
logyType : | 481 MorphologyType type = random->nextBool() ? GrMorphologyEffect::kErode_Morpho
logyType : |
556 GrMorphologyEffect::kDilate_Morph
ologyType; | 482 GrMorphologyEffect::kDilate_Morph
ologyType; |
557 | 483 |
558 return GrMorphologyEffect::Create(textures[texIdx], dir, radius, type); | 484 return GrMorphologyEffect::Create(textures[texIdx], dir, radius, type); |
559 } | 485 } |
560 | 486 |
561 namespace { | 487 namespace { |
562 | 488 |
563 | 489 void apply_morphology_pass(GrContext* context, |
564 void apply_morphology_rect(GrContext* context, | |
565 GrTexture* texture, | 490 GrTexture* texture, |
566 const SkIRect& srcRect, | 491 const SkIRect& srcRect, |
567 const SkIRect& dstRect, | 492 const SkIRect& dstRect, |
568 int radius, | |
569 GrMorphologyEffect::MorphologyType morphType, | |
570 float bounds[2], | |
571 Gr1DKernelEffect::Direction direction) { | |
572 GrPaint paint; | |
573 paint.addColorProcessor(GrMorphologyEffect::Create(texture, | |
574 direction, | |
575 radius, | |
576 morphType, | |
577 bounds))->unref(); | |
578 context->drawNonAARectToRect(paint, SkMatrix::I(), SkRect::Make(dstRect), | |
579 SkRect::Make(srcRect)); | |
580 } | |
581 | |
582 void apply_morphology_rect_no_bounds(GrContext* context, | |
583 GrTexture* texture, | |
584 const SkIRect& srcRect, | |
585 const SkIRect& dstRect, | |
586 int radius, | 493 int radius, |
587 GrMorphologyEffect::MorphologyType morphType, | 494 GrMorphologyEffect::MorphologyType morphType, |
588 Gr1DKernelEffect::Direction direction) { | 495 Gr1DKernelEffect::Direction direction) { |
589 GrPaint paint; | 496 GrPaint paint; |
590 paint.addColorProcessor(GrMorphologyEffect::Create(texture, | 497 paint.addColorProcessor(GrMorphologyEffect::Create(texture, |
591 direction, | 498 direction, |
592 radius, | 499 radius, |
593 morphType))->unref(); | 500 morphType))->unref(); |
594 context->drawNonAARectToRect(paint, SkMatrix::I(), SkRect::Make(dstRect), | 501 context->drawNonAARectToRect(paint, SkMatrix::I(), SkRect::Make(dstRect), |
595 SkRect::Make(srcRect)); | 502 SkRect::Make(srcRect)); |
596 } | 503 } |
597 | 504 |
598 void apply_morphology_pass(GrContext* context, | |
599 GrTexture* texture, | |
600 const SkIRect& srcRect, | |
601 const SkIRect& dstRect, | |
602 int radius, | |
603 GrMorphologyEffect::MorphologyType morphType, | |
604 Gr1DKernelEffect::Direction direction) { | |
605 float bounds[2] = { 0.0f, 1.0f }; | |
606 SkIRect lowerSrcRect = srcRect, lowerDstRect = dstRect; | |
607 SkIRect middleSrcRect = srcRect, middleDstRect = dstRect; | |
608 SkIRect upperSrcRect = srcRect, upperDstRect = dstRect; | |
609 if (direction == Gr1DKernelEffect::kX_Direction) { | |
610 bounds[0] = (SkIntToScalar(srcRect.left()) + 0.5f) / texture->width(); | |
611 bounds[1] = (SkIntToScalar(srcRect.right()) - 0.5f) / texture->width(); | |
612 lowerSrcRect.fRight = srcRect.left() + radius; | |
613 lowerDstRect.fRight = dstRect.left() + radius; | |
614 upperSrcRect.fLeft = srcRect.right() - radius; | |
615 upperDstRect.fLeft = dstRect.right() - radius; | |
616 middleSrcRect.inset(radius, 0); | |
617 middleDstRect.inset(radius, 0); | |
618 } else { | |
619 bounds[0] = (SkIntToScalar(srcRect.top()) + 0.5f) / texture->height(); | |
620 bounds[1] = (SkIntToScalar(srcRect.bottom()) - 0.5f) / texture->height()
; | |
621 lowerSrcRect.fBottom = srcRect.top() + radius; | |
622 lowerDstRect.fBottom = dstRect.top() + radius; | |
623 upperSrcRect.fTop = srcRect.bottom() - radius; | |
624 upperDstRect.fTop = dstRect.bottom() - radius; | |
625 middleSrcRect.inset(0, radius); | |
626 middleDstRect.inset(0, radius); | |
627 } | |
628 if (middleSrcRect.fLeft - middleSrcRect.fRight >= 0) { | |
629 // radius covers srcRect; use bounds over entire draw | |
630 apply_morphology_rect(context, texture, srcRect, dstRect, radius, | |
631 morphType, bounds, direction); | |
632 } else { | |
633 // Draw upper and lower margins with bounds; middle without. | |
634 apply_morphology_rect(context, texture, lowerSrcRect, lowerDstRect, radi
us, | |
635 morphType, bounds, direction); | |
636 apply_morphology_rect(context, texture, upperSrcRect, upperDstRect, radi
us, | |
637 morphType, bounds, direction); | |
638 apply_morphology_rect_no_bounds(context, texture, middleSrcRect, middleD
stRect, radius, | |
639 morphType, direction); | |
640 } | |
641 } | |
642 | |
643 bool apply_morphology(const SkBitmap& input, | 505 bool apply_morphology(const SkBitmap& input, |
644 const SkIRect& rect, | 506 const SkIRect& rect, |
645 GrMorphologyEffect::MorphologyType morphType, | 507 GrMorphologyEffect::MorphologyType morphType, |
646 SkISize radius, | 508 SkISize radius, |
647 SkBitmap* dst) { | 509 SkBitmap* dst) { |
648 SkAutoTUnref<GrTexture> srcTexture(SkRef(input.getTexture())); | 510 SkAutoTUnref<GrTexture> srcTexture(SkRef(input.getTexture())); |
649 SkASSERT(srcTexture); | 511 SkASSERT(srcTexture); |
650 GrContext* context = srcTexture->getContext(); | 512 GrContext* context = srcTexture->getContext(); |
651 | 513 |
652 GrContext::AutoClip acs(context, SkRect::MakeWH(SkIntToScalar(srcTexture->wi
dth()), | 514 GrContext::AutoClip acs(context, SkRect::MakeWH(SkIntToScalar(srcTexture->wi
dth()), |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
741 SkBitmap* result, SkIPoint* offset) con
st { | 603 SkBitmap* result, SkIPoint* offset) con
st { |
742 return this->filterImageGPUGeneric(true, proxy, src, ctx, result, offset); | 604 return this->filterImageGPUGeneric(true, proxy, src, ctx, result, offset); |
743 } | 605 } |
744 | 606 |
745 bool SkErodeImageFilter::filterImageGPU(Proxy* proxy, const SkBitmap& src, const
Context& ctx, | 607 bool SkErodeImageFilter::filterImageGPU(Proxy* proxy, const SkBitmap& src, const
Context& ctx, |
746 SkBitmap* result, SkIPoint* offset) cons
t { | 608 SkBitmap* result, SkIPoint* offset) cons
t { |
747 return this->filterImageGPUGeneric(false, proxy, src, ctx, result, offset); | 609 return this->filterImageGPUGeneric(false, proxy, src, ctx, result, offset); |
748 } | 610 } |
749 | 611 |
750 #endif | 612 #endif |
OLD | NEW |