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