|
@@ -157,11 +157,16 @@ static dumb_buffer *KMSDRM_CreateDumbBuffer(_THIS)
|
|
|
SDL_VideoData *viddata = ((SDL_VideoData *)_this->driverdata);
|
|
|
SDL_DisplayData *dispdata = (SDL_DisplayData *)SDL_GetDisplayDriverData(0);
|
|
|
|
|
|
- dumb_buffer *ret = calloc(1, sizeof(*ret));
|
|
|
struct drm_mode_create_dumb create;
|
|
|
struct drm_mode_map_dumb map;
|
|
|
struct drm_mode_destroy_dumb destroy;
|
|
|
|
|
|
+ dumb_buffer *ret = SDL_calloc(1, sizeof(*ret));
|
|
|
+ if (!ret)
|
|
|
+ SDL_OutOfMemory();
|
|
|
+ return NULL;
|
|
|
+ }
|
|
|
+
|
|
|
/*
|
|
|
* The create ioctl uses the combination of depth and bpp to infer
|
|
|
* a format; 24/32 refers to DRM_FORMAT_XRGB8888 as defined in
|
|
@@ -174,14 +179,14 @@ static dumb_buffer *KMSDRM_CreateDumbBuffer(_THIS)
|
|
|
* for us, also returning us the GEM handle.
|
|
|
*/
|
|
|
create = (struct drm_mode_create_dumb) {
|
|
|
- .width = dispdata->mode.hdisplay,
|
|
|
- .height = dispdata->mode.vdisplay,
|
|
|
- .bpp = 32,
|
|
|
+ .width = dispdata->mode.hdisplay,
|
|
|
+ .height = dispdata->mode.vdisplay,
|
|
|
+ .bpp = 32,
|
|
|
};
|
|
|
|
|
|
if (KMSDRM_drmIoctl(viddata->drm_fd, DRM_IOCTL_MODE_CREATE_DUMB, &create)) {
|
|
|
- SDL_SetError("failed to create dumb buffer\n");
|
|
|
- goto err;
|
|
|
+ SDL_SetError("failed to create dumb buffer\n");
|
|
|
+ goto err;
|
|
|
}
|
|
|
|
|
|
ret->gem_handles[0] = create.handle;
|
|
@@ -247,10 +252,10 @@ KMSDRM_FillDumbBuffer(dumb_buffer *buffer)
|
|
|
{
|
|
|
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 (x = 0; x < buffer->width; x++) {
|
|
|
- *pix++ = (0x00000000);
|
|
|
- }
|
|
|
+ uint32_t *pix = (uint32_t *) ((uint8_t *) buffer->dumb.mem + (y * buffer->pitches[0]));
|
|
|
+ for (x = 0; x < buffer->width; x++) {
|
|
|
+ *pix++ = (0x00000000);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -302,15 +307,15 @@ int add_connector_property(drmModeAtomicReq *req, struct connector *connector,
|
|
|
int prop_id = 0;
|
|
|
|
|
|
for (i = 0 ; i < connector->props->count_props ; i++) {
|
|
|
- if (strcmp(connector->props_info[i]->name, name) == 0) {
|
|
|
- prop_id = connector->props_info[i]->prop_id;
|
|
|
- break;
|
|
|
- }
|
|
|
+ if (strcmp(connector->props_info[i]->name, name) == 0) {
|
|
|
+ prop_id = connector->props_info[i]->prop_id;
|
|
|
+ break;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
if (prop_id < 0) {
|
|
|
- SDL_SetError("no connector property: %s", name);
|
|
|
- return -EINVAL;
|
|
|
+ SDL_SetError("no connector property: %s", name);
|
|
|
+ return -EINVAL;
|
|
|
}
|
|
|
|
|
|
return KMSDRM_drmModeAtomicAddProperty(req, connector->connector->connector_id, prop_id, value);
|
|
@@ -323,15 +328,15 @@ int add_crtc_property(drmModeAtomicReq *req, struct crtc *crtc,
|
|
|
int prop_id = -1;
|
|
|
|
|
|
for (i = 0 ; i < crtc->props->count_props ; i++) {
|
|
|
- if (strcmp(crtc->props_info[i]->name, name) == 0) {
|
|
|
- prop_id = crtc->props_info[i]->prop_id;
|
|
|
- break;
|
|
|
- }
|
|
|
+ if (strcmp(crtc->props_info[i]->name, name) == 0) {
|
|
|
+ prop_id = crtc->props_info[i]->prop_id;
|
|
|
+ break;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
if (prop_id < 0) {
|
|
|
- SDL_SetError("no crtc property: %s", name);
|
|
|
- return -EINVAL;
|
|
|
+ SDL_SetError("no crtc property: %s", name);
|
|
|
+ return -EINVAL;
|
|
|
}
|
|
|
|
|
|
return KMSDRM_drmModeAtomicAddProperty(req, crtc->crtc->crtc_id, prop_id, value);
|
|
@@ -345,8 +350,8 @@ int add_plane_property(drmModeAtomicReq *req, struct plane *plane,
|
|
|
|
|
|
for (i = 0 ; i < plane->props->count_props ; i++) {
|
|
|
if (strcmp(plane->props_info[i]->name, name) == 0) {
|
|
|
- prop_id = plane->props_info[i]->prop_id;
|
|
|
- break;
|
|
|
+ prop_id = plane->props_info[i]->prop_id;
|
|
|
+ break;
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -373,27 +378,27 @@ void print_plane_info(_THIS, drmModePlanePtr plane)
|
|
|
/* Search the plane props for the plane type. */
|
|
|
for (int j = 0; j < props->count_props; j++) {
|
|
|
|
|
|
- drmModePropertyPtr p = KMSDRM_drmModeGetProperty(viddata->drm_fd, props->props[j]);
|
|
|
+ drmModePropertyPtr p = KMSDRM_drmModeGetProperty(viddata->drm_fd, props->props[j]);
|
|
|
|
|
|
- if ((strcmp(p->name, "type") == 0)) {
|
|
|
- type = props->prop_values[j];
|
|
|
- }
|
|
|
+ if ((strcmp(p->name, "type") == 0)) {
|
|
|
+ type = props->prop_values[j];
|
|
|
+ }
|
|
|
|
|
|
- KMSDRM_drmModeFreeProperty(p);
|
|
|
+ KMSDRM_drmModeFreeProperty(p);
|
|
|
}
|
|
|
|
|
|
switch (type) {
|
|
|
case DRM_PLANE_TYPE_OVERLAY:
|
|
|
- plane_type = "overlay";
|
|
|
- break;
|
|
|
+ plane_type = "overlay";
|
|
|
+ break;
|
|
|
|
|
|
case DRM_PLANE_TYPE_PRIMARY:
|
|
|
- plane_type = "primary";
|
|
|
- break;
|
|
|
+ plane_type = "primary";
|
|
|
+ break;
|
|
|
|
|
|
case DRM_PLANE_TYPE_CURSOR:
|
|
|
- plane_type = "cursor";
|
|
|
- break;
|
|
|
+ plane_type = "cursor";
|
|
|
+ break;
|
|
|
}
|
|
|
|
|
|
|
|
@@ -408,11 +413,11 @@ void print_plane_info(_THIS, drmModePlanePtr plane)
|
|
|
|
|
|
printf("--PLANE ID: %d\nPLANE TYPE: %s\nCRTC READING THIS PLANE: %d\nCRTCS SUPPORTED BY THIS PLANE: ", plane->plane_id, plane_type, plane->crtc_id);
|
|
|
for (int i = 0; i < resources->count_crtcs; i++) {
|
|
|
- if (plane->possible_crtcs & (1 << i)) {
|
|
|
- uint32_t crtc_id = resources->crtcs[i];
|
|
|
+ if (plane->possible_crtcs & (1 << i)) {
|
|
|
+ uint32_t crtc_id = resources->crtcs[i];
|
|
|
printf ("%d", crtc_id);
|
|
|
- break;
|
|
|
- }
|
|
|
+ break;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
printf ("\n\n");
|
|
@@ -428,8 +433,8 @@ void get_planes_info(_THIS)
|
|
|
|
|
|
plane_resources = KMSDRM_drmModeGetPlaneResources(viddata->drm_fd);
|
|
|
if (!plane_resources) {
|
|
|
- printf("drmModeGetPlaneResources failed: %s\n", strerror(errno));
|
|
|
- return;
|
|
|
+ printf("drmModeGetPlaneResources failed: %s\n", strerror(errno));
|
|
|
+ return;
|
|
|
}
|
|
|
|
|
|
printf("--Number of planes found: %d-- \n", plane_resources->count_planes);
|
|
@@ -440,11 +445,11 @@ void get_planes_info(_THIS)
|
|
|
|
|
|
uint32_t plane_id = plane_resources->planes[i];
|
|
|
|
|
|
- drmModePlanePtr plane = KMSDRM_drmModeGetPlane(viddata->drm_fd, plane_id);
|
|
|
- if (!plane) {
|
|
|
- printf("drmModeGetPlane(%u) failed: %s\n", plane_id, strerror(errno));
|
|
|
- continue;
|
|
|
- }
|
|
|
+ drmModePlanePtr plane = KMSDRM_drmModeGetPlane(viddata->drm_fd, plane_id);
|
|
|
+ if (!plane) {
|
|
|
+ printf("drmModeGetPlane(%u) failed: %s\n", plane_id, strerror(errno));
|
|
|
+ continue;
|
|
|
+ }
|
|
|
|
|
|
/* Print plane info. */
|
|
|
print_plane_info(_this, plane);
|
|
@@ -475,54 +480,53 @@ static int get_plane_id(_THIS, uint32_t plane_type)
|
|
|
/* Get the crtc_index for the current CRTC.
|
|
|
It's needed to find out if a plane supports the CRTC. */
|
|
|
for (i = 0; i < resources->count_crtcs; i++) {
|
|
|
- if (resources->crtcs[i] == dispdata->crtc->crtc->crtc_id) {
|
|
|
- crtc_index = i;
|
|
|
- break;
|
|
|
- }
|
|
|
+ if (resources->crtcs[i] == dispdata->crtc->crtc->crtc_id) {
|
|
|
+ crtc_index = i;
|
|
|
+ break;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
plane_resources = KMSDRM_drmModeGetPlaneResources(viddata->drm_fd);
|
|
|
if (!plane_resources) {
|
|
|
- return SDL_SetError("drmModeGetPlaneResources failed.");
|
|
|
+ return SDL_SetError("drmModeGetPlaneResources failed.");
|
|
|
}
|
|
|
|
|
|
/* Iterate on all the available planes. */
|
|
|
for (i = 0; (i < plane_resources->count_planes) && !found; i++) {
|
|
|
|
|
|
- uint32_t plane_id = plane_resources->planes[i];
|
|
|
+ uint32_t plane_id = plane_resources->planes[i];
|
|
|
|
|
|
- drmModePlanePtr plane = KMSDRM_drmModeGetPlane(viddata->drm_fd, plane_id);
|
|
|
- if (!plane) {
|
|
|
- continue;
|
|
|
- }
|
|
|
+ drmModePlanePtr plane = KMSDRM_drmModeGetPlane(viddata->drm_fd, plane_id);
|
|
|
+ if (!plane) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
|
|
|
/* See if the current CRTC is available for this plane. */
|
|
|
- if (plane->possible_crtcs & (1 << crtc_index)) {
|
|
|
+ if (plane->possible_crtcs & (1 << crtc_index)) {
|
|
|
|
|
|
- drmModeObjectPropertiesPtr props = KMSDRM_drmModeObjectGetProperties(viddata->drm_fd,
|
|
|
- plane_id, DRM_MODE_OBJECT_PLANE);
|
|
|
- ret = plane_id;
|
|
|
+ drmModeObjectPropertiesPtr props = KMSDRM_drmModeObjectGetProperties(
|
|
|
+ viddata->drm_fd, plane_id, DRM_MODE_OBJECT_PLANE);
|
|
|
+ ret = plane_id;
|
|
|
|
|
|
/* Iterate on the plane props to find the type of the plane,
|
|
|
to see if it's of the type we want. */
|
|
|
- for (j = 0; j < props->count_props; j++) {
|
|
|
+ for (j = 0; j < props->count_props; j++) {
|
|
|
|
|
|
- drmModePropertyPtr p = KMSDRM_drmModeGetProperty(viddata->drm_fd,
|
|
|
- props->props[j]);
|
|
|
+ drmModePropertyPtr p = KMSDRM_drmModeGetProperty(viddata->drm_fd,
|
|
|
+ props->props[j]);
|
|
|
|
|
|
- if ((strcmp(p->name, "type") == 0) &&
|
|
|
- (props->prop_values[j] == plane_type)) {
|
|
|
- /* found our plane, use that: */
|
|
|
- found = 1;
|
|
|
- }
|
|
|
+ if ((strcmp(p->name, "type") == 0) && (props->prop_values[j] == plane_type)) {
|
|
|
+ /* found our plane, use that: */
|
|
|
+ found = 1;
|
|
|
+ }
|
|
|
|
|
|
KMSDRM_drmModeFreeProperty(p);
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
- KMSDRM_drmModeFreeObjectProperties(props);
|
|
|
- }
|
|
|
+ KMSDRM_drmModeFreeObjectProperties(props);
|
|
|
+ }
|
|
|
|
|
|
- KMSDRM_drmModeFreePlane(plane);
|
|
|
+ KMSDRM_drmModeFreePlane(plane);
|
|
|
}
|
|
|
|
|
|
KMSDRM_drmModeFreePlaneResources(plane_resources);
|
|
@@ -554,7 +558,7 @@ setup_plane(_THIS, struct plane **plane, uint32_t plane_type)
|
|
|
if ((*plane)->plane) {
|
|
|
unsigned int i;
|
|
|
(*plane)->props = KMSDRM_drmModeObjectGetProperties(viddata->drm_fd,
|
|
|
- (*plane)->plane->plane_id, DRM_MODE_OBJECT_PLANE);
|
|
|
+ (*plane)->plane->plane_id, DRM_MODE_OBJECT_PLANE);
|
|
|
|
|
|
(*plane)->props_info = SDL_calloc((*plane)->props->count_props,
|
|
|
sizeof(*(*plane)->props_info));
|
|
@@ -647,12 +651,12 @@ int drm_atomic_commit(_THIS, SDL_bool blocking)
|
|
|
SDL_SetError("Atomic commit failed, returned %d.", ret);
|
|
|
/* Uncomment this for fast-debugging */
|
|
|
// printf("ATOMIC COMMIT FAILED: %d.\n", ret);
|
|
|
- goto out;
|
|
|
+ goto out;
|
|
|
}
|
|
|
|
|
|
if (dispdata->kms_in_fence_fd != -1) {
|
|
|
- close(dispdata->kms_in_fence_fd);
|
|
|
- dispdata->kms_in_fence_fd = -1;
|
|
|
+ close(dispdata->kms_in_fence_fd);
|
|
|
+ dispdata->kms_in_fence_fd = -1;
|
|
|
}
|
|
|
|
|
|
out:
|
|
@@ -671,15 +675,15 @@ drm_atomic_waitpending(_THIS)
|
|
|
/* Will return immediately if we have already destroyed the fence, because we NULL-ify it just after.
|
|
|
Also, will return immediately in double-buffer mode, because kms_fence will alsawys be NULL. */
|
|
|
if (dispdata->kms_fence) {
|
|
|
- EGLint status;
|
|
|
+ EGLint status;
|
|
|
|
|
|
- do {
|
|
|
- status = _this->egl_data->eglClientWaitSyncKHR(_this->egl_data->egl_display,
|
|
|
- dispdata->kms_fence, 0, EGL_FOREVER_KHR);
|
|
|
- } while (status != EGL_CONDITION_SATISFIED_KHR);
|
|
|
+ do {
|
|
|
+ status = _this->egl_data->eglClientWaitSyncKHR(_this->egl_data->egl_display,
|
|
|
+ dispdata->kms_fence, 0, EGL_FOREVER_KHR);
|
|
|
+ } while (status != EGL_CONDITION_SATISFIED_KHR);
|
|
|
|
|
|
- _this->egl_data->eglDestroySyncKHR(_this->egl_data->egl_display, dispdata->kms_fence);
|
|
|
- dispdata->kms_fence = NULL;
|
|
|
+ _this->egl_data->eglDestroySyncKHR(_this->egl_data->egl_display, dispdata->kms_fence);
|
|
|
+ dispdata->kms_fence = NULL;
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -883,16 +887,16 @@ KMSDRM_FBFromBO(_THIS, struct gbm_bo *bo)
|
|
|
format = KMSDRM_gbm_bo_get_format(bo);
|
|
|
|
|
|
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);
|
|
|
+ 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);
|
|
|
}
|
|
|
|
|
|
/* Create framebuffer object for the buffer.
|
|
|
It's VERY important to note that fb_id is what we ise to set the FB_ID prop of a plane
|
|
|
when using the ATOMIC interface, and we get fb_id it here. */
|
|
|
ret = KMSDRM_drmModeAddFB2(viddata->drm_fd, width, height, format,
|
|
|
- handles, strides, offsets, &fb_info->fb_id, 0);
|
|
|
+ handles, strides, offsets, &fb_info->fb_id, 0);
|
|
|
|
|
|
if (ret) {
|
|
|
SDL_free(fb_info);
|
|
@@ -960,8 +964,8 @@ KMSDRM_DestroySurfaces(_THIS, SDL_Window *window)
|
|
|
}
|
|
|
|
|
|
if (windata->next_bo) {
|
|
|
- KMSDRM_gbm_surface_release_buffer(windata->gs, windata->next_bo);
|
|
|
- windata->next_bo = NULL;
|
|
|
+ KMSDRM_gbm_surface_release_buffer(windata->gs, windata->next_bo);
|
|
|
+ windata->next_bo = NULL;
|
|
|
}
|
|
|
|
|
|
/* Destroy the EGL surface. */
|
|
@@ -985,8 +989,8 @@ KMSDRM_DestroySurfaces(_THIS, SDL_Window *window)
|
|
|
#endif
|
|
|
|
|
|
if (windata->gs) {
|
|
|
- KMSDRM_gbm_surface_destroy(windata->gs);
|
|
|
- windata->gs = NULL;
|
|
|
+ KMSDRM_gbm_surface_destroy(windata->gs);
|
|
|
+ windata->gs = NULL;
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -1114,7 +1118,7 @@ KMSDRM_ReconfigureWindow( _THIS, SDL_Window * window) {
|
|
|
}
|
|
|
|
|
|
if (KMSDRM_CreateSurfaces(_this, window)) {
|
|
|
- return -1;
|
|
|
+ return -1;
|
|
|
}
|
|
|
|
|
|
return 0;
|
|
@@ -1133,9 +1137,9 @@ KMSDRM_VideoInit(_THIS)
|
|
|
SDL_VideoDisplay display = {0};
|
|
|
|
|
|
dispdata = (SDL_DisplayData *) SDL_calloc(1, sizeof(SDL_DisplayData));
|
|
|
- dispdata->display_plane = calloc(1, sizeof(*dispdata->display_plane));
|
|
|
- dispdata->crtc = calloc(1, sizeof(*dispdata->crtc));
|
|
|
- dispdata->connector = calloc(1, sizeof(*dispdata->connector));
|
|
|
+ dispdata->display_plane = SDL_calloc(1, sizeof(*dispdata->display_plane));
|
|
|
+ dispdata->crtc = SDL_calloc(1, sizeof(*dispdata->crtc));
|
|
|
+ dispdata->connector = SDL_calloc(1, sizeof(*dispdata->connector));
|
|
|
|
|
|
dispdata->atomic_flags = 0;
|
|
|
dispdata->atomic_req = NULL;
|
|
@@ -1333,7 +1337,7 @@ KMSDRM_VideoInit(_THIS)
|
|
|
sizeof(*dispdata->crtc->props_info));
|
|
|
|
|
|
for (i = 0; i < dispdata->crtc->props->count_props; i++) {
|
|
|
- dispdata->crtc->props_info[i] = KMSDRM_drmModeGetProperty(viddata->drm_fd,
|
|
|
+ dispdata->crtc->props_info[i] = KMSDRM_drmModeGetProperty(viddata->drm_fd,
|
|
|
dispdata->crtc->props->props[i]);
|
|
|
}
|
|
|
|
|
@@ -1345,7 +1349,7 @@ KMSDRM_VideoInit(_THIS)
|
|
|
sizeof(*dispdata->connector->props_info));
|
|
|
|
|
|
for (i = 0; i < dispdata->connector->props->count_props; i++) {
|
|
|
- dispdata->connector->props_info[i] = KMSDRM_drmModeGetProperty(viddata->drm_fd,
|
|
|
+ dispdata->connector->props_info[i] = KMSDRM_drmModeGetProperty(viddata->drm_fd,
|
|
|
dispdata->connector->props->props[i]);
|
|
|
}
|
|
|
|
|
@@ -1615,9 +1619,9 @@ KMSDRM_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode)
|
|
|
for (i = 0; i < viddata->num_windows; i++) {
|
|
|
SDL_Window *window = viddata->windows[i];
|
|
|
|
|
|
- if (KMSDRM_CreateSurfaces(_this, window)) {
|
|
|
- return -1;
|
|
|
- }
|
|
|
+ if (KMSDRM_CreateSurfaces(_this, window)) {
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
|
|
|
/* Tell app about the window resize */
|
|
|
SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESIZED, mode->w, mode->h);
|
|
@@ -1796,7 +1800,7 @@ KMSDRM_GetWindowWMInfo(_THIS, SDL_Window * window, struct SDL_SysWMinfo *info)
|
|
|
return SDL_TRUE;
|
|
|
} else {
|
|
|
SDL_SetError("application not compiled with SDL %d.%d\n",
|
|
|
- SDL_MAJOR_VERSION, SDL_MINOR_VERSION);
|
|
|
+ SDL_MAJOR_VERSION, SDL_MINOR_VERSION);
|
|
|
return SDL_FALSE;
|
|
|
}
|
|
|
|