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 this->force_direct_context = false; 38 this->allow_invalid_glx_destroy_window = false; 39 40 this->display = glx_dpy; 41 this->dpy = (glx_dpy != NULL) ? glx_dpy->dpy : NULL; 42 43 this->serverGLXexts = new char[strlen(ext) + 1]; 44 strcpy((char *) this->serverGLXexts, ext); 45 } 46 ~fake_glx_screen()47 ~fake_glx_screen() 48 { 49 delete [] this->serverGLXexts; 50 } 51 52 private: 53 static struct glx_screen_vtable vt; 54 }; 55 56 class fake_glx_screen_direct : public fake_glx_screen { 57 public: fake_glx_screen_direct(struct glx_display * glx_dpy,int num,const char * ext)58 fake_glx_screen_direct(struct glx_display *glx_dpy, int num, 59 const char *ext) 60 : fake_glx_screen(glx_dpy, num, ext) 61 { 62 this->vtable = &fake_glx_screen_direct::vt; 63 } 64 65 private: 66 static struct glx_screen_vtable vt; 67 }; 68 69 class fake_glx_context : public glx_context { 70 public: fake_glx_context(struct glx_screen * psc,struct glx_config * mode)71 fake_glx_context(struct glx_screen *psc, struct glx_config *mode) 72 { 73 contexts_allocated++; 74 75 this->vtable = &fake_glx_context::vt; 76 this->majorOpcode = 123; 77 this->psc = psc; 78 this->config = mode; 79 this->isDirect = false; 80 this->currentContextTag = -1; 81 82 this->client_state_private = (struct __GLXattributeRec *) 0xcafebabe; 83 } 84 ~fake_glx_context()85 ~fake_glx_context() 86 { 87 contexts_allocated--; 88 } 89 90 /** Number of context that are allocated (and not freed). */ 91 static int contexts_allocated; 92 93 private: 94 static const struct glx_context_vtable vt; 95 destroy(struct glx_context * gc)96 static void destroy(struct glx_context *gc) 97 { 98 delete gc; 99 } 100 }; 101 102 class fake_glx_context_direct : public fake_glx_context { 103 public: fake_glx_context_direct(struct glx_screen * psc,struct glx_config * mode)104 fake_glx_context_direct(struct glx_screen *psc, struct glx_config *mode) 105 : fake_glx_context(psc, mode) 106 { 107 this->isDirect = True; 108 } 109 create(struct glx_screen * psc,struct glx_config * mode,struct glx_context * shareList,int renderType)110 static glx_context *create(struct glx_screen *psc, struct glx_config *mode, 111 struct glx_context *shareList, int renderType) 112 { 113 (void) shareList; 114 (void) renderType; 115 116 return new fake_glx_context_direct(psc, mode); 117 } 118 create_attribs(struct glx_screen * psc,struct glx_config * mode,struct glx_context * shareList,unsigned num_attribs,const uint32_t * attribs,unsigned * error)119 static glx_context *create_attribs(struct glx_screen *psc, 120 struct glx_config *mode, 121 struct glx_context *shareList, 122 unsigned num_attribs, 123 const uint32_t *attribs, 124 unsigned *error) 125 { 126 (void) shareList; 127 (void) num_attribs; 128 (void) attribs; 129 130 *error = 0; 131 return new fake_glx_context_direct(psc, mode); 132 } 133 }; 134