blob: b6e880bed1733d67bb6b2df9622be4a5d2960428 [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
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#include "tests/Test.h"
Hal Canaryb6c5e5b2017-10-09 16:13:02 -04009
Robert Phillipsb87b39b2020-07-01 14:45:24 -040010#include "include/gpu/GrDirectContext.h"
11
Hal Canaryb6c5e5b2017-10-09 16:13:02 -040012using sk_gpu_test::GrContextFactory;
13using sk_gpu_test::GLTestContext;
14using sk_gpu_test::ContextInfo;
15
Hal Canaryb6c5e5b2017-10-09 16:13:02 -040016namespace skiatest {
17
Hal Canaryb6c5e5b2017-10-09 16:13:02 -040018bool IsGLContextType(sk_gpu_test::GrContextFactory::ContextType type) {
Greg Danielbdf12ad2018-10-12 09:31:11 -040019 return GrBackendApi::kOpenGL == GrContextFactory::ContextTypeBackend(type);
Hal Canaryb6c5e5b2017-10-09 16:13:02 -040020}
21bool IsVulkanContextType(sk_gpu_test::GrContextFactory::ContextType type) {
Greg Danielbdf12ad2018-10-12 09:31:11 -040022 return GrBackendApi::kVulkan == GrContextFactory::ContextTypeBackend(type);
Hal Canaryb6c5e5b2017-10-09 16:13:02 -040023}
Timothy Liang760dbc42018-07-17 13:28:20 -040024bool IsMetalContextType(sk_gpu_test::GrContextFactory::ContextType type) {
Greg Danielbdf12ad2018-10-12 09:31:11 -040025 return GrBackendApi::kMetal == GrContextFactory::ContextTypeBackend(type);
Timothy Liang760dbc42018-07-17 13:28:20 -040026}
Greg Danield4928d02020-06-19 11:13:26 -040027bool IsDirect3DContextType(sk_gpu_test::GrContextFactory::ContextType type) {
28 return GrBackendApi::kDirect3D == GrContextFactory::ContextTypeBackend(type);
29}
Greg Daniela58db7f2020-07-15 09:17:59 -040030bool IsDawnContextType(sk_gpu_test::GrContextFactory::ContextType type) {
31 return GrBackendApi::kDawn == GrContextFactory::ContextTypeBackend(type);
32}
Hal Canaryb6c5e5b2017-10-09 16:13:02 -040033bool IsRenderingGLContextType(sk_gpu_test::GrContextFactory::ContextType type) {
34 return IsGLContextType(type) && GrContextFactory::IsRenderingContext(type);
35}
Brian Osman7c597742019-03-26 11:10:11 -040036bool IsMockContextType(sk_gpu_test::GrContextFactory::ContextType type) {
37 return type == GrContextFactory::kMock_ContextType;
38}
Hal Canaryb6c5e5b2017-10-09 16:13:02 -040039
40void RunWithGPUTestContexts(GrContextTestFn* test, GrContextTypeFilterFn* contextTypeFilter,
Brian Salomondcfca432017-11-15 15:48:03 -050041 Reporter* reporter, const GrContextOptions& options) {
Hal Canaryb6c5e5b2017-10-09 16:13:02 -040042#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);
Chris Daltonb3c97452019-06-25 20:07:56 -060063 ContextInfo ctxInfo = factory.getContextInfo(contextType);
Hal Canaryb6c5e5b2017-10-09 16:13:02 -040064 if (contextTypeFilter && !(*contextTypeFilter)(contextType)) {
65 continue;
66 }
67
68 ReporterContext ctx(reporter, SkString(GrContextFactory::ContextTypeName(contextType)));
Robert Phillipsb87b39b2020-07-01 14:45:24 -040069 if (ctxInfo.directContext()) {
Hal Canaryb6c5e5b2017-10-09 16:13:02 -040070 (*test)(reporter, ctxInfo);
Greg Daniel58b5a542020-04-09 14:55:00 -040071 // In case the test changed the current context make sure we move it back before
72 // calling flush.
73 ctxInfo.testContext()->makeCurrent();
Brian Salomon72050802020-10-12 20:45:06 -040074 // Sync so any release/finished procs get called.
75 ctxInfo.directContext()->flushAndSubmit(/*sync*/true);
Hal Canaryb6c5e5b2017-10-09 16:13:02 -040076 }
Hal Canaryb6c5e5b2017-10-09 16:13:02 -040077 }
Hal Canaryb6c5e5b2017-10-09 16:13:02 -040078}
79} // namespace skiatest