1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/skia/trunk/include/gpu/GrEffectUnitTest.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,101 @@ 1.4 +/* 1.5 + * Copyright 2012 Google Inc. 1.6 + * 1.7 + * Use of this source code is governed by a BSD-style license that can be 1.8 + * found in the LICENSE file. 1.9 + */ 1.10 + 1.11 +#ifndef GrEffectUnitTest_DEFINED 1.12 +#define GrEffectUnitTest_DEFINED 1.13 + 1.14 +#include "SkRandom.h" 1.15 +#include "SkTArray.h" 1.16 +#include "SkTypes.h" 1.17 + 1.18 +class SkMatrix; 1.19 +class GrDrawTargetCaps; 1.20 + 1.21 +namespace GrEffectUnitTest { 1.22 +// Used to access the dummy textures in TestCreate procs. 1.23 +enum { 1.24 + kSkiaPMTextureIdx = 0, 1.25 + kAlphaTextureIdx = 1, 1.26 +}; 1.27 + 1.28 +/** 1.29 + * A helper for use in GrEffect::TestCreate functions. 1.30 + */ 1.31 +const SkMatrix& TestMatrix(SkRandom*); 1.32 + 1.33 +} 1.34 + 1.35 +#if SK_ALLOW_STATIC_GLOBAL_INITIALIZERS 1.36 + 1.37 +class GrContext; 1.38 +class GrEffectRef; 1.39 +class GrTexture; 1.40 + 1.41 +class GrEffectTestFactory : public SkNoncopyable { 1.42 +public: 1.43 + 1.44 + typedef GrEffectRef* (*CreateProc)(SkRandom*, 1.45 + GrContext*, 1.46 + const GrDrawTargetCaps& caps, 1.47 + GrTexture* dummyTextures[]); 1.48 + 1.49 + GrEffectTestFactory(CreateProc createProc) { 1.50 + fCreateProc = createProc; 1.51 + GetFactories()->push_back(this); 1.52 + } 1.53 + 1.54 + static GrEffectRef* CreateStage(SkRandom* random, 1.55 + GrContext* context, 1.56 + const GrDrawTargetCaps& caps, 1.57 + GrTexture* dummyTextures[]) { 1.58 + uint32_t idx = random->nextRangeU(0, GetFactories()->count() - 1); 1.59 + GrEffectTestFactory* factory = (*GetFactories())[idx]; 1.60 + return factory->fCreateProc(random, context, caps, dummyTextures); 1.61 + } 1.62 + 1.63 +private: 1.64 + CreateProc fCreateProc; 1.65 + static SkTArray<GrEffectTestFactory*, true>* GetFactories(); 1.66 +}; 1.67 + 1.68 +/** GrEffect subclasses should insert this macro in their declaration to be included in the 1.69 + * program generation unit test. 1.70 + */ 1.71 +#define GR_DECLARE_EFFECT_TEST \ 1.72 + static GrEffectTestFactory gTestFactory; \ 1.73 + static GrEffectRef* TestCreate(SkRandom*, \ 1.74 + GrContext*, \ 1.75 + const GrDrawTargetCaps&, \ 1.76 + GrTexture* dummyTextures[2]) 1.77 + 1.78 +/** GrEffect subclasses should insert this macro in their implementation file. They must then 1.79 + * also implement this static function: 1.80 + * GrEffect* TestCreate(SkRandom*, 1.81 + * GrContext*, 1.82 + * const GrDrawTargetCaps&, 1.83 + * GrTexture* dummyTextures[2]); 1.84 + * dummyTextures[] are valid textures that can optionally be used to construct GrTextureAccesses. 1.85 + * The first texture has config kSkia8888_GrPixelConfig and the second has 1.86 + * kAlpha_8_GrPixelConfig. TestCreate functions are also free to create additional textures using 1.87 + * the GrContext. 1.88 + */ 1.89 +#define GR_DEFINE_EFFECT_TEST(Effect) \ 1.90 + GrEffectTestFactory Effect :: gTestFactory(Effect :: TestCreate) 1.91 + 1.92 +#else // !SK_ALLOW_STATIC_GLOBAL_INITIALIZERS 1.93 + 1.94 +// The unit test relies on static initializers. Just declare the TestCreate function so that 1.95 +// its definitions will compile. 1.96 +#define GR_DECLARE_EFFECT_TEST \ 1.97 + static GrEffectRef* TestCreate(SkRandom*, \ 1.98 + GrContext*, \ 1.99 + const GrDrawTargetCaps&, \ 1.100 + GrTexture* dummyTextures[2]) 1.101 +#define GR_DEFINE_EFFECT_TEST(X) 1.102 + 1.103 +#endif // !SK_ALLOW_STATIC_GLOBAL_INITIALIZERS 1.104 +#endif