Path: blob/21.2-virgl/src/gallium/targets/libgl-xlib/xlib.c
4565 views
/**************************************************************************1*2* Copyright 2007 VMware, Inc., Bismarck, ND., USA3* All Rights Reserved.4*5* Permission is hereby granted, free of charge, to any person obtaining a6* copy of this software and associated documentation files (the7* "Software"), to deal in the Software without restriction, including8* without limitation the rights to use, copy, modify, merge, publish,9* distribute, sub license, and/or sell copies of the Software, and to10* permit persons to whom the Software is furnished to do so, subject to11* the following conditions:12*13* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR14* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,15* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL16* THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,17* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR18* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE19* USE OR OTHER DEALINGS IN THE SOFTWARE.20*21* The above copyright notice and this permission notice (including the22* next paragraph) shall be included in all copies or substantial portions23* of the Software.24*25*26**************************************************************************/2728/*29* Authors:30* Keith Whitwell31*/32#include "pipe/p_compiler.h"33#include "util/u_debug.h"34#include "sw/xlib/xlib_sw_winsys.h"35#include "xm_public.h"3637#include "state_tracker/st_gl_api.h"38#include "target-helpers/inline_sw_helper.h"39#include "target-helpers/inline_debug_helper.h"40414243/* Helper function to build a subset of a driver stack consisting of44* one of the software rasterizers (llvmpipe, softpipe) and the45* xlib winsys.46*/47static struct pipe_screen *48swrast_xlib_create_screen( Display *display )49{50struct sw_winsys *winsys;51struct pipe_screen *screen = NULL;5253/* Create the underlying winsys, which performs presents to Xlib54* drawables:55*/56winsys = xlib_create_sw_winsys( display );57if (winsys == NULL)58return NULL;5960/* Create a software rasterizer on top of that winsys:61*/62screen = sw_screen_create( winsys );63if (screen == NULL)64goto fail;6566/* Inject any wrapping layers we want to here:67*/68return debug_screen_wrap( screen );6970fail:71if (winsys)72winsys->destroy( winsys );7374return NULL;75}7677static struct xm_driver xlib_driver =78{79.create_pipe_screen = swrast_xlib_create_screen,80.create_st_api = st_gl_api_create,81};828384/* Build the rendering stack.85*/86static void _init( void ) __attribute__((constructor));87static void _init( void )88{89/* Initialize the xlib libgl code, pass in the winsys:90*/91xmesa_set_driver( &xlib_driver );92}939495/***********************************************************************96*97* Butt-ugly hack to convince the linker not to throw away public GL98* symbols (they are all referenced from getprocaddress, I guess).99*/100extern void (*linker_foo(const unsigned char *procName))();101extern void (*glXGetProcAddress(const unsigned char *procName))();102103extern void (*linker_foo(const unsigned char *procName))()104{105return glXGetProcAddress(procName);106}107108109/**110* When GLX_INDIRECT_RENDERING is defined, some symbols are missing in111* libglapi.a. We need to define them here.112*/113#ifdef GLX_INDIRECT_RENDERING114115#define GL_GLEXT_PROTOTYPES116#include "main/glheader.h"117#include "glapi/glapi.h"118#include "glapi/glapitable.h"119120#define NAME(func) gl##func121122#define DISPATCH(FUNC, ARGS, MESSAGE) \123GET_DISPATCH()->FUNC ARGS124125#define RETURN_DISPATCH(FUNC, ARGS, MESSAGE) \126return GET_DISPATCH()->FUNC ARGS127128/* skip normal ones */129#define _GLAPI_SKIP_NORMAL_ENTRY_POINTS130#include "glapitemp.h"131132#endif /* GLX_INDIRECT_RENDERING */133134135