| 1 |
/* |
| 2 |
* Copyright (c) 2007 Intel Corporation. All Rights Reserved. |
| 3 |
* Copyright (c) 2023 Emil Velikov |
| 4 |
* |
| 5 |
* Permission is hereby granted, free of charge, to any person obtaining a |
| 6 |
* copy of this software and associated documentation files (the |
| 7 |
* "Software"), to deal in the Software without restriction, including |
| 8 |
* without limitation the rights to use, copy, modify, merge, publish, |
| 9 |
* distribute, sub license, and/or sell copies of the Software, and to |
| 10 |
* permit persons to whom the Software is furnished to do so, subject to |
| 11 |
* the following conditions: |
| 12 |
* |
| 13 |
* The above copyright notice and this permission notice (including the |
| 14 |
* next paragraph) shall be included in all copies or substantial portions |
| 15 |
* of the Software. |
| 16 |
* |
| 17 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 18 |
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 19 |
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. |
| 20 |
* IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR |
| 21 |
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
| 22 |
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
| 23 |
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 24 |
*/ |
| 25 |
|
| 26 |
#define _GNU_SOURCE 1 |
| 27 |
#include "sysdeps.h" |
| 28 |
#include "va.h" |
| 29 |
#include "va_backend.h" |
| 30 |
#include "va_internal.h" |
| 31 |
#include "va_trace.h" |
| 32 |
#include "va_x11.h" |
| 33 |
#include "va_dri2.h" |
| 34 |
#include "va_dri2_priv.h" |
| 35 |
#include "va_dri3.h" |
| 36 |
#include "va_dricommon.h" |
| 37 |
#include "va_nvctrl.h" |
| 38 |
#include "va_fglrx.h" |
| 39 |
#include <stdio.h> |
| 40 |
#include <stdlib.h> |
| 41 |
#include <stdarg.h> |
| 42 |
#include <string.h> |
| 43 |
#include <unistd.h> |
| 44 |
#include <sys/types.h> |
| 45 |
#include <sys/stat.h> |
| 46 |
#include <fcntl.h> |
| 47 |
#include <errno.h> |
| 48 |
|
| 49 |
static void va_DisplayContextDestroy( |
| 50 |
VADisplayContextP pDisplayContext |
| 51 |
) |
| 52 |
{ |
| 53 |
VADriverContextP ctx; |
| 54 |
struct dri_state *dri_state; |
| 55 |
|
| 56 |
if (pDisplayContext == NULL) |
| 57 |
return; |
| 58 |
|
| 59 |
ctx = pDisplayContext->pDriverContext; |
| 60 |
dri_state = ctx->drm_state; |
| 61 |
|
| 62 |
if (dri_state && dri_state->close) |
| 63 |
dri_state->close(ctx); |
| 64 |
|
| 65 |
if (dri_state && dri_state->base.fd != -1) |
| 66 |
close(dri_state->base.fd); |
| 67 |
|
| 68 |
free(pDisplayContext->pDriverContext->drm_state); |
| 69 |
free(pDisplayContext->pDriverContext); |
| 70 |
free(pDisplayContext); |
| 71 |
} |
| 72 |
|
| 73 |
static VAStatus va_DisplayContextGetDriverNames( |
| 74 |
VADisplayContextP pDisplayContext, |
| 75 |
char **drivers, unsigned *num_drivers |
| 76 |
) |
| 77 |
{ |
| 78 |
VAStatus vaStatus = VA_STATUS_ERROR_UNKNOWN; |
| 79 |
|
| 80 |
if (!getenv("LIBVA_DRI3_DISABLE")) |
| 81 |
vaStatus = va_DRI3_GetDriverNames(pDisplayContext, drivers, num_drivers); |
| 82 |
if (vaStatus != VA_STATUS_SUCCESS) |
| 83 |
vaStatus = va_DRI2_GetDriverNames(pDisplayContext, drivers, num_drivers); |
| 84 |
#ifdef HAVE_NVCTRL |
| 85 |
if (vaStatus != VA_STATUS_SUCCESS) |
| 86 |
vaStatus = va_NVCTRL_GetDriverNames(pDisplayContext, drivers, num_drivers); |
| 87 |
#endif |
| 88 |
#ifdef HAVE_FGLRX |
| 89 |
if (vaStatus != VA_STATUS_SUCCESS) |
| 90 |
vaStatus = va_FGLRX_GetDriverNames(pDisplayContext, drivers, num_drivers); |
| 91 |
#endif |
| 92 |
|
| 93 |
return vaStatus; |
| 94 |
} |
| 95 |
|
| 96 |
VADisplay vaGetDisplay( |
| 97 |
Display *native_dpy /* implementation specific */ |
| 98 |
) |
| 99 |
{ |
| 100 |
VADisplayContextP pDisplayContext; |
| 101 |
VADriverContextP pDriverContext; |
| 102 |
struct dri_state *dri_state; |
| 103 |
|
| 104 |
if (!native_dpy) |
| 105 |
return NULL; |
| 106 |
|
| 107 |
pDisplayContext = va_newDisplayContext(); |
| 108 |
if (!pDisplayContext) |
| 109 |
return NULL; |
| 110 |
|
| 111 |
pDisplayContext->vaDestroy = va_DisplayContextDestroy; |
| 112 |
pDisplayContext->vaGetDriverNames = va_DisplayContextGetDriverNames; |
| 113 |
|
| 114 |
pDriverContext = va_newDriverContext(pDisplayContext); |
| 115 |
if (!pDriverContext) { |
| 116 |
free(pDisplayContext); |
| 117 |
return NULL; |
| 118 |
} |
| 119 |
|
| 120 |
pDriverContext->native_dpy = (void *)native_dpy; |
| 121 |
pDriverContext->x11_screen = XDefaultScreen(native_dpy); |
| 122 |
pDriverContext->display_type = VA_DISPLAY_X11; |
| 123 |
|
| 124 |
dri_state = calloc(1, sizeof(*dri_state)); |
| 125 |
if (!dri_state) { |
| 126 |
free(pDisplayContext); |
| 127 |
free(pDriverContext); |
| 128 |
return NULL; |
| 129 |
} |
| 130 |
|
| 131 |
dri_state->base.fd = -1; |
| 132 |
dri_state->base.auth_type = VA_NONE; |
| 133 |
|
| 134 |
pDriverContext->drm_state = dri_state; |
| 135 |
|
| 136 |
return (VADisplay)pDisplayContext; |
| 137 |
} |
| 138 |
|
| 139 |
void va_TracePutSurface( |
| 140 |
VADisplay dpy, |
| 141 |
VASurfaceID surface, |
| 142 |
void *draw, /* the target Drawable */ |
| 143 |
short srcx, |
| 144 |
short srcy, |
| 145 |
unsigned short srcw, |
| 146 |
unsigned short srch, |
| 147 |
short destx, |
| 148 |
short desty, |
| 149 |
unsigned short destw, |
| 150 |
unsigned short desth, |
| 151 |
VARectangle *cliprects, /* client supplied clip list */ |
| 152 |
unsigned int number_cliprects, /* number of clip rects in the clip list */ |
| 153 |
unsigned int flags /* de-interlacing flags */ |
| 154 |
); |
| 155 |
|
| 156 |
VAStatus vaPutSurface( |
| 157 |
VADisplay dpy, |
| 158 |
VASurfaceID surface, |
| 159 |
Drawable draw, /* X Drawable */ |
| 160 |
short srcx, |
| 161 |
short srcy, |
| 162 |
unsigned short srcw, |
| 163 |
unsigned short srch, |
| 164 |
short destx, |
| 165 |
short desty, |
| 166 |
unsigned short destw, |
| 167 |
unsigned short desth, |
| 168 |
VARectangle *cliprects, /* client supplied clip list */ |
| 169 |
unsigned int number_cliprects, /* number of clip rects in the clip list */ |
| 170 |
unsigned int flags /* de-interlacing flags */ |
| 171 |
) |
| 172 |
{ |
| 173 |
VADriverContextP ctx; |
| 174 |
VAStatus vaStatus = VA_STATUS_SUCCESS; |
| 175 |
CHECK_DISPLAY(dpy); |
| 176 |
ctx = CTX(dpy); |
| 177 |
|
| 178 |
VA_TRACE_LOG(va_TracePutSurface, dpy, surface, (void *)draw, srcx, srcy, srcw, srch, |
| 179 |
destx, desty, destw, desth, |
| 180 |
cliprects, number_cliprects, flags); |
| 181 |
|
| 182 |
vaStatus = ctx->vtable->vaPutSurface(ctx, surface, (void *)draw, srcx, srcy, srcw, srch, |
| 183 |
destx, desty, destw, desth, |
| 184 |
cliprects, number_cliprects, flags); |
| 185 |
VA_TRACE_RET(dpy, vaStatus); |
| 186 |
return vaStatus; |
| 187 |
} |