1bf215546Sopenharmony_ci/************************************************************************** 2bf215546Sopenharmony_ci * 3bf215546Sopenharmony_ci * Copyright 2007 VMware, Inc., Bismarck, ND., USA 4bf215546Sopenharmony_ci * All Rights Reserved. 5bf215546Sopenharmony_ci * 6bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a 7bf215546Sopenharmony_ci * copy of this software and associated documentation files (the 8bf215546Sopenharmony_ci * "Software"), to deal in the Software without restriction, including 9bf215546Sopenharmony_ci * without limitation the rights to use, copy, modify, merge, publish, 10bf215546Sopenharmony_ci * distribute, sub license, and/or sell copies of the Software, and to 11bf215546Sopenharmony_ci * permit persons to whom the Software is furnished to do so, subject to 12bf215546Sopenharmony_ci * the following conditions: 13bf215546Sopenharmony_ci * 14bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15bf215546Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL 17bf215546Sopenharmony_ci * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, 18bf215546Sopenharmony_ci * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 19bf215546Sopenharmony_ci * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 20bf215546Sopenharmony_ci * USE OR OTHER DEALINGS IN THE SOFTWARE. 21bf215546Sopenharmony_ci * 22bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the 23bf215546Sopenharmony_ci * next paragraph) shall be included in all copies or substantial portions 24bf215546Sopenharmony_ci * of the Software. 25bf215546Sopenharmony_ci * 26bf215546Sopenharmony_ci * 27bf215546Sopenharmony_ci **************************************************************************/ 28bf215546Sopenharmony_ci 29bf215546Sopenharmony_ci/* 30bf215546Sopenharmony_ci * Authors: 31bf215546Sopenharmony_ci * Keith Whitwell 32bf215546Sopenharmony_ci */ 33bf215546Sopenharmony_ci#include "pipe/p_compiler.h" 34bf215546Sopenharmony_ci#include "util/u_debug.h" 35bf215546Sopenharmony_ci#include "sw/xlib/xlib_sw_winsys.h" 36bf215546Sopenharmony_ci#include "xm_public.h" 37bf215546Sopenharmony_ci 38bf215546Sopenharmony_ci#include "state_tracker/st_gl_api.h" 39bf215546Sopenharmony_ci#include "target-helpers/inline_sw_helper.h" 40bf215546Sopenharmony_ci#include "target-helpers/inline_debug_helper.h" 41bf215546Sopenharmony_ci 42bf215546Sopenharmony_ci 43bf215546Sopenharmony_ci 44bf215546Sopenharmony_ci/* Helper function to build a subset of a driver stack consisting of 45bf215546Sopenharmony_ci * one of the software rasterizers (llvmpipe, softpipe) and the 46bf215546Sopenharmony_ci * xlib winsys. 47bf215546Sopenharmony_ci */ 48bf215546Sopenharmony_cistatic struct pipe_screen * 49bf215546Sopenharmony_ciswrast_xlib_create_screen( Display *display ) 50bf215546Sopenharmony_ci{ 51bf215546Sopenharmony_ci struct sw_winsys *winsys; 52bf215546Sopenharmony_ci struct pipe_screen *screen = NULL; 53bf215546Sopenharmony_ci 54bf215546Sopenharmony_ci /* Create the underlying winsys, which performs presents to Xlib 55bf215546Sopenharmony_ci * drawables: 56bf215546Sopenharmony_ci */ 57bf215546Sopenharmony_ci winsys = xlib_create_sw_winsys( display ); 58bf215546Sopenharmony_ci if (winsys == NULL) 59bf215546Sopenharmony_ci return NULL; 60bf215546Sopenharmony_ci 61bf215546Sopenharmony_ci /* Create a software rasterizer on top of that winsys: 62bf215546Sopenharmony_ci */ 63bf215546Sopenharmony_ci screen = sw_screen_create( winsys ); 64bf215546Sopenharmony_ci if (screen == NULL) 65bf215546Sopenharmony_ci goto fail; 66bf215546Sopenharmony_ci 67bf215546Sopenharmony_ci /* Inject any wrapping layers we want to here: 68bf215546Sopenharmony_ci */ 69bf215546Sopenharmony_ci return debug_screen_wrap( screen ); 70bf215546Sopenharmony_ci 71bf215546Sopenharmony_cifail: 72bf215546Sopenharmony_ci if (winsys) 73bf215546Sopenharmony_ci winsys->destroy( winsys ); 74bf215546Sopenharmony_ci 75bf215546Sopenharmony_ci return NULL; 76bf215546Sopenharmony_ci} 77bf215546Sopenharmony_ci 78bf215546Sopenharmony_cistatic struct xm_driver xlib_driver = 79bf215546Sopenharmony_ci{ 80bf215546Sopenharmony_ci .create_pipe_screen = swrast_xlib_create_screen, 81bf215546Sopenharmony_ci .create_st_api = st_gl_api_create, 82bf215546Sopenharmony_ci}; 83bf215546Sopenharmony_ci 84bf215546Sopenharmony_ci 85bf215546Sopenharmony_ci/* Build the rendering stack. 86bf215546Sopenharmony_ci */ 87bf215546Sopenharmony_cistatic void _init( void ) __attribute__((constructor)); 88bf215546Sopenharmony_cistatic void _init( void ) 89bf215546Sopenharmony_ci{ 90bf215546Sopenharmony_ci /* Initialize the xlib libgl code, pass in the winsys: 91bf215546Sopenharmony_ci */ 92bf215546Sopenharmony_ci xmesa_set_driver( &xlib_driver ); 93bf215546Sopenharmony_ci} 94bf215546Sopenharmony_ci 95bf215546Sopenharmony_ci 96bf215546Sopenharmony_ci/*********************************************************************** 97bf215546Sopenharmony_ci * 98bf215546Sopenharmony_ci * Butt-ugly hack to convince the linker not to throw away public GL 99bf215546Sopenharmony_ci * symbols (they are all referenced from getprocaddress, I guess). 100bf215546Sopenharmony_ci */ 101bf215546Sopenharmony_ciextern void (*linker_foo(const unsigned char *procName))(); 102bf215546Sopenharmony_ciextern void (*glXGetProcAddress(const unsigned char *procName))(); 103bf215546Sopenharmony_ci 104bf215546Sopenharmony_ciextern void (*linker_foo(const unsigned char *procName))() 105bf215546Sopenharmony_ci{ 106bf215546Sopenharmony_ci return glXGetProcAddress(procName); 107bf215546Sopenharmony_ci} 108bf215546Sopenharmony_ci 109bf215546Sopenharmony_ci 110bf215546Sopenharmony_ci/** 111bf215546Sopenharmony_ci * When GLX_INDIRECT_RENDERING is defined, some symbols are missing in 112bf215546Sopenharmony_ci * libglapi.a. We need to define them here. 113bf215546Sopenharmony_ci */ 114bf215546Sopenharmony_ci#ifdef GLX_INDIRECT_RENDERING 115bf215546Sopenharmony_ci 116bf215546Sopenharmony_ci#define GL_GLEXT_PROTOTYPES 117bf215546Sopenharmony_ci#include "main/glheader.h" 118bf215546Sopenharmony_ci#include "glapi/glapi.h" 119bf215546Sopenharmony_ci#include "glapi/glapitable.h" 120bf215546Sopenharmony_ci 121bf215546Sopenharmony_ci#define NAME(func) gl##func 122bf215546Sopenharmony_ci 123bf215546Sopenharmony_ci#define DISPATCH(FUNC, ARGS, MESSAGE) \ 124bf215546Sopenharmony_ci GET_DISPATCH()->FUNC ARGS 125bf215546Sopenharmony_ci 126bf215546Sopenharmony_ci#define RETURN_DISPATCH(FUNC, ARGS, MESSAGE) \ 127bf215546Sopenharmony_ci return GET_DISPATCH()->FUNC ARGS 128bf215546Sopenharmony_ci 129bf215546Sopenharmony_ci/* skip normal ones */ 130bf215546Sopenharmony_ci#define _GLAPI_SKIP_NORMAL_ENTRY_POINTS 131bf215546Sopenharmony_ci#include "glapitemp.h" 132bf215546Sopenharmony_ci 133bf215546Sopenharmony_ci#endif /* GLX_INDIRECT_RENDERING */ 134