blob: e5bdf9f28e20296c88dda60678a53aac5a837678 [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)));
chudy@google.comea5488b2012-07-26 19:38:22 +0000100 connect(&fActionPause, SIGNAL(toggled(bool)), this, SLOT(pauseDrawing(bool)));
chudy@google.come504de02012-07-16 18:35:23 +0000101 connect(&fActionCreateBreakpoint, SIGNAL(activated()), this, SLOT(toggleBreakpoint()));
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000102 connect(&fActionShowDeletes, SIGNAL(triggered()), this, SLOT(showDeletes()));
chudy@google.comea5488b2012-07-26 19:38:22 +0000103 connect(&fCanvasWidget, SIGNAL(hitChanged(int)), this, SLOT(selectCommand(int)));
104 connect(&fCanvasWidget, SIGNAL(hitChanged(int)), &fSettingsWidget, SLOT(updateHit(int)));
105 connect(&fCanvasWidget, SIGNAL(scaleFactorChanged(float)), this, SLOT(actionScale(float)));
106 connect(&fCanvasWidget, SIGNAL(commandChanged(int)), &fSettingsWidget, SLOT(updateCommand(int)));
chudy@google.com0ab03392012-07-28 20:16:11 +0000107 connect(&fActionSaveAs, SIGNAL(triggered()), this, SLOT(actionSaveAs()));
108 connect(&fActionSave, SIGNAL(triggered()), this, SLOT(actionSave()));
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000109
bungeman@google.come8cc6e82013-01-17 16:30:56 +0000110 fMapper.setMapping(&fActionZoomIn, SkCanvasWidget::kIn_ZoomCommand);
111 fMapper.setMapping(&fActionZoomOut, SkCanvasWidget::kOut_ZoomCommand);
chudy@google.coma1226312012-07-26 20:26:44 +0000112
113 connect(&fActionZoomIn, SIGNAL(triggered()), &fMapper, SLOT(map()));
114 connect(&fActionZoomOut, SIGNAL(triggered()), &fMapper, SLOT(map()));
bungeman@google.come8cc6e82013-01-17 16:30:56 +0000115 connect(&fMapper, SIGNAL(mapped(int)), &fCanvasWidget, SLOT(zoom(int)));
chudy@google.coma1226312012-07-26 20:26:44 +0000116
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000117 fInspectorWidget.setDisabled(true);
chudy@google.comd3058f52012-07-19 13:41:27 +0000118 fMenuEdit.setDisabled(true);
119 fMenuNavigate.setDisabled(true);
120 fMenuView.setDisabled(true);
chudy@google.combbad34d2012-08-13 14:26:36 +0000121
122 SkGraphics::Init();
chudy@google.com902ebe52012-06-29 14:21:22 +0000123}
124
chudy@google.combbad34d2012-08-13 14:26:36 +0000125SkDebuggerGUI::~SkDebuggerGUI() {
126 SkGraphics::Term();
127}
chudy@google.com902ebe52012-06-29 14:21:22 +0000128
129void SkDebuggerGUI::actionBreakpoints() {
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000130 fBreakpointsActivated = !fBreakpointsActivated;
chudy@google.comc432f002012-07-10 13:19:25 +0000131 for (int row = 0; row < fListWidget.count(); row++) {
132 QListWidgetItem *item = fListWidget.item(row);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000133 item->setHidden(item->checkState() == Qt::Unchecked && fBreakpointsActivated);
134 }
135}
chudy@google.com902ebe52012-06-29 14:21:22 +0000136
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000137void SkDebuggerGUI::showDeletes() {
138 fDeletesActivated = !fDeletesActivated;
139 for (int row = 0; row < fListWidget.count(); row++) {
140 QListWidgetItem *item = fListWidget.item(row);
chudy@google.com607357f2012-08-07 16:12:23 +0000141 item->setHidden(fDebugger.isCommandVisible(row)
142 && fDeletesActivated);
chudy@google.com902ebe52012-06-29 14:21:22 +0000143 }
144}
145
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000146// The timed picture playback uses the SkPicturePlayback's profiling stubs
147// to time individual commands. The offsets are needed to map SkPicture
148// offsets to individual commands.
149class SkTimedPicturePlayback : public SkPicturePlayback {
150public:
scroggo@google.com12705322013-10-01 15:30:46 +0000151 static SkTimedPicturePlayback* CreateFromStream(SkStream* stream, const SkPictInfo& info,
152 SkPicture::InstallPixelRefProc proc,
153 const SkTDArray<bool>& deletedCommands) {
154 // Mimics SkPicturePlayback::CreateFromStream
155 SkAutoTDelete<SkTimedPicturePlayback> playback(SkNEW_ARGS(SkTimedPicturePlayback,
156 (deletedCommands)));
157 if (!playback->parseStream(stream, info, proc)) {
158 return NULL; // we're invalid
159 }
160 return playback.detach();
161 }
162
163 SkTimedPicturePlayback(const SkTDArray<bool>& deletedCommands)
164 : INHERITED()
bungeman@google.come8cc6e82013-01-17 16:30:56 +0000165 , fSkipCommands(deletedCommands)
166 , fTot(0.0)
167 , fCurCommand(0) {
robertphillips@google.com6d9c92b2013-05-23 13:21:18 +0000168 fTimes.setCount(deletedCommands.count());
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000169 fTypeTimes.setCount(LAST_DRAWTYPE_ENUM+1);
170 this->resetTimes();
171 }
172
173 void resetTimes() {
robertphillips@google.com6d9c92b2013-05-23 13:21:18 +0000174 for (int i = 0; i < fTimes.count(); ++i) {
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000175 fTimes[i] = 0.0;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000176 }
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000177 for (int i = 0; i < fTypeTimes.count(); ++i) {
178 fTypeTimes[i] = 0.0f;
179 }
180 fTot = 0.0;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000181 }
182
183 int count() const { return fTimes.count(); }
184
185 double time(int index) const { return fTimes[index] / fTot; }
186
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000187 const SkTDArray<double>* typeTimes() const { return &fTypeTimes; }
188
189 double totTime() const { return fTot; }
190
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000191protected:
robertphillips@google.come174a8b2012-11-27 16:04:42 +0000192 BenchSysTimer fTimer;
robertphillips@google.com5f971142012-12-07 20:48:56 +0000193 SkTDArray<bool> fSkipCommands; // has the command been deleted in the GUI?
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000194 SkTDArray<double> fTimes; // sum of time consumed for each command
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000195 SkTDArray<double> fTypeTimes; // sum of time consumed for each type of command (e.g., drawPath)
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000196 double fTot; // total of all times in 'fTimes'
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000197 int fCurType;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000198 int fCurCommand; // the current command being executed/timed
199
robertphillips@google.com6d9c92b2013-05-23 13:21:18 +0000200#ifdef SK_DEVELOPER
201 virtual bool preDraw(int opIndex, int type) SK_OVERRIDE {
202 fCurCommand = opIndex;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000203
robertphillips@google.com5f971142012-12-07 20:48:56 +0000204 if (fSkipCommands[fCurCommand]) {
robertphillips@google.com6d9c92b2013-05-23 13:21:18 +0000205 return true;
robertphillips@google.com5f971142012-12-07 20:48:56 +0000206 }
207
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000208 fCurType = type;
209 // The SkDebugCanvas doesn't recognize these types. This class needs to
210 // convert or else we'll wind up with a mismatch between the type counts
211 // the debugger displays and the profile times.
212 if (DRAW_POS_TEXT_TOP_BOTTOM == type) {
213 fCurType = DRAW_POS_TEXT;
214 } else if (DRAW_POS_TEXT_H_TOP_BOTTOM == type) {
215 fCurType = DRAW_POS_TEXT_H;
216 }
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000217
robertphillips@google.come174a8b2012-11-27 16:04:42 +0000218#if defined(SK_BUILD_FOR_WIN32)
219 // CPU timer doesn't work well on Windows
220 fTimer.startWall();
221#else
222 fTimer.startCpu();
223#endif
robertphillips@google.com5f971142012-12-07 20:48:56 +0000224
robertphillips@google.com6d9c92b2013-05-23 13:21:18 +0000225 return false;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000226 }
227
robertphillips@google.com6d9c92b2013-05-23 13:21:18 +0000228 virtual void postDraw(int opIndex) SK_OVERRIDE {
robertphillips@google.come174a8b2012-11-27 16:04:42 +0000229#if defined(SK_BUILD_FOR_WIN32)
230 // CPU timer doesn't work well on Windows
231 double time = fTimer.endWall();
232#else
233 double time = fTimer.endCpu();
234#endif
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000235
robertphillips@google.com6d9c92b2013-05-23 13:21:18 +0000236 SkASSERT(opIndex == fCurCommand);
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000237 SkASSERT(fCurType <= LAST_DRAWTYPE_ENUM);
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000238
robertphillips@google.come174a8b2012-11-27 16:04:42 +0000239 fTimes[fCurCommand] += time;
240 fTypeTimes[fCurType] += time;
241 fTot += time;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000242 }
robertphillips@google.com6d9c92b2013-05-23 13:21:18 +0000243#endif
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000244
245private:
scroggo@google.com12705322013-10-01 15:30:46 +0000246 // SkPicturePlayback::parseStream is protected, so it can be
247 // called here, but not by our static factory function. This
248 // allows the factory function to call it.
249 bool parseStream(SkStream* stream, const SkPictInfo& info,
250 SkPicture::InstallPixelRefProc proc) {
251 return this->INHERITED::parseStream(stream, info, proc);
252 }
253
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000254 typedef SkPicturePlayback INHERITED;
255};
256
257// Wrap SkPicture to allow installation of an SkTimedPicturePlayback object
258class SkTimedPicture : public SkPicture {
259public:
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000260 static SkTimedPicture* CreateTimedPicture(SkStream* stream,
261 SkPicture::InstallPixelRefProc proc,
262 const SkTDArray<bool>& deletedCommands) {
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000263 SkPictInfo info;
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000264 if (!StreamIsSKP(stream, &info)) {
265 return NULL;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000266 }
267
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000268 SkTimedPicturePlayback* playback;
269 // Check to see if there is a playback to recreate.
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000270 if (stream->readBool()) {
scroggo@google.com12705322013-10-01 15:30:46 +0000271 playback = SkTimedPicturePlayback::CreateFromStream(stream, info, proc,
272 deletedCommands);
273 if (NULL == playback) {
274 return NULL;
275 }
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000276 } else {
277 playback = NULL;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000278 }
279
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000280 return SkNEW_ARGS(SkTimedPicture, (playback, info.fWidth, info.fHeight));
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000281 }
282
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000283 void resetTimes() { ((SkTimedPicturePlayback*) fPlayback)->resetTimes(); }
284
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000285 int count() const { return ((SkTimedPicturePlayback*) fPlayback)->count(); }
286
287 // return the fraction of the total time this command consumed
288 double time(int index) const { return ((SkTimedPicturePlayback*) fPlayback)->time(index); }
289
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000290 const SkTDArray<double>* typeTimes() const { return ((SkTimedPicturePlayback*) fPlayback)->typeTimes(); }
291
292 double totTime() const { return ((SkTimedPicturePlayback*) fPlayback)->totTime(); }
293
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000294private:
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000295 // disallow default ctor b.c. we don't have a good way to setup the fPlayback ptr
296 SkTimedPicture();
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000297 // Private ctor only used by CreateTimedPicture, which has created the playback.
298 SkTimedPicture(SkTimedPicturePlayback* playback, int width, int height)
299 : INHERITED(playback, width, height) {}
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000300 // disallow the copy ctor - enabling would require copying code from SkPicture
301 SkTimedPicture(const SkTimedPicture& src);
302
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000303 typedef SkPicture INHERITED;
304};
305
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000306// This is a simplification of PictureBenchmark's run with the addition of
307// clearing of the times after the first pass (in resetTimes)
skia.committer@gmail.com34587162012-11-20 02:01:23 +0000308void SkDebuggerGUI::run(SkTimedPicture* pict,
309 sk_tools::PictureRenderer* renderer,
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000310 int repeats) {
311 SkASSERT(pict);
312 if (NULL == pict) {
313 return;
314 }
315
316 SkASSERT(renderer != NULL);
317 if (NULL == renderer) {
318 return;
319 }
320
321 renderer->init(pict);
322
323 renderer->setup();
324 renderer->render(NULL);
jvanverth@google.comade32662013-01-28 21:09:05 +0000325 renderer->resetState(true);
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000326
327 // We throw this away the first batch of times to remove first time effects (such as paging in this program)
328 pict->resetTimes();
329
330 for (int i = 0; i < repeats; ++i) {
331 renderer->setup();
332 renderer->render(NULL);
jvanverth@google.comade32662013-01-28 21:09:05 +0000333 renderer->resetState(true);
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000334 }
335
336 renderer->end();
337}
338
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000339void SkDebuggerGUI::actionProfile() {
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000340 // In order to profile we pass the command offsets (that were read-in
341 // in loadPicture by the SkOffsetPicture) to an SkTimedPlaybackPicture.
skia.committer@gmail.com884e60b2012-11-16 02:01:17 +0000342 // The SkTimedPlaybackPicture in turn passes the offsets to an
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000343 // SkTimedPicturePlayback object which uses them to track the performance
344 // of individual commands.
345 if (fFileName.isEmpty()) {
346 return;
347 }
348
349 SkFILEStream inputStream;
350
351 inputStream.setPath(fFileName.c_str());
352 if (!inputStream.isValid()) {
353 return;
354 }
355
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000356 SkAutoTUnref<SkTimedPicture> picture(SkTimedPicture::CreateTimedPicture(&inputStream,
357 &SkImageDecoder::DecodeMemory, fSkipCommands));
358 if (NULL == picture.get()) {
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000359 return;
360 }
361
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000362 // For now this #if allows switching between tiled and simple rendering
363 // modes. Eventually this will be accomplished via the GUI
robertphillips@google.come174a8b2012-11-27 16:04:42 +0000364#if 0
365 // With the current batch of SysTimers, profiling in tiled mode
366 // gets swamped by the timing overhead:
367 //
368 // tile mode simple mode
369 // debugger 64.2ms 12.8ms
370 // bench_pictures 16.9ms 12.4ms
371 //
372 // This is b.c. in tiled mode each command is called many more times
373 // but typically does less work on each invocation (due to clipping)
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000374 sk_tools::TiledPictureRenderer* renderer = NULL;
375
376 renderer = SkNEW(sk_tools::TiledPictureRenderer);
377 renderer->setTileWidth(256);
378 renderer->setTileHeight(256);
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000379#else
380 sk_tools::SimplePictureRenderer* renderer = NULL;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000381
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000382 renderer = SkNEW(sk_tools::SimplePictureRenderer);
robertphillips@google.com1447aa32013-01-30 21:09:09 +0000383
384#if SK_SUPPORT_GPU
commit-bot@chromium.orgfde1e7c2013-08-02 13:59:50 +0000385 if (fSettingsWidget.isGLActive()) {
robertphillips@google.com1447aa32013-01-30 21:09:09 +0000386 renderer->setDeviceType(sk_tools::PictureRenderer::kGPU_DeviceType);
commit-bot@chromium.orgfde1e7c2013-08-02 13:59:50 +0000387 renderer->setSampleCount(fSettingsWidget.getGLSampleCount());
robertphillips@google.com1447aa32013-01-30 21:09:09 +0000388 }
389#endif
390
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000391#endif
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000392
robertphillips@google.come174a8b2012-11-27 16:04:42 +0000393 static const int kNumRepeats = 10;
394
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000395 run(picture.get(), renderer, kNumRepeats);
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000396
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000397 SkASSERT(picture->count() == fListWidget.count());
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000398
399 // extract the individual command times from the SkTimedPlaybackPicture
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000400 for (int i = 0; i < picture->count(); ++i) {
401 double temp = picture->time(i);
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000402
403 QListWidgetItem* item = fListWidget.item(i);
404
405 item->setData(Qt::UserRole + 4, 100.0*temp);
406 }
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000407
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000408 setupOverviewText(picture->typeTimes(), picture->totTime(), kNumRepeats);
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000409}
410
chudy@google.com902ebe52012-06-29 14:21:22 +0000411void SkDebuggerGUI::actionCancel() {
chudy@google.comc432f002012-07-10 13:19:25 +0000412 for (int row = 0; row < fListWidget.count(); row++) {
413 fListWidget.item(row)->setHidden(false);
chudy@google.com902ebe52012-06-29 14:21:22 +0000414 }
415}
416
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000417void SkDebuggerGUI::actionClearBreakpoints() {
418 for (int row = 0; row < fListWidget.count(); row++) {
419 QListWidgetItem* item = fListWidget.item(row);
420 item->setCheckState(Qt::Unchecked);
421 item->setData(Qt::DecorationRole,
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000422 QPixmap(":/blank.png"));
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000423 }
424}
425
426void SkDebuggerGUI::actionClearDeletes() {
427 for (int row = 0; row < fListWidget.count(); row++) {
428 QListWidgetItem* item = fListWidget.item(row);
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000429 item->setData(Qt::UserRole + 2, QPixmap(":/blank.png"));
chudy@google.com607357f2012-08-07 16:12:23 +0000430 fDebugger.setCommandVisible(row, true);
robertphillips@google.com5f971142012-12-07 20:48:56 +0000431 fSkipCommands[row] = false;
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000432 }
433 if (fPause) {
434 fCanvasWidget.drawTo(fPausedRow);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000435 fImageWidget.draw();
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000436 } else {
437 fCanvasWidget.drawTo(fListWidget.currentRow());
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000438 fImageWidget.draw();
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000439 }
440}
441
chudy@google.com902ebe52012-06-29 14:21:22 +0000442void SkDebuggerGUI::actionCommandFilter() {
commit-bot@chromium.org22d39332013-11-21 15:37:29 +0000443 fDebugger.highlightCurrentCommand(fSettingsWidget.getVisibilityFilter());
chudy@google.comc432f002012-07-10 13:19:25 +0000444 fCanvasWidget.drawTo(fListWidget.currentRow());
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000445 fImageWidget.draw();
chudy@google.com902ebe52012-06-29 14:21:22 +0000446}
447
448void SkDebuggerGUI::actionClose() {
449 this->close();
450}
451
452void SkDebuggerGUI::actionDelete() {
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000453
robertphillips@google.comdd4b7452013-01-22 19:38:46 +0000454 for (int row = 0; row < fListWidget.count(); ++row) {
455 QListWidgetItem* item = fListWidget.item(row);
456
457 if (!item->isSelected()) {
458 continue;
459 }
460
461 if (fDebugger.isCommandVisible(row)) {
462 item->setData(Qt::UserRole + 2, QPixmap(":/delete.png"));
463 fDebugger.setCommandVisible(row, false);
464 fSkipCommands[row] = true;
465 } else {
466 item->setData(Qt::UserRole + 2, QPixmap(":/blank.png"));
467 fDebugger.setCommandVisible(row, true);
468 fSkipCommands[row] = false;
469 }
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000470 }
471
robertphillips@google.comdd4b7452013-01-22 19:38:46 +0000472 int currentRow = fListWidget.currentRow();
473
chudy@google.come504de02012-07-16 18:35:23 +0000474 if (fPause) {
475 fCanvasWidget.drawTo(fPausedRow);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000476 fImageWidget.draw();
chudy@google.come504de02012-07-16 18:35:23 +0000477 } else {
478 fCanvasWidget.drawTo(currentRow);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000479 fImageWidget.draw();
chudy@google.come504de02012-07-16 18:35:23 +0000480 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000481}
482
robertphillips@google.come8fe4bc2013-02-13 13:26:13 +0000483#if SK_SUPPORT_GPU
commit-bot@chromium.orgfde1e7c2013-08-02 13:59:50 +0000484void SkDebuggerGUI::actionGLWidget() {
485 bool isToggled = fSettingsWidget.isGLActive();
486 if (isToggled) {
487 fCanvasWidget.setGLSampleCount(fSettingsWidget.getGLSampleCount());
488 }
chudy@google.comea5488b2012-07-26 19:38:22 +0000489 fCanvasWidget.setWidgetVisibility(SkCanvasWidget::kGPU_WidgetType, !isToggled);
490}
robertphillips@google.come8fe4bc2013-02-13 13:26:13 +0000491#endif
chudy@google.comea5488b2012-07-26 19:38:22 +0000492
chudy@google.com902ebe52012-06-29 14:21:22 +0000493void SkDebuggerGUI::actionInspector() {
chudy@google.comc432f002012-07-10 13:19:25 +0000494 if (fInspectorWidget.isHidden()) {
495 fInspectorWidget.setHidden(false);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000496 fImageWidget.setHidden(false);
chudy@google.com902ebe52012-06-29 14:21:22 +0000497 } else {
chudy@google.comc432f002012-07-10 13:19:25 +0000498 fInspectorWidget.setHidden(true);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000499 fImageWidget.setHidden(true);
chudy@google.com902ebe52012-06-29 14:21:22 +0000500 }
501}
502
503void SkDebuggerGUI::actionPlay() {
chudy@google.comc432f002012-07-10 13:19:25 +0000504 for (int row = fListWidget.currentRow() + 1; row < fListWidget.count();
chudy@google.com7dcae672012-07-09 20:26:53 +0000505 row++) {
chudy@google.comc432f002012-07-10 13:19:25 +0000506 QListWidgetItem *item = fListWidget.item(row);
chudy@google.com902ebe52012-06-29 14:21:22 +0000507 if (item->checkState() == Qt::Checked) {
chudy@google.comc432f002012-07-10 13:19:25 +0000508 fListWidget.setCurrentItem(item);
chudy@google.com902ebe52012-06-29 14:21:22 +0000509 return;
510 }
511 }
chudy@google.comc432f002012-07-10 13:19:25 +0000512 fListWidget.setCurrentRow(fListWidget.count() - 1);
chudy@google.com902ebe52012-06-29 14:21:22 +0000513}
514
chudy@google.comea5488b2012-07-26 19:38:22 +0000515void SkDebuggerGUI::actionRasterWidget(bool isToggled) {
516 fCanvasWidget.setWidgetVisibility(SkCanvasWidget::kRaster_8888_WidgetType, !isToggled);
517}
518
robertphillips@google.comf4741c12013-02-06 20:13:54 +0000519void SkDebuggerGUI::actionOverdrawVizWidget(bool isToggled) {
520 fDebugger.setOverdrawViz(isToggled);
521 fCanvasWidget.update();
522}
523
robertphillips@google.com32bbcf82013-10-17 17:56:10 +0000524void SkDebuggerGUI::actionTextureFilter() {
525 SkPaint::FilterLevel level;
526 bool enabled = fSettingsWidget.getFilterOverride(&level);
527 fDebugger.setTexFilterOverride(enabled, level);
528 fCanvasWidget.update();
529}
530
chudy@google.com902ebe52012-06-29 14:21:22 +0000531void SkDebuggerGUI::actionRewind() {
chudy@google.come504de02012-07-16 18:35:23 +0000532 fListWidget.setCurrentRow(0);
chudy@google.com902ebe52012-06-29 14:21:22 +0000533}
534
chudy@google.com0ab03392012-07-28 20:16:11 +0000535void SkDebuggerGUI::actionSave() {
robertphillips@google.come219baf2013-01-28 19:25:43 +0000536 fFileName = fPath.toAscii().data();
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000537 fFileName.append("/");
robertphillips@google.come219baf2013-01-28 19:25:43 +0000538 fFileName.append(fDirectoryWidget.currentItem()->text().toAscii().data());
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000539 saveToFile(fFileName);
chudy@google.com0ab03392012-07-28 20:16:11 +0000540}
541
542void SkDebuggerGUI::actionSaveAs() {
543 QString filename = QFileDialog::getSaveFileName(this, "Save File", "",
544 "Skia Picture (*skp)");
chudy@google.com38b08ce2012-07-28 23:26:10 +0000545 if (!filename.endsWith(".skp", Qt::CaseInsensitive)) {
chudy@google.com0ab03392012-07-28 20:16:11 +0000546 filename.append(".skp");
547 }
djsollen@google.comc3c82162012-11-13 18:35:10 +0000548 saveToFile(SkString(filename.toAscii().data()));
chudy@google.com0ab03392012-07-28 20:16:11 +0000549}
550
chudy@google.com7dcae672012-07-09 20:26:53 +0000551void SkDebuggerGUI::actionScale(float scaleFactor) {
chudy@google.comc432f002012-07-10 13:19:25 +0000552 fSettingsWidget.setZoomText(scaleFactor);
chudy@google.com7dcae672012-07-09 20:26:53 +0000553}
554
chudy@google.com902ebe52012-06-29 14:21:22 +0000555void SkDebuggerGUI::actionSettings() {
chudy@google.comc432f002012-07-10 13:19:25 +0000556 if (fSettingsWidget.isHidden()) {
557 fSettingsWidget.setHidden(false);
chudy@google.com902ebe52012-06-29 14:21:22 +0000558 } else {
chudy@google.comc432f002012-07-10 13:19:25 +0000559 fSettingsWidget.setHidden(true);
chudy@google.com902ebe52012-06-29 14:21:22 +0000560 }
561}
562
563void SkDebuggerGUI::actionStepBack() {
chudy@google.comc432f002012-07-10 13:19:25 +0000564 int currentRow = fListWidget.currentRow();
chudy@google.com902ebe52012-06-29 14:21:22 +0000565 if (currentRow != 0) {
chudy@google.comc432f002012-07-10 13:19:25 +0000566 fListWidget.setCurrentRow(currentRow - 1);
chudy@google.com902ebe52012-06-29 14:21:22 +0000567 }
568}
569
570void SkDebuggerGUI::actionStepForward() {
chudy@google.comc432f002012-07-10 13:19:25 +0000571 int currentRow = fListWidget.currentRow();
chudy@google.com902ebe52012-06-29 14:21:22 +0000572 QString curRow = QString::number(currentRow);
chudy@google.comc432f002012-07-10 13:19:25 +0000573 QString curCount = QString::number(fListWidget.count());
574 if (currentRow < fListWidget.count() - 1) {
575 fListWidget.setCurrentRow(currentRow + 1);
chudy@google.com902ebe52012-06-29 14:21:22 +0000576 }
577}
578
chudy@google.coma9e937c2012-08-03 17:32:05 +0000579void SkDebuggerGUI::drawComplete() {
chudy@google.com607357f2012-08-07 16:12:23 +0000580 fInspectorWidget.setMatrix(fDebugger.getCurrentMatrix());
581 fInspectorWidget.setClip(fDebugger.getCurrentClip());
chudy@google.coma9e937c2012-08-03 17:32:05 +0000582}
583
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000584void SkDebuggerGUI::saveToFile(const SkString& filename) {
585 SkFILEWStream file(filename.c_str());
robertphillips@google.com25bc2f82013-01-22 18:03:56 +0000586 SkAutoTUnref<SkPicture> copy(fDebugger.copyPicture());
587
588 copy->serialize(&file);
chudy@google.com0ab03392012-07-28 20:16:11 +0000589}
590
chudy@google.com902ebe52012-06-29 14:21:22 +0000591void SkDebuggerGUI::loadFile(QListWidgetItem *item) {
592 if (fDirectoryWidgetActive) {
robertphillips@google.come219baf2013-01-28 19:25:43 +0000593 fFileName = fPath.toAscii().data();
jvanverth@google.com0ac6f162013-02-05 19:44:07 +0000594 // don't add a '/' to files in the local directory
595 if (fFileName.size() > 0) {
596 fFileName.append("/");
597 }
robertphillips@google.come219baf2013-01-28 19:25:43 +0000598 fFileName.append(item->text().toAscii().data());
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000599 loadPicture(fFileName);
chudy@google.com902ebe52012-06-29 14:21:22 +0000600 }
601}
602
603void SkDebuggerGUI::openFile() {
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000604 QString temp = QFileDialog::getOpenFileName(this, tr("Open File"), "",
chudy@google.com7dcae672012-07-09 20:26:53 +0000605 tr("Files (*.*)"));
robertphillips@google.comff6e6ba2013-01-28 17:43:26 +0000606 openFile(temp);
607}
608
609void SkDebuggerGUI::openFile(const QString &filename) {
chudy@google.com902ebe52012-06-29 14:21:22 +0000610 fDirectoryWidgetActive = false;
robertphillips@google.comff6e6ba2013-01-28 17:43:26 +0000611 if (!filename.isEmpty()) {
612 QFileInfo pathInfo(filename);
613 loadPicture(SkString(filename.toAscii().data()));
614 setupDirectoryWidget(pathInfo.path());
chudy@google.com902ebe52012-06-29 14:21:22 +0000615 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000616 fDirectoryWidgetActive = true;
617}
618
chudy@google.comc432f002012-07-10 13:19:25 +0000619void SkDebuggerGUI::pauseDrawing(bool isPaused) {
chudy@google.com607357f2012-08-07 16:12:23 +0000620 fPause = isPaused;
621 fPausedRow = fListWidget.currentRow();
622 fCanvasWidget.drawTo(fPausedRow);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000623 fImageWidget.draw();
chudy@google.com7dcae672012-07-09 20:26:53 +0000624}
625
chudy@google.com902ebe52012-06-29 14:21:22 +0000626void SkDebuggerGUI::registerListClick(QListWidgetItem *item) {
chudy@google.comd3058f52012-07-19 13:41:27 +0000627 if(!fLoading) {
628 int currentRow = fListWidget.currentRow();
chudy@google.comd3058f52012-07-19 13:41:27 +0000629
chudy@google.comea5488b2012-07-26 19:38:22 +0000630 if (currentRow != -1) {
631 if (!fPause) {
632 fCanvasWidget.drawTo(currentRow);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000633 fImageWidget.draw();
chudy@google.comd3058f52012-07-19 13:41:27 +0000634 }
chudy@google.com97cee972012-08-07 20:41:37 +0000635 SkTDArray<SkString*> *currInfo = fDebugger.getCommandInfo(
chudy@google.comea5488b2012-07-26 19:38:22 +0000636 currentRow);
637
638 /* TODO(chudy): Add command type before parameters. Rename v
639 * to something more informative. */
chudy@google.com97cee972012-08-07 20:41:37 +0000640 if (currInfo) {
chudy@google.comea5488b2012-07-26 19:38:22 +0000641 QString info;
642 info.append("<b>Parameters: </b><br/>");
chudy@google.com97cee972012-08-07 20:41:37 +0000643 for (int i = 0; i < currInfo->count(); i++) {
644
645 info.append(QString((*currInfo)[i]->c_str()));
chudy@google.comea5488b2012-07-26 19:38:22 +0000646 info.append("<br/>");
647 }
chudy@google.com6bd109a2012-08-14 19:34:13 +0000648 fInspectorWidget.setText(info, SkInspectorWidget::kDetail_TabType);
chudy@google.comea5488b2012-07-26 19:38:22 +0000649 fInspectorWidget.setDisabled(false);
chudy@google.comea5488b2012-07-26 19:38:22 +0000650 }
chudy@google.comd3058f52012-07-19 13:41:27 +0000651 }
chudy@google.comea5488b2012-07-26 19:38:22 +0000652
chudy@google.com902ebe52012-06-29 14:21:22 +0000653 }
654}
655
chudy@google.com9ca9bfe2012-07-12 21:58:14 +0000656void SkDebuggerGUI::selectCommand(int command) {
657 if (fPause) {
658 fListWidget.setCurrentRow(command);
659 }
660}
661
chudy@google.com902ebe52012-06-29 14:21:22 +0000662void SkDebuggerGUI::toggleBreakpoint() {
chudy@google.comc432f002012-07-10 13:19:25 +0000663 QListWidgetItem* item = fListWidget.currentItem();
chudy@google.com902ebe52012-06-29 14:21:22 +0000664 if (item->checkState() == Qt::Unchecked) {
665 item->setCheckState(Qt::Checked);
chudy@google.come565de42012-07-12 14:15:54 +0000666 item->setData(Qt::DecorationRole,
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000667 QPixmap(":/breakpoint_16x16.png"));
chudy@google.com902ebe52012-06-29 14:21:22 +0000668 } else {
chudy@google.com902ebe52012-06-29 14:21:22 +0000669 item->setCheckState(Qt::Unchecked);
chudy@google.come565de42012-07-12 14:15:54 +0000670 item->setData(Qt::DecorationRole,
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000671 QPixmap(":/blank.png"));
chudy@google.com902ebe52012-06-29 14:21:22 +0000672 }
673}
674
675void SkDebuggerGUI::toggleDirectory() {
chudy@google.com607357f2012-08-07 16:12:23 +0000676 fDirectoryWidget.setHidden(!fDirectoryWidget.isHidden());
chudy@google.com902ebe52012-06-29 14:21:22 +0000677}
678
679void SkDebuggerGUI::toggleFilter(QString string) {
chudy@google.comc432f002012-07-10 13:19:25 +0000680 for (int row = 0; row < fListWidget.count(); row++) {
681 QListWidgetItem *item = fListWidget.item(row);
chudy@google.com607357f2012-08-07 16:12:23 +0000682 item->setHidden(item->text() != string);
chudy@google.com902ebe52012-06-29 14:21:22 +0000683 }
684}
685
686void SkDebuggerGUI::setupUi(QMainWindow *SkDebuggerGUI) {
687 QIcon windowIcon;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000688 windowIcon.addFile(QString::fromUtf8(":/skia.png"), QSize(),
chudy@google.com7dcae672012-07-09 20:26:53 +0000689 QIcon::Normal, QIcon::Off);
chudy@google.com902ebe52012-06-29 14:21:22 +0000690 SkDebuggerGUI->setObjectName(QString::fromUtf8("SkDebuggerGUI"));
691 SkDebuggerGUI->resize(1200, 1000);
692 SkDebuggerGUI->setWindowIcon(windowIcon);
chudy@google.comc432f002012-07-10 13:19:25 +0000693 SkDebuggerGUI->setWindowTitle("Skia Debugger");
chudy@google.com902ebe52012-06-29 14:21:22 +0000694
chudy@google.come504de02012-07-16 18:35:23 +0000695 fActionOpen.setShortcuts(QKeySequence::Open);
chudy@google.comc432f002012-07-10 13:19:25 +0000696 fActionOpen.setText("Open");
chudy@google.com902ebe52012-06-29 14:21:22 +0000697
698 QIcon breakpoint;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000699 breakpoint.addFile(QString::fromUtf8(":/breakpoint.png"),
chudy@google.com7dcae672012-07-09 20:26:53 +0000700 QSize(), QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000701 fActionBreakpoint.setShortcut(QKeySequence(tr("Ctrl+B")));
chudy@google.comc432f002012-07-10 13:19:25 +0000702 fActionBreakpoint.setIcon(breakpoint);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000703 fActionBreakpoint.setText("Breakpoints");
chudy@google.com902ebe52012-06-29 14:21:22 +0000704
705 QIcon cancel;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000706 cancel.addFile(QString::fromUtf8(":/reload.png"), QSize(),
chudy@google.com7dcae672012-07-09 20:26:53 +0000707 QIcon::Normal, QIcon::Off);
chudy@google.comc432f002012-07-10 13:19:25 +0000708 fActionCancel.setIcon(cancel);
709 fActionCancel.setText("Clear Filter");
chudy@google.com902ebe52012-06-29 14:21:22 +0000710
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000711 fActionClearBreakpoints.setShortcut(QKeySequence(tr("Alt+B")));
712 fActionClearBreakpoints.setText("Clear Breakpoints");
713
714 fActionClearDeletes.setShortcut(QKeySequence(tr("Alt+X")));
715 fActionClearDeletes.setText("Clear Deletes");
716
chudy@google.come504de02012-07-16 18:35:23 +0000717 fActionClose.setShortcuts(QKeySequence::Quit);
chudy@google.comc432f002012-07-10 13:19:25 +0000718 fActionClose.setText("Exit");
chudy@google.com902ebe52012-06-29 14:21:22 +0000719
chudy@google.come504de02012-07-16 18:35:23 +0000720 fActionCreateBreakpoint.setShortcut(QKeySequence(tr("B")));
721 fActionCreateBreakpoint.setText("Set Breakpoint");
722
723 fActionDelete.setShortcut(QKeySequence(tr("X")));
chudy@google.comc432f002012-07-10 13:19:25 +0000724 fActionDelete.setText("Delete Command");
chudy@google.com902ebe52012-06-29 14:21:22 +0000725
chudy@google.come504de02012-07-16 18:35:23 +0000726 fActionDirectory.setShortcut(QKeySequence(tr("Ctrl+D")));
727 fActionDirectory.setText("Directory");
chudy@google.com902ebe52012-06-29 14:21:22 +0000728
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000729 QIcon profile;
robertphillips@google.comd1636362012-11-19 18:25:09 +0000730 profile.addFile(QString::fromUtf8(":/profile.png"), QSize(),
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000731 QIcon::Normal, QIcon::Off);
732 fActionProfile.setIcon(profile);
733 fActionProfile.setText("Profile");
robertphillips@google.come099bc42012-11-19 16:26:40 +0000734 fActionProfile.setDisabled(true);
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000735
chudy@google.comc432f002012-07-10 13:19:25 +0000736 QIcon inspector;
robertphillips@google.comd1636362012-11-19 18:25:09 +0000737 inspector.addFile(QString::fromUtf8(":/inspector.png"),
chudy@google.comc432f002012-07-10 13:19:25 +0000738 QSize(), QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000739 fActionInspector.setShortcut(QKeySequence(tr("Ctrl+I")));
chudy@google.comc432f002012-07-10 13:19:25 +0000740 fActionInspector.setIcon(inspector);
chudy@google.come504de02012-07-16 18:35:23 +0000741 fActionInspector.setText("Inspector");
chudy@google.com902ebe52012-06-29 14:21:22 +0000742
bungeman@google.com2ff6d1d2013-07-01 14:24:12 +0000743 QIcon settings;
744 settings.addFile(QString::fromUtf8(":/inspector.png"),
745 QSize(), QIcon::Normal, QIcon::Off);
746 fActionSettings.setShortcut(QKeySequence(tr("Ctrl+G")));
747 fActionSettings.setIcon(settings);
748 fActionSettings.setText("Settings");
skia.committer@gmail.com0d55dd72013-07-02 07:00:59 +0000749
chudy@google.comc432f002012-07-10 13:19:25 +0000750 QIcon play;
robertphillips@google.comd1636362012-11-19 18:25:09 +0000751 play.addFile(QString::fromUtf8(":/play.png"), QSize(),
chudy@google.comc432f002012-07-10 13:19:25 +0000752 QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000753 fActionPlay.setShortcut(QKeySequence(tr("Ctrl+P")));
chudy@google.comc432f002012-07-10 13:19:25 +0000754 fActionPlay.setIcon(play);
755 fActionPlay.setText("Play");
chudy@google.com902ebe52012-06-29 14:21:22 +0000756
chudy@google.come504de02012-07-16 18:35:23 +0000757 QIcon pause;
robertphillips@google.comd1636362012-11-19 18:25:09 +0000758 pause.addFile(QString::fromUtf8(":/pause.png"), QSize(),
chudy@google.comc432f002012-07-10 13:19:25 +0000759 QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000760 fActionPause.setShortcut(QKeySequence(tr("Space")));
761 fActionPause.setCheckable(true);
762 fActionPause.setIcon(pause);
763 fActionPause.setText("Pause");
764
chudy@google.comc432f002012-07-10 13:19:25 +0000765 QIcon rewind;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000766 rewind.addFile(QString::fromUtf8(":/rewind.png"), QSize(),
chudy@google.comc432f002012-07-10 13:19:25 +0000767 QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000768 fActionRewind.setShortcut(QKeySequence(tr("Ctrl+R")));
chudy@google.comc432f002012-07-10 13:19:25 +0000769 fActionRewind.setIcon(rewind);
770 fActionRewind.setText("Rewind");
chudy@google.com902ebe52012-06-29 14:21:22 +0000771
chudy@google.com0ab03392012-07-28 20:16:11 +0000772 fActionSave.setShortcut(QKeySequence::Save);
773 fActionSave.setText("Save");
774 fActionSave.setDisabled(true);
775 fActionSaveAs.setShortcut(QKeySequence::SaveAs);
776 fActionSaveAs.setText("Save As");
777 fActionSaveAs.setDisabled(true);
778
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000779 fActionShowDeletes.setShortcut(QKeySequence(tr("Ctrl+X")));
780 fActionShowDeletes.setText("Deleted Commands");
781
chudy@google.comc432f002012-07-10 13:19:25 +0000782 QIcon stepBack;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000783 stepBack.addFile(QString::fromUtf8(":/previous.png"), QSize(),
chudy@google.comc432f002012-07-10 13:19:25 +0000784 QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000785 fActionStepBack.setShortcut(QKeySequence(tr("[")));
chudy@google.comc432f002012-07-10 13:19:25 +0000786 fActionStepBack.setIcon(stepBack);
787 fActionStepBack.setText("Step Back");
chudy@google.com902ebe52012-06-29 14:21:22 +0000788
chudy@google.comc432f002012-07-10 13:19:25 +0000789 QIcon stepForward;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000790 stepForward.addFile(QString::fromUtf8(":/next.png"),
chudy@google.comc432f002012-07-10 13:19:25 +0000791 QSize(), QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000792 fActionStepForward.setShortcut(QKeySequence(tr("]")));
chudy@google.comc432f002012-07-10 13:19:25 +0000793 fActionStepForward.setIcon(stepForward);
794 fActionStepForward.setText("Step Forward");
795
chudy@google.coma1226312012-07-26 20:26:44 +0000796 fActionZoomIn.setShortcut(QKeySequence(tr("Ctrl+=")));
797 fActionZoomIn.setText("Zoom In");
798 fActionZoomOut.setShortcut(QKeySequence(tr("Ctrl+-")));
799 fActionZoomOut.setText("Zoom Out");
800
chudy@google.comc432f002012-07-10 13:19:25 +0000801 fListWidget.setItemDelegate(new SkListWidget(&fListWidget));
802 fListWidget.setObjectName(QString::fromUtf8("listWidget"));
commit-bot@chromium.orgbcd431e2013-11-21 13:41:37 +0000803 fListWidget.setMinimumWidth(250);
chudy@google.comc432f002012-07-10 13:19:25 +0000804
805 fFilter.addItem("--Filter By Available Commands--");
806
commit-bot@chromium.orgbcd431e2013-11-21 13:41:37 +0000807 fDirectoryWidget.setMinimumWidth(250);
chudy@google.comc432f002012-07-10 13:19:25 +0000808 fDirectoryWidget.setStyleSheet("QListWidget::Item {padding: 5px;}");
809
810 fCanvasWidget.setSizePolicy(QSizePolicy::Expanding,
chudy@google.com7dcae672012-07-09 20:26:53 +0000811 QSizePolicy::Expanding);
chudy@google.com902ebe52012-06-29 14:21:22 +0000812
skia.committer@gmail.com1c9c0d32012-11-22 02:02:41 +0000813 fImageWidget.setFixedSize(SkImageWidget::kImageWidgetWidth,
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000814 SkImageWidget::kImageWidgetHeight);
815
chudy@google.comc432f002012-07-10 13:19:25 +0000816 fInspectorWidget.setSizePolicy(QSizePolicy::Expanding,
chudy@google.com7dcae672012-07-09 20:26:53 +0000817 QSizePolicy::Expanding);
chudy@google.comc432f002012-07-10 13:19:25 +0000818 fInspectorWidget.setMaximumHeight(300);
chudy@google.com902ebe52012-06-29 14:21:22 +0000819
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000820 fSettingsAndImageLayout.setSpacing(6);
821 fSettingsAndImageLayout.addWidget(&fSettingsWidget);
822 fSettingsAndImageLayout.addWidget(&fImageWidget);
823
chudy@google.comc432f002012-07-10 13:19:25 +0000824 fSettingsWidget.setSizePolicy(QSizePolicy::Expanding,
825 QSizePolicy::Expanding);
826 fSettingsWidget.setMaximumWidth(250);
chudy@google.com902ebe52012-06-29 14:21:22 +0000827
commit-bot@chromium.orgbcd431e2013-11-21 13:41:37 +0000828 fLeftColumnSplitter.addWidget(&fListWidget);
829 fLeftColumnSplitter.addWidget(&fDirectoryWidget);
830 fLeftColumnSplitter.setOrientation(Qt::Vertical);
chudy@google.com902ebe52012-06-29 14:21:22 +0000831
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000832 fCanvasSettingsAndImageLayout.setSpacing(6);
833 fCanvasSettingsAndImageLayout.addWidget(&fCanvasWidget);
834 fCanvasSettingsAndImageLayout.addLayout(&fSettingsAndImageLayout);
835
chudy@google.comc432f002012-07-10 13:19:25 +0000836 fMainAndRightColumnLayout.setSpacing(6);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000837 fMainAndRightColumnLayout.addLayout(&fCanvasSettingsAndImageLayout);
chudy@google.comc432f002012-07-10 13:19:25 +0000838 fMainAndRightColumnLayout.addWidget(&fInspectorWidget);
commit-bot@chromium.orgbcd431e2013-11-21 13:41:37 +0000839 fMainAndRightColumnWidget.setLayout(&fMainAndRightColumnLayout);
chudy@google.com902ebe52012-06-29 14:21:22 +0000840
commit-bot@chromium.orgbcd431e2013-11-21 13:41:37 +0000841 fCentralSplitter.addWidget(&fLeftColumnSplitter);
842 fCentralSplitter.addWidget(&fMainAndRightColumnWidget);
843 fCentralSplitter.setStretchFactor(0, 0);
844 fCentralSplitter.setStretchFactor(1, 1);
chudy@google.comc432f002012-07-10 13:19:25 +0000845
commit-bot@chromium.orgbcd431e2013-11-21 13:41:37 +0000846 SkDebuggerGUI->setCentralWidget(&fCentralSplitter);
chudy@google.comc432f002012-07-10 13:19:25 +0000847 SkDebuggerGUI->setStatusBar(&fStatusBar);
848
chudy@google.come504de02012-07-16 18:35:23 +0000849 fToolBar.setIconSize(QSize(32, 32));
chudy@google.comc432f002012-07-10 13:19:25 +0000850 fToolBar.setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
851 SkDebuggerGUI->addToolBar(Qt::TopToolBarArea, &fToolBar);
chudy@google.com902ebe52012-06-29 14:21:22 +0000852
chudy@google.com0ab03392012-07-28 20:16:11 +0000853 fSpacer.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
chudy@google.com902ebe52012-06-29 14:21:22 +0000854
chudy@google.comc432f002012-07-10 13:19:25 +0000855 fToolBar.addAction(&fActionRewind);
856 fToolBar.addAction(&fActionStepBack);
chudy@google.come504de02012-07-16 18:35:23 +0000857 fToolBar.addAction(&fActionPause);
chudy@google.comc432f002012-07-10 13:19:25 +0000858 fToolBar.addAction(&fActionStepForward);
859 fToolBar.addAction(&fActionPlay);
860 fToolBar.addSeparator();
chudy@google.come504de02012-07-16 18:35:23 +0000861 fToolBar.addAction(&fActionInspector);
bungeman@google.com2ff6d1d2013-07-01 14:24:12 +0000862 fToolBar.addAction(&fActionSettings);
chudy@google.comc432f002012-07-10 13:19:25 +0000863 fToolBar.addSeparator();
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000864 fToolBar.addAction(&fActionProfile);
865
866 fToolBar.addSeparator();
chudy@google.com0ab03392012-07-28 20:16:11 +0000867 fToolBar.addWidget(&fSpacer);
chudy@google.comc432f002012-07-10 13:19:25 +0000868 fToolBar.addWidget(&fFilter);
869 fToolBar.addAction(&fActionCancel);
chudy@google.com902ebe52012-06-29 14:21:22 +0000870
871 // TODO(chudy): Remove static call.
872 fDirectoryWidgetActive = false;
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000873 fFileName = "";
robertphillips@google.comff6e6ba2013-01-28 17:43:26 +0000874 setupDirectoryWidget("");
chudy@google.com902ebe52012-06-29 14:21:22 +0000875 fDirectoryWidgetActive = true;
876
chudy@google.com902ebe52012-06-29 14:21:22 +0000877 // Menu Bar
chudy@google.comc432f002012-07-10 13:19:25 +0000878 fMenuFile.setTitle("File");
879 fMenuFile.addAction(&fActionOpen);
chudy@google.com0ab03392012-07-28 20:16:11 +0000880 fMenuFile.addAction(&fActionSave);
881 fMenuFile.addAction(&fActionSaveAs);
chudy@google.comc432f002012-07-10 13:19:25 +0000882 fMenuFile.addAction(&fActionClose);
chudy@google.come504de02012-07-16 18:35:23 +0000883
884 fMenuEdit.setTitle("Edit");
885 fMenuEdit.addAction(&fActionDelete);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000886 fMenuEdit.addAction(&fActionClearDeletes);
887 fMenuEdit.addSeparator();
chudy@google.come504de02012-07-16 18:35:23 +0000888 fMenuEdit.addAction(&fActionCreateBreakpoint);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000889 fMenuEdit.addAction(&fActionClearBreakpoints);
chudy@google.come504de02012-07-16 18:35:23 +0000890
chudy@google.comc432f002012-07-10 13:19:25 +0000891 fMenuNavigate.setTitle("Navigate");
chudy@google.come504de02012-07-16 18:35:23 +0000892 fMenuNavigate.addAction(&fActionRewind);
893 fMenuNavigate.addAction(&fActionStepBack);
894 fMenuNavigate.addAction(&fActionStepForward);
895 fMenuNavigate.addAction(&fActionPlay);
896 fMenuNavigate.addAction(&fActionPause);
chudy@google.comc432f002012-07-10 13:19:25 +0000897 fMenuNavigate.addAction(&fActionGoToLine);
chudy@google.come504de02012-07-16 18:35:23 +0000898
chudy@google.comc432f002012-07-10 13:19:25 +0000899 fMenuView.setTitle("View");
chudy@google.come504de02012-07-16 18:35:23 +0000900 fMenuView.addAction(&fActionBreakpoint);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000901 fMenuView.addAction(&fActionShowDeletes);
chudy@google.coma1226312012-07-26 20:26:44 +0000902 fMenuView.addAction(&fActionZoomIn);
903 fMenuView.addAction(&fActionZoomOut);
chudy@google.come504de02012-07-16 18:35:23 +0000904
905 fMenuWindows.setTitle("Window");
906 fMenuWindows.addAction(&fActionInspector);
bungeman@google.com2ff6d1d2013-07-01 14:24:12 +0000907 fMenuWindows.addAction(&fActionSettings);
chudy@google.come504de02012-07-16 18:35:23 +0000908 fMenuWindows.addAction(&fActionDirectory);
chudy@google.comc432f002012-07-10 13:19:25 +0000909
910 fActionGoToLine.setText("Go to Line...");
911 fActionGoToLine.setDisabled(true);
912 fMenuBar.addAction(fMenuFile.menuAction());
chudy@google.come504de02012-07-16 18:35:23 +0000913 fMenuBar.addAction(fMenuEdit.menuAction());
chudy@google.comc432f002012-07-10 13:19:25 +0000914 fMenuBar.addAction(fMenuView.menuAction());
915 fMenuBar.addAction(fMenuNavigate.menuAction());
chudy@google.come504de02012-07-16 18:35:23 +0000916 fMenuBar.addAction(fMenuWindows.menuAction());
chudy@google.com902ebe52012-06-29 14:21:22 +0000917
chudy@google.com7dcae672012-07-09 20:26:53 +0000918 fPause = false;
919
chudy@google.comc432f002012-07-10 13:19:25 +0000920 SkDebuggerGUI->setMenuBar(&fMenuBar);
chudy@google.com902ebe52012-06-29 14:21:22 +0000921 QMetaObject::connectSlotsByName(SkDebuggerGUI);
922}
923
robertphillips@google.comff6e6ba2013-01-28 17:43:26 +0000924void SkDebuggerGUI::setupDirectoryWidget(const QString& path) {
925 fPath = path;
926 QDir dir(path);
chudy@google.com902ebe52012-06-29 14:21:22 +0000927 QRegExp r(".skp");
chudy@google.comc432f002012-07-10 13:19:25 +0000928 fDirectoryWidget.clear();
929 const QStringList files = dir.entryList();
chudy@google.com902ebe52012-06-29 14:21:22 +0000930 foreach (QString f, files) {
chudy@google.com7dcae672012-07-09 20:26:53 +0000931 if (f.contains(r))
chudy@google.comc432f002012-07-10 13:19:25 +0000932 fDirectoryWidget.addItem(f);
chudy@google.com902ebe52012-06-29 14:21:22 +0000933 }
934}
935
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000936void SkDebuggerGUI::loadPicture(const SkString& fileName) {
937 fFileName = fileName;
chudy@google.comd3058f52012-07-19 13:41:27 +0000938 fLoading = true;
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000939 SkStream* stream = SkNEW_ARGS(SkFILEStream, (fileName.c_str()));
robertphillips@google.com2d40ec42013-02-07 20:39:40 +0000940
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000941 SkPicture* picture = SkPicture::CreateFromStream(stream);
robertphillips@google.com2d40ec42013-02-07 20:39:40 +0000942
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000943 if (NULL == picture) {
robertphillips@google.com2d40ec42013-02-07 20:39:40 +0000944 QMessageBox::critical(this, "Error loading file", "Couldn't read file, sorry.");
945 SkSafeUnref(stream);
946 return;
947 }
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000948
chudy@google.com686e6802012-08-14 16:00:32 +0000949 fCanvasWidget.resetWidgetTransform();
chudy@google.com607357f2012-08-07 16:12:23 +0000950 fDebugger.loadPicture(picture);
chudy@google.com4c7962e2012-08-14 19:38:31 +0000951
robertphillips@google.com6d9c92b2013-05-23 13:21:18 +0000952 fSkipCommands.setCount(fDebugger.getSize());
953 for (int i = 0; i < fSkipCommands.count(); ++i) {
robertphillips@google.com5f971142012-12-07 20:48:56 +0000954 fSkipCommands[i] = false;
955 }
956
chudy@google.com607357f2012-08-07 16:12:23 +0000957 SkSafeUnref(stream);
958 SkSafeUnref(picture);
959
chudy@google.com97cee972012-08-07 20:41:37 +0000960 // Will this automatically clear out due to nature of refcnt?
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000961 SkTArray<SkString>* commands = fDebugger.getDrawCommandsAsStrings();
chudy@google.com607357f2012-08-07 16:12:23 +0000962
robertphillips@google.com6d9c92b2013-05-23 13:21:18 +0000963 fActionProfile.setDisabled(false);
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000964
chudy@google.com7dcae672012-07-09 20:26:53 +0000965 /* fDebugCanvas is reinitialized every load picture. Need it to retain value
chudy@google.com607357f2012-08-07 16:12:23 +0000966 * of the visibility filter.
967 * TODO(chudy): This should be deprecated since fDebugger is not
968 * recreated.
969 * */
commit-bot@chromium.org22d39332013-11-21 15:37:29 +0000970 fDebugger.highlightCurrentCommand(fSettingsWidget.getVisibilityFilter());
chudy@google.com607357f2012-08-07 16:12:23 +0000971
chudy@google.com97cee972012-08-07 20:41:37 +0000972 setupListWidget(commands);
973 setupComboBox(commands);
robertphillips@google.come428f9b2013-03-12 15:33:40 +0000974 setupOverviewText(NULL, 0.0, 1);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000975 fInspectorWidget.setDisabled(false);
chudy@google.come606d6e2012-07-12 14:31:25 +0000976 fSettingsWidget.setDisabled(false);
chudy@google.comd3058f52012-07-19 13:41:27 +0000977 fMenuEdit.setDisabled(false);
978 fMenuNavigate.setDisabled(false);
979 fMenuView.setDisabled(false);
chudy@google.com0ab03392012-07-28 20:16:11 +0000980 fActionSave.setDisabled(false);
981 fActionSaveAs.setDisabled(false);
chudy@google.comd3058f52012-07-19 13:41:27 +0000982 fLoading = false;
983 actionPlay();
chudy@google.com902ebe52012-06-29 14:21:22 +0000984}
985
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000986void SkDebuggerGUI::setupListWidget(SkTArray<SkString>* command) {
chudy@google.comc432f002012-07-10 13:19:25 +0000987 fListWidget.clear();
chudy@google.com902ebe52012-06-29 14:21:22 +0000988 int counter = 0;
robertphillips@google.com30d35f22012-11-06 16:45:36 +0000989 int indent = 0;
chudy@google.com97cee972012-08-07 20:41:37 +0000990 for (int i = 0; i < command->count(); i++) {
chudy@google.com902ebe52012-06-29 14:21:22 +0000991 QListWidgetItem *item = new QListWidgetItem();
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000992 item->setData(Qt::DisplayRole, (*command)[i].c_str());
chudy@google.com902ebe52012-06-29 14:21:22 +0000993 item->setData(Qt::UserRole + 1, counter++);
robertphillips@google.com30d35f22012-11-06 16:45:36 +0000994
robertphillips@google.com0a4805e2013-05-29 13:24:23 +0000995 if (0 == strcmp("Restore", (*command)[i].c_str()) ||
996 0 == strcmp("EndCommentGroup", (*command)[i].c_str())) {
robertphillips@google.com30d35f22012-11-06 16:45:36 +0000997 indent -= 10;
998 }
999
1000 item->setData(Qt::UserRole + 3, indent);
1001
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +00001002 if (0 == strcmp("Save", (*command)[i].c_str()) ||
robertphillips@google.com0a4805e2013-05-29 13:24:23 +00001003 0 == strcmp("Save Layer", (*command)[i].c_str()) ||
1004 0 == strcmp("BeginCommentGroup", (*command)[i].c_str())) {
robertphillips@google.com30d35f22012-11-06 16:45:36 +00001005 indent += 10;
1006 }
1007
robertphillips@google.comd26c7062012-11-12 20:42:12 +00001008 item->setData(Qt::UserRole + 4, -1.0);
1009
chudy@google.comc432f002012-07-10 13:19:25 +00001010 fListWidget.addItem(item);
chudy@google.com902ebe52012-06-29 14:21:22 +00001011 }
1012}
1013
skia.committer@gmail.com91274b92013-03-13 07:01:04 +00001014void SkDebuggerGUI::setupOverviewText(const SkTDArray<double>* typeTimes,
robertphillips@google.come428f9b2013-03-12 15:33:40 +00001015 double totTime,
1016 int numRuns) {
borenet@google.com2d9dbd42013-03-12 13:07:40 +00001017 SkString overview;
robertphillips@google.come428f9b2013-03-12 15:33:40 +00001018 fDebugger.getOverviewText(typeTimes, totTime, &overview, numRuns);
borenet@google.com2d9dbd42013-03-12 13:07:40 +00001019 fInspectorWidget.setText(overview.c_str(), SkInspectorWidget::kOverview_TabType);
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +00001020}
1021
1022void SkDebuggerGUI::setupComboBox(SkTArray<SkString>* command) {
1023 fFilter.clear();
1024 fFilter.addItem("--Filter By Available Commands--");
1025
1026 std::map<std::string, int> map;
1027 for (int i = 0; i < command->count(); i++) {
1028 map[(*command)[i].c_str()]++;
1029 }
1030
skia.committer@gmail.com34587162012-11-20 02:01:23 +00001031 for (std::map<std::string, int>::iterator it = map.begin(); it != map.end();
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +00001032 ++it) {
1033 fFilter.addItem((it->first).c_str());
1034 }
chudy@google.com902ebe52012-06-29 14:21:22 +00001035
1036 // NOTE(chudy): Makes first item unselectable.
chudy@google.com7dcae672012-07-09 20:26:53 +00001037 QStandardItemModel* model = qobject_cast<QStandardItemModel*>(
chudy@google.comc432f002012-07-10 13:19:25 +00001038 fFilter.model());
1039 QModelIndex firstIndex = model->index(0, fFilter.modelColumn(),
1040 fFilter.rootModelIndex());
chudy@google.com902ebe52012-06-29 14:21:22 +00001041 QStandardItem* firstItem = model->itemFromIndex(firstIndex);
1042 firstItem->setSelectable(false);
1043}