diff options
author | 2012-08-03 18:12:20 +0000 | |
---|---|---|
committer | 2012-08-03 18:12:20 +0000 | |
commit | 0a7672f85ef7655b343679609d02018f83fcfc23 (patch) | |
tree | 182413e9da8c9e33040b7fd22bd0e5ec912a45bd /src/gpu/effects/GrMorphologyEffect.cpp | |
parent | a9e937c7b712b024de108fa963f92d0e70e4a296 (diff) |
Add morphology, convolution, single texture, texture domain effects to new unit test system
Review URL: http://codereview.appspot.com/6442085/
git-svn-id: http://skia.googlecode.com/svn/trunk@4951 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src/gpu/effects/GrMorphologyEffect.cpp')
-rw-r--r-- | src/gpu/effects/GrMorphologyEffect.cpp | 33 |
1 files changed, 22 insertions, 11 deletions
diff --git a/src/gpu/effects/GrMorphologyEffect.cpp b/src/gpu/effects/GrMorphologyEffect.cpp index be8485e554..a4c5ef9118 100644 --- a/src/gpu/effects/GrMorphologyEffect.cpp +++ b/src/gpu/effects/GrMorphologyEffect.cpp @@ -20,7 +20,7 @@ public: virtual void setupVariables(GrGLShaderBuilder* builder) SK_OVERRIDE; virtual void emitVS(GrGLShaderBuilder* state, - const char* vertexCoords) SK_OVERRIDE; + const char* vertexCoords) SK_OVERRIDE {}; virtual void emitFS(GrGLShaderBuilder* state, const char* outputColor, const char* inputColor, @@ -53,18 +53,10 @@ GrGLMorphologyEffect ::GrGLMorphologyEffect(const GrProgramStageFactory& factory } void GrGLMorphologyEffect::setupVariables(GrGLShaderBuilder* builder) { - fImageIncrementUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType | - GrGLShaderBuilder::kVertex_ShaderType, + fImageIncrementUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType, kVec2f_GrSLType, "ImageIncrement"); } -void GrGLMorphologyEffect::emitVS(GrGLShaderBuilder* builder, - const char* vertexCoords) { - SkString* code = &builder->fVSCode; - const char* imgInc = builder->getUniformCStr(fImageIncrementUni); - code->appendf("\t\t%s -= vec2(%d, %d) * %s;\n", vertexCoords, fRadius, fRadius, imgInc); -} - void GrGLMorphologyEffect ::emitFS(GrGLShaderBuilder* builder, const char* outputColor, const char* inputColor, @@ -88,7 +80,8 @@ void GrGLMorphologyEffect ::emitFS(GrGLShaderBuilder* builder, } const char* imgInc = builder->getUniformCStr(fImageIncrementUni); - code->appendf("\t\tvec2 coord = %s;\n", builder->fSampleCoords.c_str()); + code->appendf("\t\tvec2 coord = %s - %d * %s;\n", + builder->fSampleCoords.c_str(), fRadius, imgInc); code->appendf("\t\tfor (int i = 0; i < %d; i++) {\n", this->width()); code->appendf("\t\t\tvalue = %s(value, ", func); builder->emitTextureLookup(samplerName, "coord"); @@ -155,3 +148,21 @@ bool GrMorphologyEffect::isEqual(const GrCustomStage& sBase) const { this->direction() == s.direction() && this->type() == s.type()); } + +/////////////////////////////////////////////////////////////////////////////// + +GR_DEFINE_CUSTOM_STAGE_TEST(GrMorphologyEffect); + +GrCustomStage* GrMorphologyEffect::TestCreate(SkRandom* random, + GrContext* context, + GrTexture* textures[]) { + int texIdx = random->nextBool() ? GrCustomStageTestFactory::kSkiaPMTextureIdx : + GrCustomStageTestFactory::kAlphaTextureIdx; + Direction dir = random->nextBool() ? kX_Direction : kY_Direction; + static const int kMaxRadius = 10; + int radius = random->nextRangeU(1, kMaxRadius); + MorphologyType type = random->nextBool() ? GrContext::kErode_MorphologyType : + GrContext::kDilate_MorphologyType; + + return SkNEW_ARGS(GrMorphologyEffect, (textures[texIdx], dir, radius, type)); +} |