Bug 365243

Summary: Red and blue channels swapped with fbdev backend on cirrus
Product: [Plasma] kwin Reporter: Fabian Vogt <fabian>
Component: platform-fbdevAssignee: KWin default assignee <kwin-bugs-null>
Status: RESOLVED FIXED    
Severity: normal Flags: mgraesslin: ReviewRequest+
Priority: NOR    
Version First Reported In: git master   
Target Milestone: ---   
Platform: Compiled Sources   
OS: Linux   
Latest Commit: Version Fixed In: 5.7.2
Sentry Crash Report:

Description Fabian Vogt 2016-07-08 17:00:56 UTC
When starting KWIN_COMPOSE=Q kwin_wayland --framebuffer [...] in a VM with the cirrus backend,
the red and blue channels appear swapped, so RGB <-> BGR. 
I couldn't test whether the bug is in the QPainter or the framebuffer backend as the DRM backend is currently broken with cirrus (bug 365242).

Reproducible: Always
Comment 1 Martin Flöser 2016-07-11 06:49:16 UTC
Could you please enable debug output for the category:
kwin_wayland_framebuffer

The format of the framebuffer device and the mapping to a QImage format is logged out so we should see what KWin does. My best guess is that this is a format we don't support yet.
Comment 2 Fabian Vogt 2016-07-11 07:13:13 UTC
(In reply to Martin Gräßlin from comment #1)
> Could you please enable debug output for the category:
> kwin_wayland_framebuffer
> 
> The format of the framebuffer device and the mapping to a QImage format is
> logged out so we should see what KWin does. My best guess is that this is a
> format we don't support yet.

kwin_wayland_framebuffer: Bits Per Pixel:  24                                                                                   
kwin_wayland_framebuffer: Buffer Length:  33554432                                                                              
kwin_wayland_framebuffer: Bytes Per Line:  3072                                                                                 
kwin_wayland_framebuffer: Alpha Length:  0                                                                                      
kwin_wayland_framebuffer: Red Length:  8                                                                                        
kwin_wayland_framebuffer: Green Length:  8                                                                                      
kwin_wayland_framebuffer: Blue Length:  8                                                                                       
kwin_wayland_framebuffer: Blue Offset:  0                                                                                       
kwin_wayland_framebuffer: Green Offset:  8                                                                                     
kwin_wayland_framebuffer: Red Offset:  16                                                                                       
kwin_wayland_framebuffer: Alpha Offset:  0                                                                                      
kwin_wayland_framebuffer: Framebuffer Format is RGB888   

IIRC, RGB888 has its red at an offset of 0, so RGB888 is wrong here.
Comment 3 Martin Flöser 2016-07-11 08:40:50 UTC
yep looks like a BGR format to me.
Comment 4 Martin Flöser 2016-07-11 08:57:26 UTC
Please try: https://phabricator.kde.org/D2134 - I hope that this fixes the problem, but I don't have a way to test it on my system.
Comment 5 Fabian Vogt 2016-07-11 11:57:05 UTC
(In reply to Martin Gräßlin from comment #4)
> Please try: https://phabricator.kde.org/D2134 - I hope that this fixes the
> problem, but I don't have a way to test it on my system.

It does not work, kwin_wayland does not display anything at all. Causing kwin to draw by moving the cursor, for example, results in "QPainter::begin: Paint device returned engine == 0, type: 3 " being printed.
Comment 6 Martin Flöser 2016-07-11 12:25:47 UTC
Thanks for testing. Looks like I need to setup a VM...
Comment 7 Martin Flöser 2016-07-12 12:30:22 UTC
VM is setup, I can confirm the issues with the rgb being swapped and must say that it looks "beautiful"
Comment 8 Martin Flöser 2016-07-12 14:15:09 UTC
Uploaded a new patch version on phabricator. Now it works and colors are correct.
Comment 9 Fabian Vogt 2016-07-12 14:41:00 UTC
(In reply to Martin Gräßlin from comment #8)
> Uploaded a new patch version on phabricator. Now it works and colors are
> correct.

Works here as well, thanks!
Comment 10 Martin Flöser 2016-07-13 07:38:54 UTC
Git commit aaf8ce16dfb258a48ea25209b6747f5d9f5a85b6 by Martin Gräßlin.
Committed on 13/07/2016 at 07:37.
Pushed by graesslin into branch 'Plasma/5.7'.

[platforms/fbdev] Properly detect a BGR image format

Summary:
If the format of the framebuffer is BGR we cannot create an RGB image
format from it - the rendering is incorrect. Unfortunately QImage does
not support a BGR image format.

To solve this problem we still use an RGB image format but on rendering
the front buffer is rgbSwapped to convert the RGB image to a BGR image.
FIXED-IN: 5.7.2

Test Plan: Tested on a neon kvm

Reviewers: #kwin, #plasma_on_wayland

Subscribers: plasma-devel, kwin

Tags: #plasma_on_wayland, #kwin

Differential Revision: https://phabricator.kde.org/D2134

M  +11   -5    plugins/platforms/fbdev/fb_backend.cpp
M  +9    -0    plugins/platforms/fbdev/fb_backend.h
M  +1    -1    plugins/platforms/fbdev/scene_qpainter_fb_backend.cpp

http://commits.kde.org/kwin/aaf8ce16dfb258a48ea25209b6747f5d9f5a85b6