Commit 7834bec5 authored by David Edmundson's avatar David Edmundson

[libkwineffects] Replace property name lookup with calling the virtual methods

Summary:
EffectWindow proxies its properties from the client/deleted's
properties.

QObject::property(char*) is a slow string search. It's a loop
of string comparisons not a hash lookup!

QML's use of properties is different, there's a property cache.

It's fetched multiple times for every window in every paint of some
effects (such as blur). Hotspot shows this as a significant amount of
the render pass (X11) with nothing in kwin animating.

This patch replaces the macro that does
parent()->property("propertyName")
with a macro calling the relevant function directly without metaobjects.

This also improves type safety for future changes.

Test Plan:
Existing unit tests
Ran it for a bit

Reviewers: #kwin, graesslin

Subscribers: graesslin, zzag, broulik, kwin

Tags: #kwin

Differential Revision: https://phabricator.kde.org/D16602
parent 4985cf2d
......@@ -29,51 +29,217 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
using namespace KWin;
class MockEffectWindowHelper : public QObject
class MockEffectWindow : public EffectWindow
{
Q_OBJECT
Q_PROPERTY(qreal opacity READ opacity WRITE setOpacity)
public:
MockEffectWindowHelper(QObject *parent = nullptr);
double opacity() const {
MockEffectWindow(QObject *parent = nullptr);
WindowQuadList buildQuads(bool force = false) const override;
QVariant data(int role) const override;
QRect decorationInnerRect() const override;
void deleteProperty(long int atom) const override;
void disablePainting(int reason) override;
void enablePainting(int reason) override;
EffectWindow *findModal() override;
const EffectWindowGroup *group() const override;
bool isPaintingEnabled() override;
EffectWindowList mainWindows() const override;
QByteArray readProperty(long int atom, long int type, int format) const override;
void refWindow() override;
void unrefWindow() override;
QRegion shape() const override;
void setData(int role, const QVariant &data) override;
void referencePreviousWindowPixmap() override {}
void unreferencePreviousWindowPixmap() override {}
bool isDeleted() const override {
return false;
}
bool isMinimized() const override {
return false;
}
double opacity() const override {
return m_opacity;
}
void setOpacity(qreal opacity) {
m_opacity = opacity;
}
private:
qreal m_opacity;
};
MockEffectWindowHelper::MockEffectWindowHelper(QObject *parent)
: QObject(parent)
, m_opacity(1.0)
{
}
bool hasAlpha() const override {
return true;
}
QStringList activities() const override {
return QStringList();
}
int desktop() const override {
return 0;
}
QVector<uint> desktops() const override {
return {};
}
int x() const override {
return 0;
}
int y() const override {
return 0;
}
int width() const override {
return 100;
}
int height() const override {
return 100;
}
QSize basicUnit() const override {
return QSize();
}
QRect geometry() const override {
return QRect();
}
QRect expandedGeometry() const override {
return QRect();
}
int screen() const override {
return 0;
}
bool hasOwnShape() const override {
return false;
}
QPoint pos() const override {
return QPoint();
}
QSize size() const override {
return QSize(100,100);
}
QRect rect() const override {
return QRect(0,0,100,100);
}
bool isMovable() const override {
return true;
}
bool isMovableAcrossScreens() const override {
return true;
}
bool isUserMove() const override {
return false;
}
bool isUserResize() const override {
return false;
}
QRect iconGeometry() const override {
return QRect();
}
bool isDesktop() const override {
return false;
}
bool isDock() const override {
return false;
}
bool isToolbar() const override {
return false;
}
bool isMenu() const override {
return false;
}
bool isNormalWindow() const override {
return true;
}
bool isSpecialWindow() const override {
return false;
}
bool isDialog() const override {
return false;
}
bool isSplash() const override {
return false;
}
bool isUtility() const override {
return false;
}
bool isDropdownMenu() const override {
return false;
}
bool isPopupMenu() const override {
return false;
}
bool isTooltip() const override {
return false;
}
bool isNotification() const override {
return false;
}
bool isOnScreenDisplay() const override {
return false;
}
bool isComboBox() const override {
return false;
}
bool isDNDIcon() const override {
return false;
}
QRect contentsRect() const override {
return QRect();
}
bool decorationHasAlpha() const override {
return false;
}
QString caption() const override {
return QString();
}
QIcon icon() const override {
return QIcon();
}
QString windowClass() const override {
return QString();
}
QString windowRole() const override {
return QString();
}
NET::WindowType windowType() const override {
return NET::Normal;
}
bool acceptsFocus() const override {
return true;
}
bool keepAbove() const override {
return false;
}
bool keepBelow() const override {
return false;
}
bool isModal() const override {
return false;
}
bool isSkipSwitcher() const override {
return false;
}
bool isCurrentTab() const override {
return true;
}
bool skipsCloseAnimation() const override {
return false;
}
KWayland::Server::SurfaceInterface *surface() const override {
return nullptr;
}
bool isFullScreen() const override {
return false;
}
bool isUnresponsive() const override {
return false;
}
bool isPopupWindow() const override {
return false;
}
bool isManaged() const override {
return true;
}
bool isWaylandClient() const override {
return true;
}
bool isX11Client() const override {
return false;
}
class MockEffectWindow : public EffectWindow
{
Q_OBJECT
public:
MockEffectWindow(QObject *parent = nullptr);
virtual WindowQuadList buildQuads(bool force = false) const;
virtual QVariant data(int role) const;
virtual QRect decorationInnerRect() const;
virtual void deleteProperty(long int atom) const;
virtual void disablePainting(int reason);
virtual void enablePainting(int reason);
virtual EffectWindow *findModal();
virtual const EffectWindowGroup *group() const;
virtual bool isPaintingEnabled();
virtual EffectWindowList mainWindows() const;
virtual QByteArray readProperty(long int atom, long int type, int format) const;
virtual void refWindow();
virtual void unrefWindow();
virtual QRegion shape() const;
virtual void setData(int role, const QVariant &data);
virtual void referencePreviousWindowPixmap() {}
virtual void unreferencePreviousWindowPixmap() {}
QList<int> desktops() const { return {};}
private:
qreal m_opacity = 1.0;
};
MockEffectWindow::MockEffectWindow(QObject *parent)
......@@ -175,9 +341,8 @@ private Q_SLOTS:
void TestWindowPaintData::testCtor()
{
MockEffectWindowHelper helper;
helper.setOpacity(0.5);
MockEffectWindow w(&helper);
MockEffectWindow w;
w.setOpacity(0.5);
WindowPaintData data(&w);
QCOMPARE(data.xScale(), 1.0);
QCOMPARE(data.yScale(), 1.0);
......@@ -196,8 +361,7 @@ void TestWindowPaintData::testCtor()
void TestWindowPaintData::testCopyCtor()
{
MockEffectWindowHelper helper;
MockEffectWindow w(&helper);
MockEffectWindow w;
WindowPaintData data(&w);
WindowPaintData data2(data);
// no value had been changed
......@@ -242,8 +406,7 @@ void TestWindowPaintData::testCopyCtor()
void TestWindowPaintData::testOperatorMultiplyAssign()
{
MockEffectWindowHelper helper;
MockEffectWindow w(&helper);
MockEffectWindow w;
WindowPaintData data(&w);
// without anything set, it's 1.0 on all axis
QCOMPARE(data.xScale(), 1.0);
......@@ -268,8 +431,7 @@ void TestWindowPaintData::testOperatorMultiplyAssign()
void TestWindowPaintData::testOperatorPlus()
{
MockEffectWindowHelper helper;
MockEffectWindow w(&helper);
MockEffectWindow w;
WindowPaintData data(&w);
QCOMPARE(data.xTranslation(), 0.0);
QCOMPARE(data.yTranslation(), 0.0);
......@@ -291,8 +453,7 @@ void TestWindowPaintData::testOperatorPlus()
void TestWindowPaintData::testMultiplyBrightness()
{
MockEffectWindowHelper helper;
MockEffectWindow w(&helper);
MockEffectWindow w;
WindowPaintData data(&w);
QCOMPARE(0.2, data.multiplyBrightness(0.2));
QCOMPARE(0.2, data.brightness());
......@@ -305,8 +466,7 @@ void TestWindowPaintData::testMultiplyBrightness()
void TestWindowPaintData::testMultiplyOpacity()
{
MockEffectWindowHelper helper;
MockEffectWindow w(&helper);
MockEffectWindow w;
WindowPaintData data(&w);
QCOMPARE(0.2, data.multiplyOpacity(0.2));
QCOMPARE(0.2, data.opacity());
......@@ -319,8 +479,7 @@ void TestWindowPaintData::testMultiplyOpacity()
void TestWindowPaintData::testMultiplySaturation()
{
MockEffectWindowHelper helper;
MockEffectWindow w(&helper);
MockEffectWindow w;
WindowPaintData data(&w);
QCOMPARE(0.2, data.multiplySaturation(0.2));
QCOMPARE(0.2, data.saturation());
......
......@@ -254,6 +254,20 @@ QByteArray Deleted::windowRole() const
return m_windowRole;
}
QVector<uint> Deleted::x11DesktopIds() const
{
const auto desks = desktops();
QVector<uint> x11Ids;
x11Ids.reserve(desks.count());
std::transform(desks.constBegin(), desks.constEnd(),
std::back_inserter(x11Ids),
[] (const VirtualDesktop *vd) {
return vd->x11DesktopNumber();
}
);
return x11Ids;
}
void Deleted::addTransient(Deleted *transient)
{
m_transients.append(transient);
......
......@@ -181,6 +181,8 @@ public:
return m_wasPopupWindow;
}
QVector<uint> x11DesktopIds() const;
protected:
virtual void debug(QDebug& stream) const;
private Q_SLOTS:
......
......@@ -1658,8 +1658,19 @@ KSharedConfigPtr EffectsHandlerImpl::inputConfig() const
EffectWindowImpl::EffectWindowImpl(Toplevel *toplevel)
: EffectWindow(toplevel)
, toplevel(toplevel)
, sw(NULL)
, sw(nullptr)
{
// Deleted windows are not managed. So, when windowClosed signal is
// emitted, effects can't distinguish managed windows from unmanaged
// windows(e.g. combo box popups, popup menus, etc). Save value of the
// managed property during construction of EffectWindow. At that time,
// parent can be Client, ShellClient, or Unmanaged. So, later on, when
// an instance of Deleted becomes parent of the EffectWindow, effects
// can still figure out whether it is/was a managed window.
managed = toplevel->isClient();
waylandClient = qobject_cast<KWin::ShellClient *>(toplevel) != nullptr;
x11Client = !waylandClient;
}
EffectWindowImpl::~EffectWindowImpl()
......@@ -1690,7 +1701,7 @@ const EffectWindowGroup* EffectWindowImpl::group() const
{
if (Client* c = dynamic_cast< Client* >(toplevel))
return c->group()->effectGroup();
return NULL; // TODO
return nullptr; // TODO
}
void EffectWindowImpl::refWindow()
......@@ -1707,6 +1718,122 @@ void EffectWindowImpl::unrefWindow()
abort(); // TODO
}
#define TOPLEVEL_HELPER( rettype, prototype, toplevelPrototype) \
rettype EffectWindowImpl::prototype ( ) const \
{ \
return toplevel->toplevelPrototype(); \
}
TOPLEVEL_HELPER(double, opacity, opacity)
TOPLEVEL_HELPER(bool, hasAlpha, hasAlpha)
TOPLEVEL_HELPER(int, x, x)
TOPLEVEL_HELPER(int, y, y)
TOPLEVEL_HELPER(int, width, width)
TOPLEVEL_HELPER(int, height, height)
TOPLEVEL_HELPER(QPoint, pos, pos)
TOPLEVEL_HELPER(QSize, size, size)
TOPLEVEL_HELPER(int, screen, screen)
TOPLEVEL_HELPER(QRect, geometry, geometry)
TOPLEVEL_HELPER(QRect, expandedGeometry, visibleRect)
TOPLEVEL_HELPER(QRect, rect, rect)
TOPLEVEL_HELPER(int, desktop, desktop)
TOPLEVEL_HELPER(bool, isDesktop, isDesktop)
TOPLEVEL_HELPER(bool, isDock, isDock)
TOPLEVEL_HELPER(bool, isToolbar, isToolbar)
TOPLEVEL_HELPER(bool, isMenu, isMenu)
TOPLEVEL_HELPER(bool, isNormalWindow, isNormalWindow)
TOPLEVEL_HELPER(bool, isDialog, isDialog)
TOPLEVEL_HELPER(bool, isSplash, isSplash)
TOPLEVEL_HELPER(bool, isUtility, isUtility)
TOPLEVEL_HELPER(bool, isDropdownMenu, isDropdownMenu)
TOPLEVEL_HELPER(bool, isPopupMenu, isPopupMenu)
TOPLEVEL_HELPER(bool, isTooltip, isTooltip)
TOPLEVEL_HELPER(bool, isNotification, isNotification)
TOPLEVEL_HELPER(bool, isOnScreenDisplay, isOnScreenDisplay)
TOPLEVEL_HELPER(bool, isComboBox, isComboBox)
TOPLEVEL_HELPER(bool, isDNDIcon, isDNDIcon)
TOPLEVEL_HELPER(bool, isDeleted, isDeleted)
TOPLEVEL_HELPER(bool, hasOwnShape, shape)
TOPLEVEL_HELPER(QString, windowRole, windowRole)
TOPLEVEL_HELPER(QStringList, activities, activities)
TOPLEVEL_HELPER(bool, skipsCloseAnimation, skipsCloseAnimation)
TOPLEVEL_HELPER(KWayland::Server::SurfaceInterface *, surface, surface)
TOPLEVEL_HELPER(bool, isPopupWindow, isPopupWindow)
#undef TOPLEVEL_HELPER
#define CLIENT_HELPER_WITH_DELETED( rettype, prototype, propertyname, defaultValue ) \
rettype EffectWindowImpl::prototype ( ) const \
{ \
auto client = qobject_cast<AbstractClient *>(toplevel); \
if (client) { \
return client->propertyname(); \
} \
auto deleted = qobject_cast<Deleted *>(toplevel); \
if (deleted) { \
return deleted->propertyname(); \
} \
return defaultValue; \
}
CLIENT_HELPER_WITH_DELETED(bool, isMinimized, isMinimized, false)
CLIENT_HELPER_WITH_DELETED(bool, isModal, isModal, false)
CLIENT_HELPER_WITH_DELETED(bool, isFullScreen, isFullScreen, false)
CLIENT_HELPER_WITH_DELETED(bool, isCurrentTab, isCurrentTab, false)
CLIENT_HELPER_WITH_DELETED(bool, keepAbove, keepAbove, false)
CLIENT_HELPER_WITH_DELETED(bool, keepBelow, keepBelow, false)
CLIENT_HELPER_WITH_DELETED(QString, caption, caption, QString());
CLIENT_HELPER_WITH_DELETED(QVector<uint>, desktops, x11DesktopIds, QVector<uint>());
#undef CLIENT_HELPER_WITH_DELETED
QString EffectWindowImpl::windowClass() const
{
return toplevel->resourceName() + QLatin1Char(' ') + toplevel->resourceClass();
}
QRect EffectWindowImpl::contentsRect() const
{
return QRect(toplevel->clientPos(), toplevel->clientSize());
}
NET::WindowType EffectWindowImpl::windowType() const
{
return toplevel->windowType();
}
#define CLIENT_HELPER( rettype, prototype, propertyname, defaultValue ) \
rettype EffectWindowImpl::prototype ( ) const \
{ \
auto client = qobject_cast<AbstractClient *>(toplevel); \
if (client) { \
return client->propertyname(); \
} \
return defaultValue; \
}
CLIENT_HELPER(bool, isMovable, isMovable, false)
CLIENT_HELPER(bool, isMovableAcrossScreens, isMovableAcrossScreens, false)
CLIENT_HELPER(bool, isUserMove, isMove, false)
CLIENT_HELPER(bool, isUserResize, isResize, false)
CLIENT_HELPER(QRect, iconGeometry, iconGeometry, QRect())
CLIENT_HELPER(bool, isSpecialWindow, isSpecialWindow, true)
CLIENT_HELPER(bool, acceptsFocus, wantsInput, true) // We don't actually know...
CLIENT_HELPER(QIcon, icon, icon, QIcon())
CLIENT_HELPER(bool, isSkipSwitcher, skipSwitcher, false)
CLIENT_HELPER(bool, decorationHasAlpha, decorationHasAlpha, false)
CLIENT_HELPER(bool, isUnresponsive, unresponsive, false)
#undef CLIENT_HELPER
QSize EffectWindowImpl::basicUnit() const
{
if (auto client = qobject_cast<Client*>(toplevel)){
return client->basicUnit();
}
return QSize(1,1);
}
void EffectWindowImpl::setWindow(Toplevel* w)
{
toplevel = w;
......@@ -1868,6 +1995,22 @@ void EffectWindowImpl::unreferencePreviousWindowPixmap()
}
}
bool EffectWindowImpl::isManaged() const
{
return managed;
}
bool EffectWindowImpl::isWaylandClient() const
{
return waylandClient;
}
bool EffectWindowImpl::isX11Client() const
{
return x11Client;
}
//****************************************
// EffectWindowGroupImpl
//****************************************
......
......@@ -357,7 +357,7 @@ class EffectWindowImpl : public EffectWindow
Q_OBJECT
public:
explicit EffectWindowImpl(Toplevel *toplevel);
virtual ~EffectWindowImpl();
~EffectWindowImpl() override;
void enablePainting(int reason) override;
void disablePainting(int reason) override;
......@@ -368,7 +368,79 @@ public:
const EffectWindowGroup* group() const override;
bool isDeleted() const override;
bool isMinimized() const override;
double opacity() const override;
bool hasAlpha() const override;
QStringList activities() const override;
int desktop() const override;
QVector<uint> desktops() const override;
int x() const override;
int y() const override;
int width() const override;
int height() const override;
QSize basicUnit() const override;
QRect geometry() const override;
QString caption() const override;
QRect expandedGeometry() const override;
QRegion shape() const override;
int screen() const override;
bool hasOwnShape() const override; // only for shadow effect, for now
QPoint pos() const override;
QSize size() const override;
QRect rect() const override;
bool isMovable() const override;
bool isMovableAcrossScreens() const override;
bool isUserMove() const override;
bool isUserResize() const override;
QRect iconGeometry() const override;
bool isDesktop() const override;
bool isDock() const override;
bool isToolbar() const override;
bool isMenu() const override;
bool isNormalWindow() const override;
bool isSpecialWindow() const override;
bool isDialog() const override;
bool isSplash() const override;
bool isUtility() const override;
bool isDropdownMenu() const override;
bool isPopupMenu() const override;
bool isTooltip() const override;
bool isNotification() const override;
bool isOnScreenDisplay() const override;
bool isComboBox() const override;
bool isDNDIcon() const override;
bool skipsCloseAnimation() const override;
bool acceptsFocus() const override;
bool keepAbove() const override;
bool keepBelow() const override;
bool isModal() const override;
bool isPopupWindow() const override;
KWayland::Server::SurfaceInterface *surface() const override;
bool isFullScreen() const override;
bool isUnresponsive() const override;
QRect contentsRect() const override;
bool decorationHasAlpha() const override;
QIcon icon() const override;
QString windowClass() const override;
NET::WindowType windowType() const override;
bool isSkipSwitcher() const override;
bool isCurrentTab() const override;
QString windowRole() const override;
bool isManaged() const override;
bool isWaylandClient() const override;
bool isX11Client() const override;
QRect decorationInnerRect() const override;
QByteArray readProperty(long atom, long type, int format) const override;
void deleteProperty(long atom) const override;
......@@ -401,6 +473,7 @@ public:
QList<DesktopThumbnailItem*> const &desktopThumbnails() const {
return m_desktopThumbnails;
}
private Q_SLOTS:
void thumbnailDestroyed(QObject *object);
void thumbnailTargetChanged();
......@@ -412,6 +485,9 @@ private:
QHash<int, QVariant> dataMap;
QHash<WindowThumbnailItem*, QWeakPointer<EffectWindowImpl> > m_thumbnails;
QList<DesktopThumbnailItem*> m_desktopThumbnails;
bool managed = false;
bool waylandClient;
bool x11Client;
};
class EffectWindowGroupImpl
......
......@@ -775,9 +775,6 @@ public:
Private(EffectWindow *q);
EffectWindow *q;
bool managed = false;
bool waylandClient;
bool x11Client;
};
EffectWindow::Private::Private(EffectWindow *q)
......@@ -789,128 +786,23 @@ EffectWindow::EffectWindow(QObject *parent)
: QObject(parent)
, d(new Private(this))
{
// Deleted windows are not managed. So, when windowClosed signal is
// emitted, effects can't distinguish managed windows from unmanaged
// windows(e.g. combo box popups, popup menus, etc). Save value of the
// managed property during construction of EffectWindow. At that time,
// parent can be Client, ShellClient, or Unmanaged. So, later on, when
// an instance of Deleted becomes parent of the EffectWindow, effects
// can still figure out whether it is/was a managed window.
d->managed = parent->property("managed").value<bool>();
d->waylandClient = parent->inherits("KWin::ShellClient");
d->x11Client = !d->waylandClient;
}
EffectWindow::~EffectWindow()
{
}
#define WINDOW_HELPER( rettype, prototype, propertyname ) \
rettype EffectWindow::prototype ( ) const \
{ \
return parent()->property( propertyname ).value< rettype >(); \
}
WINDOW_HELPER(double, opacity, "opacity")
WINDOW_HELPER(bool, hasAlpha, "alpha")
WINDOW_HELPER(int, x, "x")
WINDOW_HELPER(int, y, "y")
WINDOW_HELPER(int, width, "width")
WINDOW_HELPER(int, height, "height")
WINDOW_HELPER(QPoint, pos, "pos")
WINDOW_HELPER(QSize, size, "size")
WINDOW_HELPER(int, screen, "screen")
WINDOW_HELPER(QRect, geometry, "geometry")
WINDOW_HELPER(QRect, expandedGeometry, "visibleRect")
WINDOW_HELPER(QRect, rect, "rect")
#ifndef KWIN_NO_DEPRECATED