blob: ea3564ca0d60d143b7900496092f808b6d24df47 [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)
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +000035 , fActionToggleIndexStyle(this)
robertphillips@google.comd26c7062012-11-12 20:42:12 +000036 , fActionProfile(this)
chudy@google.comc432f002012-07-10 13:19:25 +000037 , fActionCancel(this)
chudy@google.com7e4cfbf2012-07-17 15:40:51 +000038 , fActionClearBreakpoints(this)
chudy@google.come504de02012-07-16 18:35:23 +000039 , fActionClearDeletes(this)
chudy@google.comc432f002012-07-10 13:19:25 +000040 , fActionClose(this)
chudy@google.come504de02012-07-16 18:35:23 +000041 , fActionCreateBreakpoint(this)
chudy@google.comc432f002012-07-10 13:19:25 +000042 , fActionDelete(this)
43 , fActionDirectory(this)
44 , fActionGoToLine(this)
45 , fActionInspector(this)
bungeman@google.com2ff6d1d2013-07-01 14:24:12 +000046 , fActionSettings(this)
chudy@google.comc432f002012-07-10 13:19:25 +000047 , fActionPlay(this)
chudy@google.come504de02012-07-16 18:35:23 +000048 , fActionPause(this)
chudy@google.comc432f002012-07-10 13:19:25 +000049 , fActionRewind(this)
chudy@google.com0ab03392012-07-28 20:16:11 +000050 , fActionSave(this)
51 , fActionSaveAs(this)
chudy@google.com7e4cfbf2012-07-17 15:40:51 +000052 , fActionShowDeletes(this)
chudy@google.comc432f002012-07-10 13:19:25 +000053 , fActionStepBack(this)
54 , fActionStepForward(this)
chudy@google.coma1226312012-07-26 20:26:44 +000055 , fActionZoomIn(this)
56 , fActionZoomOut(this)
57 , fMapper(this)
commit-bot@chromium.orgbcd431e2013-11-21 13:41:37 +000058 , fListWidget(&fCentralSplitter)
59 , fDirectoryWidget(&fCentralSplitter)
chudy@google.com607357f2012-08-07 16:12:23 +000060 , fCanvasWidget(this, &fDebugger)
kkinnunen63a47022014-12-30 23:03:56 -080061 , fDrawCommandGeometryWidget(&fDebugger)
chudy@google.comc432f002012-07-10 13:19:25 +000062 , fMenuBar(this)
63 , fMenuFile(this)
64 , fMenuNavigate(this)
65 , fMenuView(this)
chudy@google.comd3058f52012-07-19 13:41:27 +000066 , fLoading(false)
chudy@google.comc432f002012-07-10 13:19:25 +000067{
chudy@google.com902ebe52012-06-29 14:21:22 +000068 setupUi(this);
robertphillips@google.comdd4b7452013-01-22 19:38:46 +000069 fListWidget.setSelectionMode(QAbstractItemView::ExtendedSelection);
kkinnunen0cfeaf32015-01-07 07:33:46 -080070 connect(&fListWidget, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)), this,
71 SLOT(updateDrawCommandInfo()));
chudy@google.comc432f002012-07-10 13:19:25 +000072 connect(&fActionOpen, SIGNAL(triggered()), this, SLOT(openFile()));
chudy@google.comea5488b2012-07-26 19:38:22 +000073 connect(&fActionDirectory, SIGNAL(triggered()), this, SLOT(toggleDirectory()));
74 connect(&fDirectoryWidget, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)), this, SLOT(loadFile(QListWidgetItem *)));
chudy@google.comc432f002012-07-10 13:19:25 +000075 connect(&fActionDelete, SIGNAL(triggered()), this, SLOT(actionDelete()));
chudy@google.comea5488b2012-07-26 19:38:22 +000076 connect(&fListWidget, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(toggleBreakpoint()));
chudy@google.comc432f002012-07-10 13:19:25 +000077 connect(&fActionRewind, SIGNAL(triggered()), this, SLOT(actionRewind()));
78 connect(&fActionPlay, SIGNAL(triggered()), this, SLOT(actionPlay()));
79 connect(&fActionStepBack, SIGNAL(triggered()), this, SLOT(actionStepBack()));
chudy@google.comea5488b2012-07-26 19:38:22 +000080 connect(&fActionStepForward, SIGNAL(triggered()), this, SLOT(actionStepForward()));
81 connect(&fActionBreakpoint, SIGNAL(triggered()), this, SLOT(actionBreakpoints()));
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +000082 connect(&fActionToggleIndexStyle, SIGNAL(triggered()), this, SLOT(actionToggleIndexStyle()));
chudy@google.comea5488b2012-07-26 19:38:22 +000083 connect(&fActionInspector, SIGNAL(triggered()), this, SLOT(actionInspector()));
bungeman@google.com2ff6d1d2013-07-01 14:24:12 +000084 connect(&fActionSettings, SIGNAL(triggered()), this, SLOT(actionSettings()));
chudy@google.comea5488b2012-07-26 19:38:22 +000085 connect(&fFilter, SIGNAL(activated(QString)), this, SLOT(toggleFilter(QString)));
robertphillips@google.comd26c7062012-11-12 20:42:12 +000086 connect(&fActionProfile, SIGNAL(triggered()), this, SLOT(actionProfile()));
chudy@google.comc432f002012-07-10 13:19:25 +000087 connect(&fActionCancel, SIGNAL(triggered()), this, SLOT(actionCancel()));
chudy@google.com7e4cfbf2012-07-17 15:40:51 +000088 connect(&fActionClearBreakpoints, SIGNAL(triggered()), this, SLOT(actionClearBreakpoints()));
89 connect(&fActionClearDeletes, SIGNAL(triggered()), this, SLOT(actionClearDeletes()));
chudy@google.comc432f002012-07-10 13:19:25 +000090 connect(&fActionClose, SIGNAL(triggered()), this, SLOT(actionClose()));
robertphillips@google.come8fe4bc2013-02-13 13:26:13 +000091#if SK_SUPPORT_GPU
kkinnunen41c79cc2014-12-30 22:49:58 -080092 connect(&fSettingsWidget, SIGNAL(glSettingsChanged()), this, SLOT(actionGLSettingsChanged()));
robertphillips@google.come8fe4bc2013-02-13 13:26:13 +000093#endif
kkinnunen41c79cc2014-12-30 22:49:58 -080094 connect(&fSettingsWidget, SIGNAL(rasterSettingsChanged()), this, SLOT(actionRasterSettingsChanged()));
95 connect(&fSettingsWidget, SIGNAL(visualizationsChanged()), this, SLOT(actionVisualizationsChanged()));
robertphillips@google.com32bbcf82013-10-17 17:56:10 +000096 connect(&fSettingsWidget, SIGNAL(texFilterSettingsChanged()), this, SLOT(actionTextureFilter()));
chudy@google.comea5488b2012-07-26 19:38:22 +000097 connect(&fActionPause, SIGNAL(toggled(bool)), this, SLOT(pauseDrawing(bool)));
chudy@google.come504de02012-07-16 18:35:23 +000098 connect(&fActionCreateBreakpoint, SIGNAL(activated()), this, SLOT(toggleBreakpoint()));
chudy@google.com7e4cfbf2012-07-17 15:40:51 +000099 connect(&fActionShowDeletes, SIGNAL(triggered()), this, SLOT(showDeletes()));
chudy@google.comea5488b2012-07-26 19:38:22 +0000100 connect(&fCanvasWidget, SIGNAL(hitChanged(int)), this, SLOT(selectCommand(int)));
kkinnunen41c79cc2014-12-30 22:49:58 -0800101 connect(&fCanvasWidget, SIGNAL(hitChanged(int)), this, SLOT(updateHit(int)));
chudy@google.comea5488b2012-07-26 19:38:22 +0000102 connect(&fCanvasWidget, SIGNAL(scaleFactorChanged(float)), this, SLOT(actionScale(float)));
kkinnunen63a47022014-12-30 23:03:56 -0800103
chudy@google.com0ab03392012-07-28 20:16:11 +0000104 connect(&fActionSaveAs, SIGNAL(triggered()), this, SLOT(actionSaveAs()));
105 connect(&fActionSave, SIGNAL(triggered()), this, SLOT(actionSave()));
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000106
bungeman@google.come8cc6e82013-01-17 16:30:56 +0000107 fMapper.setMapping(&fActionZoomIn, SkCanvasWidget::kIn_ZoomCommand);
108 fMapper.setMapping(&fActionZoomOut, SkCanvasWidget::kOut_ZoomCommand);
chudy@google.coma1226312012-07-26 20:26:44 +0000109
110 connect(&fActionZoomIn, SIGNAL(triggered()), &fMapper, SLOT(map()));
111 connect(&fActionZoomOut, SIGNAL(triggered()), &fMapper, SLOT(map()));
bungeman@google.come8cc6e82013-01-17 16:30:56 +0000112 connect(&fMapper, SIGNAL(mapped(int)), &fCanvasWidget, SLOT(zoom(int)));
chudy@google.coma1226312012-07-26 20:26:44 +0000113
kkinnunen41c79cc2014-12-30 22:49:58 -0800114 fViewStateFrame.setDisabled(true);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000115 fInspectorWidget.setDisabled(true);
chudy@google.comd3058f52012-07-19 13:41:27 +0000116 fMenuEdit.setDisabled(true);
117 fMenuNavigate.setDisabled(true);
118 fMenuView.setDisabled(true);
chudy@google.combbad34d2012-08-13 14:26:36 +0000119}
chudy@google.com902ebe52012-06-29 14:21:22 +0000120
121void SkDebuggerGUI::actionBreakpoints() {
kkinnunenf3a9e992015-01-05 01:14:11 -0800122 bool breakpointsActivated = fActionBreakpoint.isChecked();
chudy@google.comc432f002012-07-10 13:19:25 +0000123 for (int row = 0; row < fListWidget.count(); row++) {
124 QListWidgetItem *item = fListWidget.item(row);
kkinnunenf3a9e992015-01-05 01:14:11 -0800125 item->setHidden(item->checkState() == Qt::Unchecked && breakpointsActivated);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000126 }
127}
chudy@google.com902ebe52012-06-29 14:21:22 +0000128
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000129void SkDebuggerGUI::actionToggleIndexStyle() {
kkinnunenf3a9e992015-01-05 01:14:11 -0800130 bool indexStyleToggle = fActionToggleIndexStyle.isChecked();
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000131 SkListWidget* list = (SkListWidget*) fListWidget.itemDelegate();
kkinnunenf3a9e992015-01-05 01:14:11 -0800132 list->setIndexStyle(indexStyleToggle ? SkListWidget::kOffset_IndexStyle
133 : SkListWidget::kIndex_IndexStyle);
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000134 fListWidget.update();
135}
136
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000137void SkDebuggerGUI::showDeletes() {
kkinnunenf3a9e992015-01-05 01:14:11 -0800138 bool deletesActivated = fActionShowDeletes.isChecked();
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000139 for (int row = 0; row < fListWidget.count(); row++) {
140 QListWidgetItem *item = fListWidget.item(row);
kkinnunenf3a9e992015-01-05 01:14:11 -0800141 item->setHidden(fDebugger.isCommandVisible(row) && deletesActivated);
chudy@google.com902ebe52012-06-29 14:21:22 +0000142 }
143}
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000144// This is a simplification of PictureBenchmark's run with the addition of
145// clearing of the times after the first pass (in resetTimes)
robertphillipsce4dd3d2014-07-07 13:46:35 -0700146void SkDebuggerGUI::run(const SkPicture* pict,
skia.committer@gmail.com34587162012-11-20 02:01:23 +0000147 sk_tools::PictureRenderer* renderer,
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000148 int repeats) {
149 SkASSERT(pict);
150 if (NULL == pict) {
151 return;
152 }
153
154 SkASSERT(renderer != NULL);
155 if (NULL == renderer) {
156 return;
157 }
158
robertphillips78c71272014-10-09 04:59:19 -0700159 renderer->init(pict, NULL, NULL, NULL, false, false);
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000160
161 renderer->setup();
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000162 renderer->render();
commit-bot@chromium.org51c040e2014-03-11 22:58:00 +0000163 renderer->resetState(true); // flush, swapBuffers and Finish
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000164
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000165 for (int i = 0; i < repeats; ++i) {
166 renderer->setup();
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000167 renderer->render();
commit-bot@chromium.org51c040e2014-03-11 22:58:00 +0000168 renderer->resetState(false); // flush & swapBuffers, but don't Finish
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000169 }
commit-bot@chromium.org51c040e2014-03-11 22:58:00 +0000170 renderer->resetState(true); // flush, swapBuffers and Finish
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000171
172 renderer->end();
173}
174
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000175void SkDebuggerGUI::actionProfile() {
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000176 // In order to profile we pass the command offsets (that were read-in
177 // in loadPicture by the SkOffsetPicture) to an SkTimedPlaybackPicture.
skia.committer@gmail.com884e60b2012-11-16 02:01:17 +0000178 // The SkTimedPlaybackPicture in turn passes the offsets to an
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000179 // SkTimedPicturePlayback object which uses them to track the performance
180 // of individual commands.
181 if (fFileName.isEmpty()) {
182 return;
183 }
184
185 SkFILEStream inputStream;
186
187 inputStream.setPath(fFileName.c_str());
188 if (!inputStream.isValid()) {
189 return;
190 }
191
robertphillipsce4dd3d2014-07-07 13:46:35 -0700192 SkAutoTUnref<SkPicture> picture(SkPicture::CreateFromStream(&inputStream,
193 &SkImageDecoder::DecodeMemory)); // , fSkipCommands));
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000194 if (NULL == picture.get()) {
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000195 return;
196 }
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000197}
198
chudy@google.com902ebe52012-06-29 14:21:22 +0000199void SkDebuggerGUI::actionCancel() {
chudy@google.comc432f002012-07-10 13:19:25 +0000200 for (int row = 0; row < fListWidget.count(); row++) {
201 fListWidget.item(row)->setHidden(false);
chudy@google.com902ebe52012-06-29 14:21:22 +0000202 }
203}
204
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000205void SkDebuggerGUI::actionClearBreakpoints() {
206 for (int row = 0; row < fListWidget.count(); row++) {
207 QListWidgetItem* item = fListWidget.item(row);
208 item->setCheckState(Qt::Unchecked);
209 item->setData(Qt::DecorationRole,
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000210 QPixmap(":/blank.png"));
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000211 }
212}
213
214void SkDebuggerGUI::actionClearDeletes() {
215 for (int row = 0; row < fListWidget.count(); row++) {
216 QListWidgetItem* item = fListWidget.item(row);
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000217 item->setData(Qt::UserRole + 2, QPixmap(":/blank.png"));
chudy@google.com607357f2012-08-07 16:12:23 +0000218 fDebugger.setCommandVisible(row, true);
robertphillips@google.com5f971142012-12-07 20:48:56 +0000219 fSkipCommands[row] = false;
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000220 }
kkinnunencfdc0e32015-01-13 22:49:02 -0800221 this->updateImage();
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000222}
223
chudy@google.com902ebe52012-06-29 14:21:22 +0000224void SkDebuggerGUI::actionClose() {
225 this->close();
226}
227
228void SkDebuggerGUI::actionDelete() {
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000229
robertphillips@google.comdd4b7452013-01-22 19:38:46 +0000230 for (int row = 0; row < fListWidget.count(); ++row) {
231 QListWidgetItem* item = fListWidget.item(row);
232
233 if (!item->isSelected()) {
234 continue;
235 }
236
237 if (fDebugger.isCommandVisible(row)) {
238 item->setData(Qt::UserRole + 2, QPixmap(":/delete.png"));
239 fDebugger.setCommandVisible(row, false);
240 fSkipCommands[row] = true;
241 } else {
242 item->setData(Qt::UserRole + 2, QPixmap(":/blank.png"));
243 fDebugger.setCommandVisible(row, true);
244 fSkipCommands[row] = false;
245 }
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000246 }
247
kkinnunencfdc0e32015-01-13 22:49:02 -0800248 this->updateImage();
chudy@google.com902ebe52012-06-29 14:21:22 +0000249}
250
robertphillips@google.come8fe4bc2013-02-13 13:26:13 +0000251#if SK_SUPPORT_GPU
kkinnunen41c79cc2014-12-30 22:49:58 -0800252void SkDebuggerGUI::actionGLSettingsChanged() {
commit-bot@chromium.orgfde1e7c2013-08-02 13:59:50 +0000253 bool isToggled = fSettingsWidget.isGLActive();
254 if (isToggled) {
255 fCanvasWidget.setGLSampleCount(fSettingsWidget.getGLSampleCount());
256 }
chudy@google.comea5488b2012-07-26 19:38:22 +0000257 fCanvasWidget.setWidgetVisibility(SkCanvasWidget::kGPU_WidgetType, !isToggled);
258}
robertphillips@google.come8fe4bc2013-02-13 13:26:13 +0000259#endif
chudy@google.comea5488b2012-07-26 19:38:22 +0000260
chudy@google.com902ebe52012-06-29 14:21:22 +0000261void SkDebuggerGUI::actionInspector() {
kkinnunen41c79cc2014-12-30 22:49:58 -0800262 bool newState = !fInspectorWidget.isHidden();
263
264 fInspectorWidget.setHidden(newState);
265 fViewStateFrame.setHidden(newState);
kkinnunen63a47022014-12-30 23:03:56 -0800266 fDrawCommandGeometryWidget.setHidden(newState);
chudy@google.com902ebe52012-06-29 14:21:22 +0000267}
268
269void SkDebuggerGUI::actionPlay() {
chudy@google.comc432f002012-07-10 13:19:25 +0000270 for (int row = fListWidget.currentRow() + 1; row < fListWidget.count();
chudy@google.com7dcae672012-07-09 20:26:53 +0000271 row++) {
chudy@google.comc432f002012-07-10 13:19:25 +0000272 QListWidgetItem *item = fListWidget.item(row);
chudy@google.com902ebe52012-06-29 14:21:22 +0000273 if (item->checkState() == Qt::Checked) {
chudy@google.comc432f002012-07-10 13:19:25 +0000274 fListWidget.setCurrentItem(item);
chudy@google.com902ebe52012-06-29 14:21:22 +0000275 return;
276 }
277 }
chudy@google.comc432f002012-07-10 13:19:25 +0000278 fListWidget.setCurrentRow(fListWidget.count() - 1);
chudy@google.com902ebe52012-06-29 14:21:22 +0000279}
280
kkinnunen41c79cc2014-12-30 22:49:58 -0800281void SkDebuggerGUI::actionRasterSettingsChanged() {
282 fCanvasWidget.setWidgetVisibility(SkCanvasWidget::kRaster_8888_WidgetType,
283 !fSettingsWidget.isRasterEnabled());
284 fDebugger.setOverdrawViz(fSettingsWidget.isOverdrawVizEnabled());
kkinnunencfdc0e32015-01-13 22:49:02 -0800285 this->updateImage();
robertphillips@google.comf4741c12013-02-06 20:13:54 +0000286}
287
kkinnunen41c79cc2014-12-30 22:49:58 -0800288void SkDebuggerGUI::actionVisualizationsChanged() {
289 fDebugger.setMegaViz(fSettingsWidget.isMegaVizEnabled());
290 fDebugger.setPathOps(fSettingsWidget.isPathOpsEnabled());
291 fDebugger.highlightCurrentCommand(fSettingsWidget.isVisibilityFilterEnabled());
kkinnunencfdc0e32015-01-13 22:49:02 -0800292 this->updateImage();
commit-bot@chromium.org2a67e122014-05-19 13:53:10 +0000293}
294
robertphillips@google.com32bbcf82013-10-17 17:56:10 +0000295void SkDebuggerGUI::actionTextureFilter() {
reede7903c72015-03-16 10:26:13 -0700296 SkFilterQuality quality;
297 bool enabled = fSettingsWidget.getFilterOverride(&quality);
298 fDebugger.setTexFilterOverride(enabled, quality);
robertphillips@google.com32bbcf82013-10-17 17:56:10 +0000299 fCanvasWidget.update();
300}
301
chudy@google.com902ebe52012-06-29 14:21:22 +0000302void SkDebuggerGUI::actionRewind() {
chudy@google.come504de02012-07-16 18:35:23 +0000303 fListWidget.setCurrentRow(0);
chudy@google.com902ebe52012-06-29 14:21:22 +0000304}
305
chudy@google.com0ab03392012-07-28 20:16:11 +0000306void SkDebuggerGUI::actionSave() {
robertphillips@google.come219baf2013-01-28 19:25:43 +0000307 fFileName = fPath.toAscii().data();
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000308 fFileName.append("/");
robertphillips@google.come219baf2013-01-28 19:25:43 +0000309 fFileName.append(fDirectoryWidget.currentItem()->text().toAscii().data());
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000310 saveToFile(fFileName);
chudy@google.com0ab03392012-07-28 20:16:11 +0000311}
312
313void SkDebuggerGUI::actionSaveAs() {
314 QString filename = QFileDialog::getSaveFileName(this, "Save File", "",
315 "Skia Picture (*skp)");
chudy@google.com38b08ce2012-07-28 23:26:10 +0000316 if (!filename.endsWith(".skp", Qt::CaseInsensitive)) {
chudy@google.com0ab03392012-07-28 20:16:11 +0000317 filename.append(".skp");
318 }
djsollen@google.comc3c82162012-11-13 18:35:10 +0000319 saveToFile(SkString(filename.toAscii().data()));
chudy@google.com0ab03392012-07-28 20:16:11 +0000320}
321
chudy@google.com7dcae672012-07-09 20:26:53 +0000322void SkDebuggerGUI::actionScale(float scaleFactor) {
kkinnunen41c79cc2014-12-30 22:49:58 -0800323 fZoomBox.setText(QString::number(scaleFactor * 100, 'f', 0).append("%"));
chudy@google.com7dcae672012-07-09 20:26:53 +0000324}
325
chudy@google.com902ebe52012-06-29 14:21:22 +0000326void SkDebuggerGUI::actionSettings() {
chudy@google.comc432f002012-07-10 13:19:25 +0000327 if (fSettingsWidget.isHidden()) {
328 fSettingsWidget.setHidden(false);
chudy@google.com902ebe52012-06-29 14:21:22 +0000329 } else {
chudy@google.comc432f002012-07-10 13:19:25 +0000330 fSettingsWidget.setHidden(true);
chudy@google.com902ebe52012-06-29 14:21:22 +0000331 }
332}
333
334void SkDebuggerGUI::actionStepBack() {
chudy@google.comc432f002012-07-10 13:19:25 +0000335 int currentRow = fListWidget.currentRow();
chudy@google.com902ebe52012-06-29 14:21:22 +0000336 if (currentRow != 0) {
chudy@google.comc432f002012-07-10 13:19:25 +0000337 fListWidget.setCurrentRow(currentRow - 1);
chudy@google.com902ebe52012-06-29 14:21:22 +0000338 }
339}
340
341void SkDebuggerGUI::actionStepForward() {
chudy@google.comc432f002012-07-10 13:19:25 +0000342 int currentRow = fListWidget.currentRow();
chudy@google.com902ebe52012-06-29 14:21:22 +0000343 QString curRow = QString::number(currentRow);
chudy@google.comc432f002012-07-10 13:19:25 +0000344 QString curCount = QString::number(fListWidget.count());
345 if (currentRow < fListWidget.count() - 1) {
346 fListWidget.setCurrentRow(currentRow + 1);
chudy@google.com902ebe52012-06-29 14:21:22 +0000347 }
348}
349
chudy@google.coma9e937c2012-08-03 17:32:05 +0000350void SkDebuggerGUI::drawComplete() {
kkinnunencfdc0e32015-01-13 22:49:02 -0800351 SkString clipStack;
352 fDebugger.getClipStackText(&clipStack);
353 fInspectorWidget.setText(clipStack.c_str(), SkInspectorWidget::kClipStack_TabType);
354
chudy@google.com607357f2012-08-07 16:12:23 +0000355 fInspectorWidget.setMatrix(fDebugger.getCurrentMatrix());
356 fInspectorWidget.setClip(fDebugger.getCurrentClip());
chudy@google.coma9e937c2012-08-03 17:32:05 +0000357}
358
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000359void SkDebuggerGUI::saveToFile(const SkString& filename) {
360 SkFILEWStream file(filename.c_str());
robertphillips@google.com25bc2f82013-01-22 18:03:56 +0000361 SkAutoTUnref<SkPicture> copy(fDebugger.copyPicture());
362
robertphillips3e5c2b12015-03-23 05:46:51 -0700363 sk_tool_utils::PngPixelSerializer serializer;
364 copy->serialize(&file, &serializer);
chudy@google.com0ab03392012-07-28 20:16:11 +0000365}
366
chudy@google.com902ebe52012-06-29 14:21:22 +0000367void SkDebuggerGUI::loadFile(QListWidgetItem *item) {
368 if (fDirectoryWidgetActive) {
robertphillips@google.come219baf2013-01-28 19:25:43 +0000369 fFileName = fPath.toAscii().data();
jvanverth@google.com0ac6f162013-02-05 19:44:07 +0000370 // don't add a '/' to files in the local directory
371 if (fFileName.size() > 0) {
372 fFileName.append("/");
373 }
robertphillips@google.come219baf2013-01-28 19:25:43 +0000374 fFileName.append(item->text().toAscii().data());
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000375 loadPicture(fFileName);
chudy@google.com902ebe52012-06-29 14:21:22 +0000376 }
377}
378
379void SkDebuggerGUI::openFile() {
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000380 QString temp = QFileDialog::getOpenFileName(this, tr("Open File"), "",
chudy@google.com7dcae672012-07-09 20:26:53 +0000381 tr("Files (*.*)"));
robertphillips@google.comff6e6ba2013-01-28 17:43:26 +0000382 openFile(temp);
383}
384
385void SkDebuggerGUI::openFile(const QString &filename) {
chudy@google.com902ebe52012-06-29 14:21:22 +0000386 fDirectoryWidgetActive = false;
robertphillips@google.comff6e6ba2013-01-28 17:43:26 +0000387 if (!filename.isEmpty()) {
388 QFileInfo pathInfo(filename);
389 loadPicture(SkString(filename.toAscii().data()));
390 setupDirectoryWidget(pathInfo.path());
chudy@google.com902ebe52012-06-29 14:21:22 +0000391 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000392 fDirectoryWidgetActive = true;
393}
394
chudy@google.comc432f002012-07-10 13:19:25 +0000395void SkDebuggerGUI::pauseDrawing(bool isPaused) {
chudy@google.com607357f2012-08-07 16:12:23 +0000396 fPausedRow = fListWidget.currentRow();
kkinnunencfdc0e32015-01-13 22:49:02 -0800397 this->updateDrawCommandInfo();
chudy@google.com7dcae672012-07-09 20:26:53 +0000398}
399
kkinnunen0cfeaf32015-01-07 07:33:46 -0800400void SkDebuggerGUI::updateDrawCommandInfo() {
401 int currentRow = -1;
402 if (!fLoading) {
403 currentRow = fListWidget.currentRow();
404 }
405 if (currentRow == -1) {
406 fInspectorWidget.setText("", SkInspectorWidget::kDetail_TabType);
407 fInspectorWidget.setText("", SkInspectorWidget::kClipStack_TabType);
408 fCurrentCommandBox.setText("");
409 fDrawCommandGeometryWidget.setDrawCommandIndex(-1);
410 } else {
kkinnunencfdc0e32015-01-13 22:49:02 -0800411 this->updateImage();
412
kkinnunen0cfeaf32015-01-07 07:33:46 -0800413 const SkTDArray<SkString*> *currInfo = fDebugger.getCommandInfo(currentRow);
chudy@google.comd3058f52012-07-19 13:41:27 +0000414
kkinnunen0cfeaf32015-01-07 07:33:46 -0800415 /* TODO(chudy): Add command type before parameters. Rename v
416 * to something more informative. */
417 if (currInfo) {
418 QString info;
419 info.append("<b>Parameters: </b><br/>");
420 for (int i = 0; i < currInfo->count(); i++) {
421 info.append(QString((*currInfo)[i]->c_str()));
422 info.append("<br/>");
chudy@google.comd3058f52012-07-19 13:41:27 +0000423 }
kkinnunen0cfeaf32015-01-07 07:33:46 -0800424 fInspectorWidget.setText(info, SkInspectorWidget::kDetail_TabType);
chudy@google.comd3058f52012-07-19 13:41:27 +0000425 }
chudy@google.comea5488b2012-07-26 19:38:22 +0000426
kkinnunen0cfeaf32015-01-07 07:33:46 -0800427 fCurrentCommandBox.setText(QString::number(currentRow));
428
429 fDrawCommandGeometryWidget.setDrawCommandIndex(currentRow);
430
431 fInspectorWidget.setDisabled(false);
432 fViewStateFrame.setDisabled(false);
chudy@google.com902ebe52012-06-29 14:21:22 +0000433 }
434}
435
chudy@google.com9ca9bfe2012-07-12 21:58:14 +0000436void SkDebuggerGUI::selectCommand(int command) {
kkinnunenf3a9e992015-01-05 01:14:11 -0800437 if (this->isPaused()) {
chudy@google.com9ca9bfe2012-07-12 21:58:14 +0000438 fListWidget.setCurrentRow(command);
439 }
440}
441
chudy@google.com902ebe52012-06-29 14:21:22 +0000442void SkDebuggerGUI::toggleBreakpoint() {
chudy@google.comc432f002012-07-10 13:19:25 +0000443 QListWidgetItem* item = fListWidget.currentItem();
chudy@google.com902ebe52012-06-29 14:21:22 +0000444 if (item->checkState() == Qt::Unchecked) {
445 item->setCheckState(Qt::Checked);
chudy@google.come565de42012-07-12 14:15:54 +0000446 item->setData(Qt::DecorationRole,
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000447 QPixmap(":/breakpoint_16x16.png"));
chudy@google.com902ebe52012-06-29 14:21:22 +0000448 } else {
chudy@google.com902ebe52012-06-29 14:21:22 +0000449 item->setCheckState(Qt::Unchecked);
chudy@google.come565de42012-07-12 14:15:54 +0000450 item->setData(Qt::DecorationRole,
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000451 QPixmap(":/blank.png"));
chudy@google.com902ebe52012-06-29 14:21:22 +0000452 }
453}
454
455void SkDebuggerGUI::toggleDirectory() {
chudy@google.com607357f2012-08-07 16:12:23 +0000456 fDirectoryWidget.setHidden(!fDirectoryWidget.isHidden());
chudy@google.com902ebe52012-06-29 14:21:22 +0000457}
458
459void SkDebuggerGUI::toggleFilter(QString string) {
chudy@google.comc432f002012-07-10 13:19:25 +0000460 for (int row = 0; row < fListWidget.count(); row++) {
461 QListWidgetItem *item = fListWidget.item(row);
chudy@google.com607357f2012-08-07 16:12:23 +0000462 item->setHidden(item->text() != string);
chudy@google.com902ebe52012-06-29 14:21:22 +0000463 }
464}
465
466void SkDebuggerGUI::setupUi(QMainWindow *SkDebuggerGUI) {
467 QIcon windowIcon;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000468 windowIcon.addFile(QString::fromUtf8(":/skia.png"), QSize(),
chudy@google.com7dcae672012-07-09 20:26:53 +0000469 QIcon::Normal, QIcon::Off);
chudy@google.com902ebe52012-06-29 14:21:22 +0000470 SkDebuggerGUI->setObjectName(QString::fromUtf8("SkDebuggerGUI"));
471 SkDebuggerGUI->resize(1200, 1000);
472 SkDebuggerGUI->setWindowIcon(windowIcon);
chudy@google.comc432f002012-07-10 13:19:25 +0000473 SkDebuggerGUI->setWindowTitle("Skia Debugger");
chudy@google.com902ebe52012-06-29 14:21:22 +0000474
chudy@google.come504de02012-07-16 18:35:23 +0000475 fActionOpen.setShortcuts(QKeySequence::Open);
chudy@google.comc432f002012-07-10 13:19:25 +0000476 fActionOpen.setText("Open");
chudy@google.com902ebe52012-06-29 14:21:22 +0000477
478 QIcon breakpoint;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000479 breakpoint.addFile(QString::fromUtf8(":/breakpoint.png"),
chudy@google.com7dcae672012-07-09 20:26:53 +0000480 QSize(), QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000481 fActionBreakpoint.setShortcut(QKeySequence(tr("Ctrl+B")));
chudy@google.comc432f002012-07-10 13:19:25 +0000482 fActionBreakpoint.setIcon(breakpoint);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000483 fActionBreakpoint.setText("Breakpoints");
kkinnunenf3a9e992015-01-05 01:14:11 -0800484 fActionBreakpoint.setCheckable(true);
chudy@google.com902ebe52012-06-29 14:21:22 +0000485
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000486 fActionToggleIndexStyle.setShortcut(QKeySequence(tr("Ctrl+T")));
487 fActionToggleIndexStyle.setText("Toggle Index Style");
kkinnunenf3a9e992015-01-05 01:14:11 -0800488 fActionToggleIndexStyle.setCheckable(true);
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000489
chudy@google.com902ebe52012-06-29 14:21:22 +0000490 QIcon cancel;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000491 cancel.addFile(QString::fromUtf8(":/reload.png"), QSize(),
chudy@google.com7dcae672012-07-09 20:26:53 +0000492 QIcon::Normal, QIcon::Off);
chudy@google.comc432f002012-07-10 13:19:25 +0000493 fActionCancel.setIcon(cancel);
494 fActionCancel.setText("Clear Filter");
chudy@google.com902ebe52012-06-29 14:21:22 +0000495
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000496 fActionClearBreakpoints.setShortcut(QKeySequence(tr("Alt+B")));
497 fActionClearBreakpoints.setText("Clear Breakpoints");
498
499 fActionClearDeletes.setShortcut(QKeySequence(tr("Alt+X")));
500 fActionClearDeletes.setText("Clear Deletes");
501
chudy@google.come504de02012-07-16 18:35:23 +0000502 fActionClose.setShortcuts(QKeySequence::Quit);
chudy@google.comc432f002012-07-10 13:19:25 +0000503 fActionClose.setText("Exit");
chudy@google.com902ebe52012-06-29 14:21:22 +0000504
chudy@google.come504de02012-07-16 18:35:23 +0000505 fActionCreateBreakpoint.setShortcut(QKeySequence(tr("B")));
506 fActionCreateBreakpoint.setText("Set Breakpoint");
507
508 fActionDelete.setShortcut(QKeySequence(tr("X")));
chudy@google.comc432f002012-07-10 13:19:25 +0000509 fActionDelete.setText("Delete Command");
chudy@google.com902ebe52012-06-29 14:21:22 +0000510
chudy@google.come504de02012-07-16 18:35:23 +0000511 fActionDirectory.setShortcut(QKeySequence(tr("Ctrl+D")));
512 fActionDirectory.setText("Directory");
chudy@google.com902ebe52012-06-29 14:21:22 +0000513
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000514 QIcon profile;
robertphillips@google.comd1636362012-11-19 18:25:09 +0000515 profile.addFile(QString::fromUtf8(":/profile.png"), QSize(),
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000516 QIcon::Normal, QIcon::Off);
517 fActionProfile.setIcon(profile);
518 fActionProfile.setText("Profile");
robertphillips@google.come099bc42012-11-19 16:26:40 +0000519 fActionProfile.setDisabled(true);
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000520
chudy@google.comc432f002012-07-10 13:19:25 +0000521 QIcon inspector;
robertphillips@google.comd1636362012-11-19 18:25:09 +0000522 inspector.addFile(QString::fromUtf8(":/inspector.png"),
chudy@google.comc432f002012-07-10 13:19:25 +0000523 QSize(), QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000524 fActionInspector.setShortcut(QKeySequence(tr("Ctrl+I")));
chudy@google.comc432f002012-07-10 13:19:25 +0000525 fActionInspector.setIcon(inspector);
chudy@google.come504de02012-07-16 18:35:23 +0000526 fActionInspector.setText("Inspector");
chudy@google.com902ebe52012-06-29 14:21:22 +0000527
bungeman@google.com2ff6d1d2013-07-01 14:24:12 +0000528 QIcon settings;
529 settings.addFile(QString::fromUtf8(":/inspector.png"),
530 QSize(), QIcon::Normal, QIcon::Off);
531 fActionSettings.setShortcut(QKeySequence(tr("Ctrl+G")));
532 fActionSettings.setIcon(settings);
533 fActionSettings.setText("Settings");
skia.committer@gmail.com0d55dd72013-07-02 07:00:59 +0000534
chudy@google.comc432f002012-07-10 13:19:25 +0000535 QIcon play;
robertphillips@google.comd1636362012-11-19 18:25:09 +0000536 play.addFile(QString::fromUtf8(":/play.png"), QSize(),
chudy@google.comc432f002012-07-10 13:19:25 +0000537 QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000538 fActionPlay.setShortcut(QKeySequence(tr("Ctrl+P")));
chudy@google.comc432f002012-07-10 13:19:25 +0000539 fActionPlay.setIcon(play);
540 fActionPlay.setText("Play");
chudy@google.com902ebe52012-06-29 14:21:22 +0000541
chudy@google.come504de02012-07-16 18:35:23 +0000542 QIcon pause;
robertphillips@google.comd1636362012-11-19 18:25:09 +0000543 pause.addFile(QString::fromUtf8(":/pause.png"), QSize(),
chudy@google.comc432f002012-07-10 13:19:25 +0000544 QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000545 fActionPause.setShortcut(QKeySequence(tr("Space")));
546 fActionPause.setCheckable(true);
547 fActionPause.setIcon(pause);
548 fActionPause.setText("Pause");
549
chudy@google.comc432f002012-07-10 13:19:25 +0000550 QIcon rewind;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000551 rewind.addFile(QString::fromUtf8(":/rewind.png"), QSize(),
chudy@google.comc432f002012-07-10 13:19:25 +0000552 QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000553 fActionRewind.setShortcut(QKeySequence(tr("Ctrl+R")));
chudy@google.comc432f002012-07-10 13:19:25 +0000554 fActionRewind.setIcon(rewind);
555 fActionRewind.setText("Rewind");
chudy@google.com902ebe52012-06-29 14:21:22 +0000556
chudy@google.com0ab03392012-07-28 20:16:11 +0000557 fActionSave.setShortcut(QKeySequence::Save);
558 fActionSave.setText("Save");
559 fActionSave.setDisabled(true);
560 fActionSaveAs.setShortcut(QKeySequence::SaveAs);
561 fActionSaveAs.setText("Save As");
562 fActionSaveAs.setDisabled(true);
563
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000564 fActionShowDeletes.setShortcut(QKeySequence(tr("Ctrl+X")));
565 fActionShowDeletes.setText("Deleted Commands");
kkinnunenf3a9e992015-01-05 01:14:11 -0800566 fActionShowDeletes.setCheckable(true);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000567
chudy@google.comc432f002012-07-10 13:19:25 +0000568 QIcon stepBack;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000569 stepBack.addFile(QString::fromUtf8(":/previous.png"), QSize(),
chudy@google.comc432f002012-07-10 13:19:25 +0000570 QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000571 fActionStepBack.setShortcut(QKeySequence(tr("[")));
chudy@google.comc432f002012-07-10 13:19:25 +0000572 fActionStepBack.setIcon(stepBack);
573 fActionStepBack.setText("Step Back");
chudy@google.com902ebe52012-06-29 14:21:22 +0000574
chudy@google.comc432f002012-07-10 13:19:25 +0000575 QIcon stepForward;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000576 stepForward.addFile(QString::fromUtf8(":/next.png"),
chudy@google.comc432f002012-07-10 13:19:25 +0000577 QSize(), QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000578 fActionStepForward.setShortcut(QKeySequence(tr("]")));
chudy@google.comc432f002012-07-10 13:19:25 +0000579 fActionStepForward.setIcon(stepForward);
580 fActionStepForward.setText("Step Forward");
581
chudy@google.coma1226312012-07-26 20:26:44 +0000582 fActionZoomIn.setShortcut(QKeySequence(tr("Ctrl+=")));
583 fActionZoomIn.setText("Zoom In");
584 fActionZoomOut.setShortcut(QKeySequence(tr("Ctrl+-")));
585 fActionZoomOut.setText("Zoom Out");
586
chudy@google.comc432f002012-07-10 13:19:25 +0000587 fListWidget.setItemDelegate(new SkListWidget(&fListWidget));
588 fListWidget.setObjectName(QString::fromUtf8("listWidget"));
commit-bot@chromium.orgbcd431e2013-11-21 13:41:37 +0000589 fListWidget.setMinimumWidth(250);
chudy@google.comc432f002012-07-10 13:19:25 +0000590
591 fFilter.addItem("--Filter By Available Commands--");
592
commit-bot@chromium.orgbcd431e2013-11-21 13:41:37 +0000593 fDirectoryWidget.setMinimumWidth(250);
chudy@google.comc432f002012-07-10 13:19:25 +0000594 fDirectoryWidget.setStyleSheet("QListWidget::Item {padding: 5px;}");
595
596 fCanvasWidget.setSizePolicy(QSizePolicy::Expanding,
chudy@google.com7dcae672012-07-09 20:26:53 +0000597 QSizePolicy::Expanding);
chudy@google.com902ebe52012-06-29 14:21:22 +0000598
kkinnunen63a47022014-12-30 23:03:56 -0800599 fDrawCommandGeometryWidget.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000600
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000601 fSettingsAndImageLayout.addWidget(&fSettingsWidget);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000602
kkinnunen41c79cc2014-12-30 22:49:58 -0800603 // View state group, part of inspector.
604 fViewStateFrame.setFrameStyle(QFrame::Panel);
605 fViewStateFrame.setLayout(&fViewStateFrameLayout);
606 fViewStateFrameLayout.addWidget(&fViewStateGroup);
kkinnunen63a47022014-12-30 23:03:56 -0800607 fViewStateGroup.setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
kkinnunen41c79cc2014-12-30 22:49:58 -0800608 fViewStateGroup.setTitle("View");
609 fViewStateLayout.addRow("Zoom Level", &fZoomBox);
610 fZoomBox.setText("100%");
611 fZoomBox.setMinimumSize(QSize(50,25));
612 fZoomBox.setMaximumSize(QSize(50,25));
613 fZoomBox.setAlignment(Qt::AlignRight);
614 fZoomBox.setReadOnly(true);
615 fViewStateLayout.addRow("Command HitBox", &fCommandHitBox);
616 fCommandHitBox.setText("0");
617 fCommandHitBox.setMinimumSize(QSize(50,25));
618 fCommandHitBox.setMaximumSize(QSize(50,25));
619 fCommandHitBox.setAlignment(Qt::AlignRight);
620 fCommandHitBox.setReadOnly(true);
621 fViewStateLayout.addRow("Current Command", &fCurrentCommandBox);
622 fCurrentCommandBox.setText("0");
623 fCurrentCommandBox.setMinimumSize(QSize(50,25));
624 fCurrentCommandBox.setMaximumSize(QSize(50,25));
625 fCurrentCommandBox.setAlignment(Qt::AlignRight);
626 fCurrentCommandBox.setReadOnly(true);
627 fViewStateGroup.setLayout(&fViewStateLayout);
628 fSettingsAndImageLayout.addWidget(&fViewStateFrame);
629
kkinnunen63a47022014-12-30 23:03:56 -0800630 fDrawCommandGeometryWidget.setToolTip("Current Command Geometry");
631 fSettingsAndImageLayout.addWidget(&fDrawCommandGeometryWidget);
chudy@google.com902ebe52012-06-29 14:21:22 +0000632
commit-bot@chromium.orgbcd431e2013-11-21 13:41:37 +0000633 fLeftColumnSplitter.addWidget(&fListWidget);
634 fLeftColumnSplitter.addWidget(&fDirectoryWidget);
635 fLeftColumnSplitter.setOrientation(Qt::Vertical);
chudy@google.com902ebe52012-06-29 14:21:22 +0000636
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000637 fCanvasSettingsAndImageLayout.setSpacing(6);
kkinnunen41c79cc2014-12-30 22:49:58 -0800638 fCanvasSettingsAndImageLayout.addWidget(&fCanvasWidget, 1);
639 fCanvasSettingsAndImageLayout.addLayout(&fSettingsAndImageLayout, 0);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000640
chudy@google.comc432f002012-07-10 13:19:25 +0000641 fMainAndRightColumnLayout.setSpacing(6);
kkinnunen7c339ae2015-01-02 06:35:43 -0800642 fMainAndRightColumnLayout.addLayout(&fCanvasSettingsAndImageLayout, 1);
643 fMainAndRightColumnLayout.addWidget(&fInspectorWidget, 0);
commit-bot@chromium.orgbcd431e2013-11-21 13:41:37 +0000644 fMainAndRightColumnWidget.setLayout(&fMainAndRightColumnLayout);
chudy@google.com902ebe52012-06-29 14:21:22 +0000645
commit-bot@chromium.orgbcd431e2013-11-21 13:41:37 +0000646 fCentralSplitter.addWidget(&fLeftColumnSplitter);
647 fCentralSplitter.addWidget(&fMainAndRightColumnWidget);
648 fCentralSplitter.setStretchFactor(0, 0);
649 fCentralSplitter.setStretchFactor(1, 1);
chudy@google.comc432f002012-07-10 13:19:25 +0000650
commit-bot@chromium.orgbcd431e2013-11-21 13:41:37 +0000651 SkDebuggerGUI->setCentralWidget(&fCentralSplitter);
chudy@google.comc432f002012-07-10 13:19:25 +0000652 SkDebuggerGUI->setStatusBar(&fStatusBar);
653
chudy@google.come504de02012-07-16 18:35:23 +0000654 fToolBar.setIconSize(QSize(32, 32));
chudy@google.comc432f002012-07-10 13:19:25 +0000655 fToolBar.setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
656 SkDebuggerGUI->addToolBar(Qt::TopToolBarArea, &fToolBar);
chudy@google.com902ebe52012-06-29 14:21:22 +0000657
chudy@google.com0ab03392012-07-28 20:16:11 +0000658 fSpacer.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
chudy@google.com902ebe52012-06-29 14:21:22 +0000659
chudy@google.comc432f002012-07-10 13:19:25 +0000660 fToolBar.addAction(&fActionRewind);
661 fToolBar.addAction(&fActionStepBack);
chudy@google.come504de02012-07-16 18:35:23 +0000662 fToolBar.addAction(&fActionPause);
chudy@google.comc432f002012-07-10 13:19:25 +0000663 fToolBar.addAction(&fActionStepForward);
664 fToolBar.addAction(&fActionPlay);
665 fToolBar.addSeparator();
chudy@google.come504de02012-07-16 18:35:23 +0000666 fToolBar.addAction(&fActionInspector);
bungeman@google.com2ff6d1d2013-07-01 14:24:12 +0000667 fToolBar.addAction(&fActionSettings);
chudy@google.comc432f002012-07-10 13:19:25 +0000668 fToolBar.addSeparator();
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000669 fToolBar.addAction(&fActionProfile);
670
671 fToolBar.addSeparator();
chudy@google.com0ab03392012-07-28 20:16:11 +0000672 fToolBar.addWidget(&fSpacer);
chudy@google.comc432f002012-07-10 13:19:25 +0000673 fToolBar.addWidget(&fFilter);
674 fToolBar.addAction(&fActionCancel);
chudy@google.com902ebe52012-06-29 14:21:22 +0000675
676 // TODO(chudy): Remove static call.
677 fDirectoryWidgetActive = false;
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000678 fFileName = "";
robertphillips@google.comff6e6ba2013-01-28 17:43:26 +0000679 setupDirectoryWidget("");
chudy@google.com902ebe52012-06-29 14:21:22 +0000680 fDirectoryWidgetActive = true;
681
chudy@google.com902ebe52012-06-29 14:21:22 +0000682 // Menu Bar
chudy@google.comc432f002012-07-10 13:19:25 +0000683 fMenuFile.setTitle("File");
684 fMenuFile.addAction(&fActionOpen);
chudy@google.com0ab03392012-07-28 20:16:11 +0000685 fMenuFile.addAction(&fActionSave);
686 fMenuFile.addAction(&fActionSaveAs);
chudy@google.comc432f002012-07-10 13:19:25 +0000687 fMenuFile.addAction(&fActionClose);
chudy@google.come504de02012-07-16 18:35:23 +0000688
689 fMenuEdit.setTitle("Edit");
690 fMenuEdit.addAction(&fActionDelete);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000691 fMenuEdit.addAction(&fActionClearDeletes);
692 fMenuEdit.addSeparator();
chudy@google.come504de02012-07-16 18:35:23 +0000693 fMenuEdit.addAction(&fActionCreateBreakpoint);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000694 fMenuEdit.addAction(&fActionClearBreakpoints);
chudy@google.come504de02012-07-16 18:35:23 +0000695
chudy@google.comc432f002012-07-10 13:19:25 +0000696 fMenuNavigate.setTitle("Navigate");
chudy@google.come504de02012-07-16 18:35:23 +0000697 fMenuNavigate.addAction(&fActionRewind);
698 fMenuNavigate.addAction(&fActionStepBack);
699 fMenuNavigate.addAction(&fActionStepForward);
700 fMenuNavigate.addAction(&fActionPlay);
701 fMenuNavigate.addAction(&fActionPause);
chudy@google.comc432f002012-07-10 13:19:25 +0000702 fMenuNavigate.addAction(&fActionGoToLine);
chudy@google.come504de02012-07-16 18:35:23 +0000703
chudy@google.comc432f002012-07-10 13:19:25 +0000704 fMenuView.setTitle("View");
chudy@google.come504de02012-07-16 18:35:23 +0000705 fMenuView.addAction(&fActionBreakpoint);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000706 fMenuView.addAction(&fActionShowDeletes);
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000707 fMenuView.addAction(&fActionToggleIndexStyle);
chudy@google.coma1226312012-07-26 20:26:44 +0000708 fMenuView.addAction(&fActionZoomIn);
709 fMenuView.addAction(&fActionZoomOut);
chudy@google.come504de02012-07-16 18:35:23 +0000710
711 fMenuWindows.setTitle("Window");
712 fMenuWindows.addAction(&fActionInspector);
bungeman@google.com2ff6d1d2013-07-01 14:24:12 +0000713 fMenuWindows.addAction(&fActionSettings);
chudy@google.come504de02012-07-16 18:35:23 +0000714 fMenuWindows.addAction(&fActionDirectory);
chudy@google.comc432f002012-07-10 13:19:25 +0000715
716 fActionGoToLine.setText("Go to Line...");
717 fActionGoToLine.setDisabled(true);
718 fMenuBar.addAction(fMenuFile.menuAction());
chudy@google.come504de02012-07-16 18:35:23 +0000719 fMenuBar.addAction(fMenuEdit.menuAction());
chudy@google.comc432f002012-07-10 13:19:25 +0000720 fMenuBar.addAction(fMenuView.menuAction());
721 fMenuBar.addAction(fMenuNavigate.menuAction());
chudy@google.come504de02012-07-16 18:35:23 +0000722 fMenuBar.addAction(fMenuWindows.menuAction());
chudy@google.com902ebe52012-06-29 14:21:22 +0000723
chudy@google.comc432f002012-07-10 13:19:25 +0000724 SkDebuggerGUI->setMenuBar(&fMenuBar);
chudy@google.com902ebe52012-06-29 14:21:22 +0000725 QMetaObject::connectSlotsByName(SkDebuggerGUI);
726}
727
robertphillips@google.comff6e6ba2013-01-28 17:43:26 +0000728void SkDebuggerGUI::setupDirectoryWidget(const QString& path) {
729 fPath = path;
730 QDir dir(path);
chudy@google.com902ebe52012-06-29 14:21:22 +0000731 QRegExp r(".skp");
chudy@google.comc432f002012-07-10 13:19:25 +0000732 fDirectoryWidget.clear();
733 const QStringList files = dir.entryList();
chudy@google.com902ebe52012-06-29 14:21:22 +0000734 foreach (QString f, files) {
chudy@google.com7dcae672012-07-09 20:26:53 +0000735 if (f.contains(r))
chudy@google.comc432f002012-07-10 13:19:25 +0000736 fDirectoryWidget.addItem(f);
chudy@google.com902ebe52012-06-29 14:21:22 +0000737 }
738}
739
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000740void SkDebuggerGUI::loadPicture(const SkString& fileName) {
741 fFileName = fileName;
chudy@google.comd3058f52012-07-19 13:41:27 +0000742 fLoading = true;
scroggoa1193e42015-01-21 12:09:53 -0800743 SkAutoTDelete<SkStream> stream(SkNEW_ARGS(SkFILEStream, (fileName.c_str())));
robertphillips@google.com2d40ec42013-02-07 20:39:40 +0000744
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000745 SkPicture* picture = SkPicture::CreateFromStream(stream);
robertphillips@google.com2d40ec42013-02-07 20:39:40 +0000746
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000747 if (NULL == picture) {
robertphillips@google.com2d40ec42013-02-07 20:39:40 +0000748 QMessageBox::critical(this, "Error loading file", "Couldn't read file, sorry.");
robertphillips@google.com2d40ec42013-02-07 20:39:40 +0000749 return;
750 }
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000751
chudy@google.com686e6802012-08-14 16:00:32 +0000752 fCanvasWidget.resetWidgetTransform();
chudy@google.com607357f2012-08-07 16:12:23 +0000753 fDebugger.loadPicture(picture);
chudy@google.com4c7962e2012-08-14 19:38:31 +0000754
robertphillips@google.com6d9c92b2013-05-23 13:21:18 +0000755 fSkipCommands.setCount(fDebugger.getSize());
756 for (int i = 0; i < fSkipCommands.count(); ++i) {
robertphillips@google.com5f971142012-12-07 20:48:56 +0000757 fSkipCommands[i] = false;
758 }
759
chudy@google.com607357f2012-08-07 16:12:23 +0000760 SkSafeUnref(picture);
761
robertphillips@google.com6d9c92b2013-05-23 13:21:18 +0000762 fActionProfile.setDisabled(false);
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000763
chudy@google.com7dcae672012-07-09 20:26:53 +0000764 /* fDebugCanvas is reinitialized every load picture. Need it to retain value
chudy@google.com607357f2012-08-07 16:12:23 +0000765 * of the visibility filter.
766 * TODO(chudy): This should be deprecated since fDebugger is not
767 * recreated.
768 * */
kkinnunen41c79cc2014-12-30 22:49:58 -0800769 fDebugger.highlightCurrentCommand(fSettingsWidget.isVisibilityFilterEnabled());
chudy@google.com607357f2012-08-07 16:12:23 +0000770
kkinnunen5037e9d2014-12-30 07:22:58 -0800771 this->setupListWidget();
772 this->setupComboBox();
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000773 this->setupOverviewText(NULL, 0.0, 1);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000774 fInspectorWidget.setDisabled(false);
kkinnunen41c79cc2014-12-30 22:49:58 -0800775 fViewStateFrame.setDisabled(false);
chudy@google.come606d6e2012-07-12 14:31:25 +0000776 fSettingsWidget.setDisabled(false);
chudy@google.comd3058f52012-07-19 13:41:27 +0000777 fMenuEdit.setDisabled(false);
778 fMenuNavigate.setDisabled(false);
779 fMenuView.setDisabled(false);
chudy@google.com0ab03392012-07-28 20:16:11 +0000780 fActionSave.setDisabled(false);
781 fActionSaveAs.setDisabled(false);
kkinnunenf3a9e992015-01-05 01:14:11 -0800782 fActionPause.setChecked(false);
kkinnunen0cfeaf32015-01-07 07:33:46 -0800783 fDrawCommandGeometryWidget.setDrawCommandIndex(-1);
784
chudy@google.comd3058f52012-07-19 13:41:27 +0000785 fLoading = false;
786 actionPlay();
chudy@google.com902ebe52012-06-29 14:21:22 +0000787}
788
kkinnunen5037e9d2014-12-30 07:22:58 -0800789void SkDebuggerGUI::setupListWidget() {
chudy@google.comc432f002012-07-10 13:19:25 +0000790 fListWidget.clear();
chudy@google.com902ebe52012-06-29 14:21:22 +0000791 int counter = 0;
robertphillips@google.com30d35f22012-11-06 16:45:36 +0000792 int indent = 0;
kkinnunen5037e9d2014-12-30 07:22:58 -0800793 for (int i = 0; i < fDebugger.getSize(); i++) {
chudy@google.com902ebe52012-06-29 14:21:22 +0000794 QListWidgetItem *item = new QListWidgetItem();
kkinnunen5037e9d2014-12-30 07:22:58 -0800795 SkDrawCommand* command = fDebugger.getDrawCommandAt(i);
796 SkString commandString = command->toString();
797 item->setData(Qt::DisplayRole, commandString.c_str());
chudy@google.com902ebe52012-06-29 14:21:22 +0000798 item->setData(Qt::UserRole + 1, counter++);
robertphillips@google.com30d35f22012-11-06 16:45:36 +0000799
kkinnunen5037e9d2014-12-30 07:22:58 -0800800 if (0 == strcmp("Restore", commandString.c_str()) ||
801 0 == strcmp("EndCommentGroup", commandString.c_str())) {
robertphillips@google.com30d35f22012-11-06 16:45:36 +0000802 indent -= 10;
803 }
804
805 item->setData(Qt::UserRole + 3, indent);
806
kkinnunen5037e9d2014-12-30 07:22:58 -0800807 if (0 == strcmp("Save", commandString.c_str()) ||
808 0 == strcmp("Save Layer", commandString.c_str()) ||
809 0 == strcmp("BeginCommentGroup", commandString.c_str())) {
robertphillips@google.com30d35f22012-11-06 16:45:36 +0000810 indent += 10;
811 }
812
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000813 item->setData(Qt::UserRole + 4, -1);
kkinnunen5037e9d2014-12-30 07:22:58 -0800814 item->setData(Qt::UserRole + 5, (int) command->offset());
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000815
chudy@google.comc432f002012-07-10 13:19:25 +0000816 fListWidget.addItem(item);
chudy@google.com902ebe52012-06-29 14:21:22 +0000817 }
818}
819
skia.committer@gmail.com91274b92013-03-13 07:01:04 +0000820void SkDebuggerGUI::setupOverviewText(const SkTDArray<double>* typeTimes,
robertphillips@google.come428f9b2013-03-12 15:33:40 +0000821 double totTime,
822 int numRuns) {
borenet@google.com2d9dbd42013-03-12 13:07:40 +0000823 SkString overview;
robertphillips@google.come428f9b2013-03-12 15:33:40 +0000824 fDebugger.getOverviewText(typeTimes, totTime, &overview, numRuns);
borenet@google.com2d9dbd42013-03-12 13:07:40 +0000825 fInspectorWidget.setText(overview.c_str(), SkInspectorWidget::kOverview_TabType);
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000826}
827
commit-bot@chromium.org2a67e122014-05-19 13:53:10 +0000828
kkinnunen5037e9d2014-12-30 07:22:58 -0800829void SkDebuggerGUI::setupComboBox() {
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000830 fFilter.clear();
831 fFilter.addItem("--Filter By Available Commands--");
832
833 std::map<std::string, int> map;
kkinnunen5037e9d2014-12-30 07:22:58 -0800834 for (int i = 0; i < fDebugger.getSize(); i++) {
835 map[fDebugger.getDrawCommandAt(i)->toString().c_str()]++;
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000836 }
837
skia.committer@gmail.com34587162012-11-20 02:01:23 +0000838 for (std::map<std::string, int>::iterator it = map.begin(); it != map.end();
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000839 ++it) {
840 fFilter.addItem((it->first).c_str());
841 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000842
843 // NOTE(chudy): Makes first item unselectable.
chudy@google.com7dcae672012-07-09 20:26:53 +0000844 QStandardItemModel* model = qobject_cast<QStandardItemModel*>(
chudy@google.comc432f002012-07-10 13:19:25 +0000845 fFilter.model());
846 QModelIndex firstIndex = model->index(0, fFilter.modelColumn(),
847 fFilter.rootModelIndex());
chudy@google.com902ebe52012-06-29 14:21:22 +0000848 QStandardItem* firstItem = model->itemFromIndex(firstIndex);
849 firstItem->setSelectable(false);
850}
kkinnunen41c79cc2014-12-30 22:49:58 -0800851
kkinnunencfdc0e32015-01-13 22:49:02 -0800852void SkDebuggerGUI::updateImage() {
853 if (this->isPaused()) {
854 fCanvasWidget.drawTo(fPausedRow);
855 } else {
856 fCanvasWidget.drawTo(fListWidget.currentRow());
857 }
858}
859
kkinnunen41c79cc2014-12-30 22:49:58 -0800860void SkDebuggerGUI::updateHit(int newHit) {
861 fCommandHitBox.setText(QString::number(newHit));
862}
863