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