Merge branch 'master' of ssh://git@moblin.intel.com/umg-moorestown-libva
[profile/ivi/libva.git] / va / x11 / va_dricommon.c
1 #include "va_dricommon.h"
2
3 static struct dri_drawable *                                                                                                                                                                                   
4 do_drawable_hash(VADriverContextP ctx, XID drawable)
5 {
6     struct dri_state *dri_state = (struct dri_state *)ctx->dri_state;
7     int index = drawable % DRAWABLE_HASH_SZ;
8     struct dri_drawable *dri_drawable = dri_state->drawable_hash[index];
9
10     while (dri_drawable) {
11         if (dri_drawable->x_drawable == drawable)
12             return dri_drawable;
13         dri_drawable = dri_drawable->next;
14     }
15
16     dri_drawable = dri_state->createDrawable(ctx, drawable);
17     dri_drawable->x_drawable = drawable;
18     dri_drawable->next = dri_state->drawable_hash[index];
19     dri_state->drawable_hash[index] = dri_drawable;
20
21     return dri_drawable;
22 }
23
24 void
25 free_drawable_hashtable(VADriverContextP ctx)
26 {
27     struct dri_state *dri_state = (struct dri_state *)ctx->dri_state;
28     int i;
29     struct dri_drawable *dri_drawable, *prev;
30
31     for (i = 0; i < DRAWABLE_HASH_SZ; i++) {
32         dri_drawable = dri_state->drawable_hash[i];
33
34         while (dri_drawable) {
35             prev = dri_drawable;
36             dri_drawable = prev->next;
37             dri_state->destroyDrawable(ctx, prev);
38         }
39     }
40 }
41
42 struct dri_drawable *
43 dri_get_drawable(VADriverContextP ctx, XID drawable)
44 {
45     return do_drawable_hash(ctx, drawable);
46 }
47
48 void 
49 dri_swap_buffer(VADriverContextP ctx, struct dri_drawable *dri_drawable)
50 {
51     struct dri_state *dri_state = (struct dri_state *)ctx->dri_state;
52
53     dri_state->swapBuffer(ctx, dri_drawable);
54 }
55
56 union dri_buffer *
57 dri_get_rendering_buffer(VADriverContextP ctx, struct dri_drawable *dri_drawable)
58 {
59     struct dri_state *dri_state = (struct dri_state *)ctx->dri_state;
60     
61     return dri_state->getRenderingBuffer(ctx, dri_drawable);
62 }