DRMDisplay: Restore previous framebuffer on shutdown
This commit is contained in:
parent
b2e8aa2d30
commit
9f6c3c8d44
|
@ -19,6 +19,10 @@ DRMDisplay::DRMDisplay(int card /*= 1*/) : m_card_id(card) {}
|
|||
|
||||
DRMDisplay::~DRMDisplay()
|
||||
{
|
||||
// restore original buffer
|
||||
if (m_prev_crtc)
|
||||
RestoreBuffer();
|
||||
|
||||
if (m_connector)
|
||||
drmModeFreeConnector(m_connector);
|
||||
|
||||
|
@ -90,6 +94,18 @@ bool DRMDisplay::Initialize(u32 width, u32 height, float refresh_rate)
|
|||
return TryOpeningCard(m_card_id, width, height, refresh_rate);
|
||||
}
|
||||
|
||||
void DRMDisplay::RestoreBuffer()
|
||||
{
|
||||
if (m_prev_crtc)
|
||||
{
|
||||
u32 connector_id = m_connector->connector_id;
|
||||
drmModeSetCrtc(m_card_fd, m_prev_crtc->crtc_id, m_prev_crtc->buffer_id, m_prev_crtc->x, m_prev_crtc->y,
|
||||
&connector_id, 1, &m_prev_crtc->mode);
|
||||
drmModeFreeCrtc(m_prev_crtc);
|
||||
m_prev_crtc = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
bool DRMDisplay::TryOpeningCard(int card, u32 width, u32 height, float refresh_rate)
|
||||
{
|
||||
if (m_card_fd >= 0)
|
||||
|
@ -201,6 +217,7 @@ bool DRMDisplay::TryOpeningCard(int card, u32 width, u32 height, float refresh_r
|
|||
drmModeFreeResources(resources);
|
||||
|
||||
m_card_id = card;
|
||||
m_prev_crtc = drmModeGetCrtc(m_card_fd, m_crtc_id);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -15,6 +15,9 @@ public:
|
|||
|
||||
bool Initialize(u32 width, u32 height, float refresh_rate);
|
||||
|
||||
/// Restores the buffer saved at startup.
|
||||
void RestoreBuffer();
|
||||
|
||||
int GetCardID() const { return m_card_id; }
|
||||
int GetCardFD() const { return m_card_fd; }
|
||||
u32 GetWidth() const { return m_mode->hdisplay; }
|
||||
|
@ -53,4 +56,6 @@ private:
|
|||
drmModeRes* m_resources = nullptr;
|
||||
drmModeConnector* m_connector = nullptr;
|
||||
drmModeModeInfo* m_mode = nullptr;
|
||||
|
||||
drmModeCrtc* m_prev_crtc = nullptr;
|
||||
};
|
||||
|
|
|
@ -21,6 +21,8 @@ ContextEGLGBM::~ContextEGLGBM()
|
|||
Assert(!m_current_present_buffer);
|
||||
#endif
|
||||
|
||||
m_drm_display.RestoreBuffer();
|
||||
|
||||
// We have to destroy the context before the surface/device.
|
||||
// Leaving it to the base class would be too late.
|
||||
DestroySurface();
|
||||
|
|
Loading…
Reference in New Issue