1 /* 2 * Copyright 2021 The WebRTC project authors. All Rights Reserved. 3 * 4 * Use of this source code is governed by a BSD-style license 5 * that can be found in the LICENSE file in the root of the source 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 11 #ifndef MODULES_DESKTOP_CAPTURE_LINUX_WAYLAND_EGL_DMABUF_H_ 12 #define MODULES_DESKTOP_CAPTURE_LINUX_WAYLAND_EGL_DMABUF_H_ 13 14 #include <epoxy/egl.h> 15 #include <epoxy/gl.h> 16 #include <gbm.h> 17 18 #include <memory> 19 #include <string> 20 #include <vector> 21 22 #include "absl/types/optional.h" 23 #include "modules/desktop_capture/desktop_geometry.h" 24 25 namespace webrtc { 26 27 class EglDmaBuf { 28 public: 29 struct EGLStruct { 30 std::vector<std::string> extensions; 31 EGLDisplay display = EGL_NO_DISPLAY; 32 EGLContext context = EGL_NO_CONTEXT; 33 }; 34 35 struct PlaneData { 36 int32_t fd; 37 uint32_t stride; 38 uint32_t offset; 39 }; 40 41 EglDmaBuf(); 42 ~EglDmaBuf(); 43 44 std::unique_ptr<uint8_t[]> ImageFromDmaBuf( 45 const DesktopSize& size, 46 uint32_t format, 47 const std::vector<PlaneData>& plane_datas, 48 uint64_t modifiers); 49 std::vector<uint64_t> QueryDmaBufModifiers(uint32_t format); 50 IsEglInitialized()51 bool IsEglInitialized() const { return egl_initialized_; } 52 53 private: 54 bool GetClientExtensions(EGLDisplay dpy, EGLint name); 55 56 bool egl_initialized_ = false; 57 bool has_image_dma_buf_import_ext_ = false; 58 int32_t drm_fd_ = -1; // for GBM buffer mmap 59 gbm_device* gbm_device_ = nullptr; // for passed GBM buffer retrieval 60 61 EGLStruct egl_; 62 63 absl::optional<std::string> GetRenderNode(); 64 }; 65 66 } // namespace webrtc 67 68 #endif // MODULES_DESKTOP_CAPTURE_LINUX_WAYLAND_EGL_DMABUF_H_ 69