1
0
mirror of https://github.com/TomHarte/CLK.git synced 2025-01-28 13:30:55 +00:00

Makes effort to round out draft 1 of Outputs::Display::Metrics.

This commit is contained in:
Thomas Harte 2019-03-05 22:01:58 -05:00
parent 5660007221
commit f18132d674
2 changed files with 28 additions and 6 deletions

View File

@ -8,7 +8,7 @@
#include "DisplayMetrics.hpp" #include "DisplayMetrics.hpp"
#include <iostream> #include <numeric>
using namespace Outputs::Display; using namespace Outputs::Display;
@ -19,8 +19,10 @@ void Metrics::announce_event(ScanTarget::Event event) {
case ScanTarget::Event::EndHorizontalRetrace: case ScanTarget::Event::EndHorizontalRetrace:
++lines_this_frame_; ++lines_this_frame_;
break; break;
case ScanTarget::Event::EndVerticalRetrace: case ScanTarget::Event::BeginVerticalRetrace:
add_line_total(lines_this_frame_); add_line_total(lines_this_frame_);
break;
case ScanTarget::Event::EndVerticalRetrace:
lines_this_frame_ = 0; lines_this_frame_ = 0;
break; break;
default: break; default: break;
@ -28,11 +30,18 @@ void Metrics::announce_event(ScanTarget::Event event) {
} }
void Metrics::add_line_total(int total) { 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() { float Metrics::visible_lines_per_frame_estimate() {
return 1.0f; // TODO. // 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. // MARK: GPU processing speed decisions.

View File

@ -10,6 +10,8 @@
#define DisplayMetrics_hpp #define DisplayMetrics_hpp
#include "ScanTarget.hpp" #include "ScanTarget.hpp"
#include <array>
#include <chrono> #include <chrono>
namespace Outputs { namespace Outputs {
@ -22,16 +24,27 @@ namespace Display {
*/ */
class Metrics { class Metrics {
public: public:
/// Notifies Metrics of a beam event.
void announce_event(ScanTarget::Event event); void announce_event(ScanTarget::Event event);
/// Notifies Metrics that the size of the output buffer has changed.
void announce_did_resize(); 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); 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(); 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: private:
int lines_this_frame_ = 0; int lines_this_frame_ = 0;
std::array<int, 20> line_total_history_;
size_t line_total_history_pointer_ = 0;
void add_line_total(int); void add_line_total(int);
int frames_hit_ = 0; int frames_hit_ = 0;