blob: 05725500ff27078ab415f3fcebe58d466216e8f0 [file] [log] [blame]
chudy@google.com902ebe52012-06-29 14:21:22 +00001/*
2 * Copyright 2012 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
chudy@google.com902ebe52012-06-29 14:21:22 +00008#include "SkDebuggerGUI.h"
scroggo@google.com7def5e12013-05-31 14:00:10 +00009#include "SkForceLinking.h"
chudy@google.combbad34d2012-08-13 14:26:36 +000010#include "SkGraphics.h"
scroggo@google.comb4467e62012-11-06 23:10:09 +000011#include "SkImageDecoder.h"
chudy@google.com902ebe52012-06-29 14:21:22 +000012#include <QListWidgetItem>
robertphillips@google.com2bde91d2012-11-15 14:57:57 +000013#include "PictureRenderer.h"
robertphillips@google.com2bde91d2012-11-15 14:57:57 +000014#include "SkPictureRecord.h"
15#include "SkPicturePlayback.h"
robertphillips@google.come174a8b2012-11-27 16:04:42 +000016
scroggo@google.com7def5e12013-05-31 14:00:10 +000017__SK_FORCE_IMAGE_DECODER_LINKING;
18
robertphillips@google.come174a8b2012-11-27 16:04:42 +000019#if defined(SK_BUILD_FOR_WIN32)
20 #include "BenchSysTimer_windows.h"
21#elif defined(SK_BUILD_FOR_MAC)
22 #include "BenchSysTimer_mach.h"
23#elif defined(SK_BUILD_FOR_UNIX) || defined(SK_BUILD_FOR_ANDROID)
24 #include "BenchSysTimer_posix.h"
25#else
26 #include "BenchSysTimer_c.h"
27#endif
28
chudy@google.com902ebe52012-06-29 14:21:22 +000029
30SkDebuggerGUI::SkDebuggerGUI(QWidget *parent) :
chudy@google.comc432f002012-07-10 13:19:25 +000031 QMainWindow(parent)
commit-bot@chromium.orgbcd431e2013-11-21 13:41:37 +000032 , fCentralSplitter(this)
chudy@google.com2d537a12012-07-31 12:49:52 +000033 , fStatusBar(this)
34 , fToolBar(this)
chudy@google.comc432f002012-07-10 13:19:25 +000035 , fActionOpen(this)
36 , fActionBreakpoint(this)
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +000037 , fActionToggleIndexStyle(this)
robertphillips@google.comd26c7062012-11-12 20:42:12 +000038 , fActionProfile(this)
chudy@google.comc432f002012-07-10 13:19:25 +000039 , fActionCancel(this)
chudy@google.com7e4cfbf2012-07-17 15:40:51 +000040 , fActionClearBreakpoints(this)
chudy@google.come504de02012-07-16 18:35:23 +000041 , fActionClearDeletes(this)
chudy@google.comc432f002012-07-10 13:19:25 +000042 , fActionClose(this)
chudy@google.come504de02012-07-16 18:35:23 +000043 , fActionCreateBreakpoint(this)
chudy@google.comc432f002012-07-10 13:19:25 +000044 , fActionDelete(this)
45 , fActionDirectory(this)
46 , fActionGoToLine(this)
47 , fActionInspector(this)
bungeman@google.com2ff6d1d2013-07-01 14:24:12 +000048 , fActionSettings(this)
chudy@google.comc432f002012-07-10 13:19:25 +000049 , fActionPlay(this)
chudy@google.come504de02012-07-16 18:35:23 +000050 , fActionPause(this)
chudy@google.comc432f002012-07-10 13:19:25 +000051 , fActionRewind(this)
chudy@google.com0ab03392012-07-28 20:16:11 +000052 , fActionSave(this)
53 , fActionSaveAs(this)
chudy@google.com7e4cfbf2012-07-17 15:40:51 +000054 , fActionShowDeletes(this)
chudy@google.comc432f002012-07-10 13:19:25 +000055 , fActionStepBack(this)
56 , fActionStepForward(this)
chudy@google.coma1226312012-07-26 20:26:44 +000057 , fActionZoomIn(this)
58 , fActionZoomOut(this)
59 , fMapper(this)
commit-bot@chromium.orgbcd431e2013-11-21 13:41:37 +000060 , fListWidget(&fCentralSplitter)
61 , fDirectoryWidget(&fCentralSplitter)
chudy@google.com607357f2012-08-07 16:12:23 +000062 , fCanvasWidget(this, &fDebugger)
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +000063 , fImageWidget(&fDebugger)
chudy@google.comc432f002012-07-10 13:19:25 +000064 , fMenuBar(this)
65 , fMenuFile(this)
66 , fMenuNavigate(this)
67 , fMenuView(this)
chudy@google.com7e4cfbf2012-07-17 15:40:51 +000068 , fBreakpointsActivated(false)
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +000069 , fIndexStyleToggle(false)
chudy@google.com7e4cfbf2012-07-17 15:40:51 +000070 , fDeletesActivated(false)
71 , fPause(false)
chudy@google.comd3058f52012-07-19 13:41:27 +000072 , fLoading(false)
chudy@google.comc432f002012-07-10 13:19:25 +000073{
chudy@google.com902ebe52012-06-29 14:21:22 +000074 setupUi(this);
robertphillips@google.comdd4b7452013-01-22 19:38:46 +000075 fListWidget.setSelectionMode(QAbstractItemView::ExtendedSelection);
chudy@google.comea5488b2012-07-26 19:38:22 +000076 connect(&fListWidget, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)), this, SLOT(registerListClick(QListWidgetItem *)));
chudy@google.comc432f002012-07-10 13:19:25 +000077 connect(&fActionOpen, SIGNAL(triggered()), this, SLOT(openFile()));
chudy@google.comea5488b2012-07-26 19:38:22 +000078 connect(&fActionDirectory, SIGNAL(triggered()), this, SLOT(toggleDirectory()));
79 connect(&fDirectoryWidget, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)), this, SLOT(loadFile(QListWidgetItem *)));
chudy@google.comc432f002012-07-10 13:19:25 +000080 connect(&fActionDelete, SIGNAL(triggered()), this, SLOT(actionDelete()));
chudy@google.comea5488b2012-07-26 19:38:22 +000081 connect(&fListWidget, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(toggleBreakpoint()));
chudy@google.comc432f002012-07-10 13:19:25 +000082 connect(&fActionRewind, SIGNAL(triggered()), this, SLOT(actionRewind()));
83 connect(&fActionPlay, SIGNAL(triggered()), this, SLOT(actionPlay()));
84 connect(&fActionStepBack, SIGNAL(triggered()), this, SLOT(actionStepBack()));
chudy@google.comea5488b2012-07-26 19:38:22 +000085 connect(&fActionStepForward, SIGNAL(triggered()), this, SLOT(actionStepForward()));
86 connect(&fActionBreakpoint, SIGNAL(triggered()), this, SLOT(actionBreakpoints()));
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +000087 connect(&fActionToggleIndexStyle, SIGNAL(triggered()), this, SLOT(actionToggleIndexStyle()));
chudy@google.comea5488b2012-07-26 19:38:22 +000088 connect(&fActionInspector, SIGNAL(triggered()), this, SLOT(actionInspector()));
bungeman@google.com2ff6d1d2013-07-01 14:24:12 +000089 connect(&fActionSettings, SIGNAL(triggered()), this, SLOT(actionSettings()));
chudy@google.comea5488b2012-07-26 19:38:22 +000090 connect(&fFilter, SIGNAL(activated(QString)), this, SLOT(toggleFilter(QString)));
robertphillips@google.comd26c7062012-11-12 20:42:12 +000091 connect(&fActionProfile, SIGNAL(triggered()), this, SLOT(actionProfile()));
chudy@google.comc432f002012-07-10 13:19:25 +000092 connect(&fActionCancel, SIGNAL(triggered()), this, SLOT(actionCancel()));
chudy@google.com7e4cfbf2012-07-17 15:40:51 +000093 connect(&fActionClearBreakpoints, SIGNAL(triggered()), this, SLOT(actionClearBreakpoints()));
94 connect(&fActionClearDeletes, SIGNAL(triggered()), this, SLOT(actionClearDeletes()));
chudy@google.comc432f002012-07-10 13:19:25 +000095 connect(&fActionClose, SIGNAL(triggered()), this, SLOT(actionClose()));
commit-bot@chromium.org22d39332013-11-21 15:37:29 +000096 connect(&fSettingsWidget, SIGNAL(visibilityFilterChanged()), this, SLOT(actionCommandFilter()));
robertphillips@google.come8fe4bc2013-02-13 13:26:13 +000097#if SK_SUPPORT_GPU
commit-bot@chromium.orgfde1e7c2013-08-02 13:59:50 +000098 connect(&fSettingsWidget, SIGNAL(glSettingsChanged()), this, SLOT(actionGLWidget()));
robertphillips@google.come8fe4bc2013-02-13 13:26:13 +000099#endif
robertphillips@google.com32bbcf82013-10-17 17:56:10 +0000100 connect(&fSettingsWidget, SIGNAL(texFilterSettingsChanged()), this, SLOT(actionTextureFilter()));
chudy@google.comea5488b2012-07-26 19:38:22 +0000101 connect(fSettingsWidget.getRasterCheckBox(), SIGNAL(toggled(bool)), this, SLOT(actionRasterWidget(bool)));
robertphillips@google.comf4741c12013-02-06 20:13:54 +0000102 connect(fSettingsWidget.getOverdrawVizCheckBox(), SIGNAL(toggled(bool)), this, SLOT(actionOverdrawVizWidget(bool)));
commit-bot@chromium.org768ac852014-03-03 16:32:17 +0000103 connect(fSettingsWidget.getMegaVizCheckBox(), SIGNAL(toggled(bool)), this, SLOT(actionMegaVizWidget(bool)));
chudy@google.comea5488b2012-07-26 19:38:22 +0000104 connect(&fActionPause, SIGNAL(toggled(bool)), this, SLOT(pauseDrawing(bool)));
chudy@google.come504de02012-07-16 18:35:23 +0000105 connect(&fActionCreateBreakpoint, SIGNAL(activated()), this, SLOT(toggleBreakpoint()));
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000106 connect(&fActionShowDeletes, SIGNAL(triggered()), this, SLOT(showDeletes()));
chudy@google.comea5488b2012-07-26 19:38:22 +0000107 connect(&fCanvasWidget, SIGNAL(hitChanged(int)), this, SLOT(selectCommand(int)));
108 connect(&fCanvasWidget, SIGNAL(hitChanged(int)), &fSettingsWidget, SLOT(updateHit(int)));
109 connect(&fCanvasWidget, SIGNAL(scaleFactorChanged(float)), this, SLOT(actionScale(float)));
110 connect(&fCanvasWidget, SIGNAL(commandChanged(int)), &fSettingsWidget, SLOT(updateCommand(int)));
chudy@google.com0ab03392012-07-28 20:16:11 +0000111 connect(&fActionSaveAs, SIGNAL(triggered()), this, SLOT(actionSaveAs()));
112 connect(&fActionSave, SIGNAL(triggered()), this, SLOT(actionSave()));
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000113
bungeman@google.come8cc6e82013-01-17 16:30:56 +0000114 fMapper.setMapping(&fActionZoomIn, SkCanvasWidget::kIn_ZoomCommand);
115 fMapper.setMapping(&fActionZoomOut, SkCanvasWidget::kOut_ZoomCommand);
chudy@google.coma1226312012-07-26 20:26:44 +0000116
117 connect(&fActionZoomIn, SIGNAL(triggered()), &fMapper, SLOT(map()));
118 connect(&fActionZoomOut, SIGNAL(triggered()), &fMapper, SLOT(map()));
bungeman@google.come8cc6e82013-01-17 16:30:56 +0000119 connect(&fMapper, SIGNAL(mapped(int)), &fCanvasWidget, SLOT(zoom(int)));
chudy@google.coma1226312012-07-26 20:26:44 +0000120
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000121 fInspectorWidget.setDisabled(true);
chudy@google.comd3058f52012-07-19 13:41:27 +0000122 fMenuEdit.setDisabled(true);
123 fMenuNavigate.setDisabled(true);
124 fMenuView.setDisabled(true);
chudy@google.combbad34d2012-08-13 14:26:36 +0000125
126 SkGraphics::Init();
chudy@google.com902ebe52012-06-29 14:21:22 +0000127}
128
chudy@google.combbad34d2012-08-13 14:26:36 +0000129SkDebuggerGUI::~SkDebuggerGUI() {
130 SkGraphics::Term();
131}
chudy@google.com902ebe52012-06-29 14:21:22 +0000132
133void SkDebuggerGUI::actionBreakpoints() {
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000134 fBreakpointsActivated = !fBreakpointsActivated;
chudy@google.comc432f002012-07-10 13:19:25 +0000135 for (int row = 0; row < fListWidget.count(); row++) {
136 QListWidgetItem *item = fListWidget.item(row);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000137 item->setHidden(item->checkState() == Qt::Unchecked && fBreakpointsActivated);
138 }
139}
chudy@google.com902ebe52012-06-29 14:21:22 +0000140
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000141void SkDebuggerGUI::actionToggleIndexStyle() {
142 fIndexStyleToggle = !fIndexStyleToggle;
143 SkListWidget* list = (SkListWidget*) fListWidget.itemDelegate();
skia.committer@gmail.comdb35dab2014-03-27 03:02:48 +0000144 list->setIndexStyle(fIndexStyleToggle ? SkListWidget::kIndex_IndexStyle :
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000145 SkListWidget::kOffset_IndexStyle);
146 fListWidget.update();
147}
148
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000149void SkDebuggerGUI::showDeletes() {
150 fDeletesActivated = !fDeletesActivated;
151 for (int row = 0; row < fListWidget.count(); row++) {
152 QListWidgetItem *item = fListWidget.item(row);
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000153 item->setHidden(fDebugger.isCommandVisible(row) && fDeletesActivated);
chudy@google.com902ebe52012-06-29 14:21:22 +0000154 }
155}
156
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000157// The timed picture playback uses the SkPicturePlayback's profiling stubs
158// to time individual commands. The offsets are needed to map SkPicture
159// offsets to individual commands.
160class SkTimedPicturePlayback : public SkPicturePlayback {
161public:
scroggo@google.com12705322013-10-01 15:30:46 +0000162 static SkTimedPicturePlayback* CreateFromStream(SkStream* stream, const SkPictInfo& info,
163 SkPicture::InstallPixelRefProc proc,
164 const SkTDArray<bool>& deletedCommands) {
165 // Mimics SkPicturePlayback::CreateFromStream
166 SkAutoTDelete<SkTimedPicturePlayback> playback(SkNEW_ARGS(SkTimedPicturePlayback,
commit-bot@chromium.org0943f5f2014-03-28 18:05:47 +0000167 (deletedCommands, info)));
168 if (!playback->parseStream(stream, proc)) {
scroggo@google.com12705322013-10-01 15:30:46 +0000169 return NULL; // we're invalid
170 }
171 return playback.detach();
172 }
173
commit-bot@chromium.org0943f5f2014-03-28 18:05:47 +0000174 SkTimedPicturePlayback(const SkTDArray<bool>& deletedCommands, const SkPictInfo& info)
175 : INHERITED(info)
bungeman@google.come8cc6e82013-01-17 16:30:56 +0000176 , fSkipCommands(deletedCommands)
177 , fTot(0.0)
178 , fCurCommand(0) {
robertphillips@google.com6d9c92b2013-05-23 13:21:18 +0000179 fTimes.setCount(deletedCommands.count());
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000180 fTypeTimes.setCount(LAST_DRAWTYPE_ENUM+1);
181 this->resetTimes();
182 }
183
184 void resetTimes() {
robertphillips@google.com6d9c92b2013-05-23 13:21:18 +0000185 for (int i = 0; i < fTimes.count(); ++i) {
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000186 fTimes[i] = 0.0;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000187 }
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000188 for (int i = 0; i < fTypeTimes.count(); ++i) {
189 fTypeTimes[i] = 0.0f;
190 }
191 fTot = 0.0;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000192 }
193
194 int count() const { return fTimes.count(); }
195
196 double time(int index) const { return fTimes[index] / fTot; }
197
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000198 const SkTDArray<double>* typeTimes() const { return &fTypeTimes; }
199
200 double totTime() const { return fTot; }
201
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000202protected:
robertphillips@google.come174a8b2012-11-27 16:04:42 +0000203 BenchSysTimer fTimer;
robertphillips@google.com5f971142012-12-07 20:48:56 +0000204 SkTDArray<bool> fSkipCommands; // has the command been deleted in the GUI?
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000205 SkTDArray<double> fTimes; // sum of time consumed for each command
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000206 SkTDArray<double> fTypeTimes; // sum of time consumed for each type of command (e.g., drawPath)
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000207 double fTot; // total of all times in 'fTimes'
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000208 int fCurType;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000209 int fCurCommand; // the current command being executed/timed
210
robertphillips@google.com6d9c92b2013-05-23 13:21:18 +0000211#ifdef SK_DEVELOPER
212 virtual bool preDraw(int opIndex, int type) SK_OVERRIDE {
213 fCurCommand = opIndex;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000214
robertphillips@google.com5f971142012-12-07 20:48:56 +0000215 if (fSkipCommands[fCurCommand]) {
robertphillips@google.com6d9c92b2013-05-23 13:21:18 +0000216 return true;
robertphillips@google.com5f971142012-12-07 20:48:56 +0000217 }
218
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000219 fCurType = type;
220 // The SkDebugCanvas doesn't recognize these types. This class needs to
221 // convert or else we'll wind up with a mismatch between the type counts
222 // the debugger displays and the profile times.
223 if (DRAW_POS_TEXT_TOP_BOTTOM == type) {
224 fCurType = DRAW_POS_TEXT;
225 } else if (DRAW_POS_TEXT_H_TOP_BOTTOM == type) {
226 fCurType = DRAW_POS_TEXT_H;
227 }
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000228
robertphillips@google.come174a8b2012-11-27 16:04:42 +0000229#if defined(SK_BUILD_FOR_WIN32)
230 // CPU timer doesn't work well on Windows
231 fTimer.startWall();
232#else
233 fTimer.startCpu();
234#endif
robertphillips@google.com5f971142012-12-07 20:48:56 +0000235
robertphillips@google.com6d9c92b2013-05-23 13:21:18 +0000236 return false;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000237 }
238
robertphillips@google.com6d9c92b2013-05-23 13:21:18 +0000239 virtual void postDraw(int opIndex) SK_OVERRIDE {
robertphillips@google.come174a8b2012-11-27 16:04:42 +0000240#if defined(SK_BUILD_FOR_WIN32)
241 // CPU timer doesn't work well on Windows
242 double time = fTimer.endWall();
243#else
244 double time = fTimer.endCpu();
245#endif
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000246
robertphillips@google.com6d9c92b2013-05-23 13:21:18 +0000247 SkASSERT(opIndex == fCurCommand);
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000248 SkASSERT(fCurType <= LAST_DRAWTYPE_ENUM);
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000249
robertphillips@google.come174a8b2012-11-27 16:04:42 +0000250 fTimes[fCurCommand] += time;
251 fTypeTimes[fCurType] += time;
252 fTot += time;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000253 }
robertphillips@google.com6d9c92b2013-05-23 13:21:18 +0000254#endif
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000255
256private:
257 typedef SkPicturePlayback INHERITED;
258};
259
260// Wrap SkPicture to allow installation of an SkTimedPicturePlayback object
261class SkTimedPicture : public SkPicture {
262public:
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000263 static SkTimedPicture* CreateTimedPicture(SkStream* stream,
264 SkPicture::InstallPixelRefProc proc,
265 const SkTDArray<bool>& deletedCommands) {
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000266 SkPictInfo info;
commit-bot@chromium.org6f4fb0f2014-03-03 19:18:39 +0000267 if (!InternalOnly_StreamIsSKP(stream, &info)) {
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000268 return NULL;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000269 }
270
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000271 SkTimedPicturePlayback* playback;
272 // Check to see if there is a playback to recreate.
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000273 if (stream->readBool()) {
scroggo@google.com12705322013-10-01 15:30:46 +0000274 playback = SkTimedPicturePlayback::CreateFromStream(stream, info, proc,
275 deletedCommands);
276 if (NULL == playback) {
277 return NULL;
278 }
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000279 } else {
280 playback = NULL;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000281 }
282
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000283 return SkNEW_ARGS(SkTimedPicture, (playback, info.fWidth, info.fHeight));
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000284 }
285
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000286 void resetTimes() { ((SkTimedPicturePlayback*) fPlayback)->resetTimes(); }
287
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000288 int count() const { return ((SkTimedPicturePlayback*) fPlayback)->count(); }
289
290 // return the fraction of the total time this command consumed
291 double time(int index) const { return ((SkTimedPicturePlayback*) fPlayback)->time(index); }
292
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000293 const SkTDArray<double>* typeTimes() const { return ((SkTimedPicturePlayback*) fPlayback)->typeTimes(); }
294
295 double totTime() const { return ((SkTimedPicturePlayback*) fPlayback)->totTime(); }
296
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000297private:
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000298 // disallow default ctor b.c. we don't have a good way to setup the fPlayback ptr
299 SkTimedPicture();
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000300 // Private ctor only used by CreateTimedPicture, which has created the playback.
301 SkTimedPicture(SkTimedPicturePlayback* playback, int width, int height)
302 : INHERITED(playback, width, height) {}
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000303 // disallow the copy ctor - enabling would require copying code from SkPicture
304 SkTimedPicture(const SkTimedPicture& src);
305
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000306 typedef SkPicture INHERITED;
307};
308
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000309// This is a simplification of PictureBenchmark's run with the addition of
310// clearing of the times after the first pass (in resetTimes)
skia.committer@gmail.com34587162012-11-20 02:01:23 +0000311void SkDebuggerGUI::run(SkTimedPicture* pict,
312 sk_tools::PictureRenderer* renderer,
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000313 int repeats) {
314 SkASSERT(pict);
315 if (NULL == pict) {
316 return;
317 }
318
319 SkASSERT(renderer != NULL);
320 if (NULL == renderer) {
321 return;
322 }
323
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000324 renderer->init(pict, NULL, NULL, false);
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000325
326 renderer->setup();
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000327 renderer->render();
commit-bot@chromium.org51c040e2014-03-11 22:58:00 +0000328 renderer->resetState(true); // flush, swapBuffers and Finish
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000329
330 // We throw this away the first batch of times to remove first time effects (such as paging in this program)
331 pict->resetTimes();
332
333 for (int i = 0; i < repeats; ++i) {
334 renderer->setup();
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000335 renderer->render();
commit-bot@chromium.org51c040e2014-03-11 22:58:00 +0000336 renderer->resetState(false); // flush & swapBuffers, but don't Finish
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000337 }
commit-bot@chromium.org51c040e2014-03-11 22:58:00 +0000338 renderer->resetState(true); // flush, swapBuffers and Finish
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000339
340 renderer->end();
341}
342
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000343void SkDebuggerGUI::actionProfile() {
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000344 // In order to profile we pass the command offsets (that were read-in
345 // in loadPicture by the SkOffsetPicture) to an SkTimedPlaybackPicture.
skia.committer@gmail.com884e60b2012-11-16 02:01:17 +0000346 // The SkTimedPlaybackPicture in turn passes the offsets to an
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000347 // SkTimedPicturePlayback object which uses them to track the performance
348 // of individual commands.
349 if (fFileName.isEmpty()) {
350 return;
351 }
352
353 SkFILEStream inputStream;
354
355 inputStream.setPath(fFileName.c_str());
356 if (!inputStream.isValid()) {
357 return;
358 }
359
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000360 SkAutoTUnref<SkTimedPicture> picture(SkTimedPicture::CreateTimedPicture(&inputStream,
361 &SkImageDecoder::DecodeMemory, fSkipCommands));
362 if (NULL == picture.get()) {
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000363 return;
364 }
365
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000366 // For now this #if allows switching between tiled and simple rendering
367 // modes. Eventually this will be accomplished via the GUI
robertphillips@google.come174a8b2012-11-27 16:04:42 +0000368#if 0
369 // With the current batch of SysTimers, profiling in tiled mode
370 // gets swamped by the timing overhead:
371 //
372 // tile mode simple mode
373 // debugger 64.2ms 12.8ms
374 // bench_pictures 16.9ms 12.4ms
375 //
376 // This is b.c. in tiled mode each command is called many more times
377 // but typically does less work on each invocation (due to clipping)
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000378 sk_tools::TiledPictureRenderer* renderer = NULL;
379
380 renderer = SkNEW(sk_tools::TiledPictureRenderer);
381 renderer->setTileWidth(256);
382 renderer->setTileHeight(256);
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000383#else
384 sk_tools::SimplePictureRenderer* renderer = NULL;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000385
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000386 renderer = SkNEW(sk_tools::SimplePictureRenderer);
robertphillips@google.com1447aa32013-01-30 21:09:09 +0000387
388#if SK_SUPPORT_GPU
commit-bot@chromium.orgfde1e7c2013-08-02 13:59:50 +0000389 if (fSettingsWidget.isGLActive()) {
robertphillips@google.com1447aa32013-01-30 21:09:09 +0000390 renderer->setDeviceType(sk_tools::PictureRenderer::kGPU_DeviceType);
commit-bot@chromium.orgfde1e7c2013-08-02 13:59:50 +0000391 renderer->setSampleCount(fSettingsWidget.getGLSampleCount());
robertphillips@google.com1447aa32013-01-30 21:09:09 +0000392 }
393#endif
394
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000395#endif
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000396
robertphillips@google.come174a8b2012-11-27 16:04:42 +0000397 static const int kNumRepeats = 10;
398
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000399 run(picture.get(), renderer, kNumRepeats);
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000400
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000401 SkASSERT(picture->count() == fListWidget.count());
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000402
403 // extract the individual command times from the SkTimedPlaybackPicture
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000404 for (int i = 0; i < picture->count(); ++i) {
405 double temp = picture->time(i);
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000406
407 QListWidgetItem* item = fListWidget.item(i);
408
409 item->setData(Qt::UserRole + 4, 100.0*temp);
410 }
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000411
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000412 setupOverviewText(picture->typeTimes(), picture->totTime(), kNumRepeats);
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000413}
414
chudy@google.com902ebe52012-06-29 14:21:22 +0000415void SkDebuggerGUI::actionCancel() {
chudy@google.comc432f002012-07-10 13:19:25 +0000416 for (int row = 0; row < fListWidget.count(); row++) {
417 fListWidget.item(row)->setHidden(false);
chudy@google.com902ebe52012-06-29 14:21:22 +0000418 }
419}
420
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000421void SkDebuggerGUI::actionClearBreakpoints() {
422 for (int row = 0; row < fListWidget.count(); row++) {
423 QListWidgetItem* item = fListWidget.item(row);
424 item->setCheckState(Qt::Unchecked);
425 item->setData(Qt::DecorationRole,
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000426 QPixmap(":/blank.png"));
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000427 }
428}
429
430void SkDebuggerGUI::actionClearDeletes() {
431 for (int row = 0; row < fListWidget.count(); row++) {
432 QListWidgetItem* item = fListWidget.item(row);
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000433 item->setData(Qt::UserRole + 2, QPixmap(":/blank.png"));
chudy@google.com607357f2012-08-07 16:12:23 +0000434 fDebugger.setCommandVisible(row, true);
robertphillips@google.com5f971142012-12-07 20:48:56 +0000435 fSkipCommands[row] = false;
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000436 }
437 if (fPause) {
438 fCanvasWidget.drawTo(fPausedRow);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000439 fImageWidget.draw();
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000440 } else {
441 fCanvasWidget.drawTo(fListWidget.currentRow());
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000442 fImageWidget.draw();
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000443 }
444}
445
chudy@google.com902ebe52012-06-29 14:21:22 +0000446void SkDebuggerGUI::actionCommandFilter() {
commit-bot@chromium.org22d39332013-11-21 15:37:29 +0000447 fDebugger.highlightCurrentCommand(fSettingsWidget.getVisibilityFilter());
chudy@google.comc432f002012-07-10 13:19:25 +0000448 fCanvasWidget.drawTo(fListWidget.currentRow());
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000449 fImageWidget.draw();
chudy@google.com902ebe52012-06-29 14:21:22 +0000450}
451
452void SkDebuggerGUI::actionClose() {
453 this->close();
454}
455
456void SkDebuggerGUI::actionDelete() {
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000457
robertphillips@google.comdd4b7452013-01-22 19:38:46 +0000458 for (int row = 0; row < fListWidget.count(); ++row) {
459 QListWidgetItem* item = fListWidget.item(row);
460
461 if (!item->isSelected()) {
462 continue;
463 }
464
465 if (fDebugger.isCommandVisible(row)) {
466 item->setData(Qt::UserRole + 2, QPixmap(":/delete.png"));
467 fDebugger.setCommandVisible(row, false);
468 fSkipCommands[row] = true;
469 } else {
470 item->setData(Qt::UserRole + 2, QPixmap(":/blank.png"));
471 fDebugger.setCommandVisible(row, true);
472 fSkipCommands[row] = false;
473 }
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000474 }
475
robertphillips@google.comdd4b7452013-01-22 19:38:46 +0000476 int currentRow = fListWidget.currentRow();
477
chudy@google.come504de02012-07-16 18:35:23 +0000478 if (fPause) {
479 fCanvasWidget.drawTo(fPausedRow);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000480 fImageWidget.draw();
chudy@google.come504de02012-07-16 18:35:23 +0000481 } else {
482 fCanvasWidget.drawTo(currentRow);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000483 fImageWidget.draw();
chudy@google.come504de02012-07-16 18:35:23 +0000484 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000485}
486
robertphillips@google.come8fe4bc2013-02-13 13:26:13 +0000487#if SK_SUPPORT_GPU
commit-bot@chromium.orgfde1e7c2013-08-02 13:59:50 +0000488void SkDebuggerGUI::actionGLWidget() {
489 bool isToggled = fSettingsWidget.isGLActive();
490 if (isToggled) {
491 fCanvasWidget.setGLSampleCount(fSettingsWidget.getGLSampleCount());
492 }
chudy@google.comea5488b2012-07-26 19:38:22 +0000493 fCanvasWidget.setWidgetVisibility(SkCanvasWidget::kGPU_WidgetType, !isToggled);
494}
robertphillips@google.come8fe4bc2013-02-13 13:26:13 +0000495#endif
chudy@google.comea5488b2012-07-26 19:38:22 +0000496
chudy@google.com902ebe52012-06-29 14:21:22 +0000497void SkDebuggerGUI::actionInspector() {
chudy@google.comc432f002012-07-10 13:19:25 +0000498 if (fInspectorWidget.isHidden()) {
499 fInspectorWidget.setHidden(false);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000500 fImageWidget.setHidden(false);
chudy@google.com902ebe52012-06-29 14:21:22 +0000501 } else {
chudy@google.comc432f002012-07-10 13:19:25 +0000502 fInspectorWidget.setHidden(true);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000503 fImageWidget.setHidden(true);
chudy@google.com902ebe52012-06-29 14:21:22 +0000504 }
505}
506
507void SkDebuggerGUI::actionPlay() {
chudy@google.comc432f002012-07-10 13:19:25 +0000508 for (int row = fListWidget.currentRow() + 1; row < fListWidget.count();
chudy@google.com7dcae672012-07-09 20:26:53 +0000509 row++) {
chudy@google.comc432f002012-07-10 13:19:25 +0000510 QListWidgetItem *item = fListWidget.item(row);
chudy@google.com902ebe52012-06-29 14:21:22 +0000511 if (item->checkState() == Qt::Checked) {
chudy@google.comc432f002012-07-10 13:19:25 +0000512 fListWidget.setCurrentItem(item);
chudy@google.com902ebe52012-06-29 14:21:22 +0000513 return;
514 }
515 }
chudy@google.comc432f002012-07-10 13:19:25 +0000516 fListWidget.setCurrentRow(fListWidget.count() - 1);
chudy@google.com902ebe52012-06-29 14:21:22 +0000517}
518
chudy@google.comea5488b2012-07-26 19:38:22 +0000519void SkDebuggerGUI::actionRasterWidget(bool isToggled) {
520 fCanvasWidget.setWidgetVisibility(SkCanvasWidget::kRaster_8888_WidgetType, !isToggled);
521}
522
robertphillips@google.comf4741c12013-02-06 20:13:54 +0000523void SkDebuggerGUI::actionOverdrawVizWidget(bool isToggled) {
524 fDebugger.setOverdrawViz(isToggled);
525 fCanvasWidget.update();
526}
527
commit-bot@chromium.org768ac852014-03-03 16:32:17 +0000528void SkDebuggerGUI::actionMegaVizWidget(bool isToggled) {
529 fDebugger.setMegaViz(isToggled);
530 fCanvasWidget.update();
531}
532
robertphillips@google.com32bbcf82013-10-17 17:56:10 +0000533void SkDebuggerGUI::actionTextureFilter() {
534 SkPaint::FilterLevel level;
535 bool enabled = fSettingsWidget.getFilterOverride(&level);
536 fDebugger.setTexFilterOverride(enabled, level);
537 fCanvasWidget.update();
538}
539
chudy@google.com902ebe52012-06-29 14:21:22 +0000540void SkDebuggerGUI::actionRewind() {
chudy@google.come504de02012-07-16 18:35:23 +0000541 fListWidget.setCurrentRow(0);
chudy@google.com902ebe52012-06-29 14:21:22 +0000542}
543
chudy@google.com0ab03392012-07-28 20:16:11 +0000544void SkDebuggerGUI::actionSave() {
robertphillips@google.come219baf2013-01-28 19:25:43 +0000545 fFileName = fPath.toAscii().data();
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000546 fFileName.append("/");
robertphillips@google.come219baf2013-01-28 19:25:43 +0000547 fFileName.append(fDirectoryWidget.currentItem()->text().toAscii().data());
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000548 saveToFile(fFileName);
chudy@google.com0ab03392012-07-28 20:16:11 +0000549}
550
551void SkDebuggerGUI::actionSaveAs() {
552 QString filename = QFileDialog::getSaveFileName(this, "Save File", "",
553 "Skia Picture (*skp)");
chudy@google.com38b08ce2012-07-28 23:26:10 +0000554 if (!filename.endsWith(".skp", Qt::CaseInsensitive)) {
chudy@google.com0ab03392012-07-28 20:16:11 +0000555 filename.append(".skp");
556 }
djsollen@google.comc3c82162012-11-13 18:35:10 +0000557 saveToFile(SkString(filename.toAscii().data()));
chudy@google.com0ab03392012-07-28 20:16:11 +0000558}
559
chudy@google.com7dcae672012-07-09 20:26:53 +0000560void SkDebuggerGUI::actionScale(float scaleFactor) {
chudy@google.comc432f002012-07-10 13:19:25 +0000561 fSettingsWidget.setZoomText(scaleFactor);
chudy@google.com7dcae672012-07-09 20:26:53 +0000562}
563
chudy@google.com902ebe52012-06-29 14:21:22 +0000564void SkDebuggerGUI::actionSettings() {
chudy@google.comc432f002012-07-10 13:19:25 +0000565 if (fSettingsWidget.isHidden()) {
566 fSettingsWidget.setHidden(false);
chudy@google.com902ebe52012-06-29 14:21:22 +0000567 } else {
chudy@google.comc432f002012-07-10 13:19:25 +0000568 fSettingsWidget.setHidden(true);
chudy@google.com902ebe52012-06-29 14:21:22 +0000569 }
570}
571
572void SkDebuggerGUI::actionStepBack() {
chudy@google.comc432f002012-07-10 13:19:25 +0000573 int currentRow = fListWidget.currentRow();
chudy@google.com902ebe52012-06-29 14:21:22 +0000574 if (currentRow != 0) {
chudy@google.comc432f002012-07-10 13:19:25 +0000575 fListWidget.setCurrentRow(currentRow - 1);
chudy@google.com902ebe52012-06-29 14:21:22 +0000576 }
577}
578
579void SkDebuggerGUI::actionStepForward() {
chudy@google.comc432f002012-07-10 13:19:25 +0000580 int currentRow = fListWidget.currentRow();
chudy@google.com902ebe52012-06-29 14:21:22 +0000581 QString curRow = QString::number(currentRow);
chudy@google.comc432f002012-07-10 13:19:25 +0000582 QString curCount = QString::number(fListWidget.count());
583 if (currentRow < fListWidget.count() - 1) {
584 fListWidget.setCurrentRow(currentRow + 1);
chudy@google.com902ebe52012-06-29 14:21:22 +0000585 }
586}
587
chudy@google.coma9e937c2012-08-03 17:32:05 +0000588void SkDebuggerGUI::drawComplete() {
chudy@google.com607357f2012-08-07 16:12:23 +0000589 fInspectorWidget.setMatrix(fDebugger.getCurrentMatrix());
590 fInspectorWidget.setClip(fDebugger.getCurrentClip());
chudy@google.coma9e937c2012-08-03 17:32:05 +0000591}
592
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000593void SkDebuggerGUI::saveToFile(const SkString& filename) {
594 SkFILEWStream file(filename.c_str());
robertphillips@google.com25bc2f82013-01-22 18:03:56 +0000595 SkAutoTUnref<SkPicture> copy(fDebugger.copyPicture());
596
597 copy->serialize(&file);
chudy@google.com0ab03392012-07-28 20:16:11 +0000598}
599
chudy@google.com902ebe52012-06-29 14:21:22 +0000600void SkDebuggerGUI::loadFile(QListWidgetItem *item) {
601 if (fDirectoryWidgetActive) {
robertphillips@google.come219baf2013-01-28 19:25:43 +0000602 fFileName = fPath.toAscii().data();
jvanverth@google.com0ac6f162013-02-05 19:44:07 +0000603 // don't add a '/' to files in the local directory
604 if (fFileName.size() > 0) {
605 fFileName.append("/");
606 }
robertphillips@google.come219baf2013-01-28 19:25:43 +0000607 fFileName.append(item->text().toAscii().data());
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000608 loadPicture(fFileName);
chudy@google.com902ebe52012-06-29 14:21:22 +0000609 }
610}
611
612void SkDebuggerGUI::openFile() {
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000613 QString temp = QFileDialog::getOpenFileName(this, tr("Open File"), "",
chudy@google.com7dcae672012-07-09 20:26:53 +0000614 tr("Files (*.*)"));
robertphillips@google.comff6e6ba2013-01-28 17:43:26 +0000615 openFile(temp);
616}
617
618void SkDebuggerGUI::openFile(const QString &filename) {
chudy@google.com902ebe52012-06-29 14:21:22 +0000619 fDirectoryWidgetActive = false;
robertphillips@google.comff6e6ba2013-01-28 17:43:26 +0000620 if (!filename.isEmpty()) {
621 QFileInfo pathInfo(filename);
622 loadPicture(SkString(filename.toAscii().data()));
623 setupDirectoryWidget(pathInfo.path());
chudy@google.com902ebe52012-06-29 14:21:22 +0000624 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000625 fDirectoryWidgetActive = true;
626}
627
chudy@google.comc432f002012-07-10 13:19:25 +0000628void SkDebuggerGUI::pauseDrawing(bool isPaused) {
chudy@google.com607357f2012-08-07 16:12:23 +0000629 fPause = isPaused;
630 fPausedRow = fListWidget.currentRow();
631 fCanvasWidget.drawTo(fPausedRow);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000632 fImageWidget.draw();
chudy@google.com7dcae672012-07-09 20:26:53 +0000633}
634
chudy@google.com902ebe52012-06-29 14:21:22 +0000635void SkDebuggerGUI::registerListClick(QListWidgetItem *item) {
chudy@google.comd3058f52012-07-19 13:41:27 +0000636 if(!fLoading) {
637 int currentRow = fListWidget.currentRow();
chudy@google.comd3058f52012-07-19 13:41:27 +0000638
chudy@google.comea5488b2012-07-26 19:38:22 +0000639 if (currentRow != -1) {
640 if (!fPause) {
641 fCanvasWidget.drawTo(currentRow);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000642 fImageWidget.draw();
chudy@google.comd3058f52012-07-19 13:41:27 +0000643 }
chudy@google.com97cee972012-08-07 20:41:37 +0000644 SkTDArray<SkString*> *currInfo = fDebugger.getCommandInfo(
chudy@google.comea5488b2012-07-26 19:38:22 +0000645 currentRow);
646
647 /* TODO(chudy): Add command type before parameters. Rename v
648 * to something more informative. */
chudy@google.com97cee972012-08-07 20:41:37 +0000649 if (currInfo) {
chudy@google.comea5488b2012-07-26 19:38:22 +0000650 QString info;
651 info.append("<b>Parameters: </b><br/>");
chudy@google.com97cee972012-08-07 20:41:37 +0000652 for (int i = 0; i < currInfo->count(); i++) {
653
654 info.append(QString((*currInfo)[i]->c_str()));
chudy@google.comea5488b2012-07-26 19:38:22 +0000655 info.append("<br/>");
656 }
chudy@google.com6bd109a2012-08-14 19:34:13 +0000657 fInspectorWidget.setText(info, SkInspectorWidget::kDetail_TabType);
chudy@google.comea5488b2012-07-26 19:38:22 +0000658 fInspectorWidget.setDisabled(false);
chudy@google.comea5488b2012-07-26 19:38:22 +0000659 }
chudy@google.comd3058f52012-07-19 13:41:27 +0000660 }
chudy@google.comea5488b2012-07-26 19:38:22 +0000661
chudy@google.com902ebe52012-06-29 14:21:22 +0000662 }
663}
664
chudy@google.com9ca9bfe2012-07-12 21:58:14 +0000665void SkDebuggerGUI::selectCommand(int command) {
666 if (fPause) {
667 fListWidget.setCurrentRow(command);
668 }
669}
670
chudy@google.com902ebe52012-06-29 14:21:22 +0000671void SkDebuggerGUI::toggleBreakpoint() {
chudy@google.comc432f002012-07-10 13:19:25 +0000672 QListWidgetItem* item = fListWidget.currentItem();
chudy@google.com902ebe52012-06-29 14:21:22 +0000673 if (item->checkState() == Qt::Unchecked) {
674 item->setCheckState(Qt::Checked);
chudy@google.come565de42012-07-12 14:15:54 +0000675 item->setData(Qt::DecorationRole,
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000676 QPixmap(":/breakpoint_16x16.png"));
chudy@google.com902ebe52012-06-29 14:21:22 +0000677 } else {
chudy@google.com902ebe52012-06-29 14:21:22 +0000678 item->setCheckState(Qt::Unchecked);
chudy@google.come565de42012-07-12 14:15:54 +0000679 item->setData(Qt::DecorationRole,
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000680 QPixmap(":/blank.png"));
chudy@google.com902ebe52012-06-29 14:21:22 +0000681 }
682}
683
684void SkDebuggerGUI::toggleDirectory() {
chudy@google.com607357f2012-08-07 16:12:23 +0000685 fDirectoryWidget.setHidden(!fDirectoryWidget.isHidden());
chudy@google.com902ebe52012-06-29 14:21:22 +0000686}
687
688void SkDebuggerGUI::toggleFilter(QString string) {
chudy@google.comc432f002012-07-10 13:19:25 +0000689 for (int row = 0; row < fListWidget.count(); row++) {
690 QListWidgetItem *item = fListWidget.item(row);
chudy@google.com607357f2012-08-07 16:12:23 +0000691 item->setHidden(item->text() != string);
chudy@google.com902ebe52012-06-29 14:21:22 +0000692 }
693}
694
695void SkDebuggerGUI::setupUi(QMainWindow *SkDebuggerGUI) {
696 QIcon windowIcon;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000697 windowIcon.addFile(QString::fromUtf8(":/skia.png"), QSize(),
chudy@google.com7dcae672012-07-09 20:26:53 +0000698 QIcon::Normal, QIcon::Off);
chudy@google.com902ebe52012-06-29 14:21:22 +0000699 SkDebuggerGUI->setObjectName(QString::fromUtf8("SkDebuggerGUI"));
700 SkDebuggerGUI->resize(1200, 1000);
701 SkDebuggerGUI->setWindowIcon(windowIcon);
chudy@google.comc432f002012-07-10 13:19:25 +0000702 SkDebuggerGUI->setWindowTitle("Skia Debugger");
chudy@google.com902ebe52012-06-29 14:21:22 +0000703
chudy@google.come504de02012-07-16 18:35:23 +0000704 fActionOpen.setShortcuts(QKeySequence::Open);
chudy@google.comc432f002012-07-10 13:19:25 +0000705 fActionOpen.setText("Open");
chudy@google.com902ebe52012-06-29 14:21:22 +0000706
707 QIcon breakpoint;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000708 breakpoint.addFile(QString::fromUtf8(":/breakpoint.png"),
chudy@google.com7dcae672012-07-09 20:26:53 +0000709 QSize(), QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000710 fActionBreakpoint.setShortcut(QKeySequence(tr("Ctrl+B")));
chudy@google.comc432f002012-07-10 13:19:25 +0000711 fActionBreakpoint.setIcon(breakpoint);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000712 fActionBreakpoint.setText("Breakpoints");
chudy@google.com902ebe52012-06-29 14:21:22 +0000713
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000714 fActionToggleIndexStyle.setShortcut(QKeySequence(tr("Ctrl+T")));
715 fActionToggleIndexStyle.setText("Toggle Index Style");
716
chudy@google.com902ebe52012-06-29 14:21:22 +0000717 QIcon cancel;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000718 cancel.addFile(QString::fromUtf8(":/reload.png"), QSize(),
chudy@google.com7dcae672012-07-09 20:26:53 +0000719 QIcon::Normal, QIcon::Off);
chudy@google.comc432f002012-07-10 13:19:25 +0000720 fActionCancel.setIcon(cancel);
721 fActionCancel.setText("Clear Filter");
chudy@google.com902ebe52012-06-29 14:21:22 +0000722
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000723 fActionClearBreakpoints.setShortcut(QKeySequence(tr("Alt+B")));
724 fActionClearBreakpoints.setText("Clear Breakpoints");
725
726 fActionClearDeletes.setShortcut(QKeySequence(tr("Alt+X")));
727 fActionClearDeletes.setText("Clear Deletes");
728
chudy@google.come504de02012-07-16 18:35:23 +0000729 fActionClose.setShortcuts(QKeySequence::Quit);
chudy@google.comc432f002012-07-10 13:19:25 +0000730 fActionClose.setText("Exit");
chudy@google.com902ebe52012-06-29 14:21:22 +0000731
chudy@google.come504de02012-07-16 18:35:23 +0000732 fActionCreateBreakpoint.setShortcut(QKeySequence(tr("B")));
733 fActionCreateBreakpoint.setText("Set Breakpoint");
734
735 fActionDelete.setShortcut(QKeySequence(tr("X")));
chudy@google.comc432f002012-07-10 13:19:25 +0000736 fActionDelete.setText("Delete Command");
chudy@google.com902ebe52012-06-29 14:21:22 +0000737
chudy@google.come504de02012-07-16 18:35:23 +0000738 fActionDirectory.setShortcut(QKeySequence(tr("Ctrl+D")));
739 fActionDirectory.setText("Directory");
chudy@google.com902ebe52012-06-29 14:21:22 +0000740
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000741 QIcon profile;
robertphillips@google.comd1636362012-11-19 18:25:09 +0000742 profile.addFile(QString::fromUtf8(":/profile.png"), QSize(),
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000743 QIcon::Normal, QIcon::Off);
744 fActionProfile.setIcon(profile);
745 fActionProfile.setText("Profile");
robertphillips@google.come099bc42012-11-19 16:26:40 +0000746 fActionProfile.setDisabled(true);
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000747
chudy@google.comc432f002012-07-10 13:19:25 +0000748 QIcon inspector;
robertphillips@google.comd1636362012-11-19 18:25:09 +0000749 inspector.addFile(QString::fromUtf8(":/inspector.png"),
chudy@google.comc432f002012-07-10 13:19:25 +0000750 QSize(), QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000751 fActionInspector.setShortcut(QKeySequence(tr("Ctrl+I")));
chudy@google.comc432f002012-07-10 13:19:25 +0000752 fActionInspector.setIcon(inspector);
chudy@google.come504de02012-07-16 18:35:23 +0000753 fActionInspector.setText("Inspector");
chudy@google.com902ebe52012-06-29 14:21:22 +0000754
bungeman@google.com2ff6d1d2013-07-01 14:24:12 +0000755 QIcon settings;
756 settings.addFile(QString::fromUtf8(":/inspector.png"),
757 QSize(), QIcon::Normal, QIcon::Off);
758 fActionSettings.setShortcut(QKeySequence(tr("Ctrl+G")));
759 fActionSettings.setIcon(settings);
760 fActionSettings.setText("Settings");
skia.committer@gmail.com0d55dd72013-07-02 07:00:59 +0000761
chudy@google.comc432f002012-07-10 13:19:25 +0000762 QIcon play;
robertphillips@google.comd1636362012-11-19 18:25:09 +0000763 play.addFile(QString::fromUtf8(":/play.png"), QSize(),
chudy@google.comc432f002012-07-10 13:19:25 +0000764 QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000765 fActionPlay.setShortcut(QKeySequence(tr("Ctrl+P")));
chudy@google.comc432f002012-07-10 13:19:25 +0000766 fActionPlay.setIcon(play);
767 fActionPlay.setText("Play");
chudy@google.com902ebe52012-06-29 14:21:22 +0000768
chudy@google.come504de02012-07-16 18:35:23 +0000769 QIcon pause;
robertphillips@google.comd1636362012-11-19 18:25:09 +0000770 pause.addFile(QString::fromUtf8(":/pause.png"), QSize(),
chudy@google.comc432f002012-07-10 13:19:25 +0000771 QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000772 fActionPause.setShortcut(QKeySequence(tr("Space")));
773 fActionPause.setCheckable(true);
774 fActionPause.setIcon(pause);
775 fActionPause.setText("Pause");
776
chudy@google.comc432f002012-07-10 13:19:25 +0000777 QIcon rewind;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000778 rewind.addFile(QString::fromUtf8(":/rewind.png"), QSize(),
chudy@google.comc432f002012-07-10 13:19:25 +0000779 QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000780 fActionRewind.setShortcut(QKeySequence(tr("Ctrl+R")));
chudy@google.comc432f002012-07-10 13:19:25 +0000781 fActionRewind.setIcon(rewind);
782 fActionRewind.setText("Rewind");
chudy@google.com902ebe52012-06-29 14:21:22 +0000783
chudy@google.com0ab03392012-07-28 20:16:11 +0000784 fActionSave.setShortcut(QKeySequence::Save);
785 fActionSave.setText("Save");
786 fActionSave.setDisabled(true);
787 fActionSaveAs.setShortcut(QKeySequence::SaveAs);
788 fActionSaveAs.setText("Save As");
789 fActionSaveAs.setDisabled(true);
790
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000791 fActionShowDeletes.setShortcut(QKeySequence(tr("Ctrl+X")));
792 fActionShowDeletes.setText("Deleted Commands");
793
chudy@google.comc432f002012-07-10 13:19:25 +0000794 QIcon stepBack;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000795 stepBack.addFile(QString::fromUtf8(":/previous.png"), QSize(),
chudy@google.comc432f002012-07-10 13:19:25 +0000796 QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000797 fActionStepBack.setShortcut(QKeySequence(tr("[")));
chudy@google.comc432f002012-07-10 13:19:25 +0000798 fActionStepBack.setIcon(stepBack);
799 fActionStepBack.setText("Step Back");
chudy@google.com902ebe52012-06-29 14:21:22 +0000800
chudy@google.comc432f002012-07-10 13:19:25 +0000801 QIcon stepForward;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000802 stepForward.addFile(QString::fromUtf8(":/next.png"),
chudy@google.comc432f002012-07-10 13:19:25 +0000803 QSize(), QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000804 fActionStepForward.setShortcut(QKeySequence(tr("]")));
chudy@google.comc432f002012-07-10 13:19:25 +0000805 fActionStepForward.setIcon(stepForward);
806 fActionStepForward.setText("Step Forward");
807
chudy@google.coma1226312012-07-26 20:26:44 +0000808 fActionZoomIn.setShortcut(QKeySequence(tr("Ctrl+=")));
809 fActionZoomIn.setText("Zoom In");
810 fActionZoomOut.setShortcut(QKeySequence(tr("Ctrl+-")));
811 fActionZoomOut.setText("Zoom Out");
812
chudy@google.comc432f002012-07-10 13:19:25 +0000813 fListWidget.setItemDelegate(new SkListWidget(&fListWidget));
814 fListWidget.setObjectName(QString::fromUtf8("listWidget"));
commit-bot@chromium.orgbcd431e2013-11-21 13:41:37 +0000815 fListWidget.setMinimumWidth(250);
chudy@google.comc432f002012-07-10 13:19:25 +0000816
817 fFilter.addItem("--Filter By Available Commands--");
818
commit-bot@chromium.orgbcd431e2013-11-21 13:41:37 +0000819 fDirectoryWidget.setMinimumWidth(250);
chudy@google.comc432f002012-07-10 13:19:25 +0000820 fDirectoryWidget.setStyleSheet("QListWidget::Item {padding: 5px;}");
821
822 fCanvasWidget.setSizePolicy(QSizePolicy::Expanding,
chudy@google.com7dcae672012-07-09 20:26:53 +0000823 QSizePolicy::Expanding);
chudy@google.com902ebe52012-06-29 14:21:22 +0000824
skia.committer@gmail.com1c9c0d32012-11-22 02:02:41 +0000825 fImageWidget.setFixedSize(SkImageWidget::kImageWidgetWidth,
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000826 SkImageWidget::kImageWidgetHeight);
827
chudy@google.comc432f002012-07-10 13:19:25 +0000828 fInspectorWidget.setSizePolicy(QSizePolicy::Expanding,
chudy@google.com7dcae672012-07-09 20:26:53 +0000829 QSizePolicy::Expanding);
chudy@google.comc432f002012-07-10 13:19:25 +0000830 fInspectorWidget.setMaximumHeight(300);
chudy@google.com902ebe52012-06-29 14:21:22 +0000831
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000832 fSettingsAndImageLayout.setSpacing(6);
833 fSettingsAndImageLayout.addWidget(&fSettingsWidget);
834 fSettingsAndImageLayout.addWidget(&fImageWidget);
835
chudy@google.comc432f002012-07-10 13:19:25 +0000836 fSettingsWidget.setSizePolicy(QSizePolicy::Expanding,
837 QSizePolicy::Expanding);
838 fSettingsWidget.setMaximumWidth(250);
chudy@google.com902ebe52012-06-29 14:21:22 +0000839
commit-bot@chromium.orgbcd431e2013-11-21 13:41:37 +0000840 fLeftColumnSplitter.addWidget(&fListWidget);
841 fLeftColumnSplitter.addWidget(&fDirectoryWidget);
842 fLeftColumnSplitter.setOrientation(Qt::Vertical);
chudy@google.com902ebe52012-06-29 14:21:22 +0000843
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000844 fCanvasSettingsAndImageLayout.setSpacing(6);
845 fCanvasSettingsAndImageLayout.addWidget(&fCanvasWidget);
846 fCanvasSettingsAndImageLayout.addLayout(&fSettingsAndImageLayout);
847
chudy@google.comc432f002012-07-10 13:19:25 +0000848 fMainAndRightColumnLayout.setSpacing(6);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000849 fMainAndRightColumnLayout.addLayout(&fCanvasSettingsAndImageLayout);
chudy@google.comc432f002012-07-10 13:19:25 +0000850 fMainAndRightColumnLayout.addWidget(&fInspectorWidget);
commit-bot@chromium.orgbcd431e2013-11-21 13:41:37 +0000851 fMainAndRightColumnWidget.setLayout(&fMainAndRightColumnLayout);
chudy@google.com902ebe52012-06-29 14:21:22 +0000852
commit-bot@chromium.orgbcd431e2013-11-21 13:41:37 +0000853 fCentralSplitter.addWidget(&fLeftColumnSplitter);
854 fCentralSplitter.addWidget(&fMainAndRightColumnWidget);
855 fCentralSplitter.setStretchFactor(0, 0);
856 fCentralSplitter.setStretchFactor(1, 1);
chudy@google.comc432f002012-07-10 13:19:25 +0000857
commit-bot@chromium.orgbcd431e2013-11-21 13:41:37 +0000858 SkDebuggerGUI->setCentralWidget(&fCentralSplitter);
chudy@google.comc432f002012-07-10 13:19:25 +0000859 SkDebuggerGUI->setStatusBar(&fStatusBar);
860
chudy@google.come504de02012-07-16 18:35:23 +0000861 fToolBar.setIconSize(QSize(32, 32));
chudy@google.comc432f002012-07-10 13:19:25 +0000862 fToolBar.setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
863 SkDebuggerGUI->addToolBar(Qt::TopToolBarArea, &fToolBar);
chudy@google.com902ebe52012-06-29 14:21:22 +0000864
chudy@google.com0ab03392012-07-28 20:16:11 +0000865 fSpacer.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
chudy@google.com902ebe52012-06-29 14:21:22 +0000866
chudy@google.comc432f002012-07-10 13:19:25 +0000867 fToolBar.addAction(&fActionRewind);
868 fToolBar.addAction(&fActionStepBack);
chudy@google.come504de02012-07-16 18:35:23 +0000869 fToolBar.addAction(&fActionPause);
chudy@google.comc432f002012-07-10 13:19:25 +0000870 fToolBar.addAction(&fActionStepForward);
871 fToolBar.addAction(&fActionPlay);
872 fToolBar.addSeparator();
chudy@google.come504de02012-07-16 18:35:23 +0000873 fToolBar.addAction(&fActionInspector);
bungeman@google.com2ff6d1d2013-07-01 14:24:12 +0000874 fToolBar.addAction(&fActionSettings);
chudy@google.comc432f002012-07-10 13:19:25 +0000875 fToolBar.addSeparator();
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000876 fToolBar.addAction(&fActionProfile);
877
878 fToolBar.addSeparator();
chudy@google.com0ab03392012-07-28 20:16:11 +0000879 fToolBar.addWidget(&fSpacer);
chudy@google.comc432f002012-07-10 13:19:25 +0000880 fToolBar.addWidget(&fFilter);
881 fToolBar.addAction(&fActionCancel);
chudy@google.com902ebe52012-06-29 14:21:22 +0000882
883 // TODO(chudy): Remove static call.
884 fDirectoryWidgetActive = false;
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000885 fFileName = "";
robertphillips@google.comff6e6ba2013-01-28 17:43:26 +0000886 setupDirectoryWidget("");
chudy@google.com902ebe52012-06-29 14:21:22 +0000887 fDirectoryWidgetActive = true;
888
chudy@google.com902ebe52012-06-29 14:21:22 +0000889 // Menu Bar
chudy@google.comc432f002012-07-10 13:19:25 +0000890 fMenuFile.setTitle("File");
891 fMenuFile.addAction(&fActionOpen);
chudy@google.com0ab03392012-07-28 20:16:11 +0000892 fMenuFile.addAction(&fActionSave);
893 fMenuFile.addAction(&fActionSaveAs);
chudy@google.comc432f002012-07-10 13:19:25 +0000894 fMenuFile.addAction(&fActionClose);
chudy@google.come504de02012-07-16 18:35:23 +0000895
896 fMenuEdit.setTitle("Edit");
897 fMenuEdit.addAction(&fActionDelete);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000898 fMenuEdit.addAction(&fActionClearDeletes);
899 fMenuEdit.addSeparator();
chudy@google.come504de02012-07-16 18:35:23 +0000900 fMenuEdit.addAction(&fActionCreateBreakpoint);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000901 fMenuEdit.addAction(&fActionClearBreakpoints);
chudy@google.come504de02012-07-16 18:35:23 +0000902
chudy@google.comc432f002012-07-10 13:19:25 +0000903 fMenuNavigate.setTitle("Navigate");
chudy@google.come504de02012-07-16 18:35:23 +0000904 fMenuNavigate.addAction(&fActionRewind);
905 fMenuNavigate.addAction(&fActionStepBack);
906 fMenuNavigate.addAction(&fActionStepForward);
907 fMenuNavigate.addAction(&fActionPlay);
908 fMenuNavigate.addAction(&fActionPause);
chudy@google.comc432f002012-07-10 13:19:25 +0000909 fMenuNavigate.addAction(&fActionGoToLine);
chudy@google.come504de02012-07-16 18:35:23 +0000910
chudy@google.comc432f002012-07-10 13:19:25 +0000911 fMenuView.setTitle("View");
chudy@google.come504de02012-07-16 18:35:23 +0000912 fMenuView.addAction(&fActionBreakpoint);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000913 fMenuView.addAction(&fActionShowDeletes);
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000914 fMenuView.addAction(&fActionToggleIndexStyle);
chudy@google.coma1226312012-07-26 20:26:44 +0000915 fMenuView.addAction(&fActionZoomIn);
916 fMenuView.addAction(&fActionZoomOut);
chudy@google.come504de02012-07-16 18:35:23 +0000917
918 fMenuWindows.setTitle("Window");
919 fMenuWindows.addAction(&fActionInspector);
bungeman@google.com2ff6d1d2013-07-01 14:24:12 +0000920 fMenuWindows.addAction(&fActionSettings);
chudy@google.come504de02012-07-16 18:35:23 +0000921 fMenuWindows.addAction(&fActionDirectory);
chudy@google.comc432f002012-07-10 13:19:25 +0000922
923 fActionGoToLine.setText("Go to Line...");
924 fActionGoToLine.setDisabled(true);
925 fMenuBar.addAction(fMenuFile.menuAction());
chudy@google.come504de02012-07-16 18:35:23 +0000926 fMenuBar.addAction(fMenuEdit.menuAction());
chudy@google.comc432f002012-07-10 13:19:25 +0000927 fMenuBar.addAction(fMenuView.menuAction());
928 fMenuBar.addAction(fMenuNavigate.menuAction());
chudy@google.come504de02012-07-16 18:35:23 +0000929 fMenuBar.addAction(fMenuWindows.menuAction());
chudy@google.com902ebe52012-06-29 14:21:22 +0000930
chudy@google.com7dcae672012-07-09 20:26:53 +0000931 fPause = false;
932
chudy@google.comc432f002012-07-10 13:19:25 +0000933 SkDebuggerGUI->setMenuBar(&fMenuBar);
chudy@google.com902ebe52012-06-29 14:21:22 +0000934 QMetaObject::connectSlotsByName(SkDebuggerGUI);
935}
936
robertphillips@google.comff6e6ba2013-01-28 17:43:26 +0000937void SkDebuggerGUI::setupDirectoryWidget(const QString& path) {
938 fPath = path;
939 QDir dir(path);
chudy@google.com902ebe52012-06-29 14:21:22 +0000940 QRegExp r(".skp");
chudy@google.comc432f002012-07-10 13:19:25 +0000941 fDirectoryWidget.clear();
942 const QStringList files = dir.entryList();
chudy@google.com902ebe52012-06-29 14:21:22 +0000943 foreach (QString f, files) {
chudy@google.com7dcae672012-07-09 20:26:53 +0000944 if (f.contains(r))
chudy@google.comc432f002012-07-10 13:19:25 +0000945 fDirectoryWidget.addItem(f);
chudy@google.com902ebe52012-06-29 14:21:22 +0000946 }
947}
948
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000949void SkDebuggerGUI::loadPicture(const SkString& fileName) {
950 fFileName = fileName;
chudy@google.comd3058f52012-07-19 13:41:27 +0000951 fLoading = true;
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000952 SkStream* stream = SkNEW_ARGS(SkFILEStream, (fileName.c_str()));
robertphillips@google.com2d40ec42013-02-07 20:39:40 +0000953
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000954 SkPicture* picture = SkPicture::CreateFromStream(stream);
robertphillips@google.com2d40ec42013-02-07 20:39:40 +0000955
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000956 if (NULL == picture) {
robertphillips@google.com2d40ec42013-02-07 20:39:40 +0000957 QMessageBox::critical(this, "Error loading file", "Couldn't read file, sorry.");
958 SkSafeUnref(stream);
959 return;
960 }
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000961
chudy@google.com686e6802012-08-14 16:00:32 +0000962 fCanvasWidget.resetWidgetTransform();
chudy@google.com607357f2012-08-07 16:12:23 +0000963 fDebugger.loadPicture(picture);
chudy@google.com4c7962e2012-08-14 19:38:31 +0000964
robertphillips@google.com6d9c92b2013-05-23 13:21:18 +0000965 fSkipCommands.setCount(fDebugger.getSize());
966 for (int i = 0; i < fSkipCommands.count(); ++i) {
robertphillips@google.com5f971142012-12-07 20:48:56 +0000967 fSkipCommands[i] = false;
968 }
969
chudy@google.com607357f2012-08-07 16:12:23 +0000970 SkSafeUnref(stream);
971 SkSafeUnref(picture);
972
chudy@google.com97cee972012-08-07 20:41:37 +0000973 // Will this automatically clear out due to nature of refcnt?
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000974 SkTArray<SkString>* commands = fDebugger.getDrawCommandsAsStrings();
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000975 SkTDArray<size_t>* offsets = fDebugger.getDrawCommandOffsets();
976 SkASSERT(commands->count() == offsets->count());
chudy@google.com607357f2012-08-07 16:12:23 +0000977
robertphillips@google.com6d9c92b2013-05-23 13:21:18 +0000978 fActionProfile.setDisabled(false);
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000979
chudy@google.com7dcae672012-07-09 20:26:53 +0000980 /* fDebugCanvas is reinitialized every load picture. Need it to retain value
chudy@google.com607357f2012-08-07 16:12:23 +0000981 * of the visibility filter.
982 * TODO(chudy): This should be deprecated since fDebugger is not
983 * recreated.
984 * */
commit-bot@chromium.org22d39332013-11-21 15:37:29 +0000985 fDebugger.highlightCurrentCommand(fSettingsWidget.getVisibilityFilter());
chudy@google.com607357f2012-08-07 16:12:23 +0000986
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000987 this->setupListWidget(commands, offsets);
988 this->setupComboBox(commands);
989 this->setupOverviewText(NULL, 0.0, 1);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000990 fInspectorWidget.setDisabled(false);
chudy@google.come606d6e2012-07-12 14:31:25 +0000991 fSettingsWidget.setDisabled(false);
chudy@google.comd3058f52012-07-19 13:41:27 +0000992 fMenuEdit.setDisabled(false);
993 fMenuNavigate.setDisabled(false);
994 fMenuView.setDisabled(false);
chudy@google.com0ab03392012-07-28 20:16:11 +0000995 fActionSave.setDisabled(false);
996 fActionSaveAs.setDisabled(false);
chudy@google.comd3058f52012-07-19 13:41:27 +0000997 fLoading = false;
998 actionPlay();
chudy@google.com902ebe52012-06-29 14:21:22 +0000999}
1000
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +00001001void SkDebuggerGUI::setupListWidget(SkTArray<SkString>* commands, SkTDArray<size_t>* offsets) {
1002 SkASSERT(commands->count() == offsets->count());
chudy@google.comc432f002012-07-10 13:19:25 +00001003 fListWidget.clear();
chudy@google.com902ebe52012-06-29 14:21:22 +00001004 int counter = 0;
robertphillips@google.com30d35f22012-11-06 16:45:36 +00001005 int indent = 0;
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +00001006 for (int i = 0; i < commands->count(); i++) {
chudy@google.com902ebe52012-06-29 14:21:22 +00001007 QListWidgetItem *item = new QListWidgetItem();
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +00001008 item->setData(Qt::DisplayRole, (*commands)[i].c_str());
chudy@google.com902ebe52012-06-29 14:21:22 +00001009 item->setData(Qt::UserRole + 1, counter++);
robertphillips@google.com30d35f22012-11-06 16:45:36 +00001010
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +00001011 if (0 == strcmp("Restore", (*commands)[i].c_str()) ||
1012 0 == strcmp("EndCommentGroup", (*commands)[i].c_str()) ||
1013 0 == strcmp("PopCull", (*commands)[i].c_str())) {
robertphillips@google.com30d35f22012-11-06 16:45:36 +00001014 indent -= 10;
1015 }
1016
1017 item->setData(Qt::UserRole + 3, indent);
1018
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +00001019 if (0 == strcmp("Save", (*commands)[i].c_str()) ||
1020 0 == strcmp("Save Layer", (*commands)[i].c_str()) ||
1021 0 == strcmp("BeginCommentGroup", (*commands)[i].c_str()) ||
1022 0 == strcmp("PushCull", (*commands)[i].c_str())) {
robertphillips@google.com30d35f22012-11-06 16:45:36 +00001023 indent += 10;
1024 }
1025
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +00001026 item->setData(Qt::UserRole + 4, -1);
1027 item->setData(Qt::UserRole + 5, (int)(*offsets)[i]);
robertphillips@google.comd26c7062012-11-12 20:42:12 +00001028
chudy@google.comc432f002012-07-10 13:19:25 +00001029 fListWidget.addItem(item);
chudy@google.com902ebe52012-06-29 14:21:22 +00001030 }
1031}
1032
skia.committer@gmail.com91274b92013-03-13 07:01:04 +00001033void SkDebuggerGUI::setupOverviewText(const SkTDArray<double>* typeTimes,
robertphillips@google.come428f9b2013-03-12 15:33:40 +00001034 double totTime,
1035 int numRuns) {
borenet@google.com2d9dbd42013-03-12 13:07:40 +00001036 SkString overview;
robertphillips@google.come428f9b2013-03-12 15:33:40 +00001037 fDebugger.getOverviewText(typeTimes, totTime, &overview, numRuns);
borenet@google.com2d9dbd42013-03-12 13:07:40 +00001038 fInspectorWidget.setText(overview.c_str(), SkInspectorWidget::kOverview_TabType);
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +00001039}
1040
1041void SkDebuggerGUI::setupComboBox(SkTArray<SkString>* command) {
1042 fFilter.clear();
1043 fFilter.addItem("--Filter By Available Commands--");
1044
1045 std::map<std::string, int> map;
1046 for (int i = 0; i < command->count(); i++) {
1047 map[(*command)[i].c_str()]++;
1048 }
1049
skia.committer@gmail.com34587162012-11-20 02:01:23 +00001050 for (std::map<std::string, int>::iterator it = map.begin(); it != map.end();
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +00001051 ++it) {
1052 fFilter.addItem((it->first).c_str());
1053 }
chudy@google.com902ebe52012-06-29 14:21:22 +00001054
1055 // NOTE(chudy): Makes first item unselectable.
chudy@google.com7dcae672012-07-09 20:26:53 +00001056 QStandardItemModel* model = qobject_cast<QStandardItemModel*>(
chudy@google.comc432f002012-07-10 13:19:25 +00001057 fFilter.model());
1058 QModelIndex firstIndex = model->index(0, fFilter.modelColumn(),
1059 fFilter.rootModelIndex());
chudy@google.com902ebe52012-06-29 14:21:22 +00001060 QStandardItem* firstItem = model->itemFromIndex(firstIndex);
1061 firstItem->setSelectable(false);
1062}