Changeset View
Changeset View
Standalone View
Standalone View
plugins/platforms/drm/drm_output.cpp
Show All 30 Lines | |||||
31 | #include "main.h" | 31 | #include "main.h" | ||
32 | #include "orientation_sensor.h" | 32 | #include "orientation_sensor.h" | ||
33 | #include "screens_drm.h" | 33 | #include "screens_drm.h" | ||
34 | #include "wayland_server.h" | 34 | #include "wayland_server.h" | ||
35 | // KWayland | 35 | // KWayland | ||
36 | #include <KWayland/Server/display.h> | 36 | #include <KWayland/Server/display.h> | ||
37 | #include <KWayland/Server/output_interface.h> | 37 | #include <KWayland/Server/output_interface.h> | ||
38 | #include <KWayland/Server/outputchangeset.h> | 38 | #include <KWayland/Server/outputchangeset.h> | ||
39 | #include <KWayland/Server/outputdevice_interface.h> | | |||
40 | #include <KWayland/Server/outputmanagement_interface.h> | 39 | #include <KWayland/Server/outputmanagement_interface.h> | ||
41 | #include <KWayland/Server/outputconfiguration_interface.h> | 40 | #include <KWayland/Server/outputconfiguration_interface.h> | ||
42 | // KF5 | 41 | // KF5 | ||
43 | #include <KConfigGroup> | 42 | #include <KConfigGroup> | ||
44 | #include <KLocalizedString> | 43 | #include <KLocalizedString> | ||
45 | #include <KSharedConfig> | 44 | #include <KSharedConfig> | ||
46 | // Qt | 45 | // Qt | ||
47 | #include <QMatrix4x4> | 46 | #include <QMatrix4x4> | ||
48 | #include <QCryptographicHash> | 47 | #include <QCryptographicHash> | ||
49 | #include <QPainter> | 48 | #include <QPainter> | ||
50 | // drm | 49 | // drm | ||
51 | #include <xf86drm.h> | 50 | #include <xf86drm.h> | ||
52 | #include <xf86drmMode.h> | 51 | #include <xf86drmMode.h> | ||
53 | #include <libdrm/drm_mode.h> | 52 | #include <libdrm/drm_mode.h> | ||
54 | 53 | | |||
55 | 54 | | |||
56 | namespace KWin | 55 | namespace KWin | ||
57 | { | 56 | { | ||
58 | 57 | | |||
59 | DrmOutput::DrmOutput(DrmBackend *backend) | 58 | DrmOutput::DrmOutput(DrmBackend *backend) | ||
60 | : QObject() | 59 | : Output() | ||
61 | , m_backend(backend) | 60 | , m_backend(backend) | ||
62 | { | 61 | { | ||
63 | } | 62 | } | ||
64 | 63 | | |||
65 | DrmOutput::~DrmOutput() | 64 | DrmOutput::~DrmOutput() | ||
66 | { | 65 | { | ||
67 | hideCursor(); | 66 | hideCursor(); | ||
68 | m_crtc->blank(); | 67 | m_crtc->blank(); | ||
69 | 68 | | |||
70 | if (m_primaryPlane) { | 69 | if (m_primaryPlane) { | ||
71 | // TODO: when having multiple planes, also clean up these | 70 | // TODO: when having multiple planes, also clean up these | ||
72 | m_primaryPlane->setOutput(nullptr); | 71 | m_primaryPlane->setOutput(nullptr); | ||
73 | 72 | | |||
74 | if (m_backend->deleteBufferAfterPageFlip()) { | 73 | if (m_backend->deleteBufferAfterPageFlip()) { | ||
75 | delete m_primaryPlane->current(); | 74 | delete m_primaryPlane->current(); | ||
76 | } | 75 | } | ||
77 | m_primaryPlane->setCurrent(nullptr); | 76 | m_primaryPlane->setCurrent(nullptr); | ||
78 | } | 77 | } | ||
79 | 78 | | |||
80 | m_crtc->setOutput(nullptr); | 79 | m_crtc->setOutput(nullptr); | ||
81 | m_conn->setOutput(nullptr); | 80 | m_conn->setOutput(nullptr); | ||
82 | 81 | | |||
83 | delete m_waylandOutput.data(); | 82 | delete m_waylandOutput.data(); | ||
84 | delete m_waylandOutputDevice.data(); | 83 | delete m_waylandOutputDevice.data(); | ||
zzag: Is it safe? Shouldn't you test the pointer for validity?
Also, it looks like DrmOutput deletes… | |||||
You can delete a nullptr. But in general yes, the waylandOutput() and waylandOutputDevice() data fields should be deleted on Output level. I just wanted to keep the logical changes minimal and delete them at the same position as before. But yea, accepting this logical change in this case probably makes more sense. romangg: You can delete a nullptr.
But in general yes, the waylandOutput() and waylandOutputDevice()… | |||||
85 | delete m_cursor[0]; | 84 | delete m_cursor[0]; | ||
86 | delete m_cursor[1]; | 85 | delete m_cursor[1]; | ||
87 | } | 86 | } | ||
88 | 87 | | |||
89 | void DrmOutput::releaseGbm() | 88 | void DrmOutput::releaseGbm() | ||
90 | { | 89 | { | ||
91 | if (DrmBuffer *b = m_crtc->current()) { | 90 | if (DrmBuffer *b = m_crtc->current()) { | ||
92 | b->releaseGbm(); | 91 | b->releaseGbm(); | ||
▲ Show 20 Lines • Show All 67 Lines • ▼ Show 20 Line(s) | |||||
160 | QSize DrmOutput::pixelSize() const | 159 | QSize DrmOutput::pixelSize() const | ||
161 | { | 160 | { | ||
162 | if (m_orientation == Qt::PortraitOrientation || m_orientation == Qt::InvertedPortraitOrientation) { | 161 | if (m_orientation == Qt::PortraitOrientation || m_orientation == Qt::InvertedPortraitOrientation) { | ||
163 | return QSize(m_mode.vdisplay, m_mode.hdisplay); | 162 | return QSize(m_mode.vdisplay, m_mode.hdisplay); | ||
164 | } | 163 | } | ||
165 | return QSize(m_mode.hdisplay, m_mode.vdisplay); | 164 | return QSize(m_mode.hdisplay, m_mode.vdisplay); | ||
166 | } | 165 | } | ||
167 | 166 | | |||
168 | QSize DrmOutput::physicalSize() const | | |||
169 | { | | |||
170 | if (m_orientation == Qt::PortraitOrientation || m_orientation == Qt::InvertedPortraitOrientation) { | | |||
171 | return QSize(m_physicalSize.height(), m_physicalSize.width()); | | |||
172 | } | | |||
173 | return m_physicalSize; | | |||
174 | } | | |||
175 | | ||||
176 | QRect DrmOutput::geometry() const | | |||
177 | { | | |||
178 | return QRect(m_globalPos, pixelSize() / scale()); | | |||
179 | } | | |||
180 | | ||||
181 | qreal DrmOutput::scale() const | | |||
182 | { | | |||
183 | return m_scale; | | |||
184 | } | | |||
185 | | ||||
186 | void DrmOutput::setEnabled(bool enabled) | 167 | void DrmOutput::setEnabled(bool enabled) | ||
187 | { | 168 | { | ||
188 | if (enabled == isEnabled()) { | 169 | if (enabled == isEnabled()) { | ||
189 | return; | 170 | return; | ||
190 | } | 171 | } | ||
191 | if (enabled) { | 172 | if (enabled) { | ||
192 | setDpms(DpmsMode::On); | 173 | setDpms(DpmsMode::On); | ||
193 | initOutput(); | 174 | initOutput(); | ||
194 | } else { | 175 | } else { | ||
195 | setDpms(DpmsMode::Off); | 176 | setDpms(DpmsMode::Off); | ||
196 | delete m_waylandOutput.data(); | 177 | delete m_waylandOutput.data(); | ||
197 | } | 178 | } | ||
198 | m_waylandOutputDevice->setEnabled(enabled ? | 179 | m_waylandOutputDevice->setEnabled(enabled ? | ||
199 | KWayland::Server::OutputDeviceInterface::Enablement::Enabled : KWayland::Server::OutputDeviceInterface::Enablement::Disabled); | 180 | KWayland::Server::OutputDeviceInterface::Enablement::Enabled : KWayland::Server::OutputDeviceInterface::Enablement::Disabled); | ||
200 | } | 181 | } | ||
201 | 182 | | |||
202 | bool DrmOutput::isEnabled() const | | |||
203 | { | | |||
204 | return !m_waylandOutput.isNull(); | | |||
205 | } | | |||
206 | | ||||
207 | static KWayland::Server::OutputInterface::DpmsMode toWaylandDpmsMode(DrmOutput::DpmsMode mode) | 183 | static KWayland::Server::OutputInterface::DpmsMode toWaylandDpmsMode(DrmOutput::DpmsMode mode) | ||
208 | { | 184 | { | ||
209 | using namespace KWayland::Server; | 185 | using namespace KWayland::Server; | ||
210 | switch (mode) { | 186 | switch (mode) { | ||
211 | case DrmOutput::DpmsMode::On: | 187 | case DrmOutput::DpmsMode::On: | ||
212 | return OutputInterface::DpmsMode::On; | 188 | return OutputInterface::DpmsMode::On; | ||
213 | case DrmOutput::DpmsMode::Standby: | 189 | case DrmOutput::DpmsMode::Standby: | ||
214 | return OutputInterface::DpmsMode::Standby; | 190 | return OutputInterface::DpmsMode::Standby; | ||
▲ Show 20 Lines • Show All 534 Lines • ▼ Show 20 Line(s) | 722 | { | |||
749 | if (m_waylandOutput) { | 725 | if (m_waylandOutput) { | ||
750 | m_waylandOutput->setDpmsMode(toWaylandDpmsMode(m_dpmsModePending)); | 726 | m_waylandOutput->setDpmsMode(toWaylandDpmsMode(m_dpmsModePending)); | ||
751 | } | 727 | } | ||
752 | emit dpmsChanged(); | 728 | emit dpmsChanged(); | ||
753 | 729 | | |||
754 | m_backend->outputWentOff(); | 730 | m_backend->outputWentOff(); | ||
755 | } | 731 | } | ||
756 | 732 | | |||
757 | QString DrmOutput::name() const | | |||
758 | { | | |||
759 | if (!m_waylandOutput) { | | |||
760 | return i18n("unknown"); | | |||
761 | } | | |||
762 | return QStringLiteral("%1 %2").arg(m_waylandOutput->manufacturer()).arg(m_waylandOutput->model()); | | |||
763 | } | | |||
764 | | ||||
765 | int DrmOutput::currentRefreshRate() const | 733 | int DrmOutput::currentRefreshRate() const | ||
766 | { | 734 | { | ||
767 | if (!m_waylandOutput) { | 735 | if (!m_waylandOutput) { | ||
768 | return 60000; | 736 | return 60000; | ||
769 | } | 737 | } | ||
770 | return m_waylandOutput->refreshRate(); | 738 | return m_waylandOutput->refreshRate(); | ||
771 | } | 739 | } | ||
772 | 740 | | |||
773 | void DrmOutput::setGlobalPos(const QPoint &pos) | | |||
774 | { | | |||
775 | m_globalPos = pos; | | |||
776 | if (m_waylandOutput) { | | |||
777 | m_waylandOutput->setGlobalPosition(pos); | | |||
778 | } | | |||
779 | if (m_waylandOutputDevice) { | | |||
780 | m_waylandOutputDevice->setGlobalPosition(pos); | | |||
781 | } | | |||
782 | } | | |||
783 | | ||||
784 | void DrmOutput::setScale(qreal scale) | | |||
785 | { | | |||
786 | m_scale = scale; | | |||
787 | if (m_waylandOutput) { | | |||
788 | m_waylandOutput->setScale(scale); | | |||
789 | } | | |||
790 | if (m_waylandOutputDevice) { | | |||
791 | m_waylandOutputDevice->setScale(scale); | | |||
792 | } | | |||
793 | } | | |||
794 | | ||||
795 | void DrmOutput::setChanges(KWayland::Server::OutputChangeSet *changes) | | |||
796 | { | | |||
797 | m_changeset = changes; | | |||
798 | qCDebug(KWIN_DRM) << "set changes in DrmOutput"; | | |||
799 | commitChanges(); | | |||
800 | } | | |||
801 | | ||||
802 | bool DrmOutput::commitChanges() | 741 | bool DrmOutput::commitChanges() | ||
803 | { | 742 | { | ||
804 | Q_ASSERT(!m_waylandOutputDevice.isNull()); | 743 | Q_ASSERT(!m_waylandOutputDevice.isNull()); | ||
805 | 744 | | |||
806 | if (m_changeset.isNull()) { | 745 | if (m_changeset.isNull()) { | ||
807 | qCDebug(KWIN_DRM) << "no changes"; | 746 | qCDebug(KWIN_DRM) << "no changes"; | ||
808 | // No changes to an output is an entirely valid thing | 747 | // No changes to an output is an entirely valid thing | ||
809 | return true; | 748 | return true; | ||
▲ Show 20 Lines • Show All 489 Lines • Show Last 20 Lines |
Is it safe? Shouldn't you test the pointer for validity?
Also, it looks like DrmOutput deletes objects that it doesn't own. Is it a good idea?