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