[krita/kazakov/svg-loading] libs/ui: Make it possible to disable animation rendering in background

Dmitry Kazakov null at kde.org
Tue Apr 4 10:04:08 UTC 2017


Git commit a84998f0b61dd10eb069937d60b7b0683bb33c70 by Dmitry Kazakov.
Committed on 04/04/2017 at 10:02.
Pushed by dkazakov into branch 'kazakov/svg-loading'.

Make it possible to disable animation rendering in background

Now, when the cache is recalculated before every playback start,
we can let the user to disable background rendering of the animation.
That will save him cpu cycles and battery life.

See the option in

Preferences->General->Recalculate animation cache in background

CC:kimageshop at kde.org

M  +8    -0    libs/ui/dialogs/kis_dlg_preferences.cc
M  +3    -0    libs/ui/dialogs/kis_dlg_preferences.h
M  +12   -5    libs/ui/forms/wdggeneralsettings.ui
M  +15   -0    libs/ui/kis_animation_cache_populator.cpp
M  +2    -0    libs/ui/kis_animation_cache_populator.h
M  +10   -0    libs/ui/kis_config.cc
M  +3    -0    libs/ui/kis_config.h

https://commits.kde.org/krita/a84998f0b61dd10eb069937d60b7b0683bb33c70

diff --git a/libs/ui/dialogs/kis_dlg_preferences.cc b/libs/ui/dialogs/kis_dlg_preferences.cc
index 81b758ed464..6e89178f9d0 100644
--- a/libs/ui/dialogs/kis_dlg_preferences.cc
+++ b/libs/ui/dialogs/kis_dlg_preferences.cc
@@ -140,6 +140,7 @@ GeneralTab::GeneralTab(QWidget *_parent, const char *_name)
     m_radioToolOptionsInDocker->setChecked(cfg.toolOptionsInDocker());
     m_chkSwitchSelectionCtrlAlt->setChecked(cfg.switchSelectionCtrlAlt());
     m_chkConvertOnImport->setChecked(cfg.convertToImageColorspaceOnImport());
+    m_chkCacheAnimatioInBackground->setChecked(cfg.calculateAnimationCacheInBackground());
 
     connect(m_bnFileName, SIGNAL(clicked()), SLOT(getBackgroundImage()));
     connect(clearBgImageButton, SIGNAL(clicked()), SLOT(clearBackgroundImage()));
@@ -178,6 +179,7 @@ void GeneralTab::setDefault()
     m_radioToolOptionsInDocker->setChecked(cfg.toolOptionsInDocker(true));
     m_chkSwitchSelectionCtrlAlt->setChecked(cfg.switchSelectionCtrlAlt(true));
     m_chkConvertOnImport->setChecked(cfg.convertToImageColorspaceOnImport(true));
+    m_chkCacheAnimatioInBackground->setChecked(cfg.calculateAnimationCacheInBackground(true));
 
 }
 
@@ -253,6 +255,11 @@ bool GeneralTab::convertToImageColorspaceOnImport()
     return m_chkConvertOnImport->isChecked();
 }
 
