blob: b03b8f3b16eb33352dce1cde3700bdcce1a7e25e [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"
robertphillipsce4dd3d2014-07-07 13:46:35 -070014#include "SkPicturePlayback.h"
robertphillips@google.com2bde91d2012-11-15 14:57:57 +000015#include "SkPictureRecord.h"
robertphillipsdb539902014-07-01 08:47:04 -070016#include "SkPictureData.h"
robertphillips@google.come174a8b2012-11-27 16:04:42 +000017
scroggo@google.com7def5e12013-05-31 14:00:10 +000018__SK_FORCE_IMAGE_DECODER_LINKING;
19
robertphillips@google.come174a8b2012-11-27 16:04:42 +000020#if defined(SK_BUILD_FOR_WIN32)
mtklein9ac68ee2014-06-20 11:29:20 -070021 #include "SysTimer_windows.h"
robertphillips@google.come174a8b2012-11-27 16:04:42 +000022#elif defined(SK_BUILD_FOR_MAC)
mtklein9ac68ee2014-06-20 11:29:20 -070023 #include "SysTimer_mach.h"
robertphillips@google.come174a8b2012-11-27 16:04:42 +000024#elif defined(SK_BUILD_FOR_UNIX) || defined(SK_BUILD_FOR_ANDROID)
mtklein9ac68ee2014-06-20 11:29:20 -070025 #include "SysTimer_posix.h"
robertphillips@google.come174a8b2012-11-27 16:04:42 +000026#else
mtklein9ac68ee2014-06-20 11:29:20 -070027 #include "SysTimer_c.h"
robertphillips@google.come174a8b2012-11-27 16:04:42 +000028#endif
29
chudy@google.com902ebe52012-06-29 14:21:22 +000030
31SkDebuggerGUI::SkDebuggerGUI(QWidget *parent) :
chudy@google.comc432f002012-07-10 13:19:25 +000032 QMainWindow(parent)
commit-bot@chromium.orgbcd431e2013-11-21 13:41:37 +000033 , fCentralSplitter(this)
chudy@google.com2d537a12012-07-31 12:49:52 +000034 , fStatusBar(this)
35 , fToolBar(this)
chudy@google.comc432f002012-07-10 13:19:25 +000036 , fActionOpen(this)
37 , fActionBreakpoint(this)
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +000038 , fActionToggleIndexStyle(this)
robertphillips@google.comd26c7062012-11-12 20:42:12 +000039 , fActionProfile(this)
chudy@google.comc432f002012-07-10 13:19:25 +000040 , fActionCancel(this)
chudy@google.com7e4cfbf2012-07-17 15:40:51 +000041 , fActionClearBreakpoints(this)
chudy@google.come504de02012-07-16 18:35:23 +000042 , fActionClearDeletes(this)
chudy@google.comc432f002012-07-10 13:19:25 +000043 , fActionClose(this)
chudy@google.come504de02012-07-16 18:35:23 +000044 , fActionCreateBreakpoint(this)
chudy@google.comc432f002012-07-10 13:19:25 +000045 , fActionDelete(this)
46 , fActionDirectory(this)
47 , fActionGoToLine(this)
48 , fActionInspector(this)
bungeman@google.com2ff6d1d2013-07-01 14:24:12 +000049 , fActionSettings(this)
chudy@google.comc432f002012-07-10 13:19:25 +000050 , fActionPlay(this)
chudy@google.come504de02012-07-16 18:35:23 +000051 , fActionPause(this)
chudy@google.comc432f002012-07-10 13:19:25 +000052 , fActionRewind(this)
chudy@google.com0ab03392012-07-28 20:16:11 +000053 , fActionSave(this)
54 , fActionSaveAs(this)
chudy@google.com7e4cfbf2012-07-17 15:40:51 +000055 , fActionShowDeletes(this)
chudy@google.comc432f002012-07-10 13:19:25 +000056 , fActionStepBack(this)
57 , fActionStepForward(this)
chudy@google.coma1226312012-07-26 20:26:44 +000058 , fActionZoomIn(this)
59 , fActionZoomOut(this)
60 , fMapper(this)
commit-bot@chromium.orgbcd431e2013-11-21 13:41:37 +000061 , fListWidget(&fCentralSplitter)
62 , fDirectoryWidget(&fCentralSplitter)
chudy@google.com607357f2012-08-07 16:12:23 +000063 , fCanvasWidget(this, &fDebugger)
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +000064 , fImageWidget(&fDebugger)
chudy@google.comc432f002012-07-10 13:19:25 +000065 , fMenuBar(this)
66 , fMenuFile(this)
67 , fMenuNavigate(this)
68 , fMenuView(this)
chudy@google.com7e4cfbf2012-07-17 15:40:51 +000069 , fBreakpointsActivated(false)
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +000070 , fIndexStyleToggle(false)
chudy@google.com7e4cfbf2012-07-17 15:40:51 +000071 , fDeletesActivated(false)
72 , fPause(false)
chudy@google.comd3058f52012-07-19 13:41:27 +000073 , fLoading(false)
chudy@google.comc432f002012-07-10 13:19:25 +000074{
chudy@google.com902ebe52012-06-29 14:21:22 +000075 setupUi(this);
robertphillips@google.comdd4b7452013-01-22 19:38:46 +000076 fListWidget.setSelectionMode(QAbstractItemView::ExtendedSelection);
chudy@google.comea5488b2012-07-26 19:38:22 +000077 connect(&fListWidget, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)), this, SLOT(registerListClick(QListWidgetItem *)));
chudy@google.comc432f002012-07-10 13:19:25 +000078 connect(&fActionOpen, SIGNAL(triggered()), this, SLOT(openFile()));
chudy@google.comea5488b2012-07-26 19:38:22 +000079 connect(&fActionDirectory, SIGNAL(triggered()), this, SLOT(toggleDirectory()));
80 connect(&fDirectoryWidget, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)), this, SLOT(loadFile(QListWidgetItem *)));
chudy@google.comc432f002012-07-10 13:19:25 +000081 connect(&fActionDelete, SIGNAL(triggered()), this, SLOT(actionDelete()));
chudy@google.comea5488b2012-07-26 19:38:22 +000082 connect(&fListWidget, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(toggleBreakpoint()));
chudy@google.comc432f002012-07-10 13:19:25 +000083 connect(&fActionRewind, SIGNAL(triggered()), this, SLOT(actionRewind()));
84 connect(&fActionPlay, SIGNAL(triggered()), this, SLOT(actionPlay()));
85 connect(&fActionStepBack, SIGNAL(triggered()), this, SLOT(actionStepBack()));
chudy@google.comea5488b2012-07-26 19:38:22 +000086 connect(&fActionStepForward, SIGNAL(triggered()), this, SLOT(actionStepForward()));
87 connect(&fActionBreakpoint, SIGNAL(triggered()), this, SLOT(actionBreakpoints()));
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +000088 connect(&fActionToggleIndexStyle, SIGNAL(triggered()), this, SLOT(actionToggleIndexStyle()));
chudy@google.comea5488b2012-07-26 19:38:22 +000089 connect(&fActionInspector, SIGNAL(triggered()), this, SLOT(actionInspector()));
bungeman@google.com2ff6d1d2013-07-01 14:24:12 +000090 connect(&fActionSettings, SIGNAL(triggered()), this, SLOT(actionSettings()));
chudy@google.comea5488b2012-07-26 19:38:22 +000091 connect(&fFilter, SIGNAL(activated(QString)), this, SLOT(toggleFilter(QString)));
robertphillips@google.comd26c7062012-11-12 20:42:12 +000092 connect(&fActionProfile, SIGNAL(triggered()), this, SLOT(actionProfile()));
chudy@google.comc432f002012-07-10 13:19:25 +000093 connect(&fActionCancel, SIGNAL(triggered()), this, SLOT(actionCancel()));
chudy@google.com7e4cfbf2012-07-17 15:40:51 +000094 connect(&fActionClearBreakpoints, SIGNAL(triggered()), this, SLOT(actionClearBreakpoints()));
95 connect(&fActionClearDeletes, SIGNAL(triggered()), this, SLOT(actionClearDeletes()));
chudy@google.comc432f002012-07-10 13:19:25 +000096 connect(&fActionClose, SIGNAL(triggered()), this, SLOT(actionClose()));
commit-bot@chromium.org22d39332013-11-21 15:37:29 +000097 connect(&fSettingsWidget, SIGNAL(visibilityFilterChanged()), this, SLOT(actionCommandFilter()));
robertphillips@google.come8fe4bc2013-02-13 13:26:13 +000098#if SK_SUPPORT_GPU
commit-bot@chromium.orgfde1e7c2013-08-02 13:59:50 +000099 connect(&fSettingsWidget, SIGNAL(glSettingsChanged()), this, SLOT(actionGLWidget()));
robertphillips@google.come8fe4bc2013-02-13 13:26:13 +0000100#endif
robertphillips@google.com32bbcf82013-10-17 17:56:10 +0000101 connect(&fSettingsWidget, SIGNAL(texFilterSettingsChanged()), this, SLOT(actionTextureFilter()));
chudy@google.comea5488b2012-07-26 19:38:22 +0000102 connect(fSettingsWidget.getRasterCheckBox(), SIGNAL(toggled(bool)), this, SLOT(actionRasterWidget(bool)));
robertphillips@google.comf4741c12013-02-06 20:13:54 +0000103 connect(fSettingsWidget.getOverdrawVizCheckBox(), SIGNAL(toggled(bool)), this, SLOT(actionOverdrawVizWidget(bool)));
commit-bot@chromium.org768ac852014-03-03 16:32:17 +0000104 connect(fSettingsWidget.getMegaVizCheckBox(), SIGNAL(toggled(bool)), this, SLOT(actionMegaVizWidget(bool)));
commit-bot@chromium.org2a67e122014-05-19 13:53:10 +0000105 connect(fSettingsWidget.getPathOpsCheckBox(), SIGNAL(toggled(bool)), this, SLOT(actionPathOpsWidget(bool)));
chudy@google.comea5488b2012-07-26 19:38:22 +0000106 connect(&fActionPause, SIGNAL(toggled(bool)), this, SLOT(pauseDrawing(bool)));
chudy@google.come504de02012-07-16 18:35:23 +0000107 connect(&fActionCreateBreakpoint, SIGNAL(activated()), this, SLOT(toggleBreakpoint()));
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000108 connect(&fActionShowDeletes, SIGNAL(triggered()), this, SLOT(showDeletes()));
chudy@google.comea5488b2012-07-26 19:38:22 +0000109 connect(&fCanvasWidget, SIGNAL(hitChanged(int)), this, SLOT(selectCommand(int)));
110 connect(&fCanvasWidget, SIGNAL(hitChanged(int)), &fSettingsWidget, SLOT(updateHit(int)));
111 connect(&fCanvasWidget, SIGNAL(scaleFactorChanged(float)), this, SLOT(actionScale(float)));
112 connect(&fCanvasWidget, SIGNAL(commandChanged(int)), &fSettingsWidget, SLOT(updateCommand(int)));
chudy@google.com0ab03392012-07-28 20:16:11 +0000113 connect(&fActionSaveAs, SIGNAL(triggered()), this, SLOT(actionSaveAs()));
114 connect(&fActionSave, SIGNAL(triggered()), this, SLOT(actionSave()));
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000115
bungeman@google.come8cc6e82013-01-17 16:30:56 +0000116 fMapper.setMapping(&fActionZoomIn, SkCanvasWidget::kIn_ZoomCommand);
117 fMapper.setMapping(&fActionZoomOut, SkCanvasWidget::kOut_ZoomCommand);
chudy@google.coma1226312012-07-26 20:26:44 +0000118
119 connect(&fActionZoomIn, SIGNAL(triggered()), &fMapper, SLOT(map()));
120 connect(&fActionZoomOut, SIGNAL(triggered()), &fMapper, SLOT(map()));
bungeman@google.come8cc6e82013-01-17 16:30:56 +0000121 connect(&fMapper, SIGNAL(mapped(int)), &fCanvasWidget, SLOT(zoom(int)));
chudy@google.coma1226312012-07-26 20:26:44 +0000122
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000123 fInspectorWidget.setDisabled(true);
chudy@google.comd3058f52012-07-19 13:41:27 +0000124 fMenuEdit.setDisabled(true);
125 fMenuNavigate.setDisabled(true);
126 fMenuView.setDisabled(true);
chudy@google.combbad34d2012-08-13 14:26:36 +0000127
128 SkGraphics::Init();
chudy@google.com902ebe52012-06-29 14:21:22 +0000129}
130
chudy@google.combbad34d2012-08-13 14:26:36 +0000131SkDebuggerGUI::~SkDebuggerGUI() {
132 SkGraphics::Term();
133}
chudy@google.com902ebe52012-06-29 14:21:22 +0000134
135void SkDebuggerGUI::actionBreakpoints() {
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000136 fBreakpointsActivated = !fBreakpointsActivated;
chudy@google.comc432f002012-07-10 13:19:25 +0000137 for (int row = 0; row < fListWidget.count(); row++) {
138 QListWidgetItem *item = fListWidget.item(row);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000139 item->setHidden(item->checkState() == Qt::Unchecked && fBreakpointsActivated);
140 }
141}
chudy@google.com902ebe52012-06-29 14:21:22 +0000142
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000143void SkDebuggerGUI::actionToggleIndexStyle() {
144 fIndexStyleToggle = !fIndexStyleToggle;
145 SkListWidget* list = (SkListWidget*) fListWidget.itemDelegate();
skia.committer@gmail.comdb35dab2014-03-27 03:02:48 +0000146 list->setIndexStyle(fIndexStyleToggle ? SkListWidget::kIndex_IndexStyle :
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000147 SkListWidget::kOffset_IndexStyle);
148 fListWidget.update();
149}
150
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000151void SkDebuggerGUI::showDeletes() {
152 fDeletesActivated = !fDeletesActivated;
153 for (int row = 0; row < fListWidget.count(); row++) {
154 QListWidgetItem *item = fListWidget.item(row);
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000155 item->setHidden(fDebugger.isCommandVisible(row) && fDeletesActivated);
chudy@google.com902ebe52012-06-29 14:21:22 +0000156 }
157}
158
robertphillips92432c72014-07-08 13:07:57 -0700159// The timed picture playback just steps through every operation timing
160// each one individually. Note that each picture should be replayed multiple
161// times (via calls to 'draw') before each command's time is accessed via 'time'.
robertphillipsce4dd3d2014-07-07 13:46:35 -0700162class SkTimedPicturePlayback : public SkPicturePlayback {
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000163public:
scroggo@google.com12705322013-10-01 15:30:46 +0000164
robertphillipsce4dd3d2014-07-07 13:46:35 -0700165 SkTimedPicturePlayback(const SkPicture* picture, const SkTDArray<bool>& deletedCommands)
166 : INHERITED(picture)
bungeman@google.come8cc6e82013-01-17 16:30:56 +0000167 , fSkipCommands(deletedCommands)
168 , fTot(0.0)
169 , fCurCommand(0) {
robertphillips@google.com6d9c92b2013-05-23 13:21:18 +0000170 fTimes.setCount(deletedCommands.count());
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000171 fTypeTimes.setCount(LAST_DRAWTYPE_ENUM+1);
172 this->resetTimes();
173 }
174
robertphillips92432c72014-07-08 13:07:57 -0700175 virtual void draw(SkCanvas* canvas, SkDrawPictureCallback* callback) SK_OVERRIDE {
176 AutoResetOpID aroi(this);
177 SkASSERT(0 == fCurOffset);
178
179 SkReader32 reader(fPictureData->opData()->bytes(), fPictureData->opData()->size());
180
181 // Record this, so we can concat w/ it if we encounter a setMatrix()
182 SkMatrix initialMatrix = canvas->getTotalMatrix();
183
184 SkAutoCanvasRestore acr(canvas, false);
185
186 int opIndex = -1;
187
188 while (!reader.eof()) {
bsalomon49f085d2014-09-05 13:34:00 -0700189 if (callback && callback->abortDrawing()) {
robertphillips92432c72014-07-08 13:07:57 -0700190 return;
191 }
192
193 fCurOffset = reader.offset();
194 uint32_t size;
195 DrawType op = ReadOpAndSize(&reader, &size);
196 if (NOOP == op) {
197 // NOOPs are to be ignored - do not propagate them any further
198 reader.setOffset(fCurOffset + size);
199 continue;
200 }
201
202 opIndex++;
203
204 if (this->preDraw(opIndex, op)) {
205 // This operation is disabled in the debugger's GUI
206 reader.setOffset(fCurOffset + size);
207 continue;
208 }
209
210 this->handleOp(&reader, op, size, canvas, initialMatrix);
211
212 this->postDraw(opIndex);
213 }
214 }
215
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000216 void resetTimes() {
robertphillips@google.com6d9c92b2013-05-23 13:21:18 +0000217 for (int i = 0; i < fTimes.count(); ++i) {
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000218 fTimes[i] = 0.0;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000219 }
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000220 for (int i = 0; i < fTypeTimes.count(); ++i) {
221 fTypeTimes[i] = 0.0f;
222 }
223 fTot = 0.0;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000224 }
225
226 int count() const { return fTimes.count(); }
227
robertphillips92432c72014-07-08 13:07:57 -0700228 // Return the fraction of the total time consumed by the index-th operation
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000229 double time(int index) const { return fTimes[index] / fTot; }
230
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000231 const SkTDArray<double>* typeTimes() const { return &fTypeTimes; }
232
233 double totTime() const { return fTot; }
234
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000235protected:
mtklein9ac68ee2014-06-20 11:29:20 -0700236 SysTimer fTimer;
robertphillips@google.com5f971142012-12-07 20:48:56 +0000237 SkTDArray<bool> fSkipCommands; // has the command been deleted in the GUI?
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000238 SkTDArray<double> fTimes; // sum of time consumed for each command
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000239 SkTDArray<double> fTypeTimes; // sum of time consumed for each type of command (e.g., drawPath)
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000240 double fTot; // total of all times in 'fTimes'
robertphillips92432c72014-07-08 13:07:57 -0700241
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000242 int fCurType;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000243 int fCurCommand; // the current command being executed/timed
244
robertphillips92432c72014-07-08 13:07:57 -0700245 bool preDraw(int opIndex, int type) {
robertphillips@google.com6d9c92b2013-05-23 13:21:18 +0000246 fCurCommand = opIndex;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000247
robertphillips@google.com5f971142012-12-07 20:48:56 +0000248 if (fSkipCommands[fCurCommand]) {
robertphillips@google.com6d9c92b2013-05-23 13:21:18 +0000249 return true;
robertphillips@google.com5f971142012-12-07 20:48:56 +0000250 }
251
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000252 fCurType = type;
253 // The SkDebugCanvas doesn't recognize these types. This class needs to
254 // convert or else we'll wind up with a mismatch between the type counts
255 // the debugger displays and the profile times.
256 if (DRAW_POS_TEXT_TOP_BOTTOM == type) {
257 fCurType = DRAW_POS_TEXT;
258 } else if (DRAW_POS_TEXT_H_TOP_BOTTOM == type) {
259 fCurType = DRAW_POS_TEXT_H;
260 }
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000261
robertphillips@google.come174a8b2012-11-27 16:04:42 +0000262#if defined(SK_BUILD_FOR_WIN32)
263 // CPU timer doesn't work well on Windows
264 fTimer.startWall();
265#else
266 fTimer.startCpu();
267#endif
robertphillips@google.com5f971142012-12-07 20:48:56 +0000268
robertphillips@google.com6d9c92b2013-05-23 13:21:18 +0000269 return false;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000270 }
271
robertphillips92432c72014-07-08 13:07:57 -0700272 void postDraw(int opIndex) {
robertphillips@google.come174a8b2012-11-27 16:04:42 +0000273#if defined(SK_BUILD_FOR_WIN32)
274 // CPU timer doesn't work well on Windows
275 double time = fTimer.endWall();
276#else
277 double time = fTimer.endCpu();
278#endif
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000279
robertphillips@google.com6d9c92b2013-05-23 13:21:18 +0000280 SkASSERT(opIndex == fCurCommand);
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000281 SkASSERT(fCurType <= LAST_DRAWTYPE_ENUM);
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000282
robertphillips@google.come174a8b2012-11-27 16:04:42 +0000283 fTimes[fCurCommand] += time;
284 fTypeTimes[fCurType] += time;
285 fTot += time;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000286 }
287
288private:
robertphillipsce4dd3d2014-07-07 13:46:35 -0700289 typedef SkPicturePlayback INHERITED;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000290};
291
robertphillipsce4dd3d2014-07-07 13:46:35 -0700292#if 0
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000293// Wrap SkPicture to allow installation of an SkTimedPicturePlayback object
294class SkTimedPicture : public SkPicture {
295public:
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000296 static SkTimedPicture* CreateTimedPicture(SkStream* stream,
297 SkPicture::InstallPixelRefProc proc,
298 const SkTDArray<bool>& deletedCommands) {
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000299 SkPictInfo info;
commit-bot@chromium.org6f4fb0f2014-03-03 19:18:39 +0000300 if (!InternalOnly_StreamIsSKP(stream, &info)) {
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000301 return NULL;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000302 }
303
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000304 // Check to see if there is a playback to recreate.
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000305 if (stream->readBool()) {
commit-bot@chromium.org8f831f22014-04-23 22:35:42 +0000306 SkTimedPicturePlayback* playback = SkTimedPicturePlayback::CreateFromStream(
robertphillipse26e65e2014-06-12 05:51:22 -0700307 stream,
commit-bot@chromium.org8f831f22014-04-23 22:35:42 +0000308 info, proc,
scroggo@google.com12705322013-10-01 15:30:46 +0000309 deletedCommands);
310 if (NULL == playback) {
311 return NULL;
312 }
robertphillipse26e65e2014-06-12 05:51:22 -0700313
314 return SkNEW_ARGS(SkTimedPicture, (playback, info.fWidth, info.fHeight));
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000315 }
316
robertphillipse26e65e2014-06-12 05:51:22 -0700317 return NULL;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000318 }
319
robertphillipsdb539902014-07-01 08:47:04 -0700320 void resetTimes() { ((SkTimedPicturePlayback*) fData.get())->resetTimes(); }
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000321
robertphillipsdb539902014-07-01 08:47:04 -0700322 int count() const { return ((SkTimedPicturePlayback*) fData.get())->count(); }
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000323
324 // return the fraction of the total time this command consumed
robertphillipsdb539902014-07-01 08:47:04 -0700325 double time(int index) const { return ((SkTimedPicturePlayback*) fData.get())->time(index); }
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000326
robertphillipsdb539902014-07-01 08:47:04 -0700327 const SkTDArray<double>* typeTimes() const { return ((SkTimedPicturePlayback*) fData.get())->typeTimes(); }
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000328
robertphillipsdb539902014-07-01 08:47:04 -0700329 double totTime() const { return ((SkTimedPicturePlayback*) fData.get())->totTime(); }
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000330
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000331private:
robertphillipsdb539902014-07-01 08:47:04 -0700332 // disallow default ctor b.c. we don't have a good way to setup the fData ptr
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000333 SkTimedPicture();
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000334 // Private ctor only used by CreateTimedPicture, which has created the playback.
335 SkTimedPicture(SkTimedPicturePlayback* playback, int width, int height)
336 : INHERITED(playback, width, height) {}
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000337 // disallow the copy ctor - enabling would require copying code from SkPicture
338 SkTimedPicture(const SkTimedPicture& src);
339
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000340 typedef SkPicture INHERITED;
341};
robertphillipsce4dd3d2014-07-07 13:46:35 -0700342#endif
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000343
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000344// This is a simplification of PictureBenchmark's run with the addition of
345// clearing of the times after the first pass (in resetTimes)
robertphillipsce4dd3d2014-07-07 13:46:35 -0700346void SkDebuggerGUI::run(const SkPicture* pict,
skia.committer@gmail.com34587162012-11-20 02:01:23 +0000347 sk_tools::PictureRenderer* renderer,
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000348 int repeats) {
349 SkASSERT(pict);
350 if (NULL == pict) {
351 return;
352 }
353
354 SkASSERT(renderer != NULL);
355 if (NULL == renderer) {
356 return;
357 }
358
commit-bot@chromium.org3f045172014-05-15 15:10:48 +0000359 renderer->init(pict, NULL, NULL, NULL, false);
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000360
361 renderer->setup();
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000362 renderer->render();
commit-bot@chromium.org51c040e2014-03-11 22:58:00 +0000363 renderer->resetState(true); // flush, swapBuffers and Finish
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000364
robertphillipsce4dd3d2014-07-07 13:46:35 -0700365#if 0
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000366 // We throw this away the first batch of times to remove first time effects (such as paging in this program)
367 pict->resetTimes();
robertphillipsce4dd3d2014-07-07 13:46:35 -0700368#endif
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000369
370 for (int i = 0; i < repeats; ++i) {
371 renderer->setup();
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000372 renderer->render();
commit-bot@chromium.org51c040e2014-03-11 22:58:00 +0000373 renderer->resetState(false); // flush & swapBuffers, but don't Finish
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000374 }
commit-bot@chromium.org51c040e2014-03-11 22:58:00 +0000375 renderer->resetState(true); // flush, swapBuffers and Finish
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000376
377 renderer->end();
378}
379
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000380void SkDebuggerGUI::actionProfile() {
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000381 // In order to profile we pass the command offsets (that were read-in
382 // in loadPicture by the SkOffsetPicture) to an SkTimedPlaybackPicture.
skia.committer@gmail.com884e60b2012-11-16 02:01:17 +0000383 // The SkTimedPlaybackPicture in turn passes the offsets to an
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000384 // SkTimedPicturePlayback object which uses them to track the performance
385 // of individual commands.
386 if (fFileName.isEmpty()) {
387 return;
388 }
389
390 SkFILEStream inputStream;
391
392 inputStream.setPath(fFileName.c_str());
393 if (!inputStream.isValid()) {
394 return;
395 }
396
robertphillipsce4dd3d2014-07-07 13:46:35 -0700397 SkAutoTUnref<SkPicture> picture(SkPicture::CreateFromStream(&inputStream,
398 &SkImageDecoder::DecodeMemory)); // , fSkipCommands));
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000399 if (NULL == picture.get()) {
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000400 return;
401 }
402
robertphillipsce4dd3d2014-07-07 13:46:35 -0700403
404#if 0
405
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000406 // For now this #if allows switching between tiled and simple rendering
407 // modes. Eventually this will be accomplished via the GUI
robertphillips@google.come174a8b2012-11-27 16:04:42 +0000408#if 0
409 // With the current batch of SysTimers, profiling in tiled mode
410 // gets swamped by the timing overhead:
411 //
412 // tile mode simple mode
413 // debugger 64.2ms 12.8ms
414 // bench_pictures 16.9ms 12.4ms
415 //
416 // This is b.c. in tiled mode each command is called many more times
417 // but typically does less work on each invocation (due to clipping)
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000418 sk_tools::TiledPictureRenderer* renderer = NULL;
419
420 renderer = SkNEW(sk_tools::TiledPictureRenderer);
421 renderer->setTileWidth(256);
422 renderer->setTileHeight(256);
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000423#else
424 sk_tools::SimplePictureRenderer* renderer = NULL;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000425
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000426 renderer = SkNEW(sk_tools::SimplePictureRenderer);
robertphillips@google.com1447aa32013-01-30 21:09:09 +0000427
428#if SK_SUPPORT_GPU
commit-bot@chromium.orgfde1e7c2013-08-02 13:59:50 +0000429 if (fSettingsWidget.isGLActive()) {
robertphillips@google.com1447aa32013-01-30 21:09:09 +0000430 renderer->setDeviceType(sk_tools::PictureRenderer::kGPU_DeviceType);
commit-bot@chromium.orgfde1e7c2013-08-02 13:59:50 +0000431 renderer->setSampleCount(fSettingsWidget.getGLSampleCount());
robertphillips@google.com1447aa32013-01-30 21:09:09 +0000432 }
433#endif
434
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000435#endif
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000436
robertphillips@google.come174a8b2012-11-27 16:04:42 +0000437 static const int kNumRepeats = 10;
438
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000439 run(picture.get(), renderer, kNumRepeats);
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000440
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000441 SkASSERT(picture->count() == fListWidget.count());
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000442
443 // extract the individual command times from the SkTimedPlaybackPicture
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000444 for (int i = 0; i < picture->count(); ++i) {
445 double temp = picture->time(i);
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000446
447 QListWidgetItem* item = fListWidget.item(i);
448
449 item->setData(Qt::UserRole + 4, 100.0*temp);
450 }
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000451
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000452 setupOverviewText(picture->typeTimes(), picture->totTime(), kNumRepeats);
commit-bot@chromium.org2a67e122014-05-19 13:53:10 +0000453 setupClipStackText();
robertphillipsce4dd3d2014-07-07 13:46:35 -0700454
455#endif
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000456}
457
chudy@google.com902ebe52012-06-29 14:21:22 +0000458void SkDebuggerGUI::actionCancel() {
chudy@google.comc432f002012-07-10 13:19:25 +0000459 for (int row = 0; row < fListWidget.count(); row++) {
460 fListWidget.item(row)->setHidden(false);
chudy@google.com902ebe52012-06-29 14:21:22 +0000461 }
462}
463
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000464void SkDebuggerGUI::actionClearBreakpoints() {
465 for (int row = 0; row < fListWidget.count(); row++) {
466 QListWidgetItem* item = fListWidget.item(row);
467 item->setCheckState(Qt::Unchecked);
468 item->setData(Qt::DecorationRole,
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000469 QPixmap(":/blank.png"));
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000470 }
471}
472
473void SkDebuggerGUI::actionClearDeletes() {
474 for (int row = 0; row < fListWidget.count(); row++) {
475 QListWidgetItem* item = fListWidget.item(row);
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000476 item->setData(Qt::UserRole + 2, QPixmap(":/blank.png"));
chudy@google.com607357f2012-08-07 16:12:23 +0000477 fDebugger.setCommandVisible(row, true);
robertphillips@google.com5f971142012-12-07 20:48:56 +0000478 fSkipCommands[row] = false;
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000479 }
480 if (fPause) {
481 fCanvasWidget.drawTo(fPausedRow);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000482 fImageWidget.draw();
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000483 } else {
484 fCanvasWidget.drawTo(fListWidget.currentRow());
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000485 fImageWidget.draw();
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000486 }
487}
488
chudy@google.com902ebe52012-06-29 14:21:22 +0000489void SkDebuggerGUI::actionCommandFilter() {
commit-bot@chromium.org22d39332013-11-21 15:37:29 +0000490 fDebugger.highlightCurrentCommand(fSettingsWidget.getVisibilityFilter());
chudy@google.comc432f002012-07-10 13:19:25 +0000491 fCanvasWidget.drawTo(fListWidget.currentRow());
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000492 fImageWidget.draw();
chudy@google.com902ebe52012-06-29 14:21:22 +0000493}
494
495void SkDebuggerGUI::actionClose() {
496 this->close();
497}
498
499void SkDebuggerGUI::actionDelete() {
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000500
robertphillips@google.comdd4b7452013-01-22 19:38:46 +0000501 for (int row = 0; row < fListWidget.count(); ++row) {
502 QListWidgetItem* item = fListWidget.item(row);
503
504 if (!item->isSelected()) {
505 continue;
506 }
507
508 if (fDebugger.isCommandVisible(row)) {
509 item->setData(Qt::UserRole + 2, QPixmap(":/delete.png"));
510 fDebugger.setCommandVisible(row, false);
511 fSkipCommands[row] = true;
512 } else {
513 item->setData(Qt::UserRole + 2, QPixmap(":/blank.png"));
514 fDebugger.setCommandVisible(row, true);
515 fSkipCommands[row] = false;
516 }
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000517 }
518
robertphillips@google.comdd4b7452013-01-22 19:38:46 +0000519 int currentRow = fListWidget.currentRow();
520
chudy@google.come504de02012-07-16 18:35:23 +0000521 if (fPause) {
522 fCanvasWidget.drawTo(fPausedRow);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000523 fImageWidget.draw();
chudy@google.come504de02012-07-16 18:35:23 +0000524 } else {
525 fCanvasWidget.drawTo(currentRow);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000526 fImageWidget.draw();
chudy@google.come504de02012-07-16 18:35:23 +0000527 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000528}
529
robertphillips@google.come8fe4bc2013-02-13 13:26:13 +0000530#if SK_SUPPORT_GPU
commit-bot@chromium.orgfde1e7c2013-08-02 13:59:50 +0000531void SkDebuggerGUI::actionGLWidget() {
532 bool isToggled = fSettingsWidget.isGLActive();
533 if (isToggled) {
534 fCanvasWidget.setGLSampleCount(fSettingsWidget.getGLSampleCount());
535 }
chudy@google.comea5488b2012-07-26 19:38:22 +0000536 fCanvasWidget.setWidgetVisibility(SkCanvasWidget::kGPU_WidgetType, !isToggled);
537}
robertphillips@google.come8fe4bc2013-02-13 13:26:13 +0000538#endif
chudy@google.comea5488b2012-07-26 19:38:22 +0000539
chudy@google.com902ebe52012-06-29 14:21:22 +0000540void SkDebuggerGUI::actionInspector() {
chudy@google.comc432f002012-07-10 13:19:25 +0000541 if (fInspectorWidget.isHidden()) {
542 fInspectorWidget.setHidden(false);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000543 fImageWidget.setHidden(false);
chudy@google.com902ebe52012-06-29 14:21:22 +0000544 } else {
chudy@google.comc432f002012-07-10 13:19:25 +0000545 fInspectorWidget.setHidden(true);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000546 fImageWidget.setHidden(true);
chudy@google.com902ebe52012-06-29 14:21:22 +0000547 }
548}
549
550void SkDebuggerGUI::actionPlay() {
chudy@google.comc432f002012-07-10 13:19:25 +0000551 for (int row = fListWidget.currentRow() + 1; row < fListWidget.count();
chudy@google.com7dcae672012-07-09 20:26:53 +0000552 row++) {
chudy@google.comc432f002012-07-10 13:19:25 +0000553 QListWidgetItem *item = fListWidget.item(row);
chudy@google.com902ebe52012-06-29 14:21:22 +0000554 if (item->checkState() == Qt::Checked) {
chudy@google.comc432f002012-07-10 13:19:25 +0000555 fListWidget.setCurrentItem(item);
chudy@google.com902ebe52012-06-29 14:21:22 +0000556 return;
557 }
558 }
chudy@google.comc432f002012-07-10 13:19:25 +0000559 fListWidget.setCurrentRow(fListWidget.count() - 1);
chudy@google.com902ebe52012-06-29 14:21:22 +0000560}
561
chudy@google.comea5488b2012-07-26 19:38:22 +0000562void SkDebuggerGUI::actionRasterWidget(bool isToggled) {
563 fCanvasWidget.setWidgetVisibility(SkCanvasWidget::kRaster_8888_WidgetType, !isToggled);
564}
565
robertphillips@google.comf4741c12013-02-06 20:13:54 +0000566void SkDebuggerGUI::actionOverdrawVizWidget(bool isToggled) {
567 fDebugger.setOverdrawViz(isToggled);
568 fCanvasWidget.update();
569}
570
commit-bot@chromium.org768ac852014-03-03 16:32:17 +0000571void SkDebuggerGUI::actionMegaVizWidget(bool isToggled) {
572 fDebugger.setMegaViz(isToggled);
573 fCanvasWidget.update();
574}
575
commit-bot@chromium.org2a67e122014-05-19 13:53:10 +0000576void SkDebuggerGUI::actionPathOpsWidget(bool isToggled) {
577 fDebugger.setPathOps(isToggled);
578 fCanvasWidget.update();
579}
580
robertphillips@google.com32bbcf82013-10-17 17:56:10 +0000581void SkDebuggerGUI::actionTextureFilter() {
582 SkPaint::FilterLevel level;
583 bool enabled = fSettingsWidget.getFilterOverride(&level);
584 fDebugger.setTexFilterOverride(enabled, level);
585 fCanvasWidget.update();
586}
587
chudy@google.com902ebe52012-06-29 14:21:22 +0000588void SkDebuggerGUI::actionRewind() {
chudy@google.come504de02012-07-16 18:35:23 +0000589 fListWidget.setCurrentRow(0);
chudy@google.com902ebe52012-06-29 14:21:22 +0000590}
591
chudy@google.com0ab03392012-07-28 20:16:11 +0000592void SkDebuggerGUI::actionSave() {
robertphillips@google.come219baf2013-01-28 19:25:43 +0000593 fFileName = fPath.toAscii().data();
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000594 fFileName.append("/");
robertphillips@google.come219baf2013-01-28 19:25:43 +0000595 fFileName.append(fDirectoryWidget.currentItem()->text().toAscii().data());
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000596 saveToFile(fFileName);
chudy@google.com0ab03392012-07-28 20:16:11 +0000597}
598
599void SkDebuggerGUI::actionSaveAs() {
600 QString filename = QFileDialog::getSaveFileName(this, "Save File", "",
601 "Skia Picture (*skp)");
chudy@google.com38b08ce2012-07-28 23:26:10 +0000602 if (!filename.endsWith(".skp", Qt::CaseInsensitive)) {
chudy@google.com0ab03392012-07-28 20:16:11 +0000603 filename.append(".skp");
604 }
djsollen@google.comc3c82162012-11-13 18:35:10 +0000605 saveToFile(SkString(filename.toAscii().data()));
chudy@google.com0ab03392012-07-28 20:16:11 +0000606}
607
chudy@google.com7dcae672012-07-09 20:26:53 +0000608void SkDebuggerGUI::actionScale(float scaleFactor) {
chudy@google.comc432f002012-07-10 13:19:25 +0000609 fSettingsWidget.setZoomText(scaleFactor);
chudy@google.com7dcae672012-07-09 20:26:53 +0000610}
611
chudy@google.com902ebe52012-06-29 14:21:22 +0000612void SkDebuggerGUI::actionSettings() {
chudy@google.comc432f002012-07-10 13:19:25 +0000613 if (fSettingsWidget.isHidden()) {
614 fSettingsWidget.setHidden(false);
chudy@google.com902ebe52012-06-29 14:21:22 +0000615 } else {
chudy@google.comc432f002012-07-10 13:19:25 +0000616 fSettingsWidget.setHidden(true);
chudy@google.com902ebe52012-06-29 14:21:22 +0000617 }
618}
619
620void SkDebuggerGUI::actionStepBack() {
chudy@google.comc432f002012-07-10 13:19:25 +0000621 int currentRow = fListWidget.currentRow();
chudy@google.com902ebe52012-06-29 14:21:22 +0000622 if (currentRow != 0) {
chudy@google.comc432f002012-07-10 13:19:25 +0000623 fListWidget.setCurrentRow(currentRow - 1);
chudy@google.com902ebe52012-06-29 14:21:22 +0000624 }
625}
626
627void SkDebuggerGUI::actionStepForward() {
chudy@google.comc432f002012-07-10 13:19:25 +0000628 int currentRow = fListWidget.currentRow();
chudy@google.com902ebe52012-06-29 14:21:22 +0000629 QString curRow = QString::number(currentRow);
chudy@google.comc432f002012-07-10 13:19:25 +0000630 QString curCount = QString::number(fListWidget.count());
631 if (currentRow < fListWidget.count() - 1) {
632 fListWidget.setCurrentRow(currentRow + 1);
chudy@google.com902ebe52012-06-29 14:21:22 +0000633 }
634}
635
chudy@google.coma9e937c2012-08-03 17:32:05 +0000636void SkDebuggerGUI::drawComplete() {
chudy@google.com607357f2012-08-07 16:12:23 +0000637 fInspectorWidget.setMatrix(fDebugger.getCurrentMatrix());
638 fInspectorWidget.setClip(fDebugger.getCurrentClip());
chudy@google.coma9e937c2012-08-03 17:32:05 +0000639}
640
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000641void SkDebuggerGUI::saveToFile(const SkString& filename) {
642 SkFILEWStream file(filename.c_str());
robertphillips@google.com25bc2f82013-01-22 18:03:56 +0000643 SkAutoTUnref<SkPicture> copy(fDebugger.copyPicture());
644
645 copy->serialize(&file);
chudy@google.com0ab03392012-07-28 20:16:11 +0000646}
647
chudy@google.com902ebe52012-06-29 14:21:22 +0000648void SkDebuggerGUI::loadFile(QListWidgetItem *item) {
649 if (fDirectoryWidgetActive) {
robertphillips@google.come219baf2013-01-28 19:25:43 +0000650 fFileName = fPath.toAscii().data();
jvanverth@google.com0ac6f162013-02-05 19:44:07 +0000651 // don't add a '/' to files in the local directory
652 if (fFileName.size() > 0) {
653 fFileName.append("/");
654 }
robertphillips@google.come219baf2013-01-28 19:25:43 +0000655 fFileName.append(item->text().toAscii().data());
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000656 loadPicture(fFileName);
chudy@google.com902ebe52012-06-29 14:21:22 +0000657 }
658}
659
660void SkDebuggerGUI::openFile() {
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000661 QString temp = QFileDialog::getOpenFileName(this, tr("Open File"), "",
chudy@google.com7dcae672012-07-09 20:26:53 +0000662 tr("Files (*.*)"));
robertphillips@google.comff6e6ba2013-01-28 17:43:26 +0000663 openFile(temp);
664}
665
666void SkDebuggerGUI::openFile(const QString &filename) {
chudy@google.com902ebe52012-06-29 14:21:22 +0000667 fDirectoryWidgetActive = false;
robertphillips@google.comff6e6ba2013-01-28 17:43:26 +0000668 if (!filename.isEmpty()) {
669 QFileInfo pathInfo(filename);
670 loadPicture(SkString(filename.toAscii().data()));
671 setupDirectoryWidget(pathInfo.path());
chudy@google.com902ebe52012-06-29 14:21:22 +0000672 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000673 fDirectoryWidgetActive = true;
674}
675
chudy@google.comc432f002012-07-10 13:19:25 +0000676void SkDebuggerGUI::pauseDrawing(bool isPaused) {
chudy@google.com607357f2012-08-07 16:12:23 +0000677 fPause = isPaused;
678 fPausedRow = fListWidget.currentRow();
679 fCanvasWidget.drawTo(fPausedRow);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000680 fImageWidget.draw();
chudy@google.com7dcae672012-07-09 20:26:53 +0000681}
682
chudy@google.com902ebe52012-06-29 14:21:22 +0000683void SkDebuggerGUI::registerListClick(QListWidgetItem *item) {
chudy@google.comd3058f52012-07-19 13:41:27 +0000684 if(!fLoading) {
685 int currentRow = fListWidget.currentRow();
chudy@google.comd3058f52012-07-19 13:41:27 +0000686
chudy@google.comea5488b2012-07-26 19:38:22 +0000687 if (currentRow != -1) {
688 if (!fPause) {
689 fCanvasWidget.drawTo(currentRow);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000690 fImageWidget.draw();
chudy@google.comd3058f52012-07-19 13:41:27 +0000691 }
chudy@google.com97cee972012-08-07 20:41:37 +0000692 SkTDArray<SkString*> *currInfo = fDebugger.getCommandInfo(
chudy@google.comea5488b2012-07-26 19:38:22 +0000693 currentRow);
694
695 /* TODO(chudy): Add command type before parameters. Rename v
696 * to something more informative. */
chudy@google.com97cee972012-08-07 20:41:37 +0000697 if (currInfo) {
chudy@google.comea5488b2012-07-26 19:38:22 +0000698 QString info;
699 info.append("<b>Parameters: </b><br/>");
chudy@google.com97cee972012-08-07 20:41:37 +0000700 for (int i = 0; i < currInfo->count(); i++) {
701
702 info.append(QString((*currInfo)[i]->c_str()));
chudy@google.comea5488b2012-07-26 19:38:22 +0000703 info.append("<br/>");
704 }
chudy@google.com6bd109a2012-08-14 19:34:13 +0000705 fInspectorWidget.setText(info, SkInspectorWidget::kDetail_TabType);
chudy@google.comea5488b2012-07-26 19:38:22 +0000706 fInspectorWidget.setDisabled(false);
chudy@google.comea5488b2012-07-26 19:38:22 +0000707 }
commit-bot@chromium.org2a67e122014-05-19 13:53:10 +0000708 setupClipStackText();
chudy@google.comd3058f52012-07-19 13:41:27 +0000709 }
chudy@google.comea5488b2012-07-26 19:38:22 +0000710
chudy@google.com902ebe52012-06-29 14:21:22 +0000711 }
712}
713
chudy@google.com9ca9bfe2012-07-12 21:58:14 +0000714void SkDebuggerGUI::selectCommand(int command) {
715 if (fPause) {
716 fListWidget.setCurrentRow(command);
717 }
718}
719
chudy@google.com902ebe52012-06-29 14:21:22 +0000720void SkDebuggerGUI::toggleBreakpoint() {
chudy@google.comc432f002012-07-10 13:19:25 +0000721 QListWidgetItem* item = fListWidget.currentItem();
chudy@google.com902ebe52012-06-29 14:21:22 +0000722 if (item->checkState() == Qt::Unchecked) {
723 item->setCheckState(Qt::Checked);
chudy@google.come565de42012-07-12 14:15:54 +0000724 item->setData(Qt::DecorationRole,
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000725 QPixmap(":/breakpoint_16x16.png"));
chudy@google.com902ebe52012-06-29 14:21:22 +0000726 } else {
chudy@google.com902ebe52012-06-29 14:21:22 +0000727 item->setCheckState(Qt::Unchecked);
chudy@google.come565de42012-07-12 14:15:54 +0000728 item->setData(Qt::DecorationRole,
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000729 QPixmap(":/blank.png"));
chudy@google.com902ebe52012-06-29 14:21:22 +0000730 }
731}
732
733void SkDebuggerGUI::toggleDirectory() {
chudy@google.com607357f2012-08-07 16:12:23 +0000734 fDirectoryWidget.setHidden(!fDirectoryWidget.isHidden());
chudy@google.com902ebe52012-06-29 14:21:22 +0000735}
736
737void SkDebuggerGUI::toggleFilter(QString string) {
chudy@google.comc432f002012-07-10 13:19:25 +0000738 for (int row = 0; row < fListWidget.count(); row++) {
739 QListWidgetItem *item = fListWidget.item(row);
chudy@google.com607357f2012-08-07 16:12:23 +0000740 item->setHidden(item->text() != string);
chudy@google.com902ebe52012-06-29 14:21:22 +0000741 }
742}
743
744void SkDebuggerGUI::setupUi(QMainWindow *SkDebuggerGUI) {
745 QIcon windowIcon;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000746 windowIcon.addFile(QString::fromUtf8(":/skia.png"), QSize(),
chudy@google.com7dcae672012-07-09 20:26:53 +0000747 QIcon::Normal, QIcon::Off);
chudy@google.com902ebe52012-06-29 14:21:22 +0000748 SkDebuggerGUI->setObjectName(QString::fromUtf8("SkDebuggerGUI"));
749 SkDebuggerGUI->resize(1200, 1000);
750 SkDebuggerGUI->setWindowIcon(windowIcon);
chudy@google.comc432f002012-07-10 13:19:25 +0000751 SkDebuggerGUI->setWindowTitle("Skia Debugger");
chudy@google.com902ebe52012-06-29 14:21:22 +0000752
chudy@google.come504de02012-07-16 18:35:23 +0000753 fActionOpen.setShortcuts(QKeySequence::Open);
chudy@google.comc432f002012-07-10 13:19:25 +0000754 fActionOpen.setText("Open");
chudy@google.com902ebe52012-06-29 14:21:22 +0000755
756 QIcon breakpoint;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000757 breakpoint.addFile(QString::fromUtf8(":/breakpoint.png"),
chudy@google.com7dcae672012-07-09 20:26:53 +0000758 QSize(), QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000759 fActionBreakpoint.setShortcut(QKeySequence(tr("Ctrl+B")));
chudy@google.comc432f002012-07-10 13:19:25 +0000760 fActionBreakpoint.setIcon(breakpoint);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000761 fActionBreakpoint.setText("Breakpoints");
chudy@google.com902ebe52012-06-29 14:21:22 +0000762
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000763 fActionToggleIndexStyle.setShortcut(QKeySequence(tr("Ctrl+T")));
764 fActionToggleIndexStyle.setText("Toggle Index Style");
765
chudy@google.com902ebe52012-06-29 14:21:22 +0000766 QIcon cancel;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000767 cancel.addFile(QString::fromUtf8(":/reload.png"), QSize(),
chudy@google.com7dcae672012-07-09 20:26:53 +0000768 QIcon::Normal, QIcon::Off);
chudy@google.comc432f002012-07-10 13:19:25 +0000769 fActionCancel.setIcon(cancel);
770 fActionCancel.setText("Clear Filter");
chudy@google.com902ebe52012-06-29 14:21:22 +0000771
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000772 fActionClearBreakpoints.setShortcut(QKeySequence(tr("Alt+B")));
773 fActionClearBreakpoints.setText("Clear Breakpoints");
774
775 fActionClearDeletes.setShortcut(QKeySequence(tr("Alt+X")));
776 fActionClearDeletes.setText("Clear Deletes");
777
chudy@google.come504de02012-07-16 18:35:23 +0000778 fActionClose.setShortcuts(QKeySequence::Quit);
chudy@google.comc432f002012-07-10 13:19:25 +0000779 fActionClose.setText("Exit");
chudy@google.com902ebe52012-06-29 14:21:22 +0000780
chudy@google.come504de02012-07-16 18:35:23 +0000781 fActionCreateBreakpoint.setShortcut(QKeySequence(tr("B")));
782 fActionCreateBreakpoint.setText("Set Breakpoint");
783
784 fActionDelete.setShortcut(QKeySequence(tr("X")));
chudy@google.comc432f002012-07-10 13:19:25 +0000785 fActionDelete.setText("Delete Command");
chudy@google.com902ebe52012-06-29 14:21:22 +0000786
chudy@google.come504de02012-07-16 18:35:23 +0000787 fActionDirectory.setShortcut(QKeySequence(tr("Ctrl+D")));
788 fActionDirectory.setText("Directory");
chudy@google.com902ebe52012-06-29 14:21:22 +0000789
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000790 QIcon profile;
robertphillips@google.comd1636362012-11-19 18:25:09 +0000791 profile.addFile(QString::fromUtf8(":/profile.png"), QSize(),
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000792 QIcon::Normal, QIcon::Off);
793 fActionProfile.setIcon(profile);
794 fActionProfile.setText("Profile");
robertphillips@google.come099bc42012-11-19 16:26:40 +0000795 fActionProfile.setDisabled(true);
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000796
chudy@google.comc432f002012-07-10 13:19:25 +0000797 QIcon inspector;
robertphillips@google.comd1636362012-11-19 18:25:09 +0000798 inspector.addFile(QString::fromUtf8(":/inspector.png"),
chudy@google.comc432f002012-07-10 13:19:25 +0000799 QSize(), QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000800 fActionInspector.setShortcut(QKeySequence(tr("Ctrl+I")));
chudy@google.comc432f002012-07-10 13:19:25 +0000801 fActionInspector.setIcon(inspector);
chudy@google.come504de02012-07-16 18:35:23 +0000802 fActionInspector.setText("Inspector");
chudy@google.com902ebe52012-06-29 14:21:22 +0000803
bungeman@google.com2ff6d1d2013-07-01 14:24:12 +0000804 QIcon settings;
805 settings.addFile(QString::fromUtf8(":/inspector.png"),
806 QSize(), QIcon::Normal, QIcon::Off);
807 fActionSettings.setShortcut(QKeySequence(tr("Ctrl+G")));
808 fActionSettings.setIcon(settings);
809 fActionSettings.setText("Settings");
skia.committer@gmail.com0d55dd72013-07-02 07:00:59 +0000810
chudy@google.comc432f002012-07-10 13:19:25 +0000811 QIcon play;
robertphillips@google.comd1636362012-11-19 18:25:09 +0000812 play.addFile(QString::fromUtf8(":/play.png"), QSize(),
chudy@google.comc432f002012-07-10 13:19:25 +0000813 QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000814 fActionPlay.setShortcut(QKeySequence(tr("Ctrl+P")));
chudy@google.comc432f002012-07-10 13:19:25 +0000815 fActionPlay.setIcon(play);
816 fActionPlay.setText("Play");
chudy@google.com902ebe52012-06-29 14:21:22 +0000817
chudy@google.come504de02012-07-16 18:35:23 +0000818 QIcon pause;
robertphillips@google.comd1636362012-11-19 18:25:09 +0000819 pause.addFile(QString::fromUtf8(":/pause.png"), QSize(),
chudy@google.comc432f002012-07-10 13:19:25 +0000820 QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000821 fActionPause.setShortcut(QKeySequence(tr("Space")));
822 fActionPause.setCheckable(true);
823 fActionPause.setIcon(pause);
824 fActionPause.setText("Pause");
825
chudy@google.comc432f002012-07-10 13:19:25 +0000826 QIcon rewind;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000827 rewind.addFile(QString::fromUtf8(":/rewind.png"), QSize(),
chudy@google.comc432f002012-07-10 13:19:25 +0000828 QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000829 fActionRewind.setShortcut(QKeySequence(tr("Ctrl+R")));
chudy@google.comc432f002012-07-10 13:19:25 +0000830 fActionRewind.setIcon(rewind);
831 fActionRewind.setText("Rewind");
chudy@google.com902ebe52012-06-29 14:21:22 +0000832
chudy@google.com0ab03392012-07-28 20:16:11 +0000833 fActionSave.setShortcut(QKeySequence::Save);
834 fActionSave.setText("Save");
835 fActionSave.setDisabled(true);
836 fActionSaveAs.setShortcut(QKeySequence::SaveAs);
837 fActionSaveAs.setText("Save As");
838 fActionSaveAs.setDisabled(true);
839
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000840 fActionShowDeletes.setShortcut(QKeySequence(tr("Ctrl+X")));
841 fActionShowDeletes.setText("Deleted Commands");
842
chudy@google.comc432f002012-07-10 13:19:25 +0000843 QIcon stepBack;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000844 stepBack.addFile(QString::fromUtf8(":/previous.png"), QSize(),
chudy@google.comc432f002012-07-10 13:19:25 +0000845 QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000846 fActionStepBack.setShortcut(QKeySequence(tr("[")));
chudy@google.comc432f002012-07-10 13:19:25 +0000847 fActionStepBack.setIcon(stepBack);
848 fActionStepBack.setText("Step Back");
chudy@google.com902ebe52012-06-29 14:21:22 +0000849
chudy@google.comc432f002012-07-10 13:19:25 +0000850 QIcon stepForward;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000851 stepForward.addFile(QString::fromUtf8(":/next.png"),
chudy@google.comc432f002012-07-10 13:19:25 +0000852 QSize(), QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000853 fActionStepForward.setShortcut(QKeySequence(tr("]")));
chudy@google.comc432f002012-07-10 13:19:25 +0000854 fActionStepForward.setIcon(stepForward);
855 fActionStepForward.setText("Step Forward");
856
chudy@google.coma1226312012-07-26 20:26:44 +0000857 fActionZoomIn.setShortcut(QKeySequence(tr("Ctrl+=")));
858 fActionZoomIn.setText("Zoom In");
859 fActionZoomOut.setShortcut(QKeySequence(tr("Ctrl+-")));
860 fActionZoomOut.setText("Zoom Out");
861
chudy@google.comc432f002012-07-10 13:19:25 +0000862 fListWidget.setItemDelegate(new SkListWidget(&fListWidget));
863 fListWidget.setObjectName(QString::fromUtf8("listWidget"));
commit-bot@chromium.orgbcd431e2013-11-21 13:41:37 +0000864 fListWidget.setMinimumWidth(250);
chudy@google.comc432f002012-07-10 13:19:25 +0000865
866 fFilter.addItem("--Filter By Available Commands--");
867
commit-bot@chromium.orgbcd431e2013-11-21 13:41:37 +0000868 fDirectoryWidget.setMinimumWidth(250);
chudy@google.comc432f002012-07-10 13:19:25 +0000869 fDirectoryWidget.setStyleSheet("QListWidget::Item {padding: 5px;}");
870
871 fCanvasWidget.setSizePolicy(QSizePolicy::Expanding,
chudy@google.com7dcae672012-07-09 20:26:53 +0000872 QSizePolicy::Expanding);
chudy@google.com902ebe52012-06-29 14:21:22 +0000873
skia.committer@gmail.com1c9c0d32012-11-22 02:02:41 +0000874 fImageWidget.setFixedSize(SkImageWidget::kImageWidgetWidth,
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000875 SkImageWidget::kImageWidgetHeight);
876
chudy@google.comc432f002012-07-10 13:19:25 +0000877 fInspectorWidget.setSizePolicy(QSizePolicy::Expanding,
chudy@google.com7dcae672012-07-09 20:26:53 +0000878 QSizePolicy::Expanding);
chudy@google.comc432f002012-07-10 13:19:25 +0000879 fInspectorWidget.setMaximumHeight(300);
chudy@google.com902ebe52012-06-29 14:21:22 +0000880
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000881 fSettingsAndImageLayout.setSpacing(6);
882 fSettingsAndImageLayout.addWidget(&fSettingsWidget);
883 fSettingsAndImageLayout.addWidget(&fImageWidget);
884
chudy@google.comc432f002012-07-10 13:19:25 +0000885 fSettingsWidget.setSizePolicy(QSizePolicy::Expanding,
886 QSizePolicy::Expanding);
887 fSettingsWidget.setMaximumWidth(250);
chudy@google.com902ebe52012-06-29 14:21:22 +0000888
commit-bot@chromium.orgbcd431e2013-11-21 13:41:37 +0000889 fLeftColumnSplitter.addWidget(&fListWidget);
890 fLeftColumnSplitter.addWidget(&fDirectoryWidget);
891 fLeftColumnSplitter.setOrientation(Qt::Vertical);
chudy@google.com902ebe52012-06-29 14:21:22 +0000892
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000893 fCanvasSettingsAndImageLayout.setSpacing(6);
894 fCanvasSettingsAndImageLayout.addWidget(&fCanvasWidget);
895 fCanvasSettingsAndImageLayout.addLayout(&fSettingsAndImageLayout);
896
chudy@google.comc432f002012-07-10 13:19:25 +0000897 fMainAndRightColumnLayout.setSpacing(6);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000898 fMainAndRightColumnLayout.addLayout(&fCanvasSettingsAndImageLayout);
chudy@google.comc432f002012-07-10 13:19:25 +0000899 fMainAndRightColumnLayout.addWidget(&fInspectorWidget);
commit-bot@chromium.orgbcd431e2013-11-21 13:41:37 +0000900 fMainAndRightColumnWidget.setLayout(&fMainAndRightColumnLayout);
chudy@google.com902ebe52012-06-29 14:21:22 +0000901
commit-bot@chromium.orgbcd431e2013-11-21 13:41:37 +0000902 fCentralSplitter.addWidget(&fLeftColumnSplitter);
903 fCentralSplitter.addWidget(&fMainAndRightColumnWidget);
904 fCentralSplitter.setStretchFactor(0, 0);
905 fCentralSplitter.setStretchFactor(1, 1);
chudy@google.comc432f002012-07-10 13:19:25 +0000906
commit-bot@chromium.orgbcd431e2013-11-21 13:41:37 +0000907 SkDebuggerGUI->setCentralWidget(&fCentralSplitter);
chudy@google.comc432f002012-07-10 13:19:25 +0000908 SkDebuggerGUI->setStatusBar(&fStatusBar);
909
chudy@google.come504de02012-07-16 18:35:23 +0000910 fToolBar.setIconSize(QSize(32, 32));
chudy@google.comc432f002012-07-10 13:19:25 +0000911 fToolBar.setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
912 SkDebuggerGUI->addToolBar(Qt::TopToolBarArea, &fToolBar);
chudy@google.com902ebe52012-06-29 14:21:22 +0000913
chudy@google.com0ab03392012-07-28 20:16:11 +0000914 fSpacer.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
chudy@google.com902ebe52012-06-29 14:21:22 +0000915
chudy@google.comc432f002012-07-10 13:19:25 +0000916 fToolBar.addAction(&fActionRewind);
917 fToolBar.addAction(&fActionStepBack);
chudy@google.come504de02012-07-16 18:35:23 +0000918 fToolBar.addAction(&fActionPause);
chudy@google.comc432f002012-07-10 13:19:25 +0000919 fToolBar.addAction(&fActionStepForward);
920 fToolBar.addAction(&fActionPlay);
921 fToolBar.addSeparator();
chudy@google.come504de02012-07-16 18:35:23 +0000922 fToolBar.addAction(&fActionInspector);
bungeman@google.com2ff6d1d2013-07-01 14:24:12 +0000923 fToolBar.addAction(&fActionSettings);
chudy@google.comc432f002012-07-10 13:19:25 +0000924 fToolBar.addSeparator();
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000925 fToolBar.addAction(&fActionProfile);
926
927 fToolBar.addSeparator();
chudy@google.com0ab03392012-07-28 20:16:11 +0000928 fToolBar.addWidget(&fSpacer);
chudy@google.comc432f002012-07-10 13:19:25 +0000929 fToolBar.addWidget(&fFilter);
930 fToolBar.addAction(&fActionCancel);
chudy@google.com902ebe52012-06-29 14:21:22 +0000931
932 // TODO(chudy): Remove static call.
933 fDirectoryWidgetActive = false;
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000934 fFileName = "";
robertphillips@google.comff6e6ba2013-01-28 17:43:26 +0000935 setupDirectoryWidget("");
chudy@google.com902ebe52012-06-29 14:21:22 +0000936 fDirectoryWidgetActive = true;
937
chudy@google.com902ebe52012-06-29 14:21:22 +0000938 // Menu Bar
chudy@google.comc432f002012-07-10 13:19:25 +0000939 fMenuFile.setTitle("File");
940 fMenuFile.addAction(&fActionOpen);
chudy@google.com0ab03392012-07-28 20:16:11 +0000941 fMenuFile.addAction(&fActionSave);
942 fMenuFile.addAction(&fActionSaveAs);
chudy@google.comc432f002012-07-10 13:19:25 +0000943 fMenuFile.addAction(&fActionClose);
chudy@google.come504de02012-07-16 18:35:23 +0000944
945 fMenuEdit.setTitle("Edit");
946 fMenuEdit.addAction(&fActionDelete);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000947 fMenuEdit.addAction(&fActionClearDeletes);
948 fMenuEdit.addSeparator();
chudy@google.come504de02012-07-16 18:35:23 +0000949 fMenuEdit.addAction(&fActionCreateBreakpoint);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000950 fMenuEdit.addAction(&fActionClearBreakpoints);
chudy@google.come504de02012-07-16 18:35:23 +0000951
chudy@google.comc432f002012-07-10 13:19:25 +0000952 fMenuNavigate.setTitle("Navigate");
chudy@google.come504de02012-07-16 18:35:23 +0000953 fMenuNavigate.addAction(&fActionRewind);
954 fMenuNavigate.addAction(&fActionStepBack);
955 fMenuNavigate.addAction(&fActionStepForward);
956 fMenuNavigate.addAction(&fActionPlay);
957 fMenuNavigate.addAction(&fActionPause);
chudy@google.comc432f002012-07-10 13:19:25 +0000958 fMenuNavigate.addAction(&fActionGoToLine);
chudy@google.come504de02012-07-16 18:35:23 +0000959
chudy@google.comc432f002012-07-10 13:19:25 +0000960 fMenuView.setTitle("View");
chudy@google.come504de02012-07-16 18:35:23 +0000961 fMenuView.addAction(&fActionBreakpoint);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000962 fMenuView.addAction(&fActionShowDeletes);
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000963 fMenuView.addAction(&fActionToggleIndexStyle);
chudy@google.coma1226312012-07-26 20:26:44 +0000964 fMenuView.addAction(&fActionZoomIn);
965 fMenuView.addAction(&fActionZoomOut);
chudy@google.come504de02012-07-16 18:35:23 +0000966
967 fMenuWindows.setTitle("Window");
968 fMenuWindows.addAction(&fActionInspector);
bungeman@google.com2ff6d1d2013-07-01 14:24:12 +0000969 fMenuWindows.addAction(&fActionSettings);
chudy@google.come504de02012-07-16 18:35:23 +0000970 fMenuWindows.addAction(&fActionDirectory);
chudy@google.comc432f002012-07-10 13:19:25 +0000971
972 fActionGoToLine.setText("Go to Line...");
973 fActionGoToLine.setDisabled(true);
974 fMenuBar.addAction(fMenuFile.menuAction());
chudy@google.come504de02012-07-16 18:35:23 +0000975 fMenuBar.addAction(fMenuEdit.menuAction());
chudy@google.comc432f002012-07-10 13:19:25 +0000976 fMenuBar.addAction(fMenuView.menuAction());
977 fMenuBar.addAction(fMenuNavigate.menuAction());
chudy@google.come504de02012-07-16 18:35:23 +0000978 fMenuBar.addAction(fMenuWindows.menuAction());
chudy@google.com902ebe52012-06-29 14:21:22 +0000979
chudy@google.com7dcae672012-07-09 20:26:53 +0000980 fPause = false;
981
chudy@google.comc432f002012-07-10 13:19:25 +0000982 SkDebuggerGUI->setMenuBar(&fMenuBar);
chudy@google.com902ebe52012-06-29 14:21:22 +0000983 QMetaObject::connectSlotsByName(SkDebuggerGUI);
984}
985
robertphillips@google.comff6e6ba2013-01-28 17:43:26 +0000986void SkDebuggerGUI::setupDirectoryWidget(const QString& path) {
987 fPath = path;
988 QDir dir(path);
chudy@google.com902ebe52012-06-29 14:21:22 +0000989 QRegExp r(".skp");
chudy@google.comc432f002012-07-10 13:19:25 +0000990 fDirectoryWidget.clear();
991 const QStringList files = dir.entryList();
chudy@google.com902ebe52012-06-29 14:21:22 +0000992 foreach (QString f, files) {
chudy@google.com7dcae672012-07-09 20:26:53 +0000993 if (f.contains(r))
chudy@google.comc432f002012-07-10 13:19:25 +0000994 fDirectoryWidget.addItem(f);
chudy@google.com902ebe52012-06-29 14:21:22 +0000995 }
996}
997
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000998void SkDebuggerGUI::loadPicture(const SkString& fileName) {
999 fFileName = fileName;
chudy@google.comd3058f52012-07-19 13:41:27 +00001000 fLoading = true;
robertphillips@google.comd26c7062012-11-12 20:42:12 +00001001 SkStream* stream = SkNEW_ARGS(SkFILEStream, (fileName.c_str()));
robertphillips@google.com2d40ec42013-02-07 20:39:40 +00001002
scroggo@google.comf1754ec2013-06-28 21:32:00 +00001003 SkPicture* picture = SkPicture::CreateFromStream(stream);
robertphillips@google.com2d40ec42013-02-07 20:39:40 +00001004
scroggo@google.comf1754ec2013-06-28 21:32:00 +00001005 if (NULL == picture) {
robertphillips@google.com2d40ec42013-02-07 20:39:40 +00001006 QMessageBox::critical(this, "Error loading file", "Couldn't read file, sorry.");
1007 SkSafeUnref(stream);
1008 return;
1009 }
robertphillips@google.com2bde91d2012-11-15 14:57:57 +00001010
chudy@google.com686e6802012-08-14 16:00:32 +00001011 fCanvasWidget.resetWidgetTransform();
chudy@google.com607357f2012-08-07 16:12:23 +00001012 fDebugger.loadPicture(picture);
chudy@google.com4c7962e2012-08-14 19:38:31 +00001013
robertphillips@google.com6d9c92b2013-05-23 13:21:18 +00001014 fSkipCommands.setCount(fDebugger.getSize());
1015 for (int i = 0; i < fSkipCommands.count(); ++i) {
robertphillips@google.com5f971142012-12-07 20:48:56 +00001016 fSkipCommands[i] = false;
1017 }
1018
chudy@google.com607357f2012-08-07 16:12:23 +00001019 SkSafeUnref(stream);
1020 SkSafeUnref(picture);
1021
chudy@google.com97cee972012-08-07 20:41:37 +00001022 // Will this automatically clear out due to nature of refcnt?
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +00001023 SkTArray<SkString>* commands = fDebugger.getDrawCommandsAsStrings();
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +00001024 SkTDArray<size_t>* offsets = fDebugger.getDrawCommandOffsets();
1025 SkASSERT(commands->count() == offsets->count());
chudy@google.com607357f2012-08-07 16:12:23 +00001026
robertphillips@google.com6d9c92b2013-05-23 13:21:18 +00001027 fActionProfile.setDisabled(false);
robertphillips@google.com2bde91d2012-11-15 14:57:57 +00001028
chudy@google.com7dcae672012-07-09 20:26:53 +00001029 /* fDebugCanvas is reinitialized every load picture. Need it to retain value
chudy@google.com607357f2012-08-07 16:12:23 +00001030 * of the visibility filter.
1031 * TODO(chudy): This should be deprecated since fDebugger is not
1032 * recreated.
1033 * */
commit-bot@chromium.org22d39332013-11-21 15:37:29 +00001034 fDebugger.highlightCurrentCommand(fSettingsWidget.getVisibilityFilter());
chudy@google.com607357f2012-08-07 16:12:23 +00001035
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +00001036 this->setupListWidget(commands, offsets);
1037 this->setupComboBox(commands);
1038 this->setupOverviewText(NULL, 0.0, 1);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +00001039 fInspectorWidget.setDisabled(false);
chudy@google.come606d6e2012-07-12 14:31:25 +00001040 fSettingsWidget.setDisabled(false);
chudy@google.comd3058f52012-07-19 13:41:27 +00001041 fMenuEdit.setDisabled(false);
1042 fMenuNavigate.setDisabled(false);
1043 fMenuView.setDisabled(false);
chudy@google.com0ab03392012-07-28 20:16:11 +00001044 fActionSave.setDisabled(false);
1045 fActionSaveAs.setDisabled(false);
chudy@google.comd3058f52012-07-19 13:41:27 +00001046 fLoading = false;
1047 actionPlay();
chudy@google.com902ebe52012-06-29 14:21:22 +00001048}
1049
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +00001050void SkDebuggerGUI::setupListWidget(SkTArray<SkString>* commands, SkTDArray<size_t>* offsets) {
1051 SkASSERT(commands->count() == offsets->count());
chudy@google.comc432f002012-07-10 13:19:25 +00001052 fListWidget.clear();
chudy@google.com902ebe52012-06-29 14:21:22 +00001053 int counter = 0;
robertphillips@google.com30d35f22012-11-06 16:45:36 +00001054 int indent = 0;
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +00001055 for (int i = 0; i < commands->count(); i++) {
chudy@google.com902ebe52012-06-29 14:21:22 +00001056 QListWidgetItem *item = new QListWidgetItem();
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +00001057 item->setData(Qt::DisplayRole, (*commands)[i].c_str());
chudy@google.com902ebe52012-06-29 14:21:22 +00001058 item->setData(Qt::UserRole + 1, counter++);
robertphillips@google.com30d35f22012-11-06 16:45:36 +00001059
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +00001060 if (0 == strcmp("Restore", (*commands)[i].c_str()) ||
1061 0 == strcmp("EndCommentGroup", (*commands)[i].c_str()) ||
1062 0 == strcmp("PopCull", (*commands)[i].c_str())) {
robertphillips@google.com30d35f22012-11-06 16:45:36 +00001063 indent -= 10;
1064 }
1065
1066 item->setData(Qt::UserRole + 3, indent);
1067
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +00001068 if (0 == strcmp("Save", (*commands)[i].c_str()) ||
1069 0 == strcmp("Save Layer", (*commands)[i].c_str()) ||
1070 0 == strcmp("BeginCommentGroup", (*commands)[i].c_str()) ||
1071 0 == strcmp("PushCull", (*commands)[i].c_str())) {
robertphillips@google.com30d35f22012-11-06 16:45:36 +00001072 indent += 10;
1073 }
1074
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +00001075 item->setData(Qt::UserRole + 4, -1);
1076 item->setData(Qt::UserRole + 5, (int)(*offsets)[i]);
robertphillips@google.comd26c7062012-11-12 20:42:12 +00001077
chudy@google.comc432f002012-07-10 13:19:25 +00001078 fListWidget.addItem(item);
chudy@google.com902ebe52012-06-29 14:21:22 +00001079 }
1080}
1081
skia.committer@gmail.com91274b92013-03-13 07:01:04 +00001082void SkDebuggerGUI::setupOverviewText(const SkTDArray<double>* typeTimes,
robertphillips@google.come428f9b2013-03-12 15:33:40 +00001083 double totTime,
1084 int numRuns) {
borenet@google.com2d9dbd42013-03-12 13:07:40 +00001085 SkString overview;
robertphillips@google.come428f9b2013-03-12 15:33:40 +00001086 fDebugger.getOverviewText(typeTimes, totTime, &overview, numRuns);
borenet@google.com2d9dbd42013-03-12 13:07:40 +00001087 fInspectorWidget.setText(overview.c_str(), SkInspectorWidget::kOverview_TabType);
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +00001088}
1089
commit-bot@chromium.org2a67e122014-05-19 13:53:10 +00001090void SkDebuggerGUI::setupClipStackText() {
1091 SkString clipStack;
1092 fDebugger.getClipStackText(&clipStack);
1093 fInspectorWidget.setText(clipStack.c_str(), SkInspectorWidget::kClipStack_TabType);
1094}
1095
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +00001096void SkDebuggerGUI::setupComboBox(SkTArray<SkString>* command) {
1097 fFilter.clear();
1098 fFilter.addItem("--Filter By Available Commands--");
1099
1100 std::map<std::string, int> map;
1101 for (int i = 0; i < command->count(); i++) {
1102 map[(*command)[i].c_str()]++;
1103 }
1104
skia.committer@gmail.com34587162012-11-20 02:01:23 +00001105 for (std::map<std::string, int>::iterator it = map.begin(); it != map.end();
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +00001106 ++it) {
1107 fFilter.addItem((it->first).c_str());
1108 }
chudy@google.com902ebe52012-06-29 14:21:22 +00001109
1110 // NOTE(chudy): Makes first item unselectable.
chudy@google.com7dcae672012-07-09 20:26:53 +00001111 QStandardItemModel* model = qobject_cast<QStandardItemModel*>(
chudy@google.comc432f002012-07-10 13:19:25 +00001112 fFilter.model());
1113 QModelIndex firstIndex = model->index(0, fFilter.modelColumn(),
1114 fFilter.rootModelIndex());
chudy@google.com902ebe52012-06-29 14:21:22 +00001115 QStandardItem* firstItem = model->itemFromIndex(firstIndex);
1116 firstItem->setSelectable(false);
1117}