blob: a30cde23c409eb425af8fd1ef412c7083b7d1501 [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)
commit-bot@chromium.orgbcd431e2013-11-21 13:41:37 +000032 , fCentralSplitter(this)
chudy@google.com2d537a12012-07-31 12:49:52 +000033 , 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)
commit-bot@chromium.orgbcd431e2013-11-21 13:41:37 +000059 , fListWidget(&fCentralSplitter)
60 , fDirectoryWidget(&fCentralSplitter)
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()));
commit-bot@chromium.org22d39332013-11-21 15:37:29 +000093 connect(&fSettingsWidget, SIGNAL(visibilityFilterChanged()), 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)));
commit-bot@chromium.org768ac852014-03-03 16:32:17 +0000100 connect(fSettingsWidget.getMegaVizCheckBox(), SIGNAL(toggled(bool)), this, SLOT(actionMegaVizWidget(bool)));
chudy@google.comea5488b2012-07-26 19:38:22 +0000101 connect(&fActionPause, SIGNAL(toggled(bool)), this, SLOT(pauseDrawing(bool)));
chudy@google.come504de02012-07-16 18:35:23 +0000102 connect(&fActionCreateBreakpoint, SIGNAL(activated()), this, SLOT(toggleBreakpoint()));
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000103 connect(&fActionShowDeletes, SIGNAL(triggered()), this, SLOT(showDeletes()));
chudy@google.comea5488b2012-07-26 19:38:22 +0000104 connect(&fCanvasWidget, SIGNAL(hitChanged(int)), this, SLOT(selectCommand(int)));
105 connect(&fCanvasWidget, SIGNAL(hitChanged(int)), &fSettingsWidget, SLOT(updateHit(int)));
106 connect(&fCanvasWidget, SIGNAL(scaleFactorChanged(float)), this, SLOT(actionScale(float)));
107 connect(&fCanvasWidget, SIGNAL(commandChanged(int)), &fSettingsWidget, SLOT(updateCommand(int)));
chudy@google.com0ab03392012-07-28 20:16:11 +0000108 connect(&fActionSaveAs, SIGNAL(triggered()), this, SLOT(actionSaveAs()));
109 connect(&fActionSave, SIGNAL(triggered()), this, SLOT(actionSave()));
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000110
bungeman@google.come8cc6e82013-01-17 16:30:56 +0000111 fMapper.setMapping(&fActionZoomIn, SkCanvasWidget::kIn_ZoomCommand);
112 fMapper.setMapping(&fActionZoomOut, SkCanvasWidget::kOut_ZoomCommand);
chudy@google.coma1226312012-07-26 20:26:44 +0000113
114 connect(&fActionZoomIn, SIGNAL(triggered()), &fMapper, SLOT(map()));
115 connect(&fActionZoomOut, SIGNAL(triggered()), &fMapper, SLOT(map()));
bungeman@google.come8cc6e82013-01-17 16:30:56 +0000116 connect(&fMapper, SIGNAL(mapped(int)), &fCanvasWidget, SLOT(zoom(int)));
chudy@google.coma1226312012-07-26 20:26:44 +0000117
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000118 fInspectorWidget.setDisabled(true);
chudy@google.comd3058f52012-07-19 13:41:27 +0000119 fMenuEdit.setDisabled(true);
120 fMenuNavigate.setDisabled(true);
121 fMenuView.setDisabled(true);
chudy@google.combbad34d2012-08-13 14:26:36 +0000122
123 SkGraphics::Init();
chudy@google.com902ebe52012-06-29 14:21:22 +0000124}
125
chudy@google.combbad34d2012-08-13 14:26:36 +0000126SkDebuggerGUI::~SkDebuggerGUI() {
127 SkGraphics::Term();
128}
chudy@google.com902ebe52012-06-29 14:21:22 +0000129
130void SkDebuggerGUI::actionBreakpoints() {
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000131 fBreakpointsActivated = !fBreakpointsActivated;
chudy@google.comc432f002012-07-10 13:19:25 +0000132 for (int row = 0; row < fListWidget.count(); row++) {
133 QListWidgetItem *item = fListWidget.item(row);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000134 item->setHidden(item->checkState() == Qt::Unchecked && fBreakpointsActivated);
135 }
136}
chudy@google.com902ebe52012-06-29 14:21:22 +0000137
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000138void SkDebuggerGUI::showDeletes() {
139 fDeletesActivated = !fDeletesActivated;
140 for (int row = 0; row < fListWidget.count(); row++) {
141 QListWidgetItem *item = fListWidget.item(row);
chudy@google.com607357f2012-08-07 16:12:23 +0000142 item->setHidden(fDebugger.isCommandVisible(row)
143 && fDeletesActivated);
chudy@google.com902ebe52012-06-29 14:21:22 +0000144 }
145}
146
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000147// The timed picture playback uses the SkPicturePlayback's profiling stubs
148// to time individual commands. The offsets are needed to map SkPicture
149// offsets to individual commands.
150class SkTimedPicturePlayback : public SkPicturePlayback {
151public:
scroggo@google.com12705322013-10-01 15:30:46 +0000152 static SkTimedPicturePlayback* CreateFromStream(SkStream* stream, const SkPictInfo& info,
153 SkPicture::InstallPixelRefProc proc,
154 const SkTDArray<bool>& deletedCommands) {
155 // Mimics SkPicturePlayback::CreateFromStream
156 SkAutoTDelete<SkTimedPicturePlayback> playback(SkNEW_ARGS(SkTimedPicturePlayback,
157 (deletedCommands)));
158 if (!playback->parseStream(stream, info, proc)) {
159 return NULL; // we're invalid
160 }
161 return playback.detach();
162 }
163
164 SkTimedPicturePlayback(const SkTDArray<bool>& deletedCommands)
165 : INHERITED()
bungeman@google.come8cc6e82013-01-17 16:30:56 +0000166 , fSkipCommands(deletedCommands)
167 , fTot(0.0)
168 , fCurCommand(0) {
robertphillips@google.com6d9c92b2013-05-23 13:21:18 +0000169 fTimes.setCount(deletedCommands.count());
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000170 fTypeTimes.setCount(LAST_DRAWTYPE_ENUM+1);
171 this->resetTimes();
172 }
173
174 void resetTimes() {
robertphillips@google.com6d9c92b2013-05-23 13:21:18 +0000175 for (int i = 0; i < fTimes.count(); ++i) {
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000176 fTimes[i] = 0.0;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000177 }
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000178 for (int i = 0; i < fTypeTimes.count(); ++i) {
179 fTypeTimes[i] = 0.0f;
180 }
181 fTot = 0.0;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000182 }
183
184 int count() const { return fTimes.count(); }
185
186 double time(int index) const { return fTimes[index] / fTot; }
187
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000188 const SkTDArray<double>* typeTimes() const { return &fTypeTimes; }
189
190 double totTime() const { return fTot; }
191
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000192protected:
robertphillips@google.come174a8b2012-11-27 16:04:42 +0000193 BenchSysTimer fTimer;
robertphillips@google.com5f971142012-12-07 20:48:56 +0000194 SkTDArray<bool> fSkipCommands; // has the command been deleted in the GUI?
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000195 SkTDArray<double> fTimes; // sum of time consumed for each command
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000196 SkTDArray<double> fTypeTimes; // sum of time consumed for each type of command (e.g., drawPath)
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000197 double fTot; // total of all times in 'fTimes'
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000198 int fCurType;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000199 int fCurCommand; // the current command being executed/timed
200
robertphillips@google.com6d9c92b2013-05-23 13:21:18 +0000201#ifdef SK_DEVELOPER
202 virtual bool preDraw(int opIndex, int type) SK_OVERRIDE {
203 fCurCommand = opIndex;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000204
robertphillips@google.com5f971142012-12-07 20:48:56 +0000205 if (fSkipCommands[fCurCommand]) {
robertphillips@google.com6d9c92b2013-05-23 13:21:18 +0000206 return true;
robertphillips@google.com5f971142012-12-07 20:48:56 +0000207 }
208
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000209 fCurType = type;
210 // The SkDebugCanvas doesn't recognize these types. This class needs to
211 // convert or else we'll wind up with a mismatch between the type counts
212 // the debugger displays and the profile times.
213 if (DRAW_POS_TEXT_TOP_BOTTOM == type) {
214 fCurType = DRAW_POS_TEXT;
215 } else if (DRAW_POS_TEXT_H_TOP_BOTTOM == type) {
216 fCurType = DRAW_POS_TEXT_H;
217 }
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000218
robertphillips@google.come174a8b2012-11-27 16:04:42 +0000219#if defined(SK_BUILD_FOR_WIN32)
220 // CPU timer doesn't work well on Windows
221 fTimer.startWall();
222#else
223 fTimer.startCpu();
224#endif
robertphillips@google.com5f971142012-12-07 20:48:56 +0000225
robertphillips@google.com6d9c92b2013-05-23 13:21:18 +0000226 return false;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000227 }
228
robertphillips@google.com6d9c92b2013-05-23 13:21:18 +0000229 virtual void postDraw(int opIndex) SK_OVERRIDE {
robertphillips@google.come174a8b2012-11-27 16:04:42 +0000230#if defined(SK_BUILD_FOR_WIN32)
231 // CPU timer doesn't work well on Windows
232 double time = fTimer.endWall();
233#else
234 double time = fTimer.endCpu();
235#endif
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000236
robertphillips@google.com6d9c92b2013-05-23 13:21:18 +0000237 SkASSERT(opIndex == fCurCommand);
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000238 SkASSERT(fCurType <= LAST_DRAWTYPE_ENUM);
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000239
robertphillips@google.come174a8b2012-11-27 16:04:42 +0000240 fTimes[fCurCommand] += time;
241 fTypeTimes[fCurType] += time;
242 fTot += time;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000243 }
robertphillips@google.com6d9c92b2013-05-23 13:21:18 +0000244#endif
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000245
246private:
scroggo@google.com12705322013-10-01 15:30:46 +0000247 // SkPicturePlayback::parseStream is protected, so it can be
248 // called here, but not by our static factory function. This
249 // allows the factory function to call it.
250 bool parseStream(SkStream* stream, const SkPictInfo& info,
251 SkPicture::InstallPixelRefProc proc) {
252 return this->INHERITED::parseStream(stream, info, proc);
253 }
254
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000255 typedef SkPicturePlayback INHERITED;
256};
257
258// Wrap SkPicture to allow installation of an SkTimedPicturePlayback object
259class SkTimedPicture : public SkPicture {
260public:
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000261 static SkTimedPicture* CreateTimedPicture(SkStream* stream,
262 SkPicture::InstallPixelRefProc proc,
263 const SkTDArray<bool>& deletedCommands) {
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000264 SkPictInfo info;
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000265 if (!StreamIsSKP(stream, &info)) {
266 return NULL;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000267 }
268
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000269 SkTimedPicturePlayback* playback;
270 // Check to see if there is a playback to recreate.
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000271 if (stream->readBool()) {
scroggo@google.com12705322013-10-01 15:30:46 +0000272 playback = SkTimedPicturePlayback::CreateFromStream(stream, info, proc,
273 deletedCommands);
274 if (NULL == playback) {
275 return NULL;
276 }
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000277 } else {
278 playback = NULL;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000279 }
280
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000281 return SkNEW_ARGS(SkTimedPicture, (playback, info.fWidth, info.fHeight));
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000282 }
283
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000284 void resetTimes() { ((SkTimedPicturePlayback*) fPlayback)->resetTimes(); }
285
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000286 int count() const { return ((SkTimedPicturePlayback*) fPlayback)->count(); }
287
288 // return the fraction of the total time this command consumed
289 double time(int index) const { return ((SkTimedPicturePlayback*) fPlayback)->time(index); }
290
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000291 const SkTDArray<double>* typeTimes() const { return ((SkTimedPicturePlayback*) fPlayback)->typeTimes(); }
292
293 double totTime() const { return ((SkTimedPicturePlayback*) fPlayback)->totTime(); }
294
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000295private:
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000296 // disallow default ctor b.c. we don't have a good way to setup the fPlayback ptr
297 SkTimedPicture();
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000298 // Private ctor only used by CreateTimedPicture, which has created the playback.
299 SkTimedPicture(SkTimedPicturePlayback* playback, int width, int height)
300 : INHERITED(playback, width, height) {}
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000301 // disallow the copy ctor - enabling would require copying code from SkPicture
302 SkTimedPicture(const SkTimedPicture& src);
303
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000304 typedef SkPicture INHERITED;
305};
306
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000307// This is a simplification of PictureBenchmark's run with the addition of
308// clearing of the times after the first pass (in resetTimes)
skia.committer@gmail.com34587162012-11-20 02:01:23 +0000309void SkDebuggerGUI::run(SkTimedPicture* pict,
310 sk_tools::PictureRenderer* renderer,
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000311 int repeats) {
312 SkASSERT(pict);
313 if (NULL == pict) {
314 return;
315 }
316
317 SkASSERT(renderer != NULL);
318 if (NULL == renderer) {
319 return;
320 }
321
322 renderer->init(pict);
323
324 renderer->setup();
325 renderer->render(NULL);
jvanverth@google.comade32662013-01-28 21:09:05 +0000326 renderer->resetState(true);
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000327
328 // We throw this away the first batch of times to remove first time effects (such as paging in this program)
329 pict->resetTimes();
330
331 for (int i = 0; i < repeats; ++i) {
332 renderer->setup();
333 renderer->render(NULL);
jvanverth@google.comade32662013-01-28 21:09:05 +0000334 renderer->resetState(true);
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000335 }
336
337 renderer->end();
338}
339
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000340void SkDebuggerGUI::actionProfile() {
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000341 // In order to profile we pass the command offsets (that were read-in
342 // in loadPicture by the SkOffsetPicture) to an SkTimedPlaybackPicture.
skia.committer@gmail.com884e60b2012-11-16 02:01:17 +0000343 // The SkTimedPlaybackPicture in turn passes the offsets to an
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000344 // SkTimedPicturePlayback object which uses them to track the performance
345 // of individual commands.
346 if (fFileName.isEmpty()) {
347 return;
348 }
349
350 SkFILEStream inputStream;
351
352 inputStream.setPath(fFileName.c_str());
353 if (!inputStream.isValid()) {
354 return;
355 }
356
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000357 SkAutoTUnref<SkTimedPicture> picture(SkTimedPicture::CreateTimedPicture(&inputStream,
358 &SkImageDecoder::DecodeMemory, fSkipCommands));
359 if (NULL == picture.get()) {
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000360 return;
361 }
362
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000363 // For now this #if allows switching between tiled and simple rendering
364 // modes. Eventually this will be accomplished via the GUI
robertphillips@google.come174a8b2012-11-27 16:04:42 +0000365#if 0
366 // With the current batch of SysTimers, profiling in tiled mode
367 // gets swamped by the timing overhead:
368 //
369 // tile mode simple mode
370 // debugger 64.2ms 12.8ms
371 // bench_pictures 16.9ms 12.4ms
372 //
373 // This is b.c. in tiled mode each command is called many more times
374 // but typically does less work on each invocation (due to clipping)
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000375 sk_tools::TiledPictureRenderer* renderer = NULL;
376
377 renderer = SkNEW(sk_tools::TiledPictureRenderer);
378 renderer->setTileWidth(256);
379 renderer->setTileHeight(256);
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000380#else
381 sk_tools::SimplePictureRenderer* renderer = NULL;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000382
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000383 renderer = SkNEW(sk_tools::SimplePictureRenderer);
robertphillips@google.com1447aa32013-01-30 21:09:09 +0000384
385#if SK_SUPPORT_GPU
commit-bot@chromium.orgfde1e7c2013-08-02 13:59:50 +0000386 if (fSettingsWidget.isGLActive()) {
robertphillips@google.com1447aa32013-01-30 21:09:09 +0000387 renderer->setDeviceType(sk_tools::PictureRenderer::kGPU_DeviceType);
commit-bot@chromium.orgfde1e7c2013-08-02 13:59:50 +0000388 renderer->setSampleCount(fSettingsWidget.getGLSampleCount());
robertphillips@google.com1447aa32013-01-30 21:09:09 +0000389 }
390#endif
391
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000392#endif
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000393
robertphillips@google.come174a8b2012-11-27 16:04:42 +0000394 static const int kNumRepeats = 10;
395
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000396 run(picture.get(), renderer, kNumRepeats);
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000397
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000398 SkASSERT(picture->count() == fListWidget.count());
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000399
400 // extract the individual command times from the SkTimedPlaybackPicture
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000401 for (int i = 0; i < picture->count(); ++i) {
402 double temp = picture->time(i);
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000403
404 QListWidgetItem* item = fListWidget.item(i);
405
406 item->setData(Qt::UserRole + 4, 100.0*temp);
407 }
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000408
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000409 setupOverviewText(picture->typeTimes(), picture->totTime(), kNumRepeats);
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000410}
411
chudy@google.com902ebe52012-06-29 14:21:22 +0000412void SkDebuggerGUI::actionCancel() {
chudy@google.comc432f002012-07-10 13:19:25 +0000413 for (int row = 0; row < fListWidget.count(); row++) {
414 fListWidget.item(row)->setHidden(false);
chudy@google.com902ebe52012-06-29 14:21:22 +0000415 }
416}
417
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000418void SkDebuggerGUI::actionClearBreakpoints() {
419 for (int row = 0; row < fListWidget.count(); row++) {
420 QListWidgetItem* item = fListWidget.item(row);
421 item->setCheckState(Qt::Unchecked);
422 item->setData(Qt::DecorationRole,
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000423 QPixmap(":/blank.png"));
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000424 }
425}
426
427void SkDebuggerGUI::actionClearDeletes() {
428 for (int row = 0; row < fListWidget.count(); row++) {
429 QListWidgetItem* item = fListWidget.item(row);
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000430 item->setData(Qt::UserRole + 2, QPixmap(":/blank.png"));
chudy@google.com607357f2012-08-07 16:12:23 +0000431 fDebugger.setCommandVisible(row, true);
robertphillips@google.com5f971142012-12-07 20:48:56 +0000432 fSkipCommands[row] = false;
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000433 }
434 if (fPause) {
435 fCanvasWidget.drawTo(fPausedRow);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000436 fImageWidget.draw();
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000437 } else {
438 fCanvasWidget.drawTo(fListWidget.currentRow());
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000439 fImageWidget.draw();
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000440 }
441}
442
chudy@google.com902ebe52012-06-29 14:21:22 +0000443void SkDebuggerGUI::actionCommandFilter() {
commit-bot@chromium.org22d39332013-11-21 15:37:29 +0000444 fDebugger.highlightCurrentCommand(fSettingsWidget.getVisibilityFilter());
chudy@google.comc432f002012-07-10 13:19:25 +0000445 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
commit-bot@chromium.org768ac852014-03-03 16:32:17 +0000525void SkDebuggerGUI::actionMegaVizWidget(bool isToggled) {
526 fDebugger.setMegaViz(isToggled);
527 fCanvasWidget.update();
528}
529
robertphillips@google.com32bbcf82013-10-17 17:56:10 +0000530void SkDebuggerGUI::actionTextureFilter() {
531 SkPaint::FilterLevel level;
532 bool enabled = fSettingsWidget.getFilterOverride(&level);
533 fDebugger.setTexFilterOverride(enabled, level);
534 fCanvasWidget.update();
535}
536
chudy@google.com902ebe52012-06-29 14:21:22 +0000537void SkDebuggerGUI::actionRewind() {
chudy@google.come504de02012-07-16 18:35:23 +0000538 fListWidget.setCurrentRow(0);
chudy@google.com902ebe52012-06-29 14:21:22 +0000539}
540
chudy@google.com0ab03392012-07-28 20:16:11 +0000541void SkDebuggerGUI::actionSave() {
robertphillips@google.come219baf2013-01-28 19:25:43 +0000542 fFileName = fPath.toAscii().data();
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000543 fFileName.append("/");
robertphillips@google.come219baf2013-01-28 19:25:43 +0000544 fFileName.append(fDirectoryWidget.currentItem()->text().toAscii().data());
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000545 saveToFile(fFileName);
chudy@google.com0ab03392012-07-28 20:16:11 +0000546}
547
548void SkDebuggerGUI::actionSaveAs() {
549 QString filename = QFileDialog::getSaveFileName(this, "Save File", "",
550 "Skia Picture (*skp)");
chudy@google.com38b08ce2012-07-28 23:26:10 +0000551 if (!filename.endsWith(".skp", Qt::CaseInsensitive)) {
chudy@google.com0ab03392012-07-28 20:16:11 +0000552 filename.append(".skp");
553 }
djsollen@google.comc3c82162012-11-13 18:35:10 +0000554 saveToFile(SkString(filename.toAscii().data()));
chudy@google.com0ab03392012-07-28 20:16:11 +0000555}
556
chudy@google.com7dcae672012-07-09 20:26:53 +0000557void SkDebuggerGUI::actionScale(float scaleFactor) {
chudy@google.comc432f002012-07-10 13:19:25 +0000558 fSettingsWidget.setZoomText(scaleFactor);
chudy@google.com7dcae672012-07-09 20:26:53 +0000559}
560
chudy@google.com902ebe52012-06-29 14:21:22 +0000561void SkDebuggerGUI::actionSettings() {
chudy@google.comc432f002012-07-10 13:19:25 +0000562 if (fSettingsWidget.isHidden()) {
563 fSettingsWidget.setHidden(false);
chudy@google.com902ebe52012-06-29 14:21:22 +0000564 } else {
chudy@google.comc432f002012-07-10 13:19:25 +0000565 fSettingsWidget.setHidden(true);
chudy@google.com902ebe52012-06-29 14:21:22 +0000566 }
567}
568
569void SkDebuggerGUI::actionStepBack() {
chudy@google.comc432f002012-07-10 13:19:25 +0000570 int currentRow = fListWidget.currentRow();
chudy@google.com902ebe52012-06-29 14:21:22 +0000571 if (currentRow != 0) {
chudy@google.comc432f002012-07-10 13:19:25 +0000572 fListWidget.setCurrentRow(currentRow - 1);
chudy@google.com902ebe52012-06-29 14:21:22 +0000573 }
574}
575
576void SkDebuggerGUI::actionStepForward() {
chudy@google.comc432f002012-07-10 13:19:25 +0000577 int currentRow = fListWidget.currentRow();
chudy@google.com902ebe52012-06-29 14:21:22 +0000578 QString curRow = QString::number(currentRow);
chudy@google.comc432f002012-07-10 13:19:25 +0000579 QString curCount = QString::number(fListWidget.count());
580 if (currentRow < fListWidget.count() - 1) {
581 fListWidget.setCurrentRow(currentRow + 1);
chudy@google.com902ebe52012-06-29 14:21:22 +0000582 }
583}
584
chudy@google.coma9e937c2012-08-03 17:32:05 +0000585void SkDebuggerGUI::drawComplete() {
chudy@google.com607357f2012-08-07 16:12:23 +0000586 fInspectorWidget.setMatrix(fDebugger.getCurrentMatrix());
587 fInspectorWidget.setClip(fDebugger.getCurrentClip());
chudy@google.coma9e937c2012-08-03 17:32:05 +0000588}
589
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000590void SkDebuggerGUI::saveToFile(const SkString& filename) {
591 SkFILEWStream file(filename.c_str());
robertphillips@google.com25bc2f82013-01-22 18:03:56 +0000592 SkAutoTUnref<SkPicture> copy(fDebugger.copyPicture());
593
594 copy->serialize(&file);
chudy@google.com0ab03392012-07-28 20:16:11 +0000595}
596
chudy@google.com902ebe52012-06-29 14:21:22 +0000597void SkDebuggerGUI::loadFile(QListWidgetItem *item) {
598 if (fDirectoryWidgetActive) {
robertphillips@google.come219baf2013-01-28 19:25:43 +0000599 fFileName = fPath.toAscii().data();
jvanverth@google.com0ac6f162013-02-05 19:44:07 +0000600 // don't add a '/' to files in the local directory
601 if (fFileName.size() > 0) {
602 fFileName.append("/");
603 }
robertphillips@google.come219baf2013-01-28 19:25:43 +0000604 fFileName.append(item->text().toAscii().data());
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000605 loadPicture(fFileName);
chudy@google.com902ebe52012-06-29 14:21:22 +0000606 }
607}
608
609void SkDebuggerGUI::openFile() {
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000610 QString temp = QFileDialog::getOpenFileName(this, tr("Open File"), "",
chudy@google.com7dcae672012-07-09 20:26:53 +0000611 tr("Files (*.*)"));
robertphillips@google.comff6e6ba2013-01-28 17:43:26 +0000612 openFile(temp);
613}
614
615void SkDebuggerGUI::openFile(const QString &filename) {
chudy@google.com902ebe52012-06-29 14:21:22 +0000616 fDirectoryWidgetActive = false;
robertphillips@google.comff6e6ba2013-01-28 17:43:26 +0000617 if (!filename.isEmpty()) {
618 QFileInfo pathInfo(filename);
619 loadPicture(SkString(filename.toAscii().data()));
620 setupDirectoryWidget(pathInfo.path());
chudy@google.com902ebe52012-06-29 14:21:22 +0000621 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000622 fDirectoryWidgetActive = true;
623}
624
chudy@google.comc432f002012-07-10 13:19:25 +0000625void SkDebuggerGUI::pauseDrawing(bool isPaused) {
chudy@google.com607357f2012-08-07 16:12:23 +0000626 fPause = isPaused;
627 fPausedRow = fListWidget.currentRow();
628 fCanvasWidget.drawTo(fPausedRow);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000629 fImageWidget.draw();
chudy@google.com7dcae672012-07-09 20:26:53 +0000630}
631
chudy@google.com902ebe52012-06-29 14:21:22 +0000632void SkDebuggerGUI::registerListClick(QListWidgetItem *item) {
chudy@google.comd3058f52012-07-19 13:41:27 +0000633 if(!fLoading) {
634 int currentRow = fListWidget.currentRow();
chudy@google.comd3058f52012-07-19 13:41:27 +0000635
chudy@google.comea5488b2012-07-26 19:38:22 +0000636 if (currentRow != -1) {
637 if (!fPause) {
638 fCanvasWidget.drawTo(currentRow);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000639 fImageWidget.draw();
chudy@google.comd3058f52012-07-19 13:41:27 +0000640 }
chudy@google.com97cee972012-08-07 20:41:37 +0000641 SkTDArray<SkString*> *currInfo = fDebugger.getCommandInfo(
chudy@google.comea5488b2012-07-26 19:38:22 +0000642 currentRow);
643
644 /* TODO(chudy): Add command type before parameters. Rename v
645 * to something more informative. */
chudy@google.com97cee972012-08-07 20:41:37 +0000646 if (currInfo) {
chudy@google.comea5488b2012-07-26 19:38:22 +0000647 QString info;
648 info.append("<b>Parameters: </b><br/>");
chudy@google.com97cee972012-08-07 20:41:37 +0000649 for (int i = 0; i < currInfo->count(); i++) {
650
651 info.append(QString((*currInfo)[i]->c_str()));
chudy@google.comea5488b2012-07-26 19:38:22 +0000652 info.append("<br/>");
653 }
chudy@google.com6bd109a2012-08-14 19:34:13 +0000654 fInspectorWidget.setText(info, SkInspectorWidget::kDetail_TabType);
chudy@google.comea5488b2012-07-26 19:38:22 +0000655 fInspectorWidget.setDisabled(false);
chudy@google.comea5488b2012-07-26 19:38:22 +0000656 }
chudy@google.comd3058f52012-07-19 13:41:27 +0000657 }
chudy@google.comea5488b2012-07-26 19:38:22 +0000658
chudy@google.com902ebe52012-06-29 14:21:22 +0000659 }
660}
661
chudy@google.com9ca9bfe2012-07-12 21:58:14 +0000662void SkDebuggerGUI::selectCommand(int command) {
663 if (fPause) {
664 fListWidget.setCurrentRow(command);
665 }
666}
667
chudy@google.com902ebe52012-06-29 14:21:22 +0000668void SkDebuggerGUI::toggleBreakpoint() {
chudy@google.comc432f002012-07-10 13:19:25 +0000669 QListWidgetItem* item = fListWidget.currentItem();
chudy@google.com902ebe52012-06-29 14:21:22 +0000670 if (item->checkState() == Qt::Unchecked) {
671 item->setCheckState(Qt::Checked);
chudy@google.come565de42012-07-12 14:15:54 +0000672 item->setData(Qt::DecorationRole,
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000673 QPixmap(":/breakpoint_16x16.png"));
chudy@google.com902ebe52012-06-29 14:21:22 +0000674 } else {
chudy@google.com902ebe52012-06-29 14:21:22 +0000675 item->setCheckState(Qt::Unchecked);
chudy@google.come565de42012-07-12 14:15:54 +0000676 item->setData(Qt::DecorationRole,
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000677 QPixmap(":/blank.png"));
chudy@google.com902ebe52012-06-29 14:21:22 +0000678 }
679}
680
681void SkDebuggerGUI::toggleDirectory() {
chudy@google.com607357f2012-08-07 16:12:23 +0000682 fDirectoryWidget.setHidden(!fDirectoryWidget.isHidden());
chudy@google.com902ebe52012-06-29 14:21:22 +0000683}
684
685void SkDebuggerGUI::toggleFilter(QString string) {
chudy@google.comc432f002012-07-10 13:19:25 +0000686 for (int row = 0; row < fListWidget.count(); row++) {
687 QListWidgetItem *item = fListWidget.item(row);
chudy@google.com607357f2012-08-07 16:12:23 +0000688 item->setHidden(item->text() != string);
chudy@google.com902ebe52012-06-29 14:21:22 +0000689 }
690}
691
692void SkDebuggerGUI::setupUi(QMainWindow *SkDebuggerGUI) {
693 QIcon windowIcon;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000694 windowIcon.addFile(QString::fromUtf8(":/skia.png"), QSize(),
chudy@google.com7dcae672012-07-09 20:26:53 +0000695 QIcon::Normal, QIcon::Off);
chudy@google.com902ebe52012-06-29 14:21:22 +0000696 SkDebuggerGUI->setObjectName(QString::fromUtf8("SkDebuggerGUI"));
697 SkDebuggerGUI->resize(1200, 1000);
698 SkDebuggerGUI->setWindowIcon(windowIcon);
chudy@google.comc432f002012-07-10 13:19:25 +0000699 SkDebuggerGUI->setWindowTitle("Skia Debugger");
chudy@google.com902ebe52012-06-29 14:21:22 +0000700
chudy@google.come504de02012-07-16 18:35:23 +0000701 fActionOpen.setShortcuts(QKeySequence::Open);
chudy@google.comc432f002012-07-10 13:19:25 +0000702 fActionOpen.setText("Open");
chudy@google.com902ebe52012-06-29 14:21:22 +0000703
704 QIcon breakpoint;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000705 breakpoint.addFile(QString::fromUtf8(":/breakpoint.png"),
chudy@google.com7dcae672012-07-09 20:26:53 +0000706 QSize(), QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000707 fActionBreakpoint.setShortcut(QKeySequence(tr("Ctrl+B")));
chudy@google.comc432f002012-07-10 13:19:25 +0000708 fActionBreakpoint.setIcon(breakpoint);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000709 fActionBreakpoint.setText("Breakpoints");
chudy@google.com902ebe52012-06-29 14:21:22 +0000710
711 QIcon cancel;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000712 cancel.addFile(QString::fromUtf8(":/reload.png"), QSize(),
chudy@google.com7dcae672012-07-09 20:26:53 +0000713 QIcon::Normal, QIcon::Off);
chudy@google.comc432f002012-07-10 13:19:25 +0000714 fActionCancel.setIcon(cancel);
715 fActionCancel.setText("Clear Filter");
chudy@google.com902ebe52012-06-29 14:21:22 +0000716
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000717 fActionClearBreakpoints.setShortcut(QKeySequence(tr("Alt+B")));
718 fActionClearBreakpoints.setText("Clear Breakpoints");
719
720 fActionClearDeletes.setShortcut(QKeySequence(tr("Alt+X")));
721 fActionClearDeletes.setText("Clear Deletes");
722
chudy@google.come504de02012-07-16 18:35:23 +0000723 fActionClose.setShortcuts(QKeySequence::Quit);
chudy@google.comc432f002012-07-10 13:19:25 +0000724 fActionClose.setText("Exit");
chudy@google.com902ebe52012-06-29 14:21:22 +0000725
chudy@google.come504de02012-07-16 18:35:23 +0000726 fActionCreateBreakpoint.setShortcut(QKeySequence(tr("B")));
727 fActionCreateBreakpoint.setText("Set Breakpoint");
728
729 fActionDelete.setShortcut(QKeySequence(tr("X")));
chudy@google.comc432f002012-07-10 13:19:25 +0000730 fActionDelete.setText("Delete Command");
chudy@google.com902ebe52012-06-29 14:21:22 +0000731
chudy@google.come504de02012-07-16 18:35:23 +0000732 fActionDirectory.setShortcut(QKeySequence(tr("Ctrl+D")));
733 fActionDirectory.setText("Directory");
chudy@google.com902ebe52012-06-29 14:21:22 +0000734
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000735 QIcon profile;
robertphillips@google.comd1636362012-11-19 18:25:09 +0000736 profile.addFile(QString::fromUtf8(":/profile.png"), QSize(),
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000737 QIcon::Normal, QIcon::Off);
738 fActionProfile.setIcon(profile);
739 fActionProfile.setText("Profile");
robertphillips@google.come099bc42012-11-19 16:26:40 +0000740 fActionProfile.setDisabled(true);
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000741
chudy@google.comc432f002012-07-10 13:19:25 +0000742 QIcon inspector;
robertphillips@google.comd1636362012-11-19 18:25:09 +0000743 inspector.addFile(QString::fromUtf8(":/inspector.png"),
chudy@google.comc432f002012-07-10 13:19:25 +0000744 QSize(), QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000745 fActionInspector.setShortcut(QKeySequence(tr("Ctrl+I")));
chudy@google.comc432f002012-07-10 13:19:25 +0000746 fActionInspector.setIcon(inspector);
chudy@google.come504de02012-07-16 18:35:23 +0000747 fActionInspector.setText("Inspector");
chudy@google.com902ebe52012-06-29 14:21:22 +0000748
bungeman@google.com2ff6d1d2013-07-01 14:24:12 +0000749 QIcon settings;
750 settings.addFile(QString::fromUtf8(":/inspector.png"),
751 QSize(), QIcon::Normal, QIcon::Off);
752 fActionSettings.setShortcut(QKeySequence(tr("Ctrl+G")));
753 fActionSettings.setIcon(settings);
754 fActionSettings.setText("Settings");
skia.committer@gmail.com0d55dd72013-07-02 07:00:59 +0000755
chudy@google.comc432f002012-07-10 13:19:25 +0000756 QIcon play;
robertphillips@google.comd1636362012-11-19 18:25:09 +0000757 play.addFile(QString::fromUtf8(":/play.png"), QSize(),
chudy@google.comc432f002012-07-10 13:19:25 +0000758 QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000759 fActionPlay.setShortcut(QKeySequence(tr("Ctrl+P")));
chudy@google.comc432f002012-07-10 13:19:25 +0000760 fActionPlay.setIcon(play);
761 fActionPlay.setText("Play");
chudy@google.com902ebe52012-06-29 14:21:22 +0000762
chudy@google.come504de02012-07-16 18:35:23 +0000763 QIcon pause;
robertphillips@google.comd1636362012-11-19 18:25:09 +0000764 pause.addFile(QString::fromUtf8(":/pause.png"), QSize(),
chudy@google.comc432f002012-07-10 13:19:25 +0000765 QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000766 fActionPause.setShortcut(QKeySequence(tr("Space")));
767 fActionPause.setCheckable(true);
768 fActionPause.setIcon(pause);
769 fActionPause.setText("Pause");
770
chudy@google.comc432f002012-07-10 13:19:25 +0000771 QIcon rewind;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000772 rewind.addFile(QString::fromUtf8(":/rewind.png"), QSize(),
chudy@google.comc432f002012-07-10 13:19:25 +0000773 QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000774 fActionRewind.setShortcut(QKeySequence(tr("Ctrl+R")));
chudy@google.comc432f002012-07-10 13:19:25 +0000775 fActionRewind.setIcon(rewind);
776 fActionRewind.setText("Rewind");
chudy@google.com902ebe52012-06-29 14:21:22 +0000777
chudy@google.com0ab03392012-07-28 20:16:11 +0000778 fActionSave.setShortcut(QKeySequence::Save);
779 fActionSave.setText("Save");
780 fActionSave.setDisabled(true);
781 fActionSaveAs.setShortcut(QKeySequence::SaveAs);
782 fActionSaveAs.setText("Save As");
783 fActionSaveAs.setDisabled(true);
784
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000785 fActionShowDeletes.setShortcut(QKeySequence(tr("Ctrl+X")));
786 fActionShowDeletes.setText("Deleted Commands");
787
chudy@google.comc432f002012-07-10 13:19:25 +0000788 QIcon stepBack;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000789 stepBack.addFile(QString::fromUtf8(":/previous.png"), QSize(),
chudy@google.comc432f002012-07-10 13:19:25 +0000790 QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000791 fActionStepBack.setShortcut(QKeySequence(tr("[")));
chudy@google.comc432f002012-07-10 13:19:25 +0000792 fActionStepBack.setIcon(stepBack);
793 fActionStepBack.setText("Step Back");
chudy@google.com902ebe52012-06-29 14:21:22 +0000794
chudy@google.comc432f002012-07-10 13:19:25 +0000795 QIcon stepForward;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000796 stepForward.addFile(QString::fromUtf8(":/next.png"),
chudy@google.comc432f002012-07-10 13:19:25 +0000797 QSize(), QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000798 fActionStepForward.setShortcut(QKeySequence(tr("]")));
chudy@google.comc432f002012-07-10 13:19:25 +0000799 fActionStepForward.setIcon(stepForward);
800 fActionStepForward.setText("Step Forward");
801
chudy@google.coma1226312012-07-26 20:26:44 +0000802 fActionZoomIn.setShortcut(QKeySequence(tr("Ctrl+=")));
803 fActionZoomIn.setText("Zoom In");
804 fActionZoomOut.setShortcut(QKeySequence(tr("Ctrl+-")));
805 fActionZoomOut.setText("Zoom Out");
806
chudy@google.comc432f002012-07-10 13:19:25 +0000807 fListWidget.setItemDelegate(new SkListWidget(&fListWidget));
808 fListWidget.setObjectName(QString::fromUtf8("listWidget"));
commit-bot@chromium.orgbcd431e2013-11-21 13:41:37 +0000809 fListWidget.setMinimumWidth(250);
chudy@google.comc432f002012-07-10 13:19:25 +0000810
811 fFilter.addItem("--Filter By Available Commands--");
812
commit-bot@chromium.orgbcd431e2013-11-21 13:41:37 +0000813 fDirectoryWidget.setMinimumWidth(250);
chudy@google.comc432f002012-07-10 13:19:25 +0000814 fDirectoryWidget.setStyleSheet("QListWidget::Item {padding: 5px;}");
815
816 fCanvasWidget.setSizePolicy(QSizePolicy::Expanding,
chudy@google.com7dcae672012-07-09 20:26:53 +0000817 QSizePolicy::Expanding);
chudy@google.com902ebe52012-06-29 14:21:22 +0000818
skia.committer@gmail.com1c9c0d32012-11-22 02:02:41 +0000819 fImageWidget.setFixedSize(SkImageWidget::kImageWidgetWidth,
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000820 SkImageWidget::kImageWidgetHeight);
821
chudy@google.comc432f002012-07-10 13:19:25 +0000822 fInspectorWidget.setSizePolicy(QSizePolicy::Expanding,
chudy@google.com7dcae672012-07-09 20:26:53 +0000823 QSizePolicy::Expanding);
chudy@google.comc432f002012-07-10 13:19:25 +0000824 fInspectorWidget.setMaximumHeight(300);
chudy@google.com902ebe52012-06-29 14:21:22 +0000825
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000826 fSettingsAndImageLayout.setSpacing(6);
827 fSettingsAndImageLayout.addWidget(&fSettingsWidget);
828 fSettingsAndImageLayout.addWidget(&fImageWidget);
829
chudy@google.comc432f002012-07-10 13:19:25 +0000830 fSettingsWidget.setSizePolicy(QSizePolicy::Expanding,
831 QSizePolicy::Expanding);
832 fSettingsWidget.setMaximumWidth(250);
chudy@google.com902ebe52012-06-29 14:21:22 +0000833
commit-bot@chromium.orgbcd431e2013-11-21 13:41:37 +0000834 fLeftColumnSplitter.addWidget(&fListWidget);
835 fLeftColumnSplitter.addWidget(&fDirectoryWidget);
836 fLeftColumnSplitter.setOrientation(Qt::Vertical);
chudy@google.com902ebe52012-06-29 14:21:22 +0000837
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000838 fCanvasSettingsAndImageLayout.setSpacing(6);
839 fCanvasSettingsAndImageLayout.addWidget(&fCanvasWidget);
840 fCanvasSettingsAndImageLayout.addLayout(&fSettingsAndImageLayout);
841
chudy@google.comc432f002012-07-10 13:19:25 +0000842 fMainAndRightColumnLayout.setSpacing(6);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000843 fMainAndRightColumnLayout.addLayout(&fCanvasSettingsAndImageLayout);
chudy@google.comc432f002012-07-10 13:19:25 +0000844 fMainAndRightColumnLayout.addWidget(&fInspectorWidget);
commit-bot@chromium.orgbcd431e2013-11-21 13:41:37 +0000845 fMainAndRightColumnWidget.setLayout(&fMainAndRightColumnLayout);
chudy@google.com902ebe52012-06-29 14:21:22 +0000846
commit-bot@chromium.orgbcd431e2013-11-21 13:41:37 +0000847 fCentralSplitter.addWidget(&fLeftColumnSplitter);
848 fCentralSplitter.addWidget(&fMainAndRightColumnWidget);
849 fCentralSplitter.setStretchFactor(0, 0);
850 fCentralSplitter.setStretchFactor(1, 1);
chudy@google.comc432f002012-07-10 13:19:25 +0000851
commit-bot@chromium.orgbcd431e2013-11-21 13:41:37 +0000852 SkDebuggerGUI->setCentralWidget(&fCentralSplitter);
chudy@google.comc432f002012-07-10 13:19:25 +0000853 SkDebuggerGUI->setStatusBar(&fStatusBar);
854
chudy@google.come504de02012-07-16 18:35:23 +0000855 fToolBar.setIconSize(QSize(32, 32));
chudy@google.comc432f002012-07-10 13:19:25 +0000856 fToolBar.setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
857 SkDebuggerGUI->addToolBar(Qt::TopToolBarArea, &fToolBar);
chudy@google.com902ebe52012-06-29 14:21:22 +0000858
chudy@google.com0ab03392012-07-28 20:16:11 +0000859 fSpacer.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
chudy@google.com902ebe52012-06-29 14:21:22 +0000860
chudy@google.comc432f002012-07-10 13:19:25 +0000861 fToolBar.addAction(&fActionRewind);
862 fToolBar.addAction(&fActionStepBack);
chudy@google.come504de02012-07-16 18:35:23 +0000863 fToolBar.addAction(&fActionPause);
chudy@google.comc432f002012-07-10 13:19:25 +0000864 fToolBar.addAction(&fActionStepForward);
865 fToolBar.addAction(&fActionPlay);
866 fToolBar.addSeparator();
chudy@google.come504de02012-07-16 18:35:23 +0000867 fToolBar.addAction(&fActionInspector);
bungeman@google.com2ff6d1d2013-07-01 14:24:12 +0000868 fToolBar.addAction(&fActionSettings);
chudy@google.comc432f002012-07-10 13:19:25 +0000869 fToolBar.addSeparator();
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000870 fToolBar.addAction(&fActionProfile);
871
872 fToolBar.addSeparator();
chudy@google.com0ab03392012-07-28 20:16:11 +0000873 fToolBar.addWidget(&fSpacer);
chudy@google.comc432f002012-07-10 13:19:25 +0000874 fToolBar.addWidget(&fFilter);
875 fToolBar.addAction(&fActionCancel);
chudy@google.com902ebe52012-06-29 14:21:22 +0000876
877 // TODO(chudy): Remove static call.
878 fDirectoryWidgetActive = false;
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000879 fFileName = "";
robertphillips@google.comff6e6ba2013-01-28 17:43:26 +0000880 setupDirectoryWidget("");
chudy@google.com902ebe52012-06-29 14:21:22 +0000881 fDirectoryWidgetActive = true;
882
chudy@google.com902ebe52012-06-29 14:21:22 +0000883 // Menu Bar
chudy@google.comc432f002012-07-10 13:19:25 +0000884 fMenuFile.setTitle("File");
885 fMenuFile.addAction(&fActionOpen);
chudy@google.com0ab03392012-07-28 20:16:11 +0000886 fMenuFile.addAction(&fActionSave);
887 fMenuFile.addAction(&fActionSaveAs);
chudy@google.comc432f002012-07-10 13:19:25 +0000888 fMenuFile.addAction(&fActionClose);
chudy@google.come504de02012-07-16 18:35:23 +0000889
890 fMenuEdit.setTitle("Edit");
891 fMenuEdit.addAction(&fActionDelete);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000892 fMenuEdit.addAction(&fActionClearDeletes);
893 fMenuEdit.addSeparator();
chudy@google.come504de02012-07-16 18:35:23 +0000894 fMenuEdit.addAction(&fActionCreateBreakpoint);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000895 fMenuEdit.addAction(&fActionClearBreakpoints);
chudy@google.come504de02012-07-16 18:35:23 +0000896
chudy@google.comc432f002012-07-10 13:19:25 +0000897 fMenuNavigate.setTitle("Navigate");
chudy@google.come504de02012-07-16 18:35:23 +0000898 fMenuNavigate.addAction(&fActionRewind);
899 fMenuNavigate.addAction(&fActionStepBack);
900 fMenuNavigate.addAction(&fActionStepForward);
901 fMenuNavigate.addAction(&fActionPlay);
902 fMenuNavigate.addAction(&fActionPause);
chudy@google.comc432f002012-07-10 13:19:25 +0000903 fMenuNavigate.addAction(&fActionGoToLine);
chudy@google.come504de02012-07-16 18:35:23 +0000904
chudy@google.comc432f002012-07-10 13:19:25 +0000905 fMenuView.setTitle("View");
chudy@google.come504de02012-07-16 18:35:23 +0000906 fMenuView.addAction(&fActionBreakpoint);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000907 fMenuView.addAction(&fActionShowDeletes);
chudy@google.coma1226312012-07-26 20:26:44 +0000908 fMenuView.addAction(&fActionZoomIn);
909 fMenuView.addAction(&fActionZoomOut);
chudy@google.come504de02012-07-16 18:35:23 +0000910
911 fMenuWindows.setTitle("Window");
912 fMenuWindows.addAction(&fActionInspector);
bungeman@google.com2ff6d1d2013-07-01 14:24:12 +0000913 fMenuWindows.addAction(&fActionSettings);
chudy@google.come504de02012-07-16 18:35:23 +0000914 fMenuWindows.addAction(&fActionDirectory);
chudy@google.comc432f002012-07-10 13:19:25 +0000915
916 fActionGoToLine.setText("Go to Line...");
917 fActionGoToLine.setDisabled(true);
918 fMenuBar.addAction(fMenuFile.menuAction());
chudy@google.come504de02012-07-16 18:35:23 +0000919 fMenuBar.addAction(fMenuEdit.menuAction());
chudy@google.comc432f002012-07-10 13:19:25 +0000920 fMenuBar.addAction(fMenuView.menuAction());
921 fMenuBar.addAction(fMenuNavigate.menuAction());
chudy@google.come504de02012-07-16 18:35:23 +0000922 fMenuBar.addAction(fMenuWindows.menuAction());
chudy@google.com902ebe52012-06-29 14:21:22 +0000923
chudy@google.com7dcae672012-07-09 20:26:53 +0000924 fPause = false;
925
chudy@google.comc432f002012-07-10 13:19:25 +0000926 SkDebuggerGUI->setMenuBar(&fMenuBar);
chudy@google.com902ebe52012-06-29 14:21:22 +0000927 QMetaObject::connectSlotsByName(SkDebuggerGUI);
928}
929
robertphillips@google.comff6e6ba2013-01-28 17:43:26 +0000930void SkDebuggerGUI::setupDirectoryWidget(const QString& path) {
931 fPath = path;
932 QDir dir(path);
chudy@google.com902ebe52012-06-29 14:21:22 +0000933 QRegExp r(".skp");
chudy@google.comc432f002012-07-10 13:19:25 +0000934 fDirectoryWidget.clear();
935 const QStringList files = dir.entryList();
chudy@google.com902ebe52012-06-29 14:21:22 +0000936 foreach (QString f, files) {
chudy@google.com7dcae672012-07-09 20:26:53 +0000937 if (f.contains(r))
chudy@google.comc432f002012-07-10 13:19:25 +0000938 fDirectoryWidget.addItem(f);
chudy@google.com902ebe52012-06-29 14:21:22 +0000939 }
940}
941
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000942void SkDebuggerGUI::loadPicture(const SkString& fileName) {
943 fFileName = fileName;
chudy@google.comd3058f52012-07-19 13:41:27 +0000944 fLoading = true;
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000945 SkStream* stream = SkNEW_ARGS(SkFILEStream, (fileName.c_str()));
robertphillips@google.com2d40ec42013-02-07 20:39:40 +0000946
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000947 SkPicture* picture = SkPicture::CreateFromStream(stream);
robertphillips@google.com2d40ec42013-02-07 20:39:40 +0000948
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000949 if (NULL == picture) {
robertphillips@google.com2d40ec42013-02-07 20:39:40 +0000950 QMessageBox::critical(this, "Error loading file", "Couldn't read file, sorry.");
951 SkSafeUnref(stream);
952 return;
953 }
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000954
chudy@google.com686e6802012-08-14 16:00:32 +0000955 fCanvasWidget.resetWidgetTransform();
chudy@google.com607357f2012-08-07 16:12:23 +0000956 fDebugger.loadPicture(picture);
chudy@google.com4c7962e2012-08-14 19:38:31 +0000957
robertphillips@google.com6d9c92b2013-05-23 13:21:18 +0000958 fSkipCommands.setCount(fDebugger.getSize());
959 for (int i = 0; i < fSkipCommands.count(); ++i) {
robertphillips@google.com5f971142012-12-07 20:48:56 +0000960 fSkipCommands[i] = false;
961 }
962
chudy@google.com607357f2012-08-07 16:12:23 +0000963 SkSafeUnref(stream);
964 SkSafeUnref(picture);
965
chudy@google.com97cee972012-08-07 20:41:37 +0000966 // Will this automatically clear out due to nature of refcnt?
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000967 SkTArray<SkString>* commands = fDebugger.getDrawCommandsAsStrings();
chudy@google.com607357f2012-08-07 16:12:23 +0000968
robertphillips@google.com6d9c92b2013-05-23 13:21:18 +0000969 fActionProfile.setDisabled(false);
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000970
chudy@google.com7dcae672012-07-09 20:26:53 +0000971 /* fDebugCanvas is reinitialized every load picture. Need it to retain value
chudy@google.com607357f2012-08-07 16:12:23 +0000972 * of the visibility filter.
973 * TODO(chudy): This should be deprecated since fDebugger is not
974 * recreated.
975 * */
commit-bot@chromium.org22d39332013-11-21 15:37:29 +0000976 fDebugger.highlightCurrentCommand(fSettingsWidget.getVisibilityFilter());
chudy@google.com607357f2012-08-07 16:12:23 +0000977
chudy@google.com97cee972012-08-07 20:41:37 +0000978 setupListWidget(commands);
979 setupComboBox(commands);
robertphillips@google.come428f9b2013-03-12 15:33:40 +0000980 setupOverviewText(NULL, 0.0, 1);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000981 fInspectorWidget.setDisabled(false);
chudy@google.come606d6e2012-07-12 14:31:25 +0000982 fSettingsWidget.setDisabled(false);
chudy@google.comd3058f52012-07-19 13:41:27 +0000983 fMenuEdit.setDisabled(false);
984 fMenuNavigate.setDisabled(false);
985 fMenuView.setDisabled(false);
chudy@google.com0ab03392012-07-28 20:16:11 +0000986 fActionSave.setDisabled(false);
987 fActionSaveAs.setDisabled(false);
chudy@google.comd3058f52012-07-19 13:41:27 +0000988 fLoading = false;
989 actionPlay();
chudy@google.com902ebe52012-06-29 14:21:22 +0000990}
991
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000992void SkDebuggerGUI::setupListWidget(SkTArray<SkString>* command) {
chudy@google.comc432f002012-07-10 13:19:25 +0000993 fListWidget.clear();
chudy@google.com902ebe52012-06-29 14:21:22 +0000994 int counter = 0;
robertphillips@google.com30d35f22012-11-06 16:45:36 +0000995 int indent = 0;
chudy@google.com97cee972012-08-07 20:41:37 +0000996 for (int i = 0; i < command->count(); i++) {
chudy@google.com902ebe52012-06-29 14:21:22 +0000997 QListWidgetItem *item = new QListWidgetItem();
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000998 item->setData(Qt::DisplayRole, (*command)[i].c_str());
chudy@google.com902ebe52012-06-29 14:21:22 +0000999 item->setData(Qt::UserRole + 1, counter++);
robertphillips@google.com30d35f22012-11-06 16:45:36 +00001000
robertphillips@google.com0a4805e2013-05-29 13:24:23 +00001001 if (0 == strcmp("Restore", (*command)[i].c_str()) ||
commit-bot@chromium.org210ae2a2014-02-27 17:40:13 +00001002 0 == strcmp("EndCommentGroup", (*command)[i].c_str()) ||
1003 0 == strcmp("PopCull", (*command)[i].c_str())) {
robertphillips@google.com30d35f22012-11-06 16:45:36 +00001004 indent -= 10;
1005 }
1006
1007 item->setData(Qt::UserRole + 3, indent);
1008
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +00001009 if (0 == strcmp("Save", (*command)[i].c_str()) ||
robertphillips@google.com0a4805e2013-05-29 13:24:23 +00001010 0 == strcmp("Save Layer", (*command)[i].c_str()) ||
commit-bot@chromium.org210ae2a2014-02-27 17:40:13 +00001011 0 == strcmp("BeginCommentGroup", (*command)[i].c_str()) ||
1012 0 == strcmp("PushCull", (*command)[i].c_str())) {
robertphillips@google.com30d35f22012-11-06 16:45:36 +00001013 indent += 10;
1014 }
1015
robertphillips@google.comd26c7062012-11-12 20:42:12 +00001016 item->setData(Qt::UserRole + 4, -1.0);
1017
chudy@google.comc432f002012-07-10 13:19:25 +00001018 fListWidget.addItem(item);
chudy@google.com902ebe52012-06-29 14:21:22 +00001019 }
1020}
1021
skia.committer@gmail.com91274b92013-03-13 07:01:04 +00001022void SkDebuggerGUI::setupOverviewText(const SkTDArray<double>* typeTimes,
robertphillips@google.come428f9b2013-03-12 15:33:40 +00001023 double totTime,
1024 int numRuns) {
borenet@google.com2d9dbd42013-03-12 13:07:40 +00001025 SkString overview;
robertphillips@google.come428f9b2013-03-12 15:33:40 +00001026 fDebugger.getOverviewText(typeTimes, totTime, &overview, numRuns);
borenet@google.com2d9dbd42013-03-12 13:07:40 +00001027 fInspectorWidget.setText(overview.c_str(), SkInspectorWidget::kOverview_TabType);
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +00001028}
1029
1030void SkDebuggerGUI::setupComboBox(SkTArray<SkString>* command) {
1031 fFilter.clear();
1032 fFilter.addItem("--Filter By Available Commands--");
1033
1034 std::map<std::string, int> map;
1035 for (int i = 0; i < command->count(); i++) {
1036 map[(*command)[i].c_str()]++;
1037 }
1038
skia.committer@gmail.com34587162012-11-20 02:01:23 +00001039 for (std::map<std::string, int>::iterator it = map.begin(); it != map.end();
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +00001040 ++it) {
1041 fFilter.addItem((it->first).c_str());
1042 }
chudy@google.com902ebe52012-06-29 14:21:22 +00001043
1044 // NOTE(chudy): Makes first item unselectable.
chudy@google.com7dcae672012-07-09 20:26:53 +00001045 QStandardItemModel* model = qobject_cast<QStandardItemModel*>(
chudy@google.comc432f002012-07-10 13:19:25 +00001046 fFilter.model());
1047 QModelIndex firstIndex = model->index(0, fFilter.modelColumn(),
1048 fFilter.rootModelIndex());
chudy@google.com902ebe52012-06-29 14:21:22 +00001049 QStandardItem* firstItem = model->itemFromIndex(firstIndex);
1050 firstItem->setSelectable(false);
1051}