| 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 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 } | 122 } |
| 123 | 123 |
| 124 static void set_random_xpf(GrContext* context, const GrDrawTargetCaps& caps, GrD
rawState* ds, | 124 static void set_random_xpf(GrContext* context, const GrDrawTargetCaps& caps, GrD
rawState* ds, |
| 125 SkRandom* random, GrTexture* dummyTextures[]) { | 125 SkRandom* random, GrTexture* dummyTextures[]) { |
| 126 SkAutoTUnref<const GrXPFactory> xpf( | 126 SkAutoTUnref<const GrXPFactory> xpf( |
| 127 GrProcessorTestFactory<GrXPFactory>::CreateStage(random, context, caps,
dummyTextures)); | 127 GrProcessorTestFactory<GrXPFactory>::CreateStage(random, context, caps,
dummyTextures)); |
| 128 SkASSERT(xpf); | 128 SkASSERT(xpf); |
| 129 ds->setXPFactory(xpf.get()); | 129 ds->setXPFactory(xpf.get()); |
| 130 } | 130 } |
| 131 | 131 |
| 132 static const GrGeometryProcessor* get_random_gp(GrContext* context, | 132 static void set_random_gp(GrContext* context, |
| 133 const GrDrawTargetCaps& caps, | 133 const GrDrawTargetCaps& caps, |
| 134 SkRandom* random, | 134 GrDrawState* ds, |
| 135 GrTexture* dummyTextures[]) { | 135 SkRandom* random, |
| 136 return GrProcessorTestFactory<GrGeometryProcessor>::CreateStage(random, | 136 GrTexture* dummyTextures[]) { |
| 137 context, | 137 SkAutoTUnref<const GrGeometryProcessor> gp( |
| 138 caps, | 138 GrProcessorTestFactory<GrGeometryProcessor>::CreateStage(random, |
| 139 dummyTexture
s); | 139 context, |
| 140 caps, |
| 141 dummyTextur
es)); |
| 142 SkASSERT(gp); |
| 143 |
| 144 ds->setGeometryProcessor(gp); |
| 140 } | 145 } |
| 141 | 146 |
| 142 static void set_random_color_coverage_stages(GrGpuGL* gpu, | 147 static void set_random_color_coverage_stages(GrGpuGL* gpu, |
| 143 GrDrawState* ds, | 148 GrDrawState* ds, |
| 144 int maxStages, | 149 int maxStages, |
| 145 bool usePathRendering, | 150 bool usePathRendering, |
| 146 SkRandom* random, | 151 SkRandom* random, |
| 147 GrTexture* dummyTextures[]) { | 152 GrTexture* dummyTextures[]) { |
| 148 int numProcs = random->nextULessThan(maxStages + 1); | 153 int numProcs = random->nextULessThan(maxStages + 1); |
| 149 int numColorProcs = random->nextULessThan(numProcs + 1); | 154 int numColorProcs = random->nextULessThan(numProcs + 1); |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 281 ds.setRenderTarget(rt.get()); | 286 ds.setRenderTarget(rt.get()); |
| 282 | 287 |
| 283 // if path rendering we have to setup a couple of things like the draw t
ype | 288 // if path rendering we have to setup a couple of things like the draw t
ype |
| 284 bool usePathRendering = gpu->glCaps().pathRenderingSupport() && random.n
extBool(); | 289 bool usePathRendering = gpu->glCaps().pathRenderingSupport() && random.n
extBool(); |
| 285 | 290 |
| 286 GrGpu::DrawType drawType = usePathRendering ? GrGpu::kDrawPath_DrawType
: | 291 GrGpu::DrawType drawType = usePathRendering ? GrGpu::kDrawPath_DrawType
: |
| 287 GrGpu::kDrawPoints_DrawTyp
e; | 292 GrGpu::kDrawPoints_DrawTyp
e; |
| 288 | 293 |
| 289 // twiddle drawstate knobs randomly | 294 // twiddle drawstate knobs randomly |
| 290 bool hasGeometryProcessor = !usePathRendering; | 295 bool hasGeometryProcessor = !usePathRendering; |
| 291 const GrGeometryProcessor* gp = NULL; | |
| 292 const GrPathProcessor* pathProc = NULL; | |
| 293 if (hasGeometryProcessor) { | 296 if (hasGeometryProcessor) { |
| 294 gp = get_random_gp(fContext, gpu->glCaps(), &random, dummyTextures); | 297 set_random_gp(fContext, gpu->glCaps(), &ds, &random, dummyTextures); |
| 295 } else { | |
| 296 pathProc = GrPathProcessor::Create(GrColor_WHITE); | |
| 297 } | 298 } |
| 298 set_random_color_coverage_stages(gpu, | 299 set_random_color_coverage_stages(gpu, |
| 299 &ds, | 300 &ds, |
| 300 maxStages - hasGeometryProcessor, | 301 maxStages - hasGeometryProcessor, |
| 301 usePathRendering, | 302 usePathRendering, |
| 302 &random, | 303 &random, |
| 303 dummyTextures); | 304 dummyTextures); |
| 304 | 305 |
| 305 // creates a random xfer processor factory on the draw state | 306 // creates a random xfer processor factory on the draw state |
| 306 set_random_xpf(fContext, gpu->glCaps(), &ds, &random, dummyTextures); | 307 set_random_xpf(fContext, gpu->glCaps(), &ds, &random, dummyTextures); |
| 307 | 308 |
| 308 set_random_hints(&ds, &random); | 309 set_random_hints(&ds, &random); |
| 309 set_random_state(&ds, &random); | 310 set_random_state(&ds, &random); |
| 310 set_random_stencil(&ds, &random); | 311 set_random_stencil(&ds, &random); |
| 311 | 312 |
| 312 GrDeviceCoordTexture dstCopy; | 313 GrDeviceCoordTexture dstCopy; |
| 313 | 314 |
| 314 const GrPrimitiveProcessor* primProc; | 315 // TODO take color off the PP when its installed |
| 315 if (hasGeometryProcessor) { | 316 GrColor color = ds.hasGeometryProcessor() ? ds.getGeometryProcessor()->g
etColor() : |
| 316 primProc = gp; | 317 GrColor_WHITE; |
| 317 } else { | 318 uint8_t coverage = ds.hasGeometryProcessor() ? ds.getGeometryProcessor()
->getCoverage() : |
| 318 primProc = pathProc; | 319 0xff; |
| 319 } | 320 if (!this->setupDstReadIfNecessary(&ds, color, coverage, &dstCopy, NULL)
) { |
| 320 if (!this->setupDstReadIfNecessary(&ds, primProc, &dstCopy, NULL)) { | |
| 321 SkDebugf("Couldn't setup dst read texture"); | 321 SkDebugf("Couldn't setup dst read texture"); |
| 322 return false; | 322 return false; |
| 323 } | 323 } |
| 324 | 324 |
| 325 // create optimized draw state, setup readDst texture if required, and b
uild a descriptor | 325 // create optimized draw state, setup readDst texture if required, and b
uild a descriptor |
| 326 // and program. ODS creation can fail, so we have to check | 326 // and program. ODS creation can fail, so we have to check |
| 327 GrOptDrawState ods(ds, gp, pathProc, *gpu->caps(), scissor, &dstCopy, dr
awType); | 327 GrOptDrawState ods(ds, color, coverage, *gpu->caps(), scissor, &dstCopy,
drawType); |
| 328 if (ods.mustSkip()) { | 328 if (ods.mustSkip()) { |
| 329 continue; | 329 continue; |
| 330 } | 330 } |
| 331 ods.finalize(gpu); | 331 ods.finalize(gpu); |
| 332 SkAutoTUnref<GrGLProgram> program(GrGLProgramBuilder::CreateProgram(ods,
gpu)); | 332 SkAutoTUnref<GrGLProgram> program(GrGLProgramBuilder::CreateProgram(ods,
gpu)); |
| 333 if (NULL == program.get()) { | 333 if (NULL == program.get()) { |
| 334 SkDebugf("Failed to create program!"); | 334 SkDebugf("Failed to create program!"); |
| 335 return false; | 335 return false; |
| 336 } | 336 } |
| 337 | 337 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 } | 370 } |
| 371 #endif | 371 #endif |
| 372 GrTestTarget target; | 372 GrTestTarget target; |
| 373 context->getTestTarget(&target); | 373 context->getTestTarget(&target); |
| 374 REPORTER_ASSERT(reporter, target.target()->programUnitTest(maxStages
)); | 374 REPORTER_ASSERT(reporter, target.target()->programUnitTest(maxStages
)); |
| 375 } | 375 } |
| 376 } | 376 } |
| 377 } | 377 } |
| 378 | 378 |
| 379 #endif | 379 #endif |
| OLD | NEW |