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
|
|
|
|
2020-07-01 18:45:24 +00:00
|
|
|
#include "include/gpu/GrDirectContext.h"
|
|
|
|
|
2021-10-11 20:37:42 +00:00
|
|
|
#ifdef SK_GRAPHITE_ENABLED
|
2022-04-11 15:48:46 +00:00
|
|
|
#include "include/gpu/graphite/Context.h"
|
2021-10-11 15:28:21 +00:00
|
|
|
#include "tools/graphite/ContextFactory.h"
|
2021-10-11 20:37:42 +00:00
|
|
|
#endif
|
2021-10-11 15:28:21 +00:00
|
|
|
|
2017-10-09 20:13:02 +00:00
|
|
|
using sk_gpu_test::GrContextFactory;
|
2022-02-02 22:03:33 +00:00
|
|
|
using sk_gpu_test::ContextInfo;
|
2022-02-02 14:55:42 +00:00
|
|
|
|
2022-02-03 15:54:07 +00:00
|
|
|
#ifdef SK_GL
|
|
|
|
using sk_gpu_test::GLTestContext;
|
|
|
|
#endif
|
|
|
|
|
2017-10-09 20:13:02 +00:00
|
|
|
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
|
|
|
}
|
2020-06-19 15:13:26 +00:00
|
|
|
bool IsDirect3DContextType(sk_gpu_test::GrContextFactory::ContextType type) {
|
|
|
|
return GrBackendApi::kDirect3D == GrContextFactory::ContextTypeBackend(type);
|
|
|
|
}
|
2020-07-15 13:17:59 +00:00
|
|
|
bool IsDawnContextType(sk_gpu_test::GrContextFactory::ContextType type) {
|
|
|
|
return GrBackendApi::kDawn == GrContextFactory::ContextTypeBackend(type);
|
|
|
|
}
|
2017-10-09 20:13:02 +00:00
|
|
|
bool IsRenderingGLContextType(sk_gpu_test::GrContextFactory::ContextType type) {
|
|
|
|
return IsGLContextType(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)));
|
2020-07-01 18:45:24 +00:00
|
|
|
if (ctxInfo.directContext()) {
|
2017-10-09 20:13:02 +00:00
|
|
|
(*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-10-13 00:45:06 +00:00
|
|
|
// Sync so any release/finished procs get called.
|
|
|
|
ctxInfo.directContext()->flushAndSubmit(/*sync*/true);
|
2017-10-09 20:13:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-10-11 15:28:21 +00:00
|
|
|
|
|
|
|
#ifdef SK_GRAPHITE_ENABLED
|
|
|
|
|
|
|
|
namespace graphite {
|
|
|
|
|
|
|
|
void RunWithGraphiteTestContexts(GraphiteTestFn* test, Reporter* reporter) {
|
|
|
|
ContextFactory factory;
|
|
|
|
|
|
|
|
auto [_, context] = factory.getContextInfo(ContextFactory::ContextType::kMetal);
|
|
|
|
if (!context) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-02-03 16:12:45 +00:00
|
|
|
(*test)(reporter, context);
|
2021-10-11 15:28:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace graphite
|
|
|
|
|
|
|
|
#endif // SK_GRAPHITE_ENABLED
|
|
|
|
|
2017-10-09 20:13:02 +00:00
|
|
|
} // namespace skiatest
|