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