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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
|
#include "utils.h"
#include "vblank.h"
#include "xmlpool.h"
#include "pipe/p_context.h"
#include "state_tracker/st_public.h"
#include "state_tracker/st_cb_fbo.h"
#include "nouveau_context.h"
#include "nouveau_device.h"
#include "nouveau_drm.h"
#include "nouveau_dri.h"
#include "nouveau_local.h"
#include "nouveau_screen.h"
#include "nouveau_swapbuffers.h"
#if NOUVEAU_DRM_HEADER_PATCHLEVEL != 10
#error nouveau_drm.h version does not match expected version
#endif
PUBLIC const char __driConfigOptions[] =
DRI_CONF_BEGIN
DRI_CONF_END;
static const GLuint __driNConfigOptions = 0;
extern const struct dri_extension common_extensions[];
extern const struct dri_extension nv40_extensions[];
static GLboolean
nouveau_screen_create(__DRIscreenPrivate *driScrnPriv)
{
struct nouveau_dri *nv_dri = driScrnPriv->pDevPriv;
struct nouveau_screen *nv_screen;
int ret;
if (driScrnPriv->devPrivSize != sizeof(struct nouveau_dri)) {
NOUVEAU_ERR("DRI struct mismatch between DDX/DRI\n");
return GL_FALSE;
}
nv_screen = CALLOC_STRUCT(nouveau_screen);
if (!nv_screen)
return GL_FALSE;
nv_screen->driScrnPriv = driScrnPriv;
driScrnPriv->private = (void *)nv_screen;
driParseOptionInfo(&nv_screen->option_cache,
__driConfigOptions, __driNConfigOptions);
if ((ret = nouveau_device_open_existing(&nv_screen->device, 0,
driScrnPriv->fd, 0))) {
NOUVEAU_ERR("Failed opening nouveau device: %d\n", ret);
return GL_FALSE;
}
nv_screen->front_offset = nv_dri->front_offset;
nv_screen->front_pitch = nv_dri->front_pitch * (nv_dri->bpp / 8);
nv_screen->front_cpp = nv_dri->bpp / 8;
nv_screen->front_height = nv_dri->height;
return GL_TRUE;
}
static void
nouveau_screen_destroy(__DRIscreenPrivate *driScrnPriv)
{
struct nouveau_screen *nv_screen = driScrnPriv->private;
driScrnPriv->private = NULL;
FREE(nv_screen);
}
static GLboolean
nouveau_create_buffer(__DRIscreenPrivate * driScrnPriv,
__DRIdrawablePrivate * driDrawPriv,
const __GLcontextModes *glVis, GLboolean pixmapBuffer)
{
struct nouveau_framebuffer *nvfb;
if (pixmapBuffer)
return GL_FALSE;
nvfb = CALLOC_STRUCT(nouveau_framebuffer);
if (!nvfb)
return GL_FALSE;
nvfb->stfb = st_create_framebuffer(glVis, GL_TRUE, (void*)nvfb);
if (!nvfb->stfb) {
free(nvfb);
return GL_FALSE;
}
driDrawPriv->driverPrivate = (void *)nvfb;
return GL_TRUE;
}
static void
nouveau_destroy_buffer(__DRIdrawablePrivate * driDrawPriv)
{
struct nouveau_framebuffer *nvfb;
nvfb = (struct nouveau_framebuffer *)driDrawPriv;
st_unreference_framebuffer(&nvfb->stfb);
free(nvfb);
}
static struct __DriverAPIRec
nouveau_api = {
.InitDriver = nouveau_screen_create,
.DestroyScreen = nouveau_screen_destroy,
.CreateContext = nouveau_context_create,
.DestroyContext = nouveau_context_destroy,
.CreateBuffer = nouveau_create_buffer,
.DestroyBuffer = nouveau_destroy_buffer,
.SwapBuffers = nouveau_swap_buffers,
.MakeCurrent = nouveau_context_bind,
.UnbindContext = nouveau_context_unbind,
.GetSwapInfo = NULL,
.GetMSC = NULL,
.WaitForMSC = NULL,
.WaitForSBC = NULL,
.SwapBuffersMSC = NULL,
.CopySubBuffer = nouveau_copy_sub_buffer,
.setTexOffset = NULL
};
static __GLcontextModes *
nouveau_fill_in_modes(unsigned pixel_bits, unsigned depth_bits,
unsigned stencil_bits, GLboolean have_back_buffer)
{
__GLcontextModes * modes;
__GLcontextModes * m;
unsigned num_modes;
unsigned depth_buffer_factor;
unsigned back_buffer_factor;
int i;
static const struct {
GLenum format;
GLenum type;
} fb_format_array[] = {
{ GL_RGB , GL_UNSIGNED_SHORT_5_6_5 },
{ GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV },
{ GL_BGR , GL_UNSIGNED_INT_8_8_8_8_REV },
};
/* GLX_SWAP_COPY_OML is only supported because the Intel driver doesn't
* support pageflipping at all.
*/
static const GLenum back_buffer_modes[] = {
GLX_NONE, GLX_SWAP_UNDEFINED_OML, GLX_SWAP_COPY_OML
};
u_int8_t depth_bits_array[4] = { 0, 16, 24, 24 };
u_int8_t stencil_bits_array[4] = { 0, 0, 0, 8 };
depth_buffer_factor = 4;
back_buffer_factor = (have_back_buffer) ? 3 : 1;
num_modes = ((pixel_bits==16) ? 1 : 2) *
depth_buffer_factor * back_buffer_factor * 4;
modes = (*dri_interface->createContextModes)(num_modes,
sizeof(__GLcontextModes));
m = modes;
for (i=((pixel_bits==16)?0:1);i<((pixel_bits==16)?1:3);i++) {
if (!driFillInModes(&m, fb_format_array[i].format,
fb_format_array[i].type,
depth_bits_array,
stencil_bits_array,
depth_buffer_factor,
back_buffer_modes,
back_buffer_factor,
GLX_TRUE_COLOR)) {
fprintf( stderr, "[%s:%u] Error creating FBConfig!\n",
__func__, __LINE__ );
return NULL;
}
if (!driFillInModes(&m, fb_format_array[i].format,
fb_format_array[i].type,
depth_bits_array,
stencil_bits_array,
depth_buffer_factor,
back_buffer_modes,
back_buffer_factor,
GLX_DIRECT_COLOR)) {
fprintf( stderr, "[%s:%u] Error creating FBConfig!\n",
__func__, __LINE__ );
return NULL;
}
}
return modes;
}
PUBLIC void *
__driCreateNewScreen_20050727(__DRInativeDisplay *dpy, int scrn,
__DRIscreen *psc, const __GLcontextModes * modes,
const __DRIversion * ddx_version,
const __DRIversion * dri_version,
const __DRIversion * drm_version,
const __DRIframebuffer * frame_buffer,
void * pSAREA, int fd, int internal_api_version,
const __DRIinterfaceMethods * interface,
__GLcontextModes ** driver_modes)
{
__DRIscreenPrivate *psp;
static const __DRIversion ddx_expected = { 1, 2, 0 };
static const __DRIversion dri_expected = { 4, 0, 0 };
static const __DRIversion drm_expected =
{ 0, 0, NOUVEAU_DRM_HEADER_PATCHLEVEL };
struct nouveau_dri *nv_dri = NULL;
dri_interface = interface;
if (!driCheckDriDdxDrmVersions2("nouveau",
dri_version, &dri_expected,
ddx_version, &ddx_expected,
drm_version, &drm_expected)) {
return NULL;
}
if (drm_expected.patch != drm_version->patch) {
fprintf(stderr, "Incompatible DRM patch level.\n"
"Expected: %d\n" "Current : %d\n",
drm_expected.patch, drm_version->patch);
return NULL;
}
psp = __driUtilCreateNewScreen(dpy, scrn, psc, NULL,
ddx_version, dri_version, drm_version,
frame_buffer, pSAREA, fd,
internal_api_version,
&nouveau_api);
if (psp == NULL)
return NULL;
nv_dri = psp->pDevPriv;
*driver_modes = nouveau_fill_in_modes(nv_dri->bpp,
(nv_dri->bpp == 16) ? 16 : 24,
(nv_dri->bpp == 16) ? 0 : 8,
1);
driInitExtensions(NULL, common_extensions, GL_FALSE);
driInitExtensions(NULL, nv40_extensions, GL_FALSE);
return (void *)psp;
}
|