blob: b476a14ccf85fcaaf399c96e2b1349cb2efc50dc [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"
robertphillips@google.com2bde91d2012-11-15 14:57:57 +000014#include "SkPictureRecord.h"
15#include "SkPicturePlayback.h"
robertphillips@google.come174a8b2012-11-27 16:04:42 +000016
scroggo@google.com7def5e12013-05-31 14:00:10 +000017__SK_FORCE_IMAGE_DECODER_LINKING;
18
robertphillips@google.come174a8b2012-11-27 16:04:42 +000019#if defined(SK_BUILD_FOR_WIN32)
20 #include "BenchSysTimer_windows.h"
21#elif defined(SK_BUILD_FOR_MAC)
22 #include "BenchSysTimer_mach.h"
23#elif defined(SK_BUILD_FOR_UNIX) || defined(SK_BUILD_FOR_ANDROID)
24 #include "BenchSysTimer_posix.h"
25#else
26 #include "BenchSysTimer_c.h"
27#endif
28
chudy@google.com902ebe52012-06-29 14:21:22 +000029
30SkDebuggerGUI::SkDebuggerGUI(QWidget *parent) :
chudy@google.comc432f002012-07-10 13:19:25 +000031 QMainWindow(parent)
commit-bot@chromium.orgbcd431e2013-11-21 13:41:37 +000032 , fCentralSplitter(this)
chudy@google.com2d537a12012-07-31 12:49:52 +000033 , fStatusBar(this)
34 , fToolBar(this)
chudy@google.comc432f002012-07-10 13:19:25 +000035 , fActionOpen(this)
36 , fActionBreakpoint(this)
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +000037 , fActionToggleIndexStyle(this)
robertphillips@google.comd26c7062012-11-12 20:42:12 +000038 , fActionProfile(this)
chudy@google.comc432f002012-07-10 13:19:25 +000039 , fActionCancel(this)
chudy@google.com7e4cfbf2012-07-17 15:40:51 +000040 , fActionClearBreakpoints(this)
chudy@google.come504de02012-07-16 18:35:23 +000041 , fActionClearDeletes(this)
chudy@google.comc432f002012-07-10 13:19:25 +000042 , fActionClose(this)
chudy@google.come504de02012-07-16 18:35:23 +000043 , fActionCreateBreakpoint(this)
chudy@google.comc432f002012-07-10 13:19:25 +000044 , fActionDelete(this)
45 , fActionDirectory(this)
46 , fActionGoToLine(this)
47 , fActionInspector(this)
bungeman@google.com2ff6d1d2013-07-01 14:24:12 +000048 , fActionSettings(this)
chudy@google.comc432f002012-07-10 13:19:25 +000049 , fActionPlay(this)
chudy@google.come504de02012-07-16 18:35:23 +000050 , fActionPause(this)
chudy@google.comc432f002012-07-10 13:19:25 +000051 , fActionRewind(this)
chudy@google.com0ab03392012-07-28 20:16:11 +000052 , fActionSave(this)
53 , fActionSaveAs(this)
chudy@google.com7e4cfbf2012-07-17 15:40:51 +000054 , fActionShowDeletes(this)
chudy@google.comc432f002012-07-10 13:19:25 +000055 , fActionStepBack(this)
56 , fActionStepForward(this)
chudy@google.coma1226312012-07-26 20:26:44 +000057 , fActionZoomIn(this)
58 , fActionZoomOut(this)
59 , fMapper(this)
commit-bot@chromium.orgbcd431e2013-11-21 13:41:37 +000060 , fListWidget(&fCentralSplitter)
61 , fDirectoryWidget(&fCentralSplitter)
chudy@google.com607357f2012-08-07 16:12:23 +000062 , fCanvasWidget(this, &fDebugger)
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +000063 , fImageWidget(&fDebugger)
chudy@google.comc432f002012-07-10 13:19:25 +000064 , fMenuBar(this)
65 , fMenuFile(this)
66 , fMenuNavigate(this)
67 , fMenuView(this)
chudy@google.com7e4cfbf2012-07-17 15:40:51 +000068 , fBreakpointsActivated(false)
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +000069 , fIndexStyleToggle(false)
chudy@google.com7e4cfbf2012-07-17 15:40:51 +000070 , fDeletesActivated(false)
71 , fPause(false)
chudy@google.comd3058f52012-07-19 13:41:27 +000072 , fLoading(false)
chudy@google.comc432f002012-07-10 13:19:25 +000073{
chudy@google.com902ebe52012-06-29 14:21:22 +000074 setupUi(this);
robertphillips@google.comdd4b7452013-01-22 19:38:46 +000075 fListWidget.setSelectionMode(QAbstractItemView::ExtendedSelection);
chudy@google.comea5488b2012-07-26 19:38:22 +000076 connect(&fListWidget, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)), this, SLOT(registerListClick(QListWidgetItem *)));
chudy@google.comc432f002012-07-10 13:19:25 +000077 connect(&fActionOpen, SIGNAL(triggered()), this, SLOT(openFile()));
chudy@google.comea5488b2012-07-26 19:38:22 +000078 connect(&fActionDirectory, SIGNAL(triggered()), this, SLOT(toggleDirectory()));
79 connect(&fDirectoryWidget, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)), this, SLOT(loadFile(QListWidgetItem *)));
chudy@google.comc432f002012-07-10 13:19:25 +000080 connect(&fActionDelete, SIGNAL(triggered()), this, SLOT(actionDelete()));
chudy@google.comea5488b2012-07-26 19:38:22 +000081 connect(&fListWidget, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(toggleBreakpoint()));
chudy@google.comc432f002012-07-10 13:19:25 +000082 connect(&fActionRewind, SIGNAL(triggered()), this, SLOT(actionRewind()));
83 connect(&fActionPlay, SIGNAL(triggered()), this, SLOT(actionPlay()));
84 connect(&fActionStepBack, SIGNAL(triggered()), this, SLOT(actionStepBack()));
chudy@google.comea5488b2012-07-26 19:38:22 +000085 connect(&fActionStepForward, SIGNAL(triggered()), this, SLOT(actionStepForward()));
86 connect(&fActionBreakpoint, SIGNAL(triggered()), this, SLOT(actionBreakpoints()));
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +000087 connect(&fActionToggleIndexStyle, SIGNAL(triggered()), this, SLOT(actionToggleIndexStyle()));
chudy@google.comea5488b2012-07-26 19:38:22 +000088 connect(&fActionInspector, SIGNAL(triggered()), this, SLOT(actionInspector()));
bungeman@google.com2ff6d1d2013-07-01 14:24:12 +000089 connect(&fActionSettings, SIGNAL(triggered()), this, SLOT(actionSettings()));
chudy@google.comea5488b2012-07-26 19:38:22 +000090 connect(&fFilter, SIGNAL(activated(QString)), this, SLOT(toggleFilter(QString)));
robertphillips@google.comd26c7062012-11-12 20:42:12 +000091 connect(&fActionProfile, SIGNAL(triggered()), this, SLOT(actionProfile()));
chudy@google.comc432f002012-07-10 13:19:25 +000092 connect(&fActionCancel, SIGNAL(triggered()), this, SLOT(actionCancel()));
chudy@google.com7e4cfbf2012-07-17 15:40:51 +000093 connect(&fActionClearBreakpoints, SIGNAL(triggered()), this, SLOT(actionClearBreakpoints()));
94 connect(&fActionClearDeletes, SIGNAL(triggered()), this, SLOT(actionClearDeletes()));
chudy@google.comc432f002012-07-10 13:19:25 +000095 connect(&fActionClose, SIGNAL(triggered()), this, SLOT(actionClose()));
commit-bot@chromium.org22d39332013-11-21 15:37:29 +000096 connect(&fSettingsWidget, SIGNAL(visibilityFilterChanged()), this, SLOT(actionCommandFilter()));
robertphillips@google.come8fe4bc2013-02-13 13:26:13 +000097#if SK_SUPPORT_GPU
commit-bot@chromium.orgfde1e7c2013-08-02 13:59:50 +000098 connect(&fSettingsWidget, SIGNAL(glSettingsChanged()), this, SLOT(actionGLWidget()));
robertphillips@google.come8fe4bc2013-02-13 13:26:13 +000099#endif
robertphillips@google.com32bbcf82013-10-17 17:56:10 +0000100 connect(&fSettingsWidget, SIGNAL(texFilterSettingsChanged()), this, SLOT(actionTextureFilter()));
chudy@google.comea5488b2012-07-26 19:38:22 +0000101 connect(fSettingsWidget.getRasterCheckBox(), SIGNAL(toggled(bool)), this, SLOT(actionRasterWidget(bool)));
robertphillips@google.comf4741c12013-02-06 20:13:54 +0000102 connect(fSettingsWidget.getOverdrawVizCheckBox(), SIGNAL(toggled(bool)), this, SLOT(actionOverdrawVizWidget(bool)));
commit-bot@chromium.org768ac852014-03-03 16:32:17 +0000103 connect(fSettingsWidget.getMegaVizCheckBox(), SIGNAL(toggled(bool)), this, SLOT(actionMegaVizWidget(bool)));
chudy@google.comea5488b2012-07-26 19:38:22 +0000104 connect(&fActionPause, SIGNAL(toggled(bool)), this, SLOT(pauseDrawing(bool)));
chudy@google.come504de02012-07-16 18:35:23 +0000105 connect(&fActionCreateBreakpoint, SIGNAL(activated()), this, SLOT(toggleBreakpoint()));
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000106 connect(&fActionShowDeletes, SIGNAL(triggered()), this, SLOT(showDeletes()));
chudy@google.comea5488b2012-07-26 19:38:22 +0000107 connect(&fCanvasWidget, SIGNAL(hitChanged(int)), this, SLOT(selectCommand(int)));
108 connect(&fCanvasWidget, SIGNAL(hitChanged(int)), &fSettingsWidget, SLOT(updateHit(int)));
109 connect(&fCanvasWidget, SIGNAL(scaleFactorChanged(float)), this, SLOT(actionScale(float)));
110 connect(&fCanvasWidget, SIGNAL(commandChanged(int)), &fSettingsWidget, SLOT(updateCommand(int)));
chudy@google.com0ab03392012-07-28 20:16:11 +0000111 connect(&fActionSaveAs, SIGNAL(triggered()), this, SLOT(actionSaveAs()));
112 connect(&fActionSave, SIGNAL(triggered()), this, SLOT(actionSave()));
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000113
bungeman@google.come8cc6e82013-01-17 16:30:56 +0000114 fMapper.setMapping(&fActionZoomIn, SkCanvasWidget::kIn_ZoomCommand);
115 fMapper.setMapping(&fActionZoomOut, SkCanvasWidget::kOut_ZoomCommand);
chudy@google.coma1226312012-07-26 20:26:44 +0000116
117 connect(&fActionZoomIn, SIGNAL(triggered()), &fMapper, SLOT(map()));
118 connect(&fActionZoomOut, SIGNAL(triggered()), &fMapper, SLOT(map()));
bungeman@google.come8cc6e82013-01-17 16:30:56 +0000119 connect(&fMapper, SIGNAL(mapped(int)), &fCanvasWidget, SLOT(zoom(int)));
chudy@google.coma1226312012-07-26 20:26:44 +0000120
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000121 fInspectorWidget.setDisabled(true);
chudy@google.comd3058f52012-07-19 13:41:27 +0000122 fMenuEdit.setDisabled(true);
123 fMenuNavigate.setDisabled(true);
124 fMenuView.setDisabled(true);
chudy@google.combbad34d2012-08-13 14:26:36 +0000125
126 SkGraphics::Init();
chudy@google.com902ebe52012-06-29 14:21:22 +0000127}
128
chudy@google.combbad34d2012-08-13 14:26:36 +0000129SkDebuggerGUI::~SkDebuggerGUI() {
130 SkGraphics::Term();
131}
chudy@google.com902ebe52012-06-29 14:21:22 +0000132
133void SkDebuggerGUI::actionBreakpoints() {
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000134 fBreakpointsActivated = !fBreakpointsActivated;
chudy@google.comc432f002012-07-10 13:19:25 +0000135 for (int row = 0; row < fListWidget.count(); row++) {
136 QListWidgetItem *item = fListWidget.item(row);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000137 item->setHidden(item->checkState() == Qt::Unchecked && fBreakpointsActivated);
138 }
139}
chudy@google.com902ebe52012-06-29 14:21:22 +0000140
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000141void SkDebuggerGUI::actionToggleIndexStyle() {
142 fIndexStyleToggle = !fIndexStyleToggle;
143 SkListWidget* list = (SkListWidget*) fListWidget.itemDelegate();
skia.committer@gmail.comdb35dab2014-03-27 03:02:48 +0000144 list->setIndexStyle(fIndexStyleToggle ? SkListWidget::kIndex_IndexStyle :
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000145 SkListWidget::kOffset_IndexStyle);
146 fListWidget.update();
147}
148
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000149void SkDebuggerGUI::showDeletes() {
150 fDeletesActivated = !fDeletesActivated;
151 for (int row = 0; row < fListWidget.count(); row++) {
152 QListWidgetItem *item = fListWidget.item(row);
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000153 item->setHidden(fDebugger.isCommandVisible(row) && fDeletesActivated);
chudy@google.com902ebe52012-06-29 14:21:22 +0000154 }
155}
156
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000157// The timed picture playback uses the SkPicturePlayback's profiling stubs
158// to time individual commands. The offsets are needed to map SkPicture
159// offsets to individual commands.
160class SkTimedPicturePlayback : public SkPicturePlayback {
161public:
commit-bot@chromium.org8f831f22014-04-23 22:35:42 +0000162 static SkTimedPicturePlayback* CreateFromStream(SkPicture* picture,
163 SkStream* stream, const SkPictInfo& info,
scroggo@google.com12705322013-10-01 15:30:46 +0000164 SkPicture::InstallPixelRefProc proc,
165 const SkTDArray<bool>& deletedCommands) {
166 // Mimics SkPicturePlayback::CreateFromStream
167 SkAutoTDelete<SkTimedPicturePlayback> playback(SkNEW_ARGS(SkTimedPicturePlayback,
commit-bot@chromium.org8f831f22014-04-23 22:35:42 +0000168 (picture, deletedCommands, info)));
169 if (!playback->parseStream(picture, stream, proc)) {
scroggo@google.com12705322013-10-01 15:30:46 +0000170 return NULL; // we're invalid
171 }
172 return playback.detach();
173 }
174
commit-bot@chromium.org8f831f22014-04-23 22:35:42 +0000175 SkTimedPicturePlayback(SkPicture* picture,
176 const SkTDArray<bool>& deletedCommands,
177 const SkPictInfo& info)
178 : INHERITED(picture, info)
bungeman@google.come8cc6e82013-01-17 16:30:56 +0000179 , fSkipCommands(deletedCommands)
180 , fTot(0.0)
181 , fCurCommand(0) {
robertphillips@google.com6d9c92b2013-05-23 13:21:18 +0000182 fTimes.setCount(deletedCommands.count());
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000183 fTypeTimes.setCount(LAST_DRAWTYPE_ENUM+1);
184 this->resetTimes();
185 }
186
187 void resetTimes() {
robertphillips@google.com6d9c92b2013-05-23 13:21:18 +0000188 for (int i = 0; i < fTimes.count(); ++i) {
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000189 fTimes[i] = 0.0;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000190 }
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000191 for (int i = 0; i < fTypeTimes.count(); ++i) {
192 fTypeTimes[i] = 0.0f;
193 }
194 fTot = 0.0;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000195 }
196
197 int count() const { return fTimes.count(); }
198
199 double time(int index) const { return fTimes[index] / fTot; }
200
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000201 const SkTDArray<double>* typeTimes() const { return &fTypeTimes; }
202
203 double totTime() const { return fTot; }
204
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000205protected:
robertphillips@google.come174a8b2012-11-27 16:04:42 +0000206 BenchSysTimer fTimer;
robertphillips@google.com5f971142012-12-07 20:48:56 +0000207 SkTDArray<bool> fSkipCommands; // has the command been deleted in the GUI?
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000208 SkTDArray<double> fTimes; // sum of time consumed for each command
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000209 SkTDArray<double> fTypeTimes; // sum of time consumed for each type of command (e.g., drawPath)
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000210 double fTot; // total of all times in 'fTimes'
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000211 int fCurType;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000212 int fCurCommand; // the current command being executed/timed
213
robertphillips@google.com6d9c92b2013-05-23 13:21:18 +0000214#ifdef SK_DEVELOPER
215 virtual bool preDraw(int opIndex, int type) SK_OVERRIDE {
216 fCurCommand = opIndex;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000217
robertphillips@google.com5f971142012-12-07 20:48:56 +0000218 if (fSkipCommands[fCurCommand]) {
robertphillips@google.com6d9c92b2013-05-23 13:21:18 +0000219 return true;
robertphillips@google.com5f971142012-12-07 20:48:56 +0000220 }
221
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000222 fCurType = type;
223 // The SkDebugCanvas doesn't recognize these types. This class needs to
224 // convert or else we'll wind up with a mismatch between the type counts
225 // the debugger displays and the profile times.
226 if (DRAW_POS_TEXT_TOP_BOTTOM == type) {
227 fCurType = DRAW_POS_TEXT;
228 } else if (DRAW_POS_TEXT_H_TOP_BOTTOM == type) {
229 fCurType = DRAW_POS_TEXT_H;
230 }
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000231
robertphillips@google.come174a8b2012-11-27 16:04:42 +0000232#if defined(SK_BUILD_FOR_WIN32)
233 // CPU timer doesn't work well on Windows
234 fTimer.startWall();
235#else
236 fTimer.startCpu();
237#endif
robertphillips@google.com5f971142012-12-07 20:48:56 +0000238
robertphillips@google.com6d9c92b2013-05-23 13:21:18 +0000239 return false;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000240 }
241
robertphillips@google.com6d9c92b2013-05-23 13:21:18 +0000242 virtual void postDraw(int opIndex) SK_OVERRIDE {
robertphillips@google.come174a8b2012-11-27 16:04:42 +0000243#if defined(SK_BUILD_FOR_WIN32)
244 // CPU timer doesn't work well on Windows
245 double time = fTimer.endWall();
246#else
247 double time = fTimer.endCpu();
248#endif
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000249
robertphillips@google.com6d9c92b2013-05-23 13:21:18 +0000250 SkASSERT(opIndex == fCurCommand);
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000251 SkASSERT(fCurType <= LAST_DRAWTYPE_ENUM);
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000252
robertphillips@google.come174a8b2012-11-27 16:04:42 +0000253 fTimes[fCurCommand] += time;
254 fTypeTimes[fCurType] += time;
255 fTot += time;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000256 }
robertphillips@google.com6d9c92b2013-05-23 13:21:18 +0000257#endif
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000258
259private:
260 typedef SkPicturePlayback INHERITED;
261};
262
263// Wrap SkPicture to allow installation of an SkTimedPicturePlayback object
264class SkTimedPicture : public SkPicture {
265public:
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000266 static SkTimedPicture* CreateTimedPicture(SkStream* stream,
267 SkPicture::InstallPixelRefProc proc,
268 const SkTDArray<bool>& deletedCommands) {
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000269 SkPictInfo info;
commit-bot@chromium.org6f4fb0f2014-03-03 19:18:39 +0000270 if (!InternalOnly_StreamIsSKP(stream, &info)) {
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000271 return NULL;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000272 }
273
commit-bot@chromium.org8f831f22014-04-23 22:35:42 +0000274 SkTimedPicture* newPict = SkNEW_ARGS(SkTimedPicture, (NULL, info.fWidth, info.fHeight));
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000275 // Check to see if there is a playback to recreate.
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000276 if (stream->readBool()) {
commit-bot@chromium.org8f831f22014-04-23 22:35:42 +0000277 SkTimedPicturePlayback* playback = SkTimedPicturePlayback::CreateFromStream(
278 newPict, stream,
279 info, proc,
scroggo@google.com12705322013-10-01 15:30:46 +0000280 deletedCommands);
281 if (NULL == playback) {
commit-bot@chromium.org8f831f22014-04-23 22:35:42 +0000282 SkDELETE(newPict);
scroggo@google.com12705322013-10-01 15:30:46 +0000283 return NULL;
284 }
commit-bot@chromium.org8f831f22014-04-23 22:35:42 +0000285 newPict->fPlayback = playback;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000286 }
287
commit-bot@chromium.org8f831f22014-04-23 22:35:42 +0000288 return newPict;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000289 }
290
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000291 void resetTimes() { ((SkTimedPicturePlayback*) fPlayback)->resetTimes(); }
292
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000293 int count() const { return ((SkTimedPicturePlayback*) fPlayback)->count(); }
294
295 // return the fraction of the total time this command consumed
296 double time(int index) const { return ((SkTimedPicturePlayback*) fPlayback)->time(index); }
297
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000298 const SkTDArray<double>* typeTimes() const { return ((SkTimedPicturePlayback*) fPlayback)->typeTimes(); }
299
300 double totTime() const { return ((SkTimedPicturePlayback*) fPlayback)->totTime(); }
301
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000302private:
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000303 // disallow default ctor b.c. we don't have a good way to setup the fPlayback ptr
304 SkTimedPicture();
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000305 // Private ctor only used by CreateTimedPicture, which has created the playback.
306 SkTimedPicture(SkTimedPicturePlayback* playback, int width, int height)
307 : INHERITED(playback, width, height) {}
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000308 // disallow the copy ctor - enabling would require copying code from SkPicture
309 SkTimedPicture(const SkTimedPicture& src);
310
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000311 typedef SkPicture INHERITED;
312};
313
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000314// This is a simplification of PictureBenchmark's run with the addition of
315// clearing of the times after the first pass (in resetTimes)
skia.committer@gmail.com34587162012-11-20 02:01:23 +0000316void SkDebuggerGUI::run(SkTimedPicture* pict,
317 sk_tools::PictureRenderer* renderer,
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000318 int repeats) {
319 SkASSERT(pict);
320 if (NULL == pict) {
321 return;
322 }
323
324 SkASSERT(renderer != NULL);
325 if (NULL == renderer) {
326 return;
327 }
328
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000329 renderer->init(pict, NULL, NULL, false);
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000330
331 renderer->setup();
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000332 renderer->render();
commit-bot@chromium.org51c040e2014-03-11 22:58:00 +0000333 renderer->resetState(true); // flush, swapBuffers and Finish
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000334
335 // We throw this away the first batch of times to remove first time effects (such as paging in this program)
336 pict->resetTimes();
337
338 for (int i = 0; i < repeats; ++i) {
339 renderer->setup();
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000340 renderer->render();
commit-bot@chromium.org51c040e2014-03-11 22:58:00 +0000341 renderer->resetState(false); // flush & swapBuffers, but don't Finish
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000342 }
commit-bot@chromium.org51c040e2014-03-11 22:58:00 +0000343 renderer->resetState(true); // flush, swapBuffers and Finish
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000344
345 renderer->end();
346}
347
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000348void SkDebuggerGUI::actionProfile() {
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000349 // In order to profile we pass the command offsets (that were read-in
350 // in loadPicture by the SkOffsetPicture) to an SkTimedPlaybackPicture.
skia.committer@gmail.com884e60b2012-11-16 02:01:17 +0000351 // The SkTimedPlaybackPicture in turn passes the offsets to an
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000352 // SkTimedPicturePlayback object which uses them to track the performance
353 // of individual commands.
354 if (fFileName.isEmpty()) {
355 return;
356 }
357
358 SkFILEStream inputStream;
359
360 inputStream.setPath(fFileName.c_str());
361 if (!inputStream.isValid()) {
362 return;
363 }
364
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000365 SkAutoTUnref<SkTimedPicture> picture(SkTimedPicture::CreateTimedPicture(&inputStream,
366 &SkImageDecoder::DecodeMemory, fSkipCommands));
367 if (NULL == picture.get()) {
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000368 return;
369 }
370
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000371 // For now this #if allows switching between tiled and simple rendering
372 // modes. Eventually this will be accomplished via the GUI
robertphillips@google.come174a8b2012-11-27 16:04:42 +0000373#if 0
374 // With the current batch of SysTimers, profiling in tiled mode
375 // gets swamped by the timing overhead:
376 //
377 // tile mode simple mode
378 // debugger 64.2ms 12.8ms
379 // bench_pictures 16.9ms 12.4ms
380 //
381 // This is b.c. in tiled mode each command is called many more times
382 // but typically does less work on each invocation (due to clipping)
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000383 sk_tools::TiledPictureRenderer* renderer = NULL;
384
385 renderer = SkNEW(sk_tools::TiledPictureRenderer);
386 renderer->setTileWidth(256);
387 renderer->setTileHeight(256);
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000388#else
389 sk_tools::SimplePictureRenderer* renderer = NULL;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000390
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000391 renderer = SkNEW(sk_tools::SimplePictureRenderer);
robertphillips@google.com1447aa32013-01-30 21:09:09 +0000392
393#if SK_SUPPORT_GPU
commit-bot@chromium.orgfde1e7c2013-08-02 13:59:50 +0000394 if (fSettingsWidget.isGLActive()) {
robertphillips@google.com1447aa32013-01-30 21:09:09 +0000395 renderer->setDeviceType(sk_tools::PictureRenderer::kGPU_DeviceType);
commit-bot@chromium.orgfde1e7c2013-08-02 13:59:50 +0000396 renderer->setSampleCount(fSettingsWidget.getGLSampleCount());
robertphillips@google.com1447aa32013-01-30 21:09:09 +0000397 }
398#endif
399
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000400#endif
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000401
robertphillips@google.come174a8b2012-11-27 16:04:42 +0000402 static const int kNumRepeats = 10;
403
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000404 run(picture.get(), renderer, kNumRepeats);
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000405
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000406 SkASSERT(picture->count() == fListWidget.count());
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000407
408 // extract the individual command times from the SkTimedPlaybackPicture
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000409 for (int i = 0; i < picture->count(); ++i) {
410 double temp = picture->time(i);
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000411
412 QListWidgetItem* item = fListWidget.item(i);
413
414 item->setData(Qt::UserRole + 4, 100.0*temp);
415 }
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000416
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000417 setupOverviewText(picture->typeTimes(), picture->totTime(), kNumRepeats);
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000418}
419
chudy@google.com902ebe52012-06-29 14:21:22 +0000420void SkDebuggerGUI::actionCancel() {
chudy@google.comc432f002012-07-10 13:19:25 +0000421 for (int row = 0; row < fListWidget.count(); row++) {
422 fListWidget.item(row)->setHidden(false);
chudy@google.com902ebe52012-06-29 14:21:22 +0000423 }
424}
425
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000426void SkDebuggerGUI::actionClearBreakpoints() {
427 for (int row = 0; row < fListWidget.count(); row++) {
428 QListWidgetItem* item = fListWidget.item(row);
429 item->setCheckState(Qt::Unchecked);
430 item->setData(Qt::DecorationRole,
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000431 QPixmap(":/blank.png"));
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000432 }
433}
434
435void SkDebuggerGUI::actionClearDeletes() {
436 for (int row = 0; row < fListWidget.count(); row++) {
437 QListWidgetItem* item = fListWidget.item(row);
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000438 item->setData(Qt::UserRole + 2, QPixmap(":/blank.png"));
chudy@google.com607357f2012-08-07 16:12:23 +0000439 fDebugger.setCommandVisible(row, true);
robertphillips@google.com5f971142012-12-07 20:48:56 +0000440 fSkipCommands[row] = false;
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000441 }
442 if (fPause) {
443 fCanvasWidget.drawTo(fPausedRow);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000444 fImageWidget.draw();
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000445 } else {
446 fCanvasWidget.drawTo(fListWidget.currentRow());
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000447 fImageWidget.draw();
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000448 }
449}
450
chudy@google.com902ebe52012-06-29 14:21:22 +0000451void SkDebuggerGUI::actionCommandFilter() {
commit-bot@chromium.org22d39332013-11-21 15:37:29 +0000452 fDebugger.highlightCurrentCommand(fSettingsWidget.getVisibilityFilter());
chudy@google.comc432f002012-07-10 13:19:25 +0000453 fCanvasWidget.drawTo(fListWidget.currentRow());
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000454 fImageWidget.draw();
chudy@google.com902ebe52012-06-29 14:21:22 +0000455}
456
457void SkDebuggerGUI::actionClose() {
458 this->close();
459}
460
461void SkDebuggerGUI::actionDelete() {
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000462
robertphillips@google.comdd4b7452013-01-22 19:38:46 +0000463 for (int row = 0; row < fListWidget.count(); ++row) {
464 QListWidgetItem* item = fListWidget.item(row);
465
466 if (!item->isSelected()) {
467 continue;
468 }
469
470 if (fDebugger.isCommandVisible(row)) {
471 item->setData(Qt::UserRole + 2, QPixmap(":/delete.png"));
472 fDebugger.setCommandVisible(row, false);
473 fSkipCommands[row] = true;
474 } else {
475 item->setData(Qt::UserRole + 2, QPixmap(":/blank.png"));
476 fDebugger.setCommandVisible(row, true);
477 fSkipCommands[row] = false;
478 }
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000479 }
480
robertphillips@google.comdd4b7452013-01-22 19:38:46 +0000481 int currentRow = fListWidget.currentRow();
482
chudy@google.come504de02012-07-16 18:35:23 +0000483 if (fPause) {
484 fCanvasWidget.drawTo(fPausedRow);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000485 fImageWidget.draw();
chudy@google.come504de02012-07-16 18:35:23 +0000486 } else {
487 fCanvasWidget.drawTo(currentRow);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000488 fImageWidget.draw();
chudy@google.come504de02012-07-16 18:35:23 +0000489 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000490}
491
robertphillips@google.come8fe4bc2013-02-13 13:26:13 +0000492#if SK_SUPPORT_GPU
commit-bot@chromium.orgfde1e7c2013-08-02 13:59:50 +0000493void SkDebuggerGUI::actionGLWidget() {
494 bool isToggled = fSettingsWidget.isGLActive();
495 if (isToggled) {
496 fCanvasWidget.setGLSampleCount(fSettingsWidget.getGLSampleCount());
497 }
chudy@google.comea5488b2012-07-26 19:38:22 +0000498 fCanvasWidget.setWidgetVisibility(SkCanvasWidget::kGPU_WidgetType, !isToggled);
499}
robertphillips@google.come8fe4bc2013-02-13 13:26:13 +0000500#endif
chudy@google.comea5488b2012-07-26 19:38:22 +0000501
chudy@google.com902ebe52012-06-29 14:21:22 +0000502void SkDebuggerGUI::actionInspector() {
chudy@google.comc432f002012-07-10 13:19:25 +0000503 if (fInspectorWidget.isHidden()) {
504 fInspectorWidget.setHidden(false);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000505 fImageWidget.setHidden(false);
chudy@google.com902ebe52012-06-29 14:21:22 +0000506 } else {
chudy@google.comc432f002012-07-10 13:19:25 +0000507 fInspectorWidget.setHidden(true);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000508 fImageWidget.setHidden(true);
chudy@google.com902ebe52012-06-29 14:21:22 +0000509 }
510}
511
512void SkDebuggerGUI::actionPlay() {
chudy@google.comc432f002012-07-10 13:19:25 +0000513 for (int row = fListWidget.currentRow() + 1; row < fListWidget.count();
chudy@google.com7dcae672012-07-09 20:26:53 +0000514 row++) {
chudy@google.comc432f002012-07-10 13:19:25 +0000515 QListWidgetItem *item = fListWidget.item(row);
chudy@google.com902ebe52012-06-29 14:21:22 +0000516 if (item->checkState() == Qt::Checked) {
chudy@google.comc432f002012-07-10 13:19:25 +0000517 fListWidget.setCurrentItem(item);
chudy@google.com902ebe52012-06-29 14:21:22 +0000518 return;
519 }
520 }
chudy@google.comc432f002012-07-10 13:19:25 +0000521 fListWidget.setCurrentRow(fListWidget.count() - 1);
chudy@google.com902ebe52012-06-29 14:21:22 +0000522}
523
chudy@google.comea5488b2012-07-26 19:38:22 +0000524void SkDebuggerGUI::actionRasterWidget(bool isToggled) {
525 fCanvasWidget.setWidgetVisibility(SkCanvasWidget::kRaster_8888_WidgetType, !isToggled);
526}
527
robertphillips@google.comf4741c12013-02-06 20:13:54 +0000528void SkDebuggerGUI::actionOverdrawVizWidget(bool isToggled) {
529 fDebugger.setOverdrawViz(isToggled);
530 fCanvasWidget.update();
531}
532
commit-bot@chromium.org768ac852014-03-03 16:32:17 +0000533void SkDebuggerGUI::actionMegaVizWidget(bool isToggled) {
534 fDebugger.setMegaViz(isToggled);
535 fCanvasWidget.update();
536}
537
robertphillips@google.com32bbcf82013-10-17 17:56:10 +0000538void SkDebuggerGUI::actionTextureFilter() {
539 SkPaint::FilterLevel level;
540 bool enabled = fSettingsWidget.getFilterOverride(&level);
541 fDebugger.setTexFilterOverride(enabled, level);
542 fCanvasWidget.update();
543}
544
chudy@google.com902ebe52012-06-29 14:21:22 +0000545void SkDebuggerGUI::actionRewind() {
chudy@google.come504de02012-07-16 18:35:23 +0000546 fListWidget.setCurrentRow(0);
chudy@google.com902ebe52012-06-29 14:21:22 +0000547}
548
chudy@google.com0ab03392012-07-28 20:16:11 +0000549void SkDebuggerGUI::actionSave() {
robertphillips@google.come219baf2013-01-28 19:25:43 +0000550 fFileName = fPath.toAscii().data();
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000551 fFileName.append("/");
robertphillips@google.come219baf2013-01-28 19:25:43 +0000552 fFileName.append(fDirectoryWidget.currentItem()->text().toAscii().data());
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000553 saveToFile(fFileName);
chudy@google.com0ab03392012-07-28 20:16:11 +0000554}
555
556void SkDebuggerGUI::actionSaveAs() {
557 QString filename = QFileDialog::getSaveFileName(this, "Save File", "",
558 "Skia Picture (*skp)");
chudy@google.com38b08ce2012-07-28 23:26:10 +0000559 if (!filename.endsWith(".skp", Qt::CaseInsensitive)) {
chudy@google.com0ab03392012-07-28 20:16:11 +0000560 filename.append(".skp");
561 }
djsollen@google.comc3c82162012-11-13 18:35:10 +0000562 saveToFile(SkString(filename.toAscii().data()));
chudy@google.com0ab03392012-07-28 20:16:11 +0000563}
564
chudy@google.com7dcae672012-07-09 20:26:53 +0000565void SkDebuggerGUI::actionScale(float scaleFactor) {
chudy@google.comc432f002012-07-10 13:19:25 +0000566 fSettingsWidget.setZoomText(scaleFactor);
chudy@google.com7dcae672012-07-09 20:26:53 +0000567}
568
chudy@google.com902ebe52012-06-29 14:21:22 +0000569void SkDebuggerGUI::actionSettings() {
chudy@google.comc432f002012-07-10 13:19:25 +0000570 if (fSettingsWidget.isHidden()) {
571 fSettingsWidget.setHidden(false);
chudy@google.com902ebe52012-06-29 14:21:22 +0000572 } else {
chudy@google.comc432f002012-07-10 13:19:25 +0000573 fSettingsWidget.setHidden(true);
chudy@google.com902ebe52012-06-29 14:21:22 +0000574 }
575}
576
577void SkDebuggerGUI::actionStepBack() {
chudy@google.comc432f002012-07-10 13:19:25 +0000578 int currentRow = fListWidget.currentRow();
chudy@google.com902ebe52012-06-29 14:21:22 +0000579 if (currentRow != 0) {
chudy@google.comc432f002012-07-10 13:19:25 +0000580 fListWidget.setCurrentRow(currentRow - 1);
chudy@google.com902ebe52012-06-29 14:21:22 +0000581 }
582}
583
584void SkDebuggerGUI::actionStepForward() {
chudy@google.comc432f002012-07-10 13:19:25 +0000585 int currentRow = fListWidget.currentRow();
chudy@google.com902ebe52012-06-29 14:21:22 +0000586 QString curRow = QString::number(currentRow);
chudy@google.comc432f002012-07-10 13:19:25 +0000587 QString curCount = QString::number(fListWidget.count());
588 if (currentRow < fListWidget.count() - 1) {
589 fListWidget.setCurrentRow(currentRow + 1);
chudy@google.com902ebe52012-06-29 14:21:22 +0000590 }
591}
592
chudy@google.coma9e937c2012-08-03 17:32:05 +0000593void SkDebuggerGUI::drawComplete() {
chudy@google.com607357f2012-08-07 16:12:23 +0000594 fInspectorWidget.setMatrix(fDebugger.getCurrentMatrix());
595 fInspectorWidget.setClip(fDebugger.getCurrentClip());
chudy@google.coma9e937c2012-08-03 17:32:05 +0000596}
597
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000598void SkDebuggerGUI::saveToFile(const SkString& filename) {
599 SkFILEWStream file(filename.c_str());
robertphillips@google.com25bc2f82013-01-22 18:03:56 +0000600 SkAutoTUnref<SkPicture> copy(fDebugger.copyPicture());
601
602 copy->serialize(&file);
chudy@google.com0ab03392012-07-28 20:16:11 +0000603}
604
chudy@google.com902ebe52012-06-29 14:21:22 +0000605void SkDebuggerGUI::loadFile(QListWidgetItem *item) {
606 if (fDirectoryWidgetActive) {
robertphillips@google.come219baf2013-01-28 19:25:43 +0000607 fFileName = fPath.toAscii().data();
jvanverth@google.com0ac6f162013-02-05 19:44:07 +0000608 // don't add a '/' to files in the local directory
609 if (fFileName.size() > 0) {
610 fFileName.append("/");
611 }
robertphillips@google.come219baf2013-01-28 19:25:43 +0000612 fFileName.append(item->text().toAscii().data());
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000613 loadPicture(fFileName);
chudy@google.com902ebe52012-06-29 14:21:22 +0000614 }
615}
616
617void SkDebuggerGUI::openFile() {
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000618 QString temp = QFileDialog::getOpenFileName(this, tr("Open File"), "",
chudy@google.com7dcae672012-07-09 20:26:53 +0000619 tr("Files (*.*)"));
robertphillips@google.comff6e6ba2013-01-28 17:43:26 +0000620 openFile(temp);
621}
622
623void SkDebuggerGUI::openFile(const QString &filename) {
chudy@google.com902ebe52012-06-29 14:21:22 +0000624 fDirectoryWidgetActive = false;
robertphillips@google.comff6e6ba2013-01-28 17:43:26 +0000625 if (!filename.isEmpty()) {
626 QFileInfo pathInfo(filename);
627 loadPicture(SkString(filename.toAscii().data()));
628 setupDirectoryWidget(pathInfo.path());
chudy@google.com902ebe52012-06-29 14:21:22 +0000629 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000630 fDirectoryWidgetActive = true;
631}
632
chudy@google.comc432f002012-07-10 13:19:25 +0000633void SkDebuggerGUI::pauseDrawing(bool isPaused) {
chudy@google.com607357f2012-08-07 16:12:23 +0000634 fPause = isPaused;
635 fPausedRow = fListWidget.currentRow();
636 fCanvasWidget.drawTo(fPausedRow);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000637 fImageWidget.draw();
chudy@google.com7dcae672012-07-09 20:26:53 +0000638}
639
chudy@google.com902ebe52012-06-29 14:21:22 +0000640void SkDebuggerGUI::registerListClick(QListWidgetItem *item) {
chudy@google.comd3058f52012-07-19 13:41:27 +0000641 if(!fLoading) {
642 int currentRow = fListWidget.currentRow();
chudy@google.comd3058f52012-07-19 13:41:27 +0000643
chudy@google.comea5488b2012-07-26 19:38:22 +0000644 if (currentRow != -1) {
645 if (!fPause) {
646 fCanvasWidget.drawTo(currentRow);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000647 fImageWidget.draw();
chudy@google.comd3058f52012-07-19 13:41:27 +0000648 }
chudy@google.com97cee972012-08-07 20:41:37 +0000649 SkTDArray<SkString*> *currInfo = fDebugger.getCommandInfo(
chudy@google.comea5488b2012-07-26 19:38:22 +0000650 currentRow);
651
652 /* TODO(chudy): Add command type before parameters. Rename v
653 * to something more informative. */
chudy@google.com97cee972012-08-07 20:41:37 +0000654 if (currInfo) {
chudy@google.comea5488b2012-07-26 19:38:22 +0000655 QString info;
656 info.append("<b>Parameters: </b><br/>");
chudy@google.com97cee972012-08-07 20:41:37 +0000657 for (int i = 0; i < currInfo->count(); i++) {
658
659 info.append(QString((*currInfo)[i]->c_str()));
chudy@google.comea5488b2012-07-26 19:38:22 +0000660 info.append("<br/>");
661 }
chudy@google.com6bd109a2012-08-14 19:34:13 +0000662 fInspectorWidget.setText(info, SkInspectorWidget::kDetail_TabType);
chudy@google.comea5488b2012-07-26 19:38:22 +0000663 fInspectorWidget.setDisabled(false);
chudy@google.comea5488b2012-07-26 19:38:22 +0000664 }
chudy@google.comd3058f52012-07-19 13:41:27 +0000665 }
chudy@google.comea5488b2012-07-26 19:38:22 +0000666
chudy@google.com902ebe52012-06-29 14:21:22 +0000667 }
668}
669
chudy@google.com9ca9bfe2012-07-12 21:58:14 +0000670void SkDebuggerGUI::selectCommand(int command) {
671 if (fPause) {
672 fListWidget.setCurrentRow(command);
673 }
674}
675
chudy@google.com902ebe52012-06-29 14:21:22 +0000676void SkDebuggerGUI::toggleBreakpoint() {
chudy@google.comc432f002012-07-10 13:19:25 +0000677 QListWidgetItem* item = fListWidget.currentItem();
chudy@google.com902ebe52012-06-29 14:21:22 +0000678 if (item->checkState() == Qt::Unchecked) {
679 item->setCheckState(Qt::Checked);
chudy@google.come565de42012-07-12 14:15:54 +0000680 item->setData(Qt::DecorationRole,
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000681 QPixmap(":/breakpoint_16x16.png"));
chudy@google.com902ebe52012-06-29 14:21:22 +0000682 } else {
chudy@google.com902ebe52012-06-29 14:21:22 +0000683 item->setCheckState(Qt::Unchecked);
chudy@google.come565de42012-07-12 14:15:54 +0000684 item->setData(Qt::DecorationRole,
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000685 QPixmap(":/blank.png"));
chudy@google.com902ebe52012-06-29 14:21:22 +0000686 }
687}
688
689void SkDebuggerGUI::toggleDirectory() {
chudy@google.com607357f2012-08-07 16:12:23 +0000690 fDirectoryWidget.setHidden(!fDirectoryWidget.isHidden());
chudy@google.com902ebe52012-06-29 14:21:22 +0000691}
692
693void SkDebuggerGUI::toggleFilter(QString string) {
chudy@google.comc432f002012-07-10 13:19:25 +0000694 for (int row = 0; row < fListWidget.count(); row++) {
695 QListWidgetItem *item = fListWidget.item(row);
chudy@google.com607357f2012-08-07 16:12:23 +0000696 item->setHidden(item->text() != string);
chudy@google.com902ebe52012-06-29 14:21:22 +0000697 }
698}
699
700void SkDebuggerGUI::setupUi(QMainWindow *SkDebuggerGUI) {
701 QIcon windowIcon;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000702 windowIcon.addFile(QString::fromUtf8(":/skia.png"), QSize(),
chudy@google.com7dcae672012-07-09 20:26:53 +0000703 QIcon::Normal, QIcon::Off);
chudy@google.com902ebe52012-06-29 14:21:22 +0000704 SkDebuggerGUI->setObjectName(QString::fromUtf8("SkDebuggerGUI"));
705 SkDebuggerGUI->resize(1200, 1000);
706 SkDebuggerGUI->setWindowIcon(windowIcon);
chudy@google.comc432f002012-07-10 13:19:25 +0000707 SkDebuggerGUI->setWindowTitle("Skia Debugger");
chudy@google.com902ebe52012-06-29 14:21:22 +0000708
chudy@google.come504de02012-07-16 18:35:23 +0000709 fActionOpen.setShortcuts(QKeySequence::Open);
chudy@google.comc432f002012-07-10 13:19:25 +0000710 fActionOpen.setText("Open");
chudy@google.com902ebe52012-06-29 14:21:22 +0000711
712 QIcon breakpoint;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000713 breakpoint.addFile(QString::fromUtf8(":/breakpoint.png"),
chudy@google.com7dcae672012-07-09 20:26:53 +0000714 QSize(), QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000715 fActionBreakpoint.setShortcut(QKeySequence(tr("Ctrl+B")));
chudy@google.comc432f002012-07-10 13:19:25 +0000716 fActionBreakpoint.setIcon(breakpoint);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000717 fActionBreakpoint.setText("Breakpoints");
chudy@google.com902ebe52012-06-29 14:21:22 +0000718
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000719 fActionToggleIndexStyle.setShortcut(QKeySequence(tr("Ctrl+T")));
720 fActionToggleIndexStyle.setText("Toggle Index Style");
721
chudy@google.com902ebe52012-06-29 14:21:22 +0000722 QIcon cancel;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000723 cancel.addFile(QString::fromUtf8(":/reload.png"), QSize(),
chudy@google.com7dcae672012-07-09 20:26:53 +0000724 QIcon::Normal, QIcon::Off);
chudy@google.comc432f002012-07-10 13:19:25 +0000725 fActionCancel.setIcon(cancel);
726 fActionCancel.setText("Clear Filter");
chudy@google.com902ebe52012-06-29 14:21:22 +0000727
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000728 fActionClearBreakpoints.setShortcut(QKeySequence(tr("Alt+B")));
729 fActionClearBreakpoints.setText("Clear Breakpoints");
730
731 fActionClearDeletes.setShortcut(QKeySequence(tr("Alt+X")));
732 fActionClearDeletes.setText("Clear Deletes");
733
chudy@google.come504de02012-07-16 18:35:23 +0000734 fActionClose.setShortcuts(QKeySequence::Quit);
chudy@google.comc432f002012-07-10 13:19:25 +0000735 fActionClose.setText("Exit");
chudy@google.com902ebe52012-06-29 14:21:22 +0000736
chudy@google.come504de02012-07-16 18:35:23 +0000737 fActionCreateBreakpoint.setShortcut(QKeySequence(tr("B")));
738 fActionCreateBreakpoint.setText("Set Breakpoint");
739
740 fActionDelete.setShortcut(QKeySequence(tr("X")));
chudy@google.comc432f002012-07-10 13:19:25 +0000741 fActionDelete.setText("Delete Command");
chudy@google.com902ebe52012-06-29 14:21:22 +0000742
chudy@google.come504de02012-07-16 18:35:23 +0000743 fActionDirectory.setShortcut(QKeySequence(tr("Ctrl+D")));
744 fActionDirectory.setText("Directory");
chudy@google.com902ebe52012-06-29 14:21:22 +0000745
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000746 QIcon profile;
robertphillips@google.comd1636362012-11-19 18:25:09 +0000747 profile.addFile(QString::fromUtf8(":/profile.png"), QSize(),
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000748 QIcon::Normal, QIcon::Off);
749 fActionProfile.setIcon(profile);
750 fActionProfile.setText("Profile");
robertphillips@google.come099bc42012-11-19 16:26:40 +0000751 fActionProfile.setDisabled(true);
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000752
chudy@google.comc432f002012-07-10 13:19:25 +0000753 QIcon inspector;
robertphillips@google.comd1636362012-11-19 18:25:09 +0000754 inspector.addFile(QString::fromUtf8(":/inspector.png"),
chudy@google.comc432f002012-07-10 13:19:25 +0000755 QSize(), QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000756 fActionInspector.setShortcut(QKeySequence(tr("Ctrl+I")));
chudy@google.comc432f002012-07-10 13:19:25 +0000757 fActionInspector.setIcon(inspector);
chudy@google.come504de02012-07-16 18:35:23 +0000758 fActionInspector.setText("Inspector");
chudy@google.com902ebe52012-06-29 14:21:22 +0000759
bungeman@google.com2ff6d1d2013-07-01 14:24:12 +0000760 QIcon settings;
761 settings.addFile(QString::fromUtf8(":/inspector.png"),
762 QSize(), QIcon::Normal, QIcon::Off);
763 fActionSettings.setShortcut(QKeySequence(tr("Ctrl+G")));
764 fActionSettings.setIcon(settings);
765 fActionSettings.setText("Settings");
skia.committer@gmail.com0d55dd72013-07-02 07:00:59 +0000766
chudy@google.comc432f002012-07-10 13:19:25 +0000767 QIcon play;
robertphillips@google.comd1636362012-11-19 18:25:09 +0000768 play.addFile(QString::fromUtf8(":/play.png"), QSize(),
chudy@google.comc432f002012-07-10 13:19:25 +0000769 QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000770 fActionPlay.setShortcut(QKeySequence(tr("Ctrl+P")));
chudy@google.comc432f002012-07-10 13:19:25 +0000771 fActionPlay.setIcon(play);
772 fActionPlay.setText("Play");
chudy@google.com902ebe52012-06-29 14:21:22 +0000773
chudy@google.come504de02012-07-16 18:35:23 +0000774 QIcon pause;
robertphillips@google.comd1636362012-11-19 18:25:09 +0000775 pause.addFile(QString::fromUtf8(":/pause.png"), QSize(),
chudy@google.comc432f002012-07-10 13:19:25 +0000776 QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000777 fActionPause.setShortcut(QKeySequence(tr("Space")));
778 fActionPause.setCheckable(true);
779 fActionPause.setIcon(pause);
780 fActionPause.setText("Pause");
781
chudy@google.comc432f002012-07-10 13:19:25 +0000782 QIcon rewind;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000783 rewind.addFile(QString::fromUtf8(":/rewind.png"), QSize(),
chudy@google.comc432f002012-07-10 13:19:25 +0000784 QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000785 fActionRewind.setShortcut(QKeySequence(tr("Ctrl+R")));
chudy@google.comc432f002012-07-10 13:19:25 +0000786 fActionRewind.setIcon(rewind);
787 fActionRewind.setText("Rewind");
chudy@google.com902ebe52012-06-29 14:21:22 +0000788
chudy@google.com0ab03392012-07-28 20:16:11 +0000789 fActionSave.setShortcut(QKeySequence::Save);
790 fActionSave.setText("Save");
791 fActionSave.setDisabled(true);
792 fActionSaveAs.setShortcut(QKeySequence::SaveAs);
793 fActionSaveAs.setText("Save As");
794 fActionSaveAs.setDisabled(true);
795
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000796 fActionShowDeletes.setShortcut(QKeySequence(tr("Ctrl+X")));
797 fActionShowDeletes.setText("Deleted Commands");
798
chudy@google.comc432f002012-07-10 13:19:25 +0000799 QIcon stepBack;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000800 stepBack.addFile(QString::fromUtf8(":/previous.png"), QSize(),
chudy@google.comc432f002012-07-10 13:19:25 +0000801 QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000802 fActionStepBack.setShortcut(QKeySequence(tr("[")));
chudy@google.comc432f002012-07-10 13:19:25 +0000803 fActionStepBack.setIcon(stepBack);
804 fActionStepBack.setText("Step Back");
chudy@google.com902ebe52012-06-29 14:21:22 +0000805
chudy@google.comc432f002012-07-10 13:19:25 +0000806 QIcon stepForward;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000807 stepForward.addFile(QString::fromUtf8(":/next.png"),
chudy@google.comc432f002012-07-10 13:19:25 +0000808 QSize(), QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000809 fActionStepForward.setShortcut(QKeySequence(tr("]")));
chudy@google.comc432f002012-07-10 13:19:25 +0000810 fActionStepForward.setIcon(stepForward);
811 fActionStepForward.setText("Step Forward");
812
chudy@google.coma1226312012-07-26 20:26:44 +0000813 fActionZoomIn.setShortcut(QKeySequence(tr("Ctrl+=")));
814 fActionZoomIn.setText("Zoom In");
815 fActionZoomOut.setShortcut(QKeySequence(tr("Ctrl+-")));
816 fActionZoomOut.setText("Zoom Out");
817
chudy@google.comc432f002012-07-10 13:19:25 +0000818 fListWidget.setItemDelegate(new SkListWidget(&fListWidget));
819 fListWidget.setObjectName(QString::fromUtf8("listWidget"));
commit-bot@chromium.orgbcd431e2013-11-21 13:41:37 +0000820 fListWidget.setMinimumWidth(250);
chudy@google.comc432f002012-07-10 13:19:25 +0000821
822 fFilter.addItem("--Filter By Available Commands--");
823
commit-bot@chromium.orgbcd431e2013-11-21 13:41:37 +0000824 fDirectoryWidget.setMinimumWidth(250);
chudy@google.comc432f002012-07-10 13:19:25 +0000825 fDirectoryWidget.setStyleSheet("QListWidget::Item {padding: 5px;}");
826
827 fCanvasWidget.setSizePolicy(QSizePolicy::Expanding,
chudy@google.com7dcae672012-07-09 20:26:53 +0000828 QSizePolicy::Expanding);
chudy@google.com902ebe52012-06-29 14:21:22 +0000829
skia.committer@gmail.com1c9c0d32012-11-22 02:02:41 +0000830 fImageWidget.setFixedSize(SkImageWidget::kImageWidgetWidth,
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000831 SkImageWidget::kImageWidgetHeight);
832
chudy@google.comc432f002012-07-10 13:19:25 +0000833 fInspectorWidget.setSizePolicy(QSizePolicy::Expanding,
chudy@google.com7dcae672012-07-09 20:26:53 +0000834 QSizePolicy::Expanding);
chudy@google.comc432f002012-07-10 13:19:25 +0000835 fInspectorWidget.setMaximumHeight(300);
chudy@google.com902ebe52012-06-29 14:21:22 +0000836
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000837 fSettingsAndImageLayout.setSpacing(6);
838 fSettingsAndImageLayout.addWidget(&fSettingsWidget);
839 fSettingsAndImageLayout.addWidget(&fImageWidget);
840
chudy@google.comc432f002012-07-10 13:19:25 +0000841 fSettingsWidget.setSizePolicy(QSizePolicy::Expanding,
842 QSizePolicy::Expanding);
843 fSettingsWidget.setMaximumWidth(250);
chudy@google.com902ebe52012-06-29 14:21:22 +0000844
commit-bot@chromium.orgbcd431e2013-11-21 13:41:37 +0000845 fLeftColumnSplitter.addWidget(&fListWidget);
846 fLeftColumnSplitter.addWidget(&fDirectoryWidget);
847 fLeftColumnSplitter.setOrientation(Qt::Vertical);
chudy@google.com902ebe52012-06-29 14:21:22 +0000848
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000849 fCanvasSettingsAndImageLayout.setSpacing(6);
850 fCanvasSettingsAndImageLayout.addWidget(&fCanvasWidget);
851 fCanvasSettingsAndImageLayout.addLayout(&fSettingsAndImageLayout);
852
chudy@google.comc432f002012-07-10 13:19:25 +0000853 fMainAndRightColumnLayout.setSpacing(6);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000854 fMainAndRightColumnLayout.addLayout(&fCanvasSettingsAndImageLayout);
chudy@google.comc432f002012-07-10 13:19:25 +0000855 fMainAndRightColumnLayout.addWidget(&fInspectorWidget);
commit-bot@chromium.orgbcd431e2013-11-21 13:41:37 +0000856 fMainAndRightColumnWidget.setLayout(&fMainAndRightColumnLayout);
chudy@google.com902ebe52012-06-29 14:21:22 +0000857
commit-bot@chromium.orgbcd431e2013-11-21 13:41:37 +0000858 fCentralSplitter.addWidget(&fLeftColumnSplitter);
859 fCentralSplitter.addWidget(&fMainAndRightColumnWidget);
860 fCentralSplitter.setStretchFactor(0, 0);
861 fCentralSplitter.setStretchFactor(1, 1);
chudy@google.comc432f002012-07-10 13:19:25 +0000862
commit-bot@chromium.orgbcd431e2013-11-21 13:41:37 +0000863 SkDebuggerGUI->setCentralWidget(&fCentralSplitter);
chudy@google.comc432f002012-07-10 13:19:25 +0000864 SkDebuggerGUI->setStatusBar(&fStatusBar);
865
chudy@google.come504de02012-07-16 18:35:23 +0000866 fToolBar.setIconSize(QSize(32, 32));
chudy@google.comc432f002012-07-10 13:19:25 +0000867 fToolBar.setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
868 SkDebuggerGUI->addToolBar(Qt::TopToolBarArea, &fToolBar);
chudy@google.com902ebe52012-06-29 14:21:22 +0000869
chudy@google.com0ab03392012-07-28 20:16:11 +0000870 fSpacer.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
chudy@google.com902ebe52012-06-29 14:21:22 +0000871
chudy@google.comc432f002012-07-10 13:19:25 +0000872 fToolBar.addAction(&fActionRewind);
873 fToolBar.addAction(&fActionStepBack);
chudy@google.come504de02012-07-16 18:35:23 +0000874 fToolBar.addAction(&fActionPause);
chudy@google.comc432f002012-07-10 13:19:25 +0000875 fToolBar.addAction(&fActionStepForward);
876 fToolBar.addAction(&fActionPlay);
877 fToolBar.addSeparator();
chudy@google.come504de02012-07-16 18:35:23 +0000878 fToolBar.addAction(&fActionInspector);
bungeman@google.com2ff6d1d2013-07-01 14:24:12 +0000879 fToolBar.addAction(&fActionSettings);
chudy@google.comc432f002012-07-10 13:19:25 +0000880 fToolBar.addSeparator();
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000881 fToolBar.addAction(&fActionProfile);
882
883 fToolBar.addSeparator();
chudy@google.com0ab03392012-07-28 20:16:11 +0000884 fToolBar.addWidget(&fSpacer);
chudy@google.comc432f002012-07-10 13:19:25 +0000885 fToolBar.addWidget(&fFilter);
886 fToolBar.addAction(&fActionCancel);
chudy@google.com902ebe52012-06-29 14:21:22 +0000887
888 // TODO(chudy): Remove static call.
889 fDirectoryWidgetActive = false;
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000890 fFileName = "";
robertphillips@google.comff6e6ba2013-01-28 17:43:26 +0000891 setupDirectoryWidget("");
chudy@google.com902ebe52012-06-29 14:21:22 +0000892 fDirectoryWidgetActive = true;
893
chudy@google.com902ebe52012-06-29 14:21:22 +0000894 // Menu Bar
chudy@google.comc432f002012-07-10 13:19:25 +0000895 fMenuFile.setTitle("File");
896 fMenuFile.addAction(&fActionOpen);
chudy@google.com0ab03392012-07-28 20:16:11 +0000897 fMenuFile.addAction(&fActionSave);
898 fMenuFile.addAction(&fActionSaveAs);
chudy@google.comc432f002012-07-10 13:19:25 +0000899 fMenuFile.addAction(&fActionClose);
chudy@google.come504de02012-07-16 18:35:23 +0000900
901 fMenuEdit.setTitle("Edit");
902 fMenuEdit.addAction(&fActionDelete);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000903 fMenuEdit.addAction(&fActionClearDeletes);
904 fMenuEdit.addSeparator();
chudy@google.come504de02012-07-16 18:35:23 +0000905 fMenuEdit.addAction(&fActionCreateBreakpoint);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000906 fMenuEdit.addAction(&fActionClearBreakpoints);
chudy@google.come504de02012-07-16 18:35:23 +0000907
chudy@google.comc432f002012-07-10 13:19:25 +0000908 fMenuNavigate.setTitle("Navigate");
chudy@google.come504de02012-07-16 18:35:23 +0000909 fMenuNavigate.addAction(&fActionRewind);
910 fMenuNavigate.addAction(&fActionStepBack);
911 fMenuNavigate.addAction(&fActionStepForward);
912 fMenuNavigate.addAction(&fActionPlay);
913 fMenuNavigate.addAction(&fActionPause);
chudy@google.comc432f002012-07-10 13:19:25 +0000914 fMenuNavigate.addAction(&fActionGoToLine);
chudy@google.come504de02012-07-16 18:35:23 +0000915
chudy@google.comc432f002012-07-10 13:19:25 +0000916 fMenuView.setTitle("View");
chudy@google.come504de02012-07-16 18:35:23 +0000917 fMenuView.addAction(&fActionBreakpoint);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000918 fMenuView.addAction(&fActionShowDeletes);
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000919 fMenuView.addAction(&fActionToggleIndexStyle);
chudy@google.coma1226312012-07-26 20:26:44 +0000920 fMenuView.addAction(&fActionZoomIn);
921 fMenuView.addAction(&fActionZoomOut);
chudy@google.come504de02012-07-16 18:35:23 +0000922
923 fMenuWindows.setTitle("Window");
924 fMenuWindows.addAction(&fActionInspector);
bungeman@google.com2ff6d1d2013-07-01 14:24:12 +0000925 fMenuWindows.addAction(&fActionSettings);
chudy@google.come504de02012-07-16 18:35:23 +0000926 fMenuWindows.addAction(&fActionDirectory);
chudy@google.comc432f002012-07-10 13:19:25 +0000927
928 fActionGoToLine.setText("Go to Line...");
929 fActionGoToLine.setDisabled(true);
930 fMenuBar.addAction(fMenuFile.menuAction());
chudy@google.come504de02012-07-16 18:35:23 +0000931 fMenuBar.addAction(fMenuEdit.menuAction());
chudy@google.comc432f002012-07-10 13:19:25 +0000932 fMenuBar.addAction(fMenuView.menuAction());
933 fMenuBar.addAction(fMenuNavigate.menuAction());
chudy@google.come504de02012-07-16 18:35:23 +0000934 fMenuBar.addAction(fMenuWindows.menuAction());
chudy@google.com902ebe52012-06-29 14:21:22 +0000935
chudy@google.com7dcae672012-07-09 20:26:53 +0000936 fPause = false;
937
chudy@google.comc432f002012-07-10 13:19:25 +0000938 SkDebuggerGUI->setMenuBar(&fMenuBar);
chudy@google.com902ebe52012-06-29 14:21:22 +0000939 QMetaObject::connectSlotsByName(SkDebuggerGUI);
940}
941
robertphillips@google.comff6e6ba2013-01-28 17:43:26 +0000942void SkDebuggerGUI::setupDirectoryWidget(const QString& path) {
943 fPath = path;
944 QDir dir(path);
chudy@google.com902ebe52012-06-29 14:21:22 +0000945 QRegExp r(".skp");
chudy@google.comc432f002012-07-10 13:19:25 +0000946 fDirectoryWidget.clear();
947 const QStringList files = dir.entryList();
chudy@google.com902ebe52012-06-29 14:21:22 +0000948 foreach (QString f, files) {
chudy@google.com7dcae672012-07-09 20:26:53 +0000949 if (f.contains(r))
chudy@google.comc432f002012-07-10 13:19:25 +0000950 fDirectoryWidget.addItem(f);
chudy@google.com902ebe52012-06-29 14:21:22 +0000951 }
952}
953
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000954void SkDebuggerGUI::loadPicture(const SkString& fileName) {
955 fFileName = fileName;
chudy@google.comd3058f52012-07-19 13:41:27 +0000956 fLoading = true;
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000957 SkStream* stream = SkNEW_ARGS(SkFILEStream, (fileName.c_str()));
robertphillips@google.com2d40ec42013-02-07 20:39:40 +0000958
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000959 SkPicture* picture = SkPicture::CreateFromStream(stream);
robertphillips@google.com2d40ec42013-02-07 20:39:40 +0000960
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000961 if (NULL == picture) {
robertphillips@google.com2d40ec42013-02-07 20:39:40 +0000962 QMessageBox::critical(this, "Error loading file", "Couldn't read file, sorry.");
963 SkSafeUnref(stream);
964 return;
965 }
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000966
chudy@google.com686e6802012-08-14 16:00:32 +0000967 fCanvasWidget.resetWidgetTransform();
chudy@google.com607357f2012-08-07 16:12:23 +0000968 fDebugger.loadPicture(picture);
chudy@google.com4c7962e2012-08-14 19:38:31 +0000969
robertphillips@google.com6d9c92b2013-05-23 13:21:18 +0000970 fSkipCommands.setCount(fDebugger.getSize());
971 for (int i = 0; i < fSkipCommands.count(); ++i) {
robertphillips@google.com5f971142012-12-07 20:48:56 +0000972 fSkipCommands[i] = false;
973 }
974
chudy@google.com607357f2012-08-07 16:12:23 +0000975 SkSafeUnref(stream);
976 SkSafeUnref(picture);
977
chudy@google.com97cee972012-08-07 20:41:37 +0000978 // Will this automatically clear out due to nature of refcnt?
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000979 SkTArray<SkString>* commands = fDebugger.getDrawCommandsAsStrings();
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000980 SkTDArray<size_t>* offsets = fDebugger.getDrawCommandOffsets();
981 SkASSERT(commands->count() == offsets->count());
chudy@google.com607357f2012-08-07 16:12:23 +0000982
robertphillips@google.com6d9c92b2013-05-23 13:21:18 +0000983 fActionProfile.setDisabled(false);
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000984
chudy@google.com7dcae672012-07-09 20:26:53 +0000985 /* fDebugCanvas is reinitialized every load picture. Need it to retain value
chudy@google.com607357f2012-08-07 16:12:23 +0000986 * of the visibility filter.
987 * TODO(chudy): This should be deprecated since fDebugger is not
988 * recreated.
989 * */
commit-bot@chromium.org22d39332013-11-21 15:37:29 +0000990 fDebugger.highlightCurrentCommand(fSettingsWidget.getVisibilityFilter());
chudy@google.com607357f2012-08-07 16:12:23 +0000991
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000992 this->setupListWidget(commands, offsets);
993 this->setupComboBox(commands);
994 this->setupOverviewText(NULL, 0.0, 1);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000995 fInspectorWidget.setDisabled(false);
chudy@google.come606d6e2012-07-12 14:31:25 +0000996 fSettingsWidget.setDisabled(false);
chudy@google.comd3058f52012-07-19 13:41:27 +0000997 fMenuEdit.setDisabled(false);
998 fMenuNavigate.setDisabled(false);
999 fMenuView.setDisabled(false);
chudy@google.com0ab03392012-07-28 20:16:11 +00001000 fActionSave.setDisabled(false);
1001 fActionSaveAs.setDisabled(false);
chudy@google.comd3058f52012-07-19 13:41:27 +00001002 fLoading = false;
1003 actionPlay();
chudy@google.com902ebe52012-06-29 14:21:22 +00001004}
1005
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +00001006void SkDebuggerGUI::setupListWidget(SkTArray<SkString>* commands, SkTDArray<size_t>* offsets) {
1007 SkASSERT(commands->count() == offsets->count());
chudy@google.comc432f002012-07-10 13:19:25 +00001008 fListWidget.clear();
chudy@google.com902ebe52012-06-29 14:21:22 +00001009 int counter = 0;
robertphillips@google.com30d35f22012-11-06 16:45:36 +00001010 int indent = 0;
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +00001011 for (int i = 0; i < commands->count(); i++) {
chudy@google.com902ebe52012-06-29 14:21:22 +00001012 QListWidgetItem *item = new QListWidgetItem();
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +00001013 item->setData(Qt::DisplayRole, (*commands)[i].c_str());
chudy@google.com902ebe52012-06-29 14:21:22 +00001014 item->setData(Qt::UserRole + 1, counter++);
robertphillips@google.com30d35f22012-11-06 16:45:36 +00001015
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +00001016 if (0 == strcmp("Restore", (*commands)[i].c_str()) ||
1017 0 == strcmp("EndCommentGroup", (*commands)[i].c_str()) ||
1018 0 == strcmp("PopCull", (*commands)[i].c_str())) {
robertphillips@google.com30d35f22012-11-06 16:45:36 +00001019 indent -= 10;
1020 }
1021
1022 item->setData(Qt::UserRole + 3, indent);
1023
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +00001024 if (0 == strcmp("Save", (*commands)[i].c_str()) ||
1025 0 == strcmp("Save Layer", (*commands)[i].c_str()) ||
1026 0 == strcmp("BeginCommentGroup", (*commands)[i].c_str()) ||
1027 0 == strcmp("PushCull", (*commands)[i].c_str())) {
robertphillips@google.com30d35f22012-11-06 16:45:36 +00001028 indent += 10;
1029 }
1030
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +00001031 item->setData(Qt::UserRole + 4, -1);
1032 item->setData(Qt::UserRole + 5, (int)(*offsets)[i]);
robertphillips@google.comd26c7062012-11-12 20:42:12 +00001033
chudy@google.comc432f002012-07-10 13:19:25 +00001034 fListWidget.addItem(item);
chudy@google.com902ebe52012-06-29 14:21:22 +00001035 }
1036}
1037
skia.committer@gmail.com91274b92013-03-13 07:01:04 +00001038void SkDebuggerGUI::setupOverviewText(const SkTDArray<double>* typeTimes,
robertphillips@google.come428f9b2013-03-12 15:33:40 +00001039 double totTime,
1040 int numRuns) {
borenet@google.com2d9dbd42013-03-12 13:07:40 +00001041 SkString overview;
robertphillips@google.come428f9b2013-03-12 15:33:40 +00001042 fDebugger.getOverviewText(typeTimes, totTime, &overview, numRuns);
borenet@google.com2d9dbd42013-03-12 13:07:40 +00001043 fInspectorWidget.setText(overview.c_str(), SkInspectorWidget::kOverview_TabType);
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +00001044}
1045
1046void SkDebuggerGUI::setupComboBox(SkTArray<SkString>* command) {
1047 fFilter.clear();
1048 fFilter.addItem("--Filter By Available Commands--");
1049
1050 std::map<std::string, int> map;
1051 for (int i = 0; i < command->count(); i++) {
1052 map[(*command)[i].c_str()]++;
1053 }
1054
skia.committer@gmail.com34587162012-11-20 02:01:23 +00001055 for (std::map<std::string, int>::iterator it = map.begin(); it != map.end();
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +00001056 ++it) {
1057 fFilter.addItem((it->first).c_str());
1058 }
chudy@google.com902ebe52012-06-29 14:21:22 +00001059
1060 // NOTE(chudy): Makes first item unselectable.
chudy@google.com7dcae672012-07-09 20:26:53 +00001061 QStandardItemModel* model = qobject_cast<QStandardItemModel*>(
chudy@google.comc432f002012-07-10 13:19:25 +00001062 fFilter.model());
1063 QModelIndex firstIndex = model->index(0, fFilter.modelColumn(),
1064 fFilter.rootModelIndex());
chudy@google.com902ebe52012-06-29 14:21:22 +00001065 QStandardItem* firstItem = model->itemFromIndex(firstIndex);
1066 firstItem->setSelectable(false);
1067}