blob: fad5c0cd554b37fa4b071d56922201a0cd9b9edf [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
robertphillips@google.com32bbcf82013-10-17 17:56:10 +000097 connect(&fSettingsWidget, SIGNAL(texFilterSettingsChanged()), this, SLOT(actionTextureFilter()));
chudy@google.comea5488b2012-07-26 19:38:22 +000098 connect(fSettingsWidget.getRasterCheckBox(), SIGNAL(toggled(bool)), this, SLOT(actionRasterWidget(bool)));
robertphillips@google.comf4741c12013-02-06 20:13:54 +000099 connect(fSettingsWidget.getOverdrawVizCheckBox(), SIGNAL(toggled(bool)), this, SLOT(actionOverdrawVizWidget(bool)));
chudy@google.comea5488b2012-07-26 19:38:22 +0000100 connect(&fActionPause, SIGNAL(toggled(bool)), this, SLOT(pauseDrawing(bool)));
chudy@google.come504de02012-07-16 18:35:23 +0000101 connect(&fActionCreateBreakpoint, SIGNAL(activated()), this, SLOT(toggleBreakpoint()));
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000102 connect(&fActionShowDeletes, SIGNAL(triggered()), this, SLOT(showDeletes()));
chudy@google.comea5488b2012-07-26 19:38:22 +0000103 connect(&fCanvasWidget, SIGNAL(hitChanged(int)), this, SLOT(selectCommand(int)));
104 connect(&fCanvasWidget, SIGNAL(hitChanged(int)), &fSettingsWidget, SLOT(updateHit(int)));
105 connect(&fCanvasWidget, SIGNAL(scaleFactorChanged(float)), this, SLOT(actionScale(float)));
106 connect(&fCanvasWidget, SIGNAL(commandChanged(int)), &fSettingsWidget, SLOT(updateCommand(int)));
chudy@google.com0ab03392012-07-28 20:16:11 +0000107 connect(&fActionSaveAs, SIGNAL(triggered()), this, SLOT(actionSaveAs()));
108 connect(&fActionSave, SIGNAL(triggered()), this, SLOT(actionSave()));
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000109
bungeman@google.come8cc6e82013-01-17 16:30:56 +0000110 fMapper.setMapping(&fActionZoomIn, SkCanvasWidget::kIn_ZoomCommand);
111 fMapper.setMapping(&fActionZoomOut, SkCanvasWidget::kOut_ZoomCommand);
chudy@google.coma1226312012-07-26 20:26:44 +0000112
113 connect(&fActionZoomIn, SIGNAL(triggered()), &fMapper, SLOT(map()));
114 connect(&fActionZoomOut, SIGNAL(triggered()), &fMapper, SLOT(map()));
bungeman@google.come8cc6e82013-01-17 16:30:56 +0000115 connect(&fMapper, SIGNAL(mapped(int)), &fCanvasWidget, SLOT(zoom(int)));
chudy@google.coma1226312012-07-26 20:26:44 +0000116
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000117 fInspectorWidget.setDisabled(true);
chudy@google.comd3058f52012-07-19 13:41:27 +0000118 fMenuEdit.setDisabled(true);
119 fMenuNavigate.setDisabled(true);
120 fMenuView.setDisabled(true);
chudy@google.combbad34d2012-08-13 14:26:36 +0000121
122 SkGraphics::Init();
chudy@google.com902ebe52012-06-29 14:21:22 +0000123}
124
chudy@google.combbad34d2012-08-13 14:26:36 +0000125SkDebuggerGUI::~SkDebuggerGUI() {
126 SkGraphics::Term();
127}
chudy@google.com902ebe52012-06-29 14:21:22 +0000128
129void SkDebuggerGUI::actionBreakpoints() {
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000130 fBreakpointsActivated = !fBreakpointsActivated;
chudy@google.comc432f002012-07-10 13:19:25 +0000131 for (int row = 0; row < fListWidget.count(); row++) {
132 QListWidgetItem *item = fListWidget.item(row);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000133 item->setHidden(item->checkState() == Qt::Unchecked && fBreakpointsActivated);
134 }
135}
chudy@google.com902ebe52012-06-29 14:21:22 +0000136
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000137void SkDebuggerGUI::showDeletes() {
138 fDeletesActivated = !fDeletesActivated;
139 for (int row = 0; row < fListWidget.count(); row++) {
140 QListWidgetItem *item = fListWidget.item(row);
chudy@google.com607357f2012-08-07 16:12:23 +0000141 item->setHidden(fDebugger.isCommandVisible(row)
142 && fDeletesActivated);
chudy@google.com902ebe52012-06-29 14:21:22 +0000143 }
144}
145
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000146// The timed picture playback uses the SkPicturePlayback's profiling stubs
147// to time individual commands. The offsets are needed to map SkPicture
148// offsets to individual commands.
149class SkTimedPicturePlayback : public SkPicturePlayback {
150public:
scroggo@google.com12705322013-10-01 15:30:46 +0000151 static SkTimedPicturePlayback* CreateFromStream(SkStream* stream, const SkPictInfo& info,
152 SkPicture::InstallPixelRefProc proc,
153 const SkTDArray<bool>& deletedCommands) {
154 // Mimics SkPicturePlayback::CreateFromStream
155 SkAutoTDelete<SkTimedPicturePlayback> playback(SkNEW_ARGS(SkTimedPicturePlayback,
156 (deletedCommands)));
157 if (!playback->parseStream(stream, info, proc)) {
158 return NULL; // we're invalid
159 }
160 return playback.detach();
161 }
162
163 SkTimedPicturePlayback(const SkTDArray<bool>& deletedCommands)
164 : INHERITED()
bungeman@google.come8cc6e82013-01-17 16:30:56 +0000165 , fSkipCommands(deletedCommands)
166 , fTot(0.0)
167 , fCurCommand(0) {
robertphillips@google.com6d9c92b2013-05-23 13:21:18 +0000168 fTimes.setCount(deletedCommands.count());
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000169 fTypeTimes.setCount(LAST_DRAWTYPE_ENUM+1);
170 this->resetTimes();
171 }
172
173 void resetTimes() {
robertphillips@google.com6d9c92b2013-05-23 13:21:18 +0000174 for (int i = 0; i < fTimes.count(); ++i) {
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000175 fTimes[i] = 0.0;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000176 }
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000177 for (int i = 0; i < fTypeTimes.count(); ++i) {
178 fTypeTimes[i] = 0.0f;
179 }
180 fTot = 0.0;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000181 }
182
183 int count() const { return fTimes.count(); }
184
185 double time(int index) const { return fTimes[index] / fTot; }
186
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000187 const SkTDArray<double>* typeTimes() const { return &fTypeTimes; }
188
189 double totTime() const { return fTot; }
190
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000191protected:
robertphillips@google.come174a8b2012-11-27 16:04:42 +0000192 BenchSysTimer fTimer;
robertphillips@google.com5f971142012-12-07 20:48:56 +0000193 SkTDArray<bool> fSkipCommands; // has the command been deleted in the GUI?
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000194 SkTDArray<double> fTimes; // sum of time consumed for each command
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000195 SkTDArray<double> fTypeTimes; // sum of time consumed for each type of command (e.g., drawPath)
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000196 double fTot; // total of all times in 'fTimes'
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000197 int fCurType;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000198 int fCurCommand; // the current command being executed/timed
199
robertphillips@google.com6d9c92b2013-05-23 13:21:18 +0000200#ifdef SK_DEVELOPER
201 virtual bool preDraw(int opIndex, int type) SK_OVERRIDE {
202 fCurCommand = opIndex;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000203
robertphillips@google.com5f971142012-12-07 20:48:56 +0000204 if (fSkipCommands[fCurCommand]) {
robertphillips@google.com6d9c92b2013-05-23 13:21:18 +0000205 return true;
robertphillips@google.com5f971142012-12-07 20:48:56 +0000206 }
207
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000208 fCurType = type;
209 // The SkDebugCanvas doesn't recognize these types. This class needs to
210 // convert or else we'll wind up with a mismatch between the type counts
211 // the debugger displays and the profile times.
212 if (DRAW_POS_TEXT_TOP_BOTTOM == type) {
213 fCurType = DRAW_POS_TEXT;
214 } else if (DRAW_POS_TEXT_H_TOP_BOTTOM == type) {
215 fCurType = DRAW_POS_TEXT_H;
216 }
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000217
robertphillips@google.come174a8b2012-11-27 16:04:42 +0000218#if defined(SK_BUILD_FOR_WIN32)
219 // CPU timer doesn't work well on Windows
220 fTimer.startWall();
221#else
222 fTimer.startCpu();
223#endif
robertphillips@google.com5f971142012-12-07 20:48:56 +0000224
robertphillips@google.com6d9c92b2013-05-23 13:21:18 +0000225 return false;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000226 }
227
robertphillips@google.com6d9c92b2013-05-23 13:21:18 +0000228 virtual void postDraw(int opIndex) SK_OVERRIDE {
robertphillips@google.come174a8b2012-11-27 16:04:42 +0000229#if defined(SK_BUILD_FOR_WIN32)
230 // CPU timer doesn't work well on Windows
231 double time = fTimer.endWall();
232#else
233 double time = fTimer.endCpu();
234#endif
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000235
robertphillips@google.com6d9c92b2013-05-23 13:21:18 +0000236 SkASSERT(opIndex == fCurCommand);
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000237 SkASSERT(fCurType <= LAST_DRAWTYPE_ENUM);
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000238
robertphillips@google.come174a8b2012-11-27 16:04:42 +0000239 fTimes[fCurCommand] += time;
240 fTypeTimes[fCurType] += time;
241 fTot += time;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000242 }
robertphillips@google.com6d9c92b2013-05-23 13:21:18 +0000243#endif
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000244
245private:
scroggo@google.com12705322013-10-01 15:30:46 +0000246 // SkPicturePlayback::parseStream is protected, so it can be
247 // called here, but not by our static factory function. This
248 // allows the factory function to call it.
249 bool parseStream(SkStream* stream, const SkPictInfo& info,
250 SkPicture::InstallPixelRefProc proc) {
251 return this->INHERITED::parseStream(stream, info, proc);
252 }
253
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000254 typedef SkPicturePlayback INHERITED;
255};
256
257// Wrap SkPicture to allow installation of an SkTimedPicturePlayback object
258class SkTimedPicture : public SkPicture {
259public:
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000260 static SkTimedPicture* CreateTimedPicture(SkStream* stream,
261 SkPicture::InstallPixelRefProc proc,
262 const SkTDArray<bool>& deletedCommands) {
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000263 SkPictInfo info;
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000264 if (!StreamIsSKP(stream, &info)) {
265 return NULL;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000266 }
267
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000268 SkTimedPicturePlayback* playback;
269 // Check to see if there is a playback to recreate.
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000270 if (stream->readBool()) {
scroggo@google.com12705322013-10-01 15:30:46 +0000271 playback = SkTimedPicturePlayback::CreateFromStream(stream, info, proc,
272 deletedCommands);
273 if (NULL == playback) {
274 return NULL;
275 }
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000276 } else {
277 playback = NULL;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000278 }
279
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000280 return SkNEW_ARGS(SkTimedPicture, (playback, info.fWidth, info.fHeight));
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000281 }
282
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000283 void resetTimes() { ((SkTimedPicturePlayback*) fPlayback)->resetTimes(); }
284
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000285 int count() const { return ((SkTimedPicturePlayback*) fPlayback)->count(); }
286
287 // return the fraction of the total time this command consumed
288 double time(int index) const { return ((SkTimedPicturePlayback*) fPlayback)->time(index); }
289
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000290 const SkTDArray<double>* typeTimes() const { return ((SkTimedPicturePlayback*) fPlayback)->typeTimes(); }
291
292 double totTime() const { return ((SkTimedPicturePlayback*) fPlayback)->totTime(); }
293
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000294private:
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000295 // disallow default ctor b.c. we don't have a good way to setup the fPlayback ptr
296 SkTimedPicture();
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000297 // Private ctor only used by CreateTimedPicture, which has created the playback.
298 SkTimedPicture(SkTimedPicturePlayback* playback, int width, int height)
299 : INHERITED(playback, width, height) {}
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000300 // disallow the copy ctor - enabling would require copying code from SkPicture
301 SkTimedPicture(const SkTimedPicture& src);
302
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000303 typedef SkPicture INHERITED;
304};
305
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000306// This is a simplification of PictureBenchmark's run with the addition of
307// clearing of the times after the first pass (in resetTimes)
skia.committer@gmail.com34587162012-11-20 02:01:23 +0000308void SkDebuggerGUI::run(SkTimedPicture* pict,
309 sk_tools::PictureRenderer* renderer,
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000310 int repeats) {
311 SkASSERT(pict);
312 if (NULL == pict) {
313 return;
314 }
315
316 SkASSERT(renderer != NULL);
317 if (NULL == renderer) {
318 return;
319 }
320
321 renderer->init(pict);
322
323 renderer->setup();
324 renderer->render(NULL);
jvanverth@google.comade32662013-01-28 21:09:05 +0000325 renderer->resetState(true);
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000326
327 // We throw this away the first batch of times to remove first time effects (such as paging in this program)
328 pict->resetTimes();
329
330 for (int i = 0; i < repeats; ++i) {
331 renderer->setup();
332 renderer->render(NULL);
jvanverth@google.comade32662013-01-28 21:09:05 +0000333 renderer->resetState(true);
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000334 }
335
336 renderer->end();
337}
338
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000339void SkDebuggerGUI::actionProfile() {
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000340 // In order to profile we pass the command offsets (that were read-in
341 // in loadPicture by the SkOffsetPicture) to an SkTimedPlaybackPicture.
skia.committer@gmail.com884e60b2012-11-16 02:01:17 +0000342 // The SkTimedPlaybackPicture in turn passes the offsets to an
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000343 // SkTimedPicturePlayback object which uses them to track the performance
344 // of individual commands.
345 if (fFileName.isEmpty()) {
346 return;
347 }
348
349 SkFILEStream inputStream;
350
351 inputStream.setPath(fFileName.c_str());
352 if (!inputStream.isValid()) {
353 return;
354 }
355
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000356 SkAutoTUnref<SkTimedPicture> picture(SkTimedPicture::CreateTimedPicture(&inputStream,
357 &SkImageDecoder::DecodeMemory, fSkipCommands));
358 if (NULL == picture.get()) {
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000359 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
commit-bot@chromium.orgfde1e7c2013-08-02 13:59:50 +0000385 if (fSettingsWidget.isGLActive()) {
robertphillips@google.com1447aa32013-01-30 21:09:09 +0000386 renderer->setDeviceType(sk_tools::PictureRenderer::kGPU_DeviceType);
commit-bot@chromium.orgfde1e7c2013-08-02 13:59:50 +0000387 renderer->setSampleCount(fSettingsWidget.getGLSampleCount());
robertphillips@google.com1447aa32013-01-30 21:09:09 +0000388 }
389#endif
390
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000391#endif
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000392
robertphillips@google.come174a8b2012-11-27 16:04:42 +0000393 static const int kNumRepeats = 10;
394
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000395 run(picture.get(), renderer, kNumRepeats);
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000396
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000397 SkASSERT(picture->count() == fListWidget.count());
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000398
399 // extract the individual command times from the SkTimedPlaybackPicture
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000400 for (int i = 0; i < picture->count(); ++i) {
401 double temp = picture->time(i);
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000402
403 QListWidgetItem* item = fListWidget.item(i);
404
405 item->setData(Qt::UserRole + 4, 100.0*temp);
406 }
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000407
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000408 setupOverviewText(picture->typeTimes(), picture->totTime(), kNumRepeats);
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000409}
410
chudy@google.com902ebe52012-06-29 14:21:22 +0000411void SkDebuggerGUI::actionCancel() {
chudy@google.comc432f002012-07-10 13:19:25 +0000412 for (int row = 0; row < fListWidget.count(); row++) {
413 fListWidget.item(row)->setHidden(false);
chudy@google.com902ebe52012-06-29 14:21:22 +0000414 }
415}
416
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000417void SkDebuggerGUI::actionClearBreakpoints() {
418 for (int row = 0; row < fListWidget.count(); row++) {
419 QListWidgetItem* item = fListWidget.item(row);
420 item->setCheckState(Qt::Unchecked);
421 item->setData(Qt::DecorationRole,
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000422 QPixmap(":/blank.png"));
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000423 }
424}
425
426void SkDebuggerGUI::actionClearDeletes() {
427 for (int row = 0; row < fListWidget.count(); row++) {
428 QListWidgetItem* item = fListWidget.item(row);
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000429 item->setData(Qt::UserRole + 2, QPixmap(":/blank.png"));
chudy@google.com607357f2012-08-07 16:12:23 +0000430 fDebugger.setCommandVisible(row, true);
robertphillips@google.com5f971142012-12-07 20:48:56 +0000431 fSkipCommands[row] = false;
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000432 }
433 if (fPause) {
434 fCanvasWidget.drawTo(fPausedRow);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000435 fImageWidget.draw();
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000436 } else {
437 fCanvasWidget.drawTo(fListWidget.currentRow());
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000438 fImageWidget.draw();
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000439 }
440}
441
chudy@google.com902ebe52012-06-29 14:21:22 +0000442void SkDebuggerGUI::actionCommandFilter() {
chudy@google.com607357f2012-08-07 16:12:23 +0000443 fDebugger.highlightCurrentCommand(
chudy@google.comc432f002012-07-10 13:19:25 +0000444 fSettingsWidget.getVisibilityButton()->isChecked());
445 fCanvasWidget.drawTo(fListWidget.currentRow());
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000446 fImageWidget.draw();
chudy@google.com902ebe52012-06-29 14:21:22 +0000447}
448
449void SkDebuggerGUI::actionClose() {
450 this->close();
451}
452
453void SkDebuggerGUI::actionDelete() {
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000454
robertphillips@google.comdd4b7452013-01-22 19:38:46 +0000455 for (int row = 0; row < fListWidget.count(); ++row) {
456 QListWidgetItem* item = fListWidget.item(row);
457
458 if (!item->isSelected()) {
459 continue;
460 }
461
462 if (fDebugger.isCommandVisible(row)) {
463 item->setData(Qt::UserRole + 2, QPixmap(":/delete.png"));
464 fDebugger.setCommandVisible(row, false);
465 fSkipCommands[row] = true;
466 } else {
467 item->setData(Qt::UserRole + 2, QPixmap(":/blank.png"));
468 fDebugger.setCommandVisible(row, true);
469 fSkipCommands[row] = false;
470 }
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000471 }
472
robertphillips@google.comdd4b7452013-01-22 19:38:46 +0000473 int currentRow = fListWidget.currentRow();
474
chudy@google.come504de02012-07-16 18:35:23 +0000475 if (fPause) {
476 fCanvasWidget.drawTo(fPausedRow);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000477 fImageWidget.draw();
chudy@google.come504de02012-07-16 18:35:23 +0000478 } else {
479 fCanvasWidget.drawTo(currentRow);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000480 fImageWidget.draw();
chudy@google.come504de02012-07-16 18:35:23 +0000481 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000482}
483
robertphillips@google.come8fe4bc2013-02-13 13:26:13 +0000484#if SK_SUPPORT_GPU
commit-bot@chromium.orgfde1e7c2013-08-02 13:59:50 +0000485void SkDebuggerGUI::actionGLWidget() {
486 bool isToggled = fSettingsWidget.isGLActive();
487 if (isToggled) {
488 fCanvasWidget.setGLSampleCount(fSettingsWidget.getGLSampleCount());
489 }
chudy@google.comea5488b2012-07-26 19:38:22 +0000490 fCanvasWidget.setWidgetVisibility(SkCanvasWidget::kGPU_WidgetType, !isToggled);
491}
robertphillips@google.come8fe4bc2013-02-13 13:26:13 +0000492#endif
chudy@google.comea5488b2012-07-26 19:38:22 +0000493
chudy@google.com902ebe52012-06-29 14:21:22 +0000494void SkDebuggerGUI::actionInspector() {
chudy@google.comc432f002012-07-10 13:19:25 +0000495 if (fInspectorWidget.isHidden()) {
496 fInspectorWidget.setHidden(false);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000497 fImageWidget.setHidden(false);
chudy@google.com902ebe52012-06-29 14:21:22 +0000498 } else {
chudy@google.comc432f002012-07-10 13:19:25 +0000499 fInspectorWidget.setHidden(true);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000500 fImageWidget.setHidden(true);
chudy@google.com902ebe52012-06-29 14:21:22 +0000501 }
502}
503
504void SkDebuggerGUI::actionPlay() {
chudy@google.comc432f002012-07-10 13:19:25 +0000505 for (int row = fListWidget.currentRow() + 1; row < fListWidget.count();
chudy@google.com7dcae672012-07-09 20:26:53 +0000506 row++) {
chudy@google.comc432f002012-07-10 13:19:25 +0000507 QListWidgetItem *item = fListWidget.item(row);
chudy@google.com902ebe52012-06-29 14:21:22 +0000508 if (item->checkState() == Qt::Checked) {
chudy@google.comc432f002012-07-10 13:19:25 +0000509 fListWidget.setCurrentItem(item);
chudy@google.com902ebe52012-06-29 14:21:22 +0000510 return;
511 }
512 }
chudy@google.comc432f002012-07-10 13:19:25 +0000513 fListWidget.setCurrentRow(fListWidget.count() - 1);
chudy@google.com902ebe52012-06-29 14:21:22 +0000514}
515
chudy@google.comea5488b2012-07-26 19:38:22 +0000516void SkDebuggerGUI::actionRasterWidget(bool isToggled) {
517 fCanvasWidget.setWidgetVisibility(SkCanvasWidget::kRaster_8888_WidgetType, !isToggled);
518}
519
robertphillips@google.comf4741c12013-02-06 20:13:54 +0000520void SkDebuggerGUI::actionOverdrawVizWidget(bool isToggled) {
521 fDebugger.setOverdrawViz(isToggled);
522 fCanvasWidget.update();
523}
524
robertphillips@google.com32bbcf82013-10-17 17:56:10 +0000525void SkDebuggerGUI::actionTextureFilter() {
526 SkPaint::FilterLevel level;
527 bool enabled = fSettingsWidget.getFilterOverride(&level);
528 fDebugger.setTexFilterOverride(enabled, level);
529 fCanvasWidget.update();
530}
531
chudy@google.com902ebe52012-06-29 14:21:22 +0000532void SkDebuggerGUI::actionRewind() {
chudy@google.come504de02012-07-16 18:35:23 +0000533 fListWidget.setCurrentRow(0);
chudy@google.com902ebe52012-06-29 14:21:22 +0000534}
535
chudy@google.com0ab03392012-07-28 20:16:11 +0000536void SkDebuggerGUI::actionSave() {
robertphillips@google.come219baf2013-01-28 19:25:43 +0000537 fFileName = fPath.toAscii().data();
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000538 fFileName.append("/");
robertphillips@google.come219baf2013-01-28 19:25:43 +0000539 fFileName.append(fDirectoryWidget.currentItem()->text().toAscii().data());
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000540 saveToFile(fFileName);
chudy@google.com0ab03392012-07-28 20:16:11 +0000541}
542
543void SkDebuggerGUI::actionSaveAs() {
544 QString filename = QFileDialog::getSaveFileName(this, "Save File", "",
545 "Skia Picture (*skp)");
chudy@google.com38b08ce2012-07-28 23:26:10 +0000546 if (!filename.endsWith(".skp", Qt::CaseInsensitive)) {
chudy@google.com0ab03392012-07-28 20:16:11 +0000547 filename.append(".skp");
548 }
djsollen@google.comc3c82162012-11-13 18:35:10 +0000549 saveToFile(SkString(filename.toAscii().data()));
chudy@google.com0ab03392012-07-28 20:16:11 +0000550}
551
chudy@google.com7dcae672012-07-09 20:26:53 +0000552void SkDebuggerGUI::actionScale(float scaleFactor) {
chudy@google.comc432f002012-07-10 13:19:25 +0000553 fSettingsWidget.setZoomText(scaleFactor);
chudy@google.com7dcae672012-07-09 20:26:53 +0000554}
555
chudy@google.com902ebe52012-06-29 14:21:22 +0000556void SkDebuggerGUI::actionSettings() {
chudy@google.comc432f002012-07-10 13:19:25 +0000557 if (fSettingsWidget.isHidden()) {
558 fSettingsWidget.setHidden(false);
chudy@google.com902ebe52012-06-29 14:21:22 +0000559 } else {
chudy@google.comc432f002012-07-10 13:19:25 +0000560 fSettingsWidget.setHidden(true);
chudy@google.com902ebe52012-06-29 14:21:22 +0000561 }
562}
563
564void SkDebuggerGUI::actionStepBack() {
chudy@google.comc432f002012-07-10 13:19:25 +0000565 int currentRow = fListWidget.currentRow();
chudy@google.com902ebe52012-06-29 14:21:22 +0000566 if (currentRow != 0) {
chudy@google.comc432f002012-07-10 13:19:25 +0000567 fListWidget.setCurrentRow(currentRow - 1);
chudy@google.com902ebe52012-06-29 14:21:22 +0000568 }
569}
570
571void SkDebuggerGUI::actionStepForward() {
chudy@google.comc432f002012-07-10 13:19:25 +0000572 int currentRow = fListWidget.currentRow();
chudy@google.com902ebe52012-06-29 14:21:22 +0000573 QString curRow = QString::number(currentRow);
chudy@google.comc432f002012-07-10 13:19:25 +0000574 QString curCount = QString::number(fListWidget.count());
575 if (currentRow < fListWidget.count() - 1) {
576 fListWidget.setCurrentRow(currentRow + 1);
chudy@google.com902ebe52012-06-29 14:21:22 +0000577 }
578}
579
chudy@google.coma9e937c2012-08-03 17:32:05 +0000580void SkDebuggerGUI::drawComplete() {
chudy@google.com607357f2012-08-07 16:12:23 +0000581 fInspectorWidget.setMatrix(fDebugger.getCurrentMatrix());
582 fInspectorWidget.setClip(fDebugger.getCurrentClip());
chudy@google.coma9e937c2012-08-03 17:32:05 +0000583}
584
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000585void SkDebuggerGUI::saveToFile(const SkString& filename) {
586 SkFILEWStream file(filename.c_str());
robertphillips@google.com25bc2f82013-01-22 18:03:56 +0000587 SkAutoTUnref<SkPicture> copy(fDebugger.copyPicture());
588
589 copy->serialize(&file);
chudy@google.com0ab03392012-07-28 20:16:11 +0000590}
591
chudy@google.com902ebe52012-06-29 14:21:22 +0000592void SkDebuggerGUI::loadFile(QListWidgetItem *item) {
593 if (fDirectoryWidgetActive) {
robertphillips@google.come219baf2013-01-28 19:25:43 +0000594 fFileName = fPath.toAscii().data();
jvanverth@google.com0ac6f162013-02-05 19:44:07 +0000595 // don't add a '/' to files in the local directory
596 if (fFileName.size() > 0) {
597 fFileName.append("/");
598 }
robertphillips@google.come219baf2013-01-28 19:25:43 +0000599 fFileName.append(item->text().toAscii().data());
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000600 loadPicture(fFileName);
chudy@google.com902ebe52012-06-29 14:21:22 +0000601 }
602}
603
604void SkDebuggerGUI::openFile() {
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000605 QString temp = QFileDialog::getOpenFileName(this, tr("Open File"), "",
chudy@google.com7dcae672012-07-09 20:26:53 +0000606 tr("Files (*.*)"));
robertphillips@google.comff6e6ba2013-01-28 17:43:26 +0000607 openFile(temp);
608}
609
610void SkDebuggerGUI::openFile(const QString &filename) {
chudy@google.com902ebe52012-06-29 14:21:22 +0000611 fDirectoryWidgetActive = false;
robertphillips@google.comff6e6ba2013-01-28 17:43:26 +0000612 if (!filename.isEmpty()) {
613 QFileInfo pathInfo(filename);
614 loadPicture(SkString(filename.toAscii().data()));
615 setupDirectoryWidget(pathInfo.path());
chudy@google.com902ebe52012-06-29 14:21:22 +0000616 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000617 fDirectoryWidgetActive = true;
618}
619
chudy@google.comc432f002012-07-10 13:19:25 +0000620void SkDebuggerGUI::pauseDrawing(bool isPaused) {
chudy@google.com607357f2012-08-07 16:12:23 +0000621 fPause = isPaused;
622 fPausedRow = fListWidget.currentRow();
623 fCanvasWidget.drawTo(fPausedRow);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000624 fImageWidget.draw();
chudy@google.com7dcae672012-07-09 20:26:53 +0000625}
626
chudy@google.com902ebe52012-06-29 14:21:22 +0000627void SkDebuggerGUI::registerListClick(QListWidgetItem *item) {
chudy@google.comd3058f52012-07-19 13:41:27 +0000628 if(!fLoading) {
629 int currentRow = fListWidget.currentRow();
chudy@google.comd3058f52012-07-19 13:41:27 +0000630
chudy@google.comea5488b2012-07-26 19:38:22 +0000631 if (currentRow != -1) {
632 if (!fPause) {
633 fCanvasWidget.drawTo(currentRow);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000634 fImageWidget.draw();
chudy@google.comd3058f52012-07-19 13:41:27 +0000635 }
chudy@google.com97cee972012-08-07 20:41:37 +0000636 SkTDArray<SkString*> *currInfo = fDebugger.getCommandInfo(
chudy@google.comea5488b2012-07-26 19:38:22 +0000637 currentRow);
638
639 /* TODO(chudy): Add command type before parameters. Rename v
640 * to something more informative. */
chudy@google.com97cee972012-08-07 20:41:37 +0000641 if (currInfo) {
chudy@google.comea5488b2012-07-26 19:38:22 +0000642 QString info;
643 info.append("<b>Parameters: </b><br/>");
chudy@google.com97cee972012-08-07 20:41:37 +0000644 for (int i = 0; i < currInfo->count(); i++) {
645
646 info.append(QString((*currInfo)[i]->c_str()));
chudy@google.comea5488b2012-07-26 19:38:22 +0000647 info.append("<br/>");
648 }
chudy@google.com6bd109a2012-08-14 19:34:13 +0000649 fInspectorWidget.setText(info, SkInspectorWidget::kDetail_TabType);
chudy@google.comea5488b2012-07-26 19:38:22 +0000650 fInspectorWidget.setDisabled(false);
chudy@google.comea5488b2012-07-26 19:38:22 +0000651 }
chudy@google.comd3058f52012-07-19 13:41:27 +0000652 }
chudy@google.comea5488b2012-07-26 19:38:22 +0000653
chudy@google.com902ebe52012-06-29 14:21:22 +0000654 }
655}
656
chudy@google.com9ca9bfe2012-07-12 21:58:14 +0000657void SkDebuggerGUI::selectCommand(int command) {
658 if (fPause) {
659 fListWidget.setCurrentRow(command);
660 }
661}
662
chudy@google.com902ebe52012-06-29 14:21:22 +0000663void SkDebuggerGUI::toggleBreakpoint() {
chudy@google.comc432f002012-07-10 13:19:25 +0000664 QListWidgetItem* item = fListWidget.currentItem();
chudy@google.com902ebe52012-06-29 14:21:22 +0000665 if (item->checkState() == Qt::Unchecked) {
666 item->setCheckState(Qt::Checked);
chudy@google.come565de42012-07-12 14:15:54 +0000667 item->setData(Qt::DecorationRole,
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000668 QPixmap(":/breakpoint_16x16.png"));
chudy@google.com902ebe52012-06-29 14:21:22 +0000669 } else {
chudy@google.com902ebe52012-06-29 14:21:22 +0000670 item->setCheckState(Qt::Unchecked);
chudy@google.come565de42012-07-12 14:15:54 +0000671 item->setData(Qt::DecorationRole,
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000672 QPixmap(":/blank.png"));
chudy@google.com902ebe52012-06-29 14:21:22 +0000673 }
674}
675
676void SkDebuggerGUI::toggleDirectory() {
chudy@google.com607357f2012-08-07 16:12:23 +0000677 fDirectoryWidget.setHidden(!fDirectoryWidget.isHidden());
chudy@google.com902ebe52012-06-29 14:21:22 +0000678}
679
680void SkDebuggerGUI::toggleFilter(QString string) {
chudy@google.comc432f002012-07-10 13:19:25 +0000681 for (int row = 0; row < fListWidget.count(); row++) {
682 QListWidgetItem *item = fListWidget.item(row);
chudy@google.com607357f2012-08-07 16:12:23 +0000683 item->setHidden(item->text() != string);
chudy@google.com902ebe52012-06-29 14:21:22 +0000684 }
685}
686
687void SkDebuggerGUI::setupUi(QMainWindow *SkDebuggerGUI) {
688 QIcon windowIcon;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000689 windowIcon.addFile(QString::fromUtf8(":/skia.png"), QSize(),
chudy@google.com7dcae672012-07-09 20:26:53 +0000690 QIcon::Normal, QIcon::Off);
chudy@google.com902ebe52012-06-29 14:21:22 +0000691 SkDebuggerGUI->setObjectName(QString::fromUtf8("SkDebuggerGUI"));
692 SkDebuggerGUI->resize(1200, 1000);
693 SkDebuggerGUI->setWindowIcon(windowIcon);
chudy@google.comc432f002012-07-10 13:19:25 +0000694 SkDebuggerGUI->setWindowTitle("Skia Debugger");
chudy@google.com902ebe52012-06-29 14:21:22 +0000695
chudy@google.come504de02012-07-16 18:35:23 +0000696 fActionOpen.setShortcuts(QKeySequence::Open);
chudy@google.comc432f002012-07-10 13:19:25 +0000697 fActionOpen.setText("Open");
chudy@google.com902ebe52012-06-29 14:21:22 +0000698
699 QIcon breakpoint;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000700 breakpoint.addFile(QString::fromUtf8(":/breakpoint.png"),
chudy@google.com7dcae672012-07-09 20:26:53 +0000701 QSize(), QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000702 fActionBreakpoint.setShortcut(QKeySequence(tr("Ctrl+B")));
chudy@google.comc432f002012-07-10 13:19:25 +0000703 fActionBreakpoint.setIcon(breakpoint);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000704 fActionBreakpoint.setText("Breakpoints");
chudy@google.com902ebe52012-06-29 14:21:22 +0000705
706 QIcon cancel;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000707 cancel.addFile(QString::fromUtf8(":/reload.png"), QSize(),
chudy@google.com7dcae672012-07-09 20:26:53 +0000708 QIcon::Normal, QIcon::Off);
chudy@google.comc432f002012-07-10 13:19:25 +0000709 fActionCancel.setIcon(cancel);
710 fActionCancel.setText("Clear Filter");
chudy@google.com902ebe52012-06-29 14:21:22 +0000711
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000712 fActionClearBreakpoints.setShortcut(QKeySequence(tr("Alt+B")));
713 fActionClearBreakpoints.setText("Clear Breakpoints");
714
715 fActionClearDeletes.setShortcut(QKeySequence(tr("Alt+X")));
716 fActionClearDeletes.setText("Clear Deletes");
717
chudy@google.come504de02012-07-16 18:35:23 +0000718 fActionClose.setShortcuts(QKeySequence::Quit);
chudy@google.comc432f002012-07-10 13:19:25 +0000719 fActionClose.setText("Exit");
chudy@google.com902ebe52012-06-29 14:21:22 +0000720
chudy@google.come504de02012-07-16 18:35:23 +0000721 fActionCreateBreakpoint.setShortcut(QKeySequence(tr("B")));
722 fActionCreateBreakpoint.setText("Set Breakpoint");
723
724 fActionDelete.setShortcut(QKeySequence(tr("X")));
chudy@google.comc432f002012-07-10 13:19:25 +0000725 fActionDelete.setText("Delete Command");
chudy@google.com902ebe52012-06-29 14:21:22 +0000726
chudy@google.come504de02012-07-16 18:35:23 +0000727 fActionDirectory.setShortcut(QKeySequence(tr("Ctrl+D")));
728 fActionDirectory.setText("Directory");
chudy@google.com902ebe52012-06-29 14:21:22 +0000729
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000730 QIcon profile;
robertphillips@google.comd1636362012-11-19 18:25:09 +0000731 profile.addFile(QString::fromUtf8(":/profile.png"), QSize(),
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000732 QIcon::Normal, QIcon::Off);
733 fActionProfile.setIcon(profile);
734 fActionProfile.setText("Profile");
robertphillips@google.come099bc42012-11-19 16:26:40 +0000735 fActionProfile.setDisabled(true);
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000736
chudy@google.comc432f002012-07-10 13:19:25 +0000737 QIcon inspector;
robertphillips@google.comd1636362012-11-19 18:25:09 +0000738 inspector.addFile(QString::fromUtf8(":/inspector.png"),
chudy@google.comc432f002012-07-10 13:19:25 +0000739 QSize(), QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000740 fActionInspector.setShortcut(QKeySequence(tr("Ctrl+I")));
chudy@google.comc432f002012-07-10 13:19:25 +0000741 fActionInspector.setIcon(inspector);
chudy@google.come504de02012-07-16 18:35:23 +0000742 fActionInspector.setText("Inspector");
chudy@google.com902ebe52012-06-29 14:21:22 +0000743
bungeman@google.com2ff6d1d2013-07-01 14:24:12 +0000744 QIcon settings;
745 settings.addFile(QString::fromUtf8(":/inspector.png"),
746 QSize(), QIcon::Normal, QIcon::Off);
747 fActionSettings.setShortcut(QKeySequence(tr("Ctrl+G")));
748 fActionSettings.setIcon(settings);
749 fActionSettings.setText("Settings");
skia.committer@gmail.com0d55dd72013-07-02 07:00:59 +0000750
chudy@google.comc432f002012-07-10 13:19:25 +0000751 QIcon play;
robertphillips@google.comd1636362012-11-19 18:25:09 +0000752 play.addFile(QString::fromUtf8(":/play.png"), QSize(),
chudy@google.comc432f002012-07-10 13:19:25 +0000753 QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000754 fActionPlay.setShortcut(QKeySequence(tr("Ctrl+P")));
chudy@google.comc432f002012-07-10 13:19:25 +0000755 fActionPlay.setIcon(play);
756 fActionPlay.setText("Play");
chudy@google.com902ebe52012-06-29 14:21:22 +0000757
chudy@google.come504de02012-07-16 18:35:23 +0000758 QIcon pause;
robertphillips@google.comd1636362012-11-19 18:25:09 +0000759 pause.addFile(QString::fromUtf8(":/pause.png"), QSize(),
chudy@google.comc432f002012-07-10 13:19:25 +0000760 QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000761 fActionPause.setShortcut(QKeySequence(tr("Space")));
762 fActionPause.setCheckable(true);
763 fActionPause.setIcon(pause);
764 fActionPause.setText("Pause");
765
chudy@google.comc432f002012-07-10 13:19:25 +0000766 QIcon rewind;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000767 rewind.addFile(QString::fromUtf8(":/rewind.png"), QSize(),
chudy@google.comc432f002012-07-10 13:19:25 +0000768 QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000769 fActionRewind.setShortcut(QKeySequence(tr("Ctrl+R")));
chudy@google.comc432f002012-07-10 13:19:25 +0000770 fActionRewind.setIcon(rewind);
771 fActionRewind.setText("Rewind");
chudy@google.com902ebe52012-06-29 14:21:22 +0000772
chudy@google.com0ab03392012-07-28 20:16:11 +0000773 fActionSave.setShortcut(QKeySequence::Save);
774 fActionSave.setText("Save");
775 fActionSave.setDisabled(true);
776 fActionSaveAs.setShortcut(QKeySequence::SaveAs);
777 fActionSaveAs.setText("Save As");
778 fActionSaveAs.setDisabled(true);
779
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000780 fActionShowDeletes.setShortcut(QKeySequence(tr("Ctrl+X")));
781 fActionShowDeletes.setText("Deleted Commands");
782
chudy@google.comc432f002012-07-10 13:19:25 +0000783 QIcon stepBack;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000784 stepBack.addFile(QString::fromUtf8(":/previous.png"), QSize(),
chudy@google.comc432f002012-07-10 13:19:25 +0000785 QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000786 fActionStepBack.setShortcut(QKeySequence(tr("[")));
chudy@google.comc432f002012-07-10 13:19:25 +0000787 fActionStepBack.setIcon(stepBack);
788 fActionStepBack.setText("Step Back");
chudy@google.com902ebe52012-06-29 14:21:22 +0000789
chudy@google.comc432f002012-07-10 13:19:25 +0000790 QIcon stepForward;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000791 stepForward.addFile(QString::fromUtf8(":/next.png"),
chudy@google.comc432f002012-07-10 13:19:25 +0000792 QSize(), QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000793 fActionStepForward.setShortcut(QKeySequence(tr("]")));
chudy@google.comc432f002012-07-10 13:19:25 +0000794 fActionStepForward.setIcon(stepForward);
795 fActionStepForward.setText("Step Forward");
796
chudy@google.coma1226312012-07-26 20:26:44 +0000797 fActionZoomIn.setShortcut(QKeySequence(tr("Ctrl+=")));
798 fActionZoomIn.setText("Zoom In");
799 fActionZoomOut.setShortcut(QKeySequence(tr("Ctrl+-")));
800 fActionZoomOut.setText("Zoom Out");
801
chudy@google.comc432f002012-07-10 13:19:25 +0000802 fListWidget.setItemDelegate(new SkListWidget(&fListWidget));
803 fListWidget.setObjectName(QString::fromUtf8("listWidget"));
804 fListWidget.setMaximumWidth(250);
805
806 fFilter.addItem("--Filter By Available Commands--");
807
808 fDirectoryWidget.setMaximumWidth(250);
809 fDirectoryWidget.setStyleSheet("QListWidget::Item {padding: 5px;}");
810
811 fCanvasWidget.setSizePolicy(QSizePolicy::Expanding,
chudy@google.com7dcae672012-07-09 20:26:53 +0000812 QSizePolicy::Expanding);
chudy@google.com902ebe52012-06-29 14:21:22 +0000813
skia.committer@gmail.com1c9c0d32012-11-22 02:02:41 +0000814 fImageWidget.setFixedSize(SkImageWidget::kImageWidgetWidth,
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000815 SkImageWidget::kImageWidgetHeight);
816
chudy@google.comc432f002012-07-10 13:19:25 +0000817 fInspectorWidget.setSizePolicy(QSizePolicy::Expanding,
chudy@google.com7dcae672012-07-09 20:26:53 +0000818 QSizePolicy::Expanding);
chudy@google.comc432f002012-07-10 13:19:25 +0000819 fInspectorWidget.setMaximumHeight(300);
chudy@google.com902ebe52012-06-29 14:21:22 +0000820
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000821 fSettingsAndImageLayout.setSpacing(6);
822 fSettingsAndImageLayout.addWidget(&fSettingsWidget);
823 fSettingsAndImageLayout.addWidget(&fImageWidget);
824
chudy@google.comc432f002012-07-10 13:19:25 +0000825 fSettingsWidget.setSizePolicy(QSizePolicy::Expanding,
826 QSizePolicy::Expanding);
827 fSettingsWidget.setMaximumWidth(250);
chudy@google.com902ebe52012-06-29 14:21:22 +0000828
chudy@google.comc432f002012-07-10 13:19:25 +0000829 fLeftColumnLayout.setSpacing(6);
830 fLeftColumnLayout.addWidget(&fListWidget);
831 fLeftColumnLayout.addWidget(&fDirectoryWidget);
chudy@google.com902ebe52012-06-29 14:21:22 +0000832
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000833 fCanvasSettingsAndImageLayout.setSpacing(6);
834 fCanvasSettingsAndImageLayout.addWidget(&fCanvasWidget);
835 fCanvasSettingsAndImageLayout.addLayout(&fSettingsAndImageLayout);
836
chudy@google.com902ebe52012-06-29 14:21:22 +0000837
chudy@google.comc432f002012-07-10 13:19:25 +0000838 fMainAndRightColumnLayout.setSpacing(6);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000839 fMainAndRightColumnLayout.addLayout(&fCanvasSettingsAndImageLayout);
chudy@google.comc432f002012-07-10 13:19:25 +0000840 fMainAndRightColumnLayout.addWidget(&fInspectorWidget);
chudy@google.com902ebe52012-06-29 14:21:22 +0000841
chudy@google.com2d537a12012-07-31 12:49:52 +0000842 fCentralWidget.setLayout(&fContainerLayout);
chudy@google.comc432f002012-07-10 13:19:25 +0000843 fContainerLayout.setSpacing(6);
844 fContainerLayout.setContentsMargins(11, 11, 11, 11);
845 fContainerLayout.addLayout(&fLeftColumnLayout);
846 fContainerLayout.addLayout(&fMainAndRightColumnLayout);
847
848 SkDebuggerGUI->setCentralWidget(&fCentralWidget);
849 SkDebuggerGUI->setStatusBar(&fStatusBar);
850
chudy@google.come504de02012-07-16 18:35:23 +0000851 fToolBar.setIconSize(QSize(32, 32));
chudy@google.comc432f002012-07-10 13:19:25 +0000852 fToolBar.setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
853 SkDebuggerGUI->addToolBar(Qt::TopToolBarArea, &fToolBar);
chudy@google.com902ebe52012-06-29 14:21:22 +0000854
chudy@google.com0ab03392012-07-28 20:16:11 +0000855 fSpacer.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
chudy@google.com902ebe52012-06-29 14:21:22 +0000856
chudy@google.comc432f002012-07-10 13:19:25 +0000857 fToolBar.addAction(&fActionRewind);
858 fToolBar.addAction(&fActionStepBack);
chudy@google.come504de02012-07-16 18:35:23 +0000859 fToolBar.addAction(&fActionPause);
chudy@google.comc432f002012-07-10 13:19:25 +0000860 fToolBar.addAction(&fActionStepForward);
861 fToolBar.addAction(&fActionPlay);
862 fToolBar.addSeparator();
chudy@google.come504de02012-07-16 18:35:23 +0000863 fToolBar.addAction(&fActionInspector);
bungeman@google.com2ff6d1d2013-07-01 14:24:12 +0000864 fToolBar.addAction(&fActionSettings);
chudy@google.comc432f002012-07-10 13:19:25 +0000865 fToolBar.addSeparator();
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000866 fToolBar.addAction(&fActionProfile);
867
868 fToolBar.addSeparator();
chudy@google.com0ab03392012-07-28 20:16:11 +0000869 fToolBar.addWidget(&fSpacer);
chudy@google.comc432f002012-07-10 13:19:25 +0000870 fToolBar.addWidget(&fFilter);
871 fToolBar.addAction(&fActionCancel);
chudy@google.com902ebe52012-06-29 14:21:22 +0000872
873 // TODO(chudy): Remove static call.
874 fDirectoryWidgetActive = false;
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000875 fFileName = "";
robertphillips@google.comff6e6ba2013-01-28 17:43:26 +0000876 setupDirectoryWidget("");
chudy@google.com902ebe52012-06-29 14:21:22 +0000877 fDirectoryWidgetActive = true;
878
chudy@google.com902ebe52012-06-29 14:21:22 +0000879 // Menu Bar
chudy@google.comc432f002012-07-10 13:19:25 +0000880 fMenuFile.setTitle("File");
881 fMenuFile.addAction(&fActionOpen);
chudy@google.com0ab03392012-07-28 20:16:11 +0000882 fMenuFile.addAction(&fActionSave);
883 fMenuFile.addAction(&fActionSaveAs);
chudy@google.comc432f002012-07-10 13:19:25 +0000884 fMenuFile.addAction(&fActionClose);
chudy@google.come504de02012-07-16 18:35:23 +0000885
886 fMenuEdit.setTitle("Edit");
887 fMenuEdit.addAction(&fActionDelete);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000888 fMenuEdit.addAction(&fActionClearDeletes);
889 fMenuEdit.addSeparator();
chudy@google.come504de02012-07-16 18:35:23 +0000890 fMenuEdit.addAction(&fActionCreateBreakpoint);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000891 fMenuEdit.addAction(&fActionClearBreakpoints);
chudy@google.come504de02012-07-16 18:35:23 +0000892
chudy@google.comc432f002012-07-10 13:19:25 +0000893 fMenuNavigate.setTitle("Navigate");
chudy@google.come504de02012-07-16 18:35:23 +0000894 fMenuNavigate.addAction(&fActionRewind);
895 fMenuNavigate.addAction(&fActionStepBack);
896 fMenuNavigate.addAction(&fActionStepForward);
897 fMenuNavigate.addAction(&fActionPlay);
898 fMenuNavigate.addAction(&fActionPause);
chudy@google.comc432f002012-07-10 13:19:25 +0000899 fMenuNavigate.addAction(&fActionGoToLine);
chudy@google.come504de02012-07-16 18:35:23 +0000900
chudy@google.comc432f002012-07-10 13:19:25 +0000901 fMenuView.setTitle("View");
chudy@google.come504de02012-07-16 18:35:23 +0000902 fMenuView.addAction(&fActionBreakpoint);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000903 fMenuView.addAction(&fActionShowDeletes);
chudy@google.coma1226312012-07-26 20:26:44 +0000904 fMenuView.addAction(&fActionZoomIn);
905 fMenuView.addAction(&fActionZoomOut);
chudy@google.come504de02012-07-16 18:35:23 +0000906
907 fMenuWindows.setTitle("Window");
908 fMenuWindows.addAction(&fActionInspector);
bungeman@google.com2ff6d1d2013-07-01 14:24:12 +0000909 fMenuWindows.addAction(&fActionSettings);
chudy@google.come504de02012-07-16 18:35:23 +0000910 fMenuWindows.addAction(&fActionDirectory);
chudy@google.comc432f002012-07-10 13:19:25 +0000911
912 fActionGoToLine.setText("Go to Line...");
913 fActionGoToLine.setDisabled(true);
914 fMenuBar.addAction(fMenuFile.menuAction());
chudy@google.come504de02012-07-16 18:35:23 +0000915 fMenuBar.addAction(fMenuEdit.menuAction());
chudy@google.comc432f002012-07-10 13:19:25 +0000916 fMenuBar.addAction(fMenuView.menuAction());
917 fMenuBar.addAction(fMenuNavigate.menuAction());
chudy@google.come504de02012-07-16 18:35:23 +0000918 fMenuBar.addAction(fMenuWindows.menuAction());
chudy@google.com902ebe52012-06-29 14:21:22 +0000919
chudy@google.com7dcae672012-07-09 20:26:53 +0000920 fPause = false;
921
chudy@google.comc432f002012-07-10 13:19:25 +0000922 SkDebuggerGUI->setMenuBar(&fMenuBar);
chudy@google.com902ebe52012-06-29 14:21:22 +0000923 QMetaObject::connectSlotsByName(SkDebuggerGUI);
924}
925
robertphillips@google.comff6e6ba2013-01-28 17:43:26 +0000926void SkDebuggerGUI::setupDirectoryWidget(const QString& path) {
927 fPath = path;
928 QDir dir(path);
chudy@google.com902ebe52012-06-29 14:21:22 +0000929 QRegExp r(".skp");
chudy@google.comc432f002012-07-10 13:19:25 +0000930 fDirectoryWidget.clear();
931 const QStringList files = dir.entryList();
chudy@google.com902ebe52012-06-29 14:21:22 +0000932 foreach (QString f, files) {
chudy@google.com7dcae672012-07-09 20:26:53 +0000933 if (f.contains(r))
chudy@google.comc432f002012-07-10 13:19:25 +0000934 fDirectoryWidget.addItem(f);
chudy@google.com902ebe52012-06-29 14:21:22 +0000935 }
936}
937
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000938void SkDebuggerGUI::loadPicture(const SkString& fileName) {
939 fFileName = fileName;
chudy@google.comd3058f52012-07-19 13:41:27 +0000940 fLoading = true;
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000941 SkStream* stream = SkNEW_ARGS(SkFILEStream, (fileName.c_str()));
robertphillips@google.com2d40ec42013-02-07 20:39:40 +0000942
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000943 SkPicture* picture = SkPicture::CreateFromStream(stream);
robertphillips@google.com2d40ec42013-02-07 20:39:40 +0000944
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000945 if (NULL == picture) {
robertphillips@google.com2d40ec42013-02-07 20:39:40 +0000946 QMessageBox::critical(this, "Error loading file", "Couldn't read file, sorry.");
947 SkSafeUnref(stream);
948 return;
949 }
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000950
chudy@google.com686e6802012-08-14 16:00:32 +0000951 fCanvasWidget.resetWidgetTransform();
chudy@google.com607357f2012-08-07 16:12:23 +0000952 fDebugger.loadPicture(picture);
chudy@google.com4c7962e2012-08-14 19:38:31 +0000953
robertphillips@google.com6d9c92b2013-05-23 13:21:18 +0000954 fSkipCommands.setCount(fDebugger.getSize());
955 for (int i = 0; i < fSkipCommands.count(); ++i) {
robertphillips@google.com5f971142012-12-07 20:48:56 +0000956 fSkipCommands[i] = false;
957 }
958
chudy@google.com607357f2012-08-07 16:12:23 +0000959 SkSafeUnref(stream);
960 SkSafeUnref(picture);
961
chudy@google.com97cee972012-08-07 20:41:37 +0000962 // Will this automatically clear out due to nature of refcnt?
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000963 SkTArray<SkString>* commands = fDebugger.getDrawCommandsAsStrings();
chudy@google.com607357f2012-08-07 16:12:23 +0000964
robertphillips@google.com6d9c92b2013-05-23 13:21:18 +0000965 fActionProfile.setDisabled(false);
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000966
chudy@google.com7dcae672012-07-09 20:26:53 +0000967 /* fDebugCanvas is reinitialized every load picture. Need it to retain value
chudy@google.com607357f2012-08-07 16:12:23 +0000968 * of the visibility filter.
969 * TODO(chudy): This should be deprecated since fDebugger is not
970 * recreated.
971 * */
972 fDebugger.highlightCurrentCommand(fSettingsWidget.getVisibilityButton()->isChecked());
973
chudy@google.com97cee972012-08-07 20:41:37 +0000974 setupListWidget(commands);
975 setupComboBox(commands);
robertphillips@google.come428f9b2013-03-12 15:33:40 +0000976 setupOverviewText(NULL, 0.0, 1);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000977 fInspectorWidget.setDisabled(false);
chudy@google.come606d6e2012-07-12 14:31:25 +0000978 fSettingsWidget.setDisabled(false);
chudy@google.comd3058f52012-07-19 13:41:27 +0000979 fMenuEdit.setDisabled(false);
980 fMenuNavigate.setDisabled(false);
981 fMenuView.setDisabled(false);
chudy@google.com0ab03392012-07-28 20:16:11 +0000982 fActionSave.setDisabled(false);
983 fActionSaveAs.setDisabled(false);
chudy@google.comd3058f52012-07-19 13:41:27 +0000984 fLoading = false;
985 actionPlay();
chudy@google.com902ebe52012-06-29 14:21:22 +0000986}
987
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000988void SkDebuggerGUI::setupListWidget(SkTArray<SkString>* command) {
chudy@google.comc432f002012-07-10 13:19:25 +0000989 fListWidget.clear();
chudy@google.com902ebe52012-06-29 14:21:22 +0000990 int counter = 0;
robertphillips@google.com30d35f22012-11-06 16:45:36 +0000991 int indent = 0;
chudy@google.com97cee972012-08-07 20:41:37 +0000992 for (int i = 0; i < command->count(); i++) {
chudy@google.com902ebe52012-06-29 14:21:22 +0000993 QListWidgetItem *item = new QListWidgetItem();
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000994 item->setData(Qt::DisplayRole, (*command)[i].c_str());
chudy@google.com902ebe52012-06-29 14:21:22 +0000995 item->setData(Qt::UserRole + 1, counter++);
robertphillips@google.com30d35f22012-11-06 16:45:36 +0000996
robertphillips@google.com0a4805e2013-05-29 13:24:23 +0000997 if (0 == strcmp("Restore", (*command)[i].c_str()) ||
998 0 == strcmp("EndCommentGroup", (*command)[i].c_str())) {
robertphillips@google.com30d35f22012-11-06 16:45:36 +0000999 indent -= 10;
1000 }
1001
1002 item->setData(Qt::UserRole + 3, indent);
1003
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +00001004 if (0 == strcmp("Save", (*command)[i].c_str()) ||
robertphillips@google.com0a4805e2013-05-29 13:24:23 +00001005 0 == strcmp("Save Layer", (*command)[i].c_str()) ||
1006 0 == strcmp("BeginCommentGroup", (*command)[i].c_str())) {
robertphillips@google.com30d35f22012-11-06 16:45:36 +00001007 indent += 10;
1008 }
1009
robertphillips@google.comd26c7062012-11-12 20:42:12 +00001010 item->setData(Qt::UserRole + 4, -1.0);
1011
chudy@google.comc432f002012-07-10 13:19:25 +00001012 fListWidget.addItem(item);
chudy@google.com902ebe52012-06-29 14:21:22 +00001013 }
1014}
1015
skia.committer@gmail.com91274b92013-03-13 07:01:04 +00001016void SkDebuggerGUI::setupOverviewText(const SkTDArray<double>* typeTimes,
robertphillips@google.come428f9b2013-03-12 15:33:40 +00001017 double totTime,
1018 int numRuns) {
borenet@google.com2d9dbd42013-03-12 13:07:40 +00001019 SkString overview;
robertphillips@google.come428f9b2013-03-12 15:33:40 +00001020 fDebugger.getOverviewText(typeTimes, totTime, &overview, numRuns);
borenet@google.com2d9dbd42013-03-12 13:07:40 +00001021 fInspectorWidget.setText(overview.c_str(), SkInspectorWidget::kOverview_TabType);
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +00001022}
1023
1024void SkDebuggerGUI::setupComboBox(SkTArray<SkString>* command) {
1025 fFilter.clear();
1026 fFilter.addItem("--Filter By Available Commands--");
1027
1028 std::map<std::string, int> map;
1029 for (int i = 0; i < command->count(); i++) {
1030 map[(*command)[i].c_str()]++;
1031 }
1032
skia.committer@gmail.com34587162012-11-20 02:01:23 +00001033 for (std::map<std::string, int>::iterator it = map.begin(); it != map.end();
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +00001034 ++it) {
1035 fFilter.addItem((it->first).c_str());
1036 }
chudy@google.com902ebe52012-06-29 14:21:22 +00001037
1038 // NOTE(chudy): Makes first item unselectable.
chudy@google.com7dcae672012-07-09 20:26:53 +00001039 QStandardItemModel* model = qobject_cast<QStandardItemModel*>(
chudy@google.comc432f002012-07-10 13:19:25 +00001040 fFilter.model());
1041 QModelIndex firstIndex = model->index(0, fFilter.modelColumn(),
1042 fFilter.rootModelIndex());
chudy@google.com902ebe52012-06-29 14:21:22 +00001043 QStandardItem* firstItem = model->itemFromIndex(firstIndex);
1044 firstItem->setSelectable(false);
1045}