1848b8605Smrg/**************************************************************************
2848b8605Smrg *
3848b8605Smrg * Copyright 2007 VMware, Inc., Bismarck, ND., USA
4848b8605Smrg * All Rights Reserved.
5848b8605Smrg *
6848b8605Smrg * Permission is hereby granted, free of charge, to any person obtaining a
7848b8605Smrg * copy of this software and associated documentation files (the
8848b8605Smrg * "Software"), to deal in the Software without restriction, including
9848b8605Smrg * without limitation the rights to use, copy, modify, merge, publish,
10848b8605Smrg * distribute, sub license, and/or sell copies of the Software, and to
11848b8605Smrg * permit persons to whom the Software is furnished to do so, subject to
12848b8605Smrg * the following conditions:
13848b8605Smrg *
14848b8605Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15848b8605Smrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16848b8605Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
17848b8605Smrg * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
18848b8605Smrg * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19848b8605Smrg * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20848b8605Smrg * USE OR OTHER DEALINGS IN THE SOFTWARE.
21848b8605Smrg *
22848b8605Smrg * The above copyright notice and this permission notice (including the
23848b8605Smrg * next paragraph) shall be included in all copies or substantial portions
24848b8605Smrg * of the Software.
25848b8605Smrg *
26848b8605Smrg *
27848b8605Smrg **************************************************************************/
28848b8605Smrg
29848b8605Smrg/*
30848b8605Smrg * Authors:
31848b8605Smrg *   Keith Whitwell
32848b8605Smrg */
33848b8605Smrg#include "pipe/p_compiler.h"
34848b8605Smrg#include "util/u_debug.h"
35848b8605Smrg#include "sw/xlib/xlib_sw_winsys.h"
36848b8605Smrg#include "xm_public.h"
37848b8605Smrg
38848b8605Smrg#include "state_tracker/st_gl_api.h"
39848b8605Smrg#include "target-helpers/inline_sw_helper.h"
40848b8605Smrg#include "target-helpers/inline_debug_helper.h"
41848b8605Smrg
42848b8605Smrg
43848b8605Smrg
44848b8605Smrg/* Helper function to build a subset of a driver stack consisting of
45848b8605Smrg * one of the software rasterizers (llvmpipe, softpipe) and the
46848b8605Smrg * xlib winsys.
47848b8605Smrg */
48848b8605Smrgstatic struct pipe_screen *
49848b8605Smrgswrast_xlib_create_screen( Display *display )
50848b8605Smrg{
51848b8605Smrg   struct sw_winsys *winsys;
52848b8605Smrg   struct pipe_screen *screen = NULL;
53848b8605Smrg
54848b8605Smrg   /* Create the underlying winsys, which performs presents to Xlib
55848b8605Smrg    * drawables:
56848b8605Smrg    */
57848b8605Smrg   winsys = xlib_create_sw_winsys( display );
58848b8605Smrg   if (winsys == NULL)
59848b8605Smrg      return NULL;
60848b8605Smrg
61848b8605Smrg   /* Create a software rasterizer on top of that winsys:
62848b8605Smrg    */
63848b8605Smrg   screen = sw_screen_create( winsys );
64848b8605Smrg   if (screen == NULL)
65848b8605Smrg      goto fail;
66848b8605Smrg
67848b8605Smrg   /* Inject any wrapping layers we want to here:
68848b8605Smrg    */
69848b8605Smrg   return debug_screen_wrap( screen );
70848b8605Smrg
71848b8605Smrgfail:
72848b8605Smrg   if (winsys)
73848b8605Smrg      winsys->destroy( winsys );
74848b8605Smrg
75848b8605Smrg   return NULL;
76848b8605Smrg}
77848b8605Smrg
78848b8605Smrgstatic struct xm_driver xlib_driver =
79848b8605Smrg{
80848b8605Smrg   .create_pipe_screen = swrast_xlib_create_screen,
81848b8605Smrg   .create_st_api = st_gl_api_create,
82848b8605Smrg};
83848b8605Smrg
84848b8605Smrg
85848b8605Smrg/* Build the rendering stack.
86848b8605Smrg */
87848b8605Smrgstatic void _init( void ) __attribute__((constructor));
88848b8605Smrgstatic void _init( void )
89848b8605Smrg{
90848b8605Smrg   /* Initialize the xlib libgl code, pass in the winsys:
91848b8605Smrg    */
92848b8605Smrg   xmesa_set_driver( &xlib_driver );
93848b8605Smrg}
94848b8605Smrg
95848b8605Smrg
96848b8605Smrg/***********************************************************************
97848b8605Smrg *
98848b8605Smrg * Butt-ugly hack to convince the linker not to throw away public GL
99848b8605Smrg * symbols (they are all referenced from getprocaddress, I guess).
100848b8605Smrg */
101848b8605Smrgextern void (*linker_foo(const unsigned char *procName))();
102848b8605Smrgextern void (*glXGetProcAddress(const unsigned char *procName))();
103848b8605Smrg
104848b8605Smrgextern void (*linker_foo(const unsigned char *procName))()
105848b8605Smrg{
106848b8605Smrg   return glXGetProcAddress(procName);
107848b8605Smrg}
108848b8605Smrg
109848b8605Smrg
110848b8605Smrg/**
111848b8605Smrg * When GLX_INDIRECT_RENDERING is defined, some symbols are missing in
112848b8605Smrg * libglapi.a.  We need to define them here.
113848b8605Smrg */
114848b8605Smrg#ifdef GLX_INDIRECT_RENDERING
115848b8605Smrg
116848b8605Smrg#define GL_GLEXT_PROTOTYPES
117848b8605Smrg#include "main/glheader.h"
118848b8605Smrg#include "glapi/glapi.h"
119848b8605Smrg#include "glapi/glapitable.h"
120848b8605Smrg
121848b8605Smrg#if defined(USE_MGL_NAMESPACE)
122848b8605Smrg#define NAME(func)  mgl##func
123848b8605Smrg#else
124848b8605Smrg#define NAME(func)  gl##func
125848b8605Smrg#endif
126848b8605Smrg
127848b8605Smrg#define DISPATCH(FUNC, ARGS, MESSAGE)		\
128848b8605Smrg   GET_DISPATCH()->FUNC ARGS
129848b8605Smrg
130848b8605Smrg#define RETURN_DISPATCH(FUNC, ARGS, MESSAGE) 	\
131848b8605Smrg   return GET_DISPATCH()->FUNC ARGS
132848b8605Smrg
133848b8605Smrg/* skip normal ones */
134848b8605Smrg#define _GLAPI_SKIP_NORMAL_ENTRY_POINTS
135848b8605Smrg#include "glapi/glapitemp.h"
136848b8605Smrg
137848b8605Smrg#endif /* GLX_INDIRECT_RENDERING */
138