• 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 "tests/Test.h"
9 
10 using sk_gpu_test::GrContextFactory;
11 using sk_gpu_test::GLTestContext;
12 using sk_gpu_test::ContextInfo;
13 
14 namespace skiatest {
15 
IsGLContextType(sk_gpu_test::GrContextFactory::ContextType type)16 bool IsGLContextType(sk_gpu_test::GrContextFactory::ContextType type) {
17     return GrBackendApi::kOpenGL == GrContextFactory::ContextTypeBackend(type);
18 }
IsVulkanContextType(sk_gpu_test::GrContextFactory::ContextType type)19 bool IsVulkanContextType(sk_gpu_test::GrContextFactory::ContextType type) {
20     return GrBackendApi::kVulkan == GrContextFactory::ContextTypeBackend(type);
21 }
IsMetalContextType(sk_gpu_test::GrContextFactory::ContextType type)22 bool IsMetalContextType(sk_gpu_test::GrContextFactory::ContextType type) {
23     return GrBackendApi::kMetal == 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 }
IsMockContextType(sk_gpu_test::GrContextFactory::ContextType type)28 bool IsMockContextType(sk_gpu_test::GrContextFactory::ContextType type) {
29     return type == GrContextFactory::kMock_ContextType;
30 }
31 
RunWithGPUTestContexts(GrContextTestFn * test,GrContextTypeFilterFn * contextTypeFilter,Reporter * reporter,const GrContextOptions & options)32 void RunWithGPUTestContexts(GrContextTestFn* test, GrContextTypeFilterFn* contextTypeFilter,
33                             Reporter* reporter, const GrContextOptions& options) {
34 #if defined(SK_BUILD_FOR_UNIX) || defined(SK_BUILD_FOR_WIN) || defined(SK_BUILD_FOR_MAC)
35     static constexpr auto kNativeGLType = GrContextFactory::kGL_ContextType;
36 #else
37     static constexpr auto kNativeGLType = GrContextFactory::kGLES_ContextType;
38 #endif
39 
40     for (int typeInt = 0; typeInt < GrContextFactory::kContextTypeCnt; ++typeInt) {
41         GrContextFactory::ContextType contextType = (GrContextFactory::ContextType) typeInt;
42         // Use "native" instead of explicitly trying OpenGL and OpenGL ES. Do not use GLES on
43         // desktop since tests do not account for not fixing http://skbug.com/2809
44         if (contextType == GrContextFactory::kGL_ContextType ||
45             contextType == GrContextFactory::kGLES_ContextType) {
46             if (contextType != kNativeGLType) {
47                 continue;
48             }
49         }
50         // We destroy the factory and its associated contexts after each test. This is due to the
51         // fact that the command buffer sits on top of the native GL windowing (cgl, wgl, ...) but
52         // also tracks which of its contexts is current above that API and gets tripped up if the
53         // native windowing API is used directly outside of the command buffer code.
54         GrContextFactory factory(options);
55         ContextInfo ctxInfo = factory.getContextInfo(contextType);
56         if (contextTypeFilter && !(*contextTypeFilter)(contextType)) {
57             continue;
58         }
59 
60         ReporterContext ctx(reporter, SkString(GrContextFactory::ContextTypeName(contextType)));
61         if (ctxInfo.grContext()) {
62             (*test)(reporter, ctxInfo);
63             ctxInfo.grContext()->flush();
64         }
65     }
66 }
67 } // namespace skiatest
68