Hal Canary | ac7f23c | 2018-11-26 14:07:41 -0500 | [diff] [blame] | 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 <tuple> |
| 15 | #include <unordered_set> |
| 16 | #include <unordered_map> |
| 17 | #include <vector> |
| 18 | |
| 19 | class SkData; |
| 20 | template <typename T> class sk_sp; |
| 21 | |
| 22 | namespace skiagm { |
| 23 | class GM; |
| 24 | } |
| 25 | |
| 26 | namespace skiatest { |
| 27 | struct Test; |
| 28 | } |
| 29 | |
| 30 | class SkStreamAsset; |
| 31 | |
| 32 | //////////////////////////////////////////////////////////////////////////////// |
| 33 | class SkQPAssetManager { |
| 34 | public: |
| 35 | SkQPAssetManager() {} |
| 36 | virtual ~SkQPAssetManager() {} |
| 37 | virtual sk_sp<SkData> open(const char* path) = 0; |
| 38 | private: |
| 39 | SkQPAssetManager(const SkQPAssetManager&) = delete; |
| 40 | SkQPAssetManager& operator=(const SkQPAssetManager&) = delete; |
| 41 | }; |
| 42 | |
| 43 | class SkQP { |
| 44 | public: |
| 45 | enum class SkiaBackend { |
| 46 | kGL, |
| 47 | kGLES, |
| 48 | kVulkan, |
| 49 | }; |
| 50 | using GMFactory = skiagm::GM* (*)(void*); |
| 51 | using UnitTest = const skiatest::Test*; |
| 52 | |
| 53 | //////////////////////////////////////////////////////////////////////////// |
| 54 | |
| 55 | /** These functions provide a descriptive name for the given value.*/ |
| 56 | static std::string GetGMName(GMFactory); |
| 57 | static const char* GetUnitTestName(UnitTest); |
| 58 | static const char* GetBackendName(SkiaBackend); |
| 59 | |
| 60 | SkQP(); |
| 61 | ~SkQP(); |
| 62 | |
| 63 | /** |
| 64 | Initialize Skia and the SkQP. Should be executed only once. |
| 65 | |
| 66 | @param assetManager - provides assets for the models. Does not take ownership. |
| 67 | @param reportDirectory - where to write out report. |
| 68 | */ |
| 69 | void init(SkQPAssetManager* assetManager, const char* reportDirectory); |
| 70 | |
| 71 | struct RenderOutcome { |
| 72 | // All three values will be 0 if the test passes. |
| 73 | int fMaxError = 0; // maximum error of all pixel. |
| 74 | int fBadPixelCount = 0; // number of pixels with non-zero error. |
| 75 | int64_t fTotalError = 0; // sum of error for all bad pixels. |
| 76 | }; |
| 77 | |
| 78 | /** |
| 79 | @return render outcome and error string. Only errors running or |
| 80 | evaluating the GM will result in a non-empty error string. |
| 81 | */ |
| 82 | std::tuple<RenderOutcome, std::string> evaluateGM(SkiaBackend, GMFactory); |
| 83 | |
| 84 | /** @return a (hopefully empty) list of errors produced by this unit test. */ |
| 85 | std::vector<std::string> executeTest(UnitTest); |
| 86 | |
| 87 | /** Call this after running all checks to write a report into the given |
| 88 | report directory. */ |
| 89 | void makeReport(); |
| 90 | |
| 91 | /** @return a list of backends that this version of SkQP supports. */ |
| 92 | const std::vector<SkiaBackend>& getSupportedBackends() const { return fSupportedBackends; } |
| 93 | /** @return a list of all Skia GMs in lexicographic order. */ |
| 94 | const std::vector<GMFactory>& getGMs() const { return fGMs; } |
| 95 | /** @return a list of all Skia GPU unit tests in lexicographic order. */ |
| 96 | const std::vector<UnitTest>& getUnitTests() const { return fUnitTests; } |
| 97 | //////////////////////////////////////////////////////////////////////////// |
| 98 | |
| 99 | private: |
| 100 | struct RenderResult { |
| 101 | SkiaBackend fBackend; |
| 102 | GMFactory fGM; |
| 103 | RenderOutcome fOutcome; |
| 104 | }; |
| 105 | struct UnitTestResult { |
| 106 | UnitTest fUnitTest; |
| 107 | std::vector<std::string> fErrors; |
| 108 | }; |
| 109 | std::vector<RenderResult> fRenderResults; |
| 110 | std::vector<UnitTestResult> fUnitTestResults; |
| 111 | std::vector<SkiaBackend> fSupportedBackends; |
| 112 | SkQPAssetManager* fAssetManager = nullptr; |
| 113 | std::string fReportDirectory; |
| 114 | std::vector<UnitTest> fUnitTests; |
| 115 | std::vector<GMFactory> fGMs; |
| 116 | std::unordered_map<std::string, int64_t> fGMThresholds; |
| 117 | |
| 118 | SkQP(const SkQP&) = delete; |
| 119 | SkQP& operator=(const SkQP&) = delete; |
| 120 | }; |
| 121 | #endif // skqp_DEFINED |
| 122 | |