diff --git a/src/gpu/GrGpu.cpp b/src/gpu/GrGpu.cpp index d58ff44d02..b0ff943681 100644 --- a/src/gpu/GrGpu.cpp +++ b/src/gpu/GrGpu.cpp @@ -457,6 +457,7 @@ 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, @@ -470,8 +471,6 @@ 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 f49590dcae..f812d3a425 100644 --- a/src/gpu/GrGpu.h +++ b/src/gpu/GrGpu.h @@ -394,6 +394,7 @@ 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, @@ -407,16 +408,14 @@ 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 dcbd8a54ba..5798f720ea 100644 --- a/src/gpu/gl/GrGLGpu.cpp +++ b/src/gpu/gl/GrGLGpu.cpp @@ -4008,6 +4008,7 @@ 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) { @@ -4191,25 +4192,12 @@ 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()); @@ -4224,6 +4212,15 @@ 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 f2b1ac0da5..e8d5be1a04 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; -#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 038c523094..2a8d4b3bbd 100644 --- a/src/gpu/mock/GrMockGpu.cpp +++ b/src/gpu/mock/GrMockGpu.cpp @@ -196,6 +196,7 @@ 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, @@ -219,16 +220,6 @@ 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()); @@ -240,6 +231,15 @@ 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 24d541a192..f037676259 100644 --- a/src/gpu/mock/GrMockGpu.h +++ b/src/gpu/mock/GrMockGpu.h @@ -121,14 +121,13 @@ 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; - void deleteTestingOnlyBackendTexture(const GrBackendTexture&) override; - -#if GR_TEST_UTILS bool isTestingOnlyBackendTexture(const GrBackendTexture&) const override; + void deleteTestingOnlyBackendTexture(const GrBackendTexture&) 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 35f505ed3b..54b6f34ab2 100644 --- a/src/gpu/mtl/GrMtlGpu.h +++ b/src/gpu/mtl/GrMtlGpu.h @@ -60,6 +60,7 @@ 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, @@ -67,12 +68,12 @@ public: const void* pixels = nullptr, size_t rowBytes = 0) override; - void deleteTestingOnlyBackendTexture(const GrBackendTexture&) override; - -#if GR_TEST_UTILS bool isTestingOnlyBackendTexture(const GrBackendTexture&) const override; + void deleteTestingOnlyBackendTexture(const GrBackendTexture&) override; + GrBackendRenderTarget createTestingOnlyBackendRenderTarget(int w, int h, GrColorType) override; + void deleteTestingOnlyBackendRenderTarget(const GrBackendRenderTarget&) override; void testingOnly_flushGpuAndSync() override; @@ -213,11 +214,13 @@ 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 430983f6ec..9b0f42e243 100644 --- a/src/gpu/mtl/GrMtlGpu.mm +++ b/src/gpu/mtl/GrMtlGpu.mm @@ -608,6 +608,7 @@ 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, @@ -799,17 +800,6 @@ 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()); @@ -825,6 +815,16 @@ 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 c52da42213..4d802342b9 100644 --- a/src/gpu/vk/GrVkGpu.cpp +++ b/src/gpu/vk/GrVkGpu.cpp @@ -1482,6 +1482,7 @@ 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) { @@ -1922,24 +1923,12 @@ 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); @@ -1962,6 +1951,15 @@ 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();