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 GrTexture* dstTexture, | 26 const GrTexture* dstTexture, |
27 const GrEffectStage stages[GrDrawState::kNumStag
es], | 27 const GrEffectStage* stages[GrDrawState::kNumSta
ges], |
28 int currAttribIndex) { | 28 int currAttribIndex) { |
29 fEmitsPointSize = random->nextBool(); | 29 fEmitsPointSize = random->nextBool(); |
30 | 30 |
31 fPositionAttributeIndex = 0; | 31 fPositionAttributeIndex = 0; |
32 | 32 |
33 // if the effects have used up all off the available attributes, | 33 // if the effects have used up all off the available attributes, |
34 // don't try to use color or coverage attributes as input | 34 // don't try to use color or coverage attributes as input |
35 do { | 35 do { |
36 fColorInput = random->nextULessThan(kColorInputCnt); | 36 fColorInput = random->nextULessThan(kColorInputCnt); |
37 } while (GrDrawState::kMaxVertexAttribCnt <= currAttribIndex && | 37 } while (GrDrawState::kMaxVertexAttribCnt <= currAttribIndex && |
(...skipping 14 matching lines...) Expand all Loading... |
52 fExperimentalGS = gpu->caps()->geometryShaderSupport() && random->nextBool()
; | 52 fExperimentalGS = gpu->caps()->geometryShaderSupport() && random->nextBool()
; |
53 #endif | 53 #endif |
54 | 54 |
55 fDiscardIfZeroCoverage = random->nextBool(); | 55 fDiscardIfZeroCoverage = random->nextBool(); |
56 | 56 |
57 bool useLocalCoords = random->nextBool() && currAttribIndex < GrDrawState::k
MaxVertexAttribCnt; | 57 bool useLocalCoords = random->nextBool() && currAttribIndex < GrDrawState::k
MaxVertexAttribCnt; |
58 fLocalCoordAttributeIndex = useLocalCoords ? currAttribIndex++ : -1; | 58 fLocalCoordAttributeIndex = useLocalCoords ? currAttribIndex++ : -1; |
59 | 59 |
60 bool dstRead = false; | 60 bool dstRead = false; |
61 for (int s = 0; s < GrDrawState::kNumStages; ++s) { | 61 for (int s = 0; s < GrDrawState::kNumStages; ++s) { |
62 if (NULL != stages[s].getEffect()) { | 62 if (NULL != stages[s]) { |
63 const GrBackendEffectFactory& factory = (*stages[s].getEffect())->ge
tFactory(); | 63 const GrBackendEffectFactory& factory = (*stages[s]->getEffect())->g
etFactory(); |
64 GrDrawEffect drawEffect(stages[s], useLocalCoords); | 64 GrDrawEffect drawEffect(*stages[s], useLocalCoords); |
65 fEffectKeys[s] = factory.glEffectKey(drawEffect, gpu->glCaps()); | 65 fEffectKeys[s] = factory.glEffectKey(drawEffect, gpu->glCaps()); |
66 if ((*stages[s].getEffect())->willReadDst()) { | 66 if ((*stages[s]->getEffect())->willReadDst()) { |
67 dstRead = true; | 67 dstRead = true; |
68 } | 68 } |
69 } | 69 } |
70 } | 70 } |
71 | 71 |
72 if (dstRead) { | 72 if (dstRead) { |
73 this->fDstRead = GrGLShaderBuilder::KeyForDstRead(dstTexture, gpu->glCap
s()); | 73 this->fDstRead = GrGLShaderBuilder::KeyForDstRead(dstTexture, gpu->glCap
s()); |
74 } | 74 } |
75 | 75 |
76 CoverageOutput coverageOutput; | 76 CoverageOutput coverageOutput; |
(...skipping 29 matching lines...) Expand all Loading... |
106 | 106 |
107 #if 0 | 107 #if 0 |
108 GrPrintf("\nTest Program %d\n-------------\n", t); | 108 GrPrintf("\nTest Program %d\n-------------\n", t); |
109 static const int stop = -1; | 109 static const int stop = -1; |
110 if (t == stop) { | 110 if (t == stop) { |
111 int breakpointhere = 9; | 111 int breakpointhere = 9; |
112 } | 112 } |
113 #endif | 113 #endif |
114 | 114 |
115 GrGLProgramDesc pdesc; | 115 GrGLProgramDesc pdesc; |
116 GrEffectStage stages[GrDrawState::kNumStages]; | 116 const GrEffectStage* stages[GrDrawState::kNumStages]; |
| 117 memset(stages, 0, sizeof(stages)); |
117 | 118 |
118 int currAttribIndex = 1; // we need to always leave room for position | 119 int currAttribIndex = 1; // we need to always leave room for position |
119 int attribIndices[2]; | 120 int attribIndices[2]; |
120 GrTexture* dummyTextures[] = {dummyTexture1.get(), dummyTexture2.get()}; | 121 GrTexture* dummyTextures[] = {dummyTexture1.get(), dummyTexture2.get()}; |
121 for (int s = 0; s < maxStages; ++s) { | 122 for (int s = 0; s < maxStages; ++s) { |
122 // enable the stage? | 123 // enable the stage? |
123 if (random.nextBool()) { | 124 if (random.nextBool()) { |
124 SkAutoTUnref<const GrEffectRef> effect(GrEffectTestFactory::Crea
teStage( | 125 SkAutoTUnref<const GrEffectRef> effect(GrEffectTestFactory::Crea
teStage( |
125
&random, | 126
&random, |
126
this->getContext(), | 127
this->getContext(), |
127
*this->caps(), | 128
*this->caps(), |
128
dummyTextures)); | 129
dummyTextures)); |
129 int numAttribs = (*effect)->numVertexAttribs(); | 130 int numAttribs = (*effect)->numVertexAttribs(); |
130 | 131 |
131 // If adding this effect would exceed the max attrib count then
generate a | 132 // If adding this effect would exceed the max attrib count then
generate a |
132 // new random effect. | 133 // new random effect. |
133 if (currAttribIndex + numAttribs > GrDrawState::kMaxVertexAttrib
Cnt) { | 134 if (currAttribIndex + numAttribs > GrDrawState::kMaxVertexAttrib
Cnt) { |
134 --s; | 135 --s; |
135 continue; | 136 continue; |
136 } | 137 } |
137 for (int i = 0; i < numAttribs; ++i) { | 138 for (int i = 0; i < numAttribs; ++i) { |
138 attribIndices[i] = currAttribIndex++; | 139 attribIndices[i] = currAttribIndex++; |
139 } | 140 } |
140 stages[s].setEffect(effect.get(), attribIndices[0], attribIndice
s[1]); | 141 GrEffectStage* stage = SkNEW(GrEffectStage); |
| 142 stage->setEffect(effect.get(), attribIndices[0], attribIndices[1
]); |
| 143 stages[s] = stage; |
141 } | 144 } |
142 } | 145 } |
143 const GrTexture* dstTexture = random.nextBool() ? dummyTextures[0] : dum
myTextures[1]; | 146 const GrTexture* dstTexture = random.nextBool() ? dummyTextures[0] : dum
myTextures[1]; |
144 pdesc.setRandom(&random, this, dstTexture, stages, currAttribIndex); | 147 pdesc.setRandom(&random, this, dstTexture, stages, currAttribIndex); |
145 | 148 |
146 const GrEffectStage* stagePtrs[GrDrawState::kNumStages]; | |
147 for (int s = 0; s < GrDrawState::kNumStages; ++s) { | |
148 stagePtrs[s] = &stages[s]; | |
149 } | |
150 SkAutoTUnref<GrGLProgram> program(GrGLProgram::Create(this->glContext(), | 149 SkAutoTUnref<GrGLProgram> program(GrGLProgram::Create(this->glContext(), |
151 pdesc, | 150 pdesc, |
152 stagePtrs)); | 151 stages)); |
| 152 for (int s = 0; s < maxStages; ++s) { |
| 153 SkDELETE(stages[s]); |
| 154 } |
153 if (NULL == program.get()) { | 155 if (NULL == program.get()) { |
154 return false; | 156 return false; |
155 } | 157 } |
156 } | 158 } |
157 return true; | 159 return true; |
158 } | 160 } |
159 | 161 |
160 static void GLProgramsTest(skiatest::Reporter* reporter, GrContextFactory* facto
ry) { | 162 static void GLProgramsTest(skiatest::Reporter* reporter, GrContextFactory* facto
ry) { |
161 for (int type = 0; type < GrContextFactory::kLastGLContextType; ++type) { | 163 for (int type = 0; type < GrContextFactory::kLastGLContextType; ++type) { |
162 GrContext* context = factory->get(static_cast<GrContextFactory::GLContex
tType>(type)); | 164 GrContext* context = factory->get(static_cast<GrContextFactory::GLContex
tType>(type)); |
(...skipping 30 matching lines...) Expand all Loading... |
193 SkMagnifierImageFilter mag(SkRect::MakeWH(SK_Scalar1, SK_Scalar1), SK_Scalar
1); | 195 SkMagnifierImageFilter mag(SkRect::MakeWH(SK_Scalar1, SK_Scalar1), SK_Scalar
1); |
194 GrConfigConversionEffect::Create(NULL, | 196 GrConfigConversionEffect::Create(NULL, |
195 false, | 197 false, |
196 GrConfigConversionEffect::kNone_PMConversio
n, | 198 GrConfigConversionEffect::kNone_PMConversio
n, |
197 SkMatrix::I()); | 199 SkMatrix::I()); |
198 SkScalar matrix[20]; | 200 SkScalar matrix[20]; |
199 SkColorMatrixFilter cmf(matrix); | 201 SkColorMatrixFilter cmf(matrix); |
200 } | 202 } |
201 | 203 |
202 #endif | 204 #endif |
OLD | NEW |