Chromium Code Reviews| 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 GrAuditTrail() : fUniqueID(0) {} |
| 23 | |
| 24 class AutoFrame { | |
| 25 public: | |
| 26 AutoFrame(GrAuditTrail* auditTrail, const char* name) | |
| 27 : fAuditTrail(auditTrail) { | |
| 28 if (GR_BATCH_DEBUGGING_OUTPUT) { | |
| 29 fAuditTrail->pushFrame(name); | |
| 30 } | |
| 31 } | |
| 32 | |
| 33 ~AutoFrame() { | |
| 34 if (GR_BATCH_DEBUGGING_OUTPUT) { | |
| 35 fAuditTrail->popFrame(); | |
| 36 } | |
| 37 } | |
| 38 | |
| 39 private: | |
| 40 GrAuditTrail* fAuditTrail; | |
| 41 }; | |
| 42 | |
| 43 void pushFrame(const char* name) { | |
| 23 SkASSERT(GR_BATCH_DEBUGGING_OUTPUT); | 44 SkASSERT(GR_BATCH_DEBUGGING_OUTPUT); |
| 24 fOps.push_back().fName = name; | 45 Frame* frame; |
| 46 if (fStack.empty()) { | |
| 47 frame = &fFrames.push_back(); | |
| 48 } else { | |
| 49 frame = &fStack.back()->fChildren.push_back(); | |
| 50 } | |
| 51 | |
| 52 frame->fUniqueID = fUniqueID++; | |
| 53 frame->fName = name; | |
| 54 fStack.push_back(frame); | |
| 25 } | 55 } |
| 26 | 56 |
| 27 void addBatch(const SkString& name, const SkRect& bounds) { | 57 void popFrame() { |
| 28 SkASSERT(GR_BATCH_DEBUGGING_OUTPUT); | 58 SkASSERT(GR_BATCH_DEBUGGING_OUTPUT); |
| 29 Op::Batch& batch = fOps.back().fBatches.push_back(); | 59 fStack.pop_back(); |
| 60 } | |
| 61 | |
| 62 void addBatch(const char* name, const SkRect& bounds) { | |
| 63 // TODO when every internal callsite pushes a frame, we can add the asse rt | |
| 64 SkASSERT(GR_BATCH_DEBUGGING_OUTPUT /*&& !fStack.empty()*/); | |
| 65 Frame::Batch& batch = fStack.back()->fBatches.push_back(); | |
| 30 batch.fName = name; | 66 batch.fName = name; |
| 31 batch.fBounds = bounds; | 67 batch.fBounds = bounds; |
| 32 } | 68 } |
| 33 | 69 |
| 34 SkString toJson() const; | 70 SkString toJson() const; |
| 35 | 71 |
| 36 void reset() { SkASSERT(GR_BATCH_DEBUGGING_OUTPUT); fOps.reset(); } | 72 void reset() { SkASSERT(GR_BATCH_DEBUGGING_OUTPUT && fStack.empty()); fFrame s.reset(); } |
| 37 | 73 |
| 38 private: | 74 private: |
| 39 struct Op { | 75 struct Frame { |
| 40 SkString toJson() const; | 76 SkString toJson() const; |
| 41 struct Batch { | 77 struct Batch { |
| 42 SkString toJson() const; | 78 SkString toJson() const; |
| 43 SkString fName; | 79 const char* fName; |
| 44 SkRect fBounds; | 80 SkRect fBounds; |
| 45 }; | 81 }; |
| 46 | 82 |
| 47 SkString fName; | 83 const char* fName; |
| 84 // TODO combine these into a single array | |
|
bsalomon
2016/01/12 19:51:13
Is this in order to preserve the sequence?
| |
| 48 SkTArray<Batch> fBatches; | 85 SkTArray<Batch> fBatches; |
| 86 SkTArray<Frame> fChildren; | |
| 87 uint64_t fUniqueID; | |
| 49 }; | 88 }; |
| 50 | 89 |
| 51 SkTArray<Op> fOps; | 90 SkTArray<Frame> fFrames; |
| 91 SkTArray<Frame*> fStack; | |
| 92 uint64_t fUniqueID; | |
| 52 }; | 93 }; |
| 53 | 94 |
| 54 #define GR_AUDIT_TRAIL_INVOKE_GUARD(invoke, ...) \ | 95 #define GR_AUDIT_TRAIL_INVOKE_GUARD(invoke, ...) \ |
| 55 if (GR_BATCH_DEBUGGING_OUTPUT) { \ | 96 if (GR_BATCH_DEBUGGING_OUTPUT) { \ |
| 56 invoke(__VA_ARGS__); \ | 97 invoke(__VA_ARGS__); \ |
| 57 } | 98 } |
| 58 | 99 |
| 59 #define GR_AUDIT_TRAIL_ADDOP(audit_trail, opname) \ | 100 #define GR_AUDIT_TRAIL_AUTO_FRAME(audit_trail, framename) \ |
| 60 GR_AUDIT_TRAIL_INVOKE_GUARD(audit_trail->addOp, opname); | 101 GrAuditTrail::AutoFrame SK_MACRO_APPEND_LINE(auto_frame)(audit_trail, framen ame); |
| 61 | 102 |
| 62 #define GR_AUDIT_TRAIL_RESET(audit_trail) \ | 103 #define GR_AUDIT_TRAIL_RESET(audit_trail) \ |
| 63 GR_AUDIT_TRAIL_INVOKE_GUARD(audit_trail->reset); | 104 GR_AUDIT_TRAIL_INVOKE_GUARD(audit_trail->reset); |
| 64 | 105 |
| 65 #define GR_AUDIT_TRAIL_ADDBATCH(audit_trail, batchname, bounds) \ | 106 #define GR_AUDIT_TRAIL_ADDBATCH(audit_trail, batchname, bounds) \ |
| 66 GR_AUDIT_TRAIL_INVOKE_GUARD(audit_trail->addBatch, SkString(batchname), boun ds); | 107 GR_AUDIT_TRAIL_INVOKE_GUARD(audit_trail->addBatch, batchname, bounds); |
| 67 | 108 |
| 68 #endif | 109 #endif |
| OLD | NEW |