Changeset View
Changeset View
Standalone View
Standalone View
plugins/platforms/drm/drm_output.cpp
Show First 20 Lines • Show All 121 Lines • ▼ Show 20 Line(s) | 116 | { | |||
---|---|---|---|---|---|
122 | if (m_hasNewCursor) { | 122 | if (m_hasNewCursor) { | ||
123 | m_cursorIndex = (m_cursorIndex + 1) % 2; | 123 | m_cursorIndex = (m_cursorIndex + 1) % 2; | ||
124 | m_hasNewCursor = false; | 124 | m_hasNewCursor = false; | ||
125 | } | 125 | } | ||
126 | 126 | | |||
127 | return ret; | 127 | return ret; | ||
128 | } | 128 | } | ||
129 | 129 | | |||
130 | qreal orientationToRotation(Qt::ScreenOrientation orientation) | 130 | int orientationToRotation(Qt::ScreenOrientation orientation) | ||
zzag: Could you please explain this change? | |||||
We are using the result to check if there's orientation. It's not really a good idea to compare doubles to 0 so I changed to int. apol: We are using the result to check if there's orientation. It's not really a good idea to compare… | |||||
131 | { | 131 | { | ||
132 | switch (orientation) { | 132 | switch (orientation) { | ||
133 | case Qt::PrimaryOrientation: | 133 | case Qt::PrimaryOrientation: | ||
134 | case Qt::LandscapeOrientation: | 134 | case Qt::LandscapeOrientation: | ||
135 | return 0.; | 135 | return 0; | ||
136 | case Qt::InvertedPortraitOrientation: | 136 | case Qt::InvertedPortraitOrientation: | ||
137 | return 90.; | 137 | return 90; | ||
138 | case Qt::InvertedLandscapeOrientation: | 138 | case Qt::InvertedLandscapeOrientation: | ||
139 | return 180.; | 139 | return 180; | ||
140 | case Qt::PortraitOrientation: | 140 | case Qt::PortraitOrientation: | ||
141 | return 270.; | 141 | return 270; | ||
142 | } | 142 | } | ||
143 | Q_UNREACHABLE(); | 143 | Q_UNREACHABLE(); | ||
144 | return 0; | 144 | return 0; | ||
145 | } | 145 | } | ||
146 | 146 | | |||
147 | QMatrix4x4 &&DrmOutput::matrixDisplay(const QSize &s) const | ||||
zzag: QMatrix4x4 && | |||||
zzag: ```lang=cpp
QMatrix4x4 &&DrmOutput::
``` | |||||
148 | { | ||||
149 | QMatrix4x4 matrix; | ||||
150 | const int angle = orientationToRotation(orientation()); | ||||
151 | if (angle) { | ||||
152 | const QSize center = s / 2; | ||||
zzag: Please follow coding style.
`s / 2` | |||||
153 | | ||||
154 | matrix.translate(center.width(), center.height()); | ||||
155 | matrix.rotate(angle, 0, 0, 1); | ||||
156 | matrix.translate(-center.width(), -center.height()); | ||||
157 | } | ||||
158 | matrix.scale(scale()); | ||||
159 | return std::move(matrix); | ||||
160 | } | ||||
161 | | ||||
147 | void DrmOutput::updateCursor() | 162 | void DrmOutput::updateCursor() | ||
148 | { | 163 | { | ||
149 | QImage cursorImage = m_backend->softwareCursor(); | 164 | QImage cursorImage = m_backend->softwareCursor(); | ||
150 | if (cursorImage.isNull()) { | 165 | if (cursorImage.isNull()) { | ||
151 | return; | 166 | return; | ||
152 | } | 167 | } | ||
153 | m_hasNewCursor = true; | 168 | m_hasNewCursor = true; | ||
154 | QImage *c = m_cursor[m_cursorIndex]->image(); | 169 | QImage *c = m_cursor[m_cursorIndex]->image(); | ||
155 | c->fill(Qt::transparent); | 170 | c->fill(Qt::transparent); | ||
156 | c->setDevicePixelRatio(scale()); | | |||
157 | 171 | | |||
158 | QPainter p; | 172 | QPainter p; | ||
159 | p.begin(c); | 173 | p.begin(c); | ||
160 | if (orientation() != Qt::LandscapeOrientation) { | 174 | p.setWorldTransform(matrixDisplay(QSize(cursorImage.width(), cursorImage.height())).toTransform()); | ||
161 | QMatrix4x4 matrix; | | |||
162 | matrix.translate(cursorImage.width() / 2.0, cursorImage.height() / 2.0); | | |||
163 | matrix.rotate(orientationToRotation(orientation()), 0.0f, 0.0f, 1.0f); | | |||
164 | matrix.translate(-cursorImage.width() / 2.0, -cursorImage.height() / 2.0); | | |||
165 | p.setWorldTransform(matrix.toTransform()); | | |||
166 | } | | |||
167 | p.drawImage(QPoint(0, 0), cursorImage); | 175 | p.drawImage(QPoint(0, 0), cursorImage); | ||
168 | p.end(); | 176 | p.end(); | ||
169 | } | 177 | } | ||
170 | 178 | | |||
171 | void DrmOutput::moveCursor(const QPoint &globalPos) | 179 | void DrmOutput::moveCursor(const QPoint &globalPos) | ||
172 | { | 180 | { | ||
173 | QMatrix4x4 matrix; | 181 | const QMatrix4x4 hotspotMatrix = matrixDisplay(m_backend->softwareCursor().size()); | ||
174 | QMatrix4x4 hotspotMatrix; | 182 | | ||
175 | if (orientation() != Qt::LandscapeOrientation) { | 183 | QPoint p = globalPos-AbstractOutput::globalPos(); | ||
176 | auto rotation = orientationToRotation(orientation()); | 184 | switch (orientation()) { | ||
177 | matrix.translate(pixelSize().width() /2.0, pixelSize().height() / 2.0); | 185 | case Qt::PrimaryOrientation: | ||
zzag: Please don't indent `case`s. | |||||
178 | matrix.rotate(rotation, 0.0f, 0.0f, 1.0f); | 186 | case Qt::LandscapeOrientation: | ||
179 | matrix.translate(-pixelSize().width() /2.0, -pixelSize().height() / 2.0); | 187 | break; | ||
180 | const auto cursorSize = m_backend->softwareCursor().size(); | 188 | case Qt::PortraitOrientation: | ||
181 | hotspotMatrix.translate(cursorSize.width()/2.0, cursorSize.height()/2.0); | 189 | p = QPoint(p.y(), pixelSize().height() - p.x()); | ||
zzag: Why `ry` and `rx`? | |||||
182 | hotspotMatrix.rotate(rotation, 0.0f, 0.0f, 1.0f); | 190 | break; | ||
183 | hotspotMatrix.translate(-cursorSize.width()/2.0, -cursorSize.height()/2.0); | 191 | case Qt::InvertedPortraitOrientation: | ||
192 | p = QPoint(pixelSize().width() - p.y(), p.x()); | ||||
193 | break; | ||||
194 | case Qt::InvertedLandscapeOrientation: | ||||
195 | p = QPoint(pixelSize().width() - p.x(), pixelSize().height() - p.y()); | ||||
196 | break; | ||||
184 | } | 197 | } | ||
185 | hotspotMatrix.scale(scale()); | 198 | p *= scale(); | ||
186 | matrix.scale(scale()); | 199 | p -= hotspotMatrix.map(m_backend->softwareCursorHotspot()); | ||
zzag: I'd say that's abuse of `auto` even though the name contains "Matrix". | |||||
187 | const auto outputGlobalPos = AbstractOutput::globalPos(); | | |||
188 | matrix.translate(-outputGlobalPos.x(), -outputGlobalPos.y()); | | |||
189 | const QPoint p = matrix.map(globalPos) - hotspotMatrix.map(m_backend->softwareCursorHotspot()); | | |||
190 | drmModeMoveCursor(m_backend->fd(), m_crtc->id(), p.x(), p.y()); | 200 | drmModeMoveCursor(m_backend->fd(), m_crtc->id(), p.x(), p.y()); | ||
191 | } | 201 | } | ||
192 | 202 | | |||
193 | static QHash<int, QByteArray> s_connectorNames = { | 203 | static QHash<int, QByteArray> s_connectorNames = { | ||
194 | {DRM_MODE_CONNECTOR_Unknown, QByteArrayLiteral("Unknown")}, | 204 | {DRM_MODE_CONNECTOR_Unknown, QByteArrayLiteral("Unknown")}, | ||
195 | {DRM_MODE_CONNECTOR_VGA, QByteArrayLiteral("VGA")}, | 205 | {DRM_MODE_CONNECTOR_VGA, QByteArrayLiteral("VGA")}, | ||
196 | {DRM_MODE_CONNECTOR_DVII, QByteArrayLiteral("DVI-I")}, | 206 | {DRM_MODE_CONNECTOR_DVII, QByteArrayLiteral("DVI-I")}, | ||
197 | {DRM_MODE_CONNECTOR_DVID, QByteArrayLiteral("DVI-D")}, | 207 | {DRM_MODE_CONNECTOR_DVID, QByteArrayLiteral("DVI-D")}, | ||
▲ Show 20 Lines • Show All 1007 Lines • Show Last 20 Lines |
Could you please explain this change?