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
;
105 * DRI2 flush extension.
108 dri2_flush_drawable(__DRIdrawable
*dPriv
)
110 dri_flush(dPriv
->driContextPriv
, dPriv
, __DRI2_FLUSH_DRAWABLE
, -1);
114 dri2_invalidate_drawable(__DRIdrawable
*dPriv
)
116 struct dri_drawable
*drawable
= dri_drawable(dPriv
);
118 dri2InvalidateDrawable(dPriv
);
119 drawable
->dPriv
->lastStamp
= drawable
->dPriv
->dri2
.stamp
;
121 p_atomic_inc(&drawable
->base
.stamp
);
124 static const __DRI2flushExtension dri2FlushExtension
= {
125 .base
= { __DRI2_FLUSH
, 4 },
127 .flush
= dri2_flush_drawable
,
128 .invalidate
= dri2_invalidate_drawable
,
129 .flush_with_flags
= dri_flush
,
133 * Retrieve __DRIbuffer from the DRI loader.
136 dri2_drawable_get_buffers(struct dri_drawable
*drawable
,
137 const enum st_attachment_type
*atts
,
140 __DRIdrawable
*dri_drawable
= drawable
->dPriv
;
141 const __DRIdri2LoaderExtension
*loader
= drawable
->sPriv
->dri2
.loader
;
143 __DRIbuffer
*buffers
;
145 unsigned attachments
[10];
146 unsigned num_attachments
, i
;
149 with_format
= dri_with_format(drawable
->sPriv
);
153 /* for Xserver 1.6.0 (DRI2 version 1) we always need to ask for the front */
155 attachments
[num_attachments
++] = __DRI_BUFFER_FRONT_LEFT
;
157 for (i
= 0; i
< *count
; i
++) {
158 enum pipe_format format
;
162 dri_drawable_get_format(drawable
, atts
[i
], &format
, &bind
);
163 if (format
== PIPE_FORMAT_NONE
)
167 case ST_ATTACHMENT_FRONT_LEFT
:
171 att
= __DRI_BUFFER_FRONT_LEFT
;
173 case ST_ATTACHMENT_BACK_LEFT
:
174 att
= __DRI_BUFFER_BACK_LEFT
;
176 case ST_ATTACHMENT_FRONT_RIGHT
:
177 att
= __DRI_BUFFER_FRONT_RIGHT
;
179 case ST_ATTACHMENT_BACK_RIGHT
:
180 att
= __DRI_BUFFER_BACK_RIGHT
;
187 * In this switch statement we must support all formats that
188 * may occur as the stvis->color_format.
191 case PIPE_FORMAT_BGRA8888_UNORM
:
194 case PIPE_FORMAT_BGRX8888_UNORM
:
197 case PIPE_FORMAT_B5G6R5_UNORM
:
201 depth
= util_format_get_blocksizebits(format
);
202 assert(!"Unexpected format in dri2_drawable_get_buffers()");
205 attachments
[num_attachments
++] = att
;
207 attachments
[num_attachments
++] = depth
;
212 num_attachments
/= 2;
213 buffers
= loader
->getBuffersWithFormat(dri_drawable
,
214 &dri_drawable
->w
, &dri_drawable
->h
,
215 attachments
, num_attachments
,
216 &num_buffers
, dri_drawable
->loaderPrivate
);
219 buffers
= loader
->getBuffers(dri_drawable
,
220 &dri_drawable
->w
, &dri_drawable
->h
,
221 attachments
, num_attachments
,
222 &num_buffers
, dri_drawable
->loaderPrivate
);
226 *count
= num_buffers
;
232 dri_image_drawable_get_buffers(struct dri_drawable
*drawable
,
233 struct __DRIimageList
*images
,
234 const enum st_attachment_type
*statts
,
235 unsigned statts_count
)
237 __DRIdrawable
*dPriv
= drawable
->dPriv
;
238 __DRIscreen
*sPriv
= drawable
->sPriv
;
239 unsigned int image_format
= __DRI_IMAGE_FORMAT_NONE
;
241 uint32_t buffer_mask
= 0;
244 for (i
= 0; i
< statts_count
; i
++) {
245 dri_drawable_get_format(drawable
, statts
[i
], &pf
, &bind
);
246 if (pf
== PIPE_FORMAT_NONE
)
250 case ST_ATTACHMENT_FRONT_LEFT
:
251 buffer_mask
|= __DRI_IMAGE_BUFFER_FRONT
;
253 case ST_ATTACHMENT_BACK_LEFT
:
254 buffer_mask
|= __DRI_IMAGE_BUFFER_BACK
;
261 case PIPE_FORMAT_B5G6R5_UNORM
:
262 image_format
= __DRI_IMAGE_FORMAT_RGB565
;
264 case PIPE_FORMAT_BGRX8888_UNORM
:
265 image_format
= __DRI_IMAGE_FORMAT_XRGB8888
;
267 case PIPE_FORMAT_BGRA8888_UNORM
:
268 image_format
= __DRI_IMAGE_FORMAT_ARGB8888
;
270 case PIPE_FORMAT_RGBA8888_UNORM
:
271 image_format
= __DRI_IMAGE_FORMAT_ABGR8888
;
274 image_format
= __DRI_IMAGE_FORMAT_NONE
;
279 return (*sPriv
->image
.loader
->getBuffers
) (dPriv
, image_format
,
280 (uint32_t *) &drawable
->base
.stamp
,
281 dPriv
->loaderPrivate
, buffer_mask
,
286 dri2_allocate_buffer(__DRIscreen
*sPriv
,
287 unsigned attachment
, unsigned format
,
288 int width
, int height
)
290 struct dri_screen
*screen
= dri_screen(sPriv
);
291 struct dri2_buffer
*buffer
;
292 struct pipe_resource templ
;
295 struct winsys_handle whandle
;
297 switch (attachment
) {
298 case __DRI_BUFFER_FRONT_LEFT
:
299 case __DRI_BUFFER_FAKE_FRONT_LEFT
:
300 bind
= PIPE_BIND_RENDER_TARGET
| PIPE_BIND_SAMPLER_VIEW
;
302 case __DRI_BUFFER_BACK_LEFT
:
303 bind
= PIPE_BIND_RENDER_TARGET
| PIPE_BIND_SAMPLER_VIEW
;
305 case __DRI_BUFFER_DEPTH
:
306 case __DRI_BUFFER_DEPTH_STENCIL
:
307 case __DRI_BUFFER_STENCIL
:
308 bind
= PIPE_BIND_DEPTH_STENCIL
; /* XXX sampler? */
312 /* because we get the handle and stride */
313 bind
|= PIPE_BIND_SHARED
;
317 pf
= PIPE_FORMAT_BGRA8888_UNORM
;
320 pf
= PIPE_FORMAT_BGRX8888_UNORM
;
323 pf
= PIPE_FORMAT_Z16_UNORM
;
329 buffer
= CALLOC_STRUCT(dri2_buffer
);
333 memset(&templ
, 0, sizeof(templ
));
336 templ
.target
= PIPE_TEXTURE_2D
;
337 templ
.last_level
= 0;
338 templ
.width0
= width
;
339 templ
.height0
= height
;
341 templ
.array_size
= 1;
344 screen
->base
.screen
->resource_create(screen
->base
.screen
, &templ
);
345 if (!buffer
->resource
) {
350 memset(&whandle
, 0, sizeof(whandle
));
351 if (screen
->can_share_buffer
)
352 whandle
.type
= DRM_API_HANDLE_TYPE_SHARED
;
354 whandle
.type
= DRM_API_HANDLE_TYPE_KMS
;
356 screen
->base
.screen
->resource_get_handle(screen
->base
.screen
,
357 buffer
->resource
, &whandle
,
358 PIPE_HANDLE_USAGE_EXPLICIT_FLUSH
| PIPE_HANDLE_USAGE_READ
);
360 buffer
->base
.attachment
= attachment
;
361 buffer
->base
.name
= whandle
.handle
;
362 buffer
->base
.cpp
= util_format_get_blocksize(pf
);
363 buffer
->base
.pitch
= whandle
.stride
;
365 return &buffer
->base
;
369 dri2_release_buffer(__DRIscreen
*sPriv
, __DRIbuffer
*bPriv
)
371 struct dri2_buffer
*buffer
= dri2_buffer(bPriv
);
373 pipe_resource_reference(&buffer
->resource
, NULL
);
378 * Backend functions for st_framebuffer interface.
382 dri2_allocate_textures(struct dri_context
*ctx
,
383 struct dri_drawable
*drawable
,
384 const enum st_attachment_type
*statts
,
385 unsigned statts_count
)
387 __DRIscreen
*sPriv
= drawable
->sPriv
;
388 __DRIdrawable
*dri_drawable
= drawable
->dPriv
;
389 struct dri_screen
*screen
= dri_screen(sPriv
);
390 struct pipe_resource templ
;
391 boolean alloc_depthstencil
= FALSE
;
393 const __DRIimageLoaderExtension
*image
= sPriv
->image
.loader
;
394 /* Image specific variables */
395 struct __DRIimageList images
;
396 /* Dri2 specific variables */
397 __DRIbuffer
*buffers
= NULL
;
398 struct winsys_handle whandle
;
399 unsigned num_buffers
= statts_count
;
401 /* First get the buffers from the loader */
403 if (!dri_image_drawable_get_buffers(drawable
, &images
,
404 statts
, statts_count
))
408 buffers
= dri2_drawable_get_buffers(drawable
, statts
, &num_buffers
);
409 if (!buffers
|| (drawable
->old_num
== num_buffers
&&
410 drawable
->old_w
== dri_drawable
->w
&&
411 drawable
->old_h
== dri_drawable
->h
&&
412 memcmp(drawable
->old
, buffers
,
413 sizeof(__DRIbuffer
) * num_buffers
) == 0))
417 /* Second clean useless resources*/
419 /* See if we need a depth-stencil buffer. */
420 for (i
= 0; i
< statts_count
; i
++) {
421 if (statts
[i
] == ST_ATTACHMENT_DEPTH_STENCIL
) {
422 alloc_depthstencil
= TRUE
;
427 /* Delete the resources we won't need. */
428 for (i
= 0; i
< ST_ATTACHMENT_COUNT
; i
++) {
429 /* Don't delete the depth-stencil buffer, we can reuse it. */
430 if (i
== ST_ATTACHMENT_DEPTH_STENCIL
&& alloc_depthstencil
)
433 /* Flush the texture before unreferencing, so that other clients can
434 * see what the driver has rendered.
436 if (i
!= ST_ATTACHMENT_DEPTH_STENCIL
&& drawable
->textures
[i
]) {
437 struct pipe_context
*pipe
= ctx
->st
->pipe
;
438 pipe
->flush_resource(pipe
, drawable
->textures
[i
]);
441 pipe_resource_reference(&drawable
->textures
[i
], NULL
);
444 if (drawable
->stvis
.samples
> 1) {
445 for (i
= 0; i
< ST_ATTACHMENT_COUNT
; i
++) {
448 /* Don't delete MSAA resources for the attachments which are enabled,
449 * we can reuse them. */
450 for (j
= 0; j
< statts_count
; j
++) {
451 if (i
== statts
[j
]) {
458 pipe_resource_reference(&drawable
->msaa_textures
[i
], NULL
);
463 /* Third use the buffers retrieved to fill the drawable info */
465 memset(&templ
, 0, sizeof(templ
));
466 templ
.target
= screen
->target
;
467 templ
.last_level
= 0;
469 templ
.array_size
= 1;
472 if (images
.image_mask
& __DRI_IMAGE_BUFFER_FRONT
) {
473 struct pipe_resource
**buf
=
474 &drawable
->textures
[ST_ATTACHMENT_FRONT_LEFT
];
475 struct pipe_resource
*texture
= images
.front
->texture
;
477 dri_drawable
->w
= texture
->width0
;
478 dri_drawable
->h
= texture
->height0
;
480 pipe_resource_reference(buf
, texture
);
483 if (images
.image_mask
& __DRI_IMAGE_BUFFER_BACK
) {
484 struct pipe_resource
**buf
=
485 &drawable
->textures
[ST_ATTACHMENT_BACK_LEFT
];
486 struct pipe_resource
*texture
= images
.back
->texture
;
488 dri_drawable
->w
= texture
->width0
;
489 dri_drawable
->h
= texture
->height0
;
491 pipe_resource_reference(buf
, texture
);
494 /* Note: if there is both a back and a front buffer,
495 * then they have the same size.
497 templ
.width0
= dri_drawable
->w
;
498 templ
.height0
= dri_drawable
->h
;
501 memset(&whandle
, 0, sizeof(whandle
));
503 /* Process DRI-provided buffers and get pipe_resources. */
504 for (i
= 0; i
< num_buffers
; i
++) {
505 __DRIbuffer
*buf
= &buffers
[i
];
506 enum st_attachment_type statt
;
507 enum pipe_format format
;
509 switch (buf
->attachment
) {
510 case __DRI_BUFFER_FRONT_LEFT
:
511 if (!screen
->auto_fake_front
) {
512 continue; /* invalid attachment */
515 case __DRI_BUFFER_FAKE_FRONT_LEFT
:
516 statt
= ST_ATTACHMENT_FRONT_LEFT
;
518 case __DRI_BUFFER_BACK_LEFT
:
519 statt
= ST_ATTACHMENT_BACK_LEFT
;
522 continue; /* invalid attachment */
525 dri_drawable_get_format(drawable
, statt
, &format
, &bind
);
526 if (format
== PIPE_FORMAT_NONE
)
529 /* dri2_drawable_get_buffers has already filled dri_drawable->w
530 * and dri_drawable->h */
531 templ
.width0
= dri_drawable
->w
;
532 templ
.height0
= dri_drawable
->h
;
533 templ
.format
= format
;
535 whandle
.handle
= buf
->name
;
536 whandle
.stride
= buf
->pitch
;
537 if (screen
->can_share_buffer
)
538 whandle
.type
= DRM_API_HANDLE_TYPE_SHARED
;
540 whandle
.type
= DRM_API_HANDLE_TYPE_KMS
;
541 drawable
->textures
[statt
] =
542 screen
->base
.screen
->resource_from_handle(screen
->base
.screen
,
544 PIPE_HANDLE_USAGE_EXPLICIT_FLUSH
| PIPE_HANDLE_USAGE_READ
);
545 assert(drawable
->textures
[statt
]);
549 /* Allocate private MSAA colorbuffers. */
550 if (drawable
->stvis
.samples
> 1) {
551 for (i
= 0; i
< statts_count
; i
++) {
552 enum st_attachment_type statt
= statts
[i
];
554 if (statt
== ST_ATTACHMENT_DEPTH_STENCIL
)
557 if (drawable
->textures
[statt
]) {
558 templ
.format
= drawable
->textures
[statt
]->format
;
559 templ
.bind
= drawable
->textures
[statt
]->bind
& ~PIPE_BIND_SCANOUT
;
560 templ
.nr_samples
= drawable
->stvis
.samples
;
562 /* Try to reuse the resource.
563 * (the other resource parameters should be constant)
565 if (!drawable
->msaa_textures
[statt
] ||
566 drawable
->msaa_textures
[statt
]->width0
!= templ
.width0
||
567 drawable
->msaa_textures
[statt
]->height0
!= templ
.height0
) {
568 /* Allocate a new one. */
569 pipe_resource_reference(&drawable
->msaa_textures
[statt
], NULL
);
571 drawable
->msaa_textures
[statt
] =
572 screen
->base
.screen
->resource_create(screen
->base
.screen
,
574 assert(drawable
->msaa_textures
[statt
]);
576 /* If there are any MSAA resources, we should initialize them
577 * such that they contain the same data as the single-sample
578 * resources we just got from the X server.
580 * The reason for this is that the state tracker (and
581 * therefore the app) can access the MSAA resources only.
582 * The single-sample resources are not exposed
583 * to the state tracker.
586 dri_pipe_blit(ctx
->st
->pipe
,
587 drawable
->msaa_textures
[statt
],
588 drawable
->textures
[statt
]);
592 pipe_resource_reference(&drawable
->msaa_textures
[statt
], NULL
);
597 /* Allocate a private depth-stencil buffer. */
598 if (alloc_depthstencil
) {
599 enum st_attachment_type statt
= ST_ATTACHMENT_DEPTH_STENCIL
;
600 struct pipe_resource
**zsbuf
;
601 enum pipe_format format
;
604 dri_drawable_get_format(drawable
, statt
, &format
, &bind
);
607 templ
.format
= format
;
610 if (drawable
->stvis
.samples
> 1) {
611 templ
.nr_samples
= drawable
->stvis
.samples
;
612 zsbuf
= &drawable
->msaa_textures
[statt
];
615 templ
.nr_samples
= 0;
616 zsbuf
= &drawable
->textures
[statt
];
619 /* Try to reuse the resource.
620 * (the other resource parameters should be constant)
623 (*zsbuf
)->width0
!= templ
.width0
||
624 (*zsbuf
)->height0
!= templ
.height0
) {
625 /* Allocate a new one. */
626 pipe_resource_reference(zsbuf
, NULL
);
627 *zsbuf
= screen
->base
.screen
->resource_create(screen
->base
.screen
,
633 pipe_resource_reference(&drawable
->msaa_textures
[statt
], NULL
);
634 pipe_resource_reference(&drawable
->textures
[statt
], NULL
);
638 /* For DRI2, we may get the same buffers again from the server.
639 * To prevent useless imports of gem names, drawable->old* is used
640 * to bypass the import if we get the same buffers. This doesn't apply
641 * to DRI3/Wayland, users of image.loader, since the buffer is managed
642 * by the client (no import), and the back buffer is going to change
646 drawable
->old_num
= num_buffers
;
647 drawable
->old_w
= dri_drawable
->w
;
648 drawable
->old_h
= dri_drawable
->h
;
649 memcpy(drawable
->old
, buffers
, sizeof(__DRIbuffer
) * num_buffers
);
654 dri2_flush_frontbuffer(struct dri_context
*ctx
,
655 struct dri_drawable
*drawable
,
656 enum st_attachment_type statt
)
658 __DRIdrawable
*dri_drawable
= drawable
->dPriv
;
659 const __DRIimageLoaderExtension
*image
= drawable
->sPriv
->image
.loader
;
660 const __DRIdri2LoaderExtension
*loader
= drawable
->sPriv
->dri2
.loader
;
661 struct pipe_context
*pipe
= ctx
->st
->pipe
;
663 if (statt
!= ST_ATTACHMENT_FRONT_LEFT
)
666 if (drawable
->stvis
.samples
> 1) {
667 /* Resolve the front buffer. */
668 dri_pipe_blit(ctx
->st
->pipe
,
669 drawable
->textures
[ST_ATTACHMENT_FRONT_LEFT
],
670 drawable
->msaa_textures
[ST_ATTACHMENT_FRONT_LEFT
]);
673 if (drawable
->textures
[ST_ATTACHMENT_FRONT_LEFT
]) {
674 pipe
->flush_resource(pipe
, drawable
->textures
[ST_ATTACHMENT_FRONT_LEFT
]);
677 pipe
->flush(pipe
, NULL
, 0);
680 image
->flushFrontBuffer(dri_drawable
, dri_drawable
->loaderPrivate
);
682 else if (loader
->flushFrontBuffer
) {
683 loader
->flushFrontBuffer(dri_drawable
, dri_drawable
->loaderPrivate
);
688 dri2_update_tex_buffer(struct dri_drawable
*drawable
,
689 struct dri_context
*ctx
,
690 struct pipe_resource
*res
)
696 dri2_lookup_egl_image(struct dri_screen
*screen
, void *handle
)
698 const __DRIimageLookupExtension
*loader
= screen
->sPriv
->dri2
.image
;
701 if (!loader
->lookupEGLImage
)
704 img
= loader
->lookupEGLImage(screen
->sPriv
,
705 handle
, screen
->sPriv
->loaderPrivate
);
711 dri2_create_image_from_winsys(__DRIscreen
*_screen
,
712 int width
, int height
, int format
,
713 struct winsys_handle
*whandle
, int pitch
,
716 struct dri_screen
*screen
= dri_screen(_screen
);
718 struct pipe_resource templ
;
722 tex_usage
= PIPE_BIND_RENDER_TARGET
| PIPE_BIND_SAMPLER_VIEW
;
725 case __DRI_IMAGE_FORMAT_RGB565
:
726 pf
= PIPE_FORMAT_B5G6R5_UNORM
;
728 case __DRI_IMAGE_FORMAT_XRGB8888
:
729 pf
= PIPE_FORMAT_BGRX8888_UNORM
;
731 case __DRI_IMAGE_FORMAT_ARGB8888
:
732 pf
= PIPE_FORMAT_BGRA8888_UNORM
;
734 case __DRI_IMAGE_FORMAT_ABGR8888
:
735 pf
= PIPE_FORMAT_RGBA8888_UNORM
;
738 pf
= PIPE_FORMAT_NONE
;
741 if (pf
== PIPE_FORMAT_NONE
)
744 img
= CALLOC_STRUCT(__DRIimageRec
);
748 memset(&templ
, 0, sizeof(templ
));
749 templ
.bind
= tex_usage
;
751 templ
.target
= screen
->target
;
752 templ
.last_level
= 0;
753 templ
.width0
= width
;
754 templ
.height0
= height
;
756 templ
.array_size
= 1;
758 whandle
->stride
= pitch
* util_format_get_blocksize(pf
);
760 img
->texture
= screen
->base
.screen
->resource_from_handle(screen
->base
.screen
,
761 &templ
, whandle
, PIPE_HANDLE_USAGE_READ_WRITE
);
769 img
->dri_format
= format
;
771 img
->loader_private
= loaderPrivate
;
777 dri2_create_image_from_name(__DRIscreen
*_screen
,
778 int width
, int height
, int format
,
779 int name
, int pitch
, void *loaderPrivate
)
781 struct winsys_handle whandle
;
783 memset(&whandle
, 0, sizeof(whandle
));
784 whandle
.type
= DRM_API_HANDLE_TYPE_SHARED
;
785 whandle
.handle
= name
;
787 return dri2_create_image_from_winsys(_screen
, width
, height
, format
,
788 &whandle
, pitch
, loaderPrivate
);
792 dri2_create_image_from_fd(__DRIscreen
*_screen
,
793 int width
, int height
, int format
,
794 int fd
, int pitch
, void *loaderPrivate
)
796 struct winsys_handle whandle
;
801 memset(&whandle
, 0, sizeof(whandle
));
802 whandle
.type
= DRM_API_HANDLE_TYPE_FD
;
803 whandle
.handle
= (unsigned)fd
;
805 return dri2_create_image_from_winsys(_screen
, width
, height
, format
,
806 &whandle
, pitch
, loaderPrivate
);
810 dri2_create_image_from_renderbuffer(__DRIcontext
*context
,
811 int renderbuffer
, void *loaderPrivate
)
813 struct dri_context
*ctx
= dri_context(context
);
815 if (!ctx
->st
->get_resource_for_egl_image
)
823 dri2_create_image(__DRIscreen
*_screen
,
824 int width
, int height
, int format
,
825 unsigned int use
, void *loaderPrivate
)
827 struct dri_screen
*screen
= dri_screen(_screen
);
829 struct pipe_resource templ
;
833 tex_usage
= PIPE_BIND_RENDER_TARGET
| PIPE_BIND_SAMPLER_VIEW
;
834 if (use
& __DRI_IMAGE_USE_SCANOUT
)
835 tex_usage
|= PIPE_BIND_SCANOUT
;
836 if (use
& __DRI_IMAGE_USE_SHARE
)
837 tex_usage
|= PIPE_BIND_SHARED
;
838 if (use
& __DRI_IMAGE_USE_LINEAR
)
839 tex_usage
|= PIPE_BIND_LINEAR
;
840 if (use
& __DRI_IMAGE_USE_CURSOR
) {
841 if (width
!= 64 || height
!= 64)
843 tex_usage
|= PIPE_BIND_CURSOR
;
847 case __DRI_IMAGE_FORMAT_RGB565
:
848 pf
= PIPE_FORMAT_B5G6R5_UNORM
;
850 case __DRI_IMAGE_FORMAT_XRGB8888
:
851 pf
= PIPE_FORMAT_BGRX8888_UNORM
;
853 case __DRI_IMAGE_FORMAT_ARGB8888
:
854 pf
= PIPE_FORMAT_BGRA8888_UNORM
;
856 case __DRI_IMAGE_FORMAT_ABGR8888
:
857 pf
= PIPE_FORMAT_RGBA8888_UNORM
;
860 pf
= PIPE_FORMAT_NONE
;
863 if (pf
== PIPE_FORMAT_NONE
)
866 img
= CALLOC_STRUCT(__DRIimageRec
);
870 memset(&templ
, 0, sizeof(templ
));
871 templ
.bind
= tex_usage
;
873 templ
.target
= PIPE_TEXTURE_2D
;
874 templ
.last_level
= 0;
875 templ
.width0
= width
;
876 templ
.height0
= height
;
878 templ
.array_size
= 1;
880 img
->texture
= screen
->base
.screen
->resource_create(screen
->base
.screen
, &templ
);
888 img
->dri_format
= format
;
889 img
->dri_components
= 0;
892 img
->loader_private
= loaderPrivate
;
897 dri2_query_image(__DRIimage
*image
, int attrib
, int *value
)
899 struct winsys_handle whandle
;
902 if (image
->use
& __DRI_IMAGE_USE_BACKBUFFER
)
903 usage
= PIPE_HANDLE_USAGE_EXPLICIT_FLUSH
| PIPE_HANDLE_USAGE_READ
;
905 usage
= PIPE_HANDLE_USAGE_READ_WRITE
;
907 memset(&whandle
, 0, sizeof(whandle
));
910 case __DRI_IMAGE_ATTRIB_STRIDE
:
911 whandle
.type
= DRM_API_HANDLE_TYPE_KMS
;
912 image
->texture
->screen
->resource_get_handle(image
->texture
->screen
,
913 image
->texture
, &whandle
, usage
);
914 *value
= whandle
.stride
;
916 case __DRI_IMAGE_ATTRIB_HANDLE
:
917 whandle
.type
= DRM_API_HANDLE_TYPE_KMS
;
918 image
->texture
->screen
->resource_get_handle(image
->texture
->screen
,
919 image
->texture
, &whandle
, usage
);
920 *value
= whandle
.handle
;
922 case __DRI_IMAGE_ATTRIB_NAME
:
923 whandle
.type
= DRM_API_HANDLE_TYPE_SHARED
;
924 image
->texture
->screen
->resource_get_handle(image
->texture
->screen
,
925 image
->texture
, &whandle
, usage
);
926 *value
= whandle
.handle
;
928 case __DRI_IMAGE_ATTRIB_FD
:
929 whandle
.type
= DRM_API_HANDLE_TYPE_FD
;
930 image
->texture
->screen
->resource_get_handle(image
->texture
->screen
,
931 image
->texture
, &whandle
, usage
);
932 *value
= whandle
.handle
;
934 case __DRI_IMAGE_ATTRIB_FORMAT
:
935 *value
= image
->dri_format
;
937 case __DRI_IMAGE_ATTRIB_WIDTH
:
938 *value
= image
->texture
->width0
;
940 case __DRI_IMAGE_ATTRIB_HEIGHT
:
941 *value
= image
->texture
->height0
;
943 case __DRI_IMAGE_ATTRIB_COMPONENTS
:
944 if (image
->dri_components
== 0)
946 *value
= image
->dri_components
;
948 case __DRI_IMAGE_ATTRIB_FOURCC
:
949 *value
= convert_to_fourcc(image
->dri_format
);
951 case __DRI_IMAGE_ATTRIB_NUM_PLANES
:
960 dri2_dup_image(__DRIimage
*image
, void *loaderPrivate
)
964 img
= CALLOC_STRUCT(__DRIimageRec
);
969 pipe_resource_reference(&img
->texture
, image
->texture
);
970 img
->level
= image
->level
;
971 img
->layer
= image
->layer
;
972 img
->dri_format
= image
->dri_format
;
973 /* This should be 0 for sub images, but dup is also used for base images. */
974 img
->dri_components
= image
->dri_components
;
975 img
->loader_private
= loaderPrivate
;
981 dri2_validate_usage(__DRIimage
*image
, unsigned int use
)
984 * Gallium drivers are bad at adding usages to the resources
985 * once opened again in another process, which is the main use
986 * case for this, so we have to lie.
995 dri2_from_names(__DRIscreen
*screen
, int width
, int height
, int format
,
996 int *names
, int num_names
, int *strides
, int *offsets
,
1000 int stride
, dri_components
;
1004 if (offsets
[0] != 0)
1007 format
= convert_fourcc(format
, &dri_components
);
1011 /* Strides are in bytes not pixels. */
1012 stride
= strides
[0] /4;
1014 img
= dri2_create_image_from_name(screen
, width
, height
, format
,
1015 names
[0], stride
, loaderPrivate
);
1019 img
->dri_components
= dri_components
;
1024 dri2_from_planar(__DRIimage
*image
, int plane
, void *loaderPrivate
)
1031 if (image
->dri_components
== 0)
1034 img
= dri2_dup_image(image
, loaderPrivate
);
1038 /* set this to 0 for sub images. */
1039 img
->dri_components
= 0;
1044 dri2_create_from_texture(__DRIcontext
*context
, int target
, unsigned texture
,
1045 int depth
, int level
, unsigned *error
,
1046 void *loaderPrivate
)
1049 struct gl_context
*ctx
= ((struct st_context
*)dri_context(context
)->st
)->ctx
;
1050 struct gl_texture_object
*obj
;
1051 struct pipe_resource
*tex
;
1054 obj
= _mesa_lookup_texture(ctx
, texture
);
1055 if (!obj
|| obj
->Target
!= target
) {
1056 *error
= __DRI_IMAGE_ERROR_BAD_PARAMETER
;
1060 tex
= st_get_texobj_resource(obj
);
1062 *error
= __DRI_IMAGE_ERROR_BAD_PARAMETER
;
1066 if (target
== GL_TEXTURE_CUBE_MAP
)
1069 _mesa_test_texobj_completeness(ctx
, obj
);
1070 if (!obj
->_BaseComplete
|| (level
> 0 && !obj
->_MipmapComplete
)) {
1071 *error
= __DRI_IMAGE_ERROR_BAD_PARAMETER
;
1075 if (level
< obj
->BaseLevel
|| level
> obj
->_MaxLevel
) {
1076 *error
= __DRI_IMAGE_ERROR_BAD_MATCH
;
1080 if (target
== GL_TEXTURE_3D
&& obj
->Image
[face
][level
]->Depth
< depth
) {
1081 *error
= __DRI_IMAGE_ERROR_BAD_MATCH
;
1085 img
= CALLOC_STRUCT(__DRIimageRec
);
1087 *error
= __DRI_IMAGE_ERROR_BAD_ALLOC
;
1093 img
->dri_format
= driGLFormatToImageFormat(obj
->Image
[face
][level
]->TexFormat
);
1095 img
->loader_private
= loaderPrivate
;
1097 if (img
->dri_format
== __DRI_IMAGE_FORMAT_NONE
) {
1098 *error
= __DRI_IMAGE_ERROR_BAD_PARAMETER
;
1103 pipe_resource_reference(&img
->texture
, tex
);
1105 *error
= __DRI_IMAGE_ERROR_SUCCESS
;
1110 dri2_from_fds(__DRIscreen
*screen
, int width
, int height
, int fourcc
,
1111 int *fds
, int num_fds
, int *strides
, int *offsets
,
1112 void *loaderPrivate
)
1115 int format
, stride
, dri_components
;
1119 if (offsets
[0] != 0)
1122 format
= convert_fourcc(fourcc
, &dri_components
);
1126 /* Strides are in bytes not pixels. */
1127 stride
= strides
[0] /4;
1129 img
= dri2_create_image_from_fd(screen
, width
, height
, format
,
1130 fds
[0], stride
, loaderPrivate
);
1134 img
->dri_components
= dri_components
;
1139 dri2_from_dma_bufs(__DRIscreen
*screen
,
1140 int width
, int height
, int fourcc
,
1141 int *fds
, int num_fds
,
1142 int *strides
, int *offsets
,
1143 enum __DRIYUVColorSpace yuv_color_space
,
1144 enum __DRISampleRange sample_range
,
1145 enum __DRIChromaSiting horizontal_siting
,
1146 enum __DRIChromaSiting vertical_siting
,
1148 void *loaderPrivate
)
1151 int format
, stride
, dri_components
;
1153 if (num_fds
!= 1 || offsets
[0] != 0) {
1154 *error
= __DRI_IMAGE_ERROR_BAD_MATCH
;
1158 format
= convert_fourcc(fourcc
, &dri_components
);
1160 *error
= __DRI_IMAGE_ERROR_BAD_MATCH
;
1164 /* Strides are in bytes not pixels. */
1165 stride
= strides
[0] /4;
1167 img
= dri2_create_image_from_fd(screen
, width
, height
, format
,
1168 fds
[0], stride
, loaderPrivate
);
1170 *error
= __DRI_IMAGE_ERROR_BAD_ALLOC
;
1174 img
->yuv_color_space
= yuv_color_space
;
1175 img
->sample_range
= sample_range
;
1176 img
->horizontal_siting
= horizontal_siting
;
1177 img
->vertical_siting
= vertical_siting
;
1178 img
->dri_components
= dri_components
;
1180 *error
= __DRI_IMAGE_ERROR_SUCCESS
;
1185 dri2_blit_image(__DRIcontext
*context
, __DRIimage
*dst
, __DRIimage
*src
,
1186 int dstx0
, int dsty0
, int dstwidth
, int dstheight
,
1187 int srcx0
, int srcy0
, int srcwidth
, int srcheight
,
1190 struct dri_context
*ctx
= dri_context(context
);
1191 struct pipe_context
*pipe
= ctx
->st
->pipe
;
1192 struct pipe_screen
*screen
;
1193 struct pipe_fence_handle
*fence
;
1194 struct pipe_blit_info blit
;
1199 memset(&blit
, 0, sizeof(blit
));
1200 blit
.dst
.resource
= dst
->texture
;
1201 blit
.dst
.box
.x
= dstx0
;
1202 blit
.dst
.box
.y
= dsty0
;
1203 blit
.dst
.box
.width
= dstwidth
;
1204 blit
.dst
.box
.height
= dstheight
;
1205 blit
.dst
.box
.depth
= 1;
1206 blit
.dst
.format
= dst
->texture
->format
;
1207 blit
.src
.resource
= src
->texture
;
1208 blit
.src
.box
.x
= srcx0
;
1209 blit
.src
.box
.y
= srcy0
;
1210 blit
.src
.box
.width
= srcwidth
;
1211 blit
.src
.box
.height
= srcheight
;
1212 blit
.src
.box
.depth
= 1;
1213 blit
.src
.format
= src
->texture
->format
;
1214 blit
.mask
= PIPE_MASK_RGBA
;
1215 blit
.filter
= PIPE_TEX_FILTER_NEAREST
;
1217 pipe
->blit(pipe
, &blit
);
1219 if (flush_flag
== __BLIT_FLAG_FLUSH
) {
1220 pipe
->flush_resource(pipe
, dst
->texture
);
1221 ctx
->st
->flush(ctx
->st
, 0, NULL
);
1222 } else if (flush_flag
== __BLIT_FLAG_FINISH
) {
1223 screen
= dri_screen(ctx
->sPriv
)->base
.screen
;
1224 pipe
->flush_resource(pipe
, dst
->texture
);
1225 ctx
->st
->flush(ctx
->st
, 0, &fence
);
1226 (void) screen
->fence_finish(screen
, fence
, PIPE_TIMEOUT_INFINITE
);
1227 screen
->fence_reference(screen
, &fence
, NULL
);
1232 dri2_destroy_image(__DRIimage
*img
)
1234 pipe_resource_reference(&img
->texture
, NULL
);
1239 dri2_get_capabilities(__DRIscreen
*_screen
)
1241 struct dri_screen
*screen
= dri_screen(_screen
);
1243 return (screen
->can_share_buffer
? __DRI_IMAGE_CAP_GLOBAL_NAMES
: 0);
1246 /* The extension is modified during runtime if DRI_PRIME is detected */
1247 static __DRIimageExtension dri2ImageExtension
= {
1248 .base
= { __DRI_IMAGE
, 11 },
1250 .createImageFromName
= dri2_create_image_from_name
,
1251 .createImageFromRenderbuffer
= dri2_create_image_from_renderbuffer
,
1252 .destroyImage
= dri2_destroy_image
,
1253 .createImage
= dri2_create_image
,
1254 .queryImage
= dri2_query_image
,
1255 .dupImage
= dri2_dup_image
,
1256 .validateUsage
= dri2_validate_usage
,
1257 .createImageFromNames
= dri2_from_names
,
1258 .fromPlanar
= dri2_from_planar
,
1259 .createImageFromTexture
= dri2_create_from_texture
,
1260 .createImageFromFds
= NULL
,
1261 .createImageFromDmaBufs
= NULL
,
1262 .blitImage
= dri2_blit_image
,
1263 .getCapabilities
= dri2_get_capabilities
,
1268 dri2_is_opencl_interop_loaded_locked(struct dri_screen
*screen
)
1270 return screen
->opencl_dri_event_add_ref
&&
1271 screen
->opencl_dri_event_release
&&
1272 screen
->opencl_dri_event_wait
&&
1273 screen
->opencl_dri_event_get_fence
;
1277 dri2_load_opencl_interop(struct dri_screen
*screen
)
1279 #if defined(RTLD_DEFAULT)
1282 pipe_mutex_lock(screen
->opencl_func_mutex
);
1284 if (dri2_is_opencl_interop_loaded_locked(screen
)) {
1285 pipe_mutex_unlock(screen
->opencl_func_mutex
);
1289 screen
->opencl_dri_event_add_ref
=
1290 dlsym(RTLD_DEFAULT
, "opencl_dri_event_add_ref");
1291 screen
->opencl_dri_event_release
=
1292 dlsym(RTLD_DEFAULT
, "opencl_dri_event_release");
1293 screen
->opencl_dri_event_wait
=
1294 dlsym(RTLD_DEFAULT
, "opencl_dri_event_wait");
1295 screen
->opencl_dri_event_get_fence
=
1296 dlsym(RTLD_DEFAULT
, "opencl_dri_event_get_fence");
1298 success
= dri2_is_opencl_interop_loaded_locked(screen
);
1299 pipe_mutex_unlock(screen
->opencl_func_mutex
);
1307 struct dri_screen
*driscreen
;
1308 struct pipe_fence_handle
*pipe_fence
;
1313 dri2_create_fence(__DRIcontext
*_ctx
)
1315 struct pipe_context
*ctx
= dri_context(_ctx
)->st
->pipe
;
1316 struct dri2_fence
*fence
= CALLOC_STRUCT(dri2_fence
);
1321 ctx
->flush(ctx
, &fence
->pipe_fence
, 0);
1323 if (!fence
->pipe_fence
) {
1328 fence
->driscreen
= dri_screen(_ctx
->driScreenPriv
);
1333 dri2_get_fence_from_cl_event(__DRIscreen
*_screen
, intptr_t cl_event
)
1335 struct dri_screen
*driscreen
= dri_screen(_screen
);
1336 struct dri2_fence
*fence
;
1338 if (!dri2_load_opencl_interop(driscreen
))
1341 fence
= CALLOC_STRUCT(dri2_fence
);
1345 fence
->cl_event
= (void*)cl_event
;
1347 if (!driscreen
->opencl_dri_event_add_ref(fence
->cl_event
)) {
1352 fence
->driscreen
= driscreen
;
1357 dri2_destroy_fence(__DRIscreen
*_screen
, void *_fence
)
1359 struct dri_screen
*driscreen
= dri_screen(_screen
);
1360 struct pipe_screen
*screen
= driscreen
->base
.screen
;
1361 struct dri2_fence
*fence
= (struct dri2_fence
*)_fence
;
1363 if (fence
->pipe_fence
)
1364 screen
->fence_reference(screen
, &fence
->pipe_fence
, NULL
);
1365 else if (fence
->cl_event
)
1366 driscreen
->opencl_dri_event_release(fence
->cl_event
);
1374 dri2_client_wait_sync(__DRIcontext
*_ctx
, void *_fence
, unsigned flags
,
1377 struct dri2_fence
*fence
= (struct dri2_fence
*)_fence
;
1378 struct dri_screen
*driscreen
= fence
->driscreen
;
1379 struct pipe_screen
*screen
= driscreen
->base
.screen
;
1381 /* No need to flush. The context was flushed when the fence was created. */
1383 if (fence
->pipe_fence
)
1384 return screen
->fence_finish(screen
, fence
->pipe_fence
, timeout
);
1385 else if (fence
->cl_event
) {
1386 struct pipe_fence_handle
*pipe_fence
=
1387 driscreen
->opencl_dri_event_get_fence(fence
->cl_event
);
1390 return screen
->fence_finish(screen
, pipe_fence
, timeout
);
1392 return driscreen
->opencl_dri_event_wait(fence
->cl_event
, timeout
);
1401 dri2_server_wait_sync(__DRIcontext
*_ctx
, void *_fence
, unsigned flags
)
1403 /* AFAIK, no driver currently supports parallel context execution. */
1406 static __DRI2fenceExtension dri2FenceExtension
= {
1407 .base
= { __DRI2_FENCE
, 1 },
1409 .create_fence
= dri2_create_fence
,
1410 .get_fence_from_cl_event
= dri2_get_fence_from_cl_event
,
1411 .destroy_fence
= dri2_destroy_fence
,
1412 .client_wait_sync
= dri2_client_wait_sync
,
1413 .server_wait_sync
= dri2_server_wait_sync
1416 static const __DRIrobustnessExtension dri2Robustness
= {
1417 .base
= { __DRI2_ROBUSTNESS
, 1 }
1421 * Backend function init_screen.
1424 static const __DRIextension
*dri_screen_extensions
[] = {
1425 &driTexBufferExtension
.base
,
1426 &dri2FlushExtension
.base
,
1427 &dri2ImageExtension
.base
,
1428 &dri2RendererQueryExtension
.base
,
1429 &dri2ConfigQueryExtension
.base
,
1430 &dri2ThrottleExtension
.base
,
1431 &dri2FenceExtension
.base
,
1435 static const __DRIextension
*dri_robust_screen_extensions
[] = {
1436 &driTexBufferExtension
.base
,
1437 &dri2FlushExtension
.base
,
1438 &dri2ImageExtension
.base
,
1439 &dri2RendererQueryExtension
.base
,
1440 &dri2ConfigQueryExtension
.base
,
1441 &dri2ThrottleExtension
.base
,
1442 &dri2FenceExtension
.base
,
1443 &dri2Robustness
.base
,
1448 * This is the driver specific part of the createNewScreen entry point.
1450 * Returns the struct gl_config supported by this driver.
1452 static const __DRIconfig
**
1453 dri2_init_screen(__DRIscreen
* sPriv
)
1455 const __DRIconfig
**configs
;
1456 struct dri_screen
*screen
;
1457 struct pipe_screen
*pscreen
= NULL
;
1458 const struct drm_conf_ret
*throttle_ret
;
1459 const struct drm_conf_ret
*dmabuf_ret
;
1462 screen
= CALLOC_STRUCT(dri_screen
);
1466 screen
->sPriv
= sPriv
;
1467 screen
->fd
= sPriv
->fd
;
1468 pipe_mutex_init(screen
->opencl_func_mutex
);
1470 sPriv
->driverPrivate
= (void *)screen
;
1472 if (screen
->fd
< 0 || (fd
= dup(screen
->fd
)) < 0)
1475 if (pipe_loader_drm_probe_fd(&screen
->dev
, fd
))
1476 pscreen
= pipe_loader_create_screen(screen
->dev
);
1481 throttle_ret
= pipe_loader_configuration(screen
->dev
, DRM_CONF_THROTTLE
);
1482 dmabuf_ret
= pipe_loader_configuration(screen
->dev
, DRM_CONF_SHARE_FD
);
1484 if (throttle_ret
&& throttle_ret
->val
.val_int
!= -1) {
1485 screen
->throttling_enabled
= TRUE
;
1486 screen
->default_throttle_frames
= throttle_ret
->val
.val_int
;
1489 if (dmabuf_ret
&& dmabuf_ret
->val
.val_bool
) {
1492 if (drmGetCap(sPriv
->fd
, DRM_CAP_PRIME
, &cap
) == 0 &&
1493 (cap
& DRM_PRIME_CAP_IMPORT
)) {
1494 dri2ImageExtension
.createImageFromFds
= dri2_from_fds
;
1495 dri2ImageExtension
.createImageFromDmaBufs
= dri2_from_dma_bufs
;
1499 if (pscreen
->get_param(pscreen
, PIPE_CAP_DEVICE_RESET_STATUS_QUERY
)) {
1500 sPriv
->extensions
= dri_robust_screen_extensions
;
1501 screen
->has_reset_status_query
= true;
1504 sPriv
->extensions
= dri_screen_extensions
;
1506 configs
= dri_init_screen_helper(screen
, pscreen
, screen
->dev
->driver_name
);
1510 screen
->can_share_buffer
= true;
1511 screen
->auto_fake_front
= dri_with_format(sPriv
);
1512 screen
->broken_invalidate
= !sPriv
->dri2
.useInvalidate
;
1513 screen
->lookup_egl_image
= dri2_lookup_egl_image
;
1517 dri_destroy_screen_helper(screen
);
1519 pipe_loader_release(&screen
->dev
, 1);
1527 * This is the driver specific part of the createNewScreen entry point.
1529 * Returns the struct gl_config supported by this driver.
1531 static const __DRIconfig
**
1532 dri_kms_init_screen(__DRIscreen
* sPriv
)
1534 #if defined(GALLIUM_SOFTPIPE)
1535 const __DRIconfig
**configs
;
1536 struct dri_screen
*screen
;
1537 struct pipe_screen
*pscreen
= NULL
;
1541 screen
= CALLOC_STRUCT(dri_screen
);
1545 screen
->sPriv
= sPriv
;
1546 screen
->fd
= sPriv
->fd
;
1548 sPriv
->driverPrivate
= (void *)screen
;
1550 if (screen
->fd
< 0 || (fd
= dup(screen
->fd
)) < 0)
1553 if (pipe_loader_sw_probe_kms(&screen
->dev
, fd
))
1554 pscreen
= pipe_loader_create_screen(screen
->dev
);
1559 if (drmGetCap(sPriv
->fd
, DRM_CAP_PRIME
, &cap
) == 0 &&
1560 (cap
& DRM_PRIME_CAP_IMPORT
)) {
1561 dri2ImageExtension
.createImageFromFds
= dri2_from_fds
;
1562 dri2ImageExtension
.createImageFromDmaBufs
= dri2_from_dma_bufs
;
1565 sPriv
->extensions
= dri_screen_extensions
;
1567 configs
= dri_init_screen_helper(screen
, pscreen
, "swrast");
1571 screen
->can_share_buffer
= false;
1572 screen
->auto_fake_front
= dri_with_format(sPriv
);
1573 screen
->broken_invalidate
= !sPriv
->dri2
.useInvalidate
;
1574 screen
->lookup_egl_image
= dri2_lookup_egl_image
;
1578 dri_destroy_screen_helper(screen
);
1580 pipe_loader_release(&screen
->dev
, 1);
1584 #endif // GALLIUM_SOFTPIPE
1589 dri2_create_buffer(__DRIscreen
* sPriv
,
1590 __DRIdrawable
* dPriv
,
1591 const struct gl_config
* visual
, boolean isPixmap
)
1593 struct dri_drawable
*drawable
= NULL
;
1595 if (!dri_create_buffer(sPriv
, dPriv
, visual
, isPixmap
))
1598 drawable
= dPriv
->driverPrivate
;
1600 drawable
->allocate_textures
= dri2_allocate_textures
;
1601 drawable
->flush_frontbuffer
= dri2_flush_frontbuffer
;
1602 drawable
->update_tex_buffer
= dri2_update_tex_buffer
;
1608 * DRI driver virtual function table.
1610 * DRI versions differ in their implementation of init_screen and swap_buffers.
1612 const struct __DriverAPIRec galliumdrm_driver_api
= {
1613 .InitScreen
= dri2_init_screen
,
1614 .DestroyScreen
= dri_destroy_screen
,
1615 .CreateContext
= dri_create_context
,
1616 .DestroyContext
= dri_destroy_context
,
1617 .CreateBuffer
= dri2_create_buffer
,
1618 .DestroyBuffer
= dri_destroy_buffer
,
1619 .MakeCurrent
= dri_make_current
,
1620 .UnbindContext
= dri_unbind_context
,
1622 .AllocateBuffer
= dri2_allocate_buffer
,
1623 .ReleaseBuffer
= dri2_release_buffer
,
1627 * DRI driver virtual function table.
1629 * KMS/DRM version of the DriverAPI above sporting a different InitScreen
1630 * hook. The latter is used to explicitly initialise the kms_swrast driver
1631 * rather than selecting the approapriate driver as suggested by the loader.
1633 const struct __DriverAPIRec dri_kms_driver_api
= {
1634 .InitScreen
= dri_kms_init_screen
,
1635 .DestroyScreen
= dri_destroy_screen
,
1636 .CreateContext
= dri_create_context
,
1637 .DestroyContext
= dri_destroy_context
,
1638 .CreateBuffer
= dri2_create_buffer
,
1639 .DestroyBuffer
= dri_destroy_buffer
,
1640 .MakeCurrent
= dri_make_current
,
1641 .UnbindContext
= dri_unbind_context
,
1643 .AllocateBuffer
= dri2_allocate_buffer
,
1644 .ReleaseBuffer
= dri2_release_buffer
,
1647 /* This is the table of extensions that the loader will dlsym() for. */
1648 const __DRIextension
*galliumdrm_driver_extensions
[] = {
1649 &driCoreExtension
.base
,
1650 &driImageDriverExtension
.base
,
1651 &driDRI2Extension
.base
,
1652 &gallium_config_options
.base
,
1656 /* vim: set sw=3 ts=8 sts=3 expandtab: */