~misterc/libva/Trunk

« back to all changes in this revision

Viewing changes to va/x11/va_dricommon.c

  • Committer: Sean V Kelley
  • Date: 2017-02-18 23:19:05 UTC
  • Revision ID: git-v1:7b8cc07dc7a9b954b9a8c9bde5091fb2e8d443dc
PROJECT HAS MOVED

See https://github.com/01org/libva

Signed-off-by: Sean V Kelley <seanvk@posteo.de>

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 
#include "va_dricommon.h"
25
 
 
26
 
// X error trap
27
 
static int x11_error_code = 0;
28
 
static int (*old_error_handler)(Display *, XErrorEvent *);
29
 
 
30
 
static int 
31
 
error_handler(Display *dpy, XErrorEvent *error)
32
 
{
33
 
    x11_error_code = error->error_code;
34
 
    return 0;
35
 
}
36
 
 
37
 
static void 
38
 
x11_trap_errors(void)
39
 
{
40
 
    x11_error_code    = 0;
41
 
    old_error_handler = XSetErrorHandler(error_handler);
42
 
}
43
 
 
44
 
static int 
45
 
x11_untrap_errors(void)
46
 
{
47
 
    XSetErrorHandler(old_error_handler);
48
 
    return x11_error_code;
49
 
}
50
 
 
51
 
static int 
52
 
is_window(Display *dpy, Drawable drawable)
53
 
{
54
 
    XWindowAttributes wattr;
55
 
 
56
 
    x11_trap_errors();
57
 
    XGetWindowAttributes(dpy, drawable, &wattr);
58
 
    return x11_untrap_errors() == 0;
59
 
}
60
 
 
61
 
static struct dri_drawable *
62
 
do_drawable_hash(VADriverContextP ctx, XID drawable)
63
 
{
64
 
    struct dri_state *dri_state = (struct dri_state *)ctx->drm_state;
65
 
    int index = drawable % DRAWABLE_HASH_SZ;
66
 
    struct dri_drawable *dri_drawable = dri_state->drawable_hash[index];
67
 
 
68
 
    while (dri_drawable) {
69
 
        if (dri_drawable->x_drawable == drawable)
70
 
            return dri_drawable;
71
 
        dri_drawable = dri_drawable->next;
72
 
    }
73
 
 
74
 
    dri_drawable = dri_state->createDrawable(ctx, drawable);
75
 
    dri_drawable->x_drawable = drawable;
76
 
    dri_drawable->is_window = is_window(ctx->native_dpy, drawable);
77
 
    dri_drawable->next = dri_state->drawable_hash[index];
78
 
    dri_state->drawable_hash[index] = dri_drawable;
79
 
 
80
 
    return dri_drawable;
81
 
}
82
 
 
83
 
void
84
 
free_drawable(VADriverContextP ctx, struct dri_drawable* dri_drawable)
85
 
{
86
 
    struct dri_state *dri_state = (struct dri_state *)ctx->drm_state;
87
 
    int i = 0;
88
 
 
89
 
    while (i < DRAWABLE_HASH_SZ) {
90
 
        if (dri_drawable == dri_state->drawable_hash[i]) {
91
 
            dri_state->destroyDrawable(ctx, dri_drawable);
92
 
            dri_state->drawable_hash[i] = NULL;
93
 
        }
94
 
        i++;
95
 
    }
96
 
}
97
 
 
98
 
void
99
 
free_drawable_hashtable(VADriverContextP ctx)
100
 
{
101
 
    struct dri_state *dri_state = (struct dri_state *)ctx->drm_state;
102
 
    int i;
103
 
    struct dri_drawable *dri_drawable, *prev;
104
 
 
105
 
    for (i = 0; i < DRAWABLE_HASH_SZ; i++) {
106
 
        dri_drawable = dri_state->drawable_hash[i];
107
 
 
108
 
        while (dri_drawable) {
109
 
            prev = dri_drawable;
110
 
            dri_drawable = prev->next;
111
 
            dri_state->destroyDrawable(ctx, prev);
112
 
        }
113
 
 
114
 
        dri_state->drawable_hash[i] = NULL;
115
 
    }
116
 
}
117
 
 
118
 
struct dri_drawable *
119
 
dri_get_drawable(VADriverContextP ctx, XID drawable)
120
 
{
121
 
    return do_drawable_hash(ctx, drawable);
122
 
}
123
 
 
124
 
void 
125
 
dri_swap_buffer(VADriverContextP ctx, struct dri_drawable *dri_drawable)
126
 
{
127
 
    struct dri_state *dri_state = (struct dri_state *)ctx->drm_state;
128
 
 
129
 
    dri_state->swapBuffer(ctx, dri_drawable);
130
 
}
131
 
 
132
 
union dri_buffer *
133
 
dri_get_rendering_buffer(VADriverContextP ctx, struct dri_drawable *dri_drawable)
134
 
{
135
 
    struct dri_state *dri_state = (struct dri_state *)ctx->drm_state;
136
 
    
137
 
    return dri_state->getRenderingBuffer(ctx, dri_drawable);
138
 
}