From 2e4089a1d13bfd69757a87670795dfffd44505e9 Mon Sep 17 00:00:00 2001 From: Sylvain Munaut Date: Mon, 2 Dec 2019 20:10:24 +0100 Subject: [PATCH] gr-fosphor: Add concept of visibility to the base block implementation If we're not visible, don't do any GL calls Signed-off-by: Sylvain Munaut --- CMakeLists.txt | 2 +- lib/base_sink_c_impl.cc | 43 +++++++++++++++++++++++++++++------------ lib/base_sink_c_impl.h | 4 ++++ 3 files changed, 36 insertions(+), 13 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3a6ffa1..78a4acf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -64,7 +64,7 @@ set(Boost_ADDITIONAL_VERSIONS "1.60.0" "1.60" "1.61.0" "1.61" "1.62.0" "1.62" "1.63.0" "1.63" "1.64.0" "1.64" "1.65.0" "1.65" "1.66.0" "1.66" "1.67.0" "1.67" "1.68.0" "1.68" "1.69.0" "1.69" ) -find_package(Boost "1.35" COMPONENTS system thread) +find_package(Boost "1.35" COMPONENTS system chrono thread) if(NOT Boost_FOUND) message(FATAL_ERROR "Boost required to compile gr-fosphor") diff --git a/lib/base_sink_c_impl.cc b/lib/base_sink_c_impl.cc index c4af03e..c9cc868 100644 --- a/lib/base_sink_c_impl.cc +++ b/lib/base_sink_c_impl.cc @@ -61,7 +61,7 @@ const int base_sink_c_impl::k_db_per_div[] = {1, 2, 5, 10, 20}; base_sink_c_impl::base_sink_c_impl() : d_db_ref(0), d_db_per_div_idx(3), d_zoom_enabled(false), d_zoom_center(0.5), d_zoom_width(0.2), - d_ratio(0.35f), d_frozen(false), d_active(false), + d_ratio(0.35f), d_frozen(false), d_active(false), d_visible(true), d_frequency(), d_fft_window(gr::fft::window::WIN_BLACKMAN_hARRIS) { /* Init FIFO */ @@ -150,13 +150,9 @@ base_sink_c_impl::render(void) /* Handle pending settings */ this->settings_apply(this->settings_get_and_reset_changed()); - /* Clear everything */ - glClearColor( 0.0f, 0.0f, 0.0f, 0.0f ); - glClear(GL_COLOR_BUFFER_BIT); - + /* Process as much we can */ tot_len = this->d_fifo->used(); - /* Process as much we can */ for (i=0; id_fifo->read_discard(len); } - /* Draw */ - fosphor_draw(this->d_fosphor, this->d_render_main); + /* Are we visible ? */ + { + gr::thread::scoped_lock guard(this->d_render_mutex); - if (this->d_zoom_enabled) - fosphor_draw(this->d_fosphor, this->d_render_zoom); + if (this->d_visible) { + /* Clear everything */ + glClearColor( 0.0f, 0.0f, 0.0f, 0.0f ); + glClear(GL_COLOR_BUFFER_BIT); - /* Done, swap buffer */ - this->glctx_swap(); + /* Draw */ + fosphor_draw(this->d_fosphor, this->d_render_main); + + if (this->d_zoom_enabled) + fosphor_draw(this->d_fosphor, this->d_render_zoom); + + /* Done, swap buffer */ + this->glctx_swap(); + } + } + + if (!this->d_visible) { + /* If hidden, we can't draw or swap buffer, so just wait a bit */ + boost::this_thread::sleep_for(boost::chrono::milliseconds(10)); + } } @@ -301,6 +313,13 @@ base_sink_c_impl::cb_reshape(int width, int height) this->settings_mark_changed(SETTING_DIMENSIONS); } +void +base_sink_c_impl::cb_visibility(bool visible) +{ + gr::thread::scoped_lock guard(this->d_render_mutex); + this->d_visible = visible; +} + void base_sink_c_impl::execute_ui_action(enum ui_action_t action) diff --git a/lib/base_sink_c_impl.h b/lib/base_sink_c_impl.h index bebb20c..0d06fed 100644 --- a/lib/base_sink_c_impl.h +++ b/lib/base_sink_c_impl.h @@ -45,12 +45,15 @@ namespace gr { private: /* Worker thread */ gr::thread::thread d_worker; + bool d_visible; bool d_active; bool d_frozen; void worker(); static void _worker(base_sink_c_impl *obj); + gr::thread::mutex d_render_mutex; + /* fosphor core */ fifo *d_fifo; @@ -111,6 +114,7 @@ namespace gr { /* Callbacks from GL window */ void cb_reshape(int width, int height); + void cb_visibility(bool visible); public: virtual ~base_sink_c_impl();