blob: 8f1dc5520849b1d795511457b52fd104c17bfb51 [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"
robertphillips@google.come174a8b2012-11-27 16:04:42 +000015
16#if defined(SK_BUILD_FOR_WIN32)
17 #include "BenchSysTimer_windows.h"
18#elif defined(SK_BUILD_FOR_MAC)
19 #include "BenchSysTimer_mach.h"
20#elif defined(SK_BUILD_FOR_UNIX) || defined(SK_BUILD_FOR_ANDROID)
21 #include "BenchSysTimer_posix.h"
22#else
23 #include "BenchSysTimer_c.h"
24#endif
25
chudy@google.com902ebe52012-06-29 14:21:22 +000026
27SkDebuggerGUI::SkDebuggerGUI(QWidget *parent) :
chudy@google.comc432f002012-07-10 13:19:25 +000028 QMainWindow(parent)
chudy@google.com2d537a12012-07-31 12:49:52 +000029 , fCentralWidget(this)
30 , fStatusBar(this)
31 , fToolBar(this)
chudy@google.comc432f002012-07-10 13:19:25 +000032 , fActionOpen(this)
33 , fActionBreakpoint(this)
robertphillips@google.comd26c7062012-11-12 20:42:12 +000034 , fActionProfile(this)
chudy@google.comc432f002012-07-10 13:19:25 +000035 , fActionCancel(this)
chudy@google.com7e4cfbf2012-07-17 15:40:51 +000036 , fActionClearBreakpoints(this)
chudy@google.come504de02012-07-16 18:35:23 +000037 , fActionClearDeletes(this)
chudy@google.comc432f002012-07-10 13:19:25 +000038 , fActionClose(this)
chudy@google.come504de02012-07-16 18:35:23 +000039 , fActionCreateBreakpoint(this)
chudy@google.comc432f002012-07-10 13:19:25 +000040 , fActionDelete(this)
41 , fActionDirectory(this)
42 , fActionGoToLine(this)
43 , fActionInspector(this)
44 , fActionPlay(this)
chudy@google.come504de02012-07-16 18:35:23 +000045 , fActionPause(this)
chudy@google.comc432f002012-07-10 13:19:25 +000046 , fActionRewind(this)
chudy@google.com0ab03392012-07-28 20:16:11 +000047 , fActionSave(this)
48 , fActionSaveAs(this)
chudy@google.com7e4cfbf2012-07-17 15:40:51 +000049 , fActionShowDeletes(this)
chudy@google.comc432f002012-07-10 13:19:25 +000050 , fActionStepBack(this)
51 , fActionStepForward(this)
chudy@google.coma1226312012-07-26 20:26:44 +000052 , fActionZoomIn(this)
53 , fActionZoomOut(this)
54 , fMapper(this)
chudy@google.comc432f002012-07-10 13:19:25 +000055 , fListWidget(&fCentralWidget)
56 , fDirectoryWidget(&fCentralWidget)
chudy@google.com607357f2012-08-07 16:12:23 +000057 , fCanvasWidget(this, &fDebugger)
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +000058 , fImageWidget(&fDebugger)
chudy@google.comc432f002012-07-10 13:19:25 +000059 , fMenuBar(this)
60 , fMenuFile(this)
61 , fMenuNavigate(this)
62 , fMenuView(this)
chudy@google.com7e4cfbf2012-07-17 15:40:51 +000063 , fBreakpointsActivated(false)
64 , fDeletesActivated(false)
65 , fPause(false)
chudy@google.comd3058f52012-07-19 13:41:27 +000066 , fLoading(false)
chudy@google.comc432f002012-07-10 13:19:25 +000067{
chudy@google.com902ebe52012-06-29 14:21:22 +000068 setupUi(this);
robertphillips@google.comdd4b7452013-01-22 19:38:46 +000069 fListWidget.setSelectionMode(QAbstractItemView::ExtendedSelection);
chudy@google.comea5488b2012-07-26 19:38:22 +000070 connect(&fListWidget, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)), this, SLOT(registerListClick(QListWidgetItem *)));
chudy@google.comc432f002012-07-10 13:19:25 +000071 connect(&fActionOpen, SIGNAL(triggered()), this, SLOT(openFile()));
chudy@google.comea5488b2012-07-26 19:38:22 +000072 connect(&fActionDirectory, SIGNAL(triggered()), this, SLOT(toggleDirectory()));
73 connect(&fDirectoryWidget, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)), this, SLOT(loadFile(QListWidgetItem *)));
chudy@google.comc432f002012-07-10 13:19:25 +000074 connect(&fActionDelete, SIGNAL(triggered()), this, SLOT(actionDelete()));
chudy@google.comea5488b2012-07-26 19:38:22 +000075 connect(&fListWidget, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(toggleBreakpoint()));
chudy@google.comc432f002012-07-10 13:19:25 +000076 connect(&fActionRewind, SIGNAL(triggered()), this, SLOT(actionRewind()));
77 connect(&fActionPlay, SIGNAL(triggered()), this, SLOT(actionPlay()));
78 connect(&fActionStepBack, SIGNAL(triggered()), this, SLOT(actionStepBack()));
chudy@google.comea5488b2012-07-26 19:38:22 +000079 connect(&fActionStepForward, SIGNAL(triggered()), this, SLOT(actionStepForward()));
80 connect(&fActionBreakpoint, SIGNAL(triggered()), this, SLOT(actionBreakpoints()));
81 connect(&fActionInspector, SIGNAL(triggered()), this, SLOT(actionInspector()));
82 connect(&fActionInspector, SIGNAL(triggered()), this, SLOT(actionSettings()));
83 connect(&fFilter, SIGNAL(activated(QString)), this, SLOT(toggleFilter(QString)));
robertphillips@google.comd26c7062012-11-12 20:42:12 +000084 connect(&fActionProfile, SIGNAL(triggered()), this, SLOT(actionProfile()));
chudy@google.comc432f002012-07-10 13:19:25 +000085 connect(&fActionCancel, SIGNAL(triggered()), this, SLOT(actionCancel()));
chudy@google.com7e4cfbf2012-07-17 15:40:51 +000086 connect(&fActionClearBreakpoints, SIGNAL(triggered()), this, SLOT(actionClearBreakpoints()));
87 connect(&fActionClearDeletes, SIGNAL(triggered()), this, SLOT(actionClearDeletes()));
chudy@google.comc432f002012-07-10 13:19:25 +000088 connect(&fActionClose, SIGNAL(triggered()), this, SLOT(actionClose()));
chudy@google.comea5488b2012-07-26 19:38:22 +000089 connect(fSettingsWidget.getVisibilityButton(), SIGNAL(toggled(bool)), this, SLOT(actionCommandFilter()));
robertphillips@google.come8fe4bc2013-02-13 13:26:13 +000090#if SK_SUPPORT_GPU
chudy@google.comea5488b2012-07-26 19:38:22 +000091 connect(fSettingsWidget.getGLCheckBox(), SIGNAL(toggled(bool)), this, SLOT(actionGLWidget(bool)));
robertphillips@google.come8fe4bc2013-02-13 13:26:13 +000092#endif
chudy@google.comea5488b2012-07-26 19:38:22 +000093 connect(fSettingsWidget.getRasterCheckBox(), SIGNAL(toggled(bool)), this, SLOT(actionRasterWidget(bool)));
robertphillips@google.comf4741c12013-02-06 20:13:54 +000094 connect(fSettingsWidget.getOverdrawVizCheckBox(), SIGNAL(toggled(bool)), this, SLOT(actionOverdrawVizWidget(bool)));
chudy@google.comea5488b2012-07-26 19:38:22 +000095 connect(&fActionPause, SIGNAL(toggled(bool)), this, SLOT(pauseDrawing(bool)));
chudy@google.come504de02012-07-16 18:35:23 +000096 connect(&fActionCreateBreakpoint, SIGNAL(activated()), this, SLOT(toggleBreakpoint()));
chudy@google.com7e4cfbf2012-07-17 15:40:51 +000097 connect(&fActionShowDeletes, SIGNAL(triggered()), this, SLOT(showDeletes()));
chudy@google.comea5488b2012-07-26 19:38:22 +000098 connect(&fCanvasWidget, SIGNAL(hitChanged(int)), this, SLOT(selectCommand(int)));
99 connect(&fCanvasWidget, SIGNAL(hitChanged(int)), &fSettingsWidget, SLOT(updateHit(int)));
100 connect(&fCanvasWidget, SIGNAL(scaleFactorChanged(float)), this, SLOT(actionScale(float)));
101 connect(&fCanvasWidget, SIGNAL(commandChanged(int)), &fSettingsWidget, SLOT(updateCommand(int)));
chudy@google.com0ab03392012-07-28 20:16:11 +0000102 connect(&fActionSaveAs, SIGNAL(triggered()), this, SLOT(actionSaveAs()));
103 connect(&fActionSave, SIGNAL(triggered()), this, SLOT(actionSave()));
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000104
bungeman@google.come8cc6e82013-01-17 16:30:56 +0000105 fMapper.setMapping(&fActionZoomIn, SkCanvasWidget::kIn_ZoomCommand);
106 fMapper.setMapping(&fActionZoomOut, SkCanvasWidget::kOut_ZoomCommand);
chudy@google.coma1226312012-07-26 20:26:44 +0000107
108 connect(&fActionZoomIn, SIGNAL(triggered()), &fMapper, SLOT(map()));
109 connect(&fActionZoomOut, SIGNAL(triggered()), &fMapper, SLOT(map()));
bungeman@google.come8cc6e82013-01-17 16:30:56 +0000110 connect(&fMapper, SIGNAL(mapped(int)), &fCanvasWidget, SLOT(zoom(int)));
chudy@google.coma1226312012-07-26 20:26:44 +0000111
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000112 fInspectorWidget.setDisabled(true);
chudy@google.comd3058f52012-07-19 13:41:27 +0000113 fMenuEdit.setDisabled(true);
114 fMenuNavigate.setDisabled(true);
115 fMenuView.setDisabled(true);
chudy@google.combbad34d2012-08-13 14:26:36 +0000116
117 SkGraphics::Init();
chudy@google.com902ebe52012-06-29 14:21:22 +0000118}
119
chudy@google.combbad34d2012-08-13 14:26:36 +0000120SkDebuggerGUI::~SkDebuggerGUI() {
121 SkGraphics::Term();
122}
chudy@google.com902ebe52012-06-29 14:21:22 +0000123
124void SkDebuggerGUI::actionBreakpoints() {
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000125 fBreakpointsActivated = !fBreakpointsActivated;
chudy@google.comc432f002012-07-10 13:19:25 +0000126 for (int row = 0; row < fListWidget.count(); row++) {
127 QListWidgetItem *item = fListWidget.item(row);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000128 item->setHidden(item->checkState() == Qt::Unchecked && fBreakpointsActivated);
129 }
130}
chudy@google.com902ebe52012-06-29 14:21:22 +0000131
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000132void SkDebuggerGUI::showDeletes() {
133 fDeletesActivated = !fDeletesActivated;
134 for (int row = 0; row < fListWidget.count(); row++) {
135 QListWidgetItem *item = fListWidget.item(row);
chudy@google.com607357f2012-08-07 16:12:23 +0000136 item->setHidden(fDebugger.isCommandVisible(row)
137 && fDeletesActivated);
chudy@google.com902ebe52012-06-29 14:21:22 +0000138 }
139}
140
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000141// The timed picture playback uses the SkPicturePlayback's profiling stubs
142// to time individual commands. The offsets are needed to map SkPicture
143// offsets to individual commands.
144class SkTimedPicturePlayback : public SkPicturePlayback {
145public:
146 SkTimedPicturePlayback(SkStream* stream, const SkPictInfo& info, bool* isValid,
scroggo@google.comf8d7d272013-02-22 21:38:35 +0000147 SkPicture::InstallPixelRefProc proc, const SkTDArray<size_t>& offsets,
robertphillips@google.com5f971142012-12-07 20:48:56 +0000148 const SkTDArray<bool>& deletedCommands)
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000149 : INHERITED(stream, info, isValid, decoder)
robertphillips@google.com5f971142012-12-07 20:48:56 +0000150 , fOffsets(offsets)
bungeman@google.come8cc6e82013-01-17 16:30:56 +0000151 , fSkipCommands(deletedCommands)
152 , fTot(0.0)
153 , fCurCommand(0) {
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000154 fTimes.setCount(fOffsets.count());
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000155 fTypeTimes.setCount(LAST_DRAWTYPE_ENUM+1);
156 this->resetTimes();
157 }
158
159 void resetTimes() {
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000160 for (int i = 0; i < fOffsets.count(); ++i) {
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000161 fTimes[i] = 0.0;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000162 }
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000163 for (int i = 0; i < fTypeTimes.count(); ++i) {
164 fTypeTimes[i] = 0.0f;
165 }
166 fTot = 0.0;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000167 }
168
169 int count() const { return fTimes.count(); }
170
171 double time(int index) const { return fTimes[index] / fTot; }
172
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000173 const SkTDArray<double>* typeTimes() const { return &fTypeTimes; }
174
175 double totTime() const { return fTot; }
176
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000177protected:
robertphillips@google.come174a8b2012-11-27 16:04:42 +0000178 BenchSysTimer fTimer;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000179 SkTDArray<size_t> fOffsets; // offset in the SkPicture for each command
robertphillips@google.com5f971142012-12-07 20:48:56 +0000180 SkTDArray<bool> fSkipCommands; // has the command been deleted in the GUI?
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000181 SkTDArray<double> fTimes; // sum of time consumed for each command
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000182 SkTDArray<double> fTypeTimes; // sum of time consumed for each type of command (e.g., drawPath)
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000183 double fTot; // total of all times in 'fTimes'
184 size_t fCurOffset;
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.comca47aae2012-12-12 15:58:25 +0000188 virtual size_t preDraw(size_t offset, int type) {
skia.committer@gmail.com884e60b2012-11-16 02:01:17 +0000189 // This search isn't as bad as it seems. In normal playback mode, the
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000190 // base class steps through the commands in order and can only skip ahead
skia.committer@gmail.com884e60b2012-11-16 02:01:17 +0000191 // a bit on a clip. This class is only used during profiling so we
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000192 // don't have to worry about forward/backward scrubbing through commands.
193 for (int i = 0; offset != fOffsets[fCurCommand]; ++i) {
194 fCurCommand = (fCurCommand+1) % fOffsets.count();
195 SkASSERT(i <= fOffsets.count()); // should always find the offset in the list
196 }
197
robertphillips@google.com5f971142012-12-07 20:48:56 +0000198 if (fSkipCommands[fCurCommand]) {
199 while (fCurCommand < fSkipCommands.count() && fSkipCommands[fCurCommand]) {
200 ++fCurCommand;
201 }
202 if (fCurCommand == fSkipCommands.count()) {
203 // Signal SkPicturePlayback to stop playing back
204 return SK_MaxU32;
205 }
206 return fOffsets[fCurCommand];
207 }
208
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000209 fCurOffset = offset;
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000210 fCurType = type;
211 // The SkDebugCanvas doesn't recognize these types. This class needs to
212 // convert or else we'll wind up with a mismatch between the type counts
213 // the debugger displays and the profile times.
214 if (DRAW_POS_TEXT_TOP_BOTTOM == type) {
215 fCurType = DRAW_POS_TEXT;
216 } else if (DRAW_POS_TEXT_H_TOP_BOTTOM == type) {
217 fCurType = DRAW_POS_TEXT_H;
218 }
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000219
robertphillips@google.come174a8b2012-11-27 16:04:42 +0000220#if defined(SK_BUILD_FOR_WIN32)
221 // CPU timer doesn't work well on Windows
222 fTimer.startWall();
223#else
224 fTimer.startCpu();
225#endif
robertphillips@google.com5f971142012-12-07 20:48:56 +0000226
227 return 0;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000228 }
229
robertphillips@google.comca47aae2012-12-12 15:58:25 +0000230 virtual void postDraw(size_t offset) {
robertphillips@google.come174a8b2012-11-27 16:04:42 +0000231#if defined(SK_BUILD_FOR_WIN32)
232 // CPU timer doesn't work well on Windows
233 double time = fTimer.endWall();
234#else
235 double time = fTimer.endCpu();
236#endif
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000237
238 SkASSERT(offset == fCurOffset);
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000239 SkASSERT(fCurType <= LAST_DRAWTYPE_ENUM);
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000240
robertphillips@google.come174a8b2012-11-27 16:04:42 +0000241 fTimes[fCurCommand] += time;
242 fTypeTimes[fCurType] += time;
243 fTot += time;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000244 }
245
246private:
247 typedef SkPicturePlayback INHERITED;
248};
249
250// Wrap SkPicture to allow installation of an SkTimedPicturePlayback object
251class SkTimedPicture : public SkPicture {
252public:
scroggo@google.comf8d7d272013-02-22 21:38:35 +0000253 explicit SkTimedPicture(SkStream* stream, bool* success, SkPicture::InstallPixelRefProc,
robertphillips@google.com5f971142012-12-07 20:48:56 +0000254 const SkTDArray<size_t>& offsets,
255 const SkTDArray<bool>& deletedCommands) {
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000256 if (success) {
257 *success = false;
258 }
259 fRecord = NULL;
260 fPlayback = NULL;
261 fWidth = fHeight = 0;
262
263 SkPictInfo info;
264
265 if (!stream->read(&info, sizeof(info))) {
266 return;
267 }
268 if (SkPicture::PICTURE_VERSION != info.fVersion) {
269 return;
270 }
271
272 if (stream->readBool()) {
273 bool isValid = false;
skia.committer@gmail.com884e60b2012-11-16 02:01:17 +0000274 fPlayback = SkNEW_ARGS(SkTimedPicturePlayback,
robertphillips@google.com5f971142012-12-07 20:48:56 +0000275 (stream, info, &isValid, decoder, offsets, deletedCommands));
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000276 if (!isValid) {
277 SkDELETE(fPlayback);
278 fPlayback = NULL;
279 return;
280 }
281 }
282
283 // do this at the end, so that they will be zero if we hit an error.
284 fWidth = info.fWidth;
285 fHeight = info.fHeight;
286 if (success) {
287 *success = true;
288 }
289 }
290
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000291 void resetTimes() { ((SkTimedPicturePlayback*) fPlayback)->resetTimes(); }
292
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000293 int count() const { return ((SkTimedPicturePlayback*) fPlayback)->count(); }
294
295 // return the fraction of the total time this command consumed
296 double time(int index) const { return ((SkTimedPicturePlayback*) fPlayback)->time(index); }
297
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000298 const SkTDArray<double>* typeTimes() const { return ((SkTimedPicturePlayback*) fPlayback)->typeTimes(); }
299
300 double totTime() const { return ((SkTimedPicturePlayback*) fPlayback)->totTime(); }
301
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000302private:
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000303 // disallow default ctor b.c. we don't have a good way to setup the fPlayback ptr
304 SkTimedPicture();
305 // disallow the copy ctor - enabling would require copying code from SkPicture
306 SkTimedPicture(const SkTimedPicture& src);
307
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000308 typedef SkPicture INHERITED;
309};
310
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000311// This is a simplification of PictureBenchmark's run with the addition of
312// clearing of the times after the first pass (in resetTimes)
skia.committer@gmail.com34587162012-11-20 02:01:23 +0000313void SkDebuggerGUI::run(SkTimedPicture* pict,
314 sk_tools::PictureRenderer* renderer,
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000315 int repeats) {
316 SkASSERT(pict);
317 if (NULL == pict) {
318 return;
319 }
320
321 SkASSERT(renderer != NULL);
322 if (NULL == renderer) {
323 return;
324 }
325
326 renderer->init(pict);
327
328 renderer->setup();
329 renderer->render(NULL);
jvanverth@google.comade32662013-01-28 21:09:05 +0000330 renderer->resetState(true);
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000331
332 // We throw this away the first batch of times to remove first time effects (such as paging in this program)
333 pict->resetTimes();
334
335 for (int i = 0; i < repeats; ++i) {
336 renderer->setup();
337 renderer->render(NULL);
jvanverth@google.comade32662013-01-28 21:09:05 +0000338 renderer->resetState(true);
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000339 }
340
341 renderer->end();
342}
343
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000344void SkDebuggerGUI::actionProfile() {
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000345 // In order to profile we pass the command offsets (that were read-in
346 // in loadPicture by the SkOffsetPicture) to an SkTimedPlaybackPicture.
skia.committer@gmail.com884e60b2012-11-16 02:01:17 +0000347 // The SkTimedPlaybackPicture in turn passes the offsets to an
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000348 // SkTimedPicturePlayback object which uses them to track the performance
349 // of individual commands.
350 if (fFileName.isEmpty()) {
351 return;
352 }
353
354 SkFILEStream inputStream;
355
356 inputStream.setPath(fFileName.c_str());
357 if (!inputStream.isValid()) {
358 return;
359 }
360
361 bool success = false;
scroggo@google.comf8d7d272013-02-22 21:38:35 +0000362 SkTimedPicture picture(&inputStream, &success, &SkImageDecoder::DecodeMemory,
robertphillips@google.com5f971142012-12-07 20:48:56 +0000363 fOffsets, fSkipCommands);
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000364 if (!success) {
365 return;
366 }
367
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000368 // For now this #if allows switching between tiled and simple rendering
369 // modes. Eventually this will be accomplished via the GUI
robertphillips@google.come174a8b2012-11-27 16:04:42 +0000370#if 0
371 // With the current batch of SysTimers, profiling in tiled mode
372 // gets swamped by the timing overhead:
373 //
374 // tile mode simple mode
375 // debugger 64.2ms 12.8ms
376 // bench_pictures 16.9ms 12.4ms
377 //
378 // This is b.c. in tiled mode each command is called many more times
379 // but typically does less work on each invocation (due to clipping)
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000380 sk_tools::TiledPictureRenderer* renderer = NULL;
381
382 renderer = SkNEW(sk_tools::TiledPictureRenderer);
383 renderer->setTileWidth(256);
384 renderer->setTileHeight(256);
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000385#else
386 sk_tools::SimplePictureRenderer* renderer = NULL;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000387
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000388 renderer = SkNEW(sk_tools::SimplePictureRenderer);
robertphillips@google.com1447aa32013-01-30 21:09:09 +0000389
390#if SK_SUPPORT_GPU
391 if (Qt::Checked == fSettingsWidget.getGLCheckBox()->checkState()) {
392 renderer->setDeviceType(sk_tools::PictureRenderer::kGPU_DeviceType);
393 }
394#endif
395
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000396#endif
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000397
robertphillips@google.come174a8b2012-11-27 16:04:42 +0000398 static const int kNumRepeats = 10;
399
400 run(&picture, renderer, kNumRepeats);
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000401
402 SkASSERT(picture.count() == fListWidget.count());
403
404 // extract the individual command times from the SkTimedPlaybackPicture
405 for (int i = 0; i < picture.count(); ++i) {
406 double temp = picture.time(i);
407
408 QListWidgetItem* item = fListWidget.item(i);
409
410 item->setData(Qt::UserRole + 4, 100.0*temp);
411 }
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000412
413 setupOverviewText(picture.typeTimes(), picture.totTime());
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000414}
415
chudy@google.com902ebe52012-06-29 14:21:22 +0000416void SkDebuggerGUI::actionCancel() {
chudy@google.comc432f002012-07-10 13:19:25 +0000417 for (int row = 0; row < fListWidget.count(); row++) {
418 fListWidget.item(row)->setHidden(false);
chudy@google.com902ebe52012-06-29 14:21:22 +0000419 }
420}
421
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000422void SkDebuggerGUI::actionClearBreakpoints() {
423 for (int row = 0; row < fListWidget.count(); row++) {
424 QListWidgetItem* item = fListWidget.item(row);
425 item->setCheckState(Qt::Unchecked);
426 item->setData(Qt::DecorationRole,
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000427 QPixmap(":/blank.png"));
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000428 }
429}
430
431void SkDebuggerGUI::actionClearDeletes() {
432 for (int row = 0; row < fListWidget.count(); row++) {
433 QListWidgetItem* item = fListWidget.item(row);
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000434 item->setData(Qt::UserRole + 2, QPixmap(":/blank.png"));
chudy@google.com607357f2012-08-07 16:12:23 +0000435 fDebugger.setCommandVisible(row, true);
robertphillips@google.com5f971142012-12-07 20:48:56 +0000436 fSkipCommands[row] = false;
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000437 }
438 if (fPause) {
439 fCanvasWidget.drawTo(fPausedRow);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000440 fImageWidget.draw();
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000441 } else {
442 fCanvasWidget.drawTo(fListWidget.currentRow());
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000443 fImageWidget.draw();
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000444 }
445}
446
chudy@google.com902ebe52012-06-29 14:21:22 +0000447void SkDebuggerGUI::actionCommandFilter() {
chudy@google.com607357f2012-08-07 16:12:23 +0000448 fDebugger.highlightCurrentCommand(
chudy@google.comc432f002012-07-10 13:19:25 +0000449 fSettingsWidget.getVisibilityButton()->isChecked());
450 fCanvasWidget.drawTo(fListWidget.currentRow());
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000451 fImageWidget.draw();
chudy@google.com902ebe52012-06-29 14:21:22 +0000452}
453
454void SkDebuggerGUI::actionClose() {
455 this->close();
456}
457
458void SkDebuggerGUI::actionDelete() {
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000459
robertphillips@google.comdd4b7452013-01-22 19:38:46 +0000460 for (int row = 0; row < fListWidget.count(); ++row) {
461 QListWidgetItem* item = fListWidget.item(row);
462
463 if (!item->isSelected()) {
464 continue;
465 }
466
467 if (fDebugger.isCommandVisible(row)) {
468 item->setData(Qt::UserRole + 2, QPixmap(":/delete.png"));
469 fDebugger.setCommandVisible(row, false);
470 fSkipCommands[row] = true;
471 } else {
472 item->setData(Qt::UserRole + 2, QPixmap(":/blank.png"));
473 fDebugger.setCommandVisible(row, true);
474 fSkipCommands[row] = false;
475 }
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000476 }
477
robertphillips@google.comdd4b7452013-01-22 19:38:46 +0000478 int currentRow = fListWidget.currentRow();
479
chudy@google.come504de02012-07-16 18:35:23 +0000480 if (fPause) {
481 fCanvasWidget.drawTo(fPausedRow);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000482 fImageWidget.draw();
chudy@google.come504de02012-07-16 18:35:23 +0000483 } else {
484 fCanvasWidget.drawTo(currentRow);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000485 fImageWidget.draw();
chudy@google.come504de02012-07-16 18:35:23 +0000486 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000487}
488
robertphillips@google.come8fe4bc2013-02-13 13:26:13 +0000489#if SK_SUPPORT_GPU
chudy@google.comea5488b2012-07-26 19:38:22 +0000490void SkDebuggerGUI::actionGLWidget(bool isToggled) {
491 fCanvasWidget.setWidgetVisibility(SkCanvasWidget::kGPU_WidgetType, !isToggled);
492}
robertphillips@google.come8fe4bc2013-02-13 13:26:13 +0000493#endif
chudy@google.comea5488b2012-07-26 19:38:22 +0000494
chudy@google.com902ebe52012-06-29 14:21:22 +0000495void SkDebuggerGUI::actionInspector() {
chudy@google.comc432f002012-07-10 13:19:25 +0000496 if (fInspectorWidget.isHidden()) {
497 fInspectorWidget.setHidden(false);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000498 fImageWidget.setHidden(false);
chudy@google.com902ebe52012-06-29 14:21:22 +0000499 } else {
chudy@google.comc432f002012-07-10 13:19:25 +0000500 fInspectorWidget.setHidden(true);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000501 fImageWidget.setHidden(true);
chudy@google.com902ebe52012-06-29 14:21:22 +0000502 }
503}
504
505void SkDebuggerGUI::actionPlay() {
chudy@google.comc432f002012-07-10 13:19:25 +0000506 for (int row = fListWidget.currentRow() + 1; row < fListWidget.count();
chudy@google.com7dcae672012-07-09 20:26:53 +0000507 row++) {
chudy@google.comc432f002012-07-10 13:19:25 +0000508 QListWidgetItem *item = fListWidget.item(row);
chudy@google.com902ebe52012-06-29 14:21:22 +0000509 if (item->checkState() == Qt::Checked) {
chudy@google.comc432f002012-07-10 13:19:25 +0000510 fListWidget.setCurrentItem(item);
chudy@google.com902ebe52012-06-29 14:21:22 +0000511 return;
512 }
513 }
chudy@google.comc432f002012-07-10 13:19:25 +0000514 fListWidget.setCurrentRow(fListWidget.count() - 1);
chudy@google.com902ebe52012-06-29 14:21:22 +0000515}
516
chudy@google.comea5488b2012-07-26 19:38:22 +0000517void SkDebuggerGUI::actionRasterWidget(bool isToggled) {
518 fCanvasWidget.setWidgetVisibility(SkCanvasWidget::kRaster_8888_WidgetType, !isToggled);
519}
520
robertphillips@google.comf4741c12013-02-06 20:13:54 +0000521void SkDebuggerGUI::actionOverdrawVizWidget(bool isToggled) {
522 fDebugger.setOverdrawViz(isToggled);
523 fCanvasWidget.update();
524}
525
chudy@google.com902ebe52012-06-29 14:21:22 +0000526void SkDebuggerGUI::actionRewind() {
chudy@google.come504de02012-07-16 18:35:23 +0000527 fListWidget.setCurrentRow(0);
chudy@google.com902ebe52012-06-29 14:21:22 +0000528}
529
chudy@google.com0ab03392012-07-28 20:16:11 +0000530void SkDebuggerGUI::actionSave() {
robertphillips@google.come219baf2013-01-28 19:25:43 +0000531 fFileName = fPath.toAscii().data();
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000532 fFileName.append("/");
robertphillips@google.come219baf2013-01-28 19:25:43 +0000533 fFileName.append(fDirectoryWidget.currentItem()->text().toAscii().data());
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000534 saveToFile(fFileName);
chudy@google.com0ab03392012-07-28 20:16:11 +0000535}
536
537void SkDebuggerGUI::actionSaveAs() {
538 QString filename = QFileDialog::getSaveFileName(this, "Save File", "",
539 "Skia Picture (*skp)");
chudy@google.com38b08ce2012-07-28 23:26:10 +0000540 if (!filename.endsWith(".skp", Qt::CaseInsensitive)) {
chudy@google.com0ab03392012-07-28 20:16:11 +0000541 filename.append(".skp");
542 }
djsollen@google.comc3c82162012-11-13 18:35:10 +0000543 saveToFile(SkString(filename.toAscii().data()));
chudy@google.com0ab03392012-07-28 20:16:11 +0000544}
545
chudy@google.com7dcae672012-07-09 20:26:53 +0000546void SkDebuggerGUI::actionScale(float scaleFactor) {
chudy@google.comc432f002012-07-10 13:19:25 +0000547 fSettingsWidget.setZoomText(scaleFactor);
chudy@google.com7dcae672012-07-09 20:26:53 +0000548}
549
chudy@google.com902ebe52012-06-29 14:21:22 +0000550void SkDebuggerGUI::actionSettings() {
chudy@google.comc432f002012-07-10 13:19:25 +0000551 if (fSettingsWidget.isHidden()) {
552 fSettingsWidget.setHidden(false);
chudy@google.com902ebe52012-06-29 14:21:22 +0000553 } else {
chudy@google.comc432f002012-07-10 13:19:25 +0000554 fSettingsWidget.setHidden(true);
chudy@google.com902ebe52012-06-29 14:21:22 +0000555 }
556}
557
558void SkDebuggerGUI::actionStepBack() {
chudy@google.comc432f002012-07-10 13:19:25 +0000559 int currentRow = fListWidget.currentRow();
chudy@google.com902ebe52012-06-29 14:21:22 +0000560 if (currentRow != 0) {
chudy@google.comc432f002012-07-10 13:19:25 +0000561 fListWidget.setCurrentRow(currentRow - 1);
chudy@google.com902ebe52012-06-29 14:21:22 +0000562 }
563}
564
565void SkDebuggerGUI::actionStepForward() {
chudy@google.comc432f002012-07-10 13:19:25 +0000566 int currentRow = fListWidget.currentRow();
chudy@google.com902ebe52012-06-29 14:21:22 +0000567 QString curRow = QString::number(currentRow);
chudy@google.comc432f002012-07-10 13:19:25 +0000568 QString curCount = QString::number(fListWidget.count());
569 if (currentRow < fListWidget.count() - 1) {
570 fListWidget.setCurrentRow(currentRow + 1);
chudy@google.com902ebe52012-06-29 14:21:22 +0000571 }
572}
573
chudy@google.coma9e937c2012-08-03 17:32:05 +0000574void SkDebuggerGUI::drawComplete() {
chudy@google.com607357f2012-08-07 16:12:23 +0000575 fInspectorWidget.setMatrix(fDebugger.getCurrentMatrix());
576 fInspectorWidget.setClip(fDebugger.getCurrentClip());
chudy@google.coma9e937c2012-08-03 17:32:05 +0000577}
578
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000579void SkDebuggerGUI::saveToFile(const SkString& filename) {
580 SkFILEWStream file(filename.c_str());
robertphillips@google.com25bc2f82013-01-22 18:03:56 +0000581 SkAutoTUnref<SkPicture> copy(fDebugger.copyPicture());
582
583 copy->serialize(&file);
chudy@google.com0ab03392012-07-28 20:16:11 +0000584}
585
chudy@google.com902ebe52012-06-29 14:21:22 +0000586void SkDebuggerGUI::loadFile(QListWidgetItem *item) {
587 if (fDirectoryWidgetActive) {
robertphillips@google.come219baf2013-01-28 19:25:43 +0000588 fFileName = fPath.toAscii().data();
jvanverth@google.com0ac6f162013-02-05 19:44:07 +0000589 // don't add a '/' to files in the local directory
590 if (fFileName.size() > 0) {
591 fFileName.append("/");
592 }
robertphillips@google.come219baf2013-01-28 19:25:43 +0000593 fFileName.append(item->text().toAscii().data());
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000594 loadPicture(fFileName);
chudy@google.com902ebe52012-06-29 14:21:22 +0000595 }
596}
597
598void SkDebuggerGUI::openFile() {
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000599 QString temp = QFileDialog::getOpenFileName(this, tr("Open File"), "",
chudy@google.com7dcae672012-07-09 20:26:53 +0000600 tr("Files (*.*)"));
robertphillips@google.comff6e6ba2013-01-28 17:43:26 +0000601 openFile(temp);
602}
603
604void SkDebuggerGUI::openFile(const QString &filename) {
chudy@google.com902ebe52012-06-29 14:21:22 +0000605 fDirectoryWidgetActive = false;
robertphillips@google.comff6e6ba2013-01-28 17:43:26 +0000606 if (!filename.isEmpty()) {
607 QFileInfo pathInfo(filename);
608 loadPicture(SkString(filename.toAscii().data()));
609 setupDirectoryWidget(pathInfo.path());
chudy@google.com902ebe52012-06-29 14:21:22 +0000610 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000611 fDirectoryWidgetActive = true;
612}
613
chudy@google.comc432f002012-07-10 13:19:25 +0000614void SkDebuggerGUI::pauseDrawing(bool isPaused) {
chudy@google.com607357f2012-08-07 16:12:23 +0000615 fPause = isPaused;
616 fPausedRow = fListWidget.currentRow();
617 fCanvasWidget.drawTo(fPausedRow);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000618 fImageWidget.draw();
chudy@google.com7dcae672012-07-09 20:26:53 +0000619}
620
chudy@google.com902ebe52012-06-29 14:21:22 +0000621void SkDebuggerGUI::registerListClick(QListWidgetItem *item) {
chudy@google.comd3058f52012-07-19 13:41:27 +0000622 if(!fLoading) {
623 int currentRow = fListWidget.currentRow();
chudy@google.comd3058f52012-07-19 13:41:27 +0000624
chudy@google.comea5488b2012-07-26 19:38:22 +0000625 if (currentRow != -1) {
626 if (!fPause) {
627 fCanvasWidget.drawTo(currentRow);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000628 fImageWidget.draw();
chudy@google.comd3058f52012-07-19 13:41:27 +0000629 }
chudy@google.com97cee972012-08-07 20:41:37 +0000630 SkTDArray<SkString*> *currInfo = fDebugger.getCommandInfo(
chudy@google.comea5488b2012-07-26 19:38:22 +0000631 currentRow);
632
633 /* TODO(chudy): Add command type before parameters. Rename v
634 * to something more informative. */
chudy@google.com97cee972012-08-07 20:41:37 +0000635 if (currInfo) {
chudy@google.comea5488b2012-07-26 19:38:22 +0000636 QString info;
637 info.append("<b>Parameters: </b><br/>");
chudy@google.com97cee972012-08-07 20:41:37 +0000638 for (int i = 0; i < currInfo->count(); i++) {
639
640 info.append(QString((*currInfo)[i]->c_str()));
chudy@google.comea5488b2012-07-26 19:38:22 +0000641 info.append("<br/>");
642 }
chudy@google.com6bd109a2012-08-14 19:34:13 +0000643 fInspectorWidget.setText(info, SkInspectorWidget::kDetail_TabType);
chudy@google.comea5488b2012-07-26 19:38:22 +0000644 fInspectorWidget.setDisabled(false);
chudy@google.comea5488b2012-07-26 19:38:22 +0000645 }
chudy@google.comd3058f52012-07-19 13:41:27 +0000646 }
chudy@google.comea5488b2012-07-26 19:38:22 +0000647
chudy@google.com902ebe52012-06-29 14:21:22 +0000648 }
649}
650
chudy@google.com9ca9bfe2012-07-12 21:58:14 +0000651void SkDebuggerGUI::selectCommand(int command) {
652 if (fPause) {
653 fListWidget.setCurrentRow(command);
654 }
655}
656
chudy@google.com902ebe52012-06-29 14:21:22 +0000657void SkDebuggerGUI::toggleBreakpoint() {
chudy@google.comc432f002012-07-10 13:19:25 +0000658 QListWidgetItem* item = fListWidget.currentItem();
chudy@google.com902ebe52012-06-29 14:21:22 +0000659 if (item->checkState() == Qt::Unchecked) {
660 item->setCheckState(Qt::Checked);
chudy@google.come565de42012-07-12 14:15:54 +0000661 item->setData(Qt::DecorationRole,
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000662 QPixmap(":/breakpoint_16x16.png"));
chudy@google.com902ebe52012-06-29 14:21:22 +0000663 } else {
chudy@google.com902ebe52012-06-29 14:21:22 +0000664 item->setCheckState(Qt::Unchecked);
chudy@google.come565de42012-07-12 14:15:54 +0000665 item->setData(Qt::DecorationRole,
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000666 QPixmap(":/blank.png"));
chudy@google.com902ebe52012-06-29 14:21:22 +0000667 }
668}
669
670void SkDebuggerGUI::toggleDirectory() {
chudy@google.com607357f2012-08-07 16:12:23 +0000671 fDirectoryWidget.setHidden(!fDirectoryWidget.isHidden());
chudy@google.com902ebe52012-06-29 14:21:22 +0000672}
673
674void SkDebuggerGUI::toggleFilter(QString string) {
chudy@google.comc432f002012-07-10 13:19:25 +0000675 for (int row = 0; row < fListWidget.count(); row++) {
676 QListWidgetItem *item = fListWidget.item(row);
chudy@google.com607357f2012-08-07 16:12:23 +0000677 item->setHidden(item->text() != string);
chudy@google.com902ebe52012-06-29 14:21:22 +0000678 }
679}
680
681void SkDebuggerGUI::setupUi(QMainWindow *SkDebuggerGUI) {
682 QIcon windowIcon;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000683 windowIcon.addFile(QString::fromUtf8(":/skia.png"), QSize(),
chudy@google.com7dcae672012-07-09 20:26:53 +0000684 QIcon::Normal, QIcon::Off);
chudy@google.com902ebe52012-06-29 14:21:22 +0000685 SkDebuggerGUI->setObjectName(QString::fromUtf8("SkDebuggerGUI"));
686 SkDebuggerGUI->resize(1200, 1000);
687 SkDebuggerGUI->setWindowIcon(windowIcon);
chudy@google.comc432f002012-07-10 13:19:25 +0000688 SkDebuggerGUI->setWindowTitle("Skia Debugger");
chudy@google.com902ebe52012-06-29 14:21:22 +0000689
chudy@google.come504de02012-07-16 18:35:23 +0000690 fActionOpen.setShortcuts(QKeySequence::Open);
chudy@google.comc432f002012-07-10 13:19:25 +0000691 fActionOpen.setText("Open");
chudy@google.com902ebe52012-06-29 14:21:22 +0000692
693 QIcon breakpoint;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000694 breakpoint.addFile(QString::fromUtf8(":/breakpoint.png"),
chudy@google.com7dcae672012-07-09 20:26:53 +0000695 QSize(), QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000696 fActionBreakpoint.setShortcut(QKeySequence(tr("Ctrl+B")));
chudy@google.comc432f002012-07-10 13:19:25 +0000697 fActionBreakpoint.setIcon(breakpoint);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000698 fActionBreakpoint.setText("Breakpoints");
chudy@google.com902ebe52012-06-29 14:21:22 +0000699
700 QIcon cancel;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000701 cancel.addFile(QString::fromUtf8(":/reload.png"), QSize(),
chudy@google.com7dcae672012-07-09 20:26:53 +0000702 QIcon::Normal, QIcon::Off);
chudy@google.comc432f002012-07-10 13:19:25 +0000703 fActionCancel.setIcon(cancel);
704 fActionCancel.setText("Clear Filter");
chudy@google.com902ebe52012-06-29 14:21:22 +0000705
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000706 fActionClearBreakpoints.setShortcut(QKeySequence(tr("Alt+B")));
707 fActionClearBreakpoints.setText("Clear Breakpoints");
708
709 fActionClearDeletes.setShortcut(QKeySequence(tr("Alt+X")));
710 fActionClearDeletes.setText("Clear Deletes");
711
chudy@google.come504de02012-07-16 18:35:23 +0000712 fActionClose.setShortcuts(QKeySequence::Quit);
chudy@google.comc432f002012-07-10 13:19:25 +0000713 fActionClose.setText("Exit");
chudy@google.com902ebe52012-06-29 14:21:22 +0000714
chudy@google.come504de02012-07-16 18:35:23 +0000715 fActionCreateBreakpoint.setShortcut(QKeySequence(tr("B")));
716 fActionCreateBreakpoint.setText("Set Breakpoint");
717
718 fActionDelete.setShortcut(QKeySequence(tr("X")));
chudy@google.comc432f002012-07-10 13:19:25 +0000719 fActionDelete.setText("Delete Command");
chudy@google.com902ebe52012-06-29 14:21:22 +0000720
chudy@google.come504de02012-07-16 18:35:23 +0000721 fActionDirectory.setShortcut(QKeySequence(tr("Ctrl+D")));
722 fActionDirectory.setText("Directory");
chudy@google.com902ebe52012-06-29 14:21:22 +0000723
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000724 QIcon profile;
robertphillips@google.comd1636362012-11-19 18:25:09 +0000725 profile.addFile(QString::fromUtf8(":/profile.png"), QSize(),
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000726 QIcon::Normal, QIcon::Off);
727 fActionProfile.setIcon(profile);
728 fActionProfile.setText("Profile");
robertphillips@google.come099bc42012-11-19 16:26:40 +0000729 fActionProfile.setDisabled(true);
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000730
chudy@google.comc432f002012-07-10 13:19:25 +0000731 QIcon inspector;
robertphillips@google.comd1636362012-11-19 18:25:09 +0000732 inspector.addFile(QString::fromUtf8(":/inspector.png"),
chudy@google.comc432f002012-07-10 13:19:25 +0000733 QSize(), QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000734 fActionInspector.setShortcut(QKeySequence(tr("Ctrl+I")));
chudy@google.comc432f002012-07-10 13:19:25 +0000735 fActionInspector.setIcon(inspector);
chudy@google.come504de02012-07-16 18:35:23 +0000736 fActionInspector.setText("Inspector");
chudy@google.com902ebe52012-06-29 14:21:22 +0000737
chudy@google.comc432f002012-07-10 13:19:25 +0000738 QIcon play;
robertphillips@google.comd1636362012-11-19 18:25:09 +0000739 play.addFile(QString::fromUtf8(":/play.png"), QSize(),
chudy@google.comc432f002012-07-10 13:19:25 +0000740 QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000741 fActionPlay.setShortcut(QKeySequence(tr("Ctrl+P")));
chudy@google.comc432f002012-07-10 13:19:25 +0000742 fActionPlay.setIcon(play);
743 fActionPlay.setText("Play");
chudy@google.com902ebe52012-06-29 14:21:22 +0000744
chudy@google.come504de02012-07-16 18:35:23 +0000745 QIcon pause;
robertphillips@google.comd1636362012-11-19 18:25:09 +0000746 pause.addFile(QString::fromUtf8(":/pause.png"), QSize(),
chudy@google.comc432f002012-07-10 13:19:25 +0000747 QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000748 fActionPause.setShortcut(QKeySequence(tr("Space")));
749 fActionPause.setCheckable(true);
750 fActionPause.setIcon(pause);
751 fActionPause.setText("Pause");
752
chudy@google.comc432f002012-07-10 13:19:25 +0000753 QIcon rewind;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000754 rewind.addFile(QString::fromUtf8(":/rewind.png"), QSize(),
chudy@google.comc432f002012-07-10 13:19:25 +0000755 QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000756 fActionRewind.setShortcut(QKeySequence(tr("Ctrl+R")));
chudy@google.comc432f002012-07-10 13:19:25 +0000757 fActionRewind.setIcon(rewind);
758 fActionRewind.setText("Rewind");
chudy@google.com902ebe52012-06-29 14:21:22 +0000759
chudy@google.com0ab03392012-07-28 20:16:11 +0000760 fActionSave.setShortcut(QKeySequence::Save);
761 fActionSave.setText("Save");
762 fActionSave.setDisabled(true);
763 fActionSaveAs.setShortcut(QKeySequence::SaveAs);
764 fActionSaveAs.setText("Save As");
765 fActionSaveAs.setDisabled(true);
766
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000767 fActionShowDeletes.setShortcut(QKeySequence(tr("Ctrl+X")));
768 fActionShowDeletes.setText("Deleted Commands");
769
chudy@google.comc432f002012-07-10 13:19:25 +0000770 QIcon stepBack;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000771 stepBack.addFile(QString::fromUtf8(":/previous.png"), QSize(),
chudy@google.comc432f002012-07-10 13:19:25 +0000772 QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000773 fActionStepBack.setShortcut(QKeySequence(tr("[")));
chudy@google.comc432f002012-07-10 13:19:25 +0000774 fActionStepBack.setIcon(stepBack);
775 fActionStepBack.setText("Step Back");
chudy@google.com902ebe52012-06-29 14:21:22 +0000776
chudy@google.comc432f002012-07-10 13:19:25 +0000777 QIcon stepForward;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000778 stepForward.addFile(QString::fromUtf8(":/next.png"),
chudy@google.comc432f002012-07-10 13:19:25 +0000779 QSize(), QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000780 fActionStepForward.setShortcut(QKeySequence(tr("]")));
chudy@google.comc432f002012-07-10 13:19:25 +0000781 fActionStepForward.setIcon(stepForward);
782 fActionStepForward.setText("Step Forward");
783
chudy@google.coma1226312012-07-26 20:26:44 +0000784 fActionZoomIn.setShortcut(QKeySequence(tr("Ctrl+=")));
785 fActionZoomIn.setText("Zoom In");
786 fActionZoomOut.setShortcut(QKeySequence(tr("Ctrl+-")));
787 fActionZoomOut.setText("Zoom Out");
788
chudy@google.comc432f002012-07-10 13:19:25 +0000789 fListWidget.setItemDelegate(new SkListWidget(&fListWidget));
790 fListWidget.setObjectName(QString::fromUtf8("listWidget"));
791 fListWidget.setMaximumWidth(250);
792
793 fFilter.addItem("--Filter By Available Commands--");
794
795 fDirectoryWidget.setMaximumWidth(250);
796 fDirectoryWidget.setStyleSheet("QListWidget::Item {padding: 5px;}");
797
798 fCanvasWidget.setSizePolicy(QSizePolicy::Expanding,
chudy@google.com7dcae672012-07-09 20:26:53 +0000799 QSizePolicy::Expanding);
chudy@google.com902ebe52012-06-29 14:21:22 +0000800
skia.committer@gmail.com1c9c0d32012-11-22 02:02:41 +0000801 fImageWidget.setFixedSize(SkImageWidget::kImageWidgetWidth,
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000802 SkImageWidget::kImageWidgetHeight);
803
chudy@google.comc432f002012-07-10 13:19:25 +0000804 fInspectorWidget.setSizePolicy(QSizePolicy::Expanding,
chudy@google.com7dcae672012-07-09 20:26:53 +0000805 QSizePolicy::Expanding);
chudy@google.comc432f002012-07-10 13:19:25 +0000806 fInspectorWidget.setMaximumHeight(300);
chudy@google.com902ebe52012-06-29 14:21:22 +0000807
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000808 fSettingsAndImageLayout.setSpacing(6);
809 fSettingsAndImageLayout.addWidget(&fSettingsWidget);
810 fSettingsAndImageLayout.addWidget(&fImageWidget);
811
chudy@google.comc432f002012-07-10 13:19:25 +0000812 fSettingsWidget.setSizePolicy(QSizePolicy::Expanding,
813 QSizePolicy::Expanding);
814 fSettingsWidget.setMaximumWidth(250);
chudy@google.com902ebe52012-06-29 14:21:22 +0000815
chudy@google.comc432f002012-07-10 13:19:25 +0000816 fLeftColumnLayout.setSpacing(6);
817 fLeftColumnLayout.addWidget(&fListWidget);
818 fLeftColumnLayout.addWidget(&fDirectoryWidget);
chudy@google.com902ebe52012-06-29 14:21:22 +0000819
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000820 fCanvasSettingsAndImageLayout.setSpacing(6);
821 fCanvasSettingsAndImageLayout.addWidget(&fCanvasWidget);
822 fCanvasSettingsAndImageLayout.addLayout(&fSettingsAndImageLayout);
823
chudy@google.com902ebe52012-06-29 14:21:22 +0000824
chudy@google.comc432f002012-07-10 13:19:25 +0000825 fMainAndRightColumnLayout.setSpacing(6);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000826 fMainAndRightColumnLayout.addLayout(&fCanvasSettingsAndImageLayout);
chudy@google.comc432f002012-07-10 13:19:25 +0000827 fMainAndRightColumnLayout.addWidget(&fInspectorWidget);
chudy@google.com902ebe52012-06-29 14:21:22 +0000828
chudy@google.com2d537a12012-07-31 12:49:52 +0000829 fCentralWidget.setLayout(&fContainerLayout);
chudy@google.comc432f002012-07-10 13:19:25 +0000830 fContainerLayout.setSpacing(6);
831 fContainerLayout.setContentsMargins(11, 11, 11, 11);
832 fContainerLayout.addLayout(&fLeftColumnLayout);
833 fContainerLayout.addLayout(&fMainAndRightColumnLayout);
834
835 SkDebuggerGUI->setCentralWidget(&fCentralWidget);
836 SkDebuggerGUI->setStatusBar(&fStatusBar);
837
chudy@google.come504de02012-07-16 18:35:23 +0000838 fToolBar.setIconSize(QSize(32, 32));
chudy@google.comc432f002012-07-10 13:19:25 +0000839 fToolBar.setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
840 SkDebuggerGUI->addToolBar(Qt::TopToolBarArea, &fToolBar);
chudy@google.com902ebe52012-06-29 14:21:22 +0000841
chudy@google.com0ab03392012-07-28 20:16:11 +0000842 fSpacer.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
chudy@google.com902ebe52012-06-29 14:21:22 +0000843
chudy@google.comc432f002012-07-10 13:19:25 +0000844 fToolBar.addAction(&fActionRewind);
845 fToolBar.addAction(&fActionStepBack);
chudy@google.come504de02012-07-16 18:35:23 +0000846 fToolBar.addAction(&fActionPause);
chudy@google.comc432f002012-07-10 13:19:25 +0000847 fToolBar.addAction(&fActionStepForward);
848 fToolBar.addAction(&fActionPlay);
849 fToolBar.addSeparator();
chudy@google.come504de02012-07-16 18:35:23 +0000850 fToolBar.addAction(&fActionInspector);
chudy@google.comc432f002012-07-10 13:19:25 +0000851 fToolBar.addSeparator();
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000852 fToolBar.addAction(&fActionProfile);
853
854 fToolBar.addSeparator();
chudy@google.com0ab03392012-07-28 20:16:11 +0000855 fToolBar.addWidget(&fSpacer);
chudy@google.comc432f002012-07-10 13:19:25 +0000856 fToolBar.addWidget(&fFilter);
857 fToolBar.addAction(&fActionCancel);
chudy@google.com902ebe52012-06-29 14:21:22 +0000858
859 // TODO(chudy): Remove static call.
860 fDirectoryWidgetActive = false;
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000861 fFileName = "";
robertphillips@google.comff6e6ba2013-01-28 17:43:26 +0000862 setupDirectoryWidget("");
chudy@google.com902ebe52012-06-29 14:21:22 +0000863 fDirectoryWidgetActive = true;
864
chudy@google.com902ebe52012-06-29 14:21:22 +0000865 // Menu Bar
chudy@google.comc432f002012-07-10 13:19:25 +0000866 fMenuFile.setTitle("File");
867 fMenuFile.addAction(&fActionOpen);
chudy@google.com0ab03392012-07-28 20:16:11 +0000868 fMenuFile.addAction(&fActionSave);
869 fMenuFile.addAction(&fActionSaveAs);
chudy@google.comc432f002012-07-10 13:19:25 +0000870 fMenuFile.addAction(&fActionClose);
chudy@google.come504de02012-07-16 18:35:23 +0000871
872 fMenuEdit.setTitle("Edit");
873 fMenuEdit.addAction(&fActionDelete);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000874 fMenuEdit.addAction(&fActionClearDeletes);
875 fMenuEdit.addSeparator();
chudy@google.come504de02012-07-16 18:35:23 +0000876 fMenuEdit.addAction(&fActionCreateBreakpoint);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000877 fMenuEdit.addAction(&fActionClearBreakpoints);
chudy@google.come504de02012-07-16 18:35:23 +0000878
chudy@google.comc432f002012-07-10 13:19:25 +0000879 fMenuNavigate.setTitle("Navigate");
chudy@google.come504de02012-07-16 18:35:23 +0000880 fMenuNavigate.addAction(&fActionRewind);
881 fMenuNavigate.addAction(&fActionStepBack);
882 fMenuNavigate.addAction(&fActionStepForward);
883 fMenuNavigate.addAction(&fActionPlay);
884 fMenuNavigate.addAction(&fActionPause);
chudy@google.comc432f002012-07-10 13:19:25 +0000885 fMenuNavigate.addAction(&fActionGoToLine);
chudy@google.come504de02012-07-16 18:35:23 +0000886
chudy@google.comc432f002012-07-10 13:19:25 +0000887 fMenuView.setTitle("View");
chudy@google.come504de02012-07-16 18:35:23 +0000888 fMenuView.addAction(&fActionBreakpoint);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000889 fMenuView.addAction(&fActionShowDeletes);
chudy@google.coma1226312012-07-26 20:26:44 +0000890 fMenuView.addAction(&fActionZoomIn);
891 fMenuView.addAction(&fActionZoomOut);
chudy@google.come504de02012-07-16 18:35:23 +0000892
893 fMenuWindows.setTitle("Window");
894 fMenuWindows.addAction(&fActionInspector);
895 fMenuWindows.addAction(&fActionDirectory);
chudy@google.comc432f002012-07-10 13:19:25 +0000896
897 fActionGoToLine.setText("Go to Line...");
898 fActionGoToLine.setDisabled(true);
899 fMenuBar.addAction(fMenuFile.menuAction());
chudy@google.come504de02012-07-16 18:35:23 +0000900 fMenuBar.addAction(fMenuEdit.menuAction());
chudy@google.comc432f002012-07-10 13:19:25 +0000901 fMenuBar.addAction(fMenuView.menuAction());
902 fMenuBar.addAction(fMenuNavigate.menuAction());
chudy@google.come504de02012-07-16 18:35:23 +0000903 fMenuBar.addAction(fMenuWindows.menuAction());
chudy@google.com902ebe52012-06-29 14:21:22 +0000904
chudy@google.com7dcae672012-07-09 20:26:53 +0000905 fPause = false;
906
chudy@google.comc432f002012-07-10 13:19:25 +0000907 SkDebuggerGUI->setMenuBar(&fMenuBar);
chudy@google.com902ebe52012-06-29 14:21:22 +0000908 QMetaObject::connectSlotsByName(SkDebuggerGUI);
909}
910
robertphillips@google.comff6e6ba2013-01-28 17:43:26 +0000911void SkDebuggerGUI::setupDirectoryWidget(const QString& path) {
912 fPath = path;
913 QDir dir(path);
chudy@google.com902ebe52012-06-29 14:21:22 +0000914 QRegExp r(".skp");
chudy@google.comc432f002012-07-10 13:19:25 +0000915 fDirectoryWidget.clear();
916 const QStringList files = dir.entryList();
chudy@google.com902ebe52012-06-29 14:21:22 +0000917 foreach (QString f, files) {
chudy@google.com7dcae672012-07-09 20:26:53 +0000918 if (f.contains(r))
chudy@google.comc432f002012-07-10 13:19:25 +0000919 fDirectoryWidget.addItem(f);
chudy@google.com902ebe52012-06-29 14:21:22 +0000920 }
921}
922
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000923// SkOffsetPicturePlayback records the offset of each command in the picture.
924// These are needed by the profiling system.
925class SkOffsetPicturePlayback : public SkPicturePlayback {
926public:
927 SkOffsetPicturePlayback(SkStream* stream, const SkPictInfo& info, bool* isValid,
scroggo@google.comf8d7d272013-02-22 21:38:35 +0000928 SkPicture::InstallPixelRefProc proc)
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000929 : INHERITED(stream, info, isValid, decoder) {
930 }
931
932 const SkTDArray<size_t>& offsets() const { return fOffsets; }
933
934protected:
935 SkTDArray<size_t> fOffsets;
936
robertphillips@google.comca47aae2012-12-12 15:58:25 +0000937 virtual size_t preDraw(size_t offset, int type) {
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000938 *fOffsets.append() = offset;
robertphillips@google.com5f971142012-12-07 20:48:56 +0000939 return 0;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000940 }
941
942private:
943 typedef SkPicturePlayback INHERITED;
944};
945
946// Picture to wrap an SkOffsetPicturePlayback.
947class SkOffsetPicture : public SkPicture {
948public:
scroggo@google.comf8d7d272013-02-22 21:38:35 +0000949 SkOffsetPicture(SkStream* stream, bool* success, SkPicture::InstallPixelRefProc proc) {
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000950 if (success) {
951 *success = false;
952 }
953 fRecord = NULL;
954 fPlayback = NULL;
955 fWidth = fHeight = 0;
956
957 SkPictInfo info;
958
959 if (!stream->read(&info, sizeof(info))) {
960 return;
961 }
962 if (PICTURE_VERSION != info.fVersion) {
963 return;
964 }
965
966 if (stream->readBool()) {
967 bool isValid = false;
968 fPlayback = SkNEW_ARGS(SkOffsetPicturePlayback, (stream, info, &isValid, decoder));
969 if (!isValid) {
970 SkDELETE(fPlayback);
971 fPlayback = NULL;
972 return;
973 }
974 }
975
976 // do this at the end, so that they will be zero if we hit an error.
977 fWidth = info.fWidth;
978 fHeight = info.fHeight;
979 if (success) {
980 *success = true;
981 }
982 }
983
skia.committer@gmail.com884e60b2012-11-16 02:01:17 +0000984 const SkTDArray<size_t>& offsets() const {
985 return ((SkOffsetPicturePlayback*) fPlayback)->offsets();
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000986 }
987
988private:
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000989 // disallow default ctor b.c. we don't have a good way to setup the fPlayback ptr
990 SkOffsetPicture();
991 // disallow the copy ctor - enabling would require copying code from SkPicture
992 SkOffsetPicture(const SkOffsetPicture& src);
993
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000994 typedef SkPicture INHERITED;
995};
996
997
998
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000999void SkDebuggerGUI::loadPicture(const SkString& fileName) {
1000 fFileName = fileName;
chudy@google.comd3058f52012-07-19 13:41:27 +00001001 fLoading = true;
robertphillips@google.comd26c7062012-11-12 20:42:12 +00001002 SkStream* stream = SkNEW_ARGS(SkFILEStream, (fileName.c_str()));
robertphillips@google.com2d40ec42013-02-07 20:39:40 +00001003
1004 bool success = false;
1005
scroggo@google.comf8d7d272013-02-22 21:38:35 +00001006 SkOffsetPicture* picture = SkNEW_ARGS(SkOffsetPicture,
1007 (stream, &success, &SkImageDecoder::DecodeMemory));
robertphillips@google.com2d40ec42013-02-07 20:39:40 +00001008
1009 if (!success) {
1010 QMessageBox::critical(this, "Error loading file", "Couldn't read file, sorry.");
1011 SkSafeUnref(stream);
1012 return;
1013 }
robertphillips@google.com2bde91d2012-11-15 14:57:57 +00001014
chudy@google.com686e6802012-08-14 16:00:32 +00001015 fCanvasWidget.resetWidgetTransform();
chudy@google.com607357f2012-08-07 16:12:23 +00001016 fDebugger.loadPicture(picture);
chudy@google.com4c7962e2012-08-14 19:38:31 +00001017
robertphillips@google.com2bde91d2012-11-15 14:57:57 +00001018 fOffsets = picture->offsets();
1019
robertphillips@google.com5f971142012-12-07 20:48:56 +00001020 fSkipCommands.setCount(fOffsets.count());
1021 for (int i = 0; i < fOffsets.count(); ++i) {
1022 fSkipCommands[i] = false;
1023 }
1024
chudy@google.com607357f2012-08-07 16:12:23 +00001025 SkSafeUnref(stream);
1026 SkSafeUnref(picture);
1027
chudy@google.com97cee972012-08-07 20:41:37 +00001028 // Will this automatically clear out due to nature of refcnt?
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +00001029 SkTArray<SkString>* commands = fDebugger.getDrawCommandsAsStrings();
chudy@google.com607357f2012-08-07 16:12:23 +00001030
robertphillips@google.comfe830a42012-11-15 16:33:31 +00001031 // If SkPicturePlayback is compiled w/o SK_PICTURE_PROFILING_STUBS
1032 // the offset count will always be zero
1033 SkASSERT(0 == fOffsets.count() || commands->count() == fOffsets.count());
robertphillips@google.come099bc42012-11-19 16:26:40 +00001034 if (commands->count() == fOffsets.count()) {
1035 fActionProfile.setDisabled(false);
robertphillips@google.comfe830a42012-11-15 16:33:31 +00001036 }
robertphillips@google.com2bde91d2012-11-15 14:57:57 +00001037
chudy@google.com7dcae672012-07-09 20:26:53 +00001038 /* fDebugCanvas is reinitialized every load picture. Need it to retain value
chudy@google.com607357f2012-08-07 16:12:23 +00001039 * of the visibility filter.
1040 * TODO(chudy): This should be deprecated since fDebugger is not
1041 * recreated.
1042 * */
1043 fDebugger.highlightCurrentCommand(fSettingsWidget.getVisibilityButton()->isChecked());
1044
chudy@google.com97cee972012-08-07 20:41:37 +00001045 setupListWidget(commands);
1046 setupComboBox(commands);
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +00001047 setupOverviewText(NULL, 0.0);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +00001048 fInspectorWidget.setDisabled(false);
chudy@google.come606d6e2012-07-12 14:31:25 +00001049 fSettingsWidget.setDisabled(false);
chudy@google.comd3058f52012-07-19 13:41:27 +00001050 fMenuEdit.setDisabled(false);
1051 fMenuNavigate.setDisabled(false);
1052 fMenuView.setDisabled(false);
chudy@google.com0ab03392012-07-28 20:16:11 +00001053 fActionSave.setDisabled(false);
1054 fActionSaveAs.setDisabled(false);
chudy@google.comd3058f52012-07-19 13:41:27 +00001055 fLoading = false;
1056 actionPlay();
chudy@google.com902ebe52012-06-29 14:21:22 +00001057}
1058
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +00001059void SkDebuggerGUI::setupListWidget(SkTArray<SkString>* command) {
chudy@google.comc432f002012-07-10 13:19:25 +00001060 fListWidget.clear();
chudy@google.com902ebe52012-06-29 14:21:22 +00001061 int counter = 0;
robertphillips@google.com30d35f22012-11-06 16:45:36 +00001062 int indent = 0;
chudy@google.com97cee972012-08-07 20:41:37 +00001063 for (int i = 0; i < command->count(); i++) {
chudy@google.com902ebe52012-06-29 14:21:22 +00001064 QListWidgetItem *item = new QListWidgetItem();
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +00001065 item->setData(Qt::DisplayRole, (*command)[i].c_str());
chudy@google.com902ebe52012-06-29 14:21:22 +00001066 item->setData(Qt::UserRole + 1, counter++);
robertphillips@google.com30d35f22012-11-06 16:45:36 +00001067
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +00001068 if (0 == strcmp("Restore", (*command)[i].c_str())) {
robertphillips@google.com30d35f22012-11-06 16:45:36 +00001069 indent -= 10;
1070 }
1071
1072 item->setData(Qt::UserRole + 3, indent);
1073
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +00001074 if (0 == strcmp("Save", (*command)[i].c_str()) ||
1075 0 == strcmp("Save Layer", (*command)[i].c_str())) {
robertphillips@google.com30d35f22012-11-06 16:45:36 +00001076 indent += 10;
1077 }
1078
robertphillips@google.comd26c7062012-11-12 20:42:12 +00001079 item->setData(Qt::UserRole + 4, -1.0);
1080
chudy@google.comc432f002012-07-10 13:19:25 +00001081 fListWidget.addItem(item);
chudy@google.com902ebe52012-06-29 14:21:22 +00001082 }
1083}
1084
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +00001085void SkDebuggerGUI::setupOverviewText(const SkTDArray<double>* typeTimes, double totTime) {
chudy@google.com902ebe52012-06-29 14:21:22 +00001086
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +00001087 const SkTDArray<SkDrawCommand*>& commands = fDebugger.getDrawCommands();
1088
1089 SkTDArray<int> counts;
1090 counts.setCount(LAST_DRAWTYPE_ENUM+1);
1091 for (int i = 0; i < LAST_DRAWTYPE_ENUM+1; ++i) {
1092 counts[i] = 0;
1093 }
1094
1095 for (int i = 0; i < commands.count(); i++) {
1096 counts[commands[i]->getType()]++;
chudy@google.com902ebe52012-06-29 14:21:22 +00001097 }
1098
1099 QString overview;
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +00001100 int total = 0;
1101#ifdef SK_DEBUG
1102 double totPercent = 0, tempSum = 0;
1103#endif
1104 for (int i = 0; i < LAST_DRAWTYPE_ENUM+1; ++i) {
1105 if (0 == counts[i]) {
1106 // if there were no commands of this type then they should've consumed no time
1107 SkASSERT(NULL == typeTimes || 0.0 == (*typeTimes)[i]);
1108 continue;
1109 }
1110
1111 overview.append(SkDrawCommand::GetCommandString((DrawType) i));
chudy@google.com902ebe52012-06-29 14:21:22 +00001112 overview.append(": ");
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +00001113 overview.append(QString::number(counts[i]));
1114 if (NULL != typeTimes) {
1115 overview.append(" - ");
1116 overview.append(QString::number((*typeTimes)[i], 'f', 1));
1117 overview.append("ms");
1118 overview.append(" - ");
1119 double percent = 100.0*(*typeTimes)[i]/totTime;
1120 overview.append(QString::number(percent, 'f', 1));
1121 overview.append("%");
1122#ifdef SK_DEBUG
1123 totPercent += percent;
1124 tempSum += (*typeTimes)[i];
1125#endif
1126 }
chudy@google.com902ebe52012-06-29 14:21:22 +00001127 overview.append("<br/>");
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +00001128 total += counts[i];
chudy@google.com902ebe52012-06-29 14:21:22 +00001129 }
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +00001130#ifdef SK_DEBUG
1131 if (NULL != typeTimes) {
1132 SkASSERT(SkScalarNearlyEqual(totPercent, 100.0));
1133 SkASSERT(SkScalarNearlyEqual(tempSum, totTime));
1134 }
1135#endif
1136
1137 if (totTime > 0.0) {
1138 overview.append("Total Time: ");
1139 overview.append(QString::number(totTime, 'f', 2));
1140 overview.append("ms");
1141#ifdef SK_DEBUG
1142 overview.append(" ");
1143 overview.append(QString::number(totPercent));
1144 overview.append("% ");
1145#endif
1146 overview.append("<br/>");
1147 }
1148
1149 QString totalStr;
1150 totalStr.append("Total Draw Commands: ");
1151 totalStr.append(QString::number(total));
1152 totalStr.append("<br/>");
1153 overview.insert(0, totalStr);
chudy@google.com902ebe52012-06-29 14:21:22 +00001154
1155 overview.append("<br/>");
chudy@google.com607357f2012-08-07 16:12:23 +00001156 overview.append("SkPicture Width: ");
chudy@google.com902ebe52012-06-29 14:21:22 +00001157 // NOTE(chudy): This is where we can pull out the SkPictures width.
chudy@google.com607357f2012-08-07 16:12:23 +00001158 overview.append(QString::number(fDebugger.pictureWidth()));
chudy@google.com902ebe52012-06-29 14:21:22 +00001159 overview.append("px<br/>");
chudy@google.com607357f2012-08-07 16:12:23 +00001160 overview.append("SkPicture Height: ");
1161 overview.append(QString::number(fDebugger.pictureHeight()));
chudy@google.com902ebe52012-06-29 14:21:22 +00001162 overview.append("px");
chudy@google.com6bd109a2012-08-14 19:34:13 +00001163 fInspectorWidget.setText(overview, SkInspectorWidget::kOverview_TabType);
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +00001164}
1165
1166void SkDebuggerGUI::setupComboBox(SkTArray<SkString>* command) {
1167 fFilter.clear();
1168 fFilter.addItem("--Filter By Available Commands--");
1169
1170 std::map<std::string, int> map;
1171 for (int i = 0; i < command->count(); i++) {
1172 map[(*command)[i].c_str()]++;
1173 }
1174
skia.committer@gmail.com34587162012-11-20 02:01:23 +00001175 for (std::map<std::string, int>::iterator it = map.begin(); it != map.end();
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +00001176 ++it) {
1177 fFilter.addItem((it->first).c_str());
1178 }
chudy@google.com902ebe52012-06-29 14:21:22 +00001179
1180 // NOTE(chudy): Makes first item unselectable.
chudy@google.com7dcae672012-07-09 20:26:53 +00001181 QStandardItemModel* model = qobject_cast<QStandardItemModel*>(
chudy@google.comc432f002012-07-10 13:19:25 +00001182 fFilter.model());
1183 QModelIndex firstIndex = model->index(0, fFilter.modelColumn(),
1184 fFilter.rootModelIndex());
chudy@google.com902ebe52012-06-29 14:21:22 +00001185 QStandardItem* firstItem = model->itemFromIndex(firstIndex);
1186 firstItem->setSelectable(false);
1187}