diff options
author | Greg Daniel <egdaniel@google.com> | 2017-10-23 09:37:36 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-10-23 15:32:15 +0000 |
commit | 261b8aa1de8562f79c1a7c515d968787e027a2c8 (patch) | |
tree | 738bada2d198062d8ed72d5fdbe6f5b9f1b3b7f4 /tests | |
parent | 1cb41717bc4a44272eab48bd47ca7579425dc22e (diff) |
Revert "Revert "Support creation/use of mipped proxy in GrBackendTextureImageGenerator""
This reverts commit 7477d9693869982a4b0b18d20fee32d2f3eaedbf.
Reason for revert: Putting in fixes in tests
Original change's description:
> Revert "Support creation/use of mipped proxy in GrBackendTextureImageGenerator"
>
> This reverts commit b8ad00b5a68975cafd68d6df0d66f0a01f5c07c2.
>
> Reason for revert: Some various test failures
>
> Original change's description:
> > Support creation/use of mipped proxy in GrBackendTextureImageGenerator
> >
> > Bug: skia:
> > Change-Id: I9d06780ccb2db0865100b67041c03408f2445c62
> > Reviewed-on: https://skia-review.googlesource.com/61241
> > Reviewed-by: Brian Salomon <bsalomon@google.com>
> > Commit-Queue: Greg Daniel <egdaniel@google.com>
>
> TBR=egdaniel@google.com,bsalomon@google.com,brianosman@google.com
>
> Change-Id: I28e625776352ee6f9f27e66cd5d4b149ef50a22a
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Bug: skia:
> Reviewed-on: https://skia-review.googlesource.com/61941
> Reviewed-by: Greg Daniel <egdaniel@google.com>
> Commit-Queue: Greg Daniel <egdaniel@google.com>
TBR=egdaniel@google.com,bsalomon@google.com,brianosman@google.com
# Not skipping CQ checks because original CL landed > 1 day ago.
Bug: skia:
Change-Id: Ibfbca5101b06d9ff8f8a5d33bc6f2114806db552
Reviewed-on: https://skia-review.googlesource.com/62561
Commit-Queue: Greg Daniel <egdaniel@google.com>
Reviewed-by: Greg Daniel <egdaniel@google.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/EGLImageTest.cpp | 6 | ||||
-rw-r--r-- | tests/GrMipMappedTest.cpp | 125 |
2 files changed, 131 insertions, 0 deletions
diff --git a/tests/EGLImageTest.cpp b/tests/EGLImageTest.cpp index 784ec5d99e..82e4c4bb55 100644 --- a/tests/EGLImageTest.cpp +++ b/tests/EGLImageTest.cpp @@ -107,6 +107,12 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(EGLImageTest, reporter, ctxInfo) { return; } + // Since we are dealing with two different GL contexts here, we need to call finish so that the + // clearing of the texture that happens in createTextingOnlyBackendTexture occurs before we call + // TexSubImage below on the other context. Otherwise, it is possible the calls get reordered and + // the clearing overwrites the TexSubImage writes. + GR_GL_CALL(glCtx1->gl(), Finish()); + // Populate the texture using GL context 1. Important to use TexSubImage as TexImage orphans // the EGL image. Also, this must be done after creating the EGLImage as the texture // contents may not be preserved when the image is created. diff --git a/tests/GrMipMappedTest.cpp b/tests/GrMipMappedTest.cpp index 166713a2bd..143e902a7e 100644 --- a/tests/GrMipMappedTest.cpp +++ b/tests/GrMipMappedTest.cpp @@ -10,10 +10,12 @@ #if SK_SUPPORT_GPU #include "GrBackendSurface.h" +#include "GrBackendTextureImageGenerator.h" #include "GrContext.h" #include "GrContextPriv.h" #include "GrGpu.h" #include "GrRenderTargetContext.h" +#include "GrSemaphore.h" #include "GrSurfaceProxyPriv.h" #include "GrTest.h" #include "GrTexturePriv.h" @@ -21,6 +23,7 @@ #include "SkCanvas.h" #include "SkImage_Base.h" #include "SkGpuDevice.h" +#include "SkPoint.h" #include "SkSurface.h" #include "SkSurface_Gpu.h" #include "Test.h" @@ -29,6 +32,9 @@ // SkImages and SkSurfaces DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrWrappedMipMappedTest, reporter, ctxInfo) { GrContext* context = ctxInfo.grContext(); + if (!context->caps()->mipMapSupport()) { + return; + } for (auto mipMapped : {GrMipMapped::kNo, GrMipMapped::kYes}) { for (auto isRT : {false, true}) { // CreateTestingOnlyBackendTexture currently doesn't support uploading data to mip maps @@ -94,4 +100,123 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrWrappedMipMappedTest, reporter, ctxInfo) { } } +// Test that we correctly copy or don't copy GrBackendTextures in the GrBackendTextureImageGenerator +// based on if we will use mips in the draw and the mip status of the GrBackendTexture. +DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrBackendTextureImageMipMappedTest, reporter, ctxInfo) { + static const int kSize = 8; + + GrContext* context = ctxInfo.grContext(); + if (!context->caps()->mipMapSupport()) { + return; + } + for (auto mipMapped : {GrMipMapped::kNo, GrMipMapped::kYes}) { + for (auto willUseMips : {false, true}) { + GrBackendObject backendHandle = context->getGpu()->createTestingOnlyBackendTexture( + nullptr, kSize, kSize, kRGBA_8888_GrPixelConfig, false, mipMapped); + + GrBackend backend = context->contextPriv().getBackend(); + GrBackendTexture backendTex = GrTest::CreateBackendTexture(backend, + kSize, + kSize, + kRGBA_8888_GrPixelConfig, + mipMapped, + backendHandle); + + sk_sp<SkImage> image = SkImage::MakeFromTexture(context, backendTex, + kTopLeft_GrSurfaceOrigin, + kPremul_SkAlphaType, nullptr); + + GrTextureProxy* proxy = as_IB(image)->peekProxy(); + REPORTER_ASSERT(reporter, proxy); + if (!proxy) { + context->getGpu()->deleteTestingOnlyBackendTexture(backendHandle); + return; + } + + REPORTER_ASSERT(reporter, proxy->priv().isInstantiated()); + + sk_sp<GrTexture> texture = sk_ref_sp(proxy->priv().peekTexture()); + REPORTER_ASSERT(reporter, texture); + if (!texture) { + context->getGpu()->deleteTestingOnlyBackendTexture(backendHandle); + return; + } + + std::unique_ptr<SkImageGenerator> imageGen = GrBackendTextureImageGenerator::Make( + texture, kTopLeft_GrSurfaceOrigin, nullptr, kPremul_SkAlphaType, nullptr); + REPORTER_ASSERT(reporter, imageGen); + if (!imageGen) { + context->getGpu()->deleteTestingOnlyBackendTexture(backendHandle); + return; + } + + SkIPoint origin = SkIPoint::Make(0,0); + // The transfer function behavior isn't used in the generator so set we set it + // arbitrarily here. + SkTransferFunctionBehavior behavior = SkTransferFunctionBehavior::kIgnore; + SkImageInfo imageInfo = SkImageInfo::Make(kSize, kSize, kRGBA_8888_SkColorType, + kPremul_SkAlphaType); + sk_sp<GrTextureProxy> genProxy = imageGen->generateTexture(context, imageInfo, + origin, behavior, + willUseMips); + + REPORTER_ASSERT(reporter, genProxy); + if (!genProxy) { + context->getGpu()->deleteTestingOnlyBackendTexture(backendHandle); + return; + } + + REPORTER_ASSERT(reporter, genProxy->priv().isInstantiated()); + + GrTexture* genTexture = genProxy->priv().peekTexture(); + REPORTER_ASSERT(reporter, genTexture); + if (!genTexture) { + context->getGpu()->deleteTestingOnlyBackendTexture(backendHandle); + return; + } + + GrBackendObject genBackendObject = genTexture->getTextureHandle(); + + if (kOpenGL_GrBackend == backend) { + const GrGLTextureInfo* origTexInfo = backendTex.getGLTextureInfo(); + GrGLTextureInfo* genTexInfo = (GrGLTextureInfo*)genBackendObject; + if (willUseMips && GrMipMapped::kNo == mipMapped) { + // We did a copy so the texture IDs should be different + REPORTER_ASSERT(reporter, origTexInfo->fID != genTexInfo->fID); + } else { + REPORTER_ASSERT(reporter, origTexInfo->fID == genTexInfo->fID); + } + } else if (kVulkan_GrBackend == backend) { +#ifdef SK_VULKAN + const GrVkImageInfo* origImageInfo = backendTex.getVkImageInfo(); + GrVkImageInfo* genImageInfo = (GrVkImageInfo*)genBackendObject; + if (willUseMips && GrMipMapped::kNo == mipMapped) { + // We did a copy so the texture IDs should be different + REPORTER_ASSERT(reporter, origImageInfo->fImage != genImageInfo->fImage); + } else { + REPORTER_ASSERT(reporter, origImageInfo->fImage == genImageInfo->fImage); + } +#endif + } else if (kMetal_GrBackend == backend) { + REPORTER_ASSERT(reporter, false); + } else { + REPORTER_ASSERT(reporter, false); + } + + // Must make sure the uses of the backend texture have finished (we possibly have a + // queued up copy) before we delete the backend texture. Thus we use readPixels here + // just to force the synchronization. + sk_sp<GrSurfaceContext> surfContext = + context->contextPriv().makeWrappedSurfaceContext(genProxy, nullptr); + + SkBitmap bitmap; + bitmap.allocPixels(imageInfo); + surfContext->readPixels(imageInfo, bitmap.getPixels(), 0, 0, 0, 0); + + context->getGpu()->deleteTestingOnlyBackendTexture(backendHandle); + } + } +} + + #endif |