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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "tests/Test.h" |
Hal Canary | b6c5e5b | 2017-10-09 16:13:02 -0400 | [diff] [blame] | 9 | |
Robert Phillips | b87b39b | 2020-07-01 14:45:24 -0400 | [diff] [blame] | 10 | #include "include/gpu/GrDirectContext.h" |
| 11 | |
Hal Canary | b6c5e5b | 2017-10-09 16:13:02 -0400 | [diff] [blame] | 12 | using sk_gpu_test::GrContextFactory; |
| 13 | using sk_gpu_test::GLTestContext; |
| 14 | using sk_gpu_test::ContextInfo; |
| 15 | |
Hal Canary | b6c5e5b | 2017-10-09 16:13:02 -0400 | [diff] [blame] | 16 | namespace skiatest { |
| 17 | |
Hal Canary | b6c5e5b | 2017-10-09 16:13:02 -0400 | [diff] [blame] | 18 | bool IsGLContextType(sk_gpu_test::GrContextFactory::ContextType type) { |
Greg Daniel | bdf12ad | 2018-10-12 09:31:11 -0400 | [diff] [blame] | 19 | return GrBackendApi::kOpenGL == GrContextFactory::ContextTypeBackend(type); |
Hal Canary | b6c5e5b | 2017-10-09 16:13:02 -0400 | [diff] [blame] | 20 | } |
| 21 | bool IsVulkanContextType(sk_gpu_test::GrContextFactory::ContextType type) { |
Greg Daniel | bdf12ad | 2018-10-12 09:31:11 -0400 | [diff] [blame] | 22 | return GrBackendApi::kVulkan == GrContextFactory::ContextTypeBackend(type); |
Hal Canary | b6c5e5b | 2017-10-09 16:13:02 -0400 | [diff] [blame] | 23 | } |
Timothy Liang | 760dbc4 | 2018-07-17 13:28:20 -0400 | [diff] [blame] | 24 | bool IsMetalContextType(sk_gpu_test::GrContextFactory::ContextType type) { |
Greg Daniel | bdf12ad | 2018-10-12 09:31:11 -0400 | [diff] [blame] | 25 | return GrBackendApi::kMetal == GrContextFactory::ContextTypeBackend(type); |
Timothy Liang | 760dbc4 | 2018-07-17 13:28:20 -0400 | [diff] [blame] | 26 | } |
Greg Daniel | d4928d0 | 2020-06-19 11:13:26 -0400 | [diff] [blame] | 27 | bool IsDirect3DContextType(sk_gpu_test::GrContextFactory::ContextType type) { |
| 28 | return GrBackendApi::kDirect3D == GrContextFactory::ContextTypeBackend(type); |
| 29 | } |
Hal Canary | b6c5e5b | 2017-10-09 16:13:02 -0400 | [diff] [blame] | 30 | bool IsRenderingGLContextType(sk_gpu_test::GrContextFactory::ContextType type) { |
| 31 | return IsGLContextType(type) && GrContextFactory::IsRenderingContext(type); |
| 32 | } |
Jim Van Verth | 5a8f3e4 | 2019-10-24 10:23:26 -0400 | [diff] [blame] | 33 | bool IsRenderingGLOrMetalContextType(sk_gpu_test::GrContextFactory::ContextType type) { |
| 34 | return (IsGLContextType(type) || IsMetalContextType(type)) && |
| 35 | GrContextFactory::IsRenderingContext(type); |
| 36 | } |
Brian Osman | 7c59774 | 2019-03-26 11:10:11 -0400 | [diff] [blame] | 37 | bool IsMockContextType(sk_gpu_test::GrContextFactory::ContextType type) { |
| 38 | return type == GrContextFactory::kMock_ContextType; |
| 39 | } |
Hal Canary | b6c5e5b | 2017-10-09 16:13:02 -0400 | [diff] [blame] | 40 | |
| 41 | void RunWithGPUTestContexts(GrContextTestFn* test, GrContextTypeFilterFn* contextTypeFilter, |
Brian Salomon | dcfca43 | 2017-11-15 15:48:03 -0500 | [diff] [blame] | 42 | Reporter* reporter, const GrContextOptions& options) { |
Hal Canary | b6c5e5b | 2017-10-09 16:13:02 -0400 | [diff] [blame] | 43 | #if defined(SK_BUILD_FOR_UNIX) || defined(SK_BUILD_FOR_WIN) || defined(SK_BUILD_FOR_MAC) |
| 44 | static constexpr auto kNativeGLType = GrContextFactory::kGL_ContextType; |
| 45 | #else |
| 46 | static constexpr auto kNativeGLType = GrContextFactory::kGLES_ContextType; |
| 47 | #endif |
| 48 | |
| 49 | for (int typeInt = 0; typeInt < GrContextFactory::kContextTypeCnt; ++typeInt) { |
| 50 | GrContextFactory::ContextType contextType = (GrContextFactory::ContextType) typeInt; |
| 51 | // Use "native" instead of explicitly trying OpenGL and OpenGL ES. Do not use GLES on |
| 52 | // desktop since tests do not account for not fixing http://skbug.com/2809 |
| 53 | if (contextType == GrContextFactory::kGL_ContextType || |
| 54 | contextType == GrContextFactory::kGLES_ContextType) { |
| 55 | if (contextType != kNativeGLType) { |
| 56 | continue; |
| 57 | } |
| 58 | } |
Brian Salomon | dcfca43 | 2017-11-15 15:48:03 -0500 | [diff] [blame] | 59 | // We destroy the factory and its associated contexts after each test. This is due to the |
| 60 | // fact that the command buffer sits on top of the native GL windowing (cgl, wgl, ...) but |
| 61 | // also tracks which of its contexts is current above that API and gets tripped up if the |
| 62 | // native windowing API is used directly outside of the command buffer code. |
| 63 | GrContextFactory factory(options); |
Chris Dalton | b3c9745 | 2019-06-25 20:07:56 -0600 | [diff] [blame] | 64 | ContextInfo ctxInfo = factory.getContextInfo(contextType); |
Hal Canary | b6c5e5b | 2017-10-09 16:13:02 -0400 | [diff] [blame] | 65 | if (contextTypeFilter && !(*contextTypeFilter)(contextType)) { |
| 66 | continue; |
| 67 | } |
| 68 | |
| 69 | ReporterContext ctx(reporter, SkString(GrContextFactory::ContextTypeName(contextType))); |
Robert Phillips | b87b39b | 2020-07-01 14:45:24 -0400 | [diff] [blame] | 70 | if (ctxInfo.directContext()) { |
Hal Canary | b6c5e5b | 2017-10-09 16:13:02 -0400 | [diff] [blame] | 71 | (*test)(reporter, ctxInfo); |
Greg Daniel | 58b5a54 | 2020-04-09 14:55:00 -0400 | [diff] [blame] | 72 | // In case the test changed the current context make sure we move it back before |
| 73 | // calling flush. |
| 74 | ctxInfo.testContext()->makeCurrent(); |
Robert Phillips | b87b39b | 2020-07-01 14:45:24 -0400 | [diff] [blame] | 75 | ctxInfo.directContext()->flushAndSubmit(); |
Hal Canary | b6c5e5b | 2017-10-09 16:13:02 -0400 | [diff] [blame] | 76 | } |
Hal Canary | b6c5e5b | 2017-10-09 16:13:02 -0400 | [diff] [blame] | 77 | } |
Hal Canary | b6c5e5b | 2017-10-09 16:13:02 -0400 | [diff] [blame] | 78 | } |
| 79 | } // namespace skiatest |