1
0
Fork 0

VideoDisplay: Move render code to render callback

Previously, Render is called every time when the content is updated from event callbacks. So simply moving the mouse around will spam the event queue and cause video stuck. Now we do render in render callback, and only set a flag to indicate the need of re-render.
This commit is contained in:
wangqr 2019-11-04 03:38:06 -05:00
parent f2676ddc3a
commit 557e81be1d
2 changed files with 20 additions and 3 deletions

View File

@ -104,7 +104,7 @@ VideoDisplay::VideoDisplay(wxToolBar *toolbar, bool freeSize, wxComboBox *zoomBo
con->videoController->AddARChangeListener(&VideoDisplay::UpdateSize, this),
});
Bind(wxEVT_PAINT, std::bind(&VideoDisplay::Render, this));
Bind(wxEVT_UPDATE_UI, &VideoDisplay::OnUpdateUIEvent, this);
Bind(wxEVT_SIZE, &VideoDisplay::OnSizeEvent, this);
Bind(wxEVT_CONTEXT_MENU, &VideoDisplay::OnContextMenu, this);
Bind(wxEVT_ENTER_WINDOW, &VideoDisplay::OnMouseEvent, this);
@ -148,10 +148,23 @@ bool VideoDisplay::InitContext() {
void VideoDisplay::UploadFrameData(FrameReadyEvent &evt) {
pending_frame = evt.frame;
Render();
// Instead of calling Render(), we force a render here to minimize delay
DoRender();
}
void VideoDisplay::Render() try {
void VideoDisplay::Render() {
render_requested = true;
}
void VideoDisplay::OnUpdateUIEvent(wxUpdateUIEvent&) {
if (render_requested)
DoRender();
}
void VideoDisplay::DoRender() try {
render_requested = false;
if (!con->project->VideoProvider() || !InitContext() || (!videoOut && !pending_frame))
return;

View File

@ -111,6 +111,8 @@ class VideoDisplay final : public wxGLCanvas {
int scale_factor;
agi::signal::Connection scale_factor_connection;
bool render_requested;
/// @brief Draw an overscan mask
/// @param horizontal_percent The percent of the video reserved horizontally
/// @param vertical_percent The percent of the video reserved vertically
@ -140,6 +142,8 @@ class VideoDisplay final : public wxGLCanvas {
/// @brief Recalculate video positioning and scaling when the available area or zoom changes
void OnSizeEvent(wxSizeEvent &event);
void OnContextMenu(wxContextMenuEvent&);
void OnUpdateUIEvent(wxUpdateUIEvent& event);
void DoRender();
public:
/// @brief Constructor