]> git.cworth.org Git - apitrace/blobdiff - gui/mainwindow.cpp
Reduce the size of ApiTraceCall, ApiTraceEvent and ApiTraceFrame
[apitrace] / gui / mainwindow.cpp
index 9d8748d7699fe0c8e624d6bbdfaaa25259bf9425..5072db74000f032b10eb94141287df58e1267287 100644 (file)
@@ -132,7 +132,7 @@ void MainWindow::callItemSelected(const QModelIndex &index)
         m_ui.detailsDock->hide();
         m_ui.vertexDataDock->hide();
     }
-    if (m_selectedEvent && !m_selectedEvent->state().isEmpty()) {
+    if (m_selectedEvent && m_selectedEvent->hasState()) {
         fillStateForFrame();
     } else
         m_ui.stateDock->hide();
@@ -464,9 +464,7 @@ static void addSurfaceItem(const ApiSurface &surface,
 
 void MainWindow::fillStateForFrame()
 {
-    QVariantMap params;
-
-    if (!m_selectedEvent || m_selectedEvent->state().isEmpty())
+    if (!m_selectedEvent || !m_selectedEvent->hasState())
         return;
 
     if (m_nonDefaultsLookupEvent) {
@@ -482,11 +480,10 @@ void MainWindow::fillStateForFrame()
         defaultParams = defaultState.parameters();
     }
 
-    const ApiTraceState &state = m_selectedEvent->state();
+    const ApiTraceState &state = *m_selectedEvent->state();
     m_ui.stateTreeWidget->clear();
-    params = state.parameters();
     QList<QTreeWidgetItem *> items;
-    variantMapToItems(params, defaultParams, items);
+    variantMapToItems(state.parameters(), defaultParams, items);
     m_ui.stateTreeWidget->insertTopLevelItems(0, items);
 
     QMap<QString, QString> shaderSources = state.shaderSources();
@@ -496,6 +493,11 @@ void MainWindow::fillStateForFrame()
         m_sourcesWidget->setShaders(shaderSources);
     }
 
+    m_ui.uniformsTreeWidget->clear();
+    QList<QTreeWidgetItem *> uniformsItems;
+    variantMapToItems(state.uniforms(), QVariantMap(), uniformsItems);
+    m_ui.uniformsTreeWidget->insertTopLevelItems(0, uniformsItems);
+
     const QList<ApiTexture> &textures =
         state.textures();
     const QList<ApiFramebuffer> &fbos =
@@ -562,12 +564,17 @@ void MainWindow::showSurfacesMenu(const QPoint &pos)
         return;
 
     QMenu menu(tr("Surfaces"), this);
-    //add needed actions
+
     QAction *act = menu.addAction(tr("View Image"));
     act->setStatusTip(tr("View the currently selected surface"));
     connect(act, SIGNAL(triggered()),
             SLOT(showSelectedSurface()));
 
+    act = menu.addAction(tr("Save Image"));
+    act->setStatusTip(tr("Save the currently selected surface"));
+    connect(act, SIGNAL(triggered()),
+            SLOT(saveSelectedSurface()));
+
     menu.exec(tree->viewport()->mapToGlobal(pos));
 }
 
@@ -605,6 +612,7 @@ void MainWindow::showSelectedSurface()
 void MainWindow::initObjects()
 {
     m_ui.stateTreeWidget->sortByColumn(0, Qt::AscendingOrder);
+    m_ui.uniformsTreeWidget->sortByColumn(0, Qt::AscendingOrder);
 
     m_sourcesWidget = new ShadersSourceWidget(m_ui.shadersTab);
     QVBoxLayout *layout = new QVBoxLayout;
@@ -686,8 +694,8 @@ void MainWindow::initConnections()
             this, SLOT(replayFinished(const QString&)));
     connect(m_retracer, SIGNAL(error(const QString&)),
             this, SLOT(replayError(const QString&)));
-    connect(m_retracer, SIGNAL(foundState(const ApiTraceState&)),
-            this, SLOT(replayStateFound(const ApiTraceState&)));
+    connect(m_retracer, SIGNAL(foundState(ApiTraceState*)),
+            this, SLOT(replayStateFound(ApiTraceState*)));
     connect(m_retracer, SIGNAL(retraceErrors(const QList<RetraceError>&)),
             this, SLOT(slotRetraceErrors(const QList<RetraceError>&)));
 
@@ -770,7 +778,7 @@ void MainWindow::initConnections()
             this, SLOT(slotErrorSelected(QTreeWidgetItem*)));
 }
 
