blob: 619aa0ac9284cc45a8628ea2408cdb9c764b6562 [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;
commit-bot@chromium.org6f4fb0f2014-03-03 19:18:39 +0000265 if (!InternalOnly_StreamIsSKP(stream, &info)) {
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000266 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
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000322 renderer->init(pict, NULL, NULL, false);
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000323
324 renderer->setup();
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000325 renderer->render();
commit-bot@chromium.org51c040e2014-03-11 22:58:00 +0000326 renderer->resetState(true); // flush, swapBuffers and Finish
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();
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000333 renderer->render();
commit-bot@chromium.org51c040e2014-03-11 22:58:00 +0000334 renderer->resetState(false); // flush & swapBuffers, but don't Finish
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000335 }
commit-bot@chromium.org51c040e2014-03-11 22:58:00 +0000336 renderer->resetState(true); // flush, swapBuffers and Finish
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000337
338 renderer->end();
339}
340
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000341void SkDebuggerGUI::actionProfile() {
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000342 // In order to profile we pass the command offsets (that were read-in
343 // in loadPicture by the SkOffsetPicture) to an SkTimedPlaybackPicture.
skia.committer@gmail.com884e60b2012-11-16 02:01:17 +0000344 // The SkTimedPlaybackPicture in turn passes the offsets to an
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000345 // SkTimedPicturePlayback object which uses them to track the performance
346 // of individual commands.
347 if (fFileName.isEmpty()) {
348 return;
349 }
350
351 SkFILEStream inputStream;
352
353 inputStream.setPath(fFileName.c_str());
354 if (!inputStream.isValid()) {
355 return;
356 }
357
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000358 SkAutoTUnref<SkTimedPicture> picture(SkTimedPicture::CreateTimedPicture(&inputStream,
359 &SkImageDecoder::DecodeMemory, fSkipCommands));
360 if (NULL == picture.get()) {
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000361 return;
362 }
363
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000364 // For now this #if allows switching between tiled and simple rendering
365 // modes. Eventually this will be accomplished via the GUI
robertphillips@google.come174a8b2012-11-27 16:04:42 +0000366#if 0
367 // With the current batch of SysTimers, profiling in tiled mode
368 // gets swamped by the timing overhead:
369 //
370 // tile mode simple mode
371 // debugger 64.2ms 12.8ms
372 // bench_pictures 16.9ms 12.4ms
373 //
374 // This is b.c. in tiled mode each command is called many more times
375 // but typically does less work on each invocation (due to clipping)
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000376 sk_tools::TiledPictureRenderer* renderer = NULL;
377
378 renderer = SkNEW(sk_tools::TiledPictureRenderer);
379 renderer->setTileWidth(256);
380 renderer->setTileHeight(256);
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000381#else
382 sk_tools::SimplePictureRenderer* renderer = NULL;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000383
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000384 renderer = SkNEW(sk_tools::SimplePictureRenderer);
robertphillips@google.com1447aa32013-01-30 21:09:09 +0000385
386#if SK_SUPPORT_GPU
commit-bot@chromium.orgfde1e7c2013-08-02 13:59:50 +0000387 if (fSettingsWidget.isGLActive()) {
robertphillips@google.com1447aa32013-01-30 21:09:09 +0000388 renderer->setDeviceType(sk_tools::PictureRenderer::kGPU_DeviceType);
commit-bot@chromium.orgfde1e7c2013-08-02 13:59:50 +0000389 renderer->setSampleCount(fSettingsWidget.getGLSampleCount());
robertphillips@google.com1447aa32013-01-30 21:09:09 +0000390 }
391#endif
392
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000393#endif
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000394
robertphillips@google.come174a8b2012-11-27 16:04:42 +0000395 static const int kNumRepeats = 10;
396
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000397 run(picture.get(), renderer, kNumRepeats);
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000398
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000399 SkASSERT(picture->count() == fListWidget.count());
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000400
401 // extract the individual command times from the SkTimedPlaybackPicture
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000402 for (int i = 0; i < picture->count(); ++i) {
403 double temp = picture->time(i);
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000404
405 QListWidgetItem* item = fListWidget.item(i);
406
407 item->setData(Qt::UserRole + 4, 100.0*temp);
408 }
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000409
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000410 setupOverviewText(picture->typeTimes(), picture->totTime(), kNumRepeats);
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000411}
412
chudy@google.com902ebe52012-06-29 14:21:22 +0000413void SkDebuggerGUI::actionCancel() {
chudy@google.comc432f002012-07-10 13:19:25 +0000414 for (int row = 0; row < fListWidget.count(); row++) {
415 fListWidget.item(row)->setHidden(false);
chudy@google.com902ebe52012-06-29 14:21:22 +0000416 }
417}
418
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000419void SkDebuggerGUI::actionClearBreakpoints() {
420 for (int row = 0; row < fListWidget.count(); row++) {
421 QListWidgetItem* item = fListWidget.item(row);
422 item->setCheckState(Qt::Unchecked);
423 item->setData(Qt::DecorationRole,
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000424 QPixmap(":/blank.png"));
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000425 }
426}
427
428void SkDebuggerGUI::actionClearDeletes() {
429 for (int row = 0; row < fListWidget.count(); row++) {
430 QListWidgetItem* item = fListWidget.item(row);
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000431 item->setData(Qt::UserRole + 2, QPixmap(":/blank.png"));
chudy@google.com607357f2012-08-07 16:12:23 +0000432 fDebugger.setCommandVisible(row, true);
robertphillips@google.com5f971142012-12-07 20:48:56 +0000433 fSkipCommands[row] = false;
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000434 }
435 if (fPause) {
436 fCanvasWidget.drawTo(fPausedRow);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000437 fImageWidget.draw();
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000438 } else {
439 fCanvasWidget.drawTo(fListWidget.currentRow());
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000440 fImageWidget.draw();
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000441 }
442}
443
chudy@google.com902ebe52012-06-29 14:21:22 +0000444void SkDebuggerGUI::actionCommandFilter() {
commit-bot@chromium.org22d39332013-11-21 15:37:29 +0000445 fDebugger.highlightCurrentCommand(fSettingsWidget.getVisibilityFilter());
chudy@google.comc432f002012-07-10 13:19:25 +0000446 fCanvasWidget.drawTo(fListWidget.currentRow());
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000447 fImageWidget.draw();
chudy@google.com902ebe52012-06-29 14:21:22 +0000448}
449
450void SkDebuggerGUI::actionClose() {
451 this->close();
452}
453
454void SkDebuggerGUI::actionDelete() {
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000455
robertphillips@google.comdd4b7452013-01-22 19:38:46 +0000456 for (int row = 0; row < fListWidget.count(); ++row) {
457 QListWidgetItem* item = fListWidget.item(row);
458
459 if (!item->isSelected()) {
460 continue;
461 }
462
463 if (fDebugger.isCommandVisible(row)) {
464 item->setData(Qt::UserRole + 2, QPixmap(":/delete.png"));
465 fDebugger.setCommandVisible(row, false);
466 fSkipCommands[row] = true;
467 } else {
468 item->setData(Qt::UserRole + 2, QPixmap(":/blank.png"));
469 fDebugger.setCommandVisible(row, true);
470 fSkipCommands[row] = false;
471 }
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000472 }
473
robertphillips@google.comdd4b7452013-01-22 19:38:46 +0000474 int currentRow = fListWidget.currentRow();
475
chudy@google.come504de02012-07-16 18:35:23 +0000476 if (fPause) {
477 fCanvasWidget.drawTo(fPausedRow);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000478 fImageWidget.draw();
chudy@google.come504de02012-07-16 18:35:23 +0000479 } else {
480 fCanvasWidget.drawTo(currentRow);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000481 fImageWidget.draw();
chudy@google.come504de02012-07-16 18:35:23 +0000482 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000483}
484
robertphillips@google.come8fe4bc2013-02-13 13:26:13 +0000485#if SK_SUPPORT_GPU
commit-bot@chromium.orgfde1e7c2013-08-02 13:59:50 +0000486void SkDebuggerGUI::actionGLWidget() {
487 bool isToggled = fSettingsWidget.isGLActive();
488 if (isToggled) {
489 fCanvasWidget.setGLSampleCount(fSettingsWidget.getGLSampleCount());
490 }
chudy@google.comea5488b2012-07-26 19:38:22 +0000491 fCanvasWidget.setWidgetVisibility(SkCanvasWidget::kGPU_WidgetType, !isToggled);
492}
robertphillips@google.come8fe4bc2013-02-13 13:26:13 +0000493#endif
chudy@google.comea5488b2012-07-26 19:38:22 +0000494
chudy@google.com902ebe52012-06-29 14:21:22 +0000495void SkDebuggerGUI::actionInspector() {
chudy@google.comc432f002012-07-10 13:19:25 +0000496 if (fInspectorWidget.isHidden()) {
497 fInspectorWidget.setHidden(false);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000498 fImageWidget.setHidden(false);
chudy@google.com902ebe52012-06-29 14:21:22 +0000499 } else {
chudy@google.comc432f002012-07-10 13:19:25 +0000500 fInspectorWidget.setHidden(true);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000501 fImageWidget.setHidden(true);
chudy@google.com902ebe52012-06-29 14:21:22 +0000502 }
503}
504
505void SkDebuggerGUI::actionPlay() {
chudy@google.comc432f002012-07-10 13:19:25 +0000506 for (int row = fListWidget.currentRow() + 1; row < fListWidget.count();
chudy@google.com7dcae672012-07-09 20:26:53 +0000507 row++) {
chudy@google.comc432f002012-07-10 13:19:25 +0000508 QListWidgetItem *item = fListWidget.item(row);
chudy@google.com902ebe52012-06-29 14:21:22 +0000509 if (item->checkState() == Qt::Checked) {
chudy@google.comc432f002012-07-10 13:19:25 +0000510 fListWidget.setCurrentItem(item);
chudy@google.com902ebe52012-06-29 14:21:22 +0000511 return;
512 }
513 }
chudy@google.comc432f002012-07-10 13:19:25 +0000514 fListWidget.setCurrentRow(fListWidget.count() - 1);
chudy@google.com902ebe52012-06-29 14:21:22 +0000515}
516
chudy@google.comea5488b2012-07-26 19:38:22 +0000517void SkDebuggerGUI::actionRasterWidget(bool isToggled) {
518 fCanvasWidget.setWidgetVisibility(SkCanvasWidget::kRaster_8888_WidgetType, !isToggled);
519}
520
robertphillips@google.comf4741c12013-02-06 20:13:54 +0000521void SkDebuggerGUI::actionOverdrawVizWidget(bool isToggled) {
522 fDebugger.setOverdrawViz(isToggled);
523 fCanvasWidget.update();
524}
525
commit-bot@chromium.org768ac852014-03-03 16:32:17 +0000526void SkDebuggerGUI::actionMegaVizWidget(bool isToggled) {
527 fDebugger.setMegaViz(isToggled);
528 fCanvasWidget.update();
529}
530
robertphillips@google.com32bbcf82013-10-17 17:56:10 +0000531void SkDebuggerGUI::actionTextureFilter() {
532 SkPaint::FilterLevel level;
533 bool enabled = fSettingsWidget.getFilterOverride(&level);
534 fDebugger.setTexFilterOverride(enabled, level);
535 fCanvasWidget.update();
536}
537
chudy@google.com902ebe52012-06-29 14:21:22 +0000538void SkDebuggerGUI::actionRewind() {
chudy@google.come504de02012-07-16 18:35:23 +0000539 fListWidget.setCurrentRow(0);
chudy@google.com902ebe52012-06-29 14:21:22 +0000540}
541
chudy@google.com0ab03392012-07-28 20:16:11 +0000542void SkDebuggerGUI::actionSave() {
robertphillips@google.come219baf2013-01-28 19:25:43 +0000543 fFileName = fPath.toAscii().data();
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000544 fFileName.append("/");
robertphillips@google.come219baf2013-01-28 19:25:43 +0000545 fFileName.append(fDirectoryWidget.currentItem()->text().toAscii().data());
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000546 saveToFile(fFileName);
chudy@google.com0ab03392012-07-28 20:16:11 +0000547}
548
549void SkDebuggerGUI::actionSaveAs() {
550 QString filename = QFileDialog::getSaveFileName(this, "Save File", "",
551 "Skia Picture (*skp)");
chudy@google.com38b08ce2012-07-28 23:26:10 +0000552 if (!filename.endsWith(".skp", Qt::CaseInsensitive)) {
chudy@google.com0ab03392012-07-28 20:16:11 +0000553 filename.append(".skp");
554 }
djsollen@google.comc3c82162012-11-13 18:35:10 +0000555 saveToFile(SkString(filename.toAscii().data()));
chudy@google.com0ab03392012-07-28 20:16:11 +0000556}
557
chudy@google.com7dcae672012-07-09 20:26:53 +0000558void SkDebuggerGUI::actionScale(float scaleFactor) {
chudy@google.comc432f002012-07-10 13:19:25 +0000559 fSettingsWidget.setZoomText(scaleFactor);
chudy@google.com7dcae672012-07-09 20:26:53 +0000560}
561
chudy@google.com902ebe52012-06-29 14:21:22 +0000562void SkDebuggerGUI::actionSettings() {
chudy@google.comc432f002012-07-10 13:19:25 +0000563 if (fSettingsWidget.isHidden()) {
564 fSettingsWidget.setHidden(false);
chudy@google.com902ebe52012-06-29 14:21:22 +0000565 } else {
chudy@google.comc432f002012-07-10 13:19:25 +0000566 fSettingsWidget.setHidden(true);
chudy@google.com902ebe52012-06-29 14:21:22 +0000567 }
568}
569
570void SkDebuggerGUI::actionStepBack() {
chudy@google.comc432f002012-07-10 13:19:25 +0000571 int currentRow = fListWidget.currentRow();
chudy@google.com902ebe52012-06-29 14:21:22 +0000572 if (currentRow != 0) {
chudy@google.comc432f002012-07-10 13:19:25 +0000573 fListWidget.setCurrentRow(currentRow - 1);
chudy@google.com902ebe52012-06-29 14:21:22 +0000574 }
575}
576
577void SkDebuggerGUI::actionStepForward() {
chudy@google.comc432f002012-07-10 13:19:25 +0000578 int currentRow = fListWidget.currentRow();
chudy@google.com902ebe52012-06-29 14:21:22 +0000579 QString curRow = QString::number(currentRow);
chudy@google.comc432f002012-07-10 13:19:25 +0000580 QString curCount = QString::number(fListWidget.count());
581 if (currentRow < fListWidget.count() - 1) {
582 fListWidget.setCurrentRow(currentRow + 1);
chudy@google.com902ebe52012-06-29 14:21:22 +0000583 }
584}
585
chudy@google.coma9e937c2012-08-03 17:32:05 +0000586void SkDebuggerGUI::drawComplete() {
chudy@google.com607357f2012-08-07 16:12:23 +0000587 fInspectorWidget.setMatrix(fDebugger.getCurrentMatrix());
588 fInspectorWidget.setClip(fDebugger.getCurrentClip());
chudy@google.coma9e937c2012-08-03 17:32:05 +0000589}
590
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000591void SkDebuggerGUI::saveToFile(const SkString& filename) {
592 SkFILEWStream file(filename.c_str());
robertphillips@google.com25bc2f82013-01-22 18:03:56 +0000593 SkAutoTUnref<SkPicture> copy(fDebugger.copyPicture());
594
595 copy->serialize(&file);
chudy@google.com0ab03392012-07-28 20:16:11 +0000596}
597
chudy@google.com902ebe52012-06-29 14:21:22 +0000598void SkDebuggerGUI::loadFile(QListWidgetItem *item) {
599 if (fDirectoryWidgetActive) {
robertphillips@google.come219baf2013-01-28 19:25:43 +0000600 fFileName = fPath.toAscii().data();
jvanverth@google.com0ac6f162013-02-05 19:44:07 +0000601 // don't add a '/' to files in the local directory
602 if (fFileName.size() > 0) {
603 fFileName.append("/");
604 }
robertphillips@google.come219baf2013-01-28 19:25:43 +0000605 fFileName.append(item->text().toAscii().data());
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000606 loadPicture(fFileName);
chudy@google.com902ebe52012-06-29 14:21:22 +0000607 }
608}
609
610void SkDebuggerGUI::openFile() {
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000611 QString temp = QFileDialog::getOpenFileName(this, tr("Open File"), "",
chudy@google.com7dcae672012-07-09 20:26:53 +0000612 tr("Files (*.*)"));
robertphillips@google.comff6e6ba2013-01-28 17:43:26 +0000613 openFile(temp);
614}
615
616void SkDebuggerGUI::openFile(const QString &filename) {
chudy@google.com902ebe52012-06-29 14:21:22 +0000617 fDirectoryWidgetActive = false;
robertphillips@google.comff6e6ba2013-01-28 17:43:26 +0000618 if (!filename.isEmpty()) {
619 QFileInfo pathInfo(filename);
620 loadPicture(SkString(filename.toAscii().data()));
621 setupDirectoryWidget(pathInfo.path());
chudy@google.com902ebe52012-06-29 14:21:22 +0000622 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000623 fDirectoryWidgetActive = true;
624}
625
chudy@google.comc432f002012-07-10 13:19:25 +0000626void SkDebuggerGUI::pauseDrawing(bool isPaused) {
chudy@google.com607357f2012-08-07 16:12:23 +0000627 fPause = isPaused;
628 fPausedRow = fListWidget.currentRow();
629 fCanvasWidget.drawTo(fPausedRow);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000630 fImageWidget.draw();
chudy@google.com7dcae672012-07-09 20:26:53 +0000631}
632
chudy@google.com902ebe52012-06-29 14:21:22 +0000633void SkDebuggerGUI::registerListClick(QListWidgetItem *item) {
chudy@google.comd3058f52012-07-19 13:41:27 +0000634 if(!fLoading) {
635 int currentRow = fListWidget.currentRow();
chudy@google.comd3058f52012-07-19 13:41:27 +0000636
chudy@google.comea5488b2012-07-26 19:38:22 +0000637 if (currentRow != -1) {
638 if (!fPause) {
639 fCanvasWidget.drawTo(currentRow);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000640 fImageWidget.draw();
chudy@google.comd3058f52012-07-19 13:41:27 +0000641 }
chudy@google.com97cee972012-08-07 20:41:37 +0000642 SkTDArray<SkString*> *currInfo = fDebugger.getCommandInfo(
chudy@google.comea5488b2012-07-26 19:38:22 +0000643 currentRow);
644
645 /* TODO(chudy): Add command type before parameters. Rename v
646 * to something more informative. */
chudy@google.com97cee972012-08-07 20:41:37 +0000647 if (currInfo) {
chudy@google.comea5488b2012-07-26 19:38:22 +0000648 QString info;
649 info.append("<b>Parameters: </b><br/>");
chudy@google.com97cee972012-08-07 20:41:37 +0000650 for (int i = 0; i < currInfo->count(); i++) {
651
652 info.append(QString((*currInfo)[i]->c_str()));
chudy@google.comea5488b2012-07-26 19:38:22 +0000653 info.append("<br/>");
654 }
chudy@google.com6bd109a2012-08-14 19:34:13 +0000655 fInspectorWidget.setText(info, SkInspectorWidget::kDetail_TabType);
chudy@google.comea5488b2012-07-26 19:38:22 +0000656 fInspectorWidget.setDisabled(false);
chudy@google.comea5488b2012-07-26 19:38:22 +0000657 }
chudy@google.comd3058f52012-07-19 13:41:27 +0000658 }
chudy@google.comea5488b2012-07-26 19:38:22 +0000659
chudy@google.com902ebe52012-06-29 14:21:22 +0000660 }
661}
662
chudy@google.com9ca9bfe2012-07-12 21:58:14 +0000663void SkDebuggerGUI::selectCommand(int command) {
664 if (fPause) {
665 fListWidget.setCurrentRow(command);
666 }
667}
668
chudy@google.com902ebe52012-06-29 14:21:22 +0000669void SkDebuggerGUI::toggleBreakpoint() {
chudy@google.comc432f002012-07-10 13:19:25 +0000670 QListWidgetItem* item = fListWidget.currentItem();
chudy@google.com902ebe52012-06-29 14:21:22 +0000671 if (item->checkState() == Qt::Unchecked) {
672 item->setCheckState(Qt::Checked);
chudy@google.come565de42012-07-12 14:15:54 +0000673 item->setData(Qt::DecorationRole,
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000674 QPixmap(":/breakpoint_16x16.png"));
chudy@google.com902ebe52012-06-29 14:21:22 +0000675 } else {
chudy@google.com902ebe52012-06-29 14:21:22 +0000676 item->setCheckState(Qt::Unchecked);
chudy@google.come565de42012-07-12 14:15:54 +0000677 item->setData(Qt::DecorationRole,
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000678 QPixmap(":/blank.png"));
chudy@google.com902ebe52012-06-29 14:21:22 +0000679 }
680}
681
682void SkDebuggerGUI::toggleDirectory() {
chudy@google.com607357f2012-08-07 16:12:23 +0000683 fDirectoryWidget.setHidden(!fDirectoryWidget.isHidden());
chudy@google.com902ebe52012-06-29 14:21:22 +0000684}
685
686void SkDebuggerGUI::toggleFilter(QString string) {
chudy@google.comc432f002012-07-10 13:19:25 +0000687 for (int row = 0; row < fListWidget.count(); row++) {
688 QListWidgetItem *item = fListWidget.item(row);
chudy@google.com607357f2012-08-07 16:12:23 +0000689 item->setHidden(item->text() != string);
chudy@google.com902ebe52012-06-29 14:21:22 +0000690 }
691}
692
693void SkDebuggerGUI::setupUi(QMainWindow *SkDebuggerGUI) {
694 QIcon windowIcon;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000695 windowIcon.addFile(QString::fromUtf8(":/skia.png"), QSize(),
chudy@google.com7dcae672012-07-09 20:26:53 +0000696 QIcon::Normal, QIcon::Off);
chudy@google.com902ebe52012-06-29 14:21:22 +0000697 SkDebuggerGUI->setObjectName(QString::fromUtf8("SkDebuggerGUI"));
698 SkDebuggerGUI->resize(1200, 1000);
699 SkDebuggerGUI->setWindowIcon(windowIcon);
chudy@google.comc432f002012-07-10 13:19:25 +0000700 SkDebuggerGUI->setWindowTitle("Skia Debugger");
chudy@google.com902ebe52012-06-29 14:21:22 +0000701
chudy@google.come504de02012-07-16 18:35:23 +0000702 fActionOpen.setShortcuts(QKeySequence::Open);
chudy@google.comc432f002012-07-10 13:19:25 +0000703 fActionOpen.setText("Open");
chudy@google.com902ebe52012-06-29 14:21:22 +0000704
705 QIcon breakpoint;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000706 breakpoint.addFile(QString::fromUtf8(":/breakpoint.png"),
chudy@google.com7dcae672012-07-09 20:26:53 +0000707 QSize(), QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000708 fActionBreakpoint.setShortcut(QKeySequence(tr("Ctrl+B")));
chudy@google.comc432f002012-07-10 13:19:25 +0000709 fActionBreakpoint.setIcon(breakpoint);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000710 fActionBreakpoint.setText("Breakpoints");
chudy@google.com902ebe52012-06-29 14:21:22 +0000711
712 QIcon cancel;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000713 cancel.addFile(QString::fromUtf8(":/reload.png"), QSize(),
chudy@google.com7dcae672012-07-09 20:26:53 +0000714 QIcon::Normal, QIcon::Off);
chudy@google.comc432f002012-07-10 13:19:25 +0000715 fActionCancel.setIcon(cancel);
716 fActionCancel.setText("Clear Filter");
chudy@google.com902ebe52012-06-29 14:21:22 +0000717
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000718 fActionClearBreakpoints.setShortcut(QKeySequence(tr("Alt+B")));
719 fActionClearBreakpoints.setText("Clear Breakpoints");
720
721 fActionClearDeletes.setShortcut(QKeySequence(tr("Alt+X")));
722 fActionClearDeletes.setText("Clear Deletes");
723
chudy@google.come504de02012-07-16 18:35:23 +0000724 fActionClose.setShortcuts(QKeySequence::Quit);
chudy@google.comc432f002012-07-10 13:19:25 +0000725 fActionClose.setText("Exit");
chudy@google.com902ebe52012-06-29 14:21:22 +0000726
chudy@google.come504de02012-07-16 18:35:23 +0000727 fActionCreateBreakpoint.setShortcut(QKeySequence(tr("B")));
728 fActionCreateBreakpoint.setText("Set Breakpoint");
729
730 fActionDelete.setShortcut(QKeySequence(tr("X")));
chudy@google.comc432f002012-07-10 13:19:25 +0000731 fActionDelete.setText("Delete Command");
chudy@google.com902ebe52012-06-29 14:21:22 +0000732
chudy@google.come504de02012-07-16 18:35:23 +0000733 fActionDirectory.setShortcut(QKeySequence(tr("Ctrl+D")));
734 fActionDirectory.setText("Directory");
chudy@google.com902ebe52012-06-29 14:21:22 +0000735
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000736 QIcon profile;
robertphillips@google.comd1636362012-11-19 18:25:09 +0000737 profile.addFile(QString::fromUtf8(":/profile.png"), QSize(),
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000738 QIcon::Normal, QIcon::Off);
739 fActionProfile.setIcon(profile);
740 fActionProfile.setText("Profile");
robertphillips@google.come099bc42012-11-19 16:26:40 +0000741 fActionProfile.setDisabled(true);
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000742
chudy@google.comc432f002012-07-10 13:19:25 +0000743 QIcon inspector;
robertphillips@google.comd1636362012-11-19 18:25:09 +0000744 inspector.addFile(QString::fromUtf8(":/inspector.png"),
chudy@google.comc432f002012-07-10 13:19:25 +0000745 QSize(), QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000746 fActionInspector.setShortcut(QKeySequence(tr("Ctrl+I")));
chudy@google.comc432f002012-07-10 13:19:25 +0000747 fActionInspector.setIcon(inspector);
chudy@google.come504de02012-07-16 18:35:23 +0000748 fActionInspector.setText("Inspector");
chudy@google.com902ebe52012-06-29 14:21:22 +0000749
bungeman@google.com2ff6d1d2013-07-01 14:24:12 +0000750 QIcon settings;
751 settings.addFile(QString::fromUtf8(":/inspector.png"),
752 QSize(), QIcon::Normal, QIcon::Off);
753 fActionSettings.setShortcut(QKeySequence(tr("Ctrl+G")));
754 fActionSettings.setIcon(settings);
755 fActionSettings.setText("Settings");
skia.committer@gmail.com0d55dd72013-07-02 07:00:59 +0000756
chudy@google.comc432f002012-07-10 13:19:25 +0000757 QIcon play;
robertphillips@google.comd1636362012-11-19 18:25:09 +0000758 play.addFile(QString::fromUtf8(":/play.png"), QSize(),
chudy@google.comc432f002012-07-10 13:19:25 +0000759 QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000760 fActionPlay.setShortcut(QKeySequence(tr("Ctrl+P")));
chudy@google.comc432f002012-07-10 13:19:25 +0000761 fActionPlay.setIcon(play);
762 fActionPlay.setText("Play");
chudy@google.com902ebe52012-06-29 14:21:22 +0000763
chudy@google.come504de02012-07-16 18:35:23 +0000764 QIcon pause;
robertphillips@google.comd1636362012-11-19 18:25:09 +0000765 pause.addFile(QString::fromUtf8(":/pause.png"), QSize(),
chudy@google.comc432f002012-07-10 13:19:25 +0000766 QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000767 fActionPause.setShortcut(QKeySequence(tr("Space")));
768 fActionPause.setCheckable(true);
769 fActionPause.setIcon(pause);
770 fActionPause.setText("Pause");
771
chudy@google.comc432f002012-07-10 13:19:25 +0000772 QIcon rewind;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000773 rewind.addFile(QString::fromUtf8(":/rewind.png"), QSize(),
chudy@google.comc432f002012-07-10 13:19:25 +0000774 QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000775 fActionRewind.setShortcut(QKeySequence(tr("Ctrl+R")));
chudy@google.comc432f002012-07-10 13:19:25 +0000776 fActionRewind.setIcon(rewind);
777 fActionRewind.setText("Rewind");
chudy@google.com902ebe52012-06-29 14:21:22 +0000778
chudy@google.com0ab03392012-07-28 20:16:11 +0000779 fActionSave.setShortcut(QKeySequence::Save);
780 fActionSave.setText("Save");
781 fActionSave.setDisabled(true);
782 fActionSaveAs.setShortcut(QKeySequence::SaveAs);
783 fActionSaveAs.setText("Save As");
784 fActionSaveAs.setDisabled(true);
785
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000786 fActionShowDeletes.setShortcut(QKeySequence(tr("Ctrl+X")));
787 fActionShowDeletes.setText("Deleted Commands");
788
chudy@google.comc432f002012-07-10 13:19:25 +0000789 QIcon stepBack;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000790 stepBack.addFile(QString::fromUtf8(":/previous.png"), QSize(),
chudy@google.comc432f002012-07-10 13:19:25 +0000791 QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000792 fActionStepBack.setShortcut(QKeySequence(tr("[")));
chudy@google.comc432f002012-07-10 13:19:25 +0000793 fActionStepBack.setIcon(stepBack);
794 fActionStepBack.setText("Step Back");
chudy@google.com902ebe52012-06-29 14:21:22 +0000795
chudy@google.comc432f002012-07-10 13:19:25 +0000796 QIcon stepForward;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000797 stepForward.addFile(QString::fromUtf8(":/next.png"),
chudy@google.comc432f002012-07-10 13:19:25 +0000798 QSize(), QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000799 fActionStepForward.setShortcut(QKeySequence(tr("]")));
chudy@google.comc432f002012-07-10 13:19:25 +0000800 fActionStepForward.setIcon(stepForward);
801 fActionStepForward.setText("Step Forward");
802
chudy@google.coma1226312012-07-26 20:26:44 +0000803 fActionZoomIn.setShortcut(QKeySequence(tr("Ctrl+=")));
804 fActionZoomIn.setText("Zoom In");
805 fActionZoomOut.setShortcut(QKeySequence(tr("Ctrl+-")));
806 fActionZoomOut.setText("Zoom Out");
807
chudy@google.comc432f002012-07-10 13:19:25 +0000808 fListWidget.setItemDelegate(new SkListWidget(&fListWidget));
809 fListWidget.setObjectName(QString::fromUtf8("listWidget"));
commit-bot@chromium.orgbcd431e2013-11-21 13:41:37 +0000810 fListWidget.setMinimumWidth(250);
chudy@google.comc432f002012-07-10 13:19:25 +0000811
812 fFilter.addItem("--Filter By Available Commands--");
813
commit-bot@chromium.orgbcd431e2013-11-21 13:41:37 +0000814 fDirectoryWidget.setMinimumWidth(250);
chudy@google.comc432f002012-07-10 13:19:25 +0000815 fDirectoryWidget.setStyleSheet("QListWidget::Item {padding: 5px;}");
816
817 fCanvasWidget.setSizePolicy(QSizePolicy::Expanding,
chudy@google.com7dcae672012-07-09 20:26:53 +0000818 QSizePolicy::Expanding);
chudy@google.com902ebe52012-06-29 14:21:22 +0000819
skia.committer@gmail.com1c9c0d32012-11-22 02:02:41 +0000820 fImageWidget.setFixedSize(SkImageWidget::kImageWidgetWidth,
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000821 SkImageWidget::kImageWidgetHeight);
822
chudy@google.comc432f002012-07-10 13:19:25 +0000823 fInspectorWidget.setSizePolicy(QSizePolicy::Expanding,
chudy@google.com7dcae672012-07-09 20:26:53 +0000824 QSizePolicy::Expanding);
chudy@google.comc432f002012-07-10 13:19:25 +0000825 fInspectorWidget.setMaximumHeight(300);
chudy@google.com902ebe52012-06-29 14:21:22 +0000826
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000827 fSettingsAndImageLayout.setSpacing(6);
828 fSettingsAndImageLayout.addWidget(&fSettingsWidget);
829 fSettingsAndImageLayout.addWidget(&fImageWidget);
830
chudy@google.comc432f002012-07-10 13:19:25 +0000831 fSettingsWidget.setSizePolicy(QSizePolicy::Expanding,
832 QSizePolicy::Expanding);
833 fSettingsWidget.setMaximumWidth(250);
chudy@google.com902ebe52012-06-29 14:21:22 +0000834
commit-bot@chromium.orgbcd431e2013-11-21 13:41:37 +0000835 fLeftColumnSplitter.addWidget(&fListWidget);
836 fLeftColumnSplitter.addWidget(&fDirectoryWidget);
837 fLeftColumnSplitter.setOrientation(Qt::Vertical);
chudy@google.com902ebe52012-06-29 14:21:22 +0000838
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000839 fCanvasSettingsAndImageLayout.setSpacing(6);
840 fCanvasSettingsAndImageLayout.addWidget(&fCanvasWidget);
841 fCanvasSettingsAndImageLayout.addLayout(&fSettingsAndImageLayout);
842
chudy@google.comc432f002012-07-10 13:19:25 +0000843 fMainAndRightColumnLayout.setSpacing(6);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000844 fMainAndRightColumnLayout.addLayout(&fCanvasSettingsAndImageLayout);
chudy@google.comc432f002012-07-10 13:19:25 +0000845 fMainAndRightColumnLayout.addWidget(&fInspectorWidget);
commit-bot@chromium.orgbcd431e2013-11-21 13:41:37 +0000846 fMainAndRightColumnWidget.setLayout(&fMainAndRightColumnLayout);
chudy@google.com902ebe52012-06-29 14:21:22 +0000847
commit-bot@chromium.orgbcd431e2013-11-21 13:41:37 +0000848 fCentralSplitter.addWidget(&fLeftColumnSplitter);
849 fCentralSplitter.addWidget(&fMainAndRightColumnWidget);
850 fCentralSplitter.setStretchFactor(0, 0);
851 fCentralSplitter.setStretchFactor(1, 1);
chudy@google.comc432f002012-07-10 13:19:25 +0000852
commit-bot@chromium.orgbcd431e2013-11-21 13:41:37 +0000853 SkDebuggerGUI->setCentralWidget(&fCentralSplitter);
chudy@google.comc432f002012-07-10 13:19:25 +0000854 SkDebuggerGUI->setStatusBar(&fStatusBar);
855
chudy@google.come504de02012-07-16 18:35:23 +0000856 fToolBar.setIconSize(QSize(32, 32));
chudy@google.comc432f002012-07-10 13:19:25 +0000857 fToolBar.setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
858 SkDebuggerGUI->addToolBar(Qt::TopToolBarArea, &fToolBar);
chudy@google.com902ebe52012-06-29 14:21:22 +0000859
chudy@google.com0ab03392012-07-28 20:16:11 +0000860 fSpacer.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
chudy@google.com902ebe52012-06-29 14:21:22 +0000861
chudy@google.comc432f002012-07-10 13:19:25 +0000862 fToolBar.addAction(&fActionRewind);
863 fToolBar.addAction(&fActionStepBack);
chudy@google.come504de02012-07-16 18:35:23 +0000864 fToolBar.addAction(&fActionPause);
chudy@google.comc432f002012-07-10 13:19:25 +0000865 fToolBar.addAction(&fActionStepForward);
866 fToolBar.addAction(&fActionPlay);
867 fToolBar.addSeparator();
chudy@google.come504de02012-07-16 18:35:23 +0000868 fToolBar.addAction(&fActionInspector);
bungeman@google.com2ff6d1d2013-07-01 14:24:12 +0000869 fToolBar.addAction(&fActionSettings);
chudy@google.comc432f002012-07-10 13:19:25 +0000870 fToolBar.addSeparator();
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000871 fToolBar.addAction(&fActionProfile);
872
873 fToolBar.addSeparator();
chudy@google.com0ab03392012-07-28 20:16:11 +0000874 fToolBar.addWidget(&fSpacer);
chudy@google.comc432f002012-07-10 13:19:25 +0000875 fToolBar.addWidget(&fFilter);
876 fToolBar.addAction(&fActionCancel);
chudy@google.com902ebe52012-06-29 14:21:22 +0000877
878 // TODO(chudy): Remove static call.
879 fDirectoryWidgetActive = false;
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000880 fFileName = "";
robertphillips@google.comff6e6ba2013-01-28 17:43:26 +0000881 setupDirectoryWidget("");
chudy@google.com902ebe52012-06-29 14:21:22 +0000882 fDirectoryWidgetActive = true;
883
chudy@google.com902ebe52012-06-29 14:21:22 +0000884 // Menu Bar
chudy@google.comc432f002012-07-10 13:19:25 +0000885 fMenuFile.setTitle("File");
886 fMenuFile.addAction(&fActionOpen);
chudy@google.com0ab03392012-07-28 20:16:11 +0000887 fMenuFile.addAction(&fActionSave);
888 fMenuFile.addAction(&fActionSaveAs);
chudy@google.comc432f002012-07-10 13:19:25 +0000889 fMenuFile.addAction(&fActionClose);
chudy@google.come504de02012-07-16 18:35:23 +0000890
891 fMenuEdit.setTitle("Edit");
892 fMenuEdit.addAction(&fActionDelete);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000893 fMenuEdit.addAction(&fActionClearDeletes);
894 fMenuEdit.addSeparator();
chudy@google.come504de02012-07-16 18:35:23 +0000895 fMenuEdit.addAction(&fActionCreateBreakpoint);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000896 fMenuEdit.addAction(&fActionClearBreakpoints);
chudy@google.come504de02012-07-16 18:35:23 +0000897
chudy@google.comc432f002012-07-10 13:19:25 +0000898 fMenuNavigate.setTitle("Navigate");
chudy@google.come504de02012-07-16 18:35:23 +0000899 fMenuNavigate.addAction(&fActionRewind);
900 fMenuNavigate.addAction(&fActionStepBack);
901 fMenuNavigate.addAction(&fActionStepForward);
902 fMenuNavigate.addAction(&fActionPlay);
903 fMenuNavigate.addAction(&fActionPause);
chudy@google.comc432f002012-07-10 13:19:25 +0000904 fMenuNavigate.addAction(&fActionGoToLine);
chudy@google.come504de02012-07-16 18:35:23 +0000905
chudy@google.comc432f002012-07-10 13:19:25 +0000906 fMenuView.setTitle("View");
chudy@google.come504de02012-07-16 18:35:23 +0000907 fMenuView.addAction(&fActionBreakpoint);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000908 fMenuView.addAction(&fActionShowDeletes);
chudy@google.coma1226312012-07-26 20:26:44 +0000909 fMenuView.addAction(&fActionZoomIn);
910 fMenuView.addAction(&fActionZoomOut);
chudy@google.come504de02012-07-16 18:35:23 +0000911
912 fMenuWindows.setTitle("Window");
913 fMenuWindows.addAction(&fActionInspector);
bungeman@google.com2ff6d1d2013-07-01 14:24:12 +0000914 fMenuWindows.addAction(&fActionSettings);
chudy@google.come504de02012-07-16 18:35:23 +0000915 fMenuWindows.addAction(&fActionDirectory);
chudy@google.comc432f002012-07-10 13:19:25 +0000916
917 fActionGoToLine.setText("Go to Line...");
918 fActionGoToLine.setDisabled(true);
919 fMenuBar.addAction(fMenuFile.menuAction());
chudy@google.come504de02012-07-16 18:35:23 +0000920 fMenuBar.addAction(fMenuEdit.menuAction());
chudy@google.comc432f002012-07-10 13:19:25 +0000921 fMenuBar.addAction(fMenuView.menuAction());
922 fMenuBar.addAction(fMenuNavigate.menuAction());
chudy@google.come504de02012-07-16 18:35:23 +0000923 fMenuBar.addAction(fMenuWindows.menuAction());
chudy@google.com902ebe52012-06-29 14:21:22 +0000924
chudy@google.com7dcae672012-07-09 20:26:53 +0000925 fPause = false;
926
chudy@google.comc432f002012-07-10 13:19:25 +0000927 SkDebuggerGUI->setMenuBar(&fMenuBar);
chudy@google.com902ebe52012-06-29 14:21:22 +0000928 QMetaObject::connectSlotsByName(SkDebuggerGUI);
929}
930
robertphillips@google.comff6e6ba2013-01-28 17:43:26 +0000931void SkDebuggerGUI::setupDirectoryWidget(const QString& path) {
932 fPath = path;
933 QDir dir(path);
chudy@google.com902ebe52012-06-29 14:21:22 +0000934 QRegExp r(".skp");
chudy@google.comc432f002012-07-10 13:19:25 +0000935 fDirectoryWidget.clear();
936 const QStringList files = dir.entryList();
chudy@google.com902ebe52012-06-29 14:21:22 +0000937 foreach (QString f, files) {
chudy@google.com7dcae672012-07-09 20:26:53 +0000938 if (f.contains(r))
chudy@google.comc432f002012-07-10 13:19:25 +0000939 fDirectoryWidget.addItem(f);
chudy@google.com902ebe52012-06-29 14:21:22 +0000940 }
941}
942
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000943void SkDebuggerGUI::loadPicture(const SkString& fileName) {
944 fFileName = fileName;
chudy@google.comd3058f52012-07-19 13:41:27 +0000945 fLoading = true;
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000946 SkStream* stream = SkNEW_ARGS(SkFILEStream, (fileName.c_str()));
robertphillips@google.com2d40ec42013-02-07 20:39:40 +0000947
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000948 SkPicture* picture = SkPicture::CreateFromStream(stream);
robertphillips@google.com2d40ec42013-02-07 20:39:40 +0000949
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000950 if (NULL == picture) {
robertphillips@google.com2d40ec42013-02-07 20:39:40 +0000951 QMessageBox::critical(this, "Error loading file", "Couldn't read file, sorry.");
952 SkSafeUnref(stream);
953 return;
954 }
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000955
chudy@google.com686e6802012-08-14 16:00:32 +0000956 fCanvasWidget.resetWidgetTransform();
chudy@google.com607357f2012-08-07 16:12:23 +0000957 fDebugger.loadPicture(picture);
chudy@google.com4c7962e2012-08-14 19:38:31 +0000958
robertphillips@google.com6d9c92b2013-05-23 13:21:18 +0000959 fSkipCommands.setCount(fDebugger.getSize());
960 for (int i = 0; i < fSkipCommands.count(); ++i) {
robertphillips@google.com5f971142012-12-07 20:48:56 +0000961 fSkipCommands[i] = false;
962 }
963
chudy@google.com607357f2012-08-07 16:12:23 +0000964 SkSafeUnref(stream);
965 SkSafeUnref(picture);
966
chudy@google.com97cee972012-08-07 20:41:37 +0000967 // Will this automatically clear out due to nature of refcnt?
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000968 SkTArray<SkString>* commands = fDebugger.getDrawCommandsAsStrings();
chudy@google.com607357f2012-08-07 16:12:23 +0000969
robertphillips@google.com6d9c92b2013-05-23 13:21:18 +0000970 fActionProfile.setDisabled(false);
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000971
chudy@google.com7dcae672012-07-09 20:26:53 +0000972 /* fDebugCanvas is reinitialized every load picture. Need it to retain value
chudy@google.com607357f2012-08-07 16:12:23 +0000973 * of the visibility filter.
974 * TODO(chudy): This should be deprecated since fDebugger is not
975 * recreated.
976 * */
commit-bot@chromium.org22d39332013-11-21 15:37:29 +0000977 fDebugger.highlightCurrentCommand(fSettingsWidget.getVisibilityFilter());
chudy@google.com607357f2012-08-07 16:12:23 +0000978
chudy@google.com97cee972012-08-07 20:41:37 +0000979 setupListWidget(commands);
980 setupComboBox(commands);
robertphillips@google.come428f9b2013-03-12 15:33:40 +0000981 setupOverviewText(NULL, 0.0, 1);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000982 fInspectorWidget.setDisabled(false);
chudy@google.come606d6e2012-07-12 14:31:25 +0000983 fSettingsWidget.setDisabled(false);
chudy@google.comd3058f52012-07-19 13:41:27 +0000984 fMenuEdit.setDisabled(false);
985 fMenuNavigate.setDisabled(false);
986 fMenuView.setDisabled(false);
chudy@google.com0ab03392012-07-28 20:16:11 +0000987 fActionSave.setDisabled(false);
988 fActionSaveAs.setDisabled(false);
chudy@google.comd3058f52012-07-19 13:41:27 +0000989 fLoading = false;
990 actionPlay();
chudy@google.com902ebe52012-06-29 14:21:22 +0000991}
992
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000993void SkDebuggerGUI::setupListWidget(SkTArray<SkString>* command) {
chudy@google.comc432f002012-07-10 13:19:25 +0000994 fListWidget.clear();
chudy@google.com902ebe52012-06-29 14:21:22 +0000995 int counter = 0;
robertphillips@google.com30d35f22012-11-06 16:45:36 +0000996 int indent = 0;
chudy@google.com97cee972012-08-07 20:41:37 +0000997 for (int i = 0; i < command->count(); i++) {
chudy@google.com902ebe52012-06-29 14:21:22 +0000998 QListWidgetItem *item = new QListWidgetItem();
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000999 item->setData(Qt::DisplayRole, (*command)[i].c_str());
chudy@google.com902ebe52012-06-29 14:21:22 +00001000 item->setData(Qt::UserRole + 1, counter++);
robertphillips@google.com30d35f22012-11-06 16:45:36 +00001001
robertphillips@google.com0a4805e2013-05-29 13:24:23 +00001002 if (0 == strcmp("Restore", (*command)[i].c_str()) ||
commit-bot@chromium.org210ae2a2014-02-27 17:40:13 +00001003 0 == strcmp("EndCommentGroup", (*command)[i].c_str()) ||
1004 0 == strcmp("PopCull", (*command)[i].c_str())) {
robertphillips@google.com30d35f22012-11-06 16:45:36 +00001005 indent -= 10;
1006 }
1007
1008 item->setData(Qt::UserRole + 3, indent);
1009
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +00001010 if (0 == strcmp("Save", (*command)[i].c_str()) ||
robertphillips@google.com0a4805e2013-05-29 13:24:23 +00001011 0 == strcmp("Save Layer", (*command)[i].c_str()) ||
commit-bot@chromium.org210ae2a2014-02-27 17:40:13 +00001012 0 == strcmp("BeginCommentGroup", (*command)[i].c_str()) ||
1013 0 == strcmp("PushCull", (*command)[i].c_str())) {
robertphillips@google.com30d35f22012-11-06 16:45:36 +00001014 indent += 10;
1015 }
1016
robertphillips@google.comd26c7062012-11-12 20:42:12 +00001017 item->setData(Qt::UserRole + 4, -1.0);
1018
chudy@google.comc432f002012-07-10 13:19:25 +00001019 fListWidget.addItem(item);
chudy@google.com902ebe52012-06-29 14:21:22 +00001020 }
1021}
1022
skia.committer@gmail.com91274b92013-03-13 07:01:04 +00001023void SkDebuggerGUI::setupOverviewText(const SkTDArray<double>* typeTimes,
robertphillips@google.come428f9b2013-03-12 15:33:40 +00001024 double totTime,
1025 int numRuns) {
borenet@google.com2d9dbd42013-03-12 13:07:40 +00001026 SkString overview;
robertphillips@google.come428f9b2013-03-12 15:33:40 +00001027 fDebugger.getOverviewText(typeTimes, totTime, &overview, numRuns);
borenet@google.com2d9dbd42013-03-12 13:07:40 +00001028 fInspectorWidget.setText(overview.c_str(), SkInspectorWidget::kOverview_TabType);
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +00001029}
1030
1031void SkDebuggerGUI::setupComboBox(SkTArray<SkString>* command) {
1032 fFilter.clear();
1033 fFilter.addItem("--Filter By Available Commands--");
1034
1035 std::map<std::string, int> map;
1036 for (int i = 0; i < command->count(); i++) {
1037 map[(*command)[i].c_str()]++;
1038 }
1039
skia.committer@gmail.com34587162012-11-20 02:01:23 +00001040 for (std::map<std::string, int>::iterator it = map.begin(); it != map.end();
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +00001041 ++it) {
1042 fFilter.addItem((it->first).c_str());
1043 }
chudy@google.com902ebe52012-06-29 14:21:22 +00001044
1045 // NOTE(chudy): Makes first item unselectable.
chudy@google.com7dcae672012-07-09 20:26:53 +00001046 QStandardItemModel* model = qobject_cast<QStandardItemModel*>(
chudy@google.comc432f002012-07-10 13:19:25 +00001047 fFilter.model());
1048 QModelIndex firstIndex = model->index(0, fFilter.modelColumn(),
1049 fFilter.rootModelIndex());
chudy@google.com902ebe52012-06-29 14:21:22 +00001050 QStandardItem* firstItem = model->itemFromIndex(firstIndex);
1051 firstItem->setSelectable(false);
1052}