diff --git a/gm/imagefromyuvtextures.cpp b/gm/imagefromyuvtextures.cpp index 3741dc5cad..a86aad4623 100644 --- a/gm/imagefromyuvtextures.cpp +++ b/gm/imagefromyuvtextures.cpp @@ -108,7 +108,7 @@ protected: yuvTextures[i] = gpu->createTestingOnlyBackendTexture(fYUVBmps[i].getPixels(), fYUVBmps[i].width(), fYUVBmps[i].height(), - kAlpha_8_GrPixelConfig, + GrColorType::kAlpha_8, false, GrMipMapped::kNo); } context->resetContext(); @@ -126,7 +126,7 @@ protected: } *resultTexture = gpu->createTestingOnlyBackendTexture( - nullptr, width, height, kRGBA_8888_GrPixelConfig, true, GrMipMapped::kNo); + nullptr, width, height, GrColorType::kRGBA_8888, true, GrMipMapped::kNo); context->resetContext(); } diff --git a/src/core/SkConvertPixels.h b/src/core/SkConvertPixels.h index ccd76c35a7..cfe81f49cc 100644 --- a/src/core/SkConvertPixels.h +++ b/src/core/SkConvertPixels.h @@ -17,16 +17,16 @@ void SkConvertPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowB const SkImageInfo& srcInfo, const void* srcPixels, size_t srcRowBytes); static inline void SkRectMemcpy(void* dst, size_t dstRB, const void* src, size_t srcRB, - size_t bytesPerRow, int rowCount) { - SkASSERT(bytesPerRow <= dstRB); - SkASSERT(bytesPerRow <= srcRB); - if (bytesPerRow == dstRB && bytesPerRow == srcRB) { - memcpy(dst, src, bytesPerRow * rowCount); + size_t trimRowBytes, int rowCount) { + SkASSERT(trimRowBytes <= dstRB); + SkASSERT(trimRowBytes <= srcRB); + if (trimRowBytes == dstRB && trimRowBytes == srcRB) { + memcpy(dst, src, trimRowBytes * rowCount); return; } for (int i = 0; i < rowCount; ++i) { - memcpy(dst, src, bytesPerRow); + memcpy(dst, src, trimRowBytes); dst = SkTAddOffset(dst, dstRB); src = SkTAddOffset(src, srcRB); } diff --git a/src/gpu/GrGpu.cpp b/src/gpu/GrGpu.cpp index 70ec772685..7a17fe65d5 100644 --- a/src/gpu/GrGpu.cpp +++ b/src/gpu/GrGpu.cpp @@ -366,3 +366,14 @@ void GrGpu::dumpJSON(SkJSONWriter* writer) const { writer->endObject(); } + +#if GR_TEST_UTILS +GrBackendTexture GrGpu::createTestingOnlyBackendTexture(const void* pixels, int w, int h, + SkColorType colorType, bool isRenderTarget, + GrMipMapped isMipped, size_t rowBytes) { + GrColorType grCT = SkColorTypeToGrColorType(colorType); + + return this->createTestingOnlyBackendTexture(pixels, w, h, grCT, isRenderTarget, isMipped, + rowBytes); +} +#endif diff --git a/src/gpu/GrGpu.h b/src/gpu/GrGpu.h index 783537aa42..a5beb9ee3d 100644 --- a/src/gpu/GrGpu.h +++ b/src/gpu/GrGpu.h @@ -339,16 +339,17 @@ public: void dumpJSON(SkJSONWriter*) const; #if GR_TEST_UTILS + GrBackendTexture createTestingOnlyBackendTexture(const void* pixels, int w, int h, + SkColorType, bool isRenderTarget, + GrMipMapped, size_t rowBytes = 0); + /** Creates a texture directly in the backend API without wrapping it in a GrTexture. This is 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); - /** 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, - bool isRenderTarget, - GrMipMapped mipMapped) = 0; + GrColorType, bool isRenderTarget, + GrMipMapped, size_t rowBytes = 0) = 0; + /** Check a handle represents an actual texture in the backend API that has not been freed. */ virtual bool isTestingOnlyBackendTexture(const GrBackendTexture&) const = 0; /** diff --git a/src/gpu/gl/GrGLGpu.cpp b/src/gpu/gl/GrGLGpu.cpp index f33fedcd69..a48d661adb 100644 --- a/src/gpu/gl/GrGLGpu.cpp +++ b/src/gpu/gl/GrGLGpu.cpp @@ -3921,9 +3921,12 @@ void GrGLGpu::xferBarrier(GrRenderTarget* rt, GrXferBarrierType type) { #if GR_TEST_UTILS GrBackendTexture GrGLGpu::createTestingOnlyBackendTexture(const void* pixels, int w, int h, - GrPixelConfig config, bool /*isRT*/, - GrMipMapped mipMapped) { + GrColorType colorType, bool /*isRT*/, + GrMipMapped mipMapped, + size_t rowBytes) { this->handleDirtyContext(); + + GrPixelConfig config = GrColorTypeToPixelConfig(colorType, GrSRGBEncoded::kNo); if (!this->caps()->isConfigTexturable(config)) { return GrBackendTexture(); // invalid } @@ -3937,6 +3940,12 @@ GrBackendTexture GrGLGpu::createTestingOnlyBackendTexture(const void* pixels, in return GrBackendTexture(); // invalid } + int bpp = GrColorTypeBytesPerPixel(colorType); + const size_t trimRowBytes = w * bpp; + if (!rowBytes) { + rowBytes = trimRowBytes; + } + GrGLTextureInfo info; info.fTarget = GR_GL_TEXTURE_2D; info.fID = 0; @@ -3950,6 +3959,12 @@ GrBackendTexture GrGLGpu::createTestingOnlyBackendTexture(const void* pixels, in GL_CALL(TexParameteri(info.fTarget, GR_GL_TEXTURE_WRAP_S, GR_GL_CLAMP_TO_EDGE)); GL_CALL(TexParameteri(info.fTarget, GR_GL_TEXTURE_WRAP_T, GR_GL_CLAMP_TO_EDGE)); + bool restoreGLRowLength = false; + if (trimRowBytes != rowBytes && this->glCaps().unpackRowLengthSupport()) { + GL_CALL(PixelStorei(GR_GL_UNPACK_ROW_LENGTH, rowBytes / bpp)); + restoreGLRowLength = true; + } + GrGLenum internalFormat; GrGLenum externalFormat; GrGLenum externalType; @@ -3969,13 +3984,19 @@ GrBackendTexture GrGLGpu::createTestingOnlyBackendTexture(const void* pixels, in mipLevels = SkMipMap::ComputeLevelCount(w, h) + 1; } - size_t bpp = GrBytesPerPixel(config); size_t baseLayerSize = bpp * w * h; SkAutoMalloc defaultStorage(baseLayerSize); if (!pixels) { // Fill in the texture with all zeros so we don't have random garbage pixels = defaultStorage.get(); memset(defaultStorage.get(), 0, baseLayerSize); + } else if (trimRowBytes != rowBytes && !restoreGLRowLength) { + // We weren't able to use GR_GL_UNPACK_ROW_LENGTH so make a copy + char* copy = (char*) defaultStorage.get(); + for (int y = 0; y < h; ++y) { + memcpy(©[y*trimRowBytes], &((const char*)pixels)[y*rowBytes], trimRowBytes); + } + pixels = copy; } int width = w; @@ -3990,6 +4011,10 @@ GrBackendTexture GrGLGpu::createTestingOnlyBackendTexture(const void* pixels, in // unbind the texture from the texture unit to avoid asserts GL_CALL(BindTexture(info.fTarget, 0)); + if (restoreGLRowLength) { + GL_CALL(PixelStorei(GR_GL_UNPACK_ROW_LENGTH, 0)); + } + GrBackendTexture beTex = GrBackendTexture(w, h, mipMapped, info); // Lots of tests don't go through Skia's public interface which will set the config so for // testing we make sure we set a config here. diff --git a/src/gpu/gl/GrGLGpu.h b/src/gpu/gl/GrGLGpu.h index 295ca42179..2c6fa1281a 100644 --- a/src/gpu/gl/GrGLGpu.h +++ b/src/gpu/gl/GrGLGpu.h @@ -136,8 +136,9 @@ public: int height) override; #if GR_TEST_UTILS GrBackendTexture createTestingOnlyBackendTexture(const void* pixels, int w, int h, - GrPixelConfig config, bool isRenderTarget, - GrMipMapped mipMapped) override; + GrColorType colorType, bool isRenderTarget, + GrMipMapped mipMapped, + size_t rowBytes = 0) override; bool isTestingOnlyBackendTexture(const GrBackendTexture&) const override; void deleteTestingOnlyBackendTexture(const GrBackendTexture&) override; diff --git a/src/gpu/mock/GrMockGpu.cpp b/src/gpu/mock/GrMockGpu.cpp index 8a66b7906f..ac3e5ca2c8 100644 --- a/src/gpu/mock/GrMockGpu.cpp +++ b/src/gpu/mock/GrMockGpu.cpp @@ -192,8 +192,15 @@ GrStencilAttachment* GrMockGpu::createStencilAttachmentForRenderTarget(const GrR #if GR_TEST_UTILS GrBackendTexture GrMockGpu::createTestingOnlyBackendTexture(const void* pixels, int w, int h, - GrPixelConfig config, bool isRT, - GrMipMapped mipMapped) { + GrColorType colorType, bool isRT, + GrMipMapped mipMapped, + size_t rowBytes) { + + GrPixelConfig config = GrColorTypeToPixelConfig(colorType, GrSRGBEncoded::kNo); + if (!this->caps()->isConfigTexturable(config)) { + return GrBackendTexture(); // invalid + } + GrMockTextureInfo info; info.fConfig = config; info.fID = NextExternalTextureID(); diff --git a/src/gpu/mock/GrMockGpu.h b/src/gpu/mock/GrMockGpu.h index 6f0d5e2456..1b7385f39e 100644 --- a/src/gpu/mock/GrMockGpu.h +++ b/src/gpu/mock/GrMockGpu.h @@ -107,8 +107,8 @@ private: #if GR_TEST_UTILS GrBackendTexture createTestingOnlyBackendTexture(const void* pixels, int w, int h, - GrPixelConfig, bool isRT, - GrMipMapped) override; + GrColorType, bool isRT, + GrMipMapped, size_t rowBytes = 0) override; bool isTestingOnlyBackendTexture(const GrBackendTexture&) const override; void deleteTestingOnlyBackendTexture(const GrBackendTexture&) override; diff --git a/src/gpu/mtl/GrMtlGpu.h b/src/gpu/mtl/GrMtlGpu.h index bf9b1f5823..9cdb87171a 100644 --- a/src/gpu/mtl/GrMtlGpu.h +++ b/src/gpu/mtl/GrMtlGpu.h @@ -54,8 +54,8 @@ public: #ifdef GR_TEST_UTILS GrBackendTexture createTestingOnlyBackendTexture(const void* pixels, int w, int h, - GrPixelConfig config, bool isRT, - GrMipMapped) override; + GrColorType colorType, bool isRT, + GrMipMapped, size_t rowBytes = 0) override; bool isTestingOnlyBackendTexture(const GrBackendTexture&) const override; @@ -177,9 +177,10 @@ private: void clearStencil(GrRenderTarget* target, int clearValue) override {} #if GR_TEST_UTILS - bool createTestingOnlyMtlTextureInfo(GrPixelConfig config, int w, int h, bool texturable, + bool createTestingOnlyMtlTextureInfo(GrColorType colorType, int w, int h, bool texturable, bool renderable, GrMipMapped mipMapped, - const void* srcData, GrMtlTextureInfo* info); + const void* srcData, size_t rowBytes, + GrMtlTextureInfo* info); #endif sk_sp fMtlCaps; diff --git a/src/gpu/mtl/GrMtlGpu.mm b/src/gpu/mtl/GrMtlGpu.mm index fd1611f32f..a2c1f0fbe3 100644 --- a/src/gpu/mtl/GrMtlGpu.mm +++ b/src/gpu/mtl/GrMtlGpu.mm @@ -383,15 +383,18 @@ sk_sp GrMtlGpu::onWrapBackendTextureAsRenderTarget( } #ifdef GR_TEST_UTILS -bool GrMtlGpu::createTestingOnlyMtlTextureInfo(GrPixelConfig config, int w, int h, bool texturable, - bool renderable, GrMipMapped mipMapped, - const void* srcData, GrMtlTextureInfo* info) { +bool GrMtlGpu::createTestingOnlyMtlTextureInfo(GrColorType colorType, int w, int h, bool texturable, + bool renderable, GrMipMapped mipMapped, + const void* srcData, size_t srcRowBytes, + GrMtlTextureInfo* info) { SkASSERT(texturable || renderable); if (!texturable) { SkASSERT(GrMipMapped::kNo == mipMapped); SkASSERT(!srcData); } + GrPixelConfig config = GrColorTypeToPixelConfig(colorType, GrSRGBEncoded::kNo); + MTLPixelFormat format; if (!GrPixelConfigToMTLFormat(config, &format)) { return false; @@ -435,8 +438,11 @@ bool GrMtlGpu::createTestingOnlyMtlTextureInfo(GrPixelConfig config, int w, int desc.storageMode = MTLStorageModeShared; #endif id transferTexture = [fDevice newTextureWithDescriptor: desc]; - auto colorType = GrPixelConfigToColorType(config); - int rowBytes = w * GrColorTypeBytesPerPixel(colorType); + size_t trimRowBytes = w * GrColorTypeBytesPerPixel(colorType); + if (!srcRowBytes) { + srcRowBytes = trimRowBytes; + } + MTLOrigin origin = MTLOriginMake(0, 0, 0); SkASSERT(testTexture.pixelFormat == transferTexture.pixelFormat); @@ -450,7 +456,7 @@ bool GrMtlGpu::createTestingOnlyMtlTextureInfo(GrPixelConfig config, int w, int [transferTexture replaceRegion: MTLRegionMake2D(0, 0, currentWidth, currentHeight) mipmapLevel: mipLevel withBytes: srcData - bytesPerRow: rowBytes]; + bytesPerRow: srcRowBytes]; [blitCmdEncoder copyFromTexture: transferTexture sourceSlice: 0 @@ -473,17 +479,19 @@ bool GrMtlGpu::createTestingOnlyMtlTextureInfo(GrPixelConfig config, int w, int } GrBackendTexture GrMtlGpu::createTestingOnlyBackendTexture(const void* pixels, int w, int h, - GrPixelConfig config, bool isRT, - GrMipMapped mipMapped) { + GrColorType colorType, bool isRT, + GrMipMapped mipMapped, size_t rowBytes) { if (w > this->caps()->maxTextureSize() || h > this->caps()->maxTextureSize()) { return GrBackendTexture(); } GrMtlTextureInfo info; - if (!this->createTestingOnlyMtlTextureInfo(config, w, h, true, isRT, mipMapped, pixels, - &info)) { + if (!this->createTestingOnlyMtlTextureInfo(colorType, w, h, true, isRT, mipMapped, pixels, + rowBytes, &info)) { return {}; } + GrPixelConfig config = GrColorTypeToPixelConfig(colorType, GrSRGBEncoded::kNo); + GrBackendTexture backendTex(w, h, mipMapped, info); backendTex.fConfig = config; return backendTex; @@ -518,16 +526,15 @@ GrBackendRenderTarget GrMtlGpu::createTestingOnlyBackendRenderTarget(int w, int if (w > this->caps()->maxRenderTargetSize() || h > this->caps()->maxRenderTargetSize()) { return GrBackendRenderTarget(); } - auto config = GrColorTypeToPixelConfig(ct, GrSRGBEncoded::kNo); - if (kUnknown_GrPixelConfig == config) { - return {}; - } + GrMtlTextureInfo info; - if (!this->createTestingOnlyMtlTextureInfo(config, w, h, false, true, GrMipMapped::kNo, nullptr, - &info)) { + if (!this->createTestingOnlyMtlTextureInfo(ct, w, h, false, true, GrMipMapped::kNo, nullptr, + 0, &info)) { return {}; } + GrPixelConfig config = GrColorTypeToPixelConfig(ct, GrSRGBEncoded::kNo); + GrBackendRenderTarget backendRT(w, h, 1, info); backendRT.fConfig = config; return backendRT; diff --git a/src/gpu/vk/GrVkGpu.cpp b/src/gpu/vk/GrVkGpu.cpp index 8c63ea89f4..4505138804 100644 --- a/src/gpu/vk/GrVkGpu.cpp +++ b/src/gpu/vk/GrVkGpu.cpp @@ -1044,7 +1044,8 @@ GrStencilAttachment* GrVkGpu::createStencilAttachmentForRenderTarget(const GrRen //////////////////////////////////////////////////////////////////////////////// bool copy_testing_data(GrVkGpu* gpu, const void* srcData, const GrVkAlloc& alloc, - size_t bufferOffset, size_t srcRowBytes, size_t dstRowBytes, int h) { + size_t bufferOffset, size_t srcRowBytes, size_t dstRowBytes, + size_t trimRowBytes, int h) { VkDeviceSize size = dstRowBytes * h; VkDeviceSize offset = bufferOffset; SkASSERT(size + offset <= alloc.fSize); @@ -1057,19 +1058,11 @@ bool copy_testing_data(GrVkGpu* gpu, const void* srcData, const GrVkAlloc& alloc if (srcData) { // If there is no padding on dst we can do a single memcopy. // This assumes the srcData comes in with no padding. - SkRectMemcpy(mapPtr, static_cast(dstRowBytes), - srcData, srcRowBytes, srcRowBytes, h); + SkRectMemcpy(mapPtr, dstRowBytes, srcData, srcRowBytes, trimRowBytes, h); } else { // If there is no srcdata we always copy 0's into the textures so that it is initialized // with some data. - if (srcRowBytes == static_cast(dstRowBytes)) { - memset(mapPtr, 0, srcRowBytes * h); - } else { - for (int i = 0; i < h; ++i) { - memset(mapPtr, 0, srcRowBytes); - mapPtr = SkTAddOffset(mapPtr, static_cast(dstRowBytes)); - } - } + memset(mapPtr, 0, dstRowBytes * h); } GrVkMemory::FlushMappedAlloc(gpu, alloc, offset, size); GrVkMemory::UnmapAlloc(gpu, alloc); @@ -1079,7 +1072,7 @@ bool copy_testing_data(GrVkGpu* gpu, const void* srcData, const GrVkAlloc& alloc #if GR_TEST_UTILS bool GrVkGpu::createTestingOnlyVkImage(GrPixelConfig config, int w, int h, bool texturable, bool renderable, GrMipMapped mipMapped, const void* srcData, - GrVkImageInfo* info) { + size_t srcRowBytes, GrVkImageInfo* info) { SkASSERT(texturable || renderable); if (!texturable) { SkASSERT(GrMipMapped::kNo == mipMapped); @@ -1189,6 +1182,11 @@ bool GrVkGpu::createTestingOnlyVkImage(GrPixelConfig config, int w, int h, bool size_t bpp = GrBytesPerPixel(config); SkASSERT(w && h); + const size_t trimRowBytes = w * bpp; + if (!srcRowBytes) { + srcRowBytes = trimRowBytes; + } + SkTArray individualMipOffsets(mipLevels); individualMipOffsets.push_back(0); size_t combinedBufferSize = w * bpp * h; @@ -1247,8 +1245,8 @@ bool GrVkGpu::createTestingOnlyVkImage(GrPixelConfig config, int w, int h, bool SkASSERT(0 == currentMipLevel || !srcData); size_t currentRowBytes = bpp * currentWidth; size_t bufferOffset = individualMipOffsets[currentMipLevel]; - if (!copy_testing_data(this, srcData, bufferAlloc, bufferOffset, currentRowBytes, - currentRowBytes, currentHeight)) { + if (!copy_testing_data(this, srcData, bufferAlloc, bufferOffset, srcRowBytes, + currentRowBytes, trimRowBytes, currentHeight)) { GrVkMemory::FreeImageMemory(this, false, alloc); VK_CALL(DestroyImage(fDevice, image, nullptr)); GrVkMemory::FreeBufferMemory(this, GrVkBuffer::kCopyRead_Type, bufferAlloc); @@ -1384,17 +1382,23 @@ bool GrVkGpu::createTestingOnlyVkImage(GrPixelConfig config, int w, int h, bool } GrBackendTexture GrVkGpu::createTestingOnlyBackendTexture(const void* srcData, int w, int h, - GrPixelConfig config, bool isRenderTarget, - GrMipMapped mipMapped) { + GrColorType colorType, + bool isRenderTarget, + GrMipMapped mipMapped, size_t rowBytes) { this->handleDirtyContext(); if (w > this->caps()->maxTextureSize() || h > this->caps()->maxTextureSize()) { return GrBackendTexture(); } + GrPixelConfig config = GrColorTypeToPixelConfig(colorType, GrSRGBEncoded::kNo); + if (!this->caps()->isConfigTexturable(config)) { + return GrBackendTexture(); + } + GrVkImageInfo info; if (!this->createTestingOnlyVkImage(config, w, h, true, isRenderTarget, mipMapped, srcData, - &info)) { + rowBytes, &info)) { return {}; } GrBackendTexture beTex = GrBackendTexture(w, h, info); @@ -1446,7 +1450,7 @@ GrBackendRenderTarget GrVkGpu::createTestingOnlyBackendRenderTarget(int w, int h if (kUnknown_GrPixelConfig == config) { return {}; } - if (!this->createTestingOnlyVkImage(config, w, h, false, true, GrMipMapped::kNo, nullptr, + if (!this->createTestingOnlyVkImage(config, w, h, false, true, GrMipMapped::kNo, nullptr, 0, &info)) { return {}; } diff --git a/src/gpu/vk/GrVkGpu.h b/src/gpu/vk/GrVkGpu.h index dc98ca7bdd..fcf1ab9f14 100644 --- a/src/gpu/vk/GrVkGpu.h +++ b/src/gpu/vk/GrVkGpu.h @@ -76,8 +76,8 @@ public: #if GR_TEST_UTILS GrBackendTexture createTestingOnlyBackendTexture(const void* pixels, int w, int h, - GrPixelConfig config, bool isRenderTarget, - GrMipMapped) override; + GrColorType colorType, bool isRenderTarget, + GrMipMapped, size_t rowBytes = 0) override; bool isTestingOnlyBackendTexture(const GrBackendTexture&) const override; void deleteTestingOnlyBackendTexture(const GrBackendTexture&) override; @@ -226,7 +226,7 @@ private: #if GR_TEST_UTILS bool createTestingOnlyVkImage(GrPixelConfig config, int w, int h, bool texturable, bool renderable, GrMipMapped mipMapped, const void* srcData, - GrVkImageInfo* info); + size_t srcRowBytes, GrVkImageInfo* info); #endif sk_sp fInterface; diff --git a/tests/DeferredDisplayListTest.cpp b/tests/DeferredDisplayListTest.cpp index 66aec1c8a7..c4a7efd67f 100644 --- a/tests/DeferredDisplayListTest.cpp +++ b/tests/DeferredDisplayListTest.cpp @@ -359,7 +359,7 @@ public: : GrMipMapped(fShouldCreateMipMaps); *backend = gpu->createTestingOnlyBackendTexture(nullptr, fWidth, fHeight, - fConfig, true, mipmapped); + fColorType, true, mipmapped); if (!backend->isValid() || !gpu->isTestingOnlyBackendTexture(*backend)) { return nullptr; } @@ -686,7 +686,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DDLWrapBackendTest, reporter, ctxInfo) { GrContext* context = ctxInfo.grContext(); GrGpu* gpu = context->contextPriv().getGpu(); GrBackendTexture backendTex = gpu->createTestingOnlyBackendTexture( - nullptr, kSize, kSize, kRGBA_8888_GrPixelConfig, false, GrMipMapped::kNo); + nullptr, kSize, kSize, GrColorType::kRGBA_8888, false, GrMipMapped::kNo); if (!backendTex.isValid()) { return; } @@ -848,14 +848,14 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(DDLTextureFlagsTest, reporter, ctxInfo) { //////////////////////////////////////////////////////////////////////////////// -// Exhaustively test colorType and pixelConfig compatibility. +// Test colorType and pixelConfig compatibility. DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(DDLCompatibilityTest, reporter, ctxInfo) { GrContext* context = ctxInfo.grContext(); for (int ct = 0; ct <= kLastEnum_SkColorType; ++ct) { SkColorType colorType = static_cast(ct); - for (int config = 0; config < kGrPixelConfigCnt; ++config) { + for (int config = 0; config < kPrivateConfig1_GrPixelConfig; ++config) { GrPixelConfig pixelConfig = static_cast(config); SurfaceParameters params(context->contextPriv().caps()); diff --git a/tests/EGLImageTest.cpp b/tests/EGLImageTest.cpp index bffc05f2e9..0881cc49f6 100644 --- a/tests/EGLImageTest.cpp +++ b/tests/EGLImageTest.cpp @@ -88,7 +88,7 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(EGLImageTest, reporter, ctxInfo) { GrGpu* gpu1 = context1->contextPriv().getGpu(); static const int kSize = 100; backendTexture1 = - gpu1->createTestingOnlyBackendTexture(nullptr, kSize, kSize, kRGBA_8888_GrPixelConfig, + gpu1->createTestingOnlyBackendTexture(nullptr, kSize, kSize, GrColorType::kRGBA_8888, false, GrMipMapped::kNo); if (!backendTexture1.isValid() || !gpu1->isTestingOnlyBackendTexture(backendTexture1)) { diff --git a/tests/GrMipMappedTest.cpp b/tests/GrMipMappedTest.cpp index 658ac61ac5..f7e376831b 100644 --- a/tests/GrMipMappedTest.cpp +++ b/tests/GrMipMappedTest.cpp @@ -42,7 +42,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrWrappedMipMappedTest, reporter, ctxInfo) { // so we don't send any. However, we pretend there is data for the checks below which is // fine since we are never actually using these textures for any work on the gpu. GrBackendTexture backendTex = gpu->createTestingOnlyBackendTexture( - nullptr, kSize, kSize, kRGBA_8888_GrPixelConfig, isRT, mipMapped); + nullptr, kSize, kSize, GrColorType::kRGBA_8888, isRT, mipMapped); sk_sp proxy; sk_sp image; @@ -108,7 +108,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrBackendTextureImageMipMappedTest, reporter, for (auto mipMapped : {GrMipMapped::kNo, GrMipMapped::kYes}) { for (auto willUseMips : {false, true}) { GrBackendTexture backendTex = gpu->createTestingOnlyBackendTexture( - nullptr, kSize, kSize, kRGBA_8888_GrPixelConfig, false, mipMapped); + nullptr, kSize, kSize, GrColorType::kRGBA_8888, false, mipMapped); sk_sp image = SkImage::MakeFromTexture(context, backendTex, kTopLeft_GrSurfaceOrigin, @@ -234,7 +234,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrImageSnapshotMipMappedTest, reporter, ctxIn GrMipMapped mipMapped = willUseMips ? GrMipMapped::kYes : GrMipMapped::kNo; sk_sp surface; GrBackendTexture backendTex = gpu->createTestingOnlyBackendTexture( - nullptr, kSize, kSize, kRGBA_8888_GrPixelConfig, true, mipMapped); + nullptr, kSize, kSize, GrColorType::kRGBA_8888, true, mipMapped); if (isWrapped) { surface = SkSurface::MakeFromBackendTexture(context, backendTex, diff --git a/tests/GrPorterDuffTest.cpp b/tests/GrPorterDuffTest.cpp index 4410181e67..e621fb865a 100644 --- a/tests/GrPorterDuffTest.cpp +++ b/tests/GrPorterDuffTest.cpp @@ -1062,7 +1062,7 @@ DEF_GPUTEST(PorterDuffNoDualSourceBlending, reporter, options) { } GrBackendTexture backendTex = - gpu->createTestingOnlyBackendTexture(nullptr, 100, 100, kRGBA_8888_GrPixelConfig, + gpu->createTestingOnlyBackendTexture(nullptr, 100, 100, GrColorType::kRGBA_8888, false, GrMipMapped::kNo); GrXferProcessor::DstProxy fakeDstProxy; diff --git a/tests/GrSurfaceTest.cpp b/tests/GrSurfaceTest.cpp index 677145ffc6..f7961875db 100644 --- a/tests/GrSurfaceTest.cpp +++ b/tests/GrSurfaceTest.cpp @@ -48,7 +48,7 @@ DEF_GPUTEST_FOR_NULLGL_CONTEXT(GrSurface, reporter, ctxInfo) { REPORTER_ASSERT(reporter, static_cast(tex1.get()) == tex1->asTexture()); GrBackendTexture backendTex = gpu->createTestingOnlyBackendTexture( - nullptr, 256, 256, kRGBA_8888_GrPixelConfig, false, GrMipMapped::kNo); + nullptr, 256, 256, GrColorType::kRGBA_8888, false, GrMipMapped::kNo); sk_sp texRT2 = resourceProvider->wrapRenderableBackendTexture(backendTex, 1, kBorrow_GrWrapOwnership); diff --git a/tests/GrTestingBackendTextureUploadTest.cpp b/tests/GrTestingBackendTextureUploadTest.cpp index e4fec187dc..bfea1b67a3 100644 --- a/tests/GrTestingBackendTextureUploadTest.cpp +++ b/tests/GrTestingBackendTextureUploadTest.cpp @@ -38,9 +38,13 @@ void testing_only_texture_test(skiatest::Reporter* reporter, GrContext* context, GrBackendTexture backendTex = gpu->createTestingOnlyBackendTexture(srcBuffer, kWidth, kHeight, - config, + ct, renderTarget, mipMapped); + if (!backendTex.isValid()) { + return; + } + sk_sp wrappedTex; if (renderTarget) { wrappedTex = gpu->wrapRenderableBackendTexture(backendTex, 1, @@ -67,7 +71,7 @@ void testing_only_texture_test(skiatest::Reporter* reporter, GrContext* context, } DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrTestingBackendTextureUploadTest, reporter, ctxInfo) { - for (auto colorType: {GrColorType::kRGBA_8888, GrColorType::kBGRA_8888}) { + for (auto colorType: { GrColorType::kRGBA_8888, GrColorType::kBGRA_8888 }) { for (bool renderable: {true, false}) { for (bool doDataUpload: {true, false}) { testing_only_texture_test(reporter, ctxInfo.grContext(), colorType, diff --git a/tests/ImageTest.cpp b/tests/ImageTest.cpp index cf287ef20d..51603c7988 100644 --- a/tests/ImageTest.cpp +++ b/tests/ImageTest.cpp @@ -842,7 +842,7 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SkImage_NewFromTextureRelease, reporter, c GrGpu* gpu = ctx->contextPriv().getGpu(); GrBackendTexture backendTex = gpu->createTestingOnlyBackendTexture( - pixels.get(), kWidth, kHeight, kRGBA_8888_GrPixelConfig, true, GrMipMapped::kNo); + pixels.get(), kWidth, kHeight, GrColorType::kRGBA_8888, true, GrMipMapped::kNo); TextureReleaseChecker releaseChecker; GrSurfaceOrigin texOrigin = kBottomLeft_GrSurfaceOrigin; diff --git a/tests/LazyProxyTest.cpp b/tests/LazyProxyTest.cpp index 1b65585c7a..e6516aa767 100644 --- a/tests/LazyProxyTest.cpp +++ b/tests/LazyProxyTest.cpp @@ -435,7 +435,7 @@ DEF_GPUTEST(LazyProxyUninstantiateTest, reporter, /* options */) { desc.fConfig = kRGBA_8888_GrPixelConfig; GrBackendTexture backendTex = gpu->createTestingOnlyBackendTexture( - nullptr, kSize, kSize, kRGBA_8888_GrPixelConfig, false, GrMipMapped::kNo); + nullptr, kSize, kSize, GrColorType::kRGBA_8888, false, GrMipMapped::kNo); sk_sp lazyProxy = proxyProvider->createLazyProxy( [instantiatePtr, releasePtr, backendTex](GrResourceProvider* rp) { diff --git a/tests/PackedConfigsTextureTest.cpp b/tests/PackedConfigsTextureTest.cpp index 75bc666a63..e1ca67b8be 100644 --- a/tests/PackedConfigsTextureTest.cpp +++ b/tests/PackedConfigsTextureTest.cpp @@ -113,7 +113,7 @@ static void run_test(skiatest::Reporter* reporter, GrContext* context, int array for (auto origin : { kTopLeft_GrSurfaceOrigin, kBottomLeft_GrSurfaceOrigin }) { auto proxy = sk_gpu_test::MakeTextureProxyFromData(context, false, DEV_W, DEV_H, - SkColorTypeToGrColorType(colorType), + colorType, origin, controlPixelData.begin(), 0); SkASSERT(proxy); diff --git a/tests/PromiseImageTest.cpp b/tests/PromiseImageTest.cpp index e1b482bbf6..7eed68f0a1 100644 --- a/tests/PromiseImageTest.cpp +++ b/tests/PromiseImageTest.cpp @@ -101,7 +101,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(PromiseImageTest, reporter, ctxInfo) { for (bool releaseImageEarly : {true, false}) { GrBackendTexture backendTex = gpu->createTestingOnlyBackendTexture( - nullptr, kWidth, kHeight, kRGBA_8888_GrPixelConfig, true, GrMipMapped::kNo); + nullptr, kWidth, kHeight, GrColorType::kRGBA_8888, true, GrMipMapped::kNo); REPORTER_ASSERT(reporter, backendTex.isValid()); GrBackendFormat backendFormat = gpu->caps()->createFormatFromBackendTexture(backendTex); diff --git a/tests/ResourceAllocatorTest.cpp b/tests/ResourceAllocatorTest.cpp index 948cfac434..e839d0452f 100644 --- a/tests/ResourceAllocatorTest.cpp +++ b/tests/ResourceAllocatorTest.cpp @@ -24,7 +24,7 @@ struct ProxyParams { int fSize; bool fIsRT; - GrPixelConfig fConfig; + SkColorType fColorType; SkBackingFit fFit; int fSampleCnt; GrSurfaceOrigin fOrigin; @@ -32,11 +32,14 @@ struct ProxyParams { }; static GrSurfaceProxy* make_deferred(GrProxyProvider* proxyProvider, const ProxyParams& p) { + GrColorType grCT = SkColorTypeToGrColorType(p.fColorType); + GrPixelConfig config = GrColorTypeToPixelConfig(grCT, GrSRGBEncoded::kNo); + GrSurfaceDesc desc; desc.fFlags = p.fIsRT ? kRenderTarget_GrSurfaceFlag : kNone_GrSurfaceFlags; desc.fWidth = p.fSize; desc.fHeight = p.fSize; - desc.fConfig = p.fConfig; + desc.fConfig = config; desc.fSampleCnt = p.fSampleCnt; auto tmp = proxyProvider->createProxy(desc, p.fOrigin, p.fFit, SkBudgeted::kNo); @@ -57,8 +60,11 @@ static GrSurfaceProxy* make_backend(GrContext* context, const ProxyParams& p, GrGpu* gpu = context->contextPriv().getGpu(); *backendTex = gpu->createTestingOnlyBackendTexture(nullptr, p.fSize, p.fSize, - p.fConfig, false, + p.fColorType, false, GrMipMapped::kNo); + if (!backendTex->isValid()) { + return nullptr; + } auto tmp = proxyProvider->wrapBackendTexture(*backendTex, p.fOrigin); if (!tmp) { @@ -147,8 +153,8 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ResourceAllocatorTest, reporter, ctxInfo) { // Non-RT GrSurfaces are never recycled on some platforms. bool kConditionallyShare = resourceProvider->caps()->reuseScratchTextures(); - const GrPixelConfig kRGBA = kRGBA_8888_GrPixelConfig; - const GrPixelConfig kBGRA = kBGRA_8888_GrPixelConfig; + const SkColorType kRGBA = kRGBA_8888_SkColorType; + const SkColorType kBGRA = kBGRA_8888_SkColorType; const SkBackingFit kE = SkBackingFit::kExact; const SkBackingFit kA = SkBackingFit::kApprox; @@ -174,8 +180,10 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ResourceAllocatorTest, reporter, ctxInfo) { p2->completedRead(); } - int k2 = ctxInfo.grContext()->contextPriv().caps()->getRenderTargetSampleCount(2, kRGBA); - int k4 = ctxInfo.grContext()->contextPriv().caps()->getRenderTargetSampleCount(4, kRGBA); + int k2 = ctxInfo.grContext()->contextPriv().caps()->getRenderTargetSampleCount( + 2, kRGBA_8888_GrPixelConfig); + int k4 = ctxInfo.grContext()->contextPriv().caps()->getRenderTargetSampleCount( + 4, kRGBA_8888_GrPixelConfig); //-------------------------------------------------------------------------------------------- TestCase gNonOverlappingTests[] = { diff --git a/tests/ResourceCacheTest.cpp b/tests/ResourceCacheTest.cpp index 26fab1f1c0..3dcf194d4a 100644 --- a/tests/ResourceCacheTest.cpp +++ b/tests/ResourceCacheTest.cpp @@ -209,10 +209,10 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ResourceCacheWrappedResources, reporter, ctxI static const int kH = 100; backendTextures[0] = gpu->createTestingOnlyBackendTexture(nullptr, kW, kH, - kRGBA_8888_GrPixelConfig, + GrColorType::kRGBA_8888, false, GrMipMapped::kNo); backendTextures[1] = gpu->createTestingOnlyBackendTexture(nullptr, kW, kH, - kRGBA_8888_GrPixelConfig, + GrColorType::kRGBA_8888, false, GrMipMapped::kNo); REPORTER_ASSERT(reporter, backendTextures[0].isValid()); REPORTER_ASSERT(reporter, backendTextures[1].isValid()); diff --git a/tests/SurfaceTest.cpp b/tests/SurfaceTest.cpp index 2f6205ceff..d956e08adb 100644 --- a/tests/SurfaceTest.cpp +++ b/tests/SurfaceTest.cpp @@ -685,7 +685,7 @@ static sk_sp create_gpu_surface_backend_texture( sk_memset32(pixels.get(), color, kWidth * kHeight); *outTexture = gpu->createTestingOnlyBackendTexture( - pixels.get(), kWidth, kHeight, kRGBA_8888_GrPixelConfig, true, GrMipMapped::kNo); + pixels.get(), kWidth, kHeight, GrColorType::kRGBA_8888, true, GrMipMapped::kNo); if (!outTexture->isValid() || !gpu->isTestingOnlyBackendTexture(*outTexture)) { return nullptr; @@ -712,7 +712,7 @@ static sk_sp create_gpu_surface_backend_texture_as_render_target( sk_memset32(pixels.get(), color, kWidth * kHeight); *outTexture = gpu->createTestingOnlyBackendTexture( - pixels.get(), kWidth, kHeight, kRGBA_8888_GrPixelConfig, true, GrMipMapped::kNo); + pixels.get(), kWidth, kHeight, GrColorType::kRGBA_8888, true, GrMipMapped::kNo, 0); if (!outTexture->isValid() || !gpu->isTestingOnlyBackendTexture(*outTexture)) { return nullptr; @@ -994,11 +994,9 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceCreationWithColorSpace_Gpu, reporter, GrGpu* gpu = context->contextPriv().getGpu(); static const int kSize = 10; - GrPixelConfig config = SkImageInfo2GrPixelConfig(info); - SkASSERT(kUnknown_GrPixelConfig != config); GrBackendTexture backendTex = gpu->createTestingOnlyBackendTexture( - nullptr, kSize, kSize, config, true, GrMipMapped::kNo); + nullptr, kSize, kSize, info.colorType(), true, GrMipMapped::kNo); if (!backendTex.isValid() || !gpu->isTestingOnlyBackendTexture(backendTex)) { diff --git a/tests/VkBackendSurfaceTest.cpp b/tests/VkBackendSurfaceTest.cpp index b6d332552c..bbce1f37b5 100644 --- a/tests/VkBackendSurfaceTest.cpp +++ b/tests/VkBackendSurfaceTest.cpp @@ -29,7 +29,7 @@ DEF_GPUTEST_FOR_VULKAN_CONTEXT(VkImageLayoutTest, reporter, ctxInfo) { GrVkGpu* gpu = static_cast(context->contextPriv().getGpu()); GrBackendTexture backendTex = gpu->createTestingOnlyBackendTexture(nullptr, 1, 1, - kRGBA_8888_GrPixelConfig, + GrColorType::kRGBA_8888, false, GrMipMapped::kNo); REPORTER_ASSERT(reporter, backendTex.isValid()); diff --git a/tests/VkWrapTests.cpp b/tests/VkWrapTests.cpp index f49c249a47..5b2f2096a7 100644 --- a/tests/VkWrapTests.cpp +++ b/tests/VkWrapTests.cpp @@ -28,13 +28,14 @@ using sk_gpu_test::GrContextFactory; const int kW = 1024; const int kH = 1024; const GrPixelConfig kPixelConfig = kRGBA_8888_GrPixelConfig; +const GrColorType kColorType = GrColorType::kRGBA_8888; void wrap_tex_test(skiatest::Reporter* reporter, GrContext* context) { GrVkGpu* gpu = static_cast(context->contextPriv().getGpu()); GrBackendTexture origBackendTex = gpu->createTestingOnlyBackendTexture(nullptr, kW, kH, - kPixelConfig, false, + kColorType, false, GrMipMapped::kNo); GrVkImageInfo imageInfo; SkAssertResult(origBackendTex.getVkImageInfo(&imageInfo)); @@ -81,7 +82,7 @@ void wrap_rt_test(skiatest::Reporter* reporter, GrContext* context) { GrVkGpu* gpu = static_cast(context->contextPriv().getGpu()); GrBackendTexture origBackendTex = gpu->createTestingOnlyBackendTexture(nullptr, kW, kH, - kPixelConfig, true, + kColorType, true, GrMipMapped::kNo); GrVkImageInfo imageInfo; @@ -123,7 +124,7 @@ void wrap_trt_test(skiatest::Reporter* reporter, GrContext* context) { GrVkGpu* gpu = static_cast(context->contextPriv().getGpu()); GrBackendTexture origBackendTex = gpu->createTestingOnlyBackendTexture(nullptr, kW, kH, - kPixelConfig, true, + kColorType, true, GrMipMapped::kNo); GrVkImageInfo imageInfo; SkAssertResult(origBackendTex.getVkImageInfo(&imageInfo)); diff --git a/tests/WritePixelsTest.cpp b/tests/WritePixelsTest.cpp index 82690a38d6..007f16b319 100644 --- a/tests/WritePixelsTest.cpp +++ b/tests/WritePixelsTest.cpp @@ -457,7 +457,7 @@ static void test_write_pixels_non_texture(skiatest::Reporter* reporter, GrContex for (auto& origin : { kTopLeft_GrSurfaceOrigin, kBottomLeft_GrSurfaceOrigin }) { GrBackendTexture backendTex = gpu->createTestingOnlyBackendTexture( - nullptr, DEV_W, DEV_H, kSkia8888_GrPixelConfig, true, GrMipMapped::kNo); + nullptr, DEV_W, DEV_H, GrColorType::kRGBA_8888, true, GrMipMapped::kNo); if (!backendTex.isValid()) { continue; } diff --git a/tools/gpu/GrTest.cpp b/tools/gpu/GrTest.cpp index abf5393d84..4afb07a760 100644 --- a/tools/gpu/GrTest.cpp +++ b/tools/gpu/GrTest.cpp @@ -6,6 +6,7 @@ */ #include "GrBackendSurface.h" +#include "GrClip.h" #include "GrContextOptions.h" #include "GrContextPriv.h" #include "GrDrawOpAtlas.h" @@ -134,16 +135,6 @@ void GrGpu::Stats::dumpKeyValuePairs(SkTArray* keys, SkTArray* #endif -GrBackendTexture GrGpu::createTestingOnlyBackendTexture(const void* pixels, int w, int h, - SkColorType colorType, bool isRenderTarget, - GrMipMapped mipMapped) { - GrPixelConfig config = SkColorType2GrPixelConfig(colorType); - if (kUnknown_GrPixelConfig == config) { - return GrBackendTexture(); - } - return this->createTestingOnlyBackendTexture(pixels, w, h, config, isRenderTarget, mipMapped); -} - #if GR_CACHE_STATS void GrResourceCache::getStats(Stats* stats) const { stats->reset(); diff --git a/tools/gpu/ProxyUtils.cpp b/tools/gpu/ProxyUtils.cpp index dab3ca6b82..9e77a91ee6 100644 --- a/tools/gpu/ProxyUtils.cpp +++ b/tools/gpu/ProxyUtils.cpp @@ -15,19 +15,18 @@ namespace sk_gpu_test { sk_sp MakeTextureProxyFromData(GrContext* context, bool isRT, int width, int height, - GrColorType ct, GrSRGBEncoded srgbEncoded, + GrColorType colorType, GrSRGBEncoded srgbEncoded, GrSurfaceOrigin origin, const void* data, size_t rowBytes) { if (context->abandoned()) { return nullptr; } - auto config = GrColorTypeToPixelConfig(ct, srgbEncoded); sk_sp proxy; if (kBottomLeft_GrSurfaceOrigin == origin) { // We (soon will) only support using kBottomLeft with wrapped textures. auto backendTex = context->contextPriv().getGpu()->createTestingOnlyBackendTexture( - nullptr, width, height, config, isRT, GrMipMapped::kNo); + nullptr, width, height, colorType, isRT, GrMipMapped::kNo); if (!backendTex.isValid()) { return nullptr; } @@ -46,6 +45,11 @@ sk_sp MakeTextureProxyFromData(GrContext* context, bool isRT, in } } else { + GrPixelConfig config = GrColorTypeToPixelConfig(colorType, srgbEncoded); + if (!context->contextPriv().caps()->isConfigTexturable(config)) { + return nullptr; + } + GrSurfaceDesc desc; desc.fConfig = config; desc.fWidth = width; @@ -61,8 +65,8 @@ sk_sp MakeTextureProxyFromData(GrContext* context, bool isRT, in if (!sContext) { return nullptr; } - if (!context->contextPriv().writeSurfacePixels(sContext.get(), 0, 0, width, height, ct, nullptr, - data, rowBytes)) { + if (!context->contextPriv().writeSurfacePixels(sContext.get(), 0, 0, width, height, colorType, + nullptr, data, rowBytes)) { return nullptr; } return proxy;