| 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 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 fAuditTrail->popFrame(); | 35 fAuditTrail->popFrame(); |
| 36 } | 36 } |
| 37 } | 37 } |
| 38 | 38 |
| 39 private: | 39 private: |
| 40 GrAuditTrail* fAuditTrail; | 40 GrAuditTrail* fAuditTrail; |
| 41 }; | 41 }; |
| 42 | 42 |
| 43 void pushFrame(const char* name) { | 43 void pushFrame(const char* name) { |
| 44 SkASSERT(GR_BATCH_DEBUGGING_OUTPUT); | 44 SkASSERT(GR_BATCH_DEBUGGING_OUTPUT); |
| 45 Frame* frame; | 45 Frame* frame = new Frame; |
| 46 if (fStack.empty()) { | 46 if (fStack.empty()) { |
| 47 frame = &fFrames.push_back(); | 47 fFrames.emplace_back(frame); |
| 48 } else { | 48 } else { |
| 49 frame = &fStack.back()->fChildren.push_back(); | 49 fStack.back()->fChildren.emplace_back(frame); |
| 50 } | 50 } |
| 51 | 51 |
| 52 frame->fUniqueID = fUniqueID++; | 52 frame->fUniqueID = fUniqueID++; |
| 53 frame->fName = name; | 53 frame->fName = name; |
| 54 fStack.push_back(frame); | 54 fStack.push_back(frame); |
| 55 } | 55 } |
| 56 | 56 |
| 57 void popFrame() { | 57 void popFrame() { |
| 58 SkASSERT(GR_BATCH_DEBUGGING_OUTPUT); | 58 SkASSERT(GR_BATCH_DEBUGGING_OUTPUT); |
| 59 fStack.pop_back(); | 59 fStack.pop_back(); |
| 60 } | 60 } |
| 61 | 61 |
| 62 void addBatch(const char* name, const SkRect& bounds) { | 62 void addBatch(const char* name, const SkRect& bounds) { |
| 63 // TODO when every internal callsite pushes a frame, we can add the asse
rt | 63 SkASSERT(GR_BATCH_DEBUGGING_OUTPUT && !fStack.empty()); |
| 64 SkASSERT(GR_BATCH_DEBUGGING_OUTPUT /*&& !fStack.empty()*/); | 64 Batch* batch = new Batch; |
| 65 Frame::Batch& batch = fStack.back()->fBatches.push_back(); | 65 fStack.back()->fChildren.emplace_back(batch); |
| 66 batch.fName = name; | 66 batch->fName = name; |
| 67 batch.fBounds = bounds; | 67 batch->fBounds = bounds; |
| 68 } | 68 } |
| 69 | 69 |
| 70 SkString toJson() const; | 70 SkString toJson() const; |
| 71 | 71 |
| 72 void reset() { SkASSERT(GR_BATCH_DEBUGGING_OUTPUT && fStack.empty()); fFrame
s.reset(); } | 72 void reset() { SkASSERT(GR_BATCH_DEBUGGING_OUTPUT && fStack.empty()); fFrame
s.reset(); } |
| 73 | 73 |
| 74 private: | 74 private: |
| 75 struct Frame { | 75 // TODO if performance becomes an issue, we can move to using SkVarAlloc |
| 76 SkString toJson() const; | 76 struct Event { |
| 77 struct Batch { | 77 virtual ~Event() {} |
| 78 SkString toJson() const; | 78 virtual SkString toJson() const=0; |
| 79 const char* fName; | |
| 80 SkRect fBounds; | |
| 81 }; | |
| 82 | 79 |
| 83 const char* fName; | 80 const char* fName; |
| 84 // TODO combine these into a single array | |
| 85 SkTArray<Batch> fBatches; | |
| 86 SkTArray<Frame> fChildren; | |
| 87 uint64_t fUniqueID; | 81 uint64_t fUniqueID; |
| 88 }; | 82 }; |
| 89 | 83 |
| 90 SkTArray<Frame> fFrames; | 84 typedef SkTArray<SkAutoTDelete<Event>, true> FrameArray; |
| 85 struct Frame : public Event { |
| 86 SkString toJson() const override; |
| 87 FrameArray fChildren; |
| 88 }; |
| 89 |
| 90 struct Batch : public Event { |
| 91 SkString toJson() const override; |
| 92 SkRect fBounds; |
| 93 }; |
| 94 |
| 95 static void JsonifyTArray(SkString* json, const char* name, const FrameArray
& array); |
| 96 |
| 97 FrameArray fFrames; |
| 91 SkTArray<Frame*> fStack; | 98 SkTArray<Frame*> fStack; |
| 92 uint64_t fUniqueID; | 99 uint64_t fUniqueID; |
| 93 }; | 100 }; |
| 94 | 101 |
| 95 #define GR_AUDIT_TRAIL_INVOKE_GUARD(invoke, ...) \ | 102 #define GR_AUDIT_TRAIL_INVOKE_GUARD(invoke, ...) \ |
| 96 if (GR_BATCH_DEBUGGING_OUTPUT) { \ | 103 if (GR_BATCH_DEBUGGING_OUTPUT) { \ |
| 97 invoke(__VA_ARGS__); \ | 104 invoke(__VA_ARGS__); \ |
| 98 } | 105 } |
| 99 | 106 |
| 100 #define GR_AUDIT_TRAIL_AUTO_FRAME(audit_trail, framename) \ | 107 #define GR_AUDIT_TRAIL_AUTO_FRAME(audit_trail, framename) \ |
| 101 GrAuditTrail::AutoFrame SK_MACRO_APPEND_LINE(auto_frame)(audit_trail, framen
ame); | 108 GrAuditTrail::AutoFrame SK_MACRO_APPEND_LINE(auto_frame)(audit_trail, framen
ame); |
| 102 | 109 |
| 103 #define GR_AUDIT_TRAIL_RESET(audit_trail) \ | 110 #define GR_AUDIT_TRAIL_RESET(audit_trail) \ |
| 104 GR_AUDIT_TRAIL_INVOKE_GUARD(audit_trail->reset); | 111 GR_AUDIT_TRAIL_INVOKE_GUARD(audit_trail->reset); |
| 105 | 112 |
| 106 #define GR_AUDIT_TRAIL_ADDBATCH(audit_trail, batchname, bounds) \ | 113 #define GR_AUDIT_TRAIL_ADDBATCH(audit_trail, batchname, bounds) \ |
| 107 GR_AUDIT_TRAIL_INVOKE_GUARD(audit_trail->addBatch, batchname, bounds); | 114 GR_AUDIT_TRAIL_INVOKE_GUARD(audit_trail->addBatch, batchname, bounds); |
| 108 | 115 |
| 109 #endif | 116 #endif |
| OLD | NEW |