blob: ef55c0ab55718746908e0ca99c1112fb9dc867e6 [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,
Brian Salomondcfca432017-11-15 15:48:03 -050039 Reporter* reporter, const GrContextOptions& options) {
Hal Canaryb6c5e5b2017-10-09 16:13:02 -040040#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 }
Brian Salomondcfca432017-11-15 15:48:03 -050058 // We destroy the factory and its associated contexts after each test. This is due to the
59 // fact that the command buffer sits on top of the native GL windowing (cgl, wgl, ...) but
60 // also tracks which of its contexts is current above that API and gets tripped up if the
61 // native windowing API is used directly outside of the command buffer code.
62 GrContextFactory factory(options);
63 ContextInfo ctxInfo = factory.getContextInfo(
64 contextType, GrContextFactory::ContextOverrides::kDisableNVPR);
Hal Canaryb6c5e5b2017-10-09 16:13:02 -040065 if (contextTypeFilter && !(*contextTypeFilter)(contextType)) {
66 continue;
67 }
68
69 ReporterContext ctx(reporter, SkString(GrContextFactory::ContextTypeName(contextType)));
70 if (ctxInfo.grContext()) {
71 (*test)(reporter, ctxInfo);
72 ctxInfo.grContext()->flush();
73 }
Brian Salomondcfca432017-11-15 15:48:03 -050074 ctxInfo = factory.getContextInfo(contextType,
75 GrContextFactory::ContextOverrides::kRequireNVPRSupport);
Hal Canaryb6c5e5b2017-10-09 16:13:02 -040076 if (ctxInfo.grContext()) {
77 (*test)(reporter, ctxInfo);
78 ctxInfo.grContext()->flush();
79 }
80 }
81#endif
82}
83} // namespace skiatest