| 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 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 421 SkRandom random; | 421 SkRandom random; |
| 422 static const int NUM_TESTS = 512; | 422 static const int NUM_TESTS = 512; |
| 423 for (int t = 0; t < NUM_TESTS;) { | 423 for (int t = 0; t < NUM_TESTS;) { |
| 424 // setup random render target(can fail) | 424 // setup random render target(can fail) |
| 425 SkAutoTUnref<GrRenderTarget> rt(random_render_target(fContext, glProgram
sCacheID, &random)); | 425 SkAutoTUnref<GrRenderTarget> rt(random_render_target(fContext, glProgram
sCacheID, &random)); |
| 426 if (!rt.get()) { | 426 if (!rt.get()) { |
| 427 SkDebugf("Could not allocate render target"); | 427 SkDebugf("Could not allocate render target"); |
| 428 return false; | 428 return false; |
| 429 } | 429 } |
| 430 | 430 |
| 431 GrDrawState* ds = this->drawState(); | 431 GrDrawState ds; |
| 432 ds->setRenderTarget(rt.get()); | 432 ds.setRenderTarget(rt.get()); |
| 433 | 433 |
| 434 // if path rendering we have to setup a couple of things like the draw t
ype | 434 // if path rendering we have to setup a couple of things like the draw t
ype |
| 435 bool usePathRendering = gpu->glCaps().pathRenderingSupport() && random.n
extBool(); | 435 bool usePathRendering = gpu->glCaps().pathRenderingSupport() && random.n
extBool(); |
| 436 | 436 |
| 437 GrGpu::DrawType drawType = usePathRendering ? GrGpu::kDrawPath_DrawType
: | 437 GrGpu::DrawType drawType = usePathRendering ? GrGpu::kDrawPath_DrawType
: |
| 438 GrGpu::kDrawPoints_DrawTyp
e; | 438 GrGpu::kDrawPoints_DrawTyp
e; |
| 439 | 439 |
| 440 // twiddle drawstate knobs randomly | 440 // twiddle drawstate knobs randomly |
| 441 bool hasGeometryProcessor = !usePathRendering; | 441 bool hasGeometryProcessor = !usePathRendering; |
| 442 if (hasGeometryProcessor) { | 442 if (hasGeometryProcessor) { |
| 443 set_random_gp(fContext, gpu->glCaps(), ds, &random, dummyTextures); | 443 set_random_gp(fContext, gpu->glCaps(), &ds, &random, dummyTextures); |
| 444 } | 444 } |
| 445 set_random_color_coverage_stages(gpu, | 445 set_random_color_coverage_stages(gpu, |
| 446 ds, | 446 &ds, |
| 447 maxStages - hasGeometryProcessor, | 447 maxStages - hasGeometryProcessor, |
| 448 usePathRendering, | 448 usePathRendering, |
| 449 &random, | 449 &random, |
| 450 dummyTextures); | 450 dummyTextures); |
| 451 set_random_color(ds, &random); | 451 set_random_color(&ds, &random); |
| 452 set_random_coverage(ds, &random); | 452 set_random_coverage(&ds, &random); |
| 453 set_random_hints(ds, &random); | 453 set_random_hints(&ds, &random); |
| 454 set_random_state(ds, &random); | 454 set_random_state(&ds, &random); |
| 455 set_random_blend_func(ds, &random); | 455 set_random_blend_func(&ds, &random); |
| 456 set_random_stencil(ds, &random); | 456 set_random_stencil(&ds, &random); |
| 457 | 457 |
| 458 GrDeviceCoordTexture dstCopy; | 458 GrDeviceCoordTexture dstCopy; |
| 459 | 459 |
| 460 if (!this->setupDstReadIfNecessary(&dstCopy, NULL)) { | 460 if (!this->setupDstReadIfNecessary(&ds, &dstCopy, NULL)) { |
| 461 SkDebugf("Couldn't setup dst read texture"); | 461 SkDebugf("Couldn't setup dst read texture"); |
| 462 return false; | 462 return false; |
| 463 } | 463 } |
| 464 | 464 |
| 465 // create optimized draw state, setup readDst texture if required, and b
uild a descriptor | 465 // create optimized draw state, setup readDst texture if required, and b
uild a descriptor |
| 466 // and program. ODS creation can fail, so we have to check | 466 // and program. ODS creation can fail, so we have to check |
| 467 SkAutoTUnref<GrOptDrawState> ods(GrOptDrawState::Create(this->getDrawSta
te(), | 467 SkAutoTUnref<GrOptDrawState> ods(GrOptDrawState::Create(gpu, |
| 468 gpu, | 468 ds, |
| 469 &dstCopy, | 469 &dstCopy, |
| 470 drawType)); | 470 drawType)); |
| 471 if (!ods.get()) { | 471 if (!ods.get()) { |
| 472 ds->reset(); | |
| 473 continue; | 472 continue; |
| 474 } | 473 } |
| 475 SkAutoTUnref<GrGLProgram> program(GrGLProgramBuilder::CreateProgram(*ods
, drawType, gpu)); | 474 SkAutoTUnref<GrGLProgram> program(GrGLProgramBuilder::CreateProgram(*ods
, drawType, gpu)); |
| 476 if (NULL == program.get()) { | 475 if (NULL == program.get()) { |
| 477 SkDebugf("Failed to create program!"); | 476 SkDebugf("Failed to create program!"); |
| 478 return false; | 477 return false; |
| 479 } | 478 } |
| 480 | 479 |
| 481 // We have to reset the drawstate because we might have added a gp | |
| 482 ds->reset(); | |
| 483 | |
| 484 // because occasionally optimized drawstate creation will fail for valid
reasons, we only | 480 // because occasionally optimized drawstate creation will fail for valid
reasons, we only |
| 485 // want to increment on success | 481 // want to increment on success |
| 486 ++t; | 482 ++t; |
| 487 } | 483 } |
| 488 return true; | 484 return true; |
| 489 } | 485 } |
| 490 | 486 |
| 491 DEF_GPUTEST(GLPrograms, reporter, factory) { | 487 DEF_GPUTEST(GLPrograms, reporter, factory) { |
| 492 for (int type = 0; type < GrContextFactory::kLastGLContextType; ++type) { | 488 for (int type = 0; type < GrContextFactory::kLastGLContextType; ++type) { |
| 493 GrContext* context = factory->get(static_cast<GrContextFactory::GLContex
tType>(type)); | 489 GrContext* context = factory->get(static_cast<GrContextFactory::GLContex
tType>(type)); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 516 } | 512 } |
| 517 #endif | 513 #endif |
| 518 GrTestTarget target; | 514 GrTestTarget target; |
| 519 context->getTestTarget(&target); | 515 context->getTestTarget(&target); |
| 520 REPORTER_ASSERT(reporter, target.target()->programUnitTest(maxStages
)); | 516 REPORTER_ASSERT(reporter, target.target()->programUnitTest(maxStages
)); |
| 521 } | 517 } |
| 522 } | 518 } |
| 523 } | 519 } |
| 524 | 520 |
| 525 #endif | 521 #endif |
| OLD | NEW |