Skip to content

Commit

Permalink
enable driver candidate select fucntion for DRM
Browse files Browse the repository at this point in the history
add multiple backend driver support part 3
enable vaGetDriverNameByIndex for DRM

Signed-off-by: Carl Zhang <carl.zhang@intel.com>
  • Loading branch information
XinfengZhang committed Dec 19, 2019
1 parent 9982d1b commit 1ce2041
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 10 deletions.
18 changes: 14 additions & 4 deletions va/drm/va_drm.c
Expand Up @@ -51,11 +51,20 @@ va_DisplayContextDestroy(VADisplayContextP pDisplayContext)
free(pDisplayContext->pDriverContext);
free(pDisplayContext);
}
static VAStatus va_DisplayContextGetCandidateNum(
VADisplayContextP pDisplayContext,
int *candidate_index
)
{
VADriverContextP const ctx = pDisplayContext->pDriverContext;
return VA_DRM_GetCandidateNum(ctx, candidate_index);
}

static VAStatus
va_DisplayContextGetDriverName(
va_DisplayContextGetDriverNameByIndex(
VADisplayContextP pDisplayContext,
char **driver_name_ptr
char **driver_name_ptr,
int candidate_index
)
{

Expand All @@ -65,7 +74,7 @@ va_DisplayContextGetDriverName(
VAStatus status;
int ret;

status = VA_DRM_GetDriverName(ctx, driver_name_ptr);
status = VA_DRM_GetDriverName(ctx, driver_name_ptr, candidate_index);
if (status != VA_STATUS_SUCCESS)
return status;

Expand Down Expand Up @@ -108,7 +117,8 @@ vaGetDisplayDRM(int fd)

pDisplayContext->vaIsValid = va_DisplayContextIsValid;
pDisplayContext->vaDestroy = va_DisplayContextDestroy;
pDisplayContext->vaGetDriverName = va_DisplayContextGetDriverName;
pDisplayContext->vaGetCandidateNum = va_DisplayContextGetCandidateNum;
pDisplayContext->vaGetDriverNameByIndex = va_DisplayContextGetDriverNameByIndex;

pDriverContext = va_newDriverContext(pDisplayContext);
if (!pDriverContext)
Expand Down
34 changes: 31 additions & 3 deletions va/drm/va_drm_utils.c
Expand Up @@ -48,14 +48,38 @@ static const struct driver_name_map g_driver_name_map[] = {
{ NULL, 0, NULL }
};

/* Returns the VA driver candidate num for the active display*/
VAStatus
VA_DRM_GetCandidateNum(VADriverContextP ctx, int * candidate_num)
{
struct drm_state * const drm_state = ctx->drm_state;
drmVersionPtr drm_version;
int num_of_candidate = 0;
const struct driver_name_map *m = NULL;
if (!drm_state || drm_state->fd < 0)
return VA_STATUS_ERROR_INVALID_DISPLAY;
drm_version = drmGetVersion(drm_state->fd);
if (!drm_version)
return VA_STATUS_ERROR_UNKNOWN;
for (m = g_driver_name_map; m->key != NULL; m++) {
if (drm_version->name_len >= m->key_len &&
strncmp(drm_version->name, m->key, m->key_len) == 0) {
num_of_candidate ++;
}
}
drmFreeVersion(drm_version);
*candidate_num = num_of_candidate;
}

/* Returns the VA driver name for the active display */
VAStatus
VA_DRM_GetDriverName(VADriverContextP ctx, char **driver_name_ptr)
VA_DRM_GetDriverName(VADriverContextP ctx, char **driver_name_ptr, int candidate_index)
{
struct drm_state * const drm_state = ctx->drm_state;
drmVersionPtr drm_version;
char *driver_name = NULL;
const struct driver_name_map *m;
int current_index = 0;

*driver_name_ptr = NULL;

Expand All @@ -68,8 +92,12 @@ VA_DRM_GetDriverName(VADriverContextP ctx, char **driver_name_ptr)

for (m = g_driver_name_map; m->key != NULL; m++) {
if (drm_version->name_len >= m->key_len &&
strncmp(drm_version->name, m->key, m->key_len) == 0)
break;
strncmp(drm_version->name, m->key, m->key_len) == 0) {
if (current_index == candidate_index) {
break;
}
current_index ++;
}
}
drmFreeVersion(drm_version);

Expand Down
6 changes: 4 additions & 2 deletions va/drm/va_drm_utils.h
Expand Up @@ -41,7 +41,9 @@
#ifdef __cplusplus
extern "C" {
#endif

DLL_HIDDEN
VAStatus
VA_DRM_GetCandidateNum(VADriverContextP ctx, int * candidate_num);
/**
* \brief Returns the VA driver name for the active display.
*
Expand All @@ -62,7 +64,7 @@ extern "C" {
*/
DLL_HIDDEN
VAStatus
VA_DRM_GetDriverName(VADriverContextP ctx, char **driver_name_ptr);
VA_DRM_GetDriverName(VADriverContextP ctx, char **driver_name_ptr, int candidate_index);

/**
* \brief Checks whether the file descriptor is a DRM Render-Nodes one
Expand Down
27 changes: 26 additions & 1 deletion va/wayland/va_wayland_drm.c
Expand Up @@ -116,6 +116,29 @@ static const struct wl_drm_listener drm_listener = {
drm_handle_capabilities,
};

static VAStatus
va_DisplayContextGetCandidateNum(
VADisplayContextP pDisplayContext,
int *candidate_index
)
{
VADriverContextP const ctx = pDisplayContext->pDriverContext;

return VA_DRM_GetCandidateNum(ctx, candidate_index);
}

static VAStatus
va_DisplayContextGetDriverNameByIndex(
VADisplayContextP pDisplayContext,
char **driver_name_ptr,
int candidate_index
)
{
VADriverContextP const ctx = pDisplayContext->pDriverContext;

return VA_DRM_GetDriverName(ctx, driver_name_ptr, candidate_index);
}

static VAStatus
va_DisplayContextGetDriverName(
VADisplayContextP pDisplayContext,
Expand All @@ -124,7 +147,7 @@ va_DisplayContextGetDriverName(
{
VADriverContextP const ctx = pDisplayContext->pDriverContext;

return VA_DRM_GetDriverName(ctx, driver_name_ptr);
return VA_DRM_GetDriverName(ctx, driver_name_ptr, 0);
}

void
Expand Down Expand Up @@ -237,6 +260,8 @@ va_wayland_drm_create(VADisplayContextP pDisplayContext)
wl_drm_ctx->is_authenticated = 0;
pDisplayContext->opaque = wl_drm_ctx;
pDisplayContext->vaGetDriverName = va_DisplayContextGetDriverName;
pDisplayContext->vaGetCandidateNum = va_DisplayContextGetCandidateNum;
pDisplayContext->vaGetDriverNameByIndex = va_DisplayContextGetDriverNameByIndex;

drm_state = calloc(1, sizeof(struct drm_state));
if (!drm_state) {
Expand Down

0 comments on commit 1ce2041

Please sign in to comment.