| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2012 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 | |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 8 | #include "SkDebuggerGUI.h" |
| chudy@google.com | bbad34d | 2012-08-13 14:26:36 +0000 | [diff] [blame] | 9 | #include "SkGraphics.h" |
| scroggo@google.com | b4467e6 | 2012-11-06 23:10:09 +0000 | [diff] [blame] | 10 | #include "SkImageDecoder.h" |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 11 | #include <QListWidgetItem> |
| robertphillips@google.com | 2bde91d | 2012-11-15 14:57:57 +0000 | [diff] [blame] | 12 | #include "PictureRenderer.h" |
| robertphillips@google.com | 2bde91d | 2012-11-15 14:57:57 +0000 | [diff] [blame] | 13 | #include "SkPictureRecord.h" |
| 14 | #include "SkPicturePlayback.h" |
| robertphillips@google.com | e174a8b | 2012-11-27 16:04:42 +0000 | [diff] [blame^] | 15 | |
| 16 | #if defined(SK_BUILD_FOR_WIN32) |
| 17 | #include "BenchSysTimer_windows.h" |
| 18 | #elif defined(SK_BUILD_FOR_MAC) |
| 19 | #include "BenchSysTimer_mach.h" |
| 20 | #elif defined(SK_BUILD_FOR_UNIX) || defined(SK_BUILD_FOR_ANDROID) |
| 21 | #include "BenchSysTimer_posix.h" |
| 22 | #else |
| 23 | #include "BenchSysTimer_c.h" |
| 24 | #endif |
| 25 | |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 26 | |
| 27 | SkDebuggerGUI::SkDebuggerGUI(QWidget *parent) : |
| chudy@google.com | c432f00 | 2012-07-10 13:19:25 +0000 | [diff] [blame] | 28 | QMainWindow(parent) |
| chudy@google.com | 2d537a1 | 2012-07-31 12:49:52 +0000 | [diff] [blame] | 29 | , fCentralWidget(this) |
| 30 | , fStatusBar(this) |
| 31 | , fToolBar(this) |
| chudy@google.com | c432f00 | 2012-07-10 13:19:25 +0000 | [diff] [blame] | 32 | , fActionOpen(this) |
| 33 | , fActionBreakpoint(this) |
| robertphillips@google.com | d26c706 | 2012-11-12 20:42:12 +0000 | [diff] [blame] | 34 | , fActionProfile(this) |
| chudy@google.com | c432f00 | 2012-07-10 13:19:25 +0000 | [diff] [blame] | 35 | , fActionCancel(this) |
| chudy@google.com | 7e4cfbf | 2012-07-17 15:40:51 +0000 | [diff] [blame] | 36 | , fActionClearBreakpoints(this) |
| chudy@google.com | e504de0 | 2012-07-16 18:35:23 +0000 | [diff] [blame] | 37 | , fActionClearDeletes(this) |
| chudy@google.com | c432f00 | 2012-07-10 13:19:25 +0000 | [diff] [blame] | 38 | , fActionClose(this) |
| chudy@google.com | e504de0 | 2012-07-16 18:35:23 +0000 | [diff] [blame] | 39 | , fActionCreateBreakpoint(this) |
| chudy@google.com | c432f00 | 2012-07-10 13:19:25 +0000 | [diff] [blame] | 40 | , fActionDelete(this) |
| 41 | , fActionDirectory(this) |
| 42 | , fActionGoToLine(this) |
| 43 | , fActionInspector(this) |
| 44 | , fActionPlay(this) |
| chudy@google.com | e504de0 | 2012-07-16 18:35:23 +0000 | [diff] [blame] | 45 | , fActionPause(this) |
| chudy@google.com | c432f00 | 2012-07-10 13:19:25 +0000 | [diff] [blame] | 46 | , fActionRewind(this) |
| chudy@google.com | 0ab0339 | 2012-07-28 20:16:11 +0000 | [diff] [blame] | 47 | , fActionSave(this) |
| 48 | , fActionSaveAs(this) |
| chudy@google.com | 7e4cfbf | 2012-07-17 15:40:51 +0000 | [diff] [blame] | 49 | , fActionShowDeletes(this) |
| chudy@google.com | c432f00 | 2012-07-10 13:19:25 +0000 | [diff] [blame] | 50 | , fActionStepBack(this) |
| 51 | , fActionStepForward(this) |
| chudy@google.com | a122631 | 2012-07-26 20:26:44 +0000 | [diff] [blame] | 52 | , fActionZoomIn(this) |
| 53 | , fActionZoomOut(this) |
| 54 | , fMapper(this) |
| chudy@google.com | c432f00 | 2012-07-10 13:19:25 +0000 | [diff] [blame] | 55 | , fListWidget(&fCentralWidget) |
| 56 | , fDirectoryWidget(&fCentralWidget) |
| chudy@google.com | 607357f | 2012-08-07 16:12:23 +0000 | [diff] [blame] | 57 | , fCanvasWidget(this, &fDebugger) |
| robertphillips@google.com | 6dec8fc | 2012-11-21 17:11:02 +0000 | [diff] [blame] | 58 | , fImageWidget(&fDebugger) |
| chudy@google.com | c432f00 | 2012-07-10 13:19:25 +0000 | [diff] [blame] | 59 | , fMenuBar(this) |
| 60 | , fMenuFile(this) |
| 61 | , fMenuNavigate(this) |
| 62 | , fMenuView(this) |
| chudy@google.com | 7e4cfbf | 2012-07-17 15:40:51 +0000 | [diff] [blame] | 63 | , fBreakpointsActivated(false) |
| 64 | , fDeletesActivated(false) |
| 65 | , fPause(false) |
| chudy@google.com | d3058f5 | 2012-07-19 13:41:27 +0000 | [diff] [blame] | 66 | , fLoading(false) |
| chudy@google.com | c432f00 | 2012-07-10 13:19:25 +0000 | [diff] [blame] | 67 | { |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 68 | setupUi(this); |
| chudy@google.com | ea5488b | 2012-07-26 19:38:22 +0000 | [diff] [blame] | 69 | connect(&fListWidget, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)), this, SLOT(registerListClick(QListWidgetItem *))); |
| chudy@google.com | c432f00 | 2012-07-10 13:19:25 +0000 | [diff] [blame] | 70 | connect(&fActionOpen, SIGNAL(triggered()), this, SLOT(openFile())); |
| chudy@google.com | ea5488b | 2012-07-26 19:38:22 +0000 | [diff] [blame] | 71 | connect(&fActionDirectory, SIGNAL(triggered()), this, SLOT(toggleDirectory())); |
| 72 | connect(&fDirectoryWidget, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)), this, SLOT(loadFile(QListWidgetItem *))); |
| chudy@google.com | c432f00 | 2012-07-10 13:19:25 +0000 | [diff] [blame] | 73 | connect(&fActionDelete, SIGNAL(triggered()), this, SLOT(actionDelete())); |
| chudy@google.com | ea5488b | 2012-07-26 19:38:22 +0000 | [diff] [blame] | 74 | connect(&fListWidget, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(toggleBreakpoint())); |
| chudy@google.com | c432f00 | 2012-07-10 13:19:25 +0000 | [diff] [blame] | 75 | connect(&fActionRewind, SIGNAL(triggered()), this, SLOT(actionRewind())); |
| 76 | connect(&fActionPlay, SIGNAL(triggered()), this, SLOT(actionPlay())); |
| 77 | connect(&fActionStepBack, SIGNAL(triggered()), this, SLOT(actionStepBack())); |
| chudy@google.com | ea5488b | 2012-07-26 19:38:22 +0000 | [diff] [blame] | 78 | connect(&fActionStepForward, SIGNAL(triggered()), this, SLOT(actionStepForward())); |
| 79 | connect(&fActionBreakpoint, SIGNAL(triggered()), this, SLOT(actionBreakpoints())); |
| 80 | connect(&fActionInspector, SIGNAL(triggered()), this, SLOT(actionInspector())); |
| 81 | connect(&fActionInspector, SIGNAL(triggered()), this, SLOT(actionSettings())); |
| 82 | connect(&fFilter, SIGNAL(activated(QString)), this, SLOT(toggleFilter(QString))); |
| robertphillips@google.com | d26c706 | 2012-11-12 20:42:12 +0000 | [diff] [blame] | 83 | connect(&fActionProfile, SIGNAL(triggered()), this, SLOT(actionProfile())); |
| chudy@google.com | c432f00 | 2012-07-10 13:19:25 +0000 | [diff] [blame] | 84 | connect(&fActionCancel, SIGNAL(triggered()), this, SLOT(actionCancel())); |
| chudy@google.com | 7e4cfbf | 2012-07-17 15:40:51 +0000 | [diff] [blame] | 85 | connect(&fActionClearBreakpoints, SIGNAL(triggered()), this, SLOT(actionClearBreakpoints())); |
| 86 | connect(&fActionClearDeletes, SIGNAL(triggered()), this, SLOT(actionClearDeletes())); |
| chudy@google.com | c432f00 | 2012-07-10 13:19:25 +0000 | [diff] [blame] | 87 | connect(&fActionClose, SIGNAL(triggered()), this, SLOT(actionClose())); |
| chudy@google.com | ea5488b | 2012-07-26 19:38:22 +0000 | [diff] [blame] | 88 | connect(fSettingsWidget.getVisibilityButton(), SIGNAL(toggled(bool)), this, SLOT(actionCommandFilter())); |
| 89 | connect(fSettingsWidget.getGLCheckBox(), SIGNAL(toggled(bool)), this, SLOT(actionGLWidget(bool))); |
| 90 | connect(fSettingsWidget.getRasterCheckBox(), SIGNAL(toggled(bool)), this, SLOT(actionRasterWidget(bool))); |
| 91 | connect(&fActionPause, SIGNAL(toggled(bool)), this, SLOT(pauseDrawing(bool))); |
| chudy@google.com | e504de0 | 2012-07-16 18:35:23 +0000 | [diff] [blame] | 92 | connect(&fActionCreateBreakpoint, SIGNAL(activated()), this, SLOT(toggleBreakpoint())); |
| chudy@google.com | 7e4cfbf | 2012-07-17 15:40:51 +0000 | [diff] [blame] | 93 | connect(&fActionShowDeletes, SIGNAL(triggered()), this, SLOT(showDeletes())); |
| chudy@google.com | ea5488b | 2012-07-26 19:38:22 +0000 | [diff] [blame] | 94 | connect(&fCanvasWidget, SIGNAL(hitChanged(int)), this, SLOT(selectCommand(int))); |
| 95 | connect(&fCanvasWidget, SIGNAL(hitChanged(int)), &fSettingsWidget, SLOT(updateHit(int))); |
| 96 | connect(&fCanvasWidget, SIGNAL(scaleFactorChanged(float)), this, SLOT(actionScale(float))); |
| 97 | connect(&fCanvasWidget, SIGNAL(commandChanged(int)), &fSettingsWidget, SLOT(updateCommand(int))); |
| chudy@google.com | 0ab0339 | 2012-07-28 20:16:11 +0000 | [diff] [blame] | 98 | connect(&fActionSaveAs, SIGNAL(triggered()), this, SLOT(actionSaveAs())); |
| 99 | connect(&fActionSave, SIGNAL(triggered()), this, SLOT(actionSave())); |
| chudy@google.com | 7e4cfbf | 2012-07-17 15:40:51 +0000 | [diff] [blame] | 100 | |
| chudy@google.com | a122631 | 2012-07-26 20:26:44 +0000 | [diff] [blame] | 101 | fMapper.setMapping(&fActionZoomIn, 1); |
| 102 | fMapper.setMapping(&fActionZoomOut, -1); |
| 103 | |
| 104 | connect(&fActionZoomIn, SIGNAL(triggered()), &fMapper, SLOT(map())); |
| 105 | connect(&fActionZoomOut, SIGNAL(triggered()), &fMapper, SLOT(map())); |
| 106 | connect(&fMapper, SIGNAL(mapped(int)), &fCanvasWidget, SLOT(keyZoom(int))); |
| 107 | |
| chudy@google.com | 7e4cfbf | 2012-07-17 15:40:51 +0000 | [diff] [blame] | 108 | fInspectorWidget.setDisabled(true); |
| chudy@google.com | d3058f5 | 2012-07-19 13:41:27 +0000 | [diff] [blame] | 109 | fMenuEdit.setDisabled(true); |
| 110 | fMenuNavigate.setDisabled(true); |
| 111 | fMenuView.setDisabled(true); |
| chudy@google.com | bbad34d | 2012-08-13 14:26:36 +0000 | [diff] [blame] | 112 | |
| 113 | SkGraphics::Init(); |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 114 | } |
| 115 | |
| chudy@google.com | bbad34d | 2012-08-13 14:26:36 +0000 | [diff] [blame] | 116 | SkDebuggerGUI::~SkDebuggerGUI() { |
| 117 | SkGraphics::Term(); |
| 118 | } |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 119 | |
| 120 | void SkDebuggerGUI::actionBreakpoints() { |
| chudy@google.com | 7e4cfbf | 2012-07-17 15:40:51 +0000 | [diff] [blame] | 121 | fBreakpointsActivated = !fBreakpointsActivated; |
| chudy@google.com | c432f00 | 2012-07-10 13:19:25 +0000 | [diff] [blame] | 122 | for (int row = 0; row < fListWidget.count(); row++) { |
| 123 | QListWidgetItem *item = fListWidget.item(row); |
| chudy@google.com | 7e4cfbf | 2012-07-17 15:40:51 +0000 | [diff] [blame] | 124 | item->setHidden(item->checkState() == Qt::Unchecked && fBreakpointsActivated); |
| 125 | } |
| 126 | } |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 127 | |
| chudy@google.com | 7e4cfbf | 2012-07-17 15:40:51 +0000 | [diff] [blame] | 128 | void SkDebuggerGUI::showDeletes() { |
| 129 | fDeletesActivated = !fDeletesActivated; |
| 130 | for (int row = 0; row < fListWidget.count(); row++) { |
| 131 | QListWidgetItem *item = fListWidget.item(row); |
| chudy@google.com | 607357f | 2012-08-07 16:12:23 +0000 | [diff] [blame] | 132 | item->setHidden(fDebugger.isCommandVisible(row) |
| 133 | && fDeletesActivated); |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 134 | } |
| 135 | } |
| 136 | |
| robertphillips@google.com | 2bde91d | 2012-11-15 14:57:57 +0000 | [diff] [blame] | 137 | // The timed picture playback uses the SkPicturePlayback's profiling stubs |
| 138 | // to time individual commands. The offsets are needed to map SkPicture |
| 139 | // offsets to individual commands. |
| 140 | class SkTimedPicturePlayback : public SkPicturePlayback { |
| 141 | public: |
| 142 | SkTimedPicturePlayback(SkStream* stream, const SkPictInfo& info, bool* isValid, |
| 143 | SkSerializationHelpers::DecodeBitmap decoder, |
| skia.committer@gmail.com | 884e60b | 2012-11-16 02:01:17 +0000 | [diff] [blame] | 144 | const SkTDArray<size_t>& offsets) |
| robertphillips@google.com | 2bde91d | 2012-11-15 14:57:57 +0000 | [diff] [blame] | 145 | : INHERITED(stream, info, isValid, decoder) |
| 146 | , fTot(0.0) |
| 147 | , fCurCommand(0) |
| 148 | , fOffsets(offsets) { |
| 149 | fTimes.setCount(fOffsets.count()); |
| robertphillips@google.com | 8a1cdae | 2012-11-19 20:44:29 +0000 | [diff] [blame] | 150 | fTypeTimes.setCount(LAST_DRAWTYPE_ENUM+1); |
| 151 | this->resetTimes(); |
| 152 | } |
| 153 | |
| 154 | void resetTimes() { |
| robertphillips@google.com | 2bde91d | 2012-11-15 14:57:57 +0000 | [diff] [blame] | 155 | for (int i = 0; i < fOffsets.count(); ++i) { |
| robertphillips@google.com | 8a1cdae | 2012-11-19 20:44:29 +0000 | [diff] [blame] | 156 | fTimes[i] = 0.0; |
| robertphillips@google.com | 2bde91d | 2012-11-15 14:57:57 +0000 | [diff] [blame] | 157 | } |
| robertphillips@google.com | 8a1cdae | 2012-11-19 20:44:29 +0000 | [diff] [blame] | 158 | for (int i = 0; i < fTypeTimes.count(); ++i) { |
| 159 | fTypeTimes[i] = 0.0f; |
| 160 | } |
| 161 | fTot = 0.0; |
| robertphillips@google.com | 2bde91d | 2012-11-15 14:57:57 +0000 | [diff] [blame] | 162 | } |
| 163 | |
| 164 | int count() const { return fTimes.count(); } |
| 165 | |
| 166 | double time(int index) const { return fTimes[index] / fTot; } |
| 167 | |
| robertphillips@google.com | 8a1cdae | 2012-11-19 20:44:29 +0000 | [diff] [blame] | 168 | const SkTDArray<double>* typeTimes() const { return &fTypeTimes; } |
| 169 | |
| 170 | double totTime() const { return fTot; } |
| 171 | |
| robertphillips@google.com | 2bde91d | 2012-11-15 14:57:57 +0000 | [diff] [blame] | 172 | protected: |
| robertphillips@google.com | e174a8b | 2012-11-27 16:04:42 +0000 | [diff] [blame^] | 173 | BenchSysTimer fTimer; |
| robertphillips@google.com | 2bde91d | 2012-11-15 14:57:57 +0000 | [diff] [blame] | 174 | SkTDArray<size_t> fOffsets; // offset in the SkPicture for each command |
| 175 | SkTDArray<double> fTimes; // sum of time consumed for each command |
| robertphillips@google.com | 8a1cdae | 2012-11-19 20:44:29 +0000 | [diff] [blame] | 176 | SkTDArray<double> fTypeTimes; // sum of time consumed for each type of command (e.g., drawPath) |
| robertphillips@google.com | 2bde91d | 2012-11-15 14:57:57 +0000 | [diff] [blame] | 177 | double fTot; // total of all times in 'fTimes' |
| 178 | size_t fCurOffset; |
| robertphillips@google.com | 8a1cdae | 2012-11-19 20:44:29 +0000 | [diff] [blame] | 179 | int fCurType; |
| robertphillips@google.com | 2bde91d | 2012-11-15 14:57:57 +0000 | [diff] [blame] | 180 | int fCurCommand; // the current command being executed/timed |
| 181 | |
| 182 | virtual void preDraw(size_t offset, int type) { |
| skia.committer@gmail.com | 884e60b | 2012-11-16 02:01:17 +0000 | [diff] [blame] | 183 | // This search isn't as bad as it seems. In normal playback mode, the |
| robertphillips@google.com | 2bde91d | 2012-11-15 14:57:57 +0000 | [diff] [blame] | 184 | // base class steps through the commands in order and can only skip ahead |
| skia.committer@gmail.com | 884e60b | 2012-11-16 02:01:17 +0000 | [diff] [blame] | 185 | // a bit on a clip. This class is only used during profiling so we |
| robertphillips@google.com | 2bde91d | 2012-11-15 14:57:57 +0000 | [diff] [blame] | 186 | // don't have to worry about forward/backward scrubbing through commands. |
| 187 | for (int i = 0; offset != fOffsets[fCurCommand]; ++i) { |
| 188 | fCurCommand = (fCurCommand+1) % fOffsets.count(); |
| 189 | SkASSERT(i <= fOffsets.count()); // should always find the offset in the list |
| 190 | } |
| 191 | |
| 192 | fCurOffset = offset; |
| robertphillips@google.com | 8a1cdae | 2012-11-19 20:44:29 +0000 | [diff] [blame] | 193 | fCurType = type; |
| 194 | // The SkDebugCanvas doesn't recognize these types. This class needs to |
| 195 | // convert or else we'll wind up with a mismatch between the type counts |
| 196 | // the debugger displays and the profile times. |
| 197 | if (DRAW_POS_TEXT_TOP_BOTTOM == type) { |
| 198 | fCurType = DRAW_POS_TEXT; |
| 199 | } else if (DRAW_POS_TEXT_H_TOP_BOTTOM == type) { |
| 200 | fCurType = DRAW_POS_TEXT_H; |
| 201 | } |
| robertphillips@google.com | 2bde91d | 2012-11-15 14:57:57 +0000 | [diff] [blame] | 202 | |
| robertphillips@google.com | e174a8b | 2012-11-27 16:04:42 +0000 | [diff] [blame^] | 203 | #if defined(SK_BUILD_FOR_WIN32) |
| 204 | // CPU timer doesn't work well on Windows |
| 205 | fTimer.startWall(); |
| 206 | #else |
| 207 | fTimer.startCpu(); |
| 208 | #endif |
| robertphillips@google.com | 2bde91d | 2012-11-15 14:57:57 +0000 | [diff] [blame] | 209 | } |
| 210 | |
| 211 | virtual void postDraw(size_t offset) { |
| robertphillips@google.com | e174a8b | 2012-11-27 16:04:42 +0000 | [diff] [blame^] | 212 | #if defined(SK_BUILD_FOR_WIN32) |
| 213 | // CPU timer doesn't work well on Windows |
| 214 | double time = fTimer.endWall(); |
| 215 | #else |
| 216 | double time = fTimer.endCpu(); |
| 217 | #endif |
| robertphillips@google.com | 2bde91d | 2012-11-15 14:57:57 +0000 | [diff] [blame] | 218 | |
| 219 | SkASSERT(offset == fCurOffset); |
| robertphillips@google.com | 8a1cdae | 2012-11-19 20:44:29 +0000 | [diff] [blame] | 220 | SkASSERT(fCurType <= LAST_DRAWTYPE_ENUM); |
| robertphillips@google.com | 2bde91d | 2012-11-15 14:57:57 +0000 | [diff] [blame] | 221 | |
| robertphillips@google.com | e174a8b | 2012-11-27 16:04:42 +0000 | [diff] [blame^] | 222 | fTimes[fCurCommand] += time; |
| 223 | fTypeTimes[fCurType] += time; |
| 224 | fTot += time; |
| robertphillips@google.com | 2bde91d | 2012-11-15 14:57:57 +0000 | [diff] [blame] | 225 | } |
| 226 | |
| 227 | private: |
| 228 | typedef SkPicturePlayback INHERITED; |
| 229 | }; |
| 230 | |
| 231 | // Wrap SkPicture to allow installation of an SkTimedPicturePlayback object |
| 232 | class SkTimedPicture : public SkPicture { |
| 233 | public: |
| 234 | explicit SkTimedPicture(SkStream* stream, |
| 235 | bool* success, |
| 236 | SkSerializationHelpers::DecodeBitmap decoder, |
| 237 | const SkTDArray<size_t>& offsets) { |
| 238 | if (success) { |
| 239 | *success = false; |
| 240 | } |
| 241 | fRecord = NULL; |
| 242 | fPlayback = NULL; |
| 243 | fWidth = fHeight = 0; |
| 244 | |
| 245 | SkPictInfo info; |
| 246 | |
| 247 | if (!stream->read(&info, sizeof(info))) { |
| 248 | return; |
| 249 | } |
| 250 | if (SkPicture::PICTURE_VERSION != info.fVersion) { |
| 251 | return; |
| 252 | } |
| 253 | |
| 254 | if (stream->readBool()) { |
| 255 | bool isValid = false; |
| skia.committer@gmail.com | 884e60b | 2012-11-16 02:01:17 +0000 | [diff] [blame] | 256 | fPlayback = SkNEW_ARGS(SkTimedPicturePlayback, |
| robertphillips@google.com | 2bde91d | 2012-11-15 14:57:57 +0000 | [diff] [blame] | 257 | (stream, info, &isValid, decoder, offsets)); |
| 258 | if (!isValid) { |
| 259 | SkDELETE(fPlayback); |
| 260 | fPlayback = NULL; |
| 261 | return; |
| 262 | } |
| 263 | } |
| 264 | |
| 265 | // do this at the end, so that they will be zero if we hit an error. |
| 266 | fWidth = info.fWidth; |
| 267 | fHeight = info.fHeight; |
| 268 | if (success) { |
| 269 | *success = true; |
| 270 | } |
| 271 | } |
| 272 | |
| robertphillips@google.com | 8a1cdae | 2012-11-19 20:44:29 +0000 | [diff] [blame] | 273 | void resetTimes() { ((SkTimedPicturePlayback*) fPlayback)->resetTimes(); } |
| 274 | |
| robertphillips@google.com | 2bde91d | 2012-11-15 14:57:57 +0000 | [diff] [blame] | 275 | int count() const { return ((SkTimedPicturePlayback*) fPlayback)->count(); } |
| 276 | |
| 277 | // return the fraction of the total time this command consumed |
| 278 | double time(int index) const { return ((SkTimedPicturePlayback*) fPlayback)->time(index); } |
| 279 | |
| robertphillips@google.com | 8a1cdae | 2012-11-19 20:44:29 +0000 | [diff] [blame] | 280 | const SkTDArray<double>* typeTimes() const { return ((SkTimedPicturePlayback*) fPlayback)->typeTimes(); } |
| 281 | |
| 282 | double totTime() const { return ((SkTimedPicturePlayback*) fPlayback)->totTime(); } |
| 283 | |
| robertphillips@google.com | 2bde91d | 2012-11-15 14:57:57 +0000 | [diff] [blame] | 284 | private: |
| robertphillips@google.com | 8a1cdae | 2012-11-19 20:44:29 +0000 | [diff] [blame] | 285 | // disallow default ctor b.c. we don't have a good way to setup the fPlayback ptr |
| 286 | SkTimedPicture(); |
| 287 | // disallow the copy ctor - enabling would require copying code from SkPicture |
| 288 | SkTimedPicture(const SkTimedPicture& src); |
| 289 | |
| robertphillips@google.com | 2bde91d | 2012-11-15 14:57:57 +0000 | [diff] [blame] | 290 | typedef SkPicture INHERITED; |
| 291 | }; |
| 292 | |
| robertphillips@google.com | 8a1cdae | 2012-11-19 20:44:29 +0000 | [diff] [blame] | 293 | // This is a simplification of PictureBenchmark's run with the addition of |
| 294 | // clearing of the times after the first pass (in resetTimes) |
| skia.committer@gmail.com | 3458716 | 2012-11-20 02:01:23 +0000 | [diff] [blame] | 295 | void SkDebuggerGUI::run(SkTimedPicture* pict, |
| 296 | sk_tools::PictureRenderer* renderer, |
| robertphillips@google.com | 8a1cdae | 2012-11-19 20:44:29 +0000 | [diff] [blame] | 297 | int repeats) { |
| 298 | SkASSERT(pict); |
| 299 | if (NULL == pict) { |
| 300 | return; |
| 301 | } |
| 302 | |
| 303 | SkASSERT(renderer != NULL); |
| 304 | if (NULL == renderer) { |
| 305 | return; |
| 306 | } |
| 307 | |
| 308 | renderer->init(pict); |
| 309 | |
| 310 | renderer->setup(); |
| 311 | renderer->render(NULL); |
| 312 | renderer->resetState(); |
| 313 | |
| 314 | // We throw this away the first batch of times to remove first time effects (such as paging in this program) |
| 315 | pict->resetTimes(); |
| 316 | |
| 317 | for (int i = 0; i < repeats; ++i) { |
| 318 | renderer->setup(); |
| 319 | renderer->render(NULL); |
| 320 | renderer->resetState(); |
| 321 | } |
| 322 | |
| 323 | renderer->end(); |
| 324 | } |
| 325 | |
| robertphillips@google.com | d26c706 | 2012-11-12 20:42:12 +0000 | [diff] [blame] | 326 | void SkDebuggerGUI::actionProfile() { |
| robertphillips@google.com | 2bde91d | 2012-11-15 14:57:57 +0000 | [diff] [blame] | 327 | // In order to profile we pass the command offsets (that were read-in |
| 328 | // in loadPicture by the SkOffsetPicture) to an SkTimedPlaybackPicture. |
| skia.committer@gmail.com | 884e60b | 2012-11-16 02:01:17 +0000 | [diff] [blame] | 329 | // The SkTimedPlaybackPicture in turn passes the offsets to an |
| robertphillips@google.com | 2bde91d | 2012-11-15 14:57:57 +0000 | [diff] [blame] | 330 | // SkTimedPicturePlayback object which uses them to track the performance |
| 331 | // of individual commands. |
| 332 | if (fFileName.isEmpty()) { |
| 333 | return; |
| 334 | } |
| 335 | |
| 336 | SkFILEStream inputStream; |
| 337 | |
| 338 | inputStream.setPath(fFileName.c_str()); |
| 339 | if (!inputStream.isValid()) { |
| 340 | return; |
| 341 | } |
| 342 | |
| 343 | bool success = false; |
| 344 | SkTimedPicture picture(&inputStream, &success, &SkImageDecoder::DecodeStream, fOffsets); |
| 345 | if (!success) { |
| 346 | return; |
| 347 | } |
| 348 | |
| robertphillips@google.com | 8a1cdae | 2012-11-19 20:44:29 +0000 | [diff] [blame] | 349 | // For now this #if allows switching between tiled and simple rendering |
| 350 | // modes. Eventually this will be accomplished via the GUI |
| robertphillips@google.com | e174a8b | 2012-11-27 16:04:42 +0000 | [diff] [blame^] | 351 | #if 0 |
| 352 | // With the current batch of SysTimers, profiling in tiled mode |
| 353 | // gets swamped by the timing overhead: |
| 354 | // |
| 355 | // tile mode simple mode |
| 356 | // debugger 64.2ms 12.8ms |
| 357 | // bench_pictures 16.9ms 12.4ms |
| 358 | // |
| 359 | // This is b.c. in tiled mode each command is called many more times |
| 360 | // but typically does less work on each invocation (due to clipping) |
| robertphillips@google.com | 2bde91d | 2012-11-15 14:57:57 +0000 | [diff] [blame] | 361 | sk_tools::TiledPictureRenderer* renderer = NULL; |
| 362 | |
| 363 | renderer = SkNEW(sk_tools::TiledPictureRenderer); |
| 364 | renderer->setTileWidth(256); |
| 365 | renderer->setTileHeight(256); |
| robertphillips@google.com | 8a1cdae | 2012-11-19 20:44:29 +0000 | [diff] [blame] | 366 | #else |
| 367 | sk_tools::SimplePictureRenderer* renderer = NULL; |
| robertphillips@google.com | 2bde91d | 2012-11-15 14:57:57 +0000 | [diff] [blame] | 368 | |
| robertphillips@google.com | 8a1cdae | 2012-11-19 20:44:29 +0000 | [diff] [blame] | 369 | renderer = SkNEW(sk_tools::SimplePictureRenderer); |
| 370 | #endif |
| robertphillips@google.com | 2bde91d | 2012-11-15 14:57:57 +0000 | [diff] [blame] | 371 | |
| robertphillips@google.com | e174a8b | 2012-11-27 16:04:42 +0000 | [diff] [blame^] | 372 | static const int kNumRepeats = 10; |
| 373 | |
| 374 | run(&picture, renderer, kNumRepeats); |
| robertphillips@google.com | 2bde91d | 2012-11-15 14:57:57 +0000 | [diff] [blame] | 375 | |
| 376 | SkASSERT(picture.count() == fListWidget.count()); |
| 377 | |
| 378 | // extract the individual command times from the SkTimedPlaybackPicture |
| 379 | for (int i = 0; i < picture.count(); ++i) { |
| 380 | double temp = picture.time(i); |
| 381 | |
| 382 | QListWidgetItem* item = fListWidget.item(i); |
| 383 | |
| 384 | item->setData(Qt::UserRole + 4, 100.0*temp); |
| 385 | } |
| robertphillips@google.com | 8a1cdae | 2012-11-19 20:44:29 +0000 | [diff] [blame] | 386 | |
| 387 | setupOverviewText(picture.typeTimes(), picture.totTime()); |
| robertphillips@google.com | d26c706 | 2012-11-12 20:42:12 +0000 | [diff] [blame] | 388 | } |
| 389 | |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 390 | void SkDebuggerGUI::actionCancel() { |
| chudy@google.com | c432f00 | 2012-07-10 13:19:25 +0000 | [diff] [blame] | 391 | for (int row = 0; row < fListWidget.count(); row++) { |
| 392 | fListWidget.item(row)->setHidden(false); |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 393 | } |
| 394 | } |
| 395 | |
| chudy@google.com | 7e4cfbf | 2012-07-17 15:40:51 +0000 | [diff] [blame] | 396 | void SkDebuggerGUI::actionClearBreakpoints() { |
| 397 | for (int row = 0; row < fListWidget.count(); row++) { |
| 398 | QListWidgetItem* item = fListWidget.item(row); |
| 399 | item->setCheckState(Qt::Unchecked); |
| 400 | item->setData(Qt::DecorationRole, |
| robertphillips@google.com | 8e41a16 | 2012-11-19 17:39:18 +0000 | [diff] [blame] | 401 | QPixmap(":/blank.png")); |
| chudy@google.com | 7e4cfbf | 2012-07-17 15:40:51 +0000 | [diff] [blame] | 402 | } |
| 403 | } |
| 404 | |
| 405 | void SkDebuggerGUI::actionClearDeletes() { |
| 406 | for (int row = 0; row < fListWidget.count(); row++) { |
| 407 | QListWidgetItem* item = fListWidget.item(row); |
| robertphillips@google.com | 8e41a16 | 2012-11-19 17:39:18 +0000 | [diff] [blame] | 408 | item->setData(Qt::UserRole + 2, QPixmap(":/blank.png")); |
| chudy@google.com | 607357f | 2012-08-07 16:12:23 +0000 | [diff] [blame] | 409 | fDebugger.setCommandVisible(row, true); |
| chudy@google.com | 7e4cfbf | 2012-07-17 15:40:51 +0000 | [diff] [blame] | 410 | } |
| 411 | if (fPause) { |
| 412 | fCanvasWidget.drawTo(fPausedRow); |
| robertphillips@google.com | 6dec8fc | 2012-11-21 17:11:02 +0000 | [diff] [blame] | 413 | fImageWidget.draw(); |
| chudy@google.com | 7e4cfbf | 2012-07-17 15:40:51 +0000 | [diff] [blame] | 414 | } else { |
| 415 | fCanvasWidget.drawTo(fListWidget.currentRow()); |
| robertphillips@google.com | 6dec8fc | 2012-11-21 17:11:02 +0000 | [diff] [blame] | 416 | fImageWidget.draw(); |
| chudy@google.com | 7e4cfbf | 2012-07-17 15:40:51 +0000 | [diff] [blame] | 417 | } |
| 418 | } |
| 419 | |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 420 | void SkDebuggerGUI::actionCommandFilter() { |
| chudy@google.com | 607357f | 2012-08-07 16:12:23 +0000 | [diff] [blame] | 421 | fDebugger.highlightCurrentCommand( |
| chudy@google.com | c432f00 | 2012-07-10 13:19:25 +0000 | [diff] [blame] | 422 | fSettingsWidget.getVisibilityButton()->isChecked()); |
| 423 | fCanvasWidget.drawTo(fListWidget.currentRow()); |
| robertphillips@google.com | 6dec8fc | 2012-11-21 17:11:02 +0000 | [diff] [blame] | 424 | fImageWidget.draw(); |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 425 | } |
| 426 | |
| 427 | void SkDebuggerGUI::actionClose() { |
| 428 | this->close(); |
| 429 | } |
| 430 | |
| 431 | void SkDebuggerGUI::actionDelete() { |
| chudy@google.com | c432f00 | 2012-07-10 13:19:25 +0000 | [diff] [blame] | 432 | int currentRow = fListWidget.currentRow(); |
| chudy@google.com | 7e4cfbf | 2012-07-17 15:40:51 +0000 | [diff] [blame] | 433 | QListWidgetItem* item = fListWidget.currentItem(); |
| 434 | |
| chudy@google.com | 607357f | 2012-08-07 16:12:23 +0000 | [diff] [blame] | 435 | if (fDebugger.isCommandVisible(currentRow)) { |
| robertphillips@google.com | 8e41a16 | 2012-11-19 17:39:18 +0000 | [diff] [blame] | 436 | item->setData(Qt::UserRole + 2, QPixmap(":/delete.png")); |
| chudy@google.com | 607357f | 2012-08-07 16:12:23 +0000 | [diff] [blame] | 437 | fDebugger.setCommandVisible(currentRow, false); |
| chudy@google.com | 7e4cfbf | 2012-07-17 15:40:51 +0000 | [diff] [blame] | 438 | } else { |
| robertphillips@google.com | 8e41a16 | 2012-11-19 17:39:18 +0000 | [diff] [blame] | 439 | item->setData(Qt::UserRole + 2, QPixmap(":/blank.png")); |
| chudy@google.com | 607357f | 2012-08-07 16:12:23 +0000 | [diff] [blame] | 440 | fDebugger.setCommandVisible(currentRow, true); |
| chudy@google.com | 7e4cfbf | 2012-07-17 15:40:51 +0000 | [diff] [blame] | 441 | } |
| 442 | |
| chudy@google.com | e504de0 | 2012-07-16 18:35:23 +0000 | [diff] [blame] | 443 | if (fPause) { |
| 444 | fCanvasWidget.drawTo(fPausedRow); |
| robertphillips@google.com | 6dec8fc | 2012-11-21 17:11:02 +0000 | [diff] [blame] | 445 | fImageWidget.draw(); |
| chudy@google.com | e504de0 | 2012-07-16 18:35:23 +0000 | [diff] [blame] | 446 | } else { |
| 447 | fCanvasWidget.drawTo(currentRow); |
| robertphillips@google.com | 6dec8fc | 2012-11-21 17:11:02 +0000 | [diff] [blame] | 448 | fImageWidget.draw(); |
| chudy@google.com | e504de0 | 2012-07-16 18:35:23 +0000 | [diff] [blame] | 449 | } |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 450 | } |
| 451 | |
| chudy@google.com | ea5488b | 2012-07-26 19:38:22 +0000 | [diff] [blame] | 452 | void SkDebuggerGUI::actionGLWidget(bool isToggled) { |
| 453 | fCanvasWidget.setWidgetVisibility(SkCanvasWidget::kGPU_WidgetType, !isToggled); |
| 454 | } |
| 455 | |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 456 | void SkDebuggerGUI::actionInspector() { |
| chudy@google.com | c432f00 | 2012-07-10 13:19:25 +0000 | [diff] [blame] | 457 | if (fInspectorWidget.isHidden()) { |
| 458 | fInspectorWidget.setHidden(false); |
| robertphillips@google.com | 6dec8fc | 2012-11-21 17:11:02 +0000 | [diff] [blame] | 459 | fImageWidget.setHidden(false); |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 460 | } else { |
| chudy@google.com | c432f00 | 2012-07-10 13:19:25 +0000 | [diff] [blame] | 461 | fInspectorWidget.setHidden(true); |
| robertphillips@google.com | 6dec8fc | 2012-11-21 17:11:02 +0000 | [diff] [blame] | 462 | fImageWidget.setHidden(true); |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 463 | } |
| 464 | } |
| 465 | |
| 466 | void SkDebuggerGUI::actionPlay() { |
| chudy@google.com | c432f00 | 2012-07-10 13:19:25 +0000 | [diff] [blame] | 467 | for (int row = fListWidget.currentRow() + 1; row < fListWidget.count(); |
| chudy@google.com | 7dcae67 | 2012-07-09 20:26:53 +0000 | [diff] [blame] | 468 | row++) { |
| chudy@google.com | c432f00 | 2012-07-10 13:19:25 +0000 | [diff] [blame] | 469 | QListWidgetItem *item = fListWidget.item(row); |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 470 | if (item->checkState() == Qt::Checked) { |
| chudy@google.com | c432f00 | 2012-07-10 13:19:25 +0000 | [diff] [blame] | 471 | fListWidget.setCurrentItem(item); |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 472 | return; |
| 473 | } |
| 474 | } |
| chudy@google.com | c432f00 | 2012-07-10 13:19:25 +0000 | [diff] [blame] | 475 | fListWidget.setCurrentRow(fListWidget.count() - 1); |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 476 | } |
| 477 | |
| chudy@google.com | ea5488b | 2012-07-26 19:38:22 +0000 | [diff] [blame] | 478 | void SkDebuggerGUI::actionRasterWidget(bool isToggled) { |
| 479 | fCanvasWidget.setWidgetVisibility(SkCanvasWidget::kRaster_8888_WidgetType, !isToggled); |
| 480 | } |
| 481 | |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 482 | void SkDebuggerGUI::actionRewind() { |
| chudy@google.com | e504de0 | 2012-07-16 18:35:23 +0000 | [diff] [blame] | 483 | fListWidget.setCurrentRow(0); |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 484 | } |
| 485 | |
| chudy@google.com | 0ab0339 | 2012-07-28 20:16:11 +0000 | [diff] [blame] | 486 | void SkDebuggerGUI::actionSave() { |
| robertphillips@google.com | d26c706 | 2012-11-12 20:42:12 +0000 | [diff] [blame] | 487 | fFileName = fPath.toAscii(); |
| 488 | fFileName.append("/"); |
| 489 | fFileName.append(fDirectoryWidget.currentItem()->text().toAscii()); |
| 490 | saveToFile(fFileName); |
| chudy@google.com | 0ab0339 | 2012-07-28 20:16:11 +0000 | [diff] [blame] | 491 | } |
| 492 | |
| 493 | void SkDebuggerGUI::actionSaveAs() { |
| 494 | QString filename = QFileDialog::getSaveFileName(this, "Save File", "", |
| 495 | "Skia Picture (*skp)"); |
| chudy@google.com | 38b08ce | 2012-07-28 23:26:10 +0000 | [diff] [blame] | 496 | if (!filename.endsWith(".skp", Qt::CaseInsensitive)) { |
| chudy@google.com | 0ab0339 | 2012-07-28 20:16:11 +0000 | [diff] [blame] | 497 | filename.append(".skp"); |
| 498 | } |
| djsollen@google.com | c3c8216 | 2012-11-13 18:35:10 +0000 | [diff] [blame] | 499 | saveToFile(SkString(filename.toAscii().data())); |
| chudy@google.com | 0ab0339 | 2012-07-28 20:16:11 +0000 | [diff] [blame] | 500 | } |
| 501 | |
| chudy@google.com | 7dcae67 | 2012-07-09 20:26:53 +0000 | [diff] [blame] | 502 | void SkDebuggerGUI::actionScale(float scaleFactor) { |
| chudy@google.com | c432f00 | 2012-07-10 13:19:25 +0000 | [diff] [blame] | 503 | fSettingsWidget.setZoomText(scaleFactor); |
| chudy@google.com | 7dcae67 | 2012-07-09 20:26:53 +0000 | [diff] [blame] | 504 | } |
| 505 | |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 506 | void SkDebuggerGUI::actionSettings() { |
| chudy@google.com | c432f00 | 2012-07-10 13:19:25 +0000 | [diff] [blame] | 507 | if (fSettingsWidget.isHidden()) { |
| 508 | fSettingsWidget.setHidden(false); |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 509 | } else { |
| chudy@google.com | c432f00 | 2012-07-10 13:19:25 +0000 | [diff] [blame] | 510 | fSettingsWidget.setHidden(true); |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 511 | } |
| 512 | } |
| 513 | |
| 514 | void SkDebuggerGUI::actionStepBack() { |
| chudy@google.com | c432f00 | 2012-07-10 13:19:25 +0000 | [diff] [blame] | 515 | int currentRow = fListWidget.currentRow(); |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 516 | if (currentRow != 0) { |
| chudy@google.com | c432f00 | 2012-07-10 13:19:25 +0000 | [diff] [blame] | 517 | fListWidget.setCurrentRow(currentRow - 1); |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 518 | } |
| 519 | } |
| 520 | |
| 521 | void SkDebuggerGUI::actionStepForward() { |
| chudy@google.com | c432f00 | 2012-07-10 13:19:25 +0000 | [diff] [blame] | 522 | int currentRow = fListWidget.currentRow(); |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 523 | QString curRow = QString::number(currentRow); |
| chudy@google.com | c432f00 | 2012-07-10 13:19:25 +0000 | [diff] [blame] | 524 | QString curCount = QString::number(fListWidget.count()); |
| 525 | if (currentRow < fListWidget.count() - 1) { |
| 526 | fListWidget.setCurrentRow(currentRow + 1); |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 527 | } |
| 528 | } |
| 529 | |
| chudy@google.com | a9e937c | 2012-08-03 17:32:05 +0000 | [diff] [blame] | 530 | void SkDebuggerGUI::drawComplete() { |
| chudy@google.com | 607357f | 2012-08-07 16:12:23 +0000 | [diff] [blame] | 531 | fInspectorWidget.setMatrix(fDebugger.getCurrentMatrix()); |
| 532 | fInspectorWidget.setClip(fDebugger.getCurrentClip()); |
| chudy@google.com | a9e937c | 2012-08-03 17:32:05 +0000 | [diff] [blame] | 533 | } |
| 534 | |
| robertphillips@google.com | d26c706 | 2012-11-12 20:42:12 +0000 | [diff] [blame] | 535 | void SkDebuggerGUI::saveToFile(const SkString& filename) { |
| 536 | SkFILEWStream file(filename.c_str()); |
| chudy@google.com | 607357f | 2012-08-07 16:12:23 +0000 | [diff] [blame] | 537 | fDebugger.makePicture()->serialize(&file); |
| chudy@google.com | 0ab0339 | 2012-07-28 20:16:11 +0000 | [diff] [blame] | 538 | } |
| 539 | |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 540 | void SkDebuggerGUI::loadFile(QListWidgetItem *item) { |
| 541 | if (fDirectoryWidgetActive) { |
| robertphillips@google.com | d26c706 | 2012-11-12 20:42:12 +0000 | [diff] [blame] | 542 | fFileName = fPath.toAscii(); |
| 543 | fFileName.append("/"); |
| 544 | fFileName.append(item->text().toAscii()); |
| 545 | loadPicture(fFileName); |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 546 | } |
| 547 | } |
| 548 | |
| 549 | void SkDebuggerGUI::openFile() { |
| robertphillips@google.com | d26c706 | 2012-11-12 20:42:12 +0000 | [diff] [blame] | 550 | QString temp = QFileDialog::getOpenFileName(this, tr("Open File"), "", |
| chudy@google.com | 7dcae67 | 2012-07-09 20:26:53 +0000 | [diff] [blame] | 551 | tr("Files (*.*)")); |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 552 | fDirectoryWidgetActive = false; |
| robertphillips@google.com | d26c706 | 2012-11-12 20:42:12 +0000 | [diff] [blame] | 553 | if (!temp.isEmpty()) { |
| 554 | QFileInfo pathInfo(temp); |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 555 | fPath = pathInfo.path(); |
| djsollen@google.com | c3c8216 | 2012-11-13 18:35:10 +0000 | [diff] [blame] | 556 | loadPicture(SkString(temp.toAscii().data())); |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 557 | setupDirectoryWidget(); |
| 558 | } |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 559 | fDirectoryWidgetActive = true; |
| 560 | } |
| 561 | |
| chudy@google.com | c432f00 | 2012-07-10 13:19:25 +0000 | [diff] [blame] | 562 | void SkDebuggerGUI::pauseDrawing(bool isPaused) { |
| chudy@google.com | 607357f | 2012-08-07 16:12:23 +0000 | [diff] [blame] | 563 | fPause = isPaused; |
| 564 | fPausedRow = fListWidget.currentRow(); |
| 565 | fCanvasWidget.drawTo(fPausedRow); |
| robertphillips@google.com | 6dec8fc | 2012-11-21 17:11:02 +0000 | [diff] [blame] | 566 | fImageWidget.draw(); |
| chudy@google.com | 7dcae67 | 2012-07-09 20:26:53 +0000 | [diff] [blame] | 567 | } |
| 568 | |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 569 | void SkDebuggerGUI::registerListClick(QListWidgetItem *item) { |
| chudy@google.com | d3058f5 | 2012-07-19 13:41:27 +0000 | [diff] [blame] | 570 | if(!fLoading) { |
| 571 | int currentRow = fListWidget.currentRow(); |
| chudy@google.com | d3058f5 | 2012-07-19 13:41:27 +0000 | [diff] [blame] | 572 | |
| chudy@google.com | ea5488b | 2012-07-26 19:38:22 +0000 | [diff] [blame] | 573 | if (currentRow != -1) { |
| 574 | if (!fPause) { |
| 575 | fCanvasWidget.drawTo(currentRow); |
| robertphillips@google.com | 6dec8fc | 2012-11-21 17:11:02 +0000 | [diff] [blame] | 576 | fImageWidget.draw(); |
| chudy@google.com | d3058f5 | 2012-07-19 13:41:27 +0000 | [diff] [blame] | 577 | } |
| chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 578 | SkTDArray<SkString*> *currInfo = fDebugger.getCommandInfo( |
| chudy@google.com | ea5488b | 2012-07-26 19:38:22 +0000 | [diff] [blame] | 579 | currentRow); |
| 580 | |
| 581 | /* TODO(chudy): Add command type before parameters. Rename v |
| 582 | * to something more informative. */ |
| chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 583 | if (currInfo) { |
| chudy@google.com | ea5488b | 2012-07-26 19:38:22 +0000 | [diff] [blame] | 584 | QString info; |
| 585 | info.append("<b>Parameters: </b><br/>"); |
| chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 586 | for (int i = 0; i < currInfo->count(); i++) { |
| 587 | |
| 588 | info.append(QString((*currInfo)[i]->c_str())); |
| chudy@google.com | ea5488b | 2012-07-26 19:38:22 +0000 | [diff] [blame] | 589 | info.append("<br/>"); |
| 590 | } |
| chudy@google.com | 6bd109a | 2012-08-14 19:34:13 +0000 | [diff] [blame] | 591 | fInspectorWidget.setText(info, SkInspectorWidget::kDetail_TabType); |
| chudy@google.com | ea5488b | 2012-07-26 19:38:22 +0000 | [diff] [blame] | 592 | fInspectorWidget.setDisabled(false); |
| chudy@google.com | ea5488b | 2012-07-26 19:38:22 +0000 | [diff] [blame] | 593 | } |
| chudy@google.com | d3058f5 | 2012-07-19 13:41:27 +0000 | [diff] [blame] | 594 | } |
| chudy@google.com | ea5488b | 2012-07-26 19:38:22 +0000 | [diff] [blame] | 595 | |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 596 | } |
| 597 | } |
| 598 | |
| chudy@google.com | 9ca9bfe | 2012-07-12 21:58:14 +0000 | [diff] [blame] | 599 | void SkDebuggerGUI::selectCommand(int command) { |
| 600 | if (fPause) { |
| 601 | fListWidget.setCurrentRow(command); |
| 602 | } |
| 603 | } |
| 604 | |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 605 | void SkDebuggerGUI::toggleBreakpoint() { |
| chudy@google.com | c432f00 | 2012-07-10 13:19:25 +0000 | [diff] [blame] | 606 | QListWidgetItem* item = fListWidget.currentItem(); |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 607 | if (item->checkState() == Qt::Unchecked) { |
| 608 | item->setCheckState(Qt::Checked); |
| chudy@google.com | e565de4 | 2012-07-12 14:15:54 +0000 | [diff] [blame] | 609 | item->setData(Qt::DecorationRole, |
| robertphillips@google.com | 8e41a16 | 2012-11-19 17:39:18 +0000 | [diff] [blame] | 610 | QPixmap(":/breakpoint_16x16.png")); |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 611 | } else { |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 612 | item->setCheckState(Qt::Unchecked); |
| chudy@google.com | e565de4 | 2012-07-12 14:15:54 +0000 | [diff] [blame] | 613 | item->setData(Qt::DecorationRole, |
| robertphillips@google.com | 8e41a16 | 2012-11-19 17:39:18 +0000 | [diff] [blame] | 614 | QPixmap(":/blank.png")); |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 615 | } |
| 616 | } |
| 617 | |
| 618 | void SkDebuggerGUI::toggleDirectory() { |
| chudy@google.com | 607357f | 2012-08-07 16:12:23 +0000 | [diff] [blame] | 619 | fDirectoryWidget.setHidden(!fDirectoryWidget.isHidden()); |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 620 | } |
| 621 | |
| 622 | void SkDebuggerGUI::toggleFilter(QString string) { |
| chudy@google.com | c432f00 | 2012-07-10 13:19:25 +0000 | [diff] [blame] | 623 | for (int row = 0; row < fListWidget.count(); row++) { |
| 624 | QListWidgetItem *item = fListWidget.item(row); |
| chudy@google.com | 607357f | 2012-08-07 16:12:23 +0000 | [diff] [blame] | 625 | item->setHidden(item->text() != string); |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 626 | } |
| 627 | } |
| 628 | |
| 629 | void SkDebuggerGUI::setupUi(QMainWindow *SkDebuggerGUI) { |
| 630 | QIcon windowIcon; |
| robertphillips@google.com | 8e41a16 | 2012-11-19 17:39:18 +0000 | [diff] [blame] | 631 | windowIcon.addFile(QString::fromUtf8(":/skia.png"), QSize(), |
| chudy@google.com | 7dcae67 | 2012-07-09 20:26:53 +0000 | [diff] [blame] | 632 | QIcon::Normal, QIcon::Off); |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 633 | SkDebuggerGUI->setObjectName(QString::fromUtf8("SkDebuggerGUI")); |
| 634 | SkDebuggerGUI->resize(1200, 1000); |
| 635 | SkDebuggerGUI->setWindowIcon(windowIcon); |
| chudy@google.com | c432f00 | 2012-07-10 13:19:25 +0000 | [diff] [blame] | 636 | SkDebuggerGUI->setWindowTitle("Skia Debugger"); |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 637 | |
| chudy@google.com | e504de0 | 2012-07-16 18:35:23 +0000 | [diff] [blame] | 638 | fActionOpen.setShortcuts(QKeySequence::Open); |
| chudy@google.com | c432f00 | 2012-07-10 13:19:25 +0000 | [diff] [blame] | 639 | fActionOpen.setText("Open"); |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 640 | |
| 641 | QIcon breakpoint; |
| robertphillips@google.com | 8e41a16 | 2012-11-19 17:39:18 +0000 | [diff] [blame] | 642 | breakpoint.addFile(QString::fromUtf8(":/breakpoint.png"), |
| chudy@google.com | 7dcae67 | 2012-07-09 20:26:53 +0000 | [diff] [blame] | 643 | QSize(), QIcon::Normal, QIcon::Off); |
| chudy@google.com | e504de0 | 2012-07-16 18:35:23 +0000 | [diff] [blame] | 644 | fActionBreakpoint.setShortcut(QKeySequence(tr("Ctrl+B"))); |
| chudy@google.com | c432f00 | 2012-07-10 13:19:25 +0000 | [diff] [blame] | 645 | fActionBreakpoint.setIcon(breakpoint); |
| chudy@google.com | 7e4cfbf | 2012-07-17 15:40:51 +0000 | [diff] [blame] | 646 | fActionBreakpoint.setText("Breakpoints"); |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 647 | |
| 648 | QIcon cancel; |
| robertphillips@google.com | 8e41a16 | 2012-11-19 17:39:18 +0000 | [diff] [blame] | 649 | cancel.addFile(QString::fromUtf8(":/reload.png"), QSize(), |
| chudy@google.com | 7dcae67 | 2012-07-09 20:26:53 +0000 | [diff] [blame] | 650 | QIcon::Normal, QIcon::Off); |
| chudy@google.com | c432f00 | 2012-07-10 13:19:25 +0000 | [diff] [blame] | 651 | fActionCancel.setIcon(cancel); |
| 652 | fActionCancel.setText("Clear Filter"); |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 653 | |
| chudy@google.com | 7e4cfbf | 2012-07-17 15:40:51 +0000 | [diff] [blame] | 654 | fActionClearBreakpoints.setShortcut(QKeySequence(tr("Alt+B"))); |
| 655 | fActionClearBreakpoints.setText("Clear Breakpoints"); |
| 656 | |
| 657 | fActionClearDeletes.setShortcut(QKeySequence(tr("Alt+X"))); |
| 658 | fActionClearDeletes.setText("Clear Deletes"); |
| 659 | |
| chudy@google.com | e504de0 | 2012-07-16 18:35:23 +0000 | [diff] [blame] | 660 | fActionClose.setShortcuts(QKeySequence::Quit); |
| chudy@google.com | c432f00 | 2012-07-10 13:19:25 +0000 | [diff] [blame] | 661 | fActionClose.setText("Exit"); |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 662 | |
| chudy@google.com | e504de0 | 2012-07-16 18:35:23 +0000 | [diff] [blame] | 663 | fActionCreateBreakpoint.setShortcut(QKeySequence(tr("B"))); |
| 664 | fActionCreateBreakpoint.setText("Set Breakpoint"); |
| 665 | |
| 666 | fActionDelete.setShortcut(QKeySequence(tr("X"))); |
| chudy@google.com | c432f00 | 2012-07-10 13:19:25 +0000 | [diff] [blame] | 667 | fActionDelete.setText("Delete Command"); |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 668 | |
| chudy@google.com | e504de0 | 2012-07-16 18:35:23 +0000 | [diff] [blame] | 669 | fActionDirectory.setShortcut(QKeySequence(tr("Ctrl+D"))); |
| 670 | fActionDirectory.setText("Directory"); |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 671 | |
| robertphillips@google.com | d26c706 | 2012-11-12 20:42:12 +0000 | [diff] [blame] | 672 | QIcon profile; |
| robertphillips@google.com | d163636 | 2012-11-19 18:25:09 +0000 | [diff] [blame] | 673 | profile.addFile(QString::fromUtf8(":/profile.png"), QSize(), |
| robertphillips@google.com | d26c706 | 2012-11-12 20:42:12 +0000 | [diff] [blame] | 674 | QIcon::Normal, QIcon::Off); |
| 675 | fActionProfile.setIcon(profile); |
| 676 | fActionProfile.setText("Profile"); |
| robertphillips@google.com | e099bc4 | 2012-11-19 16:26:40 +0000 | [diff] [blame] | 677 | fActionProfile.setDisabled(true); |
| robertphillips@google.com | d26c706 | 2012-11-12 20:42:12 +0000 | [diff] [blame] | 678 | |
| chudy@google.com | c432f00 | 2012-07-10 13:19:25 +0000 | [diff] [blame] | 679 | QIcon inspector; |
| robertphillips@google.com | d163636 | 2012-11-19 18:25:09 +0000 | [diff] [blame] | 680 | inspector.addFile(QString::fromUtf8(":/inspector.png"), |
| chudy@google.com | c432f00 | 2012-07-10 13:19:25 +0000 | [diff] [blame] | 681 | QSize(), QIcon::Normal, QIcon::Off); |
| chudy@google.com | e504de0 | 2012-07-16 18:35:23 +0000 | [diff] [blame] | 682 | fActionInspector.setShortcut(QKeySequence(tr("Ctrl+I"))); |
| chudy@google.com | c432f00 | 2012-07-10 13:19:25 +0000 | [diff] [blame] | 683 | fActionInspector.setIcon(inspector); |
| chudy@google.com | e504de0 | 2012-07-16 18:35:23 +0000 | [diff] [blame] | 684 | fActionInspector.setText("Inspector"); |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 685 | |
| chudy@google.com | c432f00 | 2012-07-10 13:19:25 +0000 | [diff] [blame] | 686 | QIcon play; |
| robertphillips@google.com | d163636 | 2012-11-19 18:25:09 +0000 | [diff] [blame] | 687 | play.addFile(QString::fromUtf8(":/play.png"), QSize(), |
| chudy@google.com | c432f00 | 2012-07-10 13:19:25 +0000 | [diff] [blame] | 688 | QIcon::Normal, QIcon::Off); |
| chudy@google.com | e504de0 | 2012-07-16 18:35:23 +0000 | [diff] [blame] | 689 | fActionPlay.setShortcut(QKeySequence(tr("Ctrl+P"))); |
| chudy@google.com | c432f00 | 2012-07-10 13:19:25 +0000 | [diff] [blame] | 690 | fActionPlay.setIcon(play); |
| 691 | fActionPlay.setText("Play"); |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 692 | |
| chudy@google.com | e504de0 | 2012-07-16 18:35:23 +0000 | [diff] [blame] | 693 | QIcon pause; |
| robertphillips@google.com | d163636 | 2012-11-19 18:25:09 +0000 | [diff] [blame] | 694 | pause.addFile(QString::fromUtf8(":/pause.png"), QSize(), |
| chudy@google.com | c432f00 | 2012-07-10 13:19:25 +0000 | [diff] [blame] | 695 | QIcon::Normal, QIcon::Off); |
| chudy@google.com | e504de0 | 2012-07-16 18:35:23 +0000 | [diff] [blame] | 696 | fActionPause.setShortcut(QKeySequence(tr("Space"))); |
| 697 | fActionPause.setCheckable(true); |
| 698 | fActionPause.setIcon(pause); |
| 699 | fActionPause.setText("Pause"); |
| 700 | |
| chudy@google.com | c432f00 | 2012-07-10 13:19:25 +0000 | [diff] [blame] | 701 | QIcon rewind; |
| robertphillips@google.com | 8e41a16 | 2012-11-19 17:39:18 +0000 | [diff] [blame] | 702 | rewind.addFile(QString::fromUtf8(":/rewind.png"), QSize(), |
| chudy@google.com | c432f00 | 2012-07-10 13:19:25 +0000 | [diff] [blame] | 703 | QIcon::Normal, QIcon::Off); |
| chudy@google.com | e504de0 | 2012-07-16 18:35:23 +0000 | [diff] [blame] | 704 | fActionRewind.setShortcut(QKeySequence(tr("Ctrl+R"))); |
| chudy@google.com | c432f00 | 2012-07-10 13:19:25 +0000 | [diff] [blame] | 705 | fActionRewind.setIcon(rewind); |
| 706 | fActionRewind.setText("Rewind"); |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 707 | |
| chudy@google.com | 0ab0339 | 2012-07-28 20:16:11 +0000 | [diff] [blame] | 708 | fActionSave.setShortcut(QKeySequence::Save); |
| 709 | fActionSave.setText("Save"); |
| 710 | fActionSave.setDisabled(true); |
| 711 | fActionSaveAs.setShortcut(QKeySequence::SaveAs); |
| 712 | fActionSaveAs.setText("Save As"); |
| 713 | fActionSaveAs.setDisabled(true); |
| 714 | |
| chudy@google.com | 7e4cfbf | 2012-07-17 15:40:51 +0000 | [diff] [blame] | 715 | fActionShowDeletes.setShortcut(QKeySequence(tr("Ctrl+X"))); |
| 716 | fActionShowDeletes.setText("Deleted Commands"); |
| 717 | |
| chudy@google.com | c432f00 | 2012-07-10 13:19:25 +0000 | [diff] [blame] | 718 | QIcon stepBack; |
| robertphillips@google.com | 8e41a16 | 2012-11-19 17:39:18 +0000 | [diff] [blame] | 719 | stepBack.addFile(QString::fromUtf8(":/previous.png"), QSize(), |
| chudy@google.com | c432f00 | 2012-07-10 13:19:25 +0000 | [diff] [blame] | 720 | QIcon::Normal, QIcon::Off); |
| chudy@google.com | e504de0 | 2012-07-16 18:35:23 +0000 | [diff] [blame] | 721 | fActionStepBack.setShortcut(QKeySequence(tr("["))); |
| chudy@google.com | c432f00 | 2012-07-10 13:19:25 +0000 | [diff] [blame] | 722 | fActionStepBack.setIcon(stepBack); |
| 723 | fActionStepBack.setText("Step Back"); |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 724 | |
| chudy@google.com | c432f00 | 2012-07-10 13:19:25 +0000 | [diff] [blame] | 725 | QIcon stepForward; |
| robertphillips@google.com | 8e41a16 | 2012-11-19 17:39:18 +0000 | [diff] [blame] | 726 | stepForward.addFile(QString::fromUtf8(":/next.png"), |
| chudy@google.com | c432f00 | 2012-07-10 13:19:25 +0000 | [diff] [blame] | 727 | QSize(), QIcon::Normal, QIcon::Off); |
| chudy@google.com | e504de0 | 2012-07-16 18:35:23 +0000 | [diff] [blame] | 728 | fActionStepForward.setShortcut(QKeySequence(tr("]"))); |
| chudy@google.com | c432f00 | 2012-07-10 13:19:25 +0000 | [diff] [blame] | 729 | fActionStepForward.setIcon(stepForward); |
| 730 | fActionStepForward.setText("Step Forward"); |
| 731 | |
| chudy@google.com | a122631 | 2012-07-26 20:26:44 +0000 | [diff] [blame] | 732 | fActionZoomIn.setShortcut(QKeySequence(tr("Ctrl+="))); |
| 733 | fActionZoomIn.setText("Zoom In"); |
| 734 | fActionZoomOut.setShortcut(QKeySequence(tr("Ctrl+-"))); |
| 735 | fActionZoomOut.setText("Zoom Out"); |
| 736 | |
| chudy@google.com | c432f00 | 2012-07-10 13:19:25 +0000 | [diff] [blame] | 737 | fListWidget.setItemDelegate(new SkListWidget(&fListWidget)); |
| 738 | fListWidget.setObjectName(QString::fromUtf8("listWidget")); |
| 739 | fListWidget.setMaximumWidth(250); |
| 740 | |
| 741 | fFilter.addItem("--Filter By Available Commands--"); |
| 742 | |
| 743 | fDirectoryWidget.setMaximumWidth(250); |
| 744 | fDirectoryWidget.setStyleSheet("QListWidget::Item {padding: 5px;}"); |
| 745 | |
| 746 | fCanvasWidget.setSizePolicy(QSizePolicy::Expanding, |
| chudy@google.com | 7dcae67 | 2012-07-09 20:26:53 +0000 | [diff] [blame] | 747 | QSizePolicy::Expanding); |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 748 | |
| skia.committer@gmail.com | 1c9c0d3 | 2012-11-22 02:02:41 +0000 | [diff] [blame] | 749 | fImageWidget.setFixedSize(SkImageWidget::kImageWidgetWidth, |
| robertphillips@google.com | 6dec8fc | 2012-11-21 17:11:02 +0000 | [diff] [blame] | 750 | SkImageWidget::kImageWidgetHeight); |
| 751 | |
| chudy@google.com | c432f00 | 2012-07-10 13:19:25 +0000 | [diff] [blame] | 752 | fInspectorWidget.setSizePolicy(QSizePolicy::Expanding, |
| chudy@google.com | 7dcae67 | 2012-07-09 20:26:53 +0000 | [diff] [blame] | 753 | QSizePolicy::Expanding); |
| chudy@google.com | c432f00 | 2012-07-10 13:19:25 +0000 | [diff] [blame] | 754 | fInspectorWidget.setMaximumHeight(300); |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 755 | |
| robertphillips@google.com | 6dec8fc | 2012-11-21 17:11:02 +0000 | [diff] [blame] | 756 | fSettingsAndImageLayout.setSpacing(6); |
| 757 | fSettingsAndImageLayout.addWidget(&fSettingsWidget); |
| 758 | fSettingsAndImageLayout.addWidget(&fImageWidget); |
| 759 | |
| chudy@google.com | c432f00 | 2012-07-10 13:19:25 +0000 | [diff] [blame] | 760 | fSettingsWidget.setSizePolicy(QSizePolicy::Expanding, |
| 761 | QSizePolicy::Expanding); |
| 762 | fSettingsWidget.setMaximumWidth(250); |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 763 | |
| chudy@google.com | c432f00 | 2012-07-10 13:19:25 +0000 | [diff] [blame] | 764 | fLeftColumnLayout.setSpacing(6); |
| 765 | fLeftColumnLayout.addWidget(&fListWidget); |
| 766 | fLeftColumnLayout.addWidget(&fDirectoryWidget); |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 767 | |
| robertphillips@google.com | 6dec8fc | 2012-11-21 17:11:02 +0000 | [diff] [blame] | 768 | fCanvasSettingsAndImageLayout.setSpacing(6); |
| 769 | fCanvasSettingsAndImageLayout.addWidget(&fCanvasWidget); |
| 770 | fCanvasSettingsAndImageLayout.addLayout(&fSettingsAndImageLayout); |
| 771 | |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 772 | |
| chudy@google.com | c432f00 | 2012-07-10 13:19:25 +0000 | [diff] [blame] | 773 | fMainAndRightColumnLayout.setSpacing(6); |
| robertphillips@google.com | 6dec8fc | 2012-11-21 17:11:02 +0000 | [diff] [blame] | 774 | fMainAndRightColumnLayout.addLayout(&fCanvasSettingsAndImageLayout); |
| chudy@google.com | c432f00 | 2012-07-10 13:19:25 +0000 | [diff] [blame] | 775 | fMainAndRightColumnLayout.addWidget(&fInspectorWidget); |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 776 | |
| chudy@google.com | 2d537a1 | 2012-07-31 12:49:52 +0000 | [diff] [blame] | 777 | fCentralWidget.setLayout(&fContainerLayout); |
| chudy@google.com | c432f00 | 2012-07-10 13:19:25 +0000 | [diff] [blame] | 778 | fContainerLayout.setSpacing(6); |
| 779 | fContainerLayout.setContentsMargins(11, 11, 11, 11); |
| 780 | fContainerLayout.addLayout(&fLeftColumnLayout); |
| 781 | fContainerLayout.addLayout(&fMainAndRightColumnLayout); |
| 782 | |
| 783 | SkDebuggerGUI->setCentralWidget(&fCentralWidget); |
| 784 | SkDebuggerGUI->setStatusBar(&fStatusBar); |
| 785 | |
| chudy@google.com | e504de0 | 2012-07-16 18:35:23 +0000 | [diff] [blame] | 786 | fToolBar.setIconSize(QSize(32, 32)); |
| chudy@google.com | c432f00 | 2012-07-10 13:19:25 +0000 | [diff] [blame] | 787 | fToolBar.setToolButtonStyle(Qt::ToolButtonTextUnderIcon); |
| 788 | SkDebuggerGUI->addToolBar(Qt::TopToolBarArea, &fToolBar); |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 789 | |
| chudy@google.com | 0ab0339 | 2012-07-28 20:16:11 +0000 | [diff] [blame] | 790 | fSpacer.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 791 | |
| chudy@google.com | c432f00 | 2012-07-10 13:19:25 +0000 | [diff] [blame] | 792 | fToolBar.addAction(&fActionRewind); |
| 793 | fToolBar.addAction(&fActionStepBack); |
| chudy@google.com | e504de0 | 2012-07-16 18:35:23 +0000 | [diff] [blame] | 794 | fToolBar.addAction(&fActionPause); |
| chudy@google.com | c432f00 | 2012-07-10 13:19:25 +0000 | [diff] [blame] | 795 | fToolBar.addAction(&fActionStepForward); |
| 796 | fToolBar.addAction(&fActionPlay); |
| 797 | fToolBar.addSeparator(); |
| chudy@google.com | e504de0 | 2012-07-16 18:35:23 +0000 | [diff] [blame] | 798 | fToolBar.addAction(&fActionInspector); |
| chudy@google.com | c432f00 | 2012-07-10 13:19:25 +0000 | [diff] [blame] | 799 | fToolBar.addSeparator(); |
| robertphillips@google.com | d26c706 | 2012-11-12 20:42:12 +0000 | [diff] [blame] | 800 | fToolBar.addAction(&fActionProfile); |
| 801 | |
| 802 | fToolBar.addSeparator(); |
| chudy@google.com | 0ab0339 | 2012-07-28 20:16:11 +0000 | [diff] [blame] | 803 | fToolBar.addWidget(&fSpacer); |
| chudy@google.com | c432f00 | 2012-07-10 13:19:25 +0000 | [diff] [blame] | 804 | fToolBar.addWidget(&fFilter); |
| 805 | fToolBar.addAction(&fActionCancel); |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 806 | |
| 807 | // TODO(chudy): Remove static call. |
| 808 | fDirectoryWidgetActive = false; |
| robertphillips@google.com | d26c706 | 2012-11-12 20:42:12 +0000 | [diff] [blame] | 809 | fPath = ""; |
| 810 | fFileName = ""; |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 811 | setupDirectoryWidget(); |
| 812 | fDirectoryWidgetActive = true; |
| 813 | |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 814 | // Menu Bar |
| chudy@google.com | c432f00 | 2012-07-10 13:19:25 +0000 | [diff] [blame] | 815 | fMenuFile.setTitle("File"); |
| 816 | fMenuFile.addAction(&fActionOpen); |
| chudy@google.com | 0ab0339 | 2012-07-28 20:16:11 +0000 | [diff] [blame] | 817 | fMenuFile.addAction(&fActionSave); |
| 818 | fMenuFile.addAction(&fActionSaveAs); |
| chudy@google.com | c432f00 | 2012-07-10 13:19:25 +0000 | [diff] [blame] | 819 | fMenuFile.addAction(&fActionClose); |
| chudy@google.com | e504de0 | 2012-07-16 18:35:23 +0000 | [diff] [blame] | 820 | |
| 821 | fMenuEdit.setTitle("Edit"); |
| 822 | fMenuEdit.addAction(&fActionDelete); |
| chudy@google.com | 7e4cfbf | 2012-07-17 15:40:51 +0000 | [diff] [blame] | 823 | fMenuEdit.addAction(&fActionClearDeletes); |
| 824 | fMenuEdit.addSeparator(); |
| chudy@google.com | e504de0 | 2012-07-16 18:35:23 +0000 | [diff] [blame] | 825 | fMenuEdit.addAction(&fActionCreateBreakpoint); |
| chudy@google.com | 7e4cfbf | 2012-07-17 15:40:51 +0000 | [diff] [blame] | 826 | fMenuEdit.addAction(&fActionClearBreakpoints); |
| chudy@google.com | e504de0 | 2012-07-16 18:35:23 +0000 | [diff] [blame] | 827 | |
| chudy@google.com | c432f00 | 2012-07-10 13:19:25 +0000 | [diff] [blame] | 828 | fMenuNavigate.setTitle("Navigate"); |
| chudy@google.com | e504de0 | 2012-07-16 18:35:23 +0000 | [diff] [blame] | 829 | fMenuNavigate.addAction(&fActionRewind); |
| 830 | fMenuNavigate.addAction(&fActionStepBack); |
| 831 | fMenuNavigate.addAction(&fActionStepForward); |
| 832 | fMenuNavigate.addAction(&fActionPlay); |
| 833 | fMenuNavigate.addAction(&fActionPause); |
| chudy@google.com | c432f00 | 2012-07-10 13:19:25 +0000 | [diff] [blame] | 834 | fMenuNavigate.addAction(&fActionGoToLine); |
| chudy@google.com | e504de0 | 2012-07-16 18:35:23 +0000 | [diff] [blame] | 835 | |
| chudy@google.com | c432f00 | 2012-07-10 13:19:25 +0000 | [diff] [blame] | 836 | fMenuView.setTitle("View"); |
| chudy@google.com | e504de0 | 2012-07-16 18:35:23 +0000 | [diff] [blame] | 837 | fMenuView.addAction(&fActionBreakpoint); |
| chudy@google.com | 7e4cfbf | 2012-07-17 15:40:51 +0000 | [diff] [blame] | 838 | fMenuView.addAction(&fActionShowDeletes); |
| chudy@google.com | a122631 | 2012-07-26 20:26:44 +0000 | [diff] [blame] | 839 | fMenuView.addAction(&fActionZoomIn); |
| 840 | fMenuView.addAction(&fActionZoomOut); |
| chudy@google.com | e504de0 | 2012-07-16 18:35:23 +0000 | [diff] [blame] | 841 | |
| 842 | fMenuWindows.setTitle("Window"); |
| 843 | fMenuWindows.addAction(&fActionInspector); |
| 844 | fMenuWindows.addAction(&fActionDirectory); |
| chudy@google.com | c432f00 | 2012-07-10 13:19:25 +0000 | [diff] [blame] | 845 | |
| 846 | fActionGoToLine.setText("Go to Line..."); |
| 847 | fActionGoToLine.setDisabled(true); |
| 848 | fMenuBar.addAction(fMenuFile.menuAction()); |
| chudy@google.com | e504de0 | 2012-07-16 18:35:23 +0000 | [diff] [blame] | 849 | fMenuBar.addAction(fMenuEdit.menuAction()); |
| chudy@google.com | c432f00 | 2012-07-10 13:19:25 +0000 | [diff] [blame] | 850 | fMenuBar.addAction(fMenuView.menuAction()); |
| 851 | fMenuBar.addAction(fMenuNavigate.menuAction()); |
| chudy@google.com | e504de0 | 2012-07-16 18:35:23 +0000 | [diff] [blame] | 852 | fMenuBar.addAction(fMenuWindows.menuAction()); |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 853 | |
| chudy@google.com | 7dcae67 | 2012-07-09 20:26:53 +0000 | [diff] [blame] | 854 | fPause = false; |
| 855 | |
| chudy@google.com | c432f00 | 2012-07-10 13:19:25 +0000 | [diff] [blame] | 856 | SkDebuggerGUI->setMenuBar(&fMenuBar); |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 857 | QMetaObject::connectSlotsByName(SkDebuggerGUI); |
| 858 | } |
| 859 | |
| 860 | void SkDebuggerGUI::setupDirectoryWidget() { |
| chudy@google.com | c432f00 | 2012-07-10 13:19:25 +0000 | [diff] [blame] | 861 | QDir dir(fPath); |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 862 | QRegExp r(".skp"); |
| chudy@google.com | c432f00 | 2012-07-10 13:19:25 +0000 | [diff] [blame] | 863 | fDirectoryWidget.clear(); |
| 864 | const QStringList files = dir.entryList(); |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 865 | foreach (QString f, files) { |
| chudy@google.com | 7dcae67 | 2012-07-09 20:26:53 +0000 | [diff] [blame] | 866 | if (f.contains(r)) |
| chudy@google.com | c432f00 | 2012-07-10 13:19:25 +0000 | [diff] [blame] | 867 | fDirectoryWidget.addItem(f); |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 868 | } |
| 869 | } |
| 870 | |
| robertphillips@google.com | 2bde91d | 2012-11-15 14:57:57 +0000 | [diff] [blame] | 871 | // SkOffsetPicturePlayback records the offset of each command in the picture. |
| 872 | // These are needed by the profiling system. |
| 873 | class SkOffsetPicturePlayback : public SkPicturePlayback { |
| 874 | public: |
| 875 | SkOffsetPicturePlayback(SkStream* stream, const SkPictInfo& info, bool* isValid, |
| 876 | SkSerializationHelpers::DecodeBitmap decoder) |
| 877 | : INHERITED(stream, info, isValid, decoder) { |
| 878 | } |
| 879 | |
| 880 | const SkTDArray<size_t>& offsets() const { return fOffsets; } |
| 881 | |
| 882 | protected: |
| 883 | SkTDArray<size_t> fOffsets; |
| 884 | |
| 885 | virtual void preDraw(size_t offset, int type) { |
| 886 | *fOffsets.append() = offset; |
| 887 | } |
| 888 | |
| 889 | private: |
| 890 | typedef SkPicturePlayback INHERITED; |
| 891 | }; |
| 892 | |
| 893 | // Picture to wrap an SkOffsetPicturePlayback. |
| 894 | class SkOffsetPicture : public SkPicture { |
| 895 | public: |
| skia.committer@gmail.com | 884e60b | 2012-11-16 02:01:17 +0000 | [diff] [blame] | 896 | SkOffsetPicture(SkStream* stream, |
| 897 | bool* success, |
| robertphillips@google.com | 2bde91d | 2012-11-15 14:57:57 +0000 | [diff] [blame] | 898 | SkSerializationHelpers::DecodeBitmap decoder) { |
| 899 | if (success) { |
| 900 | *success = false; |
| 901 | } |
| 902 | fRecord = NULL; |
| 903 | fPlayback = NULL; |
| 904 | fWidth = fHeight = 0; |
| 905 | |
| 906 | SkPictInfo info; |
| 907 | |
| 908 | if (!stream->read(&info, sizeof(info))) { |
| 909 | return; |
| 910 | } |
| 911 | if (PICTURE_VERSION != info.fVersion) { |
| 912 | return; |
| 913 | } |
| 914 | |
| 915 | if (stream->readBool()) { |
| 916 | bool isValid = false; |
| 917 | fPlayback = SkNEW_ARGS(SkOffsetPicturePlayback, (stream, info, &isValid, decoder)); |
| 918 | if (!isValid) { |
| 919 | SkDELETE(fPlayback); |
| 920 | fPlayback = NULL; |
| 921 | return; |
| 922 | } |
| 923 | } |
| 924 | |
| 925 | // do this at the end, so that they will be zero if we hit an error. |
| 926 | fWidth = info.fWidth; |
| 927 | fHeight = info.fHeight; |
| 928 | if (success) { |
| 929 | *success = true; |
| 930 | } |
| 931 | } |
| 932 | |
| skia.committer@gmail.com | 884e60b | 2012-11-16 02:01:17 +0000 | [diff] [blame] | 933 | const SkTDArray<size_t>& offsets() const { |
| 934 | return ((SkOffsetPicturePlayback*) fPlayback)->offsets(); |
| robertphillips@google.com | 2bde91d | 2012-11-15 14:57:57 +0000 | [diff] [blame] | 935 | } |
| 936 | |
| 937 | private: |
| robertphillips@google.com | 8a1cdae | 2012-11-19 20:44:29 +0000 | [diff] [blame] | 938 | // disallow default ctor b.c. we don't have a good way to setup the fPlayback ptr |
| 939 | SkOffsetPicture(); |
| 940 | // disallow the copy ctor - enabling would require copying code from SkPicture |
| 941 | SkOffsetPicture(const SkOffsetPicture& src); |
| 942 | |
| robertphillips@google.com | 2bde91d | 2012-11-15 14:57:57 +0000 | [diff] [blame] | 943 | typedef SkPicture INHERITED; |
| 944 | }; |
| 945 | |
| 946 | |
| 947 | |
| robertphillips@google.com | d26c706 | 2012-11-12 20:42:12 +0000 | [diff] [blame] | 948 | void SkDebuggerGUI::loadPicture(const SkString& fileName) { |
| 949 | fFileName = fileName; |
| chudy@google.com | d3058f5 | 2012-07-19 13:41:27 +0000 | [diff] [blame] | 950 | fLoading = true; |
| robertphillips@google.com | d26c706 | 2012-11-12 20:42:12 +0000 | [diff] [blame] | 951 | SkStream* stream = SkNEW_ARGS(SkFILEStream, (fileName.c_str())); |
| robertphillips@google.com | 2bde91d | 2012-11-15 14:57:57 +0000 | [diff] [blame] | 952 | SkOffsetPicture* picture = SkNEW_ARGS(SkOffsetPicture, (stream, NULL, &SkImageDecoder::DecodeStream)); |
| 953 | |
| chudy@google.com | 686e680 | 2012-08-14 16:00:32 +0000 | [diff] [blame] | 954 | fCanvasWidget.resetWidgetTransform(); |
| chudy@google.com | 607357f | 2012-08-07 16:12:23 +0000 | [diff] [blame] | 955 | fDebugger.loadPicture(picture); |
| chudy@google.com | 4c7962e | 2012-08-14 19:38:31 +0000 | [diff] [blame] | 956 | |
| robertphillips@google.com | 2bde91d | 2012-11-15 14:57:57 +0000 | [diff] [blame] | 957 | fOffsets = picture->offsets(); |
| 958 | |
| chudy@google.com | 607357f | 2012-08-07 16:12:23 +0000 | [diff] [blame] | 959 | SkSafeUnref(stream); |
| 960 | SkSafeUnref(picture); |
| 961 | |
| chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 962 | // Will this automatically clear out due to nature of refcnt? |
| robertphillips@google.com | 8a1cdae | 2012-11-19 20:44:29 +0000 | [diff] [blame] | 963 | SkTArray<SkString>* commands = fDebugger.getDrawCommandsAsStrings(); |
| chudy@google.com | 607357f | 2012-08-07 16:12:23 +0000 | [diff] [blame] | 964 | |
| robertphillips@google.com | fe830a4 | 2012-11-15 16:33:31 +0000 | [diff] [blame] | 965 | // If SkPicturePlayback is compiled w/o SK_PICTURE_PROFILING_STUBS |
| 966 | // the offset count will always be zero |
| 967 | SkASSERT(0 == fOffsets.count() || commands->count() == fOffsets.count()); |
| robertphillips@google.com | e099bc4 | 2012-11-19 16:26:40 +0000 | [diff] [blame] | 968 | if (commands->count() == fOffsets.count()) { |
| 969 | fActionProfile.setDisabled(false); |
| robertphillips@google.com | fe830a4 | 2012-11-15 16:33:31 +0000 | [diff] [blame] | 970 | } |
| robertphillips@google.com | 2bde91d | 2012-11-15 14:57:57 +0000 | [diff] [blame] | 971 | |
| chudy@google.com | 7dcae67 | 2012-07-09 20:26:53 +0000 | [diff] [blame] | 972 | /* fDebugCanvas is reinitialized every load picture. Need it to retain value |
| chudy@google.com | 607357f | 2012-08-07 16:12:23 +0000 | [diff] [blame] | 973 | * of the visibility filter. |
| 974 | * TODO(chudy): This should be deprecated since fDebugger is not |
| 975 | * recreated. |
| 976 | * */ |
| 977 | fDebugger.highlightCurrentCommand(fSettingsWidget.getVisibilityButton()->isChecked()); |
| 978 | |
| chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 979 | setupListWidget(commands); |
| 980 | setupComboBox(commands); |
| robertphillips@google.com | 8a1cdae | 2012-11-19 20:44:29 +0000 | [diff] [blame] | 981 | setupOverviewText(NULL, 0.0); |
| chudy@google.com | 7e4cfbf | 2012-07-17 15:40:51 +0000 | [diff] [blame] | 982 | fInspectorWidget.setDisabled(false); |
| chudy@google.com | e606d6e | 2012-07-12 14:31:25 +0000 | [diff] [blame] | 983 | fSettingsWidget.setDisabled(false); |
| chudy@google.com | d3058f5 | 2012-07-19 13:41:27 +0000 | [diff] [blame] | 984 | fMenuEdit.setDisabled(false); |
| 985 | fMenuNavigate.setDisabled(false); |
| 986 | fMenuView.setDisabled(false); |
| chudy@google.com | 0ab0339 | 2012-07-28 20:16:11 +0000 | [diff] [blame] | 987 | fActionSave.setDisabled(false); |
| 988 | fActionSaveAs.setDisabled(false); |
| chudy@google.com | d3058f5 | 2012-07-19 13:41:27 +0000 | [diff] [blame] | 989 | fLoading = false; |
| 990 | actionPlay(); |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 991 | } |
| 992 | |
| robertphillips@google.com | 8a1cdae | 2012-11-19 20:44:29 +0000 | [diff] [blame] | 993 | void SkDebuggerGUI::setupListWidget(SkTArray<SkString>* command) { |
| chudy@google.com | c432f00 | 2012-07-10 13:19:25 +0000 | [diff] [blame] | 994 | fListWidget.clear(); |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 995 | int counter = 0; |
| robertphillips@google.com | 30d35f2 | 2012-11-06 16:45:36 +0000 | [diff] [blame] | 996 | int indent = 0; |
| chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 997 | for (int i = 0; i < command->count(); i++) { |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 998 | QListWidgetItem *item = new QListWidgetItem(); |
| robertphillips@google.com | 8a1cdae | 2012-11-19 20:44:29 +0000 | [diff] [blame] | 999 | item->setData(Qt::DisplayRole, (*command)[i].c_str()); |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 1000 | item->setData(Qt::UserRole + 1, counter++); |
| robertphillips@google.com | 30d35f2 | 2012-11-06 16:45:36 +0000 | [diff] [blame] | 1001 | |
| robertphillips@google.com | 8a1cdae | 2012-11-19 20:44:29 +0000 | [diff] [blame] | 1002 | if (0 == strcmp("Restore", (*command)[i].c_str())) { |
| robertphillips@google.com | 30d35f2 | 2012-11-06 16:45:36 +0000 | [diff] [blame] | 1003 | indent -= 10; |
| 1004 | } |
| 1005 | |
| 1006 | item->setData(Qt::UserRole + 3, indent); |
| 1007 | |
| robertphillips@google.com | 8a1cdae | 2012-11-19 20:44:29 +0000 | [diff] [blame] | 1008 | if (0 == strcmp("Save", (*command)[i].c_str()) || |
| 1009 | 0 == strcmp("Save Layer", (*command)[i].c_str())) { |
| robertphillips@google.com | 30d35f2 | 2012-11-06 16:45:36 +0000 | [diff] [blame] | 1010 | indent += 10; |
| 1011 | } |
| 1012 | |
| robertphillips@google.com | d26c706 | 2012-11-12 20:42:12 +0000 | [diff] [blame] | 1013 | item->setData(Qt::UserRole + 4, -1.0); |
| 1014 | |
| chudy@google.com | c432f00 | 2012-07-10 13:19:25 +0000 | [diff] [blame] | 1015 | fListWidget.addItem(item); |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 1016 | } |
| 1017 | } |
| 1018 | |
| robertphillips@google.com | 8a1cdae | 2012-11-19 20:44:29 +0000 | [diff] [blame] | 1019 | void SkDebuggerGUI::setupOverviewText(const SkTDArray<double>* typeTimes, double totTime) { |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 1020 | |
| robertphillips@google.com | 8a1cdae | 2012-11-19 20:44:29 +0000 | [diff] [blame] | 1021 | const SkTDArray<SkDrawCommand*>& commands = fDebugger.getDrawCommands(); |
| 1022 | |
| 1023 | SkTDArray<int> counts; |
| 1024 | counts.setCount(LAST_DRAWTYPE_ENUM+1); |
| 1025 | for (int i = 0; i < LAST_DRAWTYPE_ENUM+1; ++i) { |
| 1026 | counts[i] = 0; |
| 1027 | } |
| 1028 | |
| 1029 | for (int i = 0; i < commands.count(); i++) { |
| 1030 | counts[commands[i]->getType()]++; |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 1031 | } |
| 1032 | |
| 1033 | QString overview; |
| robertphillips@google.com | 8a1cdae | 2012-11-19 20:44:29 +0000 | [diff] [blame] | 1034 | int total = 0; |
| 1035 | #ifdef SK_DEBUG |
| 1036 | double totPercent = 0, tempSum = 0; |
| 1037 | #endif |
| 1038 | for (int i = 0; i < LAST_DRAWTYPE_ENUM+1; ++i) { |
| 1039 | if (0 == counts[i]) { |
| 1040 | // if there were no commands of this type then they should've consumed no time |
| 1041 | SkASSERT(NULL == typeTimes || 0.0 == (*typeTimes)[i]); |
| 1042 | continue; |
| 1043 | } |
| 1044 | |
| 1045 | overview.append(SkDrawCommand::GetCommandString((DrawType) i)); |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 1046 | overview.append(": "); |
| robertphillips@google.com | 8a1cdae | 2012-11-19 20:44:29 +0000 | [diff] [blame] | 1047 | overview.append(QString::number(counts[i])); |
| 1048 | if (NULL != typeTimes) { |
| 1049 | overview.append(" - "); |
| 1050 | overview.append(QString::number((*typeTimes)[i], 'f', 1)); |
| 1051 | overview.append("ms"); |
| 1052 | overview.append(" - "); |
| 1053 | double percent = 100.0*(*typeTimes)[i]/totTime; |
| 1054 | overview.append(QString::number(percent, 'f', 1)); |
| 1055 | overview.append("%"); |
| 1056 | #ifdef SK_DEBUG |
| 1057 | totPercent += percent; |
| 1058 | tempSum += (*typeTimes)[i]; |
| 1059 | #endif |
| 1060 | } |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 1061 | overview.append("<br/>"); |
| robertphillips@google.com | 8a1cdae | 2012-11-19 20:44:29 +0000 | [diff] [blame] | 1062 | total += counts[i]; |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 1063 | } |
| robertphillips@google.com | 8a1cdae | 2012-11-19 20:44:29 +0000 | [diff] [blame] | 1064 | #ifdef SK_DEBUG |
| 1065 | if (NULL != typeTimes) { |
| 1066 | SkASSERT(SkScalarNearlyEqual(totPercent, 100.0)); |
| 1067 | SkASSERT(SkScalarNearlyEqual(tempSum, totTime)); |
| 1068 | } |
| 1069 | #endif |
| 1070 | |
| 1071 | if (totTime > 0.0) { |
| 1072 | overview.append("Total Time: "); |
| 1073 | overview.append(QString::number(totTime, 'f', 2)); |
| 1074 | overview.append("ms"); |
| 1075 | #ifdef SK_DEBUG |
| 1076 | overview.append(" "); |
| 1077 | overview.append(QString::number(totPercent)); |
| 1078 | overview.append("% "); |
| 1079 | #endif |
| 1080 | overview.append("<br/>"); |
| 1081 | } |
| 1082 | |
| 1083 | QString totalStr; |
| 1084 | totalStr.append("Total Draw Commands: "); |
| 1085 | totalStr.append(QString::number(total)); |
| 1086 | totalStr.append("<br/>"); |
| 1087 | overview.insert(0, totalStr); |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 1088 | |
| 1089 | overview.append("<br/>"); |
| chudy@google.com | 607357f | 2012-08-07 16:12:23 +0000 | [diff] [blame] | 1090 | overview.append("SkPicture Width: "); |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 1091 | // NOTE(chudy): This is where we can pull out the SkPictures width. |
| chudy@google.com | 607357f | 2012-08-07 16:12:23 +0000 | [diff] [blame] | 1092 | overview.append(QString::number(fDebugger.pictureWidth())); |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 1093 | overview.append("px<br/>"); |
| chudy@google.com | 607357f | 2012-08-07 16:12:23 +0000 | [diff] [blame] | 1094 | overview.append("SkPicture Height: "); |
| 1095 | overview.append(QString::number(fDebugger.pictureHeight())); |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 1096 | overview.append("px"); |
| chudy@google.com | 6bd109a | 2012-08-14 19:34:13 +0000 | [diff] [blame] | 1097 | fInspectorWidget.setText(overview, SkInspectorWidget::kOverview_TabType); |
| robertphillips@google.com | 8a1cdae | 2012-11-19 20:44:29 +0000 | [diff] [blame] | 1098 | } |
| 1099 | |
| 1100 | void SkDebuggerGUI::setupComboBox(SkTArray<SkString>* command) { |
| 1101 | fFilter.clear(); |
| 1102 | fFilter.addItem("--Filter By Available Commands--"); |
| 1103 | |
| 1104 | std::map<std::string, int> map; |
| 1105 | for (int i = 0; i < command->count(); i++) { |
| 1106 | map[(*command)[i].c_str()]++; |
| 1107 | } |
| 1108 | |
| skia.committer@gmail.com | 3458716 | 2012-11-20 02:01:23 +0000 | [diff] [blame] | 1109 | for (std::map<std::string, int>::iterator it = map.begin(); it != map.end(); |
| robertphillips@google.com | 8a1cdae | 2012-11-19 20:44:29 +0000 | [diff] [blame] | 1110 | ++it) { |
| 1111 | fFilter.addItem((it->first).c_str()); |
| 1112 | } |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 1113 | |
| 1114 | // NOTE(chudy): Makes first item unselectable. |
| chudy@google.com | 7dcae67 | 2012-07-09 20:26:53 +0000 | [diff] [blame] | 1115 | QStandardItemModel* model = qobject_cast<QStandardItemModel*>( |
| chudy@google.com | c432f00 | 2012-07-10 13:19:25 +0000 | [diff] [blame] | 1116 | fFilter.model()); |
| 1117 | QModelIndex firstIndex = model->index(0, fFilter.modelColumn(), |
| 1118 | fFilter.rootModelIndex()); |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 1119 | QStandardItem* firstItem = model->itemFromIndex(firstIndex); |
| 1120 | firstItem->setSelectable(false); |
| 1121 | } |