tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

egl_dmabuf.h (2111B)


      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 <EGL/egl.h>
     15 #include <EGL/eglplatform.h>
     16 #include <GL/gl.h>
     17 #include <gbm.h>
     18 
     19 #include <cstdint>
     20 #include <optional>
     21 #include <string>
     22 #include <vector>
     23 
     24 #include "modules/desktop_capture/desktop_geometry.h"
     25 
     26 namespace webrtc {
     27 
     28 class EglDmaBuf {
     29 public:
     30  struct EGLStruct {
     31    std::vector<std::string> extensions;
     32    EGLDisplay display = EGL_NO_DISPLAY;
     33    EGLContext context = EGL_NO_CONTEXT;
     34  };
     35 
     36  struct PlaneData {
     37    int32_t fd;
     38    uint32_t stride;
     39    uint32_t offset;
     40  };
     41 
     42  EglDmaBuf();
     43  ~EglDmaBuf();
     44 
     45  // Returns whether the image was successfully imported from
     46  // given DmaBuf and its parameters
     47  bool ImageFromDmaBuf(const DesktopSize& size,
     48                       uint32_t format,
     49                       const std::vector<PlaneData>& plane_datas,
     50                       uint64_t modifiers,
     51                       const DesktopVector& offset,
     52                       const DesktopSize& buffer_size,
     53                       uint8_t* data);
     54  std::vector<uint64_t> QueryDmaBufModifiers(uint32_t format);
     55 
     56  bool IsEglInitialized() const { return egl_initialized_; }
     57 
     58 private:
     59  bool GetClientExtensions(EGLDisplay dpy, EGLint name);
     60 
     61  bool egl_initialized_ = false;
     62  bool has_image_dma_buf_import_ext_ = false;
     63  int32_t drm_fd_ = -1;               // for GBM buffer mmap
     64  gbm_device* gbm_device_ = nullptr;  // for passed GBM buffer retrieval
     65 
     66  GLuint fbo_ = 0;
     67  GLuint texture_ = 0;
     68  EGLStruct egl_;
     69 
     70  std::optional<std::string> GetRenderNode();
     71 };
     72 
     73 }  // namespace webrtc
     74 
     75 #endif  // MODULES_DESKTOP_CAPTURE_LINUX_WAYLAND_EGL_DMABUF_H_