+bool GeneralTab::calculateAnimationCacheInBackground()
+{
+    return m_chkCacheAnimatioInBackground->isChecked();
+}
+
 
 void GeneralTab::getBackgroundImage()
 {
@@ -1011,6 +1018,7 @@ bool KisDlgPreferences::editPreferences()
         cfg.setShowRootLayer(dialog->m_general->showRootLayer());
         cfg.setShowOutlineWhilePainting(dialog->m_general->showOutlineWhilePainting());
         cfg.setHideSplashScreen(dialog->m_general->hideSplashScreen());
+        cfg.setCalculateAnimationCacheInBackground(dialog->m_general->calculateAnimationCacheInBackground());
 
         KConfigGroup group = KSharedConfig::openConfig()->group("File Dialogs");
         group.writeEntry("DontUseNativeFileDialog", !dialog->m_general->m_chkNativeFileDialog->isChecked());
diff --git a/libs/ui/dialogs/kis_dlg_preferences.h b/libs/ui/dialogs/kis_dlg_preferences.h
index db24fc2f3df..6ade17541e9 100644
--- a/libs/ui/dialogs/kis_dlg_preferences.h
+++ b/libs/ui/dialogs/kis_dlg_preferences.h
@@ -81,6 +81,9 @@ public:
     bool toolOptionsInDocker();
     bool switchSelectionCtrlAlt();
     bool convertToImageColorspaceOnImport();
+
+    bool calculateAnimationCacheInBackground();
+
 private Q_SLOTS:
     void getBackgroundImage();
     void clearBackgroundImage();
diff --git a/libs/ui/forms/wdggeneralsettings.ui b/libs/ui/forms/wdggeneralsettings.ui
index 9a321828295..9581309781c 100644
--- a/libs/ui/forms/wdggeneralsettings.ui
+++ b/libs/ui/forms/wdggeneralsettings.ui
@@ -660,6 +660,13 @@
          </property>
         </spacer>
        </item>
+       <item row="16" column="1">
+        <widget class="QCheckBox" name="m_chkCacheAnimatioInBackground">
+         <property name="text">
+          <string>Recalculate animation cache in background</string>
+         </property>
+        </widget>
+       </item>
       </layout>
      </widget>
     </widget>
@@ -668,15 +675,15 @@
  </widget>
  <customwidgets>
   <customwidget>
-   <class>KisColorButton</class>
-   <extends>QPushButton</extends>
-   <header>kis_color_button.h</header>
-  </customwidget>
-  <customwidget>
    <class>KisIntParseSpinBox</class>
    <extends>QSpinBox</extends>
    <header>kis_int_parse_spin_box.h</header>
   </customwidget>
+  <customwidget>
+   <class>KisColorButton</class>
+   <extends>QPushButton</extends>
+   <header>kis_color_button.h</header>
+  </customwidget>
  </customwidgets>
  <resources/>
  <connections/>
diff --git a/libs/ui/kis_animation_cache_populator.cpp b/libs/ui/kis_animation_cache_populator.cpp
index f2913299da5..5e83991a0b8 100644
--- a/libs/ui/kis_animation_cache_populator.cpp
+++ b/libs/ui/kis_animation_cache_populator.cpp
@@ -24,6 +24,8 @@
 #include <QMutex>
 #include <QtConcurrent>
 
+#include "kis_config.h"
+#include "kis_config_notifier.h"
 #include "KisPart.h"
 #include "KisDocument.h"
 #include "kis_image.h"
@@ -64,6 +66,7 @@ struct KisAnimationCachePopulator::Private
     QFutureWatcher<void> infoConversionWatcher;
 
     KisAnimationCacheRegenerator regenerator;
+    bool calculateAnimationCacheInBackground = true;
 
 
 
@@ -265,6 +268,9 @@ KisAnimationCachePopulator::KisAnimationCachePopulator(KisPart *part)
 
     connect(&m_d->regenerator, SIGNAL(sigFrameCancelled()), SLOT(slotRegeneratorFrameCancelled()));
     connect(&m_d->regenerator, SIGNAL(sigFrameFinished()), SLOT(slotRegeneratorFrameReady()));
+
+    connect(KisConfigNotifier::instance(), SIGNAL(configChanged()), SLOT(slotConfigChanged()));
+    slotConfigChanged();
 }
 
 KisAnimationCachePopulator::~KisAnimationCachePopulator()
@@ -282,6 +288,9 @@ void KisAnimationCachePopulator::slotTimer()
 
 void KisAnimationCachePopulator::slotRequestRegeneration()
 {
+    // skip if the user forbade background regeneration
+    if (!m_d->calculateAnimationCacheInBackground) return;
+
     m_d->enterState(Private::WaitingForIdle);
 }
 
@@ -295,3 +304,9 @@ void KisAnimationCachePopulator::slotRegeneratorFrameReady()
 {
     m_d->enterState(Private::BetweenFrames);
 }
+
+void KisAnimationCachePopulator::slotConfigChanged()
+{
+    KisConfig cfg;
+    m_d->calculateAnimationCacheInBackground = cfg.calculateAnimationCacheInBackground();
+}
diff --git a/libs/ui/kis_animation_cache_populator.h b/libs/ui/kis_animation_cache_populator.h
index 7754f9e1887..3a117a233d5 100644
--- a/libs/ui/kis_animation_cache_populator.h
+++ b/libs/ui/kis_animation_cache_populator.h
@@ -48,6 +48,8 @@ private Q_SLOTS:
     void slotRegeneratorFrameCancelled();
     void slotRegeneratorFrameReady();
 
+    void slotConfigChanged();
+
 private:
     struct Private;
     QScopedPointer<Private> m_d;
diff --git a/libs/ui/kis_config.cc b/libs/ui/kis_config.cc
index 5d053bd040f..b396d29e955 100644
--- a/libs/ui/kis_config.cc
+++ b/libs/ui/kis_config.cc
@@ -1791,6 +1791,16 @@ void KisConfig::setBrushHudSetting(const QString &value) const
     m_cfg.writeEntry("brushHudSettings", value);
 }
 
+bool KisConfig::calculateAnimationCacheInBackground(bool defaultValue) const
+{
+    return defaultValue ? true : m_cfg.readEntry("calculateAnimationCacheInBackground", true);
+}
+
+void KisConfig::setCalculateAnimationCacheInBackground(bool value)
+{
+    m_cfg.writeEntry("calculateAnimationCacheInBackground", value);
+}
+
 #include <QDomDocument>
 #include <QDomElement>
 
diff --git a/libs/ui/kis_config.h b/libs/ui/kis_config.h
index f8dffd62212..b0a561d7ae0 100644
--- a/libs/ui/kis_config.h
+++ b/libs/ui/kis_config.h
@@ -510,6 +510,9 @@ public:
     QString brushHudSetting(bool defaultValue = false) const;
     void setBrushHudSetting(const QString &value) const;
 
+    bool calculateAnimationCacheInBackground(bool defaultValue = false) const;
+    void setCalculateAnimationCacheInBackground(bool value);
+
     template<class T>
     void writeEntry(const QString& name, const T& value) {
         m_cfg.writeEntry(name, value);


More information about the kimageshop mailing list