1 /* 2 * Copyright 2018 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 #ifndef skqp_DEFINED 9 #define skqp_DEFINED 10 11 #include <cstdint> 12 #include <memory> 13 #include <string> 14 #include <vector> 15 16 class SkData; 17 template <typename T> class sk_sp; 18 19 namespace skiagm { 20 class GM; 21 } // namespace skiagm 22 23 namespace skiatest { 24 struct Test; 25 } // namespace skiatest 26 27 class SkStreamAsset; 28 29 //////////////////////////////////////////////////////////////////////////////// 30 class SkQPAssetManager { 31 public: SkQPAssetManager()32 SkQPAssetManager() {} ~SkQPAssetManager()33 virtual ~SkQPAssetManager() {} 34 virtual sk_sp<SkData> open(const char* path) = 0; 35 virtual std::vector<std::string> iterateDir(const char* directory, const char* extension) = 0; 36 37 private: 38 SkQPAssetManager(const SkQPAssetManager&) = delete; 39 SkQPAssetManager& operator=(const SkQPAssetManager&) = delete; 40 }; 41 42 class SkQP { 43 public: 44 enum class SkiaBackend { 45 kGL, 46 kGLES, 47 kVulkan, 48 }; 49 using UnitTest = const skiatest::Test*; 50 51 struct SkSLErrorTest { 52 std::string name; 53 std::string shaderText; 54 }; 55 56 //////////////////////////////////////////////////////////////////////////// 57 58 /** These functions provide a descriptive name for the given value.*/ 59 static const char* GetUnitTestName(UnitTest); 60 61 SkQP(); 62 ~SkQP(); 63 64 /** 65 Initialize Skia and the SkQP. Should be executed only once. 66 67 @param assetManager - provides assets for the models. Does not take ownership. 68 @param reportDirectory - where to write out report. 69 */ 70 void init(SkQPAssetManager* assetManager, const char* reportDirectory); 71 72 /** @return a (hopefully empty) list of errors produced by this unit test. */ 73 std::vector<std::string> executeTest(UnitTest); 74 75 /** Call this after running all checks to write a report into the given report directory. */ 76 void makeReport(); 77 78 /** @return a sorted list of all Skia GPU unit tests */ getUnitTests()79 const std::vector<UnitTest>& getUnitTests() const { return fUnitTests; } 80 81 /** @return a sorted list of all SkSL error tests */ getSkSLErrorTests()82 const std::vector<SkSLErrorTest>& getSkSLErrorTests() const { return fSkSLErrorTests; } 83 84 //////////////////////////////////////////////////////////////////////////// 85 86 private: 87 struct TestResult { 88 std::string name; 89 std::vector<std::string> errors; 90 }; 91 std::vector<TestResult> fTestResults; 92 std::vector<SkiaBackend> fSupportedBackends; 93 std::string fReportDirectory; 94 std::vector<UnitTest> fUnitTests; 95 std::vector<SkSLErrorTest> fSkSLErrorTests; 96 97 SkQP(const SkQP&) = delete; 98 SkQP& operator=(const SkQP&) = delete; 99 }; 100 #endif // skqp_DEFINED 101 102