summaryrefslogtreecommitdiff
path: root/src/gallium/winsys/g3dvl/nouveau/nouveau_context_vl.c
blob: dfc4905bc036190d0a5f16ae7666f7d2c7d97ac2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#include "nouveau_context_vl.h"
#include <pipe/p_defines.h>
#include <pipe/p_context.h>
#include <pipe/p_screen.h>
#include <util/u_memory.h>
#include <common/nouveau_dri.h>
#include <common/nouveau_local.h>
#include <common/nouveau_winsys_pipe.h>
#include "nouveau_screen_vl.h"

/*
#ifdef DEBUG
static const struct dri_debug_control debug_control[] = {
	{ "bo", DEBUG_BO },
	{ NULL, 0 }
};
int __nouveau_debug = 0;
#endif
*/

int
nouveau_context_create(dri_context_t *dri_context)
{
	dri_screen_t			*dri_screen;
	struct nouveau_screen_vl	*nv_screen;
	struct nouveau_context_vl	*nv;

	assert (dri_context);

	dri_screen = dri_context->dri_screen;
	nv_screen = dri_screen->private;
	nv = CALLOC_STRUCT(nouveau_context_vl);

	if (!nv)
		return 1;

	if (nouveau_context_init(&nv_screen->base, dri_context->drm_context,
	                        (drmLock*)&dri_screen->sarea->lock, NULL, &nv->base))
	{
		FREE(nv);
		return 1;
	}

	dri_context->private = (void*)nv;
	nv->dri_context = dri_context;
	nv->nv_screen  = nv_screen;

	/*
	driParseConfigFiles(&nv->dri_option_cache, &nv_screen->option_cache,
			    nv->dri_screen->myNum, "nouveau");
#ifdef DEBUG
	__nouveau_debug = driParseDebugString(getenv("NOUVEAU_DEBUG"),
					      debug_control);
#endif
	*/

	nv->base.nvc->pctx[nv->base.pctx_id]->priv = nv;

	return 0;
}

void
nouveau_context_destroy(dri_context_t *dri_context)
{
	struct nouveau_context_vl *nv = dri_context->private;

	assert(dri_context);

	nouveau_context_cleanup(&nv->base);

	FREE(nv);
}

int
nouveau_context_bind(struct nouveau_context_vl *nv, dri_drawable_t *dri_drawable)
{
	assert(nv);
	assert(dri_drawable);

	if (nv->dri_drawable != dri_drawable)
	{
		nv->dri_drawable = dri_drawable;
		dri_drawable->private = nv;
	}

	return 0;
}

int
nouveau_context_unbind(struct nouveau_context_vl *nv)
{
	assert(nv);

	nv->dri_drawable = NULL;

	return 0;
}

/* Show starts here */

int bind_pipe_drawable(struct pipe_context *pipe, Drawable drawable)
{
	struct nouveau_context_vl	*nv;
	dri_drawable_t			*dri_drawable;

	assert(pipe);

	nv = pipe->priv;

	driCreateDrawable(nv->nv_screen->dri_screen, drawable, &dri_drawable);

	nouveau_context_bind(nv, dri_drawable);

	return 0;
}

int unbind_pipe_drawable(struct pipe_context *pipe)
{
	assert (pipe);

	nouveau_context_unbind(pipe->priv);

	return 0;
}

struct pipe_context* create_pipe_context(Display *display, int screen)
{
	dri_screen_t			*dri_screen;
	dri_framebuffer_t		dri_framebuf;
	dri_context_t			*dri_context;
	struct nouveau_context_vl	*nv;

	assert(display);

	driCreateScreen(display, screen, &dri_screen, &dri_framebuf);
	driCreateContext(dri_screen, XDefaultVisual(display, screen), &dri_context);

	nouveau_screen_create(dri_screen, &dri_framebuf);
	nouveau_context_create(dri_context);

	nv = dri_context->private;

	return nv->base.nvc->pctx[nv->base.pctx_id];
}

int destroy_pipe_context(struct pipe_context *pipe)
{
	struct pipe_screen		*screen;
	struct pipe_winsys		*winsys;
	struct nouveau_context_vl	*nv;
	dri_screen_t			*dri_screen;
	dri_context_t			*dri_context;

	assert(pipe);

	screen = pipe->screen;
	winsys = pipe->winsys;
	nv = pipe->priv;
	dri_context = nv->dri_context;
	dri_screen = dri_context->dri_screen;

	pipe->destroy(pipe);
	screen->destroy(screen);
	FREE(winsys);

	nouveau_context_destroy(dri_context);
	nouveau_screen_destroy(dri_screen);
	driDestroyContext(dri_context);
	driDestroyScreen(dri_screen);

	return 0;
}