2021-01-30 16:25:05 +00:00
|
|
|
#pragma once
|
2021-10-10 07:09:34 +00:00
|
|
|
#include "types.h"
|
2021-01-30 16:25:05 +00:00
|
|
|
#include <array>
|
|
|
|
#include <optional>
|
|
|
|
#include <xf86drm.h>
|
|
|
|
#include <xf86drmMode.h>
|
|
|
|
|
|
|
|
class DRMDisplay
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
DRMDisplay(int card = -1);
|
|
|
|
~DRMDisplay();
|
|
|
|
|
2021-04-07 17:02:24 +00:00
|
|
|
static bool GetCurrentMode(u32* width, u32* height, float* refresh_rate, int card = -1, int connector = -1);
|
|
|
|
|
2021-02-13 11:25:45 +00:00
|
|
|
bool Initialize(u32 width, u32 height, float refresh_rate);
|
2021-01-30 16:25:05 +00:00
|
|
|
|
2021-06-21 12:04:59 +00:00
|
|
|
/// Restores the buffer saved at startup.
|
|
|
|
void RestoreBuffer();
|
|
|
|
|
2021-01-30 16:25:05 +00:00
|
|
|
int GetCardID() const { return m_card_id; }
|
|
|
|
int GetCardFD() const { return m_card_fd; }
|
|
|
|
u32 GetWidth() const { return m_mode->hdisplay; }
|
|
|
|
u32 GetHeight() const { return m_mode->vdisplay; }
|
2021-04-02 14:55:09 +00:00
|
|
|
float GetRefreshRate() const
|
|
|
|
{
|
|
|
|
return (static_cast<float>(m_mode->clock) * 1000.0f) /
|
|
|
|
(static_cast<float>(m_mode->htotal) * static_cast<float>(m_mode->vtotal));
|
|
|
|
}
|
2021-01-30 16:25:05 +00:00
|
|
|
|
2021-02-13 14:52:18 +00:00
|
|
|
u32 GetModeCount() const { return m_connector->count_modes; }
|
|
|
|
u32 GetModeWidth(u32 i) const { return m_connector->modes[i].hdisplay; }
|
|
|
|
u32 GetModeHeight(u32 i) const { return m_connector->modes[i].vdisplay; }
|
|
|
|
float GetModeRefreshRate(u32 i) const
|
|
|
|
{
|
|
|
|
return (static_cast<float>(m_connector->modes[i].clock) * 1000.0f) /
|
|
|
|
(static_cast<float>(m_connector->modes[i].htotal) * static_cast<float>(m_connector->modes[i].vtotal));
|
|
|
|
}
|
|
|
|
|
2021-01-30 16:25:05 +00:00
|
|
|
std::optional<u32> AddBuffer(u32 width, u32 height, u32 format, u32 handle, u32 pitch, u32 offset);
|
|
|
|
void RemoveBuffer(u32 fb_id);
|
|
|
|
void PresentBuffer(u32 fb_id, bool wait_for_vsync);
|
|
|
|
|
|
|
|
private:
|
|
|
|
enum : u32
|
|
|
|
{
|
|
|
|
MAX_BUFFERS = 5
|
|
|
|
};
|
|
|
|
|
2021-02-13 11:25:45 +00:00
|
|
|
bool TryOpeningCard(int card, u32 width, u32 height, float refresh_rate);
|
2021-01-30 16:25:05 +00:00
|
|
|
|
|
|
|
int m_card_id = 0;
|
|
|
|
int m_card_fd = -1;
|
|
|
|
u32 m_crtc_id = 0;
|
2021-02-13 14:52:18 +00:00
|
|
|
|
|
|
|
drmModeRes* m_resources = nullptr;
|
2021-01-30 16:25:05 +00:00
|
|
|
drmModeConnector* m_connector = nullptr;
|
|
|
|
drmModeModeInfo* m_mode = nullptr;
|
2021-06-21 12:04:59 +00:00
|
|
|
|
|
|
|
drmModeCrtc* m_prev_crtc = nullptr;
|
2021-01-30 16:25:05 +00:00
|
|
|
};
|