Revert "Carve some helper functions off of GPUSink"

This reverts commit 7b2fcfbc5a.

Reason for revert: Need to loosen up error handling

Original change's description:
> Carve some helper functions off of GPUSink
> 
> I'm adding a new DDL Sink and would like to reuse this functionality.
> 
> Change-Id: I9f4535ca5e0f36925bf896cb0076eab73fe60fd1
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/270639
> Commit-Queue: Robert Phillips <robertphillips@google.com>
> Reviewed-by: Greg Daniel <egdaniel@google.com>

TBR=egdaniel@google.com,robertphillips@google.com

Change-Id: I97968834b5719c2061d53caff0dcf08a80917beb
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/270798
Reviewed-by: Robert Phillips <robertphillips@google.com>
Commit-Queue: Robert Phillips <robertphillips@google.com>
This commit is contained in:
Robert Phillips 2020-02-13 20:26:58 +00:00 committed by Skia Commit-Bot
parent 242536fe8b
commit 45f37c3795
3 changed files with 43 additions and 74 deletions

View File

@ -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);
}

View File

@ -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<SkSurface> GPUSink::createDstSurface(GrContext* context, SkISize size,
GrBackendTexture* backendTexture,
GrBackendRenderTarget* backendRT,
SkString* log) const {
sk_sp<SkSurface> 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<void(GrContext*)> 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<SkSurface> 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<SkSurface> 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) {

View File

@ -366,7 +366,7 @@ public:
std::function<void(GrContext*)> 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<SkSurface> 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;