Merge remote branch 'upstream/gallium-0.2' into nouveau-gallium-0.2
[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 nouveau_check_dri_drm_ddx(dri_version_t *dri, dri_version_t *drm, dri_version_t *ddx)
22 {
23 static const dri_version_t ddx_expected = {0, 0, NOUVEAU_DRM_HEADER_PATCHLEVEL};
24 static const dri_version_t dri_expected = {4, 0, 0};
25 static const dri_version_t drm_expected = {0, 0, NOUVEAU_DRM_HEADER_PATCHLEVEL};
26
27 assert(dri);
28 assert(drm);
29 assert(ddx);
30
31 if (dri->major != dri_expected.major || dri->minor < dri_expected.minor)
32 {
33 NOUVEAU_ERR("Unexpected DRI version.\n");
34 return 1;
35 }
36 if (drm->major != drm_expected.major || drm->minor < drm_expected.minor)
37 {
38 NOUVEAU_ERR("Unexpected DRM version.\n");
39 return 1;
40 }
41 if (ddx->major != ddx_expected.major || ddx->minor < ddx_expected.minor)
42 {
43 NOUVEAU_ERR("Unexpected DDX version.\n");
44 return 1;
45 }
46
47 return 0;
48 }
49
50 int
51 nouveau_screen_create(dri_screen_t *dri_screen, dri_framebuffer_t *dri_framebuf)
52 {
53 struct nouveau_dri *nv_dri = dri_framebuf->private;
54 struct nouveau_screen *nv_screen;
55 int ret;
56
57 if (nouveau_check_dri_drm_ddx(&dri_screen->dri, &dri_screen->drm, &dri_screen->ddx))
58 return 1;
59
60 nv_screen = CALLOC_STRUCT(nouveau_screen);
61 if (!nv_screen)
62 return 1;
63 nv_screen->dri_screen = dri_screen;
64 dri_screen->private = (void*)nv_screen;
65
66 /*
67 driParseOptionInfo(&nv_screen->option_cache,
68 __driConfigOptions, __driNConfigOptions);
69 */
70
71 if ((ret = nouveau_device_open_existing(&nv_screen->device, 0,
72 dri_screen->fd, 0))) {
73 NOUVEAU_ERR("Failed opening nouveau device: %d.\n", ret);
74 return 1;
75 }
76
77 nv_screen->front_offset = nv_dri->front_offset;
78 nv_screen->front_pitch = nv_dri->front_pitch * (nv_dri->bpp / 8);
79 nv_screen->front_cpp = nv_dri->bpp / 8;
80 nv_screen->front_height = nv_dri->height;
81
82 return 0;
83 }
84
85 void
86 nouveau_screen_destroy(dri_screen_t *dri_screen)
87 {
88 struct nouveau_screen *nv_screen = dri_screen->private;
89
90 FREE(nv_screen);
91 }
92