2 * Mesa 3-D graphics library
4 * Copyright 2009, VMware, Inc.
6 * Copyright (C) 2010 LunarG Inc.
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
22 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
23 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24 * OTHER DEALINGS IN THE SOFTWARE.
27 * Keith Whitwell <keithw@vmware.com> Jakob Bornecrantz
28 * <wallbraker@gmail.com> Chia-I Wu <olv@lunarg.com>
33 #include "util/u_memory.h"
34 #include "util/u_inlines.h"
35 #include "util/u_format.h"
36 #include "util/u_debug.h"
37 #include "state_tracker/drm_driver.h"
38 #include "state_tracker/st_texture.h"
39 #include "state_tracker/st_context.h"
40 #include "pipe-loader/pipe_loader.h"
41 #include "main/texobj.h"
43 #include "dri_screen.h"
44 #include "dri_context.h"
45 #include "dri_drawable.h"
46 #include "dri_query_renderer.h"
47 #include "dri2_buffer.h"
49 static int convert_fourcc(int format
, int *dri_components_p
)
53 case __DRI_IMAGE_FOURCC_RGB565
:
54 format
= __DRI_IMAGE_FORMAT_RGB565
;
55 dri_components
= __DRI_IMAGE_COMPONENTS_RGB
;
57 case __DRI_IMAGE_FOURCC_ARGB8888
:
58 format
= __DRI_IMAGE_FORMAT_ARGB8888
;
59 dri_components
= __DRI_IMAGE_COMPONENTS_RGBA
;
61 case __DRI_IMAGE_FOURCC_XRGB8888
:
62 format
= __DRI_IMAGE_FORMAT_XRGB8888
;
63 dri_components
= __DRI_IMAGE_COMPONENTS_RGB
;
65 case __DRI_IMAGE_FOURCC_ABGR8888
:
66 format
= __DRI_IMAGE_FORMAT_ABGR8888
;
67 dri_components
= __DRI_IMAGE_COMPONENTS_RGBA
;
69 case __DRI_IMAGE_FOURCC_XBGR8888
:
70 format
= __DRI_IMAGE_FORMAT_XBGR8888
;
71 dri_components
= __DRI_IMAGE_COMPONENTS_RGB
;
76 *dri_components_p
= dri_components
;
80 static int convert_to_fourcc(int format
)
83 case __DRI_IMAGE_FORMAT_RGB565
:
84 format
= __DRI_IMAGE_FOURCC_RGB565
;
86 case __DRI_IMAGE_FORMAT_ARGB8888
:
87 format
= __DRI_IMAGE_FOURCC_ARGB8888
;
89 case __DRI_IMAGE_FORMAT_XRGB8888
:
90 format
= __DRI_IMAGE_FOURCC_XRGB8888
;
92 case __DRI_IMAGE_FORMAT_ABGR8888
:
93 format
= __DRI_IMAGE_FOURCC_ABGR8888
;
95 case __DRI_IMAGE_FORMAT_XBGR8888
:
96 format
= __DRI_IMAGE_FOURCC_XBGR8888
;
104 static enum pipe_format
dri2_format_to_pipe_format (int format
)
109 case __DRI_IMAGE_FORMAT_RGB565
:
110 pf
= PIPE_FORMAT_B5G6R5_UNORM
;
112 case __DRI_IMAGE_FORMAT_XRGB8888
:
113 pf
= PIPE_FORMAT_BGRX8888_UNORM
;
115 case __DRI_IMAGE_FORMAT_ARGB8888
:
116 pf
= PIPE_FORMAT_BGRA8888_UNORM
;
118 case __DRI_IMAGE_FORMAT_ABGR8888
:
119 pf
= PIPE_FORMAT_RGBA8888_UNORM
;
122 pf
= PIPE_FORMAT_NONE
;
130 * DRI2 flush extension.
133 dri2_flush_drawable(__DRIdrawable
*dPriv
)
135 dri_flush(dPriv
->driContextPriv
, dPriv
, __DRI2_FLUSH_DRAWABLE
, -1);
139 dri2_invalidate_drawable(__DRIdrawable
*dPriv
)
141 struct dri_drawable
*drawable
= dri_drawable(dPriv
);
143 dri2InvalidateDrawable(dPriv
);
144 drawable
->dPriv
->lastStamp
= drawable
->dPriv
->dri2
.stamp
;
146 p_atomic_inc(&drawable
->base
.stamp
);
149 static const __DRI2flushExtension dri2FlushExtension
= {
150 .base
= { __DRI2_FLUSH
, 4 },
152 .flush
= dri2_flush_drawable
,
153 .invalidate
= dri2_invalidate_drawable
,
154 .flush_with_flags
= dri_flush
,
158 * Retrieve __DRIbuffer from the DRI loader.
161 dri2_drawable_get_buffers(struct dri_drawable
*drawable
,
162 const enum st_attachment_type
*atts
,
165 __DRIdrawable
*dri_drawable
= drawable
->dPriv
;
166 const __DRIdri2LoaderExtension
*loader
= drawable
->sPriv
->dri2
.loader
;
168 __DRIbuffer
*buffers
;
170 unsigned attachments
[10];
171 unsigned num_attachments
, i
;
174 with_format
= dri_with_format(drawable
->sPriv
);
178 /* for Xserver 1.6.0 (DRI2 version 1) we always need to ask for the front */
180 attachments
[num_attachments
++] = __DRI_BUFFER_FRONT_LEFT
;
182 for (i
= 0; i
< *count
; i
++) {
183 enum pipe_format format
;
187 dri_drawable_get_format(drawable
, atts
[i
], &format
, &bind
);
188 if (format
== PIPE_FORMAT_NONE
)
192 case ST_ATTACHMENT_FRONT_LEFT
:
196 att
= __DRI_BUFFER_FRONT_LEFT
;
198 case ST_ATTACHMENT_BACK_LEFT
:
199 att
= __DRI_BUFFER_BACK_LEFT
;
201 case ST_ATTACHMENT_FRONT_RIGHT
:
202 att
= __DRI_BUFFER_FRONT_RIGHT
;
204 case ST_ATTACHMENT_BACK_RIGHT
:
205 att
= __DRI_BUFFER_BACK_RIGHT
;
212 * In this switch statement we must support all formats that
213 * may occur as the stvis->color_format.
216 case PIPE_FORMAT_BGRA8888_UNORM
:
219 case PIPE_FORMAT_BGRX8888_UNORM
:
222 case PIPE_FORMAT_B5G6R5_UNORM
:
226 depth
= util_format_get_blocksizebits(format
);
227 assert(!"Unexpected format in dri2_drawable_get_buffers()");
230 attachments
[num_attachments
++] = att
;
232 attachments
[num_attachments
++] = depth
;
237 num_attachments
/= 2;
238 buffers
= loader
->getBuffersWithFormat(dri_drawable
,
239 &dri_drawable
->w
, &dri_drawable
->h
,
240 attachments
, num_attachments
,
241 &num_buffers
, dri_drawable
->loaderPrivate
);
244 buffers
= loader
->getBuffers(dri_drawable
,
245 &dri_drawable
->w
, &dri_drawable
->h
,
246 attachments
, num_attachments
,
247 &num_buffers
, dri_drawable
->loaderPrivate
);
251 *count
= num_buffers
;
257 dri_image_drawable_get_buffers(struct dri_drawable
*drawable
,
258 struct __DRIimageList
*images
,
259 const enum st_attachment_type
*statts
,
260 unsigned statts_count
)
262 __DRIdrawable
*dPriv
= drawable
->dPriv
;
263 __DRIscreen
*sPriv
= drawable
->sPriv
;
264 unsigned int image_format
= __DRI_IMAGE_FORMAT_NONE
;
266 uint32_t buffer_mask
= 0;
269 for (i
= 0; i
< statts_count
; i
++) {
270 dri_drawable_get_format(drawable
, statts
[i
], &pf
, &bind
);
271 if (pf
== PIPE_FORMAT_NONE
)
275 case ST_ATTACHMENT_FRONT_LEFT
:
276 buffer_mask
|= __DRI_IMAGE_BUFFER_FRONT
;
278 case ST_ATTACHMENT_BACK_LEFT
:
279 buffer_mask
|= __DRI_IMAGE_BUFFER_BACK
;
286 case PIPE_FORMAT_B5G6R5_UNORM
:
287 image_format
= __DRI_IMAGE_FORMAT_RGB565
;
289 case PIPE_FORMAT_BGRX8888_UNORM
:
290 image_format
= __DRI_IMAGE_FORMAT_XRGB8888
;
292 case PIPE_FORMAT_BGRA8888_UNORM
:
293 image_format
= __DRI_IMAGE_FORMAT_ARGB8888
;
295 case PIPE_FORMAT_RGBA8888_UNORM
:
296 image_format
= __DRI_IMAGE_FORMAT_ABGR8888
;
299 image_format
= __DRI_IMAGE_FORMAT_NONE
;
304 return (*sPriv
->image
.loader
->getBuffers
) (dPriv
, image_format
,
305 (uint32_t *) &drawable
->base
.stamp
,
306 dPriv
->loaderPrivate
, buffer_mask
,
311 dri2_allocate_buffer(__DRIscreen
*sPriv
,
312 unsigned attachment
, unsigned format
,
313 int width
, int height
)
315 struct dri_screen
*screen
= dri_screen(sPriv
);
316 struct dri2_buffer
*buffer
;
317 struct pipe_resource templ
;
320 struct winsys_handle whandle
;
322 switch (attachment
) {
323 case __DRI_BUFFER_FRONT_LEFT
:
324 case __DRI_BUFFER_FAKE_FRONT_LEFT
:
325 bind
= PIPE_BIND_RENDER_TARGET
| PIPE_BIND_SAMPLER_VIEW
;
327 case __DRI_BUFFER_BACK_LEFT
:
328 bind
= PIPE_BIND_RENDER_TARGET
| PIPE_BIND_SAMPLER_VIEW
;
330 case __DRI_BUFFER_DEPTH
:
331 case __DRI_BUFFER_DEPTH_STENCIL
:
332 case __DRI_BUFFER_STENCIL
:
333 bind
= PIPE_BIND_DEPTH_STENCIL
; /* XXX sampler? */
337 /* because we get the handle and stride */
338 bind
|= PIPE_BIND_SHARED
;
342 pf
= PIPE_FORMAT_BGRA8888_UNORM
;
345 pf
= PIPE_FORMAT_BGRX8888_UNORM
;
348 pf
= PIPE_FORMAT_Z16_UNORM
;
354 buffer
= CALLOC_STRUCT(dri2_buffer
);
358 memset(&templ
, 0, sizeof(templ
));
361 templ
.target
= PIPE_TEXTURE_2D
;
362 templ
.last_level
= 0;
363 templ
.width0
= width
;
364 templ
.height0
= height
;
366 templ
.array_size
= 1;
369 screen
->base
.screen
->resource_create(screen
->base
.screen
, &templ
);
370 if (!buffer
->resource
) {
375 memset(&whandle
, 0, sizeof(whandle
));
376 if (screen
->can_share_buffer
)
377 whandle
.type
= DRM_API_HANDLE_TYPE_SHARED
;
379 whandle
.type
= DRM_API_HANDLE_TYPE_KMS
;
381 screen
->base
.screen
->resource_get_handle(screen
->base
.screen
,
382 buffer
->resource
, &whandle
,
383 PIPE_HANDLE_USAGE_EXPLICIT_FLUSH
| PIPE_HANDLE_USAGE_READ
);
385 buffer
->base
.attachment
= attachment
;
386 buffer
->base
.name
= whandle
.handle
;
387 buffer
->base
.cpp
= util_format_get_blocksize(pf
);
388 buffer
->base
.pitch
= whandle
.stride
;
390 return &buffer
->base
;
394 dri2_release_buffer(__DRIscreen
*sPriv
, __DRIbuffer
*bPriv
)
396 struct dri2_buffer
*buffer
= dri2_buffer(bPriv
);
398 pipe_resource_reference(&buffer
->resource
, NULL
);
403 * Backend functions for st_framebuffer interface.
407 dri2_allocate_textures(struct dri_context
*ctx
,
408 struct dri_drawable
*drawable
,
409 const enum st_attachment_type
*statts
,
410 unsigned statts_count
)
412 __DRIscreen
*sPriv
= drawable
->sPriv
;
413 __DRIdrawable
*dri_drawable
= drawable
->dPriv
;
414 struct dri_screen
*screen
= dri_screen(sPriv
);
415 struct pipe_resource templ
;
416 boolean alloc_depthstencil
= FALSE
;
418 const __DRIimageLoaderExtension
*image
= sPriv
->image
.loader
;
419 /* Image specific variables */
420 struct __DRIimageList images
;
421 /* Dri2 specific variables */
422 __DRIbuffer
*buffers
= NULL
;
423 struct winsys_handle whandle
;
424 unsigned num_buffers
= statts_count
;
426 /* First get the buffers from the loader */
428 if (!dri_image_drawable_get_buffers(drawable
, &images
,
429 statts
, statts_count
))
433 buffers
= dri2_drawable_get_buffers(drawable
, statts
, &num_buffers
);
434 if (!buffers
|| (drawable
->old_num
== num_buffers
&&
435 drawable
->old_w
== dri_drawable
->w
&&
436 drawable
->old_h
== dri_drawable
->h
&&
437 memcmp(drawable
->old
, buffers
,
438 sizeof(__DRIbuffer
) * num_buffers
) == 0))
442 /* Second clean useless resources*/
444 /* See if we need a depth-stencil buffer. */
445 for (i
= 0; i
< statts_count
; i
++) {
446 if (statts
[i
] == ST_ATTACHMENT_DEPTH_STENCIL
) {
447 alloc_depthstencil
= TRUE
;
452 /* Delete the resources we won't need. */
453 for (i
= 0; i
< ST_ATTACHMENT_COUNT
; i
++) {
454 /* Don't delete the depth-stencil buffer, we can reuse it. */
455 if (i
== ST_ATTACHMENT_DEPTH_STENCIL
&& alloc_depthstencil
)
458 /* Flush the texture before unreferencing, so that other clients can
459 * see what the driver has rendered.
461 if (i
!= ST_ATTACHMENT_DEPTH_STENCIL
&& drawable
->textures
[i
]) {
462 struct pipe_context
*pipe
= ctx
->st
->pipe
;
463 pipe
->flush_resource(pipe
, drawable
->textures
[i
]);
466 pipe_resource_reference(&drawable
->textures
[i
], NULL
);
469 if (drawable
->stvis
.samples
> 1) {
470 for (i
= 0; i
< ST_ATTACHMENT_COUNT
; i
++) {
473 /* Don't delete MSAA resources for the attachments which are enabled,
474 * we can reuse them. */
475 for (j
= 0; j
< statts_count
; j
++) {
476 if (i
== statts
[j
]) {
483 pipe_resource_reference(&drawable
->msaa_textures
[i
], NULL
);
488 /* Third use the buffers retrieved to fill the drawable info */
490 memset(&templ
, 0, sizeof(templ
));
491 templ
.target
= screen
->target
;
492 templ
.last_level
= 0;
494 templ
.array_size
= 1;
497 if (images
.image_mask
& __DRI_IMAGE_BUFFER_FRONT
) {
498 struct pipe_resource
**buf
=
499 &drawable
->textures
[ST_ATTACHMENT_FRONT_LEFT
];
500 struct pipe_resource
*texture
= images
.front
->texture
;
502 dri_drawable
->w
= texture
->width0
;
503 dri_drawable
->h
= texture
->height0
;
505 pipe_resource_reference(buf
, texture
);
508 if (images
.image_mask
& __DRI_IMAGE_BUFFER_BACK
) {
509 struct pipe_resource
**buf
=
510 &drawable
->textures
[ST_ATTACHMENT_BACK_LEFT
];
511 struct pipe_resource
*texture
= images
.back
->texture
;
513 dri_drawable
->w
= texture
->width0
;
514 dri_drawable
->h
= texture
->height0
;
516 pipe_resource_reference(buf
, texture
);
519 /* Note: if there is both a back and a front buffer,
520 * then they have the same size.
522 templ
.width0
= dri_drawable
->w
;
523 templ
.height0
= dri_drawable
->h
;
526 memset(&whandle
, 0, sizeof(whandle
));
528 /* Process DRI-provided buffers and get pipe_resources. */
529 for (i
= 0; i
< num_buffers
; i
++) {
530 __DRIbuffer
*buf
= &buffers
[i
];
531 enum st_attachment_type statt
;
532 enum pipe_format format
;
534 switch (buf
->attachment
) {
535 case __DRI_BUFFER_FRONT_LEFT
:
536 if (!screen
->auto_fake_front
) {
537 continue; /* invalid attachment */
540 case __DRI_BUFFER_FAKE_FRONT_LEFT
:
541 statt
= ST_ATTACHMENT_FRONT_LEFT
;
543 case __DRI_BUFFER_BACK_LEFT
:
544 statt
= ST_ATTACHMENT_BACK_LEFT
;
547 continue; /* invalid attachment */
550 dri_drawable_get_format(drawable
, statt
, &format
, &bind
);
551 if (format
== PIPE_FORMAT_NONE
)
554 /* dri2_drawable_get_buffers has already filled dri_drawable->w
555 * and dri_drawable->h */
556 templ
.width0
= dri_drawable
->w
;
557 templ
.height0
= dri_drawable
->h
;
558 templ
.format
= format
;
560 whandle
.handle
= buf
->name
;
561 whandle
.stride
= buf
->pitch
;
563 if (screen
->can_share_buffer
)
564 whandle
.type
= DRM_API_HANDLE_TYPE_SHARED
;
566 whandle
.type
= DRM_API_HANDLE_TYPE_KMS
;
567 drawable
->textures
[statt
] =
568 screen
->base
.screen
->resource_from_handle(screen
->base
.screen
,
570 PIPE_HANDLE_USAGE_EXPLICIT_FLUSH
| PIPE_HANDLE_USAGE_READ
);
571 assert(drawable
->textures
[statt
]);
575 /* Allocate private MSAA colorbuffers. */
576 if (drawable
->stvis
.samples
> 1) {
577 for (i
= 0; i
< statts_count
; i
++) {
578 enum st_attachment_type statt
= statts
[i
];
580 if (statt
== ST_ATTACHMENT_DEPTH_STENCIL
)
583 if (drawable
->textures
[statt
]) {
584 templ
.format
= drawable
->textures
[statt
]->format
;
585 templ
.bind
= drawable
->textures
[statt
]->bind
& ~PIPE_BIND_SCANOUT
;
586 templ
.nr_samples
= drawable
->stvis
.samples
;
588 /* Try to reuse the resource.
589 * (the other resource parameters should be constant)
591 if (!drawable
->msaa_textures
[statt
] ||
592 drawable
->msaa_textures
[statt
]->width0
!= templ
.width0
||
593 drawable
->msaa_textures
[statt
]->height0
!= templ
.height0
) {
594 /* Allocate a new one. */
595 pipe_resource_reference(&drawable
->msaa_textures
[statt
], NULL
);
597 drawable
->msaa_textures
[statt
] =
598 screen
->base
.screen
->resource_create(screen
->base
.screen
,
600 assert(drawable
->msaa_textures
[statt
]);
602 /* If there are any MSAA resources, we should initialize them
603 * such that they contain the same data as the single-sample
604 * resources we just got from the X server.
606 * The reason for this is that the state tracker (and
607 * therefore the app) can access the MSAA resources only.
608 * The single-sample resources are not exposed
609 * to the state tracker.
612 dri_pipe_blit(ctx
->st
->pipe
,
613 drawable
->msaa_textures
[statt
],
614 drawable
->textures
[statt
]);
618 pipe_resource_reference(&drawable
->msaa_textures
[statt
], NULL
);
623 /* Allocate a private depth-stencil buffer. */
624 if (alloc_depthstencil
) {
625 enum st_attachment_type statt
= ST_ATTACHMENT_DEPTH_STENCIL
;
626 struct pipe_resource
**zsbuf
;
627 enum pipe_format format
;
630 dri_drawable_get_format(drawable
, statt
, &format
, &bind
);
633 templ
.format
= format
;
636 if (drawable
->stvis
.samples
> 1) {
637 templ
.nr_samples
= drawable
->stvis
.samples
;
638 zsbuf
= &drawable
->msaa_textures
[statt
];
641 templ
.nr_samples
= 0;
642 zsbuf
= &drawable
->textures
[statt
];
645 /* Try to reuse the resource.
646 * (the other resource parameters should be constant)
649 (*zsbuf
)->width0
!= templ
.width0
||
650 (*zsbuf
)->height0
!= templ
.height0
) {
651 /* Allocate a new one. */
652 pipe_resource_reference(zsbuf
, NULL
);
653 *zsbuf
= screen
->base
.screen
->resource_create(screen
->base
.screen
,
659 pipe_resource_reference(&drawable
->msaa_textures
[statt
], NULL
);
660 pipe_resource_reference(&drawable
->textures
[statt
], NULL
);
664 /* For DRI2, we may get the same buffers again from the server.
665 * To prevent useless imports of gem names, drawable->old* is used
666 * to bypass the import if we get the same buffers. This doesn't apply
667 * to DRI3/Wayland, users of image.loader, since the buffer is managed
668 * by the client (no import), and the back buffer is going to change
672 drawable
->old_num
= num_buffers
;
673 drawable
->old_w
= dri_drawable
->w
;
674 drawable
->old_h
= dri_drawable
->h
;
675 memcpy(drawable
->old
, buffers
, sizeof(__DRIbuffer
) * num_buffers
);
680 dri2_flush_frontbuffer(struct dri_context
*ctx
,
681 struct dri_drawable
*drawable
,
682 enum st_attachment_type statt
)
684 __DRIdrawable
*dri_drawable
= drawable
->dPriv
;
685 const __DRIimageLoaderExtension
*image
= drawable
->sPriv
->image
.loader
;
686 const __DRIdri2LoaderExtension
*loader
= drawable
->sPriv
->dri2
.loader
;
687 struct pipe_context
*pipe
= ctx
->st
->pipe
;
689 if (statt
!= ST_ATTACHMENT_FRONT_LEFT
)
692 if (drawable
->stvis
.samples
> 1) {
693 /* Resolve the front buffer. */
694 dri_pipe_blit(ctx
->st
->pipe
,
695 drawable
->textures
[ST_ATTACHMENT_FRONT_LEFT
],
696 drawable
->msaa_textures
[ST_ATTACHMENT_FRONT_LEFT
]);
699 if (drawable
->textures
[ST_ATTACHMENT_FRONT_LEFT
]) {
700 pipe
->flush_resource(pipe
, drawable
->textures
[ST_ATTACHMENT_FRONT_LEFT
]);
703 pipe
->flush(pipe
, NULL
, 0);
706 image
->flushFrontBuffer(dri_drawable
, dri_drawable
->loaderPrivate
);
708 else if (loader
->flushFrontBuffer
) {
709 loader
->flushFrontBuffer(dri_drawable
, dri_drawable
->loaderPrivate
);
714 dri2_update_tex_buffer(struct dri_drawable
*drawable
,
715 struct dri_context
*ctx
,
716 struct pipe_resource
*res
)
722 dri2_lookup_egl_image(struct dri_screen
*screen
, void *handle
)
724 const __DRIimageLookupExtension
*loader
= screen
->sPriv
->dri2
.image
;
727 if (!loader
->lookupEGLImage
)
730 img
= loader
->lookupEGLImage(screen
->sPriv
,
731 handle
, screen
->sPriv
->loaderPrivate
);
737 dri2_create_image_from_winsys(__DRIscreen
*_screen
,
738 int width
, int height
, int format
,
739 struct winsys_handle
*whandle
, int pitch
,
742 struct dri_screen
*screen
= dri_screen(_screen
);
744 struct pipe_resource templ
;
748 tex_usage
= PIPE_BIND_RENDER_TARGET
| PIPE_BIND_SAMPLER_VIEW
;
750 pf
= dri2_format_to_pipe_format (format
);
751 if (pf
== PIPE_FORMAT_NONE
)
754 img
= CALLOC_STRUCT(__DRIimageRec
);
758 memset(&templ
, 0, sizeof(templ
));
759 templ
.bind
= tex_usage
;
761 templ
.target
= screen
->target
;
762 templ
.last_level
= 0;
763 templ
.width0
= width
;
764 templ
.height0
= height
;
766 templ
.array_size
= 1;
768 whandle
->stride
= pitch
* util_format_get_blocksize(pf
);
771 img
->texture
= screen
->base
.screen
->resource_from_handle(screen
->base
.screen
,
772 &templ
, whandle
, PIPE_HANDLE_USAGE_READ_WRITE
);
780 img
->dri_format
= format
;
782 img
->loader_private
= loaderPrivate
;
788 dri2_create_image_from_name(__DRIscreen
*_screen
,
789 int width
, int height
, int format
,
790 int name
, int pitch
, void *loaderPrivate
)
792 struct winsys_handle whandle
;
794 memset(&whandle
, 0, sizeof(whandle
));
795 whandle
.type
= DRM_API_HANDLE_TYPE_SHARED
;
796 whandle
.handle
= name
;
798 return dri2_create_image_from_winsys(_screen
, width
, height
, format
,
799 &whandle
, pitch
, loaderPrivate
);
803 dri2_create_image_from_fd(__DRIscreen
*_screen
,
804 int width
, int height
, int format
,
805 int fd
, int pitch
, void *loaderPrivate
)
807 struct winsys_handle whandle
;
812 memset(&whandle
, 0, sizeof(whandle
));
813 whandle
.type
= DRM_API_HANDLE_TYPE_FD
;
814 whandle
.handle
= (unsigned)fd
;
816 return dri2_create_image_from_winsys(_screen
, width
, height
, format
,
817 &whandle
, pitch
, loaderPrivate
);
821 dri2_create_image_from_renderbuffer(__DRIcontext
*context
,
822 int renderbuffer
, void *loaderPrivate
)
824 struct dri_context
*ctx
= dri_context(context
);
826 if (!ctx
->st
->get_resource_for_egl_image
)
834 dri2_create_image(__DRIscreen
*_screen
,
835 int width
, int height
, int format
,
836 unsigned int use
, void *loaderPrivate
)
838 struct dri_screen
*screen
= dri_screen(_screen
);
840 struct pipe_resource templ
;
844 tex_usage
= PIPE_BIND_RENDER_TARGET
| PIPE_BIND_SAMPLER_VIEW
;
845 if (use
& __DRI_IMAGE_USE_SCANOUT
)
846 tex_usage
|= PIPE_BIND_SCANOUT
;
847 if (use
& __DRI_IMAGE_USE_SHARE
)
848 tex_usage
|= PIPE_BIND_SHARED
;
849 if (use
& __DRI_IMAGE_USE_LINEAR
)
850 tex_usage
|= PIPE_BIND_LINEAR
;
851 if (use
& __DRI_IMAGE_USE_CURSOR
) {
852 if (width
!= 64 || height
!= 64)
854 tex_usage
|= PIPE_BIND_CURSOR
;
857 pf
= dri2_format_to_pipe_format (format
);
858 if (pf
== PIPE_FORMAT_NONE
)
861 img
= CALLOC_STRUCT(__DRIimageRec
);
865 memset(&templ
, 0, sizeof(templ
));
866 templ
.bind
= tex_usage
;
868 templ
.target
= PIPE_TEXTURE_2D
;
869 templ
.last_level
= 0;
870 templ
.width0
= width
;
871 templ
.height0
= height
;
873 templ
.array_size
= 1;
875 img
->texture
= screen
->base
.screen
->resource_create(screen
->base
.screen
, &templ
);
883 img
->dri_format
= format
;
884 img
->dri_components
= 0;
887 img
->loader_private
= loaderPrivate
;
892 dri2_query_image(__DRIimage
*image
, int attrib
, int *value
)
894 struct winsys_handle whandle
;
897 if (image
->use
& __DRI_IMAGE_USE_BACKBUFFER
)
898 usage
= PIPE_HANDLE_USAGE_EXPLICIT_FLUSH
| PIPE_HANDLE_USAGE_READ
;
900 usage
= PIPE_HANDLE_USAGE_READ_WRITE
;
902 memset(&whandle
, 0, sizeof(whandle
));
905 case __DRI_IMAGE_ATTRIB_STRIDE
:
906 whandle
.type
= DRM_API_HANDLE_TYPE_KMS
;
907 image
->texture
->screen
->resource_get_handle(image
->texture
->screen
,
908 image
->texture
, &whandle
, usage
);
909 *value
= whandle
.stride
;
911 case __DRI_IMAGE_ATTRIB_HANDLE
:
912 whandle
.type
= DRM_API_HANDLE_TYPE_KMS
;
913 image
->texture
->screen
->resource_get_handle(image
->texture
->screen
,
914 image
->texture
, &whandle
, usage
);
915 *value
= whandle
.handle
;
917 case __DRI_IMAGE_ATTRIB_NAME
:
918 whandle
.type
= DRM_API_HANDLE_TYPE_SHARED
;
919 image
->texture
->screen
->resource_get_handle(image
->texture
->screen
,
920 image
->texture
, &whandle
, usage
);
921 *value
= whandle
.handle
;
923 case __DRI_IMAGE_ATTRIB_FD
:
924 whandle
.type
= DRM_API_HANDLE_TYPE_FD
;
925 image
->texture
->screen
->resource_get_handle(image
->texture
->screen
,
926 image
->texture
, &whandle
, usage
);
927 *value
= whandle
.handle
;
929 case __DRI_IMAGE_ATTRIB_FORMAT
:
930 *value
= image
->dri_format
;
932 case __DRI_IMAGE_ATTRIB_WIDTH
:
933 *value
= image
->texture
->width0
;
935 case __DRI_IMAGE_ATTRIB_HEIGHT
:
936 *value
= image
->texture
->height0
;
938 case __DRI_IMAGE_ATTRIB_COMPONENTS
:
939 if (image
->dri_components
== 0)
941 *value
= image
->dri_components
;
943 case __DRI_IMAGE_ATTRIB_FOURCC
:
944 *value
= convert_to_fourcc(image
->dri_format
);
946 case __DRI_IMAGE_ATTRIB_NUM_PLANES
:
955 dri2_dup_image(__DRIimage
*image
, void *loaderPrivate
)
959 img
= CALLOC_STRUCT(__DRIimageRec
);
964 pipe_resource_reference(&img
->texture
, image
->texture
);
965 img
->level
= image
->level
;
966 img
->layer
= image
->layer
;
967 img
->dri_format
= image
->dri_format
;
968 /* This should be 0 for sub images, but dup is also used for base images. */
969 img
->dri_components
= image
->dri_components
;
970 img
->loader_private
= loaderPrivate
;
976 dri2_validate_usage(__DRIimage
*image
, unsigned int use
)
979 * Gallium drivers are bad at adding usages to the resources
980 * once opened again in another process, which is the main use
981 * case for this, so we have to lie.
990 dri2_from_names(__DRIscreen
*screen
, int width
, int height
, int format
,
991 int *names
, int num_names
, int *strides
, int *offsets
,
995 int stride
, dri_components
;
1002 format
= convert_fourcc(format
, &dri_components
);
1006 /* Strides are in bytes not pixels. */
1007 stride
= strides
[0] /4;
1009 img
= dri2_create_image_from_name(screen
, width
, height
, format
,
1010 names
[0], stride
, loaderPrivate
);
1014 img
->dri_components
= dri_components
;
1019 dri2_from_planar(__DRIimage
*image
, int plane
, void *loaderPrivate
)
1026 if (image
->dri_components
== 0)
1029 img
= dri2_dup_image(image
, loaderPrivate
);
1033 /* set this to 0 for sub images. */
1034 img
->dri_components
= 0;
1039 dri2_create_from_texture(__DRIcontext
*context
, int target
, unsigned texture
,
1040 int depth
, int level
, unsigned *error
,
1041 void *loaderPrivate
)
1044 struct gl_context
*ctx
= ((struct st_context
*)dri_context(context
)->st
)->ctx
;
1045 struct gl_texture_object
*obj
;
1046 struct pipe_resource
*tex
;
1049 obj
= _mesa_lookup_texture(ctx
, texture
);
1050 if (!obj
|| obj
->Target
!= target
) {
1051 *error
= __DRI_IMAGE_ERROR_BAD_PARAMETER
;
1055 tex
= st_get_texobj_resource(obj
);
1057 *error
= __DRI_IMAGE_ERROR_BAD_PARAMETER
;
1061 if (target
== GL_TEXTURE_CUBE_MAP
)
1064 _mesa_test_texobj_completeness(ctx
, obj
);
1065 if (!obj
->_BaseComplete
|| (level
> 0 && !obj
->_MipmapComplete
)) {
1066 *error
= __DRI_IMAGE_ERROR_BAD_PARAMETER
;
1070 if (level
< obj
->BaseLevel
|| level
> obj
->_MaxLevel
) {
1071 *error
= __DRI_IMAGE_ERROR_BAD_MATCH
;
1075 if (target
== GL_TEXTURE_3D
&& obj
->Image
[face
][level
]->Depth
< depth
) {
1076 *error
= __DRI_IMAGE_ERROR_BAD_MATCH
;
1080 img
= CALLOC_STRUCT(__DRIimageRec
);
1082 *error
= __DRI_IMAGE_ERROR_BAD_ALLOC
;
1088 img
->dri_format
= driGLFormatToImageFormat(obj
->Image
[face
][level
]->TexFormat
);
1090 img
->loader_private
= loaderPrivate
;
1092 if (img
->dri_format
== __DRI_IMAGE_FORMAT_NONE
) {
1093 *error
= __DRI_IMAGE_ERROR_BAD_PARAMETER
;
1098 pipe_resource_reference(&img
->texture
, tex
);
1100 *error
= __DRI_IMAGE_ERROR_SUCCESS
;
1105 dri2_from_fds(__DRIscreen
*screen
, int width
, int height
, int fourcc
,
1106 int *fds
, int num_fds
, int *strides
, int *offsets
,
1107 void *loaderPrivate
)
1110 int format
, stride
, dri_components
;
1114 if (offsets
[0] != 0)
1117 format
= convert_fourcc(fourcc
, &dri_components
);
1121 /* Strides are in bytes not pixels. */
1122 stride
= strides
[0] /4;
1124 img
= dri2_create_image_from_fd(screen
, width
, height
, format
,
1125 fds
[0], stride
, loaderPrivate
);
1129 img
->dri_components
= dri_components
;
1134 dri2_from_dma_bufs(__DRIscreen
*screen
,
1135 int width
, int height
, int fourcc
,
1136 int *fds
, int num_fds
,
1137 int *strides
, int *offsets
,
1138 enum __DRIYUVColorSpace yuv_color_space
,
1139 enum __DRISampleRange sample_range
,
1140 enum __DRIChromaSiting horizontal_siting
,
1141 enum __DRIChromaSiting vertical_siting
,
1143 void *loaderPrivate
)
1146 int format
, stride
, dri_components
;
1148 if (num_fds
!= 1 || offsets
[0] != 0) {
1149 *error
= __DRI_IMAGE_ERROR_BAD_MATCH
;
1153 format
= convert_fourcc(fourcc
, &dri_components
);
1155 *error
= __DRI_IMAGE_ERROR_BAD_MATCH
;
1159 /* Strides are in bytes not pixels. */
1160 stride
= strides
[0] /4;
1162 img
= dri2_create_image_from_fd(screen
, width
, height
, format
,
1163 fds
[0], stride
, loaderPrivate
);
1165 *error
= __DRI_IMAGE_ERROR_BAD_ALLOC
;
1169 img
->yuv_color_space
= yuv_color_space
;
1170 img
->sample_range
= sample_range
;
1171 img
->horizontal_siting
= horizontal_siting
;
1172 img
->vertical_siting
= vertical_siting
;
1173 img
->dri_components
= dri_components
;
1175 *error
= __DRI_IMAGE_ERROR_SUCCESS
;
1180 dri2_blit_image(__DRIcontext
*context
, __DRIimage
*dst
, __DRIimage
*src
,
1181 int dstx0
, int dsty0
, int dstwidth
, int dstheight
,
1182 int srcx0
, int srcy0
, int srcwidth
, int srcheight
,
1185 struct dri_context
*ctx
= dri_context(context
);
1186 struct pipe_context
*pipe
= ctx
->st
->pipe
;
1187 struct pipe_screen
*screen
;
1188 struct pipe_fence_handle
*fence
;
1189 struct pipe_blit_info blit
;
1194 memset(&blit
, 0, sizeof(blit
));
1195 blit
.dst
.resource
= dst
->texture
;
1196 blit
.dst
.box
.x
= dstx0
;
1197 blit
.dst
.box
.y
= dsty0
;
1198 blit
.dst
.box
.width
= dstwidth
;
1199 blit
.dst
.box
.height
= dstheight
;
1200 blit
.dst
.box
.depth
= 1;
1201 blit
.dst
.format
= dst
->texture
->format
;
1202 blit
.src
.resource
= src
->texture
;
1203 blit
.src
.box
.x
= srcx0
;
1204 blit
.src
.box
.y
= srcy0
;
1205 blit
.src
.box
.width
= srcwidth
;
1206 blit
.src
.box
.height
= srcheight
;
1207 blit
.src
.box
.depth
= 1;
1208 blit
.src
.format
= src
->texture
->format
;
1209 blit
.mask
= PIPE_MASK_RGBA
;
1210 blit
.filter
= PIPE_TEX_FILTER_NEAREST
;
1212 pipe
->blit(pipe
, &blit
);
1214 if (flush_flag
== __BLIT_FLAG_FLUSH
) {
1215 pipe
->flush_resource(pipe
, dst
->texture
);
1216 ctx
->st
->flush(ctx
->st
, 0, NULL
);
1217 } else if (flush_flag
== __BLIT_FLAG_FINISH
) {
1218 screen
= dri_screen(ctx
->sPriv
)->base
.screen
;
1219 pipe
->flush_resource(pipe
, dst
->texture
);
1220 ctx
->st
->flush(ctx
->st
, 0, &fence
);
1221 (void) screen
->fence_finish(screen
, fence
, PIPE_TIMEOUT_INFINITE
);
1222 screen
->fence_reference(screen
, &fence
, NULL
);
1227 dri2_destroy_image(__DRIimage
*img
)
1229 pipe_resource_reference(&img
->texture
, NULL
);
1234 dri2_get_capabilities(__DRIscreen
*_screen
)
1236 struct dri_screen
*screen
= dri_screen(_screen
);
1238 return (screen
->can_share_buffer
? __DRI_IMAGE_CAP_GLOBAL_NAMES
: 0);
1241 /* The extension is modified during runtime if DRI_PRIME is detected */
1242 static __DRIimageExtension dri2ImageExtension
= {
1243 .base
= { __DRI_IMAGE
, 11 },
1245 .createImageFromName
= dri2_create_image_from_name
,
1246 .createImageFromRenderbuffer
= dri2_create_image_from_renderbuffer
,
1247 .destroyImage
= dri2_destroy_image
,
1248 .createImage
= dri2_create_image
,
1249 .queryImage
= dri2_query_image
,
1250 .dupImage
= dri2_dup_image
,
1251 .validateUsage
= dri2_validate_usage
,
1252 .createImageFromNames
= dri2_from_names
,
1253 .fromPlanar
= dri2_from_planar
,
1254 .createImageFromTexture
= dri2_create_from_texture
,
1255 .createImageFromFds
= NULL
,
1256 .createImageFromDmaBufs
= NULL
,
1257 .blitImage
= dri2_blit_image
,
1258 .getCapabilities
= dri2_get_capabilities
,
1263 dri2_is_opencl_interop_loaded_locked(struct dri_screen
*screen
)
1265 return screen
->opencl_dri_event_add_ref
&&
1266 screen
->opencl_dri_event_release
&&
1267 screen
->opencl_dri_event_wait
&&
1268 screen
->opencl_dri_event_get_fence
;
1272 dri2_load_opencl_interop(struct dri_screen
*screen
)
1274 #if defined(RTLD_DEFAULT)
1277 pipe_mutex_lock(screen
->opencl_func_mutex
);
1279 if (dri2_is_opencl_interop_loaded_locked(screen
)) {
1280 pipe_mutex_unlock(screen
->opencl_func_mutex
);
1284 screen
->opencl_dri_event_add_ref
=
1285 dlsym(RTLD_DEFAULT
, "opencl_dri_event_add_ref");
1286 screen
->opencl_dri_event_release
=
1287 dlsym(RTLD_DEFAULT
, "opencl_dri_event_release");
1288 screen
->opencl_dri_event_wait
=
1289 dlsym(RTLD_DEFAULT
, "opencl_dri_event_wait");
1290 screen
->opencl_dri_event_get_fence
=
1291 dlsym(RTLD_DEFAULT
, "opencl_dri_event_get_fence");
1293 success
= dri2_is_opencl_interop_loaded_locked(screen
);
1294 pipe_mutex_unlock(screen
->opencl_func_mutex
);
1302 struct dri_screen
*driscreen
;
1303 struct pipe_fence_handle
*pipe_fence
;
1308 dri2_create_fence(__DRIcontext
*_ctx
)
1310 struct pipe_context
*ctx
= dri_context(_ctx
)->st
->pipe
;
1311 struct dri2_fence
*fence
= CALLOC_STRUCT(dri2_fence
);
1316 ctx
->flush(ctx
, &fence
->pipe_fence
, 0);
1318 if (!fence
->pipe_fence
) {
1323 fence
->driscreen
= dri_screen(_ctx
->driScreenPriv
);
1328 dri2_get_fence_from_cl_event(__DRIscreen
*_screen
, intptr_t cl_event
)
1330 struct dri_screen
*driscreen
= dri_screen(_screen
);
1331 struct dri2_fence
*fence
;
1333 if (!dri2_load_opencl_interop(driscreen
))
1336 fence
= CALLOC_STRUCT(dri2_fence
);
1340 fence
->cl_event
= (void*)cl_event
;
1342 if (!driscreen
->opencl_dri_event_add_ref(fence
->cl_event
)) {
1347 fence
->driscreen
= driscreen
;
1352 dri2_destroy_fence(__DRIscreen
*_screen
, void *_fence
)
1354 struct dri_screen
*driscreen
= dri_screen(_screen
);
1355 struct pipe_screen
*screen
= driscreen
->base
.screen
;
1356 struct dri2_fence
*fence
= (struct dri2_fence
*)_fence
;
1358 if (fence
->pipe_fence
)
1359 screen
->fence_reference(screen
, &fence
->pipe_fence
, NULL
);
1360 else if (fence
->cl_event
)
1361 driscreen
->opencl_dri_event_release(fence
->cl_event
);
1369 dri2_client_wait_sync(__DRIcontext
*_ctx
, void *_fence
, unsigned flags
,
1372 struct dri2_fence
*fence
= (struct dri2_fence
*)_fence
;
1373 struct dri_screen
*driscreen
= fence
->driscreen
;
1374 struct pipe_screen
*screen
= driscreen
->base
.screen
;
1376 /* No need to flush. The context was flushed when the fence was created. */
1378 if (fence
->pipe_fence
)
1379 return screen
->fence_finish(screen
, fence
->pipe_fence
, timeout
);
1380 else if (fence
->cl_event
) {
1381 struct pipe_fence_handle
*pipe_fence
=
1382 driscreen
->opencl_dri_event_get_fence(fence
->cl_event
);
1385 return screen
->fence_finish(screen
, pipe_fence
, timeout
);
1387 return driscreen
->opencl_dri_event_wait(fence
->cl_event
, timeout
);
1396 dri2_server_wait_sync(__DRIcontext
*_ctx
, void *_fence
, unsigned flags
)
1398 /* AFAIK, no driver currently supports parallel context execution. */
1401 static __DRI2fenceExtension dri2FenceExtension
= {
1402 .base
= { __DRI2_FENCE
, 1 },
1404 .create_fence
= dri2_create_fence
,
1405 .get_fence_from_cl_event
= dri2_get_fence_from_cl_event
,
1406 .destroy_fence
= dri2_destroy_fence
,
1407 .client_wait_sync
= dri2_client_wait_sync
,
1408 .server_wait_sync
= dri2_server_wait_sync
1411 static const __DRIrobustnessExtension dri2Robustness
= {
1412 .base
= { __DRI2_ROBUSTNESS
, 1 }
1416 * Backend function init_screen.
1419 static const __DRIextension
*dri_screen_extensions
[] = {
1420 &driTexBufferExtension
.base
,
1421 &dri2FlushExtension
.base
,
1422 &dri2ImageExtension
.base
,
1423 &dri2RendererQueryExtension
.base
,
1424 &dri2ConfigQueryExtension
.base
,
1425 &dri2ThrottleExtension
.base
,
1426 &dri2FenceExtension
.base
,
1430 static const __DRIextension
*dri_robust_screen_extensions
[] = {
1431 &driTexBufferExtension
.base
,
1432 &dri2FlushExtension
.base
,
1433 &dri2ImageExtension
.base
,
1434 &dri2RendererQueryExtension
.base
,
1435 &dri2ConfigQueryExtension
.base
,
1436 &dri2ThrottleExtension
.base
,
1437 &dri2FenceExtension
.base
,
1438 &dri2Robustness
.base
,
1443 * This is the driver specific part of the createNewScreen entry point.
1445 * Returns the struct gl_config supported by this driver.
1447 static const __DRIconfig
**
1448 dri2_init_screen(__DRIscreen
* sPriv
)
1450 const __DRIconfig
**configs
;
1451 struct dri_screen
*screen
;
1452 struct pipe_screen
*pscreen
= NULL
;
1453 const struct drm_conf_ret
*throttle_ret
;
1454 const struct drm_conf_ret
*dmabuf_ret
;
1457 screen
= CALLOC_STRUCT(dri_screen
);
1461 screen
->sPriv
= sPriv
;
1462 screen
->fd
= sPriv
->fd
;
1463 pipe_mutex_init(screen
->opencl_func_mutex
);
1465 sPriv
->driverPrivate
= (void *)screen
;
1467 if (screen
->fd
< 0 || (fd
= dup(screen
->fd
)) < 0)
1470 if (pipe_loader_drm_probe_fd(&screen
->dev
, fd
))
1471 pscreen
= pipe_loader_create_screen(screen
->dev
);
1476 throttle_ret
= pipe_loader_configuration(screen
->dev
, DRM_CONF_THROTTLE
);
1477 dmabuf_ret
= pipe_loader_configuration(screen
->dev
, DRM_CONF_SHARE_FD
);
1479 if (throttle_ret
&& throttle_ret
->val
.val_int
!= -1) {
1480 screen
->throttling_enabled
= TRUE
;
1481 screen
->default_throttle_frames
= throttle_ret
->val
.val_int
;
1484 if (dmabuf_ret
&& dmabuf_ret
->val
.val_bool
) {
1487 if (drmGetCap(sPriv
->fd
, DRM_CAP_PRIME
, &cap
) == 0 &&
1488 (cap
& DRM_PRIME_CAP_IMPORT
)) {
1489 dri2ImageExtension
.createImageFromFds
= dri2_from_fds
;
1490 dri2ImageExtension
.createImageFromDmaBufs
= dri2_from_dma_bufs
;
1494 if (pscreen
->get_param(pscreen
, PIPE_CAP_DEVICE_RESET_STATUS_QUERY
)) {
1495 sPriv
->extensions
= dri_robust_screen_extensions
;
1496 screen
->has_reset_status_query
= true;
1499 sPriv
->extensions
= dri_screen_extensions
;
1501 configs
= dri_init_screen_helper(screen
, pscreen
, screen
->dev
->driver_name
);
1505 screen
->can_share_buffer
= true;
1506 screen
->auto_fake_front
= dri_with_format(sPriv
);
1507 screen
->broken_invalidate
= !sPriv
->dri2
.useInvalidate
;
1508 screen
->lookup_egl_image
= dri2_lookup_egl_image
;
1512 dri_destroy_screen_helper(screen
);
1514 pipe_loader_release(&screen
->dev
, 1);
1522 * This is the driver specific part of the createNewScreen entry point.
1524 * Returns the struct gl_config supported by this driver.
1526 static const __DRIconfig
**
1527 dri_kms_init_screen(__DRIscreen
* sPriv
)
1529 #if defined(GALLIUM_SOFTPIPE)
1530 const __DRIconfig
**configs
;
1531 struct dri_screen
*screen
;
1532 struct pipe_screen
*pscreen
= NULL
;
1536 screen
= CALLOC_STRUCT(dri_screen
);
1540 screen
->sPriv
= sPriv
;
1541 screen
->fd
= sPriv
->fd
;
1543 sPriv
->driverPrivate
= (void *)screen
;
1545 if (screen
->fd
< 0 || (fd
= dup(screen
->fd
)) < 0)
1548 if (pipe_loader_sw_probe_kms(&screen
->dev
, fd
))
1549 pscreen
= pipe_loader_create_screen(screen
->dev
);
1554 if (drmGetCap(sPriv
->fd
, DRM_CAP_PRIME
, &cap
) == 0 &&
1555 (cap
& DRM_PRIME_CAP_IMPORT
)) {
1556 dri2ImageExtension
.createImageFromFds
= dri2_from_fds
;
1557 dri2ImageExtension
.createImageFromDmaBufs
= dri2_from_dma_bufs
;
1560 sPriv
->extensions
= dri_screen_extensions
;
1562 configs
= dri_init_screen_helper(screen
, pscreen
, "swrast");
1566 screen
->can_share_buffer
= false;
1567 screen
->auto_fake_front
= dri_with_format(sPriv
);
1568 screen
->broken_invalidate
= !sPriv
->dri2
.useInvalidate
;
1569 screen
->lookup_egl_image
= dri2_lookup_egl_image
;
1573 dri_destroy_screen_helper(screen
);
1575 pipe_loader_release(&screen
->dev
, 1);
1579 #endif // GALLIUM_SOFTPIPE
1584 dri2_create_buffer(__DRIscreen
* sPriv
,
1585 __DRIdrawable
* dPriv
,
1586 const struct gl_config
* visual
, boolean isPixmap
)
1588 struct dri_drawable
*drawable
= NULL
;
1590 if (!dri_create_buffer(sPriv
, dPriv
, visual
, isPixmap
))
1593 drawable
= dPriv
->driverPrivate
;
1595 drawable
->allocate_textures
= dri2_allocate_textures
;
1596 drawable
->flush_frontbuffer
= dri2_flush_frontbuffer
;
1597 drawable
->update_tex_buffer
= dri2_update_tex_buffer
;
1603 * DRI driver virtual function table.
1605 * DRI versions differ in their implementation of init_screen and swap_buffers.
1607 const struct __DriverAPIRec galliumdrm_driver_api
= {
1608 .InitScreen
= dri2_init_screen
,
1609 .DestroyScreen
= dri_destroy_screen
,
1610 .CreateContext
= dri_create_context
,
1611 .DestroyContext
= dri_destroy_context
,
1612 .CreateBuffer
= dri2_create_buffer
,
1613 .DestroyBuffer
= dri_destroy_buffer
,
1614 .MakeCurrent
= dri_make_current
,
1615 .UnbindContext
= dri_unbind_context
,
1617 .AllocateBuffer
= dri2_allocate_buffer
,
1618 .ReleaseBuffer
= dri2_release_buffer
,
1622 * DRI driver virtual function table.
1624 * KMS/DRM version of the DriverAPI above sporting a different InitScreen
1625 * hook. The latter is used to explicitly initialise the kms_swrast driver
1626 * rather than selecting the approapriate driver as suggested by the loader.
1628 const struct __DriverAPIRec dri_kms_driver_api
= {
1629 .InitScreen
= dri_kms_init_screen
,
1630 .DestroyScreen
= dri_destroy_screen
,
1631 .CreateContext
= dri_create_context
,
1632 .DestroyContext
= dri_destroy_context
,
1633 .CreateBuffer
= dri2_create_buffer
,
1634 .DestroyBuffer
= dri_destroy_buffer
,
1635 .MakeCurrent
= dri_make_current
,
1636 .UnbindContext
= dri_unbind_context
,
1638 .AllocateBuffer
= dri2_allocate_buffer
,
1639 .ReleaseBuffer
= dri2_release_buffer
,
1642 /* This is the table of extensions that the loader will dlsym() for. */
1643 const __DRIextension
*galliumdrm_driver_extensions
[] = {
1644 &driCoreExtension
.base
,
1645 &driImageDriverExtension
.base
,
1646 &driDRI2Extension
.base
,
1647 &gallium_config_options
.base
,
1651 /* vim: set sw=3 ts=8 sts=3 expandtab: */