diff options
author | Greg Daniel <egdaniel@google.com> | 2017-10-12 12:27:11 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-10-12 17:02:41 +0000 |
commit | 177e695589edb1f776cc5c28b9d3eee244d48284 (patch) | |
tree | eaa617f0300127c65a90a6aea03dc85f7d136d46 | |
parent | 18e5cbbe65cc70c6818cc6b135ff45f4653f960b (diff) |
Add flag on GrBackendTexture to say whether texture is mipped or not
Bug: skia:
Change-Id: Ia684e3daf779ec2feaaec64c04dabf5cb03cd07a
Reviewed-on: https://skia-review.googlesource.com/57821
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Greg Daniel <egdaniel@google.com>
31 files changed, 249 insertions, 39 deletions
diff --git a/gn/tests.gni b/gn/tests.gni index a6135ed9c8..3c42b80ba2 100644 --- a/gn/tests.gni +++ b/gn/tests.gni @@ -92,6 +92,7 @@ tests_sources = [ "$_tests/GrContextFactoryTest.cpp", "$_tests/GrMemoryPoolTest.cpp", "$_tests/GrMeshTest.cpp", + "$_tests/GrMipMappedTest.cpp", "$_tests/GrPipelineDynamicStateTest.cpp", "$_tests/GrPorterDuffTest.cpp", "$_tests/GrShapeTest.cpp", diff --git a/include/gpu/GrBackendSurface.h b/include/gpu/GrBackendSurface.h index 55cec78548..647d20d52b 100644 --- a/include/gpu/GrBackendSurface.h +++ b/include/gpu/GrBackendSurface.h @@ -26,6 +26,12 @@ public: GrPixelConfig config, const GrGLTextureInfo& glInfo); + GrBackendTexture(int width, + int height, + GrPixelConfig config, + GrMipMapped, + const GrGLTextureInfo& glInfo); + #ifdef SK_VULKAN GrBackendTexture(int width, int height, @@ -37,9 +43,16 @@ public: GrPixelConfig config, const GrMockTextureInfo& mockInfo); + GrBackendTexture(int width, + int height, + GrPixelConfig config, + GrMipMapped, + const GrMockTextureInfo& mockInfo); + int width() const { return fWidth; } int height() const { return fHeight; } GrPixelConfig config() const { return fConfig; } + bool hasMipMaps() const { return GrMipMapped::kYes == fMipMapped; } GrBackend backend() const {return fBackend; } // If the backend API is GL, this returns a pointer to the GrGLTextureInfo struct. Otherwise @@ -62,6 +75,7 @@ private: int fWidth; //<! width in pixels int fHeight; //<! height in pixels GrPixelConfig fConfig; + GrMipMapped fMipMapped; GrBackend fBackend; union { diff --git a/include/gpu/GrTypes.h b/include/gpu/GrTypes.h index 606fc00cb3..5055ec165e 100644 --- a/include/gpu/GrTypes.h +++ b/include/gpu/GrTypes.h @@ -218,6 +218,20 @@ static inline GrAA GrBoolToAA(bool aa) { return aa ? GrAA::kYes : GrAA::kNo; } /////////////////////////////////////////////////////////////////////////////// /** + * Used to say whether a texture has mip levels allocated or not. + */ +enum class GrMipMapped { + kYes, + kNo +}; + +static inline GrMipMapped GrBoolToMipMapped(bool mipMapped) { + return mipMapped ? GrMipMapped::kYes : GrMipMapped::kNo; +} + +/////////////////////////////////////////////////////////////////////////////// + +/** * Geometric primitives used for drawing. */ enum class GrPrimitiveType { diff --git a/src/gpu/GrBackendSurface.cpp b/src/gpu/GrBackendSurface.cpp index 04216b7508..67cc634ce0 100644 --- a/src/gpu/GrBackendSurface.cpp +++ b/src/gpu/GrBackendSurface.cpp @@ -19,6 +19,7 @@ GrBackendTexture::GrBackendTexture(int width, : fWidth(width) , fHeight(height) , fConfig(GrVkFormatToPixelConfig(vkInfo.fFormat)) + , fMipMapped(GrBoolToMipMapped(vkInfo.fLevelCount > 1)) , fBackend(kVulkan_GrBackend) , fVkInfo(vkInfo) {} #endif @@ -27,9 +28,17 @@ GrBackendTexture::GrBackendTexture(int width, int height, GrPixelConfig config, const GrGLTextureInfo& glInfo) + : GrBackendTexture(width, height, config, GrMipMapped::kNo, glInfo) {} + +GrBackendTexture::GrBackendTexture(int width, + int height, + GrPixelConfig config, + GrMipMapped mipMapped, + const GrGLTextureInfo& glInfo) : fWidth(width) , fHeight(height) , fConfig(config) + , fMipMapped(mipMapped) , fBackend(kOpenGL_GrBackend) , fGLInfo(glInfo) {} @@ -37,9 +46,17 @@ GrBackendTexture::GrBackendTexture(int width, int height, GrPixelConfig config, const GrMockTextureInfo& mockInfo) + : GrBackendTexture(width, height, config, GrMipMapped::kNo, mockInfo) {} + +GrBackendTexture::GrBackendTexture(int width, + int height, + GrPixelConfig config, + GrMipMapped mipMapped, + const GrMockTextureInfo& mockInfo) : fWidth(width) , fHeight(height) , fConfig(config) + , fMipMapped(mipMapped) , fBackend(kMock_GrBackend) , fMockInfo(mockInfo) {} diff --git a/src/gpu/GrGpu.h b/src/gpu/GrGpu.h index ef99a4801e..676b3b0811 100644 --- a/src/gpu/GrGpu.h +++ b/src/gpu/GrGpu.h @@ -465,9 +465,11 @@ public: /** 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(). */ - virtual GrBackendObject createTestingOnlyBackendTexture(void* pixels, int w, int h, - GrPixelConfig config, - bool isRenderTarget = false) = 0; + virtual GrBackendObject createTestingOnlyBackendTexture( + void* pixels, int w, int h, + GrPixelConfig config, + bool isRenderTarget = false, + GrMipMapped mipMapped = GrMipMapped::kNo) = 0; /** Check a handle represents an actual texture in the backend API that has not been freed. */ virtual bool isTestingOnlyBackendTexture(GrBackendObject) const = 0; /** If ownership of the backend texture has been transferred pass true for abandonTexture. This diff --git a/src/gpu/gl/GrGLGpu.cpp b/src/gpu/gl/GrGLGpu.cpp index 86aa76f981..3d347eca10 100644 --- a/src/gpu/gl/GrGLGpu.cpp +++ b/src/gpu/gl/GrGLGpu.cpp @@ -551,7 +551,10 @@ sk_sp<GrTexture> GrGLGpu::onWrapBackendTexture(const GrBackendTexture& backendTe surfDesc.fConfig = backendTex.config(); surfDesc.fSampleCnt = 0; - return GrGLTexture::MakeWrapped(this, surfDesc, idDesc); + GrMipMapsStatus mipMapsStatus = backendTex.hasMipMaps() ? GrMipMapsStatus::kValid + : GrMipMapsStatus::kNotAllocated; + + return GrGLTexture::MakeWrapped(this, surfDesc, mipMapsStatus, idDesc); } sk_sp<GrTexture> GrGLGpu::onWrapRenderableBackendTexture(const GrBackendTexture& backendTex, @@ -585,8 +588,12 @@ sk_sp<GrTexture> GrGLGpu::onWrapRenderableBackendTexture(const GrBackendTexture& if (!this->createRenderTargetObjects(surfDesc, idDesc.fInfo, &rtIDDesc)) { return nullptr; } + + GrMipMapsStatus mipMapsStatus = backendTex.hasMipMaps() ? GrMipMapsStatus::kDirty + : GrMipMapsStatus::kNotAllocated; + sk_sp<GrGLTextureRenderTarget> texRT( - GrGLTextureRenderTarget::MakeWrapped(this, surfDesc, idDesc, rtIDDesc)); + GrGLTextureRenderTarget::MakeWrapped(this, surfDesc, idDesc, rtIDDesc, mipMapsStatus)); texRT->baseLevelWasBoundToFBO(); return std::move(texRT); } @@ -4230,10 +4237,17 @@ void GrGLGpu::xferBarrier(GrRenderTarget* rt, GrXferBarrierType type) { } GrBackendObject GrGLGpu::createTestingOnlyBackendTexture(void* pixels, int w, int h, - GrPixelConfig config, bool /*isRT*/) { + GrPixelConfig config, bool /*isRT*/, + GrMipMapped mipMapped) { if (!this->caps()->isConfigTexturable(config)) { - return false; + return reinterpret_cast<GrBackendObject>(nullptr); + } + + // Currently we don't support uploading pixel data when mipped. + if (pixels && GrMipMapped::kYes == mipMapped) { + return reinterpret_cast<GrBackendObject>(nullptr); } + std::unique_ptr<GrGLTextureInfo> info = skstd::make_unique<GrGLTextureInfo>(); info->fTarget = GR_GL_TEXTURE_2D; info->fID = 0; @@ -4257,8 +4271,21 @@ GrBackendObject GrGLGpu::createTestingOnlyBackendTexture(void* pixels, int w, in } this->unbindCpuToGpuXferBuffer(); - GL_CALL(TexImage2D(info->fTarget, 0, internalFormat, w, h, 0, externalFormat, - externalType, pixels)); + + // Figure out the number of mip levels. + int mipLevels = 1; + if (GrMipMapped::kYes == mipMapped) { + mipLevels = SkMipMap::ComputeLevelCount(w, h) + 1; + } + + int width = w; + int height = h; + for (int i = 0; i < mipLevels; ++i) { + GL_CALL(TexImage2D(info->fTarget, 0, internalFormat, width, height, 0, externalFormat, + externalType, pixels)); + width = SkTMax(1, width / 2); + height = SkTMax(1, height / 2); + } return reinterpret_cast<GrBackendObject>(info.release()); } diff --git a/src/gpu/gl/GrGLGpu.h b/src/gpu/gl/GrGLGpu.h index a3af0ae8db..0fef2afb05 100644 --- a/src/gpu/gl/GrGLGpu.h +++ b/src/gpu/gl/GrGLGpu.h @@ -165,7 +165,8 @@ public: GrBackendObject createTestingOnlyBackendTexture(void* pixels, int w, int h, GrPixelConfig config, - bool isRenderTarget = false) override; + bool isRenderTarget, + GrMipMapped mipMapped) override; bool isTestingOnlyBackendTexture(GrBackendObject) const override; void deleteTestingOnlyBackendTexture(GrBackendObject, bool abandonTexture) override; diff --git a/src/gpu/gl/GrGLTexture.cpp b/src/gpu/gl/GrGLTexture.cpp index aa918d5ed7..b5c8c697e1 100644 --- a/src/gpu/gl/GrGLTexture.cpp +++ b/src/gpu/gl/GrGLTexture.cpp @@ -57,10 +57,11 @@ GrGLTexture::GrGLTexture(GrGLGpu* gpu, SkBudgeted budgeted, const GrSurfaceDesc& this->registerWithCache(budgeted); } -GrGLTexture::GrGLTexture(GrGLGpu* gpu, Wrapped, const GrSurfaceDesc& desc, const IDDesc& idDesc) +GrGLTexture::GrGLTexture(GrGLGpu* gpu, Wrapped, const GrSurfaceDesc& desc, + GrMipMapsStatus mipMapsStatus, const IDDesc& idDesc) : GrSurface(gpu, desc) , INHERITED(gpu, desc, sampler_type(idDesc, desc.fConfig, gpu), - highest_filter_mode(idDesc, desc.fConfig), GrMipMapsStatus::kNotAllocated) { + highest_filter_mode(idDesc, desc.fConfig), mipMapsStatus) { this->init(desc, idDesc); this->registerWithCacheWrapped(); } @@ -112,7 +113,7 @@ void GrGLTexture::setMemoryBacking(SkTraceMemoryDump* traceMemoryDump, } sk_sp<GrGLTexture> GrGLTexture::MakeWrapped(GrGLGpu* gpu, const GrSurfaceDesc& desc, - const IDDesc& idDesc) { - return sk_sp<GrGLTexture>(new GrGLTexture(gpu, kWrapped, desc, idDesc)); + GrMipMapsStatus mipMapsStatus, const IDDesc& idDesc) { + return sk_sp<GrGLTexture>(new GrGLTexture(gpu, kWrapped, desc, mipMapsStatus, idDesc)); } diff --git a/src/gpu/gl/GrGLTexture.h b/src/gpu/gl/GrGLTexture.h index 8ab6805738..bb46d8d9b6 100644 --- a/src/gpu/gl/GrGLTexture.h +++ b/src/gpu/gl/GrGLTexture.h @@ -67,7 +67,8 @@ public: bool hasBaseLevelBeenBoundToFBO() const { return fBaseLevelHasBeenBoundToFBO; } void baseLevelWasBoundToFBO() { fBaseLevelHasBeenBoundToFBO = true; } - static sk_sp<GrGLTexture> MakeWrapped(GrGLGpu*, const GrSurfaceDesc&, const IDDesc&); + static sk_sp<GrGLTexture> MakeWrapped(GrGLGpu*, const GrSurfaceDesc&, GrMipMapsStatus, + const IDDesc&); protected: // Constructor for subclasses. @@ -75,7 +76,7 @@ protected: enum Wrapped { kWrapped }; // Constructor for instances wrapping backend objects. - GrGLTexture(GrGLGpu*, Wrapped, const GrSurfaceDesc&, const IDDesc&); + GrGLTexture(GrGLGpu*, Wrapped, const GrSurfaceDesc&, GrMipMapsStatus, const IDDesc&); void init(const GrSurfaceDesc&, const IDDesc&); diff --git a/src/gpu/gl/GrGLTextureRenderTarget.cpp b/src/gpu/gl/GrGLTextureRenderTarget.cpp index c5a75be872..c4a0456171 100644 --- a/src/gpu/gl/GrGLTextureRenderTarget.cpp +++ b/src/gpu/gl/GrGLTextureRenderTarget.cpp @@ -27,9 +27,10 @@ GrGLTextureRenderTarget::GrGLTextureRenderTarget(GrGLGpu* gpu, GrGLTextureRenderTarget::GrGLTextureRenderTarget(GrGLGpu* gpu, const GrSurfaceDesc& desc, const GrGLTexture::IDDesc& texIDDesc, - const GrGLRenderTarget::IDDesc& rtIDDesc) + const GrGLRenderTarget::IDDesc& rtIDDesc, + GrMipMapsStatus mipMapsStatus) : GrSurface(gpu, desc) - , GrGLTexture(gpu, desc, texIDDesc, GrMipMapsStatus::kNotAllocated) + , GrGLTexture(gpu, desc, texIDDesc, mipMapsStatus) , GrGLRenderTarget(gpu, desc, rtIDDesc) { this->registerWithCacheWrapped(); } @@ -70,11 +71,11 @@ bool GrGLTextureRenderTarget::canAttemptStencilAttachment() const { } sk_sp<GrGLTextureRenderTarget> GrGLTextureRenderTarget::MakeWrapped( - GrGLGpu* gpu, const GrSurfaceDesc& desc, - const GrGLTexture::IDDesc& texIDDesc, const GrGLRenderTarget::IDDesc& rtIDDesc) + GrGLGpu* gpu, const GrSurfaceDesc& desc, const GrGLTexture::IDDesc& texIDDesc, + const GrGLRenderTarget::IDDesc& rtIDDesc, GrMipMapsStatus mipMapsStatus) { return sk_sp<GrGLTextureRenderTarget>( - new GrGLTextureRenderTarget(gpu, desc, texIDDesc, rtIDDesc)); + new GrGLTextureRenderTarget(gpu, desc, texIDDesc, rtIDDesc, mipMapsStatus)); } size_t GrGLTextureRenderTarget::onGpuMemorySize() const { diff --git a/src/gpu/gl/GrGLTextureRenderTarget.h b/src/gpu/gl/GrGLTextureRenderTarget.h index 6621f9c004..4a6cae0b97 100644 --- a/src/gpu/gl/GrGLTextureRenderTarget.h +++ b/src/gpu/gl/GrGLTextureRenderTarget.h @@ -37,7 +37,8 @@ public: static sk_sp<GrGLTextureRenderTarget> MakeWrapped(GrGLGpu* gpu, const GrSurfaceDesc& desc, const GrGLTexture::IDDesc& texIDDesc, - const GrGLRenderTarget::IDDesc& rtIDDesc); + const GrGLRenderTarget::IDDesc& rtIDDesc, + GrMipMapsStatus); protected: void onAbandon() override { GrGLRenderTarget::onAbandon(); @@ -54,7 +55,8 @@ private: GrGLTextureRenderTarget(GrGLGpu* gpu, const GrSurfaceDesc& desc, const GrGLTexture::IDDesc& texIDDesc, - const GrGLRenderTarget::IDDesc& rtIDDesc); + const GrGLRenderTarget::IDDesc& rtIDDesc, + GrMipMapsStatus); size_t onGpuMemorySize() const override; }; diff --git a/src/gpu/mock/GrMockGpu.cpp b/src/gpu/mock/GrMockGpu.cpp index 9730ddaefe..a21991fabe 100644 --- a/src/gpu/mock/GrMockGpu.cpp +++ b/src/gpu/mock/GrMockGpu.cpp @@ -91,7 +91,8 @@ GrStencilAttachment* GrMockGpu::createStencilAttachmentForRenderTarget(const GrR } GrBackendObject GrMockGpu::createTestingOnlyBackendTexture(void* pixels, int w, int h, - GrPixelConfig config, bool isRT) { + GrPixelConfig config, bool isRT, + GrMipMapped) { auto info = new GrMockTextureInfo; info->fID = NextExternalTextureID(); fOutstandingTestingOnlyTextureIDs.add(info->fID); diff --git a/src/gpu/mock/GrMockGpu.h b/src/gpu/mock/GrMockGpu.h index 5efe3b796e..574906ea3d 100644 --- a/src/gpu/mock/GrMockGpu.h +++ b/src/gpu/mock/GrMockGpu.h @@ -132,7 +132,7 @@ private: void clearStencil(GrRenderTarget*, int clearValue) override {} GrBackendObject createTestingOnlyBackendTexture(void* pixels, int w, int h, GrPixelConfig, - bool isRT) override; + bool isRT, GrMipMapped) override; bool isTestingOnlyBackendTexture(GrBackendObject) const override; diff --git a/src/gpu/mtl/GrMtlGpu.h b/src/gpu/mtl/GrMtlGpu.h index 17949488cc..fb2c368102 100644 --- a/src/gpu/mtl/GrMtlGpu.h +++ b/src/gpu/mtl/GrMtlGpu.h @@ -144,7 +144,8 @@ private: void clearStencil(GrRenderTarget* target, int clearValue) override {} GrBackendObject createTestingOnlyBackendTexture(void* pixels, int w, int h, - GrPixelConfig config, bool isRT) override { + GrPixelConfig config, bool isRT, + GrMipMapped) override { return 0; } bool isTestingOnlyBackendTexture(GrBackendObject ) const override { return false; } diff --git a/src/gpu/vk/GrVkGpu.cpp b/src/gpu/vk/GrVkGpu.cpp index 2119199f65..1a9bd2f254 100644 --- a/src/gpu/vk/GrVkGpu.cpp +++ b/src/gpu/vk/GrVkGpu.cpp @@ -1175,7 +1175,8 @@ bool copy_testing_data(GrVkGpu* gpu, void* srcData, const GrVkAlloc& alloc, GrBackendObject GrVkGpu::createTestingOnlyBackendTexture(void* srcData, int w, int h, GrPixelConfig config, - bool isRenderTarget) { + bool isRenderTarget, + GrMipMapped mipMapped) { VkFormat pixelFormat; if (!GrPixelConfigToVkFormat(config, &pixelFormat)) { @@ -1191,8 +1192,14 @@ GrBackendObject GrVkGpu::createTestingOnlyBackendTexture(void* srcData, int w, i return 0; } + // Currently we don't support uploading pixel data when mipped. + if (srcData && GrMipMapped::kYes == mipMapped) { + return 0; + } + if (fVkCaps->isConfigTexturableLinearly(config) && - (!isRenderTarget || fVkCaps->isConfigRenderableLinearly(config, false))) { + (!isRenderTarget || fVkCaps->isConfigRenderableLinearly(config, false)) && + GrMipMapped::kNo == mipMapped) { linearTiling = true; } @@ -1217,6 +1224,12 @@ GrBackendObject GrVkGpu::createTestingOnlyBackendTexture(void* srcData, int w, i return 0; } + // Figure out the number of mip levels. + uint32_t mipLevels = 1; + if (GrMipMapped::kYes == mipMapped) { + mipLevels = SkMipMap::ComputeLevelCount(w, h) + 1; + } + const VkImageCreateInfo imageCreateInfo = { VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, // sType nullptr, // pNext @@ -1224,7 +1237,7 @@ GrBackendObject GrVkGpu::createTestingOnlyBackendTexture(void* srcData, int w, i VK_IMAGE_TYPE_2D, // VkImageType pixelFormat, // VkFormat { (uint32_t) w, (uint32_t) h, 1 }, // VkExtent3D - 1, // mipLevels + mipLevels, // mipLevels 1, // arrayLayers vkSamples, // samples imageTiling, // VkImageTiling @@ -1414,7 +1427,7 @@ GrBackendObject GrVkGpu::createTestingOnlyBackendTexture(void* srcData, int w, i info->fImageTiling = imageTiling; info->fImageLayout = initialLayout; info->fFormat = pixelFormat; - info->fLevelCount = 1; + info->fLevelCount = mipLevels; return (GrBackendObject)info; } diff --git a/src/gpu/vk/GrVkGpu.h b/src/gpu/vk/GrVkGpu.h index 3850af623d..1d2aca3673 100644 --- a/src/gpu/vk/GrVkGpu.h +++ b/src/gpu/vk/GrVkGpu.h @@ -87,7 +87,8 @@ public: GrBackendObject createTestingOnlyBackendTexture(void* pixels, int w, int h, GrPixelConfig config, - bool isRenderTarget) override; + bool isRenderTarget, + GrMipMapped) override; bool isTestingOnlyBackendTexture(GrBackendObject id) const override; void deleteTestingOnlyBackendTexture(GrBackendObject id, bool abandonTexture) override; diff --git a/tests/BlendTest.cpp b/tests/BlendTest.cpp index 20ea6e0f00..354bb3cebb 100644 --- a/tests/BlendTest.cpp +++ b/tests/BlendTest.cpp @@ -105,6 +105,7 @@ static sk_sp<SkSurface> create_gpu_surface_backend_texture_as_render_target( width, height, config, + GrMipMapped::kNo, (*backingSurface)->getTextureHandle()); sk_sp<SkSurface> surface = SkSurface::MakeFromBackendTextureAsRenderTarget(context, backendTex, origin, diff --git a/tests/GrMipMappedTest.cpp b/tests/GrMipMappedTest.cpp new file mode 100644 index 0000000000..166713a2bd --- /dev/null +++ b/tests/GrMipMappedTest.cpp @@ -0,0 +1,97 @@ +/* + * Copyright 2017 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "SkTypes.h" + +#if SK_SUPPORT_GPU + +#include "GrBackendSurface.h" +#include "GrContext.h" +#include "GrContextPriv.h" +#include "GrGpu.h" +#include "GrRenderTargetContext.h" +#include "GrSurfaceProxyPriv.h" +#include "GrTest.h" +#include "GrTexturePriv.h" +#include "GrTextureProxy.h" +#include "SkCanvas.h" +#include "SkImage_Base.h" +#include "SkGpuDevice.h" +#include "SkSurface.h" +#include "SkSurface_Gpu.h" +#include "Test.h" + +// Test that the correct mip map states are on the GrTextures when wrapping GrBackendTextures in +// SkImages and SkSurfaces +DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrWrappedMipMappedTest, reporter, ctxInfo) { + GrContext* context = ctxInfo.grContext(); + for (auto mipMapped : {GrMipMapped::kNo, GrMipMapped::kYes}) { + for (auto isRT : {false, true}) { + // CreateTestingOnlyBackendTexture currently doesn't support uploading data to mip maps + // 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. + GrBackendObject backendHandle = context->getGpu()->createTestingOnlyBackendTexture( + nullptr, 8, 8, kRGBA_8888_GrPixelConfig, isRT, mipMapped); + + GrBackend backend = context->contextPriv().getBackend(); + GrBackendTexture backendTex = GrTest::CreateBackendTexture(backend, + 8, + 8, + kRGBA_8888_GrPixelConfig, + mipMapped, + backendHandle); + + GrTextureProxy* proxy; + sk_sp<SkImage> image; + if (isRT) { + sk_sp<SkSurface> surface = SkSurface::MakeFromBackendTexture( + context, + backendTex, + kTopLeft_GrSurfaceOrigin, + 0, + nullptr, + nullptr); + + SkGpuDevice* device = ((SkSurface_Gpu*)surface.get())->getDevice(); + proxy = device->accessRenderTargetContext()->asTextureProxy(); + } else { + image = SkImage::MakeFromTexture(context, backendTex, + kTopLeft_GrSurfaceOrigin, + kPremul_SkAlphaType, nullptr); + proxy = as_IB(image)->peekProxy(); + } + REPORTER_ASSERT(reporter, proxy); + if (!proxy) { + context->getGpu()->deleteTestingOnlyBackendTexture(backendHandle); + return; + } + + REPORTER_ASSERT(reporter, proxy->priv().isInstantiated()); + + GrTexture* texture = proxy->priv().peekTexture(); + REPORTER_ASSERT(reporter, texture); + if (!texture) { + context->getGpu()->deleteTestingOnlyBackendTexture(backendHandle); + return; + } + + if (GrMipMapped::kYes == mipMapped) { + REPORTER_ASSERT(reporter, texture->texturePriv().hasMipMaps()); + if (isRT) { + REPORTER_ASSERT(reporter, texture->texturePriv().mipMapsAreDirty()); + } else { + REPORTER_ASSERT(reporter, !texture->texturePriv().mipMapsAreDirty()); + } + } else { + REPORTER_ASSERT(reporter, !texture->texturePriv().hasMipMaps()); + } + context->getGpu()->deleteTestingOnlyBackendTexture(backendHandle); + } + } +} + +#endif diff --git a/tests/GrPorterDuffTest.cpp b/tests/GrPorterDuffTest.cpp index 073bdf0667..6ce0458a56 100644 --- a/tests/GrPorterDuffTest.cpp +++ b/tests/GrPorterDuffTest.cpp @@ -1072,6 +1072,7 @@ DEF_GPUTEST(PorterDuffNoDualSourceBlending, reporter, /*factory*/) { 100, 100, kRGBA_8888_GrPixelConfig, + GrMipMapped::kNo, backendTexHandle); GrXferProcessor::DstProxy fakeDstProxy; diff --git a/tests/GrSurfaceTest.cpp b/tests/GrSurfaceTest.cpp index 8f5aa55685..e5dc6ae824 100644 --- a/tests/GrSurfaceTest.cpp +++ b/tests/GrSurfaceTest.cpp @@ -54,6 +54,7 @@ DEF_GPUTEST_FOR_NULLGL_CONTEXT(GrSurface, reporter, ctxInfo) { 256, 256, kRGBA_8888_GrPixelConfig, + GrMipMapped::kNo, backendTexHandle); sk_sp<GrSurface> texRT2 = context->resourceProvider()->wrapRenderableBackendTexture( diff --git a/tests/ImageFilterCacheTest.cpp b/tests/ImageFilterCacheTest.cpp index 4e6df3b57e..449b252acf 100644 --- a/tests/ImageFilterCacheTest.cpp +++ b/tests/ImageFilterCacheTest.cpp @@ -219,6 +219,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImageFilterCache_ImageBackedGPU, reporter, ct kFullSize, kFullSize, kRGBA_8888_GrPixelConfig, + GrMipMapped::kNo, tex->getTextureHandle()); GrSurfaceOrigin texOrigin = kTopLeft_GrSurfaceOrigin; sk_sp<SkImage> srcImage(SkImage::MakeFromTexture(context, diff --git a/tests/ImageTest.cpp b/tests/ImageTest.cpp index 9e0137f3cf..a35d56caf3 100644 --- a/tests/ImageTest.cpp +++ b/tests/ImageTest.cpp @@ -776,6 +776,7 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SkImage_NewFromTextureRelease, reporter, c kWidth, kHeight, kRGBA_8888_GrPixelConfig, + GrMipMapped::kNo, backendTexHandle); TextureReleaseChecker releaseChecker; diff --git a/tests/ResourceAllocatorTest.cpp b/tests/ResourceAllocatorTest.cpp index 7af0d03a35..bb4acf013f 100644 --- a/tests/ResourceAllocatorTest.cpp +++ b/tests/ResourceAllocatorTest.cpp @@ -52,6 +52,7 @@ static sk_sp<GrSurfaceProxy> make_backend(GrContext* context, const ProxyParams& p.fSize, p.fSize, p.fConfig, + GrMipMapped::kNo, *backendTexHandle); sk_sp<GrSurface> tex = context->resourceProvider()->wrapBackendTexture(backendTex, diff --git a/tests/ResourceCacheTest.cpp b/tests/ResourceCacheTest.cpp index af33f2d9bc..0cb1d2b269 100644 --- a/tests/ResourceCacheTest.cpp +++ b/tests/ResourceCacheTest.cpp @@ -214,6 +214,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ResourceCacheWrappedResources, reporter, ctxI kW, kH, kRGBA_8888_GrPixelConfig, + GrMipMapped::kNo, texHandles[0]); sk_sp<GrTexture> borrowed(context->resourceProvider()->wrapBackendTexture( backendTex1, kBorrow_GrWrapOwnership)); @@ -222,6 +223,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ResourceCacheWrappedResources, reporter, ctxI kW, kH, kRGBA_8888_GrPixelConfig, + GrMipMapped::kNo, texHandles[1]); sk_sp<GrTexture> adopted(context->resourceProvider()->wrapBackendTexture( backendTex2, kAdopt_GrWrapOwnership)); diff --git a/tests/SurfaceSemaphoreTest.cpp b/tests/SurfaceSemaphoreTest.cpp index 09d3c35900..9b3f90429a 100644 --- a/tests/SurfaceSemaphoreTest.cpp +++ b/tests/SurfaceSemaphoreTest.cpp @@ -67,6 +67,7 @@ void draw_child(skiatest::Reporter* reporter, GrBackendTexture backendTexture = GrTest::CreateBackendTexture(childInfo.backend(), MAIN_W, MAIN_H, kRGBA_8888_GrPixelConfig, + GrMipMapped::kNo, backendImage); childInfo.testContext()->makeCurrent(); diff --git a/tests/SurfaceTest.cpp b/tests/SurfaceTest.cpp index 2fd987fdf6..bcd9e2dc7e 100644 --- a/tests/SurfaceTest.cpp +++ b/tests/SurfaceTest.cpp @@ -596,6 +596,7 @@ static sk_sp<SkSurface> create_gpu_surface_backend_texture( kWidth, kHeight, kRGBA_8888_GrPixelConfig, + GrMipMapped::kNo, backendHandle); sk_sp<SkSurface> surface = SkSurface::MakeFromBackendTexture(context, backendTex, @@ -623,6 +624,7 @@ static sk_sp<SkSurface> create_gpu_surface_backend_texture_as_render_target( kWidth, kHeight, kRGBA_8888_GrPixelConfig, + GrMipMapped::kNo, backendHandle); sk_sp<SkSurface> surface = SkSurface::MakeFromBackendTextureAsRenderTarget( context, backendTex, kTopLeft_GrSurfaceOrigin, sampleCnt, nullptr, nullptr); @@ -904,6 +906,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceCreationWithColorSpace_Gpu, reporter, kSize, kSize, config, + GrMipMapped::kNo, backendHandle); return SkSurface::MakeFromBackendTexture(context, backendTex, diff --git a/tests/TextureProxyTest.cpp b/tests/TextureProxyTest.cpp index d2277890c2..a4b93c8d7a 100644 --- a/tests/TextureProxyTest.cpp +++ b/tests/TextureProxyTest.cpp @@ -125,6 +125,7 @@ static sk_sp<GrTextureProxy> create_wrapped_backend(GrContext* context, SkBackin GrTest::CreateBackendTexture(context->contextPriv().getBackend(), 64, 64, kRGBA_8888_GrPixelConfig, + GrMipMapped::kNo, (*backingSurface)->getTextureHandle()); return GrSurfaceProxy::MakeWrappedBackend(context, backendTex, kBottomLeft_GrSurfaceOrigin); diff --git a/tests/VkWrapTests.cpp b/tests/VkWrapTests.cpp index 4f4c83362f..07b82a8a2d 100644 --- a/tests/VkWrapTests.cpp +++ b/tests/VkWrapTests.cpp @@ -33,7 +33,7 @@ void wrap_tex_test(skiatest::Reporter* reporter, GrContext* context) { GrVkGpu* gpu = static_cast<GrVkGpu*>(context->getGpu()); GrBackendObject backendObj = gpu->createTestingOnlyBackendTexture(nullptr, kW, kH, kPixelConfig, - false); + false, GrMipMapped::kNo); const GrVkImageInfo* imageInfo = reinterpret_cast<const GrVkImageInfo*>(backendObj); GrBackendTexture backendTex = GrBackendTexture(kW, kH, *imageInfo); @@ -71,7 +71,7 @@ void wrap_rt_test(skiatest::Reporter* reporter, GrContext* context) { GrVkGpu* gpu = static_cast<GrVkGpu*>(context->getGpu()); GrBackendObject backendObj = gpu->createTestingOnlyBackendTexture(nullptr, kW, kH, kPixelConfig, - true); + true, GrMipMapped::kNo); const GrVkImageInfo* backendTex = reinterpret_cast<const GrVkImageInfo*>(backendObj); GrBackendRenderTarget backendRT(kW, kH, 0, 0, *backendTex); @@ -103,7 +103,7 @@ void wrap_trt_test(skiatest::Reporter* reporter, GrContext* context) { GrVkGpu* gpu = static_cast<GrVkGpu*>(context->getGpu()); GrBackendObject backendObj = gpu->createTestingOnlyBackendTexture(nullptr, kW, kH, kPixelConfig, - true); + true, GrMipMapped::kNo); const GrVkImageInfo* imageInfo = reinterpret_cast<const GrVkImageInfo*>(backendObj); GrBackendTexture backendTex = GrBackendTexture(kW, kH, *imageInfo); diff --git a/tests/WritePixelsTest.cpp b/tests/WritePixelsTest.cpp index 7ea0aad12f..92390ae023 100644 --- a/tests/WritePixelsTest.cpp +++ b/tests/WritePixelsTest.cpp @@ -431,7 +431,8 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(WritePixelsNonTexture_Gpu, reporter, ctxInfo) auto handle = context->getGpu()->createTestingOnlyBackendTexture( nullptr, DEV_W, DEV_H, kSkia8888_GrPixelConfig, true); GrBackendTexture backendTexture = GrTest::CreateBackendTexture( - ctxInfo.backend(), DEV_W, DEV_H, kSkia8888_GrPixelConfig, handle); + ctxInfo.backend(), DEV_W, DEV_H, kSkia8888_GrPixelConfig, GrMipMapped::kNo, + handle); sk_sp<SkSurface> surface(SkSurface::MakeFromBackendTextureAsRenderTarget( context, backendTexture, origin, sampleCnt, nullptr, nullptr)); if (!surface) { diff --git a/tools/gpu/GrTest.cpp b/tools/gpu/GrTest.cpp index 3a74b6fe54..32e2cfa91d 100644 --- a/tools/gpu/GrTest.cpp +++ b/tools/gpu/GrTest.cpp @@ -55,21 +55,23 @@ void SetupAlwaysEvictAtlas(GrContext* context) { } GrBackendTexture CreateBackendTexture(GrBackend backend, int width, int height, - GrPixelConfig config, GrBackendObject handle) { + GrPixelConfig config, GrMipMapped mipMapped, + GrBackendObject handle) { switch (backend) { #ifdef SK_VULKAN case kVulkan_GrBackend: { GrVkImageInfo* vkInfo = (GrVkImageInfo*)(handle); + SkASSERT((GrMipMapped::kYes == mipMapped) == (vkInfo->fLevelCount > 1)); return GrBackendTexture(width, height, *vkInfo); } #endif case kOpenGL_GrBackend: { GrGLTextureInfo* glInfo = (GrGLTextureInfo*)(handle); - return GrBackendTexture(width, height, config, *glInfo); + return GrBackendTexture(width, height, config, mipMapped, *glInfo); } case kMock_GrBackend: { GrMockTextureInfo* mockInfo = (GrMockTextureInfo*)(handle); - return GrBackendTexture(width, height, config, *mockInfo); + return GrBackendTexture(width, height, config, mipMapped, *mockInfo); } default: return GrBackendTexture(); diff --git a/tools/gpu/GrTest.h b/tools/gpu/GrTest.h index d4a4c6dfac..612245f07b 100644 --- a/tools/gpu/GrTest.h +++ b/tools/gpu/GrTest.h @@ -19,7 +19,7 @@ namespace GrTest { void SetupAlwaysEvictAtlas(GrContext*); GrBackendTexture CreateBackendTexture(GrBackend, int width, int height, - GrPixelConfig, GrBackendObject); + GrPixelConfig, GrMipMapped, GrBackendObject); }; #endif |