blob: acf8a3fbf28afe136724e2f9476db441d95266bd [file] [log] [blame]
scroggo7a10fb62014-11-04 07:21:10 -08001/*
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
8#ifndef DMJsonWriter_DEFINED
9#define DMJsonWriter_DEFINED
10
Mike Kleinc0bd9f92019-04-23 12:05:21 -050011#include "include/core/SkString.h"
12#include "tools/flags/CommandLineFlags.h"
scroggo7a10fb62014-11-04 07:21:10 -080013
14namespace DM {
15
16/**
17 * Class for collecting results from DM and writing to a json file.
18 * All methods are thread-safe.
19 */
20class JsonWriter {
21public:
22 /**
23 * Info describing a single run.
24 */
25 struct BitmapResult {
mtklein748ca3b2015-01-15 10:56:12 -080026 SkString name; // E.g. "ninepatch-stretch", "desk_gws.skp"
27 SkString config; // "gpu", "8888", "serialize", "pipe"
28 SkString sourceType; // "gm", "skp", "image"
djsollen54416de2015-04-03 07:24:48 -070029 SkString sourceOptions; // "image", "codec", "subset", "scanline"
scroggo7a10fb62014-11-04 07:21:10 -080030 SkString md5; // In ASCII, so 32 bytes long.
mtklein748ca3b2015-01-15 10:56:12 -080031 SkString ext; // Extension of file we wrote: "png", "pdf", ...
Mike Klein66f09a72019-02-12 13:03:54 -050032 SkString gamut;
33 SkString transferFn;
Mike Klein0abbaca2019-03-06 09:57:49 -060034 SkString colorType;
35 SkString alphaType;
Mike Klein82020c22019-03-07 14:11:16 -060036 SkString colorDepth;
scroggo7a10fb62014-11-04 07:21:10 -080037 };
38
39 /**
40 * Add a result to the end of the list of results.
41 */
42 static void AddBitmapResult(const BitmapResult&);
43
44 /**
Mike Kleinc6142d82019-03-25 10:54:59 -050045 * Write all collected results to the file dir/dm.json.
scroggo7a10fb62014-11-04 07:21:10 -080046 */
Mike Kleinc6142d82019-03-25 10:54:59 -050047 static void DumpJson(const char* dir,
48 CommandLineFlags::StringArray key,
49 CommandLineFlags::StringArray properties);
Brian Osman57796b32019-01-25 18:02:59 +000050
51 /**
52 * Read JSON file at path written by DumpJson, calling callback for each
53 * BitmapResult recorded in the file. Return success.
54 */
55 static bool ReadJson(const char* path, void(*callback)(BitmapResult));
scroggo7a10fb62014-11-04 07:21:10 -080056};
57
mtklein62bd1a62015-01-27 14:46:26 -080058
scroggo7a10fb62014-11-04 07:21:10 -080059} // namespace DM
60#endif // DMJsonWriter_DEFINED