DMJsonWriter.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. * Copyright 2014 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 DMJsonWriter_DEFINED
  8. #define DMJsonWriter_DEFINED
  9. #include "include/core/SkString.h"
  10. #include "tools/flags/CommandLineFlags.h"
  11. namespace DM {
  12. /**
  13. * Class for collecting results from DM and writing to a json file.
  14. * All methods are thread-safe.
  15. */
  16. class JsonWriter {
  17. public:
  18. /**
  19. * Info describing a single run.
  20. */
  21. struct BitmapResult {
  22. SkString name; // E.g. "ninepatch-stretch", "desk_gws.skp"
  23. SkString config; // "gpu", "8888", "serialize", "pipe"
  24. SkString sourceType; // "gm", "skp", "image"
  25. SkString sourceOptions; // "image", "codec", "subset", "scanline"
  26. SkString md5; // In ASCII, so 32 bytes long.
  27. SkString ext; // Extension of file we wrote: "png", "pdf", ...
  28. SkString gamut;
  29. SkString transferFn;
  30. SkString colorType;
  31. SkString alphaType;
  32. SkString colorDepth;
  33. };
  34. /**
  35. * Add a result to the end of the list of results.
  36. */
  37. static void AddBitmapResult(const BitmapResult&);
  38. /**
  39. * Write all collected results to the file dir/dm.json.
  40. */
  41. static void DumpJson(const char* dir,
  42. CommandLineFlags::StringArray key,
  43. CommandLineFlags::StringArray properties);
  44. /**
  45. * Read JSON file at path written by DumpJson, calling callback for each
  46. * BitmapResult recorded in the file. Return success.
  47. */
  48. static bool ReadJson(const char* path, void(*callback)(BitmapResult));
  49. };
  50. } // namespace DM
  51. #endif // DMJsonWriter_DEFINED