blob: d3c6fadbd039c0f2780362ba46f429f503dcb46f [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 "PictureRenderer.h"
robertphillips@google.com2bde91d2012-11-15 14:57:57 +000013#include "SkPictureRecord.h"
14#include "SkPicturePlayback.h"
robertphillips@google.come174a8b2012-11-27 16:04:42 +000015
16#if defined(SK_BUILD_FOR_WIN32)
17 #include "BenchSysTimer_windows.h"
18#elif defined(SK_BUILD_FOR_MAC)
19 #include "BenchSysTimer_mach.h"
20#elif defined(SK_BUILD_FOR_UNIX) || defined(SK_BUILD_FOR_ANDROID)
21 #include "BenchSysTimer_posix.h"
22#else
23 #include "BenchSysTimer_c.h"
24#endif
25
chudy@google.com902ebe52012-06-29 14:21:22 +000026
27SkDebuggerGUI::SkDebuggerGUI(QWidget *parent) :
chudy@google.comc432f002012-07-10 13:19:25 +000028 QMainWindow(parent)
chudy@google.com2d537a12012-07-31 12:49:52 +000029 , fCentralWidget(this)
30 , fStatusBar(this)
31 , fToolBar(this)
chudy@google.comc432f002012-07-10 13:19:25 +000032 , fActionOpen(this)
33 , fActionBreakpoint(this)
robertphillips@google.comd26c7062012-11-12 20:42:12 +000034 , fActionProfile(this)
chudy@google.comc432f002012-07-10 13:19:25 +000035 , fActionCancel(this)
chudy@google.com7e4cfbf2012-07-17 15:40:51 +000036 , fActionClearBreakpoints(this)
chudy@google.come504de02012-07-16 18:35:23 +000037 , fActionClearDeletes(this)
chudy@google.comc432f002012-07-10 13:19:25 +000038 , fActionClose(this)
chudy@google.come504de02012-07-16 18:35:23 +000039 , fActionCreateBreakpoint(this)
chudy@google.comc432f002012-07-10 13:19:25 +000040 , fActionDelete(this)
41 , fActionDirectory(this)
42 , fActionGoToLine(this)
43 , fActionInspector(this)
44 , fActionPlay(this)
chudy@google.come504de02012-07-16 18:35:23 +000045 , fActionPause(this)
chudy@google.comc432f002012-07-10 13:19:25 +000046 , fActionRewind(this)
chudy@google.com0ab03392012-07-28 20:16:11 +000047 , fActionSave(this)
48 , fActionSaveAs(this)
chudy@google.com7e4cfbf2012-07-17 15:40:51 +000049 , fActionShowDeletes(this)
chudy@google.comc432f002012-07-10 13:19:25 +000050 , fActionStepBack(this)
51 , fActionStepForward(this)
chudy@google.coma1226312012-07-26 20:26:44 +000052 , fActionZoomIn(this)
53 , fActionZoomOut(this)
54 , fMapper(this)
chudy@google.comc432f002012-07-10 13:19:25 +000055 , fListWidget(&fCentralWidget)
56 , fDirectoryWidget(&fCentralWidget)
chudy@google.com607357f2012-08-07 16:12:23 +000057 , fCanvasWidget(this, &fDebugger)
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +000058 , fImageWidget(&fDebugger)
chudy@google.comc432f002012-07-10 13:19:25 +000059 , fMenuBar(this)
60 , fMenuFile(this)
61 , fMenuNavigate(this)
62 , fMenuView(this)
chudy@google.com7e4cfbf2012-07-17 15:40:51 +000063 , fBreakpointsActivated(false)
64 , fDeletesActivated(false)
65 , fPause(false)
chudy@google.comd3058f52012-07-19 13:41:27 +000066 , fLoading(false)
chudy@google.comc432f002012-07-10 13:19:25 +000067{
chudy@google.com902ebe52012-06-29 14:21:22 +000068 setupUi(this);
robertphillips@google.comdd4b7452013-01-22 19:38:46 +000069 fListWidget.setSelectionMode(QAbstractItemView::ExtendedSelection);
chudy@google.comea5488b2012-07-26 19:38:22 +000070 connect(&fListWidget, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)), this, SLOT(registerListClick(QListWidgetItem *)));
chudy@google.comc432f002012-07-10 13:19:25 +000071 connect(&fActionOpen, SIGNAL(triggered()), this, SLOT(openFile()));
chudy@google.comea5488b2012-07-26 19:38:22 +000072 connect(&fActionDirectory, SIGNAL(triggered()), this, SLOT(toggleDirectory()));
73 connect(&fDirectoryWidget, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)), this, SLOT(loadFile(QListWidgetItem *)));
chudy@google.comc432f002012-07-10 13:19:25 +000074 connect(&fActionDelete, SIGNAL(triggered()), this, SLOT(actionDelete()));
chudy@google.comea5488b2012-07-26 19:38:22 +000075 connect(&fListWidget, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(toggleBreakpoint()));
chudy@google.comc432f002012-07-10 13:19:25 +000076 connect(&fActionRewind, SIGNAL(triggered()), this, SLOT(actionRewind()));
77 connect(&fActionPlay, SIGNAL(triggered()), this, SLOT(actionPlay()));
78 connect(&fActionStepBack, SIGNAL(triggered()), this, SLOT(actionStepBack()));
chudy@google.comea5488b2012-07-26 19:38:22 +000079 connect(&fActionStepForward, SIGNAL(triggered()), this, SLOT(actionStepForward()));
80 connect(&fActionBreakpoint, SIGNAL(triggered()), this, SLOT(actionBreakpoints()));
81 connect(&fActionInspector, SIGNAL(triggered()), this, SLOT(actionInspector()));
82 connect(&fActionInspector, SIGNAL(triggered()), this, SLOT(actionSettings()));
83 connect(&fFilter, SIGNAL(activated(QString)), this, SLOT(toggleFilter(QString)));
robertphillips@google.comd26c7062012-11-12 20:42:12 +000084 connect(&fActionProfile, SIGNAL(triggered()), this, SLOT(actionProfile()));
chudy@google.comc432f002012-07-10 13:19:25 +000085 connect(&fActionCancel, SIGNAL(triggered()), this, SLOT(actionCancel()));
chudy@google.com7e4cfbf2012-07-17 15:40:51 +000086 connect(&fActionClearBreakpoints, SIGNAL(triggered()), this, SLOT(actionClearBreakpoints()));
87 connect(&fActionClearDeletes, SIGNAL(triggered()), this, SLOT(actionClearDeletes()));
chudy@google.comc432f002012-07-10 13:19:25 +000088 connect(&fActionClose, SIGNAL(triggered()), this, SLOT(actionClose()));
chudy@google.comea5488b2012-07-26 19:38:22 +000089 connect(fSettingsWidget.getVisibilityButton(), SIGNAL(toggled(bool)), this, SLOT(actionCommandFilter()));
robertphillips@google.come8fe4bc2013-02-13 13:26:13 +000090#if SK_SUPPORT_GPU
chudy@google.comea5488b2012-07-26 19:38:22 +000091 connect(fSettingsWidget.getGLCheckBox(), SIGNAL(toggled(bool)), this, SLOT(actionGLWidget(bool)));
robertphillips@google.come8fe4bc2013-02-13 13:26:13 +000092#endif
chudy@google.comea5488b2012-07-26 19:38:22 +000093 connect(fSettingsWidget.getRasterCheckBox(), SIGNAL(toggled(bool)), this, SLOT(actionRasterWidget(bool)));
robertphillips@google.comf4741c12013-02-06 20:13:54 +000094 connect(fSettingsWidget.getOverdrawVizCheckBox(), SIGNAL(toggled(bool)), this, SLOT(actionOverdrawVizWidget(bool)));
chudy@google.comea5488b2012-07-26 19:38:22 +000095 connect(&fActionPause, SIGNAL(toggled(bool)), this, SLOT(pauseDrawing(bool)));
chudy@google.come504de02012-07-16 18:35:23 +000096 connect(&fActionCreateBreakpoint, SIGNAL(activated()), this, SLOT(toggleBreakpoint()));
chudy@google.com7e4cfbf2012-07-17 15:40:51 +000097 connect(&fActionShowDeletes, SIGNAL(triggered()), this, SLOT(showDeletes()));
chudy@google.comea5488b2012-07-26 19:38:22 +000098 connect(&fCanvasWidget, SIGNAL(hitChanged(int)), this, SLOT(selectCommand(int)));
99 connect(&fCanvasWidget, SIGNAL(hitChanged(int)), &fSettingsWidget, SLOT(updateHit(int)));
100 connect(&fCanvasWidget, SIGNAL(scaleFactorChanged(float)), this, SLOT(actionScale(float)));
101 connect(&fCanvasWidget, SIGNAL(commandChanged(int)), &fSettingsWidget, SLOT(updateCommand(int)));
chudy@google.com0ab03392012-07-28 20:16:11 +0000102 connect(&fActionSaveAs, SIGNAL(triggered()), this, SLOT(actionSaveAs()));
103 connect(&fActionSave, SIGNAL(triggered()), this, SLOT(actionSave()));
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000104
bungeman@google.come8cc6e82013-01-17 16:30:56 +0000105 fMapper.setMapping(&fActionZoomIn, SkCanvasWidget::kIn_ZoomCommand);
106 fMapper.setMapping(&fActionZoomOut, SkCanvasWidget::kOut_ZoomCommand);
chudy@google.coma1226312012-07-26 20:26:44 +0000107
108 connect(&fActionZoomIn, SIGNAL(triggered()), &fMapper, SLOT(map()));
109 connect(&fActionZoomOut, SIGNAL(triggered()), &fMapper, SLOT(map()));
bungeman@google.come8cc6e82013-01-17 16:30:56 +0000110 connect(&fMapper, SIGNAL(mapped(int)), &fCanvasWidget, SLOT(zoom(int)));
chudy@google.coma1226312012-07-26 20:26:44 +0000111
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000112 fInspectorWidget.setDisabled(true);
chudy@google.comd3058f52012-07-19 13:41:27 +0000113 fMenuEdit.setDisabled(true);
114 fMenuNavigate.setDisabled(true);
115 fMenuView.setDisabled(true);
chudy@google.combbad34d2012-08-13 14:26:36 +0000116
117 SkGraphics::Init();
chudy@google.com902ebe52012-06-29 14:21:22 +0000118}
119
chudy@google.combbad34d2012-08-13 14:26:36 +0000120SkDebuggerGUI::~SkDebuggerGUI() {
121 SkGraphics::Term();
122}
chudy@google.com902ebe52012-06-29 14:21:22 +0000123
124void SkDebuggerGUI::actionBreakpoints() {
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000125 fBreakpointsActivated = !fBreakpointsActivated;
chudy@google.comc432f002012-07-10 13:19:25 +0000126 for (int row = 0; row < fListWidget.count(); row++) {
127 QListWidgetItem *item = fListWidget.item(row);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000128 item->setHidden(item->checkState() == Qt::Unchecked && fBreakpointsActivated);
129 }
130}
chudy@google.com902ebe52012-06-29 14:21:22 +0000131
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000132void SkDebuggerGUI::showDeletes() {
133 fDeletesActivated = !fDeletesActivated;
134 for (int row = 0; row < fListWidget.count(); row++) {
135 QListWidgetItem *item = fListWidget.item(row);
chudy@google.com607357f2012-08-07 16:12:23 +0000136 item->setHidden(fDebugger.isCommandVisible(row)
137 && fDeletesActivated);
chudy@google.com902ebe52012-06-29 14:21:22 +0000138 }
139}
140
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000141// The timed picture playback uses the SkPicturePlayback's profiling stubs
142// to time individual commands. The offsets are needed to map SkPicture
143// offsets to individual commands.
144class SkTimedPicturePlayback : public SkPicturePlayback {
145public:
scroggo@google.com12d588a2013-02-25 16:05:00 +0000146 SkTimedPicturePlayback(SkStream* stream, const SkPictInfo& info,
scroggo@google.comf8d7d272013-02-22 21:38:35 +0000147 SkPicture::InstallPixelRefProc proc, const SkTDArray<size_t>& offsets,
robertphillips@google.com5f971142012-12-07 20:48:56 +0000148 const SkTDArray<bool>& deletedCommands)
scroggo@google.com12d588a2013-02-25 16:05:00 +0000149 : INHERITED(stream, info, proc)
robertphillips@google.com5f971142012-12-07 20:48:56 +0000150 , fOffsets(offsets)
bungeman@google.come8cc6e82013-01-17 16:30:56 +0000151 , fSkipCommands(deletedCommands)
152 , fTot(0.0)
153 , fCurCommand(0) {
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000154 fTimes.setCount(fOffsets.count());
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000155 fTypeTimes.setCount(LAST_DRAWTYPE_ENUM+1);
156 this->resetTimes();
157 }
158
159 void resetTimes() {
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000160 for (int i = 0; i < fOffsets.count(); ++i) {
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000161 fTimes[i] = 0.0;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000162 }
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000163 for (int i = 0; i < fTypeTimes.count(); ++i) {
164 fTypeTimes[i] = 0.0f;
165 }
166 fTot = 0.0;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000167 }
168
169 int count() const { return fTimes.count(); }
170
171 double time(int index) const { return fTimes[index] / fTot; }
172
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000173 const SkTDArray<double>* typeTimes() const { return &fTypeTimes; }
174
175 double totTime() const { return fTot; }
176
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000177protected:
robertphillips@google.come174a8b2012-11-27 16:04:42 +0000178 BenchSysTimer fTimer;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000179 SkTDArray<size_t> fOffsets; // offset in the SkPicture for each command
robertphillips@google.com5f971142012-12-07 20:48:56 +0000180 SkTDArray<bool> fSkipCommands; // has the command been deleted in the GUI?
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000181 SkTDArray<double> fTimes; // sum of time consumed for each command
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000182 SkTDArray<double> fTypeTimes; // sum of time consumed for each type of command (e.g., drawPath)
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000183 double fTot; // total of all times in 'fTimes'
184 size_t fCurOffset;
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000185 int fCurType;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000186 int fCurCommand; // the current command being executed/timed
187
robertphillips@google.comca47aae2012-12-12 15:58:25 +0000188 virtual size_t preDraw(size_t offset, int type) {
skia.committer@gmail.com884e60b2012-11-16 02:01:17 +0000189 // This search isn't as bad as it seems. In normal playback mode, the
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000190 // base class steps through the commands in order and can only skip ahead
skia.committer@gmail.com884e60b2012-11-16 02:01:17 +0000191 // a bit on a clip. This class is only used during profiling so we
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000192 // don't have to worry about forward/backward scrubbing through commands.
193 for (int i = 0; offset != fOffsets[fCurCommand]; ++i) {
194 fCurCommand = (fCurCommand+1) % fOffsets.count();
195 SkASSERT(i <= fOffsets.count()); // should always find the offset in the list
196 }
197
robertphillips@google.com5f971142012-12-07 20:48:56 +0000198 if (fSkipCommands[fCurCommand]) {
199 while (fCurCommand < fSkipCommands.count() && fSkipCommands[fCurCommand]) {
200 ++fCurCommand;
201 }
202 if (fCurCommand == fSkipCommands.count()) {
203 // Signal SkPicturePlayback to stop playing back
204 return SK_MaxU32;
205 }
206 return fOffsets[fCurCommand];
207 }
208
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000209 fCurOffset = offset;
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000210 fCurType = type;
211 // The SkDebugCanvas doesn't recognize these types. This class needs to
212 // convert or else we'll wind up with a mismatch between the type counts
213 // the debugger displays and the profile times.
214 if (DRAW_POS_TEXT_TOP_BOTTOM == type) {
215 fCurType = DRAW_POS_TEXT;
216 } else if (DRAW_POS_TEXT_H_TOP_BOTTOM == type) {
217 fCurType = DRAW_POS_TEXT_H;
218 }
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000219
robertphillips@google.come174a8b2012-11-27 16:04:42 +0000220#if defined(SK_BUILD_FOR_WIN32)
221 // CPU timer doesn't work well on Windows
222 fTimer.startWall();
223#else
224 fTimer.startCpu();
225#endif
robertphillips@google.com5f971142012-12-07 20:48:56 +0000226
227 return 0;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000228 }
229
robertphillips@google.comca47aae2012-12-12 15:58:25 +0000230 virtual void postDraw(size_t offset) {
robertphillips@google.come174a8b2012-11-27 16:04:42 +0000231#if defined(SK_BUILD_FOR_WIN32)
232 // CPU timer doesn't work well on Windows
233 double time = fTimer.endWall();
234#else
235 double time = fTimer.endCpu();
236#endif
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000237
238 SkASSERT(offset == fCurOffset);
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000239 SkASSERT(fCurType <= LAST_DRAWTYPE_ENUM);
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000240
robertphillips@google.come174a8b2012-11-27 16:04:42 +0000241 fTimes[fCurCommand] += time;
242 fTypeTimes[fCurType] += time;
243 fTot += time;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000244 }
245
246private:
247 typedef SkPicturePlayback INHERITED;
248};
249
250// Wrap SkPicture to allow installation of an SkTimedPicturePlayback object
251class SkTimedPicture : public SkPicture {
252public:
scroggo@google.com9f123162013-02-22 22:37:31 +0000253 explicit SkTimedPicture(SkStream* stream, bool* success, SkPicture::InstallPixelRefProc proc,
robertphillips@google.com5f971142012-12-07 20:48:56 +0000254 const SkTDArray<size_t>& offsets,
255 const SkTDArray<bool>& deletedCommands) {
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000256 if (success) {
257 *success = false;
258 }
259 fRecord = NULL;
260 fPlayback = NULL;
261 fWidth = fHeight = 0;
262
263 SkPictInfo info;
264
265 if (!stream->read(&info, sizeof(info))) {
266 return;
267 }
268 if (SkPicture::PICTURE_VERSION != info.fVersion) {
269 return;
270 }
271
272 if (stream->readBool()) {
skia.committer@gmail.com884e60b2012-11-16 02:01:17 +0000273 fPlayback = SkNEW_ARGS(SkTimedPicturePlayback,
scroggo@google.com12d588a2013-02-25 16:05:00 +0000274 (stream, info, proc, offsets, deletedCommands));
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000275 }
276
277 // do this at the end, so that they will be zero if we hit an error.
278 fWidth = info.fWidth;
279 fHeight = info.fHeight;
280 if (success) {
281 *success = true;
282 }
283 }
284
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000285 void resetTimes() { ((SkTimedPicturePlayback*) fPlayback)->resetTimes(); }
286
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000287 int count() const { return ((SkTimedPicturePlayback*) fPlayback)->count(); }
288
289 // return the fraction of the total time this command consumed
290 double time(int index) const { return ((SkTimedPicturePlayback*) fPlayback)->time(index); }
291
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000292 const SkTDArray<double>* typeTimes() const { return ((SkTimedPicturePlayback*) fPlayback)->typeTimes(); }
293
294 double totTime() const { return ((SkTimedPicturePlayback*) fPlayback)->totTime(); }
295
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000296private:
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000297 // disallow default ctor b.c. we don't have a good way to setup the fPlayback ptr
298 SkTimedPicture();
299 // disallow the copy ctor - enabling would require copying code from SkPicture
300 SkTimedPicture(const SkTimedPicture& src);
301
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000302 typedef SkPicture INHERITED;
303};
304
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000305// This is a simplification of PictureBenchmark's run with the addition of
306// clearing of the times after the first pass (in resetTimes)
skia.committer@gmail.com34587162012-11-20 02:01:23 +0000307void SkDebuggerGUI::run(SkTimedPicture* pict,
308 sk_tools::PictureRenderer* renderer,
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000309 int repeats) {
310 SkASSERT(pict);
311 if (NULL == pict) {
312 return;
313 }
314
315 SkASSERT(renderer != NULL);
316 if (NULL == renderer) {
317 return;
318 }
319
320 renderer->init(pict);
321
322 renderer->setup();
323 renderer->render(NULL);
jvanverth@google.comade32662013-01-28 21:09:05 +0000324 renderer->resetState(true);
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000325
326 // We throw this away the first batch of times to remove first time effects (such as paging in this program)
327 pict->resetTimes();
328
329 for (int i = 0; i < repeats; ++i) {
330 renderer->setup();
331 renderer->render(NULL);
jvanverth@google.comade32662013-01-28 21:09:05 +0000332 renderer->resetState(true);
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000333 }
334
335 renderer->end();
336}
337
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000338void SkDebuggerGUI::actionProfile() {
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000339 // In order to profile we pass the command offsets (that were read-in
340 // in loadPicture by the SkOffsetPicture) to an SkTimedPlaybackPicture.
skia.committer@gmail.com884e60b2012-11-16 02:01:17 +0000341 // The SkTimedPlaybackPicture in turn passes the offsets to an
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000342 // SkTimedPicturePlayback object which uses them to track the performance
343 // of individual commands.
344 if (fFileName.isEmpty()) {
345 return;
346 }
347
348 SkFILEStream inputStream;
349
350 inputStream.setPath(fFileName.c_str());
351 if (!inputStream.isValid()) {
352 return;
353 }
354
355 bool success = false;
scroggo@google.comf8d7d272013-02-22 21:38:35 +0000356 SkTimedPicture picture(&inputStream, &success, &SkImageDecoder::DecodeMemory,
robertphillips@google.com5f971142012-12-07 20:48:56 +0000357 fOffsets, fSkipCommands);
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000358 if (!success) {
359 return;
360 }
361
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000362 // For now this #if allows switching between tiled and simple rendering
363 // modes. Eventually this will be accomplished via the GUI
robertphillips@google.come174a8b2012-11-27 16:04:42 +0000364#if 0
365 // With the current batch of SysTimers, profiling in tiled mode
366 // gets swamped by the timing overhead:
367 //
368 // tile mode simple mode
369 // debugger 64.2ms 12.8ms
370 // bench_pictures 16.9ms 12.4ms
371 //
372 // This is b.c. in tiled mode each command is called many more times
373 // but typically does less work on each invocation (due to clipping)
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000374 sk_tools::TiledPictureRenderer* renderer = NULL;
375
376 renderer = SkNEW(sk_tools::TiledPictureRenderer);
377 renderer->setTileWidth(256);
378 renderer->setTileHeight(256);
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000379#else
380 sk_tools::SimplePictureRenderer* renderer = NULL;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000381
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000382 renderer = SkNEW(sk_tools::SimplePictureRenderer);
robertphillips@google.com1447aa32013-01-30 21:09:09 +0000383
384#if SK_SUPPORT_GPU
385 if (Qt::Checked == fSettingsWidget.getGLCheckBox()->checkState()) {
386 renderer->setDeviceType(sk_tools::PictureRenderer::kGPU_DeviceType);
387 }
388#endif
389
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000390#endif
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000391
robertphillips@google.come174a8b2012-11-27 16:04:42 +0000392 static const int kNumRepeats = 10;
393
394 run(&picture, renderer, kNumRepeats);
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000395
396 SkASSERT(picture.count() == fListWidget.count());
397
398 // extract the individual command times from the SkTimedPlaybackPicture
399 for (int i = 0; i < picture.count(); ++i) {
400 double temp = picture.time(i);
401
402 QListWidgetItem* item = fListWidget.item(i);
403
404 item->setData(Qt::UserRole + 4, 100.0*temp);
405 }
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000406
borenet@google.com2d9dbd42013-03-12 13:07:40 +0000407 setupOverviewText(picture.typeTimes(), picture.totTime());
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000408}
409
chudy@google.com902ebe52012-06-29 14:21:22 +0000410void SkDebuggerGUI::actionCancel() {
chudy@google.comc432f002012-07-10 13:19:25 +0000411 for (int row = 0; row < fListWidget.count(); row++) {
412 fListWidget.item(row)->setHidden(false);
chudy@google.com902ebe52012-06-29 14:21:22 +0000413 }
414}
415
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000416void SkDebuggerGUI::actionClearBreakpoints() {
417 for (int row = 0; row < fListWidget.count(); row++) {
418 QListWidgetItem* item = fListWidget.item(row);
419 item->setCheckState(Qt::Unchecked);
420 item->setData(Qt::DecorationRole,
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000421 QPixmap(":/blank.png"));
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000422 }
423}
424
425void SkDebuggerGUI::actionClearDeletes() {
426 for (int row = 0; row < fListWidget.count(); row++) {
427 QListWidgetItem* item = fListWidget.item(row);
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000428 item->setData(Qt::UserRole + 2, QPixmap(":/blank.png"));
chudy@google.com607357f2012-08-07 16:12:23 +0000429 fDebugger.setCommandVisible(row, true);
robertphillips@google.com5f971142012-12-07 20:48:56 +0000430 fSkipCommands[row] = false;
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000431 }
432 if (fPause) {
433 fCanvasWidget.drawTo(fPausedRow);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000434 fImageWidget.draw();
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000435 } else {
436 fCanvasWidget.drawTo(fListWidget.currentRow());
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000437 fImageWidget.draw();
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000438 }
439}
440
chudy@google.com902ebe52012-06-29 14:21:22 +0000441void SkDebuggerGUI::actionCommandFilter() {
chudy@google.com607357f2012-08-07 16:12:23 +0000442 fDebugger.highlightCurrentCommand(
chudy@google.comc432f002012-07-10 13:19:25 +0000443 fSettingsWidget.getVisibilityButton()->isChecked());
444 fCanvasWidget.drawTo(fListWidget.currentRow());
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000445 fImageWidget.draw();
chudy@google.com902ebe52012-06-29 14:21:22 +0000446}
447
448void SkDebuggerGUI::actionClose() {
449 this->close();
450}
451
452void SkDebuggerGUI::actionDelete() {
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000453
robertphillips@google.comdd4b7452013-01-22 19:38:46 +0000454 for (int row = 0; row < fListWidget.count(); ++row) {
455 QListWidgetItem* item = fListWidget.item(row);
456
457 if (!item->isSelected()) {
458 continue;
459 }
460
461 if (fDebugger.isCommandVisible(row)) {
462 item->setData(Qt::UserRole + 2, QPixmap(":/delete.png"));
463 fDebugger.setCommandVisible(row, false);
464 fSkipCommands[row] = true;
465 } else {
466 item->setData(Qt::UserRole + 2, QPixmap(":/blank.png"));
467 fDebugger.setCommandVisible(row, true);
468 fSkipCommands[row] = false;
469 }
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000470 }
471
robertphillips@google.comdd4b7452013-01-22 19:38:46 +0000472 int currentRow = fListWidget.currentRow();
473
chudy@google.come504de02012-07-16 18:35:23 +0000474 if (fPause) {
475 fCanvasWidget.drawTo(fPausedRow);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000476 fImageWidget.draw();
chudy@google.come504de02012-07-16 18:35:23 +0000477 } else {
478 fCanvasWidget.drawTo(currentRow);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000479 fImageWidget.draw();
chudy@google.come504de02012-07-16 18:35:23 +0000480 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000481}
482
robertphillips@google.come8fe4bc2013-02-13 13:26:13 +0000483#if SK_SUPPORT_GPU
chudy@google.comea5488b2012-07-26 19:38:22 +0000484void SkDebuggerGUI::actionGLWidget(bool isToggled) {
485 fCanvasWidget.setWidgetVisibility(SkCanvasWidget::kGPU_WidgetType, !isToggled);
486}
robertphillips@google.come8fe4bc2013-02-13 13:26:13 +0000487#endif
chudy@google.comea5488b2012-07-26 19:38:22 +0000488
chudy@google.com902ebe52012-06-29 14:21:22 +0000489void SkDebuggerGUI::actionInspector() {
chudy@google.comc432f002012-07-10 13:19:25 +0000490 if (fInspectorWidget.isHidden()) {
491 fInspectorWidget.setHidden(false);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000492 fImageWidget.setHidden(false);
chudy@google.com902ebe52012-06-29 14:21:22 +0000493 } else {
chudy@google.comc432f002012-07-10 13:19:25 +0000494 fInspectorWidget.setHidden(true);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000495 fImageWidget.setHidden(true);
chudy@google.com902ebe52012-06-29 14:21:22 +0000496 }
497}
498
499void SkDebuggerGUI::actionPlay() {
chudy@google.comc432f002012-07-10 13:19:25 +0000500 for (int row = fListWidget.currentRow() + 1; row < fListWidget.count();
chudy@google.com7dcae672012-07-09 20:26:53 +0000501 row++) {
chudy@google.comc432f002012-07-10 13:19:25 +0000502 QListWidgetItem *item = fListWidget.item(row);
chudy@google.com902ebe52012-06-29 14:21:22 +0000503 if (item->checkState() == Qt::Checked) {
chudy@google.comc432f002012-07-10 13:19:25 +0000504 fListWidget.setCurrentItem(item);
chudy@google.com902ebe52012-06-29 14:21:22 +0000505 return;
506 }
507 }
chudy@google.comc432f002012-07-10 13:19:25 +0000508 fListWidget.setCurrentRow(fListWidget.count() - 1);
chudy@google.com902ebe52012-06-29 14:21:22 +0000509}
510
chudy@google.comea5488b2012-07-26 19:38:22 +0000511void SkDebuggerGUI::actionRasterWidget(bool isToggled) {
512 fCanvasWidget.setWidgetVisibility(SkCanvasWidget::kRaster_8888_WidgetType, !isToggled);
513}
514
robertphillips@google.comf4741c12013-02-06 20:13:54 +0000515void SkDebuggerGUI::actionOverdrawVizWidget(bool isToggled) {
516 fDebugger.setOverdrawViz(isToggled);
517 fCanvasWidget.update();
518}
519
chudy@google.com902ebe52012-06-29 14:21:22 +0000520void SkDebuggerGUI::actionRewind() {
chudy@google.come504de02012-07-16 18:35:23 +0000521 fListWidget.setCurrentRow(0);
chudy@google.com902ebe52012-06-29 14:21:22 +0000522}
523
chudy@google.com0ab03392012-07-28 20:16:11 +0000524void SkDebuggerGUI::actionSave() {
robertphillips@google.come219baf2013-01-28 19:25:43 +0000525 fFileName = fPath.toAscii().data();
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000526 fFileName.append("/");
robertphillips@google.come219baf2013-01-28 19:25:43 +0000527 fFileName.append(fDirectoryWidget.currentItem()->text().toAscii().data());
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000528 saveToFile(fFileName);
chudy@google.com0ab03392012-07-28 20:16:11 +0000529}
530
531void SkDebuggerGUI::actionSaveAs() {
532 QString filename = QFileDialog::getSaveFileName(this, "Save File", "",
533 "Skia Picture (*skp)");
chudy@google.com38b08ce2012-07-28 23:26:10 +0000534 if (!filename.endsWith(".skp", Qt::CaseInsensitive)) {
chudy@google.com0ab03392012-07-28 20:16:11 +0000535 filename.append(".skp");
536 }
djsollen@google.comc3c82162012-11-13 18:35:10 +0000537 saveToFile(SkString(filename.toAscii().data()));
chudy@google.com0ab03392012-07-28 20:16:11 +0000538}
539
chudy@google.com7dcae672012-07-09 20:26:53 +0000540void SkDebuggerGUI::actionScale(float scaleFactor) {
chudy@google.comc432f002012-07-10 13:19:25 +0000541 fSettingsWidget.setZoomText(scaleFactor);
chudy@google.com7dcae672012-07-09 20:26:53 +0000542}
543
chudy@google.com902ebe52012-06-29 14:21:22 +0000544void SkDebuggerGUI::actionSettings() {
chudy@google.comc432f002012-07-10 13:19:25 +0000545 if (fSettingsWidget.isHidden()) {
546 fSettingsWidget.setHidden(false);
chudy@google.com902ebe52012-06-29 14:21:22 +0000547 } else {
chudy@google.comc432f002012-07-10 13:19:25 +0000548 fSettingsWidget.setHidden(true);
chudy@google.com902ebe52012-06-29 14:21:22 +0000549 }
550}
551
552void SkDebuggerGUI::actionStepBack() {
chudy@google.comc432f002012-07-10 13:19:25 +0000553 int currentRow = fListWidget.currentRow();
chudy@google.com902ebe52012-06-29 14:21:22 +0000554 if (currentRow != 0) {
chudy@google.comc432f002012-07-10 13:19:25 +0000555 fListWidget.setCurrentRow(currentRow - 1);
chudy@google.com902ebe52012-06-29 14:21:22 +0000556 }
557}
558
559void SkDebuggerGUI::actionStepForward() {
chudy@google.comc432f002012-07-10 13:19:25 +0000560 int currentRow = fListWidget.currentRow();
chudy@google.com902ebe52012-06-29 14:21:22 +0000561 QString curRow = QString::number(currentRow);
chudy@google.comc432f002012-07-10 13:19:25 +0000562 QString curCount = QString::number(fListWidget.count());
563 if (currentRow < fListWidget.count() - 1) {
564 fListWidget.setCurrentRow(currentRow + 1);
chudy@google.com902ebe52012-06-29 14:21:22 +0000565 }
566}
567
chudy@google.coma9e937c2012-08-03 17:32:05 +0000568void SkDebuggerGUI::drawComplete() {
chudy@google.com607357f2012-08-07 16:12:23 +0000569 fInspectorWidget.setMatrix(fDebugger.getCurrentMatrix());
570 fInspectorWidget.setClip(fDebugger.getCurrentClip());
chudy@google.coma9e937c2012-08-03 17:32:05 +0000571}
572
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000573void SkDebuggerGUI::saveToFile(const SkString& filename) {
574 SkFILEWStream file(filename.c_str());
robertphillips@google.com25bc2f82013-01-22 18:03:56 +0000575 SkAutoTUnref<SkPicture> copy(fDebugger.copyPicture());
576
577 copy->serialize(&file);
chudy@google.com0ab03392012-07-28 20:16:11 +0000578}
579
chudy@google.com902ebe52012-06-29 14:21:22 +0000580void SkDebuggerGUI::loadFile(QListWidgetItem *item) {
581 if (fDirectoryWidgetActive) {
robertphillips@google.come219baf2013-01-28 19:25:43 +0000582 fFileName = fPath.toAscii().data();
jvanverth@google.com0ac6f162013-02-05 19:44:07 +0000583 // don't add a '/' to files in the local directory
584 if (fFileName.size() > 0) {
585 fFileName.append("/");
586 }
robertphillips@google.come219baf2013-01-28 19:25:43 +0000587 fFileName.append(item->text().toAscii().data());
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000588 loadPicture(fFileName);
chudy@google.com902ebe52012-06-29 14:21:22 +0000589 }
590}
591
592void SkDebuggerGUI::openFile() {
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000593 QString temp = QFileDialog::getOpenFileName(this, tr("Open File"), "",
chudy@google.com7dcae672012-07-09 20:26:53 +0000594 tr("Files (*.*)"));
robertphillips@google.comff6e6ba2013-01-28 17:43:26 +0000595 openFile(temp);
596}
597
598void SkDebuggerGUI::openFile(const QString &filename) {
chudy@google.com902ebe52012-06-29 14:21:22 +0000599 fDirectoryWidgetActive = false;
robertphillips@google.comff6e6ba2013-01-28 17:43:26 +0000600 if (!filename.isEmpty()) {
601 QFileInfo pathInfo(filename);
602 loadPicture(SkString(filename.toAscii().data()));
603 setupDirectoryWidget(pathInfo.path());
chudy@google.com902ebe52012-06-29 14:21:22 +0000604 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000605 fDirectoryWidgetActive = true;
606}
607
chudy@google.comc432f002012-07-10 13:19:25 +0000608void SkDebuggerGUI::pauseDrawing(bool isPaused) {
chudy@google.com607357f2012-08-07 16:12:23 +0000609 fPause = isPaused;
610 fPausedRow = fListWidget.currentRow();
611 fCanvasWidget.drawTo(fPausedRow);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000612 fImageWidget.draw();
chudy@google.com7dcae672012-07-09 20:26:53 +0000613}
614
chudy@google.com902ebe52012-06-29 14:21:22 +0000615void SkDebuggerGUI::registerListClick(QListWidgetItem *item) {
chudy@google.comd3058f52012-07-19 13:41:27 +0000616 if(!fLoading) {
617 int currentRow = fListWidget.currentRow();
chudy@google.comd3058f52012-07-19 13:41:27 +0000618
chudy@google.comea5488b2012-07-26 19:38:22 +0000619 if (currentRow != -1) {
620 if (!fPause) {
621 fCanvasWidget.drawTo(currentRow);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000622 fImageWidget.draw();
chudy@google.comd3058f52012-07-19 13:41:27 +0000623 }
chudy@google.com97cee972012-08-07 20:41:37 +0000624 SkTDArray<SkString*> *currInfo = fDebugger.getCommandInfo(
chudy@google.comea5488b2012-07-26 19:38:22 +0000625 currentRow);
626
627 /* TODO(chudy): Add command type before parameters. Rename v
628 * to something more informative. */
chudy@google.com97cee972012-08-07 20:41:37 +0000629 if (currInfo) {
chudy@google.comea5488b2012-07-26 19:38:22 +0000630 QString info;
631 info.append("<b>Parameters: </b><br/>");
chudy@google.com97cee972012-08-07 20:41:37 +0000632 for (int i = 0; i < currInfo->count(); i++) {
633
634 info.append(QString((*currInfo)[i]->c_str()));
chudy@google.comea5488b2012-07-26 19:38:22 +0000635 info.append("<br/>");
636 }
chudy@google.com6bd109a2012-08-14 19:34:13 +0000637 fInspectorWidget.setText(info, SkInspectorWidget::kDetail_TabType);
chudy@google.comea5488b2012-07-26 19:38:22 +0000638 fInspectorWidget.setDisabled(false);
chudy@google.comea5488b2012-07-26 19:38:22 +0000639 }
chudy@google.comd3058f52012-07-19 13:41:27 +0000640 }
chudy@google.comea5488b2012-07-26 19:38:22 +0000641
chudy@google.com902ebe52012-06-29 14:21:22 +0000642 }
643}
644
chudy@google.com9ca9bfe2012-07-12 21:58:14 +0000645void SkDebuggerGUI::selectCommand(int command) {
646 if (fPause) {
647 fListWidget.setCurrentRow(command);
648 }
649}
650
chudy@google.com902ebe52012-06-29 14:21:22 +0000651void SkDebuggerGUI::toggleBreakpoint() {
chudy@google.comc432f002012-07-10 13:19:25 +0000652 QListWidgetItem* item = fListWidget.currentItem();
chudy@google.com902ebe52012-06-29 14:21:22 +0000653 if (item->checkState() == Qt::Unchecked) {
654 item->setCheckState(Qt::Checked);
chudy@google.come565de42012-07-12 14:15:54 +0000655 item->setData(Qt::DecorationRole,
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000656 QPixmap(":/breakpoint_16x16.png"));
chudy@google.com902ebe52012-06-29 14:21:22 +0000657 } else {
chudy@google.com902ebe52012-06-29 14:21:22 +0000658 item->setCheckState(Qt::Unchecked);
chudy@google.come565de42012-07-12 14:15:54 +0000659 item->setData(Qt::DecorationRole,
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000660 QPixmap(":/blank.png"));
chudy@google.com902ebe52012-06-29 14:21:22 +0000661 }
662}
663
664void SkDebuggerGUI::toggleDirectory() {
chudy@google.com607357f2012-08-07 16:12:23 +0000665 fDirectoryWidget.setHidden(!fDirectoryWidget.isHidden());
chudy@google.com902ebe52012-06-29 14:21:22 +0000666}
667
668void SkDebuggerGUI::toggleFilter(QString string) {
chudy@google.comc432f002012-07-10 13:19:25 +0000669 for (int row = 0; row < fListWidget.count(); row++) {
670 QListWidgetItem *item = fListWidget.item(row);
chudy@google.com607357f2012-08-07 16:12:23 +0000671 item->setHidden(item->text() != string);
chudy@google.com902ebe52012-06-29 14:21:22 +0000672 }
673}
674
675void SkDebuggerGUI::setupUi(QMainWindow *SkDebuggerGUI) {
676 QIcon windowIcon;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000677 windowIcon.addFile(QString::fromUtf8(":/skia.png"), QSize(),
chudy@google.com7dcae672012-07-09 20:26:53 +0000678 QIcon::Normal, QIcon::Off);
chudy@google.com902ebe52012-06-29 14:21:22 +0000679 SkDebuggerGUI->setObjectName(QString::fromUtf8("SkDebuggerGUI"));
680 SkDebuggerGUI->resize(1200, 1000);
681 SkDebuggerGUI->setWindowIcon(windowIcon);
chudy@google.comc432f002012-07-10 13:19:25 +0000682 SkDebuggerGUI->setWindowTitle("Skia Debugger");
chudy@google.com902ebe52012-06-29 14:21:22 +0000683
chudy@google.come504de02012-07-16 18:35:23 +0000684 fActionOpen.setShortcuts(QKeySequence::Open);
chudy@google.comc432f002012-07-10 13:19:25 +0000685 fActionOpen.setText("Open");
chudy@google.com902ebe52012-06-29 14:21:22 +0000686
687 QIcon breakpoint;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000688 breakpoint.addFile(QString::fromUtf8(":/breakpoint.png"),
chudy@google.com7dcae672012-07-09 20:26:53 +0000689 QSize(), QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000690 fActionBreakpoint.setShortcut(QKeySequence(tr("Ctrl+B")));
chudy@google.comc432f002012-07-10 13:19:25 +0000691 fActionBreakpoint.setIcon(breakpoint);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000692 fActionBreakpoint.setText("Breakpoints");
chudy@google.com902ebe52012-06-29 14:21:22 +0000693
694 QIcon cancel;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000695 cancel.addFile(QString::fromUtf8(":/reload.png"), QSize(),
chudy@google.com7dcae672012-07-09 20:26:53 +0000696 QIcon::Normal, QIcon::Off);
chudy@google.comc432f002012-07-10 13:19:25 +0000697 fActionCancel.setIcon(cancel);
698 fActionCancel.setText("Clear Filter");
chudy@google.com902ebe52012-06-29 14:21:22 +0000699
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000700 fActionClearBreakpoints.setShortcut(QKeySequence(tr("Alt+B")));
701 fActionClearBreakpoints.setText("Clear Breakpoints");
702
703 fActionClearDeletes.setShortcut(QKeySequence(tr("Alt+X")));
704 fActionClearDeletes.setText("Clear Deletes");
705
chudy@google.come504de02012-07-16 18:35:23 +0000706 fActionClose.setShortcuts(QKeySequence::Quit);
chudy@google.comc432f002012-07-10 13:19:25 +0000707 fActionClose.setText("Exit");
chudy@google.com902ebe52012-06-29 14:21:22 +0000708
chudy@google.come504de02012-07-16 18:35:23 +0000709 fActionCreateBreakpoint.setShortcut(QKeySequence(tr("B")));
710 fActionCreateBreakpoint.setText("Set Breakpoint");
711
712 fActionDelete.setShortcut(QKeySequence(tr("X")));
chudy@google.comc432f002012-07-10 13:19:25 +0000713 fActionDelete.setText("Delete Command");
chudy@google.com902ebe52012-06-29 14:21:22 +0000714
chudy@google.come504de02012-07-16 18:35:23 +0000715 fActionDirectory.setShortcut(QKeySequence(tr("Ctrl+D")));
716 fActionDirectory.setText("Directory");
chudy@google.com902ebe52012-06-29 14:21:22 +0000717
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000718 QIcon profile;
robertphillips@google.comd1636362012-11-19 18:25:09 +0000719 profile.addFile(QString::fromUtf8(":/profile.png"), QSize(),
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000720 QIcon::Normal, QIcon::Off);
721 fActionProfile.setIcon(profile);
722 fActionProfile.setText("Profile");
robertphillips@google.come099bc42012-11-19 16:26:40 +0000723 fActionProfile.setDisabled(true);
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000724
chudy@google.comc432f002012-07-10 13:19:25 +0000725 QIcon inspector;
robertphillips@google.comd1636362012-11-19 18:25:09 +0000726 inspector.addFile(QString::fromUtf8(":/inspector.png"),
chudy@google.comc432f002012-07-10 13:19:25 +0000727 QSize(), QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000728 fActionInspector.setShortcut(QKeySequence(tr("Ctrl+I")));
chudy@google.comc432f002012-07-10 13:19:25 +0000729 fActionInspector.setIcon(inspector);
chudy@google.come504de02012-07-16 18:35:23 +0000730 fActionInspector.setText("Inspector");
chudy@google.com902ebe52012-06-29 14:21:22 +0000731
chudy@google.comc432f002012-07-10 13:19:25 +0000732 QIcon play;
robertphillips@google.comd1636362012-11-19 18:25:09 +0000733 play.addFile(QString::fromUtf8(":/play.png"), QSize(),
chudy@google.comc432f002012-07-10 13:19:25 +0000734 QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000735 fActionPlay.setShortcut(QKeySequence(tr("Ctrl+P")));
chudy@google.comc432f002012-07-10 13:19:25 +0000736 fActionPlay.setIcon(play);
737 fActionPlay.setText("Play");
chudy@google.com902ebe52012-06-29 14:21:22 +0000738
chudy@google.come504de02012-07-16 18:35:23 +0000739 QIcon pause;
robertphillips@google.comd1636362012-11-19 18:25:09 +0000740 pause.addFile(QString::fromUtf8(":/pause.png"), QSize(),
chudy@google.comc432f002012-07-10 13:19:25 +0000741 QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000742 fActionPause.setShortcut(QKeySequence(tr("Space")));
743 fActionPause.setCheckable(true);
744 fActionPause.setIcon(pause);
745 fActionPause.setText("Pause");
746
chudy@google.comc432f002012-07-10 13:19:25 +0000747 QIcon rewind;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000748 rewind.addFile(QString::fromUtf8(":/rewind.png"), QSize(),
chudy@google.comc432f002012-07-10 13:19:25 +0000749 QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000750 fActionRewind.setShortcut(QKeySequence(tr("Ctrl+R")));
chudy@google.comc432f002012-07-10 13:19:25 +0000751 fActionRewind.setIcon(rewind);
752 fActionRewind.setText("Rewind");
chudy@google.com902ebe52012-06-29 14:21:22 +0000753
chudy@google.com0ab03392012-07-28 20:16:11 +0000754 fActionSave.setShortcut(QKeySequence::Save);
755 fActionSave.setText("Save");
756 fActionSave.setDisabled(true);
757 fActionSaveAs.setShortcut(QKeySequence::SaveAs);
758 fActionSaveAs.setText("Save As");
759 fActionSaveAs.setDisabled(true);
760
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000761 fActionShowDeletes.setShortcut(QKeySequence(tr("Ctrl+X")));
762 fActionShowDeletes.setText("Deleted Commands");
763
chudy@google.comc432f002012-07-10 13:19:25 +0000764 QIcon stepBack;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000765 stepBack.addFile(QString::fromUtf8(":/previous.png"), QSize(),
chudy@google.comc432f002012-07-10 13:19:25 +0000766 QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000767 fActionStepBack.setShortcut(QKeySequence(tr("[")));
chudy@google.comc432f002012-07-10 13:19:25 +0000768 fActionStepBack.setIcon(stepBack);
769 fActionStepBack.setText("Step Back");
chudy@google.com902ebe52012-06-29 14:21:22 +0000770
chudy@google.comc432f002012-07-10 13:19:25 +0000771 QIcon stepForward;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000772 stepForward.addFile(QString::fromUtf8(":/next.png"),
chudy@google.comc432f002012-07-10 13:19:25 +0000773 QSize(), QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000774 fActionStepForward.setShortcut(QKeySequence(tr("]")));
chudy@google.comc432f002012-07-10 13:19:25 +0000775 fActionStepForward.setIcon(stepForward);
776 fActionStepForward.setText("Step Forward");
777
chudy@google.coma1226312012-07-26 20:26:44 +0000778 fActionZoomIn.setShortcut(QKeySequence(tr("Ctrl+=")));
779 fActionZoomIn.setText("Zoom In");
780 fActionZoomOut.setShortcut(QKeySequence(tr("Ctrl+-")));
781 fActionZoomOut.setText("Zoom Out");
782
chudy@google.comc432f002012-07-10 13:19:25 +0000783 fListWidget.setItemDelegate(new SkListWidget(&fListWidget));
784 fListWidget.setObjectName(QString::fromUtf8("listWidget"));
785 fListWidget.setMaximumWidth(250);
786
787 fFilter.addItem("--Filter By Available Commands--");
788
789 fDirectoryWidget.setMaximumWidth(250);
790 fDirectoryWidget.setStyleSheet("QListWidget::Item {padding: 5px;}");
791
792 fCanvasWidget.setSizePolicy(QSizePolicy::Expanding,
chudy@google.com7dcae672012-07-09 20:26:53 +0000793 QSizePolicy::Expanding);
chudy@google.com902ebe52012-06-29 14:21:22 +0000794
skia.committer@gmail.com1c9c0d32012-11-22 02:02:41 +0000795 fImageWidget.setFixedSize(SkImageWidget::kImageWidgetWidth,
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000796 SkImageWidget::kImageWidgetHeight);
797
chudy@google.comc432f002012-07-10 13:19:25 +0000798 fInspectorWidget.setSizePolicy(QSizePolicy::Expanding,
chudy@google.com7dcae672012-07-09 20:26:53 +0000799 QSizePolicy::Expanding);
chudy@google.comc432f002012-07-10 13:19:25 +0000800 fInspectorWidget.setMaximumHeight(300);
chudy@google.com902ebe52012-06-29 14:21:22 +0000801
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000802 fSettingsAndImageLayout.setSpacing(6);
803 fSettingsAndImageLayout.addWidget(&fSettingsWidget);
804 fSettingsAndImageLayout.addWidget(&fImageWidget);
805
chudy@google.comc432f002012-07-10 13:19:25 +0000806 fSettingsWidget.setSizePolicy(QSizePolicy::Expanding,
807 QSizePolicy::Expanding);
808 fSettingsWidget.setMaximumWidth(250);
chudy@google.com902ebe52012-06-29 14:21:22 +0000809
chudy@google.comc432f002012-07-10 13:19:25 +0000810 fLeftColumnLayout.setSpacing(6);
811 fLeftColumnLayout.addWidget(&fListWidget);
812 fLeftColumnLayout.addWidget(&fDirectoryWidget);
chudy@google.com902ebe52012-06-29 14:21:22 +0000813
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000814 fCanvasSettingsAndImageLayout.setSpacing(6);
815 fCanvasSettingsAndImageLayout.addWidget(&fCanvasWidget);
816 fCanvasSettingsAndImageLayout.addLayout(&fSettingsAndImageLayout);
817
chudy@google.com902ebe52012-06-29 14:21:22 +0000818
chudy@google.comc432f002012-07-10 13:19:25 +0000819 fMainAndRightColumnLayout.setSpacing(6);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000820 fMainAndRightColumnLayout.addLayout(&fCanvasSettingsAndImageLayout);
chudy@google.comc432f002012-07-10 13:19:25 +0000821 fMainAndRightColumnLayout.addWidget(&fInspectorWidget);
chudy@google.com902ebe52012-06-29 14:21:22 +0000822
chudy@google.com2d537a12012-07-31 12:49:52 +0000823 fCentralWidget.setLayout(&fContainerLayout);
chudy@google.comc432f002012-07-10 13:19:25 +0000824 fContainerLayout.setSpacing(6);
825 fContainerLayout.setContentsMargins(11, 11, 11, 11);
826 fContainerLayout.addLayout(&fLeftColumnLayout);
827 fContainerLayout.addLayout(&fMainAndRightColumnLayout);
828
829 SkDebuggerGUI->setCentralWidget(&fCentralWidget);
830 SkDebuggerGUI->setStatusBar(&fStatusBar);
831
chudy@google.come504de02012-07-16 18:35:23 +0000832 fToolBar.setIconSize(QSize(32, 32));
chudy@google.comc432f002012-07-10 13:19:25 +0000833 fToolBar.setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
834 SkDebuggerGUI->addToolBar(Qt::TopToolBarArea, &fToolBar);
chudy@google.com902ebe52012-06-29 14:21:22 +0000835
chudy@google.com0ab03392012-07-28 20:16:11 +0000836 fSpacer.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
chudy@google.com902ebe52012-06-29 14:21:22 +0000837
chudy@google.comc432f002012-07-10 13:19:25 +0000838 fToolBar.addAction(&fActionRewind);
839 fToolBar.addAction(&fActionStepBack);
chudy@google.come504de02012-07-16 18:35:23 +0000840 fToolBar.addAction(&fActionPause);
chudy@google.comc432f002012-07-10 13:19:25 +0000841 fToolBar.addAction(&fActionStepForward);
842 fToolBar.addAction(&fActionPlay);
843 fToolBar.addSeparator();
chudy@google.come504de02012-07-16 18:35:23 +0000844 fToolBar.addAction(&fActionInspector);
chudy@google.comc432f002012-07-10 13:19:25 +0000845 fToolBar.addSeparator();
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000846 fToolBar.addAction(&fActionProfile);
847
848 fToolBar.addSeparator();
chudy@google.com0ab03392012-07-28 20:16:11 +0000849 fToolBar.addWidget(&fSpacer);
chudy@google.comc432f002012-07-10 13:19:25 +0000850 fToolBar.addWidget(&fFilter);
851 fToolBar.addAction(&fActionCancel);
chudy@google.com902ebe52012-06-29 14:21:22 +0000852
853 // TODO(chudy): Remove static call.
854 fDirectoryWidgetActive = false;
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000855 fFileName = "";
robertphillips@google.comff6e6ba2013-01-28 17:43:26 +0000856 setupDirectoryWidget("");
chudy@google.com902ebe52012-06-29 14:21:22 +0000857 fDirectoryWidgetActive = true;
858
chudy@google.com902ebe52012-06-29 14:21:22 +0000859 // Menu Bar
chudy@google.comc432f002012-07-10 13:19:25 +0000860 fMenuFile.setTitle("File");
861 fMenuFile.addAction(&fActionOpen);
chudy@google.com0ab03392012-07-28 20:16:11 +0000862 fMenuFile.addAction(&fActionSave);
863 fMenuFile.addAction(&fActionSaveAs);
chudy@google.comc432f002012-07-10 13:19:25 +0000864 fMenuFile.addAction(&fActionClose);
chudy@google.come504de02012-07-16 18:35:23 +0000865
866 fMenuEdit.setTitle("Edit");
867 fMenuEdit.addAction(&fActionDelete);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000868 fMenuEdit.addAction(&fActionClearDeletes);
869 fMenuEdit.addSeparator();
chudy@google.come504de02012-07-16 18:35:23 +0000870 fMenuEdit.addAction(&fActionCreateBreakpoint);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000871 fMenuEdit.addAction(&fActionClearBreakpoints);
chudy@google.come504de02012-07-16 18:35:23 +0000872
chudy@google.comc432f002012-07-10 13:19:25 +0000873 fMenuNavigate.setTitle("Navigate");
chudy@google.come504de02012-07-16 18:35:23 +0000874 fMenuNavigate.addAction(&fActionRewind);
875 fMenuNavigate.addAction(&fActionStepBack);
876 fMenuNavigate.addAction(&fActionStepForward);
877 fMenuNavigate.addAction(&fActionPlay);
878 fMenuNavigate.addAction(&fActionPause);
chudy@google.comc432f002012-07-10 13:19:25 +0000879 fMenuNavigate.addAction(&fActionGoToLine);
chudy@google.come504de02012-07-16 18:35:23 +0000880
chudy@google.comc432f002012-07-10 13:19:25 +0000881 fMenuView.setTitle("View");
chudy@google.come504de02012-07-16 18:35:23 +0000882 fMenuView.addAction(&fActionBreakpoint);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000883 fMenuView.addAction(&fActionShowDeletes);
chudy@google.coma1226312012-07-26 20:26:44 +0000884 fMenuView.addAction(&fActionZoomIn);
885 fMenuView.addAction(&fActionZoomOut);
chudy@google.come504de02012-07-16 18:35:23 +0000886
887 fMenuWindows.setTitle("Window");
888 fMenuWindows.addAction(&fActionInspector);
889 fMenuWindows.addAction(&fActionDirectory);
chudy@google.comc432f002012-07-10 13:19:25 +0000890
891 fActionGoToLine.setText("Go to Line...");
892 fActionGoToLine.setDisabled(true);
893 fMenuBar.addAction(fMenuFile.menuAction());
chudy@google.come504de02012-07-16 18:35:23 +0000894 fMenuBar.addAction(fMenuEdit.menuAction());
chudy@google.comc432f002012-07-10 13:19:25 +0000895 fMenuBar.addAction(fMenuView.menuAction());
896 fMenuBar.addAction(fMenuNavigate.menuAction());
chudy@google.come504de02012-07-16 18:35:23 +0000897 fMenuBar.addAction(fMenuWindows.menuAction());
chudy@google.com902ebe52012-06-29 14:21:22 +0000898
chudy@google.com7dcae672012-07-09 20:26:53 +0000899 fPause = false;
900
chudy@google.comc432f002012-07-10 13:19:25 +0000901 SkDebuggerGUI->setMenuBar(&fMenuBar);
chudy@google.com902ebe52012-06-29 14:21:22 +0000902 QMetaObject::connectSlotsByName(SkDebuggerGUI);
903}
904
robertphillips@google.comff6e6ba2013-01-28 17:43:26 +0000905void SkDebuggerGUI::setupDirectoryWidget(const QString& path) {
906 fPath = path;
907 QDir dir(path);
chudy@google.com902ebe52012-06-29 14:21:22 +0000908 QRegExp r(".skp");
chudy@google.comc432f002012-07-10 13:19:25 +0000909 fDirectoryWidget.clear();
910 const QStringList files = dir.entryList();
chudy@google.com902ebe52012-06-29 14:21:22 +0000911 foreach (QString f, files) {
chudy@google.com7dcae672012-07-09 20:26:53 +0000912 if (f.contains(r))
chudy@google.comc432f002012-07-10 13:19:25 +0000913 fDirectoryWidget.addItem(f);
chudy@google.com902ebe52012-06-29 14:21:22 +0000914 }
915}
916
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000917// SkOffsetPicturePlayback records the offset of each command in the picture.
918// These are needed by the profiling system.
919class SkOffsetPicturePlayback : public SkPicturePlayback {
920public:
scroggo@google.com12d588a2013-02-25 16:05:00 +0000921 SkOffsetPicturePlayback(SkStream* stream, const SkPictInfo& info,
scroggo@google.comf8d7d272013-02-22 21:38:35 +0000922 SkPicture::InstallPixelRefProc proc)
scroggo@google.com12d588a2013-02-25 16:05:00 +0000923 : INHERITED(stream, info, proc) {
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000924 }
925
926 const SkTDArray<size_t>& offsets() const { return fOffsets; }
927
928protected:
929 SkTDArray<size_t> fOffsets;
930
robertphillips@google.comca47aae2012-12-12 15:58:25 +0000931 virtual size_t preDraw(size_t offset, int type) {
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000932 *fOffsets.append() = offset;
robertphillips@google.com5f971142012-12-07 20:48:56 +0000933 return 0;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000934 }
935
936private:
937 typedef SkPicturePlayback INHERITED;
938};
939
940// Picture to wrap an SkOffsetPicturePlayback.
941class SkOffsetPicture : public SkPicture {
942public:
scroggo@google.comf8d7d272013-02-22 21:38:35 +0000943 SkOffsetPicture(SkStream* stream, bool* success, SkPicture::InstallPixelRefProc proc) {
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000944 if (success) {
945 *success = false;
946 }
947 fRecord = NULL;
948 fPlayback = NULL;
949 fWidth = fHeight = 0;
950
951 SkPictInfo info;
952
953 if (!stream->read(&info, sizeof(info))) {
954 return;
955 }
956 if (PICTURE_VERSION != info.fVersion) {
957 return;
958 }
959
960 if (stream->readBool()) {
scroggo@google.com12d588a2013-02-25 16:05:00 +0000961 fPlayback = SkNEW_ARGS(SkOffsetPicturePlayback, (stream, info, proc));
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000962 }
963
964 // do this at the end, so that they will be zero if we hit an error.
965 fWidth = info.fWidth;
966 fHeight = info.fHeight;
967 if (success) {
968 *success = true;
969 }
970 }
971
skia.committer@gmail.com884e60b2012-11-16 02:01:17 +0000972 const SkTDArray<size_t>& offsets() const {
973 return ((SkOffsetPicturePlayback*) fPlayback)->offsets();
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000974 }
975
976private:
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000977 // disallow default ctor b.c. we don't have a good way to setup the fPlayback ptr
978 SkOffsetPicture();
979 // disallow the copy ctor - enabling would require copying code from SkPicture
980 SkOffsetPicture(const SkOffsetPicture& src);
981
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000982 typedef SkPicture INHERITED;
983};
984
985
986
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000987void SkDebuggerGUI::loadPicture(const SkString& fileName) {
988 fFileName = fileName;
chudy@google.comd3058f52012-07-19 13:41:27 +0000989 fLoading = true;
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000990 SkStream* stream = SkNEW_ARGS(SkFILEStream, (fileName.c_str()));
robertphillips@google.com2d40ec42013-02-07 20:39:40 +0000991
992 bool success = false;
993
scroggo@google.comf8d7d272013-02-22 21:38:35 +0000994 SkOffsetPicture* picture = SkNEW_ARGS(SkOffsetPicture,
995 (stream, &success, &SkImageDecoder::DecodeMemory));
robertphillips@google.com2d40ec42013-02-07 20:39:40 +0000996
997 if (!success) {
998 QMessageBox::critical(this, "Error loading file", "Couldn't read file, sorry.");
999 SkSafeUnref(stream);
1000 return;
1001 }
robertphillips@google.com2bde91d2012-11-15 14:57:57 +00001002
chudy@google.com686e6802012-08-14 16:00:32 +00001003 fCanvasWidget.resetWidgetTransform();
chudy@google.com607357f2012-08-07 16:12:23 +00001004 fDebugger.loadPicture(picture);
chudy@google.com4c7962e2012-08-14 19:38:31 +00001005
robertphillips@google.com2bde91d2012-11-15 14:57:57 +00001006 fOffsets = picture->offsets();
1007
robertphillips@google.com5f971142012-12-07 20:48:56 +00001008 fSkipCommands.setCount(fOffsets.count());
1009 for (int i = 0; i < fOffsets.count(); ++i) {
1010 fSkipCommands[i] = false;
1011 }
1012
chudy@google.com607357f2012-08-07 16:12:23 +00001013 SkSafeUnref(stream);
1014 SkSafeUnref(picture);
1015
chudy@google.com97cee972012-08-07 20:41:37 +00001016 // Will this automatically clear out due to nature of refcnt?
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +00001017 SkTArray<SkString>* commands = fDebugger.getDrawCommandsAsStrings();
chudy@google.com607357f2012-08-07 16:12:23 +00001018
robertphillips@google.comfe830a42012-11-15 16:33:31 +00001019 // If SkPicturePlayback is compiled w/o SK_PICTURE_PROFILING_STUBS
1020 // the offset count will always be zero
1021 SkASSERT(0 == fOffsets.count() || commands->count() == fOffsets.count());
robertphillips@google.come099bc42012-11-19 16:26:40 +00001022 if (commands->count() == fOffsets.count()) {
1023 fActionProfile.setDisabled(false);
robertphillips@google.comfe830a42012-11-15 16:33:31 +00001024 }
robertphillips@google.com2bde91d2012-11-15 14:57:57 +00001025
chudy@google.com7dcae672012-07-09 20:26:53 +00001026 /* fDebugCanvas is reinitialized every load picture. Need it to retain value
chudy@google.com607357f2012-08-07 16:12:23 +00001027 * of the visibility filter.
1028 * TODO(chudy): This should be deprecated since fDebugger is not
1029 * recreated.
1030 * */
1031 fDebugger.highlightCurrentCommand(fSettingsWidget.getVisibilityButton()->isChecked());
1032
chudy@google.com97cee972012-08-07 20:41:37 +00001033 setupListWidget(commands);
1034 setupComboBox(commands);
borenet@google.com2d9dbd42013-03-12 13:07:40 +00001035 setupOverviewText(NULL, 0.0);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +00001036 fInspectorWidget.setDisabled(false);
chudy@google.come606d6e2012-07-12 14:31:25 +00001037 fSettingsWidget.setDisabled(false);
chudy@google.comd3058f52012-07-19 13:41:27 +00001038 fMenuEdit.setDisabled(false);
1039 fMenuNavigate.setDisabled(false);
1040 fMenuView.setDisabled(false);
chudy@google.com0ab03392012-07-28 20:16:11 +00001041 fActionSave.setDisabled(false);
1042 fActionSaveAs.setDisabled(false);
chudy@google.comd3058f52012-07-19 13:41:27 +00001043 fLoading = false;
1044 actionPlay();
chudy@google.com902ebe52012-06-29 14:21:22 +00001045}
1046
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +00001047void SkDebuggerGUI::setupListWidget(SkTArray<SkString>* command) {
chudy@google.comc432f002012-07-10 13:19:25 +00001048 fListWidget.clear();
chudy@google.com902ebe52012-06-29 14:21:22 +00001049 int counter = 0;
robertphillips@google.com30d35f22012-11-06 16:45:36 +00001050 int indent = 0;
chudy@google.com97cee972012-08-07 20:41:37 +00001051 for (int i = 0; i < command->count(); i++) {
chudy@google.com902ebe52012-06-29 14:21:22 +00001052 QListWidgetItem *item = new QListWidgetItem();
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +00001053 item->setData(Qt::DisplayRole, (*command)[i].c_str());
chudy@google.com902ebe52012-06-29 14:21:22 +00001054 item->setData(Qt::UserRole + 1, counter++);
robertphillips@google.com30d35f22012-11-06 16:45:36 +00001055
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +00001056 if (0 == strcmp("Restore", (*command)[i].c_str())) {
robertphillips@google.com30d35f22012-11-06 16:45:36 +00001057 indent -= 10;
1058 }
1059
1060 item->setData(Qt::UserRole + 3, indent);
1061
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +00001062 if (0 == strcmp("Save", (*command)[i].c_str()) ||
1063 0 == strcmp("Save Layer", (*command)[i].c_str())) {
robertphillips@google.com30d35f22012-11-06 16:45:36 +00001064 indent += 10;
1065 }
1066
robertphillips@google.comd26c7062012-11-12 20:42:12 +00001067 item->setData(Qt::UserRole + 4, -1.0);
1068
chudy@google.comc432f002012-07-10 13:19:25 +00001069 fListWidget.addItem(item);
chudy@google.com902ebe52012-06-29 14:21:22 +00001070 }
1071}
1072
borenet@google.com2d9dbd42013-03-12 13:07:40 +00001073void SkDebuggerGUI::setupOverviewText(const SkTDArray<double>* typeTimes, double totTime) {
1074 SkString overview;
1075 fDebugger.getOverviewText(typeTimes, totTime, &overview);
1076 fInspectorWidget.setText(overview.c_str(), SkInspectorWidget::kOverview_TabType);
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +00001077}
1078
1079void SkDebuggerGUI::setupComboBox(SkTArray<SkString>* command) {
1080 fFilter.clear();
1081 fFilter.addItem("--Filter By Available Commands--");
1082
1083 std::map<std::string, int> map;
1084 for (int i = 0; i < command->count(); i++) {
1085 map[(*command)[i].c_str()]++;
1086 }
1087
skia.committer@gmail.com34587162012-11-20 02:01:23 +00001088 for (std::map<std::string, int>::iterator it = map.begin(); it != map.end();
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +00001089 ++it) {
1090 fFilter.addItem((it->first).c_str());
1091 }
chudy@google.com902ebe52012-06-29 14:21:22 +00001092
1093 // NOTE(chudy): Makes first item unselectable.
chudy@google.com7dcae672012-07-09 20:26:53 +00001094 QStandardItemModel* model = qobject_cast<QStandardItemModel*>(
chudy@google.comc432f002012-07-10 13:19:25 +00001095 fFilter.model());
1096 QModelIndex firstIndex = model->index(0, fFilter.modelColumn(),
1097 fFilter.rootModelIndex());
chudy@google.com902ebe52012-06-29 14:21:22 +00001098 QStandardItem* firstItem = model->itemFromIndex(firstIndex);
1099 firstItem->setSelectable(false);
1100}