blob: a64ec9bbfe7ca27cbed7da28b5a182ff0a3ad80a [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);
jvanverth@google.comade32662013-01-28 21:09:05 +0000330 renderer->resetState(true);
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000331
332 // We throw this away the first batch of times to remove first time effects (such as paging in this program)
333 pict->resetTimes();
334
335 for (int i = 0; i < repeats; ++i) {
336 renderer->setup();
337 renderer->render(NULL);
jvanverth@google.comade32662013-01-28 21:09:05 +0000338 renderer->resetState(true);
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000339 }
340
341 renderer->end();
342}
343
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000344void SkDebuggerGUI::actionProfile() {
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000345 // In order to profile we pass the command offsets (that were read-in
346 // in loadPicture by the SkOffsetPicture) to an SkTimedPlaybackPicture.
skia.committer@gmail.com884e60b2012-11-16 02:01:17 +0000347 // The SkTimedPlaybackPicture in turn passes the offsets to an
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000348 // SkTimedPicturePlayback object which uses them to track the performance
349 // of individual commands.
350 if (fFileName.isEmpty()) {
351 return;
352 }
353
354 SkFILEStream inputStream;
355
356 inputStream.setPath(fFileName.c_str());
357 if (!inputStream.isValid()) {
358 return;
359 }
360
361 bool success = false;
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);
robertphillips@google.com1447aa32013-01-30 21:09:09 +0000389
390#if SK_SUPPORT_GPU
391 if (Qt::Checked == fSettingsWidget.getGLCheckBox()->checkState()) {
392 renderer->setDeviceType(sk_tools::PictureRenderer::kGPU_DeviceType);
393 }
394#endif
395
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000396#endif
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000397
robertphillips@google.come174a8b2012-11-27 16:04:42 +0000398 static const int kNumRepeats = 10;
399
400 run(&picture, renderer, kNumRepeats);
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000401
402 SkASSERT(picture.count() == fListWidget.count());
403
404 // extract the individual command times from the SkTimedPlaybackPicture
405 for (int i = 0; i < picture.count(); ++i) {
406 double temp = picture.time(i);
407
408 QListWidgetItem* item = fListWidget.item(i);
409
410 item->setData(Qt::UserRole + 4, 100.0*temp);
411 }
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000412
413 setupOverviewText(picture.typeTimes(), picture.totTime());
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000414}
415
chudy@google.com902ebe52012-06-29 14:21:22 +0000416void SkDebuggerGUI::actionCancel() {
chudy@google.comc432f002012-07-10 13:19:25 +0000417 for (int row = 0; row < fListWidget.count(); row++) {
418 fListWidget.item(row)->setHidden(false);
chudy@google.com902ebe52012-06-29 14:21:22 +0000419 }
420}
421
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000422void SkDebuggerGUI::actionClearBreakpoints() {
423 for (int row = 0; row < fListWidget.count(); row++) {
424 QListWidgetItem* item = fListWidget.item(row);
425 item->setCheckState(Qt::Unchecked);
426 item->setData(Qt::DecorationRole,
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000427 QPixmap(":/blank.png"));
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000428 }
429}
430
431void SkDebuggerGUI::actionClearDeletes() {
432 for (int row = 0; row < fListWidget.count(); row++) {
433 QListWidgetItem* item = fListWidget.item(row);
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000434 item->setData(Qt::UserRole + 2, QPixmap(":/blank.png"));
chudy@google.com607357f2012-08-07 16:12:23 +0000435 fDebugger.setCommandVisible(row, true);
robertphillips@google.com5f971142012-12-07 20:48:56 +0000436 fSkipCommands[row] = false;
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000437 }
438 if (fPause) {
439 fCanvasWidget.drawTo(fPausedRow);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000440 fImageWidget.draw();
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000441 } else {
442 fCanvasWidget.drawTo(fListWidget.currentRow());
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000443 fImageWidget.draw();
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000444 }
445}
446
chudy@google.com902ebe52012-06-29 14:21:22 +0000447void SkDebuggerGUI::actionCommandFilter() {
chudy@google.com607357f2012-08-07 16:12:23 +0000448 fDebugger.highlightCurrentCommand(
chudy@google.comc432f002012-07-10 13:19:25 +0000449 fSettingsWidget.getVisibilityButton()->isChecked());
450 fCanvasWidget.drawTo(fListWidget.currentRow());
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000451 fImageWidget.draw();
chudy@google.com902ebe52012-06-29 14:21:22 +0000452}
453
454void SkDebuggerGUI::actionClose() {
455 this->close();
456}
457
458void SkDebuggerGUI::actionDelete() {
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000459
robertphillips@google.comdd4b7452013-01-22 19:38:46 +0000460 for (int row = 0; row < fListWidget.count(); ++row) {
461 QListWidgetItem* item = fListWidget.item(row);
462
463 if (!item->isSelected()) {
464 continue;
465 }
466
467 if (fDebugger.isCommandVisible(row)) {
468 item->setData(Qt::UserRole + 2, QPixmap(":/delete.png"));
469 fDebugger.setCommandVisible(row, false);
470 fSkipCommands[row] = true;
471 } else {
472 item->setData(Qt::UserRole + 2, QPixmap(":/blank.png"));
473 fDebugger.setCommandVisible(row, true);
474 fSkipCommands[row] = false;
475 }
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000476 }
477
robertphillips@google.comdd4b7452013-01-22 19:38:46 +0000478 int currentRow = fListWidget.currentRow();
479
chudy@google.come504de02012-07-16 18:35:23 +0000480 if (fPause) {
481 fCanvasWidget.drawTo(fPausedRow);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000482 fImageWidget.draw();
chudy@google.come504de02012-07-16 18:35:23 +0000483 } else {
484 fCanvasWidget.drawTo(currentRow);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000485 fImageWidget.draw();
chudy@google.come504de02012-07-16 18:35:23 +0000486 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000487}
488
chudy@google.comea5488b2012-07-26 19:38:22 +0000489void SkDebuggerGUI::actionGLWidget(bool isToggled) {
490 fCanvasWidget.setWidgetVisibility(SkCanvasWidget::kGPU_WidgetType, !isToggled);
491}
492
chudy@google.com902ebe52012-06-29 14:21:22 +0000493void SkDebuggerGUI::actionInspector() {
chudy@google.comc432f002012-07-10 13:19:25 +0000494 if (fInspectorWidget.isHidden()) {
495 fInspectorWidget.setHidden(false);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000496 fImageWidget.setHidden(false);
chudy@google.com902ebe52012-06-29 14:21:22 +0000497 } else {
chudy@google.comc432f002012-07-10 13:19:25 +0000498 fInspectorWidget.setHidden(true);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000499 fImageWidget.setHidden(true);
chudy@google.com902ebe52012-06-29 14:21:22 +0000500 }
501}
502
503void SkDebuggerGUI::actionPlay() {
chudy@google.comc432f002012-07-10 13:19:25 +0000504 for (int row = fListWidget.currentRow() + 1; row < fListWidget.count();
chudy@google.com7dcae672012-07-09 20:26:53 +0000505 row++) {
chudy@google.comc432f002012-07-10 13:19:25 +0000506 QListWidgetItem *item = fListWidget.item(row);
chudy@google.com902ebe52012-06-29 14:21:22 +0000507 if (item->checkState() == Qt::Checked) {
chudy@google.comc432f002012-07-10 13:19:25 +0000508 fListWidget.setCurrentItem(item);
chudy@google.com902ebe52012-06-29 14:21:22 +0000509 return;
510 }
511 }
chudy@google.comc432f002012-07-10 13:19:25 +0000512 fListWidget.setCurrentRow(fListWidget.count() - 1);
chudy@google.com902ebe52012-06-29 14:21:22 +0000513}
514
chudy@google.comea5488b2012-07-26 19:38:22 +0000515void SkDebuggerGUI::actionRasterWidget(bool isToggled) {
516 fCanvasWidget.setWidgetVisibility(SkCanvasWidget::kRaster_8888_WidgetType, !isToggled);
517}
518
chudy@google.com902ebe52012-06-29 14:21:22 +0000519void SkDebuggerGUI::actionRewind() {
chudy@google.come504de02012-07-16 18:35:23 +0000520 fListWidget.setCurrentRow(0);
chudy@google.com902ebe52012-06-29 14:21:22 +0000521}
522
chudy@google.com0ab03392012-07-28 20:16:11 +0000523void SkDebuggerGUI::actionSave() {
robertphillips@google.come219baf2013-01-28 19:25:43 +0000524 fFileName = fPath.toAscii().data();
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000525 fFileName.append("/");
robertphillips@google.come219baf2013-01-28 19:25:43 +0000526 fFileName.append(fDirectoryWidget.currentItem()->text().toAscii().data());
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000527 saveToFile(fFileName);
chudy@google.com0ab03392012-07-28 20:16:11 +0000528}
529
530void SkDebuggerGUI::actionSaveAs() {
531 QString filename = QFileDialog::getSaveFileName(this, "Save File", "",
532 "Skia Picture (*skp)");
chudy@google.com38b08ce2012-07-28 23:26:10 +0000533 if (!filename.endsWith(".skp", Qt::CaseInsensitive)) {
chudy@google.com0ab03392012-07-28 20:16:11 +0000534 filename.append(".skp");
535 }
djsollen@google.comc3c82162012-11-13 18:35:10 +0000536 saveToFile(SkString(filename.toAscii().data()));
chudy@google.com0ab03392012-07-28 20:16:11 +0000537}
538
chudy@google.com7dcae672012-07-09 20:26:53 +0000539void SkDebuggerGUI::actionScale(float scaleFactor) {
chudy@google.comc432f002012-07-10 13:19:25 +0000540 fSettingsWidget.setZoomText(scaleFactor);
chudy@google.com7dcae672012-07-09 20:26:53 +0000541}
542
chudy@google.com902ebe52012-06-29 14:21:22 +0000543void SkDebuggerGUI::actionSettings() {
chudy@google.comc432f002012-07-10 13:19:25 +0000544 if (fSettingsWidget.isHidden()) {
545 fSettingsWidget.setHidden(false);
chudy@google.com902ebe52012-06-29 14:21:22 +0000546 } else {
chudy@google.comc432f002012-07-10 13:19:25 +0000547 fSettingsWidget.setHidden(true);
chudy@google.com902ebe52012-06-29 14:21:22 +0000548 }
549}
550
551void SkDebuggerGUI::actionStepBack() {
chudy@google.comc432f002012-07-10 13:19:25 +0000552 int currentRow = fListWidget.currentRow();
chudy@google.com902ebe52012-06-29 14:21:22 +0000553 if (currentRow != 0) {
chudy@google.comc432f002012-07-10 13:19:25 +0000554 fListWidget.setCurrentRow(currentRow - 1);
chudy@google.com902ebe52012-06-29 14:21:22 +0000555 }
556}
557
558void SkDebuggerGUI::actionStepForward() {
chudy@google.comc432f002012-07-10 13:19:25 +0000559 int currentRow = fListWidget.currentRow();
chudy@google.com902ebe52012-06-29 14:21:22 +0000560 QString curRow = QString::number(currentRow);
chudy@google.comc432f002012-07-10 13:19:25 +0000561 QString curCount = QString::number(fListWidget.count());
562 if (currentRow < fListWidget.count() - 1) {
563 fListWidget.setCurrentRow(currentRow + 1);
chudy@google.com902ebe52012-06-29 14:21:22 +0000564 }
565}
566
chudy@google.coma9e937c2012-08-03 17:32:05 +0000567void SkDebuggerGUI::drawComplete() {
chudy@google.com607357f2012-08-07 16:12:23 +0000568 fInspectorWidget.setMatrix(fDebugger.getCurrentMatrix());
569 fInspectorWidget.setClip(fDebugger.getCurrentClip());
chudy@google.coma9e937c2012-08-03 17:32:05 +0000570}
571
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000572void SkDebuggerGUI::saveToFile(const SkString& filename) {
573 SkFILEWStream file(filename.c_str());
robertphillips@google.com25bc2f82013-01-22 18:03:56 +0000574 SkAutoTUnref<SkPicture> copy(fDebugger.copyPicture());
575
576 copy->serialize(&file);
chudy@google.com0ab03392012-07-28 20:16:11 +0000577}
578
chudy@google.com902ebe52012-06-29 14:21:22 +0000579void SkDebuggerGUI::loadFile(QListWidgetItem *item) {
580 if (fDirectoryWidgetActive) {
robertphillips@google.come219baf2013-01-28 19:25:43 +0000581 fFileName = fPath.toAscii().data();
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000582 fFileName.append("/");
robertphillips@google.come219baf2013-01-28 19:25:43 +0000583 fFileName.append(item->text().toAscii().data());
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000584 loadPicture(fFileName);
chudy@google.com902ebe52012-06-29 14:21:22 +0000585 }
586}
587
588void SkDebuggerGUI::openFile() {
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000589 QString temp = QFileDialog::getOpenFileName(this, tr("Open File"), "",
chudy@google.com7dcae672012-07-09 20:26:53 +0000590 tr("Files (*.*)"));
robertphillips@google.comff6e6ba2013-01-28 17:43:26 +0000591 openFile(temp);
592}
593
594void SkDebuggerGUI::openFile(const QString &filename) {
chudy@google.com902ebe52012-06-29 14:21:22 +0000595 fDirectoryWidgetActive = false;
robertphillips@google.comff6e6ba2013-01-28 17:43:26 +0000596 if (!filename.isEmpty()) {
597 QFileInfo pathInfo(filename);
598 loadPicture(SkString(filename.toAscii().data()));
599 setupDirectoryWidget(pathInfo.path());
chudy@google.com902ebe52012-06-29 14:21:22 +0000600 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000601 fDirectoryWidgetActive = true;
602}
603
chudy@google.comc432f002012-07-10 13:19:25 +0000604void SkDebuggerGUI::pauseDrawing(bool isPaused) {
chudy@google.com607357f2012-08-07 16:12:23 +0000605 fPause = isPaused;
606 fPausedRow = fListWidget.currentRow();
607 fCanvasWidget.drawTo(fPausedRow);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000608 fImageWidget.draw();
chudy@google.com7dcae672012-07-09 20:26:53 +0000609}
610
chudy@google.com902ebe52012-06-29 14:21:22 +0000611void SkDebuggerGUI::registerListClick(QListWidgetItem *item) {
chudy@google.comd3058f52012-07-19 13:41:27 +0000612 if(!fLoading) {
613 int currentRow = fListWidget.currentRow();
chudy@google.comd3058f52012-07-19 13:41:27 +0000614
chudy@google.comea5488b2012-07-26 19:38:22 +0000615 if (currentRow != -1) {
616 if (!fPause) {
617 fCanvasWidget.drawTo(currentRow);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000618 fImageWidget.draw();
chudy@google.comd3058f52012-07-19 13:41:27 +0000619 }
chudy@google.com97cee972012-08-07 20:41:37 +0000620 SkTDArray<SkString*> *currInfo = fDebugger.getCommandInfo(
chudy@google.comea5488b2012-07-26 19:38:22 +0000621 currentRow);
622
623 /* TODO(chudy): Add command type before parameters. Rename v
624 * to something more informative. */
chudy@google.com97cee972012-08-07 20:41:37 +0000625 if (currInfo) {
chudy@google.comea5488b2012-07-26 19:38:22 +0000626 QString info;
627 info.append("<b>Parameters: </b><br/>");
chudy@google.com97cee972012-08-07 20:41:37 +0000628 for (int i = 0; i < currInfo->count(); i++) {
629
630 info.append(QString((*currInfo)[i]->c_str()));
chudy@google.comea5488b2012-07-26 19:38:22 +0000631 info.append("<br/>");
632 }
chudy@google.com6bd109a2012-08-14 19:34:13 +0000633 fInspectorWidget.setText(info, SkInspectorWidget::kDetail_TabType);
chudy@google.comea5488b2012-07-26 19:38:22 +0000634 fInspectorWidget.setDisabled(false);
chudy@google.comea5488b2012-07-26 19:38:22 +0000635 }
chudy@google.comd3058f52012-07-19 13:41:27 +0000636 }
chudy@google.comea5488b2012-07-26 19:38:22 +0000637
chudy@google.com902ebe52012-06-29 14:21:22 +0000638 }
639}
640
chudy@google.com9ca9bfe2012-07-12 21:58:14 +0000641void SkDebuggerGUI::selectCommand(int command) {
642 if (fPause) {
643 fListWidget.setCurrentRow(command);
644 }
645}
646
chudy@google.com902ebe52012-06-29 14:21:22 +0000647void SkDebuggerGUI::toggleBreakpoint() {
chudy@google.comc432f002012-07-10 13:19:25 +0000648 QListWidgetItem* item = fListWidget.currentItem();
chudy@google.com902ebe52012-06-29 14:21:22 +0000649 if (item->checkState() == Qt::Unchecked) {
650 item->setCheckState(Qt::Checked);
chudy@google.come565de42012-07-12 14:15:54 +0000651 item->setData(Qt::DecorationRole,
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000652 QPixmap(":/breakpoint_16x16.png"));
chudy@google.com902ebe52012-06-29 14:21:22 +0000653 } else {
chudy@google.com902ebe52012-06-29 14:21:22 +0000654 item->setCheckState(Qt::Unchecked);
chudy@google.come565de42012-07-12 14:15:54 +0000655 item->setData(Qt::DecorationRole,
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000656 QPixmap(":/blank.png"));
chudy@google.com902ebe52012-06-29 14:21:22 +0000657 }
658}
659
660void SkDebuggerGUI::toggleDirectory() {
chudy@google.com607357f2012-08-07 16:12:23 +0000661 fDirectoryWidget.setHidden(!fDirectoryWidget.isHidden());
chudy@google.com902ebe52012-06-29 14:21:22 +0000662}
663
664void SkDebuggerGUI::toggleFilter(QString string) {
chudy@google.comc432f002012-07-10 13:19:25 +0000665 for (int row = 0; row < fListWidget.count(); row++) {
666 QListWidgetItem *item = fListWidget.item(row);
chudy@google.com607357f2012-08-07 16:12:23 +0000667 item->setHidden(item->text() != string);
chudy@google.com902ebe52012-06-29 14:21:22 +0000668 }
669}
670
671void SkDebuggerGUI::setupUi(QMainWindow *SkDebuggerGUI) {
672 QIcon windowIcon;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000673 windowIcon.addFile(QString::fromUtf8(":/skia.png"), QSize(),
chudy@google.com7dcae672012-07-09 20:26:53 +0000674 QIcon::Normal, QIcon::Off);
chudy@google.com902ebe52012-06-29 14:21:22 +0000675 SkDebuggerGUI->setObjectName(QString::fromUtf8("SkDebuggerGUI"));
676 SkDebuggerGUI->resize(1200, 1000);
677 SkDebuggerGUI->setWindowIcon(windowIcon);
chudy@google.comc432f002012-07-10 13:19:25 +0000678 SkDebuggerGUI->setWindowTitle("Skia Debugger");
chudy@google.com902ebe52012-06-29 14:21:22 +0000679
chudy@google.come504de02012-07-16 18:35:23 +0000680 fActionOpen.setShortcuts(QKeySequence::Open);
chudy@google.comc432f002012-07-10 13:19:25 +0000681 fActionOpen.setText("Open");
chudy@google.com902ebe52012-06-29 14:21:22 +0000682
683 QIcon breakpoint;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000684 breakpoint.addFile(QString::fromUtf8(":/breakpoint.png"),
chudy@google.com7dcae672012-07-09 20:26:53 +0000685 QSize(), QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000686 fActionBreakpoint.setShortcut(QKeySequence(tr("Ctrl+B")));
chudy@google.comc432f002012-07-10 13:19:25 +0000687 fActionBreakpoint.setIcon(breakpoint);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000688 fActionBreakpoint.setText("Breakpoints");
chudy@google.com902ebe52012-06-29 14:21:22 +0000689
690 QIcon cancel;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000691 cancel.addFile(QString::fromUtf8(":/reload.png"), QSize(),
chudy@google.com7dcae672012-07-09 20:26:53 +0000692 QIcon::Normal, QIcon::Off);
chudy@google.comc432f002012-07-10 13:19:25 +0000693 fActionCancel.setIcon(cancel);
694 fActionCancel.setText("Clear Filter");
chudy@google.com902ebe52012-06-29 14:21:22 +0000695
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000696 fActionClearBreakpoints.setShortcut(QKeySequence(tr("Alt+B")));
697 fActionClearBreakpoints.setText("Clear Breakpoints");
698
699 fActionClearDeletes.setShortcut(QKeySequence(tr("Alt+X")));
700 fActionClearDeletes.setText("Clear Deletes");
701
chudy@google.come504de02012-07-16 18:35:23 +0000702 fActionClose.setShortcuts(QKeySequence::Quit);
chudy@google.comc432f002012-07-10 13:19:25 +0000703 fActionClose.setText("Exit");
chudy@google.com902ebe52012-06-29 14:21:22 +0000704
chudy@google.come504de02012-07-16 18:35:23 +0000705 fActionCreateBreakpoint.setShortcut(QKeySequence(tr("B")));
706 fActionCreateBreakpoint.setText("Set Breakpoint");
707
708 fActionDelete.setShortcut(QKeySequence(tr("X")));
chudy@google.comc432f002012-07-10 13:19:25 +0000709 fActionDelete.setText("Delete Command");
chudy@google.com902ebe52012-06-29 14:21:22 +0000710
chudy@google.come504de02012-07-16 18:35:23 +0000711 fActionDirectory.setShortcut(QKeySequence(tr("Ctrl+D")));
712 fActionDirectory.setText("Directory");
chudy@google.com902ebe52012-06-29 14:21:22 +0000713
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000714 QIcon profile;
robertphillips@google.comd1636362012-11-19 18:25:09 +0000715 profile.addFile(QString::fromUtf8(":/profile.png"), QSize(),
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000716 QIcon::Normal, QIcon::Off);
717 fActionProfile.setIcon(profile);
718 fActionProfile.setText("Profile");
robertphillips@google.come099bc42012-11-19 16:26:40 +0000719 fActionProfile.setDisabled(true);
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000720
chudy@google.comc432f002012-07-10 13:19:25 +0000721 QIcon inspector;
robertphillips@google.comd1636362012-11-19 18:25:09 +0000722 inspector.addFile(QString::fromUtf8(":/inspector.png"),
chudy@google.comc432f002012-07-10 13:19:25 +0000723 QSize(), QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000724 fActionInspector.setShortcut(QKeySequence(tr("Ctrl+I")));
chudy@google.comc432f002012-07-10 13:19:25 +0000725 fActionInspector.setIcon(inspector);
chudy@google.come504de02012-07-16 18:35:23 +0000726 fActionInspector.setText("Inspector");
chudy@google.com902ebe52012-06-29 14:21:22 +0000727
chudy@google.comc432f002012-07-10 13:19:25 +0000728 QIcon play;
robertphillips@google.comd1636362012-11-19 18:25:09 +0000729 play.addFile(QString::fromUtf8(":/play.png"), QSize(),
chudy@google.comc432f002012-07-10 13:19:25 +0000730 QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000731 fActionPlay.setShortcut(QKeySequence(tr("Ctrl+P")));
chudy@google.comc432f002012-07-10 13:19:25 +0000732 fActionPlay.setIcon(play);
733 fActionPlay.setText("Play");
chudy@google.com902ebe52012-06-29 14:21:22 +0000734
chudy@google.come504de02012-07-16 18:35:23 +0000735 QIcon pause;
robertphillips@google.comd1636362012-11-19 18:25:09 +0000736 pause.addFile(QString::fromUtf8(":/pause.png"), QSize(),
chudy@google.comc432f002012-07-10 13:19:25 +0000737 QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000738 fActionPause.setShortcut(QKeySequence(tr("Space")));
739 fActionPause.setCheckable(true);
740 fActionPause.setIcon(pause);
741 fActionPause.setText("Pause");
742
chudy@google.comc432f002012-07-10 13:19:25 +0000743 QIcon rewind;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000744 rewind.addFile(QString::fromUtf8(":/rewind.png"), QSize(),
chudy@google.comc432f002012-07-10 13:19:25 +0000745 QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000746 fActionRewind.setShortcut(QKeySequence(tr("Ctrl+R")));
chudy@google.comc432f002012-07-10 13:19:25 +0000747 fActionRewind.setIcon(rewind);
748 fActionRewind.setText("Rewind");
chudy@google.com902ebe52012-06-29 14:21:22 +0000749
chudy@google.com0ab03392012-07-28 20:16:11 +0000750 fActionSave.setShortcut(QKeySequence::Save);
751 fActionSave.setText("Save");
752 fActionSave.setDisabled(true);
753 fActionSaveAs.setShortcut(QKeySequence::SaveAs);
754 fActionSaveAs.setText("Save As");
755 fActionSaveAs.setDisabled(true);
756
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000757 fActionShowDeletes.setShortcut(QKeySequence(tr("Ctrl+X")));
758 fActionShowDeletes.setText("Deleted Commands");
759
chudy@google.comc432f002012-07-10 13:19:25 +0000760 QIcon stepBack;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000761 stepBack.addFile(QString::fromUtf8(":/previous.png"), QSize(),
chudy@google.comc432f002012-07-10 13:19:25 +0000762 QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000763 fActionStepBack.setShortcut(QKeySequence(tr("[")));
chudy@google.comc432f002012-07-10 13:19:25 +0000764 fActionStepBack.setIcon(stepBack);
765 fActionStepBack.setText("Step Back");
chudy@google.com902ebe52012-06-29 14:21:22 +0000766
chudy@google.comc432f002012-07-10 13:19:25 +0000767 QIcon stepForward;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000768 stepForward.addFile(QString::fromUtf8(":/next.png"),
chudy@google.comc432f002012-07-10 13:19:25 +0000769 QSize(), QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000770 fActionStepForward.setShortcut(QKeySequence(tr("]")));
chudy@google.comc432f002012-07-10 13:19:25 +0000771 fActionStepForward.setIcon(stepForward);
772 fActionStepForward.setText("Step Forward");
773
chudy@google.coma1226312012-07-26 20:26:44 +0000774 fActionZoomIn.setShortcut(QKeySequence(tr("Ctrl+=")));
775 fActionZoomIn.setText("Zoom In");
776 fActionZoomOut.setShortcut(QKeySequence(tr("Ctrl+-")));
777 fActionZoomOut.setText("Zoom Out");
778
chudy@google.comc432f002012-07-10 13:19:25 +0000779 fListWidget.setItemDelegate(new SkListWidget(&fListWidget));
780 fListWidget.setObjectName(QString::fromUtf8("listWidget"));
781 fListWidget.setMaximumWidth(250);
782
783 fFilter.addItem("--Filter By Available Commands--");
784
785 fDirectoryWidget.setMaximumWidth(250);
786 fDirectoryWidget.setStyleSheet("QListWidget::Item {padding: 5px;}");
787
788 fCanvasWidget.setSizePolicy(QSizePolicy::Expanding,
chudy@google.com7dcae672012-07-09 20:26:53 +0000789 QSizePolicy::Expanding);
chudy@google.com902ebe52012-06-29 14:21:22 +0000790
skia.committer@gmail.com1c9c0d32012-11-22 02:02:41 +0000791 fImageWidget.setFixedSize(SkImageWidget::kImageWidgetWidth,
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000792 SkImageWidget::kImageWidgetHeight);
793
chudy@google.comc432f002012-07-10 13:19:25 +0000794 fInspectorWidget.setSizePolicy(QSizePolicy::Expanding,
chudy@google.com7dcae672012-07-09 20:26:53 +0000795 QSizePolicy::Expanding);
chudy@google.comc432f002012-07-10 13:19:25 +0000796 fInspectorWidget.setMaximumHeight(300);
chudy@google.com902ebe52012-06-29 14:21:22 +0000797
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000798 fSettingsAndImageLayout.setSpacing(6);
799 fSettingsAndImageLayout.addWidget(&fSettingsWidget);
800 fSettingsAndImageLayout.addWidget(&fImageWidget);
801
chudy@google.comc432f002012-07-10 13:19:25 +0000802 fSettingsWidget.setSizePolicy(QSizePolicy::Expanding,
803 QSizePolicy::Expanding);
804 fSettingsWidget.setMaximumWidth(250);
chudy@google.com902ebe52012-06-29 14:21:22 +0000805
chudy@google.comc432f002012-07-10 13:19:25 +0000806 fLeftColumnLayout.setSpacing(6);
807 fLeftColumnLayout.addWidget(&fListWidget);
808 fLeftColumnLayout.addWidget(&fDirectoryWidget);
chudy@google.com902ebe52012-06-29 14:21:22 +0000809
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000810 fCanvasSettingsAndImageLayout.setSpacing(6);
811 fCanvasSettingsAndImageLayout.addWidget(&fCanvasWidget);
812 fCanvasSettingsAndImageLayout.addLayout(&fSettingsAndImageLayout);
813
chudy@google.com902ebe52012-06-29 14:21:22 +0000814
chudy@google.comc432f002012-07-10 13:19:25 +0000815 fMainAndRightColumnLayout.setSpacing(6);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000816 fMainAndRightColumnLayout.addLayout(&fCanvasSettingsAndImageLayout);
chudy@google.comc432f002012-07-10 13:19:25 +0000817 fMainAndRightColumnLayout.addWidget(&fInspectorWidget);
chudy@google.com902ebe52012-06-29 14:21:22 +0000818
chudy@google.com2d537a12012-07-31 12:49:52 +0000819 fCentralWidget.setLayout(&fContainerLayout);
chudy@google.comc432f002012-07-10 13:19:25 +0000820 fContainerLayout.setSpacing(6);
821 fContainerLayout.setContentsMargins(11, 11, 11, 11);
822 fContainerLayout.addLayout(&fLeftColumnLayout);
823 fContainerLayout.addLayout(&fMainAndRightColumnLayout);
824
825 SkDebuggerGUI->setCentralWidget(&fCentralWidget);
826 SkDebuggerGUI->setStatusBar(&fStatusBar);
827
chudy@google.come504de02012-07-16 18:35:23 +0000828 fToolBar.setIconSize(QSize(32, 32));
chudy@google.comc432f002012-07-10 13:19:25 +0000829 fToolBar.setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
830 SkDebuggerGUI->addToolBar(Qt::TopToolBarArea, &fToolBar);
chudy@google.com902ebe52012-06-29 14:21:22 +0000831
chudy@google.com0ab03392012-07-28 20:16:11 +0000832 fSpacer.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
chudy@google.com902ebe52012-06-29 14:21:22 +0000833
chudy@google.comc432f002012-07-10 13:19:25 +0000834 fToolBar.addAction(&fActionRewind);
835 fToolBar.addAction(&fActionStepBack);
chudy@google.come504de02012-07-16 18:35:23 +0000836 fToolBar.addAction(&fActionPause);
chudy@google.comc432f002012-07-10 13:19:25 +0000837 fToolBar.addAction(&fActionStepForward);
838 fToolBar.addAction(&fActionPlay);
839 fToolBar.addSeparator();
chudy@google.come504de02012-07-16 18:35:23 +0000840 fToolBar.addAction(&fActionInspector);
chudy@google.comc432f002012-07-10 13:19:25 +0000841 fToolBar.addSeparator();
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000842 fToolBar.addAction(&fActionProfile);
843
844 fToolBar.addSeparator();
chudy@google.com0ab03392012-07-28 20:16:11 +0000845 fToolBar.addWidget(&fSpacer);
chudy@google.comc432f002012-07-10 13:19:25 +0000846 fToolBar.addWidget(&fFilter);
847 fToolBar.addAction(&fActionCancel);
chudy@google.com902ebe52012-06-29 14:21:22 +0000848
849 // TODO(chudy): Remove static call.
850 fDirectoryWidgetActive = false;
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000851 fFileName = "";
robertphillips@google.comff6e6ba2013-01-28 17:43:26 +0000852 setupDirectoryWidget("");
chudy@google.com902ebe52012-06-29 14:21:22 +0000853 fDirectoryWidgetActive = true;
854
chudy@google.com902ebe52012-06-29 14:21:22 +0000855 // Menu Bar
chudy@google.comc432f002012-07-10 13:19:25 +0000856 fMenuFile.setTitle("File");
857 fMenuFile.addAction(&fActionOpen);
chudy@google.com0ab03392012-07-28 20:16:11 +0000858 fMenuFile.addAction(&fActionSave);
859 fMenuFile.addAction(&fActionSaveAs);
chudy@google.comc432f002012-07-10 13:19:25 +0000860 fMenuFile.addAction(&fActionClose);
chudy@google.come504de02012-07-16 18:35:23 +0000861
862 fMenuEdit.setTitle("Edit");
863 fMenuEdit.addAction(&fActionDelete);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000864 fMenuEdit.addAction(&fActionClearDeletes);
865 fMenuEdit.addSeparator();
chudy@google.come504de02012-07-16 18:35:23 +0000866 fMenuEdit.addAction(&fActionCreateBreakpoint);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000867 fMenuEdit.addAction(&fActionClearBreakpoints);
chudy@google.come504de02012-07-16 18:35:23 +0000868
chudy@google.comc432f002012-07-10 13:19:25 +0000869 fMenuNavigate.setTitle("Navigate");
chudy@google.come504de02012-07-16 18:35:23 +0000870 fMenuNavigate.addAction(&fActionRewind);
871 fMenuNavigate.addAction(&fActionStepBack);
872 fMenuNavigate.addAction(&fActionStepForward);
873 fMenuNavigate.addAction(&fActionPlay);
874 fMenuNavigate.addAction(&fActionPause);
chudy@google.comc432f002012-07-10 13:19:25 +0000875 fMenuNavigate.addAction(&fActionGoToLine);
chudy@google.come504de02012-07-16 18:35:23 +0000876
chudy@google.comc432f002012-07-10 13:19:25 +0000877 fMenuView.setTitle("View");
chudy@google.come504de02012-07-16 18:35:23 +0000878 fMenuView.addAction(&fActionBreakpoint);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000879 fMenuView.addAction(&fActionShowDeletes);
chudy@google.coma1226312012-07-26 20:26:44 +0000880 fMenuView.addAction(&fActionZoomIn);
881 fMenuView.addAction(&fActionZoomOut);
chudy@google.come504de02012-07-16 18:35:23 +0000882
883 fMenuWindows.setTitle("Window");
884 fMenuWindows.addAction(&fActionInspector);
885 fMenuWindows.addAction(&fActionDirectory);
chudy@google.comc432f002012-07-10 13:19:25 +0000886
887 fActionGoToLine.setText("Go to Line...");
888 fActionGoToLine.setDisabled(true);
889 fMenuBar.addAction(fMenuFile.menuAction());
chudy@google.come504de02012-07-16 18:35:23 +0000890 fMenuBar.addAction(fMenuEdit.menuAction());
chudy@google.comc432f002012-07-10 13:19:25 +0000891 fMenuBar.addAction(fMenuView.menuAction());
892 fMenuBar.addAction(fMenuNavigate.menuAction());
chudy@google.come504de02012-07-16 18:35:23 +0000893 fMenuBar.addAction(fMenuWindows.menuAction());
chudy@google.com902ebe52012-06-29 14:21:22 +0000894
chudy@google.com7dcae672012-07-09 20:26:53 +0000895 fPause = false;
896
chudy@google.comc432f002012-07-10 13:19:25 +0000897 SkDebuggerGUI->setMenuBar(&fMenuBar);
chudy@google.com902ebe52012-06-29 14:21:22 +0000898 QMetaObject::connectSlotsByName(SkDebuggerGUI);
899}
900
robertphillips@google.comff6e6ba2013-01-28 17:43:26 +0000901void SkDebuggerGUI::setupDirectoryWidget(const QString& path) {
902 fPath = path;
903 QDir dir(path);
chudy@google.com902ebe52012-06-29 14:21:22 +0000904 QRegExp r(".skp");
chudy@google.comc432f002012-07-10 13:19:25 +0000905 fDirectoryWidget.clear();
906 const QStringList files = dir.entryList();
chudy@google.com902ebe52012-06-29 14:21:22 +0000907 foreach (QString f, files) {
chudy@google.com7dcae672012-07-09 20:26:53 +0000908 if (f.contains(r))
chudy@google.comc432f002012-07-10 13:19:25 +0000909 fDirectoryWidget.addItem(f);
chudy@google.com902ebe52012-06-29 14:21:22 +0000910 }
911}
912
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000913// SkOffsetPicturePlayback records the offset of each command in the picture.
914// These are needed by the profiling system.
915class SkOffsetPicturePlayback : public SkPicturePlayback {
916public:
917 SkOffsetPicturePlayback(SkStream* stream, const SkPictInfo& info, bool* isValid,
918 SkSerializationHelpers::DecodeBitmap decoder)
919 : INHERITED(stream, info, isValid, decoder) {
920 }
921
922 const SkTDArray<size_t>& offsets() const { return fOffsets; }
923
924protected:
925 SkTDArray<size_t> fOffsets;
926
robertphillips@google.comca47aae2012-12-12 15:58:25 +0000927 virtual size_t preDraw(size_t offset, int type) {
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000928 *fOffsets.append() = offset;
robertphillips@google.com5f971142012-12-07 20:48:56 +0000929 return 0;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000930 }
931
932private:
933 typedef SkPicturePlayback INHERITED;
934};
935
936// Picture to wrap an SkOffsetPicturePlayback.
937class SkOffsetPicture : public SkPicture {
938public:
skia.committer@gmail.com884e60b2012-11-16 02:01:17 +0000939 SkOffsetPicture(SkStream* stream,
940 bool* success,
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000941 SkSerializationHelpers::DecodeBitmap decoder) {
942 if (success) {
943 *success = false;
944 }
945 fRecord = NULL;
946 fPlayback = NULL;
947 fWidth = fHeight = 0;
948
949 SkPictInfo info;
950
951 if (!stream->read(&info, sizeof(info))) {
952 return;
953 }
954 if (PICTURE_VERSION != info.fVersion) {
955 return;
956 }
957
958 if (stream->readBool()) {
959 bool isValid = false;
960 fPlayback = SkNEW_ARGS(SkOffsetPicturePlayback, (stream, info, &isValid, decoder));
961 if (!isValid) {
962 SkDELETE(fPlayback);
963 fPlayback = NULL;
964 return;
965 }
966 }
967
968 // do this at the end, so that they will be zero if we hit an error.
969 fWidth = info.fWidth;
970 fHeight = info.fHeight;
971 if (success) {
972 *success = true;
973 }
974 }
975
skia.committer@gmail.com884e60b2012-11-16 02:01:17 +0000976 const SkTDArray<size_t>& offsets() const {
977 return ((SkOffsetPicturePlayback*) fPlayback)->offsets();
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000978 }
979
980private:
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000981 // disallow default ctor b.c. we don't have a good way to setup the fPlayback ptr
982 SkOffsetPicture();
983 // disallow the copy ctor - enabling would require copying code from SkPicture
984 SkOffsetPicture(const SkOffsetPicture& src);
985
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000986 typedef SkPicture INHERITED;
987};
988
989
990
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000991void SkDebuggerGUI::loadPicture(const SkString& fileName) {
992 fFileName = fileName;
chudy@google.comd3058f52012-07-19 13:41:27 +0000993 fLoading = true;
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000994 SkStream* stream = SkNEW_ARGS(SkFILEStream, (fileName.c_str()));
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000995 SkOffsetPicture* picture = SkNEW_ARGS(SkOffsetPicture, (stream, NULL, &SkImageDecoder::DecodeStream));
996
chudy@google.com686e6802012-08-14 16:00:32 +0000997 fCanvasWidget.resetWidgetTransform();
chudy@google.com607357f2012-08-07 16:12:23 +0000998 fDebugger.loadPicture(picture);
chudy@google.com4c7962e2012-08-14 19:38:31 +0000999
robertphillips@google.com2bde91d2012-11-15 14:57:57 +00001000 fOffsets = picture->offsets();
1001
robertphillips@google.com5f971142012-12-07 20:48:56 +00001002 fSkipCommands.setCount(fOffsets.count());
1003 for (int i = 0; i < fOffsets.count(); ++i) {
1004 fSkipCommands[i] = false;
1005 }
1006
chudy@google.com607357f2012-08-07 16:12:23 +00001007 SkSafeUnref(stream);
1008 SkSafeUnref(picture);
1009
chudy@google.com97cee972012-08-07 20:41:37 +00001010 // Will this automatically clear out due to nature of refcnt?
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +00001011 SkTArray<SkString>* commands = fDebugger.getDrawCommandsAsStrings();
chudy@google.com607357f2012-08-07 16:12:23 +00001012
robertphillips@google.comfe830a42012-11-15 16:33:31 +00001013 // If SkPicturePlayback is compiled w/o SK_PICTURE_PROFILING_STUBS
1014 // the offset count will always be zero
1015 SkASSERT(0 == fOffsets.count() || commands->count() == fOffsets.count());
robertphillips@google.come099bc42012-11-19 16:26:40 +00001016 if (commands->count() == fOffsets.count()) {
1017 fActionProfile.setDisabled(false);
robertphillips@google.comfe830a42012-11-15 16:33:31 +00001018 }
robertphillips@google.com2bde91d2012-11-15 14:57:57 +00001019
chudy@google.com7dcae672012-07-09 20:26:53 +00001020 /* fDebugCanvas is reinitialized every load picture. Need it to retain value
chudy@google.com607357f2012-08-07 16:12:23 +00001021 * of the visibility filter.
1022 * TODO(chudy): This should be deprecated since fDebugger is not
1023 * recreated.
1024 * */
1025 fDebugger.highlightCurrentCommand(fSettingsWidget.getVisibilityButton()->isChecked());
1026
chudy@google.com97cee972012-08-07 20:41:37 +00001027 setupListWidget(commands);
1028 setupComboBox(commands);
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +00001029 setupOverviewText(NULL, 0.0);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +00001030 fInspectorWidget.setDisabled(false);
chudy@google.come606d6e2012-07-12 14:31:25 +00001031 fSettingsWidget.setDisabled(false);
chudy@google.comd3058f52012-07-19 13:41:27 +00001032 fMenuEdit.setDisabled(false);
1033 fMenuNavigate.setDisabled(false);
1034 fMenuView.setDisabled(false);
chudy@google.com0ab03392012-07-28 20:16:11 +00001035 fActionSave.setDisabled(false);
1036 fActionSaveAs.setDisabled(false);
chudy@google.comd3058f52012-07-19 13:41:27 +00001037 fLoading = false;
1038 actionPlay();
chudy@google.com902ebe52012-06-29 14:21:22 +00001039}
1040
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +00001041void SkDebuggerGUI::setupListWidget(SkTArray<SkString>* command) {
chudy@google.comc432f002012-07-10 13:19:25 +00001042 fListWidget.clear();
chudy@google.com902ebe52012-06-29 14:21:22 +00001043 int counter = 0;
robertphillips@google.com30d35f22012-11-06 16:45:36 +00001044 int indent = 0;
chudy@google.com97cee972012-08-07 20:41:37 +00001045 for (int i = 0; i < command->count(); i++) {
chudy@google.com902ebe52012-06-29 14:21:22 +00001046 QListWidgetItem *item = new QListWidgetItem();
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +00001047 item->setData(Qt::DisplayRole, (*command)[i].c_str());
chudy@google.com902ebe52012-06-29 14:21:22 +00001048 item->setData(Qt::UserRole + 1, counter++);
robertphillips@google.com30d35f22012-11-06 16:45:36 +00001049
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +00001050 if (0 == strcmp("Restore", (*command)[i].c_str())) {
robertphillips@google.com30d35f22012-11-06 16:45:36 +00001051 indent -= 10;
1052 }
1053
1054 item->setData(Qt::UserRole + 3, indent);
1055
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +00001056 if (0 == strcmp("Save", (*command)[i].c_str()) ||
1057 0 == strcmp("Save Layer", (*command)[i].c_str())) {
robertphillips@google.com30d35f22012-11-06 16:45:36 +00001058 indent += 10;
1059 }
1060
robertphillips@google.comd26c7062012-11-12 20:42:12 +00001061 item->setData(Qt::UserRole + 4, -1.0);
1062
chudy@google.comc432f002012-07-10 13:19:25 +00001063 fListWidget.addItem(item);
chudy@google.com902ebe52012-06-29 14:21:22 +00001064 }
1065}
1066
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +00001067void SkDebuggerGUI::setupOverviewText(const SkTDArray<double>* typeTimes, double totTime) {
chudy@google.com902ebe52012-06-29 14:21:22 +00001068
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +00001069 const SkTDArray<SkDrawCommand*>& commands = fDebugger.getDrawCommands();
1070
1071 SkTDArray<int> counts;
1072 counts.setCount(LAST_DRAWTYPE_ENUM+1);
1073 for (int i = 0; i < LAST_DRAWTYPE_ENUM+1; ++i) {
1074 counts[i] = 0;
1075 }
1076
1077 for (int i = 0; i < commands.count(); i++) {
1078 counts[commands[i]->getType()]++;
chudy@google.com902ebe52012-06-29 14:21:22 +00001079 }
1080
1081 QString overview;
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +00001082 int total = 0;
1083#ifdef SK_DEBUG
1084 double totPercent = 0, tempSum = 0;
1085#endif
1086 for (int i = 0; i < LAST_DRAWTYPE_ENUM+1; ++i) {
1087 if (0 == counts[i]) {
1088 // if there were no commands of this type then they should've consumed no time
1089 SkASSERT(NULL == typeTimes || 0.0 == (*typeTimes)[i]);
1090 continue;
1091 }
1092
1093 overview.append(SkDrawCommand::GetCommandString((DrawType) i));
chudy@google.com902ebe52012-06-29 14:21:22 +00001094 overview.append(": ");
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +00001095 overview.append(QString::number(counts[i]));
1096 if (NULL != typeTimes) {
1097 overview.append(" - ");
1098 overview.append(QString::number((*typeTimes)[i], 'f', 1));
1099 overview.append("ms");
1100 overview.append(" - ");
1101 double percent = 100.0*(*typeTimes)[i]/totTime;
1102 overview.append(QString::number(percent, 'f', 1));
1103 overview.append("%");
1104#ifdef SK_DEBUG
1105 totPercent += percent;
1106 tempSum += (*typeTimes)[i];
1107#endif
1108 }
chudy@google.com902ebe52012-06-29 14:21:22 +00001109 overview.append("<br/>");
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +00001110 total += counts[i];
chudy@google.com902ebe52012-06-29 14:21:22 +00001111 }
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +00001112#ifdef SK_DEBUG
1113 if (NULL != typeTimes) {
1114 SkASSERT(SkScalarNearlyEqual(totPercent, 100.0));
1115 SkASSERT(SkScalarNearlyEqual(tempSum, totTime));
1116 }
1117#endif
1118
1119 if (totTime > 0.0) {
1120 overview.append("Total Time: ");
1121 overview.append(QString::number(totTime, 'f', 2));
1122 overview.append("ms");
1123#ifdef SK_DEBUG
1124 overview.append(" ");
1125 overview.append(QString::number(totPercent));
1126 overview.append("% ");
1127#endif
1128 overview.append("<br/>");
1129 }
1130
1131 QString totalStr;
1132 totalStr.append("Total Draw Commands: ");
1133 totalStr.append(QString::number(total));
1134 totalStr.append("<br/>");
1135 overview.insert(0, totalStr);
chudy@google.com902ebe52012-06-29 14:21:22 +00001136
1137 overview.append("<br/>");
chudy@google.com607357f2012-08-07 16:12:23 +00001138 overview.append("SkPicture Width: ");
chudy@google.com902ebe52012-06-29 14:21:22 +00001139 // NOTE(chudy): This is where we can pull out the SkPictures width.
chudy@google.com607357f2012-08-07 16:12:23 +00001140 overview.append(QString::number(fDebugger.pictureWidth()));
chudy@google.com902ebe52012-06-29 14:21:22 +00001141 overview.append("px<br/>");
chudy@google.com607357f2012-08-07 16:12:23 +00001142 overview.append("SkPicture Height: ");
1143 overview.append(QString::number(fDebugger.pictureHeight()));
chudy@google.com902ebe52012-06-29 14:21:22 +00001144 overview.append("px");
chudy@google.com6bd109a2012-08-14 19:34:13 +00001145 fInspectorWidget.setText(overview, SkInspectorWidget::kOverview_TabType);
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +00001146}
1147
1148void SkDebuggerGUI::setupComboBox(SkTArray<SkString>* command) {
1149 fFilter.clear();
1150 fFilter.addItem("--Filter By Available Commands--");
1151
1152 std::map<std::string, int> map;
1153 for (int i = 0; i < command->count(); i++) {
1154 map[(*command)[i].c_str()]++;
1155 }
1156
skia.committer@gmail.com34587162012-11-20 02:01:23 +00001157 for (std::map<std::string, int>::iterator it = map.begin(); it != map.end();
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +00001158 ++it) {
1159 fFilter.addItem((it->first).c_str());
1160 }
chudy@google.com902ebe52012-06-29 14:21:22 +00001161
1162 // NOTE(chudy): Makes first item unselectable.
chudy@google.com7dcae672012-07-09 20:26:53 +00001163 QStandardItemModel* model = qobject_cast<QStandardItemModel*>(
chudy@google.comc432f002012-07-10 13:19:25 +00001164 fFilter.model());
1165 QModelIndex firstIndex = model->index(0, fFilter.modelColumn(),
1166 fFilter.rootModelIndex());
chudy@google.com902ebe52012-06-29 14:21:22 +00001167 QStandardItem* firstItem = model->itemFromIndex(firstIndex);
1168 firstItem->setSelectable(false);
1169}