#include "mainwindow.h"
+#include "apitrace.h"
#include "apitracecall.h"
#include "apicalldelegate.h"
#include "apitracemodel.h"
#include "apitracefilter.h"
+#include "retracer.h"
+#include "settingsdialog.h"
+#include "shaderssourcewidget.h"
+#include "ui_retracerdialog.h"
+#include "vertexdatainterpreter.h"
+
+#include <qjson/parser.h>
#include <QAction>
#include <QDebug>
+#include <QDesktopServices>
#include <QDir>
#include <QFileDialog>
#include <QLineEdit>
#include <QMessageBox>
-#include <QProcess>
+#include <QProgressBar>
#include <QToolBar>
+#include <QUrl>
+#include <QVBoxLayout>
+#include <QWebPage>
#include <QWebView>
MainWindow::MainWindow()
: QMainWindow(),
- m_replayProcess(0)
+ m_selectedEvent(0),
+ m_stateEvent(0),
+ m_jsonParser(new QJson::Parser())
{
m_ui.setupUi(this);
+ m_ui.stateTreeWidget->sortByColumn(0, Qt::AscendingOrder);
+
+ m_sourcesWidget = new ShadersSourceWidget(m_ui.shadersTab);
+ QVBoxLayout *layout = new QVBoxLayout;
+ layout->addWidget(m_sourcesWidget);
+ m_ui.shadersTab->setLayout(layout);
+
+ m_trace = new ApiTrace();
+ connect(m_trace, SIGNAL(startedLoadingTrace()),
+ this, SLOT(startedLoadingTrace()));
+ connect(m_trace, SIGNAL(finishedLoadingTrace()),
+ this, SLOT(finishedLoadingTrace()));
+
+ m_retracer = new Retracer(this);
+ connect(m_retracer, SIGNAL(finished(const QByteArray&)),
+ this, SLOT(replayFinished(const QByteArray&)));
+ connect(m_retracer, SIGNAL(error(const QString&)),
+ this, SLOT(replayError(const QString&)));
+
+ m_vdataInterpreter = new VertexDataInterpreter(this);
+ m_vdataInterpreter->setListWidget(m_ui.vertexDataListWidget);
+ m_vdataInterpreter->setStride(
+ m_ui.vertexStrideSB->value());
+ m_vdataInterpreter->setComponents(
+ m_ui.vertexComponentsSB->value());
+ m_vdataInterpreter->setStartingOffset(
+ m_ui.startingOffsetSB->value());
+ m_vdataInterpreter->setTypeFromString(
+ m_ui.vertexTypeCB->currentText());
+
+ connect(m_ui.vertexInterpretButton, SIGNAL(clicked()),
+ m_vdataInterpreter, SLOT(interpretData()));
+ connect(m_ui.vertexTypeCB, SIGNAL(currentIndexChanged(const QString&)),
+ m_vdataInterpreter, SLOT(setTypeFromString(const QString&)));
+ connect(m_ui.vertexStrideSB, SIGNAL(valueChanged(int)),
+ m_vdataInterpreter, SLOT(setStride(int)));
+ connect(m_ui.vertexComponentsSB, SIGNAL(valueChanged(int)),
+ m_vdataInterpreter, SLOT(setComponents(int)));
+ connect(m_ui.startingOffsetSB, SIGNAL(valueChanged(int)),
+ m_vdataInterpreter, SLOT(setStartingOffset(int)));
m_model = new ApiTraceModel();
+ m_model->setApiTrace(m_trace);
m_proxyModel = new ApiTraceFilter();
m_proxyModel->setSourceModel(m_model);
m_ui.callView->setModel(m_proxyModel);
m_ui.callView->setItemDelegate(new ApiCallDelegate);
- for (int column = 0; column < m_model->columnCount(); ++column)
- m_ui.callView->resizeColumnToContents(column);
+ m_ui.callView->resizeColumnToContents(0);
+ m_ui.callView->header()->swapSections(0, 1);
+ m_ui.callView->setColumnWidth(1, 42);
QToolBar *toolBar = addToolBar(tr("Navigation"));
m_filterEdit = new QLineEdit(toolBar);
toolBar->addWidget(m_filterEdit);
+ m_progressBar = new QProgressBar();
+ m_progressBar->setRange(0, 0);
+ statusBar()->addPermanentWidget(m_progressBar);
+ m_progressBar->hide();
+
m_ui.detailsDock->hide();
+ m_ui.vertexDataDock->hide();
+ m_ui.stateDock->hide();
+ setDockOptions(dockOptions() | QMainWindow::ForceTabbedDocks);
+
+ tabifyDockWidget(m_ui.stateDock, m_ui.vertexDataDock);
connect(m_ui.actionOpen, SIGNAL(triggered()),
this, SLOT(openTrace()));
this, SLOT(replayStart()));
connect(m_ui.actionStop, SIGNAL(triggered()),
this, SLOT(replayStop()));
+ connect(m_ui.actionLookupState, SIGNAL(triggered()),
+ this, SLOT(lookupState()));
+ connect(m_ui.actionOptions, SIGNAL(triggered()),
+ this, SLOT(showSettings()));
connect(m_ui.callView, SIGNAL(activated(const QModelIndex &)),
this, SLOT(callItemSelected(const QModelIndex &)));
connect(m_filterEdit, SIGNAL(returnPressed()),
this, SLOT(filterTrace()));
+
+ m_ui.detailsWebView->page()->setLinkDelegationPolicy(
+ QWebPage::DelegateExternalLinks);
+ connect(m_ui.detailsWebView, SIGNAL(linkClicked(const QUrl&)),
+ this, SLOT(openHelp(const QUrl&)));
}
void MainWindow::openTrace()
qDebug()<< "File name : " <<fileName;
newTraceFile(fileName);
- m_model->loadTraceFile(fileName);
}
void MainWindow::loadTrace(const QString &fileName)
}
qDebug()<< "Loading : " <<fileName;
- m_model->loadTraceFile(fileName);
+ m_progressBar->setValue(0);
newTraceFile(fileName);
}
void MainWindow::callItemSelected(const QModelIndex &index)
{
- ApiTraceCall *call = index.data().value<ApiTraceCall*>();
- if (call) {
+ ApiTraceEvent *event =
+ index.data(ApiTraceModel::EventRole).value<ApiTraceEvent*>();
+
+ if (event && event->type() == ApiTraceEvent::Call) {
+ ApiTraceCall *call = static_cast<ApiTraceCall*>(event);
m_ui.detailsWebView->setHtml(call->toHtml());
m_ui.detailsDock->show();
+ if (call->hasBinaryData()) {
+ QByteArray data =
+ call->argValues[call->binaryDataIndex()].toByteArray();
+ m_vdataInterpreter->setData(data);
+
+ for (int i = 0; i < call->argNames.count(); ++i) {
+ QString name = call->argNames[i];
+ if (name == QLatin1String("stride")) {
+ int stride = call->argValues[i].toInt();
+ m_ui.vertexStrideSB->setValue(stride);
+ } else if (name == QLatin1String("size")) {
+ int components = call->argValues[i].toInt();
+ m_ui.vertexComponentsSB->setValue(components);
+ } else if (name == QLatin1String("type")) {
+ QString val = call->argValues[i].toString();
+ int textIndex = m_ui.vertexTypeCB->findText(val);
+ if (textIndex >= 0)
+ m_ui.vertexTypeCB->setCurrentIndex(textIndex);
+ }
+ }
+ }
+ m_ui.vertexDataDock->setVisible(call->hasBinaryData());
+ m_selectedEvent = call;
} else {
+ if (event && event->type() == ApiTraceEvent::Frame) {
+ m_selectedEvent = static_cast<ApiTraceFrame*>(event);
+ } else
+ m_selectedEvent = 0;
m_ui.detailsDock->hide();
+ m_ui.vertexDataDock->hide();
}
+ if (m_selectedEvent && !m_selectedEvent->state().isEmpty()) {
+ fillStateForFrame();
+ } else
+ m_ui.stateDock->hide();
}
void MainWindow::filterTrace()
void MainWindow::replayStart()
{
- if (!m_replayProcess) {
-#ifdef Q_OS_WIN
- QString format = QLatin1String("%1;");
-#else
- QString format = QLatin1String("%1:");
-#endif
- QString buildPath = format.arg(BUILD_DIR);
- QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
- env.insert("PATH", buildPath + env.value("PATH"));
-
- qputenv("PATH", env.value("PATH").toLatin1());
-
- m_replayProcess = new QProcess(this);
- m_replayProcess->setProcessEnvironment(env);
-
- connect(m_replayProcess, SIGNAL(finished(int, QProcess::ExitStatus)),
- this, SLOT(replayFinished()));
- connect(m_replayProcess, SIGNAL(error(QProcess::ProcessError)),
- this, SLOT(replayError(QProcess::ProcessError)));
+ QDialog dlg;
+ Ui_RetracerDialog dlgUi;
+ dlgUi.setupUi(&dlg);
+
+ dlgUi.doubleBufferingCB->setChecked(
+ m_retracer->isDoubleBuffered());
+ dlgUi.benchmarkCB->setChecked(
+ m_retracer->isBenchmarking());
+
+ if (dlg.exec() == QDialog::Accepted) {
+ m_retracer->setDoubleBuffered(
+ dlgUi.doubleBufferingCB->isChecked());
+ m_retracer->setBenchmarking(
+ dlgUi.benchmarkCB->isChecked());
+ replayTrace(false);
}
-
- if (m_traceFileName.isEmpty())
- return;
-
- QStringList arguments;
- arguments << m_traceFileName;
-
- m_replayProcess->start(QLatin1String("glretrace"),
- arguments);
-
- m_ui.actionStop->setEnabled(true);
- m_ui.actionReplay->setEnabled(false);
}
void MainWindow::replayStop()
{
- if (m_replayProcess) {
- m_replayProcess->kill();
-
- m_ui.actionStop->setEnabled(false);
- m_ui.actionReplay->setEnabled(true);
- }
+ m_retracer->terminate();
+ m_ui.actionStop->setEnabled(false);
+ m_ui.actionReplay->setEnabled(true);
+ m_ui.actionLookupState->setEnabled(true);
}
void MainWindow::newTraceFile(const QString &fileName)
{
m_traceFileName = fileName;
+ m_trace->setFileName(fileName);
if (m_traceFileName.isEmpty()) {
m_ui.actionReplay->setEnabled(false);
+ m_ui.actionLookupState->setEnabled(false);
+ setWindowTitle(tr("QApiTrace"));
} else {
+ QFileInfo info(fileName);
m_ui.actionReplay->setEnabled(true);
+ m_ui.actionLookupState->setEnabled(true);
+ setWindowTitle(
+ tr("QApiTrace - %1").arg(info.fileName()));
}
}
-void MainWindow::replayFinished()
+void MainWindow::replayFinished(const QByteArray &output)
{
m_ui.actionStop->setEnabled(false);
m_ui.actionReplay->setEnabled(true);
+ m_ui.actionLookupState->setEnabled(true);
- QString output = m_replayProcess->readAllStandardOutput();
-
-#if 0
- qDebug()<<"Process finished = ";
- qDebug()<<"\terr = "<<m_replayProcess->readAllStandardError();
- qDebug()<<"\tout = "<<output;
-#endif
-
- if (output.length() < 80) {
+ if (m_retracer->captureState()) {
+ bool ok = false;
+ QVariantMap parsedJson = m_jsonParser->parse(output, &ok).toMap();
+ parseState(parsedJson);
+ } else if (output.length() < 80) {
statusBar()->showMessage(output);
}
+ m_stateEvent = 0;
}
-void MainWindow::replayError(QProcess::ProcessError err)
+void MainWindow::replayError(const QString &message)
{
m_ui.actionStop->setEnabled(false);
m_ui.actionReplay->setEnabled(true);
+ m_ui.actionLookupState->setEnabled(true);
+ m_stateEvent = 0;
- qDebug()<<"Process error = "<<err;
- qDebug()<<"\terr = "<<m_replayProcess->readAllStandardError();
- qDebug()<<"\tout = "<<m_replayProcess->readAllStandardOutput();
QMessageBox::warning(
- this, tr("Replay Failed"),
- tr("Couldn't execute the replay file '%1'").arg(m_traceFileName));
+ this, tr("Replay Failed"), message);
+}
+
+void MainWindow::startedLoadingTrace()
+{
+ Q_ASSERT(m_trace);
+ m_progressBar->show();
+ QFileInfo info(m_trace->fileName());
+ statusBar()->showMessage(
+ tr("Loading %1...").arg(info.fileName()));
+}
+
+void MainWindow::finishedLoadingTrace()
+{
+ m_progressBar->hide();
+ if (!m_trace) {
+ return;
+ }
+ QFileInfo info(m_trace->fileName());
+ statusBar()->showMessage(
+ tr("Loaded %1").arg(info.fileName()), 3000);
+}
+
+void MainWindow::replayTrace(bool dumpState)
+{
+ if (m_traceFileName.isEmpty())
+ return;
+
+ m_retracer->setFileName(m_traceFileName);
+ m_retracer->setCaptureState(dumpState);
+ if (m_retracer->captureState() && m_selectedEvent) {
+ int index = 0;
+ if (m_selectedEvent->type() == ApiTraceEvent::Call) {
+ index = static_cast<ApiTraceCall*>(m_selectedEvent)->index;
+ } else if (m_selectedEvent->type() == ApiTraceEvent::Frame) {
+ ApiTraceFrame *frame = static_cast<ApiTraceFrame*>(m_selectedEvent);
+ if (frame->calls.isEmpty()) {
+ //XXX i guess we could still get the current state
+ qDebug()<<"tried to get a state for an empty frame";
+ return;
+ }
+ index = frame->calls.first()->index;
+ } else {
+ qDebug()<<"Unknown event type";
+ return;
+ }
+ m_retracer->setCaptureAtCallNumber(index);
+ }
+ m_retracer->start();
+
+ m_ui.actionStop->setEnabled(true);
+}
+
+void MainWindow::lookupState()
+{
+ if (!m_selectedEvent) {
+ QMessageBox::warning(
+ this, tr("Unknown Event"),
+ tr("To inspect the state select an event in the event list."));
+ return;
+ }
+ m_stateEvent = m_selectedEvent;
+ replayTrace(true);
+}
+
+MainWindow::~MainWindow()
+{
+ delete m_jsonParser;
+}
+
+void MainWindow::parseState(const QVariantMap &parsedJson)
+{
+ m_stateEvent->setState(ApiTraceState(parsedJson));
+ m_model->stateSetOnEvent(m_stateEvent);
+ if (m_selectedEvent == m_stateEvent) {
+ fillStateForFrame();
+ } else {
+ m_ui.stateDock->hide();
+ }
+}
+
+static void
+variantToString(const QVariant &var, QString &str)
+{
+ if (var.type() == QVariant::List) {
+ QVariantList lst = var.toList();
+ str += QLatin1String("[");
+ for (int i = 0; i < lst.count(); ++i) {
+ QVariant val = lst[i];
+ variantToString(val, str);
+ if (i < lst.count() - 1)
+ str += QLatin1String(", ");
+ }
+ str += QLatin1String("]");
+ } else if (var.type() == QVariant::Map) {
+ Q_ASSERT(!"unsupported state type");
+ } else if (var.type() == QVariant::Hash) {
+ Q_ASSERT(!"unsupported state type");
+ } else {
+ str += var.toString();
+ }
+}
+
+void MainWindow::fillStateForFrame()
+{
+ QVariantMap::const_iterator itr;
+ QVariantMap params;
+
+ if (!m_selectedEvent || m_selectedEvent->state().isEmpty())
+ return;
+
+ const ApiTraceState &state = m_selectedEvent->state();
+ m_ui.stateTreeWidget->clear();
+ params = state.parameters();
+ QList<QTreeWidgetItem *> items;
+ for (itr = params.constBegin(); itr != params.constEnd(); ++itr) {
+ QString key = itr.key();
+ QString val;
+
+ variantToString(itr.value(), val);
+ //qDebug()<<"key = "<<key;
+ //qDebug()<<"val = "<<val;
+ QStringList lst;
+ lst += key;
+ lst += val;
+ items.append(new QTreeWidgetItem((QTreeWidget*)0, lst));
+ }
+ m_ui.stateTreeWidget->insertTopLevelItems(0, items);
+
+ QStringList shaderSources = state.shaderSources();
+ if (shaderSources.isEmpty()) {
+ m_sourcesWidget->setShaders(shaderSources);
+ } else {
+ m_sourcesWidget->setShaders(shaderSources);
+ }
+
+ m_ui.surfacesTab->setEnabled(false);
+ m_ui.stateDock->show();
+}
+
+void MainWindow::showSettings()
+{
+ SettingsDialog dialog;
+ dialog.setFilterOptions(m_proxyModel->filterOptions());
+
+ if (dialog.exec() == QDialog::Accepted) {
+ m_proxyModel->setFilterOptions(dialog.filterOptions());
+ }
+}
+
+void MainWindow::openHelp(const QUrl &url)
+{
+ QDesktopServices::openUrl(url);
}
#include "mainwindow.moc"