blob: 58b8da790e1841306942ce803af670316379590c [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:
scroggo@google.com12705322013-10-01 15:30:46 +0000162 static SkTimedPicturePlayback* CreateFromStream(SkStream* stream, const SkPictInfo& info,
163 SkPicture::InstallPixelRefProc proc,
164 const SkTDArray<bool>& deletedCommands) {
165 // Mimics SkPicturePlayback::CreateFromStream
166 SkAutoTDelete<SkTimedPicturePlayback> playback(SkNEW_ARGS(SkTimedPicturePlayback,
167 (deletedCommands)));
168 if (!playback->parseStream(stream, info, proc)) {
169 return NULL; // we're invalid
170 }
171 return playback.detach();
172 }
173
174 SkTimedPicturePlayback(const SkTDArray<bool>& deletedCommands)
175 : INHERITED()
bungeman@google.come8cc6e82013-01-17 16:30:56 +0000176 , fSkipCommands(deletedCommands)
177 , fTot(0.0)
178 , fCurCommand(0) {
robertphillips@google.com6d9c92b2013-05-23 13:21:18 +0000179 fTimes.setCount(deletedCommands.count());
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000180 fTypeTimes.setCount(LAST_DRAWTYPE_ENUM+1);
181 this->resetTimes();
182 }
183
184 void resetTimes() {
robertphillips@google.com6d9c92b2013-05-23 13:21:18 +0000185 for (int i = 0; i < fTimes.count(); ++i) {
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000186 fTimes[i] = 0.0;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000187 }
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000188 for (int i = 0; i < fTypeTimes.count(); ++i) {
189 fTypeTimes[i] = 0.0f;
190 }
191 fTot = 0.0;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000192 }
193
194 int count() const { return fTimes.count(); }
195
196 double time(int index) const { return fTimes[index] / fTot; }
197
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000198 const SkTDArray<double>* typeTimes() const { return &fTypeTimes; }
199
200 double totTime() const { return fTot; }
201
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000202protected:
robertphillips@google.come174a8b2012-11-27 16:04:42 +0000203 BenchSysTimer fTimer;
robertphillips@google.com5f971142012-12-07 20:48:56 +0000204 SkTDArray<bool> fSkipCommands; // has the command been deleted in the GUI?
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000205 SkTDArray<double> fTimes; // sum of time consumed for each command
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000206 SkTDArray<double> fTypeTimes; // sum of time consumed for each type of command (e.g., drawPath)
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000207 double fTot; // total of all times in 'fTimes'
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000208 int fCurType;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000209 int fCurCommand; // the current command being executed/timed
210
robertphillips@google.com6d9c92b2013-05-23 13:21:18 +0000211#ifdef SK_DEVELOPER
212 virtual bool preDraw(int opIndex, int type) SK_OVERRIDE {
213 fCurCommand = opIndex;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000214
robertphillips@google.com5f971142012-12-07 20:48:56 +0000215 if (fSkipCommands[fCurCommand]) {
robertphillips@google.com6d9c92b2013-05-23 13:21:18 +0000216 return true;
robertphillips@google.com5f971142012-12-07 20:48:56 +0000217 }
218
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000219 fCurType = type;
220 // The SkDebugCanvas doesn't recognize these types. This class needs to
221 // convert or else we'll wind up with a mismatch between the type counts
222 // the debugger displays and the profile times.
223 if (DRAW_POS_TEXT_TOP_BOTTOM == type) {
224 fCurType = DRAW_POS_TEXT;
225 } else if (DRAW_POS_TEXT_H_TOP_BOTTOM == type) {
226 fCurType = DRAW_POS_TEXT_H;
227 }
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000228
robertphillips@google.come174a8b2012-11-27 16:04:42 +0000229#if defined(SK_BUILD_FOR_WIN32)
230 // CPU timer doesn't work well on Windows
231 fTimer.startWall();
232#else
233 fTimer.startCpu();
234#endif
robertphillips@google.com5f971142012-12-07 20:48:56 +0000235
robertphillips@google.com6d9c92b2013-05-23 13:21:18 +0000236 return false;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000237 }
238
robertphillips@google.com6d9c92b2013-05-23 13:21:18 +0000239 virtual void postDraw(int opIndex) SK_OVERRIDE {
robertphillips@google.come174a8b2012-11-27 16:04:42 +0000240#if defined(SK_BUILD_FOR_WIN32)
241 // CPU timer doesn't work well on Windows
242 double time = fTimer.endWall();
243#else
244 double time = fTimer.endCpu();
245#endif
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000246
robertphillips@google.com6d9c92b2013-05-23 13:21:18 +0000247 SkASSERT(opIndex == fCurCommand);
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000248 SkASSERT(fCurType <= LAST_DRAWTYPE_ENUM);
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000249
robertphillips@google.come174a8b2012-11-27 16:04:42 +0000250 fTimes[fCurCommand] += time;
251 fTypeTimes[fCurType] += time;
252 fTot += time;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000253 }
robertphillips@google.com6d9c92b2013-05-23 13:21:18 +0000254#endif
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000255
256private:
scroggo@google.com12705322013-10-01 15:30:46 +0000257 // SkPicturePlayback::parseStream is protected, so it can be
258 // called here, but not by our static factory function. This
259 // allows the factory function to call it.
260 bool parseStream(SkStream* stream, const SkPictInfo& info,
261 SkPicture::InstallPixelRefProc proc) {
262 return this->INHERITED::parseStream(stream, info, proc);
263 }
264
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000265 typedef SkPicturePlayback INHERITED;
266};
267
268// Wrap SkPicture to allow installation of an SkTimedPicturePlayback object
269class SkTimedPicture : public SkPicture {
270public:
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000271 static SkTimedPicture* CreateTimedPicture(SkStream* stream,
272 SkPicture::InstallPixelRefProc proc,
273 const SkTDArray<bool>& deletedCommands) {
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000274 SkPictInfo info;
commit-bot@chromium.org6f4fb0f2014-03-03 19:18:39 +0000275 if (!InternalOnly_StreamIsSKP(stream, &info)) {
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000276 return NULL;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000277 }
278
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000279 SkTimedPicturePlayback* playback;
280 // Check to see if there is a playback to recreate.
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000281 if (stream->readBool()) {
scroggo@google.com12705322013-10-01 15:30:46 +0000282 playback = SkTimedPicturePlayback::CreateFromStream(stream, info, proc,
283 deletedCommands);
284 if (NULL == playback) {
285 return NULL;
286 }
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000287 } else {
288 playback = NULL;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000289 }
290
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000291 return SkNEW_ARGS(SkTimedPicture, (playback, info.fWidth, info.fHeight));
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000292 }
293
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000294 void resetTimes() { ((SkTimedPicturePlayback*) fPlayback)->resetTimes(); }
295
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000296 int count() const { return ((SkTimedPicturePlayback*) fPlayback)->count(); }
297
298 // return the fraction of the total time this command consumed
299 double time(int index) const { return ((SkTimedPicturePlayback*) fPlayback)->time(index); }
300
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000301 const SkTDArray<double>* typeTimes() const { return ((SkTimedPicturePlayback*) fPlayback)->typeTimes(); }
302
303 double totTime() const { return ((SkTimedPicturePlayback*) fPlayback)->totTime(); }
304
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000305private:
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000306 // disallow default ctor b.c. we don't have a good way to setup the fPlayback ptr
307 SkTimedPicture();
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000308 // Private ctor only used by CreateTimedPicture, which has created the playback.
309 SkTimedPicture(SkTimedPicturePlayback* playback, int width, int height)
310 : INHERITED(playback, width, height) {}
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000311 // disallow the copy ctor - enabling would require copying code from SkPicture
312 SkTimedPicture(const SkTimedPicture& src);
313
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000314 typedef SkPicture INHERITED;
315};
316
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000317// This is a simplification of PictureBenchmark's run with the addition of
318// clearing of the times after the first pass (in resetTimes)
skia.committer@gmail.com34587162012-11-20 02:01:23 +0000319void SkDebuggerGUI::run(SkTimedPicture* pict,
320 sk_tools::PictureRenderer* renderer,
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000321 int repeats) {
322 SkASSERT(pict);
323 if (NULL == pict) {
324 return;
325 }
326
327 SkASSERT(renderer != NULL);
328 if (NULL == renderer) {
329 return;
330 }
331
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000332 renderer->init(pict, NULL, NULL, false);
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000333
334 renderer->setup();
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000335 renderer->render();
commit-bot@chromium.org51c040e2014-03-11 22:58:00 +0000336 renderer->resetState(true); // flush, swapBuffers and Finish
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000337
338 // We throw this away the first batch of times to remove first time effects (such as paging in this program)
339 pict->resetTimes();
340
341 for (int i = 0; i < repeats; ++i) {
342 renderer->setup();
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000343 renderer->render();
commit-bot@chromium.org51c040e2014-03-11 22:58:00 +0000344 renderer->resetState(false); // flush & swapBuffers, but don't Finish
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000345 }
commit-bot@chromium.org51c040e2014-03-11 22:58:00 +0000346 renderer->resetState(true); // flush, swapBuffers and Finish
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000347
348 renderer->end();
349}
350
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000351void SkDebuggerGUI::actionProfile() {
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000352 // In order to profile we pass the command offsets (that were read-in
353 // in loadPicture by the SkOffsetPicture) to an SkTimedPlaybackPicture.
skia.committer@gmail.com884e60b2012-11-16 02:01:17 +0000354 // The SkTimedPlaybackPicture in turn passes the offsets to an
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000355 // SkTimedPicturePlayback object which uses them to track the performance
356 // of individual commands.
357 if (fFileName.isEmpty()) {
358 return;
359 }
360
361 SkFILEStream inputStream;
362
363 inputStream.setPath(fFileName.c_str());
364 if (!inputStream.isValid()) {
365 return;
366 }
367
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000368 SkAutoTUnref<SkTimedPicture> picture(SkTimedPicture::CreateTimedPicture(&inputStream,
369 &SkImageDecoder::DecodeMemory, fSkipCommands));
370 if (NULL == picture.get()) {
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000371 return;
372 }
373
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000374 // For now this #if allows switching between tiled and simple rendering
375 // modes. Eventually this will be accomplished via the GUI
robertphillips@google.come174a8b2012-11-27 16:04:42 +0000376#if 0
377 // With the current batch of SysTimers, profiling in tiled mode
378 // gets swamped by the timing overhead:
379 //
380 // tile mode simple mode
381 // debugger 64.2ms 12.8ms
382 // bench_pictures 16.9ms 12.4ms
383 //
384 // This is b.c. in tiled mode each command is called many more times
385 // but typically does less work on each invocation (due to clipping)
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000386 sk_tools::TiledPictureRenderer* renderer = NULL;
387
388 renderer = SkNEW(sk_tools::TiledPictureRenderer);
389 renderer->setTileWidth(256);
390 renderer->setTileHeight(256);
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000391#else
392 sk_tools::SimplePictureRenderer* renderer = NULL;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000393
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000394 renderer = SkNEW(sk_tools::SimplePictureRenderer);
robertphillips@google.com1447aa32013-01-30 21:09:09 +0000395
396#if SK_SUPPORT_GPU
commit-bot@chromium.orgfde1e7c2013-08-02 13:59:50 +0000397 if (fSettingsWidget.isGLActive()) {
robertphillips@google.com1447aa32013-01-30 21:09:09 +0000398 renderer->setDeviceType(sk_tools::PictureRenderer::kGPU_DeviceType);
commit-bot@chromium.orgfde1e7c2013-08-02 13:59:50 +0000399 renderer->setSampleCount(fSettingsWidget.getGLSampleCount());
robertphillips@google.com1447aa32013-01-30 21:09:09 +0000400 }
401#endif
402
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000403#endif
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000404
robertphillips@google.come174a8b2012-11-27 16:04:42 +0000405 static const int kNumRepeats = 10;
406
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000407 run(picture.get(), renderer, kNumRepeats);
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000408
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000409 SkASSERT(picture->count() == fListWidget.count());
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000410
411 // extract the individual command times from the SkTimedPlaybackPicture
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000412 for (int i = 0; i < picture->count(); ++i) {
413 double temp = picture->time(i);
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000414
415 QListWidgetItem* item = fListWidget.item(i);
416
417 item->setData(Qt::UserRole + 4, 100.0*temp);
418 }
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000419
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000420 setupOverviewText(picture->typeTimes(), picture->totTime(), kNumRepeats);
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000421}
422
chudy@google.com902ebe52012-06-29 14:21:22 +0000423void SkDebuggerGUI::actionCancel() {
chudy@google.comc432f002012-07-10 13:19:25 +0000424 for (int row = 0; row < fListWidget.count(); row++) {
425 fListWidget.item(row)->setHidden(false);
chudy@google.com902ebe52012-06-29 14:21:22 +0000426 }
427}
428
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000429void SkDebuggerGUI::actionClearBreakpoints() {
430 for (int row = 0; row < fListWidget.count(); row++) {
431 QListWidgetItem* item = fListWidget.item(row);
432 item->setCheckState(Qt::Unchecked);
433 item->setData(Qt::DecorationRole,
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000434 QPixmap(":/blank.png"));
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000435 }
436}
437
438void SkDebuggerGUI::actionClearDeletes() {
439 for (int row = 0; row < fListWidget.count(); row++) {
440 QListWidgetItem* item = fListWidget.item(row);
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000441 item->setData(Qt::UserRole + 2, QPixmap(":/blank.png"));
chudy@google.com607357f2012-08-07 16:12:23 +0000442 fDebugger.setCommandVisible(row, true);
robertphillips@google.com5f971142012-12-07 20:48:56 +0000443 fSkipCommands[row] = false;
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000444 }
445 if (fPause) {
446 fCanvasWidget.drawTo(fPausedRow);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000447 fImageWidget.draw();
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000448 } else {
449 fCanvasWidget.drawTo(fListWidget.currentRow());
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000450 fImageWidget.draw();
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000451 }
452}
453
chudy@google.com902ebe52012-06-29 14:21:22 +0000454void SkDebuggerGUI::actionCommandFilter() {
commit-bot@chromium.org22d39332013-11-21 15:37:29 +0000455 fDebugger.highlightCurrentCommand(fSettingsWidget.getVisibilityFilter());
chudy@google.comc432f002012-07-10 13:19:25 +0000456 fCanvasWidget.drawTo(fListWidget.currentRow());
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000457 fImageWidget.draw();
chudy@google.com902ebe52012-06-29 14:21:22 +0000458}
459
460void SkDebuggerGUI::actionClose() {
461 this->close();
462}
463
464void SkDebuggerGUI::actionDelete() {
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000465
robertphillips@google.comdd4b7452013-01-22 19:38:46 +0000466 for (int row = 0; row < fListWidget.count(); ++row) {
467 QListWidgetItem* item = fListWidget.item(row);
468
469 if (!item->isSelected()) {
470 continue;
471 }
472
473 if (fDebugger.isCommandVisible(row)) {
474 item->setData(Qt::UserRole + 2, QPixmap(":/delete.png"));
475 fDebugger.setCommandVisible(row, false);
476 fSkipCommands[row] = true;
477 } else {
478 item->setData(Qt::UserRole + 2, QPixmap(":/blank.png"));
479 fDebugger.setCommandVisible(row, true);
480 fSkipCommands[row] = false;
481 }
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000482 }
483
robertphillips@google.comdd4b7452013-01-22 19:38:46 +0000484 int currentRow = fListWidget.currentRow();
485
chudy@google.come504de02012-07-16 18:35:23 +0000486 if (fPause) {
487 fCanvasWidget.drawTo(fPausedRow);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000488 fImageWidget.draw();
chudy@google.come504de02012-07-16 18:35:23 +0000489 } else {
490 fCanvasWidget.drawTo(currentRow);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000491 fImageWidget.draw();
chudy@google.come504de02012-07-16 18:35:23 +0000492 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000493}
494
robertphillips@google.come8fe4bc2013-02-13 13:26:13 +0000495#if SK_SUPPORT_GPU
commit-bot@chromium.orgfde1e7c2013-08-02 13:59:50 +0000496void SkDebuggerGUI::actionGLWidget() {
497 bool isToggled = fSettingsWidget.isGLActive();
498 if (isToggled) {
499 fCanvasWidget.setGLSampleCount(fSettingsWidget.getGLSampleCount());
500 }
chudy@google.comea5488b2012-07-26 19:38:22 +0000501 fCanvasWidget.setWidgetVisibility(SkCanvasWidget::kGPU_WidgetType, !isToggled);
502}
robertphillips@google.come8fe4bc2013-02-13 13:26:13 +0000503#endif
chudy@google.comea5488b2012-07-26 19:38:22 +0000504
chudy@google.com902ebe52012-06-29 14:21:22 +0000505void SkDebuggerGUI::actionInspector() {
chudy@google.comc432f002012-07-10 13:19:25 +0000506 if (fInspectorWidget.isHidden()) {
507 fInspectorWidget.setHidden(false);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000508 fImageWidget.setHidden(false);
chudy@google.com902ebe52012-06-29 14:21:22 +0000509 } else {
chudy@google.comc432f002012-07-10 13:19:25 +0000510 fInspectorWidget.setHidden(true);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000511 fImageWidget.setHidden(true);
chudy@google.com902ebe52012-06-29 14:21:22 +0000512 }
513}
514
515void SkDebuggerGUI::actionPlay() {
chudy@google.comc432f002012-07-10 13:19:25 +0000516 for (int row = fListWidget.currentRow() + 1; row < fListWidget.count();
chudy@google.com7dcae672012-07-09 20:26:53 +0000517 row++) {
chudy@google.comc432f002012-07-10 13:19:25 +0000518 QListWidgetItem *item = fListWidget.item(row);
chudy@google.com902ebe52012-06-29 14:21:22 +0000519 if (item->checkState() == Qt::Checked) {
chudy@google.comc432f002012-07-10 13:19:25 +0000520 fListWidget.setCurrentItem(item);
chudy@google.com902ebe52012-06-29 14:21:22 +0000521 return;
522 }
523 }
chudy@google.comc432f002012-07-10 13:19:25 +0000524 fListWidget.setCurrentRow(fListWidget.count() - 1);
chudy@google.com902ebe52012-06-29 14:21:22 +0000525}
526
chudy@google.comea5488b2012-07-26 19:38:22 +0000527void SkDebuggerGUI::actionRasterWidget(bool isToggled) {
528 fCanvasWidget.setWidgetVisibility(SkCanvasWidget::kRaster_8888_WidgetType, !isToggled);
529}
530
robertphillips@google.comf4741c12013-02-06 20:13:54 +0000531void SkDebuggerGUI::actionOverdrawVizWidget(bool isToggled) {
532 fDebugger.setOverdrawViz(isToggled);
533 fCanvasWidget.update();
534}
535
commit-bot@chromium.org768ac852014-03-03 16:32:17 +0000536void SkDebuggerGUI::actionMegaVizWidget(bool isToggled) {
537 fDebugger.setMegaViz(isToggled);
538 fCanvasWidget.update();
539}
540
robertphillips@google.com32bbcf82013-10-17 17:56:10 +0000541void SkDebuggerGUI::actionTextureFilter() {
542 SkPaint::FilterLevel level;
543 bool enabled = fSettingsWidget.getFilterOverride(&level);
544 fDebugger.setTexFilterOverride(enabled, level);
545 fCanvasWidget.update();
546}
547
chudy@google.com902ebe52012-06-29 14:21:22 +0000548void SkDebuggerGUI::actionRewind() {
chudy@google.come504de02012-07-16 18:35:23 +0000549 fListWidget.setCurrentRow(0);
chudy@google.com902ebe52012-06-29 14:21:22 +0000550}
551
chudy@google.com0ab03392012-07-28 20:16:11 +0000552void SkDebuggerGUI::actionSave() {
robertphillips@google.come219baf2013-01-28 19:25:43 +0000553 fFileName = fPath.toAscii().data();
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000554 fFileName.append("/");
robertphillips@google.come219baf2013-01-28 19:25:43 +0000555 fFileName.append(fDirectoryWidget.currentItem()->text().toAscii().data());
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000556 saveToFile(fFileName);
chudy@google.com0ab03392012-07-28 20:16:11 +0000557}
558
559void SkDebuggerGUI::actionSaveAs() {
560 QString filename = QFileDialog::getSaveFileName(this, "Save File", "",
561 "Skia Picture (*skp)");
chudy@google.com38b08ce2012-07-28 23:26:10 +0000562 if (!filename.endsWith(".skp", Qt::CaseInsensitive)) {
chudy@google.com0ab03392012-07-28 20:16:11 +0000563 filename.append(".skp");
564 }
djsollen@google.comc3c82162012-11-13 18:35:10 +0000565 saveToFile(SkString(filename.toAscii().data()));
chudy@google.com0ab03392012-07-28 20:16:11 +0000566}
567
chudy@google.com7dcae672012-07-09 20:26:53 +0000568void SkDebuggerGUI::actionScale(float scaleFactor) {
chudy@google.comc432f002012-07-10 13:19:25 +0000569 fSettingsWidget.setZoomText(scaleFactor);
chudy@google.com7dcae672012-07-09 20:26:53 +0000570}
571
chudy@google.com902ebe52012-06-29 14:21:22 +0000572void SkDebuggerGUI::actionSettings() {
chudy@google.comc432f002012-07-10 13:19:25 +0000573 if (fSettingsWidget.isHidden()) {
574 fSettingsWidget.setHidden(false);
chudy@google.com902ebe52012-06-29 14:21:22 +0000575 } else {
chudy@google.comc432f002012-07-10 13:19:25 +0000576 fSettingsWidget.setHidden(true);
chudy@google.com902ebe52012-06-29 14:21:22 +0000577 }
578}
579
580void SkDebuggerGUI::actionStepBack() {
chudy@google.comc432f002012-07-10 13:19:25 +0000581 int currentRow = fListWidget.currentRow();
chudy@google.com902ebe52012-06-29 14:21:22 +0000582 if (currentRow != 0) {
chudy@google.comc432f002012-07-10 13:19:25 +0000583 fListWidget.setCurrentRow(currentRow - 1);
chudy@google.com902ebe52012-06-29 14:21:22 +0000584 }
585}
586
587void SkDebuggerGUI::actionStepForward() {
chudy@google.comc432f002012-07-10 13:19:25 +0000588 int currentRow = fListWidget.currentRow();
chudy@google.com902ebe52012-06-29 14:21:22 +0000589 QString curRow = QString::number(currentRow);
chudy@google.comc432f002012-07-10 13:19:25 +0000590 QString curCount = QString::number(fListWidget.count());
591 if (currentRow < fListWidget.count() - 1) {
592 fListWidget.setCurrentRow(currentRow + 1);
chudy@google.com902ebe52012-06-29 14:21:22 +0000593 }
594}
595
chudy@google.coma9e937c2012-08-03 17:32:05 +0000596void SkDebuggerGUI::drawComplete() {
chudy@google.com607357f2012-08-07 16:12:23 +0000597 fInspectorWidget.setMatrix(fDebugger.getCurrentMatrix());
598 fInspectorWidget.setClip(fDebugger.getCurrentClip());
chudy@google.coma9e937c2012-08-03 17:32:05 +0000599}
600
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000601void SkDebuggerGUI::saveToFile(const SkString& filename) {
602 SkFILEWStream file(filename.c_str());
robertphillips@google.com25bc2f82013-01-22 18:03:56 +0000603 SkAutoTUnref<SkPicture> copy(fDebugger.copyPicture());
604
605 copy->serialize(&file);
chudy@google.com0ab03392012-07-28 20:16:11 +0000606}
607
chudy@google.com902ebe52012-06-29 14:21:22 +0000608void SkDebuggerGUI::loadFile(QListWidgetItem *item) {
609 if (fDirectoryWidgetActive) {
robertphillips@google.come219baf2013-01-28 19:25:43 +0000610 fFileName = fPath.toAscii().data();
jvanverth@google.com0ac6f162013-02-05 19:44:07 +0000611 // don't add a '/' to files in the local directory
612 if (fFileName.size() > 0) {
613 fFileName.append("/");
614 }
robertphillips@google.come219baf2013-01-28 19:25:43 +0000615 fFileName.append(item->text().toAscii().data());
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000616 loadPicture(fFileName);
chudy@google.com902ebe52012-06-29 14:21:22 +0000617 }
618}
619
620void SkDebuggerGUI::openFile() {
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000621 QString temp = QFileDialog::getOpenFileName(this, tr("Open File"), "",
chudy@google.com7dcae672012-07-09 20:26:53 +0000622 tr("Files (*.*)"));
robertphillips@google.comff6e6ba2013-01-28 17:43:26 +0000623 openFile(temp);
624}
625
626void SkDebuggerGUI::openFile(const QString &filename) {
chudy@google.com902ebe52012-06-29 14:21:22 +0000627 fDirectoryWidgetActive = false;
robertphillips@google.comff6e6ba2013-01-28 17:43:26 +0000628 if (!filename.isEmpty()) {
629 QFileInfo pathInfo(filename);
630 loadPicture(SkString(filename.toAscii().data()));
631 setupDirectoryWidget(pathInfo.path());
chudy@google.com902ebe52012-06-29 14:21:22 +0000632 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000633 fDirectoryWidgetActive = true;
634}
635
chudy@google.comc432f002012-07-10 13:19:25 +0000636void SkDebuggerGUI::pauseDrawing(bool isPaused) {
chudy@google.com607357f2012-08-07 16:12:23 +0000637 fPause = isPaused;
638 fPausedRow = fListWidget.currentRow();
639 fCanvasWidget.drawTo(fPausedRow);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000640 fImageWidget.draw();
chudy@google.com7dcae672012-07-09 20:26:53 +0000641}
642
chudy@google.com902ebe52012-06-29 14:21:22 +0000643void SkDebuggerGUI::registerListClick(QListWidgetItem *item) {
chudy@google.comd3058f52012-07-19 13:41:27 +0000644 if(!fLoading) {
645 int currentRow = fListWidget.currentRow();
chudy@google.comd3058f52012-07-19 13:41:27 +0000646
chudy@google.comea5488b2012-07-26 19:38:22 +0000647 if (currentRow != -1) {
648 if (!fPause) {
649 fCanvasWidget.drawTo(currentRow);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000650 fImageWidget.draw();
chudy@google.comd3058f52012-07-19 13:41:27 +0000651 }
chudy@google.com97cee972012-08-07 20:41:37 +0000652 SkTDArray<SkString*> *currInfo = fDebugger.getCommandInfo(
chudy@google.comea5488b2012-07-26 19:38:22 +0000653 currentRow);
654
655 /* TODO(chudy): Add command type before parameters. Rename v
656 * to something more informative. */
chudy@google.com97cee972012-08-07 20:41:37 +0000657 if (currInfo) {
chudy@google.comea5488b2012-07-26 19:38:22 +0000658 QString info;
659 info.append("<b>Parameters: </b><br/>");
chudy@google.com97cee972012-08-07 20:41:37 +0000660 for (int i = 0; i < currInfo->count(); i++) {
661
662 info.append(QString((*currInfo)[i]->c_str()));
chudy@google.comea5488b2012-07-26 19:38:22 +0000663 info.append("<br/>");
664 }
chudy@google.com6bd109a2012-08-14 19:34:13 +0000665 fInspectorWidget.setText(info, SkInspectorWidget::kDetail_TabType);
chudy@google.comea5488b2012-07-26 19:38:22 +0000666 fInspectorWidget.setDisabled(false);
chudy@google.comea5488b2012-07-26 19:38:22 +0000667 }
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
1049void SkDebuggerGUI::setupComboBox(SkTArray<SkString>* command) {
1050 fFilter.clear();
1051 fFilter.addItem("--Filter By Available Commands--");
1052
1053 std::map<std::string, int> map;
1054 for (int i = 0; i < command->count(); i++) {
1055 map[(*command)[i].c_str()]++;
1056 }
1057
skia.committer@gmail.com34587162012-11-20 02:01:23 +00001058 for (std::map<std::string, int>::iterator it = map.begin(); it != map.end();
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +00001059 ++it) {
1060 fFilter.addItem((it->first).c_str());
1061 }
chudy@google.com902ebe52012-06-29 14:21:22 +00001062
1063 // NOTE(chudy): Makes first item unselectable.
chudy@google.com7dcae672012-07-09 20:26:53 +00001064 QStandardItemModel* model = qobject_cast<QStandardItemModel*>(
chudy@google.comc432f002012-07-10 13:19:25 +00001065 fFilter.model());
1066 QModelIndex firstIndex = model->index(0, fFilter.modelColumn(),
1067 fFilter.rootModelIndex());
chudy@google.com902ebe52012-06-29 14:21:22 +00001068 QStandardItem* firstItem = model->itemFromIndex(firstIndex);
1069 firstItem->setSelectable(false);
1070}