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