]> git.cworth.org Git - apitrace/blobdiff - gui/mainwindow.cpp
Merge branch 'gui-thumbnails'
[apitrace] / gui / mainwindow.cpp
index 2974f31228af14fa2c7d91fcf1172769491ee7fe..fce9984a33c89fc8b34b8ecca08d597ab3af3c42 100644 (file)
@@ -36,6 +36,8 @@
 
 MainWindow::MainWindow()
     : QMainWindow(),
+      m_api(trace::API_GL),
+      m_initalCallNum(-1),
       m_selectedEvent(0),
       m_stateEvent(0),
       m_nonDefaultsLookupEvent(0)
@@ -47,8 +49,6 @@ MainWindow::MainWindow()
 
 void MainWindow::createTrace()
 {
-    TraceDialog dialog;
-
     if (!m_traceProcess->canTrace()) {
         QMessageBox::warning(
             this,
@@ -57,9 +57,11 @@ void MainWindow::createTrace()
         return;
     }
 
+    TraceDialog dialog;
     if (dialog.exec() == QDialog::Accepted) {
         qDebug()<< "App : " <<dialog.applicationPath();
         qDebug()<< "  Arguments: "<<dialog.arguments();
+        m_traceProcess->setApi(dialog.api());
         m_traceProcess->setExecutablePath(dialog.applicationPath());
         m_traceProcess->setArguments(dialog.arguments());
         m_traceProcess->start();
@@ -69,18 +71,18 @@ void MainWindow::createTrace()
 void MainWindow::openTrace()
 {
     QString fileName =
-        QFileDialog::getOpenFileName(
-            this,
-            tr("Open Trace"),
-            QDir::homePath(),
-            tr("Trace Files (*.trace)"));
+            QFileDialog::getOpenFileName(
+                this,
+                tr("Open Trace"),
+                QDir::homePath(),
+                tr("Trace Files (*.trace)"));
 
     if (!fileName.isEmpty() && QFile::exists(fileName)) {
         newTraceFile(fileName);
     }
 }
 
-void MainWindow::loadTrace(const QString &fileName)
+void MainWindow::loadTrace(const QString &fileName, int callNum)
 {
     if (!QFile::exists(fileName)) {
         QMessageBox::warning(this, tr("File Missing"),
@@ -88,6 +90,7 @@ void MainWindow::loadTrace(const QString &fileName)
         return;
     }
 
+    m_initalCallNum = callNum;
     newTraceFile(fileName);
 }
 
@@ -98,14 +101,18 @@ void MainWindow::callItemSelected(const QModelIndex &index)
 
     if (event && event->type() == ApiTraceEvent::Call) {
         ApiTraceCall *call = static_cast<ApiTraceCall*>(event);
+        m_ui.detailsDock->setWindowTitle(
+            tr("Details View. Frame %1, Call %2")
+            .arg(call->parentFrame() ? call->parentFrame()->number : 0)
+            .arg(call->index()));
         m_ui.detailsWebView->setHtml(call->toHtml());
         m_ui.detailsDock->show();
         if (call->hasBinaryData()) {
             QByteArray data =
                 call->arguments()[call->binaryDataIndex()].toByteArray();
             m_vdataInterpreter->setData(data);
-            QVector<QVariant> args = call->arguments();
 
+            QVector<QVariant> args = call->arguments();
             for (int i = 0; i < call->argNames().count(); ++i) {
                 QString name = call->argNames()[i];
                 if (name == QLatin1String("stride")) {
@@ -117,8 +124,9 @@ void MainWindow::callItemSelected(const QModelIndex &index)
                 } else if (name == QLatin1String("type")) {
                     QString val = args[i].toString();
                     int textIndex = m_ui.vertexTypeCB->findText(val);
-                    if (textIndex >= 0)
+                    if (textIndex >= 0) {
                         m_ui.vertexTypeCB->setCurrentIndex(textIndex);
+                    }
                 }
             }
         }
@@ -127,15 +135,21 @@ void MainWindow::callItemSelected(const QModelIndex &index)
     } else {
         if (event && event->type() == ApiTraceEvent::Frame) {
             m_selectedEvent = static_cast<ApiTraceFrame*>(event);
-        } else
+        } else {
             m_selectedEvent = 0;
+        }
         m_ui.detailsDock->hide();
         m_ui.vertexDataDock->hide();
     }
     if (m_selectedEvent && m_selectedEvent->hasState()) {
         fillStateForFrame();
-    } else
+    } else {
         m_ui.stateDock->hide();
+    }
+}
+
+void MainWindow::callItemActivated(const QModelIndex &index) {
+    lookupState();
 }
 
 void MainWindow::replayStart()
@@ -162,7 +176,7 @@ void MainWindow::replayStart()
             dlgUi.doubleBufferingCB->isChecked());
         m_retracer->setBenchmarking(
             !dlgUi.errorCheckCB->isChecked());
