bool GrDrawingManager::ProgramUnitTest(GrContext* context, GrDrawTarget* drawTarget, int maxStages) { GrDrawingManager* drawingManager = context->drawingManager(); // setup dummy textures GrSurfaceDesc dummyDesc; dummyDesc.fFlags = kRenderTarget_GrSurfaceFlag; dummyDesc.fConfig = kSkia8888_GrPixelConfig; dummyDesc.fWidth = 34; dummyDesc.fHeight = 18; SkAutoTUnref<GrTexture> dummyTexture1( context->textureProvider()->createTexture(dummyDesc, false, nullptr, 0)); dummyDesc.fFlags = kNone_GrSurfaceFlags; dummyDesc.fConfig = kAlpha_8_GrPixelConfig; dummyDesc.fWidth = 16; dummyDesc.fHeight = 22; SkAutoTUnref<GrTexture> dummyTexture2( context->textureProvider()->createTexture(dummyDesc, false, nullptr, 0)); if (!dummyTexture1 || ! dummyTexture2) { SkDebugf("Could not allocate dummy textures"); return false; } GrTexture* dummyTextures[] = {dummyTexture1.get(), dummyTexture2.get()}; // dummy scissor state GrScissorState scissor; // wide open clip GrClip clip; SkRandom random; static const int NUM_TESTS = 2048; for (int t = 0; t < NUM_TESTS; t++) { // setup random render target(can fail) SkAutoTUnref<GrRenderTarget> rt(random_render_target( context->textureProvider(), &random, context->caps())); if (!rt.get()) { SkDebugf("Could not allocate render target"); return false; } GrPipelineBuilder pipelineBuilder; pipelineBuilder.setRenderTarget(rt.get()); pipelineBuilder.setClip(clip); SkAutoTUnref<GrDrawBatch> batch(GrRandomDrawBatch(&random, context)); SkASSERT(batch); GrProcessorTestData ptd(&random, context, context->caps(), dummyTextures); set_random_color_coverage_stages(&pipelineBuilder, &ptd, maxStages); set_random_xpf(&pipelineBuilder, &ptd); set_random_state(&pipelineBuilder, &random); set_random_stencil(&pipelineBuilder, &random); drawTarget->drawBatch(pipelineBuilder, batch); } // Flush everything, test passes if flush is successful(ie, no asserts are hit, no crashes) drawingManager->flush(); // Validate that GrFPs work correctly without an input. GrSurfaceDesc rtDesc; rtDesc.fWidth = kRenderTargetWidth; rtDesc.fHeight = kRenderTargetHeight; rtDesc.fFlags = kRenderTarget_GrSurfaceFlag; rtDesc.fConfig = kRGBA_8888_GrPixelConfig; SkAutoTUnref<GrRenderTarget> rt( context->textureProvider()->createTexture(rtDesc, false)->asRenderTarget()); int fpFactoryCnt = GrProcessorTestFactory<GrFragmentProcessor>::Count(); for (int i = 0; i < fpFactoryCnt; ++i) { // Since FP factories internally randomize, call each 10 times. for (int j = 0; j < 10; ++j) { SkAutoTUnref<GrDrawBatch> batch(GrRandomDrawBatch(&random, context)); SkASSERT(batch); GrProcessorTestData ptd(&random, context, context->caps(), dummyTextures); GrPipelineBuilder builder; builder.setXPFactory(GrPorterDuffXPFactory::Create(SkXfermode::kSrc_Mode))->unref(); builder.setRenderTarget(rt); builder.setClip(clip); SkAutoTUnref<const GrFragmentProcessor> fp( GrProcessorTestFactory<GrFragmentProcessor>::CreateIdx(i, &ptd)); SkAutoTUnref<const GrFragmentProcessor> blockFP( BlockInputFragmentProcessor::Create(fp)); builder.addColorFragmentProcessor(blockFP); drawTarget->drawBatch(builder, batch); drawingManager->flush(); } } return true; }
bool GrDrawingManager::ProgramUnitTest(GrContext* context, int maxStages) { GrDrawingManager* drawingManager = context->drawingManager(); // setup dummy textures GrSurfaceDesc dummyDesc; dummyDesc.fFlags = kRenderTarget_GrSurfaceFlag; dummyDesc.fConfig = kSkia8888_GrPixelConfig; dummyDesc.fWidth = 34; dummyDesc.fHeight = 18; SkAutoTUnref<GrTexture> dummyTexture1( context->textureProvider()->createTexture(dummyDesc, SkBudgeted::kNo, nullptr, 0)); dummyDesc.fFlags = kNone_GrSurfaceFlags; dummyDesc.fConfig = kAlpha_8_GrPixelConfig; dummyDesc.fWidth = 16; dummyDesc.fHeight = 22; SkAutoTUnref<GrTexture> dummyTexture2( context->textureProvider()->createTexture(dummyDesc, SkBudgeted::kNo, nullptr, 0)); if (!dummyTexture1 || ! dummyTexture2) { SkDebugf("Could not allocate dummy textures"); return false; } GrTexture* dummyTextures[] = {dummyTexture1.get(), dummyTexture2.get()}; // dummy scissor state GrScissorState scissor; SkRandom random; static const int NUM_TESTS = 1024; for (int t = 0; t < NUM_TESTS; t++) { // setup random render target(can fail) sk_sp<GrDrawContext> drawContext(random_draw_context(context, &random, context->caps())); if (!drawContext) { SkDebugf("Could not allocate drawContext"); return false; } GrPaint grPaint; SkAutoTUnref<GrDrawBatch> batch(GrRandomDrawBatch(&random, context)); SkASSERT(batch); GrProcessorTestData ptd(&random, context, context->caps(), drawContext.get(), dummyTextures); set_random_color_coverage_stages(&grPaint, &ptd, maxStages); set_random_xpf(&grPaint, &ptd); bool snapToCenters = set_random_state(&grPaint, &random); const GrUserStencilSettings* uss = get_random_stencil(&random); drawContext->drawContextPriv().testingOnly_drawBatch(grPaint, batch, uss, snapToCenters); } // Flush everything, test passes if flush is successful(ie, no asserts are hit, no crashes) drawingManager->flush(); // Validate that GrFPs work correctly without an input. sk_sp<GrDrawContext> drawContext(context->newDrawContext(SkBackingFit::kExact, kRenderTargetWidth, kRenderTargetHeight, kRGBA_8888_GrPixelConfig)); if (!drawContext) { SkDebugf("Could not allocate a drawContext"); return false; } int fpFactoryCnt = GrProcessorTestFactory<GrFragmentProcessor>::Count(); for (int i = 0; i < fpFactoryCnt; ++i) { // Since FP factories internally randomize, call each 10 times. for (int j = 0; j < 10; ++j) { SkAutoTUnref<GrDrawBatch> batch(GrRandomDrawBatch(&random, context)); SkASSERT(batch); GrProcessorTestData ptd(&random, context, context->caps(), drawContext.get(), dummyTextures); GrPaint grPaint; grPaint.setXPFactory(GrPorterDuffXPFactory::Make(SkXfermode::kSrc_Mode)); sk_sp<GrFragmentProcessor> fp( GrProcessorTestFactory<GrFragmentProcessor>::MakeIdx(i, &ptd)); sk_sp<GrFragmentProcessor> blockFP( BlockInputFragmentProcessor::Make(std::move(fp))); grPaint.addColorFragmentProcessor(std::move(blockFP)); drawContext->drawContextPriv().testingOnly_drawBatch(grPaint, batch); drawingManager->flush(); } } return true; }
bool GrDrawTarget::programUnitTest(GrContext* context, int maxStages) { // setup dummy textures GrSurfaceDesc dummyDesc; dummyDesc.fFlags = kRenderTarget_GrSurfaceFlag; dummyDesc.fConfig = kSkia8888_GrPixelConfig; dummyDesc.fWidth = 34; dummyDesc.fHeight = 18; SkAutoTUnref<GrTexture> dummyTexture1( context->textureProvider()->createTexture(dummyDesc, false, nullptr, 0)); dummyDesc.fFlags = kNone_GrSurfaceFlags; dummyDesc.fConfig = kAlpha_8_GrPixelConfig; dummyDesc.fWidth = 16; dummyDesc.fHeight = 22; SkAutoTUnref<GrTexture> dummyTexture2( context->textureProvider()->createTexture(dummyDesc, false, nullptr, 0)); if (!dummyTexture1 || ! dummyTexture2) { SkDebugf("Could not allocate dummy textures"); return false; } GrTexture* dummyTextures[] = {dummyTexture1.get(), dummyTexture2.get()}; // dummy scissor state GrScissorState scissor; // wide open clip GrClip clip; SkRandom random; static const int NUM_TESTS = 2048; for (int t = 0; t < NUM_TESTS; t++) { // setup random render target(can fail) SkAutoTUnref<GrRenderTarget> rt(random_render_target( context->textureProvider(), &random, this->caps())); if (!rt.get()) { SkDebugf("Could not allocate render target"); return false; } GrPipelineBuilder pipelineBuilder; pipelineBuilder.setRenderTarget(rt.get()); pipelineBuilder.setClip(clip); SkAutoTUnref<GrDrawBatch> batch(GrRandomDrawBatch(&random, context)); SkASSERT(batch); GrProcessorDataManager procDataManager; GrProcessorTestData ptd(&random, context, &procDataManager, fGpu->caps(), dummyTextures); set_random_color_coverage_stages(&pipelineBuilder, &ptd, maxStages); set_random_xpf(&pipelineBuilder, &ptd); set_random_state(&pipelineBuilder, &random); set_random_stencil(&pipelineBuilder, &random); this->drawBatch(pipelineBuilder, batch); } // Flush everything, test passes if flush is successful(ie, no asserts are hit, no crashes) this->flush(); return true; }