From: Zack Rusin Date: Sat, 27 Aug 2011 23:19:18 +0000 (-0400) Subject: Cleanup that file. X-Git-Tag: 2.0_alpha^2~709 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a1a3ad5737b10636a593289f21706baaee7a1f13;p=tools%2Fapitrace.git Cleanup that file. just order it to match the header --- diff --git a/gui/apitracecall.cpp b/gui/apitracecall.cpp index c3f8831..90ebca4 100644 --- a/gui/apitracecall.cpp +++ b/gui/apitracecall.cpp @@ -44,18 +44,6 @@ const char * const styleSheet = //" -moz-box-shadow: 0 1px 5px #0061aa, inset 0 10px 20px #b6f9ff;\n" "}\n"; -ApiPointer::ApiPointer(unsigned long long val) - : m_value(val) -{ -} - -QString ApiPointer::toString() const -{ - if (m_value) - return QString("0x%1").arg(m_value, 0, 16); - else - return QLatin1String("NULL"); -} // Qt::convertFromPlainText doesn't do precisely what we want static QString @@ -109,7 +97,8 @@ plainTextToHTML(const QString & plain, bool multiLine) return rich; } -QString apiVariantToString(const QVariant &variant, bool multiLine) +QString +apiVariantToString(const QVariant &variant, bool multiLine) { if (variant.userType() == QVariant::Double) { return QString::number(variant.toFloat()); @@ -151,13 +140,146 @@ QString apiVariantToString(const QVariant &variant, bool multiLine) return QString(); } + +void VariantVisitor::visit(Trace::Null *) +{ + m_variant = QVariant::fromValue(ApiPointer(0)); +} + +void VariantVisitor::visit(Trace::Bool *node) +{ + m_variant = QVariant(node->value); +} + +void VariantVisitor::visit(Trace::SInt *node) +{ + m_variant = QVariant(node->value); +} + +void VariantVisitor::visit(Trace::UInt *node) +{ + m_variant = QVariant(node->value); +} + +void VariantVisitor::visit(Trace::Float *node) +{ + m_variant = QVariant(node->value); +} + +void VariantVisitor::visit(Trace::String *node) +{ + m_variant = QVariant(QString::fromStdString(node->value)); +} + +void VariantVisitor::visit(Trace::Enum *e) +{ + QVariant val = QVariant(e->sig->value); + + m_variant = QVariant::fromValue( + ApiEnum(QString::fromStdString(e->sig->name), val)); +} + +void VariantVisitor::visit(Trace::Bitmask *bitmask) +{ + m_variant = QVariant::fromValue(ApiBitmask(bitmask)); +} + +void VariantVisitor::visit(Trace::Struct *str) +{ + m_variant = QVariant::fromValue(ApiStruct(str)); +} + +void VariantVisitor::visit(Trace::Array *array) +{ + m_variant = QVariant::fromValue(ApiArray(array)); +} + +void VariantVisitor::visit(Trace::Blob *blob) +{ + //XXX + //FIXME: this is a nasty hack. Trace::Blob's can't + // delete the contents in the destructor because + // the data is being used by other calls. We piggy back + // on that assumption and don't deep copy the data. If + // Blob's will start deleting the data we will need to + // start deep copying it or switch to using something like + // Boost's shared_ptr or Qt's QSharedPointer to handle it + QByteArray barray = QByteArray::fromRawData(blob->buf, blob->size); + m_variant = QVariant(barray); +} + +void VariantVisitor::visit(Trace::Pointer *ptr) +{ + m_variant = QVariant::fromValue(ApiPointer(ptr->value)); +} + + +ApiEnum::ApiEnum(const QString &name, const QVariant &val) + : m_name(name), + m_value(val) +{ +} + +QString ApiEnum::toString() const +{ + return m_name; +} + +QVariant ApiEnum::value() const +{ + return m_value; +} + +QString ApiEnum::name() const +{ + return m_name; +} + +unsigned long long ApiBitmask::value() const +{ + return m_value; +} + +ApiBitmask::Signature ApiBitmask::signature() const +{ + return m_sig; +} + +ApiStruct::Signature ApiStruct::signature() const +{ + return m_sig; +} + +QList ApiStruct::values() const +{ + return m_members; +} + +ApiPointer::ApiPointer(unsigned long long val) + : m_value(val) +{ +} + + +unsigned long long ApiPointer::value() const +{ + return m_value; +} + +QString ApiPointer::toString() const +{ + if (m_value) + return QString("0x%1").arg(m_value, 0, 16); + else + return QLatin1String("NULL"); +} + ApiBitmask::ApiBitmask(const Trace::Bitmask *bitmask) : m_value(0) { init(bitmask); } - void ApiBitmask::init(const Trace::Bitmask *bitmask) { if (!bitmask) @@ -239,78 +361,6 @@ void ApiStruct::init(const Trace::Struct *s) } } -void VariantVisitor::visit(Trace::Null *) -{ - m_variant = QVariant::fromValue(ApiPointer(0)); -} - -void VariantVisitor::visit(Trace::Bool *node) -{ - m_variant = QVariant(node->value); -} - -void VariantVisitor::visit(Trace::SInt *node) -{ - m_variant = QVariant(node->value); -} - -void VariantVisitor::visit(Trace::UInt *node) -{ - m_variant = QVariant(node->value); -} - -void VariantVisitor::visit(Trace::Float *node) -{ - m_variant = QVariant(node->value); -} - -void VariantVisitor::visit(Trace::String *node) -{ - m_variant = QVariant(QString::fromStdString(node->value)); -} - -void VariantVisitor::visit(Trace::Enum *e) -{ - QVariant val = QVariant(e->sig->value); - - m_variant = QVariant::fromValue( - ApiEnum(QString::fromStdString(e->sig->name), val)); -} - -void VariantVisitor::visit(Trace::Bitmask *bitmask) -{ - m_variant = QVariant::fromValue(ApiBitmask(bitmask)); -} - -void VariantVisitor::visit(Trace::Struct *str) -{ - m_variant = QVariant::fromValue(ApiStruct(str)); -} - -void VariantVisitor::visit(Trace::Array *array) -{ - m_variant = QVariant::fromValue(ApiArray(array)); -} - -void VariantVisitor::visit(Trace::Blob *blob) -{ - //XXX - //FIXME: this is a nasty hack. Trace::Blob's can't - // delete the contents in the destructor because - // the data is being used by other calls. We piggy back - // on that assumption and don't deep copy the data. If - // Blob's will start deleting the data we will need to - // start deep copying it or switch to using something like - // Boost's shared_ptr or Qt's QSharedPointer to handle it - QByteArray barray = QByteArray::fromRawData(blob->buf, blob->size); - m_variant = QVariant(barray); -} - -void VariantVisitor::visit(Trace::Pointer *ptr) -{ - m_variant = QVariant::fromValue(ApiPointer(ptr->value)); -} - ApiArray::ApiArray(const Trace::Array *arr) { init(arr); @@ -321,6 +371,11 @@ ApiArray::ApiArray(const QList &vals) { } +QList ApiArray::values() const +{ + return m_array; +} + QString ApiArray::toString() const { QString str; @@ -349,255 +404,16 @@ void ApiArray::init(const Trace::Array *arr) } } -QStaticText ApiTraceCall::staticText() const +ApiTraceState::ApiTraceState() { - if (m_staticText && !m_staticText->text().isEmpty()) - return *m_staticText; +} - QVariantList argValues = arguments(); - - QString richText = QString::fromLatin1( - "%1(").arg(m_name); - for (int i = 0; i < m_argNames.count(); ++i) { - richText += QLatin1String(""); - QString argText = apiVariantToString(argValues[i]); - - //if arguments are really long (e.g. shader text), cut them - // and elide it - if (argText.length() > 40) { - QString shortened = argText.mid(0, 40); - shortened[argText.length() - 5] = '.'; - shortened[argText.length() - 4] = '.'; - shortened[argText.length() - 3] = '.'; - shortened[argText.length() - 2] = argText[argText.length() - 2]; - shortened[argText.length() - 1] = argText[argText.length() - 1]; - richText += shortened; - } else { - richText += argText; - } - richText += QLatin1String(""); - if (i < m_argNames.count() - 1) - richText += QLatin1String(", "); - } - richText += QLatin1String(")"); - if (m_returnValue.isValid()) { - richText += - QLatin1Literal(" = ") % - QLatin1Literal("") % - apiVariantToString(m_returnValue) % - QLatin1Literal(""); - } - - if (!m_staticText) - m_staticText = new QStaticText(richText); - else - m_staticText->setText(richText); - QTextOption opt; - opt.setWrapMode(QTextOption::NoWrap); - m_staticText->setTextOption(opt); - m_staticText->prepare(); - - return *m_staticText; -} - -QString ApiTraceCall::toHtml() const -{ - if (!m_richText.isEmpty()) - return m_richText; - - m_richText = QLatin1String("
"); - - if (m_helpUrl.isEmpty()) { - m_richText += QString::fromLatin1( - "%1) %2(") - .arg(m_index) - .arg(m_name); - } else { - m_richText += QString::fromLatin1( - "%1) %3(") - .arg(m_index) - .arg(m_helpUrl.toString()) - .arg(m_name); - } - - QVariantList argValues = arguments(); - for (int i = 0; i < m_argNames.count(); ++i) { - m_richText += - QLatin1String("") + - m_argNames[i] + - QLatin1String("") + - QLatin1Literal(" = ") + - QLatin1Literal("") + - apiVariantToString(argValues[i], true) + - QLatin1Literal(""); - if (i < m_argNames.count() - 1) - m_richText += QLatin1String(", "); - } - m_richText += QLatin1String(")"); - - if (m_returnValue.isValid()) { - m_richText += - QLatin1String(" = ") + - QLatin1String("") + - apiVariantToString(m_returnValue, true) + - QLatin1String(""); - } - m_richText += QLatin1String("
"); - - if (hasError()) { - QString errorStr = - QString::fromLatin1( - "
%1
") - .arg(m_error); - m_richText += errorStr; - } - - m_richText = - QString::fromLatin1( - "%2") - .arg(styleSheet) - .arg(m_richText); - m_richText.squeeze(); - - //qDebug()<text().isEmpty()) - return *m_staticText; - - QString richText; - - //mark the frame if it uploads more than a meg a frame - if (m_binaryDataSize > (1024*1024)) { - richText = - QObject::tr( - "" - "Frame %1" - "" - "    (%2MB)") - .arg(number) - .arg(double(m_binaryDataSize / (1024.*1024.)), 0, 'g', 2); - } else { - richText = - QObject::tr( - "Frame %1") - .arg(number); - } - - if (!m_staticText) - m_staticText = new QStaticText(richText); - - QTextOption opt; - opt.setWrapMode(QTextOption::NoWrap); - m_staticText->setTextOption(opt); - m_staticText->prepare(); - - return *m_staticText; -} - -int ApiTraceCall::numChildren() const -{ - return 0; -} - -int ApiTraceFrame::numChildren() const -{ - return m_calls.count(); -} - -ApiTraceFrame::ApiTraceFrame() - : ApiTraceEvent(ApiTraceEvent::Frame), - m_parentTrace(0), - m_binaryDataSize(0) -{ -} - -ApiTraceCall::ApiTraceCall() - : ApiTraceEvent(ApiTraceEvent::Call), - m_hasBinaryData(false), - m_binaryDataIndex(0) -{ -} - -ApiTraceEvent::ApiTraceEvent() - : m_type(ApiTraceEvent::None), - m_staticText(0) -{ -} - -ApiTraceEvent::ApiTraceEvent(Type t) - : m_type(t), - m_staticText(0) -{ -} - -ApiTraceCall::~ApiTraceCall() -{ -} - -QVariantMap ApiTraceEvent::stateParameters() const -{ - return m_state.parameters(); -} - -ApiTraceState ApiTraceEvent::state() const -{ - return m_state; -} - -void ApiTraceEvent::setState(const ApiTraceState &state) -{ - m_state = state; -} - -bool ApiTraceCall::hasBinaryData() const -{ - return m_hasBinaryData; -} - -int ApiTraceCall::binaryDataIndex() const -{ - return m_binaryDataIndex; -} - -ApiTraceState::ApiTraceState() -{ -} - -ApiTraceState::ApiTraceState(const QVariantMap &parsedJson) -{ - m_parameters = parsedJson[QLatin1String("parameters")].toMap(); - QVariantMap attachedShaders = - parsedJson[QLatin1String("shaders")].toMap(); - QVariantMap::const_iterator itr; +ApiTraceState::ApiTraceState(const QVariantMap &parsedJson) +{ + m_parameters = parsedJson[QLatin1String("parameters")].toMap(); + QVariantMap attachedShaders = + parsedJson[QLatin1String("shaders")].toMap(); + QVariantMap::const_iterator itr; for (itr = attachedShaders.constBegin(); itr != attachedShaders.constEnd(); @@ -693,43 +509,46 @@ const QList & ApiTraceState::framebuffers() const return m_framebuffers; } -QList ApiArray::values() const +ApiTraceEvent::ApiTraceEvent() + : m_type(ApiTraceEvent::None), + m_staticText(0) { - return m_array; } -int ApiTraceCall::index() const +ApiTraceEvent::ApiTraceEvent(Type t) + : m_type(t), + m_staticText(0) { - return m_index; } -QString ApiTraceCall::name() const +ApiTraceEvent::~ApiTraceEvent() { - return m_name; + delete m_staticText; } -QStringList ApiTraceCall::argNames() const +QVariantMap ApiTraceEvent::stateParameters() const { - return m_argNames; + return m_state.parameters(); } -QVariantList ApiTraceCall::arguments() const +ApiTraceState ApiTraceEvent::state() const { - if (m_editedValues.isEmpty()) - return m_argValues; - else - return m_editedValues; + return m_state; } -QVariant ApiTraceCall::returnValue() const +void ApiTraceEvent::setState(const ApiTraceState &state) +{ + m_state = state; +} + + +ApiTraceCall::ApiTraceCall() + : ApiTraceEvent(ApiTraceEvent::Call), + m_hasBinaryData(false), + m_binaryDataIndex(0) { - return m_returnValue; } -QUrl ApiTraceCall::helpUrl() const -{ - return m_helpUrl; -} ApiTraceCall::ApiTraceCall(const Trace::Call *call) : ApiTraceEvent(ApiTraceEvent::Call), @@ -760,39 +579,37 @@ ApiTraceCall::ApiTraceCall(const Trace::Call *call) } } -void ApiTraceCall::setHelpUrl(const QUrl &url) -{ - m_helpUrl = url; -} - -void ApiTraceCall::setParentFrame(ApiTraceFrame *frame) +ApiTraceCall::~ApiTraceCall() { - m_parentFrame = frame; } -ApiTraceFrame * ApiTraceCall::parentFrame()const -{ - return m_parentFrame; -} -ApiTraceEvent::~ApiTraceEvent() +bool ApiTraceCall::hasError() const { - delete m_staticText; + return !m_error.isEmpty(); } -void ApiTraceCall::revert() +QString ApiTraceCall::error() const { - setEditedValues(QVariantList()); + return m_error; } -ApiTrace * ApiTraceFrame::parentTrace() const +void ApiTraceCall::setError(const QString &msg) { - return m_parentTrace; + if (m_error != msg) { + ApiTrace *trace = parentTrace(); + m_error = msg; + m_richText = QString(); + if (trace) + trace->callError(this); + } } -void ApiTraceFrame::setParentTrace(ApiTrace *trace) +ApiTrace * ApiTraceCall::parentTrace() const { - m_parentTrace = trace; + if (m_parentFrame) + return m_parentFrame->parentTrace(); + return NULL; } QVariantList ApiTraceCall::originalValues() const @@ -830,78 +647,268 @@ bool ApiTraceCall::edited() const return !m_editedValues.isEmpty(); } -ApiEnum::ApiEnum(const QString &name, const QVariant &val) - : m_name(name), - m_value(val) +void ApiTraceCall::revert() { + setEditedValues(QVariantList()); } -QString ApiEnum::toString() const +void ApiTraceCall::setHelpUrl(const QUrl &url) { - return m_name; + m_helpUrl = url; } -QVariant ApiEnum::value() const +void ApiTraceCall::setParentFrame(ApiTraceFrame *frame) { - return m_value; + m_parentFrame = frame; } -QString ApiEnum::name() const +ApiTraceFrame * ApiTraceCall::parentFrame()const +{ + return m_parentFrame; +} + +int ApiTraceCall::index() const +{ + return m_index; +} + +QString ApiTraceCall::name() const { return m_name; } -unsigned long long ApiBitmask::value() const +QStringList ApiTraceCall::argNames() const { - return m_value; + return m_argNames; } -ApiBitmask::Signature ApiBitmask::signature() const +QVariantList ApiTraceCall::arguments() const { - return m_sig; + if (m_editedValues.isEmpty()) + return m_argValues; + else + return m_editedValues; } -ApiStruct::Signature ApiStruct::signature() const +QVariant ApiTraceCall::returnValue() const { - return m_sig; + return m_returnValue; } -QList ApiStruct::values() const +QUrl ApiTraceCall::helpUrl() const { - return m_members; + return m_helpUrl; } -unsigned long long ApiPointer::value() const +bool ApiTraceCall::hasBinaryData() const { - return m_value; + return m_hasBinaryData; } -bool ApiTraceCall::hasError() const +int ApiTraceCall::binaryDataIndex() const { - return !m_error.isEmpty(); + return m_binaryDataIndex; } -QString ApiTraceCall::error() const +QStaticText ApiTraceCall::staticText() const { - return m_error; + if (m_staticText && !m_staticText->text().isEmpty()) + return *m_staticText; + + QVariantList argValues = arguments(); + + QString richText = QString::fromLatin1( + "%1(").arg(m_name); + for (int i = 0; i < m_argNames.count(); ++i) { + richText += QLatin1String(""); + QString argText = apiVariantToString(argValues[i]); + + //if arguments are really long (e.g. shader text), cut them + // and elide it + if (argText.length() > 40) { + QString shortened = argText.mid(0, 40); + shortened[argText.length() - 5] = '.'; + shortened[argText.length() - 4] = '.'; + shortened[argText.length() - 3] = '.'; + shortened[argText.length() - 2] = argText[argText.length() - 2]; + shortened[argText.length() - 1] = argText[argText.length() - 1]; + richText += shortened; + } else { + richText += argText; + } + richText += QLatin1String(""); + if (i < m_argNames.count() - 1) + richText += QLatin1String(", "); + } + richText += QLatin1String(")"); + if (m_returnValue.isValid()) { + richText += + QLatin1Literal(" = ") % + QLatin1Literal("") % + apiVariantToString(m_returnValue) % + QLatin1Literal(""); + } + + if (!m_staticText) + m_staticText = new QStaticText(richText); + else + m_staticText->setText(richText); + QTextOption opt; + opt.setWrapMode(QTextOption::NoWrap); + m_staticText->setTextOption(opt); + m_staticText->prepare(); + + return *m_staticText; } -void ApiTraceCall::setError(const QString &msg) +QString ApiTraceCall::toHtml() const { - if (m_error != msg) { - ApiTrace *trace = parentTrace(); - m_error = msg; - m_richText = QString(); - if (trace) - trace->callError(this); + if (!m_richText.isEmpty()) + return m_richText; + + m_richText = QLatin1String("
"); + + if (m_helpUrl.isEmpty()) { + m_richText += QString::fromLatin1( + "%1) %2(") + .arg(m_index) + .arg(m_name); + } else { + m_richText += QString::fromLatin1( + "%1) %3(") + .arg(m_index) + .arg(m_helpUrl.toString()) + .arg(m_name); } + + QVariantList argValues = arguments(); + for (int i = 0; i < m_argNames.count(); ++i) { + m_richText += + QLatin1String("") + + m_argNames[i] + + QLatin1String("") + + QLatin1Literal(" = ") + + QLatin1Literal("") + + apiVariantToString(argValues[i], true) + + QLatin1Literal(""); + if (i < m_argNames.count() - 1) + m_richText += QLatin1String(", "); + } + m_richText += QLatin1String(")"); + + if (m_returnValue.isValid()) { + m_richText += + QLatin1String(" = ") + + QLatin1String("") + + apiVariantToString(m_returnValue, true) + + QLatin1String(""); + } + m_richText += QLatin1String("
"); + + if (hasError()) { + QString errorStr = + QString::fromLatin1( + "
%1
") + .arg(m_error); + m_richText += errorStr; + } + + m_richText = + QString::fromLatin1( + "%2") + .arg(styleSheet) + .arg(m_richText); + m_richText.squeeze(); + + //qDebug()<parentTrace(); - return NULL; +} + +QStaticText ApiTraceFrame::staticText() const +{ + if (m_staticText && !m_staticText->text().isEmpty()) + return *m_staticText; + + QString richText; + + //mark the frame if it uploads more than a meg a frame + if (m_binaryDataSize > (1024*1024)) { + richText = + QObject::tr( + "" + "Frame %1" + "" + "    (%2MB)") + .arg(number) + .arg(double(m_binaryDataSize / (1024.*1024.)), 0, 'g', 2); + } else { + richText = + QObject::tr( + "Frame %1") + .arg(number); + } + + if (!m_staticText) + m_staticText = new QStaticText(richText); + + QTextOption opt; + opt.setWrapMode(QTextOption::NoWrap); + m_staticText->setTextOption(opt); + m_staticText->prepare(); + + return *m_staticText; +} + +int ApiTraceFrame::numChildren() const +{ + return m_calls.count(); +} + +ApiTrace * ApiTraceFrame::parentTrace() const +{ + return m_parentTrace; +} + +void ApiTraceFrame::setParentTrace(ApiTrace *trace) +{ + m_parentTrace = trace; } void ApiTraceFrame::addCall(ApiTraceCall *call) @@ -938,4 +945,3 @@ int ApiTraceFrame::binaryDataSize() const { return m_binaryDataSize; } -