From: Zack Rusin Date: Fri, 16 Sep 2011 00:23:27 +0000 (-0400) Subject: Show thumbnail of the color buffer in tooltips. X-Git-Url: https://git.cworth.org/git?a=commitdiff_plain;h=353f0535f43b54d04cc9c8080790ffac606e5b0b;p=apitrace Show thumbnail of the color buffer in tooltips. if we got the state for the given frame we can show a nicer tooltip with a thumbnail of the current color buffer. --- diff --git a/gui/apitracecall.cpp b/gui/apitracecall.cpp index 5ac8829..9a6a32e 100644 --- a/gui/apitracecall.cpp +++ b/gui/apitracecall.cpp @@ -537,6 +537,22 @@ const QList & 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), diff --git a/gui/apitracecall.h b/gui/apitracecall.h index 572b302..15dca13 100644 --- a/gui/apitracecall.h +++ b/gui/apitracecall.h @@ -169,6 +169,7 @@ public: const QList & textures() const; const QList & framebuffers() const; + ApiFramebuffer colorBuffer() const; private: QVariantMap m_parameters; QMap m_shaderSources; diff --git a/gui/apitracemodel.cpp b/gui/apitracemodel.cpp index 0101e33..96a9888 100644 --- a/gui/apitracemodel.cpp +++ b/gui/apitracemodel.cpp @@ -4,6 +4,7 @@ #include "traceloader.h" #include "trace_parser.hpp" +#include #include #include #include @@ -52,22 +53,53 @@ QVariant ApiTraceModel::data(const QModelIndex &index, int role) const .arg(call->name()) .arg(stateText); } else { + const char *htmlTempl = + "
\n" + "
\n" + "%1" + "\n" + "Frame %2\n" + "
\n" + "
%3 calls%4
\n" + "
\n"; + + ApiTraceFrame *frame = static_cast(itm); - QString text = QObject::tr("%1) Frame ") - .arg(frame->number); - int binaryDataSize = frame->binaryDataSize() / 1024; - if (!frame->hasState()) - return QObject::tr( - "%1 (binary data size = %2kB)") - .arg(text) - .arg(binaryDataSize); - else - return QObject::tr( - "%1 (binary data size = %2kB)" - "
%3") - .arg(text) - .arg(binaryDataSize) - .arg(stateText); + QString thumbStr, sizeStr; + + if (frame->hasState()) { + static const char *imgTempl = + "\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: