Files
platform-external-webrtc/modules/desktop_capture/linux/egl_dmabuf.h
Jan Grulich f2177f6612 PipeWire capturer: implement proper DMA-BUFs support
Currently both KWin (KDE) and Mutter (GNOME) window managers don't
use DMA-BUFs by default, but only when client asks specifically for
them (KWin) or when experimental DMA-BUF support is enabled (Mutter).
While current implementation works just fine on integrated graphics
cards, it causes issues on dedicated GPUs (AMD and NVidia) where the
code either crashes or screensharing is slow and unusable.

To fix this, DMA-BUFs has to be opened using OpenGL context and not
being directly mmaped(). This implementation requires to use DMA-BUF
modifiers, as they are now mandatory for DMA-BUFs usage.

Documentation for this behavior can be found here:
https://gitlab.freedesktop.org/pipewire/pipewire/-/blob/master/doc/dma-buf.dox

Bug: chromium:1233417, webrtc:13137
Change-Id: I0cecf16d6bb0f576954b9e8f071cab526f7baf2c
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/227022
Commit-Queue: Tommi <tommi@webrtc.org>
Reviewed-by: Tommi <tommi@webrtc.org>
Reviewed-by: Erik Språng <sprang@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#34889}
2021-09-01 08:10:40 +00:00

59 lines
1.7 KiB
C++

/*
* Copyright 2021 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef MODULES_DESKTOP_CAPTURE_LINUX_EGL_DMABUF_H_
#define MODULES_DESKTOP_CAPTURE_LINUX_EGL_DMABUF_H_
#include <epoxy/egl.h>
#include <epoxy/gl.h>
#include <gbm.h>
#include <memory>
#include <string>
#include <vector>
#include "modules/desktop_capture/desktop_geometry.h"
namespace webrtc {
class EglDmaBuf {
public:
struct EGLStruct {
std::vector<std::string> extensions;
EGLDisplay display = EGL_NO_DISPLAY;
EGLContext context = EGL_NO_CONTEXT;
};
EglDmaBuf();
~EglDmaBuf();
std::unique_ptr<uint8_t[]> ImageFromDmaBuf(const DesktopSize& size,
uint32_t format,
uint32_t n_planes,
const int32_t* fds,
const uint32_t* strides,
const uint32_t* offsets,
uint64_t modifiers);
std::vector<uint64_t> QueryDmaBufModifiers(uint32_t format);
bool IsEglInitialized() const { return egl_initialized_; }
private:
bool egl_initialized_ = false;
int32_t drm_fd_ = -1; // for GBM buffer mmap
gbm_device* gbm_device_ = nullptr; // for passed GBM buffer retrieval
EGLStruct egl_;
};
} // namespace webrtc
#endif // MODULES_DESKTOP_CAPTURE_LINUX_EGL_DMABUF_H_