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 8 #include "ok.h" 9 #include "Test.h" 10 11 struct TestStream : Stream { 12 const skiatest::TestRegistry* registry = skiatest::TestRegistry::Head(); 13 bool extended = false, verbose = false; 14 CreateTestStream15 static std::unique_ptr<Stream> Create(Options options) { 16 TestStream stream; 17 if (options("extended") != "") { stream.extended = true; } 18 if (options("verbose" ) != "") { stream.verbose = true; } 19 20 return move_unique(stream); 21 } 22 23 struct TestSrc : Src { 24 skiatest::Test test {"", false, nullptr}; 25 bool extended, verbose; 26 nameTestStream::TestSrc27 std::string name() override { return test.name; } sizeTestStream::TestSrc28 SkISize size() override { return {0,0}; } 29 drawTestStream::TestSrc30 bool draw(SkCanvas*) override { 31 // TODO(mtklein): GrContext 32 33 struct : public skiatest::Reporter { 34 bool ok = true; 35 const char* name; 36 bool extended, verbose_; 37 38 void reportFailed(const skiatest::Failure& failure) override { 39 SkDebugf("%s: %s\n", name, failure.toString().c_str()); 40 ok = false; 41 } 42 bool allowExtendedTest() const override { return extended; } 43 bool verbose() const override { return verbose_; } 44 } reporter; 45 reporter.name = test.name; 46 reporter.extended = extended; 47 reporter.verbose_ = verbose; 48 49 test.proc(&reporter, nullptr); 50 return reporter.ok; 51 } 52 }; 53 nextTestStream54 std::unique_ptr<Src> next() override { 55 if (!registry) { 56 return nullptr; 57 } 58 TestSrc src; 59 src.test = registry->factory(); 60 src.extended = extended; 61 src.verbose = verbose; 62 registry = registry->next(); 63 return move_unique(src); 64 } 65 }; 66 static Register test{"test", TestStream::Create}; 67 68 // Hey, now why were these defined in DM.cpp? That's kind of weird. 69 namespace skiatest { 70 #if SK_SUPPORT_GPU IsGLContextType(sk_gpu_test::GrContextFactory::ContextType type)71 bool IsGLContextType(sk_gpu_test::GrContextFactory::ContextType type) { 72 return kOpenGL_GrBackend == sk_gpu_test::GrContextFactory::ContextTypeBackend(type); 73 } IsVulkanContextType(sk_gpu_test::GrContextFactory::ContextType type)74 bool IsVulkanContextType(sk_gpu_test::GrContextFactory::ContextType type) { 75 return kVulkan_GrBackend == sk_gpu_test::GrContextFactory::ContextTypeBackend(type); 76 } IsRenderingGLContextType(sk_gpu_test::GrContextFactory::ContextType type)77 bool IsRenderingGLContextType(sk_gpu_test::GrContextFactory::ContextType type) { 78 return IsGLContextType(type) && sk_gpu_test::GrContextFactory::IsRenderingContext(type); 79 } IsNullGLContextType(sk_gpu_test::GrContextFactory::ContextType type)80 bool IsNullGLContextType(sk_gpu_test::GrContextFactory::ContextType type) { 81 return type == sk_gpu_test::GrContextFactory::kNullGL_ContextType; 82 } 83 #else 84 bool IsGLContextType (int) { return false; } 85 bool IsVulkanContextType (int) { return false; } 86 bool IsRenderingGLContextType(int) { return false; } 87 bool IsNullGLContextType (int) { return false; } 88 #endif 89 RunWithGPUTestContexts(GrContextTestFn * test,GrContextTypeFilterFn * contextTypeFilter,Reporter * reporter,sk_gpu_test::GrContextFactory * factory)90 void RunWithGPUTestContexts(GrContextTestFn* test, GrContextTypeFilterFn* contextTypeFilter, 91 Reporter* reporter, sk_gpu_test::GrContextFactory* factory) { 92 // TODO(bsalomon) 93 } 94 } 95