Commit graph

106 commits

Author SHA1 Message Date
David Edmundson
10ed34bc9d Avoid painting unchanged scene layers
Currently when we move the mouse the one render loop triggers a repaint.
When the cursor layer needs a new update we end up in the compositor
repainting the main content.

Even though painting should mostly no-op it still goes through all
existing items and effects to collect damage, still potentially making
the GL context current which could stall. A waste when we know we
haven't got anything to do. It's enough to cause noticable mouse lag on
some hardware.

Co-authored-by: Vlad Zahorodnii <vlad.zahorodnii@kde.org>
2023-08-28 11:38:18 +00:00
Xaver Hugl
fe1d4ffbc5 move cursor rendering from the backends to the compositor 2023-08-28 11:10:41 +00:00
Vlad Zahorodnii
75275bbc8f core: Move dmaBufAttributesForBo() to gbmgraphicsbufferallocator.cpp 2023-08-23 17:13:07 +03:00
Vlad Zahorodnii
dabf3038f0 core: Drop dmabuf texture creation api in OutputBackend
It never belonged in the OutputBackend, but we also didn't have a better
place when the relevant code had been added.

With the introduction of graphics buffer allocators, it's no longer the
case.
2023-08-23 17:13:07 +03:00
Xaver Hugl
44937136cd backends: record GPU render time
This should make it much less likely for KWin to miss frames
2023-08-23 10:51:19 +00:00
Vlad Zahorodnii
54e2a5761c wayland: Use correct bounds size when computing the source box
The buffer transform specifies a transform from the buffer coordinate
space to the surface coordinate space.

The inverse buffer transform specifies a transform from the surface
coordinate space to the buffer coordinate space.

OutputTransform::map(QRect, QSizeF) expects both arguments to be in the
same coordinate space.

In case of SurfaceInterfacePrivate::computeSourceBox(), both should be
scaled surface coordinates so bufferTransform.inverted() maps the source
rect to the proper buffer coordinate space.
2023-08-21 12:27:06 +00:00
Xaver Hugl
56aab75a57 plugins/qpa: handle modifiers more correctly
Instead of hardcoding ARGB8888 and using implicit modifiers, look through
the list of available formats and modifiers and pick a match that egl will
actually accept.
2023-08-18 13:17:38 +00:00
Xaver Hugl
bf17d6388c backends/drm: don't commit buffers that are still being rendered to
This allows updating the commit until the next vblank happens, making the
effect of the dropped frame less visible
2023-08-07 18:51:04 +00:00
Vlad Zahorodnii
1687183d4d qpa: Port OpenGL code path to GraphicsBuffer
This allows us to unify graphics buffer handling for normal wayland
windows and internal windows.
2023-08-07 13:17:18 +00:00
Vlad Zahorodnii
76335880bf core: Expose graphics buffer allocator in RenderBackend
It can be used by other components to allocate buffers on the
compositing render device. For example, QPA.
2023-08-07 13:17:18 +00:00
Xaver Hugl
53c2b8c68b port most remaining uses of EGLDisplay and EGLContext to their wrappers 2023-07-29 22:07:46 +00:00
Vlad Zahorodnii
84149945f6 core: Keep shared memory graphics buffer memory map persistent
This simplifies the logic a bit if a graphics buffer is mapped both by
the SurfacePixmap and QPA.
2023-07-26 07:29:27 +00:00
Vlad Zahorodnii
9a2355339c core: Rework OutputTransform type
In some cases, it's desired to know what the inverse transform of a
given output transform is. It's possible to make it work by providing
helper functions, but we tend to avoid doing so.

This change converts the OutputTransform from an enum to a class so it's
possible to have both data + methods in the same type. Unfortunately,
unlike Rust, C++ provides no way to attach methods to enums, classes and
structs is the only way to go.
2023-07-25 12:09:19 +03:00
Vlad Zahorodnii
637e3a6389 core: Move Output::Transform enum to KWin namespace
Being in the KWin namespace has a couple of advantages: the enum can be
forward declared, and the transform can be replaced with a slightly more
complex but useful type.
2023-07-25 12:09:01 +03:00
Vlad Zahorodnii
9e898c0e68 scene: Expand surface damage if the surface is scaled
If the surface item's contents is scaled, i.e. its scale factor doesn't
match the output's scale, GL_LINEAR will be applied to smooth the
contents. The unfortunate thing is that it's possible some of the
changed pixels will bleed to the neighbor ones.

