diff options
author | 2012-10-24 19:07:10 +0000 | |
---|---|---|
committer | 2012-10-24 19:07:10 +0000 | |
commit | 6f261bed0252e3f3caa595798364e0bf12a2573a (patch) | |
tree | e6cf7cfab6ff785b002b88b165a6bd00a9402960 /include/gpu/GrEffectUnitTest.h | |
parent | a469c28c3c16214733a25201a286970f57b3d944 (diff) |
GrCustomStage Renaming Part 2
GrSamplerState member rename
GrCustomStageUnitTest rename
some comment updates
Review URL: https://codereview.appspot.com/6771043
git-svn-id: http://skia.googlecode.com/svn/trunk@6078 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'include/gpu/GrEffectUnitTest.h')
-rw-r--r-- | include/gpu/GrEffectUnitTest.h | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/include/gpu/GrEffectUnitTest.h b/include/gpu/GrEffectUnitTest.h new file mode 100644 index 0000000000..c18bdd0990 --- /dev/null +++ b/include/gpu/GrEffectUnitTest.h @@ -0,0 +1,78 @@ +/* + * 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 GrEffectUnitTest_DEFINED +#define GrEffectUnitTest_DEFINED + +#include "SkRandom.h" +#include "GrNoncopyable.h" +#include "SkTArray.h" + +namespace GrEffectUnitTest { +// Used to access the dummy textures in TestCreate procs. +enum { + kSkiaPMTextureIdx = 0, + kAlphaTextureIdx = 1, +}; +} + +#if SK_ALLOW_STATIC_GLOBAL_INITIALIZERS + +class GrContext; +class GrEffect; +class GrTexture; + +class GrEffectTestFactory : GrNoncopyable { +public: + + typedef GrEffect* (*CreateProc)(SkRandom*, GrContext*, GrTexture* dummyTextures[]); + + GrEffectTestFactory(CreateProc createProc) { + fCreateProc = createProc; + GetFactories()->push_back(this); + } + + static GrEffect* CreateStage(SkRandom* random, + GrContext* context, + GrTexture* dummyTextures[]) { + uint32_t idx = random->nextRangeU(0, GetFactories()->count() - 1); + GrEffectTestFactory* factory = (*GetFactories())[idx]; + return factory->fCreateProc(random, context, dummyTextures); + } + +private: + CreateProc fCreateProc; + static SkTArray<GrEffectTestFactory*, true>* GetFactories(); +}; + +/** GrEffect subclasses should insert this macro in their declaration to be included in the + * program generation unit test. + */ +#define GR_DECLARE_CUSTOM_STAGE_TEST \ + static GrEffectTestFactory gTestFactory; \ + static GrEffect* TestCreate(SkRandom*, GrContext*, GrTexture* dummyTextures[2]) + +/** GrEffect subclasses should insert this macro in their implemenation file. They must then + * also implement this static function: + * GrEffect* TestCreate(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) \ + GrEffectTestFactory 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 GrEffect* TestCreate(SkRandom*, GrContext*, GrTexture* dummyTextures[2]) +#define GR_DEFINE_CUSTOM_STAGE_TEST(X) + +#endif // !SK_ALLOW_STATIC_GLOBAL_INITIALIZERS +#endif |