Remove now unneeded static effect loader class
This commit is contained in:
parent
66352bfc87
commit
f61097f3cb
3 changed files with 16 additions and 180 deletions
|
@ -192,152 +192,6 @@ void ScriptedEffectLoader::clear()
|
||||||
m_queue->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<StaticPluginEffectLoader, QString>(this))
|
|
||||||
{
|
|
||||||
const QVector<QStaticPlugin> staticPlugins = QPluginLoader::staticPlugins();
|
|
||||||
qWarning()<<Q_FUNC_INFO<<staticPlugins.count();
|
|
||||||
for (const QStaticPlugin &staticPlugin : staticPlugins) {
|
|
||||||
const QJsonObject rootMetaData = staticPlugin.metaData();
|
|
||||||
if (rootMetaData.value(QLatin1String("IID")) != QLatin1String(EffectPluginFactory_iid)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
const QJsonObject pluginMetaData = rootMetaData.value(QLatin1String("MetaData")).toObject();
|
|
||||||
const QString pluginId = readPluginInfo(pluginMetaData, QStringLiteral("Id")).toString();
|
|
||||||
if (pluginId.isEmpty()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (m_staticPlugins.contains(pluginId)) {
|
|
||||||
qCWarning(KWIN_CORE) << "Conflicting plugin id" << pluginId;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_staticPlugins.insert(pluginId, staticPlugin);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
StaticPluginEffectLoader::~StaticPluginEffectLoader()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
bool StaticPluginEffectLoader::hasEffect(const QString &name) const
|
|
||||||
{
|
|
||||||
return m_staticPlugins.contains(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool StaticPluginEffectLoader::isEffectSupported(const QString &name) const
|
|
||||||
{
|
|
||||||
auto it = m_staticPlugins.constFind(name);
|
|
||||||
if (it == m_staticPlugins.constEnd()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (EffectPluginFactory *effectFactory = factory(*it)) {
|
|
||||||
return effectFactory->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<EffectPluginFactory *>(staticPlugin.instance());
|
|
||||||
}
|
|
||||||
|
|
||||||
PluginEffectLoader::PluginEffectLoader(QObject *parent)
|
PluginEffectLoader::PluginEffectLoader(QObject *parent)
|
||||||
: AbstractEffectLoader(parent)
|
: AbstractEffectLoader(parent)
|
||||||
, m_queue(new EffectLoadQueue< PluginEffectLoader, KPluginMetaData>(this))
|
, m_queue(new EffectLoadQueue< PluginEffectLoader, KPluginMetaData>(this))
|
||||||
|
@ -381,12 +235,20 @@ EffectPluginFactory *PluginEffectLoader::factory(const KPluginMetaData &info) co
|
||||||
if (!info.isValid()) {
|
if (!info.isValid()) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
QPluginLoader loader(info.fileName());
|
KPluginFactory *factory;
|
||||||
if (loader.metaData().value("IID").toString() != EffectPluginFactory_iid) {
|
if (info.isStaticPlugin()) {
|
||||||
qCDebug(KWIN_CORE) << info.pluginId() << " has not matching plugin version, expected " << PluginFactory_iid << "got " << loader.metaData().value("IID");
|
// in case of static plugins we don't need to worry about the versions, because
|
||||||
return nullptr;
|
// 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<KPluginFactory *>(loader.instance());
|
||||||
}
|
}
|
||||||
KPluginFactory *factory = qobject_cast<KPluginFactory *>(loader.instance());
|
|
||||||
if (!factory) {
|
if (!factory) {
|
||||||
qCDebug(KWIN_CORE) << "Did not get KPluginFactory for " << info.pluginId();
|
qCDebug(KWIN_CORE) << "Did not get KPluginFactory for " << info.pluginId();
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
@ -511,8 +373,7 @@ void PluginEffectLoader::clear()
|
||||||
EffectLoader::EffectLoader(QObject *parent)
|
EffectLoader::EffectLoader(QObject *parent)
|
||||||
: AbstractEffectLoader(parent)
|
: AbstractEffectLoader(parent)
|
||||||
{
|
{
|
||||||
m_loaders << new StaticPluginEffectLoader(this)
|
m_loaders << new ScriptedEffectLoader(this)
|
||||||
<< new ScriptedEffectLoader(this)
|
|
||||||
<< new PluginEffectLoader(this);
|
<< new PluginEffectLoader(this);
|
||||||
for (auto it = m_loaders.constBegin(); it != m_loaders.constEnd(); ++it) {
|
for (auto it = m_loaders.constBegin(); it != m_loaders.constEnd(); ++it) {
|
||||||
connect(*it, &AbstractEffectLoader::effectLoaded, this, &AbstractEffectLoader::effectLoaded);
|
connect(*it, &AbstractEffectLoader::effectLoaded, this, &AbstractEffectLoader::effectLoaded);
|
||||||
|
|
|
@ -294,31 +294,6 @@ private:
|
||||||
QMetaObject::Connection m_queryConnection;
|
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<QString, QStaticPlugin> m_staticPlugins;
|
|
||||||
EffectLoadQueue<StaticPluginEffectLoader, QString> *m_queue;
|
|
||||||
QStringList m_loadedEffects;
|
|
||||||
};
|
|
||||||
|
|
||||||
class PluginEffectLoader : public AbstractEffectLoader
|
class PluginEffectLoader : public AbstractEffectLoader
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
|
@ -77,7 +77,7 @@ set(kwin_effect_XCB_LIBS
|
||||||
set(kwin_effect_OWN_LIBS ${kwin_effect_OWN_LIBS} kwinglutils)
|
set(kwin_effect_OWN_LIBS ${kwin_effect_OWN_LIBS} kwinglutils)
|
||||||
|
|
||||||
macro(KWIN4_ADD_EFFECT_MODULE name)
|
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
|
target_link_libraries(${name} PRIVATE
|
||||||
${kwin_effect_KDE_LIBS}
|
${kwin_effect_KDE_LIBS}
|
||||||
${kwin_effect_OWN_LIBS}
|
${kwin_effect_OWN_LIBS}
|
||||||
|
@ -170,7 +170,7 @@ set(kwin4_effect_builtins_sources
|
||||||
qt5_add_resources(kwin4_effect_builtins_sources shaders.qrc)
|
qt5_add_resources(kwin4_effect_builtins_sources shaders.qrc)
|
||||||
|
|
||||||
add_library(kwin4_effect_builtins STATIC ${kwin4_effect_builtins_sources})
|
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
|
target_link_libraries(kwin4_effect_builtins PRIVATE
|
||||||
${kwin_effect_KDE_LIBS}
|
${kwin_effect_KDE_LIBS}
|
||||||
${kwin_effect_OWN_LIBS}
|
${kwin_effect_OWN_LIBS}
|
||||||
|
|
Loading…
Reference in a new issue