blob: 4486434e669109edfff02b7a6ba0c6ca61614821 [file] [log] [blame]
chudy@google.com902ebe52012-06-29 14:21:22 +00001/*
2 * Copyright 2012 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
chudy@google.com902ebe52012-06-29 14:21:22 +00008#include "SkDebuggerGUI.h"
chudy@google.combbad34d2012-08-13 14:26:36 +00009#include "SkGraphics.h"
scroggo@google.comb4467e62012-11-06 23:10:09 +000010#include "SkImageDecoder.h"
chudy@google.com902ebe52012-06-29 14:21:22 +000011#include <QListWidgetItem>
robertphillips@google.com2bde91d2012-11-15 14:57:57 +000012#include "PictureRenderer.h"
robertphillips@google.com2bde91d2012-11-15 14:57:57 +000013#include "SkPictureRecord.h"
14#include "SkPicturePlayback.h"
robertphillips@google.come174a8b2012-11-27 16:04:42 +000015
16#if defined(SK_BUILD_FOR_WIN32)
17 #include "BenchSysTimer_windows.h"
18#elif defined(SK_BUILD_FOR_MAC)
19 #include "BenchSysTimer_mach.h"
20#elif defined(SK_BUILD_FOR_UNIX) || defined(SK_BUILD_FOR_ANDROID)
21 #include "BenchSysTimer_posix.h"
22#else
23 #include "BenchSysTimer_c.h"
24#endif
25
chudy@google.com902ebe52012-06-29 14:21:22 +000026
27SkDebuggerGUI::SkDebuggerGUI(QWidget *parent) :
chudy@google.comc432f002012-07-10 13:19:25 +000028 QMainWindow(parent)
chudy@google.com2d537a12012-07-31 12:49:52 +000029 , fCentralWidget(this)
30 , fStatusBar(this)
31 , fToolBar(this)
chudy@google.comc432f002012-07-10 13:19:25 +000032 , fActionOpen(this)
33 , fActionBreakpoint(this)
robertphillips@google.comd26c7062012-11-12 20:42:12 +000034 , fActionProfile(this)
chudy@google.comc432f002012-07-10 13:19:25 +000035 , fActionCancel(this)
chudy@google.com7e4cfbf2012-07-17 15:40:51 +000036 , fActionClearBreakpoints(this)
chudy@google.come504de02012-07-16 18:35:23 +000037 , fActionClearDeletes(this)
chudy@google.comc432f002012-07-10 13:19:25 +000038 , fActionClose(this)
chudy@google.come504de02012-07-16 18:35:23 +000039 , fActionCreateBreakpoint(this)
chudy@google.comc432f002012-07-10 13:19:25 +000040 , fActionDelete(this)
41 , fActionDirectory(this)
42 , fActionGoToLine(this)
43 , fActionInspector(this)
44 , fActionPlay(this)
chudy@google.come504de02012-07-16 18:35:23 +000045 , fActionPause(this)
chudy@google.comc432f002012-07-10 13:19:25 +000046 , fActionRewind(this)
chudy@google.com0ab03392012-07-28 20:16:11 +000047 , fActionSave(this)
48 , fActionSaveAs(this)
chudy@google.com7e4cfbf2012-07-17 15:40:51 +000049 , fActionShowDeletes(this)
chudy@google.comc432f002012-07-10 13:19:25 +000050 , fActionStepBack(this)
51 , fActionStepForward(this)
chudy@google.coma1226312012-07-26 20:26:44 +000052 , fActionZoomIn(this)
53 , fActionZoomOut(this)
54 , fMapper(this)
chudy@google.comc432f002012-07-10 13:19:25 +000055 , fListWidget(&fCentralWidget)
56 , fDirectoryWidget(&fCentralWidget)
chudy@google.com607357f2012-08-07 16:12:23 +000057 , fCanvasWidget(this, &fDebugger)
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +000058 , fImageWidget(&fDebugger)
chudy@google.comc432f002012-07-10 13:19:25 +000059 , fMenuBar(this)
60 , fMenuFile(this)
61 , fMenuNavigate(this)
62 , fMenuView(this)
chudy@google.com7e4cfbf2012-07-17 15:40:51 +000063 , fBreakpointsActivated(false)
64 , fDeletesActivated(false)
65 , fPause(false)
chudy@google.comd3058f52012-07-19 13:41:27 +000066 , fLoading(false)
chudy@google.comc432f002012-07-10 13:19:25 +000067{
chudy@google.com902ebe52012-06-29 14:21:22 +000068 setupUi(this);
robertphillips@google.comdd4b7452013-01-22 19:38:46 +000069 fListWidget.setSelectionMode(QAbstractItemView::ExtendedSelection);
chudy@google.comea5488b2012-07-26 19:38:22 +000070 connect(&fListWidget, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)), this, SLOT(registerListClick(QListWidgetItem *)));
chudy@google.comc432f002012-07-10 13:19:25 +000071 connect(&fActionOpen, SIGNAL(triggered()), this, SLOT(openFile()));
chudy@google.comea5488b2012-07-26 19:38:22 +000072 connect(&fActionDirectory, SIGNAL(triggered()), this, SLOT(toggleDirectory()));
73 connect(&fDirectoryWidget, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)), this, SLOT(loadFile(QListWidgetItem *)));
chudy@google.comc432f002012-07-10 13:19:25 +000074 connect(&fActionDelete, SIGNAL(triggered()), this, SLOT(actionDelete()));
chudy@google.comea5488b2012-07-26 19:38:22 +000075 connect(&fListWidget, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(toggleBreakpoint()));
chudy@google.comc432f002012-07-10 13:19:25 +000076 connect(&fActionRewind, SIGNAL(triggered()), this, SLOT(actionRewind()));
77 connect(&fActionPlay, SIGNAL(triggered()), this, SLOT(actionPlay()));
78 connect(&fActionStepBack, SIGNAL(triggered()), this, SLOT(actionStepBack()));
chudy@google.comea5488b2012-07-26 19:38:22 +000079 connect(&fActionStepForward, SIGNAL(triggered()), this, SLOT(actionStepForward()));
80 connect(&fActionBreakpoint, SIGNAL(triggered()), this, SLOT(actionBreakpoints()));
81 connect(&fActionInspector, SIGNAL(triggered()), this, SLOT(actionInspector()));
82 connect(&fActionInspector, SIGNAL(triggered()), this, SLOT(actionSettings()));
83 connect(&fFilter, SIGNAL(activated(QString)), this, SLOT(toggleFilter(QString)));
robertphillips@google.comd26c7062012-11-12 20:42:12 +000084 connect(&fActionProfile, SIGNAL(triggered()), this, SLOT(actionProfile()));
chudy@google.comc432f002012-07-10 13:19:25 +000085 connect(&fActionCancel, SIGNAL(triggered()), this, SLOT(actionCancel()));
chudy@google.com7e4cfbf2012-07-17 15:40:51 +000086 connect(&fActionClearBreakpoints, SIGNAL(triggered()), this, SLOT(actionClearBreakpoints()));
87 connect(&fActionClearDeletes, SIGNAL(triggered()), this, SLOT(actionClearDeletes()));
chudy@google.comc432f002012-07-10 13:19:25 +000088 connect(&fActionClose, SIGNAL(triggered()), this, SLOT(actionClose()));
chudy@google.comea5488b2012-07-26 19:38:22 +000089 connect(fSettingsWidget.getVisibilityButton(), SIGNAL(toggled(bool)), this, SLOT(actionCommandFilter()));
90 connect(fSettingsWidget.getGLCheckBox(), SIGNAL(toggled(bool)), this, SLOT(actionGLWidget(bool)));
91 connect(fSettingsWidget.getRasterCheckBox(), SIGNAL(toggled(bool)), this, SLOT(actionRasterWidget(bool)));
92 connect(&fActionPause, SIGNAL(toggled(bool)), this, SLOT(pauseDrawing(bool)));
chudy@google.come504de02012-07-16 18:35:23 +000093 connect(&fActionCreateBreakpoint, SIGNAL(activated()), this, SLOT(toggleBreakpoint()));
chudy@google.com7e4cfbf2012-07-17 15:40:51 +000094 connect(&fActionShowDeletes, SIGNAL(triggered()), this, SLOT(showDeletes()));
chudy@google.comea5488b2012-07-26 19:38:22 +000095 connect(&fCanvasWidget, SIGNAL(hitChanged(int)), this, SLOT(selectCommand(int)));
96 connect(&fCanvasWidget, SIGNAL(hitChanged(int)), &fSettingsWidget, SLOT(updateHit(int)));
97 connect(&fCanvasWidget, SIGNAL(scaleFactorChanged(float)), this, SLOT(actionScale(float)));
98 connect(&fCanvasWidget, SIGNAL(commandChanged(int)), &fSettingsWidget, SLOT(updateCommand(int)));
chudy@google.com0ab03392012-07-28 20:16:11 +000099 connect(&fActionSaveAs, SIGNAL(triggered()), this, SLOT(actionSaveAs()));
100 connect(&fActionSave, SIGNAL(triggered()), this, SLOT(actionSave()));
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000101
bungeman@google.come8cc6e82013-01-17 16:30:56 +0000102 fMapper.setMapping(&fActionZoomIn, SkCanvasWidget::kIn_ZoomCommand);
103 fMapper.setMapping(&fActionZoomOut, SkCanvasWidget::kOut_ZoomCommand);
chudy@google.coma1226312012-07-26 20:26:44 +0000104
105 connect(&fActionZoomIn, SIGNAL(triggered()), &fMapper, SLOT(map()));
106 connect(&fActionZoomOut, SIGNAL(triggered()), &fMapper, SLOT(map()));
bungeman@google.come8cc6e82013-01-17 16:30:56 +0000107 connect(&fMapper, SIGNAL(mapped(int)), &fCanvasWidget, SLOT(zoom(int)));
chudy@google.coma1226312012-07-26 20:26:44 +0000108
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000109 fInspectorWidget.setDisabled(true);
chudy@google.comd3058f52012-07-19 13:41:27 +0000110 fMenuEdit.setDisabled(true);
111 fMenuNavigate.setDisabled(true);
112 fMenuView.setDisabled(true);
chudy@google.combbad34d2012-08-13 14:26:36 +0000113
114 SkGraphics::Init();
chudy@google.com902ebe52012-06-29 14:21:22 +0000115}
116
chudy@google.combbad34d2012-08-13 14:26:36 +0000117SkDebuggerGUI::~SkDebuggerGUI() {
118 SkGraphics::Term();
119}
chudy@google.com902ebe52012-06-29 14:21:22 +0000120
121void SkDebuggerGUI::actionBreakpoints() {
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000122 fBreakpointsActivated = !fBreakpointsActivated;
chudy@google.comc432f002012-07-10 13:19:25 +0000123 for (int row = 0; row < fListWidget.count(); row++) {
124 QListWidgetItem *item = fListWidget.item(row);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000125 item->setHidden(item->checkState() == Qt::Unchecked && fBreakpointsActivated);
126 }
127}
chudy@google.com902ebe52012-06-29 14:21:22 +0000128
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000129void SkDebuggerGUI::showDeletes() {
130 fDeletesActivated = !fDeletesActivated;
131 for (int row = 0; row < fListWidget.count(); row++) {
132 QListWidgetItem *item = fListWidget.item(row);
chudy@google.com607357f2012-08-07 16:12:23 +0000133 item->setHidden(fDebugger.isCommandVisible(row)
134 && fDeletesActivated);
chudy@google.com902ebe52012-06-29 14:21:22 +0000135 }
136}
137
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000138// The timed picture playback uses the SkPicturePlayback's profiling stubs
139// to time individual commands. The offsets are needed to map SkPicture
140// offsets to individual commands.
141class SkTimedPicturePlayback : public SkPicturePlayback {
142public:
143 SkTimedPicturePlayback(SkStream* stream, const SkPictInfo& info, bool* isValid,
144 SkSerializationHelpers::DecodeBitmap decoder,
robertphillips@google.com5f971142012-12-07 20:48:56 +0000145 const SkTDArray<size_t>& offsets,
146 const SkTDArray<bool>& deletedCommands)
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000147 : INHERITED(stream, info, isValid, decoder)
robertphillips@google.com5f971142012-12-07 20:48:56 +0000148 , fOffsets(offsets)
bungeman@google.come8cc6e82013-01-17 16:30:56 +0000149 , fSkipCommands(deletedCommands)
150 , fTot(0.0)
151 , fCurCommand(0) {
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000152 fTimes.setCount(fOffsets.count());
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000153 fTypeTimes.setCount(LAST_DRAWTYPE_ENUM+1);
154 this->resetTimes();
155 }
156
157 void resetTimes() {
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000158 for (int i = 0; i < fOffsets.count(); ++i) {
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000159 fTimes[i] = 0.0;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000160 }
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000161 for (int i = 0; i < fTypeTimes.count(); ++i) {
162 fTypeTimes[i] = 0.0f;
163 }
164 fTot = 0.0;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000165 }
166
167 int count() const { return fTimes.count(); }
168
169 double time(int index) const { return fTimes[index] / fTot; }
170
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000171 const SkTDArray<double>* typeTimes() const { return &fTypeTimes; }
172
173 double totTime() const { return fTot; }
174
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000175protected:
robertphillips@google.come174a8b2012-11-27 16:04:42 +0000176 BenchSysTimer fTimer;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000177 SkTDArray<size_t> fOffsets; // offset in the SkPicture for each command
robertphillips@google.com5f971142012-12-07 20:48:56 +0000178 SkTDArray<bool> fSkipCommands; // has the command been deleted in the GUI?
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000179 SkTDArray<double> fTimes; // sum of time consumed for each command
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000180 SkTDArray<double> fTypeTimes; // sum of time consumed for each type of command (e.g., drawPath)
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000181 double fTot; // total of all times in 'fTimes'
182 size_t fCurOffset;
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000183 int fCurType;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000184 int fCurCommand; // the current command being executed/timed
185
robertphillips@google.comca47aae2012-12-12 15:58:25 +0000186 virtual size_t preDraw(size_t offset, int type) {
skia.committer@gmail.com884e60b2012-11-16 02:01:17 +0000187 // This search isn't as bad as it seems. In normal playback mode, the
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000188 // base class steps through the commands in order and can only skip ahead
skia.committer@gmail.com884e60b2012-11-16 02:01:17 +0000189 // a bit on a clip. This class is only used during profiling so we
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000190 // don't have to worry about forward/backward scrubbing through commands.
191 for (int i = 0; offset != fOffsets[fCurCommand]; ++i) {
192 fCurCommand = (fCurCommand+1) % fOffsets.count();
193 SkASSERT(i <= fOffsets.count()); // should always find the offset in the list
194 }
195
robertphillips@google.com5f971142012-12-07 20:48:56 +0000196 if (fSkipCommands[fCurCommand]) {
197 while (fCurCommand < fSkipCommands.count() && fSkipCommands[fCurCommand]) {
198 ++fCurCommand;
199 }
200 if (fCurCommand == fSkipCommands.count()) {
201 // Signal SkPicturePlayback to stop playing back
202 return SK_MaxU32;
203 }
204 return fOffsets[fCurCommand];
205 }
206
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000207 fCurOffset = offset;
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000208 fCurType = type;
209 // The SkDebugCanvas doesn't recognize these types. This class needs to
210 // convert or else we'll wind up with a mismatch between the type counts
211 // the debugger displays and the profile times.
212 if (DRAW_POS_TEXT_TOP_BOTTOM == type) {
213 fCurType = DRAW_POS_TEXT;
214 } else if (DRAW_POS_TEXT_H_TOP_BOTTOM == type) {
215 fCurType = DRAW_POS_TEXT_H;
216 }
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000217
robertphillips@google.come174a8b2012-11-27 16:04:42 +0000218#if defined(SK_BUILD_FOR_WIN32)
219 // CPU timer doesn't work well on Windows
220 fTimer.startWall();
221#else
222 fTimer.startCpu();
223#endif
robertphillips@google.com5f971142012-12-07 20:48:56 +0000224
225 return 0;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000226 }
227
robertphillips@google.comca47aae2012-12-12 15:58:25 +0000228 virtual void postDraw(size_t offset) {
robertphillips@google.come174a8b2012-11-27 16:04:42 +0000229#if defined(SK_BUILD_FOR_WIN32)
230 // CPU timer doesn't work well on Windows
231 double time = fTimer.endWall();
232#else
233 double time = fTimer.endCpu();
234#endif
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000235
236 SkASSERT(offset == fCurOffset);
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000237 SkASSERT(fCurType <= LAST_DRAWTYPE_ENUM);
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000238
robertphillips@google.come174a8b2012-11-27 16:04:42 +0000239 fTimes[fCurCommand] += time;
240 fTypeTimes[fCurType] += time;
241 fTot += time;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000242 }
243
244private:
245 typedef SkPicturePlayback INHERITED;
246};
247
248// Wrap SkPicture to allow installation of an SkTimedPicturePlayback object
249class SkTimedPicture : public SkPicture {
250public:
251 explicit SkTimedPicture(SkStream* stream,
252 bool* success,
253 SkSerializationHelpers::DecodeBitmap decoder,
robertphillips@google.com5f971142012-12-07 20:48:56 +0000254 const SkTDArray<size_t>& offsets,
255 const SkTDArray<bool>& deletedCommands) {
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000256 if (success) {
257 *success = false;
258 }
259 fRecord = NULL;
260 fPlayback = NULL;
261 fWidth = fHeight = 0;
262
263 SkPictInfo info;
264
265 if (!stream->read(&info, sizeof(info))) {
266 return;
267 }
268 if (SkPicture::PICTURE_VERSION != info.fVersion) {
269 return;
270 }
271
272 if (stream->readBool()) {
273 bool isValid = false;
skia.committer@gmail.com884e60b2012-11-16 02:01:17 +0000274 fPlayback = SkNEW_ARGS(SkTimedPicturePlayback,
robertphillips@google.com5f971142012-12-07 20:48:56 +0000275 (stream, info, &isValid, decoder, offsets, deletedCommands));
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000276 if (!isValid) {
277 SkDELETE(fPlayback);
278 fPlayback = NULL;
279 return;
280 }
281 }
282
283 // do this at the end, so that they will be zero if we hit an error.
284 fWidth = info.fWidth;
285 fHeight = info.fHeight;
286 if (success) {
287 *success = true;
288 }
289 }
290
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000291 void resetTimes() { ((SkTimedPicturePlayback*) fPlayback)->resetTimes(); }
292
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000293 int count() const { return ((SkTimedPicturePlayback*) fPlayback)->count(); }
294
295 // return the fraction of the total time this command consumed
296 double time(int index) const { return ((SkTimedPicturePlayback*) fPlayback)->time(index); }
297
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000298 const SkTDArray<double>* typeTimes() const { return ((SkTimedPicturePlayback*) fPlayback)->typeTimes(); }
299
300 double totTime() const { return ((SkTimedPicturePlayback*) fPlayback)->totTime(); }
301
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000302private:
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000303 // disallow default ctor b.c. we don't have a good way to setup the fPlayback ptr
304 SkTimedPicture();
305 // disallow the copy ctor - enabling would require copying code from SkPicture
306 SkTimedPicture(const SkTimedPicture& src);
307
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000308 typedef SkPicture INHERITED;
309};
310
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000311// This is a simplification of PictureBenchmark's run with the addition of
312// clearing of the times after the first pass (in resetTimes)
skia.committer@gmail.com34587162012-11-20 02:01:23 +0000313void SkDebuggerGUI::run(SkTimedPicture* pict,
314 sk_tools::PictureRenderer* renderer,
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000315 int repeats) {
316 SkASSERT(pict);
317 if (NULL == pict) {
318 return;
319 }
320
321 SkASSERT(renderer != NULL);
322 if (NULL == renderer) {
323 return;
324 }
325
326 renderer->init(pict);
327
328 renderer->setup();
329 renderer->render(NULL);
330 renderer->resetState();
331
332 // We throw this away the first batch of times to remove first time effects (such as paging in this program)
333 pict->resetTimes();
334
335 for (int i = 0; i < repeats; ++i) {
336 renderer->setup();
337 renderer->render(NULL);
338 renderer->resetState();
339 }
340
341 renderer->end();
342}
343
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000344void SkDebuggerGUI::actionProfile() {
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000345 // In order to profile we pass the command offsets (that were read-in
346 // in loadPicture by the SkOffsetPicture) to an SkTimedPlaybackPicture.
skia.committer@gmail.com884e60b2012-11-16 02:01:17 +0000347 // The SkTimedPlaybackPicture in turn passes the offsets to an
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000348 // SkTimedPicturePlayback object which uses them to track the performance
349 // of individual commands.
350 if (fFileName.isEmpty()) {
351 return;
352 }
353
354 SkFILEStream inputStream;
355
356 inputStream.setPath(fFileName.c_str());
357 if (!inputStream.isValid()) {
358 return;
359 }
360
361 bool success = false;
skia.committer@gmail.comc1f224a2012-12-08 02:01:38 +0000362 SkTimedPicture picture(&inputStream, &success, &SkImageDecoder::DecodeStream,
robertphillips@google.com5f971142012-12-07 20:48:56 +0000363 fOffsets, fSkipCommands);
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000364 if (!success) {
365 return;
366 }
367
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000368 // For now this #if allows switching between tiled and simple rendering
369 // modes. Eventually this will be accomplished via the GUI
robertphillips@google.come174a8b2012-11-27 16:04:42 +0000370#if 0
371 // With the current batch of SysTimers, profiling in tiled mode
372 // gets swamped by the timing overhead:
373 //
374 // tile mode simple mode
375 // debugger 64.2ms 12.8ms
376 // bench_pictures 16.9ms 12.4ms
377 //
378 // This is b.c. in tiled mode each command is called many more times
379 // but typically does less work on each invocation (due to clipping)
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000380 sk_tools::TiledPictureRenderer* renderer = NULL;
381
382 renderer = SkNEW(sk_tools::TiledPictureRenderer);
383 renderer->setTileWidth(256);
384 renderer->setTileHeight(256);
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000385#else
386 sk_tools::SimplePictureRenderer* renderer = NULL;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000387
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000388 renderer = SkNEW(sk_tools::SimplePictureRenderer);
389#endif
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000390
robertphillips@google.come174a8b2012-11-27 16:04:42 +0000391 static const int kNumRepeats = 10;
392
393 run(&picture, renderer, kNumRepeats);
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000394
395 SkASSERT(picture.count() == fListWidget.count());
396
397 // extract the individual command times from the SkTimedPlaybackPicture
398 for (int i = 0; i < picture.count(); ++i) {
399 double temp = picture.time(i);
400
401 QListWidgetItem* item = fListWidget.item(i);
402
403 item->setData(Qt::UserRole + 4, 100.0*temp);
404 }
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000405
406 setupOverviewText(picture.typeTimes(), picture.totTime());
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000407}
408
chudy@google.com902ebe52012-06-29 14:21:22 +0000409void SkDebuggerGUI::actionCancel() {
chudy@google.comc432f002012-07-10 13:19:25 +0000410 for (int row = 0; row < fListWidget.count(); row++) {
411 fListWidget.item(row)->setHidden(false);
chudy@google.com902ebe52012-06-29 14:21:22 +0000412 }
413}
414
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000415void SkDebuggerGUI::actionClearBreakpoints() {
416 for (int row = 0; row < fListWidget.count(); row++) {
417 QListWidgetItem* item = fListWidget.item(row);
418 item->setCheckState(Qt::Unchecked);
419 item->setData(Qt::DecorationRole,
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000420 QPixmap(":/blank.png"));
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000421 }
422}
423
424void SkDebuggerGUI::actionClearDeletes() {
425 for (int row = 0; row < fListWidget.count(); row++) {
426 QListWidgetItem* item = fListWidget.item(row);
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000427 item->setData(Qt::UserRole + 2, QPixmap(":/blank.png"));
chudy@google.com607357f2012-08-07 16:12:23 +0000428 fDebugger.setCommandVisible(row, true);
robertphillips@google.com5f971142012-12-07 20:48:56 +0000429 fSkipCommands[row] = false;
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000430 }
431 if (fPause) {
432 fCanvasWidget.drawTo(fPausedRow);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000433 fImageWidget.draw();
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000434 } else {
435 fCanvasWidget.drawTo(fListWidget.currentRow());
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000436 fImageWidget.draw();
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000437 }
438}
439
chudy@google.com902ebe52012-06-29 14:21:22 +0000440void SkDebuggerGUI::actionCommandFilter() {
chudy@google.com607357f2012-08-07 16:12:23 +0000441 fDebugger.highlightCurrentCommand(
chudy@google.comc432f002012-07-10 13:19:25 +0000442 fSettingsWidget.getVisibilityButton()->isChecked());
443 fCanvasWidget.drawTo(fListWidget.currentRow());
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000444 fImageWidget.draw();
chudy@google.com902ebe52012-06-29 14:21:22 +0000445}
446
447void SkDebuggerGUI::actionClose() {
448 this->close();
449}
450
451void SkDebuggerGUI::actionDelete() {
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000452
robertphillips@google.comdd4b7452013-01-22 19:38:46 +0000453 for (int row = 0; row < fListWidget.count(); ++row) {
454 QListWidgetItem* item = fListWidget.item(row);
455
456 if (!item->isSelected()) {
457 continue;
458 }
459
460 if (fDebugger.isCommandVisible(row)) {
461 item->setData(Qt::UserRole + 2, QPixmap(":/delete.png"));
462 fDebugger.setCommandVisible(row, false);
463 fSkipCommands[row] = true;
464 } else {
465 item->setData(Qt::UserRole + 2, QPixmap(":/blank.png"));
466 fDebugger.setCommandVisible(row, true);
467 fSkipCommands[row] = false;
468 }
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000469 }
470
robertphillips@google.comdd4b7452013-01-22 19:38:46 +0000471 int currentRow = fListWidget.currentRow();
472
chudy@google.come504de02012-07-16 18:35:23 +0000473 if (fPause) {
474 fCanvasWidget.drawTo(fPausedRow);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000475 fImageWidget.draw();
chudy@google.come504de02012-07-16 18:35:23 +0000476 } else {
477 fCanvasWidget.drawTo(currentRow);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000478 fImageWidget.draw();
chudy@google.come504de02012-07-16 18:35:23 +0000479 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000480}
481
chudy@google.comea5488b2012-07-26 19:38:22 +0000482void SkDebuggerGUI::actionGLWidget(bool isToggled) {
483 fCanvasWidget.setWidgetVisibility(SkCanvasWidget::kGPU_WidgetType, !isToggled);
484}
485
chudy@google.com902ebe52012-06-29 14:21:22 +0000486void SkDebuggerGUI::actionInspector() {
chudy@google.comc432f002012-07-10 13:19:25 +0000487 if (fInspectorWidget.isHidden()) {
488 fInspectorWidget.setHidden(false);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000489 fImageWidget.setHidden(false);
chudy@google.com902ebe52012-06-29 14:21:22 +0000490 } else {
chudy@google.comc432f002012-07-10 13:19:25 +0000491 fInspectorWidget.setHidden(true);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000492 fImageWidget.setHidden(true);
chudy@google.com902ebe52012-06-29 14:21:22 +0000493 }
494}
495
496void SkDebuggerGUI::actionPlay() {
chudy@google.comc432f002012-07-10 13:19:25 +0000497 for (int row = fListWidget.currentRow() + 1; row < fListWidget.count();
chudy@google.com7dcae672012-07-09 20:26:53 +0000498 row++) {
chudy@google.comc432f002012-07-10 13:19:25 +0000499 QListWidgetItem *item = fListWidget.item(row);
chudy@google.com902ebe52012-06-29 14:21:22 +0000500 if (item->checkState() == Qt::Checked) {
chudy@google.comc432f002012-07-10 13:19:25 +0000501 fListWidget.setCurrentItem(item);
chudy@google.com902ebe52012-06-29 14:21:22 +0000502 return;
503 }
504 }
chudy@google.comc432f002012-07-10 13:19:25 +0000505 fListWidget.setCurrentRow(fListWidget.count() - 1);
chudy@google.com902ebe52012-06-29 14:21:22 +0000506}
507
chudy@google.comea5488b2012-07-26 19:38:22 +0000508void SkDebuggerGUI::actionRasterWidget(bool isToggled) {
509 fCanvasWidget.setWidgetVisibility(SkCanvasWidget::kRaster_8888_WidgetType, !isToggled);
510}
511
chudy@google.com902ebe52012-06-29 14:21:22 +0000512void SkDebuggerGUI::actionRewind() {
chudy@google.come504de02012-07-16 18:35:23 +0000513 fListWidget.setCurrentRow(0);
chudy@google.com902ebe52012-06-29 14:21:22 +0000514}
515
chudy@google.com0ab03392012-07-28 20:16:11 +0000516void SkDebuggerGUI::actionSave() {
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000517 fFileName = fPath.toAscii();
518 fFileName.append("/");
519 fFileName.append(fDirectoryWidget.currentItem()->text().toAscii());
520 saveToFile(fFileName);
chudy@google.com0ab03392012-07-28 20:16:11 +0000521}
522
523void SkDebuggerGUI::actionSaveAs() {
524 QString filename = QFileDialog::getSaveFileName(this, "Save File", "",
525 "Skia Picture (*skp)");
chudy@google.com38b08ce2012-07-28 23:26:10 +0000526 if (!filename.endsWith(".skp", Qt::CaseInsensitive)) {
chudy@google.com0ab03392012-07-28 20:16:11 +0000527 filename.append(".skp");
528 }
djsollen@google.comc3c82162012-11-13 18:35:10 +0000529 saveToFile(SkString(filename.toAscii().data()));
chudy@google.com0ab03392012-07-28 20:16:11 +0000530}
531
chudy@google.com7dcae672012-07-09 20:26:53 +0000532void SkDebuggerGUI::actionScale(float scaleFactor) {
chudy@google.comc432f002012-07-10 13:19:25 +0000533 fSettingsWidget.setZoomText(scaleFactor);
chudy@google.com7dcae672012-07-09 20:26:53 +0000534}
535
chudy@google.com902ebe52012-06-29 14:21:22 +0000536void SkDebuggerGUI::actionSettings() {
chudy@google.comc432f002012-07-10 13:19:25 +0000537 if (fSettingsWidget.isHidden()) {
538 fSettingsWidget.setHidden(false);
chudy@google.com902ebe52012-06-29 14:21:22 +0000539 } else {
chudy@google.comc432f002012-07-10 13:19:25 +0000540 fSettingsWidget.setHidden(true);
chudy@google.com902ebe52012-06-29 14:21:22 +0000541 }
542}
543
544void SkDebuggerGUI::actionStepBack() {
chudy@google.comc432f002012-07-10 13:19:25 +0000545 int currentRow = fListWidget.currentRow();
chudy@google.com902ebe52012-06-29 14:21:22 +0000546 if (currentRow != 0) {
chudy@google.comc432f002012-07-10 13:19:25 +0000547 fListWidget.setCurrentRow(currentRow - 1);
chudy@google.com902ebe52012-06-29 14:21:22 +0000548 }
549}
550
551void SkDebuggerGUI::actionStepForward() {
chudy@google.comc432f002012-07-10 13:19:25 +0000552 int currentRow = fListWidget.currentRow();
chudy@google.com902ebe52012-06-29 14:21:22 +0000553 QString curRow = QString::number(currentRow);
chudy@google.comc432f002012-07-10 13:19:25 +0000554 QString curCount = QString::number(fListWidget.count());
555 if (currentRow < fListWidget.count() - 1) {
556 fListWidget.setCurrentRow(currentRow + 1);
chudy@google.com902ebe52012-06-29 14:21:22 +0000557 }
558}
559
chudy@google.coma9e937c2012-08-03 17:32:05 +0000560void SkDebuggerGUI::drawComplete() {
chudy@google.com607357f2012-08-07 16:12:23 +0000561 fInspectorWidget.setMatrix(fDebugger.getCurrentMatrix());
562 fInspectorWidget.setClip(fDebugger.getCurrentClip());
chudy@google.coma9e937c2012-08-03 17:32:05 +0000563}
564
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000565void SkDebuggerGUI::saveToFile(const SkString& filename) {
566 SkFILEWStream file(filename.c_str());
robertphillips@google.com25bc2f82013-01-22 18:03:56 +0000567 SkAutoTUnref<SkPicture> copy(fDebugger.copyPicture());
568
569 copy->serialize(&file);
chudy@google.com0ab03392012-07-28 20:16:11 +0000570}
571
chudy@google.com902ebe52012-06-29 14:21:22 +0000572void SkDebuggerGUI::loadFile(QListWidgetItem *item) {
573 if (fDirectoryWidgetActive) {
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000574 fFileName = fPath.toAscii();
575 fFileName.append("/");
576 fFileName.append(item->text().toAscii());
577 loadPicture(fFileName);
chudy@google.com902ebe52012-06-29 14:21:22 +0000578 }
579}
580
581void SkDebuggerGUI::openFile() {
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000582 QString temp = QFileDialog::getOpenFileName(this, tr("Open File"), "",
chudy@google.com7dcae672012-07-09 20:26:53 +0000583 tr("Files (*.*)"));
chudy@google.com902ebe52012-06-29 14:21:22 +0000584 fDirectoryWidgetActive = false;
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000585 if (!temp.isEmpty()) {
586 QFileInfo pathInfo(temp);
chudy@google.com902ebe52012-06-29 14:21:22 +0000587 fPath = pathInfo.path();
djsollen@google.comc3c82162012-11-13 18:35:10 +0000588 loadPicture(SkString(temp.toAscii().data()));
chudy@google.com902ebe52012-06-29 14:21:22 +0000589 setupDirectoryWidget();
590 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000591 fDirectoryWidgetActive = true;
592}
593
chudy@google.comc432f002012-07-10 13:19:25 +0000594void SkDebuggerGUI::pauseDrawing(bool isPaused) {
chudy@google.com607357f2012-08-07 16:12:23 +0000595 fPause = isPaused;
596 fPausedRow = fListWidget.currentRow();
597 fCanvasWidget.drawTo(fPausedRow);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000598 fImageWidget.draw();
chudy@google.com7dcae672012-07-09 20:26:53 +0000599}
600
chudy@google.com902ebe52012-06-29 14:21:22 +0000601void SkDebuggerGUI::registerListClick(QListWidgetItem *item) {
chudy@google.comd3058f52012-07-19 13:41:27 +0000602 if(!fLoading) {
603 int currentRow = fListWidget.currentRow();
chudy@google.comd3058f52012-07-19 13:41:27 +0000604
chudy@google.comea5488b2012-07-26 19:38:22 +0000605 if (currentRow != -1) {
606 if (!fPause) {
607 fCanvasWidget.drawTo(currentRow);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000608 fImageWidget.draw();
chudy@google.comd3058f52012-07-19 13:41:27 +0000609 }
chudy@google.com97cee972012-08-07 20:41:37 +0000610 SkTDArray<SkString*> *currInfo = fDebugger.getCommandInfo(
chudy@google.comea5488b2012-07-26 19:38:22 +0000611 currentRow);
612
613 /* TODO(chudy): Add command type before parameters. Rename v
614 * to something more informative. */
chudy@google.com97cee972012-08-07 20:41:37 +0000615 if (currInfo) {
chudy@google.comea5488b2012-07-26 19:38:22 +0000616 QString info;
617 info.append("<b>Parameters: </b><br/>");
chudy@google.com97cee972012-08-07 20:41:37 +0000618 for (int i = 0; i < currInfo->count(); i++) {
619
620 info.append(QString((*currInfo)[i]->c_str()));
chudy@google.comea5488b2012-07-26 19:38:22 +0000621 info.append("<br/>");
622 }
chudy@google.com6bd109a2012-08-14 19:34:13 +0000623 fInspectorWidget.setText(info, SkInspectorWidget::kDetail_TabType);
chudy@google.comea5488b2012-07-26 19:38:22 +0000624 fInspectorWidget.setDisabled(false);
chudy@google.comea5488b2012-07-26 19:38:22 +0000625 }
chudy@google.comd3058f52012-07-19 13:41:27 +0000626 }
chudy@google.comea5488b2012-07-26 19:38:22 +0000627
chudy@google.com902ebe52012-06-29 14:21:22 +0000628 }
629}
630
chudy@google.com9ca9bfe2012-07-12 21:58:14 +0000631void SkDebuggerGUI::selectCommand(int command) {
632 if (fPause) {
633 fListWidget.setCurrentRow(command);
634 }
635}
636
chudy@google.com902ebe52012-06-29 14:21:22 +0000637void SkDebuggerGUI::toggleBreakpoint() {
chudy@google.comc432f002012-07-10 13:19:25 +0000638 QListWidgetItem* item = fListWidget.currentItem();
chudy@google.com902ebe52012-06-29 14:21:22 +0000639 if (item->checkState() == Qt::Unchecked) {
640 item->setCheckState(Qt::Checked);
chudy@google.come565de42012-07-12 14:15:54 +0000641 item->setData(Qt::DecorationRole,
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000642 QPixmap(":/breakpoint_16x16.png"));
chudy@google.com902ebe52012-06-29 14:21:22 +0000643 } else {
chudy@google.com902ebe52012-06-29 14:21:22 +0000644 item->setCheckState(Qt::Unchecked);
chudy@google.come565de42012-07-12 14:15:54 +0000645 item->setData(Qt::DecorationRole,
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000646 QPixmap(":/blank.png"));
chudy@google.com902ebe52012-06-29 14:21:22 +0000647 }
648}
649
650void SkDebuggerGUI::toggleDirectory() {
chudy@google.com607357f2012-08-07 16:12:23 +0000651 fDirectoryWidget.setHidden(!fDirectoryWidget.isHidden());
chudy@google.com902ebe52012-06-29 14:21:22 +0000652}
653
654void SkDebuggerGUI::toggleFilter(QString string) {
chudy@google.comc432f002012-07-10 13:19:25 +0000655 for (int row = 0; row < fListWidget.count(); row++) {
656 QListWidgetItem *item = fListWidget.item(row);
chudy@google.com607357f2012-08-07 16:12:23 +0000657 item->setHidden(item->text() != string);
chudy@google.com902ebe52012-06-29 14:21:22 +0000658 }
659}
660
661void SkDebuggerGUI::setupUi(QMainWindow *SkDebuggerGUI) {
662 QIcon windowIcon;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000663 windowIcon.addFile(QString::fromUtf8(":/skia.png"), QSize(),
chudy@google.com7dcae672012-07-09 20:26:53 +0000664 QIcon::Normal, QIcon::Off);
chudy@google.com902ebe52012-06-29 14:21:22 +0000665 SkDebuggerGUI->setObjectName(QString::fromUtf8("SkDebuggerGUI"));
666 SkDebuggerGUI->resize(1200, 1000);
667 SkDebuggerGUI->setWindowIcon(windowIcon);
chudy@google.comc432f002012-07-10 13:19:25 +0000668 SkDebuggerGUI->setWindowTitle("Skia Debugger");
chudy@google.com902ebe52012-06-29 14:21:22 +0000669
chudy@google.come504de02012-07-16 18:35:23 +0000670 fActionOpen.setShortcuts(QKeySequence::Open);
chudy@google.comc432f002012-07-10 13:19:25 +0000671 fActionOpen.setText("Open");
chudy@google.com902ebe52012-06-29 14:21:22 +0000672
673 QIcon breakpoint;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000674 breakpoint.addFile(QString::fromUtf8(":/breakpoint.png"),
chudy@google.com7dcae672012-07-09 20:26:53 +0000675 QSize(), QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000676 fActionBreakpoint.setShortcut(QKeySequence(tr("Ctrl+B")));
chudy@google.comc432f002012-07-10 13:19:25 +0000677 fActionBreakpoint.setIcon(breakpoint);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000678 fActionBreakpoint.setText("Breakpoints");
chudy@google.com902ebe52012-06-29 14:21:22 +0000679
680 QIcon cancel;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000681 cancel.addFile(QString::fromUtf8(":/reload.png"), QSize(),
chudy@google.com7dcae672012-07-09 20:26:53 +0000682 QIcon::Normal, QIcon::Off);
chudy@google.comc432f002012-07-10 13:19:25 +0000683 fActionCancel.setIcon(cancel);
684 fActionCancel.setText("Clear Filter");
chudy@google.com902ebe52012-06-29 14:21:22 +0000685
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000686 fActionClearBreakpoints.setShortcut(QKeySequence(tr("Alt+B")));
687 fActionClearBreakpoints.setText("Clear Breakpoints");
688
689 fActionClearDeletes.setShortcut(QKeySequence(tr("Alt+X")));
690 fActionClearDeletes.setText("Clear Deletes");
691
chudy@google.come504de02012-07-16 18:35:23 +0000692 fActionClose.setShortcuts(QKeySequence::Quit);
chudy@google.comc432f002012-07-10 13:19:25 +0000693 fActionClose.setText("Exit");
chudy@google.com902ebe52012-06-29 14:21:22 +0000694
chudy@google.come504de02012-07-16 18:35:23 +0000695 fActionCreateBreakpoint.setShortcut(QKeySequence(tr("B")));
696 fActionCreateBreakpoint.setText("Set Breakpoint");
697
698 fActionDelete.setShortcut(QKeySequence(tr("X")));
chudy@google.comc432f002012-07-10 13:19:25 +0000699 fActionDelete.setText("Delete Command");
chudy@google.com902ebe52012-06-29 14:21:22 +0000700
chudy@google.come504de02012-07-16 18:35:23 +0000701 fActionDirectory.setShortcut(QKeySequence(tr("Ctrl+D")));
702 fActionDirectory.setText("Directory");
chudy@google.com902ebe52012-06-29 14:21:22 +0000703
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000704 QIcon profile;
robertphillips@google.comd1636362012-11-19 18:25:09 +0000705 profile.addFile(QString::fromUtf8(":/profile.png"), QSize(),
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000706 QIcon::Normal, QIcon::Off);
707 fActionProfile.setIcon(profile);
708 fActionProfile.setText("Profile");
robertphillips@google.come099bc42012-11-19 16:26:40 +0000709 fActionProfile.setDisabled(true);
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000710
chudy@google.comc432f002012-07-10 13:19:25 +0000711 QIcon inspector;
robertphillips@google.comd1636362012-11-19 18:25:09 +0000712 inspector.addFile(QString::fromUtf8(":/inspector.png"),
chudy@google.comc432f002012-07-10 13:19:25 +0000713 QSize(), QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000714 fActionInspector.setShortcut(QKeySequence(tr("Ctrl+I")));
chudy@google.comc432f002012-07-10 13:19:25 +0000715 fActionInspector.setIcon(inspector);
chudy@google.come504de02012-07-16 18:35:23 +0000716 fActionInspector.setText("Inspector");
chudy@google.com902ebe52012-06-29 14:21:22 +0000717
chudy@google.comc432f002012-07-10 13:19:25 +0000718 QIcon play;
robertphillips@google.comd1636362012-11-19 18:25:09 +0000719 play.addFile(QString::fromUtf8(":/play.png"), QSize(),
chudy@google.comc432f002012-07-10 13:19:25 +0000720 QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000721 fActionPlay.setShortcut(QKeySequence(tr("Ctrl+P")));
chudy@google.comc432f002012-07-10 13:19:25 +0000722 fActionPlay.setIcon(play);
723 fActionPlay.setText("Play");
chudy@google.com902ebe52012-06-29 14:21:22 +0000724
chudy@google.come504de02012-07-16 18:35:23 +0000725 QIcon pause;
robertphillips@google.comd1636362012-11-19 18:25:09 +0000726 pause.addFile(QString::fromUtf8(":/pause.png"), QSize(),
chudy@google.comc432f002012-07-10 13:19:25 +0000727 QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000728 fActionPause.setShortcut(QKeySequence(tr("Space")));
729 fActionPause.setCheckable(true);
730 fActionPause.setIcon(pause);
731 fActionPause.setText("Pause");
732
chudy@google.comc432f002012-07-10 13:19:25 +0000733 QIcon rewind;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000734 rewind.addFile(QString::fromUtf8(":/rewind.png"), QSize(),
chudy@google.comc432f002012-07-10 13:19:25 +0000735 QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000736 fActionRewind.setShortcut(QKeySequence(tr("Ctrl+R")));
chudy@google.comc432f002012-07-10 13:19:25 +0000737 fActionRewind.setIcon(rewind);
738 fActionRewind.setText("Rewind");
chudy@google.com902ebe52012-06-29 14:21:22 +0000739
chudy@google.com0ab03392012-07-28 20:16:11 +0000740 fActionSave.setShortcut(QKeySequence::Save);
741 fActionSave.setText("Save");
742 fActionSave.setDisabled(true);
743 fActionSaveAs.setShortcut(QKeySequence::SaveAs);
744 fActionSaveAs.setText("Save As");
745 fActionSaveAs.setDisabled(true);
746
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000747 fActionShowDeletes.setShortcut(QKeySequence(tr("Ctrl+X")));
748 fActionShowDeletes.setText("Deleted Commands");
749
chudy@google.comc432f002012-07-10 13:19:25 +0000750 QIcon stepBack;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000751 stepBack.addFile(QString::fromUtf8(":/previous.png"), QSize(),
chudy@google.comc432f002012-07-10 13:19:25 +0000752 QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000753 fActionStepBack.setShortcut(QKeySequence(tr("[")));
chudy@google.comc432f002012-07-10 13:19:25 +0000754 fActionStepBack.setIcon(stepBack);
755 fActionStepBack.setText("Step Back");
chudy@google.com902ebe52012-06-29 14:21:22 +0000756
chudy@google.comc432f002012-07-10 13:19:25 +0000757 QIcon stepForward;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000758 stepForward.addFile(QString::fromUtf8(":/next.png"),
chudy@google.comc432f002012-07-10 13:19:25 +0000759 QSize(), QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000760 fActionStepForward.setShortcut(QKeySequence(tr("]")));
chudy@google.comc432f002012-07-10 13:19:25 +0000761 fActionStepForward.setIcon(stepForward);
762 fActionStepForward.setText("Step Forward");
763
chudy@google.coma1226312012-07-26 20:26:44 +0000764 fActionZoomIn.setShortcut(QKeySequence(tr("Ctrl+=")));
765 fActionZoomIn.setText("Zoom In");
766 fActionZoomOut.setShortcut(QKeySequence(tr("Ctrl+-")));
767 fActionZoomOut.setText("Zoom Out");
768
chudy@google.comc432f002012-07-10 13:19:25 +0000769 fListWidget.setItemDelegate(new SkListWidget(&fListWidget));
770 fListWidget.setObjectName(QString::fromUtf8("listWidget"));
771 fListWidget.setMaximumWidth(250);
772
773 fFilter.addItem("--Filter By Available Commands--");
774
775 fDirectoryWidget.setMaximumWidth(250);
776 fDirectoryWidget.setStyleSheet("QListWidget::Item {padding: 5px;}");
777
778 fCanvasWidget.setSizePolicy(QSizePolicy::Expanding,
chudy@google.com7dcae672012-07-09 20:26:53 +0000779 QSizePolicy::Expanding);
chudy@google.com902ebe52012-06-29 14:21:22 +0000780
skia.committer@gmail.com1c9c0d32012-11-22 02:02:41 +0000781 fImageWidget.setFixedSize(SkImageWidget::kImageWidgetWidth,
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000782 SkImageWidget::kImageWidgetHeight);
783
chudy@google.comc432f002012-07-10 13:19:25 +0000784 fInspectorWidget.setSizePolicy(QSizePolicy::Expanding,
chudy@google.com7dcae672012-07-09 20:26:53 +0000785 QSizePolicy::Expanding);
chudy@google.comc432f002012-07-10 13:19:25 +0000786 fInspectorWidget.setMaximumHeight(300);
chudy@google.com902ebe52012-06-29 14:21:22 +0000787
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000788 fSettingsAndImageLayout.setSpacing(6);
789 fSettingsAndImageLayout.addWidget(&fSettingsWidget);
790 fSettingsAndImageLayout.addWidget(&fImageWidget);
791
chudy@google.comc432f002012-07-10 13:19:25 +0000792 fSettingsWidget.setSizePolicy(QSizePolicy::Expanding,
793 QSizePolicy::Expanding);
794 fSettingsWidget.setMaximumWidth(250);
chudy@google.com902ebe52012-06-29 14:21:22 +0000795
chudy@google.comc432f002012-07-10 13:19:25 +0000796 fLeftColumnLayout.setSpacing(6);
797 fLeftColumnLayout.addWidget(&fListWidget);
798 fLeftColumnLayout.addWidget(&fDirectoryWidget);
chudy@google.com902ebe52012-06-29 14:21:22 +0000799
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000800 fCanvasSettingsAndImageLayout.setSpacing(6);
801 fCanvasSettingsAndImageLayout.addWidget(&fCanvasWidget);
802 fCanvasSettingsAndImageLayout.addLayout(&fSettingsAndImageLayout);
803
chudy@google.com902ebe52012-06-29 14:21:22 +0000804
chudy@google.comc432f002012-07-10 13:19:25 +0000805 fMainAndRightColumnLayout.setSpacing(6);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000806 fMainAndRightColumnLayout.addLayout(&fCanvasSettingsAndImageLayout);
chudy@google.comc432f002012-07-10 13:19:25 +0000807 fMainAndRightColumnLayout.addWidget(&fInspectorWidget);
chudy@google.com902ebe52012-06-29 14:21:22 +0000808
chudy@google.com2d537a12012-07-31 12:49:52 +0000809 fCentralWidget.setLayout(&fContainerLayout);
chudy@google.comc432f002012-07-10 13:19:25 +0000810 fContainerLayout.setSpacing(6);
811 fContainerLayout.setContentsMargins(11, 11, 11, 11);
812 fContainerLayout.addLayout(&fLeftColumnLayout);
813 fContainerLayout.addLayout(&fMainAndRightColumnLayout);
814
815 SkDebuggerGUI->setCentralWidget(&fCentralWidget);
816 SkDebuggerGUI->setStatusBar(&fStatusBar);
817
chudy@google.come504de02012-07-16 18:35:23 +0000818 fToolBar.setIconSize(QSize(32, 32));
chudy@google.comc432f002012-07-10 13:19:25 +0000819 fToolBar.setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
820 SkDebuggerGUI->addToolBar(Qt::TopToolBarArea, &fToolBar);
chudy@google.com902ebe52012-06-29 14:21:22 +0000821
chudy@google.com0ab03392012-07-28 20:16:11 +0000822 fSpacer.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
chudy@google.com902ebe52012-06-29 14:21:22 +0000823
chudy@google.comc432f002012-07-10 13:19:25 +0000824 fToolBar.addAction(&fActionRewind);
825 fToolBar.addAction(&fActionStepBack);
chudy@google.come504de02012-07-16 18:35:23 +0000826 fToolBar.addAction(&fActionPause);
chudy@google.comc432f002012-07-10 13:19:25 +0000827 fToolBar.addAction(&fActionStepForward);
828 fToolBar.addAction(&fActionPlay);
829 fToolBar.addSeparator();
chudy@google.come504de02012-07-16 18:35:23 +0000830 fToolBar.addAction(&fActionInspector);
chudy@google.comc432f002012-07-10 13:19:25 +0000831 fToolBar.addSeparator();
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000832 fToolBar.addAction(&fActionProfile);
833
834 fToolBar.addSeparator();
chudy@google.com0ab03392012-07-28 20:16:11 +0000835 fToolBar.addWidget(&fSpacer);
chudy@google.comc432f002012-07-10 13:19:25 +0000836 fToolBar.addWidget(&fFilter);
837 fToolBar.addAction(&fActionCancel);
chudy@google.com902ebe52012-06-29 14:21:22 +0000838
839 // TODO(chudy): Remove static call.
840 fDirectoryWidgetActive = false;
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000841 fPath = "";
842 fFileName = "";
chudy@google.com902ebe52012-06-29 14:21:22 +0000843 setupDirectoryWidget();
844 fDirectoryWidgetActive = true;
845
chudy@google.com902ebe52012-06-29 14:21:22 +0000846 // Menu Bar
chudy@google.comc432f002012-07-10 13:19:25 +0000847 fMenuFile.setTitle("File");
848 fMenuFile.addAction(&fActionOpen);
chudy@google.com0ab03392012-07-28 20:16:11 +0000849 fMenuFile.addAction(&fActionSave);
850 fMenuFile.addAction(&fActionSaveAs);
chudy@google.comc432f002012-07-10 13:19:25 +0000851 fMenuFile.addAction(&fActionClose);
chudy@google.come504de02012-07-16 18:35:23 +0000852
853 fMenuEdit.setTitle("Edit");
854 fMenuEdit.addAction(&fActionDelete);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000855 fMenuEdit.addAction(&fActionClearDeletes);
856 fMenuEdit.addSeparator();
chudy@google.come504de02012-07-16 18:35:23 +0000857 fMenuEdit.addAction(&fActionCreateBreakpoint);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000858 fMenuEdit.addAction(&fActionClearBreakpoints);
chudy@google.come504de02012-07-16 18:35:23 +0000859
chudy@google.comc432f002012-07-10 13:19:25 +0000860 fMenuNavigate.setTitle("Navigate");
chudy@google.come504de02012-07-16 18:35:23 +0000861 fMenuNavigate.addAction(&fActionRewind);
862 fMenuNavigate.addAction(&fActionStepBack);
863 fMenuNavigate.addAction(&fActionStepForward);
864 fMenuNavigate.addAction(&fActionPlay);
865 fMenuNavigate.addAction(&fActionPause);
chudy@google.comc432f002012-07-10 13:19:25 +0000866 fMenuNavigate.addAction(&fActionGoToLine);
chudy@google.come504de02012-07-16 18:35:23 +0000867
chudy@google.comc432f002012-07-10 13:19:25 +0000868 fMenuView.setTitle("View");
chudy@google.come504de02012-07-16 18:35:23 +0000869 fMenuView.addAction(&fActionBreakpoint);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000870 fMenuView.addAction(&fActionShowDeletes);
chudy@google.coma1226312012-07-26 20:26:44 +0000871 fMenuView.addAction(&fActionZoomIn);
872 fMenuView.addAction(&fActionZoomOut);
chudy@google.come504de02012-07-16 18:35:23 +0000873
874 fMenuWindows.setTitle("Window");
875 fMenuWindows.addAction(&fActionInspector);
876 fMenuWindows.addAction(&fActionDirectory);
chudy@google.comc432f002012-07-10 13:19:25 +0000877
878 fActionGoToLine.setText("Go to Line...");
879 fActionGoToLine.setDisabled(true);
880 fMenuBar.addAction(fMenuFile.menuAction());
chudy@google.come504de02012-07-16 18:35:23 +0000881 fMenuBar.addAction(fMenuEdit.menuAction());
chudy@google.comc432f002012-07-10 13:19:25 +0000882 fMenuBar.addAction(fMenuView.menuAction());
883 fMenuBar.addAction(fMenuNavigate.menuAction());
chudy@google.come504de02012-07-16 18:35:23 +0000884 fMenuBar.addAction(fMenuWindows.menuAction());
chudy@google.com902ebe52012-06-29 14:21:22 +0000885
chudy@google.com7dcae672012-07-09 20:26:53 +0000886 fPause = false;
887
chudy@google.comc432f002012-07-10 13:19:25 +0000888 SkDebuggerGUI->setMenuBar(&fMenuBar);
chudy@google.com902ebe52012-06-29 14:21:22 +0000889 QMetaObject::connectSlotsByName(SkDebuggerGUI);
890}
891
892void SkDebuggerGUI::setupDirectoryWidget() {
chudy@google.comc432f002012-07-10 13:19:25 +0000893 QDir dir(fPath);
chudy@google.com902ebe52012-06-29 14:21:22 +0000894 QRegExp r(".skp");
chudy@google.comc432f002012-07-10 13:19:25 +0000895 fDirectoryWidget.clear();
896 const QStringList files = dir.entryList();
chudy@google.com902ebe52012-06-29 14:21:22 +0000897 foreach (QString f, files) {
chudy@google.com7dcae672012-07-09 20:26:53 +0000898 if (f.contains(r))
chudy@google.comc432f002012-07-10 13:19:25 +0000899 fDirectoryWidget.addItem(f);
chudy@google.com902ebe52012-06-29 14:21:22 +0000900 }
901}
902
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000903// SkOffsetPicturePlayback records the offset of each command in the picture.
904// These are needed by the profiling system.
905class SkOffsetPicturePlayback : public SkPicturePlayback {
906public:
907 SkOffsetPicturePlayback(SkStream* stream, const SkPictInfo& info, bool* isValid,
908 SkSerializationHelpers::DecodeBitmap decoder)
909 : INHERITED(stream, info, isValid, decoder) {
910 }
911
912 const SkTDArray<size_t>& offsets() const { return fOffsets; }
913
914protected:
915 SkTDArray<size_t> fOffsets;
916
robertphillips@google.comca47aae2012-12-12 15:58:25 +0000917 virtual size_t preDraw(size_t offset, int type) {
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000918 *fOffsets.append() = offset;
robertphillips@google.com5f971142012-12-07 20:48:56 +0000919 return 0;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000920 }
921
922private:
923 typedef SkPicturePlayback INHERITED;
924};
925
926// Picture to wrap an SkOffsetPicturePlayback.
927class SkOffsetPicture : public SkPicture {
928public:
skia.committer@gmail.com884e60b2012-11-16 02:01:17 +0000929 SkOffsetPicture(SkStream* stream,
930 bool* success,
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000931 SkSerializationHelpers::DecodeBitmap decoder) {
932 if (success) {
933 *success = false;
934 }
935 fRecord = NULL;
936 fPlayback = NULL;
937 fWidth = fHeight = 0;
938
939 SkPictInfo info;
940
941 if (!stream->read(&info, sizeof(info))) {
942 return;
943 }
944 if (PICTURE_VERSION != info.fVersion) {
945 return;
946 }
947
948 if (stream->readBool()) {
949 bool isValid = false;
950 fPlayback = SkNEW_ARGS(SkOffsetPicturePlayback, (stream, info, &isValid, decoder));
951 if (!isValid) {
952 SkDELETE(fPlayback);
953 fPlayback = NULL;
954 return;
955 }
956 }
957
958 // do this at the end, so that they will be zero if we hit an error.
959 fWidth = info.fWidth;
960 fHeight = info.fHeight;
961 if (success) {
962 *success = true;
963 }
964 }
965
skia.committer@gmail.com884e60b2012-11-16 02:01:17 +0000966 const SkTDArray<size_t>& offsets() const {
967 return ((SkOffsetPicturePlayback*) fPlayback)->offsets();
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000968 }
969
970private:
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000971 // disallow default ctor b.c. we don't have a good way to setup the fPlayback ptr
972 SkOffsetPicture();
973 // disallow the copy ctor - enabling would require copying code from SkPicture
974 SkOffsetPicture(const SkOffsetPicture& src);
975
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000976 typedef SkPicture INHERITED;
977};
978
979
980
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000981void SkDebuggerGUI::loadPicture(const SkString& fileName) {
982 fFileName = fileName;
chudy@google.comd3058f52012-07-19 13:41:27 +0000983 fLoading = true;
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000984 SkStream* stream = SkNEW_ARGS(SkFILEStream, (fileName.c_str()));
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000985 SkOffsetPicture* picture = SkNEW_ARGS(SkOffsetPicture, (stream, NULL, &SkImageDecoder::DecodeStream));
986
chudy@google.com686e6802012-08-14 16:00:32 +0000987 fCanvasWidget.resetWidgetTransform();
chudy@google.com607357f2012-08-07 16:12:23 +0000988 fDebugger.loadPicture(picture);
chudy@google.com4c7962e2012-08-14 19:38:31 +0000989
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000990 fOffsets = picture->offsets();
991
robertphillips@google.com5f971142012-12-07 20:48:56 +0000992 fSkipCommands.setCount(fOffsets.count());
993 for (int i = 0; i < fOffsets.count(); ++i) {
994 fSkipCommands[i] = false;
995 }
996
chudy@google.com607357f2012-08-07 16:12:23 +0000997 SkSafeUnref(stream);
998 SkSafeUnref(picture);
999
chudy@google.com97cee972012-08-07 20:41:37 +00001000 // Will this automatically clear out due to nature of refcnt?
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +00001001 SkTArray<SkString>* commands = fDebugger.getDrawCommandsAsStrings();
chudy@google.com607357f2012-08-07 16:12:23 +00001002
robertphillips@google.comfe830a42012-11-15 16:33:31 +00001003 // If SkPicturePlayback is compiled w/o SK_PICTURE_PROFILING_STUBS
1004 // the offset count will always be zero
1005 SkASSERT(0 == fOffsets.count() || commands->count() == fOffsets.count());
robertphillips@google.come099bc42012-11-19 16:26:40 +00001006 if (commands->count() == fOffsets.count()) {
1007 fActionProfile.setDisabled(false);
robertphillips@google.comfe830a42012-11-15 16:33:31 +00001008 }
robertphillips@google.com2bde91d2012-11-15 14:57:57 +00001009
chudy@google.com7dcae672012-07-09 20:26:53 +00001010 /* fDebugCanvas is reinitialized every load picture. Need it to retain value
chudy@google.com607357f2012-08-07 16:12:23 +00001011 * of the visibility filter.
1012 * TODO(chudy): This should be deprecated since fDebugger is not
1013 * recreated.
1014 * */
1015 fDebugger.highlightCurrentCommand(fSettingsWidget.getVisibilityButton()->isChecked());
1016
chudy@google.com97cee972012-08-07 20:41:37 +00001017 setupListWidget(commands);
1018 setupComboBox(commands);
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +00001019 setupOverviewText(NULL, 0.0);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +00001020 fInspectorWidget.setDisabled(false);
chudy@google.come606d6e2012-07-12 14:31:25 +00001021 fSettingsWidget.setDisabled(false);
chudy@google.comd3058f52012-07-19 13:41:27 +00001022 fMenuEdit.setDisabled(false);
1023 fMenuNavigate.setDisabled(false);
1024 fMenuView.setDisabled(false);
chudy@google.com0ab03392012-07-28 20:16:11 +00001025 fActionSave.setDisabled(false);
1026 fActionSaveAs.setDisabled(false);
chudy@google.comd3058f52012-07-19 13:41:27 +00001027 fLoading = false;
1028 actionPlay();
chudy@google.com902ebe52012-06-29 14:21:22 +00001029}
1030
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +00001031void SkDebuggerGUI::setupListWidget(SkTArray<SkString>* command) {
chudy@google.comc432f002012-07-10 13:19:25 +00001032 fListWidget.clear();
chudy@google.com902ebe52012-06-29 14:21:22 +00001033 int counter = 0;
robertphillips@google.com30d35f22012-11-06 16:45:36 +00001034 int indent = 0;
chudy@google.com97cee972012-08-07 20:41:37 +00001035 for (int i = 0; i < command->count(); i++) {
chudy@google.com902ebe52012-06-29 14:21:22 +00001036 QListWidgetItem *item = new QListWidgetItem();
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +00001037 item->setData(Qt::DisplayRole, (*command)[i].c_str());
chudy@google.com902ebe52012-06-29 14:21:22 +00001038 item->setData(Qt::UserRole + 1, counter++);
robertphillips@google.com30d35f22012-11-06 16:45:36 +00001039
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +00001040 if (0 == strcmp("Restore", (*command)[i].c_str())) {
robertphillips@google.com30d35f22012-11-06 16:45:36 +00001041 indent -= 10;
1042 }
1043
1044 item->setData(Qt::UserRole + 3, indent);
1045
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +00001046 if (0 == strcmp("Save", (*command)[i].c_str()) ||
1047 0 == strcmp("Save Layer", (*command)[i].c_str())) {
robertphillips@google.com30d35f22012-11-06 16:45:36 +00001048 indent += 10;
1049 }
1050
robertphillips@google.comd26c7062012-11-12 20:42:12 +00001051 item->setData(Qt::UserRole + 4, -1.0);
1052
chudy@google.comc432f002012-07-10 13:19:25 +00001053 fListWidget.addItem(item);
chudy@google.com902ebe52012-06-29 14:21:22 +00001054 }
1055}
1056
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +00001057void SkDebuggerGUI::setupOverviewText(const SkTDArray<double>* typeTimes, double totTime) {
chudy@google.com902ebe52012-06-29 14:21:22 +00001058
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +00001059 const SkTDArray<SkDrawCommand*>& commands = fDebugger.getDrawCommands();
1060
1061 SkTDArray<int> counts;
1062 counts.setCount(LAST_DRAWTYPE_ENUM+1);
1063 for (int i = 0; i < LAST_DRAWTYPE_ENUM+1; ++i) {
1064 counts[i] = 0;
1065 }
1066
1067 for (int i = 0; i < commands.count(); i++) {
1068 counts[commands[i]->getType()]++;
chudy@google.com902ebe52012-06-29 14:21:22 +00001069 }
1070
1071 QString overview;
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +00001072 int total = 0;
1073#ifdef SK_DEBUG
1074 double totPercent = 0, tempSum = 0;
1075#endif
1076 for (int i = 0; i < LAST_DRAWTYPE_ENUM+1; ++i) {
1077 if (0 == counts[i]) {
1078 // if there were no commands of this type then they should've consumed no time
1079 SkASSERT(NULL == typeTimes || 0.0 == (*typeTimes)[i]);
1080 continue;
1081 }
1082
1083 overview.append(SkDrawCommand::GetCommandString((DrawType) i));
chudy@google.com902ebe52012-06-29 14:21:22 +00001084 overview.append(": ");
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +00001085 overview.append(QString::number(counts[i]));
1086 if (NULL != typeTimes) {
1087 overview.append(" - ");
1088 overview.append(QString::number((*typeTimes)[i], 'f', 1));
1089 overview.append("ms");
1090 overview.append(" - ");
1091 double percent = 100.0*(*typeTimes)[i]/totTime;
1092 overview.append(QString::number(percent, 'f', 1));
1093 overview.append("%");
1094#ifdef SK_DEBUG
1095 totPercent += percent;
1096 tempSum += (*typeTimes)[i];
1097#endif
1098 }
chudy@google.com902ebe52012-06-29 14:21:22 +00001099 overview.append("<br/>");
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +00001100 total += counts[i];
chudy@google.com902ebe52012-06-29 14:21:22 +00001101 }
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +00001102#ifdef SK_DEBUG
1103 if (NULL != typeTimes) {
1104 SkASSERT(SkScalarNearlyEqual(totPercent, 100.0));
1105 SkASSERT(SkScalarNearlyEqual(tempSum, totTime));
1106 }
1107#endif
1108
1109 if (totTime > 0.0) {
1110 overview.append("Total Time: ");
1111 overview.append(QString::number(totTime, 'f', 2));
1112 overview.append("ms");
1113#ifdef SK_DEBUG
1114 overview.append(" ");
1115 overview.append(QString::number(totPercent));
1116 overview.append("% ");
1117#endif
1118 overview.append("<br/>");
1119 }
1120
1121 QString totalStr;
1122 totalStr.append("Total Draw Commands: ");
1123 totalStr.append(QString::number(total));
1124 totalStr.append("<br/>");
1125 overview.insert(0, totalStr);
chudy@google.com902ebe52012-06-29 14:21:22 +00001126
1127 overview.append("<br/>");
chudy@google.com607357f2012-08-07 16:12:23 +00001128 overview.append("SkPicture Width: ");
chudy@google.com902ebe52012-06-29 14:21:22 +00001129 // NOTE(chudy): This is where we can pull out the SkPictures width.
chudy@google.com607357f2012-08-07 16:12:23 +00001130 overview.append(QString::number(fDebugger.pictureWidth()));
chudy@google.com902ebe52012-06-29 14:21:22 +00001131 overview.append("px<br/>");
chudy@google.com607357f2012-08-07 16:12:23 +00001132 overview.append("SkPicture Height: ");
1133 overview.append(QString::number(fDebugger.pictureHeight()));
chudy@google.com902ebe52012-06-29 14:21:22 +00001134 overview.append("px");
chudy@google.com6bd109a2012-08-14 19:34:13 +00001135 fInspectorWidget.setText(overview, SkInspectorWidget::kOverview_TabType);
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +00001136}
1137
1138void SkDebuggerGUI::setupComboBox(SkTArray<SkString>* command) {
1139 fFilter.clear();
1140 fFilter.addItem("--Filter By Available Commands--");
1141
1142 std::map<std::string, int> map;
1143 for (int i = 0; i < command->count(); i++) {
1144 map[(*command)[i].c_str()]++;
1145 }
1146
skia.committer@gmail.com34587162012-11-20 02:01:23 +00001147 for (std::map<std::string, int>::iterator it = map.begin(); it != map.end();
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +00001148 ++it) {
1149 fFilter.addItem((it->first).c_str());
1150 }
chudy@google.com902ebe52012-06-29 14:21:22 +00001151
1152 // NOTE(chudy): Makes first item unselectable.
chudy@google.com7dcae672012-07-09 20:26:53 +00001153 QStandardItemModel* model = qobject_cast<QStandardItemModel*>(
chudy@google.comc432f002012-07-10 13:19:25 +00001154 fFilter.model());
1155 QModelIndex firstIndex = model->index(0, fFilter.modelColumn(),
1156 fFilter.rootModelIndex());
chudy@google.com902ebe52012-06-29 14:21:22 +00001157 QStandardItem* firstItem = model->itemFromIndex(firstIndex);
1158 firstItem->setSelectable(false);
1159}