Bug 409762 - [wayland] Screenshots taken on displays with scaling lack resolution
Summary: [wayland] Screenshots taken on displays with scaling lack resolution
Status: VERIFIED FIXED
Alias: None
Product: Spectacle
Classification: Applications
Component: General (show other bugs)
Version: 19.04.3
Platform: Other Linux
: VHI grave
Target Milestone: ---
Assignee: Boudhayan Gupta
URL:
Keywords: wayland
: 414296 418313 418881 425226 (view as bug list)
Depends on:
Blocks:
 
Reported: 2019-07-13 07:25 UTC by Marvin Hagemeister
Modified: 2021-08-04 23:53 UTC (History)
9 users (show)

See Also:
Latest Commit:
Version Fixed In: 20.12


Attachments
Sample blurry screenshot taken by spectacle (22.89 KB, image/png)
2019-07-13 07:25 UTC, Marvin Hagemeister
Details
Spectacle X11 (695.23 KB, image/png)
2019-07-16 06:04 UTC, Marvin Hagemeister
Details
Spectacle Wayland (291.94 KB, image/png)
2019-07-16 06:04 UTC, Marvin Hagemeister
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Marvin Hagemeister 2019-07-13 07:25:49 UTC
Created attachment 121489 [details]
Sample blurry screenshot taken by spectacle

SUMMARY

Whenever I take a screenshot with spectacle the resulting image is super blurry. I'm not sure if this is related to wayland or caused by a high-dpi screen or anti-aliasing. Please have a look at the attached screenshot which shows the problem

STEPS TO REPRODUCE
1. Run a wayland session
2. Make a screenshot
3. Open created screenshot

OBSERVED RESULT
Screenshot is blurry


EXPECTED RESULT
Screenshot is crisp sharp


SOFTWARE/OS VERSIONS
Linux/KDE Plasma: Arch Linux
KDE Plasma Version: 5.16.3
KDE Frameworks Version: 5.59.0
Qt Version: 5.13.0

ADDITIONAL INFORMATION
My laptop has a 4k screen (Dell XPS 9380)
Comment 1 Nate Graham 2019-07-15 14:57:35 UTC
Can you attach an equivalent or similar screenshot taken by Spectacle on X11 for comparison's sake?
Comment 2 Marvin Hagemeister 2019-07-16 06:04:04 UTC
Created attachment 121539 [details]
Spectacle X11

Screenshot taken with spectacle on X11
Comment 3 Marvin Hagemeister 2019-07-16 06:04:41 UTC
Created attachment 121540 [details]
Spectacle Wayland

Screenshot taken with spectacle on wayland
Comment 4 Marvin Hagemeister 2019-07-16 06:10:04 UTC
@Nate Thanks a bunch for responding. I've added two screenshots with Konsole fully maximized on the left half of the screen.

One thing I noticed is that they wayland screenshot has only half the resolution. That's why the file sizes are wildly different. That peaked my curiosity and I took another screenshot with display scaling set to 1x instead of the default 2x. Et voila spectacle takes a screenshot with the right resolution.
Comment 5 Nate Graham 2019-07-16 14:31:15 UTC
Thanks, that's very helpful! It looks like the X11 screenshot is actually higher resolution than the Wayland one, which would explain why it's sharper. Can you confirm?
Comment 6 Marvin Hagemeister 2019-07-16 20:15:25 UTC
Yup, I can confirm that the X11 screen is the proper screen resolution and that the wayland screenshot exactly half of that. The bug only occurs when the scaling setting in KDE's "Display Settings" page is set to something other than 1x. In my case that's 2x so spectacle seems to think it'd only need to use half the resolution.
Comment 7 Nate Graham 2019-07-17 16:07:41 UTC
Thanks for the info!
Comment 8 Méven Car 2019-11-19 12:17:13 UTC

*** This bug has been marked as a duplicate of bug 414296 ***
Comment 9 Méven Car 2019-11-19 14:09:03 UTC
*** Bug 414296 has been marked as a duplicate of this bug. ***
Comment 10 Méven Car 2019-11-19 14:11:02 UTC
I believe the fix needs to be made in kwin/effects/screenshot/screenshot.cpp:607 :

QImage ScreenShotEffect::blitScreenshot(const QRect &geometry)
{
    QImage img;
    if (effects->isOpenGLCompositing())
    {
        img = QImage(geometry.size(), QImage::Format_ARGB32);
        if (GLRenderTarget::blitSupported() && !GLPlatform::instance()->isGLES()) {
            GLTexture tex(GL_RGBA8, geometry.width(), geometry.height());
            GLRenderTarget target(tex);
            target.blitFromFramebuffer(geometry);
            // copy content from framebuffer into image
            tex.bind();
            glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, (GLvoid*)img.bits());
            tex.unbind();
        } else {
            glReadPixels(0, 0, img.width(), img.height(), GL_RGBA, GL_UNSIGNED_BYTE, (GLvoid*)img.bits());
        }
        ScreenShotEffect::convertFromGLImage(img, geometry.width(), geometry.height());
    }
