Commit 63a866d9 authored by Vlad Zahorodnii's avatar Vlad Zahorodnii
Browse files

Make WindowItem handle opacity

This change makes the WindowItem track the opacity and schedule a
repaint. It further decouples the legacy scene from code window
abstractions.

It's an API breaking change. WindowPaintData no longer can make windows
more opaque. It only provides additional opacity factor.
parent 99f01ee9
......@@ -19,446 +19,6 @@
using namespace KWin;
class MockEffectWindow : public EffectWindow
{
Q_OBJECT
public:
MockEffectWindow(QObject *parent = nullptr);
QVariant data(int role) const override;
QRect decorationInnerRect() const override;
void deleteProperty(long int atom) const override;
void refVisible(int reason) override;
void unrefVisible(int reason) override;
void addRepaint(const QRect &r) override;
void addRepaint(int x, int y, int w, int h) override;
void addRepaintFull() override;
void addLayerRepaint(const QRect &r) override;
void addLayerRepaint(int x, int y, int w, int h) override;
EffectWindow *findModal() override;
EffectWindow *transientFor() override;
const EffectWindowGroup *group() const override;
EffectWindowList mainWindows() const override;
QByteArray readProperty(long int atom, long int type, int format) const override;
void refWindow() override;
void unrefWindow() override;
void setData(int role, const QVariant &data) override;
void minimize() override;
void unminimize() override;
void closeWindow() override;
void referencePreviousWindowPixmap() override
{
}
void unreferencePreviousWindowPixmap() override
{
}
QWindow *internalWindow() const override
{
return nullptr;
}
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;
}
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();
}
QRect frameGeometry() const override
{
return QRect();
}
QRect bufferGeometry() const override
{
return QRect();
}
QRect clientGeometry() const override
{
return QRect();
}
EffectScreen *screen() const override
{
return nullptr;
}
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 isCriticalNotification() 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;
}
KDecoration2::Decoration *decoration() const override
{
return nullptr;
}
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;
}
KWaylandServer::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;
}
bool isOutline() const override
{
return false;
}
bool isLockScreen() const override
{
return false;
}
pid_t pid() const override
{
return 0;
}
qlonglong windowId() const override
{
return 0;
}
QUuid internalId() const override
{
return QUuid();
}
private:
qreal m_opacity = 1.0;
};
MockEffectWindow::MockEffectWindow(QObject *parent)
: EffectWindow(parent)
{
}
QVariant MockEffectWindow::data(int role) const
{
Q_UNUSED(role)
return QVariant();
}
QRect MockEffectWindow::decorationInnerRect() const
{
return QRect();
}
void MockEffectWindow::deleteProperty(long int atom) const
{
Q_UNUSED(atom)
}
void MockEffectWindow::refVisible(int reason)
{
Q_UNUSED(reason)
}
void MockEffectWindow::unrefVisible(int reason)
{
Q_UNUSED(reason)
}
void MockEffectWindow::addRepaint(const QRect &r)
{
Q_UNUSED(r)
}
void MockEffectWindow::addRepaint(int x, int y, int w, int h)
{
Q_UNUSED(x)
Q_UNUSED(y)
Q_UNUSED(w)
Q_UNUSED(h)
}
void MockEffectWindow::addRepaintFull()
{
}
void MockEffectWindow::addLayerRepaint(const QRect &r)
{
Q_UNUSED(r)
}
void MockEffectWindow::addLayerRepaint(int x, int y, int w, int h)
{
Q_UNUSED(x)
Q_UNUSED(y)
Q_UNUSED(w)
Q_UNUSED(h)
}
EffectWindow *MockEffectWindow::findModal()
{
return nullptr;
}
EffectWindow *MockEffectWindow::transientFor()
{
return nullptr;
}
const EffectWindowGroup *MockEffectWindow::group() const
{
return nullptr;
}
EffectWindowList MockEffectWindow::mainWindows() const
{
return EffectWindowList();
}
QByteArray MockEffectWindow::readProperty(long int atom, long int type, int format) const
{
Q_UNUSED(atom)
Q_UNUSED(type)
Q_UNUSED(format)
return QByteArray();
}
void MockEffectWindow::refWindow()
{
}
void MockEffectWindow::setData(int role, const QVariant &data)
{
Q_UNUSED(role)
Q_UNUSED(data)
}
void MockEffectWindow::minimize()
{
}
void MockEffectWindow::unminimize()
{
}
void MockEffectWindow::closeWindow()
{
}
void MockEffectWindow::unrefWindow()
{
}
class TestWindowPaintData : public QObject
{
Q_OBJECT
......@@ -474,9 +34,7 @@ private Q_SLOTS:
void TestWindowPaintData::testCtor()
{
MockEffectWindow w;
w.setOpacity(0.5);
WindowPaintData data(&w);
WindowPaintData data;
QCOMPARE(data.xScale(), 1.0);
QCOMPARE(data.yScale(), 1.0);
QCOMPARE(data.zScale(), 1.0);
......@@ -487,15 +45,14 @@ void TestWindowPaintData::testCtor()
QCOMPARE(data.rotationAngle(), 0.0);
QCOMPARE(data.rotationOrigin(), QVector3D());
QCOMPARE(data.rotationAxis(), QVector3D(0.0, 0.0, 1.0));
QCOMPARE(data.opacity(), 0.5);
QCOMPARE(data.opacity(), 1.0);
QCOMPARE(data.brightness(), 1.0);
QCOMPARE(data.saturation(), 1.0);
}
void TestWindowPaintData::testCopyCtor()
{
MockEffectWindow w;
WindowPaintData data(&w);
WindowPaintData data;
WindowPaintData data2(data);
// no value had been changed
QCOMPARE(data2.xScale(), 1.0);
......@@ -539,8 +96,7 @@ void TestWindowPaintData::testCopyCtor()
void TestWindowPaintData::testOperatorMultiplyAssign()
{
MockEffectWindow w;
WindowPaintData data(&w);
WindowPaintData data;
// without anything set, it's 1.0 on all axis
QCOMPARE(data.xScale(), 1.0);
QCOMPARE(data.yScale(), 1.0);
......@@ -564,8 +120,7 @@ void TestWindowPaintData::testOperatorMultiplyAssign()
void TestWindowPaintData::testOperatorPlus()
{
MockEffectWindow w;
WindowPaintData data(&w);
WindowPaintData data;
QCOMPARE(data.xTranslation(), 0.0);
QCOMPARE(data.yTranslation(), 0.0);
QCOMPARE(data.zTranslation(), 0.0);
......@@ -586,8 +141,7 @@ void TestWindowPaintData::testOperatorPlus()
void TestWindowPaintData::testMultiplyBrightness()
{
MockEffectWindow w;
WindowPaintData data(&w);
WindowPaintData data;
QCOMPARE(0.2, data.multiplyBrightness(0.2));
QCOMPARE(0.2, data.brightness());
QCOMPARE(0.6, data.multiplyBrightness(3.0));
......@@ -599,8 +153,7 @@ void TestWindowPaintData::testMultiplyBrightness()
void TestWindowPaintData::testMultiplyOpacity()
{
MockEffectWindow w;
WindowPaintData data(&w);
WindowPaintData data;
QCOMPARE(0.2, data.multiplyOpacity(0.2));
QCOMPARE(0.2, data.opacity());
QCOMPARE(0.6, data.multiplyOpacity(3.0));
......@@ -612,8 +165,7 @@ void TestWindowPaintData::testMultiplyOpacity()
void TestWindowPaintData::testMultiplySaturation()
{
MockEffectWindow w;
WindowPaintData data(&w);
WindowPaintData data;
QCOMPARE(0.2, data.multiplySaturation(0.2));
QCOMPARE(0.2, data.saturation());
QCOMPARE(0.6, data.multiplySaturation(3.0));
......
......@@ -222,7 +222,7 @@ void ScreenShotEffect::takeScreenShot(ScreenShotWindowData *screenshot)
{
EffectWindow *window = screenshot->window;
WindowPaintData d(window);
WindowPaintData d;
QRect geometry = window->expandedGeometry();
qreal devicePixelRatio = 1;
if (window->hasDecoration() && !(screenshot->flags & ScreenShotIncludeDecoration)) {
......
......@@ -57,7 +57,7 @@ void ThumbnailAsideEffect::paintScreen(int mask, const QRegion &region, ScreenPa
const QMatrix4x4 projectionMatrix = data.projectionMatrix();
for (const Data &d : qAsConst(windows)) {
if (painted.intersects(d.rect)) {
WindowPaintData data(d.window, projectionMatrix);
WindowPaintData data(projectionMatrix);
data.multiplyOpacity(opacity);
QRect region;
setPositionTransformations(data, region, d.window, d.rect, Qt::KeepAspectRatio);
......
......@@ -33,6 +33,19 @@ Item::~Item()
}
}
qreal Item::opacity() const
{
return m_opacity;
}
void Item::setOpacity(qreal opacity)
{
if (m_opacity != opacity) {
m_opacity = opacity;
scheduleRepaint(boundingRect());
}
}
int Item::z() const
{
return m_z;
......
......@@ -30,6 +30,9 @@ public:
explicit Item(Item *parent = nullptr);
~Item() override;
qreal opacity() const;
void setOpacity(qreal opacity);
QPoint position() const;
void setPosition(const QPoint &point);
......@@ -134,6 +137,7 @@ private:
QRect m_boundingRect;
QPoint m_position;
QSize m_size = QSize(0, 0);
qreal m_opacity = 1;
int m_z = 0;
bool m_explicitVisible = true;
bool m_effectiveVisible = true;
......
......@@ -114,7 +114,7 @@ GLTexture *DeformEffectPrivate::maybeRender(EffectWindow *window, DeformOffscree
QMatrix4x4 projectionMatrix;
projectionMatrix.ortho(QRect(0, 0, geometry.width(), geometry.height()));
WindowPaintData data(window);
WindowPaintData data;
data.setXTranslation(-geometry.x());
data.setYTranslation(-geometry.y());
data.setOpacity(1.0);
......
......@@ -219,18 +219,18 @@ public:
QMatrix4x4 screenProjectionMatrix;
};
WindowPaintData::WindowPaintData(EffectWindow *w)
: WindowPaintData(w, QMatrix4x4())
WindowPaintData::WindowPaintData()
: WindowPaintData(QMatrix4x4())
{
}
WindowPaintData::WindowPaintData(EffectWindow *w, const QMatrix4x4 &screenProjectionMatrix)
WindowPaintData::WindowPaintData(const QMatrix4x4 &screenProjectionMatrix)
: PaintData()
, shader(nullptr)
, d(new WindowPaintDataPrivate())
{
d->screenProjectionMatrix = screenProjectionMatrix;
setOpacity(w->opacity());
setOpacity(1.0);
setSaturation(1.0);
setBrightness(1.0);
setScreen(0);
......
......@@ -3109,8 +3109,8 @@ private:
class KWINEFFECTS_EXPORT WindowPaintData : public PaintData