2 * Mesa 3-D graphics library
5 * Copyright (C) 2010 Chia-I Wu <olv@0xlab.org>
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:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
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.
27 #include "pipe/p_screen.h"
28 #include "pipe/p_context.h"
29 #include "util/u_debug.h"
30 #include "util/u_memory.h"
33 #include "native_kms.h"
36 kms_surface_validate(struct native_surface
*nsurf
, uint attachment_mask
,
37 unsigned int *seq_num
, struct pipe_texture
**textures
,
38 int *width
, int *height
)
40 struct kms_surface
*ksurf
= kms_surface(nsurf
);
41 struct kms_display
*kdpy
= ksurf
->kdpy
;
42 struct pipe_screen
*screen
= kdpy
->base
.screen
;
43 struct pipe_texture templ
, *ptex
;
46 if (attachment_mask
) {
47 memset(&templ
, 0, sizeof(templ
));
48 templ
.target
= PIPE_TEXTURE_2D
;
50 templ
.width0
= ksurf
->width
;
51 templ
.height0
= ksurf
->height
;
53 templ
.format
= ksurf
->color_format
;
54 templ
.tex_usage
= PIPE_TEXTURE_USAGE_RENDER_TARGET
;
55 if (ksurf
->type
== KMS_SURFACE_TYPE_SCANOUT
)
56 templ
.tex_usage
|= PIPE_TEXTURE_USAGE_PRIMARY
;
60 for (att
= 0; att
< NUM_NATIVE_ATTACHMENTS
; att
++) {
61 /* delay the allocation */
62 if (!native_attachment_mask_test(attachment_mask
, att
))
65 ptex
= ksurf
->textures
[att
];
67 ptex
= screen
->texture_create(screen
, &templ
);
68 ksurf
->textures
[att
] = ptex
;
73 pipe_texture_reference(&textures
[att
], ptex
);
78 *seq_num
= ksurf
->sequence_number
;
80 *width
= ksurf
->width
;
82 *height
= ksurf
->height
;
88 * Add textures as DRM framebuffers.
91 kms_surface_init_framebuffers(struct native_surface
*nsurf
, boolean need_back
)
93 struct kms_surface
*ksurf
= kms_surface(nsurf
);
94 struct kms_display
*kdpy
= ksurf
->kdpy
;
95 int num_framebuffers
= (need_back
) ? 2 : 1;
98 for (i
= 0; i
< num_framebuffers
; i
++) {
99 struct kms_framebuffer
*fb
;
100 enum native_attachment natt
;
101 unsigned int handle
, stride
;
105 fb
= &ksurf
->front_fb
;
106 natt
= NATIVE_ATTACHMENT_FRONT_LEFT
;
109 fb
= &ksurf
->back_fb
;
110 natt
= NATIVE_ATTACHMENT_BACK_LEFT
;
114 /* make sure the texture has been allocated */
115 kms_surface_validate(&ksurf
->base
, 1 << natt
, NULL
, NULL
, NULL
, NULL
);
116 if (!ksurf
->textures
[natt
])
119 pipe_texture_reference(&fb
->texture
, ksurf
->textures
[natt
]);
122 /* already initialized */
126 /* TODO detect the real value */
127 fb
->is_passive
= TRUE
;
129 if (!kdpy
->api
->local_handle_from_texture(kdpy
->api
,
130 kdpy
->base
.screen
, fb
->texture
, &stride
, &handle
))
133 block_bits
= util_format_get_blocksizebits(ksurf
->color_format
);
134 err
= drmModeAddFB(kdpy
->fd
, ksurf
->width
, ksurf
->height
,
135 block_bits
, block_bits
, stride
, handle
, &fb
->buffer_id
);
146 kms_surface_flush_frontbuffer(struct native_surface
*nsurf
)
148 #ifdef DRM_MODE_FEATURE_DIRTYFB
149 struct kms_surface
*ksurf
= kms_surface(nsurf
);
150 struct kms_display
*kdpy
= ksurf
->kdpy
;
152 /* pbuffer is private */
153 if (ksurf
->type
== KMS_SURFACE_TYPE_PBUFFER
)
156 if (ksurf
->front_fb
.is_passive
)
157 drmModeDirtyFB(kdpy
->fd
, ksurf
->front_fb
.buffer_id
, NULL
, 0);
164 kms_surface_swap_buffers(struct native_surface
*nsurf
)
166 struct kms_surface
*ksurf
= kms_surface(nsurf
);
167 struct kms_crtc
*kcrtc
= &ksurf
->current_crtc
;
168 struct kms_display
*kdpy
= ksurf
->kdpy
;
169 struct kms_framebuffer tmp_fb
;
170 struct pipe_texture
*tmp_texture
;
173 /* pbuffer is private */
174 if (ksurf
->type
== KMS_SURFACE_TYPE_PBUFFER
)
177 if (!ksurf
->back_fb
.buffer_id
) {
178 if (!kms_surface_init_framebuffers(&ksurf
->base
, TRUE
))
182 if (ksurf
->is_shown
&& kcrtc
->crtc
) {
183 err
= drmModeSetCrtc(kdpy
->fd
, kcrtc
->crtc
->crtc_id
,
184 ksurf
->back_fb
.buffer_id
, kcrtc
->crtc
->x
, kcrtc
->crtc
->y
,
185 kcrtc
->connectors
, kcrtc
->num_connectors
, &kcrtc
->crtc
->mode
);
190 /* swap the buffers */
191 tmp_fb
= ksurf
->front_fb
;
192 ksurf
->front_fb
= ksurf
->back_fb
;
193 ksurf
->back_fb
= tmp_fb
;
195 tmp_texture
= ksurf
->textures
[NATIVE_ATTACHMENT_FRONT_LEFT
];
196 ksurf
->textures
[NATIVE_ATTACHMENT_FRONT_LEFT
] =
197 ksurf
->textures
[NATIVE_ATTACHMENT_BACK_LEFT
];
198 ksurf
->textures
[NATIVE_ATTACHMENT_BACK_LEFT
] = tmp_texture
;
200 /* the front/back textures are swapped */
201 ksurf
->sequence_number
++;
207 kms_surface_wait(struct native_surface
*nsurf
)
213 kms_surface_destroy(struct native_surface
*nsurf
)
215 struct kms_surface
*ksurf
= kms_surface(nsurf
);
218 if (ksurf
->current_crtc
.crtc
)
219 drmModeFreeCrtc(ksurf
->current_crtc
.crtc
);
221 if (ksurf
->front_fb
.buffer_id
)
222 drmModeRmFB(ksurf
->kdpy
->fd
, ksurf
->front_fb
.buffer_id
);
223 pipe_texture_reference(&ksurf
->front_fb
.texture
, NULL
);
225 if (ksurf
->back_fb
.buffer_id
)
226 drmModeRmFB(ksurf
->kdpy
->fd
, ksurf
->back_fb
.buffer_id
);
227 pipe_texture_reference(&ksurf
->back_fb
.texture
, NULL
);
229 for (i
= 0; i
< NUM_NATIVE_ATTACHMENTS
; i
++) {
230 struct pipe_texture
*ptex
= ksurf
->textures
[i
];
231 pipe_texture_reference(&ptex
, NULL
);
237 static struct kms_surface
*
238 kms_display_create_surface(struct native_display
*ndpy
,
239 enum kms_surface_type type
,
240 const struct native_config
*nconf
,
241 uint width
, uint height
)
243 struct kms_display
*kdpy
= kms_display(ndpy
);
244 struct kms_config
*kconf
= kms_config(nconf
);
245 struct kms_surface
*ksurf
;
247 ksurf
= CALLOC_STRUCT(kms_surface
);
253 ksurf
->color_format
= kconf
->base
.color_format
;
254 ksurf
->width
= width
;
255 ksurf
->height
= height
;
257 ksurf
->base
.destroy
= kms_surface_destroy
;
258 ksurf
->base
.swap_buffers
= kms_surface_swap_buffers
;
259 ksurf
->base
.flush_frontbuffer
= kms_surface_flush_frontbuffer
;
260 ksurf
->base
.validate
= kms_surface_validate
;
261 ksurf
->base
.wait
= kms_surface_wait
;
267 * Choose a CRTC that supports all given connectors.
270 kms_display_choose_crtc(struct native_display
*ndpy
,
271 uint32_t *connectors
, int num_connectors
)
273 struct kms_display
*kdpy
= kms_display(ndpy
);
276 for (idx
= 0; idx
< kdpy
->resources
->count_crtcs
; idx
++) {
277 boolean found_crtc
= TRUE
;
280 for (i
= 0; i
< num_connectors
; i
++) {
281 drmModeConnectorPtr connector
;
282 int encoder_idx
= -1;
284 connector
= drmModeGetConnector(kdpy
->fd
, connectors
[i
]);
290 /* find an encoder the CRTC supports */
291 for (j
= 0; j
< connector
->count_encoders
; j
++) {
292 drmModeEncoderPtr encoder
=
293 drmModeGetEncoder(kdpy
->fd
, connector
->encoders
[j
]);
294 if (encoder
->possible_crtcs
& (1 << idx
)) {
298 drmModeFreeEncoder(encoder
);
301 drmModeFreeConnector(connector
);
302 if (encoder_idx
< 0) {
312 if (idx
>= kdpy
->resources
->count_crtcs
) {
313 _eglLog(_EGL_WARNING
,
314 "failed to find a CRTC that supports the given %d connectors",
319 return kdpy
->resources
->crtcs
[idx
];
323 * Remember the original CRTC status and set the CRTC
326 kms_display_set_crtc(struct native_display
*ndpy
, int crtc_idx
,
327 uint32_t buffer_id
, uint32_t x
, uint32_t y
,
328 uint32_t *connectors
, int num_connectors
,
329 drmModeModeInfoPtr mode
)
331 struct kms_display
*kdpy
= kms_display(ndpy
);
332 struct kms_crtc
*kcrtc
= &kdpy
->saved_crtcs
[crtc_idx
];
337 crtc_id
= kcrtc
->crtc
->crtc_id
;
343 * Choose the CRTC once. It could be more dynamic, but let's keep it
346 crtc_id
= kms_display_choose_crtc(&kdpy
->base
,
347 connectors
, num_connectors
);
349 /* save the original CRTC status */
350 kcrtc
->crtc
= drmModeGetCrtc(kdpy
->fd
, crtc_id
);
354 for (i
= 0; i
< kdpy
->num_connectors
; i
++) {
355 struct kms_connector
*kconn
= &kdpy
->connectors
[i
];
356 drmModeConnectorPtr connector
= kconn
->connector
;
357 drmModeEncoderPtr encoder
;
359 encoder
= drmModeGetEncoder(kdpy
->fd
, connector
->encoder_id
);
361 if (encoder
->crtc_id
== crtc_id
) {
362 kcrtc
->connectors
[count
++] = connector
->connector_id
;
363 if (count
>= Elements(kcrtc
->connectors
))
366 drmModeFreeEncoder(encoder
);
370 kcrtc
->num_connectors
= count
;
373 err
= drmModeSetCrtc(kdpy
->fd
, crtc_id
, buffer_id
, x
, y
,
374 connectors
, num_connectors
, mode
);
376 drmModeFreeCrtc(kcrtc
->crtc
);
378 kcrtc
->num_connectors
= 0;
387 kms_display_program(struct native_display
*ndpy
, int crtc_idx
,
388 struct native_surface
*nsurf
, uint x
, uint y
,
389 const struct native_connector
**nconns
, int num_nconns
,
390 const struct native_mode
*nmode
)
392 struct kms_display
*kdpy
= kms_display(ndpy
);
393 struct kms_surface
*ksurf
= kms_surface(nsurf
);
394 const struct kms_mode
*kmode
= kms_mode(nmode
);
395 uint32_t connector_ids
[32];
397 drmModeModeInfo mode_tmp
, *mode
;
400 if (num_nconns
> Elements(connector_ids
)) {
401 _eglLog(_EGL_WARNING
, "too many connectors (%d)", num_nconns
);
402 num_nconns
= Elements(connector_ids
);
406 if (!kms_surface_init_framebuffers(&ksurf
->base
, FALSE
))
409 buffer_id
= ksurf
->front_fb
.buffer_id
;
410 /* the mode argument of drmModeSetCrtc is not constified */
411 mode_tmp
= kmode
->mode
;
415 /* disable the CRTC */
421 for (i
= 0; i
< num_nconns
; i
++) {
422 struct kms_connector
*kconn
= kms_connector(nconns
[i
]);
423 connector_ids
[i
] = kconn
->connector
->connector_id
;
426 if (!kms_display_set_crtc(&kdpy
->base
, crtc_idx
, buffer_id
, x
, y
,
427 connector_ids
, num_nconns
, mode
)) {
428 _eglLog(_EGL_WARNING
, "failed to set CRTC %d", crtc_idx
);
433 if (kdpy
->shown_surfaces
[crtc_idx
])
434 kdpy
->shown_surfaces
[crtc_idx
]->is_shown
= FALSE
;
435 kdpy
->shown_surfaces
[crtc_idx
] = ksurf
;
437 /* remember the settings for buffer swapping */
439 uint32_t crtc_id
= kdpy
->saved_crtcs
[crtc_idx
].crtc
->crtc_id
;
440 struct kms_crtc
*kcrtc
= &ksurf
->current_crtc
;
443 drmModeFreeCrtc(kcrtc
->crtc
);
444 kcrtc
->crtc
= drmModeGetCrtc(kdpy
->fd
, crtc_id
);
446 assert(num_nconns
< Elements(kcrtc
->connectors
));
447 memcpy(kcrtc
->connectors
, connector_ids
,
448 sizeof(*connector_ids
) * num_nconns
);
449 kcrtc
->num_connectors
= num_nconns
;
451 ksurf
->is_shown
= TRUE
;
457 static const struct native_mode
**
458 kms_display_get_modes(struct native_display
*ndpy
,
459 const struct native_connector
*nconn
,
462 struct kms_display
*kdpy
= kms_display(ndpy
);
463 struct kms_connector
*kconn
= kms_connector(nconn
);
464 const struct native_mode
**nmodes_return
;
467 /* delete old data */
468 if (kconn
->connector
) {
469 drmModeFreeConnector(kconn
->connector
);
470 free(kconn
->kms_modes
);
472 kconn
->connector
= NULL
;
473 kconn
->kms_modes
= NULL
;
474 kconn
->num_modes
= 0;
478 kconn
->connector
= drmModeGetConnector(kdpy
->fd
, kconn
->connector_id
);
479 if (!kconn
->connector
)
482 count
= kconn
->connector
->count_modes
;
483 kconn
->kms_modes
= calloc(count
, sizeof(*kconn
->kms_modes
));
484 if (!kconn
->kms_modes
) {
485 drmModeFreeConnector(kconn
->connector
);
486 kconn
->connector
= NULL
;
491 for (i
= 0; i
< count
; i
++) {
492 struct kms_mode
*kmode
= &kconn
->kms_modes
[i
];
493 drmModeModeInfoPtr mode
= &kconn
->connector
->modes
[i
];
497 kmode
->base
.desc
= kmode
->mode
.name
;
498 kmode
->base
.width
= kmode
->mode
.hdisplay
;
499 kmode
->base
.height
= kmode
->mode
.vdisplay
;
500 kmode
->base
.refresh_rate
= kmode
->mode
.vrefresh
/ 1000;
503 nmodes_return
= malloc(count
* sizeof(*nmodes_return
));
505 for (i
= 0; i
< count
; i
++)
506 nmodes_return
[i
] = &kconn
->kms_modes
[i
].base
;
511 return nmodes_return
;
514 static const struct native_connector
**
515 kms_display_get_connectors(struct native_display
*ndpy
, int *num_connectors
,
518 struct kms_display
*kdpy
= kms_display(ndpy
);
519 const struct native_connector
**connectors
;
522 if (!kdpy
->connectors
) {
524 calloc(kdpy
->resources
->count_connectors
, sizeof(*kdpy
->connectors
));
525 if (!kdpy
->connectors
)
528 for (i
= 0; i
< kdpy
->resources
->count_connectors
; i
++) {
529 struct kms_connector
*kconn
= &kdpy
->connectors
[i
];
531 kconn
->connector_id
= kdpy
->resources
->connectors
[i
];
532 /* kconn->connector is allocated when the modes are asked */
535 kdpy
->num_connectors
= kdpy
->resources
->count_connectors
;
538 connectors
= malloc(kdpy
->num_connectors
* sizeof(*connectors
));
540 for (i
= 0; i
< kdpy
->num_connectors
; i
++)
541 connectors
[i
] = &kdpy
->connectors
[i
].base
;
543 *num_connectors
= kdpy
->num_connectors
;
547 *num_crtc
= kdpy
->resources
->count_crtcs
;
552 static struct native_surface
*
553 kms_display_create_scanout_surface(struct native_display
*ndpy
,
554 const struct native_config
*nconf
,
555 uint width
, uint height
)
557 struct kms_surface
*ksurf
;
559 ksurf
= kms_display_create_surface(ndpy
,
560 KMS_SURFACE_TYPE_SCANOUT
, nconf
, width
, height
);
564 static struct native_surface
*
565 kms_display_create_pbuffer_surface(struct native_display
*ndpy
,
566 const struct native_config
*nconf
,
567 uint width
, uint height
)
569 struct kms_surface
*ksurf
;
571 ksurf
= kms_display_create_surface(ndpy
,
572 KMS_SURFACE_TYPE_PBUFFER
, nconf
, width
, height
);
576 static struct pipe_context
*
577 kms_display_create_context(struct native_display
*ndpy
, void *context_private
)
579 struct kms_display
*kdpy
= kms_display(ndpy
);
580 struct pipe_context
*pctx
;
582 pctx
= kdpy
->api
->create_context(kdpy
->api
, kdpy
->base
.screen
);
584 pctx
->priv
= context_private
;
589 kms_display_is_format_supported(struct native_display
*ndpy
,
590 enum pipe_format fmt
, boolean is_color
)
592 return ndpy
->screen
->is_format_supported(ndpy
->screen
,
593 fmt
, PIPE_TEXTURE_2D
,
594 (is_color
) ? PIPE_TEXTURE_USAGE_RENDER_TARGET
:
595 PIPE_TEXTURE_USAGE_DEPTH_STENCIL
, 0);
598 static const struct native_config
**
599 kms_display_get_configs(struct native_display
*ndpy
, int *num_configs
)
601 struct kms_display
*kdpy
= kms_display(ndpy
);
602 const struct native_config
**configs
;
606 struct native_config
*nconf
;
607 enum pipe_format format
;
609 kdpy
->config
= calloc(1, sizeof(*kdpy
->config
));
613 nconf
= &kdpy
->config
->base
;
615 /* always double-buffered */
616 nconf
->mode
.doubleBufferMode
= TRUE
;
618 format
= PIPE_FORMAT_A8R8G8B8_UNORM
;
619 if (!kms_display_is_format_supported(&kdpy
->base
, format
, TRUE
)) {
620 format
= PIPE_FORMAT_B8G8R8A8_UNORM
;
621 if (!kms_display_is_format_supported(&kdpy
->base
, format
, TRUE
))
622 format
= PIPE_FORMAT_NONE
;
624 if (format
== PIPE_FORMAT_NONE
)
627 nconf
->color_format
= format
;
628 nconf
->mode
.redBits
= 8;
629 nconf
->mode
.greenBits
= 8;
630 nconf
->mode
.blueBits
= 8;
631 nconf
->mode
.alphaBits
= 8;
632 nconf
->mode
.rgbBits
= 32;
634 format
= PIPE_FORMAT_S8Z24_UNORM
;
635 if (!kms_display_is_format_supported(&kdpy
->base
, format
, FALSE
)) {
636 format
= PIPE_FORMAT_Z24S8_UNORM
;
637 if (!kms_display_is_format_supported(&kdpy
->base
, format
, FALSE
))
638 format
= PIPE_FORMAT_NONE
;
640 if (format
!= PIPE_FORMAT_NONE
) {
641 nconf
->depth_format
= format
;
642 nconf
->stencil_format
= format
;
644 nconf
->mode
.depthBits
= 24;
645 nconf
->mode
.stencilBits
= 8;
646 nconf
->mode
.haveDepthBuffer
= TRUE
;
647 nconf
->mode
.haveStencilBuffer
= TRUE
;
650 nconf
->scanout_bit
= TRUE
;
651 nconf
->mode
.drawableType
= GLX_PBUFFER_BIT
;
652 nconf
->mode
.swapMethod
= GLX_SWAP_EXCHANGE_OML
;
654 nconf
->mode
.visualID
= 0;
655 nconf
->mode
.visualType
= EGL_NONE
;
657 nconf
->mode
.renderType
= GLX_RGBA_BIT
;
658 nconf
->mode
.rgbMode
= TRUE
;
659 nconf
->mode
.xRenderable
= FALSE
;
662 configs
= malloc(sizeof(*configs
));
664 configs
[0] = &kdpy
->config
->base
;
673 kms_display_destroy(struct native_display
*ndpy
)
675 struct kms_display
*kdpy
= kms_display(ndpy
);
681 if (kdpy
->connectors
) {
682 for (i
= 0; i
< kdpy
->num_connectors
; i
++) {
683 struct kms_connector
*kconn
= &kdpy
->connectors
[i
];
684 if (kconn
->connector
) {
685 drmModeFreeConnector(kconn
->connector
);
686 free(kconn
->kms_modes
);
689 free(kdpy
->connectors
);
692 if (kdpy
->shown_surfaces
)
693 free(kdpy
->shown_surfaces
);
695 if (kdpy
->saved_crtcs
) {
696 for (i
= 0; i
< kdpy
->resources
->count_crtcs
; i
++) {
697 struct kms_crtc
*kcrtc
= &kdpy
->saved_crtcs
[i
];
701 drmModeSetCrtc(kdpy
->fd
, kcrtc
->crtc
->crtc_id
,
702 kcrtc
->crtc
->buffer_id
, kcrtc
->crtc
->x
, kcrtc
->crtc
->y
,
703 kcrtc
->connectors
, kcrtc
->num_connectors
,
706 drmModeFreeCrtc(kcrtc
->crtc
);
709 free(kdpy
->saved_crtcs
);
713 drmModeFreeResources(kdpy
->resources
);
715 if (kdpy
->base
.screen
)
716 kdpy
->base
.screen
->destroy(kdpy
->base
.screen
);
722 kdpy
->api
->destroy(kdpy
->api
);
727 * Initialize KMS and pipe screen.
730 kms_display_init_screen(struct native_display
*ndpy
)
732 struct kms_display
*kdpy
= kms_display(ndpy
);
733 struct drm_create_screen_arg arg
;
736 fd
= drmOpen(kdpy
->api
->name
, NULL
);
738 _eglLog(_EGL_WARNING
, "failed to open DRM device");
743 if (drmSetMaster(fd
)) {
744 _eglLog(_EGL_WARNING
, "failed to become DRM master");
749 memset(&arg
, 0, sizeof(arg
));
750 arg
.mode
= DRM_CREATE_NORMAL
;
751 kdpy
->base
.screen
= kdpy
->api
->create_screen(kdpy
->api
, fd
, &arg
);
752 if (!kdpy
->base
.screen
) {
753 _eglLog(_EGL_WARNING
, "failed to create DRM screen");
763 static struct native_display_modeset kms_display_modeset
= {
764 .get_connectors
= kms_display_get_connectors
,
765 .get_modes
= kms_display_get_modes
,
766 .create_scanout_surface
= kms_display_create_scanout_surface
,
767 .program
= kms_display_program
770 static struct native_display
*
771 kms_create_display(EGLNativeDisplayType dpy
, struct drm_api
*api
)
773 struct kms_display
*kdpy
;
775 kdpy
= CALLOC_STRUCT(kms_display
);
781 _eglLog(_EGL_WARNING
, "failed to create DRM API");
787 if (!kms_display_init_screen(&kdpy
->base
)) {
788 kms_display_destroy(&kdpy
->base
);
792 /* resources are fixed, unlike crtc, connector, or encoder */
793 kdpy
->resources
= drmModeGetResources(kdpy
->fd
);
794 if (!kdpy
->resources
) {
795 kms_display_destroy(&kdpy
->base
);
800 calloc(kdpy
->resources
->count_crtcs
, sizeof(*kdpy
->saved_crtcs
));
801 if (!kdpy
->saved_crtcs
) {
802 kms_display_destroy(&kdpy
->base
);
806 kdpy
->shown_surfaces
=
807 calloc(kdpy
->resources
->count_crtcs
, sizeof(*kdpy
->shown_surfaces
));
808 if (!kdpy
->shown_surfaces
) {
809 kms_display_destroy(&kdpy
->base
);
813 kdpy
->base
.destroy
= kms_display_destroy
;
814 kdpy
->base
.get_configs
= kms_display_get_configs
;
815 kdpy
->base
.create_context
= kms_display_create_context
;
816 kdpy
->base
.create_pbuffer_surface
= kms_display_create_pbuffer_surface
;
818 kdpy
->base
.modeset
= &kms_display_modeset
;
823 struct native_probe
*
824 native_create_probe(EGLNativeDisplayType dpy
)
829 enum native_probe_result
830 native_get_probe_result(struct native_probe
*nprobe
)
832 return NATIVE_PROBE_UNKNOWN
;
835 /* the api is destroyed with the native display */
836 static struct drm_api
*drm_api
;
839 native_get_name(void)
841 static char kms_name
[32];
844 drm_api
= drm_api_create();
847 snprintf(kms_name
, sizeof(kms_name
), "KMS/%s", drm_api
->name
);
849 snprintf(kms_name
, sizeof(kms_name
), "KMS");
854 struct native_display
*
855 native_create_display(EGLNativeDisplayType dpy
)
857 struct native_display
*ndpy
= NULL
;
860 drm_api
= drm_api_create();
863 ndpy
= kms_create_display(dpy
, drm_api
);