From 727c2a1185a5aed42195123bed032c248e5fe3ee Mon Sep 17 00:00:00 2001 From: shun-iwasawa Date: Mon, 21 Feb 2022 14:47:45 +0900 Subject: [PATCH] fix viewer playback --- toonz/sources/toonz/comboviewerpane.cpp | 7 +------ toonz/sources/toonz/sceneviewer.cpp | 11 +---------- toonz/sources/toonz/sceneviewer.h | 9 --------- toonz/sources/toonz/viewerpane.cpp | 7 +------ toonz/sources/toonzqt/flipconsole.cpp | 13 +++++++++++-- 5 files changed, 14 insertions(+), 33 deletions(-) diff --git a/toonz/sources/toonz/comboviewerpane.cpp b/toonz/sources/toonz/comboviewerpane.cpp index a3b5d824..bfaf0121 100644 --- a/toonz/sources/toonz/comboviewerpane.cpp +++ b/toonz/sources/toonz/comboviewerpane.cpp @@ -311,10 +311,9 @@ void ComboViewerPanel::onShowHideActionTriggered(QAction *act) { void ComboViewerPanel::onDrawFrame(int frame, const ImagePainter::VisualSettings &settings, - QElapsedTimer *timer, qint64 targetInstant) { + QElapsedTimer *, qint64) { TApp *app = TApp::instance(); m_sceneViewer->setVisual(settings); - m_sceneViewer->setTimerAndTargetInstant(timer, targetInstant); TFrameHandle *frameHandle = app->getCurrentFrame(); @@ -350,10 +349,6 @@ void ComboViewerPanel::onDrawFrame(int frame, else if (settings.m_blankColor != TPixel::Transparent) m_sceneViewer->update(); - - // make sure to redraw the frame here. - // repaint() does NOT immediately redraw the frame for QOpenGLWidget - if (frameHandle->isPlaying()) qApp->processEvents(); } //----------------------------------------------------------------------------- diff --git a/toonz/sources/toonz/sceneviewer.cpp b/toonz/sources/toonz/sceneviewer.cpp index 41cfa848..3abd98d4 100644 --- a/toonz/sources/toonz/sceneviewer.cpp +++ b/toonz/sources/toonz/sceneviewer.cpp @@ -800,8 +800,7 @@ SceneViewer::SceneViewer(ImageUtils::FullScreenWidget *parent) , m_mousePanning(0) , m_mouseZooming(0) , m_mouseRotating(0) - , m_keyAction(0) - , m_timer(nullptr) { + , m_keyAction(0) { m_visualSettings.m_sceneProperties = TApp::instance()->getCurrentScene()->getScene()->getProperties(); m_stopMotion = StopMotion::instance(); @@ -2053,14 +2052,6 @@ void SceneViewer::paintGL() { if (!m_isPicking && m_lutCalibrator && m_lutCalibrator->isValid()) m_lutCalibrator->onEndDraw(m_fbo); - - // wait to achieve precise fps - if (m_timer && m_timer->isValid()) { - qint64 currentInstant = m_timer->nsecsElapsed(); - while (currentInstant < m_targetInstant) { - currentInstant = m_timer->nsecsElapsed(); - } - } } //----------------------------------------------------------------------------- diff --git a/toonz/sources/toonz/sceneviewer.h b/toonz/sources/toonz/sceneviewer.h index 98a13558..d36710d0 100644 --- a/toonz/sources/toonz/sceneviewer.h +++ b/toonz/sources/toonz/sceneviewer.h @@ -219,10 +219,6 @@ class SceneViewer final : public GLWidgetForHighDpi, QAction *m_keyAction; - // passed from PlaybackExecutor - QElapsedTimer *m_timer; - qint64 m_targetInstant; - public: enum ReferenceMode { NORMAL_REFERENCE = 1, @@ -331,11 +327,6 @@ public: void setPreviewBGColor(const QColor &color) { m_previewBgColor = color; } QColor getPreviewBGColor() const { return m_previewBgColor; } - void setTimerAndTargetInstant(QElapsedTimer *timer, qint64 target) { - m_timer = timer; - m_targetInstant = target; - } - public: // SceneViewer's gadget public functions TPointD winToWorld(const QPointF &pos) const; diff --git a/toonz/sources/toonz/viewerpane.cpp b/toonz/sources/toonz/viewerpane.cpp index eff224b5..87cb9709 100644 --- a/toonz/sources/toonz/viewerpane.cpp +++ b/toonz/sources/toonz/viewerpane.cpp @@ -276,10 +276,9 @@ void SceneViewerPanel::onShowHideActionTriggered(QAction *act) { void SceneViewerPanel::onDrawFrame(int frame, const ImagePainter::VisualSettings &settings, - QElapsedTimer *timer, qint64 targetInstant) { + QElapsedTimer *, qint64) { TApp *app = TApp::instance(); m_sceneViewer->setVisual(settings); - m_sceneViewer->setTimerAndTargetInstant(timer, targetInstant); TFrameHandle *frameHandle = app->getCurrentFrame(); @@ -314,10 +313,6 @@ void SceneViewerPanel::onDrawFrame(int frame, else if (settings.m_blankColor != TPixel::Transparent) m_sceneViewer->update(); - - // make sure to redraw the frame here. - // repaint() does NOT immediately redraw the frame for QOpenGLWidget - if (frameHandle->isPlaying()) qApp->processEvents(); } //----------------------------------------------------------------------------- diff --git a/toonz/sources/toonzqt/flipconsole.cpp b/toonz/sources/toonzqt/flipconsole.cpp index 971d6dcd..e599fafc 100644 --- a/toonz/sources/toonzqt/flipconsole.cpp +++ b/toonz/sources/toonzqt/flipconsole.cpp @@ -220,10 +220,19 @@ void PlaybackExecutor::run() { shortTermDelayAdjuster -= delayAdjust; // Show the next frame, telling currently measured fps - // The wait time will be inserted at the end of paintGL in order to - // achieve precise playback + // For the Flipbook, the wait time will be inserted at the end of paintGL + // in order to achieve precise playback emit nextFrame(fps, &m_timer, targetInstant); + // Playing on Viewer / Combo Viewer will advance the current frame. + // Calling qApp->processEvents() on drawing frame causes repaint of other + // panels which slows playback. Therefore in Viewer / Combo Viewer panels + // it just calls update() and necessary wait will be inserted here. + qint64 currentInstant = m_timer.nsecsElapsed(); + while (currentInstant < targetInstant) { + currentInstant = m_timer.nsecsElapsed(); + } + if (FlipConsole::m_areLinked) { // In case there are linked consoles, update them too. // Their load time must be included in the fps calculation.