blob: 0f816eec7cebd55d8b726e903f180158b9642437 [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)));
commit-bot@chromium.org2a67e122014-05-19 13:53:10 +0000104 connect(fSettingsWidget.getPathOpsCheckBox(), SIGNAL(toggled(bool)), this, SLOT(actionPathOpsWidget(bool)));
chudy@google.comea5488b2012-07-26 19:38:22 +0000105 connect(&fActionPause, SIGNAL(toggled(bool)), this, SLOT(pauseDrawing(bool)));
chudy@google.come504de02012-07-16 18:35:23 +0000106 connect(&fActionCreateBreakpoint, SIGNAL(activated()), this, SLOT(toggleBreakpoint()));
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000107 connect(&fActionShowDeletes, SIGNAL(triggered()), this, SLOT(showDeletes()));
chudy@google.comea5488b2012-07-26 19:38:22 +0000108 connect(&fCanvasWidget, SIGNAL(hitChanged(int)), this, SLOT(selectCommand(int)));
109 connect(&fCanvasWidget, SIGNAL(hitChanged(int)), &fSettingsWidget, SLOT(updateHit(int)));
110 connect(&fCanvasWidget, SIGNAL(scaleFactorChanged(float)), this, SLOT(actionScale(float)));
111 connect(&fCanvasWidget, SIGNAL(commandChanged(int)), &fSettingsWidget, SLOT(updateCommand(int)));
chudy@google.com0ab03392012-07-28 20:16:11 +0000112 connect(&fActionSaveAs, SIGNAL(triggered()), this, SLOT(actionSaveAs()));
113 connect(&fActionSave, SIGNAL(triggered()), this, SLOT(actionSave()));
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000114
bungeman@google.come8cc6e82013-01-17 16:30:56 +0000115 fMapper.setMapping(&fActionZoomIn, SkCanvasWidget::kIn_ZoomCommand);
116 fMapper.setMapping(&fActionZoomOut, SkCanvasWidget::kOut_ZoomCommand);
chudy@google.coma1226312012-07-26 20:26:44 +0000117
118 connect(&fActionZoomIn, SIGNAL(triggered()), &fMapper, SLOT(map()));
119 connect(&fActionZoomOut, SIGNAL(triggered()), &fMapper, SLOT(map()));
bungeman@google.come8cc6e82013-01-17 16:30:56 +0000120 connect(&fMapper, SIGNAL(mapped(int)), &fCanvasWidget, SLOT(zoom(int)));
chudy@google.coma1226312012-07-26 20:26:44 +0000121
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000122 fInspectorWidget.setDisabled(true);
chudy@google.comd3058f52012-07-19 13:41:27 +0000123 fMenuEdit.setDisabled(true);
124 fMenuNavigate.setDisabled(true);
125 fMenuView.setDisabled(true);
chudy@google.combbad34d2012-08-13 14:26:36 +0000126
127 SkGraphics::Init();
chudy@google.com902ebe52012-06-29 14:21:22 +0000128}
129
chudy@google.combbad34d2012-08-13 14:26:36 +0000130SkDebuggerGUI::~SkDebuggerGUI() {
131 SkGraphics::Term();
132}
chudy@google.com902ebe52012-06-29 14:21:22 +0000133
134void SkDebuggerGUI::actionBreakpoints() {
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000135 fBreakpointsActivated = !fBreakpointsActivated;
chudy@google.comc432f002012-07-10 13:19:25 +0000136 for (int row = 0; row < fListWidget.count(); row++) {
137 QListWidgetItem *item = fListWidget.item(row);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000138 item->setHidden(item->checkState() == Qt::Unchecked && fBreakpointsActivated);
139 }
140}
chudy@google.com902ebe52012-06-29 14:21:22 +0000141
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000142void SkDebuggerGUI::actionToggleIndexStyle() {
143 fIndexStyleToggle = !fIndexStyleToggle;
144 SkListWidget* list = (SkListWidget*) fListWidget.itemDelegate();
skia.committer@gmail.comdb35dab2014-03-27 03:02:48 +0000145 list->setIndexStyle(fIndexStyleToggle ? SkListWidget::kIndex_IndexStyle :
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000146 SkListWidget::kOffset_IndexStyle);
147 fListWidget.update();
148}
149
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000150void SkDebuggerGUI::showDeletes() {
151 fDeletesActivated = !fDeletesActivated;
152 for (int row = 0; row < fListWidget.count(); row++) {
153 QListWidgetItem *item = fListWidget.item(row);
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000154 item->setHidden(fDebugger.isCommandVisible(row) && fDeletesActivated);
chudy@google.com902ebe52012-06-29 14:21:22 +0000155 }
156}
157
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000158// The timed picture playback uses the SkPicturePlayback's profiling stubs
159// to time individual commands. The offsets are needed to map SkPicture
160// offsets to individual commands.
161class SkTimedPicturePlayback : public SkPicturePlayback {
162public:
commit-bot@chromium.org8f831f22014-04-23 22:35:42 +0000163 static SkTimedPicturePlayback* CreateFromStream(SkPicture* picture,
164 SkStream* stream, const SkPictInfo& info,
scroggo@google.com12705322013-10-01 15:30:46 +0000165 SkPicture::InstallPixelRefProc proc,
166 const SkTDArray<bool>& deletedCommands) {
167 // Mimics SkPicturePlayback::CreateFromStream
168 SkAutoTDelete<SkTimedPicturePlayback> playback(SkNEW_ARGS(SkTimedPicturePlayback,
commit-bot@chromium.org8f831f22014-04-23 22:35:42 +0000169 (picture, deletedCommands, info)));
170 if (!playback->parseStream(picture, stream, proc)) {
scroggo@google.com12705322013-10-01 15:30:46 +0000171 return NULL; // we're invalid
172 }
173 return playback.detach();
174 }
175
commit-bot@chromium.org8f831f22014-04-23 22:35:42 +0000176 SkTimedPicturePlayback(SkPicture* picture,
skia.committer@gmail.comb0430d02014-04-24 03:05:07 +0000177 const SkTDArray<bool>& deletedCommands,
commit-bot@chromium.org8f831f22014-04-23 22:35:42 +0000178 const SkPictInfo& info)
179 : INHERITED(picture, info)
bungeman@google.come8cc6e82013-01-17 16:30:56 +0000180 , fSkipCommands(deletedCommands)
181 , fTot(0.0)
182 , fCurCommand(0) {
robertphillips@google.com6d9c92b2013-05-23 13:21:18 +0000183 fTimes.setCount(deletedCommands.count());
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000184 fTypeTimes.setCount(LAST_DRAWTYPE_ENUM+1);
185 this->resetTimes();
186 }
187
188 void resetTimes() {
robertphillips@google.com6d9c92b2013-05-23 13:21:18 +0000189 for (int i = 0; i < fTimes.count(); ++i) {
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000190 fTimes[i] = 0.0;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000191 }
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000192 for (int i = 0; i < fTypeTimes.count(); ++i) {
193 fTypeTimes[i] = 0.0f;
194 }
195 fTot = 0.0;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000196 }
197
198 int count() const { return fTimes.count(); }
199
200 double time(int index) const { return fTimes[index] / fTot; }
201
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000202 const SkTDArray<double>* typeTimes() const { return &fTypeTimes; }
203
204 double totTime() const { return fTot; }
205
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000206protected:
robertphillips@google.come174a8b2012-11-27 16:04:42 +0000207 BenchSysTimer fTimer;
robertphillips@google.com5f971142012-12-07 20:48:56 +0000208 SkTDArray<bool> fSkipCommands; // has the command been deleted in the GUI?
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000209 SkTDArray<double> fTimes; // sum of time consumed for each command
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000210 SkTDArray<double> fTypeTimes; // sum of time consumed for each type of command (e.g., drawPath)
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000211 double fTot; // total of all times in 'fTimes'
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000212 int fCurType;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000213 int fCurCommand; // the current command being executed/timed
214
robertphillips@google.com6d9c92b2013-05-23 13:21:18 +0000215#ifdef SK_DEVELOPER
216 virtual bool preDraw(int opIndex, int type) SK_OVERRIDE {
217 fCurCommand = opIndex;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000218
robertphillips@google.com5f971142012-12-07 20:48:56 +0000219 if (fSkipCommands[fCurCommand]) {
robertphillips@google.com6d9c92b2013-05-23 13:21:18 +0000220 return true;
robertphillips@google.com5f971142012-12-07 20:48:56 +0000221 }
222
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000223 fCurType = type;
224 // The SkDebugCanvas doesn't recognize these types. This class needs to
225 // convert or else we'll wind up with a mismatch between the type counts
226 // the debugger displays and the profile times.
227 if (DRAW_POS_TEXT_TOP_BOTTOM == type) {
228 fCurType = DRAW_POS_TEXT;
229 } else if (DRAW_POS_TEXT_H_TOP_BOTTOM == type) {
230 fCurType = DRAW_POS_TEXT_H;
231 }
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000232
robertphillips@google.come174a8b2012-11-27 16:04:42 +0000233#if defined(SK_BUILD_FOR_WIN32)
234 // CPU timer doesn't work well on Windows
235 fTimer.startWall();
236#else
237 fTimer.startCpu();
238#endif
robertphillips@google.com5f971142012-12-07 20:48:56 +0000239
robertphillips@google.com6d9c92b2013-05-23 13:21:18 +0000240 return false;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000241 }
242
robertphillips@google.com6d9c92b2013-05-23 13:21:18 +0000243 virtual void postDraw(int opIndex) SK_OVERRIDE {
robertphillips@google.come174a8b2012-11-27 16:04:42 +0000244#if defined(SK_BUILD_FOR_WIN32)
245 // CPU timer doesn't work well on Windows
246 double time = fTimer.endWall();
247#else
248 double time = fTimer.endCpu();
249#endif
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000250
robertphillips@google.com6d9c92b2013-05-23 13:21:18 +0000251 SkASSERT(opIndex == fCurCommand);
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000252 SkASSERT(fCurType <= LAST_DRAWTYPE_ENUM);
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000253
robertphillips@google.come174a8b2012-11-27 16:04:42 +0000254 fTimes[fCurCommand] += time;
255 fTypeTimes[fCurType] += time;
256 fTot += time;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000257 }
robertphillips@google.com6d9c92b2013-05-23 13:21:18 +0000258#endif
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000259
260private:
261 typedef SkPicturePlayback INHERITED;
262};
263
264// Wrap SkPicture to allow installation of an SkTimedPicturePlayback object
265class SkTimedPicture : public SkPicture {
266public:
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000267 static SkTimedPicture* CreateTimedPicture(SkStream* stream,
268 SkPicture::InstallPixelRefProc proc,
269 const SkTDArray<bool>& deletedCommands) {
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000270 SkPictInfo info;
commit-bot@chromium.org6f4fb0f2014-03-03 19:18:39 +0000271 if (!InternalOnly_StreamIsSKP(stream, &info)) {
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000272 return NULL;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000273 }
274
commit-bot@chromium.org8f831f22014-04-23 22:35:42 +0000275 SkTimedPicture* newPict = SkNEW_ARGS(SkTimedPicture, (NULL, info.fWidth, info.fHeight));
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000276 // Check to see if there is a playback to recreate.
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000277 if (stream->readBool()) {
commit-bot@chromium.org8f831f22014-04-23 22:35:42 +0000278 SkTimedPicturePlayback* playback = SkTimedPicturePlayback::CreateFromStream(
279 newPict, stream,
280 info, proc,
scroggo@google.com12705322013-10-01 15:30:46 +0000281 deletedCommands);
282 if (NULL == playback) {
commit-bot@chromium.org8f831f22014-04-23 22:35:42 +0000283 SkDELETE(newPict);
scroggo@google.com12705322013-10-01 15:30:46 +0000284 return NULL;
285 }
commit-bot@chromium.org8f831f22014-04-23 22:35:42 +0000286 newPict->fPlayback = playback;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000287 }
288
commit-bot@chromium.org8f831f22014-04-23 22:35:42 +0000289 return newPict;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000290 }
291
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000292 void resetTimes() { ((SkTimedPicturePlayback*) fPlayback)->resetTimes(); }
293
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000294 int count() const { return ((SkTimedPicturePlayback*) fPlayback)->count(); }
295
296 // return the fraction of the total time this command consumed
297 double time(int index) const { return ((SkTimedPicturePlayback*) fPlayback)->time(index); }
298
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000299 const SkTDArray<double>* typeTimes() const { return ((SkTimedPicturePlayback*) fPlayback)->typeTimes(); }
300
301 double totTime() const { return ((SkTimedPicturePlayback*) fPlayback)->totTime(); }
302
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000303private:
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000304 // disallow default ctor b.c. we don't have a good way to setup the fPlayback ptr
305 SkTimedPicture();
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000306 // Private ctor only used by CreateTimedPicture, which has created the playback.
307 SkTimedPicture(SkTimedPicturePlayback* playback, int width, int height)
308 : INHERITED(playback, width, height) {}
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000309 // disallow the copy ctor - enabling would require copying code from SkPicture
310 SkTimedPicture(const SkTimedPicture& src);
311
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000312 typedef SkPicture INHERITED;
313};
314
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000315// This is a simplification of PictureBenchmark's run with the addition of
316// clearing of the times after the first pass (in resetTimes)
skia.committer@gmail.com34587162012-11-20 02:01:23 +0000317void SkDebuggerGUI::run(SkTimedPicture* pict,
318 sk_tools::PictureRenderer* renderer,
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000319 int repeats) {
320 SkASSERT(pict);
321 if (NULL == pict) {
322 return;
323 }
324
325 SkASSERT(renderer != NULL);
326 if (NULL == renderer) {
327 return;
328 }
329
commit-bot@chromium.org3f045172014-05-15 15:10:48 +0000330 renderer->init(pict, NULL, NULL, NULL, false);
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000331
332 renderer->setup();
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000333 renderer->render();
commit-bot@chromium.org51c040e2014-03-11 22:58:00 +0000334 renderer->resetState(true); // flush, swapBuffers and Finish
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000335
336 // We throw this away the first batch of times to remove first time effects (such as paging in this program)
337 pict->resetTimes();
338
339 for (int i = 0; i < repeats; ++i) {
340 renderer->setup();
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000341 renderer->render();
commit-bot@chromium.org51c040e2014-03-11 22:58:00 +0000342 renderer->resetState(false); // flush & swapBuffers, but don't Finish
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000343 }
commit-bot@chromium.org51c040e2014-03-11 22:58:00 +0000344 renderer->resetState(true); // flush, swapBuffers and Finish
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000345
346 renderer->end();
347}
348
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000349void SkDebuggerGUI::actionProfile() {
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000350 // In order to profile we pass the command offsets (that were read-in
351 // in loadPicture by the SkOffsetPicture) to an SkTimedPlaybackPicture.
skia.committer@gmail.com884e60b2012-11-16 02:01:17 +0000352 // The SkTimedPlaybackPicture in turn passes the offsets to an
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000353 // SkTimedPicturePlayback object which uses them to track the performance
354 // of individual commands.
355 if (fFileName.isEmpty()) {
356 return;
357 }
358
359 SkFILEStream inputStream;
360
361 inputStream.setPath(fFileName.c_str());
362 if (!inputStream.isValid()) {
363 return;
364 }
365
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000366 SkAutoTUnref<SkTimedPicture> picture(SkTimedPicture::CreateTimedPicture(&inputStream,
367 &SkImageDecoder::DecodeMemory, fSkipCommands));
368 if (NULL == picture.get()) {
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000369 return;
370 }
371
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000372 // For now this #if allows switching between tiled and simple rendering
373 // modes. Eventually this will be accomplished via the GUI
robertphillips@google.come174a8b2012-11-27 16:04:42 +0000374#if 0
375 // With the current batch of SysTimers, profiling in tiled mode
376 // gets swamped by the timing overhead:
377 //
378 // tile mode simple mode
379 // debugger 64.2ms 12.8ms
380 // bench_pictures 16.9ms 12.4ms
381 //
382 // This is b.c. in tiled mode each command is called many more times
383 // but typically does less work on each invocation (due to clipping)
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000384 sk_tools::TiledPictureRenderer* renderer = NULL;
385
386 renderer = SkNEW(sk_tools::TiledPictureRenderer);
387 renderer->setTileWidth(256);
388 renderer->setTileHeight(256);
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000389#else
390 sk_tools::SimplePictureRenderer* renderer = NULL;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000391
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000392 renderer = SkNEW(sk_tools::SimplePictureRenderer);
robertphillips@google.com1447aa32013-01-30 21:09:09 +0000393
394#if SK_SUPPORT_GPU
commit-bot@chromium.orgfde1e7c2013-08-02 13:59:50 +0000395 if (fSettingsWidget.isGLActive()) {
robertphillips@google.com1447aa32013-01-30 21:09:09 +0000396 renderer->setDeviceType(sk_tools::PictureRenderer::kGPU_DeviceType);
commit-bot@chromium.orgfde1e7c2013-08-02 13:59:50 +0000397 renderer->setSampleCount(fSettingsWidget.getGLSampleCount());
robertphillips@google.com1447aa32013-01-30 21:09:09 +0000398 }
399#endif
400
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000401#endif
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000402
robertphillips@google.come174a8b2012-11-27 16:04:42 +0000403 static const int kNumRepeats = 10;
404
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000405 run(picture.get(), renderer, kNumRepeats);
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000406
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000407 SkASSERT(picture->count() == fListWidget.count());
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000408
409 // extract the individual command times from the SkTimedPlaybackPicture
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000410 for (int i = 0; i < picture->count(); ++i) {
411 double temp = picture->time(i);
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000412
413 QListWidgetItem* item = fListWidget.item(i);
414
415 item->setData(Qt::UserRole + 4, 100.0*temp);
416 }
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000417
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000418 setupOverviewText(picture->typeTimes(), picture->totTime(), kNumRepeats);
commit-bot@chromium.org2a67e122014-05-19 13:53:10 +0000419 setupClipStackText();
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000420}
421
chudy@google.com902ebe52012-06-29 14:21:22 +0000422void SkDebuggerGUI::actionCancel() {
chudy@google.comc432f002012-07-10 13:19:25 +0000423 for (int row = 0; row < fListWidget.count(); row++) {
424 fListWidget.item(row)->setHidden(false);
chudy@google.com902ebe52012-06-29 14:21:22 +0000425 }
426}
427
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000428void SkDebuggerGUI::actionClearBreakpoints() {
429 for (int row = 0; row < fListWidget.count(); row++) {
430 QListWidgetItem* item = fListWidget.item(row);
431 item->setCheckState(Qt::Unchecked);
432 item->setData(Qt::DecorationRole,
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000433 QPixmap(":/blank.png"));
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000434 }
435}
436
437void SkDebuggerGUI::actionClearDeletes() {
438 for (int row = 0; row < fListWidget.count(); row++) {
439 QListWidgetItem* item = fListWidget.item(row);
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000440 item->setData(Qt::UserRole + 2, QPixmap(":/blank.png"));
chudy@google.com607357f2012-08-07 16:12:23 +0000441 fDebugger.setCommandVisible(row, true);
robertphillips@google.com5f971142012-12-07 20:48:56 +0000442 fSkipCommands[row] = false;
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000443 }
444 if (fPause) {
445 fCanvasWidget.drawTo(fPausedRow);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000446 fImageWidget.draw();
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000447 } else {
448 fCanvasWidget.drawTo(fListWidget.currentRow());
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000449 fImageWidget.draw();
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000450 }
451}
452
chudy@google.com902ebe52012-06-29 14:21:22 +0000453void SkDebuggerGUI::actionCommandFilter() {
commit-bot@chromium.org22d39332013-11-21 15:37:29 +0000454 fDebugger.highlightCurrentCommand(fSettingsWidget.getVisibilityFilter());
chudy@google.comc432f002012-07-10 13:19:25 +0000455 fCanvasWidget.drawTo(fListWidget.currentRow());
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000456 fImageWidget.draw();
chudy@google.com902ebe52012-06-29 14:21:22 +0000457}
458
459void SkDebuggerGUI::actionClose() {
460 this->close();
461}
462
463void SkDebuggerGUI::actionDelete() {
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000464
robertphillips@google.comdd4b7452013-01-22 19:38:46 +0000465 for (int row = 0; row < fListWidget.count(); ++row) {
466 QListWidgetItem* item = fListWidget.item(row);
467
468 if (!item->isSelected()) {
469 continue;
470 }
471
472 if (fDebugger.isCommandVisible(row)) {
473 item->setData(Qt::UserRole + 2, QPixmap(":/delete.png"));
474 fDebugger.setCommandVisible(row, false);
475 fSkipCommands[row] = true;
476 } else {
477 item->setData(Qt::UserRole + 2, QPixmap(":/blank.png"));
478 fDebugger.setCommandVisible(row, true);
479 fSkipCommands[row] = false;
480 }
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000481 }
482
robertphillips@google.comdd4b7452013-01-22 19:38:46 +0000483 int currentRow = fListWidget.currentRow();
484
chudy@google.come504de02012-07-16 18:35:23 +0000485 if (fPause) {
486 fCanvasWidget.drawTo(fPausedRow);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000487 fImageWidget.draw();
chudy@google.come504de02012-07-16 18:35:23 +0000488 } else {
489 fCanvasWidget.drawTo(currentRow);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000490 fImageWidget.draw();
chudy@google.come504de02012-07-16 18:35:23 +0000491 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000492}
493
robertphillips@google.come8fe4bc2013-02-13 13:26:13 +0000494#if SK_SUPPORT_GPU
commit-bot@chromium.orgfde1e7c2013-08-02 13:59:50 +0000495void SkDebuggerGUI::actionGLWidget() {
496 bool isToggled = fSettingsWidget.isGLActive();
497 if (isToggled) {
498 fCanvasWidget.setGLSampleCount(fSettingsWidget.getGLSampleCount());
499 }
chudy@google.comea5488b2012-07-26 19:38:22 +0000500 fCanvasWidget.setWidgetVisibility(SkCanvasWidget::kGPU_WidgetType, !isToggled);
501}
robertphillips@google.come8fe4bc2013-02-13 13:26:13 +0000502#endif
chudy@google.comea5488b2012-07-26 19:38:22 +0000503
chudy@google.com902ebe52012-06-29 14:21:22 +0000504void SkDebuggerGUI::actionInspector() {
chudy@google.comc432f002012-07-10 13:19:25 +0000505 if (fInspectorWidget.isHidden()) {
506 fInspectorWidget.setHidden(false);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000507 fImageWidget.setHidden(false);
chudy@google.com902ebe52012-06-29 14:21:22 +0000508 } else {
chudy@google.comc432f002012-07-10 13:19:25 +0000509 fInspectorWidget.setHidden(true);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000510 fImageWidget.setHidden(true);
chudy@google.com902ebe52012-06-29 14:21:22 +0000511 }
512}
513
514void SkDebuggerGUI::actionPlay() {
chudy@google.comc432f002012-07-10 13:19:25 +0000515 for (int row = fListWidget.currentRow() + 1; row < fListWidget.count();
chudy@google.com7dcae672012-07-09 20:26:53 +0000516 row++) {
chudy@google.comc432f002012-07-10 13:19:25 +0000517 QListWidgetItem *item = fListWidget.item(row);
chudy@google.com902ebe52012-06-29 14:21:22 +0000518 if (item->checkState() == Qt::Checked) {
chudy@google.comc432f002012-07-10 13:19:25 +0000519 fListWidget.setCurrentItem(item);
chudy@google.com902ebe52012-06-29 14:21:22 +0000520 return;
521 }
522 }
chudy@google.comc432f002012-07-10 13:19:25 +0000523 fListWidget.setCurrentRow(fListWidget.count() - 1);
chudy@google.com902ebe52012-06-29 14:21:22 +0000524}
525
chudy@google.comea5488b2012-07-26 19:38:22 +0000526void SkDebuggerGUI::actionRasterWidget(bool isToggled) {
527 fCanvasWidget.setWidgetVisibility(SkCanvasWidget::kRaster_8888_WidgetType, !isToggled);
528}
529
robertphillips@google.comf4741c12013-02-06 20:13:54 +0000530void SkDebuggerGUI::actionOverdrawVizWidget(bool isToggled) {
531 fDebugger.setOverdrawViz(isToggled);
532 fCanvasWidget.update();
533}
534
commit-bot@chromium.org768ac852014-03-03 16:32:17 +0000535void SkDebuggerGUI::actionMegaVizWidget(bool isToggled) {
536 fDebugger.setMegaViz(isToggled);
537 fCanvasWidget.update();
538}
539
commit-bot@chromium.org2a67e122014-05-19 13:53:10 +0000540void SkDebuggerGUI::actionPathOpsWidget(bool isToggled) {
541 fDebugger.setPathOps(isToggled);
542 fCanvasWidget.update();
543}
544
robertphillips@google.com32bbcf82013-10-17 17:56:10 +0000545void SkDebuggerGUI::actionTextureFilter() {
546 SkPaint::FilterLevel level;
547 bool enabled = fSettingsWidget.getFilterOverride(&level);
548 fDebugger.setTexFilterOverride(enabled, level);
549 fCanvasWidget.update();
550}
551
chudy@google.com902ebe52012-06-29 14:21:22 +0000552void SkDebuggerGUI::actionRewind() {
chudy@google.come504de02012-07-16 18:35:23 +0000553 fListWidget.setCurrentRow(0);
chudy@google.com902ebe52012-06-29 14:21:22 +0000554}
555
chudy@google.com0ab03392012-07-28 20:16:11 +0000556void SkDebuggerGUI::actionSave() {
robertphillips@google.come219baf2013-01-28 19:25:43 +0000557 fFileName = fPath.toAscii().data();
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000558 fFileName.append("/");
robertphillips@google.come219baf2013-01-28 19:25:43 +0000559 fFileName.append(fDirectoryWidget.currentItem()->text().toAscii().data());
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000560 saveToFile(fFileName);
chudy@google.com0ab03392012-07-28 20:16:11 +0000561}
562
563void SkDebuggerGUI::actionSaveAs() {
564 QString filename = QFileDialog::getSaveFileName(this, "Save File", "",
565 "Skia Picture (*skp)");
chudy@google.com38b08ce2012-07-28 23:26:10 +0000566 if (!filename.endsWith(".skp", Qt::CaseInsensitive)) {
chudy@google.com0ab03392012-07-28 20:16:11 +0000567 filename.append(".skp");
568 }
djsollen@google.comc3c82162012-11-13 18:35:10 +0000569 saveToFile(SkString(filename.toAscii().data()));
chudy@google.com0ab03392012-07-28 20:16:11 +0000570}
571
chudy@google.com7dcae672012-07-09 20:26:53 +0000572void SkDebuggerGUI::actionScale(float scaleFactor) {
chudy@google.comc432f002012-07-10 13:19:25 +0000573 fSettingsWidget.setZoomText(scaleFactor);
chudy@google.com7dcae672012-07-09 20:26:53 +0000574}
575
chudy@google.com902ebe52012-06-29 14:21:22 +0000576void SkDebuggerGUI::actionSettings() {
chudy@google.comc432f002012-07-10 13:19:25 +0000577 if (fSettingsWidget.isHidden()) {
578 fSettingsWidget.setHidden(false);
chudy@google.com902ebe52012-06-29 14:21:22 +0000579 } else {
chudy@google.comc432f002012-07-10 13:19:25 +0000580 fSettingsWidget.setHidden(true);
chudy@google.com902ebe52012-06-29 14:21:22 +0000581 }
582}
583
584void SkDebuggerGUI::actionStepBack() {
chudy@google.comc432f002012-07-10 13:19:25 +0000585 int currentRow = fListWidget.currentRow();
chudy@google.com902ebe52012-06-29 14:21:22 +0000586 if (currentRow != 0) {
chudy@google.comc432f002012-07-10 13:19:25 +0000587 fListWidget.setCurrentRow(currentRow - 1);
chudy@google.com902ebe52012-06-29 14:21:22 +0000588 }
589}
590
591void SkDebuggerGUI::actionStepForward() {
chudy@google.comc432f002012-07-10 13:19:25 +0000592 int currentRow = fListWidget.currentRow();
chudy@google.com902ebe52012-06-29 14:21:22 +0000593 QString curRow = QString::number(currentRow);
chudy@google.comc432f002012-07-10 13:19:25 +0000594 QString curCount = QString::number(fListWidget.count());
595 if (currentRow < fListWidget.count() - 1) {
596 fListWidget.setCurrentRow(currentRow + 1);
chudy@google.com902ebe52012-06-29 14:21:22 +0000597 }
598}
599
chudy@google.coma9e937c2012-08-03 17:32:05 +0000600void SkDebuggerGUI::drawComplete() {
chudy@google.com607357f2012-08-07 16:12:23 +0000601 fInspectorWidget.setMatrix(fDebugger.getCurrentMatrix());
602 fInspectorWidget.setClip(fDebugger.getCurrentClip());
chudy@google.coma9e937c2012-08-03 17:32:05 +0000603}
604
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000605void SkDebuggerGUI::saveToFile(const SkString& filename) {
606 SkFILEWStream file(filename.c_str());
robertphillips@google.com25bc2f82013-01-22 18:03:56 +0000607 SkAutoTUnref<SkPicture> copy(fDebugger.copyPicture());
608
609 copy->serialize(&file);
chudy@google.com0ab03392012-07-28 20:16:11 +0000610}
611
chudy@google.com902ebe52012-06-29 14:21:22 +0000612void SkDebuggerGUI::loadFile(QListWidgetItem *item) {
613 if (fDirectoryWidgetActive) {
robertphillips@google.come219baf2013-01-28 19:25:43 +0000614 fFileName = fPath.toAscii().data();
jvanverth@google.com0ac6f162013-02-05 19:44:07 +0000615 // don't add a '/' to files in the local directory
616 if (fFileName.size() > 0) {
617 fFileName.append("/");
618 }
robertphillips@google.come219baf2013-01-28 19:25:43 +0000619 fFileName.append(item->text().toAscii().data());
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000620 loadPicture(fFileName);
chudy@google.com902ebe52012-06-29 14:21:22 +0000621 }
622}
623
624void SkDebuggerGUI::openFile() {
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000625 QString temp = QFileDialog::getOpenFileName(this, tr("Open File"), "",
chudy@google.com7dcae672012-07-09 20:26:53 +0000626 tr("Files (*.*)"));
robertphillips@google.comff6e6ba2013-01-28 17:43:26 +0000627 openFile(temp);
628}
629
630void SkDebuggerGUI::openFile(const QString &filename) {
chudy@google.com902ebe52012-06-29 14:21:22 +0000631 fDirectoryWidgetActive = false;
robertphillips@google.comff6e6ba2013-01-28 17:43:26 +0000632 if (!filename.isEmpty()) {
633 QFileInfo pathInfo(filename);
634 loadPicture(SkString(filename.toAscii().data()));
635 setupDirectoryWidget(pathInfo.path());
chudy@google.com902ebe52012-06-29 14:21:22 +0000636 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000637 fDirectoryWidgetActive = true;
638}
639
chudy@google.comc432f002012-07-10 13:19:25 +0000640void SkDebuggerGUI::pauseDrawing(bool isPaused) {
chudy@google.com607357f2012-08-07 16:12:23 +0000641 fPause = isPaused;
642 fPausedRow = fListWidget.currentRow();
643 fCanvasWidget.drawTo(fPausedRow);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000644 fImageWidget.draw();
chudy@google.com7dcae672012-07-09 20:26:53 +0000645}
646
chudy@google.com902ebe52012-06-29 14:21:22 +0000647void SkDebuggerGUI::registerListClick(QListWidgetItem *item) {
chudy@google.comd3058f52012-07-19 13:41:27 +0000648 if(!fLoading) {
649 int currentRow = fListWidget.currentRow();
chudy@google.comd3058f52012-07-19 13:41:27 +0000650
chudy@google.comea5488b2012-07-26 19:38:22 +0000651 if (currentRow != -1) {
652 if (!fPause) {
653 fCanvasWidget.drawTo(currentRow);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000654 fImageWidget.draw();
chudy@google.comd3058f52012-07-19 13:41:27 +0000655 }
chudy@google.com97cee972012-08-07 20:41:37 +0000656 SkTDArray<SkString*> *currInfo = fDebugger.getCommandInfo(
chudy@google.comea5488b2012-07-26 19:38:22 +0000657 currentRow);
658
659 /* TODO(chudy): Add command type before parameters. Rename v
660 * to something more informative. */
chudy@google.com97cee972012-08-07 20:41:37 +0000661 if (currInfo) {
chudy@google.comea5488b2012-07-26 19:38:22 +0000662 QString info;
663 info.append("<b>Parameters: </b><br/>");
chudy@google.com97cee972012-08-07 20:41:37 +0000664 for (int i = 0; i < currInfo->count(); i++) {
665
666 info.append(QString((*currInfo)[i]->c_str()));
chudy@google.comea5488b2012-07-26 19:38:22 +0000667 info.append("<br/>");
668 }
chudy@google.com6bd109a2012-08-14 19:34:13 +0000669 fInspectorWidget.setText(info, SkInspectorWidget::kDetail_TabType);
chudy@google.comea5488b2012-07-26 19:38:22 +0000670 fInspectorWidget.setDisabled(false);
chudy@google.comea5488b2012-07-26 19:38:22 +0000671 }
commit-bot@chromium.org2a67e122014-05-19 13:53:10 +0000672 setupClipStackText();
chudy@google.comd3058f52012-07-19 13:41:27 +0000673 }
chudy@google.comea5488b2012-07-26 19:38:22 +0000674
chudy@google.com902ebe52012-06-29 14:21:22 +0000675 }
676}
677
chudy@google.com9ca9bfe2012-07-12 21:58:14 +0000678void SkDebuggerGUI::selectCommand(int command) {
679 if (fPause) {
680 fListWidget.setCurrentRow(command);
681 }
682}
683
chudy@google.com902ebe52012-06-29 14:21:22 +0000684void SkDebuggerGUI::toggleBreakpoint() {
chudy@google.comc432f002012-07-10 13:19:25 +0000685 QListWidgetItem* item = fListWidget.currentItem();
chudy@google.com902ebe52012-06-29 14:21:22 +0000686 if (item->checkState() == Qt::Unchecked) {
687 item->setCheckState(Qt::Checked);
chudy@google.come565de42012-07-12 14:15:54 +0000688 item->setData(Qt::DecorationRole,
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000689 QPixmap(":/breakpoint_16x16.png"));
chudy@google.com902ebe52012-06-29 14:21:22 +0000690 } else {
chudy@google.com902ebe52012-06-29 14:21:22 +0000691 item->setCheckState(Qt::Unchecked);
chudy@google.come565de42012-07-12 14:15:54 +0000692 item->setData(Qt::DecorationRole,
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000693 QPixmap(":/blank.png"));
chudy@google.com902ebe52012-06-29 14:21:22 +0000694 }
695}
696
697void SkDebuggerGUI::toggleDirectory() {
chudy@google.com607357f2012-08-07 16:12:23 +0000698 fDirectoryWidget.setHidden(!fDirectoryWidget.isHidden());
chudy@google.com902ebe52012-06-29 14:21:22 +0000699}
700
701void SkDebuggerGUI::toggleFilter(QString string) {
chudy@google.comc432f002012-07-10 13:19:25 +0000702 for (int row = 0; row < fListWidget.count(); row++) {
703 QListWidgetItem *item = fListWidget.item(row);
chudy@google.com607357f2012-08-07 16:12:23 +0000704 item->setHidden(item->text() != string);
chudy@google.com902ebe52012-06-29 14:21:22 +0000705 }
706}
707
708void SkDebuggerGUI::setupUi(QMainWindow *SkDebuggerGUI) {
709 QIcon windowIcon;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000710 windowIcon.addFile(QString::fromUtf8(":/skia.png"), QSize(),
chudy@google.com7dcae672012-07-09 20:26:53 +0000711 QIcon::Normal, QIcon::Off);
chudy@google.com902ebe52012-06-29 14:21:22 +0000712 SkDebuggerGUI->setObjectName(QString::fromUtf8("SkDebuggerGUI"));
713 SkDebuggerGUI->resize(1200, 1000);
714 SkDebuggerGUI->setWindowIcon(windowIcon);
chudy@google.comc432f002012-07-10 13:19:25 +0000715 SkDebuggerGUI->setWindowTitle("Skia Debugger");
chudy@google.com902ebe52012-06-29 14:21:22 +0000716
chudy@google.come504de02012-07-16 18:35:23 +0000717 fActionOpen.setShortcuts(QKeySequence::Open);
chudy@google.comc432f002012-07-10 13:19:25 +0000718 fActionOpen.setText("Open");
chudy@google.com902ebe52012-06-29 14:21:22 +0000719
720 QIcon breakpoint;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000721 breakpoint.addFile(QString::fromUtf8(":/breakpoint.png"),
chudy@google.com7dcae672012-07-09 20:26:53 +0000722 QSize(), QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000723 fActionBreakpoint.setShortcut(QKeySequence(tr("Ctrl+B")));
chudy@google.comc432f002012-07-10 13:19:25 +0000724 fActionBreakpoint.setIcon(breakpoint);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000725 fActionBreakpoint.setText("Breakpoints");
chudy@google.com902ebe52012-06-29 14:21:22 +0000726
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000727 fActionToggleIndexStyle.setShortcut(QKeySequence(tr("Ctrl+T")));
728 fActionToggleIndexStyle.setText("Toggle Index Style");
729
chudy@google.com902ebe52012-06-29 14:21:22 +0000730 QIcon cancel;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000731 cancel.addFile(QString::fromUtf8(":/reload.png"), QSize(),
chudy@google.com7dcae672012-07-09 20:26:53 +0000732 QIcon::Normal, QIcon::Off);
chudy@google.comc432f002012-07-10 13:19:25 +0000733 fActionCancel.setIcon(cancel);
734 fActionCancel.setText("Clear Filter");
chudy@google.com902ebe52012-06-29 14:21:22 +0000735
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000736 fActionClearBreakpoints.setShortcut(QKeySequence(tr("Alt+B")));
737 fActionClearBreakpoints.setText("Clear Breakpoints");
738
739 fActionClearDeletes.setShortcut(QKeySequence(tr("Alt+X")));
740 fActionClearDeletes.setText("Clear Deletes");
741
chudy@google.come504de02012-07-16 18:35:23 +0000742 fActionClose.setShortcuts(QKeySequence::Quit);
chudy@google.comc432f002012-07-10 13:19:25 +0000743 fActionClose.setText("Exit");
chudy@google.com902ebe52012-06-29 14:21:22 +0000744
chudy@google.come504de02012-07-16 18:35:23 +0000745 fActionCreateBreakpoint.setShortcut(QKeySequence(tr("B")));
746 fActionCreateBreakpoint.setText("Set Breakpoint");
747
748 fActionDelete.setShortcut(QKeySequence(tr("X")));
chudy@google.comc432f002012-07-10 13:19:25 +0000749 fActionDelete.setText("Delete Command");
chudy@google.com902ebe52012-06-29 14:21:22 +0000750
chudy@google.come504de02012-07-16 18:35:23 +0000751 fActionDirectory.setShortcut(QKeySequence(tr("Ctrl+D")));
752 fActionDirectory.setText("Directory");
chudy@google.com902ebe52012-06-29 14:21:22 +0000753
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000754 QIcon profile;
robertphillips@google.comd1636362012-11-19 18:25:09 +0000755 profile.addFile(QString::fromUtf8(":/profile.png"), QSize(),
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000756 QIcon::Normal, QIcon::Off);
757 fActionProfile.setIcon(profile);
758 fActionProfile.setText("Profile");
robertphillips@google.come099bc42012-11-19 16:26:40 +0000759 fActionProfile.setDisabled(true);
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000760
chudy@google.comc432f002012-07-10 13:19:25 +0000761 QIcon inspector;
robertphillips@google.comd1636362012-11-19 18:25:09 +0000762 inspector.addFile(QString::fromUtf8(":/inspector.png"),
chudy@google.comc432f002012-07-10 13:19:25 +0000763 QSize(), QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000764 fActionInspector.setShortcut(QKeySequence(tr("Ctrl+I")));
chudy@google.comc432f002012-07-10 13:19:25 +0000765 fActionInspector.setIcon(inspector);
chudy@google.come504de02012-07-16 18:35:23 +0000766 fActionInspector.setText("Inspector");
chudy@google.com902ebe52012-06-29 14:21:22 +0000767
bungeman@google.com2ff6d1d2013-07-01 14:24:12 +0000768 QIcon settings;
769 settings.addFile(QString::fromUtf8(":/inspector.png"),
770 QSize(), QIcon::Normal, QIcon::Off);
771 fActionSettings.setShortcut(QKeySequence(tr("Ctrl+G")));
772 fActionSettings.setIcon(settings);
773 fActionSettings.setText("Settings");
skia.committer@gmail.com0d55dd72013-07-02 07:00:59 +0000774
chudy@google.comc432f002012-07-10 13:19:25 +0000775 QIcon play;
robertphillips@google.comd1636362012-11-19 18:25:09 +0000776 play.addFile(QString::fromUtf8(":/play.png"), QSize(),
chudy@google.comc432f002012-07-10 13:19:25 +0000777 QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000778 fActionPlay.setShortcut(QKeySequence(tr("Ctrl+P")));
chudy@google.comc432f002012-07-10 13:19:25 +0000779 fActionPlay.setIcon(play);
780 fActionPlay.setText("Play");
chudy@google.com902ebe52012-06-29 14:21:22 +0000781
chudy@google.come504de02012-07-16 18:35:23 +0000782 QIcon pause;
robertphillips@google.comd1636362012-11-19 18:25:09 +0000783 pause.addFile(QString::fromUtf8(":/pause.png"), QSize(),
chudy@google.comc432f002012-07-10 13:19:25 +0000784 QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000785 fActionPause.setShortcut(QKeySequence(tr("Space")));
786 fActionPause.setCheckable(true);
787 fActionPause.setIcon(pause);
788 fActionPause.setText("Pause");
789
chudy@google.comc432f002012-07-10 13:19:25 +0000790 QIcon rewind;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000791 rewind.addFile(QString::fromUtf8(":/rewind.png"), QSize(),
chudy@google.comc432f002012-07-10 13:19:25 +0000792 QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000793 fActionRewind.setShortcut(QKeySequence(tr("Ctrl+R")));
chudy@google.comc432f002012-07-10 13:19:25 +0000794 fActionRewind.setIcon(rewind);
795 fActionRewind.setText("Rewind");
chudy@google.com902ebe52012-06-29 14:21:22 +0000796
chudy@google.com0ab03392012-07-28 20:16:11 +0000797 fActionSave.setShortcut(QKeySequence::Save);
798 fActionSave.setText("Save");
799 fActionSave.setDisabled(true);
800 fActionSaveAs.setShortcut(QKeySequence::SaveAs);
801 fActionSaveAs.setText("Save As");
802 fActionSaveAs.setDisabled(true);
803
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000804 fActionShowDeletes.setShortcut(QKeySequence(tr("Ctrl+X")));
805 fActionShowDeletes.setText("Deleted Commands");
806
chudy@google.comc432f002012-07-10 13:19:25 +0000807 QIcon stepBack;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000808 stepBack.addFile(QString::fromUtf8(":/previous.png"), QSize(),
chudy@google.comc432f002012-07-10 13:19:25 +0000809 QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000810 fActionStepBack.setShortcut(QKeySequence(tr("[")));
chudy@google.comc432f002012-07-10 13:19:25 +0000811 fActionStepBack.setIcon(stepBack);
812 fActionStepBack.setText("Step Back");
chudy@google.com902ebe52012-06-29 14:21:22 +0000813
chudy@google.comc432f002012-07-10 13:19:25 +0000814 QIcon stepForward;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000815 stepForward.addFile(QString::fromUtf8(":/next.png"),
chudy@google.comc432f002012-07-10 13:19:25 +0000816 QSize(), QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000817 fActionStepForward.setShortcut(QKeySequence(tr("]")));
chudy@google.comc432f002012-07-10 13:19:25 +0000818 fActionStepForward.setIcon(stepForward);
819 fActionStepForward.setText("Step Forward");
820
chudy@google.coma1226312012-07-26 20:26:44 +0000821 fActionZoomIn.setShortcut(QKeySequence(tr("Ctrl+=")));
822 fActionZoomIn.setText("Zoom In");
823 fActionZoomOut.setShortcut(QKeySequence(tr("Ctrl+-")));
824 fActionZoomOut.setText("Zoom Out");
825
chudy@google.comc432f002012-07-10 13:19:25 +0000826 fListWidget.setItemDelegate(new SkListWidget(&fListWidget));
827 fListWidget.setObjectName(QString::fromUtf8("listWidget"));
commit-bot@chromium.orgbcd431e2013-11-21 13:41:37 +0000828 fListWidget.setMinimumWidth(250);
chudy@google.comc432f002012-07-10 13:19:25 +0000829
830 fFilter.addItem("--Filter By Available Commands--");
831
commit-bot@chromium.orgbcd431e2013-11-21 13:41:37 +0000832 fDirectoryWidget.setMinimumWidth(250);
chudy@google.comc432f002012-07-10 13:19:25 +0000833 fDirectoryWidget.setStyleSheet("QListWidget::Item {padding: 5px;}");
834
835 fCanvasWidget.setSizePolicy(QSizePolicy::Expanding,
chudy@google.com7dcae672012-07-09 20:26:53 +0000836 QSizePolicy::Expanding);
chudy@google.com902ebe52012-06-29 14:21:22 +0000837
skia.committer@gmail.com1c9c0d32012-11-22 02:02:41 +0000838 fImageWidget.setFixedSize(SkImageWidget::kImageWidgetWidth,
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000839 SkImageWidget::kImageWidgetHeight);
840
chudy@google.comc432f002012-07-10 13:19:25 +0000841 fInspectorWidget.setSizePolicy(QSizePolicy::Expanding,
chudy@google.com7dcae672012-07-09 20:26:53 +0000842 QSizePolicy::Expanding);
chudy@google.comc432f002012-07-10 13:19:25 +0000843 fInspectorWidget.setMaximumHeight(300);
chudy@google.com902ebe52012-06-29 14:21:22 +0000844
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000845 fSettingsAndImageLayout.setSpacing(6);
846 fSettingsAndImageLayout.addWidget(&fSettingsWidget);
847 fSettingsAndImageLayout.addWidget(&fImageWidget);
848
chudy@google.comc432f002012-07-10 13:19:25 +0000849 fSettingsWidget.setSizePolicy(QSizePolicy::Expanding,
850 QSizePolicy::Expanding);
851 fSettingsWidget.setMaximumWidth(250);
chudy@google.com902ebe52012-06-29 14:21:22 +0000852
commit-bot@chromium.orgbcd431e2013-11-21 13:41:37 +0000853 fLeftColumnSplitter.addWidget(&fListWidget);
854 fLeftColumnSplitter.addWidget(&fDirectoryWidget);
855 fLeftColumnSplitter.setOrientation(Qt::Vertical);
chudy@google.com902ebe52012-06-29 14:21:22 +0000856
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000857 fCanvasSettingsAndImageLayout.setSpacing(6);
858 fCanvasSettingsAndImageLayout.addWidget(&fCanvasWidget);
859 fCanvasSettingsAndImageLayout.addLayout(&fSettingsAndImageLayout);
860
chudy@google.comc432f002012-07-10 13:19:25 +0000861 fMainAndRightColumnLayout.setSpacing(6);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000862 fMainAndRightColumnLayout.addLayout(&fCanvasSettingsAndImageLayout);
chudy@google.comc432f002012-07-10 13:19:25 +0000863 fMainAndRightColumnLayout.addWidget(&fInspectorWidget);
commit-bot@chromium.orgbcd431e2013-11-21 13:41:37 +0000864 fMainAndRightColumnWidget.setLayout(&fMainAndRightColumnLayout);
chudy@google.com902ebe52012-06-29 14:21:22 +0000865
commit-bot@chromium.orgbcd431e2013-11-21 13:41:37 +0000866 fCentralSplitter.addWidget(&fLeftColumnSplitter);
867 fCentralSplitter.addWidget(&fMainAndRightColumnWidget);
868 fCentralSplitter.setStretchFactor(0, 0);
869 fCentralSplitter.setStretchFactor(1, 1);
chudy@google.comc432f002012-07-10 13:19:25 +0000870
commit-bot@chromium.orgbcd431e2013-11-21 13:41:37 +0000871 SkDebuggerGUI->setCentralWidget(&fCentralSplitter);
chudy@google.comc432f002012-07-10 13:19:25 +0000872 SkDebuggerGUI->setStatusBar(&fStatusBar);
873
chudy@google.come504de02012-07-16 18:35:23 +0000874 fToolBar.setIconSize(QSize(32, 32));
chudy@google.comc432f002012-07-10 13:19:25 +0000875 fToolBar.setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
876 SkDebuggerGUI->addToolBar(Qt::TopToolBarArea, &fToolBar);
chudy@google.com902ebe52012-06-29 14:21:22 +0000877
chudy@google.com0ab03392012-07-28 20:16:11 +0000878 fSpacer.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
chudy@google.com902ebe52012-06-29 14:21:22 +0000879
chudy@google.comc432f002012-07-10 13:19:25 +0000880 fToolBar.addAction(&fActionRewind);
881 fToolBar.addAction(&fActionStepBack);
chudy@google.come504de02012-07-16 18:35:23 +0000882 fToolBar.addAction(&fActionPause);
chudy@google.comc432f002012-07-10 13:19:25 +0000883 fToolBar.addAction(&fActionStepForward);
884 fToolBar.addAction(&fActionPlay);
885 fToolBar.addSeparator();
chudy@google.come504de02012-07-16 18:35:23 +0000886 fToolBar.addAction(&fActionInspector);
bungeman@google.com2ff6d1d2013-07-01 14:24:12 +0000887 fToolBar.addAction(&fActionSettings);
chudy@google.comc432f002012-07-10 13:19:25 +0000888 fToolBar.addSeparator();
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000889 fToolBar.addAction(&fActionProfile);
890
891 fToolBar.addSeparator();
chudy@google.com0ab03392012-07-28 20:16:11 +0000892 fToolBar.addWidget(&fSpacer);
chudy@google.comc432f002012-07-10 13:19:25 +0000893 fToolBar.addWidget(&fFilter);
894 fToolBar.addAction(&fActionCancel);
chudy@google.com902ebe52012-06-29 14:21:22 +0000895
896 // TODO(chudy): Remove static call.
897 fDirectoryWidgetActive = false;
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000898 fFileName = "";
robertphillips@google.comff6e6ba2013-01-28 17:43:26 +0000899 setupDirectoryWidget("");
chudy@google.com902ebe52012-06-29 14:21:22 +0000900 fDirectoryWidgetActive = true;
901
chudy@google.com902ebe52012-06-29 14:21:22 +0000902 // Menu Bar
chudy@google.comc432f002012-07-10 13:19:25 +0000903 fMenuFile.setTitle("File");
904 fMenuFile.addAction(&fActionOpen);
chudy@google.com0ab03392012-07-28 20:16:11 +0000905 fMenuFile.addAction(&fActionSave);
906 fMenuFile.addAction(&fActionSaveAs);
chudy@google.comc432f002012-07-10 13:19:25 +0000907 fMenuFile.addAction(&fActionClose);
chudy@google.come504de02012-07-16 18:35:23 +0000908
909 fMenuEdit.setTitle("Edit");
910 fMenuEdit.addAction(&fActionDelete);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000911 fMenuEdit.addAction(&fActionClearDeletes);
912 fMenuEdit.addSeparator();
chudy@google.come504de02012-07-16 18:35:23 +0000913 fMenuEdit.addAction(&fActionCreateBreakpoint);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000914 fMenuEdit.addAction(&fActionClearBreakpoints);
chudy@google.come504de02012-07-16 18:35:23 +0000915
chudy@google.comc432f002012-07-10 13:19:25 +0000916 fMenuNavigate.setTitle("Navigate");
chudy@google.come504de02012-07-16 18:35:23 +0000917 fMenuNavigate.addAction(&fActionRewind);
918 fMenuNavigate.addAction(&fActionStepBack);
919 fMenuNavigate.addAction(&fActionStepForward);
920 fMenuNavigate.addAction(&fActionPlay);
921 fMenuNavigate.addAction(&fActionPause);
chudy@google.comc432f002012-07-10 13:19:25 +0000922 fMenuNavigate.addAction(&fActionGoToLine);
chudy@google.come504de02012-07-16 18:35:23 +0000923
chudy@google.comc432f002012-07-10 13:19:25 +0000924 fMenuView.setTitle("View");
chudy@google.come504de02012-07-16 18:35:23 +0000925 fMenuView.addAction(&fActionBreakpoint);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000926 fMenuView.addAction(&fActionShowDeletes);
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000927 fMenuView.addAction(&fActionToggleIndexStyle);
chudy@google.coma1226312012-07-26 20:26:44 +0000928 fMenuView.addAction(&fActionZoomIn);
929 fMenuView.addAction(&fActionZoomOut);
chudy@google.come504de02012-07-16 18:35:23 +0000930
931 fMenuWindows.setTitle("Window");
932 fMenuWindows.addAction(&fActionInspector);
bungeman@google.com2ff6d1d2013-07-01 14:24:12 +0000933 fMenuWindows.addAction(&fActionSettings);
chudy@google.come504de02012-07-16 18:35:23 +0000934 fMenuWindows.addAction(&fActionDirectory);
chudy@google.comc432f002012-07-10 13:19:25 +0000935
936 fActionGoToLine.setText("Go to Line...");
937 fActionGoToLine.setDisabled(true);
938 fMenuBar.addAction(fMenuFile.menuAction());
chudy@google.come504de02012-07-16 18:35:23 +0000939 fMenuBar.addAction(fMenuEdit.menuAction());
chudy@google.comc432f002012-07-10 13:19:25 +0000940 fMenuBar.addAction(fMenuView.menuAction());
941 fMenuBar.addAction(fMenuNavigate.menuAction());
chudy@google.come504de02012-07-16 18:35:23 +0000942 fMenuBar.addAction(fMenuWindows.menuAction());
chudy@google.com902ebe52012-06-29 14:21:22 +0000943
chudy@google.com7dcae672012-07-09 20:26:53 +0000944 fPause = false;
945
chudy@google.comc432f002012-07-10 13:19:25 +0000946 SkDebuggerGUI->setMenuBar(&fMenuBar);
chudy@google.com902ebe52012-06-29 14:21:22 +0000947 QMetaObject::connectSlotsByName(SkDebuggerGUI);
948}
949
robertphillips@google.comff6e6ba2013-01-28 17:43:26 +0000950void SkDebuggerGUI::setupDirectoryWidget(const QString& path) {
951 fPath = path;
952 QDir dir(path);
chudy@google.com902ebe52012-06-29 14:21:22 +0000953 QRegExp r(".skp");
chudy@google.comc432f002012-07-10 13:19:25 +0000954 fDirectoryWidget.clear();
955 const QStringList files = dir.entryList();
chudy@google.com902ebe52012-06-29 14:21:22 +0000956 foreach (QString f, files) {
chudy@google.com7dcae672012-07-09 20:26:53 +0000957 if (f.contains(r))
chudy@google.comc432f002012-07-10 13:19:25 +0000958 fDirectoryWidget.addItem(f);
chudy@google.com902ebe52012-06-29 14:21:22 +0000959 }
960}
961
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000962void SkDebuggerGUI::loadPicture(const SkString& fileName) {
963 fFileName = fileName;
chudy@google.comd3058f52012-07-19 13:41:27 +0000964 fLoading = true;
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000965 SkStream* stream = SkNEW_ARGS(SkFILEStream, (fileName.c_str()));
robertphillips@google.com2d40ec42013-02-07 20:39:40 +0000966
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000967 SkPicture* picture = SkPicture::CreateFromStream(stream);
robertphillips@google.com2d40ec42013-02-07 20:39:40 +0000968
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000969 if (NULL == picture) {
robertphillips@google.com2d40ec42013-02-07 20:39:40 +0000970 QMessageBox::critical(this, "Error loading file", "Couldn't read file, sorry.");
971 SkSafeUnref(stream);
972 return;
973 }
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000974
chudy@google.com686e6802012-08-14 16:00:32 +0000975 fCanvasWidget.resetWidgetTransform();
chudy@google.com607357f2012-08-07 16:12:23 +0000976 fDebugger.loadPicture(picture);
chudy@google.com4c7962e2012-08-14 19:38:31 +0000977
robertphillips@google.com6d9c92b2013-05-23 13:21:18 +0000978 fSkipCommands.setCount(fDebugger.getSize());
979 for (int i = 0; i < fSkipCommands.count(); ++i) {
robertphillips@google.com5f971142012-12-07 20:48:56 +0000980 fSkipCommands[i] = false;
981 }
982
chudy@google.com607357f2012-08-07 16:12:23 +0000983 SkSafeUnref(stream);
984 SkSafeUnref(picture);
985
chudy@google.com97cee972012-08-07 20:41:37 +0000986 // Will this automatically clear out due to nature of refcnt?
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000987 SkTArray<SkString>* commands = fDebugger.getDrawCommandsAsStrings();
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000988 SkTDArray<size_t>* offsets = fDebugger.getDrawCommandOffsets();
989 SkASSERT(commands->count() == offsets->count());
chudy@google.com607357f2012-08-07 16:12:23 +0000990
robertphillips@google.com6d9c92b2013-05-23 13:21:18 +0000991 fActionProfile.setDisabled(false);
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000992
chudy@google.com7dcae672012-07-09 20:26:53 +0000993 /* fDebugCanvas is reinitialized every load picture. Need it to retain value
chudy@google.com607357f2012-08-07 16:12:23 +0000994 * of the visibility filter.
995 * TODO(chudy): This should be deprecated since fDebugger is not
996 * recreated.
997 * */
commit-bot@chromium.org22d39332013-11-21 15:37:29 +0000998 fDebugger.highlightCurrentCommand(fSettingsWidget.getVisibilityFilter());
chudy@google.com607357f2012-08-07 16:12:23 +0000999
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +00001000 this->setupListWidget(commands, offsets);
1001 this->setupComboBox(commands);
1002 this->setupOverviewText(NULL, 0.0, 1);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +00001003 fInspectorWidget.setDisabled(false);
chudy@google.come606d6e2012-07-12 14:31:25 +00001004 fSettingsWidget.setDisabled(false);
chudy@google.comd3058f52012-07-19 13:41:27 +00001005 fMenuEdit.setDisabled(false);
1006 fMenuNavigate.setDisabled(false);
1007 fMenuView.setDisabled(false);
chudy@google.com0ab03392012-07-28 20:16:11 +00001008 fActionSave.setDisabled(false);
1009 fActionSaveAs.setDisabled(false);
chudy@google.comd3058f52012-07-19 13:41:27 +00001010 fLoading = false;
1011 actionPlay();
chudy@google.com902ebe52012-06-29 14:21:22 +00001012}
1013
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +00001014void SkDebuggerGUI::setupListWidget(SkTArray<SkString>* commands, SkTDArray<size_t>* offsets) {
1015 SkASSERT(commands->count() == offsets->count());
chudy@google.comc432f002012-07-10 13:19:25 +00001016 fListWidget.clear();
chudy@google.com902ebe52012-06-29 14:21:22 +00001017 int counter = 0;
robertphillips@google.com30d35f22012-11-06 16:45:36 +00001018 int indent = 0;
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +00001019 for (int i = 0; i < commands->count(); i++) {
chudy@google.com902ebe52012-06-29 14:21:22 +00001020 QListWidgetItem *item = new QListWidgetItem();
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +00001021 item->setData(Qt::DisplayRole, (*commands)[i].c_str());
chudy@google.com902ebe52012-06-29 14:21:22 +00001022 item->setData(Qt::UserRole + 1, counter++);
robertphillips@google.com30d35f22012-11-06 16:45:36 +00001023
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +00001024 if (0 == strcmp("Restore", (*commands)[i].c_str()) ||
1025 0 == strcmp("EndCommentGroup", (*commands)[i].c_str()) ||
1026 0 == strcmp("PopCull", (*commands)[i].c_str())) {
robertphillips@google.com30d35f22012-11-06 16:45:36 +00001027 indent -= 10;
1028 }
1029
1030 item->setData(Qt::UserRole + 3, indent);
1031
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +00001032 if (0 == strcmp("Save", (*commands)[i].c_str()) ||
1033 0 == strcmp("Save Layer", (*commands)[i].c_str()) ||
1034 0 == strcmp("BeginCommentGroup", (*commands)[i].c_str()) ||
1035 0 == strcmp("PushCull", (*commands)[i].c_str())) {
robertphillips@google.com30d35f22012-11-06 16:45:36 +00001036 indent += 10;
1037 }
1038
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +00001039 item->setData(Qt::UserRole + 4, -1);
1040 item->setData(Qt::UserRole + 5, (int)(*offsets)[i]);
robertphillips@google.comd26c7062012-11-12 20:42:12 +00001041
chudy@google.comc432f002012-07-10 13:19:25 +00001042 fListWidget.addItem(item);
chudy@google.com902ebe52012-06-29 14:21:22 +00001043 }
1044}
1045
skia.committer@gmail.com91274b92013-03-13 07:01:04 +00001046void SkDebuggerGUI::setupOverviewText(const SkTDArray<double>* typeTimes,
robertphillips@google.come428f9b2013-03-12 15:33:40 +00001047 double totTime,
1048 int numRuns) {
borenet@google.com2d9dbd42013-03-12 13:07:40 +00001049 SkString overview;
robertphillips@google.come428f9b2013-03-12 15:33:40 +00001050 fDebugger.getOverviewText(typeTimes, totTime, &overview, numRuns);
borenet@google.com2d9dbd42013-03-12 13:07:40 +00001051 fInspectorWidget.setText(overview.c_str(), SkInspectorWidget::kOverview_TabType);
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +00001052}
1053
commit-bot@chromium.org2a67e122014-05-19 13:53:10 +00001054void SkDebuggerGUI::setupClipStackText() {
1055 SkString clipStack;
1056 fDebugger.getClipStackText(&clipStack);
1057 fInspectorWidget.setText(clipStack.c_str(), SkInspectorWidget::kClipStack_TabType);
1058}
1059
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +00001060void SkDebuggerGUI::setupComboBox(SkTArray<SkString>* command) {
1061 fFilter.clear();
1062 fFilter.addItem("--Filter By Available Commands--");
1063
1064 std::map<std::string, int> map;
1065 for (int i = 0; i < command->count(); i++) {
1066 map[(*command)[i].c_str()]++;
1067 }
1068
skia.committer@gmail.com34587162012-11-20 02:01:23 +00001069 for (std::map<std::string, int>::iterator it = map.begin(); it != map.end();
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +00001070 ++it) {
1071 fFilter.addItem((it->first).c_str());
1072 }
chudy@google.com902ebe52012-06-29 14:21:22 +00001073
1074 // NOTE(chudy): Makes first item unselectable.
chudy@google.com7dcae672012-07-09 20:26:53 +00001075 QStandardItemModel* model = qobject_cast<QStandardItemModel*>(
chudy@google.comc432f002012-07-10 13:19:25 +00001076 fFilter.model());
1077 QModelIndex firstIndex = model->index(0, fFilter.modelColumn(),
1078 fFilter.rootModelIndex());
chudy@google.com902ebe52012-06-29 14:21:22 +00001079 QStandardItem* firstItem = model->itemFromIndex(firstIndex);
1080 firstItem->setSelectable(false);
1081}