blob: 237f701ccb7f3466c59db724840731ba39ad8708 [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"
robertphillips@google.com2bde91d2012-11-15 14:57:57 +00009#include "PictureRenderer.h"
robertphillips2de59392015-02-11 13:18:14 -080010#include "SkPictureData.h"
11#include "SkPicturePlayback.h"
12#include "SkPictureRecord.h"
kkinnunencfdc0e32015-01-13 22:49:02 -080013#include <QListWidgetItem>
14#include <QtGui>
robertphillips3e5c2b12015-03-23 05:46:51 -070015#include "sk_tool_utils.h"
robertphillips@google.come174a8b2012-11-27 16:04:42 +000016
17#if defined(SK_BUILD_FOR_WIN32)
mtklein9ac68ee2014-06-20 11:29:20 -070018 #include "SysTimer_windows.h"
robertphillips@google.come174a8b2012-11-27 16:04:42 +000019#elif defined(SK_BUILD_FOR_MAC)
mtklein9ac68ee2014-06-20 11:29:20 -070020 #include "SysTimer_mach.h"
robertphillips@google.come174a8b2012-11-27 16:04:42 +000021#elif defined(SK_BUILD_FOR_UNIX) || defined(SK_BUILD_FOR_ANDROID)
mtklein9ac68ee2014-06-20 11:29:20 -070022 #include "SysTimer_posix.h"
robertphillips@google.come174a8b2012-11-27 16:04:42 +000023#else
mtklein9ac68ee2014-06-20 11:29:20 -070024 #include "SysTimer_c.h"
robertphillips@google.come174a8b2012-11-27 16:04:42 +000025#endif
26
chudy@google.com902ebe52012-06-29 14:21:22 +000027
28SkDebuggerGUI::SkDebuggerGUI(QWidget *parent) :
chudy@google.comc432f002012-07-10 13:19:25 +000029 QMainWindow(parent)
commit-bot@chromium.orgbcd431e2013-11-21 13:41:37 +000030 , fCentralSplitter(this)
chudy@google.com2d537a12012-07-31 12:49:52 +000031 , fStatusBar(this)
32 , fToolBar(this)
chudy@google.comc432f002012-07-10 13:19:25 +000033 , fActionOpen(this)
34 , fActionBreakpoint(this)
robertphillips@google.comd26c7062012-11-12 20:42:12 +000035 , fActionProfile(this)
chudy@google.comc432f002012-07-10 13:19:25 +000036 , fActionCancel(this)
chudy@google.com7e4cfbf2012-07-17 15:40:51 +000037 , fActionClearBreakpoints(this)
chudy@google.come504de02012-07-16 18:35:23 +000038 , fActionClearDeletes(this)
chudy@google.comc432f002012-07-10 13:19:25 +000039 , fActionClose(this)
chudy@google.come504de02012-07-16 18:35:23 +000040 , fActionCreateBreakpoint(this)
chudy@google.comc432f002012-07-10 13:19:25 +000041 , fActionDelete(this)
42 , fActionDirectory(this)
43 , fActionGoToLine(this)
44 , fActionInspector(this)
bungeman@google.com2ff6d1d2013-07-01 14:24:12 +000045 , fActionSettings(this)
chudy@google.comc432f002012-07-10 13:19:25 +000046 , fActionPlay(this)
chudy@google.come504de02012-07-16 18:35:23 +000047 , fActionPause(this)
chudy@google.comc432f002012-07-10 13:19:25 +000048 , fActionRewind(this)
chudy@google.com0ab03392012-07-28 20:16:11 +000049 , fActionSave(this)
50 , fActionSaveAs(this)
chudy@google.com7e4cfbf2012-07-17 15:40:51 +000051 , fActionShowDeletes(this)
chudy@google.comc432f002012-07-10 13:19:25 +000052 , fActionStepBack(this)
53 , fActionStepForward(this)
chudy@google.coma1226312012-07-26 20:26:44 +000054 , fActionZoomIn(this)
55 , fActionZoomOut(this)
56 , fMapper(this)
commit-bot@chromium.orgbcd431e2013-11-21 13:41:37 +000057 , fListWidget(&fCentralSplitter)
58 , fDirectoryWidget(&fCentralSplitter)
chudy@google.com607357f2012-08-07 16:12:23 +000059 , fCanvasWidget(this, &fDebugger)
kkinnunen63a47022014-12-30 23:03:56 -080060 , fDrawCommandGeometryWidget(&fDebugger)
chudy@google.comc432f002012-07-10 13:19:25 +000061 , fMenuBar(this)
62 , fMenuFile(this)
63 , fMenuNavigate(this)
64 , fMenuView(this)
chudy@google.comd3058f52012-07-19 13:41:27 +000065 , fLoading(false)
chudy@google.comc432f002012-07-10 13:19:25 +000066{
chudy@google.com902ebe52012-06-29 14:21:22 +000067 setupUi(this);
robertphillips@google.comdd4b7452013-01-22 19:38:46 +000068 fListWidget.setSelectionMode(QAbstractItemView::ExtendedSelection);
kkinnunen0cfeaf32015-01-07 07:33:46 -080069 connect(&fListWidget, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)), this,
70 SLOT(updateDrawCommandInfo()));
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()));
bungeman@google.com2ff6d1d2013-07-01 14:24:12 +000082 connect(&fActionSettings, SIGNAL(triggered()), this, SLOT(actionSettings()));
chudy@google.comea5488b2012-07-26 19:38:22 +000083 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()));
robertphillips@google.come8fe4bc2013-02-13 13:26:13 +000089#if SK_SUPPORT_GPU
kkinnunen41c79cc2014-12-30 22:49:58 -080090 connect(&fSettingsWidget, SIGNAL(glSettingsChanged()), this, SLOT(actionGLSettingsChanged()));
robertphillips@google.come8fe4bc2013-02-13 13:26:13 +000091#endif
kkinnunen41c79cc2014-12-30 22:49:58 -080092 connect(&fSettingsWidget, SIGNAL(rasterSettingsChanged()), this, SLOT(actionRasterSettingsChanged()));
93 connect(&fSettingsWidget, SIGNAL(visualizationsChanged()), this, SLOT(actionVisualizationsChanged()));
robertphillips@google.com32bbcf82013-10-17 17:56:10 +000094 connect(&fSettingsWidget, SIGNAL(texFilterSettingsChanged()), this, SLOT(actionTextureFilter()));
chudy@google.comea5488b2012-07-26 19:38:22 +000095 connect(&fActionPause, SIGNAL(toggled(bool)), this, SLOT(pauseDrawing(bool)));
chudy@google.come504de02012-07-16 18:35:23 +000096 connect(&fActionCreateBreakpoint, SIGNAL(activated()), this, SLOT(toggleBreakpoint()));
chudy@google.com7e4cfbf2012-07-17 15:40:51 +000097 connect(&fActionShowDeletes, SIGNAL(triggered()), this, SLOT(showDeletes()));
chudy@google.comea5488b2012-07-26 19:38:22 +000098 connect(&fCanvasWidget, SIGNAL(hitChanged(int)), this, SLOT(selectCommand(int)));
kkinnunen41c79cc2014-12-30 22:49:58 -080099 connect(&fCanvasWidget, SIGNAL(hitChanged(int)), this, SLOT(updateHit(int)));
chudy@google.comea5488b2012-07-26 19:38:22 +0000100 connect(&fCanvasWidget, SIGNAL(scaleFactorChanged(float)), this, SLOT(actionScale(float)));
kkinnunen63a47022014-12-30 23:03:56 -0800101
chudy@google.com0ab03392012-07-28 20:16:11 +0000102 connect(&fActionSaveAs, SIGNAL(triggered()), this, SLOT(actionSaveAs()));
103 connect(&fActionSave, SIGNAL(triggered()), this, SLOT(actionSave()));
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000104
bungeman@google.come8cc6e82013-01-17 16:30:56 +0000105 fMapper.setMapping(&fActionZoomIn, SkCanvasWidget::kIn_ZoomCommand);
106 fMapper.setMapping(&fActionZoomOut, SkCanvasWidget::kOut_ZoomCommand);
chudy@google.coma1226312012-07-26 20:26:44 +0000107
108 connect(&fActionZoomIn, SIGNAL(triggered()), &fMapper, SLOT(map()));
109 connect(&fActionZoomOut, SIGNAL(triggered()), &fMapper, SLOT(map()));
bungeman@google.come8cc6e82013-01-17 16:30:56 +0000110 connect(&fMapper, SIGNAL(mapped(int)), &fCanvasWidget, SLOT(zoom(int)));
chudy@google.coma1226312012-07-26 20:26:44 +0000111
kkinnunen41c79cc2014-12-30 22:49:58 -0800112 fViewStateFrame.setDisabled(true);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000113 fInspectorWidget.setDisabled(true);
chudy@google.comd3058f52012-07-19 13:41:27 +0000114 fMenuEdit.setDisabled(true);
115 fMenuNavigate.setDisabled(true);
116 fMenuView.setDisabled(true);
chudy@google.combbad34d2012-08-13 14:26:36 +0000117}
chudy@google.com902ebe52012-06-29 14:21:22 +0000118
119void SkDebuggerGUI::actionBreakpoints() {
kkinnunenf3a9e992015-01-05 01:14:11 -0800120 bool breakpointsActivated = fActionBreakpoint.isChecked();
chudy@google.comc432f002012-07-10 13:19:25 +0000121 for (int row = 0; row < fListWidget.count(); row++) {
122 QListWidgetItem *item = fListWidget.item(row);
kkinnunenf3a9e992015-01-05 01:14:11 -0800123 item->setHidden(item->checkState() == Qt::Unchecked && breakpointsActivated);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000124 }
125}
chudy@google.com902ebe52012-06-29 14:21:22 +0000126
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000127void SkDebuggerGUI::showDeletes() {
kkinnunenf3a9e992015-01-05 01:14:11 -0800128 bool deletesActivated = fActionShowDeletes.isChecked();
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000129 for (int row = 0; row < fListWidget.count(); row++) {
130 QListWidgetItem *item = fListWidget.item(row);
kkinnunenf3a9e992015-01-05 01:14:11 -0800131 item->setHidden(fDebugger.isCommandVisible(row) && deletesActivated);
chudy@google.com902ebe52012-06-29 14:21:22 +0000132 }
133}
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000134// This is a simplification of PictureBenchmark's run with the addition of
135// clearing of the times after the first pass (in resetTimes)
robertphillipsce4dd3d2014-07-07 13:46:35 -0700136void SkDebuggerGUI::run(const SkPicture* pict,
skia.committer@gmail.com34587162012-11-20 02:01:23 +0000137 sk_tools::PictureRenderer* renderer,
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000138 int repeats) {
139 SkASSERT(pict);
140 if (NULL == pict) {
141 return;
142 }
143
144 SkASSERT(renderer != NULL);
145 if (NULL == renderer) {
146 return;
147 }
148
robertphillips78c71272014-10-09 04:59:19 -0700149 renderer->init(pict, NULL, NULL, NULL, false, false);
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000150
151 renderer->setup();
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000152 renderer->render();
commit-bot@chromium.org51c040e2014-03-11 22:58:00 +0000153 renderer->resetState(true); // flush, swapBuffers and Finish
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000154
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000155 for (int i = 0; i < repeats; ++i) {
156 renderer->setup();
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000157 renderer->render();
commit-bot@chromium.org51c040e2014-03-11 22:58:00 +0000158 renderer->resetState(false); // flush & swapBuffers, but don't Finish
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000159 }
commit-bot@chromium.org51c040e2014-03-11 22:58:00 +0000160 renderer->resetState(true); // flush, swapBuffers and Finish
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000161
162 renderer->end();
163}
164
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000165void SkDebuggerGUI::actionProfile() {
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000166 // In order to profile we pass the command offsets (that were read-in
167 // in loadPicture by the SkOffsetPicture) to an SkTimedPlaybackPicture.
skia.committer@gmail.com884e60b2012-11-16 02:01:17 +0000168 // The SkTimedPlaybackPicture in turn passes the offsets to an
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000169 // SkTimedPicturePlayback object which uses them to track the performance
170 // of individual commands.
171 if (fFileName.isEmpty()) {
172 return;
173 }
174
175 SkFILEStream inputStream;
176
177 inputStream.setPath(fFileName.c_str());
178 if (!inputStream.isValid()) {
179 return;
180 }
181
robertphillipsce4dd3d2014-07-07 13:46:35 -0700182 SkAutoTUnref<SkPicture> picture(SkPicture::CreateFromStream(&inputStream,
183 &SkImageDecoder::DecodeMemory)); // , fSkipCommands));
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000184 if (NULL == picture.get()) {
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000185 return;
186 }
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000187}
188
chudy@google.com902ebe52012-06-29 14:21:22 +0000189void SkDebuggerGUI::actionCancel() {
chudy@google.comc432f002012-07-10 13:19:25 +0000190 for (int row = 0; row < fListWidget.count(); row++) {
191 fListWidget.item(row)->setHidden(false);
chudy@google.com902ebe52012-06-29 14:21:22 +0000192 }
193}
194
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000195void SkDebuggerGUI::actionClearBreakpoints() {
196 for (int row = 0; row < fListWidget.count(); row++) {
197 QListWidgetItem* item = fListWidget.item(row);
198 item->setCheckState(Qt::Unchecked);
199 item->setData(Qt::DecorationRole,
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000200 QPixmap(":/blank.png"));
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000201 }
202}
203
204void SkDebuggerGUI::actionClearDeletes() {
205 for (int row = 0; row < fListWidget.count(); row++) {
206 QListWidgetItem* item = fListWidget.item(row);
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000207 item->setData(Qt::UserRole + 2, QPixmap(":/blank.png"));
chudy@google.com607357f2012-08-07 16:12:23 +0000208 fDebugger.setCommandVisible(row, true);
robertphillips@google.com5f971142012-12-07 20:48:56 +0000209 fSkipCommands[row] = false;
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000210 }
kkinnunencfdc0e32015-01-13 22:49:02 -0800211 this->updateImage();
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000212}
213
chudy@google.com902ebe52012-06-29 14:21:22 +0000214void SkDebuggerGUI::actionClose() {
215 this->close();
216}
217
218void SkDebuggerGUI::actionDelete() {
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000219
robertphillips@google.comdd4b7452013-01-22 19:38:46 +0000220 for (int row = 0; row < fListWidget.count(); ++row) {
221 QListWidgetItem* item = fListWidget.item(row);
222
223 if (!item->isSelected()) {
224 continue;
225 }
226
227 if (fDebugger.isCommandVisible(row)) {
228 item->setData(Qt::UserRole + 2, QPixmap(":/delete.png"));
229 fDebugger.setCommandVisible(row, false);
230 fSkipCommands[row] = true;
231 } else {
232 item->setData(Qt::UserRole + 2, QPixmap(":/blank.png"));
233 fDebugger.setCommandVisible(row, true);
234 fSkipCommands[row] = false;
235 }
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000236 }
237
kkinnunencfdc0e32015-01-13 22:49:02 -0800238 this->updateImage();
chudy@google.com902ebe52012-06-29 14:21:22 +0000239}
240
robertphillips@google.come8fe4bc2013-02-13 13:26:13 +0000241#if SK_SUPPORT_GPU
kkinnunen41c79cc2014-12-30 22:49:58 -0800242void SkDebuggerGUI::actionGLSettingsChanged() {
commit-bot@chromium.orgfde1e7c2013-08-02 13:59:50 +0000243 bool isToggled = fSettingsWidget.isGLActive();
244 if (isToggled) {
245 fCanvasWidget.setGLSampleCount(fSettingsWidget.getGLSampleCount());
246 }
chudy@google.comea5488b2012-07-26 19:38:22 +0000247 fCanvasWidget.setWidgetVisibility(SkCanvasWidget::kGPU_WidgetType, !isToggled);
248}
robertphillips@google.come8fe4bc2013-02-13 13:26:13 +0000249#endif
chudy@google.comea5488b2012-07-26 19:38:22 +0000250
chudy@google.com902ebe52012-06-29 14:21:22 +0000251void SkDebuggerGUI::actionInspector() {
kkinnunen41c79cc2014-12-30 22:49:58 -0800252 bool newState = !fInspectorWidget.isHidden();
253
254 fInspectorWidget.setHidden(newState);
255 fViewStateFrame.setHidden(newState);
kkinnunen63a47022014-12-30 23:03:56 -0800256 fDrawCommandGeometryWidget.setHidden(newState);
chudy@google.com902ebe52012-06-29 14:21:22 +0000257}
258
259void SkDebuggerGUI::actionPlay() {
chudy@google.comc432f002012-07-10 13:19:25 +0000260 for (int row = fListWidget.currentRow() + 1; row < fListWidget.count();
chudy@google.com7dcae672012-07-09 20:26:53 +0000261 row++) {
chudy@google.comc432f002012-07-10 13:19:25 +0000262 QListWidgetItem *item = fListWidget.item(row);
chudy@google.com902ebe52012-06-29 14:21:22 +0000263 if (item->checkState() == Qt::Checked) {
chudy@google.comc432f002012-07-10 13:19:25 +0000264 fListWidget.setCurrentItem(item);
chudy@google.com902ebe52012-06-29 14:21:22 +0000265 return;
266 }
267 }
chudy@google.comc432f002012-07-10 13:19:25 +0000268 fListWidget.setCurrentRow(fListWidget.count() - 1);
chudy@google.com902ebe52012-06-29 14:21:22 +0000269}
270
kkinnunen41c79cc2014-12-30 22:49:58 -0800271void SkDebuggerGUI::actionRasterSettingsChanged() {
272 fCanvasWidget.setWidgetVisibility(SkCanvasWidget::kRaster_8888_WidgetType,
273 !fSettingsWidget.isRasterEnabled());
274 fDebugger.setOverdrawViz(fSettingsWidget.isOverdrawVizEnabled());
kkinnunencfdc0e32015-01-13 22:49:02 -0800275 this->updateImage();
robertphillips@google.comf4741c12013-02-06 20:13:54 +0000276}
277
kkinnunen41c79cc2014-12-30 22:49:58 -0800278void SkDebuggerGUI::actionVisualizationsChanged() {
279 fDebugger.setMegaViz(fSettingsWidget.isMegaVizEnabled());
280 fDebugger.setPathOps(fSettingsWidget.isPathOpsEnabled());
281 fDebugger.highlightCurrentCommand(fSettingsWidget.isVisibilityFilterEnabled());
kkinnunencfdc0e32015-01-13 22:49:02 -0800282 this->updateImage();
commit-bot@chromium.org2a67e122014-05-19 13:53:10 +0000283}
284
robertphillips@google.com32bbcf82013-10-17 17:56:10 +0000285void SkDebuggerGUI::actionTextureFilter() {
reede7903c72015-03-16 10:26:13 -0700286 SkFilterQuality quality;
287 bool enabled = fSettingsWidget.getFilterOverride(&quality);
288 fDebugger.setTexFilterOverride(enabled, quality);
robertphillips@google.com32bbcf82013-10-17 17:56:10 +0000289 fCanvasWidget.update();
290}
291
chudy@google.com902ebe52012-06-29 14:21:22 +0000292void SkDebuggerGUI::actionRewind() {
chudy@google.come504de02012-07-16 18:35:23 +0000293 fListWidget.setCurrentRow(0);
chudy@google.com902ebe52012-06-29 14:21:22 +0000294}
295
chudy@google.com0ab03392012-07-28 20:16:11 +0000296void SkDebuggerGUI::actionSave() {
robertphillips@google.come219baf2013-01-28 19:25:43 +0000297 fFileName = fPath.toAscii().data();
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000298 fFileName.append("/");
robertphillips@google.come219baf2013-01-28 19:25:43 +0000299 fFileName.append(fDirectoryWidget.currentItem()->text().toAscii().data());
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000300 saveToFile(fFileName);
chudy@google.com0ab03392012-07-28 20:16:11 +0000301}
302
303void SkDebuggerGUI::actionSaveAs() {
304 QString filename = QFileDialog::getSaveFileName(this, "Save File", "",
305 "Skia Picture (*skp)");
chudy@google.com38b08ce2012-07-28 23:26:10 +0000306 if (!filename.endsWith(".skp", Qt::CaseInsensitive)) {
chudy@google.com0ab03392012-07-28 20:16:11 +0000307 filename.append(".skp");
308 }
djsollen@google.comc3c82162012-11-13 18:35:10 +0000309 saveToFile(SkString(filename.toAscii().data()));
chudy@google.com0ab03392012-07-28 20:16:11 +0000310}
311
chudy@google.com7dcae672012-07-09 20:26:53 +0000312void SkDebuggerGUI::actionScale(float scaleFactor) {
kkinnunen41c79cc2014-12-30 22:49:58 -0800313 fZoomBox.setText(QString::number(scaleFactor * 100, 'f', 0).append("%"));
chudy@google.com7dcae672012-07-09 20:26:53 +0000314}
315
chudy@google.com902ebe52012-06-29 14:21:22 +0000316void SkDebuggerGUI::actionSettings() {
chudy@google.comc432f002012-07-10 13:19:25 +0000317 if (fSettingsWidget.isHidden()) {
318 fSettingsWidget.setHidden(false);
chudy@google.com902ebe52012-06-29 14:21:22 +0000319 } else {
chudy@google.comc432f002012-07-10 13:19:25 +0000320 fSettingsWidget.setHidden(true);
chudy@google.com902ebe52012-06-29 14:21:22 +0000321 }
322}
323
324void SkDebuggerGUI::actionStepBack() {
chudy@google.comc432f002012-07-10 13:19:25 +0000325 int currentRow = fListWidget.currentRow();
chudy@google.com902ebe52012-06-29 14:21:22 +0000326 if (currentRow != 0) {
chudy@google.comc432f002012-07-10 13:19:25 +0000327 fListWidget.setCurrentRow(currentRow - 1);
chudy@google.com902ebe52012-06-29 14:21:22 +0000328 }
329}
330
331void SkDebuggerGUI::actionStepForward() {
chudy@google.comc432f002012-07-10 13:19:25 +0000332 int currentRow = fListWidget.currentRow();
chudy@google.com902ebe52012-06-29 14:21:22 +0000333 QString curRow = QString::number(currentRow);
chudy@google.comc432f002012-07-10 13:19:25 +0000334 QString curCount = QString::number(fListWidget.count());
335 if (currentRow < fListWidget.count() - 1) {
336 fListWidget.setCurrentRow(currentRow + 1);
chudy@google.com902ebe52012-06-29 14:21:22 +0000337 }
338}
339
chudy@google.coma9e937c2012-08-03 17:32:05 +0000340void SkDebuggerGUI::drawComplete() {
kkinnunencfdc0e32015-01-13 22:49:02 -0800341 SkString clipStack;
342 fDebugger.getClipStackText(&clipStack);
343 fInspectorWidget.setText(clipStack.c_str(), SkInspectorWidget::kClipStack_TabType);
344
chudy@google.com607357f2012-08-07 16:12:23 +0000345 fInspectorWidget.setMatrix(fDebugger.getCurrentMatrix());
346 fInspectorWidget.setClip(fDebugger.getCurrentClip());
chudy@google.coma9e937c2012-08-03 17:32:05 +0000347}
348
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000349void SkDebuggerGUI::saveToFile(const SkString& filename) {
350 SkFILEWStream file(filename.c_str());
robertphillips@google.com25bc2f82013-01-22 18:03:56 +0000351 SkAutoTUnref<SkPicture> copy(fDebugger.copyPicture());
352
robertphillips3e5c2b12015-03-23 05:46:51 -0700353 sk_tool_utils::PngPixelSerializer serializer;
354 copy->serialize(&file, &serializer);
chudy@google.com0ab03392012-07-28 20:16:11 +0000355}
356
chudy@google.com902ebe52012-06-29 14:21:22 +0000357void SkDebuggerGUI::loadFile(QListWidgetItem *item) {
358 if (fDirectoryWidgetActive) {
robertphillips@google.come219baf2013-01-28 19:25:43 +0000359 fFileName = fPath.toAscii().data();
jvanverth@google.com0ac6f162013-02-05 19:44:07 +0000360 // don't add a '/' to files in the local directory
361 if (fFileName.size() > 0) {
362 fFileName.append("/");
363 }
robertphillips@google.come219baf2013-01-28 19:25:43 +0000364 fFileName.append(item->text().toAscii().data());
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000365 loadPicture(fFileName);
chudy@google.com902ebe52012-06-29 14:21:22 +0000366 }
367}
368
369void SkDebuggerGUI::openFile() {
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000370 QString temp = QFileDialog::getOpenFileName(this, tr("Open File"), "",
chudy@google.com7dcae672012-07-09 20:26:53 +0000371 tr("Files (*.*)"));
robertphillips@google.comff6e6ba2013-01-28 17:43:26 +0000372 openFile(temp);
373}
374
375void SkDebuggerGUI::openFile(const QString &filename) {
chudy@google.com902ebe52012-06-29 14:21:22 +0000376 fDirectoryWidgetActive = false;
robertphillips@google.comff6e6ba2013-01-28 17:43:26 +0000377 if (!filename.isEmpty()) {
378 QFileInfo pathInfo(filename);
379 loadPicture(SkString(filename.toAscii().data()));
380 setupDirectoryWidget(pathInfo.path());
chudy@google.com902ebe52012-06-29 14:21:22 +0000381 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000382 fDirectoryWidgetActive = true;
383}
384
chudy@google.comc432f002012-07-10 13:19:25 +0000385void SkDebuggerGUI::pauseDrawing(bool isPaused) {
chudy@google.com607357f2012-08-07 16:12:23 +0000386 fPausedRow = fListWidget.currentRow();
kkinnunencfdc0e32015-01-13 22:49:02 -0800387 this->updateDrawCommandInfo();
chudy@google.com7dcae672012-07-09 20:26:53 +0000388}
389
kkinnunen0cfeaf32015-01-07 07:33:46 -0800390void SkDebuggerGUI::updateDrawCommandInfo() {
391 int currentRow = -1;
392 if (!fLoading) {
393 currentRow = fListWidget.currentRow();
394 }
395 if (currentRow == -1) {
396 fInspectorWidget.setText("", SkInspectorWidget::kDetail_TabType);
397 fInspectorWidget.setText("", SkInspectorWidget::kClipStack_TabType);
398 fCurrentCommandBox.setText("");
399 fDrawCommandGeometryWidget.setDrawCommandIndex(-1);
400 } else {
kkinnunencfdc0e32015-01-13 22:49:02 -0800401 this->updateImage();
402
kkinnunen0cfeaf32015-01-07 07:33:46 -0800403 const SkTDArray<SkString*> *currInfo = fDebugger.getCommandInfo(currentRow);
chudy@google.comd3058f52012-07-19 13:41:27 +0000404
kkinnunen0cfeaf32015-01-07 07:33:46 -0800405 /* TODO(chudy): Add command type before parameters. Rename v
406 * to something more informative. */
407 if (currInfo) {
408 QString info;
409 info.append("<b>Parameters: </b><br/>");
410 for (int i = 0; i < currInfo->count(); i++) {
411 info.append(QString((*currInfo)[i]->c_str()));
412 info.append("<br/>");
chudy@google.comd3058f52012-07-19 13:41:27 +0000413 }
kkinnunen0cfeaf32015-01-07 07:33:46 -0800414 fInspectorWidget.setText(info, SkInspectorWidget::kDetail_TabType);
chudy@google.comd3058f52012-07-19 13:41:27 +0000415 }
chudy@google.comea5488b2012-07-26 19:38:22 +0000416
kkinnunen0cfeaf32015-01-07 07:33:46 -0800417 fCurrentCommandBox.setText(QString::number(currentRow));
418
419 fDrawCommandGeometryWidget.setDrawCommandIndex(currentRow);
420
421 fInspectorWidget.setDisabled(false);
422 fViewStateFrame.setDisabled(false);
chudy@google.com902ebe52012-06-29 14:21:22 +0000423 }
424}
425
chudy@google.com9ca9bfe2012-07-12 21:58:14 +0000426void SkDebuggerGUI::selectCommand(int command) {
kkinnunenf3a9e992015-01-05 01:14:11 -0800427 if (this->isPaused()) {
chudy@google.com9ca9bfe2012-07-12 21:58:14 +0000428 fListWidget.setCurrentRow(command);
429 }
430}
431
chudy@google.com902ebe52012-06-29 14:21:22 +0000432void SkDebuggerGUI::toggleBreakpoint() {
chudy@google.comc432f002012-07-10 13:19:25 +0000433 QListWidgetItem* item = fListWidget.currentItem();
chudy@google.com902ebe52012-06-29 14:21:22 +0000434 if (item->checkState() == Qt::Unchecked) {
435 item->setCheckState(Qt::Checked);
chudy@google.come565de42012-07-12 14:15:54 +0000436 item->setData(Qt::DecorationRole,
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000437 QPixmap(":/breakpoint_16x16.png"));
chudy@google.com902ebe52012-06-29 14:21:22 +0000438 } else {
chudy@google.com902ebe52012-06-29 14:21:22 +0000439 item->setCheckState(Qt::Unchecked);
chudy@google.come565de42012-07-12 14:15:54 +0000440 item->setData(Qt::DecorationRole,
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000441 QPixmap(":/blank.png"));
chudy@google.com902ebe52012-06-29 14:21:22 +0000442 }
443}
444
445void SkDebuggerGUI::toggleDirectory() {
chudy@google.com607357f2012-08-07 16:12:23 +0000446 fDirectoryWidget.setHidden(!fDirectoryWidget.isHidden());
chudy@google.com902ebe52012-06-29 14:21:22 +0000447}
448
449void SkDebuggerGUI::toggleFilter(QString string) {
chudy@google.comc432f002012-07-10 13:19:25 +0000450 for (int row = 0; row < fListWidget.count(); row++) {
451 QListWidgetItem *item = fListWidget.item(row);
chudy@google.com607357f2012-08-07 16:12:23 +0000452 item->setHidden(item->text() != string);
chudy@google.com902ebe52012-06-29 14:21:22 +0000453 }
454}
455
456void SkDebuggerGUI::setupUi(QMainWindow *SkDebuggerGUI) {
457 QIcon windowIcon;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000458 windowIcon.addFile(QString::fromUtf8(":/skia.png"), QSize(),
chudy@google.com7dcae672012-07-09 20:26:53 +0000459 QIcon::Normal, QIcon::Off);
chudy@google.com902ebe52012-06-29 14:21:22 +0000460 SkDebuggerGUI->setObjectName(QString::fromUtf8("SkDebuggerGUI"));
461 SkDebuggerGUI->resize(1200, 1000);
462 SkDebuggerGUI->setWindowIcon(windowIcon);
chudy@google.comc432f002012-07-10 13:19:25 +0000463 SkDebuggerGUI->setWindowTitle("Skia Debugger");
chudy@google.com902ebe52012-06-29 14:21:22 +0000464
chudy@google.come504de02012-07-16 18:35:23 +0000465 fActionOpen.setShortcuts(QKeySequence::Open);
chudy@google.comc432f002012-07-10 13:19:25 +0000466 fActionOpen.setText("Open");
chudy@google.com902ebe52012-06-29 14:21:22 +0000467
468 QIcon breakpoint;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000469 breakpoint.addFile(QString::fromUtf8(":/breakpoint.png"),
chudy@google.com7dcae672012-07-09 20:26:53 +0000470 QSize(), QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000471 fActionBreakpoint.setShortcut(QKeySequence(tr("Ctrl+B")));
chudy@google.comc432f002012-07-10 13:19:25 +0000472 fActionBreakpoint.setIcon(breakpoint);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000473 fActionBreakpoint.setText("Breakpoints");
kkinnunenf3a9e992015-01-05 01:14:11 -0800474 fActionBreakpoint.setCheckable(true);
chudy@google.com902ebe52012-06-29 14:21:22 +0000475
476 QIcon cancel;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000477 cancel.addFile(QString::fromUtf8(":/reload.png"), QSize(),
chudy@google.com7dcae672012-07-09 20:26:53 +0000478 QIcon::Normal, QIcon::Off);
chudy@google.comc432f002012-07-10 13:19:25 +0000479 fActionCancel.setIcon(cancel);
480 fActionCancel.setText("Clear Filter");
chudy@google.com902ebe52012-06-29 14:21:22 +0000481
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000482 fActionClearBreakpoints.setShortcut(QKeySequence(tr("Alt+B")));
483 fActionClearBreakpoints.setText("Clear Breakpoints");
484
485 fActionClearDeletes.setShortcut(QKeySequence(tr("Alt+X")));
486 fActionClearDeletes.setText("Clear Deletes");
487
chudy@google.come504de02012-07-16 18:35:23 +0000488 fActionClose.setShortcuts(QKeySequence::Quit);
chudy@google.comc432f002012-07-10 13:19:25 +0000489 fActionClose.setText("Exit");
chudy@google.com902ebe52012-06-29 14:21:22 +0000490
chudy@google.come504de02012-07-16 18:35:23 +0000491 fActionCreateBreakpoint.setShortcut(QKeySequence(tr("B")));
492 fActionCreateBreakpoint.setText("Set Breakpoint");
493
494 fActionDelete.setShortcut(QKeySequence(tr("X")));
chudy@google.comc432f002012-07-10 13:19:25 +0000495 fActionDelete.setText("Delete Command");
chudy@google.com902ebe52012-06-29 14:21:22 +0000496
chudy@google.come504de02012-07-16 18:35:23 +0000497 fActionDirectory.setShortcut(QKeySequence(tr("Ctrl+D")));
498 fActionDirectory.setText("Directory");
chudy@google.com902ebe52012-06-29 14:21:22 +0000499
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000500 QIcon profile;
robertphillips@google.comd1636362012-11-19 18:25:09 +0000501 profile.addFile(QString::fromUtf8(":/profile.png"), QSize(),
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000502 QIcon::Normal, QIcon::Off);
503 fActionProfile.setIcon(profile);
504 fActionProfile.setText("Profile");
robertphillips@google.come099bc42012-11-19 16:26:40 +0000505 fActionProfile.setDisabled(true);
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000506
chudy@google.comc432f002012-07-10 13:19:25 +0000507 QIcon inspector;
robertphillips@google.comd1636362012-11-19 18:25:09 +0000508 inspector.addFile(QString::fromUtf8(":/inspector.png"),
chudy@google.comc432f002012-07-10 13:19:25 +0000509 QSize(), QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000510 fActionInspector.setShortcut(QKeySequence(tr("Ctrl+I")));
chudy@google.comc432f002012-07-10 13:19:25 +0000511 fActionInspector.setIcon(inspector);
chudy@google.come504de02012-07-16 18:35:23 +0000512 fActionInspector.setText("Inspector");
chudy@google.com902ebe52012-06-29 14:21:22 +0000513
bungeman@google.com2ff6d1d2013-07-01 14:24:12 +0000514 QIcon settings;
515 settings.addFile(QString::fromUtf8(":/inspector.png"),
516 QSize(), QIcon::Normal, QIcon::Off);
517 fActionSettings.setShortcut(QKeySequence(tr("Ctrl+G")));
518 fActionSettings.setIcon(settings);
519 fActionSettings.setText("Settings");
skia.committer@gmail.com0d55dd72013-07-02 07:00:59 +0000520
chudy@google.comc432f002012-07-10 13:19:25 +0000521 QIcon play;
robertphillips@google.comd1636362012-11-19 18:25:09 +0000522 play.addFile(QString::fromUtf8(":/play.png"), QSize(),
chudy@google.comc432f002012-07-10 13:19:25 +0000523 QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000524 fActionPlay.setShortcut(QKeySequence(tr("Ctrl+P")));
chudy@google.comc432f002012-07-10 13:19:25 +0000525 fActionPlay.setIcon(play);
526 fActionPlay.setText("Play");
chudy@google.com902ebe52012-06-29 14:21:22 +0000527
chudy@google.come504de02012-07-16 18:35:23 +0000528 QIcon pause;
robertphillips@google.comd1636362012-11-19 18:25:09 +0000529 pause.addFile(QString::fromUtf8(":/pause.png"), QSize(),
chudy@google.comc432f002012-07-10 13:19:25 +0000530 QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000531 fActionPause.setShortcut(QKeySequence(tr("Space")));
532 fActionPause.setCheckable(true);
533 fActionPause.setIcon(pause);
534 fActionPause.setText("Pause");
535
chudy@google.comc432f002012-07-10 13:19:25 +0000536 QIcon rewind;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000537 rewind.addFile(QString::fromUtf8(":/rewind.png"), QSize(),
chudy@google.comc432f002012-07-10 13:19:25 +0000538 QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000539 fActionRewind.setShortcut(QKeySequence(tr("Ctrl+R")));
chudy@google.comc432f002012-07-10 13:19:25 +0000540 fActionRewind.setIcon(rewind);
541 fActionRewind.setText("Rewind");
chudy@google.com902ebe52012-06-29 14:21:22 +0000542
chudy@google.com0ab03392012-07-28 20:16:11 +0000543 fActionSave.setShortcut(QKeySequence::Save);
544 fActionSave.setText("Save");
545 fActionSave.setDisabled(true);
546 fActionSaveAs.setShortcut(QKeySequence::SaveAs);
547 fActionSaveAs.setText("Save As");
548 fActionSaveAs.setDisabled(true);
549
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000550 fActionShowDeletes.setShortcut(QKeySequence(tr("Ctrl+X")));
551 fActionShowDeletes.setText("Deleted Commands");
kkinnunenf3a9e992015-01-05 01:14:11 -0800552 fActionShowDeletes.setCheckable(true);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000553
chudy@google.comc432f002012-07-10 13:19:25 +0000554 QIcon stepBack;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000555 stepBack.addFile(QString::fromUtf8(":/previous.png"), QSize(),
chudy@google.comc432f002012-07-10 13:19:25 +0000556 QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000557 fActionStepBack.setShortcut(QKeySequence(tr("[")));
chudy@google.comc432f002012-07-10 13:19:25 +0000558 fActionStepBack.setIcon(stepBack);
559 fActionStepBack.setText("Step Back");
chudy@google.com902ebe52012-06-29 14:21:22 +0000560
chudy@google.comc432f002012-07-10 13:19:25 +0000561 QIcon stepForward;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000562 stepForward.addFile(QString::fromUtf8(":/next.png"),
chudy@google.comc432f002012-07-10 13:19:25 +0000563 QSize(), QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000564 fActionStepForward.setShortcut(QKeySequence(tr("]")));
chudy@google.comc432f002012-07-10 13:19:25 +0000565 fActionStepForward.setIcon(stepForward);
566 fActionStepForward.setText("Step Forward");
567
chudy@google.coma1226312012-07-26 20:26:44 +0000568 fActionZoomIn.setShortcut(QKeySequence(tr("Ctrl+=")));
569 fActionZoomIn.setText("Zoom In");
570 fActionZoomOut.setShortcut(QKeySequence(tr("Ctrl+-")));
571 fActionZoomOut.setText("Zoom Out");
572
chudy@google.comc432f002012-07-10 13:19:25 +0000573 fListWidget.setItemDelegate(new SkListWidget(&fListWidget));
574 fListWidget.setObjectName(QString::fromUtf8("listWidget"));
commit-bot@chromium.orgbcd431e2013-11-21 13:41:37 +0000575 fListWidget.setMinimumWidth(250);
chudy@google.comc432f002012-07-10 13:19:25 +0000576
577 fFilter.addItem("--Filter By Available Commands--");
578
commit-bot@chromium.orgbcd431e2013-11-21 13:41:37 +0000579 fDirectoryWidget.setMinimumWidth(250);
chudy@google.comc432f002012-07-10 13:19:25 +0000580 fDirectoryWidget.setStyleSheet("QListWidget::Item {padding: 5px;}");
581
582 fCanvasWidget.setSizePolicy(QSizePolicy::Expanding,
chudy@google.com7dcae672012-07-09 20:26:53 +0000583 QSizePolicy::Expanding);
chudy@google.com902ebe52012-06-29 14:21:22 +0000584
kkinnunen63a47022014-12-30 23:03:56 -0800585 fDrawCommandGeometryWidget.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000586
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000587 fSettingsAndImageLayout.addWidget(&fSettingsWidget);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000588
kkinnunen41c79cc2014-12-30 22:49:58 -0800589 // View state group, part of inspector.
590 fViewStateFrame.setFrameStyle(QFrame::Panel);
591 fViewStateFrame.setLayout(&fViewStateFrameLayout);
592 fViewStateFrameLayout.addWidget(&fViewStateGroup);
kkinnunen63a47022014-12-30 23:03:56 -0800593 fViewStateGroup.setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
kkinnunen41c79cc2014-12-30 22:49:58 -0800594 fViewStateGroup.setTitle("View");
595 fViewStateLayout.addRow("Zoom Level", &fZoomBox);
596 fZoomBox.setText("100%");
597 fZoomBox.setMinimumSize(QSize(50,25));
598 fZoomBox.setMaximumSize(QSize(50,25));
599 fZoomBox.setAlignment(Qt::AlignRight);
600 fZoomBox.setReadOnly(true);
601 fViewStateLayout.addRow("Command HitBox", &fCommandHitBox);
602 fCommandHitBox.setText("0");
603 fCommandHitBox.setMinimumSize(QSize(50,25));
604 fCommandHitBox.setMaximumSize(QSize(50,25));
605 fCommandHitBox.setAlignment(Qt::AlignRight);
606 fCommandHitBox.setReadOnly(true);
607 fViewStateLayout.addRow("Current Command", &fCurrentCommandBox);
608 fCurrentCommandBox.setText("0");
609 fCurrentCommandBox.setMinimumSize(QSize(50,25));
610 fCurrentCommandBox.setMaximumSize(QSize(50,25));
611 fCurrentCommandBox.setAlignment(Qt::AlignRight);
612 fCurrentCommandBox.setReadOnly(true);
613 fViewStateGroup.setLayout(&fViewStateLayout);
614 fSettingsAndImageLayout.addWidget(&fViewStateFrame);
615
kkinnunen63a47022014-12-30 23:03:56 -0800616 fDrawCommandGeometryWidget.setToolTip("Current Command Geometry");
617 fSettingsAndImageLayout.addWidget(&fDrawCommandGeometryWidget);
chudy@google.com902ebe52012-06-29 14:21:22 +0000618
commit-bot@chromium.orgbcd431e2013-11-21 13:41:37 +0000619 fLeftColumnSplitter.addWidget(&fListWidget);
620 fLeftColumnSplitter.addWidget(&fDirectoryWidget);
621 fLeftColumnSplitter.setOrientation(Qt::Vertical);
chudy@google.com902ebe52012-06-29 14:21:22 +0000622
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000623 fCanvasSettingsAndImageLayout.setSpacing(6);
kkinnunen41c79cc2014-12-30 22:49:58 -0800624 fCanvasSettingsAndImageLayout.addWidget(&fCanvasWidget, 1);
625 fCanvasSettingsAndImageLayout.addLayout(&fSettingsAndImageLayout, 0);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000626
chudy@google.comc432f002012-07-10 13:19:25 +0000627 fMainAndRightColumnLayout.setSpacing(6);
kkinnunen7c339ae2015-01-02 06:35:43 -0800628 fMainAndRightColumnLayout.addLayout(&fCanvasSettingsAndImageLayout, 1);
629 fMainAndRightColumnLayout.addWidget(&fInspectorWidget, 0);
commit-bot@chromium.orgbcd431e2013-11-21 13:41:37 +0000630 fMainAndRightColumnWidget.setLayout(&fMainAndRightColumnLayout);
chudy@google.com902ebe52012-06-29 14:21:22 +0000631
commit-bot@chromium.orgbcd431e2013-11-21 13:41:37 +0000632 fCentralSplitter.addWidget(&fLeftColumnSplitter);
633 fCentralSplitter.addWidget(&fMainAndRightColumnWidget);
634 fCentralSplitter.setStretchFactor(0, 0);
635 fCentralSplitter.setStretchFactor(1, 1);
chudy@google.comc432f002012-07-10 13:19:25 +0000636
commit-bot@chromium.orgbcd431e2013-11-21 13:41:37 +0000637 SkDebuggerGUI->setCentralWidget(&fCentralSplitter);
chudy@google.comc432f002012-07-10 13:19:25 +0000638 SkDebuggerGUI->setStatusBar(&fStatusBar);
639
chudy@google.come504de02012-07-16 18:35:23 +0000640 fToolBar.setIconSize(QSize(32, 32));
chudy@google.comc432f002012-07-10 13:19:25 +0000641 fToolBar.setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
642 SkDebuggerGUI->addToolBar(Qt::TopToolBarArea, &fToolBar);
chudy@google.com902ebe52012-06-29 14:21:22 +0000643
chudy@google.com0ab03392012-07-28 20:16:11 +0000644 fSpacer.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
chudy@google.com902ebe52012-06-29 14:21:22 +0000645
chudy@google.comc432f002012-07-10 13:19:25 +0000646 fToolBar.addAction(&fActionRewind);
647 fToolBar.addAction(&fActionStepBack);
chudy@google.come504de02012-07-16 18:35:23 +0000648 fToolBar.addAction(&fActionPause);
chudy@google.comc432f002012-07-10 13:19:25 +0000649 fToolBar.addAction(&fActionStepForward);
650 fToolBar.addAction(&fActionPlay);
651 fToolBar.addSeparator();
chudy@google.come504de02012-07-16 18:35:23 +0000652 fToolBar.addAction(&fActionInspector);
bungeman@google.com2ff6d1d2013-07-01 14:24:12 +0000653 fToolBar.addAction(&fActionSettings);
chudy@google.comc432f002012-07-10 13:19:25 +0000654 fToolBar.addSeparator();
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000655 fToolBar.addAction(&fActionProfile);
656
657 fToolBar.addSeparator();
chudy@google.com0ab03392012-07-28 20:16:11 +0000658 fToolBar.addWidget(&fSpacer);
chudy@google.comc432f002012-07-10 13:19:25 +0000659 fToolBar.addWidget(&fFilter);
660 fToolBar.addAction(&fActionCancel);
chudy@google.com902ebe52012-06-29 14:21:22 +0000661
662 // TODO(chudy): Remove static call.
663 fDirectoryWidgetActive = false;
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000664 fFileName = "";
robertphillips@google.comff6e6ba2013-01-28 17:43:26 +0000665 setupDirectoryWidget("");
chudy@google.com902ebe52012-06-29 14:21:22 +0000666 fDirectoryWidgetActive = true;
667
chudy@google.com902ebe52012-06-29 14:21:22 +0000668 // Menu Bar
chudy@google.comc432f002012-07-10 13:19:25 +0000669 fMenuFile.setTitle("File");
670 fMenuFile.addAction(&fActionOpen);
chudy@google.com0ab03392012-07-28 20:16:11 +0000671 fMenuFile.addAction(&fActionSave);
672 fMenuFile.addAction(&fActionSaveAs);
chudy@google.comc432f002012-07-10 13:19:25 +0000673 fMenuFile.addAction(&fActionClose);
chudy@google.come504de02012-07-16 18:35:23 +0000674
675 fMenuEdit.setTitle("Edit");
676 fMenuEdit.addAction(&fActionDelete);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000677 fMenuEdit.addAction(&fActionClearDeletes);
678 fMenuEdit.addSeparator();
chudy@google.come504de02012-07-16 18:35:23 +0000679 fMenuEdit.addAction(&fActionCreateBreakpoint);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000680 fMenuEdit.addAction(&fActionClearBreakpoints);
chudy@google.come504de02012-07-16 18:35:23 +0000681
chudy@google.comc432f002012-07-10 13:19:25 +0000682 fMenuNavigate.setTitle("Navigate");
chudy@google.come504de02012-07-16 18:35:23 +0000683 fMenuNavigate.addAction(&fActionRewind);
684 fMenuNavigate.addAction(&fActionStepBack);
685 fMenuNavigate.addAction(&fActionStepForward);
686 fMenuNavigate.addAction(&fActionPlay);
687 fMenuNavigate.addAction(&fActionPause);
chudy@google.comc432f002012-07-10 13:19:25 +0000688 fMenuNavigate.addAction(&fActionGoToLine);
chudy@google.come504de02012-07-16 18:35:23 +0000689
chudy@google.comc432f002012-07-10 13:19:25 +0000690 fMenuView.setTitle("View");
chudy@google.come504de02012-07-16 18:35:23 +0000691 fMenuView.addAction(&fActionBreakpoint);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000692 fMenuView.addAction(&fActionShowDeletes);
chudy@google.coma1226312012-07-26 20:26:44 +0000693 fMenuView.addAction(&fActionZoomIn);
694 fMenuView.addAction(&fActionZoomOut);
chudy@google.come504de02012-07-16 18:35:23 +0000695
696 fMenuWindows.setTitle("Window");
697 fMenuWindows.addAction(&fActionInspector);
bungeman@google.com2ff6d1d2013-07-01 14:24:12 +0000698 fMenuWindows.addAction(&fActionSettings);
chudy@google.come504de02012-07-16 18:35:23 +0000699 fMenuWindows.addAction(&fActionDirectory);
chudy@google.comc432f002012-07-10 13:19:25 +0000700
701 fActionGoToLine.setText("Go to Line...");
702 fActionGoToLine.setDisabled(true);
703 fMenuBar.addAction(fMenuFile.menuAction());
chudy@google.come504de02012-07-16 18:35:23 +0000704 fMenuBar.addAction(fMenuEdit.menuAction());
chudy@google.comc432f002012-07-10 13:19:25 +0000705 fMenuBar.addAction(fMenuView.menuAction());
706 fMenuBar.addAction(fMenuNavigate.menuAction());
chudy@google.come504de02012-07-16 18:35:23 +0000707 fMenuBar.addAction(fMenuWindows.menuAction());
chudy@google.com902ebe52012-06-29 14:21:22 +0000708
chudy@google.comc432f002012-07-10 13:19:25 +0000709 SkDebuggerGUI->setMenuBar(&fMenuBar);
chudy@google.com902ebe52012-06-29 14:21:22 +0000710 QMetaObject::connectSlotsByName(SkDebuggerGUI);
711}
712
robertphillips@google.comff6e6ba2013-01-28 17:43:26 +0000713void SkDebuggerGUI::setupDirectoryWidget(const QString& path) {
714 fPath = path;
715 QDir dir(path);
chudy@google.com902ebe52012-06-29 14:21:22 +0000716 QRegExp r(".skp");
chudy@google.comc432f002012-07-10 13:19:25 +0000717 fDirectoryWidget.clear();
718 const QStringList files = dir.entryList();
chudy@google.com902ebe52012-06-29 14:21:22 +0000719 foreach (QString f, files) {
chudy@google.com7dcae672012-07-09 20:26:53 +0000720 if (f.contains(r))
chudy@google.comc432f002012-07-10 13:19:25 +0000721 fDirectoryWidget.addItem(f);
chudy@google.com902ebe52012-06-29 14:21:22 +0000722 }
723}
724
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000725void SkDebuggerGUI::loadPicture(const SkString& fileName) {
726 fFileName = fileName;
chudy@google.comd3058f52012-07-19 13:41:27 +0000727 fLoading = true;
scroggoa1193e42015-01-21 12:09:53 -0800728 SkAutoTDelete<SkStream> stream(SkNEW_ARGS(SkFILEStream, (fileName.c_str())));
robertphillips@google.com2d40ec42013-02-07 20:39:40 +0000729
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000730 SkPicture* picture = SkPicture::CreateFromStream(stream);
robertphillips@google.com2d40ec42013-02-07 20:39:40 +0000731
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000732 if (NULL == picture) {
robertphillips@google.com2d40ec42013-02-07 20:39:40 +0000733 QMessageBox::critical(this, "Error loading file", "Couldn't read file, sorry.");
robertphillips@google.com2d40ec42013-02-07 20:39:40 +0000734 return;
735 }
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000736
chudy@google.com686e6802012-08-14 16:00:32 +0000737 fCanvasWidget.resetWidgetTransform();
chudy@google.com607357f2012-08-07 16:12:23 +0000738 fDebugger.loadPicture(picture);
chudy@google.com4c7962e2012-08-14 19:38:31 +0000739
robertphillips@google.com6d9c92b2013-05-23 13:21:18 +0000740 fSkipCommands.setCount(fDebugger.getSize());
741 for (int i = 0; i < fSkipCommands.count(); ++i) {
robertphillips@google.com5f971142012-12-07 20:48:56 +0000742 fSkipCommands[i] = false;
743 }
744
chudy@google.com607357f2012-08-07 16:12:23 +0000745 SkSafeUnref(picture);
746
robertphillips@google.com6d9c92b2013-05-23 13:21:18 +0000747 fActionProfile.setDisabled(false);
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000748
chudy@google.com7dcae672012-07-09 20:26:53 +0000749 /* fDebugCanvas is reinitialized every load picture. Need it to retain value
chudy@google.com607357f2012-08-07 16:12:23 +0000750 * of the visibility filter.
751 * TODO(chudy): This should be deprecated since fDebugger is not
752 * recreated.
753 * */
kkinnunen41c79cc2014-12-30 22:49:58 -0800754 fDebugger.highlightCurrentCommand(fSettingsWidget.isVisibilityFilterEnabled());
chudy@google.com607357f2012-08-07 16:12:23 +0000755
kkinnunen5037e9d2014-12-30 07:22:58 -0800756 this->setupListWidget();
757 this->setupComboBox();
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000758 this->setupOverviewText(NULL, 0.0, 1);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000759 fInspectorWidget.setDisabled(false);
kkinnunen41c79cc2014-12-30 22:49:58 -0800760 fViewStateFrame.setDisabled(false);
chudy@google.come606d6e2012-07-12 14:31:25 +0000761 fSettingsWidget.setDisabled(false);
chudy@google.comd3058f52012-07-19 13:41:27 +0000762 fMenuEdit.setDisabled(false);
763 fMenuNavigate.setDisabled(false);
764 fMenuView.setDisabled(false);
chudy@google.com0ab03392012-07-28 20:16:11 +0000765 fActionSave.setDisabled(false);
766 fActionSaveAs.setDisabled(false);
kkinnunenf3a9e992015-01-05 01:14:11 -0800767 fActionPause.setChecked(false);
kkinnunen0cfeaf32015-01-07 07:33:46 -0800768 fDrawCommandGeometryWidget.setDrawCommandIndex(-1);
769
chudy@google.comd3058f52012-07-19 13:41:27 +0000770 fLoading = false;
771 actionPlay();
chudy@google.com902ebe52012-06-29 14:21:22 +0000772}
773
kkinnunen5037e9d2014-12-30 07:22:58 -0800774void SkDebuggerGUI::setupListWidget() {
robertphillips546db462015-03-26 10:08:04 -0700775
776 SkASSERT(!strcmp("Save",
777 SkDrawCommand::GetCommandString(SkDrawCommand::kSave_OpType)));
778 SkASSERT(!strcmp("SaveLayer",
779 SkDrawCommand::GetCommandString(SkDrawCommand::kSaveLayer_OpType)));
780 SkASSERT(!strcmp("Restore",
781 SkDrawCommand::GetCommandString(SkDrawCommand::kRestore_OpType)));
782 SkASSERT(!strcmp("BeginCommentGroup",
783 SkDrawCommand::GetCommandString(SkDrawCommand::kBeginCommentGroup_OpType)));
784 SkASSERT(!strcmp("EndCommentGroup",
785 SkDrawCommand::GetCommandString(SkDrawCommand::kEndCommentGroup_OpType)));
fmalita160ebb22015-04-01 20:58:37 -0700786 SkASSERT(!strcmp("BeginDrawPicture",
787 SkDrawCommand::GetCommandString(SkDrawCommand::kBeginDrawPicture_OpType)));
788 SkASSERT(!strcmp("EndDrawPicture",
789 SkDrawCommand::GetCommandString(SkDrawCommand::kEndDrawPicture_OpType)));
robertphillips546db462015-03-26 10:08:04 -0700790
chudy@google.comc432f002012-07-10 13:19:25 +0000791 fListWidget.clear();
chudy@google.com902ebe52012-06-29 14:21:22 +0000792 int counter = 0;
robertphillips@google.com30d35f22012-11-06 16:45:36 +0000793 int indent = 0;
kkinnunen5037e9d2014-12-30 07:22:58 -0800794 for (int i = 0; i < fDebugger.getSize(); i++) {
chudy@google.com902ebe52012-06-29 14:21:22 +0000795 QListWidgetItem *item = new QListWidgetItem();
kkinnunen5037e9d2014-12-30 07:22:58 -0800796 SkDrawCommand* command = fDebugger.getDrawCommandAt(i);
797 SkString commandString = command->toString();
798 item->setData(Qt::DisplayRole, commandString.c_str());
chudy@google.com902ebe52012-06-29 14:21:22 +0000799 item->setData(Qt::UserRole + 1, counter++);
robertphillips@google.com30d35f22012-11-06 16:45:36 +0000800
kkinnunen5037e9d2014-12-30 07:22:58 -0800801 if (0 == strcmp("Restore", commandString.c_str()) ||
fmalita160ebb22015-04-01 20:58:37 -0700802 0 == strcmp("EndCommentGroup", commandString.c_str()) ||
803 0 == strcmp("EndDrawPicture", commandString.c_str())) {
robertphillips@google.com30d35f22012-11-06 16:45:36 +0000804 indent -= 10;
805 }
806
807 item->setData(Qt::UserRole + 3, indent);
808
kkinnunen5037e9d2014-12-30 07:22:58 -0800809 if (0 == strcmp("Save", commandString.c_str()) ||
robertphillips546db462015-03-26 10:08:04 -0700810 0 == strcmp("SaveLayer", commandString.c_str()) ||
fmalita160ebb22015-04-01 20:58:37 -0700811 0 == strcmp("BeginCommentGroup", commandString.c_str()) ||
812 0 == strcmp("BeginDrawPicture", commandString.c_str())) {
robertphillips@google.com30d35f22012-11-06 16:45:36 +0000813 indent += 10;
814 }
815
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000816 item->setData(Qt::UserRole + 4, -1);
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000817
chudy@google.comc432f002012-07-10 13:19:25 +0000818 fListWidget.addItem(item);
chudy@google.com902ebe52012-06-29 14:21:22 +0000819 }
820}
821
skia.committer@gmail.com91274b92013-03-13 07:01:04 +0000822void SkDebuggerGUI::setupOverviewText(const SkTDArray<double>* typeTimes,
robertphillips@google.come428f9b2013-03-12 15:33:40 +0000823 double totTime,
824 int numRuns) {
borenet@google.com2d9dbd42013-03-12 13:07:40 +0000825 SkString overview;
robertphillips@google.come428f9b2013-03-12 15:33:40 +0000826 fDebugger.getOverviewText(typeTimes, totTime, &overview, numRuns);
borenet@google.com2d9dbd42013-03-12 13:07:40 +0000827 fInspectorWidget.setText(overview.c_str(), SkInspectorWidget::kOverview_TabType);
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000828}
829
commit-bot@chromium.org2a67e122014-05-19 13:53:10 +0000830
kkinnunen5037e9d2014-12-30 07:22:58 -0800831void SkDebuggerGUI::setupComboBox() {
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000832 fFilter.clear();
833 fFilter.addItem("--Filter By Available Commands--");
834
835 std::map<std::string, int> map;
kkinnunen5037e9d2014-12-30 07:22:58 -0800836 for (int i = 0; i < fDebugger.getSize(); i++) {
837 map[fDebugger.getDrawCommandAt(i)->toString().c_str()]++;
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000838 }
839
skia.committer@gmail.com34587162012-11-20 02:01:23 +0000840 for (std::map<std::string, int>::iterator it = map.begin(); it != map.end();
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000841 ++it) {
842 fFilter.addItem((it->first).c_str());
843 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000844
845 // NOTE(chudy): Makes first item unselectable.
chudy@google.com7dcae672012-07-09 20:26:53 +0000846 QStandardItemModel* model = qobject_cast<QStandardItemModel*>(
chudy@google.comc432f002012-07-10 13:19:25 +0000847 fFilter.model());
848 QModelIndex firstIndex = model->index(0, fFilter.modelColumn(),
849 fFilter.rootModelIndex());
chudy@google.com902ebe52012-06-29 14:21:22 +0000850 QStandardItem* firstItem = model->itemFromIndex(firstIndex);
851 firstItem->setSelectable(false);
852}
kkinnunen41c79cc2014-12-30 22:49:58 -0800853
kkinnunencfdc0e32015-01-13 22:49:02 -0800854void SkDebuggerGUI::updateImage() {
855 if (this->isPaused()) {
856 fCanvasWidget.drawTo(fPausedRow);
857 } else {
858 fCanvasWidget.drawTo(fListWidget.currentRow());
859 }
860}
861
kkinnunen41c79cc2014-12-30 22:49:58 -0800862void SkDebuggerGUI::updateHit(int newHit) {
863 fCommandHitBox.setText(QString::number(newHit));
864}
865