Subversion Repositories Kolibri OS

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
5362 serge 1
/*
2
 * Copyright (c) 2012 Intel Corporation. All Rights Reserved.
3
 *
4
 * Permission is hereby granted, free of charge, to any person obtaining a
5
 * copy of this software and associated documentation files (the
6
 * "Software"), to deal in the Software without restriction, including
7
 * without limitation the rights to use, copy, modify, merge, publish,
8
 * distribute, sub license, and/or sell copies of the Software, and to
9
 * permit persons to whom the Software is furnished to do so, subject to
10
 * the following conditions:
11
 *
12
 * The above copyright notice and this permission notice (including the
13
 * next paragraph) shall be included in all copies or substantial portions
14
 * of the Software.
15
 *
16
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
19
 * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
20
 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
 */
24
 
25
#include "sysdeps.h"
26
#include 
27
#include "va_drm.h"
28
#include "va_backend.h"
29
#include "va_drmcommon.h"
30
#include "va_drm_auth.h"
31
#include "va_drm_utils.h"
32
 
33
static int
34
va_DisplayContextIsValid(VADisplayContextP pDisplayContext)
35
{
36
    VADriverContextP const pDriverContext = pDisplayContext->pDriverContext;
37
 
38
    return (pDriverContext &&
39
            ((pDriverContext->display_type & VA_DISPLAY_MAJOR_MASK) ==
40
             VA_DISPLAY_DRM));
41
}
42
 
43
static void
44
va_DisplayContextDestroy(VADisplayContextP pDisplayContext)
45
{
46
    if (!pDisplayContext)
47
        return;
48
 
49
    free(pDisplayContext->pDriverContext->drm_state);
50
    free(pDisplayContext->pDriverContext);
51
    free(pDisplayContext);
52
}
53
 
54
static VAStatus
55
va_DisplayContextGetDriverName(
56
    VADisplayContextP pDisplayContext,
57
    char            **driver_name_ptr
58
)
59
{
60
    VADriverContextP const ctx = pDisplayContext->pDriverContext;
61
    struct drm_state * const drm_state = ctx->drm_state;
62
    VAStatus status;
63
 
64
    status = VA_DRM_GetDriverName(ctx, driver_name_ptr);
65
    if (status != VA_STATUS_SUCCESS)
66
        return status;
67
 
68
    drm_state->auth_type = VA_DRM_AUTH_CUSTOM;
69
 
70
    return VA_STATUS_SUCCESS;
71
}
72
 
73
VADisplay
74
vaGetDisplayDRM(int fd)
75
{
76
    VADisplayContextP pDisplayContext = NULL;
77
    VADriverContextP  pDriverContext  = NULL;
78
    struct drm_state *drm_state       = NULL;
79
 
80
    if (fd == 0)
81
        return NULL;
82
 
83
    /* Create new entry */
84
    /* XXX: handle cache? */
85
    drm_state = calloc(1, sizeof(*drm_state));
86
    if (!drm_state)
87
        goto error;
88
    drm_state->fd = fd;
89
 
90
    pDriverContext = calloc(1, sizeof(*pDriverContext));
91
    if (!pDriverContext)
92
        goto error;
93
    pDriverContext->native_dpy   = NULL;
94
    pDriverContext->display_type = VA_DISPLAY_DRM;
95
    pDriverContext->drm_state    = drm_state;
96
 
97
    pDisplayContext = calloc(1, sizeof(*pDisplayContext));
98
    if (!pDisplayContext)
99
        goto error;
100
 
101
    pDisplayContext->vadpy_magic     = VA_DISPLAY_MAGIC;
102
    pDisplayContext->pDriverContext  = pDriverContext;
103
    pDisplayContext->vaIsValid       = va_DisplayContextIsValid;
104
    pDisplayContext->vaDestroy       = va_DisplayContextDestroy;
105
    pDisplayContext->vaGetDriverName = va_DisplayContextGetDriverName;
106
    return pDisplayContext;
107
 
108
error:
109
    free(pDisplayContext);
110
    free(pDriverContext);
111
    free(drm_state);
112
    return NULL;
113
}