X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fgallium%2Fstate_trackers%2Fxorg%2Fxorg_dri2.c;h=b90f9c908d2a28ed03072d0a4bd1b9d40bc41ed9;hb=0ff2373131011cf3d7dec737aa4ef5f54d2b7ba5;hp=bdd6a8b205195d97ac80d1a1c130eea86c05b5ea;hpb=eaa3a025da18a0b7f25460f86bb4afcd08017dfe;p=mesa.git diff --git a/src/gallium/state_trackers/xorg/xorg_dri2.c b/src/gallium/state_trackers/xorg/xorg_dri2.c index bdd6a8b2051..b90f9c908d2 100644 --- a/src/gallium/state_trackers/xorg/xorg_dri2.c +++ b/src/gallium/state_trackers/xorg/xorg_dri2.c @@ -38,33 +38,36 @@ #include "dri2.h" #include "pipe/p_state.h" -#include "pipe/p_inlines.h" +#include "util/u_inlines.h" -#include "util/u_rect.h" +#include "util/u_format.h" /* Make all the #if cases in the code esier to read */ -/* XXX can it be set to 1? */ #ifndef DRI2INFOREC_VERSION -#define DRI2INFOREC_VERSION 0 +#define DRI2INFOREC_VERSION 1 +#endif + +#if DRI2INFOREC_VERSION == 2 +static Bool set_format_in_do_create_buffer; #endif typedef struct { PixmapPtr pPixmap; - struct pipe_texture *tex; + struct pipe_resource *tex; struct pipe_fence_handle *fence; } *BufferPrivatePtr; static Bool dri2_do_create_buffer(DrawablePtr pDraw, DRI2BufferPtr buffer, unsigned int format) { - struct pipe_texture *tex = NULL; + struct pipe_resource *tex = NULL; ScreenPtr pScreen = pDraw->pScreen; ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; modesettingPtr ms = modesettingPTR(pScrn); struct exa_pixmap_priv *exa_priv; BufferPrivatePtr private = buffer->driverPrivate; PixmapPtr pPixmap; - unsigned stride, handle; + struct winsys_handle whandle; if (pDraw->type == DRAWABLE_PIXMAP) pPixmap = (PixmapPtr) pDraw; @@ -72,6 +75,7 @@ dri2_do_create_buffer(DrawablePtr pDraw, DRI2BufferPtr buffer, unsigned int form pPixmap = (*pScreen->GetWindowPixmap)((WindowPtr) pDraw); exa_priv = exaGetPixmapDriverPrivate(pPixmap); + switch (buffer->attachment) { default: if (buffer->attachment != DRI2BufferFakeFrontLeft || @@ -92,30 +96,42 @@ dri2_do_create_buffer(DrawablePtr pDraw, DRI2BufferPtr buffer, unsigned int form case 9: #endif if (exa_priv->depth_stencil_tex && - !pf_is_depth_stencil(exa_priv->depth_stencil_tex->format)) + !util_format_is_depth_or_stencil(exa_priv->depth_stencil_tex->format)) exa_priv->depth_stencil_tex = NULL; /* Fall through */ case DRI2BufferDepth: if (exa_priv->depth_stencil_tex) - pipe_texture_reference(&tex, exa_priv->depth_stencil_tex); + pipe_resource_reference(&tex, exa_priv->depth_stencil_tex); else { - struct pipe_texture template; + struct pipe_resource template; + unsigned depthBits = (format != 0) ? format : pDraw->depth; memset(&template, 0, sizeof(template)); template.target = PIPE_TEXTURE_2D; - if (buffer->attachment == DRI2BufferDepth) - template.format = ms->ds_depth_bits_last ? - PIPE_FORMAT_X8Z24_UNORM : PIPE_FORMAT_Z24X8_UNORM; - else - template.format = ms->ds_depth_bits_last ? - PIPE_FORMAT_S8Z24_UNORM : PIPE_FORMAT_Z24S8_UNORM; + if (buffer->attachment == DRI2BufferDepth) { + switch(depthBits) { + case 16: + template.format = PIPE_FORMAT_Z16_UNORM; + break; + case 32: + template.format = PIPE_FORMAT_Z32_UNORM; + break; + default: + template.format = ms->ds_depth_bits_last ? + PIPE_FORMAT_Z24X8_UNORM : PIPE_FORMAT_X8Z24_UNORM; + break; + } + } else { + template.format = ms->ds_depth_bits_last ? + PIPE_FORMAT_Z24_UNORM_S8_USCALED : PIPE_FORMAT_S8_USCALED_Z24_UNORM; + } template.width0 = pDraw->width; template.height0 = pDraw->height; template.depth0 = 1; template.last_level = 0; - template.tex_usage = PIPE_TEXTURE_USAGE_DEPTH_STENCIL | - PIPE_TEXTURE_USAGE_DISPLAY_TARGET; - tex = ms->screen->texture_create(ms->screen, &template); - pipe_texture_reference(&exa_priv->depth_stencil_tex, tex); + template.bind = PIPE_BIND_DEPTH_STENCIL | + PIPE_BIND_SHARED; + tex = ms->screen->resource_create(ms->screen, &template); + pipe_resource_reference(&exa_priv->depth_stencil_tex, tex); } break; } @@ -138,15 +154,20 @@ dri2_do_create_buffer(DrawablePtr pDraw, DRI2BufferPtr buffer, unsigned int form if (!tex) FatalError("NO TEXTURE IN DRI2\n"); - ms->api->shared_handle_from_texture(ms->api, ms->screen, tex, &stride, &handle); + memset(&whandle, 0, sizeof(whandle)); + whandle.type = DRM_API_HANDLE_TYPE_SHARED; + + ms->screen->resource_get_handle(ms->screen, tex, &whandle); - buffer->name = handle; - buffer->pitch = stride; + buffer->name = whandle.handle; + buffer->pitch = whandle.stride; buffer->cpp = 4; buffer->driverPrivate = private; buffer->flags = 0; /* not tiled */ #if DRI2INFOREC_VERSION == 2 - ((DRI2Buffer2Ptr)buffer)->format = 0; + /* ABI forwards/backwards compatibility */ + if (set_format_in_do_create_buffer) + ((DRI2Buffer2Ptr)buffer)->format = 0; #elif DRI2INFOREC_VERSION >= 3 buffer->format = 0; #endif @@ -164,9 +185,9 @@ dri2_do_destroy_buffer(DrawablePtr pDraw, DRI2BufferPtr buffer) BufferPrivatePtr private = buffer->driverPrivate; struct exa_pixmap_priv *exa_priv = exaGetPixmapDriverPrivate(private->pPixmap); - pipe_texture_reference(&private->tex, NULL); + pipe_resource_reference(&private->tex, NULL); ms->screen->fence_reference(ms->screen, &private->fence, NULL); - pipe_texture_reference(&exa_priv->depth_stencil_tex, NULL); + pipe_resource_reference(&exa_priv->depth_stencil_tex, NULL); (*pScreen->DestroyPixmap)(private->pPixmap); } @@ -210,7 +231,9 @@ dri2_destroy_buffer(DrawablePtr pDraw, DRI2Buffer2Ptr buffer) xfree(buffer); } -#else /* DRI2INFOREC_VERSION < 2 */ +#endif /* DRI2INFOREC_VERSION >= 2 */ + +#if DRI2INFOREC_VERSION <= 2 static DRI2BufferPtr dri2_create_buffers(DrawablePtr pDraw, unsigned int *attachments, int count) @@ -260,7 +283,7 @@ dri2_destroy_buffers(DrawablePtr pDraw, DRI2BufferPtr buffers, int count) } } -#endif /* DRI2INFOREC_VERSION >= 2 */ +#endif /* DRI2INFOREC_VERSION <= 2 */ static void dri2_copy_region(DrawablePtr pDraw, RegionPtr pRegion, @@ -368,12 +391,19 @@ xorg_dri2_init(ScreenPtr pScreen) ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; modesettingPtr ms = modesettingPTR(pScrn); DRI2InfoRec dri2info; - #if DRI2INFOREC_VERSION >= 2 - dri2info.version = DRI2INFOREC_VERSION; -#else - dri2info.version = 1; + int major, minor; + + if (xf86LoaderCheckSymbol("DRI2Version")) { + DRI2Version(&major, &minor); + } else { + /* Assume version 1.0 */ + major = 1; + minor = 0; + } #endif + + dri2info.version = DRI2INFOREC_VERSION; dri2info.fd = ms->fd; dri2info.driverName = pScrn->driverName; @@ -382,7 +412,22 @@ xorg_dri2_init(ScreenPtr pScreen) #if DRI2INFOREC_VERSION >= 2 dri2info.CreateBuffer = dri2_create_buffer; dri2info.DestroyBuffer = dri2_destroy_buffer; -#else +#endif + + /* For X servers in the 1.6.x series there where two DRI2 version. + * This allows us to build one binary that works on both servers. + */ +#if DRI2INFOREC_VERSION == 2 + if (minor == 0) { + set_format_in_do_create_buffer = FALSE; + dri2info.CreateBuffers = dri2_create_buffers; + dri2info.DestroyBuffers = dri2_destroy_buffers; + } else + set_format_in_do_create_buffer = FALSE; +#endif + + /* For version 1 set these unconditionaly. */ +#if DRI2INFOREC_VERSION == 1 dri2info.CreateBuffers = dri2_create_buffers; dri2info.DestroyBuffers = dri2_destroy_buffers; #endif @@ -390,13 +435,13 @@ xorg_dri2_init(ScreenPtr pScreen) dri2info.Wait = NULL; ms->d_depth_bits_last = - ms->screen->is_format_supported(ms->screen, PIPE_FORMAT_X8Z24_UNORM, + ms->screen->is_format_supported(ms->screen, PIPE_FORMAT_Z24X8_UNORM, PIPE_TEXTURE_2D, - PIPE_TEXTURE_USAGE_DEPTH_STENCIL, 0); + PIPE_BIND_DEPTH_STENCIL, 0); ms->ds_depth_bits_last = - ms->screen->is_format_supported(ms->screen, PIPE_FORMAT_S8Z24_UNORM, + ms->screen->is_format_supported(ms->screen, PIPE_FORMAT_Z24_UNORM_S8_USCALED, PIPE_TEXTURE_2D, - PIPE_TEXTURE_USAGE_DEPTH_STENCIL, 0); + PIPE_BIND_DEPTH_STENCIL, 0); return DRI2ScreenInit(pScreen, &dri2info); }