diff --git a/include/gpu/GrBackendSurface.h b/include/gpu/GrBackendSurface.h index 7bab31d0dd..0145dc44c0 100644 --- a/include/gpu/GrBackendSurface.h +++ b/include/gpu/GrBackendSurface.h @@ -138,10 +138,7 @@ public: // Returns true if the backend texture has been initialized. bool isValid() const { return fConfig != kUnknown_GrPixelConfig; } -#if GR_TEST_UTILS - GrPixelConfig getPixelConfig() const { return fConfig; } - void setPixelConfig(GrPixelConfig config) { fConfig = config; } -#endif + GrPixelConfig testingOnly_getPixelConfig() const; private: // Friending for access to the GrPixelConfig @@ -152,7 +149,6 @@ private: friend class GrGpu; friend class GrGLGpu; friend class GrVkGpu; - friend class PromiseImageHelper; GrPixelConfig config() const { return fConfig; } int fWidth; // 1)) , fBackend(kVulkan_GrBackend) , fVkInfo(vkInfo) {} @@ -99,7 +99,7 @@ GrBackendTexture::GrBackendTexture(int width, const GrGLTextureInfo& glInfo) : fWidth(width) , fHeight(height) - , fConfig(kUnknown_GrPixelConfig) + , fConfig(GrGLSizedFormatToPixelConfig(glInfo.fFormat)) , fMipMapped(mipMapped) , fBackend(kOpenGL_GrBackend) , fGLInfo(glInfo) {} @@ -159,7 +159,7 @@ GrBackendRenderTarget::GrBackendRenderTarget(int width, , fHeight(height) , fSampleCnt(SkTMax(1, sampleCnt)) , fStencilBits(0) // We always create stencil buffers internally for vulkan - , fConfig(kUnknown_GrPixelConfig) + , fConfig(GrVkFormatToPixelConfig(vkInfo.fFormat)) , fBackend(kVulkan_GrBackend) , fVkInfo(vkInfo) {} #endif @@ -187,7 +187,7 @@ GrBackendRenderTarget::GrBackendRenderTarget(int width, , fHeight(height) , fSampleCnt(SkTMax(1, sampleCnt)) , fStencilBits(stencilBits) - , fConfig(kUnknown_GrPixelConfig) + , fConfig(GrGLSizedFormatToPixelConfig(glInfo.fFormat)) , fBackend(kOpenGL_GrBackend) , fGLInfo(glInfo) {} diff --git a/src/gpu/gl/GrGLGpu.cpp b/src/gpu/gl/GrGLGpu.cpp index 9a9f90c04e..4e88f7dde2 100644 --- a/src/gpu/gl/GrGLGpu.cpp +++ b/src/gpu/gl/GrGLGpu.cpp @@ -4411,9 +4411,7 @@ GrBackendTexture GrGLGpu::createTestingOnlyBackendTexture(const void* pixels, in // unbind the texture from the texture unit to avoid asserts GL_CALL(BindTexture(info.fTarget, 0)); - GrBackendTexture beTex = GrBackendTexture(w, h, mipMapped, info); - beTex.setPixelConfig(config); - return beTex; + return GrBackendTexture(w, h, mipMapped, info); } bool GrGLGpu::isTestingOnlyBackendTexture(const GrBackendTexture& tex) const { @@ -4503,9 +4501,7 @@ GrBackendRenderTarget GrGLGpu::createTestingOnlyBackendRenderTarget(int w, int h return {}; } auto stencilBits = SkToInt(this->glCaps().stencilFormats()[sFormatIdx].fStencilBits); - GrBackendRenderTarget beRT = {w, h, 1, stencilBits, info}; - beRT.setPixelConfig(config); - return beRT; + return {w, h, 1, stencilBits, config, info}; } void GrGLGpu::deleteTestingOnlyBackendRenderTarget(const GrBackendRenderTarget& backendRT) { diff --git a/src/gpu/gl/GrGLRenderTarget.cpp b/src/gpu/gl/GrGLRenderTarget.cpp index 73c5fdf4b3..de7399bd92 100644 --- a/src/gpu/gl/GrGLRenderTarget.cpp +++ b/src/gpu/gl/GrGLRenderTarget.cpp @@ -91,16 +91,8 @@ GrBackendRenderTarget GrGLRenderTarget::getBackendRenderTarget() const { numStencilBits = stencil->bits(); } - GrBackendRenderTarget beRT = GrBackendRenderTarget(this->width(), this->height(), - this->numColorSamples(), numStencilBits, - fbi); -#if GR_TEST_UTILS - // We shouldn't have to set this since the client can't access it and we will handle the config - // correctly if we go through our public SkSurface APIs. However, some of our tests bypass the - // public APIs so we need to set this manually here. - beRT.setPixelConfig(this->config()); -#endif - return beRT; + return GrBackendRenderTarget(this->width(), this->height(), this->numColorSamples(), + numStencilBits, fbi); } size_t GrGLRenderTarget::onGpuMemorySize() const { diff --git a/src/gpu/gl/GrGLTexture.cpp b/src/gpu/gl/GrGLTexture.cpp index 771006919b..0f36dd0f32 100644 --- a/src/gpu/gl/GrGLTexture.cpp +++ b/src/gpu/gl/GrGLTexture.cpp @@ -98,15 +98,7 @@ GrBackendObject GrGLTexture::getTextureHandle() const { } GrBackendTexture GrGLTexture::getBackendTexture() const { - GrBackendTexture beTex = GrBackendTexture(this->width(), this->height(), - this->texturePriv().mipMapped(), fInfo); -#if GR_TEST_UTILS - // We shouldn't have to set this since the client can't access it and we will handle the config - // correctly if we go through our public SkSurface and SkImage APIs. However, some of our tests - // bypass the public APIs so we need to set this manually here. - beTex.setPixelConfig(this->config()); -#endif - return beTex; + return GrBackendTexture(this->width(), this->height(), this->texturePriv().mipMapped(), fInfo); } void GrGLTexture::setMemoryBacking(SkTraceMemoryDump* traceMemoryDump, diff --git a/src/gpu/gl/GrGLUtil.cpp b/src/gpu/gl/GrGLUtil.cpp index a268827e23..6b44402c1b 100644 --- a/src/gpu/gl/GrGLUtil.cpp +++ b/src/gpu/gl/GrGLUtil.cpp @@ -486,3 +486,38 @@ GrGLenum GrToGLStencilFunc(GrStencilTest test) { return gTable[(int)test]; } +GrPixelConfig GrGLSizedFormatToPixelConfig(GrGLenum sizedFormat) { + switch (sizedFormat) { + case GR_GL_R8: + return kAlpha_8_as_Red_GrPixelConfig; + case GR_GL_ALPHA8: + return kAlpha_8_as_Alpha_GrPixelConfig; + case GR_GL_RGBA8: + return kRGBA_8888_GrPixelConfig; + case GR_GL_BGRA8: + return kBGRA_8888_GrPixelConfig; + case GR_GL_SRGB8_ALPHA8: + return kSRGBA_8888_GrPixelConfig; + case GR_GL_RGB565: + return kRGB_565_GrPixelConfig; + case GR_GL_RGB5: + return kRGB_565_GrPixelConfig; + case GR_GL_RGBA4: + return kRGBA_4444_GrPixelConfig; + case GR_GL_RGB10_A2: + return kRGBA_1010102_GrPixelConfig; + case GR_GL_LUMINANCE8: + return kGray_8_GrPixelConfig; + case GR_GL_RGBA32F: + return kRGBA_float_GrPixelConfig; + case GR_GL_RG32F: + return kRG_float_GrPixelConfig; + case GR_GL_R16F: + return kAlpha_half_as_Red_GrPixelConfig; + case GR_GL_RGBA16F: + return kRGBA_half_GrPixelConfig; + default: + return kUnknown_GrPixelConfig; + } +} + diff --git a/src/gpu/gl/GrGLUtil.h b/src/gpu/gl/GrGLUtil.h index 88e8901047..9905d75ef1 100644 --- a/src/gpu/gl/GrGLUtil.h +++ b/src/gpu/gl/GrGLUtil.h @@ -248,4 +248,6 @@ void GrGLClearErr(const GrGLInterface* gl); GrGLenum GrToGLStencilFunc(GrStencilTest test); +GrPixelConfig GrGLSizedFormatToPixelConfig(GrGLenum sizedFormat); + #endif diff --git a/src/gpu/vk/GrVkGpu.cpp b/src/gpu/vk/GrVkGpu.cpp index 5469b0e981..6c16a17416 100644 --- a/src/gpu/vk/GrVkGpu.cpp +++ b/src/gpu/vk/GrVkGpu.cpp @@ -1422,6 +1422,7 @@ bool GrVkGpu::createTestingOnlyVkImage(GrPixelConfig config, int w, int h, bool barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; barrier.image = image; barrier.subresourceRange = {VK_IMAGE_ASPECT_COLOR_BIT, 0, mipLevels, 0, 1}; + initialLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; VK_CALL(CmdPipelineBarrier(cmdBuffer, GrVkMemory::LayoutToPipelineStageFlags(initialLayout), VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, @@ -1429,7 +1430,6 @@ bool GrVkGpu::createTestingOnlyVkImage(GrPixelConfig config, int w, int h, bool 0, nullptr, 0, nullptr, 1, &barrier)); - initialLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; } // End CommandBuffer @@ -1499,9 +1499,7 @@ GrBackendTexture GrVkGpu::createTestingOnlyBackendTexture(const void* srcData, i &info)) { return {}; } - GrBackendTexture beTex = GrBackendTexture(w, h, info); - beTex.setPixelConfig(config); - return beTex; + return GrBackendTexture(w, h, info); } bool GrVkGpu::isTestingOnlyBackendTexture(const GrBackendTexture& tex) const { @@ -1545,9 +1543,7 @@ GrBackendRenderTarget GrVkGpu::createTestingOnlyBackendRenderTarget(int w, int h &info)) { return {}; } - GrBackendRenderTarget beRT = {w, h, 1, 0, info}; - beRT.setPixelConfig(config); - return beRT; + return {w, h, 1, 0, info}; } void GrVkGpu::deleteTestingOnlyBackendRenderTarget(const GrBackendRenderTarget& rt) { diff --git a/src/gpu/vk/GrVkRenderTarget.cpp b/src/gpu/vk/GrVkRenderTarget.cpp index 9c57ec01bd..99b6b7632c 100644 --- a/src/gpu/vk/GrVkRenderTarget.cpp +++ b/src/gpu/vk/GrVkRenderTarget.cpp @@ -352,16 +352,8 @@ GrBackendRenderTarget GrVkRenderTarget::getBackendRenderTarget() const { if (GrStencilAttachment* stencil = this->renderTargetPriv().getStencilAttachment()) { numStencilBits = stencil->bits(); } - GrBackendRenderTarget beRT = GrBackendRenderTarget(this->width(), this->height(), - this->numColorSamples(), numStencilBits, - fInfo); -#if GR_TEST_UTILS - // We shouldn't have to set this since the client can't access it and we will handle the config - // correctly if we go through our public SkSurface APIs. However, some of our tests bypass the - // public APIs so we need to set this manually here. - beRT.setPixelConfig(this->config()); -#endif - return beRT; + return GrBackendRenderTarget(this->width(), this->height(), this->numColorSamples(), + numStencilBits, fInfo); } const GrVkResource* GrVkRenderTarget::stencilImageResource() const { diff --git a/src/gpu/vk/GrVkTexture.cpp b/src/gpu/vk/GrVkTexture.cpp index 6668b8f4c1..109b10638d 100644 --- a/src/gpu/vk/GrVkTexture.cpp +++ b/src/gpu/vk/GrVkTexture.cpp @@ -162,14 +162,7 @@ GrBackendObject GrVkTexture::getTextureHandle() const { } GrBackendTexture GrVkTexture::getBackendTexture() const { - GrBackendTexture beTex = GrBackendTexture(this->width(), this->height(), fInfo); -#if GR_TEST_UTILS - // We shouldn't have to set this since the client can't access it and we will handle the config - // correctly if we go through our public SkSurface and SkImage APIs. However, some of our tests - // bypass the public APIs so we need to set this manually here. - beTex.setPixelConfig(this->config()); -#endif - return beTex; + return GrBackendTexture(this->width(), this->height(), fInfo); } GrVkGpu* GrVkTexture::getVkGpu() const { diff --git a/src/gpu/vk/GrVkUtil.cpp b/src/gpu/vk/GrVkUtil.cpp index 5edb2e3818..4f0acdb8f4 100644 --- a/src/gpu/vk/GrVkUtil.cpp +++ b/src/gpu/vk/GrVkUtil.cpp @@ -72,6 +72,40 @@ bool GrPixelConfigToVkFormat(GrPixelConfig config, VkFormat* format) { return false; } +GrPixelConfig GrVkFormatToPixelConfig(VkFormat format) { + switch (format) { + case VK_FORMAT_R8G8B8A8_UNORM: + return kRGBA_8888_GrPixelConfig; + case VK_FORMAT_B8G8R8A8_UNORM: + return kBGRA_8888_GrPixelConfig; + case VK_FORMAT_R8G8B8A8_SRGB: + return kSRGBA_8888_GrPixelConfig; + case VK_FORMAT_B8G8R8A8_SRGB: + return kSBGRA_8888_GrPixelConfig; + case VK_FORMAT_A2B10G10R10_UNORM_PACK32: + return kRGBA_1010102_GrPixelConfig; + case VK_FORMAT_R5G6B5_UNORM_PACK16: + return kRGB_565_GrPixelConfig; + break; + case VK_FORMAT_B4G4R4A4_UNORM_PACK16: + // R4G4B4A4 is not required to be supported so we actually + // store RGBA_4444 data as B4G4R4A4. + return kRGBA_4444_GrPixelConfig; + case VK_FORMAT_R8_UNORM: + return kAlpha_8_GrPixelConfig; + case VK_FORMAT_R32G32B32A32_SFLOAT: + return kRGBA_float_GrPixelConfig; + case VK_FORMAT_R32G32_SFLOAT: + return kRG_float_GrPixelConfig; + case VK_FORMAT_R16G16B16A16_SFLOAT: + return kRGBA_half_GrPixelConfig; + case VK_FORMAT_R16_SFLOAT: + return kAlpha_half_GrPixelConfig; + default: + return kUnknown_GrPixelConfig; + } +} + bool GrVkFormatPixelConfigPairIsValid(VkFormat format, GrPixelConfig config) { switch (format) { case VK_FORMAT_R8G8B8A8_UNORM: diff --git a/src/gpu/vk/GrVkUtil.h b/src/gpu/vk/GrVkUtil.h index b0d118adb5..01688c8486 100644 --- a/src/gpu/vk/GrVkUtil.h +++ b/src/gpu/vk/GrVkUtil.h @@ -32,6 +32,11 @@ class GrVkGpu; */ bool GrPixelConfigToVkFormat(GrPixelConfig config, VkFormat* format); +/** +* Returns the GrPixelConfig for the given vulkan texture format +*/ +GrPixelConfig GrVkFormatToPixelConfig(VkFormat format); + bool GrVkFormatIsSupported(VkFormat); /** diff --git a/src/image/SkImage_Gpu.cpp b/src/image/SkImage_Gpu.cpp index 45906009f8..7c842f69c0 100644 --- a/src/image/SkImage_Gpu.cpp +++ b/src/image/SkImage_Gpu.cpp @@ -589,7 +589,7 @@ public: this->resetReleaseHelper(); } - sk_sp getTexture(GrResourceProvider* resourceProvider, GrPixelConfig config) { + sk_sp getTexture(GrResourceProvider* resourceProvider) { // Releases the promise helper if there are no outstanding hard refs. This means that we // don't have any ReleaseProcs waiting to be called so we will need to do a fulfill. if (fReleaseHelper && fReleaseHelper->weak_expired()) { @@ -599,7 +599,6 @@ public: sk_sp tex; if (!fReleaseHelper) { fFulfillProc(fContext, &fBackendTex); - fBackendTex.fConfig = config; if (!fBackendTex.isValid()) { // Even though the GrBackendTexture is not valid, we must call the release // proc to keep our contract of always calling Fulfill and Release in pairs. @@ -701,13 +700,13 @@ sk_sp SkImage_Gpu::MakePromiseTexture(GrContext* context, PromiseImageHelper promiseHelper(textureFulfillProc, textureReleaseProc, textureContext); sk_sp proxy = proxyProvider->createLazyProxy( - [promiseHelper, config] (GrResourceProvider* resourceProvider) mutable { + [promiseHelper] (GrResourceProvider* resourceProvider) mutable { if (!resourceProvider) { promiseHelper.reset(); return sk_sp(); } - return promiseHelper.getTexture(resourceProvider, config); + return promiseHelper.getTexture(resourceProvider); }, desc, origin, mipMapped, GrRenderTargetFlags::kNone, SkBackingFit::kExact, SkBudgeted::kNo, GrSurfaceProxy::LazyInstantiationType::kUninstantiate); diff --git a/tests/ProxyTest.cpp b/tests/ProxyTest.cpp index 5092abebe6..4970e43a20 100644 --- a/tests/ProxyTest.cpp +++ b/tests/ProxyTest.cpp @@ -215,7 +215,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(WrappedProxyTest, reporter, ctxInfo) { sk_sp sProxy( proxyProvider->wrapBackendRenderTarget(backendRT, origin)); check_surface(reporter, sProxy.get(), origin, kWidthHeight, kWidthHeight, - backendRT.getPixelConfig(), SkBudgeted::kNo); + backendRT.testingOnly_getPixelConfig(), SkBudgeted::kNo); static constexpr int kExpectedNumSamples = 1; check_rendertarget(reporter, caps, resourceProvider, sProxy->asRenderTargetProxy(), kExpectedNumSamples, SkBackingFit::kExact, @@ -244,7 +244,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(WrappedProxyTest, reporter, ctxInfo) { proxyProvider->wrapBackendRenderTarget(backendRT, origin)); check_surface(reporter, sProxy.get(), origin, kWidthHeight, kWidthHeight, - backendRT.getPixelConfig(), SkBudgeted::kNo); + backendRT.testingOnly_getPixelConfig(), SkBudgeted::kNo); check_rendertarget(reporter, caps, resourceProvider, sProxy->asRenderTargetProxy(), supportedNumSamples, SkBackingFit::kExact, 0); @@ -265,7 +265,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(WrappedProxyTest, reporter, ctxInfo) { check_surface(reporter, sProxy.get(), origin, kWidthHeight, kWidthHeight, - backendTex.getPixelConfig(), SkBudgeted::kNo); + backendTex.testingOnly_getPixelConfig(), SkBudgeted::kNo); check_rendertarget(reporter, caps, resourceProvider, sProxy->asRenderTargetProxy(), supportedNumSamples, SkBackingFit::kExact, @@ -290,7 +290,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(WrappedProxyTest, reporter, ctxInfo) { check_surface(reporter, sProxy.get(), origin, kWidthHeight, kWidthHeight, - backendTex.getPixelConfig(), SkBudgeted::kNo); + backendTex.testingOnly_getPixelConfig(), SkBudgeted::kNo); check_rendertarget(reporter, caps, resourceProvider, sProxy->asRenderTargetProxy(), supportedNumSamples, SkBackingFit::kExact, @@ -316,7 +316,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(WrappedProxyTest, reporter, ctxInfo) { check_surface(reporter, sProxy.get(), origin, kWidthHeight, kWidthHeight, - backendTex.getPixelConfig(), SkBudgeted::kNo); + backendTex.testingOnly_getPixelConfig(), SkBudgeted::kNo); check_texture(reporter, resourceProvider, sProxy->asTextureProxy(), SkBackingFit::kExact); diff --git a/tests/SurfaceTest.cpp b/tests/SurfaceTest.cpp index 955a5c550a..bd3090cc8e 100644 --- a/tests/SurfaceTest.cpp +++ b/tests/SurfaceTest.cpp @@ -205,8 +205,6 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrContext_maxSurfaceSamplesForColorType, repo ->accessRenderTargetContext() ->numStencilSamples(); REPORTER_ASSERT(reporter, sampleCnt == max, "Exected: %d, actual: %d", max, sampleCnt); - - gpu->deleteTestingOnlyBackendTexture(backendTex); } } #endif diff --git a/tests/VkWrapTests.cpp b/tests/VkWrapTests.cpp index 58270cd7da..367fdb5c53 100644 --- a/tests/VkWrapTests.cpp +++ b/tests/VkWrapTests.cpp @@ -46,7 +46,6 @@ void wrap_tex_test(skiatest::Reporter* reporter, GrContext* context) { GrVkImageInfo backendCopy = *imageInfo; backendCopy.fImage = VK_NULL_HANDLE; GrBackendTexture backendTex = GrBackendTexture(kW, kH, backendCopy); - backendTex.setPixelConfig(kPixelConfig); tex = gpu->wrapBackendTexture(backendTex, kBorrow_GrWrapOwnership); REPORTER_ASSERT(reporter, !tex); tex = gpu->wrapBackendTexture(backendTex, kAdopt_GrWrapOwnership); @@ -58,7 +57,6 @@ void wrap_tex_test(skiatest::Reporter* reporter, GrContext* context) { GrVkImageInfo backendCopy = *imageInfo; backendCopy.fAlloc = GrVkAlloc(); GrBackendTexture backendTex = GrBackendTexture(kW, kH, backendCopy); - backendTex.setPixelConfig(kPixelConfig); tex = gpu->wrapBackendTexture(backendTex, kBorrow_GrWrapOwnership); REPORTER_ASSERT(reporter, !tex); tex = gpu->wrapBackendTexture(backendTex, kAdopt_GrWrapOwnership); @@ -69,7 +67,6 @@ void wrap_tex_test(skiatest::Reporter* reporter, GrContext* context) { { GrVkImageInfo backendCopy = *imageInfo; GrBackendTexture backendTex = GrBackendTexture(kW, kH, backendCopy); - backendTex.setPixelConfig(kPixelConfig); tex = gpu->wrapBackendTexture(backendTex, kAdopt_GrWrapOwnership); REPORTER_ASSERT(reporter, tex); @@ -79,11 +76,12 @@ void wrap_tex_test(skiatest::Reporter* reporter, GrContext* context) { void wrap_rt_test(skiatest::Reporter* reporter, GrContext* context) { GrVkGpu* gpu = static_cast(context->contextPriv().getGpu()); - GrBackendRenderTarget origBackendRT = gpu->createTestingOnlyBackendRenderTarget( - kW, kH, GrColorType::kRGBA_8888, GrSRGBEncoded::kNo); + GrBackendTexture origBackendTex = gpu->createTestingOnlyBackendTexture(nullptr, kW, kH, + kPixelConfig, true, + GrMipMapped::kNo); + const GrVkImageInfo* imageInfo = origBackendTex.getVkImageInfo(); - const GrVkImageInfo* imageInfo = origBackendRT.getVkImageInfo(); - GrPixelConfig pixelConfig = origBackendRT.getPixelConfig(); + GrBackendRenderTarget origBackendRT(kW, kH, 1, 0, *imageInfo); sk_sp rt = gpu->wrapBackendRenderTarget(origBackendRT); REPORTER_ASSERT(reporter, rt); @@ -93,7 +91,6 @@ void wrap_rt_test(skiatest::Reporter* reporter, GrContext* context) { GrVkImageInfo backendCopy = *imageInfo; backendCopy.fImage = VK_NULL_HANDLE; GrBackendRenderTarget backendRT(kW, kH, 1, 0, backendCopy); - backendRT.setPixelConfig(pixelConfig); rt = gpu->wrapBackendRenderTarget(backendRT); REPORTER_ASSERT(reporter, !rt); } @@ -104,12 +101,13 @@ void wrap_rt_test(skiatest::Reporter* reporter, GrContext* context) { backendCopy.fAlloc = GrVkAlloc(); // can wrap null alloc GrBackendRenderTarget backendRT(kW, kH, 1, 0, backendCopy); - backendRT.setPixelConfig(pixelConfig); rt = gpu->wrapBackendRenderTarget(backendRT); REPORTER_ASSERT(reporter, rt); } - gpu->deleteTestingOnlyBackendRenderTarget(origBackendRT); + // When we wrapBackendRenderTarget it is always borrowed, so we must make sure to free the + // resource when we're done. + gpu->deleteTestingOnlyBackendTexture(origBackendTex); } void wrap_trt_test(skiatest::Reporter* reporter, GrContext* context) { @@ -129,7 +127,6 @@ void wrap_trt_test(skiatest::Reporter* reporter, GrContext* context) { GrVkImageInfo backendCopy = *imageInfo; backendCopy.fImage = VK_NULL_HANDLE; GrBackendTexture backendTex = GrBackendTexture(kW, kH, backendCopy); - backendTex.setPixelConfig(kPixelConfig); tex = gpu->wrapRenderableBackendTexture(backendTex, 1, kBorrow_GrWrapOwnership); REPORTER_ASSERT(reporter, !tex); tex = gpu->wrapRenderableBackendTexture(backendTex, 1, kAdopt_GrWrapOwnership); @@ -141,7 +138,6 @@ void wrap_trt_test(skiatest::Reporter* reporter, GrContext* context) { GrVkImageInfo backendCopy = *imageInfo; backendCopy.fAlloc = GrVkAlloc(); GrBackendTexture backendTex = GrBackendTexture(kW, kH, backendCopy); - backendTex.setPixelConfig(kPixelConfig); tex = gpu->wrapRenderableBackendTexture(backendTex, 1, kBorrow_GrWrapOwnership); REPORTER_ASSERT(reporter, !tex); tex = gpu->wrapRenderableBackendTexture(backendTex, 1, kAdopt_GrWrapOwnership); @@ -152,7 +148,6 @@ void wrap_trt_test(skiatest::Reporter* reporter, GrContext* context) { { GrVkImageInfo backendCopy = *imageInfo; GrBackendTexture backendTex = GrBackendTexture(kW, kH, backendCopy); - backendTex.setPixelConfig(kPixelConfig); tex = gpu->wrapRenderableBackendTexture(backendTex, 1, kAdopt_GrWrapOwnership); REPORTER_ASSERT(reporter, tex); } diff --git a/tools/gpu/GrTest.cpp b/tools/gpu/GrTest.cpp index dfb8c2d4f6..e1a7924062 100644 --- a/tools/gpu/GrTest.cpp +++ b/tools/gpu/GrTest.cpp @@ -56,32 +56,26 @@ void SetupAlwaysEvictAtlas(GrContext* context, int dim) { GrBackendTexture CreateBackendTexture(GrBackend backend, int width, int height, GrPixelConfig config, GrMipMapped mipMapped, GrBackendObject handle) { - GrBackendTexture beTex; switch (backend) { #ifdef SK_VULKAN case kVulkan_GrBackend: { GrVkImageInfo* vkInfo = (GrVkImageInfo*)(handle); SkASSERT((GrMipMapped::kYes == mipMapped) == (vkInfo->fLevelCount > 1)); - beTex = GrBackendTexture(width, height, *vkInfo); - break; + return GrBackendTexture(width, height, *vkInfo); } #endif case kOpenGL_GrBackend: { GrGLTextureInfo* glInfo = (GrGLTextureInfo*)(handle); SkASSERT(glInfo->fFormat); - beTex = GrBackendTexture(width, height, mipMapped, *glInfo); - break; + return GrBackendTexture(width, height, mipMapped, *glInfo); } case kMock_GrBackend: { GrMockTextureInfo* mockInfo = (GrMockTextureInfo*)(handle); - beTex = GrBackendTexture(width, height, mipMapped, *mockInfo); - break; + return GrBackendTexture(width, height, mipMapped, *mockInfo); } default: return GrBackendTexture(); } - beTex.setPixelConfig(config); - return beTex; } GrBackendFormat CreateBackendFormatFromTexture(const GrBackendTexture& tex) { @@ -344,6 +338,16 @@ void GrDrawingManager::testingOnly_removeOnFlushCallbackObject(GrOnFlushCallback ////////////////////////////////////////////////////////////////////////////// +GrPixelConfig GrBackendTexture::testingOnly_getPixelConfig() const { + return fConfig; +} + +GrPixelConfig GrBackendRenderTarget::testingOnly_getPixelConfig() const { + return fConfig; +} + +////////////////////////////////////////////////////////////////////////////// + #define DRAW_OP_TEST_EXTERN(Op) \ extern std::unique_ptr Op##__Test(GrPaint&&, SkRandom*, GrContext*, GrFSAAType) #define DRAW_OP_TEST_ENTRY(Op) Op##__Test