blob: 53f44f2173e64f7b87df0c5597bec31a5883e8ba [file] [log] [blame]
joshualitt27a48dc2016-01-08 07:19:47 -08001/*
2 * Copyright 2016 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 GrAuditTrail_DEFINED
9#define GrAuditTrail_DEFINED
10
joshualitt5651ee62016-01-11 10:39:11 -080011#include "GrConfig.h"
joshualitt086cee12016-01-12 06:45:24 -080012#include "SkRect.h"
joshualitt27a48dc2016-01-08 07:19:47 -080013#include "SkString.h"
14#include "SkTArray.h"
15
16/*
17 * GrAuditTrail collects a list of draw ops, detailed information about those ops, and can dump them
18 * to json.
19 */
20class GrAuditTrail {
21public:
joshualitt086cee12016-01-12 06:45:24 -080022 void addOp(const SkString& name) {
joshualitt5651ee62016-01-11 10:39:11 -080023 SkASSERT(GR_BATCH_DEBUGGING_OUTPUT);
joshualitt27a48dc2016-01-08 07:19:47 -080024 fOps.push_back().fName = name;
25 }
26
joshualitt086cee12016-01-12 06:45:24 -080027 void addBatch(const SkString& name, const SkRect& bounds) {
28 SkASSERT(GR_BATCH_DEBUGGING_OUTPUT);
29 Op::Batch& batch = fOps.back().fBatches.push_back();
30 batch.fName = name;
31 batch.fBounds = bounds;
32 }
33
joshualitt27a48dc2016-01-08 07:19:47 -080034 SkString toJson() const;
35
joshualitt5651ee62016-01-11 10:39:11 -080036 void reset() { SkASSERT(GR_BATCH_DEBUGGING_OUTPUT); fOps.reset(); }
joshualitt27a48dc2016-01-08 07:19:47 -080037
38private:
39 struct Op {
40 SkString toJson() const;
joshualitt086cee12016-01-12 06:45:24 -080041 struct Batch {
42 SkString toJson() const;
43 SkString fName;
44 SkRect fBounds;
45 };
46
joshualitt27a48dc2016-01-08 07:19:47 -080047 SkString fName;
joshualitt086cee12016-01-12 06:45:24 -080048 SkTArray<Batch> fBatches;
joshualitt27a48dc2016-01-08 07:19:47 -080049 };
50
51 SkTArray<Op> fOps;
52};
53
joshualitt5651ee62016-01-11 10:39:11 -080054#define GR_AUDIT_TRAIL_INVOKE_GUARD(invoke, ...) \
55 if (GR_BATCH_DEBUGGING_OUTPUT) { \
56 invoke(__VA_ARGS__); \
57 }
58
joshualitt5651ee62016-01-11 10:39:11 -080059#define GR_AUDIT_TRAIL_ADDOP(audit_trail, opname) \
60 GR_AUDIT_TRAIL_INVOKE_GUARD(audit_trail->addOp, opname);
61
62#define GR_AUDIT_TRAIL_RESET(audit_trail) \
63 GR_AUDIT_TRAIL_INVOKE_GUARD(audit_trail->reset);
64
joshualitt086cee12016-01-12 06:45:24 -080065#define GR_AUDIT_TRAIL_ADDBATCH(audit_trail, batchname, bounds) \
66 GR_AUDIT_TRAIL_INVOKE_GUARD(audit_trail->addBatch, SkString(batchname), bounds);
67
joshualitt27a48dc2016-01-08 07:19:47 -080068#endif