Hal Canary | b6c5e5b | 2017-10-09 16:13:02 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #include "Test.h" |
| 9 | |
| 10 | using sk_gpu_test::GrContextFactory; |
| 11 | using sk_gpu_test::GLTestContext; |
| 12 | using sk_gpu_test::ContextInfo; |
| 13 | |
Hal Canary | b6c5e5b | 2017-10-09 16:13:02 -0400 | [diff] [blame] | 14 | namespace skiatest { |
| 15 | |
Hal Canary | b6c5e5b | 2017-10-09 16:13:02 -0400 | [diff] [blame] | 16 | bool IsGLContextType(sk_gpu_test::GrContextFactory::ContextType type) { |
Greg Daniel | bdf12ad | 2018-10-12 09:31:11 -0400 | [diff] [blame] | 17 | return GrBackendApi::kOpenGL == GrContextFactory::ContextTypeBackend(type); |
Hal Canary | b6c5e5b | 2017-10-09 16:13:02 -0400 | [diff] [blame] | 18 | } |
| 19 | bool IsVulkanContextType(sk_gpu_test::GrContextFactory::ContextType type) { |
Greg Daniel | bdf12ad | 2018-10-12 09:31:11 -0400 | [diff] [blame] | 20 | return GrBackendApi::kVulkan == GrContextFactory::ContextTypeBackend(type); |
Hal Canary | b6c5e5b | 2017-10-09 16:13:02 -0400 | [diff] [blame] | 21 | } |
Timothy Liang | 760dbc4 | 2018-07-17 13:28:20 -0400 | [diff] [blame] | 22 | bool IsMetalContextType(sk_gpu_test::GrContextFactory::ContextType type) { |
Greg Daniel | bdf12ad | 2018-10-12 09:31:11 -0400 | [diff] [blame] | 23 | return GrBackendApi::kMetal == GrContextFactory::ContextTypeBackend(type); |
Timothy Liang | 760dbc4 | 2018-07-17 13:28:20 -0400 | [diff] [blame] | 24 | } |
Hal Canary | b6c5e5b | 2017-10-09 16:13:02 -0400 | [diff] [blame] | 25 | bool IsRenderingGLContextType(sk_gpu_test::GrContextFactory::ContextType type) { |
| 26 | return IsGLContextType(type) && GrContextFactory::IsRenderingContext(type); |
| 27 | } |
| 28 | bool IsNullGLContextType(sk_gpu_test::GrContextFactory::ContextType type) { |
| 29 | return type == GrContextFactory::kNullGL_ContextType; |
| 30 | } |
Hal Canary | b6c5e5b | 2017-10-09 16:13:02 -0400 | [diff] [blame] | 31 | |
| 32 | void RunWithGPUTestContexts(GrContextTestFn* test, GrContextTypeFilterFn* contextTypeFilter, |
Brian Salomon | dcfca43 | 2017-11-15 15:48:03 -0500 | [diff] [blame] | 33 | Reporter* reporter, const GrContextOptions& options) { |
Hal Canary | b6c5e5b | 2017-10-09 16:13:02 -0400 | [diff] [blame] | 34 | #if defined(SK_BUILD_FOR_UNIX) || defined(SK_BUILD_FOR_WIN) || defined(SK_BUILD_FOR_MAC) |
| 35 | static constexpr auto kNativeGLType = GrContextFactory::kGL_ContextType; |
| 36 | #else |
| 37 | static constexpr auto kNativeGLType = GrContextFactory::kGLES_ContextType; |
| 38 | #endif |
| 39 | |
| 40 | for (int typeInt = 0; typeInt < GrContextFactory::kContextTypeCnt; ++typeInt) { |
| 41 | GrContextFactory::ContextType contextType = (GrContextFactory::ContextType) typeInt; |
| 42 | // Use "native" instead of explicitly trying OpenGL and OpenGL ES. Do not use GLES on |
| 43 | // desktop since tests do not account for not fixing http://skbug.com/2809 |
| 44 | if (contextType == GrContextFactory::kGL_ContextType || |
| 45 | contextType == GrContextFactory::kGLES_ContextType) { |
| 46 | if (contextType != kNativeGLType) { |
| 47 | continue; |
| 48 | } |
| 49 | } |
Brian Salomon | dcfca43 | 2017-11-15 15:48:03 -0500 | [diff] [blame] | 50 | // We destroy the factory and its associated contexts after each test. This is due to the |
| 51 | // fact that the command buffer sits on top of the native GL windowing (cgl, wgl, ...) but |
| 52 | // also tracks which of its contexts is current above that API and gets tripped up if the |
| 53 | // native windowing API is used directly outside of the command buffer code. |
| 54 | GrContextFactory factory(options); |
| 55 | ContextInfo ctxInfo = factory.getContextInfo( |
| 56 | contextType, GrContextFactory::ContextOverrides::kDisableNVPR); |
Hal Canary | b6c5e5b | 2017-10-09 16:13:02 -0400 | [diff] [blame] | 57 | if (contextTypeFilter && !(*contextTypeFilter)(contextType)) { |
| 58 | continue; |
| 59 | } |
| 60 | |
| 61 | ReporterContext ctx(reporter, SkString(GrContextFactory::ContextTypeName(contextType))); |
| 62 | if (ctxInfo.grContext()) { |
| 63 | (*test)(reporter, ctxInfo); |
| 64 | ctxInfo.grContext()->flush(); |
| 65 | } |
Brian Salomon | dcfca43 | 2017-11-15 15:48:03 -0500 | [diff] [blame] | 66 | ctxInfo = factory.getContextInfo(contextType, |
| 67 | GrContextFactory::ContextOverrides::kRequireNVPRSupport); |
Hal Canary | b6c5e5b | 2017-10-09 16:13:02 -0400 | [diff] [blame] | 68 | if (ctxInfo.grContext()) { |
| 69 | (*test)(reporter, ctxInfo); |
| 70 | ctxInfo.grContext()->flush(); |
| 71 | } |
| 72 | } |
Hal Canary | b6c5e5b | 2017-10-09 16:13:02 -0400 | [diff] [blame] | 73 | } |
| 74 | } // namespace skiatest |