blob: 3b9b8aaefb3e20a760321691e4de70cf6ae1b0a4 [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"
15#include "BenchTimer.h"
chudy@google.com902ebe52012-06-29 14:21:22 +000016
17SkDebuggerGUI::SkDebuggerGUI(QWidget *parent) :
chudy@google.comc432f002012-07-10 13:19:25 +000018 QMainWindow(parent)
chudy@google.com2d537a12012-07-31 12:49:52 +000019 , fCentralWidget(this)
20 , fStatusBar(this)
21 , fToolBar(this)
chudy@google.comc432f002012-07-10 13:19:25 +000022 , fActionOpen(this)
23 , fActionBreakpoint(this)
robertphillips@google.comd26c7062012-11-12 20:42:12 +000024 , fActionProfile(this)
chudy@google.comc432f002012-07-10 13:19:25 +000025 , fActionCancel(this)
chudy@google.com7e4cfbf2012-07-17 15:40:51 +000026 , fActionClearBreakpoints(this)
chudy@google.come504de02012-07-16 18:35:23 +000027 , fActionClearDeletes(this)
chudy@google.comc432f002012-07-10 13:19:25 +000028 , fActionClose(this)
chudy@google.come504de02012-07-16 18:35:23 +000029 , fActionCreateBreakpoint(this)
chudy@google.comc432f002012-07-10 13:19:25 +000030 , fActionDelete(this)
31 , fActionDirectory(this)
32 , fActionGoToLine(this)
33 , fActionInspector(this)
34 , fActionPlay(this)
chudy@google.come504de02012-07-16 18:35:23 +000035 , fActionPause(this)
chudy@google.comc432f002012-07-10 13:19:25 +000036 , fActionRewind(this)
chudy@google.com0ab03392012-07-28 20:16:11 +000037 , fActionSave(this)
38 , fActionSaveAs(this)
chudy@google.com7e4cfbf2012-07-17 15:40:51 +000039 , fActionShowDeletes(this)
chudy@google.comc432f002012-07-10 13:19:25 +000040 , fActionStepBack(this)
41 , fActionStepForward(this)
chudy@google.coma1226312012-07-26 20:26:44 +000042 , fActionZoomIn(this)
43 , fActionZoomOut(this)
44 , fMapper(this)
chudy@google.comc432f002012-07-10 13:19:25 +000045 , fListWidget(&fCentralWidget)
46 , fDirectoryWidget(&fCentralWidget)
chudy@google.com607357f2012-08-07 16:12:23 +000047 , fCanvasWidget(this, &fDebugger)
chudy@google.comc432f002012-07-10 13:19:25 +000048 , fMenuBar(this)
49 , fMenuFile(this)
50 , fMenuNavigate(this)
51 , fMenuView(this)
chudy@google.com7e4cfbf2012-07-17 15:40:51 +000052 , fBreakpointsActivated(false)
53 , fDeletesActivated(false)
54 , fPause(false)
chudy@google.comd3058f52012-07-19 13:41:27 +000055 , fLoading(false)
chudy@google.comc432f002012-07-10 13:19:25 +000056{
chudy@google.com902ebe52012-06-29 14:21:22 +000057 setupUi(this);
chudy@google.comea5488b2012-07-26 19:38:22 +000058 connect(&fListWidget, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)), this, SLOT(registerListClick(QListWidgetItem *)));
chudy@google.comc432f002012-07-10 13:19:25 +000059 connect(&fActionOpen, SIGNAL(triggered()), this, SLOT(openFile()));
chudy@google.comea5488b2012-07-26 19:38:22 +000060 connect(&fActionDirectory, SIGNAL(triggered()), this, SLOT(toggleDirectory()));
61 connect(&fDirectoryWidget, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)), this, SLOT(loadFile(QListWidgetItem *)));
chudy@google.comc432f002012-07-10 13:19:25 +000062 connect(&fActionDelete, SIGNAL(triggered()), this, SLOT(actionDelete()));
chudy@google.comea5488b2012-07-26 19:38:22 +000063 connect(&fListWidget, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(toggleBreakpoint()));
chudy@google.comc432f002012-07-10 13:19:25 +000064 connect(&fActionRewind, SIGNAL(triggered()), this, SLOT(actionRewind()));
65 connect(&fActionPlay, SIGNAL(triggered()), this, SLOT(actionPlay()));
66 connect(&fActionStepBack, SIGNAL(triggered()), this, SLOT(actionStepBack()));
chudy@google.comea5488b2012-07-26 19:38:22 +000067 connect(&fActionStepForward, SIGNAL(triggered()), this, SLOT(actionStepForward()));
68 connect(&fActionBreakpoint, SIGNAL(triggered()), this, SLOT(actionBreakpoints()));
69 connect(&fActionInspector, SIGNAL(triggered()), this, SLOT(actionInspector()));
70 connect(&fActionInspector, SIGNAL(triggered()), this, SLOT(actionSettings()));
71 connect(&fFilter, SIGNAL(activated(QString)), this, SLOT(toggleFilter(QString)));
robertphillips@google.comd26c7062012-11-12 20:42:12 +000072 connect(&fActionProfile, SIGNAL(triggered()), this, SLOT(actionProfile()));
chudy@google.comc432f002012-07-10 13:19:25 +000073 connect(&fActionCancel, SIGNAL(triggered()), this, SLOT(actionCancel()));
chudy@google.com7e4cfbf2012-07-17 15:40:51 +000074 connect(&fActionClearBreakpoints, SIGNAL(triggered()), this, SLOT(actionClearBreakpoints()));
75 connect(&fActionClearDeletes, SIGNAL(triggered()), this, SLOT(actionClearDeletes()));
chudy@google.comc432f002012-07-10 13:19:25 +000076 connect(&fActionClose, SIGNAL(triggered()), this, SLOT(actionClose()));
chudy@google.comea5488b2012-07-26 19:38:22 +000077 connect(fSettingsWidget.getVisibilityButton(), SIGNAL(toggled(bool)), this, SLOT(actionCommandFilter()));
78 connect(fSettingsWidget.getGLCheckBox(), SIGNAL(toggled(bool)), this, SLOT(actionGLWidget(bool)));
79 connect(fSettingsWidget.getRasterCheckBox(), SIGNAL(toggled(bool)), this, SLOT(actionRasterWidget(bool)));
80 connect(&fActionPause, SIGNAL(toggled(bool)), this, SLOT(pauseDrawing(bool)));
chudy@google.come504de02012-07-16 18:35:23 +000081 connect(&fActionCreateBreakpoint, SIGNAL(activated()), this, SLOT(toggleBreakpoint()));
chudy@google.com7e4cfbf2012-07-17 15:40:51 +000082 connect(&fActionShowDeletes, SIGNAL(triggered()), this, SLOT(showDeletes()));
chudy@google.comea5488b2012-07-26 19:38:22 +000083 connect(&fCanvasWidget, SIGNAL(hitChanged(int)), this, SLOT(selectCommand(int)));
84 connect(&fCanvasWidget, SIGNAL(hitChanged(int)), &fSettingsWidget, SLOT(updateHit(int)));
85 connect(&fCanvasWidget, SIGNAL(scaleFactorChanged(float)), this, SLOT(actionScale(float)));
86 connect(&fCanvasWidget, SIGNAL(commandChanged(int)), &fSettingsWidget, SLOT(updateCommand(int)));
chudy@google.com0ab03392012-07-28 20:16:11 +000087 connect(&fActionSaveAs, SIGNAL(triggered()), this, SLOT(actionSaveAs()));
88 connect(&fActionSave, SIGNAL(triggered()), this, SLOT(actionSave()));
chudy@google.com7e4cfbf2012-07-17 15:40:51 +000089
chudy@google.coma1226312012-07-26 20:26:44 +000090 fMapper.setMapping(&fActionZoomIn, 1);
91 fMapper.setMapping(&fActionZoomOut, -1);
92
93 connect(&fActionZoomIn, SIGNAL(triggered()), &fMapper, SLOT(map()));
94 connect(&fActionZoomOut, SIGNAL(triggered()), &fMapper, SLOT(map()));
95 connect(&fMapper, SIGNAL(mapped(int)), &fCanvasWidget, SLOT(keyZoom(int)));
96
chudy@google.com7e4cfbf2012-07-17 15:40:51 +000097 fInspectorWidget.setDisabled(true);
chudy@google.comd3058f52012-07-19 13:41:27 +000098 fMenuEdit.setDisabled(true);
99 fMenuNavigate.setDisabled(true);
100 fMenuView.setDisabled(true);
chudy@google.combbad34d2012-08-13 14:26:36 +0000101
102 SkGraphics::Init();
chudy@google.com902ebe52012-06-29 14:21:22 +0000103}
104
chudy@google.combbad34d2012-08-13 14:26:36 +0000105SkDebuggerGUI::~SkDebuggerGUI() {
106 SkGraphics::Term();
107}
chudy@google.com902ebe52012-06-29 14:21:22 +0000108
109void SkDebuggerGUI::actionBreakpoints() {
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000110 fBreakpointsActivated = !fBreakpointsActivated;
chudy@google.comc432f002012-07-10 13:19:25 +0000111 for (int row = 0; row < fListWidget.count(); row++) {
112 QListWidgetItem *item = fListWidget.item(row);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000113 item->setHidden(item->checkState() == Qt::Unchecked && fBreakpointsActivated);
114 }
115}
chudy@google.com902ebe52012-06-29 14:21:22 +0000116
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000117void SkDebuggerGUI::showDeletes() {
118 fDeletesActivated = !fDeletesActivated;
119 for (int row = 0; row < fListWidget.count(); row++) {
120 QListWidgetItem *item = fListWidget.item(row);
chudy@google.com607357f2012-08-07 16:12:23 +0000121 item->setHidden(fDebugger.isCommandVisible(row)
122 && fDeletesActivated);
chudy@google.com902ebe52012-06-29 14:21:22 +0000123 }
124}
125
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000126// The timed picture playback uses the SkPicturePlayback's profiling stubs
127// to time individual commands. The offsets are needed to map SkPicture
128// offsets to individual commands.
129class SkTimedPicturePlayback : public SkPicturePlayback {
130public:
131 SkTimedPicturePlayback(SkStream* stream, const SkPictInfo& info, bool* isValid,
132 SkSerializationHelpers::DecodeBitmap decoder,
skia.committer@gmail.com884e60b2012-11-16 02:01:17 +0000133 const SkTDArray<size_t>& offsets)
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000134 : INHERITED(stream, info, isValid, decoder)
135 , fTot(0.0)
136 , fCurCommand(0)
137 , fOffsets(offsets) {
138 fTimes.setCount(fOffsets.count());
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000139 fTypeTimes.setCount(LAST_DRAWTYPE_ENUM+1);
140 this->resetTimes();
141 }
142
143 void resetTimes() {
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000144 for (int i = 0; i < fOffsets.count(); ++i) {
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000145 fTimes[i] = 0.0;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000146 }
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000147 for (int i = 0; i < fTypeTimes.count(); ++i) {
148 fTypeTimes[i] = 0.0f;
149 }
150 fTot = 0.0;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000151 }
152
153 int count() const { return fTimes.count(); }
154
155 double time(int index) const { return fTimes[index] / fTot; }
156
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000157 const SkTDArray<double>* typeTimes() const { return &fTypeTimes; }
158
159 double totTime() const { return fTot; }
160
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000161protected:
162 BenchTimer fTimer;
163 SkTDArray<size_t> fOffsets; // offset in the SkPicture for each command
164 SkTDArray<double> fTimes; // sum of time consumed for each command
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000165 SkTDArray<double> fTypeTimes; // sum of time consumed for each type of command (e.g., drawPath)
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000166 double fTot; // total of all times in 'fTimes'
167 size_t fCurOffset;
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000168 int fCurType;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000169 int fCurCommand; // the current command being executed/timed
170
171 virtual void preDraw(size_t offset, int type) {
skia.committer@gmail.com884e60b2012-11-16 02:01:17 +0000172 // This search isn't as bad as it seems. In normal playback mode, the
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000173 // base class steps through the commands in order and can only skip ahead
skia.committer@gmail.com884e60b2012-11-16 02:01:17 +0000174 // a bit on a clip. This class is only used during profiling so we
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000175 // don't have to worry about forward/backward scrubbing through commands.
176 for (int i = 0; offset != fOffsets[fCurCommand]; ++i) {
177 fCurCommand = (fCurCommand+1) % fOffsets.count();
178 SkASSERT(i <= fOffsets.count()); // should always find the offset in the list
179 }
180
181 fCurOffset = offset;
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000182 fCurType = type;
183 // The SkDebugCanvas doesn't recognize these types. This class needs to
184 // convert or else we'll wind up with a mismatch between the type counts
185 // the debugger displays and the profile times.
186 if (DRAW_POS_TEXT_TOP_BOTTOM == type) {
187 fCurType = DRAW_POS_TEXT;
188 } else if (DRAW_POS_TEXT_H_TOP_BOTTOM == type) {
189 fCurType = DRAW_POS_TEXT_H;
190 }
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000191
192 fTimer.start();
193 }
194
195 virtual void postDraw(size_t offset) {
196 fTimer.end();
197
198 SkASSERT(offset == fCurOffset);
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000199 SkASSERT(fCurType <= LAST_DRAWTYPE_ENUM);
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000200
robertphillips@google.come099bc42012-11-19 16:26:40 +0000201#if defined(SK_BUILD_FOR_WIN32)
202 // CPU timer doesn't work well on Windows
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000203 fTimes[fCurCommand] += fTimer.fWall;
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000204 fTypeTimes[fCurType] += fTimer.fWall;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000205 fTot += fTimer.fWall;
robertphillips@google.come099bc42012-11-19 16:26:40 +0000206#else
207 fTimes[fCurCommand] += fTimer.fCpu;
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000208 fTypeTimes[fCurType] += fTimer.fCpu;
robertphillips@google.come099bc42012-11-19 16:26:40 +0000209 fTot += fTimer.fCpu;
210#endif
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000211 }
212
213private:
214 typedef SkPicturePlayback INHERITED;
215};
216
217// Wrap SkPicture to allow installation of an SkTimedPicturePlayback object
218class SkTimedPicture : public SkPicture {
219public:
220 explicit SkTimedPicture(SkStream* stream,
221 bool* success,
222 SkSerializationHelpers::DecodeBitmap decoder,
223 const SkTDArray<size_t>& offsets) {
224 if (success) {
225 *success = false;
226 }
227 fRecord = NULL;
228 fPlayback = NULL;
229 fWidth = fHeight = 0;
230
231 SkPictInfo info;
232
233 if (!stream->read(&info, sizeof(info))) {
234 return;
235 }
236 if (SkPicture::PICTURE_VERSION != info.fVersion) {
237 return;
238 }
239
240 if (stream->readBool()) {
241 bool isValid = false;
skia.committer@gmail.com884e60b2012-11-16 02:01:17 +0000242 fPlayback = SkNEW_ARGS(SkTimedPicturePlayback,
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000243 (stream, info, &isValid, decoder, offsets));
244 if (!isValid) {
245 SkDELETE(fPlayback);
246 fPlayback = NULL;
247 return;
248 }
249 }
250
251 // do this at the end, so that they will be zero if we hit an error.
252 fWidth = info.fWidth;
253 fHeight = info.fHeight;
254 if (success) {
255 *success = true;
256 }
257 }
258
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000259 void resetTimes() { ((SkTimedPicturePlayback*) fPlayback)->resetTimes(); }
260
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000261 int count() const { return ((SkTimedPicturePlayback*) fPlayback)->count(); }
262
263 // return the fraction of the total time this command consumed
264 double time(int index) const { return ((SkTimedPicturePlayback*) fPlayback)->time(index); }
265
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000266 const SkTDArray<double>* typeTimes() const { return ((SkTimedPicturePlayback*) fPlayback)->typeTimes(); }
267
268 double totTime() const { return ((SkTimedPicturePlayback*) fPlayback)->totTime(); }
269
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000270private:
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000271 // disallow default ctor b.c. we don't have a good way to setup the fPlayback ptr
272 SkTimedPicture();
273 // disallow the copy ctor - enabling would require copying code from SkPicture
274 SkTimedPicture(const SkTimedPicture& src);
275
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000276 typedef SkPicture INHERITED;
277};
278
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000279// This is a simplification of PictureBenchmark's run with the addition of
280// clearing of the times after the first pass (in resetTimes)
281void SkDebuggerGUI::run(SkTimedPicture* pict,
282 sk_tools::PictureRenderer* renderer,
283 int repeats) {
284 SkASSERT(pict);
285 if (NULL == pict) {
286 return;
287 }
288
289 SkASSERT(renderer != NULL);
290 if (NULL == renderer) {
291 return;
292 }
293
294 renderer->init(pict);
295
296 renderer->setup();
297 renderer->render(NULL);
298 renderer->resetState();
299
300 // We throw this away the first batch of times to remove first time effects (such as paging in this program)
301 pict->resetTimes();
302
303 for (int i = 0; i < repeats; ++i) {
304 renderer->setup();
305 renderer->render(NULL);
306 renderer->resetState();
307 }
308
309 renderer->end();
310}
311
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000312void SkDebuggerGUI::actionProfile() {
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000313 // In order to profile we pass the command offsets (that were read-in
314 // in loadPicture by the SkOffsetPicture) to an SkTimedPlaybackPicture.
skia.committer@gmail.com884e60b2012-11-16 02:01:17 +0000315 // The SkTimedPlaybackPicture in turn passes the offsets to an
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000316 // SkTimedPicturePlayback object which uses them to track the performance
317 // of individual commands.
318 if (fFileName.isEmpty()) {
319 return;
320 }
321
322 SkFILEStream inputStream;
323
324 inputStream.setPath(fFileName.c_str());
325 if (!inputStream.isValid()) {
326 return;
327 }
328
329 bool success = false;
330 SkTimedPicture picture(&inputStream, &success, &SkImageDecoder::DecodeStream, fOffsets);
331 if (!success) {
332 return;
333 }
334
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000335 // For now this #if allows switching between tiled and simple rendering
336 // modes. Eventually this will be accomplished via the GUI
337#if 1
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000338 sk_tools::TiledPictureRenderer* renderer = NULL;
339
340 renderer = SkNEW(sk_tools::TiledPictureRenderer);
341 renderer->setTileWidth(256);
342 renderer->setTileHeight(256);
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000343#else
344 sk_tools::SimplePictureRenderer* renderer = NULL;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000345
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000346 renderer = SkNEW(sk_tools::SimplePictureRenderer);
347#endif
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000348
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000349 run(&picture, renderer, 2);
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000350
351 SkASSERT(picture.count() == fListWidget.count());
352
353 // extract the individual command times from the SkTimedPlaybackPicture
354 for (int i = 0; i < picture.count(); ++i) {
355 double temp = picture.time(i);
356
357 QListWidgetItem* item = fListWidget.item(i);
358
359 item->setData(Qt::UserRole + 4, 100.0*temp);
360 }
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000361
362 setupOverviewText(picture.typeTimes(), picture.totTime());
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000363}
364
chudy@google.com902ebe52012-06-29 14:21:22 +0000365void SkDebuggerGUI::actionCancel() {
chudy@google.comc432f002012-07-10 13:19:25 +0000366 for (int row = 0; row < fListWidget.count(); row++) {
367 fListWidget.item(row)->setHidden(false);
chudy@google.com902ebe52012-06-29 14:21:22 +0000368 }
369}
370
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000371void SkDebuggerGUI::actionClearBreakpoints() {
372 for (int row = 0; row < fListWidget.count(); row++) {
373 QListWidgetItem* item = fListWidget.item(row);
374 item->setCheckState(Qt::Unchecked);
375 item->setData(Qt::DecorationRole,
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000376 QPixmap(":/blank.png"));
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000377 }
378}
379
380void SkDebuggerGUI::actionClearDeletes() {
381 for (int row = 0; row < fListWidget.count(); row++) {
382 QListWidgetItem* item = fListWidget.item(row);
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000383 item->setData(Qt::UserRole + 2, QPixmap(":/blank.png"));
chudy@google.com607357f2012-08-07 16:12:23 +0000384 fDebugger.setCommandVisible(row, true);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000385 }
386 if (fPause) {
387 fCanvasWidget.drawTo(fPausedRow);
388 } else {
389 fCanvasWidget.drawTo(fListWidget.currentRow());
390 }
391}
392
chudy@google.com902ebe52012-06-29 14:21:22 +0000393void SkDebuggerGUI::actionCommandFilter() {
chudy@google.com607357f2012-08-07 16:12:23 +0000394 fDebugger.highlightCurrentCommand(
chudy@google.comc432f002012-07-10 13:19:25 +0000395 fSettingsWidget.getVisibilityButton()->isChecked());
396 fCanvasWidget.drawTo(fListWidget.currentRow());
chudy@google.com902ebe52012-06-29 14:21:22 +0000397}
398
399void SkDebuggerGUI::actionClose() {
400 this->close();
401}
402
403void SkDebuggerGUI::actionDelete() {
chudy@google.comc432f002012-07-10 13:19:25 +0000404 int currentRow = fListWidget.currentRow();
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000405 QListWidgetItem* item = fListWidget.currentItem();
406
chudy@google.com607357f2012-08-07 16:12:23 +0000407 if (fDebugger.isCommandVisible(currentRow)) {
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000408 item->setData(Qt::UserRole + 2, QPixmap(":/delete.png"));
chudy@google.com607357f2012-08-07 16:12:23 +0000409 fDebugger.setCommandVisible(currentRow, false);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000410 } else {
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000411 item->setData(Qt::UserRole + 2, QPixmap(":/blank.png"));
chudy@google.com607357f2012-08-07 16:12:23 +0000412 fDebugger.setCommandVisible(currentRow, true);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000413 }
414
chudy@google.come504de02012-07-16 18:35:23 +0000415 if (fPause) {
416 fCanvasWidget.drawTo(fPausedRow);
417 } else {
418 fCanvasWidget.drawTo(currentRow);
419 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000420}
421
chudy@google.comea5488b2012-07-26 19:38:22 +0000422void SkDebuggerGUI::actionGLWidget(bool isToggled) {
423 fCanvasWidget.setWidgetVisibility(SkCanvasWidget::kGPU_WidgetType, !isToggled);
424}
425
chudy@google.com902ebe52012-06-29 14:21:22 +0000426void SkDebuggerGUI::actionInspector() {
chudy@google.comc432f002012-07-10 13:19:25 +0000427 if (fInspectorWidget.isHidden()) {
428 fInspectorWidget.setHidden(false);
chudy@google.com902ebe52012-06-29 14:21:22 +0000429 } else {
chudy@google.comc432f002012-07-10 13:19:25 +0000430 fInspectorWidget.setHidden(true);
chudy@google.com902ebe52012-06-29 14:21:22 +0000431 }
432}
433
434void SkDebuggerGUI::actionPlay() {
chudy@google.comc432f002012-07-10 13:19:25 +0000435 for (int row = fListWidget.currentRow() + 1; row < fListWidget.count();
chudy@google.com7dcae672012-07-09 20:26:53 +0000436 row++) {
chudy@google.comc432f002012-07-10 13:19:25 +0000437 QListWidgetItem *item = fListWidget.item(row);
chudy@google.com902ebe52012-06-29 14:21:22 +0000438 if (item->checkState() == Qt::Checked) {
chudy@google.comc432f002012-07-10 13:19:25 +0000439 fListWidget.setCurrentItem(item);
chudy@google.com902ebe52012-06-29 14:21:22 +0000440 return;
441 }
442 }
chudy@google.comc432f002012-07-10 13:19:25 +0000443 fListWidget.setCurrentRow(fListWidget.count() - 1);
chudy@google.com902ebe52012-06-29 14:21:22 +0000444}
445
chudy@google.comea5488b2012-07-26 19:38:22 +0000446void SkDebuggerGUI::actionRasterWidget(bool isToggled) {
447 fCanvasWidget.setWidgetVisibility(SkCanvasWidget::kRaster_8888_WidgetType, !isToggled);
448}
449
chudy@google.com902ebe52012-06-29 14:21:22 +0000450void SkDebuggerGUI::actionRewind() {
chudy@google.come504de02012-07-16 18:35:23 +0000451 fListWidget.setCurrentRow(0);
chudy@google.com902ebe52012-06-29 14:21:22 +0000452}
453
chudy@google.com0ab03392012-07-28 20:16:11 +0000454void SkDebuggerGUI::actionSave() {
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000455 fFileName = fPath.toAscii();
456 fFileName.append("/");
457 fFileName.append(fDirectoryWidget.currentItem()->text().toAscii());
458 saveToFile(fFileName);
chudy@google.com0ab03392012-07-28 20:16:11 +0000459}
460
461void SkDebuggerGUI::actionSaveAs() {
462 QString filename = QFileDialog::getSaveFileName(this, "Save File", "",
463 "Skia Picture (*skp)");
chudy@google.com38b08ce2012-07-28 23:26:10 +0000464 if (!filename.endsWith(".skp", Qt::CaseInsensitive)) {
chudy@google.com0ab03392012-07-28 20:16:11 +0000465 filename.append(".skp");
466 }
djsollen@google.comc3c82162012-11-13 18:35:10 +0000467 saveToFile(SkString(filename.toAscii().data()));
chudy@google.com0ab03392012-07-28 20:16:11 +0000468}
469
chudy@google.com7dcae672012-07-09 20:26:53 +0000470void SkDebuggerGUI::actionScale(float scaleFactor) {
chudy@google.comc432f002012-07-10 13:19:25 +0000471 fSettingsWidget.setZoomText(scaleFactor);
chudy@google.com7dcae672012-07-09 20:26:53 +0000472}
473
chudy@google.com902ebe52012-06-29 14:21:22 +0000474void SkDebuggerGUI::actionSettings() {
chudy@google.comc432f002012-07-10 13:19:25 +0000475 if (fSettingsWidget.isHidden()) {
476 fSettingsWidget.setHidden(false);
chudy@google.com902ebe52012-06-29 14:21:22 +0000477 } else {
chudy@google.comc432f002012-07-10 13:19:25 +0000478 fSettingsWidget.setHidden(true);
chudy@google.com902ebe52012-06-29 14:21:22 +0000479 }
480}
481
482void SkDebuggerGUI::actionStepBack() {
chudy@google.comc432f002012-07-10 13:19:25 +0000483 int currentRow = fListWidget.currentRow();
chudy@google.com902ebe52012-06-29 14:21:22 +0000484 if (currentRow != 0) {
chudy@google.comc432f002012-07-10 13:19:25 +0000485 fListWidget.setCurrentRow(currentRow - 1);
chudy@google.com902ebe52012-06-29 14:21:22 +0000486 }
487}
488
489void SkDebuggerGUI::actionStepForward() {
chudy@google.comc432f002012-07-10 13:19:25 +0000490 int currentRow = fListWidget.currentRow();
chudy@google.com902ebe52012-06-29 14:21:22 +0000491 QString curRow = QString::number(currentRow);
chudy@google.comc432f002012-07-10 13:19:25 +0000492 QString curCount = QString::number(fListWidget.count());
493 if (currentRow < fListWidget.count() - 1) {
494 fListWidget.setCurrentRow(currentRow + 1);
chudy@google.com902ebe52012-06-29 14:21:22 +0000495 }
496}
497
chudy@google.coma9e937c2012-08-03 17:32:05 +0000498void SkDebuggerGUI::drawComplete() {
chudy@google.com607357f2012-08-07 16:12:23 +0000499 fInspectorWidget.setMatrix(fDebugger.getCurrentMatrix());
500 fInspectorWidget.setClip(fDebugger.getCurrentClip());
chudy@google.coma9e937c2012-08-03 17:32:05 +0000501}
502
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000503void SkDebuggerGUI::saveToFile(const SkString& filename) {
504 SkFILEWStream file(filename.c_str());
chudy@google.com607357f2012-08-07 16:12:23 +0000505 fDebugger.makePicture()->serialize(&file);
chudy@google.com0ab03392012-07-28 20:16:11 +0000506}
507
chudy@google.com902ebe52012-06-29 14:21:22 +0000508void SkDebuggerGUI::loadFile(QListWidgetItem *item) {
509 if (fDirectoryWidgetActive) {
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000510 fFileName = fPath.toAscii();
511 fFileName.append("/");
512 fFileName.append(item->text().toAscii());
513 loadPicture(fFileName);
chudy@google.com902ebe52012-06-29 14:21:22 +0000514 }
515}
516
517void SkDebuggerGUI::openFile() {
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000518 QString temp = QFileDialog::getOpenFileName(this, tr("Open File"), "",
chudy@google.com7dcae672012-07-09 20:26:53 +0000519 tr("Files (*.*)"));
chudy@google.com902ebe52012-06-29 14:21:22 +0000520 fDirectoryWidgetActive = false;
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000521 if (!temp.isEmpty()) {
522 QFileInfo pathInfo(temp);
chudy@google.com902ebe52012-06-29 14:21:22 +0000523 fPath = pathInfo.path();
djsollen@google.comc3c82162012-11-13 18:35:10 +0000524 loadPicture(SkString(temp.toAscii().data()));
chudy@google.com902ebe52012-06-29 14:21:22 +0000525 setupDirectoryWidget();
526 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000527 fDirectoryWidgetActive = true;
528}
529
chudy@google.comc432f002012-07-10 13:19:25 +0000530void SkDebuggerGUI::pauseDrawing(bool isPaused) {
chudy@google.com607357f2012-08-07 16:12:23 +0000531 fPause = isPaused;
532 fPausedRow = fListWidget.currentRow();
533 fCanvasWidget.drawTo(fPausedRow);
chudy@google.com7dcae672012-07-09 20:26:53 +0000534}
535
chudy@google.com902ebe52012-06-29 14:21:22 +0000536void SkDebuggerGUI::registerListClick(QListWidgetItem *item) {
chudy@google.comd3058f52012-07-19 13:41:27 +0000537 if(!fLoading) {
538 int currentRow = fListWidget.currentRow();
chudy@google.comd3058f52012-07-19 13:41:27 +0000539
chudy@google.comea5488b2012-07-26 19:38:22 +0000540 if (currentRow != -1) {
541 if (!fPause) {
542 fCanvasWidget.drawTo(currentRow);
chudy@google.comd3058f52012-07-19 13:41:27 +0000543 }
chudy@google.com97cee972012-08-07 20:41:37 +0000544 SkTDArray<SkString*> *currInfo = fDebugger.getCommandInfo(
chudy@google.comea5488b2012-07-26 19:38:22 +0000545 currentRow);
546
547 /* TODO(chudy): Add command type before parameters. Rename v
548 * to something more informative. */
chudy@google.com97cee972012-08-07 20:41:37 +0000549 if (currInfo) {
chudy@google.comea5488b2012-07-26 19:38:22 +0000550 QString info;
551 info.append("<b>Parameters: </b><br/>");
chudy@google.com97cee972012-08-07 20:41:37 +0000552 for (int i = 0; i < currInfo->count(); i++) {
553
554 info.append(QString((*currInfo)[i]->c_str()));
chudy@google.comea5488b2012-07-26 19:38:22 +0000555 info.append("<br/>");
556 }
chudy@google.com6bd109a2012-08-14 19:34:13 +0000557 fInspectorWidget.setText(info, SkInspectorWidget::kDetail_TabType);
chudy@google.comea5488b2012-07-26 19:38:22 +0000558 fInspectorWidget.setDisabled(false);
chudy@google.comea5488b2012-07-26 19:38:22 +0000559 }
chudy@google.comd3058f52012-07-19 13:41:27 +0000560 }
chudy@google.comea5488b2012-07-26 19:38:22 +0000561
chudy@google.com902ebe52012-06-29 14:21:22 +0000562 }
563}
564
chudy@google.com9ca9bfe2012-07-12 21:58:14 +0000565void SkDebuggerGUI::selectCommand(int command) {
566 if (fPause) {
567 fListWidget.setCurrentRow(command);
568 }
569}
570
chudy@google.com902ebe52012-06-29 14:21:22 +0000571void SkDebuggerGUI::toggleBreakpoint() {
chudy@google.comc432f002012-07-10 13:19:25 +0000572 QListWidgetItem* item = fListWidget.currentItem();
chudy@google.com902ebe52012-06-29 14:21:22 +0000573 if (item->checkState() == Qt::Unchecked) {
574 item->setCheckState(Qt::Checked);
chudy@google.come565de42012-07-12 14:15:54 +0000575 item->setData(Qt::DecorationRole,
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000576 QPixmap(":/breakpoint_16x16.png"));
chudy@google.com902ebe52012-06-29 14:21:22 +0000577 } else {
chudy@google.com902ebe52012-06-29 14:21:22 +0000578 item->setCheckState(Qt::Unchecked);
chudy@google.come565de42012-07-12 14:15:54 +0000579 item->setData(Qt::DecorationRole,
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000580 QPixmap(":/blank.png"));
chudy@google.com902ebe52012-06-29 14:21:22 +0000581 }
582}
583
584void SkDebuggerGUI::toggleDirectory() {
chudy@google.com607357f2012-08-07 16:12:23 +0000585 fDirectoryWidget.setHidden(!fDirectoryWidget.isHidden());
chudy@google.com902ebe52012-06-29 14:21:22 +0000586}
587
588void SkDebuggerGUI::toggleFilter(QString string) {
chudy@google.comc432f002012-07-10 13:19:25 +0000589 for (int row = 0; row < fListWidget.count(); row++) {
590 QListWidgetItem *item = fListWidget.item(row);
chudy@google.com607357f2012-08-07 16:12:23 +0000591 item->setHidden(item->text() != string);
chudy@google.com902ebe52012-06-29 14:21:22 +0000592 }
593}
594
595void SkDebuggerGUI::setupUi(QMainWindow *SkDebuggerGUI) {
596 QIcon windowIcon;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000597 windowIcon.addFile(QString::fromUtf8(":/skia.png"), QSize(),
chudy@google.com7dcae672012-07-09 20:26:53 +0000598 QIcon::Normal, QIcon::Off);
chudy@google.com902ebe52012-06-29 14:21:22 +0000599 SkDebuggerGUI->setObjectName(QString::fromUtf8("SkDebuggerGUI"));
600 SkDebuggerGUI->resize(1200, 1000);
601 SkDebuggerGUI->setWindowIcon(windowIcon);
chudy@google.comc432f002012-07-10 13:19:25 +0000602 SkDebuggerGUI->setWindowTitle("Skia Debugger");
chudy@google.com902ebe52012-06-29 14:21:22 +0000603
chudy@google.come504de02012-07-16 18:35:23 +0000604 fActionOpen.setShortcuts(QKeySequence::Open);
chudy@google.comc432f002012-07-10 13:19:25 +0000605 fActionOpen.setText("Open");
chudy@google.com902ebe52012-06-29 14:21:22 +0000606
607 QIcon breakpoint;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000608 breakpoint.addFile(QString::fromUtf8(":/breakpoint.png"),
chudy@google.com7dcae672012-07-09 20:26:53 +0000609 QSize(), QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000610 fActionBreakpoint.setShortcut(QKeySequence(tr("Ctrl+B")));
chudy@google.comc432f002012-07-10 13:19:25 +0000611 fActionBreakpoint.setIcon(breakpoint);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000612 fActionBreakpoint.setText("Breakpoints");
chudy@google.com902ebe52012-06-29 14:21:22 +0000613
614 QIcon cancel;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000615 cancel.addFile(QString::fromUtf8(":/reload.png"), QSize(),
chudy@google.com7dcae672012-07-09 20:26:53 +0000616 QIcon::Normal, QIcon::Off);
chudy@google.comc432f002012-07-10 13:19:25 +0000617 fActionCancel.setIcon(cancel);
618 fActionCancel.setText("Clear Filter");
chudy@google.com902ebe52012-06-29 14:21:22 +0000619
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000620 fActionClearBreakpoints.setShortcut(QKeySequence(tr("Alt+B")));
621 fActionClearBreakpoints.setText("Clear Breakpoints");
622
623 fActionClearDeletes.setShortcut(QKeySequence(tr("Alt+X")));
624 fActionClearDeletes.setText("Clear Deletes");
625
chudy@google.come504de02012-07-16 18:35:23 +0000626 fActionClose.setShortcuts(QKeySequence::Quit);
chudy@google.comc432f002012-07-10 13:19:25 +0000627 fActionClose.setText("Exit");
chudy@google.com902ebe52012-06-29 14:21:22 +0000628
chudy@google.come504de02012-07-16 18:35:23 +0000629 fActionCreateBreakpoint.setShortcut(QKeySequence(tr("B")));
630 fActionCreateBreakpoint.setText("Set Breakpoint");
631
632 fActionDelete.setShortcut(QKeySequence(tr("X")));
chudy@google.comc432f002012-07-10 13:19:25 +0000633 fActionDelete.setText("Delete Command");
chudy@google.com902ebe52012-06-29 14:21:22 +0000634
chudy@google.come504de02012-07-16 18:35:23 +0000635 fActionDirectory.setShortcut(QKeySequence(tr("Ctrl+D")));
636 fActionDirectory.setText("Directory");
chudy@google.com902ebe52012-06-29 14:21:22 +0000637
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000638 QIcon profile;
robertphillips@google.comd1636362012-11-19 18:25:09 +0000639 profile.addFile(QString::fromUtf8(":/profile.png"), QSize(),
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000640 QIcon::Normal, QIcon::Off);
641 fActionProfile.setIcon(profile);
642 fActionProfile.setText("Profile");
robertphillips@google.come099bc42012-11-19 16:26:40 +0000643 fActionProfile.setDisabled(true);
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000644
chudy@google.comc432f002012-07-10 13:19:25 +0000645 QIcon inspector;
robertphillips@google.comd1636362012-11-19 18:25:09 +0000646 inspector.addFile(QString::fromUtf8(":/inspector.png"),
chudy@google.comc432f002012-07-10 13:19:25 +0000647 QSize(), QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000648 fActionInspector.setShortcut(QKeySequence(tr("Ctrl+I")));
chudy@google.comc432f002012-07-10 13:19:25 +0000649 fActionInspector.setIcon(inspector);
chudy@google.come504de02012-07-16 18:35:23 +0000650 fActionInspector.setText("Inspector");
chudy@google.com902ebe52012-06-29 14:21:22 +0000651
chudy@google.comc432f002012-07-10 13:19:25 +0000652 QIcon play;
robertphillips@google.comd1636362012-11-19 18:25:09 +0000653 play.addFile(QString::fromUtf8(":/play.png"), QSize(),
chudy@google.comc432f002012-07-10 13:19:25 +0000654 QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000655 fActionPlay.setShortcut(QKeySequence(tr("Ctrl+P")));
chudy@google.comc432f002012-07-10 13:19:25 +0000656 fActionPlay.setIcon(play);
657 fActionPlay.setText("Play");
chudy@google.com902ebe52012-06-29 14:21:22 +0000658
chudy@google.come504de02012-07-16 18:35:23 +0000659 QIcon pause;
robertphillips@google.comd1636362012-11-19 18:25:09 +0000660 pause.addFile(QString::fromUtf8(":/pause.png"), QSize(),
chudy@google.comc432f002012-07-10 13:19:25 +0000661 QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000662 fActionPause.setShortcut(QKeySequence(tr("Space")));
663 fActionPause.setCheckable(true);
664 fActionPause.setIcon(pause);
665 fActionPause.setText("Pause");
666
chudy@google.comc432f002012-07-10 13:19:25 +0000667 QIcon rewind;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000668 rewind.addFile(QString::fromUtf8(":/rewind.png"), QSize(),
chudy@google.comc432f002012-07-10 13:19:25 +0000669 QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000670 fActionRewind.setShortcut(QKeySequence(tr("Ctrl+R")));
chudy@google.comc432f002012-07-10 13:19:25 +0000671 fActionRewind.setIcon(rewind);
672 fActionRewind.setText("Rewind");
chudy@google.com902ebe52012-06-29 14:21:22 +0000673
chudy@google.com0ab03392012-07-28 20:16:11 +0000674 fActionSave.setShortcut(QKeySequence::Save);
675 fActionSave.setText("Save");
676 fActionSave.setDisabled(true);
677 fActionSaveAs.setShortcut(QKeySequence::SaveAs);
678 fActionSaveAs.setText("Save As");
679 fActionSaveAs.setDisabled(true);
680
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000681 fActionShowDeletes.setShortcut(QKeySequence(tr("Ctrl+X")));
682 fActionShowDeletes.setText("Deleted Commands");
683
chudy@google.comc432f002012-07-10 13:19:25 +0000684 QIcon stepBack;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000685 stepBack.addFile(QString::fromUtf8(":/previous.png"), QSize(),
chudy@google.comc432f002012-07-10 13:19:25 +0000686 QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000687 fActionStepBack.setShortcut(QKeySequence(tr("[")));
chudy@google.comc432f002012-07-10 13:19:25 +0000688 fActionStepBack.setIcon(stepBack);
689 fActionStepBack.setText("Step Back");
chudy@google.com902ebe52012-06-29 14:21:22 +0000690
chudy@google.comc432f002012-07-10 13:19:25 +0000691 QIcon stepForward;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000692 stepForward.addFile(QString::fromUtf8(":/next.png"),
chudy@google.comc432f002012-07-10 13:19:25 +0000693 QSize(), QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000694 fActionStepForward.setShortcut(QKeySequence(tr("]")));
chudy@google.comc432f002012-07-10 13:19:25 +0000695 fActionStepForward.setIcon(stepForward);
696 fActionStepForward.setText("Step Forward");
697
chudy@google.coma1226312012-07-26 20:26:44 +0000698 fActionZoomIn.setShortcut(QKeySequence(tr("Ctrl+=")));
699 fActionZoomIn.setText("Zoom In");
700 fActionZoomOut.setShortcut(QKeySequence(tr("Ctrl+-")));
701 fActionZoomOut.setText("Zoom Out");
702
chudy@google.comc432f002012-07-10 13:19:25 +0000703 fListWidget.setItemDelegate(new SkListWidget(&fListWidget));
704 fListWidget.setObjectName(QString::fromUtf8("listWidget"));
705 fListWidget.setMaximumWidth(250);
706
707 fFilter.addItem("--Filter By Available Commands--");
708
709 fDirectoryWidget.setMaximumWidth(250);
710 fDirectoryWidget.setStyleSheet("QListWidget::Item {padding: 5px;}");
711
712 fCanvasWidget.setSizePolicy(QSizePolicy::Expanding,
chudy@google.com7dcae672012-07-09 20:26:53 +0000713 QSizePolicy::Expanding);
chudy@google.com902ebe52012-06-29 14:21:22 +0000714
chudy@google.comc432f002012-07-10 13:19:25 +0000715 fInspectorWidget.setSizePolicy(QSizePolicy::Expanding,
chudy@google.com7dcae672012-07-09 20:26:53 +0000716 QSizePolicy::Expanding);
chudy@google.comc432f002012-07-10 13:19:25 +0000717 fInspectorWidget.setMaximumHeight(300);
chudy@google.com902ebe52012-06-29 14:21:22 +0000718
chudy@google.comc432f002012-07-10 13:19:25 +0000719 fSettingsWidget.setSizePolicy(QSizePolicy::Expanding,
720 QSizePolicy::Expanding);
721 fSettingsWidget.setMaximumWidth(250);
chudy@google.com902ebe52012-06-29 14:21:22 +0000722
chudy@google.comc432f002012-07-10 13:19:25 +0000723 fLeftColumnLayout.setSpacing(6);
724 fLeftColumnLayout.addWidget(&fListWidget);
725 fLeftColumnLayout.addWidget(&fDirectoryWidget);
chudy@google.com902ebe52012-06-29 14:21:22 +0000726
chudy@google.comc432f002012-07-10 13:19:25 +0000727 fCanvasAndSettingsLayout.setSpacing(6);
728 fCanvasAndSettingsLayout.addWidget(&fCanvasWidget);
729 fCanvasAndSettingsLayout.addWidget(&fSettingsWidget);
chudy@google.com902ebe52012-06-29 14:21:22 +0000730
chudy@google.comc432f002012-07-10 13:19:25 +0000731 fMainAndRightColumnLayout.setSpacing(6);
732 fMainAndRightColumnLayout.addLayout(&fCanvasAndSettingsLayout);
733 fMainAndRightColumnLayout.addWidget(&fInspectorWidget);
chudy@google.com902ebe52012-06-29 14:21:22 +0000734
chudy@google.com2d537a12012-07-31 12:49:52 +0000735 fCentralWidget.setLayout(&fContainerLayout);
chudy@google.comc432f002012-07-10 13:19:25 +0000736 fContainerLayout.setSpacing(6);
737 fContainerLayout.setContentsMargins(11, 11, 11, 11);
738 fContainerLayout.addLayout(&fLeftColumnLayout);
739 fContainerLayout.addLayout(&fMainAndRightColumnLayout);
740
741 SkDebuggerGUI->setCentralWidget(&fCentralWidget);
742 SkDebuggerGUI->setStatusBar(&fStatusBar);
743
chudy@google.come504de02012-07-16 18:35:23 +0000744 fToolBar.setIconSize(QSize(32, 32));
chudy@google.comc432f002012-07-10 13:19:25 +0000745 fToolBar.setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
746 SkDebuggerGUI->addToolBar(Qt::TopToolBarArea, &fToolBar);
chudy@google.com902ebe52012-06-29 14:21:22 +0000747
chudy@google.com0ab03392012-07-28 20:16:11 +0000748 fSpacer.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
chudy@google.com902ebe52012-06-29 14:21:22 +0000749
chudy@google.comc432f002012-07-10 13:19:25 +0000750 fToolBar.addAction(&fActionRewind);
751 fToolBar.addAction(&fActionStepBack);
chudy@google.come504de02012-07-16 18:35:23 +0000752 fToolBar.addAction(&fActionPause);
chudy@google.comc432f002012-07-10 13:19:25 +0000753 fToolBar.addAction(&fActionStepForward);
754 fToolBar.addAction(&fActionPlay);
755 fToolBar.addSeparator();
chudy@google.come504de02012-07-16 18:35:23 +0000756 fToolBar.addAction(&fActionInspector);
chudy@google.comc432f002012-07-10 13:19:25 +0000757 fToolBar.addSeparator();
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000758 fToolBar.addAction(&fActionProfile);
759
760 fToolBar.addSeparator();
chudy@google.com0ab03392012-07-28 20:16:11 +0000761 fToolBar.addWidget(&fSpacer);
chudy@google.comc432f002012-07-10 13:19:25 +0000762 fToolBar.addWidget(&fFilter);
763 fToolBar.addAction(&fActionCancel);
chudy@google.com902ebe52012-06-29 14:21:22 +0000764
765 // TODO(chudy): Remove static call.
766 fDirectoryWidgetActive = false;
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000767 fPath = "";
768 fFileName = "";
chudy@google.com902ebe52012-06-29 14:21:22 +0000769 setupDirectoryWidget();
770 fDirectoryWidgetActive = true;
771
chudy@google.com902ebe52012-06-29 14:21:22 +0000772 // Menu Bar
chudy@google.comc432f002012-07-10 13:19:25 +0000773 fMenuFile.setTitle("File");
774 fMenuFile.addAction(&fActionOpen);
chudy@google.com0ab03392012-07-28 20:16:11 +0000775 fMenuFile.addAction(&fActionSave);
776 fMenuFile.addAction(&fActionSaveAs);
chudy@google.comc432f002012-07-10 13:19:25 +0000777 fMenuFile.addAction(&fActionClose);
chudy@google.come504de02012-07-16 18:35:23 +0000778
779 fMenuEdit.setTitle("Edit");
780 fMenuEdit.addAction(&fActionDelete);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000781 fMenuEdit.addAction(&fActionClearDeletes);
782 fMenuEdit.addSeparator();
chudy@google.come504de02012-07-16 18:35:23 +0000783 fMenuEdit.addAction(&fActionCreateBreakpoint);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000784 fMenuEdit.addAction(&fActionClearBreakpoints);
chudy@google.come504de02012-07-16 18:35:23 +0000785
chudy@google.comc432f002012-07-10 13:19:25 +0000786 fMenuNavigate.setTitle("Navigate");
chudy@google.come504de02012-07-16 18:35:23 +0000787 fMenuNavigate.addAction(&fActionRewind);
788 fMenuNavigate.addAction(&fActionStepBack);
789 fMenuNavigate.addAction(&fActionStepForward);
790 fMenuNavigate.addAction(&fActionPlay);
791 fMenuNavigate.addAction(&fActionPause);
chudy@google.comc432f002012-07-10 13:19:25 +0000792 fMenuNavigate.addAction(&fActionGoToLine);
chudy@google.come504de02012-07-16 18:35:23 +0000793
chudy@google.comc432f002012-07-10 13:19:25 +0000794 fMenuView.setTitle("View");
chudy@google.come504de02012-07-16 18:35:23 +0000795 fMenuView.addAction(&fActionBreakpoint);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000796 fMenuView.addAction(&fActionShowDeletes);
chudy@google.coma1226312012-07-26 20:26:44 +0000797 fMenuView.addAction(&fActionZoomIn);
798 fMenuView.addAction(&fActionZoomOut);
chudy@google.come504de02012-07-16 18:35:23 +0000799
800 fMenuWindows.setTitle("Window");
801 fMenuWindows.addAction(&fActionInspector);
802 fMenuWindows.addAction(&fActionDirectory);
chudy@google.comc432f002012-07-10 13:19:25 +0000803
804 fActionGoToLine.setText("Go to Line...");
805 fActionGoToLine.setDisabled(true);
806 fMenuBar.addAction(fMenuFile.menuAction());
chudy@google.come504de02012-07-16 18:35:23 +0000807 fMenuBar.addAction(fMenuEdit.menuAction());
chudy@google.comc432f002012-07-10 13:19:25 +0000808 fMenuBar.addAction(fMenuView.menuAction());
809 fMenuBar.addAction(fMenuNavigate.menuAction());
chudy@google.come504de02012-07-16 18:35:23 +0000810 fMenuBar.addAction(fMenuWindows.menuAction());
chudy@google.com902ebe52012-06-29 14:21:22 +0000811
chudy@google.com7dcae672012-07-09 20:26:53 +0000812 fPause = false;
813
chudy@google.comc432f002012-07-10 13:19:25 +0000814 SkDebuggerGUI->setMenuBar(&fMenuBar);
chudy@google.com902ebe52012-06-29 14:21:22 +0000815 QMetaObject::connectSlotsByName(SkDebuggerGUI);
816}
817
818void SkDebuggerGUI::setupDirectoryWidget() {
chudy@google.comc432f002012-07-10 13:19:25 +0000819 QDir dir(fPath);
chudy@google.com902ebe52012-06-29 14:21:22 +0000820 QRegExp r(".skp");
chudy@google.comc432f002012-07-10 13:19:25 +0000821 fDirectoryWidget.clear();
822 const QStringList files = dir.entryList();
chudy@google.com902ebe52012-06-29 14:21:22 +0000823 foreach (QString f, files) {
chudy@google.com7dcae672012-07-09 20:26:53 +0000824 if (f.contains(r))
chudy@google.comc432f002012-07-10 13:19:25 +0000825 fDirectoryWidget.addItem(f);
chudy@google.com902ebe52012-06-29 14:21:22 +0000826 }
827}
828
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000829// SkOffsetPicturePlayback records the offset of each command in the picture.
830// These are needed by the profiling system.
831class SkOffsetPicturePlayback : public SkPicturePlayback {
832public:
833 SkOffsetPicturePlayback(SkStream* stream, const SkPictInfo& info, bool* isValid,
834 SkSerializationHelpers::DecodeBitmap decoder)
835 : INHERITED(stream, info, isValid, decoder) {
836 }
837
838 const SkTDArray<size_t>& offsets() const { return fOffsets; }
839
840protected:
841 SkTDArray<size_t> fOffsets;
842
843 virtual void preDraw(size_t offset, int type) {
844 *fOffsets.append() = offset;
845 }
846
847private:
848 typedef SkPicturePlayback INHERITED;
849};
850
851// Picture to wrap an SkOffsetPicturePlayback.
852class SkOffsetPicture : public SkPicture {
853public:
skia.committer@gmail.com884e60b2012-11-16 02:01:17 +0000854 SkOffsetPicture(SkStream* stream,
855 bool* success,
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000856 SkSerializationHelpers::DecodeBitmap decoder) {
857 if (success) {
858 *success = false;
859 }
860 fRecord = NULL;
861 fPlayback = NULL;
862 fWidth = fHeight = 0;
863
864 SkPictInfo info;
865
866 if (!stream->read(&info, sizeof(info))) {
867 return;
868 }
869 if (PICTURE_VERSION != info.fVersion) {
870 return;
871 }
872
873 if (stream->readBool()) {
874 bool isValid = false;
875 fPlayback = SkNEW_ARGS(SkOffsetPicturePlayback, (stream, info, &isValid, decoder));
876 if (!isValid) {
877 SkDELETE(fPlayback);
878 fPlayback = NULL;
879 return;
880 }
881 }
882
883 // do this at the end, so that they will be zero if we hit an error.
884 fWidth = info.fWidth;
885 fHeight = info.fHeight;
886 if (success) {
887 *success = true;
888 }
889 }
890
skia.committer@gmail.com884e60b2012-11-16 02:01:17 +0000891 const SkTDArray<size_t>& offsets() const {
892 return ((SkOffsetPicturePlayback*) fPlayback)->offsets();
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000893 }
894
895private:
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000896 // disallow default ctor b.c. we don't have a good way to setup the fPlayback ptr
897 SkOffsetPicture();
898 // disallow the copy ctor - enabling would require copying code from SkPicture
899 SkOffsetPicture(const SkOffsetPicture& src);
900
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000901 typedef SkPicture INHERITED;
902};
903
904
905
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000906void SkDebuggerGUI::loadPicture(const SkString& fileName) {
907 fFileName = fileName;
chudy@google.comd3058f52012-07-19 13:41:27 +0000908 fLoading = true;
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000909 SkStream* stream = SkNEW_ARGS(SkFILEStream, (fileName.c_str()));
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000910 SkOffsetPicture* picture = SkNEW_ARGS(SkOffsetPicture, (stream, NULL, &SkImageDecoder::DecodeStream));
911
chudy@google.com686e6802012-08-14 16:00:32 +0000912 fCanvasWidget.resetWidgetTransform();
chudy@google.com607357f2012-08-07 16:12:23 +0000913 fDebugger.loadPicture(picture);
chudy@google.com4c7962e2012-08-14 19:38:31 +0000914
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000915 fOffsets = picture->offsets();
916
chudy@google.com607357f2012-08-07 16:12:23 +0000917 SkSafeUnref(stream);
918 SkSafeUnref(picture);
919
chudy@google.com97cee972012-08-07 20:41:37 +0000920 // Will this automatically clear out due to nature of refcnt?
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000921 SkTArray<SkString>* commands = fDebugger.getDrawCommandsAsStrings();
chudy@google.com607357f2012-08-07 16:12:23 +0000922
robertphillips@google.comfe830a42012-11-15 16:33:31 +0000923 // If SkPicturePlayback is compiled w/o SK_PICTURE_PROFILING_STUBS
924 // the offset count will always be zero
925 SkASSERT(0 == fOffsets.count() || commands->count() == fOffsets.count());
robertphillips@google.come099bc42012-11-19 16:26:40 +0000926 if (commands->count() == fOffsets.count()) {
927 fActionProfile.setDisabled(false);
robertphillips@google.comfe830a42012-11-15 16:33:31 +0000928 }
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000929
chudy@google.com7dcae672012-07-09 20:26:53 +0000930 /* fDebugCanvas is reinitialized every load picture. Need it to retain value
chudy@google.com607357f2012-08-07 16:12:23 +0000931 * of the visibility filter.
932 * TODO(chudy): This should be deprecated since fDebugger is not
933 * recreated.
934 * */
935 fDebugger.highlightCurrentCommand(fSettingsWidget.getVisibilityButton()->isChecked());
936
chudy@google.com97cee972012-08-07 20:41:37 +0000937 setupListWidget(commands);
938 setupComboBox(commands);
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000939 setupOverviewText(NULL, 0.0);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000940 fInspectorWidget.setDisabled(false);
chudy@google.come606d6e2012-07-12 14:31:25 +0000941 fSettingsWidget.setDisabled(false);
chudy@google.comd3058f52012-07-19 13:41:27 +0000942 fMenuEdit.setDisabled(false);
943 fMenuNavigate.setDisabled(false);
944 fMenuView.setDisabled(false);
chudy@google.com0ab03392012-07-28 20:16:11 +0000945 fActionSave.setDisabled(false);
946 fActionSaveAs.setDisabled(false);
chudy@google.comd3058f52012-07-19 13:41:27 +0000947 fLoading = false;
948 actionPlay();
chudy@google.com902ebe52012-06-29 14:21:22 +0000949}
950
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000951void SkDebuggerGUI::setupListWidget(SkTArray<SkString>* command) {
chudy@google.comc432f002012-07-10 13:19:25 +0000952 fListWidget.clear();
chudy@google.com902ebe52012-06-29 14:21:22 +0000953 int counter = 0;
robertphillips@google.com30d35f22012-11-06 16:45:36 +0000954 int indent = 0;
chudy@google.com97cee972012-08-07 20:41:37 +0000955 for (int i = 0; i < command->count(); i++) {
chudy@google.com902ebe52012-06-29 14:21:22 +0000956 QListWidgetItem *item = new QListWidgetItem();
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000957 item->setData(Qt::DisplayRole, (*command)[i].c_str());
chudy@google.com902ebe52012-06-29 14:21:22 +0000958 item->setData(Qt::UserRole + 1, counter++);
robertphillips@google.com30d35f22012-11-06 16:45:36 +0000959
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000960 if (0 == strcmp("Restore", (*command)[i].c_str())) {
robertphillips@google.com30d35f22012-11-06 16:45:36 +0000961 indent -= 10;
962 }
963
964 item->setData(Qt::UserRole + 3, indent);
965
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000966 if (0 == strcmp("Save", (*command)[i].c_str()) ||
967 0 == strcmp("Save Layer", (*command)[i].c_str())) {
robertphillips@google.com30d35f22012-11-06 16:45:36 +0000968 indent += 10;
969 }
970
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000971 item->setData(Qt::UserRole + 4, -1.0);
972
chudy@google.comc432f002012-07-10 13:19:25 +0000973 fListWidget.addItem(item);
chudy@google.com902ebe52012-06-29 14:21:22 +0000974 }
975}
976
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000977void SkDebuggerGUI::setupOverviewText(const SkTDArray<double>* typeTimes, double totTime) {
chudy@google.com902ebe52012-06-29 14:21:22 +0000978
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000979 const SkTDArray<SkDrawCommand*>& commands = fDebugger.getDrawCommands();
980
981 SkTDArray<int> counts;
982 counts.setCount(LAST_DRAWTYPE_ENUM+1);
983 for (int i = 0; i < LAST_DRAWTYPE_ENUM+1; ++i) {
984 counts[i] = 0;
985 }
986
987 for (int i = 0; i < commands.count(); i++) {
988 counts[commands[i]->getType()]++;
chudy@google.com902ebe52012-06-29 14:21:22 +0000989 }
990
991 QString overview;
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000992 int total = 0;
993#ifdef SK_DEBUG
994 double totPercent = 0, tempSum = 0;
995#endif
996 for (int i = 0; i < LAST_DRAWTYPE_ENUM+1; ++i) {
997 if (0 == counts[i]) {
998 // if there were no commands of this type then they should've consumed no time
999 SkASSERT(NULL == typeTimes || 0.0 == (*typeTimes)[i]);
1000 continue;
1001 }
1002
1003 overview.append(SkDrawCommand::GetCommandString((DrawType) i));
chudy@google.com902ebe52012-06-29 14:21:22 +00001004 overview.append(": ");
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +00001005 overview.append(QString::number(counts[i]));
1006 if (NULL != typeTimes) {
1007 overview.append(" - ");
1008 overview.append(QString::number((*typeTimes)[i], 'f', 1));
1009 overview.append("ms");
1010 overview.append(" - ");
1011 double percent = 100.0*(*typeTimes)[i]/totTime;
1012 overview.append(QString::number(percent, 'f', 1));
1013 overview.append("%");
1014#ifdef SK_DEBUG
1015 totPercent += percent;
1016 tempSum += (*typeTimes)[i];
1017#endif
1018 }
chudy@google.com902ebe52012-06-29 14:21:22 +00001019 overview.append("<br/>");
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +00001020 total += counts[i];
chudy@google.com902ebe52012-06-29 14:21:22 +00001021 }
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +00001022#ifdef SK_DEBUG
1023 if (NULL != typeTimes) {
1024 SkASSERT(SkScalarNearlyEqual(totPercent, 100.0));
1025 SkASSERT(SkScalarNearlyEqual(tempSum, totTime));
1026 }
1027#endif
1028
1029 if (totTime > 0.0) {
1030 overview.append("Total Time: ");
1031 overview.append(QString::number(totTime, 'f', 2));
1032 overview.append("ms");
1033#ifdef SK_DEBUG
1034 overview.append(" ");
1035 overview.append(QString::number(totPercent));
1036 overview.append("% ");
1037#endif
1038 overview.append("<br/>");
1039 }
1040
1041 QString totalStr;
1042 totalStr.append("Total Draw Commands: ");
1043 totalStr.append(QString::number(total));
1044 totalStr.append("<br/>");
1045 overview.insert(0, totalStr);
chudy@google.com902ebe52012-06-29 14:21:22 +00001046
1047 overview.append("<br/>");
chudy@google.com607357f2012-08-07 16:12:23 +00001048 overview.append("SkPicture Width: ");
chudy@google.com902ebe52012-06-29 14:21:22 +00001049 // NOTE(chudy): This is where we can pull out the SkPictures width.
chudy@google.com607357f2012-08-07 16:12:23 +00001050 overview.append(QString::number(fDebugger.pictureWidth()));
chudy@google.com902ebe52012-06-29 14:21:22 +00001051 overview.append("px<br/>");
chudy@google.com607357f2012-08-07 16:12:23 +00001052 overview.append("SkPicture Height: ");
1053 overview.append(QString::number(fDebugger.pictureHeight()));
chudy@google.com902ebe52012-06-29 14:21:22 +00001054 overview.append("px");
chudy@google.com6bd109a2012-08-14 19:34:13 +00001055 fInspectorWidget.setText(overview, SkInspectorWidget::kOverview_TabType);
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +00001056}
1057
1058void SkDebuggerGUI::setupComboBox(SkTArray<SkString>* command) {
1059 fFilter.clear();
1060 fFilter.addItem("--Filter By Available Commands--");
1061
1062 std::map<std::string, int> map;
1063 for (int i = 0; i < command->count(); i++) {
1064 map[(*command)[i].c_str()]++;
1065 }
1066
1067 for (std::map<std::string, int>::iterator it = map.begin(); it != map.end();
1068 ++it) {
1069 fFilter.addItem((it->first).c_str());
1070 }
chudy@google.com902ebe52012-06-29 14:21:22 +00001071
1072 // NOTE(chudy): Makes first item unselectable.
chudy@google.com7dcae672012-07-09 20:26:53 +00001073 QStandardItemModel* model = qobject_cast<QStandardItemModel*>(
chudy@google.comc432f002012-07-10 13:19:25 +00001074 fFilter.model());
1075 QModelIndex firstIndex = model->index(0, fFilter.modelColumn(),
1076 fFilter.rootModelIndex());
chudy@google.com902ebe52012-06-29 14:21:22 +00001077 QStandardItem* firstItem = model->itemFromIndex(firstIndex);
1078 firstItem->setSelectable(false);
1079}