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