DMGpuTestProcs.cpp 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  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. #include "tests/Test.h"
  8. using sk_gpu_test::GrContextFactory;
  9. using sk_gpu_test::GLTestContext;
  10. using sk_gpu_test::ContextInfo;
  11. namespace skiatest {
  12. bool IsGLContextType(sk_gpu_test::GrContextFactory::ContextType type) {
  13. return GrBackendApi::kOpenGL == GrContextFactory::ContextTypeBackend(type);
  14. }
  15. bool IsVulkanContextType(sk_gpu_test::GrContextFactory::ContextType type) {
  16. return GrBackendApi::kVulkan == GrContextFactory::ContextTypeBackend(type);
  17. }
  18. bool IsMetalContextType(sk_gpu_test::GrContextFactory::ContextType type) {
  19. return GrBackendApi::kMetal == GrContextFactory::ContextTypeBackend(type);
  20. }
  21. bool IsRenderingGLContextType(sk_gpu_test::GrContextFactory::ContextType type) {
  22. return IsGLContextType(type) && GrContextFactory::IsRenderingContext(type);
  23. }
  24. bool IsMockContextType(sk_gpu_test::GrContextFactory::ContextType type) {
  25. return type == GrContextFactory::kMock_ContextType;
  26. }
  27. void RunWithGPUTestContexts(GrContextTestFn* test, GrContextTypeFilterFn* contextTypeFilter,
  28. Reporter* reporter, const GrContextOptions& options) {
  29. #if defined(SK_BUILD_FOR_UNIX) || defined(SK_BUILD_FOR_WIN) || defined(SK_BUILD_FOR_MAC)
  30. static constexpr auto kNativeGLType = GrContextFactory::kGL_ContextType;
  31. #else
  32. static constexpr auto kNativeGLType = GrContextFactory::kGLES_ContextType;
  33. #endif
  34. for (int typeInt = 0; typeInt < GrContextFactory::kContextTypeCnt; ++typeInt) {
  35. GrContextFactory::ContextType contextType = (GrContextFactory::ContextType) typeInt;
  36. // Use "native" instead of explicitly trying OpenGL and OpenGL ES. Do not use GLES on
  37. // desktop since tests do not account for not fixing http://skbug.com/2809
  38. if (contextType == GrContextFactory::kGL_ContextType ||
  39. contextType == GrContextFactory::kGLES_ContextType) {
  40. if (contextType != kNativeGLType) {
  41. continue;
  42. }
  43. }
  44. // We destroy the factory and its associated contexts after each test. This is due to the
  45. // fact that the command buffer sits on top of the native GL windowing (cgl, wgl, ...) but
  46. // also tracks which of its contexts is current above that API and gets tripped up if the
  47. // native windowing API is used directly outside of the command buffer code.
  48. GrContextFactory factory(options);
  49. ContextInfo ctxInfo = factory.getContextInfo(contextType);
  50. if (contextTypeFilter && !(*contextTypeFilter)(contextType)) {
  51. continue;
  52. }
  53. ReporterContext ctx(reporter, SkString(GrContextFactory::ContextTypeName(contextType)));
  54. if (ctxInfo.grContext()) {
  55. (*test)(reporter, ctxInfo);
  56. ctxInfo.grContext()->flush();
  57. }
  58. }
  59. }
  60. } // namespace skiatest