joshualitt | 27a48dc | 2016-01-08 07:19:47 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
joshualitt | 5651ee6 | 2016-01-11 10:39:11 -0800 | [diff] [blame] | 11 | #include "GrConfig.h" |
joshualitt | 086cee1 | 2016-01-12 06:45:24 -0800 | [diff] [blame^] | 12 | #include "SkRect.h" |
joshualitt | 27a48dc | 2016-01-08 07:19:47 -0800 | [diff] [blame] | 13 | #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 | */ |
| 20 | class GrAuditTrail { |
| 21 | public: |
joshualitt | 086cee1 | 2016-01-12 06:45:24 -0800 | [diff] [blame^] | 22 | void addOp(const SkString& name) { |
joshualitt | 5651ee6 | 2016-01-11 10:39:11 -0800 | [diff] [blame] | 23 | SkASSERT(GR_BATCH_DEBUGGING_OUTPUT); |
joshualitt | 27a48dc | 2016-01-08 07:19:47 -0800 | [diff] [blame] | 24 | fOps.push_back().fName = name; |
| 25 | } |
| 26 | |
joshualitt | 086cee1 | 2016-01-12 06:45:24 -0800 | [diff] [blame^] | 27 | 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 | |
joshualitt | 27a48dc | 2016-01-08 07:19:47 -0800 | [diff] [blame] | 34 | SkString toJson() const; |
| 35 | |
joshualitt | 5651ee6 | 2016-01-11 10:39:11 -0800 | [diff] [blame] | 36 | void reset() { SkASSERT(GR_BATCH_DEBUGGING_OUTPUT); fOps.reset(); } |
joshualitt | 27a48dc | 2016-01-08 07:19:47 -0800 | [diff] [blame] | 37 | |
| 38 | private: |
| 39 | struct Op { |
| 40 | SkString toJson() const; |
joshualitt | 086cee1 | 2016-01-12 06:45:24 -0800 | [diff] [blame^] | 41 | struct Batch { |
| 42 | SkString toJson() const; |
| 43 | SkString fName; |
| 44 | SkRect fBounds; |
| 45 | }; |
| 46 | |
joshualitt | 27a48dc | 2016-01-08 07:19:47 -0800 | [diff] [blame] | 47 | SkString fName; |
joshualitt | 086cee1 | 2016-01-12 06:45:24 -0800 | [diff] [blame^] | 48 | SkTArray<Batch> fBatches; |
joshualitt | 27a48dc | 2016-01-08 07:19:47 -0800 | [diff] [blame] | 49 | }; |
| 50 | |
| 51 | SkTArray<Op> fOps; |
| 52 | }; |
| 53 | |
joshualitt | 5651ee6 | 2016-01-11 10:39:11 -0800 | [diff] [blame] | 54 | #define GR_AUDIT_TRAIL_INVOKE_GUARD(invoke, ...) \ |
| 55 | if (GR_BATCH_DEBUGGING_OUTPUT) { \ |
| 56 | invoke(__VA_ARGS__); \ |
| 57 | } |
| 58 | |
joshualitt | 5651ee6 | 2016-01-11 10:39:11 -0800 | [diff] [blame] | 59 | #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 | |
joshualitt | 086cee1 | 2016-01-12 06:45:24 -0800 | [diff] [blame^] | 65 | #define GR_AUDIT_TRAIL_ADDBATCH(audit_trail, batchname, bounds) \ |
| 66 | GR_AUDIT_TRAIL_INVOKE_GUARD(audit_trail->addBatch, SkString(batchname), bounds); |
| 67 | |
joshualitt | 27a48dc | 2016-01-08 07:19:47 -0800 | [diff] [blame] | 68 | #endif |