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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "Test.h"
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
bool IsNullGLContextType(sk_gpu_test::GrContextFactory::ContextType type) {
|
|
|
|
return type == GrContextFactory::kNullGL_ContextType;
|
|
|
|
}
|
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);
|
|
|
|
ContextInfo ctxInfo = factory.getContextInfo(
|
|
|
|
contextType, GrContextFactory::ContextOverrides::kDisableNVPR);
|
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);
|
|
|
|
ctxInfo.grContext()->flush();
|
|
|
|
}
|
2017-11-15 20:48:03 +00:00
|
|
|
ctxInfo = factory.getContextInfo(contextType,
|
|
|
|
GrContextFactory::ContextOverrides::kRequireNVPRSupport);
|
2017-10-09 20:13:02 +00:00
|
|
|
if (ctxInfo.grContext()) {
|
|
|
|
(*test)(reporter, ctxInfo);
|
|
|
|
ctxInfo.grContext()->flush();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} // namespace skiatest
|