blob: 67277070e5124576607754c402ecf261d82713a2 [file] [log] [blame]
chudy@google.com902ebe52012-06-29 14:21:22 +00001/*
2 * Copyright 2012 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
chudy@google.com902ebe52012-06-29 14:21:22 +00008#include "SkDebuggerGUI.h"
scroggo@google.com7def5e12013-05-31 14:00:10 +00009#include "SkForceLinking.h"
chudy@google.combbad34d2012-08-13 14:26:36 +000010#include "SkGraphics.h"
scroggo@google.comb4467e62012-11-06 23:10:09 +000011#include "SkImageDecoder.h"
chudy@google.com902ebe52012-06-29 14:21:22 +000012#include <QListWidgetItem>
robertphillips@google.com2bde91d2012-11-15 14:57:57 +000013#include "PictureRenderer.h"
robertphillips@google.com2bde91d2012-11-15 14:57:57 +000014#include "SkPictureRecord.h"
15#include "SkPicturePlayback.h"
robertphillips@google.come174a8b2012-11-27 16:04:42 +000016
scroggo@google.com7def5e12013-05-31 14:00:10 +000017__SK_FORCE_IMAGE_DECODER_LINKING;
18
robertphillips@google.come174a8b2012-11-27 16:04:42 +000019#if defined(SK_BUILD_FOR_WIN32)
20 #include "BenchSysTimer_windows.h"
21#elif defined(SK_BUILD_FOR_MAC)
22 #include "BenchSysTimer_mach.h"
23#elif defined(SK_BUILD_FOR_UNIX) || defined(SK_BUILD_FOR_ANDROID)
24 #include "BenchSysTimer_posix.h"
25#else
26 #include "BenchSysTimer_c.h"
27#endif
28
chudy@google.com902ebe52012-06-29 14:21:22 +000029
30SkDebuggerGUI::SkDebuggerGUI(QWidget *parent) :
chudy@google.comc432f002012-07-10 13:19:25 +000031 QMainWindow(parent)
chudy@google.com2d537a12012-07-31 12:49:52 +000032 , fCentralWidget(this)
33 , fStatusBar(this)
34 , fToolBar(this)
chudy@google.comc432f002012-07-10 13:19:25 +000035 , fActionOpen(this)
36 , fActionBreakpoint(this)
robertphillips@google.comd26c7062012-11-12 20:42:12 +000037 , fActionProfile(this)
chudy@google.comc432f002012-07-10 13:19:25 +000038 , fActionCancel(this)
chudy@google.com7e4cfbf2012-07-17 15:40:51 +000039 , fActionClearBreakpoints(this)
chudy@google.come504de02012-07-16 18:35:23 +000040 , fActionClearDeletes(this)
chudy@google.comc432f002012-07-10 13:19:25 +000041 , fActionClose(this)
chudy@google.come504de02012-07-16 18:35:23 +000042 , fActionCreateBreakpoint(this)
chudy@google.comc432f002012-07-10 13:19:25 +000043 , fActionDelete(this)
44 , fActionDirectory(this)
45 , fActionGoToLine(this)
46 , fActionInspector(this)
47 , fActionPlay(this)
chudy@google.come504de02012-07-16 18:35:23 +000048 , fActionPause(this)
chudy@google.comc432f002012-07-10 13:19:25 +000049 , fActionRewind(this)
chudy@google.com0ab03392012-07-28 20:16:11 +000050 , fActionSave(this)
51 , fActionSaveAs(this)
chudy@google.com7e4cfbf2012-07-17 15:40:51 +000052 , fActionShowDeletes(this)
chudy@google.comc432f002012-07-10 13:19:25 +000053 , fActionStepBack(this)
54 , fActionStepForward(this)
chudy@google.coma1226312012-07-26 20:26:44 +000055 , fActionZoomIn(this)
56 , fActionZoomOut(this)
57 , fMapper(this)
chudy@google.comc432f002012-07-10 13:19:25 +000058 , fListWidget(&fCentralWidget)
59 , fDirectoryWidget(&fCentralWidget)
chudy@google.com607357f2012-08-07 16:12:23 +000060 , fCanvasWidget(this, &fDebugger)
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +000061 , fImageWidget(&fDebugger)
chudy@google.comc432f002012-07-10 13:19:25 +000062 , fMenuBar(this)
63 , fMenuFile(this)
64 , fMenuNavigate(this)
65 , fMenuView(this)
chudy@google.com7e4cfbf2012-07-17 15:40:51 +000066 , fBreakpointsActivated(false)
67 , fDeletesActivated(false)
68 , fPause(false)
chudy@google.comd3058f52012-07-19 13:41:27 +000069 , fLoading(false)
chudy@google.comc432f002012-07-10 13:19:25 +000070{
chudy@google.com902ebe52012-06-29 14:21:22 +000071 setupUi(this);
robertphillips@google.comdd4b7452013-01-22 19:38:46 +000072 fListWidget.setSelectionMode(QAbstractItemView::ExtendedSelection);
chudy@google.comea5488b2012-07-26 19:38:22 +000073 connect(&fListWidget, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)), this, SLOT(registerListClick(QListWidgetItem *)));
chudy@google.comc432f002012-07-10 13:19:25 +000074 connect(&fActionOpen, SIGNAL(triggered()), this, SLOT(openFile()));
chudy@google.comea5488b2012-07-26 19:38:22 +000075 connect(&fActionDirectory, SIGNAL(triggered()), this, SLOT(toggleDirectory()));
76 connect(&fDirectoryWidget, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)), this, SLOT(loadFile(QListWidgetItem *)));
chudy@google.comc432f002012-07-10 13:19:25 +000077 connect(&fActionDelete, SIGNAL(triggered()), this, SLOT(actionDelete()));
chudy@google.comea5488b2012-07-26 19:38:22 +000078 connect(&fListWidget, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(toggleBreakpoint()));
chudy@google.comc432f002012-07-10 13:19:25 +000079 connect(&fActionRewind, SIGNAL(triggered()), this, SLOT(actionRewind()));
80 connect(&fActionPlay, SIGNAL(triggered()), this, SLOT(actionPlay()));
81 connect(&fActionStepBack, SIGNAL(triggered()), this, SLOT(actionStepBack()));
chudy@google.comea5488b2012-07-26 19:38:22 +000082 connect(&fActionStepForward, SIGNAL(triggered()), this, SLOT(actionStepForward()));
83 connect(&fActionBreakpoint, SIGNAL(triggered()), this, SLOT(actionBreakpoints()));
84 connect(&fActionInspector, SIGNAL(triggered()), this, SLOT(actionInspector()));
85 connect(&fActionInspector, SIGNAL(triggered()), this, SLOT(actionSettings()));
86 connect(&fFilter, SIGNAL(activated(QString)), this, SLOT(toggleFilter(QString)));
robertphillips@google.comd26c7062012-11-12 20:42:12 +000087 connect(&fActionProfile, SIGNAL(triggered()), this, SLOT(actionProfile()));
chudy@google.comc432f002012-07-10 13:19:25 +000088 connect(&fActionCancel, SIGNAL(triggered()), this, SLOT(actionCancel()));
chudy@google.com7e4cfbf2012-07-17 15:40:51 +000089 connect(&fActionClearBreakpoints, SIGNAL(triggered()), this, SLOT(actionClearBreakpoints()));
90 connect(&fActionClearDeletes, SIGNAL(triggered()), this, SLOT(actionClearDeletes()));
chudy@google.comc432f002012-07-10 13:19:25 +000091 connect(&fActionClose, SIGNAL(triggered()), this, SLOT(actionClose()));
chudy@google.comea5488b2012-07-26 19:38:22 +000092 connect(fSettingsWidget.getVisibilityButton(), SIGNAL(toggled(bool)), this, SLOT(actionCommandFilter()));
robertphillips@google.come8fe4bc2013-02-13 13:26:13 +000093#if SK_SUPPORT_GPU
chudy@google.comea5488b2012-07-26 19:38:22 +000094 connect(fSettingsWidget.getGLCheckBox(), SIGNAL(toggled(bool)), this, SLOT(actionGLWidget(bool)));
robertphillips@google.come8fe4bc2013-02-13 13:26:13 +000095#endif
chudy@google.comea5488b2012-07-26 19:38:22 +000096 connect(fSettingsWidget.getRasterCheckBox(), SIGNAL(toggled(bool)), this, SLOT(actionRasterWidget(bool)));
robertphillips@google.comf4741c12013-02-06 20:13:54 +000097 connect(fSettingsWidget.getOverdrawVizCheckBox(), SIGNAL(toggled(bool)), this, SLOT(actionOverdrawVizWidget(bool)));
chudy@google.comea5488b2012-07-26 19:38:22 +000098 connect(&fActionPause, SIGNAL(toggled(bool)), this, SLOT(pauseDrawing(bool)));
chudy@google.come504de02012-07-16 18:35:23 +000099 connect(&fActionCreateBreakpoint, SIGNAL(activated()), this, SLOT(toggleBreakpoint()));
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000100 connect(&fActionShowDeletes, SIGNAL(triggered()), this, SLOT(showDeletes()));
chudy@google.comea5488b2012-07-26 19:38:22 +0000101 connect(&fCanvasWidget, SIGNAL(hitChanged(int)), this, SLOT(selectCommand(int)));
102 connect(&fCanvasWidget, SIGNAL(hitChanged(int)), &fSettingsWidget, SLOT(updateHit(int)));
103 connect(&fCanvasWidget, SIGNAL(scaleFactorChanged(float)), this, SLOT(actionScale(float)));
104 connect(&fCanvasWidget, SIGNAL(commandChanged(int)), &fSettingsWidget, SLOT(updateCommand(int)));
chudy@google.com0ab03392012-07-28 20:16:11 +0000105 connect(&fActionSaveAs, SIGNAL(triggered()), this, SLOT(actionSaveAs()));
106 connect(&fActionSave, SIGNAL(triggered()), this, SLOT(actionSave()));
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000107
bungeman@google.come8cc6e82013-01-17 16:30:56 +0000108 fMapper.setMapping(&fActionZoomIn, SkCanvasWidget::kIn_ZoomCommand);
109 fMapper.setMapping(&fActionZoomOut, SkCanvasWidget::kOut_ZoomCommand);
chudy@google.coma1226312012-07-26 20:26:44 +0000110
111 connect(&fActionZoomIn, SIGNAL(triggered()), &fMapper, SLOT(map()));
112 connect(&fActionZoomOut, SIGNAL(triggered()), &fMapper, SLOT(map()));
bungeman@google.come8cc6e82013-01-17 16:30:56 +0000113 connect(&fMapper, SIGNAL(mapped(int)), &fCanvasWidget, SLOT(zoom(int)));
chudy@google.coma1226312012-07-26 20:26:44 +0000114
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000115 fInspectorWidget.setDisabled(true);
chudy@google.comd3058f52012-07-19 13:41:27 +0000116 fMenuEdit.setDisabled(true);
117 fMenuNavigate.setDisabled(true);
118 fMenuView.setDisabled(true);
chudy@google.combbad34d2012-08-13 14:26:36 +0000119
120 SkGraphics::Init();
chudy@google.com902ebe52012-06-29 14:21:22 +0000121}
122
chudy@google.combbad34d2012-08-13 14:26:36 +0000123SkDebuggerGUI::~SkDebuggerGUI() {
124 SkGraphics::Term();
125}
chudy@google.com902ebe52012-06-29 14:21:22 +0000126
127void SkDebuggerGUI::actionBreakpoints() {
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000128 fBreakpointsActivated = !fBreakpointsActivated;
chudy@google.comc432f002012-07-10 13:19:25 +0000129 for (int row = 0; row < fListWidget.count(); row++) {
130 QListWidgetItem *item = fListWidget.item(row);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000131 item->setHidden(item->checkState() == Qt::Unchecked && fBreakpointsActivated);
132 }
133}
chudy@google.com902ebe52012-06-29 14:21:22 +0000134
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000135void SkDebuggerGUI::showDeletes() {
136 fDeletesActivated = !fDeletesActivated;
137 for (int row = 0; row < fListWidget.count(); row++) {
138 QListWidgetItem *item = fListWidget.item(row);
chudy@google.com607357f2012-08-07 16:12:23 +0000139 item->setHidden(fDebugger.isCommandVisible(row)
140 && fDeletesActivated);
chudy@google.com902ebe52012-06-29 14:21:22 +0000141 }
142}
143
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000144// The timed picture playback uses the SkPicturePlayback's profiling stubs
145// to time individual commands. The offsets are needed to map SkPicture
146// offsets to individual commands.
147class SkTimedPicturePlayback : public SkPicturePlayback {
148public:
scroggo@google.com12d588a2013-02-25 16:05:00 +0000149 SkTimedPicturePlayback(SkStream* stream, const SkPictInfo& info,
skia.committer@gmail.com3e2345a2013-05-24 07:01:26 +0000150 SkPicture::InstallPixelRefProc proc,
robertphillips@google.com5f971142012-12-07 20:48:56 +0000151 const SkTDArray<bool>& deletedCommands)
scroggo@google.com12d588a2013-02-25 16:05:00 +0000152 : INHERITED(stream, info, proc)
bungeman@google.come8cc6e82013-01-17 16:30:56 +0000153 , fSkipCommands(deletedCommands)
154 , fTot(0.0)
155 , fCurCommand(0) {
robertphillips@google.com6d9c92b2013-05-23 13:21:18 +0000156 fTimes.setCount(deletedCommands.count());
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000157 fTypeTimes.setCount(LAST_DRAWTYPE_ENUM+1);
158 this->resetTimes();
159 }
160
161 void resetTimes() {
robertphillips@google.com6d9c92b2013-05-23 13:21:18 +0000162 for (int i = 0; i < fTimes.count(); ++i) {
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000163 fTimes[i] = 0.0;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000164 }
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000165 for (int i = 0; i < fTypeTimes.count(); ++i) {
166 fTypeTimes[i] = 0.0f;
167 }
168 fTot = 0.0;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000169 }
170
171 int count() const { return fTimes.count(); }
172
173 double time(int index) const { return fTimes[index] / fTot; }
174
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000175 const SkTDArray<double>* typeTimes() const { return &fTypeTimes; }
176
177 double totTime() const { return fTot; }
178
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000179protected:
robertphillips@google.come174a8b2012-11-27 16:04:42 +0000180 BenchSysTimer fTimer;
robertphillips@google.com5f971142012-12-07 20:48:56 +0000181 SkTDArray<bool> fSkipCommands; // has the command been deleted in the GUI?
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000182 SkTDArray<double> fTimes; // sum of time consumed for each command
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000183 SkTDArray<double> fTypeTimes; // sum of time consumed for each type of command (e.g., drawPath)
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000184 double fTot; // total of all times in 'fTimes'
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000185 int fCurType;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000186 int fCurCommand; // the current command being executed/timed
187
robertphillips@google.com6d9c92b2013-05-23 13:21:18 +0000188#ifdef SK_DEVELOPER
189 virtual bool preDraw(int opIndex, int type) SK_OVERRIDE {
190 fCurCommand = opIndex;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000191
robertphillips@google.com5f971142012-12-07 20:48:56 +0000192 if (fSkipCommands[fCurCommand]) {
robertphillips@google.com6d9c92b2013-05-23 13:21:18 +0000193 return true;
robertphillips@google.com5f971142012-12-07 20:48:56 +0000194 }
195
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000196 fCurType = type;
197 // The SkDebugCanvas doesn't recognize these types. This class needs to
198 // convert or else we'll wind up with a mismatch between the type counts
199 // the debugger displays and the profile times.
200 if (DRAW_POS_TEXT_TOP_BOTTOM == type) {
201 fCurType = DRAW_POS_TEXT;
202 } else if (DRAW_POS_TEXT_H_TOP_BOTTOM == type) {
203 fCurType = DRAW_POS_TEXT_H;
204 }
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000205
robertphillips@google.come174a8b2012-11-27 16:04:42 +0000206#if defined(SK_BUILD_FOR_WIN32)
207 // CPU timer doesn't work well on Windows
208 fTimer.startWall();
209#else
210 fTimer.startCpu();
211#endif
robertphillips@google.com5f971142012-12-07 20:48:56 +0000212
robertphillips@google.com6d9c92b2013-05-23 13:21:18 +0000213 return false;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000214 }
215
robertphillips@google.com6d9c92b2013-05-23 13:21:18 +0000216 virtual void postDraw(int opIndex) SK_OVERRIDE {
robertphillips@google.come174a8b2012-11-27 16:04:42 +0000217#if defined(SK_BUILD_FOR_WIN32)
218 // CPU timer doesn't work well on Windows
219 double time = fTimer.endWall();
220#else
221 double time = fTimer.endCpu();
222#endif
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000223
robertphillips@google.com6d9c92b2013-05-23 13:21:18 +0000224 SkASSERT(opIndex == fCurCommand);
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000225 SkASSERT(fCurType <= LAST_DRAWTYPE_ENUM);
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000226
robertphillips@google.come174a8b2012-11-27 16:04:42 +0000227 fTimes[fCurCommand] += time;
228 fTypeTimes[fCurType] += time;
229 fTot += time;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000230 }
robertphillips@google.com6d9c92b2013-05-23 13:21:18 +0000231#endif
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000232
233private:
234 typedef SkPicturePlayback INHERITED;
235};
236
237// Wrap SkPicture to allow installation of an SkTimedPicturePlayback object
238class SkTimedPicture : public SkPicture {
239public:
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000240 static SkTimedPicture* CreateTimedPicture(SkStream* stream,
241 SkPicture::InstallPixelRefProc proc,
242 const SkTDArray<bool>& deletedCommands) {
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000243 SkPictInfo info;
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000244 if (!StreamIsSKP(stream, &info)) {
245 return NULL;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000246 }
247
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000248 SkTimedPicturePlayback* playback;
249 // Check to see if there is a playback to recreate.
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000250 if (stream->readBool()) {
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000251 playback = SkNEW_ARGS(SkTimedPicturePlayback,
252 (stream, info, proc, deletedCommands));
253 } else {
254 playback = NULL;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000255 }
256
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000257 return SkNEW_ARGS(SkTimedPicture, (playback, info.fWidth, info.fHeight));
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000258 }
259
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000260 void resetTimes() { ((SkTimedPicturePlayback*) fPlayback)->resetTimes(); }
261
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000262 int count() const { return ((SkTimedPicturePlayback*) fPlayback)->count(); }
263
264 // return the fraction of the total time this command consumed
265 double time(int index) const { return ((SkTimedPicturePlayback*) fPlayback)->time(index); }
266
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000267 const SkTDArray<double>* typeTimes() const { return ((SkTimedPicturePlayback*) fPlayback)->typeTimes(); }
268
269 double totTime() const { return ((SkTimedPicturePlayback*) fPlayback)->totTime(); }
270
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000271private:
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000272 // disallow default ctor b.c. we don't have a good way to setup the fPlayback ptr
273 SkTimedPicture();
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000274 // Private ctor only used by CreateTimedPicture, which has created the playback.
275 SkTimedPicture(SkTimedPicturePlayback* playback, int width, int height)
276 : INHERITED(playback, width, height) {}
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000277 // disallow the copy ctor - enabling would require copying code from SkPicture
278 SkTimedPicture(const SkTimedPicture& src);
279
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000280 typedef SkPicture INHERITED;
281};
282
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000283// This is a simplification of PictureBenchmark's run with the addition of
284// clearing of the times after the first pass (in resetTimes)
skia.committer@gmail.com34587162012-11-20 02:01:23 +0000285void SkDebuggerGUI::run(SkTimedPicture* pict,
286 sk_tools::PictureRenderer* renderer,
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000287 int repeats) {
288 SkASSERT(pict);
289 if (NULL == pict) {
290 return;
291 }
292
293 SkASSERT(renderer != NULL);
294 if (NULL == renderer) {
295 return;
296 }
297
298 renderer->init(pict);
299
300 renderer->setup();
301 renderer->render(NULL);
jvanverth@google.comade32662013-01-28 21:09:05 +0000302 renderer->resetState(true);
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000303
304 // We throw this away the first batch of times to remove first time effects (such as paging in this program)
305 pict->resetTimes();
306
307 for (int i = 0; i < repeats; ++i) {
308 renderer->setup();
309 renderer->render(NULL);
jvanverth@google.comade32662013-01-28 21:09:05 +0000310 renderer->resetState(true);
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000311 }
312
313 renderer->end();
314}
315
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000316void SkDebuggerGUI::actionProfile() {
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000317 // In order to profile we pass the command offsets (that were read-in
318 // in loadPicture by the SkOffsetPicture) to an SkTimedPlaybackPicture.
skia.committer@gmail.com884e60b2012-11-16 02:01:17 +0000319 // The SkTimedPlaybackPicture in turn passes the offsets to an
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000320 // SkTimedPicturePlayback object which uses them to track the performance
321 // of individual commands.
322 if (fFileName.isEmpty()) {
323 return;
324 }
325
326 SkFILEStream inputStream;
327
328 inputStream.setPath(fFileName.c_str());
329 if (!inputStream.isValid()) {
330 return;
331 }
332
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000333 SkAutoTUnref<SkTimedPicture> picture(SkTimedPicture::CreateTimedPicture(&inputStream,
334 &SkImageDecoder::DecodeMemory, fSkipCommands));
335 if (NULL == picture.get()) {
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000336 return;
337 }
338
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000339 // For now this #if allows switching between tiled and simple rendering
340 // modes. Eventually this will be accomplished via the GUI
robertphillips@google.come174a8b2012-11-27 16:04:42 +0000341#if 0
342 // With the current batch of SysTimers, profiling in tiled mode
343 // gets swamped by the timing overhead:
344 //
345 // tile mode simple mode
346 // debugger 64.2ms 12.8ms
347 // bench_pictures 16.9ms 12.4ms
348 //
349 // This is b.c. in tiled mode each command is called many more times
350 // but typically does less work on each invocation (due to clipping)
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000351 sk_tools::TiledPictureRenderer* renderer = NULL;
352
353 renderer = SkNEW(sk_tools::TiledPictureRenderer);
354 renderer->setTileWidth(256);
355 renderer->setTileHeight(256);
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000356#else
357 sk_tools::SimplePictureRenderer* renderer = NULL;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000358
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000359 renderer = SkNEW(sk_tools::SimplePictureRenderer);
robertphillips@google.com1447aa32013-01-30 21:09:09 +0000360
361#if SK_SUPPORT_GPU
362 if (Qt::Checked == fSettingsWidget.getGLCheckBox()->checkState()) {
363 renderer->setDeviceType(sk_tools::PictureRenderer::kGPU_DeviceType);
364 }
365#endif
366
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000367#endif
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000368
robertphillips@google.come174a8b2012-11-27 16:04:42 +0000369 static const int kNumRepeats = 10;
370
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000371 run(picture.get(), renderer, kNumRepeats);
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000372
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000373 SkASSERT(picture->count() == fListWidget.count());
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000374
375 // extract the individual command times from the SkTimedPlaybackPicture
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000376 for (int i = 0; i < picture->count(); ++i) {
377 double temp = picture->time(i);
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000378
379 QListWidgetItem* item = fListWidget.item(i);
380
381 item->setData(Qt::UserRole + 4, 100.0*temp);
382 }
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000383
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000384 setupOverviewText(picture->typeTimes(), picture->totTime(), kNumRepeats);
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000385}
386
chudy@google.com902ebe52012-06-29 14:21:22 +0000387void SkDebuggerGUI::actionCancel() {
chudy@google.comc432f002012-07-10 13:19:25 +0000388 for (int row = 0; row < fListWidget.count(); row++) {
389 fListWidget.item(row)->setHidden(false);
chudy@google.com902ebe52012-06-29 14:21:22 +0000390 }
391}
392
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000393void SkDebuggerGUI::actionClearBreakpoints() {
394 for (int row = 0; row < fListWidget.count(); row++) {
395 QListWidgetItem* item = fListWidget.item(row);
396 item->setCheckState(Qt::Unchecked);
397 item->setData(Qt::DecorationRole,
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000398 QPixmap(":/blank.png"));
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000399 }
400}
401
402void SkDebuggerGUI::actionClearDeletes() {
403 for (int row = 0; row < fListWidget.count(); row++) {
404 QListWidgetItem* item = fListWidget.item(row);
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000405 item->setData(Qt::UserRole + 2, QPixmap(":/blank.png"));
chudy@google.com607357f2012-08-07 16:12:23 +0000406 fDebugger.setCommandVisible(row, true);
robertphillips@google.com5f971142012-12-07 20:48:56 +0000407 fSkipCommands[row] = false;
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000408 }
409 if (fPause) {
410 fCanvasWidget.drawTo(fPausedRow);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000411 fImageWidget.draw();
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000412 } else {
413 fCanvasWidget.drawTo(fListWidget.currentRow());
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000414 fImageWidget.draw();
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000415 }
416}
417
chudy@google.com902ebe52012-06-29 14:21:22 +0000418void SkDebuggerGUI::actionCommandFilter() {
chudy@google.com607357f2012-08-07 16:12:23 +0000419 fDebugger.highlightCurrentCommand(
chudy@google.comc432f002012-07-10 13:19:25 +0000420 fSettingsWidget.getVisibilityButton()->isChecked());
421 fCanvasWidget.drawTo(fListWidget.currentRow());
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000422 fImageWidget.draw();
chudy@google.com902ebe52012-06-29 14:21:22 +0000423}
424
425void SkDebuggerGUI::actionClose() {
426 this->close();
427}
428
429void SkDebuggerGUI::actionDelete() {
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000430
robertphillips@google.comdd4b7452013-01-22 19:38:46 +0000431 for (int row = 0; row < fListWidget.count(); ++row) {
432 QListWidgetItem* item = fListWidget.item(row);
433
434 if (!item->isSelected()) {
435 continue;
436 }
437
438 if (fDebugger.isCommandVisible(row)) {
439 item->setData(Qt::UserRole + 2, QPixmap(":/delete.png"));
440 fDebugger.setCommandVisible(row, false);
441 fSkipCommands[row] = true;
442 } else {
443 item->setData(Qt::UserRole + 2, QPixmap(":/blank.png"));
444 fDebugger.setCommandVisible(row, true);
445 fSkipCommands[row] = false;
446 }
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000447 }
448
robertphillips@google.comdd4b7452013-01-22 19:38:46 +0000449 int currentRow = fListWidget.currentRow();
450
chudy@google.come504de02012-07-16 18:35:23 +0000451 if (fPause) {
452 fCanvasWidget.drawTo(fPausedRow);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000453 fImageWidget.draw();
chudy@google.come504de02012-07-16 18:35:23 +0000454 } else {
455 fCanvasWidget.drawTo(currentRow);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000456 fImageWidget.draw();
chudy@google.come504de02012-07-16 18:35:23 +0000457 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000458}
459
robertphillips@google.come8fe4bc2013-02-13 13:26:13 +0000460#if SK_SUPPORT_GPU
chudy@google.comea5488b2012-07-26 19:38:22 +0000461void SkDebuggerGUI::actionGLWidget(bool isToggled) {
462 fCanvasWidget.setWidgetVisibility(SkCanvasWidget::kGPU_WidgetType, !isToggled);
463}
robertphillips@google.come8fe4bc2013-02-13 13:26:13 +0000464#endif
chudy@google.comea5488b2012-07-26 19:38:22 +0000465
chudy@google.com902ebe52012-06-29 14:21:22 +0000466void SkDebuggerGUI::actionInspector() {
chudy@google.comc432f002012-07-10 13:19:25 +0000467 if (fInspectorWidget.isHidden()) {
468 fInspectorWidget.setHidden(false);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000469 fImageWidget.setHidden(false);
chudy@google.com902ebe52012-06-29 14:21:22 +0000470 } else {
chudy@google.comc432f002012-07-10 13:19:25 +0000471 fInspectorWidget.setHidden(true);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000472 fImageWidget.setHidden(true);
chudy@google.com902ebe52012-06-29 14:21:22 +0000473 }
474}
475
476void SkDebuggerGUI::actionPlay() {
chudy@google.comc432f002012-07-10 13:19:25 +0000477 for (int row = fListWidget.currentRow() + 1; row < fListWidget.count();
chudy@google.com7dcae672012-07-09 20:26:53 +0000478 row++) {
chudy@google.comc432f002012-07-10 13:19:25 +0000479 QListWidgetItem *item = fListWidget.item(row);
chudy@google.com902ebe52012-06-29 14:21:22 +0000480 if (item->checkState() == Qt::Checked) {
chudy@google.comc432f002012-07-10 13:19:25 +0000481 fListWidget.setCurrentItem(item);
chudy@google.com902ebe52012-06-29 14:21:22 +0000482 return;
483 }
484 }
chudy@google.comc432f002012-07-10 13:19:25 +0000485 fListWidget.setCurrentRow(fListWidget.count() - 1);
chudy@google.com902ebe52012-06-29 14:21:22 +0000486}
487
chudy@google.comea5488b2012-07-26 19:38:22 +0000488void SkDebuggerGUI::actionRasterWidget(bool isToggled) {
489 fCanvasWidget.setWidgetVisibility(SkCanvasWidget::kRaster_8888_WidgetType, !isToggled);
490}
491
robertphillips@google.comf4741c12013-02-06 20:13:54 +0000492void SkDebuggerGUI::actionOverdrawVizWidget(bool isToggled) {
493 fDebugger.setOverdrawViz(isToggled);
494 fCanvasWidget.update();
495}
496
chudy@google.com902ebe52012-06-29 14:21:22 +0000497void SkDebuggerGUI::actionRewind() {
chudy@google.come504de02012-07-16 18:35:23 +0000498 fListWidget.setCurrentRow(0);
chudy@google.com902ebe52012-06-29 14:21:22 +0000499}
500
chudy@google.com0ab03392012-07-28 20:16:11 +0000501void SkDebuggerGUI::actionSave() {
robertphillips@google.come219baf2013-01-28 19:25:43 +0000502 fFileName = fPath.toAscii().data();
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000503 fFileName.append("/");
robertphillips@google.come219baf2013-01-28 19:25:43 +0000504 fFileName.append(fDirectoryWidget.currentItem()->text().toAscii().data());
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000505 saveToFile(fFileName);
chudy@google.com0ab03392012-07-28 20:16:11 +0000506}
507
508void SkDebuggerGUI::actionSaveAs() {
509 QString filename = QFileDialog::getSaveFileName(this, "Save File", "",
510 "Skia Picture (*skp)");
chudy@google.com38b08ce2012-07-28 23:26:10 +0000511 if (!filename.endsWith(".skp", Qt::CaseInsensitive)) {
chudy@google.com0ab03392012-07-28 20:16:11 +0000512 filename.append(".skp");
513 }
djsollen@google.comc3c82162012-11-13 18:35:10 +0000514 saveToFile(SkString(filename.toAscii().data()));
chudy@google.com0ab03392012-07-28 20:16:11 +0000515}
516
chudy@google.com7dcae672012-07-09 20:26:53 +0000517void SkDebuggerGUI::actionScale(float scaleFactor) {
chudy@google.comc432f002012-07-10 13:19:25 +0000518 fSettingsWidget.setZoomText(scaleFactor);
chudy@google.com7dcae672012-07-09 20:26:53 +0000519}
520
chudy@google.com902ebe52012-06-29 14:21:22 +0000521void SkDebuggerGUI::actionSettings() {
chudy@google.comc432f002012-07-10 13:19:25 +0000522 if (fSettingsWidget.isHidden()) {
523 fSettingsWidget.setHidden(false);
chudy@google.com902ebe52012-06-29 14:21:22 +0000524 } else {
chudy@google.comc432f002012-07-10 13:19:25 +0000525 fSettingsWidget.setHidden(true);
chudy@google.com902ebe52012-06-29 14:21:22 +0000526 }
527}
528
529void SkDebuggerGUI::actionStepBack() {
chudy@google.comc432f002012-07-10 13:19:25 +0000530 int currentRow = fListWidget.currentRow();
chudy@google.com902ebe52012-06-29 14:21:22 +0000531 if (currentRow != 0) {
chudy@google.comc432f002012-07-10 13:19:25 +0000532 fListWidget.setCurrentRow(currentRow - 1);
chudy@google.com902ebe52012-06-29 14:21:22 +0000533 }
534}
535
536void SkDebuggerGUI::actionStepForward() {
chudy@google.comc432f002012-07-10 13:19:25 +0000537 int currentRow = fListWidget.currentRow();
chudy@google.com902ebe52012-06-29 14:21:22 +0000538 QString curRow = QString::number(currentRow);
chudy@google.comc432f002012-07-10 13:19:25 +0000539 QString curCount = QString::number(fListWidget.count());
540 if (currentRow < fListWidget.count() - 1) {
541 fListWidget.setCurrentRow(currentRow + 1);
chudy@google.com902ebe52012-06-29 14:21:22 +0000542 }
543}
544
chudy@google.coma9e937c2012-08-03 17:32:05 +0000545void SkDebuggerGUI::drawComplete() {
chudy@google.com607357f2012-08-07 16:12:23 +0000546 fInspectorWidget.setMatrix(fDebugger.getCurrentMatrix());
547 fInspectorWidget.setClip(fDebugger.getCurrentClip());
chudy@google.coma9e937c2012-08-03 17:32:05 +0000548}
549
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000550void SkDebuggerGUI::saveToFile(const SkString& filename) {
551 SkFILEWStream file(filename.c_str());
robertphillips@google.com25bc2f82013-01-22 18:03:56 +0000552 SkAutoTUnref<SkPicture> copy(fDebugger.copyPicture());
553
554 copy->serialize(&file);
chudy@google.com0ab03392012-07-28 20:16:11 +0000555}
556
chudy@google.com902ebe52012-06-29 14:21:22 +0000557void SkDebuggerGUI::loadFile(QListWidgetItem *item) {
558 if (fDirectoryWidgetActive) {
robertphillips@google.come219baf2013-01-28 19:25:43 +0000559 fFileName = fPath.toAscii().data();
jvanverth@google.com0ac6f162013-02-05 19:44:07 +0000560 // don't add a '/' to files in the local directory
561 if (fFileName.size() > 0) {
562 fFileName.append("/");
563 }
robertphillips@google.come219baf2013-01-28 19:25:43 +0000564 fFileName.append(item->text().toAscii().data());
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000565 loadPicture(fFileName);
chudy@google.com902ebe52012-06-29 14:21:22 +0000566 }
567}
568
569void SkDebuggerGUI::openFile() {
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000570 QString temp = QFileDialog::getOpenFileName(this, tr("Open File"), "",
chudy@google.com7dcae672012-07-09 20:26:53 +0000571 tr("Files (*.*)"));
robertphillips@google.comff6e6ba2013-01-28 17:43:26 +0000572 openFile(temp);
573}
574
575void SkDebuggerGUI::openFile(const QString &filename) {
chudy@google.com902ebe52012-06-29 14:21:22 +0000576 fDirectoryWidgetActive = false;
robertphillips@google.comff6e6ba2013-01-28 17:43:26 +0000577 if (!filename.isEmpty()) {
578 QFileInfo pathInfo(filename);
579 loadPicture(SkString(filename.toAscii().data()));
580 setupDirectoryWidget(pathInfo.path());
chudy@google.com902ebe52012-06-29 14:21:22 +0000581 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000582 fDirectoryWidgetActive = true;
583}
584
chudy@google.comc432f002012-07-10 13:19:25 +0000585void SkDebuggerGUI::pauseDrawing(bool isPaused) {
chudy@google.com607357f2012-08-07 16:12:23 +0000586 fPause = isPaused;
587 fPausedRow = fListWidget.currentRow();
588 fCanvasWidget.drawTo(fPausedRow);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000589 fImageWidget.draw();
chudy@google.com7dcae672012-07-09 20:26:53 +0000590}
591
chudy@google.com902ebe52012-06-29 14:21:22 +0000592void SkDebuggerGUI::registerListClick(QListWidgetItem *item) {
chudy@google.comd3058f52012-07-19 13:41:27 +0000593 if(!fLoading) {
594 int currentRow = fListWidget.currentRow();
chudy@google.comd3058f52012-07-19 13:41:27 +0000595
chudy@google.comea5488b2012-07-26 19:38:22 +0000596 if (currentRow != -1) {
597 if (!fPause) {
598 fCanvasWidget.drawTo(currentRow);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000599 fImageWidget.draw();
chudy@google.comd3058f52012-07-19 13:41:27 +0000600 }
chudy@google.com97cee972012-08-07 20:41:37 +0000601 SkTDArray<SkString*> *currInfo = fDebugger.getCommandInfo(
chudy@google.comea5488b2012-07-26 19:38:22 +0000602 currentRow);
603
604 /* TODO(chudy): Add command type before parameters. Rename v
605 * to something more informative. */
chudy@google.com97cee972012-08-07 20:41:37 +0000606 if (currInfo) {
chudy@google.comea5488b2012-07-26 19:38:22 +0000607 QString info;
608 info.append("<b>Parameters: </b><br/>");
chudy@google.com97cee972012-08-07 20:41:37 +0000609 for (int i = 0; i < currInfo->count(); i++) {
610
611 info.append(QString((*currInfo)[i]->c_str()));
chudy@google.comea5488b2012-07-26 19:38:22 +0000612 info.append("<br/>");
613 }
chudy@google.com6bd109a2012-08-14 19:34:13 +0000614 fInspectorWidget.setText(info, SkInspectorWidget::kDetail_TabType);
chudy@google.comea5488b2012-07-26 19:38:22 +0000615 fInspectorWidget.setDisabled(false);
chudy@google.comea5488b2012-07-26 19:38:22 +0000616 }
chudy@google.comd3058f52012-07-19 13:41:27 +0000617 }
chudy@google.comea5488b2012-07-26 19:38:22 +0000618
chudy@google.com902ebe52012-06-29 14:21:22 +0000619 }
620}
621
chudy@google.com9ca9bfe2012-07-12 21:58:14 +0000622void SkDebuggerGUI::selectCommand(int command) {
623 if (fPause) {
624 fListWidget.setCurrentRow(command);
625 }
626}
627
chudy@google.com902ebe52012-06-29 14:21:22 +0000628void SkDebuggerGUI::toggleBreakpoint() {
chudy@google.comc432f002012-07-10 13:19:25 +0000629 QListWidgetItem* item = fListWidget.currentItem();
chudy@google.com902ebe52012-06-29 14:21:22 +0000630 if (item->checkState() == Qt::Unchecked) {
631 item->setCheckState(Qt::Checked);
chudy@google.come565de42012-07-12 14:15:54 +0000632 item->setData(Qt::DecorationRole,
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000633 QPixmap(":/breakpoint_16x16.png"));
chudy@google.com902ebe52012-06-29 14:21:22 +0000634 } else {
chudy@google.com902ebe52012-06-29 14:21:22 +0000635 item->setCheckState(Qt::Unchecked);
chudy@google.come565de42012-07-12 14:15:54 +0000636 item->setData(Qt::DecorationRole,
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000637 QPixmap(":/blank.png"));
chudy@google.com902ebe52012-06-29 14:21:22 +0000638 }
639}
640
641void SkDebuggerGUI::toggleDirectory() {
chudy@google.com607357f2012-08-07 16:12:23 +0000642 fDirectoryWidget.setHidden(!fDirectoryWidget.isHidden());
chudy@google.com902ebe52012-06-29 14:21:22 +0000643}
644
645void SkDebuggerGUI::toggleFilter(QString string) {
chudy@google.comc432f002012-07-10 13:19:25 +0000646 for (int row = 0; row < fListWidget.count(); row++) {
647 QListWidgetItem *item = fListWidget.item(row);
chudy@google.com607357f2012-08-07 16:12:23 +0000648 item->setHidden(item->text() != string);
chudy@google.com902ebe52012-06-29 14:21:22 +0000649 }
650}
651
652void SkDebuggerGUI::setupUi(QMainWindow *SkDebuggerGUI) {
653 QIcon windowIcon;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000654 windowIcon.addFile(QString::fromUtf8(":/skia.png"), QSize(),
chudy@google.com7dcae672012-07-09 20:26:53 +0000655 QIcon::Normal, QIcon::Off);
chudy@google.com902ebe52012-06-29 14:21:22 +0000656 SkDebuggerGUI->setObjectName(QString::fromUtf8("SkDebuggerGUI"));
657 SkDebuggerGUI->resize(1200, 1000);
658 SkDebuggerGUI->setWindowIcon(windowIcon);
chudy@google.comc432f002012-07-10 13:19:25 +0000659 SkDebuggerGUI->setWindowTitle("Skia Debugger");
chudy@google.com902ebe52012-06-29 14:21:22 +0000660
chudy@google.come504de02012-07-16 18:35:23 +0000661 fActionOpen.setShortcuts(QKeySequence::Open);
chudy@google.comc432f002012-07-10 13:19:25 +0000662 fActionOpen.setText("Open");
chudy@google.com902ebe52012-06-29 14:21:22 +0000663
664 QIcon breakpoint;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000665 breakpoint.addFile(QString::fromUtf8(":/breakpoint.png"),
chudy@google.com7dcae672012-07-09 20:26:53 +0000666 QSize(), QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000667 fActionBreakpoint.setShortcut(QKeySequence(tr("Ctrl+B")));
chudy@google.comc432f002012-07-10 13:19:25 +0000668 fActionBreakpoint.setIcon(breakpoint);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000669 fActionBreakpoint.setText("Breakpoints");
chudy@google.com902ebe52012-06-29 14:21:22 +0000670
671 QIcon cancel;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000672 cancel.addFile(QString::fromUtf8(":/reload.png"), QSize(),
chudy@google.com7dcae672012-07-09 20:26:53 +0000673 QIcon::Normal, QIcon::Off);
chudy@google.comc432f002012-07-10 13:19:25 +0000674 fActionCancel.setIcon(cancel);
675 fActionCancel.setText("Clear Filter");
chudy@google.com902ebe52012-06-29 14:21:22 +0000676
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000677 fActionClearBreakpoints.setShortcut(QKeySequence(tr("Alt+B")));
678 fActionClearBreakpoints.setText("Clear Breakpoints");
679
680 fActionClearDeletes.setShortcut(QKeySequence(tr("Alt+X")));
681 fActionClearDeletes.setText("Clear Deletes");
682
chudy@google.come504de02012-07-16 18:35:23 +0000683 fActionClose.setShortcuts(QKeySequence::Quit);
chudy@google.comc432f002012-07-10 13:19:25 +0000684 fActionClose.setText("Exit");
chudy@google.com902ebe52012-06-29 14:21:22 +0000685
chudy@google.come504de02012-07-16 18:35:23 +0000686 fActionCreateBreakpoint.setShortcut(QKeySequence(tr("B")));
687 fActionCreateBreakpoint.setText("Set Breakpoint");
688
689 fActionDelete.setShortcut(QKeySequence(tr("X")));
chudy@google.comc432f002012-07-10 13:19:25 +0000690 fActionDelete.setText("Delete Command");
chudy@google.com902ebe52012-06-29 14:21:22 +0000691
chudy@google.come504de02012-07-16 18:35:23 +0000692 fActionDirectory.setShortcut(QKeySequence(tr("Ctrl+D")));
693 fActionDirectory.setText("Directory");
chudy@google.com902ebe52012-06-29 14:21:22 +0000694
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000695 QIcon profile;
robertphillips@google.comd1636362012-11-19 18:25:09 +0000696 profile.addFile(QString::fromUtf8(":/profile.png"), QSize(),
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000697 QIcon::Normal, QIcon::Off);
698 fActionProfile.setIcon(profile);
699 fActionProfile.setText("Profile");
robertphillips@google.come099bc42012-11-19 16:26:40 +0000700 fActionProfile.setDisabled(true);
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000701
chudy@google.comc432f002012-07-10 13:19:25 +0000702 QIcon inspector;
robertphillips@google.comd1636362012-11-19 18:25:09 +0000703 inspector.addFile(QString::fromUtf8(":/inspector.png"),
chudy@google.comc432f002012-07-10 13:19:25 +0000704 QSize(), QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000705 fActionInspector.setShortcut(QKeySequence(tr("Ctrl+I")));
chudy@google.comc432f002012-07-10 13:19:25 +0000706 fActionInspector.setIcon(inspector);
chudy@google.come504de02012-07-16 18:35:23 +0000707 fActionInspector.setText("Inspector");
chudy@google.com902ebe52012-06-29 14:21:22 +0000708
chudy@google.comc432f002012-07-10 13:19:25 +0000709 QIcon play;
robertphillips@google.comd1636362012-11-19 18:25:09 +0000710 play.addFile(QString::fromUtf8(":/play.png"), QSize(),
chudy@google.comc432f002012-07-10 13:19:25 +0000711 QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000712 fActionPlay.setShortcut(QKeySequence(tr("Ctrl+P")));
chudy@google.comc432f002012-07-10 13:19:25 +0000713 fActionPlay.setIcon(play);
714 fActionPlay.setText("Play");
chudy@google.com902ebe52012-06-29 14:21:22 +0000715
chudy@google.come504de02012-07-16 18:35:23 +0000716 QIcon pause;
robertphillips@google.comd1636362012-11-19 18:25:09 +0000717 pause.addFile(QString::fromUtf8(":/pause.png"), QSize(),
chudy@google.comc432f002012-07-10 13:19:25 +0000718 QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000719 fActionPause.setShortcut(QKeySequence(tr("Space")));
720 fActionPause.setCheckable(true);
721 fActionPause.setIcon(pause);
722 fActionPause.setText("Pause");
723
chudy@google.comc432f002012-07-10 13:19:25 +0000724 QIcon rewind;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000725 rewind.addFile(QString::fromUtf8(":/rewind.png"), QSize(),
chudy@google.comc432f002012-07-10 13:19:25 +0000726 QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000727 fActionRewind.setShortcut(QKeySequence(tr("Ctrl+R")));
chudy@google.comc432f002012-07-10 13:19:25 +0000728 fActionRewind.setIcon(rewind);
729 fActionRewind.setText("Rewind");
chudy@google.com902ebe52012-06-29 14:21:22 +0000730
chudy@google.com0ab03392012-07-28 20:16:11 +0000731 fActionSave.setShortcut(QKeySequence::Save);
732 fActionSave.setText("Save");
733 fActionSave.setDisabled(true);
734 fActionSaveAs.setShortcut(QKeySequence::SaveAs);
735 fActionSaveAs.setText("Save As");
736 fActionSaveAs.setDisabled(true);
737
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000738 fActionShowDeletes.setShortcut(QKeySequence(tr("Ctrl+X")));
739 fActionShowDeletes.setText("Deleted Commands");
740
chudy@google.comc432f002012-07-10 13:19:25 +0000741 QIcon stepBack;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000742 stepBack.addFile(QString::fromUtf8(":/previous.png"), QSize(),
chudy@google.comc432f002012-07-10 13:19:25 +0000743 QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000744 fActionStepBack.setShortcut(QKeySequence(tr("[")));
chudy@google.comc432f002012-07-10 13:19:25 +0000745 fActionStepBack.setIcon(stepBack);
746 fActionStepBack.setText("Step Back");
chudy@google.com902ebe52012-06-29 14:21:22 +0000747
chudy@google.comc432f002012-07-10 13:19:25 +0000748 QIcon stepForward;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000749 stepForward.addFile(QString::fromUtf8(":/next.png"),
chudy@google.comc432f002012-07-10 13:19:25 +0000750 QSize(), QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000751 fActionStepForward.setShortcut(QKeySequence(tr("]")));
chudy@google.comc432f002012-07-10 13:19:25 +0000752 fActionStepForward.setIcon(stepForward);
753 fActionStepForward.setText("Step Forward");
754
chudy@google.coma1226312012-07-26 20:26:44 +0000755 fActionZoomIn.setShortcut(QKeySequence(tr("Ctrl+=")));
756 fActionZoomIn.setText("Zoom In");
757 fActionZoomOut.setShortcut(QKeySequence(tr("Ctrl+-")));
758 fActionZoomOut.setText("Zoom Out");
759
chudy@google.comc432f002012-07-10 13:19:25 +0000760 fListWidget.setItemDelegate(new SkListWidget(&fListWidget));
761 fListWidget.setObjectName(QString::fromUtf8("listWidget"));
762 fListWidget.setMaximumWidth(250);
763
764 fFilter.addItem("--Filter By Available Commands--");
765
766 fDirectoryWidget.setMaximumWidth(250);
767 fDirectoryWidget.setStyleSheet("QListWidget::Item {padding: 5px;}");
768
769 fCanvasWidget.setSizePolicy(QSizePolicy::Expanding,
chudy@google.com7dcae672012-07-09 20:26:53 +0000770 QSizePolicy::Expanding);
chudy@google.com902ebe52012-06-29 14:21:22 +0000771
skia.committer@gmail.com1c9c0d32012-11-22 02:02:41 +0000772 fImageWidget.setFixedSize(SkImageWidget::kImageWidgetWidth,
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000773 SkImageWidget::kImageWidgetHeight);
774
chudy@google.comc432f002012-07-10 13:19:25 +0000775 fInspectorWidget.setSizePolicy(QSizePolicy::Expanding,
chudy@google.com7dcae672012-07-09 20:26:53 +0000776 QSizePolicy::Expanding);
chudy@google.comc432f002012-07-10 13:19:25 +0000777 fInspectorWidget.setMaximumHeight(300);
chudy@google.com902ebe52012-06-29 14:21:22 +0000778
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000779 fSettingsAndImageLayout.setSpacing(6);
780 fSettingsAndImageLayout.addWidget(&fSettingsWidget);
781 fSettingsAndImageLayout.addWidget(&fImageWidget);
782
chudy@google.comc432f002012-07-10 13:19:25 +0000783 fSettingsWidget.setSizePolicy(QSizePolicy::Expanding,
784 QSizePolicy::Expanding);
785 fSettingsWidget.setMaximumWidth(250);
chudy@google.com902ebe52012-06-29 14:21:22 +0000786
chudy@google.comc432f002012-07-10 13:19:25 +0000787 fLeftColumnLayout.setSpacing(6);
788 fLeftColumnLayout.addWidget(&fListWidget);
789 fLeftColumnLayout.addWidget(&fDirectoryWidget);
chudy@google.com902ebe52012-06-29 14:21:22 +0000790
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000791 fCanvasSettingsAndImageLayout.setSpacing(6);
792 fCanvasSettingsAndImageLayout.addWidget(&fCanvasWidget);
793 fCanvasSettingsAndImageLayout.addLayout(&fSettingsAndImageLayout);
794
chudy@google.com902ebe52012-06-29 14:21:22 +0000795
chudy@google.comc432f002012-07-10 13:19:25 +0000796 fMainAndRightColumnLayout.setSpacing(6);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000797 fMainAndRightColumnLayout.addLayout(&fCanvasSettingsAndImageLayout);
chudy@google.comc432f002012-07-10 13:19:25 +0000798 fMainAndRightColumnLayout.addWidget(&fInspectorWidget);
chudy@google.com902ebe52012-06-29 14:21:22 +0000799
chudy@google.com2d537a12012-07-31 12:49:52 +0000800 fCentralWidget.setLayout(&fContainerLayout);
chudy@google.comc432f002012-07-10 13:19:25 +0000801 fContainerLayout.setSpacing(6);
802 fContainerLayout.setContentsMargins(11, 11, 11, 11);
803 fContainerLayout.addLayout(&fLeftColumnLayout);
804 fContainerLayout.addLayout(&fMainAndRightColumnLayout);
805
806 SkDebuggerGUI->setCentralWidget(&fCentralWidget);
807 SkDebuggerGUI->setStatusBar(&fStatusBar);
808
chudy@google.come504de02012-07-16 18:35:23 +0000809 fToolBar.setIconSize(QSize(32, 32));
chudy@google.comc432f002012-07-10 13:19:25 +0000810 fToolBar.setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
811 SkDebuggerGUI->addToolBar(Qt::TopToolBarArea, &fToolBar);
chudy@google.com902ebe52012-06-29 14:21:22 +0000812
chudy@google.com0ab03392012-07-28 20:16:11 +0000813 fSpacer.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
chudy@google.com902ebe52012-06-29 14:21:22 +0000814
chudy@google.comc432f002012-07-10 13:19:25 +0000815 fToolBar.addAction(&fActionRewind);
816 fToolBar.addAction(&fActionStepBack);
chudy@google.come504de02012-07-16 18:35:23 +0000817 fToolBar.addAction(&fActionPause);
chudy@google.comc432f002012-07-10 13:19:25 +0000818 fToolBar.addAction(&fActionStepForward);
819 fToolBar.addAction(&fActionPlay);
820 fToolBar.addSeparator();
chudy@google.come504de02012-07-16 18:35:23 +0000821 fToolBar.addAction(&fActionInspector);
chudy@google.comc432f002012-07-10 13:19:25 +0000822 fToolBar.addSeparator();
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000823 fToolBar.addAction(&fActionProfile);
824
825 fToolBar.addSeparator();
chudy@google.com0ab03392012-07-28 20:16:11 +0000826 fToolBar.addWidget(&fSpacer);
chudy@google.comc432f002012-07-10 13:19:25 +0000827 fToolBar.addWidget(&fFilter);
828 fToolBar.addAction(&fActionCancel);
chudy@google.com902ebe52012-06-29 14:21:22 +0000829
830 // TODO(chudy): Remove static call.
831 fDirectoryWidgetActive = false;
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000832 fFileName = "";
robertphillips@google.comff6e6ba2013-01-28 17:43:26 +0000833 setupDirectoryWidget("");
chudy@google.com902ebe52012-06-29 14:21:22 +0000834 fDirectoryWidgetActive = true;
835
chudy@google.com902ebe52012-06-29 14:21:22 +0000836 // Menu Bar
chudy@google.comc432f002012-07-10 13:19:25 +0000837 fMenuFile.setTitle("File");
838 fMenuFile.addAction(&fActionOpen);
chudy@google.com0ab03392012-07-28 20:16:11 +0000839 fMenuFile.addAction(&fActionSave);
840 fMenuFile.addAction(&fActionSaveAs);
chudy@google.comc432f002012-07-10 13:19:25 +0000841 fMenuFile.addAction(&fActionClose);
chudy@google.come504de02012-07-16 18:35:23 +0000842
843 fMenuEdit.setTitle("Edit");
844 fMenuEdit.addAction(&fActionDelete);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000845 fMenuEdit.addAction(&fActionClearDeletes);
846 fMenuEdit.addSeparator();
chudy@google.come504de02012-07-16 18:35:23 +0000847 fMenuEdit.addAction(&fActionCreateBreakpoint);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000848 fMenuEdit.addAction(&fActionClearBreakpoints);
chudy@google.come504de02012-07-16 18:35:23 +0000849
chudy@google.comc432f002012-07-10 13:19:25 +0000850 fMenuNavigate.setTitle("Navigate");
chudy@google.come504de02012-07-16 18:35:23 +0000851 fMenuNavigate.addAction(&fActionRewind);
852 fMenuNavigate.addAction(&fActionStepBack);
853 fMenuNavigate.addAction(&fActionStepForward);
854 fMenuNavigate.addAction(&fActionPlay);
855 fMenuNavigate.addAction(&fActionPause);
chudy@google.comc432f002012-07-10 13:19:25 +0000856 fMenuNavigate.addAction(&fActionGoToLine);
chudy@google.come504de02012-07-16 18:35:23 +0000857
chudy@google.comc432f002012-07-10 13:19:25 +0000858 fMenuView.setTitle("View");
chudy@google.come504de02012-07-16 18:35:23 +0000859 fMenuView.addAction(&fActionBreakpoint);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000860 fMenuView.addAction(&fActionShowDeletes);
chudy@google.coma1226312012-07-26 20:26:44 +0000861 fMenuView.addAction(&fActionZoomIn);
862 fMenuView.addAction(&fActionZoomOut);
chudy@google.come504de02012-07-16 18:35:23 +0000863
864 fMenuWindows.setTitle("Window");
865 fMenuWindows.addAction(&fActionInspector);
866 fMenuWindows.addAction(&fActionDirectory);
chudy@google.comc432f002012-07-10 13:19:25 +0000867
868 fActionGoToLine.setText("Go to Line...");
869 fActionGoToLine.setDisabled(true);
870 fMenuBar.addAction(fMenuFile.menuAction());
chudy@google.come504de02012-07-16 18:35:23 +0000871 fMenuBar.addAction(fMenuEdit.menuAction());
chudy@google.comc432f002012-07-10 13:19:25 +0000872 fMenuBar.addAction(fMenuView.menuAction());
873 fMenuBar.addAction(fMenuNavigate.menuAction());
chudy@google.come504de02012-07-16 18:35:23 +0000874 fMenuBar.addAction(fMenuWindows.menuAction());
chudy@google.com902ebe52012-06-29 14:21:22 +0000875
chudy@google.com7dcae672012-07-09 20:26:53 +0000876 fPause = false;
877
chudy@google.comc432f002012-07-10 13:19:25 +0000878 SkDebuggerGUI->setMenuBar(&fMenuBar);
chudy@google.com902ebe52012-06-29 14:21:22 +0000879 QMetaObject::connectSlotsByName(SkDebuggerGUI);
880}
881
robertphillips@google.comff6e6ba2013-01-28 17:43:26 +0000882void SkDebuggerGUI::setupDirectoryWidget(const QString& path) {
883 fPath = path;
884 QDir dir(path);
chudy@google.com902ebe52012-06-29 14:21:22 +0000885 QRegExp r(".skp");
chudy@google.comc432f002012-07-10 13:19:25 +0000886 fDirectoryWidget.clear();
887 const QStringList files = dir.entryList();
chudy@google.com902ebe52012-06-29 14:21:22 +0000888 foreach (QString f, files) {
chudy@google.com7dcae672012-07-09 20:26:53 +0000889 if (f.contains(r))
chudy@google.comc432f002012-07-10 13:19:25 +0000890 fDirectoryWidget.addItem(f);
chudy@google.com902ebe52012-06-29 14:21:22 +0000891 }
892}
893
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000894void SkDebuggerGUI::loadPicture(const SkString& fileName) {
895 fFileName = fileName;
chudy@google.comd3058f52012-07-19 13:41:27 +0000896 fLoading = true;
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000897 SkStream* stream = SkNEW_ARGS(SkFILEStream, (fileName.c_str()));
robertphillips@google.com2d40ec42013-02-07 20:39:40 +0000898
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000899 SkPicture* picture = SkPicture::CreateFromStream(stream);
robertphillips@google.com2d40ec42013-02-07 20:39:40 +0000900
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000901 if (NULL == picture) {
robertphillips@google.com2d40ec42013-02-07 20:39:40 +0000902 QMessageBox::critical(this, "Error loading file", "Couldn't read file, sorry.");
903 SkSafeUnref(stream);
904 return;
905 }
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000906
chudy@google.com686e6802012-08-14 16:00:32 +0000907 fCanvasWidget.resetWidgetTransform();
chudy@google.com607357f2012-08-07 16:12:23 +0000908 fDebugger.loadPicture(picture);
chudy@google.com4c7962e2012-08-14 19:38:31 +0000909
robertphillips@google.com6d9c92b2013-05-23 13:21:18 +0000910 fSkipCommands.setCount(fDebugger.getSize());
911 for (int i = 0; i < fSkipCommands.count(); ++i) {
robertphillips@google.com5f971142012-12-07 20:48:56 +0000912 fSkipCommands[i] = false;
913 }
914
chudy@google.com607357f2012-08-07 16:12:23 +0000915 SkSafeUnref(stream);
916 SkSafeUnref(picture);
917
chudy@google.com97cee972012-08-07 20:41:37 +0000918 // Will this automatically clear out due to nature of refcnt?
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000919 SkTArray<SkString>* commands = fDebugger.getDrawCommandsAsStrings();
chudy@google.com607357f2012-08-07 16:12:23 +0000920
robertphillips@google.com6d9c92b2013-05-23 13:21:18 +0000921 fActionProfile.setDisabled(false);
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000922
chudy@google.com7dcae672012-07-09 20:26:53 +0000923 /* fDebugCanvas is reinitialized every load picture. Need it to retain value
chudy@google.com607357f2012-08-07 16:12:23 +0000924 * of the visibility filter.
925 * TODO(chudy): This should be deprecated since fDebugger is not
926 * recreated.
927 * */
928 fDebugger.highlightCurrentCommand(fSettingsWidget.getVisibilityButton()->isChecked());
929
chudy@google.com97cee972012-08-07 20:41:37 +0000930 setupListWidget(commands);
931 setupComboBox(commands);
robertphillips@google.come428f9b2013-03-12 15:33:40 +0000932 setupOverviewText(NULL, 0.0, 1);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000933 fInspectorWidget.setDisabled(false);
chudy@google.come606d6e2012-07-12 14:31:25 +0000934 fSettingsWidget.setDisabled(false);
chudy@google.comd3058f52012-07-19 13:41:27 +0000935 fMenuEdit.setDisabled(false);
936 fMenuNavigate.setDisabled(false);
937 fMenuView.setDisabled(false);
chudy@google.com0ab03392012-07-28 20:16:11 +0000938 fActionSave.setDisabled(false);
939 fActionSaveAs.setDisabled(false);
chudy@google.comd3058f52012-07-19 13:41:27 +0000940 fLoading = false;
941 actionPlay();
chudy@google.com902ebe52012-06-29 14:21:22 +0000942}
943
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000944void SkDebuggerGUI::setupListWidget(SkTArray<SkString>* command) {
chudy@google.comc432f002012-07-10 13:19:25 +0000945 fListWidget.clear();
chudy@google.com902ebe52012-06-29 14:21:22 +0000946 int counter = 0;
robertphillips@google.com30d35f22012-11-06 16:45:36 +0000947 int indent = 0;
chudy@google.com97cee972012-08-07 20:41:37 +0000948 for (int i = 0; i < command->count(); i++) {
chudy@google.com902ebe52012-06-29 14:21:22 +0000949 QListWidgetItem *item = new QListWidgetItem();
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000950 item->setData(Qt::DisplayRole, (*command)[i].c_str());
chudy@google.com902ebe52012-06-29 14:21:22 +0000951 item->setData(Qt::UserRole + 1, counter++);
robertphillips@google.com30d35f22012-11-06 16:45:36 +0000952
robertphillips@google.com0a4805e2013-05-29 13:24:23 +0000953 if (0 == strcmp("Restore", (*command)[i].c_str()) ||
954 0 == strcmp("EndCommentGroup", (*command)[i].c_str())) {
robertphillips@google.com30d35f22012-11-06 16:45:36 +0000955 indent -= 10;
956 }
957
958 item->setData(Qt::UserRole + 3, indent);
959
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000960 if (0 == strcmp("Save", (*command)[i].c_str()) ||
robertphillips@google.com0a4805e2013-05-29 13:24:23 +0000961 0 == strcmp("Save Layer", (*command)[i].c_str()) ||
962 0 == strcmp("BeginCommentGroup", (*command)[i].c_str())) {
robertphillips@google.com30d35f22012-11-06 16:45:36 +0000963 indent += 10;
964 }
965
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000966 item->setData(Qt::UserRole + 4, -1.0);
967
chudy@google.comc432f002012-07-10 13:19:25 +0000968 fListWidget.addItem(item);
chudy@google.com902ebe52012-06-29 14:21:22 +0000969 }
970}
971
skia.committer@gmail.com91274b92013-03-13 07:01:04 +0000972void SkDebuggerGUI::setupOverviewText(const SkTDArray<double>* typeTimes,
robertphillips@google.come428f9b2013-03-12 15:33:40 +0000973 double totTime,
974 int numRuns) {
borenet@google.com2d9dbd42013-03-12 13:07:40 +0000975 SkString overview;
robertphillips@google.come428f9b2013-03-12 15:33:40 +0000976 fDebugger.getOverviewText(typeTimes, totTime, &overview, numRuns);
borenet@google.com2d9dbd42013-03-12 13:07:40 +0000977 fInspectorWidget.setText(overview.c_str(), SkInspectorWidget::kOverview_TabType);
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000978}
979
980void SkDebuggerGUI::setupComboBox(SkTArray<SkString>* command) {
981 fFilter.clear();
982 fFilter.addItem("--Filter By Available Commands--");
983
984 std::map<std::string, int> map;
985 for (int i = 0; i < command->count(); i++) {
986 map[(*command)[i].c_str()]++;
987 }
988
skia.committer@gmail.com34587162012-11-20 02:01:23 +0000989 for (std::map<std::string, int>::iterator it = map.begin(); it != map.end();
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000990 ++it) {
991 fFilter.addItem((it->first).c_str());
992 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000993
994 // NOTE(chudy): Makes first item unselectable.
chudy@google.com7dcae672012-07-09 20:26:53 +0000995 QStandardItemModel* model = qobject_cast<QStandardItemModel*>(
chudy@google.comc432f002012-07-10 13:19:25 +0000996 fFilter.model());
997 QModelIndex firstIndex = model->index(0, fFilter.modelColumn(),
998 fFilter.rootModelIndex());
chudy@google.com902ebe52012-06-29 14:21:22 +0000999 QStandardItem* firstItem = model->itemFromIndex(firstIndex);
1000 firstItem->setSelectable(false);
1001}