OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2012 Google Inc. | 3 * Copyright 2012 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 #include "SkDebugger.h" | 9 #include "SkDebugger.h" |
| 10 #include "SkString.h" |
| 11 |
10 | 12 |
11 SkDebugger::SkDebugger() { | 13 SkDebugger::SkDebugger() { |
12 // Create this some other dynamic way? | 14 // Create this some other dynamic way? |
13 fDebugCanvas = new SkDebugCanvas(100, 100); | 15 fDebugCanvas = new SkDebugCanvas(100, 100); |
14 fPicture = NULL; | 16 fPicture = NULL; |
15 fPictureWidth = 0; | 17 fPictureWidth = 0; |
16 fPictureHeight = 0; | 18 fPictureHeight = 0; |
17 fIndex = 0; | 19 fIndex = 0; |
18 } | 20 } |
19 | 21 |
(...skipping 16 matching lines...) Expand all Loading... |
36 | 38 |
37 SkPicture* SkDebugger::copyPicture() { | 39 SkPicture* SkDebugger::copyPicture() { |
38 // We can't just call clone here since we want to removed the "deleted" | 40 // We can't just call clone here since we want to removed the "deleted" |
39 // commands. Playing back will strip those out. | 41 // commands. Playing back will strip those out. |
40 SkPicture* newPicture = new SkPicture; | 42 SkPicture* newPicture = new SkPicture; |
41 SkCanvas* canvas = newPicture->beginRecording(fPictureWidth, fPictureHeight)
; | 43 SkCanvas* canvas = newPicture->beginRecording(fPictureWidth, fPictureHeight)
; |
42 fDebugCanvas->draw(canvas); | 44 fDebugCanvas->draw(canvas); |
43 newPicture->endRecording(); | 45 newPicture->endRecording(); |
44 return newPicture; | 46 return newPicture; |
45 } | 47 } |
| 48 |
| 49 void SkDebugger::getOverviewText(const SkTDArray<double>* typeTimes, |
| 50 double totTime, |
| 51 SkString* overview) { |
| 52 const SkTDArray<SkDrawCommand*>& commands = this->getDrawCommands(); |
| 53 |
| 54 SkTDArray<int> counts; |
| 55 counts.setCount(LAST_DRAWTYPE_ENUM+1); |
| 56 for (int i = 0; i < LAST_DRAWTYPE_ENUM+1; ++i) { |
| 57 counts[i] = 0; |
| 58 } |
| 59 |
| 60 for (int i = 0; i < commands.count(); i++) { |
| 61 counts[commands[i]->getType()]++; |
| 62 } |
| 63 |
| 64 overview->reset(); |
| 65 int total = 0; |
| 66 #ifdef SK_DEBUG |
| 67 double totPercent = 0, tempSum = 0; |
| 68 #endif |
| 69 for (int i = 0; i < LAST_DRAWTYPE_ENUM+1; ++i) { |
| 70 if (0 == counts[i]) { |
| 71 // if there were no commands of this type then they should've consum
ed no time |
| 72 SkASSERT(NULL == typeTimes || 0.0 == (*typeTimes)[i]); |
| 73 continue; |
| 74 } |
| 75 |
| 76 overview->append(SkDrawCommand::GetCommandString((DrawType) i)); |
| 77 overview->append(": "); |
| 78 overview->appendScalar(counts[i]); |
| 79 if (NULL != typeTimes) { |
| 80 overview->append(" - "); |
| 81 overview->appendScalar((*typeTimes)[i]); |
| 82 overview->append("ms"); |
| 83 overview->append(" - "); |
| 84 double percent = 100.0*(*typeTimes)[i]/totTime; |
| 85 overview->appendScalar(percent); |
| 86 overview->append("%"); |
| 87 #ifdef SK_DEBUG |
| 88 totPercent += percent; |
| 89 tempSum += (*typeTimes)[i]; |
| 90 #endif |
| 91 } |
| 92 overview->append("<br/>"); |
| 93 total += counts[i]; |
| 94 } |
| 95 #ifdef SK_DEBUG |
| 96 if (NULL != typeTimes) { |
| 97 SkASSERT(SkScalarNearlyEqual(totPercent, 100.0)); |
| 98 SkASSERT(SkScalarNearlyEqual(tempSum, totTime)); |
| 99 } |
| 100 #endif |
| 101 |
| 102 if (totTime > 0.0) { |
| 103 overview->append("Total Time: "); |
| 104 overview->appendScalar(totTime); |
| 105 overview->append("ms"); |
| 106 #ifdef SK_DEBUG |
| 107 overview->append(" "); |
| 108 overview->appendScalar(totPercent); |
| 109 overview->append("% "); |
| 110 #endif |
| 111 overview->append("<br/>"); |
| 112 } |
| 113 |
| 114 SkString totalStr; |
| 115 totalStr.append("Total Draw Commands: "); |
| 116 totalStr.appendScalar(total); |
| 117 totalStr.append("<br/>"); |
| 118 overview->insert(0, totalStr); |
| 119 |
| 120 overview->append("<br/>"); |
| 121 overview->append("SkPicture Width: "); |
| 122 overview->appendScalar(pictureWidth()); |
| 123 overview->append("px<br/>"); |
| 124 overview->append("SkPicture Height: "); |
| 125 overview->appendScalar(pictureHeight()); |
| 126 overview->append("px"); |
| 127 } |
OLD | NEW |