2
* Copyright (c) 2012 Intel Corporation. All Rights Reserved.
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:
12
* The above copyright notice and this permission notice (including the
13
* next paragraph) shall be included in all copies or substantial portions
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.
24
#include "va_dricommon.h"
27
static int x11_error_code = 0;
28
static int (*old_error_handler)(Display *, XErrorEvent *);
31
error_handler(Display *dpy, XErrorEvent *error)
33
x11_error_code = error->error_code;
41
old_error_handler = XSetErrorHandler(error_handler);
45
x11_untrap_errors(void)
47
XSetErrorHandler(old_error_handler);
48
return x11_error_code;
52
is_window(Display *dpy, Drawable drawable)
54
XWindowAttributes wattr;
57
XGetWindowAttributes(dpy, drawable, &wattr);
58
return x11_untrap_errors() == 0;
61
static struct dri_drawable *
62
do_drawable_hash(VADriverContextP ctx, XID drawable)
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];
68
while (dri_drawable) {
69
if (dri_drawable->x_drawable == drawable)
71
dri_drawable = dri_drawable->next;
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;
84
free_drawable(VADriverContextP ctx, struct dri_drawable* dri_drawable)
86
struct dri_state *dri_state = (struct dri_state *)ctx->drm_state;
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;
99
free_drawable_hashtable(VADriverContextP ctx)
101
struct dri_state *dri_state = (struct dri_state *)ctx->drm_state;
103
struct dri_drawable *dri_drawable, *prev;
105
for (i = 0; i < DRAWABLE_HASH_SZ; i++) {
106
dri_drawable = dri_state->drawable_hash[i];
108
while (dri_drawable) {
110
dri_drawable = prev->next;
111
dri_state->destroyDrawable(ctx, prev);
114
dri_state->drawable_hash[i] = NULL;
118
struct dri_drawable *
119
dri_get_drawable(VADriverContextP ctx, XID drawable)
121
return do_drawable_hash(ctx, drawable);
125
dri_swap_buffer(VADriverContextP ctx, struct dri_drawable *dri_drawable)
127
struct dri_state *dri_state = (struct dri_state *)ctx->drm_state;
129
dri_state->swapBuffer(ctx, dri_drawable);
133
dri_get_rendering_buffer(VADriverContextP ctx, struct dri_drawable *dri_drawable)
135
struct dri_state *dri_state = (struct dri_state *)ctx->drm_state;
137
return dri_state->getRenderingBuffer(ctx, dri_drawable);