Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(923)

Side by Side Diff: tests/GLProgramsTest.cpp

Issue 732693002: Drawstate on stack (Closed) Base URL: https://skia.googlesource.com/skia.git@real_def_gp
Patch Set: tiny fix Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/gpu/gl/GrGpuGL.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 411 matching lines...) Expand 10 before | Expand all | Expand 10 after
422 SkRandom random; 422 SkRandom random;
423 static const int NUM_TESTS = 512; 423 static const int NUM_TESTS = 512;
424 for (int t = 0; t < NUM_TESTS;) { 424 for (int t = 0; t < NUM_TESTS;) {
425 // setup random render target(can fail) 425 // setup random render target(can fail)
426 SkAutoTUnref<GrRenderTarget> rt(random_render_target(fContext, glProgram sCacheID, &random)); 426 SkAutoTUnref<GrRenderTarget> rt(random_render_target(fContext, glProgram sCacheID, &random));
427 if (!rt.get()) { 427 if (!rt.get()) {
428 SkDebugf("Could not allocate render target"); 428 SkDebugf("Could not allocate render target");
429 return false; 429 return false;
430 } 430 }
431 431
432 GrDrawState* ds = this->drawState(); 432 GrDrawState ds;
433 ds->setRenderTarget(rt.get()); 433 ds.setRenderTarget(rt.get());
434 434
435 // if path rendering we have to setup a couple of things like the draw t ype 435 // if path rendering we have to setup a couple of things like the draw t ype
436 bool usePathRendering = gpu->glCaps().pathRenderingSupport() && random.n extBool(); 436 bool usePathRendering = gpu->glCaps().pathRenderingSupport() && random.n extBool();
437 437
438 GrGpu::DrawType drawType = usePathRendering ? GrGpu::kDrawPath_DrawType : 438 GrGpu::DrawType drawType = usePathRendering ? GrGpu::kDrawPath_DrawType :
439 GrGpu::kDrawPoints_DrawTyp e; 439 GrGpu::kDrawPoints_DrawTyp e;
440 440
441 // twiddle drawstate knobs randomly 441 // twiddle drawstate knobs randomly
442 bool hasGeometryProcessor = !usePathRendering; 442 bool hasGeometryProcessor = !usePathRendering;
443 if (hasGeometryProcessor) { 443 if (hasGeometryProcessor) {
444 set_random_gp(fContext, gpu->glCaps(), ds, &random, dummyTextures); 444 set_random_gp(fContext, gpu->glCaps(), &ds, &random, dummyTextures);
445 } 445 }
446 set_random_color_coverage_stages(gpu, 446 set_random_color_coverage_stages(gpu,
447 ds, 447 &ds,
448 maxStages - hasGeometryProcessor, 448 maxStages - hasGeometryProcessor,
449 usePathRendering, 449 usePathRendering,
450 &random, 450 &random,
451 dummyTextures); 451 dummyTextures);
452 set_random_color(ds, &random); 452 set_random_color(&ds, &random);
453 set_random_coverage(ds, &random); 453 set_random_coverage(&ds, &random);
454 set_random_hints(ds, &random); 454 set_random_hints(&ds, &random);
455 set_random_state(ds, &random); 455 set_random_state(&ds, &random);
456 set_random_blend_func(ds, &random); 456 set_random_blend_func(&ds, &random);
457 set_random_stencil(ds, &random); 457 set_random_stencil(&ds, &random);
458 458
459 GrDeviceCoordTexture dstCopy; 459 GrDeviceCoordTexture dstCopy;
460 460
461 if (!this->setupDstReadIfNecessary(&dstCopy, NULL)) { 461 if (!this->setupDstReadIfNecessary(&ds, &dstCopy, NULL)) {
462 SkDebugf("Couldn't setup dst read texture"); 462 SkDebugf("Couldn't setup dst read texture");
463 return false; 463 return false;
464 } 464 }
465 465
466 // create optimized draw state, setup readDst texture if required, and b uild a descriptor 466 // create optimized draw state, setup readDst texture if required, and b uild a descriptor
467 // and program. ODS creation can fail, so we have to check 467 // and program. ODS creation can fail, so we have to check
468 SkAutoTUnref<GrOptDrawState> ods(GrOptDrawState::Create(this->getDrawSta te(), 468 SkAutoTUnref<GrOptDrawState> ods(GrOptDrawState::Create(ds,
469 gpu, 469 gpu,
470 &dstCopy, 470 &dstCopy,
471 drawType)); 471 drawType));
472 if (!ods.get()) { 472 if (!ods.get()) {
473 ds->reset();
474 continue; 473 continue;
475 } 474 }
476 SkAutoTUnref<GrGLProgram> program(GrGLProgramBuilder::CreateProgram(*ods , drawType, gpu)); 475 SkAutoTUnref<GrGLProgram> program(GrGLProgramBuilder::CreateProgram(*ods , drawType, gpu));
477 if (NULL == program.get()) { 476 if (NULL == program.get()) {
478 SkDebugf("Failed to create program!"); 477 SkDebugf("Failed to create program!");
479 return false; 478 return false;
480 } 479 }
481 480
482 // We have to reset the drawstate because we might have added a gp
483 ds->reset();
484
485 // because occasionally optimized drawstate creation will fail for valid reasons, we only 481 // because occasionally optimized drawstate creation will fail for valid reasons, we only
486 // want to increment on success 482 // want to increment on success
487 ++t; 483 ++t;
488 } 484 }
489 return true; 485 return true;
490 } 486 }
491 487
492 DEF_GPUTEST(GLPrograms, reporter, factory) { 488 DEF_GPUTEST(GLPrograms, reporter, factory) {
493 for (int type = 0; type < GrContextFactory::kLastGLContextType; ++type) { 489 for (int type = 0; type < GrContextFactory::kLastGLContextType; ++type) {
494 GrContext* context = factory->get(static_cast<GrContextFactory::GLContex tType>(type)); 490 GrContext* context = factory->get(static_cast<GrContextFactory::GLContex tType>(type));
(...skipping 22 matching lines...) Expand all
517 } 513 }
518 #endif 514 #endif
519 GrTestTarget target; 515 GrTestTarget target;
520 context->getTestTarget(&target); 516 context->getTestTarget(&target);
521 REPORTER_ASSERT(reporter, target.target()->programUnitTest(maxStages )); 517 REPORTER_ASSERT(reporter, target.target()->programUnitTest(maxStages ));
522 } 518 }
523 } 519 }
524 } 520 }
525 521
526 #endif 522 #endif
OLDNEW
« no previous file with comments | « src/gpu/gl/GrGpuGL.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698