skqp.h 3.6 KB

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