blob: c3ec588b817b8c114b7ff0f9c6552ca3907a7996 [file] [log] [blame]
Hal Canaryb6c5e5b2017-10-09 16:13:02 -04001/*
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
10using sk_gpu_test::GrContextFactory;
11using sk_gpu_test::GLTestContext;
12using sk_gpu_test::ContextInfo;
13
14// TODO: currently many GPU tests are declared outside SK_SUPPORT_GPU guards.
15// Thus we export the empty RunWithGPUTestContexts when SK_SUPPORT_GPU=0.
16namespace skiatest {
17
18#if SK_SUPPORT_GPU
19bool IsGLContextType(sk_gpu_test::GrContextFactory::ContextType type) {
20 return kOpenGL_GrBackend == GrContextFactory::ContextTypeBackend(type);
21}
22bool IsVulkanContextType(sk_gpu_test::GrContextFactory::ContextType type) {
23 return kVulkan_GrBackend == GrContextFactory::ContextTypeBackend(type);
24}
25bool IsRenderingGLContextType(sk_gpu_test::GrContextFactory::ContextType type) {
26 return IsGLContextType(type) && GrContextFactory::IsRenderingContext(type);
27}
28bool IsNullGLContextType(sk_gpu_test::GrContextFactory::ContextType type) {
29 return type == GrContextFactory::kNullGL_ContextType;
30}
31#else
32bool IsGLContextType(int) { return false; }
33bool IsVulkanContextType(int) { return false; }
34bool IsRenderingGLContextType(int) { return false; }
35bool IsNullGLContextType(int) { return false; }
36#endif
37
38void RunWithGPUTestContexts(GrContextTestFn* test, GrContextTypeFilterFn* contextTypeFilter,
39 Reporter* reporter, GrContextFactory* factory) {
40#if SK_SUPPORT_GPU
41
42#if defined(SK_BUILD_FOR_UNIX) || defined(SK_BUILD_FOR_WIN) || defined(SK_BUILD_FOR_MAC)
43 static constexpr auto kNativeGLType = GrContextFactory::kGL_ContextType;
44#else
45 static constexpr auto kNativeGLType = GrContextFactory::kGLES_ContextType;
46#endif
47
48 for (int typeInt = 0; typeInt < GrContextFactory::kContextTypeCnt; ++typeInt) {
49 GrContextFactory::ContextType contextType = (GrContextFactory::ContextType) typeInt;
50 // Use "native" instead of explicitly trying OpenGL and OpenGL ES. Do not use GLES on
51 // desktop since tests do not account for not fixing http://skbug.com/2809
52 if (contextType == GrContextFactory::kGL_ContextType ||
53 contextType == GrContextFactory::kGLES_ContextType) {
54 if (contextType != kNativeGLType) {
55 continue;
56 }
57 }
58 ContextInfo ctxInfo = factory->getContextInfo(contextType,
59 GrContextFactory::ContextOverrides::kDisableNVPR);
60 if (contextTypeFilter && !(*contextTypeFilter)(contextType)) {
61 continue;
62 }
63
64 ReporterContext ctx(reporter, SkString(GrContextFactory::ContextTypeName(contextType)));
65 if (ctxInfo.grContext()) {
66 (*test)(reporter, ctxInfo);
67 ctxInfo.grContext()->flush();
68 }
69 ctxInfo = factory->getContextInfo(contextType,
70 GrContextFactory::ContextOverrides::kRequireNVPRSupport);
71 if (ctxInfo.grContext()) {
72 (*test)(reporter, ctxInfo);
73 ctxInfo.grContext()->flush();
74 }
75 }
76#endif
77}
78} // namespace skiatest