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 {
|
2021-07-20 18:00:25 +00:00
|
|
|
uint32_t id;
|
2019-12-03 07:04:09 +00:00
|
|
|
drmModePlane *plane;
|
2021-07-28 15:02:47 +00:00
|
|
|
std::map<std::string, const drmModePropertyRes *> props;
|
2021-07-20 19:32:02 +00:00
|
|
|
std::map<std::string, uint64_t> initial_prop_values;
|
2019-12-03 07:04:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct crtc {
|
2021-07-20 18:00:25 +00:00
|
|
|
uint32_t id;
|
2019-12-03 07:04:09 +00:00
|
|
|
drmModeCrtc *crtc;
|
2021-07-28 15:02:47 +00:00
|
|
|
std::map<std::string, const drmModePropertyRes *> props;
|
2021-07-20 19:32:02 +00:00
|
|
|
std::map<std::string, uint64_t> initial_prop_values;
|
2021-07-28 15:33:20 +00:00
|
|
|
|
|
|
|
struct {
|
|
|
|
bool active;
|
|
|
|
} current, pending;
|
2019-12-03 07:04:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct connector {
|
2021-07-20 18:00:25 +00:00
|
|
|
uint32_t id;
|
2021-07-22 14:50:16 +00:00
|
|
|
char *name;
|
2019-12-03 07:04:09 +00:00
|
|
|
drmModeConnector *connector;
|
2021-09-01 11:23:12 +00:00
|
|
|
uint32_t possible_crtcs;
|
2021-07-28 15:02:47 +00:00
|
|
|
std::map<std::string, const drmModePropertyRes *> props;
|
2021-07-20 19:32:02 +00:00
|
|
|
std::map<std::string, uint64_t> initial_prop_values;
|
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
|
|
|
|
2021-09-13 16:34:27 +00:00
|
|
|
int preferred_width, preferred_height, preferred_refresh;
|
|
|
|
|
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;
|
2021-07-20 18:00:25 +00:00
|
|
|
|
|
|
|
std::vector< struct plane > planes;
|
|
|
|
std::vector< struct crtc > crtcs;
|
|
|
|
std::vector< struct connector > connectors;
|
2021-07-28 15:02:47 +00:00
|
|
|
|
|
|
|
std::map< uint32_t, drmModePropertyRes * > props;
|
2019-11-25 03:12:06 +00:00
|
|
|
|
2021-07-28 17:27:51 +00:00
|
|
|
struct plane *primary;
|
2019-11-25 03:12:06 +00:00
|
|
|
struct crtc *crtc;
|
|
|
|
struct connector *connector;
|
|
|
|
int crtc_index;
|
|
|
|
int kms_in_fence_fd;
|
|
|
|
int kms_out_fence_fd;
|
|
|
|
|
2021-07-28 17:26:31 +00:00
|
|
|
struct wlr_drm_format_set primary_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
|
|
|
|
2021-07-20 15:53:38 +00:00
|
|
|
struct {
|
|
|
|
uint32_t mode_id;
|
2021-07-28 16:09:52 +00:00
|
|
|
} current, pending;
|
2021-07-20 15:53:38 +00:00
|
|
|
|
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;
|
2021-07-27 12:09:04 +00:00
|
|
|
|
|
|
|
std::atomic < bool > paused;
|
2021-07-28 15:47:41 +00:00
|
|
|
std::atomic < bool > out_of_date;
|
2021-07-28 16:17:07 +00:00
|
|
|
std::atomic < bool > needs_modeset;
|
2021-08-25 14:20:04 +00:00
|
|
|
|
|
|
|
std::unordered_map< std::string, int > connector_priorities;
|
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;
|
2021-07-22 14:50:16 +00:00
|
|
|
extern const char *g_sOutputName;
|
2020-01-07 03:36:20 +00:00
|
|
|
|
2021-09-14 14:59:46 +00:00
|
|
|
bool init_drm(struct drm_t *drm, const char *device, int width, int height, int refresh);
|
2021-09-10 09:05:09 +00:00
|
|
|
void finish_drm(struct drm_t *drm);
|
2021-07-27 11:54:47 +00:00
|
|
|
int drm_commit(struct drm_t *drm, struct Composite_t *pComposite, struct VulkanPipeline_t *pPipeline );
|
|
|
|
int drm_prepare( struct drm_t *drm, const struct Composite_t *pComposite, const struct VulkanPipeline_t *pPipeline );
|
2021-09-02 21:52:16 +00:00
|
|
|
bool drm_poll_state(struct drm_t *drm);
|
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-07-28 17:03:30 +00:00
|
|
|
bool drm_set_connector( struct drm_t *drm, struct connector *conn );
|
2021-07-20 15:53:38 +00:00
|
|
|
bool drm_set_mode( struct drm_t *drm, const drmModeModeInfo *mode );
|
|
|
|
bool drm_set_refresh( struct drm_t *drm, int refresh );
|
2021-07-28 14:40:51 +00:00
|
|
|
bool drm_set_resolution( struct drm_t *drm, int width, int height );
|