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