-void MainWindow::replayStateFound(const ApiTraceState &state)
+void MainWindow::replayStateFound(ApiTraceState *state)
 {
     m_stateEvent->setState(state);
     m_model->stateSetOnEvent(m_stateEvent);
@@ -857,7 +865,7 @@ void MainWindow::slotSearchNext(const QString &str,
         /* if it's not valid it means that the proxy model has already
          * filtered it out */
         if (index.isValid()) {
-            QString txt = testCall->filterText();
+            QString txt = testCall->searchText();
             if (txt.contains(str, sensitivity)) {
                 m_ui.callView->setCurrentIndex(index);
                 m_searchWidget->setFound(true);
@@ -908,7 +916,7 @@ void MainWindow::slotSearchPrev(const QString &str,
         /* if it's not valid it means that the proxy model has already
          * filtered it out */
         if (index.isValid()) {
-            QString txt = testCall->filterText();
+            QString txt = testCall->searchText();
             if (txt.contains(str, sensitivity)) {
                 m_ui.callView->setCurrentIndex(index);
                 m_searchWidget->setFound(true);
@@ -927,17 +935,6 @@ void MainWindow::fillState(bool nonDefaults)
             m_ui.nonDefaultsCB->blockSignals(true);
             m_ui.nonDefaultsCB->setChecked(false);
             m_ui.nonDefaultsCB->blockSignals(false);
-            int ret = QMessageBox::question(
-                this, tr("Empty Default State"),
-                tr("The applcation needs to figure out the "
-                   "default state for the current trace. "
-                   "This only has to be done once and "
-                   "afterwards you will be able to enable "
-                   "displaying of non default state for all calls."
-                   "\nDo you want to lookup the default state now?"),
-                QMessageBox::Yes | QMessageBox::No);
-            if (ret != QMessageBox::Yes)
-                return;
             ApiTraceFrame *firstFrame =
                 m_trace->frameAt(0);
             ApiTraceEvent *oldSelected = m_selectedEvent;
@@ -1108,4 +1105,57 @@ ApiTraceCall * MainWindow::currentCall() const
     return NULL;
 }
 
+void MainWindow::saveSelectedSurface()
+{
+    QTreeWidgetItem *item =
+        m_ui.surfacesTreeWidget->currentItem();
+
+    if (!item || !m_trace)
+        return;
+
+    QVariant var = item->data(0, Qt::UserRole);
+    QImage img = var.value<QImage>();
+
+    QString imageIndex;
+    if (currentCall()) {
+        imageIndex = tr("_call_%1")
+                     .arg(currentCall()->index());
+    } else if (currentFrame()) {
+        ApiTraceCall *firstCall = currentFrame()->call(0);
+        if (firstCall) {
+            imageIndex = tr("_frame_%1")
+                         .arg(firstCall->index());
+        } else {
+            qDebug()<<"unknown frame number";
+            imageIndex = tr("_frame_%1")
+                         .arg(firstCall->index());
+        }
+    }
+
+    //which of the surfaces are we saving
+    QTreeWidgetItem *parent = item->parent();
+    int parentIndex =
+        m_ui.surfacesTreeWidget->indexOfTopLevelItem(parent);
+    if (parentIndex < 0) {
+        parentIndex = 0;
+    }
+    int childIndex = 0;
+    if (parent) {
+        childIndex = parent->indexOfChild(item);
+    } else {
+        childIndex = m_ui.surfacesTreeWidget->indexOfTopLevelItem(item);
+    }
+
+
+    QString fileName =
+        tr("%1%2-%3_%4.png")
+        .arg(m_trace->fileName())
+        .arg(imageIndex)
+        .arg(parentIndex)
+        .arg(childIndex);
+    //qDebug()<<"save "<<fileName;
+    img.save(fileName, "PNG");
+    statusBar()->showMessage( tr("Saved '%1'").arg(fileName), 5000);
+}
+
 #include "mainwindow.moc"