diff --git a/dm/DM.cpp b/dm/DM.cpp index 320e9bb7ea..d03f17beb5 100644 --- a/dm/DM.cpp +++ b/dm/DM.cpp @@ -915,7 +915,7 @@ static void push_sink(const SkCommandLineConfig& config, Sink* s) { SkString log; Result result = sink->draw(justOneRect, &bitmap, &stream, &log); if (result.isFatal()) { - info("Could not run %s: %s\n%s\n", config.getTag().c_str(), result.c_str(), log.c_str()); + info("Could not run %s: %s\n", config.getTag().c_str(), result.c_str()); exit(1); } diff --git a/dm/DMSrcSink.cpp b/dm/DMSrcSink.cpp index 486b648c27..947240f998 100644 --- a/dm/DMSrcSink.cpp +++ b/dm/DMSrcSink.cpp @@ -79,7 +79,6 @@ static DEFINE_bool(RAW_threading, true, "Allow RAW decodes to run on multiple th DECLARE_int(gpuThreads); using sk_gpu_test::GrContextFactory; -using sk_gpu_test::ContextInfo; namespace DM { @@ -1369,65 +1368,6 @@ Result GPUSink::draw(const Src& src, SkBitmap* dst, SkWStream* dstStream, SkStri return this->onDraw(src, dst, dstStream, log, fBaseContextOptions); } -sk_sp GPUSink::createDstSurface(GrContext* context, SkISize size, - GrBackendTexture* backendTexture, - GrBackendRenderTarget* backendRT, - SkString* log) const { - sk_sp surface; - - SkImageInfo info = SkImageInfo::Make(size, fColorType, fAlphaType, fColorSpace); - uint32_t flags = fUseDIText ? SkSurfaceProps::kUseDeviceIndependentFonts_Flag : 0; - SkSurfaceProps props(flags, SkSurfaceProps::kLegacyFontHost_InitType); - - const int maxDimension = context->priv().caps()->maxTextureSize(); - if (maxDimension < std::max(size.width(), size.height())) { - log->appendf("Src (%dx%d) too large to create a texture.\n", size.width(), size.height()); - return nullptr; - } - - switch (fSurfType) { - case SkCommandLineConfigGpu::SurfType::kDefault: - surface = SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, info, fSampleCount, - &props); - break; - case SkCommandLineConfigGpu::SurfType::kBackendTexture: - *backendTexture = context->createBackendTexture( - info.width(), info.height(), info.colorType(), SkColors::kTransparent, - GrMipMapped::kNo, GrRenderable::kYes, GrProtected::kNo); - surface = SkSurface::MakeFromBackendTexture(context, *backendTexture, - kTopLeft_GrSurfaceOrigin, fSampleCount, - fColorType, info.refColorSpace(), &props); - break; - case SkCommandLineConfigGpu::SurfType::kBackendRenderTarget: - if (1 == fSampleCount) { - auto colorType = SkColorTypeToGrColorType(info.colorType()); - *backendRT = context->priv().getGpu()->createTestingOnlyBackendRenderTarget( - info.width(), info.height(), colorType); - surface = SkSurface::MakeFromBackendRenderTarget( - context, *backendRT, kBottomLeft_GrSurfaceOrigin, info.colorType(), - info.refColorSpace(), &props); - } - break; - } - - return surface; -} - -bool GPUSink::readBack(SkSurface* surface, SkBitmap* dst) const { - SkCanvas* canvas = surface->getCanvas(); - SkISize size = surface->imageInfo().dimensions(); - - SkImageInfo info = SkImageInfo::Make(size, fColorType, fAlphaType, fColorSpace); - if (info.colorType() == kRGB_565_SkColorType || info.colorType() == kARGB_4444_SkColorType || - info.colorType() == kRGB_888x_SkColorType) { - // We don't currently support readbacks into these formats on the GPU backend. Convert to - // 32 bit. - info = SkImageInfo::Make(size, kRGBA_8888_SkColorType, kPremul_SkAlphaType, fColorSpace); - } - dst->allocPixels(info); - return canvas->readPixels(*dst, 0, 0); -} - Result GPUSink::onDraw(const Src& src, SkBitmap* dst, SkWStream*, SkString* log, const GrContextOptions& baseOptions, std::function initContext) const { @@ -1441,15 +1381,46 @@ Result GPUSink::onDraw(const Src& src, SkBitmap* dst, SkWStream*, SkString* log, SkASSERT(exec == grOptions.fExecutor); GrContextFactory factory(grOptions); + const SkISize size = src.size(); + SkImageInfo info = SkImageInfo::Make(size, fColorType, fAlphaType, fColorSpace); + sk_sp surface; GrContext* context = factory.getContextInfo(fContextType, fContextOverrides).grContext(); if (initContext) { initContext(context); } - + const int maxDimension = context->priv().caps()->maxTextureSize(); + if (maxDimension < std::max(size.width(), size.height())) { + return Result::Skip("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; - sk_sp surface = this->createDstSurface(context, src.size(), - &backendTexture, &backendRT, log); + switch (fSurfType) { + case SkCommandLineConfigGpu::SurfType::kDefault: + surface = SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, info, fSampleCount, + &props); + break; + case SkCommandLineConfigGpu::SurfType::kBackendTexture: + backendTexture = context->createBackendTexture( + info.width(), info.height(), info.colorType(), SkColors::kTransparent, + GrMipMapped::kNo, GrRenderable::kYes, GrProtected::kNo); + surface = SkSurface::MakeFromBackendTexture(context, backendTexture, + kTopLeft_GrSurfaceOrigin, fSampleCount, + fColorType, info.refColorSpace(), &props); + break; + case SkCommandLineConfigGpu::SurfType::kBackendRenderTarget: + if (1 == fSampleCount) { + auto colorType = SkColorTypeToGrColorType(info.colorType()); + backendRT = context->priv().getGpu()->createTestingOnlyBackendRenderTarget( + info.width(), info.height(), colorType); + surface = SkSurface::MakeFromBackendRenderTarget( + context, backendRT, kBottomLeft_GrSurfaceOrigin, info.colorType(), + info.refColorSpace(), &props); + } + break; + } + if (!surface) { return Result::Fatal("Could not create a surface."); } @@ -1466,11 +1437,14 @@ Result GPUSink::onDraw(const Src& src, SkBitmap* dst, SkWStream*, SkString* log, canvas->getGrContext()->priv().dumpCacheStats(log); canvas->getGrContext()->priv().dumpGpuStats(log); } - - if (!this->readBack(surface.get(), dst)) { - return Result::Fatal("Could not readback from surface."); + if (info.colorType() == kRGB_565_SkColorType || info.colorType() == kARGB_4444_SkColorType || + info.colorType() == kRGB_888x_SkColorType) { + // We don't currently support readbacks into these formats on the GPU backend. Convert to + // 32 bit. + info = SkImageInfo::Make(size, kRGBA_8888_SkColorType, kPremul_SkAlphaType, fColorSpace); } - + dst->allocPixels(info); + canvas->readPixels(*dst, 0, 0); if (FLAGS_abandonGpuContext) { factory.abandonContexts(); } else if (FLAGS_releaseAndAbandonGpuContext) { diff --git a/dm/DMSrcSink.h b/dm/DMSrcSink.h index b2f2e64655..ae05d9fca9 100644 --- a/dm/DMSrcSink.h +++ b/dm/DMSrcSink.h @@ -366,7 +366,7 @@ public: std::function initContext = nullptr) const; sk_gpu_test::GrContextFactory::ContextType contextType() const { return fContextType; } - const sk_gpu_test::GrContextFactory::ContextOverrides& contextOverrides() const { + const sk_gpu_test::GrContextFactory::ContextOverrides& contextOverrides() { return fContextOverrides; } SkCommandLineConfigGpu::SurfType surfType() const { return fSurfType; } @@ -383,11 +383,6 @@ public: return SkColorInfo(fColorType, fAlphaType, fColorSpace); } -protected: - sk_sp createDstSurface(GrContext*, SkISize size, GrBackendTexture*, - GrBackendRenderTarget*, SkString* log) const; - bool readBack(SkSurface*, SkBitmap* dst) const; - private: sk_gpu_test::GrContextFactory::ContextType fContextType; sk_gpu_test::GrContextFactory::ContextOverrides fContextOverrides;