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

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: bug fix 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
« no previous file with comments | « include/gpu/GrContext.h ('k') | src/gpu/GrAAConvexPathRenderer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
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 }
92
32 #if SK_ALLOW_STATIC_GLOBAL_INITIALIZERS 93 #if SK_ALLOW_STATIC_GLOBAL_INITIALIZERS
33 94
34 class GrContext; 95 class GrContext;
35 class GrProcessor; 96 class GrProcessor;
36 class GrTexture; 97 class GrTexture;
37 98
38 template <class Processor> 99 template <class Processor>
39 class GrProcessorTestFactory : SkNoncopyable { 100 class GrProcessorTestFactory : SkNoncopyable {
40 public: 101 public:
41 102
(...skipping 78 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') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698