Chromium Code Reviews| 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 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 366 0xffff, | 366 0xffff, |
| 367 0xffff); | 367 0xffff); |
| 368 | 368 |
| 369 if (random->nextBool()) { | 369 if (random->nextBool()) { |
| 370 gpu->drawState()->setStencil(kDoesWriteStencil); | 370 gpu->drawState()->setStencil(kDoesWriteStencil); |
| 371 } else { | 371 } else { |
| 372 gpu->drawState()->setStencil(kDoesNotWriteStencil); | 372 gpu->drawState()->setStencil(kDoesNotWriteStencil); |
| 373 } | 373 } |
| 374 } | 374 } |
| 375 | 375 |
| 376 bool GrGpuGL::programUnitTest(int maxStages) { | 376 bool GrDrawTarget::programUnitTest(int maxStages) { |
| 377 GrGpuGL* gpu = static_cast<GrGpuGL*>(fContext->getGpu()); | |
|
bsalomon
2014/11/05 19:13:43
Does this have to be the GL subclass?
joshualitt
2014/11/05 19:55:47
Otherwise we can't build the GL program and we nee
bsalomon
2014/11/05 20:00:22
Gotcha, seems like we're pretty close to making th
| |
| 377 // setup dummy textures | 378 // setup dummy textures |
| 378 GrSurfaceDesc dummyDesc; | 379 GrSurfaceDesc dummyDesc; |
| 379 dummyDesc.fFlags = kRenderTarget_GrSurfaceFlag; | 380 dummyDesc.fFlags = kRenderTarget_GrSurfaceFlag; |
| 380 dummyDesc.fConfig = kSkia8888_GrPixelConfig; | 381 dummyDesc.fConfig = kSkia8888_GrPixelConfig; |
| 381 dummyDesc.fWidth = 34; | 382 dummyDesc.fWidth = 34; |
| 382 dummyDesc.fHeight = 18; | 383 dummyDesc.fHeight = 18; |
| 383 SkAutoTUnref<GrTexture> dummyTexture1(this->createTexture(dummyDesc, NULL, 0 )); | 384 SkAutoTUnref<GrTexture> dummyTexture1(gpu->createTexture(dummyDesc, NULL, 0) ); |
| 384 dummyDesc.fFlags = kNone_GrSurfaceFlags; | 385 dummyDesc.fFlags = kNone_GrSurfaceFlags; |
| 385 dummyDesc.fConfig = kAlpha_8_GrPixelConfig; | 386 dummyDesc.fConfig = kAlpha_8_GrPixelConfig; |
| 386 dummyDesc.fWidth = 16; | 387 dummyDesc.fWidth = 16; |
| 387 dummyDesc.fHeight = 22; | 388 dummyDesc.fHeight = 22; |
| 388 SkAutoTUnref<GrTexture> dummyTexture2(this->createTexture(dummyDesc, NULL, 0 )); | 389 SkAutoTUnref<GrTexture> dummyTexture2(gpu->createTexture(dummyDesc, NULL, 0) ); |
| 389 | 390 |
| 390 if (!dummyTexture1 || ! dummyTexture2) { | 391 if (!dummyTexture1 || ! dummyTexture2) { |
| 391 SkDebugf("Could not allocate dummy textures"); | 392 SkDebugf("Could not allocate dummy textures"); |
| 392 return false; | 393 return false; |
| 393 } | 394 } |
| 394 | 395 |
| 395 GrTexture* dummyTextures[] = {dummyTexture1.get(), dummyTexture2.get()}; | 396 GrTexture* dummyTextures[] = {dummyTexture1.get(), dummyTexture2.get()}; |
| 396 | 397 |
| 397 // Setup texture cache id key | 398 // Setup texture cache id key |
| 398 const GrCacheID::Domain glProgramsDomain = GrCacheID::GenerateDomain(); | 399 const GrCacheID::Domain glProgramsDomain = GrCacheID::GenerateDomain(); |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 411 | 412 |
| 412 // wrap the SkClipStack in a GrClipData | 413 // wrap the SkClipStack in a GrClipData |
| 413 GrClipData clipData; | 414 GrClipData clipData; |
| 414 clipData.fClipStack = &stack; | 415 clipData.fClipStack = &stack; |
| 415 this->setClip(&clipData); | 416 this->setClip(&clipData); |
| 416 | 417 |
| 417 SkRandom random; | 418 SkRandom random; |
| 418 static const int NUM_TESTS = 512; | 419 static const int NUM_TESTS = 512; |
| 419 for (int t = 0; t < NUM_TESTS;) { | 420 for (int t = 0; t < NUM_TESTS;) { |
| 420 // setup random render target(can fail) | 421 // setup random render target(can fail) |
| 421 SkAutoTUnref<GrRenderTarget> rt(random_render_target(this, glProgramsCac heID, &random)); | 422 SkAutoTUnref<GrRenderTarget> rt(random_render_target(gpu, glProgramsCach eID, &random)); |
| 422 if (!rt) { | 423 if (!rt) { |
| 423 SkDebugf("Could not allocate render target"); | 424 SkDebugf("Could not allocate render target"); |
| 424 return false; | 425 return false; |
| 425 } | 426 } |
| 426 | 427 |
| 427 GrDrawState* ds = this->drawState(); | 428 GrDrawState* ds = this->drawState(); |
| 428 ds->setRenderTarget(rt.get()); | 429 ds->setRenderTarget(rt.get()); |
| 429 | 430 |
| 430 // if path rendering we have to setup a couple of things like the draw t ype | 431 // if path rendering we have to setup a couple of things like the draw t ype |
| 431 bool usePathRendering = this->glCaps().pathRenderingSupport() && random. nextBool(); | 432 bool usePathRendering = gpu->glCaps().pathRenderingSupport() && random.n extBool(); |
| 432 | 433 |
| 433 GrGpu::DrawType drawType = usePathRendering ? GrGpu::kDrawPath_DrawType : | 434 GrGpu::DrawType drawType = usePathRendering ? GrGpu::kDrawPath_DrawType : |
| 434 GrGpu::kDrawPoints_DrawTyp e; | 435 GrGpu::kDrawPoints_DrawTyp e; |
| 435 | 436 |
| 436 // twiddle drawstate knobs randomly | 437 // twiddle drawstate knobs randomly |
| 437 bool hasGeometryProcessor = usePathRendering ? false : random.nextBool() ; | 438 bool hasGeometryProcessor = usePathRendering ? false : random.nextBool() ; |
| 438 if (hasGeometryProcessor) { | 439 if (hasGeometryProcessor) { |
| 439 set_random_gp(this, &random, dummyTextures); | 440 set_random_gp(gpu, &random, dummyTextures); |
| 440 } | 441 } |
| 441 set_random_color_coverage_stages(this, maxStages - hasGeometryProcessor, usePathRendering, | 442 set_random_color_coverage_stages(gpu, maxStages - hasGeometryProcessor, usePathRendering, |
| 442 &random, dummyTextures); | 443 &random, dummyTextures); |
| 443 set_random_color(this, &random); | 444 set_random_color(gpu, &random); |
| 444 set_random_coverage(this, &random); | 445 set_random_coverage(gpu, &random); |
| 445 set_random_hints(this, &random); | 446 set_random_hints(gpu, &random); |
| 446 set_random_state(this, &random); | 447 set_random_state(gpu, &random); |
| 447 set_random_blend_func(this, &random); | 448 set_random_blend_func(gpu, &random); |
| 448 set_random_stencil(this, &random); | 449 set_random_stencil(gpu, &random); |
| 449 | 450 |
| 450 GrDeviceCoordTexture dstCopy; | 451 GrDeviceCoordTexture dstCopy; |
| 451 | 452 |
| 452 if (!this->setupDstReadIfNecessary(&dstCopy, NULL)) { | 453 if (!this->setupDstReadIfNecessary(&dstCopy, NULL)) { |
| 453 SkDebugf("Couldn't setup dst read texture"); | 454 SkDebugf("Couldn't setup dst read texture"); |
| 454 return false; | 455 return false; |
| 455 } | 456 } |
| 456 | 457 |
| 457 // create optimized draw state, setup readDst texture if required, and b uild a descriptor | 458 // create optimized draw state, setup readDst texture if required, and b uild a descriptor |
| 458 // and program. ODS creation can fail, so we have to check | 459 // and program. ODS creation can fail, so we have to check |
| 459 SkAutoTUnref<GrOptDrawState> ods(GrOptDrawState::Create(this->getDrawSta te(), | 460 SkAutoTUnref<GrOptDrawState> ods(GrOptDrawState::Create(gpu->getDrawStat e(), |
| 460 this, | 461 gpu, |
| 461 &dstCopy, | 462 &dstCopy, |
| 462 drawType)); | 463 drawType)); |
| 463 if (!ods.get()) { | 464 if (!ods.get()) { |
| 464 ds->reset(); | 465 ds->reset(); |
| 465 continue; | 466 continue; |
| 466 } | 467 } |
| 467 SkAutoTUnref<GrGLProgram> program(GrGLProgramBuilder::CreateProgram(*ods , drawType, this)); | 468 SkAutoTUnref<GrGLProgram> program(GrGLProgramBuilder::CreateProgram(*ods , drawType, gpu)); |
| 468 if (NULL == program.get()) { | 469 if (NULL == program.get()) { |
| 469 SkDebugf("Failed to create program!"); | 470 SkDebugf("Failed to create program!"); |
| 470 return false; | 471 return false; |
| 471 } | 472 } |
| 472 | 473 |
| 473 // We have to reset the drawstate because we might have added a gp | 474 // We have to reset the drawstate because we might have added a gp |
| 474 ds->reset(); | 475 ds->reset(); |
| 475 | 476 |
| 476 // because occasionally optimized drawstate creation will fail for valid reasons, we only | 477 // because occasionally optimized drawstate creation will fail for valid reasons, we only |
| 477 // want to increment on success | 478 // want to increment on success |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 500 maxStages = 1; | 501 maxStages = 1; |
| 501 } else { | 502 } else { |
| 502 return; | 503 return; |
| 503 } | 504 } |
| 504 #if SK_ANGLE | 505 #if SK_ANGLE |
| 505 // Some long shaders run out of temporary registers in the D3D compi ler on ANGLE. | 506 // Some long shaders run out of temporary registers in the D3D compi ler on ANGLE. |
| 506 if (type == GrContextFactory::kANGLE_GLContextType) { | 507 if (type == GrContextFactory::kANGLE_GLContextType) { |
| 507 maxStages = 3; | 508 maxStages = 3; |
| 508 } | 509 } |
| 509 #endif | 510 #endif |
| 510 REPORTER_ASSERT(reporter, gpu->programUnitTest(maxStages)); | 511 GrDrawTarget* dt = static_cast<GrDrawTarget*>(context->getDrawTarget ()); |
| 512 REPORTER_ASSERT(reporter, dt->programUnitTest(maxStages)); | |
| 511 } | 513 } |
| 512 } | 514 } |
| 513 } | 515 } |
| 514 | 516 |
| 515 #endif | 517 #endif |
| OLD | NEW |