blob: 812ce0300e32d9163c075348570cae4e29d3cd8e [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);
chudy@google.comea5488b2012-07-26 19:38:22 +000069 connect(&fListWidget, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)), this, SLOT(registerListClick(QListWidgetItem *)));
chudy@google.comc432f002012-07-10 13:19:25 +000070 connect(&fActionOpen, SIGNAL(triggered()), this, SLOT(openFile()));
chudy@google.comea5488b2012-07-26 19:38:22 +000071 connect(&fActionDirectory, SIGNAL(triggered()), this, SLOT(toggleDirectory()));
72 connect(&fDirectoryWidget, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)), this, SLOT(loadFile(QListWidgetItem *)));
chudy@google.comc432f002012-07-10 13:19:25 +000073 connect(&fActionDelete, SIGNAL(triggered()), this, SLOT(actionDelete()));
chudy@google.comea5488b2012-07-26 19:38:22 +000074 connect(&fListWidget, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(toggleBreakpoint()));
chudy@google.comc432f002012-07-10 13:19:25 +000075 connect(&fActionRewind, SIGNAL(triggered()), this, SLOT(actionRewind()));
76 connect(&fActionPlay, SIGNAL(triggered()), this, SLOT(actionPlay()));
77 connect(&fActionStepBack, SIGNAL(triggered()), this, SLOT(actionStepBack()));
chudy@google.comea5488b2012-07-26 19:38:22 +000078 connect(&fActionStepForward, SIGNAL(triggered()), this, SLOT(actionStepForward()));
79 connect(&fActionBreakpoint, SIGNAL(triggered()), this, SLOT(actionBreakpoints()));
80 connect(&fActionInspector, SIGNAL(triggered()), this, SLOT(actionInspector()));
81 connect(&fActionInspector, SIGNAL(triggered()), this, SLOT(actionSettings()));
82 connect(&fFilter, SIGNAL(activated(QString)), this, SLOT(toggleFilter(QString)));
robertphillips@google.comd26c7062012-11-12 20:42:12 +000083 connect(&fActionProfile, SIGNAL(triggered()), this, SLOT(actionProfile()));
chudy@google.comc432f002012-07-10 13:19:25 +000084 connect(&fActionCancel, SIGNAL(triggered()), this, SLOT(actionCancel()));
chudy@google.com7e4cfbf2012-07-17 15:40:51 +000085 connect(&fActionClearBreakpoints, SIGNAL(triggered()), this, SLOT(actionClearBreakpoints()));
86 connect(&fActionClearDeletes, SIGNAL(triggered()), this, SLOT(actionClearDeletes()));
chudy@google.comc432f002012-07-10 13:19:25 +000087 connect(&fActionClose, SIGNAL(triggered()), this, SLOT(actionClose()));
chudy@google.comea5488b2012-07-26 19:38:22 +000088 connect(fSettingsWidget.getVisibilityButton(), SIGNAL(toggled(bool)), this, SLOT(actionCommandFilter()));
89 connect(fSettingsWidget.getGLCheckBox(), SIGNAL(toggled(bool)), this, SLOT(actionGLWidget(bool)));
90 connect(fSettingsWidget.getRasterCheckBox(), SIGNAL(toggled(bool)), this, SLOT(actionRasterWidget(bool)));
91 connect(&fActionPause, SIGNAL(toggled(bool)), this, SLOT(pauseDrawing(bool)));
chudy@google.come504de02012-07-16 18:35:23 +000092 connect(&fActionCreateBreakpoint, SIGNAL(activated()), this, SLOT(toggleBreakpoint()));
chudy@google.com7e4cfbf2012-07-17 15:40:51 +000093 connect(&fActionShowDeletes, SIGNAL(triggered()), this, SLOT(showDeletes()));
chudy@google.comea5488b2012-07-26 19:38:22 +000094 connect(&fCanvasWidget, SIGNAL(hitChanged(int)), this, SLOT(selectCommand(int)));
95 connect(&fCanvasWidget, SIGNAL(hitChanged(int)), &fSettingsWidget, SLOT(updateHit(int)));
96 connect(&fCanvasWidget, SIGNAL(scaleFactorChanged(float)), this, SLOT(actionScale(float)));
97 connect(&fCanvasWidget, SIGNAL(commandChanged(int)), &fSettingsWidget, SLOT(updateCommand(int)));
chudy@google.com0ab03392012-07-28 20:16:11 +000098 connect(&fActionSaveAs, SIGNAL(triggered()), this, SLOT(actionSaveAs()));
99 connect(&fActionSave, SIGNAL(triggered()), this, SLOT(actionSave()));
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000100
bungeman@google.come8cc6e82013-01-17 16:30:56 +0000101 fMapper.setMapping(&fActionZoomIn, SkCanvasWidget::kIn_ZoomCommand);
102 fMapper.setMapping(&fActionZoomOut, SkCanvasWidget::kOut_ZoomCommand);
chudy@google.coma1226312012-07-26 20:26:44 +0000103
104 connect(&fActionZoomIn, SIGNAL(triggered()), &fMapper, SLOT(map()));
105 connect(&fActionZoomOut, SIGNAL(triggered()), &fMapper, SLOT(map()));
bungeman@google.come8cc6e82013-01-17 16:30:56 +0000106 connect(&fMapper, SIGNAL(mapped(int)), &fCanvasWidget, SLOT(zoom(int)));
chudy@google.coma1226312012-07-26 20:26:44 +0000107
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000108 fInspectorWidget.setDisabled(true);
chudy@google.comd3058f52012-07-19 13:41:27 +0000109 fMenuEdit.setDisabled(true);
110 fMenuNavigate.setDisabled(true);
111 fMenuView.setDisabled(true);
chudy@google.combbad34d2012-08-13 14:26:36 +0000112
113 SkGraphics::Init();
chudy@google.com902ebe52012-06-29 14:21:22 +0000114}
115
chudy@google.combbad34d2012-08-13 14:26:36 +0000116SkDebuggerGUI::~SkDebuggerGUI() {
117 SkGraphics::Term();
118}
chudy@google.com902ebe52012-06-29 14:21:22 +0000119
120void SkDebuggerGUI::actionBreakpoints() {
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000121 fBreakpointsActivated = !fBreakpointsActivated;
chudy@google.comc432f002012-07-10 13:19:25 +0000122 for (int row = 0; row < fListWidget.count(); row++) {
123 QListWidgetItem *item = fListWidget.item(row);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000124 item->setHidden(item->checkState() == Qt::Unchecked && fBreakpointsActivated);
125 }
126}
chudy@google.com902ebe52012-06-29 14:21:22 +0000127
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000128void SkDebuggerGUI::showDeletes() {
129 fDeletesActivated = !fDeletesActivated;
130 for (int row = 0; row < fListWidget.count(); row++) {
131 QListWidgetItem *item = fListWidget.item(row);
chudy@google.com607357f2012-08-07 16:12:23 +0000132 item->setHidden(fDebugger.isCommandVisible(row)
133 && fDeletesActivated);
chudy@google.com902ebe52012-06-29 14:21:22 +0000134 }
135}
136
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000137// The timed picture playback uses the SkPicturePlayback's profiling stubs
138// to time individual commands. The offsets are needed to map SkPicture
139// offsets to individual commands.
140class SkTimedPicturePlayback : public SkPicturePlayback {
141public:
142 SkTimedPicturePlayback(SkStream* stream, const SkPictInfo& info, bool* isValid,
143 SkSerializationHelpers::DecodeBitmap decoder,
robertphillips@google.com5f971142012-12-07 20:48:56 +0000144 const SkTDArray<size_t>& offsets,
145 const SkTDArray<bool>& deletedCommands)
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000146 : INHERITED(stream, info, isValid, decoder)
robertphillips@google.com5f971142012-12-07 20:48:56 +0000147 , fOffsets(offsets)
bungeman@google.come8cc6e82013-01-17 16:30:56 +0000148 , fSkipCommands(deletedCommands)
149 , fTot(0.0)
150 , fCurCommand(0) {
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000151 fTimes.setCount(fOffsets.count());
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000152 fTypeTimes.setCount(LAST_DRAWTYPE_ENUM+1);
153 this->resetTimes();
154 }
155
156 void resetTimes() {
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000157 for (int i = 0; i < fOffsets.count(); ++i) {
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000158 fTimes[i] = 0.0;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000159 }
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000160 for (int i = 0; i < fTypeTimes.count(); ++i) {
161 fTypeTimes[i] = 0.0f;
162 }
163 fTot = 0.0;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000164 }
165
166 int count() const { return fTimes.count(); }
167
168 double time(int index) const { return fTimes[index] / fTot; }
169
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000170 const SkTDArray<double>* typeTimes() const { return &fTypeTimes; }
171
172 double totTime() const { return fTot; }
173
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000174protected:
robertphillips@google.come174a8b2012-11-27 16:04:42 +0000175 BenchSysTimer fTimer;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000176 SkTDArray<size_t> fOffsets; // offset in the SkPicture for each command
robertphillips@google.com5f971142012-12-07 20:48:56 +0000177 SkTDArray<bool> fSkipCommands; // has the command been deleted in the GUI?
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000178 SkTDArray<double> fTimes; // sum of time consumed for each command
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000179 SkTDArray<double> fTypeTimes; // sum of time consumed for each type of command (e.g., drawPath)
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000180 double fTot; // total of all times in 'fTimes'
181 size_t fCurOffset;
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000182 int fCurType;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000183 int fCurCommand; // the current command being executed/timed
184
robertphillips@google.comca47aae2012-12-12 15:58:25 +0000185 virtual size_t preDraw(size_t offset, int type) {
skia.committer@gmail.com884e60b2012-11-16 02:01:17 +0000186 // This search isn't as bad as it seems. In normal playback mode, the
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000187 // base class steps through the commands in order and can only skip ahead
skia.committer@gmail.com884e60b2012-11-16 02:01:17 +0000188 // a bit on a clip. This class is only used during profiling so we
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000189 // don't have to worry about forward/backward scrubbing through commands.
190 for (int i = 0; offset != fOffsets[fCurCommand]; ++i) {
191 fCurCommand = (fCurCommand+1) % fOffsets.count();
192 SkASSERT(i <= fOffsets.count()); // should always find the offset in the list
193 }
194
robertphillips@google.com5f971142012-12-07 20:48:56 +0000195 if (fSkipCommands[fCurCommand]) {
196 while (fCurCommand < fSkipCommands.count() && fSkipCommands[fCurCommand]) {
197 ++fCurCommand;
198 }
199 if (fCurCommand == fSkipCommands.count()) {
200 // Signal SkPicturePlayback to stop playing back
201 return SK_MaxU32;
202 }
203 return fOffsets[fCurCommand];
204 }
205
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000206 fCurOffset = offset;
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000207 fCurType = type;
208 // The SkDebugCanvas doesn't recognize these types. This class needs to
209 // convert or else we'll wind up with a mismatch between the type counts
210 // the debugger displays and the profile times.
211 if (DRAW_POS_TEXT_TOP_BOTTOM == type) {
212 fCurType = DRAW_POS_TEXT;
213 } else if (DRAW_POS_TEXT_H_TOP_BOTTOM == type) {
214 fCurType = DRAW_POS_TEXT_H;
215 }
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000216
robertphillips@google.come174a8b2012-11-27 16:04:42 +0000217#if defined(SK_BUILD_FOR_WIN32)
218 // CPU timer doesn't work well on Windows
219 fTimer.startWall();
220#else
221 fTimer.startCpu();
222#endif
robertphillips@google.com5f971142012-12-07 20:48:56 +0000223
224 return 0;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000225 }
226
robertphillips@google.comca47aae2012-12-12 15:58:25 +0000227 virtual void postDraw(size_t offset) {
robertphillips@google.come174a8b2012-11-27 16:04:42 +0000228#if defined(SK_BUILD_FOR_WIN32)
229 // CPU timer doesn't work well on Windows
230 double time = fTimer.endWall();
231#else
232 double time = fTimer.endCpu();
233#endif
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000234
235 SkASSERT(offset == fCurOffset);
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000236 SkASSERT(fCurType <= LAST_DRAWTYPE_ENUM);
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000237
robertphillips@google.come174a8b2012-11-27 16:04:42 +0000238 fTimes[fCurCommand] += time;
239 fTypeTimes[fCurType] += time;
240 fTot += time;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000241 }
242
243private:
244 typedef SkPicturePlayback INHERITED;
245};
246
247// Wrap SkPicture to allow installation of an SkTimedPicturePlayback object
248class SkTimedPicture : public SkPicture {
249public:
250 explicit SkTimedPicture(SkStream* stream,
251 bool* success,
252 SkSerializationHelpers::DecodeBitmap decoder,
robertphillips@google.com5f971142012-12-07 20:48:56 +0000253 const SkTDArray<size_t>& offsets,
254 const SkTDArray<bool>& deletedCommands) {
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000255 if (success) {
256 *success = false;
257 }
258 fRecord = NULL;
259 fPlayback = NULL;
260 fWidth = fHeight = 0;
261
262 SkPictInfo info;
263
264 if (!stream->read(&info, sizeof(info))) {
265 return;
266 }
267 if (SkPicture::PICTURE_VERSION != info.fVersion) {
268 return;
269 }
270
271 if (stream->readBool()) {
272 bool isValid = false;
skia.committer@gmail.com884e60b2012-11-16 02:01:17 +0000273 fPlayback = SkNEW_ARGS(SkTimedPicturePlayback,
robertphillips@google.com5f971142012-12-07 20:48:56 +0000274 (stream, info, &isValid, decoder, offsets, deletedCommands));
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000275 if (!isValid) {
276 SkDELETE(fPlayback);
277 fPlayback = NULL;
278 return;
279 }
280 }
281
282 // do this at the end, so that they will be zero if we hit an error.
283 fWidth = info.fWidth;
284 fHeight = info.fHeight;
285 if (success) {
286 *success = true;
287 }
288 }
289
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000290 void resetTimes() { ((SkTimedPicturePlayback*) fPlayback)->resetTimes(); }
291
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000292 int count() const { return ((SkTimedPicturePlayback*) fPlayback)->count(); }
293
294 // return the fraction of the total time this command consumed
295 double time(int index) const { return ((SkTimedPicturePlayback*) fPlayback)->time(index); }
296
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000297 const SkTDArray<double>* typeTimes() const { return ((SkTimedPicturePlayback*) fPlayback)->typeTimes(); }
298
299 double totTime() const { return ((SkTimedPicturePlayback*) fPlayback)->totTime(); }
300
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000301private:
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000302 // disallow default ctor b.c. we don't have a good way to setup the fPlayback ptr
303 SkTimedPicture();
304 // disallow the copy ctor - enabling would require copying code from SkPicture
305 SkTimedPicture(const SkTimedPicture& src);
306
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000307 typedef SkPicture INHERITED;
308};
309
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000310// This is a simplification of PictureBenchmark's run with the addition of
311// clearing of the times after the first pass (in resetTimes)
skia.committer@gmail.com34587162012-11-20 02:01:23 +0000312void SkDebuggerGUI::run(SkTimedPicture* pict,
313 sk_tools::PictureRenderer* renderer,
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000314 int repeats) {
315 SkASSERT(pict);
316 if (NULL == pict) {
317 return;
318 }
319
320 SkASSERT(renderer != NULL);
321 if (NULL == renderer) {
322 return;
323 }
324
325 renderer->init(pict);
326
327 renderer->setup();
328 renderer->render(NULL);
329 renderer->resetState();
330
331 // We throw this away the first batch of times to remove first time effects (such as paging in this program)
332 pict->resetTimes();
333
334 for (int i = 0; i < repeats; ++i) {
335 renderer->setup();
336 renderer->render(NULL);
337 renderer->resetState();
338 }
339
340 renderer->end();
341}
342
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000343void SkDebuggerGUI::actionProfile() {
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000344 // In order to profile we pass the command offsets (that were read-in
345 // in loadPicture by the SkOffsetPicture) to an SkTimedPlaybackPicture.
skia.committer@gmail.com884e60b2012-11-16 02:01:17 +0000346 // The SkTimedPlaybackPicture in turn passes the offsets to an
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000347 // SkTimedPicturePlayback object which uses them to track the performance
348 // of individual commands.
349 if (fFileName.isEmpty()) {
350 return;
351 }
352
353 SkFILEStream inputStream;
354
355 inputStream.setPath(fFileName.c_str());
356 if (!inputStream.isValid()) {
357 return;
358 }
359
360 bool success = false;
skia.committer@gmail.comc1f224a2012-12-08 02:01:38 +0000361 SkTimedPicture picture(&inputStream, &success, &SkImageDecoder::DecodeStream,
robertphillips@google.com5f971142012-12-07 20:48:56 +0000362 fOffsets, fSkipCommands);
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000363 if (!success) {
364 return;
365 }
366
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000367 // For now this #if allows switching between tiled and simple rendering
368 // modes. Eventually this will be accomplished via the GUI
robertphillips@google.come174a8b2012-11-27 16:04:42 +0000369#if 0
370 // With the current batch of SysTimers, profiling in tiled mode
371 // gets swamped by the timing overhead:
372 //
373 // tile mode simple mode
374 // debugger 64.2ms 12.8ms
375 // bench_pictures 16.9ms 12.4ms
376 //
377 // This is b.c. in tiled mode each command is called many more times
378 // but typically does less work on each invocation (due to clipping)
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000379 sk_tools::TiledPictureRenderer* renderer = NULL;
380
381 renderer = SkNEW(sk_tools::TiledPictureRenderer);
382 renderer->setTileWidth(256);
383 renderer->setTileHeight(256);
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000384#else
385 sk_tools::SimplePictureRenderer* renderer = NULL;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000386
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000387 renderer = SkNEW(sk_tools::SimplePictureRenderer);
388#endif
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000389
robertphillips@google.come174a8b2012-11-27 16:04:42 +0000390 static const int kNumRepeats = 10;
391
392 run(&picture, renderer, kNumRepeats);
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000393
394 SkASSERT(picture.count() == fListWidget.count());
395
396 // extract the individual command times from the SkTimedPlaybackPicture
397 for (int i = 0; i < picture.count(); ++i) {
398 double temp = picture.time(i);
399
400 QListWidgetItem* item = fListWidget.item(i);
401
402 item->setData(Qt::UserRole + 4, 100.0*temp);
403 }
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000404
405 setupOverviewText(picture.typeTimes(), picture.totTime());
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000406}
407
chudy@google.com902ebe52012-06-29 14:21:22 +0000408void SkDebuggerGUI::actionCancel() {
chudy@google.comc432f002012-07-10 13:19:25 +0000409 for (int row = 0; row < fListWidget.count(); row++) {
410 fListWidget.item(row)->setHidden(false);
chudy@google.com902ebe52012-06-29 14:21:22 +0000411 }
412}
413
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000414void SkDebuggerGUI::actionClearBreakpoints() {
415 for (int row = 0; row < fListWidget.count(); row++) {
416 QListWidgetItem* item = fListWidget.item(row);
417 item->setCheckState(Qt::Unchecked);
418 item->setData(Qt::DecorationRole,
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000419 QPixmap(":/blank.png"));
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000420 }
421}
422
423void SkDebuggerGUI::actionClearDeletes() {
424 for (int row = 0; row < fListWidget.count(); row++) {
425 QListWidgetItem* item = fListWidget.item(row);
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000426 item->setData(Qt::UserRole + 2, QPixmap(":/blank.png"));
chudy@google.com607357f2012-08-07 16:12:23 +0000427 fDebugger.setCommandVisible(row, true);
robertphillips@google.com5f971142012-12-07 20:48:56 +0000428 fSkipCommands[row] = false;
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000429 }
430 if (fPause) {
431 fCanvasWidget.drawTo(fPausedRow);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000432 fImageWidget.draw();
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000433 } else {
434 fCanvasWidget.drawTo(fListWidget.currentRow());
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000435 fImageWidget.draw();
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000436 }
437}
438
chudy@google.com902ebe52012-06-29 14:21:22 +0000439void SkDebuggerGUI::actionCommandFilter() {
chudy@google.com607357f2012-08-07 16:12:23 +0000440 fDebugger.highlightCurrentCommand(
chudy@google.comc432f002012-07-10 13:19:25 +0000441 fSettingsWidget.getVisibilityButton()->isChecked());
442 fCanvasWidget.drawTo(fListWidget.currentRow());
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000443 fImageWidget.draw();
chudy@google.com902ebe52012-06-29 14:21:22 +0000444}
445
446void SkDebuggerGUI::actionClose() {
447 this->close();
448}
449
450void SkDebuggerGUI::actionDelete() {
chudy@google.comc432f002012-07-10 13:19:25 +0000451 int currentRow = fListWidget.currentRow();
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000452 QListWidgetItem* item = fListWidget.currentItem();
453
chudy@google.com607357f2012-08-07 16:12:23 +0000454 if (fDebugger.isCommandVisible(currentRow)) {
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000455 item->setData(Qt::UserRole + 2, QPixmap(":/delete.png"));
chudy@google.com607357f2012-08-07 16:12:23 +0000456 fDebugger.setCommandVisible(currentRow, false);
robertphillips@google.com5f971142012-12-07 20:48:56 +0000457 fSkipCommands[currentRow] = true;
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000458 } else {
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000459 item->setData(Qt::UserRole + 2, QPixmap(":/blank.png"));
chudy@google.com607357f2012-08-07 16:12:23 +0000460 fDebugger.setCommandVisible(currentRow, true);
robertphillips@google.com5f971142012-12-07 20:48:56 +0000461 fSkipCommands[currentRow] = false;
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000462 }
463
chudy@google.come504de02012-07-16 18:35:23 +0000464 if (fPause) {
465 fCanvasWidget.drawTo(fPausedRow);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000466 fImageWidget.draw();
chudy@google.come504de02012-07-16 18:35:23 +0000467 } else {
468 fCanvasWidget.drawTo(currentRow);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000469 fImageWidget.draw();
chudy@google.come504de02012-07-16 18:35:23 +0000470 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000471}
472
chudy@google.comea5488b2012-07-26 19:38:22 +0000473void SkDebuggerGUI::actionGLWidget(bool isToggled) {
474 fCanvasWidget.setWidgetVisibility(SkCanvasWidget::kGPU_WidgetType, !isToggled);
475}
476
chudy@google.com902ebe52012-06-29 14:21:22 +0000477void SkDebuggerGUI::actionInspector() {
chudy@google.comc432f002012-07-10 13:19:25 +0000478 if (fInspectorWidget.isHidden()) {
479 fInspectorWidget.setHidden(false);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000480 fImageWidget.setHidden(false);
chudy@google.com902ebe52012-06-29 14:21:22 +0000481 } else {
chudy@google.comc432f002012-07-10 13:19:25 +0000482 fInspectorWidget.setHidden(true);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000483 fImageWidget.setHidden(true);
chudy@google.com902ebe52012-06-29 14:21:22 +0000484 }
485}
486
487void SkDebuggerGUI::actionPlay() {
chudy@google.comc432f002012-07-10 13:19:25 +0000488 for (int row = fListWidget.currentRow() + 1; row < fListWidget.count();
chudy@google.com7dcae672012-07-09 20:26:53 +0000489 row++) {
chudy@google.comc432f002012-07-10 13:19:25 +0000490 QListWidgetItem *item = fListWidget.item(row);
chudy@google.com902ebe52012-06-29 14:21:22 +0000491 if (item->checkState() == Qt::Checked) {
chudy@google.comc432f002012-07-10 13:19:25 +0000492 fListWidget.setCurrentItem(item);
chudy@google.com902ebe52012-06-29 14:21:22 +0000493 return;
494 }
495 }
chudy@google.comc432f002012-07-10 13:19:25 +0000496 fListWidget.setCurrentRow(fListWidget.count() - 1);
chudy@google.com902ebe52012-06-29 14:21:22 +0000497}
498
chudy@google.comea5488b2012-07-26 19:38:22 +0000499void SkDebuggerGUI::actionRasterWidget(bool isToggled) {
500 fCanvasWidget.setWidgetVisibility(SkCanvasWidget::kRaster_8888_WidgetType, !isToggled);
501}
502
chudy@google.com902ebe52012-06-29 14:21:22 +0000503void SkDebuggerGUI::actionRewind() {
chudy@google.come504de02012-07-16 18:35:23 +0000504 fListWidget.setCurrentRow(0);
chudy@google.com902ebe52012-06-29 14:21:22 +0000505}
506
chudy@google.com0ab03392012-07-28 20:16:11 +0000507void SkDebuggerGUI::actionSave() {
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000508 fFileName = fPath.toAscii();
509 fFileName.append("/");
510 fFileName.append(fDirectoryWidget.currentItem()->text().toAscii());
511 saveToFile(fFileName);
chudy@google.com0ab03392012-07-28 20:16:11 +0000512}
513
514void SkDebuggerGUI::actionSaveAs() {
515 QString filename = QFileDialog::getSaveFileName(this, "Save File", "",
516 "Skia Picture (*skp)");
chudy@google.com38b08ce2012-07-28 23:26:10 +0000517 if (!filename.endsWith(".skp", Qt::CaseInsensitive)) {
chudy@google.com0ab03392012-07-28 20:16:11 +0000518 filename.append(".skp");
519 }
djsollen@google.comc3c82162012-11-13 18:35:10 +0000520 saveToFile(SkString(filename.toAscii().data()));
chudy@google.com0ab03392012-07-28 20:16:11 +0000521}
522
chudy@google.com7dcae672012-07-09 20:26:53 +0000523void SkDebuggerGUI::actionScale(float scaleFactor) {
chudy@google.comc432f002012-07-10 13:19:25 +0000524 fSettingsWidget.setZoomText(scaleFactor);
chudy@google.com7dcae672012-07-09 20:26:53 +0000525}
526
chudy@google.com902ebe52012-06-29 14:21:22 +0000527void SkDebuggerGUI::actionSettings() {
chudy@google.comc432f002012-07-10 13:19:25 +0000528 if (fSettingsWidget.isHidden()) {
529 fSettingsWidget.setHidden(false);
chudy@google.com902ebe52012-06-29 14:21:22 +0000530 } else {
chudy@google.comc432f002012-07-10 13:19:25 +0000531 fSettingsWidget.setHidden(true);
chudy@google.com902ebe52012-06-29 14:21:22 +0000532 }
533}
534
535void SkDebuggerGUI::actionStepBack() {
chudy@google.comc432f002012-07-10 13:19:25 +0000536 int currentRow = fListWidget.currentRow();
chudy@google.com902ebe52012-06-29 14:21:22 +0000537 if (currentRow != 0) {
chudy@google.comc432f002012-07-10 13:19:25 +0000538 fListWidget.setCurrentRow(currentRow - 1);
chudy@google.com902ebe52012-06-29 14:21:22 +0000539 }
540}
541
542void SkDebuggerGUI::actionStepForward() {
chudy@google.comc432f002012-07-10 13:19:25 +0000543 int currentRow = fListWidget.currentRow();
chudy@google.com902ebe52012-06-29 14:21:22 +0000544 QString curRow = QString::number(currentRow);
chudy@google.comc432f002012-07-10 13:19:25 +0000545 QString curCount = QString::number(fListWidget.count());
546 if (currentRow < fListWidget.count() - 1) {
547 fListWidget.setCurrentRow(currentRow + 1);
chudy@google.com902ebe52012-06-29 14:21:22 +0000548 }
549}
550
chudy@google.coma9e937c2012-08-03 17:32:05 +0000551void SkDebuggerGUI::drawComplete() {
chudy@google.com607357f2012-08-07 16:12:23 +0000552 fInspectorWidget.setMatrix(fDebugger.getCurrentMatrix());
553 fInspectorWidget.setClip(fDebugger.getCurrentClip());
chudy@google.coma9e937c2012-08-03 17:32:05 +0000554}
555
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000556void SkDebuggerGUI::saveToFile(const SkString& filename) {
557 SkFILEWStream file(filename.c_str());
robertphillips@google.com25bc2f82013-01-22 18:03:56 +0000558 SkAutoTUnref<SkPicture> copy(fDebugger.copyPicture());
559
560 copy->serialize(&file);
chudy@google.com0ab03392012-07-28 20:16:11 +0000561}
562
chudy@google.com902ebe52012-06-29 14:21:22 +0000563void SkDebuggerGUI::loadFile(QListWidgetItem *item) {
564 if (fDirectoryWidgetActive) {
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000565 fFileName = fPath.toAscii();
566 fFileName.append("/");
567 fFileName.append(item->text().toAscii());
568 loadPicture(fFileName);
chudy@google.com902ebe52012-06-29 14:21:22 +0000569 }
570}
571
572void SkDebuggerGUI::openFile() {
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000573 QString temp = QFileDialog::getOpenFileName(this, tr("Open File"), "",
chudy@google.com7dcae672012-07-09 20:26:53 +0000574 tr("Files (*.*)"));
chudy@google.com902ebe52012-06-29 14:21:22 +0000575 fDirectoryWidgetActive = false;
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000576 if (!temp.isEmpty()) {
577 QFileInfo pathInfo(temp);
chudy@google.com902ebe52012-06-29 14:21:22 +0000578 fPath = pathInfo.path();
djsollen@google.comc3c82162012-11-13 18:35:10 +0000579 loadPicture(SkString(temp.toAscii().data()));
chudy@google.com902ebe52012-06-29 14:21:22 +0000580 setupDirectoryWidget();
581 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000582 fDirectoryWidgetActive = true;
583}
584
chudy@google.comc432f002012-07-10 13:19:25 +0000585void SkDebuggerGUI::pauseDrawing(bool isPaused) {
chudy@google.com607357f2012-08-07 16:12:23 +0000586 fPause = isPaused;
587 fPausedRow = fListWidget.currentRow();
588 fCanvasWidget.drawTo(fPausedRow);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000589 fImageWidget.draw();
chudy@google.com7dcae672012-07-09 20:26:53 +0000590}
591
chudy@google.com902ebe52012-06-29 14:21:22 +0000592void SkDebuggerGUI::registerListClick(QListWidgetItem *item) {
chudy@google.comd3058f52012-07-19 13:41:27 +0000593 if(!fLoading) {
594 int currentRow = fListWidget.currentRow();
chudy@google.comd3058f52012-07-19 13:41:27 +0000595
chudy@google.comea5488b2012-07-26 19:38:22 +0000596 if (currentRow != -1) {
597 if (!fPause) {
598 fCanvasWidget.drawTo(currentRow);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000599 fImageWidget.draw();
chudy@google.comd3058f52012-07-19 13:41:27 +0000600 }
chudy@google.com97cee972012-08-07 20:41:37 +0000601 SkTDArray<SkString*> *currInfo = fDebugger.getCommandInfo(
chudy@google.comea5488b2012-07-26 19:38:22 +0000602 currentRow);
603
604 /* TODO(chudy): Add command type before parameters. Rename v
605 * to something more informative. */
chudy@google.com97cee972012-08-07 20:41:37 +0000606 if (currInfo) {
chudy@google.comea5488b2012-07-26 19:38:22 +0000607 QString info;
608 info.append("<b>Parameters: </b><br/>");
chudy@google.com97cee972012-08-07 20:41:37 +0000609 for (int i = 0; i < currInfo->count(); i++) {
610
611 info.append(QString((*currInfo)[i]->c_str()));
chudy@google.comea5488b2012-07-26 19:38:22 +0000612 info.append("<br/>");
613 }
chudy@google.com6bd109a2012-08-14 19:34:13 +0000614 fInspectorWidget.setText(info, SkInspectorWidget::kDetail_TabType);
chudy@google.comea5488b2012-07-26 19:38:22 +0000615 fInspectorWidget.setDisabled(false);
chudy@google.comea5488b2012-07-26 19:38:22 +0000616 }
chudy@google.comd3058f52012-07-19 13:41:27 +0000617 }
chudy@google.comea5488b2012-07-26 19:38:22 +0000618
chudy@google.com902ebe52012-06-29 14:21:22 +0000619 }
620}
621
chudy@google.com9ca9bfe2012-07-12 21:58:14 +0000622void SkDebuggerGUI::selectCommand(int command) {
623 if (fPause) {
624 fListWidget.setCurrentRow(command);
625 }
626}
627
chudy@google.com902ebe52012-06-29 14:21:22 +0000628void SkDebuggerGUI::toggleBreakpoint() {
chudy@google.comc432f002012-07-10 13:19:25 +0000629 QListWidgetItem* item = fListWidget.currentItem();
chudy@google.com902ebe52012-06-29 14:21:22 +0000630 if (item->checkState() == Qt::Unchecked) {
631 item->setCheckState(Qt::Checked);
chudy@google.come565de42012-07-12 14:15:54 +0000632 item->setData(Qt::DecorationRole,
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000633 QPixmap(":/breakpoint_16x16.png"));
chudy@google.com902ebe52012-06-29 14:21:22 +0000634 } else {
chudy@google.com902ebe52012-06-29 14:21:22 +0000635 item->setCheckState(Qt::Unchecked);
chudy@google.come565de42012-07-12 14:15:54 +0000636 item->setData(Qt::DecorationRole,
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000637 QPixmap(":/blank.png"));
chudy@google.com902ebe52012-06-29 14:21:22 +0000638 }
639}
640
641void SkDebuggerGUI::toggleDirectory() {
chudy@google.com607357f2012-08-07 16:12:23 +0000642 fDirectoryWidget.setHidden(!fDirectoryWidget.isHidden());
chudy@google.com902ebe52012-06-29 14:21:22 +0000643}
644
645void SkDebuggerGUI::toggleFilter(QString string) {
chudy@google.comc432f002012-07-10 13:19:25 +0000646 for (int row = 0; row < fListWidget.count(); row++) {
647 QListWidgetItem *item = fListWidget.item(row);
chudy@google.com607357f2012-08-07 16:12:23 +0000648 item->setHidden(item->text() != string);
chudy@google.com902ebe52012-06-29 14:21:22 +0000649 }
650}
651
652void SkDebuggerGUI::setupUi(QMainWindow *SkDebuggerGUI) {
653 QIcon windowIcon;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000654 windowIcon.addFile(QString::fromUtf8(":/skia.png"), QSize(),
chudy@google.com7dcae672012-07-09 20:26:53 +0000655 QIcon::Normal, QIcon::Off);
chudy@google.com902ebe52012-06-29 14:21:22 +0000656 SkDebuggerGUI->setObjectName(QString::fromUtf8("SkDebuggerGUI"));
657 SkDebuggerGUI->resize(1200, 1000);
658 SkDebuggerGUI->setWindowIcon(windowIcon);
chudy@google.comc432f002012-07-10 13:19:25 +0000659 SkDebuggerGUI->setWindowTitle("Skia Debugger");
chudy@google.com902ebe52012-06-29 14:21:22 +0000660
chudy@google.come504de02012-07-16 18:35:23 +0000661 fActionOpen.setShortcuts(QKeySequence::Open);
chudy@google.comc432f002012-07-10 13:19:25 +0000662 fActionOpen.setText("Open");
chudy@google.com902ebe52012-06-29 14:21:22 +0000663
664 QIcon breakpoint;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000665 breakpoint.addFile(QString::fromUtf8(":/breakpoint.png"),
chudy@google.com7dcae672012-07-09 20:26:53 +0000666 QSize(), QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000667 fActionBreakpoint.setShortcut(QKeySequence(tr("Ctrl+B")));
chudy@google.comc432f002012-07-10 13:19:25 +0000668 fActionBreakpoint.setIcon(breakpoint);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000669 fActionBreakpoint.setText("Breakpoints");
chudy@google.com902ebe52012-06-29 14:21:22 +0000670
671 QIcon cancel;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000672 cancel.addFile(QString::fromUtf8(":/reload.png"), QSize(),
chudy@google.com7dcae672012-07-09 20:26:53 +0000673 QIcon::Normal, QIcon::Off);
chudy@google.comc432f002012-07-10 13:19:25 +0000674 fActionCancel.setIcon(cancel);
675 fActionCancel.setText("Clear Filter");
chudy@google.com902ebe52012-06-29 14:21:22 +0000676
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000677 fActionClearBreakpoints.setShortcut(QKeySequence(tr("Alt+B")));
678 fActionClearBreakpoints.setText("Clear Breakpoints");
679
680 fActionClearDeletes.setShortcut(QKeySequence(tr("Alt+X")));
681 fActionClearDeletes.setText("Clear Deletes");
682
chudy@google.come504de02012-07-16 18:35:23 +0000683 fActionClose.setShortcuts(QKeySequence::Quit);
chudy@google.comc432f002012-07-10 13:19:25 +0000684 fActionClose.setText("Exit");
chudy@google.com902ebe52012-06-29 14:21:22 +0000685
chudy@google.come504de02012-07-16 18:35:23 +0000686 fActionCreateBreakpoint.setShortcut(QKeySequence(tr("B")));
687 fActionCreateBreakpoint.setText("Set Breakpoint");
688
689 fActionDelete.setShortcut(QKeySequence(tr("X")));
chudy@google.comc432f002012-07-10 13:19:25 +0000690 fActionDelete.setText("Delete Command");
chudy@google.com902ebe52012-06-29 14:21:22 +0000691
chudy@google.come504de02012-07-16 18:35:23 +0000692 fActionDirectory.setShortcut(QKeySequence(tr("Ctrl+D")));
693 fActionDirectory.setText("Directory");
chudy@google.com902ebe52012-06-29 14:21:22 +0000694
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000695 QIcon profile;
robertphillips@google.comd1636362012-11-19 18:25:09 +0000696 profile.addFile(QString::fromUtf8(":/profile.png"), QSize(),
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000697 QIcon::Normal, QIcon::Off);
698 fActionProfile.setIcon(profile);
699 fActionProfile.setText("Profile");
robertphillips@google.come099bc42012-11-19 16:26:40 +0000700 fActionProfile.setDisabled(true);
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000701
chudy@google.comc432f002012-07-10 13:19:25 +0000702 QIcon inspector;
robertphillips@google.comd1636362012-11-19 18:25:09 +0000703 inspector.addFile(QString::fromUtf8(":/inspector.png"),
chudy@google.comc432f002012-07-10 13:19:25 +0000704 QSize(), QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000705 fActionInspector.setShortcut(QKeySequence(tr("Ctrl+I")));
chudy@google.comc432f002012-07-10 13:19:25 +0000706 fActionInspector.setIcon(inspector);
chudy@google.come504de02012-07-16 18:35:23 +0000707 fActionInspector.setText("Inspector");
chudy@google.com902ebe52012-06-29 14:21:22 +0000708
chudy@google.comc432f002012-07-10 13:19:25 +0000709 QIcon play;
robertphillips@google.comd1636362012-11-19 18:25:09 +0000710 play.addFile(QString::fromUtf8(":/play.png"), QSize(),
chudy@google.comc432f002012-07-10 13:19:25 +0000711 QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000712 fActionPlay.setShortcut(QKeySequence(tr("Ctrl+P")));
chudy@google.comc432f002012-07-10 13:19:25 +0000713 fActionPlay.setIcon(play);
714 fActionPlay.setText("Play");
chudy@google.com902ebe52012-06-29 14:21:22 +0000715
chudy@google.come504de02012-07-16 18:35:23 +0000716 QIcon pause;
robertphillips@google.comd1636362012-11-19 18:25:09 +0000717 pause.addFile(QString::fromUtf8(":/pause.png"), QSize(),
chudy@google.comc432f002012-07-10 13:19:25 +0000718 QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000719 fActionPause.setShortcut(QKeySequence(tr("Space")));
720 fActionPause.setCheckable(true);
721 fActionPause.setIcon(pause);
722 fActionPause.setText("Pause");
723
chudy@google.comc432f002012-07-10 13:19:25 +0000724 QIcon rewind;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000725 rewind.addFile(QString::fromUtf8(":/rewind.png"), QSize(),
chudy@google.comc432f002012-07-10 13:19:25 +0000726 QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000727 fActionRewind.setShortcut(QKeySequence(tr("Ctrl+R")));
chudy@google.comc432f002012-07-10 13:19:25 +0000728 fActionRewind.setIcon(rewind);
729 fActionRewind.setText("Rewind");
chudy@google.com902ebe52012-06-29 14:21:22 +0000730
chudy@google.com0ab03392012-07-28 20:16:11 +0000731 fActionSave.setShortcut(QKeySequence::Save);
732 fActionSave.setText("Save");
733 fActionSave.setDisabled(true);
734 fActionSaveAs.setShortcut(QKeySequence::SaveAs);
735 fActionSaveAs.setText("Save As");
736 fActionSaveAs.setDisabled(true);
737
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000738 fActionShowDeletes.setShortcut(QKeySequence(tr("Ctrl+X")));
739 fActionShowDeletes.setText("Deleted Commands");
740
chudy@google.comc432f002012-07-10 13:19:25 +0000741 QIcon stepBack;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000742 stepBack.addFile(QString::fromUtf8(":/previous.png"), QSize(),
chudy@google.comc432f002012-07-10 13:19:25 +0000743 QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000744 fActionStepBack.setShortcut(QKeySequence(tr("[")));
chudy@google.comc432f002012-07-10 13:19:25 +0000745 fActionStepBack.setIcon(stepBack);
746 fActionStepBack.setText("Step Back");
chudy@google.com902ebe52012-06-29 14:21:22 +0000747
chudy@google.comc432f002012-07-10 13:19:25 +0000748 QIcon stepForward;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000749 stepForward.addFile(QString::fromUtf8(":/next.png"),
chudy@google.comc432f002012-07-10 13:19:25 +0000750 QSize(), QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000751 fActionStepForward.setShortcut(QKeySequence(tr("]")));
chudy@google.comc432f002012-07-10 13:19:25 +0000752 fActionStepForward.setIcon(stepForward);
753 fActionStepForward.setText("Step Forward");
754
chudy@google.coma1226312012-07-26 20:26:44 +0000755 fActionZoomIn.setShortcut(QKeySequence(tr("Ctrl+=")));
756 fActionZoomIn.setText("Zoom In");
757 fActionZoomOut.setShortcut(QKeySequence(tr("Ctrl+-")));
758 fActionZoomOut.setText("Zoom Out");
759
chudy@google.comc432f002012-07-10 13:19:25 +0000760 fListWidget.setItemDelegate(new SkListWidget(&fListWidget));
761 fListWidget.setObjectName(QString::fromUtf8("listWidget"));
762 fListWidget.setMaximumWidth(250);
763
764 fFilter.addItem("--Filter By Available Commands--");
765
766 fDirectoryWidget.setMaximumWidth(250);
767 fDirectoryWidget.setStyleSheet("QListWidget::Item {padding: 5px;}");
768
769 fCanvasWidget.setSizePolicy(QSizePolicy::Expanding,
chudy@google.com7dcae672012-07-09 20:26:53 +0000770 QSizePolicy::Expanding);
chudy@google.com902ebe52012-06-29 14:21:22 +0000771
skia.committer@gmail.com1c9c0d32012-11-22 02:02:41 +0000772 fImageWidget.setFixedSize(SkImageWidget::kImageWidgetWidth,
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000773 SkImageWidget::kImageWidgetHeight);
774
chudy@google.comc432f002012-07-10 13:19:25 +0000775 fInspectorWidget.setSizePolicy(QSizePolicy::Expanding,
chudy@google.com7dcae672012-07-09 20:26:53 +0000776 QSizePolicy::Expanding);
chudy@google.comc432f002012-07-10 13:19:25 +0000777 fInspectorWidget.setMaximumHeight(300);
chudy@google.com902ebe52012-06-29 14:21:22 +0000778
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000779 fSettingsAndImageLayout.setSpacing(6);
780 fSettingsAndImageLayout.addWidget(&fSettingsWidget);
781 fSettingsAndImageLayout.addWidget(&fImageWidget);
782
chudy@google.comc432f002012-07-10 13:19:25 +0000783 fSettingsWidget.setSizePolicy(QSizePolicy::Expanding,
784 QSizePolicy::Expanding);
785 fSettingsWidget.setMaximumWidth(250);
chudy@google.com902ebe52012-06-29 14:21:22 +0000786
chudy@google.comc432f002012-07-10 13:19:25 +0000787 fLeftColumnLayout.setSpacing(6);
788 fLeftColumnLayout.addWidget(&fListWidget);
789 fLeftColumnLayout.addWidget(&fDirectoryWidget);
chudy@google.com902ebe52012-06-29 14:21:22 +0000790
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000791 fCanvasSettingsAndImageLayout.setSpacing(6);
792 fCanvasSettingsAndImageLayout.addWidget(&fCanvasWidget);
793 fCanvasSettingsAndImageLayout.addLayout(&fSettingsAndImageLayout);
794
chudy@google.com902ebe52012-06-29 14:21:22 +0000795
chudy@google.comc432f002012-07-10 13:19:25 +0000796 fMainAndRightColumnLayout.setSpacing(6);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000797 fMainAndRightColumnLayout.addLayout(&fCanvasSettingsAndImageLayout);
chudy@google.comc432f002012-07-10 13:19:25 +0000798 fMainAndRightColumnLayout.addWidget(&fInspectorWidget);
chudy@google.com902ebe52012-06-29 14:21:22 +0000799
chudy@google.com2d537a12012-07-31 12:49:52 +0000800 fCentralWidget.setLayout(&fContainerLayout);
chudy@google.comc432f002012-07-10 13:19:25 +0000801 fContainerLayout.setSpacing(6);
802 fContainerLayout.setContentsMargins(11, 11, 11, 11);
803 fContainerLayout.addLayout(&fLeftColumnLayout);
804 fContainerLayout.addLayout(&fMainAndRightColumnLayout);
805
806 SkDebuggerGUI->setCentralWidget(&fCentralWidget);
807 SkDebuggerGUI->setStatusBar(&fStatusBar);
808
chudy@google.come504de02012-07-16 18:35:23 +0000809 fToolBar.setIconSize(QSize(32, 32));
chudy@google.comc432f002012-07-10 13:19:25 +0000810 fToolBar.setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
811 SkDebuggerGUI->addToolBar(Qt::TopToolBarArea, &fToolBar);
chudy@google.com902ebe52012-06-29 14:21:22 +0000812
chudy@google.com0ab03392012-07-28 20:16:11 +0000813 fSpacer.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
chudy@google.com902ebe52012-06-29 14:21:22 +0000814
chudy@google.comc432f002012-07-10 13:19:25 +0000815 fToolBar.addAction(&fActionRewind);
816 fToolBar.addAction(&fActionStepBack);
chudy@google.come504de02012-07-16 18:35:23 +0000817 fToolBar.addAction(&fActionPause);
chudy@google.comc432f002012-07-10 13:19:25 +0000818 fToolBar.addAction(&fActionStepForward);
819 fToolBar.addAction(&fActionPlay);
820 fToolBar.addSeparator();
chudy@google.come504de02012-07-16 18:35:23 +0000821 fToolBar.addAction(&fActionInspector);
chudy@google.comc432f002012-07-10 13:19:25 +0000822 fToolBar.addSeparator();
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000823 fToolBar.addAction(&fActionProfile);
824
825 fToolBar.addSeparator();
chudy@google.com0ab03392012-07-28 20:16:11 +0000826 fToolBar.addWidget(&fSpacer);
chudy@google.comc432f002012-07-10 13:19:25 +0000827 fToolBar.addWidget(&fFilter);
828 fToolBar.addAction(&fActionCancel);
chudy@google.com902ebe52012-06-29 14:21:22 +0000829
830 // TODO(chudy): Remove static call.
831 fDirectoryWidgetActive = false;
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000832 fPath = "";
833 fFileName = "";
chudy@google.com902ebe52012-06-29 14:21:22 +0000834 setupDirectoryWidget();
835 fDirectoryWidgetActive = true;
836
chudy@google.com902ebe52012-06-29 14:21:22 +0000837 // Menu Bar
chudy@google.comc432f002012-07-10 13:19:25 +0000838 fMenuFile.setTitle("File");
839 fMenuFile.addAction(&fActionOpen);
chudy@google.com0ab03392012-07-28 20:16:11 +0000840 fMenuFile.addAction(&fActionSave);
841 fMenuFile.addAction(&fActionSaveAs);
chudy@google.comc432f002012-07-10 13:19:25 +0000842 fMenuFile.addAction(&fActionClose);
chudy@google.come504de02012-07-16 18:35:23 +0000843
844 fMenuEdit.setTitle("Edit");
845 fMenuEdit.addAction(&fActionDelete);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000846 fMenuEdit.addAction(&fActionClearDeletes);
847 fMenuEdit.addSeparator();
chudy@google.come504de02012-07-16 18:35:23 +0000848 fMenuEdit.addAction(&fActionCreateBreakpoint);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000849 fMenuEdit.addAction(&fActionClearBreakpoints);
chudy@google.come504de02012-07-16 18:35:23 +0000850
chudy@google.comc432f002012-07-10 13:19:25 +0000851 fMenuNavigate.setTitle("Navigate");
chudy@google.come504de02012-07-16 18:35:23 +0000852 fMenuNavigate.addAction(&fActionRewind);
853 fMenuNavigate.addAction(&fActionStepBack);
854 fMenuNavigate.addAction(&fActionStepForward);
855 fMenuNavigate.addAction(&fActionPlay);
856 fMenuNavigate.addAction(&fActionPause);
chudy@google.comc432f002012-07-10 13:19:25 +0000857 fMenuNavigate.addAction(&fActionGoToLine);
chudy@google.come504de02012-07-16 18:35:23 +0000858
chudy@google.comc432f002012-07-10 13:19:25 +0000859 fMenuView.setTitle("View");
chudy@google.come504de02012-07-16 18:35:23 +0000860 fMenuView.addAction(&fActionBreakpoint);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000861 fMenuView.addAction(&fActionShowDeletes);
chudy@google.coma1226312012-07-26 20:26:44 +0000862 fMenuView.addAction(&fActionZoomIn);
863 fMenuView.addAction(&fActionZoomOut);
chudy@google.come504de02012-07-16 18:35:23 +0000864
865 fMenuWindows.setTitle("Window");
866 fMenuWindows.addAction(&fActionInspector);
867 fMenuWindows.addAction(&fActionDirectory);
chudy@google.comc432f002012-07-10 13:19:25 +0000868
869 fActionGoToLine.setText("Go to Line...");
870 fActionGoToLine.setDisabled(true);
871 fMenuBar.addAction(fMenuFile.menuAction());
chudy@google.come504de02012-07-16 18:35:23 +0000872 fMenuBar.addAction(fMenuEdit.menuAction());
chudy@google.comc432f002012-07-10 13:19:25 +0000873 fMenuBar.addAction(fMenuView.menuAction());
874 fMenuBar.addAction(fMenuNavigate.menuAction());
chudy@google.come504de02012-07-16 18:35:23 +0000875 fMenuBar.addAction(fMenuWindows.menuAction());
chudy@google.com902ebe52012-06-29 14:21:22 +0000876
chudy@google.com7dcae672012-07-09 20:26:53 +0000877 fPause = false;
878
chudy@google.comc432f002012-07-10 13:19:25 +0000879 SkDebuggerGUI->setMenuBar(&fMenuBar);
chudy@google.com902ebe52012-06-29 14:21:22 +0000880 QMetaObject::connectSlotsByName(SkDebuggerGUI);
881}
882
883void SkDebuggerGUI::setupDirectoryWidget() {
chudy@google.comc432f002012-07-10 13:19:25 +0000884 QDir dir(fPath);
chudy@google.com902ebe52012-06-29 14:21:22 +0000885 QRegExp r(".skp");
chudy@google.comc432f002012-07-10 13:19:25 +0000886 fDirectoryWidget.clear();
887 const QStringList files = dir.entryList();
chudy@google.com902ebe52012-06-29 14:21:22 +0000888 foreach (QString f, files) {
chudy@google.com7dcae672012-07-09 20:26:53 +0000889 if (f.contains(r))
chudy@google.comc432f002012-07-10 13:19:25 +0000890 fDirectoryWidget.addItem(f);
chudy@google.com902ebe52012-06-29 14:21:22 +0000891 }
892}
893
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000894// SkOffsetPicturePlayback records the offset of each command in the picture.
895// These are needed by the profiling system.
896class SkOffsetPicturePlayback : public SkPicturePlayback {
897public:
898 SkOffsetPicturePlayback(SkStream* stream, const SkPictInfo& info, bool* isValid,
899 SkSerializationHelpers::DecodeBitmap decoder)
900 : INHERITED(stream, info, isValid, decoder) {
901 }
902
903 const SkTDArray<size_t>& offsets() const { return fOffsets; }
904
905protected:
906 SkTDArray<size_t> fOffsets;
907
robertphillips@google.comca47aae2012-12-12 15:58:25 +0000908 virtual size_t preDraw(size_t offset, int type) {
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000909 *fOffsets.append() = offset;
robertphillips@google.com5f971142012-12-07 20:48:56 +0000910 return 0;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000911 }
912
913private:
914 typedef SkPicturePlayback INHERITED;
915};
916
917// Picture to wrap an SkOffsetPicturePlayback.
918class SkOffsetPicture : public SkPicture {
919public:
skia.committer@gmail.com884e60b2012-11-16 02:01:17 +0000920 SkOffsetPicture(SkStream* stream,
921 bool* success,
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000922 SkSerializationHelpers::DecodeBitmap decoder) {
923 if (success) {
924 *success = false;
925 }
926 fRecord = NULL;
927 fPlayback = NULL;
928 fWidth = fHeight = 0;
929
930 SkPictInfo info;
931
932 if (!stream->read(&info, sizeof(info))) {
933 return;
934 }
935 if (PICTURE_VERSION != info.fVersion) {
936 return;
937 }
938
939 if (stream->readBool()) {
940 bool isValid = false;
941 fPlayback = SkNEW_ARGS(SkOffsetPicturePlayback, (stream, info, &isValid, decoder));
942 if (!isValid) {
943 SkDELETE(fPlayback);
944 fPlayback = NULL;
945 return;
946 }
947 }
948
949 // do this at the end, so that they will be zero if we hit an error.
950 fWidth = info.fWidth;
951 fHeight = info.fHeight;
952 if (success) {
953 *success = true;
954 }
955 }
956
skia.committer@gmail.com884e60b2012-11-16 02:01:17 +0000957 const SkTDArray<size_t>& offsets() const {
958 return ((SkOffsetPicturePlayback*) fPlayback)->offsets();
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000959 }
960
961private:
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000962 // disallow default ctor b.c. we don't have a good way to setup the fPlayback ptr
963 SkOffsetPicture();
964 // disallow the copy ctor - enabling would require copying code from SkPicture
965 SkOffsetPicture(const SkOffsetPicture& src);
966
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000967 typedef SkPicture INHERITED;
968};
969
970
971
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000972void SkDebuggerGUI::loadPicture(const SkString& fileName) {
973 fFileName = fileName;
chudy@google.comd3058f52012-07-19 13:41:27 +0000974 fLoading = true;
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000975 SkStream* stream = SkNEW_ARGS(SkFILEStream, (fileName.c_str()));
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000976 SkOffsetPicture* picture = SkNEW_ARGS(SkOffsetPicture, (stream, NULL, &SkImageDecoder::DecodeStream));
977
chudy@google.com686e6802012-08-14 16:00:32 +0000978 fCanvasWidget.resetWidgetTransform();
chudy@google.com607357f2012-08-07 16:12:23 +0000979 fDebugger.loadPicture(picture);
chudy@google.com4c7962e2012-08-14 19:38:31 +0000980
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000981 fOffsets = picture->offsets();
982
robertphillips@google.com5f971142012-12-07 20:48:56 +0000983 fSkipCommands.setCount(fOffsets.count());
984 for (int i = 0; i < fOffsets.count(); ++i) {
985 fSkipCommands[i] = false;
986 }
987
chudy@google.com607357f2012-08-07 16:12:23 +0000988 SkSafeUnref(stream);
989 SkSafeUnref(picture);
990
chudy@google.com97cee972012-08-07 20:41:37 +0000991 // Will this automatically clear out due to nature of refcnt?
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000992 SkTArray<SkString>* commands = fDebugger.getDrawCommandsAsStrings();
chudy@google.com607357f2012-08-07 16:12:23 +0000993
robertphillips@google.comfe830a42012-11-15 16:33:31 +0000994 // If SkPicturePlayback is compiled w/o SK_PICTURE_PROFILING_STUBS
995 // the offset count will always be zero
996 SkASSERT(0 == fOffsets.count() || commands->count() == fOffsets.count());
robertphillips@google.come099bc42012-11-19 16:26:40 +0000997 if (commands->count() == fOffsets.count()) {
998 fActionProfile.setDisabled(false);
robertphillips@google.comfe830a42012-11-15 16:33:31 +0000999 }
robertphillips@google.com2bde91d2012-11-15 14:57:57 +00001000
chudy@google.com7dcae672012-07-09 20:26:53 +00001001 /* fDebugCanvas is reinitialized every load picture. Need it to retain value
chudy@google.com607357f2012-08-07 16:12:23 +00001002 * of the visibility filter.
1003 * TODO(chudy): This should be deprecated since fDebugger is not
1004 * recreated.
1005 * */
1006 fDebugger.highlightCurrentCommand(fSettingsWidget.getVisibilityButton()->isChecked());
1007
chudy@google.com97cee972012-08-07 20:41:37 +00001008 setupListWidget(commands);
1009 setupComboBox(commands);
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +00001010 setupOverviewText(NULL, 0.0);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +00001011 fInspectorWidget.setDisabled(false);
chudy@google.come606d6e2012-07-12 14:31:25 +00001012 fSettingsWidget.setDisabled(false);
chudy@google.comd3058f52012-07-19 13:41:27 +00001013 fMenuEdit.setDisabled(false);
1014 fMenuNavigate.setDisabled(false);
1015 fMenuView.setDisabled(false);
chudy@google.com0ab03392012-07-28 20:16:11 +00001016 fActionSave.setDisabled(false);
1017 fActionSaveAs.setDisabled(false);
chudy@google.comd3058f52012-07-19 13:41:27 +00001018 fLoading = false;
1019 actionPlay();
chudy@google.com902ebe52012-06-29 14:21:22 +00001020}
1021
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +00001022void SkDebuggerGUI::setupListWidget(SkTArray<SkString>* command) {
chudy@google.comc432f002012-07-10 13:19:25 +00001023 fListWidget.clear();
chudy@google.com902ebe52012-06-29 14:21:22 +00001024 int counter = 0;
robertphillips@google.com30d35f22012-11-06 16:45:36 +00001025 int indent = 0;
chudy@google.com97cee972012-08-07 20:41:37 +00001026 for (int i = 0; i < command->count(); i++) {
chudy@google.com902ebe52012-06-29 14:21:22 +00001027 QListWidgetItem *item = new QListWidgetItem();
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +00001028 item->setData(Qt::DisplayRole, (*command)[i].c_str());
chudy@google.com902ebe52012-06-29 14:21:22 +00001029 item->setData(Qt::UserRole + 1, counter++);
robertphillips@google.com30d35f22012-11-06 16:45:36 +00001030
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +00001031 if (0 == strcmp("Restore", (*command)[i].c_str())) {
robertphillips@google.com30d35f22012-11-06 16:45:36 +00001032 indent -= 10;
1033 }
1034
1035 item->setData(Qt::UserRole + 3, indent);
1036
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +00001037 if (0 == strcmp("Save", (*command)[i].c_str()) ||
1038 0 == strcmp("Save Layer", (*command)[i].c_str())) {
robertphillips@google.com30d35f22012-11-06 16:45:36 +00001039 indent += 10;
1040 }
1041
robertphillips@google.comd26c7062012-11-12 20:42:12 +00001042 item->setData(Qt::UserRole + 4, -1.0);
1043
chudy@google.comc432f002012-07-10 13:19:25 +00001044 fListWidget.addItem(item);
chudy@google.com902ebe52012-06-29 14:21:22 +00001045 }
1046}
1047
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +00001048void SkDebuggerGUI::setupOverviewText(const SkTDArray<double>* typeTimes, double totTime) {
chudy@google.com902ebe52012-06-29 14:21:22 +00001049
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +00001050 const SkTDArray<SkDrawCommand*>& commands = fDebugger.getDrawCommands();
1051
1052 SkTDArray<int> counts;
1053 counts.setCount(LAST_DRAWTYPE_ENUM+1);
1054 for (int i = 0; i < LAST_DRAWTYPE_ENUM+1; ++i) {
1055 counts[i] = 0;
1056 }
1057
1058 for (int i = 0; i < commands.count(); i++) {
1059 counts[commands[i]->getType()]++;
chudy@google.com902ebe52012-06-29 14:21:22 +00001060 }
1061
1062 QString overview;
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +00001063 int total = 0;
1064#ifdef SK_DEBUG
1065 double totPercent = 0, tempSum = 0;
1066#endif
1067 for (int i = 0; i < LAST_DRAWTYPE_ENUM+1; ++i) {
1068 if (0 == counts[i]) {
1069 // if there were no commands of this type then they should've consumed no time
1070 SkASSERT(NULL == typeTimes || 0.0 == (*typeTimes)[i]);
1071 continue;
1072 }
1073
1074 overview.append(SkDrawCommand::GetCommandString((DrawType) i));
chudy@google.com902ebe52012-06-29 14:21:22 +00001075 overview.append(": ");
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +00001076 overview.append(QString::number(counts[i]));
1077 if (NULL != typeTimes) {
1078 overview.append(" - ");
1079 overview.append(QString::number((*typeTimes)[i], 'f', 1));
1080 overview.append("ms");
1081 overview.append(" - ");
1082 double percent = 100.0*(*typeTimes)[i]/totTime;
1083 overview.append(QString::number(percent, 'f', 1));
1084 overview.append("%");
1085#ifdef SK_DEBUG
1086 totPercent += percent;
1087 tempSum += (*typeTimes)[i];
1088#endif
1089 }
chudy@google.com902ebe52012-06-29 14:21:22 +00001090 overview.append("<br/>");
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +00001091 total += counts[i];
chudy@google.com902ebe52012-06-29 14:21:22 +00001092 }
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +00001093#ifdef SK_DEBUG
1094 if (NULL != typeTimes) {
1095 SkASSERT(SkScalarNearlyEqual(totPercent, 100.0));
1096 SkASSERT(SkScalarNearlyEqual(tempSum, totTime));
1097 }
1098#endif
1099
1100 if (totTime > 0.0) {
1101 overview.append("Total Time: ");
1102 overview.append(QString::number(totTime, 'f', 2));
1103 overview.append("ms");
1104#ifdef SK_DEBUG
1105 overview.append(" ");
1106 overview.append(QString::number(totPercent));
1107 overview.append("% ");
1108#endif
1109 overview.append("<br/>");
1110 }
1111
1112 QString totalStr;
1113 totalStr.append("Total Draw Commands: ");
1114 totalStr.append(QString::number(total));
1115 totalStr.append("<br/>");
1116 overview.insert(0, totalStr);
chudy@google.com902ebe52012-06-29 14:21:22 +00001117
1118 overview.append("<br/>");
chudy@google.com607357f2012-08-07 16:12:23 +00001119 overview.append("SkPicture Width: ");
chudy@google.com902ebe52012-06-29 14:21:22 +00001120 // NOTE(chudy): This is where we can pull out the SkPictures width.
chudy@google.com607357f2012-08-07 16:12:23 +00001121 overview.append(QString::number(fDebugger.pictureWidth()));
chudy@google.com902ebe52012-06-29 14:21:22 +00001122 overview.append("px<br/>");
chudy@google.com607357f2012-08-07 16:12:23 +00001123 overview.append("SkPicture Height: ");
1124 overview.append(QString::number(fDebugger.pictureHeight()));
chudy@google.com902ebe52012-06-29 14:21:22 +00001125 overview.append("px");
chudy@google.com6bd109a2012-08-14 19:34:13 +00001126 fInspectorWidget.setText(overview, SkInspectorWidget::kOverview_TabType);
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +00001127}
1128
1129void SkDebuggerGUI::setupComboBox(SkTArray<SkString>* command) {
1130 fFilter.clear();
1131 fFilter.addItem("--Filter By Available Commands--");
1132
1133 std::map<std::string, int> map;
1134 for (int i = 0; i < command->count(); i++) {
1135 map[(*command)[i].c_str()]++;
1136 }
1137
skia.committer@gmail.com34587162012-11-20 02:01:23 +00001138 for (std::map<std::string, int>::iterator it = map.begin(); it != map.end();
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +00001139 ++it) {
1140 fFilter.addItem((it->first).c_str());
1141 }
chudy@google.com902ebe52012-06-29 14:21:22 +00001142
1143 // NOTE(chudy): Makes first item unselectable.
chudy@google.com7dcae672012-07-09 20:26:53 +00001144 QStandardItemModel* model = qobject_cast<QStandardItemModel*>(
chudy@google.comc432f002012-07-10 13:19:25 +00001145 fFilter.model());
1146 QModelIndex firstIndex = model->index(0, fFilter.modelColumn(),
1147 fFilter.rootModelIndex());
chudy@google.com902ebe52012-06-29 14:21:22 +00001148 QStandardItem* firstItem = model->itemFromIndex(firstIndex);
1149 firstItem->setSelectable(false);
1150}