From a1b3653802fdeb8df79c594d0129608576d88fa2 Mon Sep 17 00:00:00 2001 From: "Simon A. Eugster" Date: Sat, 24 Jul 2010 14:21:07 +0000 Subject: [PATCH] Fixed: Don't paint scope if it is not visible. svn path=/trunk/kdenlive/; revision=4641 --- src/abstractscopewidget.cpp | 91 ++++++++++++++++++------------------- src/abstractscopewidget.h | 1 + 2 files changed, 45 insertions(+), 47 deletions(-) diff --git a/src/abstractscopewidget.cpp b/src/abstractscopewidget.cpp index d61f3b6f..d38d6b4c 100644 --- a/src/abstractscopewidget.cpp +++ b/src/abstractscopewidget.cpp @@ -89,17 +89,18 @@ void AbstractScopeWidget::prodHUDThread() { if (this->visibleRegion().isEmpty()) { qDebug() << "Scope " << widgetName() << " is not visible. Not calculating HUD."; - } - if (m_semaphoreHUD.tryAcquire(1)) { - Q_ASSERT(!m_threadHUD.isRunning()); + } else { + if (m_semaphoreHUD.tryAcquire(1)) { + Q_ASSERT(!m_threadHUD.isRunning()); - m_newHUDFrames.fetchAndStoreRelaxed(0); - m_newHUDUpdates.fetchAndStoreRelaxed(0); - m_threadHUD = QtConcurrent::run(this, &AbstractScopeWidget::renderHUD, m_accelFactorHUD); - qDebug() << "HUD thread started in " << widgetName(); + m_newHUDFrames.fetchAndStoreRelaxed(0); + m_newHUDUpdates.fetchAndStoreRelaxed(0); + m_threadHUD = QtConcurrent::run(this, &AbstractScopeWidget::renderHUD, m_accelFactorHUD); + qDebug() << "HUD thread started in " << widgetName(); - } else { - qDebug() << "HUD semaphore locked, not prodding in " << widgetName() << ". Thread running: " << m_threadHUD.isRunning(); + } else { + qDebug() << "HUD semaphore locked, not prodding in " << widgetName() << ". Thread running: " << m_threadHUD.isRunning(); + } } } @@ -109,41 +110,43 @@ void AbstractScopeWidget::prodScopeThread() // and not hidden by another widget on the stack. if (this->visibleRegion().isEmpty()) { qDebug() << "Scope " << widgetName() << " is not visible. Not calculating scope."; - } - // Try to acquire the semaphore. This must only succeed if m_threadScope is not running - // anymore. Therefore the semaphore must NOT be released before m_threadScope ends. - // If acquiring the semaphore fails, the thread is still running. - if (m_semaphoreScope.tryAcquire(1)) { - Q_ASSERT(!m_threadScope.isRunning()); + } else { + // Try to acquire the semaphore. This must only succeed if m_threadScope is not running + // anymore. Therefore the semaphore must NOT be released before m_threadScope ends. + // If acquiring the semaphore fails, the thread is still running. + if (m_semaphoreScope.tryAcquire(1)) { + Q_ASSERT(!m_threadScope.isRunning()); - m_newScopeFrames.fetchAndStoreRelaxed(0); - m_newScopeUpdates.fetchAndStoreRelaxed(0); + m_newScopeFrames.fetchAndStoreRelaxed(0); + m_newScopeUpdates.fetchAndStoreRelaxed(0); - // See http://doc.qt.nokia.com/latest/qtconcurrentrun.html#run about - // running member functions in a thread - m_threadScope = QtConcurrent::run(this, &AbstractScopeWidget::renderScope, m_accelFactorScope); + // See http://doc.qt.nokia.com/latest/qtconcurrentrun.html#run about + // running member functions in a thread + m_threadScope = QtConcurrent::run(this, &AbstractScopeWidget::renderScope, m_accelFactorScope); - qDebug() << "Scope thread started in " << widgetName(); + qDebug() << "Scope thread started in " << widgetName(); - } else { - qDebug() << "Scope semaphore locked, not prodding in " << widgetName() << ". Thread running: " << m_threadScope.isRunning(); + } else { + qDebug() << "Scope semaphore locked, not prodding in " << widgetName() << ". Thread running: " << m_threadScope.isRunning(); + } } } void AbstractScopeWidget::prodBackgroundThread() { if (this->visibleRegion().isEmpty()) { qDebug() << "Scope " << widgetName() << " is not visible. Not calculating background."; - } - if (m_semaphoreBackground.tryAcquire(1)) { - Q_ASSERT(!m_threadBackground.isRunning()); + } else { + if (m_semaphoreBackground.tryAcquire(1)) { + Q_ASSERT(!m_threadBackground.isRunning()); - m_newBackgroundFrames.fetchAndStoreRelaxed(0); - m_newBackgroundUpdates.fetchAndStoreRelaxed(0); - m_threadBackground = QtConcurrent::run(this, &AbstractScopeWidget::renderBackground, m_accelFactorBackground); - qDebug() << "Background thread started in " << widgetName(); + m_newBackgroundFrames.fetchAndStoreRelaxed(0); + m_newBackgroundUpdates.fetchAndStoreRelaxed(0); + m_threadBackground = QtConcurrent::run(this, &AbstractScopeWidget::renderBackground, m_accelFactorBackground); + qDebug() << "Background thread started in " << widgetName(); - } else { - qDebug() << "Background semaphore locked, not prodding in " << widgetName() << ". Thread running: " << m_threadBackground.isRunning(); + } else { + qDebug() << "Background semaphore locked, not prodding in " << widgetName() << ". Thread running: " << m_threadBackground.isRunning(); + } } } @@ -204,20 +207,15 @@ void AbstractScopeWidget::raise() forceUpdate(); } -void AbstractScopeWidget::paintEvent(QPaintEvent *) +void AbstractScopeWidget::showEvent(QShowEvent *event) { -// qDebug() << "Painting now on scope " << widgetName(); - if (!initialDimensionUpdateDone) { - // This is a workaround. - // When updating the dimensions in the constructor, the size - // of the control items at the top are simply ignored! So do - // it here instead. - m_scopeRect = scopeRect(); - initialDimensionUpdateDone = true; - } - - qDebug() << "Drawing top/left at " << m_scopeRect.topLeft().y() << "/" << m_scopeRect.topLeft().x(); + m_scopeRect = scopeRect(); + QWidget::showEvent(event); + m_scopeRect = scopeRect(); +} +void AbstractScopeWidget::paintEvent(QPaintEvent *) +{ QPainter davinci(this); davinci.drawImage(m_scopeRect.topLeft(), m_imgBackground); davinci.drawImage(m_scopeRect.topLeft(), m_imgScope); @@ -324,12 +322,11 @@ void AbstractScopeWidget::slotActiveMonitorChanged(bool isClipMonitor) { qDebug() << "Active monitor has changed in " << widgetName() << ". Is the clip monitor active now? " << isClipMonitor; - bool disconnected = m_activeRender->disconnect(this); - Q_ASSERT(disconnected); + bool b = m_activeRender->disconnect(this); + Q_ASSERT(b); m_activeRender = (isClipMonitor) ? m_clipMonitor->render : m_projMonitor->render; - bool b = true; b &= connect(m_activeRender, SIGNAL(rendererPosition(int)), this, SLOT(slotRenderZoneUpdated())); b &= connect(m_activeRender, SIGNAL(frameUpdated(int)), this, SLOT(slotRenderZoneUpdated())); Q_ASSERT(b); diff --git a/src/abstractscopewidget.h b/src/abstractscopewidget.h index fba34962..9514db5c 100644 --- a/src/abstractscopewidget.h +++ b/src/abstractscopewidget.h @@ -151,6 +151,7 @@ protected: void paintEvent(QPaintEvent *); void raise(); void resizeEvent(QResizeEvent *); + void showEvent(QShowEvent *); protected slots: /** Forces an update of all layers. */ -- 2.39.2