opengl_server execute method is changed from process to thread.
authorfredrick.kim <fredrick.kim@samsung.com>
Wed, 20 Jul 2011 10:48:31 +0000 (19:48 +0900)
committerfredrick.kim <fredrick.kim@samsung.com>
Wed, 20 Jul 2011 10:48:31 +0000 (19:48 +0900)
Makefile.target
target-i386/helper_opengl.c
target-i386/helper_opengl.h
target-i386/op_helper.c
target-i386/opengl_client.c
target-i386/opengl_exec.c
target-i386/opengl_func.h
target-i386/opengl_server.c
target-i386/opengl_server.h [new file with mode: 0644]
target-i386/opengl_utils.h
target-i386/translate.c

index 2e2ee68..6b9b7ca 100644 (file)
@@ -225,7 +225,7 @@ obj-i386-y += pc_piix.o
 obj-i386-$(CONFIG_SPICE) += qxl.o qxl-logger.o qxl-render.o
 ##########################################################
 # opengl library for i386 
-obj-i386-y += helper_opengl.o opengl_exec.o
+obj-i386-y += helper_opengl.o opengl_exec.o opengl_server.o
 ##########################################################
 
 ##########################################################
@@ -388,6 +388,8 @@ client_stub.c server_stub.c gl_func.h: parse_gl_h
 
 opengl_exec.o: opengl_exec.c server_stub.c gl_func.h
 
+opengl_server.o: opengl_server.c opengl_exec.c
+
 helper_opengl.o: gl_func.h
 
 $(TARGET_PATH)/libGL.so.1: opengl_client.c gl_func.h
index f98dce0..db5c76e 100755 (executable)
@@ -49,18 +49,18 @@ typedef HDC Display;
 HWND           displayHWND;
 #endif
 
-#include "qemu-common.h"
-
-#include "opengl_func.h"
+//## remove GCC warning
+//#include "qemu-common.h"
+//#include "opengl_func.h"
+#include "helper_opengl.h"
 
 #define ENABLE_GL_LOG
 
-extern void init_process_tab(void);
-#ifdef _WIN32
-extern int do_function_call(Display dpy, int func_number, int pid, int* args, char* ret_string);
-#else
-extern int do_function_call(Display* dpy, int func_number, int pid, int* args, char* ret_string);
-#endif
+//#ifdef _WIN32
+//extern int do_function_call(Display dpy, int func_number, int pid, int* args, char* ret_string);
+//#else
+//extern int do_function_call(Display* dpy, int func_number, int pid, int* args, char* ret_string);
+//#endif
 extern int last_process_id;
 
 #ifndef _WIN32
@@ -68,7 +68,7 @@ extern void sdl_set_opengl_window(int x, int y, int width, int height);
 #endif
 
 #ifdef _WIN32
-Display CreateDisplay(void)
+static Display CreateDisplay(void)
 {
   HWND        hWnd;
   WNDCLASS    wc;
@@ -367,7 +367,7 @@ static int write_gl_debug_cmd_short(int my_int)
   return r;
 }
 
-static int inline  write_gl_debug_cmd_buffer_with_size(int size, void* buffer)
+inline static int write_gl_debug_cmd_buffer_with_size(int size, void* buffer)
 {
   int r;
   write_gl_debug_init();
@@ -377,7 +377,7 @@ static int inline  write_gl_debug_cmd_buffer_with_size(int size, void* buffer)
   return r;
 }
 
