blob: 1873afca678d972cf7f68e9ccc125916041736c9 [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:
robertphillipse26e65e2014-06-12 05:51:22 -0700163 static SkTimedPicturePlayback* CreateFromStream(SkStream* stream, const SkPictInfo& info,
scroggo@google.com12705322013-10-01 15:30:46 +0000164 SkPicture::InstallPixelRefProc proc,
165 const SkTDArray<bool>& deletedCommands) {
166 // Mimics SkPicturePlayback::CreateFromStream
167 SkAutoTDelete<SkTimedPicturePlayback> playback(SkNEW_ARGS(SkTimedPicturePlayback,
robertphillipse26e65e2014-06-12 05:51:22 -0700168 (deletedCommands, info)));
169 if (!playback->parseStream(stream, proc)) {
scroggo@google.com12705322013-10-01 15:30:46 +0000170 return NULL; // we're invalid
171 }
172 return playback.detach();
173 }
174
robertphillipse26e65e2014-06-12 05:51:22 -0700175 SkTimedPicturePlayback(const SkTDArray<bool>& deletedCommands,
commit-bot@chromium.org8f831f22014-04-23 22:35:42 +0000176 const SkPictInfo& info)
robertphillipse26e65e2014-06-12 05:51:22 -0700177 : INHERITED(info)
bungeman@google.come8cc6e82013-01-17 16:30:56 +0000178 , fSkipCommands(deletedCommands)
179 , fTot(0.0)
180 , fCurCommand(0) {
robertphillips@google.com6d9c92b2013-05-23 13:21:18 +0000181 fTimes.setCount(deletedCommands.count());
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000182 fTypeTimes.setCount(LAST_DRAWTYPE_ENUM+1);
183 this->resetTimes();
184 }
185
186 void resetTimes() {
robertphillips@google.com6d9c92b2013-05-23 13:21:18 +0000187 for (int i = 0; i < fTimes.count(); ++i) {
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000188 fTimes[i] = 0.0;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000189 }
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000190 for (int i = 0; i < fTypeTimes.count(); ++i) {
191 fTypeTimes[i] = 0.0f;
192 }
193 fTot = 0.0;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000194 }
195
196 int count() const { return fTimes.count(); }
197
198 double time(int index) const { return fTimes[index] / fTot; }
199
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000200 const SkTDArray<double>* typeTimes() const { return &fTypeTimes; }
201
202 double totTime() const { return fTot; }
203
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000204protected:
robertphillips@google.come174a8b2012-11-27 16:04:42 +0000205 BenchSysTimer fTimer;
robertphillips@google.com5f971142012-12-07 20:48:56 +0000206 SkTDArray<bool> fSkipCommands; // has the command been deleted in the GUI?
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000207 SkTDArray<double> fTimes; // sum of time consumed for each command
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000208 SkTDArray<double> fTypeTimes; // sum of time consumed for each type of command (e.g., drawPath)
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000209 double fTot; // total of all times in 'fTimes'
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000210 int fCurType;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000211 int fCurCommand; // the current command being executed/timed
212
robertphillips@google.com6d9c92b2013-05-23 13:21:18 +0000213#ifdef SK_DEVELOPER
214 virtual bool preDraw(int opIndex, int type) SK_OVERRIDE {
215 fCurCommand = opIndex;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000216
robertphillips@google.com5f971142012-12-07 20:48:56 +0000217 if (fSkipCommands[fCurCommand]) {
robertphillips@google.com6d9c92b2013-05-23 13:21:18 +0000218 return true;
robertphillips@google.com5f971142012-12-07 20:48:56 +0000219 }
220
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000221 fCurType = type;
222 // The SkDebugCanvas doesn't recognize these types. This class needs to
223 // convert or else we'll wind up with a mismatch between the type counts
224 // the debugger displays and the profile times.
225 if (DRAW_POS_TEXT_TOP_BOTTOM == type) {
226 fCurType = DRAW_POS_TEXT;
227 } else if (DRAW_POS_TEXT_H_TOP_BOTTOM == type) {
228 fCurType = DRAW_POS_TEXT_H;
229 }
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000230
robertphillips@google.come174a8b2012-11-27 16:04:42 +0000231#if defined(SK_BUILD_FOR_WIN32)
232 // CPU timer doesn't work well on Windows
233 fTimer.startWall();
234#else
235 fTimer.startCpu();
236#endif
robertphillips@google.com5f971142012-12-07 20:48:56 +0000237
robertphillips@google.com6d9c92b2013-05-23 13:21:18 +0000238 return false;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000239 }
240
robertphillips@google.com6d9c92b2013-05-23 13:21:18 +0000241 virtual void postDraw(int opIndex) SK_OVERRIDE {
robertphillips@google.come174a8b2012-11-27 16:04:42 +0000242#if defined(SK_BUILD_FOR_WIN32)
243 // CPU timer doesn't work well on Windows
244 double time = fTimer.endWall();
245#else
246 double time = fTimer.endCpu();
247#endif
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000248
robertphillips@google.com6d9c92b2013-05-23 13:21:18 +0000249 SkASSERT(opIndex == fCurCommand);
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000250 SkASSERT(fCurType <= LAST_DRAWTYPE_ENUM);
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000251
robertphillips@google.come174a8b2012-11-27 16:04:42 +0000252 fTimes[fCurCommand] += time;
253 fTypeTimes[fCurType] += time;
254 fTot += time;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000255 }
robertphillips@google.com6d9c92b2013-05-23 13:21:18 +0000256#endif
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000257
258private:
259 typedef SkPicturePlayback INHERITED;
260};
261
262// Wrap SkPicture to allow installation of an SkTimedPicturePlayback object
263class SkTimedPicture : public SkPicture {
264public:
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000265 static SkTimedPicture* CreateTimedPicture(SkStream* stream,
266 SkPicture::InstallPixelRefProc proc,
267 const SkTDArray<bool>& deletedCommands) {
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000268 SkPictInfo info;
commit-bot@chromium.org6f4fb0f2014-03-03 19:18:39 +0000269 if (!InternalOnly_StreamIsSKP(stream, &info)) {
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000270 return NULL;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000271 }
272
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000273 // Check to see if there is a playback to recreate.
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000274 if (stream->readBool()) {
commit-bot@chromium.org8f831f22014-04-23 22:35:42 +0000275 SkTimedPicturePlayback* playback = SkTimedPicturePlayback::CreateFromStream(
robertphillipse26e65e2014-06-12 05:51:22 -0700276 stream,
commit-bot@chromium.org8f831f22014-04-23 22:35:42 +0000277 info, proc,
scroggo@google.com12705322013-10-01 15:30:46 +0000278 deletedCommands);
279 if (NULL == playback) {
280 return NULL;
281 }
robertphillipse26e65e2014-06-12 05:51:22 -0700282
283 return SkNEW_ARGS(SkTimedPicture, (playback, info.fWidth, info.fHeight));
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000284 }
285
robertphillipse26e65e2014-06-12 05:51:22 -0700286 return NULL;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000287 }
288
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000289 void resetTimes() { ((SkTimedPicturePlayback*) fPlayback)->resetTimes(); }
290
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000291 int count() const { return ((SkTimedPicturePlayback*) fPlayback)->count(); }
292
293 // return the fraction of the total time this command consumed
294 double time(int index) const { return ((SkTimedPicturePlayback*) fPlayback)->time(index); }
295
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000296 const SkTDArray<double>* typeTimes() const { return ((SkTimedPicturePlayback*) fPlayback)->typeTimes(); }
297
298 double totTime() const { return ((SkTimedPicturePlayback*) fPlayback)->totTime(); }
299
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000300private:
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000301 // disallow default ctor b.c. we don't have a good way to setup the fPlayback ptr
302 SkTimedPicture();
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000303 // Private ctor only used by CreateTimedPicture, which has created the playback.
304 SkTimedPicture(SkTimedPicturePlayback* playback, int width, int height)
305 : INHERITED(playback, width, height) {}
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000306 // disallow the copy ctor - enabling would require copying code from SkPicture
307 SkTimedPicture(const SkTimedPicture& src);
308
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000309 typedef SkPicture INHERITED;
310};
311
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000312// This is a simplification of PictureBenchmark's run with the addition of
313// clearing of the times after the first pass (in resetTimes)
skia.committer@gmail.com34587162012-11-20 02:01:23 +0000314void SkDebuggerGUI::run(SkTimedPicture* pict,
315 sk_tools::PictureRenderer* renderer,
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000316 int repeats) {
317 SkASSERT(pict);
318 if (NULL == pict) {
319 return;
320 }
321
322 SkASSERT(renderer != NULL);
323 if (NULL == renderer) {
324 return;
325 }
326
commit-bot@chromium.org3f045172014-05-15 15:10:48 +0000327 renderer->init(pict, NULL, NULL, NULL, false);
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000328
329 renderer->setup();
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000330 renderer->render();
commit-bot@chromium.org51c040e2014-03-11 22:58:00 +0000331 renderer->resetState(true); // flush, swapBuffers and Finish
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000332
333 // We throw this away the first batch of times to remove first time effects (such as paging in this program)
334 pict->resetTimes();
335
336 for (int i = 0; i < repeats; ++i) {
337 renderer->setup();
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000338 renderer->render();
commit-bot@chromium.org51c040e2014-03-11 22:58:00 +0000339 renderer->resetState(false); // flush & swapBuffers, but don't Finish
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000340 }
commit-bot@chromium.org51c040e2014-03-11 22:58:00 +0000341 renderer->resetState(true); // flush, swapBuffers and Finish
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000342
343 renderer->end();
344}
345
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000346void SkDebuggerGUI::actionProfile() {
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000347 // In order to profile we pass the command offsets (that were read-in
348 // in loadPicture by the SkOffsetPicture) to an SkTimedPlaybackPicture.
skia.committer@gmail.com884e60b2012-11-16 02:01:17 +0000349 // The SkTimedPlaybackPicture in turn passes the offsets to an
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000350 // SkTimedPicturePlayback object which uses them to track the performance
351 // of individual commands.
352 if (fFileName.isEmpty()) {
353 return;
354 }
355
356 SkFILEStream inputStream;
357
358 inputStream.setPath(fFileName.c_str());
359 if (!inputStream.isValid()) {
360 return;
361 }
362
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000363 SkAutoTUnref<SkTimedPicture> picture(SkTimedPicture::CreateTimedPicture(&inputStream,
364 &SkImageDecoder::DecodeMemory, fSkipCommands));
365 if (NULL == picture.get()) {
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000366 return;
367 }
368
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000369 // For now this #if allows switching between tiled and simple rendering
370 // modes. Eventually this will be accomplished via the GUI
robertphillips@google.come174a8b2012-11-27 16:04:42 +0000371#if 0
372 // With the current batch of SysTimers, profiling in tiled mode
373 // gets swamped by the timing overhead:
374 //
375 // tile mode simple mode
376 // debugger 64.2ms 12.8ms
377 // bench_pictures 16.9ms 12.4ms
378 //
379 // This is b.c. in tiled mode each command is called many more times
380 // but typically does less work on each invocation (due to clipping)
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000381 sk_tools::TiledPictureRenderer* renderer = NULL;
382
383 renderer = SkNEW(sk_tools::TiledPictureRenderer);
384 renderer->setTileWidth(256);
385 renderer->setTileHeight(256);
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000386#else
387 sk_tools::SimplePictureRenderer* renderer = NULL;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000388
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000389 renderer = SkNEW(sk_tools::SimplePictureRenderer);
robertphillips@google.com1447aa32013-01-30 21:09:09 +0000390
391#if SK_SUPPORT_GPU
commit-bot@chromium.orgfde1e7c2013-08-02 13:59:50 +0000392 if (fSettingsWidget.isGLActive()) {
robertphillips@google.com1447aa32013-01-30 21:09:09 +0000393 renderer->setDeviceType(sk_tools::PictureRenderer::kGPU_DeviceType);
commit-bot@chromium.orgfde1e7c2013-08-02 13:59:50 +0000394 renderer->setSampleCount(fSettingsWidget.getGLSampleCount());
robertphillips@google.com1447aa32013-01-30 21:09:09 +0000395 }
396#endif
397
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000398#endif
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000399
robertphillips@google.come174a8b2012-11-27 16:04:42 +0000400 static const int kNumRepeats = 10;
401
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000402 run(picture.get(), renderer, kNumRepeats);
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000403
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000404 SkASSERT(picture->count() == fListWidget.count());
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000405
406 // extract the individual command times from the SkTimedPlaybackPicture
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000407 for (int i = 0; i < picture->count(); ++i) {
408 double temp = picture->time(i);
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000409
410 QListWidgetItem* item = fListWidget.item(i);
411
412 item->setData(Qt::UserRole + 4, 100.0*temp);
413 }
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000414
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000415 setupOverviewText(picture->typeTimes(), picture->totTime(), kNumRepeats);
commit-bot@chromium.org2a67e122014-05-19 13:53:10 +0000416 setupClipStackText();
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000417}
418
chudy@google.com902ebe52012-06-29 14:21:22 +0000419void SkDebuggerGUI::actionCancel() {
chudy@google.comc432f002012-07-10 13:19:25 +0000420 for (int row = 0; row < fListWidget.count(); row++) {
421 fListWidget.item(row)->setHidden(false);
chudy@google.com902ebe52012-06-29 14:21:22 +0000422 }
423}
424
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000425void SkDebuggerGUI::actionClearBreakpoints() {
426 for (int row = 0; row < fListWidget.count(); row++) {
427 QListWidgetItem* item = fListWidget.item(row);
428 item->setCheckState(Qt::Unchecked);
429 item->setData(Qt::DecorationRole,
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000430 QPixmap(":/blank.png"));
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000431 }
432}
433
434void SkDebuggerGUI::actionClearDeletes() {
435 for (int row = 0; row < fListWidget.count(); row++) {
436 QListWidgetItem* item = fListWidget.item(row);
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000437 item->setData(Qt::UserRole + 2, QPixmap(":/blank.png"));
chudy@google.com607357f2012-08-07 16:12:23 +0000438 fDebugger.setCommandVisible(row, true);
robertphillips@google.com5f971142012-12-07 20:48:56 +0000439 fSkipCommands[row] = false;
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000440 }
441 if (fPause) {
442 fCanvasWidget.drawTo(fPausedRow);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000443 fImageWidget.draw();
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000444 } else {
445 fCanvasWidget.drawTo(fListWidget.currentRow());
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000446 fImageWidget.draw();
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000447 }
448}
449
chudy@google.com902ebe52012-06-29 14:21:22 +0000450void SkDebuggerGUI::actionCommandFilter() {
commit-bot@chromium.org22d39332013-11-21 15:37:29 +0000451 fDebugger.highlightCurrentCommand(fSettingsWidget.getVisibilityFilter());
chudy@google.comc432f002012-07-10 13:19:25 +0000452 fCanvasWidget.drawTo(fListWidget.currentRow());
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000453 fImageWidget.draw();
chudy@google.com902ebe52012-06-29 14:21:22 +0000454}
455
456void SkDebuggerGUI::actionClose() {
457 this->close();
458}
459
460void SkDebuggerGUI::actionDelete() {
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000461
robertphillips@google.comdd4b7452013-01-22 19:38:46 +0000462 for (int row = 0; row < fListWidget.count(); ++row) {
463 QListWidgetItem* item = fListWidget.item(row);
464
465 if (!item->isSelected()) {
466 continue;
467 }
468
469 if (fDebugger.isCommandVisible(row)) {
470 item->setData(Qt::UserRole + 2, QPixmap(":/delete.png"));
471 fDebugger.setCommandVisible(row, false);
472 fSkipCommands[row] = true;
473 } else {
474 item->setData(Qt::UserRole + 2, QPixmap(":/blank.png"));
475 fDebugger.setCommandVisible(row, true);
476 fSkipCommands[row] = false;
477 }
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000478 }
479
robertphillips@google.comdd4b7452013-01-22 19:38:46 +0000480 int currentRow = fListWidget.currentRow();
481
chudy@google.come504de02012-07-16 18:35:23 +0000482 if (fPause) {
483 fCanvasWidget.drawTo(fPausedRow);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000484 fImageWidget.draw();
chudy@google.come504de02012-07-16 18:35:23 +0000485 } else {
486 fCanvasWidget.drawTo(currentRow);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000487 fImageWidget.draw();
chudy@google.come504de02012-07-16 18:35:23 +0000488 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000489}
490
robertphillips@google.come8fe4bc2013-02-13 13:26:13 +0000491#if SK_SUPPORT_GPU
commit-bot@chromium.orgfde1e7c2013-08-02 13:59:50 +0000492void SkDebuggerGUI::actionGLWidget() {
493 bool isToggled = fSettingsWidget.isGLActive();
494 if (isToggled) {
495 fCanvasWidget.setGLSampleCount(fSettingsWidget.getGLSampleCount());
496 }
chudy@google.comea5488b2012-07-26 19:38:22 +0000497 fCanvasWidget.setWidgetVisibility(SkCanvasWidget::kGPU_WidgetType, !isToggled);
498}
robertphillips@google.come8fe4bc2013-02-13 13:26:13 +0000499#endif
chudy@google.comea5488b2012-07-26 19:38:22 +0000500
chudy@google.com902ebe52012-06-29 14:21:22 +0000501void SkDebuggerGUI::actionInspector() {
chudy@google.comc432f002012-07-10 13:19:25 +0000502 if (fInspectorWidget.isHidden()) {
503 fInspectorWidget.setHidden(false);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000504 fImageWidget.setHidden(false);
chudy@google.com902ebe52012-06-29 14:21:22 +0000505 } else {
chudy@google.comc432f002012-07-10 13:19:25 +0000506 fInspectorWidget.setHidden(true);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000507 fImageWidget.setHidden(true);
chudy@google.com902ebe52012-06-29 14:21:22 +0000508 }
509}
510
511void SkDebuggerGUI::actionPlay() {
chudy@google.comc432f002012-07-10 13:19:25 +0000512 for (int row = fListWidget.currentRow() + 1; row < fListWidget.count();
chudy@google.com7dcae672012-07-09 20:26:53 +0000513 row++) {
chudy@google.comc432f002012-07-10 13:19:25 +0000514 QListWidgetItem *item = fListWidget.item(row);
chudy@google.com902ebe52012-06-29 14:21:22 +0000515 if (item->checkState() == Qt::Checked) {
chudy@google.comc432f002012-07-10 13:19:25 +0000516 fListWidget.setCurrentItem(item);
chudy@google.com902ebe52012-06-29 14:21:22 +0000517 return;
518 }
519 }
chudy@google.comc432f002012-07-10 13:19:25 +0000520 fListWidget.setCurrentRow(fListWidget.count() - 1);
chudy@google.com902ebe52012-06-29 14:21:22 +0000521}
522
chudy@google.comea5488b2012-07-26 19:38:22 +0000523void SkDebuggerGUI::actionRasterWidget(bool isToggled) {
524 fCanvasWidget.setWidgetVisibility(SkCanvasWidget::kRaster_8888_WidgetType, !isToggled);
525}
526
robertphillips@google.comf4741c12013-02-06 20:13:54 +0000527void SkDebuggerGUI::actionOverdrawVizWidget(bool isToggled) {
528 fDebugger.setOverdrawViz(isToggled);
529 fCanvasWidget.update();
530}
531
commit-bot@chromium.org768ac852014-03-03 16:32:17 +0000532void SkDebuggerGUI::actionMegaVizWidget(bool isToggled) {
533 fDebugger.setMegaViz(isToggled);
534 fCanvasWidget.update();
535}
536
commit-bot@chromium.org2a67e122014-05-19 13:53:10 +0000537void SkDebuggerGUI::actionPathOpsWidget(bool isToggled) {
538 fDebugger.setPathOps(isToggled);
539 fCanvasWidget.update();
540}
541
robertphillips@google.com32bbcf82013-10-17 17:56:10 +0000542void SkDebuggerGUI::actionTextureFilter() {
543 SkPaint::FilterLevel level;
544 bool enabled = fSettingsWidget.getFilterOverride(&level);
545 fDebugger.setTexFilterOverride(enabled, level);
546 fCanvasWidget.update();
547}
548
chudy@google.com902ebe52012-06-29 14:21:22 +0000549void SkDebuggerGUI::actionRewind() {
chudy@google.come504de02012-07-16 18:35:23 +0000550 fListWidget.setCurrentRow(0);
chudy@google.com902ebe52012-06-29 14:21:22 +0000551}
552
chudy@google.com0ab03392012-07-28 20:16:11 +0000553void SkDebuggerGUI::actionSave() {
robertphillips@google.come219baf2013-01-28 19:25:43 +0000554 fFileName = fPath.toAscii().data();
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000555 fFileName.append("/");
robertphillips@google.come219baf2013-01-28 19:25:43 +0000556 fFileName.append(fDirectoryWidget.currentItem()->text().toAscii().data());
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000557 saveToFile(fFileName);
chudy@google.com0ab03392012-07-28 20:16:11 +0000558}
559
560void SkDebuggerGUI::actionSaveAs() {
561 QString filename = QFileDialog::getSaveFileName(this, "Save File", "",
562 "Skia Picture (*skp)");
chudy@google.com38b08ce2012-07-28 23:26:10 +0000563 if (!filename.endsWith(".skp", Qt::CaseInsensitive)) {
chudy@google.com0ab03392012-07-28 20:16:11 +0000564 filename.append(".skp");
565 }
djsollen@google.comc3c82162012-11-13 18:35:10 +0000566 saveToFile(SkString(filename.toAscii().data()));
chudy@google.com0ab03392012-07-28 20:16:11 +0000567}
568
chudy@google.com7dcae672012-07-09 20:26:53 +0000569void SkDebuggerGUI::actionScale(float scaleFactor) {
chudy@google.comc432f002012-07-10 13:19:25 +0000570 fSettingsWidget.setZoomText(scaleFactor);
chudy@google.com7dcae672012-07-09 20:26:53 +0000571}
572
chudy@google.com902ebe52012-06-29 14:21:22 +0000573void SkDebuggerGUI::actionSettings() {
chudy@google.comc432f002012-07-10 13:19:25 +0000574 if (fSettingsWidget.isHidden()) {
575 fSettingsWidget.setHidden(false);
chudy@google.com902ebe52012-06-29 14:21:22 +0000576 } else {
chudy@google.comc432f002012-07-10 13:19:25 +0000577 fSettingsWidget.setHidden(true);
chudy@google.com902ebe52012-06-29 14:21:22 +0000578 }
579}
580
581void SkDebuggerGUI::actionStepBack() {
chudy@google.comc432f002012-07-10 13:19:25 +0000582 int currentRow = fListWidget.currentRow();
chudy@google.com902ebe52012-06-29 14:21:22 +0000583 if (currentRow != 0) {
chudy@google.comc432f002012-07-10 13:19:25 +0000584 fListWidget.setCurrentRow(currentRow - 1);
chudy@google.com902ebe52012-06-29 14:21:22 +0000585 }
586}
587
588void SkDebuggerGUI::actionStepForward() {
chudy@google.comc432f002012-07-10 13:19:25 +0000589 int currentRow = fListWidget.currentRow();
chudy@google.com902ebe52012-06-29 14:21:22 +0000590 QString curRow = QString::number(currentRow);
chudy@google.comc432f002012-07-10 13:19:25 +0000591 QString curCount = QString::number(fListWidget.count());
592 if (currentRow < fListWidget.count() - 1) {
593 fListWidget.setCurrentRow(currentRow + 1);
chudy@google.com902ebe52012-06-29 14:21:22 +0000594 }
595}
596
chudy@google.coma9e937c2012-08-03 17:32:05 +0000597void SkDebuggerGUI::drawComplete() {
chudy@google.com607357f2012-08-07 16:12:23 +0000598 fInspectorWidget.setMatrix(fDebugger.getCurrentMatrix());
599 fInspectorWidget.setClip(fDebugger.getCurrentClip());
chudy@google.coma9e937c2012-08-03 17:32:05 +0000600}
601
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000602void SkDebuggerGUI::saveToFile(const SkString& filename) {
603 SkFILEWStream file(filename.c_str());
robertphillips@google.com25bc2f82013-01-22 18:03:56 +0000604 SkAutoTUnref<SkPicture> copy(fDebugger.copyPicture());
605
606 copy->serialize(&file);
chudy@google.com0ab03392012-07-28 20:16:11 +0000607}
608
chudy@google.com902ebe52012-06-29 14:21:22 +0000609void SkDebuggerGUI::loadFile(QListWidgetItem *item) {
610 if (fDirectoryWidgetActive) {
robertphillips@google.come219baf2013-01-28 19:25:43 +0000611 fFileName = fPath.toAscii().data();
jvanverth@google.com0ac6f162013-02-05 19:44:07 +0000612 // don't add a '/' to files in the local directory
613 if (fFileName.size() > 0) {
614 fFileName.append("/");
615 }
robertphillips@google.come219baf2013-01-28 19:25:43 +0000616 fFileName.append(item->text().toAscii().data());
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000617 loadPicture(fFileName);
chudy@google.com902ebe52012-06-29 14:21:22 +0000618 }
619}
620
621void SkDebuggerGUI::openFile() {
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000622 QString temp = QFileDialog::getOpenFileName(this, tr("Open File"), "",
chudy@google.com7dcae672012-07-09 20:26:53 +0000623 tr("Files (*.*)"));
robertphillips@google.comff6e6ba2013-01-28 17:43:26 +0000624 openFile(temp);
625}
626
627void SkDebuggerGUI::openFile(const QString &filename) {
chudy@google.com902ebe52012-06-29 14:21:22 +0000628 fDirectoryWidgetActive = false;
robertphillips@google.comff6e6ba2013-01-28 17:43:26 +0000629 if (!filename.isEmpty()) {
630 QFileInfo pathInfo(filename);
631 loadPicture(SkString(filename.toAscii().data()));
632 setupDirectoryWidget(pathInfo.path());
chudy@google.com902ebe52012-06-29 14:21:22 +0000633 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000634 fDirectoryWidgetActive = true;
635}
636
chudy@google.comc432f002012-07-10 13:19:25 +0000637void SkDebuggerGUI::pauseDrawing(bool isPaused) {
chudy@google.com607357f2012-08-07 16:12:23 +0000638 fPause = isPaused;
639 fPausedRow = fListWidget.currentRow();
640 fCanvasWidget.drawTo(fPausedRow);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000641 fImageWidget.draw();
chudy@google.com7dcae672012-07-09 20:26:53 +0000642}
643
chudy@google.com902ebe52012-06-29 14:21:22 +0000644void SkDebuggerGUI::registerListClick(QListWidgetItem *item) {
chudy@google.comd3058f52012-07-19 13:41:27 +0000645 if(!fLoading) {
646 int currentRow = fListWidget.currentRow();
chudy@google.comd3058f52012-07-19 13:41:27 +0000647
chudy@google.comea5488b2012-07-26 19:38:22 +0000648 if (currentRow != -1) {
649 if (!fPause) {
650 fCanvasWidget.drawTo(currentRow);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000651 fImageWidget.draw();
chudy@google.comd3058f52012-07-19 13:41:27 +0000652 }
chudy@google.com97cee972012-08-07 20:41:37 +0000653 SkTDArray<SkString*> *currInfo = fDebugger.getCommandInfo(
chudy@google.comea5488b2012-07-26 19:38:22 +0000654 currentRow);
655
656 /* TODO(chudy): Add command type before parameters. Rename v
657 * to something more informative. */
chudy@google.com97cee972012-08-07 20:41:37 +0000658 if (currInfo) {
chudy@google.comea5488b2012-07-26 19:38:22 +0000659 QString info;
660 info.append("<b>Parameters: </b><br/>");
chudy@google.com97cee972012-08-07 20:41:37 +0000661 for (int i = 0; i < currInfo->count(); i++) {
662
663 info.append(QString((*currInfo)[i]->c_str()));
chudy@google.comea5488b2012-07-26 19:38:22 +0000664 info.append("<br/>");
665 }
chudy@google.com6bd109a2012-08-14 19:34:13 +0000666 fInspectorWidget.setText(info, SkInspectorWidget::kDetail_TabType);
chudy@google.comea5488b2012-07-26 19:38:22 +0000667 fInspectorWidget.setDisabled(false);
chudy@google.comea5488b2012-07-26 19:38:22 +0000668 }
commit-bot@chromium.org2a67e122014-05-19 13:53:10 +0000669 setupClipStackText();
chudy@google.comd3058f52012-07-19 13:41:27 +0000670 }
chudy@google.comea5488b2012-07-26 19:38:22 +0000671
chudy@google.com902ebe52012-06-29 14:21:22 +0000672 }
673}
674
chudy@google.com9ca9bfe2012-07-12 21:58:14 +0000675void SkDebuggerGUI::selectCommand(int command) {
676 if (fPause) {
677 fListWidget.setCurrentRow(command);
678 }
679}
680
chudy@google.com902ebe52012-06-29 14:21:22 +0000681void SkDebuggerGUI::toggleBreakpoint() {
chudy@google.comc432f002012-07-10 13:19:25 +0000682 QListWidgetItem* item = fListWidget.currentItem();
chudy@google.com902ebe52012-06-29 14:21:22 +0000683 if (item->checkState() == Qt::Unchecked) {
684 item->setCheckState(Qt::Checked);
chudy@google.come565de42012-07-12 14:15:54 +0000685 item->setData(Qt::DecorationRole,
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000686 QPixmap(":/breakpoint_16x16.png"));
chudy@google.com902ebe52012-06-29 14:21:22 +0000687 } else {
chudy@google.com902ebe52012-06-29 14:21:22 +0000688 item->setCheckState(Qt::Unchecked);
chudy@google.come565de42012-07-12 14:15:54 +0000689 item->setData(Qt::DecorationRole,
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000690 QPixmap(":/blank.png"));
chudy@google.com902ebe52012-06-29 14:21:22 +0000691 }
692}
693
694void SkDebuggerGUI::toggleDirectory() {
chudy@google.com607357f2012-08-07 16:12:23 +0000695 fDirectoryWidget.setHidden(!fDirectoryWidget.isHidden());
chudy@google.com902ebe52012-06-29 14:21:22 +0000696}
697
698void SkDebuggerGUI::toggleFilter(QString string) {
chudy@google.comc432f002012-07-10 13:19:25 +0000699 for (int row = 0; row < fListWidget.count(); row++) {
700 QListWidgetItem *item = fListWidget.item(row);
chudy@google.com607357f2012-08-07 16:12:23 +0000701 item->setHidden(item->text() != string);
chudy@google.com902ebe52012-06-29 14:21:22 +0000702 }
703}
704
705void SkDebuggerGUI::setupUi(QMainWindow *SkDebuggerGUI) {
706 QIcon windowIcon;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000707 windowIcon.addFile(QString::fromUtf8(":/skia.png"), QSize(),
chudy@google.com7dcae672012-07-09 20:26:53 +0000708 QIcon::Normal, QIcon::Off);
chudy@google.com902ebe52012-06-29 14:21:22 +0000709 SkDebuggerGUI->setObjectName(QString::fromUtf8("SkDebuggerGUI"));
710 SkDebuggerGUI->resize(1200, 1000);
711 SkDebuggerGUI->setWindowIcon(windowIcon);
chudy@google.comc432f002012-07-10 13:19:25 +0000712 SkDebuggerGUI->setWindowTitle("Skia Debugger");
chudy@google.com902ebe52012-06-29 14:21:22 +0000713
chudy@google.come504de02012-07-16 18:35:23 +0000714 fActionOpen.setShortcuts(QKeySequence::Open);
chudy@google.comc432f002012-07-10 13:19:25 +0000715 fActionOpen.setText("Open");
chudy@google.com902ebe52012-06-29 14:21:22 +0000716
717 QIcon breakpoint;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000718 breakpoint.addFile(QString::fromUtf8(":/breakpoint.png"),
chudy@google.com7dcae672012-07-09 20:26:53 +0000719 QSize(), QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000720 fActionBreakpoint.setShortcut(QKeySequence(tr("Ctrl+B")));
chudy@google.comc432f002012-07-10 13:19:25 +0000721 fActionBreakpoint.setIcon(breakpoint);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000722 fActionBreakpoint.setText("Breakpoints");
chudy@google.com902ebe52012-06-29 14:21:22 +0000723
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000724 fActionToggleIndexStyle.setShortcut(QKeySequence(tr("Ctrl+T")));
725 fActionToggleIndexStyle.setText("Toggle Index Style");
726
chudy@google.com902ebe52012-06-29 14:21:22 +0000727 QIcon cancel;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000728 cancel.addFile(QString::fromUtf8(":/reload.png"), QSize(),
chudy@google.com7dcae672012-07-09 20:26:53 +0000729 QIcon::Normal, QIcon::Off);
chudy@google.comc432f002012-07-10 13:19:25 +0000730 fActionCancel.setIcon(cancel);
731 fActionCancel.setText("Clear Filter");
chudy@google.com902ebe52012-06-29 14:21:22 +0000732
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000733 fActionClearBreakpoints.setShortcut(QKeySequence(tr("Alt+B")));
734 fActionClearBreakpoints.setText("Clear Breakpoints");
735
736 fActionClearDeletes.setShortcut(QKeySequence(tr("Alt+X")));
737 fActionClearDeletes.setText("Clear Deletes");
738
chudy@google.come504de02012-07-16 18:35:23 +0000739 fActionClose.setShortcuts(QKeySequence::Quit);
chudy@google.comc432f002012-07-10 13:19:25 +0000740 fActionClose.setText("Exit");
chudy@google.com902ebe52012-06-29 14:21:22 +0000741
chudy@google.come504de02012-07-16 18:35:23 +0000742 fActionCreateBreakpoint.setShortcut(QKeySequence(tr("B")));
743 fActionCreateBreakpoint.setText("Set Breakpoint");
744
745 fActionDelete.setShortcut(QKeySequence(tr("X")));
chudy@google.comc432f002012-07-10 13:19:25 +0000746 fActionDelete.setText("Delete Command");
chudy@google.com902ebe52012-06-29 14:21:22 +0000747
chudy@google.come504de02012-07-16 18:35:23 +0000748 fActionDirectory.setShortcut(QKeySequence(tr("Ctrl+D")));
749 fActionDirectory.setText("Directory");
chudy@google.com902ebe52012-06-29 14:21:22 +0000750
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000751 QIcon profile;
robertphillips@google.comd1636362012-11-19 18:25:09 +0000752 profile.addFile(QString::fromUtf8(":/profile.png"), QSize(),
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000753 QIcon::Normal, QIcon::Off);
754 fActionProfile.setIcon(profile);
755 fActionProfile.setText("Profile");
robertphillips@google.come099bc42012-11-19 16:26:40 +0000756 fActionProfile.setDisabled(true);
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000757
chudy@google.comc432f002012-07-10 13:19:25 +0000758 QIcon inspector;
robertphillips@google.comd1636362012-11-19 18:25:09 +0000759 inspector.addFile(QString::fromUtf8(":/inspector.png"),
chudy@google.comc432f002012-07-10 13:19:25 +0000760 QSize(), QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000761 fActionInspector.setShortcut(QKeySequence(tr("Ctrl+I")));
chudy@google.comc432f002012-07-10 13:19:25 +0000762 fActionInspector.setIcon(inspector);
chudy@google.come504de02012-07-16 18:35:23 +0000763 fActionInspector.setText("Inspector");
chudy@google.com902ebe52012-06-29 14:21:22 +0000764
bungeman@google.com2ff6d1d2013-07-01 14:24:12 +0000765 QIcon settings;
766 settings.addFile(QString::fromUtf8(":/inspector.png"),
767 QSize(), QIcon::Normal, QIcon::Off);
768 fActionSettings.setShortcut(QKeySequence(tr("Ctrl+G")));
769 fActionSettings.setIcon(settings);
770 fActionSettings.setText("Settings");
skia.committer@gmail.com0d55dd72013-07-02 07:00:59 +0000771
chudy@google.comc432f002012-07-10 13:19:25 +0000772 QIcon play;
robertphillips@google.comd1636362012-11-19 18:25:09 +0000773 play.addFile(QString::fromUtf8(":/play.png"), QSize(),
chudy@google.comc432f002012-07-10 13:19:25 +0000774 QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000775 fActionPlay.setShortcut(QKeySequence(tr("Ctrl+P")));
chudy@google.comc432f002012-07-10 13:19:25 +0000776 fActionPlay.setIcon(play);
777 fActionPlay.setText("Play");
chudy@google.com902ebe52012-06-29 14:21:22 +0000778
chudy@google.come504de02012-07-16 18:35:23 +0000779 QIcon pause;
robertphillips@google.comd1636362012-11-19 18:25:09 +0000780 pause.addFile(QString::fromUtf8(":/pause.png"), QSize(),
chudy@google.comc432f002012-07-10 13:19:25 +0000781 QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000782 fActionPause.setShortcut(QKeySequence(tr("Space")));
783 fActionPause.setCheckable(true);
784 fActionPause.setIcon(pause);
785 fActionPause.setText("Pause");
786
chudy@google.comc432f002012-07-10 13:19:25 +0000787 QIcon rewind;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000788 rewind.addFile(QString::fromUtf8(":/rewind.png"), QSize(),
chudy@google.comc432f002012-07-10 13:19:25 +0000789 QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000790 fActionRewind.setShortcut(QKeySequence(tr("Ctrl+R")));
chudy@google.comc432f002012-07-10 13:19:25 +0000791 fActionRewind.setIcon(rewind);
792 fActionRewind.setText("Rewind");
chudy@google.com902ebe52012-06-29 14:21:22 +0000793
chudy@google.com0ab03392012-07-28 20:16:11 +0000794 fActionSave.setShortcut(QKeySequence::Save);
795 fActionSave.setText("Save");
796 fActionSave.setDisabled(true);
797 fActionSaveAs.setShortcut(QKeySequence::SaveAs);
798 fActionSaveAs.setText("Save As");
799 fActionSaveAs.setDisabled(true);
800
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000801 fActionShowDeletes.setShortcut(QKeySequence(tr("Ctrl+X")));
802 fActionShowDeletes.setText("Deleted Commands");
803
chudy@google.comc432f002012-07-10 13:19:25 +0000804 QIcon stepBack;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000805 stepBack.addFile(QString::fromUtf8(":/previous.png"), QSize(),
chudy@google.comc432f002012-07-10 13:19:25 +0000806 QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000807 fActionStepBack.setShortcut(QKeySequence(tr("[")));
chudy@google.comc432f002012-07-10 13:19:25 +0000808 fActionStepBack.setIcon(stepBack);
809 fActionStepBack.setText("Step Back");
chudy@google.com902ebe52012-06-29 14:21:22 +0000810
chudy@google.comc432f002012-07-10 13:19:25 +0000811 QIcon stepForward;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000812 stepForward.addFile(QString::fromUtf8(":/next.png"),
chudy@google.comc432f002012-07-10 13:19:25 +0000813 QSize(), QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000814 fActionStepForward.setShortcut(QKeySequence(tr("]")));
chudy@google.comc432f002012-07-10 13:19:25 +0000815 fActionStepForward.setIcon(stepForward);
816 fActionStepForward.setText("Step Forward");
817
chudy@google.coma1226312012-07-26 20:26:44 +0000818 fActionZoomIn.setShortcut(QKeySequence(tr("Ctrl+=")));
819 fActionZoomIn.setText("Zoom In");
820 fActionZoomOut.setShortcut(QKeySequence(tr("Ctrl+-")));
821 fActionZoomOut.setText("Zoom Out");
822
chudy@google.comc432f002012-07-10 13:19:25 +0000823 fListWidget.setItemDelegate(new SkListWidget(&fListWidget));
824 fListWidget.setObjectName(QString::fromUtf8("listWidget"));
commit-bot@chromium.orgbcd431e2013-11-21 13:41:37 +0000825 fListWidget.setMinimumWidth(250);
chudy@google.comc432f002012-07-10 13:19:25 +0000826
827 fFilter.addItem("--Filter By Available Commands--");
828
commit-bot@chromium.orgbcd431e2013-11-21 13:41:37 +0000829 fDirectoryWidget.setMinimumWidth(250);
chudy@google.comc432f002012-07-10 13:19:25 +0000830 fDirectoryWidget.setStyleSheet("QListWidget::Item {padding: 5px;}");
831
832 fCanvasWidget.setSizePolicy(QSizePolicy::Expanding,
chudy@google.com7dcae672012-07-09 20:26:53 +0000833 QSizePolicy::Expanding);
chudy@google.com902ebe52012-06-29 14:21:22 +0000834
skia.committer@gmail.com1c9c0d32012-11-22 02:02:41 +0000835 fImageWidget.setFixedSize(SkImageWidget::kImageWidgetWidth,
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000836 SkImageWidget::kImageWidgetHeight);
837
chudy@google.comc432f002012-07-10 13:19:25 +0000838 fInspectorWidget.setSizePolicy(QSizePolicy::Expanding,
chudy@google.com7dcae672012-07-09 20:26:53 +0000839 QSizePolicy::Expanding);
chudy@google.comc432f002012-07-10 13:19:25 +0000840 fInspectorWidget.setMaximumHeight(300);
chudy@google.com902ebe52012-06-29 14:21:22 +0000841
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000842 fSettingsAndImageLayout.setSpacing(6);
843 fSettingsAndImageLayout.addWidget(&fSettingsWidget);
844 fSettingsAndImageLayout.addWidget(&fImageWidget);
845
chudy@google.comc432f002012-07-10 13:19:25 +0000846 fSettingsWidget.setSizePolicy(QSizePolicy::Expanding,
847 QSizePolicy::Expanding);
848 fSettingsWidget.setMaximumWidth(250);
chudy@google.com902ebe52012-06-29 14:21:22 +0000849
commit-bot@chromium.orgbcd431e2013-11-21 13:41:37 +0000850 fLeftColumnSplitter.addWidget(&fListWidget);
851 fLeftColumnSplitter.addWidget(&fDirectoryWidget);
852 fLeftColumnSplitter.setOrientation(Qt::Vertical);
chudy@google.com902ebe52012-06-29 14:21:22 +0000853
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000854 fCanvasSettingsAndImageLayout.setSpacing(6);
855 fCanvasSettingsAndImageLayout.addWidget(&fCanvasWidget);
856 fCanvasSettingsAndImageLayout.addLayout(&fSettingsAndImageLayout);
857
chudy@google.comc432f002012-07-10 13:19:25 +0000858 fMainAndRightColumnLayout.setSpacing(6);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000859 fMainAndRightColumnLayout.addLayout(&fCanvasSettingsAndImageLayout);
chudy@google.comc432f002012-07-10 13:19:25 +0000860 fMainAndRightColumnLayout.addWidget(&fInspectorWidget);
commit-bot@chromium.orgbcd431e2013-11-21 13:41:37 +0000861 fMainAndRightColumnWidget.setLayout(&fMainAndRightColumnLayout);
chudy@google.com902ebe52012-06-29 14:21:22 +0000862
commit-bot@chromium.orgbcd431e2013-11-21 13:41:37 +0000863 fCentralSplitter.addWidget(&fLeftColumnSplitter);
864 fCentralSplitter.addWidget(&fMainAndRightColumnWidget);
865 fCentralSplitter.setStretchFactor(0, 0);
866 fCentralSplitter.setStretchFactor(1, 1);
chudy@google.comc432f002012-07-10 13:19:25 +0000867
commit-bot@chromium.orgbcd431e2013-11-21 13:41:37 +0000868 SkDebuggerGUI->setCentralWidget(&fCentralSplitter);
chudy@google.comc432f002012-07-10 13:19:25 +0000869 SkDebuggerGUI->setStatusBar(&fStatusBar);
870
chudy@google.come504de02012-07-16 18:35:23 +0000871 fToolBar.setIconSize(QSize(32, 32));
chudy@google.comc432f002012-07-10 13:19:25 +0000872 fToolBar.setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
873 SkDebuggerGUI->addToolBar(Qt::TopToolBarArea, &fToolBar);
chudy@google.com902ebe52012-06-29 14:21:22 +0000874
chudy@google.com0ab03392012-07-28 20:16:11 +0000875 fSpacer.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
chudy@google.com902ebe52012-06-29 14:21:22 +0000876
chudy@google.comc432f002012-07-10 13:19:25 +0000877 fToolBar.addAction(&fActionRewind);
878 fToolBar.addAction(&fActionStepBack);
chudy@google.come504de02012-07-16 18:35:23 +0000879 fToolBar.addAction(&fActionPause);
chudy@google.comc432f002012-07-10 13:19:25 +0000880 fToolBar.addAction(&fActionStepForward);
881 fToolBar.addAction(&fActionPlay);
882 fToolBar.addSeparator();
chudy@google.come504de02012-07-16 18:35:23 +0000883 fToolBar.addAction(&fActionInspector);
bungeman@google.com2ff6d1d2013-07-01 14:24:12 +0000884 fToolBar.addAction(&fActionSettings);
chudy@google.comc432f002012-07-10 13:19:25 +0000885 fToolBar.addSeparator();
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000886 fToolBar.addAction(&fActionProfile);
887
888 fToolBar.addSeparator();
chudy@google.com0ab03392012-07-28 20:16:11 +0000889 fToolBar.addWidget(&fSpacer);
chudy@google.comc432f002012-07-10 13:19:25 +0000890 fToolBar.addWidget(&fFilter);
891 fToolBar.addAction(&fActionCancel);
chudy@google.com902ebe52012-06-29 14:21:22 +0000892
893 // TODO(chudy): Remove static call.
894 fDirectoryWidgetActive = false;
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000895 fFileName = "";
robertphillips@google.comff6e6ba2013-01-28 17:43:26 +0000896 setupDirectoryWidget("");
chudy@google.com902ebe52012-06-29 14:21:22 +0000897 fDirectoryWidgetActive = true;
898
chudy@google.com902ebe52012-06-29 14:21:22 +0000899 // Menu Bar
chudy@google.comc432f002012-07-10 13:19:25 +0000900 fMenuFile.setTitle("File");
901 fMenuFile.addAction(&fActionOpen);
chudy@google.com0ab03392012-07-28 20:16:11 +0000902 fMenuFile.addAction(&fActionSave);
903 fMenuFile.addAction(&fActionSaveAs);
chudy@google.comc432f002012-07-10 13:19:25 +0000904 fMenuFile.addAction(&fActionClose);
chudy@google.come504de02012-07-16 18:35:23 +0000905
906 fMenuEdit.setTitle("Edit");
907 fMenuEdit.addAction(&fActionDelete);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000908 fMenuEdit.addAction(&fActionClearDeletes);
909 fMenuEdit.addSeparator();
chudy@google.come504de02012-07-16 18:35:23 +0000910 fMenuEdit.addAction(&fActionCreateBreakpoint);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000911 fMenuEdit.addAction(&fActionClearBreakpoints);
chudy@google.come504de02012-07-16 18:35:23 +0000912
chudy@google.comc432f002012-07-10 13:19:25 +0000913 fMenuNavigate.setTitle("Navigate");
chudy@google.come504de02012-07-16 18:35:23 +0000914 fMenuNavigate.addAction(&fActionRewind);
915 fMenuNavigate.addAction(&fActionStepBack);
916 fMenuNavigate.addAction(&fActionStepForward);
917 fMenuNavigate.addAction(&fActionPlay);
918 fMenuNavigate.addAction(&fActionPause);
chudy@google.comc432f002012-07-10 13:19:25 +0000919 fMenuNavigate.addAction(&fActionGoToLine);
chudy@google.come504de02012-07-16 18:35:23 +0000920
chudy@google.comc432f002012-07-10 13:19:25 +0000921 fMenuView.setTitle("View");
chudy@google.come504de02012-07-16 18:35:23 +0000922 fMenuView.addAction(&fActionBreakpoint);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000923 fMenuView.addAction(&fActionShowDeletes);
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000924 fMenuView.addAction(&fActionToggleIndexStyle);
chudy@google.coma1226312012-07-26 20:26:44 +0000925 fMenuView.addAction(&fActionZoomIn);
926 fMenuView.addAction(&fActionZoomOut);
chudy@google.come504de02012-07-16 18:35:23 +0000927
928 fMenuWindows.setTitle("Window");
929 fMenuWindows.addAction(&fActionInspector);
bungeman@google.com2ff6d1d2013-07-01 14:24:12 +0000930 fMenuWindows.addAction(&fActionSettings);
chudy@google.come504de02012-07-16 18:35:23 +0000931 fMenuWindows.addAction(&fActionDirectory);
chudy@google.comc432f002012-07-10 13:19:25 +0000932
933 fActionGoToLine.setText("Go to Line...");
934 fActionGoToLine.setDisabled(true);
935 fMenuBar.addAction(fMenuFile.menuAction());
chudy@google.come504de02012-07-16 18:35:23 +0000936 fMenuBar.addAction(fMenuEdit.menuAction());
chudy@google.comc432f002012-07-10 13:19:25 +0000937 fMenuBar.addAction(fMenuView.menuAction());
938 fMenuBar.addAction(fMenuNavigate.menuAction());
chudy@google.come504de02012-07-16 18:35:23 +0000939 fMenuBar.addAction(fMenuWindows.menuAction());
chudy@google.com902ebe52012-06-29 14:21:22 +0000940
chudy@google.com7dcae672012-07-09 20:26:53 +0000941 fPause = false;
942
chudy@google.comc432f002012-07-10 13:19:25 +0000943 SkDebuggerGUI->setMenuBar(&fMenuBar);
chudy@google.com902ebe52012-06-29 14:21:22 +0000944 QMetaObject::connectSlotsByName(SkDebuggerGUI);
945}
946
robertphillips@google.comff6e6ba2013-01-28 17:43:26 +0000947void SkDebuggerGUI::setupDirectoryWidget(const QString& path) {
948 fPath = path;
949 QDir dir(path);
chudy@google.com902ebe52012-06-29 14:21:22 +0000950 QRegExp r(".skp");
chudy@google.comc432f002012-07-10 13:19:25 +0000951 fDirectoryWidget.clear();
952 const QStringList files = dir.entryList();
chudy@google.com902ebe52012-06-29 14:21:22 +0000953 foreach (QString f, files) {
chudy@google.com7dcae672012-07-09 20:26:53 +0000954 if (f.contains(r))
chudy@google.comc432f002012-07-10 13:19:25 +0000955 fDirectoryWidget.addItem(f);
chudy@google.com902ebe52012-06-29 14:21:22 +0000956 }
957}
958
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000959void SkDebuggerGUI::loadPicture(const SkString& fileName) {
960 fFileName = fileName;
chudy@google.comd3058f52012-07-19 13:41:27 +0000961 fLoading = true;
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000962 SkStream* stream = SkNEW_ARGS(SkFILEStream, (fileName.c_str()));
robertphillips@google.com2d40ec42013-02-07 20:39:40 +0000963
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000964 SkPicture* picture = SkPicture::CreateFromStream(stream);
robertphillips@google.com2d40ec42013-02-07 20:39:40 +0000965
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000966 if (NULL == picture) {
robertphillips@google.com2d40ec42013-02-07 20:39:40 +0000967 QMessageBox::critical(this, "Error loading file", "Couldn't read file, sorry.");
968 SkSafeUnref(stream);
969 return;
970 }
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000971
chudy@google.com686e6802012-08-14 16:00:32 +0000972 fCanvasWidget.resetWidgetTransform();
chudy@google.com607357f2012-08-07 16:12:23 +0000973 fDebugger.loadPicture(picture);
chudy@google.com4c7962e2012-08-14 19:38:31 +0000974
robertphillips@google.com6d9c92b2013-05-23 13:21:18 +0000975 fSkipCommands.setCount(fDebugger.getSize());
976 for (int i = 0; i < fSkipCommands.count(); ++i) {
robertphillips@google.com5f971142012-12-07 20:48:56 +0000977 fSkipCommands[i] = false;
978 }
979
chudy@google.com607357f2012-08-07 16:12:23 +0000980 SkSafeUnref(stream);
981 SkSafeUnref(picture);
982
chudy@google.com97cee972012-08-07 20:41:37 +0000983 // Will this automatically clear out due to nature of refcnt?
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000984 SkTArray<SkString>* commands = fDebugger.getDrawCommandsAsStrings();
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000985 SkTDArray<size_t>* offsets = fDebugger.getDrawCommandOffsets();
986 SkASSERT(commands->count() == offsets->count());
chudy@google.com607357f2012-08-07 16:12:23 +0000987
robertphillips@google.com6d9c92b2013-05-23 13:21:18 +0000988 fActionProfile.setDisabled(false);
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000989
chudy@google.com7dcae672012-07-09 20:26:53 +0000990 /* fDebugCanvas is reinitialized every load picture. Need it to retain value
chudy@google.com607357f2012-08-07 16:12:23 +0000991 * of the visibility filter.
992 * TODO(chudy): This should be deprecated since fDebugger is not
993 * recreated.
994 * */
commit-bot@chromium.org22d39332013-11-21 15:37:29 +0000995 fDebugger.highlightCurrentCommand(fSettingsWidget.getVisibilityFilter());
chudy@google.com607357f2012-08-07 16:12:23 +0000996
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000997 this->setupListWidget(commands, offsets);
998 this->setupComboBox(commands);
999 this->setupOverviewText(NULL, 0.0, 1);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +00001000 fInspectorWidget.setDisabled(false);
chudy@google.come606d6e2012-07-12 14:31:25 +00001001 fSettingsWidget.setDisabled(false);
chudy@google.comd3058f52012-07-19 13:41:27 +00001002 fMenuEdit.setDisabled(false);
1003 fMenuNavigate.setDisabled(false);
1004 fMenuView.setDisabled(false);
chudy@google.com0ab03392012-07-28 20:16:11 +00001005 fActionSave.setDisabled(false);
1006 fActionSaveAs.setDisabled(false);
chudy@google.comd3058f52012-07-19 13:41:27 +00001007 fLoading = false;
1008 actionPlay();
chudy@google.com902ebe52012-06-29 14:21:22 +00001009}
1010
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +00001011void SkDebuggerGUI::setupListWidget(SkTArray<SkString>* commands, SkTDArray<size_t>* offsets) {
1012 SkASSERT(commands->count() == offsets->count());
chudy@google.comc432f002012-07-10 13:19:25 +00001013 fListWidget.clear();
chudy@google.com902ebe52012-06-29 14:21:22 +00001014 int counter = 0;
robertphillips@google.com30d35f22012-11-06 16:45:36 +00001015 int indent = 0;
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +00001016 for (int i = 0; i < commands->count(); i++) {
chudy@google.com902ebe52012-06-29 14:21:22 +00001017 QListWidgetItem *item = new QListWidgetItem();
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +00001018 item->setData(Qt::DisplayRole, (*commands)[i].c_str());
chudy@google.com902ebe52012-06-29 14:21:22 +00001019 item->setData(Qt::UserRole + 1, counter++);
robertphillips@google.com30d35f22012-11-06 16:45:36 +00001020
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +00001021 if (0 == strcmp("Restore", (*commands)[i].c_str()) ||
1022 0 == strcmp("EndCommentGroup", (*commands)[i].c_str()) ||
1023 0 == strcmp("PopCull", (*commands)[i].c_str())) {
robertphillips@google.com30d35f22012-11-06 16:45:36 +00001024 indent -= 10;
1025 }
1026
1027 item->setData(Qt::UserRole + 3, indent);
1028
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +00001029 if (0 == strcmp("Save", (*commands)[i].c_str()) ||
1030 0 == strcmp("Save Layer", (*commands)[i].c_str()) ||
1031 0 == strcmp("BeginCommentGroup", (*commands)[i].c_str()) ||
1032 0 == strcmp("PushCull", (*commands)[i].c_str())) {
robertphillips@google.com30d35f22012-11-06 16:45:36 +00001033 indent += 10;
1034 }
1035
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +00001036 item->setData(Qt::UserRole + 4, -1);
1037 item->setData(Qt::UserRole + 5, (int)(*offsets)[i]);
robertphillips@google.comd26c7062012-11-12 20:42:12 +00001038
chudy@google.comc432f002012-07-10 13:19:25 +00001039 fListWidget.addItem(item);
chudy@google.com902ebe52012-06-29 14:21:22 +00001040 }
1041}
1042
skia.committer@gmail.com91274b92013-03-13 07:01:04 +00001043void SkDebuggerGUI::setupOverviewText(const SkTDArray<double>* typeTimes,
robertphillips@google.come428f9b2013-03-12 15:33:40 +00001044 double totTime,
1045 int numRuns) {
borenet@google.com2d9dbd42013-03-12 13:07:40 +00001046 SkString overview;
robertphillips@google.come428f9b2013-03-12 15:33:40 +00001047 fDebugger.getOverviewText(typeTimes, totTime, &overview, numRuns);
borenet@google.com2d9dbd42013-03-12 13:07:40 +00001048 fInspectorWidget.setText(overview.c_str(), SkInspectorWidget::kOverview_TabType);
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +00001049}
1050
commit-bot@chromium.org2a67e122014-05-19 13:53:10 +00001051void SkDebuggerGUI::setupClipStackText() {
1052 SkString clipStack;
1053 fDebugger.getClipStackText(&clipStack);
1054 fInspectorWidget.setText(clipStack.c_str(), SkInspectorWidget::kClipStack_TabType);
1055}
1056
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +00001057void SkDebuggerGUI::setupComboBox(SkTArray<SkString>* command) {
1058 fFilter.clear();
1059 fFilter.addItem("--Filter By Available Commands--");
1060
1061 std::map<std::string, int> map;
1062 for (int i = 0; i < command->count(); i++) {
1063 map[(*command)[i].c_str()]++;
1064 }
1065
skia.committer@gmail.com34587162012-11-20 02:01:23 +00001066 for (std::map<std::string, int>::iterator it = map.begin(); it != map.end();
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +00001067 ++it) {
1068 fFilter.addItem((it->first).c_str());
1069 }
chudy@google.com902ebe52012-06-29 14:21:22 +00001070
1071 // NOTE(chudy): Makes first item unselectable.
chudy@google.com7dcae672012-07-09 20:26:53 +00001072 QStandardItemModel* model = qobject_cast<QStandardItemModel*>(
chudy@google.comc432f002012-07-10 13:19:25 +00001073 fFilter.model());
1074 QModelIndex firstIndex = model->index(0, fFilter.modelColumn(),
1075 fFilter.rootModelIndex());
chudy@google.com902ebe52012-06-29 14:21:22 +00001076 QStandardItem* firstItem = model->itemFromIndex(firstIndex);
1077 firstItem->setSelectable(false);
1078}