OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #ifndef GrEffectUnitTest_DEFINED | 8 #ifndef GrEffectUnitTest_DEFINED |
9 #define GrEffectUnitTest_DEFINED | 9 #define GrEffectUnitTest_DEFINED |
10 | 10 |
11 #include "GrNoncopyable.h" | |
11 #include "SkRandom.h" | 12 #include "SkRandom.h" |
12 #include "GrNoncopyable.h" | |
13 #include "SkTArray.h" | 13 #include "SkTArray.h" |
14 | 14 |
15 class SkMatrix; | 15 class SkMatrix; |
16 class GrDrawTargetCaps; | |
16 | 17 |
17 namespace GrEffectUnitTest { | 18 namespace GrEffectUnitTest { |
18 // Used to access the dummy textures in TestCreate procs. | 19 // Used to access the dummy textures in TestCreate procs. |
19 enum { | 20 enum { |
20 kSkiaPMTextureIdx = 0, | 21 kSkiaPMTextureIdx = 0, |
21 kAlphaTextureIdx = 1, | 22 kAlphaTextureIdx = 1, |
22 }; | 23 }; |
23 | 24 |
24 /** | 25 /** |
25 * A helper for use in GrEffect::TestCreate functions. | 26 * A helper for use in GrEffect::TestCreate functions. |
26 */ | 27 */ |
27 const SkMatrix& TestMatrix(SkMWCRandom*); | 28 const SkMatrix& TestMatrix(SkMWCRandom*); |
28 | 29 |
29 } | 30 } |
30 | 31 |
31 #if SK_ALLOW_STATIC_GLOBAL_INITIALIZERS | 32 #if SK_ALLOW_STATIC_GLOBAL_INITIALIZERS |
32 | 33 |
33 class GrContext; | 34 class GrContext; |
34 class GrEffectRef; | 35 class GrEffectRef; |
35 class GrTexture; | 36 class GrTexture; |
36 | 37 |
37 class GrEffectTestFactory : GrNoncopyable { | 38 class GrEffectTestFactory : GrNoncopyable { |
38 public: | 39 public: |
39 | 40 |
40 typedef GrEffectRef* (*CreateProc)(SkMWCRandom*, GrContext*, GrTexture* dumm yTextures[]); | 41 typedef GrEffectRef* (*CreateProc)(SkMWCRandom*, |
42 GrContext*, | |
43 const GrDrawTargetCaps& caps, | |
44 GrTexture* dummyTextures[]); | |
41 | 45 |
42 GrEffectTestFactory(CreateProc createProc) { | 46 GrEffectTestFactory(CreateProc createProc) { |
43 fCreateProc = createProc; | 47 fCreateProc = createProc; |
44 GetFactories()->push_back(this); | 48 GetFactories()->push_back(this); |
45 } | 49 } |
46 | 50 |
47 static GrEffectRef* CreateStage(SkMWCRandom* random, | 51 static GrEffectRef* CreateStage(SkMWCRandom* random, |
48 GrContext* context, | 52 GrContext* context, |
53 const GrDrawTargetCaps& caps, | |
49 GrTexture* dummyTextures[]) { | 54 GrTexture* dummyTextures[]) { |
50 uint32_t idx = random->nextRangeU(0, GetFactories()->count() - 1); | 55 uint32_t idx = random->nextRangeU(0, GetFactories()->count() - 1); |
51 GrEffectTestFactory* factory = (*GetFactories())[idx]; | 56 GrEffectTestFactory* factory = (*GetFactories())[idx]; |
52 return factory->fCreateProc(random, context, dummyTextures); | 57 return factory->fCreateProc(random, context, caps, dummyTextures); |
53 } | 58 } |
54 | 59 |
55 private: | 60 private: |
56 CreateProc fCreateProc; | 61 CreateProc fCreateProc; |
57 static SkTArray<GrEffectTestFactory*, true>* GetFactories(); | 62 static SkTArray<GrEffectTestFactory*, true>* GetFactories(); |
58 }; | 63 }; |
59 | 64 |
60 /** GrEffect subclasses should insert this macro in their declaration to be incl uded in the | 65 /** GrEffect subclasses should insert this macro in their declaration to be incl uded in the |
61 * program generation unit test. | 66 * program generation unit test. |
62 */ | 67 */ |
robertphillips
2013/03/25 18:11:36
line up trailing '\'s?
bsalomon
2013/03/25 18:20:14
Done.
| |
63 #define GR_DECLARE_EFFECT_TEST \ | 68 #define GR_DECLARE_EFFECT_TEST \ |
64 static GrEffectTestFactory gTestFactory; \ | 69 static GrEffectTestFactory gTestFactory; \ |
65 static GrEffectRef* TestCreate(SkMWCRandom*, GrContext*, GrTexture* dummyTex tures[2]) | 70 static GrEffectRef* TestCreate(SkMWCRandom*, \ |
71 GrContext*, \ | |
72 const GrDrawTargetCaps&, \ | |
73 GrTexture* dummyTextures[2]) | |
66 | 74 |
67 /** GrEffect subclasses should insert this macro in their implementation file. T hey must then | 75 /** GrEffect subclasses should insert this macro in their implementation file. T hey must then |
68 * also implement this static function: | 76 * also implement this static function: |
69 * GrEffect* TestCreate(SkMWCRandom*, GrContext*, GrTexture* dummyTextures[ 2]); | 77 * GrEffect* TestCreate(SkMWCRandom*, |
78 * GrContext*, | |
79 * const GrDrawTargetCaps&, | |
80 * GrTexture* dummyTextures[2]); | |
70 * dummyTextures[] are valid textures that can optionally be used to construct G rTextureAccesses. | 81 * dummyTextures[] are valid textures that can optionally be used to construct G rTextureAccesses. |
71 * The first texture has config kSkia8888_GrPixelConfig and the second has | 82 * The first texture has config kSkia8888_GrPixelConfig and the second has |
72 * kAlpha_8_GrPixelConfig. TestCreate functions are also free to create addition al textures using | 83 * kAlpha_8_GrPixelConfig. TestCreate functions are also free to create addition al textures using |
73 * the GrContext. | 84 * the GrContext. |
74 */ | 85 */ |
75 #define GR_DEFINE_EFFECT_TEST(Effect) \ | 86 #define GR_DEFINE_EFFECT_TEST(Effect) \ |
76 GrEffectTestFactory Effect :: gTestFactory(Effect :: TestCreate) | 87 GrEffectTestFactory Effect :: gTestFactory(Effect :: TestCreate) |
77 | 88 |
78 #else // !SK_ALLOW_STATIC_GLOBAL_INITIALIZERS | 89 #else // !SK_ALLOW_STATIC_GLOBAL_INITIALIZERS |
79 | 90 |
80 // The unit test relies on static initializers. Just declare the TestCreate func tion so that | 91 // The unit test relies on static initializers. Just declare the TestCreate func tion so that |
81 // its definitions will compile. | 92 // its definitions will compile. |
robertphillips
2013/03/25 18:11:36
same here?
bsalomon
2013/03/25 18:20:14
Done.
| |
82 #define GR_DECLARE_EFFECT_TEST \ | 93 #define GR_DECLARE_EFFECT_TEST \ |
83 static GrEffectRef* TestCreate(SkMWCRandom*, GrContext*, GrTexture* dummyTex tures[2]) | 94 static GrEffectRef* TestCreate(SkMWCRandom*, \ |
95 GrContext*, \ | |
96 const GrDrawTargetCaps&, \ | |
97 GrTexture* dummyTextures[2]) | |
84 #define GR_DEFINE_EFFECT_TEST(X) | 98 #define GR_DEFINE_EFFECT_TEST(X) |
85 | 99 |
86 #endif // !SK_ALLOW_STATIC_GLOBAL_INITIALIZERS | 100 #endif // !SK_ALLOW_STATIC_GLOBAL_INITIALIZERS |
87 #endif | 101 #endif |
OLD | NEW |