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 | |
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')
-rw-r--r-- | src/gpu/effects/GrColorTableEffect.cpp | 10 | ||||
-rw-r--r-- | src/gpu/effects/GrColorTableEffect.h | 1 | ||||
-rw-r--r-- | src/gpu/effects/GrConvolutionEffect.cpp | 38 | ||||
-rw-r--r-- | src/gpu/effects/GrConvolutionEffect.h | 1 | ||||
-rw-r--r-- | src/gpu/effects/GrMorphologyEffect.cpp | 33 | ||||
-rw-r--r-- | src/gpu/effects/GrMorphologyEffect.h | 1 | ||||
-rw-r--r-- | src/gpu/effects/GrSingleTextureEffect.cpp | 12 | ||||
-rw-r--r-- | src/gpu/effects/GrSingleTextureEffect.h | 2 | ||||
-rw-r--r-- | src/gpu/effects/GrTextureDomainEffect.cpp | 17 | ||||
-rw-r--r-- | src/gpu/effects/GrTextureDomainEffect.h | 1 |
10 files changed, 93 insertions, 23 deletions
diff --git a/src/gpu/effects/GrColorTableEffect.cpp b/src/gpu/effects/GrColorTableEffect.cpp index 94eb8fdd74..c6ce5599e4 100644 --- a/src/gpu/effects/GrColorTableEffect.cpp +++ b/src/gpu/effects/GrColorTableEffect.cpp @@ -124,3 +124,13 @@ const GrTextureAccess* GrColorTableEffect::textureAccess(unsigned int index) con return NULL; } + +/////////////////////////////////////////////////////////////////////////////// + +GR_DEFINE_CUSTOM_STAGE_TEST(GrColorTableEffect); + +GrCustomStage* GrColorTableEffect::TestCreate(SkRandom* random, + GrContext* context, + GrTexture* textures[]) { + return SkNEW_ARGS(GrColorTableEffect, (textures[GrCustomStageTestFactory::kAlphaTextureIdx])); +} diff --git a/src/gpu/effects/GrColorTableEffect.h b/src/gpu/effects/GrColorTableEffect.h index 16d76ade7f..de86768ca3 100644 --- a/src/gpu/effects/GrColorTableEffect.h +++ b/src/gpu/effects/GrColorTableEffect.h @@ -34,6 +34,7 @@ public: typedef GrGLColorTableEffect GLProgramStage; private: + GR_DECLARE_CUSTOM_STAGE_TEST; GrTextureAccess fTextureAccess; diff --git a/src/gpu/effects/GrConvolutionEffect.cpp b/src/gpu/effects/GrConvolutionEffect.cpp index 5cce800b51..a28d44d76b 100644 --- a/src/gpu/effects/GrConvolutionEffect.cpp +++ b/src/gpu/effects/GrConvolutionEffect.cpp @@ -22,7 +22,7 @@ public: virtual void setupVariables(GrGLShaderBuilder* builder) SK_OVERRIDE; virtual void emitVS(GrGLShaderBuilder* builder, - const char* vertexCoords) SK_OVERRIDE; + const char* vertexCoords) SK_OVERRIDE {}; virtual void emitFS(GrGLShaderBuilder* builder, const char* outputColor, const char* inputColor, @@ -56,20 +56,12 @@ GrGLConvolutionEffect::GrGLConvolutionEffect(const GrProgramStageFactory& factor } void GrGLConvolutionEffect::setupVariables(GrGLShaderBuilder* builder) { - fImageIncrementUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType | - GrGLShaderBuilder::kVertex_ShaderType, + fImageIncrementUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType, kVec2f_GrSLType, "ImageIncrement"); fKernelUni = builder->addUniformArray(GrGLShaderBuilder::kFragment_ShaderType, kFloat_GrSLType, "Kernel", this->width()); } -void GrGLConvolutionEffect::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 GrGLConvolutionEffect::emitFS(GrGLShaderBuilder* builder, const char* outputColor, const char* inputColor, @@ -77,12 +69,14 @@ void GrGLConvolutionEffect::emitFS(GrGLShaderBuilder* builder, SkString* code = &builder->fFSCode; code->appendf("\t\t%s = vec4(0, 0, 0, 0);\n", outputColor); - - code->appendf("\t\tvec2 coord = %s;\n", builder->fSampleCoords.c_str()); int width = this ->width(); const GrGLShaderVar& kernel = builder->getUniformVariable(fKernelUni); const char* imgInc = builder->getUniformCStr(fImageIncrementUni); + + code->appendf("\t\tvec2 coord = %s - %d * %s;\n", + builder->fSampleCoords.c_str(), fRadius, imgInc); + // Manually unroll loop because some drivers don't; yields 20-30% speedup. for (int i = 0; i < width; i++) { SkString index; @@ -185,3 +179,23 @@ bool GrConvolutionEffect::isEqual(const GrCustomStage& sBase) const { this->direction() == s.direction() && 0 == memcmp(fKernel, s.fKernel, this->width() * sizeof(float))); } + +/////////////////////////////////////////////////////////////////////////////// + +GR_DEFINE_CUSTOM_STAGE_TEST(GrConvolutionEffect); + +GrCustomStage* GrConvolutionEffect::TestCreate(SkRandom* random, + GrContext* context, + GrTexture* textures[]) { + int texIdx = random->nextBool() ? GrCustomStageTestFactory::kSkiaPMTextureIdx : + GrCustomStageTestFactory::kAlphaTextureIdx; + Direction dir = random->nextBool() ? kX_Direction : kY_Direction; + int radius = random->nextRangeU(1, kMaxKernelRadius); + float kernel[kMaxKernelRadius]; + for (int i = 0; i < kMaxKernelRadius; ++i) { + kernel[i] = random->nextSScalar1(); + } + + return SkNEW_ARGS(GrConvolutionEffect, (textures[texIdx], dir, radius, kernel)); +} + diff --git a/src/gpu/effects/GrConvolutionEffect.h b/src/gpu/effects/GrConvolutionEffect.h index e04e802666..21c022d85f 100644 --- a/src/gpu/effects/GrConvolutionEffect.h +++ b/src/gpu/effects/GrConvolutionEffect.h @@ -55,6 +55,7 @@ protected: float fKernel[kMaxKernelWidth]; private: + GR_DECLARE_CUSTOM_STAGE_TEST; typedef Gr1DKernelEffect INHERITED; }; 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)); +} diff --git a/src/gpu/effects/GrMorphologyEffect.h b/src/gpu/effects/GrMorphologyEffect.h index c8bd2d51db..bb65de73c6 100644 --- a/src/gpu/effects/GrMorphologyEffect.h +++ b/src/gpu/effects/GrMorphologyEffect.h @@ -42,6 +42,7 @@ protected: MorphologyType fType; private: + GR_DECLARE_CUSTOM_STAGE_TEST; typedef Gr1DKernelEffect INHERITED; }; diff --git a/src/gpu/effects/GrSingleTextureEffect.cpp b/src/gpu/effects/GrSingleTextureEffect.cpp index 5f66e09805..ebd09130c0 100644 --- a/src/gpu/effects/GrSingleTextureEffect.cpp +++ b/src/gpu/effects/GrSingleTextureEffect.cpp @@ -56,3 +56,15 @@ GrTexture* GrSingleTextureEffect::texture(unsigned int index) const { const GrProgramStageFactory& GrSingleTextureEffect::getFactory() const { return GrTProgramStageFactory<GrSingleTextureEffect>::getInstance(); } + +/////////////////////////////////////////////////////////////////////////////// + +GR_DEFINE_CUSTOM_STAGE_TEST(GrSingleTextureEffect); + +GrCustomStage* GrSingleTextureEffect::TestCreate(SkRandom* random, + GrContext* context, + GrTexture* textures[]) { + int texIdx = random->nextBool() ? GrCustomStageTestFactory::kSkiaPMTextureIdx : + GrCustomStageTestFactory::kAlphaTextureIdx; + return SkNEW_ARGS(GrSingleTextureEffect, (textures[texIdx])); +} diff --git a/src/gpu/effects/GrSingleTextureEffect.h b/src/gpu/effects/GrSingleTextureEffect.h index c49dac8859..211319cf51 100644 --- a/src/gpu/effects/GrSingleTextureEffect.h +++ b/src/gpu/effects/GrSingleTextureEffect.h @@ -31,6 +31,8 @@ public: virtual const GrProgramStageFactory& getFactory() const SK_OVERRIDE; private: + GR_DECLARE_CUSTOM_STAGE_TEST; + GrTexture* fTexture; typedef GrCustomStage INHERITED; diff --git a/src/gpu/effects/GrTextureDomainEffect.cpp b/src/gpu/effects/GrTextureDomainEffect.cpp index e76d0c916b..6b22690197 100644 --- a/src/gpu/effects/GrTextureDomainEffect.cpp +++ b/src/gpu/effects/GrTextureDomainEffect.cpp @@ -107,3 +107,20 @@ bool GrTextureDomainEffect::isEqual(const GrCustomStage& sBase) const { const GrTextureDomainEffect& s = static_cast<const GrTextureDomainEffect&>(sBase); return (INHERITED::isEqual(sBase) && this->fTextureDomain == s.fTextureDomain); } + +/////////////////////////////////////////////////////////////////////////////// + +GR_DEFINE_CUSTOM_STAGE_TEST(GrTextureDomainEffect); + +GrCustomStage* GrTextureDomainEffect::TestCreate(SkRandom* random, + GrContext* context, + GrTexture* textures[]) { + int texIdx = random->nextBool() ? GrCustomStageTestFactory::kSkiaPMTextureIdx : + GrCustomStageTestFactory::kAlphaTextureIdx; + GrRect domain; + domain.fLeft = random->nextUScalar1(); + domain.fRight = random->nextRangeScalar(domain.fLeft, SK_Scalar1); + domain.fTop = random->nextUScalar1(); + domain.fBottom = random->nextRangeScalar(domain.fTop, SK_Scalar1); + return SkNEW_ARGS(GrTextureDomainEffect, (textures[texIdx], domain)); +} diff --git a/src/gpu/effects/GrTextureDomainEffect.h b/src/gpu/effects/GrTextureDomainEffect.h index 6157175cb4..559398eca9 100644 --- a/src/gpu/effects/GrTextureDomainEffect.h +++ b/src/gpu/effects/GrTextureDomainEffect.h @@ -38,6 +38,7 @@ protected: GrRect fTextureDomain; private: + GR_DECLARE_CUSTOM_STAGE_TEST; typedef GrSingleTextureEffect INHERITED; }; |