• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
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.
16 namespace skiatest {
17 
18 #if SK_SUPPORT_GPU
IsGLContextType(sk_gpu_test::GrContextFactory::ContextType type)19 bool IsGLContextType(sk_gpu_test::GrContextFactory::ContextType type) {
20     return kOpenGL_GrBackend == GrContextFactory::ContextTypeBackend(type);
21 }
IsVulkanContextType(sk_gpu_test::GrContextFactory::ContextType type)22 bool IsVulkanContextType(sk_gpu_test::GrContextFactory::ContextType type) {
23     return kVulkan_GrBackend == GrContextFactory::ContextTypeBackend(type);
24 }
IsRenderingGLContextType(sk_gpu_test::GrContextFactory::ContextType type)25 bool IsRenderingGLContextType(sk_gpu_test::GrContextFactory::ContextType type) {
26     return IsGLContextType(type) && GrContextFactory::IsRenderingContext(type);
27 }
IsNullGLContextType(sk_gpu_test::GrContextFactory::ContextType type)28 bool IsNullGLContextType(sk_gpu_test::GrContextFactory::ContextType type) {
29     return type == GrContextFactory::kNullGL_ContextType;
30 }
31 #else
32 bool IsGLContextType(int) { return false; }
33 bool IsVulkanContextType(int) { return false; }
34 bool IsRenderingGLContextType(int) { return false; }
35 bool IsNullGLContextType(int) { return false; }
36 #endif
37 
RunWithGPUTestContexts(GrContextTestFn * test,GrContextTypeFilterFn * contextTypeFilter,Reporter * reporter,const GrContextOptions & options)38 void RunWithGPUTestContexts(GrContextTestFn* test, GrContextTypeFilterFn* contextTypeFilter,
39                             Reporter* reporter, const GrContextOptions& options) {
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         // 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);
65         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         }
74         ctxInfo = factory.getContextInfo(contextType,
75                                          GrContextFactory::ContextOverrides::kRequireNVPRSupport);
76         if (ctxInfo.grContext()) {
77             (*test)(reporter, ctxInfo);
78             ctxInfo.grContext()->flush();
79         }
80     }
81 #endif
82 }
83 } // namespace skiatest
84