-        replayTrace(false);
+        replayTrace(false, true);
     }
 }
 
@@ -172,6 +186,7 @@ void MainWindow::replayStop()
     m_ui.actionStop->setEnabled(false);
     m_ui.actionReplay->setEnabled(true);
     m_ui.actionLookupState->setEnabled(true);
+    m_ui.actionShowThumbnails->setEnabled(true);
 }
 
 void MainWindow::newTraceFile(const QString &fileName)
@@ -184,11 +199,13 @@ void MainWindow::newTraceFile(const QString &fileName)
     if (fileName.isEmpty()) {
         m_ui.actionReplay->setEnabled(false);
         m_ui.actionLookupState->setEnabled(false);
+        m_ui.actionShowThumbnails->setEnabled(false);
         setWindowTitle(tr("QApiTrace"));
     } else {
         QFileInfo info(fileName);
         m_ui.actionReplay->setEnabled(true);
         m_ui.actionLookupState->setEnabled(true);
+        m_ui.actionShowThumbnails->setEnabled(true);
         setWindowTitle(
             tr("QApiTrace - %1").arg(info.fileName()));
     }
@@ -199,6 +216,7 @@ void MainWindow::replayFinished(const QString &output)
     m_ui.actionStop->setEnabled(false);
     m_ui.actionReplay->setEnabled(true);
     m_ui.actionLookupState->setEnabled(true);
+    m_ui.actionShowThumbnails->setEnabled(true);
 
     m_progressBar->hide();
     if (output.length() < 80) {
@@ -207,8 +225,9 @@ void MainWindow::replayFinished(const QString &output)
     m_stateEvent = 0;
     m_ui.actionShowErrorsDock->setEnabled(m_trace->hasErrors());
     m_ui.errorsDock->setVisible(m_trace->hasErrors());
-    if (!m_trace->hasErrors())
+    if (!m_trace->hasErrors()) {
         m_ui.errorsTreeWidget->clear();
+    }
 
     statusBar()->showMessage(
         tr("Replaying finished!"), 2000);
@@ -219,6 +238,7 @@ void MainWindow::replayError(const QString &message)
     m_ui.actionStop->setEnabled(false);
     m_ui.actionReplay->setEnabled(true);
     m_ui.actionLookupState->setEnabled(true);
+    m_ui.actionShowThumbnails->setEnabled(true);
     m_stateEvent = 0;
     m_nonDefaultsLookupEvent = 0;
 
@@ -247,15 +267,22 @@ void MainWindow::finishedLoadingTrace()
     QFileInfo info(m_trace->fileName());
     statusBar()->showMessage(
         tr("Loaded %1").arg(info.fileName()), 3000);
+    if (m_initalCallNum >= 0) {
+        m_trace->findCallIndex(m_initalCallNum);
+        m_initalCallNum = -1;
+    }
 }
 
