kmsdrm: free all connector, crtc and plane memory on KMSDRM_VideoQuit().

This commit is contained in:
Manuel Alfayate Corchete 2020-08-18 01:52:15 +02:00
parent 96d555e25a
commit f79da81721
2 changed files with 65 additions and 42 deletions

View File

@ -345,8 +345,8 @@ KMSDRM_WarpMouseGlobal(int x, int y)
if (curdata->bo) { if (curdata->bo) {
int ret; int ret;
drm_atomic_movecursor(curdata, x, y); ret = drm_atomic_movecursor(curdata, x, y);
ret = drm_atomic_commit(curdata->video, SDL_TRUE); //ret = drm_atomic_commit(curdata->video, SDL_TRUE);
if (ret) { if (ret) {
SDL_SetError("drm_atomic_movecursor() failed."); SDL_SetError("drm_atomic_movecursor() failed.");
@ -401,8 +401,8 @@ KMSDRM_MoveCursor(SDL_Cursor * cursor)
/* In SDLPoP "QUIT?" menu, no more pageflips are generated, so no more atomic_commit() calls /* In SDLPoP "QUIT?" menu, no more pageflips are generated, so no more atomic_commit() calls
from SwapWindow(), causing the cursor movement requested here not to be seen on screen. from SwapWindow(), causing the cursor movement requested here not to be seen on screen.
Thus we have to do an atomic_commit() here, so requested movements are commited and seen. */ Thus we have to do an atomic_commit() here, so requested movements are commited and seen. */
drm_atomic_movecursor(curdata, mouse->x, mouse->y); ret = drm_atomic_movecursor(curdata, mouse->x, mouse->y);
ret = drm_atomic_commit(curdata->video, SDL_TRUE); //ret = drm_atomic_commit(curdata->video, SDL_TRUE);
if (ret) { if (ret) {
SDL_SetError("drm_atomic_movecursor() failed."); SDL_SetError("drm_atomic_movecursor() failed.");

View File

@ -1169,6 +1169,8 @@ cleanup:
return ret; return ret;
} }
/* The driverdata pointers, like dispdata, viddata, etc...
are freed by SDL internals, so not our job. */
void void
KMSDRM_VideoQuit(_THIS) KMSDRM_VideoQuit(_THIS)
{ {
@ -1183,12 +1185,12 @@ KMSDRM_VideoQuit(_THIS)
viddata->max_windows = 0; viddata->max_windows = 0;
viddata->num_windows = 0; viddata->num_windows = 0;
/* Restore original buffer. */ /* Restore original buffer. Probably not needed
if (viddata->drm_fd >= 0 && dispdata && dispdata->connector->connector && dispdata->crtc->crtc) { b/c DestroySurfaces also points the display plane
/***********************************************************/ to the original buffer before destrying the GBM surface. */
/* Atomic block for original crt->buffer restoration */ if (viddata->drm_fd >= 0 && dispdata && dispdata->connector->connector &&
/***********************************************************/ dispdata->crtc->crtc)
{
/* Issue sync/blocking atomic commit that points crtc to original buffer. /* Issue sync/blocking atomic commit that points crtc to original buffer.
SDL_video has already called SetDisplayMode() to set the original SDL_video has already called SetDisplayMode() to set the original
display mode at this point. display mode at this point.
@ -1196,49 +1198,70 @@ KMSDRM_VideoQuit(_THIS)
atomic_commit() call, hence we are explicitly calling atomic_commit() here. atomic_commit() call, hence we are explicitly calling atomic_commit() here.
*/ */
drm_atomic_setbuffer(_this, dispdata->display_plane, dispdata->crtc->crtc->buffer_id); drm_atomic_setbuffer(_this, dispdata->display_plane,
ret = drm_atomic_commit(_this, SDL_TRUE); dispdata->crtc->crtc->buffer_id);
/*********************/ ret = drm_atomic_commit(_this, SDL_TRUE);
/* Atomic block ends */
/*********************/
if (ret != 0) { if (ret != 0)
SDL_LogWarn(SDL_LOG_CATEGORY_VIDEO, "Could not restore original videomode"); {
} SDL_LogWarn(SDL_LOG_CATEGORY_VIDEO, "Could not restore original buffer and videomode");
}
} }
if (_this->gl_config.driver_loaded) { if (_this->gl_config.driver_loaded) {
SDL_GL_UnloadLibrary(); SDL_GL_UnloadLibrary();
} }
/**********************************************/ /* Free connector */
/* Atomic block for freeing up property sets. */ if (dispdata && dispdata->connector) {
/**********************************************/ if (dispdata->connector->connector) {
if (dispdata && dispdata->connector->props_info) { KMSDRM_drmModeFreeConnector(dispdata->connector->connector);
SDL_free(dispdata->connector->props_info); dispdata->connector->connector = NULL;
dispdata->connector->props_info = NULL; }
} if (dispdata->connector->props_info) {
if (dispdata && dispdata->crtc->props_info) { SDL_free(dispdata->connector->props_info);
SDL_free(dispdata->crtc->props_info); dispdata->connector->props_info = NULL;
dispdata->crtc->props_info = NULL; }
} SDL_free(dispdata->connector);
if (dispdata && dispdata->display_plane->props_info) {
SDL_free(dispdata->display_plane->props_info);
dispdata->display_plane->props_info = NULL;
}
/*********************/
/* Atomic block ends */
/*********************/
if (dispdata && dispdata->connector->connector != NULL) {
KMSDRM_drmModeFreeConnector(dispdata->connector->connector);
dispdata->connector = NULL; dispdata->connector = NULL;
} }
if (dispdata && dispdata->crtc->crtc != NULL) {
KMSDRM_drmModeFreeCrtc(dispdata->crtc->crtc); /* Free CRTC */
dispdata->crtc->crtc = NULL; if (dispdata && dispdata->crtc) {
if (dispdata->crtc->crtc) {
KMSDRM_drmModeFreeCrtc(dispdata->crtc->crtc);
dispdata->crtc->crtc = NULL;
}
if (dispdata->crtc->props_info) {
SDL_free(dispdata->crtc->props_info);
dispdata->crtc->props_info = NULL;
}
SDL_free(dispdata->crtc);
dispdata->crtc = NULL;
} }
/* Free main display plane */
if (dispdata && dispdata->display_plane) {
if (dispdata->display_plane->props_info) {
SDL_free(dispdata->display_plane->props_info);
dispdata->display_plane->props_info = NULL;
}
SDL_free(dispdata->display_plane);
dispdata->display_plane = NULL;
}
/* Free main cursor plane */
if (dispdata && dispdata->cursor_plane) {
if (dispdata->cursor_plane->props_info) {
SDL_free(dispdata->cursor_plane->props_info);
dispdata->cursor_plane->props_info = NULL;
}
SDL_free(dispdata->cursor_plane);
dispdata->cursor_plane = NULL;
}
/* Destroy GBM device. GBM surface is destroyed by DestroySurfaces(). */
if (viddata->gbm_dev) { if (viddata->gbm_dev) {
KMSDRM_gbm_device_destroy(viddata->gbm_dev); KMSDRM_gbm_device_destroy(viddata->gbm_dev);
viddata->gbm_dev = NULL; viddata->gbm_dev = NULL;