In order to handle that scenario better, this change makes the
SurfaceItem expand the damage if there's scale factor mismatch.

bufferSourceBox and bufferTransform properties were introduced to detect
if the surface contents is going to be scaled. bufferSourceBox covers
both crop transform from wp_viewport and scale factor from wl_surface.
bufferTransform is same as wl_surface's buffer transform property.
2023-07-25 12:09:01 +03:00
Vlad Zahorodnii
b98ffaf785 wayland: Introduce SurfaceInterface::bufferSourceBox()
The bufferSourceBox provides a way to get the source region of the
attached buffer. It can be used to compute the effective scale factor
when using wp_viewport.
2023-07-25 12:09:01 +03:00
Laurent Montel
8c51619c1e Remove extra ; 2023-07-18 11:51:09 +00:00
Laurent Montel
b823747c3b Add explicit moc includes to sources for moc-covered headers
* speeds up incremental builds as changes to a header will not always
  need the full mocs_compilation.cpp for all the target's headers rebuild,
  while having a moc file sourced into a source file only adds minor
  extra costs, due to small own code and the used headers usually
  already covered by the source file, being for the same class/struct
* seems to not slow down clean builds, due to empty mocs_compilation.cpp
  resulting in those quickly processed, while the minor extra cost of the
  sourced moc files does not outweigh that in summary.
  Measured times actually improved by some percent points.
  (ideally CMake would just skip empty mocs_compilation.cpp & its object
  file one day)
* enables compiler to see all methods of a class in same compilation unit
  to do some sanity checks
* potentially more inlining in general, due to more in the compilation unit
* allows to keep using more forward declarations in the header, as with the
  moc code being sourced into the cpp file there definitions can be ensured
  and often are already for the needs of the normal class methods
2023-07-15 08:40:49 +00:00
Vlad Zahorodnii
147b862d7f core: Add GraphicsBufferRef
It's a helper to make GraphicsBuffer refcounting less error prone.
2023-07-11 11:55:53 +00:00
Vlad Zahorodnii
fc02990b77 core: Hide GraphicsBuffer implementations
The user code should not rely on concrete GraphicsBuffer
implementations, but instead of generic abstractions.
2023-07-05 11:14:12 +03:00
Xaver Hugl
457f966bf1 core/graphicsbuffer: correct stride handling with buffer mappings
The stride of the mapping is not necessarily the same as the stride of the
underlying buffer
2023-07-04 17:33:38 +02:00
Aleix Pol Gonzalez
6fd1867681 Drop options.h include
Don't include options.h from renderloop.h. This way it can be included
from outside the project without dragging all of the KWin dependencies.
2023-07-04 08:22:43 +00:00
Vlad Zahorodnii
80a3fea9f8 core: Allow mapping shared memory graphics buffer
Shared memory graphics buffers can be mapped, so implement
GraphicsBuffer::map() and GraphicsBuffer::unmap().
2023-07-01 12:22:28 +00:00
Xaver Hugl
7872e7cb22 backends/drm: hardcode a list of known formats instead of querying egl for information on drm formats 2023-06-20 18:24:37 +02:00
Vlad Zahorodnii
dc70be404a core: Provide own dumb graphics buffer allocator
If a gbm_bo is allocated with GBM_BO_USE_WRITE, it will be backed by a
dumb buffer under the hood. However, it seems like neither gbm_bo_get_fd()
nor gbm_bo_get_plane_fd() would return valid file descriptors, which are
required to fill in DmaBufAttributes.

As an interim solution, this change makes the GbmGraphicsBufferAllocator
allocate dumb buffers on its own rather than delegate it to gbm.
2023-06-19 22:43:01 +03:00
Vlad Zahorodnii
082301920e backends/drm: Port to GraphicsBuffer
This change ports the drm backend to the GraphicsBuffer and
GraphicsBufferAllocator.

