From f61097f3cb858e5d9b584c6c36ce18b3e3264cff Mon Sep 17 00:00:00 2001 From: Alexander Lohnau Date: Sat, 23 Oct 2021 18:18:47 +0200 Subject: [PATCH] Remove now unneeded static effect loader class --- src/effectloader.cpp | 167 ++++--------------------------------- src/effectloader.h | 25 ------ src/effects/CMakeLists.txt | 4 +- 3 files changed, 16 insertions(+), 180 deletions(-) diff --git a/src/effectloader.cpp b/src/effectloader.cpp index bcc92e2452..8345585b80 100644 --- a/src/effectloader.cpp +++ b/src/effectloader.cpp @@ -192,152 +192,6 @@ void ScriptedEffectLoader::clear() m_queue->clear(); } -static QJsonValue readPluginInfo(const QJsonObject &metadata, const QString &key) -{ - return metadata.value(QLatin1String("KPlugin")).toObject().value(key); -} - -StaticPluginEffectLoader::StaticPluginEffectLoader(QObject *parent) - : AbstractEffectLoader(parent) - , m_queue(new EffectLoadQueue(this)) -{ - const QVector staticPlugins = QPluginLoader::staticPlugins(); - qWarning()<isSupported(); - } - return false; -} - -QStringList StaticPluginEffectLoader::listOfKnownEffects() const -{ - return m_staticPlugins.keys(); -} - -void StaticPluginEffectLoader::clear() -{ - m_queue->clear(); -} - -bool StaticPluginEffectLoader::checkEnabledByDefault(const QStaticPlugin &staticPlugin) const -{ - const QJsonObject metadata = staticPlugin.metaData().value("MetaData").toObject(); - if (metadata.value("org.kde.kwin.effect").toObject().value("enabledByDefaultMethod").toBool()) { - if (EffectPluginFactory *effectFactory = factory(staticPlugin)) { - return effectFactory->enabledByDefault(); - } - } else if (metadata.value("KPlugin").toObject().value("EnabledByDefault").toBool()) { - return true; - } - - return false; -} - -void StaticPluginEffectLoader::queryAndLoadAll() -{ - for (auto it = m_staticPlugins.constBegin(); it != m_staticPlugins.constEnd(); ++it) { - const LoadEffectFlags flags = readConfig(it.key(), checkEnabledByDefault(it.value())); - if (flags.testFlag(LoadEffectFlag::Load)) { - m_queue->enqueue(qMakePair(it.key(), flags)); - } - } -} - -bool StaticPluginEffectLoader::loadEffect(const QString &name) -{ - return loadEffect(name, LoadEffectFlag::Load); -} - -bool StaticPluginEffectLoader::loadEffect(const QString &name, LoadEffectFlags flags) -{ - if (m_loadedEffects.contains(name)) { - qCDebug(KWIN_CORE) << name << "is already loaded"; - return false; - } - - auto staticPlugin = m_staticPlugins.constFind(name); - if (staticPlugin == m_staticPlugins.constEnd()) { - return false; - } - - EffectPluginFactory *effectFactory = factory(*staticPlugin); - if (!effectFactory) { - qCDebug(KWIN_CORE) << "Couldn't get an EffectPluginFactory for: " << name; - return false; - } - -#ifndef KWIN_UNIT_TEST - effects->makeOpenGLContextCurrent(); -#endif - if (!effectFactory->isSupported()) { - qCDebug(KWIN_CORE) << "Effect is not supported: " << name; - return false; - } - - if (flags & LoadEffectFlag::CheckDefaultFunction) { - if (!checkEnabledByDefault(*staticPlugin)) { - qCDebug(KWIN_CORE) << "Enabled by default function disables effect: " << name; - return false; - } - } - - Effect *effect = effectFactory->createEffect(); - if (!effect) { - qCDebug(KWIN_CORE) << "Failed to create effect: " << name; - return false; - } - - // insert in our loaded effects - m_loadedEffects << name; - connect(effect, &Effect::destroyed, this, [this, name]() { - m_loadedEffects.removeAll(name); - }); - - qCDebug(KWIN_CORE) << "Successfully loaded plugin effect: " << name; - Q_EMIT effectLoaded(effect, name); - return true; -} - -EffectPluginFactory *StaticPluginEffectLoader::factory(const QStaticPlugin &staticPlugin) const -{ - return qobject_cast(staticPlugin.instance()); -} - PluginEffectLoader::PluginEffectLoader(QObject *parent) : AbstractEffectLoader(parent) , m_queue(new EffectLoadQueue< PluginEffectLoader, KPluginMetaData>(this)) @@ -381,12 +235,20 @@ EffectPluginFactory *PluginEffectLoader::factory(const KPluginMetaData &info) co if (!info.isValid()) { return nullptr; } - QPluginLoader loader(info.fileName()); - if (loader.metaData().value("IID").toString() != EffectPluginFactory_iid) { - qCDebug(KWIN_CORE) << info.pluginId() << " has not matching plugin version, expected " << PluginFactory_iid << "got " << loader.metaData().value("IID"); - return nullptr; + KPluginFactory *factory; + if (info.isStaticPlugin()) { + // in case of static plugins we don't need to worry about the versions, because + // they are shipped as part of the kwin executables + factory = KPluginFactory::loadFactory(info).plugin; + } else { + QPluginLoader loader(info.fileName()); + if (loader.metaData().value("IID").toString() != EffectPluginFactory_iid) { + qCDebug(KWIN_CORE) << info.pluginId() << " has not matching plugin version, expected " << PluginFactory_iid << "got " + << loader.metaData().value("IID"); + return nullptr; + } + factory = qobject_cast(loader.instance()); } - KPluginFactory *factory = qobject_cast(loader.instance()); if (!factory) { qCDebug(KWIN_CORE) << "Did not get KPluginFactory for " << info.pluginId(); return nullptr; @@ -511,8 +373,7 @@ void PluginEffectLoader::clear() EffectLoader::EffectLoader(QObject *parent) : AbstractEffectLoader(parent) { - m_loaders << new StaticPluginEffectLoader(this) - << new ScriptedEffectLoader(this) + m_loaders << new ScriptedEffectLoader(this) << new PluginEffectLoader(this); for (auto it = m_loaders.constBegin(); it != m_loaders.constEnd(); ++it) { connect(*it, &AbstractEffectLoader::effectLoaded, this, &AbstractEffectLoader::effectLoaded); diff --git a/src/effectloader.h b/src/effectloader.h index c74c424921..4b0594564b 100644 --- a/src/effectloader.h +++ b/src/effectloader.h @@ -294,31 +294,6 @@ private: QMetaObject::Connection m_queryConnection; }; -class StaticPluginEffectLoader : public AbstractEffectLoader -{ - Q_OBJECT -public: - explicit StaticPluginEffectLoader(QObject *parent = nullptr); - ~StaticPluginEffectLoader() override; - - bool hasEffect(const QString &name) const override; - bool isEffectSupported(const QString &name) const override; - QStringList listOfKnownEffects() const override; - - void clear() override; - void queryAndLoadAll() override; - bool loadEffect(const QString &name) override; - bool loadEffect(const QString &name, LoadEffectFlags flags); - -private: - EffectPluginFactory *factory(const QStaticPlugin &staticPlugin) const; - bool checkEnabledByDefault(const QStaticPlugin &staticPlugin) const; - - QHash m_staticPlugins; - EffectLoadQueue *m_queue; - QStringList m_loadedEffects; -}; - class PluginEffectLoader : public AbstractEffectLoader { Q_OBJECT diff --git a/src/effects/CMakeLists.txt b/src/effects/CMakeLists.txt index 2f92ecaf32..1f3614d0a2 100644 --- a/src/effects/CMakeLists.txt +++ b/src/effects/CMakeLists.txt @@ -77,7 +77,7 @@ set(kwin_effect_XCB_LIBS set(kwin_effect_OWN_LIBS ${kwin_effect_OWN_LIBS} kwinglutils) macro(KWIN4_ADD_EFFECT_MODULE name) - kcoreaddons_add_plugin(${name} STATIC SOURCES ${ARGN} INSTALL_NAMESPACE "kwin/effects/static") + kcoreaddons_add_plugin(${name} STATIC SOURCES ${ARGN} INSTALL_NAMESPACE "kwin/effects/plugins") target_link_libraries(${name} PRIVATE ${kwin_effect_KDE_LIBS} ${kwin_effect_OWN_LIBS} @@ -170,7 +170,7 @@ set(kwin4_effect_builtins_sources qt5_add_resources(kwin4_effect_builtins_sources shaders.qrc) add_library(kwin4_effect_builtins STATIC ${kwin4_effect_builtins_sources}) -kcoreaddons_target_static_plugins(kwin4_effect_builtins "kwin/effects/static" LINK_OPTION "PRIVATE") +kcoreaddons_target_static_plugins(kwin4_effect_builtins "kwin/effects/plugins" LINK_OPTION "PRIVATE") target_link_libraries(kwin4_effect_builtins PRIVATE ${kwin_effect_KDE_LIBS} ${kwin_effect_OWN_LIBS}