| 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 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 340 | 340 |
| 341 typedef Gr1DKernelEffect INHERITED; | 341 typedef Gr1DKernelEffect INHERITED; |
| 342 }; | 342 }; |
| 343 | 343 |
| 344 /////////////////////////////////////////////////////////////////////////////// | 344 /////////////////////////////////////////////////////////////////////////////// |
| 345 | 345 |
| 346 class GrGLMorphologyEffect : public GrGLFragmentProcessor { | 346 class GrGLMorphologyEffect : public GrGLFragmentProcessor { |
| 347 public: | 347 public: |
| 348 GrGLMorphologyEffect(const GrProcessor&); | 348 GrGLMorphologyEffect(const GrProcessor&); |
| 349 | 349 |
| 350 virtual void emitCode(GrGLFPBuilder*, | 350 virtual void emitCode(EmitArgs&) override; |
| 351 const GrFragmentProcessor&, | |
| 352 const char* outputColor, | |
| 353 const char* inputColor, | |
| 354 const TransformedCoordsArray&, | |
| 355 const TextureSamplerArray&) override; | |
| 356 | 351 |
| 357 static inline void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessor
KeyBuilder* b); | 352 static inline void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessor
KeyBuilder* b); |
| 358 | 353 |
| 359 void setData(const GrGLProgramDataManager&, const GrProcessor&) override; | 354 void setData(const GrGLProgramDataManager&, const GrProcessor&) override; |
| 360 | 355 |
| 361 private: | 356 private: |
| 362 int width() const { return GrMorphologyEffect::WidthFromRadius(fRadius); } | 357 int width() const { return GrMorphologyEffect::WidthFromRadius(fRadius); } |
| 363 | 358 |
| 364 int fRadius; | 359 int fRadius; |
| 365 Gr1DKernelEffect::Direction fDirection; | 360 Gr1DKernelEffect::Direction fDirection; |
| 366 bool fUseRange; | 361 bool fUseRange; |
| 367 GrMorphologyEffect::MorphologyType fType; | 362 GrMorphologyEffect::MorphologyType fType; |
| 368 GrGLProgramDataManager::UniformHandle fPixelSizeUni; | 363 GrGLProgramDataManager::UniformHandle fPixelSizeUni; |
| 369 GrGLProgramDataManager::UniformHandle fRangeUni; | 364 GrGLProgramDataManager::UniformHandle fRangeUni; |
| 370 | 365 |
| 371 typedef GrGLFragmentProcessor INHERITED; | 366 typedef GrGLFragmentProcessor INHERITED; |
| 372 }; | 367 }; |
| 373 | 368 |
| 374 GrGLMorphologyEffect::GrGLMorphologyEffect(const GrProcessor& proc) { | 369 GrGLMorphologyEffect::GrGLMorphologyEffect(const GrProcessor& proc) { |
| 375 const GrMorphologyEffect& m = proc.cast<GrMorphologyEffect>(); | 370 const GrMorphologyEffect& m = proc.cast<GrMorphologyEffect>(); |
| 376 fRadius = m.radius(); | 371 fRadius = m.radius(); |
| 377 fDirection = m.direction(); | 372 fDirection = m.direction(); |
| 378 fUseRange = m.useRange(); | 373 fUseRange = m.useRange(); |
| 379 fType = m.type(); | 374 fType = m.type(); |
| 380 } | 375 } |
| 381 | 376 |
| 382 void GrGLMorphologyEffect::emitCode(GrGLFPBuilder* builder, | 377 void GrGLMorphologyEffect::emitCode(EmitArgs& args) { |
| 383 const GrFragmentProcessor&, | 378 fPixelSizeUni = args.fBuilder->addUniform(GrGLProgramBuilder::kFragment_Visi
bility, |
| 384 const char* outputColor, | |
| 385 const char* inputColor, | |
| 386 const TransformedCoordsArray& coords, | |
| 387 const TextureSamplerArray& samplers) { | |
| 388 fPixelSizeUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visibility
, | |
| 389 kFloat_GrSLType, kDefault_GrSLPrecis
ion, | 379 kFloat_GrSLType, kDefault_GrSLPrecis
ion, |
| 390 "PixelSize"); | 380 "PixelSize"); |
| 391 const char* pixelSizeInc = builder->getUniformCStr(fPixelSizeUni); | 381 const char* pixelSizeInc = args.fBuilder->getUniformCStr(fPixelSizeUni); |
| 392 fRangeUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visibility, | 382 fRangeUni = args.fBuilder->addUniform(GrGLProgramBuilder::kFragment_Visibili
ty, |
| 393 kVec2f_GrSLType, kDefault_GrSLPrecis
ion, | 383 kVec2f_GrSLType, kDefault_GrSLPrecis
ion, |
| 394 "Range"); | 384 "Range"); |
| 395 const char* range = builder->getUniformCStr(fRangeUni); | 385 const char* range = args.fBuilder->getUniformCStr(fRangeUni); |
| 396 | 386 |
| 397 GrGLFragmentBuilder* fsBuilder = builder->getFragmentShaderBuilder(); | 387 GrGLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder(); |
| 398 SkString coords2D = fsBuilder->ensureFSCoords2D(coords, 0); | 388 SkString coords2D = fsBuilder->ensureFSCoords2D(args.fCoords, 0); |
| 399 const char* func; | 389 const char* func; |
| 400 switch (fType) { | 390 switch (fType) { |
| 401 case GrMorphologyEffect::kErode_MorphologyType: | 391 case GrMorphologyEffect::kErode_MorphologyType: |
| 402 fsBuilder->codeAppendf("\t\t%s = vec4(1, 1, 1, 1);\n", outputColor); | 392 fsBuilder->codeAppendf("\t\t%s = vec4(1, 1, 1, 1);\n", args.fOutputC
olor); |
| 403 func = "min"; | 393 func = "min"; |
| 404 break; | 394 break; |
| 405 case GrMorphologyEffect::kDilate_MorphologyType: | 395 case GrMorphologyEffect::kDilate_MorphologyType: |
| 406 fsBuilder->codeAppendf("\t\t%s = vec4(0, 0, 0, 0);\n", outputColor); | 396 fsBuilder->codeAppendf("\t\t%s = vec4(0, 0, 0, 0);\n", args.fOutputC
olor); |
| 407 func = "max"; | 397 func = "max"; |
| 408 break; | 398 break; |
| 409 default: | 399 default: |
| 410 SkFAIL("Unexpected type"); | 400 SkFAIL("Unexpected type"); |
| 411 func = ""; // suppress warning | 401 func = ""; // suppress warning |
| 412 break; | 402 break; |
| 413 } | 403 } |
| 414 | 404 |
| 415 const char* dir; | 405 const char* dir; |
| 416 switch (fDirection) { | 406 switch (fDirection) { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 430 // coord.x -= radius * pixelSize; | 420 // coord.x -= radius * pixelSize; |
| 431 fsBuilder->codeAppendf("\t\tcoord.%s -= %d.0 * %s; \n", dir, fRadius, pixelS
izeInc); | 421 fsBuilder->codeAppendf("\t\tcoord.%s -= %d.0 * %s; \n", dir, fRadius, pixelS
izeInc); |
| 432 if (fUseRange) { | 422 if (fUseRange) { |
| 433 // highBound = min(highBound, coord.x + (width-1) * pixelSize); | 423 // highBound = min(highBound, coord.x + (width-1) * pixelSize); |
| 434 fsBuilder->codeAppendf("\t\tfloat highBound = min(%s.y, coord.%s + %f *
%s);", | 424 fsBuilder->codeAppendf("\t\tfloat highBound = min(%s.y, coord.%s + %f *
%s);", |
| 435 range, dir, float(width() - 1), pixelSizeInc); | 425 range, dir, float(width() - 1), pixelSizeInc); |
| 436 // coord.x = max(lowBound, coord.x); | 426 // coord.x = max(lowBound, coord.x); |
| 437 fsBuilder->codeAppendf("\t\tcoord.%s = max(%s.x, coord.%s);", dir, range
, dir); | 427 fsBuilder->codeAppendf("\t\tcoord.%s = max(%s.x, coord.%s);", dir, range
, dir); |
| 438 } | 428 } |
| 439 fsBuilder->codeAppendf("\t\tfor (int i = 0; i < %d; i++) {\n", width()); | 429 fsBuilder->codeAppendf("\t\tfor (int i = 0; i < %d; i++) {\n", width()); |
| 440 fsBuilder->codeAppendf("\t\t\t%s = %s(%s, ", outputColor, func, outputColor)
; | 430 fsBuilder->codeAppendf("\t\t\t%s = %s(%s, ", args.fOutputColor, func, args.f
OutputColor); |
| 441 fsBuilder->appendTextureLookup(samplers[0], "coord"); | 431 fsBuilder->appendTextureLookup(args.fSamplers[0], "coord"); |
| 442 fsBuilder->codeAppend(");\n"); | 432 fsBuilder->codeAppend(");\n"); |
| 443 // coord.x += pixelSize; | 433 // coord.x += pixelSize; |
| 444 fsBuilder->codeAppendf("\t\t\tcoord.%s += %s;\n", dir, pixelSizeInc); | 434 fsBuilder->codeAppendf("\t\t\tcoord.%s += %s;\n", dir, pixelSizeInc); |
| 445 if (fUseRange) { | 435 if (fUseRange) { |
| 446 // coord.x = min(highBound, coord.x); | 436 // coord.x = min(highBound, coord.x); |
| 447 fsBuilder->codeAppendf("\t\t\tcoord.%s = min(highBound, coord.%s);", dir
, dir); | 437 fsBuilder->codeAppendf("\t\t\tcoord.%s = min(highBound, coord.%s);", dir
, dir); |
| 448 } | 438 } |
| 449 fsBuilder->codeAppend("\t\t}\n"); | 439 fsBuilder->codeAppend("\t\t}\n"); |
| 450 SkString modulate; | 440 SkString modulate; |
| 451 GrGLSLMulVarBy4f(&modulate, outputColor, inputColor); | 441 GrGLSLMulVarBy4f(&modulate, args.fOutputColor, args.fInputColor); |
| 452 fsBuilder->codeAppend(modulate.c_str()); | 442 fsBuilder->codeAppend(modulate.c_str()); |
| 453 } | 443 } |
| 454 | 444 |
| 455 void GrGLMorphologyEffect::GenKey(const GrProcessor& proc, | 445 void GrGLMorphologyEffect::GenKey(const GrProcessor& proc, |
| 456 const GrGLSLCaps&, GrProcessorKeyBuilder* b) { | 446 const GrGLSLCaps&, GrProcessorKeyBuilder* b) { |
| 457 const GrMorphologyEffect& m = proc.cast<GrMorphologyEffect>(); | 447 const GrMorphologyEffect& m = proc.cast<GrMorphologyEffect>(); |
| 458 uint32_t key = static_cast<uint32_t>(m.radius()); | 448 uint32_t key = static_cast<uint32_t>(m.radius()); |
| 459 key |= (m.type() << 8); | 449 key |= (m.type() << 8); |
| 460 key |= (m.direction() << 9); | 450 key |= (m.direction() << 9); |
| 461 if (m.useRange()) key |= 1 << 10; | 451 if (m.useRange()) key |= 1 << 10; |
| (...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 758 SkBitmap* result, SkIPoint* offset) con
st { | 748 SkBitmap* result, SkIPoint* offset) con
st { |
| 759 return this->filterImageGPUGeneric(true, proxy, src, ctx, result, offset); | 749 return this->filterImageGPUGeneric(true, proxy, src, ctx, result, offset); |
| 760 } | 750 } |
| 761 | 751 |
| 762 bool SkErodeImageFilter::filterImageGPU(Proxy* proxy, const SkBitmap& src, const
Context& ctx, | 752 bool SkErodeImageFilter::filterImageGPU(Proxy* proxy, const SkBitmap& src, const
Context& ctx, |
| 763 SkBitmap* result, SkIPoint* offset) cons
t { | 753 SkBitmap* result, SkIPoint* offset) cons
t { |
| 764 return this->filterImageGPUGeneric(false, proxy, src, ctx, result, offset); | 754 return this->filterImageGPUGeneric(false, proxy, src, ctx, result, offset); |
| 765 } | 755 } |
| 766 | 756 |
| 767 #endif | 757 #endif |
| OLD | NEW |