2019-11-25 03:12:06 +00:00
|
|
|
// DRM output stuff
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <xf86drm.h>
|
|
|
|
#include <xf86drmMode.h>
|
2019-12-05 09:11:52 +00:00
|
|
|
#include <assert.h>
|
2019-12-08 04:33:58 +00:00
|
|
|
#include <drm_fourcc.h>
|
2021-05-17 17:21:23 +00:00
|
|
|
#include <wayland-server-core.h>
|
2019-11-25 03:12:06 +00:00
|
|
|
|
2020-06-11 10:42:27 +00:00
|
|
|
extern "C" {
|
|
|
|
#include <libliftoff.h>
|
2019-12-03 07:19:13 +00:00
|
|
|
#include <wlr/render/dmabuf.h>
|
2021-02-01 14:08:01 +00:00
|
|
|
#include <wlr/render/drm_format_set.h>
|
2020-06-11 10:42:27 +00:00
|
|
|
}
|
2019-12-03 07:19:13 +00:00
|
|
|
|
2019-12-12 06:17:53 +00:00
|
|
|
#include "rendervulkan.hpp"
|
|
|
|
|
2019-12-05 09:11:52 +00:00
|
|
|
#include <unordered_map>
|
|
|
|
#include <utility>
|
|
|
|
#include <atomic>
|
2021-03-05 13:18:09 +00:00
|
|
|
#include <map>
|
2019-12-05 09:11:52 +00:00
|
|
|
#include <mutex>
|
|
|
|
#include <vector>
|
|
|
|
|
2019-12-03 07:04:09 +00:00
|
|
|
struct plane {
|
|
|
|
drmModePlane *plane;
|
2021-03-05 13:18:09 +00:00
|
|
|
std::map<std::string, drmModePropertyRes *> props;
|
2019-12-03 07:04:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct crtc {
|
|
|
|
drmModeCrtc *crtc;
|
2021-03-05 13:18:09 +00:00
|
|
|
std::map<std::string, drmModePropertyRes *> props;
|
2019-12-03 07:04:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct connector {
|
|
|
|
drmModeConnector *connector;
|
2021-03-05 13:18:09 +00:00
|
|
|
std::map<std::string, drmModePropertyRes *> props;
|
2019-12-03 07:04:09 +00:00
|
|
|
};
|
|
|
|
|
2020-05-19 12:05:52 +00:00
|
|
|
struct fb {
|
2020-05-19 12:25:59 +00:00
|
|
|
uint32_t id;
|
2020-05-19 12:37:46 +00:00
|
|
|
/* Client buffer, if any */
|
|
|
|
struct wlr_buffer *buf;
|
2020-05-19 12:05:52 +00:00
|
|
|
/* A FB is held if it's being used by steamcompmgr */
|
|
|
|
bool held;
|
|
|
|
/* Number of page-flips using the FB */
|
|
|
|
std::atomic< uint32_t > n_refs;
|
|
|
|
};
|
|
|
|
|
2019-11-25 03:12:06 +00:00
|
|
|
struct drm_t {
|
|
|
|
int fd;
|
2020-12-02 14:40:04 +00:00
|
|
|
|
|
|
|
uint64_t cursor_width, cursor_height;
|
2021-02-01 14:52:48 +00:00
|
|
|
bool allow_modifiers;
|
2021-03-05 13:26:30 +00:00
|
|
|
struct wlr_drm_format_set formats;
|
2019-11-25 03:12:06 +00:00
|
|
|
|
|
|
|
/* only used for atomic: */
|
|
|
|
struct plane *plane;
|
|
|
|
struct crtc *crtc;
|
|
|
|
struct connector *connector;
|
|
|
|
int crtc_index;
|
|
|
|
int kms_in_fence_fd;
|
|
|
|
int kms_out_fence_fd;
|
|
|
|
|
|
|
|
drmModeModeInfo *mode;
|
2020-05-26 08:57:57 +00:00
|
|
|
uint32_t mode_id;
|
2019-11-25 03:12:06 +00:00
|
|
|
uint32_t crtc_id;
|
|
|
|
uint32_t connector_id;
|
2019-12-03 07:04:09 +00:00
|
|
|
|
|
|
|
uint32_t plane_id;
|
2021-02-01 14:08:01 +00:00
|
|
|
struct wlr_drm_format_set plane_formats;
|
2019-12-05 09:11:52 +00:00
|
|
|
|
2020-01-06 04:22:27 +00:00
|
|
|
drmModeAtomicReq *req;
|
|
|
|
uint32_t flags;
|
|
|
|
|
|
|
|
struct liftoff_device *lo_device;
|
|
|
|
struct liftoff_output *lo_output;
|
|
|
|
struct liftoff_layer *lo_layers[ k_nMaxLayers ];
|
2020-05-26 14:29:50 +00:00
|
|
|
|
|
|
|
/* FBs in the atomic request, but not yet submitted to KMS */
|
2020-01-06 04:22:27 +00:00
|
|
|
std::vector < uint32_t > fbids_in_req;
|
2020-05-26 14:29:50 +00:00
|
|
|
/* FBs submitted to KMS, but not yet displayed on screen */
|
|
|
|
std::vector < uint32_t > fbids_queued;
|
|
|
|
/* FBs currently on screen */
|
2020-01-06 04:22:27 +00:00
|
|
|
std::vector < uint32_t > fbids_on_screen;
|
|
|
|
|
2020-05-19 12:05:52 +00:00
|
|
|
std::unordered_map< uint32_t, struct fb > map_fbid_inflightflips;
|
2019-12-05 09:11:52 +00:00
|
|
|
std::mutex free_queue_lock;
|
|
|
|
std::vector< uint32_t > fbid_free_queue;
|
2020-01-06 04:22:27 +00:00
|
|
|
|
|
|
|
std::mutex flip_lock;
|
2020-01-14 04:57:39 +00:00
|
|
|
|
|
|
|
std::atomic < uint64_t > flipcount;
|
2019-11-25 03:12:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
extern struct drm_t g_DRM;
|
|
|
|
|
2019-12-08 04:33:58 +00:00
|
|
|
extern uint32_t g_nDRMFormat;
|
|
|
|
|
2020-01-07 03:36:20 +00:00
|
|
|
extern bool g_bUseLayers;
|
2020-01-17 09:57:39 +00:00
|
|
|
extern bool g_bRotated;
|
2020-02-25 23:38:57 +00:00
|
|
|
extern bool g_bDebugLayers;
|
2020-01-07 03:36:20 +00:00
|
|
|
|
2021-07-20 13:53:15 +00:00
|
|
|
int init_drm(struct drm_t *drm, const char *device);
|
2019-12-12 06:44:52 +00:00
|
|
|
int drm_atomic_commit(struct drm_t *drm, struct Composite_t *pComposite, struct VulkanPipeline_t *pPipeline );
|
2020-05-19 12:37:46 +00:00
|
|
|
uint32_t drm_fbid_from_dmabuf( struct drm_t *drm, struct wlr_buffer *buf, struct wlr_dmabuf_attributes *dma_buf );
|
2020-05-19 12:05:52 +00:00
|
|
|
void drm_drop_fbid( struct drm_t *drm, uint32_t fbid );
|
2021-04-30 14:18:29 +00:00
|
|
|
bool drm_prepare( struct drm_t *drm, const struct Composite_t *pComposite, const struct VulkanPipeline_t *pPipeline );
|