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.
This commit is contained in:
parent
99f01ee9c5
commit
63a866d98c
17 changed files with 79 additions and 521 deletions
|
@ -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 ®ion, 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);
|
||||
|
|
13
src/item.cpp
13
src/item.cpp
|
@ -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
|
||||
{
|
||||
public:
|
||||
explicit WindowPaintData(EffectWindow *w);
|
||||
explicit WindowPaintData(EffectWindow *w, const QMatrix4x4 &screenProjectionMatrix);
|
||||
WindowPaintData();
|
||||
explicit WindowPaintData(const QMatrix4x4 &screenProjectionMatrix);
|
||||
WindowPaintData(const WindowPaintData &other);
|
||||
~WindowPaintData() override;
|
||||
/**
|
||||
|
|
|
@ -55,7 +55,7 @@ void WindowScreenCastSource::render(GLFramebuffer *target)
|
|||
projectionMatrix.ortho(geometry.x(), geometry.x() + geometry.width(),
|
||||
geometry.y(), geometry.y() + geometry.height(), -1, 1);
|
||||
|
||||
WindowPaintData data(m_window->effectWindow());
|
||||
WindowPaintData data;
|
||||
data.setProjectionMatrix(projectionMatrix);
|
||||
|
||||
GLFramebuffer::pushFramebuffer(target);
|
||||
|
|
|
@ -586,9 +586,8 @@ void Scene::paintWindow(WindowItem *item, int mask, const QRegion ®ion)
|
|||
return;
|
||||
}
|
||||
|
||||
EffectWindowImpl *effectWindow = item->window()->effectWindow();
|
||||
WindowPaintData data(effectWindow, screenProjectionMatrix());
|
||||
effects->paintWindow(effectWindow, mask, region, data);
|
||||
WindowPaintData data(screenProjectionMatrix());
|
||||
effects->paintWindow(item->window()->effectWindow(), mask, region, data);
|
||||
}
|
||||
|
||||
// the function that'll be eventually called by paintWindow() above
|
||||
|
|
|
@ -374,6 +374,8 @@ void SceneOpenGL::createRenderNode(Item *item, RenderContext *context)
|
|||
matrix *= item->transform();
|
||||
context->transforms.push(context->transforms.top() * matrix);
|
||||
|
||||
context->opacityStack.push(context->opacityStack.top() * item->opacity());
|
||||
|
||||
for (Item *childItem : sortedChildItems) {
|
||||
if (childItem->z() >= 0) {
|
||||
break;
|
||||
|
@ -392,7 +394,7 @@ void SceneOpenGL::createRenderNode(Item *item, RenderContext *context)
|
|||
.texture = shadow->shadowTexture(),
|
||||
.quads = quads,
|
||||
.transformMatrix = context->transforms.top(),
|
||||
.opacity = context->paintData.opacity(),
|
||||
.opacity = context->opacityStack.top(),
|
||||
.hasAlpha = true,
|
||||
.coordinateType = UnnormalizedCoordinates,
|
||||
});
|
||||
|
@ -405,7 +407,7 @@ void SceneOpenGL::createRenderNode(Item *item, RenderContext *context)
|
|||
.texture = renderer->texture(),
|
||||
.quads = quads,
|
||||
.transformMatrix = context->transforms.top(),
|
||||
.opacity = context->paintData.opacity(),
|
||||
.opacity = context->opacityStack.top(),
|
||||
.hasAlpha = true,
|
||||
.coordinateType = UnnormalizedCoordinates,
|
||||
});
|
||||
|
@ -421,7 +423,7 @@ void SceneOpenGL::createRenderNode(Item *item, RenderContext *context)
|
|||
.texture = bindSurfaceTexture(surfaceItem),
|
||||
.quads = quads,
|
||||
.transformMatrix = context->transforms.top(),
|
||||
.opacity = context->paintData.opacity(),
|
||||
.opacity = context->opacityStack.top(),
|
||||
.hasAlpha = hasAlpha,
|
||||
.coordinateType = UnnormalizedCoordinates,
|
||||
});
|
||||
|
@ -439,6 +441,7 @@ void SceneOpenGL::createRenderNode(Item *item, RenderContext *context)
|
|||
}
|
||||
|
||||
context->transforms.pop();
|
||||
context->opacityStack.pop();
|
||||
}
|
||||
|
||||
QMatrix4x4 SceneOpenGL::modelViewProjectionMatrix(int mask, const WindowPaintData &data) const
|
||||
|
@ -500,11 +503,11 @@ void SceneOpenGL::render(Item *item, int mask, const QRegion ®ion, const Wind
|
|||
|
||||
RenderContext renderContext{
|
||||
.clip = region,
|
||||
.paintData = data,
|
||||
.hardwareClipping = region != infiniteRegion() && ((mask & Scene::PAINT_WINDOW_TRANSFORMED) || (mask & Scene::PAINT_SCREEN_TRANSFORMED)),
|
||||
};
|
||||
|
||||
renderContext.transforms.push(QMatrix4x4());
|
||||
renderContext.opacityStack.push(data.opacity());
|
||||
|
||||
item->setTransform(transformForPaintData(mask, data));
|
||||
|
||||
|
@ -518,29 +521,18 @@ void SceneOpenGL::render(Item *item, int mask, const QRegion ®ion, const Wind
|
|||
return;
|
||||
}
|
||||
|
||||
GLShader *shader = data.shader;
|
||||
if (!shader) {
|
||||
ShaderTraits traits = ShaderTrait::MapTexture;
|
||||
|
||||
if (data.opacity() != 1.0 || data.brightness() != 1.0 || data.crossFadeProgress() != 1.0) {
|
||||
traits |= ShaderTrait::Modulate;
|
||||
}
|
||||
|
||||
if (data.saturation() != 1.0) {
|
||||
traits |= ShaderTrait::AdjustSaturation;
|
||||
}
|
||||
|
||||
shader = ShaderManager::instance()->pushShader(traits);
|
||||
}
|
||||
shader->setUniform(GLShader::Saturation, data.saturation());
|
||||
|
||||
const bool indexedQuads = GLVertexBuffer::supportsIndexedQuads();
|
||||
const GLenum primitiveType = indexedQuads ? GL_QUADS : GL_TRIANGLES;
|
||||
const int verticesPerQuad = indexedQuads ? 4 : 6;
|
||||
const size_t size = verticesPerQuad * quadCount * sizeof(GLVertex2D);
|
||||
|
||||
if (renderContext.hardwareClipping) {
|
||||
glEnable(GL_SCISSOR_TEST);
|
||||
ShaderTraits shaderTraits = ShaderTrait::MapTexture;
|
||||
|
||||
if (data.brightness() != 1.0 || data.crossFadeProgress() != 1.0) {
|
||||
shaderTraits |= ShaderTrait::Modulate;
|
||||
}
|
||||
if (data.saturation() != 1.0) {
|
||||
shaderTraits |= ShaderTrait::AdjustSaturation;
|
||||
}
|
||||
|
||||
const GLVertexAttrib attribs[] = {
|
||||
|
@ -560,6 +552,10 @@ void SceneOpenGL::render(Item *item, int mask, const QRegion ®ion, const Wind
|
|||
continue;
|
||||
}
|
||||
|
||||
if (renderNode.opacity != 1.0) {
|
||||
shaderTraits |= ShaderTrait::Modulate;
|
||||
}
|
||||
|
||||
renderNode.firstVertex = v;
|
||||
renderNode.vertexCount = renderNode.quads.count() * verticesPerQuad;
|
||||
|
||||
|
@ -572,6 +568,16 @@ void SceneOpenGL::render(Item *item, int mask, const QRegion ®ion, const Wind
|
|||
vbo->unmap();
|
||||
vbo->bindArrays();
|
||||
|
||||
GLShader *shader = data.shader;
|
||||
if (!shader) {
|
||||
shader = ShaderManager::instance()->pushShader(shaderTraits);
|
||||
}
|
||||
shader->setUniform(GLShader::Saturation, data.saturation());
|
||||
|
||||
if (renderContext.hardwareClipping) {
|
||||
glEnable(GL_SCISSOR_TEST);
|
||||
}
|
||||
|
||||
// Make sure the blend function is set up correctly in case we will be doing blending
|
||||
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
|
|
|
@ -44,8 +44,8 @@ public:
|
|||
{
|
||||
QVector<RenderNode> renderNodes;
|
||||
QStack<QMatrix4x4> transforms;
|
||||
QStack<qreal> opacityStack;
|
||||
const QRegion clip;
|
||||
const WindowPaintData &paintData;
|
||||
const bool hardwareClipping;
|
||||
};
|
||||
|
||||
|
|
|
@ -120,38 +120,15 @@ void SceneQPainter::render(Item *item, int mask, const QRegion &_region, const W
|
|||
painter->save();
|
||||
painter->setClipRegion(region);
|
||||
painter->setClipping(true);
|
||||
painter->setOpacity(data.opacity());
|
||||
|
||||
if (mask & Scene::PAINT_WINDOW_TRANSFORMED) {
|
||||
painter->translate(data.xTranslation(), data.yTranslation());
|
||||
painter->scale(data.xScale(), data.yScale());
|
||||
}
|
||||
|
||||
const bool opaque = qFuzzyCompare(1.0, data.opacity());
|
||||
QImage tempImage;
|
||||
QPainter tempPainter;
|
||||
if (!opaque) {
|
||||
// need a temp render target which we later on blit to the screen
|
||||
tempImage = QImage(boundingRect.size(), QImage::Format_ARGB32_Premultiplied);
|
||||
tempImage.fill(Qt::transparent);
|
||||
tempPainter.begin(&tempImage);
|
||||
tempPainter.save();
|
||||
tempPainter.translate(-boundingRect.topLeft());
|
||||
painter = &tempPainter;
|
||||
}
|
||||
|
||||
renderItem(painter, item);
|
||||
|
||||
if (!opaque) {
|
||||
tempPainter.restore();
|
||||
tempPainter.setCompositionMode(QPainter::CompositionMode_DestinationIn);
|
||||
QColor translucent(Qt::transparent);
|
||||
translucent.setAlphaF(data.opacity());
|
||||
tempPainter.fillRect(QRect(QPoint(0, 0), boundingRect.size()), translucent);
|
||||
tempPainter.end();
|
||||
painter = scenePainter();
|
||||
painter->drawImage(boundingRect.topLeft(), tempImage);
|
||||
}
|
||||
|
||||
painter->restore();
|
||||
}
|
||||
|
||||
|
@ -161,6 +138,7 @@ void SceneQPainter::renderItem(QPainter *painter, Item *item) const
|
|||
|
||||
painter->save();
|
||||
painter->translate(item->position());
|
||||
painter->setOpacity(painter->opacity() * item->opacity());
|
||||
|
||||
for (Item *childItem : sortedChildItems) {
|
||||
if (childItem->z() >= 0) {
|
||||
|
|
|
@ -432,7 +432,7 @@ void WindowThumbnailItem::updateOffscreenTexture()
|
|||
projectionMatrix.ortho(geometry.x(), geometry.x() + geometry.width(),
|
||||
geometry.y(), geometry.y() + geometry.height(), -1, 1);
|
||||
|
||||
WindowPaintData data(m_client->effectWindow());
|
||||
WindowPaintData data;
|
||||
data.setProjectionMatrix(projectionMatrix);
|
||||
|
||||
// The thumbnail must be rendered using kwin's opengl context as VAOs are not
|
||||
|
|
|
@ -331,10 +331,7 @@ void Window::setOpacity(qreal opacity)
|
|||
}
|
||||
const qreal oldOpacity = m_opacity;
|
||||
m_opacity = opacity;
|
||||
if (Compositor::compositing()) {
|
||||
addRepaintFull();
|
||||
Q_EMIT opacityChanged(this, oldOpacity);
|
||||
}
|
||||
}
|
||||
|
||||
bool Window::setupCompositing()
|
||||
|
|
|
@ -43,6 +43,9 @@ WindowItem::WindowItem(Window *window, Item *parent)
|
|||
connect(workspace(), &Workspace::currentDesktopChanged, this, &WindowItem::updateVisibility);
|
||||
updateVisibility();
|
||||
|
||||
connect(window, &Window::opacityChanged, this, &WindowItem::updateOpacity);
|
||||
updateOpacity();
|
||||
|
||||
connect(window, &Window::windowClosed, this, &WindowItem::handleWindowClosed);
|
||||
}
|
||||
|
||||
|
@ -229,6 +232,11 @@ void WindowItem::updateDecorationItem()
|
|||
}
|
||||
}
|
||||
|
||||
void WindowItem::updateOpacity()
|
||||
{
|
||||
setOpacity(m_window->opacity());
|
||||
}
|
||||
|
||||
WindowItemX11::WindowItemX11(Window *window, Item *parent)
|
||||
: WindowItem(window, parent)
|
||||
{
|
||||
|
|
|
@ -63,6 +63,7 @@ private Q_SLOTS:
|
|||
void updateSurfacePosition();
|
||||
void updateSurfaceVisibility();
|
||||
void updatePosition();
|
||||
void updateOpacity();
|
||||
|
||||
private:
|
||||
bool computeVisibility() const;
|
||||
|
|
Loading…
Reference in a new issue