From 843aa9186532f2ec0bb58c06efed628502c00683 Mon Sep 17 00:00:00 2001 From: Eric Heien Date: Fri, 20 Dec 2002 20:20:56 +0000 Subject: [PATCH] graphics fixes svn path=/trunk/boinc/; revision=784 --- api/boinc_api.C | 17 ++++++++++---- api/windows_opengl.cpp | 51 ++++++++++++++++++++++++++++++------------ lib/parse.C | 2 +- lib/parse.h | 1 - 4 files changed, 51 insertions(+), 20 deletions(-) diff --git a/api/boinc_api.C b/api/boinc_api.C index ab84c33b80..aab82e9922 100644 --- a/api/boinc_api.C +++ b/api/boinc_api.C @@ -55,7 +55,7 @@ MMRESULT timer_id; #include // Header File For The OpenGL32 Library #include // Header File For The GLu32 Library #include // Header File For The Glaux Library -HANDLE hGlobalDrawEvent,hQuitEvent; +HANDLE hDoneDrawingEvent,hQuitEvent, hGraphicsDrawEvent; extern HANDLE graphics_threadh; extern BOOL win_loop_done; #endif @@ -311,11 +311,14 @@ bool boinc_time_to_checkpoint() { ok_to_draw = 1; // And wait for the graphics thread to notify us that it's done drawing #ifdef _WIN32 - ResetEvent(hGlobalDrawEvent); + // Notify the graphics thread + SetEvent(hGraphicsDrawEvent); + // Reset the draw done event + ResetEvent(hDoneDrawingEvent); while (ok_to_draw) { // Wait for drawing to finish. We don't do an infinite wait here to avoid the // possibility of deadlock (which was happening with an infinite wait value) - WaitForSingleObject( hGlobalDrawEvent, 10 ); + WaitForSingleObject( hDoneDrawingEvent, 10 ); } #endif _WIN32 #ifdef __APPLE_CC__ @@ -516,7 +519,13 @@ int set_timer(double period) { #ifdef BOINC_APP_GRAPHICS // Create the event object used to signal between the // worker and event threads - hGlobalDrawEvent = CreateEvent( + hDoneDrawingEvent = CreateEvent( + NULL, // no security attributes + TRUE, // manual reset event + TRUE, // initial state is signaled + NULL); // object not named + + hGraphicsDrawEvent = CreateEvent( NULL, // no security attributes TRUE, // manual reset event TRUE, // initial state is signaled diff --git a/api/windows_opengl.cpp b/api/windows_opengl.cpp index 54d260cd31..c028669e55 100755 --- a/api/windows_opengl.cpp +++ b/api/windows_opengl.cpp @@ -53,7 +53,7 @@ bool active=TRUE; // Window Active Flag Set To TRUE By Default bool fullscreen=TRUE; // Fullscreen Flag Set To Fullscreen Mode By Default BOOL win_loop_done=FALSE; // Bool Variable To Exit Loop int counter,old_left,old_top,old_right,old_bottom,cur_gfx_mode,old_gfx_mode; -extern HANDLE hGlobalDrawEvent,hQuitEvent; +extern HANDLE hGraphicsDrawEvent,hQuitEvent,hDoneDrawingEvent; int DrawGLScene(GLvoid); LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); // Declaration For WndProc @@ -164,6 +164,11 @@ void ChangeMode( int mode ) { switch (mode) { case MODE_NO_GRAPHICS: if (fullscreen) while(ShowCursor(true) < 0); // Show Mouse Pointer + GetWindowRect( hWnd, &WindowRect ); + old_left = WindowRect.left; + old_top = WindowRect.top; + old_right = WindowRect.right; + old_bottom = WindowRect.bottom; fullscreen = false; break; case MODE_WINDOW: @@ -420,6 +425,21 @@ LRESULT CALLBACK WndProc( HWND hWnd, // Handle For This Window ReSizeGLScene(LOWORD(lParam),HIWORD(lParam)); // LoWord=Width, HiWord=Height return 0; // Jump Back } + + // If we get a redraw request outside of our normal + // redraw framework, just fill the window with black + case WM_PAINT: + { + PAINTSTRUCT ps; + HDC hdc; + RECT winRect; + + hdc = BeginPaint(hWnd, &ps); + GetClientRect(hWnd, &winRect); + FillRect(hdc, &winRect, (HBRUSH) GetStockObject(BLACK_BRUSH)); + EndPaint(hWnd, &ps); + return 0; + } } // Pass All Unhandled Messages To DefWindowProc @@ -428,6 +448,7 @@ LRESULT CALLBACK WndProc( HWND hWnd, // Handle For This Window DWORD WINAPI win_graphics_event_loop( LPVOID gi ) { MSG msg; // Windows Message Structure + HANDLE objs[1]; fullscreen=FALSE; // Windowed Mode @@ -461,21 +482,23 @@ DWORD WINAPI win_graphics_event_loop( LPVOID gi ) { TranslateMessage(&msg); // Translate The Message DispatchMessage(&msg); // Dispatch The Message } + } else { + objs[0] = hGraphicsDrawEvent; + MsgWaitForMultipleObjects( 1, objs, FALSE, 1000, QS_ALLEVENTS|QS_POSTMESSAGE ); } - else // If There Are No Messages - { - if (ok_to_draw) { // Window Active? - if (active) { // Not Time To Quit, Update Screen - // Draw The Scene - DrawGLScene(); - // Swap Buffers (Double Buffering). This seems to take lots of CPU time - SwapBuffers(hDC); - } - // TODO: Do we need a mutex for ok_to_draw? - ok_to_draw = 0; - // Signal the worker thread that we're done drawing - SetEvent(hGlobalDrawEvent); + if (ok_to_draw) { // Window Active? + if (active) { // Time To Update Screen + // Draw The Scene + DrawGLScene(); + // Swap Buffers (Double Buffering). This seems to take lots of CPU time + SwapBuffers(hDC); } + // TODO: Do we need a mutex for ok_to_draw? + ok_to_draw = 0; + // Signal the worker thread that we're done drawing + SetEvent(hDoneDrawingEvent); + // Put hGraphicsDrawEvent in unsignaled state so we don't immediately wake up + ResetEvent(hGraphicsDrawEvent); } } diff --git a/lib/parse.C b/lib/parse.C index 33e189adc9..518ba8e936 100644 --- a/lib/parse.C +++ b/lib/parse.C @@ -151,7 +151,7 @@ int read_file_malloc(char* pathname, char*& str) { // replace XML element contents. not currently used // void replace_element(char* buf, char* start, char* end, char* replacement) { - char temp[MAX_BLOB_SIZE], *p, *q; + char temp[4096], *p, *q; p = strstr(buf, start); p += strlen(start); diff --git a/lib/parse.h b/lib/parse.h index d4ef0d371a..3280e69224 100644 --- a/lib/parse.h +++ b/lib/parse.h @@ -18,7 +18,6 @@ // #include -#include extern bool parse(char*, char*); extern bool parse_int(char*, char*, int&);