• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright © 2011 Intel Corporation
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice (including the next
12  * paragraph) shall be included in all copies or substantial portions of the
13  * Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21  * DEALINGS IN THE SOFTWARE.
22  */
23 #include "glxclient.h"
24 
25 class fake_glx_screen : public glx_screen {
26 public:
fake_glx_screen(struct glx_display * glx_dpy,int num,const char * ext)27    fake_glx_screen(struct glx_display *glx_dpy, int num, const char *ext)
28    {
29       this->vtable = &fake_glx_screen::vt;
30       this->serverGLXexts = 0;
31       this->effectiveGLXexts = 0;
32       this->display = 0;
33       this->dpy = 0;
34       this->scr = num;
35       this->visuals = 0;
36       this->configs = 0;
37 
38       this->display = glx_dpy;
39       this->dpy = (glx_dpy != NULL) ? glx_dpy->dpy : NULL;
40 
41       this->serverGLXexts = new char[strlen(ext) + 1];
42       strcpy((char *) this->serverGLXexts, ext);
43    }
44 
~fake_glx_screen()45    ~fake_glx_screen()
46    {
47       delete [] this->serverGLXexts;
48    }
49 
50 private:
51    static struct glx_screen_vtable vt;
52 };
53 
54 class fake_glx_screen_direct : public fake_glx_screen {
55 public:
fake_glx_screen_direct(struct glx_display * glx_dpy,int num,const char * ext)56    fake_glx_screen_direct(struct glx_display *glx_dpy, int num,
57 			  const char *ext)
58       : fake_glx_screen(glx_dpy, num, ext)
59    {
60       this->vtable = &fake_glx_screen_direct::vt;
61    }
62 
63 private:
64    static struct glx_screen_vtable vt;
65 };
66 
67 class fake_glx_context : public glx_context {
68 public:
fake_glx_context(struct glx_screen * psc,struct glx_config * mode)69    fake_glx_context(struct glx_screen *psc, struct glx_config *mode)
70    {
71       contexts_allocated++;
72 
73       this->vtable = &fake_glx_context::vt;
74       this->majorOpcode = 123;
75       this->screen = psc->scr;
76       this->psc = psc;
77       this->config = mode;
78       this->isDirect = false;
79       this->currentContextTag = -1;
80 
81       this->client_state_private = (struct __GLXattributeRec *) 0xcafebabe;
82    }
83 
~fake_glx_context()84    ~fake_glx_context()
85    {
86       contexts_allocated--;
87    }
88 
89    /** Number of context that are allocated (and not freed). */
90    static int contexts_allocated;
91 
92 private:
93    static const struct glx_context_vtable vt;
94 
destroy(struct glx_context * gc)95    static void destroy(struct glx_context *gc)
96    {
97       delete gc;
98    }
99 };
100 
101 class fake_glx_context_direct : public fake_glx_context {
102 public:
fake_glx_context_direct(struct glx_screen * psc,struct glx_config * mode)103    fake_glx_context_direct(struct glx_screen *psc, struct glx_config *mode)
104       : fake_glx_context(psc, mode)
105    {
106       this->isDirect = True;
107    }
108 
create(struct glx_screen * psc,struct glx_config * mode,struct glx_context * shareList,int renderType)109    static glx_context *create(struct glx_screen *psc, struct glx_config *mode,
110 			      struct glx_context *shareList, int renderType)
111    {
112       (void) shareList;
113       (void) renderType;
114 
115       return new fake_glx_context_direct(psc, mode);
116    }
117 
create_attribs(struct glx_screen * psc,struct glx_config * mode,struct glx_context * shareList,unsigned num_attribs,const uint32_t * attribs,unsigned * error)118    static glx_context *create_attribs(struct glx_screen *psc,
119 				      struct glx_config *mode,
120 				      struct glx_context *shareList,
121 				      unsigned num_attribs,
122 				      const uint32_t *attribs,
123 				      unsigned *error)
124    {
125       (void) shareList;
126       (void) num_attribs;
127       (void) attribs;
128 
129       *error = 0;
130       return new fake_glx_context_direct(psc, mode);
131    }
132 };
133