The main motivation is to unify graphics buffer abstractions across
various backends and to prepare it for output layers, which could be
nicer if we could have direct control over the buffers.
2023-06-19 22:42:58 +03:00
Vlad Zahorodnii
0a7bfcf1a3 backends: Remove concrete graphics buffer types 2023-06-19 16:47:26 +03:00
Vlad Zahorodnii
ea639ad170 core: Add GraphicsBuffer map flags
This allows to specify whether the graphics buffer will be read or
written. It's mainly needed to map our APIs to gbm APIs.
2023-06-19 16:47:26 +03:00
Vlad Zahorodnii
9bbe0cc4ac core: Allow GbmGraphicsBufferAllocator allocate dumb buffers
The drm backend needs to allocate both dmabuf and dumb buffers, for
example for multi-gpu import.

Allowing GbmGraphicsBufferAllocator to allocate dumb buffers allows us
to avoid using several buffer allocators in the drm backend.
2023-06-19 16:47:26 +03:00
Vlad Zahorodnii
7782cb6853 core: Add GraphicsBufferOptions::software
The software flag indicates whether the graphics buffer allocator needs
to allocate a buffer suitable for software rendering. Its intended usage
is to allow the gbm allocator to allocate both dmabuf and dumb buffers.
2023-06-19 16:47:26 +03:00
Vlad Zahorodnii
1833d790f5 core: Introduce GraphicsBufferOptions
GraphicsBufferOptions describes the properties of the allocated graphics
buffer.
2023-06-19 16:47:26 +03:00
Vlad Zahorodnii
bdc14f247e core: Allow allocating linear gbm buffers with implicit modifier 2023-06-19 16:47:26 +03:00
Vlad Zahorodnii
f579b073c9 core: Change type of DmaBufAttributes::{pitch,offset}
Change it to uint32_t[] to match drmModeAddFB() API.
2023-06-19 16:47:26 +03:00
Vlad Zahorodnii
f1d6366d4a core: Introduce GraphicsBufferView
GraphicsBufferView provides a way to map the contents of a graphics
buffer as an image.
2023-06-08 06:22:46 +00:00
Vlad Zahorodnii
006ab40e44 wayland: Make LinuxDmaBufV1ClientBuffer private
dmabuf related code can rely on DmaBufAttributes instead, so let's make
LinuxDmaBufV1ClientBuffer private to make graphics buffer handling
generic.
2023-05-23 09:39:19 +00:00
Xaver Hugl
afc5567651 Implement initial support for color management and HDR
This is done by converting from the sRGB + gamma 2.2 input from clients
to linear with the color space of the output (BT.709 or BT2020 atm) in
a shadow buffer, and then convert from the shadow buffer to the transfer
function the output needs (sRGB or PQ).
2023-05-15 17:01:03 +00:00
Vlad Zahorodnii
380aaab2cc Fix deleting GraphicsBuffer twice
When GraphicsBuffer::dropped() is emitted, the buffer can be
unreferenced. If that's the case, the GraphicsBuffer will be deleted
twice: first in GraphicsBuffer::unref(), the second time in drop().

In order to address the issue, this change gets rid of the
GraphicsBuffer::dropped() signal, so it's always guaranteed that the
buffer stays alive until the reference count is checked.

The GraphicsBuffer::dropped() signal is used to remove the mapping
between wl_resource and ShmClientBuffer when the corresponding
wl_shm_buffer object is destroyed. On the other hand, we could perform
such cleanup when calling drop() too. This code can be further improved
by reimplementing wl-shm, which we need to do at some point in the
future.
2023-05-09 16:29:00 +00:00
Vlad Zahorodnii
e6b5cf283e core: Batch pointer input device events
This change introduces InputDevice::pointerFrame(). The main motivation
behind it is to allow batching multiple pointer events within a single
event frame.

BUG: 454428
2023-05-05 10:27:08 +00:00
Vlad Zahorodnii
ce2b4c0bee {core,backends/wayland}: Refactor shm buffer allocator 2023-05-02 13:14:30 +00:00
Vlad Zahorodnii
f410819fff Remove "Default implementation ..." comments
These methods are not virtual anymore.
2023-04-28 14:51:01 +00:00
Alexander Volkov
64ce247104 Use non-rotated physical size of an output when required
1. In wl_output and kde_output_device_v2 protocols.
This should fix dpi calculation in
KScreen::Generator::bestScaleForOutput() when panel_orientation
is set to rotate a screen by 90 or 270 degrees.

