From 50a4e6e3b1289117264c26d66ddaa9862c400acf Mon Sep 17 00:00:00 2001 From: Robert Phillips Date: Wed, 15 May 2019 12:31:15 -0400 Subject: [PATCH] Make createTestingOnlyBackendTexture and deleteTestingOnlyBackendTexture no longer be behind GR_TEST_UTILS Change-Id: Iec44bc46aa2ab2899af3f6df130a93adf3f26e2a Reviewed-on: https://skia-review.googlesource.com/c/skia/+/213821 Commit-Queue: Robert Phillips Reviewed-by: Greg Daniel --- src/gpu/GrGpu.cpp | 3 ++- src/gpu/GrGpu.h | 7 ++++--- src/gpu/gl/GrGLGpu.cpp | 23 +++++++++++++---------- src/gpu/gl/GrGLGpu.h | 6 +++--- src/gpu/mock/GrMockGpu.cpp | 20 ++++++++++---------- src/gpu/mock/GrMockGpu.h | 5 +++-- src/gpu/mtl/GrMtlGpu.h | 9 +++------ src/gpu/mtl/GrMtlGpu.mm | 22 +++++++++++----------- src/gpu/vk/GrVkGpu.cpp | 22 ++++++++++++---------- 9 files changed, 61 insertions(+), 56 deletions(-) diff --git a/src/gpu/GrGpu.cpp b/src/gpu/GrGpu.cpp index b0ff943681..d58ff44d02 100644 --- a/src/gpu/GrGpu.cpp +++ b/src/gpu/GrGpu.cpp @@ -457,7 +457,6 @@ void GrGpu::dumpJSON(SkJSONWriter* writer) const { void GrGpu::dumpJSON(SkJSONWriter* writer) const { } #endif -#if GR_TEST_UTILS GrBackendTexture GrGpu::createTestingOnlyBackendTexture(int w, int h, SkColorType colorType, GrMipMapped mipMapped, GrRenderable renderable, @@ -471,6 +470,8 @@ GrBackendTexture GrGpu::createTestingOnlyBackendTexture(int w, int h, SkColorTyp pixels, rowBytes); } +#if GR_TEST_UTILS + #if GR_GPU_STATS void GrGpu::Stats::dump(SkString* out) { out->appendf("Render Target Binds: %d\n", fRenderTargetBinds); diff --git a/src/gpu/GrGpu.h b/src/gpu/GrGpu.h index f812d3a425..f49590dcae 100644 --- a/src/gpu/GrGpu.h +++ b/src/gpu/GrGpu.h @@ -394,7 +394,6 @@ public: Stats* stats() { return &fStats; } void dumpJSON(SkJSONWriter*) const; -#if GR_TEST_UTILS GrBackendTexture createTestingOnlyBackendTexture(int w, int h, SkColorType, GrMipMapped, GrRenderable, const void* pixels = nullptr, @@ -408,14 +407,16 @@ public: const void* pixels = nullptr, 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; /** * Frees a texture created by createTestingOnlyBackendTexture(). If ownership of the backend * texture has been transferred to a GrContext using adopt semantics this should not be called. */ virtual void deleteTestingOnlyBackendTexture(const GrBackendTexture&) = 0; +#if GR_TEST_UTILS + /** Check a handle represents an actual texture in the backend API that has not been freed. */ + virtual bool isTestingOnlyBackendTexture(const GrBackendTexture&) const = 0; + virtual GrBackendRenderTarget createTestingOnlyBackendRenderTarget(int w, int h, GrColorType) = 0; diff --git a/src/gpu/gl/GrGLGpu.cpp b/src/gpu/gl/GrGLGpu.cpp index 5798f720ea..dcbd8a54ba 100644 --- a/src/gpu/gl/GrGLGpu.cpp +++ b/src/gpu/gl/GrGLGpu.cpp @@ -4008,7 +4008,6 @@ void GrGLGpu::xferBarrier(GrRenderTarget* rt, GrXferBarrierType type) { } } -#if GR_TEST_UTILS static bool gl_format_to_pixel_config(GrGLenum format, GrPixelConfig* config) { GrPixelConfig dontCare; if (!config) { @@ -4192,12 +4191,25 @@ GrBackendTexture GrGLGpu::createTestingOnlyBackendTexture(int w, int h, GL_CALL(BindTexture(info.fTarget, 0)); GrBackendTexture beTex = GrBackendTexture(w, h, mipMapped, info); +#if GR_TEST_UTILS // 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. beTex.setPixelConfig(config); +#endif return beTex; } +void GrGLGpu::deleteTestingOnlyBackendTexture(const GrBackendTexture& tex) { + SkASSERT(GrBackendApi::kOpenGL == tex.backend()); + + GrGLTextureInfo info; + if (tex.getGLTextureInfo(&info)) { + GL_CALL(DeleteTextures(1, &info.fID)); + } +} + +#if GR_TEST_UTILS + bool GrGLGpu::isTestingOnlyBackendTexture(const GrBackendTexture& tex) const { SkASSERT(GrBackendApi::kOpenGL == tex.backend()); @@ -4212,15 +4224,6 @@ bool GrGLGpu::isTestingOnlyBackendTexture(const GrBackendTexture& tex) const { return (GR_GL_TRUE == result); } -void GrGLGpu::deleteTestingOnlyBackendTexture(const GrBackendTexture& tex) { - SkASSERT(GrBackendApi::kOpenGL == tex.backend()); - - GrGLTextureInfo info; - if (tex.getGLTextureInfo(&info)) { - GL_CALL(DeleteTextures(1, &info.fID)); - } -} - GrBackendRenderTarget GrGLGpu::createTestingOnlyBackendRenderTarget(int w, int h, GrColorType colorType) { if (w > this->caps()->maxRenderTargetSize() || h > this->caps()->maxRenderTargetSize()) { diff --git a/src/gpu/gl/GrGLGpu.h b/src/gpu/gl/GrGLGpu.h index e8d5be1a04..f2b1ac0da5 100644 --- a/src/gpu/gl/GrGLGpu.h +++ b/src/gpu/gl/GrGLGpu.h @@ -136,16 +136,16 @@ public: GrStencilAttachment* createStencilAttachmentForRenderTarget(const GrRenderTarget* rt, int width, int height) override; -#if GR_TEST_UTILS GrBackendTexture createTestingOnlyBackendTexture(int w, int h, const GrBackendFormat&, GrMipMapped, GrRenderable, const void* pixels = nullptr, size_t rowBytes = 0) override; - bool isTestingOnlyBackendTexture(const GrBackendTexture&) const override; void deleteTestingOnlyBackendTexture(const GrBackendTexture&) override; - GrBackendRenderTarget createTestingOnlyBackendRenderTarget(int w, int h, GrColorType) override; +#if GR_TEST_UTILS + bool isTestingOnlyBackendTexture(const GrBackendTexture&) const override; + GrBackendRenderTarget createTestingOnlyBackendRenderTarget(int w, int h, GrColorType) override; void deleteTestingOnlyBackendRenderTarget(const GrBackendRenderTarget&) override; const GrGLContext* glContextForTesting() const override { return &this->glContext(); } diff --git a/src/gpu/mock/GrMockGpu.cpp b/src/gpu/mock/GrMockGpu.cpp index 2a8d4b3bbd..038c523094 100644 --- a/src/gpu/mock/GrMockGpu.cpp +++ b/src/gpu/mock/GrMockGpu.cpp @@ -196,7 +196,6 @@ GrStencilAttachment* GrMockGpu::createStencilAttachmentForRenderTarget(const GrR return new GrMockStencilAttachment(this, width, height, kBits, rt->numColorSamples()); } -#if GR_TEST_UTILS GrBackendTexture GrMockGpu::createTestingOnlyBackendTexture(int w, int h, const GrBackendFormat& format, GrMipMapped mipMapped, @@ -220,6 +219,16 @@ GrBackendTexture GrMockGpu::createTestingOnlyBackendTexture(int w, int h, return GrBackendTexture(w, h, mipMapped, info); } +void GrMockGpu::deleteTestingOnlyBackendTexture(const GrBackendTexture& tex) { + SkASSERT(GrBackendApi::kMock == tex.backend()); + + GrMockTextureInfo info; + if (tex.getMockTextureInfo(&info)) { + fOutstandingTestingOnlyTextureIDs.remove(info.fID); + } +} + +#if GR_TEST_UTILS bool GrMockGpu::isTestingOnlyBackendTexture(const GrBackendTexture& tex) const { SkASSERT(GrBackendApi::kMock == tex.backend()); @@ -231,15 +240,6 @@ bool GrMockGpu::isTestingOnlyBackendTexture(const GrBackendTexture& tex) const { return fOutstandingTestingOnlyTextureIDs.contains(info.fID); } -void GrMockGpu::deleteTestingOnlyBackendTexture(const GrBackendTexture& tex) { - SkASSERT(GrBackendApi::kMock == tex.backend()); - - GrMockTextureInfo info; - if (tex.getMockTextureInfo(&info)) { - fOutstandingTestingOnlyTextureIDs.remove(info.fID); - } -} - GrBackendRenderTarget GrMockGpu::createTestingOnlyBackendRenderTarget(int w, int h, GrColorType colorType) { auto config = GrColorTypeToPixelConfig(colorType, GrSRGBEncoded::kNo); diff --git a/src/gpu/mock/GrMockGpu.h b/src/gpu/mock/GrMockGpu.h index f037676259..24d541a192 100644 --- a/src/gpu/mock/GrMockGpu.h +++ b/src/gpu/mock/GrMockGpu.h @@ -121,14 +121,15 @@ private: GrStencilAttachment* createStencilAttachmentForRenderTarget(const GrRenderTarget*, int width, int height) override; -#if GR_TEST_UTILS GrBackendTexture createTestingOnlyBackendTexture(int w, int h, const GrBackendFormat&, GrMipMapped, GrRenderable, const void* pixels = nullptr, size_t rowBytes = 0) override; - bool isTestingOnlyBackendTexture(const GrBackendTexture&) const override; void deleteTestingOnlyBackendTexture(const GrBackendTexture&) override; +#if GR_TEST_UTILS + bool isTestingOnlyBackendTexture(const GrBackendTexture&) const override; + GrBackendRenderTarget createTestingOnlyBackendRenderTarget(int w, int h, GrColorType) override; void deleteTestingOnlyBackendRenderTarget(const GrBackendRenderTarget&) override; diff --git a/src/gpu/mtl/GrMtlGpu.h b/src/gpu/mtl/GrMtlGpu.h index 54b6f34ab2..35f505ed3b 100644 --- a/src/gpu/mtl/GrMtlGpu.h +++ b/src/gpu/mtl/GrMtlGpu.h @@ -60,7 +60,6 @@ public: // command buffer to finish before creating a new buffer and returning. void submitCommandBuffer(SyncQueue sync); -#if GR_TEST_UTILS GrBackendTexture createTestingOnlyBackendTexture(int w, int h, const GrBackendFormat& format, GrMipMapped mipMapped, @@ -68,12 +67,12 @@ public: const void* pixels = nullptr, size_t rowBytes = 0) override; - bool isTestingOnlyBackendTexture(const GrBackendTexture&) const override; - void deleteTestingOnlyBackendTexture(const GrBackendTexture&) override; - GrBackendRenderTarget createTestingOnlyBackendRenderTarget(int w, int h, GrColorType) override; +#if GR_TEST_UTILS + bool isTestingOnlyBackendTexture(const GrBackendTexture&) const override; + GrBackendRenderTarget createTestingOnlyBackendRenderTarget(int w, int h, GrColorType) override; void deleteTestingOnlyBackendRenderTarget(const GrBackendRenderTarget&) override; void testingOnly_flushGpuAndSync() override; @@ -214,13 +213,11 @@ private: int width, int height) override; -#if GR_TEST_UTILS bool createTestingOnlyMtlTextureInfo(GrPixelConfig, MTLPixelFormat, int w, int h, bool texturable, bool renderable, GrMipMapped mipMapped, 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 9b0f42e243..430983f6ec 100644 --- a/src/gpu/mtl/GrMtlGpu.mm +++ b/src/gpu/mtl/GrMtlGpu.mm @@ -608,7 +608,6 @@ bool GrMtlGpu::onRegenerateMipMapLevels(GrTexture* texture) { return true; } -#if GR_TEST_UTILS bool GrMtlGpu::createTestingOnlyMtlTextureInfo(GrPixelConfig config, MTLPixelFormat format, int w, int h, bool texturable, bool renderable, GrMipMapped mipMapped, @@ -800,6 +799,17 @@ GrBackendTexture GrMtlGpu::createTestingOnlyBackendTexture(int w, int h, return backendTex; } +void GrMtlGpu::deleteTestingOnlyBackendTexture(const GrBackendTexture& tex) { + SkASSERT(GrBackendApi::kMetal == tex.fBackend); + + GrMtlTextureInfo info; + if (tex.getMtlTextureInfo(&info)) { + // Adopts the metal texture so that ARC will clean it up. + GrGetMTLTexture(info.fTexture, GrWrapOwnership::kAdopt_GrWrapOwnership); + } +} + +#if GR_TEST_UTILS bool GrMtlGpu::isTestingOnlyBackendTexture(const GrBackendTexture& tex) const { SkASSERT(GrBackendApi::kMetal == tex.backend()); @@ -815,16 +825,6 @@ bool GrMtlGpu::isTestingOnlyBackendTexture(const GrBackendTexture& tex) const { return mtlTexture.usage & MTLTextureUsageShaderRead; } -void GrMtlGpu::deleteTestingOnlyBackendTexture(const GrBackendTexture& tex) { - SkASSERT(GrBackendApi::kMetal == tex.fBackend); - - GrMtlTextureInfo info; - if (tex.getMtlTextureInfo(&info)) { - // Adopts the metal texture so that ARC will clean it up. - GrGetMTLTexture(info.fTexture, GrWrapOwnership::kAdopt_GrWrapOwnership); - } -} - GrBackendRenderTarget GrMtlGpu::createTestingOnlyBackendRenderTarget(int w, int h, GrColorType ct) { if (w > this->caps()->maxRenderTargetSize() || h > this->caps()->maxRenderTargetSize()) { return GrBackendRenderTarget(); diff --git a/src/gpu/vk/GrVkGpu.cpp b/src/gpu/vk/GrVkGpu.cpp index 4d802342b9..c52da42213 100644 --- a/src/gpu/vk/GrVkGpu.cpp +++ b/src/gpu/vk/GrVkGpu.cpp @@ -1482,7 +1482,6 @@ bool copy_testing_data(GrVkGpu* gpu, const void* srcData, const GrVkAlloc& alloc return true; } -#if GR_TEST_UTILS static size_t compute_combined_buffer_size(VkFormat format, size_t bpp, int w, int h, SkTArray* individualMipOffsets, uint32_t mipLevels) { @@ -1923,12 +1922,24 @@ GrBackendTexture GrVkGpu::createTestingOnlyBackendTexture(int w, int h, return {}; } GrBackendTexture beTex = GrBackendTexture(w, h, info); +#if GR_TEST_UTILS // 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. beTex.setPixelConfig(config); +#endif return beTex; } +void GrVkGpu::deleteTestingOnlyBackendTexture(const GrBackendTexture& tex) { + SkASSERT(GrBackendApi::kVulkan == tex.fBackend); + + GrVkImageInfo info; + if (tex.getVkImageInfo(&info)) { + GrVkImage::DestroyImageInfo(this, const_cast(&info)); + } +} + +#if GR_TEST_UTILS bool GrVkGpu::isTestingOnlyBackendTexture(const GrBackendTexture& tex) const { SkASSERT(GrBackendApi::kVulkan == tex.fBackend); @@ -1951,15 +1962,6 @@ bool GrVkGpu::isTestingOnlyBackendTexture(const GrBackendTexture& tex) const { return false; } -void GrVkGpu::deleteTestingOnlyBackendTexture(const GrBackendTexture& tex) { - SkASSERT(GrBackendApi::kVulkan == tex.fBackend); - - GrVkImageInfo info; - if (tex.getVkImageInfo(&info)) { - GrVkImage::DestroyImageInfo(this, const_cast(&info)); - } -} - GrBackendRenderTarget GrVkGpu::createTestingOnlyBackendRenderTarget(int w, int h, GrColorType ct) { if (w > this->caps()->maxRenderTargetSize() || h > this->caps()->maxRenderTargetSize()) { return GrBackendRenderTarget();