diff options
author | bsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2012-08-03 14:34:46 +0000 |
---|---|---|
committer | bsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2012-08-03 14:34:46 +0000 |
commit | d472620458e2383e6dd949f4e1aaf61160717ffe (patch) | |
tree | 2822ac4f1c55d6eaa9ed4ac6dc2b7014de5410ff /include/gpu | |
parent | dea8e252e1259f5bdd15e16a21646402058b939d (diff) |
Registry-based unit test for custom effects
Review URL: http://codereview.appspot.com/6447085/
git-svn-id: http://skia.googlecode.com/svn/trunk@4946 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'include/gpu')
-rw-r--r-- | include/gpu/GrCustomStage.h | 1 | ||||
-rw-r--r-- | include/gpu/GrCustomStageUnitTest.h | 73 |
2 files changed, 74 insertions, 0 deletions
diff --git a/include/gpu/GrCustomStage.h b/include/gpu/GrCustomStage.h index a13ecd469e..0ac7a76205 100644 --- a/include/gpu/GrCustomStage.h +++ b/include/gpu/GrCustomStage.h @@ -11,6 +11,7 @@ #include "GrRefCnt.h" #include "GrNoncopyable.h" #include "GrProgramStageFactory.h" +#include "GrCustomStageUnitTest.h" class GrContext; class GrTexture; diff --git a/include/gpu/GrCustomStageUnitTest.h b/include/gpu/GrCustomStageUnitTest.h new file mode 100644 index 0000000000..9cbadf3a5b --- /dev/null +++ b/include/gpu/GrCustomStageUnitTest.h @@ -0,0 +1,73 @@ +/* + * Copyright 2012 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef GrCustomStageUnitTest_DEFINED +#define GrCustomStageUnitTest_DEFINED + +#include "SkRandom.h" + +#if SK_ALLOW_STATIC_GLOBAL_INITIALIZERS + +class GrCustomStage; +class GrContext; +class GrTexture; + +class GrCustomStageTestFactory : GrNoncopyable { +public: + // Used to access the dummy textures in TestCreate procs. + enum { + kSkiaPMTextureIdx = 0, + kAlphaTextureIdx = 1, + }; + + typedef GrCustomStage* (*CreateProc)(SkRandom*, GrContext*, GrTexture* dummyTextures[]); + + GrCustomStageTestFactory(CreateProc createProc) { + fCreateProc = createProc; + GetFactories()->push_back(this); + } + + static GrCustomStage* CreateStage(SkRandom* random, + GrContext* context, + GrTexture* dummyTextures[]) { + uint32_t idx = random->nextRangeU(0, GetFactories()->count() - 1); + GrCustomStageTestFactory* factory = (*GetFactories())[idx]; + return factory->fCreateProc(random, context, dummyTextures); + } + +private: + CreateProc fCreateProc; + static SkTArray<GrCustomStageTestFactory*, true>* GetFactories(); +}; + +/** GrCustomStage subclasses should insert this macro in their declaration to be included in the + * program generation unit test. + */ +#define GR_DECLARE_CUSTOM_STAGE_TEST \ + static GrCustomStageTestFactory gTestFactory; \ + static GrCustomStage* TestCreate(SkRandom*, GrContext*, GrTexture* dummyTextures[2]) + +/** GrCustomStage subclasses should insert this macro in their implemenation file. They must then + * also implement this static function: + * GrCustomStage* CreateStage(SkRandom*, GrContext*, GrTexture* dummyTextures[2]); + * dummyTextures[] are valied textures that they can optionally use for their texture accesses. The + * first texture has config kSkia8888_PM_GrPixelConfig and the second has kAlpha_8_GrPixelConfig. + * TestCreate functions are also free to create additional textures using the GrContext. + */ +#define GR_DEFINE_CUSTOM_STAGE_TEST(CustomStage) \ + GrCustomStageTestFactory CustomStage :: gTestFactory(CustomStage :: TestCreate) + +#else // !SK_ALLOW_STATIC_GLOBAL_INITIALIZERS + +// The unit test relies on static initializers. Just declare the TestCreate function so that +// its definitions will compile. +#define GR_DECLARE_CUSTOM_STAGE_TEST \ + static GrCustomStage* TestCreate(SkRandom*, GrContext*, GrTexture* dummyTextures[2]) +#define GR_DEFINE_CUSTOM_STAGE_TEST(X) + +#endif // !SK_ALLOW_STATIC_GLOBAL_INITIALIZERS +#endif
\ No newline at end of file |