2017-10-09 20:13:02 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2017 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "tests/Test.h"
|
2017-10-09 20:13:02 +00:00
|
|
|
|
|
|
|
using sk_gpu_test::GrContextFactory;
|
|
|
|
using sk_gpu_test::GLTestContext;
|
|
|
|
using sk_gpu_test::ContextInfo;
|
|
|
|
|
|
|
|
namespace skiatest {
|
|
|
|
|
|
|
|
bool IsGLContextType(sk_gpu_test::GrContextFactory::ContextType type) {
|
2018-10-12 13:31:11 +00:00
|
|
|
return GrBackendApi::kOpenGL == GrContextFactory::ContextTypeBackend(type);
|
2017-10-09 20:13:02 +00:00
|
|
|
}
|
|
|
|
bool IsVulkanContextType(sk_gpu_test::GrContextFactory::ContextType type) {
|
2018-10-12 13:31:11 +00:00
|
|
|
return GrBackendApi::kVulkan == GrContextFactory::ContextTypeBackend(type);
|
2017-10-09 20:13:02 +00:00
|
|
|
}
|
2018-07-17 17:28:20 +00:00
|
|
|
bool IsMetalContextType(sk_gpu_test::GrContextFactory::ContextType type) {
|
2018-10-12 13:31:11 +00:00
|
|
|
return GrBackendApi::kMetal == GrContextFactory::ContextTypeBackend(type);
|
2018-07-17 17:28:20 +00:00
|
|
|
}
|
2017-10-09 20:13:02 +00:00
|
|
|
bool IsRenderingGLContextType(sk_gpu_test::GrContextFactory::ContextType type) {
|
|
|
|
return IsGLContextType(type) && GrContextFactory::IsRenderingContext(type);
|
|
|
|
}
|
2019-10-24 14:23:26 +00:00
|
|
|
bool IsRenderingGLOrMetalContextType(sk_gpu_test::GrContextFactory::ContextType type) {
|
|
|
|
return (IsGLContextType(type) || IsMetalContextType(type)) &&
|
|
|
|
GrContextFactory::IsRenderingContext(type);
|
|
|
|
}
|
2019-03-26 15:10:11 +00:00
|
|
|
bool IsMockContextType(sk_gpu_test::GrContextFactory::ContextType type) {
|
|
|
|
return type == GrContextFactory::kMock_ContextType;
|
|
|
|
}
|
2017-10-09 20:13:02 +00:00
|
|
|
|
|
|
|
void RunWithGPUTestContexts(GrContextTestFn* test, GrContextTypeFilterFn* contextTypeFilter,
|
2017-11-15 20:48:03 +00:00
|
|
|
Reporter* reporter, const GrContextOptions& options) {
|
2017-10-09 20:13:02 +00:00
|
|
|
#if defined(SK_BUILD_FOR_UNIX) || defined(SK_BUILD_FOR_WIN) || defined(SK_BUILD_FOR_MAC)
|
|
|
|
static constexpr auto kNativeGLType = GrContextFactory::kGL_ContextType;
|
|
|
|
#else
|
|
|
|
static constexpr auto kNativeGLType = GrContextFactory::kGLES_ContextType;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
for (int typeInt = 0; typeInt < GrContextFactory::kContextTypeCnt; ++typeInt) {
|
|
|
|
GrContextFactory::ContextType contextType = (GrContextFactory::ContextType) typeInt;
|
|
|
|
// Use "native" instead of explicitly trying OpenGL and OpenGL ES. Do not use GLES on
|
|
|
|
// desktop since tests do not account for not fixing http://skbug.com/2809
|
|
|
|
if (contextType == GrContextFactory::kGL_ContextType ||
|
|
|
|
contextType == GrContextFactory::kGLES_ContextType) {
|
|
|
|
if (contextType != kNativeGLType) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2017-11-15 20:48:03 +00:00
|
|
|
// We destroy the factory and its associated contexts after each test. This is due to the
|
|
|
|
// fact that the command buffer sits on top of the native GL windowing (cgl, wgl, ...) but
|
|
|
|
// also tracks which of its contexts is current above that API and gets tripped up if the
|
|
|
|
// native windowing API is used directly outside of the command buffer code.
|
|
|
|
GrContextFactory factory(options);
|
2019-06-26 02:07:56 +00:00
|
|
|
ContextInfo ctxInfo = factory.getContextInfo(contextType);
|
2017-10-09 20:13:02 +00:00
|
|
|
if (contextTypeFilter && !(*contextTypeFilter)(contextType)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
ReporterContext ctx(reporter, SkString(GrContextFactory::ContextTypeName(contextType)));
|
|
|
|
if (ctxInfo.grContext()) {
|
|
|
|
(*test)(reporter, ctxInfo);
|
2020-04-09 18:55:00 +00:00
|
|
|
// In case the test changed the current context make sure we move it back before
|
|
|
|
// calling flush.
|
|
|
|
ctxInfo.testContext()->makeCurrent();
|
2020-05-14 19:45:44 +00:00
|
|
|
ctxInfo.grContext()->flushAndSubmit();
|
2017-10-09 20:13:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} // namespace skiatest
|