13464ebd5Sriastradh/************************************************************************** 23464ebd5Sriastradh * 3af69d88dSmrg * Copyright 2007 VMware, Inc., Bismarck, ND., USA 43464ebd5Sriastradh * All Rights Reserved. 53464ebd5Sriastradh * 63464ebd5Sriastradh * Permission is hereby granted, free of charge, to any person obtaining a 73464ebd5Sriastradh * copy of this software and associated documentation files (the 83464ebd5Sriastradh * "Software"), to deal in the Software without restriction, including 93464ebd5Sriastradh * without limitation the rights to use, copy, modify, merge, publish, 103464ebd5Sriastradh * distribute, sub license, and/or sell copies of the Software, and to 113464ebd5Sriastradh * permit persons to whom the Software is furnished to do so, subject to 123464ebd5Sriastradh * the following conditions: 133464ebd5Sriastradh * 143464ebd5Sriastradh * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 153464ebd5Sriastradh * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 163464ebd5Sriastradh * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL 173464ebd5Sriastradh * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, 183464ebd5Sriastradh * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 193464ebd5Sriastradh * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 203464ebd5Sriastradh * USE OR OTHER DEALINGS IN THE SOFTWARE. 213464ebd5Sriastradh * 223464ebd5Sriastradh * The above copyright notice and this permission notice (including the 233464ebd5Sriastradh * next paragraph) shall be included in all copies or substantial portions 243464ebd5Sriastradh * of the Software. 253464ebd5Sriastradh * 263464ebd5Sriastradh * 273464ebd5Sriastradh **************************************************************************/ 283464ebd5Sriastradh 293464ebd5Sriastradh/* 303464ebd5Sriastradh * Authors: 313464ebd5Sriastradh * Keith Whitwell 323464ebd5Sriastradh */ 333464ebd5Sriastradh#include "pipe/p_compiler.h" 343464ebd5Sriastradh#include "util/u_debug.h" 35af69d88dSmrg#include "sw/xlib/xlib_sw_winsys.h" 363464ebd5Sriastradh#include "xm_public.h" 373464ebd5Sriastradh 383464ebd5Sriastradh#include "state_tracker/st_gl_api.h" 393464ebd5Sriastradh#include "target-helpers/inline_sw_helper.h" 403464ebd5Sriastradh#include "target-helpers/inline_debug_helper.h" 413464ebd5Sriastradh 423464ebd5Sriastradh 433464ebd5Sriastradh 443464ebd5Sriastradh/* Helper function to build a subset of a driver stack consisting of 45af69d88dSmrg * one of the software rasterizers (llvmpipe, softpipe) and the 463464ebd5Sriastradh * xlib winsys. 473464ebd5Sriastradh */ 483464ebd5Sriastradhstatic struct pipe_screen * 493464ebd5Sriastradhswrast_xlib_create_screen( Display *display ) 503464ebd5Sriastradh{ 513464ebd5Sriastradh struct sw_winsys *winsys; 523464ebd5Sriastradh struct pipe_screen *screen = NULL; 533464ebd5Sriastradh 543464ebd5Sriastradh /* Create the underlying winsys, which performs presents to Xlib 553464ebd5Sriastradh * drawables: 563464ebd5Sriastradh */ 573464ebd5Sriastradh winsys = xlib_create_sw_winsys( display ); 583464ebd5Sriastradh if (winsys == NULL) 593464ebd5Sriastradh return NULL; 603464ebd5Sriastradh 613464ebd5Sriastradh /* Create a software rasterizer on top of that winsys: 623464ebd5Sriastradh */ 633464ebd5Sriastradh screen = sw_screen_create( winsys ); 643464ebd5Sriastradh if (screen == NULL) 653464ebd5Sriastradh goto fail; 663464ebd5Sriastradh 673464ebd5Sriastradh /* Inject any wrapping layers we want to here: 683464ebd5Sriastradh */ 693464ebd5Sriastradh return debug_screen_wrap( screen ); 703464ebd5Sriastradh 713464ebd5Sriastradhfail: 723464ebd5Sriastradh if (winsys) 733464ebd5Sriastradh winsys->destroy( winsys ); 743464ebd5Sriastradh 753464ebd5Sriastradh return NULL; 763464ebd5Sriastradh} 773464ebd5Sriastradh 783464ebd5Sriastradhstatic struct xm_driver xlib_driver = 793464ebd5Sriastradh{ 803464ebd5Sriastradh .create_pipe_screen = swrast_xlib_create_screen, 813464ebd5Sriastradh .create_st_api = st_gl_api_create, 823464ebd5Sriastradh}; 833464ebd5Sriastradh 843464ebd5Sriastradh 853464ebd5Sriastradh/* Build the rendering stack. 863464ebd5Sriastradh */ 873464ebd5Sriastradhstatic void _init( void ) __attribute__((constructor)); 883464ebd5Sriastradhstatic void _init( void ) 893464ebd5Sriastradh{ 903464ebd5Sriastradh /* Initialize the xlib libgl code, pass in the winsys: 913464ebd5Sriastradh */ 923464ebd5Sriastradh xmesa_set_driver( &xlib_driver ); 933464ebd5Sriastradh} 943464ebd5Sriastradh 953464ebd5Sriastradh 963464ebd5Sriastradh/*********************************************************************** 973464ebd5Sriastradh * 983464ebd5Sriastradh * Butt-ugly hack to convince the linker not to throw away public GL 993464ebd5Sriastradh * symbols (they are all referenced from getprocaddress, I guess). 1003464ebd5Sriastradh */ 1013464ebd5Sriastradhextern void (*linker_foo(const unsigned char *procName))(); 1023464ebd5Sriastradhextern void (*glXGetProcAddress(const unsigned char *procName))(); 1033464ebd5Sriastradh 1043464ebd5Sriastradhextern void (*linker_foo(const unsigned char *procName))() 1053464ebd5Sriastradh{ 1063464ebd5Sriastradh return glXGetProcAddress(procName); 1073464ebd5Sriastradh} 1083464ebd5Sriastradh 1093464ebd5Sriastradh 1103464ebd5Sriastradh/** 1113464ebd5Sriastradh * When GLX_INDIRECT_RENDERING is defined, some symbols are missing in 1123464ebd5Sriastradh * libglapi.a. We need to define them here. 1133464ebd5Sriastradh */ 1143464ebd5Sriastradh#ifdef GLX_INDIRECT_RENDERING 1153464ebd5Sriastradh 1163464ebd5Sriastradh#define GL_GLEXT_PROTOTYPES 117af69d88dSmrg#include "main/glheader.h" 1183464ebd5Sriastradh#include "glapi/glapi.h" 1193464ebd5Sriastradh#include "glapi/glapitable.h" 1203464ebd5Sriastradh 1213464ebd5Sriastradh#define NAME(func) gl##func 1223464ebd5Sriastradh 1233464ebd5Sriastradh#define DISPATCH(FUNC, ARGS, MESSAGE) \ 1243464ebd5Sriastradh GET_DISPATCH()->FUNC ARGS 1253464ebd5Sriastradh 1263464ebd5Sriastradh#define RETURN_DISPATCH(FUNC, ARGS, MESSAGE) \ 1273464ebd5Sriastradh return GET_DISPATCH()->FUNC ARGS 1283464ebd5Sriastradh 1293464ebd5Sriastradh/* skip normal ones */ 1303464ebd5Sriastradh#define _GLAPI_SKIP_NORMAL_ENTRY_POINTS 1317ec681f3Smrg#include "glapitemp.h" 1323464ebd5Sriastradh 1333464ebd5Sriastradh#endif /* GLX_INDIRECT_RENDERING */ 134