gallium: squash-merge of gallium screen context
[mesa.git] / src / gallium / state_trackers / egl / x11 / native_dri2.c
1 /*
2 * Mesa 3-D graphics library
3 * Version: 7.8
4 *
5 * Copyright (C) 2009-2010 Chia-I Wu <olv@0xlab.org>
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
25 #include "util/u_memory.h"
26 #include "util/u_math.h"
27 #include "util/u_format.h"
28 #include "util/u_inlines.h"
29 #include "pipe/p_compiler.h"
30 #include "pipe/p_screen.h"
31 #include "pipe/p_context.h"
32 #include "pipe/p_state.h"
33 #include "state_tracker/drm_api.h"
34 #include "egllog.h"
35
36 #include "native_x11.h"
37 #include "x11_screen.h"
38
39 enum dri2_surface_type {
40 DRI2_SURFACE_TYPE_WINDOW,
41 DRI2_SURFACE_TYPE_PIXMAP,
42 DRI2_SURFACE_TYPE_PBUFFER
43 };
44
45 struct dri2_display {
46 struct native_display base;
47 Display *dpy;
48 boolean own_dpy;
49
50 struct drm_api *api;
51 struct x11_screen *xscr;
52 int xscr_number;
53
54 struct dri2_config *configs;
55 int num_configs;
56 };
57
58 struct dri2_surface {
59 struct native_surface base;
60 Drawable drawable;
61 enum dri2_surface_type type;
62 enum pipe_format color_format;
63 struct dri2_display *dri2dpy;
64
65 struct pipe_texture *pbuffer_textures[NUM_NATIVE_ATTACHMENTS];
66 boolean have_back, have_fake;
67 int width, height;
68 unsigned int sequence_number;
69 };
70
71 struct dri2_config {
72 struct native_config base;
73 };
74
75 static INLINE struct dri2_display *
76 dri2_display(const struct native_display *ndpy)
77 {
78 return (struct dri2_display *) ndpy;
79 }
80
81 static INLINE struct dri2_surface *
82 dri2_surface(const struct native_surface *nsurf)
83 {
84 return (struct dri2_surface *) nsurf;
85 }
86
87 static INLINE struct dri2_config *
88 dri2_config(const struct native_config *nconf)
89 {
90 return (struct dri2_config *) nconf;
91 }
92
93 static boolean
94 dri2_surface_flush_frontbuffer(struct native_surface *nsurf)
95 {
96 struct dri2_surface *dri2surf = dri2_surface(nsurf);
97 struct dri2_display *dri2dpy = dri2surf->dri2dpy;
98
99 /* pbuffer is private */
100 if (dri2surf->type == DRI2_SURFACE_TYPE_PBUFFER)
101 return TRUE;
102
103 /* copy to real front buffer */
104 if (dri2surf->have_fake)
105 x11_drawable_copy_buffers(dri2dpy->xscr, dri2surf->drawable,
106 0, 0, dri2surf->width, dri2surf->height,
107 DRI2BufferFakeFrontLeft, DRI2BufferFrontLeft);
108
109 return TRUE;
110 }
111
112 static boolean
113 dri2_surface_swap_buffers(struct native_surface *nsurf)
114 {
115 struct dri2_surface *dri2surf = dri2_surface(nsurf);
116 struct dri2_display *dri2dpy = dri2surf->dri2dpy;
117
118 /* pbuffer is private */
119 if (dri2surf->type == DRI2_SURFACE_TYPE_PBUFFER)
120 return TRUE;
121
122 /* copy to front buffer */
123 if (dri2surf->have_back)
124 x11_drawable_copy_buffers(dri2dpy->xscr, dri2surf->drawable,
125 0, 0, dri2surf->width, dri2surf->height,
126 DRI2BufferBackLeft, DRI2BufferFrontLeft);
127
128 /* and update fake front buffer */
129 if (dri2surf->have_fake)
130 x11_drawable_copy_buffers(dri2dpy->xscr, dri2surf->drawable,
131 0, 0, dri2surf->width, dri2surf->height,
132 DRI2BufferFrontLeft, DRI2BufferFakeFrontLeft);
133
134 return TRUE;
135 }
136
137 static boolean
138 dri2_surface_validate(struct native_surface *nsurf, uint attachment_mask,
139 unsigned int *seq_num, struct pipe_texture **textures,
140 int *width, int *height)
141 {
142 struct dri2_surface *dri2surf = dri2_surface(nsurf);
143 struct dri2_display *dri2dpy = dri2surf->dri2dpy;
144 unsigned int dri2atts[NUM_NATIVE_ATTACHMENTS];
145 struct pipe_texture templ;
146 struct x11_drawable_buffer *xbufs;
147 int num_ins, num_outs, att, i;
148
149 if (attachment_mask) {
150 memset(&templ, 0, sizeof(templ));
151 templ.target = PIPE_TEXTURE_2D;
152 templ.last_level = 0;
153 templ.width0 = dri2surf->width;
154 templ.height0 = dri2surf->height;
155 templ.depth0 = 1;
156 templ.format = dri2surf->color_format;
157 templ.tex_usage = PIPE_TEXTURE_USAGE_RENDER_TARGET;
158
159 if (textures)
160 memset(textures, 0, sizeof(*textures) * NUM_NATIVE_ATTACHMENTS);
161 }
162
163 /* create textures for pbuffer */
164 if (dri2surf->type == DRI2_SURFACE_TYPE_PBUFFER) {
165 struct pipe_screen *screen = dri2dpy->base.screen;
166
167 for (att = 0; att < NUM_NATIVE_ATTACHMENTS; att++) {
168 struct pipe_texture *ptex = dri2surf->pbuffer_textures[att];
169
170 /* delay the allocation */
171 if (!native_attachment_mask_test(attachment_mask, att))
172 continue;
173
174 if (!ptex) {
175 ptex = screen->texture_create(screen, &templ);
176 dri2surf->pbuffer_textures[att] = ptex;
177 }
178
179 if (textures)
180 pipe_texture_reference(&textures[att], ptex);
181 }
182
183 if (seq_num)
184 *seq_num = dri2surf->sequence_number;
185 if (width)
186 *width = dri2surf->width;
187 if (height)
188 *height = dri2surf->height;
189
190 return TRUE;
191 }
192
193 /* prepare the attachments */
194 num_ins = 0;
195 for (att = 0; att < NUM_NATIVE_ATTACHMENTS; att++) {
196 if (native_attachment_mask_test(attachment_mask, att)) {
197 unsigned int dri2att;
198
199 switch (att) {
200 case NATIVE_ATTACHMENT_FRONT_LEFT:
201 dri2att = DRI2BufferFrontLeft;
202 break;
203 case NATIVE_ATTACHMENT_BACK_LEFT:
204 dri2att = DRI2BufferBackLeft;
205 break;
206 case NATIVE_ATTACHMENT_FRONT_RIGHT:
207 dri2att = DRI2BufferFrontRight;
208 break;
209 case NATIVE_ATTACHMENT_BACK_RIGHT:
210 dri2att = DRI2BufferBackRight;
211 break;
212 default:
213 assert(0);
214 dri2att = 0;
215 break;
216 }
217
218 dri2atts[num_ins] = dri2att;
219 num_ins++;
220 }
221 }
222
223 dri2surf->have_back = FALSE;
224 dri2surf->have_fake = FALSE;
225
226 /* remember old geometry */
227 templ.width0 = dri2surf->width;
228 templ.height0 = dri2surf->height;
229
230 xbufs = x11_drawable_get_buffers(dri2dpy->xscr, dri2surf->drawable,
231 &dri2surf->width, &dri2surf->height,
232 dri2atts, FALSE, num_ins, &num_outs);
233 if (!xbufs)
234 return FALSE;
235
236 if (templ.width0 != dri2surf->width || templ.height0 != dri2surf->height) {
237 /* are there cases where the buffers change and the geometry doesn't? */
238 dri2surf->sequence_number++;
239
240 templ.width0 = dri2surf->width;
241 templ.height0 = dri2surf->height;
242 }
243
244 for (i = 0; i < num_outs; i++) {
245 struct x11_drawable_buffer *xbuf = &xbufs[i];
246 const char *desc;
247 enum native_attachment natt;
248
249 switch (xbuf->attachment) {
250 case DRI2BufferFrontLeft:
251 natt = NATIVE_ATTACHMENT_FRONT_LEFT;
252 desc = "DRI2 Front Buffer";
253 break;
254 case DRI2BufferFakeFrontLeft:
255 natt = NATIVE_ATTACHMENT_FRONT_LEFT;
256 desc = "DRI2 Fake Front Buffer";
257 dri2surf->have_fake = TRUE;
258 break;
259 case DRI2BufferBackLeft:
260 natt = NATIVE_ATTACHMENT_BACK_LEFT;
261 desc = "DRI2 Back Buffer";
262 dri2surf->have_back = TRUE;
263 break;
264 default:
265 desc = NULL;
266 break;
267 }
268
269 if (!desc || !native_attachment_mask_test(attachment_mask, natt) ||
270 (textures && textures[natt])) {
271 if (!desc)
272 _eglLog(_EGL_WARNING, "unknown buffer %d", xbuf->attachment);
273 else if (!native_attachment_mask_test(attachment_mask, natt))
274 _eglLog(_EGL_WARNING, "unexpected buffer %d", xbuf->attachment);
275 else
276 _eglLog(_EGL_WARNING, "both real and fake front buffers are listed");
277 continue;
278 }
279
280 if (textures) {
281 struct pipe_texture *ptex =
282 dri2dpy->api->texture_from_shared_handle(dri2dpy->api,
283 dri2dpy->base.screen, &templ,
284 desc, xbuf->pitch, xbuf->name);
285 if (ptex) {
286 /* the caller owns the textures */
287 textures[natt] = ptex;
288 }
289 }
290 }
291
292 free(xbufs);
293
294 if (seq_num)
295 *seq_num = dri2surf->sequence_number;
296 if (width)
297 *width = dri2surf->width;
298 if (height)
299 *height = dri2surf->height;
300
301 return TRUE;
302 }
303
304 static void
305 dri2_surface_wait(struct native_surface *nsurf)
306 {
307 struct dri2_surface *dri2surf = dri2_surface(nsurf);
308 struct dri2_display *dri2dpy = dri2surf->dri2dpy;
309
310 if (dri2surf->have_fake) {
311 x11_drawable_copy_buffers(dri2dpy->xscr, dri2surf->drawable,
312 0, 0, dri2surf->width, dri2surf->height,
313 DRI2BufferFrontLeft, DRI2BufferFakeFrontLeft);
314 }
315 }
316
317 static void
318 dri2_surface_destroy(struct native_surface *nsurf)
319 {
320 struct dri2_surface *dri2surf = dri2_surface(nsurf);
321 int i;
322
323 for (i = 0; i < NUM_NATIVE_ATTACHMENTS; i++) {
324 struct pipe_texture *ptex = dri2surf->pbuffer_textures[i];
325 pipe_texture_reference(&ptex, NULL);
326 }
327
328 if (dri2surf->drawable)
329 x11_drawable_enable_dri2(dri2surf->dri2dpy->xscr,
330 dri2surf->drawable, FALSE);
331 free(dri2surf);
332 }
333
334 static struct dri2_surface *
335 dri2_display_create_surface(struct native_display *ndpy,
336 enum dri2_surface_type type,
337 Drawable drawable,
338 const struct native_config *nconf)
339 {
340 struct dri2_display *dri2dpy = dri2_display(ndpy);
341 struct dri2_config *dri2conf = dri2_config(nconf);
342 struct dri2_surface *dri2surf;
343
344 dri2surf = CALLOC_STRUCT(dri2_surface);
345 if (!dri2surf)
346 return NULL;
347
348 if (drawable)
349 x11_drawable_enable_dri2(dri2dpy->xscr, drawable, TRUE);
350
351 dri2surf->dri2dpy = dri2dpy;
352 dri2surf->type = type;
353 dri2surf->drawable = drawable;
354 dri2surf->color_format = dri2conf->base.color_format;
355
356 dri2surf->base.destroy = dri2_surface_destroy;
357 dri2surf->base.swap_buffers = dri2_surface_swap_buffers;
358 dri2surf->base.flush_frontbuffer = dri2_surface_flush_frontbuffer;
359 dri2surf->base.validate = dri2_surface_validate;
360 dri2surf->base.wait = dri2_surface_wait;
361
362 return dri2surf;
363 }
364
365 static struct native_surface *
366 dri2_display_create_window_surface(struct native_display *ndpy,
367 EGLNativeWindowType win,
368 const struct native_config *nconf)
369 {
370 struct dri2_surface *dri2surf;
371
372 dri2surf = dri2_display_create_surface(ndpy, DRI2_SURFACE_TYPE_WINDOW,
373 (Drawable) win, nconf);
374 return (dri2surf) ? &dri2surf->base : NULL;
375 }
376
377 static struct native_surface *
378 dri2_display_create_pixmap_surface(struct native_display *ndpy,
379 EGLNativePixmapType pix,
380 const struct native_config *nconf)
381 {
382 struct dri2_surface *dri2surf;
383
384 dri2surf = dri2_display_create_surface(ndpy, DRI2_SURFACE_TYPE_PIXMAP,
385 (Drawable) pix, nconf);
386 return (dri2surf) ? &dri2surf->base : NULL;
387 }
388
389 static struct native_surface *
390 dri2_display_create_pbuffer_surface(struct native_display *ndpy,
391 const struct native_config *nconf,
392 uint width, uint height)
393 {
394 struct dri2_surface *dri2surf;
395
396 dri2surf = dri2_display_create_surface(ndpy, DRI2_SURFACE_TYPE_PBUFFER,
397 (Drawable) None, nconf);
398 if (dri2surf) {
399 dri2surf->width = width;
400 dri2surf->height = height;
401 }
402 return (dri2surf) ? &dri2surf->base : NULL;
403 }
404
405 static int
406 choose_color_format(const __GLcontextModes *mode, enum pipe_format formats[32])
407 {
408 int count = 0;
409
410 switch (mode->rgbBits) {
411 case 32:
412 formats[count++] = PIPE_FORMAT_A8R8G8B8_UNORM;
413 formats[count++] = PIPE_FORMAT_B8G8R8A8_UNORM;
414 break;
415 case 24:
416 formats[count++] = PIPE_FORMAT_X8R8G8B8_UNORM;
417 formats[count++] = PIPE_FORMAT_B8G8R8X8_UNORM;
418 formats[count++] = PIPE_FORMAT_A8R8G8B8_UNORM;
419 formats[count++] = PIPE_FORMAT_B8G8R8A8_UNORM;
420 break;
421 case 16:
422 formats[count++] = PIPE_FORMAT_R5G6B5_UNORM;
423 break;
424 default:
425 break;
426 }
427
428 return count;
429 }
430
431 static int
432 choose_depth_stencil_format(const __GLcontextModes *mode,
433 enum pipe_format formats[32])
434 {
435 int count = 0;
436
437 switch (mode->depthBits) {
438 case 32:
439 formats[count++] = PIPE_FORMAT_Z32_UNORM;
440 break;
441 case 24:
442 if (mode->stencilBits) {
443 formats[count++] = PIPE_FORMAT_S8Z24_UNORM;
444 formats[count++] = PIPE_FORMAT_Z24S8_UNORM;
445 }
446 else {
447 formats[count++] = PIPE_FORMAT_X8Z24_UNORM;
448 formats[count++] = PIPE_FORMAT_Z24X8_UNORM;
449 }
450 break;
451 case 16:
452 formats[count++] = PIPE_FORMAT_Z16_UNORM;
453 break;
454 default:
455 break;
456 }
457
458 return count;
459 }
460
461 static boolean
462 is_format_supported(struct pipe_screen *screen,
463 enum pipe_format fmt, boolean is_color)
464 {
465 return screen->is_format_supported(screen, fmt, PIPE_TEXTURE_2D,
466 (is_color) ? PIPE_TEXTURE_USAGE_RENDER_TARGET :
467 PIPE_TEXTURE_USAGE_DEPTH_STENCIL, 0);
468 }
469
470 static boolean
471 dri2_display_convert_config(struct native_display *ndpy,
472 const __GLcontextModes *mode,
473 struct native_config *nconf)
474 {
475 enum pipe_format formats[32];
476 int num_formats, i;
477
478 if (!(mode->renderType & GLX_RGBA_BIT) || !mode->rgbMode)
479 return FALSE;
480
481 /* skip single-buffered configs */
482 if (!mode->doubleBufferMode)
483 return FALSE;
484
485 nconf->mode = *mode;
486 nconf->mode.renderType = GLX_RGBA_BIT;
487 nconf->mode.rgbMode = TRUE;
488 /* pbuffer is allocated locally and is always supported */
489 nconf->mode.drawableType |= GLX_PBUFFER_BIT;
490 /* the swap method is always copy */
491 nconf->mode.swapMethod = GLX_SWAP_COPY_OML;
492
493 /* fix up */
494 nconf->mode.rgbBits =
495 nconf->mode.redBits + nconf->mode.greenBits +
496 nconf->mode.blueBits + nconf->mode.alphaBits;
497 if (!(nconf->mode.drawableType & GLX_WINDOW_BIT)) {
498 nconf->mode.visualID = 0;
499 nconf->mode.visualType = GLX_NONE;
500 }
501 if (!(nconf->mode.drawableType & GLX_PBUFFER_BIT)) {
502 nconf->mode.bindToTextureRgb = FALSE;
503 nconf->mode.bindToTextureRgba = FALSE;
504 }
505
506 nconf->color_format = PIPE_FORMAT_NONE;
507 nconf->depth_format = PIPE_FORMAT_NONE;
508 nconf->stencil_format = PIPE_FORMAT_NONE;
509
510 /* choose color format */
511 num_formats = choose_color_format(mode, formats);
512 for (i = 0; i < num_formats; i++) {
513 if (is_format_supported(ndpy->screen, formats[i], TRUE)) {
514 nconf->color_format = formats[i];
515 break;
516 }
517 }
518 if (nconf->color_format == PIPE_FORMAT_NONE)
519 return FALSE;
520
521 /* choose depth/stencil format */
522 num_formats = choose_depth_stencil_format(mode, formats);
523 for (i = 0; i < num_formats; i++) {
524 if (is_format_supported(ndpy->screen, formats[i], FALSE)) {
525 nconf->depth_format = formats[i];
526 nconf->stencil_format = formats[i];
527 break;
528 }
529 }
530 if ((nconf->mode.depthBits && nconf->depth_format == PIPE_FORMAT_NONE) ||
531 (nconf->mode.stencilBits && nconf->stencil_format == PIPE_FORMAT_NONE))
532 return FALSE;
533
534 return TRUE;
535 }
536
537 static const struct native_config **
538 dri2_display_get_configs(struct native_display *ndpy, int *num_configs)
539 {
540 struct dri2_display *dri2dpy = dri2_display(ndpy);
541 const struct native_config **configs;
542 int i;
543
544 /* first time */
545 if (!dri2dpy->configs) {
546 const __GLcontextModes *modes;
547 int num_modes, count;
548
549 modes = x11_screen_get_glx_configs(dri2dpy->xscr);
550 if (!modes)
551 return NULL;
552 num_modes = x11_context_modes_count(modes);
553
554 dri2dpy->configs = calloc(num_modes, sizeof(*dri2dpy->configs));
555 if (!dri2dpy->configs)
556 return NULL;
557
558 count = 0;
559 for (i = 0; i < num_modes; i++) {
560 struct native_config *nconf = &dri2dpy->configs[count].base;
561 if (dri2_display_convert_config(&dri2dpy->base, modes, nconf))
562 count++;
563 modes = modes->next;
564 }
565
566 dri2dpy->num_configs = count;
567 }
568
569 configs = malloc(dri2dpy->num_configs * sizeof(*configs));
570 if (configs) {
571 for (i = 0; i < dri2dpy->num_configs; i++)
572 configs[i] = (const struct native_config *) &dri2dpy->configs[i];
573 if (num_configs)
574 *num_configs = dri2dpy->num_configs;
575 }
576
577 return configs;
578 }
579
580 static boolean
581 dri2_display_is_pixmap_supported(struct native_display *ndpy,
582 EGLNativePixmapType pix,
583 const struct native_config *nconf)
584 {
585 struct dri2_display *dri2dpy = dri2_display(ndpy);
586 uint depth, nconf_depth;
587
588 depth = x11_drawable_get_depth(dri2dpy->xscr, (Drawable) pix);
589 nconf_depth = util_format_get_blocksizebits(nconf->color_format);
590
591 /* simple depth match for now */
592 return (depth == nconf_depth || (depth == 24 && depth + 8 == nconf_depth));
593 }
594
595 static void
596 dri2_display_destroy(struct native_display *ndpy)
597 {
598 struct dri2_display *dri2dpy = dri2_display(ndpy);
599
600 if (dri2dpy->configs)
601 free(dri2dpy->configs);
602
603 if (dri2dpy->base.screen)
604 dri2dpy->base.screen->destroy(dri2dpy->base.screen);
605
606 if (dri2dpy->xscr)
607 x11_screen_destroy(dri2dpy->xscr);
608 if (dri2dpy->own_dpy)
609 XCloseDisplay(dri2dpy->dpy);
610 if (dri2dpy->api && dri2dpy->api->destroy)
611 dri2dpy->api->destroy(dri2dpy->api);
612 free(dri2dpy);
613 }
614
615 /**
616 * Initialize DRI2 and pipe screen.
617 */
618 static boolean
619 dri2_display_init_screen(struct native_display *ndpy)
620 {
621 struct dri2_display *dri2dpy = dri2_display(ndpy);
622 const char *driver = dri2dpy->api->name;
623 struct drm_create_screen_arg arg;
624 int fd;
625
626 if (!x11_screen_support(dri2dpy->xscr, X11_SCREEN_EXTENSION_DRI2) ||
627 !x11_screen_support(dri2dpy->xscr, X11_SCREEN_EXTENSION_GLX)) {
628 _eglLog(_EGL_WARNING, "GLX/DRI2 is not supported");
629 return FALSE;
630 }
631
632 fd = x11_screen_enable_dri2(dri2dpy->xscr, driver);
633 if (fd < 0)
634 return FALSE;
635
636 memset(&arg, 0, sizeof(arg));
637 arg.mode = DRM_CREATE_NORMAL;
638 dri2dpy->base.screen = dri2dpy->api->create_screen(dri2dpy->api, fd, &arg);
639 if (!dri2dpy->base.screen) {
640 _eglLog(_EGL_WARNING, "failed to create DRM screen");
641 return FALSE;
642 }
643
644 return TRUE;
645 }
646
647 struct native_display *
648 x11_create_dri2_display(EGLNativeDisplayType dpy, struct drm_api *api)
649 {
650 struct dri2_display *dri2dpy;
651
652 dri2dpy = CALLOC_STRUCT(dri2_display);
653 if (!dri2dpy)
654 return NULL;
655
656 dri2dpy->api = api;
657 if (!dri2dpy->api) {
658 _eglLog(_EGL_WARNING, "failed to create DRM API");
659 free(dri2dpy);
660 return NULL;
661 }
662
663 dri2dpy->dpy = dpy;
664 if (!dri2dpy->dpy) {
665 dri2dpy->dpy = XOpenDisplay(NULL);
666 if (!dri2dpy->dpy) {
667 dri2_display_destroy(&dri2dpy->base);
668 return NULL;
669 }
670 dri2dpy->own_dpy = TRUE;
671 }
672
673 dri2dpy->xscr_number = DefaultScreen(dri2dpy->dpy);
674 dri2dpy->xscr = x11_screen_create(dri2dpy->dpy, dri2dpy->xscr_number);
675 if (!dri2dpy->xscr) {
676 dri2_display_destroy(&dri2dpy->base);
677 return NULL;
678 }
679
680 if (!dri2_display_init_screen(&dri2dpy->base)) {
681 dri2_display_destroy(&dri2dpy->base);
682 return NULL;
683 }
684
685 dri2dpy->base.destroy = dri2_display_destroy;
686 dri2dpy->base.get_configs = dri2_display_get_configs;
687 dri2dpy->base.is_pixmap_supported = dri2_display_is_pixmap_supported;
688 dri2dpy->base.create_window_surface = dri2_display_create_window_surface;
689 dri2dpy->base.create_pixmap_surface = dri2_display_create_pixmap_surface;
690 dri2dpy->base.create_pbuffer_surface = dri2_display_create_pbuffer_surface;
691
692 return &dri2dpy->base;
693 }