Skip to content
Permalink
Browse files

kmsdrm: merge patches from Ozkan Sezer for removing c-99'isms and rai…

…sing libgbm version reqeriments.
  • Loading branch information
vanfanel committed Sep 26, 2020
1 parent 7ad7156 commit 78c274cb5d262237647785405221a6fa03b393e2
Showing with 44 additions and 35 deletions.
  1. +16 −16 configure
  2. +2 −2 configure.ac
  3. +3 −2 src/video/kmsdrm/SDL_kmsdrmmouse.c
  4. +23 −15 src/video/kmsdrm/SDL_kmsdrmvideo.c
pkg_cv_LIBDRM_CFLAGS="$LIBDRM_CFLAGS"
elif test -n "$PKG_CONFIG"; then
if test -n "$PKG_CONFIG" && \
{ { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"libdrm >= 2.4.46\""; } >&5
($PKG_CONFIG --exists --print-errors "libdrm >= 2.4.46") 2>&5
{ { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"libdrm >= 2.4.82\""; } >&5
($PKG_CONFIG --exists --print-errors "libdrm >= 2.4.82") 2>&5
ac_status=$?
$as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
test $ac_status = 0; }; then
pkg_cv_LIBDRM_CFLAGS=`$PKG_CONFIG --cflags "libdrm >= 2.4.46" 2>/dev/null`
pkg_cv_LIBDRM_CFLAGS=`$PKG_CONFIG --cflags "libdrm >= 2.4.82" 2>/dev/null`
else
pkg_failed=yes
fi
pkg_cv_LIBDRM_LIBS="$LIBDRM_LIBS"
elif test -n "$PKG_CONFIG"; then
if test -n "$PKG_CONFIG" && \
{ { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"libdrm >= 2.4.46\""; } >&5
($PKG_CONFIG --exists --print-errors "libdrm >= 2.4.46") 2>&5
{ { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"libdrm >= 2.4.82\""; } >&5
($PKG_CONFIG --exists --print-errors "libdrm >= 2.4.82") 2>&5
ac_status=$?
$as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
test $ac_status = 0; }; then
pkg_cv_LIBDRM_LIBS=`$PKG_CONFIG --libs "libdrm >= 2.4.46" 2>/dev/null`
pkg_cv_LIBDRM_LIBS=`$PKG_CONFIG --libs "libdrm >= 2.4.82" 2>/dev/null`
else
pkg_failed=yes
fi
_pkg_short_errors_supported=no
fi
if test $_pkg_short_errors_supported = yes; then
LIBDRM_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors "libdrm >= 2.4.46" 2>&1`
LIBDRM_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors "libdrm >= 2.4.82" 2>&1`
else
LIBDRM_PKG_ERRORS=`$PKG_CONFIG --print-errors "libdrm >= 2.4.46" 2>&1`
LIBDRM_PKG_ERRORS=`$PKG_CONFIG --print-errors "libdrm >= 2.4.82" 2>&1`
fi
# Put the nasty error message in config.log where it belongs
echo "$LIBDRM_PKG_ERRORS" >&5
pkg_cv_LIBGBM_CFLAGS="$LIBGBM_CFLAGS"
elif test -n "$PKG_CONFIG"; then
if test -n "$PKG_CONFIG" && \
{ { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"gbm >= 9.0.0\""; } >&5
($PKG_CONFIG --exists --print-errors "gbm >= 9.0.0") 2>&5
{ { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"gbm >= 17.1.0\""; } >&5
($PKG_CONFIG --exists --print-errors "gbm >= 17.1.0") 2>&5
ac_status=$?
$as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
test $ac_status = 0; }; then
pkg_cv_LIBGBM_CFLAGS=`$PKG_CONFIG --cflags "gbm >= 9.0.0" 2>/dev/null`
pkg_cv_LIBGBM_CFLAGS=`$PKG_CONFIG --cflags "gbm >= 17.1.0" 2>/dev/null`
else
pkg_failed=yes
fi
pkg_cv_LIBGBM_LIBS="$LIBGBM_LIBS"
elif test -n "$PKG_CONFIG"; then
if test -n "$PKG_CONFIG" && \
{ { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"gbm >= 9.0.0\""; } >&5
($PKG_CONFIG --exists --print-errors "gbm >= 9.0.0") 2>&5
{ { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"gbm >= 17.1.0\""; } >&5
($PKG_CONFIG --exists --print-errors "gbm >= 17.1.0") 2>&5
ac_status=$?
$as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
test $ac_status = 0; }; then
pkg_cv_LIBGBM_LIBS=`$PKG_CONFIG --libs "gbm >= 9.0.0" 2>/dev/null`
pkg_cv_LIBGBM_LIBS=`$PKG_CONFIG --libs "gbm >= 17.1.0" 2>/dev/null`
else
pkg_failed=yes
fi
_pkg_short_errors_supported=no
fi
if test $_pkg_short_errors_supported = yes; then
LIBGBM_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors "gbm >= 9.0.0" 2>&1`
LIBGBM_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors "gbm >= 17.1.0" 2>&1`
else
LIBGBM_PKG_ERRORS=`$PKG_CONFIG --print-errors "gbm >= 9.0.0" 2>&1`
LIBGBM_PKG_ERRORS=`$PKG_CONFIG --print-errors "gbm >= 17.1.0" 2>&1`
fi
# Put the nasty error message in config.log where it belongs
echo "$LIBGBM_PKG_ERRORS" >&5
@@ -2245,8 +2245,8 @@ AS_HELP_STRING([--enable-video-kmsdrm], [use KMSDRM video driver [[default=no]]]
if test x$enable_video = xyes -a x$enable_video_kmsdrm = xyes; then
video_kmsdrm=no

PKG_CHECK_MODULES([LIBDRM], [libdrm >= 2.4.46], libdrm_avail=yes, libdrm_avail=no)
PKG_CHECK_MODULES([LIBGBM], [gbm >= 9.0.0], libgbm_avail=yes, libgbm_avail=no)
PKG_CHECK_MODULES([LIBDRM], [libdrm >= 2.4.82], libdrm_avail=yes, libdrm_avail=no)
PKG_CHECK_MODULES([LIBGBM], [gbm >= 17.1.0], libgbm_avail=yes, libgbm_avail=no)

if test x$libdrm_avail = xyes -a x$libgbm_avail = xyes; then
video_kmsdrm=yes
@@ -109,6 +109,7 @@ KMSDRM_CreateCursor(SDL_Surface * surface, int hot_x, int hot_y)
uint32_t bo_stride, pixel;
uint32_t *buffer = NULL;
size_t bufsize;
unsigned int i, j;

/* All code below assumes ARGB8888 format for the cursor surface, like other backends do.
Also, the GBM BO pixels have to be alpha-premultiplied, but the SDL surface we receive has
@@ -183,8 +184,8 @@ KMSDRM_CreateCursor(SDL_Surface * surface, int hot_x, int hot_y)
SDL_memset(buffer, 0x00, bo_stride * curdata->h);

/* Copy from SDL surface to buffer, pre-multiplying by alpha each pixel as we go. */
for (int i = 0; i < surface->h; i++) {
for (int j = 0; j < surface->w; j++) {
for (i = 0; i < surface->h; i++) {
for (j = 0; j < surface->w; j++) {
pixel = ((uint32_t*)surface->pixels)[i * surface->w + j];
alpha_premultiply_ARGB8888 (&pixel);
SDL_memcpy(buffer + (i * curdata->w) + j, &pixel, 4);
@@ -55,6 +55,7 @@ check_modesetting(int devindex)
{
SDL_bool available = SDL_FALSE;
char device[512];
unsigned int i;
int drm_fd;

SDL_snprintf(device, sizeof (device), "%scard%d", KMSDRM_DRI_PATH, devindex);
@@ -70,7 +71,7 @@ check_modesetting(int devindex)
resources->count_connectors, resources->count_encoders, resources->count_crtcs);

if (resources->count_connectors > 0 && resources->count_encoders > 0 && resources->count_crtcs > 0) {
for (unsigned int i = 0; i < resources->count_connectors; i++) {
for (i = 0; i < resources->count_connectors; i++) {
drmModeConnector *conn = KMSDRM_drmModeGetConnector(drm_fd, resources->connectors[i]);

if (!conn) {
@@ -244,9 +245,10 @@ KMSDRM_DestroyDumbBuffer(_THIS, dumb_buffer *buffer)
static void
KMSDRM_FillDumbBuffer(dumb_buffer *buffer)
{
for (unsigned int y = 0; y < buffer->height; y++) {
unsigned int x, y;
for (y = 0; y < buffer->height; y++) {
uint32_t *pix = (uint32_t *) ((uint8_t *) buffer->dumb.mem + (y * buffer->pitches[0]));
for (unsigned int x = 0; x < buffer->width; x++) {
for (x = 0; x < buffer->width; x++) {
*pix++ = (0x00000000);
}
}
@@ -550,13 +552,14 @@ setup_plane(_THIS, struct plane **plane, uint32_t plane_type)

/* Get the DRM plane properties. */
if ((*plane)->plane) {
unsigned int i;
(*plane)->props = KMSDRM_drmModeObjectGetProperties(viddata->drm_fd,
(*plane)->plane->plane_id, DRM_MODE_OBJECT_PLANE);

(*plane)->props_info = SDL_calloc((*plane)->props->count_props,
sizeof(*(*plane)->props_info));

for (unsigned int i = 0; i < (*plane)->props->count_props; i++) {
for (i = 0; i < (*plane)->props->count_props; i++) {
(*plane)->props_info[i] = KMSDRM_drmModeGetProperty(viddata->drm_fd,
(*plane)->props->props[i]);
}
@@ -821,6 +824,7 @@ KMSDRM_FBFromBO(_THIS, struct gbm_bo *bo)
unsigned width, height;
uint32_t format, strides[4] = {0}, handles[4] = {0}, offsets[4] = {0};
const int num_planes = KMSDRM_gbm_bo_get_plane_count(bo);
unsigned int i;
int ret;

/* Check for an existing framebuffer */
@@ -845,7 +849,7 @@ KMSDRM_FBFromBO(_THIS, struct gbm_bo *bo)
height = KMSDRM_gbm_bo_get_height(bo);
format = KMSDRM_gbm_bo_get_format(bo);

for (int i = 0; i < num_planes; i++) {
for (i = 0; i < num_planes; i++) {
strides[i] = KMSDRM_gbm_bo_get_stride_for_plane(bo, i);
handles[i] = KMSDRM_gbm_bo_get_handle(bo).u32;
offsets[i] = KMSDRM_gbm_bo_get_offset(bo, i);
@@ -1011,6 +1015,7 @@ KMSDRM_DestroyWindow(_THIS, SDL_Window *window)
{
SDL_WindowData *windata = (SDL_WindowData *) window->driverdata;
SDL_VideoData *viddata;
unsigned int i, j;

if (!windata) {
return;
@@ -1023,11 +1028,11 @@ KMSDRM_DestroyWindow(_THIS, SDL_Window *window)
/********************************************/
viddata = windata->viddata;

for (unsigned int i = 0; i < viddata->num_windows; i++) {
for (i = 0; i < viddata->num_windows; i++) {
if (viddata->windows[i] == window) {
viddata->num_windows--;

for (unsigned int j = i; j < viddata->num_windows; j++) {
for (j = i; j < viddata->num_windows; j++) {
viddata->windows[j] = viddata->windows[j + 1];
}

@@ -1085,6 +1090,7 @@ KMSDRM_ReconfigureWindow( _THIS, SDL_Window * window) {
int
KMSDRM_VideoInit(_THIS)
{
unsigned int i, j;
int ret = 0;
SDL_VideoData *viddata = ((SDL_VideoData *)_this->driverdata);
SDL_DisplayData *dispdata = NULL;
@@ -1139,7 +1145,7 @@ KMSDRM_VideoInit(_THIS)
}

/* Iterate on the available connectors to find a connected connector. */
for (unsigned int i = 0; i < resources->count_connectors; i++) {
for (i = 0; i < resources->count_connectors; i++) {
drmModeConnector *conn = KMSDRM_drmModeGetConnector(viddata->drm_fd, resources->connectors[i]);

if (!conn) {
@@ -1162,7 +1168,7 @@ KMSDRM_VideoInit(_THIS)
}

/* Try to find the connector's current encoder */
for (unsigned int i = 0; i < resources->count_encoders; i++) {
for (i = 0; i < resources->count_encoders; i++) {
encoder = KMSDRM_drmModeGetEncoder(viddata->drm_fd, resources->encoders[i]);

if (!encoder) {
@@ -1180,7 +1186,7 @@ KMSDRM_VideoInit(_THIS)

if (!encoder) {
/* No encoder was connected, find the first supported one */
for (unsigned int i = 0, j; i < resources->count_encoders; i++) {
for (i = 0; i < resources->count_encoders; i++) {
encoder = KMSDRM_drmModeGetEncoder(viddata->drm_fd, resources->encoders[i]);

if (!encoder) {
@@ -1214,7 +1220,7 @@ KMSDRM_VideoInit(_THIS)

/* If no CRTC was connected to the encoder, find the first CRTC that is supported by the encoder, and use that. */
if (!dispdata->crtc->crtc) {
for (unsigned int i = 0; i < resources->count_crtcs; i++) {
for (i = 0; i < resources->count_crtcs; i++) {
if (encoder->possible_crtcs & (1 << i)) {
encoder->crtc_id = resources->crtcs[i];
dispdata->crtc->crtc = KMSDRM_drmModeGetCrtc(viddata->drm_fd, encoder->crtc_id);
@@ -1293,7 +1299,7 @@ KMSDRM_VideoInit(_THIS)
dispdata->crtc->props_info = SDL_calloc(dispdata->crtc->props->count_props,
sizeof(*dispdata->crtc->props_info));

for (unsigned int i = 0; i < dispdata->crtc->props->count_props; i++) {
for (i = 0; i < dispdata->crtc->props->count_props; i++) {
dispdata->crtc->props_info[i] = KMSDRM_drmModeGetProperty(viddata->drm_fd,
dispdata->crtc->props->props[i]);
}
@@ -1305,7 +1311,7 @@ KMSDRM_VideoInit(_THIS)
dispdata->connector->props_info = SDL_calloc(dispdata->connector->props->count_props,
sizeof(*dispdata->connector->props_info));

for (unsigned int i = 0; i < dispdata->connector->props->count_props; i++) {
for (i = 0; i < dispdata->connector->props->count_props; i++) {
dispdata->connector->props_info[i] = KMSDRM_drmModeGetProperty(viddata->drm_fd,
dispdata->connector->props->props[i]);
}
@@ -1529,8 +1535,9 @@ KMSDRM_GetDisplayModes(_THIS, SDL_VideoDisplay * display)
SDL_DisplayData *dispdata = display->driverdata;
drmModeConnector *conn = dispdata->connector->connector;
SDL_DisplayMode mode;
int i;

for (int i = 0; i < conn->count_modes; i++) {
for (i = 0; i < conn->count_modes; i++) {
SDL_DisplayModeData *modedata = SDL_calloc(1, sizeof(SDL_DisplayModeData));

if (modedata) {
@@ -1560,6 +1567,7 @@ KMSDRM_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode)
SDL_DisplayData *dispdata = (SDL_DisplayData *)display->driverdata;
SDL_DisplayModeData *modedata = (SDL_DisplayModeData *)mode->driverdata;
drmModeConnector *conn = dispdata->connector->connector;
int i;

if (!modedata) {
return SDL_SetError("Mode doesn't have an associated index");
@@ -1571,7 +1579,7 @@ KMSDRM_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode)

dispdata->modeset_pending = SDL_TRUE;

for (int i = 0; i < viddata->num_windows; i++) {
for (i = 0; i < viddata->num_windows; i++) {
SDL_Window *window = viddata->windows[i];

if (KMSDRM_CreateSurfaces(_this, window)) {

0 comments on commit 78c274c

Please sign in to comment.