| 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 "GrTestUtils.h" |
| 12 #include "SkRandom.h" | |
| 13 #include "SkTArray.h" | 12 #include "SkTArray.h" |
| 14 #include "SkTypes.h" | 13 #include "SkTypes.h" |
| 15 | 14 |
| 16 class SkMatrix; | 15 class SkMatrix; |
| 17 class GrDrawTargetCaps; | 16 class GrDrawTargetCaps; |
| 18 | 17 |
| 19 namespace GrProcessorUnitTest { | 18 namespace GrProcessorUnitTest { |
| 20 // Used to access the dummy textures in TestCreate procs. | 19 // Used to access the dummy textures in TestCreate procs. |
| 21 enum { | 20 enum { |
| 22 kSkiaPMTextureIdx = 0, | 21 kSkiaPMTextureIdx = 0, |
| 23 kAlphaTextureIdx = 1, | 22 kAlphaTextureIdx = 1, |
| 24 }; | 23 }; |
| 25 | 24 |
| 26 /** | |
| 27 * A helper for use in GrProcessor::TestCreate functions. | |
| 28 */ | |
| 29 const SkMatrix& TestMatrix(SkRandom*); | |
| 30 | |
| 31 } | |
| 32 | |
| 33 static inline GrColor GrRandomColor(SkRandom* random) { | |
| 34 // There are only a few cases of random colors which interest us | |
| 35 enum ColorMode { | |
| 36 kAllOnes_ColorMode, | |
| 37 kAllZeros_ColorMode, | |
| 38 kAlphaOne_ColorMode, | |
| 39 kRandom_ColorMode, | |
| 40 kLast_ColorMode = kRandom_ColorMode | |
| 41 }; | |
| 42 | |
| 43 ColorMode colorMode = ColorMode(random->nextULessThan(kLast_ColorMode + 1)); | |
| 44 GrColor color; | |
| 45 switch (colorMode) { | |
| 46 case kAllOnes_ColorMode: | |
| 47 color = GrColorPackRGBA(0xFF, 0xFF, 0xFF, 0xFF); | |
| 48 break; | |
| 49 case kAllZeros_ColorMode: | |
| 50 color = GrColorPackRGBA(0, 0, 0, 0); | |
| 51 break; | |
| 52 case kAlphaOne_ColorMode: | |
| 53 color = GrColorPackRGBA(random->nextULessThan(256), | |
| 54 random->nextULessThan(256), | |
| 55 random->nextULessThan(256), | |
| 56 0xFF); | |
| 57 break; | |
| 58 case kRandom_ColorMode: | |
| 59 uint8_t alpha = random->nextULessThan(256); | |
| 60 color = GrColorPackRGBA(random->nextRangeU(0, alpha), | |
| 61 random->nextRangeU(0, alpha), | |
| 62 random->nextRangeU(0, alpha), | |
| 63 alpha); | |
| 64 break; | |
| 65 } | |
| 66 GrColorIsPMAssert(color); | |
| 67 return color; | |
| 68 } | |
| 69 | |
| 70 static inline uint8_t GrRandomCoverage(SkRandom* random) { | |
| 71 enum CoverageMode { | |
| 72 kZero_CoverageMode, | |
| 73 kAllOnes_CoverageMode, | |
| 74 kRandom_CoverageMode, | |
| 75 kLast_CoverageMode = kRandom_CoverageMode | |
| 76 }; | |
| 77 | |
| 78 CoverageMode colorMode = CoverageMode(random->nextULessThan(kLast_CoverageMo
de + 1)); | |
| 79 uint8_t coverage; | |
| 80 switch (colorMode) { | |
| 81 case kZero_CoverageMode: | |
| 82 coverage = 0; | |
| 83 case kAllOnes_CoverageMode: | |
| 84 coverage = 0xff; | |
| 85 break; | |
| 86 case kRandom_CoverageMode: | |
| 87 coverage = random->nextULessThan(256); | |
| 88 break; | |
| 89 } | |
| 90 return coverage; | |
| 91 } | 25 } |
| 92 | 26 |
| 93 #if SK_ALLOW_STATIC_GLOBAL_INITIALIZERS | 27 #if SK_ALLOW_STATIC_GLOBAL_INITIALIZERS |
| 94 | 28 |
| 95 class GrContext; | 29 class GrContext; |
| 96 class GrProcessor; | 30 class GrProcessor; |
| 97 class GrTexture; | 31 class GrTexture; |
| 98 | 32 |
| 99 template <class Processor> | 33 template <class Processor> |
| 100 class GrProcessorTestFactory : SkNoncopyable { | 34 class GrProcessorTestFactory : SkNoncopyable { |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 // its definitions will compile. | 135 // its definitions will compile. |
| 202 #define GR_DECLARE_GEOMETRY_PROCESSOR_TEST
\ | 136 #define GR_DECLARE_GEOMETRY_PROCESSOR_TEST
\ |
| 203 static GrGeometryProcessor* TestCreate(SkRandom*,
\ | 137 static GrGeometryProcessor* TestCreate(SkRandom*,
\ |
| 204 GrContext*,
\ | 138 GrContext*,
\ |
| 205 const GrDrawTargetCaps&,
\ | 139 const GrDrawTargetCaps&,
\ |
| 206 GrTexture* dummyTextures[2]) | 140 GrTexture* dummyTextures[2]) |
| 207 #define GR_DEFINE_GEOMETRY_PROCESSOR_TEST(X) | 141 #define GR_DEFINE_GEOMETRY_PROCESSOR_TEST(X) |
| 208 | 142 |
| 209 #endif // !SK_ALLOW_STATIC_GLOBAL_INITIALIZERS | 143 #endif // !SK_ALLOW_STATIC_GLOBAL_INITIALIZERS |
| 210 #endif | 144 #endif |
| OLD | NEW |