Bug 406302 - window decorations colours on 30-bit colour depth (10-bit/channel) displays are wrong (garbled)
Summary: window decorations colours on 30-bit colour depth (10-bit/channel) displays a...
Status: RESOLVED FIXED
Alias: None
Product: kwin
Classification: Plasma
Component: decorations (show other bugs)
Version: 5.19.0
Platform: Arch Linux Linux
: NOR normal
Target Milestone: ---
Assignee: KWin default assignee
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-04-07 15:30 UTC by bogdan
Modified: 2020-07-10 15:01 UTC (History)
5 users (show)

See Also:
Latest Commit:
Version Fixed In: 5.19.4


Attachments
Example of wrong colours in title bar and borders (163.23 KB, image/png)
2019-04-07 15:52 UTC, bogdan
Details
attachment-5583-0.html (1.41 KB, text/html)
2019-04-25 12:34 UTC, bogdan
Details
Purple decorations with 30bit visual (165.09 KB, image/png)
2020-06-15 11:48 UTC, Bernie Innocenti
Details

Note You need to log in before you can comment on or make changes to this bug.
Description bogdan 2019-04-07 15:30:12 UTC
SUMMARY
When the display is set to 30-bit colour depth (10-bi/channel) such as shown in the xorg.conf below, colours of teh window decoration are wrong (garbled) (see attachment.

Section "Screen"
    Identifier     "Screen0"
    Device         "Device0"
    Monitor        "Monitor0"
    DefaultDepth    30
    SubSection     "Display"
        Depth       30
    EndSubSection
EndSection


STEPS TO REPRODUCE
1.  Need a wide gamut monitor. Change the screen section in xorg.conf as shown above to enable 30 bit color depth on the display device/monitor
2. restart X 
3. Observe the window decoration (title bar & borders) colors, which are wrong, the colors displayed in the window are good. 



OBSERVED RESULT

Wrong colours of the window decorations

EXPECTED RESULT

Good colours of the window decorations as in the rest of the window.
SOFTWARE/OS VERSIONS
Windows: 
macOS: 
Linux/KDE Plasma: Open Suse Leap 15.1  
(available in About System)
KDE Plasma Version: 5.15
KDE Frameworks Version: 5.56
Qt Version: 

ADDITIONAL INFORMATION
Comment 1 bogdan 2019-04-07 15:43:03 UTC
It is Open Suse Leap 15.0
Comment 2 bogdan 2019-04-07 15:52:15 UTC
Created attachment 119284 [details]
Example of wrong colours in title bar and borders

Please look carefully at  both window decorations: title bar and borders
Comment 3 Vlad Zahorodnii 2019-04-25 10:09:03 UTC
Heh, I guess Aurorae decorations suffer from the issue, right?
Comment 4 David Edmundson 2019-04-25 10:12:55 UTC
Is it the same with compositing on?
Comment 5 bogdan 2019-04-25 12:34:35 UTC
Created attachment 119628 [details]
attachment-5583-0.html

Yes, I have compositing on. I have not tried 30 bit color in some time.
Before I fixed things using QT_NATIVE but this is not working in the new QT.

On Thu, Apr 25, 2019, 06:12 David Edmundson, <bugzilla_noreply@kde.org>
wrote:

> https://bugs.kde.org/show_bug.cgi?id=406302
>
> David Edmundson <kde@davidedmundson.co.uk> changed:
>
>            What    |Removed                     |Added
>
> ----------------------------------------------------------------------------
>                  CC|                            |kde@davidedmundson.co.uk
>
> --- Comment #4 from David Edmundson <kde@davidedmundson.co.uk> ---
> Is it the same with compositing on?
>
> --
> You are receiving this mail because:
> You are on the CC list for the bug.
Comment 6 David Edmundson 2019-04-25 12:49:32 UTC
>Yes, I have compositing on. 

Are you sure? I can't see any shadows there.

Can I have your qdbus org.kde.KWin /KWin org.kde.KWin.supportInformation
Comment 7 bogdan 2019-04-26 22:29:26 UTC
I guess that this is what you were looking for:

Compositing
===========
Compositing is not active

You were right, it was not active, but not because I din not enable it but because it crashed and was not reenabled at reboot. I went in Systemsettings and I had to press the "Reenable OpenGL" button. Now the decorations are fine and the shadow is there. 

Next time if it crashes I will know what to do, but perhaps it would help to make this more obvious? Or to try to reenable it by default at startup, but I understand that it may go into a infinite loop.

Thanks for the hint. I was so sure that I have compositing on, and it was but disabled due to a previous crash of the OpenGL library
Comment 8 Bernie Innocenti 2020-06-15 11:47:09 UTC
This is still happening with plasma 5.19 and latest mesa / libdri.

I'm seeing purple window decorations both on a laptop with i915 graphics and on a PC with amdgpu: https://codewiz.org/pub/kwin-decorations-30bpp.png

NOTE: only happens with a 30-bit visual and compositing *off*.
NOTE: also affects kwinft built from git
Comment 9 Bernie Innocenti 2020-06-15 11:48:44 UTC
Created attachment 129380 [details]
Purple decorations with 30bit visual
Comment 10 bogdan 2020-06-15 16:44:33 UTC
(In reply to bernie from comment #8)
> NOTE: only happens with a 30-bit visual and compositing *off*.

I had the same problem but I learned from the comments.  You need compositing on for 30 bit colors. Read the comments on this thread.

This may not be a bug. Someone working on this will probably confirm.
Comment 11 Bernie Innocenti 2020-06-18 13:54:04 UTC
(In reply to bogdan from comment #10)
> I had the same problem but I learned from the comments.  You need
> compositing on for 30 bit colors. Read the comments on this thread.
> 
> This may not be a bug. Someone working on this will probably confirm.

Well, but why is everything rendering fine *except* for window decorations?

And it's only *some* decorations:

 - System Settings: purple
 - Konsole (qt5): ok (why???)
 - Quassel IRC (qt5): purple
 - Signal Desktop (electron): purple
 - Firefox (gtk3 client-side decorations): ok
 - Chrome no system decorations: ok
 - Chrome system decorations: ok
Comment 12 Vlad Zahorodnii 2020-06-18 14:03:53 UTC
I'm not 100% sure, but maybe the problem is that we're using QImage::Format_ARGB32_Premultiplied instead of QImage::Format_A2RGB30_Premultiplied over here https://invent.kde.org/plasma/kwin/-/blob/1d34d29222398417961875b36d0fb3b5db9fa5b3/decorations/decorationrenderer.cpp#L70
Comment 13 Bernie Innocenti 2020-06-18 15:57:11 UTC
(In reply to Vlad Zahorodnii from comment #12)
> I'm not 100% sure, but maybe the problem is that we're using
> QImage::Format_ARGB32_Premultiplied instead of
> QImage::Format_A2RGB30_Premultiplied over here
> https://invent.kde.org/plasma/kwin/-/blob/
> 1d34d29222398417961875b36d0fb3b5db9fa5b3/decorations/decorationrenderer.
> cpp#L70

Switching to Format_A2RGB30_Premultiplied fixes the decorations when compositing is off.
However, it breaks them when compisiting is *enabled*!
Comment 14 Bernie Innocenti 2020-06-20 16:34:04 UTC
Looks like kwin extracts the bits from the QImage to draw it via xcb_put_image():

https://invent.kde.org/plasma/kwin/-/blob/master/plugins/scenes/xrender/scene_xrender.cpp#L1249-1253

I don't see a way to specify the pixel format. Do we need to convert the QImage to match the screen format beforehand?
Comment 15 Bug Janitor Service 2020-07-05 20:44:33 UTC
A possibly relevant merge request was started @ https://invent.kde.org/plasma/kwin/-/merge_requests/97
Comment 16 Bernie Innocenti 2020-07-05 20:47:08 UTC
This is my proposed fix:
https://invent.kde.org/plasma/kwin/-/merge_requests/97

It's not elegant, but should get the job done. Please review and test.
Comment 17 Bernie Innocenti 2020-07-05 21:08:46 UTC
Oops, my fix triggers a crash in QOpenGLContext::format(). I can't investigate it at the moment because I don't have Qt built with debuginfo, but here's the backtrace:

Thread 1 "kwin_x11" received signal SIGSEGV, Segmentation fault.
0x00007ffff4bfe8f7 in QOpenGLContext::format() const () from /usr/lib/libQt5Gui.so.5
(gdb) bt
#0  0x00007ffff4bfe8f7 in QOpenGLContext::format() const () at /usr/lib/libQt5Gui.so.5
#1  0x00007ffff6fc3287 in QSGBatchRenderer::Renderer::Renderer(QSGDefaultRenderContext*) () at /usr/lib/libQt5Quick.so.5
#2  0x00007ffff70148a4 in QSGDefaultRenderContext::createRenderer() () at /usr/lib/libQt5Quick.so.5
#3  0x00007ffff7081183 in QQuickWindowPrivate::syncSceneGraph() () at /usr/lib/libQt5Quick.so.5
#4  0x00007ffff70005e4 in  () at /usr/lib/libQt5Quick.so.5
#5  0x00007ffff70024ca in  () at /usr/lib/libQt5Quick.so.5
#6  0x00007ffff4bc7955 in QWindow::event(QEvent*) () at /usr/lib/libQt5Gui.so.5
#7  0x00007fff03378f70 in PlasmaQuick::Dialog::event(QEvent*) (this=0x555556260de0, event=0x7fffffffd670)
    at /home/bernie/kde/src/plasma-framework/src/plasmaquick/dialog.cpp:1212
#8  0x00007ffff52ae702 in QApplicationPrivate::notify_helper(QObject*, QEvent*) () at /usr/lib/libQt5Widgets.so.5
#9  0x000055555555c687 in KWin::ApplicationX11::notify(QObject*, QEvent*) (this=0x7fffffffd870, o=0x555556260de0, e=0x7fffffffd670)
    at /home/bernie/kde/src/kwin/main_x11.cpp:273
#10 0x00007ffff47de7ba in QCoreApplication::notifyInternal2(QObject*, QEvent*) () at /usr/lib/libQt5Core.so.5
#11 0x00007ffff4bbc7e0 in QGuiApplicationPrivate::processExposeEvent(QWindowSystemInterfacePrivate::ExposeEvent*) ()
    at /usr/lib/libQt5Gui.so.5
#12 0x00007ffff4b90b4c in QWindowSystemInterface::sendWindowSystemEvents(QFlags<QEventLoop::ProcessEventsFlag>) () at /usr/lib/libQt5Gui.so.5
#13 0x00007fffefdaa076 in  () at /usr/lib/libQt5XcbQpa.so.5
#14 0x00007ffff47dd13c in QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) () at /usr/lib/libQt5Core.so.5
#15 0x00007ffff47e55c4 in QCoreApplication::exec() () at /usr/lib/libQt5Core.so.5
#16 0x000055555555dea2 in main(int, char**) (argc=2, argv=0x7fffffffd9f8) at /home/bernie/kde/src/kwin/main_x11.cpp:479
(gdb) frame 1
#1  0x00007ffff6fc3287 in QSGBatchRenderer::Renderer::Renderer(QSGDefaultRenderContext*) () from /usr/lib/libQt5Quick.so.5
(gdb) bt
#0  0x00007ffff4bfe8f7 in QOpenGLContext::format() const () at /usr/lib/libQt5Gui.so.5
#1  0x00007ffff6fc3287 in QSGBatchRenderer::Renderer::Renderer(QSGDefaultRenderContext*) () at /usr/lib/libQt5Quick.so.5
#2  0x00007ffff70148a4 in QSGDefaultRenderContext::createRenderer() () at /usr/lib/libQt5Quick.so.5
#3  0x00007ffff7081183 in QQuickWindowPrivate::syncSceneGraph() () at /usr/lib/libQt5Quick.so.5
#4  0x00007ffff70005e4 in  () at /usr/lib/libQt5Quick.so.5
#5  0x00007ffff70024ca in  () at /usr/lib/libQt5Quick.so.5
#6  0x00007ffff4bc7955 in QWindow::event(QEvent*) () at /usr/lib/libQt5Gui.so.5
#7  0x00007fff03378f70 in PlasmaQuick::Dialog::event(QEvent*) (this=0x555556260de0, event=0x7fffffffd670)
    at /home/bernie/kde/src/plasma-framework/src/plasmaquick/dialog.cpp:1212
#8  0x00007ffff52ae702 in QApplicationPrivate::notify_helper(QObject*, QEvent*) () at /usr/lib/libQt5Widgets.so.5
#9  0x000055555555c687 in KWin::ApplicationX11::notify(QObject*, QEvent*) (this=0x7fffffffd870, o=0x555556260de0, e=0x7fffffffd670)
    at /home/bernie/kde/src/kwin/main_x11.cpp:273
#10 0x00007ffff47de7ba in QCoreApplication::notifyInternal2(QObject*, QEvent*) () at /usr/lib/libQt5Core.so.5
#11 0x00007ffff4bbc7e0 in QGuiApplicationPrivate::processExposeEvent(QWindowSystemInterfacePrivate::ExposeEvent*) ()
    at /usr/lib/libQt5Gui.so.5
#12 0x00007ffff4b90b4c in QWindowSystemInterface::sendWindowSystemEvents(QFlags<QEventLoop::ProcessEventsFlag>) () at /usr/lib/libQt5Gui.so.5
#13 0x00007fffefdaa076 in  () at /usr/lib/libQt5XcbQpa.so.5
#14 0x00007ffff47dd13c in QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) () at /usr/lib/libQt5Core.so.5
#15 0x00007ffff47e55c4 in QCoreApplication::exec() () at /usr/lib/libQt5Core.so.5
#16 0x000055555555dea2 in main(int, char**) (argc=2, argv=0x7fffffffd9f8) at /home/bernie/kde/src/kwin/main_x11.cpp:479
Comment 18 Bernie Innocenti 2020-07-10 13:45:11 UTC
Git commit 0c67eb983c84ac06a0e34ca0aaa87b840c503348 by Bernie Innocenti.
Committed on 10/07/2020 at 13:08.
Pushed by davidedmundson into branch 'master'.

[decorations] Fix rendering for depth 30 (10bpc)

When the display is set to 30-bit depth (10-bit per color component),
decorations of some clients appear garbled when compositing is disabled.
This is because the pixel format of the QImage in which the decorations
were rendered differed from the the X pixmap into which the pixels were
being copied by means of xcb_put_image().

For lack of a more robust way, this change guesses A2RGB30 for depth=30,
and keeps using ARGB32 as before for any other depth. I don't expect
anything other to 32bpp to be supported by KWin anyway.

Tested on amdgpu with KWIN_OPENGL_INTERFACE=egl.
FIXED-IN: 5.19.4

M  +20   -1    decorations/decorationrenderer.cpp

https://invent.kde.org/plasma/kwin/commit/0c67eb983c84ac06a0e34ca0aaa87b840c503348
Comment 19 Bernie Innocenti 2020-07-10 14:22:34 UTC
bogdan@, if you can build kwin from source, could you please test the fix and report back?
Comment 20 bogdan 2020-07-10 15:01:43 UTC
@bernie I could try this weekend. but I can't promise.