OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #ifndef GrAuditTrail_DEFINED | 8 #ifndef GrAuditTrail_DEFINED |
9 #define GrAuditTrail_DEFINED | 9 #define GrAuditTrail_DEFINED |
10 | 10 |
11 #include "GrConfig.h" | 11 #include "GrConfig.h" |
12 #include "SkRect.h" | 12 #include "SkRect.h" |
13 #include "SkString.h" | 13 #include "SkString.h" |
14 #include "SkTArray.h" | 14 #include "SkTArray.h" |
15 | 15 |
16 /* | 16 /* |
17 * GrAuditTrail collects a list of draw ops, detailed information about those op s, and can dump them | 17 * GrAuditTrail collects a list of draw ops, detailed information about those op s, and can dump them |
18 * to json. | 18 * to json. |
19 */ | 19 */ |
20 class GrAuditTrail { | 20 class GrAuditTrail { |
21 public: | 21 public: |
22 void addOp(const SkString& name) { | 22 class AutoFrame { |
23 public: | |
24 AutoFrame(GrAuditTrail* auditTrail, const char* name) | |
25 : fAuditTrail(auditTrail) { | |
26 if (GR_BATCH_DEBUGGING_OUTPUT) { | |
27 fAuditTrail->pushFrame(name); | |
28 } | |
29 } | |
30 | |
31 ~AutoFrame() { | |
32 if (GR_BATCH_DEBUGGING_OUTPUT) { | |
33 fAuditTrail->popFrame(); | |
34 } | |
35 } | |
36 | |
37 private: | |
38 GrAuditTrail* fAuditTrail; | |
39 }; | |
40 | |
41 void pushFrame(const char* name) { | |
23 SkASSERT(GR_BATCH_DEBUGGING_OUTPUT); | 42 SkASSERT(GR_BATCH_DEBUGGING_OUTPUT); |
24 fOps.push_back().fName = name; | 43 Frame* frame; |
44 if (fStack.empty()) { | |
45 frame = &fFrames.push_back(); | |
46 } else { | |
47 SkASSERT(fStack.back()->fBatches.empty()); | |
48 frame = &fStack.back()->fChildren.push_back(); | |
49 } | |
50 | |
51 frame->fName = name; | |
52 fStack.push_back(frame); | |
25 } | 53 } |
26 | 54 |
27 void addBatch(const SkString& name, const SkRect& bounds) { | 55 void popFrame() { |
28 SkASSERT(GR_BATCH_DEBUGGING_OUTPUT); | 56 SkASSERT(GR_BATCH_DEBUGGING_OUTPUT); |
29 Op::Batch& batch = fOps.back().fBatches.push_back(); | 57 fStack.pop_back(); |
58 } | |
59 | |
60 void addBatch(const char* name, const SkRect& bounds) { | |
61 // TODO when every internal callsite pushes a frame, we can add the asse rt | |
62 SkASSERT(GR_BATCH_DEBUGGING_OUTPUT /*&& !fStack.empty() && | |
63 fStack.back()->fChildren.empty()*/); | |
64 Frame::Batch& batch = fStack.back()->fBatches.push_back(); | |
30 batch.fName = name; | 65 batch.fName = name; |
31 batch.fBounds = bounds; | 66 batch.fBounds = bounds; |
32 } | 67 } |
33 | 68 |
34 SkString toJson() const; | 69 SkString toJson() const; |
35 | 70 |
36 void reset() { SkASSERT(GR_BATCH_DEBUGGING_OUTPUT); fOps.reset(); } | 71 void reset() { SkASSERT(GR_BATCH_DEBUGGING_OUTPUT && fStack.empty()); fFrame s.reset(); } |
37 | 72 |
38 private: | 73 private: |
robertphillips
2016/01/12 15:56:21
// A Frame can have either batches or children but
| |
39 struct Op { | 74 struct Frame { |
40 SkString toJson() const; | 75 SkString toJson() const; |
41 struct Batch { | 76 struct Batch { |
42 SkString toJson() const; | 77 SkString toJson() const; |
43 SkString fName; | 78 SkString fName; |
44 SkRect fBounds; | 79 SkRect fBounds; |
45 }; | 80 }; |
46 | 81 |
47 SkString fName; | 82 SkString fName; |
48 SkTArray<Batch> fBatches; | 83 SkTArray<Batch> fBatches; |
84 SkTArray<Frame> fChildren; | |
49 }; | 85 }; |
50 | 86 |
51 SkTArray<Op> fOps; | 87 SkTArray<Frame> fFrames; |
88 SkTArray<Frame*> fStack; | |
52 }; | 89 }; |
53 | 90 |
54 #define GR_AUDIT_TRAIL_INVOKE_GUARD(invoke, ...) \ | 91 #define GR_AUDIT_TRAIL_INVOKE_GUARD(invoke, ...) \ |
55 if (GR_BATCH_DEBUGGING_OUTPUT) { \ | 92 if (GR_BATCH_DEBUGGING_OUTPUT) { \ |
56 invoke(__VA_ARGS__); \ | 93 invoke(__VA_ARGS__); \ |
57 } | 94 } |
58 | 95 |
59 #define GR_AUDIT_TRAIL_ADDOP(audit_trail, opname) \ | 96 #define GR_AUDIT_TRAIL_AUTO_FRAME(audit_trail, framename) \ |
60 GR_AUDIT_TRAIL_INVOKE_GUARD(audit_trail->addOp, opname); | 97 GrAuditTrail::AutoFrame SK_MACRO_APPEND_LINE(auto_frame)(audit_trail, framen ame); |
61 | 98 |
62 #define GR_AUDIT_TRAIL_RESET(audit_trail) \ | 99 #define GR_AUDIT_TRAIL_RESET(audit_trail) \ |
63 GR_AUDIT_TRAIL_INVOKE_GUARD(audit_trail->reset); | 100 GR_AUDIT_TRAIL_INVOKE_GUARD(audit_trail->reset); |
64 | 101 |
65 #define GR_AUDIT_TRAIL_ADDBATCH(audit_trail, batchname, bounds) \ | 102 #define GR_AUDIT_TRAIL_ADDBATCH(audit_trail, batchname, bounds) \ |
66 GR_AUDIT_TRAIL_INVOKE_GUARD(audit_trail->addBatch, SkString(batchname), boun ds); | 103 GR_AUDIT_TRAIL_INVOKE_GUARD(audit_trail->addBatch, batchname, bounds); |
67 | 104 |
68 #endif | 105 #endif |
OLD | NEW |