From 24c9194f4c95d61a0f9df6de673d79f28aa6aee6 Mon Sep 17 00:00:00 2001 From: David Edmundson Date: Mon, 6 Mar 2017 00:39:20 +0000 Subject: [PATCH] Scaling support in ColorPicker effect Summary: glReadPixels needs the correct location relative to the framebuffer so we need to factor in the scale as well as translation when going from compositor space. Test Plan: Ran the plasma colour picker plasmoid in windowed mode Clicked on multiple parts of a window It was right every time Reviewers: #plasma Subscribers: plasma-devel, kwin, #kwin Tags: #kwin Differential Revision: https://phabricator.kde.org/D4950 --- effects/colorpicker/colorpicker.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/effects/colorpicker/colorpicker.cpp b/effects/colorpicker/colorpicker.cpp index 707e73e163..ea362318a1 100644 --- a/effects/colorpicker/colorpicker.cpp +++ b/effects/colorpicker/colorpicker.cpp @@ -74,7 +74,10 @@ void ColorPickerEffect::postPaintScreen() if (m_scheduledPosition != QPoint(-1, -1) && (m_cachedOutputGeometry.isEmpty() || m_cachedOutputGeometry.contains(m_scheduledPosition))) { uint8_t data[3]; const QRect geo = GLRenderTarget::virtualScreenGeometry(); - glReadnPixels(m_scheduledPosition.x() - geo.x(), geo.height() - geo.y() - m_scheduledPosition.y(), 1, 1, GL_RGB, GL_UNSIGNED_BYTE, 3, data); + const QPoint screenPosition(m_scheduledPosition.x() - geo.x(), m_scheduledPosition.y() - geo.y()); + const QPoint texturePosition(screenPosition.x() * GLRenderTarget::virtualScreenScale(), (geo.height() - screenPosition.y()) * GLRenderTarget::virtualScreenScale()); + + glReadnPixels(texturePosition.x(), texturePosition.y(), 1, 1, GL_RGB, GL_UNSIGNED_BYTE, 3, data); QDBusConnection::sessionBus().send(m_replyMessage.createReply(QColor(data[0], data[1], data[2]))); m_picking = false; m_scheduledPosition = QPoint(-1, -1);