From 57bf4a3dbf01f11d3f2ec2e1952388220bef50be Mon Sep 17 00:00:00 2001 From: Greg Daniel Date: Thu, 19 Apr 2018 10:28:37 -0400 Subject: When creating testing backendTexture take colorspace into account. Bug: skia: Change-Id: Ifa8dbad3eca81790648476f9a6d3fa5a088fede9 Reviewed-on: https://skia-review.googlesource.com/122341 Reviewed-by: Robert Phillips Reviewed-by: Brian Osman Commit-Queue: Greg Daniel --- dm/DMSrcSink.cpp | 4 +++- src/gpu/GrGpu.h | 3 ++- src/gpu/vk/GrVkGpu.cpp | 6 +++++- tests/ImageTest.cpp | 2 +- tests/ProxyTest.cpp | 12 ++++++------ tests/SurfaceTest.cpp | 8 ++++---- tools/gpu/GrTest.cpp | 5 +++-- 7 files changed, 24 insertions(+), 16 deletions(-) diff --git a/dm/DMSrcSink.cpp b/dm/DMSrcSink.cpp index 9829e2978d..a086094414 100644 --- a/dm/DMSrcSink.cpp +++ b/dm/DMSrcSink.cpp @@ -1510,7 +1510,8 @@ Error GPUSink::onDraw(const Src& src, SkBitmap* dst, SkWStream*, SkString* log, break; case SkCommandLineConfigGpu::SurfType::kBackendTexture: backendTexture = context->contextPriv().getGpu()->createTestingOnlyBackendTexture( - nullptr, info.width(), info.height(), info.colorType(), true, GrMipMapped::kNo); + nullptr, info.width(), info.height(), info.colorType(), info.colorSpace(), + true, GrMipMapped::kNo); surface = SkSurface::MakeFromBackendTexture(context, backendTexture, kTopLeft_GrSurfaceOrigin, fSampleCount, fColorType, info.refColorSpace(), &props); @@ -2107,6 +2108,7 @@ public: info.fBitmap.width(), info.fBitmap.height(), info.fBitmap.colorType(), + info.fBitmap.colorSpace(), false, GrMipMapped::kNo)); // The GMs sometimes request too large an image //SkAssertResult(callbackContext->backendTexture().isValid()); diff --git a/src/gpu/GrGpu.h b/src/gpu/GrGpu.h index 31870dc833..eb969e4704 100644 --- a/src/gpu/GrGpu.h +++ b/src/gpu/GrGpu.h @@ -454,7 +454,8 @@ public: only to be used for testing (particularly for testing the methods that import an externally created texture into Skia. Must be matched with a call to deleteTestingOnlyTexture(). */ GrBackendTexture createTestingOnlyBackendTexture(const void* pixels, int w, int h, SkColorType, - bool isRenderTarget, GrMipMapped); + SkColorSpace* cs, bool isRenderTarget, + GrMipMapped); /** Older version based on GrPixelConfig. Currently the preferred one above devolves to this. */ virtual GrBackendTexture createTestingOnlyBackendTexture(const void* pixels, int w, int h, GrPixelConfig config, diff --git a/src/gpu/vk/GrVkGpu.cpp b/src/gpu/vk/GrVkGpu.cpp index 800751053a..ff0f5bcbe3 100644 --- a/src/gpu/vk/GrVkGpu.cpp +++ b/src/gpu/vk/GrVkGpu.cpp @@ -1251,10 +1251,14 @@ bool GrVkGpu::createTestingOnlyVkImage(GrPixelConfig config, int w, int h, bool mipLevels = SkMipMap::ComputeLevelCount(w, h) + 1; } + // sRGB format images may need to be aliased to linear for various reasons (legacy mode): + VkImageCreateFlags createFlags = GrVkFormatIsSRGB(pixelFormat, nullptr) + ? VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT : 0; + const VkImageCreateInfo imageCreateInfo = { VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, // sType nullptr, // pNext - 0, // VkImageCreateFlags + createFlags, // VkImageCreateFlags VK_IMAGE_TYPE_2D, // VkImageType pixelFormat, // VkFormat {(uint32_t)w, (uint32_t)h, 1}, // VkExtent3D diff --git a/tests/ImageTest.cpp b/tests/ImageTest.cpp index 9940574eee..73c0bf197c 100644 --- a/tests/ImageTest.cpp +++ b/tests/ImageTest.cpp @@ -494,7 +494,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrContext_colorTypeSupportedAsImage, reporter bool can = ctxInfo.grContext()->colorTypeSupportedAsImage(colorType); auto* gpu = ctxInfo.grContext()->contextPriv().getGpu(); GrBackendTexture backendTex = gpu->createTestingOnlyBackendTexture( - nullptr, kSize, kSize, colorType, false, GrMipMapped::kNo); + nullptr, kSize, kSize, colorType, nullptr, false, GrMipMapped::kNo); auto img = SkImage::MakeFromTexture(ctxInfo.grContext(), backendTex, kTopLeft_GrSurfaceOrigin, colorType, kOpaque_SkAlphaType, nullptr); diff --git a/tests/ProxyTest.cpp b/tests/ProxyTest.cpp index fa53a7abc9..5721a41b6b 100644 --- a/tests/ProxyTest.cpp +++ b/tests/ProxyTest.cpp @@ -255,8 +255,8 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(WrappedProxyTest, reporter, ctxInfo) { { GrBackendTexture backendTex = gpu->createTestingOnlyBackendTexture(nullptr, kWidthHeight, - kWidthHeight, colorType, true, - GrMipMapped::kNo); + kWidthHeight, colorType, nullptr, + true, GrMipMapped::kNo); sk_sp sProxy = proxyProvider->wrapBackendTextureAsRenderTarget( backendTex, origin, supportedNumSamples); if (!sProxy) { @@ -279,8 +279,8 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(WrappedProxyTest, reporter, ctxInfo) { { GrBackendTexture backendTex = gpu->createTestingOnlyBackendTexture(nullptr, kWidthHeight, - kWidthHeight, colorType, true, - GrMipMapped::kNo); + kWidthHeight, colorType, nullptr, + true, GrMipMapped::kNo); sk_sp sProxy = proxyProvider->wrapRenderableBackendTexture( backendTex, origin, supportedNumSamples); @@ -305,8 +305,8 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(WrappedProxyTest, reporter, ctxInfo) { // Internal offscreen texture GrBackendTexture backendTex = gpu->createTestingOnlyBackendTexture(nullptr, kWidthHeight, - kWidthHeight, colorType, false, - GrMipMapped::kNo); + kWidthHeight, colorType, nullptr, + false, GrMipMapped::kNo); sk_sp sProxy = proxyProvider->wrapBackendTexture( backendTex, origin, kBorrow_GrWrapOwnership, nullptr, nullptr); diff --git a/tests/SurfaceTest.cpp b/tests/SurfaceTest.cpp index f2e0083a06..835e9ffc7f 100644 --- a/tests/SurfaceTest.cpp +++ b/tests/SurfaceTest.cpp @@ -109,7 +109,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrContext_colorTypeSupportedAsSurface, report auto* gpu = ctxInfo.grContext()->contextPriv().getGpu(); GrBackendTexture backendTex = gpu->createTestingOnlyBackendTexture( - nullptr, kSize, kSize, colorType, true, GrMipMapped::kNo); + nullptr, kSize, kSize, colorType, nullptr, true, GrMipMapped::kNo); surf = SkSurface::MakeFromBackendTexture(ctxInfo.grContext(), backendTex, kTopLeft_GrSurfaceOrigin, 0, colorType, nullptr, nullptr); @@ -136,8 +136,8 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrContext_colorTypeSupportedAsSurface, report REPORTER_ASSERT(reporter, can == SkToBool(surf), "ct: %d, can: %d, surf: %d", colorType, can, SkToBool(surf)); - backendTex = gpu->createTestingOnlyBackendTexture(nullptr, kSize, kSize, colorType, true, - GrMipMapped::kNo); + backendTex = gpu->createTestingOnlyBackendTexture(nullptr, kSize, kSize, colorType, nullptr, + true, GrMipMapped::kNo); surf = SkSurface::MakeFromBackendTexture(ctxInfo.grContext(), backendTex, kTopLeft_GrSurfaceOrigin, kSampleCnt, colorType, nullptr, nullptr); @@ -190,7 +190,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrContext_maxSurfaceSamplesForColorType, repo } auto* gpu = ctxInfo.grContext()->contextPriv().getGpu(); GrBackendTexture backendTex = gpu->createTestingOnlyBackendTexture( - nullptr, kSize, kSize, colorType, true, GrMipMapped::kNo); + nullptr, kSize, kSize, colorType, nullptr, true, GrMipMapped::kNo); if (!backendTex.isValid()) { continue; } diff --git a/tools/gpu/GrTest.cpp b/tools/gpu/GrTest.cpp index 3c6046712d..311f318b9f 100644 --- a/tools/gpu/GrTest.cpp +++ b/tools/gpu/GrTest.cpp @@ -164,9 +164,10 @@ void GrGpu::Stats::dumpKeyValuePairs(SkTArray* keys, SkTArray* #endif GrBackendTexture GrGpu::createTestingOnlyBackendTexture(const void* pixels, int w, int h, - SkColorType colorType, bool isRenderTarget, + SkColorType colorType, + SkColorSpace* cs, bool isRenderTarget, GrMipMapped mipMapped) { - GrPixelConfig config = SkImageInfo2GrPixelConfig(colorType, nullptr, *this->caps()); + GrPixelConfig config = SkImageInfo2GrPixelConfig(colorType, cs, *this->caps()); if (kUnknown_GrPixelConfig == config) { return GrBackendTexture(); } -- cgit v1.2.3