Introduce drm_free_fb

This function takes care of calling drmModeRmFB. In the future it'll
also take care of releasing the client buffer when using direct
scan-out.
This commit is contained in:
Simon Ser 2020-05-19 14:25:59 +02:00
parent 0ee8d451e4
commit 2062141c49
No known key found for this signature in database
GPG key ID: 0FDE7BE0E88F5E48
2 changed files with 19 additions and 2 deletions

View file

@ -190,6 +190,8 @@ static int get_plane_id(struct drm_t *drm)
return ret; return ret;
} }
static void drm_free_fb( struct drm_t *drm, struct fb *fb );
static void page_flip_handler(int fd, unsigned int frame, static void page_flip_handler(int fd, unsigned int frame,
unsigned int sec, unsigned int usec, void *data) unsigned int sec, unsigned int usec, void *data)
{ {
@ -224,7 +226,7 @@ static void page_flip_handler(int fd, unsigned int frame,
{ {
printf("deferred free %u\n", previous_fbid); printf("deferred free %u\n", previous_fbid);
} }
drmModeRmFB( g_DRM.fd, previous_fbid ); drm_free_fb( &g_DRM, &g_DRM.map_fbid_inflightflips[ previous_fbid ] );
g_DRM.fbid_free_queue.erase( g_DRM.fbid_free_queue.begin() + i ); g_DRM.fbid_free_queue.erase( g_DRM.fbid_free_queue.begin() + i );
break; break;
@ -649,12 +651,26 @@ uint32_t drm_fbid_from_dmabuf( struct drm_t *drm, struct wlr_dmabuf_attributes *
} }
assert( drm->map_fbid_inflightflips[ fb_id ].held == false ); assert( drm->map_fbid_inflightflips[ fb_id ].held == false );
drm->map_fbid_inflightflips[ fb_id ].id = fb_id;
drm->map_fbid_inflightflips[ fb_id ].held = true; drm->map_fbid_inflightflips[ fb_id ].held = true;
drm->map_fbid_inflightflips[ fb_id ].n_refs = 0; drm->map_fbid_inflightflips[ fb_id ].n_refs = 0;
return fb_id; return fb_id;
} }
static void drm_free_fb( struct drm_t *drm, struct fb *fb )
{
assert( !fb->held );
assert( fb->n_refs == 0 );
if ( drmModeRmFB( drm->fd, fb->id ) != 0 )
{
perror( "drmModeRmFB failed" );
}
fb = {};
}
void drm_drop_fbid( struct drm_t *drm, uint32_t fbid ) void drm_drop_fbid( struct drm_t *drm, uint32_t fbid )
{ {
assert( drm->map_fbid_inflightflips[ fbid ].held == true ); assert( drm->map_fbid_inflightflips[ fbid ].held == true );
@ -667,7 +683,7 @@ void drm_drop_fbid( struct drm_t *drm, uint32_t fbid )
{ {
printf("free fbid %u\n", fbid); printf("free fbid %u\n", fbid);
} }
drmModeRmFB( drm->fd, fbid ); drm_free_fb( drm, &drm->map_fbid_inflightflips[ fbid ] );
} }
else else
{ {

View file

@ -38,6 +38,7 @@ struct connector {
}; };
struct fb { struct fb {
uint32_t id;
/* A FB is held if it's being used by steamcompmgr */ /* A FB is held if it's being used by steamcompmgr */
bool held; bool held;
/* Number of page-flips using the FB */ /* Number of page-flips using the FB */