From f18132d6742a42e4d7423cc23d1382d374e97abf Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Tue, 5 Mar 2019 22:01:58 -0500 Subject: [PATCH] Makes effort to round out draft 1 of Outputs::Display::Metrics. --- Outputs/DisplayMetrics.cpp | 19 ++++++++++++++----- Outputs/DisplayMetrics.hpp | 15 ++++++++++++++- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/Outputs/DisplayMetrics.cpp b/Outputs/DisplayMetrics.cpp index 3814298d2..3df043af6 100644 --- a/Outputs/DisplayMetrics.cpp +++ b/Outputs/DisplayMetrics.cpp @@ -8,7 +8,7 @@ #include "DisplayMetrics.hpp" -#include +#include using namespace Outputs::Display; @@ -19,8 +19,10 @@ void Metrics::announce_event(ScanTarget::Event event) { case ScanTarget::Event::EndHorizontalRetrace: ++lines_this_frame_; break; - case ScanTarget::Event::EndVerticalRetrace: + case ScanTarget::Event::BeginVerticalRetrace: add_line_total(lines_this_frame_); + break; + case ScanTarget::Event::EndVerticalRetrace: lines_this_frame_ = 0; break; default: break; @@ -28,11 +30,18 @@ void Metrics::announce_event(ScanTarget::Event event) { } void Metrics::add_line_total(int total) { -// std::cout << total << '\n'; + line_total_history_[line_total_history_pointer_] = total; + line_total_history_pointer_ = (line_total_history_pointer_ + 1) % line_total_history_.size(); } -float Metrics::lines_per_frame_estimate() { - return 1.0f; // TODO. +float Metrics::visible_lines_per_frame_estimate() { + // Just average the number of records contained in line_total_history_ to provide this estimate; + // that array should be an even number, to allow for potential interlaced sources. + return float(std::accumulate(line_total_history_.begin(), line_total_history_.end(), 0)) / float(line_total_history_.size()); +} + +int Metrics::current_line() { + return lines_this_frame_; } // MARK: GPU processing speed decisions. diff --git a/Outputs/DisplayMetrics.hpp b/Outputs/DisplayMetrics.hpp index 77eccad1a..4854e950b 100644 --- a/Outputs/DisplayMetrics.hpp +++ b/Outputs/DisplayMetrics.hpp @@ -10,6 +10,8 @@ #define DisplayMetrics_hpp #include "ScanTarget.hpp" + +#include #include namespace Outputs { @@ -22,16 +24,27 @@ namespace Display { */ class Metrics { public: + /// Notifies Metrics of a beam event. void announce_event(ScanTarget::Event event); + /// Notifies Metrics that the size of the output buffer has changed. void announce_did_resize(); + /// Provides Metrics with a new data point for output speed estimation. void announce_draw_status(size_t lines, std::chrono::high_resolution_clock::duration duration, bool complete); + /// @returns @c true if Metrics thinks a lower output buffer resolution is desirable in the abstract; @c false otherwise. bool should_lower_resolution(); - float lines_per_frame_estimate(); + + /// @returns An estimate of the number of lines being produced per frame, excluding vertical sync. + float visible_lines_per_frame_estimate(); + + /// @returns The number of lines since vertical retrace ended. + int current_line(); private: int lines_this_frame_ = 0; + std::array line_total_history_; + size_t line_total_history_pointer_ = 0; void add_line_total(int); int frames_hit_ = 0;