dcfca431e3
This is to alleviate problems due to the command buffer getting bent out of shape when the current OpenGL context is switched out from under it (because we ran a test with a native GL context). This, however is not a full solution. More changes will be required to ensure that after running each command buffer or native test we bind the null context. This does allow us to take a step in that direction without breaking anything too badly. Moreover, there is no real benefit to reusing a GrContextFactory. Modifies DEF_GPUTEST to take GrContextOptions rather than a factory to use. Tests were already using their own factories anyway. In tests that use GrContextFactory the factory instance is moved to the inner loop. Modifies gpucts and skia_test to not use persistent GrContextFactories. Change-Id: Ie7a36793545c775f2f30653ead6fec93a3d22717 Reviewed-on: https://skia-review.googlesource.com/71861 Reviewed-by: Brian Osman <brianosman@google.com> Commit-Queue: Brian Salomon <bsalomon@google.com>
84 lines
3.4 KiB
C++
84 lines
3.4 KiB
C++
/*
|
|
* 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;
|
|
|
|
// TODO: currently many GPU tests are declared outside SK_SUPPORT_GPU guards.
|
|
// Thus we export the empty RunWithGPUTestContexts when SK_SUPPORT_GPU=0.
|
|
namespace skiatest {
|
|
|
|
#if SK_SUPPORT_GPU
|
|
bool IsGLContextType(sk_gpu_test::GrContextFactory::ContextType type) {
|
|
return kOpenGL_GrBackend == GrContextFactory::ContextTypeBackend(type);
|
|
}
|
|
bool IsVulkanContextType(sk_gpu_test::GrContextFactory::ContextType type) {
|
|
return kVulkan_GrBackend == GrContextFactory::ContextTypeBackend(type);
|
|
}
|
|
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;
|
|
}
|
|
#else
|
|
bool IsGLContextType(int) { return false; }
|
|
bool IsVulkanContextType(int) { return false; }
|
|
bool IsRenderingGLContextType(int) { return false; }
|
|
bool IsNullGLContextType(int) { return false; }
|
|
#endif
|
|
|
|
void RunWithGPUTestContexts(GrContextTestFn* test, GrContextTypeFilterFn* contextTypeFilter,
|
|
Reporter* reporter, const GrContextOptions& options) {
|
|
#if SK_SUPPORT_GPU
|
|
|
|
#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;
|
|
}
|
|
}
|
|
// 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);
|
|
if (contextTypeFilter && !(*contextTypeFilter)(contextType)) {
|
|
continue;
|
|
}
|
|
|
|
ReporterContext ctx(reporter, SkString(GrContextFactory::ContextTypeName(contextType)));
|
|
if (ctxInfo.grContext()) {
|
|
(*test)(reporter, ctxInfo);
|
|
ctxInfo.grContext()->flush();
|
|
}
|
|
ctxInfo = factory.getContextInfo(contextType,
|
|
GrContextFactory::ContextOverrides::kRequireNVPRSupport);
|
|
if (ctxInfo.grContext()) {
|
|
(*test)(reporter, ctxInfo);
|
|
ctxInfo.grContext()->flush();
|
|
}
|
|
}
|
|
#endif
|
|
}
|
|
} // namespace skiatest
|