// Tests that GrSurface::asTexture(), GrSurface::asRenderTarget(), and static upcasting of texture // and render targets to GrSurface all work as expected. DEF_GPUTEST_FOR_NULLGL_CONTEXT(GrSurface, reporter, ctxInfo) { GrContext* context = ctxInfo.grContext(); GrSurfaceDesc desc; desc.fConfig = kSkia8888_GrPixelConfig; desc.fFlags = kRenderTarget_GrSurfaceFlag; desc.fWidth = 256; desc.fHeight = 256; desc.fSampleCnt = 0; GrSurface* texRT1 = context->textureProvider()->createTexture( desc, SkBudgeted::kNo, nullptr, 0); REPORTER_ASSERT(reporter, texRT1 == texRT1->asRenderTarget()); REPORTER_ASSERT(reporter, texRT1 == texRT1->asTexture()); REPORTER_ASSERT(reporter, static_cast<GrSurface*>(texRT1->asRenderTarget()) == texRT1->asTexture()); REPORTER_ASSERT(reporter, texRT1->asRenderTarget() == static_cast<GrSurface*>(texRT1->asTexture())); REPORTER_ASSERT(reporter, static_cast<GrSurface*>(texRT1->asRenderTarget()) == static_cast<GrSurface*>(texRT1->asTexture())); desc.fFlags = kNone_GrSurfaceFlags; GrSurface* tex1 = context->textureProvider()->createTexture(desc, SkBudgeted::kNo, nullptr, 0); REPORTER_ASSERT(reporter, nullptr == tex1->asRenderTarget()); REPORTER_ASSERT(reporter, tex1 == tex1->asTexture()); REPORTER_ASSERT(reporter, static_cast<GrSurface*>(tex1) == tex1->asTexture()); GrBackendObject backendTex = context->getGpu()->createTestingOnlyBackendTexture( nullptr, 256, 256, kSkia8888_GrPixelConfig); GrBackendTextureDesc backendDesc; backendDesc.fConfig = kSkia8888_GrPixelConfig; backendDesc.fFlags = kRenderTarget_GrBackendTextureFlag; backendDesc.fWidth = 256; backendDesc.fHeight = 256; backendDesc.fSampleCnt = 0; backendDesc.fTextureHandle = backendTex; GrSurface* texRT2 = context->textureProvider()->wrapBackendTexture( backendDesc, kBorrow_GrWrapOwnership); REPORTER_ASSERT(reporter, texRT2 == texRT2->asRenderTarget()); REPORTER_ASSERT(reporter, texRT2 == texRT2->asTexture()); REPORTER_ASSERT(reporter, static_cast<GrSurface*>(texRT2->asRenderTarget()) == texRT2->asTexture()); REPORTER_ASSERT(reporter, texRT2->asRenderTarget() == static_cast<GrSurface*>(texRT2->asTexture())); REPORTER_ASSERT(reporter, static_cast<GrSurface*>(texRT2->asRenderTarget()) == static_cast<GrSurface*>(texRT2->asTexture())); texRT1->unref(); texRT2->unref(); tex1->unref(); context->getGpu()->deleteTestingOnlyBackendTexture(backendTex); }
GrTexture* GrTextureAdjuster::refTextureSafeForParams(const GrTextureParams& params, SkIPoint* outOffset) { GrTexture* texture = this->originalTexture(); GrContext* context = texture->getContext(); CopyParams copyParams; const SkIRect* contentArea = this->contentAreaOrNull(); if (contentArea && GrTextureParams::kMipMap_FilterMode == params.filterMode()) { // If we generate a MIP chain for texture it will read pixel values from outside the content // area. copyParams.fWidth = contentArea->width(); copyParams.fHeight = contentArea->height(); copyParams.fFilter = GrTextureParams::kBilerp_FilterMode; } else if (!context->getGpu()->makeCopyForTextureParams(texture, params, ©Params)) { if (outOffset) { if (contentArea) { outOffset->set(contentArea->fLeft, contentArea->fRight); } else { outOffset->set(0, 0); } } return SkRef(texture); } GrTexture* copy = this->refCopy(copyParams); if (copy && outOffset) { outOffset->set(0, 0); } return copy; }
static int get_glprograms_max_stages(const sk_gpu_test::ContextInfo& ctxInfo) { GrContext* context = ctxInfo.grContext(); GrGLGpu* gpu = static_cast<GrGLGpu*>(context->getGpu()); int maxStages = 6; if (kGLES_GrGLStandard == gpu->glStandard()) { // We've had issues with driver crashes and HW limits being exceeded with many effects on // Android devices. We have passes on ARM devices with the default number of stages. // TODO When we run ES 3.00 GLSL in more places, test again #ifdef SK_BUILD_FOR_ANDROID if (kARM_GrGLVendor != gpu->ctxInfo().vendor()) { maxStages = 1; } #endif // On iOS we can exceed the maximum number of varyings. http://skbug.com/6627. #ifdef SK_BUILD_FOR_IOS maxStages = 3; #endif } if (ctxInfo.type() == sk_gpu_test::GrContextFactory::kANGLE_D3D9_ES2_ContextType || ctxInfo.type() == sk_gpu_test::GrContextFactory::kANGLE_D3D11_ES2_ContextType) { // On Angle D3D we will hit a limit of out variables if we use too many stages. maxStages = 3; } return maxStages; }
DEF_GPUTEST(GLPrograms, reporter, factory) { // Set a locale that would cause shader compilation to fail because of , as decimal separator. // skbug 3330 #ifdef SK_BUILD_FOR_WIN GrAutoLocaleSetter als("sv-SE"); #else GrAutoLocaleSetter als("sv_SE.UTF-8"); #endif // We suppress prints to avoid spew GrContextOptions opts; opts.fSuppressPrints = true; GrContextFactory debugFactory(opts); for (int type = 0; type < GrContextFactory::kLastGLContextType; ++type) { GrContext* context = debugFactory.get(static_cast<GrContextFactory::GLContextType>(type)); if (context) { GrGLGpu* gpu = static_cast<GrGLGpu*>(context->getGpu()); /* * For the time being, we only support the test with desktop GL or for android on * ARM platforms * TODO When we run ES 3.00 GLSL in more places, test again */ int maxStages; if (kGL_GrGLStandard == gpu->glStandard() || kARM_GrGLVendor == gpu->ctxInfo().vendor()) { maxStages = 6; } else if (kTegra3_GrGLRenderer == gpu->ctxInfo().renderer() || kOther_GrGLRenderer == gpu->ctxInfo().renderer()) { maxStages = 1; } else { return; } #if SK_ANGLE // Some long shaders run out of temporary registers in the D3D compiler on ANGLE. if (type == GrContextFactory::kANGLE_GLContextType) { maxStages = 2; } #endif #if SK_COMMAND_BUFFER // Some long shaders run out of temporary registers in the D3D compiler on ANGLE. // TODO(hendrikw): This only needs to happen with the ANGLE comand buffer backend. if (type == GrContextFactory::kCommandBuffer_GLContextType) { maxStages = 2; } #endif GrTestTarget testTarget; context->getTestTarget(&testTarget); REPORTER_ASSERT(reporter, GrDrawingManager::ProgramUnitTest( context, testTarget.target(), maxStages)); } } }
DEF_GPUTEST(GLPrograms, reporter, factory) { for (int type = 0; type < GrContextFactory::kLastGLContextType; ++type) { GrContext* context = factory->get(static_cast<GrContextFactory::GLContextType>(type)); if (context) { GrGpuGL* gpu = static_cast<GrGpuGL*>(context->getGpu()); int maxStages = 6; #if SK_ANGLE // Some long shaders run out of temporary registers in the D3D compiler on ANGLE. if (type == GrContextFactory::kANGLE_GLContextType) { maxStages = 3; } #endif REPORTER_ASSERT(reporter, gpu->programUnitTest(maxStages)); } } }
DEF_GPUTEST_FOR_ALL_GL_CONTEXTS(VertexAttributeCount, reporter, ctxInfo) { GrContext* context = ctxInfo.fGrContext; GrTextureDesc desc; desc.fHeight = 1; desc.fWidth = 1; desc.fFlags = kRenderTarget_GrSurfaceFlag; desc.fConfig = kRGBA_8888_GrPixelConfig; SkAutoTUnref<GrTexture> target(context->textureProvider()->createTexture(desc, SkBudgeted::kYes)); if (!target) { ERRORF(reporter, "Could not create render target."); return; } SkAutoTUnref<GrDrawContext> dc(context->drawContext(target->asRenderTarget())); if (!dc) { ERRORF(reporter, "Could not create draw context."); return; } int attribCnt = context->caps()->maxVertexAttributes(); if (!attribCnt) { ERRORF(reporter, "No attributes allowed?!"); return; } context->flush(); context->resetGpuStats(); #if GR_GPU_STATS REPORTER_ASSERT(reporter, context->getGpu()->stats()->numDraws() == 0); REPORTER_ASSERT(reporter, context->getGpu()->stats()->numFailedDraws() == 0); #endif SkAutoTUnref<GrDrawBatch> batch; GrPipelineBuilder pb; pb.setRenderTarget(target->asRenderTarget()); // This one should succeed. batch.reset(new Batch(attribCnt)); dc->drawContextPriv().testingOnly_drawBatch(pb, batch); context->flush(); #if GR_GPU_STATS REPORTER_ASSERT(reporter, context->getGpu()->stats()->numDraws() == 1); REPORTER_ASSERT(reporter, context->getGpu()->stats()->numFailedDraws() == 0); #endif context->resetGpuStats(); // This one should fail. batch.reset(new Batch(attribCnt+1)); dc->drawContextPriv().testingOnly_drawBatch(pb, batch); context->flush(); #if GR_GPU_STATS REPORTER_ASSERT(reporter, context->getGpu()->stats()->numDraws() == 0); REPORTER_ASSERT(reporter, context->getGpu()->stats()->numFailedDraws() == 1); #endif }
void SKPBench::getGpuStats(SkCanvas* canvas, SkTArray<SkString>* keys, SkTArray<double>* values) { #if SK_SUPPORT_GPU // we do a special single draw and then dump the key / value pairs GrContext* context = canvas->getGrContext(); if (!context) { return; } // TODO refactor this out if we want to test other subclasses of skpbench context->flush(); context->freeGpuResources(); context->resetContext(); context->getGpu()->resetShaderCacheForTesting(); draw_pic_for_stats(canvas, context, fPic, keys, values, "first_frame"); // draw second frame draw_pic_for_stats(canvas, context, fPic, keys, values, "second_frame"); #endif }
DEF_GPUTEST_FOR_ALL_CONTEXTS(VertexAttributeCount, reporter, ctxInfo) { GrContext* context = ctxInfo.grContext(); sk_sp<GrDrawContext> drawContext(context->newDrawContext(SkBackingFit::kApprox, 1, 1, kRGBA_8888_GrPixelConfig)); if (!drawContext) { ERRORF(reporter, "Could not create draw context."); return; } int attribCnt = context->caps()->maxVertexAttributes(); if (!attribCnt) { ERRORF(reporter, "No attributes allowed?!"); return; } context->flush(); context->resetGpuStats(); #if GR_GPU_STATS REPORTER_ASSERT(reporter, context->getGpu()->stats()->numDraws() == 0); REPORTER_ASSERT(reporter, context->getGpu()->stats()->numFailedDraws() == 0); #endif SkAutoTUnref<GrDrawBatch> batch; GrPaint grPaint; // This one should succeed. batch.reset(new Batch(attribCnt)); drawContext->drawContextPriv().testingOnly_drawBatch(grPaint, batch); context->flush(); #if GR_GPU_STATS REPORTER_ASSERT(reporter, context->getGpu()->stats()->numDraws() == 1); REPORTER_ASSERT(reporter, context->getGpu()->stats()->numFailedDraws() == 0); #endif context->resetGpuStats(); // This one should fail. batch.reset(new Batch(attribCnt+1)); drawContext->drawContextPriv().testingOnly_drawBatch(grPaint, batch); context->flush(); #if GR_GPU_STATS REPORTER_ASSERT(reporter, context->getGpu()->stats()->numDraws() == 0); REPORTER_ASSERT(reporter, context->getGpu()->stats()->numFailedDraws() == 1); #endif }
DEF_GPUTEST_FOR_ALL_CONTEXTS(VertexAttributeCount, reporter, ctxInfo) { GrContext* context = ctxInfo.grContext(); sk_sp<GrRenderTargetContext> renderTargetContext(context->makeDeferredRenderTargetContext( SkBackingFit::kApprox, 1, 1, kRGBA_8888_GrPixelConfig, nullptr)); if (!renderTargetContext) { ERRORF(reporter, "Could not create render target context."); return; } int attribCnt = context->caps()->maxVertexAttributes(); if (!attribCnt) { ERRORF(reporter, "No attributes allowed?!"); return; } context->flush(); context->resetGpuStats(); #if GR_GPU_STATS REPORTER_ASSERT(reporter, context->getGpu()->stats()->numDraws() == 0); REPORTER_ASSERT(reporter, context->getGpu()->stats()->numFailedDraws() == 0); #endif GrPaint grPaint; // This one should succeed. renderTargetContext->priv().testingOnly_addDrawOp(Op::Make(attribCnt)); context->flush(); #if GR_GPU_STATS REPORTER_ASSERT(reporter, context->getGpu()->stats()->numDraws() == 1); REPORTER_ASSERT(reporter, context->getGpu()->stats()->numFailedDraws() == 0); #endif context->resetGpuStats(); renderTargetContext->priv().testingOnly_addDrawOp(Op::Make(attribCnt + 1)); context->flush(); #if GR_GPU_STATS REPORTER_ASSERT(reporter, context->getGpu()->stats()->numDraws() == 0); REPORTER_ASSERT(reporter, context->getGpu()->stats()->numFailedDraws() == 1); #endif }