blob: b6920a7b3eb46e32e4be10be6dcefad4b9a44284 [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.combbad34d2012-08-13 14:26:36 +000010#include "SkGraphics.h"
scroggo@google.comb4467e62012-11-06 23:10:09 +000011#include "SkImageDecoder.h"
chudy@google.com902ebe52012-06-29 14:21:22 +000012#include <QListWidgetItem>
robertphillips@google.com2bde91d2012-11-15 14:57:57 +000013#include "PictureRenderer.h"
robertphillipsce4dd3d2014-07-07 13:46:35 -070014#include "SkPicturePlayback.h"
robertphillips@google.com2bde91d2012-11-15 14:57:57 +000015#include "SkPictureRecord.h"
robertphillipsdb539902014-07-01 08:47:04 -070016#include "SkPictureData.h"
robertphillips@google.come174a8b2012-11-27 16:04:42 +000017
scroggo@google.com7def5e12013-05-31 14:00:10 +000018__SK_FORCE_IMAGE_DECODER_LINKING;
19
robertphillips@google.come174a8b2012-11-27 16:04:42 +000020#if defined(SK_BUILD_FOR_WIN32)
mtklein9ac68ee2014-06-20 11:29:20 -070021 #include "SysTimer_windows.h"
robertphillips@google.come174a8b2012-11-27 16:04:42 +000022#elif defined(SK_BUILD_FOR_MAC)
mtklein9ac68ee2014-06-20 11:29:20 -070023 #include "SysTimer_mach.h"
robertphillips@google.come174a8b2012-11-27 16:04:42 +000024#elif defined(SK_BUILD_FOR_UNIX) || defined(SK_BUILD_FOR_ANDROID)
mtklein9ac68ee2014-06-20 11:29:20 -070025 #include "SysTimer_posix.h"
robertphillips@google.come174a8b2012-11-27 16:04:42 +000026#else
mtklein9ac68ee2014-06-20 11:29:20 -070027 #include "SysTimer_c.h"
robertphillips@google.come174a8b2012-11-27 16:04:42 +000028#endif
29
chudy@google.com902ebe52012-06-29 14:21:22 +000030
31SkDebuggerGUI::SkDebuggerGUI(QWidget *parent) :
chudy@google.comc432f002012-07-10 13:19:25 +000032 QMainWindow(parent)
commit-bot@chromium.orgbcd431e2013-11-21 13:41:37 +000033 , fCentralSplitter(this)
chudy@google.com2d537a12012-07-31 12:49:52 +000034 , fStatusBar(this)
35 , fToolBar(this)
chudy@google.comc432f002012-07-10 13:19:25 +000036 , fActionOpen(this)
37 , fActionBreakpoint(this)
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +000038 , fActionToggleIndexStyle(this)
robertphillips@google.comd26c7062012-11-12 20:42:12 +000039 , fActionProfile(this)
chudy@google.comc432f002012-07-10 13:19:25 +000040 , fActionCancel(this)
chudy@google.com7e4cfbf2012-07-17 15:40:51 +000041 , fActionClearBreakpoints(this)
chudy@google.come504de02012-07-16 18:35:23 +000042 , fActionClearDeletes(this)
chudy@google.comc432f002012-07-10 13:19:25 +000043 , fActionClose(this)
chudy@google.come504de02012-07-16 18:35:23 +000044 , fActionCreateBreakpoint(this)
chudy@google.comc432f002012-07-10 13:19:25 +000045 , fActionDelete(this)
46 , fActionDirectory(this)
47 , fActionGoToLine(this)
48 , fActionInspector(this)
bungeman@google.com2ff6d1d2013-07-01 14:24:12 +000049 , fActionSettings(this)
chudy@google.comc432f002012-07-10 13:19:25 +000050 , fActionPlay(this)
chudy@google.come504de02012-07-16 18:35:23 +000051 , fActionPause(this)
chudy@google.comc432f002012-07-10 13:19:25 +000052 , fActionRewind(this)
chudy@google.com0ab03392012-07-28 20:16:11 +000053 , fActionSave(this)
54 , fActionSaveAs(this)
chudy@google.com7e4cfbf2012-07-17 15:40:51 +000055 , fActionShowDeletes(this)
chudy@google.comc432f002012-07-10 13:19:25 +000056 , fActionStepBack(this)
57 , fActionStepForward(this)
chudy@google.coma1226312012-07-26 20:26:44 +000058 , fActionZoomIn(this)
59 , fActionZoomOut(this)
60 , fMapper(this)
commit-bot@chromium.orgbcd431e2013-11-21 13:41:37 +000061 , fListWidget(&fCentralSplitter)
62 , fDirectoryWidget(&fCentralSplitter)
chudy@google.com607357f2012-08-07 16:12:23 +000063 , fCanvasWidget(this, &fDebugger)
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +000064 , fImageWidget(&fDebugger)
chudy@google.comc432f002012-07-10 13:19:25 +000065 , fMenuBar(this)
66 , fMenuFile(this)
67 , fMenuNavigate(this)
68 , fMenuView(this)
chudy@google.com7e4cfbf2012-07-17 15:40:51 +000069 , fBreakpointsActivated(false)
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +000070 , fIndexStyleToggle(false)
chudy@google.com7e4cfbf2012-07-17 15:40:51 +000071 , fDeletesActivated(false)
72 , fPause(false)
chudy@google.comd3058f52012-07-19 13:41:27 +000073 , fLoading(false)
chudy@google.comc432f002012-07-10 13:19:25 +000074{
chudy@google.com902ebe52012-06-29 14:21:22 +000075 setupUi(this);
robertphillips@google.comdd4b7452013-01-22 19:38:46 +000076 fListWidget.setSelectionMode(QAbstractItemView::ExtendedSelection);
chudy@google.comea5488b2012-07-26 19:38:22 +000077 connect(&fListWidget, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)), this, SLOT(registerListClick(QListWidgetItem *)));
chudy@google.comc432f002012-07-10 13:19:25 +000078 connect(&fActionOpen, SIGNAL(triggered()), this, SLOT(openFile()));
chudy@google.comea5488b2012-07-26 19:38:22 +000079 connect(&fActionDirectory, SIGNAL(triggered()), this, SLOT(toggleDirectory()));
80 connect(&fDirectoryWidget, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)), this, SLOT(loadFile(QListWidgetItem *)));
chudy@google.comc432f002012-07-10 13:19:25 +000081 connect(&fActionDelete, SIGNAL(triggered()), this, SLOT(actionDelete()));
chudy@google.comea5488b2012-07-26 19:38:22 +000082 connect(&fListWidget, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(toggleBreakpoint()));
chudy@google.comc432f002012-07-10 13:19:25 +000083 connect(&fActionRewind, SIGNAL(triggered()), this, SLOT(actionRewind()));
84 connect(&fActionPlay, SIGNAL(triggered()), this, SLOT(actionPlay()));
85 connect(&fActionStepBack, SIGNAL(triggered()), this, SLOT(actionStepBack()));
chudy@google.comea5488b2012-07-26 19:38:22 +000086 connect(&fActionStepForward, SIGNAL(triggered()), this, SLOT(actionStepForward()));
87 connect(&fActionBreakpoint, SIGNAL(triggered()), this, SLOT(actionBreakpoints()));
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +000088 connect(&fActionToggleIndexStyle, SIGNAL(triggered()), this, SLOT(actionToggleIndexStyle()));
chudy@google.comea5488b2012-07-26 19:38:22 +000089 connect(&fActionInspector, SIGNAL(triggered()), this, SLOT(actionInspector()));
bungeman@google.com2ff6d1d2013-07-01 14:24:12 +000090 connect(&fActionSettings, SIGNAL(triggered()), this, SLOT(actionSettings()));
chudy@google.comea5488b2012-07-26 19:38:22 +000091 connect(&fFilter, SIGNAL(activated(QString)), this, SLOT(toggleFilter(QString)));
robertphillips@google.comd26c7062012-11-12 20:42:12 +000092 connect(&fActionProfile, SIGNAL(triggered()), this, SLOT(actionProfile()));
chudy@google.comc432f002012-07-10 13:19:25 +000093 connect(&fActionCancel, SIGNAL(triggered()), this, SLOT(actionCancel()));
chudy@google.com7e4cfbf2012-07-17 15:40:51 +000094 connect(&fActionClearBreakpoints, SIGNAL(triggered()), this, SLOT(actionClearBreakpoints()));
95 connect(&fActionClearDeletes, SIGNAL(triggered()), this, SLOT(actionClearDeletes()));
chudy@google.comc432f002012-07-10 13:19:25 +000096 connect(&fActionClose, SIGNAL(triggered()), this, SLOT(actionClose()));
commit-bot@chromium.org22d39332013-11-21 15:37:29 +000097 connect(&fSettingsWidget, SIGNAL(visibilityFilterChanged()), this, SLOT(actionCommandFilter()));
robertphillips@google.come8fe4bc2013-02-13 13:26:13 +000098#if SK_SUPPORT_GPU
commit-bot@chromium.orgfde1e7c2013-08-02 13:59:50 +000099 connect(&fSettingsWidget, SIGNAL(glSettingsChanged()), this, SLOT(actionGLWidget()));
robertphillips@google.come8fe4bc2013-02-13 13:26:13 +0000100#endif
robertphillips@google.com32bbcf82013-10-17 17:56:10 +0000101 connect(&fSettingsWidget, SIGNAL(texFilterSettingsChanged()), this, SLOT(actionTextureFilter()));
chudy@google.comea5488b2012-07-26 19:38:22 +0000102 connect(fSettingsWidget.getRasterCheckBox(), SIGNAL(toggled(bool)), this, SLOT(actionRasterWidget(bool)));
robertphillips@google.comf4741c12013-02-06 20:13:54 +0000103 connect(fSettingsWidget.getOverdrawVizCheckBox(), SIGNAL(toggled(bool)), this, SLOT(actionOverdrawVizWidget(bool)));
commit-bot@chromium.org768ac852014-03-03 16:32:17 +0000104 connect(fSettingsWidget.getMegaVizCheckBox(), SIGNAL(toggled(bool)), this, SLOT(actionMegaVizWidget(bool)));
commit-bot@chromium.org2a67e122014-05-19 13:53:10 +0000105 connect(fSettingsWidget.getPathOpsCheckBox(), SIGNAL(toggled(bool)), this, SLOT(actionPathOpsWidget(bool)));
chudy@google.comea5488b2012-07-26 19:38:22 +0000106 connect(&fActionPause, SIGNAL(toggled(bool)), this, SLOT(pauseDrawing(bool)));
chudy@google.come504de02012-07-16 18:35:23 +0000107 connect(&fActionCreateBreakpoint, SIGNAL(activated()), this, SLOT(toggleBreakpoint()));
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000108 connect(&fActionShowDeletes, SIGNAL(triggered()), this, SLOT(showDeletes()));
chudy@google.comea5488b2012-07-26 19:38:22 +0000109 connect(&fCanvasWidget, SIGNAL(hitChanged(int)), this, SLOT(selectCommand(int)));
110 connect(&fCanvasWidget, SIGNAL(hitChanged(int)), &fSettingsWidget, SLOT(updateHit(int)));
111 connect(&fCanvasWidget, SIGNAL(scaleFactorChanged(float)), this, SLOT(actionScale(float)));
112 connect(&fCanvasWidget, SIGNAL(commandChanged(int)), &fSettingsWidget, SLOT(updateCommand(int)));
chudy@google.com0ab03392012-07-28 20:16:11 +0000113 connect(&fActionSaveAs, SIGNAL(triggered()), this, SLOT(actionSaveAs()));
114 connect(&fActionSave, SIGNAL(triggered()), this, SLOT(actionSave()));
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000115
bungeman@google.come8cc6e82013-01-17 16:30:56 +0000116 fMapper.setMapping(&fActionZoomIn, SkCanvasWidget::kIn_ZoomCommand);
117 fMapper.setMapping(&fActionZoomOut, SkCanvasWidget::kOut_ZoomCommand);
chudy@google.coma1226312012-07-26 20:26:44 +0000118
119 connect(&fActionZoomIn, SIGNAL(triggered()), &fMapper, SLOT(map()));
120 connect(&fActionZoomOut, SIGNAL(triggered()), &fMapper, SLOT(map()));
bungeman@google.come8cc6e82013-01-17 16:30:56 +0000121 connect(&fMapper, SIGNAL(mapped(int)), &fCanvasWidget, SLOT(zoom(int)));
chudy@google.coma1226312012-07-26 20:26:44 +0000122
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000123 fInspectorWidget.setDisabled(true);
chudy@google.comd3058f52012-07-19 13:41:27 +0000124 fMenuEdit.setDisabled(true);
125 fMenuNavigate.setDisabled(true);
126 fMenuView.setDisabled(true);
chudy@google.combbad34d2012-08-13 14:26:36 +0000127
128 SkGraphics::Init();
chudy@google.com902ebe52012-06-29 14:21:22 +0000129}
130
chudy@google.combbad34d2012-08-13 14:26:36 +0000131SkDebuggerGUI::~SkDebuggerGUI() {
132 SkGraphics::Term();
133}
chudy@google.com902ebe52012-06-29 14:21:22 +0000134
135void SkDebuggerGUI::actionBreakpoints() {
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000136 fBreakpointsActivated = !fBreakpointsActivated;
chudy@google.comc432f002012-07-10 13:19:25 +0000137 for (int row = 0; row < fListWidget.count(); row++) {
138 QListWidgetItem *item = fListWidget.item(row);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000139 item->setHidden(item->checkState() == Qt::Unchecked && fBreakpointsActivated);
140 }
141}
chudy@google.com902ebe52012-06-29 14:21:22 +0000142
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000143void SkDebuggerGUI::actionToggleIndexStyle() {
144 fIndexStyleToggle = !fIndexStyleToggle;
145 SkListWidget* list = (SkListWidget*) fListWidget.itemDelegate();
skia.committer@gmail.comdb35dab2014-03-27 03:02:48 +0000146 list->setIndexStyle(fIndexStyleToggle ? SkListWidget::kIndex_IndexStyle :
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000147 SkListWidget::kOffset_IndexStyle);
148 fListWidget.update();
149}
150
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000151void SkDebuggerGUI::showDeletes() {
152 fDeletesActivated = !fDeletesActivated;
153 for (int row = 0; row < fListWidget.count(); row++) {
154 QListWidgetItem *item = fListWidget.item(row);
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000155 item->setHidden(fDebugger.isCommandVisible(row) && fDeletesActivated);
chudy@google.com902ebe52012-06-29 14:21:22 +0000156 }
157}
158
robertphillipsdb539902014-07-01 08:47:04 -0700159// The timed picture playback uses the SkPictureData's profiling stubs
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000160// to time individual commands. The offsets are needed to map SkPicture
161// offsets to individual commands.
robertphillipsce4dd3d2014-07-07 13:46:35 -0700162class SkTimedPicturePlayback : public SkPicturePlayback {
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000163public:
scroggo@google.com12705322013-10-01 15:30:46 +0000164
robertphillipsce4dd3d2014-07-07 13:46:35 -0700165 SkTimedPicturePlayback(const SkPicture* picture, const SkTDArray<bool>& deletedCommands)
166 : INHERITED(picture)
bungeman@google.come8cc6e82013-01-17 16:30:56 +0000167 , fSkipCommands(deletedCommands)
168 , fTot(0.0)
169 , fCurCommand(0) {
robertphillips@google.com6d9c92b2013-05-23 13:21:18 +0000170 fTimes.setCount(deletedCommands.count());
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000171 fTypeTimes.setCount(LAST_DRAWTYPE_ENUM+1);
172 this->resetTimes();
173 }
174
175 void resetTimes() {
robertphillips@google.com6d9c92b2013-05-23 13:21:18 +0000176 for (int i = 0; i < fTimes.count(); ++i) {
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000177 fTimes[i] = 0.0;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000178 }
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000179 for (int i = 0; i < fTypeTimes.count(); ++i) {
180 fTypeTimes[i] = 0.0f;
181 }
182 fTot = 0.0;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000183 }
184
185 int count() const { return fTimes.count(); }
186
187 double time(int index) const { return fTimes[index] / fTot; }
188
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000189 const SkTDArray<double>* typeTimes() const { return &fTypeTimes; }
190
191 double totTime() const { return fTot; }
192
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000193protected:
mtklein9ac68ee2014-06-20 11:29:20 -0700194 SysTimer fTimer;
robertphillips@google.com5f971142012-12-07 20:48:56 +0000195 SkTDArray<bool> fSkipCommands; // has the command been deleted in the GUI?
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000196 SkTDArray<double> fTimes; // sum of time consumed for each command
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000197 SkTDArray<double> fTypeTimes; // sum of time consumed for each type of command (e.g., drawPath)
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000198 double fTot; // total of all times in 'fTimes'
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000199 int fCurType;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000200 int fCurCommand; // the current command being executed/timed
201
robertphillips@google.com6d9c92b2013-05-23 13:21:18 +0000202#ifdef SK_DEVELOPER
203 virtual bool preDraw(int opIndex, int type) SK_OVERRIDE {
204 fCurCommand = opIndex;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000205
robertphillips@google.com5f971142012-12-07 20:48:56 +0000206 if (fSkipCommands[fCurCommand]) {
robertphillips@google.com6d9c92b2013-05-23 13:21:18 +0000207 return true;
robertphillips@google.com5f971142012-12-07 20:48:56 +0000208 }
209
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000210 fCurType = type;
211 // The SkDebugCanvas doesn't recognize these types. This class needs to
212 // convert or else we'll wind up with a mismatch between the type counts
213 // the debugger displays and the profile times.
214 if (DRAW_POS_TEXT_TOP_BOTTOM == type) {
215 fCurType = DRAW_POS_TEXT;
216 } else if (DRAW_POS_TEXT_H_TOP_BOTTOM == type) {
217 fCurType = DRAW_POS_TEXT_H;
218 }
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000219
robertphillips@google.come174a8b2012-11-27 16:04:42 +0000220#if defined(SK_BUILD_FOR_WIN32)
221 // CPU timer doesn't work well on Windows
222 fTimer.startWall();
223#else
224 fTimer.startCpu();
225#endif
robertphillips@google.com5f971142012-12-07 20:48:56 +0000226
robertphillips@google.com6d9c92b2013-05-23 13:21:18 +0000227 return false;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000228 }
229
robertphillips@google.com6d9c92b2013-05-23 13:21:18 +0000230 virtual void postDraw(int opIndex) SK_OVERRIDE {
robertphillips@google.come174a8b2012-11-27 16:04:42 +0000231#if defined(SK_BUILD_FOR_WIN32)
232 // CPU timer doesn't work well on Windows
233 double time = fTimer.endWall();
234#else
235 double time = fTimer.endCpu();
236#endif
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000237
robertphillips@google.com6d9c92b2013-05-23 13:21:18 +0000238 SkASSERT(opIndex == fCurCommand);
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000239 SkASSERT(fCurType <= LAST_DRAWTYPE_ENUM);
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000240
robertphillips@google.come174a8b2012-11-27 16:04:42 +0000241 fTimes[fCurCommand] += time;
242 fTypeTimes[fCurType] += time;
243 fTot += time;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000244 }
robertphillips@google.com6d9c92b2013-05-23 13:21:18 +0000245#endif
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000246
247private:
robertphillipsce4dd3d2014-07-07 13:46:35 -0700248 typedef SkPicturePlayback INHERITED;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000249};
250
robertphillipsce4dd3d2014-07-07 13:46:35 -0700251#if 0
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000252// Wrap SkPicture to allow installation of an SkTimedPicturePlayback object
253class SkTimedPicture : public SkPicture {
254public:
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000255 static SkTimedPicture* CreateTimedPicture(SkStream* stream,
256 SkPicture::InstallPixelRefProc proc,
257 const SkTDArray<bool>& deletedCommands) {
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000258 SkPictInfo info;
commit-bot@chromium.org6f4fb0f2014-03-03 19:18:39 +0000259 if (!InternalOnly_StreamIsSKP(stream, &info)) {
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000260 return NULL;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000261 }
262
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000263 // Check to see if there is a playback to recreate.
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000264 if (stream->readBool()) {
commit-bot@chromium.org8f831f22014-04-23 22:35:42 +0000265 SkTimedPicturePlayback* playback = SkTimedPicturePlayback::CreateFromStream(
robertphillipse26e65e2014-06-12 05:51:22 -0700266 stream,
commit-bot@chromium.org8f831f22014-04-23 22:35:42 +0000267 info, proc,
scroggo@google.com12705322013-10-01 15:30:46 +0000268 deletedCommands);
269 if (NULL == playback) {
270 return NULL;
271 }
robertphillipse26e65e2014-06-12 05:51:22 -0700272
273 return SkNEW_ARGS(SkTimedPicture, (playback, info.fWidth, info.fHeight));
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000274 }
275
robertphillipse26e65e2014-06-12 05:51:22 -0700276 return NULL;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000277 }
278
robertphillipsdb539902014-07-01 08:47:04 -0700279 void resetTimes() { ((SkTimedPicturePlayback*) fData.get())->resetTimes(); }
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000280
robertphillipsdb539902014-07-01 08:47:04 -0700281 int count() const { return ((SkTimedPicturePlayback*) fData.get())->count(); }
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000282
283 // return the fraction of the total time this command consumed
robertphillipsdb539902014-07-01 08:47:04 -0700284 double time(int index) const { return ((SkTimedPicturePlayback*) fData.get())->time(index); }
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000285
robertphillipsdb539902014-07-01 08:47:04 -0700286 const SkTDArray<double>* typeTimes() const { return ((SkTimedPicturePlayback*) fData.get())->typeTimes(); }
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000287
robertphillipsdb539902014-07-01 08:47:04 -0700288 double totTime() const { return ((SkTimedPicturePlayback*) fData.get())->totTime(); }
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000289
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000290private:
robertphillipsdb539902014-07-01 08:47:04 -0700291 // disallow default ctor b.c. we don't have a good way to setup the fData ptr
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000292 SkTimedPicture();
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000293 // Private ctor only used by CreateTimedPicture, which has created the playback.
294 SkTimedPicture(SkTimedPicturePlayback* playback, int width, int height)
295 : INHERITED(playback, width, height) {}
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000296 // disallow the copy ctor - enabling would require copying code from SkPicture
297 SkTimedPicture(const SkTimedPicture& src);
298
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000299 typedef SkPicture INHERITED;
300};
robertphillipsce4dd3d2014-07-07 13:46:35 -0700301#endif
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000302
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000303// This is a simplification of PictureBenchmark's run with the addition of
304// clearing of the times after the first pass (in resetTimes)
robertphillipsce4dd3d2014-07-07 13:46:35 -0700305void SkDebuggerGUI::run(const SkPicture* pict,
skia.committer@gmail.com34587162012-11-20 02:01:23 +0000306 sk_tools::PictureRenderer* renderer,
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000307 int repeats) {
308 SkASSERT(pict);
309 if (NULL == pict) {
310 return;
311 }
312
313 SkASSERT(renderer != NULL);
314 if (NULL == renderer) {
315 return;
316 }
317
commit-bot@chromium.org3f045172014-05-15 15:10:48 +0000318 renderer->init(pict, NULL, NULL, NULL, false);
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000319
320 renderer->setup();
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000321 renderer->render();
commit-bot@chromium.org51c040e2014-03-11 22:58:00 +0000322 renderer->resetState(true); // flush, swapBuffers and Finish
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000323
robertphillipsce4dd3d2014-07-07 13:46:35 -0700324#if 0
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000325 // We throw this away the first batch of times to remove first time effects (such as paging in this program)
326 pict->resetTimes();
robertphillipsce4dd3d2014-07-07 13:46:35 -0700327#endif
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000328
329 for (int i = 0; i < repeats; ++i) {
330 renderer->setup();
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000331 renderer->render();
commit-bot@chromium.org51c040e2014-03-11 22:58:00 +0000332 renderer->resetState(false); // flush & swapBuffers, but don't Finish
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000333 }
commit-bot@chromium.org51c040e2014-03-11 22:58:00 +0000334 renderer->resetState(true); // flush, swapBuffers and Finish
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000335
336 renderer->end();
337}
338
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000339void SkDebuggerGUI::actionProfile() {
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000340 // In order to profile we pass the command offsets (that were read-in
341 // in loadPicture by the SkOffsetPicture) to an SkTimedPlaybackPicture.
skia.committer@gmail.com884e60b2012-11-16 02:01:17 +0000342 // The SkTimedPlaybackPicture in turn passes the offsets to an
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000343 // SkTimedPicturePlayback object which uses them to track the performance
344 // of individual commands.
345 if (fFileName.isEmpty()) {
346 return;
347 }
348
349 SkFILEStream inputStream;
350
351 inputStream.setPath(fFileName.c_str());
352 if (!inputStream.isValid()) {
353 return;
354 }
355
robertphillipsce4dd3d2014-07-07 13:46:35 -0700356 SkAutoTUnref<SkPicture> picture(SkPicture::CreateFromStream(&inputStream,
357 &SkImageDecoder::DecodeMemory)); // , fSkipCommands));
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000358 if (NULL == picture.get()) {
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000359 return;
360 }
361
robertphillipsce4dd3d2014-07-07 13:46:35 -0700362
363#if 0
364
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000365 // For now this #if allows switching between tiled and simple rendering
366 // modes. Eventually this will be accomplished via the GUI
robertphillips@google.come174a8b2012-11-27 16:04:42 +0000367#if 0
368 // With the current batch of SysTimers, profiling in tiled mode
369 // gets swamped by the timing overhead:
370 //
371 // tile mode simple mode
372 // debugger 64.2ms 12.8ms
373 // bench_pictures 16.9ms 12.4ms
374 //
375 // This is b.c. in tiled mode each command is called many more times
376 // but typically does less work on each invocation (due to clipping)
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000377 sk_tools::TiledPictureRenderer* renderer = NULL;
378
379 renderer = SkNEW(sk_tools::TiledPictureRenderer);
380 renderer->setTileWidth(256);
381 renderer->setTileHeight(256);
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000382#else
383 sk_tools::SimplePictureRenderer* renderer = NULL;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000384
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000385 renderer = SkNEW(sk_tools::SimplePictureRenderer);
robertphillips@google.com1447aa32013-01-30 21:09:09 +0000386
387#if SK_SUPPORT_GPU
commit-bot@chromium.orgfde1e7c2013-08-02 13:59:50 +0000388 if (fSettingsWidget.isGLActive()) {
robertphillips@google.com1447aa32013-01-30 21:09:09 +0000389 renderer->setDeviceType(sk_tools::PictureRenderer::kGPU_DeviceType);
commit-bot@chromium.orgfde1e7c2013-08-02 13:59:50 +0000390 renderer->setSampleCount(fSettingsWidget.getGLSampleCount());
robertphillips@google.com1447aa32013-01-30 21:09:09 +0000391 }
392#endif
393
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000394#endif
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000395
robertphillips@google.come174a8b2012-11-27 16:04:42 +0000396 static const int kNumRepeats = 10;
397
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000398 run(picture.get(), renderer, kNumRepeats);
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000399
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000400 SkASSERT(picture->count() == fListWidget.count());
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000401
402 // extract the individual command times from the SkTimedPlaybackPicture
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000403 for (int i = 0; i < picture->count(); ++i) {
404 double temp = picture->time(i);
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000405
406 QListWidgetItem* item = fListWidget.item(i);
407
408 item->setData(Qt::UserRole + 4, 100.0*temp);
409 }
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000410
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000411 setupOverviewText(picture->typeTimes(), picture->totTime(), kNumRepeats);
commit-bot@chromium.org2a67e122014-05-19 13:53:10 +0000412 setupClipStackText();
robertphillipsce4dd3d2014-07-07 13:46:35 -0700413
414#endif
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000415}
416
chudy@google.com902ebe52012-06-29 14:21:22 +0000417void SkDebuggerGUI::actionCancel() {
chudy@google.comc432f002012-07-10 13:19:25 +0000418 for (int row = 0; row < fListWidget.count(); row++) {
419 fListWidget.item(row)->setHidden(false);
chudy@google.com902ebe52012-06-29 14:21:22 +0000420 }
421}
422
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000423void SkDebuggerGUI::actionClearBreakpoints() {
424 for (int row = 0; row < fListWidget.count(); row++) {
425 QListWidgetItem* item = fListWidget.item(row);
426 item->setCheckState(Qt::Unchecked);
427 item->setData(Qt::DecorationRole,
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000428 QPixmap(":/blank.png"));
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000429 }
430}
431
432void SkDebuggerGUI::actionClearDeletes() {
433 for (int row = 0; row < fListWidget.count(); row++) {
434 QListWidgetItem* item = fListWidget.item(row);
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000435 item->setData(Qt::UserRole + 2, QPixmap(":/blank.png"));
chudy@google.com607357f2012-08-07 16:12:23 +0000436 fDebugger.setCommandVisible(row, true);
robertphillips@google.com5f971142012-12-07 20:48:56 +0000437 fSkipCommands[row] = false;
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000438 }
439 if (fPause) {
440 fCanvasWidget.drawTo(fPausedRow);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000441 fImageWidget.draw();
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000442 } else {
443 fCanvasWidget.drawTo(fListWidget.currentRow());
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000444 fImageWidget.draw();
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000445 }
446}
447
chudy@google.com902ebe52012-06-29 14:21:22 +0000448void SkDebuggerGUI::actionCommandFilter() {
commit-bot@chromium.org22d39332013-11-21 15:37:29 +0000449 fDebugger.highlightCurrentCommand(fSettingsWidget.getVisibilityFilter());
chudy@google.comc432f002012-07-10 13:19:25 +0000450 fCanvasWidget.drawTo(fListWidget.currentRow());
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000451 fImageWidget.draw();
chudy@google.com902ebe52012-06-29 14:21:22 +0000452}
453
454void SkDebuggerGUI::actionClose() {
455 this->close();
456}
457
458void SkDebuggerGUI::actionDelete() {
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000459
robertphillips@google.comdd4b7452013-01-22 19:38:46 +0000460 for (int row = 0; row < fListWidget.count(); ++row) {
461 QListWidgetItem* item = fListWidget.item(row);
462
463 if (!item->isSelected()) {
464 continue;
465 }
466
467 if (fDebugger.isCommandVisible(row)) {
468 item->setData(Qt::UserRole + 2, QPixmap(":/delete.png"));
469 fDebugger.setCommandVisible(row, false);
470 fSkipCommands[row] = true;
471 } else {
472 item->setData(Qt::UserRole + 2, QPixmap(":/blank.png"));
473 fDebugger.setCommandVisible(row, true);
474 fSkipCommands[row] = false;
475 }
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000476 }
477
robertphillips@google.comdd4b7452013-01-22 19:38:46 +0000478 int currentRow = fListWidget.currentRow();
479
chudy@google.come504de02012-07-16 18:35:23 +0000480 if (fPause) {
481 fCanvasWidget.drawTo(fPausedRow);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000482 fImageWidget.draw();
chudy@google.come504de02012-07-16 18:35:23 +0000483 } else {
484 fCanvasWidget.drawTo(currentRow);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000485 fImageWidget.draw();
chudy@google.come504de02012-07-16 18:35:23 +0000486 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000487}
488
robertphillips@google.come8fe4bc2013-02-13 13:26:13 +0000489#if SK_SUPPORT_GPU
commit-bot@chromium.orgfde1e7c2013-08-02 13:59:50 +0000490void SkDebuggerGUI::actionGLWidget() {
491 bool isToggled = fSettingsWidget.isGLActive();
492 if (isToggled) {
493 fCanvasWidget.setGLSampleCount(fSettingsWidget.getGLSampleCount());
494 }
chudy@google.comea5488b2012-07-26 19:38:22 +0000495 fCanvasWidget.setWidgetVisibility(SkCanvasWidget::kGPU_WidgetType, !isToggled);
496}
robertphillips@google.come8fe4bc2013-02-13 13:26:13 +0000497#endif
chudy@google.comea5488b2012-07-26 19:38:22 +0000498
chudy@google.com902ebe52012-06-29 14:21:22 +0000499void SkDebuggerGUI::actionInspector() {
chudy@google.comc432f002012-07-10 13:19:25 +0000500 if (fInspectorWidget.isHidden()) {
501 fInspectorWidget.setHidden(false);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000502 fImageWidget.setHidden(false);
chudy@google.com902ebe52012-06-29 14:21:22 +0000503 } else {
chudy@google.comc432f002012-07-10 13:19:25 +0000504 fInspectorWidget.setHidden(true);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000505 fImageWidget.setHidden(true);
chudy@google.com902ebe52012-06-29 14:21:22 +0000506 }
507}
508
509void SkDebuggerGUI::actionPlay() {
chudy@google.comc432f002012-07-10 13:19:25 +0000510 for (int row = fListWidget.currentRow() + 1; row < fListWidget.count();
chudy@google.com7dcae672012-07-09 20:26:53 +0000511 row++) {
chudy@google.comc432f002012-07-10 13:19:25 +0000512 QListWidgetItem *item = fListWidget.item(row);
chudy@google.com902ebe52012-06-29 14:21:22 +0000513 if (item->checkState() == Qt::Checked) {
chudy@google.comc432f002012-07-10 13:19:25 +0000514 fListWidget.setCurrentItem(item);
chudy@google.com902ebe52012-06-29 14:21:22 +0000515 return;
516 }
517 }
chudy@google.comc432f002012-07-10 13:19:25 +0000518 fListWidget.setCurrentRow(fListWidget.count() - 1);
chudy@google.com902ebe52012-06-29 14:21:22 +0000519}
520
chudy@google.comea5488b2012-07-26 19:38:22 +0000521void SkDebuggerGUI::actionRasterWidget(bool isToggled) {
522 fCanvasWidget.setWidgetVisibility(SkCanvasWidget::kRaster_8888_WidgetType, !isToggled);
523}
524
robertphillips@google.comf4741c12013-02-06 20:13:54 +0000525void SkDebuggerGUI::actionOverdrawVizWidget(bool isToggled) {
526 fDebugger.setOverdrawViz(isToggled);
527 fCanvasWidget.update();
528}
529
commit-bot@chromium.org768ac852014-03-03 16:32:17 +0000530void SkDebuggerGUI::actionMegaVizWidget(bool isToggled) {
531 fDebugger.setMegaViz(isToggled);
532 fCanvasWidget.update();
533}
534
commit-bot@chromium.org2a67e122014-05-19 13:53:10 +0000535void SkDebuggerGUI::actionPathOpsWidget(bool isToggled) {
536 fDebugger.setPathOps(isToggled);
537 fCanvasWidget.update();
538}
539
robertphillips@google.com32bbcf82013-10-17 17:56:10 +0000540void SkDebuggerGUI::actionTextureFilter() {
541 SkPaint::FilterLevel level;
542 bool enabled = fSettingsWidget.getFilterOverride(&level);
543 fDebugger.setTexFilterOverride(enabled, level);
544 fCanvasWidget.update();
545}
546
chudy@google.com902ebe52012-06-29 14:21:22 +0000547void SkDebuggerGUI::actionRewind() {
chudy@google.come504de02012-07-16 18:35:23 +0000548 fListWidget.setCurrentRow(0);
chudy@google.com902ebe52012-06-29 14:21:22 +0000549}
550
chudy@google.com0ab03392012-07-28 20:16:11 +0000551void SkDebuggerGUI::actionSave() {
robertphillips@google.come219baf2013-01-28 19:25:43 +0000552 fFileName = fPath.toAscii().data();
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000553 fFileName.append("/");
robertphillips@google.come219baf2013-01-28 19:25:43 +0000554 fFileName.append(fDirectoryWidget.currentItem()->text().toAscii().data());
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000555 saveToFile(fFileName);
chudy@google.com0ab03392012-07-28 20:16:11 +0000556}
557
558void SkDebuggerGUI::actionSaveAs() {
559 QString filename = QFileDialog::getSaveFileName(this, "Save File", "",
560 "Skia Picture (*skp)");
chudy@google.com38b08ce2012-07-28 23:26:10 +0000561 if (!filename.endsWith(".skp", Qt::CaseInsensitive)) {
chudy@google.com0ab03392012-07-28 20:16:11 +0000562 filename.append(".skp");
563 }
djsollen@google.comc3c82162012-11-13 18:35:10 +0000564 saveToFile(SkString(filename.toAscii().data()));
chudy@google.com0ab03392012-07-28 20:16:11 +0000565}
566
chudy@google.com7dcae672012-07-09 20:26:53 +0000567void SkDebuggerGUI::actionScale(float scaleFactor) {
chudy@google.comc432f002012-07-10 13:19:25 +0000568 fSettingsWidget.setZoomText(scaleFactor);
chudy@google.com7dcae672012-07-09 20:26:53 +0000569}
570
chudy@google.com902ebe52012-06-29 14:21:22 +0000571void SkDebuggerGUI::actionSettings() {
chudy@google.comc432f002012-07-10 13:19:25 +0000572 if (fSettingsWidget.isHidden()) {
573 fSettingsWidget.setHidden(false);
chudy@google.com902ebe52012-06-29 14:21:22 +0000574 } else {
chudy@google.comc432f002012-07-10 13:19:25 +0000575 fSettingsWidget.setHidden(true);
chudy@google.com902ebe52012-06-29 14:21:22 +0000576 }
577}
578
579void SkDebuggerGUI::actionStepBack() {
chudy@google.comc432f002012-07-10 13:19:25 +0000580 int currentRow = fListWidget.currentRow();
chudy@google.com902ebe52012-06-29 14:21:22 +0000581 if (currentRow != 0) {
chudy@google.comc432f002012-07-10 13:19:25 +0000582 fListWidget.setCurrentRow(currentRow - 1);
chudy@google.com902ebe52012-06-29 14:21:22 +0000583 }
584}
585
586void SkDebuggerGUI::actionStepForward() {
chudy@google.comc432f002012-07-10 13:19:25 +0000587 int currentRow = fListWidget.currentRow();
chudy@google.com902ebe52012-06-29 14:21:22 +0000588 QString curRow = QString::number(currentRow);
chudy@google.comc432f002012-07-10 13:19:25 +0000589 QString curCount = QString::number(fListWidget.count());
590 if (currentRow < fListWidget.count() - 1) {
591 fListWidget.setCurrentRow(currentRow + 1);
chudy@google.com902ebe52012-06-29 14:21:22 +0000592 }
593}
594
chudy@google.coma9e937c2012-08-03 17:32:05 +0000595void SkDebuggerGUI::drawComplete() {
chudy@google.com607357f2012-08-07 16:12:23 +0000596 fInspectorWidget.setMatrix(fDebugger.getCurrentMatrix());
597 fInspectorWidget.setClip(fDebugger.getCurrentClip());
chudy@google.coma9e937c2012-08-03 17:32:05 +0000598}
599
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000600void SkDebuggerGUI::saveToFile(const SkString& filename) {
601 SkFILEWStream file(filename.c_str());
robertphillips@google.com25bc2f82013-01-22 18:03:56 +0000602 SkAutoTUnref<SkPicture> copy(fDebugger.copyPicture());
603
604 copy->serialize(&file);
chudy@google.com0ab03392012-07-28 20:16:11 +0000605}
606
chudy@google.com902ebe52012-06-29 14:21:22 +0000607void SkDebuggerGUI::loadFile(QListWidgetItem *item) {
608 if (fDirectoryWidgetActive) {
robertphillips@google.come219baf2013-01-28 19:25:43 +0000609 fFileName = fPath.toAscii().data();
jvanverth@google.com0ac6f162013-02-05 19:44:07 +0000610 // don't add a '/' to files in the local directory
611 if (fFileName.size() > 0) {
612 fFileName.append("/");
613 }
robertphillips@google.come219baf2013-01-28 19:25:43 +0000614 fFileName.append(item->text().toAscii().data());
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000615 loadPicture(fFileName);
chudy@google.com902ebe52012-06-29 14:21:22 +0000616 }
617}
618
619void SkDebuggerGUI::openFile() {
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000620 QString temp = QFileDialog::getOpenFileName(this, tr("Open File"), "",
chudy@google.com7dcae672012-07-09 20:26:53 +0000621 tr("Files (*.*)"));
robertphillips@google.comff6e6ba2013-01-28 17:43:26 +0000622 openFile(temp);
623}
624
625void SkDebuggerGUI::openFile(const QString &filename) {
chudy@google.com902ebe52012-06-29 14:21:22 +0000626 fDirectoryWidgetActive = false;
robertphillips@google.comff6e6ba2013-01-28 17:43:26 +0000627 if (!filename.isEmpty()) {
628 QFileInfo pathInfo(filename);
629 loadPicture(SkString(filename.toAscii().data()));
630 setupDirectoryWidget(pathInfo.path());
chudy@google.com902ebe52012-06-29 14:21:22 +0000631 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000632 fDirectoryWidgetActive = true;
633}
634
chudy@google.comc432f002012-07-10 13:19:25 +0000635void SkDebuggerGUI::pauseDrawing(bool isPaused) {
chudy@google.com607357f2012-08-07 16:12:23 +0000636 fPause = isPaused;
637 fPausedRow = fListWidget.currentRow();
638 fCanvasWidget.drawTo(fPausedRow);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000639 fImageWidget.draw();
chudy@google.com7dcae672012-07-09 20:26:53 +0000640}
641
chudy@google.com902ebe52012-06-29 14:21:22 +0000642void SkDebuggerGUI::registerListClick(QListWidgetItem *item) {
chudy@google.comd3058f52012-07-19 13:41:27 +0000643 if(!fLoading) {
644 int currentRow = fListWidget.currentRow();
chudy@google.comd3058f52012-07-19 13:41:27 +0000645
chudy@google.comea5488b2012-07-26 19:38:22 +0000646 if (currentRow != -1) {
647 if (!fPause) {
648 fCanvasWidget.drawTo(currentRow);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000649 fImageWidget.draw();
chudy@google.comd3058f52012-07-19 13:41:27 +0000650 }
chudy@google.com97cee972012-08-07 20:41:37 +0000651 SkTDArray<SkString*> *currInfo = fDebugger.getCommandInfo(
chudy@google.comea5488b2012-07-26 19:38:22 +0000652 currentRow);
653
654 /* TODO(chudy): Add command type before parameters. Rename v
655 * to something more informative. */
chudy@google.com97cee972012-08-07 20:41:37 +0000656 if (currInfo) {
chudy@google.comea5488b2012-07-26 19:38:22 +0000657 QString info;
658 info.append("<b>Parameters: </b><br/>");
chudy@google.com97cee972012-08-07 20:41:37 +0000659 for (int i = 0; i < currInfo->count(); i++) {
660
661 info.append(QString((*currInfo)[i]->c_str()));
chudy@google.comea5488b2012-07-26 19:38:22 +0000662 info.append("<br/>");
663 }
chudy@google.com6bd109a2012-08-14 19:34:13 +0000664 fInspectorWidget.setText(info, SkInspectorWidget::kDetail_TabType);
chudy@google.comea5488b2012-07-26 19:38:22 +0000665 fInspectorWidget.setDisabled(false);
chudy@google.comea5488b2012-07-26 19:38:22 +0000666 }
commit-bot@chromium.org2a67e122014-05-19 13:53:10 +0000667 setupClipStackText();
chudy@google.comd3058f52012-07-19 13:41:27 +0000668 }
chudy@google.comea5488b2012-07-26 19:38:22 +0000669
chudy@google.com902ebe52012-06-29 14:21:22 +0000670 }
671}
672
chudy@google.com9ca9bfe2012-07-12 21:58:14 +0000673void SkDebuggerGUI::selectCommand(int command) {
674 if (fPause) {
675 fListWidget.setCurrentRow(command);
676 }
677}
678
chudy@google.com902ebe52012-06-29 14:21:22 +0000679void SkDebuggerGUI::toggleBreakpoint() {
chudy@google.comc432f002012-07-10 13:19:25 +0000680 QListWidgetItem* item = fListWidget.currentItem();
chudy@google.com902ebe52012-06-29 14:21:22 +0000681 if (item->checkState() == Qt::Unchecked) {
682 item->setCheckState(Qt::Checked);
chudy@google.come565de42012-07-12 14:15:54 +0000683 item->setData(Qt::DecorationRole,
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000684 QPixmap(":/breakpoint_16x16.png"));
chudy@google.com902ebe52012-06-29 14:21:22 +0000685 } else {
chudy@google.com902ebe52012-06-29 14:21:22 +0000686 item->setCheckState(Qt::Unchecked);
chudy@google.come565de42012-07-12 14:15:54 +0000687 item->setData(Qt::DecorationRole,
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000688 QPixmap(":/blank.png"));
chudy@google.com902ebe52012-06-29 14:21:22 +0000689 }
690}
691
692void SkDebuggerGUI::toggleDirectory() {
chudy@google.com607357f2012-08-07 16:12:23 +0000693 fDirectoryWidget.setHidden(!fDirectoryWidget.isHidden());
chudy@google.com902ebe52012-06-29 14:21:22 +0000694}
695
696void SkDebuggerGUI::toggleFilter(QString string) {
chudy@google.comc432f002012-07-10 13:19:25 +0000697 for (int row = 0; row < fListWidget.count(); row++) {
698 QListWidgetItem *item = fListWidget.item(row);
chudy@google.com607357f2012-08-07 16:12:23 +0000699 item->setHidden(item->text() != string);
chudy@google.com902ebe52012-06-29 14:21:22 +0000700 }
701}
702
703void SkDebuggerGUI::setupUi(QMainWindow *SkDebuggerGUI) {
704 QIcon windowIcon;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000705 windowIcon.addFile(QString::fromUtf8(":/skia.png"), QSize(),
chudy@google.com7dcae672012-07-09 20:26:53 +0000706 QIcon::Normal, QIcon::Off);
chudy@google.com902ebe52012-06-29 14:21:22 +0000707 SkDebuggerGUI->setObjectName(QString::fromUtf8("SkDebuggerGUI"));
708 SkDebuggerGUI->resize(1200, 1000);
709 SkDebuggerGUI->setWindowIcon(windowIcon);
chudy@google.comc432f002012-07-10 13:19:25 +0000710 SkDebuggerGUI->setWindowTitle("Skia Debugger");
chudy@google.com902ebe52012-06-29 14:21:22 +0000711
chudy@google.come504de02012-07-16 18:35:23 +0000712 fActionOpen.setShortcuts(QKeySequence::Open);
chudy@google.comc432f002012-07-10 13:19:25 +0000713 fActionOpen.setText("Open");
chudy@google.com902ebe52012-06-29 14:21:22 +0000714
715 QIcon breakpoint;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000716 breakpoint.addFile(QString::fromUtf8(":/breakpoint.png"),
chudy@google.com7dcae672012-07-09 20:26:53 +0000717 QSize(), QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000718 fActionBreakpoint.setShortcut(QKeySequence(tr("Ctrl+B")));
chudy@google.comc432f002012-07-10 13:19:25 +0000719 fActionBreakpoint.setIcon(breakpoint);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000720 fActionBreakpoint.setText("Breakpoints");
chudy@google.com902ebe52012-06-29 14:21:22 +0000721
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000722 fActionToggleIndexStyle.setShortcut(QKeySequence(tr("Ctrl+T")));
723 fActionToggleIndexStyle.setText("Toggle Index Style");
724
chudy@google.com902ebe52012-06-29 14:21:22 +0000725 QIcon cancel;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000726 cancel.addFile(QString::fromUtf8(":/reload.png"), QSize(),
chudy@google.com7dcae672012-07-09 20:26:53 +0000727 QIcon::Normal, QIcon::Off);
chudy@google.comc432f002012-07-10 13:19:25 +0000728 fActionCancel.setIcon(cancel);
729 fActionCancel.setText("Clear Filter");
chudy@google.com902ebe52012-06-29 14:21:22 +0000730
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000731 fActionClearBreakpoints.setShortcut(QKeySequence(tr("Alt+B")));
732 fActionClearBreakpoints.setText("Clear Breakpoints");
733
734 fActionClearDeletes.setShortcut(QKeySequence(tr("Alt+X")));
735 fActionClearDeletes.setText("Clear Deletes");
736
chudy@google.come504de02012-07-16 18:35:23 +0000737 fActionClose.setShortcuts(QKeySequence::Quit);
chudy@google.comc432f002012-07-10 13:19:25 +0000738 fActionClose.setText("Exit");
chudy@google.com902ebe52012-06-29 14:21:22 +0000739
chudy@google.come504de02012-07-16 18:35:23 +0000740 fActionCreateBreakpoint.setShortcut(QKeySequence(tr("B")));
741 fActionCreateBreakpoint.setText("Set Breakpoint");
742
743 fActionDelete.setShortcut(QKeySequence(tr("X")));
chudy@google.comc432f002012-07-10 13:19:25 +0000744 fActionDelete.setText("Delete Command");
chudy@google.com902ebe52012-06-29 14:21:22 +0000745
chudy@google.come504de02012-07-16 18:35:23 +0000746 fActionDirectory.setShortcut(QKeySequence(tr("Ctrl+D")));
747 fActionDirectory.setText("Directory");
chudy@google.com902ebe52012-06-29 14:21:22 +0000748
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000749 QIcon profile;
robertphillips@google.comd1636362012-11-19 18:25:09 +0000750 profile.addFile(QString::fromUtf8(":/profile.png"), QSize(),
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000751 QIcon::Normal, QIcon::Off);
752 fActionProfile.setIcon(profile);
753 fActionProfile.setText("Profile");
robertphillips@google.come099bc42012-11-19 16:26:40 +0000754 fActionProfile.setDisabled(true);
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000755
chudy@google.comc432f002012-07-10 13:19:25 +0000756 QIcon inspector;
robertphillips@google.comd1636362012-11-19 18:25:09 +0000757 inspector.addFile(QString::fromUtf8(":/inspector.png"),
chudy@google.comc432f002012-07-10 13:19:25 +0000758 QSize(), QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000759 fActionInspector.setShortcut(QKeySequence(tr("Ctrl+I")));
chudy@google.comc432f002012-07-10 13:19:25 +0000760 fActionInspector.setIcon(inspector);
chudy@google.come504de02012-07-16 18:35:23 +0000761 fActionInspector.setText("Inspector");
chudy@google.com902ebe52012-06-29 14:21:22 +0000762
bungeman@google.com2ff6d1d2013-07-01 14:24:12 +0000763 QIcon settings;
764 settings.addFile(QString::fromUtf8(":/inspector.png"),
765 QSize(), QIcon::Normal, QIcon::Off);
766 fActionSettings.setShortcut(QKeySequence(tr("Ctrl+G")));
767 fActionSettings.setIcon(settings);
768 fActionSettings.setText("Settings");
skia.committer@gmail.com0d55dd72013-07-02 07:00:59 +0000769
chudy@google.comc432f002012-07-10 13:19:25 +0000770 QIcon play;
robertphillips@google.comd1636362012-11-19 18:25:09 +0000771 play.addFile(QString::fromUtf8(":/play.png"), QSize(),
chudy@google.comc432f002012-07-10 13:19:25 +0000772 QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000773 fActionPlay.setShortcut(QKeySequence(tr("Ctrl+P")));
chudy@google.comc432f002012-07-10 13:19:25 +0000774 fActionPlay.setIcon(play);
775 fActionPlay.setText("Play");
chudy@google.com902ebe52012-06-29 14:21:22 +0000776
chudy@google.come504de02012-07-16 18:35:23 +0000777 QIcon pause;
robertphillips@google.comd1636362012-11-19 18:25:09 +0000778 pause.addFile(QString::fromUtf8(":/pause.png"), QSize(),
chudy@google.comc432f002012-07-10 13:19:25 +0000779 QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000780 fActionPause.setShortcut(QKeySequence(tr("Space")));
781 fActionPause.setCheckable(true);
782 fActionPause.setIcon(pause);
783 fActionPause.setText("Pause");
784
chudy@google.comc432f002012-07-10 13:19:25 +0000785 QIcon rewind;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000786 rewind.addFile(QString::fromUtf8(":/rewind.png"), QSize(),
chudy@google.comc432f002012-07-10 13:19:25 +0000787 QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000788 fActionRewind.setShortcut(QKeySequence(tr("Ctrl+R")));
chudy@google.comc432f002012-07-10 13:19:25 +0000789 fActionRewind.setIcon(rewind);
790 fActionRewind.setText("Rewind");
chudy@google.com902ebe52012-06-29 14:21:22 +0000791
chudy@google.com0ab03392012-07-28 20:16:11 +0000792 fActionSave.setShortcut(QKeySequence::Save);
793 fActionSave.setText("Save");
794 fActionSave.setDisabled(true);
795 fActionSaveAs.setShortcut(QKeySequence::SaveAs);
796 fActionSaveAs.setText("Save As");
797 fActionSaveAs.setDisabled(true);
798
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000799 fActionShowDeletes.setShortcut(QKeySequence(tr("Ctrl+X")));
800 fActionShowDeletes.setText("Deleted Commands");
801
chudy@google.comc432f002012-07-10 13:19:25 +0000802 QIcon stepBack;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000803 stepBack.addFile(QString::fromUtf8(":/previous.png"), QSize(),
chudy@google.comc432f002012-07-10 13:19:25 +0000804 QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000805 fActionStepBack.setShortcut(QKeySequence(tr("[")));
chudy@google.comc432f002012-07-10 13:19:25 +0000806 fActionStepBack.setIcon(stepBack);
807 fActionStepBack.setText("Step Back");
chudy@google.com902ebe52012-06-29 14:21:22 +0000808
chudy@google.comc432f002012-07-10 13:19:25 +0000809 QIcon stepForward;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000810 stepForward.addFile(QString::fromUtf8(":/next.png"),
chudy@google.comc432f002012-07-10 13:19:25 +0000811 QSize(), QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000812 fActionStepForward.setShortcut(QKeySequence(tr("]")));
chudy@google.comc432f002012-07-10 13:19:25 +0000813 fActionStepForward.setIcon(stepForward);
814 fActionStepForward.setText("Step Forward");
815
chudy@google.coma1226312012-07-26 20:26:44 +0000816 fActionZoomIn.setShortcut(QKeySequence(tr("Ctrl+=")));
817 fActionZoomIn.setText("Zoom In");
818 fActionZoomOut.setShortcut(QKeySequence(tr("Ctrl+-")));
819 fActionZoomOut.setText("Zoom Out");
820
chudy@google.comc432f002012-07-10 13:19:25 +0000821 fListWidget.setItemDelegate(new SkListWidget(&fListWidget));
822 fListWidget.setObjectName(QString::fromUtf8("listWidget"));
commit-bot@chromium.orgbcd431e2013-11-21 13:41:37 +0000823 fListWidget.setMinimumWidth(250);
chudy@google.comc432f002012-07-10 13:19:25 +0000824
825 fFilter.addItem("--Filter By Available Commands--");
826
commit-bot@chromium.orgbcd431e2013-11-21 13:41:37 +0000827 fDirectoryWidget.setMinimumWidth(250);
chudy@google.comc432f002012-07-10 13:19:25 +0000828 fDirectoryWidget.setStyleSheet("QListWidget::Item {padding: 5px;}");
829
830 fCanvasWidget.setSizePolicy(QSizePolicy::Expanding,
chudy@google.com7dcae672012-07-09 20:26:53 +0000831 QSizePolicy::Expanding);
chudy@google.com902ebe52012-06-29 14:21:22 +0000832
skia.committer@gmail.com1c9c0d32012-11-22 02:02:41 +0000833 fImageWidget.setFixedSize(SkImageWidget::kImageWidgetWidth,
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000834 SkImageWidget::kImageWidgetHeight);
835
chudy@google.comc432f002012-07-10 13:19:25 +0000836 fInspectorWidget.setSizePolicy(QSizePolicy::Expanding,
chudy@google.com7dcae672012-07-09 20:26:53 +0000837 QSizePolicy::Expanding);
chudy@google.comc432f002012-07-10 13:19:25 +0000838 fInspectorWidget.setMaximumHeight(300);
chudy@google.com902ebe52012-06-29 14:21:22 +0000839
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000840 fSettingsAndImageLayout.setSpacing(6);
841 fSettingsAndImageLayout.addWidget(&fSettingsWidget);
842 fSettingsAndImageLayout.addWidget(&fImageWidget);
843
chudy@google.comc432f002012-07-10 13:19:25 +0000844 fSettingsWidget.setSizePolicy(QSizePolicy::Expanding,
845 QSizePolicy::Expanding);
846 fSettingsWidget.setMaximumWidth(250);
chudy@google.com902ebe52012-06-29 14:21:22 +0000847
commit-bot@chromium.orgbcd431e2013-11-21 13:41:37 +0000848 fLeftColumnSplitter.addWidget(&fListWidget);
849 fLeftColumnSplitter.addWidget(&fDirectoryWidget);
850 fLeftColumnSplitter.setOrientation(Qt::Vertical);
chudy@google.com902ebe52012-06-29 14:21:22 +0000851
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000852 fCanvasSettingsAndImageLayout.setSpacing(6);
853 fCanvasSettingsAndImageLayout.addWidget(&fCanvasWidget);
854 fCanvasSettingsAndImageLayout.addLayout(&fSettingsAndImageLayout);
855
chudy@google.comc432f002012-07-10 13:19:25 +0000856 fMainAndRightColumnLayout.setSpacing(6);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000857 fMainAndRightColumnLayout.addLayout(&fCanvasSettingsAndImageLayout);
chudy@google.comc432f002012-07-10 13:19:25 +0000858 fMainAndRightColumnLayout.addWidget(&fInspectorWidget);
commit-bot@chromium.orgbcd431e2013-11-21 13:41:37 +0000859 fMainAndRightColumnWidget.setLayout(&fMainAndRightColumnLayout);
chudy@google.com902ebe52012-06-29 14:21:22 +0000860
commit-bot@chromium.orgbcd431e2013-11-21 13:41:37 +0000861 fCentralSplitter.addWidget(&fLeftColumnSplitter);
862 fCentralSplitter.addWidget(&fMainAndRightColumnWidget);
863 fCentralSplitter.setStretchFactor(0, 0);
864 fCentralSplitter.setStretchFactor(1, 1);
chudy@google.comc432f002012-07-10 13:19:25 +0000865
commit-bot@chromium.orgbcd431e2013-11-21 13:41:37 +0000866 SkDebuggerGUI->setCentralWidget(&fCentralSplitter);
chudy@google.comc432f002012-07-10 13:19:25 +0000867 SkDebuggerGUI->setStatusBar(&fStatusBar);
868
chudy@google.come504de02012-07-16 18:35:23 +0000869 fToolBar.setIconSize(QSize(32, 32));
chudy@google.comc432f002012-07-10 13:19:25 +0000870 fToolBar.setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
871 SkDebuggerGUI->addToolBar(Qt::TopToolBarArea, &fToolBar);
chudy@google.com902ebe52012-06-29 14:21:22 +0000872
chudy@google.com0ab03392012-07-28 20:16:11 +0000873 fSpacer.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
chudy@google.com902ebe52012-06-29 14:21:22 +0000874
chudy@google.comc432f002012-07-10 13:19:25 +0000875 fToolBar.addAction(&fActionRewind);
876 fToolBar.addAction(&fActionStepBack);
chudy@google.come504de02012-07-16 18:35:23 +0000877 fToolBar.addAction(&fActionPause);
chudy@google.comc432f002012-07-10 13:19:25 +0000878 fToolBar.addAction(&fActionStepForward);
879 fToolBar.addAction(&fActionPlay);
880 fToolBar.addSeparator();
chudy@google.come504de02012-07-16 18:35:23 +0000881 fToolBar.addAction(&fActionInspector);
bungeman@google.com2ff6d1d2013-07-01 14:24:12 +0000882 fToolBar.addAction(&fActionSettings);
chudy@google.comc432f002012-07-10 13:19:25 +0000883 fToolBar.addSeparator();
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000884 fToolBar.addAction(&fActionProfile);
885
886 fToolBar.addSeparator();
chudy@google.com0ab03392012-07-28 20:16:11 +0000887 fToolBar.addWidget(&fSpacer);
chudy@google.comc432f002012-07-10 13:19:25 +0000888 fToolBar.addWidget(&fFilter);
889 fToolBar.addAction(&fActionCancel);
chudy@google.com902ebe52012-06-29 14:21:22 +0000890
891 // TODO(chudy): Remove static call.
892 fDirectoryWidgetActive = false;
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000893 fFileName = "";
robertphillips@google.comff6e6ba2013-01-28 17:43:26 +0000894 setupDirectoryWidget("");
chudy@google.com902ebe52012-06-29 14:21:22 +0000895 fDirectoryWidgetActive = true;
896
chudy@google.com902ebe52012-06-29 14:21:22 +0000897 // Menu Bar
chudy@google.comc432f002012-07-10 13:19:25 +0000898 fMenuFile.setTitle("File");
899 fMenuFile.addAction(&fActionOpen);
chudy@google.com0ab03392012-07-28 20:16:11 +0000900 fMenuFile.addAction(&fActionSave);
901 fMenuFile.addAction(&fActionSaveAs);
chudy@google.comc432f002012-07-10 13:19:25 +0000902 fMenuFile.addAction(&fActionClose);
chudy@google.come504de02012-07-16 18:35:23 +0000903
904 fMenuEdit.setTitle("Edit");
905 fMenuEdit.addAction(&fActionDelete);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000906 fMenuEdit.addAction(&fActionClearDeletes);
907 fMenuEdit.addSeparator();
chudy@google.come504de02012-07-16 18:35:23 +0000908 fMenuEdit.addAction(&fActionCreateBreakpoint);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000909 fMenuEdit.addAction(&fActionClearBreakpoints);
chudy@google.come504de02012-07-16 18:35:23 +0000910
chudy@google.comc432f002012-07-10 13:19:25 +0000911 fMenuNavigate.setTitle("Navigate");
chudy@google.come504de02012-07-16 18:35:23 +0000912 fMenuNavigate.addAction(&fActionRewind);
913 fMenuNavigate.addAction(&fActionStepBack);
914 fMenuNavigate.addAction(&fActionStepForward);
915 fMenuNavigate.addAction(&fActionPlay);
916 fMenuNavigate.addAction(&fActionPause);
chudy@google.comc432f002012-07-10 13:19:25 +0000917 fMenuNavigate.addAction(&fActionGoToLine);
chudy@google.come504de02012-07-16 18:35:23 +0000918
chudy@google.comc432f002012-07-10 13:19:25 +0000919 fMenuView.setTitle("View");
chudy@google.come504de02012-07-16 18:35:23 +0000920 fMenuView.addAction(&fActionBreakpoint);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000921 fMenuView.addAction(&fActionShowDeletes);
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000922 fMenuView.addAction(&fActionToggleIndexStyle);
chudy@google.coma1226312012-07-26 20:26:44 +0000923 fMenuView.addAction(&fActionZoomIn);
924 fMenuView.addAction(&fActionZoomOut);
chudy@google.come504de02012-07-16 18:35:23 +0000925
926 fMenuWindows.setTitle("Window");
927 fMenuWindows.addAction(&fActionInspector);
bungeman@google.com2ff6d1d2013-07-01 14:24:12 +0000928 fMenuWindows.addAction(&fActionSettings);
chudy@google.come504de02012-07-16 18:35:23 +0000929 fMenuWindows.addAction(&fActionDirectory);
chudy@google.comc432f002012-07-10 13:19:25 +0000930
931 fActionGoToLine.setText("Go to Line...");
932 fActionGoToLine.setDisabled(true);
933 fMenuBar.addAction(fMenuFile.menuAction());
chudy@google.come504de02012-07-16 18:35:23 +0000934 fMenuBar.addAction(fMenuEdit.menuAction());
chudy@google.comc432f002012-07-10 13:19:25 +0000935 fMenuBar.addAction(fMenuView.menuAction());
936 fMenuBar.addAction(fMenuNavigate.menuAction());
chudy@google.come504de02012-07-16 18:35:23 +0000937 fMenuBar.addAction(fMenuWindows.menuAction());
chudy@google.com902ebe52012-06-29 14:21:22 +0000938
chudy@google.com7dcae672012-07-09 20:26:53 +0000939 fPause = false;
940
chudy@google.comc432f002012-07-10 13:19:25 +0000941 SkDebuggerGUI->setMenuBar(&fMenuBar);
chudy@google.com902ebe52012-06-29 14:21:22 +0000942 QMetaObject::connectSlotsByName(SkDebuggerGUI);
943}
944
robertphillips@google.comff6e6ba2013-01-28 17:43:26 +0000945void SkDebuggerGUI::setupDirectoryWidget(const QString& path) {
946 fPath = path;
947 QDir dir(path);
chudy@google.com902ebe52012-06-29 14:21:22 +0000948 QRegExp r(".skp");
chudy@google.comc432f002012-07-10 13:19:25 +0000949 fDirectoryWidget.clear();
950 const QStringList files = dir.entryList();
chudy@google.com902ebe52012-06-29 14:21:22 +0000951 foreach (QString f, files) {
chudy@google.com7dcae672012-07-09 20:26:53 +0000952 if (f.contains(r))
chudy@google.comc432f002012-07-10 13:19:25 +0000953 fDirectoryWidget.addItem(f);
chudy@google.com902ebe52012-06-29 14:21:22 +0000954 }
955}
956
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000957void SkDebuggerGUI::loadPicture(const SkString& fileName) {
958 fFileName = fileName;
chudy@google.comd3058f52012-07-19 13:41:27 +0000959 fLoading = true;
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000960 SkStream* stream = SkNEW_ARGS(SkFILEStream, (fileName.c_str()));
robertphillips@google.com2d40ec42013-02-07 20:39:40 +0000961
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000962 SkPicture* picture = SkPicture::CreateFromStream(stream);
robertphillips@google.com2d40ec42013-02-07 20:39:40 +0000963
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000964 if (NULL == picture) {
robertphillips@google.com2d40ec42013-02-07 20:39:40 +0000965 QMessageBox::critical(this, "Error loading file", "Couldn't read file, sorry.");
966 SkSafeUnref(stream);
967 return;
968 }
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000969
chudy@google.com686e6802012-08-14 16:00:32 +0000970 fCanvasWidget.resetWidgetTransform();
chudy@google.com607357f2012-08-07 16:12:23 +0000971 fDebugger.loadPicture(picture);
chudy@google.com4c7962e2012-08-14 19:38:31 +0000972
robertphillips@google.com6d9c92b2013-05-23 13:21:18 +0000973 fSkipCommands.setCount(fDebugger.getSize());
974 for (int i = 0; i < fSkipCommands.count(); ++i) {
robertphillips@google.com5f971142012-12-07 20:48:56 +0000975 fSkipCommands[i] = false;
976 }
977
chudy@google.com607357f2012-08-07 16:12:23 +0000978 SkSafeUnref(stream);
979 SkSafeUnref(picture);
980
chudy@google.com97cee972012-08-07 20:41:37 +0000981 // Will this automatically clear out due to nature of refcnt?
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000982 SkTArray<SkString>* commands = fDebugger.getDrawCommandsAsStrings();
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000983 SkTDArray<size_t>* offsets = fDebugger.getDrawCommandOffsets();
984 SkASSERT(commands->count() == offsets->count());
chudy@google.com607357f2012-08-07 16:12:23 +0000985
robertphillips@google.com6d9c92b2013-05-23 13:21:18 +0000986 fActionProfile.setDisabled(false);
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000987
chudy@google.com7dcae672012-07-09 20:26:53 +0000988 /* fDebugCanvas is reinitialized every load picture. Need it to retain value
chudy@google.com607357f2012-08-07 16:12:23 +0000989 * of the visibility filter.
990 * TODO(chudy): This should be deprecated since fDebugger is not
991 * recreated.
992 * */
commit-bot@chromium.org22d39332013-11-21 15:37:29 +0000993 fDebugger.highlightCurrentCommand(fSettingsWidget.getVisibilityFilter());
chudy@google.com607357f2012-08-07 16:12:23 +0000994
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000995 this->setupListWidget(commands, offsets);
996 this->setupComboBox(commands);
997 this->setupOverviewText(NULL, 0.0, 1);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000998 fInspectorWidget.setDisabled(false);
chudy@google.come606d6e2012-07-12 14:31:25 +0000999 fSettingsWidget.setDisabled(false);
chudy@google.comd3058f52012-07-19 13:41:27 +00001000 fMenuEdit.setDisabled(false);
1001 fMenuNavigate.setDisabled(false);
1002 fMenuView.setDisabled(false);
chudy@google.com0ab03392012-07-28 20:16:11 +00001003 fActionSave.setDisabled(false);
1004 fActionSaveAs.setDisabled(false);
chudy@google.comd3058f52012-07-19 13:41:27 +00001005 fLoading = false;
1006 actionPlay();
chudy@google.com902ebe52012-06-29 14:21:22 +00001007}
1008
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +00001009void SkDebuggerGUI::setupListWidget(SkTArray<SkString>* commands, SkTDArray<size_t>* offsets) {
1010 SkASSERT(commands->count() == offsets->count());
chudy@google.comc432f002012-07-10 13:19:25 +00001011 fListWidget.clear();
chudy@google.com902ebe52012-06-29 14:21:22 +00001012 int counter = 0;
robertphillips@google.com30d35f22012-11-06 16:45:36 +00001013 int indent = 0;
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +00001014 for (int i = 0; i < commands->count(); i++) {
chudy@google.com902ebe52012-06-29 14:21:22 +00001015 QListWidgetItem *item = new QListWidgetItem();
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +00001016 item->setData(Qt::DisplayRole, (*commands)[i].c_str());
chudy@google.com902ebe52012-06-29 14:21:22 +00001017 item->setData(Qt::UserRole + 1, counter++);
robertphillips@google.com30d35f22012-11-06 16:45:36 +00001018
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +00001019 if (0 == strcmp("Restore", (*commands)[i].c_str()) ||
1020 0 == strcmp("EndCommentGroup", (*commands)[i].c_str()) ||
1021 0 == strcmp("PopCull", (*commands)[i].c_str())) {
robertphillips@google.com30d35f22012-11-06 16:45:36 +00001022 indent -= 10;
1023 }
1024
1025 item->setData(Qt::UserRole + 3, indent);
1026
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +00001027 if (0 == strcmp("Save", (*commands)[i].c_str()) ||
1028 0 == strcmp("Save Layer", (*commands)[i].c_str()) ||
1029 0 == strcmp("BeginCommentGroup", (*commands)[i].c_str()) ||
1030 0 == strcmp("PushCull", (*commands)[i].c_str())) {
robertphillips@google.com30d35f22012-11-06 16:45:36 +00001031 indent += 10;
1032 }
1033
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +00001034 item->setData(Qt::UserRole + 4, -1);
1035 item->setData(Qt::UserRole + 5, (int)(*offsets)[i]);
robertphillips@google.comd26c7062012-11-12 20:42:12 +00001036
chudy@google.comc432f002012-07-10 13:19:25 +00001037 fListWidget.addItem(item);
chudy@google.com902ebe52012-06-29 14:21:22 +00001038 }
1039}
1040
skia.committer@gmail.com91274b92013-03-13 07:01:04 +00001041void SkDebuggerGUI::setupOverviewText(const SkTDArray<double>* typeTimes,
robertphillips@google.come428f9b2013-03-12 15:33:40 +00001042 double totTime,
1043 int numRuns) {
borenet@google.com2d9dbd42013-03-12 13:07:40 +00001044 SkString overview;
robertphillips@google.come428f9b2013-03-12 15:33:40 +00001045 fDebugger.getOverviewText(typeTimes, totTime, &overview, numRuns);
borenet@google.com2d9dbd42013-03-12 13:07:40 +00001046 fInspectorWidget.setText(overview.c_str(), SkInspectorWidget::kOverview_TabType);
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +00001047}
1048
commit-bot@chromium.org2a67e122014-05-19 13:53:10 +00001049void SkDebuggerGUI::setupClipStackText() {
1050 SkString clipStack;
1051 fDebugger.getClipStackText(&clipStack);
1052 fInspectorWidget.setText(clipStack.c_str(), SkInspectorWidget::kClipStack_TabType);
1053}
1054
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +00001055void SkDebuggerGUI::setupComboBox(SkTArray<SkString>* command) {
1056 fFilter.clear();
1057 fFilter.addItem("--Filter By Available Commands--");
1058
1059 std::map<std::string, int> map;
1060 for (int i = 0; i < command->count(); i++) {
1061 map[(*command)[i].c_str()]++;
1062 }
1063
skia.committer@gmail.com34587162012-11-20 02:01:23 +00001064 for (std::map<std::string, int>::iterator it = map.begin(); it != map.end();
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +00001065 ++it) {
1066 fFilter.addItem((it->first).c_str());
1067 }
chudy@google.com902ebe52012-06-29 14:21:22 +00001068
1069 // NOTE(chudy): Makes first item unselectable.
chudy@google.com7dcae672012-07-09 20:26:53 +00001070 QStandardItemModel* model = qobject_cast<QStandardItemModel*>(
chudy@google.comc432f002012-07-10 13:19:25 +00001071 fFilter.model());
1072 QModelIndex firstIndex = model->index(0, fFilter.modelColumn(),
1073 fFilter.rootModelIndex());
chudy@google.com902ebe52012-06-29 14:21:22 +00001074 QStandardItem* firstItem = model->itemFromIndex(firstIndex);
1075 firstItem->setSelectable(false);
1076}