use DMA_BUF_IOCTL_SYNC

This commit is contained in:
Vincent Wei
2023-07-27 10:04:53 +08:00
parent bce5b73e1c
commit 39d03be6d7
2 changed files with 29 additions and 29 deletions
+2
View File
@@ -137,6 +137,8 @@ typedef struct _DrmSurfaceBuffer {
uint32_t dumb:1; uint32_t dumb:1;
/** Is it a scanout buffer. Since 5.0.0. */ /** Is it a scanout buffer. Since 5.0.0. */
uint32_t scanout:1; uint32_t scanout:1;
/** The buffer is also a dma-buff. Since 5.0.13. */
uint32_t dma_buff:1;
/** The width of the buffer. */ /** The width of the buffer. */
uint32_t width; uint32_t width;
+27 -29
View File
@@ -2307,11 +2307,6 @@ static DrmSurfaceBuffer *drm_create_dumb_buffer_from_prime_fd(DrmVideoData* vdat
static int drm_map_buffer_via_dmabuf(DrmVideoData* vdata, static int drm_map_buffer_via_dmabuf(DrmVideoData* vdata,
DrmSurfaceBuffer *surface_buffer) DrmSurfaceBuffer *surface_buffer)
{ {
if (drmSetMaster(vdata->dev_fd)) {
_ERR_PRINTF("NEWGAL>DRM: failed drmSetMaster(): %m\n");
return -1;
}
if (drmPrimeHandleToFD(vdata->dev_fd, surface_buffer->handle, if (drmPrimeHandleToFD(vdata->dev_fd, surface_buffer->handle,
DRM_RDWR | DRM_CLOEXEC, &surface_buffer->prime_fd)) { DRM_RDWR | DRM_CLOEXEC, &surface_buffer->prime_fd)) {
_ERR_PRINTF ("NEWGAL>DRM: failed drmPrimeHandleToFD(): %m\n"); _ERR_PRINTF ("NEWGAL>DRM: failed drmPrimeHandleToFD(): %m\n");
@@ -2431,6 +2426,25 @@ static void update_real_screen_memcpy(_THIS)
} }
} }
static void drm_dmabuf_start(DrmSurfaceBuffer *real_buff)
{
struct dma_buf_sync sync;
sync.flags = DMA_BUF_SYNC_WRITE | DMA_BUF_SYNC_START;
if (ioctl(real_buff->prime_fd, DMA_BUF_IOCTL_SYNC, &sync)) {
_WRN_PRINTF("Failed ioctl(DMA_BUF_IOCTL_SYNC): %m\n");
}
}
static void drm_dmabuf_end(DrmSurfaceBuffer *real_buff)
{
struct dma_buf_sync sync;
sync.flags = DMA_BUF_SYNC_WRITE | DMA_BUF_SYNC_END;
if (ioctl(real_buff->prime_fd, DMA_BUF_IOCTL_SYNC, &sync)) {
_WRN_PRINTF("Failed ioctl(DMA_BUF_IOCTL_SYNC): %m\n");
}
}
static void update_real_screen_helper(_THIS) static void update_real_screen_helper(_THIS)
{ {
DrmVideoData* vdata = this->hidden; DrmVideoData* vdata = this->hidden;
@@ -2448,9 +2462,11 @@ static void update_real_screen_helper(_THIS)
clock_gettime(CLOCK_REALTIME, &ts_start); clock_gettime(CLOCK_REALTIME, &ts_start);
#endif #endif
if (real_buff->prime_fd >= 0 && real_buff->dma_buff)
drm_dmabuf_start(real_buff);
BOOL hw_ok = FALSE; BOOL hw_ok = FALSE;
if (real_buff && shadow_buff && vdata->driver && if (shadow_buff && vdata->driver && vdata->driver_ops->copy_buff) {
vdata->driver_ops->copy_buff) {
GAL_Rect rect = { GAL_Rect rect = {
this->hidden->update_rect.left, this->hidden->update_rect.left,
this->hidden->update_rect.top, this->hidden->update_rect.top,
@@ -2469,6 +2485,9 @@ static void update_real_screen_helper(_THIS)
update_real_screen_memcpy(this); update_real_screen_memcpy(this);
} }
if (real_buff->prime_fd >= 0 && real_buff->dma_buff)
drm_dmabuf_end(real_buff);
#if 0 // def _DEBUG #if 0 // def _DEBUG
double elapsed = get_elapsed_seconds(&ts_start, NULL); double elapsed = get_elapsed_seconds(&ts_start, NULL);
_MG_PRINTF("Cosumed time to update real screen: %f (seconds)\n", elapsed); _MG_PRINTF("Cosumed time to update real screen: %f (seconds)\n", elapsed);
@@ -2699,7 +2718,7 @@ static GAL_Surface *DRM_SetVideoMode(_THIS, GAL_Surface *current,
assert (vdata->driver_ops->create_buffer); assert (vdata->driver_ops->create_buffer);
shadow_buffer = vdata->driver_ops->create_buffer(vdata->driver, shadow_buffer = vdata->driver_ops->create_buffer(vdata->driver,
drm_format, hdr_size, drm_format, hdr_size,
info->width, info->height, DRM_SURBUF_TYPE_OFFSCREEN); info->width, info->height, DRM_SURBUF_TYPE_SHADOW);
vdata->driver_ops->map_buffer(vdata->driver, shadow_buffer); vdata->driver_ops->map_buffer(vdata->driver, shadow_buffer);
} }
@@ -4079,27 +4098,6 @@ static int drm_allocate_dma_buffers(DrmVideoData* vdata, int size)
return 0; return 0;
} }
static void drm_dmabuf_start(DrmSurfaceBuffer *real_buff)
{
struct dma_buf_sync sync;
if (real_buff->prime_fd < 0)
return;
sync.flags = DMA_BUF_SYNC_RW | DMA_BUF_SYNC_START;
ioctl(real_buff->prime_fd, DMA_BUF_IOCTL_SYNC, &sync);
}
static void drm_dmabuf_end(DrmSurfaceBuffer *real_buff)
{
struct dma_buf_sync sync;
if (real_buff->prime_fd < 0)
return;
sync.flags = DMA_BUF_SYNC_RW | DMA_BUF_SYNC_END;
ioctl(real_buff->prime_fd, DMA_BUF_IOCTL_SYNC, &sync);
}
static BOOL DRM_SyncUpdateDMA (_THIS) static BOOL DRM_SyncUpdateDMA (_THIS)
{ {
drmDMAReq dma_req; drmDMAReq dma_req;