OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 // This is a GPU-backend specific test. It relies on static intializers to work | 9 // This is a GPU-backend specific test. It relies on static intializers to work |
10 | 10 |
11 #include "SkTypes.h" | 11 #include "SkTypes.h" |
12 | 12 |
13 #if SK_SUPPORT_GPU && SK_ALLOW_STATIC_GLOBAL_INITIALIZERS | 13 #if SK_SUPPORT_GPU && SK_ALLOW_STATIC_GLOBAL_INITIALIZERS |
14 | 14 |
15 #include "gl/GrGpuGL.h" | 15 #include "gl/GrGpuGL.h" |
16 #include "GrBackendEffectFactory.h" | 16 #include "GrBackendEffectFactory.h" |
17 #include "GrContextFactory.h" | 17 #include "GrContextFactory.h" |
18 #include "GrDrawEffect.h" | 18 #include "GrDrawEffect.h" |
19 #include "effects/GrConfigConversionEffect.h" | 19 #include "effects/GrConfigConversionEffect.h" |
20 | 20 |
21 #include "SkRandom.h" | 21 #include "SkRandom.h" |
22 #include "Test.h" | 22 #include "Test.h" |
23 | 23 |
24 void GrGLProgramDesc::setRandom(SkMWCRandom* random, | 24 void GrGLProgramDesc::setRandom(SkMWCRandom* random, |
25 const GrGpuGL* gpu, | 25 const GrGpuGL* gpu, |
26 const GrEffectStage stages[GrDrawState::kNumStag
es]) { | 26 const GrEffectStage stages[GrDrawState::kNumStag
es], |
27 fAttribBindings = 0; | 27 int currAttribIndex) { |
28 fEmitsPointSize = random->nextBool(); | 28 fEmitsPointSize = random->nextBool(); |
29 fColorInput = random->nextULessThan(kColorInputCnt); | 29 |
30 fCoverageInput = random->nextULessThan(kColorInputCnt); | 30 fPositionAttributeIndex = 0; |
| 31 |
| 32 // if the effects have used up all off the available attributes, |
| 33 // don't try to use color or coverage attributes as input |
| 34 do { |
| 35 fColorInput = random->nextULessThan(kColorInputCnt); |
| 36 } while (GrDrawState::kMaxVertexAttribCnt <= currAttribIndex && |
| 37 kAttribute_ColorInput == fColorInput); |
| 38 fColorAttributeIndex = (fColorInput == kAttribute_ColorInput) ? currAttribIn
dex++ : -1; |
| 39 |
| 40 do { |
| 41 fCoverageInput = random->nextULessThan(kColorInputCnt); |
| 42 } while (GrDrawState::kMaxVertexAttribCnt <= currAttribIndex && |
| 43 kAttribute_ColorInput == fCoverageInput); |
| 44 fCoverageAttributeIndex = (fCoverageInput == kAttribute_ColorInput) ? currAt
tribIndex++ : -1; |
31 | 45 |
32 fColorFilterXfermode = random->nextULessThan(SkXfermode::kCoeffModesCnt); | 46 fColorFilterXfermode = random->nextULessThan(SkXfermode::kCoeffModesCnt); |
33 | 47 |
34 fFirstCoverageStage = random->nextULessThan(GrDrawState::kNumStages); | 48 fFirstCoverageStage = random->nextULessThan(GrDrawState::kNumStages); |
35 | 49 |
36 fAttribBindings |= random->nextBool() ? GrDrawState::kCoverage_AttribBinding
sBit : 0; | |
37 | |
38 #if GR_GL_EXPERIMENTAL_GS | 50 #if GR_GL_EXPERIMENTAL_GS |
39 fExperimentalGS = gpu->caps()->geometryShaderSupport() && random->nextBool()
; | 51 fExperimentalGS = gpu->caps()->geometryShaderSupport() && random->nextBool()
; |
40 #endif | 52 #endif |
41 | 53 |
42 fDiscardIfZeroCoverage = random->nextBool(); | 54 fDiscardIfZeroCoverage = random->nextBool(); |
43 | 55 |
44 if (gpu->caps()->dualSourceBlendingSupport()) { | 56 if (gpu->caps()->dualSourceBlendingSupport()) { |
45 fDualSrcOutput = random->nextULessThan(kDualSrcOutputCnt); | 57 fDualSrcOutput = random->nextULessThan(kDualSrcOutputCnt); |
46 } else { | 58 } else { |
47 fDualSrcOutput = kNone_DualSrcOutput; | 59 fDualSrcOutput = kNone_DualSrcOutput; |
48 } | 60 } |
49 | 61 |
50 // use separate tex coords? | 62 bool useLocalCoords = random->nextBool() && currAttribIndex < GrDrawState::k
MaxVertexAttribCnt; |
51 if (random->nextBool()) { | 63 fLocalCoordAttributeIndex = useLocalCoords ? currAttribIndex++ : -1; |
52 fAttribBindings |= GrDrawState::kLocalCoords_AttribBindingsBit; | |
53 } | |
54 | 64 |
55 for (int s = 0; s < GrDrawState::kNumStages; ++s) { | 65 for (int s = 0; s < GrDrawState::kNumStages; ++s) { |
56 if (NULL != stages[s].getEffect()) { | 66 if (NULL != stages[s].getEffect()) { |
57 const GrBackendEffectFactory& factory = (*stages[s].getEffect())->ge
tFactory(); | 67 const GrBackendEffectFactory& factory = (*stages[s].getEffect())->ge
tFactory(); |
58 bool explicitLocalCoords = (fAttribBindings & | 68 GrDrawEffect drawEffect(stages[s], useLocalCoords); |
59 GrDrawState::kLocalCoords_AttribBindings
Bit); | |
60 GrDrawEffect drawEffect(stages[s], explicitLocalCoords); | |
61 fEffectKeys[s] = factory.glEffectKey(drawEffect, gpu->glCaps()); | 69 fEffectKeys[s] = factory.glEffectKey(drawEffect, gpu->glCaps()); |
62 } | 70 } |
63 } | 71 } |
64 | |
65 int attributeIndex = 0; | |
66 fPositionAttributeIndex = attributeIndex; | |
67 ++attributeIndex; | |
68 if (fColorInput || (fAttribBindings & GrDrawState::kColor_AttribBindingsBit)
) { | |
69 fColorAttributeIndex = attributeIndex; | |
70 ++attributeIndex; | |
71 } | |
72 if (fCoverageInput || (fAttribBindings & GrDrawState::kCoverage_AttribBindin
gsBit)) { | |
73 fCoverageAttributeIndex = attributeIndex; | |
74 ++attributeIndex; | |
75 } | |
76 if (fAttribBindings & GrDrawState::kLocalCoords_AttribBindingsBit) { | |
77 fLocalCoordsAttributeIndex = attributeIndex; | |
78 ++attributeIndex; | |
79 } | |
80 } | 72 } |
81 | 73 |
82 bool GrGpuGL::programUnitTest(int maxStages) { | 74 bool GrGpuGL::programUnitTest(int maxStages) { |
83 | 75 |
84 maxStages = GrMin(maxStages, (int)GrDrawState::kNumStages); | 76 maxStages = GrMin(maxStages, (int)GrDrawState::kNumStages); |
85 | 77 |
86 GrTextureDesc dummyDesc; | 78 GrTextureDesc dummyDesc; |
87 dummyDesc.fConfig = kSkia8888_GrPixelConfig; | 79 dummyDesc.fConfig = kSkia8888_GrPixelConfig; |
88 dummyDesc.fWidth = 34; | 80 dummyDesc.fWidth = 34; |
89 dummyDesc.fHeight = 18; | 81 dummyDesc.fHeight = 18; |
(...skipping 12 matching lines...) Expand all Loading... |
102 GrPrintf("\nTest Program %d\n-------------\n", t); | 94 GrPrintf("\nTest Program %d\n-------------\n", t); |
103 static const int stop = -1; | 95 static const int stop = -1; |
104 if (t == stop) { | 96 if (t == stop) { |
105 int breakpointhere = 9; | 97 int breakpointhere = 9; |
106 } | 98 } |
107 #endif | 99 #endif |
108 | 100 |
109 GrGLProgramDesc pdesc; | 101 GrGLProgramDesc pdesc; |
110 GrEffectStage stages[GrDrawState::kNumStages]; | 102 GrEffectStage stages[GrDrawState::kNumStages]; |
111 | 103 |
112 int currAttribIndex = GrDrawState::kAttribIndexCount; | 104 int currAttribIndex = 1; // we need to always leave room for position |
113 int attribIndices[2]; | 105 int attribIndices[2]; |
114 for (int s = 0; s < maxStages; ++s) { | 106 for (int s = 0; s < maxStages; ++s) { |
115 // enable the stage? | 107 // enable the stage? |
116 if (random.nextBool()) { | 108 if (random.nextBool()) { |
117 GrTexture* dummyTextures[] = {dummyTexture1.get(), dummyTexture2
.get()}; | 109 GrTexture* dummyTextures[] = {dummyTexture1.get(), dummyTexture2
.get()}; |
118 SkAutoTUnref<const GrEffectRef> effect(GrEffectTestFactory::Crea
teStage( | 110 SkAutoTUnref<const GrEffectRef> effect(GrEffectTestFactory::Crea
teStage( |
119
&random, | 111
&random, |
120
this->getContext(), | 112
this->getContext(), |
121
*this->caps(), | 113
*this->caps(), |
122
dummyTextures)); | 114
dummyTextures)); |
123 int numAttribs = (*effect)->numVertexAttribs(); | 115 int numAttribs = (*effect)->numVertexAttribs(); |
124 | 116 |
125 // If adding this effect would cause to exceed the max attrib co
unt then generate a | 117 // If adding this effect would exceed the max attrib count then
generate a |
126 // new random effect. The explanation for why this check is corr
ect is a bit | 118 // new random effect. |
127 // convoluted and this code will be removed soon. | 119 if (currAttribIndex + numAttribs > GrDrawState::kMaxVertexAttrib
Cnt) { |
128 if (currAttribIndex + numAttribs > GrDrawState::kCoverageOverrid
eAttribIndexValue) { | |
129 --s; | 120 --s; |
130 continue; | 121 continue; |
131 } | 122 } |
132 for (int i = 0; i < numAttribs; ++i) { | 123 for (int i = 0; i < numAttribs; ++i) { |
133 attribIndices[i] = currAttribIndex++; | 124 attribIndices[i] = currAttribIndex++; |
134 } | 125 } |
135 stages[s].setEffect(effect.get(), attribIndices[0], attribIndice
s[1]); | 126 stages[s].setEffect(effect.get(), attribIndices[0], attribIndice
s[1]); |
136 } | 127 } |
137 } | 128 } |
138 pdesc.setRandom(&random, this, stages); | 129 pdesc.setRandom(&random, this, stages, currAttribIndex); |
139 | 130 |
140 const GrEffectStage* stagePtrs[GrDrawState::kNumStages]; | 131 const GrEffectStage* stagePtrs[GrDrawState::kNumStages]; |
141 for (int s = 0; s < GrDrawState::kNumStages; ++s) { | 132 for (int s = 0; s < GrDrawState::kNumStages; ++s) { |
142 stagePtrs[s] = &stages[s]; | 133 stagePtrs[s] = &stages[s]; |
143 } | 134 } |
144 SkAutoTUnref<GrGLProgram> program(GrGLProgram::Create(this->glContext(), | 135 SkAutoTUnref<GrGLProgram> program(GrGLProgram::Create(this->glContext(), |
145 pdesc, | 136 pdesc, |
146 stagePtrs)); | 137 stagePtrs)); |
147 if (NULL == program.get()) { | 138 if (NULL == program.get()) { |
148 return false; | 139 return false; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 SkMagnifierImageFilter mag(SkRect::MakeWH(SK_Scalar1, SK_Scalar1), SK_Scalar
1); | 178 SkMagnifierImageFilter mag(SkRect::MakeWH(SK_Scalar1, SK_Scalar1), SK_Scalar
1); |
188 GrConfigConversionEffect::Create(NULL, | 179 GrConfigConversionEffect::Create(NULL, |
189 false, | 180 false, |
190 GrConfigConversionEffect::kNone_PMConversio
n, | 181 GrConfigConversionEffect::kNone_PMConversio
n, |
191 SkMatrix::I()); | 182 SkMatrix::I()); |
192 SkScalar matrix[20]; | 183 SkScalar matrix[20]; |
193 SkColorMatrixFilter cmf(matrix); | 184 SkColorMatrixFilter cmf(matrix); |
194 } | 185 } |
195 | 186 |
196 #endif | 187 #endif |
OLD | NEW |