1848b8605Smrg/*
2848b8605Smrg * Copyright © 2011 Intel Corporation
3848b8605Smrg *
4848b8605Smrg * Permission is hereby granted, free of charge, to any person obtaining a
5848b8605Smrg * copy of this software and associated documentation files (the "Software"),
6848b8605Smrg * to deal in the Software without restriction, including without limitation
7848b8605Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8848b8605Smrg * and/or sell copies of the Software, and to permit persons to whom the
9848b8605Smrg * Software is furnished to do so, subject to the following conditions:
10848b8605Smrg *
11848b8605Smrg * The above copyright notice and this permission notice (including the next
12848b8605Smrg * paragraph) shall be included in all copies or substantial portions of the
13848b8605Smrg * Software.
14848b8605Smrg *
15848b8605Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16848b8605Smrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17848b8605Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18848b8605Smrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19848b8605Smrg * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20848b8605Smrg * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21848b8605Smrg * DEALINGS IN THE SOFTWARE.
22848b8605Smrg */
23848b8605Smrg#include "fake_glx_screen.h"
24848b8605Smrg
25848b8605Smrgstruct glx_screen_vtable fake_glx_screen::vt = {
26848b8605Smrg   indirect_create_context,
27848b8605Smrg   indirect_create_context_attribs,
28848b8605Smrg   NULL,
29848b8605Smrg   NULL,
30848b8605Smrg};
31848b8605Smrg
32848b8605Smrgstruct glx_screen_vtable fake_glx_screen_direct::vt = {
33848b8605Smrg   fake_glx_context_direct::create,
34848b8605Smrg   fake_glx_context_direct::create_attribs,
35848b8605Smrg   NULL,
36848b8605Smrg   NULL,
37848b8605Smrg};
38848b8605Smrg
39848b8605Smrgconst struct glx_context_vtable fake_glx_context::vt = {
40848b8605Smrg   fake_glx_context::destroy,
41848b8605Smrg   NULL,
42848b8605Smrg   NULL,
43848b8605Smrg   NULL,
44848b8605Smrg   NULL,
45848b8605Smrg   NULL,
46848b8605Smrg   NULL,
47848b8605Smrg   NULL,
48848b8605Smrg   NULL,
49848b8605Smrg};
50848b8605Smrg
51848b8605Smrgint fake_glx_context::contexts_allocated = 0;
52848b8605Smrg
53848b8605Smrgextern "C" struct glx_context *
54848b8605Smrgindirect_create_context(struct glx_screen *psc, struct glx_config *mode,
55848b8605Smrg			struct glx_context *shareList, int renderType)
56848b8605Smrg{
57848b8605Smrg   (void) shareList;
58848b8605Smrg   (void) renderType;
59848b8605Smrg
60848b8605Smrg   return new fake_glx_context(psc, mode);
61848b8605Smrg}
62848b8605Smrg
63848b8605Smrgextern "C" struct glx_context *
64848b8605Smrgindirect_create_context_attribs(struct glx_screen *base,
65848b8605Smrg				struct glx_config *config_base,
66848b8605Smrg				struct glx_context *shareList,
67848b8605Smrg				unsigned num_attribs,
68848b8605Smrg				const uint32_t *attribs,
69848b8605Smrg				unsigned *error)
70848b8605Smrg{
71848b8605Smrg   (void) num_attribs;
72848b8605Smrg   (void) attribs;
73848b8605Smrg   (void) error;
74848b8605Smrg
75848b8605Smrg   return indirect_create_context(base, config_base, shareList, 0);
76848b8605Smrg}
77848b8605Smrg
78b8e80941Smrg#ifdef GLX_USE_APPLEGL
79b8e80941Smrg#warning Indirect GLX tests are not built
80b8e80941Smrgextern "C" struct glx_context *
81b8e80941Smrgapplegl_create_context(struct glx_screen *base,
82b8e80941Smrg		       struct glx_config *config_base,
83b8e80941Smrg		       struct glx_context *shareList,
84b8e80941Smrg		       int renderType)
85b8e80941Smrg{
86b8e80941Smrg   return indirect_create_context(base, config_base, shareList, renderType);
87b8e80941Smrg}
88b8e80941Smrg#endif
89b8e80941Smrg
90b8e80941Smrg/* This is necessary so that we don't have to link with glxcurrent.c
91b8e80941Smrg * which would require us to link with X libraries and what not.
92b8e80941Smrg */
93b8e80941SmrgGLubyte dummyBuffer[__GLX_BUFFER_LIMIT_SIZE];
94b8e80941Smrgstruct glx_context_vtable dummyVtable;
95b8e80941Smrgstruct glx_context dummyContext = {
96b8e80941Smrg   &dummyBuffer[0],
97b8e80941Smrg   &dummyBuffer[0],
98b8e80941Smrg   &dummyBuffer[0],
99b8e80941Smrg   &dummyBuffer[__GLX_BUFFER_LIMIT_SIZE],
100b8e80941Smrg   sizeof(dummyBuffer),
101b8e80941Smrg   &dummyVtable
102b8e80941Smrg};
103b8e80941Smrg__thread void *__glX_tls_Context = &dummyContext;
104848b8605Smrg
105b8e80941Smrg#if !defined(GLX_USE_TLS)
106848b8605Smrgextern "C" struct glx_context *
107848b8605Smrg__glXGetCurrentContext()
108848b8605Smrg{
109848b8605Smrg return (struct glx_context *) __glX_tls_Context;
110848b8605Smrg}
111848b8605Smrg#endif
112