blob: 01d8c665e35ce8877a12d1e1831793d0723c4c1a [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>
robertphillips@google.come174a8b2012-11-27 16:04:42 +000015
16#if defined(SK_BUILD_FOR_WIN32)
mtklein9ac68ee2014-06-20 11:29:20 -070017 #include "SysTimer_windows.h"
robertphillips@google.come174a8b2012-11-27 16:04:42 +000018#elif defined(SK_BUILD_FOR_MAC)
mtklein9ac68ee2014-06-20 11:29:20 -070019 #include "SysTimer_mach.h"
robertphillips@google.come174a8b2012-11-27 16:04:42 +000020#elif defined(SK_BUILD_FOR_UNIX) || defined(SK_BUILD_FOR_ANDROID)
mtklein9ac68ee2014-06-20 11:29:20 -070021 #include "SysTimer_posix.h"
robertphillips@google.come174a8b2012-11-27 16:04:42 +000022#else
mtklein9ac68ee2014-06-20 11:29:20 -070023 #include "SysTimer_c.h"
robertphillips@google.come174a8b2012-11-27 16:04:42 +000024#endif
25
chudy@google.com902ebe52012-06-29 14:21:22 +000026
27SkDebuggerGUI::SkDebuggerGUI(QWidget *parent) :
chudy@google.comc432f002012-07-10 13:19:25 +000028 QMainWindow(parent)
commit-bot@chromium.orgbcd431e2013-11-21 13:41:37 +000029 , fCentralSplitter(this)
chudy@google.com2d537a12012-07-31 12:49:52 +000030 , fStatusBar(this)
31 , fToolBar(this)
chudy@google.comc432f002012-07-10 13:19:25 +000032 , fActionOpen(this)
33 , fActionBreakpoint(this)
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +000034 , fActionToggleIndexStyle(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()));
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +000081 connect(&fActionToggleIndexStyle, SIGNAL(triggered()), this, SLOT(actionToggleIndexStyle()));
chudy@google.comea5488b2012-07-26 19:38:22 +000082 connect(&fActionInspector, SIGNAL(triggered()), this, SLOT(actionInspector()));
bungeman@google.com2ff6d1d2013-07-01 14:24:12 +000083 connect(&fActionSettings, SIGNAL(triggered()), this, SLOT(actionSettings()));
chudy@google.comea5488b2012-07-26 19:38:22 +000084 connect(&fFilter, SIGNAL(activated(QString)), this, SLOT(toggleFilter(QString)));
robertphillips@google.comd26c7062012-11-12 20:42:12 +000085 connect(&fActionProfile, SIGNAL(triggered()), this, SLOT(actionProfile()));
chudy@google.comc432f002012-07-10 13:19:25 +000086 connect(&fActionCancel, SIGNAL(triggered()), this, SLOT(actionCancel()));
chudy@google.com7e4cfbf2012-07-17 15:40:51 +000087 connect(&fActionClearBreakpoints, SIGNAL(triggered()), this, SLOT(actionClearBreakpoints()));
88 connect(&fActionClearDeletes, SIGNAL(triggered()), this, SLOT(actionClearDeletes()));
chudy@google.comc432f002012-07-10 13:19:25 +000089 connect(&fActionClose, SIGNAL(triggered()), this, SLOT(actionClose()));
robertphillips@google.come8fe4bc2013-02-13 13:26:13 +000090#if SK_SUPPORT_GPU
kkinnunen41c79cc2014-12-30 22:49:58 -080091 connect(&fSettingsWidget, SIGNAL(glSettingsChanged()), this, SLOT(actionGLSettingsChanged()));
robertphillips@google.come8fe4bc2013-02-13 13:26:13 +000092#endif
kkinnunen41c79cc2014-12-30 22:49:58 -080093 connect(&fSettingsWidget, SIGNAL(rasterSettingsChanged()), this, SLOT(actionRasterSettingsChanged()));
94 connect(&fSettingsWidget, SIGNAL(visualizationsChanged()), this, SLOT(actionVisualizationsChanged()));
robertphillips@google.com32bbcf82013-10-17 17:56:10 +000095 connect(&fSettingsWidget, SIGNAL(texFilterSettingsChanged()), this, SLOT(actionTextureFilter()));
chudy@google.comea5488b2012-07-26 19:38:22 +000096 connect(&fActionPause, SIGNAL(toggled(bool)), this, SLOT(pauseDrawing(bool)));
chudy@google.come504de02012-07-16 18:35:23 +000097 connect(&fActionCreateBreakpoint, SIGNAL(activated()), this, SLOT(toggleBreakpoint()));
chudy@google.com7e4cfbf2012-07-17 15:40:51 +000098 connect(&fActionShowDeletes, SIGNAL(triggered()), this, SLOT(showDeletes()));
chudy@google.comea5488b2012-07-26 19:38:22 +000099 connect(&fCanvasWidget, SIGNAL(hitChanged(int)), this, SLOT(selectCommand(int)));
kkinnunen41c79cc2014-12-30 22:49:58 -0800100 connect(&fCanvasWidget, SIGNAL(hitChanged(int)), this, SLOT(updateHit(int)));
chudy@google.comea5488b2012-07-26 19:38:22 +0000101 connect(&fCanvasWidget, SIGNAL(scaleFactorChanged(float)), this, SLOT(actionScale(float)));
kkinnunen63a47022014-12-30 23:03:56 -0800102
chudy@google.com0ab03392012-07-28 20:16:11 +0000103 connect(&fActionSaveAs, SIGNAL(triggered()), this, SLOT(actionSaveAs()));
104 connect(&fActionSave, SIGNAL(triggered()), this, SLOT(actionSave()));
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000105
bungeman@google.come8cc6e82013-01-17 16:30:56 +0000106 fMapper.setMapping(&fActionZoomIn, SkCanvasWidget::kIn_ZoomCommand);
107 fMapper.setMapping(&fActionZoomOut, SkCanvasWidget::kOut_ZoomCommand);
chudy@google.coma1226312012-07-26 20:26:44 +0000108
109 connect(&fActionZoomIn, SIGNAL(triggered()), &fMapper, SLOT(map()));
110 connect(&fActionZoomOut, SIGNAL(triggered()), &fMapper, SLOT(map()));
bungeman@google.come8cc6e82013-01-17 16:30:56 +0000111 connect(&fMapper, SIGNAL(mapped(int)), &fCanvasWidget, SLOT(zoom(int)));
chudy@google.coma1226312012-07-26 20:26:44 +0000112
kkinnunen41c79cc2014-12-30 22:49:58 -0800113 fViewStateFrame.setDisabled(true);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000114 fInspectorWidget.setDisabled(true);
chudy@google.comd3058f52012-07-19 13:41:27 +0000115 fMenuEdit.setDisabled(true);
116 fMenuNavigate.setDisabled(true);
117 fMenuView.setDisabled(true);
chudy@google.combbad34d2012-08-13 14:26:36 +0000118}
chudy@google.com902ebe52012-06-29 14:21:22 +0000119
120void SkDebuggerGUI::actionBreakpoints() {
kkinnunenf3a9e992015-01-05 01:14:11 -0800121 bool breakpointsActivated = fActionBreakpoint.isChecked();
chudy@google.comc432f002012-07-10 13:19:25 +0000122 for (int row = 0; row < fListWidget.count(); row++) {
123 QListWidgetItem *item = fListWidget.item(row);
kkinnunenf3a9e992015-01-05 01:14:11 -0800124 item->setHidden(item->checkState() == Qt::Unchecked && breakpointsActivated);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000125 }
126}
chudy@google.com902ebe52012-06-29 14:21:22 +0000127
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000128void SkDebuggerGUI::actionToggleIndexStyle() {
kkinnunenf3a9e992015-01-05 01:14:11 -0800129 bool indexStyleToggle = fActionToggleIndexStyle.isChecked();
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000130 SkListWidget* list = (SkListWidget*) fListWidget.itemDelegate();
kkinnunenf3a9e992015-01-05 01:14:11 -0800131 list->setIndexStyle(indexStyleToggle ? SkListWidget::kOffset_IndexStyle
132 : SkListWidget::kIndex_IndexStyle);
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000133 fListWidget.update();
134}
135
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000136void SkDebuggerGUI::showDeletes() {
kkinnunenf3a9e992015-01-05 01:14:11 -0800137 bool deletesActivated = fActionShowDeletes.isChecked();
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000138 for (int row = 0; row < fListWidget.count(); row++) {
139 QListWidgetItem *item = fListWidget.item(row);
kkinnunenf3a9e992015-01-05 01:14:11 -0800140 item->setHidden(fDebugger.isCommandVisible(row) && deletesActivated);
chudy@google.com902ebe52012-06-29 14:21:22 +0000141 }
142}
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000143// This is a simplification of PictureBenchmark's run with the addition of
144// clearing of the times after the first pass (in resetTimes)
robertphillipsce4dd3d2014-07-07 13:46:35 -0700145void SkDebuggerGUI::run(const SkPicture* pict,
skia.committer@gmail.com34587162012-11-20 02:01:23 +0000146 sk_tools::PictureRenderer* renderer,
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000147 int repeats) {
148 SkASSERT(pict);
149 if (NULL == pict) {
150 return;
151 }
152
153 SkASSERT(renderer != NULL);
154 if (NULL == renderer) {
155 return;
156 }
157
robertphillips78c71272014-10-09 04:59:19 -0700158 renderer->init(pict, NULL, NULL, NULL, false, false);
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000159
160 renderer->setup();
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000161 renderer->render();
commit-bot@chromium.org51c040e2014-03-11 22:58:00 +0000162 renderer->resetState(true); // flush, swapBuffers and Finish
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000163
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000164 for (int i = 0; i < repeats; ++i) {
165 renderer->setup();
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000166 renderer->render();
commit-bot@chromium.org51c040e2014-03-11 22:58:00 +0000167 renderer->resetState(false); // flush & swapBuffers, but don't Finish
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000168 }
commit-bot@chromium.org51c040e2014-03-11 22:58:00 +0000169 renderer->resetState(true); // flush, swapBuffers and Finish
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000170
171 renderer->end();
172}
173
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000174void SkDebuggerGUI::actionProfile() {
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000175 // In order to profile we pass the command offsets (that were read-in
176 // in loadPicture by the SkOffsetPicture) to an SkTimedPlaybackPicture.
skia.committer@gmail.com884e60b2012-11-16 02:01:17 +0000177 // The SkTimedPlaybackPicture in turn passes the offsets to an
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000178 // SkTimedPicturePlayback object which uses them to track the performance
179 // of individual commands.
180 if (fFileName.isEmpty()) {
181 return;
182 }
183
184 SkFILEStream inputStream;
185
186 inputStream.setPath(fFileName.c_str());
187 if (!inputStream.isValid()) {
188 return;
189 }
190
robertphillipsce4dd3d2014-07-07 13:46:35 -0700191 SkAutoTUnref<SkPicture> picture(SkPicture::CreateFromStream(&inputStream,
192 &SkImageDecoder::DecodeMemory)); // , fSkipCommands));
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000193 if (NULL == picture.get()) {
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000194 return;
195 }
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000196}
197
chudy@google.com902ebe52012-06-29 14:21:22 +0000198void SkDebuggerGUI::actionCancel() {
chudy@google.comc432f002012-07-10 13:19:25 +0000199 for (int row = 0; row < fListWidget.count(); row++) {
200 fListWidget.item(row)->setHidden(false);
chudy@google.com902ebe52012-06-29 14:21:22 +0000201 }
202}
203
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000204void SkDebuggerGUI::actionClearBreakpoints() {
205 for (int row = 0; row < fListWidget.count(); row++) {
206 QListWidgetItem* item = fListWidget.item(row);
207 item->setCheckState(Qt::Unchecked);
208 item->setData(Qt::DecorationRole,
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000209 QPixmap(":/blank.png"));
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000210 }
211}
212
213void SkDebuggerGUI::actionClearDeletes() {
214 for (int row = 0; row < fListWidget.count(); row++) {
215 QListWidgetItem* item = fListWidget.item(row);
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000216 item->setData(Qt::UserRole + 2, QPixmap(":/blank.png"));
chudy@google.com607357f2012-08-07 16:12:23 +0000217 fDebugger.setCommandVisible(row, true);
robertphillips@google.com5f971142012-12-07 20:48:56 +0000218 fSkipCommands[row] = false;
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000219 }
kkinnunencfdc0e32015-01-13 22:49:02 -0800220 this->updateImage();
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000221}
222
chudy@google.com902ebe52012-06-29 14:21:22 +0000223void SkDebuggerGUI::actionClose() {
224 this->close();
225}
226
227void SkDebuggerGUI::actionDelete() {
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000228
robertphillips@google.comdd4b7452013-01-22 19:38:46 +0000229 for (int row = 0; row < fListWidget.count(); ++row) {
230 QListWidgetItem* item = fListWidget.item(row);
231
232 if (!item->isSelected()) {
233 continue;
234 }
235
236 if (fDebugger.isCommandVisible(row)) {
237 item->setData(Qt::UserRole + 2, QPixmap(":/delete.png"));
238 fDebugger.setCommandVisible(row, false);
239 fSkipCommands[row] = true;
240 } else {
241 item->setData(Qt::UserRole + 2, QPixmap(":/blank.png"));
242 fDebugger.setCommandVisible(row, true);
243 fSkipCommands[row] = false;
244 }
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000245 }
246
kkinnunencfdc0e32015-01-13 22:49:02 -0800247 this->updateImage();
chudy@google.com902ebe52012-06-29 14:21:22 +0000248}
249
robertphillips@google.come8fe4bc2013-02-13 13:26:13 +0000250#if SK_SUPPORT_GPU
kkinnunen41c79cc2014-12-30 22:49:58 -0800251void SkDebuggerGUI::actionGLSettingsChanged() {
commit-bot@chromium.orgfde1e7c2013-08-02 13:59:50 +0000252 bool isToggled = fSettingsWidget.isGLActive();
253 if (isToggled) {
254 fCanvasWidget.setGLSampleCount(fSettingsWidget.getGLSampleCount());
255 }
chudy@google.comea5488b2012-07-26 19:38:22 +0000256 fCanvasWidget.setWidgetVisibility(SkCanvasWidget::kGPU_WidgetType, !isToggled);
257}
robertphillips@google.come8fe4bc2013-02-13 13:26:13 +0000258#endif
chudy@google.comea5488b2012-07-26 19:38:22 +0000259
chudy@google.com902ebe52012-06-29 14:21:22 +0000260void SkDebuggerGUI::actionInspector() {
kkinnunen41c79cc2014-12-30 22:49:58 -0800261 bool newState = !fInspectorWidget.isHidden();
262
263 fInspectorWidget.setHidden(newState);
264 fViewStateFrame.setHidden(newState);
kkinnunen63a47022014-12-30 23:03:56 -0800265 fDrawCommandGeometryWidget.setHidden(newState);
chudy@google.com902ebe52012-06-29 14:21:22 +0000266}
267
268void SkDebuggerGUI::actionPlay() {
chudy@google.comc432f002012-07-10 13:19:25 +0000269 for (int row = fListWidget.currentRow() + 1; row < fListWidget.count();
chudy@google.com7dcae672012-07-09 20:26:53 +0000270 row++) {
chudy@google.comc432f002012-07-10 13:19:25 +0000271 QListWidgetItem *item = fListWidget.item(row);
chudy@google.com902ebe52012-06-29 14:21:22 +0000272 if (item->checkState() == Qt::Checked) {
chudy@google.comc432f002012-07-10 13:19:25 +0000273 fListWidget.setCurrentItem(item);
chudy@google.com902ebe52012-06-29 14:21:22 +0000274 return;
275 }
276 }
chudy@google.comc432f002012-07-10 13:19:25 +0000277 fListWidget.setCurrentRow(fListWidget.count() - 1);
chudy@google.com902ebe52012-06-29 14:21:22 +0000278}
279
kkinnunen41c79cc2014-12-30 22:49:58 -0800280void SkDebuggerGUI::actionRasterSettingsChanged() {
281 fCanvasWidget.setWidgetVisibility(SkCanvasWidget::kRaster_8888_WidgetType,
282 !fSettingsWidget.isRasterEnabled());
283 fDebugger.setOverdrawViz(fSettingsWidget.isOverdrawVizEnabled());
kkinnunencfdc0e32015-01-13 22:49:02 -0800284 this->updateImage();
robertphillips@google.comf4741c12013-02-06 20:13:54 +0000285}
286
kkinnunen41c79cc2014-12-30 22:49:58 -0800287void SkDebuggerGUI::actionVisualizationsChanged() {
288 fDebugger.setMegaViz(fSettingsWidget.isMegaVizEnabled());
289 fDebugger.setPathOps(fSettingsWidget.isPathOpsEnabled());
290 fDebugger.highlightCurrentCommand(fSettingsWidget.isVisibilityFilterEnabled());
kkinnunencfdc0e32015-01-13 22:49:02 -0800291 this->updateImage();
commit-bot@chromium.org2a67e122014-05-19 13:53:10 +0000292}
293
robertphillips@google.com32bbcf82013-10-17 17:56:10 +0000294void SkDebuggerGUI::actionTextureFilter() {
295 SkPaint::FilterLevel level;
296 bool enabled = fSettingsWidget.getFilterOverride(&level);
297 fDebugger.setTexFilterOverride(enabled, level);
298 fCanvasWidget.update();
299}
300
chudy@google.com902ebe52012-06-29 14:21:22 +0000301void SkDebuggerGUI::actionRewind() {
chudy@google.come504de02012-07-16 18:35:23 +0000302 fListWidget.setCurrentRow(0);
chudy@google.com902ebe52012-06-29 14:21:22 +0000303}
304
chudy@google.com0ab03392012-07-28 20:16:11 +0000305void SkDebuggerGUI::actionSave() {
robertphillips@google.come219baf2013-01-28 19:25:43 +0000306 fFileName = fPath.toAscii().data();
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000307 fFileName.append("/");
robertphillips@google.come219baf2013-01-28 19:25:43 +0000308 fFileName.append(fDirectoryWidget.currentItem()->text().toAscii().data());
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000309 saveToFile(fFileName);
chudy@google.com0ab03392012-07-28 20:16:11 +0000310}
311
312void SkDebuggerGUI::actionSaveAs() {
313 QString filename = QFileDialog::getSaveFileName(this, "Save File", "",
314 "Skia Picture (*skp)");
chudy@google.com38b08ce2012-07-28 23:26:10 +0000315 if (!filename.endsWith(".skp", Qt::CaseInsensitive)) {
chudy@google.com0ab03392012-07-28 20:16:11 +0000316 filename.append(".skp");
317 }
djsollen@google.comc3c82162012-11-13 18:35:10 +0000318 saveToFile(SkString(filename.toAscii().data()));
chudy@google.com0ab03392012-07-28 20:16:11 +0000319}
320
chudy@google.com7dcae672012-07-09 20:26:53 +0000321void SkDebuggerGUI::actionScale(float scaleFactor) {
kkinnunen41c79cc2014-12-30 22:49:58 -0800322 fZoomBox.setText(QString::number(scaleFactor * 100, 'f', 0).append("%"));
chudy@google.com7dcae672012-07-09 20:26:53 +0000323}
324
chudy@google.com902ebe52012-06-29 14:21:22 +0000325void SkDebuggerGUI::actionSettings() {
chudy@google.comc432f002012-07-10 13:19:25 +0000326 if (fSettingsWidget.isHidden()) {
327 fSettingsWidget.setHidden(false);
chudy@google.com902ebe52012-06-29 14:21:22 +0000328 } else {
chudy@google.comc432f002012-07-10 13:19:25 +0000329 fSettingsWidget.setHidden(true);
chudy@google.com902ebe52012-06-29 14:21:22 +0000330 }
331}
332
333void SkDebuggerGUI::actionStepBack() {
chudy@google.comc432f002012-07-10 13:19:25 +0000334 int currentRow = fListWidget.currentRow();
chudy@google.com902ebe52012-06-29 14:21:22 +0000335 if (currentRow != 0) {
chudy@google.comc432f002012-07-10 13:19:25 +0000336 fListWidget.setCurrentRow(currentRow - 1);
chudy@google.com902ebe52012-06-29 14:21:22 +0000337 }
338}
339
340void SkDebuggerGUI::actionStepForward() {
chudy@google.comc432f002012-07-10 13:19:25 +0000341 int currentRow = fListWidget.currentRow();
chudy@google.com902ebe52012-06-29 14:21:22 +0000342 QString curRow = QString::number(currentRow);
chudy@google.comc432f002012-07-10 13:19:25 +0000343 QString curCount = QString::number(fListWidget.count());
344 if (currentRow < fListWidget.count() - 1) {
345 fListWidget.setCurrentRow(currentRow + 1);
chudy@google.com902ebe52012-06-29 14:21:22 +0000346 }
347}
348
chudy@google.coma9e937c2012-08-03 17:32:05 +0000349void SkDebuggerGUI::drawComplete() {
kkinnunencfdc0e32015-01-13 22:49:02 -0800350 SkString clipStack;
351 fDebugger.getClipStackText(&clipStack);
352 fInspectorWidget.setText(clipStack.c_str(), SkInspectorWidget::kClipStack_TabType);
353
chudy@google.com607357f2012-08-07 16:12:23 +0000354 fInspectorWidget.setMatrix(fDebugger.getCurrentMatrix());
355 fInspectorWidget.setClip(fDebugger.getCurrentClip());
chudy@google.coma9e937c2012-08-03 17:32:05 +0000356}
357
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000358void SkDebuggerGUI::saveToFile(const SkString& filename) {
359 SkFILEWStream file(filename.c_str());
robertphillips@google.com25bc2f82013-01-22 18:03:56 +0000360 SkAutoTUnref<SkPicture> copy(fDebugger.copyPicture());
361
362 copy->serialize(&file);
chudy@google.com0ab03392012-07-28 20:16:11 +0000363}
364
chudy@google.com902ebe52012-06-29 14:21:22 +0000365void SkDebuggerGUI::loadFile(QListWidgetItem *item) {
366 if (fDirectoryWidgetActive) {
robertphillips@google.come219baf2013-01-28 19:25:43 +0000367 fFileName = fPath.toAscii().data();
jvanverth@google.com0ac6f162013-02-05 19:44:07 +0000368 // don't add a '/' to files in the local directory
369 if (fFileName.size() > 0) {
370 fFileName.append("/");
371 }
robertphillips@google.come219baf2013-01-28 19:25:43 +0000372 fFileName.append(item->text().toAscii().data());
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000373 loadPicture(fFileName);
chudy@google.com902ebe52012-06-29 14:21:22 +0000374 }
375}
376
377void SkDebuggerGUI::openFile() {
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000378 QString temp = QFileDialog::getOpenFileName(this, tr("Open File"), "",
chudy@google.com7dcae672012-07-09 20:26:53 +0000379 tr("Files (*.*)"));
robertphillips@google.comff6e6ba2013-01-28 17:43:26 +0000380 openFile(temp);
381}
382
383void SkDebuggerGUI::openFile(const QString &filename) {
chudy@google.com902ebe52012-06-29 14:21:22 +0000384 fDirectoryWidgetActive = false;
robertphillips@google.comff6e6ba2013-01-28 17:43:26 +0000385 if (!filename.isEmpty()) {
386 QFileInfo pathInfo(filename);
387 loadPicture(SkString(filename.toAscii().data()));
388 setupDirectoryWidget(pathInfo.path());
chudy@google.com902ebe52012-06-29 14:21:22 +0000389 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000390 fDirectoryWidgetActive = true;
391}
392
chudy@google.comc432f002012-07-10 13:19:25 +0000393void SkDebuggerGUI::pauseDrawing(bool isPaused) {
chudy@google.com607357f2012-08-07 16:12:23 +0000394 fPausedRow = fListWidget.currentRow();
kkinnunencfdc0e32015-01-13 22:49:02 -0800395 this->updateDrawCommandInfo();
chudy@google.com7dcae672012-07-09 20:26:53 +0000396}
397
kkinnunen0cfeaf32015-01-07 07:33:46 -0800398void SkDebuggerGUI::updateDrawCommandInfo() {
399 int currentRow = -1;
400 if (!fLoading) {
401 currentRow = fListWidget.currentRow();
402 }
403 if (currentRow == -1) {
404 fInspectorWidget.setText("", SkInspectorWidget::kDetail_TabType);
405 fInspectorWidget.setText("", SkInspectorWidget::kClipStack_TabType);
406 fCurrentCommandBox.setText("");
407 fDrawCommandGeometryWidget.setDrawCommandIndex(-1);
408 } else {
kkinnunencfdc0e32015-01-13 22:49:02 -0800409 this->updateImage();
410
kkinnunen0cfeaf32015-01-07 07:33:46 -0800411 const SkTDArray<SkString*> *currInfo = fDebugger.getCommandInfo(currentRow);
chudy@google.comd3058f52012-07-19 13:41:27 +0000412
kkinnunen0cfeaf32015-01-07 07:33:46 -0800413 /* TODO(chudy): Add command type before parameters. Rename v
414 * to something more informative. */
415 if (currInfo) {
416 QString info;
417 info.append("<b>Parameters: </b><br/>");
418 for (int i = 0; i < currInfo->count(); i++) {
419 info.append(QString((*currInfo)[i]->c_str()));
420 info.append("<br/>");
chudy@google.comd3058f52012-07-19 13:41:27 +0000421 }
kkinnunen0cfeaf32015-01-07 07:33:46 -0800422 fInspectorWidget.setText(info, SkInspectorWidget::kDetail_TabType);
chudy@google.comd3058f52012-07-19 13:41:27 +0000423 }
chudy@google.comea5488b2012-07-26 19:38:22 +0000424
kkinnunen0cfeaf32015-01-07 07:33:46 -0800425 fCurrentCommandBox.setText(QString::number(currentRow));
426
427 fDrawCommandGeometryWidget.setDrawCommandIndex(currentRow);
428
429 fInspectorWidget.setDisabled(false);
430 fViewStateFrame.setDisabled(false);
chudy@google.com902ebe52012-06-29 14:21:22 +0000431 }
432}
433
chudy@google.com9ca9bfe2012-07-12 21:58:14 +0000434void SkDebuggerGUI::selectCommand(int command) {
kkinnunenf3a9e992015-01-05 01:14:11 -0800435 if (this->isPaused()) {
chudy@google.com9ca9bfe2012-07-12 21:58:14 +0000436 fListWidget.setCurrentRow(command);
437 }
438}
439
chudy@google.com902ebe52012-06-29 14:21:22 +0000440void SkDebuggerGUI::toggleBreakpoint() {
chudy@google.comc432f002012-07-10 13:19:25 +0000441 QListWidgetItem* item = fListWidget.currentItem();
chudy@google.com902ebe52012-06-29 14:21:22 +0000442 if (item->checkState() == Qt::Unchecked) {
443 item->setCheckState(Qt::Checked);
chudy@google.come565de42012-07-12 14:15:54 +0000444 item->setData(Qt::DecorationRole,
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000445 QPixmap(":/breakpoint_16x16.png"));
chudy@google.com902ebe52012-06-29 14:21:22 +0000446 } else {
chudy@google.com902ebe52012-06-29 14:21:22 +0000447 item->setCheckState(Qt::Unchecked);
chudy@google.come565de42012-07-12 14:15:54 +0000448 item->setData(Qt::DecorationRole,
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000449 QPixmap(":/blank.png"));
chudy@google.com902ebe52012-06-29 14:21:22 +0000450 }
451}
452
453void SkDebuggerGUI::toggleDirectory() {
chudy@google.com607357f2012-08-07 16:12:23 +0000454 fDirectoryWidget.setHidden(!fDirectoryWidget.isHidden());
chudy@google.com902ebe52012-06-29 14:21:22 +0000455}
456
457void SkDebuggerGUI::toggleFilter(QString string) {
chudy@google.comc432f002012-07-10 13:19:25 +0000458 for (int row = 0; row < fListWidget.count(); row++) {
459 QListWidgetItem *item = fListWidget.item(row);
chudy@google.com607357f2012-08-07 16:12:23 +0000460 item->setHidden(item->text() != string);
chudy@google.com902ebe52012-06-29 14:21:22 +0000461 }
462}
463
464void SkDebuggerGUI::setupUi(QMainWindow *SkDebuggerGUI) {
465 QIcon windowIcon;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000466 windowIcon.addFile(QString::fromUtf8(":/skia.png"), QSize(),
chudy@google.com7dcae672012-07-09 20:26:53 +0000467 QIcon::Normal, QIcon::Off);
chudy@google.com902ebe52012-06-29 14:21:22 +0000468 SkDebuggerGUI->setObjectName(QString::fromUtf8("SkDebuggerGUI"));
469 SkDebuggerGUI->resize(1200, 1000);
470 SkDebuggerGUI->setWindowIcon(windowIcon);
chudy@google.comc432f002012-07-10 13:19:25 +0000471 SkDebuggerGUI->setWindowTitle("Skia Debugger");
chudy@google.com902ebe52012-06-29 14:21:22 +0000472
chudy@google.come504de02012-07-16 18:35:23 +0000473 fActionOpen.setShortcuts(QKeySequence::Open);
chudy@google.comc432f002012-07-10 13:19:25 +0000474 fActionOpen.setText("Open");
chudy@google.com902ebe52012-06-29 14:21:22 +0000475
476 QIcon breakpoint;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000477 breakpoint.addFile(QString::fromUtf8(":/breakpoint.png"),
chudy@google.com7dcae672012-07-09 20:26:53 +0000478 QSize(), QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000479 fActionBreakpoint.setShortcut(QKeySequence(tr("Ctrl+B")));
chudy@google.comc432f002012-07-10 13:19:25 +0000480 fActionBreakpoint.setIcon(breakpoint);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000481 fActionBreakpoint.setText("Breakpoints");
kkinnunenf3a9e992015-01-05 01:14:11 -0800482 fActionBreakpoint.setCheckable(true);
chudy@google.com902ebe52012-06-29 14:21:22 +0000483
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000484 fActionToggleIndexStyle.setShortcut(QKeySequence(tr("Ctrl+T")));
485 fActionToggleIndexStyle.setText("Toggle Index Style");
kkinnunenf3a9e992015-01-05 01:14:11 -0800486 fActionToggleIndexStyle.setCheckable(true);
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000487
chudy@google.com902ebe52012-06-29 14:21:22 +0000488 QIcon cancel;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000489 cancel.addFile(QString::fromUtf8(":/reload.png"), QSize(),
chudy@google.com7dcae672012-07-09 20:26:53 +0000490 QIcon::Normal, QIcon::Off);
chudy@google.comc432f002012-07-10 13:19:25 +0000491 fActionCancel.setIcon(cancel);
492 fActionCancel.setText("Clear Filter");
chudy@google.com902ebe52012-06-29 14:21:22 +0000493
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000494 fActionClearBreakpoints.setShortcut(QKeySequence(tr("Alt+B")));
495 fActionClearBreakpoints.setText("Clear Breakpoints");
496
497 fActionClearDeletes.setShortcut(QKeySequence(tr("Alt+X")));
498 fActionClearDeletes.setText("Clear Deletes");
499
chudy@google.come504de02012-07-16 18:35:23 +0000500 fActionClose.setShortcuts(QKeySequence::Quit);
chudy@google.comc432f002012-07-10 13:19:25 +0000501 fActionClose.setText("Exit");
chudy@google.com902ebe52012-06-29 14:21:22 +0000502
chudy@google.come504de02012-07-16 18:35:23 +0000503 fActionCreateBreakpoint.setShortcut(QKeySequence(tr("B")));
504 fActionCreateBreakpoint.setText("Set Breakpoint");
505
506 fActionDelete.setShortcut(QKeySequence(tr("X")));
chudy@google.comc432f002012-07-10 13:19:25 +0000507 fActionDelete.setText("Delete Command");
chudy@google.com902ebe52012-06-29 14:21:22 +0000508
chudy@google.come504de02012-07-16 18:35:23 +0000509 fActionDirectory.setShortcut(QKeySequence(tr("Ctrl+D")));
510 fActionDirectory.setText("Directory");
chudy@google.com902ebe52012-06-29 14:21:22 +0000511
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000512 QIcon profile;
robertphillips@google.comd1636362012-11-19 18:25:09 +0000513 profile.addFile(QString::fromUtf8(":/profile.png"), QSize(),
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000514 QIcon::Normal, QIcon::Off);
515 fActionProfile.setIcon(profile);
516 fActionProfile.setText("Profile");
robertphillips@google.come099bc42012-11-19 16:26:40 +0000517 fActionProfile.setDisabled(true);
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000518
chudy@google.comc432f002012-07-10 13:19:25 +0000519 QIcon inspector;
robertphillips@google.comd1636362012-11-19 18:25:09 +0000520 inspector.addFile(QString::fromUtf8(":/inspector.png"),
chudy@google.comc432f002012-07-10 13:19:25 +0000521 QSize(), QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000522 fActionInspector.setShortcut(QKeySequence(tr("Ctrl+I")));
chudy@google.comc432f002012-07-10 13:19:25 +0000523 fActionInspector.setIcon(inspector);
chudy@google.come504de02012-07-16 18:35:23 +0000524 fActionInspector.setText("Inspector");
chudy@google.com902ebe52012-06-29 14:21:22 +0000525
bungeman@google.com2ff6d1d2013-07-01 14:24:12 +0000526 QIcon settings;
527 settings.addFile(QString::fromUtf8(":/inspector.png"),
528 QSize(), QIcon::Normal, QIcon::Off);
529 fActionSettings.setShortcut(QKeySequence(tr("Ctrl+G")));
530 fActionSettings.setIcon(settings);
531 fActionSettings.setText("Settings");
skia.committer@gmail.com0d55dd72013-07-02 07:00:59 +0000532
chudy@google.comc432f002012-07-10 13:19:25 +0000533 QIcon play;
robertphillips@google.comd1636362012-11-19 18:25:09 +0000534 play.addFile(QString::fromUtf8(":/play.png"), QSize(),
chudy@google.comc432f002012-07-10 13:19:25 +0000535 QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000536 fActionPlay.setShortcut(QKeySequence(tr("Ctrl+P")));
chudy@google.comc432f002012-07-10 13:19:25 +0000537 fActionPlay.setIcon(play);
538 fActionPlay.setText("Play");
chudy@google.com902ebe52012-06-29 14:21:22 +0000539
chudy@google.come504de02012-07-16 18:35:23 +0000540 QIcon pause;
robertphillips@google.comd1636362012-11-19 18:25:09 +0000541 pause.addFile(QString::fromUtf8(":/pause.png"), QSize(),
chudy@google.comc432f002012-07-10 13:19:25 +0000542 QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000543 fActionPause.setShortcut(QKeySequence(tr("Space")));
544 fActionPause.setCheckable(true);
545 fActionPause.setIcon(pause);
546 fActionPause.setText("Pause");
547
chudy@google.comc432f002012-07-10 13:19:25 +0000548 QIcon rewind;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000549 rewind.addFile(QString::fromUtf8(":/rewind.png"), QSize(),
chudy@google.comc432f002012-07-10 13:19:25 +0000550 QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000551 fActionRewind.setShortcut(QKeySequence(tr("Ctrl+R")));
chudy@google.comc432f002012-07-10 13:19:25 +0000552 fActionRewind.setIcon(rewind);
553 fActionRewind.setText("Rewind");
chudy@google.com902ebe52012-06-29 14:21:22 +0000554
chudy@google.com0ab03392012-07-28 20:16:11 +0000555 fActionSave.setShortcut(QKeySequence::Save);
556 fActionSave.setText("Save");
557 fActionSave.setDisabled(true);
558 fActionSaveAs.setShortcut(QKeySequence::SaveAs);
559 fActionSaveAs.setText("Save As");
560 fActionSaveAs.setDisabled(true);
561
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000562 fActionShowDeletes.setShortcut(QKeySequence(tr("Ctrl+X")));
563 fActionShowDeletes.setText("Deleted Commands");
kkinnunenf3a9e992015-01-05 01:14:11 -0800564 fActionShowDeletes.setCheckable(true);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000565
chudy@google.comc432f002012-07-10 13:19:25 +0000566 QIcon stepBack;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000567 stepBack.addFile(QString::fromUtf8(":/previous.png"), QSize(),
chudy@google.comc432f002012-07-10 13:19:25 +0000568 QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000569 fActionStepBack.setShortcut(QKeySequence(tr("[")));
chudy@google.comc432f002012-07-10 13:19:25 +0000570 fActionStepBack.setIcon(stepBack);
571 fActionStepBack.setText("Step Back");
chudy@google.com902ebe52012-06-29 14:21:22 +0000572
chudy@google.comc432f002012-07-10 13:19:25 +0000573 QIcon stepForward;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000574 stepForward.addFile(QString::fromUtf8(":/next.png"),
chudy@google.comc432f002012-07-10 13:19:25 +0000575 QSize(), QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000576 fActionStepForward.setShortcut(QKeySequence(tr("]")));
chudy@google.comc432f002012-07-10 13:19:25 +0000577 fActionStepForward.setIcon(stepForward);
578 fActionStepForward.setText("Step Forward");
579
chudy@google.coma1226312012-07-26 20:26:44 +0000580 fActionZoomIn.setShortcut(QKeySequence(tr("Ctrl+=")));
581 fActionZoomIn.setText("Zoom In");
582 fActionZoomOut.setShortcut(QKeySequence(tr("Ctrl+-")));
583 fActionZoomOut.setText("Zoom Out");
584
chudy@google.comc432f002012-07-10 13:19:25 +0000585 fListWidget.setItemDelegate(new SkListWidget(&fListWidget));
586 fListWidget.setObjectName(QString::fromUtf8("listWidget"));
commit-bot@chromium.orgbcd431e2013-11-21 13:41:37 +0000587 fListWidget.setMinimumWidth(250);
chudy@google.comc432f002012-07-10 13:19:25 +0000588
589 fFilter.addItem("--Filter By Available Commands--");
590
commit-bot@chromium.orgbcd431e2013-11-21 13:41:37 +0000591 fDirectoryWidget.setMinimumWidth(250);
chudy@google.comc432f002012-07-10 13:19:25 +0000592 fDirectoryWidget.setStyleSheet("QListWidget::Item {padding: 5px;}");
593
594 fCanvasWidget.setSizePolicy(QSizePolicy::Expanding,
chudy@google.com7dcae672012-07-09 20:26:53 +0000595 QSizePolicy::Expanding);
chudy@google.com902ebe52012-06-29 14:21:22 +0000596
kkinnunen63a47022014-12-30 23:03:56 -0800597 fDrawCommandGeometryWidget.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000598
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000599 fSettingsAndImageLayout.addWidget(&fSettingsWidget);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000600
kkinnunen41c79cc2014-12-30 22:49:58 -0800601 // View state group, part of inspector.
602 fViewStateFrame.setFrameStyle(QFrame::Panel);
603 fViewStateFrame.setLayout(&fViewStateFrameLayout);
604 fViewStateFrameLayout.addWidget(&fViewStateGroup);
kkinnunen63a47022014-12-30 23:03:56 -0800605 fViewStateGroup.setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
kkinnunen41c79cc2014-12-30 22:49:58 -0800606 fViewStateGroup.setTitle("View");
607 fViewStateLayout.addRow("Zoom Level", &fZoomBox);
608 fZoomBox.setText("100%");
609 fZoomBox.setMinimumSize(QSize(50,25));
610 fZoomBox.setMaximumSize(QSize(50,25));
611 fZoomBox.setAlignment(Qt::AlignRight);
612 fZoomBox.setReadOnly(true);
613 fViewStateLayout.addRow("Command HitBox", &fCommandHitBox);
614 fCommandHitBox.setText("0");
615 fCommandHitBox.setMinimumSize(QSize(50,25));
616 fCommandHitBox.setMaximumSize(QSize(50,25));
617 fCommandHitBox.setAlignment(Qt::AlignRight);
618 fCommandHitBox.setReadOnly(true);
619 fViewStateLayout.addRow("Current Command", &fCurrentCommandBox);
620 fCurrentCommandBox.setText("0");
621 fCurrentCommandBox.setMinimumSize(QSize(50,25));
622 fCurrentCommandBox.setMaximumSize(QSize(50,25));
623 fCurrentCommandBox.setAlignment(Qt::AlignRight);
624 fCurrentCommandBox.setReadOnly(true);
625 fViewStateGroup.setLayout(&fViewStateLayout);
626 fSettingsAndImageLayout.addWidget(&fViewStateFrame);
627
kkinnunen63a47022014-12-30 23:03:56 -0800628 fDrawCommandGeometryWidget.setToolTip("Current Command Geometry");
629 fSettingsAndImageLayout.addWidget(&fDrawCommandGeometryWidget);
chudy@google.com902ebe52012-06-29 14:21:22 +0000630
commit-bot@chromium.orgbcd431e2013-11-21 13:41:37 +0000631 fLeftColumnSplitter.addWidget(&fListWidget);
632 fLeftColumnSplitter.addWidget(&fDirectoryWidget);
633 fLeftColumnSplitter.setOrientation(Qt::Vertical);
chudy@google.com902ebe52012-06-29 14:21:22 +0000634
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000635 fCanvasSettingsAndImageLayout.setSpacing(6);
kkinnunen41c79cc2014-12-30 22:49:58 -0800636 fCanvasSettingsAndImageLayout.addWidget(&fCanvasWidget, 1);
637 fCanvasSettingsAndImageLayout.addLayout(&fSettingsAndImageLayout, 0);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000638
chudy@google.comc432f002012-07-10 13:19:25 +0000639 fMainAndRightColumnLayout.setSpacing(6);
kkinnunen7c339ae2015-01-02 06:35:43 -0800640 fMainAndRightColumnLayout.addLayout(&fCanvasSettingsAndImageLayout, 1);
641 fMainAndRightColumnLayout.addWidget(&fInspectorWidget, 0);
commit-bot@chromium.orgbcd431e2013-11-21 13:41:37 +0000642 fMainAndRightColumnWidget.setLayout(&fMainAndRightColumnLayout);
chudy@google.com902ebe52012-06-29 14:21:22 +0000643
commit-bot@chromium.orgbcd431e2013-11-21 13:41:37 +0000644 fCentralSplitter.addWidget(&fLeftColumnSplitter);
645 fCentralSplitter.addWidget(&fMainAndRightColumnWidget);
646 fCentralSplitter.setStretchFactor(0, 0);
647 fCentralSplitter.setStretchFactor(1, 1);
chudy@google.comc432f002012-07-10 13:19:25 +0000648
commit-bot@chromium.orgbcd431e2013-11-21 13:41:37 +0000649 SkDebuggerGUI->setCentralWidget(&fCentralSplitter);
chudy@google.comc432f002012-07-10 13:19:25 +0000650 SkDebuggerGUI->setStatusBar(&fStatusBar);
651
chudy@google.come504de02012-07-16 18:35:23 +0000652 fToolBar.setIconSize(QSize(32, 32));
chudy@google.comc432f002012-07-10 13:19:25 +0000653 fToolBar.setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
654 SkDebuggerGUI->addToolBar(Qt::TopToolBarArea, &fToolBar);
chudy@google.com902ebe52012-06-29 14:21:22 +0000655
chudy@google.com0ab03392012-07-28 20:16:11 +0000656 fSpacer.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
chudy@google.com902ebe52012-06-29 14:21:22 +0000657
chudy@google.comc432f002012-07-10 13:19:25 +0000658 fToolBar.addAction(&fActionRewind);
659 fToolBar.addAction(&fActionStepBack);
chudy@google.come504de02012-07-16 18:35:23 +0000660 fToolBar.addAction(&fActionPause);
chudy@google.comc432f002012-07-10 13:19:25 +0000661 fToolBar.addAction(&fActionStepForward);
662 fToolBar.addAction(&fActionPlay);
663 fToolBar.addSeparator();
chudy@google.come504de02012-07-16 18:35:23 +0000664 fToolBar.addAction(&fActionInspector);
bungeman@google.com2ff6d1d2013-07-01 14:24:12 +0000665 fToolBar.addAction(&fActionSettings);
chudy@google.comc432f002012-07-10 13:19:25 +0000666 fToolBar.addSeparator();
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000667 fToolBar.addAction(&fActionProfile);
668
669 fToolBar.addSeparator();
chudy@google.com0ab03392012-07-28 20:16:11 +0000670 fToolBar.addWidget(&fSpacer);
chudy@google.comc432f002012-07-10 13:19:25 +0000671 fToolBar.addWidget(&fFilter);
672 fToolBar.addAction(&fActionCancel);
chudy@google.com902ebe52012-06-29 14:21:22 +0000673
674 // TODO(chudy): Remove static call.
675 fDirectoryWidgetActive = false;
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000676 fFileName = "";
robertphillips@google.comff6e6ba2013-01-28 17:43:26 +0000677 setupDirectoryWidget("");
chudy@google.com902ebe52012-06-29 14:21:22 +0000678 fDirectoryWidgetActive = true;
679
chudy@google.com902ebe52012-06-29 14:21:22 +0000680 // Menu Bar
chudy@google.comc432f002012-07-10 13:19:25 +0000681 fMenuFile.setTitle("File");
682 fMenuFile.addAction(&fActionOpen);
chudy@google.com0ab03392012-07-28 20:16:11 +0000683 fMenuFile.addAction(&fActionSave);
684 fMenuFile.addAction(&fActionSaveAs);
chudy@google.comc432f002012-07-10 13:19:25 +0000685 fMenuFile.addAction(&fActionClose);
chudy@google.come504de02012-07-16 18:35:23 +0000686
687 fMenuEdit.setTitle("Edit");
688 fMenuEdit.addAction(&fActionDelete);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000689 fMenuEdit.addAction(&fActionClearDeletes);
690 fMenuEdit.addSeparator();
chudy@google.come504de02012-07-16 18:35:23 +0000691 fMenuEdit.addAction(&fActionCreateBreakpoint);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000692 fMenuEdit.addAction(&fActionClearBreakpoints);
chudy@google.come504de02012-07-16 18:35:23 +0000693
chudy@google.comc432f002012-07-10 13:19:25 +0000694 fMenuNavigate.setTitle("Navigate");
chudy@google.come504de02012-07-16 18:35:23 +0000695 fMenuNavigate.addAction(&fActionRewind);
696 fMenuNavigate.addAction(&fActionStepBack);
697 fMenuNavigate.addAction(&fActionStepForward);
698 fMenuNavigate.addAction(&fActionPlay);
699 fMenuNavigate.addAction(&fActionPause);
chudy@google.comc432f002012-07-10 13:19:25 +0000700 fMenuNavigate.addAction(&fActionGoToLine);
chudy@google.come504de02012-07-16 18:35:23 +0000701
chudy@google.comc432f002012-07-10 13:19:25 +0000702 fMenuView.setTitle("View");
chudy@google.come504de02012-07-16 18:35:23 +0000703 fMenuView.addAction(&fActionBreakpoint);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000704 fMenuView.addAction(&fActionShowDeletes);
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000705 fMenuView.addAction(&fActionToggleIndexStyle);
chudy@google.coma1226312012-07-26 20:26:44 +0000706 fMenuView.addAction(&fActionZoomIn);
707 fMenuView.addAction(&fActionZoomOut);
chudy@google.come504de02012-07-16 18:35:23 +0000708
709 fMenuWindows.setTitle("Window");
710 fMenuWindows.addAction(&fActionInspector);
bungeman@google.com2ff6d1d2013-07-01 14:24:12 +0000711 fMenuWindows.addAction(&fActionSettings);
chudy@google.come504de02012-07-16 18:35:23 +0000712 fMenuWindows.addAction(&fActionDirectory);
chudy@google.comc432f002012-07-10 13:19:25 +0000713
714 fActionGoToLine.setText("Go to Line...");
715 fActionGoToLine.setDisabled(true);
716 fMenuBar.addAction(fMenuFile.menuAction());
chudy@google.come504de02012-07-16 18:35:23 +0000717 fMenuBar.addAction(fMenuEdit.menuAction());
chudy@google.comc432f002012-07-10 13:19:25 +0000718 fMenuBar.addAction(fMenuView.menuAction());
719 fMenuBar.addAction(fMenuNavigate.menuAction());
chudy@google.come504de02012-07-16 18:35:23 +0000720 fMenuBar.addAction(fMenuWindows.menuAction());
chudy@google.com902ebe52012-06-29 14:21:22 +0000721
chudy@google.comc432f002012-07-10 13:19:25 +0000722 SkDebuggerGUI->setMenuBar(&fMenuBar);
chudy@google.com902ebe52012-06-29 14:21:22 +0000723 QMetaObject::connectSlotsByName(SkDebuggerGUI);
724}
725
robertphillips@google.comff6e6ba2013-01-28 17:43:26 +0000726void SkDebuggerGUI::setupDirectoryWidget(const QString& path) {
727 fPath = path;
728 QDir dir(path);
chudy@google.com902ebe52012-06-29 14:21:22 +0000729 QRegExp r(".skp");
chudy@google.comc432f002012-07-10 13:19:25 +0000730 fDirectoryWidget.clear();
731 const QStringList files = dir.entryList();
chudy@google.com902ebe52012-06-29 14:21:22 +0000732 foreach (QString f, files) {
chudy@google.com7dcae672012-07-09 20:26:53 +0000733 if (f.contains(r))
chudy@google.comc432f002012-07-10 13:19:25 +0000734 fDirectoryWidget.addItem(f);
chudy@google.com902ebe52012-06-29 14:21:22 +0000735 }
736}
737
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000738void SkDebuggerGUI::loadPicture(const SkString& fileName) {
739 fFileName = fileName;
chudy@google.comd3058f52012-07-19 13:41:27 +0000740 fLoading = true;
scroggoa1193e42015-01-21 12:09:53 -0800741 SkAutoTDelete<SkStream> stream(SkNEW_ARGS(SkFILEStream, (fileName.c_str())));
robertphillips@google.com2d40ec42013-02-07 20:39:40 +0000742
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000743 SkPicture* picture = SkPicture::CreateFromStream(stream);
robertphillips@google.com2d40ec42013-02-07 20:39:40 +0000744
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000745 if (NULL == picture) {
robertphillips@google.com2d40ec42013-02-07 20:39:40 +0000746 QMessageBox::critical(this, "Error loading file", "Couldn't read file, sorry.");
robertphillips@google.com2d40ec42013-02-07 20:39:40 +0000747 return;
748 }
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000749
chudy@google.com686e6802012-08-14 16:00:32 +0000750 fCanvasWidget.resetWidgetTransform();
chudy@google.com607357f2012-08-07 16:12:23 +0000751 fDebugger.loadPicture(picture);
chudy@google.com4c7962e2012-08-14 19:38:31 +0000752
robertphillips@google.com6d9c92b2013-05-23 13:21:18 +0000753 fSkipCommands.setCount(fDebugger.getSize());
754 for (int i = 0; i < fSkipCommands.count(); ++i) {
robertphillips@google.com5f971142012-12-07 20:48:56 +0000755 fSkipCommands[i] = false;
756 }
757
chudy@google.com607357f2012-08-07 16:12:23 +0000758 SkSafeUnref(picture);
759
robertphillips@google.com6d9c92b2013-05-23 13:21:18 +0000760 fActionProfile.setDisabled(false);
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000761
chudy@google.com7dcae672012-07-09 20:26:53 +0000762 /* fDebugCanvas is reinitialized every load picture. Need it to retain value
chudy@google.com607357f2012-08-07 16:12:23 +0000763 * of the visibility filter.
764 * TODO(chudy): This should be deprecated since fDebugger is not
765 * recreated.
766 * */
kkinnunen41c79cc2014-12-30 22:49:58 -0800767 fDebugger.highlightCurrentCommand(fSettingsWidget.isVisibilityFilterEnabled());
chudy@google.com607357f2012-08-07 16:12:23 +0000768
kkinnunen5037e9d2014-12-30 07:22:58 -0800769 this->setupListWidget();
770 this->setupComboBox();
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000771 this->setupOverviewText(NULL, 0.0, 1);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000772 fInspectorWidget.setDisabled(false);
kkinnunen41c79cc2014-12-30 22:49:58 -0800773 fViewStateFrame.setDisabled(false);
chudy@google.come606d6e2012-07-12 14:31:25 +0000774 fSettingsWidget.setDisabled(false);
chudy@google.comd3058f52012-07-19 13:41:27 +0000775 fMenuEdit.setDisabled(false);
776 fMenuNavigate.setDisabled(false);
777 fMenuView.setDisabled(false);
chudy@google.com0ab03392012-07-28 20:16:11 +0000778 fActionSave.setDisabled(false);
779 fActionSaveAs.setDisabled(false);
kkinnunenf3a9e992015-01-05 01:14:11 -0800780 fActionPause.setChecked(false);
kkinnunen0cfeaf32015-01-07 07:33:46 -0800781 fDrawCommandGeometryWidget.setDrawCommandIndex(-1);
782
chudy@google.comd3058f52012-07-19 13:41:27 +0000783 fLoading = false;
784 actionPlay();
chudy@google.com902ebe52012-06-29 14:21:22 +0000785}
786
kkinnunen5037e9d2014-12-30 07:22:58 -0800787void SkDebuggerGUI::setupListWidget() {
chudy@google.comc432f002012-07-10 13:19:25 +0000788 fListWidget.clear();
chudy@google.com902ebe52012-06-29 14:21:22 +0000789 int counter = 0;
robertphillips@google.com30d35f22012-11-06 16:45:36 +0000790 int indent = 0;
kkinnunen5037e9d2014-12-30 07:22:58 -0800791 for (int i = 0; i < fDebugger.getSize(); i++) {
chudy@google.com902ebe52012-06-29 14:21:22 +0000792 QListWidgetItem *item = new QListWidgetItem();
kkinnunen5037e9d2014-12-30 07:22:58 -0800793 SkDrawCommand* command = fDebugger.getDrawCommandAt(i);
794 SkString commandString = command->toString();
795 item->setData(Qt::DisplayRole, commandString.c_str());
chudy@google.com902ebe52012-06-29 14:21:22 +0000796 item->setData(Qt::UserRole + 1, counter++);
robertphillips@google.com30d35f22012-11-06 16:45:36 +0000797
kkinnunen5037e9d2014-12-30 07:22:58 -0800798 if (0 == strcmp("Restore", commandString.c_str()) ||
799 0 == strcmp("EndCommentGroup", commandString.c_str())) {
robertphillips@google.com30d35f22012-11-06 16:45:36 +0000800 indent -= 10;
801 }
802
803 item->setData(Qt::UserRole + 3, indent);
804
kkinnunen5037e9d2014-12-30 07:22:58 -0800805 if (0 == strcmp("Save", commandString.c_str()) ||
806 0 == strcmp("Save Layer", commandString.c_str()) ||
807 0 == strcmp("BeginCommentGroup", commandString.c_str())) {
robertphillips@google.com30d35f22012-11-06 16:45:36 +0000808 indent += 10;
809 }
810
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000811 item->setData(Qt::UserRole + 4, -1);
kkinnunen5037e9d2014-12-30 07:22:58 -0800812 item->setData(Qt::UserRole + 5, (int) command->offset());
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000813
chudy@google.comc432f002012-07-10 13:19:25 +0000814 fListWidget.addItem(item);
chudy@google.com902ebe52012-06-29 14:21:22 +0000815 }
816}
817
skia.committer@gmail.com91274b92013-03-13 07:01:04 +0000818void SkDebuggerGUI::setupOverviewText(const SkTDArray<double>* typeTimes,
robertphillips@google.come428f9b2013-03-12 15:33:40 +0000819 double totTime,
820 int numRuns) {
borenet@google.com2d9dbd42013-03-12 13:07:40 +0000821 SkString overview;
robertphillips@google.come428f9b2013-03-12 15:33:40 +0000822 fDebugger.getOverviewText(typeTimes, totTime, &overview, numRuns);
borenet@google.com2d9dbd42013-03-12 13:07:40 +0000823 fInspectorWidget.setText(overview.c_str(), SkInspectorWidget::kOverview_TabType);
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000824}
825
commit-bot@chromium.org2a67e122014-05-19 13:53:10 +0000826
kkinnunen5037e9d2014-12-30 07:22:58 -0800827void SkDebuggerGUI::setupComboBox() {
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000828 fFilter.clear();
829 fFilter.addItem("--Filter By Available Commands--");
830
831 std::map<std::string, int> map;
kkinnunen5037e9d2014-12-30 07:22:58 -0800832 for (int i = 0; i < fDebugger.getSize(); i++) {
833 map[fDebugger.getDrawCommandAt(i)->toString().c_str()]++;
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000834 }
835
skia.committer@gmail.com34587162012-11-20 02:01:23 +0000836 for (std::map<std::string, int>::iterator it = map.begin(); it != map.end();
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000837 ++it) {
838 fFilter.addItem((it->first).c_str());
839 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000840
841 // NOTE(chudy): Makes first item unselectable.
chudy@google.com7dcae672012-07-09 20:26:53 +0000842 QStandardItemModel* model = qobject_cast<QStandardItemModel*>(
chudy@google.comc432f002012-07-10 13:19:25 +0000843 fFilter.model());
844 QModelIndex firstIndex = model->index(0, fFilter.modelColumn(),
845 fFilter.rootModelIndex());
chudy@google.com902ebe52012-06-29 14:21:22 +0000846 QStandardItem* firstItem = model->itemFromIndex(firstIndex);
847 firstItem->setSelectable(false);
848}
kkinnunen41c79cc2014-12-30 22:49:58 -0800849
kkinnunencfdc0e32015-01-13 22:49:02 -0800850void SkDebuggerGUI::updateImage() {
851 if (this->isPaused()) {
852 fCanvasWidget.drawTo(fPausedRow);
853 } else {
854 fCanvasWidget.drawTo(fListWidget.currentRow());
855 }
856}
857
kkinnunen41c79cc2014-12-30 22:49:58 -0800858void SkDebuggerGUI::updateHit(int newHit) {
859 fCommandHitBox.setText(QString::number(newHit));
860}
861