blob: 64b1aa1c35e70e6c9663edc8a7af4ffbc5092d26 [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
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) {
Greg Danielbdf12ad2018-10-12 09:31:11 -040017 return GrBackendApi::kOpenGL == GrContextFactory::ContextTypeBackend(type);
Hal Canaryb6c5e5b2017-10-09 16:13:02 -040018}
19bool IsVulkanContextType(sk_gpu_test::GrContextFactory::ContextType type) {
Greg Danielbdf12ad2018-10-12 09:31:11 -040020 return GrBackendApi::kVulkan == GrContextFactory::ContextTypeBackend(type);
Hal Canaryb6c5e5b2017-10-09 16:13:02 -040021}
Timothy Liang760dbc42018-07-17 13:28:20 -040022bool IsMetalContextType(sk_gpu_test::GrContextFactory::ContextType type) {
Greg Danielbdf12ad2018-10-12 09:31:11 -040023 return GrBackendApi::kMetal == GrContextFactory::ContextTypeBackend(type);
Timothy Liang760dbc42018-07-17 13:28:20 -040024}
Hal Canaryb6c5e5b2017-10-09 16:13:02 -040025bool IsRenderingGLContextType(sk_gpu_test::GrContextFactory::ContextType type) {
26 return IsGLContextType(type) && GrContextFactory::IsRenderingContext(type);
27}
Jim Van Verth5a8f3e42019-10-24 10:23:26 -040028bool IsRenderingGLOrMetalContextType(sk_gpu_test::GrContextFactory::ContextType type) {
29 return (IsGLContextType(type) || IsMetalContextType(type)) &&
30 GrContextFactory::IsRenderingContext(type);
31}
Brian Osman7c597742019-03-26 11:10:11 -040032bool IsMockContextType(sk_gpu_test::GrContextFactory::ContextType type) {
33 return type == GrContextFactory::kMock_ContextType;
34}
Hal Canaryb6c5e5b2017-10-09 16:13:02 -040035
36void RunWithGPUTestContexts(GrContextTestFn* test, GrContextTypeFilterFn* contextTypeFilter,
Brian Salomondcfca432017-11-15 15:48:03 -050037 Reporter* reporter, const GrContextOptions& options) {
Hal Canaryb6c5e5b2017-10-09 16:13:02 -040038#if defined(SK_BUILD_FOR_UNIX) || defined(SK_BUILD_FOR_WIN) || defined(SK_BUILD_FOR_MAC)
39 static constexpr auto kNativeGLType = GrContextFactory::kGL_ContextType;
40#else
41 static constexpr auto kNativeGLType = GrContextFactory::kGLES_ContextType;
42#endif
43
44 for (int typeInt = 0; typeInt < GrContextFactory::kContextTypeCnt; ++typeInt) {
45 GrContextFactory::ContextType contextType = (GrContextFactory::ContextType) typeInt;
46 // Use "native" instead of explicitly trying OpenGL and OpenGL ES. Do not use GLES on
47 // desktop since tests do not account for not fixing http://skbug.com/2809
48 if (contextType == GrContextFactory::kGL_ContextType ||
49 contextType == GrContextFactory::kGLES_ContextType) {
50 if (contextType != kNativeGLType) {
51 continue;
52 }
53 }
Brian Salomondcfca432017-11-15 15:48:03 -050054 // We destroy the factory and its associated contexts after each test. This is due to the
55 // fact that the command buffer sits on top of the native GL windowing (cgl, wgl, ...) but
56 // also tracks which of its contexts is current above that API and gets tripped up if the
57 // native windowing API is used directly outside of the command buffer code.
58 GrContextFactory factory(options);
Chris Daltonb3c97452019-06-25 20:07:56 -060059 ContextInfo ctxInfo = factory.getContextInfo(contextType);
Hal Canaryb6c5e5b2017-10-09 16:13:02 -040060 if (contextTypeFilter && !(*contextTypeFilter)(contextType)) {
61 continue;
62 }
63
64 ReporterContext ctx(reporter, SkString(GrContextFactory::ContextTypeName(contextType)));
65 if (ctxInfo.grContext()) {
66 (*test)(reporter, ctxInfo);
Greg Daniel58b5a542020-04-09 14:55:00 -040067 // In case the test changed the current context make sure we move it back before
68 // calling flush.
69 ctxInfo.testContext()->makeCurrent();
Greg Daniel0a2464f2020-05-14 15:45:44 -040070 ctxInfo.grContext()->flushAndSubmit();
Hal Canaryb6c5e5b2017-10-09 16:13:02 -040071 }
Hal Canaryb6c5e5b2017-10-09 16:13:02 -040072 }
Hal Canaryb6c5e5b2017-10-09 16:13:02 -040073}
74} // namespace skiatest