blob: 4383f65771d0491caf4d3e59cdb8e3dcd430e70f [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"
scroggo@google.com7def5e12013-05-31 14:00:10 +00009#include "SkForceLinking.h"
chudy@google.combbad34d2012-08-13 14:26:36 +000010#include "SkGraphics.h"
scroggo@google.comb4467e62012-11-06 23:10:09 +000011#include "SkImageDecoder.h"
chudy@google.com902ebe52012-06-29 14:21:22 +000012#include <QListWidgetItem>
robertphillips@google.com2bde91d2012-11-15 14:57:57 +000013#include "PictureRenderer.h"
robertphillips@google.com2bde91d2012-11-15 14:57:57 +000014#include "SkPictureRecord.h"
15#include "SkPicturePlayback.h"
robertphillips@google.come174a8b2012-11-27 16:04:42 +000016
scroggo@google.com7def5e12013-05-31 14:00:10 +000017__SK_FORCE_IMAGE_DECODER_LINKING;
18
robertphillips@google.come174a8b2012-11-27 16:04:42 +000019#if defined(SK_BUILD_FOR_WIN32)
20 #include "BenchSysTimer_windows.h"
21#elif defined(SK_BUILD_FOR_MAC)
22 #include "BenchSysTimer_mach.h"
23#elif defined(SK_BUILD_FOR_UNIX) || defined(SK_BUILD_FOR_ANDROID)
24 #include "BenchSysTimer_posix.h"
25#else
26 #include "BenchSysTimer_c.h"
27#endif
28
chudy@google.com902ebe52012-06-29 14:21:22 +000029
30SkDebuggerGUI::SkDebuggerGUI(QWidget *parent) :
chudy@google.comc432f002012-07-10 13:19:25 +000031 QMainWindow(parent)
chudy@google.com2d537a12012-07-31 12:49:52 +000032 , fCentralWidget(this)
33 , fStatusBar(this)
34 , fToolBar(this)
chudy@google.comc432f002012-07-10 13:19:25 +000035 , fActionOpen(this)
36 , fActionBreakpoint(this)
robertphillips@google.comd26c7062012-11-12 20:42:12 +000037 , fActionProfile(this)
chudy@google.comc432f002012-07-10 13:19:25 +000038 , fActionCancel(this)
chudy@google.com7e4cfbf2012-07-17 15:40:51 +000039 , fActionClearBreakpoints(this)
chudy@google.come504de02012-07-16 18:35:23 +000040 , fActionClearDeletes(this)
chudy@google.comc432f002012-07-10 13:19:25 +000041 , fActionClose(this)
chudy@google.come504de02012-07-16 18:35:23 +000042 , fActionCreateBreakpoint(this)
chudy@google.comc432f002012-07-10 13:19:25 +000043 , fActionDelete(this)
44 , fActionDirectory(this)
45 , fActionGoToLine(this)
46 , fActionInspector(this)
bungeman@google.com2ff6d1d2013-07-01 14:24:12 +000047 , fActionSettings(this)
chudy@google.comc432f002012-07-10 13:19:25 +000048 , fActionPlay(this)
chudy@google.come504de02012-07-16 18:35:23 +000049 , fActionPause(this)
chudy@google.comc432f002012-07-10 13:19:25 +000050 , fActionRewind(this)
chudy@google.com0ab03392012-07-28 20:16:11 +000051 , fActionSave(this)
52 , fActionSaveAs(this)
chudy@google.com7e4cfbf2012-07-17 15:40:51 +000053 , fActionShowDeletes(this)
chudy@google.comc432f002012-07-10 13:19:25 +000054 , fActionStepBack(this)
55 , fActionStepForward(this)
chudy@google.coma1226312012-07-26 20:26:44 +000056 , fActionZoomIn(this)
57 , fActionZoomOut(this)
58 , fMapper(this)
chudy@google.comc432f002012-07-10 13:19:25 +000059 , fListWidget(&fCentralWidget)
60 , fDirectoryWidget(&fCentralWidget)
chudy@google.com607357f2012-08-07 16:12:23 +000061 , fCanvasWidget(this, &fDebugger)
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +000062 , fImageWidget(&fDebugger)
chudy@google.comc432f002012-07-10 13:19:25 +000063 , fMenuBar(this)
64 , fMenuFile(this)
65 , fMenuNavigate(this)
66 , fMenuView(this)
chudy@google.com7e4cfbf2012-07-17 15:40:51 +000067 , fBreakpointsActivated(false)
68 , fDeletesActivated(false)
69 , fPause(false)
chudy@google.comd3058f52012-07-19 13:41:27 +000070 , fLoading(false)
chudy@google.comc432f002012-07-10 13:19:25 +000071{
chudy@google.com902ebe52012-06-29 14:21:22 +000072 setupUi(this);
robertphillips@google.comdd4b7452013-01-22 19:38:46 +000073 fListWidget.setSelectionMode(QAbstractItemView::ExtendedSelection);
chudy@google.comea5488b2012-07-26 19:38:22 +000074 connect(&fListWidget, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)), this, SLOT(registerListClick(QListWidgetItem *)));
chudy@google.comc432f002012-07-10 13:19:25 +000075 connect(&fActionOpen, SIGNAL(triggered()), this, SLOT(openFile()));
chudy@google.comea5488b2012-07-26 19:38:22 +000076 connect(&fActionDirectory, SIGNAL(triggered()), this, SLOT(toggleDirectory()));
77 connect(&fDirectoryWidget, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)), this, SLOT(loadFile(QListWidgetItem *)));
chudy@google.comc432f002012-07-10 13:19:25 +000078 connect(&fActionDelete, SIGNAL(triggered()), this, SLOT(actionDelete()));
chudy@google.comea5488b2012-07-26 19:38:22 +000079 connect(&fListWidget, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(toggleBreakpoint()));
chudy@google.comc432f002012-07-10 13:19:25 +000080 connect(&fActionRewind, SIGNAL(triggered()), this, SLOT(actionRewind()));
81 connect(&fActionPlay, SIGNAL(triggered()), this, SLOT(actionPlay()));
82 connect(&fActionStepBack, SIGNAL(triggered()), this, SLOT(actionStepBack()));
chudy@google.comea5488b2012-07-26 19:38:22 +000083 connect(&fActionStepForward, SIGNAL(triggered()), this, SLOT(actionStepForward()));
84 connect(&fActionBreakpoint, SIGNAL(triggered()), this, SLOT(actionBreakpoints()));
85 connect(&fActionInspector, SIGNAL(triggered()), this, SLOT(actionInspector()));
bungeman@google.com2ff6d1d2013-07-01 14:24:12 +000086 connect(&fActionSettings, SIGNAL(triggered()), this, SLOT(actionSettings()));
chudy@google.comea5488b2012-07-26 19:38:22 +000087 connect(&fFilter, SIGNAL(activated(QString)), this, SLOT(toggleFilter(QString)));
robertphillips@google.comd26c7062012-11-12 20:42:12 +000088 connect(&fActionProfile, SIGNAL(triggered()), this, SLOT(actionProfile()));
chudy@google.comc432f002012-07-10 13:19:25 +000089 connect(&fActionCancel, SIGNAL(triggered()), this, SLOT(actionCancel()));
chudy@google.com7e4cfbf2012-07-17 15:40:51 +000090 connect(&fActionClearBreakpoints, SIGNAL(triggered()), this, SLOT(actionClearBreakpoints()));
91 connect(&fActionClearDeletes, SIGNAL(triggered()), this, SLOT(actionClearDeletes()));
chudy@google.comc432f002012-07-10 13:19:25 +000092 connect(&fActionClose, SIGNAL(triggered()), this, SLOT(actionClose()));
chudy@google.comea5488b2012-07-26 19:38:22 +000093 connect(fSettingsWidget.getVisibilityButton(), SIGNAL(toggled(bool)), this, SLOT(actionCommandFilter()));
robertphillips@google.come8fe4bc2013-02-13 13:26:13 +000094#if SK_SUPPORT_GPU
commit-bot@chromium.orgfde1e7c2013-08-02 13:59:50 +000095 connect(&fSettingsWidget, SIGNAL(glSettingsChanged()), this, SLOT(actionGLWidget()));
robertphillips@google.come8fe4bc2013-02-13 13:26:13 +000096#endif
chudy@google.comea5488b2012-07-26 19:38:22 +000097 connect(fSettingsWidget.getRasterCheckBox(), SIGNAL(toggled(bool)), this, SLOT(actionRasterWidget(bool)));
robertphillips@google.comf4741c12013-02-06 20:13:54 +000098 connect(fSettingsWidget.getOverdrawVizCheckBox(), SIGNAL(toggled(bool)), this, SLOT(actionOverdrawVizWidget(bool)));
chudy@google.comea5488b2012-07-26 19:38:22 +000099 connect(&fActionPause, SIGNAL(toggled(bool)), this, SLOT(pauseDrawing(bool)));
chudy@google.come504de02012-07-16 18:35:23 +0000100 connect(&fActionCreateBreakpoint, SIGNAL(activated()), this, SLOT(toggleBreakpoint()));
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000101 connect(&fActionShowDeletes, SIGNAL(triggered()), this, SLOT(showDeletes()));
chudy@google.comea5488b2012-07-26 19:38:22 +0000102 connect(&fCanvasWidget, SIGNAL(hitChanged(int)), this, SLOT(selectCommand(int)));
103 connect(&fCanvasWidget, SIGNAL(hitChanged(int)), &fSettingsWidget, SLOT(updateHit(int)));
104 connect(&fCanvasWidget, SIGNAL(scaleFactorChanged(float)), this, SLOT(actionScale(float)));
105 connect(&fCanvasWidget, SIGNAL(commandChanged(int)), &fSettingsWidget, SLOT(updateCommand(int)));
chudy@google.com0ab03392012-07-28 20:16:11 +0000106 connect(&fActionSaveAs, SIGNAL(triggered()), this, SLOT(actionSaveAs()));
107 connect(&fActionSave, SIGNAL(triggered()), this, SLOT(actionSave()));
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000108
bungeman@google.come8cc6e82013-01-17 16:30:56 +0000109 fMapper.setMapping(&fActionZoomIn, SkCanvasWidget::kIn_ZoomCommand);
110 fMapper.setMapping(&fActionZoomOut, SkCanvasWidget::kOut_ZoomCommand);
chudy@google.coma1226312012-07-26 20:26:44 +0000111
112 connect(&fActionZoomIn, SIGNAL(triggered()), &fMapper, SLOT(map()));
113 connect(&fActionZoomOut, SIGNAL(triggered()), &fMapper, SLOT(map()));
bungeman@google.come8cc6e82013-01-17 16:30:56 +0000114 connect(&fMapper, SIGNAL(mapped(int)), &fCanvasWidget, SLOT(zoom(int)));
chudy@google.coma1226312012-07-26 20:26:44 +0000115
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000116 fInspectorWidget.setDisabled(true);
chudy@google.comd3058f52012-07-19 13:41:27 +0000117 fMenuEdit.setDisabled(true);
118 fMenuNavigate.setDisabled(true);
119 fMenuView.setDisabled(true);
chudy@google.combbad34d2012-08-13 14:26:36 +0000120
121 SkGraphics::Init();
chudy@google.com902ebe52012-06-29 14:21:22 +0000122}
123
chudy@google.combbad34d2012-08-13 14:26:36 +0000124SkDebuggerGUI::~SkDebuggerGUI() {
125 SkGraphics::Term();
126}
chudy@google.com902ebe52012-06-29 14:21:22 +0000127
128void SkDebuggerGUI::actionBreakpoints() {
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000129 fBreakpointsActivated = !fBreakpointsActivated;
chudy@google.comc432f002012-07-10 13:19:25 +0000130 for (int row = 0; row < fListWidget.count(); row++) {
131 QListWidgetItem *item = fListWidget.item(row);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000132 item->setHidden(item->checkState() == Qt::Unchecked && fBreakpointsActivated);
133 }
134}
chudy@google.com902ebe52012-06-29 14:21:22 +0000135
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000136void SkDebuggerGUI::showDeletes() {
137 fDeletesActivated = !fDeletesActivated;
138 for (int row = 0; row < fListWidget.count(); row++) {
139 QListWidgetItem *item = fListWidget.item(row);
chudy@google.com607357f2012-08-07 16:12:23 +0000140 item->setHidden(fDebugger.isCommandVisible(row)
141 && fDeletesActivated);
chudy@google.com902ebe52012-06-29 14:21:22 +0000142 }
143}
144
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000145// The timed picture playback uses the SkPicturePlayback's profiling stubs
146// to time individual commands. The offsets are needed to map SkPicture
147// offsets to individual commands.
148class SkTimedPicturePlayback : public SkPicturePlayback {
149public:
scroggo@google.com12705322013-10-01 15:30:46 +0000150 static SkTimedPicturePlayback* CreateFromStream(SkStream* stream, const SkPictInfo& info,
151 SkPicture::InstallPixelRefProc proc,
152 const SkTDArray<bool>& deletedCommands) {
153 // Mimics SkPicturePlayback::CreateFromStream
154 SkAutoTDelete<SkTimedPicturePlayback> playback(SkNEW_ARGS(SkTimedPicturePlayback,
155 (deletedCommands)));
156 if (!playback->parseStream(stream, info, proc)) {
157 return NULL; // we're invalid
158 }
159 return playback.detach();
160 }
161
162 SkTimedPicturePlayback(const SkTDArray<bool>& deletedCommands)
163 : INHERITED()
bungeman@google.come8cc6e82013-01-17 16:30:56 +0000164 , fSkipCommands(deletedCommands)
165 , fTot(0.0)
166 , fCurCommand(0) {
robertphillips@google.com6d9c92b2013-05-23 13:21:18 +0000167 fTimes.setCount(deletedCommands.count());
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000168 fTypeTimes.setCount(LAST_DRAWTYPE_ENUM+1);
169 this->resetTimes();
170 }
171
172 void resetTimes() {
robertphillips@google.com6d9c92b2013-05-23 13:21:18 +0000173 for (int i = 0; i < fTimes.count(); ++i) {
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000174 fTimes[i] = 0.0;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000175 }
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000176 for (int i = 0; i < fTypeTimes.count(); ++i) {
177 fTypeTimes[i] = 0.0f;
178 }
179 fTot = 0.0;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000180 }
181
182 int count() const { return fTimes.count(); }
183
184 double time(int index) const { return fTimes[index] / fTot; }
185
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000186 const SkTDArray<double>* typeTimes() const { return &fTypeTimes; }
187
188 double totTime() const { return fTot; }
189
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000190protected:
robertphillips@google.come174a8b2012-11-27 16:04:42 +0000191 BenchSysTimer fTimer;
robertphillips@google.com5f971142012-12-07 20:48:56 +0000192 SkTDArray<bool> fSkipCommands; // has the command been deleted in the GUI?
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000193 SkTDArray<double> fTimes; // sum of time consumed for each command
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000194 SkTDArray<double> fTypeTimes; // sum of time consumed for each type of command (e.g., drawPath)
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000195 double fTot; // total of all times in 'fTimes'
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000196 int fCurType;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000197 int fCurCommand; // the current command being executed/timed
198
robertphillips@google.com6d9c92b2013-05-23 13:21:18 +0000199#ifdef SK_DEVELOPER
200 virtual bool preDraw(int opIndex, int type) SK_OVERRIDE {
201 fCurCommand = opIndex;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000202
robertphillips@google.com5f971142012-12-07 20:48:56 +0000203 if (fSkipCommands[fCurCommand]) {
robertphillips@google.com6d9c92b2013-05-23 13:21:18 +0000204 return true;
robertphillips@google.com5f971142012-12-07 20:48:56 +0000205 }
206
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000207 fCurType = type;
208 // The SkDebugCanvas doesn't recognize these types. This class needs to
209 // convert or else we'll wind up with a mismatch between the type counts
210 // the debugger displays and the profile times.
211 if (DRAW_POS_TEXT_TOP_BOTTOM == type) {
212 fCurType = DRAW_POS_TEXT;
213 } else if (DRAW_POS_TEXT_H_TOP_BOTTOM == type) {
214 fCurType = DRAW_POS_TEXT_H;
215 }
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000216
robertphillips@google.come174a8b2012-11-27 16:04:42 +0000217#if defined(SK_BUILD_FOR_WIN32)
218 // CPU timer doesn't work well on Windows
219 fTimer.startWall();
220#else
221 fTimer.startCpu();
222#endif
robertphillips@google.com5f971142012-12-07 20:48:56 +0000223
robertphillips@google.com6d9c92b2013-05-23 13:21:18 +0000224 return false;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000225 }
226
robertphillips@google.com6d9c92b2013-05-23 13:21:18 +0000227 virtual void postDraw(int opIndex) SK_OVERRIDE {
robertphillips@google.come174a8b2012-11-27 16:04:42 +0000228#if defined(SK_BUILD_FOR_WIN32)
229 // CPU timer doesn't work well on Windows
230 double time = fTimer.endWall();
231#else
232 double time = fTimer.endCpu();
233#endif
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000234
robertphillips@google.com6d9c92b2013-05-23 13:21:18 +0000235 SkASSERT(opIndex == fCurCommand);
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000236 SkASSERT(fCurType <= LAST_DRAWTYPE_ENUM);
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000237
robertphillips@google.come174a8b2012-11-27 16:04:42 +0000238 fTimes[fCurCommand] += time;
239 fTypeTimes[fCurType] += time;
240 fTot += time;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000241 }
robertphillips@google.com6d9c92b2013-05-23 13:21:18 +0000242#endif
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000243
244private:
scroggo@google.com12705322013-10-01 15:30:46 +0000245 // SkPicturePlayback::parseStream is protected, so it can be
246 // called here, but not by our static factory function. This
247 // allows the factory function to call it.
248 bool parseStream(SkStream* stream, const SkPictInfo& info,
249 SkPicture::InstallPixelRefProc proc) {
250 return this->INHERITED::parseStream(stream, info, proc);
251 }
252
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000253 typedef SkPicturePlayback INHERITED;
254};
255
256// Wrap SkPicture to allow installation of an SkTimedPicturePlayback object
257class SkTimedPicture : public SkPicture {
258public:
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000259 static SkTimedPicture* CreateTimedPicture(SkStream* stream,
260 SkPicture::InstallPixelRefProc proc,
261 const SkTDArray<bool>& deletedCommands) {
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000262 SkPictInfo info;
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000263 if (!StreamIsSKP(stream, &info)) {
264 return NULL;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000265 }
266
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000267 SkTimedPicturePlayback* playback;
268 // Check to see if there is a playback to recreate.
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000269 if (stream->readBool()) {
scroggo@google.com12705322013-10-01 15:30:46 +0000270 playback = SkTimedPicturePlayback::CreateFromStream(stream, info, proc,
271 deletedCommands);
272 if (NULL == playback) {
273 return NULL;
274 }
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000275 } else {
276 playback = NULL;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000277 }
278
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000279 return SkNEW_ARGS(SkTimedPicture, (playback, info.fWidth, info.fHeight));
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000280 }
281
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000282 void resetTimes() { ((SkTimedPicturePlayback*) fPlayback)->resetTimes(); }
283
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000284 int count() const { return ((SkTimedPicturePlayback*) fPlayback)->count(); }
285
286 // return the fraction of the total time this command consumed
287 double time(int index) const { return ((SkTimedPicturePlayback*) fPlayback)->time(index); }
288
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000289 const SkTDArray<double>* typeTimes() const { return ((SkTimedPicturePlayback*) fPlayback)->typeTimes(); }
290
291 double totTime() const { return ((SkTimedPicturePlayback*) fPlayback)->totTime(); }
292
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000293private:
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000294 // disallow default ctor b.c. we don't have a good way to setup the fPlayback ptr
295 SkTimedPicture();
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000296 // Private ctor only used by CreateTimedPicture, which has created the playback.
297 SkTimedPicture(SkTimedPicturePlayback* playback, int width, int height)
298 : INHERITED(playback, width, height) {}
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000299 // 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
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000355 SkAutoTUnref<SkTimedPicture> picture(SkTimedPicture::CreateTimedPicture(&inputStream,
356 &SkImageDecoder::DecodeMemory, fSkipCommands));
357 if (NULL == picture.get()) {
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000358 return;
359 }
360
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000361 // For now this #if allows switching between tiled and simple rendering
362 // modes. Eventually this will be accomplished via the GUI
robertphillips@google.come174a8b2012-11-27 16:04:42 +0000363#if 0
364 // With the current batch of SysTimers, profiling in tiled mode
365 // gets swamped by the timing overhead:
366 //
367 // tile mode simple mode
368 // debugger 64.2ms 12.8ms
369 // bench_pictures 16.9ms 12.4ms
370 //
371 // This is b.c. in tiled mode each command is called many more times
372 // but typically does less work on each invocation (due to clipping)
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000373 sk_tools::TiledPictureRenderer* renderer = NULL;
374
375 renderer = SkNEW(sk_tools::TiledPictureRenderer);
376 renderer->setTileWidth(256);
377 renderer->setTileHeight(256);
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000378#else
379 sk_tools::SimplePictureRenderer* renderer = NULL;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000380
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000381 renderer = SkNEW(sk_tools::SimplePictureRenderer);
robertphillips@google.com1447aa32013-01-30 21:09:09 +0000382
383#if SK_SUPPORT_GPU
commit-bot@chromium.orgfde1e7c2013-08-02 13:59:50 +0000384 if (fSettingsWidget.isGLActive()) {
robertphillips@google.com1447aa32013-01-30 21:09:09 +0000385 renderer->setDeviceType(sk_tools::PictureRenderer::kGPU_DeviceType);
commit-bot@chromium.orgfde1e7c2013-08-02 13:59:50 +0000386 renderer->setSampleCount(fSettingsWidget.getGLSampleCount());
robertphillips@google.com1447aa32013-01-30 21:09:09 +0000387 }
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
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000394 run(picture.get(), renderer, kNumRepeats);
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000395
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000396 SkASSERT(picture->count() == fListWidget.count());
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000397
398 // extract the individual command times from the SkTimedPlaybackPicture
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000399 for (int i = 0; i < picture->count(); ++i) {
400 double temp = picture->time(i);
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000401
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
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000407 setupOverviewText(picture->typeTimes(), picture->totTime(), kNumRepeats);
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
commit-bot@chromium.orgfde1e7c2013-08-02 13:59:50 +0000484void SkDebuggerGUI::actionGLWidget() {
485 bool isToggled = fSettingsWidget.isGLActive();
486 if (isToggled) {
487 fCanvasWidget.setGLSampleCount(fSettingsWidget.getGLSampleCount());
488 }
chudy@google.comea5488b2012-07-26 19:38:22 +0000489 fCanvasWidget.setWidgetVisibility(SkCanvasWidget::kGPU_WidgetType, !isToggled);
490}
robertphillips@google.come8fe4bc2013-02-13 13:26:13 +0000491#endif
chudy@google.comea5488b2012-07-26 19:38:22 +0000492
chudy@google.com902ebe52012-06-29 14:21:22 +0000493void SkDebuggerGUI::actionInspector() {
chudy@google.comc432f002012-07-10 13:19:25 +0000494 if (fInspectorWidget.isHidden()) {
495 fInspectorWidget.setHidden(false);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000496 fImageWidget.setHidden(false);
chudy@google.com902ebe52012-06-29 14:21:22 +0000497 } else {
chudy@google.comc432f002012-07-10 13:19:25 +0000498 fInspectorWidget.setHidden(true);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000499 fImageWidget.setHidden(true);
chudy@google.com902ebe52012-06-29 14:21:22 +0000500 }
501}
502
503void SkDebuggerGUI::actionPlay() {
chudy@google.comc432f002012-07-10 13:19:25 +0000504 for (int row = fListWidget.currentRow() + 1; row < fListWidget.count();
chudy@google.com7dcae672012-07-09 20:26:53 +0000505 row++) {
chudy@google.comc432f002012-07-10 13:19:25 +0000506 QListWidgetItem *item = fListWidget.item(row);
chudy@google.com902ebe52012-06-29 14:21:22 +0000507 if (item->checkState() == Qt::Checked) {
chudy@google.comc432f002012-07-10 13:19:25 +0000508 fListWidget.setCurrentItem(item);
chudy@google.com902ebe52012-06-29 14:21:22 +0000509 return;
510 }
511 }
chudy@google.comc432f002012-07-10 13:19:25 +0000512 fListWidget.setCurrentRow(fListWidget.count() - 1);
chudy@google.com902ebe52012-06-29 14:21:22 +0000513}
514
chudy@google.comea5488b2012-07-26 19:38:22 +0000515void SkDebuggerGUI::actionRasterWidget(bool isToggled) {
516 fCanvasWidget.setWidgetVisibility(SkCanvasWidget::kRaster_8888_WidgetType, !isToggled);
517}
518
robertphillips@google.comf4741c12013-02-06 20:13:54 +0000519void SkDebuggerGUI::actionOverdrawVizWidget(bool isToggled) {
520 fDebugger.setOverdrawViz(isToggled);
521 fCanvasWidget.update();
522}
523
chudy@google.com902ebe52012-06-29 14:21:22 +0000524void SkDebuggerGUI::actionRewind() {
chudy@google.come504de02012-07-16 18:35:23 +0000525 fListWidget.setCurrentRow(0);
chudy@google.com902ebe52012-06-29 14:21:22 +0000526}
527
chudy@google.com0ab03392012-07-28 20:16:11 +0000528void SkDebuggerGUI::actionSave() {
robertphillips@google.come219baf2013-01-28 19:25:43 +0000529 fFileName = fPath.toAscii().data();
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000530 fFileName.append("/");
robertphillips@google.come219baf2013-01-28 19:25:43 +0000531 fFileName.append(fDirectoryWidget.currentItem()->text().toAscii().data());
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000532 saveToFile(fFileName);
chudy@google.com0ab03392012-07-28 20:16:11 +0000533}
534
535void SkDebuggerGUI::actionSaveAs() {
536 QString filename = QFileDialog::getSaveFileName(this, "Save File", "",
537 "Skia Picture (*skp)");
chudy@google.com38b08ce2012-07-28 23:26:10 +0000538 if (!filename.endsWith(".skp", Qt::CaseInsensitive)) {
chudy@google.com0ab03392012-07-28 20:16:11 +0000539 filename.append(".skp");
540 }
djsollen@google.comc3c82162012-11-13 18:35:10 +0000541 saveToFile(SkString(filename.toAscii().data()));
chudy@google.com0ab03392012-07-28 20:16:11 +0000542}
543
chudy@google.com7dcae672012-07-09 20:26:53 +0000544void SkDebuggerGUI::actionScale(float scaleFactor) {
chudy@google.comc432f002012-07-10 13:19:25 +0000545 fSettingsWidget.setZoomText(scaleFactor);
chudy@google.com7dcae672012-07-09 20:26:53 +0000546}
547
chudy@google.com902ebe52012-06-29 14:21:22 +0000548void SkDebuggerGUI::actionSettings() {
chudy@google.comc432f002012-07-10 13:19:25 +0000549 if (fSettingsWidget.isHidden()) {
550 fSettingsWidget.setHidden(false);
chudy@google.com902ebe52012-06-29 14:21:22 +0000551 } else {
chudy@google.comc432f002012-07-10 13:19:25 +0000552 fSettingsWidget.setHidden(true);
chudy@google.com902ebe52012-06-29 14:21:22 +0000553 }
554}
555
556void SkDebuggerGUI::actionStepBack() {
chudy@google.comc432f002012-07-10 13:19:25 +0000557 int currentRow = fListWidget.currentRow();
chudy@google.com902ebe52012-06-29 14:21:22 +0000558 if (currentRow != 0) {
chudy@google.comc432f002012-07-10 13:19:25 +0000559 fListWidget.setCurrentRow(currentRow - 1);
chudy@google.com902ebe52012-06-29 14:21:22 +0000560 }
561}
562
563void SkDebuggerGUI::actionStepForward() {
chudy@google.comc432f002012-07-10 13:19:25 +0000564 int currentRow = fListWidget.currentRow();
chudy@google.com902ebe52012-06-29 14:21:22 +0000565 QString curRow = QString::number(currentRow);
chudy@google.comc432f002012-07-10 13:19:25 +0000566 QString curCount = QString::number(fListWidget.count());
567 if (currentRow < fListWidget.count() - 1) {
568 fListWidget.setCurrentRow(currentRow + 1);
chudy@google.com902ebe52012-06-29 14:21:22 +0000569 }
570}
571
chudy@google.coma9e937c2012-08-03 17:32:05 +0000572void SkDebuggerGUI::drawComplete() {
chudy@google.com607357f2012-08-07 16:12:23 +0000573 fInspectorWidget.setMatrix(fDebugger.getCurrentMatrix());
574 fInspectorWidget.setClip(fDebugger.getCurrentClip());
chudy@google.coma9e937c2012-08-03 17:32:05 +0000575}
576
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000577void SkDebuggerGUI::saveToFile(const SkString& filename) {
578 SkFILEWStream file(filename.c_str());
robertphillips@google.com25bc2f82013-01-22 18:03:56 +0000579 SkAutoTUnref<SkPicture> copy(fDebugger.copyPicture());
580
581 copy->serialize(&file);
chudy@google.com0ab03392012-07-28 20:16:11 +0000582}
583
chudy@google.com902ebe52012-06-29 14:21:22 +0000584void SkDebuggerGUI::loadFile(QListWidgetItem *item) {
585 if (fDirectoryWidgetActive) {
robertphillips@google.come219baf2013-01-28 19:25:43 +0000586 fFileName = fPath.toAscii().data();
jvanverth@google.com0ac6f162013-02-05 19:44:07 +0000587 // don't add a '/' to files in the local directory
588 if (fFileName.size() > 0) {
589 fFileName.append("/");
590 }
robertphillips@google.come219baf2013-01-28 19:25:43 +0000591 fFileName.append(item->text().toAscii().data());
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000592 loadPicture(fFileName);
chudy@google.com902ebe52012-06-29 14:21:22 +0000593 }
594}
595
596void SkDebuggerGUI::openFile() {
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000597 QString temp = QFileDialog::getOpenFileName(this, tr("Open File"), "",
chudy@google.com7dcae672012-07-09 20:26:53 +0000598 tr("Files (*.*)"));
robertphillips@google.comff6e6ba2013-01-28 17:43:26 +0000599 openFile(temp);
600}
601
602void SkDebuggerGUI::openFile(const QString &filename) {
chudy@google.com902ebe52012-06-29 14:21:22 +0000603 fDirectoryWidgetActive = false;
robertphillips@google.comff6e6ba2013-01-28 17:43:26 +0000604 if (!filename.isEmpty()) {
605 QFileInfo pathInfo(filename);
606 loadPicture(SkString(filename.toAscii().data()));
607 setupDirectoryWidget(pathInfo.path());
chudy@google.com902ebe52012-06-29 14:21:22 +0000608 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000609 fDirectoryWidgetActive = true;
610}
611
chudy@google.comc432f002012-07-10 13:19:25 +0000612void SkDebuggerGUI::pauseDrawing(bool isPaused) {
chudy@google.com607357f2012-08-07 16:12:23 +0000613 fPause = isPaused;
614 fPausedRow = fListWidget.currentRow();
615 fCanvasWidget.drawTo(fPausedRow);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000616 fImageWidget.draw();
chudy@google.com7dcae672012-07-09 20:26:53 +0000617}
618
chudy@google.com902ebe52012-06-29 14:21:22 +0000619void SkDebuggerGUI::registerListClick(QListWidgetItem *item) {
chudy@google.comd3058f52012-07-19 13:41:27 +0000620 if(!fLoading) {
621 int currentRow = fListWidget.currentRow();
chudy@google.comd3058f52012-07-19 13:41:27 +0000622
chudy@google.comea5488b2012-07-26 19:38:22 +0000623 if (currentRow != -1) {
624 if (!fPause) {
625 fCanvasWidget.drawTo(currentRow);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000626 fImageWidget.draw();
chudy@google.comd3058f52012-07-19 13:41:27 +0000627 }
chudy@google.com97cee972012-08-07 20:41:37 +0000628 SkTDArray<SkString*> *currInfo = fDebugger.getCommandInfo(
chudy@google.comea5488b2012-07-26 19:38:22 +0000629 currentRow);
630
631 /* TODO(chudy): Add command type before parameters. Rename v
632 * to something more informative. */
chudy@google.com97cee972012-08-07 20:41:37 +0000633 if (currInfo) {
chudy@google.comea5488b2012-07-26 19:38:22 +0000634 QString info;
635 info.append("<b>Parameters: </b><br/>");
chudy@google.com97cee972012-08-07 20:41:37 +0000636 for (int i = 0; i < currInfo->count(); i++) {
637
638 info.append(QString((*currInfo)[i]->c_str()));
chudy@google.comea5488b2012-07-26 19:38:22 +0000639 info.append("<br/>");
640 }
chudy@google.com6bd109a2012-08-14 19:34:13 +0000641 fInspectorWidget.setText(info, SkInspectorWidget::kDetail_TabType);
chudy@google.comea5488b2012-07-26 19:38:22 +0000642 fInspectorWidget.setDisabled(false);
chudy@google.comea5488b2012-07-26 19:38:22 +0000643 }
chudy@google.comd3058f52012-07-19 13:41:27 +0000644 }
chudy@google.comea5488b2012-07-26 19:38:22 +0000645
chudy@google.com902ebe52012-06-29 14:21:22 +0000646 }
647}
648
chudy@google.com9ca9bfe2012-07-12 21:58:14 +0000649void SkDebuggerGUI::selectCommand(int command) {
650 if (fPause) {
651 fListWidget.setCurrentRow(command);
652 }
653}
654
chudy@google.com902ebe52012-06-29 14:21:22 +0000655void SkDebuggerGUI::toggleBreakpoint() {
chudy@google.comc432f002012-07-10 13:19:25 +0000656 QListWidgetItem* item = fListWidget.currentItem();
chudy@google.com902ebe52012-06-29 14:21:22 +0000657 if (item->checkState() == Qt::Unchecked) {
658 item->setCheckState(Qt::Checked);
chudy@google.come565de42012-07-12 14:15:54 +0000659 item->setData(Qt::DecorationRole,
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000660 QPixmap(":/breakpoint_16x16.png"));
chudy@google.com902ebe52012-06-29 14:21:22 +0000661 } else {
chudy@google.com902ebe52012-06-29 14:21:22 +0000662 item->setCheckState(Qt::Unchecked);
chudy@google.come565de42012-07-12 14:15:54 +0000663 item->setData(Qt::DecorationRole,
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000664 QPixmap(":/blank.png"));
chudy@google.com902ebe52012-06-29 14:21:22 +0000665 }
666}
667
668void SkDebuggerGUI::toggleDirectory() {
chudy@google.com607357f2012-08-07 16:12:23 +0000669 fDirectoryWidget.setHidden(!fDirectoryWidget.isHidden());
chudy@google.com902ebe52012-06-29 14:21:22 +0000670}
671
672void SkDebuggerGUI::toggleFilter(QString string) {
chudy@google.comc432f002012-07-10 13:19:25 +0000673 for (int row = 0; row < fListWidget.count(); row++) {
674 QListWidgetItem *item = fListWidget.item(row);
chudy@google.com607357f2012-08-07 16:12:23 +0000675 item->setHidden(item->text() != string);
chudy@google.com902ebe52012-06-29 14:21:22 +0000676 }
677}
678
679void SkDebuggerGUI::setupUi(QMainWindow *SkDebuggerGUI) {
680 QIcon windowIcon;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000681 windowIcon.addFile(QString::fromUtf8(":/skia.png"), QSize(),
chudy@google.com7dcae672012-07-09 20:26:53 +0000682 QIcon::Normal, QIcon::Off);
chudy@google.com902ebe52012-06-29 14:21:22 +0000683 SkDebuggerGUI->setObjectName(QString::fromUtf8("SkDebuggerGUI"));
684 SkDebuggerGUI->resize(1200, 1000);
685 SkDebuggerGUI->setWindowIcon(windowIcon);
chudy@google.comc432f002012-07-10 13:19:25 +0000686 SkDebuggerGUI->setWindowTitle("Skia Debugger");
chudy@google.com902ebe52012-06-29 14:21:22 +0000687
chudy@google.come504de02012-07-16 18:35:23 +0000688 fActionOpen.setShortcuts(QKeySequence::Open);
chudy@google.comc432f002012-07-10 13:19:25 +0000689 fActionOpen.setText("Open");
chudy@google.com902ebe52012-06-29 14:21:22 +0000690
691 QIcon breakpoint;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000692 breakpoint.addFile(QString::fromUtf8(":/breakpoint.png"),
chudy@google.com7dcae672012-07-09 20:26:53 +0000693 QSize(), QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000694 fActionBreakpoint.setShortcut(QKeySequence(tr("Ctrl+B")));
chudy@google.comc432f002012-07-10 13:19:25 +0000695 fActionBreakpoint.setIcon(breakpoint);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000696 fActionBreakpoint.setText("Breakpoints");
chudy@google.com902ebe52012-06-29 14:21:22 +0000697
698 QIcon cancel;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000699 cancel.addFile(QString::fromUtf8(":/reload.png"), QSize(),
chudy@google.com7dcae672012-07-09 20:26:53 +0000700 QIcon::Normal, QIcon::Off);
chudy@google.comc432f002012-07-10 13:19:25 +0000701 fActionCancel.setIcon(cancel);
702 fActionCancel.setText("Clear Filter");
chudy@google.com902ebe52012-06-29 14:21:22 +0000703
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000704 fActionClearBreakpoints.setShortcut(QKeySequence(tr("Alt+B")));
705 fActionClearBreakpoints.setText("Clear Breakpoints");
706
707 fActionClearDeletes.setShortcut(QKeySequence(tr("Alt+X")));
708 fActionClearDeletes.setText("Clear Deletes");
709
chudy@google.come504de02012-07-16 18:35:23 +0000710 fActionClose.setShortcuts(QKeySequence::Quit);
chudy@google.comc432f002012-07-10 13:19:25 +0000711 fActionClose.setText("Exit");
chudy@google.com902ebe52012-06-29 14:21:22 +0000712
chudy@google.come504de02012-07-16 18:35:23 +0000713 fActionCreateBreakpoint.setShortcut(QKeySequence(tr("B")));
714 fActionCreateBreakpoint.setText("Set Breakpoint");
715
716 fActionDelete.setShortcut(QKeySequence(tr("X")));
chudy@google.comc432f002012-07-10 13:19:25 +0000717 fActionDelete.setText("Delete Command");
chudy@google.com902ebe52012-06-29 14:21:22 +0000718
chudy@google.come504de02012-07-16 18:35:23 +0000719 fActionDirectory.setShortcut(QKeySequence(tr("Ctrl+D")));
720 fActionDirectory.setText("Directory");
chudy@google.com902ebe52012-06-29 14:21:22 +0000721
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000722 QIcon profile;
robertphillips@google.comd1636362012-11-19 18:25:09 +0000723 profile.addFile(QString::fromUtf8(":/profile.png"), QSize(),
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000724 QIcon::Normal, QIcon::Off);
725 fActionProfile.setIcon(profile);
726 fActionProfile.setText("Profile");
robertphillips@google.come099bc42012-11-19 16:26:40 +0000727 fActionProfile.setDisabled(true);
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000728
chudy@google.comc432f002012-07-10 13:19:25 +0000729 QIcon inspector;
robertphillips@google.comd1636362012-11-19 18:25:09 +0000730 inspector.addFile(QString::fromUtf8(":/inspector.png"),
chudy@google.comc432f002012-07-10 13:19:25 +0000731 QSize(), QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000732 fActionInspector.setShortcut(QKeySequence(tr("Ctrl+I")));
chudy@google.comc432f002012-07-10 13:19:25 +0000733 fActionInspector.setIcon(inspector);
chudy@google.come504de02012-07-16 18:35:23 +0000734 fActionInspector.setText("Inspector");
chudy@google.com902ebe52012-06-29 14:21:22 +0000735
bungeman@google.com2ff6d1d2013-07-01 14:24:12 +0000736 QIcon settings;
737 settings.addFile(QString::fromUtf8(":/inspector.png"),
738 QSize(), QIcon::Normal, QIcon::Off);
739 fActionSettings.setShortcut(QKeySequence(tr("Ctrl+G")));
740 fActionSettings.setIcon(settings);
741 fActionSettings.setText("Settings");
skia.committer@gmail.com0d55dd72013-07-02 07:00:59 +0000742
chudy@google.comc432f002012-07-10 13:19:25 +0000743 QIcon play;
robertphillips@google.comd1636362012-11-19 18:25:09 +0000744 play.addFile(QString::fromUtf8(":/play.png"), QSize(),
chudy@google.comc432f002012-07-10 13:19:25 +0000745 QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000746 fActionPlay.setShortcut(QKeySequence(tr("Ctrl+P")));
chudy@google.comc432f002012-07-10 13:19:25 +0000747 fActionPlay.setIcon(play);
748 fActionPlay.setText("Play");
chudy@google.com902ebe52012-06-29 14:21:22 +0000749
chudy@google.come504de02012-07-16 18:35:23 +0000750 QIcon pause;
robertphillips@google.comd1636362012-11-19 18:25:09 +0000751 pause.addFile(QString::fromUtf8(":/pause.png"), QSize(),
chudy@google.comc432f002012-07-10 13:19:25 +0000752 QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000753 fActionPause.setShortcut(QKeySequence(tr("Space")));
754 fActionPause.setCheckable(true);
755 fActionPause.setIcon(pause);
756 fActionPause.setText("Pause");
757
chudy@google.comc432f002012-07-10 13:19:25 +0000758 QIcon rewind;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000759 rewind.addFile(QString::fromUtf8(":/rewind.png"), QSize(),
chudy@google.comc432f002012-07-10 13:19:25 +0000760 QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000761 fActionRewind.setShortcut(QKeySequence(tr("Ctrl+R")));
chudy@google.comc432f002012-07-10 13:19:25 +0000762 fActionRewind.setIcon(rewind);
763 fActionRewind.setText("Rewind");
chudy@google.com902ebe52012-06-29 14:21:22 +0000764
chudy@google.com0ab03392012-07-28 20:16:11 +0000765 fActionSave.setShortcut(QKeySequence::Save);
766 fActionSave.setText("Save");
767 fActionSave.setDisabled(true);
768 fActionSaveAs.setShortcut(QKeySequence::SaveAs);
769 fActionSaveAs.setText("Save As");
770 fActionSaveAs.setDisabled(true);
771
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000772 fActionShowDeletes.setShortcut(QKeySequence(tr("Ctrl+X")));
773 fActionShowDeletes.setText("Deleted Commands");
774
chudy@google.comc432f002012-07-10 13:19:25 +0000775 QIcon stepBack;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000776 stepBack.addFile(QString::fromUtf8(":/previous.png"), QSize(),
chudy@google.comc432f002012-07-10 13:19:25 +0000777 QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000778 fActionStepBack.setShortcut(QKeySequence(tr("[")));
chudy@google.comc432f002012-07-10 13:19:25 +0000779 fActionStepBack.setIcon(stepBack);
780 fActionStepBack.setText("Step Back");
chudy@google.com902ebe52012-06-29 14:21:22 +0000781
chudy@google.comc432f002012-07-10 13:19:25 +0000782 QIcon stepForward;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000783 stepForward.addFile(QString::fromUtf8(":/next.png"),
chudy@google.comc432f002012-07-10 13:19:25 +0000784 QSize(), QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000785 fActionStepForward.setShortcut(QKeySequence(tr("]")));
chudy@google.comc432f002012-07-10 13:19:25 +0000786 fActionStepForward.setIcon(stepForward);
787 fActionStepForward.setText("Step Forward");
788
chudy@google.coma1226312012-07-26 20:26:44 +0000789 fActionZoomIn.setShortcut(QKeySequence(tr("Ctrl+=")));
790 fActionZoomIn.setText("Zoom In");
791 fActionZoomOut.setShortcut(QKeySequence(tr("Ctrl+-")));
792 fActionZoomOut.setText("Zoom Out");
793
chudy@google.comc432f002012-07-10 13:19:25 +0000794 fListWidget.setItemDelegate(new SkListWidget(&fListWidget));
795 fListWidget.setObjectName(QString::fromUtf8("listWidget"));
796 fListWidget.setMaximumWidth(250);
797
798 fFilter.addItem("--Filter By Available Commands--");
799
800 fDirectoryWidget.setMaximumWidth(250);
801 fDirectoryWidget.setStyleSheet("QListWidget::Item {padding: 5px;}");
802
803 fCanvasWidget.setSizePolicy(QSizePolicy::Expanding,
chudy@google.com7dcae672012-07-09 20:26:53 +0000804 QSizePolicy::Expanding);
chudy@google.com902ebe52012-06-29 14:21:22 +0000805
skia.committer@gmail.com1c9c0d32012-11-22 02:02:41 +0000806 fImageWidget.setFixedSize(SkImageWidget::kImageWidgetWidth,
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000807 SkImageWidget::kImageWidgetHeight);
808
chudy@google.comc432f002012-07-10 13:19:25 +0000809 fInspectorWidget.setSizePolicy(QSizePolicy::Expanding,
chudy@google.com7dcae672012-07-09 20:26:53 +0000810 QSizePolicy::Expanding);
chudy@google.comc432f002012-07-10 13:19:25 +0000811 fInspectorWidget.setMaximumHeight(300);
chudy@google.com902ebe52012-06-29 14:21:22 +0000812
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000813 fSettingsAndImageLayout.setSpacing(6);
814 fSettingsAndImageLayout.addWidget(&fSettingsWidget);
815 fSettingsAndImageLayout.addWidget(&fImageWidget);
816
chudy@google.comc432f002012-07-10 13:19:25 +0000817 fSettingsWidget.setSizePolicy(QSizePolicy::Expanding,
818 QSizePolicy::Expanding);
819 fSettingsWidget.setMaximumWidth(250);
chudy@google.com902ebe52012-06-29 14:21:22 +0000820
chudy@google.comc432f002012-07-10 13:19:25 +0000821 fLeftColumnLayout.setSpacing(6);
822 fLeftColumnLayout.addWidget(&fListWidget);
823 fLeftColumnLayout.addWidget(&fDirectoryWidget);
chudy@google.com902ebe52012-06-29 14:21:22 +0000824
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000825 fCanvasSettingsAndImageLayout.setSpacing(6);
826 fCanvasSettingsAndImageLayout.addWidget(&fCanvasWidget);
827 fCanvasSettingsAndImageLayout.addLayout(&fSettingsAndImageLayout);
828
chudy@google.com902ebe52012-06-29 14:21:22 +0000829
chudy@google.comc432f002012-07-10 13:19:25 +0000830 fMainAndRightColumnLayout.setSpacing(6);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000831 fMainAndRightColumnLayout.addLayout(&fCanvasSettingsAndImageLayout);
chudy@google.comc432f002012-07-10 13:19:25 +0000832 fMainAndRightColumnLayout.addWidget(&fInspectorWidget);
chudy@google.com902ebe52012-06-29 14:21:22 +0000833
chudy@google.com2d537a12012-07-31 12:49:52 +0000834 fCentralWidget.setLayout(&fContainerLayout);
chudy@google.comc432f002012-07-10 13:19:25 +0000835 fContainerLayout.setSpacing(6);
836 fContainerLayout.setContentsMargins(11, 11, 11, 11);
837 fContainerLayout.addLayout(&fLeftColumnLayout);
838 fContainerLayout.addLayout(&fMainAndRightColumnLayout);
839
840 SkDebuggerGUI->setCentralWidget(&fCentralWidget);
841 SkDebuggerGUI->setStatusBar(&fStatusBar);
842
chudy@google.come504de02012-07-16 18:35:23 +0000843 fToolBar.setIconSize(QSize(32, 32));
chudy@google.comc432f002012-07-10 13:19:25 +0000844 fToolBar.setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
845 SkDebuggerGUI->addToolBar(Qt::TopToolBarArea, &fToolBar);
chudy@google.com902ebe52012-06-29 14:21:22 +0000846
chudy@google.com0ab03392012-07-28 20:16:11 +0000847 fSpacer.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
chudy@google.com902ebe52012-06-29 14:21:22 +0000848
chudy@google.comc432f002012-07-10 13:19:25 +0000849 fToolBar.addAction(&fActionRewind);
850 fToolBar.addAction(&fActionStepBack);
chudy@google.come504de02012-07-16 18:35:23 +0000851 fToolBar.addAction(&fActionPause);
chudy@google.comc432f002012-07-10 13:19:25 +0000852 fToolBar.addAction(&fActionStepForward);
853 fToolBar.addAction(&fActionPlay);
854 fToolBar.addSeparator();
chudy@google.come504de02012-07-16 18:35:23 +0000855 fToolBar.addAction(&fActionInspector);
bungeman@google.com2ff6d1d2013-07-01 14:24:12 +0000856 fToolBar.addAction(&fActionSettings);
chudy@google.comc432f002012-07-10 13:19:25 +0000857 fToolBar.addSeparator();
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000858 fToolBar.addAction(&fActionProfile);
859
860 fToolBar.addSeparator();
chudy@google.com0ab03392012-07-28 20:16:11 +0000861 fToolBar.addWidget(&fSpacer);
chudy@google.comc432f002012-07-10 13:19:25 +0000862 fToolBar.addWidget(&fFilter);
863 fToolBar.addAction(&fActionCancel);
chudy@google.com902ebe52012-06-29 14:21:22 +0000864
865 // TODO(chudy): Remove static call.
866 fDirectoryWidgetActive = false;
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000867 fFileName = "";
robertphillips@google.comff6e6ba2013-01-28 17:43:26 +0000868 setupDirectoryWidget("");
chudy@google.com902ebe52012-06-29 14:21:22 +0000869 fDirectoryWidgetActive = true;
870
chudy@google.com902ebe52012-06-29 14:21:22 +0000871 // Menu Bar
chudy@google.comc432f002012-07-10 13:19:25 +0000872 fMenuFile.setTitle("File");
873 fMenuFile.addAction(&fActionOpen);
chudy@google.com0ab03392012-07-28 20:16:11 +0000874 fMenuFile.addAction(&fActionSave);
875 fMenuFile.addAction(&fActionSaveAs);
chudy@google.comc432f002012-07-10 13:19:25 +0000876 fMenuFile.addAction(&fActionClose);
chudy@google.come504de02012-07-16 18:35:23 +0000877
878 fMenuEdit.setTitle("Edit");
879 fMenuEdit.addAction(&fActionDelete);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000880 fMenuEdit.addAction(&fActionClearDeletes);
881 fMenuEdit.addSeparator();
chudy@google.come504de02012-07-16 18:35:23 +0000882 fMenuEdit.addAction(&fActionCreateBreakpoint);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000883 fMenuEdit.addAction(&fActionClearBreakpoints);
chudy@google.come504de02012-07-16 18:35:23 +0000884
chudy@google.comc432f002012-07-10 13:19:25 +0000885 fMenuNavigate.setTitle("Navigate");
chudy@google.come504de02012-07-16 18:35:23 +0000886 fMenuNavigate.addAction(&fActionRewind);
887 fMenuNavigate.addAction(&fActionStepBack);
888 fMenuNavigate.addAction(&fActionStepForward);
889 fMenuNavigate.addAction(&fActionPlay);
890 fMenuNavigate.addAction(&fActionPause);
chudy@google.comc432f002012-07-10 13:19:25 +0000891 fMenuNavigate.addAction(&fActionGoToLine);
chudy@google.come504de02012-07-16 18:35:23 +0000892
chudy@google.comc432f002012-07-10 13:19:25 +0000893 fMenuView.setTitle("View");
chudy@google.come504de02012-07-16 18:35:23 +0000894 fMenuView.addAction(&fActionBreakpoint);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000895 fMenuView.addAction(&fActionShowDeletes);
chudy@google.coma1226312012-07-26 20:26:44 +0000896 fMenuView.addAction(&fActionZoomIn);
897 fMenuView.addAction(&fActionZoomOut);
chudy@google.come504de02012-07-16 18:35:23 +0000898
899 fMenuWindows.setTitle("Window");
900 fMenuWindows.addAction(&fActionInspector);
bungeman@google.com2ff6d1d2013-07-01 14:24:12 +0000901 fMenuWindows.addAction(&fActionSettings);
chudy@google.come504de02012-07-16 18:35:23 +0000902 fMenuWindows.addAction(&fActionDirectory);
chudy@google.comc432f002012-07-10 13:19:25 +0000903
904 fActionGoToLine.setText("Go to Line...");
905 fActionGoToLine.setDisabled(true);
906 fMenuBar.addAction(fMenuFile.menuAction());
chudy@google.come504de02012-07-16 18:35:23 +0000907 fMenuBar.addAction(fMenuEdit.menuAction());
chudy@google.comc432f002012-07-10 13:19:25 +0000908 fMenuBar.addAction(fMenuView.menuAction());
909 fMenuBar.addAction(fMenuNavigate.menuAction());
chudy@google.come504de02012-07-16 18:35:23 +0000910 fMenuBar.addAction(fMenuWindows.menuAction());
chudy@google.com902ebe52012-06-29 14:21:22 +0000911
chudy@google.com7dcae672012-07-09 20:26:53 +0000912 fPause = false;
913
chudy@google.comc432f002012-07-10 13:19:25 +0000914 SkDebuggerGUI->setMenuBar(&fMenuBar);
chudy@google.com902ebe52012-06-29 14:21:22 +0000915 QMetaObject::connectSlotsByName(SkDebuggerGUI);
916}
917
robertphillips@google.comff6e6ba2013-01-28 17:43:26 +0000918void SkDebuggerGUI::setupDirectoryWidget(const QString& path) {
919 fPath = path;
920 QDir dir(path);
chudy@google.com902ebe52012-06-29 14:21:22 +0000921 QRegExp r(".skp");
chudy@google.comc432f002012-07-10 13:19:25 +0000922 fDirectoryWidget.clear();
923 const QStringList files = dir.entryList();
chudy@google.com902ebe52012-06-29 14:21:22 +0000924 foreach (QString f, files) {
chudy@google.com7dcae672012-07-09 20:26:53 +0000925 if (f.contains(r))
chudy@google.comc432f002012-07-10 13:19:25 +0000926 fDirectoryWidget.addItem(f);
chudy@google.com902ebe52012-06-29 14:21:22 +0000927 }
928}
929
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000930void SkDebuggerGUI::loadPicture(const SkString& fileName) {
931 fFileName = fileName;
chudy@google.comd3058f52012-07-19 13:41:27 +0000932 fLoading = true;
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000933 SkStream* stream = SkNEW_ARGS(SkFILEStream, (fileName.c_str()));
robertphillips@google.com2d40ec42013-02-07 20:39:40 +0000934
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000935 SkPicture* picture = SkPicture::CreateFromStream(stream);
robertphillips@google.com2d40ec42013-02-07 20:39:40 +0000936
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000937 if (NULL == picture) {
robertphillips@google.com2d40ec42013-02-07 20:39:40 +0000938 QMessageBox::critical(this, "Error loading file", "Couldn't read file, sorry.");
939 SkSafeUnref(stream);
940 return;
941 }
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000942
chudy@google.com686e6802012-08-14 16:00:32 +0000943 fCanvasWidget.resetWidgetTransform();
chudy@google.com607357f2012-08-07 16:12:23 +0000944 fDebugger.loadPicture(picture);
chudy@google.com4c7962e2012-08-14 19:38:31 +0000945
robertphillips@google.com6d9c92b2013-05-23 13:21:18 +0000946 fSkipCommands.setCount(fDebugger.getSize());
947 for (int i = 0; i < fSkipCommands.count(); ++i) {
robertphillips@google.com5f971142012-12-07 20:48:56 +0000948 fSkipCommands[i] = false;
949 }
950
chudy@google.com607357f2012-08-07 16:12:23 +0000951 SkSafeUnref(stream);
952 SkSafeUnref(picture);
953
chudy@google.com97cee972012-08-07 20:41:37 +0000954 // Will this automatically clear out due to nature of refcnt?
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000955 SkTArray<SkString>* commands = fDebugger.getDrawCommandsAsStrings();
chudy@google.com607357f2012-08-07 16:12:23 +0000956
robertphillips@google.com6d9c92b2013-05-23 13:21:18 +0000957 fActionProfile.setDisabled(false);
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000958
chudy@google.com7dcae672012-07-09 20:26:53 +0000959 /* fDebugCanvas is reinitialized every load picture. Need it to retain value
chudy@google.com607357f2012-08-07 16:12:23 +0000960 * of the visibility filter.
961 * TODO(chudy): This should be deprecated since fDebugger is not
962 * recreated.
963 * */
964 fDebugger.highlightCurrentCommand(fSettingsWidget.getVisibilityButton()->isChecked());
965
chudy@google.com97cee972012-08-07 20:41:37 +0000966 setupListWidget(commands);
967 setupComboBox(commands);
robertphillips@google.come428f9b2013-03-12 15:33:40 +0000968 setupOverviewText(NULL, 0.0, 1);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000969 fInspectorWidget.setDisabled(false);
chudy@google.come606d6e2012-07-12 14:31:25 +0000970 fSettingsWidget.setDisabled(false);
chudy@google.comd3058f52012-07-19 13:41:27 +0000971 fMenuEdit.setDisabled(false);
972 fMenuNavigate.setDisabled(false);
973 fMenuView.setDisabled(false);
chudy@google.com0ab03392012-07-28 20:16:11 +0000974 fActionSave.setDisabled(false);
975 fActionSaveAs.setDisabled(false);
chudy@google.comd3058f52012-07-19 13:41:27 +0000976 fLoading = false;
977 actionPlay();
chudy@google.com902ebe52012-06-29 14:21:22 +0000978}
979
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000980void SkDebuggerGUI::setupListWidget(SkTArray<SkString>* command) {
chudy@google.comc432f002012-07-10 13:19:25 +0000981 fListWidget.clear();
chudy@google.com902ebe52012-06-29 14:21:22 +0000982 int counter = 0;
robertphillips@google.com30d35f22012-11-06 16:45:36 +0000983 int indent = 0;
chudy@google.com97cee972012-08-07 20:41:37 +0000984 for (int i = 0; i < command->count(); i++) {
chudy@google.com902ebe52012-06-29 14:21:22 +0000985 QListWidgetItem *item = new QListWidgetItem();
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000986 item->setData(Qt::DisplayRole, (*command)[i].c_str());
chudy@google.com902ebe52012-06-29 14:21:22 +0000987 item->setData(Qt::UserRole + 1, counter++);
robertphillips@google.com30d35f22012-11-06 16:45:36 +0000988
robertphillips@google.com0a4805e2013-05-29 13:24:23 +0000989 if (0 == strcmp("Restore", (*command)[i].c_str()) ||
990 0 == strcmp("EndCommentGroup", (*command)[i].c_str())) {
robertphillips@google.com30d35f22012-11-06 16:45:36 +0000991 indent -= 10;
992 }
993
994 item->setData(Qt::UserRole + 3, indent);
995
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000996 if (0 == strcmp("Save", (*command)[i].c_str()) ||
robertphillips@google.com0a4805e2013-05-29 13:24:23 +0000997 0 == strcmp("Save Layer", (*command)[i].c_str()) ||
998 0 == strcmp("BeginCommentGroup", (*command)[i].c_str())) {
robertphillips@google.com30d35f22012-11-06 16:45:36 +0000999 indent += 10;
1000 }
1001
robertphillips@google.comd26c7062012-11-12 20:42:12 +00001002 item->setData(Qt::UserRole + 4, -1.0);
1003
chudy@google.comc432f002012-07-10 13:19:25 +00001004 fListWidget.addItem(item);
chudy@google.com902ebe52012-06-29 14:21:22 +00001005 }
1006}
1007
skia.committer@gmail.com91274b92013-03-13 07:01:04 +00001008void SkDebuggerGUI::setupOverviewText(const SkTDArray<double>* typeTimes,
robertphillips@google.come428f9b2013-03-12 15:33:40 +00001009 double totTime,
1010 int numRuns) {
borenet@google.com2d9dbd42013-03-12 13:07:40 +00001011 SkString overview;
robertphillips@google.come428f9b2013-03-12 15:33:40 +00001012 fDebugger.getOverviewText(typeTimes, totTime, &overview, numRuns);
borenet@google.com2d9dbd42013-03-12 13:07:40 +00001013 fInspectorWidget.setText(overview.c_str(), SkInspectorWidget::kOverview_TabType);
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +00001014}
1015
1016void SkDebuggerGUI::setupComboBox(SkTArray<SkString>* command) {
1017 fFilter.clear();
1018 fFilter.addItem("--Filter By Available Commands--");
1019
1020 std::map<std::string, int> map;
1021 for (int i = 0; i < command->count(); i++) {
1022 map[(*command)[i].c_str()]++;
1023 }
1024
skia.committer@gmail.com34587162012-11-20 02:01:23 +00001025 for (std::map<std::string, int>::iterator it = map.begin(); it != map.end();
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +00001026 ++it) {
1027 fFilter.addItem((it->first).c_str());
1028 }
chudy@google.com902ebe52012-06-29 14:21:22 +00001029
1030 // NOTE(chudy): Makes first item unselectable.
chudy@google.com7dcae672012-07-09 20:26:53 +00001031 QStandardItemModel* model = qobject_cast<QStandardItemModel*>(
chudy@google.comc432f002012-07-10 13:19:25 +00001032 fFilter.model());
1033 QModelIndex firstIndex = model->index(0, fFilter.modelColumn(),
1034 fFilter.rootModelIndex());
chudy@google.com902ebe52012-06-29 14:21:22 +00001035 QStandardItem* firstItem = model->itemFromIndex(firstIndex);
1036 firstItem->setSelectable(false);
1037}