blob: 68e27a54b1c3dd3e211c982bce3eb9326bb063cb [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
11#include "SkString.h"
scroggo0ee26272014-11-07 06:07:32 -080012#include "Test.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", ...
mtklein409d4702016-02-29 07:38:01 -080032 bool gammaCorrect; // Old configs are not gamma correct, some new ones are.
scroggo7a10fb62014-11-04 07:21:10 -080033 };
34
35 /**
36 * Add a result to the end of the list of results.
37 */
38 static void AddBitmapResult(const BitmapResult&);
39
40 /**
scroggo0ee26272014-11-07 06:07:32 -080041 * Add a Failure from a Test.
42 */
43 static void AddTestFailure(const skiatest::Failure&);
44
45 /**
scroggo7a10fb62014-11-04 07:21:10 -080046 * Write all collected results to the file FLAGS_writePath[0]/dm.json.
47 */
48 static void DumpJson();
mtklein62bd1a62015-01-27 14:46:26 -080049
50 /**
51 * Read JSON file at path written by DumpJson, calling callback for each
52 * BitmapResult recorded in the file. Return success.
53 */
54 static bool ReadJson(const char* path, void(*callback)(BitmapResult));
scroggo7a10fb62014-11-04 07:21:10 -080055};
56
mtklein62bd1a62015-01-27 14:46:26 -080057
scroggo7a10fb62014-11-04 07:21:10 -080058} // namespace DM
59#endif // DMJsonWriter_DEFINED