blob: abae62806fc887993277dcfc28267ccaa5c8397c [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
Hal Canaryb6c5e5b2017-10-09 16:13:02 -040014namespace skiatest {
15
Hal Canaryb6c5e5b2017-10-09 16:13:02 -040016bool IsGLContextType(sk_gpu_test::GrContextFactory::ContextType type) {
17 return kOpenGL_GrBackend == GrContextFactory::ContextTypeBackend(type);
18}
19bool IsVulkanContextType(sk_gpu_test::GrContextFactory::ContextType type) {
20 return kVulkan_GrBackend == GrContextFactory::ContextTypeBackend(type);
21}
22bool IsRenderingGLContextType(sk_gpu_test::GrContextFactory::ContextType type) {
23 return IsGLContextType(type) && GrContextFactory::IsRenderingContext(type);
24}
25bool IsNullGLContextType(sk_gpu_test::GrContextFactory::ContextType type) {
26 return type == GrContextFactory::kNullGL_ContextType;
27}
Hal Canaryb6c5e5b2017-10-09 16:13:02 -040028
29void RunWithGPUTestContexts(GrContextTestFn* test, GrContextTypeFilterFn* contextTypeFilter,
Brian Salomondcfca432017-11-15 15:48:03 -050030 Reporter* reporter, const GrContextOptions& options) {
Hal Canaryb6c5e5b2017-10-09 16:13:02 -040031#if defined(SK_BUILD_FOR_UNIX) || defined(SK_BUILD_FOR_WIN) || defined(SK_BUILD_FOR_MAC)
32 static constexpr auto kNativeGLType = GrContextFactory::kGL_ContextType;
33#else
34 static constexpr auto kNativeGLType = GrContextFactory::kGLES_ContextType;
35#endif
36
37 for (int typeInt = 0; typeInt < GrContextFactory::kContextTypeCnt; ++typeInt) {
38 GrContextFactory::ContextType contextType = (GrContextFactory::ContextType) typeInt;
39 // Use "native" instead of explicitly trying OpenGL and OpenGL ES. Do not use GLES on
40 // desktop since tests do not account for not fixing http://skbug.com/2809
41 if (contextType == GrContextFactory::kGL_ContextType ||
42 contextType == GrContextFactory::kGLES_ContextType) {
43 if (contextType != kNativeGLType) {
44 continue;
45 }
46 }
Brian Salomondcfca432017-11-15 15:48:03 -050047 // We destroy the factory and its associated contexts after each test. This is due to the
48 // fact that the command buffer sits on top of the native GL windowing (cgl, wgl, ...) but
49 // also tracks which of its contexts is current above that API and gets tripped up if the
50 // native windowing API is used directly outside of the command buffer code.
51 GrContextFactory factory(options);
52 ContextInfo ctxInfo = factory.getContextInfo(
53 contextType, GrContextFactory::ContextOverrides::kDisableNVPR);
Hal Canaryb6c5e5b2017-10-09 16:13:02 -040054 if (contextTypeFilter && !(*contextTypeFilter)(contextType)) {
55 continue;
56 }
57
58 ReporterContext ctx(reporter, SkString(GrContextFactory::ContextTypeName(contextType)));
59 if (ctxInfo.grContext()) {
60 (*test)(reporter, ctxInfo);
61 ctxInfo.grContext()->flush();
62 }
Brian Salomondcfca432017-11-15 15:48:03 -050063 ctxInfo = factory.getContextInfo(contextType,
64 GrContextFactory::ContextOverrides::kRequireNVPRSupport);
Hal Canaryb6c5e5b2017-10-09 16:13:02 -040065 if (ctxInfo.grContext()) {
66 (*test)(reporter, ctxInfo);
67 ctxInfo.grContext()->flush();
68 }
69 }
Hal Canaryb6c5e5b2017-10-09 16:13:02 -040070}
71} // namespace skiatest