[PATCH 2/2] Display captured snapshots as thumbnails.

Dan McCabe zen3d.linux at gmail.com
Wed Feb 29 11:56:28 PST 2012


Once snapshots are captured after being generated by glretrace, they are
then displayed in the GUI app, qapitrace.

The retracer passes a list of images to the main window. The main window
in turn binds those images to the ApiTraceFrames for later display.

When the ApiTrace events are later displayed, when a frame is being
display, its snapshot image is queried. If an image is available, it is
reduced to create a thumbnail. That thumbnail is then displayed at the
front of the line for a frame.

One bug still exists. The thumbnail only gets displayed when the user
interacts with the window.
---
 gui/apicalldelegate.cpp |   18 +++++++++++++++---
 gui/apitrace.cpp        |   10 ++++++++++
 gui/apitrace.h          |    2 ++
 gui/apitracecall.cpp    |   10 ++++++++++
 gui/apitracecall.h      |    5 +++++
 gui/mainwindow.cpp      |    2 ++
 6 files changed, 44 insertions(+), 3 deletions(-)

diff --git a/gui/apicalldelegate.cpp b/gui/apicalldelegate.cpp
index 11ed3a5..353803a 100644
--- a/gui/apicalldelegate.cpp
+++ b/gui/apicalldelegate.cpp
@@ -27,17 +27,29 @@ void ApiCallDelegate::paint(QPainter *painter,
     Q_ASSERT(index.column() == 0);
 
     if (event) {
-        QPoint offset;
+        QPoint offset = QPoint(0, 0);
         QStaticText text = event->staticText();
         //text.setTextWidth(option.rect.width());
         //QStyledItemDelegate::paint(painter, option, index);
         QStyle *style = QApplication::style();
         style->drawControl(QStyle::CE_ItemViewItem, &option, painter, 0);
+
+        // draw thumbnail of frame
+        if (event->type() == ApiTraceEvent::Frame) {
+            ApiTraceFrame *frame = static_cast<ApiTraceFrame *>(event);
+            QImage snap = frame->snap();
+            if (!snap.isNull()) {
+                QImage thumbnail = snap.scaled(16, 16, Qt::KeepAspectRatio, Qt::FastTransformation);
+                painter->drawImage(option.rect.topLeft() + offset, thumbnail);
+                offset += QPoint(option.rect.height() + 16, 0);
+            }
+        }
+
         if (event->hasState()) {
             QPixmap px = m_stateEmblem.pixmap(option.rect.height(),
                                               option.rect.height());
-            painter->drawPixmap(option.rect.topLeft(), px);
-            offset = QPoint(option.rect.height() + 5, 0);
+            painter->drawPixmap(option.rect.topLeft() + offset, px);
+            offset += QPoint(option.rect.height() + 5, 0);
         }
         if (event->type() == ApiTraceEvent::Call) {
             ApiTraceCall *call = static_cast<ApiTraceCall*>(event);
diff --git a/gui/apitrace.cpp b/gui/apitrace.cpp
index 5758b07..ee557ca 100644
--- a/gui/apitrace.cpp
+++ b/gui/apitrace.cpp
@@ -496,4 +496,14 @@ bool ApiTrace::isFrameLoading(ApiTraceFrame *frame) const
     return m_loadingFrames.contains(frame);
 }
 
+void ApiTrace::bindSnapsToFrames(QList<QImage> *snaps)
+{
+    QList<ApiTraceFrame *> frames = this->m_frames;
+
+    for (int idx = 0; idx < frames.count(); ++idx) {
+        ApiTraceFrame *frame = frames.at(idx);
+        frame->setSnap(snaps->at(idx));
+    }
+}
+
 #include "apitrace.moc"
diff --git a/gui/apitrace.h b/gui/apitrace.h
index 2833f60..2d1714b 100644
--- a/gui/apitrace.h
+++ b/gui/apitrace.h
@@ -83,6 +83,8 @@ public:
 
     bool hasErrors() const;
 
+    void bindSnapsToFrames(QList<QImage> *snaps);
+
 public slots:
     void setFileName(const QString &name);
     void save();
diff --git a/gui/apitracecall.cpp b/gui/apitracecall.cpp
index 267dc09..d9d878f 100644
--- a/gui/apitracecall.cpp
+++ b/gui/apitracecall.cpp
@@ -1197,3 +1197,13 @@ unsigned ApiTraceFrame::lastCallIndex() const
         return m_lastCallIndex;
     }
 }
+
+QImage ApiTraceFrame::snap() const
+{
+    return m_snap;
+}
+
+void ApiTraceFrame::setSnap(QImage snap)
+{
+    m_snap = snap;
+}
diff --git a/gui/apitracecall.h b/gui/apitracecall.h
index 3a9faaf..8be4476 100644
--- a/gui/apitracecall.h
+++ b/gui/apitracecall.h
@@ -335,6 +335,10 @@ public:
 
     void setLastCallIndex(unsigned index);
     unsigned lastCallIndex() const;
+
+    QImage snap() const;
+    void setSnap(QImage snap);
+
 private:
     ApiTrace *m_parentTrace;
     quint64 m_binaryDataSize;
@@ -342,6 +346,7 @@ private:
     bool m_loaded;
     unsigned m_callsToLoad;
     unsigned m_lastCallIndex;
+    QImage m_snap;
 };
 Q_DECLARE_METATYPE(ApiTraceFrame*);
 
diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp
index 20a32e7..806af77 100644
--- a/gui/mainwindow.cpp
+++ b/gui/mainwindow.cpp
@@ -850,6 +850,8 @@ void MainWindow::replayStateFound(ApiTraceState *state)
 void MainWindow::replaySnapsFound(QList<QImage> *snaps)
 {
     m_snaps = snaps;
+
+    m_trace->bindSnapsToFrames(snaps);
 }
 
 void MainWindow::slotGoTo()
-- 
1.7.5.4



More information about the apitrace mailing list