Commit 76efe517 authored by Martin Flöser's avatar Martin Flöser

Turn built-in effects into a library kwin links against

As all effects have always been compiled into the same .so file it's
questionable whether resolving the effects through a library is useful
at all. By linking against the built-in effects we gain the following
advantages:
* don't have to load/unload the KLibrary
* don't have to resolve the create, supported and enabled functions
* no version check required
* no dependency resolving (effects don't use it)
* remove the KWIN_EFFECT macros from the effects

All the effects are now registered in an effects_builtins file which
maps the name to a factory method and supported or enabled by default
methods.

During loading the effects we first check whether there is a built-in
effect by the given name and make a shortcut to create it through that.
If that's not possible the normal plugin loading is used.

Completely unscientific testing [1] showed an improvement of almost 10
msec during loading all the effects I use.

[1] QElapsedTimer around the loading code, start kwin five times, take
average.

REVIEW: 115073
parent daf0772c
......@@ -240,6 +240,7 @@ qt5_add_resources( kwin_KDEINIT_SRCS resources.qrc )
set(kwin_OWN_LIBS
kdecorations
kwineffects
kwin4_effect_builtins
)
set(kwin_QT_LIBS
......
......@@ -47,6 +47,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "virtualdesktops.h"
#include "workspace.h"
#include "kwinglutils.h"
#include "effects/effect_builtins.h"
#include <QDebug>
#include <QFile>
......@@ -1391,6 +1392,12 @@ bool EffectsHandlerImpl::loadEffect(const QString& name, bool checkDefault)
return loadScriptedEffect(name, service.data());
}
if (Effect *e = loadBuiltInEffect(internalname.remove(QStringLiteral("kwin4_effect_")).toUtf8(), checkDefault)) {
effect_order.insert(service->property(QStringLiteral("X-KDE-Ordering")).toInt(), EffectPair(name, e));
effectsChanged();
return true;
}
KLibrary* library = findEffectLibrary(service.data());
if (!library) {
return false;
......@@ -1474,6 +1481,23 @@ bool EffectsHandlerImpl::loadEffect(const QString& name, bool checkDefault)
return true;
}
Effect *EffectsHandlerImpl::loadBuiltInEffect(const QByteArray &name, bool checkDefault)
{
if (!BuiltInEffects::available(name)) {
return nullptr;
}
if (!BuiltInEffects::supported(name)) {
qWarning() << "Effect " << name << " is not supported" ;
return nullptr;
}
if (checkDefault) {
if (!BuiltInEffects::enabledByDefault(name)) {
return nullptr;
}
}
return BuiltInEffects::create(name);
}
bool EffectsHandlerImpl::loadScriptedEffect(const QString& name, KService *service)
{
#ifdef KWIN_BUILD_SCRIPTING
......
......@@ -265,6 +265,7 @@ private Q_SLOTS:
private:
typedef QVector< Effect*> EffectsList;
typedef EffectsList::const_iterator EffectsIterator;
Effect *loadBuiltInEffect(const QByteArray &name, bool checkDefault);
EffectsList m_activeEffects;
EffectsIterator m_currentDrawWindowIterator;
EffectsIterator m_currentPaintWindowIterator;
......
......@@ -42,7 +42,7 @@ elseif(KWIN_BUILD_OPENGLES)
endif()
macro( KWIN4_ADD_EFFECT_BACKEND name )
add_library( ${name} MODULE ${ARGN} )
add_library( ${name} SHARED ${ARGN} )
target_link_libraries( ${name} ${kwin_effect_OWN_LIBS} ${kwin_effect_KDE_LIBS} ${kwin_effect_QT_LIBS} ${kwin_effect_XLIB_LIBS} ${kwin_effect_XCB_LIBS})
endmacro()
......@@ -56,8 +56,10 @@ macro( KWIN4_ADD_EFFECT name )
elseif(KWIN_BUILD_OPENGLES)
set_target_properties(kwin4_effect_${name} PROPERTIES COMPILE_FLAGS "-DKWIN_HAVE_OPENGLES")
endif()
set_target_properties(kwin4_effect_${name} PROPERTIES VERSION 1.0.0 SOVERSION 1 )
set_target_properties(kwin4_effect_${name} PROPERTIES OUTPUT_NAME ${KWIN_NAME}4_effect_${name})
install( TARGETS kwin4_effect_${name} DESTINATION ${PLUGIN_INSTALL_DIR} )
install(TARGETS kwin4_effect_${name} ${INSTALL_TARGETS_DEFAULT_ARGS} )
endmacro()
......@@ -97,7 +99,7 @@ endmacro()
install( FILES kwineffect.desktop DESTINATION ${SERVICETYPES_INSTALL_DIR} )
# Create initial variables
set( kwin4_effect_builtins_sources logging.cpp)
set( kwin4_effect_builtins_sources logging.cpp effect_builtins.cpp)
if( NOT KWIN_MOBILE_EFFECTS )
set( kwin4_effect_builtins_config_sources configs_builtins.cpp )
endif()
......
......@@ -32,10 +32,6 @@
namespace KWin
{
KWIN_EFFECT(contrast, ContrastEffect)
KWIN_EFFECT_SUPPORTED(contrast, ContrastEffect::supported())
KWIN_EFFECT_ENABLEDBYDEFAULT(contrast, ContrastEffect::enabledByDefault())
ContrastEffect::ContrastEffect()
{
shader = ContrastShader::create();
......
......@@ -29,10 +29,6 @@
namespace KWin
{
KWIN_EFFECT(blur, BlurEffect)
KWIN_EFFECT_SUPPORTED(blur, BlurEffect::supported())
KWIN_EFFECT_ENABLEDBYDEFAULT(blur, BlurEffect::enabledByDefault())
BlurEffect::BlurEffect()
{
shader = BlurShader::create();
......
......@@ -37,9 +37,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
namespace KWin
{
KWIN_EFFECT(coverswitch, CoverSwitchEffect)
KWIN_EFFECT_SUPPORTED(coverswitch, CoverSwitchEffect::supported())
CoverSwitchEffect::CoverSwitchEffect()
: mActivated(0)
, angle(60.0)
......
......@@ -47,9 +47,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
namespace KWin
{
KWIN_EFFECT(cube, CubeEffect)
KWIN_EFFECT_SUPPORTED(cube, CubeEffect::supported())
CubeEffect::CubeEffect()
: activated(false)
, cube_painting(false)
......
......@@ -26,7 +26,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
namespace KWin
{
KWIN_EFFECT(dashboard, DashboardEffect)
DashboardEffect::DashboardEffect()
: transformWindow(false)
......
......@@ -45,8 +45,6 @@ namespace KWin
// WARNING, TODO: This effect relies on the desktop layout being EWMH-compliant.
KWIN_EFFECT(desktopgrid, DesktopGridEffect)
DesktopGridEffect::DesktopGridEffect()
: activated(false)
, timeline()
......
......@@ -28,8 +28,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
namespace KWin
{
KWIN_EFFECT(diminactive, DimInactiveEffect)
DimInactiveEffect::DimInactiveEffect()
{
reconfigure(ReconfigureAll);
......
......@@ -24,8 +24,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
namespace KWin
{
KWIN_EFFECT(dimscreen, DimScreenEffect)
DimScreenEffect::DimScreenEffect()
: mActivated(false)
, activateAnimation(false)
......
/********************************************************************
KWin - the KDE window manager
This file is part of the KDE project.
Copyright (C) 2014 Martin Gräßlin <mgraesslin@kde.org>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************/
#include "effect_builtins.h"
// common effects
#include "backgroundcontrast/contrast.h"
#include "blur/blur.h"
#include "kscreen/kscreen.h"
#include "presentwindows/presentwindows.h"
#include "screenedge/screenedgeeffect.h"
#include "screenshot/screenshot.h"
#include "slidingpopups/slidingpopups.h"
#include "taskbarthumbnail/taskbarthumbnail.h"
// Common effects only relevant to desktop
#include "dashboard/dashboard.h"
#include "desktopgrid/desktopgrid.h"
#include "diminactive/diminactive.h"
#include "dimscreen/dimscreen.h"
#include "fallapart/fallapart.h"
#include "highlightwindow/highlightwindow.h"
#include "magiclamp/magiclamp.h"
#include "minimizeanimation/minimizeanimation.h"
#include "resize/resize.h"
#include "showfps/showfps.h"
#include "showpaint/showpaint.h"
#include "slide/slide.h"
#include "slideback/slideback.h"
#include "thumbnailaside/thumbnailaside.h"
#include "windowgeometry/windowgeometry.h"
#include "zoom/zoom.h"
#include "logout/logout.h"
// OpenGL-specific effects for desktop
#include "coverswitch/coverswitch.h"
#include "cube/cube.h"
#include "flipswitch/flipswitch.h"
#include "glide/glide.h"
#include "invert/invert.h"
#include "lookingglass/lookingglass.h"
#include "magnifier/magnifier.h"
#include "mouseclick/mouseclick.h"
#include "mousemark/mousemark.h"
#include "sheet/sheet.h"
#include "snaphelper/snaphelper.h"
#include "startupfeedback/startupfeedback.h"
#include "trackmouse/trackmouse.h"
#include "wobblywindows/wobblywindows.h"
namespace KWin
{
template <class T>
inline Effect *createHelper()
{
return new T();
}
class EffectLoader
{
public:
EffectLoader();
Effect *create(const QByteArray &name);
bool hasEffect(const QByteArray &name) const;
bool supported(const QByteArray &name) const;
bool enabledByDefault(const QByteArray &name) const;
private:
typedef Effect *(*CreateInstanceFunction)();
typedef bool (*SupportedFunction)();
QHash<QByteArray, CreateInstanceFunction> m_createHash;
QHash<QByteArray, SupportedFunction> m_supportedHash;
QHash<QByteArray, SupportedFunction> m_enabledHash;
};
EffectLoader::EffectLoader()
{
#define EFFECT(name, className) \
m_createHash.insert(QByteArrayLiteral(#name), &createHelper< className >);
EFFECT(blur, BlurEffect)
EFFECT(contrast, ContrastEffect)
EFFECT(coverswitch, CoverSwitchEffect)
EFFECT(cube, CubeEffect)
EFFECT(dashboard, DashboardEffect)
EFFECT(desktopgrid, DesktopGridEffect)
EFFECT(diminactive, DimInactiveEffect)
EFFECT(dimscreen, DimScreenEffect)
EFFECT(fallapart, FallApartEffect)
EFFECT(flipswitch, FlipSwitchEffect)
EFFECT(glide, GlideEffect)
EFFECT(highlightwindow, HighlightWindowEffect)
EFFECT(invert, InvertEffect)
EFFECT(kscreen, KscreenEffect)
EFFECT(logout, LogoutEffect)
EFFECT(lookingglass, LookingGlassEffect)
EFFECT(magiclamp, MagicLampEffect)
EFFECT(magnifier, MagnifierEffect)
EFFECT(minimizeanimation, MinimizeAnimationEffect)
EFFECT(mouseclick, MouseClickEffect)
EFFECT(mousemark, MouseMarkEffect)
EFFECT(presentwindows, PresentWindowsEffect)
EFFECT(resize, ResizeEffect)
EFFECT(screenedge, ScreenEdgeEffect)
EFFECT(screenshot, ScreenShotEffect)
EFFECT(sheet, SheetEffect)
EFFECT(showfps, ShowFpsEffect)
EFFECT(showpaint, ShowPaintEffect)
EFFECT(slide, SlideEffect)
EFFECT(slideback, SlideBackEffect)
EFFECT(slidingpopups, SlidingPopupsEffect)
EFFECT(snaphelper, SnapHelperEffect)
EFFECT(startupfeedback, StartupFeedbackEffect)
EFFECT(taskbarthumbnail, TaskbarThumbnailEffect)
EFFECT(thumbnailaside, ThumbnailAsideEffect)
EFFECT(trackmouse, TrackMouseEffect)
EFFECT(windowgeometry, WindowGeometry)
EFFECT(wobblywindows, WobblyWindowsEffect)
EFFECT(zoom, ZoomEffect)
#undef EFFECT
#define SUPPORTED(name, method) \
m_supportedHash.insert(QByteArrayLiteral(#name), &method);
SUPPORTED(blur, BlurEffect::supported)
SUPPORTED(contrast, ContrastEffect::supported)
SUPPORTED(coverswitch, CoverSwitchEffect::supported)
SUPPORTED(cube, CubeEffect::supported)
SUPPORTED(fallapart, FallApartEffect::supported)
SUPPORTED(flipswitch, FlipSwitchEffect::supported)
SUPPORTED(glide, GlideEffect::supported)
SUPPORTED(invert, InvertEffect::supported)
SUPPORTED(lookingglass, LookingGlassEffect::supported)
SUPPORTED(magiclamp, MagicLampEffect::supported)
SUPPORTED(magnifier, MagnifierEffect::supported)
SUPPORTED(screenshot, ScreenShotEffect::supported)
SUPPORTED(sheet, SheetEffect::supported)
SUPPORTED(startupfeedback, StartupFeedbackEffect::supported)
SUPPORTED(wobblywindows, WobblyWindowsEffect::supported)
#undef SUPPORTED
#define ENABLED(name, method) \
m_enabledHash.insert(QByteArrayLiteral(#name), &method);
ENABLED(blur, BlurEffect::enabledByDefault)
ENABLED(contrast, ContrastEffect::enabledByDefault)
#undef ENABLED
}
Effect *EffectLoader::create(const QByteArray &name)
{
auto it = m_createHash.constFind(name);
if (it == m_createHash.constEnd()) {
return nullptr;
}
return it.value()();
}
bool EffectLoader::hasEffect(const QByteArray &name) const
{
return m_createHash.contains(name);
}
bool EffectLoader::supported(const QByteArray &name) const
{
auto it = m_supportedHash.constFind(name);
if (it != m_supportedHash.constEnd()) {
return it.value()();
}
return true;
}
bool EffectLoader::enabledByDefault(const QByteArray &name) const
{
auto it = m_enabledHash.constFind(name);
if (it != m_enabledHash.constEnd()) {
return it.value()();
}
return true;
}
Q_GLOBAL_STATIC(EffectLoader, s_effectLoader)
namespace BuiltInEffects
{
Effect *create(const QByteArray &name)
{
return s_effectLoader->create(name);
}
bool available(const QByteArray &name)
{
return s_effectLoader->hasEffect(name);
}
bool supported(const QByteArray &name)
{
return s_effectLoader->supported(name);
}
bool enabledByDefault(const QByteArray &name)
{
return s_effectLoader->enabledByDefault(name);
}
} // BuiltInEffects
} // namespace
/********************************************************************
KWin - the KDE window manager
This file is part of the KDE project.
Copyright (C) 2014 Martin Gräßlin <mgraesslin@kde.org>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************/
#ifndef KWIN_EFFECT_BUILTINS_H
#define KWIN_EFFECT_BUILTINS_H
#include <kwineffects_export.h>
class QByteArray;
namespace KWin
{
class Effect;
namespace BuiltInEffects
{
KWINEFFECTS_EXPORT Effect *create(const QByteArray &name);
KWINEFFECTS_EXPORT bool available(const QByteArray &name);
KWINEFFECTS_EXPORT bool supported(const QByteArray &name);
KWINEFFECTS_EXPORT bool enabledByDefault(const QByteArray &name);
}
}
#endif
......@@ -26,9 +26,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
namespace KWin
{
KWIN_EFFECT(fallapart, FallApartEffect)
KWIN_EFFECT_SUPPORTED(fallapart, FallApartEffect::supported())
bool FallApartEffect::supported()
{
return effects->isOpenGLCompositing();
......
......@@ -38,9 +38,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
namespace KWin
{
KWIN_EFFECT(flipswitch, FlipSwitchEffect)
KWIN_EFFECT_SUPPORTED(flipswitch, FlipSwitchEffect::supported())
FlipSwitchEffect::FlipSwitchEffect()
: m_currentAnimationShape(QTimeLine::EaseInOutCurve)
, m_active(false)
......
......@@ -34,9 +34,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
namespace KWin
{
KWIN_EFFECT(glide, GlideEffect)
KWIN_EFFECT_SUPPORTED(glide, GlideEffect::supported())
static const int IsGlideWindow = 0x22A982D4;
static Atom slideAtom;
......
......@@ -23,8 +23,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
namespace KWin
{
KWIN_EFFECT(highlightwindow, HighlightWindowEffect)
HighlightWindowEffect::HighlightWindowEffect()
: m_finishing(false)
, m_fadeDuration(float(animationTime(150)))
......
......@@ -33,9 +33,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
namespace KWin
{
KWIN_EFFECT(invert, InvertEffect)
KWIN_EFFECT_SUPPORTED(invert, InvertEffect::supported())
InvertEffect::InvertEffect()
: m_inited(false),
m_valid(true),
......
......@@ -50,8 +50,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
namespace KWin
{
KWIN_EFFECT(kscreen, KscreenEffect)
KscreenEffect::KscreenEffect()
: Effect()
, m_state(StateNormal)
......
......@@ -35,8 +35,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
namespace KWin
{
KWIN_EFFECT(logout, LogoutEffect)
LogoutEffect::LogoutEffect()
: progress(0.0)
, displayEffect(false)
......
......@@ -38,10 +38,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
namespace KWin
{
KWIN_EFFECT(lookingglass, LookingGlassEffect)
KWIN_EFFECT_SUPPORTED(lookingglass, LookingGlassEffect::supported())
LookingGlassEffect::LookingGlassEffect()
: zoom(1.0f)
, target_zoom(1.0f)
......
......@@ -32,9 +32,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
namespace KWin
{
KWIN_EFFECT(magiclamp, MagicLampEffect)
KWIN_EFFECT_SUPPORTED(magiclamp, MagicLampEffect::supported())
MagicLampEffect::MagicLampEffect()
{
mActiveAnimations = 0;
......
......@@ -38,9 +38,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
namespace KWin
{
KWIN_EFFECT(magnifier, MagnifierEffect)
KWIN_EFFECT_SUPPORTED(magnifier, MagnifierEffect::supported())
const int FRAME_WIDTH = 5;
MagnifierEffect::MagnifierEffect()
......
......@@ -25,8 +25,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
namespace KWin
{
KWIN_EFFECT(minimizeanimation, MinimizeAnimationEffect)
MinimizeAnimationEffect::MinimizeAnimationEffect()
{
mActiveAnimations = 0;
......
......@@ -41,8 +41,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
namespace KWin
{
KWIN_EFFECT(mouseclick, MouseClickEffect)
MouseClickEffect::MouseClickEffect()
{
m_enabled = false;
......
......@@ -43,8 +43,6 @@ namespace KWin
#define NULL_POINT (QPoint( -1, -1 )) // null point is (0,0), which is valid :-/
KWIN_EFFECT(mousemark, MouseMarkEffect)
MouseMarkEffect::MouseMarkEffect()
{
QAction* a = new QAction(this);
......
......@@ -48,8 +48,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
namespace KWin
{
KWIN_EFFECT(presentwindows, PresentWindowsEffect)
PresentWindowsEffect::PresentWindowsEffect()
: m_proxy(this)
, m_activated(false)
......
......@@ -35,8 +35,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
namespace KWin
{
KWIN_EFFECT(resize, ResizeEffect)
ResizeEffect::ResizeEffect()
: AnimationEffect()
, m_active(false)
......
......@@ -35,8 +35,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
namespace KWin {
KWIN_EFFECT(screenedge, ScreenEdgeEffect)
ScreenEdgeEffect::ScreenEdgeEffect()
: Effect()
, m_glow(new Plasma::Svg(this))
......
......@@ -32,9 +32,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
namespace KWin