Qt: faster app icons on start
Three things still held icons up: - The app list was built on Qt's thread, so nothing on screen could paint (icons included) until every app was listed and labelled. HomeActivity now lists apps on its own thread and answers through Native.appList. - Each icon was drawn, PNG-encoded in Java and decoded again in C++. Icons now cross as raw premultiplied RGBA, and drawn ones are kept in the cache dir, keyed by the app's last update, so a fresh start just reads them. - The closed drawer made its icons at the same time as home. It now waits 1.5s, or until it opens. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DPL5hiQsCq11CwCPnKPp9D
This commit is contained in:
7 files changed
+115
-16
No files matched your search
@@ -67,6 +67,13 @@ void jLegacyHome(JNIEnv *env, jclass, jstring json) {
|
||||
post([=] { emit g_backend->legacyHome(s); });
|
||||
}
|
||||
|
||||
void jAppList(JNIEnv *env, jclass, jstring json) {
|
||||
const char *c = env->GetStringUTFChars(json, nullptr);
|
||||
const QByteArray s(c);
|
||||
env->ReleaseStringUTFChars(json, c);
|
||||
post([=] { g_backend->takeAppList(s); });
|
||||
}
|
||||
|
||||
void registerNatives() {
|
||||
static bool done = false;
|
||||
if (done) return;
|
||||
@@ -81,6 +88,7 @@ void registerNatives() {
|
||||
{"widgetGrab", "(I)V", reinterpret_cast<void *>(jWidgetGrab)},
|
||||
{"widgetDrag", "(II)V", reinterpret_cast<void *>(jWidgetDrag)},
|
||||
{"widgetDrop", "(Z)V", reinterpret_cast<void *>(jWidgetDrop)},
|
||||
{"appList", "(Ljava/lang/String;)V", reinterpret_cast<void *>(jAppList)},
|
||||
{"legacyHome", "(Ljava/lang/String;)V", reinterpret_cast<void *>(jLegacyHome)},
|
||||
};
|
||||
QJniEnvironment env;
|
||||
@@ -149,6 +157,21 @@ QVariantList Backend::apps() const {
|
||||
return out;
|
||||
}
|
||||
|
||||
// apps(), without holding up the UI thread meanwhile: the list arrives as appsLoaded.
|
||||
void Backend::requestApps() {
|
||||
#ifdef Q_OS_ANDROID
|
||||
callVoid("listApps");
|
||||
#else
|
||||
QTimer::singleShot(0, this, [this] { takeAppList(demo(QStringLiteral("apps.json")).toJson(QJsonDocument::Compact)); });
|
||||
#endif
|
||||
}
|
||||
|
||||
void Backend::takeAppList(const QByteArray &json) {
|
||||
const QVariantList out = appList(QJsonDocument::fromJson(json));
|
||||
if (!out.isEmpty()) QSettings().setValue(QStringLiteral("apps"), QString::fromUtf8(json));
|
||||
emit appsLoaded(out);
|
||||
}
|
||||
|
||||
QVariantList Backend::savedApps() const {
|
||||
return appList(QJsonDocument::fromJson(QSettings().value(QStringLiteral("apps")).toString().toUtf8()));
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ public:
|
||||
|
||||
// Lists: [{label, component, system}] and [{label, app, provider, h}].
|
||||
Q_INVOKABLE QVariantList apps() const;
|
||||
Q_INVOKABLE void requestApps(); // answers with appsLoaded
|
||||
Q_INVOKABLE QVariantList savedApps() const; // the last list apps() returned, for a quick start
|
||||
Q_INVOKABLE QVariantList widgetProviders() const;
|
||||
|
||||
@@ -66,6 +67,7 @@ public:
|
||||
|
||||
signals:
|
||||
void insetsChanged();
|
||||
void appsLoaded(const QVariantList &apps);
|
||||
void appsChanged(const QString &packages); // comma-separated; empty: any
|
||||
void homePressed();
|
||||
void backPressed();
|
||||
@@ -77,6 +79,9 @@ signals:
|
||||
void legacyHome(const QString &json); // the WebView build's saved home, read once
|
||||
void toast(const QString &text); // desktop stand-in for an action
|
||||
|
||||
public:
|
||||
void takeAppList(const QByteArray &json); // HomeActivity's answer to requestApps
|
||||
|
||||
private:
|
||||
qreal dpr() const;
|
||||
qreal m_insetTop = 0, m_insetBottom = 0;
|
||||
|
||||
+11
-6
@@ -4,6 +4,8 @@
|
||||
#include <QPainter>
|
||||
#include <QUrl>
|
||||
|
||||
#include <cmath>
|
||||
|
||||
#ifdef Q_OS_ANDROID
|
||||
#include <QJniEnvironment>
|
||||
#include <QJniObject>
|
||||
@@ -17,16 +19,19 @@ QImage IconProvider::requestImage(const QString &id, QSize *size, const QSize &r
|
||||
const int px = requested.width() > 0 ? requested.width() : 144;
|
||||
QImage img;
|
||||
#ifdef Q_OS_ANDROID
|
||||
QJniObject png = QJniObject::callStaticObjectMethod(
|
||||
// Premultiplied RGBA, side x side, straight from an Android bitmap.
|
||||
QJniObject pixels = QJniObject::callStaticObjectMethod(
|
||||
"dev/ultra/launcher/HomeActivity", "icon", "(Ljava/lang/String;I)[B",
|
||||
QJniObject::fromString(key).object<jstring>(), jint(px));
|
||||
if (png.isValid()) {
|
||||
if (pixels.isValid()) {
|
||||
QJniEnvironment env;
|
||||
auto arr = png.object<jbyteArray>();
|
||||
auto arr = pixels.object<jbyteArray>();
|
||||
const jsize n = env->GetArrayLength(arr);
|
||||
QByteArray bytes(n, Qt::Uninitialized);
|
||||
env->GetByteArrayRegion(arr, 0, n, reinterpret_cast<jbyte *>(bytes.data()));
|
||||
img.loadFromData(bytes, "PNG");
|
||||
const int side = int(std::lround(std::sqrt(n / 4.0)));
|
||||
if (side > 0 && jsize(side) * side * 4 == n) {
|
||||
img = QImage(side, side, QImage::Format_RGBA8888_Premultiplied);
|
||||
env->GetByteArrayRegion(arr, 0, n, reinterpret_cast<jbyte *>(img.bits()));
|
||||
}
|
||||
}
|
||||
#else
|
||||
// A disc in a colour picked from the key, with the name's first letter.
|
||||
|
||||
Reference in new issue
Block a user