summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJohan Klokkhammer Helsing <johan.helsing@qt.io>2019-05-10 16:38:08 +0200
committerPaul Olav Tvete <paul.tvete@qt.io>2019-09-03 09:59:18 +0000
commit4ebebf0e7744ed01fc076098b890d01510eb6ae0 (patch)
tree940c88abff5c6d66bb99f71fcce8545699ed0be2 /src
parentb61f0c9a41bdedfe37891f64740750243dbdaabb (diff)
Compositor: Respect wl_shm format when converting to a QImage
[ChangeLog][Compositor] Fixed a bug where compositors would advertise support for numerous wl_shm pixel formats and then blindly assume everything to be ARGB32_Premultiplied. Note that this may cause expensive conversions if the format of the client and the screen differs. The solution is probably to add API for letting the compositor opt in to the formats it wants to support (except for argb8888 and xrgb8888 which are mandatory). Fixes: QTBUG-75635 Change-Id: I07ca3dd4ef9633222d53361860fc0ab99f02eae7 Reviewed-by: Paul Olav Tvete <paul.tvete@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/compositor/wayland_wrapper/qwlclientbuffer.cpp10
1 files changed, 6 insertions, 4 deletions
diff --git a/src/compositor/wayland_wrapper/qwlclientbuffer.cpp b/src/compositor/wayland_wrapper/qwlclientbuffer.cpp
index ef6b26483..d3f8df9f3 100644
--- a/src/compositor/wayland_wrapper/qwlclientbuffer.cpp
+++ b/src/compositor/wayland_wrapper/qwlclientbuffer.cpp
@@ -133,17 +133,19 @@ QWaylandSurface::Origin SharedMemoryBuffer::origin() const
return QWaylandSurface::OriginTopLeft;
}
-
-// TODO: support different color formats, and try to avoid QImage::convertToFormat()
-
QImage SharedMemoryBuffer::image() const
{
if (wl_shm_buffer *shmBuffer = wl_shm_buffer_get(m_buffer)) {
int width = wl_shm_buffer_get_width(shmBuffer);
int height = wl_shm_buffer_get_height(shmBuffer);
int bytesPerLine = wl_shm_buffer_get_stride(shmBuffer);
+
+ // TODO: try to avoid QImage::convertToFormat()
+ wl_shm_format shmFormat = wl_shm_format(wl_shm_buffer_get_format(shmBuffer));
+ QImage::Format format = QWaylandSharedMemoryFormatHelper::fromWaylandShmFormat(shmFormat);
+
uchar *data = static_cast<uchar *>(wl_shm_buffer_get_data(shmBuffer));
- return QImage(data, width, height, bytesPerLine, QImage::Format_ARGB32_Premultiplied);
+ return QImage(data, width, height, bytesPerLine, format);
}
return QImage();