Debian Codegraph @

tools/skqp/src/skqp.h

raw
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:
32 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 using UnitTest = const skiatest::Test*;
45
46 struct SkSLErrorTest {
47 std::string name;
48 std::string shaderText;
49 };
50
51 ////////////////////////////////////////////////////////////////////////////
52
53 /** These functions provide a descriptive name for the given value.*/
54 static const char* GetUnitTestName(UnitTest);
55
56 SkQP();
57 ~SkQP();
58
59 /**
60 Initialize Skia and the SkQP. Should be executed only once.
61
62 @param assetManager - provides assets for the models. Does not take ownership.
63 @param reportDirectory - where to write out report.
64 */
65 void init(SkQPAssetManager* assetManager, const char* reportDirectory);
66
67 /** @return a (hopefully empty) list of errors produced by this unit test. */
68 std::vector<std::string> executeTest(UnitTest);
69
70 /** Call this after running all checks to write a report into the given report directory. */
71 void makeReport();
72
73 /** @return a sorted list of all Skia GPU unit tests */
74 const std::vector<UnitTest>& getUnitTests() const { return fUnitTests; }
75
76 /** @return a sorted list of all SkSL error tests */
77 const std::vector<SkSLErrorTest>& getSkSLErrorTests() const { return fSkSLErrorTests; }
78
79 ////////////////////////////////////////////////////////////////////////////
80
81 private:
82 struct TestResult {
83 std::string name;
84 std::vector<std::string> errors;
85 };
86 std::vector<TestResult> fTestResults;
87 std::string fReportDirectory;
88 std::vector<UnitTest> fUnitTests;
89 std::vector<SkSLErrorTest> fSkSLErrorTests;
90
91 // Defaults to zero since most checks care if it is greater than a specific value. So this will
92 // just default to it being less.
93 int fEnforcedAndroidAPILevel = 0;
94
95 SkQP(const SkQP&) = delete;
96 SkQP& operator=(const SkQP&) = delete;
97 void printBackendInfo(const char* dstPath);
98 };
99 #endif // skqp_DEFINED
100