dfc4905bc036190d0a5f16ae7666f7d2c7d97ac2
[profile/ivi/mesa.git] / src / gallium / winsys / g3dvl / nouveau / nouveau_context_vl.c
1 #include "nouveau_context_vl.h"
2 #include <pipe/p_defines.h>
3 #include <pipe/p_context.h>
4 #include <pipe/p_screen.h>
5 #include <util/u_memory.h>
6 #include <common/nouveau_dri.h>
7 #include <common/nouveau_local.h>
8 #include <common/nouveau_winsys_pipe.h>
9 #include "nouveau_screen_vl.h"
10
11 /*
12 #ifdef DEBUG
13 static const struct dri_debug_control debug_control[] = {
14         { "bo", DEBUG_BO },
15         { NULL, 0 }
16 };
17 int __nouveau_debug = 0;
18 #endif
19 */
20
21 int
22 nouveau_context_create(dri_context_t *dri_context)
23 {
24         dri_screen_t                    *dri_screen;
25         struct nouveau_screen_vl        *nv_screen;
26         struct nouveau_context_vl       *nv;
27
28         assert (dri_context);
29
30         dri_screen = dri_context->dri_screen;
31         nv_screen = dri_screen->private;
32         nv = CALLOC_STRUCT(nouveau_context_vl);
33
34         if (!nv)
35                 return 1;
36
37         if (nouveau_context_init(&nv_screen->base, dri_context->drm_context,
38                                 (drmLock*)&dri_screen->sarea->lock, NULL, &nv->base))
39         {
40                 FREE(nv);
41                 return 1;
42         }
43
44         dri_context->private = (void*)nv;
45         nv->dri_context = dri_context;
46         nv->nv_screen  = nv_screen;
47
48         /*
49         driParseConfigFiles(&nv->dri_option_cache, &nv_screen->option_cache,
50                             nv->dri_screen->myNum, "nouveau");
51 #ifdef DEBUG
52         __nouveau_debug = driParseDebugString(getenv("NOUVEAU_DEBUG"),
53                                               debug_control);
54 #endif
55         */
56
57         nv->base.nvc->pctx[nv->base.pctx_id]->priv = nv;
58
59         return 0;
60 }
61
62 void
63 nouveau_context_destroy(dri_context_t *dri_context)
64 {
65         struct nouveau_context_vl *nv = dri_context->private;
66
67         assert(dri_context);
68
69         nouveau_context_cleanup(&nv->base);
70
71         FREE(nv);
72 }
73
74 int
75 nouveau_context_bind(struct nouveau_context_vl *nv, dri_drawable_t *dri_drawable)
76 {
77         assert(nv);
78         assert(dri_drawable);
79
80         if (nv->dri_drawable != dri_drawable)
81         {
82                 nv->dri_drawable = dri_drawable;
83                 dri_drawable->private = nv;
84         }
85
86         return 0;
87 }
88
89 int
90 nouveau_context_unbind(struct nouveau_context_vl *nv)
91 {
92         assert(nv);
93
94         nv->dri_drawable = NULL;
95
96         return 0;
97 }
98
99 /* Show starts here */
100
101 int bind_pipe_drawable(struct pipe_context *pipe, Drawable drawable)
102 {
103         struct nouveau_context_vl       *nv;
104         dri_drawable_t                  *dri_drawable;
105
106         assert(pipe);
107
108         nv = pipe->priv;
109
110         driCreateDrawable(nv->nv_screen->dri_screen, drawable, &dri_drawable);
111
112         nouveau_context_bind(nv, dri_drawable);
113
114         return 0;
115 }
116
117 int unbind_pipe_drawable(struct pipe_context *pipe)
118 {
119         assert (pipe);
120
121         nouveau_context_unbind(pipe->priv);
122
123         return 0;
124 }
125
126 struct pipe_context* create_pipe_context(Display *display, int screen)
127 {
128         dri_screen_t                    *dri_screen;
129         dri_framebuffer_t               dri_framebuf;
130         dri_context_t                   *dri_context;
131         struct nouveau_context_vl       *nv;
132
133         assert(display);
134
135         driCreateScreen(display, screen, &dri_screen, &dri_framebuf);
136         driCreateContext(dri_screen, XDefaultVisual(display, screen), &dri_context);
137
138         nouveau_screen_create(dri_screen, &dri_framebuf);
139         nouveau_context_create(dri_context);
140
141         nv = dri_context->private;
142
143         return nv->base.nvc->pctx[nv->base.pctx_id];
144 }
145
146 int destroy_pipe_context(struct pipe_context *pipe)
147 {
148         struct pipe_screen              *screen;
149         struct pipe_winsys              *winsys;
150         struct nouveau_context_vl       *nv;
151         dri_screen_t                    *dri_screen;
152         dri_context_t                   *dri_context;
153
154         assert(pipe);
155
156         screen = pipe->screen;
157         winsys = pipe->winsys;
158         nv = pipe->priv;
159         dri_context = nv->dri_context;
160         dri_screen = dri_context->dri_screen;
161
162         pipe->destroy(pipe);
163         screen->destroy(screen);
164         FREE(winsys);
165
166         nouveau_context_destroy(dri_context);
167         nouveau_screen_destroy(dri_screen);
168         driDestroyContext(dri_context);
169         driDestroyScreen(dri_screen);
170
171         return 0;
172 }