summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Wu <peter@lekensteyn.nl>2016-10-12 23:48:51 (GMT)
committerPeter Wu <peter@lekensteyn.nl>2016-10-20 20:41:43 (GMT)
commita6911eb80af1f67c9130d7749b3161cc40467041 (patch)
treedc2df744766122a207af0705a0a3278cadac9df3
parent1244980882382639f35925cef1d4cf3eeb3c240c (diff)
Lazy load export image, halving the startup time
Conversion of a pixmap to a data URI is quite expensive. On my Skylake laptop (i7-6500HQ), it took one second to start. A perf trace showed that 65% of the time was spent in ExportManager::pixmapDataUri. REVIEW: 129167
-rw-r--r--src/Gui/ExportMenu.cpp35
-rw-r--r--src/Gui/ExportMenu.h4
-rw-r--r--src/Gui/KSMainWindow.cpp2
3 files changed, 30 insertions, 11 deletions
diff --git a/src/Gui/ExportMenu.cpp b/src/Gui/ExportMenu.cpp
index 50333e0..69cb56a 100644
--- a/src/Gui/ExportMenu.cpp
+++ b/src/Gui/ExportMenu.cpp
@@ -42,6 +42,7 @@
ExportMenu::ExportMenu(QWidget *parent) :
QMenu(parent),
#ifdef PURPOSE_FOUND
+ mUpdatedImageAvailable(false),
mPurposeMenu(new Purpose::Menu(this)),
#endif
mExportManager(ExportManager::instance())
@@ -68,17 +69,12 @@ void ExportMenu::populateMenu()
}
-void ExportMenu::imageUpdated(const QString &dataUri)
+void ExportMenu::imageUpdated()
{
#ifdef PURPOSE_FOUND
- mPurposeMenu->model()->setInputData(QJsonObject {
- { QStringLiteral("mimeType"), QStringLiteral("image/png") },
- { QStringLiteral("urls"), QJsonArray({ dataUri }) }
- });
- mPurposeMenu->model()->setPluginType("Export");
- mPurposeMenu->reload();
-#else
- Q_UNUSED(dataUri);
+ // mark cached image as stale
+ mUpdatedImageAvailable = true;
+ mPurposeMenu->clear();
#endif
}
@@ -187,5 +183,26 @@ void ExportMenu::loadPurposeMenu()
emit imageShared(false, output["url"].toString());
}
});
+
+ // update available options based on the latest picture
+ connect(mPurposeMenu, &QMenu::aboutToShow, this, &ExportMenu::loadPurposeItems);
+}
+
+void ExportMenu::loadPurposeItems()
+{
+ if (!mUpdatedImageAvailable) {
+ return;
+ }
+
+ // updated image available, we lazily load it now
+ QString dataUri = ExportManager::instance()->pixmapDataUri();
+ mUpdatedImageAvailable = false;
+
+ mPurposeMenu->model()->setInputData(QJsonObject {
+ { QStringLiteral("mimeType"), QStringLiteral("image/png") },
+ { QStringLiteral("urls"), QJsonArray({ dataUri }) }
+ });
+ mPurposeMenu->model()->setPluginType("Export");
+ mPurposeMenu->reload();
}
#endif
diff --git a/src/Gui/ExportMenu.h b/src/Gui/ExportMenu.h
index 5040fe2..220e01f 100644
--- a/src/Gui/ExportMenu.h
+++ b/src/Gui/ExportMenu.h
@@ -41,7 +41,7 @@ class ExportMenu : public QMenu
public:
explicit ExportMenu(QWidget *parent = 0);
- void imageUpdated(const QString &dataUri);
+ void imageUpdated();
private slots:
@@ -67,7 +67,9 @@ class ExportMenu : public QMenu
#ifdef PURPOSE_FOUND
void loadPurposeMenu();
+ void loadPurposeItems();
+ bool mUpdatedImageAvailable;
Purpose::Menu *mPurposeMenu;
#endif
diff --git a/src/Gui/KSMainWindow.cpp b/src/Gui/KSMainWindow.cpp
index e011635..c9d93dc 100644
--- a/src/Gui/KSMainWindow.cpp
+++ b/src/Gui/KSMainWindow.cpp
@@ -250,7 +250,7 @@ void KSMainWindow::captureScreenshot(ImageGrabber::GrabMode mode, int timeout, b
void KSMainWindow::setScreenshotAndShow(const QPixmap &pixmap)
{
mKSWidget->setScreenshotPixmap(pixmap);
- mExportMenu->imageUpdated(ExportManager::instance()->pixmapDataUri());
+ mExportMenu->imageUpdated();
setWindowTitle(i18nc("Unsaved Screenshot", "Unsaved[*]"));
setWindowModified(true);