blob: e7be72da8881bca457a2cde23b47cb38261e7615 [file] [log] [blame]
chudy@google.com902ebe52012-06-29 14:21:22 +00001/*
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.com902ebe52012-06-29 14:21:22 +00008#include "SkDebuggerGUI.h"
chudy@google.combbad34d2012-08-13 14:26:36 +00009#include "SkGraphics.h"
scroggo@google.comb4467e62012-11-06 23:10:09 +000010#include "SkImageDecoder.h"
chudy@google.com902ebe52012-06-29 14:21:22 +000011#include <QListWidgetItem>
robertphillips@google.com2bde91d2012-11-15 14:57:57 +000012#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.com902ebe52012-06-29 14:21:22 +000018
19SkDebuggerGUI::SkDebuggerGUI(QWidget *parent) :
chudy@google.comc432f002012-07-10 13:19:25 +000020 QMainWindow(parent)
chudy@google.com2d537a12012-07-31 12:49:52 +000021 , fCentralWidget(this)
22 , fStatusBar(this)
23 , fToolBar(this)
chudy@google.comc432f002012-07-10 13:19:25 +000024 , fActionOpen(this)
25 , fActionBreakpoint(this)
robertphillips@google.comd26c7062012-11-12 20:42:12 +000026 , fActionProfile(this)
chudy@google.comc432f002012-07-10 13:19:25 +000027 , fActionCancel(this)
chudy@google.com7e4cfbf2012-07-17 15:40:51 +000028 , fActionClearBreakpoints(this)
chudy@google.come504de02012-07-16 18:35:23 +000029 , fActionClearDeletes(this)
chudy@google.comc432f002012-07-10 13:19:25 +000030 , fActionClose(this)
chudy@google.come504de02012-07-16 18:35:23 +000031 , fActionCreateBreakpoint(this)
chudy@google.comc432f002012-07-10 13:19:25 +000032 , fActionDelete(this)
33 , fActionDirectory(this)
34 , fActionGoToLine(this)
35 , fActionInspector(this)
36 , fActionPlay(this)
chudy@google.come504de02012-07-16 18:35:23 +000037 , fActionPause(this)
chudy@google.comc432f002012-07-10 13:19:25 +000038 , fActionRewind(this)
chudy@google.com0ab03392012-07-28 20:16:11 +000039 , fActionSave(this)
40 , fActionSaveAs(this)
chudy@google.com7e4cfbf2012-07-17 15:40:51 +000041 , fActionShowDeletes(this)
chudy@google.comc432f002012-07-10 13:19:25 +000042 , fActionStepBack(this)
43 , fActionStepForward(this)
chudy@google.coma1226312012-07-26 20:26:44 +000044 , fActionZoomIn(this)
45 , fActionZoomOut(this)
46 , fMapper(this)
chudy@google.comc432f002012-07-10 13:19:25 +000047 , fListWidget(&fCentralWidget)
48 , fDirectoryWidget(&fCentralWidget)
chudy@google.com607357f2012-08-07 16:12:23 +000049 , fCanvasWidget(this, &fDebugger)
chudy@google.comc432f002012-07-10 13:19:25 +000050 , fMenuBar(this)
51 , fMenuFile(this)
52 , fMenuNavigate(this)
53 , fMenuView(this)
chudy@google.com7e4cfbf2012-07-17 15:40:51 +000054 , fBreakpointsActivated(false)
55 , fDeletesActivated(false)
56 , fPause(false)
chudy@google.comd3058f52012-07-19 13:41:27 +000057 , fLoading(false)
chudy@google.comc432f002012-07-10 13:19:25 +000058{
chudy@google.com902ebe52012-06-29 14:21:22 +000059 setupUi(this);
chudy@google.comea5488b2012-07-26 19:38:22 +000060 connect(&fListWidget, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)), this, SLOT(registerListClick(QListWidgetItem *)));
chudy@google.comc432f002012-07-10 13:19:25 +000061 connect(&fActionOpen, SIGNAL(triggered()), this, SLOT(openFile()));
chudy@google.comea5488b2012-07-26 19:38:22 +000062 connect(&fActionDirectory, SIGNAL(triggered()), this, SLOT(toggleDirectory()));
63 connect(&fDirectoryWidget, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)), this, SLOT(loadFile(QListWidgetItem *)));
chudy@google.comc432f002012-07-10 13:19:25 +000064 connect(&fActionDelete, SIGNAL(triggered()), this, SLOT(actionDelete()));
chudy@google.comea5488b2012-07-26 19:38:22 +000065 connect(&fListWidget, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(toggleBreakpoint()));
chudy@google.comc432f002012-07-10 13:19:25 +000066 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.comea5488b2012-07-26 19:38:22 +000069 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.comd26c7062012-11-12 20:42:12 +000074 connect(&fActionProfile, SIGNAL(triggered()), this, SLOT(actionProfile()));
chudy@google.comc432f002012-07-10 13:19:25 +000075 connect(&fActionCancel, SIGNAL(triggered()), this, SLOT(actionCancel()));
chudy@google.com7e4cfbf2012-07-17 15:40:51 +000076 connect(&fActionClearBreakpoints, SIGNAL(triggered()), this, SLOT(actionClearBreakpoints()));
77 connect(&fActionClearDeletes, SIGNAL(triggered()), this, SLOT(actionClearDeletes()));
chudy@google.comc432f002012-07-10 13:19:25 +000078 connect(&fActionClose, SIGNAL(triggered()), this, SLOT(actionClose()));
chudy@google.comea5488b2012-07-26 19:38:22 +000079 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.come504de02012-07-16 18:35:23 +000083 connect(&fActionCreateBreakpoint, SIGNAL(activated()), this, SLOT(toggleBreakpoint()));
chudy@google.com7e4cfbf2012-07-17 15:40:51 +000084 connect(&fActionShowDeletes, SIGNAL(triggered()), this, SLOT(showDeletes()));
chudy@google.comea5488b2012-07-26 19:38:22 +000085 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.com0ab03392012-07-28 20:16:11 +000089 connect(&fActionSaveAs, SIGNAL(triggered()), this, SLOT(actionSaveAs()));
90 connect(&fActionSave, SIGNAL(triggered()), this, SLOT(actionSave()));
chudy@google.com7e4cfbf2012-07-17 15:40:51 +000091
chudy@google.coma1226312012-07-26 20:26:44 +000092 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.com7e4cfbf2012-07-17 15:40:51 +000099 fInspectorWidget.setDisabled(true);
chudy@google.comd3058f52012-07-19 13:41:27 +0000100 fMenuEdit.setDisabled(true);
101 fMenuNavigate.setDisabled(true);
102 fMenuView.setDisabled(true);
chudy@google.combbad34d2012-08-13 14:26:36 +0000103
104 SkGraphics::Init();
chudy@google.com902ebe52012-06-29 14:21:22 +0000105}
106
chudy@google.combbad34d2012-08-13 14:26:36 +0000107SkDebuggerGUI::~SkDebuggerGUI() {
108 SkGraphics::Term();
109}
chudy@google.com902ebe52012-06-29 14:21:22 +0000110
111void SkDebuggerGUI::actionBreakpoints() {
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000112 fBreakpointsActivated = !fBreakpointsActivated;
chudy@google.comc432f002012-07-10 13:19:25 +0000113 for (int row = 0; row < fListWidget.count(); row++) {
114 QListWidgetItem *item = fListWidget.item(row);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000115 item->setHidden(item->checkState() == Qt::Unchecked && fBreakpointsActivated);
116 }
117}
chudy@google.com902ebe52012-06-29 14:21:22 +0000118
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000119void SkDebuggerGUI::showDeletes() {
120 fDeletesActivated = !fDeletesActivated;
121 for (int row = 0; row < fListWidget.count(); row++) {
122 QListWidgetItem *item = fListWidget.item(row);
chudy@google.com607357f2012-08-07 16:12:23 +0000123 item->setHidden(fDebugger.isCommandVisible(row)
124 && fDeletesActivated);
chudy@google.com902ebe52012-06-29 14:21:22 +0000125 }
126}
127
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000128// 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.
131class SkTimedPicturePlayback : public SkPicturePlayback {
132public:
133 SkTimedPicturePlayback(SkStream* stream, const SkPictInfo& info, bool* isValid,
134 SkSerializationHelpers::DecodeBitmap decoder,
skia.committer@gmail.com884e60b2012-11-16 02:01:17 +0000135 const SkTDArray<size_t>& offsets)
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000136 : 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
150protected:
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.com884e60b2012-11-16 02:01:17 +0000159 // This search isn't as bad as it seems. In normal playback mode, the
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000160 // base class steps through the commands in order and can only skip ahead
skia.committer@gmail.com884e60b2012-11-16 02:01:17 +0000161 // a bit on a clip. This class is only used during profiling so we
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000162 // 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.come099bc42012-11-19 16:26:40 +0000178#if defined(SK_BUILD_FOR_WIN32)
179 // CPU timer doesn't work well on Windows
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000180 fTimes[fCurCommand] += fTimer.fWall;
181 fTot += fTimer.fWall;
robertphillips@google.come099bc42012-11-19 16:26:40 +0000182#else
183 fTimes[fCurCommand] += fTimer.fCpu;
184 fTot += fTimer.fCpu;
185#endif
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000186 }
187
188private:
189 typedef SkPicturePlayback INHERITED;
190};
191
192// Wrap SkPicture to allow installation of an SkTimedPicturePlayback object
193class SkTimedPicture : public SkPicture {
194public:
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.com884e60b2012-11-16 02:01:17 +0000217 fPlayback = SkNEW_ARGS(SkTimedPicturePlayback,
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000218 (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
239private:
240 typedef SkPicture INHERITED;
241};
242
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000243void SkDebuggerGUI::actionProfile() {
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000244 // 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.com884e60b2012-11-16 02:01:17 +0000246 // The SkTimedPlaybackPicture in turn passes the offsets to an
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000247 // 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.comd26c7062012-11-12 20:42:12 +0000295}
296
chudy@google.com902ebe52012-06-29 14:21:22 +0000297void SkDebuggerGUI::actionCancel() {
chudy@google.comc432f002012-07-10 13:19:25 +0000298 for (int row = 0; row < fListWidget.count(); row++) {
299 fListWidget.item(row)->setHidden(false);
chudy@google.com902ebe52012-06-29 14:21:22 +0000300 }
301}
302
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000303void 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.com8e41a162012-11-19 17:39:18 +0000308 QPixmap(":/blank.png"));
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000309 }
310}
311
312void SkDebuggerGUI::actionClearDeletes() {
313 for (int row = 0; row < fListWidget.count(); row++) {
314 QListWidgetItem* item = fListWidget.item(row);
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000315 item->setData(Qt::UserRole + 2, QPixmap(":/blank.png"));
chudy@google.com607357f2012-08-07 16:12:23 +0000316 fDebugger.setCommandVisible(row, true);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000317 }
318 if (fPause) {
319 fCanvasWidget.drawTo(fPausedRow);
320 } else {
321 fCanvasWidget.drawTo(fListWidget.currentRow());
322 }
323}
324
chudy@google.com902ebe52012-06-29 14:21:22 +0000325void SkDebuggerGUI::actionCommandFilter() {
chudy@google.com607357f2012-08-07 16:12:23 +0000326 fDebugger.highlightCurrentCommand(
chudy@google.comc432f002012-07-10 13:19:25 +0000327 fSettingsWidget.getVisibilityButton()->isChecked());
328 fCanvasWidget.drawTo(fListWidget.currentRow());
chudy@google.com902ebe52012-06-29 14:21:22 +0000329}
330
331void SkDebuggerGUI::actionClose() {
332 this->close();
333}
334
335void SkDebuggerGUI::actionDelete() {
chudy@google.comc432f002012-07-10 13:19:25 +0000336 int currentRow = fListWidget.currentRow();
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000337 QListWidgetItem* item = fListWidget.currentItem();
338
chudy@google.com607357f2012-08-07 16:12:23 +0000339 if (fDebugger.isCommandVisible(currentRow)) {
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000340 item->setData(Qt::UserRole + 2, QPixmap(":/delete.png"));
chudy@google.com607357f2012-08-07 16:12:23 +0000341 fDebugger.setCommandVisible(currentRow, false);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000342 } else {
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000343 item->setData(Qt::UserRole + 2, QPixmap(":/blank.png"));
chudy@google.com607357f2012-08-07 16:12:23 +0000344 fDebugger.setCommandVisible(currentRow, true);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000345 }
346
chudy@google.come504de02012-07-16 18:35:23 +0000347 if (fPause) {
348 fCanvasWidget.drawTo(fPausedRow);
349 } else {
350 fCanvasWidget.drawTo(currentRow);
351 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000352}
353
chudy@google.comea5488b2012-07-26 19:38:22 +0000354void SkDebuggerGUI::actionGLWidget(bool isToggled) {
355 fCanvasWidget.setWidgetVisibility(SkCanvasWidget::kGPU_WidgetType, !isToggled);
356}
357
chudy@google.com902ebe52012-06-29 14:21:22 +0000358void SkDebuggerGUI::actionInspector() {
chudy@google.comc432f002012-07-10 13:19:25 +0000359 if (fInspectorWidget.isHidden()) {
360 fInspectorWidget.setHidden(false);
chudy@google.com902ebe52012-06-29 14:21:22 +0000361 } else {
chudy@google.comc432f002012-07-10 13:19:25 +0000362 fInspectorWidget.setHidden(true);
chudy@google.com902ebe52012-06-29 14:21:22 +0000363 }
364}
365
366void SkDebuggerGUI::actionPlay() {
chudy@google.comc432f002012-07-10 13:19:25 +0000367 for (int row = fListWidget.currentRow() + 1; row < fListWidget.count();
chudy@google.com7dcae672012-07-09 20:26:53 +0000368 row++) {
chudy@google.comc432f002012-07-10 13:19:25 +0000369 QListWidgetItem *item = fListWidget.item(row);
chudy@google.com902ebe52012-06-29 14:21:22 +0000370 if (item->checkState() == Qt::Checked) {
chudy@google.comc432f002012-07-10 13:19:25 +0000371 fListWidget.setCurrentItem(item);
chudy@google.com902ebe52012-06-29 14:21:22 +0000372 return;
373 }
374 }
chudy@google.comc432f002012-07-10 13:19:25 +0000375 fListWidget.setCurrentRow(fListWidget.count() - 1);
chudy@google.com902ebe52012-06-29 14:21:22 +0000376}
377
chudy@google.comea5488b2012-07-26 19:38:22 +0000378void SkDebuggerGUI::actionRasterWidget(bool isToggled) {
379 fCanvasWidget.setWidgetVisibility(SkCanvasWidget::kRaster_8888_WidgetType, !isToggled);
380}
381
chudy@google.com902ebe52012-06-29 14:21:22 +0000382void SkDebuggerGUI::actionRewind() {
chudy@google.come504de02012-07-16 18:35:23 +0000383 fListWidget.setCurrentRow(0);
chudy@google.com902ebe52012-06-29 14:21:22 +0000384}
385
chudy@google.com0ab03392012-07-28 20:16:11 +0000386void SkDebuggerGUI::actionSave() {
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000387 fFileName = fPath.toAscii();
388 fFileName.append("/");
389 fFileName.append(fDirectoryWidget.currentItem()->text().toAscii());
390 saveToFile(fFileName);
chudy@google.com0ab03392012-07-28 20:16:11 +0000391}
392
393void SkDebuggerGUI::actionSaveAs() {
394 QString filename = QFileDialog::getSaveFileName(this, "Save File", "",
395 "Skia Picture (*skp)");
chudy@google.com38b08ce2012-07-28 23:26:10 +0000396 if (!filename.endsWith(".skp", Qt::CaseInsensitive)) {
chudy@google.com0ab03392012-07-28 20:16:11 +0000397 filename.append(".skp");
398 }
djsollen@google.comc3c82162012-11-13 18:35:10 +0000399 saveToFile(SkString(filename.toAscii().data()));
chudy@google.com0ab03392012-07-28 20:16:11 +0000400}
401
chudy@google.com7dcae672012-07-09 20:26:53 +0000402void SkDebuggerGUI::actionScale(float scaleFactor) {
chudy@google.comc432f002012-07-10 13:19:25 +0000403 fSettingsWidget.setZoomText(scaleFactor);
chudy@google.com7dcae672012-07-09 20:26:53 +0000404}
405
chudy@google.com902ebe52012-06-29 14:21:22 +0000406void SkDebuggerGUI::actionSettings() {
chudy@google.comc432f002012-07-10 13:19:25 +0000407 if (fSettingsWidget.isHidden()) {
408 fSettingsWidget.setHidden(false);
chudy@google.com902ebe52012-06-29 14:21:22 +0000409 } else {
chudy@google.comc432f002012-07-10 13:19:25 +0000410 fSettingsWidget.setHidden(true);
chudy@google.com902ebe52012-06-29 14:21:22 +0000411 }
412}
413
414void SkDebuggerGUI::actionStepBack() {
chudy@google.comc432f002012-07-10 13:19:25 +0000415 int currentRow = fListWidget.currentRow();
chudy@google.com902ebe52012-06-29 14:21:22 +0000416 if (currentRow != 0) {
chudy@google.comc432f002012-07-10 13:19:25 +0000417 fListWidget.setCurrentRow(currentRow - 1);
chudy@google.com902ebe52012-06-29 14:21:22 +0000418 }
419}
420
421void SkDebuggerGUI::actionStepForward() {
chudy@google.comc432f002012-07-10 13:19:25 +0000422 int currentRow = fListWidget.currentRow();
chudy@google.com902ebe52012-06-29 14:21:22 +0000423 QString curRow = QString::number(currentRow);
chudy@google.comc432f002012-07-10 13:19:25 +0000424 QString curCount = QString::number(fListWidget.count());
425 if (currentRow < fListWidget.count() - 1) {
426 fListWidget.setCurrentRow(currentRow + 1);
chudy@google.com902ebe52012-06-29 14:21:22 +0000427 }
428}
429
chudy@google.coma9e937c2012-08-03 17:32:05 +0000430void SkDebuggerGUI::drawComplete() {
chudy@google.com607357f2012-08-07 16:12:23 +0000431 fInspectorWidget.setMatrix(fDebugger.getCurrentMatrix());
432 fInspectorWidget.setClip(fDebugger.getCurrentClip());
chudy@google.coma9e937c2012-08-03 17:32:05 +0000433}
434
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000435void SkDebuggerGUI::saveToFile(const SkString& filename) {
436 SkFILEWStream file(filename.c_str());
chudy@google.com607357f2012-08-07 16:12:23 +0000437 fDebugger.makePicture()->serialize(&file);
chudy@google.com0ab03392012-07-28 20:16:11 +0000438}
439
chudy@google.com902ebe52012-06-29 14:21:22 +0000440void SkDebuggerGUI::loadFile(QListWidgetItem *item) {
441 if (fDirectoryWidgetActive) {
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000442 fFileName = fPath.toAscii();
443 fFileName.append("/");
444 fFileName.append(item->text().toAscii());
445 loadPicture(fFileName);
chudy@google.com902ebe52012-06-29 14:21:22 +0000446 }
447}
448
449void SkDebuggerGUI::openFile() {
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000450 QString temp = QFileDialog::getOpenFileName(this, tr("Open File"), "",
chudy@google.com7dcae672012-07-09 20:26:53 +0000451 tr("Files (*.*)"));
chudy@google.com902ebe52012-06-29 14:21:22 +0000452 fDirectoryWidgetActive = false;
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000453 if (!temp.isEmpty()) {
454 QFileInfo pathInfo(temp);
chudy@google.com902ebe52012-06-29 14:21:22 +0000455 fPath = pathInfo.path();
djsollen@google.comc3c82162012-11-13 18:35:10 +0000456 loadPicture(SkString(temp.toAscii().data()));
chudy@google.com902ebe52012-06-29 14:21:22 +0000457 setupDirectoryWidget();
458 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000459 fDirectoryWidgetActive = true;
460}
461
chudy@google.comc432f002012-07-10 13:19:25 +0000462void SkDebuggerGUI::pauseDrawing(bool isPaused) {
chudy@google.com607357f2012-08-07 16:12:23 +0000463 fPause = isPaused;
464 fPausedRow = fListWidget.currentRow();
465 fCanvasWidget.drawTo(fPausedRow);
chudy@google.com7dcae672012-07-09 20:26:53 +0000466}
467
chudy@google.com902ebe52012-06-29 14:21:22 +0000468void SkDebuggerGUI::registerListClick(QListWidgetItem *item) {
chudy@google.comd3058f52012-07-19 13:41:27 +0000469 if(!fLoading) {
470 int currentRow = fListWidget.currentRow();
chudy@google.comd3058f52012-07-19 13:41:27 +0000471
chudy@google.comea5488b2012-07-26 19:38:22 +0000472 if (currentRow != -1) {
473 if (!fPause) {
474 fCanvasWidget.drawTo(currentRow);
chudy@google.comd3058f52012-07-19 13:41:27 +0000475 }
chudy@google.com97cee972012-08-07 20:41:37 +0000476 SkTDArray<SkString*> *currInfo = fDebugger.getCommandInfo(
chudy@google.comea5488b2012-07-26 19:38:22 +0000477 currentRow);
478
479 /* TODO(chudy): Add command type before parameters. Rename v
480 * to something more informative. */
chudy@google.com97cee972012-08-07 20:41:37 +0000481 if (currInfo) {
chudy@google.comea5488b2012-07-26 19:38:22 +0000482 QString info;
483 info.append("<b>Parameters: </b><br/>");
chudy@google.com97cee972012-08-07 20:41:37 +0000484 for (int i = 0; i < currInfo->count(); i++) {
485
486 info.append(QString((*currInfo)[i]->c_str()));
chudy@google.comea5488b2012-07-26 19:38:22 +0000487 info.append("<br/>");
488 }
chudy@google.com6bd109a2012-08-14 19:34:13 +0000489 fInspectorWidget.setText(info, SkInspectorWidget::kDetail_TabType);
chudy@google.comea5488b2012-07-26 19:38:22 +0000490 fInspectorWidget.setDisabled(false);
chudy@google.comea5488b2012-07-26 19:38:22 +0000491 }
chudy@google.comd3058f52012-07-19 13:41:27 +0000492 }
chudy@google.comea5488b2012-07-26 19:38:22 +0000493
chudy@google.com902ebe52012-06-29 14:21:22 +0000494 }
495}
496
chudy@google.com9ca9bfe2012-07-12 21:58:14 +0000497void SkDebuggerGUI::selectCommand(int command) {
498 if (fPause) {
499 fListWidget.setCurrentRow(command);
500 }
501}
502
chudy@google.com902ebe52012-06-29 14:21:22 +0000503void SkDebuggerGUI::toggleBreakpoint() {
chudy@google.comc432f002012-07-10 13:19:25 +0000504 QListWidgetItem* item = fListWidget.currentItem();
chudy@google.com902ebe52012-06-29 14:21:22 +0000505 if (item->checkState() == Qt::Unchecked) {
506 item->setCheckState(Qt::Checked);
chudy@google.come565de42012-07-12 14:15:54 +0000507 item->setData(Qt::DecorationRole,
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000508 QPixmap(":/breakpoint_16x16.png"));
chudy@google.com902ebe52012-06-29 14:21:22 +0000509 } else {
chudy@google.com902ebe52012-06-29 14:21:22 +0000510 item->setCheckState(Qt::Unchecked);
chudy@google.come565de42012-07-12 14:15:54 +0000511 item->setData(Qt::DecorationRole,
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000512 QPixmap(":/blank.png"));
chudy@google.com902ebe52012-06-29 14:21:22 +0000513 }
514}
515
516void SkDebuggerGUI::toggleDirectory() {
chudy@google.com607357f2012-08-07 16:12:23 +0000517 fDirectoryWidget.setHidden(!fDirectoryWidget.isHidden());
chudy@google.com902ebe52012-06-29 14:21:22 +0000518}
519
520void SkDebuggerGUI::toggleFilter(QString string) {
chudy@google.comc432f002012-07-10 13:19:25 +0000521 for (int row = 0; row < fListWidget.count(); row++) {
522 QListWidgetItem *item = fListWidget.item(row);
chudy@google.com607357f2012-08-07 16:12:23 +0000523 item->setHidden(item->text() != string);
chudy@google.com902ebe52012-06-29 14:21:22 +0000524 }
525}
526
527void SkDebuggerGUI::setupUi(QMainWindow *SkDebuggerGUI) {
528 QIcon windowIcon;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000529 windowIcon.addFile(QString::fromUtf8(":/skia.png"), QSize(),
chudy@google.com7dcae672012-07-09 20:26:53 +0000530 QIcon::Normal, QIcon::Off);
chudy@google.com902ebe52012-06-29 14:21:22 +0000531 SkDebuggerGUI->setObjectName(QString::fromUtf8("SkDebuggerGUI"));
532 SkDebuggerGUI->resize(1200, 1000);
533 SkDebuggerGUI->setWindowIcon(windowIcon);
chudy@google.comc432f002012-07-10 13:19:25 +0000534 SkDebuggerGUI->setWindowTitle("Skia Debugger");
chudy@google.com902ebe52012-06-29 14:21:22 +0000535
chudy@google.come504de02012-07-16 18:35:23 +0000536 fActionOpen.setShortcuts(QKeySequence::Open);
chudy@google.comc432f002012-07-10 13:19:25 +0000537 fActionOpen.setText("Open");
chudy@google.com902ebe52012-06-29 14:21:22 +0000538
539 QIcon breakpoint;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000540 breakpoint.addFile(QString::fromUtf8(":/breakpoint.png"),
chudy@google.com7dcae672012-07-09 20:26:53 +0000541 QSize(), QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000542 fActionBreakpoint.setShortcut(QKeySequence(tr("Ctrl+B")));
chudy@google.comc432f002012-07-10 13:19:25 +0000543 fActionBreakpoint.setIcon(breakpoint);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000544 fActionBreakpoint.setText("Breakpoints");
chudy@google.com902ebe52012-06-29 14:21:22 +0000545
546 QIcon cancel;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000547 cancel.addFile(QString::fromUtf8(":/reload.png"), QSize(),
chudy@google.com7dcae672012-07-09 20:26:53 +0000548 QIcon::Normal, QIcon::Off);
chudy@google.comc432f002012-07-10 13:19:25 +0000549 fActionCancel.setIcon(cancel);
550 fActionCancel.setText("Clear Filter");
chudy@google.com902ebe52012-06-29 14:21:22 +0000551
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000552 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.come504de02012-07-16 18:35:23 +0000558 fActionClose.setShortcuts(QKeySequence::Quit);
chudy@google.comc432f002012-07-10 13:19:25 +0000559 fActionClose.setText("Exit");
chudy@google.com902ebe52012-06-29 14:21:22 +0000560
chudy@google.come504de02012-07-16 18:35:23 +0000561 fActionCreateBreakpoint.setShortcut(QKeySequence(tr("B")));
562 fActionCreateBreakpoint.setText("Set Breakpoint");
563
564 fActionDelete.setShortcut(QKeySequence(tr("X")));
chudy@google.comc432f002012-07-10 13:19:25 +0000565 fActionDelete.setText("Delete Command");
chudy@google.com902ebe52012-06-29 14:21:22 +0000566
chudy@google.come504de02012-07-16 18:35:23 +0000567 fActionDirectory.setShortcut(QKeySequence(tr("Ctrl+D")));
568 fActionDirectory.setText("Directory");
chudy@google.com902ebe52012-06-29 14:21:22 +0000569
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000570 QIcon profile;
robertphillips@google.comd1636362012-11-19 18:25:09 +0000571 profile.addFile(QString::fromUtf8(":/profile.png"), QSize(),
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000572 QIcon::Normal, QIcon::Off);
573 fActionProfile.setIcon(profile);
574 fActionProfile.setText("Profile");
robertphillips@google.come099bc42012-11-19 16:26:40 +0000575 fActionProfile.setDisabled(true);
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000576
chudy@google.comc432f002012-07-10 13:19:25 +0000577 QIcon inspector;
robertphillips@google.comd1636362012-11-19 18:25:09 +0000578 inspector.addFile(QString::fromUtf8(":/inspector.png"),
chudy@google.comc432f002012-07-10 13:19:25 +0000579 QSize(), QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000580 fActionInspector.setShortcut(QKeySequence(tr("Ctrl+I")));
chudy@google.comc432f002012-07-10 13:19:25 +0000581 fActionInspector.setIcon(inspector);
chudy@google.come504de02012-07-16 18:35:23 +0000582 fActionInspector.setText("Inspector");
chudy@google.com902ebe52012-06-29 14:21:22 +0000583
chudy@google.comc432f002012-07-10 13:19:25 +0000584 QIcon play;
robertphillips@google.comd1636362012-11-19 18:25:09 +0000585 play.addFile(QString::fromUtf8(":/play.png"), QSize(),
chudy@google.comc432f002012-07-10 13:19:25 +0000586 QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000587 fActionPlay.setShortcut(QKeySequence(tr("Ctrl+P")));
chudy@google.comc432f002012-07-10 13:19:25 +0000588 fActionPlay.setIcon(play);
589 fActionPlay.setText("Play");
chudy@google.com902ebe52012-06-29 14:21:22 +0000590
chudy@google.come504de02012-07-16 18:35:23 +0000591 QIcon pause;
robertphillips@google.comd1636362012-11-19 18:25:09 +0000592 pause.addFile(QString::fromUtf8(":/pause.png"), QSize(),
chudy@google.comc432f002012-07-10 13:19:25 +0000593 QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000594 fActionPause.setShortcut(QKeySequence(tr("Space")));
595 fActionPause.setCheckable(true);
596 fActionPause.setIcon(pause);
597 fActionPause.setText("Pause");
598
chudy@google.comc432f002012-07-10 13:19:25 +0000599 QIcon rewind;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000600 rewind.addFile(QString::fromUtf8(":/rewind.png"), QSize(),
chudy@google.comc432f002012-07-10 13:19:25 +0000601 QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000602 fActionRewind.setShortcut(QKeySequence(tr("Ctrl+R")));
chudy@google.comc432f002012-07-10 13:19:25 +0000603 fActionRewind.setIcon(rewind);
604 fActionRewind.setText("Rewind");
chudy@google.com902ebe52012-06-29 14:21:22 +0000605
chudy@google.com0ab03392012-07-28 20:16:11 +0000606 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.com7e4cfbf2012-07-17 15:40:51 +0000613 fActionShowDeletes.setShortcut(QKeySequence(tr("Ctrl+X")));
614 fActionShowDeletes.setText("Deleted Commands");
615
chudy@google.comc432f002012-07-10 13:19:25 +0000616 QIcon stepBack;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000617 stepBack.addFile(QString::fromUtf8(":/previous.png"), QSize(),
chudy@google.comc432f002012-07-10 13:19:25 +0000618 QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000619 fActionStepBack.setShortcut(QKeySequence(tr("[")));
chudy@google.comc432f002012-07-10 13:19:25 +0000620 fActionStepBack.setIcon(stepBack);
621 fActionStepBack.setText("Step Back");
chudy@google.com902ebe52012-06-29 14:21:22 +0000622
chudy@google.comc432f002012-07-10 13:19:25 +0000623 QIcon stepForward;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000624 stepForward.addFile(QString::fromUtf8(":/next.png"),
chudy@google.comc432f002012-07-10 13:19:25 +0000625 QSize(), QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000626 fActionStepForward.setShortcut(QKeySequence(tr("]")));
chudy@google.comc432f002012-07-10 13:19:25 +0000627 fActionStepForward.setIcon(stepForward);
628 fActionStepForward.setText("Step Forward");
629
chudy@google.coma1226312012-07-26 20:26:44 +0000630 fActionZoomIn.setShortcut(QKeySequence(tr("Ctrl+=")));
631 fActionZoomIn.setText("Zoom In");
632 fActionZoomOut.setShortcut(QKeySequence(tr("Ctrl+-")));
633 fActionZoomOut.setText("Zoom Out");
634
chudy@google.comc432f002012-07-10 13:19:25 +0000635 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.com7dcae672012-07-09 20:26:53 +0000645 QSizePolicy::Expanding);
chudy@google.com902ebe52012-06-29 14:21:22 +0000646
chudy@google.comc432f002012-07-10 13:19:25 +0000647 fInspectorWidget.setSizePolicy(QSizePolicy::Expanding,
chudy@google.com7dcae672012-07-09 20:26:53 +0000648 QSizePolicy::Expanding);
chudy@google.comc432f002012-07-10 13:19:25 +0000649 fInspectorWidget.setMaximumHeight(300);
chudy@google.com902ebe52012-06-29 14:21:22 +0000650
chudy@google.comc432f002012-07-10 13:19:25 +0000651 fSettingsWidget.setSizePolicy(QSizePolicy::Expanding,
652 QSizePolicy::Expanding);
653 fSettingsWidget.setMaximumWidth(250);
chudy@google.com902ebe52012-06-29 14:21:22 +0000654
chudy@google.comc432f002012-07-10 13:19:25 +0000655 fLeftColumnLayout.setSpacing(6);
656 fLeftColumnLayout.addWidget(&fListWidget);
657 fLeftColumnLayout.addWidget(&fDirectoryWidget);
chudy@google.com902ebe52012-06-29 14:21:22 +0000658
chudy@google.comc432f002012-07-10 13:19:25 +0000659 fCanvasAndSettingsLayout.setSpacing(6);
660 fCanvasAndSettingsLayout.addWidget(&fCanvasWidget);
661 fCanvasAndSettingsLayout.addWidget(&fSettingsWidget);
chudy@google.com902ebe52012-06-29 14:21:22 +0000662
chudy@google.comc432f002012-07-10 13:19:25 +0000663 fMainAndRightColumnLayout.setSpacing(6);
664 fMainAndRightColumnLayout.addLayout(&fCanvasAndSettingsLayout);
665 fMainAndRightColumnLayout.addWidget(&fInspectorWidget);
chudy@google.com902ebe52012-06-29 14:21:22 +0000666
chudy@google.com2d537a12012-07-31 12:49:52 +0000667 fCentralWidget.setLayout(&fContainerLayout);
chudy@google.comc432f002012-07-10 13:19:25 +0000668 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.come504de02012-07-16 18:35:23 +0000676 fToolBar.setIconSize(QSize(32, 32));
chudy@google.comc432f002012-07-10 13:19:25 +0000677 fToolBar.setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
678 SkDebuggerGUI->addToolBar(Qt::TopToolBarArea, &fToolBar);
chudy@google.com902ebe52012-06-29 14:21:22 +0000679
chudy@google.com0ab03392012-07-28 20:16:11 +0000680 fSpacer.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
chudy@google.com902ebe52012-06-29 14:21:22 +0000681
chudy@google.comc432f002012-07-10 13:19:25 +0000682 fToolBar.addAction(&fActionRewind);
683 fToolBar.addAction(&fActionStepBack);
chudy@google.come504de02012-07-16 18:35:23 +0000684 fToolBar.addAction(&fActionPause);
chudy@google.comc432f002012-07-10 13:19:25 +0000685 fToolBar.addAction(&fActionStepForward);
686 fToolBar.addAction(&fActionPlay);
687 fToolBar.addSeparator();
chudy@google.come504de02012-07-16 18:35:23 +0000688 fToolBar.addAction(&fActionInspector);
chudy@google.comc432f002012-07-10 13:19:25 +0000689 fToolBar.addSeparator();
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000690 fToolBar.addAction(&fActionProfile);
691
692 fToolBar.addSeparator();
chudy@google.com0ab03392012-07-28 20:16:11 +0000693 fToolBar.addWidget(&fSpacer);
chudy@google.comc432f002012-07-10 13:19:25 +0000694 fToolBar.addWidget(&fFilter);
695 fToolBar.addAction(&fActionCancel);
chudy@google.com902ebe52012-06-29 14:21:22 +0000696
697 // TODO(chudy): Remove static call.
698 fDirectoryWidgetActive = false;
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000699 fPath = "";
700 fFileName = "";
chudy@google.com902ebe52012-06-29 14:21:22 +0000701 setupDirectoryWidget();
702 fDirectoryWidgetActive = true;
703
chudy@google.com902ebe52012-06-29 14:21:22 +0000704 // Menu Bar
chudy@google.comc432f002012-07-10 13:19:25 +0000705 fMenuFile.setTitle("File");
706 fMenuFile.addAction(&fActionOpen);
chudy@google.com0ab03392012-07-28 20:16:11 +0000707 fMenuFile.addAction(&fActionSave);
708 fMenuFile.addAction(&fActionSaveAs);
chudy@google.comc432f002012-07-10 13:19:25 +0000709 fMenuFile.addAction(&fActionClose);
chudy@google.come504de02012-07-16 18:35:23 +0000710
711 fMenuEdit.setTitle("Edit");
712 fMenuEdit.addAction(&fActionDelete);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000713 fMenuEdit.addAction(&fActionClearDeletes);
714 fMenuEdit.addSeparator();
chudy@google.come504de02012-07-16 18:35:23 +0000715 fMenuEdit.addAction(&fActionCreateBreakpoint);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000716 fMenuEdit.addAction(&fActionClearBreakpoints);
chudy@google.come504de02012-07-16 18:35:23 +0000717
chudy@google.comc432f002012-07-10 13:19:25 +0000718 fMenuNavigate.setTitle("Navigate");
chudy@google.come504de02012-07-16 18:35:23 +0000719 fMenuNavigate.addAction(&fActionRewind);
720 fMenuNavigate.addAction(&fActionStepBack);
721 fMenuNavigate.addAction(&fActionStepForward);
722 fMenuNavigate.addAction(&fActionPlay);
723 fMenuNavigate.addAction(&fActionPause);
chudy@google.comc432f002012-07-10 13:19:25 +0000724 fMenuNavigate.addAction(&fActionGoToLine);
chudy@google.come504de02012-07-16 18:35:23 +0000725
chudy@google.comc432f002012-07-10 13:19:25 +0000726 fMenuView.setTitle("View");
chudy@google.come504de02012-07-16 18:35:23 +0000727 fMenuView.addAction(&fActionBreakpoint);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000728 fMenuView.addAction(&fActionShowDeletes);
chudy@google.coma1226312012-07-26 20:26:44 +0000729 fMenuView.addAction(&fActionZoomIn);
730 fMenuView.addAction(&fActionZoomOut);
chudy@google.come504de02012-07-16 18:35:23 +0000731
732 fMenuWindows.setTitle("Window");
733 fMenuWindows.addAction(&fActionInspector);
734 fMenuWindows.addAction(&fActionDirectory);
chudy@google.comc432f002012-07-10 13:19:25 +0000735
736 fActionGoToLine.setText("Go to Line...");
737 fActionGoToLine.setDisabled(true);
738 fMenuBar.addAction(fMenuFile.menuAction());
chudy@google.come504de02012-07-16 18:35:23 +0000739 fMenuBar.addAction(fMenuEdit.menuAction());
chudy@google.comc432f002012-07-10 13:19:25 +0000740 fMenuBar.addAction(fMenuView.menuAction());
741 fMenuBar.addAction(fMenuNavigate.menuAction());
chudy@google.come504de02012-07-16 18:35:23 +0000742 fMenuBar.addAction(fMenuWindows.menuAction());
chudy@google.com902ebe52012-06-29 14:21:22 +0000743
chudy@google.com7dcae672012-07-09 20:26:53 +0000744 fPause = false;
745
chudy@google.comc432f002012-07-10 13:19:25 +0000746 SkDebuggerGUI->setMenuBar(&fMenuBar);
chudy@google.com902ebe52012-06-29 14:21:22 +0000747 QMetaObject::connectSlotsByName(SkDebuggerGUI);
748}
749
750void SkDebuggerGUI::setupDirectoryWidget() {
chudy@google.comc432f002012-07-10 13:19:25 +0000751 QDir dir(fPath);
chudy@google.com902ebe52012-06-29 14:21:22 +0000752 QRegExp r(".skp");
chudy@google.comc432f002012-07-10 13:19:25 +0000753 fDirectoryWidget.clear();
754 const QStringList files = dir.entryList();
chudy@google.com902ebe52012-06-29 14:21:22 +0000755 foreach (QString f, files) {
chudy@google.com7dcae672012-07-09 20:26:53 +0000756 if (f.contains(r))
chudy@google.comc432f002012-07-10 13:19:25 +0000757 fDirectoryWidget.addItem(f);
chudy@google.com902ebe52012-06-29 14:21:22 +0000758 }
759}
760
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000761// SkOffsetPicturePlayback records the offset of each command in the picture.
762// These are needed by the profiling system.
763class SkOffsetPicturePlayback : public SkPicturePlayback {
764public:
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
772protected:
773 SkTDArray<size_t> fOffsets;
774
775 virtual void preDraw(size_t offset, int type) {
776 *fOffsets.append() = offset;
777 }
778
779private:
780 typedef SkPicturePlayback INHERITED;
781};
782
783// Picture to wrap an SkOffsetPicturePlayback.
784class SkOffsetPicture : public SkPicture {
785public:
skia.committer@gmail.com884e60b2012-11-16 02:01:17 +0000786 SkOffsetPicture(SkStream* stream,
787 bool* success,
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000788 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.com884e60b2012-11-16 02:01:17 +0000823 const SkTDArray<size_t>& offsets() const {
824 return ((SkOffsetPicturePlayback*) fPlayback)->offsets();
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000825 }
826
827private:
828 typedef SkPicture INHERITED;
829};
830
831
832
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000833void SkDebuggerGUI::loadPicture(const SkString& fileName) {
834 fFileName = fileName;
chudy@google.comd3058f52012-07-19 13:41:27 +0000835 fLoading = true;
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000836 SkStream* stream = SkNEW_ARGS(SkFILEStream, (fileName.c_str()));
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000837 SkOffsetPicture* picture = SkNEW_ARGS(SkOffsetPicture, (stream, NULL, &SkImageDecoder::DecodeStream));
838
chudy@google.com686e6802012-08-14 16:00:32 +0000839 fCanvasWidget.resetWidgetTransform();
chudy@google.com607357f2012-08-07 16:12:23 +0000840 fDebugger.loadPicture(picture);
chudy@google.com4c7962e2012-08-14 19:38:31 +0000841
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000842 fOffsets = picture->offsets();
843
chudy@google.com607357f2012-08-07 16:12:23 +0000844 SkSafeUnref(stream);
845 SkSafeUnref(picture);
846
chudy@google.com97cee972012-08-07 20:41:37 +0000847 // Will this automatically clear out due to nature of refcnt?
848 SkTDArray<SkString*>* commands = fDebugger.getDrawCommands();
chudy@google.com607357f2012-08-07 16:12:23 +0000849
robertphillips@google.comfe830a42012-11-15 16:33:31 +0000850 // 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.come099bc42012-11-19 16:26:40 +0000853 if (commands->count() == fOffsets.count()) {
854 fActionProfile.setDisabled(false);
robertphillips@google.comfe830a42012-11-15 16:33:31 +0000855 }
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000856
chudy@google.com7dcae672012-07-09 20:26:53 +0000857 /* fDebugCanvas is reinitialized every load picture. Need it to retain value
chudy@google.com607357f2012-08-07 16:12:23 +0000858 * 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.com97cee972012-08-07 20:41:37 +0000864 setupListWidget(commands);
865 setupComboBox(commands);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000866 fInspectorWidget.setDisabled(false);
chudy@google.come606d6e2012-07-12 14:31:25 +0000867 fSettingsWidget.setDisabled(false);
chudy@google.comd3058f52012-07-19 13:41:27 +0000868 fMenuEdit.setDisabled(false);
869 fMenuNavigate.setDisabled(false);
870 fMenuView.setDisabled(false);
chudy@google.com0ab03392012-07-28 20:16:11 +0000871 fActionSave.setDisabled(false);
872 fActionSaveAs.setDisabled(false);
chudy@google.comd3058f52012-07-19 13:41:27 +0000873 fLoading = false;
874 actionPlay();
chudy@google.com902ebe52012-06-29 14:21:22 +0000875}
876
chudy@google.com97cee972012-08-07 20:41:37 +0000877void SkDebuggerGUI::setupListWidget(SkTDArray<SkString*>* command) {
chudy@google.comc432f002012-07-10 13:19:25 +0000878 fListWidget.clear();
chudy@google.com902ebe52012-06-29 14:21:22 +0000879 int counter = 0;
robertphillips@google.com30d35f22012-11-06 16:45:36 +0000880 int indent = 0;
chudy@google.com97cee972012-08-07 20:41:37 +0000881 for (int i = 0; i < command->count(); i++) {
chudy@google.com902ebe52012-06-29 14:21:22 +0000882 QListWidgetItem *item = new QListWidgetItem();
chudy@google.com97cee972012-08-07 20:41:37 +0000883 item->setData(Qt::DisplayRole, (*command)[i]->c_str());
chudy@google.com902ebe52012-06-29 14:21:22 +0000884 item->setData(Qt::UserRole + 1, counter++);
robertphillips@google.com30d35f22012-11-06 16:45:36 +0000885
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.comd26c7062012-11-12 20:42:12 +0000897 item->setData(Qt::UserRole + 4, -1.0);
898
chudy@google.comc432f002012-07-10 13:19:25 +0000899 fListWidget.addItem(item);
chudy@google.com902ebe52012-06-29 14:21:22 +0000900 }
901}
902
chudy@google.com97cee972012-08-07 20:41:37 +0000903void SkDebuggerGUI::setupComboBox(SkTDArray<SkString*>* command) {
chudy@google.comc432f002012-07-10 13:19:25 +0000904 fFilter.clear();
905 fFilter.addItem("--Filter By Available Commands--");
chudy@google.com902ebe52012-06-29 14:21:22 +0000906
907 std::map<std::string, int> map;
chudy@google.com97cee972012-08-07 20:41:37 +0000908 for (int i = 0; i < command->count(); i++) {
909 map[(*command)[i]->c_str()]++;
chudy@google.com902ebe52012-06-29 14:21:22 +0000910 }
911
912 QString overview;
chudy@google.com607357f2012-08-07 16:12:23 +0000913 int counter = 0;
chudy@google.com7dcae672012-07-09 20:26:53 +0000914 for (std::map<std::string, int>::iterator it = map.begin(); it != map.end();
915 ++it) {
chudy@google.com902ebe52012-06-29 14:21:22 +0000916 overview.append((it->first).c_str());
917 overview.append(": ");
918 overview.append(QString::number(it->second));
919 overview.append("<br/>");
chudy@google.com7dcae672012-07-09 20:26:53 +0000920 counter += it->second;
chudy@google.comc432f002012-07-10 13:19:25 +0000921 fFilter.addItem((it->first).c_str());
chudy@google.com902ebe52012-06-29 14:21:22 +0000922 }
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.com607357f2012-08-07 16:12:23 +0000930 overview.append("SkPicture Width: ");
chudy@google.com902ebe52012-06-29 14:21:22 +0000931 // NOTE(chudy): This is where we can pull out the SkPictures width.
chudy@google.com607357f2012-08-07 16:12:23 +0000932 overview.append(QString::number(fDebugger.pictureWidth()));
chudy@google.com902ebe52012-06-29 14:21:22 +0000933 overview.append("px<br/>");
chudy@google.com607357f2012-08-07 16:12:23 +0000934 overview.append("SkPicture Height: ");
935 overview.append(QString::number(fDebugger.pictureHeight()));
chudy@google.com902ebe52012-06-29 14:21:22 +0000936 overview.append("px");
chudy@google.com6bd109a2012-08-14 19:34:13 +0000937 fInspectorWidget.setText(overview, SkInspectorWidget::kOverview_TabType);
chudy@google.com902ebe52012-06-29 14:21:22 +0000938
939 // NOTE(chudy): Makes first item unselectable.
chudy@google.com7dcae672012-07-09 20:26:53 +0000940 QStandardItemModel* model = qobject_cast<QStandardItemModel*>(
chudy@google.comc432f002012-07-10 13:19:25 +0000941 fFilter.model());
942 QModelIndex firstIndex = model->index(0, fFilter.modelColumn(),
943 fFilter.rootModelIndex());
chudy@google.com902ebe52012-06-29 14:21:22 +0000944 QStandardItem* firstItem = model->itemFromIndex(firstIndex);
945 firstItem->setSelectable(false);
946}