From 5dfeb70fc60f1c4752697d8ad6f80e1415213197 Mon Sep 17 00:00:00 2001 From: Joel Holdsworth Date: Sat, 30 Nov 2013 22:58:28 +0000 Subject: [PATCH] Paint the unresolved area to show the decode progress --- pv/data/decoderstack.cpp | 16 ++++++- pv/data/decoderstack.h | 3 ++ pv/view/decode/annotation.cpp | 3 +- pv/view/decodetrace.cpp | 88 ++++++++++++++++++++++++++++++----- pv/view/decodetrace.h | 4 ++ pv/view/trace.cpp | 2 + 6 files changed, 101 insertions(+), 15 deletions(-) diff --git a/pv/data/decoderstack.cpp b/pv/data/decoderstack.cpp index bc26f9fc..d6fa17ca 100644 --- a/pv/data/decoderstack.cpp +++ b/pv/data/decoderstack.cpp @@ -47,7 +47,8 @@ const int64_t DecoderStack::DecodeChunkLength = 4096; mutex DecoderStack::_global_decode_mutex; -DecoderStack::DecoderStack(const srd_decoder *const dec) +DecoderStack::DecoderStack(const srd_decoder *const dec) : + _samples_decoded(0) { _stack.push_back(shared_ptr( new decode::Decoder(dec))); @@ -87,6 +88,12 @@ void DecoderStack::remove(int index) _stack.erase(iter); } +int64_t DecoderStack::samples_decoded() const +{ + lock_guard decode_lock(_mutex); + return _samples_decoded; +} + const vector< shared_ptr > DecoderStack::annotations() const { @@ -108,6 +115,8 @@ void DecoderStack::begin_decode() _decode_thread.interrupt(); _decode_thread.join(); + _samples_decoded = 0; + _annotations.clear(); // We get the logic data of the first probe in the list. @@ -200,6 +209,11 @@ void DecoderStack::decode_proc(shared_ptr data) _error_message = tr("Failed to initialise decoder"); break; } + + { + lock_guard lock(_mutex); + _samples_decoded = chunk_end; + } } // Destroy the session diff --git a/pv/data/decoderstack.h b/pv/data/decoderstack.h index fe03df0a..4de7ae4c 100644 --- a/pv/data/decoderstack.h +++ b/pv/data/decoderstack.h @@ -76,6 +76,8 @@ public: void push(boost::shared_ptr decoder); void remove(int index); + int64_t samples_decoded() const; + const std::vector< boost::shared_ptr > annotations() const; @@ -107,6 +109,7 @@ private: std::list< boost::shared_ptr > _stack; mutable boost::mutex _mutex; + int64_t _samples_decoded; std::vector< boost::shared_ptr > _annotations; QString _error_message; diff --git a/pv/view/decode/annotation.cpp b/pv/view/decode/annotation.cpp index 7650b29e..a2db331d 100644 --- a/pv/view/decode/annotation.cpp +++ b/pv/view/decode/annotation.cpp @@ -67,11 +67,10 @@ Annotation::Annotation(const srd_proto_data *const pdata) : } } -void Annotation::paint(QPainter &p, QColor text_color, int text_height, +void Annotation::paint(QPainter &p, QColor text_color, int h, int left, int right, double samples_per_pixel, double pixels_offset, int y) { - const int h = (text_height * 5) / 4; const double start = _start_sample / samples_per_pixel - pixels_offset; const double end = _end_sample / samples_per_pixel - diff --git a/pv/view/decodetrace.cpp b/pv/view/decodetrace.cpp index b67c0f7a..beb83b1f 100644 --- a/pv/view/decodetrace.cpp +++ b/pv/view/decodetrace.cpp @@ -38,6 +38,8 @@ extern "C" { #include #include #include +#include +#include #include #include #include @@ -58,6 +60,7 @@ const QColor DecodeTrace::DecodeColours[4] = { }; const QColor DecodeTrace::ErrorBgColour = QColor(0xEF, 0x29, 0x29); +const QColor DecodeTrace::NoDecodeColour = QColor(0x88, 0x8A, 0x85); DecodeTrace::DecodeTrace(pv::SigSession &session, boost::shared_ptr decoder_stack, int index) : @@ -93,6 +96,7 @@ void DecodeTrace::set_view(pv::view::View *view) void DecodeTrace::paint_back(QPainter &p, int left, int right) { + Trace::paint_back(p, left, right); paint_axis(p, get_y(), left, right); } @@ -100,16 +104,6 @@ void DecodeTrace::paint_mid(QPainter &p, int left, int right) { using namespace pv::view::decode; - assert(_decoder_stack); - const QString err = _decoder_stack->error_message(); - if (!err.isEmpty()) { - draw_error(p, err, left, right); - return; - } - - assert(_view); - const int y = get_y(); - const double scale = _view->scale(); assert(scale > 0); @@ -123,13 +117,31 @@ void DecodeTrace::paint_mid(QPainter &p, int left, int right) _decoder_stack->get_start_time()) / scale; const double samples_per_pixel = samplerate * scale; + const int h = (_text_size.height() * 5) / 4; + + assert(_decoder_stack); + const QString err = _decoder_stack->error_message(); + if (!err.isEmpty()) + { + draw_error(p, err, left, right); + draw_unresolved_period(p, h, left, right, samples_per_pixel, + pixels_offset); + return; + } + + assert(_view); + const int y = get_y(); + assert(_decoder_stack); vector< shared_ptr > annotations(_decoder_stack->annotations()); BOOST_FOREACH(shared_ptr a, annotations) { assert(a); - a->paint(p, get_text_colour(), _text_size.height(), - left, right, samples_per_pixel, pixels_offset, y); + a->paint(p, get_text_colour(), h, left, right, + samples_per_pixel, pixels_offset, y); } + + draw_unresolved_period(p, h, left, right, + samples_per_pixel, pixels_offset); } void DecodeTrace::populate_popup_form(QWidget *parent, QFormLayout *form) @@ -219,6 +231,58 @@ void DecodeTrace::draw_error(QPainter &p, const QString &message, p.drawText(text_rect, message); } +void DecodeTrace::draw_unresolved_period(QPainter &p, int h, int left, + int right, double samples_per_pixel, double pixels_offset) +{ + using namespace pv::data; + using pv::data::decode::Decoder; + + assert(_decoder_stack); + + shared_ptr data; + shared_ptr logic_signal; + + const list< shared_ptr > &stack = _decoder_stack->stack(); + + // We get the logic data of the first probe in the list. + // This works because we are currently assuming all + // LogicSignals have the same data/snapshot + BOOST_FOREACH (const shared_ptr &dec, stack) + if (dec && !dec->probes().empty() && + ((logic_signal = (*dec->probes().begin()).second)) && + ((data = logic_signal->data()))) + break; + + if (!data || data->get_snapshots().empty()) + return; + + const shared_ptr snapshot = + data->get_snapshots().front(); + assert(snapshot); + const int64_t sample_count = (int64_t)snapshot->get_sample_count(); + if (sample_count == 0) + return; + + const int64_t samples_decoded = _decoder_stack->samples_decoded(); + if (sample_count == samples_decoded) + return; + + const int y = get_y(); + const double start = max(samples_decoded / + samples_per_pixel - pixels_offset, left - 1.0); + const double end = min(sample_count / samples_per_pixel - + pixels_offset, right + 1.0); + const QRectF no_decode_rect(start, y - h/2 + 0.5, end - start, h); + + p.setPen(QPen(Qt::NoPen)); + p.setBrush(Qt::white); + p.drawRect(no_decode_rect); + + p.setPen(NoDecodeColour); + p.setBrush(QBrush(NoDecodeColour, Qt::Dense6Pattern)); + p.drawRect(no_decode_rect); +} + void DecodeTrace::create_decoder_form(int index, shared_ptr &dec, QWidget *parent, QFormLayout *form) diff --git a/pv/view/decodetrace.h b/pv/view/decodetrace.h index ccf4a0f7..02ea023b 100644 --- a/pv/view/decodetrace.h +++ b/pv/view/decodetrace.h @@ -64,6 +64,7 @@ private: private: static const QColor DecodeColours[4]; static const QColor ErrorBgColour; + static const QColor NoDecodeColour; public: DecodeTrace(pv::SigSession &session, @@ -102,6 +103,9 @@ private: void draw_error(QPainter &p, const QString &message, int left, int right); + void draw_unresolved_period(QPainter &p, int h, int left, + int right, double samples_per_pixel, double pixels_offset); + void create_decoder_form(int index, boost::shared_ptr &dec, QWidget *parent, QFormLayout *form); diff --git a/pv/view/trace.cpp b/pv/view/trace.cpp index 464cadcd..d06c24b5 100644 --- a/pv/view/trace.cpp +++ b/pv/view/trace.cpp @@ -88,6 +88,8 @@ void Trace::paint_back(QPainter &p, int left, int right) (void)p; (void)left; (void)right; + + compute_text_size(p); } void Trace::paint_mid(QPainter &p, int left, int right) -- 2.30.2