blob: 48f18d4f5916b0602c98505781a98f90fa288461 [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"
chudy@google.combbad34d2012-08-13 14:26:36 +00009#include "SkGraphics.h"
scroggo@google.comb4467e62012-11-06 23:10:09 +000010#include "SkImageDecoder.h"
chudy@google.com902ebe52012-06-29 14:21:22 +000011#include <QListWidgetItem>
robertphillips@google.com2bde91d2012-11-15 14:57:57 +000012#include "PictureRenderer.h"
robertphillips@google.com2bde91d2012-11-15 14:57:57 +000013#include "SkPictureRecord.h"
14#include "SkPicturePlayback.h"
15#include "BenchTimer.h"
chudy@google.com902ebe52012-06-29 14:21:22 +000016
17SkDebuggerGUI::SkDebuggerGUI(QWidget *parent) :
chudy@google.comc432f002012-07-10 13:19:25 +000018 QMainWindow(parent)
chudy@google.com2d537a12012-07-31 12:49:52 +000019 , fCentralWidget(this)
20 , fStatusBar(this)
21 , fToolBar(this)
chudy@google.comc432f002012-07-10 13:19:25 +000022 , fActionOpen(this)
23 , fActionBreakpoint(this)
robertphillips@google.comd26c7062012-11-12 20:42:12 +000024 , fActionProfile(this)
chudy@google.comc432f002012-07-10 13:19:25 +000025 , fActionCancel(this)
chudy@google.com7e4cfbf2012-07-17 15:40:51 +000026 , fActionClearBreakpoints(this)
chudy@google.come504de02012-07-16 18:35:23 +000027 , fActionClearDeletes(this)
chudy@google.comc432f002012-07-10 13:19:25 +000028 , fActionClose(this)
chudy@google.come504de02012-07-16 18:35:23 +000029 , fActionCreateBreakpoint(this)
chudy@google.comc432f002012-07-10 13:19:25 +000030 , fActionDelete(this)
31 , fActionDirectory(this)
32 , fActionGoToLine(this)
33 , fActionInspector(this)
34 , fActionPlay(this)
chudy@google.come504de02012-07-16 18:35:23 +000035 , fActionPause(this)
chudy@google.comc432f002012-07-10 13:19:25 +000036 , fActionRewind(this)
chudy@google.com0ab03392012-07-28 20:16:11 +000037 , fActionSave(this)
38 , fActionSaveAs(this)
chudy@google.com7e4cfbf2012-07-17 15:40:51 +000039 , fActionShowDeletes(this)
chudy@google.comc432f002012-07-10 13:19:25 +000040 , fActionStepBack(this)
41 , fActionStepForward(this)
chudy@google.coma1226312012-07-26 20:26:44 +000042 , fActionZoomIn(this)
43 , fActionZoomOut(this)
44 , fMapper(this)
chudy@google.comc432f002012-07-10 13:19:25 +000045 , fListWidget(&fCentralWidget)
46 , fDirectoryWidget(&fCentralWidget)
chudy@google.com607357f2012-08-07 16:12:23 +000047 , fCanvasWidget(this, &fDebugger)
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +000048 , fImageWidget(&fDebugger)
chudy@google.comc432f002012-07-10 13:19:25 +000049 , fMenuBar(this)
50 , fMenuFile(this)
51 , fMenuNavigate(this)
52 , fMenuView(this)
chudy@google.com7e4cfbf2012-07-17 15:40:51 +000053 , fBreakpointsActivated(false)
54 , fDeletesActivated(false)
55 , fPause(false)
chudy@google.comd3058f52012-07-19 13:41:27 +000056 , fLoading(false)
chudy@google.comc432f002012-07-10 13:19:25 +000057{
chudy@google.com902ebe52012-06-29 14:21:22 +000058 setupUi(this);
chudy@google.comea5488b2012-07-26 19:38:22 +000059 connect(&fListWidget, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)), this, SLOT(registerListClick(QListWidgetItem *)));
chudy@google.comc432f002012-07-10 13:19:25 +000060 connect(&fActionOpen, SIGNAL(triggered()), this, SLOT(openFile()));
chudy@google.comea5488b2012-07-26 19:38:22 +000061 connect(&fActionDirectory, SIGNAL(triggered()), this, SLOT(toggleDirectory()));
62 connect(&fDirectoryWidget, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)), this, SLOT(loadFile(QListWidgetItem *)));
chudy@google.comc432f002012-07-10 13:19:25 +000063 connect(&fActionDelete, SIGNAL(triggered()), this, SLOT(actionDelete()));
chudy@google.comea5488b2012-07-26 19:38:22 +000064 connect(&fListWidget, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(toggleBreakpoint()));
chudy@google.comc432f002012-07-10 13:19:25 +000065 connect(&fActionRewind, SIGNAL(triggered()), this, SLOT(actionRewind()));
66 connect(&fActionPlay, SIGNAL(triggered()), this, SLOT(actionPlay()));
67 connect(&fActionStepBack, SIGNAL(triggered()), this, SLOT(actionStepBack()));
chudy@google.comea5488b2012-07-26 19:38:22 +000068 connect(&fActionStepForward, SIGNAL(triggered()), this, SLOT(actionStepForward()));
69 connect(&fActionBreakpoint, SIGNAL(triggered()), this, SLOT(actionBreakpoints()));
70 connect(&fActionInspector, SIGNAL(triggered()), this, SLOT(actionInspector()));
71 connect(&fActionInspector, SIGNAL(triggered()), this, SLOT(actionSettings()));
72 connect(&fFilter, SIGNAL(activated(QString)), this, SLOT(toggleFilter(QString)));
robertphillips@google.comd26c7062012-11-12 20:42:12 +000073 connect(&fActionProfile, SIGNAL(triggered()), this, SLOT(actionProfile()));
chudy@google.comc432f002012-07-10 13:19:25 +000074 connect(&fActionCancel, SIGNAL(triggered()), this, SLOT(actionCancel()));
chudy@google.com7e4cfbf2012-07-17 15:40:51 +000075 connect(&fActionClearBreakpoints, SIGNAL(triggered()), this, SLOT(actionClearBreakpoints()));
76 connect(&fActionClearDeletes, SIGNAL(triggered()), this, SLOT(actionClearDeletes()));
chudy@google.comc432f002012-07-10 13:19:25 +000077 connect(&fActionClose, SIGNAL(triggered()), this, SLOT(actionClose()));
chudy@google.comea5488b2012-07-26 19:38:22 +000078 connect(fSettingsWidget.getVisibilityButton(), SIGNAL(toggled(bool)), this, SLOT(actionCommandFilter()));
79 connect(fSettingsWidget.getGLCheckBox(), SIGNAL(toggled(bool)), this, SLOT(actionGLWidget(bool)));
80 connect(fSettingsWidget.getRasterCheckBox(), SIGNAL(toggled(bool)), this, SLOT(actionRasterWidget(bool)));
81 connect(&fActionPause, SIGNAL(toggled(bool)), this, SLOT(pauseDrawing(bool)));
chudy@google.come504de02012-07-16 18:35:23 +000082 connect(&fActionCreateBreakpoint, SIGNAL(activated()), this, SLOT(toggleBreakpoint()));
chudy@google.com7e4cfbf2012-07-17 15:40:51 +000083 connect(&fActionShowDeletes, SIGNAL(triggered()), this, SLOT(showDeletes()));
chudy@google.comea5488b2012-07-26 19:38:22 +000084 connect(&fCanvasWidget, SIGNAL(hitChanged(int)), this, SLOT(selectCommand(int)));
85 connect(&fCanvasWidget, SIGNAL(hitChanged(int)), &fSettingsWidget, SLOT(updateHit(int)));
86 connect(&fCanvasWidget, SIGNAL(scaleFactorChanged(float)), this, SLOT(actionScale(float)));
87 connect(&fCanvasWidget, SIGNAL(commandChanged(int)), &fSettingsWidget, SLOT(updateCommand(int)));
chudy@google.com0ab03392012-07-28 20:16:11 +000088 connect(&fActionSaveAs, SIGNAL(triggered()), this, SLOT(actionSaveAs()));
89 connect(&fActionSave, SIGNAL(triggered()), this, SLOT(actionSave()));
chudy@google.com7e4cfbf2012-07-17 15:40:51 +000090
chudy@google.coma1226312012-07-26 20:26:44 +000091 fMapper.setMapping(&fActionZoomIn, 1);
92 fMapper.setMapping(&fActionZoomOut, -1);
93
94 connect(&fActionZoomIn, SIGNAL(triggered()), &fMapper, SLOT(map()));
95 connect(&fActionZoomOut, SIGNAL(triggered()), &fMapper, SLOT(map()));
96 connect(&fMapper, SIGNAL(mapped(int)), &fCanvasWidget, SLOT(keyZoom(int)));
97
chudy@google.com7e4cfbf2012-07-17 15:40:51 +000098 fInspectorWidget.setDisabled(true);
chudy@google.comd3058f52012-07-19 13:41:27 +000099 fMenuEdit.setDisabled(true);
100 fMenuNavigate.setDisabled(true);
101 fMenuView.setDisabled(true);
chudy@google.combbad34d2012-08-13 14:26:36 +0000102
103 SkGraphics::Init();
chudy@google.com902ebe52012-06-29 14:21:22 +0000104}
105
chudy@google.combbad34d2012-08-13 14:26:36 +0000106SkDebuggerGUI::~SkDebuggerGUI() {
107 SkGraphics::Term();
108}
chudy@google.com902ebe52012-06-29 14:21:22 +0000109
110void SkDebuggerGUI::actionBreakpoints() {
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000111 fBreakpointsActivated = !fBreakpointsActivated;
chudy@google.comc432f002012-07-10 13:19:25 +0000112 for (int row = 0; row < fListWidget.count(); row++) {
113 QListWidgetItem *item = fListWidget.item(row);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000114 item->setHidden(item->checkState() == Qt::Unchecked && fBreakpointsActivated);
115 }
116}
chudy@google.com902ebe52012-06-29 14:21:22 +0000117
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000118void SkDebuggerGUI::showDeletes() {
119 fDeletesActivated = !fDeletesActivated;
120 for (int row = 0; row < fListWidget.count(); row++) {
121 QListWidgetItem *item = fListWidget.item(row);
chudy@google.com607357f2012-08-07 16:12:23 +0000122 item->setHidden(fDebugger.isCommandVisible(row)
123 && fDeletesActivated);
chudy@google.com902ebe52012-06-29 14:21:22 +0000124 }
125}
126
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000127// The timed picture playback uses the SkPicturePlayback's profiling stubs
128// to time individual commands. The offsets are needed to map SkPicture
129// offsets to individual commands.
130class SkTimedPicturePlayback : public SkPicturePlayback {
131public:
132 SkTimedPicturePlayback(SkStream* stream, const SkPictInfo& info, bool* isValid,
133 SkSerializationHelpers::DecodeBitmap decoder,
skia.committer@gmail.com884e60b2012-11-16 02:01:17 +0000134 const SkTDArray<size_t>& offsets)
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000135 : INHERITED(stream, info, isValid, decoder)
136 , fTot(0.0)
137 , fCurCommand(0)
138 , fOffsets(offsets) {
139 fTimes.setCount(fOffsets.count());
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000140 fTypeTimes.setCount(LAST_DRAWTYPE_ENUM+1);
141 this->resetTimes();
142 }
143
144 void resetTimes() {
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000145 for (int i = 0; i < fOffsets.count(); ++i) {
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000146 fTimes[i] = 0.0;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000147 }
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000148 for (int i = 0; i < fTypeTimes.count(); ++i) {
149 fTypeTimes[i] = 0.0f;
150 }
151 fTot = 0.0;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000152 }
153
154 int count() const { return fTimes.count(); }
155
156 double time(int index) const { return fTimes[index] / fTot; }
157
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000158 const SkTDArray<double>* typeTimes() const { return &fTypeTimes; }
159
160 double totTime() const { return fTot; }
161
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000162protected:
163 BenchTimer fTimer;
164 SkTDArray<size_t> fOffsets; // offset in the SkPicture for each command
165 SkTDArray<double> fTimes; // sum of time consumed for each command
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000166 SkTDArray<double> fTypeTimes; // sum of time consumed for each type of command (e.g., drawPath)
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000167 double fTot; // total of all times in 'fTimes'
168 size_t fCurOffset;
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000169 int fCurType;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000170 int fCurCommand; // the current command being executed/timed
171
172 virtual void preDraw(size_t offset, int type) {
skia.committer@gmail.com884e60b2012-11-16 02:01:17 +0000173 // This search isn't as bad as it seems. In normal playback mode, the
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000174 // base class steps through the commands in order and can only skip ahead
skia.committer@gmail.com884e60b2012-11-16 02:01:17 +0000175 // a bit on a clip. This class is only used during profiling so we
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000176 // don't have to worry about forward/backward scrubbing through commands.
177 for (int i = 0; offset != fOffsets[fCurCommand]; ++i) {
178 fCurCommand = (fCurCommand+1) % fOffsets.count();
179 SkASSERT(i <= fOffsets.count()); // should always find the offset in the list
180 }
181
182 fCurOffset = offset;
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000183 fCurType = type;
184 // The SkDebugCanvas doesn't recognize these types. This class needs to
185 // convert or else we'll wind up with a mismatch between the type counts
186 // the debugger displays and the profile times.
187 if (DRAW_POS_TEXT_TOP_BOTTOM == type) {
188 fCurType = DRAW_POS_TEXT;
189 } else if (DRAW_POS_TEXT_H_TOP_BOTTOM == type) {
190 fCurType = DRAW_POS_TEXT_H;
191 }
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000192
193 fTimer.start();
194 }
195
196 virtual void postDraw(size_t offset) {
197 fTimer.end();
198
199 SkASSERT(offset == fCurOffset);
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000200 SkASSERT(fCurType <= LAST_DRAWTYPE_ENUM);
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000201
robertphillips@google.come099bc42012-11-19 16:26:40 +0000202#if defined(SK_BUILD_FOR_WIN32)
203 // CPU timer doesn't work well on Windows
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000204 fTimes[fCurCommand] += fTimer.fWall;
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000205 fTypeTimes[fCurType] += fTimer.fWall;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000206 fTot += fTimer.fWall;
robertphillips@google.come099bc42012-11-19 16:26:40 +0000207#else
208 fTimes[fCurCommand] += fTimer.fCpu;
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000209 fTypeTimes[fCurType] += fTimer.fCpu;
robertphillips@google.come099bc42012-11-19 16:26:40 +0000210 fTot += fTimer.fCpu;
211#endif
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000212 }
213
214private:
215 typedef SkPicturePlayback INHERITED;
216};
217
218// Wrap SkPicture to allow installation of an SkTimedPicturePlayback object
219class SkTimedPicture : public SkPicture {
220public:
221 explicit SkTimedPicture(SkStream* stream,
222 bool* success,
223 SkSerializationHelpers::DecodeBitmap decoder,
224 const SkTDArray<size_t>& offsets) {
225 if (success) {
226 *success = false;
227 }
228 fRecord = NULL;
229 fPlayback = NULL;
230 fWidth = fHeight = 0;
231
232 SkPictInfo info;
233
234 if (!stream->read(&info, sizeof(info))) {
235 return;
236 }
237 if (SkPicture::PICTURE_VERSION != info.fVersion) {
238 return;
239 }
240
241 if (stream->readBool()) {
242 bool isValid = false;
skia.committer@gmail.com884e60b2012-11-16 02:01:17 +0000243 fPlayback = SkNEW_ARGS(SkTimedPicturePlayback,
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000244 (stream, info, &isValid, decoder, offsets));
245 if (!isValid) {
246 SkDELETE(fPlayback);
247 fPlayback = NULL;
248 return;
249 }
250 }
251
252 // do this at the end, so that they will be zero if we hit an error.
253 fWidth = info.fWidth;
254 fHeight = info.fHeight;
255 if (success) {
256 *success = true;
257 }
258 }
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();
274 // disallow the copy ctor - enabling would require copying code from SkPicture
275 SkTimedPicture(const SkTimedPicture& src);
276
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000277 typedef SkPicture INHERITED;
278};
279
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000280// This is a simplification of PictureBenchmark's run with the addition of
281// clearing of the times after the first pass (in resetTimes)
skia.committer@gmail.com34587162012-11-20 02:01:23 +0000282void SkDebuggerGUI::run(SkTimedPicture* pict,
283 sk_tools::PictureRenderer* renderer,
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000284 int repeats) {
285 SkASSERT(pict);
286 if (NULL == pict) {
287 return;
288 }
289
290 SkASSERT(renderer != NULL);
291 if (NULL == renderer) {
292 return;
293 }
294
295 renderer->init(pict);
296
297 renderer->setup();
298 renderer->render(NULL);
299 renderer->resetState();
300
301 // We throw this away the first batch of times to remove first time effects (such as paging in this program)
302 pict->resetTimes();
303
304 for (int i = 0; i < repeats; ++i) {
305 renderer->setup();
306 renderer->render(NULL);
307 renderer->resetState();
308 }
309
310 renderer->end();
311}
312
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000313void SkDebuggerGUI::actionProfile() {
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000314 // In order to profile we pass the command offsets (that were read-in
315 // in loadPicture by the SkOffsetPicture) to an SkTimedPlaybackPicture.
skia.committer@gmail.com884e60b2012-11-16 02:01:17 +0000316 // The SkTimedPlaybackPicture in turn passes the offsets to an
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000317 // SkTimedPicturePlayback object which uses them to track the performance
318 // of individual commands.
319 if (fFileName.isEmpty()) {
320 return;
321 }
322
323 SkFILEStream inputStream;
324
325 inputStream.setPath(fFileName.c_str());
326 if (!inputStream.isValid()) {
327 return;
328 }
329
330 bool success = false;
331 SkTimedPicture picture(&inputStream, &success, &SkImageDecoder::DecodeStream, fOffsets);
332 if (!success) {
333 return;
334 }
335
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000336 // For now this #if allows switching between tiled and simple rendering
337 // modes. Eventually this will be accomplished via the GUI
338#if 1
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000339 sk_tools::TiledPictureRenderer* renderer = NULL;
340
341 renderer = SkNEW(sk_tools::TiledPictureRenderer);
342 renderer->setTileWidth(256);
343 renderer->setTileHeight(256);
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000344#else
345 sk_tools::SimplePictureRenderer* renderer = NULL;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000346
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000347 renderer = SkNEW(sk_tools::SimplePictureRenderer);
348#endif
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000349
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000350 run(&picture, renderer, 2);
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000351
352 SkASSERT(picture.count() == fListWidget.count());
353
354 // extract the individual command times from the SkTimedPlaybackPicture
355 for (int i = 0; i < picture.count(); ++i) {
356 double temp = picture.time(i);
357
358 QListWidgetItem* item = fListWidget.item(i);
359
360 item->setData(Qt::UserRole + 4, 100.0*temp);
361 }
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000362
363 setupOverviewText(picture.typeTimes(), picture.totTime());
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000364}
365
chudy@google.com902ebe52012-06-29 14:21:22 +0000366void SkDebuggerGUI::actionCancel() {
chudy@google.comc432f002012-07-10 13:19:25 +0000367 for (int row = 0; row < fListWidget.count(); row++) {
368 fListWidget.item(row)->setHidden(false);
chudy@google.com902ebe52012-06-29 14:21:22 +0000369 }
370}
371
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000372void SkDebuggerGUI::actionClearBreakpoints() {
373 for (int row = 0; row < fListWidget.count(); row++) {
374 QListWidgetItem* item = fListWidget.item(row);
375 item->setCheckState(Qt::Unchecked);
376 item->setData(Qt::DecorationRole,
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000377 QPixmap(":/blank.png"));
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000378 }
379}
380
381void SkDebuggerGUI::actionClearDeletes() {
382 for (int row = 0; row < fListWidget.count(); row++) {
383 QListWidgetItem* item = fListWidget.item(row);
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000384 item->setData(Qt::UserRole + 2, QPixmap(":/blank.png"));
chudy@google.com607357f2012-08-07 16:12:23 +0000385 fDebugger.setCommandVisible(row, true);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000386 }
387 if (fPause) {
388 fCanvasWidget.drawTo(fPausedRow);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000389 fImageWidget.draw();
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000390 } else {
391 fCanvasWidget.drawTo(fListWidget.currentRow());
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000392 fImageWidget.draw();
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000393 }
394}
395
chudy@google.com902ebe52012-06-29 14:21:22 +0000396void SkDebuggerGUI::actionCommandFilter() {
chudy@google.com607357f2012-08-07 16:12:23 +0000397 fDebugger.highlightCurrentCommand(
chudy@google.comc432f002012-07-10 13:19:25 +0000398 fSettingsWidget.getVisibilityButton()->isChecked());
399 fCanvasWidget.drawTo(fListWidget.currentRow());
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000400 fImageWidget.draw();
chudy@google.com902ebe52012-06-29 14:21:22 +0000401}
402
403void SkDebuggerGUI::actionClose() {
404 this->close();
405}
406
407void SkDebuggerGUI::actionDelete() {
chudy@google.comc432f002012-07-10 13:19:25 +0000408 int currentRow = fListWidget.currentRow();
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000409 QListWidgetItem* item = fListWidget.currentItem();
410
chudy@google.com607357f2012-08-07 16:12:23 +0000411 if (fDebugger.isCommandVisible(currentRow)) {
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000412 item->setData(Qt::UserRole + 2, QPixmap(":/delete.png"));
chudy@google.com607357f2012-08-07 16:12:23 +0000413 fDebugger.setCommandVisible(currentRow, false);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000414 } else {
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000415 item->setData(Qt::UserRole + 2, QPixmap(":/blank.png"));
chudy@google.com607357f2012-08-07 16:12:23 +0000416 fDebugger.setCommandVisible(currentRow, true);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000417 }
418
chudy@google.come504de02012-07-16 18:35:23 +0000419 if (fPause) {
420 fCanvasWidget.drawTo(fPausedRow);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000421 fImageWidget.draw();
chudy@google.come504de02012-07-16 18:35:23 +0000422 } else {
423 fCanvasWidget.drawTo(currentRow);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000424 fImageWidget.draw();
chudy@google.come504de02012-07-16 18:35:23 +0000425 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000426}
427
chudy@google.comea5488b2012-07-26 19:38:22 +0000428void SkDebuggerGUI::actionGLWidget(bool isToggled) {
429 fCanvasWidget.setWidgetVisibility(SkCanvasWidget::kGPU_WidgetType, !isToggled);
430}
431
chudy@google.com902ebe52012-06-29 14:21:22 +0000432void SkDebuggerGUI::actionInspector() {
chudy@google.comc432f002012-07-10 13:19:25 +0000433 if (fInspectorWidget.isHidden()) {
434 fInspectorWidget.setHidden(false);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000435 fImageWidget.setHidden(false);
chudy@google.com902ebe52012-06-29 14:21:22 +0000436 } else {
chudy@google.comc432f002012-07-10 13:19:25 +0000437 fInspectorWidget.setHidden(true);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000438 fImageWidget.setHidden(true);
chudy@google.com902ebe52012-06-29 14:21:22 +0000439 }
440}
441
442void SkDebuggerGUI::actionPlay() {
chudy@google.comc432f002012-07-10 13:19:25 +0000443 for (int row = fListWidget.currentRow() + 1; row < fListWidget.count();
chudy@google.com7dcae672012-07-09 20:26:53 +0000444 row++) {
chudy@google.comc432f002012-07-10 13:19:25 +0000445 QListWidgetItem *item = fListWidget.item(row);
chudy@google.com902ebe52012-06-29 14:21:22 +0000446 if (item->checkState() == Qt::Checked) {
chudy@google.comc432f002012-07-10 13:19:25 +0000447 fListWidget.setCurrentItem(item);
chudy@google.com902ebe52012-06-29 14:21:22 +0000448 return;
449 }
450 }
chudy@google.comc432f002012-07-10 13:19:25 +0000451 fListWidget.setCurrentRow(fListWidget.count() - 1);
chudy@google.com902ebe52012-06-29 14:21:22 +0000452}
453
chudy@google.comea5488b2012-07-26 19:38:22 +0000454void SkDebuggerGUI::actionRasterWidget(bool isToggled) {
455 fCanvasWidget.setWidgetVisibility(SkCanvasWidget::kRaster_8888_WidgetType, !isToggled);
456}
457
chudy@google.com902ebe52012-06-29 14:21:22 +0000458void SkDebuggerGUI::actionRewind() {
chudy@google.come504de02012-07-16 18:35:23 +0000459 fListWidget.setCurrentRow(0);
chudy@google.com902ebe52012-06-29 14:21:22 +0000460}
461
chudy@google.com0ab03392012-07-28 20:16:11 +0000462void SkDebuggerGUI::actionSave() {
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000463 fFileName = fPath.toAscii();
464 fFileName.append("/");
465 fFileName.append(fDirectoryWidget.currentItem()->text().toAscii());
466 saveToFile(fFileName);
chudy@google.com0ab03392012-07-28 20:16:11 +0000467}
468
469void SkDebuggerGUI::actionSaveAs() {
470 QString filename = QFileDialog::getSaveFileName(this, "Save File", "",
471 "Skia Picture (*skp)");
chudy@google.com38b08ce2012-07-28 23:26:10 +0000472 if (!filename.endsWith(".skp", Qt::CaseInsensitive)) {
chudy@google.com0ab03392012-07-28 20:16:11 +0000473 filename.append(".skp");
474 }
djsollen@google.comc3c82162012-11-13 18:35:10 +0000475 saveToFile(SkString(filename.toAscii().data()));
chudy@google.com0ab03392012-07-28 20:16:11 +0000476}
477
chudy@google.com7dcae672012-07-09 20:26:53 +0000478void SkDebuggerGUI::actionScale(float scaleFactor) {
chudy@google.comc432f002012-07-10 13:19:25 +0000479 fSettingsWidget.setZoomText(scaleFactor);
chudy@google.com7dcae672012-07-09 20:26:53 +0000480}
481
chudy@google.com902ebe52012-06-29 14:21:22 +0000482void SkDebuggerGUI::actionSettings() {
chudy@google.comc432f002012-07-10 13:19:25 +0000483 if (fSettingsWidget.isHidden()) {
484 fSettingsWidget.setHidden(false);
chudy@google.com902ebe52012-06-29 14:21:22 +0000485 } else {
chudy@google.comc432f002012-07-10 13:19:25 +0000486 fSettingsWidget.setHidden(true);
chudy@google.com902ebe52012-06-29 14:21:22 +0000487 }
488}
489
490void SkDebuggerGUI::actionStepBack() {
chudy@google.comc432f002012-07-10 13:19:25 +0000491 int currentRow = fListWidget.currentRow();
chudy@google.com902ebe52012-06-29 14:21:22 +0000492 if (currentRow != 0) {
chudy@google.comc432f002012-07-10 13:19:25 +0000493 fListWidget.setCurrentRow(currentRow - 1);
chudy@google.com902ebe52012-06-29 14:21:22 +0000494 }
495}
496
497void SkDebuggerGUI::actionStepForward() {
chudy@google.comc432f002012-07-10 13:19:25 +0000498 int currentRow = fListWidget.currentRow();
chudy@google.com902ebe52012-06-29 14:21:22 +0000499 QString curRow = QString::number(currentRow);
chudy@google.comc432f002012-07-10 13:19:25 +0000500 QString curCount = QString::number(fListWidget.count());
501 if (currentRow < fListWidget.count() - 1) {
502 fListWidget.setCurrentRow(currentRow + 1);
chudy@google.com902ebe52012-06-29 14:21:22 +0000503 }
504}
505
chudy@google.coma9e937c2012-08-03 17:32:05 +0000506void SkDebuggerGUI::drawComplete() {
chudy@google.com607357f2012-08-07 16:12:23 +0000507 fInspectorWidget.setMatrix(fDebugger.getCurrentMatrix());
508 fInspectorWidget.setClip(fDebugger.getCurrentClip());
chudy@google.coma9e937c2012-08-03 17:32:05 +0000509}
510
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000511void SkDebuggerGUI::saveToFile(const SkString& filename) {
512 SkFILEWStream file(filename.c_str());
chudy@google.com607357f2012-08-07 16:12:23 +0000513 fDebugger.makePicture()->serialize(&file);
chudy@google.com0ab03392012-07-28 20:16:11 +0000514}
515
chudy@google.com902ebe52012-06-29 14:21:22 +0000516void SkDebuggerGUI::loadFile(QListWidgetItem *item) {
517 if (fDirectoryWidgetActive) {
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000518 fFileName = fPath.toAscii();
519 fFileName.append("/");
520 fFileName.append(item->text().toAscii());
521 loadPicture(fFileName);
chudy@google.com902ebe52012-06-29 14:21:22 +0000522 }
523}
524
525void SkDebuggerGUI::openFile() {
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000526 QString temp = QFileDialog::getOpenFileName(this, tr("Open File"), "",
chudy@google.com7dcae672012-07-09 20:26:53 +0000527 tr("Files (*.*)"));
chudy@google.com902ebe52012-06-29 14:21:22 +0000528 fDirectoryWidgetActive = false;
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000529 if (!temp.isEmpty()) {
530 QFileInfo pathInfo(temp);
chudy@google.com902ebe52012-06-29 14:21:22 +0000531 fPath = pathInfo.path();
djsollen@google.comc3c82162012-11-13 18:35:10 +0000532 loadPicture(SkString(temp.toAscii().data()));
chudy@google.com902ebe52012-06-29 14:21:22 +0000533 setupDirectoryWidget();
534 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000535 fDirectoryWidgetActive = true;
536}
537
chudy@google.comc432f002012-07-10 13:19:25 +0000538void SkDebuggerGUI::pauseDrawing(bool isPaused) {
chudy@google.com607357f2012-08-07 16:12:23 +0000539 fPause = isPaused;
540 fPausedRow = fListWidget.currentRow();
541 fCanvasWidget.drawTo(fPausedRow);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000542 fImageWidget.draw();
chudy@google.com7dcae672012-07-09 20:26:53 +0000543}
544
chudy@google.com902ebe52012-06-29 14:21:22 +0000545void SkDebuggerGUI::registerListClick(QListWidgetItem *item) {
chudy@google.comd3058f52012-07-19 13:41:27 +0000546 if(!fLoading) {
547 int currentRow = fListWidget.currentRow();
chudy@google.comd3058f52012-07-19 13:41:27 +0000548
chudy@google.comea5488b2012-07-26 19:38:22 +0000549 if (currentRow != -1) {
550 if (!fPause) {
551 fCanvasWidget.drawTo(currentRow);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000552 fImageWidget.draw();
chudy@google.comd3058f52012-07-19 13:41:27 +0000553 }
chudy@google.com97cee972012-08-07 20:41:37 +0000554 SkTDArray<SkString*> *currInfo = fDebugger.getCommandInfo(
chudy@google.comea5488b2012-07-26 19:38:22 +0000555 currentRow);
556
557 /* TODO(chudy): Add command type before parameters. Rename v
558 * to something more informative. */
chudy@google.com97cee972012-08-07 20:41:37 +0000559 if (currInfo) {
chudy@google.comea5488b2012-07-26 19:38:22 +0000560 QString info;
561 info.append("<b>Parameters: </b><br/>");
chudy@google.com97cee972012-08-07 20:41:37 +0000562 for (int i = 0; i < currInfo->count(); i++) {
563
564 info.append(QString((*currInfo)[i]->c_str()));
chudy@google.comea5488b2012-07-26 19:38:22 +0000565 info.append("<br/>");
566 }
chudy@google.com6bd109a2012-08-14 19:34:13 +0000567 fInspectorWidget.setText(info, SkInspectorWidget::kDetail_TabType);
chudy@google.comea5488b2012-07-26 19:38:22 +0000568 fInspectorWidget.setDisabled(false);
chudy@google.comea5488b2012-07-26 19:38:22 +0000569 }
chudy@google.comd3058f52012-07-19 13:41:27 +0000570 }
chudy@google.comea5488b2012-07-26 19:38:22 +0000571
chudy@google.com902ebe52012-06-29 14:21:22 +0000572 }
573}
574
chudy@google.com9ca9bfe2012-07-12 21:58:14 +0000575void SkDebuggerGUI::selectCommand(int command) {
576 if (fPause) {
577 fListWidget.setCurrentRow(command);
578 }
579}
580
chudy@google.com902ebe52012-06-29 14:21:22 +0000581void SkDebuggerGUI::toggleBreakpoint() {
chudy@google.comc432f002012-07-10 13:19:25 +0000582 QListWidgetItem* item = fListWidget.currentItem();
chudy@google.com902ebe52012-06-29 14:21:22 +0000583 if (item->checkState() == Qt::Unchecked) {
584 item->setCheckState(Qt::Checked);
chudy@google.come565de42012-07-12 14:15:54 +0000585 item->setData(Qt::DecorationRole,
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000586 QPixmap(":/breakpoint_16x16.png"));
chudy@google.com902ebe52012-06-29 14:21:22 +0000587 } else {
chudy@google.com902ebe52012-06-29 14:21:22 +0000588 item->setCheckState(Qt::Unchecked);
chudy@google.come565de42012-07-12 14:15:54 +0000589 item->setData(Qt::DecorationRole,
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000590 QPixmap(":/blank.png"));
chudy@google.com902ebe52012-06-29 14:21:22 +0000591 }
592}
593
594void SkDebuggerGUI::toggleDirectory() {
chudy@google.com607357f2012-08-07 16:12:23 +0000595 fDirectoryWidget.setHidden(!fDirectoryWidget.isHidden());
chudy@google.com902ebe52012-06-29 14:21:22 +0000596}
597
598void SkDebuggerGUI::toggleFilter(QString string) {
chudy@google.comc432f002012-07-10 13:19:25 +0000599 for (int row = 0; row < fListWidget.count(); row++) {
600 QListWidgetItem *item = fListWidget.item(row);
chudy@google.com607357f2012-08-07 16:12:23 +0000601 item->setHidden(item->text() != string);
chudy@google.com902ebe52012-06-29 14:21:22 +0000602 }
603}
604
605void SkDebuggerGUI::setupUi(QMainWindow *SkDebuggerGUI) {
606 QIcon windowIcon;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000607 windowIcon.addFile(QString::fromUtf8(":/skia.png"), QSize(),
chudy@google.com7dcae672012-07-09 20:26:53 +0000608 QIcon::Normal, QIcon::Off);
chudy@google.com902ebe52012-06-29 14:21:22 +0000609 SkDebuggerGUI->setObjectName(QString::fromUtf8("SkDebuggerGUI"));
610 SkDebuggerGUI->resize(1200, 1000);
611 SkDebuggerGUI->setWindowIcon(windowIcon);
chudy@google.comc432f002012-07-10 13:19:25 +0000612 SkDebuggerGUI->setWindowTitle("Skia Debugger");
chudy@google.com902ebe52012-06-29 14:21:22 +0000613
chudy@google.come504de02012-07-16 18:35:23 +0000614 fActionOpen.setShortcuts(QKeySequence::Open);
chudy@google.comc432f002012-07-10 13:19:25 +0000615 fActionOpen.setText("Open");
chudy@google.com902ebe52012-06-29 14:21:22 +0000616
617 QIcon breakpoint;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000618 breakpoint.addFile(QString::fromUtf8(":/breakpoint.png"),
chudy@google.com7dcae672012-07-09 20:26:53 +0000619 QSize(), QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000620 fActionBreakpoint.setShortcut(QKeySequence(tr("Ctrl+B")));
chudy@google.comc432f002012-07-10 13:19:25 +0000621 fActionBreakpoint.setIcon(breakpoint);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000622 fActionBreakpoint.setText("Breakpoints");
chudy@google.com902ebe52012-06-29 14:21:22 +0000623
624 QIcon cancel;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000625 cancel.addFile(QString::fromUtf8(":/reload.png"), QSize(),
chudy@google.com7dcae672012-07-09 20:26:53 +0000626 QIcon::Normal, QIcon::Off);
chudy@google.comc432f002012-07-10 13:19:25 +0000627 fActionCancel.setIcon(cancel);
628 fActionCancel.setText("Clear Filter");
chudy@google.com902ebe52012-06-29 14:21:22 +0000629
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000630 fActionClearBreakpoints.setShortcut(QKeySequence(tr("Alt+B")));
631 fActionClearBreakpoints.setText("Clear Breakpoints");
632
633 fActionClearDeletes.setShortcut(QKeySequence(tr("Alt+X")));
634 fActionClearDeletes.setText("Clear Deletes");
635
chudy@google.come504de02012-07-16 18:35:23 +0000636 fActionClose.setShortcuts(QKeySequence::Quit);
chudy@google.comc432f002012-07-10 13:19:25 +0000637 fActionClose.setText("Exit");
chudy@google.com902ebe52012-06-29 14:21:22 +0000638
chudy@google.come504de02012-07-16 18:35:23 +0000639 fActionCreateBreakpoint.setShortcut(QKeySequence(tr("B")));
640 fActionCreateBreakpoint.setText("Set Breakpoint");
641
642 fActionDelete.setShortcut(QKeySequence(tr("X")));
chudy@google.comc432f002012-07-10 13:19:25 +0000643 fActionDelete.setText("Delete Command");
chudy@google.com902ebe52012-06-29 14:21:22 +0000644
chudy@google.come504de02012-07-16 18:35:23 +0000645 fActionDirectory.setShortcut(QKeySequence(tr("Ctrl+D")));
646 fActionDirectory.setText("Directory");
chudy@google.com902ebe52012-06-29 14:21:22 +0000647
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000648 QIcon profile;
robertphillips@google.comd1636362012-11-19 18:25:09 +0000649 profile.addFile(QString::fromUtf8(":/profile.png"), QSize(),
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000650 QIcon::Normal, QIcon::Off);
651 fActionProfile.setIcon(profile);
652 fActionProfile.setText("Profile");
robertphillips@google.come099bc42012-11-19 16:26:40 +0000653 fActionProfile.setDisabled(true);
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000654
chudy@google.comc432f002012-07-10 13:19:25 +0000655 QIcon inspector;
robertphillips@google.comd1636362012-11-19 18:25:09 +0000656 inspector.addFile(QString::fromUtf8(":/inspector.png"),
chudy@google.comc432f002012-07-10 13:19:25 +0000657 QSize(), QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000658 fActionInspector.setShortcut(QKeySequence(tr("Ctrl+I")));
chudy@google.comc432f002012-07-10 13:19:25 +0000659 fActionInspector.setIcon(inspector);
chudy@google.come504de02012-07-16 18:35:23 +0000660 fActionInspector.setText("Inspector");
chudy@google.com902ebe52012-06-29 14:21:22 +0000661
chudy@google.comc432f002012-07-10 13:19:25 +0000662 QIcon play;
robertphillips@google.comd1636362012-11-19 18:25:09 +0000663 play.addFile(QString::fromUtf8(":/play.png"), QSize(),
chudy@google.comc432f002012-07-10 13:19:25 +0000664 QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000665 fActionPlay.setShortcut(QKeySequence(tr("Ctrl+P")));
chudy@google.comc432f002012-07-10 13:19:25 +0000666 fActionPlay.setIcon(play);
667 fActionPlay.setText("Play");
chudy@google.com902ebe52012-06-29 14:21:22 +0000668
chudy@google.come504de02012-07-16 18:35:23 +0000669 QIcon pause;
robertphillips@google.comd1636362012-11-19 18:25:09 +0000670 pause.addFile(QString::fromUtf8(":/pause.png"), QSize(),
chudy@google.comc432f002012-07-10 13:19:25 +0000671 QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000672 fActionPause.setShortcut(QKeySequence(tr("Space")));
673 fActionPause.setCheckable(true);
674 fActionPause.setIcon(pause);
675 fActionPause.setText("Pause");
676
chudy@google.comc432f002012-07-10 13:19:25 +0000677 QIcon rewind;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000678 rewind.addFile(QString::fromUtf8(":/rewind.png"), QSize(),
chudy@google.comc432f002012-07-10 13:19:25 +0000679 QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000680 fActionRewind.setShortcut(QKeySequence(tr("Ctrl+R")));
chudy@google.comc432f002012-07-10 13:19:25 +0000681 fActionRewind.setIcon(rewind);
682 fActionRewind.setText("Rewind");
chudy@google.com902ebe52012-06-29 14:21:22 +0000683
chudy@google.com0ab03392012-07-28 20:16:11 +0000684 fActionSave.setShortcut(QKeySequence::Save);
685 fActionSave.setText("Save");
686 fActionSave.setDisabled(true);
687 fActionSaveAs.setShortcut(QKeySequence::SaveAs);
688 fActionSaveAs.setText("Save As");
689 fActionSaveAs.setDisabled(true);
690
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000691 fActionShowDeletes.setShortcut(QKeySequence(tr("Ctrl+X")));
692 fActionShowDeletes.setText("Deleted Commands");
693
chudy@google.comc432f002012-07-10 13:19:25 +0000694 QIcon stepBack;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000695 stepBack.addFile(QString::fromUtf8(":/previous.png"), QSize(),
chudy@google.comc432f002012-07-10 13:19:25 +0000696 QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000697 fActionStepBack.setShortcut(QKeySequence(tr("[")));
chudy@google.comc432f002012-07-10 13:19:25 +0000698 fActionStepBack.setIcon(stepBack);
699 fActionStepBack.setText("Step Back");
chudy@google.com902ebe52012-06-29 14:21:22 +0000700
chudy@google.comc432f002012-07-10 13:19:25 +0000701 QIcon stepForward;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000702 stepForward.addFile(QString::fromUtf8(":/next.png"),
chudy@google.comc432f002012-07-10 13:19:25 +0000703 QSize(), QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000704 fActionStepForward.setShortcut(QKeySequence(tr("]")));
chudy@google.comc432f002012-07-10 13:19:25 +0000705 fActionStepForward.setIcon(stepForward);
706 fActionStepForward.setText("Step Forward");
707
chudy@google.coma1226312012-07-26 20:26:44 +0000708 fActionZoomIn.setShortcut(QKeySequence(tr("Ctrl+=")));
709 fActionZoomIn.setText("Zoom In");
710 fActionZoomOut.setShortcut(QKeySequence(tr("Ctrl+-")));
711 fActionZoomOut.setText("Zoom Out");
712
chudy@google.comc432f002012-07-10 13:19:25 +0000713 fListWidget.setItemDelegate(new SkListWidget(&fListWidget));
714 fListWidget.setObjectName(QString::fromUtf8("listWidget"));
715 fListWidget.setMaximumWidth(250);
716
717 fFilter.addItem("--Filter By Available Commands--");
718
719 fDirectoryWidget.setMaximumWidth(250);
720 fDirectoryWidget.setStyleSheet("QListWidget::Item {padding: 5px;}");
721
722 fCanvasWidget.setSizePolicy(QSizePolicy::Expanding,
chudy@google.com7dcae672012-07-09 20:26:53 +0000723 QSizePolicy::Expanding);
chudy@google.com902ebe52012-06-29 14:21:22 +0000724
skia.committer@gmail.com1c9c0d32012-11-22 02:02:41 +0000725 fImageWidget.setFixedSize(SkImageWidget::kImageWidgetWidth,
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000726 SkImageWidget::kImageWidgetHeight);
727
chudy@google.comc432f002012-07-10 13:19:25 +0000728 fInspectorWidget.setSizePolicy(QSizePolicy::Expanding,
chudy@google.com7dcae672012-07-09 20:26:53 +0000729 QSizePolicy::Expanding);
chudy@google.comc432f002012-07-10 13:19:25 +0000730 fInspectorWidget.setMaximumHeight(300);
chudy@google.com902ebe52012-06-29 14:21:22 +0000731
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000732 fSettingsAndImageLayout.setSpacing(6);
733 fSettingsAndImageLayout.addWidget(&fSettingsWidget);
734 fSettingsAndImageLayout.addWidget(&fImageWidget);
735
chudy@google.comc432f002012-07-10 13:19:25 +0000736 fSettingsWidget.setSizePolicy(QSizePolicy::Expanding,
737 QSizePolicy::Expanding);
738 fSettingsWidget.setMaximumWidth(250);
chudy@google.com902ebe52012-06-29 14:21:22 +0000739
chudy@google.comc432f002012-07-10 13:19:25 +0000740 fLeftColumnLayout.setSpacing(6);
741 fLeftColumnLayout.addWidget(&fListWidget);
742 fLeftColumnLayout.addWidget(&fDirectoryWidget);
chudy@google.com902ebe52012-06-29 14:21:22 +0000743
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000744 fCanvasSettingsAndImageLayout.setSpacing(6);
745 fCanvasSettingsAndImageLayout.addWidget(&fCanvasWidget);
746 fCanvasSettingsAndImageLayout.addLayout(&fSettingsAndImageLayout);
747
chudy@google.com902ebe52012-06-29 14:21:22 +0000748
chudy@google.comc432f002012-07-10 13:19:25 +0000749 fMainAndRightColumnLayout.setSpacing(6);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000750 fMainAndRightColumnLayout.addLayout(&fCanvasSettingsAndImageLayout);
chudy@google.comc432f002012-07-10 13:19:25 +0000751 fMainAndRightColumnLayout.addWidget(&fInspectorWidget);
chudy@google.com902ebe52012-06-29 14:21:22 +0000752
chudy@google.com2d537a12012-07-31 12:49:52 +0000753 fCentralWidget.setLayout(&fContainerLayout);
chudy@google.comc432f002012-07-10 13:19:25 +0000754 fContainerLayout.setSpacing(6);
755 fContainerLayout.setContentsMargins(11, 11, 11, 11);
756 fContainerLayout.addLayout(&fLeftColumnLayout);
757 fContainerLayout.addLayout(&fMainAndRightColumnLayout);
758
759 SkDebuggerGUI->setCentralWidget(&fCentralWidget);
760 SkDebuggerGUI->setStatusBar(&fStatusBar);
761
chudy@google.come504de02012-07-16 18:35:23 +0000762 fToolBar.setIconSize(QSize(32, 32));
chudy@google.comc432f002012-07-10 13:19:25 +0000763 fToolBar.setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
764 SkDebuggerGUI->addToolBar(Qt::TopToolBarArea, &fToolBar);
chudy@google.com902ebe52012-06-29 14:21:22 +0000765
chudy@google.com0ab03392012-07-28 20:16:11 +0000766 fSpacer.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
chudy@google.com902ebe52012-06-29 14:21:22 +0000767
chudy@google.comc432f002012-07-10 13:19:25 +0000768 fToolBar.addAction(&fActionRewind);
769 fToolBar.addAction(&fActionStepBack);
chudy@google.come504de02012-07-16 18:35:23 +0000770 fToolBar.addAction(&fActionPause);
chudy@google.comc432f002012-07-10 13:19:25 +0000771 fToolBar.addAction(&fActionStepForward);
772 fToolBar.addAction(&fActionPlay);
773 fToolBar.addSeparator();
chudy@google.come504de02012-07-16 18:35:23 +0000774 fToolBar.addAction(&fActionInspector);
chudy@google.comc432f002012-07-10 13:19:25 +0000775 fToolBar.addSeparator();
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000776 fToolBar.addAction(&fActionProfile);
777
778 fToolBar.addSeparator();
chudy@google.com0ab03392012-07-28 20:16:11 +0000779 fToolBar.addWidget(&fSpacer);
chudy@google.comc432f002012-07-10 13:19:25 +0000780 fToolBar.addWidget(&fFilter);
781 fToolBar.addAction(&fActionCancel);
chudy@google.com902ebe52012-06-29 14:21:22 +0000782
783 // TODO(chudy): Remove static call.
784 fDirectoryWidgetActive = false;
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000785 fPath = "";
786 fFileName = "";
chudy@google.com902ebe52012-06-29 14:21:22 +0000787 setupDirectoryWidget();
788 fDirectoryWidgetActive = true;
789
chudy@google.com902ebe52012-06-29 14:21:22 +0000790 // Menu Bar
chudy@google.comc432f002012-07-10 13:19:25 +0000791 fMenuFile.setTitle("File");
792 fMenuFile.addAction(&fActionOpen);
chudy@google.com0ab03392012-07-28 20:16:11 +0000793 fMenuFile.addAction(&fActionSave);
794 fMenuFile.addAction(&fActionSaveAs);
chudy@google.comc432f002012-07-10 13:19:25 +0000795 fMenuFile.addAction(&fActionClose);
chudy@google.come504de02012-07-16 18:35:23 +0000796
797 fMenuEdit.setTitle("Edit");
798 fMenuEdit.addAction(&fActionDelete);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000799 fMenuEdit.addAction(&fActionClearDeletes);
800 fMenuEdit.addSeparator();
chudy@google.come504de02012-07-16 18:35:23 +0000801 fMenuEdit.addAction(&fActionCreateBreakpoint);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000802 fMenuEdit.addAction(&fActionClearBreakpoints);
chudy@google.come504de02012-07-16 18:35:23 +0000803
chudy@google.comc432f002012-07-10 13:19:25 +0000804 fMenuNavigate.setTitle("Navigate");
chudy@google.come504de02012-07-16 18:35:23 +0000805 fMenuNavigate.addAction(&fActionRewind);
806 fMenuNavigate.addAction(&fActionStepBack);
807 fMenuNavigate.addAction(&fActionStepForward);
808 fMenuNavigate.addAction(&fActionPlay);
809 fMenuNavigate.addAction(&fActionPause);
chudy@google.comc432f002012-07-10 13:19:25 +0000810 fMenuNavigate.addAction(&fActionGoToLine);
chudy@google.come504de02012-07-16 18:35:23 +0000811
chudy@google.comc432f002012-07-10 13:19:25 +0000812 fMenuView.setTitle("View");
chudy@google.come504de02012-07-16 18:35:23 +0000813 fMenuView.addAction(&fActionBreakpoint);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000814 fMenuView.addAction(&fActionShowDeletes);
chudy@google.coma1226312012-07-26 20:26:44 +0000815 fMenuView.addAction(&fActionZoomIn);
816 fMenuView.addAction(&fActionZoomOut);
chudy@google.come504de02012-07-16 18:35:23 +0000817
818 fMenuWindows.setTitle("Window");
819 fMenuWindows.addAction(&fActionInspector);
820 fMenuWindows.addAction(&fActionDirectory);
chudy@google.comc432f002012-07-10 13:19:25 +0000821
822 fActionGoToLine.setText("Go to Line...");
823 fActionGoToLine.setDisabled(true);
824 fMenuBar.addAction(fMenuFile.menuAction());
chudy@google.come504de02012-07-16 18:35:23 +0000825 fMenuBar.addAction(fMenuEdit.menuAction());
chudy@google.comc432f002012-07-10 13:19:25 +0000826 fMenuBar.addAction(fMenuView.menuAction());
827 fMenuBar.addAction(fMenuNavigate.menuAction());
chudy@google.come504de02012-07-16 18:35:23 +0000828 fMenuBar.addAction(fMenuWindows.menuAction());
chudy@google.com902ebe52012-06-29 14:21:22 +0000829
chudy@google.com7dcae672012-07-09 20:26:53 +0000830 fPause = false;
831
chudy@google.comc432f002012-07-10 13:19:25 +0000832 SkDebuggerGUI->setMenuBar(&fMenuBar);
chudy@google.com902ebe52012-06-29 14:21:22 +0000833 QMetaObject::connectSlotsByName(SkDebuggerGUI);
834}
835
836void SkDebuggerGUI::setupDirectoryWidget() {
chudy@google.comc432f002012-07-10 13:19:25 +0000837 QDir dir(fPath);
chudy@google.com902ebe52012-06-29 14:21:22 +0000838 QRegExp r(".skp");
chudy@google.comc432f002012-07-10 13:19:25 +0000839 fDirectoryWidget.clear();
840 const QStringList files = dir.entryList();
chudy@google.com902ebe52012-06-29 14:21:22 +0000841 foreach (QString f, files) {
chudy@google.com7dcae672012-07-09 20:26:53 +0000842 if (f.contains(r))
chudy@google.comc432f002012-07-10 13:19:25 +0000843 fDirectoryWidget.addItem(f);
chudy@google.com902ebe52012-06-29 14:21:22 +0000844 }
845}
846
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000847// SkOffsetPicturePlayback records the offset of each command in the picture.
848// These are needed by the profiling system.
849class SkOffsetPicturePlayback : public SkPicturePlayback {
850public:
851 SkOffsetPicturePlayback(SkStream* stream, const SkPictInfo& info, bool* isValid,
852 SkSerializationHelpers::DecodeBitmap decoder)
853 : INHERITED(stream, info, isValid, decoder) {
854 }
855
856 const SkTDArray<size_t>& offsets() const { return fOffsets; }
857
858protected:
859 SkTDArray<size_t> fOffsets;
860
861 virtual void preDraw(size_t offset, int type) {
862 *fOffsets.append() = offset;
863 }
864
865private:
866 typedef SkPicturePlayback INHERITED;
867};
868
869// Picture to wrap an SkOffsetPicturePlayback.
870class SkOffsetPicture : public SkPicture {
871public:
skia.committer@gmail.com884e60b2012-11-16 02:01:17 +0000872 SkOffsetPicture(SkStream* stream,
873 bool* success,
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000874 SkSerializationHelpers::DecodeBitmap decoder) {
875 if (success) {
876 *success = false;
877 }
878 fRecord = NULL;
879 fPlayback = NULL;
880 fWidth = fHeight = 0;
881
882 SkPictInfo info;
883
884 if (!stream->read(&info, sizeof(info))) {
885 return;
886 }
887 if (PICTURE_VERSION != info.fVersion) {
888 return;
889 }
890
891 if (stream->readBool()) {
892 bool isValid = false;
893 fPlayback = SkNEW_ARGS(SkOffsetPicturePlayback, (stream, info, &isValid, decoder));
894 if (!isValid) {
895 SkDELETE(fPlayback);
896 fPlayback = NULL;
897 return;
898 }
899 }
900
901 // do this at the end, so that they will be zero if we hit an error.
902 fWidth = info.fWidth;
903 fHeight = info.fHeight;
904 if (success) {
905 *success = true;
906 }
907 }
908
skia.committer@gmail.com884e60b2012-11-16 02:01:17 +0000909 const SkTDArray<size_t>& offsets() const {
910 return ((SkOffsetPicturePlayback*) fPlayback)->offsets();
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000911 }
912
913private:
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000914 // disallow default ctor b.c. we don't have a good way to setup the fPlayback ptr
915 SkOffsetPicture();
916 // disallow the copy ctor - enabling would require copying code from SkPicture
917 SkOffsetPicture(const SkOffsetPicture& src);
918
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000919 typedef SkPicture INHERITED;
920};
921
922
923
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000924void SkDebuggerGUI::loadPicture(const SkString& fileName) {
925 fFileName = fileName;
chudy@google.comd3058f52012-07-19 13:41:27 +0000926 fLoading = true;
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000927 SkStream* stream = SkNEW_ARGS(SkFILEStream, (fileName.c_str()));
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000928 SkOffsetPicture* picture = SkNEW_ARGS(SkOffsetPicture, (stream, NULL, &SkImageDecoder::DecodeStream));
929
chudy@google.com686e6802012-08-14 16:00:32 +0000930 fCanvasWidget.resetWidgetTransform();
chudy@google.com607357f2012-08-07 16:12:23 +0000931 fDebugger.loadPicture(picture);
chudy@google.com4c7962e2012-08-14 19:38:31 +0000932
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000933 fOffsets = picture->offsets();
934
chudy@google.com607357f2012-08-07 16:12:23 +0000935 SkSafeUnref(stream);
936 SkSafeUnref(picture);
937
chudy@google.com97cee972012-08-07 20:41:37 +0000938 // Will this automatically clear out due to nature of refcnt?
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000939 SkTArray<SkString>* commands = fDebugger.getDrawCommandsAsStrings();
chudy@google.com607357f2012-08-07 16:12:23 +0000940
robertphillips@google.comfe830a42012-11-15 16:33:31 +0000941 // If SkPicturePlayback is compiled w/o SK_PICTURE_PROFILING_STUBS
942 // the offset count will always be zero
943 SkASSERT(0 == fOffsets.count() || commands->count() == fOffsets.count());
robertphillips@google.come099bc42012-11-19 16:26:40 +0000944 if (commands->count() == fOffsets.count()) {
945 fActionProfile.setDisabled(false);
robertphillips@google.comfe830a42012-11-15 16:33:31 +0000946 }
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000947
chudy@google.com7dcae672012-07-09 20:26:53 +0000948 /* fDebugCanvas is reinitialized every load picture. Need it to retain value
chudy@google.com607357f2012-08-07 16:12:23 +0000949 * of the visibility filter.
950 * TODO(chudy): This should be deprecated since fDebugger is not
951 * recreated.
952 * */
953 fDebugger.highlightCurrentCommand(fSettingsWidget.getVisibilityButton()->isChecked());
954
chudy@google.com97cee972012-08-07 20:41:37 +0000955 setupListWidget(commands);
956 setupComboBox(commands);
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000957 setupOverviewText(NULL, 0.0);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000958 fInspectorWidget.setDisabled(false);
chudy@google.come606d6e2012-07-12 14:31:25 +0000959 fSettingsWidget.setDisabled(false);
chudy@google.comd3058f52012-07-19 13:41:27 +0000960 fMenuEdit.setDisabled(false);
961 fMenuNavigate.setDisabled(false);
962 fMenuView.setDisabled(false);
chudy@google.com0ab03392012-07-28 20:16:11 +0000963 fActionSave.setDisabled(false);
964 fActionSaveAs.setDisabled(false);
chudy@google.comd3058f52012-07-19 13:41:27 +0000965 fLoading = false;
966 actionPlay();
chudy@google.com902ebe52012-06-29 14:21:22 +0000967}
968
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000969void SkDebuggerGUI::setupListWidget(SkTArray<SkString>* command) {
chudy@google.comc432f002012-07-10 13:19:25 +0000970 fListWidget.clear();
chudy@google.com902ebe52012-06-29 14:21:22 +0000971 int counter = 0;
robertphillips@google.com30d35f22012-11-06 16:45:36 +0000972 int indent = 0;
chudy@google.com97cee972012-08-07 20:41:37 +0000973 for (int i = 0; i < command->count(); i++) {
chudy@google.com902ebe52012-06-29 14:21:22 +0000974 QListWidgetItem *item = new QListWidgetItem();
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000975 item->setData(Qt::DisplayRole, (*command)[i].c_str());
chudy@google.com902ebe52012-06-29 14:21:22 +0000976 item->setData(Qt::UserRole + 1, counter++);
robertphillips@google.com30d35f22012-11-06 16:45:36 +0000977
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000978 if (0 == strcmp("Restore", (*command)[i].c_str())) {
robertphillips@google.com30d35f22012-11-06 16:45:36 +0000979 indent -= 10;
980 }
981
982 item->setData(Qt::UserRole + 3, indent);
983
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000984 if (0 == strcmp("Save", (*command)[i].c_str()) ||
985 0 == strcmp("Save Layer", (*command)[i].c_str())) {
robertphillips@google.com30d35f22012-11-06 16:45:36 +0000986 indent += 10;
987 }
988
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000989 item->setData(Qt::UserRole + 4, -1.0);
990
chudy@google.comc432f002012-07-10 13:19:25 +0000991 fListWidget.addItem(item);
chudy@google.com902ebe52012-06-29 14:21:22 +0000992 }
993}
994
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000995void SkDebuggerGUI::setupOverviewText(const SkTDArray<double>* typeTimes, double totTime) {
chudy@google.com902ebe52012-06-29 14:21:22 +0000996
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000997 const SkTDArray<SkDrawCommand*>& commands = fDebugger.getDrawCommands();
998
999 SkTDArray<int> counts;
1000 counts.setCount(LAST_DRAWTYPE_ENUM+1);
1001 for (int i = 0; i < LAST_DRAWTYPE_ENUM+1; ++i) {
1002 counts[i] = 0;
1003 }
1004
1005 for (int i = 0; i < commands.count(); i++) {
1006 counts[commands[i]->getType()]++;
chudy@google.com902ebe52012-06-29 14:21:22 +00001007 }
1008
1009 QString overview;
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +00001010 int total = 0;
1011#ifdef SK_DEBUG
1012 double totPercent = 0, tempSum = 0;
1013#endif
1014 for (int i = 0; i < LAST_DRAWTYPE_ENUM+1; ++i) {
1015 if (0 == counts[i]) {
1016 // if there were no commands of this type then they should've consumed no time
1017 SkASSERT(NULL == typeTimes || 0.0 == (*typeTimes)[i]);
1018 continue;
1019 }
1020
1021 overview.append(SkDrawCommand::GetCommandString((DrawType) i));
chudy@google.com902ebe52012-06-29 14:21:22 +00001022 overview.append(": ");
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +00001023 overview.append(QString::number(counts[i]));
1024 if (NULL != typeTimes) {
1025 overview.append(" - ");
1026 overview.append(QString::number((*typeTimes)[i], 'f', 1));
1027 overview.append("ms");
1028 overview.append(" - ");
1029 double percent = 100.0*(*typeTimes)[i]/totTime;
1030 overview.append(QString::number(percent, 'f', 1));
1031 overview.append("%");
1032#ifdef SK_DEBUG
1033 totPercent += percent;
1034 tempSum += (*typeTimes)[i];
1035#endif
1036 }
chudy@google.com902ebe52012-06-29 14:21:22 +00001037 overview.append("<br/>");
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +00001038 total += counts[i];
chudy@google.com902ebe52012-06-29 14:21:22 +00001039 }
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +00001040#ifdef SK_DEBUG
1041 if (NULL != typeTimes) {
1042 SkASSERT(SkScalarNearlyEqual(totPercent, 100.0));
1043 SkASSERT(SkScalarNearlyEqual(tempSum, totTime));
1044 }
1045#endif
1046
1047 if (totTime > 0.0) {
1048 overview.append("Total Time: ");
1049 overview.append(QString::number(totTime, 'f', 2));
1050 overview.append("ms");
1051#ifdef SK_DEBUG
1052 overview.append(" ");
1053 overview.append(QString::number(totPercent));
1054 overview.append("% ");
1055#endif
1056 overview.append("<br/>");
1057 }
1058
1059 QString totalStr;
1060 totalStr.append("Total Draw Commands: ");
1061 totalStr.append(QString::number(total));
1062 totalStr.append("<br/>");
1063 overview.insert(0, totalStr);
chudy@google.com902ebe52012-06-29 14:21:22 +00001064
1065 overview.append("<br/>");
chudy@google.com607357f2012-08-07 16:12:23 +00001066 overview.append("SkPicture Width: ");
chudy@google.com902ebe52012-06-29 14:21:22 +00001067 // NOTE(chudy): This is where we can pull out the SkPictures width.
chudy@google.com607357f2012-08-07 16:12:23 +00001068 overview.append(QString::number(fDebugger.pictureWidth()));
chudy@google.com902ebe52012-06-29 14:21:22 +00001069 overview.append("px<br/>");
chudy@google.com607357f2012-08-07 16:12:23 +00001070 overview.append("SkPicture Height: ");
1071 overview.append(QString::number(fDebugger.pictureHeight()));
chudy@google.com902ebe52012-06-29 14:21:22 +00001072 overview.append("px");
chudy@google.com6bd109a2012-08-14 19:34:13 +00001073 fInspectorWidget.setText(overview, SkInspectorWidget::kOverview_TabType);
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +00001074}
1075
1076void SkDebuggerGUI::setupComboBox(SkTArray<SkString>* command) {
1077 fFilter.clear();
1078 fFilter.addItem("--Filter By Available Commands--");
1079
1080 std::map<std::string, int> map;
1081 for (int i = 0; i < command->count(); i++) {
1082 map[(*command)[i].c_str()]++;
1083 }
1084
skia.committer@gmail.com34587162012-11-20 02:01:23 +00001085 for (std::map<std::string, int>::iterator it = map.begin(); it != map.end();
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +00001086 ++it) {
1087 fFilter.addItem((it->first).c_str());
1088 }
chudy@google.com902ebe52012-06-29 14:21:22 +00001089
1090 // NOTE(chudy): Makes first item unselectable.
chudy@google.com7dcae672012-07-09 20:26:53 +00001091 QStandardItemModel* model = qobject_cast<QStandardItemModel*>(
chudy@google.comc432f002012-07-10 13:19:25 +00001092 fFilter.model());
1093 QModelIndex firstIndex = model->index(0, fFilter.modelColumn(),
1094 fFilter.rootModelIndex());
chudy@google.com902ebe52012-06-29 14:21:22 +00001095 QStandardItem* firstItem = model->itemFromIndex(firstIndex);
1096 firstItem->setSelectable(false);
1097}