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