...

To have an output image whose output image is scaled up.
Comment 11 Nate Graham 2019-11-19 20:30:21 UTC
Nice, feel free to send a patch.
Comment 12 Patrick Silva 2020-02-29 11:58:10 UTC
*** Bug 418313 has been marked as a duplicate of this bug. ***
Comment 13 Patrick Silva 2020-03-15 19:07:01 UTC
*** Bug 418881 has been marked as a duplicate of this bug. ***
Comment 14 Méven Car 2020-04-20 14:50:02 UTC
Scaled Single screen screenshots are now fixed by :
https://phabricator.kde.org/D29010

(Multi screen is not ideal, rectangular selection does not work correctly ATM)
Comment 15 Patrick Silva 2020-05-14 21:58:42 UTC
Not fixed. My display is 1080p, I changed its scale to 125% and Spectacle takes screenshot with 1.536x864 resolution.

Operating System: Arch Linux 
KDE Plasma Version: 5.18.90
KDE Frameworks Version: 5.70.0
Qt Version: 5.15.0 rc2
Comment 16 Méven Car 2020-05-15 08:54:14 UTC
You are right Patrick, this depends on a spectacle patch, and change in :
https://phabricator.kde.org/D29282#inline-169560
Comment 17 Patrick Silva 2020-08-17 14:26:57 UTC
*** Bug 425226 has been marked as a duplicate of this bug. ***
Comment 18 Claudius Ellsel 2020-08-17 14:59:17 UTC
(In reply to Méven Car from comment #16)
> You are right Patrick, this depends on a spectacle patch, and change in :
> https://phabricator.kde.org/D29282#inline-169560

This linked patch looks to me like it is only (or mostly?) about multi-screen. Might there be a way to make this work on single screen before handling the special issues with multi-screen? Currently the conversation there looks like it might be either blocked currently or need some additional work to incorporate the suggestion from David Edmundson there.
Comment 19 Méven Car 2020-08-19 10:35:23 UTC
(In reply to Claudius Ellsel from comment #18)
> (In reply to Méven Car from comment #16)
> > You are right Patrick, this depends on a spectacle patch, and change in :
> > https://phabricator.kde.org/D29282#inline-169560
> 
> This linked patch looks to me like it is only (or mostly?) about
> multi-screen. Might there be a way to make this work on single screen before
> handling the special issues with multi-screen? Currently the conversation
> there looks like it might be either blocked currently or need some
> additional work to incorporate the suggestion from David Edmundson there.

The right commit relating to this is https://phabricator.kde.org/D29010
But https://phabricator.kde.org/D29122 introduced a change since that introduced a regression.

https://invent.kde.org/plasma/kwin/-/merge_requests/194 will fix the "Current screen" case.

But for muliti-screen cases should we always take screenshots in native (not downscaled)  ?
For multiscreen screenshots, this results in distorted results.
Or Should I expose a choice, or default to non-native for multiscreen with a setting ?
Comment 20 Méven Car 2020-08-19 11:06:58 UTC
Git commit 9a8b6f730d8d516594f159dbb41aa1357d65055d by Méven Car.
Committed on 19/08/2020 at 10:23.
Pushed by meven into branch 'master'.

Make ScreenShotEffect::screenshotScreen return native screen sized images

Aka not-downscaled images.

M  +2    -0    effects/screenshot/screenshot.cpp

https://invent.kde.org/plasma/kwin/commit/9a8b6f730d8d516594f159dbb41aa1357d65055d
Comment 21 Claudius Ellsel 2020-08-19 13:17:46 UTC
(In reply to Méven Car from comment #19)
> https://invent.kde.org/plasma/kwin/-/merge_requests/194 will fix the
> "Current screen" case.

Thanks for the quick fix!

> But for muliti-screen cases should we always take screenshots in native (not
> downscaled)  ?
> For multiscreen screenshots, this results in distorted results.
> Or Should I expose a choice, or default to non-native for multiscreen with a
> setting ?

I guess with "distorted results" you are referring to problems like shown in https://phabricator.kde.org/D25427#648841 for example, where the screenshot taken looks completely different to what the user sees?

I like the idea to have a choice between native resolution and downscaled for multi-screen cases. Or maybe always downscale and only do native screenshots on multi-screen setups when the user does a "current screen" screenshot. But I guess having an option would not hurt if it does not make the interface too complicated for the user.

Also it might be good to have some info text for each option noting the downsides of the selected one (either downscaled or looking unproportional).
Comment 22 Marvin Hagemeister 2020-08-19 16:43:53 UTC
As a user I'd expect screenshots to be always taken in the native resolution, regardless of whether I have multiple screens attached or not. I'd be confused if there is any downscaling happening behind the scenes. When doing a screenshot the point is to capture everything as is, and anything else seems to take away from that.
Comment 23 Christoph Feck 2020-08-19 16:53:59 UTC
It would help if snapshots were saved with DPI information. A viewer could then decide if the images need to be scaled.
Comment 24 Méven Car 2020-08-20 13:58:25 UTC
(In reply to Marvin Hagemeister from comment #22)
> As a user I'd expect screenshots to be always taken in the native
> resolution, regardless of whether I have multiple screens attached or not.
> I'd be confused if there is any downscaling happening behind the scenes.
> When doing a screenshot the point is to capture everything as is, and
> anything else seems to take away from that.

So I have opposite opinions, a setting/option seems to be necessary.
It will be wayland only, not-native by default (current screen is always native now so it will be a fast path).

(In reply to Christoph Feck from comment #23)
> It would help if snapshots were saved with DPI information. A viewer could
> then decide if the images need to be scaled.

That's not really possible for multiple screens with multiple scale factors...
Comment 25 Claudius Ellsel 2020-08-20 16:51:04 UTC
(In reply to Marvin Hagemeister from comment #22)
> As a user I'd expect screenshots to be always taken in the native
> resolution, regardless of whether I have multiple screens attached or not.
> I'd be confused if there is any downscaling happening behind the scenes.
> When doing a screenshot the point is to capture everything as is, and
> anything else seems to take away from that.

The problem with capturing everything "as is" is that you cannot really do that. From my understanding on multiscreen setups one large image will be created containing the content of all screens. With scaling enabled, you could either use the native resolution resulting in overlapping windows not matching for example (while they match perfectly when just viewing the screens because both have different DPIs). This is displayed in the post on Phabricator I linked to in comment #21.

To make things look as the user sees them, one has to use down- or upscaling in order to get multiple screens on one single image.

I just want to make sure you are aware of the facts, since I suspect you did not know that before? I think you agree that we at least need an option to scale in such circumstances so the user can get properly aligned result if they want to.

I think this also is the reason, why the suggestion from comment #23 will not work, since all screens are put into one single image.

(In reply to Méven Car from comment #24)
> (In reply to Marvin Hagemeister from comment #22)
> So I have opposite opinions, a setting/option seems to be necessary.
> It will be wayland only, not-native by default (current screen is always
> native now so it will be a fast path).

Sounds good to me!
Comment 26 Nate Graham 2020-11-20 14:21:30 UTC
Git commit 4a3cb5140cc58d73b1f0f0083d7f24f9f3a40b2a by Nate Graham, on behalf of Méven Car.
Committed on 20/11/2020 at 14:21.
Pushed by ngraham into branch 'release/20.12'.

Support Wayland rectangular selection HiDpi

When the drawn rectangle is on a single screen, the output image uses the screen native resolution.
When the drawn rectangle is on screens with multiple scale factor, the output image is upscaled to correspond to the screen with the hightest scale factor to keep the image undistorted.

Adds also a "scaled" full screen mode, to capture screens content downscaled to screens virtualsize allowing for undistorted content albeit loosing details.

Requires Plasma 5.19.80+
Related: bug 420863
FIXED-IN: 20.12

M  +17   -9    src/Gui/KSWidget.cpp
M  +7    -1    src/Platforms/Platform.h
M  +133  -21   src/Platforms/PlatformKWinWayland.cpp
M  +11   -2    src/Platforms/PlatformKWinWayland.h
M  +1    -1    src/Platforms/PlatformNull.cpp
M  +15   -1    src/Platforms/PlatformXcb.cpp
A  +41   -0    src/QuickEditor/ComparableQPoint.h     [License: LGPL (v2+)]
M  +274  -91   src/QuickEditor/QuickEditor.cpp
M  +15   -3    src/QuickEditor/QuickEditor.h
M  +2    -1    src/SpectacleCommon.h
M  +35   -11   src/SpectacleCore.cpp
M  +1    -0    src/SpectacleCore.h

https://invent.kde.org/graphics/spectacle/commit/4a3cb5140cc58d73b1f0f0083d7f24f9f3a40b2a
Comment 27 Nate Graham 2020-11-20 17:57:23 UTC
Verified. Woohoooooooooo!