blob: dade56768d59049b862e8dc4f7f233cb55e5c33f [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"
scroggo@google.com7def5e12013-05-31 14:00:10 +00009#include "SkForceLinking.h"
chudy@google.com902ebe52012-06-29 14:21:22 +000010#include <QListWidgetItem>
robertphillips@google.com2bde91d2012-11-15 14:57:57 +000011#include "PictureRenderer.h"
robertphillipsce4dd3d2014-07-07 13:46:35 -070012#include "SkPicturePlayback.h"
robertphillips@google.com2bde91d2012-11-15 14:57:57 +000013#include "SkPictureRecord.h"
robertphillipsdb539902014-07-01 08:47:04 -070014#include "SkPictureData.h"
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 }
kkinnunenf3a9e992015-01-05 01:14:11 -0800220 if (this->isPaused()) {
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000221 fCanvasWidget.drawTo(fPausedRow);
222 } else {
223 fCanvasWidget.drawTo(fListWidget.currentRow());
224 }
225}
226
chudy@google.com902ebe52012-06-29 14:21:22 +0000227void SkDebuggerGUI::actionClose() {
228 this->close();
229}
230
231void SkDebuggerGUI::actionDelete() {
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000232
robertphillips@google.comdd4b7452013-01-22 19:38:46 +0000233 for (int row = 0; row < fListWidget.count(); ++row) {
234 QListWidgetItem* item = fListWidget.item(row);
235
236 if (!item->isSelected()) {
237 continue;
238 }
239
240 if (fDebugger.isCommandVisible(row)) {
241 item->setData(Qt::UserRole + 2, QPixmap(":/delete.png"));
242 fDebugger.setCommandVisible(row, false);
243 fSkipCommands[row] = true;
244 } else {
245 item->setData(Qt::UserRole + 2, QPixmap(":/blank.png"));
246 fDebugger.setCommandVisible(row, true);
247 fSkipCommands[row] = false;
248 }
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000249 }
250
robertphillips@google.comdd4b7452013-01-22 19:38:46 +0000251 int currentRow = fListWidget.currentRow();
252
kkinnunenf3a9e992015-01-05 01:14:11 -0800253 if (this->isPaused()) {
chudy@google.come504de02012-07-16 18:35:23 +0000254 fCanvasWidget.drawTo(fPausedRow);
255 } else {
256 fCanvasWidget.drawTo(currentRow);
257 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000258}
259
robertphillips@google.come8fe4bc2013-02-13 13:26:13 +0000260#if SK_SUPPORT_GPU
kkinnunen41c79cc2014-12-30 22:49:58 -0800261void SkDebuggerGUI::actionGLSettingsChanged() {
commit-bot@chromium.orgfde1e7c2013-08-02 13:59:50 +0000262 bool isToggled = fSettingsWidget.isGLActive();
263 if (isToggled) {
264 fCanvasWidget.setGLSampleCount(fSettingsWidget.getGLSampleCount());
265 }
chudy@google.comea5488b2012-07-26 19:38:22 +0000266 fCanvasWidget.setWidgetVisibility(SkCanvasWidget::kGPU_WidgetType, !isToggled);
267}
robertphillips@google.come8fe4bc2013-02-13 13:26:13 +0000268#endif
chudy@google.comea5488b2012-07-26 19:38:22 +0000269
chudy@google.com902ebe52012-06-29 14:21:22 +0000270void SkDebuggerGUI::actionInspector() {
kkinnunen41c79cc2014-12-30 22:49:58 -0800271 bool newState = !fInspectorWidget.isHidden();
272
273 fInspectorWidget.setHidden(newState);
274 fViewStateFrame.setHidden(newState);
kkinnunen63a47022014-12-30 23:03:56 -0800275 fDrawCommandGeometryWidget.setHidden(newState);
chudy@google.com902ebe52012-06-29 14:21:22 +0000276}
277
278void SkDebuggerGUI::actionPlay() {
chudy@google.comc432f002012-07-10 13:19:25 +0000279 for (int row = fListWidget.currentRow() + 1; row < fListWidget.count();
chudy@google.com7dcae672012-07-09 20:26:53 +0000280 row++) {
chudy@google.comc432f002012-07-10 13:19:25 +0000281 QListWidgetItem *item = fListWidget.item(row);
chudy@google.com902ebe52012-06-29 14:21:22 +0000282 if (item->checkState() == Qt::Checked) {
chudy@google.comc432f002012-07-10 13:19:25 +0000283 fListWidget.setCurrentItem(item);
chudy@google.com902ebe52012-06-29 14:21:22 +0000284 return;
285 }
286 }
chudy@google.comc432f002012-07-10 13:19:25 +0000287 fListWidget.setCurrentRow(fListWidget.count() - 1);
chudy@google.com902ebe52012-06-29 14:21:22 +0000288}
289
kkinnunen41c79cc2014-12-30 22:49:58 -0800290void SkDebuggerGUI::actionRasterSettingsChanged() {
291 fCanvasWidget.setWidgetVisibility(SkCanvasWidget::kRaster_8888_WidgetType,
292 !fSettingsWidget.isRasterEnabled());
293 fDebugger.setOverdrawViz(fSettingsWidget.isOverdrawVizEnabled());
robertphillips@google.comf4741c12013-02-06 20:13:54 +0000294 fCanvasWidget.update();
295}
296
kkinnunen41c79cc2014-12-30 22:49:58 -0800297void SkDebuggerGUI::actionVisualizationsChanged() {
298 fDebugger.setMegaViz(fSettingsWidget.isMegaVizEnabled());
299 fDebugger.setPathOps(fSettingsWidget.isPathOpsEnabled());
300 fDebugger.highlightCurrentCommand(fSettingsWidget.isVisibilityFilterEnabled());
301 fCanvasWidget.drawTo(fListWidget.currentRow());
commit-bot@chromium.org2a67e122014-05-19 13:53:10 +0000302}
303
robertphillips@google.com32bbcf82013-10-17 17:56:10 +0000304void SkDebuggerGUI::actionTextureFilter() {
305 SkPaint::FilterLevel level;
306 bool enabled = fSettingsWidget.getFilterOverride(&level);
307 fDebugger.setTexFilterOverride(enabled, level);
308 fCanvasWidget.update();
309}
310
chudy@google.com902ebe52012-06-29 14:21:22 +0000311void SkDebuggerGUI::actionRewind() {
chudy@google.come504de02012-07-16 18:35:23 +0000312 fListWidget.setCurrentRow(0);
chudy@google.com902ebe52012-06-29 14:21:22 +0000313}
314
chudy@google.com0ab03392012-07-28 20:16:11 +0000315void SkDebuggerGUI::actionSave() {
robertphillips@google.come219baf2013-01-28 19:25:43 +0000316 fFileName = fPath.toAscii().data();
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000317 fFileName.append("/");
robertphillips@google.come219baf2013-01-28 19:25:43 +0000318 fFileName.append(fDirectoryWidget.currentItem()->text().toAscii().data());
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000319 saveToFile(fFileName);
chudy@google.com0ab03392012-07-28 20:16:11 +0000320}
321
322void SkDebuggerGUI::actionSaveAs() {
323 QString filename = QFileDialog::getSaveFileName(this, "Save File", "",
324 "Skia Picture (*skp)");
chudy@google.com38b08ce2012-07-28 23:26:10 +0000325 if (!filename.endsWith(".skp", Qt::CaseInsensitive)) {
chudy@google.com0ab03392012-07-28 20:16:11 +0000326 filename.append(".skp");
327 }
djsollen@google.comc3c82162012-11-13 18:35:10 +0000328 saveToFile(SkString(filename.toAscii().data()));
chudy@google.com0ab03392012-07-28 20:16:11 +0000329}
330
chudy@google.com7dcae672012-07-09 20:26:53 +0000331void SkDebuggerGUI::actionScale(float scaleFactor) {
kkinnunen41c79cc2014-12-30 22:49:58 -0800332 fZoomBox.setText(QString::number(scaleFactor * 100, 'f', 0).append("%"));
chudy@google.com7dcae672012-07-09 20:26:53 +0000333}
334
chudy@google.com902ebe52012-06-29 14:21:22 +0000335void SkDebuggerGUI::actionSettings() {
chudy@google.comc432f002012-07-10 13:19:25 +0000336 if (fSettingsWidget.isHidden()) {
337 fSettingsWidget.setHidden(false);
chudy@google.com902ebe52012-06-29 14:21:22 +0000338 } else {
chudy@google.comc432f002012-07-10 13:19:25 +0000339 fSettingsWidget.setHidden(true);
chudy@google.com902ebe52012-06-29 14:21:22 +0000340 }
341}
342
343void SkDebuggerGUI::actionStepBack() {
chudy@google.comc432f002012-07-10 13:19:25 +0000344 int currentRow = fListWidget.currentRow();
chudy@google.com902ebe52012-06-29 14:21:22 +0000345 if (currentRow != 0) {
chudy@google.comc432f002012-07-10 13:19:25 +0000346 fListWidget.setCurrentRow(currentRow - 1);
chudy@google.com902ebe52012-06-29 14:21:22 +0000347 }
348}
349
350void SkDebuggerGUI::actionStepForward() {
chudy@google.comc432f002012-07-10 13:19:25 +0000351 int currentRow = fListWidget.currentRow();
chudy@google.com902ebe52012-06-29 14:21:22 +0000352 QString curRow = QString::number(currentRow);
chudy@google.comc432f002012-07-10 13:19:25 +0000353 QString curCount = QString::number(fListWidget.count());
354 if (currentRow < fListWidget.count() - 1) {
355 fListWidget.setCurrentRow(currentRow + 1);
chudy@google.com902ebe52012-06-29 14:21:22 +0000356 }
357}
358
chudy@google.coma9e937c2012-08-03 17:32:05 +0000359void SkDebuggerGUI::drawComplete() {
chudy@google.com607357f2012-08-07 16:12:23 +0000360 fInspectorWidget.setMatrix(fDebugger.getCurrentMatrix());
361 fInspectorWidget.setClip(fDebugger.getCurrentClip());
chudy@google.coma9e937c2012-08-03 17:32:05 +0000362}
363
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000364void SkDebuggerGUI::saveToFile(const SkString& filename) {
365 SkFILEWStream file(filename.c_str());
robertphillips@google.com25bc2f82013-01-22 18:03:56 +0000366 SkAutoTUnref<SkPicture> copy(fDebugger.copyPicture());
367
368 copy->serialize(&file);
chudy@google.com0ab03392012-07-28 20:16:11 +0000369}
370
chudy@google.com902ebe52012-06-29 14:21:22 +0000371void SkDebuggerGUI::loadFile(QListWidgetItem *item) {
372 if (fDirectoryWidgetActive) {
robertphillips@google.come219baf2013-01-28 19:25:43 +0000373 fFileName = fPath.toAscii().data();
jvanverth@google.com0ac6f162013-02-05 19:44:07 +0000374 // don't add a '/' to files in the local directory
375 if (fFileName.size() > 0) {
376 fFileName.append("/");
377 }
robertphillips@google.come219baf2013-01-28 19:25:43 +0000378 fFileName.append(item->text().toAscii().data());
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000379 loadPicture(fFileName);
chudy@google.com902ebe52012-06-29 14:21:22 +0000380 }
381}
382
383void SkDebuggerGUI::openFile() {
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000384 QString temp = QFileDialog::getOpenFileName(this, tr("Open File"), "",
chudy@google.com7dcae672012-07-09 20:26:53 +0000385 tr("Files (*.*)"));
robertphillips@google.comff6e6ba2013-01-28 17:43:26 +0000386 openFile(temp);
387}
388
389void SkDebuggerGUI::openFile(const QString &filename) {
chudy@google.com902ebe52012-06-29 14:21:22 +0000390 fDirectoryWidgetActive = false;
robertphillips@google.comff6e6ba2013-01-28 17:43:26 +0000391 if (!filename.isEmpty()) {
392 QFileInfo pathInfo(filename);
393 loadPicture(SkString(filename.toAscii().data()));
394 setupDirectoryWidget(pathInfo.path());
chudy@google.com902ebe52012-06-29 14:21:22 +0000395 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000396 fDirectoryWidgetActive = true;
397}
398
chudy@google.comc432f002012-07-10 13:19:25 +0000399void SkDebuggerGUI::pauseDrawing(bool isPaused) {
chudy@google.com607357f2012-08-07 16:12:23 +0000400 fPausedRow = fListWidget.currentRow();
kkinnunenf3a9e992015-01-05 01:14:11 -0800401 if (!fLoading) {
402 fCanvasWidget.drawTo(fPausedRow);
403 }
chudy@google.com7dcae672012-07-09 20:26:53 +0000404}
405
kkinnunen0cfeaf32015-01-07 07:33:46 -0800406void SkDebuggerGUI::updateDrawCommandInfo() {
407 int currentRow = -1;
408 if (!fLoading) {
409 currentRow = fListWidget.currentRow();
410 }
411 if (currentRow == -1) {
412 fInspectorWidget.setText("", SkInspectorWidget::kDetail_TabType);
413 fInspectorWidget.setText("", SkInspectorWidget::kClipStack_TabType);
414 fCurrentCommandBox.setText("");
415 fDrawCommandGeometryWidget.setDrawCommandIndex(-1);
416 } else {
417 if (!this->isPaused()) {
418 fCanvasWidget.drawTo(currentRow);
419 }
420 const SkTDArray<SkString*> *currInfo = fDebugger.getCommandInfo(currentRow);
chudy@google.comd3058f52012-07-19 13:41:27 +0000421
kkinnunen0cfeaf32015-01-07 07:33:46 -0800422 /* TODO(chudy): Add command type before parameters. Rename v
423 * to something more informative. */
424 if (currInfo) {
425 QString info;
426 info.append("<b>Parameters: </b><br/>");
427 for (int i = 0; i < currInfo->count(); i++) {
428 info.append(QString((*currInfo)[i]->c_str()));
429 info.append("<br/>");
chudy@google.comd3058f52012-07-19 13:41:27 +0000430 }
kkinnunen0cfeaf32015-01-07 07:33:46 -0800431 fInspectorWidget.setText(info, SkInspectorWidget::kDetail_TabType);
chudy@google.comd3058f52012-07-19 13:41:27 +0000432 }
chudy@google.comea5488b2012-07-26 19:38:22 +0000433
kkinnunen0cfeaf32015-01-07 07:33:46 -0800434 SkString clipStack;
435 fDebugger.getClipStackText(&clipStack);
436 fInspectorWidget.setText(clipStack.c_str(), SkInspectorWidget::kClipStack_TabType);
437
438 fCurrentCommandBox.setText(QString::number(currentRow));
439
440 fDrawCommandGeometryWidget.setDrawCommandIndex(currentRow);
441
442 fInspectorWidget.setDisabled(false);
443 fViewStateFrame.setDisabled(false);
chudy@google.com902ebe52012-06-29 14:21:22 +0000444 }
445}
446
chudy@google.com9ca9bfe2012-07-12 21:58:14 +0000447void SkDebuggerGUI::selectCommand(int command) {
kkinnunenf3a9e992015-01-05 01:14:11 -0800448 if (this->isPaused()) {
chudy@google.com9ca9bfe2012-07-12 21:58:14 +0000449 fListWidget.setCurrentRow(command);
450 }
451}
452
chudy@google.com902ebe52012-06-29 14:21:22 +0000453void SkDebuggerGUI::toggleBreakpoint() {
chudy@google.comc432f002012-07-10 13:19:25 +0000454 QListWidgetItem* item = fListWidget.currentItem();
chudy@google.com902ebe52012-06-29 14:21:22 +0000455 if (item->checkState() == Qt::Unchecked) {
456 item->setCheckState(Qt::Checked);
chudy@google.come565de42012-07-12 14:15:54 +0000457 item->setData(Qt::DecorationRole,
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000458 QPixmap(":/breakpoint_16x16.png"));
chudy@google.com902ebe52012-06-29 14:21:22 +0000459 } else {
chudy@google.com902ebe52012-06-29 14:21:22 +0000460 item->setCheckState(Qt::Unchecked);
chudy@google.come565de42012-07-12 14:15:54 +0000461 item->setData(Qt::DecorationRole,
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000462 QPixmap(":/blank.png"));
chudy@google.com902ebe52012-06-29 14:21:22 +0000463 }
464}
465
466void SkDebuggerGUI::toggleDirectory() {
chudy@google.com607357f2012-08-07 16:12:23 +0000467 fDirectoryWidget.setHidden(!fDirectoryWidget.isHidden());
chudy@google.com902ebe52012-06-29 14:21:22 +0000468}
469
470void SkDebuggerGUI::toggleFilter(QString string) {
chudy@google.comc432f002012-07-10 13:19:25 +0000471 for (int row = 0; row < fListWidget.count(); row++) {
472 QListWidgetItem *item = fListWidget.item(row);
chudy@google.com607357f2012-08-07 16:12:23 +0000473 item->setHidden(item->text() != string);
chudy@google.com902ebe52012-06-29 14:21:22 +0000474 }
475}
476
477void SkDebuggerGUI::setupUi(QMainWindow *SkDebuggerGUI) {
478 QIcon windowIcon;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000479 windowIcon.addFile(QString::fromUtf8(":/skia.png"), QSize(),
chudy@google.com7dcae672012-07-09 20:26:53 +0000480 QIcon::Normal, QIcon::Off);
chudy@google.com902ebe52012-06-29 14:21:22 +0000481 SkDebuggerGUI->setObjectName(QString::fromUtf8("SkDebuggerGUI"));
482 SkDebuggerGUI->resize(1200, 1000);
483 SkDebuggerGUI->setWindowIcon(windowIcon);
chudy@google.comc432f002012-07-10 13:19:25 +0000484 SkDebuggerGUI->setWindowTitle("Skia Debugger");
chudy@google.com902ebe52012-06-29 14:21:22 +0000485
chudy@google.come504de02012-07-16 18:35:23 +0000486 fActionOpen.setShortcuts(QKeySequence::Open);
chudy@google.comc432f002012-07-10 13:19:25 +0000487 fActionOpen.setText("Open");
chudy@google.com902ebe52012-06-29 14:21:22 +0000488
489 QIcon breakpoint;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000490 breakpoint.addFile(QString::fromUtf8(":/breakpoint.png"),
chudy@google.com7dcae672012-07-09 20:26:53 +0000491 QSize(), QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000492 fActionBreakpoint.setShortcut(QKeySequence(tr("Ctrl+B")));
chudy@google.comc432f002012-07-10 13:19:25 +0000493 fActionBreakpoint.setIcon(breakpoint);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000494 fActionBreakpoint.setText("Breakpoints");
kkinnunenf3a9e992015-01-05 01:14:11 -0800495 fActionBreakpoint.setCheckable(true);
chudy@google.com902ebe52012-06-29 14:21:22 +0000496
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000497 fActionToggleIndexStyle.setShortcut(QKeySequence(tr("Ctrl+T")));
498 fActionToggleIndexStyle.setText("Toggle Index Style");
kkinnunenf3a9e992015-01-05 01:14:11 -0800499 fActionToggleIndexStyle.setCheckable(true);
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000500
chudy@google.com902ebe52012-06-29 14:21:22 +0000501 QIcon cancel;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000502 cancel.addFile(QString::fromUtf8(":/reload.png"), QSize(),
chudy@google.com7dcae672012-07-09 20:26:53 +0000503 QIcon::Normal, QIcon::Off);
chudy@google.comc432f002012-07-10 13:19:25 +0000504 fActionCancel.setIcon(cancel);
505 fActionCancel.setText("Clear Filter");
chudy@google.com902ebe52012-06-29 14:21:22 +0000506
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000507 fActionClearBreakpoints.setShortcut(QKeySequence(tr("Alt+B")));
508 fActionClearBreakpoints.setText("Clear Breakpoints");
509
510 fActionClearDeletes.setShortcut(QKeySequence(tr("Alt+X")));
511 fActionClearDeletes.setText("Clear Deletes");
512
chudy@google.come504de02012-07-16 18:35:23 +0000513 fActionClose.setShortcuts(QKeySequence::Quit);
chudy@google.comc432f002012-07-10 13:19:25 +0000514 fActionClose.setText("Exit");
chudy@google.com902ebe52012-06-29 14:21:22 +0000515
chudy@google.come504de02012-07-16 18:35:23 +0000516 fActionCreateBreakpoint.setShortcut(QKeySequence(tr("B")));
517 fActionCreateBreakpoint.setText("Set Breakpoint");
518
519 fActionDelete.setShortcut(QKeySequence(tr("X")));
chudy@google.comc432f002012-07-10 13:19:25 +0000520 fActionDelete.setText("Delete Command");
chudy@google.com902ebe52012-06-29 14:21:22 +0000521
chudy@google.come504de02012-07-16 18:35:23 +0000522 fActionDirectory.setShortcut(QKeySequence(tr("Ctrl+D")));
523 fActionDirectory.setText("Directory");
chudy@google.com902ebe52012-06-29 14:21:22 +0000524
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000525 QIcon profile;
robertphillips@google.comd1636362012-11-19 18:25:09 +0000526 profile.addFile(QString::fromUtf8(":/profile.png"), QSize(),
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000527 QIcon::Normal, QIcon::Off);
528 fActionProfile.setIcon(profile);
529 fActionProfile.setText("Profile");
robertphillips@google.come099bc42012-11-19 16:26:40 +0000530 fActionProfile.setDisabled(true);
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000531
chudy@google.comc432f002012-07-10 13:19:25 +0000532 QIcon inspector;
robertphillips@google.comd1636362012-11-19 18:25:09 +0000533 inspector.addFile(QString::fromUtf8(":/inspector.png"),
chudy@google.comc432f002012-07-10 13:19:25 +0000534 QSize(), QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000535 fActionInspector.setShortcut(QKeySequence(tr("Ctrl+I")));
chudy@google.comc432f002012-07-10 13:19:25 +0000536 fActionInspector.setIcon(inspector);
chudy@google.come504de02012-07-16 18:35:23 +0000537 fActionInspector.setText("Inspector");
chudy@google.com902ebe52012-06-29 14:21:22 +0000538
bungeman@google.com2ff6d1d2013-07-01 14:24:12 +0000539 QIcon settings;
540 settings.addFile(QString::fromUtf8(":/inspector.png"),
541 QSize(), QIcon::Normal, QIcon::Off);
542 fActionSettings.setShortcut(QKeySequence(tr("Ctrl+G")));
543 fActionSettings.setIcon(settings);
544 fActionSettings.setText("Settings");
skia.committer@gmail.com0d55dd72013-07-02 07:00:59 +0000545
chudy@google.comc432f002012-07-10 13:19:25 +0000546 QIcon play;
robertphillips@google.comd1636362012-11-19 18:25:09 +0000547 play.addFile(QString::fromUtf8(":/play.png"), QSize(),
chudy@google.comc432f002012-07-10 13:19:25 +0000548 QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000549 fActionPlay.setShortcut(QKeySequence(tr("Ctrl+P")));
chudy@google.comc432f002012-07-10 13:19:25 +0000550 fActionPlay.setIcon(play);
551 fActionPlay.setText("Play");
chudy@google.com902ebe52012-06-29 14:21:22 +0000552
chudy@google.come504de02012-07-16 18:35:23 +0000553 QIcon pause;
robertphillips@google.comd1636362012-11-19 18:25:09 +0000554 pause.addFile(QString::fromUtf8(":/pause.png"), QSize(),
chudy@google.comc432f002012-07-10 13:19:25 +0000555 QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000556 fActionPause.setShortcut(QKeySequence(tr("Space")));
557 fActionPause.setCheckable(true);
558 fActionPause.setIcon(pause);
559 fActionPause.setText("Pause");
560
chudy@google.comc432f002012-07-10 13:19:25 +0000561 QIcon rewind;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000562 rewind.addFile(QString::fromUtf8(":/rewind.png"), QSize(),
chudy@google.comc432f002012-07-10 13:19:25 +0000563 QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000564 fActionRewind.setShortcut(QKeySequence(tr("Ctrl+R")));
chudy@google.comc432f002012-07-10 13:19:25 +0000565 fActionRewind.setIcon(rewind);
566 fActionRewind.setText("Rewind");
chudy@google.com902ebe52012-06-29 14:21:22 +0000567
chudy@google.com0ab03392012-07-28 20:16:11 +0000568 fActionSave.setShortcut(QKeySequence::Save);
569 fActionSave.setText("Save");
570 fActionSave.setDisabled(true);
571 fActionSaveAs.setShortcut(QKeySequence::SaveAs);
572 fActionSaveAs.setText("Save As");
573 fActionSaveAs.setDisabled(true);
574
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000575 fActionShowDeletes.setShortcut(QKeySequence(tr("Ctrl+X")));
576 fActionShowDeletes.setText("Deleted Commands");
kkinnunenf3a9e992015-01-05 01:14:11 -0800577 fActionShowDeletes.setCheckable(true);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000578
chudy@google.comc432f002012-07-10 13:19:25 +0000579 QIcon stepBack;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000580 stepBack.addFile(QString::fromUtf8(":/previous.png"), QSize(),
chudy@google.comc432f002012-07-10 13:19:25 +0000581 QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000582 fActionStepBack.setShortcut(QKeySequence(tr("[")));
chudy@google.comc432f002012-07-10 13:19:25 +0000583 fActionStepBack.setIcon(stepBack);
584 fActionStepBack.setText("Step Back");
chudy@google.com902ebe52012-06-29 14:21:22 +0000585
chudy@google.comc432f002012-07-10 13:19:25 +0000586 QIcon stepForward;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000587 stepForward.addFile(QString::fromUtf8(":/next.png"),
chudy@google.comc432f002012-07-10 13:19:25 +0000588 QSize(), QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000589 fActionStepForward.setShortcut(QKeySequence(tr("]")));
chudy@google.comc432f002012-07-10 13:19:25 +0000590 fActionStepForward.setIcon(stepForward);
591 fActionStepForward.setText("Step Forward");
592
chudy@google.coma1226312012-07-26 20:26:44 +0000593 fActionZoomIn.setShortcut(QKeySequence(tr("Ctrl+=")));
594 fActionZoomIn.setText("Zoom In");
595 fActionZoomOut.setShortcut(QKeySequence(tr("Ctrl+-")));
596 fActionZoomOut.setText("Zoom Out");
597
chudy@google.comc432f002012-07-10 13:19:25 +0000598 fListWidget.setItemDelegate(new SkListWidget(&fListWidget));
599 fListWidget.setObjectName(QString::fromUtf8("listWidget"));
commit-bot@chromium.orgbcd431e2013-11-21 13:41:37 +0000600 fListWidget.setMinimumWidth(250);
chudy@google.comc432f002012-07-10 13:19:25 +0000601
602 fFilter.addItem("--Filter By Available Commands--");
603
commit-bot@chromium.orgbcd431e2013-11-21 13:41:37 +0000604 fDirectoryWidget.setMinimumWidth(250);
chudy@google.comc432f002012-07-10 13:19:25 +0000605 fDirectoryWidget.setStyleSheet("QListWidget::Item {padding: 5px;}");
606
607 fCanvasWidget.setSizePolicy(QSizePolicy::Expanding,
chudy@google.com7dcae672012-07-09 20:26:53 +0000608 QSizePolicy::Expanding);
chudy@google.com902ebe52012-06-29 14:21:22 +0000609
kkinnunen63a47022014-12-30 23:03:56 -0800610 fDrawCommandGeometryWidget.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000611
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000612 fSettingsAndImageLayout.addWidget(&fSettingsWidget);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000613
kkinnunen41c79cc2014-12-30 22:49:58 -0800614 // View state group, part of inspector.
615 fViewStateFrame.setFrameStyle(QFrame::Panel);
616 fViewStateFrame.setLayout(&fViewStateFrameLayout);
617 fViewStateFrameLayout.addWidget(&fViewStateGroup);
kkinnunen63a47022014-12-30 23:03:56 -0800618 fViewStateGroup.setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
kkinnunen41c79cc2014-12-30 22:49:58 -0800619 fViewStateGroup.setTitle("View");
620 fViewStateLayout.addRow("Zoom Level", &fZoomBox);
621 fZoomBox.setText("100%");
622 fZoomBox.setMinimumSize(QSize(50,25));
623 fZoomBox.setMaximumSize(QSize(50,25));
624 fZoomBox.setAlignment(Qt::AlignRight);
625 fZoomBox.setReadOnly(true);
626 fViewStateLayout.addRow("Command HitBox", &fCommandHitBox);
627 fCommandHitBox.setText("0");
628 fCommandHitBox.setMinimumSize(QSize(50,25));
629 fCommandHitBox.setMaximumSize(QSize(50,25));
630 fCommandHitBox.setAlignment(Qt::AlignRight);
631 fCommandHitBox.setReadOnly(true);
632 fViewStateLayout.addRow("Current Command", &fCurrentCommandBox);
633 fCurrentCommandBox.setText("0");
634 fCurrentCommandBox.setMinimumSize(QSize(50,25));
635 fCurrentCommandBox.setMaximumSize(QSize(50,25));
636 fCurrentCommandBox.setAlignment(Qt::AlignRight);
637 fCurrentCommandBox.setReadOnly(true);
638 fViewStateGroup.setLayout(&fViewStateLayout);
639 fSettingsAndImageLayout.addWidget(&fViewStateFrame);
640
kkinnunen63a47022014-12-30 23:03:56 -0800641 fDrawCommandGeometryWidget.setToolTip("Current Command Geometry");
642 fSettingsAndImageLayout.addWidget(&fDrawCommandGeometryWidget);
chudy@google.com902ebe52012-06-29 14:21:22 +0000643
commit-bot@chromium.orgbcd431e2013-11-21 13:41:37 +0000644 fLeftColumnSplitter.addWidget(&fListWidget);
645 fLeftColumnSplitter.addWidget(&fDirectoryWidget);
646 fLeftColumnSplitter.setOrientation(Qt::Vertical);
chudy@google.com902ebe52012-06-29 14:21:22 +0000647
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000648 fCanvasSettingsAndImageLayout.setSpacing(6);
kkinnunen41c79cc2014-12-30 22:49:58 -0800649 fCanvasSettingsAndImageLayout.addWidget(&fCanvasWidget, 1);
650 fCanvasSettingsAndImageLayout.addLayout(&fSettingsAndImageLayout, 0);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000651
chudy@google.comc432f002012-07-10 13:19:25 +0000652 fMainAndRightColumnLayout.setSpacing(6);
kkinnunen7c339ae2015-01-02 06:35:43 -0800653 fMainAndRightColumnLayout.addLayout(&fCanvasSettingsAndImageLayout, 1);
654 fMainAndRightColumnLayout.addWidget(&fInspectorWidget, 0);
commit-bot@chromium.orgbcd431e2013-11-21 13:41:37 +0000655 fMainAndRightColumnWidget.setLayout(&fMainAndRightColumnLayout);
chudy@google.com902ebe52012-06-29 14:21:22 +0000656
commit-bot@chromium.orgbcd431e2013-11-21 13:41:37 +0000657 fCentralSplitter.addWidget(&fLeftColumnSplitter);
658 fCentralSplitter.addWidget(&fMainAndRightColumnWidget);
659 fCentralSplitter.setStretchFactor(0, 0);
660 fCentralSplitter.setStretchFactor(1, 1);
chudy@google.comc432f002012-07-10 13:19:25 +0000661
commit-bot@chromium.orgbcd431e2013-11-21 13:41:37 +0000662 SkDebuggerGUI->setCentralWidget(&fCentralSplitter);
chudy@google.comc432f002012-07-10 13:19:25 +0000663 SkDebuggerGUI->setStatusBar(&fStatusBar);
664
chudy@google.come504de02012-07-16 18:35:23 +0000665 fToolBar.setIconSize(QSize(32, 32));
chudy@google.comc432f002012-07-10 13:19:25 +0000666 fToolBar.setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
667 SkDebuggerGUI->addToolBar(Qt::TopToolBarArea, &fToolBar);
chudy@google.com902ebe52012-06-29 14:21:22 +0000668
chudy@google.com0ab03392012-07-28 20:16:11 +0000669 fSpacer.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
chudy@google.com902ebe52012-06-29 14:21:22 +0000670
chudy@google.comc432f002012-07-10 13:19:25 +0000671 fToolBar.addAction(&fActionRewind);
672 fToolBar.addAction(&fActionStepBack);
chudy@google.come504de02012-07-16 18:35:23 +0000673 fToolBar.addAction(&fActionPause);
chudy@google.comc432f002012-07-10 13:19:25 +0000674 fToolBar.addAction(&fActionStepForward);
675 fToolBar.addAction(&fActionPlay);
676 fToolBar.addSeparator();
chudy@google.come504de02012-07-16 18:35:23 +0000677 fToolBar.addAction(&fActionInspector);
bungeman@google.com2ff6d1d2013-07-01 14:24:12 +0000678 fToolBar.addAction(&fActionSettings);
chudy@google.comc432f002012-07-10 13:19:25 +0000679 fToolBar.addSeparator();
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000680 fToolBar.addAction(&fActionProfile);
681
682 fToolBar.addSeparator();
chudy@google.com0ab03392012-07-28 20:16:11 +0000683 fToolBar.addWidget(&fSpacer);
chudy@google.comc432f002012-07-10 13:19:25 +0000684 fToolBar.addWidget(&fFilter);
685 fToolBar.addAction(&fActionCancel);
chudy@google.com902ebe52012-06-29 14:21:22 +0000686
687 // TODO(chudy): Remove static call.
688 fDirectoryWidgetActive = false;
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000689 fFileName = "";
robertphillips@google.comff6e6ba2013-01-28 17:43:26 +0000690 setupDirectoryWidget("");
chudy@google.com902ebe52012-06-29 14:21:22 +0000691 fDirectoryWidgetActive = true;
692
chudy@google.com902ebe52012-06-29 14:21:22 +0000693 // Menu Bar
chudy@google.comc432f002012-07-10 13:19:25 +0000694 fMenuFile.setTitle("File");
695 fMenuFile.addAction(&fActionOpen);
chudy@google.com0ab03392012-07-28 20:16:11 +0000696 fMenuFile.addAction(&fActionSave);
697 fMenuFile.addAction(&fActionSaveAs);
chudy@google.comc432f002012-07-10 13:19:25 +0000698 fMenuFile.addAction(&fActionClose);
chudy@google.come504de02012-07-16 18:35:23 +0000699
700 fMenuEdit.setTitle("Edit");
701 fMenuEdit.addAction(&fActionDelete);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000702 fMenuEdit.addAction(&fActionClearDeletes);
703 fMenuEdit.addSeparator();
chudy@google.come504de02012-07-16 18:35:23 +0000704 fMenuEdit.addAction(&fActionCreateBreakpoint);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000705 fMenuEdit.addAction(&fActionClearBreakpoints);
chudy@google.come504de02012-07-16 18:35:23 +0000706
chudy@google.comc432f002012-07-10 13:19:25 +0000707 fMenuNavigate.setTitle("Navigate");
chudy@google.come504de02012-07-16 18:35:23 +0000708 fMenuNavigate.addAction(&fActionRewind);
709 fMenuNavigate.addAction(&fActionStepBack);
710 fMenuNavigate.addAction(&fActionStepForward);
711 fMenuNavigate.addAction(&fActionPlay);
712 fMenuNavigate.addAction(&fActionPause);
chudy@google.comc432f002012-07-10 13:19:25 +0000713 fMenuNavigate.addAction(&fActionGoToLine);
chudy@google.come504de02012-07-16 18:35:23 +0000714
chudy@google.comc432f002012-07-10 13:19:25 +0000715 fMenuView.setTitle("View");
chudy@google.come504de02012-07-16 18:35:23 +0000716 fMenuView.addAction(&fActionBreakpoint);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000717 fMenuView.addAction(&fActionShowDeletes);
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000718 fMenuView.addAction(&fActionToggleIndexStyle);
chudy@google.coma1226312012-07-26 20:26:44 +0000719 fMenuView.addAction(&fActionZoomIn);
720 fMenuView.addAction(&fActionZoomOut);
chudy@google.come504de02012-07-16 18:35:23 +0000721
722 fMenuWindows.setTitle("Window");
723 fMenuWindows.addAction(&fActionInspector);
bungeman@google.com2ff6d1d2013-07-01 14:24:12 +0000724 fMenuWindows.addAction(&fActionSettings);
chudy@google.come504de02012-07-16 18:35:23 +0000725 fMenuWindows.addAction(&fActionDirectory);
chudy@google.comc432f002012-07-10 13:19:25 +0000726
727 fActionGoToLine.setText("Go to Line...");
728 fActionGoToLine.setDisabled(true);
729 fMenuBar.addAction(fMenuFile.menuAction());
chudy@google.come504de02012-07-16 18:35:23 +0000730 fMenuBar.addAction(fMenuEdit.menuAction());
chudy@google.comc432f002012-07-10 13:19:25 +0000731 fMenuBar.addAction(fMenuView.menuAction());
732 fMenuBar.addAction(fMenuNavigate.menuAction());
chudy@google.come504de02012-07-16 18:35:23 +0000733 fMenuBar.addAction(fMenuWindows.menuAction());
chudy@google.com902ebe52012-06-29 14:21:22 +0000734
chudy@google.comc432f002012-07-10 13:19:25 +0000735 SkDebuggerGUI->setMenuBar(&fMenuBar);
chudy@google.com902ebe52012-06-29 14:21:22 +0000736 QMetaObject::connectSlotsByName(SkDebuggerGUI);
737}
738
robertphillips@google.comff6e6ba2013-01-28 17:43:26 +0000739void SkDebuggerGUI::setupDirectoryWidget(const QString& path) {
740 fPath = path;
741 QDir dir(path);
chudy@google.com902ebe52012-06-29 14:21:22 +0000742 QRegExp r(".skp");
chudy@google.comc432f002012-07-10 13:19:25 +0000743 fDirectoryWidget.clear();
744 const QStringList files = dir.entryList();
chudy@google.com902ebe52012-06-29 14:21:22 +0000745 foreach (QString f, files) {
chudy@google.com7dcae672012-07-09 20:26:53 +0000746 if (f.contains(r))
chudy@google.comc432f002012-07-10 13:19:25 +0000747 fDirectoryWidget.addItem(f);
chudy@google.com902ebe52012-06-29 14:21:22 +0000748 }
749}
750
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000751void SkDebuggerGUI::loadPicture(const SkString& fileName) {
752 fFileName = fileName;
chudy@google.comd3058f52012-07-19 13:41:27 +0000753 fLoading = true;
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000754 SkStream* stream = SkNEW_ARGS(SkFILEStream, (fileName.c_str()));
robertphillips@google.com2d40ec42013-02-07 20:39:40 +0000755
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000756 SkPicture* picture = SkPicture::CreateFromStream(stream);
robertphillips@google.com2d40ec42013-02-07 20:39:40 +0000757
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000758 if (NULL == picture) {
robertphillips@google.com2d40ec42013-02-07 20:39:40 +0000759 QMessageBox::critical(this, "Error loading file", "Couldn't read file, sorry.");
760 SkSafeUnref(stream);
761 return;
762 }
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000763
chudy@google.com686e6802012-08-14 16:00:32 +0000764 fCanvasWidget.resetWidgetTransform();
chudy@google.com607357f2012-08-07 16:12:23 +0000765 fDebugger.loadPicture(picture);
chudy@google.com4c7962e2012-08-14 19:38:31 +0000766
robertphillips@google.com6d9c92b2013-05-23 13:21:18 +0000767 fSkipCommands.setCount(fDebugger.getSize());
768 for (int i = 0; i < fSkipCommands.count(); ++i) {
robertphillips@google.com5f971142012-12-07 20:48:56 +0000769 fSkipCommands[i] = false;
770 }
771
chudy@google.com607357f2012-08-07 16:12:23 +0000772 SkSafeUnref(stream);
773 SkSafeUnref(picture);
774
robertphillips@google.com6d9c92b2013-05-23 13:21:18 +0000775 fActionProfile.setDisabled(false);
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000776
chudy@google.com7dcae672012-07-09 20:26:53 +0000777 /* fDebugCanvas is reinitialized every load picture. Need it to retain value
chudy@google.com607357f2012-08-07 16:12:23 +0000778 * of the visibility filter.
779 * TODO(chudy): This should be deprecated since fDebugger is not
780 * recreated.
781 * */
kkinnunen41c79cc2014-12-30 22:49:58 -0800782 fDebugger.highlightCurrentCommand(fSettingsWidget.isVisibilityFilterEnabled());
chudy@google.com607357f2012-08-07 16:12:23 +0000783
kkinnunen5037e9d2014-12-30 07:22:58 -0800784 this->setupListWidget();
785 this->setupComboBox();
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000786 this->setupOverviewText(NULL, 0.0, 1);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000787 fInspectorWidget.setDisabled(false);
kkinnunen41c79cc2014-12-30 22:49:58 -0800788 fViewStateFrame.setDisabled(false);
chudy@google.come606d6e2012-07-12 14:31:25 +0000789 fSettingsWidget.setDisabled(false);
chudy@google.comd3058f52012-07-19 13:41:27 +0000790 fMenuEdit.setDisabled(false);
791 fMenuNavigate.setDisabled(false);
792 fMenuView.setDisabled(false);
chudy@google.com0ab03392012-07-28 20:16:11 +0000793 fActionSave.setDisabled(false);
794 fActionSaveAs.setDisabled(false);
kkinnunenf3a9e992015-01-05 01:14:11 -0800795 fActionPause.setChecked(false);
kkinnunen0cfeaf32015-01-07 07:33:46 -0800796 fDrawCommandGeometryWidget.setDrawCommandIndex(-1);
797
chudy@google.comd3058f52012-07-19 13:41:27 +0000798 fLoading = false;
799 actionPlay();
chudy@google.com902ebe52012-06-29 14:21:22 +0000800}
801
kkinnunen5037e9d2014-12-30 07:22:58 -0800802void SkDebuggerGUI::setupListWidget() {
chudy@google.comc432f002012-07-10 13:19:25 +0000803 fListWidget.clear();
chudy@google.com902ebe52012-06-29 14:21:22 +0000804 int counter = 0;
robertphillips@google.com30d35f22012-11-06 16:45:36 +0000805 int indent = 0;
kkinnunen5037e9d2014-12-30 07:22:58 -0800806 for (int i = 0; i < fDebugger.getSize(); i++) {
chudy@google.com902ebe52012-06-29 14:21:22 +0000807 QListWidgetItem *item = new QListWidgetItem();
kkinnunen5037e9d2014-12-30 07:22:58 -0800808 SkDrawCommand* command = fDebugger.getDrawCommandAt(i);
809 SkString commandString = command->toString();
810 item->setData(Qt::DisplayRole, commandString.c_str());
chudy@google.com902ebe52012-06-29 14:21:22 +0000811 item->setData(Qt::UserRole + 1, counter++);
robertphillips@google.com30d35f22012-11-06 16:45:36 +0000812
kkinnunen5037e9d2014-12-30 07:22:58 -0800813 if (0 == strcmp("Restore", commandString.c_str()) ||
814 0 == strcmp("EndCommentGroup", commandString.c_str())) {
robertphillips@google.com30d35f22012-11-06 16:45:36 +0000815 indent -= 10;
816 }
817
818 item->setData(Qt::UserRole + 3, indent);
819
kkinnunen5037e9d2014-12-30 07:22:58 -0800820 if (0 == strcmp("Save", commandString.c_str()) ||
821 0 == strcmp("Save Layer", commandString.c_str()) ||
822 0 == strcmp("BeginCommentGroup", commandString.c_str())) {
robertphillips@google.com30d35f22012-11-06 16:45:36 +0000823 indent += 10;
824 }
825
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000826 item->setData(Qt::UserRole + 4, -1);
kkinnunen5037e9d2014-12-30 07:22:58 -0800827 item->setData(Qt::UserRole + 5, (int) command->offset());
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000828
chudy@google.comc432f002012-07-10 13:19:25 +0000829 fListWidget.addItem(item);
chudy@google.com902ebe52012-06-29 14:21:22 +0000830 }
831}
832
skia.committer@gmail.com91274b92013-03-13 07:01:04 +0000833void SkDebuggerGUI::setupOverviewText(const SkTDArray<double>* typeTimes,
robertphillips@google.come428f9b2013-03-12 15:33:40 +0000834 double totTime,
835 int numRuns) {
borenet@google.com2d9dbd42013-03-12 13:07:40 +0000836 SkString overview;
robertphillips@google.come428f9b2013-03-12 15:33:40 +0000837 fDebugger.getOverviewText(typeTimes, totTime, &overview, numRuns);
borenet@google.com2d9dbd42013-03-12 13:07:40 +0000838 fInspectorWidget.setText(overview.c_str(), SkInspectorWidget::kOverview_TabType);
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000839}
840
commit-bot@chromium.org2a67e122014-05-19 13:53:10 +0000841
kkinnunen5037e9d2014-12-30 07:22:58 -0800842void SkDebuggerGUI::setupComboBox() {
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000843 fFilter.clear();
844 fFilter.addItem("--Filter By Available Commands--");
845
846 std::map<std::string, int> map;
kkinnunen5037e9d2014-12-30 07:22:58 -0800847 for (int i = 0; i < fDebugger.getSize(); i++) {
848 map[fDebugger.getDrawCommandAt(i)->toString().c_str()]++;
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000849 }
850
skia.committer@gmail.com34587162012-11-20 02:01:23 +0000851 for (std::map<std::string, int>::iterator it = map.begin(); it != map.end();
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000852 ++it) {
853 fFilter.addItem((it->first).c_str());
854 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000855
856 // NOTE(chudy): Makes first item unselectable.
chudy@google.com7dcae672012-07-09 20:26:53 +0000857 QStandardItemModel* model = qobject_cast<QStandardItemModel*>(
chudy@google.comc432f002012-07-10 13:19:25 +0000858 fFilter.model());
859 QModelIndex firstIndex = model->index(0, fFilter.modelColumn(),
860 fFilter.rootModelIndex());
chudy@google.com902ebe52012-06-29 14:21:22 +0000861 QStandardItem* firstItem = model->itemFromIndex(firstIndex);
862 firstItem->setSelectable(false);
863}
kkinnunen41c79cc2014-12-30 22:49:58 -0800864
kkinnunen41c79cc2014-12-30 22:49:58 -0800865void SkDebuggerGUI::updateHit(int newHit) {
866 fCommandHitBox.setText(QString::number(newHit));
867}
868