1 // Copyright (C)2004 Landmark Graphics Corporation 2 // Copyright (C)2005, 2006 Sun Microsystems, Inc. 3 // Copyright (C)2011-2012, 2014-2015, 2019-2020 D. R. Commander 4 // 5 // This library is free software and may be redistributed and/or modified under 6 // the terms of the wxWindows Library License, Version 3.1 or (at your option) 7 // any later version. The full license is in the LICENSE.txt file included 8 // with this distribution. 9 // 10 // This library is distributed in the hope that it will be useful, 11 // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 // wxWindows Library License for more details. 14 15 #ifndef __CONTEXTHASH_H__ 16 #define __CONTEXTHASH_H__ 17 18 #include "glxvisual.h" 19 #include "Hash.h" 20 21 22 typedef struct 23 { 24 VGLFBConfig config; 25 Bool direct; 26 } ContextAttribs; 27 28 29 #define HASH Hash<GLXContext, void *, ContextAttribs *> 30 31 // This maps a GLXContext to a VGLFBConfig 32 33 namespace vglfaker 34 { 35 class ContextHash : public HASH 36 { 37 public: 38 getInstance(void)39 static ContextHash *getInstance(void) 40 { 41 if(instance == NULL) 42 { 43 vglutil::CriticalSection::SafeLock l(instanceMutex); 44 if(instance == NULL) instance = new ContextHash; 45 } 46 return instance; 47 } 48 isAlloc(void)49 static bool isAlloc(void) { return instance != NULL; } 50 add(GLXContext ctx,VGLFBConfig config,Bool direct)51 void add(GLXContext ctx, VGLFBConfig config, Bool direct) 52 { 53 if(!ctx || !config) THROW("Invalid argument"); 54 ContextAttribs *attribs = NULL; 55 attribs = new ContextAttribs; 56 attribs->config = config; 57 attribs->direct = direct; 58 HASH::add(ctx, NULL, attribs); 59 } 60 findConfig(GLXContext ctx)61 VGLFBConfig findConfig(GLXContext ctx) 62 { 63 if(!ctx) THROW("Invalid argument"); 64 ContextAttribs *attribs = HASH::find(ctx, NULL); 65 if(attribs) return attribs->config; 66 return 0; 67 } 68 isDirect(GLXContext ctx)69 Bool isDirect(GLXContext ctx) 70 { 71 if(ctx) 72 { 73 ContextAttribs *attribs = HASH::find(ctx, NULL); 74 if(attribs) return attribs->direct; 75 } 76 return -1; 77 } 78 remove(GLXContext ctx)79 void remove(GLXContext ctx) 80 { 81 if(ctx) HASH::remove(ctx, NULL); 82 } 83 84 private: 85 ~ContextHash(void)86 ~ContextHash(void) 87 { 88 HASH::kill(); 89 } 90 detach(HashEntry * entry)91 void detach(HashEntry *entry) 92 { 93 ContextAttribs *attribs = entry ? entry->value : NULL; 94 delete attribs; 95 } 96 compare(GLXContext key1,void * key2,HashEntry * entry)97 bool compare(GLXContext key1, void *key2, HashEntry *entry) 98 { 99 return false; 100 } 101 102 static ContextHash *instance; 103 static vglutil::CriticalSection instanceMutex; 104 }; 105 } 106 107 #undef HASH 108 109 110 #define ctxhash (*(vglfaker::ContextHash::getInstance())) 111 112 #endif // __CONTEXTHASH_H__ 113