| 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 GrProcessorUnitTest_DEFINED | 8 #ifndef GrProcessorUnitTest_DEFINED |
| 9 #define GrProcessorUnitTest_DEFINED | 9 #define GrProcessorUnitTest_DEFINED |
| 10 | 10 |
| 11 #include "GrColor.h" |
| 11 #include "SkRandom.h" | 12 #include "SkRandom.h" |
| 12 #include "SkTArray.h" | 13 #include "SkTArray.h" |
| 13 #include "SkTypes.h" | 14 #include "SkTypes.h" |
| 14 | 15 |
| 15 class SkMatrix; | 16 class SkMatrix; |
| 16 class GrDrawTargetCaps; | 17 class GrDrawTargetCaps; |
| 17 | 18 |
| 18 namespace GrProcessorUnitTest { | 19 namespace GrProcessorUnitTest { |
| 19 // Used to access the dummy textures in TestCreate procs. | 20 // Used to access the dummy textures in TestCreate procs. |
| 20 enum { | 21 enum { |
| 21 kSkiaPMTextureIdx = 0, | 22 kSkiaPMTextureIdx = 0, |
| 22 kAlphaTextureIdx = 1, | 23 kAlphaTextureIdx = 1, |
| 23 }; | 24 }; |
| 24 | 25 |
| 25 /** | 26 /** |
| 26 * A helper for use in GrProcessor::TestCreate functions. | 27 * A helper for use in GrProcessor::TestCreate functions. |
| 27 */ | 28 */ |
| 28 const SkMatrix& TestMatrix(SkRandom*); | 29 const SkMatrix& TestMatrix(SkRandom*); |
| 29 | 30 |
| 30 } | 31 } |
| 31 | 32 |
| 32 #if SK_ALLOW_STATIC_GLOBAL_INITIALIZERS | 33 #if SK_ALLOW_STATIC_GLOBAL_INITIALIZERS |
| 33 | 34 |
| 34 class GrContext; | 35 class GrContext; |
| 35 class GrProcessor; | 36 class GrProcessor; |
| 36 class GrTexture; | 37 class GrTexture; |
| 37 | 38 |
| 39 static inline GrColor GrRandomColor(SkRandom* random) { |
| 40 // There are only a few cases of random colors which interest us |
| 41 enum ColorMode { |
| 42 kAllOnes_ColorMode, |
| 43 kAllZeros_ColorMode, |
| 44 kAlphaOne_ColorMode, |
| 45 kRandom_ColorMode, |
| 46 kLast_ColorMode = kRandom_ColorMode |
| 47 }; |
| 48 |
| 49 ColorMode colorMode = ColorMode(random->nextULessThan(kLast_ColorMode + 1)); |
| 50 GrColor color; |
| 51 switch (colorMode) { |
| 52 case kAllOnes_ColorMode: |
| 53 color = GrColorPackRGBA(0xFF, 0xFF, 0xFF, 0xFF); |
| 54 break; |
| 55 case kAllZeros_ColorMode: |
| 56 color = GrColorPackRGBA(0, 0, 0, 0); |
| 57 break; |
| 58 case kAlphaOne_ColorMode: |
| 59 color = GrColorPackRGBA(random->nextULessThan(256), |
| 60 random->nextULessThan(256), |
| 61 random->nextULessThan(256), |
| 62 0xFF); |
| 63 break; |
| 64 case kRandom_ColorMode: |
| 65 uint8_t alpha = random->nextULessThan(256); |
| 66 color = GrColorPackRGBA(random->nextRangeU(0, alpha), |
| 67 random->nextRangeU(0, alpha), |
| 68 random->nextRangeU(0, alpha), |
| 69 alpha); |
| 70 break; |
| 71 } |
| 72 GrColorIsPMAssert(color); |
| 73 return color; |
| 74 } |
| 75 |
| 76 static inline uint8_t GrRandomCoverage(SkRandom* random) { |
| 77 enum ColorModes { |
| 78 kAllOnes_ColorMode, |
| 79 kRandom_ColorMode, |
| 80 kLast_ColorMode = kRandom_ColorMode |
| 81 }; |
| 82 |
| 83 ColorModes colorMode = ColorModes(random->nextULessThan(kLast_ColorMode + 1)
); |
| 84 uint8_t coverage; |
| 85 switch (colorMode) { |
| 86 case kAllOnes_ColorMode: |
| 87 coverage = 0xff; |
| 88 break; |
| 89 case kRandom_ColorMode: |
| 90 coverage = random->nextULessThan(256); |
| 91 break; |
| 92 } |
| 93 return coverage; |
| 94 } |
| 95 |
| 38 template <class Processor> | 96 template <class Processor> |
| 39 class GrProcessorTestFactory : SkNoncopyable { | 97 class GrProcessorTestFactory : SkNoncopyable { |
| 40 public: | 98 public: |
| 41 | 99 |
| 42 typedef Processor* (*CreateProc)(SkRandom*, | 100 typedef Processor* (*CreateProc)(SkRandom*, |
| 43 GrContext*, | 101 GrContext*, |
| 44 const GrDrawTargetCaps& caps, | 102 const GrDrawTargetCaps& caps, |
| 45 GrTexture* dummyTextures[]); | 103 GrTexture* dummyTextures[]); |
| 46 | 104 |
| 47 GrProcessorTestFactory(CreateProc createProc) { | 105 GrProcessorTestFactory(CreateProc createProc) { |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 // its definitions will compile. | 178 // its definitions will compile. |
| 121 #define GR_DECLARE_GEOMETRY_PROCESSOR_TEST
\ | 179 #define GR_DECLARE_GEOMETRY_PROCESSOR_TEST
\ |
| 122 static GrGeometryProcessor* TestCreate(SkRandom*,
\ | 180 static GrGeometryProcessor* TestCreate(SkRandom*,
\ |
| 123 GrContext*,
\ | 181 GrContext*,
\ |
| 124 const GrDrawTargetCaps&,
\ | 182 const GrDrawTargetCaps&,
\ |
| 125 GrTexture* dummyTextures[2]) | 183 GrTexture* dummyTextures[2]) |
| 126 #define GR_DEFINE_GEOMETRY_PROCESSOR_TEST(X) | 184 #define GR_DEFINE_GEOMETRY_PROCESSOR_TEST(X) |
| 127 | 185 |
| 128 #endif // !SK_ALLOW_STATIC_GLOBAL_INITIALIZERS | 186 #endif // !SK_ALLOW_STATIC_GLOBAL_INITIALIZERS |
| 129 #endif | 187 #endif |
| OLD | NEW |