]> git.cworth.org Git - apitrace/commitdiff
Show thumbnail of the color buffer in tooltips.
authorZack Rusin <zack@kde.org>
Fri, 16 Sep 2011 00:23:27 +0000 (20:23 -0400)
committerZack Rusin <zack@kde.org>
Fri, 16 Sep 2011 00:23:27 +0000 (20:23 -0400)
if we got the state for the given frame we can show
a nicer tooltip with a thumbnail of the current color buffer.

gui/apitracecall.cpp
gui/apitracecall.h
gui/apitracemodel.cpp

index 5ac88292399cf225212e9db95dbbe484b87f1bfa..9a6a32e967a0a027bcf07eb7ad467e3a9c34278f 100644 (file)
@@ -537,6 +537,22 @@ const QList<ApiFramebuffer> & ApiTraceState::framebuffers() const
     return m_framebuffers;
 }
 
+ApiFramebuffer ApiTraceState::colorBuffer() const
+{
+    foreach (ApiFramebuffer fbo, m_framebuffers) {
+        if (fbo.type() == QLatin1String("GL_BACK")) {
+            return fbo;
+        }
+    }
+    foreach (ApiFramebuffer fbo, m_framebuffers) {
+        if (fbo.type() == QLatin1String("GL_FRONT")) {
+            return fbo;
+        }
+    }
+    return ApiFramebuffer();
+}
+
+
 ApiTraceCallSignature::ApiTraceCallSignature(const QString &name,
                                              const QStringList &argNames)
     : m_name(name),
index 572b302b643ab23957cdf79c9851b19fdc0e0367..15dca1321ece3703f50073020c1ab82ce350b9ec 100644 (file)
@@ -169,6 +169,7 @@ public:
     const QList<ApiTexture> & textures() const;
     const QList<ApiFramebuffer> & framebuffers() const;
 
+    ApiFramebuffer colorBuffer() const;
 private:
     QVariantMap m_parameters;
     QMap<QString, QString> m_shaderSources;
index 0101e331ca27696f477a37445e2d5323fdb3b718..96a9888ed63e057be2c068517a8b9f922d964df9 100644 (file)
@@ -4,6 +4,7 @@
 #include "traceloader.h"
 #include "trace_parser.hpp"
 
+#include <QBuffer>
 #include <QDebug>
 #include <QImage>
 #include <QVariant>
@@ -52,22 +53,53 @@ QVariant ApiTraceModel::data(const QModelIndex &index, int role) const
                     .arg(call->name())
                     .arg(stateText);
         } else {
+            const char *htmlTempl =
+                    "<div>\n"
+                    "<div>\n"
+                    "%1"
+                    "<span style=\"font-weight:bold; font-size:large; vertical-align:center; padding-bottom: 30px \">\n"
+                    "Frame %2</span>\n"
+                    "</div>\n"
+                    "<div >%3 calls%4</div>\n"
+                    "</div>\n";
+
+
             ApiTraceFrame *frame = static_cast<ApiTraceFrame*>(itm);
-            QString text = QObject::tr("%1)&nbsp;Frame&nbsp;")
-                           .arg(frame->number);
-            int binaryDataSize = frame->binaryDataSize() / 1024;
-            if (!frame->hasState())
-                return QObject::tr(
-                    "<b>%1&nbsp;</b>(binary&nbsp;data&nbsp;size&nbsp;=&nbsp;%2kB)")
-                    .arg(text)
-                    .arg(binaryDataSize);
-            else
-                return QObject::tr(
-                    "<b>%1&nbsp;(binary&nbsp;data&nbsp;size&nbsp;=&nbsp;%2kB)</b>"
-                    "<br/>%3")
-                    .arg(text)
-                    .arg(binaryDataSize)
-                    .arg(stateText);
+            QString thumbStr, sizeStr;
+
+            if (frame->hasState()) {
+                static const char *imgTempl =
+                        "<img style=\"float:left;\" "
+                        "src=\"data:image/png;base64,%1\"/>\n";
+                static const char *sizeTempl =
+                        ", %1kb";
+
+                ApiFramebuffer fbo = frame->state()->colorBuffer();
+                QImage thumb = fbo.thumb();
+                if (!thumb.isNull()) {
+                    QByteArray ba;
+                    QBuffer buffer(&ba);
+                    buffer.open(QIODevice::WriteOnly);
+                    thumb.save(&buffer, "PNG");
+                    thumbStr = tr(imgTempl).arg(
+                                QString(buffer.data().toBase64()));
+                }
+
+                int binaryDataSize = frame->binaryDataSize() / 1024;
+                if (binaryDataSize > 0) {
+                    sizeStr = tr(sizeTempl).arg(binaryDataSize);
+                }
+            }
+
+            int numCalls = frame->loaded()
+                    ? frame->numChildren()
+                    : frame->numChildrenToLoad();
+
+            return tr(htmlTempl)
+                    .arg(thumbStr)
+                    .arg(frame->number)
+                    .arg(numCalls)
+                    .arg(sizeStr);
         }
     }
     case ApiTraceModel::EventRole: