diff options
author | Brian Salomon <bsalomon@google.com> | 2018-02-01 18:02:35 -0500 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2018-02-02 00:16:28 +0000 |
commit | 85ae7159c9c8a9186a4c7e74304eabb35bca9a79 (patch) | |
tree | 8f1cf3aa71803889d1f2b1b84b43013395f188ac /tests/SurfaceTest.cpp | |
parent | e45d32abe13239e3482fc4a13f006ab72073252a (diff) |
Add new GrContext queries for imagability, surfacability, and max sample count of color types
Bug: skia:7538
Change-Id: I235fc1aa947ba57faa7aef5e7e7ce9241b315fff
Reviewed-on: https://skia-review.googlesource.com/99704
Commit-Queue: Brian Salomon <bsalomon@google.com>
Reviewed-by: Greg Daniel <egdaniel@google.com>
Diffstat (limited to 'tests/SurfaceTest.cpp')
-rw-r--r-- | tests/SurfaceTest.cpp | 127 |
1 files changed, 121 insertions, 6 deletions
diff --git a/tests/SurfaceTest.cpp b/tests/SurfaceTest.cpp index 7acd3ebbe2..de1cd9a984 100644 --- a/tests/SurfaceTest.cpp +++ b/tests/SurfaceTest.cpp @@ -19,13 +19,17 @@ #include "Test.h" #if SK_SUPPORT_GPU +#include <vector> #include "GrContext.h" #include "GrContextPriv.h" -#include "GrRenderTargetContext.h" #include "GrGpu.h" +#include "GrGpuResourcePriv.h" +#include "GrRenderTargetContext.h" #include "GrResourceProvider.h" #include "GrTest.h" -#include <vector> +#include "SkGpuDevice.h" +#include "SkImage_Gpu.h" +#include "SkSurface_Gpu.h" #endif #include <initializer_list> @@ -88,6 +92,121 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceEmpty_Gpu, reporter, ctxInfo) { } #endif +#if SK_SUPPORT_GPU +DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrContext_colorTypeSupportedAsSurface, reporter, ctxInfo) { + for (int ct = 0; ct < kLastEnum_SkColorType; ++ct) { + static constexpr int kSize = 10; + + SkColorType colorType = static_cast<SkColorType>(ct); + auto info = SkImageInfo::Make(kSize, kSize, colorType, kOpaque_SkAlphaType, nullptr); + bool can = ctxInfo.grContext()->colorTypeSupportedAsSurface(colorType); + auto surf = SkSurface::MakeRenderTarget(ctxInfo.grContext(), SkBudgeted::kYes, info, 1, + nullptr); + REPORTER_ASSERT(reporter, can == SkToBool(surf), "ct: %d, can: %d, surf: %d", + colorType, can, SkToBool(surf)); + + auto* gpu = ctxInfo.grContext()->contextPriv().getGpu(); + GrBackendTexture backendTex = gpu->createTestingOnlyBackendTexture( + nullptr, kSize, kSize, colorType, true, GrMipMapped::kNo); + surf = SkSurface::MakeFromBackendTexture(ctxInfo.grContext(), backendTex, + kTopLeft_GrSurfaceOrigin, 0, colorType, nullptr, + nullptr); + REPORTER_ASSERT(reporter, can == SkToBool(surf), "ct: %d, can: %d, surf: %d", + colorType, can, SkToBool(surf)); + + surf = SkSurface::MakeFromBackendTextureAsRenderTarget(ctxInfo.grContext(), backendTex, + kTopLeft_GrSurfaceOrigin, 1, + colorType, nullptr, nullptr); + REPORTER_ASSERT(reporter, can == SkToBool(surf), "ct: %d, can: %d, surf: %d", + colorType, can, SkToBool(surf)); + + surf.reset(); + ctxInfo.grContext()->flush(); + if (backendTex.isValid()) { + gpu->deleteTestingOnlyBackendTexture(&backendTex); + } + + static constexpr int kSampleCnt = 2; + + can = ctxInfo.grContext()->maxSurfaceSampleCountForColorType(colorType) >= kSampleCnt; + surf = SkSurface::MakeRenderTarget(ctxInfo.grContext(), SkBudgeted::kYes, info, kSampleCnt, + nullptr); + REPORTER_ASSERT(reporter, can == SkToBool(surf), "ct: %d, can: %d, surf: %d", + colorType, can, SkToBool(surf)); + + backendTex = gpu->createTestingOnlyBackendTexture(nullptr, kSize, kSize, colorType, true, + GrMipMapped::kNo); + surf = SkSurface::MakeFromBackendTexture(ctxInfo.grContext(), backendTex, + kTopLeft_GrSurfaceOrigin, kSampleCnt, colorType, + nullptr, nullptr); + REPORTER_ASSERT(reporter, can == SkToBool(surf), + "colorTypeSupportedAsSurface:%d, surf:%d, ct:%d", can, SkToBool(surf), + colorType); + // Ensure that the sample count stored on the resulting SkSurface is a valid value. + if (surf) { + auto* rtc = ((SkSurface_Gpu*)(surf.get()))->getDevice()->accessRenderTargetContext(); + int storedCnt = rtc->numStencilSamples(); + int allowedCnt = ctxInfo.grContext()->caps()->getSampleCount( + storedCnt, rtc->asSurfaceProxy()->config()); + REPORTER_ASSERT(reporter, storedCnt == allowedCnt, + "Should store an allowed sample count (%d vs %d)", allowedCnt, + storedCnt); + } + + surf = SkSurface::MakeFromBackendTextureAsRenderTarget(ctxInfo.grContext(), backendTex, + kTopLeft_GrSurfaceOrigin, kSampleCnt, + colorType, nullptr, nullptr); + REPORTER_ASSERT(reporter, can == SkToBool(surf), + "colorTypeSupportedAsSurface:%d, surf:%d, ct:%d", can, SkToBool(surf), + colorType); + if (surf) { + auto* rtc = ((SkSurface_Gpu*)(surf.get()))->getDevice()->accessRenderTargetContext(); + int storedCnt = rtc->numStencilSamples(); + int allowedCnt = ctxInfo.grContext()->caps()->getSampleCount( + storedCnt, rtc->asSurfaceProxy()->config()); + REPORTER_ASSERT(reporter, storedCnt == allowedCnt, + "Should store an allowed sample count (%d vs %d)", allowedCnt, + storedCnt); + } + + surf.reset(); + ctxInfo.grContext()->flush(); + if (backendTex.isValid()) { + gpu->deleteTestingOnlyBackendTexture(&backendTex); + } + } +} + +DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrContext_maxSurfaceSamplesForColorType, reporter, ctxInfo) { + for (int ct = 0; ct < kLastEnum_SkColorType; ++ct) { + static constexpr int kSize = 10; + + SkColorType colorType = static_cast<SkColorType>(ct); + int max = ctxInfo.grContext()->maxSurfaceSampleCountForColorType(colorType); + if (!max) { + continue; + } + auto* gpu = ctxInfo.grContext()->contextPriv().getGpu(); + GrBackendTexture backendTex = gpu->createTestingOnlyBackendTexture( + nullptr, kSize, kSize, colorType, true, GrMipMapped::kNo); + + auto info = SkImageInfo::Make(kSize, kSize, colorType, kOpaque_SkAlphaType, nullptr); + auto surf = SkSurface::MakeFromBackendTexture(ctxInfo.grContext(), backendTex, + kTopLeft_GrSurfaceOrigin, max, + colorType, nullptr, nullptr); + REPORTER_ASSERT(reporter, surf); + if (!surf) { + continue; + } + int sampleCnt = ((SkSurface_Gpu*)(surf.get())) + ->getDevice() + ->accessRenderTargetContext() + ->numStencilSamples(); + REPORTER_ASSERT(reporter, sampleCnt == max, "Exected: %d, actual: %d", max, sampleCnt); + } +} +#endif + static void test_canvas_peek(skiatest::Reporter* reporter, sk_sp<SkSurface>& surface, const SkImageInfo& requestInfo, @@ -437,10 +556,6 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfacepeekTexture_Gpu, reporter, ctxInfo) { #endif #if SK_SUPPORT_GPU -#include "GrGpuResourcePriv.h" -#include "SkGpuDevice.h" -#include "SkImage_Gpu.h" -#include "SkSurface_Gpu.h" static SkBudgeted is_budgeted(const sk_sp<SkSurface>& surf) { SkSurface_Gpu* gsurf = (SkSurface_Gpu*)surf.get(); |