wayland: Add support for zwp_linux_dmabuf
Needs ReviewPublic

Authored by fredrik on Feb 22 2018, 5:40 PM.

Details

Summary

This adds support for LinuxDmabufUnstableV1Interface in kwin.

Test Plan

I asked Marco to test it with a driver that supports modifiers, and he confirmed that it works.
I have also checked that kwin still works with drivers that don't support modifiers.

Test results before (6 failures):

The following tests FAILED:

30 - kwin-testLockScreen (Failed)
39 - kwin-testPointerInput (Failed)
57 - kwin-testSceneOpenGL-waylandonly (Failed)
71 - kwin-testKeyboardLayout (Failed)
74 - kwin-testKeymapCreationFailure-waylandonly (Failed)
88 - kwin-testColorCorrectNightColor-waylandonly (Failed)

Test results after (8 failures):

The following tests FAILED:

30 - kwin-testLockScreen (Failed)
39 - kwin-testPointerInput (Failed)
59 - kwin-testSceneOpenGLES-waylandonly (Failed)
60 - kwin-testNoXdgRuntimeDir (Failed)
61 - kwin-testNoXdgRuntimeDir-waylandonly (Failed)
71 - kwin-testKeyboardLayout (Failed)
72 - kwin-testKeyboardLayout-waylandonly (Failed)
74 - kwin-testKeymapCreationFailure-waylandonly (Failed)

I'm not sure what to make of this, but at least some of these failures are spurious.

Diff Detail

Repository
R108 KWin
Lint
Lint Skipped
Unit
Unit Tests Skipped
fredrik created this revision.Feb 22 2018, 5:40 PM
Restricted Application added a project: KWin. · View Herald TranscriptFeb 22 2018, 5:40 PM
Restricted Application added subscribers: kwin, plasma-devel. · View Herald Transcript
fredrik requested review of this revision.Feb 22 2018, 5:40 PM
Restricted Application edited projects, added Plasma; removed KWin. · View Herald TranscriptFeb 22 2018, 5:40 PM

Concerning the tests: the ones requiring OpenGL work best if module vgem is loaded. That normally makes them pass. The tests regarding keyboard layout need env variable XDG_DEFAULT_LAYOUT being unset or on us.

Restricted Application edited projects, added KWin; removed Plasma. · View Herald TranscriptFeb 22 2018, 6:58 PM
fredrik edited projects, added Plasma; removed KWin.Feb 23 2018, 3:36 PM

Concerning the tests: the ones requiring OpenGL work best if module vgem is loaded. That normally makes them pass. The tests regarding keyboard layout need env variable XDG_DEFAULT_LAYOUT being unset or on us.

Those results are with vgem loaded, and XDG_DEFAULT_LAYOUT is not set.

Restricted Application edited projects, added KWin; removed Plasma. · View Herald TranscriptFeb 23 2018, 3:36 PM
anthonyfieroni added inline comments.
platformsupport/scenes/opengl/abstract_egl_backend.cpp
117

Call delete dmabuf will have same effect.

738

This function is useless.

Restricted Application edited projects, added Plasma; removed KWin. · View Herald TranscriptFeb 23 2018, 6:11 PM
Restricted Application edited projects, added KWin; removed Plasma. · View Herald TranscriptFeb 23 2018, 8:29 PM

An issue that this patch does not fully address is switching compositing backends at runtime.

Buffers are imported by the scene. The scene allocates and returns a subclassed LinuxDmabuf::Buffer that contains the file descriptors and backend specific objects, such as EGL images. When the compositing backend is destroyed, the EGL images are also destroyed, but the buffers survive. The new backend could use the file descriptors to re-import the buffers, if the buffer class wasn't specific to the old backend.

A possible solution to this is a shared Buffer class (in platformsupport/scenes/common?):

    ...
private:
    ...
    QVector<Plane> planes;
    EGLimage eglImage;
    VkImage vulkanImage;
    VkImageView imageView;
    VkDeviceMemory deviceMemory;
};

Or a SceneBufferData object, created and destroyed by the scene:

private:
    ...
    QVector<Plane> planes;
    SceneBufferData *sceneData;
};

But even with a shared class there are no guarantees that a re-import is possible, since the new backend might not support the same formats and/or modifiers. So I don't know if runtime switching is something that should be expected to work.

platformsupport/scenes/opengl/abstract_egl_backend.cpp
117

No, it will not. It will leave a dangling pointer in the wl_resource, which will result in a double-free when the client deletes the buffer. Or a segfault the next time it tries to attach the buffer to a surface.

I will expand on this in a separate comment.

fredrik updated this revision to Diff 29331.Mar 12 2018, 2:07 PM

Import the context.

Do typedefs for KWayland::Server::LinuxDmabuf in files where you use it more than once.

platformsupport/scenes/opengl/abstract_egl_backend.cpp
346

Name should be more descriptive in relation to functionality, also it's not a signal, so "aboutTo" imo not recommended.

Suggestion: removeDmabufBuffer

platformsupport/scenes/opengl/abstract_egl_backend.h
100

Why QLinkedList? It should be no better than QList for the removeOne call. For this better use QSet.

135

Why is it necessary to export?

An issue that this patch does not fully address is switching compositing backends at runtime.

Do we support that at all? The backend is set at startup. Don't think you can change this later on.

An issue that this patch does not fully address is switching compositing backends at runtime.

Do we support that at all? The backend is set at startup. Don't think you can change this later on.

That is the question I'm asking.

platformsupport/scenes/opengl/abstract_egl_backend.h
100

I believe the use of QList is discouraged in new code, but you are right about QSet being a better choice in this case.

135

I guess it isn't. I was thinking at the time that someone might want to use this class in a class derived from AbstractEglBackend or AbstractEglTexture.

fredrik updated this revision to Diff 29953.Mar 19 2018, 11:47 PM

Fix issues pointed out by romangg.

fredrik marked 3 inline comments as done.Mar 19 2018, 11:49 PM
zzag added a subscriber: zzag.Sep 17 2018, 8:08 AM

Any update on this?