From f865b05fe50ca2c094b9c60e4405c6094415b4f6 Mon Sep 17 00:00:00 2001 From: Brian Salomon Date: Fri, 9 Mar 2018 09:01:53 -0500 Subject: Add GM configs that test rendering to a GL backend texture and render target This also adds GrGpu::create/deleteTestingOnlyBackendRenderTarget. Implemented in GL only for now. Change-Id: I9e5fdc953c4a249959af89e08332f520cefe9d90 Reviewed-on: https://skia-review.googlesource.com/113305 Reviewed-by: Greg Daniel Commit-Queue: Brian Salomon --- dm/DM.cpp | 20 ++++++++--------- dm/DMGpuSupport.h | 27 +++++------------------ dm/DMSrcSink.cpp | 64 ++++++++++++++++++++++++++++++++++++++++++++++--------- dm/DMSrcSink.h | 8 +++++-- 4 files changed, 75 insertions(+), 44 deletions(-) (limited to 'dm') diff --git a/dm/DM.cpp b/dm/DM.cpp index 972c70d484..6f2025f4b9 100644 --- a/dm/DM.cpp +++ b/dm/DM.cpp @@ -884,17 +884,17 @@ static Sink* create_sink(const GrContextOptions& grCtxOptions, const SkCommandLi return nullptr; } if (gpuConfig->getTestThreading()) { - return new GPUThreadTestingSink(contextType, contextOverrides, - gpuConfig->getSamples(), gpuConfig->getUseDIText(), - gpuConfig->getColorType(), - gpuConfig->getAlphaType(), - sk_ref_sp(gpuConfig->getColorSpace()), - FLAGS_gpu_threading, grCtxOptions); + return new GPUThreadTestingSink( + contextType, contextOverrides, gpuConfig->getSurfType(), + gpuConfig->getSamples(), gpuConfig->getUseDIText(), + gpuConfig->getColorType(), gpuConfig->getAlphaType(), + sk_ref_sp(gpuConfig->getColorSpace()), FLAGS_gpu_threading, grCtxOptions); } else { - return new GPUSink(contextType, contextOverrides, gpuConfig->getSamples(), - gpuConfig->getUseDIText(), gpuConfig->getColorType(), - gpuConfig->getAlphaType(), sk_ref_sp(gpuConfig->getColorSpace()), - FLAGS_gpu_threading, grCtxOptions); + return new GPUSink(contextType, contextOverrides, gpuConfig->getSurfType(), + gpuConfig->getSamples(), gpuConfig->getUseDIText(), + gpuConfig->getColorType(), gpuConfig->getAlphaType(), + sk_ref_sp(gpuConfig->getColorSpace()), FLAGS_gpu_threading, + grCtxOptions); } } } diff --git a/dm/DMGpuSupport.h b/dm/DMGpuSupport.h index a552d69f70..1ed00953c1 100644 --- a/dm/DMGpuSupport.h +++ b/dm/DMGpuSupport.h @@ -28,19 +28,6 @@ namespace DM { static const bool kGPUDisabled = false; -static inline sk_sp NewGpuSurface( - sk_gpu_test::GrContextFactory* grFactory, - sk_gpu_test::GrContextFactory::ContextType type, - sk_gpu_test::GrContextFactory::ContextOverrides overrides, - SkImageInfo info, - int samples, - bool useDIText) { - uint32_t flags = useDIText ? SkSurfaceProps::kUseDeviceIndependentFonts_Flag : 0; - SkSurfaceProps props(flags, SkSurfaceProps::kLegacyFontHost_InitType); - return SkSurface::MakeRenderTarget(grFactory->get(type, overrides), SkBudgeted::kNo, - info, samples, &props); -} - } // namespace DM #else// !SK_SUPPORT_GPU @@ -60,6 +47,11 @@ public: void dumpGpuStats(SkString*) const {} }; +class SkCommandLineConfigGpu { +public: + enum class SurfType; +}; + namespace sk_gpu_test { class GrContextFactory { public: @@ -93,15 +85,6 @@ namespace DM { static const bool kGPUDisabled = true; -static inline SkSurface* NewGpuSurface(sk_gpu_test::GrContextFactory*, - sk_gpu_test::GrContextFactory::ContextType, - sk_gpu_test::GrContextFactory::ContextOverrides, - SkImageInfo, - int, - bool) { - return nullptr; -} - } // namespace DM #endif//SK_SUPPORT_GPU diff --git a/dm/DMSrcSink.cpp b/dm/DMSrcSink.cpp index b84563701c..0fedd8e7ec 100644 --- a/dm/DMSrcSink.cpp +++ b/dm/DMSrcSink.cpp @@ -6,6 +6,9 @@ */ #include "DMSrcSink.h" +#include +#include +#include "../src/jumper/SkJumper.h" #include "Resources.h" #include "SkAndroidCodec.h" #include "SkAutoMalloc.h" @@ -44,17 +47,13 @@ #include "SkRandom.h" #include "SkRecordDraw.h" #include "SkRecorder.h" -#include "SkSurfaceCharacterization.h" #include "SkSVGCanvas.h" #include "SkStream.h" +#include "SkSurfaceCharacterization.h" #include "SkSwizzler.h" +#include "SkTLogic.h" #include "SkTaskGroup.h" #include "SkThreadedBMPDevice.h" -#include "SkTLogic.h" -#include -#include -#include "../src/jumper/SkJumper.h" - #if defined(SK_BUILD_FOR_WIN) #include "SkAutoCoInitialize.h" #include "SkHRESULT.h" @@ -72,7 +71,9 @@ #endif #if SK_SUPPORT_GPU +#include "GrBackendSurface.h" #include "GrContextPriv.h" +#include "GrGpu.h" #endif DEFINE_bool(multiPage, false, "For document-type backends, render the source" @@ -1603,6 +1604,7 @@ DEFINE_bool(gpuStats, false, "Append GPU stats to the log for each GPU task?"); GPUSink::GPUSink(GrContextFactory::ContextType ct, GrContextFactory::ContextOverrides overrides, + SkCommandLineConfigGpu::SurfType surfType, int samples, bool diText, SkColorType colorType, @@ -1612,6 +1614,7 @@ GPUSink::GPUSink(GrContextFactory::ContextType ct, const GrContextOptions& grCtxOptions) : fContextType(ct) , fContextOverrides(overrides) + , fSurfType(surfType) , fSampleCount(samples) , fUseDIText(diText) , fColorType(colorType) @@ -1636,16 +1639,45 @@ Error GPUSink::onDraw(const Src& src, SkBitmap* dst, SkWStream*, SkString* log, const SkISize size = src.size(); SkImageInfo info = SkImageInfo::Make(size.width(), size.height(), fColorType, fAlphaType, fColorSpace); + sk_sp surface; #if SK_SUPPORT_GPU GrContext* context = factory.getContextInfo(fContextType, fContextOverrides).grContext(); const int maxDimension = context->caps()->maxTextureSize(); if (maxDimension < SkTMax(size.width(), size.height())) { return Error::Nonfatal("Src too large to create a texture.\n"); } + uint32_t flags = fUseDIText ? SkSurfaceProps::kUseDeviceIndependentFonts_Flag : 0; + SkSurfaceProps props(flags, SkSurfaceProps::kLegacyFontHost_InitType); + GrBackendTexture backendTexture; + GrBackendRenderTarget backendRT; + switch (fSurfType) { + case SkCommandLineConfigGpu::SurfType::kDefault: + surface = SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, info, fSampleCount, + &props); + break; + case SkCommandLineConfigGpu::SurfType::kBackendTexture: + backendTexture = context->contextPriv().getGpu()->createTestingOnlyBackendTexture( + nullptr, info.width(), info.height(), info.colorType(), true, GrMipMapped::kNo); + surface = SkSurface::MakeFromBackendTexture(context, backendTexture, + kTopLeft_GrSurfaceOrigin, fSampleCount, + info.refColorSpace(), &props); + break; + case SkCommandLineConfigGpu::SurfType::kBackendRenderTarget: + if (1 == fSampleCount) { + auto srgbEncoded = info.colorSpace() && info.colorSpace()->gammaCloseToSRGB() + ? GrSRGBEncoded::kYes + : GrSRGBEncoded::kNo; + auto colorType = SkColorTypeToGrColorType(info.colorType()); + backendRT = context->contextPriv().getGpu()->createTestingOnlyBackendRenderTarget( + info.width(), info.height(), colorType, srgbEncoded); + surface = SkSurface::MakeFromBackendRenderTarget(context, backendRT, + kBottomLeft_GrSurfaceOrigin, + info.refColorSpace(), &props); + } + break; + } #endif - auto surface( - NewGpuSurface(&factory, fContextType, fContextOverrides, info, fSampleCount, fUseDIText)); if (!surface) { return "Could not create a surface."; } @@ -1677,6 +1709,17 @@ Error GPUSink::onDraw(const Src& src, SkBitmap* dst, SkWStream*, SkString* log, } else if (FLAGS_releaseAndAbandonGpuContext) { factory.releaseResourcesAndAbandonContexts(); } +#if SK_SUPPORT_GPU + if (!context->contextPriv().abandoned()) { + surface.reset(); + if (backendTexture.isValid()) { + context->contextPriv().getGpu()->deleteTestingOnlyBackendTexture(&backendTexture); + } + if (backendRT.isValid()) { + context->contextPriv().getGpu()->deleteTestingOnlyBackendRenderTarget(backendRT); + } + } +#endif return ""; } @@ -1684,6 +1727,7 @@ Error GPUSink::onDraw(const Src& src, SkBitmap* dst, SkWStream*, SkString* log, GPUThreadTestingSink::GPUThreadTestingSink(GrContextFactory::ContextType ct, GrContextFactory::ContextOverrides overrides, + SkCommandLineConfigGpu::SurfType surfType, int samples, bool diText, SkColorType colorType, @@ -1691,8 +1735,8 @@ GPUThreadTestingSink::GPUThreadTestingSink(GrContextFactory::ContextType ct, sk_sp colorSpace, bool threaded, const GrContextOptions& grCtxOptions) - : INHERITED(ct, overrides, samples, diText, colorType, alphaType, std::move(colorSpace), - threaded, grCtxOptions) + : INHERITED(ct, overrides, surfType, samples, diText, colorType, alphaType, + std::move(colorSpace), threaded, grCtxOptions) #if SK_SUPPORT_GPU , fExecutor(SkExecutor::MakeFIFOThreadPool(FLAGS_gpuThreads)) { #else diff --git a/dm/DMSrcSink.h b/dm/DMSrcSink.h index 227ef5341a..18e854bb0c 100644 --- a/dm/DMSrcSink.h +++ b/dm/DMSrcSink.h @@ -14,6 +14,7 @@ #include "SkBitmap.h" #include "SkBitmapRegionDecoder.h" #include "SkCanvas.h" +#include "SkCommonFlagsConfig.h" #include "SkData.h" #include "SkMultiPictureDocument.h" #include "SkPicture.h" @@ -339,7 +340,8 @@ public: class GPUSink : public Sink { public: GPUSink(sk_gpu_test::GrContextFactory::ContextType, - sk_gpu_test::GrContextFactory::ContextOverrides, int samples, bool diText, + sk_gpu_test::GrContextFactory::ContextOverrides, + SkCommandLineConfigGpu::SurfType surfType, int samples, bool diText, SkColorType colorType, SkAlphaType alphaType, sk_sp colorSpace, bool threaded, const GrContextOptions& grCtxOptions); @@ -359,6 +361,7 @@ public: private: sk_gpu_test::GrContextFactory::ContextType fContextType; sk_gpu_test::GrContextFactory::ContextOverrides fContextOverrides; + SkCommandLineConfigGpu::SurfType fSurfType; int fSampleCount; bool fUseDIText; SkColorType fColorType; @@ -371,7 +374,8 @@ private: class GPUThreadTestingSink : public GPUSink { public: GPUThreadTestingSink(sk_gpu_test::GrContextFactory::ContextType, - sk_gpu_test::GrContextFactory::ContextOverrides, int samples, bool diText, + sk_gpu_test::GrContextFactory::ContextOverrides, + SkCommandLineConfigGpu::SurfType surfType, int samples, bool diText, SkColorType colorType, SkAlphaType alphaType, sk_sp colorSpace, bool threaded, const GrContextOptions& grCtxOptions); -- cgit v1.2.3