135c4bbdfSmrg/* 235c4bbdfSmrg * Copyright © 2013 Keith Packard 335c4bbdfSmrg * 435c4bbdfSmrg * Permission to use, copy, modify, distribute, and sell this software and its 535c4bbdfSmrg * documentation for any purpose is hereby granted without fee, provided that 635c4bbdfSmrg * the above copyright notice appear in all copies and that both that copyright 735c4bbdfSmrg * notice and this permission notice appear in supporting documentation, and 835c4bbdfSmrg * that the name of the copyright holders not be used in advertising or 935c4bbdfSmrg * publicity pertaining to distribution of the software without specific, 1035c4bbdfSmrg * written prior permission. The copyright holders make no representations 1135c4bbdfSmrg * about the suitability of this software for any purpose. It is provided "as 1235c4bbdfSmrg * is" without express or implied warranty. 1335c4bbdfSmrg * 1435c4bbdfSmrg * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, 1535c4bbdfSmrg * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO 1635c4bbdfSmrg * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR 1735c4bbdfSmrg * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, 1835c4bbdfSmrg * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER 1935c4bbdfSmrg * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE 2035c4bbdfSmrg * OF THIS SOFTWARE. 2135c4bbdfSmrg */ 2235c4bbdfSmrg 2335c4bbdfSmrg#include "dri3_priv.h" 2435c4bbdfSmrg 251b5d61b8Smrg#include <drm_fourcc.h> 261b5d61b8Smrg 2735c4bbdfSmrgstatic int dri3_request; 2835c4bbdfSmrgDevPrivateKeyRec dri3_screen_private_key; 2935c4bbdfSmrg 3035c4bbdfSmrgstatic int dri3_screen_generation; 3135c4bbdfSmrg 3235c4bbdfSmrgstatic Bool 3335c4bbdfSmrgdri3_close_screen(ScreenPtr screen) 3435c4bbdfSmrg{ 3535c4bbdfSmrg dri3_screen_priv_ptr screen_priv = dri3_screen_priv(screen); 3635c4bbdfSmrg 3735c4bbdfSmrg unwrap(screen_priv, screen, CloseScreen); 3835c4bbdfSmrg 3935c4bbdfSmrg free(screen_priv); 4035c4bbdfSmrg return (*screen->CloseScreen) (screen); 4135c4bbdfSmrg} 4235c4bbdfSmrg 4335c4bbdfSmrgBool 441b5d61b8Smrgdri3_screen_init(ScreenPtr screen, const dri3_screen_info_rec *info) 4535c4bbdfSmrg{ 4635c4bbdfSmrg dri3_screen_generation = serverGeneration; 4735c4bbdfSmrg 4835c4bbdfSmrg if (!dixRegisterPrivateKey(&dri3_screen_private_key, PRIVATE_SCREEN, 0)) 4935c4bbdfSmrg return FALSE; 5035c4bbdfSmrg 5135c4bbdfSmrg if (!dri3_screen_priv(screen)) { 5235c4bbdfSmrg dri3_screen_priv_ptr screen_priv = calloc(1, sizeof (dri3_screen_priv_rec)); 5335c4bbdfSmrg if (!screen_priv) 5435c4bbdfSmrg return FALSE; 5535c4bbdfSmrg 5635c4bbdfSmrg wrap(screen_priv, screen, CloseScreen, dri3_close_screen); 5735c4bbdfSmrg 5835c4bbdfSmrg screen_priv->info = info; 5935c4bbdfSmrg 6035c4bbdfSmrg dixSetPrivate(&screen->devPrivates, &dri3_screen_private_key, screen_priv); 6135c4bbdfSmrg } 6235c4bbdfSmrg 6335c4bbdfSmrg return TRUE; 6435c4bbdfSmrg} 6535c4bbdfSmrg 6635c4bbdfSmrgvoid 6735c4bbdfSmrgdri3_extension_init(void) 6835c4bbdfSmrg{ 6935c4bbdfSmrg ExtensionEntry *extension; 7035c4bbdfSmrg int i; 7135c4bbdfSmrg 7235c4bbdfSmrg /* If no screens support DRI3, there's no point offering the 7335c4bbdfSmrg * extension at all 7435c4bbdfSmrg */ 7535c4bbdfSmrg if (dri3_screen_generation != serverGeneration) 7635c4bbdfSmrg return; 7735c4bbdfSmrg 7835c4bbdfSmrg#ifdef PANORAMIX 7935c4bbdfSmrg if (!noPanoramiXExtension) 8035c4bbdfSmrg return; 8135c4bbdfSmrg#endif 8235c4bbdfSmrg 8335c4bbdfSmrg extension = AddExtension(DRI3_NAME, DRI3NumberEvents, DRI3NumberErrors, 8435c4bbdfSmrg proc_dri3_dispatch, sproc_dri3_dispatch, 8535c4bbdfSmrg NULL, StandardMinorOpcode); 8635c4bbdfSmrg if (!extension) 8735c4bbdfSmrg goto bail; 8835c4bbdfSmrg 8935c4bbdfSmrg dri3_request = extension->base; 9035c4bbdfSmrg 9135c4bbdfSmrg for (i = 0; i < screenInfo.numScreens; i++) { 9235c4bbdfSmrg if (!dri3_screen_init(screenInfo.screens[i], NULL)) 9335c4bbdfSmrg goto bail; 9435c4bbdfSmrg } 9535c4bbdfSmrg return; 9635c4bbdfSmrg 9735c4bbdfSmrgbail: 9835c4bbdfSmrg FatalError("Cannot initialize DRI3 extension"); 9935c4bbdfSmrg} 1001b5d61b8Smrg 1011b5d61b8Smrguint32_t 1021b5d61b8Smrgdrm_format_for_depth(uint32_t depth, uint32_t bpp) 1031b5d61b8Smrg{ 1041b5d61b8Smrg switch (bpp) { 1051b5d61b8Smrg case 16: 1061b5d61b8Smrg return DRM_FORMAT_RGB565; 1071b5d61b8Smrg case 24: 1081b5d61b8Smrg return DRM_FORMAT_XRGB8888; 1091b5d61b8Smrg case 30: 1101b5d61b8Smrg return DRM_FORMAT_XRGB2101010; 1111b5d61b8Smrg case 32: 1121b5d61b8Smrg return DRM_FORMAT_ARGB8888; 1131b5d61b8Smrg default: 1141b5d61b8Smrg return 0; 1151b5d61b8Smrg } 1161b5d61b8Smrg} 117