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