Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(341)

Side by Side Diff: include/gpu/GrProcessorUnitTest.h

Issue 783763002: Initial CL to move color / coverage off of drawstate (Closed) Base URL: https://skia.googlesource.com/skia.git@no-static-gp
Patch Set: todo added Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 CoverageMode {
78 kZero_CoverageMode,
79 kAllOnes_CoverageMode,
80 kRandom_CoverageMode,
81 kLast_CoverageMode = kRandom_CoverageMode
82 };
83
84 CoverageMode colorMode = CoverageMode(random->nextULessThan(kLast_CoverageMo de + 1));
85 uint8_t coverage;
86 switch (colorMode) {
87 case kZero_CoverageMode:
88 coverage = 0;
89 case kAllOnes_CoverageMode:
90 coverage = 0xff;
91 break;
92 case kRandom_CoverageMode:
93 coverage = random->nextULessThan(256);
94 break;
95 }
96 return coverage;
97 }
98
38 template <class Processor> 99 template <class Processor>
39 class GrProcessorTestFactory : SkNoncopyable { 100 class GrProcessorTestFactory : SkNoncopyable {
40 public: 101 public:
41 102
42 typedef Processor* (*CreateProc)(SkRandom*, 103 typedef Processor* (*CreateProc)(SkRandom*,
43 GrContext*, 104 GrContext*,
44 const GrDrawTargetCaps& caps, 105 const GrDrawTargetCaps& caps,
45 GrTexture* dummyTextures[]); 106 GrTexture* dummyTextures[]);
46 107
47 GrProcessorTestFactory(CreateProc createProc) { 108 GrProcessorTestFactory(CreateProc createProc) {
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 // its definitions will compile. 181 // its definitions will compile.
121 #define GR_DECLARE_GEOMETRY_PROCESSOR_TEST \ 182 #define GR_DECLARE_GEOMETRY_PROCESSOR_TEST \
122 static GrGeometryProcessor* TestCreate(SkRandom*, \ 183 static GrGeometryProcessor* TestCreate(SkRandom*, \
123 GrContext*, \ 184 GrContext*, \
124 const GrDrawTargetCaps&, \ 185 const GrDrawTargetCaps&, \
125 GrTexture* dummyTextures[2]) 186 GrTexture* dummyTextures[2])
126 #define GR_DEFINE_GEOMETRY_PROCESSOR_TEST(X) 187 #define GR_DEFINE_GEOMETRY_PROCESSOR_TEST(X)
127 188
128 #endif // !SK_ALLOW_STATIC_GLOBAL_INITIALIZERS 189 #endif // !SK_ALLOW_STATIC_GLOBAL_INITIALIZERS
129 #endif 190 #endif
OLDNEW
« no previous file with comments | « include/gpu/GrContext.h ('k') | src/gpu/GrAAConvexPathRenderer.h » ('j') | src/gpu/GrDrawState.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698