2. When comparing with physical size of libinput device.

3. In calculations with mode sizes which are not rotated.

This change makes Output::physicalSize() return the raw
physical size, which is used in most of cases. It should
be rotated manually if needed.
2023-04-28 13:41:00 +00:00
Vlad Zahorodnii
e9feaefa4b Handling failing to export GEM handle to prime fd
If gbm_bo_get_fd_for_plane() or gbm_bo_get_fd() fails, ensure that the
gbm buffer allocator properly handles it and doesn't return a
GraphicsBuffer object.
2023-04-24 11:08:04 +03:00
Vlad Zahorodnii
67b898b803 Move DmaBufAttributes struct to GraphicsBuffer header
The main motivation is to avoid scattering graphics buffer things around
kwin.

DmaBufParams struct has been moved to the OutputBackend, but with the
introduction of buffer allocators, we need to port screencasting code to
the new abstractions some time in the future.
2023-04-21 06:38:58 +00:00
Vlad Zahorodnii
232bcc5d82 wayland: Drop support for linux dmabuf buffer flags
A client can specify the following flags when creating a linux dmabuf
client buffer:

- y_invert
- interlaced
- bottom_first

Only the y_invert flag is supported by kwin. The interlaced and the
bottom_first flags are ignored. On the other hand, most clients don't
specify the dmabuf flags. For example, neither EGL nor Vulkan WSIs
use the y_invert flag.

The y_invert flag is undesired because it also blocks optimizations such
as direct scanout because DRM assumes that the origin is in the top left
corner.

Therefore, this change drops the support for linux dmabuf flags. From
the protocol perspective, this is fine. It can be viewed as buffer
import failing with the specified flags.
2023-04-19 12:29:33 +03:00
Vlad Zahorodnii
99af2aa726 core: Move DmaBufAttributes getter to GraphicsBuffer
LinuxDmaBufV1ClientBuffer contains properties (formats, and flags) that
are not available in the base GraphicsBuffer type and there's no reason
to move it there.

In order to get rid of those properties (and eventually hide the
LinuxDmaBufV1ClientBuffer type from the public api), this change adds a
DmaBufAttributes getter in the GraphicsBuffer.
2023-04-19 07:29:38 +00:00
Vlad Zahorodnii
103d8d8abe {core,backends/wayland}: Refactor gbm buffer allocator 2023-04-15 10:21:42 +00:00
Vlad Zahorodnii
3ac4f8a7dc core: Introduce base GraphicsBuffer
Currently, there exists the separation between the buffers provided by
the clients and the buffers created by the compositor.

In hindsight, this separation is not great because it leads to
specialized code paths in the output backend. For example, we have a
separate code path for direct scanout and presenting composited frame.
But you could view the latter case as "direct scanout of a compositor
buffer".

The main idea behind the buffer type is to provide a base buffer type
for client buffers and composited frame buffers (not drm fbs) that we
could pass around, import as textures, etc.
2023-04-15 10:21:42 +00:00
Xaver Hugl
ab7286fad1 platformsupport/scenes: move egl context into a separate class 2023-04-12 15:01:51 +02:00
Xaver Hugl
48fb07b367 platformsupport/scenes: move egldisplay code into a helper class 2023-04-12 14:57:49 +02:00
Vlad Zahorodnii
466868f5d4 wayland: Refactor linux-dmabuf buffer management
At the moment, the render backend provides its specific implementation
of LinuxDmaBufV1ClientBuffer. This has some of its limitations. For
example, due to the strong coupling, compositing restarts must be
handled carefully. It's hard to have a generic code path to import
dmabufs, which would be nice to have in order to unify graphics buffer
allocation across various backends; currently, it's all scattered.

To make the code simpler, this change drops the commented out YUV import
code path for now. Given that Mesa implicitly handles it, the need for
it is no longer so urgent.
2023-04-11 07:59:28 +00:00