Merge commit 'origin/gallium-master-merge'
[mesa.git] / src / gallium / winsys / drm / nouveau / dri / nouveau_context_dri.c
1 #include <main/glheader.h>
2 #include <glapi/glthread.h>
3 #include <GL/internal/glcore.h>
4 #include <utils.h>
5
6 #include <state_tracker/st_public.h>
7 #include <state_tracker/st_context.h>
8 #include <pipe/p_defines.h>
9 #include <pipe/p_context.h>
10 #include <pipe/p_screen.h>
11
12 #include "../common/nouveau_winsys_pipe.h"
13 #include "../common/nouveau_dri.h"
14 #include "../common/nouveau_local.h"
15 #include "nouveau_context_dri.h"
16 #include "nouveau_screen_dri.h"
17
18 #ifdef DEBUG
19 static const struct dri_debug_control debug_control[] = {
20 { "bo", DEBUG_BO },
21 { NULL, 0 }
22 };
23 int __nouveau_debug = 0;
24 #endif
25
26 GLboolean
27 nouveau_context_create(const __GLcontextModes *glVis,
28 __DRIcontextPrivate *driContextPriv,
29 void *sharedContextPrivate)
30 {
31 __DRIscreenPrivate *driScrnPriv = driContextPriv->driScreenPriv;
32 struct nouveau_screen_dri *nv_screen = driScrnPriv->private;
33 struct nouveau_context_dri *nv = CALLOC_STRUCT(nouveau_context_dri);
34 struct st_context *st_share = NULL;
35 struct nouveau_context_dri *nv_share = NULL;
36 struct pipe_context *pipe;
37
38 if (sharedContextPrivate) {
39 st_share = ((struct nouveau_context_dri *)sharedContextPrivate)->st;
40 nv_share = st_share->pipe->priv;
41 }
42
43 if (nouveau_context_init(&nv_screen->base, driContextPriv->hHWContext,
44 (drmLock *)&driScrnPriv->pSAREA->lock,
45 &nv_share->base, &nv->base)) {
46 return GL_FALSE;
47 }
48
49 pipe = nv->base.nvc->pctx[nv->base.pctx_id];
50 driContextPriv->driverPrivate = (void *)nv;
51 //nv->nv_screen = nv_screen;
52 nv->dri_screen = driScrnPriv;
53
54 driParseConfigFiles(&nv->dri_option_cache, &nv_screen->option_cache,
55 nv->dri_screen->myNum, "nouveau");
56 #ifdef DEBUG
57 __nouveau_debug = driParseDebugString(getenv("NOUVEAU_DEBUG"),
58 debug_control);
59 #endif
60
61 nv->st = st_create_context(pipe, glVis, st_share);
62 return GL_TRUE;
63 }
64
65 void
66 nouveau_context_destroy(__DRIcontextPrivate *driContextPriv)
67 {
68 struct nouveau_context_dri *nv = driContextPriv->driverPrivate;
69
70 assert(nv);
71
72 st_finish(nv->st);
73 st_destroy_context(nv->st);
74
75 nouveau_context_cleanup(&nv->base);
76
77 FREE(nv);
78 }
79
80 GLboolean
81 nouveau_context_bind(__DRIcontextPrivate *driContextPriv,
82 __DRIdrawablePrivate *driDrawPriv,
83 __DRIdrawablePrivate *driReadPriv)
84 {
85 struct nouveau_context_dri *nv;
86 struct nouveau_framebuffer *draw, *read;
87
88 if (!driContextPriv) {
89 st_make_current(NULL, NULL, NULL);
90 return GL_TRUE;
91 }
92
93 nv = driContextPriv->driverPrivate;
94 draw = driDrawPriv->driverPrivate;
95 read = driReadPriv->driverPrivate;
96
97 st_make_current(nv->st, draw->stfb, read->stfb);
98
99 if ((nv->dri_drawable != driDrawPriv) ||
100 (nv->last_stamp != driDrawPriv->lastStamp)) {
101 nv->dri_drawable = driDrawPriv;
102 st_resize_framebuffer(draw->stfb, driDrawPriv->w,
103 driDrawPriv->h);
104 nv->last_stamp = driDrawPriv->lastStamp;
105 }
106
107 if (driDrawPriv != driReadPriv) {
108 st_resize_framebuffer(read->stfb, driReadPriv->w,
109 driReadPriv->h);
110 }
111
112 return GL_TRUE;
113 }
114
115 GLboolean
116 nouveau_context_unbind(__DRIcontextPrivate *driContextPriv)
117 {
118 struct nouveau_context_dri *nv = driContextPriv->driverPrivate;
119 (void)nv;
120
121 st_flush(nv->st, 0, NULL);
122 return GL_TRUE;
123 }
124