forked from i-rinat/libvdpau-va-gl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvdpau-entry.c
176 lines (155 loc) · 4.68 KB
/
vdpau-entry.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
/*
* Copyright 2013 Rinat Ibragimov
*
* This file is part of libvdpau-va-gl
*
* libvdpau-va-gl is distributed under the terms of the LGPLv3. See COPYING for details.
*/
#define _XOPEN_SOURCE 500
#define _GNU_SOURCE
#include <ctype.h>
#include <vdpau/vdpau.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "handle-storage.h"
#include "vdpau-soft.h"
#include "vdpau-trace.h"
#include "globals.h"
#include <sys/syscall.h>
#include <unistd.h>
void
trc_hk(void *longterm_param, void *shortterm_param, int origin, int after)
{
(void)longterm_param;
(void)origin;
int before = !after;
if (global.quirks.log_call_duration) {
static __thread struct timespec start_ts = {0, 0};
if (before) {
clock_gettime(CLOCK_MONOTONIC, &start_ts);
}
if (after) {
struct timespec end_ts;
clock_gettime(CLOCK_MONOTONIC, &end_ts);
double diff = (end_ts.tv_sec - start_ts.tv_sec) +
(end_ts.tv_nsec - start_ts.tv_nsec) / 1.0e9;
printf("Duration %7.5f secs, %s, %s\n",
diff, reverse_func_id(origin), reverse_status((VdpStatus)shortterm_param));
}
}
if (before && global.quirks.log_timestamp) {
struct timespec now;
clock_gettime(CLOCK_REALTIME, &now);
printf("%d.%03d ", (int)now.tv_sec, (int)now.tv_nsec/1000000);
}
if (before && global.quirks.log_thread_id) {
printf("[%5d] ", (pid_t)syscall(__NR_gettid));
}
}
static
void
initialize_quirks(void)
{
global.quirks.buggy_XCloseDisplay = 0;
global.quirks.show_watermark = 0;
global.quirks.log_thread_id = 0;
global.quirks.log_call_duration = 0;
global.quirks.log_pq_delay = 0;
global.quirks.log_timestamp = 0;
global.quirks.avoid_va = 0;
const char *value = getenv("VDPAU_QUIRKS");
if (!value)
return;
char *value_lc = strdup(value);
if (NULL == value_lc)
return;
for (int k = 0; value_lc[k] != 0; k ++)
value_lc[k] = tolower(value_lc[k]);
// tokenize string
const char delimiter = ',';
char *item_start = value_lc;
char *ptr = item_start;
while (1) {
int last = (0 == *ptr);
if (delimiter == *ptr || 0 == *ptr) {
*ptr = 0;
if (!strcmp("xclosedisplay", item_start)) {
global.quirks.buggy_XCloseDisplay = 1;
} else
if (!strcmp("showwatermark", item_start)) {
global.quirks.show_watermark = 1;
} else
if (!strcmp("logthreadid", item_start)) {
global.quirks.log_thread_id = 1;
} else
if (!strcmp("logcallduration", item_start)) {
global.quirks.log_call_duration = 1;
} else
if (!strcmp("logpqdelay", item_start)) {
global.quirks.log_pq_delay = 1;
} else
if (!strcmp("logtimestamp", item_start)) {
global.quirks.log_timestamp = 1;
} else
if (!strcmp("avoidva", item_start)) {
global.quirks.avoid_va = 1;
}
item_start = ptr + 1;
}
ptr ++;
if (last)
break;
}
free(value_lc);
}
__attribute__((constructor))
static
void
library_constructor(void)
{
handle_initialize_storage();
// Initialize global data
pthread_mutex_init(&global.glx_ctx_stack_mutex, NULL);
initialize_quirks();
// initialize tracer
traceSetTarget(stdout);
traceSetHook(trc_hk, NULL);
traceInfo("Software VDPAU backend library initialized\n");
#ifdef NDEBUG
traceEnableTracing(0);
#else
traceEnableTracing(1);
#endif
const char *value = getenv("VDPAU_LOG");
if (value) {
// enable tracing when variable present
traceEnableTracing(1);
char *value_lc = strdup(value); // convert to lowercase
for (int k = 0; value_lc[k] != 0; k ++) value_lc[k] = tolower(value_lc[k]);
// and disable tracing when variable value equals one of the following values
if (!strcmp(value_lc, "0") ||
!strcmp(value_lc, "false") ||
!strcmp(value_lc, "off") ||
!strcmp(value_lc, "disable") ||
!strcmp(value_lc, "disabled"))
{
traceEnableTracing(0);
}
free(value_lc);
}
}
__attribute__((destructor))
static
void
library_destructor(void)
{
handle_destory_storage();
}
__attribute__ ((visibility("default")))
VdpStatus
vdp_imp_device_create_x11(Display *display, int screen, VdpDevice *device,
VdpGetProcAddress **get_proc_address)
{
return traceVdpDeviceCreateX11(display, screen, device, get_proc_address);
}