-void MainWindow::replayTrace(bool dumpState)
+void MainWindow::replayTrace(bool dumpState, bool dumpThumbnails)
 {
-    if (m_trace->fileName().isEmpty())
+    if (m_trace->fileName().isEmpty()) {
         return;
+    }
 
     m_retracer->setFileName(m_trace->fileName());
+    m_retracer->setAPI(m_api);
     m_retracer->setCaptureState(dumpState);
+    m_retracer->setCaptureThumbnails(dumpThumbnails);
     if (m_retracer->captureState() && m_selectedEvent) {
         int index = 0;
         if (m_selectedEvent->type() == ApiTraceEvent::Call) {
@@ -279,12 +306,21 @@ void MainWindow::replayTrace(bool dumpState)
 
     m_ui.actionStop->setEnabled(true);
     m_progressBar->show();
-    if (dumpState)
-        statusBar()->showMessage(
-            tr("Looking up the state..."));
-    else
+    if (dumpState || dumpThumbnails) {
+        if (dumpState && dumpThumbnails) {
+            statusBar()->showMessage(
+                tr("Looking up the state and capturing thumbnails..."));
+        } else if (dumpState) {
+            statusBar()->showMessage(
+                tr("Looking up the state..."));
+        } else if (dumpThumbnails) {
+            statusBar()->showMessage(
+                tr("Capturing thumbnails..."));
+        }
+    } else {
         statusBar()->showMessage(
             tr("Replaying the trace file..."));
+    }
 }
 
 void MainWindow::lookupState()
@@ -304,7 +340,12 @@ void MainWindow::lookupState()
         return;
     }
     m_stateEvent = m_selectedEvent;
-    replayTrace(true);
+    replayTrace(true, false);
+}
+
+void MainWindow::showThumbnails()
+{
+    replayTrace(false, true);
 }
 
 MainWindow::~MainWindow()
@@ -339,10 +380,12 @@ variantToString(const QVariant &var, QString &str)
 }
 
 static QTreeWidgetItem *
-variantToItem(const QString &key, const QVariant &var, const QVariant &defaultVar);
+variantToItem(const QString &key, const QVariant &var,
+              const QVariant &defaultVar);
 
 static void
