g3dvl: Add Nouveau winsys, libdriclient.
[mesa.git] / src / gallium / winsys / g3dvl / nouveau / nouveau_screen.c
1 #include "pipe/p_context.h"
2 #include "pipe/p_util.h"
3 #include "nouveau_context.h"
4 #include "nouveau_drm.h"
5 #include "nouveau_dri.h"
6 #include "nouveau_local.h"
7 #include "nouveau_screen.h"
8 #include "nouveau_swapbuffers.h"
9
10 #if NOUVEAU_DRM_HEADER_PATCHLEVEL != 11
11 #error nouveau_drm.h version does not match expected version
12 #endif
13
14 /*
15 PUBLIC const char __driConfigOptions[] =
16 DRI_CONF_BEGIN
17 DRI_CONF_END;
18 static const GLuint __driNConfigOptions = 0;
19 */
20
21 int
22 nouveau_screen_create(dri_screen_t *dri_screen, dri_framebuffer_t *dri_framebuf)
23 {
24 /* XXX: Someone forgot to bump this? */
25 static const dri_version_t ddx_expected = {0, 0, 10 /*NOUVEAU_DRM_HEADER_PATCHLEVEL*/};
26 static const dri_version_t dri_expected = {4, 1, 0};
27 static const dri_version_t drm_expected = {0, 0, NOUVEAU_DRM_HEADER_PATCHLEVEL};
28
29 struct nouveau_dri *nv_dri = dri_framebuf->private;
30 struct nouveau_screen *nv_screen;
31 int ret;
32
33 if (!driCompareVersions(&ddx_expected, &dri_screen->ddx))
34 {
35 NOUVEAU_ERR("Unexpected DDX version.\n");
36 return 1;
37 }
38
39 if (!driCompareVersions(&drm_expected, &dri_screen->drm))
40 {
41 NOUVEAU_ERR("Unexpected DRM version.\n");
42 return 1;
43 }
44
45 if (!driCompareVersions(&dri_expected, &dri_screen->dri))
46 {
47 NOUVEAU_ERR("Unexpected DRI version.\n");
48 return 1;
49 }
50
51 if (dri_framebuf->private_size != sizeof(struct nouveau_dri)) {
52 NOUVEAU_ERR("DRI struct mismatch between DDX/DRI.\n");
53 return 1;
54 }
55
56 nv_screen = CALLOC_STRUCT(nouveau_screen);
57 if (!nv_screen)
58 return 1;
59 nv_screen->dri_screen = dri_screen;
60 dri_screen->private = (void*)nv_screen;
61
62 /*
63 driParseOptionInfo(&nv_screen->option_cache,
64 __driConfigOptions, __driNConfigOptions);
65 */
66
67 if ((ret = nouveau_device_open_existing(&nv_screen->device, 0,
68 dri_screen->fd, 0))) {
69 NOUVEAU_ERR("Failed opening nouveau device: %d.\n", ret);
70 return 1;
71 }
72
73 nv_screen->front_offset = nv_dri->front_offset;
74 nv_screen->front_pitch = nv_dri->front_pitch * (nv_dri->bpp / 8);
75 nv_screen->front_cpp = nv_dri->bpp / 8;
76 nv_screen->front_height = nv_dri->height;
77
78 return 0;
79 }
80
81 void
82 nouveau_screen_destroy(dri_screen_t *dri_screen)
83 {
84 struct nouveau_screen *nv_screen = dri_screen->private;
85
86 FREE(nv_screen);
87 }
88