blob: 058cb5c10c8c969e5423959b427327282a3642d8 [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());
chudy@google.com607357f2012-08-07 16:12:23 +0000558 fDebugger.makePicture()->serialize(&file);
chudy@google.com0ab03392012-07-28 20:16:11 +0000559}
560
chudy@google.com902ebe52012-06-29 14:21:22 +0000561void SkDebuggerGUI::loadFile(QListWidgetItem *item) {
562 if (fDirectoryWidgetActive) {
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000563 fFileName = fPath.toAscii();
564 fFileName.append("/");
565 fFileName.append(item->text().toAscii());
566 loadPicture(fFileName);
chudy@google.com902ebe52012-06-29 14:21:22 +0000567 }
568}
569
570void SkDebuggerGUI::openFile() {
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000571 QString temp = QFileDialog::getOpenFileName(this, tr("Open File"), "",
chudy@google.com7dcae672012-07-09 20:26:53 +0000572 tr("Files (*.*)"));
chudy@google.com902ebe52012-06-29 14:21:22 +0000573 fDirectoryWidgetActive = false;
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000574 if (!temp.isEmpty()) {
575 QFileInfo pathInfo(temp);
chudy@google.com902ebe52012-06-29 14:21:22 +0000576 fPath = pathInfo.path();
djsollen@google.comc3c82162012-11-13 18:35:10 +0000577 loadPicture(SkString(temp.toAscii().data()));
chudy@google.com902ebe52012-06-29 14:21:22 +0000578 setupDirectoryWidget();
579 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000580 fDirectoryWidgetActive = true;
581}
582
chudy@google.comc432f002012-07-10 13:19:25 +0000583void SkDebuggerGUI::pauseDrawing(bool isPaused) {
chudy@google.com607357f2012-08-07 16:12:23 +0000584 fPause = isPaused;
585 fPausedRow = fListWidget.currentRow();
586 fCanvasWidget.drawTo(fPausedRow);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000587 fImageWidget.draw();
chudy@google.com7dcae672012-07-09 20:26:53 +0000588}
589
chudy@google.com902ebe52012-06-29 14:21:22 +0000590void SkDebuggerGUI::registerListClick(QListWidgetItem *item) {
chudy@google.comd3058f52012-07-19 13:41:27 +0000591 if(!fLoading) {
592 int currentRow = fListWidget.currentRow();
chudy@google.comd3058f52012-07-19 13:41:27 +0000593
chudy@google.comea5488b2012-07-26 19:38:22 +0000594 if (currentRow != -1) {
595 if (!fPause) {
596 fCanvasWidget.drawTo(currentRow);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000597 fImageWidget.draw();
chudy@google.comd3058f52012-07-19 13:41:27 +0000598 }
chudy@google.com97cee972012-08-07 20:41:37 +0000599 SkTDArray<SkString*> *currInfo = fDebugger.getCommandInfo(
chudy@google.comea5488b2012-07-26 19:38:22 +0000600 currentRow);
601
602 /* TODO(chudy): Add command type before parameters. Rename v
603 * to something more informative. */
chudy@google.com97cee972012-08-07 20:41:37 +0000604 if (currInfo) {
chudy@google.comea5488b2012-07-26 19:38:22 +0000605 QString info;
606 info.append("<b>Parameters: </b><br/>");
chudy@google.com97cee972012-08-07 20:41:37 +0000607 for (int i = 0; i < currInfo->count(); i++) {
608
609 info.append(QString((*currInfo)[i]->c_str()));
chudy@google.comea5488b2012-07-26 19:38:22 +0000610 info.append("<br/>");
611 }
chudy@google.com6bd109a2012-08-14 19:34:13 +0000612 fInspectorWidget.setText(info, SkInspectorWidget::kDetail_TabType);
chudy@google.comea5488b2012-07-26 19:38:22 +0000613 fInspectorWidget.setDisabled(false);
chudy@google.comea5488b2012-07-26 19:38:22 +0000614 }
chudy@google.comd3058f52012-07-19 13:41:27 +0000615 }
chudy@google.comea5488b2012-07-26 19:38:22 +0000616
chudy@google.com902ebe52012-06-29 14:21:22 +0000617 }
618}
619
chudy@google.com9ca9bfe2012-07-12 21:58:14 +0000620void SkDebuggerGUI::selectCommand(int command) {
621 if (fPause) {
622 fListWidget.setCurrentRow(command);
623 }
624}
625
chudy@google.com902ebe52012-06-29 14:21:22 +0000626void SkDebuggerGUI::toggleBreakpoint() {
chudy@google.comc432f002012-07-10 13:19:25 +0000627 QListWidgetItem* item = fListWidget.currentItem();
chudy@google.com902ebe52012-06-29 14:21:22 +0000628 if (item->checkState() == Qt::Unchecked) {
629 item->setCheckState(Qt::Checked);
chudy@google.come565de42012-07-12 14:15:54 +0000630 item->setData(Qt::DecorationRole,
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000631 QPixmap(":/breakpoint_16x16.png"));
chudy@google.com902ebe52012-06-29 14:21:22 +0000632 } else {
chudy@google.com902ebe52012-06-29 14:21:22 +0000633 item->setCheckState(Qt::Unchecked);
chudy@google.come565de42012-07-12 14:15:54 +0000634 item->setData(Qt::DecorationRole,
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000635 QPixmap(":/blank.png"));
chudy@google.com902ebe52012-06-29 14:21:22 +0000636 }
637}
638
639void SkDebuggerGUI::toggleDirectory() {
chudy@google.com607357f2012-08-07 16:12:23 +0000640 fDirectoryWidget.setHidden(!fDirectoryWidget.isHidden());
chudy@google.com902ebe52012-06-29 14:21:22 +0000641}
642
643void SkDebuggerGUI::toggleFilter(QString string) {
chudy@google.comc432f002012-07-10 13:19:25 +0000644 for (int row = 0; row < fListWidget.count(); row++) {
645 QListWidgetItem *item = fListWidget.item(row);
chudy@google.com607357f2012-08-07 16:12:23 +0000646 item->setHidden(item->text() != string);
chudy@google.com902ebe52012-06-29 14:21:22 +0000647 }
648}
649
650void SkDebuggerGUI::setupUi(QMainWindow *SkDebuggerGUI) {
651 QIcon windowIcon;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000652 windowIcon.addFile(QString::fromUtf8(":/skia.png"), QSize(),
chudy@google.com7dcae672012-07-09 20:26:53 +0000653 QIcon::Normal, QIcon::Off);
chudy@google.com902ebe52012-06-29 14:21:22 +0000654 SkDebuggerGUI->setObjectName(QString::fromUtf8("SkDebuggerGUI"));
655 SkDebuggerGUI->resize(1200, 1000);
656 SkDebuggerGUI->setWindowIcon(windowIcon);
chudy@google.comc432f002012-07-10 13:19:25 +0000657 SkDebuggerGUI->setWindowTitle("Skia Debugger");
chudy@google.com902ebe52012-06-29 14:21:22 +0000658
chudy@google.come504de02012-07-16 18:35:23 +0000659 fActionOpen.setShortcuts(QKeySequence::Open);
chudy@google.comc432f002012-07-10 13:19:25 +0000660 fActionOpen.setText("Open");
chudy@google.com902ebe52012-06-29 14:21:22 +0000661
662 QIcon breakpoint;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000663 breakpoint.addFile(QString::fromUtf8(":/breakpoint.png"),
chudy@google.com7dcae672012-07-09 20:26:53 +0000664 QSize(), QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000665 fActionBreakpoint.setShortcut(QKeySequence(tr("Ctrl+B")));
chudy@google.comc432f002012-07-10 13:19:25 +0000666 fActionBreakpoint.setIcon(breakpoint);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000667 fActionBreakpoint.setText("Breakpoints");
chudy@google.com902ebe52012-06-29 14:21:22 +0000668
669 QIcon cancel;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000670 cancel.addFile(QString::fromUtf8(":/reload.png"), QSize(),
chudy@google.com7dcae672012-07-09 20:26:53 +0000671 QIcon::Normal, QIcon::Off);
chudy@google.comc432f002012-07-10 13:19:25 +0000672 fActionCancel.setIcon(cancel);
673 fActionCancel.setText("Clear Filter");
chudy@google.com902ebe52012-06-29 14:21:22 +0000674
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000675 fActionClearBreakpoints.setShortcut(QKeySequence(tr("Alt+B")));
676 fActionClearBreakpoints.setText("Clear Breakpoints");
677
678 fActionClearDeletes.setShortcut(QKeySequence(tr("Alt+X")));
679 fActionClearDeletes.setText("Clear Deletes");
680
chudy@google.come504de02012-07-16 18:35:23 +0000681 fActionClose.setShortcuts(QKeySequence::Quit);
chudy@google.comc432f002012-07-10 13:19:25 +0000682 fActionClose.setText("Exit");
chudy@google.com902ebe52012-06-29 14:21:22 +0000683
chudy@google.come504de02012-07-16 18:35:23 +0000684 fActionCreateBreakpoint.setShortcut(QKeySequence(tr("B")));
685 fActionCreateBreakpoint.setText("Set Breakpoint");
686
687 fActionDelete.setShortcut(QKeySequence(tr("X")));
chudy@google.comc432f002012-07-10 13:19:25 +0000688 fActionDelete.setText("Delete Command");
chudy@google.com902ebe52012-06-29 14:21:22 +0000689
chudy@google.come504de02012-07-16 18:35:23 +0000690 fActionDirectory.setShortcut(QKeySequence(tr("Ctrl+D")));
691 fActionDirectory.setText("Directory");
chudy@google.com902ebe52012-06-29 14:21:22 +0000692
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000693 QIcon profile;
robertphillips@google.comd1636362012-11-19 18:25:09 +0000694 profile.addFile(QString::fromUtf8(":/profile.png"), QSize(),
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000695 QIcon::Normal, QIcon::Off);
696 fActionProfile.setIcon(profile);
697 fActionProfile.setText("Profile");
robertphillips@google.come099bc42012-11-19 16:26:40 +0000698 fActionProfile.setDisabled(true);
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000699
chudy@google.comc432f002012-07-10 13:19:25 +0000700 QIcon inspector;
robertphillips@google.comd1636362012-11-19 18:25:09 +0000701 inspector.addFile(QString::fromUtf8(":/inspector.png"),
chudy@google.comc432f002012-07-10 13:19:25 +0000702 QSize(), QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000703 fActionInspector.setShortcut(QKeySequence(tr("Ctrl+I")));
chudy@google.comc432f002012-07-10 13:19:25 +0000704 fActionInspector.setIcon(inspector);
chudy@google.come504de02012-07-16 18:35:23 +0000705 fActionInspector.setText("Inspector");
chudy@google.com902ebe52012-06-29 14:21:22 +0000706
chudy@google.comc432f002012-07-10 13:19:25 +0000707 QIcon play;
robertphillips@google.comd1636362012-11-19 18:25:09 +0000708 play.addFile(QString::fromUtf8(":/play.png"), QSize(),
chudy@google.comc432f002012-07-10 13:19:25 +0000709 QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000710 fActionPlay.setShortcut(QKeySequence(tr("Ctrl+P")));
chudy@google.comc432f002012-07-10 13:19:25 +0000711 fActionPlay.setIcon(play);
712 fActionPlay.setText("Play");
chudy@google.com902ebe52012-06-29 14:21:22 +0000713
chudy@google.come504de02012-07-16 18:35:23 +0000714 QIcon pause;
robertphillips@google.comd1636362012-11-19 18:25:09 +0000715 pause.addFile(QString::fromUtf8(":/pause.png"), QSize(),
chudy@google.comc432f002012-07-10 13:19:25 +0000716 QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000717 fActionPause.setShortcut(QKeySequence(tr("Space")));
718 fActionPause.setCheckable(true);
719 fActionPause.setIcon(pause);
720 fActionPause.setText("Pause");
721
chudy@google.comc432f002012-07-10 13:19:25 +0000722 QIcon rewind;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000723 rewind.addFile(QString::fromUtf8(":/rewind.png"), QSize(),
chudy@google.comc432f002012-07-10 13:19:25 +0000724 QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000725 fActionRewind.setShortcut(QKeySequence(tr("Ctrl+R")));
chudy@google.comc432f002012-07-10 13:19:25 +0000726 fActionRewind.setIcon(rewind);
727 fActionRewind.setText("Rewind");
chudy@google.com902ebe52012-06-29 14:21:22 +0000728
chudy@google.com0ab03392012-07-28 20:16:11 +0000729 fActionSave.setShortcut(QKeySequence::Save);
730 fActionSave.setText("Save");
731 fActionSave.setDisabled(true);
732 fActionSaveAs.setShortcut(QKeySequence::SaveAs);
733 fActionSaveAs.setText("Save As");
734 fActionSaveAs.setDisabled(true);
735
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000736 fActionShowDeletes.setShortcut(QKeySequence(tr("Ctrl+X")));
737 fActionShowDeletes.setText("Deleted Commands");
738
chudy@google.comc432f002012-07-10 13:19:25 +0000739 QIcon stepBack;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000740 stepBack.addFile(QString::fromUtf8(":/previous.png"), QSize(),
chudy@google.comc432f002012-07-10 13:19:25 +0000741 QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000742 fActionStepBack.setShortcut(QKeySequence(tr("[")));
chudy@google.comc432f002012-07-10 13:19:25 +0000743 fActionStepBack.setIcon(stepBack);
744 fActionStepBack.setText("Step Back");
chudy@google.com902ebe52012-06-29 14:21:22 +0000745
chudy@google.comc432f002012-07-10 13:19:25 +0000746 QIcon stepForward;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000747 stepForward.addFile(QString::fromUtf8(":/next.png"),
chudy@google.comc432f002012-07-10 13:19:25 +0000748 QSize(), QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000749 fActionStepForward.setShortcut(QKeySequence(tr("]")));
chudy@google.comc432f002012-07-10 13:19:25 +0000750 fActionStepForward.setIcon(stepForward);
751 fActionStepForward.setText("Step Forward");
752
chudy@google.coma1226312012-07-26 20:26:44 +0000753 fActionZoomIn.setShortcut(QKeySequence(tr("Ctrl+=")));
754 fActionZoomIn.setText("Zoom In");
755 fActionZoomOut.setShortcut(QKeySequence(tr("Ctrl+-")));
756 fActionZoomOut.setText("Zoom Out");
757
chudy@google.comc432f002012-07-10 13:19:25 +0000758 fListWidget.setItemDelegate(new SkListWidget(&fListWidget));
759 fListWidget.setObjectName(QString::fromUtf8("listWidget"));
760 fListWidget.setMaximumWidth(250);
761
762 fFilter.addItem("--Filter By Available Commands--");
763
764 fDirectoryWidget.setMaximumWidth(250);
765 fDirectoryWidget.setStyleSheet("QListWidget::Item {padding: 5px;}");
766
767 fCanvasWidget.setSizePolicy(QSizePolicy::Expanding,
chudy@google.com7dcae672012-07-09 20:26:53 +0000768 QSizePolicy::Expanding);
chudy@google.com902ebe52012-06-29 14:21:22 +0000769
skia.committer@gmail.com1c9c0d32012-11-22 02:02:41 +0000770 fImageWidget.setFixedSize(SkImageWidget::kImageWidgetWidth,
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000771 SkImageWidget::kImageWidgetHeight);
772
chudy@google.comc432f002012-07-10 13:19:25 +0000773 fInspectorWidget.setSizePolicy(QSizePolicy::Expanding,
chudy@google.com7dcae672012-07-09 20:26:53 +0000774 QSizePolicy::Expanding);
chudy@google.comc432f002012-07-10 13:19:25 +0000775 fInspectorWidget.setMaximumHeight(300);
chudy@google.com902ebe52012-06-29 14:21:22 +0000776
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000777 fSettingsAndImageLayout.setSpacing(6);
778 fSettingsAndImageLayout.addWidget(&fSettingsWidget);
779 fSettingsAndImageLayout.addWidget(&fImageWidget);
780
chudy@google.comc432f002012-07-10 13:19:25 +0000781 fSettingsWidget.setSizePolicy(QSizePolicy::Expanding,
782 QSizePolicy::Expanding);
783 fSettingsWidget.setMaximumWidth(250);
chudy@google.com902ebe52012-06-29 14:21:22 +0000784
chudy@google.comc432f002012-07-10 13:19:25 +0000785 fLeftColumnLayout.setSpacing(6);
786 fLeftColumnLayout.addWidget(&fListWidget);
787 fLeftColumnLayout.addWidget(&fDirectoryWidget);
chudy@google.com902ebe52012-06-29 14:21:22 +0000788
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000789 fCanvasSettingsAndImageLayout.setSpacing(6);
790 fCanvasSettingsAndImageLayout.addWidget(&fCanvasWidget);
791 fCanvasSettingsAndImageLayout.addLayout(&fSettingsAndImageLayout);
792
chudy@google.com902ebe52012-06-29 14:21:22 +0000793
chudy@google.comc432f002012-07-10 13:19:25 +0000794 fMainAndRightColumnLayout.setSpacing(6);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000795 fMainAndRightColumnLayout.addLayout(&fCanvasSettingsAndImageLayout);
chudy@google.comc432f002012-07-10 13:19:25 +0000796 fMainAndRightColumnLayout.addWidget(&fInspectorWidget);
chudy@google.com902ebe52012-06-29 14:21:22 +0000797
chudy@google.com2d537a12012-07-31 12:49:52 +0000798 fCentralWidget.setLayout(&fContainerLayout);
chudy@google.comc432f002012-07-10 13:19:25 +0000799 fContainerLayout.setSpacing(6);
800 fContainerLayout.setContentsMargins(11, 11, 11, 11);
801 fContainerLayout.addLayout(&fLeftColumnLayout);
802 fContainerLayout.addLayout(&fMainAndRightColumnLayout);
803
804 SkDebuggerGUI->setCentralWidget(&fCentralWidget);
805 SkDebuggerGUI->setStatusBar(&fStatusBar);
806
chudy@google.come504de02012-07-16 18:35:23 +0000807 fToolBar.setIconSize(QSize(32, 32));
chudy@google.comc432f002012-07-10 13:19:25 +0000808 fToolBar.setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
809 SkDebuggerGUI->addToolBar(Qt::TopToolBarArea, &fToolBar);
chudy@google.com902ebe52012-06-29 14:21:22 +0000810
chudy@google.com0ab03392012-07-28 20:16:11 +0000811 fSpacer.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
chudy@google.com902ebe52012-06-29 14:21:22 +0000812
chudy@google.comc432f002012-07-10 13:19:25 +0000813 fToolBar.addAction(&fActionRewind);
814 fToolBar.addAction(&fActionStepBack);
chudy@google.come504de02012-07-16 18:35:23 +0000815 fToolBar.addAction(&fActionPause);
chudy@google.comc432f002012-07-10 13:19:25 +0000816 fToolBar.addAction(&fActionStepForward);
817 fToolBar.addAction(&fActionPlay);
818 fToolBar.addSeparator();
chudy@google.come504de02012-07-16 18:35:23 +0000819 fToolBar.addAction(&fActionInspector);
chudy@google.comc432f002012-07-10 13:19:25 +0000820 fToolBar.addSeparator();
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000821 fToolBar.addAction(&fActionProfile);
822
823 fToolBar.addSeparator();
chudy@google.com0ab03392012-07-28 20:16:11 +0000824 fToolBar.addWidget(&fSpacer);
chudy@google.comc432f002012-07-10 13:19:25 +0000825 fToolBar.addWidget(&fFilter);
826 fToolBar.addAction(&fActionCancel);
chudy@google.com902ebe52012-06-29 14:21:22 +0000827
828 // TODO(chudy): Remove static call.
829 fDirectoryWidgetActive = false;
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000830 fPath = "";
831 fFileName = "";
chudy@google.com902ebe52012-06-29 14:21:22 +0000832 setupDirectoryWidget();
833 fDirectoryWidgetActive = true;
834
chudy@google.com902ebe52012-06-29 14:21:22 +0000835 // Menu Bar
chudy@google.comc432f002012-07-10 13:19:25 +0000836 fMenuFile.setTitle("File");
837 fMenuFile.addAction(&fActionOpen);
chudy@google.com0ab03392012-07-28 20:16:11 +0000838 fMenuFile.addAction(&fActionSave);
839 fMenuFile.addAction(&fActionSaveAs);
chudy@google.comc432f002012-07-10 13:19:25 +0000840 fMenuFile.addAction(&fActionClose);
chudy@google.come504de02012-07-16 18:35:23 +0000841
842 fMenuEdit.setTitle("Edit");
843 fMenuEdit.addAction(&fActionDelete);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000844 fMenuEdit.addAction(&fActionClearDeletes);
845 fMenuEdit.addSeparator();
chudy@google.come504de02012-07-16 18:35:23 +0000846 fMenuEdit.addAction(&fActionCreateBreakpoint);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000847 fMenuEdit.addAction(&fActionClearBreakpoints);
chudy@google.come504de02012-07-16 18:35:23 +0000848
chudy@google.comc432f002012-07-10 13:19:25 +0000849 fMenuNavigate.setTitle("Navigate");
chudy@google.come504de02012-07-16 18:35:23 +0000850 fMenuNavigate.addAction(&fActionRewind);
851 fMenuNavigate.addAction(&fActionStepBack);
852 fMenuNavigate.addAction(&fActionStepForward);
853 fMenuNavigate.addAction(&fActionPlay);
854 fMenuNavigate.addAction(&fActionPause);
chudy@google.comc432f002012-07-10 13:19:25 +0000855 fMenuNavigate.addAction(&fActionGoToLine);
chudy@google.come504de02012-07-16 18:35:23 +0000856
chudy@google.comc432f002012-07-10 13:19:25 +0000857 fMenuView.setTitle("View");
chudy@google.come504de02012-07-16 18:35:23 +0000858 fMenuView.addAction(&fActionBreakpoint);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000859 fMenuView.addAction(&fActionShowDeletes);
chudy@google.coma1226312012-07-26 20:26:44 +0000860 fMenuView.addAction(&fActionZoomIn);
861 fMenuView.addAction(&fActionZoomOut);
chudy@google.come504de02012-07-16 18:35:23 +0000862
863 fMenuWindows.setTitle("Window");
864 fMenuWindows.addAction(&fActionInspector);
865 fMenuWindows.addAction(&fActionDirectory);
chudy@google.comc432f002012-07-10 13:19:25 +0000866
867 fActionGoToLine.setText("Go to Line...");
868 fActionGoToLine.setDisabled(true);
869 fMenuBar.addAction(fMenuFile.menuAction());
chudy@google.come504de02012-07-16 18:35:23 +0000870 fMenuBar.addAction(fMenuEdit.menuAction());
chudy@google.comc432f002012-07-10 13:19:25 +0000871 fMenuBar.addAction(fMenuView.menuAction());
872 fMenuBar.addAction(fMenuNavigate.menuAction());
chudy@google.come504de02012-07-16 18:35:23 +0000873 fMenuBar.addAction(fMenuWindows.menuAction());
chudy@google.com902ebe52012-06-29 14:21:22 +0000874
chudy@google.com7dcae672012-07-09 20:26:53 +0000875 fPause = false;
876
chudy@google.comc432f002012-07-10 13:19:25 +0000877 SkDebuggerGUI->setMenuBar(&fMenuBar);
chudy@google.com902ebe52012-06-29 14:21:22 +0000878 QMetaObject::connectSlotsByName(SkDebuggerGUI);
879}
880
881void SkDebuggerGUI::setupDirectoryWidget() {
chudy@google.comc432f002012-07-10 13:19:25 +0000882 QDir dir(fPath);
chudy@google.com902ebe52012-06-29 14:21:22 +0000883 QRegExp r(".skp");
chudy@google.comc432f002012-07-10 13:19:25 +0000884 fDirectoryWidget.clear();
885 const QStringList files = dir.entryList();
chudy@google.com902ebe52012-06-29 14:21:22 +0000886 foreach (QString f, files) {
chudy@google.com7dcae672012-07-09 20:26:53 +0000887 if (f.contains(r))
chudy@google.comc432f002012-07-10 13:19:25 +0000888 fDirectoryWidget.addItem(f);
chudy@google.com902ebe52012-06-29 14:21:22 +0000889 }
890}
891
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000892// SkOffsetPicturePlayback records the offset of each command in the picture.
893// These are needed by the profiling system.
894class SkOffsetPicturePlayback : public SkPicturePlayback {
895public:
896 SkOffsetPicturePlayback(SkStream* stream, const SkPictInfo& info, bool* isValid,
897 SkSerializationHelpers::DecodeBitmap decoder)
898 : INHERITED(stream, info, isValid, decoder) {
899 }
900
901 const SkTDArray<size_t>& offsets() const { return fOffsets; }
902
903protected:
904 SkTDArray<size_t> fOffsets;
905
robertphillips@google.comca47aae2012-12-12 15:58:25 +0000906 virtual size_t preDraw(size_t offset, int type) {
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000907 *fOffsets.append() = offset;
robertphillips@google.com5f971142012-12-07 20:48:56 +0000908 return 0;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000909 }
910
911private:
912 typedef SkPicturePlayback INHERITED;
913};
914
915// Picture to wrap an SkOffsetPicturePlayback.
916class SkOffsetPicture : public SkPicture {
917public:
skia.committer@gmail.com884e60b2012-11-16 02:01:17 +0000918 SkOffsetPicture(SkStream* stream,
919 bool* success,
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000920 SkSerializationHelpers::DecodeBitmap decoder) {
921 if (success) {
922 *success = false;
923 }
924 fRecord = NULL;
925 fPlayback = NULL;
926 fWidth = fHeight = 0;
927
928 SkPictInfo info;
929
930 if (!stream->read(&info, sizeof(info))) {
931 return;
932 }
933 if (PICTURE_VERSION != info.fVersion) {
934 return;
935 }
936
937 if (stream->readBool()) {
938 bool isValid = false;
939 fPlayback = SkNEW_ARGS(SkOffsetPicturePlayback, (stream, info, &isValid, decoder));
940 if (!isValid) {
941 SkDELETE(fPlayback);
942 fPlayback = NULL;
943 return;
944 }
945 }
946
947 // do this at the end, so that they will be zero if we hit an error.
948 fWidth = info.fWidth;
949 fHeight = info.fHeight;
950 if (success) {
951 *success = true;
952 }
953 }
954
skia.committer@gmail.com884e60b2012-11-16 02:01:17 +0000955 const SkTDArray<size_t>& offsets() const {
956 return ((SkOffsetPicturePlayback*) fPlayback)->offsets();
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000957 }
958
959private:
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000960 // disallow default ctor b.c. we don't have a good way to setup the fPlayback ptr
961 SkOffsetPicture();
962 // disallow the copy ctor - enabling would require copying code from SkPicture
963 SkOffsetPicture(const SkOffsetPicture& src);
964
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000965 typedef SkPicture INHERITED;
966};
967
968
969
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000970void SkDebuggerGUI::loadPicture(const SkString& fileName) {
971 fFileName = fileName;
chudy@google.comd3058f52012-07-19 13:41:27 +0000972 fLoading = true;
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000973 SkStream* stream = SkNEW_ARGS(SkFILEStream, (fileName.c_str()));
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000974 SkOffsetPicture* picture = SkNEW_ARGS(SkOffsetPicture, (stream, NULL, &SkImageDecoder::DecodeStream));
975
chudy@google.com686e6802012-08-14 16:00:32 +0000976 fCanvasWidget.resetWidgetTransform();
chudy@google.com607357f2012-08-07 16:12:23 +0000977 fDebugger.loadPicture(picture);
chudy@google.com4c7962e2012-08-14 19:38:31 +0000978
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000979 fOffsets = picture->offsets();
980
robertphillips@google.com5f971142012-12-07 20:48:56 +0000981 fSkipCommands.setCount(fOffsets.count());
982 for (int i = 0; i < fOffsets.count(); ++i) {
983 fSkipCommands[i] = false;
984 }
985
chudy@google.com607357f2012-08-07 16:12:23 +0000986 SkSafeUnref(stream);
987 SkSafeUnref(picture);
988
chudy@google.com97cee972012-08-07 20:41:37 +0000989 // Will this automatically clear out due to nature of refcnt?
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000990 SkTArray<SkString>* commands = fDebugger.getDrawCommandsAsStrings();
chudy@google.com607357f2012-08-07 16:12:23 +0000991
robertphillips@google.comfe830a42012-11-15 16:33:31 +0000992 // If SkPicturePlayback is compiled w/o SK_PICTURE_PROFILING_STUBS
993 // the offset count will always be zero
994 SkASSERT(0 == fOffsets.count() || commands->count() == fOffsets.count());
robertphillips@google.come099bc42012-11-19 16:26:40 +0000995 if (commands->count() == fOffsets.count()) {
996 fActionProfile.setDisabled(false);
robertphillips@google.comfe830a42012-11-15 16:33:31 +0000997 }
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000998
chudy@google.com7dcae672012-07-09 20:26:53 +0000999 /* fDebugCanvas is reinitialized every load picture. Need it to retain value
chudy@google.com607357f2012-08-07 16:12:23 +00001000 * of the visibility filter.
1001 * TODO(chudy): This should be deprecated since fDebugger is not
1002 * recreated.
1003 * */
1004 fDebugger.highlightCurrentCommand(fSettingsWidget.getVisibilityButton()->isChecked());
1005
chudy@google.com97cee972012-08-07 20:41:37 +00001006 setupListWidget(commands);
1007 setupComboBox(commands);
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +00001008 setupOverviewText(NULL, 0.0);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +00001009 fInspectorWidget.setDisabled(false);
chudy@google.come606d6e2012-07-12 14:31:25 +00001010 fSettingsWidget.setDisabled(false);
chudy@google.comd3058f52012-07-19 13:41:27 +00001011 fMenuEdit.setDisabled(false);
1012 fMenuNavigate.setDisabled(false);
1013 fMenuView.setDisabled(false);
chudy@google.com0ab03392012-07-28 20:16:11 +00001014 fActionSave.setDisabled(false);
1015 fActionSaveAs.setDisabled(false);
chudy@google.comd3058f52012-07-19 13:41:27 +00001016 fLoading = false;
1017 actionPlay();
chudy@google.com902ebe52012-06-29 14:21:22 +00001018}
1019
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +00001020void SkDebuggerGUI::setupListWidget(SkTArray<SkString>* command) {
chudy@google.comc432f002012-07-10 13:19:25 +00001021 fListWidget.clear();
chudy@google.com902ebe52012-06-29 14:21:22 +00001022 int counter = 0;
robertphillips@google.com30d35f22012-11-06 16:45:36 +00001023 int indent = 0;
chudy@google.com97cee972012-08-07 20:41:37 +00001024 for (int i = 0; i < command->count(); i++) {
chudy@google.com902ebe52012-06-29 14:21:22 +00001025 QListWidgetItem *item = new QListWidgetItem();
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +00001026 item->setData(Qt::DisplayRole, (*command)[i].c_str());
chudy@google.com902ebe52012-06-29 14:21:22 +00001027 item->setData(Qt::UserRole + 1, counter++);
robertphillips@google.com30d35f22012-11-06 16:45:36 +00001028
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +00001029 if (0 == strcmp("Restore", (*command)[i].c_str())) {
robertphillips@google.com30d35f22012-11-06 16:45:36 +00001030 indent -= 10;
1031 }
1032
1033 item->setData(Qt::UserRole + 3, indent);
1034
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +00001035 if (0 == strcmp("Save", (*command)[i].c_str()) ||
1036 0 == strcmp("Save Layer", (*command)[i].c_str())) {
robertphillips@google.com30d35f22012-11-06 16:45:36 +00001037 indent += 10;
1038 }
1039
robertphillips@google.comd26c7062012-11-12 20:42:12 +00001040 item->setData(Qt::UserRole + 4, -1.0);
1041
chudy@google.comc432f002012-07-10 13:19:25 +00001042 fListWidget.addItem(item);
chudy@google.com902ebe52012-06-29 14:21:22 +00001043 }
1044}
1045
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +00001046void SkDebuggerGUI::setupOverviewText(const SkTDArray<double>* typeTimes, double totTime) {
chudy@google.com902ebe52012-06-29 14:21:22 +00001047
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +00001048 const SkTDArray<SkDrawCommand*>& commands = fDebugger.getDrawCommands();
1049
1050 SkTDArray<int> counts;
1051 counts.setCount(LAST_DRAWTYPE_ENUM+1);
1052 for (int i = 0; i < LAST_DRAWTYPE_ENUM+1; ++i) {
1053 counts[i] = 0;
1054 }
1055
1056 for (int i = 0; i < commands.count(); i++) {
1057 counts[commands[i]->getType()]++;
chudy@google.com902ebe52012-06-29 14:21:22 +00001058 }
1059
1060 QString overview;
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +00001061 int total = 0;
1062#ifdef SK_DEBUG
1063 double totPercent = 0, tempSum = 0;
1064#endif
1065 for (int i = 0; i < LAST_DRAWTYPE_ENUM+1; ++i) {
1066 if (0 == counts[i]) {
1067 // if there were no commands of this type then they should've consumed no time
1068 SkASSERT(NULL == typeTimes || 0.0 == (*typeTimes)[i]);
1069 continue;
1070 }
1071
1072 overview.append(SkDrawCommand::GetCommandString((DrawType) i));
chudy@google.com902ebe52012-06-29 14:21:22 +00001073 overview.append(": ");
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +00001074 overview.append(QString::number(counts[i]));
1075 if (NULL != typeTimes) {
1076 overview.append(" - ");
1077 overview.append(QString::number((*typeTimes)[i], 'f', 1));
1078 overview.append("ms");
1079 overview.append(" - ");
1080 double percent = 100.0*(*typeTimes)[i]/totTime;
1081 overview.append(QString::number(percent, 'f', 1));
1082 overview.append("%");
1083#ifdef SK_DEBUG
1084 totPercent += percent;
1085 tempSum += (*typeTimes)[i];
1086#endif
1087 }
chudy@google.com902ebe52012-06-29 14:21:22 +00001088 overview.append("<br/>");
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +00001089 total += counts[i];
chudy@google.com902ebe52012-06-29 14:21:22 +00001090 }
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +00001091#ifdef SK_DEBUG
1092 if (NULL != typeTimes) {
1093 SkASSERT(SkScalarNearlyEqual(totPercent, 100.0));
1094 SkASSERT(SkScalarNearlyEqual(tempSum, totTime));
1095 }
1096#endif
1097
1098 if (totTime > 0.0) {
1099 overview.append("Total Time: ");
1100 overview.append(QString::number(totTime, 'f', 2));
1101 overview.append("ms");
1102#ifdef SK_DEBUG
1103 overview.append(" ");
1104 overview.append(QString::number(totPercent));
1105 overview.append("% ");
1106#endif
1107 overview.append("<br/>");
1108 }
1109
1110 QString totalStr;
1111 totalStr.append("Total Draw Commands: ");
1112 totalStr.append(QString::number(total));
1113 totalStr.append("<br/>");
1114 overview.insert(0, totalStr);
chudy@google.com902ebe52012-06-29 14:21:22 +00001115
1116 overview.append("<br/>");
chudy@google.com607357f2012-08-07 16:12:23 +00001117 overview.append("SkPicture Width: ");
chudy@google.com902ebe52012-06-29 14:21:22 +00001118 // NOTE(chudy): This is where we can pull out the SkPictures width.
chudy@google.com607357f2012-08-07 16:12:23 +00001119 overview.append(QString::number(fDebugger.pictureWidth()));
chudy@google.com902ebe52012-06-29 14:21:22 +00001120 overview.append("px<br/>");
chudy@google.com607357f2012-08-07 16:12:23 +00001121 overview.append("SkPicture Height: ");
1122 overview.append(QString::number(fDebugger.pictureHeight()));
chudy@google.com902ebe52012-06-29 14:21:22 +00001123 overview.append("px");
chudy@google.com6bd109a2012-08-14 19:34:13 +00001124 fInspectorWidget.setText(overview, SkInspectorWidget::kOverview_TabType);
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +00001125}
1126
1127void SkDebuggerGUI::setupComboBox(SkTArray<SkString>* command) {
1128 fFilter.clear();
1129 fFilter.addItem("--Filter By Available Commands--");
1130
1131 std::map<std::string, int> map;
1132 for (int i = 0; i < command->count(); i++) {
1133 map[(*command)[i].c_str()]++;
1134 }
1135
skia.committer@gmail.com34587162012-11-20 02:01:23 +00001136 for (std::map<std::string, int>::iterator it = map.begin(); it != map.end();
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +00001137 ++it) {
1138 fFilter.addItem((it->first).c_str());
1139 }
chudy@google.com902ebe52012-06-29 14:21:22 +00001140
1141 // NOTE(chudy): Makes first item unselectable.
chudy@google.com7dcae672012-07-09 20:26:53 +00001142 QStandardItemModel* model = qobject_cast<QStandardItemModel*>(
chudy@google.comc432f002012-07-10 13:19:25 +00001143 fFilter.model());
1144 QModelIndex firstIndex = model->index(0, fFilter.modelColumn(),
1145 fFilter.rootModelIndex());
chudy@google.com902ebe52012-06-29 14:21:22 +00001146 QStandardItem* firstItem = model->itemFromIndex(firstIndex);
1147 firstItem->setSelectable(false);
1148}