• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 }  // namespace skiagm
25 
26 namespace skiatest {
27 struct Test;
28 }  // namespace skiatest
29 
30 class SkStreamAsset;
31 
32 ////////////////////////////////////////////////////////////////////////////////
33 class SkQPAssetManager {
34 public:
SkQPAssetManager()35     SkQPAssetManager() {}
~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 = std::unique_ptr<skiagm::GM> (*)();
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 renderTests - file containing list of render tests.
68         @param reportDirectory - where to write out report.
69     */
70     void init(SkQPAssetManager* assetManager, const char* renderTests, const char* reportDirectory);
71 
72     struct RenderOutcome {
73         // All three values will be 0 if the test passes.
74         int fMaxError = 0;        // maximum error of all pixel.
75         int fBadPixelCount = 0;   // number of pixels with non-zero error.
76         int64_t fTotalError = 0;  // sum of error for all bad pixels.
77     };
78 
79     /**
80         @return render outcome and error string.  Only errors running or
81                 evaluating the GM will result in a non-empty error string.
82     */
83     std::tuple<RenderOutcome, std::string> evaluateGM(SkiaBackend, GMFactory);
84 
85     /** @return a (hopefully empty) list of errors produced by this unit test.  */
86     std::vector<std::string> executeTest(UnitTest);
87 
88     /** Call this after running all checks to write a report into the given
89         report directory. */
90     void makeReport();
91 
92     /** @return a list of backends that this version of SkQP supports.  */
getSupportedBackends()93     const std::vector<SkiaBackend>& getSupportedBackends() const { return fSupportedBackends; }
94     /** @return a list of all Skia GMs in lexicographic order.  */
getGMs()95     const std::vector<GMFactory>& getGMs() const { return fGMs; }
96     /** @return a list of all Skia GPU unit tests in lexicographic order.  */
getUnitTests()97     const std::vector<UnitTest>& getUnitTests() const { return fUnitTests; }
98     ////////////////////////////////////////////////////////////////////////////
99 
100 private:
101     struct RenderResult {
102         SkiaBackend fBackend;
103         GMFactory fGM;
104         RenderOutcome fOutcome;
105    };
106     struct UnitTestResult {
107         UnitTest fUnitTest;
108         std::vector<std::string> fErrors;
109     };
110     std::vector<RenderResult> fRenderResults;
111     std::vector<UnitTestResult> fUnitTestResults;
112     std::vector<SkiaBackend> fSupportedBackends;
113     SkQPAssetManager* fAssetManager = nullptr;
114     std::string fReportDirectory;
115     std::vector<UnitTest> fUnitTests;
116     std::vector<GMFactory> fGMs;
117     std::unordered_map<std::string, int64_t> fGMThresholds;
118 
119     SkQP(const SkQP&) = delete;
120     SkQP& operator=(const SkQP&) = delete;
121 };
122 #endif  // skqp_DEFINED
123 
124