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