| 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 |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 CoverageOutputUsesSecondaryOutput(coverageOutpu
t)) || | 155 CoverageOutputUsesSecondaryOutput(coverageOutpu
t)) || |
| 156 (!dstRead && kCombineWithDst_CoverageOutput == c
overageOutput); | 156 (!dstRead && kCombineWithDst_CoverageOutput == c
overageOutput); |
| 157 } while (illegalCoverageOutput); | 157 } while (illegalCoverageOutput); |
| 158 | 158 |
| 159 header->fCoverageOutput = coverageOutput; | 159 header->fCoverageOutput = coverageOutput; |
| 160 | 160 |
| 161 this->finalize(); | 161 this->finalize(); |
| 162 return true; | 162 return true; |
| 163 } | 163 } |
| 164 | 164 |
| 165 // TODO clean this up, we have to do this to test geometry processors but there
has got to be |
| 166 // a better way. In the mean time, we actually fill out these generic vertex at
tribs below with |
| 167 // the correct vertex attribs from the GP. We have to ensure, however, we don't
try to add more |
| 168 // than two attributes. |
| 169 GrVertexAttrib genericVertexAttribs[] = { |
| 170 { kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding }, |
| 171 { kVec2f_GrVertexAttribType, 0, kEffect_GrVertexAttribBinding }, |
| 172 { kVec2f_GrVertexAttribType, 0, kEffect_GrVertexAttribBinding } |
| 173 }; |
| 174 |
| 175 /* |
| 176 * convert sl type to vertexattrib type, not a complete implementation, only use
for debugging |
| 177 */ |
| 178 GrVertexAttribType convert_sltype_to_attribtype(GrSLType type) { |
| 179 switch (type) { |
| 180 case kFloat_GrSLType: |
| 181 return kFloat_GrVertexAttribType; |
| 182 case kVec2f_GrSLType: |
| 183 return kVec2f_GrVertexAttribType; |
| 184 case kVec3f_GrSLType: |
| 185 return kVec3f_GrVertexAttribType; |
| 186 case kVec4f_GrSLType: |
| 187 return kVec4f_GrVertexAttribType; |
| 188 default: |
| 189 SkFAIL("Type isn't convertible"); |
| 190 return kFloat_GrVertexAttribType; |
| 191 } |
| 192 } |
| 193 // TODO end test hack |
| 194 |
| 195 |
| 165 bool GrGpuGL::programUnitTest(int maxStages) { | 196 bool GrGpuGL::programUnitTest(int maxStages) { |
| 166 | 197 |
| 167 GrTextureDesc dummyDesc; | 198 GrTextureDesc dummyDesc; |
| 168 dummyDesc.fFlags = kRenderTarget_GrTextureFlagBit; | 199 dummyDesc.fFlags = kRenderTarget_GrTextureFlagBit; |
| 169 dummyDesc.fConfig = kSkia8888_GrPixelConfig; | 200 dummyDesc.fConfig = kSkia8888_GrPixelConfig; |
| 170 dummyDesc.fWidth = 34; | 201 dummyDesc.fWidth = 34; |
| 171 dummyDesc.fHeight = 18; | 202 dummyDesc.fHeight = 18; |
| 172 SkAutoTUnref<GrTexture> dummyTexture1(this->createTexture(dummyDesc, NULL, 0
)); | 203 SkAutoTUnref<GrTexture> dummyTexture1(this->createTexture(dummyDesc, NULL, 0
)); |
| 173 dummyDesc.fFlags = kNone_GrTextureFlags; | 204 dummyDesc.fFlags = kNone_GrTextureFlags; |
| 174 dummyDesc.fConfig = kAlpha_8_GrPixelConfig; | 205 dummyDesc.fConfig = kAlpha_8_GrPixelConfig; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 190 static const int stop = -1; | 221 static const int stop = -1; |
| 191 if (t == stop) { | 222 if (t == stop) { |
| 192 int breakpointhere = 9; | 223 int breakpointhere = 9; |
| 193 } | 224 } |
| 194 #endif | 225 #endif |
| 195 | 226 |
| 196 GrGLProgramDesc pdesc; | 227 GrGLProgramDesc pdesc; |
| 197 | 228 |
| 198 int currAttribIndex = 1; // we need to always leave room for position | 229 int currAttribIndex = 1; // we need to always leave room for position |
| 199 int currTextureCoordSet = 0; | 230 int currTextureCoordSet = 0; |
| 200 int attribIndices[2] = { 0, 0 }; | |
| 201 GrTexture* dummyTextures[] = {dummyTexture1.get(), dummyTexture2.get()}; | 231 GrTexture* dummyTextures[] = {dummyTexture1.get(), dummyTexture2.get()}; |
| 202 | 232 |
| 203 int numStages = random.nextULessThan(maxStages + 1); | 233 int numStages = random.nextULessThan(maxStages + 1); |
| 204 int numColorStages = random.nextULessThan(numStages + 1); | 234 int numColorStages = random.nextULessThan(numStages + 1); |
| 205 int numCoverageStages = numStages - numColorStages; | 235 int numCoverageStages = numStages - numColorStages; |
| 206 | 236 |
| 207 SkAutoSTMalloc<8, const GrEffectStage*> stages(numStages); | 237 SkAutoSTMalloc<8, const GrEffectStage*> stages(numStages); |
| 208 | 238 |
| 209 bool useFixedFunctionPathRendering = this->glCaps().pathRenderingSupport
() && | 239 bool useFixedFunctionPathRendering = this->glCaps().pathRenderingSupport
() && |
| 210 this->glPathRendering()->texturingMode() == GrGLPathRendering::Fixed
Function_TexturingMode && | 240 this->glPathRendering()->texturingMode() == GrGLPathRendering::Fixed
Function_TexturingMode && |
| 211 random.nextBool(); | 241 random.nextBool(); |
| 212 | 242 |
| 213 SkAutoTDelete<GrEffectStage> geometryProcessor; | 243 SkAutoTDelete<GrEffectStage> geometryProcessor; |
| 214 bool hasGeometryProcessor = useFixedFunctionPathRendering ? false : rand
om.nextBool(); | 244 bool hasGeometryProcessor = useFixedFunctionPathRendering ? false : rand
om.nextBool(); |
| 215 if (hasGeometryProcessor) { | 245 if (hasGeometryProcessor) { |
| 216 while (true) { | 246 while (true) { |
| 217 SkAutoTUnref<const GrEffect> effect(GrEffectTestFactory::CreateS
tage( | 247 SkAutoTUnref<const GrEffect> effect(GrEffectTestFactory::CreateS
tage( |
| 218
&random, | 248
&random, |
| 219
this->getContext(), | 249
this->getContext(), |
| 220
*this->caps(), | 250
*this->caps(), |
| 221
dummyTextures)); | 251
dummyTextures)); |
| 222 SkASSERT(effect); | 252 SkASSERT(effect); |
| 223 | |
| 224 // Only geometryProcessor can use vertex shader | 253 // Only geometryProcessor can use vertex shader |
| 225 if (!effect->requiresVertexShader()) { | 254 if (!effect->requiresVertexShader()) { |
| 226 continue; | 255 continue; |
| 227 } | 256 } |
| 228 | 257 |
| 229 int numAttribs = effect->numVertexAttribs(); | 258 GrEffectStage* stage = SkNEW_ARGS(GrEffectStage, (effect.get()))
; |
| 230 for (int i = 0; i < numAttribs; ++i) { | 259 geometryProcessor.reset(stage); |
| 231 attribIndices[i] = currAttribIndex++; | 260 |
| 261 // we have to set dummy vertex attribs |
| 262 const GrEffect::VertexAttribArray& v = effect->getVertexAttribs(
); |
| 263 int numVertexAttribs = v.count(); |
| 264 |
| 265 SkASSERT(GrEffect::kMaxVertexAttribs == 2 && |
| 266 GrEffect::kMaxVertexAttribs >= numVertexAttribs); |
| 267 size_t runningStride = GrVertexAttribTypeSize(genericVertexAttri
bs[0].fType); |
| 268 for (int i = 0; i < numVertexAttribs; i++) { |
| 269 genericVertexAttribs[i + 1].fOffset = runningStride; |
| 270 genericVertexAttribs[i + 1].fType = |
| 271 convert_sltype_to_attribtype(v[i].getType()); |
| 272 runningStride += GrVertexAttribTypeSize(genericVertexAttribs
[i + 1].fType); |
| 232 } | 273 } |
| 233 GrEffectStage* stage = SkNEW_ARGS(GrEffectStage, | 274 |
| 234 (effect.get(), attribIndices[0
], attribIndices[1])); | 275 // update the vertex attributes with the ds |
| 235 geometryProcessor.reset(stage); | 276 GrDrawState* ds = this->drawState(); |
| 277 ds->setVertexAttribs<genericVertexAttribs>(numVertexAttribs + 1,
runningStride); |
| 278 currAttribIndex = numVertexAttribs + 1; |
| 236 break; | 279 break; |
| 237 } | 280 } |
| 238 } | 281 } |
| 239 for (int s = 0; s < numStages;) { | 282 for (int s = 0; s < numStages;) { |
| 240 SkAutoTUnref<const GrEffect> effect(GrEffectTestFactory::CreateStage
( | 283 SkAutoTUnref<const GrEffect> effect(GrEffectTestFactory::CreateStage
( |
| 241 &ran
dom, | 284 &ran
dom, |
| 242 this
->getContext(), | 285 this
->getContext(), |
| 243 *thi
s->caps(), | 286 *thi
s->caps(), |
| 244 dumm
yTextures)); | 287 dumm
yTextures)); |
| 245 SkASSERT(effect); | 288 SkASSERT(effect); |
| 246 | 289 |
| 247 // Only geometryProcessor can use vertex shader | 290 // Only geometryProcessor can use vertex shader |
| 248 if (effect->requiresVertexShader()) { | 291 if (effect->requiresVertexShader()) { |
| 249 continue; | 292 continue; |
| 250 } | 293 } |
| 251 | 294 |
| 252 // If adding this effect would exceed the max texture coord set coun
t then generate a | 295 // If adding this effect would exceed the max texture coord set coun
t then generate a |
| 253 // new random effect. | 296 // new random effect. |
| 254 if (useFixedFunctionPathRendering) { | 297 if (useFixedFunctionPathRendering) { |
| 255 int numTransforms = effect->numTransforms(); | 298 int numTransforms = effect->numTransforms(); |
| 256 if (currTextureCoordSet + numTransforms > this->glCaps().maxFixe
dFunctionTextureCoords()) { | 299 if (currTextureCoordSet + numTransforms > this->glCaps().maxFixe
dFunctionTextureCoords()) { |
| 257 continue; | 300 continue; |
| 258 } | 301 } |
| 259 currTextureCoordSet += numTransforms; | 302 currTextureCoordSet += numTransforms; |
| 260 } | 303 } |
| 261 GrEffectStage* stage = SkNEW_ARGS(GrEffectStage, | 304 GrEffectStage* stage = SkNEW_ARGS(GrEffectStage, (effect.get())); |
| 262 (effect.get(), attribIndices[0], a
ttribIndices[1])); | |
| 263 | 305 |
| 264 stages[s] = stage; | 306 stages[s] = stage; |
| 265 ++s; | 307 ++s; |
| 266 } | 308 } |
| 267 const GrTexture* dstTexture = random.nextBool() ? dummyTextures[0] : dum
myTextures[1]; | 309 const GrTexture* dstTexture = random.nextBool() ? dummyTextures[0] : dum
myTextures[1]; |
| 268 if (!pdesc.setRandom(&random, | 310 if (!pdesc.setRandom(&random, |
| 269 this, | 311 this, |
| 270 dummyTextures[0]->asRenderTarget(), | 312 dummyTextures[0]->asRenderTarget(), |
| 271 dstTexture, | 313 dstTexture, |
| 272 geometryProcessor.get(), | 314 geometryProcessor.get(), |
| 273 stages.get(), | 315 stages.get(), |
| 274 numColorStages, | 316 numColorStages, |
| 275 numCoverageStages, | 317 numCoverageStages, |
| 276 currAttribIndex)) { | 318 currAttribIndex)) { |
| 277 return false; | 319 return false; |
| 278 } | 320 } |
| 279 | 321 |
| 280 SkAutoTUnref<GrGLProgram> program(GrGLProgram::Create(this, | 322 SkAutoTUnref<GrGLProgram> program(GrGLProgram::Create(this, |
| 281 pdesc, | 323 pdesc, |
| 282 geometryProcessor.
get(), | 324 geometryProcessor.
get(), |
| 283 stages, | 325 stages, |
| 284 stages + numColorS
tages)); | 326 stages + numColorS
tages)); |
| 285 for (int s = 0; s < numStages; ++s) { | 327 for (int s = 0; s < numStages; ++s) { |
| 286 SkDELETE(stages[s]); | 328 SkDELETE(stages[s]); |
| 287 } | 329 } |
| 288 if (NULL == program.get()) { | 330 if (NULL == program.get()) { |
| 289 return false; | 331 return false; |
| 290 } | 332 } |
| 333 |
| 334 // We have to reset the drawstate because we might have added a gp |
| 335 this->drawState()->reset(); |
| 291 } | 336 } |
| 292 return true; | 337 return true; |
| 293 } | 338 } |
| 294 | 339 |
| 295 DEF_GPUTEST(GLPrograms, reporter, factory) { | 340 DEF_GPUTEST(GLPrograms, reporter, factory) { |
| 296 for (int type = 0; type < GrContextFactory::kLastGLContextType; ++type) { | 341 for (int type = 0; type < GrContextFactory::kLastGLContextType; ++type) { |
| 297 GrContext* context = factory->get(static_cast<GrContextFactory::GLContex
tType>(type)); | 342 GrContext* context = factory->get(static_cast<GrContextFactory::GLContex
tType>(type)); |
| 298 if (context) { | 343 if (context) { |
| 299 GrGpuGL* gpu = static_cast<GrGpuGL*>(context->getGpu()); | 344 GrGpuGL* gpu = static_cast<GrGpuGL*>(context->getGpu()); |
| 300 int maxStages = 6; | 345 int maxStages = 6; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 328 SkRect::MakeWH(SK_Scalar1, SK_Scalar1), SK_Scalar1)); | 373 SkRect::MakeWH(SK_Scalar1, SK_Scalar1), SK_Scalar1)); |
| 329 GrConfigConversionEffect::Create(NULL, | 374 GrConfigConversionEffect::Create(NULL, |
| 330 false, | 375 false, |
| 331 GrConfigConversionEffect::kNone_PMConversio
n, | 376 GrConfigConversionEffect::kNone_PMConversio
n, |
| 332 SkMatrix::I()); | 377 SkMatrix::I()); |
| 333 SkScalar matrix[20]; | 378 SkScalar matrix[20]; |
| 334 SkAutoTUnref<SkColorMatrixFilter> cmf(SkColorMatrixFilter::Create(matrix)); | 379 SkAutoTUnref<SkColorMatrixFilter> cmf(SkColorMatrixFilter::Create(matrix)); |
| 335 } | 380 } |
| 336 | 381 |
| 337 #endif | 382 #endif |
| OLD | NEW |