-static int inline  write_gl_debug_cmd_buffer_without_size(int size, void* buffer)
+inline static int write_gl_debug_cmd_buffer_without_size(int size, void* buffer)
 {
   int r = 0;
   write_gl_debug_init();
@@ -462,7 +462,9 @@ static int decode_call_int(CPUState *env, int func_number, int pid, target_ulong
   if (dpy == NULL)
   {
     dpy = CreateDisplay();
-    init_process_tab();
+    //init_process_tab();
+    create_process_tab(NULL);
+
     ret_string = malloc(32768);
     my_strlen = strlen;
   }
@@ -961,7 +963,9 @@ static int decode_call_int(CPUState *env, int func_number, int pid, target_ulong
     }
     
     dpy = XOpenDisplay(NULL);
-    init_process_tab();
+    /*init_process_tab();*/
+    create_process_tab(NULL);
+
     ret_string = malloc(32768);
     my_strlen = strlen;
   }
index 0da7152..ed599cb 100644 (file)
@@ -2,4 +2,4 @@
 #include "opengl_func.h"
 
 extern int decode_call(CPUState *env, int func_number, int pid, target_ulong target_ret_string, target_ulong in_args, target_ulong in_args_size);
-
+extern void helper_opengl(CPUState *env);
index c268a46..ae8b68a 100644 (file)
@@ -4811,7 +4811,7 @@ void helper_int99(void)
 {
   regs_to_env();
 #ifndef _WIN32
-  helper_opengl(env);
+  //helper_opengl(env);
 #endif
   env_to_regs();
 }
index 2422c34..6b6e723 100644 (file)
@@ -1373,9 +1373,21 @@ static void do_init()
 
 /* Get fixed host IP address and connect to server */
 #ifdef USE_TCP_METHOD
-    char fixed_host_ip[] = "10.0.2.2";  /* HOST_QEMU_ADDRESS */
+    //char fixed_host_ip[] = "10.0.2.2";  /* HOST_QEMU_ADDRESS */
+    //init_sockaddr (&servername, getenv("GL_SERVER") ? getenv("GL_SERVER") : &fixed_host_ip[0], port);
 
-    init_sockaddr (&servername, getenv("GL_SERVER") ? getenv("GL_SERVER") : &fixed_host_ip[0], port);
+    FILE *fAddr;
+    char buffer[32];
+
+    fAddr = fopen("/opt/home/opengl_ip.txt", "rt");
+    if (fAddr == NULL) {
+       fprintf(stderr, "opengl_ip.txt file open error\n");
+       exit(EXIT_FAILURE);
+    }
+
+    fgets(buffer, 32, fAddr);
+    init_sockaddr(&servername, getenv("GL_SERVER") ? getenv("GL_SERVER") : buffer, port);
+    fclose(fAddr);
 #else
     init_sockaddr (&servername, getenv("GL_SERVER") ? getenv("GL_SERVER") : "localhost", port);
 #endif
@@ -1928,8 +1940,9 @@ static void do_opengl_call_no_lock(int func_number, void* ret_ptr, long* args, i
       last_command_buffer_size = -1;
     }
 
-    if (!(func_number == glXSwapBuffers_func || func_number == glFlush_func  || func_number == glFinish_func || (func_number == glReadPixels_func && disable_warning_for_gl_read_pixels)) && enable_gl_buffering)
-      log_gl("synchronous opengl call : %s.\n", tab_opengl_calls_name[func_number]);
+    //if (!(func_number == glXSwapBuffers_func || func_number == glFlush_func  || func_number == glFinish_func || (func_number == glReadPixels_func && disable_warning_for_gl_read_pixels)) && enable_gl_buffering)
+    //  log_gl("synchronous opengl call : %s.\n", tab_opengl_calls_name[func_number]);
+
     if (signature->ret_type == TYPE_CONST_CHAR)
     {
       try_to_put_into_phys_memory(ret_string, RET_STRING_SIZE);
index 38b08bf..8b56dae 100644 (file)
@@ -36,8 +36,6 @@ void init_process_tab(void);
 
 //#define _MK_DBG_
 
-typedef HDC Display;
-
 #define IsViewable         2
 #define False 0
 #define True 1
@@ -51,11 +49,6 @@ typedef HDC Display;
 #include "mesa_glu.h"
 #include "mesa_mipmap.c"
 
-
-static HDC active_win = 0; /* FIXME */
-static int active_win_x = 0;
-static int active_win_y = 0;
-
 typedef struct
 {
        HGLRC context;
@@ -70,8 +63,8 @@ typedef struct
 {
        void* key;
        void* value;
-       void* hWnd; /* Surface?? À§?? Window Handle*/
-       void* cDC; /*Context?? À§?? Dummy Window Handle*/
+       void* hWnd; /* Surface?? Ã\80§?? Window Handle*/
+       void* cDC; /*Context?? Ã\80§?? Dummy Window Handle*/
 } Assoc;
 
 
@@ -81,6 +74,7 @@ typedef struct
 #define MAX_FBCONFIG 10
 
 #include "opengl_utils.h"
+#include "opengl_server.h"
 
 #define MAX(a, b) (((a) > (b)) ? (a) : (b))
 
@@ -210,13 +204,6 @@ typedef struct
        Assoc association_fakecontext_visual[MAX_ASSOC_SIZE];
 } ProcessStruct;
 
-static ProcessStruct processTab[MAX_HANDLED_PROCESS];
-
-void init_process_tab(void)
-{
-       memset(processTab, 0, sizeof(processTab));
-}
-
 int last_process_id = 0;
 
 
@@ -228,12 +215,6 @@ typedef struct
        /*PIXELFORMATDESCRIPTOR* visInfo;*/
 } AssocAttribListVisual;
 
-static int nTabAssocAttribListVisual = 0;
-static AssocAttribListVisual* tabAssocAttribListVisual = NULL;
-
-
-
-
 #define ARG_TO_CHAR(x)                (char)(x)
 #define ARG_TO_UNSIGNED_CHAR(x)       (unsigned char)(x)
 #define ARG_TO_SHORT(x)               (short)(x)
@@ -323,10 +304,6 @@ static void _get_window_pos(HWND hWnd, WindowPosStruct* pos)
 
 int display_function_call = 0;
 
-
-static int last_assigned_internal_num = 0;
-static int last_active_internal_num = 0;
-
 static void init_gl_state(GLState* state)
 {
        state->textureAllocator = &state->ownTextureAllocator;
@@ -369,7 +346,6 @@ static void destroy_gl_state(GLState* state)
        if (state->elementPointerATI) free(state->elementPointerATI);
 }
 
-
 static void _create_context(ProcessStruct* process, HGLRC ctxt, int fake_ctxt, HGLRC shareList, int fake_shareList)
 {
        process->glstates = realloc(process->glstates, (process->nbGLStates+1)*sizeof(GLState*));
@@ -922,16 +898,17 @@ void unset_association_fakepbuffer_pbuffer(ProcessStruct* process, void* fakepbu
        }
 }
 
-static int get_visual_info_from_visual_id(Display dpy, int visualid, PIXELFORMATDESCRIPTOR* rpfd)
+static int get_visual_info_from_visual_id( OGLS_Conn *pConn, int visualid, PIXELFORMATDESCRIPTOR* rpfd)
 {
        int i;
        if( 0 < visualid )
        {
-               for(i=0;i<nTabAssocAttribListVisual;i++)
+               AssocAttribListVisual *tabAssocAttribListVisual = (AssocAttribListVisual *)pConn->tabAssocAttribListVisual ;
+               for(i=0;i<pConn->nTabAssocAttribListVisual;i++)
                {
                        if ( tabAssocAttribListVisual[i].visualID == visualid)
                        {
-                               DescribePixelFormat((HDC)dpy, (visualid -1), sizeof( PIXELFORMATDESCRIPTOR), rpfd);
+                               DescribePixelFormat((HDC)pConn->Display, (visualid -1), sizeof( PIXELFORMATDESCRIPTOR), rpfd);
                                return 1;
                        }
                }
@@ -946,8 +923,6 @@ static int get_default_visual(Display dpy, PIXELFORMATDESCRIPTOR* rpfd)
        hdc = (HDC) dpy;
        int n;
 
-       fprintf(stderr, "get_default_visual\n");
-
        if ((n = DescribePixelFormat(hdc, 0, 0, NULL)) > 0)
        {
                int i;
@@ -971,12 +946,11 @@ static int get_default_visual(Display dpy, PIXELFORMATDESCRIPTOR* rpfd)
                if( i < n ) return i + 1;
        }
 
-       fprintf(stderr, "get_default_visual() - Error \n");
        return 0;
 }
 
-/* Surface?? À§?? Window ????*/
-static HDC create_swindow(HDC clientdrawable, ProcessStruct* process, int x, int y, int width, int height)
+/* Surface?? ?? Window ????*/
+static HDC create_swindow(OGLS_Conn *pConn, HDC clientdrawable, ProcessStruct* process, int x, int y, int width, int height)
 {
        RECT rect;
        HWND hWnd;
@@ -1010,7 +984,7 @@ static HDC create_swindow(HDC clientdrawable, ProcessStruct* process, int x, int
        hDC = GetDC(hWnd);
        if(hDC)
        {
-               active_win = hDC;
+               pConn->active_win = hDC;
                ShowWindow(hWnd,SW_HIDE);
                set_association_clientdrawable_serverwnd(process, (void *) clientdrawable, (void *) hWnd);
        }
@@ -1018,7 +992,7 @@ static HDC create_swindow(HDC clientdrawable, ProcessStruct* process, int x, int
        return hDC;
 }
 
-/* pbuffer?? À§?? Window ????*/
+/* pbuffer?? ?? Window ????*/
 static HDC create_pbwindow(void *fakepbuffer, ProcessStruct* process, int x, int y, int width, int height)
 {
        RECT rect;
@@ -1060,7 +1034,7 @@ static HDC create_pbwindow(void *fakepbuffer, ProcessStruct* process, int x, int
        return hDC;
 }
 
-/* context?? À§?? Dummy Window ????*/
+/* context?? Ã\80§?? Dummy Window ????*/
 static HDC create_cwindow(int fake_ctx, ProcessStruct* process, int x, int y, int width, int height)
 {
        RECT rect;
@@ -1102,15 +1076,15 @@ static HDC create_cwindow(int fake_ctx, ProcessStruct* process, int x, int y, in
        return hDC;
 }
 
-static void destroy_glwindow(HWND hWnd, HDC hDC )
+static void destroy_glwindow(OGLS_Conn *pConn, HWND hWnd, HDC hDC )
 {
        ReleaseDC( hWnd, hDC );
        DestroyWindow(hWnd);
 
        /*PostQuitMessage(0);*/
 
-       if( active_win == hDC)
-               active_win = 0;
+       if( pConn->active_win == hDC)
+               pConn->active_win = 0;
 }
 
 static int get_server_texture(ProcessStruct* process, unsigned int client_texture)
@@ -1220,16 +1194,18 @@ translate_id(GLsizei n, GLenum type, const GLvoid * list)
 }
 
 
-int do_function_call(Display dpy, int func_number, int pid, long* args, char* ret_string)
+int do_function_call(OGLS_Conn *pConn, int func_number, int pid, long* args, char* ret_string)
 {
        char ret_char = 0;
        int ret_int = 0;
        const char* ret_str = NULL;
        int iProcess;
        ProcessStruct* process = NULL;
+       ProcessStruct *processTab = (ProcessStruct *) pConn->processTab;
 
        for(iProcess=0;iProcess<MAX_HANDLED_PROCESS;iProcess++)
        {
+               ProcessStruct *processTab = (ProcessStruct *) pConn->processTab;
                if (processTab[iProcess].process_id == pid)
                {
                        process = &processTab[iProcess];
@@ -1240,7 +1216,7 @@ int do_function_call(Display dpy, int func_number, int pid, long* args, char* re
                        process = &processTab[iProcess];
                        memset(process, 0, sizeof(ProcessStruct));
                        process->process_id = pid;
-                       process->internal_num = last_assigned_internal_num++;
+                       process->internal_num = pConn->last_assigned_internal_num++;
                        init_gl_state(&process->default_state);
                        process->current_state = &process->default_state;
                        break;
@@ -1252,10 +1228,10 @@ int do_function_call(Display dpy, int func_number, int pid, long* args, char* re
                return 0;
        }
 
-       if (process->internal_num != last_active_internal_num)
+       if (process->internal_num != pConn->last_active_internal_num)
        {
                wglMakeCurrent(process->current_state->drawable, process->current_state->context);
-               last_active_internal_num = process->internal_num;
+               pConn->last_active_internal_num = process->internal_num;
        }
 
        process->instr_counter++;
@@ -1343,7 +1319,7 @@ int do_function_call(Display dpy, int func_number, int pid, long* args, char* re
                                destroy_gl_state(&process->default_state);
                                free(process->glstates);
 
-                               active_win = 0;
+                               pConn->active_win = 0;
 
                                memmove(&processTab[iProcess], &processTab[iProcess+1], (MAX_HANDLED_PROCESS - 1 - iProcess) * sizeof(ProcessStruct));
 
@@ -1380,11 +1356,11 @@ int do_function_call(Display dpy, int func_number, int pid, long* args, char* re
                                        if (!(params[0] == pos.x && params[1] == pos.y && params[2] == pos.width && params[3] == pos.height))
                                        {
                                                int redim = !(params[2] == pos.width && params[3] == pos.height);
-                                               active_win_x = params[0];
-                                               active_win_y = params[1];
+                                               pConn->active_win_x = params[0];
+                                               pConn->active_win_y = params[1];
 
-                                               fprintf(stderr, "old x=%d y=%d width=%d height=%d\n", pos.x, pos.y, pos.width, pos.height);
-                                               fprintf(stderr, "new x=%d y=%d width=%d height=%d\n", params[0], params[1], params[2], params[3]);
+                                               //fprintf(stderr, "old x=%d y=%d width=%d height=%d\n", pos.x, pos.y, pos.width, pos.height);
+                                               //fprintf(stderr, "new x=%d y=%d width=%d height=%d\n", params[0], params[1], params[2], params[3]);
 
                                                if (redim)
                                                {
@@ -1443,7 +1419,7 @@ int do_function_call(Display dpy, int func_number, int pid, long* args, char* re
                                }
                                else
                                {
-                                       hdc = (HDC) dpy;
+                                       hdc = (HDC) pConn->Display;
 
                                        if ((n = DescribePixelFormat(hdc, 0, 0, NULL)) > 0)
                                        {
@@ -1560,17 +1536,18 @@ int do_function_call(Display dpy, int func_number, int pid, long* args, char* re
                                        visualid = fbConfig->visualID;
                                        ret_int = visualid;
 
-                                       for( i = 0; i < nTabAssocAttribListVisual && (tabAssocAttribListVisual[i].visualID != visualid); i++ );
+                                       AssocAttribListVisual *tabAssocAttribListVisual = (AssocAttribListVisual *)pConn->tabAssocAttribListVisual ;
+                                       for( i = 0; i < pConn->nTabAssocAttribListVisual && (tabAssocAttribListVisual[i].visualID != visualid); i++ );
 
-                                       if( i >= nTabAssocAttribListVisual )
+                                       if( i >= pConn->nTabAssocAttribListVisual )
                                        {
-                                               tabAssocAttribListVisual =
-                                                       realloc(tabAssocAttribListVisual, sizeof(AssocAttribListVisual) * (nTabAssocAttribListVisual+1));
+                                               pConn->tabAssocAttribListVisual = tabAssocAttribListVisual =
+                                                       realloc(tabAssocAttribListVisual, sizeof(AssocAttribListVisual) * (pConn->nTabAssocAttribListVisual+1));
 
-                                               tabAssocAttribListVisual[nTabAssocAttribListVisual].attribListLength = 0;
-                                               tabAssocAttribListVisual[nTabAssocAttribListVisual].attribList = NULL;
-                                               tabAssocAttribListVisual[nTabAssocAttribListVisual].visualID = visualid;
-                                               nTabAssocAttribListVisual++;
+                                               tabAssocAttribListVisual[pConn->nTabAssocAttribListVisual].attribListLength = 0;
+                                               tabAssocAttribListVisual[pConn->nTabAssocAttribListVisual].attribList = NULL;
+                                               tabAssocAttribListVisual[pConn->nTabAssocAttribListVisual].visualID = visualid;
+                                               pConn->nTabAssocAttribListVisual++;
                                        }
 
                                        if (display_function_call) fprintf(stderr, "visualid = %d\n", ret_int);
@@ -1650,14 +1627,14 @@ int do_function_call(Display dpy, int func_number, int pid, long* args, char* re
 
                                if (1 || display_function_call) fprintf(stderr, "visualid=%d, fake_shareList=%d\n", visualid, fake_shareList);
 
-                               if(get_visual_info_from_visual_id(dpy, visualid, &pfd))
+                               if(get_visual_info_from_visual_id(pConn, visualid, &pfd))
                                {
                                        SetPixelFormat(hdc, visualid - 1, &pfd);
                                        ctxt = wglCreateContext (hdc);
                                }
                                else
                                {
-                                       if((visualid = get_default_visual(dpy, &pfd)))
+                                       if((visualid = get_default_visual(pConn->Display, &pfd)))
                                        {
                                                SetPixelFormat(hdc, visualid - 1, &pfd);
                                                ctxt = wglCreateContext (hdc);
@@ -1769,14 +1746,14 @@ int do_function_call(Display dpy, int func_number, int pid, long* args, char* re
 
                                                if( visualid == 0 )
                                                {
-                                                       visualid = get_default_visual(dpy, &pfd);
+                                                       visualid = get_default_visual(pConn->Display, &pfd);
                                                }
 
                                                drawable = get_association_clientdrawable_serverdrawable(process, client_drawable);
                                                if (drawable == 0)
                                                {
 
-                                                       drawable = create_swindow(client_drawable, process, 0, 0, 480, 800);
+                                                       drawable = create_swindow(pConn, client_drawable, process, 0, 0, 480, 800);
                                                        set_association_clientdrawable_serverdrawable(process, (void*)client_drawable, (void*)drawable);
                                                }
 
@@ -1818,13 +1795,13 @@ int do_function_call(Display dpy, int func_number, int pid, long* args, char* re
 
                                if (visualid)
                                {
-                                       if( get_visual_info_from_visual_id(dpy, visualid, &pfd))
+                                       if( get_visual_info_from_visual_id(pConn, visualid, &pfd))
                                        {
                                                ret_int = get_pfdAttrib(&pfd, args[2], (int*)args[3]);
                                        }
                                        else
                                        {
-                                               if( get_default_visual(dpy, &pfd))
+                                               if( get_default_visual(pConn->Display, &pfd))
                                                        ret_int = get_pfdAttrib(&pfd, args[2], (int*)args[3]);
                                                else
                                                        ret_int = GLX_BAD_VISUAL;
@@ -1832,7 +1809,7 @@ int do_function_call(Display dpy, int func_number, int pid, long* args, char* re
                                }
                                else
                                {
-                                       if( get_default_visual(dpy, &pfd))
+                                       if( get_default_visual(pConn->Display, &pfd))
                                                ret_int = get_pfdAttrib(&pfd, args[2], (int*)args[3]);
                                        else
                                                ret_int = GLX_BAD_VISUAL;
@@ -1845,24 +1822,25 @@ int do_function_call(Display dpy, int func_number, int pid, long* args, char* re
                        {
                                PIXELFORMATDESCRIPTOR pfd;
                                unsigned int visualid = 0;
+                               AssocAttribListVisual *tabAssocAttribListVisual = (AssocAttribListVisual *)pConn->tabAssocAttribListVisual ;
 
                                int i;
 
                                if ((int*)args[2] == NULL)
                                        ret_int = 0;
 
-                               visualid = get_default_visual(dpy, &pfd);
+                               visualid = get_default_visual(pConn->Display, &pfd);
 
-                               for( i = 0; i < nTabAssocAttribListVisual && (tabAssocAttribListVisual[i].visualID != visualid); i++ );
+                               for( i = 0; i < pConn->nTabAssocAttribListVisual && (tabAssocAttribListVisual[i].visualID != visualid); i++ );
 
-                               if( i >= nTabAssocAttribListVisual ) {
-                                       tabAssocAttribListVisual =
-                                               realloc(tabAssocAttribListVisual, sizeof(AssocAttribListVisual) * (nTabAssocAttribListVisual+1));
+                               if( i >= pConn->nTabAssocAttribListVisual ) {
+                                       pConn->tabAssocAttribListVisual = tabAssocAttribListVisual =
+                                               realloc(tabAssocAttribListVisual, sizeof(AssocAttribListVisual) * (pConn->nTabAssocAttribListVisual+1));
 
-                                       tabAssocAttribListVisual[nTabAssocAttribListVisual].attribListLength = 0;
-                                       tabAssocAttribListVisual[nTabAssocAttribListVisual].attribList = NULL;
-                                       tabAssocAttribListVisual[nTabAssocAttribListVisual].visualID = i;
-                                       nTabAssocAttribListVisual++;
+                                       tabAssocAttribListVisual[pConn->nTabAssocAttribListVisual].attribListLength = 0;
+                                       tabAssocAttribListVisual[pConn->nTabAssocAttribListVisual].attribList = NULL;
+                                       tabAssocAttribListVisual[pConn->nTabAssocAttribListVisual].visualID = i;
+                                       pConn->nTabAssocAttribListVisual++;
                                }
 
                                ret_int = visualid;
@@ -1880,7 +1858,7 @@ int do_function_call(Display dpy, int func_number, int pid, long* args, char* re
 
                                if( drawable && hWnd )
                                {
-                                       destroy_glwindow(hWnd, drawable);
+                                       destroy_glwindow(pConn, hWnd, drawable);
 
 #if defined( _MK_DBG_ )
                                        printf("DestoryWindw( HWND 0x%p, HDC 0x%p) Client Drawable 0x%p\n", hWnd, drawable, client_drawable);
@@ -1961,7 +1939,7 @@ int do_function_call(Display dpy, int func_number, int pid, long* args, char* re
                                                        wglDeleteContext(ctxt);
 
                                                        get_association_fakecontext_glxwnd(process, (void*)(long)fake_ctxt, hWnd, hdc);
-                                                       destroy_glwindow(hWnd, hdc);
+                                                       destroy_glwindow(pConn, hWnd, hdc);
 
                                                        unset_association_fakecontext_glxcontext(process, (void*)(long)fake_ctxt);
                                                        unset_association_fakecontext_visualid(process, (void*)(long)fake_ctxt);
@@ -2189,7 +2167,7 @@ int do_function_call(Display dpy, int func_number, int pid, long* args, char* re
                                                free(pb_info);
                                        }
 
-                                       destroy_glwindow(hWnd, pbuffer);
+                                       destroy_glwindow(pConn, hWnd, pbuffer);
 
 #if defined( _MK_DBG_ )
                                        printf("DestoryPbuffer( HWND 0x%p, HDC 0x%p) fake pbuffer 0x%p\n", hWnd, pbuffer, fakepbuffer);
@@ -3540,6 +3518,7 @@ int do_function_call(Display dpy, int func_number, int pid, long* args, char* re
 
 #else
 
+#include <arpa/inet.h>
 #include <X11/Xlib.h>
 #include <X11/Xutil.h>
 
@@ -3550,6 +3529,7 @@ int do_function_call(Display dpy, int func_number, int pid, long* args, char* re
 #include <mesa_glx.h>
 
 #include "opengl_func.h"
+#include "opengl_server.h"
 
 #include "mesa_glu.h"
 #include "mesa_mipmap.c"
@@ -3641,31 +3621,17 @@ static XVisualInfo* get_default_visual(Display* dpy)
        return vis;
 }
 
-
-static Display* parent_dpy = NULL;
-static Window qemu_parent_window = 0;
-
-static Window active_win = 0; /* FIXME */
-static int active_win_x = 0;
-static int active_win_y = 0;
-
-void opengl_exec_set_parent_window(Display* _dpy, Window _parent_window)
+void opengl_exec_set_parent_window(OGLS_Conn *pConn, Window _parent_window)
 {
-       parent_dpy = _dpy;
-       qemu_parent_window = _parent_window;
-       if (active_win)
+       pConn->parent_dpy = pConn->Display;
+       pConn->qemu_parent_window = _parent_window;
+       if (pConn->active_win)
        {
-               XReparentWindow(_dpy, active_win, _parent_window, active_win_x, active_win_y);
+               XReparentWindow(pConn->Display, pConn->active_win, _parent_window, pConn->active_win_x, pConn->active_win_y);
        }
 }
 
-static int local_connection = 0;
-void opengl_exec_set_local_connection(void)
-{
-       local_connection = 1;
-}
-
-static Window create_window(Display* dpy, Window local_parent_window, XVisualInfo* vis, const char *name,
+static Window create_window(OGLS_Conn *pConn, Window local_parent_window, XVisualInfo* vis, const char *name,
                int x, int y, int width, int height)
 {
        int scrnum;
@@ -3674,13 +3640,13 @@ static Window create_window(Display* dpy, Window local_parent_window, XVisualInf
        Window root;
        Window win;
 
-       scrnum = DefaultScreen( dpy );
-       root = RootWindow( dpy, scrnum );
+       scrnum = DefaultScreen( pConn->Display );
+       root = RootWindow( pConn->Display, scrnum );
 
        /* window attributes */
        attr.background_pixel = 0;
        attr.border_pixel = 0;
-       attr.colormap = XCreateColormap( dpy, root, vis->visual, AllocNone);
+       attr.colormap = XCreateColormap( pConn->Display, root, vis->visual, AllocNone);
        attr.event_mask = StructureNotifyMask | ExposureMask /*| KeyPressMask*/;
        attr.save_under = True;
        //if (local_parent_window == NULL && qemu_parent_window == NULL)
@@ -3692,19 +3658,19 @@ static Window create_window(Display* dpy, Window local_parent_window, XVisualInf
 
        if (local_parent_window)
        {
-               win = XCreateWindow( dpy, local_parent_window, 0, 0, width, height,
+               win = XCreateWindow( pConn->Display, local_parent_window, 0, 0, width, height,
                                0, vis->depth, InputOutput,
                                vis->visual, mask, &attr );
        }
-       else if (qemu_parent_window)
+       else if (pConn->qemu_parent_window)
        {
-               win = XCreateWindow( dpy, qemu_parent_window, 0, 0, width, height,
+               win = XCreateWindow( pConn->Display, pConn->qemu_parent_window, 0, 0, width, height,
                                0, vis->depth, InputOutput,
                                vis->visual, mask, &attr );
        }
        else
        {
-               win = XCreateWindow( dpy, root, 0, 0, width, height,
+               win = XCreateWindow( pConn->Display, root, 0, 0, width, height,
                                0, vis->depth, InputOutput,
                                vis->visual, mask, &attr );
        }
@@ -3717,22 +3683,22 @@ static Window create_window(Display* dpy, Window local_parent_window, XVisualInf
                sizehints.width  = width;
                sizehints.height = height;
                sizehints.flags = USSize | USPosition;
-               XSetWMNormalHints(dpy, win, &sizehints);
-               XSetStandardProperties(dpy, win, name, name,
+               XSetWMNormalHints(pConn->Display, win, &sizehints);
+               XSetStandardProperties(pConn->Display, win, name, name,
                                None, (char **)NULL, 0, &sizehints);
        }
 
-       /* Host Window?? ?׸??? ?ʴ´?. if( win )
-          XMapWindow(dpy, win);*/
+       /* Host Window?? ?琉??? ?苛쨈?. if( win )
+          XMapWindow(pConn->Display, win);*/
 
-       XSync(dpy, 0);
+       XSync(pConn->Display, 0);
 
        /*
           int loop = 1;
           while (loop) {
-          while (XPending(dpy) > 0) {
+          while (XPending(pConn->Display) > 0) {
           XEvent event;
-          XNextEvent(dpy, &event);
+          XNextEvent(pConn->Display, &event);
           switch (event.type) {
           case CreateNotify:
           {
@@ -3746,23 +3712,23 @@ static Window create_window(Display* dpy, Window local_parent_window, XVisualInf
           }
           }*/
 
-       active_win = win;
+       pConn->active_win = win;
 
        return win;
 }
 
-static void destroy_window(Display* dpy, Window win )
+static void destroy_window(OGLS_Conn *pConn, Window win )
 {
        /*int i;*/
 
-       XDestroyWindow(dpy, win);
+       XDestroyWindow(pConn->Display, win);
 
-       XSync(dpy, 0);
+       XSync(pConn->Display, 0);
        /*int loop = 1;
          while (loop) {
-         while (XPending(dpy) > 0) {
+         while (XPending(pConn->Display) > 0) {
          XEvent event;
-         XNextEvent(dpy, &event);
+         XNextEvent(pConn->Display, &event);
          switch (event.type) {
          case DestroyNotify:
          {
@@ -3776,8 +3742,8 @@ static void destroy_window(Display* dpy, Window win )
          }
          }*/
 
-       if( active_win == win)
-               active_win = 0;
+       if( pConn->active_win == win)
+               pConn->active_win = 0;
 
 }
 
@@ -3913,13 +3879,6 @@ typedef struct
        Assoc association_fakecontext_visual[MAX_ASSOC_SIZE];
 } ProcessStruct;
 
-static ProcessStruct processTab[MAX_HANDLED_PROCESS];
-
-void init_process_tab(void)
-{
-       memset(processTab, 0, sizeof(processTab));
-}
-
 int last_process_id = 0;
 
 
@@ -4203,9 +4162,6 @@ typedef struct
        XVisualInfo* visInfo;
 } AssocAttribListVisual;
 
-static int nTabAssocAttribListVisual = 0;
-static AssocAttribListVisual* tabAssocAttribListVisual = NULL;
-
 static int _compute_length_of_attrib_list_including_zero(const int* attribList, int booleanMustHaveValue)
 {
        int i = 0;
@@ -4227,8 +4183,10 @@ static int _compute_length_of_attrib_list_including_zero(const int* attribList,
        return i + 1;
 }
 
-static int glXChooseVisualFunc(Display* dpy, const int* _attribList)
+static int glXChooseVisualFunc( OGLS_Conn *pConn, const int* _attribList)
 {
+       AssocAttribListVisual *tabAssocAttribListVisual = (AssocAttribListVisual *)pConn->tabAssocAttribListVisual ;
+
        if (_attribList == NULL)
                return 0;
        int attribListLength = _compute_length_of_attrib_list_including_zero(_attribList, 0);
@@ -4258,7 +4216,7 @@ static int glXChooseVisualFunc(Display* dpy, const int* _attribList)
                }
        }
 
-       for(i=0;i<nTabAssocAttribListVisual;i++)
+       for(i=0;i<pConn->nTabAssocAttribListVisual;i++)
        {
                if (tabAssocAttribListVisual[i].attribListLength == attribListLength &&
                                memcmp(tabAssocAttribListVisual[i].attribList, attribList, attribListLength * sizeof(int)) == 0)
@@ -4267,24 +4225,27 @@ static int glXChooseVisualFunc(Display* dpy, const int* _attribList)
                        return (tabAssocAttribListVisual[i].visInfo) ? tabAssocAttribListVisual[i].visInfo->visualid : 0;
                }
        }
-       XVisualInfo* visInfo = glXChooseVisual(dpy, 0, attribList);
-       tabAssocAttribListVisual =
-               realloc(tabAssocAttribListVisual, sizeof(AssocAttribListVisual) * (nTabAssocAttribListVisual+1));
-       tabAssocAttribListVisual[nTabAssocAttribListVisual].attribListLength = attribListLength;
-       tabAssocAttribListVisual[nTabAssocAttribListVisual].attribList = (int*)malloc(sizeof(int) * attribListLength);
-       memcpy(tabAssocAttribListVisual[nTabAssocAttribListVisual].attribList, attribList, sizeof(int) * attribListLength);
-       tabAssocAttribListVisual[nTabAssocAttribListVisual].visInfo = visInfo;
-       nTabAssocAttribListVisual++;
+       XVisualInfo* visInfo = glXChooseVisual(pConn->Display, 0, attribList);
+       pConn->tabAssocAttribListVisual = tabAssocAttribListVisual =
+               realloc(tabAssocAttribListVisual, sizeof(AssocAttribListVisual) * (pConn->nTabAssocAttribListVisual+1));
+       tabAssocAttribListVisual[pConn->nTabAssocAttribListVisual].attribListLength = attribListLength;
+       tabAssocAttribListVisual[pConn->nTabAssocAttribListVisual].attribList = (int*)malloc(sizeof(int) * attribListLength);
+       memcpy(tabAssocAttribListVisual[pConn->nTabAssocAttribListVisual].attribList, attribList, sizeof(int) * attribListLength);
+       tabAssocAttribListVisual[pConn->nTabAssocAttribListVisual].visInfo = visInfo;
+       pConn->nTabAssocAttribListVisual++;
        free(attribList);
        return (visInfo) ? visInfo->visualid : 0;
 }
 
-static XVisualInfo* get_visual_info_from_visual_id(Display* dpy, int visualid)
+static XVisualInfo* get_visual_info_from_visual_id( OGLS_Conn *pConn, int visualid)
 {
        int i, n;
        XVisualInfo template;
        XVisualInfo* visInfo;
-       for(i=0;i<nTabAssocAttribListVisual;i++)
+
+       AssocAttribListVisual *tabAssocAttribListVisual = (AssocAttribListVisual *)pConn->tabAssocAttribListVisual ;
+
+       for(i=0;i<pConn->nTabAssocAttribListVisual;i++)
        {
                if (tabAssocAttribListVisual[i].visInfo &&
                                tabAssocAttribListVisual[i].visInfo->visualid == visualid)
@@ -4293,13 +4254,13 @@ static XVisualInfo* get_visual_info_from_visual_id(Display* dpy, int visualid)
                }
        }
        template.visualid = visualid;
-       visInfo = XGetVisualInfo(dpy, VisualIDMask, &template, &n);
-       tabAssocAttribListVisual =
-               realloc(tabAssocAttribListVisual, sizeof(AssocAttribListVisual) * (nTabAssocAttribListVisual+1));
-       tabAssocAttribListVisual[nTabAssocAttribListVisual].attribListLength = 0;
-       tabAssocAttribListVisual[nTabAssocAttribListVisual].attribList = NULL;
-       tabAssocAttribListVisual[nTabAssocAttribListVisual].visInfo = visInfo;
-       nTabAssocAttribListVisual++;
+       visInfo = XGetVisualInfo(pConn->Display, VisualIDMask, &template, &n);
+       pConn->tabAssocAttribListVisual = tabAssocAttribListVisual =
+               realloc(tabAssocAttribListVisual, sizeof(AssocAttribListVisual) * (pConn->nTabAssocAttribListVisual+1));
+       tabAssocAttribListVisual[pConn->nTabAssocAttribListVisual].attribListLength = 0;
+       tabAssocAttribListVisual[pConn->nTabAssocAttribListVisual].attribList = NULL;
+       tabAssocAttribListVisual[pConn->nTabAssocAttribListVisual].visInfo = visInfo;
+       pConn->nTabAssocAttribListVisual++;
        return visInfo;
 }
 
@@ -4374,9 +4335,6 @@ static void destroy_gl_state(GLState* state)
        if (state->elementPointerATI) free(state->elementPointerATI);
 }
 
-static int last_assigned_internal_num = 0;
-static int last_active_internal_num = 0;
-
 static void init_gl_state(GLState* state)
 {
        state->textureAllocator = &state->ownTextureAllocator;
@@ -4440,7 +4398,7 @@ translate_id(GLsizei n, GLenum type, const GLvoid * list)
        }
 }
 
-void _create_context(ProcessStruct* process, GLXContext ctxt, int fake_ctxt, GLXContext shareList, int fake_shareList)
+static void _create_context(ProcessStruct* process, GLXContext ctxt, int fake_ctxt, GLXContext shareList, int fake_shareList)
 {
        process->glstates = realloc(process->glstates, (process->nbGLStates+1)*sizeof(GLState*));
        process->glstates[process->nbGLStates] = malloc(sizeof(GLState));
@@ -4477,21 +4435,23 @@ void _create_context(ProcessStruct* process, GLXContext ctxt, int fake_ctxt, GLX
        process->nbGLStates++;
 }
 
-int do_function_call(Display* dpy, int func_number, int pid, long* args, char* ret_string)
+int do_function_call(OGLS_Conn *pConn, int func_number, int pid, long* args, char* ret_string)
 {
        char ret_char = 0;
        int ret_int = 0;
        const char* ret_str = NULL;
        int iProcess;
        ProcessStruct* process = NULL;
+       ProcessStruct *processTab = (ProcessStruct *) pConn->processTab;
 
-       if (parent_dpy)
+       if (pConn->parent_dpy)
        {
-               dpy = parent_dpy;
+               pConn->Display = pConn->parent_dpy;
        }
 
        for(iProcess=0;iProcess<MAX_HANDLED_PROCESS;iProcess++)
        {
+               ProcessStruct *processTab = (ProcessStruct *) pConn->processTab;
                if (processTab[iProcess].process_id == pid)
                {
                        process = &processTab[iProcess];
@@ -4502,7 +4462,7 @@ int do_function_call(Display* dpy, int func_number, int pid, long* args, char* r
                        process = &processTab[iProcess];
                        memset(process, 0, sizeof(ProcessStruct));
                        process->process_id = pid;
-                       process->internal_num = last_assigned_internal_num++;
+                       process->internal_num = pConn->last_assigned_internal_num++;
                        init_gl_state(&process->default_state);
                        process->current_state = &process->default_state;
                        break;
@@ -4513,14 +4473,16 @@ int do_function_call(Display* dpy, int func_number, int pid, long* args, char* r
                fprintf(stderr, "Too many processes !\n");
                return 0;
        }
-       if (process->internal_num != last_active_internal_num)
+       if (process->internal_num != pConn->last_active_internal_num)
        {
-               glXMakeCurrent(dpy, process->current_state->drawable, process->current_state->context);
-               last_active_internal_num = process->internal_num;
+               glXMakeCurrent(pConn->Display, process->current_state->drawable, process->current_state->context);
+               pConn->last_active_internal_num = process->internal_num;
        }
 
        process->instr_counter++;
+
        if (display_function_call) fprintf(stderr, "[%d]> %s\n", process->instr_counter, tab_opengl_calls_name[func_number]);
+       //fprintf(stderr, "[%d]> %s\n", process->instr_counter, tab_opengl_calls_name[func_number]);
 
        switch (func_number)
        {
@@ -4543,9 +4505,9 @@ int do_function_call(Display* dpy, int func_number, int pid, long* args, char* r
                                for(i=0;i < MAX_ASSOC_SIZE && process->association_fakecontext_glxcontext[i].key != NULL;i++)
                                {
                                        GLXContext ctxt = process->association_fakecontext_glxcontext[i].value;
-                                       fprintf(stderr, "Destroy context corresponding to fake_context = %ld\n",
-                                                       (long)process->association_fakecontext_glxcontext[i].key);
-                                       glXDestroyContext(dpy, ctxt);
+                                       //fprintf(stderr, "Destroy context corresponding to fake_context = %ld\n",
+                                       //              (long)process->association_fakecontext_glxcontext[i].key);
+                                       glXDestroyContext(pConn->Display, ctxt);
                                }
 
                                GET_EXT_PTR(void, glXDestroyPbuffer, (Display*, GLXPbuffer));
@@ -4554,23 +4516,23 @@ int do_function_call(Display* dpy, int func_number, int pid, long* args, char* r
                                        GLXPbuffer pbuffer = (GLXPbuffer)process->association_fakepbuffer_pbuffer[i].value;
                                        fprintf(stderr, "Destroy pbuffer corresponding to fake_pbuffer = %ld\n",
                                                        (long)process->association_fakepbuffer_pbuffer[i].key);
-                                       if (!is_gl_vendor_ati(dpy))
-                                               ptr_func_glXDestroyPbuffer(dpy, pbuffer);
+                                       if (!is_gl_vendor_ati(pConn->Display))
+                                               ptr_func_glXDestroyPbuffer(pConn->Display, pbuffer);
                                }
 
                                for(i=0;i < MAX_ASSOC_SIZE && process->association_clientdrawable_serverdrawable[i].key != NULL;i++)
                                {
-                                       fprintf(stderr, "Destroy window corresponding to client_drawable = %p\n",
-                                                       process->association_clientdrawable_serverdrawable[i].key);
+                                       //fprintf(stderr, "Destroy window corresponding to client_drawable = %p\n",
+                                       //              process->association_clientdrawable_serverdrawable[i].key);
 
                                        Window win = (Window)process->association_clientdrawable_serverdrawable[i].value;
-                                       XDestroyWindow(dpy, win);
+                                       XDestroyWindow(pConn->Display, win);
 
                                        int loop = 1;
                                        while (loop) {
-                                               while (XPending(dpy) > 0) {
+                                               while (XPending(pConn->Display) > 0) {
                                                        XEvent event;
-                                                       XNextEvent(dpy, &event);
+                                                       XNextEvent(pConn->Display, &event);
                                                        switch (event.type) {
                                                                case DestroyNotify:
                                                                        {
@@ -4593,7 +4555,7 @@ int do_function_call(Display* dpy, int func_number, int pid, long* args, char* r
                                destroy_gl_state(&process->default_state);
                                free(process->glstates);
 
-                               active_win = 0;
+                               pConn->active_win = 0;
 
                                memmove(&processTab[iProcess], &processTab[iProcess+1], (MAX_HANDLED_PROCESS - 1 - iProcess) * sizeof(ProcessStruct));
 
@@ -4613,16 +4575,16 @@ int do_function_call(Display* dpy, int func_number, int pid, long* args, char* r
                                        if (args[1] == IsViewable)
                                        {
                                                WindowPosStruct pos;
-                                               _get_window_pos(dpy, drawable, &pos);
+                                               _get_window_pos(pConn->Display, drawable, &pos);
                                                if (pos.map_state != args[1])
                                                {
-                                                       XMapWindow(dpy, drawable);
+                                                       XMapWindow(pConn->Display, drawable);
 
                                                        int loop = 0; //1;
                                                        while (loop) {
-                                                               while (XPending(dpy) > 0) {
+                                                               while (XPending(pConn->Display) > 0) {
                                                                        XEvent event;
-                                                                       XNextEvent(dpy, &event);
+                                                                       XNextEvent(pConn->Display, &event);
                                                                        switch (event.type) {
                                                                                case ConfigureNotify:
                                                                                        {
@@ -4652,29 +4614,29 @@ int do_function_call(Display* dpy, int func_number, int pid, long* args, char* r
                                if (drawable)
                                {
                                        WindowPosStruct pos;
-                                       _get_window_pos(dpy, drawable, &pos);
+                                       _get_window_pos(pConn->Display, drawable, &pos);
                                        if (!(params[0] == pos.x && params[1] == pos.y && params[2] == pos.width && params[3] == pos.height))
                                        {
                                                int redim = !(params[2] == pos.width && params[3] == pos.height);
-                                               active_win_x = params[0];
-                                               active_win_y = params[1];
+                                               pConn->active_win_x = params[0];
+                                               pConn->active_win_y = params[1];
 
                                                /*
                                                   fprintf(stderr, "old x=%d y=%d width=%d height=%d\n", pos.x, pos.y, pos.width, pos.height);
                                                   fprintf(stderr, "new x=%d y=%d width=%d height=%d\n", params[0], params[1], params[2], params[3]);
                                                 */
 
-                                               XMoveResizeWindow(dpy, drawable, params[0], params[1], params[2], params[3]);
-                                               _get_window_pos(dpy, drawable, &pos);
+                                               XMoveResizeWindow(pConn->Display, drawable, params[0], params[1], params[2], params[3]);
+                                               _get_window_pos(pConn->Display, drawable, &pos);
                                                process->currentDrawablePos = pos;
                                                //if (getenv("FORCE_GL_VIEWPORT"))
                                                if (redim)
                                                        glViewport(0, 0, params[2], params[3]);
                                                int loop = 0; //1;
                                                while (loop) {
-                                                       while (XPending(dpy) > 0) {
+                                                       while (XPending(pConn->Display) > 0) {
                                                                XEvent event;
-                                                               XNextEvent(dpy, &event);
+                                                               XNextEvent(pConn->Display, &event);
                                                                switch (event.type) {
                                                                        case ConfigureNotify:
                                                                                {
@@ -4735,32 +4697,32 @@ int do_function_call(Display* dpy, int func_number, int pid, long* args, char* r
 
                case glXChooseVisual_func:
                        {
-                               ret_int = glXChooseVisualFunc(dpy, (int*)args[2]);
+                               ret_int = glXChooseVisualFunc(pConn, (int*)args[2]);
                                break;
                        }
 
                case glXQueryExtensionsString_func:
                        {
-                               ret_str = glXQueryExtensionsString(dpy, 0);
+                               ret_str = glXQueryExtensionsString(pConn->Display, 0);
                                break;
                        }
 
                case glXQueryServerString_func:
                        {
-                               ret_str = glXQueryServerString(dpy, 0, args[2]);
+                               ret_str = glXQueryServerString(pConn->Display, 0, args[2]);
                                break;
                        }
 
                case glXGetClientString_func:
                        {
-                               ret_str = glXGetClientString(dpy, args[1]);
+                               ret_str = glXGetClientString(pConn->Display, args[1]);
                                break;
                        }
 
                case glXGetScreenDriver_func:
                        {
                                GET_EXT_PTR(const char*, glXGetScreenDriver, (Display* , int ));
-                               ret_str = ptr_func_glXGetScreenDriver(dpy, 0);
+                               ret_str = ptr_func_glXGetScreenDriver(pConn->Display, 0);
                                break;
                        }
 
@@ -4778,18 +4740,18 @@ int do_function_call(Display* dpy, int func_number, int pid, long* args, char* r
                                if (1 || display_function_call) fprintf(stderr, "visualid=%d, fake_shareList=%d\n", visualid, fake_shareList);
 
                                GLXContext shareList = get_association_fakecontext_glxcontext(process, (void*)(long)fake_shareList);
-                               XVisualInfo* vis = get_visual_info_from_visual_id(dpy, visualid);
+                               XVisualInfo* vis = get_visual_info_from_visual_id(pConn, visualid);
                                GLXContext ctxt;
                                if (vis)
                                {
-                                       ctxt = glXCreateContext(dpy, vis, shareList, args[3]);
+                                       ctxt = glXCreateContext(pConn->Display, vis, shareList, args[3]);
                                }
                                else
                                {
-                                       vis = get_default_visual(dpy);
+                                       vis = get_default_visual(pConn->Display);
                                        int saved_visualid = vis->visualid;
                                        vis->visualid = (visualid) ? visualid : saved_visualid;
-                                       ctxt = glXCreateContext(dpy, vis, shareList, args[3]);
+                                       ctxt = glXCreateContext(pConn->Display, vis, shareList, args[3]);
                                        vis->visualid = saved_visualid;
                                }
 
@@ -4827,10 +4789,10 @@ int do_function_call(Display* dpy, int func_number, int pid, long* args, char* r
                                        GLXContext shareList = get_association_fakecontext_glxcontext(process, (void*)(long)fake_shareList);
                                        process->next_available_context_number ++;
                                        int fake_ctxt = process->next_available_context_number;
-                                       GLXContext ctxt = ptr_func_glXCreateNewContext(dpy, fbconfig, args[2], shareList, args[4]);
+                                       GLXContext ctxt = ptr_func_glXCreateNewContext(pConn->Display, fbconfig, args[2], shareList, args[4]);
                                        set_association_fakecontext_glxcontext(process, (void*)(long)fake_ctxt, ctxt);
 
-                                       vis = ptr_func_glXGetVisualFromFBConfig(dpy, fbconfig); /* visual info ????*/
+                                       vis = ptr_func_glXGetVisualFromFBConfig(pConn->Display, fbconfig); /* visual info ????*/
                                        set_association_fakecontext_visual(process, (void *)(long)fake_ctxt, vis);
 
                                        ret_int = fake_ctxt;
@@ -4858,7 +4820,7 @@ int do_function_call(Display* dpy, int func_number, int pid, long* args, char* r
                                }
                                else
                                {
-                                       glXCopyContext(dpy, src_ctxt, dst_ctxt, args[3]);
+                                       glXCopyContext(pConn->Display, src_ctxt, dst_ctxt, args[3]);
                                }
                                break;
                        }
@@ -4914,7 +4876,7 @@ int do_function_call(Display* dpy, int func_number, int pid, long* args, char* r
                                                                }
                                                        }
 
-                                                       glXDestroyContext(dpy, ctxt);
+                                                       glXDestroyContext(pConn->Display, ctxt);
                                                        unset_association_fakecontext_glxcontext(process, (void*)(long)fake_ctxt);
 
                                                        break;
@@ -4926,7 +4888,7 @@ int do_function_call(Display* dpy, int func_number, int pid, long* args, char* r
 
                case glXQueryVersion_func:
                        {
-                               ret_int = glXQueryVersion(dpy, (int*)args[1], (int*)args[2]);
+                               ret_int = glXQueryVersion(pConn->Display, (int*)args[1], (int*)args[2]);
                                break;
                        }
 
@@ -4946,7 +4908,7 @@ int do_function_call(Display* dpy, int func_number, int pid, long* args, char* r
 
                                if (client_drawable == 0 && fake_ctxt == 0)
                                {
-                                       ret_int = glXMakeCurrent(dpy, 0, NULL);
+                                       ret_int = glXMakeCurrent(pConn->Display, 0, NULL);
                                        process->current_state = &process->default_state;
                                }
                                else if ((drawable = (GLXDrawable)get_association_fakepbuffer_pbuffer(process, (void*)client_drawable)))
@@ -4959,7 +4921,7 @@ int do_function_call(Display* dpy, int func_number, int pid, long* args, char* r
                                        }
                                        else
                                        {
-                                               ret_int = glXMakeCurrent(dpy, drawable, ctxt);
+                                               ret_int = glXMakeCurrent(pConn->Display, drawable, ctxt);
                                        }
                                }
                                else
@@ -4977,25 +4939,25 @@ int do_function_call(Display* dpy, int func_number, int pid, long* args, char* r
                                                {
                                                        XVisualInfo* vis = (XVisualInfo*)get_association_fakecontext_visual(process, (void*)(long)fake_ctxt);
                                                        if (vis == NULL)
-                                                               vis = get_default_visual(dpy);
-                                                       /*if (local_connection)
+                                                               vis = get_default_visual(pConn->Display);
+                                                       /*if (pConn->local_connection)
                                                          drawable = client_drawable;
                                                          else*/
                                                        {
-                                                               if (/*local_connection &&*/ client_drawable == RootWindow(dpy, 0))
+                                                               if (/*pConn->local_connection &&*/ client_drawable == RootWindow(pConn->Display, 0))
                                                                {
                                                                        drawable = client_drawable;
                                                                }
                                                                else
                                                                {
-                                                                       drawable = create_window(dpy, (local_connection) ? (Window)client_drawable : 0, vis, "", 0, 0, 480, 800);/* Default Window ũ?⸦ Simulator ũ???? ?????Ѵ?.*/
+                                                                       drawable = create_window(pConn, (pConn->local_connection) ? (Window)client_drawable : 0, vis, "", 0, 0, 480, 800);/* Default Window 크?綬�Simulator 크???? ?????磯?.*/
                                                                }
                                                                //fprintf(stderr, "creating window\n");
                                                        }
                                                        set_association_clientdrawable_serverdrawable(process, (void*)client_drawable, (void*)drawable);
                                                }
 
-                                               ret_int = glXMakeCurrent(dpy, drawable, ctxt);
+                                               ret_int = glXMakeCurrent(pConn->Display, drawable, ctxt);
                                        }
                                }
 
@@ -5026,7 +4988,7 @@ int do_function_call(Display* dpy, int func_number, int pid, long* args, char* r
                                }
                                else
                                {
-                                       if (client_cursor.pixels && local_connection == 0)
+                                       if (client_cursor.pixels && pConn->local_connection == 0)
                                        {
                                                glPushAttrib(GL_ALL_ATTRIB_BITS);
                                                glPushClientAttrib(GL_ALL_ATTRIB_BITS);
@@ -5086,7 +5048,7 @@ int do_function_call(Display* dpy, int func_number, int pid, long* args, char* r
                                                glPopAttrib();
                                        }
 
-                                       glXSwapBuffers(dpy, drawable);
+                                       glXSwapBuffers(pConn->Display, drawable);
                                }
                                break;
                        }
@@ -5103,7 +5065,7 @@ int do_function_call(Display* dpy, int func_number, int pid, long* args, char* r
                                }
                                else
                                {
-                                       ret_char = glXIsDirect(dpy, ctxt);
+                                       ret_char = glXIsDirect(pConn->Display, ctxt);
                                }
                                break;
                        }
@@ -5113,10 +5075,10 @@ int do_function_call(Display* dpy, int func_number, int pid, long* args, char* r
                                int visualid = args[1];
                                XVisualInfo* vis = NULL;
                                if (visualid)
-                                       vis = get_visual_info_from_visual_id(dpy, visualid);
+                                       vis = get_visual_info_from_visual_id(pConn, visualid);
                                if (vis == NULL)
-                                       vis = get_default_visual(dpy);
-                               ret_int = glXGetConfig(dpy, vis, args[2], (int*)args[3]);
+                                       vis = get_default_visual(pConn->Display);
+                               ret_int = glXGetConfig(pConn->Display, vis, args[2], (int*)args[3]);
                                break;
                        }
 
@@ -5131,13 +5093,13 @@ int do_function_call(Display* dpy, int func_number, int pid, long* args, char* r
                                int* res = (int*)args[5];
 
                                if (visualid)
-                                       vis = get_visual_info_from_visual_id(dpy, visualid);
+                                       vis = get_visual_info_from_visual_id(pConn, visualid);
                                if (vis == NULL)
-                                       vis = get_default_visual(dpy);
+                                       vis = get_default_visual(pConn->Display);
 
                                for(i=0;i<n;i++)
                                {
-                                       res[i] = glXGetConfig(dpy, vis, attribs[i], &values[i]);
+                                       res[i] = glXGetConfig(pConn->Display, vis, attribs[i], &values[i]);
                                }
                                break;
                        }
@@ -5151,7 +5113,7 @@ int do_function_call(Display* dpy, int func_number, int pid, long* args, char* r
 
                case glXQueryExtension_func:
                        {
-                               ret_int = glXQueryExtension(dpy, (int*)args[1], (int*)args[2]);
+                               ret_int = glXQueryExtension(pConn->Display, (int*)args[1], (int*)args[2]);
                                break;
                        }
 
@@ -5165,7 +5127,7 @@ int do_function_call(Display* dpy, int func_number, int pid, long* args, char* r
                                }
                                else
                                {
-                                       GLXFBConfig* fbconfigs = ptr_func_glXChooseFBConfig(dpy, args[1], (int*)args[2], (int*)args[3]);
+                                       GLXFBConfig* fbconfigs = ptr_func_glXChooseFBConfig(pConn->Display, args[1], (int*)args[2], (int*)args[3]);
                                        if (fbconfigs)
                                        {
                                                process->fbconfigs[process->nfbconfig] = fbconfigs;
@@ -5192,7 +5154,7 @@ int do_function_call(Display* dpy, int func_number, int pid, long* args, char* r
                                }
                                else
                                {
-                                       GLXFBConfigSGIX* fbconfigs = ptr_func_glXChooseFBConfigSGIX(dpy, args[1], (int*)args[2], (int*)args[3]);
+                                       GLXFBConfigSGIX* fbconfigs = ptr_func_glXChooseFBConfigSGIX(pConn->Display, args[1], (int*)args[2], (int*)args[3]);
                                        if (fbconfigs)
                                        {
                                                process->fbconfigs[process->nfbconfig] = fbconfigs;
@@ -5219,7 +5181,7 @@ int do_function_call(Display* dpy, int func_number, int pid, long* args, char* r
                                }
                                else
                                {
-                                       GLXFBConfig* fbconfigs = ptr_func_glXGetFBConfigs(dpy, args[1], (int*)args[2]);
+                                       GLXFBConfig* fbconfigs = ptr_func_glXGetFBConfigs(pConn->Display, args[1], (int*)args[2]);
                                        if (fbconfigs)
                                        {
                                                process->fbconfigs[process->nfbconfig] = fbconfigs;
@@ -5243,7 +5205,7 @@ int do_function_call(Display* dpy, int func_number, int pid, long* args, char* r
 
                                GLXDrawable drawable = get_association_clientdrawable_serverdrawable(process, client_drawable);
 
-                               destroy_window(dpy, (Window)drawable);
+                               destroy_window(pConn, (Window)drawable);
 
                                int i;
                                for(i=0;process->association_clientdrawable_serverdrawable[i].key != NULL;i++)
@@ -5278,7 +5240,7 @@ int do_function_call(Display* dpy, int func_number, int pid, long* args, char* r
                                GLXFBConfig fbconfig = get_fbconfig(process, client_fbconfig);
                                if (fbconfig)
                                {
-                                       GLXPbuffer pbuffer = ptr_func_glXCreatePbuffer(dpy, fbconfig, (int*)args[2]);
+                                       GLXPbuffer pbuffer = ptr_func_glXCreatePbuffer(pConn->Display, fbconfig, (int*)args[2]);
                                        fprintf(stderr, "glXCreatePbuffer --> %X\n", (int)pbuffer);
                                        if (pbuffer)
                                        {
@@ -5300,7 +5262,7 @@ int do_function_call(Display* dpy, int func_number, int pid, long* args, char* r
                                GLXFBConfig fbconfig = get_fbconfig(process, client_fbconfig);
                                if (fbconfig)
                                {
-                                       GLXPbufferSGIX pbuffer = ptr_func_glXCreateGLXPbufferSGIX(dpy, fbconfig, args[2], args[3], (int*)args[4]);
+                                       GLXPbufferSGIX pbuffer = ptr_func_glXCreateGLXPbufferSGIX(pConn->Display, fbconfig, args[2], args[3], (int*)args[4]);
                                        if (pbuffer)
                                        {
                                                process->next_available_pbuffer_number ++;
@@ -5325,8 +5287,8 @@ int do_function_call(Display* dpy, int func_number, int pid, long* args, char* r
                                }
                                else
                                {
-                                       if (!is_gl_vendor_ati(dpy))
-                                               ptr_func_glXDestroyPbuffer(dpy, pbuffer);
+                                       if (!is_gl_vendor_ati(pConn->Display))
+                                               ptr_func_glXDestroyPbuffer(pConn->Display, pbuffer);
                                        unset_association_fakepbuffer_pbuffer(process, (void*)fake_pbuffer);
                                }
                                break;
@@ -5345,8 +5307,8 @@ int do_function_call(Display* dpy, int func_number, int pid, long* args, char* r
                                }
                                else
                                {
-                                       if (!is_gl_vendor_ati(dpy))
-                                               ptr_func_glXDestroyGLXPbufferSGIX(dpy, pbuffer);
+                                       if (!is_gl_vendor_ati(pConn->Display))
+                                               ptr_func_glXDestroyGLXPbufferSGIX(pConn->Display, pbuffer);
                                        unset_association_fakepbuffer_pbuffer(process, (void*)fake_pbuffer);
                                }
                                break;
@@ -5365,7 +5327,7 @@ int do_function_call(Display* dpy, int func_number, int pid, long* args, char* r
                                }
                                else
                                {
-                                       ptr_func_glXBindTexImageATI(dpy, pbuffer, args[2]);
+                                       ptr_func_glXBindTexImageATI(pConn->Display, pbuffer, args[2]);
                                }
                                break;
                        }
@@ -5383,7 +5345,7 @@ int do_function_call(Display* dpy, int func_number, int pid, long* args, char* r
                                }
                                else
                                {
-                                       ptr_func_glXReleaseTexImageATI(dpy, pbuffer, args[2]);
+                                       ptr_func_glXReleaseTexImageATI(pConn->Display, pbuffer, args[2]);
                                }
                                break;
                        }
@@ -5402,7 +5364,7 @@ int do_function_call(Display* dpy, int func_number, int pid, long* args, char* r
                                }
                                else
                                {
-                                       ret_int = ptr_func_glXBindTexImageARB(dpy, pbuffer, args[2]);
+                                       ret_int = ptr_func_glXBindTexImageARB(pConn->Display, pbuffer, args[2]);
                                }
                                break;
                        }
@@ -5421,7 +5383,7 @@ int do_function_call(Display* dpy, int func_number, int pid, long* args, char* r
                                }
                                else
                                {
-                                       ret_int = ptr_func_glXReleaseTexImageARB(dpy, pbuffer, args[2]);
+                                       ret_int = ptr_func_glXReleaseTexImageARB(pConn->Display, pbuffer, args[2]);
                                }
                                break;
                        }
@@ -5433,7 +5395,7 @@ int do_function_call(Display* dpy, int func_number, int pid, long* args, char* r
                                ret_int = 0;
                                GLXFBConfig fbconfig = get_fbconfig(process, client_fbconfig);
                                if (fbconfig)
-                                       ret_int = ptr_func_glXGetFBConfigAttrib(dpy, fbconfig, args[2], (int*)args[3]);
+                                       ret_int = ptr_func_glXGetFBConfigAttrib(pConn->Display, fbconfig, args[2], (int*)args[3]);
                                break;
                        }
 
@@ -5452,7 +5414,7 @@ int do_function_call(Display* dpy, int func_number, int pid, long* args, char* r
                                {
                                        if (fbconfig)
                                        {
-                                               res[i] = ptr_func_glXGetFBConfigAttrib(dpy, fbconfig, attribs[i], &values[i]);
+                                               res[i] = ptr_func_glXGetFBConfigAttrib(pConn->Display, fbconfig, attribs[i], &values[i]);
                                        }
                                        else
                                        {
@@ -5469,7 +5431,7 @@ int do_function_call(Display* dpy, int func_number, int pid, long* args, char* r
                                ret_int = 0;
                                GLXFBConfig fbconfig = get_fbconfig(process, client_fbconfig);
                                if (fbconfig)
-                                       ret_int = ptr_func_glXGetFBConfigAttribSGIX(dpy, (GLXFBConfigSGIX)fbconfig, args[2], (int*)args[3]);
+                                       ret_int = ptr_func_glXGetFBConfigAttribSGIX(pConn->Display, (GLXFBConfigSGIX)fbconfig, args[2], (int*)args[3]);
                                break;
                        }
 
@@ -5486,7 +5448,7 @@ int do_function_call(Display* dpy, int func_number, int pid, long* args, char* r
                                }
                                else
                                {
-                                       ret_int = ptr_func_glXQueryContext(dpy, ctxt, args[2], (int*)args[3]);
+                                       ret_int = ptr_func_glXQueryContext(pConn->Display, ctxt, args[2], (int*)args[3]);
                                }
                                break;
                        }
@@ -5503,7 +5465,7 @@ int do_function_call(Display* dpy, int func_number, int pid, long* args, char* r
                                }
                                else
                                {
-                                       ptr_func_glXQueryDrawable(dpy, drawable, args[2], (int*)args[3]);
+                                       ptr_func_glXQueryDrawable(pConn->Display, drawable, args[2], (int*)args[3]);
                                }
                                break;
                        }
@@ -5515,7 +5477,7 @@ int do_function_call(Display* dpy, int func_number, int pid, long* args, char* r
                                ret_int = 0;
                                GLXFBConfig fbconfig = get_fbconfig(process, client_fbconfig);
                                if (fbconfig)
-                                       ret_int = ptr_func_glXQueryGLXPbufferSGIX(dpy, (GLXFBConfigSGIX)fbconfig, args[2], (int*)args[3]);
+                                       ret_int = ptr_func_glXQueryGLXPbufferSGIX(pConn->Display, (GLXFBConfigSGIX)fbconfig, args[2], (int*)args[3]);
                                break;
                        }
 
@@ -5530,7 +5492,7 @@ int do_function_call(Display* dpy, int func_number, int pid, long* args, char* r
                                        GLXContext shareList = get_association_fakecontext_glxcontext(process, (void*)args[3]);
                                        process->next_available_context_number ++;
                                        int fake_ctxt = process->next_available_context_number;
-                                       GLXContext ctxt = ptr_func_glXCreateContextWithConfigSGIX(dpy, (GLXFBConfigSGIX)fbconfig, args[2], shareList, args[4]);
+                                       GLXContext ctxt = ptr_func_glXCreateContextWithConfigSGIX(pConn->Display, (GLXFBConfigSGIX)fbconfig, args[2], shareList, args[4]);
                                        set_association_fakecontext_glxcontext(process, (void*)(long)fake_ctxt, ctxt);
                                        ret_int = fake_ctxt;
                                }
@@ -5545,16 +5507,18 @@ int do_function_call(Display* dpy, int func_number, int pid, long* args, char* r
                                GLXFBConfig fbconfig = get_fbconfig(process, client_fbconfig);
                                if (fbconfig)
                                {
-                                       XVisualInfo* vis = ptr_func_glXGetVisualFromFBConfig(dpy, fbconfig);
+                                       AssocAttribListVisual *tabAssocAttribListVisual = (AssocAttribListVisual *)pConn->tabAssocAttribListVisual ;
+                                       XVisualInfo* vis = ptr_func_glXGetVisualFromFBConfig(pConn->Display, fbconfig);
                                        ret_int = (vis) ? vis->visualid : 0;
                                        if (vis)
                                        {
-                                               tabAssocAttribListVisual =
-                                                       realloc(tabAssocAttribListVisual, sizeof(AssocAttribListVisual) * (nTabAssocAttribListVisual+1));
-                                               tabAssocAttribListVisual[nTabAssocAttribListVisual].attribListLength = 0;
-                                               tabAssocAttribListVisual[nTabAssocAttribListVisual].attribList = NULL;
-                                               tabAssocAttribListVisual[nTabAssocAttribListVisual].visInfo = vis;
-                                               nTabAssocAttribListVisual++;
+                                               pConn->tabAssocAttribListVisual = tabAssocAttribListVisual =
+                                                       realloc(tabAssocAttribListVisual, sizeof(AssocAttribListVisual) * (pConn->nTabAssocAttribListVisual+1));
+                                               tabAssocAttribListVisual[pConn->nTabAssocAttribListVisual].attribListLength = 0;
+                                               tabAssocAttribListVisual[pConn->nTabAssocAttribListVisual].attribList = NULL;
+                                               tabAssocAttribListVisual[pConn->nTabAssocAttribListVisual].visInfo = vis;
+                                               pConn->nTabAssocAttribListVisual++;
+                                               pConn->tabAssocAttribListVisual = tabAssocAttribListVisual;
                                        }
                                        if (display_function_call) fprintf(stderr, "visualid = %d\n", ret_int);
                                }
@@ -6670,7 +6634,7 @@ int do_function_call(Display* dpy, int func_number, int pid, long* args, char* r
                case glGetIntegerv_func:
                        {
                                glGetIntegerv(args[0], (int*)args[1]);
-                               fprintf(stderr,"glGetIntegerv(%X)=%d\n", (int)args[0], *(int*)args[1]);
+                               //fprintf(stderr,"glGetIntegerv(%X)=%d\n", (int)args[0], *(int*)args[1]);
                                break;
                        }
 
@@ -6876,6 +6840,27 @@ int do_function_call(Display* dpy, int func_number, int pid, long* args, char* r
 
        return ret_int;
 }
-
 #endif
 
+void create_process_tab( OGLS_Conn *pConn )
+{
+       if (pConn == NULL) {
+               fprintf(stderr, "create_process_tab: pConn is NULL.\n");
+               return;
+       }
+       pConn->processTab = malloc( sizeof(ProcessStruct)*MAX_HANDLED_PROCESS );
+       if( !pConn->processTab )
+       {
+               perror( "init_process_tab" );
+               return ;
+       }
+
+       memset(pConn->processTab, 0, sizeof(ProcessStruct)*MAX_HANDLED_PROCESS );
+}
+
+void remove_process_tab( OGLS_Conn *pConn )
+{
+       if( !pConn->processTab ) return ;
+       free( pConn->processTab );
+       pConn->processTab = NULL;
+}
index e976f19..21f2f42 100644 (file)
 #include "mesa_gl.h"
 #include "mesa_glext.h"
 
+#include "opengl_server.h"
+
+/* To remove GCC warnings */
+//extern void opengl_exec_set_parent_window(Display* _dpy, Window _parent_window);
+extern void opengl_exec_set_parent_window(OGLS_Conn *pConn, Window _parent_window);
+
+extern void opengl_exec_set_local_connection(void);
+
+//#ifdef _WIN32
+//extern int do_function_call(Display dpy, int func_number, int pid, int* args, char* ret_string);
+//#else
+//extern int do_function_call(Display* dpy, int func_number, int pid, long* args, char* ret_string);
+//#endif
+
+extern int do_function_call(OGLS_Conn *, int, int, long*, char*);
+
+extern void execute_func(int func_number, long* args, int* pret_int, char* pret_char);
+
+extern void create_process_tab( OGLS_Conn *pConn );
+extern void remove_process_tab( OGLS_Conn *pConn );
+
 enum
 {
        TYPE_NONE,
index c352ce5..6b1c160 100644 (file)
  */
 
 /* gcc -Wall -O2 -g opengl_server.c opengl_exec.c -o opengl_server -I../i386-softmmu -I. -I.. -lGL */
+/* gcc -g -o opengl_server opengl_server.c opengl_exec.c -I../i386-softmmu -I. -I.. -I/c/mingw/include -lopengl32 -lws2_32 -lgdi32 -lpthread */
 
 #include <stdio.h>
-#include <errno.h>
 #include <stdlib.h>
-#include <unistd.h>
 #include <string.h>
 #include <assert.h>
+#include <pthread.h>
+
+#ifdef _WIN32 // or __MINGW32__
+ #include <windows.h>
+// #include <winsock2.h>
+#else // _WIN32
 #include <sys/types.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <netinet/tcp.h>
-#include <netdb.h>
-#include <arpa/inet.h>
 #include <sys/time.h>
-#include <signal.h>
 
-#include <X11/Xlib.h>
-#include <X11/Xutil.h>
+ #include <unistd.h>
+ #include <arpa/inet.h>
+ #include <errno.h>
+ #include <sys/socket.h>
+ #include <netinet/in.h>
+ #include <netinet/tcp.h>
+ #include <netdb.h>
+ #include <signal.h>
 
-#define PORT    5555
+ #include <X11/Xlib.h>
+ #include <X11/Xutil.h>
+
+#endif // _WIN32
 
+#define PORT    5555
 #define ENABLE_GL_LOG
 
 #include "opengl_func.h"
 #include "opengl_utils.h"
-
-static int refresh_rate = 1000;
-static int must_save = 0;
-static int timestamp = 1; /* only valid if must_save == 1. include timestamps in the save file to enable real-time playback */
+#include "opengl_server.h"
 
 extern int display_function_call;
-extern void init_process_tab(void);
-extern int do_function_call(Display*, int, int, long*, char*);
-extern void opengl_exec_set_local_connection(void);
-extern void opengl_exec_set_parent_window(Display* _dpy, Window _parent_window);
+
+#ifdef _WIN32
+HWND           displayHWND;
+static Display CreateDisplay(void)
+ {
+   HWND        hWnd;
+   WNDCLASS    wc;
+   LPSTR       ClassName ="DISPLAY";
+   HINSTANCE hInstance = 0;
+
+   /* only register the window class once - use hInstance as a flag. */
+   hInstance = GetModuleHandle(NULL);
+   wc.style         = CS_OWNDC;
+   wc.lpfnWndProc   = (WNDPROC)DefWindowProc;
+   wc.cbClsExtra    = 0;
+   wc.cbWndExtra    = 0;
+   wc.hInstance     = hInstance;
+   wc.hIcon         = LoadIcon(NULL, IDI_WINLOGO);
+   wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
+   wc.hbrBackground = NULL;
+   wc.lpszMenuName  = NULL;
+   wc.lpszClassName = ClassName;
+
+   RegisterClass(&wc);
+
+   displayHWND = CreateWindow(ClassName, ClassName, (WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU ),
+   0, 0, 10, 10, NULL, (HMENU)NULL, hInstance, NULL);
+
+
+   ShowWindow(hWnd, SW_HIDE);
+
+   return GetDC(displayHWND);
+}
+#else
+extern void opengl_exec_set_parent_window(OGLS_Conn *pConn, Window _parent_window);
+#endif // _WIN32
 
 #ifdef ENABLE_GL_LOG
 static FILE* f = NULL;
 
-static char* filename = "/tmp/debug_gl.bin";
+static const char* filename = "/tmp/debug_gl.bin";
 
 #define write_gl_debug_init() do { if (f == NULL) f = fopen(filename, "wb"); } while(0)
 
-static void inline  write_gl_debug_cmd_char(char my_int)
+inline static void  write_gl_debug_cmd_char(char my_int)
 {
        write_gl_debug_init();
        fwrite(&my_int, sizeof(my_int), 1, f);
 }
 
-static void inline  write_gl_debug_cmd_short(short my_int)
+inline static void  write_gl_debug_cmd_short(short my_int)
 {
        write_gl_debug_init();
        fwrite(&my_int, sizeof(my_int), 1, f);
 }
 
-static void inline write_gl_debug_cmd_int(int my_int)
+inline static void write_gl_debug_cmd_int(int my_int)
 {
        write_gl_debug_init();
        fwrite(&my_int, sizeof(my_int), 1, f);
 }
 
-static void inline  write_gl_debug_cmd_longlong(long long my_longlong)
+inline static void  write_gl_debug_cmd_longlong(long long my_longlong)
 {
        write_gl_debug_init();
        fwrite(&my_longlong, sizeof(my_longlong), 1, f);
 }
 
-static void inline  write_gl_debug_cmd_buffer_with_size(int size, void* buffer)
+inline static void  write_gl_debug_cmd_buffer_with_size(int size, void* buffer)
 {
        write_gl_debug_init();
        fwrite(&size, sizeof(int), 1, f);
@@ -98,14 +136,14 @@ static void inline  write_gl_debug_cmd_buffer_with_size(int size, void* buffer)
                fwrite(buffer, size, 1, f);
 }
 
-static void inline  write_gl_debug_cmd_buffer_without_size(int size, void* buffer)
+inline static void  write_gl_debug_cmd_buffer_without_size(int size, void* buffer)
 {
        write_gl_debug_init();
        if (size)
                fwrite(buffer, size, 1, f);
 }
 
-static void inline  write_gl_debug_end()
+inline static void  write_gl_debug_end(void)
 {
        write_gl_debug_init();
        fclose(f);
@@ -114,29 +152,35 @@ static void inline  write_gl_debug_end()
 
 #endif
 
-static void write_sock_data(int sock, void* data, int len)
+static int write_sock_data(int sock, void* data, int len)
 {
+       int offset = 0;
+
        if (len && data)
        {
-               int offset = 0;
                while(offset < len)
                {
                        int nwritten = write(sock, data + offset, len - offset);
                        if (nwritten == -1)
                        {
+#ifndef _WIN32
                                if (errno == EINTR)
                                        continue;
+#endif
                                perror("write");
-                               assert(nwritten != -1);
+                               //assert(nwritten != -1);
+                return -1;
                        }
                        offset += nwritten;
                }
        }
+
+       return offset;
 }
 
-static void inline write_sock_int(int sock, int my_int)
+inline static int write_sock_int(int sock, int my_int)
 {
-       write_sock_data(sock, &my_int, sizeof(int));
+       return write_sock_data(sock, &my_int, sizeof(int));
 }
 
 static int total_read = 0;
@@ -150,63 +194,61 @@ static void read_sock_data(int sock, void* data, int len)
                        int nread = read(sock, data + offset, len - offset);
                        if (nread == -1)
                        {
+#ifndef _WIN32
                                if (errno == EINTR)
                                        continue;
+#endif
                                perror("read");
-                               assert(nread != -1);
+                               //assert(nread != -1);
                        }
                        if (nread == 0)
                        {
-                               fprintf(stderr, "nread = 0\n");
+                               //fprintf(stderr, "nread = 0\n");
+                       }
+                       //assert(nread > 0);
+                       if (nread > 0)
+                       {
+                               offset += nread;
+                               total_read += nread;
                        }
-                       assert(nread > 0);
-                       offset += nread;
-                       total_read += nread;
                }
        }
 }
 
-static int inline read_sock_int(int sock)
+inline static int read_sock_int(int sock)
 {
        int ret;
        read_sock_data(sock, &ret, sizeof(int));
        return ret;
 }
 
-static short inline read_sock_short(int sock)
+inline static short read_sock_short(int sock)
 {
        short ret;
        read_sock_data(sock, &ret, sizeof(short));
        return ret;
 }
 
-
-static Display* dpy = NULL;
-static int parent_xid = -1;
-
-
-static struct timeval last_time, current_time, time_stamp_start;
-static int count_last_time = 0, count_current = 0;
-
-static struct timeval last_read_time, current_read_time;
-
-int has_x_error = 0;
-
-int read_from_client (int sock)
+static int OGLS_readConn( OGLS_Conn *pConn )
 {
+       int sock = pConn->sock;
        long args[50];
        int args_size[50];
        char ret_string[32768];
        char command_buffer[65536*16];
 
-       if (dpy == NULL)
+       if( pConn->Display == NULL )
        {
-               init_process_tab();
-               dpy = XOpenDisplay(NULL);
-               if (parent_xid != -1)
+               create_process_tab(pConn);
+#ifdef _WIN32
+               pConn->Display = CreateDisplay();
+#else
+               pConn->Display = XOpenDisplay(NULL);
+               if (pConn->pOption->parent_xid != -1)
                {
-                       opengl_exec_set_parent_window(dpy, parent_xid);
+                       opengl_exec_set_parent_window(pConn, pConn->pOption->parent_xid);
                }
+#endif // _WIN32
        }
 
        int i;
@@ -225,7 +267,7 @@ int read_from_client (int sock)
                read_sock_data(sock, command_buffer, command_buffer_size);
 
 #ifdef ENABLE_GL_LOG
-               if (must_save) write_gl_debug_cmd_short(_serialized_calls_func);
+               if (pConn->pOption->must_save) write_gl_debug_cmd_short(_serialized_calls_func);
 #endif
 
                while(commmand_buffer_offset < command_buffer_size)
@@ -236,11 +278,12 @@ int read_from_client (int sock)
                                fprintf(stderr, "func_number >= 0 && func_number < GL_N_CALLS failed at "
                                                "commmand_buffer_offset=%d (command_buffer_size=%d)\n",
                                                commmand_buffer_offset, command_buffer_size);
-                               exit(-1);
+                               //exit(-1);
+                               return -1;
                        }
 
 #ifdef ENABLE_GL_LOG
-                       if (must_save) write_gl_debug_cmd_short(func_number);
+                       if (pConn->pOption->must_save) write_gl_debug_cmd_short(func_number);
 #endif
                        commmand_buffer_offset += sizeof(short);
 
@@ -260,7 +303,7 @@ int read_from_client (int sock)
                                                {
                                                        args[i] = *(int*)(command_buffer + commmand_buffer_offset);
 #ifdef ENABLE_GL_LOG
-                                                       if (must_save) write_gl_debug_cmd_char(args[i]);
+                                                       if (pConn->pOption->must_save) write_gl_debug_cmd_char(args[i]);
 #endif
                                                        commmand_buffer_offset += sizeof(int);
                                                        break;
@@ -271,7 +314,7 @@ int read_from_client (int sock)
                                                {
                                                        args[i] = *(int*)(command_buffer + commmand_buffer_offset);
 #ifdef ENABLE_GL_LOG
-                                                       if (must_save) write_gl_debug_cmd_short(args[i]);
+                                                       if (pConn->pOption->must_save) write_gl_debug_cmd_short(args[i]);
 #endif
                                                        commmand_buffer_offset += sizeof(int);
                                                        break;
@@ -283,7 +326,7 @@ int read_from_client (int sock)
                                                {
                                                        args[i] = *(int*)(command_buffer + commmand_buffer_offset);
 #ifdef ENABLE_GL_LOG
-                                                       if (must_save) write_gl_debug_cmd_int(args[i]);
+                                                       if (pConn->pOption->must_save) write_gl_debug_cmd_int(args[i]);
 #endif
                                                        commmand_buffer_offset += sizeof(int);
                                                        break;
@@ -313,7 +356,7 @@ CASE_IN_UNKNOWN_SIZE_POINTERS:
                                                                }
                                                        }
 #ifdef ENABLE_GL_LOG
-                                                       if (must_save) write_gl_debug_cmd_buffer_with_size(args_size[i], (void*)args[i]);
+                                                       if (pConn->pOption->must_save) write_gl_debug_cmd_buffer_with_size(args_size[i], (void*)args[i]);
 #endif
                                                        commmand_buffer_offset += args_size[i];
 
@@ -325,7 +368,7 @@ CASE_IN_LENGTH_DEPENDING_ON_PREVIOUS_ARGS:
                                                        args_size[i] = compute_arg_length(stderr, func_number, i, args);
                                                        args[i] = (args_size[i]) ? (long)(command_buffer + commmand_buffer_offset) : 0;
 #ifdef ENABLE_GL_LOG
-                                                       if (must_save) write_gl_debug_cmd_buffer_without_size(args_size[i], (void*)args[i]);
+                                                       if (pConn->pOption->must_save) write_gl_debug_cmd_buffer_without_size(args_size[i], (void*)args[i]);
 #endif
                                                        commmand_buffer_offset += args_size[i];
                                                        break;
@@ -343,7 +386,7 @@ CASE_IN_KNOWN_SIZE_POINTERS:
                                                args[i] = (long)(command_buffer + commmand_buffer_offset);
                                                args_size[i] = tab_args_type_length[args_type[i]];
 #ifdef ENABLE_GL_LOG
-                                               if (must_save) write_gl_debug_cmd_buffer_without_size(tab_args_type_length[args_type[i]], (void*)args[i]);
+                                               if (pConn->pOption->must_save) write_gl_debug_cmd_buffer_without_size(tab_args_type_length[args_type[i]], (void*)args[i]);
 #endif
                                                commmand_buffer_offset += tab_args_type_length[args_type[i]];
                                                break;
@@ -360,14 +403,13 @@ CASE_IN_KNOWN_SIZE_POINTERS:
                        }
 
                        if (display_function_call) display_gl_call(stderr, func_number, args, args_size);
-
-                       do_function_call(dpy, func_number, 1, args, ret_string);
+                       do_function_call(pConn, func_number, 1, args, ret_string);
                }
        }
        else
        {
 #ifdef ENABLE_GL_LOG
-               if (must_save && func_number != _synchronize_func) write_gl_debug_cmd_short(func_number);
+               if (pConn->pOption->must_save && func_number != _synchronize_func) write_gl_debug_cmd_short(func_number);
 #endif
 
                for(i=0;i<nb_args;i++)
@@ -378,7 +420,7 @@ CASE_IN_KNOWN_SIZE_POINTERS:
                                case TYPE_CHAR:
                                        args[i] = read_sock_int(sock);
 #ifdef ENABLE_GL_LOG
-                                       if (must_save) write_gl_debug_cmd_char(args[i]);
+                                       if (pConn->pOption->must_save) write_gl_debug_cmd_char(args[i]);
 #endif
                                        break;
 
@@ -386,7 +428,7 @@ CASE_IN_KNOWN_SIZE_POINTERS:
                                case TYPE_SHORT:
                                        args[i] = read_sock_int(sock);
 #ifdef ENABLE_GL_LOG
-                                       if (must_save) write_gl_debug_cmd_short(args[i]);
+                                       if (pConn->pOption->must_save) write_gl_debug_cmd_short(args[i]);
 #endif
                                        break;
 
@@ -395,7 +437,7 @@ CASE_IN_KNOWN_SIZE_POINTERS:
                                case TYPE_FLOAT:
                                        args[i] = read_sock_int(sock);
 #ifdef ENABLE_GL_LOG
-                                       if (must_save) write_gl_debug_cmd_int(args[i]);
+                                       if (pConn->pOption->must_save) write_gl_debug_cmd_int(args[i]);
 #endif
                                        break;
 
@@ -418,7 +460,7 @@ CASE_IN_UNKNOWN_SIZE_POINTERS:
                                                        }
                                                }
 #ifdef ENABLE_GL_LOG
-                                               if (must_save) write_gl_debug_cmd_buffer_with_size(args_size[i], (void*)args[i]);
+                                               if (pConn->pOption->must_save) write_gl_debug_cmd_buffer_with_size(args_size[i], (void*)args[i]);
 #endif
                                                break;
                                        }
@@ -429,7 +471,7 @@ CASE_IN_LENGTH_DEPENDING_ON_PREVIOUS_ARGS:
                                                args[i] = (args_size[i]) ? (long)malloc(args_size[i]) : 0;
                                                read_sock_data(sock, (void*)args[i], args_size[i]);
 #ifdef ENABLE_GL_LOG
-                                               if (must_save) write_gl_debug_cmd_buffer_without_size(args_size[i], (void*)args[i]);
+                                               if (pConn->pOption->must_save) write_gl_debug_cmd_buffer_without_size(args_size[i], (void*)args[i]);
 #endif
                                                break;
                                        }
@@ -463,7 +505,7 @@ CASE_OUT_UNKNOWN_SIZE_POINTERS:
                                                }
                                                //fprintf(stderr, "%p %d\n", (void*)args[i], args_size[i]);
 #ifdef ENABLE_GL_LOG
-                                               if (must_save) write_gl_debug_cmd_int(args_size[i]);
+                                               if (pConn->pOption->must_save) write_gl_debug_cmd_int(args_size[i]);
 #endif
                                                break;
                                        }
@@ -483,7 +525,7 @@ CASE_IN_KNOWN_SIZE_POINTERS:
                                        args[i] = (long)malloc(args_size[i]);
                                        read_sock_data(sock, (void*)args[i], args_size[i]);
 #ifdef ENABLE_GL_LOG
-                                       if (must_save) write_gl_debug_cmd_buffer_without_size(tab_args_type_length[args_type[i]], (void*)args[i]);
+                                       if (pConn->pOption->must_save) write_gl_debug_cmd_buffer_without_size(tab_args_type_length[args_type[i]], (void*)args[i]);
 #endif
                                        break;
 
@@ -502,9 +544,9 @@ CASE_IN_KNOWN_SIZE_POINTERS:
 
                if (getenv("ALWAYS_FLUSH")) fflush(f);
 
-               int ret = do_function_call(dpy, func_number, 1, args, ret_string);
+               int ret = do_function_call(pConn, func_number, 1, args, ret_string);
 #ifdef ENABLE_GL_LOG
-               if (must_save && func_number == glXGetVisualFromFBConfig_func)
+               if (pConn->pOption->must_save && func_number == glXGetVisualFromFBConfig_func)
                {
                        write_gl_debug_cmd_int(ret);
                }
@@ -531,7 +573,12 @@ CASE_IN_POINTERS:
 
 CASE_OUT_POINTERS:
                                        //fprintf(stderr, "%p %d\n", (void*)args[i], args_size[i]);
-                                       write_sock_data(sock, (void*)args[i], args_size[i]);
+                                       if( 0> write_sock_data(sock, (void*)args[i], args_size[i]) )
+                                       {
+                                               perror( "write_sock_data" ) ;
+                                               return -1 ;
+                                       }
+
                                        if (display_function_call)
                                        {
                                                if (args_type[i] == TYPE_OUT_1INT)
@@ -559,16 +606,28 @@ CASE_OUT_POINTERS:
 
                if (signature->ret_type == TYPE_CONST_CHAR)
                {
-                       write_sock_int(sock, strlen(ret_string) + 1);
-                       write_sock_data(sock, ret_string, strlen(ret_string) + 1);
+                       if( 0 > write_sock_int(sock, strlen(ret_string) + 1) )
+                       {
+                               perror( "write_sock_int" ) ;
+                               return -1 ;
+                       }
+                       if( 0 > write_sock_data(sock, ret_string, strlen(ret_string) + 1) )
+                       {
+                               perror( "write_sock_data" ) ;
+                               return -1 ;
+                       }
                }
                else if (signature->ret_type != TYPE_NONE)
                {
-                       write_sock_int(sock, ret);
+                       if( 0 > write_sock_int(sock, ret) )
+                       {
+                               perror( "write_sock_int" ) ;
+                               return -1 ;
+                       }
                }
 
 #ifdef ENABLE_GL_LOG
-               if (must_save && func_number == _exit_process_func)
+               if (pConn->pOption->must_save && func_number == _exit_process_func)
                {
                        write_gl_debug_end();
                }
@@ -580,37 +639,37 @@ CASE_OUT_POINTERS:
                else if (func_number == glXSwapBuffers_func)
                {
                        int diff_time;
-                       count_current++;
-                       gettimeofday(&current_time, NULL);
+                       pConn->count_current++;
+                       gettimeofday(&pConn->current_time, NULL);
 #ifdef ENABLE_GL_LOG
-                       if (must_save && timestamp)
+                       if (pConn->pOption->must_save && pConn->pOption->timestamp)
                        {
-                               long long ts = (current_time.tv_sec - time_stamp_start.tv_sec) * (long long)1000000 + current_time.tv_usec - time_stamp_start.tv_usec;
+                               long long ts = (pConn->current_time.tv_sec - pConn->time_stamp_start.tv_sec) * (long long)1000000 + pConn->current_time.tv_usec - pConn->time_stamp_start.tv_usec;
                                /* -1 is special code that indicates time synchro */
                                write_gl_debug_cmd_short(timesynchro_func);
                                write_gl_debug_cmd_longlong(ts);
                        }
 #endif
-                       diff_time = (current_time.tv_sec - last_time.tv_sec) * 1000 + (current_time.tv_usec - last_time.tv_usec) / 1000;
-                       if (diff_time > refresh_rate)
+                       diff_time = (pConn->current_time.tv_sec - pConn->last_time.tv_sec) * 1000 + (pConn->current_time.tv_usec - pConn->last_time.tv_usec) / 1000;
+                       if (diff_time > pConn->pOption->refresh_rate)
                        {
 #ifdef ENABLE_GL_LOG
                                fflush(f);
 #endif
                                printf("%d frames in %.1f seconds = %.3f FPS\n",
-                                               count_current - count_last_time,
+                                               pConn->count_current - pConn->count_last_time,
                                                diff_time / 1000.,
-                                               (count_current - count_last_time) * 1000. / diff_time);
-                               last_time.tv_sec = current_time.tv_sec;
-                               last_time.tv_usec = current_time.tv_usec;
-                               count_last_time = count_current;
+                                               (pConn->count_current - pConn->count_last_time) * 1000. / diff_time);
+                               pConn->last_time.tv_sec = pConn->current_time.tv_sec;
+                               pConn->last_time.tv_usec = pConn->current_time.tv_usec;
+                               pConn->count_last_time = pConn->count_current;
                        }
                }
        }
        return 0;
 }
 
-int make_socket (uint16_t port)
+static int OGLS_createListenSocket (uint16_t port)
 {
        int sock;
        struct sockaddr_in name;
@@ -620,7 +679,8 @@ int make_socket (uint16_t port)
        if (sock < 0)
        {
                perror ("socket");
-               exit (EXIT_FAILURE);
+               //exit (EXIT_FAILURE);
+               return -1;
        }
 
        int flag = 1;
@@ -639,15 +699,89 @@ int make_socket (uint16_t port)
        name.sin_addr.s_addr = htonl (INADDR_ANY);
        if (bind (sock, (struct sockaddr *) &name, sizeof (name)) < 0)
        {
+               fprintf(stderr, "bind: errorno = %d\n", errno);
                perror ("bind");
-               exit (EXIT_FAILURE);
+               //exit (EXIT_FAILURE);
+               return -1;
        }
 
        return sock;
 }
 
-static int x_error_handler(Display     *display,
-               XErrorEvent *error)
+static OGLS_Conn * OGLS_createConn( OGLS_Opts *pOption )
+{
+       OGLS_Conn *pConn = malloc(sizeof(OGLS_Conn));
+       if( !pConn )
+       {
+               return NULL ;
+       }
+
+       memset( pConn, 0, sizeof(*pConn) );
+       pConn->pOption = pOption;
+       return pConn;
+}
+
+static void OGLS_removeConn( OGLS_Conn *pConn )
+{
+       if( !pConn ) return ;
+
+       if( pConn->sock > 0 )
+       {
+               closesocket(pConn->sock);
+               pConn->sock = 0 ;
+       }
+
+       if( pConn->Display )
+       {
+#ifdef _WIN32
+//             ReleaseDC(pConn->Display);
+#else
+               XCloseDisplay( pConn->Display );
+               pConn->Display = NULL;
+#endif // _WIN32
+       }
+
+       remove_process_tab(pConn);
+
+       free( pConn );
+}
+
+static void OGLS_loop( OGLS_Conn *pConn )
+{
+       //fprintf (stderr, "Server: connect from host %s, port %hd.\n",
+       //              inet_ntoa (pConn->clientname.sin_addr),
+       //              ntohs (pConn->clientname.sin_port));
+
+       gettimeofday(&pConn->last_time, NULL);
+       gettimeofday(&pConn->last_read_time, NULL);
+
+#ifndef _WIN32
+       if (strcmp(inet_ntoa(pConn->clientname.sin_addr), "127.0.0.1") == 0 &&
+                       pConn->pOption->different_windows == 0)
+       {
+               pConn->local_connection = 1;
+       }
+#endif // _WIN32
+
+       if( pConn->pOption->timestamp )
+       {
+               gettimeofday(&pConn->time_stamp_start, NULL);
+       }
+
+       while( OGLS_readConn(pConn) >= 0 );
+
+       do_function_call(pConn, _exit_process_func, 1, NULL, NULL);
+
+       //fprintf (stderr, "Server: disconnect from host %s, port %hd.\n",
+       //              inet_ntoa (pConn->clientname.sin_addr),
+       //              ntohs (pConn->clientname.sin_port));
+
+       OGLS_removeConn( pConn );
+}
+
+#ifndef _WIN32
+int has_x_error = 0;
+static int OGLS_x_error_handler(Display *display, XErrorEvent *error)
 {
        char buf[64];
        XGetErrorText(display, error->error_code, buf, 63);
@@ -663,8 +797,80 @@ static int x_error_handler(Display     *display,
        has_x_error = 1;
        return 0;
 }
+#endif // _WIN32
+
+static void OGLS_main( OGLS_Opts *pOption )
+{
+       int sock;
+       fd_set active_fd_set, read_fd_set;
+
+       socklen_t size;
+
+#ifndef _WIN32
+       XSetErrorHandler(OGLS_x_error_handler);
+#endif // _WIN32
+
+       /* Create the socket and set it up to accept connections. */
+       sock = OGLS_createListenSocket( pOption->port );
+       if (sock < 0)
+               return;
+
+       if (listen (sock, 1) < 0)
+       {
+               perror ("listen");
+               //exit (EXIT_FAILURE);
+               return;
+       }
+
+       FD_ZERO (&active_fd_set);
+       FD_SET (sock, &active_fd_set);
+
+       while(1)
+       {
+               OGLS_Conn *pConn = NULL;
+               pthread_t taskid;
+
+               read_fd_set = active_fd_set;
+               if (select (FD_SETSIZE, &read_fd_set, NULL, NULL, NULL) < 0)
+               {
+#ifndef _WIN32
+                       if (errno == EINTR) {
+                               continue;
+                       }
+#endif
+                       perror ("select");
+                       //exit (EXIT_FAILURE);
+                       break;
+               }
+
+               pConn = OGLS_createConn( pOption );
+               if( !pConn )
+               {
+                       perror( "OGLS_createConn" );
+                       continue;
+               }
+
+               size = sizeof(pConn->clientname);
+               pConn->sock = accept (sock, (struct sockaddr *) &pConn->clientname, &size);
+               if (pConn->sock < 0)
+               {
+                       perror ("accept");
+                       OGLS_removeConn( pConn );
+                       continue;
+               }
+
+               if( pthread_create( (pthread_t *)&taskid, NULL, (void *(*)(void *))OGLS_loop, (void *)pConn ) )
+               {
+                       perror( "pthread_create" );
+                       OGLS_removeConn( pConn );
+                       continue;
+               }
+       }
+
+       closesocket( sock );
+}
 
-void usage()
+static void usage(void)
 {
        printf("Usage : opengl_server [OPTION]\n\n");
        printf("The following options are available :\n");
@@ -679,16 +885,21 @@ void usage()
        printf("--h or --help       : display this help\n");
 }
 
-int main (int argc, char* argv[])
+//int main (int argc, char* argv[])
+void *init_opengl_server(void *arg)
 {
-       int sock;
-       fd_set active_fd_set, read_fd_set;
-       int i;
-       struct sockaddr_in clientname;
-       socklen_t size;
-       int port = PORT;
-       int different_windows = 0;
+       //int i;
+       OGLS_Opts option;
+
+       memset( &option, 0, sizeof(option) );
 
+       // set default values
+       option.port = PORT;
+       option.parent_xid = -1;
+       option.refresh_rate = 1000;
+       option.timestamp = 1; /* only valid if must_save == 1. include timestamps in the save file to enable real-time playback */
+
+#if 0
        for(i=1;i<argc;i++)
        {
                if (argv[i][0] == '-' && argv[i][1] == '-')
@@ -696,15 +907,15 @@ int main (int argc, char* argv[])
 
                if (strcmp(argv[i], "-debug") == 0)
                {
-                       display_function_call = 1;
+                       option.display_function_call = 1;
                }
                else if (strcmp(argv[i], "-save") == 0)
                {
-                       must_save = 1;
+                       option.must_save = 1;
                }
                else if (strncmp(argv[i], "-port=",6) == 0)
                {
-                       port = atoi(argv[i] + 6);
+                       option.port = atoi(argv[i] + 6);
                }
                else if (strncmp(argv[i], "-filename=",strlen("-filename=")) == 0)
                {
@@ -713,12 +924,12 @@ int main (int argc, char* argv[])
                else if (strncmp(argv[i], "-parent-xid=",strlen("-parent-xid=")) == 0)
                {
                        char* c = argv[i] + strlen("-parent-xid=");
-                       parent_xid = strtol(c, NULL, 0);
-                       different_windows = 1;
+                       option.parent_xid = strtol(c, NULL, 0);
+                       option.different_windows = 1;
                }
                else if (strcmp(argv[i], "-different-windows") == 0)
                {
-                       different_windows = 1;
+                       option.different_windows = 1;
                }
                else if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "-help") == 0)
                {
@@ -732,91 +943,8 @@ int main (int argc, char* argv[])
                        return -1;
                }
        }
+#endif /* 0 */
 
-       /* Create the socket and set it up to accept connections. */
-       sock = make_socket (port);
-
-       if (listen (sock, 1) < 0)
-       {
-               perror ("listen");
-               exit (EXIT_FAILURE);
-       }
-
-       struct sigaction action;
-       action.sa_handler = SIG_IGN;
-       action.sa_flags = SA_NOCLDWAIT;
-       sigaction(SIGCHLD,&action,NULL);
-
-       FD_ZERO (&active_fd_set);
-       FD_SET (sock, &active_fd_set);
-
-       while(1)
-       {
-               int new, pid;
-
-               read_fd_set = active_fd_set;
-               if (select (FD_SETSIZE, &read_fd_set, NULL, NULL, NULL) < 0)
-               {
-                       perror ("select");
-                       exit (EXIT_FAILURE);
-               }
-
-               size = sizeof (clientname);
-               new = accept (sock, (struct sockaddr *) &clientname, &size);
-               if (new < 0)
-               {
-                       perror ("accept");
-                       exit (EXIT_FAILURE);
-               }
-               pid = fork();
-               if (pid == -1)
-               {
-                       perror ("fork");
-                       exit(EXIT_FAILURE);
-               }
-               if (pid == 0)
-               {
-                       close(sock);
-
-                       fprintf (stderr, "Server: connect from host %s, port %hd.\n",
-                                       inet_ntoa (clientname.sin_addr),
-                                       ntohs (clientname.sin_port));
-
-                       gettimeofday(&last_time, NULL);
-                       gettimeofday(&last_read_time, NULL);
-
-                       if (strcmp(inet_ntoa(clientname.sin_addr), "127.0.0.1") == 0 &&
-                                       different_windows == 0)
-                       {
-                               opengl_exec_set_local_connection();
-                       }
-
-                       if (timestamp)
-                       {
-                               gettimeofday(&time_stamp_start, NULL);
-                       }
-
-                       XSetErrorHandler(x_error_handler);
-
-                       while(1)
-                       {
-                               if (read_from_client (new) < 0)
-                               {
-                                       do_function_call(dpy, _exit_process_func, 1, NULL, NULL);
-
-                                       fprintf (stderr, "Server: disconnect from host %s, port %hd.\n",
-                                                       inet_ntoa (clientname.sin_addr),
-                                                       ntohs (clientname.sin_port));
-
-                                       return 0;
-                               }
-                       }
-               }
-               else
-               {
-                       close(new);
-               }
-       }
-
+       OGLS_main(&option);
        return 0;
 }
diff --git a/target-i386/opengl_server.h b/target-i386/opengl_server.h
new file mode 100644 (file)
index 0000000..3c634f7
--- /dev/null
@@ -0,0 +1,70 @@
+/*
+ * opengl_server.h
+ *
+ *  Created on: 2011. 6. 30.
+ *      Author: dhhong
+ */
+
+#ifndef OPENGL_SERVER_H_
+#define OPENGL_SERVER_H_
+
+#ifndef _WIN32
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <netinet/tcp.h>
+#include <netdb.h>
+#endif /* _WIN32 */
+
+#ifdef _WIN32
+#define socklen_t      int
+typedef HDC Display;
+#else
+#define closesocket close
+#endif
+
+typedef struct {
+       int port;
+       int different_windows;
+       int display_function_call;
+       int must_save;
+       int parent_xid;
+       int refresh_rate;
+       int timestamp; /* only valid if must_save == 1. include timestamps in the save file to enable real-time playback */
+} OGLS_Opts;
+
+typedef struct {
+       int sock;
+       int count_last_time, count_current;
+       struct timeval last_time, current_time, time_stamp_start;
+       struct timeval last_read_time, current_read_time;
+
+       struct sockaddr_in clientname;
+#ifdef _WIN32
+       Display Display;
+       HDC active_win; /* FIXME */
+#else
+       Display* parent_dpy;
+       Window qemu_parent_window;
+
+       Display* Display;
+       Window active_win; /* FIXME */
+#endif
+       int active_win_x;
+       int active_win_y;
+
+       int local_connection;
+
+       int last_assigned_internal_num;
+       int last_active_internal_num;
+
+       int  nTabAssocAttribListVisual ;
+       void* tabAssocAttribListVisual ;
+       void * processTab;
+
+       OGLS_Opts *pOption;
+} OGLS_Conn ;
+
+/* opengl_server main function */
+void *init_opengl_server(void *arg);
+
+#endif /* OPENGL_SERVER_H_ */
index 7bcfade..1b0a2b5 100644 (file)
@@ -334,7 +334,7 @@ static inline void display_gl_call(FILE* f, int func_number, long* args, int* ar
        int nb_args = signature->nb_args;
        int* args_type = signature->args_type;
 
-       fprintf(f, "%s(", tab_opengl_calls_name[func_number]);
+       //fprintf(f, "%s(", tab_opengl_calls_name[func_number]);
 
        for(i=0;i<nb_args;i++)
        {
index bdbfdd6..0162da7 100644 (file)
@@ -791,6 +791,7 @@ static inline void gen_update_cc_op(DisasContext *s)
     }
 }
 
+extern void helper_int99(void);
 void  helper_opengl99(void)
 {
        helper_int99();