From ffb7a867d5620fcec4156c058daed5385f7312ec Mon Sep 17 00:00:00 2001 From: Chris Tallon Date: Fri, 22 May 2020 14:48:54 +0100 Subject: [PATCH] OsdOpenVG Render-on-demand experiment An experiment to switch from a timed render loop to rendering only on demand, in order to increase responsiveness of OSD and reduce CPU usage. There could be major negatives to this, therefore all changes are marked with OSDOVG-ROD-EXPERIMENT for easy greppage. See notes in source. There will certainly be temporary breakages. --- osd.h | 3 +++ osdopenvg.cc | 42 +++++++++++++++++++++++++++++++++++++++++- osdopenvg.h | 4 ++++ osdvector.cc | 3 +++ 4 files changed, 51 insertions(+), 1 deletion(-) diff --git a/osd.h b/osd.h index 1aa473f..dfe696c 100644 --- a/osd.h +++ b/osd.h @@ -46,6 +46,9 @@ class Osd virtual float getPixelAspect() { return 1.f; }; + // OSDOVG-ROD-EXPERIMENT - hack to allow OsdVector to call OsdOpenVG::nudge/signal render thread. work out a better way. + virtual void nudgeRenderThread() { }; + protected: static Osd* instance; bool initted{}; diff --git a/osdopenvg.cc b/osdopenvg.cc index c79eaa5..290fd1c 100644 --- a/osdopenvg.cc +++ b/osdopenvg.cc @@ -412,6 +412,41 @@ int OsdOpenVG::shutdown() return 1; } +// OSDOVG-ROD-EXPERIMENT - temp hack to allow OsdVector to signal the thread in OsdOpenVG +void OsdOpenVG::nudgeRenderThread() +{ + Log::getInstance()->log("OSD", Log::DEBUG, "Nudge render thread"); + + // signal renderLoop to go-around (from putOpenVGCommand) + renderThreadMutex.lock(); + if (renderThreadReq == 0) renderThreadReq = 1; + renderThreadCond.notify_one(); + renderThreadMutex.unlock(); +} + +/* + * OSDOVG-ROD-EXPERIMENT + * + * To switch OsdOpenVG to render-on-demand instead of rendering in a loop + * + * Pros: + * More responsive OSD + * Cuts 5% constant CPU usage + * Seems to have tickled the GFX corruption bug, might make it easier to find that + * + * Cons: + * There's a comment about video tearing if render is called too often. + * Will tearing show up in on-demand mode? + * Moves away from conventional FPS type render loop. VOMP doesn't use 3D GFX / animations + * currently, so this doesn't matter at the moment? + * Code needs updating to call nudgeRenderThread, + * e.g. FIXME backing out of the options screen doesn't redraw VWelcome + * + * Maybe have a hybrid system. One that normally works on-demand but can + * also switch to looping on the fly if necessary. + */ + + void OsdOpenVG::renderLoop() { // We have to claim the egl context for this thread @@ -438,7 +473,8 @@ void OsdOpenVG::renderLoop() long long time1 = getTimeMS(); - if ((time1 - lastrendertime) > 200) //5 fps for OSD updates are enough, avoids tearing + // OSDOVG-ROD-EXPERIMENT - always render, but only when signalled to + if (1) // ((time1 - lastrendertime) > 200) //5 fps for OSD updates are enough, avoids tearing { #if DEV dumpStyles(); @@ -467,6 +503,8 @@ void OsdOpenVG::renderLoop() if (ts != 0) { + // OSDOVG-ROD-EXPERIMENT + // renderThreadCond.wait(ul, [this]{ return renderThreadReq != 0; }); // experiment! always wait, no time limit renderThreadCond.wait_for(ul, std::chrono::milliseconds(ts), [this]{ return renderThreadReq != 0; }); if (renderThreadReq == 2) @@ -477,6 +515,8 @@ void OsdOpenVG::renderLoop() return; } + if (renderThreadReq == 0) abort(); // OSDOVG-ROD-EXPERIMENT - check this never happens + // Either timeout or renderThreadReq == 1 - go around renderThreadReq = 0; diff --git a/osdopenvg.h b/osdopenvg.h index 45e9915..43645ca 100644 --- a/osdopenvg.h +++ b/osdopenvg.h @@ -104,6 +104,10 @@ class OsdOpenVG : public OsdVector void updateBackgroundColor(DrawStyle bg); protected: + + // OSDOVG-ROD-EXPERIMENT + void nudgeRenderThread(); + /*osd vector implementation*/ void destroyImageRef(ImageIndex index); // ImageIndex createJpeg(const char* fileName, int *width,int *height); diff --git a/osdvector.cc b/osdvector.cc index 74f783f..88f536b 100644 --- a/osdvector.cc +++ b/osdvector.cc @@ -335,6 +335,9 @@ void OsdVector::updateOrAddSurface(const SurfaceVector* surf, float x, float y, Log::getInstance()->log("OsdVector", Log::CRAZY, "After UOAS:"); dumpStyles(); #endif + + // OSDOVG-ROD-EXPERIMENT + nudgeRenderThread(); } void OsdVector::removeSurface(const SurfaceVector* surf) -- 2.39.5