Changeset View
Changeset View
Standalone View
Standalone View
scene_opengl.cpp
Show First 20 Lines • Show All 43 Lines • ▼ Show 20 Line(s) | |||||
44 | #include "deleted.h" | 44 | #include "deleted.h" | ||
45 | #include "effects.h" | 45 | #include "effects.h" | ||
46 | #include "lanczosfilter.h" | 46 | #include "lanczosfilter.h" | ||
47 | #include "main.h" | 47 | #include "main.h" | ||
48 | #include "overlaywindow.h" | 48 | #include "overlaywindow.h" | ||
49 | #include "screens.h" | 49 | #include "screens.h" | ||
50 | #include "decorations/decoratedclient.h" | 50 | #include "decorations/decoratedclient.h" | ||
51 | 51 | | |||
52 | #include <KWayland/Server/subcompositor_interface.h> | ||||
53 | #include <KWayland/Server/surface_interface.h> | ||||
54 | | ||||
52 | #include <array> | 55 | #include <array> | ||
53 | #include <cmath> | 56 | #include <cmath> | ||
54 | #include <unistd.h> | 57 | #include <unistd.h> | ||
55 | #include <stddef.h> | 58 | #include <stddef.h> | ||
56 | 59 | | |||
57 | #include <qpainter.h> | 60 | #include <qpainter.h> | ||
58 | #include <QDBusConnection> | 61 | #include <QDBusConnection> | ||
59 | #include <QDBusConnectionInterface> | 62 | #include <QDBusConnectionInterface> | ||
▲ Show 20 Lines • Show All 1440 Lines • ▼ Show 20 Line(s) | 1488 | { | |||
1500 | // with the default projection matrix. If the effect hasn't specified a | 1503 | // with the default projection matrix. If the effect hasn't specified a | ||
1501 | // model-view matrix, mvMatrix will be the identity matrix. | 1504 | // model-view matrix, mvMatrix will be the identity matrix. | ||
1502 | if (mask & Scene::PAINT_SCREEN_TRANSFORMED) | 1505 | if (mask & Scene::PAINT_SCREEN_TRANSFORMED) | ||
1503 | return scene->screenProjectionMatrix() * mvMatrix; | 1506 | return scene->screenProjectionMatrix() * mvMatrix; | ||
1504 | 1507 | | |||
1505 | return scene->projectionMatrix() * mvMatrix; | 1508 | return scene->projectionMatrix() * mvMatrix; | ||
1506 | } | 1509 | } | ||
1507 | 1510 | | |||
1511 | static void renderSubSurface(GLShader *shader, const QMatrix4x4 &mvp, const QMatrix4x4 &windowMatrix, OpenGLWindowPixmap *pixmap) | ||||
1512 | { | ||||
1513 | QMatrix4x4 newWindowMatrix = windowMatrix; | ||||
1514 | newWindowMatrix.translate(pixmap->subSurface()->position().x(), pixmap->subSurface()->position().y()); | ||||
1515 | | ||||
1516 | if (!pixmap->texture()->isNull()) { | ||||
1517 | // render this texture | ||||
1518 | shader->setUniform(GLShader::ModelViewProjectionMatrix, mvp * newWindowMatrix); | ||||
1519 | auto texture = pixmap->texture(); | ||||
1520 | texture->bind(); | ||||
1521 | texture->render(QRegion(), QRect(0, 0, texture->width(), texture->height())); | ||||
1522 | texture->unbind(); | ||||
1523 | } | ||||
1524 | | ||||
1525 | const auto &children = pixmap->children(); | ||||
1526 | for (auto pixmap : children) { | ||||
1527 | if (pixmap->subSurface().isNull() || pixmap->subSurface()->surface().isNull() || !pixmap->subSurface()->surface()->isMapped()) { | ||||
1528 | continue; | ||||
1529 | } | ||||
1530 | renderSubSurface(shader, mvp, newWindowMatrix, static_cast<OpenGLWindowPixmap*>(pixmap)); | ||||
1531 | } | ||||
1532 | } | ||||
1533 | | ||||
1508 | void SceneOpenGL2Window::performPaint(int mask, QRegion region, WindowPaintData data) | 1534 | void SceneOpenGL2Window::performPaint(int mask, QRegion region, WindowPaintData data) | ||
1509 | { | 1535 | { | ||
1510 | if (!beginRenderWindow(mask, region, data)) | 1536 | if (!beginRenderWindow(mask, region, data)) | ||
1511 | return; | 1537 | return; | ||
1512 | 1538 | | |||
1513 | SceneOpenGL2 *scene = static_cast<SceneOpenGL2 *>(m_scene); | 1539 | SceneOpenGL2 *scene = static_cast<SceneOpenGL2 *>(m_scene); | ||
1514 | 1540 | | |||
1515 | const QMatrix4x4 windowMatrix = transformation(mask, data); | 1541 | QMatrix4x4 windowMatrix = transformation(mask, data); | ||
1516 | const QMatrix4x4 mvpMatrix = modelViewProjectionMatrix(mask, data) * windowMatrix; | 1542 | const QMatrix4x4 modelViewProjection = modelViewProjectionMatrix(mask, data); | ||
1543 | const QMatrix4x4 mvpMatrix = modelViewProjection * windowMatrix; | ||||
1517 | 1544 | | |||
1518 | GLShader *shader = data.shader; | 1545 | GLShader *shader = data.shader; | ||
1519 | if (!shader) { | 1546 | if (!shader) { | ||
1520 | ShaderTraits traits = ShaderTrait::MapTexture; | 1547 | ShaderTraits traits = ShaderTrait::MapTexture; | ||
1521 | 1548 | | |||
1522 | if (data.opacity() != 1.0 || data.brightness() != 1.0 || data.crossFadeProgress() != 1.0) | 1549 | if (data.opacity() != 1.0 || data.brightness() != 1.0 || data.crossFadeProgress() != 1.0) | ||
1523 | traits |= ShaderTrait::Modulate; | 1550 | traits |= ShaderTrait::Modulate; | ||
1524 | 1551 | | |||
▲ Show 20 Lines • Show All 111 Lines • ▼ Show 20 Line(s) | 1648 | for (int i = 0; i < LeafCount; i++) { | |||
1636 | 1663 | | |||
1637 | vbo->draw(region, primitiveType, nodes[i].firstVertex, nodes[i].vertexCount, m_hardwareClipping); | 1664 | vbo->draw(region, primitiveType, nodes[i].firstVertex, nodes[i].vertexCount, m_hardwareClipping); | ||
1638 | } | 1665 | } | ||
1639 | 1666 | | |||
1640 | vbo->unbindArrays(); | 1667 | vbo->unbindArrays(); | ||
1641 | 1668 | | |||
1642 | setBlendEnabled(false); | 1669 | setBlendEnabled(false); | ||
1643 | 1670 | | |||
1671 | // render sub-surfaces | ||||
1672 | const auto &children = windowPixmap<OpenGLWindowPixmap>()->children(); | ||||
1673 | windowMatrix.translate(toplevel->clientPos().x(), toplevel->clientPos().y()); | ||||
1674 | for (auto pixmap : children) { | ||||
1675 | if (pixmap->subSurface().isNull() || pixmap->subSurface()->surface().isNull() || !pixmap->subSurface()->surface()->isMapped()) { | ||||
1676 | continue; | ||||
1677 | } | ||||
1678 | renderSubSurface(shader, modelViewProjection, windowMatrix, static_cast<OpenGLWindowPixmap*>(pixmap)); | ||||
1679 | } | ||||
1680 | | ||||
1644 | if (!data.shader) | 1681 | if (!data.shader) | ||
1645 | ShaderManager::instance()->popShader(); | 1682 | ShaderManager::instance()->popShader(); | ||
1646 | 1683 | | |||
1647 | endRenderWindow(); | 1684 | endRenderWindow(); | ||
1648 | } | 1685 | } | ||
1649 | 1686 | | |||
1650 | 1687 | | |||
1651 | //**************************************** | 1688 | //**************************************** | ||
1652 | // OpenGLWindowPixmap | 1689 | // OpenGLWindowPixmap | ||
1653 | //**************************************** | 1690 | //**************************************** | ||
1654 | 1691 | | |||
1655 | OpenGLWindowPixmap::OpenGLWindowPixmap(Scene::Window *window, SceneOpenGL* scene) | 1692 | OpenGLWindowPixmap::OpenGLWindowPixmap(Scene::Window *window, SceneOpenGL* scene) | ||
1656 | : WindowPixmap(window) | 1693 | : WindowPixmap(window) | ||
1657 | , m_texture(scene->createTexture()) | 1694 | , m_texture(scene->createTexture()) | ||
1695 | , m_scene(scene) | ||||
1696 | { | ||||
1697 | } | ||||
1698 | | ||||
1699 | OpenGLWindowPixmap::OpenGLWindowPixmap(const QPointer<KWayland::Server::SubSurfaceInterface> &subSurface, WindowPixmap *parent, SceneOpenGL *scene) | ||||
1700 | : WindowPixmap(subSurface, parent) | ||||
1701 | , m_texture(scene->createTexture()) | ||||
1702 | , m_scene(scene) | ||||
1658 | { | 1703 | { | ||
1659 | } | 1704 | } | ||
1660 | 1705 | | |||
1661 | OpenGLWindowPixmap::~OpenGLWindowPixmap() | 1706 | OpenGLWindowPixmap::~OpenGLWindowPixmap() | ||
1662 | { | 1707 | { | ||
1663 | } | 1708 | } | ||
1664 | 1709 | | |||
1665 | bool OpenGLWindowPixmap::bind() | 1710 | bool OpenGLWindowPixmap::bind() | ||
1666 | { | 1711 | { | ||
1667 | if (!m_texture->isNull()) { | 1712 | if (!m_texture->isNull()) { | ||
1668 | if (!toplevel()->damage().isEmpty()) { | 1713 | // always call updateBuffer to get the sub-surface tree updated | ||
1714 | if (subSurface().isNull() && !toplevel()->damage().isEmpty()) { | ||||
1669 | updateBuffer(); | 1715 | updateBuffer(); | ||
1716 | } | ||||
1717 | auto s = surface(); | ||||
1718 | if (s && !s->trackedDamage().isEmpty()) { | ||||
1670 | m_texture->updateFromPixmap(this); | 1719 | m_texture->updateFromPixmap(this); | ||
1671 | // mipmaps need to be updated | 1720 | // mipmaps need to be updated | ||
1672 | m_texture->setDirty(); | 1721 | m_texture->setDirty(); | ||
1722 | } | ||||
1723 | if (subSurface().isNull()) { | ||||
1673 | toplevel()->resetDamage(); | 1724 | toplevel()->resetDamage(); | ||
1674 | } | 1725 | } | ||
1726 | // also bind all children | ||||
1727 | for (auto it = children().constBegin(); it != children().constEnd(); ++it) { | ||||
1728 | static_cast<OpenGLWindowPixmap*>(*it)->bind(); | ||||
1729 | } | ||||
1675 | return true; | 1730 | return true; | ||
1676 | } | 1731 | } | ||
1732 | // also bind all children, needs to be done before checking isValid | ||||
1733 | // as there might be valid children to render, see https://bugreports.qt.io/browse/QTBUG-52192 | ||||
1734 | if (subSurface().isNull()) { | ||||
1735 | updateBuffer(); | ||||
1736 | } | ||||
1737 | for (auto it = children().constBegin(); it != children().constEnd(); ++it) { | ||||
1738 | static_cast<OpenGLWindowPixmap*>(*it)->bind(); | ||||
1739 | } | ||||
1677 | if (!isValid()) { | 1740 | if (!isValid()) { | ||
1678 | return false; | 1741 | return false; | ||
1679 | } | 1742 | } | ||
1680 | 1743 | | |||
1681 | bool success = m_texture->load(this); | 1744 | bool success = m_texture->load(this); | ||
1682 | 1745 | | |||
1683 | if (success) | 1746 | if (success) { | ||
1747 | if (subSurface().isNull()) { | ||||
1684 | toplevel()->resetDamage(); | 1748 | toplevel()->resetDamage(); | ||
1685 | else | 1749 | } | ||
1750 | } else | ||||
1686 | qCDebug(KWIN_CORE) << "Failed to bind window"; | 1751 | qCDebug(KWIN_CORE) << "Failed to bind window"; | ||
1687 | return success; | 1752 | return success; | ||
1688 | } | 1753 | } | ||
1689 | 1754 | | |||
1755 | WindowPixmap *OpenGLWindowPixmap::createChild(const QPointer<KWayland::Server::SubSurfaceInterface> &subSurface) | ||||
1756 | { | ||||
1757 | return new OpenGLWindowPixmap(subSurface, this, m_scene); | ||||
1758 | } | ||||
1759 | | ||||
1690 | //**************************************** | 1760 | //**************************************** | ||
1691 | // SceneOpenGL::EffectFrame | 1761 | // SceneOpenGL::EffectFrame | ||
1692 | //**************************************** | 1762 | //**************************************** | ||
1693 | 1763 | | |||
1694 | GLTexture* SceneOpenGL::EffectFrame::m_unstyledTexture = NULL; | 1764 | GLTexture* SceneOpenGL::EffectFrame::m_unstyledTexture = NULL; | ||
1695 | QPixmap* SceneOpenGL::EffectFrame::m_unstyledPixmap = NULL; | 1765 | QPixmap* SceneOpenGL::EffectFrame::m_unstyledPixmap = NULL; | ||
1696 | 1766 | | |||
1697 | SceneOpenGL::EffectFrame::EffectFrame(EffectFrameImpl* frame, SceneOpenGL *scene) | 1767 | SceneOpenGL::EffectFrame::EffectFrame(EffectFrameImpl* frame, SceneOpenGL *scene) | ||
▲ Show 20 Lines • Show All 816 Lines • Show Last 20 Lines |