-variantMapToItems(const QVariantMap &map, const QVariantMap &defaultMap, QList<QTreeWidgetItem *> &items)
+variantMapToItems(const QVariantMap &map, const QVariantMap &defaultMap,
+                  QList<QTreeWidgetItem *> &items)
 {
     QVariantMap::const_iterator itr;
     for (itr = map.constBegin(); itr != map.constEnd(); ++itr) {
@@ -358,7 +401,8 @@ variantMapToItems(const QVariantMap &map, const QVariantMap &defaultMap, QList<Q
 }
 
 static void
-variantListToItems(const QVector<QVariant> &lst, const QVector<QVariant> &defaultLst,
+variantListToItems(const QVector<QVariant> &lst,
+                   const QVector<QVariant> &defaultLst,
                    QList<QTreeWidgetItem *> &items)
 {
     for (int i = 0; i < lst.count(); ++i) {
@@ -398,7 +442,8 @@ isVariantDeep(const QVariant &var)
 }
 
 static QTreeWidgetItem *
-variantToItem(const QString &key, const QVariant &var, const QVariant &defaultVar)
+variantToItem(const QString &key, const QVariant &var,
+              const QVariant &defaultVar)
 {
     if (var == defaultVar) {
         return NULL;
@@ -442,16 +487,16 @@ static void addSurfaceItem(const ApiSurface &surface,
                            QTreeWidgetItem *parent,
                            QTreeWidget *tree)
 {
-    int width = surface.size().width();
-    int height = surface.size().height();
     QIcon icon(QPixmap::fromImage(surface.thumb()));
     QTreeWidgetItem *item = new QTreeWidgetItem(parent);
-
     item->setIcon(0, icon);
 
+    int width = surface.size().width();
+    int height = surface.size().height();
     QString descr =
-        QString::fromLatin1("%1, %2 x %3")
+        QString::fromLatin1("%1, %2, %3 x %4")
         .arg(label)
+        .arg(surface.formatName())
         .arg(width)
         .arg(height);
 
@@ -465,8 +510,9 @@ static void addSurfaceItem(const ApiSurface &surface,
 
 void MainWindow::fillStateForFrame()
 {
-    if (!m_selectedEvent || !m_selectedEvent->hasState())
+    if (!m_selectedEvent || !m_selectedEvent->hasState()) {
         return;
+    }
 
     if (m_nonDefaultsLookupEvent) {
         m_ui.nonDefaultsCB->blockSignals(true);
@@ -513,8 +559,9 @@ void MainWindow::fillStateForFrame()
             QTreeWidgetItem *textureItem =
                 new QTreeWidgetItem(m_ui.surfacesTreeWidget);
             textureItem->setText(0, tr("Textures"));
-            if (textures.count() <= 6)
+            if (textures.count() <= 6) {
                 textureItem->setExpanded(true);
+            }
 
             for (int i = 0; i < textures.count(); ++i) {
                 const ApiTexture &texture =
@@ -528,8 +575,9 @@ void MainWindow::fillStateForFrame()
             QTreeWidgetItem *fboItem =
                 new QTreeWidgetItem(m_ui.surfacesTreeWidget);
             fboItem->setText(0, tr("Framebuffers"));
-            if (fbos.count() <= 6)
+            if (fbos.count() <= 6) {
                 fboItem->setExpanded(true);
+            }
 
             for (int i = 0; i < fbos.count(); ++i) {
                 const ApiFramebuffer &fbo =
@@ -547,9 +595,12 @@ void MainWindow::fillStateForFrame()
 void MainWindow::showSettings()
 {
     SettingsDialog dialog;
+    dialog.setAPI(m_api);
     dialog.setFilterModel(m_proxyModel);
 
     dialog.exec();
+
+    m_api = dialog.getAPI();
 }
 
 void MainWindow::openHelp(const QUrl &url)
@@ -561,8 +612,9 @@ void MainWindow::showSurfacesMenu(const QPoint &pos)
 {
     QTreeWidget *tree = m_ui.surfacesTreeWidget;
     QTreeWidgetItem *item = tree->itemAt(pos);
-    if (!item)
+    if (!item) {
         return;
+    }
 
     QMenu menu(tr("Surfaces"), this);
 
@@ -584,11 +636,10 @@ void MainWindow::showSelectedSurface()
     QTreeWidgetItem *item =
         m_ui.surfacesTreeWidget->currentItem();
 
-    if (!item)
+    if (!item) {
         return;
+    }
 
-    QVariant var = item->data(0, Qt::UserRole);
-    QImage img = var.value<QImage>();
     ImageViewer *viewer = new ImageViewer(this);
 
     QString title;
@@ -600,11 +651,13 @@ void MainWindow::showSelectedSurface()
         title = tr("QApiTrace - Surface Viewer");
     }
     viewer->setWindowTitle(title);
+
     viewer->setAttribute(Qt::WA_DeleteOnClose, true);
+
+    QVariant var = item->data(0, Qt::UserRole);
+    QImage img = var.value<QImage>();
     viewer->setImage(img);
-    QRect screenRect = QApplication::desktop()->availableGeometry();
-    viewer->resize(qMin(int(0.75 * screenRect.width()), img.width()) + 40,
-                   qMin(int(0.75 * screenRect.height()), img.height()) + 40);
+
     viewer->show();
     viewer->raise();
     viewer->activateWindow();
@@ -690,10 +743,10 @@ void MainWindow::initConnections()
             this, SLOT(slotStartedSaving()));
     connect(m_trace, SIGNAL(saved()),
             this, SLOT(slotSaved()));
-    connect(m_trace, SIGNAL(changed(ApiTraceCall*)),
-            this, SLOT(slotTraceChanged(ApiTraceCall*)));
-    connect(m_trace, SIGNAL(findResult(ApiTrace::SearchResult,ApiTraceCall*)),
-            this, SLOT(slotSearchResult(ApiTrace::SearchResult,ApiTraceCall*)));
+    connect(m_trace, SIGNAL(changed(ApiTraceEvent*)),
+            this, SLOT(slotTraceChanged(ApiTraceEvent*)));
+    connect(m_trace, SIGNAL(findResult(ApiTrace::SearchRequest,ApiTrace::SearchResult,ApiTraceCall*)),
+            this, SLOT(slotSearchResult(ApiTrace::SearchRequest,ApiTrace::SearchResult,ApiTraceCall*)));
     connect(m_trace, SIGNAL(foundFrameStart(ApiTraceFrame*)),
             this, SLOT(slotFoundFrameStart(ApiTraceFrame*)));
     connect(m_trace, SIGNAL(foundFrameEnd(ApiTraceFrame*)),
@@ -707,6 +760,8 @@ void MainWindow::initConnections()
             this, SLOT(replayError(const QString&)));
     connect(m_retracer, SIGNAL(foundState(ApiTraceState*)),
             this, SLOT(replayStateFound(ApiTraceState*)));
+    connect(m_retracer, SIGNAL(foundThumbnails(const QList<QImage>&)),
+            this, SLOT(replayThumbnailsFound(const QList<QImage>&)));
     connect(m_retracer, SIGNAL(retraceErrors(const QList<ApiTraceError>&)),
             this, SLOT(slotRetraceErrors(const QList<ApiTraceError>&)));
 
@@ -744,11 +799,15 @@ void MainWindow::initConnections()
             this, SLOT(replayStop()));
     connect(m_ui.actionLookupState, SIGNAL(triggered()),
             this, SLOT(lookupState()));
+    connect(m_ui.actionShowThumbnails, SIGNAL(triggered()),
+            this, SLOT(showThumbnails()));
     connect(m_ui.actionOptions, SIGNAL(triggered()),
             this, SLOT(showSettings()));
 
-    connect(m_ui.callView, SIGNAL(activated(const QModelIndex &)),
+    connect(m_ui.callView->selectionModel(), SIGNAL(currentChanged(const QModelIndex &, const QModelIndex &)),
             this, SLOT(callItemSelected(const QModelIndex &)));
+    connect(m_ui.callView, SIGNAL(doubleClicked(const QModelIndex &)),
+            this, SLOT(callItemActivated(const QModelIndex &)));
     connect(m_ui.callView, SIGNAL(customContextMenuRequested(QPoint)),
             this, SLOT(customContextMenuRequested(QPoint)));
 
@@ -785,7 +844,7 @@ void MainWindow::initConnections()
     connect(m_ui.actionShowErrorsDock, SIGNAL(triggered(bool)),
             m_ui.errorsDock, SLOT(setVisible(bool)));
     connect(m_ui.errorsTreeWidget,
-            SIGNAL(currentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*)),
+            SIGNAL(itemActivated(QTreeWidgetItem*, int)),
             this, SLOT(slotErrorSelected(QTreeWidgetItem*)));
 }
 
@@ -802,6 +861,11 @@ void MainWindow::replayStateFound(ApiTraceState *state)
     m_nonDefaultsLookupEvent = 0;
 }
 
+void MainWindow::replayThumbnailsFound(const QList<QImage> &thumbnails)
+{
+    m_trace->bindThumbnailsToFrames(thumbnails);
+}
+
 void MainWindow::slotGoTo()
 {
     m_searchWidget->hide();
@@ -873,9 +937,10 @@ void MainWindow::fillState(bool nonDefaults)
             m_ui.nonDefaultsCB->blockSignals(false);
             ApiTraceFrame *firstFrame =
                 m_trace->frameAt(0);
-            if (!firstFrame)
+            if (!firstFrame) {
                 return;
-            if (!firstFrame->loaded()) {
+            }
+            if (!firstFrame->isLoaded()) {
                 m_trace->loadFrame(firstFrame);
                 return;
             }
@@ -892,18 +957,20 @@ void MainWindow::fillState(bool nonDefaults)
 
 void MainWindow::customContextMenuRequested(QPoint pos)
 {
-    QMenu menu;
     QModelIndex index = m_ui.callView->indexAt(pos);
 
     callItemSelected(index);
-    if (!index.isValid())
+    if (!index.isValid()) {
         return;
+    }
 
     ApiTraceEvent *event =
         index.data(ApiTraceModel::EventRole).value<ApiTraceEvent*>();
-    if (!event)
+    if (!event) {
         return;
+    }
 
+    QMenu menu;
     menu.addAction(QIcon(":/resources/media-record.png"),
                    tr("Lookup state"), this, SLOT(lookupState()));
     if (event->type() == ApiTraceEvent::Call) {
@@ -974,11 +1041,14 @@ ApiTraceFrame * MainWindow::selectedFrame() const
     return NULL;
 }
 
-void MainWindow::slotTraceChanged(ApiTraceCall *call)
+void MainWindow::slotTraceChanged(ApiTraceEvent *event)
 {
-    Q_ASSERT(call);
-    if (call == m_selectedEvent) {
-        m_ui.detailsWebView->setHtml(call->toHtml());
+    Q_ASSERT(event);
+    if (event == m_selectedEvent) {
+        if (event->type() == ApiTraceEvent::Call) {
+            ApiTraceCall *call = static_cast<ApiTraceCall*>(event);
+            m_ui.detailsWebView->setHtml(call->toHtml());
+        }
     }
 }
 
@@ -1023,8 +1093,9 @@ void MainWindow::saveSelectedSurface()
     QTreeWidgetItem *item =
         m_ui.surfacesTreeWidget->currentItem();
 
-    if (!item || !m_trace)
+    if (!item || !m_trace) {
         return;
+    }
 
     QVariant var = item->data(0, Qt::UserRole);
     QImage img = var.value<QImage>();
@@ -1076,20 +1147,41 @@ void MainWindow::loadProgess(int percent)
     m_progressBar->setValue(percent);
 }
 
-void MainWindow::slotSearchResult(ApiTrace::SearchResult result,
+void MainWindow::slotSearchResult(const ApiTrace::SearchRequest &request,
+                                  ApiTrace::SearchResult result,
                                   ApiTraceCall *call)
 {
     switch (result) {
-    case ApiTrace::SearchNotFound:
+    case ApiTrace::SearchResult_NotFound:
         m_searchWidget->setFound(false);
         break;
-    case ApiTrace::SearchFound: {
+    case ApiTrace::SearchResult_Found: {
         QModelIndex index = m_proxyModel->indexForCall(call);
-        m_ui.callView->setCurrentIndex(index);
-        m_searchWidget->setFound(true);
+
+        if (index.isValid()) {
+            m_ui.callView->setCurrentIndex(index);
+            m_searchWidget->setFound(true);
+        } else {
+            //call is filtered out, so continue searching but from the
+            // filtered call
+            if (!call) {
+                qDebug()<<"Error: search success with no call";
+                return;
+            }
+//            qDebug()<<"filtered! search from "<<call->searchText()
+//                   <<", call idx = "<<call->index();
+
+            if (request.direction == ApiTrace::SearchRequest::Next) {
+                m_trace->findNext(call->parentFrame(), call,
+                                  request.text, request.cs);
+            } else {
+                m_trace->findNext(call->parentFrame(), call,
+                                  request.text, request.cs);
+            }
+        }
     }
         break;
-    case ApiTrace::SearchWrapped:
+    case ApiTrace::SearchResult_Wrapped:
         m_searchWidget->setFound(false);
         break;
     }
@@ -1151,7 +1243,7 @@ ApiTraceCall * MainWindow::currentCall() const
 
 void MainWindow::slotFoundFrameStart(ApiTraceFrame *frame)
 {
-    Q_ASSERT(frame->loaded());
+    Q_ASSERT(frame->isLoaded());
     if (!frame || frame->isEmpty()) {
         return;
     }
@@ -1173,7 +1265,7 @@ void MainWindow::slotFoundFrameStart(ApiTraceFrame *frame)
 
 void MainWindow::slotFoundFrameEnd(ApiTraceFrame *frame)
 {
-    Q_ASSERT(frame->loaded());
+    Q_ASSERT(frame->isLoaded());
     if (!frame || frame->isEmpty()) {
         return;
     }