From 4ebebf0e7744ed01fc076098b890d01510eb6ae0 Mon Sep 17 00:00:00 2001 From: Johan Klokkhammer Helsing Date: Fri, 10 May 2019 16:38:08 +0200 Subject: 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 --- src/compositor/wayland_wrapper/qwlclientbuffer.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'src') 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(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(); -- cgit v1.2.3