skqp_model.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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_model_DEFINED
  8. #define skqp_model_DEFINED
  9. #include <cstdint>
  10. #include <string>
  11. #include "include/core/SkBitmap.h"
  12. #include "tools/skqp/src/skqp.h"
  13. class SkQPAssetManager;
  14. class SkStreamAsset;
  15. namespace skqp {
  16. /** Prefered colortype for comparing test outcomes. */
  17. constexpr SkColorType kColorType = kRGBA_8888_SkColorType;
  18. /** Prefered alphatype for comparing test outcomes. */
  19. constexpr SkAlphaType kAlphaType = kUnpremul_SkAlphaType;
  20. /** Where to find the maximum and minimum of the model. */
  21. constexpr char kMaxPngPath[] = "max.png";
  22. constexpr char kMinPngPath[] = "min.png";
  23. struct ModelResult {
  24. SkBitmap fErrors; // Correct pixels are white, failing pixels scale from black
  25. // (1 value off) to red (255 off in some channel).
  26. sk_sp<SkData> fMinPng; // original model data, PNG encoded image.
  27. sk_sp<SkData> fMaxPng; // original model data, PNG encoded image.
  28. SkQP::RenderOutcome fOutcome;
  29. std::string fErrorString; // if non-empty, an error occured.
  30. };
  31. SkQP::RenderOutcome Check(const SkPixmap& minImg,
  32. const SkPixmap& maxImg,
  33. const SkPixmap& img,
  34. unsigned tolerance,
  35. SkBitmap* errorOut);
  36. /** Check if the given test image matches the expected results.
  37. @param name the name of the rendering test that produced the image
  38. @param image the image to be tested. Should be kRGBA_8888_SkColorType
  39. and kUnpremul_SkAlphaType.
  40. @param assetManager provides model data files
  41. */
  42. ModelResult CheckAgainstModel(const char* name, const SkPixmap& image,
  43. SkQPAssetManager* assetManager);
  44. }
  45. #endif // skqp_model_DEFINED